From 40a2cbc4d257ff06a1dd54bb17b027eee771c771 Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Tue, 13 Aug 2024 09:26:02 +0000 Subject: [PATCH] FIX_issues : ps --- app/Controllers/Inwardgateregister.php | 80 ++++++++++++++++---------- app/Views/viewinwardgateregister.php | 52 ++++++++--------- 2 files changed, 77 insertions(+), 55 deletions(-) diff --git a/app/Controllers/Inwardgateregister.php b/app/Controllers/Inwardgateregister.php index d2c5ce2a..a82917df 100755 --- a/app/Controllers/Inwardgateregister.php +++ b/app/Controllers/Inwardgateregister.php @@ -1635,44 +1635,66 @@ function updateIGRWeight(){ } } } + public function downloadFilesAsZip($igrno) - { - - // Get all file details for the given IGR number - $fileDetails = $this->inwardgateregister_model->getAllIgrFileDetails($igrno); - if (empty($fileDetails)) { +{ + // 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/'; + // Define the root path for files + $rootPath = ROOTPATH . 'public/uploads/Igrfiles/'; - // Create a new ZIP archive - $zip = new ZipArchive(); + // Create a new ZIP archive + $zip = new ZipArchive(); - // Define the name of the ZIP file - $zipFileName = $igrno . '.zip'; - $zipFilePath = ROOTPATH . 'public/uploads/Igrfiles/' . $zipFileName; + // Define the name of the ZIP file + $zipFileName = $igrno . '.zip'; + $zipFilePath = $rootPath . $zipFileName; - if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) { - // Add each file to the ZIP archive - foreach ($fileDetails as $file) { - $filePath = $rootPath . $file->file; - if (file_exists($filePath)) { - $zip->addFile($filePath, $file->filename); - } - } + if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) { + $filesAdded = false; - // Close the ZIP archive - $zip->close(); + // 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; + } + } - // Return the ZIP file as a download - return $this->response->download($zipFilePath, null)->setFileName($zipFileName); - } else { - // Handle the error - echo 'Failed to create ZIP file'; - } + // 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; } } + +} diff --git a/app/Views/viewinwardgateregister.php b/app/Views/viewinwardgateregister.php index 93a686ba..3a9ae581 100644 --- a/app/Views/viewinwardgateregister.php +++ b/app/Views/viewinwardgateregister.php @@ -205,15 +205,15 @@ - - - - - - - - - + + + + + + + + + @@ -610,15 +610,15 @@ console.log(parsedData); $("#pendingQuantityHeader").css("display", "table-cell"); trIGRHTML += '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + '' + '' + '' + @@ -641,14 +641,14 @@ console.log(parsedData); } else { $("#pendingQuantityHeader").css("display", "none"); trIGRHTML += '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + '' + '' + '' +
SNoItem CodeItem DescriptionUOMOrdred QtyReceived QtyRemarksSNoItem CodeItem DescriptionUOMOrdered QtyReceived QtyRemarks
' + i + '' + item.MaterialCode + '' + item.MaterialName + '' + item.UOM + '' + parseInt(item.Quantity) + '' + parseInt(item.Quantity - item.QuantityAsPerInvoice) + ' ' + i + '' + item.MaterialCode + '' + item.MaterialName + '' + item.UOM + '' + parseInt(item.Quantity) + '' + parseInt(item.Quantity - item.QuantityAsPerInvoice) + '
' + i + '' + item.MaterialCode + '' + item.MaterialName + '' + item.UOM + '' + item.Quantity + '' + item.QuantityAsPerInvoice + '' + item.Remarks + ' ' + i + '' + item.MaterialCode + '' + item.MaterialName + '' + item.UOM + '' + item.Quantity + '' + item.QuantityAsPerInvoice + '' + item.Remarks + '