From e32338e726762b499fa6e21568d39f3fa4858ab2 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Tue, 28 Jan 2025 16:36:07 +0530 Subject: [PATCH 1/4] stock module latest today vadivel J 28-01-2025 --- app/Controllers/StockController.php | 202 ++++++------- app/Views/bagStockDetails.php | 45 ++- app/Views/drierMachineDetails.php | 391 ++++++++++++++++---------- app/Views/powerConsumptionDetails.php | 47 +++- app/Views/resinStockDetails.php | 45 ++- app/Views/trpSandUseStockDetails.php | 58 ++++ 6 files changed, 523 insertions(+), 265 deletions(-) diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index 553668ba..79451166 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -1698,7 +1698,7 @@ class StockController extends BaseController while ($start <= $end) { $timeValue = date('H:i', $start); // 24-hour format for value - $timeLabel = date('h:i A', $start); // 12-hour format with AM/PM for display + $timeLabel = date('h:i a', $start); // 12-hour format with AM/PM for display $times[$timeValue] = $timeLabel; // Store time in associative array $start = strtotime('+15 minutes', $start); // Increment by 15 minutes } @@ -1737,138 +1737,118 @@ class StockController extends BaseController public function addOrEditdrierMachineDetails() { - $drierData = []; - $drierData = json_decode($this->request->getPost('drierData'), true); - - + $drierData = json_decode($this->request->getPost('drierData'), true) ?? []; + + // If drierData is empty, check for additionalEntry if (empty($drierData)) { - $additionalEntry = $this->request->getPost(); - - if (!empty($additionalEntry)) { - $drierData[] = [ - 'Date' => $this->convertToDateWithFlexibleFormats($additionalEntry['Date'], ["d-m-Y", "Y-m-d", "m/d/Y", "m-d-Y"], "Y-m-d"), - 'Drier On Time' => $additionalEntry['Drier_On_Time'], - 'Drier Off Time' => $additionalEntry['Drier_Off_Time'], - 'Running Hrs' => $additionalEntry['Running_Hrs'], - 'Supplier Name' => $additionalEntry['Supplier_Name'], - 'i/p Sand Moisture(%)' => $additionalEntry['i/p_Sand_Moisture(%)'], - 'Tot Gas Consumption' => $additionalEntry['Tot_Gas_Consumption'], - 'Gas Per Ton' => $additionalEntry['Gas_Per_Ton'], - 'i/p Sand Qty' => $additionalEntry['i/p_Sand_Qty'], - 'Moisture Loss Qty' => $additionalEntry['Moisture_Loss_Qty'], - 'Sand Dried Qty' => $additionalEntry['Sand_Dried_Qty'], - 'Qty Per Hrs' => $additionalEntry['Qty_Per_Hrs'], - 'Dust Qty' => $additionalEntry['Dust_Qty'], - 'Customer Name' => $additionalEntry['Customer_Name'] - ]; - } else { - + if (empty($additionalEntry)) { echo "No data received."; return; } + + $drierData[] = $this->mapDrierEntry($additionalEntry); } - - $message1 = ''; - + $this->db->transBegin(); - try { + $inserts = []; + $updates = []; + foreach ($drierData as $row) { - $data = [ - 'date' => $this->convertToDateWithFlexibleFormats($row['Date'], ["d-m-Y", "Y-m-d", "m/d/Y", "m-d-Y"], "Y-m-d"), - 'drier_on_time' => $row['Drier On Time'], - 'drier_off_time' => $row['Drier Off Time'], - 'drier_running_hours' => $row['Running Hrs'], - 'supplier_name' => $row['Supplier Name'], - 'input_sand_moisture' => $row['i/p Sand Moisture(%)'], - 'total_gas_consumption' => $row['Tot Gas Consumption'], - 'gas_per_ton' => $row['Gas Per Ton'], - 'input_sand_qty' => $row['i/p Sand Qty'], - 'moisture_loss_qty' => $row['Moisture Loss Qty'], - 'sand_dried_qty' => $row['Sand Dried Qty'], - 'qty_per_hours' => $row['Qty Per Hrs'], - 'dust_qty' => $row['Dust Qty'], - 'customer_name' => $row['Customer Name'] - ]; - - // Check if a row with the same date already exists $existingRow = $this->drierMachineDetails_model->where('id', $row['id'] ?? '')->first(); - - $inserts = []; - $updates = []; - + $data = $this->mapDrierEntry($row, $existingRow); + if ($existingRow) { - // If exists, update the row - - //before updating the row update gas stock - $existingDrierGasConsumption = $existingRow['total_gas_consumption']; - $updatedDrierGasConsumption = $row['Tot Gas Consumption']; - - if ($existingDrierGasConsumption != $updatedDrierGasConsumption) { - - $changeInConsumption = $updatedDrierGasConsumption - $existingDrierGasConsumption; - $dateToBeUpdated = $existingRow['date']; - $this->updateGasStockConsumption($dateToBeUpdated, $changeInConsumption); - } - $data['id'] = $existingRow['id']; + $this->handleGasStockUpdate($existingRow, $row); $updates[] = $data; } else { - // If not, insert a new row - //before inserting the row update gas stock - $consumption = $row['Tot Gas Consumption']; - $dateToBeInserted = $data['date']; - $this->updateGasStockConsumption($dateToBeInserted, $consumption); - + $this->updateGasStockConsumption($data['date'], $data['total_gas_consumption']); $inserts[] = $data; } - - if (!empty($inserts)) { - $this->drierMachineDetails_model->insertBatch($inserts); - - $message1 = "Warning..!! Kindly Update the next subsequent month Gas Stock If older month Gas Stock Updated..!!"; - } - - if (!empty($updates)) { - $this->drierMachineDetails_model->updateBatch($updates, 'id'); - - $message1 = "Warning..!! Kindly Update the next subsequent month Gas Stock If older month Gas Stock Updated..!!"; - } - - if ($this->db->transStatus() === false) { - throw new \Exception('Transaction failed due to database error.'); - } } - + + if (!empty($inserts)) { + $this->drierMachineDetails_model->insertBatch($inserts); + } + + if (!empty($updates)) { + $this->drierMachineDetails_model->updateBatch($updates, 'id'); + } + + if ($this->db->transStatus() === false) { + throw new \Exception('Transaction failed due to database error.'); + } + $this->db->transCommit(); - - if (!empty($additionalEntry)) { - // Data to be sent via POST - $postData = [ - 'month' => $this->convertToDateWithFlexibleFormats($additionalEntry['Date'], ["d-m-Y", "Y-m-d", "m/d/Y", "m-d-Y"], "M-Y"), - - ]; - - echo '
'; - foreach ($postData as $key => $value) { - echo ''; - } - echo '
'; - echo ''; - exit; + + // Redirect if additional entry was provided + if (!empty($additionalEntry)) { + $this->redirectToDrierMachineDetails($additionalEntry['date']); + return; } - - echo "Data saved successfully . $message1"; - - } catch (\Exception $e) { - // Rollback the transaction on any failure + + echo "Data saved successfully. Warning..!! Kindly Update the next subsequent month Gas Stock If older month Gas Stock Updated..!!"; + } catch (\Exception $e) { $this->db->transRollback(); echo "Failed to save/Update data: " . $e->getMessage(); } } - + + /** + * Maps input row to expected format. + */ + private function mapDrierEntry(array $row, $existingRow = null): array + { + return [ + 'id' => $existingRow['id'] ?? null, + 'date' => $this->convertToDateWithFlexibleFormats($row['date'], ["d-m-Y", "Y-m-d", "m/d/Y", "m-d-Y"], "Y-m-d"), + 'drier_on_time' => $row['drier_on_time'], + 'drier_off_time' => $row['drier_off_time'], + 'drier_running_hours' => $row['drier_running_hours'], + 'supplier_name' => $row['supplier_name'], + 'input_sand_moisture' => $row['input_sand_moisture'], + 'total_gas_consumption' => $row['total_gas_consumption'], + 'gas_per_ton' => $row['gas_per_ton'], + 'input_sand_qty' => $row['input_sand_qty'], + 'moisture_loss_qty' => $row['moisture_loss_qty'], + 'sand_dried_qty' => $row['sand_dried_qty'], + 'qty_per_hours' => $row['qty_per_hours'], + 'dust_qty' => $row['dust_qty'], + 'customer_name' => $row['customer_name'] + ]; + } + + /** + * Updates gas stock consumption if the value changes. + */ + private function handleGasStockUpdate($existingRow, $newRow) + { + $existingConsumption = $existingRow['total_gas_consumption']; + $updatedConsumption = $newRow['total_gas_consumption']; + + if ($existingConsumption != $updatedConsumption) { + $changeInConsumption = $updatedConsumption - $existingConsumption; + $this->updateGasStockConsumption($existingRow['date'], $changeInConsumption); + } + } + + /** + * Redirects to the drier machine details page. + */ + private function redirectToDrierMachineDetails(string $date) + { + $postData = ['month' => $this->convertToDateWithFlexibleFormats($date, ["d-m-Y", "Y-m-d", "m/d/Y", "m-d-Y"], "M-Y")]; + + echo '
'; + foreach ($postData as $key => $value) { + echo ''; + } + echo '
'; + echo ''; + exit; + } + function convertToDateWithFlexibleFormats($dateInput, array $inputFormats, string $outputFormat): ?string { diff --git a/app/Views/bagStockDetails.php b/app/Views/bagStockDetails.php index ae0a1a0a..5624481e 100644 --- a/app/Views/bagStockDetails.php +++ b/app/Views/bagStockDetails.php @@ -295,10 +295,10 @@ + @@ -968,3 +968,44 @@ + + \ No newline at end of file diff --git a/app/Views/drierMachineDetails.php b/app/Views/drierMachineDetails.php index b21eada8..20d54ddd 100644 --- a/app/Views/drierMachineDetails.php +++ b/app/Views/drierMachineDetails.php @@ -193,7 +193,6 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); color: #ffffff; font-weight: bold; padding: 6px 10px; - text-align: center; } .celda_encabezado_total { @@ -210,7 +209,7 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); /* */ text-align: center; border: 1px solid #ccc; - padding: 10px 6px; + padding: 4px 6px; } @@ -230,13 +229,19 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); /* Ensure each in thead stays sticky */ .fht-table thead th { + position: sticky; top: 0; z-index: 11; /* Higher than table rows but lower than first column */ - background-color: #00a65a; /* Green background */ + background-color:rgb(80, 187, 217); /* blue background */ color: #ffffff; border: 1px solid #ddd; - padding: 10px; + padding:5px; + white-space: normal; /* Allows text to wrap */ + word-wrap: break-word; /* Breaks long words if needed */ + text-align: center; /* Centers text for better alignment */ + max-width: 150px; /* Set a max width to control wrapping */ + } /* Sticky First Column */ @@ -244,7 +249,7 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); .fht-table td:nth-child(1) { position: sticky; left: 0; - background-color: #00a65a; + background-color:rgb(80, 187, 217); /* blue background */ z-index: 15; /* Ensures it stays above other cells */ border-right: 2px solid #ddd; color: #ffffff; @@ -286,9 +291,10 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); -
+
-
+
+ @@ -309,8 +315,11 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y');
-
- + + +
@@ -339,20 +346,22 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); - Date - Drier On Time - Drier Off Time - Running Hrs - Supplier Name - i/p Sand Moisture(%) - Tot Gas Consumption - Gas Per Ton - i/p Sand Qty - Moisture Loss Qty - Sand Dried Qty - Qty Per Hrs - Dust Qty - Customer Name + Date + Drier On Time + Drier Off Time + Running Hrs + Supplier Name + + Input Sand Qty + Input Sand Moisture(%) + Sand Dried Qty + Total Gas Consumption + Gas Per Ton + Qty Per Hrs + Moisture Loss Qty + Dust Qty + + Customer Name id @@ -431,46 +440,54 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); - + + + + + + + + + + + + - + + + + + + - + - - - + + + + - + - - - - - - - - - - + @@ -522,21 +539,23 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); + - - - - - - - - - - - - + style="padding:5px; border:#ffffff; background-color: #ffffff;">Date value + + + + + + + + + + + + + @@ -548,17 +567,18 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); - - + + - - - + - - + + + + + @@ -581,10 +601,11 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); +
- +
@@ -691,7 +712,7 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y');
-
@@ -699,7 +720,7 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); + id="additionalEntryDrierOffTimeId" name="drier_off_time"> $time) { ?> @@ -720,7 +741,7 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y');
-
@@ -728,21 +749,21 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y');
- +
+ type="text" class="form-control" id="additionalEntryTotalGasConsumptionId" name="total_gas_consumption" value="">
+ type="text" class="form-control" id="additionalEntrySandDriedQtyId" name="sand_dried_qty" value="">
-
@@ -750,21 +771,21 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y');
- +
+ type="text" class="form-control" id="additionalEntryInputSandQtyId" name="input_sand_qty" value="">
-
-
@@ -773,7 +794,7 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y');
+
@@ -806,56 +827,7 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); - + + + + + + + + + + diff --git a/app/Views/powerConsumptionDetails.php b/app/Views/powerConsumptionDetails.php index ecfec6d9..fd31f64d 100644 --- a/app/Views/powerConsumptionDetails.php +++ b/app/Views/powerConsumptionDetails.php @@ -305,7 +305,7 @@ foreach ($period as $day) { @@ -1284,4 +1284,47 @@ foreach ($period as $day) { } - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/app/Views/resinStockDetails.php b/app/Views/resinStockDetails.php index 71e07a48..3f19bb07 100644 --- a/app/Views/resinStockDetails.php +++ b/app/Views/resinStockDetails.php @@ -298,7 +298,7 @@ foreach ($period as $day) { @@ -907,4 +907,47 @@ foreach ($period as $day) { } }) } + + + + + \ No newline at end of file diff --git a/app/Views/trpSandUseStockDetails.php b/app/Views/trpSandUseStockDetails.php index 7f60fcc4..2df367eb 100644 --- a/app/Views/trpSandUseStockDetails.php +++ b/app/Views/trpSandUseStockDetails.php @@ -270,6 +270,19 @@
+
+
+ +
@@ -642,3 +655,48 @@ + + + + + + From 9c6db63662615f72a7be6d62912f78290f10be55 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Tue, 28 Jan 2025 16:49:12 +0530 Subject: [PATCH 2/4] stock module latest today vadivel J 28-01-2025 --- app/Models/Rawmaterialdetails_model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Models/Rawmaterialdetails_model.php b/app/Models/Rawmaterialdetails_model.php index 8bea1a2b..6c747c31 100755 --- a/app/Models/Rawmaterialdetails_model.php +++ b/app/Models/Rawmaterialdetails_model.php @@ -169,7 +169,7 @@ class Rawmaterialdetails_model extends Model $builder = $this->db->table('t_materialmaster') ->select('MaterialCode , MaterialName') ->where('IsActive', 1) - ->where('Category', 'bag') + ->where('Category', 'Packing Material') ->orderBy('MaterialCode', 'asc'); $query = $builder->get(); $materialResults = $query->getResultArray(); @@ -199,7 +199,7 @@ class Rawmaterialdetails_model extends Model $builder = $this->db->table('t_materialmaster') ->select('MaterialCode , MaterialName') ->where('IsActive', 1) - ->where('Category', 'plastic_chemicals') + ->where('Category', 'Resin') ->orderBy('MaterialCode', 'asc'); $query = $builder->get(); $materialResults = $query->getResultArray(); From f8c19743fff4840212ebae5d586619abc2ca2e81 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Tue, 28 Jan 2025 17:15:11 +0530 Subject: [PATCH 3/4] stock module latest today vadivel J 28-01-2025 --- app/Views/dieselStockDetails.php | 24 ++++++++++++++++++++---- app/Views/powerConsumptionDetails.php | 19 +++++++++++++++++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/Views/dieselStockDetails.php b/app/Views/dieselStockDetails.php index c9ae41d2..c7f0ba3d 100644 --- a/app/Views/dieselStockDetails.php +++ b/app/Views/dieselStockDetails.php @@ -630,6 +630,7 @@ foreach ($period as $day) { with initial values 0 for entire month --> + $dateInMonth) { ?> - > + > @@ -679,7 +683,11 @@ foreach ($period as $day) { + > + @@ -708,14 +716,22 @@ foreach ($period as $day) { contenteditable="true" + + - > + >
Date valueDrier On Time Drier Off TimeRunning HrsSupplier Name is a dropdown featurei/p Sand Moisture(%)Tot Gas ConsumptionGas Per Toni/p Sand QtyMoisture Loss QtySand Dried QtyQty Per HrsDust QtyDrier On Time Drier Off TimeRunning HrsSupplier Name input Sand Qtyinputp Sand Moisture(%)Sand Dried QtyTotal Gas ConsumptionGas Per TonQty Per HrsMoisture Loss QtyDust Qty
Total ---- --- -
+ contenteditable="true"> - > + > + contenteditable="true"> + Date: Tue, 28 Jan 2025 17:17:15 +0530 Subject: [PATCH 4/4] stock module latest today vadivel J 28-01-2025 --- app/Models/PowerConsumptionSummaryModel.Php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/PowerConsumptionSummaryModel.Php b/app/Models/PowerConsumptionSummaryModel.Php index 80aff61d..4ff51c32 100644 --- a/app/Models/PowerConsumptionSummaryModel.Php +++ b/app/Models/PowerConsumptionSummaryModel.Php @@ -6,7 +6,7 @@ use CodeIgniter\Model; class PowerConsumptionSummaryModel extends Model { - protected $table = 't_powerConsumptionSummary'; + protected $table = 't_powerconsumptionsummary'; protected $primaryKey = 'id'; protected $allowedFields = [