requistion_model = new Requistion_model(); $this->costcenter_model = new Costcenter_model(); $this->purchaseorder_model = new Purchaseorder_model(); $this->session = session(); helper('form'); //$this->load->library('form_validation'); $this->isLoggedIn(); } /** * This function used to load the first screen of the Requistion */ function requisitionlisting() { $this->global['pageTitle'] = 'Requisition Listing'; $userID = $this->session->get('userId'); // $data['ReqList'] = $this->requistion_model->getRequistListUserID($userID); $data['Status'] = $this->requistion_model->CheckDraftStatus($userID); $data['TotNoOfLine'] = $this->requistion_model->getRequistionList($userID); $this->loadViews("requisitionlisting", $this->global, $data, NULL); } /** * This function used to load the first screen of the requisition Form */ function requisition() { $this->global['pageTitle'] = 'Raise Requisition'; $data['RequestType'] = $this->requistion_model->getConfigValue('C020'); $data['EmpList'] = $this->requistion_model->getAllEmployees(); $data['ServiceOption'] = $this->requistion_model->getConfigValue('C022'); $userID = $this->session->get('userId'); $data['Emp'] = $this->requistion_model->getEmpIdByUserID($userID); $data['CostCenter'] = $this->requistion_model->getCostCenterUserID($userID); $data['RequestBy'] = $this->requistion_model->getRequestBy(); $this->loadViews("requisitionform", $this->global, $data, null); } /** * This function used to load the first screen of the Requistion List Approval Screen */ function requisitionlistApproval() { $this->global['pageTitle'] = 'Requisition Approval'; $data['Status'] = $this->requistion_model->getStatus(); $userID = $this->session->get('userId'); $data['AppList'] = $this->requistion_model->getApproverRequistList($userID); $this->loadViews("requisitionlistapproval", $this->global, $data, NULL); } /** * This function used to load the Edit Requistion Form */ function EditRequisitionForm() { $this->global['pageTitle'] = 'Edit Requisition'; $ReqNo = $_GET['ReqNo']; $ReqType = $_GET['ReqType']; $userID = $this->session->get('userId'); $data['ReqDetails'] = $this->requistion_model->getRequistDetails($ReqNo, 'Yes'); //print_r($data['ReqDetails']); $POType = $this->purchaseorder_model->GetPOType($ReqNo); $ReqPOType = ''; if (count($POType) > 0) { for ($i = 0; $i < count($POType); $i++) { if ($POType[$i]['POType'] == $ReqType) { $ReqPOType = ''; break; } else { $ReqPOType = $POType[$i]['POType']; } } } //print_r($POType); // echo 'ReqType'.$ReqPOType; $data['ReqPOType'] = $ReqPOType == '' ? $ReqType : $ReqPOType; $data['LineItem'] = $this->requistion_model->getEditRequistItemList($ReqNo); // print_r($data['LineItem']);die; $data['description'] = ''; foreach ($data['LineItem'] as $line) { $description = isset($line->MaterialDescription) ? $line->MaterialDescription : null; //echo $description; } $data['CostCenter'] = $this->requistion_model->getCostCenterUserID($userID); $data['MaterialCode'] = $this->requistion_model->EditMaterialCode($ReqNo, $ReqType); $data['ServiceOption'] = $this->requistion_model->getConfigValue('C022'); $this->loadViews("editrequisitionform", $this->global, $data, NULL); } /** * This function used to load the Delete the Requistion Items */ function DeleteRequistionForm() { $ReqList = $this->request->getPost('id'); $ReqNo = ''; $MaterialCode = ''; if (count($ReqList) > 0) { $ReqNo = $ReqList[0]; $MaterialCode = $ReqList[1]; } $this->requistion_model->DeleteRequistionLineItem($ReqNo, $MaterialCode); return $this->response->setJSON("Successfully Deleted the Line item" . $ReqNo); } /** * This function used to load the Delete the Requistion Items */ function DeleteReqNo() { $ReqNo = $this->request->getPost('id'); $updateddt = get_current_date_time(); $Request = array('Status' => REQ_DELETED, 'updatedOn' => $updateddt); $this->requistion_model->UpdateRequistion($Request, $ReqNo); return $this->response->setJSON(['message' => "Successfully Deleted the " . $ReqNo]); } function SearchRequistList() { $userID = $this->session->get('userId'); $ReqValue = $this->request->getPost('SearchDate'); $Dt = (is_string($ReqValue)) ? explode("-", $ReqValue) : []; $FromDate = ''; $ToDate = ''; $Status = ''; if (count($Dt) > 1) { $FDate = $Dt[0] . "-" . $Dt[1] . "-" . $Dt[2]; $TDate = $Dt[3] . "-" . $Dt[4] . "-" . $Dt[5]; $FromDate = get_date_time_format($FDate); $ToDate = get_date_time_format($TDate); } $St = $this->request->getPost('RequisitionStatus'); if ($St == "-1") { $Status = ''; } else { $Status = $St; } $data['AppList'] = $this->requistion_model->getApproverRequistList($userID, $Status, $FromDate, $ToDate); $this->global['pageTitle'] = 'Requisition Approval'; $data['Status'] = $this->requistion_model->getStatus(); $this->loadViews("requisitionlistapproval", $this->global, $data, NULL); } /** * This function used to load the Employee details based on the EmpID selection */ function GetSelectedEmpDetails() { $ReqType = $_GET['ReqType']; $EmpID = $this->request->getPost('id'); $empDetails = $this->requistion_model->GetEmployeeDetails($EmpID); $DeptCode = $empDetails[0]['DEPCode']; $CostList = $this->requistion_model->GetCostCenterByDept($DeptCode); $HTML = ""; $BudAmount = ""; if (count($CostList) > 0) { for ($j = 0; $j < count($CostList); $j++) { $Code = $CostList[$j]['CostCenterCode']; $Name = $CostList[$j]['CostCenterName']; $HTML .= ""; } } if (count($CostList) == 1) { $FYStart = ''; $FYEnd = ''; $FiscalYear = $this->costcenter_model->getFiscalYear(); if (!empty($FiscalYear)) { foreach ($FiscalYear as $Fy) { $FYStart = $Fy->StartYear; $FYEnd = $Fy->EndYear; } } $FYdt = $FYStart . " - " . $FYEnd; $result = $this->purchaseorder_model->GetAvailableBudgetAmount($CostCode, $FYdt, $ReqType); //print_r($result); $AvilBudAmt = '0'; if (count($result) > 0) { $BudAmount = $result[0]['BudgetAmount'] - $result[0]['Totalvalue']; } } die(json_encode(array('emp' => $empDetails, 'Cost' => $HTML, 'AvlAmount' => $BudAmount))); } function getAvailableBudAmount() { $ReqType = $_GET['ReqType']; $CostCode = $this->request->getPost('id'); $FYStart = ''; $FYEnd = ''; $FiscalYear = $this->costcenter_model->getFiscalYear(); if (!empty($FiscalYear)) { foreach ($FiscalYear as $Fy) { $FYStart = $Fy->StartYear; $FYEnd = $Fy->EndYear; } } $FYdt = $FYStart . " - " . $FYEnd; $this->purchaseorder_model = new purchaseorder_model(); $Cost = $this->purchaseorder_model->GetAvailableBudgetAmount($CostCode, $FYdt, $ReqType); //$Cost = $this->requistion_model->GetAvailableBudgetAmount( $CostCode,$Year,$ReqType); die(json_encode(array('Cost' => $Cost))); } // To get the Material code based on the Request type function getMaterialCode() { $ReqType = $this->request->getPost('id'); $MaterialCode = $this->requistion_model->GetMaterialCode($ReqType); $MaterialName = ""; $UOM = ""; $HTML = ""; if (count($MaterialCode) > 0) { for ($j = 0; $j < count($MaterialCode); $j++) { $Code = $MaterialCode[$j]['MaterialCode']; $Name = $MaterialCode[$j]['MaterialName']; $HTML .= ""; } $MaterialName = $MaterialCode[0]['MaterialName']; $UOM = $MaterialCode[0]['UOM']; } $response = ['Material' => $HTML, 'MaterialName' => $MaterialName, 'UOM' => $UOM]; return $this->response->setJSON($response); } // To get the Material value based on the MaterialCode function getMaterialDetails() { $Material = $this->request->getPost('id'); $MaterialDetails = $this->requistion_model->getRawMaterialList($Material); return $this->response->setJSON(['MatDetail' => $MaterialDetails]); } /** * To Insert the Requistion Details to Database */ function addNewRequisition() { // print_r($this->request->getPost());die(); log_message('error', " add new Requisition Fns Called"); // $this->validator->setRules(['RequestType'=> 'trim|required', // 'EmpID'=> 'trim|required']); // if ($this->validator->run() == FALSE) { // $this->requisition(); // } else {} $Status = $this->request->getPost('ID'); $RequestType = $this->request->getPost('RequestType'); $RequestType = (is_string($RequestType)) ? strtoupper(trim($RequestType)) : null; $Requestedby = $this->request->getPost('EmpID'); $Requestedby = (is_string($Requestedby)) ? strtoupper(trim($Requestedby)) : null; log_message('error', " add new Requisition empid " . $Requestedby); $RequestedbyDept = $this->session->get('DEPCode'); $CostCenter = $this->request->getPost('CostCenter'); $CreateBy = $this->session->get('userId'); $UpdatedBy = $this->session->get('userId'); $createddt = get_current_date_time(); $RowCount = $this->request->getPost('txtRowCount'); $DeletedRow = $this->request->getPost('txtDeletedRow'); $comma_separated = ($DeletedRow !== null && is_string($DeletedRow)) ? explode(':', $DeletedRow) : []; $serviceSchedule = $this->request->getPost('serviceSchedule'); $servicePeriod = $this->request->getPost('serviceSchedule'); // $noOfService = $this->request->getPost('noOfService'); $noOfService = 1; $IsExists = $this->requistion_model->RequistionIsExists($Requestedby); $Request = array('ReqType' => $RequestType, 'Requestedby' => $Requestedby, 'ReqDate' => $createddt, 'CostCenterCode' => $CostCenter, 'Status' => $Status, 'CreatedDate' => $createddt, 'CreatedBy' => $CreateBy, 'Schedule_Type' => $serviceSchedule, 'NumberOfService' => $noOfService, 'Service_Period' => $servicePeriod, 'RequestedDept' => $RequestedbyDept); if ($Status == REQ_APPROVED) { $Request['Comments'] = "Default Approved"; $Request['Approvedby'] = $this->session->get('userId'); $Request['ApprovedOn'] = get_current_date_time(); } if (count($IsExists) == 0) { $Req = $this->requistion_model->addRequisition($Request); } else { $UpdateReq = $this->requistion_model->UpdateRequistion($Request, $IsExists[0]['ReqNo']); } $ReqNumber = (count($Req) > 0) ? $Req[0]['ReqNo'] : $IsExists[0]['ReqNo']; $SkipInsert = "false"; for ($i = 1; $i <= $RowCount; $i++) { $SkipInsert = "false"; if (count($comma_separated) > 0) { for ($j = 1; $j < count($comma_separated); $j++) { $deletedRow = $comma_separated[$j]; if ($deletedRow == $i) { $SkipInsert = "true"; break; } } } if ($SkipInsert == "false") { $MaterialCode = $this->request->getPost('MaterialCode' . $i); $Quantity = $this->request->getPost('Quantity' . $i); $OtherD = $this->request->getPost('otherD' . $i); $ReqDetails = array('ReqNo' => $ReqNumber, 'MaterialCode' => $MaterialCode, 'Quantity' => $Quantity, 'MaterialDescription' => $OtherD, 'UpdatedBy' => $UpdatedBy); $this->requistion_model->addRequistionDetails($ReqDetails, $ReqNumber); } } if ($Status == REQ_DRAFT) { $display_message = 'Successfully Saved the Requistion details.Requistion No is ' . $ReqNumber; } else { $display_message = 'Successfully Created the Requistion details.Requistion No is ' . $ReqNumber; } return $this->response->setJSON([$display_message]); // return redirect()->route('supplierlisting')->with('success', $display_message); } function EditRequisition() { $Status = $this->request->getPost('txtStatus'); $ReqNumber = $this->request->getPost('txtReqNo'); $CostCenter = $this->request->getPost('CostCenter'); $UpdatedBy = $this->session->get('userId'); $updatedDate = get_current_date_time(); $DeletedRow = $this->request->getPost('txtDeletedRow'); $RowCount = $this->request->getPost('txtRowCount'); $serviceSchedule = $this->request->getPost('serviceSchedule'); $servicePeriod = $this->request->getPost('serviceSchedule'); // $noOfService = $this->request->getPost('noOfService'); $noOfService = 1; if (is_string($Status) && strlen($Status) > 1) { $Request = array('Status' => $Status, 'CreatedDate' => $updatedDate, 'CreatedBy' => $UpdatedBy, 'CostCenterCode' => $CostCenter, 'Schedule_Type' => $serviceSchedule, 'NumberOfService' => $noOfService, 'Service_Period' => $servicePeriod); $UpdateReq = $this->requistion_model->UpdateRequistion($Request, $ReqNumber); } else { $Request = array('Status' => REQ_PENDING_APPROVAL, 'updatedOn' => $updatedDate, 'CostCenterCode' => $CostCenter, 'Schedule_Type' => $serviceSchedule, 'NumberOfService' => $noOfService, 'Service_Period' => $servicePeriod); $UpdateReq = $this->requistion_model->UpdateRequistion($Request, $ReqNumber); } $comma_separated = ($DeletedRow !== null && is_string($DeletedRow)) ? explode(':', $DeletedRow) : []; /* Table value update and Insert in the table */ //echo "RowCOunt:" .$RowCount; $SkipInsert = "false"; for ($i = 1; $i <= $RowCount; $i++) { $SkipInsert = "false"; if (count($comma_separated) > 0) { for ($j = 1; $j < count($comma_separated); $j++) { $deletedRow = $comma_separated[$j]; if ($deletedRow == $i) { $SkipInsert = "true"; break; } } } if ($SkipInsert == "false") { $MaterialCode = $this->request->getPost('MaterialCode' . $i); $Quantity = $this->request->getPost('Quantity' . $i); $OtherD = $this->request->getPost('otherD' . $i); $IsExists = $this->requistion_model->LineItemIsExists($ReqNumber, $MaterialCode); if ($IsExists === null || count($IsExists) == 0) { $ReqDetails = array('ReqNo' => $ReqNumber, 'MaterialCode' => $MaterialCode, 'Quantity' => $Quantity, 'MaterialDescription' => $OtherD, 'UpdatedBy' => $UpdatedBy); $this->requistion_model->addRequistionDetails($ReqDetails, $ReqNumber); } else { $ReqDetails = array('ReqNo' => $ReqNumber, 'MaterialCode' => $MaterialCode, 'Quantity' => $Quantity, 'UpdatedBy' => $UpdatedBy, 'UpdatedOn' => $updatedDate, 'MaterialDescription' => $OtherD); $this->requistion_model->UpdateRequistionLineItem($ReqDetails, $ReqNumber, $MaterialCode); } } } $display_message = 'Successfully Updated the Requistion details.Requistion No is ' . $ReqNumber; return $this->response->setJSON([$display_message]); } /* To Edit the request*/ function ViewRequest() { $ReqNo = $this->request->getPost('id'); $result = $this->requistion_model->getRequistItemList($ReqNo); $ReqList = $this->requistion_model->getRequistDetails($ReqNo); $DepNo = $ReqList[0]['DEPCode']; //$CostList = $this->requistion_model->GetCostCenterByDept($DepNo); $HTML = ""; for ($i = 0; $i < count($result); $i++) { $SNo = $i + 1; $MaterialCode = $result[$i]['MaterialCode']; $MaterialName = $result[$i]['MaterialName']; $UOM = $result[$i]['UOM']; $Quantity = $result[$i]['Quantity']; $Quantity = $result[$i]['Quantity']; $POQTY = $result[$i]['POQTY']; $StatusName = $result[$i]['StatusName']; $HTML .= " " . $SNo . " " . $MaterialCode . " " . $MaterialName . " " . $UOM . " " . $Quantity . " " . $POQTY . " " . $StatusName . " "; //$index = $index + 1; } $CostCode = ''; $ReqType = ''; $FYStart = ''; $FYEnd = ''; $FiscalYear = $this->costcenter_model->getFiscalYear(); if (!empty($FiscalYear)) { foreach ($FiscalYear as $Fy) { $FYStart = $Fy->StartYear; $FYEnd = $Fy->EndYear; } } $FYdt = $FYStart . " - " . $FYEnd; $this->purchaseorder_model = new purchaseorder_model(); if (count($ReqList) > 0) { $ReqType = $ReqList[0]['ReqType']; $CostCode = $ReqList[0]['CostCenterCode']; } $POType = $this->purchaseorder_model->GetPOType($ReqNo); $ReqPOType = ''; if (count($POType) > 0) { for ($i = 0; $i < count($POType); $i++) { if ($POType[$i]['POType'] == $ReqType) { $ReqPOType = ''; break; } else { $ReqPOType = $POType[$i]['POType']; } } } $RequestType = ''; $RequestType = $ReqPOType == '' ? $ReqType : $ReqPOType; $AvlBudget = array(); // if($ReqType== CAPITAL&&$RequestType!=IMPORT ) // { // $AvlBudget = $this->purchaseorder_model->GetAvailableCapitalBudgetAmount($CostCode,$FYdt,$ReqType); // } if ($ReqType == CAPITAL && $RequestType != IMPORT) { $AvlBudget = $this->purchaseorder_model->GetAvailableCapitalBudgetAmount($CostCode, $FYdt, $RequestType); } // else if($ReqType== CAPITAL&&$RequestType==IMPORT) // { // $AvlBudget = $this->purchaseorder_model->GetAvailableImportBudgetAmount($CostCode,$FYdt,$RequestType); // } // else if($ReqType== IMPORT) // { // $AvlBudget = $this->purchaseorder_model->GetAvailableImportBudgetAmount($CostCode,$FYdt,$RequestType); // } else { $AvlBudget = $this->purchaseorder_model->GetAvailableBudgetAmount($CostCode, $FYdt, $ReqType); } // $AvlBudget = $this->purchaseorder_model->GetAvailableBudgetAmount($CostCode,$FYdt,$ReqType); //print_r($result); $AvilBudAmt = '0'; if (count($AvlBudget) > 0) { $AvilBudAmt = $AvlBudget[0]['BudgetAmount'] - $AvlBudget[0]['Totalvalue']; } //echo $AvilBudAmt; die(json_encode(array('Items' => $HTML, 'Requist' => $ReqList, 'AvilBudAmount' => number_format($AvilBudAmt, 2)))); } /** This function used approve or reject request - Ajax Call*/ function ApproveRequest() { $Status = $this->request->getVar('Status'); $ReqNo = $this->request->getVar('ReqNo'); $Remarks = $this->request->getVar('Remarks'); $ApprovedBy = $this->session->get('userId'); $ApprovedDate = get_current_date_time(); $Request = array('Status' => $Status, 'Comments' => $Remarks, 'ApprovedOn' => $ApprovedDate, 'Approvedby' => $ApprovedBy); $this->requistion_model->UpdateRequistion($Request, $ReqNo); return $this->response->setJSON(['message' => "Successfully Updated the Requisition No: " . $ReqNo]); } }