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 '
'; - 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 ''; + echo ''; + exit; + } + function convertToDateWithFlexibleFormats($dateInput, array $inputFormats, string $outputFormat): ?string { 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 = [ diff --git a/app/Models/Rawmaterialdetails_model.php b/app/Models/Rawmaterialdetails_model.php index 28fcb3d3..794744ae 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(); 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/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) { ?>| Date value | -Drier On Time | -Drier Off Time | -Running Hrs | -Supplier Name is a dropdown feature | -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 | + style="padding:5px; border:#ffffff; background-color: #ffffff;">Date value +Drier On Time | +Drier Off Time | +Running Hrs | +Supplier Name | + +input Sand Qty | +inputp Sand Moisture(%) | +Sand Dried Qty | +Total Gas Consumption | +Gas Per Ton | +Qty Per Hrs | +Moisture Loss Qty | +Dust Qty | Total | -- | -- | +- | +- | =$summary['drier_running_hours']?> | - | -- | -=$summary['total_gas_consumption']?> | -- | +=$summary['input_sand_qty']?> | -=$summary['moisture_loss_qty']?> | -=$summary['sand_dried_qty']?> | - | +=$summary['sand_dried_qty']?> | +=$summary['total_gas_consumption']?> | ++ | + | =$summary['moisture_loss_qty']?> | =$summary['dust_qty']?> | @@ -581,10 +601,11 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); += $previousMonthPowerConsumptionStockDetails[$powerMachineIndex]['closing_units'] ?> + contenteditable="true"> + |
\ 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 @@
+
+
+
+
+
+
+
+
+
+
+
+ |
|---|