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() public function trpProductionDetails(){
{
$session = session(); // Store session instance once //filtering month in post request
if ($this->request->getMethod() === 'POST') { if ($this->request->getMethod() === 'POST') {
$month = $this->request->getPost('month'); $month = $this->request->getPost('month');
$date = DateTime::createFromFormat('M-Y', $month); $date = DateTime::createFromFormat('M-Y', $month);
if (!$date) { $formattedDate = $date->format('Y-m');
return $this->response->setJSON(['error' => 'Invalid month format']);
} $month = $formattedDate;
$session = session ();
$month = $date->format('Y-m');
$session->set('stock_month',$month); $session->set('stock_month',$month);
} else { } else {
$month = $session->get('stock_month') ?? date('Y-m'); // Default to current month
$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 = ['month' => $month]; }
$this->global['pageTitle'] = 'Trp Production Details';
$data = [];
$data['month'] = $month;
$this->global['pageTitle'] = 'Trp production Details';
$startDate = "$month-01"; $startDate = "$month-01";
$endDate = date("Y-m-t", strtotime($startDate)); $endDate = date("Y-m-t", strtotime($startDate));
// Fetch production maintenance data
$trpProductionMaintenanceData = $this->TrpProductionMaintenance_model $trpProductionMaintenanceData = $this->TrpProductionMaintenance_model
->where('date >=', $startDate) ->where('date >=', $startDate)
->where('date <=', $endDate) ->where('date <=', $endDate)
->find(); ->find();
// Create dummy data if no records found /*
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)){ if(empty($trpProductionMaintenanceData)){
$inserts = [];
$inserts = $this->createDummyDataForTrp($startDate, $endDate);
$freshEntry = true ; $freshEntry = true ;
$data['trpProductionMaintenanceData'] = $this->updateTrpProductionDetails(
$this->createDummyDataForTrp($startDate, $endDate), $this->updateTrpProductionDetails($inserts ,$freshEntry);
$freshEntry
);
} }
// Fetch related data
$result = $this->TrpProduction_model->trpProductionDetails($startDate,$endDate); $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" $data['trpProductionDetails'] = $result[0] ;
$data['crsClientList'] = $result[1] ;
$data['wcsSupplierList'] = $result[2] ;
$trpAbstract = $this->trpAbstract_model->where('date', $startDate)->findAll(); $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()) { $groupedTrpAbstract = [] ;
return $this->response->setJSON($data);
foreach($trpAbstract as $abs){
if(!isset($groupedTrpAbstract[$abs['particulars']])){
$groupedTrpAbstract[$abs['particulars']] = $abs ;
}
} }
return $this->loadViews("stock/trpProductionStockDetails", $this->global, $data); $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 // Check if data already exists
if (isset($existingMaintenanceDateList[$date])) { if (isset($existingMaintenanceDateList[$date])) {
$dbDataTrpMaintenance['id'] = $existingMaintenanceDateList[$date]['id']; $dbDataTrpMaintenance['id'] = (int) $existingMaintenanceDateList[$date]['id'];
$updateMaintenance[] = $dbDataTrpMaintenance; $updateMaintenance[] = $dbDataTrpMaintenance;
} else { } else {
@ -3211,7 +3266,7 @@ class StockController extends BaseController
if (isset($existingProductionDateList[$date])) { if (isset($existingProductionDateList[$date])) {
$dbDataTrpProduction['id'] = $existingProductionDateList[$date]['id']; $dbDataTrpProduction['id'] = (int) $existingProductionDateList[$date]['id'];
$updateProduction[] = $dbDataTrpProduction; $updateProduction[] = $dbDataTrpProduction;
} else { } else {
@ -3220,7 +3275,7 @@ class StockController extends BaseController
if (isset($existingWasteDateList[$date])) { if (isset($existingWasteDateList[$date])) {
$dbDataTrpWaste['id'] = $existingWasteDateList[$date]['id']; $dbDataTrpWaste['id'] = (int) $existingWasteDateList[$date]['id'];
$updateWaste[] = $dbDataTrpWaste; $updateWaste[] = $dbDataTrpWaste;
} else { } else {

View File

@ -12,7 +12,7 @@ class TrpProductionMaintenanceModel extends Model
protected $returnType = 'array'; protected $returnType = 'array';
protected $useSoftDeletes = false; protected $useSoftDeletes = false;
protected $protectFields = true; 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', 'sandFeedingHours', 'workingPersonEngineers', 'workingPersonSupervisiors', 'workingPersonOperators',
'rollerDrivers', 'natureOfMaintenance', 'location', 'description']; 'rollerDrivers', 'natureOfMaintenance', 'location', 'description'];

View File

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

View File

@ -12,7 +12,7 @@ class TrpProductionWasteModel extends Model
protected $returnType = 'array'; protected $returnType = 'array';
protected $useSoftDeletes = false; protected $useSoftDeletes = false;
protected $protectFields = true; 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 $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true; protected bool $updateOnlyChanged = true;

View File

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