Пример #1
0
function RegisterCustomerPayDoc($DocObj, $PayObj, $CostID, $TafsiliID, $TafsiliID2, $CenterAccount, $BranchID, $FirstCostID, $SecondCostID, $pdo, $grouping = false)
{
    /*@var $PayObj LON_BackPays */
    $ReqObj = new LON_requests($PayObj->RequestID);
    $PartObj = LON_ReqParts::GetValidPartObj($PayObj->RequestID);
    if ($DocObj == null) {
        $dt = PdoDataAccess::runquery("select * from ACC_DocItems where SourceType=" . DOCTYPE_INSTALLMENT_PAYMENT . " AND SourceID=? AND SourceID2=?", array($ReqObj->RequestID, $PayObj->BackPayID));
        if (count($dt) > 0) {
            ExceptionHandler::PushException("سند این ردیف پرداخت قبلا صادر شده است");
            return false;
        }
    }
    $CycleID = substr(DateModules::shNow(), 0, 4);
    //------------- get CostCodes --------------------
    $LoanObj = new LON_loans($ReqObj->LoanID);
    $CostCode_Loan = FindCostID("110" . "-" . $LoanObj->_BlockCode);
    $CostCode_deposite = FindCostID("210-01");
    $CostCode_wage = FindCostID("750" . "-" . $LoanObj->_BlockCode);
    $CostCode_commitment = FindCostID("200-" . $LoanObj->_BlockCode . "-51");
    //---------------- add doc header --------------------
    if ($DocObj == null) {
        $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_INSTALLMENT_PAYMENT;
        if ($grouping) {
            $obj->description = "پرداخت گروهی اقساط";
        } else {
            $obj->description = "پرداخت قسط وام شماره " . $ReqObj->RequestID . " به نام " . $ReqObj->_LoanPersonFullname;
        }
        if (!$obj->Add($pdo)) {
            ExceptionHandler::PushException("خطا در ایجاد سند");
            return false;
        }
    } else {
        $obj = $DocObj;
    }
    //------------------ find 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;
            }
        }
    }
    //--------------------------------------------------------
    $firstPayDate = $PartObj->PartDate;
    $result = ComputeWagesAndDelays($PartObj, $PartObj->PartAmount, $firstPayDate, $PartObj->PartDate);
    $TotalFundWage = $result["TotalFundWage"];
    $TotalFundDelay = $result["TotalFundDelay"];
    $TotalAgentDelay = $result["TotalAgentDelay"];
    $PayObj->PayAmount = $PayObj->PayAmount * 1;
    $curWage = round($PayObj->PayAmount * $TotalFundWage / $PartObj->PartAmount);
    //----------------- get total remain ---------------------
    require_once getenv("DOCUMENT_ROOT") . '/loan/request/request.class.php';
    $dt = array();
    $returnArr = LON_requests::ComputePayments($PayObj->RequestID, $dt, $pdo);
    $ExtraPay = 0;
    if ($returnArr[count($returnArr) - 1]["TotalRemainder"] * 1 < 0) {
        $PayObj->PayAmount = $PayObj->PayAmount + $returnArr[count($returnArr) - 1]["TotalRemainder"] * 1;
        $PayObj->Edit();
        $ExtraPay = $returnArr[count($returnArr) - 1]["TotalRemainder"] * -1;
        $PayObj->PayAmount = $PayObj->PayAmount;
    }
    //----------------- add Doc items ------------------------
    $itemObj = new ACC_DocItems();
    $itemObj->DocID = $obj->DocID;
    $itemObj->details = "پرداخت قسط وام شماره " . $ReqObj->RequestID;
    $itemObj->TafsiliType = TAFTYPE_PERSONS;
    $itemObj->TafsiliID = $LoanPersonTafsili;
    if ($LoanMode == "Agent") {
        $itemObj->TafsiliType2 = TAFTYPE_PERSONS;
        $itemObj->TafsiliID2 = $ReqPersonTafsili;
    }
    $itemObj->locked = "YES";
    $itemObj->SourceType = DOCTYPE_INSTALLMENT_PAYMENT;
    $itemObj->SourceID = $ReqObj->RequestID;
    $itemObj->SourceID2 = $PayObj->BackPayID;
    //---------------- loan -----------------
    $itemObj->DocID = $obj->DocID;
    $itemObj->CostID = $CostCode_Loan;
    $itemObj->DebtorAmount = 0;
    $itemObj->CreditorAmount = $PayObj->PayAmount;
    if (!$itemObj->Add($pdo)) {
        ExceptionHandler::PushException("خطا در ایجاد ردیف وام");
        return false;
    }
    // -------------- bank ---------------
    if ($CenterAccount) {
        unset($itemObj->ItemID);
        unset($itemObj->TafsiliType);
        unset($itemObj->TafsiliType2);
        unset($itemObj->TafsiliID2);
        unset($itemObj->TafsiliID);
        $itemObj->locked = "NO";
        $itemObj->CostID = $FirstCostID;
        $itemObj->DebtorAmount = $PayObj->PayAmount + $ExtraPay;
        $itemObj->CreditorAmount = 0;
        if (!$itemObj->Add($pdo)) {
            ExceptionHandler::PushException("خطا در ایجاد ردیف محل پرداخت");
            return false;
        }
        $Secobj = new ACC_docs();
        $Secobj->RegDate = PDONOW;
        $Secobj->regPersonID = $_SESSION['USER']["PersonID"];
        $Secobj->DocDate = PDONOW;
        $Secobj->CycleID = $CycleID;
        $Secobj->BranchID = $BranchID;
        $Secobj->DocType = DOCTYPE_INSTALLMENT_PAYMENT;
        $Secobj->description = "پرداخت قسط وام شماره " . $ReqObj->RequestID . " به نام " . $ReqObj->_LoanPersonFullname;
        if (!$Secobj->Add($pdo)) {
            ExceptionHandler::PushException("خطا در ایجاد سند شعبه واسط ");
            return false;
        }
        unset($itemObj->ItemID);
        unset($itemObj->TafsiliType);
        unset($itemObj->TafsiliType2);
        unset($itemObj->TafsiliID2);
        unset($itemObj->TafsiliID);
        $itemObj->DocID = $Secobj->DocID;
        $itemObj->CostID = $SecondCostID;
        $itemObj->DebtorAmount = 0;
        $itemObj->CreditorAmount = $PayObj->PayAmount + $ExtraPay;
        if (!$itemObj->Add($pdo)) {
            ExceptionHandler::PushException("خطا در ایجاد ردیف سند شعبه واسط");
            return false;
        }
        $CostObj = new ACC_CostCodes($CostID);
        unset($itemObj->ItemID);
        unset($itemObj->TafsiliType);
        unset($itemObj->TafsiliType2);
        unset($itemObj->TafsiliID2);
        unset($itemObj->TafsiliID);
        $itemObj->CostID = $CostID;
        $itemObj->DebtorAmount = $PayObj->PayAmount + $ExtraPay;
        $itemObj->CreditorAmount = 0;
        $itemObj->TafsiliType = $CostObj->TafsiliType;
        if ($TafsiliID != "") {
            $itemObj->TafsiliID = $TafsiliID;
        }
        $itemObj->TafsiliType2 = $CostObj->TafsiliType2;
        if ($TafsiliID2 != "") {
            $itemObj->TafsiliID2 = $TafsiliID2;
        }
        if (!$itemObj->Add($pdo)) {
            ExceptionHandler::PushException("خطا در ایجاد ردیف سند شعبه واسط");
            return false;
        }
    } else {
        $CostObj = new ACC_CostCodes($CostID);
        unset($itemObj->ItemID);
        unset($itemObj->TafsiliType);
        unset($itemObj->TafsiliType2);
        unset($itemObj->TafsiliID2);
        unset($itemObj->TafsiliID);
        $itemObj->locked = "NO";
        $itemObj->CostID = $CostID;
        $itemObj->DebtorAmount = $PayObj->PayAmount + $ExtraPay;
        $itemObj->CreditorAmount = 0;
        $itemObj->TafsiliType = $CostObj->TafsiliType;
        if ($TafsiliID != "") {
            $itemObj->TafsiliID = $TafsiliID;
        }
        $itemObj->TafsiliType2 = $CostObj->TafsiliType2;
        if ($TafsiliID2 != "") {
            $itemObj->TafsiliID2 = $TafsiliID2;
        }
        if (!$itemObj->Add($pdo)) {
            ExceptionHandler::PushException("خطا در ایجاد ردیف بانک");
            return false;
        }
    }
    $itemObj->locked = "YES";
    $itemObj->DocID = $obj->DocID;
    unset($itemObj->TafsiliType2);
    unset($itemObj->TafsiliID2);
    //-------------- extra to Pasandaz ----------------
    if ($ExtraPay > 0) {
        unset($itemObj->ItemID);
        $itemObj->DocID = $obj->DocID;
        $itemObj->CostID = COSTID_saving;
        $itemObj->DebtorAmount = 0;
        $itemObj->CreditorAmount = $ExtraPay;
        $itemObj->TafsiliType = TAFTYPE_PERSONS;
        $itemObj->TafsiliID = $LoanPersonTafsili;
        if (!$itemObj->Add($pdo)) {
            ExceptionHandler::PushException("خطا در ایجاد ردیف وام");
            return false;
        }
    }
    //----------------------------------------
    if ($PartObj->DelayReturn == "INSTALLMENT") {
        $dt = PdoDataAccess::runquery("select ifnull(sum(CreditorAmount),0) from ACC_DocItems \r\n\t\t\twhere CostID=? AND SourceID=? AND SourceID3=?", array($CostCode_wage, $ReqObj->RequestID, "1"));
        $TotalFundDelay = $TotalFundDelay * 1 - $dt[0][0] * 1;
        unset($itemObj->ItemID);
        unset($itemObj->TafsiliType);
        unset($itemObj->TafsiliID);
        unset($itemObj->TafsiliType2);
        unset($itemObj->TafsiliID2);
        $itemObj->CostID = $CostCode_wage;
        $itemObj->details = "بابت تنفس وام " . $PayObj->RequestID;
        $itemObj->DebtorAmount = 0;
        $itemObj->SourceID3 = "1";
        $itemObj->CreditorAmount = min($TotalFundDelay, $PayObj->PayAmount);
        if (!$itemObj->Add($pdo)) {
            ExceptionHandler::PushException("خطا در ایجاد سند");
            return false;
        }
        $PayObj->PayAmount = $PayObj->PayAmount - min($TotalFundDelay, $PayObj->PayAmount);
        unset($itemObj->SourceID3);
    }
    if ($PayObj->PayAmount > 0 && $LoanMode == "Agent" && $PartObj->AgentDelayReturn == "INSTALLMENT") {
        $dt = PdoDataAccess::runquery("select ifnull(sum(CreditorAmount),0) from ACC_DocItems \r\n\t\t\twhere CostID=? AND SourceID=? AND SourceID2=? AND SourceID3=?", array($CostCode_deposite, $ReqObj->RequestID, $PayObj->BackPayID, "1"));
        $TotalAgentDelay = $TotalAgentDelay * 1 - $dt[0][0] * 1;
        unset($itemObj->ItemID);
        unset($itemObj->TafsiliType);
        unset($itemObj->TafsiliID);
        unset($itemObj->TafsiliType2);
        unset($itemObj->TafsiliID2);
        $itemObj->CostID = $CostCode_deposite;
        $itemObj->DebtorAmount = 0;
        $itemObj->details = "بابت تنفس وام " . $PayObj->RequestID;
        $itemObj->SourceID3 = "1";
        $itemObj->CreditorAmount = min($TotalAgentDelay, $PayObj->PayAmount);
        if (!$itemObj->Add($pdo)) {
            ExceptionHandler::PushException("خطا در ایجاد سند");
            return false;
        }
        $PayObj->PayAmount = $PayObj->PayAmount - min($TotalAgentDelay, $PayObj->PayAmount);
        unset($itemObj->SourceID3);
    }
    //------------- wage --------------
    if ($LoanMode == "Agent") {
        if ($PayObj->PayAmount * 1 > 0) {
            $amount = $PayObj->PayAmount;
            if ($PartObj->WageReturn == "INSTALLMENT") {
                $amount = $PayObj->PayAmount - $curWage;
                $amount = $amount < 0 ? 0 : $amount;
            }
            //---- اضافه به سپرده -----
            unset($itemObj->ItemID);
            unset($itemObj->TafsiliType2);
            unset($itemObj->TafsiliID2);
            $itemObj->details = "پرداخت قسط وام شماره " . $ReqObj->RequestID;
            $itemObj->CostID = $CostCode_deposite;
            $itemObj->DebtorAmount = 0;
            $itemObj->CreditorAmount = $amount;
            $itemObj->TafsiliType = TAFTYPE_PERSONS;
            $itemObj->TafsiliID = $ReqPersonTafsili;
            if ($SubAgentTafsili != "") {
                $itemObj->TafsiliType2 = TAFTYPE_SUBAGENT;
                $itemObj->TafsiliID2 = $SubAgentTafsili;
            }
            if (!$itemObj->Add($pdo)) {
                ExceptionHandler::PushException("خطا در ایجاد ردیف سپرده");
                return false;
            }
            unset($itemObj->ItemID);
            $itemObj->CostID = $CostCode_commitment;
            $itemObj->DebtorAmount = $amount;
            $itemObj->CreditorAmount = 0;
            if (!$itemObj->Add($pdo)) {
                ExceptionHandler::PushException("خطا در ایجاد ردیف تعهد");
                return false;
            }
        }
    }
    //---------------------------------------------------------
    if (ExceptionHandler::GetExceptionCount() > 0) {
        return false;
    }
    return true;
}
Пример #2
0
function GetEndedRequests()
{
    $query = "select rp.RequestID,ReqDate,RequestID,concat_ws(' ',fname,lname,CompanyName) LoanPersonName\r\n\t\t\tfrom LON_ReqParts rp\r\n\t\t\tjoin LON_requests using(RequestID)\r\n\t\t\tjoin BSC_persons on(LoanPersonID=PersonID)\r\n\t\t\t\t\t\t\r\n\t\t\twhere IsEnded='NO' \r\n\t\t\tgroup by rp.RequestID\r\n\t\t\torder by rp.RequestID";
    $dt = PdoDataAccess::runquery_fetchMode($query);
    $result = array();
    while ($row = $dt->fetch()) {
        $temp = array();
        $returnArr = LON_requests::ComputePayments($row["RequestID"], $temp);
        $row["TotalRemainder"] = count($returnArr) > 0 ? $returnArr[count($returnArr) - 1]["TotalRemainder"] : 0;
        if (count($returnArr) == 0) {
            continue;
        }
        if ($returnArr[count($returnArr) - 1]["TotalRemainder"] * 1 == 0) {
            if (count($result) > 0 && $result[count($result) - 1]["RequestID"] == $row["RequestID"]) {
                continue;
            }
            $result[] = $row;
        } else {
            if (count($result) > 0 && $result[count($result) - 1]["RequestID"] == $row["RequestID"]) {
                array_pop($result);
                while ($row["RequestID"] == $result[count($result) - 1]["RequestID"]) {
                    $row = $dt->fetch();
                }
            }
        }
    }
    $cnt = count($result);
    $result = array_slice($result, $_REQUEST["start"], $_REQUEST["limit"]);
    echo dataReader::getJsonData($result, $cnt, $_GET["callback"]);
    die;
}
Пример #3
0
//-----------------------------
//	Programmer	: SH.Jafarkhani
//	Date		: 94.12
//-----------------------------

require_once '../header.inc.php';
require_once "ReportGenerator.class.php";
require_once '../request/request.class.php';
require_once '../request/request.data.php';

if(isset($_REQUEST["show"]))
{
	$RequestID = $_REQUEST["RequestID"];
	
	$dt = array();
	$returnArr = LON_requests::ComputePayments($RequestID, $dt);
	
	//............ get remain untill now ......................
	$PartObj = LON_ReqParts::GetValidPartObj($RequestID);
	$CurrentRemain = 0;
	foreach($dt as $row)
	{
		if($row["InstallmentDate"] <= DateModules::Now())
			$CurrentRemain = $row["TotalRemainder"];
	}
	//.........................................................
	
	$rpg = new ReportGenerator();
	$rpg->excel = !empty($_POST["excel"]);
	function dateRender($row, $val){
		return DateModules::miladi_to_shamsi($val);