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'] = 'Edit Factory Machine Master Detail '; $data=[ 'machine_name'=> $this->request->getPost('machineName'), 'machine_type'=> $this->request->getPost('machineType'), 'energy_type' => $this->request->getPost('energyType'), ]; $inserted = $this->factoryMachineMaster_model->insert($data); if ($inserted) { // Set flashdata for success message return redirect()->to('/readFactoryMachineMasterDetails')->with('success', 'Machine details created successfully'); } else { // Set flashdata for error message return redirect()->back()->with('error', 'Failed to create machine details'); } } public function loadView_createFactoryMachineMasterDetail(){ $this->global['pageTitle'] = 'Create Factory Machine Master Detail '; $data['masterData']=''; return $this->loadViews("factoryMachineMasterDetailsForm", $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(); return $this->loadViews("factoryMachineMasterDetailsForm", $this->global, $data, NULL); } public function readFactoryMachineMasterDetails(){ $isActiveFilter = 1 ; // default showing active data $showArchive = 0 ; // if ($this->request->getMethod() === 'POST') { $showArchive = $this->request->getPost('showArchive'); //reversing condition that when user wants deleted data to be shown then we are making active filter 0 if($showArchive){ $isActiveFilter = 0; } } $data['showArchive'] = $showArchive; $this->global['pageTitle'] = 'Factory Machine Master Details'; $data['masterData'] = $this->factoryMachineMaster_model ->where('is_active',$isActiveFilter) ->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'); } } public function reActivateFactoryMachineMasterDetails(){ $this->global['pageTitle'] = 'Re Activate Factory Machine Master Details'; $id = $this->request->getGet('id'); $data['is_active']=1; $updated = $this->factoryMachineMaster_model->update($id,$data); if ($updated) { // Set flashdata for success message return redirect()->to('/readFactoryMachineMasterDetails')->with('success', 'Re Activated Factory Machine Master Details'); } else { // Set flashdata for error message return redirect()->back()->with('error', 'Failed to Re Activate machine details'); } } public function checkMachineName(){ $data = $this->request->getPost(); $machineId = $data['machineId']; $machineName = str_replace(" ","", $data['machineName']); $result = $this->factoryMachineMaster_model->checkMachineName($machineId , $machineName); return $this->response->setJSON($result); } }