From 873a206fa7059fc1d5bc8941d658b5d871b3bc6a Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Mon, 15 Jul 2024 03:07:34 +0000 Subject: [PATCH] FIX_IGR Draft Chnages --- app/Config/Constants.php | 1 + app/Config/Routes.php | 2 + app/Controllers/Inwardgateregister.php | 252 ++++++++++++++++- app/Models/Inwardgateregister_model.php | 14 +- app/Views/includes/header.php | 350 ++++++++++++++++++++++-- app/Views/inwardgateregister.php | 68 +++-- app/Views/viewIGRDetails.php | 208 ++++++++++++-- app/Views/viewinwardgateregister.php | 42 ++- 8 files changed, 852 insertions(+), 85 deletions(-) diff --git a/app/Config/Constants.php b/app/Config/Constants.php index 455424ae..a378fe33 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -143,6 +143,7 @@ define('REQ_DELIVERED','ST050'); /* IGR Status */ define('IGR_CREATED','ST027'); define('IGR_CLOSED','ST028'); +define('IGR_DRAFT','ST074'); define('IGR_CANCELLED','ST029'); define('POLINEITEM_IGRPARTIAL_CREATED','ST042'); diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 57adcfe2..01516e4f 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -259,6 +259,8 @@ $routes->post('inwardgateregister/ViewIGRfile', 'Inwardgateregister::ViewIGRfile $routes->post('inwardgateregister/ViewIGR', 'Inwardgateregister::ViewIGR'); $routes->post('inwardgateregister/edituploadfile', 'Inwardgateregister::edituploadfile'); $routes->post('inwardgateregister/addloadfile', 'Inwardgateregister::addloadfile'); +$routes->post('inwardgateregister/UpdateIGR', 'Inwardgateregister::UpdateIGR'); +$routes->post('inwardgateregister/updateIGRLineItem', 'Inwardgateregister::updateIGRLineItem'); // Application OGR Page $routes->match(['get', 'post', 'put', 'delete'],'AddOgr', 'Inwardgateregister::addoutwardgateregister'); diff --git a/app/Controllers/Inwardgateregister.php b/app/Controllers/Inwardgateregister.php index ba491704..d7ec8a1f 100755 --- a/app/Controllers/Inwardgateregister.php +++ b/app/Controllers/Inwardgateregister.php @@ -304,7 +304,8 @@ class Inwardgateregister extends BaseController $CreatedBy = $this->session->get('userId'); $RowCount = $this->request->getPost('txtRowCount'); $createddt = get_current_date_time(); - $IGRStatus = IGR_CREATED; + //$IGRStatus = IGR_CREATED;//old + $IGRStatus = (int)$this->request->getPost('hideIGRStatus') == 1 ? IGR_CREATED : IGR_DRAFT; $document = null; $igr = array(); // For IGR Master $paymentstatus = NO_PAIDIGR; @@ -376,7 +377,7 @@ class Inwardgateregister extends BaseController } #Step 3 Updating OGR Details - $OGRStatus = IGR_CREATED; + $OGRStatus = $IGRStatus; $check_OGRPO = $this->inwardgateregister_model->update_OGR($PONO, $OGRStatus); // echo "step3"; // echo "uuu".(int)$check_OGRPO; @@ -401,7 +402,7 @@ class Inwardgateregister extends BaseController $Remarks = $this->request->getPost('txtRemarks' . $i); $ItemStatus = ''; if ($PendingQty == 0.00) { - $ItemStatus = IGR_CREATED; + $ItemStatus = $IGRStatus; } else { $ItemStatus = POLINEITEM_IGRPARTIAL_CREATED; } @@ -446,7 +447,193 @@ class Inwardgateregister extends BaseController #Step 6 Updating Pending Quantity IN PO Master amd Line Item Details. if ($TotalPendingQty == 0.00) { - $Newstatus = array('Status' => IGR_CREATED); + $Newstatus = array('Status' => $IGRStatus); + $this->inwardgateregister_model->POLineItemsupdatestatus($PONO, $Newstatus); + $this->inwardgateregister_model->pomasterupdatestatus($PONO, $Newstatus); + } else { + /*echo 'error' ;*/ + } + #finally + $finalstatement = "Successfully Created IGR Number: $IGRNO \n"; + if ($fileupdated_count > 0) { + $finalstatement .= "Number of files updated: $fileupdated_count \n"; + $finalstatement .= "Files: \n " . implode('\n ', $fileupdated_name); + } else { + $finalstatement .= "No files to update"; + } + } else { + $finalstatement = 'No data available to process IGR.'; + } + + // Escape newlines and quotes for the JavaScript alert + $finalstatement = json_encode($finalstatement); + + +echo ""; + +} + +function addNewigr1() + { + #Step 1 IGR Details + $PONO = $this->request->getPost('PONO'); + $DeliveryChellanOrInvoiceNo = $this->request->getPost('InvoiceNo'); + $DeliveryChellan = (string)$this->request->getPost('InvoiceDate'); + $DeliveryChellanDate = get_date_time_format($DeliveryChellan); + $Mat_Rcvd_Dt = (string)$this->request->getPost('MaterialRcvdDate'); + $MaterialRcvdDt = get_date_time_format($Mat_Rcvd_Dt); + $VehicleNo = $this->request->getPost('VehicleNo'); + $DriverName = $this->request->getPost('DriverName'); + $DriverMobileNumber = $this->request->getPost('DriverMobileNumber'); + $CreatedBy = $this->session->get('userId'); + $RowCount = $this->request->getPost('txtRowCount'); + $createddt = get_current_date_time(); + $IGRStatus = (int)$this->request->getPost('hideIGRStatus') == 1 ? IGR_CREATED : IGR_DRAFT; + $document = null; + $igr = array(); // For IGR Master + $paymentstatus = NO_PAIDIGR; + $constant = $this->request->getPost('hideconstants'); + $arr = []; // For File to Save + $prefile = array(); + $fileupdated_count = 0; + $fileupdated_name = []; + + $igr = array('PONO' => $PONO, 'VehicleNo' => $VehicleNo, 'DeliveryChellanOrInvoiceNo' => $DeliveryChellanOrInvoiceNo, 'DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt, 'DriverName' => $DriverName, 'DriverMobileNumber' => $DriverMobileNumber,'IGRStatus' => $IGRStatus, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt, 'PaymentStatus' => $paymentstatus); + //Saving IGR details Here + $IGRNO = $this->inwardgateregister_model->addigrM($igr); + if($IGRNO){ + #Step 2 File Details Gathering + if($constant){ + for ($i = 1; $i <= $constant; $i++) { + $pathname = 'browseFiles' . $i; + $file = $this->request->getFile($pathname); + if ($file && $file->isValid()) { + $requestfilename = $file->getName(); + if (!empty($requestfilename)) { + + $files = str_replace(" ", "", $_FILES[$pathname]['name']); + $fcount = 0; + + foreach ($prefile as $value) { + if ($value == $files) { $fcount++; } + } + + if ($fcount == 0) { + if ($file->isValid() && !$file->hasMoved()) { + $path = ROOTPATH.'public/uploads/Igrfiles/'; + if(!is_dir($path)) { mkdir($path, 0777, true); } + $Picture = $file->getName(); + $file->move($path,$Picture); + log_message('error', "File new" . $i . " uploaded successfully. File name: " . $requestfilename); + } + $arr[] = array($Picture); + } + + $prefile[] = $files; + } + + } else { + log_message('error', "No file uploaded for new" . $i . " or there was an error uploading the file."); + } + } + #Step 2.1 Saving File Details + if (!empty($arr)) { + foreach ($arr as $ma) { + $index = 0; + foreach ($ma as $key => $value) { + $index++; + if ($index == 1) { + $filename = $value; + } + } + if (!empty($filename)) { + + $myfile = array('FilePath' => $filename, 'PONO' => $PONO, 'IGRNO' => $IGRNO); + $fileupdated = $this->inwardgateregister_model->fileupload($myfile); + if ($fileupdated) { + $fileupdated_count++; + $fileupdated_name[] = $filename; + } + } + } + } + } + + #Step 3 Updating OGR Details + $OGRStatus = $IGRStatus; + $check_OGRPO = $this->inwardgateregister_model->update_OGR($PONO, $OGRStatus); + // echo "step3"; + // echo "uuu".(int)$check_OGRPO; + $IGRItemStatus = REQITEM_NEW; + $TotalPendingQty = ''; + $TotalPendingQty = (int)$TotalPendingQty; + // echo "step4"; + #Step 4 To Update the Date PO MASTER , Material Master , Historydetails and IGR line Item Details Updating OGR Details + for ($i = 1; $i <= (int)$RowCount; $i++) { + $MaterialCode = $this->request->getPost('MaterialCode' . $i); + $MaterialCode = $MaterialCode !== null && is_string($MaterialCode) ? trim($MaterialCode) : null; + $QuantityAsPerInvoice = $this->request->getPost('txtQuantityAsPerInvoice' . $i); + $QuantityAsPerInvoice = $QuantityAsPerInvoice !== null && is_string($QuantityAsPerInvoice) ? trim($QuantityAsPerInvoice) : null; + $OrderedQuantity = $this->request->getPost('OrderedQuantity' . $i); + $OrderedQuantity = $OrderedQuantity !== null && is_string($OrderedQuantity) ? trim($OrderedQuantity) : null; + $ReceivedQty = $this->request->getPost('txtReceivedQuantity' . $i); + $ReceivedQty = $ReceivedQty !== null && is_string($ReceivedQty) ? trim($ReceivedQty) : null; + $PendingQty = $this->request->getPost('txtPendingQty' . $i); + $TotalPendingQty = $TotalPendingQty + $PendingQty; + + if (strlen($QuantityAsPerInvoice) > 0 && $QuantityAsPerInvoice != '0') { + $Remarks = $this->request->getPost('txtRemarks' . $i); + $ItemStatus = ''; + if ($PendingQty == 0.00) { + $ItemStatus = $IGRStatus; + } else { + $ItemStatus = POLINEITEM_IGRPARTIAL_CREATED; + } + + $CreatedBy = $this->session->get('userId'); + $igrDetails = array('IGRNO' => $IGRNO, 'MaterialCode' => $MaterialCode, 'QuantityAsPerInvoice' => $QuantityAsPerInvoice, 'Remarks' => $Remarks, 'IGRItemStatus' => $IGRItemStatus, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt); + $igrD = $this->inwardgateregister_model->addigrD($igrDetails); + $igrlineno = !empty($igrD) ? $igrD : ''; + $itemvalue = ''; + $SupplierId = ''; + $polineitemvalue = $this->inwardgateregister_model->getitemvalue($PONO, $MaterialCode); + foreach ($polineitemvalue as $it) { + $itemvalue = $it->Rate; + $SupplierId = $it->SupplierID; + } + $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); + $get_pre_qty = $this->inwardgateregister_model->get_CurrentQty($MaterialCode); + $av_qty = 0; + if (!empty($get_pre_qty)) { + foreach ($get_pre_qty as $gt) { + $av_qty = $gt->Current_stock; + } + } + $currentav_qty = $QuantityAsPerInvoice + $av_qty; + $current_qty = array('Current_stock' => $currentav_qty); + $this->inwardgateregister_model->addmaterialmaster($current_qty, $MaterialCode); + $Recqty = $this->inwardgateregister_model->getPOLineItemReceivedQty($PONO, $MaterialCode); + $ReceivedQuantity = 0.00; + if (count($Recqty) > 0) { + foreach ($Recqty as $key) { + $ReceivedQuantity = $key->ReceivedQuantity; + } + } + $totalReceivedqty = $ReceivedQuantity + $QuantityAsPerInvoice; + $POLineItem = array('ReceivedQuantity' => $totalReceivedqty, 'Status' => $ItemStatus, 'UpdateBY' => $CreatedBy, 'UpdatedOn' => $createddt); + $this->inwardgateregister_model->UpdatePOLineItem($POLineItem, $PONO, $MaterialCode); + } + } + + $this->inwardgateregister_model->UpdatePOMaster($PONO, $CreatedBy); + + #Step 6 Updating Pending Quantity IN PO Master amd Line Item Details. + if ($TotalPendingQty == 0.00) { + $Newstatus = array('Status' => $IGRStatus); $this->inwardgateregister_model->POLineItemsupdatestatus($PONO, $Newstatus); $this->inwardgateregister_model->pomasterupdatestatus($PONO, $Newstatus); } else { @@ -508,11 +695,7 @@ echo " + + + + + \ No newline at end of file diff --git a/app/Views/viewinwardgateregister.php b/app/Views/viewinwardgateregister.php index 9894b258..52364eaf 100644 --- a/app/Views/viewinwardgateregister.php +++ b/app/Views/viewinwardgateregister.php @@ -156,8 +156,13 @@ ?>
- - + + + + +
+ 'PurchaseOrderNumber','value' => set_value('PurchaseOrderNumber'),'id'=>'PONo', 'class' => 'form-control', 'required=>"true"' , 'readonly'=>'true' ); echo form_input($data); @@ -196,6 +201,30 @@ ?> +
+
+ + 'VehicleNo','value' => set_value('VehicleNo'),'id'=>'Vehicle_No', 'class' => 'form-control', 'required=>"true"' , 'readonly'=>'true' ); + echo form_input($data); + ?> +
+
+ + 'DriverName','value' => set_value('DriverName'),'id'=>'Driver_Name', 'class' => 'form-control', 'required=>"true"' , 'readonly'=>'true' ); + + echo form_input($data); + ?> +
+
+ + 'DriverMobileNumber','value' => set_value('DriverMobileNumber'),'id'=>'DriverMobileNumber', 'class' => 'form-control' , 'readonly'=>'true' ); + echo form_input($data); + ?> +
+
@@ -209,6 +238,7 @@ UOM Ordred Quantity Received Quantity + Balance Quantity Remarks @@ -268,7 +298,15 @@ $("#Igrshow").on("shown.bs.modal", function(e) { { $("#IGRNO1").val(item.IGRNO); + var baseUrl = 'purchaseorder/CreatePOPrint'; + var newUrl = baseUrl + '?PONO=' + item.PONO + '&ReqType=' + item.POType; + $('#printLink').attr('href', newUrl); //alert(item.IGRNO); + + $("#Vehicle_No").val(item.VehicleNo); + $("#Driver_Name").val(item.DriverName); + $("#DriverMobileNumber").val(item.DriverMobileNumber); + $("#IGRStatus").val(item.IGRStatus); $("#PONo").val(item.PONO); $("#Supplier").val(item.SupplierName); $("#Add1").val(item.Address);