From 9956d0617b0f7fbad6456b4d941145e28fc0d13e Mon Sep 17 00:00:00 2001 From: gandhimathi Bharathirajan Date: Thu, 13 Apr 2017 00:23:03 +0530 Subject: [PATCH] Material Master --- .../controllers/rawmaterialdetails.php | 236 +++++++++--------- 1 file changed, 117 insertions(+), 119 deletions(-) diff --git a/application/controllers/rawmaterialdetails.php b/application/controllers/rawmaterialdetails.php index 3fe6c9a6..477fab51 100644 --- a/application/controllers/rawmaterialdetails.php +++ b/application/controllers/rawmaterialdetails.php @@ -3,11 +3,11 @@ require APPPATH . '/libraries/BaseController.php'; /** - * Class : purchaseorder (PurchaseorderController) + * Class : RawMaterial (PurchaseorderController) * User Class to control all user related operations. - * @author : VenbaMail Mali + * @author : Gandhimathi * @version : 1.1 - * @since : 15 Feb 2016 + * @since : 12 Apr 2017 */ class rawmaterialdetails extends BaseController { @@ -18,6 +18,8 @@ class rawmaterialdetails extends BaseController { parent::__construct(); $this->load->model('rawmaterialdetails_model'); + $this->load->library('pagination'); + $this->load->library('form_validation'); $this->isLoggedIn(); } /** @@ -40,9 +42,7 @@ class rawmaterialdetails extends BaseController $searchText = $this->input->post('searchText'); $data['searchText'] = $searchText; - - $this->load->library('pagination'); - + $count = $this->rawmaterialdetails_model->rawmaterialListingCount($searchText); $returns = $this->paginationCompress ( "rawmaterialListing/", $count, 5 ); @@ -60,93 +60,119 @@ class rawmaterialdetails extends BaseController { $this->load->model('rawmaterialdetails_model'); - //$data['SupplierName'] = $this->rawmaterialdetails_model->getSupplierName(); - $data['material'] = $this->rawmaterialdetails_model->getmaterial(); - $data['UOM'] = $this->rawmaterialdetails_model->getUOM(); - + $data['material'] = $this->rawmaterialdetails_model->getmaterialType(); + $data['UOM'] = $this->rawmaterialdetails_model->getUOM(); $this->global['pageTitle'] = 'siddharth : AddNew RawMaterial'; $this->loadViews("addRawmaterial", $this->global, $data, NULL); } - - /** - * This function is used to add new Cost to the system + /* + Validation for Material Type Dropdown + */ + function MaterialType_validate($selectValue) +{ + //echo 'select_validate method called'; + // 'none' is the first option and the text says something like "-Choose one-" + if($selectValue == '-1') + { + $this->form_validation->set_message('MaterialType_validate', 'Please Select Material Type.'); + return false; + } + else // user picked something + { + return true; + } +} +/* + Validation for Material Type Dropdown + */ + function UOM_validate($selectValue) +{ + //echo 'select_validate method called'; + // 'none' is the first option and the text says something like "-Choose one-" + if($selectValue == '-1') + { + $this->form_validation->set_message('UOM_validate', 'Please Select UOM.'); + return false; + } + else // user picked something + { + return true; + } +} + /* This function is used to add new Cost to the system */ function addNewRawMaterial() { - $this->load->library('form_validation'); - - //$PO = $this->input->post('costID'); - - //$this->form_validation->set_rules('CostCenterID','cost Name','trim'); $this->form_validation->set_rules('MaterialName','Material Name','trim|required|'); - $this->form_validation->set_rules('MaterialType','MaterialType','trim'); - $this->form_validation->set_rules('UOM','UOM','trim'); - - - + $this->form_validation->set_rules('MaterialType','MaterialType','trim|callback_MaterialType_validate'); + $this->form_validation->set_rules('UOM','UOM','trim|callback_UOM_validate'); + if($this->form_validation->run() == FALSE) { $this->addRawMaterial(); } else { - $MaterialName = ucwords(strtolower($this->input->post('MaterialName'))); + $MaterialName = $this->input->post('MaterialName'); $MaterialType = $this->input->post('MaterialType'); $UOM = $this->input->post('UOM'); - $CreatedBy = $this->input->post('CreatedBy'); + $CreatedBy = $this->session->userdata('userId'); + + $chked = $this->input->post('isactive'); + + if( $chked != '') + { + $IsActive = '1'; + } + else + { + $IsActive = '0'; + } + + $Material = array('MaterialName'=>$MaterialName, 'MaterialType'=>$MaterialType, 'UOM'=>$UOM,'CreatedBy'=>$CreatedBy,'IsActive' => $IsActive); - - - - $RawMaterial = array('MaterialName'=>$MaterialName, 'MaterialType'=>$MaterialType, 'UOM'=>$UOM,'CreatedBy'=>$CreatedBy,'createdDate'=>date('Y-m-d H:i:sa')); - - $this->load->model('rawmaterialdetails_model'); $result = $this->rawmaterialdetails_model->addNewRawMaterial($RawMaterial); if($result > 0) { - $this->session->set_flashdata('success', 'New RawMaterial created successfully'); + //$this->session->set_flashdata('success', 'New RawMaterial created successfully'); + echo ""; + redirect('rawmaterialListing','refresh'); } else { - $this->session->set_flashdata('error', 'RawMaterial Not Create'); - } - - redirect('rawmaterialListing'); - } - + // $this->session->set_flashdata('error', 'RawMaterial Not Create'); + echo ""; + redirect('rawmaterialListing','refresh'); + } + + } } - - - function viewRawmaterial($RawMaterialID = NULL) + function viewRawmaterial($RID= '') { - - $this->load->model('rawmaterialdetails_model'); - $data['userRecords'] = $this->rawmaterialdetails_model->getuserInfo($RawMaterialID); - $data['material'] = $this->rawmaterialdetails_model->getmaterial(); - $this->global['pageTitle'] = 'Siddharth : View MaterialMaster'; - - $this->loadViews("viewrawmaterial", $this->global,$data, NULL); - - } - /** - * This function is used load user edit information - * @param number $userId : Optional : This is user id - */ - function editOldRawmaterial($RawMaterialID = NULL) - { - $data['material'] = $this->rawmaterialdetails_model->getmaterial(); - $data['UOMList'] = $this->rawmaterialdetails_model->getUOM(); - $data['userRecords'] = $this->rawmaterialdetails_model->getUserInfo($RawMaterialID); - - $this->global['pageTitle'] = 'Siddharth : Edit MaterialMaster'; - - $this->loadViews("editOldrawmaterial", $this->global, $data, NULL); - + $MaterialType = ''; + $UOM = ''; + if($RID == '') + { + $RawMaterialID = $_GET['RID']; + $MaterialType = $_GET['MType']; + $UOM = $_GET['UOM']; + } + else + { + $RawMaterialID = $RID; + } + + $data['materialDetails'] = $this->rawmaterialdetails_model->getMaterialDetails($RawMaterialID); + + $data['materialType'] = $this->rawmaterialdetails_model->getmaterialType($MaterialType ); + $data['UOMList'] = $this->rawmaterialdetails_model->getUOM($UOM); + $this->global['pageTitle'] = 'Siddharth : Edit Material Master'; + $this->loadViews("editOldRawmaterial", $this->global,$data, NULL); } @@ -155,23 +181,13 @@ class rawmaterialdetails extends BaseController */ function editRawmaterial() { - - - - - if($this->isAdmin() == TRUE) + if($this->isAdmin() == TRUE) { - echo 'allowed admin'; - $this->loadThis(); - + $this->loadThis(); } else { - //echo 'allowed data'; - $this->load->library('form_validation'); - - $MaterialCode = $this->input->post('MaterialCode'); - + $MaterialCode = $this->input->post('MaterialCode'); $this->form_validation->set_rules('MaterialName','Material Name','trim|required|'); $this->form_validation->set_rules('MaterialType','MaterialType','trim'); $this->form_validation->set_rules('UOM','UOM','trim'); @@ -183,63 +199,45 @@ class rawmaterialdetails extends BaseController } else { - $MaterialCode = $this->input->post('MaterialCode'); - $MaterialName = ucwords(strtolower($this->input->post('MaterialName'))); + $MaterialCode = $this->input->post('MaterialCode'); + $MaterialName = $this->input->post('MaterialName'); $MaterialType = $this->input->post('MaterialType'); $UOM = $this->input->post('UOM'); - $UpdatedBy = $this->input->post('UpdatedBy'); - $CreatedBy = $this->input->post('CreatedBy'); - - //echo $MaterialCode; + $UpdatedBy = $this->session->userdata ('userId'); + $chked = $this->input->post('isactive'); - //echo 'passed model'; - $RawMaterial = array(); - - $RawMaterial = array('MaterialName'=>$MaterialName,'MaterialType'=>$MaterialType,'CreatedBy'=>$CreatedBy,'UpdatedBy'=>$UpdatedBy, 'UOM'=>$UOM, 'MaterialCode'=>$MaterialCode, 'UpdatedDate'=>date('Y-m-d H:i:sa')); - - // echo ' before db Call'; + if( $chked != '') + { + $IsActive = '1'; + } + else + { + $IsActive = '0'; + } + + $RawMaterial = array(); + $RawMaterial = array('MaterialName'=>$MaterialName,'MaterialType'=>$MaterialType,'UpdatedBy'=>$UpdatedBy, 'UOM'=>$UOM,'IsActive' => $IsActive); + $result = $this->rawmaterialdetails_model->editRawmaterial($RawMaterial, $MaterialCode); - // echo ' After db Call'; - + if($result == true) { - $this->session->set_flashdata('success', 'RawMaterial updated successfully'); + redirect('rawmaterialListing','refresh'); + // $this->session->set_flashdata('success', 'RawMaterial updated successfully'); + echo ""; } else { - $this->session->set_flashdata('error', 'RawMaterial updation failed'); + redirect('rawmaterialListing','refresh'); + echo ""; + // $this->session->set_flashdata('error', 'RawMaterial updation failed'); } - redirect('rawmaterialListing'); + } } } - /** - * This function is used to delete the user using userId - * @return boolean $result : TRUE / FALSE - - function deleteUser() - { - if($this->isAdmin() == TRUE) - { - echo(json_encode(array('status'=>'access'))); - } - else - { - $userId = $this->input->post('userId'); - $userInfo = array('isDeleted'=>1,'updatedBy'=>$this->vendorId, 'updatedDtm'=>date('Y-m-d H:i:sa')); - - $result = $this->user_model->deleteUser($userId, $userInfo); - - if ($result > 0) { echo(json_encode(array('status'=>TRUE))); } - else { echo(json_encode(array('status'=>FALSE))); } - } - }*/ - - - - function pageNotFound() { $this->global['pageTitle'] = 'Siddharth : 404 - Page Not Found';