changes in stock module -vadivel J
This commit is contained in:
parent
d3fdd57fda
commit
b0c7236ec8
@ -18,6 +18,8 @@ use App\Models\ResinStockModel;
|
|||||||
use App\Models\GasStockModel;
|
use App\Models\GasStockModel;
|
||||||
use CodeIgniter\HTTP\ResponseInterface;
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use DatePeriod;
|
||||||
|
use DateInterval;
|
||||||
|
|
||||||
class StockController extends BaseController
|
class StockController extends BaseController
|
||||||
{
|
{
|
||||||
@ -855,10 +857,58 @@ class StockController extends BaseController
|
|||||||
echo "Data Saved Successfully";
|
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----------------------------------------------
|
// --------------------------------------------gwm----------------------------------------------
|
||||||
@ -1003,9 +1053,27 @@ class StockController extends BaseController
|
|||||||
|
|
||||||
if ($existingRow) {
|
if ($existingRow) {
|
||||||
// If exists, update the row
|
// 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);
|
$this->drierMachineDetails_model->update($existingRow['id'], $data);
|
||||||
} else {
|
} else {
|
||||||
// If not, insert a new row
|
// 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);
|
$this->drierMachineDetails_model->insert($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -195,8 +195,7 @@
|
|||||||
<!-- Right-aligned buttons or links can be added here -->
|
<!-- Right-aligned buttons or links can be added here -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
@ -354,7 +353,7 @@
|
|||||||
>0</td>
|
>0</td>
|
||||||
<td class="celda_normal consumption"
|
<td class="celda_normal consumption"
|
||||||
data-id="<?=$dateInMonth?>"
|
data-id="<?=$dateInMonth?>"
|
||||||
>0</td>
|
contenteditable="true">0</td>
|
||||||
<td class="celda_normal balanceStock"
|
<td class="celda_normal balanceStock"
|
||||||
data-id="<?=$dateInMonth?>"
|
data-id="<?=$dateInMonth?>"
|
||||||
>0</td>
|
>0</td>
|
||||||
@ -423,6 +422,7 @@
|
|||||||
$('#loader').hide();
|
$('#loader').hide();
|
||||||
console.log(data);
|
console.log(data);
|
||||||
alert(data);
|
alert(data);
|
||||||
|
window.location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user