stock module - 18-03-2025

This commit is contained in:
vadivelJ96 2025-03-18 12:18:22 +05:30
parent 0f455f98c3
commit 5c21e80fdf
5 changed files with 153 additions and 98 deletions

View File

@ -3017,65 +3017,120 @@ class StockController extends BaseController
public function trpProductionDetails()
{
$session = session(); // Store session instance once
if ($this->request->getMethod() === 'POST') {
$month = $this->request->getPost('month');
$date = DateTime::createFromFormat('M-Y', $month);
if (!$date) {
return $this->response->setJSON(['error' => 'Invalid month format']);
}
$month = $date->format('Y-m');
$session->set('stock_month', $month);
} else {
$month = $session->get('stock_month') ?? date('Y-m'); // Default to current month
}
$data = ['month' => $month];
$this->global['pageTitle'] = 'Trp Production Details';
$startDate = "$month-01";
$endDate = date("Y-m-t", strtotime($startDate));
// Fetch production maintenance data
$trpProductionMaintenanceData = $this->TrpProductionMaintenance_model
->where('date >=', $startDate)
->where('date <=', $endDate)
->find();
// Create dummy data if no records found
if (empty($trpProductionMaintenanceData)) {
$freshEntry = true;
$data['trpProductionMaintenanceData'] = $this->updateTrpProductionDetails(
$this->createDummyDataForTrp($startDate, $endDate),
$freshEntry
);
}
// Fetch related data
$result = $this->TrpProduction_model->trpProductionDetails($startDate, $endDate);
$data['trpProductionDetails'] = $result[0] ?? [];
$data['crsClientList'] = $result[1] ?? [];
$data['wcsSupplierList'] = $result[2] ?? [];
// Fetch abstract data and group by "particulars"
$trpAbstract = $this->trpAbstract_model->where('date', $startDate)->findAll();
$data['trpAbstract'] = array_column($trpAbstract, null, 'particulars');
// Format month for display
$date = DateTime::createFromFormat('Y-m', $month);
$data['month'] = $date->format('M-Y');
// Support AJAX responses
if ($this->request->isAJAX()) {
return $this->response->setJSON($data);
}
return $this->loadViews("stock/trpProductionStockDetails", $this->global, $data);
public function trpProductionDetails(){
//filtering month in post request
if ($this->request->getMethod() === 'POST') {
$month = $this->request->getPost('month');
$date = DateTime::createFromFormat('M-Y', $month);
$formattedDate = $date->format('Y-m');
$month = $formattedDate;
$session = session ();
$session->set('stock_month',$month);
} else {
$session = session();
//getting month from session if present
$month = $session->get('stock_month');
//else current month
if (empty($month)) {
$month = date('Y-m'); // Default to the current month
}
}
$data = [];
$data['month'] = $month;
$this->global['pageTitle'] = 'Trp production Details';
$startDate = "$month-01";
$endDate = date("Y-m-t", strtotime($startDate));
$trpProductionMaintenanceData = $this->TrpProductionMaintenance_model
->where('date >=', $startDate)
->where('date <=', $endDate)
->find();
/*
no data found for given month , create dummy data for that month
because trp production involves join with other tables which are entried by other users so it is better to be empty
and create dummy data for that month .else join wont work
*/
if(empty($trpProductionMaintenanceData)){
$inserts = [];
$inserts = $this->createDummyDataForTrp($startDate, $endDate);
$freshEntry = true ;
$this->updateTrpProductionDetails($inserts ,$freshEntry);
}
$result = $this->TrpProduction_model->trpProductionDetails($startDate,$endDate);
$data['trpProductionDetails'] = $result[0] ;
$data['crsClientList'] = $result[1] ;
$data['wcsSupplierList'] = $result[2] ;
$trpAbstract = $this->trpAbstract_model->where('date', $startDate)->findAll();
$groupedTrpAbstract = [] ;
foreach($trpAbstract as $abs){
if(!isset($groupedTrpAbstract[$abs['particulars']])){
$groupedTrpAbstract[$abs['particulars']] = $abs ;
}
}
$trpAbstract = $groupedTrpAbstract ;
$data['trpAbstract'] = $trpAbstract ;
// dd( $data['trpAbstract']['Incoming Raw Sand Details'] );
// dd((int)$trpAbstract["Incoming Raw Sand Details"]['opening_stock']);
$date = DateTime::createFromFormat('Y-m', $month);
$formattedDate = $date->format('M-Y');
$data['month'] = $formattedDate;
return $this->loadViews("stock/trpProductionStockDetails", $this->global, $data, NULL);
}
@ -3200,7 +3255,7 @@ class StockController extends BaseController
// Check if data already exists
if (isset($existingMaintenanceDateList[$date])) {
$dbDataTrpMaintenance['id'] = $existingMaintenanceDateList[$date]['id'];
$dbDataTrpMaintenance['id'] = (int) $existingMaintenanceDateList[$date]['id'];
$updateMaintenance[] = $dbDataTrpMaintenance;
} else {
@ -3211,7 +3266,7 @@ class StockController extends BaseController
if (isset($existingProductionDateList[$date])) {
$dbDataTrpProduction['id'] = $existingProductionDateList[$date]['id'];
$dbDataTrpProduction['id'] = (int) $existingProductionDateList[$date]['id'];
$updateProduction[] = $dbDataTrpProduction;
} else {
@ -3220,7 +3275,7 @@ class StockController extends BaseController
if (isset($existingWasteDateList[$date])) {
$dbDataTrpWaste['id'] = $existingWasteDateList[$date]['id'];
$dbDataTrpWaste['id'] = (int) $existingWasteDateList[$date]['id'];
$updateWaste[] = $dbDataTrpWaste;
} else {

View File

@ -12,7 +12,7 @@ class TrpProductionMaintenanceModel extends Model
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = ['date', 'openingTime', 'closingTime', 'totalHours', 'coldStart', 'breakdownHours', 'burnerFiringHours',
protected $allowedFields = ['id','date', 'openingTime', 'closingTime', 'totalHours', 'coldStart', 'breakdownHours', 'burnerFiringHours',
'sandFeedingHours', 'workingPersonEngineers', 'workingPersonSupervisiors', 'workingPersonOperators',
'rollerDrivers', 'natureOfMaintenance', 'location', 'description'];

View File

@ -13,7 +13,7 @@ class TrpProductionModel extends Model
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = ['date', 'gasReceiptBg', 'gasReceiptPg', 'physicalGasConsumption', 'trpPlusDrierGasConsumption',
protected $allowedFields = ['id','date', 'gasReceiptBg', 'gasReceiptPg', 'physicalGasConsumption', 'trpPlusDrierGasConsumption',
'trpPhysicalGasPerTon', 'panelGasConsumption','panelGasPerTon','edRunningHours','edProduction','edUsage',
'trpProduction', 'trpProductionPerHour', 'waterReceipt', 'waterConsumption' ,'ebReading',
'ebReadingPerUnitTon'];

View File

@ -12,7 +12,7 @@ class TrpProductionWasteModel extends Model
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = ['date','msSeperation','edWaste','coolerBags','edPlus20Waste','cycloneWaste'];
protected $allowedFields = ['id','date','msSeperation','edWaste','coolerBags','edPlus20Waste','cycloneWaste'];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;

View File

@ -1798,39 +1798,39 @@ $timeOtions[] = "12:00 AM";
Date : rowCells.eq(0).text().trim() ,
openingTime : openingTime ,
closingTime : closingTime ,
totalHours : $(this).find(`td[data-id='${dateInYmD} totalHours']`).text(),
coldStart : $(this).find(`td[data-id='${dateInYmD} coldStart']`).text() ,
breakdownHours : $(this).find(`td[data-id='${dateInYmD} breakdownHours']`).text() ,
burnerFiringHours : $(this).find(`td[data-id='${dateInYmD} burnerFiringHours']`).text() ,
sandFeedingHours : $(this).find(`td[data-id='${dateInYmD} sandFeedingHours']`).text() ,
gasReceiptBg : $(this).find(`td[data-id='${dateInYmD} gasReceiptBg']`).text() ,
gasReceiptPg : $(this).find(`td[data-id='${dateInYmD} gasReceiptPg']`).text() ,
physicalGasConsumption : $(this).find(`td[data-id='${dateInYmD} physicalGasConsumption']`).text() ,
trpPlusDrierGasConsumption : $(this).find(`td[data-id='${dateInYmD} trpPlusDrierGasConsumption']`).text() ,
trpPhysicalGasPerTon : $(this).find(`td[data-id='${dateInYmD} trpPhysicalGasPerTon']`).text() ,
panelGasConsumption : $(this).find(`td[data-id='${dateInYmD} panelGasConsumption']`).text() ,
panelGasPerTon : $(this).find(`td[data-id='${dateInYmD} panelGasPerTon']`).text() ,
edRunningHours : $(this).find(`td[data-id='${dateInYmD} edRunningHours']`).text() ,
edProduction : $(this).find(`td[data-id='${dateInYmD} edProduction']`).text() ,
edUsage : $(this).find(`td[data-id='${dateInYmD} edUsage']`) .text() ,
waterConsumption : $(this).find(`td[data-id='${dateInYmD} waterConsumption']`) .text() ,
trpProduction : $(this).find(`td[data-id='${dateInYmD} trpProduction']`) .text() ,
trpProductionPerHour : $(this).find(`td[data-id='${dateInYmD} trpProductionPerHour']`).text() ,
waterReceipt : $(this).find(`td[data-id='${dateInYmD} waterReceipt']`) .text() ,
ebReading : $(this).find(`td[data-id='${dateInYmD} ebReading']`) .text() ,
ebReadingPerUnitTon : $(this).find(`td[data-id='${dateInYmD} ebReadingPerUnitTon']`) .text() ,
workingPersonEngineers : $(this).find(`td[data-id='${dateInYmD} workingPersonEngineers']`).text() ,
workingPersonSupervisiors : $(this).find(`td[data-id='${dateInYmD} workingPersonSupervisiors']`).text() ,
workingPersonOperators : $(this).find(`td[data-id='${dateInYmD} workingPersonOperators']`).text() ,
rollerDrivers : $(this).find(`td[data-id='${dateInYmD} rollerDrivers']`).text() ,
natureOfMaintenance : $(this).find(`td[data-id='${dateInYmD} natureOfMaintenance']`).text() ,
location : $(this).find(`td[data-id='${dateInYmD} location']`).text() ,
description : $(this).find(`td[data-id='${dateInYmD} description']`).text() ,
msSeperation : $(this).find(`td[data-id='${dateInYmD} msSeperation']`).text() ,
edWaste : $(this).find(`td[data-id='${dateInYmD} edWaste']`).text() ,
coolerBags : $(this).find(`td[data-id='${dateInYmD} coolerBags']`).text() ,
edPlus20Waste : $(this).find(`td[data-id='${dateInYmD} edPlus20Waste']`).text() ,
cycloneWaste : $(this).find(`td[data-id='${dateInYmD} cycloneWaste']`).text() ,
totalHours : $(this).find(`td[data-id='${dateInYmD} totalHours']`).text().trim() ,
coldStart : $(this).find(`td[data-id='${dateInYmD} coldStart']`).text().trim() ,
breakdownHours : $(this).find(`td[data-id='${dateInYmD} breakdownHours']`).text().trim() ,
burnerFiringHours : $(this).find(`td[data-id='${dateInYmD} burnerFiringHours']`).text().trim() ,
sandFeedingHours : $(this).find(`td[data-id='${dateInYmD} sandFeedingHours']`).text().trim() ,
gasReceiptBg : $(this).find(`td[data-id='${dateInYmD} gasReceiptBg']`).text().trim() ,
gasReceiptPg : $(this).find(`td[data-id='${dateInYmD} gasReceiptPg']`).text().trim() ,
physicalGasConsumption : $(this).find(`td[data-id='${dateInYmD} physicalGasConsumption']`).text().trim() ,
trpPlusDrierGasConsumption : $(this).find(`td[data-id='${dateInYmD} trpPlusDrierGasConsumption']`).text().trim() ,
trpPhysicalGasPerTon : $(this).find(`td[data-id='${dateInYmD} trpPhysicalGasPerTon']`).text().trim() ,
panelGasConsumption : $(this).find(`td[data-id='${dateInYmD} panelGasConsumption']`).text().trim() ,
panelGasPerTon : $(this).find(`td[data-id='${dateInYmD} panelGasPerTon']`).text().trim() ,
edRunningHours : $(this).find(`td[data-id='${dateInYmD} edRunningHours']`).text().trim() ,
edProduction : $(this).find(`td[data-id='${dateInYmD} edProduction']`).text().trim() ,
edUsage : $(this).find(`td[data-id='${dateInYmD} edUsage']`) .text().trim() ,
waterConsumption : $(this).find(`td[data-id='${dateInYmD} waterConsumption']`) .text().trim() ,
trpProduction : $(this).find(`td[data-id='${dateInYmD} trpProduction']`) .text().trim() ,
trpProductionPerHour : $(this).find(`td[data-id='${dateInYmD} trpProductionPerHour']`).text().trim() ,
waterReceipt : $(this).find(`td[data-id='${dateInYmD} waterReceipt']`) .text().trim() ,
ebReading : $(this).find(`td[data-id='${dateInYmD} ebReading']`) .text().trim() ,
ebReadingPerUnitTon : $(this).find(`td[data-id='${dateInYmD} ebReadingPerUnitTon']`) .text().trim() ,
workingPersonEngineers : $(this).find(`td[data-id='${dateInYmD} workingPersonEngineers']`).text().trim() ,
workingPersonSupervisiors : $(this).find(`td[data-id='${dateInYmD} workingPersonSupervisiors']`).text().trim() ,
workingPersonOperators : $(this).find(`td[data-id='${dateInYmD} workingPersonOperators']`).text().trim() ,
rollerDrivers : $(this).find(`td[data-id='${dateInYmD} rollerDrivers']`).text().trim() ,
natureOfMaintenance : $(this).find(`td[data-id='${dateInYmD} natureOfMaintenance']`).text().trim() ,
location : $(this).find(`td[data-id='${dateInYmD} location']`).text().trim() ,
description : $(this).find(`td[data-id='${dateInYmD} description']`).text().trim() ,
msSeperation : $(this).find(`td[data-id='${dateInYmD} msSeperation']`).text().trim() ,
edWaste : $(this).find(`td[data-id='${dateInYmD} edWaste']`).text().trim() ,
coolerBags : $(this).find(`td[data-id='${dateInYmD} coolerBags']`).text().trim() ,
edPlus20Waste : $(this).find(`td[data-id='${dateInYmD} edPlus20Waste']`).text().trim() ,
cycloneWaste : $(this).find(`td[data-id='${dateInYmD} cycloneWaste']`).text().trim() ,
};