ria/application/models/costcenter_model.php
venbatechnologies@gmail.com b1c8fe52a4 issues fixes
2018-07-12 12:34:06 +05:30

473 lines
17 KiB
PHP
Executable File

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class costcenter_model extends CI_Model
{
/**
* To get the Cost listing
* @return array $result : result of the query (returns )
*/
function CostListing()
{
$this->db->select('Cost.CostCenterCode as code,Cost.CostCenterName as CostCenterName , Cost.ApprovedBy as ApprovedBy,Emp.FirstName as FirstName,Emp.Designation as Designation ,Cost.CreatedDate,Cost.IsActive');
$this->db->from('T_CostCenter_Master as Cost');
$this->db->join('T_Employee_Details as Emp', 'Emp.EmpID=Cost.ApprovedBy');
$query = $this->db->get();
$result = $query->result();
return $result;
}
/**
* To store cost information by id
* @param number $Cost : This will have cost
* @return number $insert_id : This will return how many value are inserted
*/
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;
}
/**
* To get fiscalyear information from company table
* @return $query->result() : This is result of the query
*/
function getFiscalYear()
{
$this->db->select('year(FiscalYearStartOn) as StartYear,year(FiscalYearEndsOn) as EndYear');
$this->db->from('T_Company_Details');
$query = $this->db->get();
return $query->result();
}
/**
* To store costcenter department information
* @param array $Dept : This will have all the information of costcenter's department
* @return number $insert_id : This will return how many value are inserted (return as number/count)
*/
function addCostCenterDepartment($Dept)
{
$this->db->trans_start();
$this->db->insert('T_CostCenter_Departments', $Dept);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
/**
* To store costcenter Budget information
* @param array $Budget : this will have all the information of costcenter's department
* @return number $insert_id : This will return how many value are inserted (return as number/count)
*/
function addBudget($Budget)
{
$this->db->trans_start();
$this->db->insert('T_CostCenter_Budget', $Budget);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
/**
* To get approver name by using department code
* @return array $query->result() : result of the query
*/
function getApproverName()
{
$this->db->select('EmpID,FirstName,LastName,Designation');
$this->db->from('T_Employee_Details');
$this->db->where('Departmentcode ', 'DEP10');
$query = $this->db->get();
return $query->result();
}
/**
* To get costcenter information by id
* @param number $CostcenterID : This is cost center code
* @return array $query->result() : This is result of the query
*/
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 : This is CostCenterCode as Parameter
* @return array $query->result() : This is result of the query (Costcenter master information)
*/
function GetCostCenterMaster($CostCenterCode)
{
$this->db->select('Cost.CostCenterCode,Cost.CostCenterName,Cost.ApprovedBy,emp.FirstName,emp.Designation,max(BudgetYear) as BudYear' );
$this->db->from('T_CostCenter_Master Cost');
$this->db->join('T_Employee_Details emp', 'emp.EmpID = Cost.ApprovedBy');
$this->db->join('T_CostCenter_Budget Bud', ' Bud.CostCenterCode = Cost.CostCenterCode');
$this->db->where('Cost.CostCenterCode', $CostCenterCode);
$query = $this->db->get();
return $query->result();
}
/**
* To get Cost center Department information by Cost center ID
* @param number $CostCenterCode : This is the CostCenterCode as Parameter
* @return array $query->result() : This is result of the query
*/
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();
}
/**
* To get Cost center Budget year information by Cost center ID
* @param number $CostCenterCode : This is CostCenterCode as Parameter
* @return array $query->result() : This is result of the query
*/
function GetBudgetYear($CostCenterCode)
{
$subQuery = 'select BudgetYear from T_CostCenter_Budget where CostCenterCode=? ';
$query = $this->db->query($subQuery, array($CostCenterCode));
return $query->result();
}
/**
* To get Cost center Budget information by Cost center ID
* @param number $CostCenterCode : This is CostCenterCode as Parameter
* @return array $query->result() : This is user information
*/
function GetCostCenterBudget($CostCenterCode)
{
$subQuery = 'select BudgetType,BudgetYear,BudgetAmount,Remarks from T_CostCenter_Budget where CostCenterCode=? and
BudgetYear=(select max(BudgetYear) from T_CostCenter_Budget where CostCenterCode=?)';
$query = $this->db->query($subQuery, array($CostCenterCode,$CostCenterCode));
return $query->result();
}
/**
* To get Cost center Budget information by Cost center ID
* @param number $CostCenterCode : This is CostCenterCode as Parameter
* @param number $ConfigID : This is Config Id
* @param number $Year : This is budget year
* @return array $query->result_array() : This is result of the query
*/
function GetCostBudgetTypeByYear($CostCenterCode,$ConfigID,$Year)
{
$subQuery = 'select ConfigValue from T_ConfigDetails Bud where ConfigValue not in
(select BudgetType from T_CostCenter_Budget where CostCenterCode=? and BudgetYear=?) and Config_ID=? ';
$query = $this->db->query($subQuery, array($CostCenterCode,$Year,$ConfigID));
return $query->result_array();
}
/**
* To get Cost center Budget information by Cost center ID and budget year
* @param number $CostCenterCode : This is CostCenterCode as Parameter
* @param number $Year : This is Budget year
* @return array $query->result_array() : This is result of the query
*/
function GetCostCenterBudgetByYear($CostCenterCode,$Year)
{
$subQuery = 'select BudgetType,BudgetYear,BudgetAmount,Remarks from T_CostCenter_Budget where CostCenterCode=? and
budgetyear=?';
$query = $this->db->query($subQuery, array($CostCenterCode,$Year));
return $query->result_array();
}
/**
* To get Department list which is not available in the Costcenter master
* @param number $CostCenterCode : CostCenterCode as Parameter
* @return array $result : This is result of the query
*/
function GetDepartmentNotinCostCenter($CostCenterCode)
{
$subQuery = 'select Dept.DEPCode,Dept.DepartmentName from T_DepartmentDetails Dept
where Dept.DEPCode not in
(select DEPCode from T_CostCenter_Departments where CostCenterCode=?) order by Dept.DEPCode asc';
$query = $this->db->query($subQuery, array($CostCenterCode));
return $query->result();
}
/**
* To get Department list which is not available in the Costcenter master based on cost code and config id
* @param number $CostCenterCode : This is CostCenterCode as Parameter
* @param number $ConfigID : This is ConfigID as Parameter
* @return array $query->result() : This is result of the query
*/
function GetBudgetTypeNotinCostCenter($CostCenterCode,$ConfigID)
{
$subQuery = 'select ConfigValue from T_ConfigDetails Bud where ConfigValue not in
(select BudgetType from T_CostCenter_Budget where CostCenterCode=? and BudgetYear=(select max(BudgetYear) from T_CostCenter_Budget)) and Config_ID=?';
$query = $this->db->query($subQuery, array($CostCenterCode,$ConfigID));
return $query->result();
}
/**
* To store edited the Costcenter master
* @param number $CostCenterCode : This have all the edited CostCenter datas
*/
function EditCost($Cost,$CostCenterCode)
{
$this->db->where('CostCenterCode', $CostCenterCode);
$this->db->update('T_CostCenter_Master', $Cost);
return TRUE;
}
/**
* To store the Costcenter budget by costcenter's budget
* @param number $Budget : This will have all the budget details
* @return number $insert_id : This is result of the query
*/
function EditBudget($Budget)
{
$this->db->trans_start();
$this->db->insert('T_CostCenter_Budget', $Budget);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
/**
* To delete the Costcenter budget
* @param string $BudgetType : Optional : This is Budgettype as Parameter
* @param number $BudgetYear : Optional : This is Budgetyear as Parameter
* @param number $CostCenterCode : Optional : This is Costcenter as parameter
*/
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');
}
/**
* To delete the Costcenter department
* @param number $Depcode : Optional : This is Depcode as Parameter
* @param number $CostCode : Optional : This is Costcenter as parameter
*/
function DeleteDepartment($DepCode='',$CostCode='')
{
$this->db->where("DEPCode", $DepCode);
$this->db->where("CostCenterCode", $CostCode);
$this->db->delete('T_CostCenter_Departments');
}
/**
* To check the costcenter if department details is already exists are not
* @param number $Depcode : Optional : This is Depcode as Parameter
* @param number $CostCode : Optional : This is Costcenter as parameter
* @return array $query->result_array() : result of the 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();
}
}
/**
* To check costcenter is already exists are not
* @param number $Depcode : Optional : This is Depcode as Parameter
* @param number $CostCode : Optional : This is Costcenter as parameter
* @return array $query->result_array() : result of the query
*/
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();
}
}
/**
* To get the Department details from T_DepartmentDetails
* @return array $query->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
* @param number $ConfigID : This is ConfigID as parameter
* @return array $result : 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();
}
/**
* To get costcenter's information for export xl
*/
function export_excel(){
$where = null;
$this->db->select('Mas.*,bud.*,emp.firstname,emp1.firstname as Updated_By');//count(dep.DEPCode) AS ctvalue');
$this->db->select('sum(distinct case when Mas.budgettype="CAPITAL" then budgetamount else 0 end) as capital',FALSE);
$this->db->select('sum(distinct case when Mas.budgettype="REVENUE" then budgetamount else 0 end) as revenue',FALSE);
$this->db->select('sum(distinct case when Mas.budgettype="SERVICE" then budgetamount else 0 end) as service',FALSE);
$this->db->select('sum(distinct case when Mas.budgettype="IMPORT" then budgetamount else 0 end) as import',FALSE);
$this->db->select('GROUP_CONCAT(distinct part.DepartmentName) as DepartmentName');
$this->db->join('T_CostCenter_Budget as Mas','Mas.CostCenterCode=bud.CostCenterCode','left');
$this->db->join('T_CostCenter_Departments as dep',' dep.CostCenterCode=Mas.CostCenterCode','left');
$this->db->join('T_DepartmentDetails as part','part.DEPCode=dep.DEPCode','left');
$this->db->group_by(array('bud.CostCenterCode','Mas.BudgetYear'));
$this->db->join('tbl_users as tbl',' bud.createdby = tbl.userid','left');
$this->db->join('T_Employee_Details as emp', 'emp.empid=tbl.empid','left');
$this->db->join('tbl_users as tbl1',' bud.UpdatedBy = tbl1.userid','left');
$this->db->join('T_Employee_Details as emp1', 'emp1.empid=tbl1.empid','left');
$this->db->where('Mas.BudgetYear !=""');
return $this->db->get('T_CostCenter_Master as bud')->result_array();
}
/**
* To check the costcenter if budget year details is already exists are not
* @param string $BudgetType : This is budget type
* @param number $BudgetYear : This is budget year
* @param number $CostCode : This is cost code
*/
function CheckExistBudget($BudgetType,$BudgetYear,$CostCode){
$this->db->select('CostCenterCode');
$this->db->from('T_CostCenter_Budget');
$this->db->where('CostCenterCode',$CostCode);
$this->db->where('BudgetType',$BudgetType);
$this->db->where('BudgetYear',$BudgetYear);
$query = $this->db->get();
if ($query->num_rows > 0) {
return TRUE;
}
else{
return FALSE;
}
}
/**
* To update Costcenter Budget Details
* @param array $Budget : This will have all the edited datas of costcenter's budget
* @param string $BudgetType : This is budget type
* @param number $BudgetYear : This is budget year
* @param number $CostCode : This is Cost code
*/
function updateBudget($Budget,$BudgetType,$BudgetYear,$CostCode)
{
$this->db->where('CostCenterCode',$CostCode);
$this->db->where('BudgetType',$BudgetType);
$this->db->where('BudgetYear',$BudgetYear);
$this->db->update('T_CostCenter_Budget', $Budget);
return TRUE;
}
function getDepartmentnotadded($Empid)
{
$subQuery = 'select Dept.DEPCode,Dept.DepartmentName from T_DepartmentDetails Dept
left join T_AccessDepartments Ass on Ass.Departmentcode= Dept.DEPCode
where Dept.DEPCode not in
(select Ass.Departmentcode from T_AccessDepartments Ass where EmpID=?) group by Dept.DEPCode';
$query = $this->db->query($subQuery, array($Empid));
return $query->result();
}
function getaccessDept($Empid)
{
$this->db->select('Ass.Departmentcode as AssDep,Dep.DepartmentName');
$this->db->from('T_AccessDepartments Ass');
$this->db->join('T_DepartmentDetails Dep', 'Dep.DEPCode = Ass.Departmentcode','left');
$this->db->where('EmpID ',$Empid);
$query = $this->db->get();
return $query->result();
}
}
?>