ria/application/models/cashbook_model.php
venbatechnologies@gmail.com 5ad352e1c4 cashbook changes
2018-06-29 16:57:03 +05:30

344 lines
10 KiB
PHP
Executable File

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class cashbook_model extends CI_Model
{
function getAccounTypes()
{
$this->db->where('status',1);
$r = $this->db->get('t_accountcode');
return $r->result();
}
/**
* To Save Recepit and Payment datas
* array $data - Recepit/Payment array datas
* return $last_id - last inserted id
*/
function saveIncomeExpense($data)
{
$this->db->insert('t_income_expense',$data);
//$r = $this->db->affected_rows();
//return $r;
$last_id = $this->db->insert_id();
return $last_id;
}
function getIncomeExpenseList($i="")
{
$this->db->select('t_accountcode.code,t_accountcode.name,T_Employee_Details.FirstName,T_Employee_Details.LastName,t_income_expense.*');
$this->db->from('t_income_expense');
$this->db->join('t_accountcode','t_income_expense.account_code=t_accountcode.code');
$this->db->join('tbl_users','t_income_expense.Created_By=tbl_users.userId');
$this->db->join('T_Employee_Details','tbl_users.EmpID=T_Employee_Details.EmpID');
if(!empty($i))
{
$this->db->where('t_income_expense.id',$i);
}
$r = $this->db->get();
return $r->result();
}
// function getIncomeExpenseList($i="",$type)
// {
// $sql="SELECT `t_accountcode`.`name`, `T_Employee_Details`.`FirstName`,
// `T_Employee_Details`.`LastName`, `t_income_expense`.*
// FROM (`t_income_expense`)
// JOIN `t_accountcode` ON `t_income_expense`.`account_code`=`t_accountcode`.`code` or `t_income_expense`.`account_code` = '999'
// JOIN `tbl_users` ON `t_income_expense`.`Created_By`=`tbl_users`.`userId`
// JOIN `T_Employee_Details` ON `tbl_users`.`EmpID`=`T_Employee_Details`.`EmpID`
// WHERE `t_income_expense`.`id` = ".$i."
// and t_income_expense.type = '".$type."'
// group by t_income_expense.id";
// $query = $this->db->query($sql);
// $result = $query->result();
// return $result;
// }
/**
* To Get Recepit and Payment datas for list
* string $aid - Recepit/Payment id
* return $query->result() - Recepit/Payment datas based on id
*/
function getreceiptpaymentlist($aid = '')
{
$sql="SELECT `t_accountcode`.`name`, `T_Employee_Details`.`FirstName`,`T_Employee_Details`.`LastName`, `t_income_expense`.*
FROM (`t_income_expense`)
JOIN `t_accountcode` ON `t_income_expense`.`account_code`=`t_accountcode`.`code` or `t_income_expense`.`account_code` = '999'
JOIN `tbl_users` ON `t_income_expense`.`Created_By`=`tbl_users`.`userId`
JOIN `T_Employee_Details` ON `tbl_users`.`EmpID`=`T_Employee_Details`.`EmpID`
group by t_income_expense.id";
$query = $this->db->query($sql);
return $query->result();
}
function getIncomeExpense($firstyear,$secondyear,$frmdt,$todt)
{
$this->db->select('t_accountcode.name,T_Employee_Details.FirstName,T_Employee_Details.LastName,t_income_expense.*');
$this->db->from('t_income_expense');
$this->db->join('t_accountcode','t_income_expense.account_code=t_accountcode.code','left');
$this->db->join('tbl_users','t_income_expense.Created_By=tbl_users.userId','left');
$this->db->join('T_Employee_Details','tbl_users.EmpID=T_Employee_Details.EmpID','left');
if ($firstyear and $secondyear != ''){
$finyear = "t_income_expense.date >= '".$firstyear."-04-01' and t_income_expense.date <= '".$secondyear."-03-31'";
$this->db->where($finyear);
}
if ($frmdt and $todt != ''){
$fromdate= date("Y-m-d",strtotime($frmdt));
$todate=date("Y-m-d",strtotime($todt));
$date = "date(t_income_expense.date) >= '".$fromdate."'
and date(t_income_expense.date) <= '".$todate."'";
$this->db->where($date);
}
$this->db->order_by("date","desc");
$r = $this->db->get();
return $r->result();
}
function finyear(){
$sql="SELECT
CASE WHEN MONTH(date)>=4 THEN
concat(YEAR(date), '-',YEAR(date)+1)
ELSE concat(YEAR(date)-1,'-', YEAR(date)) END AS financial_year
FROM t_income_expense
GROUP BY financial_year";
$query = $this->db->query($sql);
return $query->result();
}
function getCompany()
{
$r = $this->db->get('T_Company_Details');
return $r->result();
}
function getAccounutInfo($i)
{
$this->db->select('t_accountcode.name,t_income_expense.*');
$this->db->from('t_income_expense');
$this->db->join('t_accountcode','t_income_expense.account_code=t_accountcode.code');
//$this->db->where('t_income_expense.id')
$r = $this->db->get();
return $r->result();
}
function Selectcash()
{
$this->db->select('*');
$this->db->from('t_accountcode');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function viewdepartment($sid='')
{
$sql="SELECT ie.*,ac.name,date_format(ie.date,'%d-%m-%Y')as date FROM t_income_expense ie
JOIN t_accountcode ac on ac.code=ie.account_code
WHERE ie.id = ?";
$query = $this->db->query($sql,array($sid));
//print_r($this->db->last_query());
//echo $sql;
return $query->result();
}
function deletefile($cashid,$cashfile)
{
$sql="UPDATE t_income_expense SET document = NULL
WHERE id = ?";
$query = $this->db->query($sql,array($cashid));
unlink("uploads/cashbook/".$cashfile);//this deletes the file on particular folder too
//print_r($this->db->last_query());
//echo $sql;
$r = $this->db->affected_rows();
return $r;
}
function updatedepartment($updateaccount,$id1)
{
$this->db->where('id', $id1);
$this->db->update('t_income_expense',$updateaccount);
$r = $this->db->affected_rows();
return $r;
}
/**
* To Update Payment Master datas
* array $updateaccount - Payment Master datas
* string $id1 - Payment's id
* return $ar - it return how many rows will affected
*/
function updatepaymentmaster($updateaccount,$id1)
{
$this->db->where('id', $id1);
$this->db->update('t_income_expense',$updateaccount);
//$ar = $this->db->affected_rows();
//return $ar;
$last_id = $this->db->insert_id();
return $last_id;
}
/**
* To Get Payment Master for edit
* string $sid - Payment id
* return $query->result() - Payment datas based on id return as an array
*/
function viewpaymentmaster($sid='')
{
$sql="SELECT ie.*,ac.name,date_format(ie.date,'%d-%m-%Y')as date
FROM T_Paymentdetails pd
JOIN t_income_expense ie ON ie.id = pd.Payment_id
JOIN t_accountcode ac ON ac.code = pd.account_code
WHERE ie.id = ?
group by pd.Payment_id";
$query = $this->db->query($sql,array($sid));
return $query->result();
}
/**
* To Get Payment lineitem Details for list (list dialog box)
* string $paymentid - Payment id
* return $result - Payment lineitem datas based on id return as an array
*/
function viewpaymentdetails($paymentid)
{
$sql="SELECT ac.name,pd.*,ie.*
FROM T_Paymentdetails pd
JOIN t_income_expense ie ON ie.id = pd.Payment_id
JOIN t_accountcode ac ON ac.code = pd.account_code
WHERE pd.Payment_id = ".$paymentid ;
$query = $this->db->query($sql);
$result = $query->result();
return $result;
}
/**
* To Add and Update Payment Lineitem datas
* array $PaymentDetails - Payment lineitem datas
* return $i - To insert Payment datas based on id if new data means
* return $u - To update Payment datas based on id if already have means
*/
function addpaymentdetails($addPaymentDetails){
$this->db->insert('T_Paymentdetails',$addPaymentDetails);
$r = $this->db->affected_rows();
return $r;
// $this->db->set($addPaymentDetails);
// $this->db->insert($this->db->dbprefix . 'T_Paymentdetails');
}
function updatepaymentdetails($UpdatePaymentsdetails,$hidekey){
$this->db->where('ID', $hidekey);
$this->db->update('T_Paymentdetails',$UpdatePaymentsdetails);
$ar = $this->db->affected_rows();
return $ar;
}
//function addupdatepaymentdetails($PaymentDetails,$hidekey=''){
// $paymentid = $PaymentDetails['Payment_id'];
// //$key = $PaymentDetails['ID'];
// $count=0;
// $this->db->select('count(*) as count');
// $this->db->from('T_Paymentdetails');
// $this->db->where('Payment_id',$paymentid);
// $this->db->where('ID',$hidekey);
// $isExits = $this->db->get();
// $res = $isExits->result_array();
// if(!empty($res))
// {
// $count = $res[0]['count'];
// }
// if($count == 0 )//for insert
// {
// $i = $this->db->insert('T_Paymentdetails',$PaymentDetails);
// return $i;
// }
// elseif($count == 1)//for update
// {
// $this->db->where('Payment_id', $paymentid);
// $this->db->where('ID', $hidekey);
// $u = $this->db->update('T_Paymentdetails',$PaymentDetails);
// return $u;
// }
// }
/**
* To Delete Payment Lineitem datas
* string $acc - Payment's accountcode
* string $id - Payment's id
* return $ar - It returns how many rows will affetected
*/
function deletepaymentdetails($id){
$sql = "DELETE FROM T_Paymentdetails WHERE ID =".$id;
$query = $this->db->query($sql);
$ar = $this->db->affected_rows();
return $ar;
}
function Cashbook($cashbookdatas)
{
$code=$cashbookdatas['code'];
$type=$cashbookdatas['type'];
$count=0;
$this->db->select('count(*) as count');
$this->db->from('t_accountcode');
$this->db->where('type',$type);
$this->db->where('code',$code);
$isExits = $this->db->get();
$res = $isExits->result_array();
if(!empty($res))
{
$count = $res[0]['count'];
}
if($count == 0 )//for cashbook_insert
{
$cbi = $this->db->insert('t_accountcode', $cashbookdatas);
return $cbi;
}
elseif($count == 1)//for cashbook_update
{
$this->db->where('code',$code);
$cbu = $this->db->update('t_accountcode',$cashbookdatas);
return $cbu;
}
}
}
?>