Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function updateMasterStatus($borrowerid, $idloan, $status)
- {
- $data['getFundingLoanByLoanId'] = $this->Loan_model->getFundingLoanByLoanId($idloan);
- $data['getMasterLoan'] = $this->Loan_model->getDetailLoan($idloan, $borrowerid);
- $realization = $data['getFundingLoanByLoanId']->total;
- $interest_borrower = $data['getMasterLoan']->interest_borrower;
- $termLoan = getTermLoan($idloan);
- $dataUpdate = array(
- 'status' => $status,
- 'modified_date' => date("Y-m-d H:i:s"),
- 'modified_by' => $_SESSION['email'],
- 'realization_amount' => $data['getFundingLoanByLoanId']->total,
- 'installment' => ($realization / $termLoan) + ($realization * $interest_borrower),
- 'base_installment' => $realization / $termLoan
- );
- $dataUpdateBorrowerDetail = array(
- 'collateral_status' => 'yes'
- );
- $data['update'] = $this->Loan_model->updateStatusLoan($idloan, $dataUpdate);
- $data['update_borrower'] = $this->User_model->updateAccountStatusBorrower($dataUpdateBorrowerDetail, $borrowerid);
- $messages = array();
- $badges = array();
- //jika aktif, insert table payment schedule
- $installment = getInstallment($idloan);
- $paymentDate = date("Y-m-d H:i:s");
- // Create timestamp for transaction references + unique random generated number
- $t = microtime(true);
- $micro = sprintf("%06d",($t - floor($t)) * 1000000);
- $d = new DateTime( date('Y-m-d H:i:s.'.$micro,$t) );
- $date_ref = $d->format("YmdHisu");
- $transaction_ref = substr($date_ref, 0, -3).mt_rand(100, 999);
- if ($status == 'disbursed') {
- $amountDisbursed = $data['getFundingLoanByLoanId']->total - getConfiguration('ADMIN_FEE') - (getConfiguration('PROVISI_FEE') * $data['getFundingLoanByLoanId']->total);
- // Preparing insert data
- $data_insert_borrower = array(
- 'loan_id' => $idloan,
- 'borrower_id' => $borrowerid,
- 'ref' => 'disburse',
- 'tag' => '',
- 'credit' => abs($amountDisbursed),
- 'debit' => 0,
- 'status' => 'pending',
- 'payment_schedule_id' => '',
- 'create_date' => date("Y-m-d h:i:s")
- );
- $data_insert_company = array(
- 'loan_id' => $idloan,
- 'ref' => 'disburse',
- 'tag' => '',
- 'credit' => abs($amountDisbursed),
- 'debit' => 0,
- 'status' => 'pending',
- 'create_date' => date("Y-m-d h:i:s")
- );
- $success = 0;
- // Try this :
- // Cek bank yang dituju apakah BNI atau yang lain
- $borrower_doc = $this->User_model->getDocByBorrowerId($borrowerid);
- // Jika kode bank adalah BNI maka gunakan API inhouse
- if($borrower_doc[0]->bank_code == '009'){
- // First of all, cross check account
- $inhouseInquiryParams = array(
- 'client_id' => getConfiguration('BNI_CLIENT_ID'),
- 'accountNo' => $borrower_doc[0]->bank_account_number
- );
- $inquiry_result = $this->_getInhouseInquiry($inhouseInquiryParams);
- if($inquiry_result->responseCode == '001'){
- // Do Payment from escrow to borrower bank
- // yyyyMMddHHmmssSSSXXX
- $paymentParams = array(
- 'client_id' => getConfiguration('BNI_CLIENT_ID'),
- 'customer_ref_no' => $transaction_ref,
- 'debit_account_no' => $borrower_doc[0]->bank_account_number,
- 'credit_account_no' => getConfiguration('ESCROW_ACCOUNT'),
- 'amount' => abs($amountDisbursed),
- 'valued_date' => $date_ref
- );
- $this->db->trans_start();
- $trans_company = $this->Loan_model->saveTransactionCompany($data_insert_company);
- $trans_borrower = $this->Loan_model->saveTransactionBorrower($data_insert_borrower);
- $this->db->trans_complete();
- if ($this->db->trans_status() === FALSE){
- $this->db->trans_rollback();
- array_push($messages, 'Gagal memproses transaksi.');
- array_push($badges, 1);
- $this->session->set_flashdata('message', $messages);
- $this->session->set_flashdata('notif_status', $badges);
- redirect(base_url() . "loan_manager/disburseLoan/" . $borrowerid . "/" . $idloan, "refresh");
- exit(1);
- }
- else {
- $this->db->trans_commit();
- }
- $payment_result = $this->_doPayment($paymentParams);
- if($payment_result->responseCode == '001'){
- // Insert this payment reference to transaction table
- $customer_ref = $payment_result->customerReference;
- $success = 1;
- } else {
- // Payment unsuccessfull
- $error_message = $payment_result->errorMessage;
- array_push($messages, 'Error. '.$error_message);
- array_push($badges, 0);
- $this->session->set_flashdata('message', $messages);
- $this->session->set_flashdata('notif_status', $badges);
- redirect(base_url() . "loan_manager/disburseLoan/" . $borrowerid . "/" . $idloan, "refresh");
- }
- } else {
- // Account / Rekening is not valid
- $error_message = $inquiry_result->errorMessage;
- array_push($messages, 'Error. '.$error_message);
- array_push($badges, 0);
- $this->session->set_flashdata('message', $messages);
- $this->session->set_flashdata('notif_status', $badges);
- redirect(base_url() . "loan_manager/disburseLoan/" . $borrowerid . "/" . $idloan, "refresh");
- }
- } else {
- // Check others rekening first. is according to defined in system?
- $interbankInquiryParams = array(
- 'customer_ref_no' => $transaction_ref,
- 'account_num' => getConfiguration('ESCROW_ACCOUNT'),
- 'dest_bank_code' => $borrower_doc[0]->bank_code,
- 'dest_account_num' => $borrower_doc[0]->bank_account_number
- );
- $inquiry_result = $this->_getInterbankInquiry($interbankInquiryParams);
- if($inquiry_result->responseCode == '001'){
- $interbankPaymentParams = array(
- 'customerReferenceNumber' => $transaction_ref,
- 'amount' => abs($amountDisbursed),
- 'valuedDate' => $date_ref,
- 'destinationAccountNum' => $inquiry_result->destinationAccountNum,
- 'destinationAccountName' => $inquiry_result->destinationAccountName,
- 'destinationBankCode' => $borrower_doc[0]->bank_code,
- 'destinationBankName' => $inquiry_result->destinationBankName,
- 'accountNum' => getConfiguration('ESCROW_ACCOUNT'),
- 'retrievalReffNum' => $inquiry_result->retrievalReffNum
- );
- $this->db->trans_start();
- $trans_company = $this->Loan_model->saveTransactionCompany($data_insert_company);
- $trans_borrower = $this->Loan_model->saveTransactionBorrower($data_insert_borrower);
- $this->db->trans_complete();
- if ($this->db->trans_status() === FALSE){
- $this->db->trans_rollback();
- array_push($messages, 'Gagal memproses transaksi.');
- array_push($badges, 1);
- $this->session->set_flashdata('message', $messages);
- $this->session->set_flashdata('notif_status', $badges);
- redirect(base_url() . "loan_manager/disburseLoan/" . $borrowerid . "/" . $idloan, "refresh");
- exit(1);
- }
- else {
- $this->db->trans_commit();
- }
- $payment_result = $this->_getInterbankPayment($interbankPaymentParams);
- if($payment_result->responseCode == '001'){
- // Insert this payment reference to transaction table and credit to borrower
- $customer_ref = $payment_result->customerReffNum;
- $success = 1;
- } else {
- // Payment unsuccessfull
- $error_message = $payment_result->errorMessage;
- array_push($messages, 'Error. '.$error_message);
- array_push($badges, 0);
- $this->session->set_flashdata('message', $messages);
- $this->session->set_flashdata('notif_status', $badges);
- redirect(base_url() . "loan_manager/disburseLoan/" . $borrowerid . "/" . $idloan, "refresh");
- }
- } else {
- // Account / Rekening is not valid
- $error_message = $inquiry_result->errorMessage;
- array_push($messages, 'Error. '.$error_message);
- array_push($badges, 0);
- $this->session->set_flashdata('message', $messages);
- $this->session->set_flashdata('notif_status', $badges);
- redirect(base_url() . "loan_manager/disburseLoan/" . $borrowerid . "/" . $idloan, "refresh");
- }
- }
- if($success == 1){
- // Get the insert id
- $trans_borrower_id = $trans_borrower[1];
- $trans_company_id = $trans_company[1];
- // Update to borrower and company transactions
- $data_company = array(
- 'ref' => 'disburse',
- 'credit' => abs($amountDisbursed),
- 'debit' => 0,
- 'status' => 'success',
- 'bni_customer_ref' => $customer_ref
- );
- $data_borrower = array(
- 'ref' => 'disburse',
- 'credit' => abs($amountDisbursed),
- 'debit' => 0,
- 'status' => 'success',
- 'bni_customer_ref' => $customer_ref
- );
- $this->Loan_model->updateTransaction($trans_borrower_id, $data_borrower, 'borrower');
- $this->Loan_model->updateTransaction($trans_company_id, $data_company, 'company');
- // Write Log
- $dataLog = array(
- 'loan_id' => $idloan,
- 'borrower_id' => $borrowerid,
- 'investor_id' => '',
- 'message' => 'Berhasil. Pencairan dana sebesar Rp.'.abs($amountDisbursed),
- 'created_date' => date("Y-m-d h:i:s")
- );
- $log = $this->Support_model->writeLogLoan($dataLog);
- $message = $payment_result->responseMessage;
- array_push($messages, 'Success. '.$message);
- array_push($badges, 1);
- $this->session->set_flashdata('message', $messages);
- $this->session->set_flashdata('notif_status', $badges);
- }
- for ($i = 1; $i <= $termLoan; $i++) {
- $schedule_date = date('Y-m-d H:i:s', strtotime('+' . $i . ' month', strtotime($paymentDate)));
- $dataSchedule = array(
- 'loan_id' => $idloan,
- 'installment' => $installment,
- 'installment_date' => $schedule_date,
- 'month' => $i,
- 'created_date' => date("Y-m-d H:i:s")
- );
- $data['save_schedule'] = $this->Loan_model->saveScheduleLoan($dataSchedule);
- }
- redirect(base_url() . "loan_manager/disburseLoan/" . $borrowerid . "/" . $idloan, "refresh");
- // redirect(base_url() . "loan_manager/loanmasteredit/" . $borrowerid . "/" . $idloan, "refresh");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement