diff --git a/app/Controllers/Inwardgateregister.php b/app/Controllers/Inwardgateregister.php
index 2103066c..485a6421 100755
--- a/app/Controllers/Inwardgateregister.php
+++ b/app/Controllers/Inwardgateregister.php
@@ -442,7 +442,7 @@ class Inwardgateregister extends BaseController
}
}
#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;
#Step 4 Calling DB to Save IGR Master
$IGRNO = $this->inwardgateregister_model->addigrM($igr);
@@ -476,19 +476,16 @@ class Inwardgateregister extends BaseController
#Step 5 Save Master Detail On History Table
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);
- $history_id = $this->inwardgateregister_model->igr_history($igr_history);
- log_message('error', "History updated successfully. History id: " . $history_id);
+ $hist = array('key' => 'VehicleNo', 'value' => $VehicleNo, 'igr_no' => $IGRNO, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
}
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);
- $history_id = $this->inwardgateregister_model->igr_history($igr_history);
- log_message('error', "History updated successfully. History id: " . $history_id);
+ $hist = array('key' => 'DriverName', 'value' => $DriverName, 'igr_no' => $IGRNO, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
}
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);
- $history_id = $this->inwardgateregister_model->igr_history($igr_history);
- log_message('error', "History updated successfully. History id: " . $history_id);
+ $hist = array('key' => 'DriverMobileNumber', 'value' => $DriverMobileNumber, 'igr_no' => $IGRNO, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
}
#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);
$this->inwardgateregister_model->addmaterialhistory($historydetails);
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);
- $history_id = $this->inwardgateregister_model->igr_history($igr_history);
- log_message('error', "History updated successfully. History id: " . $history_id);
-
+ $hist = array('key' => 'GrossWeight', 'value' => $GrossWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
+ $this->saveIGRHistory($hist);
}
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);
- $history_id = $this->inwardgateregister_model->igr_history($igr_history);
- log_message('error', "History updated successfully. History id: " . $history_id);
-
+ $hist = array('key' => 'TareWeight', 'value' => $TareWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
+ $this->saveIGRHistory($hist);
}
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);
- $history_id = $this->inwardgateregister_model->igr_history($igr_history);
- log_message('error', "History updated successfully. History id: " . $history_id);
-
+ $hist = array('key' => 'NetWeight', 'value' => $NetWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
+ $this->saveIGRHistory($hist);
}
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);
- $history_id = $this->inwardgateregister_model->igr_history($igr_history);
- log_message('error', "History updated successfully. History id: " . $history_id);
-
+ $hist = array('key' => 'GrossWeightDate', 'value' => $GrossWeightDate, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
+ $this->saveIGRHistory($hist);
}
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);
- $history_id = $this->inwardgateregister_model->igr_history($igr_history);
- log_message('error', "History updated successfully. History id: " . $history_id);
+ $hist = array('key' => 'TareWeightDate', 'value' => $TareWeightDate, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
+ $this->saveIGRHistory($hist);
}
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);
- $history_id = $this->inwardgateregister_model->igr_history($igr_history);
- log_message('error', "History updated successfully. History id: " . $history_id);
+ $hist = array('key' => 'QuantityAsPerInvoice', 'value' => $QuantityAsPerInvoice, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
+ $this->saveIGRHistory($hist);
}
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);
- $history_id = $this->inwardgateregister_model->igr_history($igr_history);
- log_message('error', "History updated successfully. History id: " . $history_id);
+ $hist = array('key' => 'Remarks', 'value' => $Remarks, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno);
+ $this->saveIGRHistory($hist);
}
$get_pre_qty = $this->inwardgateregister_model->get_CurrentQty($MaterialCode);
$av_qty = 0; //$av_qty means Avaliable Quantity
@@ -812,7 +798,7 @@ function viewIGRDetails()
if(!is_dir($path)) { mkdir($path, 0777, true); }
$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');
@@ -868,61 +854,17 @@ function viewIGRDetails()
log_message('error', "Master updated successfully: " . $updateigrmaster);
if(!empty($tableData )){
if($VehicleNo){
- $vecno = $this->inwardgateregister_model->get_igr_history('VehicleNo',$IGRNo);
-
- 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);
- }}
+ $hist = array('key' => 'VehicleNo', 'value' => $VehicleNo, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
+ }
if($DriverName){
- $drname = $this->inwardgateregister_model->get_igr_history('DriverName',$IGRNo);
-
- 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);
- }}
+ $hist = array('key' => 'DriverName', 'value' => $DriverName, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
+ }
if($DriverMobileNumber){
- $drmob = $this->inwardgateregister_model->get_igr_history('DriverMobileNumber',$IGRNo);
-
- 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);
- }}
+ $hist = array('key' => 'DriverMobileNumber', 'value' => $DriverMobileNumber, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
+ }
foreach ($tableData as $row) {
$quantityAsPerInvoice = $row['QuantityAsPerInvoice'];
$remarks = $row['Remarks'];
@@ -965,173 +907,81 @@ function viewIGRDetails()
log_message('error', "lineitem updated successfully: " . $updateigrlineitem);
log_message('error', 'UpdateIGR updateigrlineitem: ' . json_encode($igrline));
- if($quantityAsPerInvoice){
- $qu = $this->inwardgateregister_model->get_igr_history('QuantityAsPerInvoice',$IGRNo,$igrItemNo);
-
- 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 ($quantityAsPerInvoice) {
+ $hist = array('key' => 'QuantityAsPerInvoice', 'value' => $quantityAsPerInvoice, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
+ $this->saveIGRHistory($hist);
+ }
if($remarks){
- $remak = $this->inwardgateregister_model->get_igr_history('Remarks',$IGRNo,$igrItemNo);
-
- 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);
- }}
+ $hist = array('key' => 'Remarks', 'value' => $remarks, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
+ $this->saveIGRHistory($hist);
+ }
if($grossWeight){
- $gross = $this->inwardgateregister_model->get_igr_history('GrossWeight',$IGRNo,$igrItemNo);
- if(!empty($gross)){
- $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);
-
- }
+ $hist = array('key' => 'GrossWeight', 'value' => $grossWeight, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
+ $this->saveIGRHistory($hist);
}
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 ;
- ($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);
- }
+ $hist = array('key' => 'TareWeight', 'value' => $tareWeight, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
+ $this->saveIGRHistory($hist);
}
if($netWeight){
- $net = $this->inwardgateregister_model->get_igr_history('NetWeight',$IGRNo,$igrItemNo);
- if(!empty($net)){
- $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);
- }
+ $hist = array('key' => 'NetWeight', 'value' => $netWeight, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
+ $this->saveIGRHistory($hist);
}
if($GrossWtDt){
- $grossdate = $this->inwardgateregister_model->get_igr_history('GrossWeightDate',$IGRNo,$igrItemNo);
- if(!empty($grossdate)){
- $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);
- }
+ $hist = array('key' => 'GrossWeightDate', 'value' => $GrossWtDt, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
+ $this->saveIGRHistory($hist);
}
if($TareWtDt){
- $taredate = $this->inwardgateregister_model->get_igr_history('TareWeightDate',$IGRNo,$igrItemNo);
-
- 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);
- }
+ $hist = array('key' => 'TareWeightDate', 'value' => $TareWtDt, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo);
+ $this->saveIGRHistory($hist);
}
}
}
- $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_history = $this->inwardgateregister_model->getHistoryDetailsforEmail($IGRNo);
+ // print_r($result_for_email);
+
$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 = "
The following values have been edited:";
+ 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 .= "
" . $readable_field . ": `" . $history[$j]->old_data . "` was updated to `" . $history[$j]->new_data . "` .";
+ }
+
for ($i = 0; $i < count($result_for_email['emails']); $i++) {
+
$email_response = $notification->sendEmail([
'recipient_email' => $result_for_email['emails'][$i]->email,
'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'],
'from_mail'=> $result_for_email['from_mail']
]);
-
+
log_message('error', 'email reponse : ' . json_encode($email_response));
// Determine the email response
$mail_log = isset($email_response['success']) ? 'Email sent successfully' : 'Failed to send email';
@@ -1144,11 +994,9 @@ function viewIGRDetails()
$this->logger->error("Email ID = " . $result_for_email['emails'][$i]->email . " " . $mail_log);
}
}
-
- }
+ // echo "***".$history_content;die;
}
-
if ($updateigrmaster > 0) {
$finalstatement = "Successfully Updated IGR Number: $IGRNo \n";
} else if($updateigrlineitem >0){
@@ -1192,102 +1040,26 @@ function viewIGRDetails()
if (is_array($lineitemdata)) {
if($GrossWeight){
- $gross = $this->inwardgateregister_model->get_igr_history('GrossWeight',$IGRNo);
- if(!empty($gross)){
- $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);
-
- }
+ $hist = array('key' => 'GrossWeight', 'value' => $GrossWeight, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
}
if($TareWeight){
- $tare = $this->inwardgateregister_model->get_igr_history('TareWeight',$IGRNo);
- 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);
- ($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);
- }
+ $hist = array('key' => 'TareWeight', 'value' => $TareWeight, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
}
if($NetWeight){
- $net = $this->inwardgateregister_model->get_igr_history('NetWeight',$IGRNo);
- if(!empty($net)){
- $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);
- }
+ $hist = array('key' => 'NetWeight', 'value' => $NetWeight, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
}
- if($GrossWtDt){
- $grossdate = $this->inwardgateregister_model->get_igr_history('GrossWeightDate',$IGRNo);
- if(!empty($grossdate)){
- $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($GrossWtDt){
+ $hist = array('key' => 'GrossWeightDate', 'value' => $GrossWtDt, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
}
- if($TareWtDt){
- $taredate = $this->inwardgateregister_model->get_igr_history('TareWeightDate',$IGRNo);
-
- 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($TareWtDt){
+ $hist = array('key' => 'TareWeightDate', 'value' => $TareWtDt, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
}
+
// 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);
// $history_id = $this->inwardgateregister_model->igr_history($igr_history);
@@ -1303,62 +1075,19 @@ function viewIGRDetails()
// $history_id = $this->inwardgateregister_model->igr_history($igr_history);
// log_message('error', "History updated successfully. History id: " . $history_id);
// }
- if($VehicleNo){
- $vecno = $this->inwardgateregister_model->get_igr_history('VehicleNo',$IGRNo);
-
- 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){
- $drname = $this->inwardgateregister_model->get_igr_history('DriverName',$IGRNo);
-
- 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){
- $drmob = $this->inwardgateregister_model->get_igr_history('DriverMobileNumber',$IGRNo);
-
- 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);
- }}
+ if($VehicleNo){
+ $hist = array('key' => 'VehicleNo', 'value' => $VehicleNo, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
+ }
+ if($DriverName){
+ $hist = array('key' => 'DriverName', 'value' => $DriverName, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
+ }
+ if($DriverMobileNumber){
+ $hist = array('key' => 'DriverMobileNumber', 'value' => $DriverMobileNumber, 'igr_no' => $IGRNo, 'igr_item_no' => NULL);
+ $this->saveIGRHistory($hist);
+ }
+
$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);
@@ -1382,43 +1111,14 @@ function viewIGRDetails()
);
// print_r($igrline);
$lineitemdata = $this->inwardgateregister_model->updateIGRLineItem($igrline, $IGRItemNo);
- if($QuantityAsPerInvoice){
- $qu = $this->inwardgateregister_model->get_igr_history('QuantityAsPerInvoice',$IGRNo,$IGRItemNo);
-
- 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){
- $remak = $this->inwardgateregister_model->get_igr_history('Remarks',$IGRNo,$IGRItemNo);
-
- 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($QuantityAsPerInvoice){
+ $hist = array('key' => 'QuantityAsPerInvoice', 'value' => $QuantityAsPerInvoice, 'igr_no' => $IGRNo, 'igr_item_no' => $IGRItemNo);
+ $this->saveIGRHistory($hist);
+ }
+ if($Remarks){
+ $hist = array('key' => 'Remarks', 'value' => $Remarks, 'igr_no' => $IGRNo, 'igr_item_no' => $IGRItemNo);
+ $this->saveIGRHistory($hist);
+ }
$i++;
if ($lineitemdata > 0) {
$dummy++;
@@ -1457,101 +1157,24 @@ function updateIGRWeight(){
if(!is_dir($path)) { mkdir($path, 0777, true); }
if($GrossWeight){
- $gross = $this->inwardgateregister_model->get_igr_history('GrossWeight',$IGRNO, $IGRItemNo);
- if(!empty($gross)){
- $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);
-
- }
+ $hist = array('key' => 'GrossWeight', 'value' => $GrossWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo);
+ $this->saveIGRHistory($hist);
}
- 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){
- $net = $this->inwardgateregister_model->get_igr_history('NetWeight',$IGRNO, $IGRItemNo);
- if(!empty($net)){
- $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);
- }
+ $hist = array('key' => 'NetWeight', 'value' => $NetWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo);
+ $this->saveIGRHistory($hist);
}
if($GrossWtDt){
- $grossdate = $this->inwardgateregister_model->get_igr_history('GrossWeightDate',$IGRNO, $IGRItemNo);
- if(!empty($grossdate)){
- $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);
- }
+ $hist = array('key' => 'GrossWeightDate', 'value' => $GrossWtDt, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo);
+ $this->saveIGRHistory($hist);
}
if($TareWtDt){
- $taredate = $this->inwardgateregister_model->get_igr_history('TareWeightDate',$IGRNO, $IGRItemNo);
-
- 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);
- }
+ $hist = array('key' => 'TareWeightDate', 'value' => $TareWtDt, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo);
+ $this->saveIGRHistory($hist);
}
@@ -1905,6 +1528,62 @@ function updateIGRWeight(){
echo json_encode($data);
}
+
+ 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; // Flag to check if the same data exists
+
+ 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.");
+ }
+
+ }
diff --git a/app/Controllers/Payslip.php b/app/Controllers/Payslip.php
index da5d75ab..989b3e2a 100755
--- a/app/Controllers/Payslip.php
+++ b/app/Controllers/Payslip.php
@@ -610,7 +610,7 @@ class Payslip extends BaseController
$TotalSalary = $value->TotalSalary;
$Days_worked = $value->Days_worked; // working day
$Sunday = $value->sunday_count; // Sunday count
- $LOP_Days = $value->NoofDays - ($Days_worked + $Sunday); // not working day
+ $LOP_Days = $value->NoofDays - ($Days_worked); // not working day
$Paid_leave = $value->Paid_leave; // leave day
if ($value->is_management_team == 1)
{
@@ -661,7 +661,7 @@ class Payslip extends BaseController
- $totalDaysWorked = ($Days_worked + $Sunday) + $Paid_leave;
+ $totalDaysWorked = $Days_worked + $Paid_leave;
$dayBasic = $Basic_Pay / $NoofDays;
$dayHra = $HRA_Amount / $NoofDays;
@@ -747,7 +747,7 @@ class Payslip extends BaseController
$TotalSalary = $value->TotalSalary;
$Days_worked = $value->Days_worked; // working day
$Sunday = $value->sunday_count; // Sunday count
- $LOP_Days = $value->NoofDays - ($Days_worked + $Sunday); // not working day
+ $LOP_Days = $value->NoofDays - ($Days_worked); // not working day
$Paid_leave = $value->Paid_leave; // leave day
if ($value->is_management_team == 1)
{
@@ -801,7 +801,7 @@ class Payslip extends BaseController
- $totalDaysWorked = ($Days_worked + $Sunday) + $Paid_leave;
+ $totalDaysWorked = $Days_worked + $Paid_leave;
$dayBasic = $Basic_Pay / $NoofDays;
$dayHra = $HRA_Amount / $NoofDays;
diff --git a/app/Controllers/User.php b/app/Controllers/User.php
index 94112de0..f25b7b0d 100755
--- a/app/Controllers/User.php
+++ b/app/Controllers/User.php
@@ -1385,8 +1385,12 @@ class User extends BaseController
}
$insert_count = 0;
$update_count = 0;
+ // dd($res2);
+
foreach ($res2 as $rs) {
$gst_no = $rs['gst_no'];
+ $customer_id = $rs['customer_id'];
+ $customer_name = $rs['customer_name'];
$invoice_number = $rs['invoice_number'];
$invoice_date = $rs['date'];
$status = $rs['status'];
@@ -1400,19 +1404,41 @@ class User extends BaseController
$invoice_time = $time_array[0];
$sql_invoice_chk = $Zohobook_model->ip_invoices($invoice_number, $invoice_date);
+ // dd($sql_invoice_chk);
if ($sql_invoice_chk <= 0) {
- $gst_sql = $Zohobook_model->ip_clients($gst_no);
- if ($gst_sql) {
- $client_id = $gst_sql[0]['client_id'];
- log_message('error', 'Data fetch success DB : ip_clients , client_id : ' . $client_id);
- } else {
- log_message('error', 'No data => Data fetch failed DB : ip_clients ' . $gst_no);
- $gst_no_data['client_tax_code'] = $gst_no;
- $gst_inserted_id = $Zohobook_model->customInsert($gst_no_data, 'ip_clients');
- $client_id = $gst_inserted_id;
- log_message('error', 'New Data Created : DB : ip_clients , client_id : ' . $client_id);
+ //this check only for ASHOK LEYLAND LIMITED
+ if($customer_id == '3215000000000082604' || $customer_id == '3215000000000082724')
+ {
+ //this combination of customer_id & gst_no search only for client ASHOK LEYLAND
+ $gst_sql = $Zohobook_model->ip_client_ashok_leyland($gst_no,$customer_id);
+ if ($gst_sql) {
+ $client_id = $gst_sql[0]['client_id'];
+ log_message('error', 'Data fetch success DB : ip_clients , client_id : ' . $client_id);
+ }
+
+ }else{
+
+ $gst_sql = $Zohobook_model->ip_clients($gst_no);
+ if ($gst_sql) {
+ $client_id = $gst_sql[0]['client_id'];
+ log_message('error', 'Data fetch success DB : ip_clients , client_id : ' . $client_id);
+ } else {
+ log_message('error', 'No data => Data fetch failed DB : ip_clients ' . $gst_no);
+ $client_data['client_tax_code'] = $gst_no;
+ $client_data['customer_id'] = $customer_id;
+ $client_data['customer_name'] = $customer_name;
+ $gst_inserted_id = $Zohobook_model->customInsert($client_data, 'ip_clients');
+ $client_id = $gst_inserted_id;
+ log_message('error', 'New Data Created : DB : ip_clients , client_id : ' . $client_id);
+ }
+
}
+
+
+
+
+
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
@@ -1517,6 +1543,7 @@ class User extends BaseController
$item_price = $rs['line_items'][$i]['rate'];
+ $hsn_or_sac = $rs['line_items'][$i]['hsn_or_sac'];
$item_order = $rs['line_items'][$i]['item_order'];
$item_product_unit = $rs['line_items'][$i]['unit'];
$item_name = $rs['line_items'][$i]['name'];
@@ -1595,6 +1622,8 @@ class User extends BaseController
$ip_invoice_items['item_product_unit'] = $item_product_unit;
$ip_invoice_items['Sgst_item_tax_rate_id'] = $sgsttaxid;
$ip_invoice_items['Cgst_item_tax_rate_id'] = $cgsttaxid;
+ $ip_invoice_items['hsn_or_sac'] = $hsn_or_sac;
+
$item_insert_id = $Zohobook_model->customInsert($ip_invoice_items, 'ip_invoice_items');
if ($item_insert_id)
log_message('error', 'Data insert success DB : ip_invoice_items => Sgst_item_tax_rate_id :' . $sgsttaxid);
diff --git a/app/Models/Inwardgateregister_model.php b/app/Models/Inwardgateregister_model.php
index 15551512..66c96781 100755
--- a/app/Models/Inwardgateregister_model.php
+++ b/app/Models/Inwardgateregister_model.php
@@ -221,15 +221,10 @@ class Inwardgateregister_model extends Model
}
public function igr_history($hsty_arr) {
- $this->db->transStart();
$builder = $this->db->table('t_igr_history');
$builder->insert($hsty_arr);
- $this->db->transComplete();
- if ($this->db->transStatus() === FALSE) {
- return false;
- } else {
- return $this->db->insertID();
- }
+
+ return $this->db->insertID(); // Return last inserted ID
}
function get_igr_history($col,$IGR,$IGRITEM = null)
@@ -1180,6 +1175,19 @@ class Inwardgateregister_model extends Model
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)
{
$query0 = $this->db->query("
diff --git a/app/Models/Zohobook_api_model.php b/app/Models/Zohobook_api_model.php
index e88e3d8a..7edb86bf 100755
--- a/app/Models/Zohobook_api_model.php
+++ b/app/Models/Zohobook_api_model.php
@@ -25,6 +25,16 @@ class Zohobook_api_model extends Model
return $query;
}
+ public function ip_client_ashok_leyland($gst_no,$customer_id)
+ {
+ $builder = $this->db->table('ip_clients')
+ ->where('client_tax_code', $gst_no)
+ ->where('customer_id', $customer_id)
+ ->get();
+ $query = $builder->getResultArray();
+ return $query;
+ }
+
public function ip_products($sku)
{
$builder = $this->db->table('ip_products')
diff --git a/app/Views/attendance.php b/app/Views/attendance.php
index a08b9030..a4c608f7 100755
--- a/app/Views/attendance.php
+++ b/app/Views/attendance.php
@@ -761,12 +761,6 @@ $(document).ready(function () {
var nextid = $(j).closest('td').next('td');
nxtid = nextid[0].attributes[2].value;
-
-
-
-
-
-
nxtvalue = v - 8;
curvalue = 8;
@@ -853,23 +847,27 @@ $(document).ready(function () {
if (str1 == 'W') {
- sundayValidation = false;
- let dateInt = +str3.replace(/\D/g, '');
- sundaysArray.forEach(element => {
- if (+element == dateInt) {
- sundayValidation = true;
- var text = value.textContent.trim();
- var current = (text === '' || isNaN(parseFloat(text))) ? 0 : parseFloat(value.textContent);
- sundayWorkingHr += current;
+ // sundayValidation = false;
+ // let dateInt = +str3.replace(/\D/g, '');
+ // sundaysArray.forEach(element => {
+ // if (+element == dateInt) {
+ // sundayValidation = true;
+ // var text = value.textContent.trim();
+ // var current = (text === '' || isNaN(parseFloat(text))) ? 0 : parseFloat(value.textContent);
+ // sundayWorkingHr += current;
- }
- });
+ // }
+ // });
- if (sundayValidation == false) {
- var text = value.textContent.trim();
- var current = (text === '' || isNaN(parseFloat(text))) ? 0 : parseFloat(value.textContent);
- totalworkingHrs += current;
- }
+ // if (sundayValidation == false) {
+ // var text = value.textContent.trim();
+ // var current = (text === '' || isNaN(parseFloat(text))) ? 0 : parseFloat(value.textContent);
+ // totalworkingHrs += current;
+ // }
+
+ var text = value.textContent.trim();
+ var current = (text === '' || isNaN(parseFloat(text))) ? 0 : parseFloat(value.textContent);
+ totalworkingHrs += current;
if (current == 0) {
absent++;
@@ -911,13 +909,13 @@ $(document).ready(function () {
// paidleave = 0;
// alert('else');
// }
- TotalOT = totalOTHrs + sundayWorkingHr;
- document.getElementById(totalhrsid).textContent = parseFloat(totalworkingHrs).toFixed(
- 2); // == ''?0:parseFloat(totalworkingHrs));
- document.getElementById(totalothrsid).textContent = parseFloat(TotalOT).toFixed(
- 2); // == ''?0:parseFloat(totalOTHrs));
+ // TotalOT = totalOTHrs + sundayWorkingHr;
+ TotalOT = totalOTHrs;
+ TotalWH = totalworkingHrs;
+ document.getElementById(totalhrsid).textContent = parseFloat(TotalWH).toFixed(2); // == ''?0:parseFloat(totalworkingHrs));
+ document.getElementById(totalothrsid).textContent = parseFloat(TotalOT).toFixed(2); // == ''?0:parseFloat(totalOTHrs));
document.getElementById(paidleaveid).textContent = parseFloat(publicholidays).toFixed(2);
- document.getElementById(daysworkedid).textContent = parseFloat((totalworkingHrs / 8)).toFixed(2);
+ document.getElementById(daysworkedid).textContent = parseFloat((TotalWH / 8)).toFixed(2);
absent = (absent) ? (absent - publicholidays) : 0;
document.getElementById(absentid).textContent = parseFloat(absent).toFixed(2);
}
diff --git a/app/Views/includes/new_header.php b/app/Views/includes/new_header.php
index f63bb69b..4ce942dc 100755
--- a/app/Views/includes/new_header.php
+++ b/app/Views/includes/new_header.php
@@ -120,15 +120,15 @@
}
::-webkit-scrollbar {
- width: 8px;
- height: 8px;
+ width: 10px;
+ height: 12px;
background-color: #f5f5f5;
}
::-webkit-scrollbar-thumb {
- background-color: #797a7c;
+ background-color: #aaa;
border-radius: 15px;
- height: 5px;
+ height: 12px;
}
::-webkit-scrollbar-track {
diff --git a/app/Views/inwardgateregister.php b/app/Views/inwardgateregister.php
index f5c09dd2..8798edd0 100755
--- a/app/Views/inwardgateregister.php
+++ b/app/Views/inwardgateregister.php
@@ -145,7 +145,7 @@
?>