Beispiel #1
0
function SplitYears($startDate, $endDate, $TotalAmount)
{
    if (substr($startDate, 0, 1) == 2) {
        $startDate = DateModules::miladi_to_shamsi($startDate);
    }
    if (substr($endDate, 0, 1) == 2) {
        $endDate = DateModules::miladi_to_shamsi($endDate);
    }
    $arr = preg_split('/[\\-\\/]/', $startDate);
    $StartYear = $arr[0] * 1;
    $totalDays = 0;
    $yearDays = array();
    $newStartDate = $startDate;
    while (DateModules::CompareDate($newStartDate, $endDate) < 0) {
        $arr = preg_split('/[\\-\\/]/', $newStartDate);
        $LastDayOfYear = DateModules::lastJDateOfYear($arr[0]);
        if (DateModules::CompareDate($LastDayOfYear, $endDate) > 0) {
            $LastDayOfYear = $endDate;
        }
        $yearDays[$StartYear] = DateModules::JDateMinusJDate($LastDayOfYear, $newStartDate) + 1;
        $totalDays += $yearDays[$StartYear];
        $StartYear++;
        $newStartDate = DateModules::AddToJDate($LastDayOfYear, 1);
    }
    $TotalDays = DateModules::JDateMinusJDate($endDate, $startDate) + 1;
    $sum = 0;
    foreach ($yearDays as $year => $days) {
        $yearDays[$year] = round($days / $TotalDays * $TotalAmount);
        $sum += $yearDays[$year];
        //echo  $year . " " . $days . " " . $yearDays[$year] . "\n";
    }
    if ($sum != $TotalAmount) {
        $yearDays[$year] += $TotalAmount - $sum;
    }
    return $yearDays;
}
Beispiel #2
0
function ComputeInstallments($RequestID = "", $returnMode = false, $pdo2 = null)
{
    $RequestID = empty($RequestID) ? $_REQUEST["RequestID"] : $RequestID;
    PdoDataAccess::runquery("delete from LON_installments where RequestID=? ", array($RequestID));
    //-----------------------------------------------
    $obj2 = new LON_requests($RequestID);
    if ($obj2->ReqPersonID == SHEKOOFAI) {
        return ComputeInstallmentsShekoofa($RequestID, $returnMode);
    }
    //-----------------------------------------------
    $obj = LON_ReqParts::GetValidPartObj($RequestID);
    //-----------------------------------------------
    $YearMonths = 12;
    if ($obj->IntervalType == "DAY") {
        $YearMonths = floor(365 / $obj->PayInterval);
    }
    $TotalWage = round(ComputeWage($obj->PartAmount, $obj->CustomerWage / 100, $obj->InstallmentCount, $PartObj->IntervalType, $obj->PayInterval));
    if ($obj->WageReturn == "CUSTOMER") {
        $TotalWage = 0;
        $obj->CustomerWage = 0;
    }
    $startDate = DateModules::miladi_to_shamsi($obj->PartDate);
    $DelayDuration = DateModules::JDateMinusJDate(DateModules::AddToJDate($startDate, $obj->DelayDays, $obj->DelayMonths), $startDate) + 1;
    if ($obj->DelayDays * 1 > 0) {
        $TotalDelay = round($obj->PartAmount * $obj->DelayPercent * $DelayDuration / 36500);
    } else {
        $TotalDelay = round($obj->PartAmount * $obj->DelayPercent * $obj->DelayMonths / 1200);
    }
    //-------------------------- installments -----------------------------
    $MaxWage = max($obj->CustomerWage, $obj->FundWage);
    $CustomerFactor = $MaxWage == 0 ? 0 : $obj->CustomerWage / $MaxWage;
    $FundFactor = $MaxWage == 0 ? 0 : $obj->FundWage / $MaxWage;
    $AgentFactor = $MaxWage == 0 ? 0 : ($obj->CustomerWage - $obj->FundWage) / $MaxWage;
    $extraAmount = 0;
    if ($obj->WageReturn == "INSTALLMENT") {
        if ($obj->MaxFundWage * 1 > 0) {
            $extraAmount += $obj->MaxFundWage;
        } else {
            if ($obj->CustomerWage > $obj->FundWage) {
                $extraAmount += round($TotalWage * $FundFactor);
            } else {
                $extraAmount += round($TotalWage * $CustomerFactor);
            }
        }
    }
    if ($obj->AgentReturn == "INSTALLMENT" && $obj->CustomerWage > $obj->FundWage) {
        $extraAmount += round($TotalWage * $AgentFactor);
    }
    if ($obj->DelayReturn == "INSTALLMENT") {
        $extraAmount += $TotalDelay * ($obj->FundWage / $obj->DelayPercent);
    }
    if ($obj->AgentDelayReturn == "INSTALLMENT" && $obj->DelayPercent > $obj->FundWage) {
        $extraAmount += $TotalDelay * (($obj->DelayPercent - $obj->FundWage) / $obj->DelayPercent);
    }
    $TotalAmount = $obj->PartAmount * 1 + $extraAmount;
    $allPay = ComputeInstallmentAmount($TotalAmount, $obj->InstallmentCount, $obj->PayInterval);
    if ($obj->InstallmentCount > 1) {
        $allPay = roundUp($allPay, -3);
    } else {
        $allPay = round($allPay);
    }
    if ($obj->DelayReturn == "INSTALLMENT") {
        $allPay += $TotalDelay / $obj->InstallmentCount * 1;
    }
    $LastPay = $TotalAmount - $allPay * ($obj->InstallmentCount - 1);
    //---------------------------------------------------------------------
    $jdate = DateModules::miladi_to_shamsi($obj->PartDate);
    $jdate = DateModules::AddToJDate($jdate, $obj->DelayDays, $obj->DelayMonths);
    if ($pdo2 == null) {
        $pdo = PdoDataAccess::getPdoObject();
        $pdo->beginTransaction();
    } else {
        $pdo = $pdo2;
    }
    for ($i = 0; $i < $obj->InstallmentCount - 1; $i++) {
        $obj2 = new LON_installments();
        $obj2->RequestID = $RequestID;
        $obj2->InstallmentDate = DateModules::AddToJDate($jdate, $obj->IntervalType == "DAY" ? $obj->PayInterval * ($i + 1) : 0, $obj->IntervalType == "MONTH" ? $obj->PayInterval * ($i + 1) : 0);
        $obj2->InstallmentAmount = $allPay;
        if (!$obj2->AddInstallment($pdo)) {
            $pdo->rollBack();
            print_r(ExceptionHandler::PopAllExceptions());
            echo Response::createObjectiveResponse(false, "");
            die;
        }
    }
    $obj2 = new LON_installments();
    $obj2->RequestID = $RequestID;
    $obj2->InstallmentDate = DateModules::AddToJDate($jdate, $obj->IntervalType == "DAY" ? $obj->PayInterval * $obj->InstallmentCount : 0, $obj->IntervalType == "MONTH" ? $obj->PayInterval * $obj->InstallmentCount : 0);
    $obj2->InstallmentAmount = $LastPay;
    if (!$obj2->AddInstallment($pdo)) {
        $pdo->rollBack();
        print_r(ExceptionHandler::PopAllExceptions());
        echo Response::createObjectiveResponse(false, "");
        die;
    }
    if ($returnMode) {
        return true;
    }
    $pdo->commit();
    echo Response::createObjectiveResponse(true, "");
    die;
}