| Server IP : 138.197.176.125 / Your IP : 216.73.217.122 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/ |
Upload File : |
<?php
$Vtiger_Utils_Log = true;
include_once('includes/main/WebUI.php');
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
global $adb,$current_user;
$sql = "SELECT *,SUM(vp.actual_amount_received) as total_from_payment FROM vtiger_payments as vp INNER JOIN vtiger_crmentity as vc ON vc.crmid = vp.paymentsid INNER JOIN vtiger_invoice as vi ON vi.invoiceid = vp.age_related_class WHERE vc.deleted = 0 AND vi.salesorderid = '230' group by vi.salesorderid";
$getPaymentData = $adb->pquery($sql);
$numRows = $adb->num_rows($getPaymentData);
$arr = array();
for ($i=0; $i < $numRows; $i++) {
$idArr = array();
$paymentId = $adb->query_result($getPaymentData, $i, 'paymentsid');
$total_from_payment = $adb->query_result($getPaymentData, $i, 'total_from_payment');
$paymentRecordModel = Vtiger_Record_Model::getInstanceById($paymentId);
$age_related_class = $paymentRecordModel->get('age_related_class');
if($age_related_class){
$invoiceRecordModel = Vtiger_Record_Model::getInstanceById($age_related_class);
$salesorder_id = $invoiceRecordModel->get('salesorder_id');
// $grand_total_in = $invoiceRecordModel->get('hdnGrandTotal');
// $grand_total_fin = number_format($grand_total_in,2);
// $total_invoiced_final_amount = str_replace(',', '', $grand_total_fin);
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 vc.deleted = ? GROUP BY salesorderid";
$getInvoiceData = $adb->pquery($sql, array($salesorder_id, 0));
$numberOfRows = $adb->num_rows($getInvoiceData);
if($numberOfRows){
$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);
// ----------------------------------------- End
$RecordModule = Vtiger_Record_Model::getInstanceById($salesorder_id);
$total_paid_amount = $RecordModule->get('total_paid_amount') + $total_from_payment;
$grand_total_so = $RecordModule->get('hdnGrandTotal');
$total_uninvoiced_amount = $grand_total_so - $grand_total_in;
$total_unpaid_amount = $total_invoiced_final_amount - $total_paid_amount;
$check_mail = $adb->pquery("UPDATE vtiger_salesorder SET total_invoiced_amount=?,total_uninvoiced_amount=?,total_unpaid_amount = ?,total_paid_amount=? WHERE salesorderid=?",array($total_invoiced_final_amount,$total_uninvoiced_amount,$total_unpaid_amount,$total_paid_amount,$salesorder_id));
}
}
// if($salesorder_id){
// $RecordModule = Vtiger_Record_Model::getInstanceById($salesorder_id);
// // $total_paid_amount = $RecordModule->get('total_paid_amount');
// $total_paid_amount = number_format($adb->query_result($getPaymentData, $i, 'total_from_payment'),0);
// $grand_total_so = $RecordModule->get('hdnGrandTotal');
// $total_uninvoiced_amount = $grand_total_so - $grand_total_in;
// $total_unpaid_amount = $total_invoiced_final_amount - $total_paid_amount;
// $check_mail = $adb->pquery("UPDATE vtiger_salesorder SET total_invoiced_amount=?,total_uninvoiced_amount=?,total_unpaid_amount = ?,total_paid_amount=? WHERE salesorderid=?",array($total_invoiced_final_amount,$total_uninvoiced_amount,$total_unpaid_amount,$total_paid_amount,$salesorder_id));
// }
}
}
echo 'Successfully Updated!';
?>