Esempio n. 1
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;
}
Esempio n. 2
0
function saveData()
{
    //........ Fill object ..............
    $obj = new manage_writ($_POST['writ_id'], $_POST['writ_ver'], $_POST['staff_id']);
    PdoDataAccess::FillObjectByArray($obj, $_POST);
    $obj->family_responsible = isset($_POST['family_responsible']) ? $_POST['family_responsible'] : 0;
    $obj->history_only = isset($_POST['history_only']) ? $_POST['history_only'] : 0;
    $obj->remembered = isset($_POST['remembered']) ? $_POST['remembered'] : 0;
    $obj->dont_transfer = isset($_POST['dont_transfer']) ? $_POST['dont_transfer'] : 0;
    //.............. محاسبه مجدد پایه سنواتی فرد ..................
    $Pqry = " select sex , p.person_type ,military_duration_day , military_duration\n\t\t\t\tfrom persons p inner join staff s \n\t\t\t\t\t\t\t\t\ton p.PersonID = s.PersonID \n\t\t\t\t\t\t\t\t\t\n\t\t\t\t where s.staff_id = " . $obj->staff_id;
    $Pres = PdoDataAccess::runquery($Pqry);
    if ($obj->person_type == 2 || $obj->person_type == 5) {
        if ($Pres[0]["sex"] == 1 && $Pres[0]["person_type"] == 2 && ($Pres[0]["military_duration_day"] > 0 || $Pres[0]["military_duration"] > 0)) {
            $totalDayWrt = DateModules::ymd_to_days($obj->onduty_year, $obj->onduty_month, $obj->onduty_day);
            $totalDaySar = DateModules::ymd_to_days(0, $Pres[0]["military_duration"], $Pres[0]["military_duration_day"]);
            $resDay = $totalDayWrt - $totalDaySar;
            $Vyear = 0;
            $Vmonth = $Vday = 0;
            DateModules::day_to_ymd($resDay, $Vyear, $Vmonth, $Vday);
            $Vyear = $Vyear;
        } else {
            $Vyear = $obj->onduty_year;
        }
        $obj->base = $Vyear + 1;
    }
    //............................................................
    /*$arr = get_object_vars($obj);
    	$KeyArr = array_keys($arr);
    	
    	for($i=0; $i<count($arr); $i++)
    	{
    		eval("if(isset(\$_POST['" . $KeyArr[$i] . "']))
    			\$obj->" . $KeyArr[$i] . "= \$_POST ['" . $KeyArr[$i] . "'];");
    		
    	}
    		
    	$obj->staff_id = $_POST['staff_id'];
    	$obj->writ_id  = $_POST['writ_id'];
    	$obj->writ_ver = $_POST['writ_ver'];
    	$obj->sbid = (empty($obj->sbid)) ? PDONULL : $obj->sbid;
    	$obj->issue_date = DateModules::Shamsi_to_Miladi($obj->issue_date);
    	$obj->pay_date = DateModules::Shamsi_to_Miladi($obj->pay_date);	
    	$obj->ref_letter_date = DateModules::Shamsi_to_Miladi($obj->ref_letter_date);
    	$obj->send_letter_date = DateModules::Shamsi_to_Miladi($obj->send_letter_date);	
    	$obj->warning_date = DateModules::Shamsi_to_Miladi($obj->warning_date);	
    	$obj->remembered = (isset($_POST['remembered'])) ? $_POST['remembered'] : "0" ;*/
    //....................................
    if ($obj->check_send_letter_no() === false) {
        Response::createObjectiveResponse(false, ExceptionHandler::ConvertExceptionsToJsObject());
        die;
    }
    if (!$obj->EditWrit()) {
        Response::createObjectiveResponse(false, ExceptionHandler::ConvertExceptionsToJsObject());
        die;
    }
    Response::createObjectiveResponse(true, "{WID:" . $obj->writ_id . "}");
    //echo Response::createObjectiveResponse("true", $obj->writ_id);
    die;
}
Esempio n. 3
0
 function AddPerson($staffObject, $pic = "")
 {
     $pdo = PdoDataAccess::getPdoObject();
     if ($pdo->beginTransaction()) {
         if ($this->military_from_date != NULL || $this->military_from_date != '0000-00-00') {
             $Vyear = 0;
             $Vmonth = $Vday = 0;
             $resDay = DateModules::GDateMinusGDate($this->military_to_date, $this->military_from_date);
             DateModules::day_to_ymd($resDay, $Vyear, $Vmonth, $Vday);
             $mm = $Vyear * 12 + $Vmonth;
             $dd = $Vday;
             $this->military_duration = $mm;
             $this->military_duration_day = $dd;
         }
         if (parent::insert("HRM_persons", $this, $pdo) === false) {
             parent::PushException(ER_PERSON_DONT_SAVE);
             $pdo->rollBack();
             return false;
         }
         $this->PersonID = parent::InsertID();
         $staffObject->PersonID = $this->PersonID;
         $staffObject->person_type = $this->person_type;
         $return = $staffObject->AddStaff($pdo);
         if (!$return) {
             parent::PushException(ER_PERSON_DONT_SAVE);
             $pdo->rollBack();
             return false;
         }
         if ($return) {
             $pdo->commit();
         }
         $daObj = new DataAudit();
         $daObj->ActionType = DataAudit::Action_add;
         $daObj->MainObjectID = $this->PersonID;
         $daObj->TableName = "HRM_persons";
         $daObj->execute();
         return true;
     } else {
         return false;
     }
 }
Esempio n. 4
0
	private function compute_salary_item2_60($writ_rec) {

		//param1 : ضریب حقوقی
		//param2 : عدد مبنا
		//param3 : پایه
		//param4 : ضریب مدرک تحصیلی
		//param5 : رتبه
		//param6 : مدرک تحصیلی
		//param7 : ضریب مقدار برای مدارک دیپلم و زیر دیپلم
		//param8 : پایه استحقاقی

		// دارندگان مدرک دیپلم و زیر دیپلم
	    
	  
		$coafOfDiplom = 1;
			
				
		$this->param6 = self::GetEducLevel($writ_rec);
		$this->param5 = self::GetGrade($writ_rec,$this->param6);
		
		//...................................
		if($this->param6 == '1' || ($writ_rec["education_level"] < 122 && $writ_rec["education_level"] != 117 ) ) // زیر دیپلم
		{
			$coafOfDiplom = 0.8;
		}
		elseif($this->param6 == '2') // دیپلم
		{
			$coafOfDiplom = 0.9;
		}		
					
		if($this->param6 == 1 || $this->param6 == 2 ) {
		  
		    $this->param6 = 3 ; 
		    
		}		
	
		$this->param1 = manage_salary_params::get_salaryParam_value("", $writ_rec["sp_person_type"], 
					SPT_RIAL_COEF, $writ_rec['execute_date']);
				
		$this->param7 = $coafOfDiplom;
		$this->param2 = manage_salary_params::get_salaryParam_value("", $writ_rec["sp_person_type"], 
				SPT_BASE_GRADE, $writ_rec['execute_date'], $this->param5, $this->param6);
		
			
//.................
		$qry = " select  sum(if(ba.BaseType in (6) and ba.BaseStatus = 'NORMAL' ,ba.BaseValue,0))  TashvighiValue ,
						 sum(if(ba.BaseType in (3,4,5) and ba.BaseStatus = 'NORMAL' ,ba.BaseValue,0))  IsarValue , 
						 sum(if(ba.BaseType in (1,2,7,20,21,22,23,24,25,26,27 ) and ba.BaseStatus = 'NORMAL' ,ba.BaseValue,0)) OtherBase 
						 
				 from bases ba 
				 where ba.PersonID =".$writ_rec['PersonID']." AND ExecuteDate <= '".$writ_rec['execute_date']."'" ;
		$baseRes = parent::runquery($qry) ; 

 

//.................
		$otherPoint = (($baseRes[0]["TashvighiValue"] + $baseRes[0]["OtherBase"]) > 7) ? 7 : ($baseRes[0]["TashvighiValue"] + $baseRes[0]["OtherBase"])  ; 
		
						
		if($writ_rec["sex"] == 1 &&  $writ_rec["person_type"] == 2 && ($writ_rec["military_duration_day"] > 0 || $writ_rec["military_duration"] > 0 ) )
			{
							
			$totalDayWrt = DateModules::ymd_to_days($writ_rec["onduty_year"], $writ_rec["onduty_month"], $writ_rec["onduty_day"]) ; 			
			$totalDaySar = DateModules::ymd_to_days(0, $writ_rec["military_duration"], $writ_rec["military_duration_day"]) ; 					
				
$resDay = $totalDayWrt -  $totalDaySar  ; 
	
			$Vyear = 0 ; 
			$Vmonth = $Vday = 0 ; 
			DateModules::day_to_ymd($resDay, $Vyear, $Vmonth, $Vday) ; 
			$Vyear =  $Vyear ; 
	
			
			//echo $Vyear." ---- ".$baseRes[0]["IsarValue"]."--isa---".$otherPoint  ;  die() ; 
			}						
		 else  		
			$Vyear =  $writ_rec["onduty_year"] ;  
		
	//if($_SESSION['UserID'] == 'jafarkhani') { echo $Vyear .'---' ;  die();          }		
		// به اضافه یک می شود با توجه به تبصره 8 آیین نامه	
		$this->param8 =  /*($writ_rec['execute_date'] > '2014-03-21' && $writ_rec['base'] > 0 ) ? $writ_rec['base'] :*/ ($Vyear + 1 );		
		$this->param3 = /*$writ_rec["base"] $Vyear + 1 */ $this->param8 +  $baseRes[0]["IsarValue"] + $otherPoint  ;		
				
		$this->param4 = manage_salary_params::get_salaryParam_value("", $writ_rec["sp_person_type"], 
				SPT_EDULEVEL_COAF, $writ_rec['execute_date'], $this->param6);



		$value = $coafOfDiplom * ($this->param1 * ($this->param2 + ($this->param3 * $this->param4)));	
						
		return $value;
	}
Esempio n. 5
0
function PrintWrit($writ_rec)
{
    $sum = 0;
    $content = "";
    $emp_sal_scores = $emp_sal_vals = "";
    $salary_items = $corrective_detail = $professor_post_type = $org_sub_unit_type = $writ_title = $contact_title = $worker_salary_item1_title = $worker_salary_item1_value = $worker_salary_item2_title = $worker_salary_item2_value = $worker_other_salary_items = $worker_base_salary = $emp_sal_items = $template_file = $exe_date_title = "";
    $post_title = "";
    $os_ptitle = "";
    $sit2_annual_inc_coef = "";
    $indx = array("الف-", "ب-", "پ-", "ت-", "ث-", "ج-", "چ-", "ح-", "خ-", "د-", "ذ-", "ر-", "ز-", "س-", "ش-", "و-", "ه-", "ي-");
    global $equal_payment_system_gdate;
    // مشخص كردن template مربوط به حكم جاري
    if ($writ_rec['person_type'] == HR_EMPLOYEE) {
        if ($writ_rec['emp_state'] == EMP_STATE_PROBATIONAL_CEREMONIOUS || $writ_rec['emp_state'] == EMP_STATE_APPROVED_CEREMONIOUS) {
            if (DateModules::CompareDate($writ_rec['execute_date'], $equal_payment_system_gdate) >= 0 && DateModules::CompareDate($writ_rec['execute_date'], '2013-02-19') < 0 || DateModules::CompareDate($writ_rec['execute_date'], '2013-03-21') >= 0 && DateModules::CompareDate($writ_rec['execute_date'], '2014-03-21') < 0) {
                if ($writ_rec['emp_mode'] == 14) {
                    $template_file = 'employee_ceremonious_writ_print4.htm';
                } else {
                    $template_file = 'employee_ceremonious_writ_print2.htm';
                }
            } else {
                if (DateModules::CompareDate($writ_rec['execute_date'], '2013-02-19') >= 0 && DateModules::CompareDate($writ_rec['execute_date'], '2013-03-21') < 0 || DateModules::CompareDate($writ_rec['execute_date'], '2014-03-20') > 0) {
                    $template_file = 'employee_ceremonious_writ_print3.htm';
                } else {
                    $template_file = 'employee_ceremonious_writ_print.htm';
                }
            }
        }
        if ($writ_rec['emp_state'] == EMP_STATE_CONTRACTUAL) {
            if (DateModules::CompareDate($writ_rec['execute_date'], $equal_payment_system_gdate) >= 0 && DateModules::CompareDate($writ_rec['execute_date'], '2013-02-19') < 0 || DateModules::CompareDate($writ_rec['execute_date'], '2013-03-21') >= 0 && DateModules::CompareDate($writ_rec['execute_date'], '2014-03-20') < 0) {
                $template_file = 'employee_contractual_writ_print_report2.htm';
            } else {
                if (DateModules::CompareDate($writ_rec['execute_date'], '2013-02-19') >= 0 && DateModules::CompareDate($writ_rec['execute_date'], '2013-03-21') < 0 || DateModules::CompareDate($writ_rec['execute_date'], '2014-03-20') > 0) {
                    $template_file = 'employee_contractual_writ_print_report3.htm';
                } else {
                    $template_file = 'employee_contractual_writ_print_report.htm';
                }
            }
            $writ_title = "قرارداد کارمند پیمانی";
        }
    } else {
        if ($writ_rec['person_type'] == HR_PROFESSOR) {
            if ($writ_rec['emp_state'] == EMP_STATE_PROBATIONAL_CEREMONIOUS || $writ_rec['emp_state'] == EMP_STATE_APPROVED_CEREMONIOUS) {
                $template_file = 'professor_ceremonious_writ_print.htm';
                $writ_title = 'حکم استخدام رسمي اعضاي هيات علمي';
            } else {
                if ($writ_rec['emp_state'] == EMP_STATE_SOLDIER_CONTRACTUAL || $writ_rec['emp_state'] == EMP_STATE_ONUS_SOLDIER_CONTRACTUAL || $writ_rec['emp_state'] == EMP_STATE_CONTRACTUAL || $writ_rec['emp_state'] == 11) {
                    $template_file = 'professor_contractual_writ_print_report.htm';
                    if ($writ_rec['time_limited'] == 1) {
                        $writ_title = 'قرارداد استخدام پيماني اعضاي هيات علمي';
                    } else {
                        $writ_title = $writ_rec['wst_title'] . ' اعضاي هيات علمي پيماني';
                    }
                    if ($writ_rec['emp_state'] == 11) {
                        $writ_title = " قرارداد پیمانی (مشروط) اعضای هیئت علمی ";
                    }
                }
            }
            if ($writ_rec['corrective']) {
                $template_file = 'professor_ceremonious_writ_print.htm';
            }
        } else {
            if ($writ_rec['person_type'] == HR_WORKER) {
                $template_file = 'worker_writ_print.htm';
                /*if( DateModules::CompareDate($writ_rec['execute_date'], '2013-02-19') < 0)
                			$template_file = 'worker_writ_print.htm';
                		else
                			$template_file = 'worker_writ_print2.htm';*/
                if ($writ_rec['corrective']) {
                    $writ_title = 'طرح طبقه بندي مشاغل <br>حكم اصلاحي كارگزيني';
                } else {
                    $writ_title = 'طرح طبقه بندي مشاغل <br>حکم کارگزيني';
                }
            } else {
                if ($writ_rec['person_type'] == HR_CONTRACT) {
                    if (DateModules::CompareDate($writ_rec['execute_date'], '2013-02-19') < 0 || DateModules::CompareDate($writ_rec['execute_date'], '2013-03-21') >= 0 && DateModules::CompareDate($writ_rec['execute_date'], '2014-03-20') < 0) {
                        $template_file = 'contract_writ_print.htm';
                        $writ_title = "قرار داد انجام کار مشخص";
                    } else {
                        $template_file = 'contract_writ_print3.htm';
                        $writ_title = "قرارداد کارکنان قراردادی";
                    }
                }
            }
        }
    }
    echo "<div style='display:none'>" . $template_file . "</div>";
    // محل تحصيل و زمان اخذ مدرك
    $person_education_rec = manage_person_education::GetEducationLevelByDate($writ_rec['PersonID'], $writ_rec['execute_date']);
    $edu_c_ptitle = $person_education_rec['countryTitle'];
    $edu_u_ptitle = $person_education_rec['universityTitle'];
    $education_level_title = $writ_rec['education_level_title'];
    $edu_doc_date = "";
    if ($writ_rec['sfid'] != PROFESSIONAL_WITHOUT_CERTIFY) {
        $edu_doc_date = DateModules::miladi_to_shamsi($person_education_rec['doc_date']);
    } else {
        $education_level_title = "";
    }
    // سوابق خدمت
    $onduty = "";
    if ($writ_rec['onduty_year'] > 0) {
        $onduty .= $writ_rec['onduty_year'];
        $onduty .= ' سال ';
    }
    if ($writ_rec['onduty_month'] > 0) {
        if ($writ_rec['onduty_year'] > 0) {
            $onduty .= ' و ';
        }
        $onduty .= $writ_rec['onduty_month'];
        $onduty .= ' ماه ';
    }
    if ($writ_rec['onduty_day'] > 0 || $writ_rec['onduty_year'] > 0) {
        if ($writ_rec['onduty_month'] > 0) {
            $onduty .= "&nbsp;" . ' و ';
        }
        $onduty .= $writ_rec['onduty_day'];
        $onduty .= ' روز';
    }
    // وضعيت ايثارگري
    $devotion_recSet = manage_person_devotion::get_person_devotions($writ_rec['PersonID'], NULL, 'ALL');
    $devotion_type = "";
    if (is_array($devotion_recSet)) {
        foreach ($devotion_recSet as $devotion_rec) {
            $devotion_type .= " " . $devotion_rec['devotionTypeName'] . "  ";
        }
    }
    // اقلام مربوط به نظام هماهنگ پرداخت
    if (!$writ_rec['corrective'] && $writ_rec['person_type'] == HR_EMPLOYEE && DateModules::CompareDate($writ_rec['execute_date'], $equal_payment_system_gdate) >= 0 && (DateModules::CompareDate($writ_rec['execute_date'], '2013-02-19') < 0 || DateModules::CompareDate($writ_rec['execute_date'], '2013-03-20') > 0 && DateModules::CompareDate($writ_rec['execute_date'], '2014-03-21') < 0)) {
        $item_recset = manage_writ_item::GetAllWritItems("writ_id=? AND writ_ver=? AND staff_id=?", array($writ_rec['writ_id'], $writ_rec['writ_ver'], $writ_rec["staff_id"]));
        $emp_sal_items = array();
        $Sayer = 0;
        $Sayer_Score = 0;
        $score_sum = 0;
        foreach ($item_recset as $rec) {
            if ($writ_rec['emp_mode'] == 14) {
                $emp_sal_items['<!---item_' . $rec['salary_item_type_id'] . '-->'] = CurrencyModulesclass::toCurrency($rec['value'], 'CURRENCY');
                if ($rec['value']) {
                    $emp_sal_vals[$rec['salary_item_type_id']] = $rec['value'];
                    $sum += $rec['value'];
                }
            } else {
                if ($rec['salary_item_type_id'] != 57 && $rec['salary_item_type_id'] != 45) {
                    $emp_sal_items['<!---item_' . $rec['salary_item_type_id'] . '-->'] = CurrencyModulesclass::toCurrency($rec['value'], 'CURRENCY') . " " . ($rec['value'] < 0 ? '-' : '');
                    $emp_sal_items['<!---item_' . $rec['salary_item_type_id'] . '_score-->'] = $rec['param1'];
                    if ($rec['value']) {
                        $emp_sal_vals[$rec['salary_item_type_id']] = $rec['value'];
                        $sum += $rec['value'];
                    }
                    if ($rec['param1']) {
                        $emp_sal_scores[$rec['salary_item_type_id']] = $rec['param1'];
                        $score_sum += $rec['param1'];
                    }
                } else {
                    $rec['salary_item_type_id'] = 45;
                    $Sayer += $rec['value'];
                    $Sayer_Score += $rec['param1'];
                    $emp_sal_items['<!---item_' . $rec['salary_item_type_id'] . '-->'] = CurrencyModulesclass::toCurrency($Sayer);
                    $emp_sal_items['<!---item_' . $rec['salary_item_type_id'] . '_score-->'] = $Sayer_Score != 0 ? $Sayer_Score : "";
                    if ($rec['value']) {
                        $emp_sal_vals[$rec['salary_item_type_id']] = $Sayer;
                        $sum += $rec['value'];
                    }
                    if ($rec['param1'] > 0) {
                        $emp_sal_scores[$rec['salary_item_type_id']] = $Sayer_Score;
                        $score_sum += $rec['param1'];
                    }
                }
            }
        }
        if ($emp_sal_scores != "") {
            $emp_sal_items['<!---fix_salary_score-->'] = CurrencyModulesclass::toCurrency((isset($emp_sal_scores[34]) ? $emp_sal_scores[34] : 0) + (isset($emp_sal_scores[35]) ? $emp_sal_scores[35] : 0) + (isset($emp_sal_scores[36]) ? $emp_sal_scores[36] : 0));
        }
        if ($emp_sal_vals != "") {
            $emp_sal_items['<!---fix_salary_value-->'] = CurrencyModulesclass::toCurrency((isset($emp_sal_vals[34]) ? $emp_sal_vals[34] : 0) + (isset($emp_sal_vals[35]) ? $emp_sal_vals[35] : 0) + (isset($emp_sal_vals[36]) ? $emp_sal_vals[36] : 0));
        }
        $emp_sal_items['<!---salary_score-->'] = CurrencyModulesclass::toCurrency($score_sum);
        $emp_sal_items['<!---salary_sum-->'] = CurrencyModulesclass::toCurrency($sum);
    } else {
        if (!$writ_rec['corrective'] && $writ_rec['person_type'] == HR_EMPLOYEE && (DateModules::CompareDate($writ_rec['execute_date'], '2013-02-19') >= 0 || DateModules::CompareDate($writ_rec['execute_date'], '2014-03-20') >= 0) || $writ_rec['person_type'] == HR_CONTRACT && ($writ_rec['execute_date'] >= '2013-02-19' || DateModules::CompareDate($writ_rec['execute_date'], '2014-03-21') >= 0)) {
            $item_recset = manage_writ_item::GetAllWritItems("writ_id=? AND writ_ver=? AND staff_id=?", array($writ_rec['writ_id'], $writ_rec['writ_ver'], $writ_rec["staff_id"]));
            $emp_sal_items = array();
            $Sayer = 0;
            $Sayer_Score = 0;
            $score_sum = 0;
            foreach ($item_recset as $rec) {
                if ($rec['salary_item_type_id'] == 10364) {
                    $rec['salary_item_type_id'] = 10264;
                } elseif ($rec['salary_item_type_id'] == 10367) {
                    $rec['salary_item_type_id'] = 10267;
                } elseif ($rec['salary_item_type_id'] == 10366) {
                    $rec['salary_item_type_id'] = 10266;
                } elseif ($rec['salary_item_type_id'] == 10365) {
                    $rec['salary_item_type_id'] = 10265;
                } elseif ($rec['salary_item_type_id'] == 10373) {
                    $rec['salary_item_type_id'] = 10332;
                } elseif ($rec['salary_item_type_id'] == 10374) {
                    $rec['salary_item_type_id'] = 10333;
                } elseif ($rec['salary_item_type_id'] == 10328) {
                    $rec['salary_item_type_id'] = 10369;
                } elseif ($rec['salary_item_type_id'] == 10372) {
                    $rec['salary_item_type_id'] = 10331;
                } elseif ($rec['salary_item_type_id'] == 10371) {
                    $rec['salary_item_type_id'] = 10330;
                } elseif ($rec['salary_item_type_id'] == 10370) {
                    $rec['salary_item_type_id'] = 10329;
                } elseif ($rec['salary_item_type_id'] == 10368) {
                    $rec['salary_item_type_id'] = 10327;
                } elseif ($rec['salary_item_type_id'] == 10335) {
                    $rec['salary_item_type_id'] = 10376;
                } elseif ($rec['salary_item_type_id'] == 10334) {
                    $rec['salary_item_type_id'] = 10375;
                }
                $emp_sal_items['<!---item_' . $rec['salary_item_type_id'] . '-->'] = CurrencyModulesclass::toCurrency($rec['value'], 'CURRENCY');
                //$emp_sal_items['<!---item_'.$rec['salary_item_type_id'].'_score-->'] = $rec['param1'];
                if ($rec['value']) {
                    $emp_sal_vals[$rec['salary_item_type_id']] = $rec['value'];
                    $sum += $rec['value'];
                }
                /*if($rec['param1'])
                		{
                			$emp_sal_scores[$rec['salary_item_type_id']] = $rec['param1'] ;
                			$score_sum += $rec['param1'];
                		}*/
            }
            //$emp_sal_items['<!---salary_score-->'] = CurrencyModulesclass::toCurrency($score_sum);
            $emp_sal_items['<!---salary_sum-->'] = CurrencyModulesclass::toCurrency($sum);
        } else {
            if (!$writ_rec['corrective'] && ($writ_rec['person_type'] == HR_EMPLOYEE || $writ_rec['person_type'] == HR_PROFESSOR)) {
                ob_start();
                $item_recset = manage_writ_item::GetAllWritItems("writ_id=? AND writ_ver=? AND staff_id=?", array($writ_rec['writ_id'], $writ_rec['writ_ver'], $writ_rec["staff_id"]));
                $counter = 0;
                $sum = 0;
                foreach ($item_recset as $rec) {
                    echo "<tr>\n\t\t\t\t<td class='list-beginnormal' width='50%' style='padding-top:2; padding-bottom:2'>\n\t\t\t\t\t<span class='report_data'>" . $indx[$counter] . $rec['print_title'];
                    if ($rec['salary_item_type_id'] == SIT_PROFESSOR_FOR_BYLAW_15_3015) {
                        $content .= ' (' . $rec['param1'] . ' پايه)';
                    }
                    echo "</span>\n\t\t\t\t </td><td class='list-beginnormal' width='25%' style='padding-top:2; padding-bottom:2'>\n\t\t\t\t\t<span class='report_data'>" . CurrencyModulesclass::toCurrency($rec['value']) . "</span></td>\n\t\t\t\t\t\n\t\t\t\t<td class='list-beginnormal' width='25%' align='center' style='padding-top:2; padding-bottom:2'\n\t\t\t\t\t<span class='report_data'>ريال</span></td>\n\t\t\t</tr>";
                    $counter++;
                    $sum = $sum + $rec['value'];
                }
                if (!$item_recset && $writ_rec['person_type'] == HR_PROFESSOR) {
                    $salary_item_types_recSet = manage_writ_item::GetAllWritItems('person_type = ' . $writ_rec["person_type"] . ' AND compute_place = ' . SALARY_ITEM_COMPUTE_PLACE_WRIT . ' AND salary_compute_type = ' . SALARY_COMPUTE_TYPE_FUNCTION . ' AND user_data_entry = ' . AUTOMATIC . " AND validity_start_date <= '" . $writ_rec['execute_date'] . "' AND (validity_end_date >= '" . $writ_rec['execute_date'] . "' OR validity_end_date IS NULL)" . ' ORDER BY print_order');
                    if ($salary_item_types_recSet) {
                        foreach ($salary_item_types_recSet as $key => $salary_item_types_rec) {
                            echo "<tr>\n\t\t\t\t\t\t\t<td class='list-beginnormal' colspan='2' style='padding-top:2; padding-bottom:2'>" . $indx[$counter] . $salary_item_types_rec['print_title'];
                            if ($salary_item_types_rec['salary_item_type_id'] == SIT_PROFESSOR_FOR_BYLAW_15_3015) {
                                $content .= ' (' . $salary_item_types_rec['param1'] . ' پايه)';
                            }
                            echo "</td>\n\t\t\t\t\t\t<td class='list-beginnormal' style='padding-top:2; padding-bottom:2'> ----- </td>\n\t\t\t\t\t\t<td class='list-beginnormal' style='padding-top:2; padding-bottom:2'>ريال</td>\n\t\t\t\t\t</tr>";
                            $counter++;
                        }
                    }
                }
                for ($i = $counter; $i < 8; $i++) {
                    echo "<tr>\n\t\t\t\t<td class='list-beginnormal' width='50%' style='padding-top:2; padding-bottom:2'>&nbsp;</td>\n\t\t\t\t<td class='list-beginnormal' width='25%' style='padding-top:2; padding-bottom:2'>&nbsp;</td>\n\t\t\t\t<td class='list-beginnormal' width='25%' align='center' style='padding-top:2; padding-bottom:2'>&nbsp;</td>\n\t\t\t\t</tr>";
                }
                $salary_items = ob_get_contents();
                ob_end_clean();
            }
        }
    }
    // اقلام حقوقی کارکنان قراردادی
    if ($writ_rec["person_type"] == HR_CONTRACT && ($writ_rec["execute_date"] < '2013-02-19' || $writ_rec["execute_date"] >= '2013-03-21')) {
        $item_recset = manage_writ_item::GetAllWritItems("writ_id=? AND writ_ver=? AND staff_id=?", array($writ_rec['writ_id'], $writ_rec['writ_ver'], $writ_rec["staff_id"]));
        ob_start();
        $sum = 0;
        for ($i = 0; $i < count($item_recset); $i++) {
            $sum += $item_recset[$i]['value'];
            if ($i % 2 == 0 && $item_recset[$i]['value'] > 0) {
                $val1 = $item_recset[$i]['value'] > 0 ? CurrencyModulesclass::toCurrency($item_recset[$i]['value']) . " ریال" : "&nbsp;";
                $title1 = $item_recset[$i]['print_title'];
                $i++;
                if ($i < count($item_recset)) {
                    $sum += $item_recset[$i]['value'];
                    $val2 = $item_recset[$i]['value'] > 0 ? CurrencyModulesclass::toCurrency($item_recset[$i]['value']) . " ریال" : "&nbsp;";
                    $title2 = $item_recset[$i]['print_title'];
                } else {
                    $val2 = "&nbsp;";
                    $title2 = "&nbsp;";
                }
                echo "<tr>\n\t\t\t\t\t\t<td>" . $indx[$i - 1] . $title1 . "</td>\n\t\t\t\t\t\t<td align='left' class='money'>" . $val1 . "</td>\n\t\t\t\t\t\t<td> . " . $indx[$i] . $title2 . "</td>\n\t\t\t\t\t\t<td align='left' class='money'>" . $val2 . "</td></tr>";
            }
        }
        $salary_items = ob_get_contents();
        ob_end_clean();
    }
    if (!$writ_rec['corrective'] && $writ_rec['person_type'] == HR_WORKER) {
        $item_recset = manage_writ_item::GetAllWritItems("writ_id=? AND writ_ver=? AND staff_id=?", array($writ_rec['writ_id'], $writ_rec['writ_ver'], $writ_rec['staff_id']));
        if (count($item_recset) > 0) {
            $worker_salary_item1_title = $item_recset[0]['print_title'];
            $worker_salary_item1_value = CurrencyModulesclass::toCurrency($item_recset[0]['value']);
            $worker_salary_item2_title = $item_recset[1]['print_title'];
            $worker_salary_item2_value = CurrencyModulesclass::toCurrency($item_recset[1]['value']);
            $worker_base_salary = CurrencyModulesclass::toCurrency($sum);
        }
        ob_start();
        for ($i = 0; $i <= 9; $i++) {
            echo "<tr>\n\t\t\t\t\t<td width='80px'>" . (isset($item_recset[$i]) ? $item_recset[$i]['print_title'] : "") . "</td>\n\t\t\t\t\t<td align='left' class='money'>";
            $sum += isset($item_recset[$i]) ? $item_recset[$i]['value'] : 0;
            if (isset($item_recset[$i]) && $item_recset[$i]['value'] > 0) {
                echo CurrencyModulesclass::toCurrency($item_recset[$i]['value']);
            } else {
                echo "&nbsp;";
            }
            echo "</td>\n\t\t\t\t<td style='padding-left:4px' align='left' width='40px'>" . (isset($item_recset[$i]['value']) ? 'ريال' : "&nbsp;") . "</td></tr>";
            if ($i == 1) {
                echo "<tr>\n\t\t\t\t\t\t<td><span>جمع مزد مبنا:</span></td>\n\t\t\t\t\t\t<td class='money' style='font-size:12px' align='left'>";
                echo isset($item_recset[0]) && isset($item_recset[1]) ? CurrencyModulesclass::toCurrency($item_recset[1]['value'] + $item_recset[0]['value']) : "";
                echo "</td>\n\t\t\t\t\t\t<td style='padding-left:4px' align='left' width='40px'>ريال</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td style='background-color:#bbbbbb;font-family:titr' colspan=3>20 - مزد مزايا : </td>\n\t\t\t\t\t</tr>";
            }
        }
        $worker_other_salary_items = ob_get_contents();
        ob_end_clean();
    }
    // موارد مربوط به استخدام كشوري
    if ($writ_rec['person_type'] == HR_EMPLOYEE) {
        //  وضعيت قرارداد استخدام كشوري
        $prev_writ_obj = manage_writ::get_last_writ_by_date($writ_rec['staff_id'], $writ_rec['execute_date']);
        $contact_title = $prev_writ_obj->writ_id == "" ? 'انعقاد قرارداد' : 'تمديد قرارداد';
        // ضريب افزايش سنواتي استخدام كشوري
        $WritItemObj = new manage_writ_item($writ_rec['writ_id'], $writ_rec['writ_ver'], $writ_rec['staff_id'], SIT_STAFF_ANNUAL_INC);
        $sit2_annual_inc_coef = $WritItemObj->param2 * 100;
        // پست سازماني استخدام كشوري
        $specialExtraWritItemObj = new manage_writ_item($writ_rec['writ_id'], $writ_rec['writ_ver'], $writ_rec['staff_id'], SIT_EMPLOYEE_SPECIAL_EXTRA);
        if ($specialExtraWritItemObj->writ_id) {
            $post_title = $writ_rec['p_title'];
            if ($specialExtraWritItemObj->param1 >= 600 && $specialExtraWritItemObj->param1 < 1100) {
                $post_title .= ' (کارشناس ارشد)';
            } else {
                if ($specialExtraWritItemObj->param1 >= 1100 && $specialExtraWritItemObj->param1 < 1600) {
                    $post_title .= ' (کارشناس خبره)';
                } else {
                    if ($specialExtraWritItemObj->param1 >= 1600) {
                        $post_title .= ' (کارشناس عالي)';
                    }
                }
            }
        } else {
            $post_title = $writ_rec['p_title'];
        }
    }
    if ($writ_rec["person_type"] == HR_CONTRACT) {
        $post_title = $writ_rec["p_title"] . " - " . $writ_rec["p_post_no"];
    }
    // عنوان كامل واحد سازماني
    $org_unit_title = $full_title = manage_units::get_full_title($writ_rec['ouid']);
    $ArrayUnit = preg_split('/-/', $full_title);
    $cnt = count($ArrayUnit);
    if ($cnt == 1) {
        if ($writ_rec['emp_mode'] == 6) {
            $full_title .= "<b>مامور به </b>" . $writ_rec['MissionPlace'];
        }
        if ($writ_rec['emp_mode'] == 16) {
            $full_title .= "<b>مامور از </b>" . $writ_rec['MissionPlace'];
        }
    }
    if ($cnt > 1) {
        $full_title = '';
        for ($i = 0; $i < $cnt; $i++) {
            if ($i == $cnt - 1 && $cnt > 1 && $writ_rec['emp_mode'] != 6 && $writ_rec['emp_mode'] != 16) {
                $full_title .= "<b>شاغل در </b>" . $ArrayUnit[$i];
            } else {
                if ($i == $cnt - 1 && $cnt > 1 && ($writ_rec['emp_mode'] == 6 || $writ_rec['emp_mode'] == 16)) {
                    if ($writ_rec['emp_mode'] == 6) {
                        $full_title .= "<b>مامور به </b>" . $writ_rec['MissionPlace'];
                    }
                    if ($writ_rec['emp_mode'] == 16) {
                        $full_title .= "<b>مامور از </b>" . $writ_rec['MissionPlace'];
                    }
                } elseif ($i == $cnt - 2) {
                    $full_title .= $ArrayUnit[$i] . "&nbsp;";
                } else {
                    $full_title .= $ArrayUnit[$i] . "-";
                }
            }
        }
    }
    if ($writ_rec['emp_mode'] == EMP_MODE_ENGAGEMENT) {
        $full_title = manage_units::get_full_title($writ_rec['unitCode']);
        $full_title .= '(حالت اشتغال) ';
    } else {
        if ($writ_rec['o_ouid'] != $writ_rec['pos_ouid'] && $writ_rec['pos_ouid']) {
            $same_org_unit = $writ_rec['ou_ouid'] == $writ_rec['po_ouid'];
            $full_title = '';
            if ($writ_rec['person_type'] == HR_PROFESSOR && ($writ_rec['emp_state'] == EMP_STATE_PROBATIONAL_CEREMONIOUS || $writ_rec['emp_state'] == EMP_STATE_APPROVED_CEREMONIOUS)) {
                $full_title = 'موقت از ';
                $full_title .= $writ_rec['pos_ptitle'];
                $full_title .= ' - شاغل در ';
                $full_title .= $writ_rec['o_ptitle'];
                $os_ptitle = $full_title;
            } else {
                $full_title = '';
                if ($writ_rec['person_type'] == HR_PROFESSOR) {
                    $full_title = 'موقت از ';
                }
                $full_title .= manage_units::get_full_title($writ_rec['pouid']);
                if ($writ_rec['person_type'] == HR_PROFESSOR || $writ_rec['emp_mode'] != 6 && $writ_rec['emp_mode'] != 16) {
                    $full_title .= ' - شاغل در ';
                    if (!$same_org_unit) {
                        $full_title .= $ArrayUnit[0] . ' - ';
                    }
                    for ($i = 1; $i < $cnt; $i++) {
                        if ($i != $cnt - 1) {
                            $full_title .= $ArrayUnit[$i] . ' - ';
                        } else {
                            $full_title .= $ArrayUnit[$i];
                        }
                    }
                } else {
                    if ($writ_rec['person_type'] != HR_PROFESSOR && $writ_rec['emp_mode'] == 6) {
                        $full_title .= ' مامور به ' . $writ_rec['MissionPlace'];
                    } else {
                        if ($writ_rec['person_type'] != HR_PROFESSOR && $writ_rec['emp_mode'] == 16) {
                            $full_title .= ' مامور از  ' . $writ_rec['MissionPlace'];
                        }
                    }
                }
                $os_ptitle = $full_title;
            }
        }
    }
    if ($writ_rec['emp_mode'] == 13) {
        $full_title = $ArrayUnit[0];
    }
    //گروه آموزشي / پژوهشي هيات علمي
    // واحد سازماني فرعي
    // در صورتي كه پست فرد از يك واحدي غير از واحد سازماني فرد باشد شرح آن در واحد فرعي آمده
    if (!$os_ptitle) {
        $os_ptitle = $writ_rec['os_ptitle'];
    }
    // موارد مربوط به هيات علمي
    if ($writ_rec['person_type'] == HR_PROFESSOR) {
        // نوع پست هيات علمي
        if ($writ_rec['post_type'] == POST_PROFESSOR_RSC) {
            $professor_post_type = 'پژوهشي';
        }
        // نوع گروه هيات علمي
        if ($writ_rec['org_sub_unit_type'] == EDUCATIONAL) {
            $org_sub_unit_type = ' گروه آموزشي ';
        } else {
            if ($writ_rec['org_sub_unit_type'] == RESEARCH) {
                $org_sub_unit_type = ' گروه پژوهشي ';
            }
        }
        // عنوان حكم
        if ($writ_rec['corrective']) {
            $writ_title = 'حکم اصلاحي اعضاي هيات علمي';
        }
    }
    // موارد مربوط به حكم اصلاحي
    if ($writ_rec['corrective'] == 1) {
        // مبلغ درج شده در حكم اصلاحي
        // در صورتي که حکم اصلاحي جديد است
        if ($writ_rec['history_only']) {
            $dt = PdoDataAccess::runquery("SELECT writ_id , writ_ver, staff_id FROM writs\n\t\t\t\t\tWHERE corrective_writ_id = " . $writ_rec["writ_id"] . "\n\t\t\t\t\t\tAND corrective_writ_ver = " . $writ_rec["writ_ver"] . "\n\t\t\t\t\t\tAND staff_id = " . $writ_rec["staff_id"] . "\n\t\t\t\t\tORDER BY execute_date DESC , writ_id DESC , writ_ver DESC ");
            $corective_writ_rec = $dt[0];
            $corective_writ_items_obj = new manage_writ_item($corective_writ_rec["writ_id"], $corective_writ_rec["writ_ver"], $corective_writ_rec["staff_id"], SIT_STAFF_ANNUAL_INC);
            $sit2_annual_inc_coef = $corective_writ_items_obj->param2 * 100;
            $sum = manage_writ_item::compute_writ_items_sum($corective_writ_rec["writ_id"], $corective_writ_rec["writ_ver"], $corective_writ_rec["staff_id"]);
        } else {
            $sum = manage_writ_item::compute_writ_items_sum($writ_rec['writ_id'], $writ_rec['writ_ver'], $writ_rec["staff_id"]);
        }
    }
    if ($writ_rec['corrective'] != 1) {
        $exe_date_title = '
			<tr height=25>
				<td colspan=2>
					21-تاریخ اجرای حکم :
					<span>' . DateModules::miladi_to_shamsi($writ_rec['execute_date']) . '</span>
				</td>
		   </tr>';
    }
    /*****************************************************/
    $scores = array(1 => array(1 => 2400, 2 => 2650, 3 => 2650, 4 => 2650, 5 => 2650), 2 => array(1 => 2600, 2 => 2850, 3 => 2850, 4 => 2850, 5 => 2850), 3 => array(1 => 2800, 2 => 3050, 3 => 3050, 4 => 3050, 5 => 3050), 4 => array(1 => 3000, 2 => 3250, 3 => 3600, 4 => 4050, 5 => 4600), 5 => array(1 => 3200, 2 => 3450, 3 => 3800, 4 => 4250, 5 => 4800), 6 => array(1 => 3400, 2 => 3650, 3 => 4000, 4 => 4450, 5 => 5000), 7 => array(1 => 3600, 2 => 3850, 3 => 4200, 4 => 4650, 5 => 5200), 8 => array(1 => 3800, 2 => 4050, 3 => 4400, 4 => 4850, 5 => 5400), 9 => array(1 => 4000, 2 => 4250, 3 => 4600, 4 => 5050, 5 => 5600), 10 => array(1 => 4200, 2 => 4450, 3 => 4800, 4 => 5250, 5 => 5800), 11 => array(1 => 4400, 2 => 4650, 3 => 5000, 4 => 5450, 5 => 6000), 12 => array(1 => 4600, 2 => 4850, 3 => 5200, 4 => 5650, 5 => 6200), 13 => array(1 => 4800, 2 => 5050, 3 => 5400, 4 => 5850, 5 => 6400), 14 => array(1 => 5000, 2 => 5250, 3 => 5600, 4 => 6050, 5 => 6600), 15 => array(1 => 5200, 2 => 5450, 3 => 5800, 4 => 6250, 5 => 6800), 16 => array(1 => 5400, 2 => 5650, 3 => 6000, 4 => 6450, 5 => 7000));
    $current_group = $writ_rec['cur_group'];
    $grup = "";
    if ($writ_rec['person_type'] == HR_EMPLOYEE && DateModules::CompareDate($writ_rec['execute_date'], $equal_payment_system_gdate) >= 0) {
        $s = "";
        $indx = $current_group - 4;
        if ($emp_sal_scores != "" && $emp_sal_scores[34]) {
            $s = $emp_sal_scores[34];
        } else {
            $writ_obj = manage_writ::get_last_writ_by_date($writ_rec['staff_id'], $writ_rec['execute_date'], 34);
            if ($writ_obj->writ_id) {
                $item_obj = new manage_writ_item($writ_obj->writ_id, $writ_obj->writ_ver, $writ_obj->staff_id, 34);
                $s = $item_obj->param1;
            }
        }
        $grade = "";
        if ($scores[$indx][1] == $s) {
            $grade = 'مقدماتی';
        } else {
            if ($scores[$indx][2] == $s) {
                $grade = 'پایه';
            } else {
                if ($scores[$indx][3] == $s) {
                    $grade = 'ارشد';
                } else {
                    if ($scores[$indx][4] == $s) {
                        $grade = 'خبره';
                    } else {
                        if ($scores[$indx][5] == $s) {
                            $grade = 'عالی';
                        }
                    }
                }
            }
        }
        $current_group = $grade;
        $grup = $writ_rec['new_grup'];
    } else {
        $grup = $writ_rec['old_grup'];
    }
    $listPNO = "";
    if ($writ_rec['personel_no'] != NULL && $writ_rec['person_type'] == 1) {
        $listPNO = preg_split('/-/', $writ_rec['personel_no']);
    }
    /*****************************************************/
    $MilitaryD = "";
    if ($writ_rec['militaryID'] != 17) {
        $MilitaryD = " <militaryDate> شروع : <span><!--military_from_date--></span>\n                                                             پایان: <span><!--military_to_date--></span></militaryDate>\n\t\t";
    }
    if ($writ_rec['E_base'] == NULL && ($writ_rec['person_type'] == HR_EMPLOYEE || $writ_rec['person_type'] == HR_CONTRACT)) {
        $qry = " SELECT  w.staff_id,\n\t\t\t\t\t\t\t SUBSTRING_INDEX(SUBSTRING(max(CONCAT(w.execute_date,w.writ_id,'.',w.writ_ver)),11),'.',1) writ_id,\n\t\t\t\t\t\t\t\t\t\tSUBSTRING_INDEX(max(CONCAT(w.execute_date,w.writ_id,'.',w.writ_ver)),'.',-1) writ_ver\n\n\t\t\t\t\t FROM writs w\n\t\t\t\t\t\t\tINNER JOIN staff ls\n\t\t\t\t\t\t\t\tON(w.staff_id = ls.staff_id)\n\t\t\t\t\t\t\tINNER JOIN writ_salary_items wsi\n\t\t\t\t\t\t\t\t\t\tON w.staff_id = wsi.staff_id AND w.writ_id = wsi.writ_id AND\n\t\t\t\t\t\t\t\t\t\t\tw.writ_ver = wsi.writ_ver AND salary_item_type_id = 10364\n\n\t\t\t\t\t WHERE   w.staff_id = " . $writ_rec['staff_id'];
        $tmp2 = PdoDataAccess::runquery($qry);
        $qry = " select wsi.param8\n\t\t\t\t\t\tfrom writ_salary_items wsi\n\t\t\t\t\t\t\t\t\t\t \n                          where wsi.staff_id =" . $writ_rec['staff_id'] . " AND wsi.writ_id = " . $tmp2[0]['writ_id'] . " AND \n\t\t\t\t\t\t\t    wsi.writ_ver =" . $tmp2[0]['writ_ver'] . " AND  wsi.salary_item_type_id = 10364 ";
        $tmp = PdoDataAccess::runquery($qry);
        $writ_rec['E_base'] = !empty($tmp[0]['param8']) ? $tmp[0]['param8'] : 0;
    }
    if ($writ_rec['E_base'] == NULL || $writ_rec['E_base'] == 0) {
        if ($writ_rec["sex"] == 1 && $writ_rec["person_type"] == 2 && ($writ_rec["military_duration_day"] > 0 || $writ_rec["military_duration"] > 0)) {
            $totalDayWrt = DateModules::ymd_to_days($writ_rec["onduty_year"], $writ_rec["onduty_month"], $writ_rec["onduty_day"]);
            $totalDaySar = DateModules::ymd_to_days(0, $writ_rec["military_duration"], $writ_rec["military_duration_day"]);
            $resDay = $totalDayWrt - $totalDaySar;
            $Vyear = 0;
            $Vmonth = $Vday = 0;
            DateModules::day_to_ymd($resDay, $Vyear, $Vmonth, $Vday);
            $writ_rec['E_base'] = $Vyear;
            //echo $Vyear." ---- ".$baseRes[0]["IsarValue"]."--isa---".$otherPoint  ;  die() ;
        } else {
            $writ_rec['E_base'] = $writ_rec["onduty_year"];
        }
    }
    if ($writ_rec['ComputeGrade'] == NULL && ($writ_rec['person_type'] == HR_EMPLOYEE || $writ_rec['person_type'] == HR_CONTRACT)) {
        $qry = " select  wsi.param5 ComputeGrade\n\t\t\t\t\t\tfrom writs w inner join writ_salary_items wsi\n\t\t\t\t\t\t\t\t\t\t\ton w.staff_id = wsi.staff_id and\n\t\t\t\t\t\t\t\t\t\t\t\tw.writ_id = wsi.writ_id  and\n\t\t\t\t\t\t\t\t\t\t\t\tw.writ_ver = wsi.writ_ver and wsi.salary_item_type_id = 10364\n\n\t\t\t\t\t\t\t\t\t\twhere w.staff_id = " . $writ_rec["staff_id"] . " and \n           w.corrective_writ_id = " . $writ_rec["writ_id"] . " and\n\t\t\t\t\t\t\t\t\t\t\tw.corrective_writ_ver = " . $writ_rec["writ_ver"] . "\n\n\t\t\t\t\torder  by w.writ_id  , w.writ_id\n\n\t\t\t\t\tlimit 1";
        $tmp2 = PdoDataAccess::runquery($qry);
        $writ_rec['ComputeGrade'] = !empty($tmp2[0]['ComputeGrade']) ? $tmp2[0]['ComputeGrade'] : 0;
    }
    $GradeTitle = "";
    if ($writ_rec['ComputeGrade'] == 1) {
        $GradeTitle = "مقدماتی";
    } elseif ($writ_rec['ComputeGrade'] == 2) {
        $GradeTitle = "مهارتی";
    } elseif ($writ_rec['ComputeGrade'] == 3) {
        $GradeTitle = "3";
    } elseif ($writ_rec['ComputeGrade'] == 4) {
        $GradeTitle = "2";
    } elseif ($writ_rec['ComputeGrade'] == 5) {
        $GradeTitle = "1";
    }
    if ($writ_rec['marital_status'] == 3) {
        $writ_rec['marital_status_title'] = 'مجرد';
    } else {
        if ($writ_rec['marital_status'] == 4) {
            $writ_rec['marital_status_title'] = 'متاهل';
        }
    }
    $tags = array('<!--personel_no-->' => !empty($listPNO) && count($listPNO) > 1 ? $listPNO[1] . "-" . $listPNO[0] : $writ_rec['personel_no'], '<!--national_code-->' => $writ_rec['national_code'], '<!--ps_pfname-->' => $writ_rec['ps_pfname'], '<!--ps_plname-->' => $writ_rec['ps_plname'], '<!--ps_father_name-->' => $writ_rec['ps_father_name'], '<!--ps_idcard_no-->' => $writ_rec['ps_idcard_no'], '<!--si_ptitle-->' => $writ_rec['si_ptitle'], '<!--ci_ptitle-->' => $writ_rec['ci_ptitle'], '<!--issue_place-->' => $writ_rec['issue_place'], '<!--cb_ptitle-->' => $writ_rec['cb_ptitle'], '<!--ps_birth_place-->' => $writ_rec['ps_birth_place'], '<!--ps_birth_date-->' => DateModules::miladi_to_shamsi($writ_rec['ps_birth_date']), '<!--education_level_title-->' => $education_level_title, '<!--sf_ptitle-->' => $writ_rec['sf_ptitle'], '<!--sbs_title-->' => $writ_rec['sbs_title'], '<!--p_post_no-->' => $writ_rec['p_post_no'], '<!--jc_title-->' => $writ_rec['jc_title'], '<!--jf_title-->' => $writ_rec['jf_title'], '<!--grup-->' => $grup, '<!--E_base-->' => $writ_rec['E_base'], '<!--S_base-->' => $writ_rec['S_base'], '<!--T_base-->' => $writ_rec['T_base'], '<!--I_base-->' => $writ_rec['I_base'], '<!--Total_base-->' => $writ_rec['E_base'] + $writ_rec['S_base'] + $writ_rec['T_base'] + $writ_rec['I_base'], '<!--grade-->' => $GradeTitle, '<!--cur_group-->' => $current_group, '<!--post_title-->' => $post_title, '<!--onduty-->' => $onduty, '<!--sw_ptitle-->' => $writ_rec['sw_ptitle'], '<!--cw_ptitle-->' => $writ_rec['cw_ptitle'], '<!--sit2_annual_inc_coef-->' => $sit2_annual_inc_coef, '<!--marital_status_title-->' => $writ_rec['marital_status'] == 3 ? 'مجرد' : $writ_rec['marital_status_title'], '<!--included_children_count-->' => $writ_rec['sex'] == 1 || $writ_rec['family_responsible'] == 1 ? $writ_rec['included_children_count'] : $writ_rec['children_count'], '<!--contract_start_date-->' => DateModules::miladi_to_shamsi($writ_rec['contract_start_date']), '<!--contract_end_date-->' => DateModules::miladi_to_shamsi($writ_rec['contract_end_date']), '<!--ref_letter_no-->' => $writ_rec['ref_letter_no'], '<!--ref_letter_date-->' => DateModules::miladi_to_shamsi($writ_rec['ref_letter_date']), '<!--writ_type-->' => $writ_rec['writ_type'], '<!--description-->' => nl2br($writ_rec['description']), '<!--sum-->' => CurrencyModulesclass::toCurrency($sum), '<!--sum_str-->' => CurrencyModulesclass::CurrencyToString($sum), '<!--writ_signature_post_owner-->' => $writ_rec['writ_signature_post_owner'], '<!--writ_signature_post_title-->' => $writ_rec['writ_signature_post_title'], '<!--execute_date-->' => DateModules::miladi_to_shamsi($writ_rec['execute_date']), '<!--send_letter_no-->' => $writ_rec['send_letter_no'], '<!--issue_date-->' => DateModules::miladi_to_shamsi($writ_rec['issue_date']), '<!--ref_letter_no-->' => $writ_rec['ref_letter_no'], '<!--ref_letter_date-->' => DateModules::miladi_to_shamsi($writ_rec['ref_letter_date']), '<!--SALARY_ITEMS-->' => $salary_items, '<!--org_unit_title-->' => $org_unit_title, '<!--devotion_type-->' => $devotion_type, '<!--o_ptitle-->' => $writ_rec['ou_ptitle'], '<!--military-->' => $writ_rec['military'], '<!--MilitaryD-->' => $MilitaryD, '<!--sf_title-->' => $writ_rec['sf_title'], '<!--sbs_title-->' => $writ_rec['sbs_title'], '<!--snc_level-->' => $writ_rec['snc_level'], '<!--edu_c_ptitle-->' => $edu_c_ptitle, '<!--edu_u_ptitle-->' => $edu_u_ptitle, '<!--edu_doc_date-->' => $edu_doc_date, '<!--base-->' => $writ_rec['base'], '<!--worktime-->' => $writ_rec['worktime'], '<!--emp_st-->' => $writ_rec['person_type'] == 2 && ($writ_rec['emp_st'] == 3 || $writ_rec['emp_st'] == 4) ? str_replace('رسمی قطعی', 'رسمي', $writ_rec['emp_st']) : $writ_rec['emp_st'], '<!--org_sub_unit_type-->' => $org_sub_unit_type, '<!--os_ptitle-->' => $os_ptitle, '<!--full_title-->' => $full_title, '<!--gnd-->' => $writ_rec['gnd'] == "1" ? "مرد" : "زن", '<!--professor_post_type-->' => $professor_post_type, '<!--writ_title-->' => $writ_title, '<!--wst_title-->' => $writ_rec['wst_title'], '<!--staff_id-->' => $writ_rec['staff_id'], '<!--work_start_date-->' => DateModules::miladi_to_shamsi($writ_rec['work_start_date']), '<!--job_id-->' => $writ_rec['job_id'], '<!--j_title-->' => $writ_rec['j_title'], '<!--job_group-->' => $writ_rec['job_group'], '<!--contact_title-->' => $contact_title, '<!--worker_salary_item1_title-->' => $worker_salary_item1_title, '<!--worker_salary_item1_value-->' => $worker_salary_item1_value, '<!--worker_salary_item2_title-->' => $worker_salary_item2_title, '<!--worker_salary_item2_value-->' => $worker_salary_item2_value, '<!--WORKER_OTHER_SALARY_ITEMS-->' => $worker_other_salary_items, '<--worker_base_salary-->' => $worker_base_salary, '<!--sisIMAGEPATH-->' => "", '<!--exe_date_title-->' => $exe_date_title, '<!--notes-->' => $writ_rec["notes"], '<!--military_from_date-->' => DateModules::miladi_to_shamsi($writ_rec["military_from_date"]), '<!--military_to_date-->' => DateModules::miladi_to_shamsi($writ_rec["military_to_date"]), '<cr>' => '', '</cr>' => '', '<ncr>' => '', '</ncr>' => '', '<tlm>' => '', '</tlm>' => '', '<ntlm>' => '', '</ntlm>' => '', '<sts>' => '', '</nsts>' => '', '<cnt>' => '', '</cnt>' => '', '<ncnt>' => '', '</ncnt>' => '');
    if (is_array($emp_sal_items)) {
        $tags = array_merge($emp_sal_items, $tags);
    }
    // مشخص كردن فايل template مربوط به حكم
    $content .= file_get_contents("PrintWritTemplates/" . $template_file);
    //حذف قسمتهاي مربوط به حكم اصلاحي از حكم غير اصلاحي و برعكس
    $rgEx = "";
    $sep = "";
    if ($writ_rec['corrective']) {
        $rgEx .= $sep . "<ncr>|<\\/ncr>";
        $sep = "|";
    } else {
        $rgEx .= $sep . "<cr>|<\\/cr>";
        $sep = "|";
    }
    if (!$writ_rec['time_limited']) {
        $rgEx .= $sep . "<tlm>|<\\/tlm>";
        $sep = "|";
    } else {
        $rgEx .= $sep . "<ntlm>|<\\/ntlm>";
        $sep = "|";
    }
    if (!$writ_rec['req_staff_signature']) {
        $rgEx .= $sep . "<sts>|<\\/sts>";
        $sep = "|";
    } else {
        $rgEx .= $sep . "<nsts>|<\\/nsts>";
        $sep = "|";
    }
    if ($writ_rec["person_type"] == HR_CONTRACT) {
        /*if($writ_rec["sex"] == 2)
        		{
        			$rgEx .= $sep . "<children>|<\/children>";
        			$sep = "|";
        		}*/
        if (in_array($writ_rec['military_type'], array(2, 11, 13, 15, 16))) {
            $rgEx .= $sep . "<militaryDate>|<\\/militaryDate>";
            $sep = "|";
        }
    }
    $parts = "";
    if (preg_match("/(.{$rgEx}.)/", $content)) {
        $parts = preg_split('/(' . $rgEx . ')/', $content);
    }
    if ($parts) {
        $content = "";
        for ($i = 0; $i < count($parts); $i++) {
            if ($i % 2 == 0) {
                $content .= $parts[$i];
            }
        }
    }
    $content = str_replace(array_keys($tags), array_values($tags), $content);
    return $content;
}