changes in stock module -vadivel J

This commit is contained in:
vadivel J 2024-11-13 17:08:16 +05:30
parent d3fdd57fda
commit b0c7236ec8
2 changed files with 71 additions and 3 deletions

View File

@ -18,6 +18,8 @@ use App\Models\ResinStockModel;
use App\Models\GasStockModel;
use CodeIgniter\HTTP\ResponseInterface;
use DateTime;
use DatePeriod;
use DateInterval;
class StockController extends BaseController
{
@ -855,10 +857,58 @@ class StockController extends BaseController
echo "Data Saved Successfully";
}
private function updateGasStockConsumption($date , $consumption){
echo"$date";
$resultExists = $this->gasStockDetails_model
->where('date',$date)
->first();
if($resultExists){
$resultExists['consumption'] = $resultExists['consumption']+($consumption);
$this->gasStockDetails_model->update($resultExists['id'],$resultExists);
}
else{
$startDate = DateTime::createFromFormat('Y-m-d', $date)->modify('first day of this month')->format('Y-m-d');
$endDate = DateTime::createFromFormat('Y-m-d', $date)->modify('last day of this month')->format('Y-m-d');
$datesInMonth = [];
$inserts = [];
$period = new DatePeriod(
new DateTime($startDate),
new DateInterval('P1D'),
(new DateTime($endDate))->modify('+1 day')
);
foreach ($period as $day) {
$datesInMonth[] = $day->format('Y-m-d');
}
foreach ($datesInMonth as $datesInMonthIndex => $dateInMonth) {
$inserts[] = [
'date' => $dateInMonth,
'opening' => 0,
'purchaseBharath' => 0,
'purchaseIndian' => 0,
'total' => 0,
'consumption' => $dateInMonth == $date ? $consumption : 0 ,
'balanceStock' => 0
];
}
if(!empty($inserts)){
$this->gasStockDetails_model->insertBatch($inserts);
}
}
}
// --------------------------------------------gwm----------------------------------------------
@ -1003,9 +1053,27 @@ class StockController extends BaseController
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);
}
$this->drierMachineDetails_model->update($existingRow['id'], $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->drierMachineDetails_model->insert($data);
}
}

View File

@ -195,8 +195,7 @@
<!-- Right-aligned buttons or links can be added here -->
</div>
</div>
<div class="row">
<div class="col-12">
@ -354,7 +353,7 @@
>0</td>
<td class="celda_normal consumption"
data-id="<?=$dateInMonth?>"
>0</td>
contenteditable="true">0</td>
<td class="celda_normal balanceStock"
data-id="<?=$dateInMonth?>"
>0</td>
@ -423,6 +422,7 @@
$('#loader').hide();
console.log(data);
alert(data);
window.location.reload();
}
},