示例#1
0
function save()
{
    $obj = new manage_professor_exe_posts();
    PdoDataAccess::FillObjectByArray($obj, $_POST);
    $postObj = new manage_posts($obj->post_id);
    if ($postObj->post_id == "") {
        echo Response::createObjectiveResponse(false, "کد پست وارد شده معتبر نمی باشد.");
        die;
    }
    if ($postObj->validity_start != "" && $postObj->validity_start != '0000-00-00' && DateModules::CompareDate($postObj->validity_start, str_replace("/", "-", DateModules::shamsi_to_miladi($obj->from_date))) > 0 || $postObj->validity_end != "" && $postObj->validity_end != '0000-00-00' && ($obj->to_date != "" && $obj->to_date != "0000-00-00") && DateModules::CompareDate($postObj->validity_end, str_replace("/", "-", DateModules::shamsi_to_miladi($obj->to_date))) < 0) {
        echo Response::createObjectiveResponse(false, "پست انتخابی از نظر تاریخ اعتبار و تاریخ های شروع و پایان وارد شده معتبر نمی باشد.");
        die;
    }
    if (empty($obj->row_no)) {
        $return = $obj->ADD();
    } else {
        $return = $obj->Edit();
    }
    if (!$return) {
        echo Response::createObjectiveResponse($return, ExceptionHandler::GetExceptionsToString());
        die;
    }
    if (isset($_POST["assign_post"])) {
        $return = $obj->assign_post();
    } else {
        $return = $obj->release_post();
    }
    echo Response::createObjectiveResponse($return, ExceptionHandler::GetExceptionsToString());
    die;
}
示例#2
0
function duty_year_month_day($staff_id = "", $personID = "", $toDate) {
    if ($staff_id == "" && $personID = "") {
        PdoDataAccess::PushException("يکي از دو پارامتر staff_id و PersonID بايد فرستاده شود");
        return false;                
    }
    $query = "select w.execute_date,
						w.contract_start_date ,
						w.contract_end_date ,
						w.person_type ,
						w.onduty_year ,
						w.onduty_month ,
						w.onduty_day ,
						w.annual_effect
			from writs as w";

    if ($personID != "")
        $query .= " join staff as s using(staff_id) where s.PersonID=" . $personID;

    else if ($staff_id != "")
        $query .= " where w.staff_id = $staff_id";

    $query .= " AND (w.history_only != " . HISTORY_ONLY . " OR w.history_only is null) AND w.execute_date <= '$toDate'
						order by w.execute_date DESC,w.writ_id DESC,w.writ_ver DESC
						limit 1";

    $temp = PdoDataAccess::runquery($query);

    if (count($temp) == 0)
        return array("year" => 0, "month" => 0, "day" => 0);

    $writ_rec = $temp[0];

    $temp_duration = 0;

    if (DateModules::CompareDate($toDate, $writ_rec['execute_date']) >= 0)
        $temp_duration = DateModules::GDateMinusGDate($toDate, $writ_rec['execute_date']);

    if ($writ_rec['annual_effect'] == HALF_COMPUTED)
        $temp_duration *= 0.5;
    else if ($writ_rec['annual_effect'] == DOUBLE_COMPUTED)
        $temp_duration *= 2;
    else if ($writ_rec['annual_effect'] == NOT_COMPUTED)
        $temp_duration = 0;

    $prev_writ_duration = DateModules::ymd_to_days($writ_rec['onduty_year'], $writ_rec['onduty_month'], $writ_rec['onduty_day']);

    $duration = $prev_writ_duration + $temp_duration;
    
       
    $return = array();
    DateModules::day_to_ymd($duration, $return['year'], $return['month'], $return['day']);

    return $return;
}
示例#3
0
function SplitYears($startDate, $endDate, $TotalAmount)
{
    if (substr($startDate, 0, 1) == 2) {
        $startDate = DateModules::miladi_to_shamsi($startDate);
    }
    if (substr($endDate, 0, 1) == 2) {
        $endDate = DateModules::miladi_to_shamsi($endDate);
    }
    $arr = preg_split('/[\\-\\/]/', $startDate);
    $StartYear = $arr[0] * 1;
    $totalDays = 0;
    $yearDays = array();
    $newStartDate = $startDate;
    while (DateModules::CompareDate($newStartDate, $endDate) < 0) {
        $arr = preg_split('/[\\-\\/]/', $newStartDate);
        $LastDayOfYear = DateModules::lastJDateOfYear($arr[0]);
        if (DateModules::CompareDate($LastDayOfYear, $endDate) > 0) {
            $LastDayOfYear = $endDate;
        }
        $yearDays[$StartYear] = DateModules::JDateMinusJDate($LastDayOfYear, $newStartDate) + 1;
        $totalDays += $yearDays[$StartYear];
        $StartYear++;
        $newStartDate = DateModules::AddToJDate($LastDayOfYear, 1);
    }
    $TotalDays = DateModules::JDateMinusJDate($endDate, $startDate) + 1;
    $sum = 0;
    foreach ($yearDays as $year => $days) {
        $yearDays[$year] = round($days / $TotalDays * $TotalAmount);
        $sum += $yearDays[$year];
        //echo  $year . " " . $days . " " . $yearDays[$year] . "\n";
    }
    if ($sum != $TotalAmount) {
        $yearDays[$year] += $TotalAmount - $sum;
    }
    return $yearDays;
}
function InsertData()
{
    if (!empty($_FILES['attach']['name'])) {
        $data = new Spreadsheet_Excel_Reader();
        $data->setOutputEncoding('utf-8');
        $data->setRowColOffset(0);
        $data->read($_FILES["attach"]["tmp_name"]);
    }
    $log_obj = new manage_group_pay_get_log();
    $FileType = $_POST["PayType"];
    $PayYear = $_POST["pay_year"];
    $PayMonth = $_POST["pay_month"];
    $SID = $_POST["sid"];
    $success_count = 0;
    $unsuccess_count = 0;
    //.......ماموریت.......................................................
    if ($FileType == 8) {
        if (empty($_FILES['attach']['name'])) {
            $SDate = $PayYear . "/" . $PayMonth . "/01";
            if ($PayMonth < 7) {
                $endDay = "31";
            } elseif ($PayMonth > 6 && $PayMonth < 12) {
                $endDay = "30 ";
            } elseif ($PayMonth == 12) {
                $endDay = "29";
            }
            $EDate = $PayYear . "/" . $PayMonth . "/" . $endDay;
            $pdo = PdoDataAccess::getPdoObject();
            $pdo->beginTransaction();
            $query = "\tSELECT staff_id , duration , region_coef , salary_item_type_id , mli.list_id , mli.list_row_no \n\n\t\t\t\t\t\t\tFROM pay_get_lists pgl inner join mission_list_items mli\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ton pgl.list_id = mli.list_id\n\n\t\t\t\t\t\t\t\t\t\t\t\twhere list_type = 9 and pgl.list_date >= '" . DateModules::shamsi_to_miladi($SDate) . "' and\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tpgl.list_date <= j2g({$PayYear},{$PayMonth},{$endDay}) and doc_state = 3 ";
            //".DateModules::shamsi_to_miladi($EDate) ."
            $res = PdoDataAccess::runquery($query);
            for ($i = 0; $i < count($res); $i++) {
                $PaymentObj = new manage_payments();
                $PayItmObj = new manage_payment_items();
                $query = " select staff_id , bank_id , account_no , last_cost_center_id , person_type  \n\t\t\t\t\t\t                from hrmstotal.staff where staff_id =" . $res[$i]['staff_id'];
                $resStf = PdoDataAccess::runquery($query);
                if (!isset($resStf[0]['bank_id']) || !($resStf[0]['bank_id'] > 0)) {
                    $log_obj->make_unsuccess_rows($res[$i]['staff_id'], "-", "بانک فرد جهت پرداخت مشخص نمی باشد.");
                    $unsuccess_count++;
                    continue;
                }
                if (!($resStf[0]['account_no'] > 0)) {
                    $log_obj->make_unsuccess_rows($res[$i]['staff_id'], "-", "شماره حساب فرد جهت پرداخت مشخص نمی باشد.");
                    $unsuccess_count++;
                    continue;
                }
                if (!($resStf[0]['last_cost_center_id'] > 0)) {
                    $log_obj->make_unsuccess_rows($res[$i]['staff_id'], "-", "آخرین مرکز هزینه فرد مشخص نشده است.");
                    $unsuccess_count++;
                    continue;
                }
                //......... محاسبه ماموریت............................
                $coef = !empty($res[$i]['region_coef']) ? $res[$i]['region_coef'] : 0;
                $param1 = 0;
                $missionValue = manage_payment_calculation::calculate_mission($res[$i]['staff_id'], $PayYear, $PayMonth, $res[$i]['duration'], $coef, $param1);
                /*if($res[$i]['staff_id'] == 882660 ) {
                 echo "----".$missionValue ;  	 die() ;  }*/
                //....................................................
                $PaymentObj->staff_id = $res[$i]['staff_id'];
                $PaymentObj->pay_year = $PayYear;
                $PaymentObj->pay_month = $PayMonth;
                $PaymentObj->payment_type = $FileType;
                $PaymentObj->bank_id = $resStf[0]['bank_id'];
                $PaymentObj->account_no = $resStf[0]['account_no'];
                $PaymentObj->state = 2;
                unset($payRes);
                /*if( $resStf[0]['person_type'] == 1 || $resStf[0]['person_type'] == 2 || $resStf[0]['person_type'] == 3 ) 
                			$DB = "hrms.";
                		else 
                			$DB = "hrms_sherkati."; */
                $qry = " select count(*) cn  \n\t\t\t\t\t\t\t\t\tfrom payments \n\t\t\t\t\t\t\t\t\t\t\twhere pay_year = " . $PayYear . " and pay_month = " . $PayMonth . " and staff_id = " . $PaymentObj->staff_id . " and payment_type = " . $FileType;
                $payRes = PdoDataAccess::runquery($qry);
                if ($payRes[0]['cn'] == 0) {
                    if ($PaymentObj->Add($pdo) === false) {
                        $log_obj->make_unsuccess_rows($res[$i]['staff_id'], "-", "خطا در ثبت  فیش ماموریت");
                        $unsuccess_count++;
                        continue;
                    }
                    if ($resStf[0]['person_type'] == 1) {
                        $SID = 42;
                    }
                    if ($resStf[0]['person_type'] == 2) {
                        $SID = 43;
                    }
                    if ($resStf[0]['person_type'] == 3) {
                        $SID = 10315;
                    }
                    if ($resStf[0]['person_type'] == 5) {
                        $SID = 643;
                    }
                    //$SID = $res[$i]['salary_item_type_id'] ;
                    //............ مرکز هزینه .....................
                    $PayItmObj->pay_year = $PayYear;
                    $PayItmObj->pay_month = $PayMonth;
                    $PayItmObj->param1 = $param1;
                    $PayItmObj->staff_id = $res[$i]['staff_id'];
                    $PayItmObj->salary_item_type_id = $SID;
                    $PayItmObj->pay_value = $missionValue;
                    $PayItmObj->cost_center_id = $resStf[0]['last_cost_center_id'];
                    $PayItmObj->payment_type = 8;
                    if ($PayItmObj->Add() === false) {
                        $log_obj->make_unsuccess_rows($res[$i]['staff_id'], "-", " عدم ثبت رکورد");
                        $unsuccess_count++;
                        continue;
                    }
                    $qry = " update hrmstotal.mission_list_items set PayValue =" . $missionValue . " \n\t\t\t\t\t\t\t\t\t\twhere  list_id= " . $res[$i]['list_id'] . " and list_row_no=" . $res[$i]['list_row_no'];
                    //print_r(ExceptionHandler::PopAllExceptions()) ;
                    //echo PdoDataAccess::GetLatestQueryString() .'----<br>';
                    if (PdoDataAccess::runquery($qry, array(), $pdo) === false) {
                        $log_obj->make_unsuccess_rows($res[$i]['staff_id'], "-", "خطا در ثبت مبلغ در رکورد ماموریت");
                        $unsuccess_count++;
                        continue;
                    }
                } else {
                    if ($payRes[0]['cn'] > 0) {
                        $qry = " select pay_value \n\t\t\t\t\t\t\t\t\tfrom payment_items \n\t\t\t\t\t\t\t\t\t\twhere pay_year = " . $PayYear . " and pay_month = " . $PayMonth . " and staff_id = " . $PaymentObj->staff_id . " and payment_type = " . $FileType;
                        $resItem = PdoDataAccess::runquery($qry);
                        //................................................
                        if (count($resItem) > 0) {
                            $PayItmObj->pay_year = $PayYear;
                            $PayItmObj->pay_month = $PayMonth;
                            $PayItmObj->param1 = $param1;
                            $PayItmObj->staff_id = $PaymentObj->staff_id;
                            $PayItmObj->pay_value = $missionValue + $resItem[0]['pay_value'];
                            $PayItmObj->payment_type = 8;
                            if ($PayItmObj->Edit($pdo) === false) {
                                $log_obj->make_unsuccess_rows($PaymentObj->staff_id, "-", " خطای بروز رسانی ");
                                $unsuccess_count++;
                                continue;
                            }
                            $qry = " update hrmstotal.mission_list_items set PayValue =" . $missionValue . " \n\t\t\t\t\t\t\t\t\t\twhere  list_id= " . $res[$i]['list_id'] . " and list_row_no=" . $res[$i]['list_row_no'];
                            //PdoDataAccess::runquery($qry) ;
                            // echo "***we*".PdoDataAccess::AffectedRows()."---";
                            //print_r(ExceptionHandler::PopAllExceptions()) ; echo PdoDataAccess::GetLatestQueryString() .'----<br>';     die() ;
                            if (PdoDataAccess::runquery($qry, array(), $pdo) === false) {
                                $log_obj->make_unsuccess_rows($res[$i]['staff_id'], "-", "خطا در ثبت مبلغ در رکورد ماموریت");
                                $unsuccess_count++;
                                continue;
                            }
                        }
                    }
                }
            }
            //End for
            $log_obj->finalize();
            $st = preg_replace('/\\r\\n/', "", $log_obj->make_result("UploadPayFilesObj.expand();"));
            if ($unsuccess_count > 0) {
                $pdo->rollBack();
            } else {
                //echo "************" ; die() ;
                $pdo->commit();
            }
            echo "{success:true,data:'" . $st . "'}";
            die;
        } else {
            die;
            $pdo = PdoDataAccess::getPdoObject();
            $pdo->beginTransaction();
            for ($i = 1; $i < $data->sheets[0]['numRows']; $i++) {
                $PaymentObj = new manage_payments();
                $PayItmObj = new manage_payment_items();
                if (!isset($data->sheets[0]['cells'][$i][0]) && !isset($data->sheets[0]['cells'][$i][1])) {
                    break;
                }
                $query = " select staff_id , bank_id , account_no , last_cost_center_id , person_type  \n\t\t\t\t\t\t                from staff where staff_id =" . $data->sheets[0]['cells'][$i][0];
                $resStf = PdoDataAccess::runquery($query);
                if (count($resStf) == 0) {
                    $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " شماره شناسایی معتبر نمی باشد.");
                    $unsuccess_count++;
                    continue;
                }
                if (!($resStf[0]['bank_id'] > 0)) {
                    $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", "بانک فرد جهت پرداخت مشخص نمی باشد.");
                    $unsuccess_count++;
                    continue;
                }
                if (!($resStf[0]['account_no'] > 0)) {
                    $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", "شماره حساب فرد جهت پرداخت مشخص نمی باشد.");
                    $unsuccess_count++;
                    continue;
                }
                if (!($resStf[0]['last_cost_center_id'] > 0)) {
                    $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", "آخرین مرکز هزینه فرد مشخص نشده است.");
                    $unsuccess_count++;
                    continue;
                }
                //......... محاسبه ماموریت............................
                $coef = !empty($data->sheets[0]['cells'][$i][2]) ? $data->sheets[0]['cells'][$i][2] : 0;
                $missionValue = manage_payment_calculation::calculate_mission($data->sheets[0]['cells'][$i][0], $PayYear, $PayMonth, $data->sheets[0]['cells'][$i][1], $coef);
                //....................................................
                $PaymentObj->staff_id = $data->sheets[0]['cells'][$i][0];
                $PaymentObj->pay_year = $PayYear;
                $PaymentObj->pay_month = $PayMonth;
                $PaymentObj->payment_type = $FileType;
                $PaymentObj->bank_id = $resStf[0]['bank_id'];
                $PaymentObj->account_no = $resStf[0]['account_no'];
                $PaymentObj->state = 2;
                $qry = " select count(*) cn  \n\t\t\t\t\t\t\t\t\tfrom hrms.payments \n\t\t\t\t\t\t\t\t\t\t\twhere pay_year = " . $PayYear . " and pay_month = " . $PayMonth . " and staff_id = " . $PaymentObj->staff_id . " and payment_type = " . $FileType;
                $payRes = PdoDataAccess::runquery($qry);
                if ($payRes[0]['cn'] == 0) {
                    if ($PaymentObj->Add() === false) {
                        $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطا ");
                        $unsuccess_count++;
                        continue;
                    }
                    if ($resStf[0]['person_type'] == 1) {
                        $SID = 42;
                    }
                    if ($resStf[0]['person_type'] == 2) {
                        $SID = 43;
                    }
                    //............ مرکز هزینه .....................
                    $PayItmObj->pay_year = $PayYear;
                    $PayItmObj->pay_month = $PayMonth;
                    $PayItmObj->staff_id = $data->sheets[0]['cells'][$i][0];
                    $PayItmObj->salary_item_type_id = $SID;
                    $PayItmObj->pay_value = $missionValue;
                    $PayItmObj->cost_center_id = $resStf[0]['last_cost_center_id'];
                    $PayItmObj->payment_type = 8;
                    if ($PayItmObj->Add() === false) {
                        $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطا ");
                        $unsuccess_count++;
                        continue;
                    }
                } else {
                    if (count($payRes) > 0) {
                        $qry = " select pay_value \n\t\t\t\t\t\t\t\t\tfrom hrms.payment_items \n\t\t\t\t\t\t\t\t\t\twhere pay_year = " . $PayYear . " and pay_month = " . $PayMonth . " and staff_id = " . $PaymentObj->staff_id . " and payment_type = " . $FileType;
                        $res = PdoDataAccess::runquery($qry);
                        $PayItmObj->pay_year = $PayYear;
                        $PayItmObj->pay_month = $PayMonth;
                        $PayItmObj->staff_id = $data->sheets[0]['cells'][$i][0];
                        $PayItmObj->pay_value = $missionValue + $res[0]['pay_value'];
                        $PayItmObj->payment_type = 8;
                        if ($PayItmObj->Edit() === false) {
                            $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطای بروز رسانی ");
                            $unsuccess_count++;
                            continue;
                        }
                    }
                }
            }
            // End for
            $log_obj->finalize();
            $st = preg_replace('/\\r\\n/', "", $log_obj->make_result("UploadPayFilesObj.expand();"));
            if ($unsuccess_count > 0) {
                $pdo->rollBack();
            } else {
                $pdo->commit();
            }
            echo "{success:true,data:'" . $st . "'}";
            die;
        }
    }
    //...................... بن غیر نقدی شش ماهه ........................
    if ($FileType == 4 || $FileType == 5) {
        $pdo = PdoDataAccess::getPdoObject();
        $pdo->beginTransaction();
        for ($i = 1; $i < $data->sheets[0]['numRows']; $i++) {
            $PaymentObj = new manage_payments();
            $PayItmObj = new manage_payment_items();
            if (!isset($data->sheets[0]['cells'][$i][0])) {
                break;
            }
            $query = " select staff_id , bank_id , account_no ,person_type , last_cost_center_id\n\t\t\t\t\t\t                from staff where staff_id =" . $data->sheets[0]['cells'][$i][0];
            $resStf = PdoDataAccess::runquery($query);
            if (count($resStf) == 0) {
                $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " شماره شناسایی معتبر نمی باشد.");
                $unsuccess_count++;
                continue;
            }
            if (!($resStf[0]['bank_id'] > 0)) {
                $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", "بانک فرد جهت پرداخت مشخص نمی باشد.");
                $unsuccess_count++;
                continue;
            }
            if (!($resStf[0]['account_no'] > 0)) {
                $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", "شماره حساب فرد جهت پرداخت مشخص نمی باشد.");
                $unsuccess_count++;
                continue;
            }
            if (!($resStf[0]['last_cost_center_id'] > 0)) {
                $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", "مرکز هزینه برای فرد مشخص نشده است.");
                $unsuccess_count++;
                continue;
            }
            //......... محاسبه بن نقدی............................
            $BonValue = !empty($data->sheets[0]['cells'][$i][1]) ? $data->sheets[0]['cells'][$i][1] : 0;
            $PaymentObj->staff_id = $data->sheets[0]['cells'][$i][0];
            $PaymentObj->pay_year = $PayYear;
            $PaymentObj->pay_month = $PayMonth;
            $PaymentObj->payment_type = $FileType;
            $PaymentObj->bank_id = $resStf[0]['bank_id'];
            $PaymentObj->account_no = $resStf[0]['account_no'];
            $PaymentObj->state = 1;
            /*if($resStf[0]['person_type'] == 10) 
            		{
            			$DB = "hrmr." ;
            		}
            		else 
            		{*/
            $DB = "hrmstotal.";
            //}
            //.....................................
            $qry = " select count(*) cn  \n\t\t\t\t\t\t\t\t\tfrom " . $DB . "payments \n\t\t\t\t\t\t\t\t\t\t\twhere pay_year = " . $PayYear . " and pay_month = " . $PayMonth . " and staff_id = " . $PaymentObj->staff_id . " and payment_type = " . $FileType;
            $payRes = PdoDataAccess::runquery($qry);
            if ($payRes[0]['cn'] == 0) {
                if ($PaymentObj->Add("", $DB) === false) {
                    $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطا 22");
                    $unsuccess_count++;
                    continue;
                }
                //............ مرکز هزینه .....................
                $PayItmObj->pay_year = $PayYear;
                $PayItmObj->pay_month = $PayMonth;
                $PayItmObj->staff_id = $data->sheets[0]['cells'][$i][0];
                $PayItmObj->salary_item_type_id = 9941;
                $PayItmObj->pay_value = $BonValue;
                $PayItmObj->cost_center_id = $resStf[0]['last_cost_center_id'];
                $PayItmObj->payment_type = $FileType;
                if ($PayItmObj->Add("", $DB) === false) {
                    $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطا 444");
                    $unsuccess_count++;
                    continue;
                }
            } else {
                if (count($payRes) > 0) {
                    $qry = " select pay_value \n\t\t\t\t\t\t\t\t\tfrom " . $DB . "payment_items \n\t\t\t\t\t\t\t\t\t\twhere pay_year = " . $PayYear . " and pay_month = " . $PayMonth . " and staff_id = " . $PaymentObj->staff_id . " and payment_type = " . $FileType;
                    $res = PdoDataAccess::runquery($qry);
                    $PayItmObj->pay_year = $PayYear;
                    $PayItmObj->pay_month = $PayMonth;
                    $PayItmObj->staff_id = $data->sheets[0]['cells'][$i][0];
                    $PayItmObj->pay_value = $BonValue + $res[0]['pay_value'];
                    $PayItmObj->payment_type = $FileType;
                    if ($PayItmObj->Edit("", $DB) === false) {
                        $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطای بروز رسانی ");
                        $unsuccess_count++;
                        continue;
                    }
                }
            }
        }
        // End for
        $log_obj->finalize();
        $st = preg_replace('/\\r\\n/', "", $log_obj->make_result("UploadPayFilesObj.expand();"));
        if ($unsuccess_count > 0) {
            $pdo->rollBack();
        } else {
            $pdo->commit();
        }
        echo "{success:true,data:'" . $st . "'}";
        die;
    }
    // محاسبه پرداخت تالیف و ویراستاری.............................
    if ($FileType == 12) {
        $pdo = PdoDataAccess::getPdoObject();
        $pdo->beginTransaction();
        for ($i = 1; $i < $data->sheets[0]['numRows']; $i++) {
            $PaymentObj = new manage_payments();
            $PayItmObj = new manage_payment_items();
            unset($TaxRes);
            if (!isset($data->sheets[0]['cells'][$i][0])) {
                break;
            }
            $query = " select staff_id , bank_id , account_no ,person_type ,last_cost_center_id\n\t\t\t\t\t\t                from staff where staff_id =" . $data->sheets[0]['cells'][$i][0];
            $resStf = PdoDataAccess::runquery($query);
            if (count($resStf) == 0) {
                $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " شماره شناسایی معتبر نمی باشد.");
                $unsuccess_count++;
                continue;
            }
            if (!($resStf[0]['bank_id'] > 0)) {
                $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", "بانک فرد جهت پرداخت مشخص نمی باشد.");
                $unsuccess_count++;
                continue;
            }
            if (!($resStf[0]['account_no'] > 0)) {
                $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", "شماره حساب فرد جهت پرداخت مشخص نمی باشد.");
                $unsuccess_count++;
                continue;
            }
            if (!($resStf[0]['last_cost_center_id'] > 0)) {
                $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", "آخرین مرکز هزینه فرد مشخص نشده است.");
                $unsuccess_count++;
                continue;
            }
            //.........محاسبه تالیف و ویراستاری...........................
            $TValue = !empty($data->sheets[0]['cells'][$i][1]) ? $data->sheets[0]['cells'][$i][1] : 0;
            $PaymentObj->staff_id = $data->sheets[0]['cells'][$i][0];
            $PaymentObj->pay_year = $PayYear;
            $PaymentObj->pay_month = $PayMonth;
            $PaymentObj->payment_type = $FileType;
            $PaymentObj->bank_id = $resStf[0]['bank_id'];
            $PaymentObj->account_no = $resStf[0]['account_no'];
            $PaymentObj->message = !empty($data->sheets[0]['cells'][$i][3]) ? $data->sheets[0]['cells'][$i][3] : 0;
            $PaymentObj->state = 1;
            //.....................................
            $qry = " select count(*) cn  \n\t\t\t\t\t\t\t\t\tfrom payments \n\t\t\t\t\t\t\t\t\t\t\twhere pay_year = " . $PayYear . " and pay_month = " . $PayMonth . " and \n\t\t\t\t\t\t\t\t\t\t\t\t  staff_id = " . $PaymentObj->staff_id . " and payment_type = " . $FileType;
            $payRes = PdoDataAccess::runquery($qry);
            if ($payRes[0]['cn'] == 0) {
                if ($PaymentObj->Add() === false) {
                    $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطا 22");
                    $unsuccess_count++;
                    continue;
                }
                //............ مرکز هزینه .....................
                $PayItmObj->pay_year = $PayYear;
                $PayItmObj->pay_month = $PayMonth;
                $PayItmObj->staff_id = $data->sheets[0]['cells'][$i][0];
                $PayItmObj->salary_item_type_id = 10389;
                $PayItmObj->pay_value = $TValue;
                $PayItmObj->get_value = 0;
                $PayItmObj->cost_center_id = $resStf[0]['last_cost_center_id'];
                $PayItmObj->payment_type = 12;
                if ($PayItmObj->Add() === false) {
                    $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطا 444");
                    $unsuccess_count++;
                    continue;
                }
                //.......................................... محاسبه مالیات ........................................
                if ($resStf[0]['person_type'] == 1 || $resStf[0]['person_type'] == 10) {
                    $TaxKey = 146;
                } elseif ($resStf[0]['person_type'] == 2) {
                    $TaxKey = 147;
                } elseif ($resStf[0]['person_type'] == 3) {
                    $TaxKey = 148;
                } elseif ($resStf[0]['person_type'] == 5) {
                    $TaxKey = 747;
                }
                if ($resStf[0]['person_type'] == 10) {
                    $TaxResVal = $TValue / 10;
                } else {
                    $TaxRes = process_tax($data->sheets[0]['cells'][$i][0], $TValue, $PayYear, $PayMonth);
                }
                $PayItmObj->pay_year = $PayYear;
                $PayItmObj->pay_month = $PayMonth;
                $PayItmObj->staff_id = $data->sheets[0]['cells'][$i][0];
                $PayItmObj->salary_item_type_id = $TaxKey;
                $PayItmObj->get_value = $resStf[0]['person_type'] == 10 ? $TaxResVal : $TaxRes['get_value'];
                $PayItmObj->pay_value = 0;
                $PayItmObj->cost_center_id = $resStf[0]['last_cost_center_id'];
                $PayItmObj->payment_type = 12;
                $PayItmObj->param1 = $resStf[0]['person_type'] == 10 ? 0 : $TaxRes['param1'];
                $PayItmObj->param3 = $resStf[0]['person_type'] == 10 ? 0 : $TaxRes['param3'];
                $PayItmObj->param4 = 1;
                $PayItmObj->param5 = $resStf[0]['person_type'] == 10 ? 0 : $TaxRes['param5'];
                if ($PayItmObj->Add() === false) {
                    $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطا 444");
                    $unsuccess_count++;
                    continue;
                }
                //...................افزودن مبلغ علی الحساب.....................
                if (!empty($data->sheets[0]['cells'][$i][2]) && $data->sheets[0]['cells'][$i][2] > 0) {
                    $PayItmObj->pay_year = $PayYear;
                    $PayItmObj->pay_month = $PayMonth;
                    $PayItmObj->staff_id = $data->sheets[0]['cells'][$i][0];
                    $PayItmObj->salary_item_type_id = 4600;
                    $PayItmObj->get_value = $data->sheets[0]['cells'][$i][2];
                    $PayItmObj->pay_value = 0;
                    $PayItmObj->cost_center_id = $resStf[0]['last_cost_center_id'];
                    $PayItmObj->payment_type = 12;
                    $PayItmObj->param1 = 0;
                    $PayItmObj->param2 = 0;
                    $PayItmObj->param3 = 0;
                    $PayItmObj->param4 = 2;
                    $PayItmObj->param5 = 0;
                    if ($PayItmObj->Add() === false) {
                        $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطا 444");
                        $unsuccess_count++;
                        continue;
                    }
                }
            }
        }
        // End for
        $log_obj->finalize();
        $st = preg_replace('/\\r\\n/', "", $log_obj->make_result("UploadPayFilesObj.expand();"));
        if ($unsuccess_count > 0) {
            $pdo->rollBack();
        } else {
            $pdo->commit();
        }
        echo "{success:true,data:'" . $st . "'}";
        die;
    }
    //......... محاسبه حق التدریس..................................
    if ($FileType == 14) {
        $pdo = PdoDataAccess::getPdoObject();
        $pdo->beginTransaction();
        for ($i = 1; $i < $data->sheets[0]['numRows']; $i++) {
            $PaymentObj = new manage_payments();
            $PayItmObj = new manage_payment_items();
            if (!isset($data->sheets[0]['cells'][$i][0])) {
                break;
            }
            $query = " select staff_id , bank_id , account_no ,person_type ,last_cost_center_id\n\t\t\t\t\t\t                from staff where staff_id =" . $data->sheets[0]['cells'][$i][0] . " AND person_type in (1,10) ";
            $resStf = PdoDataAccess::runquery($query);
            if (count($resStf) == 0) {
                $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " شماره شناسایی معتبر نمی باشد.");
                $unsuccess_count++;
                continue;
            }
            if (!($resStf[0]['bank_id'] > 0)) {
                $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", "بانک فرد جهت پرداخت مشخص نمی باشد.");
                $unsuccess_count++;
                continue;
            }
            if (!($resStf[0]['account_no'] > 0)) {
                $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", "شماره حساب فرد جهت پرداخت مشخص نمی باشد.");
                $unsuccess_count++;
                continue;
            }
            if (!($resStf[0]['last_cost_center_id'] > 0)) {
                $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", "آخرین مرکز هزینه فرد مشخص نشده است.");
                $unsuccess_count++;
                continue;
            }
            //............................. محاسبه مبلغ حق التدریس................
            $TValue = !empty($data->sheets[0]['cells'][$i][1]) ? $data->sheets[0]['cells'][$i][1] : 0;
            $PaymentObj->staff_id = $data->sheets[0]['cells'][$i][0];
            $PaymentObj->pay_year = $PayYear;
            $PaymentObj->pay_month = $PayMonth;
            $PaymentObj->payment_type = $FileType;
            $PaymentObj->writ_id = !empty($data->sheets[0]['cells'][$i][2]) ? $data->sheets[0]['cells'][$i][2] : 0;
            $PaymentObj->writ_ver = !empty($data->sheets[0]['cells'][$i][3]) ? $data->sheets[0]['cells'][$i][3] : 0;
            $PaymentObj->bank_id = $resStf[0]['bank_id'];
            $PaymentObj->account_no = $resStf[0]['account_no'];
            $PaymentObj->message = !empty($data->sheets[0]['cells'][$i][5]) ? $data->sheets[0]['cells'][$i][5] : 0;
            $PaymentObj->state = 1;
            //.....................................
            $qry = " select count(*) cn  \n\t\t\t\t\t\t\t\t\tfrom payments \n\t\t\t\t\t\t\t\t\t\t\twhere pay_year = " . $PayYear . " and pay_month = " . $PayMonth . " and \n\t\t\t\t\t\t\t\t\t\t\t\t  staff_id = " . $PaymentObj->staff_id . " and payment_type = " . $FileType;
            $payRes = PdoDataAccess::runquery($qry);
            if ($payRes[0]['cn'] == 0) {
                if ($PaymentObj->Add() === false) {
                    $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطا 22");
                    $unsuccess_count++;
                    continue;
                }
                //............ مرکز هزینه .....................
                $PayItmObj->pay_year = $PayYear;
                $PayItmObj->pay_month = $PayMonth;
                $PayItmObj->staff_id = $data->sheets[0]['cells'][$i][0];
                $PayItmObj->salary_item_type_id = 40;
                // کد قلم مربوط به حق التدریس
                $PayItmObj->pay_value = $TValue;
                $PayItmObj->cost_center_id = $resStf[0]['last_cost_center_id'];
                $PayItmObj->payment_type = 14;
                if ($PayItmObj->Add() === false) {
                    $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطا 444");
                    $unsuccess_count++;
                    continue;
                }
                //.......................................... محاسبه مالیات ........................................
                if ($resStf[0]['person_type'] == 1) {
                    $TaxKey = 146;
                } elseif ($resStf[0]['person_type'] == 2) {
                    $TaxKey = 147;
                } elseif ($resStf[0]['person_type'] == 3) {
                    $TaxKey = 148;
                } elseif ($resStf[0]['person_type'] == 5) {
                    $TaxKey = 747;
                } elseif ($resStf[0]['person_type'] == 10) {
                    $TaxKey = 146;
                }
                //.............. تعدیل مالیات با توجه به بازه مرتبط با ترم ................................
                // $TaxRes = process_tax_normalize($data->sheets[0]['cells'][$i][0] , $TValue ,$PayYear ,$PayMonth ) ;
                /*اين فرد مشمول ماليات نمي باشد*/
                $SDate = $PayYear . "/" . $PayMonth . "/01";
                if ($PayMonth < 7) {
                    $endDay = "31";
                } elseif ($PayMonth > 6 && $PayMonth < 12) {
                    $endDay = "30 ";
                } elseif ($PayMonth == 12) {
                    $endDay = "29";
                }
                $EDate = $PayYear . "/" . $PayMonth . "/" . $endDay;
                $EDate = DateModules::shamsi_to_miladi($EDate);
                $SDate = DateModules::shamsi_to_miladi($SDate);
                $staffID = $data->sheets[0]['cells'][$i][0];
                $qry = " select tax_include\n\t\t\t\t\t\t\t\t\tfrom staff_include_history\n\t\t\t\t\t\t\t\t\t\twhere staff_id = " . $staffID . " and start_date <= '" . $EDate . "' AND\n\t\t\t\t\t\t\t\t\t\t\t (end_date IS NULL OR end_date = '0000-00-00' OR\n\t\t\t\t\t\t\t\t\t\t\t  end_date >= '" . $EDate . "' OR end_date > '" . $SDate . "' ) ";
                $res = PdoDataAccess::runquery($qry);
                if ($res[0]['tax_include'] == 0) {
                    $TaxRes = 0;
                } else {
                    $TaxRes = $TValue * 10 / 100;
                }
                $PayItmObj->pay_year = $PayYear;
                $PayItmObj->pay_month = $PayMonth;
                $PayItmObj->staff_id = $data->sheets[0]['cells'][$i][0];
                $PayItmObj->salary_item_type_id = $TaxKey;
                $PayItmObj->get_value = $TaxRes;
                //$TaxRes['get_value'] ;
                $PayItmObj->pay_value = 0;
                $PayItmObj->cost_center_id = $resStf[0]['last_cost_center_id'];
                $PayItmObj->payment_type = 14;
                $PayItmObj->param1 = $TValue;
                //$TaxRes['param1'] ;
                $PayItmObj->param2 = 0;
                //$TaxRes['param2'] ;
                $PayItmObj->param3 = 0;
                //$TaxRes['param3'] ;
                $PayItmObj->param4 = 2;
                $PayItmObj->param5 = 0;
                //$TaxRes['param5'] ;
                if ($TaxRes > 0) {
                    if ($PayItmObj->Add() === false) {
                        $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطا 444");
                        $unsuccess_count++;
                        continue;
                    }
                }
                //...................افزودن مبلغ علی الحساب.....................
                if (!empty($data->sheets[0]['cells'][$i][4]) && $data->sheets[0]['cells'][$i][4] > 0) {
                    $PayItmObj->pay_year = $PayYear;
                    $PayItmObj->pay_month = $PayMonth;
                    $PayItmObj->staff_id = $data->sheets[0]['cells'][$i][0];
                    $PayItmObj->salary_item_type_id = 4600;
                    $PayItmObj->get_value = $data->sheets[0]['cells'][$i][4];
                    $PayItmObj->pay_value = 0;
                    $PayItmObj->cost_center_id = $resStf[0]['last_cost_center_id'];
                    $PayItmObj->payment_type = 14;
                    $PayItmObj->param1 = 0;
                    $PayItmObj->param2 = 0;
                    $PayItmObj->param3 = 0;
                    $PayItmObj->param4 = 2;
                    $PayItmObj->param5 = 0;
                    if ($PayItmObj->Add() === false) {
                        $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " خطا 444");
                        $unsuccess_count++;
                        continue;
                    }
                }
            }
        }
        // End for
        $log_obj->finalize();
        $st = preg_replace('/\\r\\n/', "", $log_obj->make_result("UploadPayFilesObj.expand();"));
        if ($unsuccess_count > 0) {
            $pdo->rollBack();
        } else {
            $pdo->commit();
        }
        echo "{success:true,data:'" . $st . "'}";
        die;
    }
    //.........محاسبه عیدی و پاداش..........................................
    if ($FileType == 2) {
        $pdo = PdoDataAccess::getPdoObject();
        $pdo->beginTransaction();
        //.........................محاسبه کارکرد سالانه...................
        $year_fdate = DateModules::shamsi_to_miladi($PayYear . "/01/01");
        $year_edate = DateModules::shamsi_to_miladi($PayYear + 1 . "/01/01");
        $year_fdate = str_replace("/", "-", $year_fdate);
        $year_edate = str_replace("/", "-", $year_edate);
        PdoDataAccess::runquery('DROP TABLE IF EXISTS temp_work_writs;');
        PdoDataAccess::runquery('
								CREATE TABLE temp_work_writs  AS
								SELECT w.staff_id,										
									CASE WHEN w.emp_mode IN (3,8,9,15,7,16,11,12,14,20,22,25,27,28,29) 
										THEN 0 
										WHEN  w.emp_mode IN ( ' . EMP_MODE_LEAVE_WITH_SALARY . ' ) THEN 1
										ELSE (CASE w.annual_effect
														WHEN 1 THEN 1
														WHEN 2 THEN 0.5
														WHEN 3 THEN 0
														WHEN 4 THEN 2
											END) END annual_coef,
									CASE 
										WHEN w.execute_date < \'' . $year_fdate . '\' THEN \'' . $year_fdate . '\'
										ELSE w.execute_date
									END execute_date,
									CASE
										WHEN ( SELECT MIN(w2.execute_date) execute_date
												FROM writs w2
												WHERE w2.execute_date <= \'' . $year_edate . '\' AND
														w2.staff_id = w.staff_id AND
														w2.history_only = 0 AND
														w2.state = ' . WRIT_SALARY . ' AND
														(w2.execute_date > w.execute_date OR
														(w2.execute_date = w.execute_date AND w2.writ_id > w.writ_id) OR
														(w2.execute_date = w.execute_date AND w2.writ_id = w.writ_id AND w2.writ_ver > w.writ_ver))
												GROUP BY staff_id) IS NULL THEN \'' . $year_edate . '\'
										ELSE ( SELECT MIN(w2.execute_date) execute_date
												FROM writs w2
												WHERE   w2.execute_date <= \'' . $year_edate . '\' AND
														w2.staff_id = w.staff_id AND
														w2.history_only = 0 AND
														w2.state = ' . WRIT_SALARY . ' AND
														(w2.execute_date > w.execute_date OR
														(w2.execute_date = w.execute_date AND w2.writ_id > w.writ_id) OR
														(w2.execute_date = w.execute_date AND w2.writ_id = w.writ_id AND w2.writ_ver > w.writ_ver))
												GROUP BY staff_id)
											END end_date,
									w.person_type
								FROM writs w
								WHERE w.history_only = 0 AND
									w.state = ' . WRIT_SALARY . ' AND
									( \'' . $year_edate . '\' >= w.execute_date OR w.execute_date IS NULL OR w.execute_date = \'0000-00-00\') 								
							');
        PdoDataAccess::runquery('ALTER TABLE temp_work_writs ADD INDEX(staff_id)');
        PdoDataAccess::runquery('DROP TABLE IF EXISTS temp_last_salary_writs;');
        PdoDataAccess::runquery('CREATE  TABLE temp_last_salary_writs  AS
									SELECT w.staff_id,
										SUBSTRING_INDEX(SUBSTRING( MAX( CONCAT(w.execute_date,w.writ_id,\'.\',w.writ_ver) ),11) ,\'.\',1) writ_id,
										SUBSTRING_INDEX(MAX( CONCAT(w.execute_date,w.writ_id,\'.\',w.writ_ver) ) ,\'.\',-1) writ_ver
									FROM writs w
									WHERE w.state = ' . WRIT_SALARY . ' AND
										w.history_only = 0  AND if(w.person_type = 3 , w.emp_mode not in ( 3,8,9,15,7,16,11,12,14,20,22) , (1=1)) 										 
									GROUP BY w.staff_id;');
        PdoDataAccess::runquery('ALTER TABLE temp_last_salary_writs ADD INDEX(staff_id,writ_id,writ_ver);');
        PdoDataAccess::runquery("SET NAMES 'utf8'");
        $WritWrk_DT = PdoDataAccess::runquery_fetchMode(' SELECT  w.staff_id,
														p.plname,
														p.pfname,
														w.person_type,
														w.cost_center_id,
														tlw.writ_id  last_writ_id,
														tlw.writ_ver last_writ_ver,
														s.bank_id,
														s.account_no,														
														si.tax_include,
														pay.staff_id as before_calced,
														( SELECT tax_table_type_id
														FROM staff_tax_history sth
														WHERE sth.staff_id = w.staff_id
														ORDER BY start_date DESC
														LIMIT 1
														) as tax_table_type_id,
														( SELECT SUM(wsi.value)
														FROM writ_salary_items wsi
														WHERE wsi.writ_id = w.writ_id AND
																wsi.writ_ver = w.writ_ver AND
																wsi.salary_item_type_id IN(' . SIT_WORKER_BASE_SALARY . ',' . SIT_WORKER_ANNUAL_INC . ') AND
																w.person_type = ' . HR_WORKER . ' AND
																w.state = ' . WRIT_SALARY . '
														) as worker_base_salary,
														SUM(DATEDIFF(tw.end_date,tw.execute_date) * tw.annual_coef) work_time
												FROM    temp_work_writs tw
														INNER JOIN staff s
															ON(tw.staff_id = s.staff_id)
														INNER JOIN staff_include_history si
															ON(s.staff_id = si.staff_id AND si.start_date <= \'' . $year_edate . '\' AND (si.end_date IS NULL OR si.end_date = \'0000-00-00\' OR si.end_date >= \'' . $year_edate . '\') )
														INNER JOIN persons p
															ON(s.PersonID = p.PersonID)
														INNER JOIN temp_last_salary_writs tlw
															ON(s.staff_id = tlw.staff_id)
														INNER JOIN writs w
															ON(tlw.staff_id = w.staff_id AND tlw.writ_id = w.writ_id AND tlw.writ_ver = w.writ_ver AND
															(w.person_type = ' . HR_WORKER . ' OR w.emp_mode <> ' . EMP_MODE_RETIRE . ') )
														LEFT OUTER JOIN payments pay
															ON(pay.pay_year = ' . $PayYear . ' AND pay.pay_month=12 AND pay.payment_type= ' . HANDSEL_PAYMENT . ' AND pay.staff_id = s.staff_id)
														
												WHERE   s.staff_id not in (1085919 , 25 , 29 , 1086493 , 1085766 , 1086203 , 1086272 , 1085025 ,2003012 ,1081975) AND tw.end_date > \'' . $year_fdate . '\' 
												GROUP BY w.staff_id,
														p.plname,
														p.pfname,
														w.person_type,
														w.cost_center_id,
														tlw.writ_id,
														tlw.writ_ver,
														s.bank_id,
														s.account_no,
														s.tafsili_id,
														pay.staff_id     having work_time > 0  ');
        //	echo PdoDataAccess::GetLatestQueryString(); die();
        $count = $WritWrk_DT->rowCount();
        //$WritWrkRes
        //.....................................................................
        if (DateModules::YearIsLeap($PayYear)) {
            $Month12Leng = 30;
        } else {
            $Month12Leng = 29;
        }
        //..............................انتقال پارامترهای حقوقی به یک آرایه .............
        exe_param_sql($PayYear, 12, $salaryParam);
        //........................................انتقال داده های جداول مالیاتی به یک آرایه ......................................
        exe_taxtable_sql($PayYear, 12, $taxTable);
        //......................................................................
        for ($i = 0; $i < $count; $i++) {
            $WritWrkRes = $WritWrk_DT->fetch();
            $PaymentObj = new manage_payments();
            $PayItmObj = new manage_payment_items();
            //................... اعمال کنترل..................................
            if ($WritWrkRes['cost_center_id'] == NULL) {
                $log_obj->make_unsuccess_rows($WritWrkRes['staff_id'], "-", "براي اين شخص مرکز هزينه مشخص نشده است.");
                $unsuccess_count++;
                continue;
            }
            if ($WritWrkRes['tax_table_type_id'] == NULL) {
                $log_obj->make_unsuccess_rows($WritWrkRes['staff_id'], "-", "براي اين شخص جدول مالياتي مشخص نشده است.");
                $unsuccess_count++;
                continue;
            }
            if ($WritWrkRes['before_calced'] > 0) {
                $log_obj->make_unsuccess_rows($WritWrkRes['staff_id'], "-", "محاسبه عيدي و پاداش اين شخص قبلا انجام شده است.");
                $unsuccess_count++;
                continue;
            }
            if (empty($taxTable[$WritWrkRes['tax_table_type_id']])) {
                $log_obj->make_unsuccess_rows($WritWrkRes['staff_id'], "-", " جدول مالیاتی برای فرد ناقص تعریف شده است.");
                $unsuccess_count++;
                continue;
            }
            if ($WritWrkRes['work_time'] == 0) {
                continue;
            }
            //.....................
            if ($WritWrkRes['staff_id'] == 2002664) {
                $WritWrkRes['work_time'] = 365;
            }
            if ($WritWrkRes['staff_id'] == 2002612) {
                $WritWrkRes['work_time'] = 365;
            }
            if ($WritWrkRes['staff_id'] == 2002561) {
                $WritWrkRes['work_time'] = 365;
            }
            if ($WritWrkRes['staff_id'] == 2003053 || $WritWrkRes['staff_id'] == 2002691) {
                $WritWrkRes['work_time'] = 365;
            }
            //..........................
            //................................محاسبه عیدی و پاداش با توجه به کارکرد فرد در طول سال................................
            $value = 0;
            if (DateModules::YearIsLeap($PayYear)) {
                $year_length = 366;
            } else {
                $year_length = 365;
            }
            if ($WritWrkRes['person_type'] == HR_WORKER) {
                if ($WritWrkRes['worker_base_salary'] * 2 > $salaryParam[SPT_JOB_SALARY][1] * 30 * 3) {
                    $value = $salaryParam[SPT_JOB_SALARY][1] * 30 * 3;
                } else {
                    $value = $WritWrkRes['worker_base_salary'] * 2;
                }
                $value *= $WritWrkRes['work_time'] / $year_length;
                $param2 = $salaryParam[SPT_JOB_SALARY][1];
            } else {
                $value = $WritWrkRes['work_time'] / $year_length * $salaryParam[SPT_HANDSEL_VALUE][0];
                $param2 = $salaryParam[SPT_HANDSEL_VALUE][0];
            }
            if ($WritWrkRes['person_type'] == HR_EMPLOYEE) {
                $key = 164;
            } elseif ($WritWrkRes['person_type'] == HR_PROFESSOR) {
                $key = 163;
            } elseif ($WritWrkRes['person_type'] == HR_WORKER) {
                $key = 165;
            } elseif ($WritWrkRes['person_type'] == HR_CONTRACT) {
                $key = 764;
            }
            $PaymentObj->staff_id = $WritWrkRes['staff_id'];
            $PaymentObj->pay_year = $PayYear;
            $PaymentObj->pay_month = 12;
            $PaymentObj->payment_type = $FileType;
            $PaymentObj->writ_id = $WritWrkRes['last_writ_id'];
            $PaymentObj->writ_ver = $WritWrkRes['last_writ_ver'];
            $PaymentObj->bank_id = $WritWrkRes['bank_id'];
            $PaymentObj->account_no = $WritWrkRes['account_no'];
            $PaymentObj->state = 1;
            if ($PaymentObj->Add() === false) {
                $log_obj->make_unsuccess_rows($WritWrkRes['staff_id'], "-", " خطا در ثبت جدول پرداخت");
                $unsuccess_count++;
                continue;
            }
            $PayItmObj->pay_year = $PayYear;
            $PayItmObj->pay_month = 12;
            $PayItmObj->staff_id = $WritWrkRes['staff_id'];
            $PayItmObj->salary_item_type_id = $key;
            $PayItmObj->pay_value = $value;
            $PayItmObj->get_value = 0;
            $PayItmObj->param1 = $WritWrkRes['work_time'];
            $PayItmObj->param2 = $param2;
            $PayItmObj->cost_center_id = $WritWrkRes['cost_center_id'];
            $PayItmObj->payment_type = HANDSEL_PAYMENT;
            if ($PayItmObj->Add() === false) {
                $log_obj->make_unsuccess_rows($WritWrkRes['staff_id'], "-", "خطا در ثبت اقلام پرداختی");
                $unsuccess_count++;
                continue;
            }
            //..........................محاسبه مالیات مربوط به عیدی و پاداش ...................
            if (empty($WritWrkRes['tax_include'])) {
                continue;
            }
            $handsel_key = $key;
            if ($WritWrkRes['person_type'] == 1) {
                $TaxKey = 146;
            } elseif ($WritWrkRes['person_type'] == 2) {
                $TaxKey = 147;
            } elseif ($WritWrkRes['person_type'] == 3) {
                $TaxKey = 148;
            } elseif ($WritWrkRes['person_type'] == 5) {
                $TaxKey = 747;
            }
            $handsel_value = $value;
            $tax = 0;
            //متغيري جهت نگهداري ماليات
            reset($taxTable);
            foreach ($taxTable[$WritWrkRes['tax_table_type_id']] as $tax_table_row) {
                $pay_mid_month_date = DateModules::shamsi_to_miladi($PayYear . "/12/15");
                if (DateModules::CompareDate($pay_mid_month_date, $tax_table_row['from_date']) != -1 && DateModules::CompareDate($pay_mid_month_date, $tax_table_row['to_date']) != 1) {
                    if ($handsel_value >= $tax_table_row['from_value'] && $handsel_value <= $tax_table_row['to_value']) {
                        $tax += ($handsel_value - $tax_table_row['from_value']) * $tax_table_row['coeficient'];
                    } else {
                        if ($handsel_value > $tax_table_row['to_value']) {
                            $tax += ($tax_table_row['to_value'] - $tax_table_row['from_value']) * $tax_table_row['coeficient'];
                        }
                    }
                }
            }
            if ($tax > 0) {
                $PayItmObj->pay_year = $PayYear;
                $PayItmObj->pay_month = 12;
                $PayItmObj->staff_id = $WritWrkRes['staff_id'];
                $PayItmObj->salary_item_type_id = $TaxKey;
                $PayItmObj->pay_value = 0;
                $PayItmObj->get_value = $tax;
                $PayItmObj->param1 = $handsel_value;
                $PayItmObj->param2 = $WritWrkRes['tax_table_type_id'];
                $PayItmObj->cost_center_id = $WritWrkRes['cost_center_id'];
                $PayItmObj->payment_type = HANDSEL_PAYMENT;
                if ($PayItmObj->Add() === false) {
                    $log_obj->make_unsuccess_rows($WritWrkRes['staff_id'], "-", "خطا در ثبت اقلام پرداختی");
                    $unsuccess_count++;
                    continue;
                }
            }
        }
        //End For
        $log_obj->finalize();
        $st = preg_replace('/\\r\\n/', "", $log_obj->make_result("UploadPayFilesObj.expand();"));
        if ($unsuccess_count > 0) {
            $pdo->rollBack();
        } else {
            $pdo->commit();
        }
        echo "{success:true,data:'" . $st . "'}";
        die;
    }
    if ($FileType == 7) {
        //echo "*ererer**" ; die();
        $pdo = PdoDataAccess::getPdoObject();
        $pdo->beginTransaction();
        for ($i = 1; $i < $data->sheets[0]['numRows']; $i++) {
            $query = " select staff_id , PersonID\n\t\t\t\t\t\t\t\t\t\t\tfrom staff where staff_id =" . $data->sheets[0]['cells'][$i][0];
            $resStf = PdoDataAccess::runquery($query);
            //echo PdoDataAccess::GetLatestQueryString() ; die();
            if (count($resStf) == 0) {
                $log_obj->make_unsuccess_rows($data->sheets[0]['cells'][$i][0], "-", " شماره شناسایی معتبر نمی باشد.");
                $unsuccess_count++;
                continue;
            }
            $query = " insert into person_subtracts (PersonID ,  subtract_type ,  first_value , instalment,\n\t\t\t\t\t\t\t\t\t\t\t remainder ,  start_date ,  end_date ,  salary_item_type_id , \n\t\t\t\t\t\t\t\t\t\t\t reg_date )  values (" . $resStf[0]['PersonID'] . " , 3 , \n\t\t\t\t\t\t\t\t\t\t\t\t                 " . $data->sheets[0]['cells'][$i][1] . ",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t " . $data->sheets[0]['cells'][$i][1] . ",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t " . $data->sheets[0]['cells'][$i][1] . ",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t '2015-02-20' ,'2015-03-20' , 9945 , '2015-03-15' ) ";
            //echo $query ; die();
            PdoDataAccess::runquery($query);
            //echo PdoDataAccess::GetLatestQueryString() ; die();
        }
        $log_obj->finalize();
        $st = preg_replace('/\\r\\n/', "", $log_obj->make_result("UploadPayFilesObj.expand();"));
        if ($unsuccess_count > 0) {
            $pdo->rollBack();
        } else {
            $pdo->commit();
        }
        echo "{success:true,data:'" . $st . "'}";
        die;
    }
}
示例#5
0
            $d = round($total - $y * 365.25 - $m * 30.4375);
            $history .= "<td align=right colspan=3>سنوات غير قابل قبول : " . $y . " سال و " . $m . " ماه و " . $d . " روز" . "</td></tr>";
            //----------------------------------------------
            $tags = array('<!--history-->' => $history);
            $content = str_replace(array_keys($tags), array_values($tags), $content);
            echo $content;
            if (!isset($data[$i])) {
                break;
            }
            echo "<div class='pageBreak'></div>";
        }
        $prof1 = $prof2 = "";
        if ($data[$i][person_type] == HR_PROFESSOR) {
            $prof1 = '<tr><td style="background-color:#F0F3FF">مرتبه :</td><td style="font-weight:bold">' . $data[$i][science_level_title] . '</td>
						  <td style="background-color:#F0F3FF">پايه :</td><td style="font-weight:bold">' . $data[$i][base] . '</td></tr>';
            if ($data[$i][exe_to_date] == "" || $data[$i][exe_to_date] == "0000-00-00" || DateModules::CompareDate($data[$i][exe_to_date], DateModules::Now()) > 0) {
                $prof2 = '<tr><td style="background-color:#F0F3FF">سمت اجرايي :</td><td style="font-weight:bold">' . $data[$i][exe_post_title] . '</td>
							  <td style="background-color:#F0F3FF">تاريخ سمت اجرايي :</td><td style="font-weight:bold">' . DateModules::miladi_to_shamsi($data[$i][exe_from_date]) . '</td></tr>';
            } else {
                $prof2 = '<tr><td style="background-color:#F0F3FF">سمت اجرايي :</td><td style="font-weight:bold"></td>
							  <td style="background-color:#F0F3FF">تاريخ سمت اجرايي :</td><td style="font-weight:bold"></td></tr>';
            }
        }
        $tags = array('<!--post_title-->' => $data[$i][person_type] == HR_WORKER ? 'عنوان شغل' : 'عنوان پست', '<!--fname-->' => $data[$i][pfname], '<!--lname-->' => $data[$i][plname], '<!--father_name-->' => $data[$i][father_name], '<!--staff_id-->' => $data[$i][staff_id], '<!--birth_date-->' => DateModules::miladi_to_shamsi($data[$i][birth_date]), '<!--birth_place-->' => $data[$i][birth_place], '<!--idcard_no-->' => $data[$i][idcard_no], '<!--national_code-->' => $data[$i][national_code], '<!--prof1-->' => $prof1, '<!--worktime_type-->' => $data[$i][worktime_type_title], '<!--military_type-->' => $data[$i][military_type_title], '<!--education_level-->' => $data[$i][education_level_title], '<!--field_title-->' => $data[$i][sf_sb_title], '<!--doc_date-->' => DateModules::miladi_to_shamsi($data[$i][doc_date]), '<!--studyPlace-->' => $data[$i][study_palce], '<!--razm-->' => $data[$i][razmAmount], '<!--janbaz-->' => $data[$i][janbazAmount], '<!--unit-->' => $data[$i][unitName], '<!--emp_state-->' => $data[$i][emp_state_title], '<!--post_no-->' => $data[$i][post_no], '<!--last_post_title-->' => $data[$i][post_title], '<!--prof2-->' => $prof2, '<!--now-->' => DateModules::shNow());
        // مشخص کردن فایل template  مربوط به خلاصه پرونده
        $content = file_get_contents("../../reports/summary_doc.htm");
        $content = str_replace(array_keys($tags), array_values($tags), $content);
        $cur_staff = $data[$i][staff_id];
        $index = $i;
        $row_index = $i;
        $history = "";
示例#6
0
	private function compute_salary_item2_13($writ_rec) {

		//param1 : ضريب فوق العاده جذب : input
		//param2 : مضروب فيه (حقوق مبنا + افزايش سنواتي + فوق العاده شغل +  + حداقل دريافتي + فوق العاده شغل برجسته )

		if (in_array($writ_rec['person_type'], array(1, 2, 3))) {
			$this->param2 = manage_writ_item::compute_writ_items_sum($writ_rec["writ_id"], $writ_rec["writ_ver"], $writ_rec["staff_id"], '( ' . SIT_STAFF_BASE_SALARY . ' , ' . SIT_STAFF_ANNUAL_INC . ' , ' .
							SIT_STAFF_JOB_EXTRA . ' , ' . SIT_STAFF_DOMINANT_JOB_EXTRA . ' , ' .
							SIT_STAFF_MIN_PAY . ' , ' . SIT_STAFF_ADAPTION_DIFFERENCE . ',' .
							SIT_STAFF_DEVOTION_ANNUAL_INC . ')');
		}
		// //از تاريخ 1/1/85 به بعد روش محاسبه اين قلم تغيير كرده است
		elseif (in_array($writ_rec['person_type'], array(5, 6)) &&
				DateModules::CompareDate($writ_rec['execute_date'], '2006-03-21') == -1) {
			//حقوق مبنا + افزايش سنواتي + حداقل دريافتي +
			//فوق العاده شغل + فوق العاده شغل برجسته
			$this->param2 = manage_writ_item::compute_writ_items_sum(
							$writ_rec["writ_id"], $writ_rec["writ_ver"], $writ_rec["staff_id"], '( ' . SIT5_STAFF_BASE_SALARY . ' , ' . SIT5_STAFF_ANNUAL_INC . ' , ' .
							SIT5_STAFF_JOB_EXTRA . ' , ' . SIT5_STAFF_DOMINANT_JOB_EXTRA . ' , ' .
							SIT5_STAFF_MIN_PAY . ' )');
		} elseif (in_array($writ_rec['person_type'], array(5, 6)) &&
				DateModules::CompareDate($writ_rec['execute_date'], '2006-03-21') != -1) {
			//(حقوق مبنا + افزايش سنواتي + فوق العاده شغل +  حداقل دريافتي
			//+ فوق العاده شغل برجسته + تفاوت تطبيق + تفاوت همترازي)
			$this->param2 = manage_writ_item::compute_writ_items_sum($writ_rec['writ_id'], $writ_rec['writ_ver'], $writ_rec['staff_id'], '( ' . SIT5_STAFF_BASE_SALARY . ' , ' . SIT5_STAFF_ANNUAL_INC . ' , ' .
							SIT5_STAFF_JOB_EXTRA . ' , ' . SIT5_STAFF_DOMINANT_JOB_EXTRA . ' , ' .
							SIT5_STAFF_MIN_PAY . ' , ' . SIT5_STAFF_ADAPTION_DIFFERENCE . ')');
		}
		//چون به کساني که تفاوت تطبيق مي گيرند حداقل دريافتي تعلق نمي گيرد
		//بنابراين جمع چهار قلم
		//حقوق مبنا + افزايش سنواتي + فوق العاده شغل + فوق العاده شغل برجسته
		//ممکن است از حداقل حقوق کمترشود که در اين موارد بايد از حداقل حقوق استفاده شود.

		$min_salary = manage_salary_params::get_salaryParam_value("", $writ_rec["person_type"].",101", SPT_MIN_SALARY, $writ_rec['execute_date']);

		if ($this->param2 < $min_salary)
			$this->param2 = $min_salary;

		$value = $this->param1 * $this->param2;
		if (!($value > 0)) {
			parent::PushException(ABSORB_ITEM_CALC_ERR);
			return 0;
		}
		return $value;
	}
 private function get_retired_coef()
 {
     $coefficient = 1;
     //init
     if ($this->staffRow['last_retired_pay'] != NULL && $this->staffRow['last_retired_pay'] != '0000-00-00' && DateModules::CompareDate($this->staffRow['last_retired_pay'], $this->month_start) == -1) {
         $coefficient = 0;
     } elseif ($this->staffRow['last_retired_pay'] != NULL && $this->staffRow['last_retired_pay'] != '0000-00-00' && DateModules::CompareDate($this->staffRow['last_retired_pay'], $this->month_end) != 1) {
         $coefficient = (round(DateModules::GDateMinusGDate($this->staffRow['last_retired_pay'], $this->month_start)) + 1) / $this->__MONTH_LENGTH;
     }
     return $coefficient;
 }
示例#8
0
                if ($valid_writs[$k][all_annual_effect] == "3") {
                    $total_non_year += $year;
                    $total_non_month += $month;
                    $total_non_day += $day;
                } else {
                    $total_year += $year;
                    $total_month += $month;
                    $total_day += $day;
                }
            }
            //......................................
            $prof1 = $prof2 = "";
            if ($valid_writs[$k - 1][person_type] == HR_PROFESSOR) {
                $prof1 = '<tr><td style="background-color:#F0F3FF">مرتبه :</td><td style="font-weight:bold">' . $valid_writs[$k - 1][science_level_title] . '</td>
						  <td style="background-color:#F0F3FF">پايه :</td><td style="font-weight:bold">' . $valid_writs[$k - 1][base] . '</td></tr>';
                if ($valid_writs[$k - 1][exe_to_date] == "" || $valid_writs[$k - 1][exe_to_date] == "0000-00-00" || DateModules::CompareDate($valid_writs[$k - 1][exe_to_date], DateModules::Now()) > 0) {
                    $prof2 = '<tr><td style="background-color:#F0F3FF">سمت اجرايي :</td><td style="font-weight:bold">' . $valid_writs[$k - 1][exe_post_title] . '</td>
							  <td style="background-color:#F0F3FF">تاريخ سمت اجرايي :</td><td style="font-weight:bold">' . DateModules::miladi_to_shamsi($valid_writs[$k - 1][exe_from_date]) . '</td></tr>';
                } else {
                    $prof2 = '<tr><td style="background-color:#F0F3FF">سمت اجرايي :</td><td style="font-weight:bold"></td>
							  <td style="background-color:#F0F3FF">تاريخ سمت اجرايي :</td><td style="font-weight:bold"></td></tr>';
                }
            }
            $ptitle = "";
            if ($valid_writs[$k - 1][person_type] == HR_WORKER) {
                $ptitle = 'عنوان شغل';
            } elseif ($valid_writs[$k - 1][person_type] == HR_PROFESSOR) {
                $ptitle = 'عنوان پست';
            } elseif ($valid_writs[$k - 1][person_type] == HR_EMPLOYEE) {
                $ptitle = 'عنوان حکم';
            }
示例#9
0
 private static function get_writ_edit_state($Gexecute_date = "", $person_type = "", $writ_id = "", $writ_ver = "", $staff_id = "")
 {
     $stage1_end_date = OPEN_WRIT_WITHOUT_CALC_END_DATE;
     $stage2_end_date = OPEN_WRIT_WITH_CALC_END_DATE;
     if ($Gexecute_date == "") {
         if ($writ_ver == "") {
             $query = "SELECT MAX(writ_ver) writ_ver\n\t\t\t\t\t  FROM HRM_writs\n\t\t\t\t\t  WHERE writ_id = :wid AND staff_id = :stid";
             $temp = PdoDataAccess::runquery($query, array(":wid" => $writ_id, ":stid" => $staff_id));
             $writ_ver = $temp[0][0];
         }
         $query = "SELECT execute_date,person_type\n\t\t\t\t\tFROM HRM_writs\n\t\t\t\t\tWHERE writ_id = :wid AND writ_ver = :wver AND staff_id = :stid";
         $temp = PdoDataAccess::runquery($query, array(":wid" => $writ_id, ":wver" => $writ_ver, ":stid" => $staff_id));
         echo PdoDataAccess::GetLatestQueryString();
         die;
         $Gexecute_date = $temp[0]["execute_date"];
         $person_type = $temp[0]["person_type"];
     }
     if ($person_type == "") {
         //echo " نوع فرد مشخص نشده است .";
         return null;
     }
     if ($person_type == HR_PROFESSOR && DateModules::CompareDate($Gexecute_date, $stage1_end_date) >= 0 || $person_type == HR_WORKER && DateModules::CompareDate($Gexecute_date, $stage1_end_date) >= 0 || $person_type == HR_EMPLOYEE && DateModules::CompareDate($Gexecute_date, $stage1_end_date) >= 0 || $person_type == HR_CONTRACT && DateModules::CompareDate($Gexecute_date, $stage1_end_date) >= 0 || $person_type == HR_RETIRED) {
         $is_auto_writ = true;
     } else {
         $is_auto_writ = false;
     }
     if ($person_type == HR_PROFESSOR && DateModules::CompareDate($Gexecute_date, $stage2_end_date) >= 0 || $person_type == HR_WORKER && DateModules::CompareDate($Gexecute_date, $stage2_end_date) >= 0 || $person_type == HR_EMPLOYEE && DateModules::CompareDate($Gexecute_date, $stage2_end_date) >= 0 || $person_type == HR_CONTRACT && DateModules::CompareDate($Gexecute_date, $stage2_end_date) >= 0) {
         $is_new_writ = true;
     } else {
         $is_new_writ = false;
     }
     if (!$is_auto_writ && !$is_new_writ) {
         return 0;
     }
     if (!$is_auto_writ && $is_new_writ) {
         return 1;
     }
     if ($is_auto_writ && !$is_new_writ) {
         return 2;
     }
     if ($is_auto_writ && $is_new_writ) {
         return 3;
     }
 }
示例#10
0
    public static function get_arrear_document($staff_id, $pay_year, $pay_month)
    {
        for ($t = $_POST['from_pay_year']; $t < $_POST['to_pay_year'] + 1; $t++) {
            $retCoef = 1;
            $qry = " select max(arrear_ver) MV\r\n\t\t\t\t\tfrom  corrective_payment_writs \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . "\r\n\t\t       ";
            $MaxVer = PdoDataAccess::runquery($qry);
            if (count($MaxVer) == 0 || $MaxVer[0]['MV'] == 0) {
                continue;
            }
            $qry = " select  cpw.staff_id , cpw.writ_id ,  cpw.writ_ver , cpw.arrear_ver , w.execute_date, w.send_letter_no , w.salary_pay_proc\r\n\t\t\r\n\t\t\t\t from corrective_payment_writs cpw inner join  writs w \r\n\t\t\t                                         on cpw.staff_id = w.staff_id and \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcpw.writ_id = w.writ_id and \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcpw.writ_ver = w.writ_ver \r\n\r\n\t\t\t where cpw.pay_year = " . $t . " and cpw.staff_id = " . $SID . " and arrear_ver = " . $MaxVer[0]['MV'] . " and cpw.pay_month = 12 \r\n\t\t\t order by  w.execute_date ";
            $res1 = PdoDataAccess::runquery($qry);
            //............................. پیدا کردن آخرین ماهی که فیش حقوقی در آن محاسبه شده است ................
            $qry = " select max(pay_month) PM from payment_writs where staff_id = " . $SID . " AND pay_year= " . $t;
            $MaxMonth = PdoDataAccess::runquery($qry);
            if ($MaxMonth[0]['PM'] > 0 && $MaxMonth[0]['PM'] < 7) {
                $LastDate = $t . "/" . $MaxMonth[0]['PM'] . "/31";
            } else {
                if ($MaxMonth[0]['PM'] > 6 && $MaxMonth[0]['PM'] < 12) {
                    $LastDate = $t . "/" . $MaxMonth[0]['PM'] . "/30";
                } else {
                    if ($MaxMonth[0]['PM'] == 12) {
                        $LastDate = $t . "/" . $MaxMonth[0]['PM'] . "/29";
                    } else {
                        $LastDate = '0000-00-00';
                    }
                }
            }
            $LAST_PAY_DATE = date('Y-m-d', strtotime(DateModules::shamsi_to_miladi($LastDate) . "+1 days"));
            $LAST_PAY_DATE = DateModules::miladi_to_shamsi($LAST_PAY_DATE);
            if ($res1[count($res1) - 1]['salary_pay_proc'] == 1) {
                $LastDate = DateModules::miladi_to_shamsi($res1[count($res1) - 1]['execute_date']);
                $arr = preg_split('/\\//', $LastDate);
                $NewDate = date('Y-m-d', strtotime(DateModules::shamsi_to_miladi($LastDate) . "-1 days"));
                $LastDate = DateModules::miladi_to_shamsi($NewDate);
                $arr = preg_split('/\\//', $LastDate);
            }
            $LD = array();
            //.................................................................................................
            for ($i = 0; $i < count($res1); $i++) {
                if ($LastDate != '0000-00-00' && DateModules::CompareDate($res1[$i]['execute_date'], str_replace("/", "-", DateModules::shamsi_to_miladi($LastDate))) >= 0) {
                    $LD[$t]['lastDate'] = $LastDate;
                    break;
                }
                $CDate = DateModules::miladi_to_shamsi($res1[$i]['execute_date']);
                $arr2 = preg_split('/\\//', $CDate);
                if (intval($arr2[1]) <= intval($MaxMonth[0]['PM'])) {
                    $qry = " select t.staff_id,max_execute_date ,SUBSTRING(max_execute_date,1,10) execute_date ,\r\n\t\t\t\t\t\tSUBSTRING_INDEX(SUBSTRING(max_execute_date,11),'.',1) writ_id,\r\n\t\t\t\t\t\tSUBSTRING_INDEX(max_execute_date,'.',-1) writ_ver\r\n\r\n\t\t\t\t\tfrom (\r\n\t\t\t\t\t\t\tselect w.staff_id,max( CONCAT(w.execute_date,w.writ_id,'.',w.writ_ver) ) max_execute_date\r\n\r\n\t\t\t\t\t\t\tfrom payment_writs cpw inner join  writs w\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ton  cpw.staff_id = w.staff_id and\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcpw.writ_id = w.writ_id and\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcpw.writ_ver = w.writ_ver\r\n\t\t\t\t\t\t\twhere cpw.pay_year = " . $t . " and cpw.staff_id = " . $SID . " and\r\n\t\t\t\t\t\t\t      /*cpw.pay_month = 12 and*/ execute_date <= '" . $res1[$i]['execute_date'] . "'\r\n\r\n\t\t\t\t\t\t\tgroup by w.staff_id\r\n\t\t\t\t\t\t) t\r\n\t\t\t\t\t\t\t";
                    // پرس و جو بالا هم بایستی union شود با ورژن های قبلی پرداخت تا احکام آنها هم دیده شود .
                    $res2 = PdoDataAccess::runquery($qry);
                    if (count($res2) == 0) {
                        $res2[0]['execute_date'] = '0000-00-00';
                        $res2[0]['writ_id'] = 0;
                        $res2[0]['writ_ver'] = 0;
                    }
                } else {
                    $res2[0]['execute_date'] = '0000-00-00';
                    $res2[0]['writ_id'] = 0;
                    $res2[0]['writ_ver'] = 0;
                }
                /* PdoDataAccess::runquery(" insert compare_arrear_writs (staff_id ,current_execute_date , current_writ_id , current_writ_ver, 
                															   prev_execute_date , prev_writ_id , prev_writ_ver , arrear_ver , pay_year ) values 
                															  (" . $res1[$i]['staff_id'] . ",'" . $res1[$i]['execute_date'] . "'," . $res1[$i]['writ_id'] . "," .
                                    $res1[$i]['writ_ver'] . ",'" . $res2[0]['execute_date'] . "'," . $res2[0]['writ_id'] . "," .
                                    $res2[0]['writ_ver'] . "," . $res1[$i]['arrear_ver'] . "," . $t . " ) ");
                			*/
                if ($res1[$i]['writ_id'] == $res2[0]['writ_id'] && $res1[$i]['writ_ver'] == $res2[0]['writ_ver']) {
                    continue;
                }
                $writNo++;
            }
            //..................اگر برج 12 در دیون محاسبه می شود ولی در قبلی نبوده است بایستی به جدول compare افزوده شود..............................
            /*   if ($res1[(count($res1) - 1)]['salary_pay_proc'] != 1 && $MaxMonth[0]['PM'] < 12) {
            
            
            
                        $qry = " select staff_id , execute_date , writ_id , writ_ver 
                            from writs 
                             where  staff_id = " . $SID . " and salary_pay_proc = 1 and 
                                    execute_date >= '" . DateModules::shamsi_to_miladi($t . '/01/01') . "' and 
                                    execute_date <= '" . DateModules::shamsi_to_miladi($t . '/12/29') . "' and 
                                    issue_date >= '" . $res1[$i - 1]['execute_date'] . "' and state = 3 ";
            
                        $res3 = PdoDataAccess::runquery($qry);
            
                        PdoDataAccess::runquery(" insert compare_arrear_writs ( staff_id ,current_execute_date , current_writ_id , current_writ_ver, 
                                                                    prev_execute_date , prev_writ_id , prev_writ_ver , arrear_ver , pay_year ) values 
                                                                  (" . $SID . ",'" . $res1[$i - 1]['execute_date'] . "'," . $res1[$i - 1]['writ_id'] . "," .
                                $res1[$i - 1]['writ_ver'] . ",'" . $res3[0]['execute_date'] . "'," . $res3[0]['writ_id'] . "," .
                                $res3[0]['writ_ver'] . "," . $res1[$i - 1]['arrear_ver'] . "," . $t . " ) ");
                    } */
            //....................we need this part......................
            $res = PdoDataAccess::runquery(" select * \r\n\t\t\t\t\t\t\t\t\t\tfrom compare_arrear_writs \r\n\t\t\t\t\t\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year =" . $t . " and arrear_ver = " . $MaxVer[0]['MV']);
            for ($i = 0; $i < count($res); $i++) {
                $writsWhereClause .= ' (wsi.writ_id=' . $res[$i]['current_writ_id'] . ' AND wsi.writ_ver=' . $res[$i]['current_writ_ver'] . ' AND wsi.staff_id=' . $res[$i]['staff_id'] . ') OR 
							 (wsi.writ_id=' . $res[$i]['prev_writ_id'] . ' AND wsi.writ_ver=' . $res[$i]['prev_writ_ver'] . ' AND wsi.staff_id=' . $res[$i]['staff_id'] . ' ) OR  ';
                $PrewritsWhereClause .= ' (wsi.writ_id=' . $res[$i]['prev_writ_id'] . ' AND wsi.writ_ver=' . $res[$i]['prev_writ_ver'] . ' AND wsi.staff_id=' . $res[$i]['staff_id'] . ' ) OR  ';
                $CurrwritsWhereClause .= ' (wsi.writ_id=' . $res[$i]['current_writ_id'] . ' AND wsi.writ_ver=' . $res[$i]['current_writ_ver'] . ' AND wsi.staff_id=' . $res[$i]['staff_id'] . ') OR ';
            }
            //.............................................................
        }
        $writsWhereClause = substr($writsWhereClause, 0, strlen($writsWhereClause) - 4);
        $PrewritsWhereClause = substr($PrewritsWhereClause, 0, strlen($PrewritsWhereClause) - 4);
        $CurrwritsWhereClause = substr($CurrwritsWhereClause, 0, strlen($CurrwritsWhereClause) - 4);
        $ResITM2 = PdoDataAccess::runquery(" select distinct wsi.salary_item_type_id  , sit.print_title ,sit.month_length_effect\r\n\t\t\t\t\t\t\t\t\t\t\t from writ_salary_items wsi \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join salary_item_types sit \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ton  wsi.salary_item_type_id  = sit.salary_item_type_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\twhere " . $writsWhereClause);
        //..............................................................................
        $ResITM = array();
        $diffVal = 0;
        for ($j = 0; $j < count($ResITM2); $j++) {
            $res6 = PdoDataAccess::runquery(" select wsi.salary_item_type_id , sit.print_title , sum(wsi.value) CurrVal \r\n\t\t\t\t\t\t\t\t\t\t\t from writ_salary_items wsi \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join salary_item_types sit \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ton  wsi.salary_item_type_id  = sit.salary_item_type_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\twhere wsi.must_pay = 1 and (" . $CurrwritsWhereClause . ") and wsi.salary_item_type_id =" . $ResITM2[$j]['salary_item_type_id']);
            $res7 = PdoDataAccess::runquery(" select wsi.salary_item_type_id , sit.print_title , sum(wsi.value) PreVal \r\n\t\t\t\t\t\t\t\t\t\t\t from writ_salary_items wsi \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join salary_item_types sit \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ton  wsi.salary_item_type_id  = sit.salary_item_type_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\twhere  wsi.must_pay = 1 and (" . $PrewritsWhereClause . ") and wsi.salary_item_type_id =" . $ResITM2[$j]['salary_item_type_id']);
            $diffVal = $res6[0]['CurrVal'] - $res7[0]['PreVal'];
            if ($diffVal != 0) {
                $diffVal = 0;
                $ResITM[] = array('salary_item_type_id' => $ResITM2[$j]['salary_item_type_id'], 'print_title' => $ResITM2[$j]['print_title'], 'month_length_effect' => $ResITM2[$j]['month_length_effect']);
            } else {
                //.................................... چنانچه قلمی در حکم فعلی حذف شده باشد.................
                for ($i = 0; $i < count($res); $i++) {
                    $res6 = PdoDataAccess::runquery(' select wsi.salary_item_type_id , sit.print_title , sum(wsi.value) CurrVal 
                                                        from writ_salary_items wsi 
                                                                    inner join salary_item_types sit 
                                                                                    on  wsi.salary_item_type_id  = sit.salary_item_type_id
                                                                    where wsi.must_pay = 1 and 
                                                                         (wsi.writ_id=' . $res[$i]['prev_writ_id'] . ' AND 
                                                                          wsi.writ_ver=' . $res[$i]['prev_writ_ver'] . ' AND
                                                                          wsi.staff_id=' . $res[$i]['staff_id'] . ' ) and 
                                                                          wsi.salary_item_type_id =' . $ResITM2[$j]['salary_item_type_id']);
                    $res7 = PdoDataAccess::runquery(' select wsi.salary_item_type_id , sit.print_title , sum(wsi.value) PreVal 
                                                        from writ_salary_items wsi 
                                                                inner join salary_item_types sit 
                                                                        on  wsi.salary_item_type_id  = sit.salary_item_type_id
                                                        where  wsi.must_pay = 1 and 
                                                              (wsi.writ_id=' . $res[$i]['current_writ_id'] . ' AND 
                                                               wsi.writ_ver=' . $res[$i]['current_writ_ver'] . ' AND 
                                                               wsi.staff_id=' . $res[$i]['staff_id'] . ') and 
                                                               wsi.salary_item_type_id =' . $ResITM2[$j]['salary_item_type_id']);
                    if (count($res6) != count($res7) || $res6[0]['CurrVal'] != $res7[0]['PreVal']) {
                        if (!in_array($ResITM2[$j]['salary_item_type_id'], $ResITM)) {
                            $ResITM[] = array('salary_item_type_id' => $ResITM2[$j]['salary_item_type_id'], 'print_title' => $ResITM2[$j]['print_title'], 'month_length_effect' => $ResITM2[$j]['month_length_effect']);
                        }
                    }
                }
            }
        }
        //..........................................................................
        $TotalsumDiff = $TotalMainVal = $TotalRowTax = $TotalRowIns = $TotalRowRet = $TotalPay = 0;
        for ($t = $_POST['from_pay_year']; $t < $_POST['to_pay_year'] + 1; $t++) {
            $retCoef = 1;
            $qry = " select max(arrear_ver) MV\r\n\t\t\t\t\tfrom  corrective_payment_writs \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . "\r\n\t\t       ";
            $MaxVer = PdoDataAccess::runquery($qry);
            if (count($MaxVer) == 0 || $MaxVer[0]['MV'] == 0) {
                continue;
            }
            $res = PdoDataAccess::runquery(" select * \r\n\t\t\t\t\t\t\t\t\t\tfrom compare_arrear_writs \r\n\t\t\t\t\t\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year =" . $t . " and arrear_ver = " . $MaxVer[0]['MV']);
            $prior_execute_date = $current_execute_date = $prior_writ_type = $current_writ_type = '';
            $current_writ_items = $prior_writ_items = array();
            $sdate = "";
            for ($i = 0; $i < count($res); $i++) {
                if ($res[$i]['current_writ_id'] == $res[$i]['prev_writ_id'] && $res[$i]['current_writ_ver'] == $res[$i]['prev_writ_ver']) {
                    continue;
                }
                if (!empty($LD[$t]['lastDate'])) {
                    $toDate = $LD[$t]['lastDate'];
                } else {
                    if ($LastDate == '0000-00-00') {
                        $toDate = $t . "/12/30";
                    } else {
                        $toDate = DateModules::CompareDate(str_replace("/", "-", DateModules::shamsi_to_miladi($t . "/12/30")), str_replace("/", "-", DateModules::shamsi_to_miladi($LastDate))) >= 0 ? $LastDate : $t . "/12/30";
                    }
                }
                /* if ($sdate != "" && $sdate > '0000-00-00')
                       $Row .= "<td>" . $sdate . "</td>";
                   else
                       $Row .= "<td>" .DateModules::miladi_to_shamsi($res[$i]['current_execute_date']). "</td>";
                   */
                if ($res[$i]['current_execute_date'] == $res[$i + 1]['current_execute_date']) {
                    //$Row .= "<td>" . DateModules::AddToJDate($toDate, 1) . "</td>";
                    $sdate = DateModules::AddToJDate($toDate, 1);
                }
                /*else if ($sdate != "" && $sdate > '0000-00-00' && empty($res[$i + 1]['current_execute_date']))
                                $Row .= "<td>" . $t . "/12/29" . "</td>";
                            elseif($res[$i + 1]['current_execute_date'] !='0000-00-00' && DateModules::CompareDate(DateModules::miladi_to_shamsi($res[$i + 1]['current_execute_date']),$LAST_PAY_DATE) == 1  )
                            {
                                  $Row .= "<td>" . $LAST_PAY_DATE . "</td>";
                                
                            }
                            else
                                $Row .= "<td>" . ( empty($res[$i + 1]['current_execute_date']) ? $toDate : DateModules::miladi_to_shamsi($res[$i + 1]['current_execute_date']) ) . "</td>";
                */
                if (!empty($LD[$t]['lastDate'])) {
                    $toDate2 = DateModules::shamsi_to_miladi(DateModules::AddToJDate($LD[$t]['lastDate'], 1));
                } else {
                    if ($LastDate == '0000-00-00') {
                        $toDate2 = DateModules::shamsi_to_miladi($t + 1 . "/01/01");
                    } else {
                        $toDate2 = DateModules::CompareDate(str_replace("/", "-", DateModules::shamsi_to_miladi($t . "/12/30")), str_replace("/", "-", DateModules::shamsi_to_miladi($LastDate))) >= 0 ? DateModules::AddToJDate($LastDate, 1) : DateModules::shamsi_to_miladi($t + 1 . "/01/01");
                    }
                }
                $endDate = empty($res[$i + 1]['current_execute_date']) ? $toDate2 : $res[$i + 1]['current_execute_date'];
                if ($res[$i]['current_execute_date'] == $res[$i + 1]['current_execute_date']) {
                    $endDate = $toDate2;
                }
                if ($sdate != "" && $sdate > '0000-00-00' && empty($res[$i + 1]['current_execute_date'])) {
                    $endDate = $t + 1 . "/1/01";
                    if ($resPerInfo[0]['person_type'] == 3) {
                        $DayNo = round(DateModules::GDateMinusGDate(DateModules::shamsi_to_miladi($endDate), DateModules::shamsi_to_miladi($sdate)));
                        $DayNo2 = calculate_duration($sdate, $endDate);
                    } else {
                        $DayNo = calculate_duration($sdate, $endDate);
                    }
                } else {
                    if ($resPerInfo[0]['person_type'] == 3) {
                        $DayNo = round(DateModules::GDateMinusGDate(DateModules::shamsi_to_miladi($endDate), $res[$i]['current_execute_date']));
                        $DayNo2 = calculate_duration($res[$i]['current_execute_date'], $endDate);
                    } else {
                        $DayNo = calculate_duration($res[$i]['current_execute_date'], $endDate);
                    }
                }
                if ($res[$i + 1]['current_execute_date'] != '0000-00-00' && DateModules::CompareDate(DateModules::miladi_to_shamsi($res[$i + 1]['current_execute_date']), $LAST_PAY_DATE) == 1) {
                    $DayNo = calculate_duration($res[$i]['current_execute_date'], DateModules::shamsi_to_miladi($LAST_PAY_DATE));
                }
                // $Row .= "<td>" . $DayNo . "</td>";
                $sumDiff = $MainVal = 0;
                $RetInc = $TaxInc = $InsInc = 0;
                for ($j = 0; $j < count($ResITM); $j++) {
                    $val1 = get_writSalaryItem_value($res[$i]["current_writ_id"], $res[$i]["current_writ_ver"], $res[$i]["staff_id"], $ResITM[$j]["salary_item_type_id"]);
                    $val2 = get_writSalaryItem_value($res[$i]["prev_writ_id"], $res[$i]["prev_writ_ver"], $res[$i]["staff_id"], $ResITM[$j]["salary_item_type_id"]);
                    $RetRes = PdoDataAccess::runquery(" select retired_include , tax_include , insure_include \r\n                                                      from salary_item_types where salary_item_type_id = " . $ResITM[$j]["salary_item_type_id"]);
                    //  $Row .= "<td>" . CurrencyModulesclass::toCurrency($val1 - $val2) . (($val1 - $val2) < 0 ? "-&nbsp;" : "" ) . "</td>";
                    $sumDiff += $val1 - $val2;
                    if (empty($Itm[$j]['sumVal'])) {
                        $Itm[$j]['sumVal'] = 0;
                        $Itm[$j]['sumCol'] = 0;
                    }
                    $Itm[$j]['sumVal'] += $val1 - $val2;
                    if ($ResITM[$j]["month_length_effect"] == 0 && $resPerInfo[0]['person_type'] == 3) {
                        $Itm[$j]['sumCol'] += round(($val1 - $val2) * $DayNo2 / 30);
                        $MainVal += round(($val1 - $val2) * $DayNo2 / 30);
                    } elseif ($resPerInfo[0]['person_type'] == 5 && $_SESSION['UserID'] == 'jafarkhani') {
                        // echo $endDate . "---<br>" ;
                        // echo DateModules::miladi_to_shamsi($res[$i]['current_execute_date'])."***<br>" ; die();
                        $arr3 = preg_split('/\\//', DateModules::miladi_to_shamsi($res[$i]['current_execute_date']));
                        $arr4 = preg_split('/\\//', DateModules::miladi_to_shamsi($endDate));
                        if ($arr4[1] * 1 == 1 && $arr4[0] == $arr3[0] + 1) {
                            $EP = 12;
                        } else {
                            $EP = $arr4[1] * 1;
                        }
                        //.........................
                        $std = $res[$i]['current_execute_date'];
                        $stMonth = $arr3[1] * 1;
                        if ($stMonth < 7) {
                            $endt = $arr3[0] . "/" . $arr3[1] . "/31";
                        } elseif (6 < $stMonth && $stMonth < 12) {
                            $endt = $arr3[0] . "/" . $arr3[1] . "/30";
                        } elseif ($stMonth == 12) {
                            $endt = $arr3[0] . "/" . $arr3[1] . "/29";
                        }
                        for ($k = $arr3[1] * 1; $k < $EP + 1; $k++) {
                            if (DateModules::CompareDate(DateModules::miladi_to_shamsi($endt), DateModules::miladi_to_shamsi($endDate)) < 1) {
                                $DYNo = round(DateModules::GDateMinusGDate(DateModules::shamsi_to_miladi($endt), $std)) + 1;
                                if ($stMonth < 7) {
                                    $mNO = 31;
                                } elseif ($stMonth > 6 && $stMonth < 12) {
                                    $mNO = 30;
                                } elseif ($stMonth == 12) {
                                    $mNO = 29;
                                }
                                $Itm[$j]['sumCol'] += round(($val1 - $val2) * $DYNo / $mNO);
                                $MainVal += round(($val1 - $val2) * $DYNo / $mNO);
                                $TaxInc += round(($val1 - $val2) * $DYNo / $mNO);
                                //........................
                                $std = DateModules::shamsi_to_miladi($arr3[0] . "/" . ($k + 1) . "/01");
                                $stMonth = $k + 1;
                                //$arr3[1] + 1;
                                if ($stMonth < 7) {
                                    $endt = $arr3[0] . "/" . $stMonth . "/31";
                                } elseif (6 < $stMonth && $stMonth < 12) {
                                    $endt = $arr3[0] . "/" . $stMonth . "/30";
                                } elseif ($stMonth == 12) {
                                    $endt = $arr3[0] . "/" . $stMonth . "/29";
                                }
                            } else {
                                //echo "****";
                                // die();
                                $endt = $endDate;
                                $DYNo = round(DateModules::GDateMinusGDate(DateModules::shamsi_to_miladi($endt), $std));
                                if ($stMonth < 7) {
                                    $mNO = 31;
                                } elseif ($stMonth > 6 && $stMonth < 12) {
                                    $mNO = 30;
                                } elseif ($stMonth == 12) {
                                    $mNO = 29;
                                }
                                $Itm[$j]['sumCol'] += round(($val1 - $val2) * $DYNo / $mNO);
                                $MainVal += round(($val1 - $val2) * $DYNo / $mNO);
                                $TaxInc += round(($val1 - $val2) * $DYNo / $mNO);
                                break;
                            }
                        }
                    } else {
                        $Itm[$j]['sumCol'] += round(($val1 - $val2) * $DayNo / 30);
                        $MainVal += round(($val1 - $val2) * $DayNo / 30);
                    }
                    //...............................
                    if ($RetRes[0]['retired_include'] == 1) {
                        $RetInc += $val1 - $val2;
                    }
                    if ($RetRes[0]['tax_include'] == 1 && $resPerInfo[0]['person_type'] != 5) {
                        if ($ResITM[$j]["month_length_effect"] == 0 && $resPerInfo[0]['person_type'] == 3) {
                            $TaxInc += round(($val1 - $val2) * $DayNo2 / 30);
                        } else {
                            $TaxInc += round(($val1 - $val2) * $DayNo / 30);
                        }
                    }
                    if ($RetRes[0]['insure_include'] == 1) {
                        $InsInc += $val1 - $val2;
                    }
                }
                //$MainVal = round(($sumDiff) * $DayNo / 30);
                //....................مالیات...........
                $qry = " select count(*) cn  \r\n\t\t\t\t\tfrom Arrear_payment_items \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . " and pay_month  = 12 and salary_item_type_id in (146,147,148,747)";
                $res4 = PdoDataAccess::runquery($qry);
                if ($res4[0]['cn'] > 0) {
                    //.........................................
                    $qry = " select count(*) cnp\r\n            from payments \r\n               where staff_id = " . $SID . " and pay_year = " . $t;
                    $resE = PdoDataAccess::runquery($qry);
                    if ($resE[0]['cnp'] == 0) {
                        $sdatetax = DateModules::shamsi_to_miladi($t . "/12/29");
                        $qry = " SELECT tti.from_value\r\n                FROM staff_tax_history sth\r\n                        inner join tax_tables tt on sth.tax_table_type_id = tt.tax_table_type_id\r\n                        inner join tax_table_items tti on tti.tax_table_id = tt.tax_table_id\r\n\r\n                WHERE sth.staff_id = " . $SID . " and \r\n                    sth.start_date < '" . DateModules::Now() . "' and\r\n                    ( sth.end_date = '0000-00-00' or sth.end_date is null or \r\n                    sth.end_date > '" . DateModules::Now() . "' ) and\r\n                    tt.from_date < '" . $sdatetax . "' and\r\n                    ( tt.to_date = '0000-00-00' or tt.to_date is null or tt.to_date >= '" . $sdatetax . "'  ) and coeficient = 0.1 ";
                        $resFval = PdoDataAccess::runquery($qry);
                        $TaxInc -= $resFval[0]['from_value'];
                    }
                    //.........................................
                    $RowTax = $TaxInc * 0.1;
                    //round(($TaxInc * $DayNo / 30) * 0.1);
                } else {
                    $RowTax = 0;
                }
                //..................................
                $qry = " select count(*) cn  \r\n\t\t\t\t\tfrom Arrear_payment_items \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . " and pay_month  = 12 and salary_item_type_id in (149 , 150)";
                $res3 = PdoDataAccess::runquery($qry);
                if ($res3[0]['cn'] > 0) {
                    $RowRet = round($RetInc * $DayNo / 30 * 0.09);
                } else {
                    $RowRet = 0;
                }
                //.......................بیمه تامین اجتماعی...........
                $qry = " select count(*) cn  \r\n\t\t\t\t\tfrom Arrear_payment_items \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . " and pay_month  = 12 and salary_item_type_id in (144,145,744,9920)";
                $res5 = PdoDataAccess::runquery($qry);
                if ($res5[0]['cn'] > 0) {
                    $RowInsure = round($InsInc * $DayNo / 30 * 0.07000000000000001);
                } else {
                    $RowInsure = 0;
                }
                //.....................................
                if ($resPerInfo[0]['last_retired_pay'] != NULL && $resPerInfo[0]['last_retired_pay'] != '0000-00-00' && DateModules::CompareDate($resPerInfo[0]['last_retired_pay'], DateModules::shamsi_to_miladi($t . "/01/01")) == -1) {
                    $RowRet = $retCoef = 0;
                }
                $TotalsumDiff += $sumDiff;
                $TotalMainVal += $MainVal;
                $TotalRowTax += $RowTax;
                $TotalRowRet += $RowRet;
                $TotalRowIns += $RowInsure;
                $TotalPay += $MainVal - ($RowTax + $RowRet + $RowInsure);
                /* $Row .= "<td>" . ( ($sumDiff < 0 ) ? CurrencyModulesclass::toCurrency($sumDiff) . "-" : CurrencyModulesclass::toCurrency($sumDiff)) . "</td>
                		 <td>" . (($MainVal < 0 ) ? CurrencyModulesclass::toCurrency($MainVal) . "-" : CurrencyModulesclass::toCurrency($MainVal)) . "</td><td>" .
                                  (($RowTax < 0 ) ? CurrencyModulesclass::toCurrency($RowTax) . "-" : CurrencyModulesclass::toCurrency($RowTax)) . "</td><td>" .
                                  (($RowRet < 0 ) ? CurrencyModulesclass::toCurrency($RowRet) . "-" : CurrencyModulesclass::toCurrency($RowRet)) . "</td><td>" .
                                  (($RowInsure < 0 ) ? CurrencyModulesclass::toCurrency($RowInsure) . "-" : CurrencyModulesclass::toCurrency($RowInsure)) . "</td><td>" .
                                  ((($MainVal - ($RowTax + $RowRet + $RowInsure )) < 0 ) ? CurrencyModulesclass::toCurrency(($MainVal - ($RowTax + $RowRet + $RowInsure))) . "-" : CurrencyModulesclass::toCurrency(($MainVal - ($RowTax + $RowRet + $RowInsure)))) . "</td></tr>"; */
            }
            //   $Row .= "</tr>";
        }
    }
示例#11
0
function generateReport($transcript_no)
{
    global $equal_payment_system_gdate;
    $fileNames = array();
    $last_writ = isset($_GET["last_writ_flag"]) || isset($_POST["last_writ_view"]) ? "1" : "";
    $dt = writ_print_list($transcript_no, $last_writ);
    if ($dt->rowCount() == 0) {
        echo "گزارش هیچ نتیجه ایی در بر ندارد.";
        return;
    }
    $current_staff_id = "";
    $cnt = $dt->rowCount();
    for ($i = 0; $i < $cnt; $i++) {
        $row = $dt->fetch();
        if ($current_staff_id != $row["staff_id"]) {
            $writForm = PrintWrit($row);
            $current_staff_id = $row["staff_id"];
        }
        if ($row['person_type'] == HR_PROFESSOR) {
            // نسخه هيات علمي
            $transcripts_title = $transcript_no == "all" ? $row['transcripts_title'] : 'عضو هيات علمي';
        } else {
            // نسخه استخدام كشوري
            //$transcripts_title = ($transcript_no == "all") ? $row['transcripts_title'] : 'مستخدم';
            $transcripts_title = $transcript_no == "all" ? $row['transcripts_title'] : ' کارگزینی';
        }
        $tags = array('<!--transcripts_title-->' => $transcripts_title);
        echo str_replace(array_keys($tags), array_values($tags), $writForm);
        echo "<div class=noprint><br><br></div>";
        if ($i == $cnt - 1 && $row['corrective'] == 1) {
            echo "<div class='pageBreak'></div>";
            // موارد مربوط به پشت حكم اصلاحي
            $corrective_detail = corrective_writ_detail($row['writ_id'], $row['writ_ver'], $row['staff_id'], $row['execute_date']);
            $tags = array('<!--CORRECTIVE_DETAIL-->' => $corrective_detail);
            $corrective_detail = str_replace(array_keys($tags), array_values($tags), $corrective_detail);
            if ($row['person_type'] == HR_PROFESSOR || DateModules::CompareDate($row['execute_date'], $equal_payment_system_gdate) < 0) {
                echo '<div class="report_header" style="font-size:medium"><B>اصلاحات احکام کارگزيني</B><br></div>
					<table cellpadding="0" cellspacing="0" class="big_corrective money" style="text-align:center">';
            } else {
                echo '<div class="report_header" style="font-size:medium"><B>اصلاحات احکام کارگزيني</B><br></div>
					<table cellpadding="0" cellspacing="0" class="report money" style="text-align:center">';
            }
            echo $corrective_detail;
            echo "</table>";
        }
        //$fileNames[] = PrintWrit($row, $transcript_no);
        if ($i != $cnt - 1) {
            echo "<div class='pageBreak'></div>";
        }
    }
    return $fileNames;
}
 function validate_salary_item_type_id($validity_start_date, $validity_end_date, $date)
 {
     if (DateModules::CompareDate($validity_start_date, $date) != 1 && (DateModules::CompareDate($validity_end_date, $date) != -1 || $validity_end_date == null || $validity_end_date == '0000-00-00')) {
         return true;
     } else {
         return false;
     }
 }
示例#13
0
" class="x-form-text x-form-field"> روز
		</td>
		<td></td>
		<td></td>
	</tr>
	<?}if($objWrt->person_type == HR_PROFESSOR){?>
	<tr>
		<td>عنوان دانشگاهي :</td>
		<td><?php 
echo $drp_science_level;
?>
</td>
		<td>پايه :</td>
		<?if(($objWrt->emp_state == EMP_STATE_SOLDIER_CONTRACTUAL ||
            $objWrt->emp_state == EMP_STATE_CONTRACTUAL || $objWrt->emp_state == EMP_STATE_ONUS_SOLDIER_CONTRACTUAL) &&
			DateModules::CompareDate($objWrt->execute_date, DateModules::shamsi_to_miladi('1389/07/01')) < 0){?>

		<td class="bluText"><?php 
echo $objWrt->base;
?>
</td>
		<?}else{?>
		<td><input type="text" id="base" name="base" class="x-form-text x-form-field" value="<?php 
echo $objWrt->base;
?>
"></td>
		<?}?>
	</tr>
	<?}?>
	<tr>
		<td>وضعيت استخدامي :</td>