siddharth_application/application/models/cashbook_model.php
2018-05-19 17:08:55 +05:30

716 lines
20 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,type');
$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.*,br.*,br.ID,ie.totalbankamount,ac.name,ie.id,date_format(ie.date,'%d-%m-%Y')as date FROM t_income_expense ie
left join t_accountcode ac on ac.code=ie.account_code
left join T_bankreport br on br.ID=ie.bankid
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->select('reportdate,Narration,Balance');
$this->db->from('T_bankreport');
$this->db->where('reportdate',$filedataupload['reportdate']);
$this->db->where('Narration',$filedataupload['Narration']);
$this->db->where('Balance',$filedataupload['Balance']);
$query = $this->db->get();
if ($query->num_rows() > 0){
return true;
}
else{
$this->db->insert('T_bankreport', $filedataupload);
$r = $this->db->affected_rows();
//print_r($this->db->last_query());
return $r;
}
}
function report_finyear(){
$sql="SELECT
CASE WHEN MONTH(reportdate)>=4 THEN
concat(YEAR(reportdate), '-',YEAR(reportdate)+1)
ELSE concat(YEAR(reportdate)-1,'-', YEAR(reportdate)) END AS financial_year
FROM T_bankreport
GROUP BY financial_year";
$query = $this->db->query($sql);
return $query->result();
}
function bankstatement($fdate,$tdate,$fa,$aa){
$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 br.reportdate !=0 ";
if ($fa and $aa != ''){
$sql.=" and (reportdate >= '".$fa."-04-01' and reportdate<= '".$aa."-03-31')";
}
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."'";
}
$sql.=" group by(br.ID) ";
$sql.=" ORDER BY br.ID+0 DESC ";
$query = $this->db->query($sql);
return $query->result();
}
function debitbankstatemet($Supplierid,$fdate,$tdate)
{
$status='ST057';
//echo $tdate;
//die();
//$Supplierid;
$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_in('POM.Status',[ST044,ST056]);
$this->db->where('POM.Paymentstatus !=','ST057');
//$this->db->or_where('POM.Status',ST056);
$this->db->where('POM.PODate BETWEEN "'. date('Y-m-d', strtotime($fdate)). '" and "'. date('Y-m-d', strtotime($tdate)).'"');
$this->db->or_where('supp.SupplierID',$Supplierid);
$this->db->group_by('POM.PONO');
$query = $this->db->get();
return $query->result();
}
function bankinvoice($Customer,$fdate,$tdate)
{
// $status='ST065';
$this->db->distinct();
$this->db->select('iva.invoice_id,iva.invoice_total,iv.invoice_date_created,iv.invoice_number,iva.invoice_paid,ic.client_name,BI.balancetoreceived,BI.amountreceived');
$this->db->from ('ip_invoice_amounts iva');
$this->db->join ('ip_invoices iv','iva.invoice_id = iv.invoice_id');
$this->db->join ('ip_clients ic','iv.client_id = ic.client_id','left');
$this->db->join ('T_Bankinvoicereport BI',' iv.invoice_number =BI.invoiceno','left');
//$this->db->where('iva.receivedstatus !=','ST065');
$this->db->where('iv.invoice_status_id','2');
$this->db->where('iv.receivedstatus !=','ST065');
$this->db->where('ic.client_id',$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('bp.mid,bp.Podate,bp.PONO,bp.Suppliername,bp.Totalpoamount,
bp.Balancetopay,bp.Amountpaid,bu.FilePath');
$this->db->from ('T_Bankmappingpo bp');
$this->db->join ('T_PurchaseOrder_BillUpload bu','bu.PONO = bp.PONO','left');
$this->db->where('mid',$bankid);
//$this->db->group_by('PONO');
$query = $this->db->get();
return $query->result();
}
function debitpolistfilter($SupplierName,$fdate,$tdate)
{
$this->db->select('bm.mid,bm.Podate,bm.PONO,bm.Suppliername,bm.Totalpoamount,
bm.Balancetopay,bm.Amountpaid');
$this->db->from ('T_Bankmappingpo bm');
$this->db->join ('T_SupplierDetailsN sd','sd.SupplierName = bm.Suppliername','left');
if($fdate!='' && $tdate!='')
{
$this->db->where('bm.Podate BETWEEN "'. date('Y-m-d', strtotime($fdate)). '" and "'. date('Y-m-d', strtotime($tdate)).'"');
}
if($SupplierName!='')
{
$this->db->where('sd.SupplierID',$SupplierName);
}
// $this->db->where('mid',$bankid);
$this->db->group_by('PONO');
$query = $this->db->get();
return $query->result();
}
function creditinvoicelist($bankid)
{
$this->db->select('indate,invoiceno,customername,totinvoiceamount,bankid,
balancetoreceived,amountreceived');
$this->db->from ('T_Bankmappingiv');
$this->db->where('bankid',$bankid);
//$this->db->group_by('invoiceno');
$query = $this->db->get();
return $query->result();
}
function creditinvoicelistfilter($Customer,$fdate,$tdate)
{
$this->db->select('bm.indate,bm.invoiceno,bm.customername,bm.totinvoiceamount,bm.bankid,
bm.balancetoreceived,bm.amountreceived');
$this->db->from ('T_Bankmappingiv bm');
$this->db->join ('ip_clients ic','ic.client_name = bm.customername','left');
if($fdate!='' && $tdate!='')
{
$this->db->where('bm.indate BETWEEN "'. date('Y-m-d', strtotime($fdate)). '" and "'. date('Y-m-d', strtotime($tdate)).'"');
}
if($Customer!='')
{
$this->db->where('ic.client_id',$Customer);
}
//$this->db->group_by('invoiceno');
$query = $this->db->get();
return $query->result();
}
//for cashbook edit screen and update bankreport//
function invoiceamonut($bankid)
{
$this->db->select('sum(amountreceived)as amountreceived');
$this->db->from ('T_Bankmappingiv');
$this->db->where('bankid',$bankid);
//$this->db->group_by('invoiceno');
$query = $this->db->get();
return $query->result();
}
//for cashbook edit screen and update bankreport//
function poamonut($bankid)
{
$this->db->select('sum(Amountpaid)as amountpaid');
$this->db->from ('T_Bankmappingpo');
$this->db->where('mid',$bankid);
//$this->db->group_by('invoiceno');
$query = $this->db->get();
return $query->result();
}
function cashbookamount($bankid)
{
$this->db->select('sum(total)as total');
$this->db->from ('t_income_expense');
$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('ie.date,ie.bankid,ie.cashtype,ie.amounttype,ie.total,ac.name,totalbankamount');
$this->db->from ('t_income_expense as ie');
$this->db->join ('t_accountcode ac ','ac.code = ie.account_code','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_Bankmappingiv as bmp');
$this->db->join('T_bankreport br','br.ID = bmp.bankid');
$this->db->where('invoiceno',$invno);
//$this->db->group_by('invoiceno');
$query = $this->db->get();
return $query->result();
}
function getsupplier()
{
$this->db->select('SupplierName,SupplierID');
$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 checkMerchant($mer){
$temp[] = '' ;
$this->db->distinct();
$this->db->select('SupplierID,SupplierName');
$this->db->from('T_SupplierDetailsN');
$this->db->like('SupplierName',$mer);
$query = $this->db->get();
$temparr[] = '' ;
foreach($query->result() as $arr){
$temparr[] = $arr->SupplierName;
}
$temp['suggestions'] = $temparr;
return $temp;
}
function getsupp_dtls($s){
$this->db->select('GSTNO');
$this->db->from('T_SupplierDetailsN');
$this->db->where('SupplierName',$s);
$r = $this->db->get();
return $r->result();
}
function getcustomer()
{
$this->db->select('client_name,client_id');
$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;
}
public function getpono($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)
{
// echo $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 poupdate($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_Bankmappingpo');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function received()
{
$this->db->select('*');
$this->db->from('T_Bankmappingiv');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function poamountstatus($pomaster,$pono)
{
//echo $pomaster;
//echo $pono;
$this->db->where('PONO', $pono);
$this->db->update('T_PurchaseOrder_Master',$pomaster);
$r = $this->db->affected_rows();
return $r;
}
function invoiceamountstatus($invoicemaster,$invid)
{
echo $invoicemaster;
$this->db->where('invoice_number',$invid);
$this->db->update('ip_invoices',$invoicemaster);
$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;
}
}
}
?>