load->model('rawmaterialdetails_model'); $this->load->library('pagination'); $this->load->library('form_validation'); $this->load->library('Excel'); $this->isLoggedIn(); } /** * This function used to load the first screen of the user */ public function index() { $this->global['pageTitle'] = 'Siddharth : RawMaterialDetails'; $this->loadViews("rawmaterialListing", $this->global, NULL , NULL); } /** * This function is used to load the RawMaterialDetails list */ function rawmaterialListing() { $this->load->model('rawmaterialdetails_model'); $data['userRecords'] = $this->rawmaterialdetails_model->rawmaterialListing(); $this->global['pageTitle'] = 'Siddharth : RawMaterial Listing'; $this->loadViews("rawmaterialListing", $this->global, $data, NULL); } /** * This function is used to load the add new cost */ function addRawMaterial() { $this->load->model('rawmaterialdetails_model'); $data['material'] = $this->rawmaterialdetails_model->getmaterialType(); $data['materialcategory'] = $this->rawmaterialdetails_model->getmaterialCategory(); $data['UOM'] = $this->rawmaterialdetails_model->getUOM(); $data['assetcode'] = $this->rawmaterialdetails_model->getAssetcode(); $data['costcentercode'] =$this->rawmaterialdetails_model->getcostcentercode(); $data['cfUOM'] = $this->rawmaterialdetails_model->getConversionfactorUOM(); $this->global['pageTitle'] = 'siddharth : AddNew RawMaterial'; $this->loadViews("addRawMaterial", $this->global, $data, NULL); } /* 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; } } /* Validation for Material Category Dropdown */ function materialcategory_validate($selectValue) { if($selectValue == '0') { $this->form_validation->set_message('materialcategory_validate', 'Please Select Material Category.'); return false; } else { return true; } } function addNewRawMaterial() { //echo "HI";die(); $TempArr = []; $this->form_validation->set_rules('MaterialName','Material Name','trim|required|'); $this->form_validation->set_rules('MaterialType','MaterialType','trim|callback_MaterialType_validate'); $this->form_validation->set_rules('MaterialCategory','MaterialCategory','trim|callback_materialcategory_validate'); $this->form_validation->set_rules('UOM','UOM','trim|callback_UOM_validate'); if($this->form_validation->run() == FALSE) { $this->addRawMaterial(); } else { $MaterialName = $this->input->post('MaterialName'); $MaterialType = $this->input->post('MaterialType'); $UOM = $this->input->post('UOM'); $MaterialCategory = $this->input->post('MatCate'); $materialcategoryarray = $this->rawmaterialdetails_model->getmaterialCategory(); foreach($materialcategoryarray as $mc){ $TempArr[] = $mc->ConfigValue; } //print_r($TempArr); if (in_array($MaterialCategory, $TempArr)) { //echo "Match found"; } else { //echo "Match not found"; $configcode = 'C023'; $config = array('Config_ID'=>$configcode,'ConfigValue'=>$MaterialCategory); $query= $this->rawmaterialdetails_model->insertvalueintoconfig($config); } $Remarks = $this->input->post('remarks'); $asset = $this->input->post('Assetcode'); $costcentercode = $this->input->post('Costcenter'); $ConversionFactor = $this->input->post('conversionfactor'); $cfuom = $this->input->post('conversionfactorUOM'); $HSN = $this->input->post('HSNcode'); $CreatedBy = $this->session->userdata('userId'); $stock = $this->input->post('openstock'); $reorder = $this->input->post('reorder'); $stockdate = $this->input->post('Date'); if (empty($stockdate)) { $stockdate = NULL; } else { $stockdate = strtotime( $stockdate); $stockdate = date("Y-m-d ", $stockdate); } $chked = $this->input->post('isactive'); if($asset == '0') { $AssetCode = null; } else { $AssetCode = $asset; } if($costcentercode == '0') { $CostCenterCode = null; } else { $CostCenterCode = $costcentercode; } if($cfuom == '0') { $ConversionFactorUOM = null; } else { $ConversionFactorUOM = $cfuom; } if($HSN == '') { $HSNcode = null; } else { $HSNcode = $HSN; } if( $chked != '') { $IsActive = '1'; } else { $IsActive = '0'; } $RawMaterial = array('MaterialName'=>$MaterialName, 'MaterialType'=>$MaterialType, 'UOM'=>$UOM,'Category'=>$MaterialCategory, 'CreatedBy'=>$CreatedBy,'IsActive' => $IsActive,'assetcode'=>$AssetCode,'CostCenterCode'=>$CostCenterCode,'ConversionFactorUnit'=>$ConversionFactor,'ConversionFactorUOM'=>$ConversionFactorUOM,'Remarks'=>$Remarks,'HSNCODE'=>$HSNcode ,'stock'=>$stock,'stockdate'=>$stockdate,'reorder'=>$reorder); //print_r($RawMaterial);die(); $result = $this->rawmaterialdetails_model->addNewRawMaterial($RawMaterial); if($result > 0) { echo "";redirect('rawmaterialListing','refresh'); } else { echo ""; redirect('rawmaterialListing','refresh'); } } } function viewRawmaterial($RID= '') { $MaterialType = ''; $UOM = ''; $MaterialCategory = ''; 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['materialCategory'] = $this->rawmaterialdetails_model->getmaterialCategory($MaterialCategory); $data['UOMList'] = $this->rawmaterialdetails_model->getUOM($UOM); $data['costcentercode'] =$this->rawmaterialdetails_model->getCostCenterCode(); $data['cfUOM'] = $this->rawmaterialdetails_model->getConversionfactorUOM(); $data['assetcode'] = $this->rawmaterialdetails_model->getAssetcode(); $this->global['pageTitle'] = 'Siddharth : Edit Material Master'; $this->loadViews("editOldRawmaterial", $this->global,$data, NULL); } /** * This function is used to edit the user information */ function editRawmaterial() { // if($this->isAdmin() == TRUE) // { // $this->loadThis(); // } // else // { $RawmaterialID = $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'); if($this->form_validation->run() == FALSE) { $this->viewRawmaterial($RawmaterialID); } else { $MaterialCode = $this->input->post('MaterialCode'); $MaterialName = $this->input->post('MaterialName'); $MaterialType = $this->input->post('MaterialType'); $MaterialCategory =$this->input->post('MaterialCategory'); $materialcategoryarray = $this->rawmaterialdetails_model->getmaterialCategory(); foreach($materialcategoryarray as $mc){ $TempArr[] = $mc->ConfigValue; } //print_r($TempArr); if (in_array($MaterialCategory, $TempArr)) { //echo "Match found"; } else { //echo "Match not found"; $configcode = 'C023'; $config = array('Config_ID'=>$configcode,'ConfigValue'=>$MaterialCategory); $query= $this->rawmaterialdetails_model->insertvalueintoconfig($config); } $UOM = $this->input->post('UOM'); $rmcode = $this->input->post('RMcode'); $Remarks = $this->input->post('remarks'); $asset = $this->input->post('Assetcode'); $costcentercode = $this->input->post('Costcenter'); $ConversionFactor = $this->input->post('conversionfactor'); $cfuom = $this->input->post('conversionfactorUOM'); $HSN = $this->input->post('HSNcode'); $UpdatedBy = $this->session->userdata ('userId'); $stock = $this->input->post('openstock'); $reorder = $this->input->post('reorder'); $stockdate = $this->input->post('Date'); if (empty($stockdate)) { $stockdate = NULL; } else { $stockdate = strtotime( $stockdate); $stockdate = date("Y-m-d ", $stockdate); } $chked = $this->input->post('isactive'); if($asset == '0') { $AssetCode = null; } else { $AssetCode = $asset; } if($costcentercode == '0') { $CostCenterCode = null; } else { $CostCenterCode = $costcentercode; } if($cfuom == '0') { $ConversionFactorUOM = null; } else { $ConversionFactorUOM = $cfuom; } if($HSN == '') { $HSNcode = null; } else { $HSNcode = $HSN; } if( $chked != '') { $IsActive = '1'; } else { $IsActive = '0'; } $RawMaterial = array(); $RawMaterial = array('MaterialName'=>$MaterialName,'MaterialType'=>$MaterialType,'UpdatedBy'=>$UpdatedBy, 'UOM'=>$UOM,'IsActive' => $IsActive,'Category'=>$MaterialCategory,'ConversionFactorUnit'=>$ConversionFactor,'ConversionFactorUOM'=>$ConversionFactorUOM,'Remarks'=>$Remarks,'assetcode'=>$AssetCode,'CostCenterCode'=>$CostCenterCode,'HSNCODE'=>$HSNcode,'stock'=>$stock,'stockdate'=>$stockdate,'reorder'=>$reorder);//,'RMCode'=>$rmcode); $result = $this->rawmaterialdetails_model->editRawmaterial($RawMaterial, $MaterialCode); if($result == true) { echo ""; redirect('rawmaterialListing','refresh'); } else { echo "";redirect('rawmaterialListing','refresh'); } } //} } function autocomplete() { $this->load->model('model','rawmaterialdetails_model'); $mc = $this->input->get('query'); //echo $mc;die; $query= $this->rawmaterialdetails_model->checkMaterialCategory($mc); echo json_encode($query); // foreach($query->result() as $row): // echo "