From 7975bf573933533e675cd923b5260fdcd4b5f2ea Mon Sep 17 00:00:00 2001 From: vadivel J Date: Fri, 8 Nov 2024 12:00:02 +0530 Subject: [PATCH] resin stock finished --- app/Controllers/StockController.php | 65 ++++++++++------ app/Views/resinStockDetails.php | 116 +++++++++++----------------- 2 files changed, 86 insertions(+), 95 deletions(-) diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index 333100b3..46ba2976 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -499,21 +499,21 @@ class StockController extends BaseController } } - if (!empty($inserts)) { - $this->dustAndRoughStockDetails_model->insertBatch($inserts); - } + if (!empty($inserts)) { + $this->dustAndRoughStockDetails_model->insertBatch($inserts); + } - if (!empty($updates)) { + if (!empty($updates)) { - $updateResult = $this->dustAndRoughStockDetails_model->updateBatch($updates, 'date'); - - if ($updateResult === FALSE) { - echo "Error during update"; - } else { - echo "Data Updated Successfully"; - return; - } - } + $updateResult = $this->dustAndRoughStockDetails_model->updateBatch($updates, 'date'); + + if ($updateResult === FALSE) { + echo "Error during update"; + } else { + echo "Data Updated Successfully"; + return; + } + } echo "Data Saved Successfully"; @@ -525,7 +525,7 @@ class StockController extends BaseController public function loadView_resinStockDetails(){ if ($this->request->getMethod() === 'POST'){ - + $month = $this->request->getPost('month'); $date = DateTime::createFromFormat('M-Y', $month); @@ -628,13 +628,17 @@ class StockController extends BaseController $updateResinStockDetailsData = json_decode($postData['updateResinStockDetails'], true); + $updates = []; + + $inserts = []; + foreach($updateResinStockDetailsData as $data){ $date = $data['date']; $materialCode = $data['materialCode']; - $dbData= [ + $dbData = [ 'date' =>$data['date'], 'materialCode' =>$data['materialCode'], 'customer' =>$data['customer'], @@ -650,19 +654,30 @@ class StockController extends BaseController ->first(); - if(!empty($resultExists)){ - - $updated = $this->resinStockDetails_model - ->where('date',$date) - ->where('materialCode',$materialCode) - ->set($dbData) - ->update(); - + if(empty($resultExists)){ + $inserts[] = $dbData; }else{ - $inserted = $this->resinStockDetails_model->insert($dbData); + $updates[] = $dbData; } - } + } + + + if (!empty($inserts)) { + $this->resinStockDetails_model->insertBatch($inserts); + } + + if (!empty($updates)) { + + $updateResult = $this->resinStockDetails_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/resinStockDetails.php b/app/Views/resinStockDetails.php index 6a9787dd..32b1ab44 100644 --- a/app/Views/resinStockDetails.php +++ b/app/Views/resinStockDetails.php @@ -173,7 +173,7 @@ @@ -193,7 +193,7 @@
-
+
@@ -210,7 +210,7 @@
- +
@@ -218,34 +218,21 @@ - + - - - - - - - - - - + - + @@ -262,16 +249,16 @@ - $bagStockDetails){ + foreach($groupedResinStockDetails as $groupedResinStockDetailsIndex => $resinStockDetails){ ?> - $bagStock){ ?> - + $resinStock){ ?> + format('d-m-Y'); + $startDate =DateTime::createFromFormat('Y-m-d', $resinStock['date'])->format('d-m-Y'); ?> @@ -355,10 +342,10 @@ $dateInMonth){ ?> $bagMaterial){ ?> + foreach($resinMaterials as $resinMaterialIndex => $resinMaterial){ ?> - + format('d-m-Y'); ?> @@ -372,39 +359,39 @@ + > + data-id="" + > @@ -448,7 +435,7 @@ //table to json function - var updateBagStockDetails = tableToJson(); + var updateResinStockDetails = tableToJson(); alert('Updation may take a while, And we appreciate your patience..!!'); @@ -456,10 +443,10 @@ $('#loader').show(); $.ajax({ data: { - updateBagStockDetails + updateResinStockDetails }, type: "POST", - url: "updateBagStockDetails", + url: "updateResinStockDetails", success: function (data) { if (data) { @@ -490,7 +477,7 @@
material - - + +
Customer - -
Date
@@ -279,46 +266,46 @@ - + + oninput="openingStockChange(this)" contenteditable="true" - > + > - + + contenteditable="true"> - + data-id=" "> +
oninput="openingStockChange(this)" contenteditable="true" - > 0 0