rawmaterialdetails_model = new Rawmaterialdetails_model(); $this->materialCategories_model = new MaterialCategoriesModel(); $this->session = session(); helper('form'); //$this->load->library('form_validation'); // $this->load->library('pagination'); // $this->load->library('Excel'); $this->isLoggedIn(); } /** * This function used to load the first screen of the user */ public function index() { $this->global['pageTitle'] = 'RawMaterialDetails'; $this->loadViews("rawmaterialListing", $this->global, NULL, NULL); } /** * This function is used to load the RawMaterialDetails list */ function rawmaterialListing() { $this->rawmaterialdetails_model = new rawmaterialdetails_model();; $data['userRecords'] = $this->rawmaterialdetails_model->rawmaterialListing(); $this->global['pageTitle'] = 'RawMaterial Listing'; $this->loadViews("rawmaterialListing", $this->global, $data, NULL); } private function get_current_date_time() { $datetime = new DateTime(); return $datetime->format('Y-m-d H:i:s'); } function deleteMaterial(){ $materialId = $this->request->getPost('id'); $updatedDate = $this->get_current_date_time(); $session = \Config\Services::session(); $userId = $session->get('userId'); $info=array('IsActive' => 0 , "UpdatedBy"=>$userId , "UpdatedDate" => $updatedDate ) ; $updated=$this->rawmaterialdetails_model->deleteMaterial($materialId,$info); if($updated){ echo"Deleted Material successfully..!!"; }else{ echo"Deleting Material unsuccessfull ..!!"; } } function reActivateMaterial(){ $materialId = $this->request->getPost('id'); $updatedDate = $this->get_current_date_time(); $session = \Config\Services::session(); $userId = $session->get('userId'); $info=array('IsActive' => 1 , "UpdatedBy"=>$userId , "UpdatedDate" => $updatedDate ) ; $updated=$this->rawmaterialdetails_model->reActivateMaterial($materialId,$info); if($updated){ echo"Re-Activated Material successfully..!!"; }else{ echo"Re-Activated Material unsuccessfull..!!"; } } function shortagematerialListing() { $this->rawmaterialdetails_model = new rawmaterialdetails_model();; $data['Records'] = $this->rawmaterialdetails_model->reOrderListing(); $this->global['pageTitle'] = 'ReOrderLevel Listing'; $this->loadViews("shortagematerialListing", $this->global, $data, NULL); } /** * This function is used to load the add new cost */ function addRawMaterial() { $this->rawmaterialdetails_model = new rawmaterialdetails_model();; $data['material'] = $this->rawmaterialdetails_model->getmaterialType(); $data['materialcategory'] = $this->rawmaterialdetails_model->getmaterialCategory(); $data['materialCategoryList']= $this->materialCategories_model->where('is_active',1)->findAll(); $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'] = '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->validator->setMessage('MaterialType_validate', 'Please Select Material Type.'); echo ""; 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->validator->setMessage('UOM_validate', 'Please Select UOM.'); echo ""; return false; } else // user picked something { return true; } } /* Validation for Material Category Dropdown */ function materialcategory_validate($selectValue) { if ($selectValue == '0') { // $this->validator->setMessage('materialcategory_validate', 'Please Select Material Category.'); echo ""; return false; } else { return true; } } function addNewRawMaterial() { //echo "HI";die(); $TempArr = []; $MaterialName = $this->request->getPost('MaterialName'); $MaterialType = $this->request->getPost('MaterialType'); $UOM = $this->request->getPost('UOM'); $MaterialCategory = $this->request->getPost('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->request->getPost('remarks'); $HSN = $this->request->getPost('HSNcode'); $CreatedBy = $this->session->get('userId'); $stock = $this->request->getPost('openstock'); $reorder = $this->request->getPost('reorder'); $stockdate = $this->request->getPost('Date'); $currentstock = ''; $today_dt = get_current_date(); if (empty($stockdate)) { // $stockdate = NULL; $stockdate = get_current_date(); $currentstock = $stock; } else { $stockdate = format_date($stockdate,0,"Y-m-d"); $todaydateyear = format_date($today_dt,0,"Y"); $openstockdateyear = format_date($stockdate,0,"Y"); $parts = explode('-', $stockdate); $openstockdatemonth = $parts[1]; $openstockdatedate = $parts[2]; if ($openstockdateyear == $todaydateyear) { if ($openstockdatemonth <= 03) { $currentstock = 0; } else { $currentstock = $stock; } } else if ($openstockdateyear < $todaydateyear) { //$total= $y; $currentstock = 0; } else if ($openstockdateyear > $todaydateyear) { $currentstock = $stock; } } $HSNcode = ($HSN == '') ? null : $HSN; $RawMaterial = array('MaterialName' => $MaterialName, 'MaterialType' => $MaterialType, 'UOM' => $UOM, 'Category' => $MaterialCategory, 'CreatedBy' => $CreatedBy, 'Remarks' => $Remarks, 'HSNCODE' => $HSNcode, 'stock' => $stock, 'stockdate' => $stockdate, 'reorder' => $reorder, 'Current_stock' => $currentstock); //print_r($RawMaterial);die(); $result = $this->rawmaterialdetails_model->addNewRawMaterial($RawMaterial); if ($result > 0) { $this->session->setFlashdata('success', 'RawMaterial Created successfully!'); } else { $this->session->setFlashdata('error', 'RawMaterial Not Created!'); } return redirect()->route('rawmaterialListing'); } function viewRawmaterial($RID = '') { $MaterialType = ''; $UOM = ''; $MaterialCategory = ''; if ($RID == '') { $RawMaterialID = $_GET['RID']; $MaterialType = $_GET['MType']; $UOM = $_GET['UOM']; $currentdate = $_GET['date1']; } else { $RawMaterialID = $RID; } $data['materialDetails'] = $this->rawmaterialdetails_model->getMaterialDetails($RawMaterialID); $data['material'] = $this->rawmaterialdetails_model->getmaterialType(); $data['currentstock'] = $this->rawmaterialdetails_model->getMaterialstock($RawMaterialID, $currentdate); $data['materialType'] = $this->rawmaterialdetails_model->getmaterialType($MaterialType); $data['materialCategory'] = $this->rawmaterialdetails_model->getmaterialCategory($MaterialCategory); $data['materialCategoryList']= $this->materialCategories_model->where('is_active',1)->findAll(); $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(); $data['avg_price'] = $this->rawmaterialdetails_model->getMaterialAvg($RawMaterialID); //print_r($data['avg_price']);die(); $this->global['pageTitle'] = 'Edit Material Master'; $this->loadViews("editRawmaterial", $this->global, $data, NULL); } /** * This function is used to edit the user information */ function editRawmaterial() { $RawmaterialID = $this->request->getPost('MaterialCode'); $MaterialCode = $this->request->getPost('MaterialCode'); $MaterialName = $this->request->getPost('MaterialName'); $MaterialType = $this->request->getPost('MaterialType'); $MaterialCategory = $this->request->getPost('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->request->getPost('UOM'); $Remarks = $this->request->getPost('remarks'); $HSN = $this->request->getPost('HSNcode'); $UpdatedBy = $this->session->get('userId'); $stock = $this->request->getPost('openstock'); $reorder = $this->request->getPost('reorder'); $stockdate = $this->request->getPost('Date'); $stockdate = (empty($stockdate)) ? NULL : format_date($stockdate,0,"Y-m-d"); $chked = $this->request->getPost('isactive'); $IsActive = ($chked != '') ? '1' : '0'; $HSNcode = ($HSN == '') ? null : $HSN; $RawMaterial = array(); $RawMaterial = array('MaterialName' => $MaterialName, 'MaterialType' => $MaterialType, 'UpdatedBy' => $UpdatedBy, 'UOM' => $UOM, 'IsActive' => $IsActive, 'Category' => $MaterialCategory, 'Remarks' => $Remarks, 'HSNCODE' => $HSNcode, 'stock' => $stock, 'stockdate' => $stockdate, 'reorder' => $reorder); //,'RMCode'=>$rmcode); $result = $this->rawmaterialdetails_model->editRawmaterial($RawMaterial, $MaterialCode); if ($result == true) { $this->session->setFlashdata('success', 'RawMaterial Updated successfully!'); } else { echo ""; $this->session->setFlashdata('error', 'RawMaterial Record Not updated!'); } return redirect()->route('rawmaterialListing'); } function addMaterialCategories(){ $data['category_name']=$this->request->getpost('category_name'); $existingCategory = $this->materialCategories_model ->where('category_name', $data['category_name']) ->first(); if ($existingCategory) { // Data already exists, handle this case (e.g., return an error or ignore the insert) return $this->response->setJSON([ 'status' => '409', 'message' => 'Category Already Exists..!!', ]); } $insertResult=$this->materialCategories_model->insert($data); if ($insertResult) { // Send a success response as JSON return $this->response->setJSON([ 'status' => '201', 'message' => 'Category added successfully', ]); } else { // Send an error response as JSON return $this->response->setJSON([ 'status' => '400', 'message' => 'Failed to add category', ]); } } function autocomplete() { $mc = $this->request->getGet('query'); //echo $mc;die; $query = $this->rawmaterialdetails_model->checkMaterialCategory($mc); echo json_encode($query); // foreach($query->result() as $row): // echo "