Пример #1
0
	private function compute_salary_item2_06($writ_rec) {
		//param1 : پايه (فقط براي كارشناسان ارشد با شغل آموزشي پژوهشي)،  (input)
		//param2 : حقوق مورد تطبيق
		//param3 : حقوق و مزاياي مستمر
		//param4 : مبلغ تفاوت تطبيق جهت استفاده در محاسبه حداقل دريافتي

		if ($this->param1 > 0) { //تفاوت تطبيق از نوع طرح همترازي
			//first check : education_level == MS
			$education_level_rec = manage_person_education::GetEducationLevelByDate($writ_rec["PersonID"]);
			$education_level = $education_level_rec['max_education_level'];

			if (!($education_level == EDUCATION_LEVEL_MS ||
					$education_level == EDUCATION_LEVEL_EQUAL_MS ||
					$education_level == EDUCATION_LEVEL_DOCTORATE ||
					$education_level == EDUCATION_LEVEL_EQUAL_PHD ||
					$education_level == EDUCATION_LEVEL_PHD)) {
				parent::PushException(EDUCATION_LEVEL_MUST_BE_MS);
				return false;
			}

			//then check : job field must be educ/research
			$job_field_educ_research = manage_posts::get_job_fields($writ_rec['post_id']);
			if (!$job_field_educ_research) {
				parent::PushException(JOB_FIELD_MUST_BE_EDUC_RESEARCH);
				return false;
			}

			//آيا شخص جانباز يا آزاده است
			$is_free_sacrifice_man = manage_person_devotion::get_person_devotions($writ_rec["PersonID"], '(' . SACRIFICE_DEVOTION . ',' . FREEDOM_DEVOTION . ')');

			//then compute : salary of equvalent professor
			$writ_rec['base'] = $this->param1; //virtual professor!

			if ($education_level == EDUCATION_LEVEL_DOCTORATE ||
					$education_level == EDUCATION_LEVEL_EQUAL_PHD ||
					$education_level == EDUCATION_LEVEL_PHD ||
					count($is_free_sacrifice_man) > 0) {
				$writ_rec['science_level'] = SCIENCE_LEVEL_PHD;	//virtual professor!
			} else if ($education_level != EDUCATION_LEVEL_MS ||
					$education_level != EDUCATION_LEVEL_EQUAL_MS) {
				$writ_rec['science_level'] = SCIENCE_LEVEL_MS;	//virtual professor!
			}

			$base = $writ_rec['base'];

			$professor_base_number = manage_writ_item::Get_professor_base_number($writ_rec['science_level']);
			$salary_coef = manage_salary_params::get_salaryParam_value("", $writ_rec["person_type"].",101", SPT_SALARY_COEF, $writ_rec['execute_date']);
			if (!$salary_coef) {
				parent::PushException(SALARY_COEF_NOT_FOUND);
				return false;
			}
			$this->param1 = $base;
			$this->param2 = $professor_base_number;
			$this->param3 = $salary_coef;

			$equal_salary_base_salary = $salary_coef * ($professor_base_number + 5 * $base);
			if (!($equal_salary_base_salary > 0)) {
				parent::PushException(BASE_SALARY_CALC_ERR);
				return false;
			}

			$special_extra_coef = manage_salary_params::get_salaryParam_value("", "1", SPT_SPECIAL_EXTRA_COEF, $writ_rec['execute_date'],  $writ_rec['science_level']);

			if (!$special_extra_coef) {
				parent::PushException(SPECIAL_EXTRA_COEF_NOT_FOUND);
				return false;
			}
			$equal_salary_special_extra = $special_extra_coef * $equal_salary_base_salary;
			if (!($equal_salary_special_extra > 0)) {
				parent::PushException(SPECIAL_EXTRA_CALC_ERR);
				return false;
			}

			///////////////////////////////////////////////////////////////////////
			$this->param2 = $equal_salary_base_salary + $equal_salary_special_extra;
			if ($this->param2 <= 0) {
				parent::PushException(EQUALENT_PROFESSOR_SALARY_CALC_ERR);
				return false;
			}
			$this->param3 = manage_writ_item::compute_writ_items_sum($writ_rec["writ_id"], $writ_rec["writ_ver"], $writ_rec["staff_id"], '( ' . SIT_STAFF_BASE_SALARY . ' , ' .
							SIT_STAFF_ANNUAL_INC . ' , ' .
							SIT_STAFF_MIN_PAY . ' , ' .
							SIT_STAFF_JOB_EXTRA . ' , ' .
							SIT_STAFF_DOMINANT_JOB_EXTRA . ' )');
			//چون به کساني که تفاوت تطبيق مي گيرند حداقل دريافتي تعلق نمي گيرد
			//بنابراين جمع چهار قلم
			//حقوق مبنا + افزايش سنواتي + فوق العاده شغل + فوق العاده شغل برجسته
			//ممکن است از حداقل حقوق کمترشود که در اين موارد بايد از حداقل حقوق استفاده شود.
			//کد نوشته شده زير اشتباه است و به همين دليل به صورت comment شده درآمد.
			/*
			  $min_salary = get_salary_param(SPT_MIN_SALARY, $writ_rec['execute_date']);
			  if ($param3 < $min_salary)
			  $param3 = $min_salary;
			 */

			$value = (0.8 * $this->param2) - $this->param3;
		} else { //تفاوت تطبيق از نوع تنزل گروه

			/*
			  ابتدا حكم قبلي استخراج مي گردد، اگر گروه آن پايين تر بود
			  حقوق و مزاياي مستمر آن استخراج مي گردد
			  اگر گروه آن برابر بود
			  تفاوت تطبيق از اقلام آن استخراج مي گردد
			  و با حقوق مورد تطبيق آن مقايسه مي گردد
			 */
			$this->param3 = manage_writ_item::get_continouse_salary($writ_rec["writ_id"], $writ_rec["writ_ver"], $writ_rec["staff_id"]);
			$prior_writ_obj = manage_writ::get_prior_writ($writ_rec);
			if ($prior_writ_obj->cur_group < $writ_rec['cur_group']) {
				$this->param2 = manage_writ_item::get_continouse_salary($prior_writ_obj->writ_id, $prior_writ_obj->writ_ver, $prior_writ_obj->staff_id);
				$value = $this->param3 - $this->param2;
			} else {
				//get prior param2:
				$value = manage_writ_item::get_writSalaryItem_value($prior_writ_obj->writ_id, $prior_writ_obj->writ_ver, $prior_writ_obj->staff_id, SIT_STAFF_ADAPTION_DIFFERENCE);
				$value = $this->param3 - $this->param2;
			}
		}

		if ($value > 0) {
			$min_pay = manage_writ_item::get_writSalaryItem_value($writ_rec["writ_id"], $writ_rec["writ_ver"], $writ_rec["staff_id"], SIT_STAFF_MIN_PAY);
			if ($min_pay) {
				$sql = 'UPDATE  writ_salary_items
		    			SET value = 0
		    			WHERE  writ_id = ' . $writ_rec['writ_id'] . ' AND
		    				   writ_ver = ' . $writ_rec['writ_ver'] . ' AND
		    				   salary_item_type_id = ' . SIT_STAFF_MIN_PAY . ' AND 
		    				   staff_id = ' . $writ_rec['staff_id'];
				PdoDataAccess::runquery($sql);
			}
		}

		if ($value <= 0) {
			parent::PushException(MATCH_DIFFERENCE_IS_ZERO);
			return false;
		}
		$this->param4 = $value;
		return $value;
	}