storerequistion_model = new Storerequistion_model(); $this->session = session(); helper('form'); //$this->load->library('form_validation'); $this->isLoggedIn(); } /** * For Store requisition listing (NOTE : this listing descripted - what are the store requistion) **/ function addstores() { $this->global['pageTitle'] = 'Raise Store Requisition'; $userId = $this->session->get('userId'); $data['DEPCode'] = $this->session->get('DEPCode'); $data['DepName'] = $this->session->get('DepartmentName'); $data['cost'] = $this->storerequistion_model->getCostUser($userId); $data['MaterialList'] = $this->storerequistion_model->getRawMaterialList(); $this->loadViews("addstorerequisitionslip", $this->global, $data, null); } /** * Store requisition listing is under Draft status (this hide the raise StoreRequisition button). **/ function addstore() { $this->global['pageTitle'] = 'Store Requisition Details'; $userId = $this->session->get('userId'); $data['Store'] = $this->storerequistion_model->Storeall($userId); $this->loadViews("storerequisition", $this->global, $data, null); } /** * Its handles Store Requistion Delete Operations ( in Store Requistion listing ) */ function DeleteReqNo() { $StoreReqNo = $this->request->getPost('id'); $updateddt = get_current_date_time(); $Request = array('Status' => REQ_DELETED, 'updatedOn' => $updateddt); $this->storerequistion_model->UpdateRequistion($StoreReqNo, $Request); echo "Successfully Deleted the " . $StoreReqNo; } /** * For editing purpose and it has oldest all store requistion. */ function EditStoreRequistion() { $StoreReqNo = $_GET['StoreReqNo']; $this->global['pageTitle'] = 'Edit StoreRequisition'; $data['cost'] = $this->storerequistion_model->editRequistDetails($StoreReqNo); $data['Status'] = $this->storerequistion_model->getStoreRequistionStatus($StoreReqNo); $data['MaterialList'] = $this->storerequistion_model->getRawMaterialList(); $data['DepName'] = $this->session->get('DepartmentName'); $data['LineItem'] = $this->storerequistion_model->editstorerequistions($StoreReqNo); $this->loadViews("editstorerequisition", $this->global, $data, null); } /** * To convert the dateformat (date with time) and store to DB */ function getDateformat($Val) { $date = new DateTime($Val); $retDate = $date->format('Y-m-d H:i:s'); return $retDate; } /** * For new StoreRequestion values inserted into DB */ function addNewRequistion() { $CostCenter = $this->request->getPost('CostCenter'); $DEPCode = $this->request->getPost('txtDepCode'); $CreateBy = $this->session->get('userId'); $createddt = get_current_date_time(); $DeletedRow = $this->request->getPost('txtDeletedRow'); $RowCount = $this->request->getPost('txtRowCount'); $Status = $this->request->getPost('txtStatus'); $Requestedby = $this->session->get('EmpID'); $comma_separated = explode(':', $DeletedRow); $StoreReqNo = ''; $StoreItemStatus = STORE_OPEN; $Request = array('Requestedby' => $Requestedby, 'DepartmentCode' => $DEPCode, 'ReqDate' => $createddt, 'CostCenterCode' => $CostCenter, 'Status' => $Status, 'CreatedDate' => $createddt, 'CreatedBy' => $CreateBy); $Req = $this->storerequistion_model->addRequistion($Request); if (count($Req) > 0) { $StoreReqNo = $Req[0]['StoreReqNo']; } $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); $QuantityRequired = $this->request->getPost('Quantity' . $i); $Remarks = $this->request->getPost('Remarks' . $i); $Request = array('MaterialCode' => $MaterialCode, 'Status' => $StoreItemStatus, 'QuantityRequired' => $QuantityRequired, 'Remarks' => $Remarks, 'StoreReqNo' => $StoreReqNo); $addReq = $this->storerequistion_model->addstoreRequistion($Request); } } if ($Status == STORE_DRAFT) { echo 'Successfully Saved the Store Requistion details'; } else { echo 'Successfully Created the Store Requistion details'; } } /** * For Store requisition listing (NOTE : this listing descripted - only approved store requistion) */ function addstorerequisitionlist() { $this->global['pageTitle'] = 'Store Requisition Listing'; $data['Status'] = $this->storerequistion_model->getStatus(); $data['TotNoOfLine'] = $this->storerequistion_model->getRequistionList(); $this->loadViews("storerequisitionlisting", $this->global, $data, null); } /** * To issue Store Requistion **/ function issuestorerequisition() { $this->global['pageTitle'] = 'Issue StoreRequisition'; $StoreReqNo = $_GET['ReqNo']; $data['ReqItem'] = $this->storerequistion_model->getRequistItemList($StoreReqNo); $data['ReqListDetails'] = $this->storerequistion_model->getRequistDetails($StoreReqNo); $this->loadViews("issueStoreRequistion", $this->global, $data, null); } /** * To Update with existing one with new one (Issued Requistion) * */ function UpdateIssueRequistion() { $ReqNO = $this->request->getPost('txtReqNo'); $RowCount = $this->request->getPost('txtRowCount'); $createddt = get_current_date_time(); $UPdateby = $this->session->get('userId'); $UPdateon = get_current_date_time(); for ($i = 1; $i <= $RowCount; $i++) { $MaterialCode = $this->request->getPost('MaterialCode' . $i); $IssuedQuantity = $this->request->getPost('txtIssuedQuantity' . $i); $Reqqty = $this->request->getPost('txtqty' . $i); $savedqty = $this->storerequistion_model->getSavedQty($ReqNO, $MaterialCode); $Qtyissued = 0; foreach ($savedqty as $Qty) { $Qtyissued = $Qty->QuantityIssued; } $ActQty = $Qtyissued + $IssuedQuantity; if ($Reqqty > $ActQty) { $ItemStatus = STORE_PARTIALLYISSUSED; } else { $ItemStatus = STORE_ISSUSED; } if (strlen($IssuedQuantity) > 0) { $Remarks = $this->request->getPost('txtRemarks' . $i); $CreatedBy = $this->session->get('userId'); $storerequisition = array('StoreReqNo' => $ReqNO, 'MaterialCode' => $MaterialCode, 'QuantityIssued' => $ActQty, 'Status' => $ItemStatus, 'StoreComments' => $Remarks, 'UpdatedOn' => $createddt, 'UpdatedBy' => $CreatedBy); $this->storerequistion_model->UpdateStoreRequistionItem($storerequisition, $ReqNO, $MaterialCode); $getAvailableqty = $this->storerequistion_model->getItemQuantityFromStock(trim($MaterialCode)); if (count($getAvailableqty) > 0) { $avlQty = $getAvailableqty[0]['Quantity']; } $BalanceQty = $avlQty - $IssuedQuantity; $updatStock = array( 'Quantity' => $BalanceQty, 'Status' => '0', 'Remarks' => 'Stock Deducted For' . $ReqNO, 'UpdatedOn' => $UPdateon, 'UpdatedBy' => $UPdateby ); $this->storerequistion_model->UpdateStock($updatStock, trim($MaterialCode)); $StoreReqNo = $ReqNO; $reqstatus = $this->storerequistion_model->getstatuscount('ST037', $ReqNO); $reqstatuscount = 0; foreach ($reqstatus as $Req) { $reqstatuscount = $Req->SCount; } if ($reqstatuscount == $RowCount) { $reqStatus = STORE_ISSUSED; } else { $reqStatus = STORE_PARTIALLYISSUSED; } $updatestatus = array('Status' => $reqStatus); $this->storerequistion_model->updatestoremaster($updatestatus, $StoreReqNo); } } echo ""; redirect('storerequisitionlisting', 'refresh'); } /** * For Store Requisition listing (Note: this listing descripted - Approve the store requisition ) **/ function SearchRequistLists() { $userID = $this->session->get('userId'); $data['AppList'] = $this->storerequistion_model->getApproverRequistList($userID); $this->global['pageTitle'] = 'Approval Store Requisition Listing'; $data['Status'] = $this->storerequistion_model->getStatus(); $this->loadViews("approvalstorerequisitionslip", $this->global, $data, NULL); } /** * To change the approval storerequisition status ( Approve Completed are not) */ function ApproveRequest() { $Status = Trim($_GET['Status']); $StoreReqNo = trim($this->request->getPost('id')); $Remarks = trim($this->request->getPost('newcomments')); $ApprovedBy = $this->session->get('userId'); $ApprovedDate = get_current_date_time(); $Request = array('Status' => $Status, 'Comments' => $Remarks, 'ApprovedOn' => $ApprovedDate, 'Approvedby' => $ApprovedBy); $this->storerequistion_model->UpdateRequistion($StoreReqNo, $Request); echo "Successfully Updated the Requistion No: " . $StoreReqNo; } /*to load the first screen of the Requistion List Approval Screen*/ function requisitionlistApproval() { $this->global['pageTitle'] = 'Approvalstorerequisitionlist'; $userID = $this->session->get('userId'); $data['AppList'] = $this->storerequistion_model->getApproverRequistList($userID); $this->loadViews("requisitionlistapproval", $this->global, $data, NULL); } /* To Edit the view store request*/ function ViewRequest() { $StoreReqNo = $this->request->getPost('id'); $result = $this->storerequistion_model->getRequistItemListApproval($StoreReqNo); $ReqList = $this->storerequistion_model->getRequistDetails($StoreReqNo); $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]['QuantityRequired']; $IssuedQty = $result[$i]['QuantityIssued']; $Status = $result[$i]['StatusName']; $Remarks = $result[$i]['Remarks']; $HTML .= " " . $SNo . " " . $MaterialCode . " " . $MaterialName . " " . $UOM . " " . $Quantity . " " . $IssuedQty . " " . $Status . " " . $Remarks . " "; } die(json_encode(array('Items' => $HTML, 'Requist' => $ReqList))); } /** * For stored new values after edited StoreRequistion information. */ function UpdateStoreRequistion() { $CostCenter = $this->request->getPost('CostCenter'); $DeletedRow = $this->request->getPost('txtDeletedRow'); $RowCount = $this->request->getPost('txtRowCount'); $Status = $this->request->getPost('txtStatus'); $Requestedby = $this->session->get('EmpID'); $comma_separated = explode(':', $DeletedRow); $StoreReqNo = $this->request->getPost('txtReqNo'); $Requestedby = $this->request->getPost('RequestedBy'); $UpdatedBy = $this->session->get('userId'); $updatedDate = get_current_date_time(); if (strlen($Status) > 1) { $Request = array('CostCenterCode' => $CostCenter, 'Status' => $Status, 'updatedOn' => $updatedDate); $UpdateReq = $this->storerequistion_model->UpdateRequistion($StoreReqNo, $Request); } $SkipInsert = False; $StoreItemStatus = STORE_OPEN; 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); $QuantityRequired = $this->request->getPost('Quantity' . $i); $Remarks = $this->request->getPost('Remarks' . $i); $IsExists = $this->storerequistion_model->LineItemIsExists($StoreReqNo, $MaterialCode); if (count($IsExists) == 0) { $ReqDetails = array('StoreReqNo' => $StoreReqNo, 'MaterialCode' => $MaterialCode, 'QuantityRequired' => $QuantityRequired, 'Remarks' => $Remarks, 'Status' => $StoreItemStatus, 'UpdatedBy' => $UpdatedBy, 'UpdatedOn' => $updatedDate); $this->storerequistion_model->addstoreRequistion($ReqDetails); } else { $ReqDetails = array('QuantityRequired' => $QuantityRequired, 'Remarks' => $Remarks, 'Status' => $StoreItemStatus, 'UpdatedBy' => $UpdatedBy, 'UpdatedOn' => $updatedDate); $this->storerequistion_model->UpdateRequistionLineItem($ReqDetails, $StoreReqNo, $MaterialCode); } } } echo 'Successfully updated the Requistion details'; } /** * Its handles Store Requistion Line item Delete Operations ( add & edit Store Requistion screen) */ function DeleteRequistionForm() { $ReqList = $this->request->getPost('id'); $StoreReqNo = ''; $MaterialCode = ''; if (count($ReqList) > 0) { $StoreReqNo = $ReqList[0]; $MaterialCode = $ReqList[1]; } $this->storerequistion_model->DeleteRequistionLineItem($StoreReqNo, $MaterialCode); echo "Successfully Deleted the Line item" . $StoreReqNo; } }