From f51aa8541e83bf56c594b141ff0b0950bc94599c Mon Sep 17 00:00:00 2001 From: vadivel J Date: Thu, 24 Oct 2024 17:58:48 +0530 Subject: [PATCH] worked on changes in purchase module --- app/Controllers/Amendmentpurchaseorder.php | 33 +++--- app/Controllers/Inwardgateregister.php | 126 +++++++++++---------- app/Models/Purchaseorder_model.php | 4 - app/Views/AmendPOlist.php | 4 +- app/Views/expense_list.php | 18 +-- app/Views/porelease_view.php | 4 +- app/Views/viewinwardgateregister.php | 3 + 7 files changed, 97 insertions(+), 95 deletions(-) diff --git a/app/Controllers/Amendmentpurchaseorder.php b/app/Controllers/Amendmentpurchaseorder.php index cecd2007..b5c5c667 100755 --- a/app/Controllers/Amendmentpurchaseorder.php +++ b/app/Controllers/Amendmentpurchaseorder.php @@ -42,23 +42,23 @@ class Amendmentpurchaseorder extends BaseController { - if ($this->request->getMethod() === 'GET') - { - $currentYear = date('Y'); - $currentMonth = date('m'); + if ($this->request->getMethod() === 'GET') + { + $currentYear = date('Y'); + $currentMonth = date('m'); $startOfMonth = "$currentYear-$currentMonth-01"; $endOfMonth = date('Y-m-t'); - $fromDate = $startOfMonth; - $toDate = $endOfMonth; - } elseif ($this->request->getMethod() === 'POST') { - $fromDate = $this->request->getPost('fromDate'); - $toDate = $this->request->getPost('toDate'); + $fromDate = $startOfMonth; + $toDate = $endOfMonth; + } elseif ($this->request->getMethod() === 'POST') { + $fromDate = $this->request->getPost('fromDate'); + $toDate = $this->request->getPost('toDate'); $fromDate = date('Y-m-d', strtotime($fromDate)); $toDate = date('Y-m-d', strtotime($toDate)); } // $this->load->library('pagination'); - $forwhat = 'amendment'; + $forwhat = 'amendment'; $data['POData'] = $this->purchaseorder_model->purchaseorderListing($forwhat,$fromDate,$toDate); $data['fromDate'] = date('d-m-Y', strtotime($fromDate)); @@ -1340,8 +1340,6 @@ class Amendmentpurchaseorder extends BaseController $createddt = get_current_date_time(); $updateddt = get_current_date_time(); - - $PaymentTerms = $this->request->getPost('PaymentTerms'); $beforePaymentTerms = $this->request->getPost('beforePaymentterms'); @@ -1410,20 +1408,17 @@ class Amendmentpurchaseorder extends BaseController } $LastPO = $this->purchaseorder_model->addAmendPOMaster($POMaster, $CreateBy, $PONO); $NewPO = ''; - // if (count($LastPO) > 0) { - // $NewPO = $LastPO[0]['PONO']; - // } - // print_r($LastPO);die; + foreach ($LastPO as $PO) : $NewPO = $PO['PONO']; endforeach; $PODetail = array('Status' => PO_AMENDED); //TO SET PARENT PO AS AMENDMENT STATUS - $APO = $this->purchaseorder_model->updateAmendPOMaster($PONO, $PODetail); + $APO = $this->purchaseorder_model->updateAmendPOMaster($PONO, $PODetail); - $LineItemStatus = REQITEM_NEW; + $LineItemStatus = REQITEM_NEW; - $igrvalue = $this->purchaseorder_model->selectigrmaster($PONO); + $igrvalue = $this->purchaseorder_model->selectigrmaster($PONO); $po = ''; $igrno = ''; diff --git a/app/Controllers/Inwardgateregister.php b/app/Controllers/Inwardgateregister.php index ac329ca6..80ab9aca 100755 --- a/app/Controllers/Inwardgateregister.php +++ b/app/Controllers/Inwardgateregister.php @@ -1670,64 +1670,72 @@ function updateIGRWeight(){ } public function downloadFilesAsZip($igrno) -{ - // Get all file details for the given IGR number - $fileDetails = $this->inwardgateregister_model->getAllIgrFileDetails($igrno); - if (empty($fileDetails)) { - // Display an alert message - echo ''; - redirect('ViewIGR', 'refresh'); - return; - } - - // Define the root path for files - $rootPath = ROOTPATH . 'public/uploads/Igrfiles/'; - - // Create a new ZIP archive - $zip = new ZipArchive(); - - // Define the name of the ZIP file - $zipFileName = $igrno . '.zip'; - $zipFilePath = $rootPath . $zipFileName; - - if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) { - $filesAdded = false; - - // Add each file to the ZIP archive - foreach ($fileDetails as $file) { - $filePath = $rootPath . $file->file; - if (file_exists($filePath)) { - if (!$zip->addFile($filePath, $file->filename)) { - // Handle error when adding file to ZIP - echo ''; - $zip->close(); - redirect('ViewIGR', 'refresh'); - return; - } - $filesAdded = true; - } - } - - // Close the ZIP archive - $zip->close(); - - if ($filesAdded) { - // Return the ZIP file as a download - return $this->response->download($zipFilePath, null)->setFileName($zipFileName); - } else { - // Delete the empty ZIP file - if (file_exists($zipFilePath)) { - unlink($zipFilePath); - } - echo ''; - redirect('ViewIGR', 'refresh'); - return; - } - } else { - echo ''; - redirect('ViewIGR', 'refresh'); - return; - } -} + { + // Get all file details for the given IGR number + $fileDetails = $this->inwardgateregister_model->getAllIgrFileDetails($igrno); + if (empty($fileDetails)) { + echo ''; + redirect('ViewIGR', 'refresh'); + return; + } + + // Define the root path for files + $rootPath = ROOTPATH . 'public/uploads/Igrfiles/'; + + // Check if root path is valid + if (!is_dir($rootPath)) { + echo ''; + return; + } + + // Create a new ZIP archive + $zip = new ZipArchive(); + $zipFileName = $igrno . '.zip'; + $zipFilePath = $rootPath . $zipFileName; + + if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) { + $filesAdded = false; + + // Add each file to the ZIP archive + foreach ($fileDetails as $file) { + $filePath = $rootPath . $file->file; + + // Check if file exists + if (!file_exists($filePath)) { + log_message('error', 'File not found: ' . $filePath); + continue; + } + + $sanitizedFilename = preg_replace('/[^a-zA-Z0-9_\-\.]/', '_', $file->filename); + + if (!$zip->addFile($filePath, $sanitizedFilename)) { + log_message('error', 'Failed to add file: ' . $sanitizedFilename); + $zip->close(); + redirect('ViewIGR', 'refresh'); + return; + } + $filesAdded = true; + } + + // Close the ZIP archive + $zip->close(); + + if ($filesAdded) { + return $this->response->download($zipFilePath, null)->setFileName($zipFileName); + } else { + if (file_exists($zipFilePath)) { + unlink($zipFilePath); + } + echo ''; + redirect('ViewIGR', 'refresh'); + return; + } + } else { + echo ''; + redirect('ViewIGR', 'refresh'); + return; + } + } + } \ No newline at end of file diff --git a/app/Models/Purchaseorder_model.php b/app/Models/Purchaseorder_model.php index 47e86528..b043b4ed 100755 --- a/app/Models/Purchaseorder_model.php +++ b/app/Models/Purchaseorder_model.php @@ -389,8 +389,6 @@ mstr.CourierNo,pom.Status,pom.POType') //,bill.BillNo,bill.FilePath, function purchaseorderListing($forwhat ,$fromDate='',$toDate='') { - - $builder = $this->db->table('t_purchaseorder_master POMast')->distinct() ->select('POMast.PONO,POMast.CreatedDate,supp.SupplierName,TotalOrderValue,PODate,Stat.StatusName,Stat.StatusCode,POMast.POType as ReqType,DeliveryDate,DeliverySchedule,DeliveryOption,POMast.CapitalRange') @@ -1595,8 +1593,6 @@ mstr.CourierNo,pom.Status,pom.POType') //,bill.BillNo,bill.FilePath, function getPOList($type, $fromDate , $toDate) { - - $builder = $this->db->table('t_purchaseorder_master mast')->distinct() ->select('mast.PODate,mast.PONO,mast.TotalOrderValue,st.StatusCode,st.StatusName,emp.FirstName,mast.CreatedDate,ccm.CostCenterName,ccm.CostCenterCode,mast.POType as RType,mast.Remarks,DepartmentName,mast.ApprovedBy,(select EmpID from tbl_users where userId=mast.ApprovedBy )as EID,rmast.ReqType,mast.Status,mast.CapitalRange, (select FirstName from t_employee_details where EmpID=EID)as Approver,sup.SupplierName,sup.MSME') diff --git a/app/Views/AmendPOlist.php b/app/Views/AmendPOlist.php index 48768bd1..75d4758f 100755 --- a/app/Views/AmendPOlist.php +++ b/app/Views/AmendPOlist.php @@ -110,7 +110,7 @@ - PO Date + Created Date PONO PO Type Supplier Name @@ -132,7 +132,7 @@ ?> - PODate); + CreatedDate); $PODate = $Pdt->format('d-m-Y'); echo $PODate ?> diff --git a/app/Views/expense_list.php b/app/Views/expense_list.php index 7c49b7c6..11a66525 100755 --- a/app/Views/expense_list.php +++ b/app/Views/expense_list.php @@ -202,7 +202,7 @@
-
+
@@ -211,7 +211,7 @@
-
+
@@ -219,7 +219,7 @@
-
+
@@ -227,7 +227,7 @@
-
+
@@ -235,7 +235,7 @@
-
+
@@ -243,7 +243,7 @@
-
+
@@ -251,7 +251,7 @@
-
+
@@ -260,7 +260,7 @@
-
+
@@ -272,7 +272,7 @@
-
+
diff --git a/app/Views/porelease_view.php b/app/Views/porelease_view.php index 58dee7b1..5741c734 100755 --- a/app/Views/porelease_view.php +++ b/app/Views/porelease_view.php @@ -173,7 +173,7 @@ if (empty($Status)) { - + @@ -200,7 +200,7 @@ if (empty($Status)) { //echo $index; ?> - diff --git a/app/Views/viewinwardgateregister.php b/app/Views/viewinwardgateregister.php index 15544f58..d410e5ee 100755 --- a/app/Views/viewinwardgateregister.php +++ b/app/Views/viewinwardgateregister.php @@ -245,10 +245,13 @@
PO DateCreated Date PONO PO Type Cost Center
PODate); + CreatedDate); $PODate = $podt->format('d-m-Y'); echo $PODate; ?>TransporterName ?> IGRStatus == 'ST074' ? 'Draft' : 'Completed'; ?> + IGRNO)){ ?>   + + FilePath)) { ?> file)) { ?>