diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 40536921..dc80c492 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -322,6 +322,7 @@ $routes->post('ViewIGRDetails', 'Inwardgateregister::viewIGRDetails'); $routes->post('GetIGRLineItemDetails', 'Inwardgateregister::getIGRLineItemDetails'); $routes->post('SaveIGR', 'Inwardgateregister::SaveIGR');// Save IGR PAGE - Working $routes->post('UpdateIGR', 'Inwardgateregister::UpdateIGR'); +$routes->post('CancelIGR', 'Inwardgateregister::CancelIGR'); $routes->post('updateIGRWeight', 'Inwardgateregister::updateIGRWeight'); $routes->post('ViewIGRHistory', 'Inwardgateregister::ViewIGRHistory'); $routes->post('getCostCenterData', 'Inwardgateregister::getCostCenterData'); diff --git a/app/Controllers/Inwardgateregister.php b/app/Controllers/Inwardgateregister.php index fd4f21e9..abdc571f 100755 --- a/app/Controllers/Inwardgateregister.php +++ b/app/Controllers/Inwardgateregister.php @@ -611,14 +611,8 @@ class Inwardgateregister extends BaseController } } $totalReceivedqty = (int)$IsThisOpenOrderPO == 1 ? 0 : (int)$ReceivedQuantity + (int)$QuantityAsPerInvoice ; - // $totalReceivedqty = $ReceivedQuantity + $QuantityAsPerInvoice; - if(((int)$totalReceivedqty > 0) && ((int)$IsThisOpenOrderPO != 1)){ - $POLineItem = array('ReceivedQuantity' => $totalReceivedqty, 'Status' => $ItemStatus, 'UpdateBY' => $CreatedBy, 'UpdatedOn' => $createddt); - $this->inwardgateregister_model->UpdatePOLineItem($POLineItem, $PONO, $MaterialCode); - }else if((int)$IsThisOpenOrderPO == 1){ - $POLineItem = array('ReceivedQuantity' => $totalReceivedqty, 'Status' => $ItemStatus, 'UpdateBY' => $CreatedBy, 'UpdatedOn' => $createddt); - $this->inwardgateregister_model->UpdatePOLineItem($POLineItem, $PONO, $MaterialCode); - } + $POLineItem = array('ReceivedQuantity' => $totalReceivedqty, 'Status' => $ItemStatus, 'UpdateBY' => $CreatedBy, 'UpdatedOn' => $createddt); + $this->inwardgateregister_model->UpdatePOLineItem($POLineItem, $PONO, $MaterialCode); } } $this->inwardgateregister_model->UpdatePOMaster($PONO, $CreatedBy,$IGRStatus); @@ -630,7 +624,7 @@ class Inwardgateregister extends BaseController $this->inwardgateregister_model->POLineItemsupdatestatus($PONO, $Newstatus); $this->inwardgateregister_model->pomasterupdatestatus($PONO, $Newstatus); } else { - /*echo 'error' ;*/ + /*echo 'Open Order PO' ;*/ }} #finally $finalstatement = "Successfully Created IGR Number: $IGRNO \n"; @@ -799,6 +793,8 @@ function viewIGRDetails() function UpdateIGR() { + + # Step 1 : Gethering Data.. $IGRNo = $this->request->getPost('igr'); $PONo = $this->request->getPost('po'); @@ -817,22 +813,27 @@ function viewIGRDetails() $IGRStatus = (int)$this->request->getPost('status') == 1 ? IGR_CREATED : IGR_DRAFT; + # Here decode the tableData for IGRLineitem $tableData = $this->request->getPost('tableData'); if (is_string($tableData)) { $tableData = json_decode($tableData, true); } + $updateby = $this->session->get('userId'); + # path for file not available means create it $path = ROOTPATH.'public/uploads/Igrfiles/'; 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,'Remark'=>$MasterRemarks); + # master file $MasterFile = $this->request->getfile('MasterFile'); $fileupdated_count = 0; $fileupdated_name = []; + # file move to dest. path if (!empty($MasterFile)) { $requestMasterFileName = $MasterFile->getName(); if ($MasterFile && $MasterFile->isValid() && !$MasterFile->hasMoved()) { @@ -848,10 +849,12 @@ function viewIGRDetails() } } + # multiple file $fileNames = $this->request->getPost('file_name'); $files = $this->request->getFileMultiple('emp_file'); + # save and move the multiple file if(isset($files)) { foreach ($files as $index => $file) { @@ -877,17 +880,22 @@ function viewIGRDetails() } } } - + + # Step 2 : inserting IGR History $this->saveIGRMasterHistory($igrarr,$IGRNo); $getigrstatus = $this->inwardgateregister_model->getigrstatus($IGRNo); $getigrstatus = $getigrstatus->IGRStatus; - $updateigrmaster = $this->inwardgateregister_model->updateigr($igrarr, $IGRNo); + # Step 3 : Updating IGR master + $updateigrmaster = $this->inwardgateregister_model->updateigr($igrarr, $IGRNo); log_message('error', "Master updated successfully: " . $updateigrmaster); + + # Step 4 : loop starts here for IGRlineitem to save if(!empty($tableData )){ foreach ($tableData as $row) { - $quantityAsPerInvoice = $row['QuantityAsPerInvoice']; + $MaterialCode = $row['MaterialCode']; + $quantityAsPerInvoice = $row['QuantityAsPerInvoice']; // is also known as inward quantity $remarks = $row['Remarks']; $grossWeight = $row['GrossWeight']; $grossWeightDate = $row['GrossWeightDate']; @@ -898,6 +906,7 @@ function viewIGRDetails() $GrossWtDt = !empty($grossWeightDate) && strtolower($grossWeightDate) !== 'null' ? get_date_time_format($grossWeightDate) : NULL; $TareWtDt = !empty($tareWeightDate) && strtolower($tareWeightDate) !== 'null' ? get_date_time_format($tareWeightDate) : NULL; + # Step 4.0 : IGR Lineitem And History Array Formation $igrline = array( 'QuantityAsPerInvoice' => $quantityAsPerInvoice, 'Remarks' => $remarks, @@ -909,7 +918,11 @@ function viewIGRDetails() 'IGRItemNo' => $igrItemNo, 'UpdateBY' => $updateby ); + + # Step 4.1 : Save IGRlineitem History $this->saveIGRLineitemHistory($igrline, $IGRNo,$igrItemNo); + + # Step 4.2 : Netweight File Details // $WeightFile = $this->request->getfile('WeightFile'); // $requestWeightFileName = $WeightFile->getName(); @@ -925,6 +938,27 @@ function viewIGRDetails() // } // } + + # Step 4.3 : IGRlineitem affectedRow have value and MaterialCode have value means + # : updated the polineitem Qty + $OldQuantityAsPerInvoice = $this->inwardgateregister_model->getOldIgrReceivedQty($IGRNo, $igrItemNo,$MaterialCode); + + if ($MaterialCode != '' && ((int)$quantityAsPerInvoice != (int)$OldQuantityAsPerInvoice)) { + + $PolineitemQty = $this->inwardgateregister_model->getPOLineItemReceivedQty($PONo, $MaterialCode); + $POReceivedQuantity = 0.00; + if (count($PolineitemQty) > 0) { + foreach ($PolineitemQty as $key) { + $POReceivedQuantity = $key->ReceivedQuantity; + } + } + + $totalReceivedqty = ($POReceivedQuantity - $OldQuantityAsPerInvoice) + $quantityAsPerInvoice; + $POLineItem = array('ReceivedQuantity' => $totalReceivedqty); + $this->inwardgateregister_model->UpdatePOLineItem($POLineItem, $PONo, $MaterialCode); + } + + # Step 4.3 : Updating IGRlineitem $updateigrlineitem = $this->inwardgateregister_model->updateIGRLineItem($igrline, $igrItemNo); log_message('error', "lineitem updated successfully: " . $updateigrlineitem); log_message('error', 'UpdateIGR updateigrlineitem: ' . json_encode($igrline)); @@ -933,6 +967,10 @@ function viewIGRDetails() } + + # Step 5 : Mail Information + # : System Admin means send a mail to Accounts (role-id 1 -> 2 ) + # : Account means send a mail to System Admin (role-id 2 -> 1 ) if ($getigrstatus == 'ST027' && ($updateigrmaster > 0 || $updateigrlineitem > 0)) { if(session()->get('roleText') == 'System Administrator') // id is 1 @@ -1037,6 +1075,7 @@ function viewIGRDetails() } } + # Step 6 : Confimation alert message if ($updateigrmaster > 0) { $finalstatement = "Successfully Updated IGR Number: $IGRNo \n"; } else if($updateigrlineitem >0){ @@ -1045,6 +1084,7 @@ function viewIGRDetails() $finalstatement = "IGR Number: $IGRNo \n"; } + # Step 6.1 : Display the file names along with Confimation alert message if ($fileupdated_count > 0) { $finalstatement .= "Number of files updated: $fileupdated_count \n"; // $finalstatement .= "Files: \n" . implode(PHP_EOL, $fileupdated_name); @@ -1056,6 +1096,76 @@ function viewIGRDetails() echo $finalstatement; } + function CancelIGR(){ + + # Step 1 : Gethering Data.. + $IGRNo = $this->request->getPost('igr'); + $PONo = $this->request->getPost('po'); + $IGRStatus = IGR_CANCELLED; + $updateby = $this->session->get('userId'); + $igrarr = array('IGRStatus' => $IGRStatus,'UpdateBY' => $updateby); + + # Step 2 : Here decode the tableData for IGRLineitem + $tableData = $this->request->getPost('tableData'); + if (is_string($tableData)) { + $tableData = json_decode($tableData, true); + } + + # Step 3 : inserting IGR History + $this->saveIGRMasterHistory(array('IGRStatus' => $IGRStatus),$IGRNo); + + # Step 4 : Updating IGR master + $updateigrmaster = $this->inwardgateregister_model->updateigr($igrarr, $IGRNo); + + # Step 5 : loop starts here for IGRlineitem to save + if(!empty($tableData )){ + + foreach ($tableData as $row) { + $MaterialCode = $row['MaterialCode']; + $quantityAsPerInvoice = $row['QuantityAsPerInvoice']; // is also known as inward quantity + $igrItemNo = $row['IGRItemNo']; + + # Step 5.0 : IGR Lineitem And History Array Formation + $igrline = array( + 'QuantityAsPerInvoice' => 0, + 'UpdateBY' => $updateby, + 'mIGRStatus' => IGR_CANCELLED + ); + + # Step 5.1 : Save IGRlineitem History + $this->saveIGRLineitemHistory(array('QuantityAsPerInvoice'=>0,'mIGRStatus' => $IGRStatus), $IGRNo,$igrItemNo); + + # Step 5.2 : IGRlineitem affectedRow have value and MaterialCode have value means + # : updated the polineitem Qty + $oldQuantityAsPerInvoice = $this->inwardgateregister_model->getOldIgrReceivedQty($IGRNo, $igrItemNo,$MaterialCode); + if ($MaterialCode != '') { + + $PolineitemQty = $this->inwardgateregister_model->getPOLineItemReceivedQty($PONo, $MaterialCode); + $ReceivedQuantity = 0.00; + if (count($PolineitemQty) > 0) { + foreach ($PolineitemQty as $key) { + $ReceivedQuantity = $key->ReceivedQuantity; + } + } + + $totalReceivedqty = ($ReceivedQuantity-$quantityAsPerInvoice); + $POLineItem = array('ReceivedQuantity' => ($totalReceivedqty > 0) ? $totalReceivedqty : 0 ); + $this->inwardgateregister_model->UpdatePOLineItem($POLineItem, $PONo, $MaterialCode); + } + + # Step 5.3 : Updating IGRlineitem + $updateigrlineitem = $this->inwardgateregister_model->updateIGRLineItem($igrline, $igrItemNo); + log_message('error', "lineitem updated successfully: " . $updateigrlineitem); + log_message('error', 'UpdateIGR updateigrlineitem: ' . json_encode($igrline)); + + } + + } + + echo "Successfully Cancelled IGR Number: $IGRNo \n"; + + } + function updateIGRWeight(){ diff --git a/app/Controllers/Purchaseorder.php b/app/Controllers/Purchaseorder.php index c1d1223f..5471d62d 100755 --- a/app/Controllers/Purchaseorder.php +++ b/app/Controllers/Purchaseorder.php @@ -2595,7 +2595,8 @@ class Purchaseorder extends BaseController $store = array('Status' => $StatusCode, 'ApprovedOn' => $ApprovedDate, 'Approvedby' => $ApprovedBy, 'Remarks' => $Remarks); $this->purchaseorder_model->UpdatePO($store, $PONO); - echo "Successfully Approve the Purchase Order No: " . $PONO; + // echo "Successfully Approve the Purchase Order No: " . $PONO; + echo "The Purchase Order No: " . $PONO . " is Approved"; } else { $store = array('Status' => $StatusCode, 'OnHoldOn' => $ApprovedDate, 'OnHoldBy' => $ApprovedBy, 'Remarks' => $Remarks); $this->purchaseorder_model->UpdatePO($store, $PONO); @@ -2662,11 +2663,11 @@ class Purchaseorder extends BaseController $store = array('Status' => $StatusCode, 'ReleasedOn' => $ReleasedDate, 'ReleasedBy' => $ReleasedBy, 'Remarks' => $Remarks); $this->purchaseorder_model->UpdatePO($store, $PONO); // echo "Successfully Released the Purchase Order No: " . $PONO; - echo "The Purchase Order No: " . $PONO . "is Approved"; + echo "The Purchase Order No: " . $PONO . " is Approved"; } else { $store = array('Status' => $StatusCode, 'OnHoldOn' => $ReleasedDate, 'OnHoldBy' => $ReleasedBy, 'Remarks' => $Remarks); $this->purchaseorder_model->UpdatePO($store, $PONO); - echo "The Purchase Order No: " . $PONO . "is On Hold"; + echo "The Purchase Order No: " . $PONO . " is On Hold"; } } /* Add capital Po*/ diff --git a/app/Models/Inwardgateregister_model.php b/app/Models/Inwardgateregister_model.php index c751e1d6..db07f673 100755 --- a/app/Models/Inwardgateregister_model.php +++ b/app/Models/Inwardgateregister_model.php @@ -571,7 +571,7 @@ class Inwardgateregister_model extends Model MM.MaterialName,MM.UOM,MM.HSNCODE, sup.Address,sup.SupplierName, POL.Rate, - POM.ServiceDescription,POL.Quantity,POM.POType,POM.IsOpenOrder, + POM.ServiceDescription,POL.Quantity, (POL.Quantity - POL.ReceivedQuantity) as POPendingQty, POM.POType,POM.IsOpenOrder, POM.CapitalRange,POM.CapitalRange, st.CGST as service_cgst,st.SGST as service_sgst,st.IGST as service_igst, it.IGST as import_igst, @@ -721,6 +721,19 @@ class Inwardgateregister_model extends Model return $result; } + function getOldIgrReceivedQty($IGRitemNo,$IGR,$MaterialCode){ + $builder = $this->db->table('t_igr_details') + ->select('QuantityAsPerInvoice') + ->where('IGRItemNo', $IGRitemNo) + ->where('MaterialCode', $MaterialCode) + ->where('IGRNO', $IGR); + + $query = $builder->get()->getRow(); + + $QuantityAsPerInvoice = $query ? $query->QuantityAsPerInvoice : 0; + return $QuantityAsPerInvoice; + } + function GetMRIROutQty($MRIRNO, $MaterialCode) { @@ -1085,6 +1098,19 @@ class Inwardgateregister_model extends Model $r = $this->db->affectedRows(); return $r; } + function getQuantityAsPerInvoice($IGR,$IGRitemNo,$itemCode){ + $builder = $this->db->table('t_igr_details') + ->select('QuantityAsPerInvoice') + ->where('IGRItemNo', $IGRitemNo) + ->where('IGRItemNo', $itemCode) + ->where('IGRNO', $IGR); + + $query = $builder->get()->getRow(); + + $QuantityAsPerInvoice = $query ? $query->QuantityAsPerInvoice : 0; + return $QuantityAsPerInvoice; + + } function getpolineqty($NewPO) { $builder = $this->db->table('t_purchaseorder_lineitem') diff --git a/app/Views/EditservicePurchaseorder.php b/app/Views/EditservicePurchaseorder.php index a75ecd90..bc616aca 100755 --- a/app/Views/EditservicePurchaseorder.php +++ b/app/Views/EditservicePurchaseorder.php @@ -1399,11 +1399,15 @@ if (!empty($getlogpodtl)) { - + + + -     + +     + @@ -2701,9 +2705,9 @@ if (!empty($getlogpodtl)) { ${basicval} ${TotalTaxValue} ${TotalOrderValue} - + - + diff --git a/app/Views/accountsDashboard.php b/app/Views/accountsDashboard.php index c2ebacde..486668e5 100644 --- a/app/Views/accountsDashboard.php +++ b/app/Views/accountsDashboard.php @@ -496,6 +496,7 @@