siddharth_application/application/models/costcenter_model.php
gandhimathi Bharathirajan a06ea245b9 Cost center
2017-05-06 17:14:53 +05:30

278 lines
9.5 KiB
PHP

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class costcenter_model extends CI_Model
{
/**
* This function is used to get the user listing count
* @param string $searchText : This is optional search text
* @return number $count : This is row count
*/
function CostListingCount($searchText = '')
{
$this->db->select('Cost.CostCenterCode,Cost.CostCenterName, Cost.ApprovedBy,Emp.FirstName,Emp.Designation ');
$this->db->from('T_CostCenter_Master Cost');
$this->db->join('T_Employee_Details as Emp', 'Emp.EmpID=Cost.ApprovedBy');
if(!empty($searchText)) {
$likeCriteria = "( Cost.CostCenterCode LIKE '%".$searchText."%'
OR Cost.CostCenterName LIKE '%".$searchText."%'
OR Cost.ApprovedBy LIKE '%".$searchText."%'
OR Emp.FirstName LIKE '%".$searchText."%'
OR Emp.Designation LIKE '%".$searchText."%'
)";
$this->db->where($likeCriteria);
}
//$this->db->where('BaseT.isDeleted', 0);
//$this->db->where('BaseT.userId !=', 1);
$query = $this->db->get();
//print_r($this->db->last_query());
return count($query->result());
}
/**
* This function is used to get the user listing count
* @param string $searchText : This is optional search text
* @param number $page : This is pagination offset
* @param number $segment : This is pagination limit
* @return array $result : This is result
*/
function CostListing($searchText = '', $page, $segment)
{
$this->db->select('Cost.CostCenterCode as code,Cost.CostCenterName as CostCenterName , Cost.ApprovedBy as ApprovedBy,Emp.FirstName as FirstName,Emp.Designation as Designation ');
$this->db->from('T_CostCenter_Master as Cost');
$this->db->join('T_Employee_Details as Emp', 'Emp.EmpID=Cost.ApprovedBy');
if(!empty($searchText)) {
$likeCriteria = "( Cost.CostCenterCode LIKE '%".$searchText."%'
OR Cost.CostCenterName LIKE '%".$searchText."%'
OR Cost.ApprovedBy LIKE '%".$searchText."%'
OR Emp.FirstName LIKE '%".$searchText."%'
OR Emp.Designation LIKE '%".$searchText."%'
)";
$this->db->where($likeCriteria);
}
//$this->db->where('BaseT.isDeleted', 0);
//$this->db->where('BaseT.userId !=', 1);
$this->db->limit($page, $segment);
$query = $this->db->get();
$result = $query->result();
// print_r($this->db->last_query());
return $result;
}
/**
* This function used to get user information by id
* @param number $userId : This is user id
* @return array $result : This is user information
*/
function addNewcost($Cost)
{
$this->db->trans_start();
$this->db->insert('T_CostCenter_Master', $Cost);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
function addCostCenterDepartment($Dept)
{
$this->db->trans_start();
$this->db->insert('T_CostCenter_Departments', $Dept);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
// print_r( $this->db->last_query());
return $insert_id;
}
function addBudget($Budget)
{
$this->db->trans_start();
$this->db->insert('T_CostCenter_Budget', $Budget);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
// print_r( $this->db->last_query());
return $insert_id;
}
function getApproverName()
{
$this->db->select('EmpID,FirstName,LastName,Designation');
$this->db->from('T_Employee_Details');
$this->db->where('Departmentcode ', 'DEP13');
$query = $this->db->get();
return $query->result();
}
/**
* This function used to get user information by id
* @param number $userId : This is user id
* @return array $result : This is user information
*/
function getuserInfo($CostCenterID)
{
$this->db->select('CostCentreID, CostName,Description,CreatedDate');
$this->db->from('T_CostCentre');
$this->db->where('CostCentreID', $CostCenterID);
$query = $this->db->get();
return $query->result();
}
/**
* This function used to get Cost center Master information by Cost center ID
* @param number $CostCenterCode : CostCenterCode as Parameter
* @return array $result : This is user information
*/
function GetCostCenterMaster($CostCenterCode)
{
$this->db->select('Cost.CostCenterCode,Cost.CostCenterName,Cost.ApprovedBy,emp.FirstName,emp.Designation' );
$this->db->from('T_CostCenter_Master Cost');
$this->db->join('T_Employee_Details emp', 'emp.EmpID = Cost.ApprovedBy');
$this->db->where('Cost.CostCenterCode', $CostCenterCode);
$query = $this->db->get();
return $query->result();
}
/**
* This function used to get Cost center Department information by Cost center ID
* @param number $CostCenterCode : CostCenterCode as Parameter
* @return array $result : This is user information
*/
function GetCostCenterDepartment($CostCenterCode)
{
$this->db->select('Dept.DEPCode,Det.DepartmentName');
$this->db->from('T_CostCenter_Departments Dept');
$this->db->join('T_DepartmentDetails Det', 'Det.DEPCode = Dept.DEPCode');
$this->db->where('Dept.CostCenterCode', $CostCenterCode);
$query = $this->db->get();
return $query->result();
}
/**
* This function used to get Cost center Budget information by Cost center ID
* @param number $CostCenterCode : CostCenterCode as Parameter
* @return array $result : This is user information
*/
function GetCostCenterBudget($CostCenterCode)
{
$this->db->select('Bud.BudgetType,Bud.BudgetYear,Bud.BudgetAmount,Bud.Remarks' );
$this->db->from('T_CostCenter_Budget Bud');
$this->db->where('Bud.CostCenterCode', $CostCenterCode);
$query = $this->db->get();
return $query->result();
}
/**
* This function used to Department list which is not available in the Costcenter master
* @param number $CostCenterCode : CostCenterCode as Parameter
* @return array $result : This is user information
*/
function GetDepartmentNotinCostCenter($CostCenterCode)
{
$code = ''.$CostCenterCode.'';
echo $code ;
$this->db->select('Dept.DEPCode,Dept.DepartmentName');
$this->db->from('T_DepartmentDetails Dept');
// $this->db->where_not_in('Dept.DEPCode','(select DEPCode from T_CostCenter_Departments where CostCenterCode = ''T0001'')');
$query = $this->db->get();
// $query = $this->db->get();
print_r( $this->db->last_query());
return $query->result();
}
function editcost($Cost, $CostCenterID)
{
$this->db->where('CostCentreID', $CostCenterID);
$this->db->update('T_CostCentre', $Cost);
return TRUE;
}
function DeleteBudget($BudgetType='',$BudgetYear='',$CostCenterCode ='')
{
$this->db->where("BudgetType", $BudgetType);
$this->db->where("BudgetYear", $BudgetYear);
$this->db->where("CostCenterCode", $CostCenterCode);
$this->db->delete('T_CostCenter_Budget');
//print_r( $this->db->last_query());
}
function DeleteDepartment($DepCode='',$CostCode='')
{
$this->db->where("DEPCode", $DepCode);
$this->db->where("CostCenterCode", $CostCode);
$this->db->delete('T_CostCenter_Departments');
//print_r( $this->db->last_query());
}
function checkDeptCostExists($DepCode='',$CostCode='')
{
$this->db->select('CostCenterCode,DEPCode');
$this->db->from('T_CostCenter_Departments');
$this->db->where('DEPCode',$DepCode);
$this->db->where('CostCenterCode',$CostCode);
$query = $this->db->get();
if ($query->num_rows > 0) {
return $query->result_array();
}
}
function checkCostDetailsExists($Code='',$CostName='')
{
$this->db->select('CostCenterCode');
$this->db->from('T_CostCenter_Master');
$this->db->where('CostCenterCode',$Code);
if ($CostName != '')
{
$this->db->where('CostCenterName !=',$CostName);
}
$query = $this->db->get();
if ($query->num_rows > 0) {
return $query->result_array();
}
}
/* *//**
* This function is used to get the Department details from T_DepartmentDetails
* @return array $result : This is result of the query
*/
function getDepartment()
{
$this->db->select('DEPCode, DepartmentName');
$this->db->from('T_DepartmentDetails');
$this->db->where('IsActive =', 1);
$query = $this->db->get();
return $query->result();
}
/**
* This function is used to get the Config value from configuration table
* @return array $result : This is result of the query
*/
function getConfigValue($ConfigID )
{
$this->db->select('ConfigValue');
$this->db->from('T_ConfigDetails');
$this->db->where('Config_id ',$ConfigID );
$query = $this->db->get();
return $query->result();
}
}
?>