Esempio n. 1
0
	private function compute_salary_item3_47($writ_rec) {


		// should be deleted at the first of 91 ------------------------------------------
		$MONTH_DAY_COUNT = ($writ_rec["person_type"] == HR_WORKER) ? 31 : MONTH_DAY_COUNT;

		if ($writ_rec['execute_date'] >= '2012-03-20') {
			$MONTH_DAY_COUNT = 30;
		}

		$k = 0;
		$devotion_coefs = manage_person_devotion::get_devotions_last_coefs($writ_rec['staff_id'] ,"", $writ_rec["person_type"] );
		$prisoner = $devotion_coefs['prisoner'] / 30;
		$fighter = $devotion_coefs['fighter'] / 30;
                                    
		if ( ($writ_rec["person_type"] == HR_WORKER) && ($prisoner >= 9 || $fighter >= 9))
			$k = 1;
		else if ($writ_rec["person_type"] == HR_WORKER)  {

			$query = "SELECT s.staff_id,
						CASE WHEN pd.devotion_type=" . DEVOTION_TYPE_FIGHTER . "
									 THEN if(( pd.from_date <= '1988-08-20' and to_date <= '1988-08-20' ),amount ,
										  if(( pd.from_date <= '1988-08-20' and to_date >= '1988-08-20' ) ,
											   datediff('1988-08-20',pd.from_date ) ,0 )) END fighter ,
						CASE WHEN pd.devotion_type=" . DEVOTION_TYPE_PRISONER . " THEN amount ELSE 0 END prisoner

				 FROM staff s
					 INNER JOIN persons p ON (p.personID = s.personID)
					 INNER JOIN person_devotions pd ON (pd.personID = p.personID)
				 WHERE s.staff_id =" . $writ_rec['staff_id'];

			$res = parent::runquery($query);

			for ($i = 0; $i < count($res); $i++) {
				if (($res[$i]['fighter'] / 30 ) >= 6 || ($res[$i]['prisoner'] / 30 ) >= 6) {
					$k = 1;
					break;
				}
			}
		}
                else if ($devotion_coefs['prisoner'] >= 1 || $devotion_coefs['fighter'] >= 1 ) 
                    $k = 1;
          
		if ($devotion_coefs['wounded'] > 0 || $k == 1) { 
			if (!(1 <= $writ_rec['job_group'] && $writ_rec['job_group'] <= 20)) {
				parent::PushException(UNKNOWN_JOB_GROUP);
				return false;
			}

			$job_group = $writ_rec['job_group'];
			$this->param1 = $job_group;
			$cur_value = manage_salary_params::get_salaryParam_value("", $writ_rec['person_type'].",101", SPT_JOB_SALARY, $writ_rec['execute_date'], $job_group);

			if (!(0 < $cur_value)) {
				parent::PushException(UNKNOWN_JOB_SALARY);
				return false;
			}
			$this->param2 = $cur_value;

			$next_value = manage_salary_params::get_salaryParam_value("", $writ_rec['person_type'].",101", SPT_JOB_SALARY, $writ_rec['execute_date'], $job_group + 1);

			if (!(0 < $next_value)) { 
				parent::PushException(UNKNOWN_JOB_SALARY);
				return false;
			}
			$this->param3 = $next_value;
			$value = ($next_value - $cur_value) * $MONTH_DAY_COUNT;

			if ($value <= 0)
				return 0;
			else
				return $value;
		} 


		return 0;
	}
Esempio n. 2
0
function DelDev()
{
    $return = manage_person_devotion::RemoveDevotion($_POST['PersonID'], $_POST['devotion_row']);
    if ($return !== true) {
        echo $return;
        die;
    }
    echo Response::createObjectiveResponse("true", $_POST['PersonID']);
    die;
}
Esempio n. 3
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;
}
Esempio n. 4
0
 /**
  * تنها با استفاده از اين تابع مي توان حکم جديد صادر کرد
  * @return boolean : قرار مي دهد  ExceptionHandler اگر صدور حکم با موفقيت انجام نشود توضيح خطا را در
  */
 private function IssueWritAction($indiv = NULL)
 {
     $temp = parent::runquery("select last_writ_id,last_writ_ver,staff_id,PersonID,person_type from HRM_staff\n   \t\t\t\t\t\t\t\t\t\t\twhere staff_id=" . $this->staff_id . " and person_type =" . $this->person_type);
     if (count($temp) == 0) {
         parent::PushException(ERROR_STAFF_ID_NOT_FOUND);
         return false;
     }
     $staff_rec = $temp[0];
     $PersonID = $staff_rec['PersonID'];
     //___________________________________________________________
     //در صورتي که روال ناتمام اصلاح وجود دارد
     if ($this->correct_is_not_completed($this->staff_id)) {
         parent::PushException(ERROR_CORRECT_IS_NOT_COMPLETED);
         return false;
     }
     //___________________________________________________________
     //در صورتي که حکم خودکار است کنترلهاي زير اعمال شود
     $is_auto = $this->is_auto_writ($this->execute_date, $this->person_type);
     if ($is_auto) {
         //___________________________________________________________
         $lastWritObj = manage_writ::GetLastWrit($this->staff_id);
         $writ_subtype_obj = new manage_writ_subType($this->person_type, $this->writ_type_id, $this->writ_subtype_id);
         //.........................................................................................
         if (($this->person_type == 5 || $writ_subtype_obj->emp_state == 2) && $this->contract_start_date != NULL && substr(DateModules::miladi_to_shamsi($this->execute_date), 0, 4) != substr(DateModules::miladi_to_shamsi($this->contract_start_date), 0, 4)) {
             parent::PushException(ER_CONTRACT_DATE);
             return false;
         }
         //.........................................................................................
         //..... در صورتی که فرد بازنشسته باشد ولی آزاده باشد امکان صدور حکم برای فرد میسر می باشد ................
         //.... جانباز نیز بهمین صورت...................................................................
         $Azadegi = manage_person_devotion::get_person_devotions($PersonID, "(2,3)");
         //...................................................................................................
         //کنترل مي کند که در صورتي که شخص بازنشسته شده باشد براي او حکمي صادر نشود.
         if (!empty($lastWritObj->writ_id) && $lastWritObj->execute_date < $this->execute_date && !$this->history_only) {
             if (($lastWritObj->emp_mode == EMP_MODE_RETIRE && $Azadegi[0]['amount'] <= 0 || $lastWritObj->emp_mode == EMP_MODE_RE_BUY || $lastWritObj->emp_mode == EMP_MODE_RUSTICATION || $lastWritObj->emp_mode == EMP_MODE_PERMANENT_BREAK || $lastWritObj->emp_mode == EMP_MODE_BREAKAWAY || $lastWritObj->emp_mode == EMP_MODE_CONVEYANCE && $writ_subtype_obj->emp_mode != 16) && $this->corrective_writ_id == PDONULL) {
                 parent::PushException(ERROR_FOR_RETIRED_PERSONS_CAN_NOT_ISSUE_WRIT);
                 return false;
             }
         }
         //___________________________________________________________
     }
     if (!empty($lastWritObj->writ_id)) {
         parent::FillObjectByObject($lastWritObj, $this);
         //--------بررسی مجدد تیک مربوط به سرپرست خانواده ----------------------------
         $query = "select family_responsible from HRM_writs\n\t\t\t\t\t\twhere staff_id=:stfid and (history_only != " . HISTORY_ONLY . " OR history_only IS NULL)\n\t\t\t\t\t\t\torder by execute_date DESC,writ_id DESC,writ_ver DESC ";
         $whereParam = array(":stfid" => $this->staff_id);
         $resResponsible = parent::runquery($query, $whereParam);
         $this->family_responsible = $resResponsible[0]['family_responsible'];
         //--------------------------------------------------------------------------
         //اگر حكم قبلي در محاسبه حقوق استفاده شده باشد و يا در وضعيت مياني باشد
         //اين حكم كه اطلاعات حكم قبلي را كپي مي كند نبايد مقدار وضعيت آن را نيز كپي كند
         $this->state = 1;
         if (!$this->corrective_writ_id && !$this->corrective_writ_ver || $this->corrective_writ_id == PDONULL && $this->corrective_writ_ver == PDONULL) {
             $this->correct_completed = 0;
         }
         //___________________________________________________________
         //در صورتي که حکم يکي از شرايط زير را داشته باشد مي تواند بدون
         // رعايت توالي تاريخي صادر شود :
         // خودکار نباشد - حکم اصلاحي و يا در حال اصلاح باشد - حکم فقط ثبت سابقه باشد
         if ($this->is_new_writ($this->execute_date, $this->person_type) && !$this->corrective && $this->corrective_writ_id == PDONULL && !$this->history_only) {
             if ($this->execute_date < $lastWritObj->execute_date && $indiv == NULL) {
                 parent::PushException(EXECUTE_DATE_OF_NORMAL_WRIT_CANT_BEFORE_LAST_ONE_ERR);
                 return false;
             }
         }
         //__________________________________________________________
         // محاسبه سنوات خدمت فرد
         $duty_duration = $this->duty_year_month_day($this->staff_id, "", $this->execute_date);
         $this->onduty_year = !empty($duty_duration['year']) ? $duty_duration['year'] : 0;
         $this->onduty_month = !empty($duty_duration['month']) ? $duty_duration['month'] : 0;
         $this->onduty_day = !empty($duty_duration['day']) ? $duty_duration['day'] : 0;
         /*  if( $this->person_type != HR_CONTRACT ){
              $related_duty_duration = $this->related_duty_years($this->staff_id, $this->execute_date, $this->post_id, "INSERT");
              $this->related_onduty_year   = !empty($related_duty_duration['year']) ? $related_duty_duration['year'] : 0;
              $this->related_onduty_month  = !empty($related_duty_duration['month']) ? $related_duty_duration['month'] : 0;
              $this->related_onduty_day    = !empty($related_duty_duration['day']) ? $related_duty_duration['day'] : 0;
             } */
         if ($this->person_type == HR_EMPLOYEE || $this->person_type == HR_CONTRACT) {
             /*if($lastWritObj->execute_date > '2014-03-20')
             		   $this->base = $lastWritObj->base ; 
             		else {*/
             $Pqry = " select sex , military_duration_day ,military_duration  \n\t\t\t\t\t\t\t\t\tfrom HRM_persons p inner join HRM_staff s on p.personid = s.personid \n\t\t\t\t\t\t\t\t\t\t\twhere s.staff_id=" . $this->staff_id;
             $Pres = parent::runquery($Pqry);
             if ($Pres[0]["sex"] == 1 && $this->person_type == 2 && ($Pres[0]["military_duration_day"] > 0 || $Pres[0]["military_duration"] > 0)) {
                 $totalDayWrt = DateModules::ymd_to_days($this->onduty_year, $this->onduty_month, $this->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 {
                 /*$totalDayWrt = DateModules::ymd_to_days($this->onduty_year, $this->onduty_month , $this->onduty_day ) ; 							
                 
                 							$diffYear = DateModules::getDateDiff(DateModules::Now(),'2014-03-21');
                 
                 							$remainDay = $totalDayWrt - $diffYear ; 
                 
                 							DateModules::day_to_ymd($remainDay, $Ryear, $Rmonth, $Rday) ; 
                 							$Vyear = $Ryear  ;*/
                 $Vyear = $this->onduty_year;
             }
             $this->base = $Vyear + 1;
             /*}*/
         }
         if ($this->person_type == HR_WORKER) {
             $qry = " select job_id\n\t\t\t\t\tfrom HRM_writs\n\t\t\t\t\twhere execute_date < '" . $this->execute_date . "' and staff_id = " . $this->staff_id . "\n\t\t\t\t\torder by execute_date  Desc\n\t\t\t\t\tlimit 1 ";
             $resJob = PdoDataAccess::runquery($qry);
             $this->job_id = empty($resJob[0]['job_id']) ? 0 : $resJob[0]['job_id'];
         }
         //__________________________________________________________
     } else {
         //___________________________________________________________
         $this->onduty_year = 0;
         $this->onduty_month = 0;
         $this->onduty_day = 0;
         /* $this->related_onduty_year   = 0;
            $this->related_onduty_month  = 0;
            $this->related_onduty_day    = 0; */
         //$this->grade = 1 ;
         $this->family_responsible = 0;
         $this->job_id = PDONULL;
     }
     //___________________________________________________________
     // محاسبه اطلاعات مربوط به آخرين مدرک تحصيلي فرد
     $education_level_rec = manage_person_education::GetEducationLevelByDate($PersonID, $this->execute_date, $is_auto);
     if ($education_level_rec === false) {
         //در صورتي که حکم دستي است بدون مدرک مي توان حکم را ثبت نمود
         if ($is_auto) {
             return false;
         } else {
             // در صورتي که حکم دستي و براي فرد مدرک تحصيلي مشخص نشده ، تحصيلات بيسواد ثبت مي شود
             $education_level_rec['max_education_level'] = '101';
         }
     }
     $this->education_level = $education_level_rec != 101 ? $education_level_rec['max_education_level'] : '101';
     $this->sfid = isset($education_level_rec['sfid']) ? $education_level_rec['sfid'] : "";
     $this->sbid = isset($education_level_rec['sbid']) ? $education_level_rec['sbid'] : "";
     if ($this->person_type == HR_CONTRACT) {
         //$this->job_id = 1111;
     }
     //__________________________________________________________
     // محاسبه تعداد فرزندان
     $where = "PersonID=" . $PersonID . "\n\t\t\t\t  AND (dependency = 5 or dependency = 6)\n\t\t\t\t  AND birth_date <='" . $this->execute_date . "'";
     $no = manage_person_dependency::CountDependency($where);
     $this->children_count = $no;
     //__________________________________________________________
     // محاسبه افراد تحت تکفل فرد
     $this->included_children_count = manage_person_dependency::bail_count($PersonID, $this->person_type, $this->execute_date, $this->execute_date);
     //__________________________________________________________
     // تعيين وضعيت تاهل و ايثارگري
     $person_obj = new manage_person($PersonID);
     $this->marital_status = $person_obj->marital_status;
     $this->military_status = $person_obj->military_status;
     $this->military_type = $person_obj->military_type;
     //__________________________________________________________
     $this->writ_ver = 1;
     if ($this->corrective == true) {
         $this->corrective = 1;
         $this->description = "";
     } else {
         if ($this->corrective_writ_id == PDONULL && $this->corrective_writ_ver == PDONULL) {
             $this->corrective = 0;
             $this->corrective_writ_id = PDONULL;
             $this->corrective_writ_ver = PDONULL;
             $this->corrective_date = '0000-00-00';
             //PDONULL;
         }
     }
     $this->send_letter_date = $this->issue_date;
     $this->pay_date = $this->execute_date > $this->issue_date ? $this->execute_date : $this->issue_date;
     $this->ref_letter_no = !empty($lastWritObj->ref_letter_no) ? $lastWritObj->ref_letter_no : PDONULL;
     //$this->ref_letter_date = (!empty($lastWritObj->ref_letter_date) ) ?  $lastWritObj->ref_letter_date : PDONULL ;
     //__________________________________________________________
     //جايگزيني مقادير مربوط به نوع اصلي و فرعي حکم
     if ($writ_subtype_obj->time_limited != 1) {
         $this->contract_start_date = '0000-00-00';
         PDONULL;
         $this->contract_end_date = '0000-00-00';
         //PDONULL;
     }
     if ($writ_subtype_obj->salary_pay_proc > 0) {
         $this->salary_pay_proc = $writ_subtype_obj->salary_pay_proc;
     }
     if ($writ_subtype_obj->annual_effect > 0) {
         $this->annual_effect = $writ_subtype_obj->annual_effect;
     }
     if ($writ_subtype_obj->emp_state > 0) {
         $this->emp_state = $writ_subtype_obj->emp_state;
     }
     if ($writ_subtype_obj->emp_mode > 0) {
         $this->emp_mode = $writ_subtype_obj->emp_mode;
     }
     if ($writ_subtype_obj->worktime_type > 0) {
         $this->worktime_type = $writ_subtype_obj->worktime_type;
     }
     if ($writ_subtype_obj->post_effect == FREE_POST_EFFECT) {
         $this->post_id = PDONULL;
     }
     if (!$writ_subtype_obj->remember_distance) {
         $writ_subtype_obj->remember_distance = 0;
     }
     if ($writ_subtype_obj->remember_distance > 0) {
         $this->warning_date = DateModules::AddToGDate($this->execute_date, 0, $writ_subtype_obj->remember_distance);
     } else {
         $this->warning_date = '0000-00-00';
     }
     //PDONULL;
     $this->warning_message = $writ_subtype_obj->remember_message;
     $this->description = $writ_subtype_obj->comments;
     if ($this->corrective == true || $this->corrective == 1) {
         $this->description = PDONULL;
     }
     $this->writ_signature_post_owner = $this->issue_date > '2014-02-01' ? ' مهدی پور' : WRIT_SIGNATURE_POST_OWNER;
     $this->writ_signature_post_title = WRIT_SIGNATURE_POST_TITLE;
     // براي افراد پيماني هر حکم جديد قرارداد جديد مي باشد .
     // بنابراين تاريخ شروع قرارداد تاريخ اجراي حکم خواهد بود .
     // تاريخ خاتمه قرارداد پرسنل قراردادي پايان سال خواهد بود .
     if ($writ_subtype_obj->time_limited == 1 && ($this->emp_state == EMP_STATE_CONTRACTUAL || $this->emp_state == EMP_STATE_SOLDIER_CONTRACTUAL || $this->emp_state == EMP_STATE_ONUS_SOLDIER_CONTRACTUAL)) {
         $this->contract_start_date = $this->execute_date;
         $arr = preg_split('/\\//', DateModules::Miladi_to_Shamsi($this->execute_date));
         $Jdate = $arr[0] . "/12/29";
         $this->contract_end_date = DateModules::Shamsi_to_Miladi($Jdate);
     }
     //__________________________________________________________
     $this->remembered = PDONULL;
     $this->dont_transfer = PDONULL;
     if ($this->history_only && ($this->state == WRIT_PERSONAL || $this->state == PDONULL)) {
         $this->history_only = 1;
     } else {
         $this->history_only = 0;
     }
     //__________________________________________________________
     $this->job_id = empty($this->job_id) ? PDONULL : $this->job_id;
     //---------------------
     $pObj = new manage_person("", $this->staff_id);
     if ($pObj->sex == 2 && $pObj->marital_status == 1) {
         $this->family_responsible = 0;
     }
     if ($pObj->sex == 1 && ($this->person_type == 3 || $this->person_type == 5) && $this->marital_status == 2) {
         $this->family_responsible = 1;
     }
     if ($pObj->sex == 2 && $this->person_type == 5 && $this->execute_date > '2014-03-20') {
         $this->family_responsible = 0;
     }
     //.............................................
     $pdo = parent::getPdoObject();
     /*@var $pdo PDO*/
     $pdo->beginTransaction();
     $this->writ_id = manage_writ::LastID() + 1;
     if (empty($this->writ_id)) {
         parent::PushException("خطاي کد آخرين رکورد");
         $pdo->rollBack();
         return false;
     }
     if (!$this->onBeforeInsert()) {
         $pdo->rollBack();
         return false;
     }
     $return = parent::insert("HRM_writs", $this);
     if (!$return) {
         parent::PushException("ايجاد با شکست مواجه شد");
         $pdo->rollBack();
         return false;
     }
     $this->onAfterInsert();
     $pdo->commit();
     return true;
 }
Esempio n. 5
0
 static function get_devotion_score($staff_id, $gdate = "")
 {
     $devotion_coefs = manage_person_devotion::get_devotions_last_coefs($staff_id, $gdate);
     if ($gdate >= '2010-03-21') {
         $query = " SELECT s.staff_id,s.person_type , s.personid\n\t\t\t\t\t\t  \t FROM staff s\n\t\t\t\t\t\t\t\t WHERE s.staff_id = " . $staff_id;
         $res = parent::runquery($query);
         $person_family_shohada = manage_person_devotion::get_person_devotions($res[0]["personid"], '(' . BEHOLDER_FAMILY_DEVOTION . ')', BOY . ',' . DAUGHTER);
         if ($person_family_shohada && $devotion_coefs['wounded'] < 50 && $res[0]["person_type"] == 2) {
             $devotion_coefs['wounded'] = 50;
         }
     }
     $d1_value = $devotion_coefs['wounded'];
     $d2_value = $devotion_coefs['prisoner'] / 30;
     $d3_value = $devotion_coefs['fighter'] / 30;
     //جانبازی
     $d_array1 = array(array("start" => 4.999, "end" => 5, "score" => 400), array("start" => 5, "end" => 10, "score" => 500), array("start" => 10, "end" => 15, "score" => 600), array("start" => 15, "end" => 20, "score" => 700), array("start" => 20, "end" => 25, "score" => 800), array("start" => 25, "end" => 30, "score" => 900), array("start" => 30, "end" => 35, "score" => 1000), array("start" => 35, "end" => 40, "score" => 1100), array("start" => 40, "end" => 45, "score" => 1200), array("start" => 45, "end" => 50, "score" => 1300), array("start" => 50, "end" => 60, "score" => 1500), array("start" => 60, "end" => 200, "score" => 1550));
     $score1 = 0;
     foreach ($d_array1 as $arr) {
         if ($arr["start"] < $d1_value && $arr["end"] >= $d1_value) {
             $score1 = $arr["score"];
             break;
         }
     }
     // اسارت
     $d_array2 = array(array("start" => 2.999, "end" => 6, "score" => 400), array("start" => 6, "end" => 12, "score" => 500), array("start" => 12, "end" => 18, "score" => 600), array("start" => 18, "end" => 24, "score" => 700), array("start" => 24, "end" => 30, "score" => 800), array("start" => 30, "end" => 36, "score" => 900), array("start" => 36, "end" => 42, "score" => 1000), array("start" => 42, "end" => 48, "score" => 1100), array("start" => 48, "end" => 54, "score" => 1200), array("start" => 54, "end" => 60, "score" => 1300), array("start" => 60, "end" => 70, "score" => 1500), array("start" => 70, "end" => 300, "score" => 1550));
     $score2 = 0;
     foreach ($d_array2 as $arr) {
         if ($arr["start"] < $d2_value && $arr["end"] >= $d2_value) {
             $score2 = $arr["score"];
             break;
         }
     }
     // رزمندگی
     $d_array3 = array(array("start" => 2.999, "end" => 6, "score" => 400), array("start" => 6, "end" => 12, "score" => 500), array("start" => 12, "end" => 18, "score" => 600), array("start" => 18, "end" => 24, "score" => 700), array("start" => 24, "end" => 30, "score" => 800), array("start" => 30, "end" => 36, "score" => 900), array("start" => 36, "end" => 42, "score" => 1000), array("start" => 42, "end" => 48, "score" => 1100), array("start" => 48, "end" => 54, "score" => 1200), array("start" => 54, "end" => 60, "score" => 1300), array("start" => 60, "end" => 70, "score" => 1500), array("start" => 70, "end" => 300, "score" => 1550));
     $score3 = 0;
     foreach ($d_array3 as $arr) {
         if ($arr["start"] < $d3_value && $arr["end"] >= $d3_value) {
             $score3 = $arr["score"];
             break;
         }
     }
     // ایثارگری که بالاترین امتیاز را دارد به اضافه ی 25 درصد سایر ایثارگری ها تا سقف 1550 امتیاز
     $max = max(array($score1, $score2, $score3));
     $sum = $score1 + $score2 + $score3;
     //return min(array($max + 0.25 * ($sum - $max),1550)) ;
     return min(array($sum, 1550));
 }