Пример #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;
}
Пример #2
0
function GetSavingLoanInfo()
{
    if (isset($_SESSION["USER"]["portal"])) {
        $PersonID = $_SESSION["USER"]["PersonID"];
    } else {
        $PersonID = $_REQUEST["PersonID"];
    }
    //----------- check for all docs confirm --------------
    /*$dt = PdoDataAccess::runquery("select group_concat(distinct LocalNo) from ACC_docs 
    		join ACC_DocItems using(DocID) join ACC_tafsilis t using(TafsiliType,TafsiliID)
    		where TafsiliType=" . TAFTYPE_PERSONS . " 
    			AND ObjectID = ? AND CostID in(" . COSTID_saving . ")
    			AND DocType not in(" . DOCTYPE_STARTCYCLE . "," . DOCTYPE_ENDCYCLE . ")
    			AND DocStatus not in('CONFIRM','ARCHIVE')", array($PersonID));
    	if(count($dt) > 0 && $dt[0][0] != "")
    	{
    		$msg = "اسناد با شماره های [" . $dt[0][0] . "] تایید نشده اند.";
    		echo dataReader::getJsonData(array(), 0, $_GET["callback"], $msg);
    		die();
    	}*/
    //------------ get sum of savings ----------------
    $dt = PdoDataAccess::runquery("\n\t\tselect DocDate,sum(CreditorAmount-DebtorAmount) amount\n\t\tfrom ACC_DocItems di\n\t\t\tjoin ACC_docs d using(DocID)\n\t\t\tjoin ACC_tafsilis t using(TafsiliType,TafsiliID)\n\t\t\n\t\twhere TafsiliType=" . TAFTYPE_PERSONS . " \n\t\t\tAND ObjectID = ?\n\t\t\tAND CostID in(" . COSTID_saving . ")\n\t\t\tAND DocType not in(" . DOCTYPE_STARTCYCLE . "," . DOCTYPE_ENDCYCLE . ")\n\t\t\tAND BranchID=" . $_SESSION["accounting"]["BranchID"] . "\n\t\tgroup by DocDate\n\t\torder by DocDate", array($PersonID));
    if (count($dt) == 0) {
        $msg = "شخص مورد نظر فاقد حساب پس انداز می باشد";
        echo dataReader::getJsonData(array(), 0, $_GET["callback"], $msg);
        die;
    }
    //------------ get the Deposite amount -------------
    $totalAmount = 0;
    $totalDays = 0;
    for ($i = 1; $i < count($dt); $i++) {
        $days = DateModules::GDateMinusGDate($dt[$i]["DocDate"], $dt[$i - 1]["DocDate"]);
        $totalDays += $days;
        $totalAmount += $dt[$i - 1]["amount"] * $days;
    }
    $days = DateModules::GDateMinusGDate(DateModules::Now(), $dt[$i - 1]["DocDate"]);
    $totalDays += $days;
    $totalAmount += $dt[$i - 1]["amount"] * $days;
    $average = round($totalAmount / $totalDays);
    $returnArray = array("PersonID" => $PersonID, "FirstDate" => DateModules::miladi_to_shamsi($dt[0]["DocDate"]), "AverageAmount" => $average, "TotalMonths" => floor($totalDays / 30.5));
    echo dataReader::getJsonData($returnArray, 1, $_GET["callback"]);
    die;
}
Пример #3
0
function ProcessPayment()
{
    $paymentCalcObj = new manage_payment_calculation();
    $paymentCalcObj->__YEAR = DateModules::GetYear($_POST["end_date"]);
    $paymentCalcObj->__MONTH = DateModules::GetMonth($_POST["end_date"]);
    $paymentCalcObj->__CALC_NORMALIZE_TAX = isset($_POST['tax_normalize']) ? "1" : "0";
    $paymentCalcObj->__START_NORMALIZE_TAX_MONTH = $_POST['tax_n_m'];
    $paymentCalcObj->__START_NORMALIZE_TAX_YEAR = $_POST['tax_normalized_year'];
    $paymentCalcObj->__BACKPAY_BEGIN_FROM = 1;
    $paymentCalcObj->__CALC_NEGATIVE_FICHE = isset($_POST['negative_fiche']) ? "1" : "0";
    $paymentCalcObj->month_start = DateModules::shamsi_to_miladi($_POST["start_date"]);
    $paymentCalcObj->month_end = DateModules::shamsi_to_miladi($_POST["end_date"]);
    $paymentCalcObj->__MONTH_LENGTH = ceil(DateModules::GDateMinusGDate($paymentCalcObj->month_end, $paymentCalcObj->month_start) + 1);
    $paymentCalcObj->__MSG = $_POST["message"];
    // <editor-fold defaultstate="collapsed" desc="Create Where" >
    $where = "1=1";
    $whereParam = array();
    if (!empty($_POST["from_staff_id"])) {
        $where .= " AND s.staff_id >= :fsid";
        $whereParam[":fsid"] = $_POST["from_staff_id"];
    }
    if (!empty($_POST["to_staff_id"])) {
        $where .= " AND s.staff_id <= :tsid";
        $whereParam[":tsid"] = $_POST["to_staff_id"];
    }
    // </editor-fold>
    $paymentCalcObj->__WHERE = $where;
    $paymentCalcObj->__WHEREPARAM = $whereParam;
    if (isset($_POST["compute_backpay"])) {
        $res = $paymentCalcObj->run_back();
    } else {
        $res = $paymentCalcObj->run();
    }
    if (!$res) {
        echo Response::createObjectiveResponse(false, ExceptionHandler::popExceptionDescription());
        die;
    } else {
        echo Response::createObjectiveResponse(true, $paymentCalcObj->success_counter . "_" . $paymentCalcObj->fail_counter);
        die;
    }
}
Пример #4
0
function ComputeWagesAndDelays($PartObj, $PayAmount, $StartDate, $PayDate)
{
    $MaxWage = max($PartObj->CustomerWage * 1, $PartObj->FundWage);
    if ($PartObj->PayInterval > 0) {
        $YearMonths = $PartObj->IntervalType == "DAY" ? floor(365 / $PartObj->PayInterval) : 12 / $PartObj->PayInterval;
    } else {
        $YearMonths = 12;
    }
    $TotalWage = round(ComputeWage($PayAmount, $MaxWage / 100, $PartObj->InstallmentCount, $PartObj->IntervalType, $PartObj->PayInterval));
    $CustomerFactor = $MaxWage == 0 ? 0 : $PartObj->CustomerWage / $MaxWage;
    $FundFactor = $MaxWage == 0 ? 0 : $PartObj->FundWage / $MaxWage;
    $AgentFactor = $MaxWage == 0 ? 0 : ($PartObj->CustomerWage - $PartObj->FundWage) / $MaxWage;
    ///...........................................................
    if ($PartObj->MaxFundWage * 1 > 0) {
        if ($PartObj->WageReturn == "INSTALLMENT") {
            $FundYears = YearWageCompute($PartObj, $PartObj->MaxFundWage * 1, $YearMonths);
        } else {
            $FundYears = array();
        }
    } else {
        $years = YearWageCompute($PartObj, $TotalWage * 1, $YearMonths);
        $FundYears = array();
        foreach ($years as $year => $amount) {
            $FundYears[$year] = round($FundFactor * $amount);
        }
    }
    $AgentYears = array();
    foreach ($years as $year => $amount) {
        $AgentYears[$year] = round($amount - $FundYears[$year]);
    }
    //.............................................................
    $endDelayDate = DateModules::AddToGDate($PayDate, $PartObj->DelayDays * 1, $PartObj->DelayMonths * 1);
    $DelayDuration = DateModules::GDateMinusGDate($endDelayDate, $PayDate) + 1;
    if ($StartDate == $PayDate) {
        if ($PartObj->DelayDays * 1 > 0) {
            $CustomerDelay = round($PayAmount * $PartObj->DelayPercent * $DelayDuration / 36500);
            $FundDelay = round($PayAmount * $PartObj->FundWage * $DelayDuration / 36500);
            $AgentDelay = round($PayAmount * ($PartObj->DelayPercent - $PartObj->FundWage) * $DelayDuration / 36500);
        } else {
            $CustomerDelay = round($PayAmount * $PartObj->DelayPercent * $PartObj->DelayMonths / 1200);
            $FundDelay = round($PayAmount * $PartObj->FundWage * $PartObj->DelayMonths / 1200);
            $AgentDelay = round($PayAmount * ($PartObj->DelayPercent - $PartObj->FundWage) * $PartObj->DelayMonths / 1200);
        }
    } else {
        $endDelayDate = DateModules::AddToGDate($StartDate, $PartObj->DelayDays * 1, $PartObj->DelayMonths * 1);
        $DelayDuration = DateModules::GDateMinusGDate($endDelayDate, $PayDate) + 1;
        $CustomerDelay = round($PayAmount * $PartObj->DelayPercent * $DelayDuration / 36500);
        $FundDelay = round($PayAmount * $PartObj->FundWage * $DelayDuration / 36500);
        $AgentDelay = round($PayAmount * ($PartObj->DelayPercent - $PartObj->FundWage) * $DelayDuration / 36500);
    }
    $CustomerYearDelays = SplitYears($PayDate, $endDelayDate, $CustomerDelay);
    //.............................................................
    return array("TotalFundWage" => round($TotalWage * $FundFactor), "TotalAgentWage" => round($TotalWage * $AgentFactor), "TotalCustomerWage" => round($TotalWage * $CustomerFactor), "FundWageYears" => $FundYears, "AgentWageYears" => $AgentYears, "TotalCustomerDelay" => $CustomerDelay, "TotalFundDelay" => $FundDelay, "TotalAgentDelay" => $AgentDelay, "CustomerYearDelays" => $CustomerYearDelays);
}
Пример #5
0
	private function compute_salary_item2_19($writ_rec) {
		//param1 : حقوق مبنا + افزايش سنواتي + فوق العاده شغل + حداقل دريافتي + فوق العاده شغل برجسته
		//param2 : ضريب فوق العاده جذب ويژه
		//param3 : نمره ارزشيابي
		//در صورتي که شخص جانباز باشد از ضريب يک مقطع بالاتر استفاده مي کند.
		// بنا به درخواست آقای دلکلاله برای همه افراد دیده می شود .
		// if($writ_rec['person_type'] != HR_CONTRACT &&  $writ_rec['person_type'] != HR_WORKER ) {


			
			

		

		$qry = " SELECT pd.personid
                             FROM   person_devotions pd
                             WHERE  (pd.devotion_type IN (" . DEVOTION_TYPE_WOUNDED . "," . DEVOTION_TYPE_PRISONER . ") OR
                                    (pd.devotion_type = " . BEHOLDER_FAMILY_DEVOTION . " AND
                                    (pd.personel_relation = " . BOY . " OR pd.personel_relation = " . DAUGHTER . "))) AND
                                     pd.PersonID = " . $writ_rec['personID'];
		$resDev = parent::runquery($qry);


		if (count($resDev) > 0)
			$personDev = true;
		else
			$personDev = false;

		// }
		// else
		// {
		// $personDev = false ;
		//}
		//..........................................................
		//چون فرمول براي قبل از سال 85 و بعد از آن متفاوت است کد به صورت زير اصلاح شد.
		$jexecute_date = DateModules::Miladi_to_Shamsi($writ_rec['execute_date']);
		list($year, $month, $day) = explode('/', $jexecute_date);
		$education_level = $writ_rec['education_level'];
		if ($year <= 1384) {
			//در صورتي که شخص جانباز باشد از ضريب يک مقطع بالاتر استفاده مي کند.
			//$person_devotions = manage_person_devotion::get_person_devotions($writ_rec["PersonID"],
			//	'('.DEVOTION_TYPE_WOUNDED.','.DEVOTION_TYPE_PRISONER.')');
			//حقوق مبنا + افزايش سنواتي + حداقل دريافتي + فوق العاده شغل + فوق العاده شغل برجسته
			$this->param1 = 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_JOB_EXTRA . ' , ' .
							SIT_STAFF_DOMINANT_JOB_EXTRA . ' , ' . SIT_STAFF_MIN_PAY . ' )');

			//در صورتي که مجموع اقلام فوق کمتر از حداقل دريافتي شود
			//حداقل دريافتي براي محاسبات ملاک خواهد بود.
			$min_salary = manage_salary_params::get_salaryParam_value("", $writ_rec["person_type"].",101", SPT_MIN_SALARY, $writ_rec['execute_date']);
			if ($this->param1 < $min_salary)
				$this->param1 = $min_salary;


			if (($education_level <= EDUCATION_LEVEL_SEVENTH_GRADE &&
					$education_level != EDUCATION_LEVEL_NEW_END_HIGH_SCHOOL) &&
					$personDev == true) {
				$this->param2 = 0.40;
			} else if (($education_level <= EDUCATION_LEVEL_SEVENTH_GRADE &&
					$education_level != EDUCATION_LEVEL_NEW_END_HIGH_SCHOOL)) {
				$this->param2 = 0.35;
			} else if (($education_level <= EDUCATION_LEVEL_THIRTH_HONARESTAN &&
					$education_level != EDUCATION_LEVEL_NEW_END_HIGH_SCHOOL) &&
					$personDev == true) {
				$this->param2 = 0.50;
			} else if (($education_level <= EDUCATION_LEVEL_THIRTH_HONARESTAN &&
					$education_level != EDUCATION_LEVEL_NEW_END_HIGH_SCHOOL)) {
				$this->param2 = 0.40;
			} else if (($education_level <= EDUCATION_LEVEL_ALL_DIPLOMA ||
					$education_level == EDUCATION_LEVEL_NEW_END_HIGH_SCHOOL) &&
					$personDev == true) {
				$this->param2 = 0.65;
			} else if ($education_level <= EDUCATION_LEVEL_ALL_DIPLOMA ||
					$education_level == EDUCATION_LEVEL_NEW_END_HIGH_SCHOOL) {
				$this->param2 = 0.50;
			} else if (($education_level == EDUCATION_LEVEL_HIGH_DIPLOMA ||
					$education_level == EDUCATION_LEVEL_EQUAL_HIGH_DIPLOMA) &&
					$personDev == true) {
				$this->param2 = 0.85;
			} else if ($education_level == EDUCATION_LEVEL_HIGH_DIPLOMA ||
					$education_level == EDUCATION_LEVEL_EQUAL_HIGH_DIPLOMA) {
				$this->param2 = 0.65;
			} else if (($education_level == EDUCATION_LEVEL_BS ||
					$education_level == EDUCATION_LEVEL_EQUAL_BS) &&
					$personDev == true) {
				$this->param2 = 1;
			} else if ($education_level == EDUCATION_LEVEL_BS ||
					$education_level == EDUCATION_LEVEL_EQUAL_BS) {
				$this->param2 = 0.85;
			} else if ($education_level == EDUCATION_LEVEL_MS ||
					$education_level == EDUCATION_LEVEL_EQUAL_MS) {
				$this->param2 = 1;
			}

			$writ_year = substr(DateModules::Miladi_to_Shamsi($writ_rec['execute_date']), 0, 4);
			$writ_year--;
			$this->param3 = manage_writ_item::get_evaluation_scores_sum($writ_year, $writ_rec['staff_id']);

			$multiplicant = $this->param2 * ($this->param3 / 100) + 0.0000001;
			$multiplicant = round($multiplicant, 2);
			$value = $this->param1 * $multiplicant;

			if (!($value > 0)) {
				parent::PushException(SPECIAL_ABSORB_EXTRA_ITEM_CALC_ERR);
				return false;
			}
		} else if ($year >= 1385 && $year < 1388) {
			$date = DateModules::Shamsi_to_Miladi('1384/12/29');
			$last_writ_obj = manage_writ::get_last_writ_by_date($writ_rec['staff_id'], $date);
			if (!empty($last_writ_obj->writ_id)) {
				$value = manage_writ_item::get_writSalaryItem_value($last_writ_obj->writ_id, $last_writ_obj->writ_ver, $last_writ_obj->staff_id, SIT_STAFF_HEIAT_OMANA_SPECIAL_EXTRA);
			}

			if (!($value > 0)) {
				parent::PushException(SPECIAL_ABSORB_EXTRA_ITEM_CALC_ERR);
				return false;
			}
		} else if ($year >= 1390) {

			if ($education_level < EDUCATION_LEVEL_DIPLOMA &&
					$education_level != EDUCATION_LEVEL_NEW_END_HIGH_SCHOOL &&
					$personDev == true) {
				$education_level = DIPLOMA_LEVEL;
			} else if ($education_level < EDUCATION_LEVEL_DIPLOMA &&
					$education_level != EDUCATION_LEVEL_NEW_END_HIGH_SCHOOL) {
				$education_level = UNDER_DIPLOMA_LEVEL;
			} else if (($education_level <= EDUCATION_LEVEL_ALL_DIPLOMA ||
					$education_level == EDUCATION_LEVEL_THREE_YEAR_HIGH_SCHOOL ||
					$education_level == EDUCATION_LEVEL_THREE_YEAR_HIGH_SCHOOL_WITHOUT_SCORE ||
					$education_level == EDUCATION_LEVEL_NEW_END_HIGH_SCHOOL) &&
					$personDev == true) {
				$education_level = HIGH_DIPLOMA_LEVEL;
			} else if ($education_level <= EDUCATION_LEVEL_ALL_DIPLOMA ||
					$education_level == EDUCATION_LEVEL_THREE_YEAR_HIGH_SCHOOL ||
					$education_level == EDUCATION_LEVEL_THREE_YEAR_HIGH_SCHOOL_WITHOUT_SCORE ||
					$education_level == EDUCATION_LEVEL_NEW_END_HIGH_SCHOOL) {
				$education_level = DIPLOMA_LEVEL;
			} else if (($education_level == EDUCATION_LEVEL_HIGH_DIPLOMA ||
					$education_level == EDUCATION_LEVEL_EQUAL_HIGH_DIPLOMA) &&
					$personDev == true) {
				$education_level = BS_LEVEL;
			} else if ($education_level == EDUCATION_LEVEL_HIGH_DIPLOMA ||
					$education_level == EDUCATION_LEVEL_EQUAL_HIGH_DIPLOMA) {
				$education_level = HIGH_DIPLOMA_LEVEL;
			} else if (($education_level == EDUCATION_LEVEL_BS ||
					$education_level == EDUCATION_LEVEL_EQUAL_BS) &&
					$personDev == true) {
				$education_level = MS_LEVEL;
			} else if ($education_level == EDUCATION_LEVEL_BS ||
					$education_level == EDUCATION_LEVEL_EQUAL_BS) {
				$education_level = BS_LEVEL;
			} else if (($education_level == EDUCATION_LEVEL_MS ||
					$education_level == EDUCATION_LEVEL_HOZE_LEVEL3_EQUAL_MS ||
					$education_level == EDUCATION_LEVEL_EQUAL_MS) &&
					$personDev == true) {
				$education_level = PHD_LEVEL;
			} else if ($education_level == EDUCATION_LEVEL_MS ||
					$education_level == EDUCATION_LEVEL_HOZE_LEVEL3_EQUAL_MS ||
					$education_level == EDUCATION_LEVEL_EQUAL_MS) {
				$education_level = MS_LEVEL;
			} else if ($education_level >= EDUCATION_LEVEL_DOCTORATE) {
				$education_level = PHD_LEVEL;
			}

			switch ($education_level) {
				case PHD_LEVEL :
					$this->param1 = 'دکتری';
					break;
				case MS_LEVEL :
					$this->param1 = 'کارشناسی ارشد';
					break;
				case BS_LEVEL :
					$this->param1 = 'کارشناسی';
					break;
				case HIGH_DIPLOMA_LEVEL :
					$this->param1 = 'فوق دیپلم';
					break;
				case DIPLOMA_LEVEL :
					$this->param1 = 'دیپلم';
					break;
				case UNDER_DIPLOMA_LEVEL :
					$this->param1 = 'زیر دیپلم';
					break;
			}

			$this->param4 = $writ_rec['onduty_year'] . ' سال و ' . $writ_rec['onduty_month'] . ' ماه و ' . $writ_rec['onduty_day'] . ' روز';

			//بررسی سنوات خدمت و اختلاف آن با سنوات خدمت در حکم.
			unset($duty_duration);
			$duty_duration_year = 0;
			$duty_duration_month = 0;
			$duty_duration_day = 0;

			$duty_qry = " SELECT s.work_start_date,
	    						 p.military_duration,
	    						 p.military_duration_day
	    				 FROM    staff s
	    				 		INNER JOIN persons p
	    				 			  ON (s.PersonID = p.PersonID)
	    				 WHERE s.staff_id = " . $writ_rec['staff_id'];

			$duty_res = parent::runquery($duty_qry);

			if ($duty_res[0]['work_start_date']) {

				$duty_duration = DateModules::GDateMinusGDate($writ_rec['execute_date'], $duty_res[0]['work_start_date']) +
						(floor($duty_res[0]['military_duration'] * 30.4375 + $duty_res[0]['military_duration_day'])) + 1;
				$duty_duration_year = floor($duty_duration / 366.25);
				$duty_duration_month = floor(($duty_duration - ($duty_duration_year * 366.25)) / 30);
				$duty_duration_day = floor($duty_duration - ($duty_duration_year * 366.25) - floor($duty_duration_month * 30));
			}

			$emp_qry = " SELECT SUM(pe.retired_duration_year) retired_duration_year,
	    						SUM(pe.retired_duration_month) retired_duration_month,
	    						SUM(pe.retired_duration_day) retired_duration_day
	    				  FROM   person_employments pe
                                 WHERE pe.PersonID = " . $writ_rec['PersonID'];

			$emp_res = parent::runquery($emp_qry);

			$duty_duration_year += $emp_res[0]['retired_duration_year'];
			$duty_duration_month += $emp_res[0]['retired_duration_month'];
			$duty_duration_day += $emp_res[0]['retired_duration_day'];

			//...........................................................................
			if ($duty_duration_day >= 30) {
				$duty_duration_month += floor($duty_duration_day / 30);
				$duty_duration_day -= floor(floor($duty_duration_day / 30) * 30);
			}

			if ($duty_duration_month >= 12) {
				$duty_duration_year += floor($duty_duration_month / 12);
				$duty_duration_month -= floor($duty_duration_month / 12) * 12;
			}

			$this->param2 = $duty_duration_year . ' سال و ' . $duty_duration_month . ' ماه و ' . $duty_duration_day . ' روز';

			$pqry = " SELECT value
        				 FROM  salary_params sp
        				 WHERE sp.param_type = " . SPT_HEIAT_OMANA_ABSORBTION_VALUE . " AND
					       sp.person_type = ".$writ_rec['person_type']." AND 	
        				       sp.from_date <= '" . $writ_rec['execute_date'] . "' AND
        				       sp.to_date >= '" . $writ_rec['execute_date'] . "' AND 
        				       sp.dim1_id = " . $education_level . " AND
        				       sp.dim2_id > " . $writ_rec['onduty_year'] . "
        				 ORDER BY sp.from_date DESC,sp.to_date DESC, dim2_id
        				 LIMIT 1 ";

			$pres = parent::runquery($pqry);
			if (count($pres) < 1) {
				parent::PushException(NOT_DEFINE_HEIAT_OMANA_PARAM);
				return false;
			}
			$value = $pres[0]['value'];
			$this->param3 = $value;
		}
		
		return $value;
	}
 private function get_retired_coef()
 {
     $coefficient = 1;
     //init
     if ($this->staffRow['last_retired_pay'] != NULL && $this->staffRow['last_retired_pay'] != '0000-00-00' && DateModules::CompareDate($this->staffRow['last_retired_pay'], $this->month_start) == -1) {
         $coefficient = 0;
     } elseif ($this->staffRow['last_retired_pay'] != NULL && $this->staffRow['last_retired_pay'] != '0000-00-00' && DateModules::CompareDate($this->staffRow['last_retired_pay'], $this->month_end) != 1) {
         $coefficient = (round(DateModules::GDateMinusGDate($this->staffRow['last_retired_pay'], $this->month_start)) + 1) / $this->__MONTH_LENGTH;
     }
     return $coefficient;
 }
Пример #7
0
    public static function get_arrear_document($staff_id, $pay_year, $pay_month)
    {
        for ($t = $_POST['from_pay_year']; $t < $_POST['to_pay_year'] + 1; $t++) {
            $retCoef = 1;
            $qry = " select max(arrear_ver) MV\r\n\t\t\t\t\tfrom  corrective_payment_writs \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . "\r\n\t\t       ";
            $MaxVer = PdoDataAccess::runquery($qry);
            if (count($MaxVer) == 0 || $MaxVer[0]['MV'] == 0) {
                continue;
            }
            $qry = " select  cpw.staff_id , cpw.writ_id ,  cpw.writ_ver , cpw.arrear_ver , w.execute_date, w.send_letter_no , w.salary_pay_proc\r\n\t\t\r\n\t\t\t\t from corrective_payment_writs cpw inner join  writs w \r\n\t\t\t                                         on cpw.staff_id = w.staff_id and \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcpw.writ_id = w.writ_id and \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcpw.writ_ver = w.writ_ver \r\n\r\n\t\t\t where cpw.pay_year = " . $t . " and cpw.staff_id = " . $SID . " and arrear_ver = " . $MaxVer[0]['MV'] . " and cpw.pay_month = 12 \r\n\t\t\t order by  w.execute_date ";
            $res1 = PdoDataAccess::runquery($qry);
            //............................. پیدا کردن آخرین ماهی که فیش حقوقی در آن محاسبه شده است ................
            $qry = " select max(pay_month) PM from payment_writs where staff_id = " . $SID . " AND pay_year= " . $t;
            $MaxMonth = PdoDataAccess::runquery($qry);
            if ($MaxMonth[0]['PM'] > 0 && $MaxMonth[0]['PM'] < 7) {
                $LastDate = $t . "/" . $MaxMonth[0]['PM'] . "/31";
            } else {
                if ($MaxMonth[0]['PM'] > 6 && $MaxMonth[0]['PM'] < 12) {
                    $LastDate = $t . "/" . $MaxMonth[0]['PM'] . "/30";
                } else {
                    if ($MaxMonth[0]['PM'] == 12) {
                        $LastDate = $t . "/" . $MaxMonth[0]['PM'] . "/29";
                    } else {
                        $LastDate = '0000-00-00';
                    }
                }
            }
            $LAST_PAY_DATE = date('Y-m-d', strtotime(DateModules::shamsi_to_miladi($LastDate) . "+1 days"));
            $LAST_PAY_DATE = DateModules::miladi_to_shamsi($LAST_PAY_DATE);
            if ($res1[count($res1) - 1]['salary_pay_proc'] == 1) {
                $LastDate = DateModules::miladi_to_shamsi($res1[count($res1) - 1]['execute_date']);
                $arr = preg_split('/\\//', $LastDate);
                $NewDate = date('Y-m-d', strtotime(DateModules::shamsi_to_miladi($LastDate) . "-1 days"));
                $LastDate = DateModules::miladi_to_shamsi($NewDate);
                $arr = preg_split('/\\//', $LastDate);
            }
            $LD = array();
            //.................................................................................................
            for ($i = 0; $i < count($res1); $i++) {
                if ($LastDate != '0000-00-00' && DateModules::CompareDate($res1[$i]['execute_date'], str_replace("/", "-", DateModules::shamsi_to_miladi($LastDate))) >= 0) {
                    $LD[$t]['lastDate'] = $LastDate;
                    break;
                }
                $CDate = DateModules::miladi_to_shamsi($res1[$i]['execute_date']);
                $arr2 = preg_split('/\\//', $CDate);
                if (intval($arr2[1]) <= intval($MaxMonth[0]['PM'])) {
                    $qry = " select t.staff_id,max_execute_date ,SUBSTRING(max_execute_date,1,10) execute_date ,\r\n\t\t\t\t\t\tSUBSTRING_INDEX(SUBSTRING(max_execute_date,11),'.',1) writ_id,\r\n\t\t\t\t\t\tSUBSTRING_INDEX(max_execute_date,'.',-1) writ_ver\r\n\r\n\t\t\t\t\tfrom (\r\n\t\t\t\t\t\t\tselect w.staff_id,max( CONCAT(w.execute_date,w.writ_id,'.',w.writ_ver) ) max_execute_date\r\n\r\n\t\t\t\t\t\t\tfrom payment_writs cpw inner join  writs w\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ton  cpw.staff_id = w.staff_id and\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcpw.writ_id = w.writ_id and\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcpw.writ_ver = w.writ_ver\r\n\t\t\t\t\t\t\twhere cpw.pay_year = " . $t . " and cpw.staff_id = " . $SID . " and\r\n\t\t\t\t\t\t\t      /*cpw.pay_month = 12 and*/ execute_date <= '" . $res1[$i]['execute_date'] . "'\r\n\r\n\t\t\t\t\t\t\tgroup by w.staff_id\r\n\t\t\t\t\t\t) t\r\n\t\t\t\t\t\t\t";
                    // پرس و جو بالا هم بایستی union شود با ورژن های قبلی پرداخت تا احکام آنها هم دیده شود .
                    $res2 = PdoDataAccess::runquery($qry);
                    if (count($res2) == 0) {
                        $res2[0]['execute_date'] = '0000-00-00';
                        $res2[0]['writ_id'] = 0;
                        $res2[0]['writ_ver'] = 0;
                    }
                } else {
                    $res2[0]['execute_date'] = '0000-00-00';
                    $res2[0]['writ_id'] = 0;
                    $res2[0]['writ_ver'] = 0;
                }
                /* PdoDataAccess::runquery(" insert compare_arrear_writs (staff_id ,current_execute_date , current_writ_id , current_writ_ver, 
                															   prev_execute_date , prev_writ_id , prev_writ_ver , arrear_ver , pay_year ) values 
                															  (" . $res1[$i]['staff_id'] . ",'" . $res1[$i]['execute_date'] . "'," . $res1[$i]['writ_id'] . "," .
                                    $res1[$i]['writ_ver'] . ",'" . $res2[0]['execute_date'] . "'," . $res2[0]['writ_id'] . "," .
                                    $res2[0]['writ_ver'] . "," . $res1[$i]['arrear_ver'] . "," . $t . " ) ");
                			*/
                if ($res1[$i]['writ_id'] == $res2[0]['writ_id'] && $res1[$i]['writ_ver'] == $res2[0]['writ_ver']) {
                    continue;
                }
                $writNo++;
            }
            //..................اگر برج 12 در دیون محاسبه می شود ولی در قبلی نبوده است بایستی به جدول compare افزوده شود..............................
            /*   if ($res1[(count($res1) - 1)]['salary_pay_proc'] != 1 && $MaxMonth[0]['PM'] < 12) {
            
            
            
                        $qry = " select staff_id , execute_date , writ_id , writ_ver 
                            from writs 
                             where  staff_id = " . $SID . " and salary_pay_proc = 1 and 
                                    execute_date >= '" . DateModules::shamsi_to_miladi($t . '/01/01') . "' and 
                                    execute_date <= '" . DateModules::shamsi_to_miladi($t . '/12/29') . "' and 
                                    issue_date >= '" . $res1[$i - 1]['execute_date'] . "' and state = 3 ";
            
                        $res3 = PdoDataAccess::runquery($qry);
            
                        PdoDataAccess::runquery(" insert compare_arrear_writs ( staff_id ,current_execute_date , current_writ_id , current_writ_ver, 
                                                                    prev_execute_date , prev_writ_id , prev_writ_ver , arrear_ver , pay_year ) values 
                                                                  (" . $SID . ",'" . $res1[$i - 1]['execute_date'] . "'," . $res1[$i - 1]['writ_id'] . "," .
                                $res1[$i - 1]['writ_ver'] . ",'" . $res3[0]['execute_date'] . "'," . $res3[0]['writ_id'] . "," .
                                $res3[0]['writ_ver'] . "," . $res1[$i - 1]['arrear_ver'] . "," . $t . " ) ");
                    } */
            //....................we need this part......................
            $res = PdoDataAccess::runquery(" select * \r\n\t\t\t\t\t\t\t\t\t\tfrom compare_arrear_writs \r\n\t\t\t\t\t\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year =" . $t . " and arrear_ver = " . $MaxVer[0]['MV']);
            for ($i = 0; $i < count($res); $i++) {
                $writsWhereClause .= ' (wsi.writ_id=' . $res[$i]['current_writ_id'] . ' AND wsi.writ_ver=' . $res[$i]['current_writ_ver'] . ' AND wsi.staff_id=' . $res[$i]['staff_id'] . ') OR 
							 (wsi.writ_id=' . $res[$i]['prev_writ_id'] . ' AND wsi.writ_ver=' . $res[$i]['prev_writ_ver'] . ' AND wsi.staff_id=' . $res[$i]['staff_id'] . ' ) OR  ';
                $PrewritsWhereClause .= ' (wsi.writ_id=' . $res[$i]['prev_writ_id'] . ' AND wsi.writ_ver=' . $res[$i]['prev_writ_ver'] . ' AND wsi.staff_id=' . $res[$i]['staff_id'] . ' ) OR  ';
                $CurrwritsWhereClause .= ' (wsi.writ_id=' . $res[$i]['current_writ_id'] . ' AND wsi.writ_ver=' . $res[$i]['current_writ_ver'] . ' AND wsi.staff_id=' . $res[$i]['staff_id'] . ') OR ';
            }
            //.............................................................
        }
        $writsWhereClause = substr($writsWhereClause, 0, strlen($writsWhereClause) - 4);
        $PrewritsWhereClause = substr($PrewritsWhereClause, 0, strlen($PrewritsWhereClause) - 4);
        $CurrwritsWhereClause = substr($CurrwritsWhereClause, 0, strlen($CurrwritsWhereClause) - 4);
        $ResITM2 = PdoDataAccess::runquery(" select distinct wsi.salary_item_type_id  , sit.print_title ,sit.month_length_effect\r\n\t\t\t\t\t\t\t\t\t\t\t from writ_salary_items wsi \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join salary_item_types sit \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ton  wsi.salary_item_type_id  = sit.salary_item_type_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\twhere " . $writsWhereClause);
        //..............................................................................
        $ResITM = array();
        $diffVal = 0;
        for ($j = 0; $j < count($ResITM2); $j++) {
            $res6 = PdoDataAccess::runquery(" select wsi.salary_item_type_id , sit.print_title , sum(wsi.value) CurrVal \r\n\t\t\t\t\t\t\t\t\t\t\t from writ_salary_items wsi \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join salary_item_types sit \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ton  wsi.salary_item_type_id  = sit.salary_item_type_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\twhere wsi.must_pay = 1 and (" . $CurrwritsWhereClause . ") and wsi.salary_item_type_id =" . $ResITM2[$j]['salary_item_type_id']);
            $res7 = PdoDataAccess::runquery(" select wsi.salary_item_type_id , sit.print_title , sum(wsi.value) PreVal \r\n\t\t\t\t\t\t\t\t\t\t\t from writ_salary_items wsi \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join salary_item_types sit \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ton  wsi.salary_item_type_id  = sit.salary_item_type_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\twhere  wsi.must_pay = 1 and (" . $PrewritsWhereClause . ") and wsi.salary_item_type_id =" . $ResITM2[$j]['salary_item_type_id']);
            $diffVal = $res6[0]['CurrVal'] - $res7[0]['PreVal'];
            if ($diffVal != 0) {
                $diffVal = 0;
                $ResITM[] = array('salary_item_type_id' => $ResITM2[$j]['salary_item_type_id'], 'print_title' => $ResITM2[$j]['print_title'], 'month_length_effect' => $ResITM2[$j]['month_length_effect']);
            } else {
                //.................................... چنانچه قلمی در حکم فعلی حذف شده باشد.................
                for ($i = 0; $i < count($res); $i++) {
                    $res6 = PdoDataAccess::runquery(' select wsi.salary_item_type_id , sit.print_title , sum(wsi.value) CurrVal 
                                                        from writ_salary_items wsi 
                                                                    inner join salary_item_types sit 
                                                                                    on  wsi.salary_item_type_id  = sit.salary_item_type_id
                                                                    where wsi.must_pay = 1 and 
                                                                         (wsi.writ_id=' . $res[$i]['prev_writ_id'] . ' AND 
                                                                          wsi.writ_ver=' . $res[$i]['prev_writ_ver'] . ' AND
                                                                          wsi.staff_id=' . $res[$i]['staff_id'] . ' ) and 
                                                                          wsi.salary_item_type_id =' . $ResITM2[$j]['salary_item_type_id']);
                    $res7 = PdoDataAccess::runquery(' select wsi.salary_item_type_id , sit.print_title , sum(wsi.value) PreVal 
                                                        from writ_salary_items wsi 
                                                                inner join salary_item_types sit 
                                                                        on  wsi.salary_item_type_id  = sit.salary_item_type_id
                                                        where  wsi.must_pay = 1 and 
                                                              (wsi.writ_id=' . $res[$i]['current_writ_id'] . ' AND 
                                                               wsi.writ_ver=' . $res[$i]['current_writ_ver'] . ' AND 
                                                               wsi.staff_id=' . $res[$i]['staff_id'] . ') and 
                                                               wsi.salary_item_type_id =' . $ResITM2[$j]['salary_item_type_id']);
                    if (count($res6) != count($res7) || $res6[0]['CurrVal'] != $res7[0]['PreVal']) {
                        if (!in_array($ResITM2[$j]['salary_item_type_id'], $ResITM)) {
                            $ResITM[] = array('salary_item_type_id' => $ResITM2[$j]['salary_item_type_id'], 'print_title' => $ResITM2[$j]['print_title'], 'month_length_effect' => $ResITM2[$j]['month_length_effect']);
                        }
                    }
                }
            }
        }
        //..........................................................................
        $TotalsumDiff = $TotalMainVal = $TotalRowTax = $TotalRowIns = $TotalRowRet = $TotalPay = 0;
        for ($t = $_POST['from_pay_year']; $t < $_POST['to_pay_year'] + 1; $t++) {
            $retCoef = 1;
            $qry = " select max(arrear_ver) MV\r\n\t\t\t\t\tfrom  corrective_payment_writs \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . "\r\n\t\t       ";
            $MaxVer = PdoDataAccess::runquery($qry);
            if (count($MaxVer) == 0 || $MaxVer[0]['MV'] == 0) {
                continue;
            }
            $res = PdoDataAccess::runquery(" select * \r\n\t\t\t\t\t\t\t\t\t\tfrom compare_arrear_writs \r\n\t\t\t\t\t\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year =" . $t . " and arrear_ver = " . $MaxVer[0]['MV']);
            $prior_execute_date = $current_execute_date = $prior_writ_type = $current_writ_type = '';
            $current_writ_items = $prior_writ_items = array();
            $sdate = "";
            for ($i = 0; $i < count($res); $i++) {
                if ($res[$i]['current_writ_id'] == $res[$i]['prev_writ_id'] && $res[$i]['current_writ_ver'] == $res[$i]['prev_writ_ver']) {
                    continue;
                }
                if (!empty($LD[$t]['lastDate'])) {
                    $toDate = $LD[$t]['lastDate'];
                } else {
                    if ($LastDate == '0000-00-00') {
                        $toDate = $t . "/12/30";
                    } else {
                        $toDate = DateModules::CompareDate(str_replace("/", "-", DateModules::shamsi_to_miladi($t . "/12/30")), str_replace("/", "-", DateModules::shamsi_to_miladi($LastDate))) >= 0 ? $LastDate : $t . "/12/30";
                    }
                }
                /* if ($sdate != "" && $sdate > '0000-00-00')
                       $Row .= "<td>" . $sdate . "</td>";
                   else
                       $Row .= "<td>" .DateModules::miladi_to_shamsi($res[$i]['current_execute_date']). "</td>";
                   */
                if ($res[$i]['current_execute_date'] == $res[$i + 1]['current_execute_date']) {
                    //$Row .= "<td>" . DateModules::AddToJDate($toDate, 1) . "</td>";
                    $sdate = DateModules::AddToJDate($toDate, 1);
                }
                /*else if ($sdate != "" && $sdate > '0000-00-00' && empty($res[$i + 1]['current_execute_date']))
                                $Row .= "<td>" . $t . "/12/29" . "</td>";
                            elseif($res[$i + 1]['current_execute_date'] !='0000-00-00' && DateModules::CompareDate(DateModules::miladi_to_shamsi($res[$i + 1]['current_execute_date']),$LAST_PAY_DATE) == 1  )
                            {
                                  $Row .= "<td>" . $LAST_PAY_DATE . "</td>";
                                
                            }
                            else
                                $Row .= "<td>" . ( empty($res[$i + 1]['current_execute_date']) ? $toDate : DateModules::miladi_to_shamsi($res[$i + 1]['current_execute_date']) ) . "</td>";
                */
                if (!empty($LD[$t]['lastDate'])) {
                    $toDate2 = DateModules::shamsi_to_miladi(DateModules::AddToJDate($LD[$t]['lastDate'], 1));
                } else {
                    if ($LastDate == '0000-00-00') {
                        $toDate2 = DateModules::shamsi_to_miladi($t + 1 . "/01/01");
                    } else {
                        $toDate2 = DateModules::CompareDate(str_replace("/", "-", DateModules::shamsi_to_miladi($t . "/12/30")), str_replace("/", "-", DateModules::shamsi_to_miladi($LastDate))) >= 0 ? DateModules::AddToJDate($LastDate, 1) : DateModules::shamsi_to_miladi($t + 1 . "/01/01");
                    }
                }
                $endDate = empty($res[$i + 1]['current_execute_date']) ? $toDate2 : $res[$i + 1]['current_execute_date'];
                if ($res[$i]['current_execute_date'] == $res[$i + 1]['current_execute_date']) {
                    $endDate = $toDate2;
                }
                if ($sdate != "" && $sdate > '0000-00-00' && empty($res[$i + 1]['current_execute_date'])) {
                    $endDate = $t + 1 . "/1/01";
                    if ($resPerInfo[0]['person_type'] == 3) {
                        $DayNo = round(DateModules::GDateMinusGDate(DateModules::shamsi_to_miladi($endDate), DateModules::shamsi_to_miladi($sdate)));
                        $DayNo2 = calculate_duration($sdate, $endDate);
                    } else {
                        $DayNo = calculate_duration($sdate, $endDate);
                    }
                } else {
                    if ($resPerInfo[0]['person_type'] == 3) {
                        $DayNo = round(DateModules::GDateMinusGDate(DateModules::shamsi_to_miladi($endDate), $res[$i]['current_execute_date']));
                        $DayNo2 = calculate_duration($res[$i]['current_execute_date'], $endDate);
                    } else {
                        $DayNo = calculate_duration($res[$i]['current_execute_date'], $endDate);
                    }
                }
                if ($res[$i + 1]['current_execute_date'] != '0000-00-00' && DateModules::CompareDate(DateModules::miladi_to_shamsi($res[$i + 1]['current_execute_date']), $LAST_PAY_DATE) == 1) {
                    $DayNo = calculate_duration($res[$i]['current_execute_date'], DateModules::shamsi_to_miladi($LAST_PAY_DATE));
                }
                // $Row .= "<td>" . $DayNo . "</td>";
                $sumDiff = $MainVal = 0;
                $RetInc = $TaxInc = $InsInc = 0;
                for ($j = 0; $j < count($ResITM); $j++) {
                    $val1 = get_writSalaryItem_value($res[$i]["current_writ_id"], $res[$i]["current_writ_ver"], $res[$i]["staff_id"], $ResITM[$j]["salary_item_type_id"]);
                    $val2 = get_writSalaryItem_value($res[$i]["prev_writ_id"], $res[$i]["prev_writ_ver"], $res[$i]["staff_id"], $ResITM[$j]["salary_item_type_id"]);
                    $RetRes = PdoDataAccess::runquery(" select retired_include , tax_include , insure_include \r\n                                                      from salary_item_types where salary_item_type_id = " . $ResITM[$j]["salary_item_type_id"]);
                    //  $Row .= "<td>" . CurrencyModulesclass::toCurrency($val1 - $val2) . (($val1 - $val2) < 0 ? "-&nbsp;" : "" ) . "</td>";
                    $sumDiff += $val1 - $val2;
                    if (empty($Itm[$j]['sumVal'])) {
                        $Itm[$j]['sumVal'] = 0;
                        $Itm[$j]['sumCol'] = 0;
                    }
                    $Itm[$j]['sumVal'] += $val1 - $val2;
                    if ($ResITM[$j]["month_length_effect"] == 0 && $resPerInfo[0]['person_type'] == 3) {
                        $Itm[$j]['sumCol'] += round(($val1 - $val2) * $DayNo2 / 30);
                        $MainVal += round(($val1 - $val2) * $DayNo2 / 30);
                    } elseif ($resPerInfo[0]['person_type'] == 5 && $_SESSION['UserID'] == 'jafarkhani') {
                        // echo $endDate . "---<br>" ;
                        // echo DateModules::miladi_to_shamsi($res[$i]['current_execute_date'])."***<br>" ; die();
                        $arr3 = preg_split('/\\//', DateModules::miladi_to_shamsi($res[$i]['current_execute_date']));
                        $arr4 = preg_split('/\\//', DateModules::miladi_to_shamsi($endDate));
                        if ($arr4[1] * 1 == 1 && $arr4[0] == $arr3[0] + 1) {
                            $EP = 12;
                        } else {
                            $EP = $arr4[1] * 1;
                        }
                        //.........................
                        $std = $res[$i]['current_execute_date'];
                        $stMonth = $arr3[1] * 1;
                        if ($stMonth < 7) {
                            $endt = $arr3[0] . "/" . $arr3[1] . "/31";
                        } elseif (6 < $stMonth && $stMonth < 12) {
                            $endt = $arr3[0] . "/" . $arr3[1] . "/30";
                        } elseif ($stMonth == 12) {
                            $endt = $arr3[0] . "/" . $arr3[1] . "/29";
                        }
                        for ($k = $arr3[1] * 1; $k < $EP + 1; $k++) {
                            if (DateModules::CompareDate(DateModules::miladi_to_shamsi($endt), DateModules::miladi_to_shamsi($endDate)) < 1) {
                                $DYNo = round(DateModules::GDateMinusGDate(DateModules::shamsi_to_miladi($endt), $std)) + 1;
                                if ($stMonth < 7) {
                                    $mNO = 31;
                                } elseif ($stMonth > 6 && $stMonth < 12) {
                                    $mNO = 30;
                                } elseif ($stMonth == 12) {
                                    $mNO = 29;
                                }
                                $Itm[$j]['sumCol'] += round(($val1 - $val2) * $DYNo / $mNO);
                                $MainVal += round(($val1 - $val2) * $DYNo / $mNO);
                                $TaxInc += round(($val1 - $val2) * $DYNo / $mNO);
                                //........................
                                $std = DateModules::shamsi_to_miladi($arr3[0] . "/" . ($k + 1) . "/01");
                                $stMonth = $k + 1;
                                //$arr3[1] + 1;
                                if ($stMonth < 7) {
                                    $endt = $arr3[0] . "/" . $stMonth . "/31";
                                } elseif (6 < $stMonth && $stMonth < 12) {
                                    $endt = $arr3[0] . "/" . $stMonth . "/30";
                                } elseif ($stMonth == 12) {
                                    $endt = $arr3[0] . "/" . $stMonth . "/29";
                                }
                            } else {
                                //echo "****";
                                // die();
                                $endt = $endDate;
                                $DYNo = round(DateModules::GDateMinusGDate(DateModules::shamsi_to_miladi($endt), $std));
                                if ($stMonth < 7) {
                                    $mNO = 31;
                                } elseif ($stMonth > 6 && $stMonth < 12) {
                                    $mNO = 30;
                                } elseif ($stMonth == 12) {
                                    $mNO = 29;
                                }
                                $Itm[$j]['sumCol'] += round(($val1 - $val2) * $DYNo / $mNO);
                                $MainVal += round(($val1 - $val2) * $DYNo / $mNO);
                                $TaxInc += round(($val1 - $val2) * $DYNo / $mNO);
                                break;
                            }
                        }
                    } else {
                        $Itm[$j]['sumCol'] += round(($val1 - $val2) * $DayNo / 30);
                        $MainVal += round(($val1 - $val2) * $DayNo / 30);
                    }
                    //...............................
                    if ($RetRes[0]['retired_include'] == 1) {
                        $RetInc += $val1 - $val2;
                    }
                    if ($RetRes[0]['tax_include'] == 1 && $resPerInfo[0]['person_type'] != 5) {
                        if ($ResITM[$j]["month_length_effect"] == 0 && $resPerInfo[0]['person_type'] == 3) {
                            $TaxInc += round(($val1 - $val2) * $DayNo2 / 30);
                        } else {
                            $TaxInc += round(($val1 - $val2) * $DayNo / 30);
                        }
                    }
                    if ($RetRes[0]['insure_include'] == 1) {
                        $InsInc += $val1 - $val2;
                    }
                }
                //$MainVal = round(($sumDiff) * $DayNo / 30);
                //....................مالیات...........
                $qry = " select count(*) cn  \r\n\t\t\t\t\tfrom Arrear_payment_items \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . " and pay_month  = 12 and salary_item_type_id in (146,147,148,747)";
                $res4 = PdoDataAccess::runquery($qry);
                if ($res4[0]['cn'] > 0) {
                    //.........................................
                    $qry = " select count(*) cnp\r\n            from payments \r\n               where staff_id = " . $SID . " and pay_year = " . $t;
                    $resE = PdoDataAccess::runquery($qry);
                    if ($resE[0]['cnp'] == 0) {
                        $sdatetax = DateModules::shamsi_to_miladi($t . "/12/29");
                        $qry = " SELECT tti.from_value\r\n                FROM staff_tax_history sth\r\n                        inner join tax_tables tt on sth.tax_table_type_id = tt.tax_table_type_id\r\n                        inner join tax_table_items tti on tti.tax_table_id = tt.tax_table_id\r\n\r\n                WHERE sth.staff_id = " . $SID . " and \r\n                    sth.start_date < '" . DateModules::Now() . "' and\r\n                    ( sth.end_date = '0000-00-00' or sth.end_date is null or \r\n                    sth.end_date > '" . DateModules::Now() . "' ) and\r\n                    tt.from_date < '" . $sdatetax . "' and\r\n                    ( tt.to_date = '0000-00-00' or tt.to_date is null or tt.to_date >= '" . $sdatetax . "'  ) and coeficient = 0.1 ";
                        $resFval = PdoDataAccess::runquery($qry);
                        $TaxInc -= $resFval[0]['from_value'];
                    }
                    //.........................................
                    $RowTax = $TaxInc * 0.1;
                    //round(($TaxInc * $DayNo / 30) * 0.1);
                } else {
                    $RowTax = 0;
                }
                //..................................
                $qry = " select count(*) cn  \r\n\t\t\t\t\tfrom Arrear_payment_items \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . " and pay_month  = 12 and salary_item_type_id in (149 , 150)";
                $res3 = PdoDataAccess::runquery($qry);
                if ($res3[0]['cn'] > 0) {
                    $RowRet = round($RetInc * $DayNo / 30 * 0.09);
                } else {
                    $RowRet = 0;
                }
                //.......................بیمه تامین اجتماعی...........
                $qry = " select count(*) cn  \r\n\t\t\t\t\tfrom Arrear_payment_items \r\n\t\t\t\t\t\twhere staff_id = " . $SID . " and pay_year = " . $t . " and pay_month  = 12 and salary_item_type_id in (144,145,744,9920)";
                $res5 = PdoDataAccess::runquery($qry);
                if ($res5[0]['cn'] > 0) {
                    $RowInsure = round($InsInc * $DayNo / 30 * 0.07000000000000001);
                } else {
                    $RowInsure = 0;
                }
                //.....................................
                if ($resPerInfo[0]['last_retired_pay'] != NULL && $resPerInfo[0]['last_retired_pay'] != '0000-00-00' && DateModules::CompareDate($resPerInfo[0]['last_retired_pay'], DateModules::shamsi_to_miladi($t . "/01/01")) == -1) {
                    $RowRet = $retCoef = 0;
                }
                $TotalsumDiff += $sumDiff;
                $TotalMainVal += $MainVal;
                $TotalRowTax += $RowTax;
                $TotalRowRet += $RowRet;
                $TotalRowIns += $RowInsure;
                $TotalPay += $MainVal - ($RowTax + $RowRet + $RowInsure);
                /* $Row .= "<td>" . ( ($sumDiff < 0 ) ? CurrencyModulesclass::toCurrency($sumDiff) . "-" : CurrencyModulesclass::toCurrency($sumDiff)) . "</td>
                		 <td>" . (($MainVal < 0 ) ? CurrencyModulesclass::toCurrency($MainVal) . "-" : CurrencyModulesclass::toCurrency($MainVal)) . "</td><td>" .
                                  (($RowTax < 0 ) ? CurrencyModulesclass::toCurrency($RowTax) . "-" : CurrencyModulesclass::toCurrency($RowTax)) . "</td><td>" .
                                  (($RowRet < 0 ) ? CurrencyModulesclass::toCurrency($RowRet) . "-" : CurrencyModulesclass::toCurrency($RowRet)) . "</td><td>" .
                                  (($RowInsure < 0 ) ? CurrencyModulesclass::toCurrency($RowInsure) . "-" : CurrencyModulesclass::toCurrency($RowInsure)) . "</td><td>" .
                                  ((($MainVal - ($RowTax + $RowRet + $RowInsure )) < 0 ) ? CurrencyModulesclass::toCurrency(($MainVal - ($RowTax + $RowRet + $RowInsure))) . "-" : CurrencyModulesclass::toCurrency(($MainVal - ($RowTax + $RowRet + $RowInsure)))) . "</td></tr>"; */
            }
            //   $Row .= "</tr>";
        }
    }
Пример #8
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;
     }
 }
Пример #9
0
function DelayInstallments()
{
    $RequestID = $_POST["RequestID"];
    $InstallmentID = $_POST["InstallmentID"];
    $newDate = $_POST["newDate"];
    $PartObj = LON_ReqParts::GetValidPartObj($RequestID);
    $pdo = PdoDataAccess::getPdoObject();
    $pdo->beginTransaction();
    if ($_POST["IsRemainCompute"] == " 0") {
        $dt = LON_installments::SelectAll("r.RequestID=? AND InstallmentID>=?", array($RequestID, $InstallmentID));
        $days = 0;
        for ($i = 0; $i < count($dt); $i++) {
            $obj = new LON_installments();
            $obj->InstallmentID = $dt[$i]["InstallmentID"];
            $obj->IsDelayed = "YES";
            if (!$obj->EditInstallment($pdo)) {
                $pdo->rollBack();
                echo Response::createObjectiveResponse(false, "1");
                die;
            }
            //...........................................
            if ($days == 0) {
                $newDate = DateModules::shamsi_to_miladi($newDate, "-");
                $days = DateModules::GDateMinusGDate($newDate, $dt[$i]["InstallmentDate"]);
            }
            $obj = new LON_installments();
            $obj->RequestID = $RequestID;
            $obj->InstallmentDate = DateModules::AddToGDate($dt[$i]["InstallmentDate"], $days);
            $extraWage = round($dt[$i]["InstallmentAmount"] * $PartObj->CustomerWage * $days / 36500);
            $obj->InstallmentAmount = $dt[$i]["InstallmentAmount"] * 1 + $extraWage;
            if (!$obj->AddInstallment($pdo)) {
                $pdo->rollBack();
                echo Response::createObjectiveResponse(false, "2");
                die;
            }
        }
    } else {
        $dt = array();
        $dt2 = LON_requests::ComputePayments($RequestID, $dt);
        $index = 0;
        $ComputeRecord = $dt2[$index++];
        $days = 0;
        for ($i = 0; $i < count($dt); $i++) {
            if ($dt[$i]["InstallmentID"] < $InstallmentID) {
                while ($ComputeRecord["InstallmentID"] == $dt[$i]["InstallmentID"]) {
                    $ComputeRecord = $dt2[++$index];
                }
                continue;
            }
            $remain = 0;
            while ($ComputeRecord["InstallmentID"] == $dt[$i]["InstallmentID"]) {
                $remain = $ComputeRecord["remainder"];
                $ComputeRecord = $index + 1 < count($dt2) ? $dt2[++$index] : null;
            }
            $obj = new LON_installments();
            $obj->InstallmentID = $dt[$i]["InstallmentID"];
            $obj->IsDelayed = "YES";
            if (!$obj->EditInstallment($pdo)) {
                $pdo->rollBack();
                echo Response::createObjectiveResponse(false, "1");
                die;
            }
            //...........................................
            if ($days == 0) {
                $newDate = DateModules::shamsi_to_miladi($newDate, "-");
                $days = DateModules::GDateMinusGDate($newDate, $dt[$i]["InstallmentDate"]);
            }
            $obj = new LON_installments();
            $obj->RequestID = $RequestID;
            $obj->InstallmentDate = DateModules::AddToGDate($dt[$i]["InstallmentDate"], $days);
            $extraWage = round($remain * $PartObj->CustomerWage * $days / 36500);
            $obj->InstallmentAmount = $dt[$i]["InstallmentAmount"] * 1 + $extraWage;
            if (!$obj->AddInstallment($pdo)) {
                $pdo->rollBack();
                echo Response::createObjectiveResponse(false, "2");
                die;
            }
        }
    }
    if (ExceptionHandler::GetExceptionCount() > 0) {
        $pdo->rollBack();
        print_r(ExceptionHandler::PopAllExceptions());
        echo Response::createObjectiveResponse(false, "");
        die;
    }
    $pdo->commit();
    echo Response::createObjectiveResponse(true, "");
    die;
}
Пример #10
0
function RegisterWarrantyDoc($ReqObj, $WageCost, $BankTafsili, $AccountTafsili, $Block_CostID, $DocID, $pdo)
{
    /*@var $ReqObj WAR_requests */
    //------------- get CostCodes --------------------
    $CostCode_warrenty = FindCostID("300");
    $CostCode_warrenty_commitment = FindCostID("700");
    $CostCode_wage = FindCostID("750-07");
    $CostCode_FutureWage = FindCostID("760-07");
    $CostCode_fund = FindCostID("100");
    $CostCode_seporde = FindCostID("690");
    $CostCode_pasandaz = FindCostID("209-10");
    $CostCode_guaranteeAmount_zemanati = FindCostID("904-02");
    $CostCode_guaranteeAmount_daryafti = FindCostID("904-04");
    $CostCode_guaranteeAmount2_zemanati = FindCostID("905-02");
    $CostCode_guaranteeAmount2_daryafti = FindCostID("905-04");
    //------------------------------------------------
    $CycleID = substr(DateModules::miladi_to_shamsi($ReqObj->StartDate), 0, 4);
    //------------------ find tafsilis ---------------
    $PersonTafsili = FindTafsiliID($ReqObj->PersonID, TAFTYPE_PERSONS);
    if (!$PersonTafsili) {
        ExceptionHandler::PushException("تفصیلی مربوطه یافت نشد.[" . $ReqObj->PersonID . "]");
        return false;
    }
    //------------------- compute wage ------------------
    $days = DateModules::GDateMinusGDate($ReqObj->EndDate, $ReqObj->StartDate);
    //if(DateModules::YearIsLeap($CycleID));
    $days -= 1;
    $TotalWage = round($days * $ReqObj->amount * 0.9 * $ReqObj->wage / 36500) + $ReqObj->RegisterAmount * 1;
    $years = SplitYears(DateModules::miladi_to_shamsi($ReqObj->StartDate), DateModules::miladi_to_shamsi($ReqObj->EndDate), $TotalWage);
    //--------------- check pasandaz remaindar -----------------
    $dt = PdoDataAccess::runquery("select sum(CreditorAmount-DebtorAmount) remain\r\n\t\tfrom ACC_DocItems join ACC_docs using(DocID) where CycleID=? AND CostID=?\r\n\t\t\tAND TafsiliType=? AND TafsiliID=? AND BranchID=?", array($CycleID, $CostCode_pasandaz, TAFTYPE_PERSONS, $PersonTafsili, $ReqObj->BranchID));
    if ($WageCost == "209-10" && $dt[0][0] * 1 < $ReqObj->amount * 0.1) {
        ExceptionHandler::PushException("مانده حساب پس انداز مشتری کمتر از 10% مبلغ ضمانت نامه می باشد");
        return false;
    }
    if ($WageCost == "209-10" && $dt[0][0] * 1 < $ReqObj->amount * 0.1 + $TotalWage) {
        ExceptionHandler::PushException("مانده حساب پس انداز مشتری کمتر از مبلغ کارمزد می باشد");
        return false;
    }
    if ($ReqObj->IsBlock == "YES") {
        if ($Block_CostID != "" && $Block_CostID != $CostCode_pasandaz) {
            $dt = PdoDataAccess::runquery("select sum(CreditorAmount-DebtorAmount) remain\r\n\t\t\tfrom ACC_DocItems join ACC_docs using(DocID) where CycleID=? AND CostID=?\r\n\t\t\t\tAND TafsiliType=? AND TafsiliID=? AND BranchID=?", array($CycleID, $Block_CostID, TAFTYPE_PERSONS, $PersonTafsili, $ReqObj->BranchID));
        }
        $amount = $ReqObj->amount * 1;
        if ($WageCost == "209-10") {
            $amount += $ReqObj->amount * 0.1 + $TotalWage;
        }
        if ($dt[0][0] * 1 < $amount) {
            ExceptionHandler::PushException("مانده حساب انتخابی جهت بلوکه کمتر از مبلغ ضمانت نامه می باشد");
            return false;
        }
    }
    //---------------- add doc header --------------------
    if ($DocID == null) {
        $DocObj = new ACC_docs();
        $DocObj->RegDate = PDONOW;
        $DocObj->regPersonID = $_SESSION['USER']["PersonID"];
        $DocObj->DocDate = PDONOW;
        $DocObj->CycleID = $CycleID;
        $DocObj->BranchID = $ReqObj->BranchID;
        $DocObj->DocType = DOCTYPE_WARRENTY;
        $DocObj->description = "ضمانت نامه " . $ReqObj->_TypeDesc . " به شماره " . $ReqObj->RequestID . " به نام " . $ReqObj->_fullname;
        if (!$DocObj->Add($pdo)) {
            ExceptionHandler::PushException("خطا در ایجاد سند");
            return false;
        }
    } else {
        $DocObj = new ACC_docs($DocID);
    }
    //----------------- add Doc items ------------------------
    $itemObj = new ACC_DocItems();
    $itemObj->DocID = $DocObj->DocID;
    $itemObj->TafsiliType = TAFTYPE_PERSONS;
    $itemObj->TafsiliID = $PersonTafsili;
    $itemObj->SourceType = DOCTYPE_WARRENTY;
    $itemObj->SourceID = $ReqObj->RequestID;
    $itemObj->SourceID2 = $ReqObj->ReqVersion;
    $itemObj->locked = "YES";
    $itemObj->CostID = $CostCode_warrenty;
    $itemObj->DebtorAmount = $ReqObj->amount;
    $itemObj->CreditorAmount = 0;
    if (!$itemObj->Add($pdo)) {
        ExceptionHandler::PushException("خطا در ثبت ردیف ضمانت نامه");
        return false;
    }
    unset($itemObj->ItemID);
    $itemObj->CostID = $CostCode_warrenty_commitment;
    $itemObj->DebtorAmount = 0;
    $itemObj->CreditorAmount = $ReqObj->amount;
    if (!$itemObj->Add($pdo)) {
        ExceptionHandler::PushException("خطا در ثبت ردیف تعهد ضمانت نامه");
        return false;
    }
    //------------------- compute wage -----------------------
    $curYear = substr(DateModules::miladi_to_shamsi($ReqObj->StartDate), 0, 4) * 1;
    foreach ($years as $Year => $amount) {
        if ($amount == 0) {
            continue;
        }
        $YearTafsili = FindTafsiliID($Year, TAFTYPE_YEARS);
        if (!$YearTafsili) {
            ExceptionHandler::PushException("تفصیلی مربوطه یافت نشد.[" . $Year . "]");
            return false;
        }
        unset($itemObj->ItemID);
        $itemObj->details = "کارمزد ضمانت نامه شماره " . $ReqObj->RequestID;
        $itemObj->CostID = $Year == $curYear ? $CostCode_wage : $CostCode_FutureWage;
        $itemObj->DebtorAmount = 0;
        $itemObj->CreditorAmount = $amount;
        $itemObj->TafsiliType = TAFTYPE_YEARS;
        $itemObj->TafsiliID = $YearTafsili;
        $itemObj->Add($pdo);
    }
    //---------------------------- block Cost ----------------------------
    if ($ReqObj->IsBlock == "YES") {
        $blockObj = new ACC_CostBlocks();
        $blockObj->CostID = !empty($Block_CostID) ? $Block_CostID : $CostCode_pasandaz;
        $blockObj->TafsiliType = TAFTYPE_PERSONS;
        $blockObj->TafsiliID = $PersonTafsili;
        $blockObj->BlockAmount = $ReqObj->amount;
        $blockObj->IsLock = "YES";
        $blockObj->SourceType = DOCTYPE_WARRENTY;
        $blockObj->SourceID = $ReqObj->RequestID;
        $blockObj->details = "بابت ضمانت نامه شماره " . $ReqObj->RequestID;
        if (!$blockObj->Add()) {
            print_r(ExceptionHandler::PopAllExceptions());
            ExceptionHandler::PushException("خطا در بلوکه کردن حساب پس انداز");
            return false;
        }
    }
    // ---------------------- Warrenty costs -----------------------------
    $totalCostAmount = 0;
    $dt = PdoDataAccess::runquery("select * from WAR_costs where RequestID=?", array($ReqObj->RequestID));
    foreach ($dt as $row) {
        $totalCostAmount += ($row["CostType"] == "DEBTOR" ? 1 : -1) * $row["CostAmount"] * 1;
        unset($itemObj->ItemID);
        $itemObj->SourceID2 = $row["CostID"];
        $itemObj->details = $row["CostDesc"];
        $itemObj->CostID = $row["CostCodeID"];
        $itemObj->DebtorAmount = $row["CostType"] == "DEBTOR" ? $row["CostAmount"] : 0;
        $itemObj->CreditorAmount = $row["CostType"] == "CREDITOR" ? $row["CostAmount"] : 0;
        $itemObj->Add($pdo);
    }
    // ----------------------------- bank --------------------------------
    unset($itemObj->ItemID);
    unset($itemObj->TafsiliType);
    unset($itemObj->TafsiliID);
    $itemObj->details = "بابت 10% سپرده ضمانت نامه شماره " . $ReqObj->RequestID;
    $itemObj->CostID = $CostCode_seporde;
    $itemObj->DebtorAmount = 0;
    $itemObj->CreditorAmount = $ReqObj->amount * 0.1;
    $itemObj->Add($pdo);
    unset($itemObj->ItemID);
    $itemObj->details = "بابت کارمزد ضمانت نامه شماره " . $ReqObj->RequestID;
    $itemObj->CostID = FindCostID($WageCost);
    $itemObj->DebtorAmount = $TotalWage + $ReqObj->amount * 0.1 - $totalCostAmount;
    $itemObj->CreditorAmount = 0;
    if ($WageCost == "101") {
        $itemObj->TafsiliType = TAFTYPE_BANKS;
        if ($BankTafsili != "") {
            $itemObj->TafsiliID = $BankTafsili;
        }
        $itemObj->TafsiliType2 = TAFTYPE_ACCOUNTS;
        if ($AccountTafsili != "") {
            $itemObj->TafsiliID2 = $AccountTafsili;
        }
    }
    $itemObj->Add($pdo);
    //---------- ردیف های تضمین  ----------
    $SumAmount = 0;
    $countAmount = 0;
    $dt = PdoDataAccess::runquery("\r\n\t\tSELECT DocumentID, ParamValue, InfoDesc as DocTypeDesc\r\n\t\t\tFROM DMS_DocParamValues\r\n\t\t\tjoin DMS_DocParams using(ParamID)\r\n\t\t\tjoin DMS_documents d using(DocumentID)\r\n\t\t\tjoin BaseInfo b on(InfoID=d.DocType AND TypeID=8)\r\n\t\t\tleft join ACC_DocItems on(SourceType=" . DOCTYPE_DOCUMENT . " AND SourceID=DocumentID)\r\n\t\twhere ItemID is null AND b.param1=1 AND \r\n\t\t\tparamType='currencyfield' AND ObjectType='warrenty' AND ObjectID=?", array($ReqObj->RequestID), $pdo);
    foreach ($dt as $row) {
        unset($itemObj->ItemID);
        $itemObj->CostID = $CostCode_guaranteeAmount_zemanati;
        $itemObj->DebtorAmount = $row["ParamValue"];
        $itemObj->CreditorAmount = 0;
        $itemObj->TafsiliType = TAFTYPE_PERSONS;
        $itemObj->TafsiliID = $PersonTafsili;
        $itemObj->SourceType = DOCTYPE_DOCUMENT;
        $itemObj->SourceID = $row["DocumentID"];
        $itemObj->details = $row["DocTypeDesc"];
        $itemObj->Add($pdo);
        $SumAmount += $row["ParamValue"] * 1;
        $countAmount++;
    }
    if ($SumAmount > 0) {
        unset($itemObj->ItemID);
        unset($itemObj->TafsiliType);
        unset($itemObj->TafsiliID);
        unset($itemObj->details);
        $itemObj->CostID = $CostCode_guaranteeAmount2_zemanati;
        $itemObj->DebtorAmount = 0;
        $itemObj->CreditorAmount = $SumAmount;
        $itemObj->Add($pdo);
    }
    if (ExceptionHandler::GetExceptionCount() > 0) {
        return false;
    }
    return $DocObj->DocID;
}
Пример #11
0
 private static function ComputePaymentsBaseOnInstallment($RequestID, &$installments, $pdo = null)
 {
     $returnArr = array();
     $pays = PdoDataAccess::runquery("\r\n\t\t\tselect substr(p.PayDate,1,10) PayDate, sum(PayAmount) PayAmount, sum(PayAmount) FixPayAmount\r\n\t\t\t\tfrom LON_BackPays p\r\n\t\t\t\tleft join ACC_IncomeCheques i using(IncomeChequeID)\r\n\t\t\t\tleft join BaseInfo bi on(bi.TypeID=6 AND bi.InfoID=p.PayType)\r\n\t\t\t\twhere RequestID=? AND \r\n\t\t\t\t\tif(p.PayType=" . BACKPAY_PAYTYPE_CHEQUE . ",i.ChequeStatus=" . INCOMECHEQUE_VOSUL . ",1=1)\r\n\r\n\t\t\t\tgroup by substr(PayDate,1,10)\r\n\t\t\t\torder by substr(PayDate,1,10)", array($RequestID), $pdo);
     $PayRecord = count($pays) == 0 ? null : $pays[0];
     $payIndex = 1;
     $Forfeit = 0;
     for ($i = 0; $i < count($installments); $i++) {
         if ($installments[$i]["IsDelayed"] == "YES") {
             continue;
         }
         $forfeitDays = 0;
         $installments[$i]["CurForfeitAmount"] = 0;
         $installments[$i]["ForfeitAmount"] = 0;
         $installments[$i]["ForfeitDays"] = 0;
         $installments[$i]["remainder"] = 0;
         $installments[$i]["FixPayAmount"] = 0;
         $installments[$i]["PayAmount"] = 0;
         $installments[$i]["UsedPayAmount"] = 0;
         $installments[$i]["PayDate"] = '';
         if ($PayRecord == null) {
             $installments[$i]["TotalRemainder"] = $i == 0 ? 0 : $installments[$i - 1]["TotalRemainder"];
             $ToDate = DateModules::Now();
             $amount = $installments[$i]["InstallmentAmount"];
             $forfeitDays = DateModules::GDateMinusGDate($ToDate, $installments[$i]["InstallmentDate"]);
             $CurForfeit = round($amount * $installments[$i]["ForfeitPercent"] * $forfeitDays / 36500);
             if ($installments[$i]["InstallmentDate"] < $ToDate) {
                 $installments[$i]["ForfeitDays"] = $forfeitDays;
                 $Forfeit += $CurForfeit;
                 $installments[$i]["ForfeitAmount"] = $Forfeit;
                 $installments[$i]["CurForfeitAmount"] = $CurForfeit;
                 $installments[$i]["remainder"] = $amount;
                 $installments[$i]["TotalRemainder"] += $amount + $CurForfeit;
             } else {
                 $installments[$i]["ForfeitDays"] = 0;
                 $installments[$i]["CurForfeitAmount"] = 0;
                 $installments[$i]["ForfeitAmount"] = $Forfeit;
                 $installments[$i]["remainder"] = $amount;
                 $installments[$i]["TotalRemainder"] += $amount;
             }
             $returnArr[] = $installments[$i];
             continue;
         } else {
             $installments[$i]["TotalRemainder"] = 0;
         }
         $remainder = $installments[$i]["InstallmentAmount"];
         $StartDate = $installments[$i]["InstallmentDate"];
         while (true) {
             $ToDate = $PayRecord == null ? DateModules::Now() : $PayRecord["PayDate"];
             if ($PayRecord != null) {
                 $installments[$i]["FixPayAmount"] = $PayRecord["FixPayAmount"] * 1;
                 $installments[$i]["PayAmount"] = $PayRecord["PayAmount"] * 1;
                 $installments[$i]["UsedPayAmount"] = $PayRecord["PayAmount"] * 1;
                 $installments[$i]["PayDate"] = $PayRecord["PayDate"];
             } else {
                 $installments[$i]["FixPayAmount"] = 0;
                 $installments[$i]["PayAmount"] = 0;
                 $installments[$i]["UsedPayAmount"] = 0;
                 $installments[$i]["PayDate"] = DateModules::Now();
             }
             $forfeitDays = DateModules::GDateMinusGDate($ToDate, $StartDate);
             $CurForfeit = round($remainder * $installments[$i]["ForfeitPercent"] * $forfeitDays / 36500);
             if ($StartDate < $ToDate) {
                 $installments[$i]["ForfeitDays"] = $forfeitDays;
                 $installments[$i]["CurForfeitAmount"] = $CurForfeit;
                 $Forfeit += $CurForfeit;
             }
             if ($PayRecord == null) {
                 $installments[$i]["TotalRemainder"] += $CurForfeit;
                 $installments[$i]["remainder"] = $remainder;
                 $installments[$i]["ForfeitAmount"] = $Forfeit;
                 $returnArr[] = $installments[$i];
                 break;
             }
             if ($remainder <= $PayRecord["PayAmount"] * 1) {
                 $PayRecord["PayAmount"] = $PayRecord["PayAmount"] * 1 - $remainder;
                 $installments[$i]["UsedPayAmount"] = $remainder;
                 $remainder = 0;
                 $installments[$i]["TotalRemainder"] = $Forfeit;
                 $installments[$i]["remainder"] = 0;
                 $installments[$i]["ForfeitAmount"] = $Forfeit;
                 if ($PayRecord["PayAmount"] == 0) {
                     $StartDate = max($PayRecord["PayDate"], $installments[$i]["InstallmentDate"]);
                     $PayRecord = $payIndex < count($pays) ? $pays[$payIndex++] : null;
                 }
                 $returnArr[] = $installments[$i];
                 break;
             }
             $remainder = $remainder - $PayRecord["PayAmount"] * 1;
             $StartDate = max($PayRecord["PayDate"], $installments[$i]["InstallmentDate"]);
             $installments[$i]["TotalRemainder"] = $remainder + $Forfeit;
             $installments[$i]["remainder"] = $remainder;
             $installments[$i]["ForfeitAmount"] = $Forfeit;
             $PayRecord = $payIndex < count($pays) ? $pays[$payIndex++] : null;
             $returnArr[] = $installments[$i];
         }
     }
     if ($Forfeit > 0) {
         while (true) {
             if ($PayRecord["PayAmount"] > 0) {
                 $installments[$i]["InstallmentDate"] = "---";
                 $installments[$i]["InstallmentAmount"] = 0;
                 $installments[$i]["FixPayAmount"] = $PayRecord["FixPayAmount"];
                 $installments[$i]["PayAmount"] = $PayRecord["PayAmount"];
                 $installments[$i]["UsedPayAmount"] = $PayRecord["PayAmount"];
                 $installments[$i]["PayDate"] = $PayRecord["PayDate"];
                 $Forfeit = $Forfeit - $PayRecord["PayAmount"] * 1;
                 $installments[$i]["ForfeitDays"] = 0;
                 $installments[$i]["TotalRemainder"] = $Forfeit;
                 $installments[$i]["CurForfeitAmount"] = 0;
                 $installments[$i]["ForfeitAmount"] = $Forfeit;
                 $installments[$i]["remainder"] = 0;
                 $returnArr[] = $installments[$i];
             }
             $PayRecord = $payIndex < count($pays) ? $pays[$payIndex++] : null;
             if ($PayRecord == null) {
                 break;
             }
         }
     }
     return $returnArr;
 }