Example #1
0
	/** حق شغل */
	private function compute_salary_item2_34($writ_rec) {
		//param1 : امتیاز
		//param2 : 
		//param3 :
		//param4 :
		//param5 :
		//param6 :
		//param7 :


                if($writ_rec['execute_date'] >='2013-02-19' && $writ_rec['execute_date'] < '2013-03-20' ) 
		{

			return ;
		}

		$job_level = "";

		// در وضعیت ثبت حکم پارامتر 4 را از حکم قبلي می خواند
		//در صورتي که کاربر آن را به روز رساني کند مقدار ثبت شده توسط کاربر مد نظر قرار می گيرد
		if ($this->param4 === null) {
			$obj = new manage_writ();
			parent::FillObjectByArray($obj, $writ_rec);
			$prior_writ = $obj->get_prior_writ("","",$writ_rec['execute_date']);

			if (!empty($prior_writ->writ_id)) {
				$item34 = new manage_writ_item($prior_writ->writ_id, $prior_writ->writ_ver, $prior_writ->staff_id, 34);
				if ($item34 && $item34->param4)
					$this->param4 = $item34->param4;
			}
		}

		$jdate = '1387/12/30';
		$date = DateModules::Shamsi_to_Miladi($jdate);
		$last_writ = manage_writ::get_last_writ_by_date($writ_rec['staff_id'], $date);
		$max_education_level = $writ_rec['education_level'];

		$Jexecute_date = DateModules::Miladi_to_Shamsi($writ_rec["execute_date"]);
		if ($Jexecute_date >= '1388/01/01')
			$new_emmployee = true;
		else
			$new_emmployee = false;

		$salary_item_type_166 = null;
		$salary_item_type_12 = null;

		if (!empty($last_writ->writ_id)) {
                  
			$salary_item_type_166 = new manage_writ_item($last_writ->writ_id, $last_writ->writ_ver, $last_writ->staff_id, 166);
			if (empty($salary_item_type_166->salary_item_type_id)) {
				$salary_item_type_12 = new manage_writ_item($last_writ->writ_id, $last_writ->writ_ver, $last_writ->staff_id, 12);
			}
		}
                   
           
		// level , job_level
		$scores = array(
			1 => array(1 => 2400, 2 => 2650, 3 => 2650, 4 => 2650, 5 => 2650),
			2 => array(1 => 2600, 2 => 2850, 3 => 2850, 4 => 2850, 4 => 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)
				);

		if (!empty($last_writ->writ_id)) {
			if ($writ_rec['cur_group'] < 6)
				$level = 1;
			else
				$level = $writ_rec['cur_group'] - 4;
		}
		else {
			if ($writ_rec['cur_group'] < 6)
				$level = 1;
			else
				$level = $writ_rec['cur_group'] - 4;
		}

		//در صورتی که به فرد نه ویژه و نه هعمترازی تعلق نگرفته باشد در سطح یک قرار می گیرد.

		if (!$salary_item_type_12 && !$salary_item_type_166) {

			$job_level = 1;
		}
 
		//به فرد در آخرین حکم سال 87 ویژه تعلق می گرفته است.
		$vije_include = false;
		if ($salary_item_type_166) {
			if ($salary_item_type_166->param1 >= 600 && $salary_item_type_166->param1 < 1100) {
				$job_level = 3;
				$vije_include = true;
			} else if ($salary_item_type_166->param1 >= 1100 && $salary_item_type_166->param1 < 1600) {
				$job_level = 4;
				$vije_include = true;
			} else if ($salary_item_type_166->param1 >= 1600) {
				$job_level = 5;
				$vije_include = true;
			}
		}
		//به فرد در آخرین حکم سال 87 تفاوت همترازی تعلق گرفته است.
		if ($salary_item_type_12 && !empty($salary_item_type_12->writ_id)) {
                    
			$person_devotions = manage_person_devotion::get_person_devotions($writ_rec["PersonID"], "(" . SACRIFICE_DEVOTION . ")");
			$person_family_shohada =  manage_person_devotion::get_person_devotions($writ_rec['PersonID'], '(' . BEHOLDER_FAMILY_DEVOTION . ')', BOY . ',' . DAUGHTER);
                       
			if (($max_education_level == 500 || $max_education_level == 501)) {
				$coef = 3;
				$vije_include = true;
			} else if ($max_education_level > 501) {
				$coef = 4;
				$vije_include = true;
			}
			if (count($person_devotions) != 0 || count($person_family_shohada) != 0) {
				$coef++;
			}
			if ($coef) {
				$job_level = $coef;
			}
		}

		if ($writ_rec['person_type'] != 1 && $job_level > 4) {
			$job_level = 4;
		}

		if ($writ_rec['onduty_year'] >= 30) {
			$writ_rec['onduty_year'] = 30;
			$writ_rec['onduty_month'] = 0;
			$writ_rec['onduty_day'] = 0;
		}

		if (!$vije_include) {                    
                     
			$related_onduty_year = ($writ_rec['related_onduty_year'] +
					($writ_rec['related_onduty_month'] / 12) +
					($writ_rec['related_onduty_day'] / 365.25)) / 6;

			if ($new_emmployee)
				$coef = 1 / 12;
			else
				$coef = 0.1;
			$onduty_year = (($writ_rec['onduty_year'] - $writ_rec['related_onduty_year']) +
					(($writ_rec['onduty_month'] - $writ_rec['related_onduty_month']) / 12) +
					(($writ_rec['onduty_day'] - $writ_rec['related_onduty_month']) / 365.25)) * $coef;

			// احتساب مضاعف سنوات آزادگان
			$dev_add_coef = 0;
			$person_devotions = manage_person_devotion::get_person_devotions($writ_rec["PersonID"], "(" . FREEDOM_DEVOTION . ")");
                        $person_family_shohada =  manage_person_devotion::get_person_devotions($writ_rec['PersonID'], '(' . BEHOLDER_FAMILY_DEVOTION . ')', BOY . ',' . DAUGHTER);
                        
			if ( ( count($person_devotions) > 0  && $person_devotions[0]['amount'] > 0 ) || 
                               count($person_family_shohada) > 0 )
				$dev_add_coef = 1;

			$job_level += floor(($related_onduty_year + $onduty_year) * (1 + $dev_add_coef));

			if ($writ_rec['person_type'] != 1 && $job_level > 4) {
				$job_level = 4;
			}

			$result = manage_posts::get_job_fields($writ_rec['post_id']);
			if ($result)
				$jl = $result["job_level"];
			else
				$jl = JOB_LEVEL_COMMON;

			if ($max_education_level < 400 && $jl < JOB_LEVEL_BS)
				$job_level = min(array($job_level, 2));
			else
				$job_level = min(array($job_level, 3));
		}


                   
		if (!empty($this->param4)) {

			$job_level = $this->param4;

		} else {
			//...... چنانچه دستی وارد نشده باشد از اولین حکم در سال 88 رتبه مربوطه برداشته می شود ........

			$MyQry = "select wsi.param3
                                         from writs w inner join writ_salary_items wsi
                                                                 on w.writ_id = wsi.writ_id and
                                                                    w.writ_ver = wsi.writ_ver

                                               where w.staff_id = " . $writ_rec['staff_id'] . " and w.execute_date >= '2009-03-21' and
                                                    ( w.history_only <> 1 or  w.history_only is null ) and  wsi.salary_item_type_id = 34
                                            order by w.execute_date ASC limit 1  ";
			$MyRes = parent::runquery($MyQry);


			if ($MyRes[0]['param3'] > 0)
				$job_level = round($MyRes[0]['param3']);
		}

		//..........................................

		$score = !empty($job_level) ? $scores[$level][$job_level] : 0;
 
		$rial_coef = manage_salary_params::get_salaryParam_value("", $writ_rec["person_type"].",101", SPT_RIAL_COEF, $writ_rec["execute_date"]);
		// echo $rial_coef ."idkjf"; die();

		$value = $score * $rial_coef;

		if (!($value > 0)) {
			return false;
		}
		$this->param1 = $score;
		$this->param2 = $level;
		$this->param3 = $job_level;

		return $value;
	}