siddharth_application/application/models/cashbook_model.php
2018-03-22 18:16:47 +05:30

562 lines
16 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();
}
function getAccountpay()
{
$this->db->where('type',PAYMENT);
$r = $this->db->get('t_accountcode');
return $r->result();
}
function getAccounTypes1()
{
$this->db->select('name');
$r = $this->db->get('t_accountcode');
return $r->result();
}
function saveIncomeExpense($data)
{
$this->db->insert('t_income_expense',$data);
$r = $this->db->affected_rows();
return $r;
}
function addcashbook($bankcash1)
{
$this->db->insert('T_Bankmappingcashbook',$bankcash1);
$r = $this->db->affected_rows();
return $r;
}
function getIncomeExpenseList($i="")
{
// echo $i;
$this->db->select('t_accountcode.name,cashtype,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');
$this->db->order_by("date","desc");
if(!empty($i))
{
$this->db->where('t_income_expense.id',$i);
}
$r = $this->db->get();
return $r->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->order_by("date", "desc");
//$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)
{
//echo $cashid;
$sql="UPDATE t_income_expense SET document = NULL
WHERE id = ?";
$query = $this->db->query($sql,array($cashid));
//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;
}
function bankfile($FileDetails)
{
$this->db->insert('T_bankingfile',$FileDetails);
$r = $this->db->affected_rows();
return $r;
}
function bankfiledata($filedataupload)
{
$this->db->insert('T_bankreport', $filedataupload);
$r = $this->db->affected_rows();
//print_r($this->db->last_query());
return $r;
}
function bankstatement($fdate,$tdate){
$sql="SELECT *,date_format(reportdate,'%d-%m-%Y')as date,tie.total,date_format(valuedate,'%d-%m-%Y')as valuedate from T_bankreport as br left join t_income_expense as tie on tie.bankid=br.ID where reportdate !=0 group by(br.ID)";
if ($fdate and $tdate != ''){
$fdate= date("Y-m-d",strtotime($fdate));
$tdate=date("Y-m-d",strtotime($tdate));
$sql.="and date(reportdate) >= '".$fdate."'
and date(reportdate) <= '".$tdate."'";
}
$query = $this->db->query($sql);
return $query->result();
}
function debitbankstatemet($SupplierName,$fdate,$tdate)
{
$status='ST057';
//echo $tdate;
//die();
$this->db->distinct();
$this->db->select('POM.PONO,POM.Paymentstatus,supp.SupplierName,
POM.TotalOrderValue,POM.ServiceDescription,BR.Balancetopay,BR.Amountpaid,
POM.PODate,POM.POType,POM.ReleasedBy,POM.IsQualityChkReqired,POM.POType,POM.CapitalRange,POM.Status,
PUADV.AdvanceAmount');
$this->db->from ('T_PurchaseOrder_Master POM');
$this->db->join('T_SupplierDetailsN supp','supp.SupplierID = POM.SupplierID');
$this->db->join('T_PurchaseOrder_AdvanceRequest PUADV','POM.PONO=PUADV.PONO','left');
$this->db->join ('T_Bankporeport BR','BR.PONO = POM.PONO','left');
$this->db->where('POM.Status',ST044);
$this->db->where('supp.SupplierName',$SupplierName);
$this->db->or_where('POM.PODate BETWEEN "'. date('Y-m-d', strtotime($fdate)). '" and "'. date('Y-m-d', strtotime($tdate)).'"');
$this->db->group_by('POM.PONO');
$query = $this->db->get();
return $query->result();
}
function bankinvoice($Customer,$fdate,$tdate)
{
$this->db->distinct();
$this->db->select('iva.invoice_id,iva.invoice_total,iv.invoice_date_created,iva.invoice_paid,ic.client_name,BI.balancetoreceived,BI.amountreceived');
$this->db->from ('ip_invoice_amounts iva');
$this->db->join ('ip_invoices iv','iv.invoice_id = iva.invoice_id','left');
$this->db->join ('ip_clients ic','ic.client_id = iv.client_id','left');
$this->db->join ('T_Bankinvoicereport BI','BI.invoiceno = iva.invoice_id','left');
$this->db->where('ic.client_name',$Customer);
$this->db->or_where('iv.invoice_date_created BETWEEN "'. date('Y-m-d', strtotime($fdate)). '" and "'. date('Y-m-d', strtotime($tdate)).'"');
$this->db->group_by('iva.invoice_id');
//$this->db->where('inc.type','PAYMENT');
$query = $this->db->get();
return $query->result();
}
function receiptdata()
{
$this->db->distinct();
$this->db->select('inc.type,inc.date,inc.account_code,inc.towhom,inc.total');
$this->db->from ('t_income_expense inc');
$this->db->where('inc.type','RECEIPT');
$query = $this->db->get();
return $query->result();
}
function paymentdata()
{
$this->db->distinct();
$this->db->select('inc.type,inc.date,inc.account_code,inc.towhom,inc.total');
$this->db->from ('t_income_expense inc');
//$this->db->group_by('inc.account_code');
//$this->db->where('inc.type','PAYMENT');
$query = $this->db->get();
return $query->result();
}
function debitpolist($bankid)
{
$this->db->select('mid,Podate,PONO,Suppliername,Totalpoamount,
Balancetopay,Amountpaid');
$this->db->from ('T_Bankmappingpo');
$this->db->where('mid',$bankid);
//$this->db->group_by('PONO');
$query = $this->db->get();
return $query->result();
}
function creditinvoicelist($SupplierName,$fdate,$tdate,$bankid)
{
$this->db->select('indate,invoiceno,customername,totinvoiceamount,
balancetoreceived,amountreceived');
$this->db->from ('T_Bankinvoicereport');
$this->db->where('bankid',$bankid);
$this->db->group_by('invoiceno');
$query = $this->db->get();
return $query->result();
}
// function mappingcash($SupplierName,$fdate,$tdate,$bankid)
// {
// $this->db->select('mid,btype,amount,boption,ie.total,ie.account_code,ie.date');
// $this->db->from ('T_Bankmappingcashbook bmc');
// $this->db->join ('t_income_expense ie','ie.bankid = bmc.mid','left');
// $this->db->where('mid',$bankid);
// $this->db->group_by('mid');
// $query = $this->db->get();
// return $query->result();
// }
function mappingcash($SupplierName,$fdate,$tdate,$bankid)
{
$this->db->select('date,bankid,cashtype,amounttype,total,account_code');
$this->db->from ('t_income_expense');
//$this->db->join ('t_income_expense ie','ie.bankid = bmc.mid','left');
$this->db->where('bankid',$bankid);
//$this->db->group_by('mid');
$query = $this->db->get();
return $query->result();
}
function newcashbook()
{
$this->db->select('cdate,mid,btype,amount,boption,mappingamount,totalamount,amounttype,alreadycreditpaid');
$this->db->from ('T_Bankmappingcashbook');
//$this->db->where('mid',$bankid);
//$this->db->group_by('mid');
$query = $this->db->get();
return $query->result();
}
function debitlistpo($SupplierName,$fdate,$tdate,$pono)
{
$this->db->select('bmp.mid,bmp.PONO,bmp.Amountpaid,br.Narration');
$this->db->from ('T_Bankmappingpo as bmp');
$this->db->join('T_bankreport br','br.ID = bmp.mid');
$this->db->where('PONO',$pono);
// $this->db->group_by('PONO');
$query = $this->db->get();
return $query->result();
}
function creditlistinv($invno)
{
$this->db->select('bmp.bankid,bmp.invoiceno,bmp.amountreceived,br.Narration');
$this->db->from ('T_Bankinvoicereport as bmp');
$this->db->join('T_bankreport br','br.ID = bmp.bankid');
$this->db->where('invoiceno',$invno);
// $this->db->group_by('PONO');
$query = $this->db->get();
return $query->result();
}
function getsupplier()
{
$this->db->select('SupplierName');
$this->db->from('T_SupplierDetailsN');
//$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 getcustomer()
{
$this->db->select('client_name');
$this->db->from('ip_clients');
//$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 invoicedata($invoicedata)
{
$this->db->insert('T_Bankinvoicereport',$invoicedata);
// $this->db->where('PONO',$pono);
$r = $this->db->affected_rows();
return $r;
}
function podata($podata)
{
$this->db->insert('T_Bankporeport',$podata);
// $this->db->where('PONO',$pono);
$r = $this->db->affected_rows();
return $r;
}
function invicedata($invoicedata)
{
$this->db->insert('T_Bankinvoicereport',$invoicedata);
$r = $this->db->affected_rows();
return $r;
}
function mappingpo($podata)
{
$this->db->insert('T_Bankmappingpo',$podata);
// $this->db->where('PONO',$pono);
$r = $this->db->affected_rows();
return $r;
}
function mappinginvoice($invoicedata)
{
$this->db->insert('T_Bankmappingiv',$invoicedata);
// $this->db->where('PONO',$pono);
$r = $this->db->affected_rows();
return $r;
}
function mappingcashbook($podata)
{
$this->db->insert('T_Bankmappingpo',$podata);
// $this->db->where('PONO',$pono);
$r = $this->db->affected_rows();
return $r;
}
public function poupdate($pono)
{
$this->db->select('PONO');
$this->db->from('T_Bankporeport');
$this->db->where('PONO ',$pono);
$query = $this->db->get();
// print_r( $this->db->last_query());
return $query->result();
}
public function invoiceupdate($invid)
{
$this->db->select('invoiceno');
$this->db->from('T_Bankinvoicereport');
$this->db->where('invoiceno',$invid);
$query = $this->db->get();
// print_r( $this->db->last_query());
return $query->result();
}
public function bankid($pono)
{
$this->db->select('PONO');
$this->db->from('T_Bankporeport');
$this->db->where('PONO ',$pono);
$query = $this->db->get();
// print_r( $this->db->last_query());
return $query->result();
}
public function cashbankupdate($cashbookstatus,$bankid)
{
$this->db->where('ID',$bankid);
$this->db->update('T_bankreport',$cashbookstatus);
return TRUE;
}
function cashcreditupdate($cashbookstatus1,$bankid)
{
$this->db->where('ID',$bankid);
$this->db->update('T_bankreport',$cashbookstatus1);
return TRUE;
}
public function bankupdate($bankdata,$bankid)
{
$this->db->where('ID ',$bankid);
$this->db->update('T_bankreport',$bankdata);
return TRUE;
}
public function bankcreditupdate($bankcreditdata,$bankid)
{
$this->db->where('ID ',$bankid);
$this->db->update('T_bankreport',$bankcreditdata);
// print_r( $this->db->last_query());
return TRUE;
}
public function getearlyamount($pono)
{
$this->db->select('Amountpaid');
$this->db->from('T_Bankporeport');
$this->db->where('PONO ',$pono);
$query = $this->db->get();
// print_r( $this->db->last_query());
return $query->result();
}
public function getearlyamountcredit($invid)
{
$this->db->select('amountreceived');
$this->db->from('T_Bankinvoicereport');
$this->db->where('invoiceno ',$invid);
$query = $this->db->get();
// print_r( $this->db->last_query());
return $query->result();
}
public function getalreadypaid($bankid)
{
$this->db->select('Clearbalance');
$this->db->from('T_bankreport');
$this->db->where('ID ',$bankid);
$query = $this->db->get();
// print_r( $this->db->last_query());
return $query->result();
}
public function getalreadyreceived($bankid)
{
$this->db->select('cclearbalance');
$this->db->from('T_bankreport');
$this->db->where('ID ',$bankid);
$query = $this->db->get();
// print_r( $this->db->last_query());
return $query->result();
}
public function poupdate1($podata,$pono)
{
$this->db->where('PONO', $pono);
$this->db->update('T_Bankporeport',$podata);
return TRUE;
}
public function invoiceupdate1($invoicedata,$invid)
{
//print_r($invoicedata);
//print_r($invid);
$this->db->where('invoiceno',$invid);
$this->db->update('T_Bankinvoicereport',$invoicedata);
return TRUE;
}
function paided()
{
$this->db->select('*');
$this->db->from('T_Bankporeport');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function received()
{
$this->db->select('*');
$this->db->from('T_Bankinvoicereport');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function poamountstatus($pomaster,$pono)
{
$this->db->where('PONO', $pono);
$this->db->update('T_PurchaseOrder_Master',$pomaster);
$r = $this->db->affected_rows();
return $r;
}
function poamountstatus1($pomaster1,$pono)
{
$this->db->where('PONO', $pono);
$this->db->update('T_PurchaseOrder_Master',$pomaster1);
$r = $this->db->affected_rows();
return $r;
}
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;
}
}
}
?>