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 @@