| Server IP : 138.197.176.125 / Your IP : 216.73.217.55 Web Server : Apache/2.4.41 (Ubuntu) System : Linux SuiteCRM-8 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/crest/modules/Payments/ |
Upload File : |
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
function UpdateAmountSo($entityData){
$adb = PearDatabase::getInstance();
$moduleName = $entityData->getModuleName();
$wsId = $entityData->getId();
$parts = explode('x', $wsId);
$record_id = $parts[1];
if ($record_id) {
$paymentRecordModel = Vtiger_Record_Model::getInstanceById($record_id);
$age_related_class = $paymentRecordModel->get('age_related_class');
$recordModel = Vtiger_Record_Model::getInstanceById($age_related_class);
$salesorder_id = $recordModel->get('salesorder_id');
$amount = $paymentRecordModel->get('amount');
$actual_amount_received = $paymentRecordModel->get('actual_amount_received');
$tax = $paymentRecordModel->get('tax');
$bank_charges = $paymentRecordModel->get('bank_charges');
$payment_amount = $paymentRecordModel->get('payment_amount');
if($salesorder_id){
$sql = "SELECT *,SUM(vi.total) as grandTotal FROM vtiger_invoice as vi INNER JOIN vtiger_crmentity as vc ON vc.crmid = vi.invoiceid WHERE vi.salesorderid = ? AND (vi.invoicestatus <> 'Cancelled' AND vi.invoicestatus <> 'Credit Invoice') AND vc.deleted = ? GROUP BY salesorderid";
$getInvoiceData = $adb->pquery($sql, array($salesorder_id, 0));
$numberOfRows = $adb->num_rows($getInvoiceData);
if($numberOfRows > 0){
$grand_total_in = $adb->query_result($getInvoiceData, 0, 'grandtotal');
$grand_total_fin = number_format($grand_total_in,2);
$total_invoiced_final_amount = str_replace(',', '', $grand_total_fin);
$RecordModule = Vtiger_Record_Model::getInstanceById($salesorder_id);
$grand_total_so = $RecordModule->get('hdnGrandTotal');
$total_uninvoiced_amount = $grand_total_so - $grand_total_in;
$check_mail = $adb->pquery("UPDATE vtiger_salesorder SET total_invoiced_amount=?, total_uninvoiced_amount=? WHERE salesorderid=?",array($total_invoiced_final_amount,$total_uninvoiced_amount,$salesorder_id));
}
$RecordModule = Vtiger_Record_Model::getInstanceById($salesorder_id);
$total_invoiced_amount = $RecordModule->get('total_invoiced_amount');
$total_paid_amount_so = $RecordModule->get('total_paid_amount');
$total_payment_amount = $actual_amount_received + $tax + $bank_charges;
if($payment_amount != $total_payment_amount && $payment_amount != 0 && $total_payment_amount != 0){
$total_so_payment_amount = $total_paid_amount_so - $payment_amount;
$total_paid_amount = $total_so_payment_amount + $total_payment_amount;
}else{
$total_paid_amount = $total_paid_amount_so + $total_payment_amount;
}
$total_unpaid_amount = $total_invoiced_amount - $total_paid_amount;
$payment_amount = $adb->pquery("UPDATE vtiger_salesorder SET total_paid_amount=?,total_unpaid_amount=? WHERE salesorderid=?",array($total_paid_amount,$total_unpaid_amount,$salesorder_id));
if($total_payment_amount){
$payment_amount = $adb->pquery("UPDATE vtiger_payments SET payment_amount=? WHERE paymentsid = ?",array($total_payment_amount, $record_id));
$invoice_amount = $adb->pquery("UPDATE vtiger_invoice SET received_amount=? WHERE invoiceid = ?",array($total_payment_amount, $age_related_class));
}
}
}
}
?>