From ae5ed3ce053280687d794652e9c5cf372f7736c1 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Mon, 30 Dec 2024 12:30:06 +0530 Subject: [PATCH] master module 3 vadivel J 30-12-2024 --- app/Config/Routes.php | 6 +- app/Controllers/StockController.php | 103 +++++- app/Models/TrpSandUseStockModel.php | 46 +++ app/Views/includes/new_header.php | 20 +- app/Views/trpSandUseStockDetails.php | 514 +++++++++++++++++++++++++++ 5 files changed, 682 insertions(+), 7 deletions(-) create mode 100644 app/Models/TrpSandUseStockModel.php create mode 100644 app/Views/trpSandUseStockDetails.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 03225b3d..4ebaaf9b 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -480,4 +480,8 @@ $routes->post('updateResinStockDetails', 'StockController::updateResinStockDetai //Gas stock details $routes->match(['GET', 'POST'], 'gasStockDetails', 'StockController::loadView_gasStockDetails'); -$routes->post('updateGasStockDetails', 'StockController::updateGasStockDetails'); \ No newline at end of file +$routes->post('updateGasStockDetails', 'StockController::updateGasStockDetails'); + +//trp sand use stock details +$routes->match(['GET', 'POST'], 'trpSandUseStockDetails', 'StockController::trpSandUseStockDetails'); +$routes->post('updateTrpSandUseStockDetails', 'StockController::updateTrpSandUseStockDetails'); \ No newline at end of file diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index 52678f66..7d166542 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -17,6 +17,7 @@ use App\Models\BagStockDetailsModel; use App\Models\DustAndRoughModel; use App\Models\ResinStockModel; use App\Models\GasStockModel; +use App\Models\TrpSandUseStockModel; use CodeIgniter\HTTP\ResponseInterface; use DateTime; use DatePeriod; @@ -42,6 +43,8 @@ class StockController extends BaseController protected $resinStockDetails_model; protected $gasStockDetails_model; + protected $TrpSandUseStock_model; + protected $db; /** @@ -80,6 +83,8 @@ class StockController extends BaseController $this->gasStockDetails_model = new GasStockModel(); + $this->TrpSandUseStock_model = new TrpSandUseStockModel(); + $this->session = session(); helper('form'); @@ -1164,6 +1169,101 @@ class StockController extends BaseController } } + public function trpSandUseStockDetails(){ + + + 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 Sand Use Stock Details'; + + $startDate = "$month-01"; + $endDate = date("Y-m-t", strtotime($startDate)); + $data['trpSandUseStockDetails'] = $this->TrpSandUseStock_model + ->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 updateTrpSandUseStockDetails(){ + $postData = $this->request->getPost(); + + $updateTrpSandUseStockDetailsData = json_decode($postData['updateTrpSandUseStockDetails'], true); + + $updates = []; + + $inserts = []; + + foreach ($updateTrpSandUseStockDetailsData as $data) { + + $data['date'] = DateTime::createFromFormat('d-m-Y', $data['date'])->format('Y-m-d'); + + $date = $data['date']; + + $dbData = [ + 'date' => $data['date'], + 'rough_kgs' => $data['rough_kgs'], + 'fine_kgs' => $data['fine_kgs'], + 'total_kgs' => $data['total_kgs'], + 'customer_name' => $data['customer_name'] + ]; + + $resultExists = $this->TrpSandUseStock_model + ->where('date', $date) + ->first(); + + + if (empty($resultExists)) { + $inserts[] = $dbData; + } else { + $dbData['id'] = $resultExists['id']; + $updates[] = $dbData; + } + } + + if (!empty($inserts)) { + $this->TrpSandUseStock_model->insertBatch($inserts); + } + + if (!empty($updates)) { + + $updateResult = $this->TrpSandUseStock_model->updateBatch($updates, 'id'); + + if ($updateResult === FALSE) { + echo "Error during update"; + } else { + echo "Data Updated Successfully"; + return; + } + } + + echo "Data Saved Successfully"; + } + // --------------------------------------------gwm---------------------------------------------- @@ -1233,9 +1333,6 @@ class StockController extends BaseController $data['datefordropdown'] = $currentMonth; - - - $this->global['pageTitle'] = 'Drier Details'; $this->loadViews("drierMachineDetails", $this->global, $data, NULL); } diff --git a/app/Models/TrpSandUseStockModel.php b/app/Models/TrpSandUseStockModel.php new file mode 100644 index 00000000..057dff90 --- /dev/null +++ b/app/Models/TrpSandUseStockModel.php @@ -0,0 +1,46 @@ + + + + +