diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index 93a29bc9..6267b06c 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -149,11 +149,11 @@ class StockController extends BaseController $startDate = "$month-01"; $endDate = date("Y-m-t", strtotime($startDate)); $data['coatingMachineDetails'] = $this->coatingMachineDetails_model - ->select('coating_machine_details.*, t_batchcard_files.filename') // Select required fields - ->join('t_batchcard_files', 't_batchcard_files.coating_id = coating_machine_details.id', 'left') - ->where('coating_machine_details.date >=', $startDate) - ->where('coating_machine_details.date <=', $endDate) - ->orderBy('coating_machine_details.date', 'asc') + ->select('t_coatingMachineDetails.*, t_batchcard_files.*') // Select required fields + ->join('t_batchcard_files', 't_batchcard_files.coating_id = t_coatingMachineDetails.id', 'left') + ->where('t_coatingMachineDetails.date >=', $startDate) + ->where('t_coatingMachineDetails.date <=', $endDate) + ->orderBy('t_coatingMachineDetails.date', 'asc') ->findAll(); $date = DateTime::createFromFormat('Y-m', $month); @@ -182,8 +182,8 @@ class StockController extends BaseController $sameShiftOnDateExists = $this->coatingMachineDetails_model ->where('date', $date) ->where('shift', $shift) - ->where('is_active', 1) - ->first(); + ->where('is_active', 1) + ->first(); if (!empty($sameShiftOnDateExists)) { return redirect()->back()->with('error', 'Already same shift exists on the same date ..!!'); @@ -224,6 +224,7 @@ class StockController extends BaseController foreach ($batchCardFiles as $file) { if ($file->isValid() && !$file->hasMoved()) { + $clientGivenName = $file->getClientName(); // User-given filename $newName = $file->getRandomName(); if ($file->move(WRITEPATH . 'uploads/batchcard', $newName)) { @@ -232,6 +233,7 @@ class StockController extends BaseController $builder = $db->table('t_batchcard_files'); $data = [ + 'client_file_name' => $clientGivenName, 'filename' => $newName, 'coating_id' => $insertedId ]; @@ -287,7 +289,7 @@ class StockController extends BaseController $dateToBeUpdated = $putData['date']; $existingCoatingGasConsumption = $putData['existingTotalGasConsumption']; - $updatedCoatingGasConsumption = $putData['totalGasConsumption']; + $updatedCoatingGasConsumption = $putData['totalGasConsumption']; if ($existingCoatingGasConsumption != $updatedCoatingGasConsumption) { @@ -335,6 +337,7 @@ class StockController extends BaseController // Step 2: Upload new files and save them in the database foreach ($batchCardFiles as $file) { if ($file->isValid() && !$file->hasMoved()) { + $clientGivenName = $file->getClientName(); // User-given filename $newName = $file->getRandomName(); // Check if the new file is different from the old ones (if needed) @@ -350,6 +353,7 @@ class StockController extends BaseController // Move the new file and save to DB if ($file->move(WRITEPATH . 'uploads/batchcard', $newName)) { $data = [ + 'client_file_name' => $clientGivenName, 'filename' => $newName, 'coating_id' => $id ]; @@ -359,9 +363,7 @@ class StockController extends BaseController } } - // Optional: Remove old files only if necessary (based on your criteria) - // Example: Delete old files if you no longer need them - // In this example, we're keeping old files that were not replaced. + foreach ($oldFiles as $oldFile) { $filePath = WRITEPATH . 'uploads/batchcard/' . $oldFile['filename']; if (file_exists($filePath)) { @@ -369,10 +371,7 @@ class StockController extends BaseController } } - // After this, you would have: - // - New files uploaded - // - Only new files added to the database - // - Optionally, old files removed + } } diff --git a/app/Views/CoatingMachineDetail.php b/app/Views/CoatingMachineDetail.php index 795088f1..0f6e57e9 100644 --- a/app/Views/CoatingMachineDetail.php +++ b/app/Views/CoatingMachineDetail.php @@ -341,7 +341,6 @@