siddharth_application/application/models/requistion_model.php
gandhimathi Bharathirajan ad8f5fe3a1 Requistion Flow
2017-05-10 13:36:23 +05:30

241 lines
7.1 KiB
PHP

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class requistion_model extends CI_Model
{
/**
* This function is used to get the SupplierID and SupplierName information
* @return array $result : This is result of the query
*/
function getSupplierName()
{
$this->db->select('SupplierID, SupplierName,Address');
$this->db->from('T_SupplierDetailsN');
//$this->db->where('roleId !=', 1);
$query = $this->db->get();
return $query->result();
}
/**
* This function is used to get the userId information
* @return array $result : This is result of the query
*/
function getusers()
{
$this->db->select('userId, name');
$this->db->from('tbl_users');
//$this->db->where('roleId !=', 1);
$query = $this->db->get();
return $query->result();
}
function GetEmployeeDetails($EmpID)
{
$this->db->select(' EMP.EmpID,EMP.Designation,DEPT.DEPCode,DEPT.DepartmentName');
$this->db->from('T_Employee_Details EMP');
$this->db->join('T_DepartmentDetails DEPT', 'EMP.Departmentcode = DEPT.DEPCode');
$this->db->where('EMP.EmpID ',$EmpID );
$query = $this->db->get();
return $query->result_array();
}
function GetCostCenterByDept($DeptId)
{
$this->db->select('Mast.CostCenterCode,Mast.CostCenterName');
$this->db->from('T_CostCenter_Master Mast ');
$this->db->join('T_CostCenter_Departments COST', 'COST.CostCenterCode = Mast.CostCenterCode');
$this->db->where('COST.DEPCode ',$DeptId );
$query = $this->db->get();
// print_r( $this->db->last_query());
return $query->result_array();
}
function GetAvailableBudgetAmount($CostCode,$Year,$BudgetType)
{
$this->db->select('BudgetAmount');
$this->db->from('T_CostCenter_Budget');
$this->db->where('CostCenterCode',$CostCode );
$this->db->where('BudgetYear',$Year );
$this->db->where('BudgetType',$BudgetType );
$query = $this->db->get();
return $query->result_array();
}
function GetMaterialCode($ReqType)
{
$this->db->select('MaterialCode, MaterialName,UOM');
$this->db->from('T_MaterialMaster');
$this->db->where('MaterialType',$ReqType );
$query = $this->db->get();
return $query->result_array();
}
/**
* This function is used to get the Raw Material information
* @return array $result : This is result of the query
*/
function getRawMaterialList($MaterialCode)
{
$this->db->select('MaterialName,UOM');
$this->db->from('T_MaterialMaster');
$this->db->where('MaterialCode',$MaterialCode );
$query = $this->db->get();
return $query->result_array();
}
/**
* This function is used to get the Config value from configuration table
* @return array $result : This is result of the query
*/
function getConfigValue($ConfigID ,$ConfigValue = '')
{
$this->db->select('ConfigValue');
$this->db->from('T_ConfigDetails');
$this->db->where('Config_id ',$ConfigID );
if($ConfigValue != '')
{
$this->db->where('ConfigValue != ',$ConfigValue );
}
$query = $this->db->get();
return $query->result();
}
/**
* This function is used to get the Purchase order Type
* @return array $result : This is result of the query
*/
function getAllEmployees()
{
$this->db->select('EmpID,FirstName,LastName');
$this->db->from('T_Employee_Details');
$query = $this->db->get();
return $query->result();
}
/**
* This function is used to get the Employee Details
* @return array $result : This is result of the query
*/
function getEmpIdByUserID($UserID)
{
$subQuery ='SELECT EMP.EmpID,EMP.FirstName,EMP.Designation,DEPT.DEPCode,DEPT.DepartmentName
FROM T_Employee_Details EMP JOIN T_DepartmentDetails DEPT ON
EMP.Departmentcode = DEPT.DEPCode
WHERE EMP.EmpID=(select EmpID from tbl_users where userId=?)';
$query = $this->db->query($subQuery, array($UserID));
return $query->result();
}
/**
* This function is used to get the CostCenter for the Selected Employee
* @return array $result : This is result of the query
*/
function getCostCenterUserID($UserID)
{
$subQuery ='SELECT Mast.CostCenterCode,Mast.CostCenterName from T_CostCenter_Master Mast
LEFT JOIN T_CostCenter_Departments COST ON COST.CostCenterCode = Mast.CostCenterCode
WHERE COST.DEPCode=(select Departmentcode from T_Employee_Details where EmpID = (select EmpID from tbl_users where userId=?))';
$query = $this->db->query($subQuery, array($UserID));
//print_r($this->db->last_query());
return $query->result();
}
/**
* This function is used to get the Purchase order Type
* @return array $result : This is result of the query
*/
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));
return $query->result();
}
/**
* This function is used to get the Purchase order Type
* @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=?)';
$query = $this->db->query($subQuery, array($UserID));
return $query->result();
}
function addRequistion($Requistion)
{
$this->db->trans_start();
$this->db->insert('T_Requestion_Master', $Requistion);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
if($insert_id>0)
{
$subQuery = 'select max(ReqNo) as ReqNo from T_Requestion_Master';
$query = $this->db->query($subQuery);
return $query->result_array();
}
}
function RequistionIsExists($ReqBy)
{
$this->db->select('ReqNo');
$this->db->from('T_Requestion_Master');
$this->db->where('Status ','Draft' );
$this->db->where('Requestedby ',$ReqBy );
$query = $this->db->get();
if ($query->num_rows > 0) {
//echo $result->num_rows;
return $query->result_array();
}
}
function addRequistionDetails($Requistion)
{
$this->db->trans_start();
$this->db->insert('T_Requestion_Details', $Requistion);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
// print_r($this->db->last_query());
return $insert_id;
}
function UpdateRequistion($Requistion, $ReqNo)
{
$this->db->where('ReqNo', $ReqNo);
$this->db->update('T_Requestion_Master', $Requistion);
return TRUE;
}
}