From fbea4b963d2eb9e44af960c5f62da7e799306f38 Mon Sep 17 00:00:00 2001 From: gandhimathi Bharathirajan Date: Fri, 12 May 2017 09:24:44 +0530 Subject: [PATCH] Requistion Code --- application/models/requistion_model.php | 167 ++++++++++++++++++++++-- 1 file changed, 153 insertions(+), 14 deletions(-) diff --git a/application/models/requistion_model.php b/application/models/requistion_model.php index 0fc95257..c082ab5e 100644 --- a/application/models/requistion_model.php +++ b/application/models/requistion_model.php @@ -30,8 +30,25 @@ class requistion_model extends CI_Model return $query->result(); } + /** + * This function is used to get the userId information + * @return array $result : This is result of the query + */ + function getStatus() + { + $this->db->select('StatusCode,StatusName '); + $this->db->from('T_Status'); + $this->db->where('StatusType', REQUISTSTATUS); + $this->db->where('StatusCode !=', REQ_DRAFT); + $query = $this->db->get(); + + return $query->result(); + } - + /** + * This function is used to get Employee details based on Employee ID Selection + * @return array $result : This is result of the query + */ function GetEmployeeDetails($EmpID) { @@ -44,6 +61,10 @@ class requistion_model extends CI_Model return $query->result_array(); } + /** + * This function is used to get the Cost Center details for the Login user department + * @return array $result : This is result of the query + */ function GetCostCenterByDept($DeptId) { @@ -55,7 +76,10 @@ class requistion_model extends CI_Model // print_r( $this->db->last_query()); return $query->result_array(); } - + /** + * This function is used to get the Available BudgetAmount for the Cost center + * @return array $result : This is result of the query + */ function GetAvailableBudgetAmount($CostCode,$Year,$BudgetType) { $this->db->select('BudgetAmount'); @@ -68,16 +92,25 @@ class requistion_model extends CI_Model return $query->result_array(); } - - function GetMaterialCode($ReqType) + /** + * This function is used to get the Material details for the Request type + * @return array $result : This is result of the query + */ + function GetMaterialCode($ReqType,$NotArray='') { $this->db->select('MaterialCode, MaterialName,UOM'); $this->db->from('T_MaterialMaster'); $this->db->where('MaterialType',$ReqType ); $query = $this->db->get(); - + if($NotArray == '') + { return $query->result_array(); + } + else + { + return $query->result(); + } } /** * This function is used to get the Raw Material information @@ -114,7 +147,7 @@ class requistion_model extends CI_Model /** - * This function is used to get the Purchase order Type + * This function is used to get the All employees * @return array $result : This is result of the query */ function getAllEmployees() @@ -164,29 +197,78 @@ class requistion_model extends CI_Model */ function CheckDraftStatus($UserID) { - $Status = 'Draft'; + $subQuery = 'select count(ReqNo) as cnt from T_Requestion_Master where Requestedby= ( select EmpID from tbl_users where userId=?) and status=?'; - $query = $this->db->query($subQuery, array($UserID,$Status)); + $query = $this->db->query($subQuery, array($UserID,REQ_DRAFT)); return $query->result(); + } + /** + * This function is used to get the Requsition List for the login user + * @return array $result : This is result of the query + */ + function getRequistDetails($ReqID,$NoArray='') + { + + $subQuery = 'select distinct ReqNo,ReqType,Requestedby,mast.CreatedDate,emp.FirstName,emp.EmpID,emp.Designation, Dept.DEPCode,Dept.DepartmentName + from T_Requestion_Master mast + join T_Employee_Details emp on mast.Requestedby = emp.EmpID + join T_DepartmentDetails Dept on emp.Departmentcode = Dept.DEPCode + where ReqNo=?'; + + $query = $this->db->query($subQuery, array($ReqID)); + if($NoArray == '') + { + return $query->result_array(); + } + else + { + return $query->result(); + } } /** - * This function is used to get the Purchase order Type + * This function is used to get the Requsition List for the login user * @return array $result : This is result of the query */ function getRequistListUserID($UserID) { - $subQuery = 'select ReqNo, ReqType ,Status,CreatedDate from T_Requestion_Master where - Requestedby= ( select EmpID from tbl_users where userId=?)'; + $subQuery = 'select ReqNo, ReqType ,Status,CreatedDate ,StatusName from T_Requestion_Master mast + join T_Status st on st.StatusCode= mast.Status where + Requestedby = ( select EmpID from tbl_users where userId=?)'; $query = $this->db->query($subQuery, array($UserID)); return $query->result(); } + /** + * This function is used to get the Requsition List for the login user + * @return array $result : This is result of the query + */ + function getRequistItemList($ReqID,$NoArray='') + { + + $subQuery = 'select ReqNo,Mat.MaterialCode,Mat.MaterialName,Mat.UOM,Quantity from + T_Requestion_Details Req join T_MaterialMaster Mat on + Req.MaterialCode = Mat.MaterialCode where ReqNo=?'; + + $query = $this->db->query($subQuery, array($ReqID)); + if($NoArray == '') + { + return $query->result_array(); + } + else + { + return $query->result(); + } + } + /** + * This function is used to add the Requistion into the Database + * @return array $result : This is result of the query + */ function addRequistion($Requistion) { $this->db->trans_start(); @@ -203,12 +285,15 @@ class requistion_model extends CI_Model } } - + /** + * This function is used to check the Request is in Draft status + * @return array $result : This is result of the query + */ function RequistionIsExists($ReqBy) { $this->db->select('ReqNo'); $this->db->from('T_Requestion_Master'); - $this->db->where('Status ','Draft' ); + $this->db->where('Status ',REQ_DRAFT ); $this->db->where('Requestedby ',$ReqBy ); $query = $this->db->get(); @@ -217,6 +302,10 @@ class requistion_model extends CI_Model return $query->result_array(); } } + /** + * This function is used to add the Line item details to the Database + * @return array $result : This is result of the query + */ function addRequistionDetails($Requistion) { $this->db->trans_start(); @@ -227,7 +316,10 @@ class requistion_model extends CI_Model return $insert_id; } - + /** + * This function is used to update the details into Database + * @return array $result : This is result of the query + */ function UpdateRequistion($Requistion, $ReqNo) { $this->db->where('ReqNo', $ReqNo); @@ -236,6 +328,53 @@ class requistion_model extends CI_Model return TRUE; } + /** + * This function is used to get the List of Requist details to the approver + * @return array $result : This is result of the query + */ + function getApproverRequistList($UserID,$Status = '',$FromDate='' ,$ToDate='') + { + // echo 'UserId: '.$UserID . 'From: '.$FromDate .'TO: '. $ToDate. 'Status: '. $Status; + + $subQuery = 'select distinct ReqNo,Status,mast.CreatedDate,Requestedby,mast.Comments,st.StatusName + from T_Requestion_Master mast join T_Employee_Details emp on mast.Requestedby = emp.EmpID + join T_DepartmentDetails Dept on emp.Departmentcode = Dept.HeadDept + join T_Status st on st.StatusCode = mast.Status + where status != ? and emp.Departmentcode = (select HeadDept from T_DepartmentDetails where DEPCode = (select Departmentcode from T_Employee_Details where EmpID=(select EmpID from tbl_users where userId=?)))'; + $subQuery1 = $subQuery; + $query =''; + + if($FromDate != '' && $ToDate != '' && $Status !='' ) + { + + $Where = 'and mast.CreatedDate >= ? and mast.CreatedDate <= ? and Status=?'; + $subQuery1 .= $Where; + $query = $this->db->query($subQuery1, array(REQ_DRAFT,$UserID,$FromDate,$ToDate,$Status)); + } + else if($FromDate != '' && $ToDate != '' && $Status =='') + { + $Where = 'and mast.CreatedDate >= ? and mast.CreatedDate <= ? '; + $subQuery1 .= $Where; + $query = $this->db->query($subQuery1, array(REQ_DRAFT,$UserID,$FromDate,$ToDate)); + } + else if($Status != '' && $FromDate == '' && $ToDate == '') + { + $Where = 'and Status = ?'; + $subQuery1 .= $Where; + $query = $this->db->query($subQuery1, array(REQ_DRAFT,$UserID,$Status)); + } + + else + { + $query = $this->db->query($subQuery, array(REQ_DRAFT,$UserID)); + } + + // print_r($this->db->last_query()); + return $query->result(); + } + + + } \ No newline at end of file