function RetPayPartDoc($ReturnMode = false, $pdo = null) { if (empty($_POST["PayID"])) { echo Response::createObjectiveResponse(false, "درخواست نامعتبر"); die; } $PayID = $_POST["PayID"]; $PayObj = new LON_payments($PayID); //------------- check for Acc doc confirm ------------------- $temp = PdoDataAccess::runquery("select DocStatus \r\n\t\tfrom ACC_DocItems join ACC_docs using(DocID) where SourceType=" . DOCTYPE_LOAN_PAYMENT . " AND \r\n\t\tDocID=?", array($PayObj->DocID)); if (count($temp) == 0) { echo Response::createObjectiveResponse(false, "سند مربوطه یافت نشد"); die; } if (count($temp) > 0 && $temp[0]["DocStatus"] != "RAW") { echo Response::createObjectiveResponse(false, "سند حسابداری این شرایط تایید شده است. و قادر به برگشت نمی باشید"); die; } //------- check for being first doc and there excists docs after ----------- $CostCode_todiee = COSTID_Todiee; $temp = PdoDataAccess::runquery("select * from ACC_DocItems \r\n\t\twhere CostID=? AND CreditorAmount>0 AND DocID=?", array($CostCode_todiee, $PayObj->DocID)); if (count($temp) > 0) { $dt = PdoDataAccess::runquery("select * from ACC_DocItems where CostID=? AND DebtorAmount>0 \r\n\t\t\tAND SourceType=? AND SourceID=?", array($CostCode_todiee, DOCTYPE_LOAN_PAYMENT, $PayObj->RequestID)); if (count($dt) > 0) { echo Response::createObjectiveResponse(false, "به دلیل اینکه این سند اولین سند پرداخت می باشد و بعد از آن اسناد پرداخت دیگری صادر شده است" . " قادر به برگشت نمی باشید. <br> برای برگشت ابتدا کلیه اسناد بعدی را برگشت بزنید"); die; } } //----------------------------------------------------------- if ($pdo == null) { $pdo = PdoDataAccess::getPdoObject(); $pdo->beginTransaction(); } if (!ReturnPayPartDoc($PayObj->DocID, $pdo, !$ReturnMode)) { if ($ReturnMode) { return false; } $pdo->rollBack(); print_r(ExceptionHandler::PopAllExceptions()); echo Response::createObjectiveResponse(false, PdoDataAccess::GetExceptionsToString()); die; } $PayObj->DocID = 0; if (!$PayObj->Edit($pdo)) { if ($ReturnMode) { return false; } $pdo->rollBack(); echo Response::createObjectiveResponse(false, PdoDataAccess::GetExceptionsToString()); die; } ChangeStatus($PayObj->RequestID, "90", "", true, $pdo); if ($ReturnMode) { return true; } $pdo->commit(); echo Response::createObjectiveResponse(true, ""); die; }
function ComputeWageOfSHekoofa($partObj) { $payments = LON_payments::Get(" AND RequestID=? order by PayDate", array($partObj->RequestID)); $payments = $payments->fetchAll(); //--------------- total pay months ------------- $firstPay = DateModules::miladi_to_shamsi($payments[0]["PayDate"]); $LastPay = DateModules::miladi_to_shamsi($payments[count($payments) - 1]["PayDate"]); $paymentPeriod = DateModules::GetDiffInMonth($firstPay, $LastPay); //---------------------------------------------- $totalWage = 0; $wages = array(); foreach ($payments as $row) { $wages[] = array(); $wageindex = count($wages) - 1; for ($i = 0; $i < $partObj->InstallmentCount; $i++) { $monthplus = $paymentPeriod + $partObj->DelayMonths * 1 + ($i + 1) * $partObj->PayInterval * 1; $installmentDate = DateModules::miladi_to_shamsi($payments[0]["PayDate"]); $installmentDate = DateModules::AddToJDate($installmentDate, 0, $monthplus); $installmentDate = DateModules::shamsi_to_miladi($installmentDate); $jdiff = DateModules::GDateMinusGDate($installmentDate, $row["PayDate"]); $wage = round($row["PayAmount"] / $partObj->InstallmentCount * $jdiff * $partObj->CustomerWage / 36500); $wages[$wageindex][] = $wage; $totalWage += $wage; } } return $totalWage; }
function RegisterSHRTFUNDPayPartDoc($ReqObj, $PartObj, $PayObj, $BankTafsili, $AccountTafsili, $pdo, $DocID = "") { /*@var $ReqObj LON_requests */ /*@var $PartObj LON_ReqParts */ /*@var $PayObj LON_payments */ //------------- get CostCodes -------------------- $LoanObj = new LON_loans($ReqObj->LoanID); $CostCode_Loan = FindCostID("110" . "-" . $LoanObj->_BlockCode); $CostCode_varizi = FindCostID("721-" . $LoanObj->_BlockCode . "-52"); $CostCode_pardakhti = FindCostID("721-" . $LoanObj->_BlockCode . "-51"); $CostCode_bank = FindCostID("101"); $CostCode_todiee = FindCostID("200-" . $LoanObj->_BlockCode . "-01"); $CostCode_agent_wage = FindCostID("200-02"); $CostCode_guaranteeAmount_zemanati = FindCostID("904-02"); $CostCode_guaranteeAmount2_zemanati = FindCostID("905-02"); //------------------------------------------------ $CycleID = substr(DateModules::miladi_to_shamsi($PayObj->PayDate), 0, 4); //---------------- add doc header -------------------- if ($DocID == "") { $obj = new ACC_docs(); $obj->RegDate = PDONOW; $obj->regPersonID = $_SESSION['USER']["PersonID"]; $obj->DocDate = PDONOW; $obj->CycleID = $CycleID; $obj->BranchID = $ReqObj->BranchID; $obj->DocType = DOCTYPE_LOAN_PAYMENT; $obj->description = "پرداخت وام شماره " . $ReqObj->RequestID . " به نام " . $ReqObj->_LoanPersonFullname; if (!$obj->Add($pdo)) { ExceptionHandler::PushException("خطا در ایجاد سند"); return false; } } else { $obj = new ACC_docs($DocID); } $PayAmount = $PayObj->PayAmount; //-------------------------------------------------------- $payments = LON_payments::Get(" AND RequestID=? order by PayDate", array($PartObj->RequestID)); $payments = $payments->fetchAll(); //------------------ nfind tafsilis --------------- $LoanPersonTafsili = FindTafsiliID($ReqObj->LoanPersonID, TAFTYPE_PERSONS); if (!$LoanPersonTafsili) { ExceptionHandler::PushException("تفصیلی مربوطه یافت نشد.[" . $ReqObj->LoanPersonID . "]"); return false; } $LoanMode = ""; if (!empty($ReqObj->ReqPersonID)) { $PersonObj = new BSC_persons($ReqObj->ReqPersonID); if ($PersonObj->IsAgent == "YES") { $LoanMode = "Agent"; } } else { $LoanMode = "Customer"; } if ($LoanMode == "Agent") { $ReqPersonTafsili = FindTafsiliID($ReqObj->ReqPersonID, TAFTYPE_PERSONS); if (!$ReqPersonTafsili) { ExceptionHandler::PushException("تفصیلی مربوطه یافت نشد.[" . $ReqObj->ReqPersonID . "]"); return false; } $SubAgentTafsili = ""; if (!empty($ReqObj->SubAgentID)) { $SubAgentTafsili = FindTafsiliID($ReqObj->SubAgentID, TAFTYPE_SUBAGENT); if (!$SubAgentTafsili) { ExceptionHandler::PushException("تفصیلی زیر واحد سرمایه گذار یافت نشد.[" . $ReqObj->SubAgentID . "]"); return false; } } } //------------ find the number step to pay --------------- $FirstStep = true; $dt = PdoDataAccess::runquery("select * from ACC_DocItems where SourceID=?", array($ReqObj->RequestID)); if (count($dt) > 0) { $FirstStep = false; $query = "select ifnull(sum(CreditorAmount-DebtorAmount),0)\r\n\t\t\tfrom ACC_DocItems where CostID=? AND TafsiliID=? AND sourceID=?"; $param = array($CostCode_todiee, $LoanPersonTafsili, $ReqObj->RequestID); if ($LoanMode == "Agent") { $query .= " AND TafsiliID2=?"; $param[] = $ReqPersonTafsili; } $dt = PdoDataAccess::runquery($query, $param); if ($dt[0][0] * 1 < $PayAmount) { print_r(ExceptionHandler::PopAllExceptions()); ExceptionHandler::PushException("حساب تودیعی این مشتری" . number_format($dt[0][0]) . " ریال می باشد که کمتر از مبلغ این مرحله از پرداخت وام می باشد"); return false; } } //----------------- add Doc items ------------------------ $itemObj = new ACC_DocItems(); $itemObj->DocID = $obj->DocID; $itemObj->TafsiliType = TAFTYPE_PERSONS; $itemObj->TafsiliID = $LoanPersonTafsili; if ($LoanMode == "Agent") { $itemObj->TafsiliType2 = TAFTYPE_PERSONS; $itemObj->TafsiliID2 = $ReqPersonTafsili; } $itemObj->locked = "YES"; $itemObj->SourceType = DOCTYPE_LOAN_PAYMENT; $itemObj->SourceID = $ReqObj->RequestID; $itemObj->SourceID2 = $PartObj->PartID; $itemObj->SourceID3 = $PayObj->PayID; if ($FirstStep) { unset($itemObj->ItemID); $itemObj->DocID = $obj->DocID; $itemObj->CostID = $CostCode_Loan; $itemObj->DebtorAmount = $PartObj->PartAmount; $itemObj->CreditorAmount = 0; $itemObj->Add($pdo); $LoanRow = clone $itemObj; if ($PartObj->PartAmount != $PayAmount) { unset($itemObj->ItemID); $itemObj->DocID = $obj->DocID; $itemObj->CostID = $CostCode_todiee; $itemObj->DebtorAmount = 0; $itemObj->CreditorAmount = $PartObj->PartAmount * 1 - $PayAmount; $itemObj->Add($pdo); } } else { unset($itemObj->ItemID); $itemObj->DocID = $obj->DocID; $itemObj->CostID = $CostCode_todiee; $itemObj->DebtorAmount = $PayAmount; $itemObj->CreditorAmount = 0; $itemObj->Add($pdo); } //--------------------------------------------------------- $itemObj = new ACC_DocItems(); $itemObj->DocID = $obj->DocID; $itemObj->CostID = $CostCode_varizi; $itemObj->DebtorAmount = $PayAmount; $itemObj->CreditorAmount = 0; $itemObj->TafsiliType = TAFTYPE_PERSONS; $itemObj->TafsiliID = $ReqPersonTafsili; $itemObj->locked = "YES"; $itemObj->SourceType = DOCTYPE_LOAN_PAYMENT; $itemObj->SourceID = $ReqObj->RequestID; $itemObj->SourceID2 = $PartObj->PartID; $itemObj->SourceID3 = $PayObj->PayID; $itemObj->Add($pdo); $itemObj = new ACC_DocItems(); $itemObj->DocID = $obj->DocID; $itemObj->CostID = $CostCode_pardakhti; $itemObj->DebtorAmount = 0; $itemObj->CreditorAmount = $PayAmount; $itemObj->TafsiliType = TAFTYPE_PERSONS; $itemObj->TafsiliID = $ReqPersonTafsili; $itemObj->locked = "YES"; $itemObj->SourceType = DOCTYPE_LOAN_PAYMENT; $itemObj->SourceID = $ReqObj->RequestID; $itemObj->SourceID2 = $PartObj->PartID; $itemObj->SourceID3 = $PayObj->PayID; $itemObj->Add($pdo); // ----------------------------- bank -------------------------------- $AgentWage = 0; if ($PartObj->CustomerWage * 1 > $PartObj->FundWage * 1 && $PartObj->AgentReturn == "CUSTOMER") { //$totalWage = ComputeWageOfSHekoofa($PartObj); $totalWage = $PayAmount * $PartObj->CustomerWage / 100; $AgentFactor = ($PartObj->CustomerWage * 1 - $PartObj->FundWage * 1) / $PartObj->CustomerWage * 1; $AgentWage = $totalWage * $AgentFactor; unset($itemObj->ItemID); $itemObj->CostID = $CostCode_agent_wage; $itemObj->DebtorAmount = 0; $itemObj->CreditorAmount = $AgentWage; $itemObj->TafsiliType = TAFTYPE_PERSONS; $itemObj->TafsiliID = $ReqPersonTafsili; unset($itemObj->TafsiliType2); unset($itemObj->TafsiliID2); $itemObj->Add($pdo); } $itemObj = new ACC_DocItems(); $itemObj->DocID = $obj->DocID; $itemObj->CostID = $CostCode_bank; $itemObj->DebtorAmount = 0; $itemObj->CreditorAmount = $PayAmount - $AgentWage; $itemObj->TafsiliType = TAFTYPE_BANKS; $itemObj->TafsiliID = $BankTafsili; $itemObj->TafsiliType2 = TAFTYPE_ACCOUNTS; $itemObj->TafsiliID2 = $AccountTafsili; $itemObj->locked = "YES"; $itemObj->SourceType = DOCTYPE_LOAN_PAYMENT; $itemObj->SourceID = $ReqObj->RequestID; $itemObj->SourceID2 = $PartObj->PartID; $itemObj->SourceID3 = $PayObj->PayID; $itemObj->Add($pdo); $BankRow = clone $itemObj; //---------- ردیف های تضمین ---------- $dt = PdoDataAccess::runquery("select * from DMS_documents \r\n\t\tjoin BaseInfo b on(InfoID=DocType AND TypeID=8)\r\n\t\tjoin ACC_DocItems on(SourceType=" . DOCTYPE_DOCUMENT . " AND SourceID=DocumentID)\r\n\t\twhere b.param1=1 AND ObjectType='loan' AND ObjectID=?", array($ReqObj->RequestID)); $SumAmount = 0; $countAmount = 0; if (count($dt) == 0) { $dt = PdoDataAccess::runquery("\r\n\t\t\tSELECT DocumentID, ParamValue, InfoDesc as DocTypeDesc\r\n\t\t\t\tFROM DMS_DocParamValues\r\n\t\t\t\tjoin DMS_DocParams using(ParamID)\r\n\t\t\t\tjoin DMS_documents d using(DocumentID)\r\n\t\t\t\tjoin BaseInfo b on(InfoID=d.DocType AND TypeID=8)\r\n\t\t\twhere b.param1=1 AND paramType='currencyfield' AND ObjectType='loan' AND ObjectID=?", array($ReqObj->RequestID), $pdo); foreach ($dt as $row) { unset($itemObj->ItemID); unset($itemObj->TafsiliType2); unset($itemObj->TafsiliID2); $itemObj->CostID = $CostCode_guaranteeAmount_zemanati; $itemObj->DebtorAmount = $row["ParamValue"]; $itemObj->CreditorAmount = 0; $itemObj->TafsiliType = TAFTYPE_PERSONS; $itemObj->TafsiliID = $LoanPersonTafsili; $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->TafsiliType2); unset($itemObj->TafsiliID2); unset($itemObj->details); $itemObj->CostID = $CostCode_guaranteeAmount2_zemanati; $itemObj->DebtorAmount = 0; $itemObj->CreditorAmount = $SumAmount; $itemObj->Add($pdo); /*unset($itemObj->ItemID); $itemObj->CostID = $CostCode_guaranteeCount; $itemObj->DebtorAmount = $countAmount; $itemObj->CreditorAmount = 0; $itemObj->Add($pdo); unset($itemObj->ItemID); $itemObj->CostID = $CostCode_guaranteeCount2; $itemObj->DebtorAmount = 0; $itemObj->CreditorAmount = $countAmount; $itemObj->Add($pdo);*/ } } //--------------- cheques of installments --------------------- /*if($FirstStep) { $dt = PdoDataAccess::runquery(" SELECT PayAmount,BackPayID FROM LON_BackPays where RequestID=? AND PayType=9",array($PartObj->RequestID), $pdo); $SumAmount = 0; foreach($dt as $row) { unset($itemObj->ItemID); unset($itemObj->TafsiliType2); unset($itemObj->TafsiliID2); $itemObj->CostID = $CostCode_guaranteeAmount_daryafti; $itemObj->DebtorAmount = $row["PayAmount"]; $itemObj->CreditorAmount = 0; $itemObj->TafsiliType = TAFTYPE_PERSONS; $itemObj->TafsiliID = $LoanPersonTafsili; $itemObj->SourceType = DOCTYPE_DOCUMENT; $itemObj->SourceID = $row["BackPayID"]; $itemObj->Add($pdo); $SumAmount += $row["ParamValue"]*1; $countAmount++; } if($SumAmount > 0) { unset($itemObj->ItemID); unset($itemObj->TafsiliType); unset($itemObj->TafsiliID); unset($itemObj->TafsiliType2); unset($itemObj->TafsiliID2); unset($itemObj->details); $itemObj->CostID = $CostCode_guaranteeAmount2_daryafti; $itemObj->DebtorAmount = 0; $itemObj->CreditorAmount = $SumAmount; $itemObj->Add($pdo); } }*/ //--------------------------------------------------------- //------ ایجاد چک ------ $chequeObj = new ACC_DocCheques(); $chequeObj->DocID = $obj->DocID; $chequeObj->CheckDate = $PayObj->PayDate; $chequeObj->amount = $PartObj->PartAmount; $chequeObj->TafsiliID = $LoanPersonTafsili; $chequeObj->description = " پرداخت وام شماره " . $ReqObj->RequestID; $chequeObj->Add($pdo); //--------------------------------------------------------- $dt = PdoDataAccess::runquery("select sum(DebtorAmount) dsum, sum(CreditorAmount) csum\r\n\t\tfrom ACC_DocItems where DocID=?", array($obj->DocID), $pdo); if ($dt[0]["dsum"] > $dt[0]["csum"]) { $BankRow->CreditorAmount += $dt[0]["dsum"] - $dt[0]["csum"]; $BankRow->Edit($pdo); } else { if ($dt[0]["csum"] > $dt[0]["dsum"]) { $LoanRow->DebtorAmount += $dt[0]["csum"] - $dt[0]["dsum"]; $LoanRow->Edit($pdo); } } //--------------------------------------------------------- if (ExceptionHandler::GetExceptionCount() > 0) { return false; } return $obj->DocID; }