ria/app/Controllers/FactoryMachineController.php
2024-10-04 14:19:10 +05:30

159 lines
4.5 KiB
PHP

<?php
namespace App\Controllers;
use App\Controllers\BaseController;
use App\Models\FactoryMachineModel;
use CodeIgniter\HTTP\ResponseInterface;
class FactoryMachineController extends BaseController
{
protected $factoryMachineMaster_model;
protected $session;
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->factoryMachineMaster_model = new FactoryMachineModel;
$this->session = session();
helper('form'); //$this->load->library('form_validation');
$this->isLoggedIn();
}
public function index()
{
//
}
public function createFactoryMachineMasterDetails(){
$this->global['pageTitle'] = 'Create Factory Machine ';
$postData=[
'machine_name'=> $this->request->getPost('machineName'),
'machine_type'=> $this->request->getPost('machineType'),
'energy_type' => $this->request->getPost('energyType'),
];
$data = $this->factoryMachineMaster_model->insert($postData);
return redirect()->to('/readFactoryMachineMasterDetails');
}
public function loadView_createFactoryMachineMasterDetail(){
$this->global['pageTitle'] = 'Create Factory Machine Master Detail ';
$data['masterData']='';
return $this->loadViews("factoryMachineMasterDetailsCreate", $this->global, $data, NULL);
}
public function loadView_updateFactoryMachineMasterDetail(){
$this->global['pageTitle'] = 'Edit Factory Machine Master Detail ';
$id = $this->request->getGet('id');
$data['masterData'] = $this->factoryMachineMaster_model->where('id', $id)->where('is_active', 1)->first();
//here we are using same view - create Factory Machine Master Detail for
// updating Factory Machine Master Detail
return $this->loadViews("factoryMachineMasterDetailsCreate", $this->global, $data, NULL);
}
public function readFactoryMachineMasterDetails(){
$this->global['pageTitle'] = 'Factory Machine Master Details';
$data['masterData'] = $this->factoryMachineMaster_model->where('is_active', 1)
->where('is_active', 1)
->orderBy('created_at','DESC')
->findAll();
return $this->loadViews("factoryMachineMasterDetails", $this->global, $data, NULL);
}
public function readFactoryMachineMasterDetailsById(){
$this->global['pageTitle'] = 'Factory Machine Master Detail ';
$id = $this->request->getPost('id');
$data = $this->factoryMachineMaster_model->where('id', $id)
->where('is_active', 1)
->orderBy('created_at','DESC')
->first();
return $this->loadViews("factoryMachineMasterDetails", $this->global, $data, NULL);
}
public function updateFactoryMachineMasterDetails(){
$this->global['pageTitle'] = 'Edit Factory Machine Master Detail ';
$id = $this->request->getGet('id');
$postData=[
'machine_name'=> $this->request->getPost('machineName'),
'machine_type'=> $this->request->getPost('machineType'),
'energy_type' => $this->request->getPost('energyType'),
];
$updated = $this->factoryMachineMaster_model->update($id,$postData);
if ($updated) {
// Set flashdata for success message
return redirect()->to('/readFactoryMachineMasterDetails')->with('success', 'Machine details updated successfully');
} else {
// Set flashdata for error message
return redirect()->back()->with('error', 'Failed to update machine details');
}
}
public function deleteFactoryMachineMasterDetails(){
$this->global['pageTitle'] = 'Delete Factory Machine Master Detail ';
$id = $this->request->getGet('id');
$data['is_active']=0;
$updated = $this->factoryMachineMaster_model->update($id,$data);
if ($updated) {
// Set flashdata for success message
return redirect()->to('/readFactoryMachineMasterDetails')->with('success', 'Machine details deleted successfully');
} else {
// Set flashdata for error message
return redirect()->back()->with('error', 'Failed to delete machine details');
}
}
}