diff --git a/app/Controllers/Inwardgateregister.php b/app/Controllers/Inwardgateregister.php index 930ed0e0..fdfe1de2 100755 --- a/app/Controllers/Inwardgateregister.php +++ b/app/Controllers/Inwardgateregister.php @@ -1525,6 +1525,10 @@ function updateIGRWeight(){ + /* + ********************************************************* sec_gas_shortage_starts ************************************************************** + */ + public function gasCylinderEntered(){ $this->global['pageTitle'] = 'Gas Cylinder Entered'; @@ -1533,7 +1537,7 @@ function updateIGRWeight(){ $gasMaterialCodes = array_column($gasMaterialCodes,'MaterialCode'); - $igrDetailsListByMcatGas = $this->inwardgateregister_model->getIgrDetailsListByMcatGas($gasMaterialCodes); + $igrDetailsListByMcatGas = $this->inwardgateregister_model->getIgrDetailsListByMcatGas($gasMaterialCodes,"gas_entered"); $data['gasCylinderEnteredList'] = $igrDetailsListByMcatGas; @@ -1544,9 +1548,16 @@ function updateIGRWeight(){ public function gasCylinderPending(){ - $this->global['pageTitle'] = 'Gas Shortage List'; - $data['gasShortageList'] = $this->gasShortage_model->findAll(); + $this->global['pageTitle'] = 'Gas Cylinder Pending'; + + $gasMaterialCodes = $this->rawMaterialDetails_model->getAllGasMaterialCode(); + + $gasMaterialCodes = array_column($gasMaterialCodes,'MaterialCode'); + + $igrDetailsListByMcatGas = $this->inwardgateregister_model->getIgrDetailsListByMcatGas($gasMaterialCodes,"gas_pending"); + + $data['gasCylinderPendingList'] = $igrDetailsListByMcatGas; $this->loadViews("gasCylinderPending", $this->global, $data, NULL); @@ -1555,58 +1566,125 @@ function updateIGRWeight(){ public function gasCylinderReturned(){ - $this->global['pageTitle'] = 'Gas Shortage List'; + $this->global['pageTitle'] = 'Gas Cylinder Returned'; - $data['gasShortageList'] = $this->gasShortage_model->findAll(); + $gasMaterialCodes = $this->rawMaterialDetails_model->getAllGasMaterialCode(); + + $gasMaterialCodes = array_column($gasMaterialCodes,'MaterialCode'); + + $igrDetailsListByMcatGas = $this->inwardgateregister_model->getIgrDetailsListByMcatGas($gasMaterialCodes,"gas_returned"); + + $data['gasCylinderReturnedList'] = $igrDetailsListByMcatGas; $this->loadViews("gasCylinderReturned", $this->global, $data, NULL); } - - public function getGasShortageDetail(){ - - $postData = $this->request->getPost(); - - $shortage = $this->gasShortage_model->where('id',$postData['id'])->find(); - - return $this->response->setJSON(['status' => 'success', 'data' => $shortage]); - - } - - - public function updateGasShortage() { - $postData = $this->request->getPost(); - - // Validate required data - if (!$postData) { - return $this->response->setJSON(['status' => 'error', 'message' => 'Invalid request. No data received.']); - } + try { - // Validate required fields for adding - if ( !isset($postData['invoiceNo']) ) { - return $this->response->setJSON(['status' => 'error', 'message' => 'Missing required fields: invoice No.']); - } + $postData = $this->request->getJSON(true); // Convert JSON to an associative array - // Handle update (edit) - if (isset($postData["id"])) { - return $this->gasShortage_model->update($postData["id"], $postData) - ? $this->response->setJSON(['status' => 'success', 'message' => 'Gas shortage details updated successfully.']) - : $this->response->setJSON(['status' => 'error', 'message' => 'Failed to update gas shortage details.']); - } - - // Insert new shortage (add) - return ($insertId = $this->gasShortage_model->insert($postData)) - ? $this->response->setJSON(['status' => 'success', 'message' => 'Gas shortage details added successfully.', 'data' => ['id' => $insertId]]) - : $this->response->setJSON(['status' => 'error', 'message' => 'Failed to save gas shortage details.']); + // Validate if any data is received + if (!$postData) { + return $this->response->setJSON([ + 'status' => 'error', + 'message' => 'Invalid request. No data received.' + ]); + } + + // Validate required fields + if (empty($postData['invoiceNo']) ) { + return $this->response->setJSON([ + 'status' => 'error', + 'message' => 'Missing invoiceNo data.' + ]); + } + + $updates = []; + $inserts = []; + + if(isset($postData['id'])){ //update operation + + $cylinderData = [ + 'id' => $postData['id'], + 'IGRNO' => $postData['IGRNO'] ?? '', + 'fullCylinderDate' => $postData['fullCylinderDate'] ?? '', + 'emptyCylinderDate' => $postData['emptyCylinderDate'] ?? '', + 'invoiceNo' => $postData['invoiceNo'] ?? '', + 'cylinderNo' => $postData['cylinderNo'], + 'grossWeight' => $postData['grossWeight'], + 'tareWeight' => $postData['tareWeight'] ?? '', + 'netWeight' => $postData['netWeight'] ?? '', + 'actualWeight' => $postData['actualWeight'], + 'shortage' => $postData['shortage'] ?? '', + 'gas_cylinder_status' => "gas_returned" + ]; + + $updates[] = $cylinderData ; + + }else{//Insert Operation + + // Process each cylinder entry + foreach ($postData['cylinders'] as $cylinder) { + + // Ensure cylinder data is valid + if (!isset($cylinder['cylinderNo'], $cylinder['grossWeight'], $cylinder['actualWeight'])) { + continue; // Skip incomplete data + } + + $cylinderData = [ + 'IGRNO' => $postData['IGRNO'] ?? '', + 'fullCylinderDate' => $postData['fullCylinderDate'] ?? '', + 'emptyCylinderDate' => $postData['emptyCylinderDate'] ?? '', + 'invoiceNo' => $postData['invoiceNo'] ?? '', + 'cylinderNo' => $cylinder['cylinderNo'], + 'grossWeight' => $cylinder['grossWeight'], + 'tareWeight' => $cylinder['tareWeight'] ?? '', + 'netWeight' => $cylinder['netWeight'] ?? '', + 'actualWeight' => $cylinder['actualWeight'], + 'shortage' => $cylinder['shortage'] ?? '', + 'gas_cylinder_status' => 'gas_pending' + ]; + + $inserts[] = $cylinderData; + + } + + } + + if (!empty($updates)) { + $this->gasShortage_model->updateBatch($updates, 'id'); + } + + if (!empty($inserts)) { + $this->gasShortage_model->insertBatch($inserts); + } + + return $this->response->setJSON([ + 'status' => 'success', + 'message' => 'Gas shortage details processed successfully.' + ]); + + + } catch (\Throwable $th) { + // Log the error for debugging + log_message('error', 'Gas Shortage Update Error: ' . $th->getMessage()); + + return $this->response->setJSON([ + 'status' => 'error', + 'message' => 'An unexpected error occurred while processing gas shortage details.', + 'error' => $th->getMessage() + ]); + } } - - + /* + ********************************************************* sec_gas_shortage_ends ************************************************************** + */ } \ No newline at end of file diff --git a/app/Models/GasShortageModel.php b/app/Models/GasShortageModel.php index e7519acf..5e8f461f 100644 --- a/app/Models/GasShortageModel.php +++ b/app/Models/GasShortageModel.php @@ -13,8 +13,18 @@ class GasShortageModel extends Model protected $useSoftDeletes = false; protected $protectFields = true; protected $allowedFields = - ['fullCylinderDate','emptyCylinderDate','invoiceNo', - 'cylinderNo','grossWeight','tareWeight','netWeight','actualWeight','shortage' + ['id', + 'IGRNO', + 'fullCylinderDate', + 'emptyCylinderDate', + 'invoiceNo', + 'cylinderNo', + 'grossWeight', + 'tareWeight', + 'netWeight', + 'actualWeight', + 'shortage', + 'gas_cylinder_status' ]; protected bool $allowEmptyInserts = false; diff --git a/app/Models/Inwardgateregister_model.php b/app/Models/Inwardgateregister_model.php index 0a3051c8..6f556582 100755 --- a/app/Models/Inwardgateregister_model.php +++ b/app/Models/Inwardgateregister_model.php @@ -1380,26 +1380,42 @@ $builder = $this->db->table('t_igr_history') } //Mcat -materialCategory - public function getIgrDetailsListByMcatGas($gasMaterialCodes){ + public function getIgrDetailsListByMcatGas($gasMaterialCodes,$gas_status){ - $result = $this->db->table('t_igr_details as t_igrd') + $builder = $this->db->table('t_igr_details as t_igrd') ->select(" - t_igrd.IGRNO, - SUM(t_igrd.QuantityAsPerInvoice) as gasCylinderCount, + t_igrd.IGRNO as IGRNO-, + (t_igrd.QuantityAsPerInvoice) as gasCylinderCount, t_sd.SupplierName, t_igrm.*, - 'gas entered' AS status + t_mm.MaterialName, + t_gsd.* ") ->join('t_igr_master t_igrm', 't_igrm.IGRNO = t_igrd.IGRNO') ->join('t_purchaseorder_master t_pom', 't_igrm.PONO = t_pom.PONO', 'left') ->join('t_supplierdetailsn t_sd', 't_sd.SupplierID = t_pom.SupplierID') ->join('t_gasshortagedetails t_gsd', 't_gsd.IGRNO = t_igrd.IGRNO', 'left') - ->whereIn('MaterialCode', $gasMaterialCodes) - ->where("DATE(t_igrd.CreatedDate) BETWEEN '2025-01-01' AND '2025-01-31' ") - ->where('t_gsd.IGRNO IS NULL') - ->groupBy('t_igrd.IGRNO') - ->get() - ->getResultArray(); + ->join('t_materialmaster t_mm','t_mm.MaterialCode = t_igrd.MaterialCode','left') + ->whereIn('t_igrd.MaterialCode', $gasMaterialCodes) + ->where("DATE(t_igrd.CreatedDate) >= '2025-04-01' "); + + + switch ($gas_status) { + case "gas_entered": + $builder->where('t_gsd.gas_cylinder_status IS NULL'); + break; + case "gas_pending": + $builder->where('t_gsd.gas_cylinder_status','gas_pending'); + break; + case "gas_returned": + $builder->where('t_gsd.gas_cylinder_status','gas_returned'); + break; + default: + $builder->where('t_gsd.gas_cylinder_status IS NULL'); + } + + + $result = $builder->get()->getResultArray(); diff --git a/app/Views/gasCylinderEntered.php b/app/Views/gasCylinderEntered.php index 47961925..e5a60de9 100644 --- a/app/Views/gasCylinderEntered.php +++ b/app/Views/gasCylinderEntered.php @@ -203,22 +203,27 @@ + + + + + + - -

No Gas Cylinder Entered in the Given Dates..!!

+

No Gas Cylinder Entered in the Given Dates..!!

$gasCylinder): @@ -228,22 +233,39 @@ + + + - + + + + + + + + + + + + + + + + - - + @@ -277,7 +299,7 @@
Full Cylinder Date IGR No Supplier Bill/Invoice NoCylinder Name Bill Date Driver Name Vehicle No Cylinder CountStatus Gas Details
- +
- + + + + + + - - + + - - - + + + + - - - - - + + +

No Gas Cylinder Entered in the Given Dates..!!

+ + + $gasCylinder): + $gasCylinder['MaterialRcvdDate'] = date('d-m-Y',strtotime($gasCylinder['MaterialRcvdDate'])); + $gasCylinder['DeliveryChellanDate'] = date('d-m-Y',strtotime($gasCylinder['DeliveryChellanDate'])); + $gasCylinder['emptyCylinderDate'] = date('d-m-Y',strtotime($gasCylinder['emptyCylinderDate'])); + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Full Cylinder DateFull Cylinder Date IGR No SupplierBill/Invoice NoCylinder Name Cylinder No Gross Weight Empty Cylinder DateTare WeightNet WeightTare WeightNet Weight Actual WeightshortageBill/Invoice NoShortage Bill Date Driver Name Vehicle NoStatusActionGas Details
+ + + +
@@ -246,68 +298,14 @@ - - - - - - - - - -