stock module latest today vadivel J 19-02-2025

This commit is contained in:
vadivelJ96 2025-02-20 14:59:16 +05:30
parent da323b81bc
commit 50db9f5ae5
3 changed files with 537 additions and 519 deletions

View File

@ -2113,18 +2113,12 @@ class StockController extends BaseController
public function addOrEditdrierMachineDetails()
{
$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)) {
echo "No data received.";
return;
}
$drierData[] = $this->mapDrierEntry($additionalEntry);
}
$data = $this->request->getPost();
$drierData[] = $this->mapDrierEntry($data);
$this->db->transBegin();
try {
@ -2132,13 +2126,18 @@ class StockController extends BaseController
$updates = [];
foreach ($drierData as $row) {
$existingRow = $this->drierMachineDetails_model->where('id', $row['id'] ?? '')->first();
$data = $this->mapDrierEntry($row, $existingRow);
$existingRow = $row['id'];
$data = $row;
if ($existingRow) {
if (($existingRow)) {
// dd("inside update");
$existingRow = $this->drierMachineDetails_model->where('id', $row['id'] ?? '')->first();
$this->handleGasStockUpdate($existingRow, $row);
$updates[] = $data;
} else {
// dd("inside insert");
$this->updateGasStockConsumption($data['date'], $data['total_gas_consumption']);
$inserts[] = $data;
}
@ -2157,41 +2156,36 @@ class StockController extends BaseController
}
$this->db->transCommit();
// Redirect if additional entry was provided
if (!empty($additionalEntry)) {
$this->redirectToDrierMachineDetails($additionalEntry['date']);
return;
return redirect()->to("/drierMachineDetails")->with('success', "Data Saved Successfully");
} catch (\Exception $error) {
$this->db->transRollback();
return redirect()->back()->with('error', ' ' . $error->getMessage());
}
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
private function mapDrierEntry(array $data): 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']
'id' => $data['id'] ?? null,
'date' => $this->convertToDateWithFlexibleFormats($data['date'], ["d-m-Y", "Y-m-d", "m/d/Y", "m-d-Y"], "Y-m-d"),
'drier_on_time' => $data['drier_on_time'],
'drier_off_time' => $data['drier_off_time'],
'drier_running_hours' => $data['drier_running_hours'],
'supplier_name' => $data['supplier_name'],
'input_sand_moisture' => $data['input_sand_moisture'],
'total_gas_consumption' => $data['total_gas_consumption'],
'gas_per_ton' => $data['gas_per_ton'],
'input_sand_qty' => $data['input_sand_qty'],
'moisture_loss_qty' => $data['moisture_loss_qty'],
'sand_dried_qty' => $data['sand_dried_qty'],
'qty_per_hours' => $data['qty_per_hours'],
'dust_qty' => $data['dust_qty'],
'customer_name' => $data['customer_name']
];
}
@ -2209,22 +2203,7 @@ class StockController extends BaseController
}
}
/**
* 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 '<form id="postForm" action="' . base_url('drierMachineDetails') . '" method="POST">';
foreach ($postData as $key => $value) {
echo '<input type="hidden" name="' . $key . '" value="' . $value . '">';
}
echo '</form>';
echo '<script type="text/javascript">document.getElementById("postForm").submit();</script>';
exit;
}
function convertToDateWithFlexibleFormats($dateInput, array $inputFormats, string $outputFormat): ?string
{

View File

@ -256,7 +256,7 @@
</ol>
</div>
<div>
<div>
<!-- <button type="button" class="btn btn-danger" data-target="#productionBatchCardDetailModalId"
data-toggle="modal">
@ -333,19 +333,19 @@
<thead>
<tr>
<th class="celda_encabezado_general" style="padding: 10px;">Date</th>
<th class="celda_encabezado_general" style="padding: 10px;">Shift</th>
<th class="celda_encabezado_general" style="padding: 10px;">Machine On Time</th>
<th class="celda_encabezado_general" style="padding: 10px;">Machine Off Time</th>
<th class="celda_encabezado_general" style="padding: 10px;">Machine Running(hr)</th>
<th class="celda_encabezado_general" style="padding: 10px;">Customer Name</th>
<th class="celda_encabezado_general" style="padding: 10px;">Grade</th>
<th class="celda_encabezado_general" style="padding: 10px;">Total Coating</th>
<th class="celda_encabezado_general" style="padding: 10px;">Total Coating Sand(kg)</th>
<th class="celda_encabezado_general" style="padding: 10px;">Total Gas Consumption</th>
<th class="celda_encabezado_general" style="padding: 10px;">Hour Gas</th>
<th class="celda_encabezado_general" style="padding: 10px;">Hour QTY(kg)</th>
<th class="celda_encabezado_general" style="padding: 10px;">Action</th>
<th class="celda_encabezado_general" >Date</th>
<th class="celda_encabezado_general" >Shift</th>
<th class="celda_encabezado_general" >Machine On Time</th>
<th class="celda_encabezado_general" >Machine Off Time</th>
<th class="celda_encabezado_general" >Machine Running(hr)</th>
<th class="celda_encabezado_general" >Customer Name</th>
<th class="celda_encabezado_general" >Grade</th>
<th class="celda_encabezado_general" >Total Coating</th>
<th class="celda_encabezado_general" >Total Coating Sand(kg)</th>
<th class="celda_encabezado_general" >Total Gas Consumption</th>
<th class="celda_encabezado_general" >Hour Gas</th>
<th class="celda_encabezado_general" >Hour QTY(kg)</th>
<th class="celda_encabezado_general" >Action</th>
</tr>
</thead>
<tbody>
@ -462,17 +462,17 @@
<th class="celda_encabezado_total"
style="padding: 10px; background-color:#ffff;"> Date </th>
<th class="celda_encabezado_total" style="padding: 10px;">Shift</th>
<th class="celda_encabezado_total" style="padding: 10px;">Machine On Time</th>
<th class="celda_encabezado_total" style="padding: 10px;">Machine Off Time</th>
<th class="celda_encabezado_total" style="padding: 10px;">Machine Running(hr)</th>
<th class="celda_encabezado_total" style="padding: 10px;">Customer Name </th>
<th class="celda_encabezado_total" style="padding: 10px;">Grade</th>
<th class="celda_encabezado_total" style="padding: 10px;">Total Coating</th>
<th class="celda_encabezado_total" style="padding: 10px;">Total Coating Sand(kg)</th>
<th class="celda_encabezado_total" style="padding: 10px;">Total Gas Consumption</th>
<th class="celda_encabezado_total" style="padding: 10px;">Hour Gas</th>
<th class="celda_encabezado_total" style="padding: 10px;">Hour QTY(kg)</th>
<th class="celda_encabezado_total" >Shift</th>
<th class="celda_encabezado_total" >Machine On Time</th>
<th class="celda_encabezado_total" >Machine Off Time</th>
<th class="celda_encabezado_total" >Machine Running(hr)</th>
<th class="celda_encabezado_total" >Customer Name </th>
<th class="celda_encabezado_total" >Grade</th>
<th class="celda_encabezado_total" >Total Coating</th>
<th class="celda_encabezado_total" >Total Coating Sand(kg)</th>
<th class="celda_encabezado_total" >Total Gas Consumption</th>
<th class="celda_encabezado_total" >Hour Gas</th>
<th class="celda_encabezado_total" >Hour QTY(kg)</th>
</thead>
<tbody>
@ -1269,7 +1269,6 @@
var perHourCoatingSandQTY = row.find('td:eq(11)').text();
var batchCards = row.find('td:eq(13)').text().trim();
console.log(batchCards);
JSON.parse(batchCards).map(element => {

File diff suppressed because it is too large Load Diff