diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 110b49d4..c92e8115 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -326,7 +326,7 @@ $routes->post('getCostCenterData', 'Inwardgateregister::getCostCenterData'); $routes->post('ViewIGRfile', 'Inwardgateregister::ViewIGRfile'); $routes->post('getAdditionalIGRFile', 'Inwardgateregister::getAdditionalIGRFile'); $routes->post('deleteAdditionalIGRFile', 'Inwardgateregister::deleteAdditionalIGRFile'); -$routes->get( 'download-files/(:segment)', 'Inwardgateregister::downloadFilesAsZip/$1'); +$routes->get( 'download-files', 'Inwardgateregister::downloadFilesAsZip'); $routes->post('inwardgateregister/edituploadfile', 'Inwardgateregister::edituploadfile'); $routes->post('getIGRRemarks', 'Inwardgateregister::getIGRRemarks'); $routes->post('saveIGRRemarks', 'Inwardgateregister::saveIGRRemarks'); diff --git a/app/Controllers/Inwardgateregister.php b/app/Controllers/Inwardgateregister.php index e42414ab..80cd15e5 100755 --- a/app/Controllers/Inwardgateregister.php +++ b/app/Controllers/Inwardgateregister.php @@ -1081,24 +1081,29 @@ function updateIGRWeight(){ $this->saveIGRLineitemHistory($igr_lineitem, $IGRNO,$IGRItemNo); $requestWeightFileName =null ; - if($WeightFile){ - if (!empty($requestWeightFileName)) { - if ($WeightFile && $WeightFile->isValid() && !$WeightFile->hasMoved()) { - if (!empty($this->inwardgateregister_model->isFileExistsInIGRdetails($requestWeightFileName))) { - log_message('error', 'File already exists in the database'.$requestWeightFileName); - } - else{ - $WeightFile->move($path, $requestWeightFileName); - $igr_lineitem['WeightFile'] = $requestWeightFileName; - } - } + $msg = null; + if ($WeightFile && $WeightFile->isValid() && !$WeightFile->hasMoved()) { + + $requestWeightFileName = $WeightFile->getName(); // Generate a unique name + + // Optional: Check for duplicates in DB if needed + if (!empty($this->inwardgateregister_model->isFileExistsInIGRdetails($requestWeightFileName))) { + log_message('error', 'File already exists in the database: ' . $requestWeightFileName); + $msg = "'File already exists in the database: ' . $requestWeightFileName"; + } else { + $WeightFile->move($path, $requestWeightFileName); + $igr_lineitem['WeightFile'] = $requestWeightFileName; + $msg = ""; } + }else{ + log_message('error', 'File invlisd: ' . $requestWeightFileName); + $msg = ""; } - + $update = $this->inwardgateregister_model->updateIGRLineItem($igr_lineitem, $IGRItemNo); if ($update) { - echo "Details update successfully!"; + echo "Details updated successfully!\n".$msg; } } function AddOgr() @@ -1328,75 +1333,82 @@ function updateIGRWeight(){ } } - public function downloadFilesAsZip($igrno) - { - // Get all file details for the given IGR number - $fileDetails = $this->inwardgateregister_model->getAllIgrFileDetails($igrno); - // Define the root path for files - $rootPath = ROOTPATH . 'public/uploads/Igrfiles/'; - - // Check if the directory exists, create if it doesn't - if (!is_dir($rootPath)) { - if (!mkdir($rootPath, 0755, true)) { - echo ''; - return; - } - } - - // Ensure the directory is writable - if (!is_writable($rootPath)) { - echo ''; - return; - } - - // Create a new ZIP archive - $zip = new ZipArchive(); - $zipFileName = $igrno . '.zip'; - $zipFilePath = $rootPath . $zipFileName; - - // Attempt to open the ZIP file - if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) { - echo ''; - return redirect()->to('/ViewIGR'); - } - - $filesAdded = false; - - // 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->file); - if (!$zip->addFile($filePath, $sanitizedFilename)) { - echo ''; - $zip->close(); - return redirect()->to('/ViewIGR'); - } - $filesAdded = true; - } else { - echo ''; - 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 { - // Close and remove any empty ZIP file created - $zip->close(); - if (file_exists($zipFilePath)) { - unlink($zipFilePath); - } - echo ''; - return redirect()->to('/ViewIGR'); - } - } + + public function downloadFilesAsZip() +{ + // Get the IGR number from query string + $igrno = $this->request->getGet('IGRNO'); + + // Get file details based on IGR number + $fileDetails = $this->inwardgateregister_model->getAllIgrFileDetails($igrno); + + // Define root path for original files + $fileRootPath = ROOTPATH . 'public/uploads/Igrfiles/'; + + // Define separate directory for ZIP output + $zipDir = ROOTPATH . 'writable/zips/'; + if (!is_dir($zipDir)) { + if (!mkdir($zipDir, 0777, true)) { + echo ''; + return; + } + } + + // Make sure ZIP directory is writable + if (!is_writable($zipDir)) { + echo ''; + return; + } + + // OPTIONAL: Set PHP's temp directory if the system one is failing + $customTemp = ROOTPATH . 'writable/tempzip/'; + if (!is_dir($customTemp)) { + mkdir($customTemp, 0777, true); + } + ini_set('sys_temp_dir', $customTemp); + + // Create ZIP archive + $zip = new ZipArchive(); + $zipFileName = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $igrno) . '.zip'; // sanitize filename + $zipFilePath = $zipDir . $zipFileName; + + if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) { + echo ''; + return redirect()->to('/ViewIGR'); + } + + $filesAdded = false; + + // Add each file to ZIP + foreach ($fileDetails as $file) { + $filePath = $fileRootPath . $file->file; + + if (file_exists($filePath) && is_file($filePath)) { + $sanitizedFilename = preg_replace('/[^a-zA-Z0-9_\-\.]/', '_', $file->file); + if (!$zip->addFile($filePath, $sanitizedFilename)) { + echo ''; + $zip->close(); + return redirect()->to('/ViewIGR'); + } + $filesAdded = true; + } else { + echo ''; + } + } + + if ($filesAdded) { + $zip->close(); + return $this->response->download($zipFilePath, null)->setFileName($zipFileName); + } else { + $zip->close(); + if (file_exists($zipFilePath)) { + unlink($zipFilePath); + } + echo ''; + return redirect()->to('/ViewIGR'); + } +} diff --git a/app/Controllers/Monthlypay.php b/app/Controllers/Monthlypay.php index 9ec20dd5..e29aba2e 100755 --- a/app/Controllers/Monthlypay.php +++ b/app/Controllers/Monthlypay.php @@ -991,18 +991,19 @@ class Monthlypay extends BaseController $leave_details['created_by'] = $userId; $affectedRows = $this->monthlypay_model->saveleaveApplicationForm($leave_details,$id); - if ($affectedRows > 0) { + // if ($affectedRows > 0) { $data = ['status' => true, 'message' => 'Leave Applicationform details created successfully.']; - } + // } } else { $leave_details['leave_application_id'] = $id; $leave_details['updated_by'] = $userId; $affectedRows = $this->monthlypay_model->saveleaveApplicationForm($leave_details,$id); - if ($affectedRows > 0) { - $data = ['status' => true, 'message' => 'Leave Applicationform details updated successfully.']; - }else{ - $data = ['status' => true, 'message' => 'There is no changes in Leave Applicationform details.']; - } + // if ($affectedRows > 0) { + // $data = ['status' => true, 'message' => 'Leave Applicationform details updated successfully.']; + // }else{ + // $data = ['status' => true, 'message' => 'There is no changes in Leave Applicationform details.']; + // } + $data = ['status' => true, 'message' => 'Leave Applicationform details updated successfully.']; } diff --git a/app/Controllers/Payslip.php b/app/Controllers/Payslip.php index d493ed23..1f3df478 100755 --- a/app/Controllers/Payslip.php +++ b/app/Controllers/Payslip.php @@ -894,7 +894,7 @@ class Payslip extends BaseController $Estimate_first = explode(".", $Estimate); - if (!is_numeric($Estimate) || (strlen((string)$Estimate)) > 8 || (strlen((string)$Estimate_first[0])) > 6) { + if (!is_numeric($Estimate) || (strlen((string)$Estimate)) > 10 || (strlen((string)$Estimate_first[0])) > 8) { // echo $Estimate_first[0]; // echo $EmpID . "-Estimate Invalid Data!"; $ErrorFlag++; diff --git a/app/Models/Driver_model.php b/app/Models/Driver_model.php index 5fee3b33..12152fa3 100755 --- a/app/Models/Driver_model.php +++ b/app/Models/Driver_model.php @@ -131,7 +131,8 @@ class Driver_model extends Model } function driverAttendanceForMonthlyPayInputs($from,$to){ - // list($year,$month,$date) = explode('-', get_current_date()); + list($year,$month,$date) = explode('-', $from); + $t_driver_monthly_pay_inputs_month_year = "$month-$year"; // $new_date_format = "$year-$month-01"; $builder = $this->db->table('t_driver_attendance') @@ -145,7 +146,11 @@ class Driver_model extends Model ->join('t_emp_pay_data','t_emp_pay_data.EmpID=driver_details.EmpID','Left') ->join('t_loan_master','t_loan_master.EmpID = driver_details.EmpID and t_loan_master.Remaining_Due != 0','Left') ->join('t_loan_history','t_loan_history.Loan_ID = t_loan_master.Loan_ID','Left') - ->join('t_driver_monthly_pay_inputs','t_driver_monthly_pay_inputs.driver_id = driver_details.EmpID','Left') + ->join('t_driver_monthly_pay_inputs', + 't_driver_monthly_pay_inputs.driver_id = driver_details.EmpID AND + t_driver_monthly_pay_inputs.month_year = "'.$t_driver_monthly_pay_inputs_month_year.'"', + 'left' + ) ->where('t_driver_attendance.date BETWEEN "'.$from.'" AND "'.$to.'"') // ->where("t_loan_master.Due_Start_Date", $new_date_format) ->groupBy('DATE_FORMAT(t_driver_attendance.date, "%M-%Y"),t_driver_attendance.driver_id'); @@ -156,7 +161,6 @@ class Driver_model extends Model } - function driverMonthlyPayInputs($monthYear){ $builder = $this->db->table('t_driver_monthly_pay_inputs'); @@ -221,7 +225,8 @@ class Driver_model extends Model ->where('DATE_FORMAT(`t_driver_attendance`.`date`, "%Y-%m")',$monthyear) ->where('t_driver_attendance.driver_id',$input_driver_id); $query = $builder->get()->getRow(); - // $last_query = $this->db->getLastQuery(); + // $last_query = $this->db->getLastQuery(); + // echo $last_query;die; return $query; } function getPayOn() diff --git a/app/Views/accountsDashboard.php b/app/Views/accountsDashboard.php index efe753ab..ea3bdd4a 100644 --- a/app/Views/accountsDashboard.php +++ b/app/Views/accountsDashboard.php @@ -262,7 +262,7 @@ isIgrFilePresent)){ ?> - + diff --git a/app/Views/driverAttendance.php b/app/Views/driverAttendance.php index 4be0a29a..7837df3c 100755 --- a/app/Views/driverAttendance.php +++ b/app/Views/driverAttendance.php @@ -553,7 +553,6 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); var diesel = parseFloat($('input[data-column="diesel_amount"]').val()) || 0; var shed = parseFloat($('input[data-column="shed_amount"]').val()) || 0; var row = parseInt($('#rowTotalAmount').text()) || 0; - console.log(row); var total = row + diesel + shed; $('#totalAmount').text(total); // Display the total with 2 decimal places @@ -570,15 +569,16 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); let param_month_year = urlParams.get("month_year"); let param_date = urlParams.get("date"); - - if(param_date == ""){ - let monthMap = {"Jan": "01", "Feb": "02", "Mar": "03", "Apr": "04","May": "05", "Jun": "06", "Jul": "07", "Aug": "08","Sep": "09", "Oct": "10", "Nov": "11", "Dec": "12"}; - let [month, year] = param_month_year.split('-'); - input_date = `01-${monthMap[month]}-${year}`; - }else{ - input_date = param_date; - } + if (!param_date || param_date.trim() === "") { + + let new_my = param_month_year ? param_month_year : ""; + let monthMap = {"Jan": "01", "Feb": "02", "Mar": "03", "Apr": "04", "May": "05", "Jun": "06", "Jul": "07", "Aug": "08", "Sep": "09", "Oct": "10", "Nov": "11", "Dec": "12"}; + let [month, year] = new_my.split('-'); + input_date = `01-${monthMap[month]}-${year}`; + + } else { input_date = param_date; } + // Send data to the server using AJAX $.ajax({ diff --git a/app/Views/employeeLeaveApplicationForm.php b/app/Views/employeeLeaveApplicationForm.php index 8bf0f2c1..65974ac5 100755 --- a/app/Views/employeeLeaveApplicationForm.php +++ b/app/Views/employeeLeaveApplicationForm.php @@ -112,9 +112,9 @@ id="drpStatus_" onchange="callLeaveStatus('', this.value, this)" style="width: 193px;"> - - + + -