diff --git a/app/Controllers/Amendmentpurchaseorder.php b/app/Controllers/Amendmentpurchaseorder.php
index 3cfc359c..dc0673e7 100755
--- a/app/Controllers/Amendmentpurchaseorder.php
+++ b/app/Controllers/Amendmentpurchaseorder.php
@@ -1425,7 +1425,7 @@ class Amendmentpurchaseorder extends BaseController
}
if( $changeStatus == "ST026" || $changeStatus == "ST014"){
-
+
$PODetail = array('Status' => PO_AMENDED); //TO SET PARENT PO AS AMENDMENT STATUS
$APO = $this->purchaseorder_model->updateAmendPOMaster($PONO, $PODetail);
@@ -1433,7 +1433,7 @@ class Amendmentpurchaseorder extends BaseController
$LineItemStatus = REQITEM_NEW;
- $igrvalue = $this->purchaseorder_model->selectigrmaster($PONO);
+ $igrvalue = $this->purchaseorder_model->selectigrmaster($PONO);
$po = '';
$igrno = '';
diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php
index a74ecba0..bacba458 100644
--- a/app/Controllers/StockController.php
+++ b/app/Controllers/StockController.php
@@ -25,353 +25,357 @@ use DateInterval;
class StockController extends BaseController
{
- protected $supplier_model;
- protected $powerConsumptionDetails_model;
- protected $coatingMachineDetails_model;
- protected $drierMachineDetails_model;
- protected $factoryMachine_model;
- protected $factoryVehicleDieselDetails_model;
- protected $factoryVehicleDieselStockSummary_model;
- protected $session;
- protected $incomingSilicaSandDetails_model;
- protected $inwardGateRegister_model;
- protected $rawmaterialdetails_model;
- protected $bagStockDetails_model;
- protected $Rawmaterialdetails_model;
- protected $dustAndRoughStockDetails_model;
- protected $resinStockDetails_model;
- protected $gasStockDetails_model;
-
+ protected $supplier_model;
+ protected $powerConsumptionDetails_model;
+ protected $coatingMachineDetails_model;
+ protected $drierMachineDetails_model;
+ protected $factoryMachine_model;
+ protected $factoryVehicleDieselDetails_model;
+ protected $factoryVehicleDieselStockSummary_model;
+ protected $session;
+ protected $incomingSilicaSandDetails_model;
+ protected $inwardGateRegister_model;
+ protected $rawmaterialdetails_model;
+ protected $bagStockDetails_model;
+ protected $Rawmaterialdetails_model;
+ protected $dustAndRoughStockDetails_model;
+ protected $resinStockDetails_model;
+ protected $gasStockDetails_model;
+
/**
* This is default constructor of the class
*/
public function __construct()
{
- $this->db = \Config\Database::connect();
- parent::__construct();
+ $this->db = \Config\Database::connect();
+ parent::__construct();
- $this->supplier_model = new Supplier_model();
+ $this->supplier_model = new Supplier_model();
- $this->powerConsumptionDetails_model = new PowerConsumptionDetails();
+ $this->powerConsumptionDetails_model = new PowerConsumptionDetails();
- $this->coatingMachineDetails_model = new CoatingMachineDetailsModel();
+ $this->coatingMachineDetails_model = new CoatingMachineDetailsModel();
- $this->drierMachineDetails_model = new DrierMachineDetailsModel();
+ $this->drierMachineDetails_model = new DrierMachineDetailsModel();
- $this->factoryMachine_model = new FactoryMachineModel();
+ $this->factoryMachine_model = new FactoryMachineModel();
- $this->factoryVehicleDieselDetails_model = new FactoryVehicleDieselDetailsModel();
+ $this->factoryVehicleDieselDetails_model = new FactoryVehicleDieselDetailsModel();
- $this->factoryVehicleDieselStockSummary_model = new FactoryVehicleDieselStockSummaryModel();
+ $this->factoryVehicleDieselStockSummary_model = new FactoryVehicleDieselStockSummaryModel();
- $this->rawmaterialdetails_model = new Rawmaterialdetails_model();
+ $this->rawmaterialdetails_model = new Rawmaterialdetails_model();
- $this->incomingSilicaSandDetails_model = new IncomingSilicaSandDetailsModel();
+ $this->incomingSilicaSandDetails_model = new IncomingSilicaSandDetailsModel();
- $this->inwardGateRegister_model = new Inwardgateregister_model();
+ $this->inwardGateRegister_model = new Inwardgateregister_model();
- $this->bagStockDetails_model = new BagStockDetailsModel();
+ $this->bagStockDetails_model = new BagStockDetailsModel();
- $this->dustAndRoughStockDetails_model = new DustAndRoughModel();
+ $this->dustAndRoughStockDetails_model = new DustAndRoughModel();
- $this->resinStockDetails_model = new ResinStockModel() ;
-
- $this->gasStockDetails_model = new GasStockModel() ;
-
-
- $this->session = session();
- helper('form');
-
- $this->isLoggedIn();
+ $this->resinStockDetails_model = new ResinStockModel();
+
+ $this->gasStockDetails_model = new GasStockModel();
+
+
+ $this->session = session();
+ helper('form');
+
+ $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');
-
- $date = DateTime::createFromFormat('M-Y', $month);
-
- $formattedDate = $date->format('Y-m');
-
- $month=$formattedDate;
- }
- else{
-
- $filteredMonth=$this->request->getGet('month');
- $month = $filteredMonth ?? 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);
-
-}
-
-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 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);
-
- 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);
- }
-
- // 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);
- }
-
- }
-
- echo "Data Saved Successfully";
-
-}
-
-
- // Bag Stock details starts
-public function loadView_bagStockDetails(){
-
- if ($this->request->getMethod() === 'POST'){
+ if ($this->request->getMethod() === 'POST') {
$month = $this->request->getPost('month');
$date = DateTime::createFromFormat('M-Y', $month);
$formattedDate = $date->format('Y-m');
- $month=$formattedDate;
+ $month = $formattedDate;
+ } else {
+
+ $filteredMonth = $this->request->getGet('month');
+ $month = $filteredMonth ?? date('Y-m');
}
- else{
+
+ $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);
+
+ }
+
+ 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 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);
+
+ 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);
+ }
+
+ // 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=[];
+ $data['month'] = $month;
- $data['month']=$month;
+ $this->global['pageTitle'] = 'Incoming Silica Sand Details';
- $this->global['pageTitle']='Bag Stock Details';
+ $materialCodes = $this->rawmaterialdetails_model->getAllSilicaRawMaterialCode();
-
- $previousMonth = DateTime::createFromFormat('Y-m', $month)->modify('-1 month')->format('Y-m');
- $previousMonthStartDate = "$previousMonth-01";
- $previousMonthEndDate = date("Y-m-t", strtotime($previousMonthStartDate));
- $data['previousMonthBagStockDetails'] = $this->bagStockDetails_model
- ->select(['materialCode', 'date' ,'balanceStock'])
- ->distinct()
- ->where('date =', $previousMonthEndDate)
- ->groupBy(['materialCode','date'])
- ->orderBy('date','desc')
- ->orderBy('materialCode','asc')
- ->findAll();
+ 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);
- $startDate = "$month-01";
- $endDate = date("Y-m-t", strtotime($startDate));
- $data['bagStockDetails'] = $this->bagStockDetails_model
- ->where('date >=', $startDate)
- ->where('date <=', $endDate)
- ->groupBy(['materialCode','date'])
- ->orderBy('date','asc')
- ->orderBy('materialCode','asc')
- ->findAll();
+ 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);
+ }
+
+ }
+
+ echo "Data Saved Successfully";
+
+ }
+
+
+ // Bag Stock details starts
+ public function loadView_bagStockDetails()
+ {
+
+ 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'] = 'Bag Stock Details';
+
+
+ $previousMonth = DateTime::createFromFormat('Y-m', $month)->modify('-1 month')->format('Y-m');
+ $previousMonthStartDate = "$previousMonth-01";
+ $previousMonthEndDate = date("Y-m-t", strtotime($previousMonthStartDate));
+ $data['previousMonthBagStockDetails'] = $this->bagStockDetails_model
+ ->select(['materialCode', 'date', 'balanceStock'])
+ ->distinct()
+ ->where('date =', $previousMonthEndDate)
+ ->groupBy(['materialCode', 'date'])
+ ->orderBy('date', 'desc')
+ ->orderBy('materialCode', 'asc')
+ ->findAll();
+
+
+
+
+ $startDate = "$month-01";
+ $endDate = date("Y-m-t", strtotime($startDate));
+ $data['bagStockDetails'] = $this->bagStockDetails_model
+ ->where('date >=', $startDate)
+ ->where('date <=', $endDate)
+ ->groupBy(['materialCode', 'date'])
+ ->orderBy('date', 'asc')
+ ->orderBy('materialCode', 'asc')
+ ->findAll();
// Initialize an empty array to hold the grouped data
$data['groupedBagStockDetails'] = [];
@@ -395,38 +399,39 @@ public function loadView_bagStockDetails(){
// Reset the structure to have indexed arrays without the date keys
$data['groupedBagStockDetails'] = array_values($groupedByDate);
-
- $bagMaterials= $this->rawmaterialdetails_model->getAllBagMaterialCode();
-
+ $bagMaterials = $this->rawmaterialdetails_model->getAllBagMaterialCode();
- foreach($bagMaterials as $key => $bagMaterial){
+
+
+ foreach ($bagMaterials as $key => $bagMaterial) {
$materialCode = $bagMaterial['MaterialCode'];
- $bagMaterials[$key]['customers'] = $this->bagStockDetails_model
- ->select('customer')
- ->where('date >=', $startDate)
- ->where('date <=', $endDate)
- ->where('materialCode', $materialCode)
- ->first()['customer'] ?? '';
- }
-
- $bagMaterialcount = count($bagMaterials);
-
- $data['bagMaterialcount'] = $bagMaterialcount;
- $data['bagMaterials'] = $bagMaterials;
-
- $date = DateTime::createFromFormat('Y-m', $month);
+ $bagMaterials[$key]['customers'] = $this->bagStockDetails_model
+ ->select('customer')
+ ->where('date >=', $startDate)
+ ->where('date <=', $endDate)
+ ->where('materialCode', $materialCode)
+ ->first()['customer'] ?? '';
+ }
- $formattedDate = $date->format('M-Y');
+ $bagMaterialcount = count($bagMaterials);
- $data['month']=$formattedDate;
+ $data['bagMaterialcount'] = $bagMaterialcount;
+ $data['bagMaterials'] = $bagMaterials;
- return $this->loadViews("bagStockDetails", $this->global, $data, NULL);
+ $date = DateTime::createFromFormat('Y-m', $month);
-}
+ $formattedDate = $date->format('M-Y');
-public function updateBagStockDetails(){
+ $data['month'] = $formattedDate;
+
+ return $this->loadViews("bagStockDetails", $this->global, $data, NULL);
+
+ }
+
+ public function updateBagStockDetails()
+ {
$postData = $this->request->getPost();
@@ -435,44 +440,44 @@ public function updateBagStockDetails(){
$inserts = [];
$updates = [];
- foreach($updateBagStockDetailsData as $data){
-
+ foreach ($updateBagStockDetailsData as $data) {
+
$date = $data['date'];
$materialCode = $data['materialCode'];
-
-
- $dbData= [
- 'date' =>$data['date'],
- 'materialCode' =>$data['materialCode'],
- 'customer' =>$data['customer'],
- 'opening' =>$data['opening'],
- 'receipt' =>$data['receipt'],
- 'used' =>$data['used'],
- 'balanceStock' =>$data['balanceStock'],
+
+
+ $dbData = [
+ 'date' => $data['date'],
+ 'materialCode' => $data['materialCode'],
+ 'customer' => $data['customer'],
+ 'opening' => $data['opening'],
+ 'receipt' => $data['receipt'],
+ 'used' => $data['used'],
+ 'balanceStock' => $data['balanceStock'],
];
-
- $resultExists=$this->bagStockDetails_model
- ->where('date',$date)
- ->where('materialCode',$materialCode)
- ->first();
+
+ $resultExists = $this->bagStockDetails_model
+ ->where('date', $date)
+ ->where('materialCode', $materialCode)
+ ->first();
- if(empty($resultExists)){
- $inserts [] = $dbData;
-
- }else{
- $dbData['id']=$resultExists['id'];
- $updates [] = $dbData;
-
- }
+ if (empty($resultExists)) {
+ $inserts[] = $dbData;
+
+ } else {
+ $dbData['id'] = $resultExists['id'];
+ $updates[] = $dbData;
+
+ }
}
-
- if(!empty($inserts)){
+
+ if (!empty($inserts)) {
$inserted = $this->bagStockDetails_model->insertBatch($inserts);
}
- if(!empty($updates)){
+ if (!empty($updates)) {
- $updateResult = $this->bagStockDetails_model->updateBatch($updates,'id');
+ $updateResult = $this->bagStockDetails_model->updateBatch($updates, 'id');
if ($updateResult === FALSE) {
echo "Error during update";
@@ -482,53 +487,54 @@ public function updateBagStockDetails(){
}
}
-
- echo "Data Saved Successfully";
-
-}
+
+ echo "Data Saved Successfully";
+
+ }
//Dust And Rough Stock Details
-public function loadView_dustAndRoughStockDetails(){
+ public function loadView_dustAndRoughStockDetails()
+ {
- if ($this->request->getMethod() === 'POST'){
+ 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 = $formattedDate;
+ } else {
$month = date('Y-m');
}
- $data=[];
+ $data = [];
- $data['month']=$month;
+ $data['month'] = $month;
- $this->global['pageTitle']='Dust And Rough Stock Details';
+ $this->global['pageTitle'] = 'Dust And Rough Stock Details';
- $startDate = "$month-01";
- $endDate = date("Y-m-t", strtotime($startDate));
- $data['dustAndRoughStockDetails'] = $this->dustAndRoughStockDetails_model
- ->where('date >=', $startDate)
- ->where('date <=', $endDate)
- ->orderBy('date','asc')
- ->findAll();
+ $startDate = "$month-01";
+ $endDate = date("Y-m-t", strtotime($startDate));
+ $data['dustAndRoughStockDetails'] = $this->dustAndRoughStockDetails_model
+ ->where('date >=', $startDate)
+ ->where('date <=', $endDate)
+ ->orderBy('date', 'asc')
+ ->findAll();
- $date = DateTime::createFromFormat('Y-m', $month);
+ $date = DateTime::createFromFormat('Y-m', $month);
- $formattedDate = $date->format('M-Y');
+ $formattedDate = $date->format('M-Y');
- $data['month']=$formattedDate;
+ $data['month'] = $formattedDate;
- return $this->loadViews("dustAndRoughStockDetails", $this->global, $data, NULL);
+ return $this->loadViews("dustAndRoughStockDetails", $this->global, $data, NULL);
-}
+ }
-public function updateDustAndRoughStockDetails(){
+ public function updateDustAndRoughStockDetails()
+ {
$postData = $this->request->getPost();
@@ -538,57 +544,58 @@ public function updateDustAndRoughStockDetails(){
$inserts = [];
- foreach($updateDustAndRoughStockDetailsData as $data){
-
- $data['date'] = DateTime::createFromFormat('d-m-Y', $data['date'])->format('Y-m-d');
+ foreach ($updateDustAndRoughStockDetailsData as $data) {
- $date =$data['date'];
-
- $dbData= [
- 'date' => $data['date'],
- 'finalRough' => $data['finalRough'],
- 'dust' => $data['dust'],
- 'total' => $data['total']
- ];
-
- $resultExists=$this->dustAndRoughStockDetails_model
- ->where('date',$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)
->first();
-
-
- if (empty($resultExists)) {
- $inserts[] = $dbData;
-
- } else {
- $updates[] = $dbData;
- }
- }
- if (!empty($inserts)) {
- $this->dustAndRoughStockDetails_model->insertBatch($inserts);
- }
- if (!empty($updates)) {
+ if (empty($resultExists)) {
+ $inserts[] = $dbData;
- $updateResult = $this->dustAndRoughStockDetails_model->updateBatch($updates, 'date');
-
- if ($updateResult === FALSE) {
- echo "Error during update";
- } else {
- echo "Data Updated Successfully";
- return;
- }
+ } else {
+ $updates[] = $dbData;
}
-
- echo "Data Saved Successfully";
-
-}
-
+ }
+
+ if (!empty($inserts)) {
+ $this->dustAndRoughStockDetails_model->insertBatch($inserts);
+ }
+
+ if (!empty($updates)) {
+
+ $updateResult = $this->dustAndRoughStockDetails_model->updateBatch($updates, 'date');
+
+ if ($updateResult === FALSE) {
+ echo "Error during update";
+ } else {
+ echo "Data Updated Successfully";
+ return;
+ }
+ }
+
+ echo "Data Saved Successfully";
+
+ }
+
//Resin Stock Details
-public function loadView_resinStockDetails(){
+ public function loadView_resinStockDetails()
+ {
- if ($this->request->getMethod() === 'POST'){
+ if ($this->request->getMethod() === 'POST') {
$month = $this->request->getPost('month');
@@ -596,43 +603,42 @@ public function loadView_resinStockDetails(){
$formattedDate = $date->format('Y-m');
- $month=$formattedDate;
- }
- else{
+ $month = $formattedDate;
+ } else {
$month = date('Y-m');
}
- $data=[];
+ $data = [];
- $data['month']=$month;
+ $data['month'] = $month;
- $this->global['pageTitle']='Resin Stock Details';
-
-
- $previousMonth = DateTime::createFromFormat('Y-m', $month)->modify('-1 month')->format('Y-m');
- $previousMonthStartDate = "$previousMonth-01";
- $previousMonthEndDate = date("Y-m-t", strtotime($previousMonthStartDate));
- $data['previousMonthResinStockDetails'] = $this->resinStockDetails_model
- ->select(['materialCode', 'date' ,'balanceStock'])
- ->distinct()
- ->where('date =', $previousMonthEndDate)
- ->groupBy(['materialCode','date'])
- ->orderBy('date','desc')
- ->orderBy('materialCode','asc')
- ->findAll();
-
-
+ $this->global['pageTitle'] = 'Resin Stock Details';
- $startDate = "$month-01";
- $endDate = date("Y-m-t", strtotime($startDate));
+ $previousMonth = DateTime::createFromFormat('Y-m', $month)->modify('-1 month')->format('Y-m');
+ $previousMonthStartDate = "$previousMonth-01";
+ $previousMonthEndDate = date("Y-m-t", strtotime($previousMonthStartDate));
+ $data['previousMonthResinStockDetails'] = $this->resinStockDetails_model
+ ->select(['materialCode', 'date', 'balanceStock'])
+ ->distinct()
+ ->where('date =', $previousMonthEndDate)
+ ->groupBy(['materialCode', 'date'])
+ ->orderBy('date', 'desc')
+ ->orderBy('materialCode', 'asc')
+ ->findAll();
+
+
+
+
+ $startDate = "$month-01";
+ $endDate = date("Y-m-t", strtotime($startDate));
$data['resinStockDetails'] = $this->resinStockDetails_model
- ->where('date >=', $startDate)
- ->where('date <=', $endDate)
- ->groupBy(['materialCode','date'])
- ->orderBy('date','asc')
- ->orderBy('materialCode','asc')
- ->findAll();
+ ->where('date >=', $startDate)
+ ->where('date <=', $endDate)
+ ->groupBy(['materialCode', 'date'])
+ ->orderBy('date', 'asc')
+ ->orderBy('materialCode', 'asc')
+ ->findAll();
// Initialize an empty array to hold the grouped data
$data['groupedResinStockDetails'] = [];
@@ -656,36 +662,37 @@ public function loadView_resinStockDetails(){
// Reset the structure to have indexed arrays without the date keys
$data['groupedResinStockDetails'] = array_values($groupedByDate);
-
- $resinMaterials= $this->rawmaterialdetails_model->getAllResinMaterialCode();
- foreach($resinMaterials as $key => $resinMaterial){
+ $resinMaterials = $this->rawmaterialdetails_model->getAllResinMaterialCode();
+
+ foreach ($resinMaterials as $key => $resinMaterial) {
$materialCode = $resinMaterial['MaterialCode'];
- $resinMaterials[$key]['customers'] = $this->bagStockDetails_model
- ->select('customer')
- ->where('date >=', $startDate)
- ->where('date <=', $endDate)
- ->where('materialCode', $materialCode)
- ->first()['customer'] ?? '';
- }
-
- $resinMaterialCount = count($resinMaterials);
-
- $data['resinMaterialCount'] = $resinMaterialCount;
- $data['resinMaterials'] = $resinMaterials;
-
- $date = DateTime::createFromFormat('Y-m', $month);
+ $resinMaterials[$key]['customers'] = $this->bagStockDetails_model
+ ->select('customer')
+ ->where('date >=', $startDate)
+ ->where('date <=', $endDate)
+ ->where('materialCode', $materialCode)
+ ->first()['customer'] ?? '';
+ }
- $formattedDate = $date->format('M-Y');
+ $resinMaterialCount = count($resinMaterials);
- $data['month']=$formattedDate;
+ $data['resinMaterialCount'] = $resinMaterialCount;
+ $data['resinMaterials'] = $resinMaterials;
- return $this->loadViews("resinStockDetails", $this->global, $data, NULL);
+ $date = DateTime::createFromFormat('Y-m', $month);
-}
+ $formattedDate = $date->format('M-Y');
-public function updateResinStockDetails(){
+ $data['month'] = $formattedDate;
+
+ return $this->loadViews("resinStockDetails", $this->global, $data, NULL);
+
+ }
+
+ public function updateResinStockDetails()
+ {
$postData = $this->request->getPost();
@@ -696,63 +703,64 @@ public function updateResinStockDetails(){
$inserts = [];
- foreach($updateResinStockDetailsData as $data){
-
+ foreach ($updateResinStockDetailsData as $data) {
+
$date = $data['date'];
$materialCode = $data['materialCode'];
-
-
- $dbData = [
- 'date' =>$data['date'],
- 'materialCode' =>$data['materialCode'],
- 'customer' =>$data['customer'],
- 'opening' =>$data['opening'],
- 'receipt' =>$data['receipt'],
- 'used' =>$data['used'],
- 'balanceStock' =>$data['balanceStock'],
+
+
+ $dbData = [
+ 'date' => $data['date'],
+ 'materialCode' => $data['materialCode'],
+ 'customer' => $data['customer'],
+ 'opening' => $data['opening'],
+ 'receipt' => $data['receipt'],
+ 'used' => $data['used'],
+ 'balanceStock' => $data['balanceStock'],
];
-
- $resultExists = $this->resinStockDetails_model
- ->where('date',$date)
- ->where('materialCode',$materialCode)
- ->first();
+
+ $resultExists = $this->resinStockDetails_model
+ ->where('date', $date)
+ ->where('materialCode', $materialCode)
+ ->first();
- if(empty($resultExists)){
- $inserts[] = $dbData;
- }else{
- $dbData['id']=$resultExists['id'];
- $updates[] = $dbData ;
- }
-
+ if (empty($resultExists)) {
+ $inserts[] = $dbData;
+ } else {
+ $dbData['id'] = $resultExists['id'];
+ $updates[] = $dbData;
+ }
+
}
- if (!empty($inserts)) {
- $this->resinStockDetails_model->insertBatch($inserts);
+ 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;
}
+ }
- if (!empty($updates)) {
+ echo "Data Saved Successfully";
- $updateResult = $this->resinStockDetails_model->updateBatch($updates, 'id');
-
- if ($updateResult === FALSE) {
- echo "Error during update";
- } else {
- echo "Data Updated Successfully";
- return;
- }
- }
-
- echo "Data Saved Successfully";
-
-}
+ }
//Gas Stock Details
-public function loadView_gasStockDetails(){
+ public function loadView_gasStockDetails()
+ {
- if ($this->request->getMethod() === 'POST'){
+ if ($this->request->getMethod() === 'POST') {
$month = $this->request->getPost('month');
@@ -760,41 +768,40 @@ public function loadView_gasStockDetails(){
$formattedDate = $date->format('Y-m');
- $month=$formattedDate;
- }
- else{
+ $month = $formattedDate;
+ } else {
$month = date('Y-m');
}
- $data=[];
+ $data = [];
- $data['month']=$month;
+ $data['month'] = $month;
$this->global['pageTitle'] = "Gas Stock Details";
- $previousMonth = DateTime::createFromFormat('Y-m', $month)->modify('-1 month')->format('Y-m');
- $previousMonthStartDate = "$previousMonth-01";
- $previousMonthEndDate = date("Y-m-t", strtotime($previousMonthStartDate));
- $data['previousMonthGasStockDetails'] = $this->gasStockDetails_model
- ->select('date,balanceStock')
- ->where('date =', $previousMonthEndDate)
- ->orderBy('date','desc')
+ $previousMonth = DateTime::createFromFormat('Y-m', $month)->modify('-1 month')->format('Y-m');
+ $previousMonthStartDate = "$previousMonth-01";
+ $previousMonthEndDate = date("Y-m-t", strtotime($previousMonthStartDate));
+ $data['previousMonthGasStockDetails'] = $this->gasStockDetails_model
+ ->select('date,balanceStock')
+ ->where('date =', $previousMonthEndDate)
+ ->orderBy('date', 'desc')
->findAll();
- $startDate = "$month-01";
- $endDate = date("Y-m-t", strtotime($startDate));
-
+ $startDate = "$month-01";
+ $endDate = date("Y-m-t", strtotime($startDate));
+
$data['gasStockDetails'] = $this->gasStockDetails_model
- ->select('t_gasStockDetails.*,
+ ->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,
+ )
+ // Subquery with early date filtering
+ ->join(
+ '(SELECT date,
SUM(totalGasconsumption) AS coatingMachineGasconsumption,
SUM(totalCoatingSandInKg) / 1000 AS coatedSand
FROM t_coatingMachineDetails
@@ -803,30 +810,32 @@ public function loadView_gasStockDetails(){
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
+ '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();
+ 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);
-}
+ return $this->loadViews("gasStockDetails", $this->global, $data, NULL);
+ }
+
+ public function updateGasStockDetails()
+ {
-public function updateGasStockDetails(){
-
$postData = $this->request->getPost();
$updateGasStockDetailsData = json_decode($postData['updateGasStockDetails'], true);
@@ -835,105 +844,105 @@ public function updateGasStockDetails(){
$inserts = [];
- foreach($updateGasStockDetailsData as $data){
-
+ 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 ;
- }
-
+ $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($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;
}
+ }
- if (!empty($updates)) {
+ echo "Data Saved Successfully";
+ }
- $updateResult = $this->gasStockDetails_model->updateBatch($updates, 'id');
+ private function updateGasStockConsumption($date, $consumption)
+ {
- if ($updateResult === FALSE) {
- echo "Error during update";
- } else {
- echo "Data Updated Successfully";
- return;
- }
- }
-
- echo "Data Saved Successfully";
-}
+ $resultExists = $this->gasStockDetails_model
+ ->where('date', $date)
+ ->first();
-private function updateGasStockConsumption($date , $consumption){
+ if ($resultExists) {
- $resultExists = $this->gasStockDetails_model
- ->where('date',$date)
- ->first();
-
- if($resultExists){
-
- $resultExists['consumption'] = $resultExists['consumption']+($consumption);
+ $resultExists['consumption'] = $resultExists['consumption'] + ($consumption);
$resultExists['balanceStock'] = $resultExists['opening'] - $resultExists['consumption'];
- $this->gasStockDetails_model->update($resultExists['id'],$resultExists);
-
- }
- else{
+ $this->gasStockDetails_model->update($resultExists['id'], $resultExists);
+
+ } else {
+
-
$previousMonthDate = new DateTime($date);
$previousMonthDate = $previousMonthDate->modify('first day of this month')
- ->modify('-1 day')
- ->format('Y-m-d');
+ ->modify('-1 day')
+ ->format('Y-m-d');
+
+
-
-
$previousMonthResultExists = $this->gasStockDetails_model
- ->where('date',$previousMonthDate)
- ->first();
+ ->where('date', $previousMonthDate)
+ ->first();
+
-
$opening = 0;
- if(!empty($previousMonthResultExists) && isset($previousMonthResultExists['balanceStock']) ){
- $opening =$previousMonthResultExists['balanceStock'];
- }
+ if (!empty($previousMonthResultExists) && isset($previousMonthResultExists['balanceStock'])) {
+ $opening = $previousMonthResultExists['balanceStock'];
+ }
+
-
$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');
+ $endDate = DateTime::createFromFormat('Y-m-d', $date)->modify('last day of this month')->format('Y-m-d');
$datesInMonth = [];
- $inserts = [];
+ $inserts = [];
$period = new DatePeriod(
new DateTime($startDate),
new DateInterval('P1D'),
- (new DateTime($endDate))->modify('+1 day')
+ (new DateTime($endDate))->modify('+1 day')
);
-
+
foreach ($period as $day) {
$datesInMonth[] = $day->format('Y-m-d');
}
@@ -941,52 +950,53 @@ private function updateGasStockConsumption($date , $consumption){
foreach ($datesInMonth as $datesInMonthIndex => $dateInMonth) {
//update previousMonthResultExists
- $balanceStock = $opening ;
+ $balanceStock = $opening;
$consumptionForDate = 0;
- if($dateInMonth == $date){
+ if ($dateInMonth == $date) {
$consumptionForDate = $consumption;
- $balanceStock = $opening - $consumption ;
+ $balanceStock = $opening - $consumption;
}
-
+
$inserts[] = [
- 'date' => $dateInMonth,
- 'opening' => $opening,
+ 'date' => $dateInMonth,
+ 'opening' => $opening,
'purchaseBharath' => 0,
- 'purchaseIndian' => 0,
- 'total' => 0,
- 'consumption' => $consumptionForDate,
- 'balanceStock' => $balanceStock
+ 'purchaseIndian' => 0,
+ 'total' => 0,
+ 'consumption' => $consumptionForDate,
+ 'balanceStock' => $balanceStock
];
- $opening = $balanceStock;
-
+ $opening = $balanceStock;
+
}
- if(!empty($inserts)){
+ if (!empty($inserts)) {
$this->gasStockDetails_model->insertBatch($inserts);
}
}
-}
+ }
// --------------------------------------------gwm----------------------------------------------
-public function getMonthDatesFromInput($monthYear) {
-
+ public function getMonthDatesFromInput($monthYear)
+ {
+
$date = DateTime::createFromFormat('M-Y', $monthYear);
if (!$date) {
return "Invalid date format. Use 'M-yyyy' format.";
}
-
+
$year = $date->format('Y');
$month = $date->format('m');
-
+
$totalDays = cal_days_in_month(CAL_GREGORIAN, $month, $year);
-
+
$dates = [];
for ($day = 1; $day <= $totalDays; $day++) {
@@ -997,11 +1007,12 @@ public function getMonthDatesFromInput($monthYear) {
'database' => $currentDate->format('Y-m-d')
];
}
-
- return $dates;
-}
-public function generateTimeOptions() {
+ return $dates;
+ }
+
+ public function generateTimeOptions()
+ {
$times = [];
$start = strtotime('00:00'); // Start at midnight (12:00 AM)
$end = strtotime('23:45'); // End at 11:45 PM
@@ -1014,43 +1025,44 @@ public function generateTimeOptions() {
}
return $times;
-}
+ }
+
+ public function drierMachineDetails()
+ {
-public function drierMachineDetails(){
-
$currentMonth = $this->request->getPost('month') ? $this->request->getPost('month') : date('M-Y');
-
+
$monthData = $this->getMonthDatesFromInput($currentMonth);
-
+
$data['startDate'] = $monthData[0]['database'];
- $data['endDate'] = $monthData[count($monthData)-1]['database'];
+ $data['endDate'] = $monthData[count($monthData) - 1]['database'];
$data['timeDropdown'] = $this->generateTimeOptions();
$data['supplierData'] = $this->supplier_model->supplierlisting();
- $data['drierDetails'] = $this->drierMachineDetails_model->where('date >=', $data['startDate'])->where('date <=', $data['endDate'])->findAll();
- if(!count($data['drierDetails']))
- {
+ $data['drierDetails'] = $this->drierMachineDetails_model->where('date >=', $data['startDate'])->where('date <=', $data['endDate'])->findAll();
+ if (!count($data['drierDetails'])) {
//insert empty data
$tempInsert = [];
foreach ($monthData as $key => $value) {
- array_push($tempInsert,[ 'date'=>$value['database'] ]);
+ array_push($tempInsert, ['date' => $value['database']]);
}
$this->drierMachineDetails_model->insertBatch($tempInsert);
- $data['drierDetails'] = $this->drierMachineDetails_model->where('date >=', $data['startDate'])->where('date <=', $data['endDate'])->findAll();
- }
+ $data['drierDetails'] = $this->drierMachineDetails_model->where('date >=', $data['startDate'])->where('date <=', $data['endDate'])->findAll();
+ }
$data['datefordropdown'] = $currentMonth;
-
-
+
+
$this->global['pageTitle'] = 'Drier Details';
- $this->loadViews("drierMachineDetails", $this->global, $data, NULL);
-}
+ $this->loadViews("drierMachineDetails", $this->global, $data, NULL);
+ }
-public function addOrEditdrierMachineDetails(){
+ public function addOrEditdrierMachineDetails()
+ {
$drierData = json_decode($this->request->getPost('drierData'), true);
if (empty($drierData)) {
@@ -1060,20 +1072,20 @@ public function addOrEditdrierMachineDetails(){
foreach ($drierData as $row) {
$data = [
- 'date' => DateTime::createFromFormat('d-m-Y', $row['Date'])->format('Y-m-d'),
- 'drier_on_time' => $row['Drier On Time'],
- 'drier_off_time' => $row['Drier Off Time'],
- 'drier_running_hours' => $row['Running Hrs'],
- 'supplier_name' => $row['Supplier Name'],
- 'input_sand_moisture' => $row['i/p Sand Moisture(%)'],
- 'total_gas_consumption'=> $row['Tot Gas Consumption'],
- 'gas_per_ton' => $row['Gas Pre Ton'],
- 'input_sand_qty' => $row['i/p Sand Qty'],
- 'moisture_loss_qty' => $row['Moisture Loss Qty'],
- 'sand_dried_qty' => $row['Sand Dried Qty'],
- 'qty_per_hours' => $row['Qty Per Hrs'],
- 'dust_qty' => $row['Dust Qty'],
- 'customer_name' => $row['Customer Name']
+ 'date' => DateTime::createFromFormat('d-m-Y', $row['Date'])->format('Y-m-d'),
+ 'drier_on_time' => $row['Drier On Time'],
+ 'drier_off_time' => $row['Drier Off Time'],
+ 'drier_running_hours' => $row['Running Hrs'],
+ 'supplier_name' => $row['Supplier Name'],
+ 'input_sand_moisture' => $row['i/p Sand Moisture(%)'],
+ 'total_gas_consumption' => $row['Tot Gas Consumption'],
+ 'gas_per_ton' => $row['Gas Pre Ton'],
+ 'input_sand_qty' => $row['i/p Sand Qty'],
+ 'moisture_loss_qty' => $row['Moisture Loss Qty'],
+ 'sand_dried_qty' => $row['Sand Dried Qty'],
+ 'qty_per_hours' => $row['Qty Per Hrs'],
+ 'dust_qty' => $row['Dust Qty'],
+ 'customer_name' => $row['Customer Name']
];
// Check if a row with the same date already exists
@@ -1085,83 +1097,80 @@ public function addOrEditdrierMachineDetails(){
//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);
+ $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
+
+ //before inserting the row update gas stock
$consumption = $row['Tot Gas Consumption'];
$dateToBeInserted = $data['date'];
- $this->updateGasStockConsumption($dateToBeInserted , $consumption);
+ $this->updateGasStockConsumption($dateToBeInserted, $consumption);
+
-
$this->drierMachineDetails_model->insert($data);
}
}
echo "Data successfully saved.";
-}
+ }
-public function factoryVehicleDieselDetails()
+ public function factoryVehicleDieselDetails()
{
$currentMonth = $this->request->getPost('month') ? $this->request->getPost('month') : date('M-Y');
-
+
$monthData = $this->getMonthDatesFromInput($currentMonth);
-
+
$data['startDate'] = $monthData[0]['database'];
- $data['endDate'] = $monthData[count($monthData)-1]['database'];
+ $data['endDate'] = $monthData[count($monthData) - 1]['database'];
$data['datefordropdown'] = $currentMonth;
//Machine Details
- $data['machineDetails'] = $this->factoryMachine_model->where('energy_type', 'diesel')->where('is_active', 1)->findAll();
- if(!count([$data['machineDetails']]))
- {
+ $data['machineDetails'] = $this->factoryMachine_model->where('energy_type', 'diesel')->where('is_active', 1)->findAll();
+ if (!count([$data['machineDetails']])) {
return $this->response->setBody("");
}
//Diesel Stock Summary Details
- $data['summaryDetails'] = $this->factoryVehicleDieselStockSummary_model->select('date,opening_stock as opening_stock_0,purchase_diesel as purchase_diesel_0,total_filling_diesel as total_filling_diesel_0,balance_stock as balance_stock_0')->where('date >=', $data['startDate'])->where('date <=', $data['endDate'])->findAll();
- if(!count($data['summaryDetails']))
- {
+ $data['summaryDetails'] = $this->factoryVehicleDieselStockSummary_model->select('date,opening_stock as opening_stock_0,purchase_diesel as purchase_diesel_0,total_filling_diesel as total_filling_diesel_0,balance_stock as balance_stock_0')->where('date >=', $data['startDate'])->where('date <=', $data['endDate'])->findAll();
+ if (!count($data['summaryDetails'])) {
//insert empty data
$tempInsert = [];
foreach ($monthData as $key => $value) {
- array_push($tempInsert,[ 'date'=>$value['database'] ]);
+ array_push($tempInsert, ['date' => $value['database']]);
}
$this->factoryVehicleDieselStockSummary_model->insertBatch($tempInsert);
- $data['summaryDetails'] = $this->factoryVehicleDieselStockSummary_model->where('date >=', $data['startDate'])->where('date <=', $data['endDate'])->findAll();
+ $data['summaryDetails'] = $this->factoryVehicleDieselStockSummary_model->where('date >=', $data['startDate'])->where('date <=', $data['endDate'])->findAll();
}
-
+
//Diesel Consumption Details
- $data['dieselConsumptionDetails'] = $this->getDieselConsumptionPivot($data['machineDetails'] , $data['startDate'] , $data['endDate']);
- if(!count($data['dieselConsumptionDetails']))
- {
+ $data['dieselConsumptionDetails'] = $this->getDieselConsumptionPivot($data['machineDetails'], $data['startDate'], $data['endDate']);
+ if (!count($data['dieselConsumptionDetails'])) {
//insert empty data
$tempInsert = [];
foreach ($monthData as $key => $value) {
- array_push($tempInsert,['date'=>$value['database'] , 'machine_id'=>$data['machineDetails'][0]['id'] ]);
+ array_push($tempInsert, ['date' => $value['database'], 'machine_id' => $data['machineDetails'][0]['id']]);
}
$this->factoryVehicleDieselDetails_model->insertBatch($tempInsert);
- $data['dieselConsumptionDetails'] = $this->getDieselConsumptionPivot($data['machineDetails'] , $data['startDate'] , $data['endDate']);
+ $data['dieselConsumptionDetails'] = $this->getDieselConsumptionPivot($data['machineDetails'], $data['startDate'], $data['endDate']);
}
-
+
$mergedArray = [];
// Loop through the first array
foreach ($data['summaryDetails'] as $item1) {
$date = $item1["date"];
-
+
// Find the matching item in the second array by date
foreach ($data['dieselConsumptionDetails'] as $item2) {
if ($item2["date"] === $date) {
@@ -1176,18 +1185,20 @@ public function factoryVehicleDieselDetails()
$data['machineName'] = array_column($data['machineDetails'], 'machine_name');
$this->global['pageTitle'] = 'Drier Details';
- $this->loadViews("factoryDieselMachineDetails", $this->global, $data, NULL);
-
-}
+ $this->loadViews("factoryDieselMachineDetails", $this->global, $data, NULL);
-public function getDieselConsumptionPivot($machineDetails , $startDate , $endDeate)
+ }
+
+ public function getDieselConsumptionPivot($machineDetails, $startDate, $endDeate)
{
$machineIds = array_column($machineDetails, 'id');
- if (empty($machineIds)) { return []; }
-
+ if (empty($machineIds)) {
+ return [];
+ }
+
$fields = ['opening_reading', 'closing_reading', 'filling_diesel', 'consumption', 'running_hours', 'mileage'];
-
+
$pivotColumns = [];
foreach ($machineIds as $machineId) {
foreach ($fields as $field) {
@@ -1196,34 +1207,36 @@ public function getDieselConsumptionPivot($machineDetails , $startDate , $endDea
}
$pivotColumnString = implode(", ", $pivotColumns);
-
+
$sql = "SELECT `date`, $pivotColumnString FROM `t_factoryVehicleDieselDetails`
WHERE machine_id IN (" . implode(",", $machineIds) . ") AND `date` >= ? AND `date` <= ?
GROUP BY `date`";
- $query = $this->db->query($sql, [$startDate,$endDeate]);
+ $query = $this->db->query($sql, [$startDate, $endDeate]);
$result = $query->getResultArray();
-
- return $result;
-}
-public function addOrEditfactoryVehicleDieselDetails()
+ return $result;
+ }
+
+ public function addOrEditfactoryVehicleDieselDetails()
{
$dieselMachineTableData = json_decode($this->request->getPost('dieselMachineTableData'), true);
-
+
$transformedData = [];
foreach ($dieselMachineTableData as $entry) {
$date = $entry['date'];
foreach ($entry as $key => $value) {
-
- if ($key === 'date') { continue; }
+
+ if ($key === 'date') {
+ continue;
+ }
preg_match('/(.*?)_(\d+)$/', $key, $matches);
if (count($matches) === 3) {
- $field = $matches[1];
- $machineId = $matches[2];
+ $field = $matches[1];
+ $machineId = $matches[2];
$insertKey = "{$date}_{$machineId}";
if (!isset($transformedData[$insertKey])) {
@@ -1247,12 +1260,11 @@ public function addOrEditfactoryVehicleDieselDetails()
foreach ($transformedData as $row) {
- if($row['machine_id'] == 0)
- {
+ if ($row['machine_id'] == 0) {
// Summary data: if machine_id is 0, it indicates summary data. This distinction is used because these records will be stored in a separate table.
- $this->factoryVehicleDieselStockSummary_model->where('date',$row['date'])->set($row)->update();
+ $this->factoryVehicleDieselStockSummary_model->where('date', $row['date'])->set($row)->update();
- }else{
+ } else {
// Diesel - factory vehicle data :
$existingRow = $this->factoryVehicleDieselDetails_model->where('date', $row['date'])->where('machine_id', $row['machine_id'])->first();
@@ -1263,65 +1275,66 @@ public function addOrEditfactoryVehicleDieselDetails()
}
}
-
+
}
echo "Data successfully saved.";
-
-}
+
+ }
-public function powerConsumptionDetails()
+ public function powerConsumptionDetails()
{
$currentMonth = $this->request->getPost('month') ? $this->request->getPost('month') : date('M-Y');
-
+
$monthData = $this->getMonthDatesFromInput($currentMonth);
-
+
$data['startDate'] = $monthData[0]['database'];
- $data['endDate'] = $monthData[count($monthData)-1]['database'];
+ $data['endDate'] = $monthData[count($monthData) - 1]['database'];
$data['datefordropdown'] = $currentMonth;
//Machine Details
- $data['machineDetails'] = $this->factoryMachine_model->where('energy_type', 'electric')->where('is_active', 1)->findAll();
- if(!count([$data['machineDetails']]))
- {
+ $data['machineDetails'] = $this->factoryMachine_model->where('energy_type', 'electric')->where('is_active', 1)->findAll();
+ if (!count([$data['machineDetails']])) {
return $this->response->setBody("");
}
-
-
+
+
//Diesel Consumption Details
- $data['powerConsumptionDetails'] = $this->getElectricConsumptionPivot($data['machineDetails'] , $data['startDate'] , $data['endDate']);
- if(!count($data['powerConsumptionDetails']))
- {
+ $data['powerConsumptionDetails'] = $this->getElectricConsumptionPivot($data['machineDetails'], $data['startDate'], $data['endDate']);
+ if (!count($data['powerConsumptionDetails'])) {
//insert empty data
$tempInsert = [];
foreach ($monthData as $key => $value) {
- array_push($tempInsert,['date'=>$value['database'] , 'machine_id'=>$data['machineDetails'][0]['id'] ]);
+ array_push($tempInsert, ['date' => $value['database'], 'machine_id' => $data['machineDetails'][0]['id']]);
}
$this->powerConsumptionDetails_model->insertBatch($tempInsert);
- $data['powerConsumptionDetails'] = $this->getElectricConsumptionPivot($data['machineDetails'] , $data['startDate'] , $data['endDate']);
+ $data['powerConsumptionDetails'] = $this->getElectricConsumptionPivot($data['machineDetails'], $data['startDate'], $data['endDate']);
}
-
-
+
+
$data['machineName'] = array_column($data['machineDetails'], 'machine_name');
$this->global['pageTitle'] = 'Power Consumption Details';
- $this->loadViews("powerConsumptionDetails", $this->global, $data, NULL);
-
-}
+ $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 []; }
-
+ if (empty($machineIds)) {
+ return [];
+ }
+
$fields = ['opening_units', 'closing_units', 'total_units'];
-
+
$pivotColumns = [];
foreach ($machineIds as $machineId) {
foreach ($fields as $field) {
@@ -1330,33 +1343,36 @@ public function getElectricConsumptionPivot($machineDetails , $startDate , $endD
}
$pivotColumnString = implode(", ", $pivotColumns);
-
+
$sql = "SELECT `date`, $pivotColumnString FROM `t_powerConsumptionDetails`
WHERE machine_id IN (" . implode(",", $machineIds) . ") AND `date` >= ? AND `date` <= ?
GROUP BY `date`";
- $query = $this->db->query($sql, [$startDate,$endDeate]);
+ $query = $this->db->query($sql, [$startDate, $endDeate]);
$result = $query->getResultArray();
-
- return $result;
-}
-public function addOrEditPowerConsumptionDetails(){
+ return $result;
+ }
+
+ public function addOrEditPowerConsumptionDetails()
+ {
$electricMachineTableData = json_decode($this->request->getPost('electricMachineTableData'), true);
-
+
$transformedData = [];
foreach ($electricMachineTableData as $entry) {
$date = $entry['date'];
foreach ($entry as $key => $value) {
-
- if ($key === 'date') { continue; }
+
+ if ($key === 'date') {
+ continue;
+ }
preg_match('/(.*?)_(\d+)$/', $key, $matches);
if (count($matches) === 3) {
- $field = $matches[1];
- $machineId = $matches[2];
+ $field = $matches[1];
+ $machineId = $matches[2];
$insertKey = "{$date}_{$machineId}";
if (!isset($transformedData[$insertKey])) {
@@ -1377,18 +1393,18 @@ public function addOrEditPowerConsumptionDetails(){
foreach ($transformedData as $row) {
- $existingRow = $this->powerConsumptionDetails_model->where('date', $row['date'])->where('machine_id', $row['machine_id'])->first();
- if ($existingRow) {
- $this->powerConsumptionDetails_model->update($existingRow['id'], $row);
- } else {
- $this->powerConsumptionDetails_model->insert($row);
- }
+ $existingRow = $this->powerConsumptionDetails_model->where('date', $row['date'])->where('machine_id', $row['machine_id'])->first();
+ if ($existingRow) {
+ $this->powerConsumptionDetails_model->update($existingRow['id'], $row);
+ } else {
+ $this->powerConsumptionDetails_model->insert($row);
+ }
}
echo "Data successfully saved.";
-
-}
-
+
+ }
+
}
diff --git a/app/Views/editImportAmendPO.php b/app/Views/editImportAmendPO.php
index 1f43901d..be8eaaa1 100755
--- a/app/Views/editImportAmendPO.php
+++ b/app/Views/editImportAmendPO.php
@@ -2956,7 +2956,7 @@ if (!empty($RequistionDetails)) {
//$('#SpcialInstruction').val('');
//$('#txtDeliveryAddress').val('');
- // window.location = status == 1 ? "amendmentpurchaseorder" : "purchaseorderListing";
+ window.location = status == 1 ? "amendmentpurchaseorder" : "purchaseorderListing";
} else {
alert("Error");
}