diff --git a/api_test.http b/api_test.http
new file mode 100644
index 00000000..7987d0c0
--- /dev/null
+++ b/api_test.http
@@ -0,0 +1,4 @@
+
+
+// $routes->match(['GET', 'POST'], 'trpProductionDetails', 'StockController::trpProductionDetails');
+GET http://localhost/ci4/ria/trpProductionDetails
diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php
index 9cc49b91..3ae75a20 100644
--- a/app/Controllers/StockController.php
+++ b/app/Controllers/StockController.php
@@ -18,6 +18,9 @@ use App\Models\DustAndRoughModel;
use App\Models\ResinStockModel;
use App\Models\GasStockModel;
use App\Models\TrpSandUseStockModel;
+use App\Models\TrpProductionModel;
+use App\Models\TrpProductionMaintenanceModel;
+use App\Models\TrpProductionWasteModel;
use CodeIgniter\HTTP\ResponseInterface;
use DateTime;
use DatePeriod;
@@ -45,6 +48,12 @@ class StockController extends BaseController
protected $TrpSandUseStock_model;
+ protected $TrpProduction_model;
+
+ protected $TrpProductionMaintenance_model;
+
+ protected $TrpProductionWaste_model;
+
protected $db;
/**
@@ -85,6 +94,12 @@ class StockController extends BaseController
$this->TrpSandUseStock_model = new TrpSandUseStockModel();
+ $this->TrpProduction_model = new TrpProductionModel();
+
+ $this->TrpProductionMaintenance_model = new TrpProductionMaintenanceModel();
+
+ $this->TrpProductionWaste_model = new TrpProductionWasteModel();
+
$this->session = session();
helper('form');
@@ -1210,6 +1225,7 @@ class StockController extends BaseController
}
public function updateTrpSandUseStockDetails(){
+
$postData = $this->request->getPost();
$updateTrpSandUseStockDetailsData = json_decode($postData['updateTrpSandUseStockDetails'], true);
@@ -1266,9 +1282,186 @@ class StockController extends BaseController
- public function trpProductionDetails(){}
+ 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;
+ } else {
+ $month = date('Y-m');
+ }
+
+ $data = [];
+
+ $data['month'] = $month;
+
+ $this->global['pageTitle'] = 'Trp production Details';
+
+ $startDate = "$month-01";
+ $endDate = date("Y-m-t", strtotime($startDate));
+
+
+
+ $data['trpProductionDetails'] = $this->TrpProduction_model->trpProductionDetails($startDate,$endDate);
+
+ // dd($data['trpProductionDetails']);
+
+ // dd($this->db->getLastQuery());
+
+
+ $date = DateTime::createFromFormat('Y-m', $month);
+
+ $formattedDate = $date->format('M-Y');
+
+ $data['month'] = $formattedDate;
+
+ // return $this->response->setJSON($data);
+
+ return $this->loadViews("trpProductionStockDetails", $this->global, $data, NULL);
+
+
+
+ }
+
+ public function updateTrpProductionDetails() {
+
+ $postData = $this->request->getPost();
+
+ $updateTrpProductionDetails = json_decode($postData['updateTrpProductionDetails'], true);
+
+ $updateProduction = [];
+ $updateMaintanence = [];
+ $updateWaste = [];
+
+ $insertProduction = [];
+ $insertMaintanence = [];
+ $insertWaste = [];
+
+ 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'],
+ ];
+
+ $trpMaintenanceResultExists = $this->TrpProductionMaintenance_model
+ ->where('date', $date)
+ ->first();
+
+ $trpProductionResultExists = $this->TrpProduction_model
+ ->where('date', $date)
+ ->first();
+
+ $trpWasteResultExists = $this->TrpProductionWaste_model
+ ->where('date', $date)
+ ->first();
+
+ if (empty($trpMaintenanceResultExists)) {
+ $insertMaintanence[] = $dbDataTrpMaintenance;
+ $insertProduction[] = $dbDataTrpProduction;
+ $insertWaste[] = $dbDataTrpWaste;
+ } else {
+ $dbDataTrpMaintenance['id'] = $trpMaintenanceResultExists['id'];
+ $dbDataTrpProduction['id'] = $trpProductionResultExists['id'];
+ $dbDataTrpWaste['id'] = $trpWasteResultExists['id'];
+
+ $updateMaintanence[] = $dbDataTrpMaintenance;
+ $updateProduction[] = $dbDataTrpProduction;
+ $updateWaste[] = $dbDataTrpWaste;
+ }
+ }
+
+ // Start the transaction
+ $this->db->transBegin();
+
+ try {
+ if (!empty($insertMaintanence)) {
+ $this->TrpProductionMaintenance_model->insertBatch($insertMaintanence);
+ }
+
+ if (!empty($insertProduction)) {
+ $this->TrpProduction_model->insertBatch($insertProduction);
+ }
+
+ if (!empty($insertWaste)) {
+ $this->TrpProductionWaste_model->insertBatch($insertWaste);
+ }
+
+ if (!empty($updateMaintanence)) {
+ $this->TrpProductionMaintenance_model->updateBatch($updateMaintanence, '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();
+ }
+ }
- public function updateTrpProductionDetails(){}
diff --git a/app/Models/TrpProductionMaintenanceModel.php b/app/Models/TrpProductionMaintenanceModel.php
new file mode 100644
index 00000000..ca39b46e
--- /dev/null
+++ b/app/Models/TrpProductionMaintenanceModel.php
@@ -0,0 +1,48 @@
+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.TotalRsQuantity,
+
+ tigrd.TotalQuantityAsPerInvoice
+
+
+ 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/Models/TrpProductionWasteModel.php b/app/Models/TrpProductionWasteModel.php
new file mode 100644
index 00000000..35992563
--- /dev/null
+++ b/app/Models/TrpProductionWasteModel.php
@@ -0,0 +1,46 @@
+
+ .num {
+ text-align: right;
+ }
+
+ .fht-table,
+ .fht-table thead,
+ .fht-table tfoot,
+ .fht-table tbody,
+ .fht-table tr,
+ .fht-table th,
+ .fht-table td {
+ margin: 0;
+ }
+
+ .fht-table td {
+ text-align: center;
+ }
+
+ .fht-table td:hover {
+ background-color: #00a65a;
+ color: #ffffff;
+ }
+
+ .fht-table {
+ border: 0 none;
+ height: auto;
+ width: auto;
+ border-collapse: collapse;
+ border-spacing: 0;
+ /*table-layout: fixed; Algoritmo de distribucion fijo */
+ white-space: nowrap;
+ }
+
+ .fht-table th,
+ .fht-table td {
+ overflow: hidden;
+ }
+
+ .fht-table-wrapper,
+ .fht-table-wrapper .fht-thead,
+ .fht-table-wrapper .fht-tfoot,
+ .fht-table-wrapper .fht-fixed-column .fht-tbody,
+ .fht-table-wrapper .fht-fixed-body .fht-tbody,
+ .fht-table-wrapper .fht-tbody {
+ overflow: hidden;
+ position: relative;
+ }
+
+ .fht-table-wrapper .fht-fixed-body .fht-tbody,
+ .fht-table-wrapper .fht-tbody {
+ overflow: auto;
+ }
+
+ .fht-table-wrapper .fht-table .fht-cell {
+ overflow: hidden;
+ height: 1px;
+ }
+
+ .fht-table-wrapper .fht-fixed-column,
+ .fht-table-wrapper .fht-fixed-body {
+ top: 0;
+ left: 0;
+ position: absolute;
+ }
+
+ .fht-table-wrapper .fht-fixed-column {
+ z-index: 1;
+ }
+
+ .fht-fixed-body .fht-thead table {
+ margin-right: 20px;
+ border: 0 none;
+ }
+
+ /*For Examples*/
+
+ .ContenedorTabla {
+ height: 500px;
+ margin: 0 auto;
+ overflow: auto;
+ width: auto;
+ position: relative;
+ }
+
+ .header,
+ .main {
+ display: inline-block;
+ height: auto;
+ width: 100%;
+ }
+
+ .titulosHeader {
+ border-bottom: 1px solid #e8bb25;
+ height: auto;
+ margin-bottom: 10px;
+ padding-bottom: 8px;
+ padding-top: 8px;
+ width: 100%;
+ }
+
+
+ .celda_encabezado_general {
+ background-color: #00a65a;
+ border: 1px solid #ccc;
+ color: #ffffff;
+ font-weight: bold;
+ padding: 6px 10px;;
+ text-align: center;
+ }
+
+
+ ._Separador {
+ background-color: #fff;
+ height: 12px;
+ border-left: 1px solid #ccc;
+ border-right: 1px solid #ccc;
+ width: 7px;
+ }
+
+ ._Separador div {
+ width: 4px;
+ }
+
+ .celda_normal {
+ /*background-color: #fff;*/
+ /* */
+ text-align: center;
+ border: 1px solid #ccc;
+ padding: 2px 4px;
+ }
+
+ /*style excel*/
+ .excel_cell {
+ border: 1px solid #CCC;
+ color: #222;
+ text-align: center;
+ font-size: 13px;
+ font-weight: normal;
+ padding: 4px;
+ white-space: pre-line;
+ empty-cells: show;
+ }
+
+ ._cell_header {
+ background-color: #EEE;
+ }
+
+ ._cell_Default {
+ background-color: #FFF;
+ text-align: left;
+ }
+
+ .excel_cell div {
+ width: 30px;
+ height: 20px;
+ }
+
+ #trpProductionStockDetailsTableId th:nth-child(1),
+ #trpProductionStockDetailsTableId td:nth-child(1) {
+ position: sticky;
+ left: 0;
+ background-color: #00a65a;
+ z-index: 2;
+ border-right: 2px solid #ddd;
+ color: #ffffff;
+ }
+
+ .modal {
+ padding-right: 30% ! important;
+ }
+
+
+
+
+ modify('first day of this month')->format('Y-m-d');
+ $endDate = $date->modify('last day of this month')->format('Y-m-d');
+
+ $datesInMonth = [];
+
+
+ $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');
+ }
+
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Stocks
+ -
+
TRP Production Stock Details
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | 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 |
+
+
+
+
+
+
+
+
+ | 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 |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $dateInMonth)
+ {
+
+ ?>
+
+ format('d-m-Y');
+ if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';}
+ ?>
+
+ >
+
+
+
+ |
+ = $dateInMonthDmYFormat ?>
+ |
+
+
+
+
+ 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
+ |
+
+
+
+
+ 0
+ |
+
+
+
+
+ 0
+ |
+
+
+
+
+ 0
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+