From e7bfa010fb0368957b98501bd202225e3fb566c1 Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Fri, 28 Jun 2024 12:45:57 +0000 Subject: [PATCH] CHANGES_FiX : ps --- app/Controllers/Employeedetails.php | 2 - app/Controllers/Inwardgateregister.php | 300 ++++++++++++------------ app/Controllers/User.php | 4 +- app/Models/Inwardgateregister_model.php | 33 +-- app/Views/Report_pending_purchase.php | 4 +- app/Views/includes/header.php | 59 ++--- app/Views/inwardgateregister.php | 55 ++--- app/Views/viewIGRDetails.php | 37 ++- app/Views/viewinwardgateregister.php | 10 +- 9 files changed, 264 insertions(+), 240 deletions(-) diff --git a/app/Controllers/Employeedetails.php b/app/Controllers/Employeedetails.php index 23c5a6ff..8d5d33ba 100644 --- a/app/Controllers/Employeedetails.php +++ b/app/Controllers/Employeedetails.php @@ -50,9 +50,7 @@ class Employeedetails extends BaseController public function index() { $data['userRecords'] = $this->employeedetails_model->employeeListing(); - $this->global['pageTitle'] = 'Employee Listing'; - $this->loadViews("employeeListing", $this->global, $data, NULL); } diff --git a/app/Controllers/Inwardgateregister.php b/app/Controllers/Inwardgateregister.php index 59bfb2da..ba491704 100755 --- a/app/Controllers/Inwardgateregister.php +++ b/app/Controllers/Inwardgateregister.php @@ -291,6 +291,7 @@ class Inwardgateregister extends BaseController function addNewigr() { + #Step 1 IGR Details $PONO = $this->request->getPost('PONO'); $DeliveryChellanOrInvoiceNo = $this->request->getPost('InvoiceNo'); $DeliveryChellan = (string)$this->request->getPost('InvoiceDate'); @@ -298,170 +299,181 @@ class Inwardgateregister extends BaseController $Mat_Rcvd_Dt = (string)$this->request->getPost('MaterialRcvdDate'); $MaterialRcvdDt = get_date_time_format($Mat_Rcvd_Dt); $VehicleNo = $this->request->getPost('VehicleNo'); - $CourierNo = $this->request->getPost('CourierNo'); + $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 = IGR_CREATED; $document = null; - $igr = array(); + $igr = array(); // For IGR Master $paymentstatus = NO_PAIDIGR; $constant = $this->request->getPost('hideconstants'); - $arr = []; + $arr = []; // For File to Save $prefile = array(); + $fileupdated_count = 0; + $fileupdated_name = []; - - $igr = array('PONO' => $PONO, 'VehicleNo' => $VehicleNo, 'DeliveryChellanOrInvoiceNo' => $DeliveryChellanOrInvoiceNo, 'DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt, 'CourierNo' => $CourierNo, 'IGRStatus' => $IGRStatus, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt, 'PaymentStatus' => $paymentstatus); - $igrM = $this->inwardgateregister_model->addigrM($igr); - - $IGRNO = !empty($igrM) ? $igrM : ''; - // $IGRNO = "IGRNO02695"; - - 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."); - } - } - 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); - $this->inwardgateregister_model->fileupload($myfile); - } - } - } - - - $OGRStatus = IGR_CREATED; - $check_OGRPO = $this->inwardgateregister_model->update_OGR($PONO, $OGRStatus); - - - $IGRItemStatus = REQITEM_NEW; - $TotalPendingQty = ''; - $TotalPendingQty = (int)$TotalPendingQty; - - for ($i = 1; $i <= $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 = IGR_CREATED; - } 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); + $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)) { - $igrlineno = !empty($igrD) ? $igrD : ''; + $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; + } - $itemvalue = ''; - $SupplierId = ''; - $polineitemvalue = $this->inwardgateregister_model->getitemvalue($PONO, $MaterialCode); - - foreach ($polineitemvalue as $it) { - $itemvalue = $it->Rate; - $SupplierId = $it->SupplierID; + } 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)) { - $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; + $myfile = array('FilePath' => $filename, 'PONO' => $PONO, 'IGRNO' => $IGRNO); + $fileupdated = $this->inwardgateregister_model->fileupload($myfile); + if ($fileupdated) { + $fileupdated_count++; + $fileupdated_name[] = $filename; + } + } } } - - $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); - if ($TotalPendingQty == 0.00) { + #Step 3 Updating OGR Details + $OGRStatus = IGR_CREATED; + $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; - $Newstatus = array('Status' => IGR_CREATED); + if (strlen($QuantityAsPerInvoice) > 0 && $QuantityAsPerInvoice != '0') { + $Remarks = $this->request->getPost('txtRemarks' . $i); + $ItemStatus = ''; + if ($PendingQty == 0.00) { + $ItemStatus = IGR_CREATED; + } else { + $ItemStatus = POLINEITEM_IGRPARTIAL_CREATED; + } - $this->inwardgateregister_model->POLineItemsupdatestatus($PONO, $Newstatus); - $this->inwardgateregister_model->pomasterupdatestatus($PONO, $Newstatus); - } else { /*echo 'error' ;*/ - } - echo ""; - + $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' => IGR_CREATED); + $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 ViewIGR() { diff --git a/app/Controllers/User.php b/app/Controllers/User.php index 99515822..0b6acdee 100644 --- a/app/Controllers/User.php +++ b/app/Controllers/User.php @@ -998,7 +998,9 @@ class User extends BaseController $email = $this->request->getPost('MailID'); $SelectedDepartment = (string)$this->request->getPost('txtSelectedDepartment'); $comma_separated = explode(':', $SelectedDepartment); - + if(count($comma_separated)== 1 && in_array('DEP27', $comma_separated)){ + $roleId = '6'; + } $userInfo = [ 'email' => $email, 'EmpID' => $EmpID, diff --git a/app/Models/Inwardgateregister_model.php b/app/Models/Inwardgateregister_model.php index 698ee627..1858b1df 100755 --- a/app/Models/Inwardgateregister_model.php +++ b/app/Models/Inwardgateregister_model.php @@ -145,7 +145,7 @@ class Inwardgateregister_model extends Model { $builder = $this->db->table('T_PurchaseOrder_Master POM') - ->distinct()->select('POM.PONO,POM.ServiceDescription,POM.DeliveryDate,sup.SupplierName,sup.Address,POM.status,OGR_Status,POM.PODate,POM.IsOpenOrder') + ->distinct()->select('POM.PONO,POM.ServiceDescription,POM.DeliveryDate,sup.SupplierName,sup.Address,POM.status,OGR_Status,POM.PODate,POM.IsOpenOrder,POM.CreatedDate') ->select("IF(POM.PODate IS NOT NULL, DATE_FORMAT(POM.PODate, '%Y-%m-%d'), NULL) AS formatted_PODate") ->select("IF(POM.IsOpenOrder IS NULL OR POM.IsOpenOrder = '', 0, POM.IsOpenOrder) AS formatted_IsOpenOrder") ->join('T_PurchaseOrder_LineItem POL', 'POL.PONO = POM.PONO') @@ -157,7 +157,8 @@ class Inwardgateregister_model extends Model ->orWhere('POM.Status',IGR_CREATED) ->orWhere('POM.Status', MRIR_CREATED) ->orWhere('POM.Status', MRIR_APPROVED) - ->orWhere('POM.Status', OGR_COMPLETE); + ->orWhere('POM.Status', OGR_COMPLETE) + ->orderBy('POM.CreatedDate', 'desc'); $query = $builder->get(); $result = $query->getResult(); @@ -198,22 +199,26 @@ class Inwardgateregister_model extends Model function addigrM($igrM) { + $this->db->transStart(); - $builder = $this->db->table('T_IGR_Master'); - $builder->insert($igrM); - $aff_row = $this->db->affectedRows(); - $this->db->transComplete(); - // echo "ii" .$this->db->getLastQuery()->getQuery(); + $builder = $this->db->table('T_IGR_Master'); + $builder->insert($igrM); + $YesIAmAffected = $this->db->affectedRows(); + $this->db->transComplete(); - $result = $this->db->table('T_IGR_Master') - ->select('IGRNO') - ->orderBy('CreatedDate', 'desc') - ->get() - ->getRow(); + $result = []; + if ($YesIAmAffected > 0) { + $result = $this->db->table('T_IGR_Master') + ->select('IGRNO') + ->orderBy('CreatedDate', 'desc') + ->get() + ->getRow(); + // $result->IGRNO; + } - $igrno = ($aff_row && $result !== null) ? $result->IGRNO : 0; + $igrno = ($YesIAmAffected && !empty($result)) ? $result->IGRNO : ''; return $igrno; - } + } function addigrD($igrD) { diff --git a/app/Views/Report_pending_purchase.php b/app/Views/Report_pending_purchase.php index 326dd007..d1908b6b 100644 --- a/app/Views/Report_pending_purchase.php +++ b/app/Views/Report_pending_purchase.php @@ -181,8 +181,8 @@
- - +
+ diff --git a/app/Views/includes/header.php b/app/Views/includes/header.php index 13bbbff9..bf2f556d 100644 --- a/app/Views/includes/header.php +++ b/app/Views/includes/header.php @@ -262,7 +262,8 @@
PO No