| 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
include_once('includes/main/WebUI.php');
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
global $adb,$current_user;
$record_id = 246;
if ($record_id) {
$invoiceRecordModel = Vtiger_Record_Model::getInstanceById($record_id);
$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);
// For Invoice which is already attached --- Ravi Added
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');
$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,0,$salesorder_id));
}
}
}
echo 'Successfully Updated!';
?>