diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index e612bec5..8e8b3463 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -85,232 +85,248 @@ class StockController extends BaseController $this->isLoggedIn(); } - public function index() - { - // - } +public function index() +{ + // +} //Coating Machine Details starts +public function loadView_coatingMachineDetails(){ - public function loadView_coatingMachineDetails(){ + if ($this->request->getMethod() === 'POST'){ + $month = $this->request->getPost('month'); - if ($this->request->getMethod() === 'POST'){ - $month = $this->request->getPost('month'); + $date = DateTime::createFromFormat('M-Y', $month); - $date = DateTime::createFromFormat('M-Y', $month); + $formattedDate = $date->format('Y-m'); - $formattedDate = $date->format('Y-m'); - - $month=$formattedDate; - } - else{ - $month = date('Y-m'); - } - - $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('date','asc') - ->findAll(); - - $date = DateTime::createFromFormat('Y-m', $month); - - $formattedDate = $date->format('M-Y'); - - $data['month']=$formattedDate; - - return $this->loadViews("CoatingMachineDetail", $this->global, $data, NULL); - + $month=$formattedDate; + } + else{ + + $filteredMonth=$this->request->getGet('month'); + $month = $filteredMonth ?? date('Y-m'); } - public function addNewCoatingMachineDetails(){ - - $postData=$this->request->getPost(); + $this->global['pageTitle'] = 'Coating Machine Details '; - $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); - - if ($inserted) { - // Set flashdata for success message - return redirect()->to('/coatingMachineDetails')->with('success', 'Coating Machine details updated successfully'); - } else { - // Set flashdata for error message - return redirect()->back()->with('error', 'Failed to update Coating machine details'); - } - - } - - - public function updateCoatingMachineDetails(){ - - $putData=$this->request->getPost(); - - $id = $putData['editCoatingMachineDetailId']; - - $updated= $this->coatingMachineDetails_model->update($id,$putData); - - if ($updated) { - // Set flashdata for success message - return redirect()->to('/coatingMachineDetails')->with('success', 'Coating Machine details updated successfully'); - } else { - // Set flashdata for error message - return redirect()->back()->with('error', 'Failed to update Coating machine details'); - } - - - } - - public function deleteCoatingMachineDetails(){ - - $id = $this->request->getGet('id'); - - $data['is_active']=0; - - $updated = $this->coatingMachineDetails_model->update($id,$data); - - if ($updated) { - // Set flashdata for success message - return redirect()->to('/coatingMachineDetails')->with('success', 'Coating Machine details deleted successfully'); - } else { - // Set flashdata for error message - return redirect()->back()->with('error', 'Failed to delete Coating machine details'); - } - } - - //incoming Silica Sand Details starts - - public function loadView_incomingSilicaSandDetails(){ - - 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['month']=$month; - - $this->global['pageTitle']='Incoming Silica Sand Details'; - - $materialCodes = $this->rawmaterialdetails_model->getAllSilicaRawMaterialCode(); - - if (!empty($materialCodes)) { - $data['igrDetails'] = $this->inwardGateRegister_model->findIgrDetailsForIncomingSilicaSand($materialCodes,$month); - - } else { - $data['igrDetails'] = []; - } + $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('date','asc') + ->findAll(); $date = DateTime::createFromFormat('Y-m', $month); $formattedDate = $date->format('M-Y'); - $data['month']=$formattedDate; + $data['month']=$formattedDate; - return $this->loadViews("incomingSilicaSandDetails", $this->global, $data, NULL); + return $this->loadViews("CoatingMachineDetail", $this->global, $data, NULL); + +} +public function addNewCoatingMachineDetails(){ + + $postData=$this->request->getPost(); + $month =$this->request->getGet('month'); + $month = DateTime::createFromFormat('M-Y', $month)->format('Y-m'); + + $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); + + if ($inserted) { + //update Gas stock consumption if insert is successfull..!! + $dateToBeInserted = $postData['date']; + $consumption = $postData['totalGasConsumption']; + $this->updateGasStockConsumption($dateToBeInserted , $consumption); + + // Set flashdata for success message + return redirect()->to("/coatingMachineDetails?month=$month")->with('success', 'Coating Machine details updated successfully'); + } else { + // Set flashdata for error message + return redirect()->back()->with('error', 'Failed to update Coating machine details'); } - public function updateIncomingSilicaSandDetails(){ - - $postData = $this->request->getPost(); - - $incomingSilicaSandDetailsData = json_decode($postData['incomingSilicaSandDetailsData'], true); - - - foreach($incomingSilicaSandDetailsData as $data){ - - $IGRNO=$data['IGR No']; - $materialCode=$data['MaterialCode']; +} - $dbData=[ - 'igrNo_fk'=>$data['IGR No'], - 'materialCode'=>$data['MaterialCode'], - 'grade'=>$data['Grade'], - 'gradeCondition'=>$data['Grade Condition'], - '_10'=>$data['___10___'], - '_20'=>$data['___20___'], - '_30'=>$data['___30___'], - '_40'=>$data['___40___'], - '_50'=>$data['___50___'], - '_70'=>$data['___70___'], - '_100'=>$data['___100___'], - '_140'=>$data['___140___'], - '_200'=>$data['___200___'], - '_300'=>$data['___300___'], - 'pan'=>$data['PAN'], - 'total'=>$data['Total'], - 'afsSpec'=>$data['AFS Spec'], - 'afsActual'=>$data['AFS Actual'], - 'plus20loss'=>$data['Plus 20 loss%'], - 'plus30Loss'=>$data['Plus 30 Loss %'], - 'moistureSpec'=>$data['Moisture % Spec'], - 'moistureActual'=>$data['Moisture Actual'], - 'moistureLoss'=>$data['Moisture Loss'], - 'moistureLossQty'=>$data['Moisture loss Qty'], - 'sieveLossQty'=>$data['Sieve Loss Qty'], - 'salableQty'=>$data['Salable Qty'], - 'remark'=>$data['Remark'] +public function updateCoatingMachineDetails(){ + $putData=$this->request->getPost(); + $month =$this->request->getGet('month'); + $month = DateTime::createFromFormat('M-Y', $month)->format('Y-m'); - ]; + $id = $putData['editCoatingMachineDetailId']; + + $updated= $this->coatingMachineDetails_model->update($id,$putData); - $resultExists=$this->incomingSilicaSandDetails_model - ->where('igrNo_fk',$IGRNO) - ->where('materialCode',$materialCode) - ->first(); - - - - if(!empty($resultExists)){ - - $updated = $this->incomingSilicaSandDetails_model - ->where('igrNo_fk', $IGRNO) - ->where('materialCode', $materialCode) - ->set($dbData) - ->update(); - - }else{ - $inserted = $this->incomingSilicaSandDetails_model->insert($dbData); - } + if ($updated) { + //update Gas stock consumption if update is successfull..!! + $dateToBeUpdated = $putData['date']; + $existingCoatingGasConsumption = $putData['existingTotalGasConsumption']; + $updatedCoatingGasConsumption = $putData['totalGasConsumption']; + if( $existingCoatingGasConsumption != $updatedCoatingGasConsumption ){ + $changeInConsumption = $updatedCoatingGasConsumption - $existingCoatingGasConsumption; + $this->updateGasStockConsumption($dateToBeUpdated , $changeInConsumption); } - echo "Data Saved Successfully"; + // Set flashdata for success message + return redirect()->to("/coatingMachineDetails?month=$month")->with('success', 'Coating Machine details updated successfully'); + } else { + // Set flashdata for error message + return redirect()->back()->with('error', 'Failed to update Coating machine details'); + } + + +} + +public function deleteCoatingMachineDetails(){ + + $id = $this->request->getGet('id'); + + $data['is_active']=0; + + $updated = $this->coatingMachineDetails_model->update($id,$data); + + if ($updated) { + // Set flashdata for success message + return redirect()->to('/coatingMachineDetails')->with('success', 'Coating Machine details deleted successfully'); + } else { + // Set flashdata for error message + return redirect()->back()->with('error', 'Failed to delete Coating machine details'); + } +} + + //incoming Silica Sand Details starts +public function loadView_incomingSilicaSandDetails(){ + + 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['month']=$month; + + $this->global['pageTitle']='Incoming Silica Sand Details'; + + $materialCodes = $this->rawmaterialdetails_model->getAllSilicaRawMaterialCode(); + + if (!empty($materialCodes)) { + $data['igrDetails'] = $this->inwardGateRegister_model->findIgrDetailsForIncomingSilicaSand($materialCodes,$month); + + } else { + $data['igrDetails'] = []; + } + + $date = DateTime::createFromFormat('Y-m', $month); + + $formattedDate = $date->format('M-Y'); + + $data['month']=$formattedDate; + + return $this->loadViews("incomingSilicaSandDetails", $this->global, $data, NULL); + +} + +public function updateIncomingSilicaSandDetails(){ + + $postData = $this->request->getPost(); + + $incomingSilicaSandDetailsData = json_decode($postData['incomingSilicaSandDetailsData'], true); + + + foreach($incomingSilicaSandDetailsData as $data){ + + $IGRNO=$data['IGR No']; + $materialCode=$data['MaterialCode']; + + + $dbData=[ + 'igrNo_fk'=>$data['IGR No'], + 'materialCode'=>$data['MaterialCode'], + 'grade'=>$data['Grade'], + 'gradeCondition'=>$data['Grade Condition'], + '_10'=>$data['___10___'], + '_20'=>$data['___20___'], + '_30'=>$data['___30___'], + '_40'=>$data['___40___'], + '_50'=>$data['___50___'], + '_70'=>$data['___70___'], + '_100'=>$data['___100___'], + '_140'=>$data['___140___'], + '_200'=>$data['___200___'], + '_300'=>$data['___300___'], + 'pan'=>$data['PAN'], + 'total'=>$data['Total'], + 'afsSpec'=>$data['AFS Spec'], + 'afsActual'=>$data['AFS Actual'], + 'plus20loss'=>$data['Plus 20 loss%'], + 'plus30Loss'=>$data['Plus 30 Loss %'], + 'moistureSpec'=>$data['Moisture % Spec'], + 'moistureActual'=>$data['Moisture Actual'], + 'moistureLoss'=>$data['Moisture Loss'], + 'moistureLossQty'=>$data['Moisture loss Qty'], + 'sieveLossQty'=>$data['Sieve Loss Qty'], + 'salableQty'=>$data['Salable Qty'], + 'remark'=>$data['Remark'] + + + ]; + + $resultExists=$this->incomingSilicaSandDetails_model + ->where('igrNo_fk',$IGRNO) + ->where('materialCode',$materialCode) + ->first(); + + + + if(!empty($resultExists)){ + + $updated = $this->incomingSilicaSandDetails_model + ->where('igrNo_fk', $IGRNO) + ->where('materialCode', $materialCode) + ->set($dbData) + ->update(); + + }else{ + $inserted = $this->incomingSilicaSandDetails_model->insert($dbData); + } } - // Bag Stock details starts + echo "Data Saved Successfully"; - public function loadView_bagStockDetails(){ +} + + + // Bag Stock details starts +public function loadView_bagStockDetails(){ if ($this->request->getMethod() === 'POST'){ $month = $this->request->getPost('month'); @@ -408,9 +424,9 @@ class StockController extends BaseController return $this->loadViews("bagStockDetails", $this->global, $data, NULL); - } +} - public function updateBagStockDetails(){ +public function updateBagStockDetails(){ $postData = $this->request->getPost(); @@ -469,12 +485,11 @@ class StockController extends BaseController echo "Data Saved Successfully"; - } +} //Dust And Rough Stock Details - - public function loadView_dustAndRoughStockDetails(){ +public function loadView_dustAndRoughStockDetails(){ if ($this->request->getMethod() === 'POST'){ $month = $this->request->getPost('month'); @@ -511,9 +526,9 @@ class StockController extends BaseController return $this->loadViews("dustAndRoughStockDetails", $this->global, $data, NULL); - } +} - public function updateDustAndRoughStockDetails(){ +public function updateDustAndRoughStockDetails(){ $postData = $this->request->getPost(); @@ -523,31 +538,31 @@ class StockController extends BaseController $inserts = []; - foreach($updateDustAndRoughStockDetailsData as $data){ - - $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) - ->first(); - + foreach($updateDustAndRoughStockDetailsData as $data){ - if (empty($resultExists)) { - $inserts[] = $dbData; + $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) + ->first(); + - } else { - $updates[] = $dbData; - } - } + if (empty($resultExists)) { + $inserts[] = $dbData; + + } else { + $updates[] = $dbData; + } + } if (!empty($inserts)) { $this->dustAndRoughStockDetails_model->insertBatch($inserts); @@ -567,12 +582,11 @@ class StockController extends BaseController echo "Data Saved Successfully"; - } +} //Resin Stock Details - - public function loadView_resinStockDetails(){ +public function loadView_resinStockDetails(){ if ($this->request->getMethod() === 'POST'){ @@ -669,9 +683,9 @@ class StockController extends BaseController return $this->loadViews("resinStockDetails", $this->global, $data, NULL); - } +} - public function updateResinStockDetails(){ +public function updateResinStockDetails(){ $postData = $this->request->getPost(); @@ -732,12 +746,11 @@ class StockController extends BaseController echo "Data Saved Successfully"; - } +} //Gas Stock Details - - public function loadView_gasStockDetails(){ +public function loadView_gasStockDetails(){ if ($this->request->getMethod() === 'POST'){ @@ -800,9 +813,9 @@ class StockController extends BaseController $data['month'] = DateTime::createFromFormat('Y-m', $month)->format('M-Y'); return $this->loadViews("gasStockDetails", $this->global, $data, NULL); - } +} - public function updateGasStockDetails(){ +public function updateGasStockDetails(){ $postData = $this->request->getPost(); @@ -859,11 +872,9 @@ class StockController extends BaseController } echo "Data Saved Successfully"; - } +} - private function updateGasStockConsumption($date , $consumption){ - - +private function updateGasStockConsumption($date , $consumption){ $resultExists = $this->gasStockDetails_model ->where('date',$date) @@ -908,17 +919,16 @@ class StockController extends BaseController if(!empty($inserts)){ $this->gasStockDetails_model->insertBatch($inserts); - } } - } +} // --------------------------------------------gwm---------------------------------------------- - function getMonthDatesFromInput($monthYear) { +public function getMonthDatesFromInput($monthYear) { $date = DateTime::createFromFormat('M-Y', $monthYear); @@ -943,10 +953,9 @@ class StockController extends BaseController } return $dates; - } - - - function generateTimeOptions() { +} + +public function generateTimeOptions() { $times = []; $start = strtotime('00:00'); // Start at midnight (12:00 AM) $end = strtotime('23:45'); // End at 11:45 PM @@ -959,10 +968,9 @@ class StockController extends BaseController } return $times; - } +} - function drierMachineDetails() - { +public function drierMachineDetails(){ $currentMonth = $this->request->getPost('month') ? $this->request->getPost('month') : date('M-Y'); @@ -994,10 +1002,9 @@ class StockController extends BaseController $this->global['pageTitle'] = 'Drier Details'; $this->loadViews("drierMachineDetails", $this->global, $data, NULL); - } +} - public function addOrEditdrierMachineDetails() - { +public function addOrEditdrierMachineDetails(){ $drierData = json_decode($this->request->getPost('drierData'), true); if (empty($drierData)) { @@ -1055,10 +1062,9 @@ class StockController extends BaseController } echo "Data successfully saved."; - } +} - - public function factoryVehicleDieselDetails() +public function factoryVehicleDieselDetails() { $currentMonth = $this->request->getPost('month') ? $this->request->getPost('month') : date('M-Y'); @@ -1126,9 +1132,9 @@ class StockController extends BaseController $this->global['pageTitle'] = 'Drier Details'; $this->loadViews("factoryDieselMachineDetails", $this->global, $data, NULL); - } +} - public function getDieselConsumptionPivot($machineDetails , $startDate , $endDeate) +public function getDieselConsumptionPivot($machineDetails , $startDate , $endDeate) { $machineIds = array_column($machineDetails, 'id'); @@ -1153,9 +1159,9 @@ class StockController extends BaseController $result = $query->getResultArray(); return $result; - } +} - public function addOrEditfactoryVehicleDieselDetails() +public function addOrEditfactoryVehicleDieselDetails() { $dieselMachineTableData = json_decode($this->request->getPost('dieselMachineTableData'), true); @@ -1217,10 +1223,10 @@ class StockController extends BaseController echo "Data successfully saved."; - } +} - public function powerConsumptionDetails() +public function powerConsumptionDetails() { $currentMonth = $this->request->getPost('month') ? $this->request->getPost('month') : date('M-Y'); @@ -1261,10 +1267,9 @@ class StockController extends BaseController $this->global['pageTitle'] = 'Power Consumption Details'; $this->loadViews("powerConsumptionDetails", $this->global, $data, NULL); - } +} - public function getElectricConsumptionPivot($machineDetails , $startDate , $endDeate) - { +public function getElectricConsumptionPivot($machineDetails , $startDate , $endDeate) { $machineIds = array_column($machineDetails, 'id'); if (empty($machineIds)) { return []; } @@ -1288,10 +1293,9 @@ class StockController extends BaseController $result = $query->getResultArray(); return $result; - } +} - public function addOrEditPowerConsumptionDetails() - { +public function addOrEditPowerConsumptionDetails(){ $electricMachineTableData = json_decode($this->request->getPost('electricMachineTableData'), true); $transformedData = []; @@ -1338,7 +1342,7 @@ class StockController extends BaseController echo "Data successfully saved."; - } +} } diff --git a/app/Views/CoatingMachineDetail.php b/app/Views/CoatingMachineDetail.php index d49fb781..87702061 100644 --- a/app/Views/CoatingMachineDetail.php +++ b/app/Views/CoatingMachineDetail.php @@ -338,7 +338,7 @@ -
+