IGR Mail content : ps

This commit is contained in:
VE10-Sanjeev 2025-02-03 06:26:33 +00:00
parent 30d5fd0714
commit ffa653f8e6
4 changed files with 250 additions and 548 deletions

View File

@ -442,7 +442,7 @@ class Inwardgateregister extends BaseController
} }
} }
#Step 3 Master Details Gathering to Save In DB #Step 3 Master Details Gathering to Save In DB
$igr = array('PONO' => $PONO, 'VehicleNo' => $VehicleNo, 'TransporterId'=>$TransporterId,'DeliveryChellanOrInvoiceNo' => $DeliveryChellanOrInvoiceNo, 'DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt, 'DriverName' => $DriverName, 'DriverMobileNumber' => $DriverMobileNumber,'IGRStatus' => $IGRStatus, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt, 'PaymentStatus' => $paymentstatus, 'Remarks'=>$MasterRemarks); $igr = array('PONO' => $PONO, 'VehicleNo' => $VehicleNo, 'TransporterId'=>$TransporterId,'DeliveryChellanOrInvoiceNo' => $DeliveryChellanOrInvoiceNo, 'DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt, 'DriverName' => $DriverName, 'DriverMobileNumber' => $DriverMobileNumber,'IGRStatus' => $IGRStatus, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt, 'PaymentStatus' => $paymentstatus, 'Remark'=>$MasterRemarks);
$igr['MasterFile'] = $requestMasterFileName; $igr['MasterFile'] = $requestMasterFileName;
#Step 4 Calling DB to Save IGR Master #Step 4 Calling DB to Save IGR Master
$IGRNO = $this->inwardgateregister_model->addigrM($igr); $IGRNO = $this->inwardgateregister_model->addigrM($igr);
@ -476,19 +476,16 @@ class Inwardgateregister extends BaseController
#Step 5 Save Master Detail On History Table #Step 5 Save Master Detail On History Table
if($VehicleNo){ if($VehicleNo){
$igr_history = array('field' => 'VehicleNo','is_add' => 1,'new_data' => $VehicleNo,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO); $hist = array('key' => 'VehicleNo', 'value' => $VehicleNo, 'igr_no' => $IGRNO, 'igr_item_no' => NULL);
$history_id = $this->inwardgateregister_model->igr_history($igr_history); $this->saveIGRHistory($hist);
log_message('error', "History updated successfully. History id: " . $history_id);
} }
if($DriverName){ if($DriverName){
$igr_history = array('field' => 'DriverName','is_add' => 1,'new_data' => $DriverName,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO); $hist = array('key' => 'DriverName', 'value' => $DriverName, 'igr_no' => $IGRNO, 'igr_item_no' => NULL);
$history_id = $this->inwardgateregister_model->igr_history($igr_history); $this->saveIGRHistory($hist);
log_message('error', "History updated successfully. History id: " . $history_id);
} }
if($DriverMobileNumber){ if($DriverMobileNumber){
$igr_history = array('field' => 'DriverMobileNumber','is_add' => 1,'new_data' => $DriverMobileNumber,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO); $hist = array('key' => 'DriverMobileNumber', 'value' => $DriverMobileNumber, 'igr_no' => $IGRNO, 'igr_item_no' => NULL);
$history_id = $this->inwardgateregister_model->igr_history($igr_history); $this->saveIGRHistory($hist);
log_message('error', "History updated successfully. History id: " . $history_id);
} }
#Step 6 Updating OGR Details #Step 6 Updating OGR Details
@ -582,43 +579,32 @@ class Inwardgateregister extends BaseController
$historydetails = array('MaterialCode' => $MaterialCode, 'Transaction_type' => "Add", 'Ref_Type' => "IGR", 'Ref_No' => $igrlineno, 'Quantity' => $QuantityAsPerInvoice, 'CreatedBy' => $CreatedBy, 'CreatedOn' => $createddt, 'SupplierID' => $SupplierId, 'ItemValue' => $itemvalue); $historydetails = array('MaterialCode' => $MaterialCode, 'Transaction_type' => "Add", 'Ref_Type' => "IGR", 'Ref_No' => $igrlineno, 'Quantity' => $QuantityAsPerInvoice, 'CreatedBy' => $CreatedBy, 'CreatedOn' => $createddt, 'SupplierID' => $SupplierId, 'ItemValue' => $itemvalue);
$this->inwardgateregister_model->addmaterialhistory($historydetails); $this->inwardgateregister_model->addmaterialhistory($historydetails);
if($GrossWeight){ if($GrossWeight){
$igr_history = array('field' => 'GrossWeight','is_add' => 1,'new_data' => $GrossWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno); $hist = array('key' => 'GrossWeight', 'value' => $GrossWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history); $this->saveIGRHistory($hist);
log_message('error', "History updated successfully. History id: " . $history_id);
} }
if($TareWeight){ if($TareWeight){
$igr_history = array('field' => 'TareWeight','is_add' => 1,'new_data' => $TareWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno); $hist = array('key' => 'TareWeight', 'value' => $TareWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history); $this->saveIGRHistory($hist);
log_message('error', "History updated successfully. History id: " . $history_id);
} }
if($NetWeight){ if($NetWeight){
$igr_history = array('field' => 'NetWeight','is_add' => 1,'new_data' => $NetWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno); $hist = array('key' => 'NetWeight', 'value' => $NetWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history); $this->saveIGRHistory($hist);
log_message('error', "History updated successfully. History id: " . $history_id);
} }
if($GrossWeightDate){ if($GrossWeightDate){
$igr_history = array('field' => 'GrossWeightDate','is_add' => 1,'new_data' => $GrossWeightDate,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno); $hist = array('key' => 'GrossWeightDate', 'value' => $GrossWeightDate, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history); $this->saveIGRHistory($hist);
log_message('error', "History updated successfully. History id: " . $history_id);
} }
if($TareWeightDate){ if($TareWeightDate){
$igr_history = array('field' => 'TareWeightDate','is_add' => 1,'new_data' => $TareWeightDate,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno); $hist = array('key' => 'TareWeightDate', 'value' => $TareWeightDate, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history); $this->saveIGRHistory($hist);
log_message('error', "History updated successfully. History id: " . $history_id);
} }
if($QuantityAsPerInvoice){ if($QuantityAsPerInvoice){
$igr_history = array('field' => 'QuantityAsPerInvoice','is_add' => 1,'new_data' => $QuantityAsPerInvoice,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno); $hist = array('key' => 'QuantityAsPerInvoice', 'value' => $QuantityAsPerInvoice, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history); $this->saveIGRHistory($hist);
log_message('error', "History updated successfully. History id: " . $history_id);
} }
if($Remarks){ if($Remarks){
$igr_history = array('field' => 'Remarks','is_add' => 1,'new_data' => $Remarks,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno); $hist = array('key' => 'Remarks', 'value' => $Remarks, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history); $this->saveIGRHistory($hist);
log_message('error', "History updated successfully. History id: " . $history_id);
} }
$get_pre_qty = $this->inwardgateregister_model->get_CurrentQty($MaterialCode); $get_pre_qty = $this->inwardgateregister_model->get_CurrentQty($MaterialCode);
$av_qty = 0; //$av_qty means Avaliable Quantity $av_qty = 0; //$av_qty means Avaliable Quantity
@ -812,7 +798,7 @@ function viewIGRDetails()
if(!is_dir($path)) { mkdir($path, 0777, true); } if(!is_dir($path)) { mkdir($path, 0777, true); }
$MasterRemarks = $this->request->getPost('MasterRemarks'); $MasterRemarks = $this->request->getPost('MasterRemarks');
$igrarr = array('DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt,'VehicleNo'=>$VehicleNo,'TransporterId'=>$TransporterId,'DriverMobileNumber'=>$DriverMobileNumber,'DriverName'=>$DriverName, 'IGRStatus' => $IGRStatus,'UpdateBY' => $updateby,'DeliveryChellanOrInvoiceNo'=>$DeliveryChellanOrInvoiceNo,'Remarks'=>$MasterRemarks); $igrarr = array('DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt,'VehicleNo'=>$VehicleNo,'TransporterId'=>$TransporterId,'DriverMobileNumber'=>$DriverMobileNumber,'DriverName'=>$DriverName, 'IGRStatus' => $IGRStatus,'UpdateBY' => $updateby,'DeliveryChellanOrInvoiceNo'=>$DeliveryChellanOrInvoiceNo,'Remark'=>$MasterRemarks);
$MasterFile = $this->request->getfile('MasterFile'); $MasterFile = $this->request->getfile('MasterFile');
@ -868,61 +854,17 @@ function viewIGRDetails()
log_message('error', "Master updated successfully: " . $updateigrmaster); log_message('error', "Master updated successfully: " . $updateigrmaster);
if(!empty($tableData )){ if(!empty($tableData )){
if($VehicleNo){ if($VehicleNo){
$vecno = $this->inwardgateregister_model->get_igr_history('VehicleNo',$IGRNo); $hist = array('key' => 'VehicleNo', 'value' => $VehicleNo, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
$this->saveIGRHistory($hist);
if(!empty($vecno)){
$old_data = NULL;
foreach ($vecno as $row) {
if ($row->field == 'VehicleNo') {
$old_data = $row->new_data;
} }
}
$igr_history = array('field' => 'VehicleNo','new_data' => $VehicleNo,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{$igr_history = array('field' => 'VehicleNo','is_edit' => 1,'new_data' => $VehicleNo,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($DriverName){ if($DriverName){
$drname = $this->inwardgateregister_model->get_igr_history('DriverName',$IGRNo); $hist = array('key' => 'DriverName', 'value' => $DriverName, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
$this->saveIGRHistory($hist);
if(!empty($drname)){
$old_data = NULL;
foreach ($drname as $row) {
if ($row->field == 'DriverName') {
$old_data = $row->new_data;
} }
}
$igr_history = array('field' => 'DriverName','new_data' => $DriverName,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'DriverName','is_edit' => 1,'new_data' => $DriverName,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($DriverMobileNumber){ if($DriverMobileNumber){
$drmob = $this->inwardgateregister_model->get_igr_history('DriverMobileNumber',$IGRNo); $hist = array('key' => 'DriverMobileNumber', 'value' => $DriverMobileNumber, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
$this->saveIGRHistory($hist);
if(!empty($drmob)){
$old_data = NULL;
foreach ($drmob as $row) {
if ($row->field == 'GrossWeight') {
$old_data = $row->new_data;
} }
}
$igr_history = array('field' => 'DriverMobileNumber','new_data' => $DriverMobileNumber,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'DriverMobileNumber','is_edit' => 1,'new_data' => $DriverMobileNumber,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
foreach ($tableData as $row) { foreach ($tableData as $row) {
$quantityAsPerInvoice = $row['QuantityAsPerInvoice']; $quantityAsPerInvoice = $row['QuantityAsPerInvoice'];
$remarks = $row['Remarks']; $remarks = $row['Remarks'];
@ -965,169 +907,77 @@ function viewIGRDetails()
log_message('error', "lineitem updated successfully: " . $updateigrlineitem); log_message('error', "lineitem updated successfully: " . $updateigrlineitem);
log_message('error', 'UpdateIGR updateigrlineitem: ' . json_encode($igrline)); log_message('error', 'UpdateIGR updateigrlineitem: ' . json_encode($igrline));
if($quantityAsPerInvoice){ if ($quantityAsPerInvoice) {
$qu = $this->inwardgateregister_model->get_igr_history('QuantityAsPerInvoice',$IGRNo,$igrItemNo); $hist = array('key' => 'QuantityAsPerInvoice', 'value' => $quantityAsPerInvoice, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
$this->saveIGRHistory($hist);
if(!empty($qu)){
$old_data = NULL;
foreach ($qu as $row) {
if ($row->field == 'QuantityAsPerInvoice') {
$old_data = $row->new_data;
} }
}
$igr_history = array('field' => 'QuantityAsPerInvoice','new_data' => $quantityAsPerInvoice,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'QuantityAsPerInvoice','is_add' => 1,'new_data' => $quantityAsPerInvoice,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $igrItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($remarks){ if($remarks){
$remak = $this->inwardgateregister_model->get_igr_history('Remarks',$IGRNo,$igrItemNo); $hist = array('key' => 'Remarks', 'value' => $remarks, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
$this->saveIGRHistory($hist);
if(!empty($remak)){
$old_data = NULL;
foreach ($remak as $row) {
if ($row->field == 'Remarks') {
$old_data = $row->new_data;
} }
}
$igr_history = array('field' => 'Remarks','new_data' => $remarks,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{$igr_history = array('field' => 'Remarks','is_add' => 1,'new_data' => $remarks,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $igrItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($grossWeight){ if($grossWeight){
$gross = $this->inwardgateregister_model->get_igr_history('GrossWeight',$IGRNo,$igrItemNo); $hist = array('key' => 'GrossWeight', 'value' => $grossWeight, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
if(!empty($gross)){ $this->saveIGRHistory($hist);
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'GrossWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'GrossWeight','new_data' => $grossWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}else{
$igr_history = array('field' => 'GrossWeight','is_add' => 1,'new_data' => $grossWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
} }
if($tareWeight){ if($tareWeight){
$tare = $this->inwardgateregister_model->get_igr_history('TareWeight',$IGRNo,$igrItemNo); $hist = array('key' => 'TareWeight', 'value' => $tareWeight, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
if(!empty($tare)){ $this->saveIGRHistory($hist);
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'TareWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'TareWeight','new_data' => $tareWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}else{
$igr_history = array('field' => 'TareWeight','is_edit' => 1,'new_data' => $tareWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
} }
if($netWeight){ if($netWeight){
$net = $this->inwardgateregister_model->get_igr_history('NetWeight',$IGRNo,$igrItemNo); $hist = array('key' => 'NetWeight', 'value' => $netWeight, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
if(!empty($net)){ $this->saveIGRHistory($hist);
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'NetWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'NetWeight','new_data' => $netWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'NetWeight','is_edit' => 1,'new_data' => $netWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
} }
if($GrossWtDt){ if($GrossWtDt){
$grossdate = $this->inwardgateregister_model->get_igr_history('GrossWeightDate',$IGRNo,$igrItemNo); $hist = array('key' => 'GrossWeightDate', 'value' => $GrossWtDt, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
if(!empty($grossdate)){ $this->saveIGRHistory($hist);
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'GrossWeightDate') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'GrossWeightDate','new_data' => $GrossWtDt,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'GrossWeightDate','is_edit' => 1,'new_data' => $GrossWtDt,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
} }
if($TareWtDt){ if($TareWtDt){
$taredate = $this->inwardgateregister_model->get_igr_history('TareWeightDate',$IGRNo,$igrItemNo); $hist = array('key' => 'TareWeightDate', 'value' => $TareWtDt, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
$this->saveIGRHistory($hist);
if(!empty($taredate)){
$old_data = NULL;
foreach ($taredate as $row) {
if ($row->field == 'TareWeightDate') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'TareWeightDate','new_data' => $TareWtDt,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'TareWeightDate','is_edit' => 1,'new_data' => $TareWtDt,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
} }
} }
} }
$result_for_email = $this->inwardgateregister_model->getDetailsforEmail($this->session->get('userId')); if ($getigrstatus == 'ST027' && ($updateigrmaster > 0 || $updateigrlineitem > 0)) {
if ($updateigrmaster > 0 || $updateigrlineitem > 0) {
if ($getigrstatus == 'ST027') {
$result_for_email = $this->inwardgateregister_model->getDetailsforEmail($this->session->get('userId')); $result_for_email = $this->inwardgateregister_model->getDetailsforEmail($this->session->get('userId'));
$result_for_history = $this->inwardgateregister_model->getHistoryDetailsforEmail($IGRNo);
// print_r($result_for_email);
$notification = new Notification(); $notification = new Notification();
$history_content = NULL;
$history = $result_for_history;
$field_labels = [
"Remarks" => "Remarks",
"QuantityAsPerInvoice" => "Received Qty",
"GrossWeight" => "Gross Weight",
"TareWeight" => "Tare Weight",
"NetWeight" => "Net Weight",
"GrossWeightDate" => "Gross Weight Date",
"TareWeightDate" => "Tare Weight Date",
"VehicleNo" => "Vehicle Number",
"DriverName" => "Driver Name",
"DriverMobileNumber" => "Driver Mobile Number"
];
$history_content = "<br>The following values have been edited:<br>";
for ($j = 0; $j < count($history); $j++) {
$field_name = $history[$j]->field;
$readable_field = isset($field_labels[$field_name]) ? $field_labels[$field_name] : $field_name;
$history_content .= "<br>" . $readable_field . ": " . $history[$j]->old_data . " was updated to " . $history[$j]->new_data . ".";
}
for ($i = 0; $i < count($result_for_email['emails']); $i++) { for ($i = 0; $i < count($result_for_email['emails']); $i++) {
$email_response = $notification->sendEmail([ $email_response = $notification->sendEmail([
'recipient_email' => $result_for_email['emails'][$i]->email, 'recipient_email' => $result_for_email['emails'][$i]->email,
'subject' => $result_for_email['company'].' - IGR Notification', 'subject' => $result_for_email['company'].' - IGR Notification',
'description' => 'IGR Number : '.$IGRNo.' is Edited By '.($result_for_email['full_name'] ?? $this->session->get('name')), 'description' => 'IGR Number : '.$IGRNo.' is Edited By '.($result_for_email['full_name'] ?? $this->session->get('name'))." On ".date('d-m-Y H:i A', strtotime(get_current_date_time() . ' +30 seconds')). $history_content,
'company' => $result_for_email['company'], 'company' => $result_for_email['company'],
'from_mail'=> $result_for_email['from_mail'] 'from_mail'=> $result_for_email['from_mail']
]); ]);
@ -1144,10 +994,8 @@ function viewIGRDetails()
$this->logger->error("Email ID = " . $result_for_email['emails'][$i]->email . " " . $mail_log); $this->logger->error("Email ID = " . $result_for_email['emails'][$i]->email . " " . $mail_log);
} }
} }
// echo "***".$history_content;die;
} }
}
if ($updateigrmaster > 0) { if ($updateigrmaster > 0) {
$finalstatement = "Successfully Updated IGR Number: $IGRNo \n"; $finalstatement = "Successfully Updated IGR Number: $IGRNo \n";
@ -1192,102 +1040,26 @@ function viewIGRDetails()
if (is_array($lineitemdata)) { if (is_array($lineitemdata)) {
if($GrossWeight){ if($GrossWeight){
$gross = $this->inwardgateregister_model->get_igr_history('GrossWeight',$IGRNo); $hist = array('key' => 'GrossWeight', 'value' => $GrossWeight, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
if(!empty($gross)){ $this->saveIGRHistory($hist);
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'GrossWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'GrossWeight','new_data' => $GrossWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}else{
$igr_history = array('field' => 'GrossWeight','is_add' => 1,'new_data' => $GrossWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
} }
if($TareWeight){ if($TareWeight){
$tare = $this->inwardgateregister_model->get_igr_history('TareWeight',$IGRNo); $hist = array('key' => 'TareWeight', 'value' => $TareWeight, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
if(!empty($tare)){ $this->saveIGRHistory($hist);
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'TareWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'TareWeight','new_data' => $TareWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}else{
$igr_history = array('field' => 'TareWeight','is_edit' => 1,'new_data' => $TareWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
} }
if($NetWeight){ if($NetWeight){
$net = $this->inwardgateregister_model->get_igr_history('NetWeight',$IGRNo); $hist = array('key' => 'NetWeight', 'value' => $NetWeight, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
if(!empty($net)){ $this->saveIGRHistory($hist);
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'NetWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'NetWeight','new_data' => $NetWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'NetWeight','is_edit' => 1,'new_data' => $NetWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
} }
if($GrossWtDt){ if($GrossWtDt){
$grossdate = $this->inwardgateregister_model->get_igr_history('GrossWeightDate',$IGRNo); $hist = array('key' => 'GrossWeightDate', 'value' => $GrossWtDt, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
if(!empty($grossdate)){ $this->saveIGRHistory($hist);
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'GrossWeightDate') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'GrossWeightDate','new_data' => $GrossWtDt,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'GrossWeightDate','is_edit' => 1,'new_data' => $GrossWtDt,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
} }
if($TareWtDt){ if($TareWtDt){
$taredate = $this->inwardgateregister_model->get_igr_history('TareWeightDate',$IGRNo); $hist = array('key' => 'TareWeightDate', 'value' => $TareWtDt, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
$this->saveIGRHistory($hist);
}
if(!empty($taredate)){
$old_data = NULL;
foreach ($taredate as $row) {
if ($row->field == 'TareWeightDate') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'TareWeightDate','new_data' => $TareWtDt,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'TareWeightDate','is_edit' => 1,'new_data' => $TareWtDt,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
// if($DeliveryChellanOrInvoiceNo){ // if($DeliveryChellanOrInvoiceNo){
// $igr_history = array('field' => 'DeliveryChellanOrInvoiceNo','is_edit' => 1,'new_data' => $DeliveryChellanOrInvoiceNo,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO); // $igr_history = array('field' => 'DeliveryChellanOrInvoiceNo','is_edit' => 1,'new_data' => $DeliveryChellanOrInvoiceNo,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO);
// $history_id = $this->inwardgateregister_model->igr_history($igr_history); // $history_id = $this->inwardgateregister_model->igr_history($igr_history);
@ -1304,61 +1076,18 @@ function viewIGRDetails()
// log_message('error', "History updated successfully. History id: " . $history_id); // log_message('error', "History updated successfully. History id: " . $history_id);
// } // }
if($VehicleNo){ if($VehicleNo){
$vecno = $this->inwardgateregister_model->get_igr_history('VehicleNo',$IGRNo); $hist = array('key' => 'VehicleNo', 'value' => $VehicleNo, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
$this->saveIGRHistory($hist);
if(!empty($vecno)){
$old_data = NULL;
foreach ($vecno as $row) {
if ($row->field == 'VehicleNo') {
$old_data = $row->new_data;
} }
}
$igr_history = array('field' => 'VehicleNo','new_data' => $VehicleNo,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{$igr_history = array('field' => 'VehicleNo','is_edit' => 1,'new_data' => $VehicleNo,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($DriverName){ if($DriverName){
$drname = $this->inwardgateregister_model->get_igr_history('DriverName',$IGRNo); $hist = array('key' => 'DriverName', 'value' => $DriverName, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
$this->saveIGRHistory($hist);
if(!empty($drname)){
$old_data = NULL;
foreach ($drname as $row) {
if ($row->field == 'DriverName') {
$old_data = $row->new_data;
} }
}
$igr_history = array('field' => 'DriverName','new_data' => $DriverName,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'DriverName','is_edit' => 1,'new_data' => $DriverName,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($DriverMobileNumber){ if($DriverMobileNumber){
$drmob = $this->inwardgateregister_model->get_igr_history('DriverMobileNumber',$IGRNo); $hist = array('key' => 'DriverMobileNumber', 'value' => $DriverMobileNumber, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
$this->saveIGRHistory($hist);
}
if(!empty($drmob)){
$old_data = NULL;
foreach ($drmob as $row) {
if ($row->field == 'GrossWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'DriverMobileNumber','new_data' => $DriverMobileNumber,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'DriverMobileNumber','is_edit' => 1,'new_data' => $DriverMobileNumber,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
$igrarr = array('VehicleNo' => $VehicleNo, 'DriverName' => $DriverName, 'DriverMobileNumber' => $DriverMobileNumber,'IGRStatus' => $Status, 'UpdateBY' => $updateby,'GrossWeight'=>$GrossWeight,'TareWeight'=>$TareWeight,'NetWeight'=>$NetWeight,'GrossWeightDate'=>$GrossWtDt,'TareWeightDate'=>$TareWtDt); $igrarr = array('VehicleNo' => $VehicleNo, 'DriverName' => $DriverName, 'DriverMobileNumber' => $DriverMobileNumber,'IGRStatus' => $Status, 'UpdateBY' => $updateby,'GrossWeight'=>$GrossWeight,'TareWeight'=>$TareWeight,'NetWeight'=>$NetWeight,'GrossWeightDate'=>$GrossWtDt,'TareWeightDate'=>$TareWtDt);
$masterdata = $this->inwardgateregister_model->updateigr($igrarr, $IGRNo); $masterdata = $this->inwardgateregister_model->updateigr($igrarr, $IGRNo);
@ -1383,42 +1112,13 @@ function viewIGRDetails()
// print_r($igrline); // print_r($igrline);
$lineitemdata = $this->inwardgateregister_model->updateIGRLineItem($igrline, $IGRItemNo); $lineitemdata = $this->inwardgateregister_model->updateIGRLineItem($igrline, $IGRItemNo);
if($QuantityAsPerInvoice){ if($QuantityAsPerInvoice){
$qu = $this->inwardgateregister_model->get_igr_history('QuantityAsPerInvoice',$IGRNo,$IGRItemNo); $hist = array('key' => 'QuantityAsPerInvoice', 'value' => $QuantityAsPerInvoice, 'igr_no' => $IGRNo, 'igr_item_no' => $IGRItemNo);
$this->saveIGRHistory($hist);
if(!empty($qu)){
$old_data = NULL;
foreach ($qu as $row) {
if ($row->field == 'QuantityAsPerInvoice') {
$old_data = $row->new_data;
} }
}
$igr_history = array('field' => 'QuantityAsPerInvoice','new_data' => $QuantityAsPerInvoice,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'QuantityAsPerInvoice','is_add' => 1,'new_data' => $QuantityAsPerInvoice,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($Remarks){ if($Remarks){
$remak = $this->inwardgateregister_model->get_igr_history('Remarks',$IGRNo,$IGRItemNo); $hist = array('key' => 'Remarks', 'value' => $Remarks, 'igr_no' => $IGRNo, 'igr_item_no' => $IGRItemNo);
$this->saveIGRHistory($hist);
if(!empty($remak)){
$old_data = NULL;
foreach ($remak as $row) {
if ($row->field == 'Remarks') {
$old_data = $row->new_data;
} }
}
$igr_history = array('field' => 'Remarks','new_data' => $Remarks,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{$igr_history = array('field' => 'Remarks','is_add' => 1,'new_data' => $Remarks,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
$i++; $i++;
if ($lineitemdata > 0) { if ($lineitemdata > 0) {
$dummy++; $dummy++;
@ -1457,101 +1157,24 @@ function updateIGRWeight(){
if(!is_dir($path)) { mkdir($path, 0777, true); } if(!is_dir($path)) { mkdir($path, 0777, true); }
if($GrossWeight){ if($GrossWeight){
$gross = $this->inwardgateregister_model->get_igr_history('GrossWeight',$IGRNO, $IGRItemNo); $hist = array('key' => 'GrossWeight', 'value' => $GrossWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo);
if(!empty($gross)){ $this->saveIGRHistory($hist);
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'GrossWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'GrossWeight','new_data' => $GrossWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}else{
$igr_history = array('field' => 'GrossWeight','is_add' => 1,'new_data' => $GrossWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
if($TareWeight){
$tare = $this->inwardgateregister_model->get_igr_history('TareWeight',$IGRNO, $IGRItemNo);
if(!empty($tare)){
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'TareWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'TareWeight','new_data' => $TareWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}else{
$igr_history = array('field' => 'TareWeight','is_edit' => 1,'new_data' => $TareWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} }
if($GrossWeight){
$hist = array('key' => 'TareWeight', 'value' => $TareWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo);
$this->saveIGRHistory($hist);
} }
if($NetWeight){ if($NetWeight){
$net = $this->inwardgateregister_model->get_igr_history('NetWeight',$IGRNO, $IGRItemNo); $hist = array('key' => 'NetWeight', 'value' => $NetWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo);
if(!empty($net)){ $this->saveIGRHistory($hist);
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'NetWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'NetWeight','new_data' => $NetWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'NetWeight','is_edit' => 1,'new_data' => $NetWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
} }
if($GrossWtDt){ if($GrossWtDt){
$grossdate = $this->inwardgateregister_model->get_igr_history('GrossWeightDate',$IGRNO, $IGRItemNo); $hist = array('key' => 'GrossWeightDate', 'value' => $GrossWtDt, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo);
if(!empty($grossdate)){ $this->saveIGRHistory($hist);
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'GrossWeightDate') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'GrossWeightDate','new_data' => $GrossWtDt,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'GrossWeightDate','is_edit' => 1,'new_data' => $GrossWtDt,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
} }
if($TareWtDt){ if($TareWtDt){
$taredate = $this->inwardgateregister_model->get_igr_history('TareWeightDate',$IGRNO, $IGRItemNo); $hist = array('key' => 'TareWeightDate', 'value' => $TareWtDt, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo);
$this->saveIGRHistory($hist);
if(!empty($taredate)){
$old_data = NULL;
foreach ($taredate as $row) {
if ($row->field == 'TareWeightDate') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'TareWeightDate','new_data' => $TareWtDt,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'TareWeightDate','is_edit' => 1,'new_data' => $TareWtDt,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
} }
@ -1906,6 +1529,62 @@ function updateIGRWeight(){
} }
public function saveIGRHistory($hist){
$field = $hist['key'];
$igr_no = $hist['igr_no'];
$igr_item_no = $hist['igr_item_no'];
$new_data = $hist['value'];
$old_data = NULL;
$same = false;
log_message('error', "$igr_no Save History function entered.");
// Get existing history
$existingHist = $this->inwardgateregister_model->get_igr_history($field, $igr_no, $igr_item_no);
if (!empty($existingHist)) {
foreach ($existingHist as $row) {
if ($row->new_data == $new_data) {
$same = true; // The same data already exists
break;
} else {
$old_data = $row->new_data; // Keep track of the latest `new_data`
}
}
}
if (!$same) {
// Insert or update history since data is different
$igr_history = array(
'field' => $field,
'new_data' => $new_data,
'old_data' => $old_data,
'history_dated' => get_current_date_time(),
'by' => $this->session->get('userId'),
'IGR_No' => $igr_no,
'IGRItem_No' => $igr_item_no
);
if ($old_data !== NULL) {
$igr_history['is_edit'] = 1; // Update existing record
} else {
$igr_history['is_add'] = 1; // Insert new record
}
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History ID: $history_id" );
} else {
// echo "No update needed: ".$param['key']." ($value) already exists.";
log_message('error', "No update needed: $field ($new_data) already exists.");
}
}

View File

@ -221,15 +221,10 @@ class Inwardgateregister_model extends Model
} }
public function igr_history($hsty_arr) { public function igr_history($hsty_arr) {
$this->db->transStart();
$builder = $this->db->table('t_igr_history'); $builder = $this->db->table('t_igr_history');
$builder->insert($hsty_arr); $builder->insert($hsty_arr);
$this->db->transComplete();
if ($this->db->transStatus() === FALSE) { return $this->db->insertID(); // Return last inserted ID
return false;
} else {
return $this->db->insertID();
}
} }
function get_igr_history($col,$IGR,$IGRITEM = null) function get_igr_history($col,$IGR,$IGRITEM = null)
@ -1179,6 +1174,19 @@ class Inwardgateregister_model extends Model
return $result; return $result;
} }
public function getHistoryDetailsforEmail($igr){
$date = date('Y-m-d H:i:s');
$to = date('Y-m-d H:i:s', strtotime($date . ' +30 seconds'));
$from = date('Y-m-d H:i:s', strtotime($date . ' -30 seconds'));
$builder = $this->db->table('t_igr_history')->where('IGR_NO', $igr)
->where('is_edit', 1)
->where('history_dated BETWEEN "'.$from.'" AND "'.$to.'"');
$query = $builder->get();
// echo $this->db->getLastQuery()->getQuery(); die;
return $query->getResult();
}
public function getDetailsforEmail($userId) public function getDetailsforEmail($userId)
{ {
$query0 = $this->db->query(" $query0 = $this->db->query("

View File

@ -145,7 +145,7 @@
?> ?>
</div> </div>
<div class="form-group col-md-3"> <div class="form-group col-md-3">
<label class="col-form-label">Remarks</label> <label class="col-form-label">Remark</label>
<?php <?php
$data = array('name' => 'MasterRemarks', 'value' => set_value('MasterRemarks'), 'id' => 'MasterRemarks', 'class' => 'form-control', 'autocomplete' => 'off','rows' => 3); $data = array('name' => 'MasterRemarks', 'value' => set_value('MasterRemarks'), 'id' => 'MasterRemarks', 'class' => 'form-control', 'autocomplete' => 'off','rows' => 3);
echo form_textarea($data); echo form_textarea($data);

View File

@ -387,13 +387,13 @@
<div class="col-md-3"> <div class="col-md-3">
<div class="form-group"> <div class="form-group">
<label class="col-form-label">Invoice Date <span class="text-danger">*</span></label> <label class="col-form-label">Invoice Date <span class="text-danger">*</span></label>
<input type="date" class="form-control" id="InvoiceDate" name="InvoiceDate" required autocomplete="off"> <input type="date" class="form-control" id="InvoiceDate" name="InvoiceDate" required autocomplete="off" style="background-color: #fff !important">
</div> </div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<div class="form-group"> <div class="form-group">
<label class="col-form-label">Material Received Date <span class="text-danger">*</span></label> <label class="col-form-label">Material Received Date <span class="text-danger">*</span></label>
<input type="date" class="form-control" id="MaterialRcvdDate" name="MaterialRcvdDate" required autocomplete="off"> <input type="date" class="form-control" id="MaterialRcvdDate" name="MaterialRcvdDate" required autocomplete="off" style="background-color: #fff !important">
</div> </div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
@ -452,7 +452,7 @@
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<div class="form-group"> <div class="form-group">
<label class="col-form-label">Remarks</label> <label class="col-form-label">Remark</label>
<?php <?php
$data = array('name' => 'MasterRemarks', 'value' => set_value('MasterRemarks'), 'id' => 'MasterRemarks', 'class' => 'form-control', 'autocomplete' => 'off','rows' => 3); $data = array('name' => 'MasterRemarks', 'value' => set_value('MasterRemarks'), 'id' => 'MasterRemarks', 'class' => 'form-control', 'autocomplete' => 'off','rows' => 3);
echo form_textarea($data); echo form_textarea($data);
@ -876,6 +876,7 @@
$("#InvoiceDate").val(''); $("#InvoiceDate").val('');
$("#MaterialRcvdDate").val(''); $("#MaterialRcvdDate").val('');
$("#MasterRemarks").val(''); $("#MasterRemarks").val('');
$("#Remark").val('');
$("#ser").val(''); $("#ser").val('');
$("#tbleIGRAppend").empty(); // Clear the table $("#tbleIGRAppend").empty(); // Clear the table
// Hide the MasterFileLabel if no data // Hide the MasterFileLabel if no data
@ -888,7 +889,7 @@
$.each(parsedData['details'], function(i, item) { $.each(parsedData['details'], function(i, item) {
if (igr == item.IGRNO) { if (igr == item.IGRNO) {
console.log(item); console.log(item,"**");
$('#IgrshowTitle').text(" ( " + item.IGRNO + " ) "); $('#IgrshowTitle').text(" ( " + item.IGRNO + " ) ");
$("#IGRNO1").val(item.IGRNO); $("#IGRNO1").val(item.IGRNO);
$("#PONO1").val(item.PONO); $("#PONO1").val(item.PONO);
@ -913,6 +914,7 @@
$("#Supplier").val(item.SupplierName + "\n" + item.Address); $("#Supplier").val(item.SupplierName + "\n" + item.Address);
$("#Add1").val(item.Address); $("#Add1").val(item.Address);
$("#Invoice_No").val(item.DeliveryChellanOrInvoiceNo); $("#Invoice_No").val(item.DeliveryChellanOrInvoiceNo);
$("#MasterRemarks").val(item.Remark);
console.log(typeof item.MasterFile); console.log(typeof item.MasterFile);
modal.find('#MasterFileLabel').hide(); modal.find('#MasterFileLabel').hide();
if (typeof item.MasterFile == 'string') { if (typeof item.MasterFile == 'string') {
@ -940,8 +942,9 @@
$("#ser").val(item.ServiceDescription); $("#ser").val(item.ServiceDescription);
var amount = item.Rate*item.QuantityAsPerInvoice; var amount = item.Rate*item.QuantityAsPerInvoice;
var tax_percentage = item.TaxInPercentage; var tax_percentage = item.TaxInPercentage;
var taxable_amount = (amount * tax_percentage) / 100; var tax_amount = (amount * tax_percentage) / 100;
var total_with_tax = amount + taxable_amount; var grand_total_amount = amount + tax_amount;
i = i + 1; i = i + 1;
// userrole is system admin also know as admin (if) // userrole is system admin also know as admin (if)
@ -955,14 +958,11 @@
'<td style="width: 100px;" id="Quantity' + i + '" name="Quantity">' + parseInt(item.Quantity) + '</td>' + '<td style="width: 100px;" id="Quantity' + i + '" name="Quantity">' + parseInt(item.Quantity) + '</td>' +
'<td style="width: 100px;" data-name="sel" ><input type="text" onchange="validateReceivedQuantity(' + i + ',' + isOpenOrder + ')"id="QuantityAsPerInvoice' + i + '" name="QuantityAsPerInvoice' + i + '" value="' + parseInt(item.QuantityAsPerInvoice) + '" onkeypress="return isNumberKey(event);" style="width: 75px;"></td>' + '<td style="width: 100px;" data-name="sel" ><input type="text" onchange="validateReceivedQuantity(' + i + ',' + isOpenOrder + ')"id="QuantityAsPerInvoice' + i + '" name="QuantityAsPerInvoice' + i + '" value="' + parseInt(item.QuantityAsPerInvoice) + '" onkeypress="return isNumberKey(event);" style="width: 75px;"></td>' +
'<td style="width: 100px;" name="PendingQuantity' + i + '" id="PendingQuantity' + i + '">' + ((isOpenOrder) ? 0 : parseInt(item.Quantity - item.QuantityAsPerInvoice)) + '</td>' + '<td style="width: 100px;" name="PendingQuantity' + i + '" id="PendingQuantity' + i + '">' + ((isOpenOrder) ? 0 : parseInt(item.Quantity - item.QuantityAsPerInvoice)) + '</td>' +
'<td style="width: 50px;" name="Rate" id="Rate" >' + Number(item.Rate).toFixed(2) + '</td>' + '<td style="width: 50px;" id="Rate' + i + '" >' + Number(item.Rate).toFixed(2) + '</td>' +
'<td style="width: 50px;" name="tax">' + tax_percentage + '</td>' + '<td style="width: 50px;" id="tax_percentage' + i + '">' + tax_percentage + '</td>' +
'<td style="width: 50px;" id="amount' + i + '">' + amount + '</td>' +
'<td style="width: 50px;" id="grand_total_amount' + i + '">' + grand_total_amount + '</td>' +
'<td style="width: 100px;"><input type="text" id="Remark' + i + '" name="Remark' + i + '" class="form" onchange="SetRemarks(' + i + ')" style="width: 75px;" value="'+item.Remarks+'"> </td>' +
'<td style="width: 50px;" name="amount">' + amount + '</td>' +
'<td style="width: 50px;" name="tax_amount">' + total_with_tax + '</td>' +
'<td style="width: 100px;"><input type="text" id="Remark' + i + '" name="Remark' + i + '" class="form" onchange="SetRemarks(' + i + ')" style="width: 75px;"> </td>' +
'<td style="width: 50px;"><a target="_blank" data-toggle="modal" data-target="#WeightCalculator" title="Weight Calculator" data-index="' + i + '" data-material="' + item.MaterialName + '" data-igrstatus = "' + igrstatus + '"><i class="fa fa-solid fa-truck" style="text-align: center;"></i></a> </td>' + '<td style="width: 50px;"><a target="_blank" data-toggle="modal" data-target="#WeightCalculator" title="Weight Calculator" data-index="' + i + '" data-material="' + item.MaterialName + '" data-igrstatus = "' + igrstatus + '"><i class="fa fa-solid fa-truck" style="text-align: center;"></i></a> </td>' +
'<input type="hidden" id="IGRNO' + i + '" name="IGRNO' + i + '" value="' + item.IGRNO + '">' + '<input type="hidden" id="IGRNO' + i + '" name="IGRNO' + i + '" value="' + item.IGRNO + '">' +
'<input type="hidden" id="MaterialCode' + i + '" name="MaterialCode' + i + '" value="' + item.MaterialCode + '">' + '<input type="hidden" id="MaterialCode' + i + '" name="MaterialCode' + i + '" value="' + item.MaterialCode + '">' +
@ -987,10 +987,7 @@
// userrole is security based on status we show and here (else if) // userrole is security based on status we show and here (else if)
else if (userRole !== 1) { else if (userRole !== 1) {
var amount = item.Rate*item.QuantityAsPerInvoice;
var tax_percentage = item.TaxInPercentage;
var taxable_amount = (amount * tax_percentage) / 100;
var total_with_tax = amount + taxable_amount;
if (igrstatus === "ST074") { if (igrstatus === "ST074") {
$("#pendingQuantityHeader").css("display", "table-cell"); $("#pendingQuantityHeader").css("display", "table-cell");
trIGRHTML += '<tr>' + trIGRHTML += '<tr>' +
@ -1001,14 +998,11 @@
'<td style="width: 100px;" id="Quantity' + i + '" name="Quantity">' + parseInt(item.Quantity) + '</td>' + '<td style="width: 100px;" id="Quantity' + i + '" name="Quantity">' + parseInt(item.Quantity) + '</td>' +
'<td style="width: 100px;" data-name="sel" ><input type="text" onchange="validateReceivedQuantity(' + i + ',' + isOpenOrder + ')"id="QuantityAsPerInvoice' + i + '" name="QuantityAsPerInvoice' + i + '" value="' + parseInt(item.QuantityAsPerInvoice) + '" onkeypress="return isNumberKey(event);" style="width: 75px;"></td>' + '<td style="width: 100px;" data-name="sel" ><input type="text" onchange="validateReceivedQuantity(' + i + ',' + isOpenOrder + ')"id="QuantityAsPerInvoice' + i + '" name="QuantityAsPerInvoice' + i + '" value="' + parseInt(item.QuantityAsPerInvoice) + '" onkeypress="return isNumberKey(event);" style="width: 75px;"></td>' +
'<td style="width: 100px;" name="PendingQuantity' + i + '" id="PendingQuantity' + i + '">' + ((isOpenOrder) ? 0 : parseInt(item.Quantity - item.QuantityAsPerInvoice)) + '</td>' + '<td style="width: 100px;" name="PendingQuantity' + i + '" id="PendingQuantity' + i + '">' + ((isOpenOrder) ? 0 : parseInt(item.Quantity - item.QuantityAsPerInvoice)) + '</td>' +
'<td style="width: 50px;" name="Rate" id="Rate" >' + Number(item.Rate).toFixed(2) + '</td>' + '<td style="width: 50px;" id="Rate' + i + '" >' + Number(item.Rate).toFixed(2) + '</td>' +
'<td style="width: 50px;" name="tax">' + tax_percentage + '</td>' + '<td style="width: 50px;" id="tax_percentage' + i + '">' + tax_percentage + '</td>' +
'<td style="width: 50px;" id="amount' + i + '">' + amount + '</td>' +
'<td style="width: 50px;" id="grand_total_amount' + i + '">' + grand_total_amount + '</td>' +
'<td style="width: 100px;"><input type="text" id="Remark' + i + '" name="Remark' + i + '" class="form" onchange="SetRemarks(' + i + ')" style="width: 75px;" value="'+item.Remarks+'"> </td>' +
'<td style="width: 50px;" name="amount">' + amount + '</td>' +
'<td style="width: 50px;" name="tax_amount">' + total_with_tax + '</td>' +
'<td style="width: 100px;"><input type="text" id="Remark' + i + '" name="Remark' + i + '" class="form" onchange="SetRemarks(' + i + ')" style="width: 75px;"> </td>' +
'<td style="width: 50px;"><a target="_blank" data-toggle="modal" data-target="#WeightCalculator" title="Weight Calculator" data-index="' + i + '" data-material="' + item.MaterialName + '" data-igrstatus = "' + igrstatus + '"><i class="fa fa-solid fa-truck" style="text-align: center;"></i></a> </td>' + '<td style="width: 50px;"><a target="_blank" data-toggle="modal" data-target="#WeightCalculator" title="Weight Calculator" data-index="' + i + '" data-material="' + item.MaterialName + '" data-igrstatus = "' + igrstatus + '"><i class="fa fa-solid fa-truck" style="text-align: center;"></i></a> </td>' +
'<input type="hidden" id="IGRNO' + i + '" name="IGRNO' + i + '" value="' + item.IGRNO + '">' + '<input type="hidden" id="IGRNO' + i + '" name="IGRNO' + i + '" value="' + item.IGRNO + '">' +
'<input type="hidden" id="MaterialCode' + i + '" name="MaterialCode' + i + '" value="' + item.MaterialCode + '">' + '<input type="hidden" id="MaterialCode' + i + '" name="MaterialCode' + i + '" value="' + item.MaterialCode + '">' +
@ -1031,10 +1025,6 @@
} else { } else {
var amount = item.Rate*item.QuantityAsPerInvoice;
var tax_percentage = item.TaxInPercentage;
var taxable_amount = (amount * tax_percentage) / 100;
var total_with_tax = amount + taxable_amount;
$("#pendingQuantityHeader").css("display", "none"); $("#pendingQuantityHeader").css("display", "none");
trIGRHTML += '<tr>' + trIGRHTML += '<tr>' +
'<td style="width: 50px;" >' + i + '</td>' + '<td style="width: 50px;" >' + i + '</td>' +
@ -1043,13 +1033,10 @@
'<td style="width: 50px;" name="UOM">' + item.UOM + '</td>' + '<td style="width: 50px;" name="UOM">' + item.UOM + '</td>' +
'<td style="width: 100px;" name="Quantity">' + item.Quantity + '</td>' + '<td style="width: 100px;" name="Quantity">' + item.Quantity + '</td>' +
'<td style="width: 100px;" data-name="sel" >' + item.QuantityAsPerInvoice + '</td>' + '<td style="width: 100px;" data-name="sel" >' + item.QuantityAsPerInvoice + '</td>' +
'<td style="width: 50px;" name="Rate" id="Rate" >' + Number(item.Rate).toFixed(2) + '</td>' + '<td style="width: 50px;" id="Rate' + i + '" >' + Number(item.Rate).toFixed(2) + '</td>' +
'<td style="width: 50px;" name="tax">' + tax_percentage + '</td>' + '<td style="width: 50px;" id="tax_percentage' + i + '">' + tax_percentage + '</td>' +
'<td style="width: 50px;" id="amount' + i + '">' + amount + '</td>' +
'<td style="width: 50px;" id="grand_total_amount' + i + '">' + grand_total_amount + '</td>' +
'<td style="width: 50px;" name="tax_amount">' + total_with_tax + '</td>' +
'<td style="width: 50px;" name="amount">' + amount + '</td>' +
'<td style="width: 50px;" name="tax_amount">' + total_with_tax + '</td>' +
'<td style="width: 50px;"><a target="_blank" data-toggle="modal" data-target="#WeightCalculator" title="Weight Calculator" data-index="' + i + '" data-material="' + item.MaterialName + '" data-igrstatus = "' + igrstatus + '"><i class="fa fa-solid fa-truck" style="text-align: center;"></i></a> </td>' + '<td style="width: 50px;"><a target="_blank" data-toggle="modal" data-target="#WeightCalculator" title="Weight Calculator" data-index="' + i + '" data-material="' + item.MaterialName + '" data-igrstatus = "' + igrstatus + '"><i class="fa fa-solid fa-truck" style="text-align: center;"></i></a> </td>' +
'<input type="hidden" id="IGRNO' + i + '" name="IGRNO' + i + '" value="' + item.IGRNO + '">' + '<input type="hidden" id="IGRNO' + i + '" name="IGRNO' + i + '" value="' + item.IGRNO + '">' +
'<input type="hidden" id="MaterialCode' + i + '" name="MaterialCode' + i + '" value="' + item.MaterialCode + '">' + '<input type="hidden" id="MaterialCode' + i + '" name="MaterialCode' + i + '" value="' + item.MaterialCode + '">' +
@ -1625,13 +1612,32 @@
} }
function validateReceivedQuantity(Rowid, isOpenOrder) { function validateReceivedQuantity(Rowid, isOpenOrder) {
console.log("validation");
var InvoiceQty = parseFloat($('#QuantityAsPerInvoice' + Rowid).val() || '0.00'); // working fine var InvoiceQty = parseFloat($('#QuantityAsPerInvoice' + Rowid).val() || '0.00'); // working fine
var OrderedQty = parseFloat($("#Quantity" + Rowid).text()); var OrderedQty = parseFloat($("#Quantity" + Rowid).text());
var Rate = parseFloat($('#Rate' + Rowid).text() || '0.00');
console.log('#Rate' + Rowid+" Rate:", Rate);
var amount = Rate * InvoiceQty;
console.log('#amount' + Rowid+" amount:", amount);
var tax_percentage = parseFloat($('#tax_percentage' + Rowid).text() || '0.00');
var tax_amount = (amount * tax_percentage) / 100;
console.log('#tax_amount' + Rowid+" tax_amount:", tax_amount);
var grand_total_amount = amount + tax_amount; // tax_amount
console.log('#grand_total_amount' + Rowid+" grand_total_amount:", grand_total_amount);
if (isOpenOrder == 1) { if (isOpenOrder == 1) {
var PendingQty = 0; var PendingQty = 0;
$('#PendingQuantity' + Rowid).text(PendingQty.toFixed(0)); $('#PendingQuantity' + Rowid).text(PendingQty.toFixed(0));
$('#txtPendingQty' + Rowid).val(PendingQty.toFixed(0)); $('#txtPendingQty' + Rowid).val(PendingQty.toFixed(0));
$('#txtQuantityAsPerInvoice' + Rowid).val(InvoiceQty.toFixed(2)); $('#txtQuantityAsPerInvoice' + Rowid).val(InvoiceQty.toFixed(2));
$('#amount' + Rowid).text(amount);
$('#tax_amount' + Rowid).text(tax_amount);
$('#grand_total_amount' + Rowid).text(grand_total_amount);
return true; return true;
} else { } else {
if (parseInt(OrderedQty) !== 0) { if (parseInt(OrderedQty) !== 0) {
@ -1642,12 +1648,18 @@
} else if ((InvoiceQty) - OrderedQty > 0.00) { } else if ((InvoiceQty) - OrderedQty > 0.00) {
alert("Order is completed."); alert("Order is completed.");
$("#QuantityAsPerInvoice" + Rowid).focus().val(''); $("#QuantityAsPerInvoice" + Rowid).focus().val('');
$('#amount' + Rowid).text(amount);
$('#tax_amount' + Rowid).text(tax_amount);
$('#grand_total_amount' + Rowid).text(grand_total_amount);
return false; return false;
} else { } else {
var PendingQty = OrderedQty - (InvoiceQty); var PendingQty = OrderedQty - (InvoiceQty);
$('#PendingQuantity' + Rowid).text(PendingQty.toFixed(0)); $('#PendingQuantity' + Rowid).text(PendingQty.toFixed(0));
$('#txtPendingQty' + Rowid).val(PendingQty.toFixed(0)); $('#txtPendingQty' + Rowid).val(PendingQty.toFixed(0));
$('#txtQuantityAsPerInvoice' + Rowid).val(InvoiceQty.toFixed(2)); $('#txtQuantityAsPerInvoice' + Rowid).val(InvoiceQty.toFixed(2));
$('#amount' + Rowid).text(amount);
$('#tax_amount' + Rowid).text(tax_amount);
$('#grand_total_amount' + Rowid).text(grand_total_amount);
return true; return true;
} }
} else { } else {
@ -1655,6 +1667,9 @@
$('#PendingQuantity' + Rowid).text(PendingQty.toFixed(0)); $('#PendingQuantity' + Rowid).text(PendingQty.toFixed(0));
$('#txtPendingQty' + Rowid).val(PendingQty.toFixed(0)); $('#txtPendingQty' + Rowid).val(PendingQty.toFixed(0));
$('#txtQuantityAsPerInvoice' + Rowid).val(InvoiceQty.toFixed(2)); $('#txtQuantityAsPerInvoice' + Rowid).val(InvoiceQty.toFixed(2));
$('#amount' + Rowid).text(amount);
$('#tax_amount' + Rowid).text(tax_amount);
$('#grand_total_amount' + Rowid).text(grand_total_amount);
return true; return true;
} }
} }