Example #1
0
	/** افزايش سنواتي */
	private function compute_salary_item2_02($writ_rec) {
		//param1 : افزايش سنوات سال قبل
		//param2 : ضريب افزايش سنواتي
		//param3 : درصد بسيج
		//param4 : مبلغ افزايش سنواتي بدون در نظر گرفتن گروه تشويقي و درصد بسيج
		//_____________________________________
		// چک کن که حکم قبلي وجود دارد يا خير

		$this_writ_year = substr(DateModules::Miladi_to_Shamsi($writ_rec['execute_date']), 0, 4);
		$one_year_ago = $this_writ_year - 1;
		$one_year_ago_first_day = $one_year_ago . "/01/01";
		$one_year_ago_last_day = $one_year_ago . "/12/30";
		$one_year_ago_last_day_writ = $one_year_ago . "/12/29";
		$Gone_year_ago_first_day = DateModules::Shamsi_to_Miladi($one_year_ago_first_day);
		$Gone_year_ago_last_day = DateModules::Shamsi_to_Miladi($one_year_ago_last_day_writ);
		$prior_writ = manage_writ::get_last_writ_by_date($writ_rec['staff_id'], DateModules::AddToGDate($writ_rec['execute_date'], -1, 0, 0));

		// در صورتی که حکم قبلی وجود داشته باشد که در همان سال باشد افزایش سنواتی آن تغییر نمی کند .
		if (!empty($prior_writ->writ_id)) {
			if (!DateModules::similar_year($writ_rec['execute_date'], $prior_writ->execute_date)) {
				$obj = new manage_writ_item($prior_writ->writ_id, $prior_writ->writ_ver, $prior_writ->staff_id,
								($prior_writ->person_type == 5 ) ? SIT5_STAFF_ANNUAL_INC : SIT_STAFF_ANNUAL_INC);
				if (!empty($obj->writ_id)) {
					$this->param1 = $obj->param1;
					$this->param2 = $obj->param2;
					$this->param3 = $obj->param3;

					if (!$obj->param4)
						$this->param4 = $obj->value;

					return $obj->value;
				}
			}
		}

		//آخرين حکم قبل از سال شخص را استخراج مي کند.
		$prior_writ = manage_writ::get_last_writ_by_date($writ_rec['staff_id'], $Gone_year_ago_last_day);

		$prior_writ_year = substr(DateModules::Miladi_to_Shamsi($prior_writ->execute_date), 0, 4);

		//____________________________________________________
		//اولين حكم- محاسبه افزايش سنواتي در بدو استخدام
		if (empty($prior_writ->writ_id)) {
			//در بدو استخدام: جانبازي + آزادگي + سربازي + جبهه
			$this->param1 = 0;
			$this->param2 = 0;
			$this->param3 = 0;
			$this->value = 0;

			if ($writ_rec['military_duration'] > 30)
				$writ_rec['military_duration'] = 30;

			//سربازي : هر ماه 0/25% سالي 3% ، حداكثر 2/5 سال
			$this->param2 += $writ_rec['military_duration'] * 0.0025;

			if ($writ_rec['execute_date'] < DateModules::Shamsi_to_Miladi('1384-11-12')) {
				$temp = manage_person_devotion::GetAllDevotions("d.PersonID=" . $writ_rec["personID"]);

				for ($i = 0; $i < count($temp); $i++) {
					switch ($temp[$i]['devotion_type']) {
						case DEVOTION_TYPE_FIGHTER://رزمندگي
							//جبهه : ماهي 5/0% سالي 6% (سوابق تا قبل از 29/5/69
							$this->param2 += ($temp[$i]['amount'] / 30) * 0.005;
							break;
						case DEVOTION_TYPE_PRISONER://آزادگي
							//- آزادگي : ماهي 0.5% سالي 6%
							$this->param2 += ($temp[$i]['amount'] / 30) * 0.005;
							break;
						case DEVOTION_TYPE_WOUNDED://جانبازي
							//- جانبازي : هر 1% جانبازي 6/0%
							$this->param2 += $temp[$i]['amount'] * 0.006;
							break;
					}
				}
			}
			//____________________________________________
			// حقوق مبنا
			$base_salary = manage_writ::get_base_salary($writ_rec["writ_id"], $writ_rec["writ_ver"], $writ_rec["staff_id"], $writ_rec["person_type"]);

			if (in_array($writ_rec['person_type'], array(1, 2, 3))) {
				// حقوق مبنا بدون گروه تشویقی
				$nh_base_salary = manage_writ::get_base_salary($writ_rec["writ_id"], $writ_rec["writ_ver"], $writ_rec["staff_id"], $writ_rec["person_type"], false);
			}
			$value = $base_salary * $this->param2;
			if (in_array($writ_rec['person_type'], array(1, 2, 3))) {
				$this->param4 = $nh_base_salary * $this->param2;
			}

			return $value;
		}
		//احكام طول دوره خدمت
		else {
			//افزايش سنواتي سال قبل
			$obj = new manage_writ_item($prior_writ->writ_id, $prior_writ->writ_ver, $prior_writ->staff_id,
							($prior_writ->person_type == 5 ) ? SIT5_STAFF_ANNUAL_INC : SIT_STAFF_ANNUAL_INC);
			$this->param1 = $obj->value;
			$this->param2 = $obj->param2;
			$this->param3 = $obj->param3;
			$this->param4 = $obj->param4;
			$this->param5 = $obj->param5;
			$this->param6 = $obj->param6;
			$this->param7 = $obj->param7;

			if ($writ_rec['emp_mode'] != EMP_MODE_ENGAGEMENT && in_array($writ_rec['person_type'], array(1, 2, 3))) {
				//ضريب افزايش سنواتي سال قبل
				$this->param2 = manage_writ_item::get_annual_coef($prior_writ_year, $writ_rec['staff_id']);
			} else {
				$this->param2 = 0.05;
			}

			if ($writ_rec['execute_date'] < DateModules::Shamsi_to_Miladi('1384/11/12')) {
				//درصد بسيج سال قبل
				$this->param3 = manage_writ_item::get_mobilization_coef($prior_writ_year, $writ_rec['staff_id']);
			} else if (manage_writ_item::get_writSalaryItem_value($writ_rec["writ_id"], $writ_rec["writ_ver"], $writ_rec["staff_id"], 287) > 0)
				$this->param3 = 0;
			else
				$this->param3 = manage_writ_item::get_mobilization_coef($prior_writ_year, $writ_rec['staff_id']);

			$base_salary = manage_writ::get_base_salary($prior_writ->writ_id, $prior_writ->writ_ver, $prior_writ->staff_id, $prior_writ->person_type);

			if (in_array($writ_rec['person_type'], array(1, 2, 3))) {
				$nh_base_salary = manage_writ::get_base_salary($writ_rec["writ_id"], $writ_rec["writ_ver"], $writ_rec["staff_id"], $writ_rec["person_type"], false);
			}

			if (!($base_salary > 0))
				return false;


			$duplicate_duration = 0;
			if (!empty($writ_rec['last_retired_pay'])) {
				if ($writ_rec['last_retired_pay'] >= $Gone_year_ago_first_day &&
						$writ_rec['last_retired_pay'] < $Gone_year_ago_last_day) {
					$jlast_retired_pay = DateModules::Miladi_to_Shamsi($writ_rec['last_retired_pay']);
					$duplicate_duration = ceil(DateModules::getDateDiff($one_year_ago_last_day, $jlast_retired_pay));
				} else if ($writ_rec['last_retired_pay'] <= $Gone_year_ago_first_day) {
					$duplicate_duration = 360;
				}
			}

			$year_work_days = manage_staff::compute_year_work_days($writ_rec['staff_id'], $Gone_year_ago_first_day, $Gone_year_ago_last_day);
			if ($year_work_days > 360) {
				$year_work_days = 360;
			}
			//نسبت کارکرد در سال قبل.
			$annual_inc_duration = ($year_work_days + $duplicate_duration) / 360;

			//فرمول محاسبه براي سال دوم به بعد.
			$value = (($base_salary + $this->param1) * $this->param2 * $annual_inc_duration) +
					($this->param3 * $base_salary ) + $this->param1;

			if (in_array($writ_rec['person_type'], array(1, 2, 3))) {
				$this->param4 = (($nh_base_salary + $this->param1) * $this->param2 * $annual_inc_duration) +
						$this->param1;
			}
		}

		return $value;
	}