From d3fdd57fda8b56c41b6dbec8e5ffb431dd1e64b8 Mon Sep 17 00:00:00 2001 From: vadivel J Date: Wed, 13 Nov 2024 10:13:55 +0530 Subject: [PATCH] changes in gas stock module -vadivel J --- app/Controllers/StockController.php | 59 ++++++- app/Views/gasStockDetails.php | 246 ++++++++++++++++------------ app/Views/includes/new_header.php | 2 +- 3 files changed, 203 insertions(+), 104 deletions(-) diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index e0ea480b..b624935c 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -769,7 +769,7 @@ class StockController extends BaseController SUM(totalGasconsumption) AS coatingMachineGasconsumption, SUM(totalCoatingSandInKg) / 1000 AS coatedSand FROM t_coatingMachineDetails - WHERE is_active = 1 + WHERE is_active = 1 AND date >= ' . $this->db->escape($startDate) . ' AND date <= ' . $this->db->escape($endDate) . ' GROUP BY date @@ -797,7 +797,62 @@ class StockController extends BaseController } public function updateGasStockDetails(){ - echo "welcome to update Gas Stock Details"; + + $postData = $this->request->getPost(); + + $updateGasStockDetailsData = json_decode($postData['updateGasStockDetails'], true); + + $updates = []; + + $inserts = []; + + foreach($updateGasStockDetailsData as $data){ + + $date = $data['date']; + + + $dbData = [ + 'date' =>$data['date'], + 'opening' =>$data['opening'], + 'purchaseBharath' =>$data['purchaseBharath'], + 'purchaseIndian' =>$data['purchaseIndian'], + 'total' =>$data['total'], + 'consumption' =>$data['consumption'], + 'balanceStock' =>$data['balanceStock'], + ]; + + $resultExists = $this->gasStockDetails_model + ->where('date',$date) + ->first(); + + + if(empty($resultExists)){ + $inserts[] = $dbData; + }else{ + $dbData['id']=$resultExists['id']; + $updates[] = $dbData ; + } + + } + + + if (!empty($inserts)) { + $this->gasStockDetails_model->insertBatch($inserts); + } + + if (!empty($updates)) { + + $updateResult = $this->gasStockDetails_model->updateBatch($updates, 'id'); + + if ($updateResult === FALSE) { + echo "Error during update"; + } else { + echo "Data Updated Successfully"; + return; + } + } + + echo "Data Saved Successfully"; } diff --git a/app/Views/gasStockDetails.php b/app/Views/gasStockDetails.php index 6fc6ecbe..88803b65 100644 --- a/app/Views/gasStockDetails.php +++ b/app/Views/gasStockDetails.php @@ -267,22 +267,44 @@ $gasStockDetail){ + + $date = Datetime::createFromFormat('Y-m-d',$gasStockDetail['date'])->format('d-m-Y') ?> - - - - - - - - + + + + + oninput="openingStockChange(this)" + data-id="" + > + + + + + + + + - - - - + + + + $dateInMonth) { - + $dateInMonthDmYFormat = Datetime::createFromFormat('Y-m-d',$dateInMonth)->format('d-m-Y') ?> - - - - - - - - - - - - - - - + + + + + oninput="openingStockChange(this)" + data-id="" + >0 + 0 + + 0 + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 @@ -364,7 +405,7 @@ //table to json function - var updateBagStockDetails = tableToJson(); + var updateGasStockDetails = tableToJson(); alert('Updation may take a while, And we appreciate your patience..!!'); @@ -372,10 +413,10 @@ $('#loader').show(); $.ajax({ data: { - updateBagStockDetails + updateGasStockDetails }, type: "POST", - url: "updateBagStockDetails", + url: "updateGasStockDetails", success: function (data) { if (data) { @@ -406,32 +447,27 @@ diff --git a/app/Views/includes/new_header.php b/app/Views/includes/new_header.php index 722c4c32..f9909118 100755 --- a/app/Views/includes/new_header.php +++ b/app/Views/includes/new_header.php @@ -767,7 +767,7 @@