Merge branch 'new_theme' of bitbucket.org:venbainformationtechnology/ria into new_theme

This commit is contained in:
Smart 2024-10-25 14:53:14 +05:30
commit b7211345ea
2 changed files with 78 additions and 59 deletions

View File

@ -67,8 +67,26 @@ class Inwardgateregister extends BaseController
$this->global['pageTitle'] = 'View Inward Gate Register';
$result = $this->inwardgateregister_model->ViewigrListing($fromDate,$toDate);
$data['IGR'] = $result[0];
$result = $this->inwardgateregister_model->ViewigrListing($fromDate, $toDate);
$igrList = $result[0];
foreach ($igrList as &$igr) {
$igrNo = $igr->IGRNO;
$fileDetails = $this->inwardgateregister_model->getAllIgrFileDetails($igrNo);
$igr->isIgrFilePresent = false; // Initialize the key
foreach ($fileDetails as $file) {
if (!empty($file->file)) {
$igr->isIgrFilePresent = true;
break;
}
}
}
// Unset reference to avoid side effects
unset($igr);
$data['IGR'] = $igrList;
$data['IGRDownload'] = $result[1];
$data['userRole'] = $this->session->get('role');
$data['transporter'] = $this->inwardgateregister_model->transporter();
@ -1672,19 +1690,22 @@ function updateIGRWeight(){
public function downloadFilesAsZip($igrno)
{
// Get all file details for the given IGR number
$fileDetails = $this->inwardgateregister_model->getAllIgrFileDetails($igrno);
if (empty($fileDetails)) {
echo '<script>alert("There are no files.");</script>';
redirect('ViewIGR', 'refresh');
return;
}
$fileDetails = $this->inwardgateregister_model->getAllIgrFileDetails($igrno);
// Define the root path for files
$rootPath = ROOTPATH . 'public/uploads/Igrfiles/';
// Check if root path is valid
// Check if the directory exists, create if it doesn't
if (!is_dir($rootPath)) {
echo '<script>alert("Invalid file directory.");</script>';
if (!mkdir($rootPath, 0755, true)) {
echo '<script>alert("Failed to create the directory.");</script>';
return;
}
}
// Ensure the directory is writable
if (!is_writable($rootPath)) {
echo '<script>alert("Directory is not writable.");</script>';
return;
}
@ -1693,49 +1714,50 @@ function updateIGRWeight(){
$zipFileName = $igrno . '.zip';
$zipFilePath = $rootPath . $zipFileName;
if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) {
$filesAdded = false;
// Attempt to open the ZIP file
if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
echo '<script>alert("Failed to create ZIP file.");</script>';
return redirect()->to('/ViewIGR');
}
// Add each file to the ZIP archive
foreach ($fileDetails as $file) {
$filePath = $rootPath . $file->file;
$filesAdded = false;
// Check if file exists
if (!file_exists($filePath)) {
log_message('error', 'File not found: ' . $filePath);
continue;
}
// Add each file to the ZIP archive
foreach ($fileDetails as $file) {
$filePath = $rootPath . $file->file;
// Ensure file exists and is not a directory
if (file_exists($filePath) && is_file($filePath)) {
// Sanitize filename for ZIP
$sanitizedFilename = preg_replace('/[^a-zA-Z0-9_\-\.]/', '_', $file->filename);
if (!$zip->addFile($filePath, $sanitizedFilename)) {
log_message('error', 'Failed to add file: ' . $sanitizedFilename);
echo '<script>alert("Failed to add file: ' . $file->filename . '");</script>';
$zip->close();
redirect('ViewIGR', 'refresh');
return;
return redirect()->to('/ViewIGR');
}
$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 '<script>alert("No files were added to the ZIP.");</script>';
redirect('ViewIGR', 'refresh');
return;
echo '<script> alert("File not found or is a directory: ' . $filePath . '");</script>';
continue;
}
}
// Close ZIP archive if files were added
if ($filesAdded) {
$zip->close(); // Close ZIP only if files were added
return $this->response->download($zipFilePath, null)->setFileName($zipFileName);
} else {
echo '<script>alert("Failed to create ZIP file");</script>';
redirect('ViewIGR', 'refresh');
return;
// Close and remove any empty ZIP file created
$zip->close();
if (file_exists($zipFilePath)) {
unlink($zipFilePath);
}
echo '<script>alert("No files were added to the ZIP.");</script>';
return redirect()->to('/ViewIGR');
}
}
}

View File

@ -165,6 +165,12 @@
</div>
</div>
<?php if (session()->getFlashdata('message')): ?>
<div class="alert alert-warning" role="alert">
<?= esc(session()->getFlashdata('message')); ?>
</div>
<?php endif; ?>
<div class="row">
<div class="col-12">
<div class="card">
@ -245,21 +251,7 @@
<td><?php echo $record->TransporterName ?></td>
<td><?php echo $record->IGRStatus == 'ST074' ? 'Draft' : 'Completed'; ?></td>
<td>
<?php if(!empty($record->IGRNO)){ ?>
<a target="_blank" href="<?php echo base_url('download-files/' . $record->IGRNO); ?>">
<i class="fa fa-download" style="text-align: center;"></i>
</a>
&nbsp;
<?php } ?>
<?php if (!empty($record->FilePath)) { ?>
<!-- <a target="_blank" data-toggle="modal" data-target="#Fileshow" data-id="<%=index%>" title="Files" data-igrno="<?php echo $record->IGRNO ?>" data-pono="<?php echo $record->PONO ?>"><i class="fa fa-clone" style="text-align: center;"></i></a> -->
<?php } else if (!empty($record->file)) { ?>
<!-- <a target="_blank" data-toggle="modal" data-target="#Fileshow" data-id="<%=index%>" title="Files" data-igrno="<?php echo $record->IGRNO ?>" data-pono="<?php echo $record->PONO ?>"><i class="fa fa-clone" style="text-align: center;"></i></a> -->
<?php } else { ?>
<!-- <a target="_blank" data-toggle="modal" data-target="#Fileshow" data-id="<%=index%>" title="Files" data-igrno="<?php echo $record->IGRNO ?>" data-pono="<?php echo $record->PONO ?>"><i class="fa fa-clone" style="text-align: center;"></i></a> -->
<?php } ?>
&nbsp;
<a target="_blank" data-toggle="modal" data-target="#Historyshow" data-id="<%=index%>" title="IGR History" data-igrno="<?php echo $record->IGRNO ?>" data-pono="<?php echo $record->PONO ?>">
<i class="fa fa-history" style="text-align: center;"></i>
</a>
@ -267,7 +259,13 @@
&nbsp;
<!-- <a class="a_tag_for_mrir" href="<?php echo base_url().'MRIRcontroller/igrdatavalues?IGRNO='.$record->IGRNO; ?>" target="_blank" data-id="<%=index%>" title="Generate MRIR"><i class="fa fa-external-link" style="text-align: center;"></i></a> -->
</td>
<?php if(($record->isIgrFilePresent)){ ?>
<a target="_blank" href="<?php echo base_url('download-files/' . $record->IGRNO); ?>">
<i class="fa fa-download" style="text-align: center;"></i>
</a>
&nbsp;
<?php } ?>
</td>
</tr>
<?php
}
@ -670,8 +668,7 @@
type: "POST",
url: "<?php echo base_url() ?>ViewIGRDetails",
success: function(data) {
// success:function(data) {
// $('#content').loader('hide');
var parsedData = JSON.parse(data);
console.log(parsedData);
if (parsedData['details'].length === 0) {