| + | @@ -470,13 +470,21 @@ |
+ +
+ +
diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 7d0fdad4..e52666f5 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -454,4 +454,8 @@ $routes->post('updateDustAndRoughStockDetails', 'StockController::updateDustAndR //Resin stock details $routes->match(['GET','POST'],'resinStockDetails', 'StockController::loadView_resinStockDetails'); -$routes->post('updateResinStockDetails', 'StockController::updateResinStockDetails'); \ No newline at end of file +$routes->post('updateResinStockDetails', 'StockController::updateResinStockDetails'); + +//Gas stock details +$routes->match(['GET','POST'],'gasStockDetails', 'StockController::loadView_gasStockDetails'); +$routes->post('updateGasStockDetails', 'StockController::updateGasStockDetails'); \ No newline at end of file diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index f1a9b932..e612bec5 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -16,8 +16,11 @@ use App\Models\Rawmaterialdetails_model; use App\Models\BagStockDetailsModel; use App\Models\DustAndRoughModel; use App\Models\ResinStockModel; +use App\Models\GasStockModel; use CodeIgniter\HTTP\ResponseInterface; use DateTime; +use DatePeriod; +use DateInterval; class StockController extends BaseController { @@ -37,6 +40,7 @@ class StockController extends BaseController protected $Rawmaterialdetails_model; protected $dustAndRoughStockDetails_model; protected $resinStockDetails_model; + protected $gasStockDetails_model; /** * This is default constructor of the class @@ -71,6 +75,8 @@ class StockController extends BaseController $this->dustAndRoughStockDetails_model = new DustAndRoughModel(); $this->resinStockDetails_model = new ResinStockModel() ; + + $this->gasStockDetails_model = new GasStockModel() ; $this->session = session(); @@ -103,10 +109,14 @@ class StockController extends BaseController $this->global['pageTitle'] = 'Coating Machine Details '; + + $startDate = "$month-01"; + $endDate = date("Y-m-t", strtotime($startDate)); $data['coatingMachineDetails']= $this->coatingMachineDetails_model + ->where('date >=', $startDate) + ->where('date <=', $endDate) ->where('is_active', 1) - ->orderBy('created_at','DESC') - ->like('created_at', $month, 'after') + ->orderBy('date','asc') ->findAll(); $date = DateTime::createFromFormat('Y-m', $month); @@ -123,6 +133,21 @@ class StockController extends BaseController $postData=$this->request->getPost(); + + $date = $postData['date']; + $shift = $postData['shift']; + + $sameShiftOnDateExists = $this->coatingMachineDetails_model + ->where('date',$date) + ->where('shift',$shift) + ->where('is_active',1) + ->first(); + + if(!empty($sameShiftOnDateExists)){ + + return redirect()->back()->with('error', 'Already same shift exists on the same date ..!!'); + } + $inserted= $this->coatingMachineDetails_model->insert($postData); @@ -391,6 +416,9 @@ class StockController extends BaseController $updateBagStockDetailsData = json_decode($postData['updateBagStockDetails'], true); + $inserts = []; + $updates = []; + foreach($updateBagStockDetailsData as $data){ $date = $data['date']; @@ -413,20 +441,32 @@ class StockController extends BaseController ->first(); - if(!empty($resultExists)){ - - $updated=$this->bagStockDetails_model - ->where('date',$date) - ->where('materialCode',$materialCode) - ->set($dbData) - ->update(); - + if(empty($resultExists)){ + $inserts [] = $dbData; + }else{ - $inserted = $this->bagStockDetails_model->insert($dbData); - } - - } + $dbData['id']=$resultExists['id']; + $updates [] = $dbData; + + } + } + if(!empty($inserts)){ + $inserted = $this->bagStockDetails_model->insertBatch($inserts); + } + if(!empty($updates)){ + + $updateResult = $this->bagStockDetails_model->updateBatch($updates,'id'); + + if ($updateResult === FALSE) { + echo "Error during update"; + } else { + echo "Data Updated Successfully"; + return; + } + + } + echo "Data Saved Successfully"; } @@ -485,15 +525,16 @@ class StockController extends BaseController foreach($updateDustAndRoughStockDetailsData as $data){ - $date = $data['date']; + $data['date'] = DateTime::createFromFormat('d-m-Y', $data['date'])->format('Y-m-d'); + + $date =$data['date']; $dbData= [ 'date' => $data['date'], 'finalRough' => $data['finalRough'], 'dust' => $data['dust'], 'total' => $data['total'] - - ]; + ]; $resultExists=$this->dustAndRoughStockDetails_model ->where('date',$date) @@ -506,7 +547,7 @@ class StockController extends BaseController } else { $updates[] = $dbData; } - } + } if (!empty($inserts)) { $this->dustAndRoughStockDetails_model->insertBatch($inserts); @@ -666,7 +707,8 @@ class StockController extends BaseController if(empty($resultExists)){ $inserts[] = $dbData; }else{ - $updates[] = $dbData; + $dbData['id']=$resultExists['id']; + $updates[] = $dbData ; } } @@ -693,20 +735,184 @@ class StockController extends BaseController } + //Gas Stock Details + + public function loadView_gasStockDetails(){ + + 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'] = "Gas Stock Details"; + + $startDate = "$month-01"; + $endDate = date("Y-m-t", strtotime($startDate)); + + $data['gasStockDetails'] = $this->gasStockDetails_model + ->select('t_gasStockDetails.*, + t_drierMachineDetails.total_gas_consumption AS drierMachineGasConsumption, + t_drierMachineDetails.sand_dried_qty AS sandDried, + coating_summary.coatingMachineGasconsumption, + coating_summary.coatedSand' + ) + // Subquery with early date filtering + ->join( + '(SELECT date, + SUM(totalGasconsumption) AS coatingMachineGasconsumption, + SUM(totalCoatingSandInKg) / 1000 AS coatedSand + FROM t_coatingMachineDetails + WHERE is_active = 1 + AND date >= ' . $this->db->escape($startDate) . ' + AND date <= ' . $this->db->escape($endDate) . ' + GROUP BY date + ) AS coating_summary', + 'coating_summary.date = t_gasStockDetails.date', + 'left' + ) + ->join('t_drierMachineDetails', + 't_drierMachineDetails.date = t_gasStockDetails.date + AND t_drierMachineDetails.date >= ' . $this->db->escape($startDate) . ' + AND t_drierMachineDetails.date <= ' . $this->db->escape($endDate), + 'left' + ) + + ->where('t_gasStockDetails.date >=', $startDate) + ->where('t_gasStockDetails.date <=', $endDate) + ->groupBy('t_gasStockDetails.date') + ->findAll(); + + + + $data['month'] = DateTime::createFromFormat('Y-m', $month)->format('M-Y'); + + return $this->loadViews("gasStockDetails", $this->global, $data, NULL); + } + + public function updateGasStockDetails(){ + + $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"; + } + private function updateGasStockConsumption($date , $consumption){ + + $resultExists = $this->gasStockDetails_model + ->where('date',$date) + ->first(); + + if($resultExists){ + $resultExists['consumption'] = $resultExists['consumption']+($consumption); + $this->gasStockDetails_model->update($resultExists['id'],$resultExists); + } + else{ + $startDate = DateTime::createFromFormat('Y-m-d', $date)->modify('first day of this month')->format('Y-m-d'); + $endDate = DateTime::createFromFormat('Y-m-d', $date)->modify('last day of this month')->format('Y-m-d'); + $datesInMonth = []; + $inserts = []; + $period = new DatePeriod( + new DateTime($startDate), + new DateInterval('P1D'), + (new DateTime($endDate))->modify('+1 day') + ); + + foreach ($period as $day) { + $datesInMonth[] = $day->format('Y-m-d'); + } + + foreach ($datesInMonth as $datesInMonthIndex => $dateInMonth) { + + $inserts[] = [ + 'date' => $dateInMonth, + 'opening' => 0, + 'purchaseBharath' => 0, + 'purchaseIndian' => 0, + 'total' => 0, + 'consumption' => $dateInMonth == $date ? $consumption : 0 , + 'balanceStock' => 0 + ]; + + } + + if(!empty($inserts)){ + $this->gasStockDetails_model->insertBatch($inserts); + + } + + } + } // --------------------------------------------gwm---------------------------------------------- @@ -823,9 +1029,27 @@ class StockController extends BaseController if ($existingRow) { // If exists, update the row + + //before updating the row update gas stock + $existingDrierGasConsumption = $existingRow['total_gas_consumption']; + $updatedDrierGasConsumption = $row['Tot Gas Consumption']; + if( $existingDrierGasConsumption != $updatedDrierGasConsumption ){ + $changeInConsumption = $updatedDrierGasConsumption - $existingDrierGasConsumption; + $dateToBeUpdated = $existingRow['date']; + $this->updateGasStockConsumption($dateToBeUpdated , $changeInConsumption); + } + $this->drierMachineDetails_model->update($existingRow['id'], $data); } else { // If not, insert a new row + + + //before inserting the row update gas stock + $consumption = $row['Tot Gas Consumption']; + $dateToBeInserted = $data['date']; + $this->updateGasStockConsumption($dateToBeInserted , $consumption); + + $this->drierMachineDetails_model->insert($data); } } diff --git a/app/Models/GasStockModel.php b/app/Models/GasStockModel.php new file mode 100644 index 00000000..e809c7e8 --- /dev/null +++ b/app/Models/GasStockModel.php @@ -0,0 +1,47 @@ + - #datatable_filter { - float: inline-end; + +
| Date | -Shift | -Machine On Time | -Machine Off Time | -Machine Running(hr) | -Total Coating | -Total Coating Sand(kg) | -Total Gas Consumption | -Hour Gas | -Hour QTY(kg) + | Date | +Shift | +Machine On Time | +Machine Off Time | +Machine Running(hr) | +Total Coating | +Total Coating Sand(kg) | +Total Gas Consumption | +Hour Gas | +Hour QTY(kg) | -Customer Name | -Action | +Customer Name | +Action |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - | + format('d-m-Y'); + ?> + + | + | + | + | + | + | + | + | + | + | + | + | + style="cursor:pointer;"> @@ -188,6 +300,17 @@ |
| + | @@ -470,13 +470,21 @@ |