ria/app/Controllers/StockController.php
2024-10-08 17:30:53 +05:30

120 lines
3.4 KiB
PHP

<?php
namespace App\Controllers;
use App\Controllers\BaseController;
use App\Models\CoatingMachineDetailsModel;
use CodeIgniter\HTTP\ResponseInterface;
use DateTime;
class StockController extends BaseController
{
protected $coatingMachineDetails_model;
protected $session;
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->coatingMachineDetails_model = new CoatingMachineDetailsModel();
$this->session = session();
helper('form');
$this->isLoggedIn();
}
public function index()
{
//
}
public function loadView_coatingMachineDetails(){
$this->global['pageTitle'] = 'Coating Machine Details ';
$data['coatingMachineDetails']= $this->coatingMachineDetails_model
->where('is_active', 1)
->orderBy('created_at','DESC')
->findAll();
return $this->loadViews("CoatingMachineDetail", $this->global, $data, NULL);
}
public function addNewCoatingMachineDetails(){
$postData=$this->request->getPost();
$machineOnTime = $postData['machineOnTime'];
$machineOffTime = $postData['machineOffTime'];
$onTime = new DateTime($machineOnTime);
$offTime = new DateTime($machineOffTime);
$timeDifference = $onTime->diff($offTime);
$machineRunningInHrs = $timeDifference->h ;
$postData['machineRunningInHrs'] = $machineRunningInHrs;
$postData['perHourGasConsumption']= (float)$postData['totalGasConsumption']/$machineRunningInHrs;
$postData['perHourCoatingSandQTY']= (float)$postData['totalCoatingSandInKg']/$machineRunningInHrs;
//dd( $postData['perHourCoatingSandQTY']);
$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 = $this->request->getGet('id');
$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');
}
}
}