diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index e7743f36..ca0bc5d9 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -3017,110 +3017,67 @@ class StockController extends BaseController - public function trpProductionDetails(){ - - - 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(); - - $month = $session->get('stock_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(); - - if(empty($trpProductionMaintenanceData)){ - - $inserts = []; - - $inserts = $this->createDummyDataForTrp($startDate, $endDate); - - $freshEntry = true ; - - $data['trpProductionMaintenanceData'] = $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->response->setJSON($data); - - - return $this->loadViews("stock/trpProductionStockDetails", $this->global, $data, NULL); - + 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); } + diff --git a/app/Models/TrpProductionModel.php b/app/Models/TrpProductionModel.php index de14aba0..9630b004 100644 --- a/app/Models/TrpProductionModel.php +++ b/app/Models/TrpProductionModel.php @@ -67,13 +67,6 @@ class TrpProductionModel extends Model $materialCodes = array_column($subquery, 'materialCode'); // Extracts 'materialCode' values - - // dd($this->db->getLastQuery()); - - // Convert the array of material codes to a comma-separated string - // $materialCodesString = "'" . implode("','", $materialCodes) . "'"; - - // dd($materialCodes); // Define your table diff --git a/app/Views/stock/bagStockDetails.php b/app/Views/stock/bagStockDetails.php index b5029b1d..4f7ee1f1 100644 --- a/app/Views/stock/bagStockDetails.php +++ b/app/Views/stock/bagStockDetails.php @@ -1140,8 +1140,7 @@ // Apply left alignment to the date column firstTd.css("text-align", "left"); - $(this).find('th').eq(13).remove(); // Remove the last column (Actions) - $(this).find('td').eq(13).remove(); // Remove the last column (Actions) + }); diff --git a/app/Views/stock/dieselStockDetails.php b/app/Views/stock/dieselStockDetails.php index 329a44d1..a0525140 100644 --- a/app/Views/stock/dieselStockDetails.php +++ b/app/Views/stock/dieselStockDetails.php @@ -1457,8 +1457,6 @@ foreach ($period as $day) { // Apply left alignment to the date column firstTd.css("text-align", "left"); - $(this).find('th').eq(13).remove(); // Remove the last column (Actions) - $(this).find('td').eq(13).remove(); // Remove the last column (Actions) }); diff --git a/app/Views/stock/dustAndRoughStockDetails.php b/app/Views/stock/dustAndRoughStockDetails.php index cafd016b..a1499b11 100644 --- a/app/Views/stock/dustAndRoughStockDetails.php +++ b/app/Views/stock/dustAndRoughStockDetails.php @@ -664,8 +664,7 @@ // Apply left alignment to the date column firstTd.css("text-align", "left"); - $(this).find('th').eq(13).remove(); // Remove the last column (Actions) - $(this).find('td').eq(13).remove(); // Remove the last column (Actions) + }); diff --git a/app/Views/stock/gasStockDetails.php b/app/Views/stock/gasStockDetails.php index 9b80ab01..4318183e 100644 --- a/app/Views/stock/gasStockDetails.php +++ b/app/Views/stock/gasStockDetails.php @@ -1138,8 +1138,7 @@ function convertToDate(dateString) { // Apply left alignment to the date column firstTd.css("text-align", "left"); - $(this).find('th').eq(13).remove(); // Remove the last column (Actions) - $(this).find('td').eq(13).remove(); // Remove the last column (Actions) + }); diff --git a/app/Views/stock/powerConsumptionDetails.php b/app/Views/stock/powerConsumptionDetails.php index 4ecf77a8..adfa62bf 100644 --- a/app/Views/stock/powerConsumptionDetails.php +++ b/app/Views/stock/powerConsumptionDetails.php @@ -1396,8 +1396,6 @@ foreach ($period as $day) { // Apply left alignment to the date column firstTd.css("text-align", "left"); - $(this).find('th').eq(13).remove(); // Remove the last column (Actions) - $(this).find('td').eq(13).remove(); // Remove the last column (Actions) }); diff --git a/app/Views/stock/resinStockDetails.php b/app/Views/stock/resinStockDetails.php index a19c21cc..1e2f5799 100644 --- a/app/Views/stock/resinStockDetails.php +++ b/app/Views/stock/resinStockDetails.php @@ -1094,8 +1094,7 @@ foreach ($period as $day) { // Apply left alignment to the date column firstTd.css("text-align", "left"); - $(this).find('th').eq(13).remove(); // Remove the last column (Actions) - $(this).find('td').eq(13).remove(); // Remove the last column (Actions) + }); diff --git a/app/Views/stock/trpProductionStockDetails.php b/app/Views/stock/trpProductionStockDetails.php index 4269c2fe..cf94e0db 100644 --- a/app/Views/stock/trpProductionStockDetails.php +++ b/app/Views/stock/trpProductionStockDetails.php @@ -2212,6 +2212,61 @@ $timeOtions[] = "12:00 AM"; + + diff --git a/app/Views/stock/trpSandUseStockDetails.php b/app/Views/stock/trpSandUseStockDetails.php index 2e323579..a60188c9 100644 --- a/app/Views/stock/trpSandUseStockDetails.php +++ b/app/Views/stock/trpSandUseStockDetails.php @@ -694,8 +694,7 @@ // Apply left alignment to the date column firstTd.css("text-align", "left"); - $(this).find('th').eq(13).remove(); // Remove the last column (Actions) - $(this).find('td').eq(13).remove(); // Remove the last column (Actions) + });