diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index 8b282ad0..c0d96a57 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -1307,81 +1307,12 @@ class StockController extends BaseController $endDate = date("Y-m-t", strtotime($startDate)); - // Subquery definition - $subquery = $this->db->table('t_materialmaster') - ->select('materialCode') - ->where('Category', 'waste core') - ->get() - ->getResultArray(); + + $data['trpProductionDetails'] = $this->TrpProduction_model->trpProductionDetails($startDate,$endDate); - $materialCodes = array_column($subquery, 'materialCode'); // Extracts 'materialCode' values + // dd($data['trpProductionDetails']); - // Convert the array of material codes to a comma-separated string - $materialCodesString = "'" . implode("','", $materialCodes) . "'"; - - // Main query - $sql = "SELECT - tpmd.*, - tpd.*, - tpwd.*, - tsu.*, - ip_invoice_items.*, - tigrd.* , - ts.SupplierName - FROM - t_trpProductionMaintenanceDetails tpmd - JOIN - t_trpProductionDetails tpd ON tpd.date = tpmd.date - JOIN - t_trpProductionWasteDetails tpwd ON tpwd.date = tpmd.date - LEFT JOIN - t_coatingMachineDetails tcmd ON tcmd.date = tpmd.date - LEFT JOIN - t_drierMachineDetails tdmd ON tdmd.date = tpmd.date - LEFT JOIN - t_trp_sand_use tsu ON tsu.date = tpmd.date - LEFT JOIN - ip_invoice_items ON ip_invoice_items.item_date_added = tpmd.date - AND ip_invoice_items.item_name = 'Core Sand Reclaimed' - - - - LEFT JOIN - t_igr_details tigrd - ON DATE(tigrd.CreatedDate) = tpmd.date - AND tigrd.MaterialCode IN ($materialCodesString) - - LEFT JOIN - t_igr_master tigm - ON tigm.IGRNo = tigrd.IGRNo - - LEFT JOIN - t_purchaseorder_master tpom - ON tpom.PONO = tigm.PONO - - LEFT JOIN - t_supplierdetailsn ts - ON tpom.SupplierID = ts.SupplierID - - - WHERE - tpmd.date >= ? - AND - tpmd.date <= ? - - Group BY - ts.SupplierName , tpmd.date , tigrd.MaterialCode - - - - ORDER BY - tpmd.date ASC"; - - // Execute the query - $query = $this->db->query($sql, [ $startDate, $endDate]); - $data['trpProductionDetails'] = $query->getResultArray(); - - dd($data['trpProductionDetails']); + // dd($this->db->getLastQuery()); $date = DateTime::createFromFormat('Y-m', $month); @@ -1392,7 +1323,7 @@ class StockController extends BaseController return $this->response->setJSON($data); - // return $this->loadViews("trpSandUseStockDetails", $this->global, $data, NULL); + // return $this->loadViews("trpProductionStockDetails", $this->global, $data, NULL); @@ -1532,151 +1463,6 @@ class StockController extends BaseController } - // public function updateTrpProductionDetails() { - // $postData = $this->request->getPost(); - // $updateTrpProductionDetails = json_decode($postData['updateTrpProductionDetails'], true); - - // $updateProduction = []; - // $updateMaintenance = []; - // $updateWaste = []; - - // $insertProduction = []; - // $insertMaintenance = []; - // $insertWaste = []; - - // // Extract dates from the data - // $dates = array_column($updateTrpProductionDetails, 'Date'); - // $formattedDates = array_map(function($date) { - // return $this->convertToDateWithFlexibleFormats($date, ["d-m-Y", "Y-m-d", "m/d/Y", "m-d-Y"], "Y-m-d"); - // }, $dates); - - // // Fetch existing records in bulk - // $existingMaintenanceRecords = $this->TrpProductionMaintenance_model->whereIn('date', $formattedDates)->findAll(); - // $existingProductionRecords = $this->TrpProduction_model->whereIn('date', $formattedDates)->findAll(); - // $existingWasteRecords = $this->TrpProductionWaste_model->whereIn('date', $formattedDates)->findAll(); - - // // Convert fetched records to associative arrays for quick lookup - // $existingMaintenanceMap = []; - // foreach ($existingMaintenanceRecords as $record) { - // $existingMaintenanceMap[$record['date']] = $record; - // } - - // $existingProductionMap = []; - // foreach ($existingProductionRecords as $record) { - // $existingProductionMap[$record['date']] = $record; - // } - - // $existingWasteMap = []; - // foreach ($existingWasteRecords as $record) { - // $existingWasteMap[$record['date']] = $record; - // } - - // foreach ($updateTrpProductionDetails as $data) { - // $data['date'] = $this->convertToDateWithFlexibleFormats($data['Date'], ["d-m-Y", "Y-m-d", "m/d/Y", "m-d-Y"], "Y-m-d"); - // $date = $data['date']; - - // $dbDataTrpMaintenance = [ - // 'date' => $data['date'], - // 'openingTime' => $data['openingTime'], - // 'closingTime' => $data['closingTime'], - // 'totalHours' => $data['totalHours'], - // 'coldStart' => $data['coldStart'], - // 'breakdownHours' => $data['breakdownHours'], - // 'burnerFiringHours' => $data['burnerFiringHours'], - // 'sandFeedingHours' => $data['sandFeedingHours'], - // 'workingPersonEngineers' => $data['workingPersonEngineers'], - // 'workingPersonSupervisiors' => $data['workingPersonSupervisiors'], - // 'workingPersonOperators' => $data['workingPersonOperators'], - // 'rollerDrivers' => $data['rollerDrivers'], - // 'natureOfMaintenance' => $data['natureOfMaintenance'], - // 'location' => $data['location'], - // 'description' => $data['description'] - // ]; - - // $dbDataTrpProduction = [ - // 'date' => $data['date'], - // 'gasReceiptBg' => $data['gasReceiptBg'], - // 'gasReceiptPg' => $data['gasReceiptPg'], - // 'physicalGasConsumption' => $data['physicalGasConsumption'], - // 'trpPlusDrierGasConsumption' => $data['trpPlusDrierGasConsumption'], - // 'trpPhysicalGasPerTon' => $data['trpPhysicalGasPerTon'], - // 'panelGasConsumption' => $data['panelGasConsumption'], - // 'panelGasPerTon' => $data['panelGasPerTon'], - // 'edRunningHours' => $data['edRunningHours'], - // 'edProduction' => $data['edProduction'], - // 'edUsage' => $data['edUsage'], - // 'trpProduction' => $data['trpProduction'], - // 'trpProductionPerHour' => $data['trpProductionPerHour'], - // 'waterReceipt' => $data['waterReceipt'], - // 'waterConsumption' => $data['waterConsumption'], - // 'ebReading' => $data['ebReading'], - // 'ebReadingPerUnitTon' => $data['ebReadingPerUnitTon'] - // ]; - - // $dbDataTrpWaste = [ - // 'date' => $data['date'], - // 'msSeperation' => $data['msSeperation'], - // 'edWaste' => $data['edWaste'], - // 'coolerBags' => $data['coolerBags'], - // 'edPlus20Waste' => $data['edPlus20Waste'], - // 'cycloneWaste' => $data['cycloneWaste'] - // ]; - - // if (empty($existingMaintenanceMap[$date])) { - // $insertMaintenance[] = $dbDataTrpMaintenance; - // $insertProduction[] = $dbDataTrpProduction; - // $insertWaste[] = $dbDataTrpWaste; - // } else { - // $dbDataTrpMaintenance['id'] = $existingMaintenanceMap[$date]['id']; - // $dbDataTrpProduction['id'] = $existingProductionMap[$date]['id']; - // $dbDataTrpWaste['id'] = $existingWasteMap[$date]['id']; - - // $updateMaintenance[] = $dbDataTrpMaintenance; - // $updateProduction[] = $dbDataTrpProduction; - // $updateWaste[] = $dbDataTrpWaste; - // } - // } - - // // Start the transaction - // $this->db->transBegin(); - - // try { - // if (!empty($insertMaintenance)) { - // $this->TrpProductionMaintenance_model->insertBatch($insertMaintenance); - // } - - // if (!empty($insertProduction)) { - // $this->TrpProduction_model->insertBatch($insertProduction); - // } - - // if (!empty($insertWaste)) { - // $this->TrpProductionWaste_model->insertBatch($insertWaste); - // } - - // if (!empty($updateMaintenance)) { - // $this->TrpProductionMaintenance_model->updateBatch($updateMaintenance, 'id'); - // } - - // if (!empty($updateProduction)) { - // $this->TrpProduction_model->updateBatch($updateProduction, 'id'); - // } - - // if (!empty($updateWaste)) { - // $this->TrpProductionWaste_model->updateBatch($updateWaste, 'id'); - // } - - // // Commit the transaction if all operations are successful - // $this->db->transCommit(); - // echo "Data Saved Successfully"; - - // } catch (\Exception $error) { - // // Rollback the transaction in case of any errors - // $this->db->transRollback(); - // echo "An error occurred: " . $error->getMessage(); - // } - // } - - diff --git a/app/Models/TrpProductionModel.php b/app/Models/TrpProductionModel.php index 7f6bc916..02cf5ba8 100644 --- a/app/Models/TrpProductionModel.php +++ b/app/Models/TrpProductionModel.php @@ -46,4 +46,189 @@ class TrpProductionModel extends Model protected $afterFind = []; protected $beforeDelete = []; protected $afterDelete = []; + + + + + public function trpProductionDetails($startDate,$endDate){ + + + + // Subquery definition + $subquery = $this->db->table('t_materialmaster') + ->select('materialCode') + ->where('Category', 'waste core') + ->get() + ->getResultArray(); + + $materialCodes = array_column($subquery, 'materialCode'); // Extracts 'materialCode' values + + // Convert the array of material codes to a comma-separated string + $materialCodesString = "'" . implode("','", $materialCodes) . "'"; + + + $sql = "SELECT + + tpmd.date, + tpmd.openingTime, + tpmd.closingTime, + tpmd.totalHours, + tpmd.coldStart, + tpmd.breakdownHours, + tpmd.burnerFiringHours, + tpmd.sandFeedingHours, + tpmd.workingPersonEngineers, + tpmd.workingPersonSupervisiors, + tpmd.workingPersonOperators, + tpmd.rollerDrivers, + tpmd.natureOfMaintenance, + tpmd.location, + tpmd.description, + + + + tpd.gasReceiptBg, + tpd.gasReceiptPg, + tpd.physicalGasConsumption, + tpd.trpPlusDrierGasConsumption, + tpd.trpPhysicalGasPerTon, + tpd.panelGasConsumption, + tpd.panelGasPerTon, + tpd.edRunningHours, + tpd.edProduction, + tpd.edUsage, + tpd.trpProduction, + tpd.trpProductionPerHour, + tpd.waterReceipt, + tpd.waterConsumption, + tpd.ebReading, + tpd.ebReadingPerUnitTon, + + + tpwd.msSeperation, + tpwd.edWaste, + tpwd.coolerBags, + tpwd.edPlus20Waste, + tpwd.cycloneWaste, + + + tcmd.totalGasConsumption as coatingGasConsumption, + + tdmd.total_gas_consumption as drierGasConsumption, + + + tsu.total_kgs as coating, + + invItems.item_date_added, + invItems.client_name, + invItems.TotalRsQuantity, + + tigrd.SupplierName, + tigrd.TotalQuantityAsPerInvoice, + tigrd.CreatedDate + + + FROM + t_trpProductionMaintenanceDetails tpmd + JOIN + t_trpProductionDetails tpd ON tpd.date = tpmd.date + JOIN + t_trpProductionWasteDetails tpwd ON tpwd.date = tpmd.date + LEFT JOIN + t_coatingMachineDetails tcmd ON tcmd.date = tpmd.date + LEFT JOIN + t_drierMachineDetails tdmd ON tdmd.date = tpmd.date + LEFT JOIN + t_trp_sand_use tsu ON tsu.date = tpmd.date + + + + LEFT JOIN + ( + Select + clients.client_name, + invItems.item_date_added, + SUM(invItems.item_quantity) AS TotalRsQuantity + + from ip_invoice_items invItems + + -- All joins to get client name thats it + LEFT JOIN + ip_invoices inv + ON inv.invoice_id = invItems.invoice_id + + LEFT JOIN + ip_clients clients + ON clients.client_id = inv.client_id + + -- getting core reclamation sand + Where invItems.item_name = 'Core Sand Reclaimed' + + -- grouping Client who provides reclamation sand on a particular date with 1 or more invoices + Group By invItems.item_date_added , clients.client_name + + ) invItems + ON invItems.item_date_added = tpmd.date + + + + LEFT JOIN + ( + Select tigrd.CreatedDate ,tigrd.MaterialCode , tigrd.IGRNo , ts.SupplierName, + SUM(QuantityAsPerInvoice) AS TotalQuantityAsPerInvoice + + from t_igr_details tigrd + + -- All joins to get supplier name thats it + LEFT JOIN + t_igr_master tigm + ON tigm.IGRNo = tigrd.IGRNo + + LEFT JOIN + t_purchaseorder_master tpom + ON tpom.PONO = tigm.PONO + + LEFT JOIN + t_supplierdetailsn ts + ON tpom.SupplierID = ts.SupplierID + + -- getting waste core sands using three distinct material codes + Where tigrd.MaterialCode IN ($materialCodesString) + + -- grouping supplier who provides waste core on a particular date with 1 or more IGRS + Group By Date(tigrd.CreatedDate) , ts.SupplierName + + ) tigrd + ON DATE(tigrd.CreatedDate) = tpmd.date + + + + + WHERE + tpmd.date >= ? + AND + tpmd.date <= ? + + + ORDER BY + tpmd.date ASC"; + + // Execute the query + $query = $this->db->query($sql, [ $startDate, $endDate]); + + $result = $query->getResultArray(); + + return $result; + + } + + + + + + + + + + } diff --git a/app/Views/trpProductionStockDetails.php b/app/Views/trpProductionStockDetails.php index cdf44e75..86e9730f 100644 --- a/app/Views/trpProductionStockDetails.php +++ b/app/Views/trpProductionStockDetails.php @@ -210,7 +210,7 @@ @@ -265,33 +265,134 @@ - - material - - - - - - - - + + Date + + Opening Time + + Closing Time + + Total Hours + + Cold Start + + Break Down Hours + + Burner Firing Hours + + Sand Feeding Hours + + Gas Receipt + + Physical Gas Consumption + + Drier Gas Consumption + + Coating Gas Consumption + + TRP plus Drier Gas Consumption + + TRP Physical Gas Per Ton + + Panel Gas Consumption + + Panel Gas Per Ton + + Incoming Sand/ Lump details + + ED details + + TRP Sand + + Usage + + Water + + EB Reading + + EB Unit Per Ton + + Working Persons + + Maintanence Details + + Description + + MS Seperation + + ED Waste + + Cooler Bags + + ED +20 Waste + + Cyclone Waste + + - - Date + + + BG + + PG + + AL(S) + + AL(E) + + ME + + SI + + caparo + + Nemak + + DR + + Running Hours + + Production + + Usage + + Production + + Production Per Hour + + Coating + + Hindhuja + + Nemak + + ME + + BI + + Karmen + + Receipt + + Consumption + + Engineers + + Supervisors + + Operators + + Roller Drivers + + Nature Of Maintenance + + Location + - - - Date - material - customer - Opening Stock - Receipt - Used - Balance Stock - + @@ -299,147 +400,486 @@ - $resinStockDetails){ - ?> - - format('d-m-Y'); - if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';} - ?> - > - $resinStock){ ?> - - format('d-m-Y'); - ?> - - - - - - - - - - - - - - - oninput="openingStockChange(this)" - contenteditable="true" - - > - - - - - - - - - - - - - - $dateInMonth){ ?> - + + + 54465656 + - + + + 0 + - $currentDate = date('d-m-Y'); - $dateInMonthDmYFormat= DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y'); - if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';} - ?> - > - $resinMaterial){ ?> - + + + + 0 + - - format('d-m-Y'); - ?> - - - - - - - - + + + + 0 + - - - + + + + 0 + - - - + + + + 0 + - - - oninput="openingStockChange(this)" - contenteditable="true" + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + + 0 + + + + + + 0 + + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + - - > - 0 - 0 - - - - @@ -467,7 +907,7 @@