diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index 9cc49b91..c581aa30 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,183 @@ class StockController extends BaseController - public function trpProductionDetails(){} + public function trpProductionDetails(){ - public function updateTrpProductionDetails(){} + + 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->TrpProductionMaintenance_model + ->join('t_trpProduction', 't_trpProduction.date = t_trpProductionMaintenance.date') + ->join('t_trpProductionWaste', 't_trpProductionWaste.date = t_trpProductionMaintenance.date') + ->join('t_') + ->where('date >=', $startDate) + ->where('date <=', $endDate) + ->orderBy('date', 'asc') + ->findAll(); + + $date = DateTime::createFromFormat('Y-m', $month); + + $formattedDate = $date->format('M-Y'); + + $data['month'] = $formattedDate; + + return $this->loadViews("trpSandUseStockDetails", $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(); + } + } + 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 @@ + + .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; + } + + #resinStockDetailsTableId th:nth-child(1), + #resinStockDetailsTableId 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'); + } + + ?> + + + +
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+
+ + + +
+
+
+
+ + +
+
+ +
+ " + class="form-control mt-2" data-provide="datepicker" + data-date-format="M-yyyy" data-date-min-view-mode="1"> +
+
+ +
+
+
+ +
+
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $resinStockDetails){ + ?> + format('d-m-Y'); + if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';} + ?> + > + $resinStock){ ?> + + format('d-m-Y'); + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + $dateInMonth){ ?> + format('d-m-Y'); + if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';} + ?> + > + $resinMaterial){ ?> + + + + format('d-m-Y'); + ?> + + + + + + + + + + + + + + + + + + + + + + + +
material + + +
Date Opening StockReceiptUsedBalance Stock
+ + + + + oninput="openingStockChange(this)" + contenteditable="true" + + + > + + + + + +
+ + + + oninput="openingStockChange(this)" + contenteditable="true" + + + >00
+
+ +
+
+ +
+
+ +
+ +
+
+
+
+
+
+
+ + + +
+ +
+ + + + + + + + + + + + + + +