ria/app/Models/Cashbook_model.php
2024-09-11 08:54:25 +05:30

2035 lines
63 KiB
PHP
Executable File

<?php
namespace App\Models;
use CodeIgniter\Model;
class Cashbook_model extends Model
{
function getAccounTypes()
{
$builder = $this->db->table('t_accountcode')->where('status', 1);
$r = $builder->get();
return $r->getResult();
}
function getAccountpay()
{
$builder = $this->db->table('t_accountcode')->where('type', 'PAYMENT');
$r = $builder->get();
return $r->getResult();
}
function getAccounTypes1()
{
$builder = $this->db->table('t_accountcode')->select('name,type');
$r = $builder->get();
return $r->getResult();
}
function saveIncomeExpense($data)
{
$builder = $this->db->table('t_income_expense');
$builder->insert($data);
$r = $this->db->affectedRows();
return $r;
}
// function addcashbook($bankcash1)
// {
// $builder = $this->db->table('t_bankmappingcashbook');
// $builder->insert($bankcash1);
// $r = $this->db->affectedRows();
// return $r;
// }
// function amountpaidcashbook()
// {
// $builder = $this->db->table('t_income_expense')
// ->select('t_accountcode.namea,total,cashtype,t_employee_details.FirstName,t_employee_details.LastName,t_income_expense.*')
// ->join('t_accountcode','t_income_expense.account_code=t_accountcode.code','left');
// ->join('tbl_users','t_income_expense.Created_By=tbl_users.userId','left');
// ->join('t_employee_details','tbl_users.EmpID=t_employee_details.EmpID','left');
// ->where('t_income_expense.IsActive',1);
// ->where('t_income_expense.account_code !=','ADV001');
// ->groupBy('t_income_expense.account_code');
// // ->orderBy("date","desc");
// $r =$builder->get();
// return $r->getResult();
// }
function getIncomeExpenseList($i = "")
{
// echo $i;
$builder = $this->db->table('t_income_expense')
->select('t_accountcode.name,cashtype,t_employee_details.FirstName,t_employee_details.LastName,t_income_expense.*')
->join('t_accountcode', 't_income_expense.account_code=t_accountcode.code', 'left')
->join('tbl_users', 't_income_expense.Created_By=tbl_users.userId', 'left')
->join('t_employee_details', 'tbl_users.EmpID=t_employee_details.EmpID', 'left')
->where('t_income_expense.IsActive', 1)
// ->where('t_income_expense.account_code !=','ADV001');
// ->where('t_income_expense.account_code !=','0013');
->orderBy("date", "desc");
if (!empty($i)) {
$builder->where('t_income_expense.id', $i);
}
$r = $builder->get();
return $r->getResult();
}
function getIncomeExpense($firstyear, $secondyear, $frmdt, $todt)
{
$builder = $this->db->table('t_income_expense')
->select('t_accountcode.name,cashtype,t_employee_details.FirstName,t_employee_details.LastName,t_income_expense.*')
->join('t_accountcode', 't_income_expense.account_code=t_accountcode.code', 'left')
->join('tbl_users', 't_income_expense.Created_By=tbl_users.userId', 'left')
->join('t_employee_details', 'tbl_users.EmpID=t_employee_details.EmpID', 'left')
->where('t_income_expense.IsActive', 1)
->where('t_income_expense.account_code !=', 'ADV001')
->where('t_income_expense.account_code !=', '0013');
if ($firstyear and $secondyear != '') {
$finyear = "t_income_expense.date >= '" . $firstyear . "-04-01' and t_income_expense.date <= '" . $secondyear . "-03-31'";
$builder->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 . "'";
$builder->where($date);
}
$builder->orderBy("date", "desc");
$r = $builder->get();
return $r->getResult();
}
function getAdvanceList($i = "")
{
// echo $i;
$builder = $this->db->table('t_income_expense')
->select('t_accountcode.name,cashtype,t_employee_details.FirstName,t_employee_details.LastName,t_income_expense.*')
->join('t_accountcode', 't_income_expense.account_code=t_accountcode.code', 'left')
->join('tbl_users', 't_income_expense.Created_By=tbl_users.userId', 'left')
->join('t_employee_details', 'tbl_users.EmpID=t_employee_details.EmpID', 'left')
->where('t_income_expense.IsActive', 1)
->where('t_income_expense.account_code', 'ADV001')
->orWhere('t_income_expense.account_code', '0013')
->orderBy("date", "desc");
if (!empty($i)) {
$builder->where('t_income_expense.id', $i);
}
$r = $builder->get();
return $r->getResult();
}
function getAdvance($firstyear, $secondyear, $frmdt, $todt)
{
$builder = $this->db->table('t_income_expense')
->select('t_accountcode.name,cashtype,t_employee_details.FirstName,t_employee_details.LastName,t_income_expense.*')
->join('t_accountcode', 't_income_expense.account_code=t_accountcode.code', 'left')
->join('tbl_users', 't_income_expense.Created_By=tbl_users.userId', 'left')
->join('t_employee_details', 'tbl_users.EmpID=t_employee_details.EmpID', 'left')
->where('t_income_expense.IsActive', 1)
->where('t_income_expense.account_code', 'ADV001')
->orWhere('t_income_expense.account_code', '0013');
if ($firstyear and $secondyear != '') {
$finyear = "t_income_expense.date >= '" . $firstyear . "-04-01' and t_income_expense.date <= '" . $secondyear . "-03-31'";
$builder->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 . "'";
$builder->where($date);
}
$builder->orderBy("date", "desc");
$r = $builder->get();
return $r->getResult();
}
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->getResult();
}
function getCompany()
{
$builder = $this->db->table('t_company_details');
$query = $builder->get();
return $query->getResult();
}
function getAccounutInfo($i)
{
$builder = $this->db->table('t_income_expense')
->select('t_accountcode.name,t_income_expense.*')
->join('t_accountcode', 't_income_expense.account_code=t_accountcode.code')
->orderBy("date", "desc");
//$this->db->where('t_income_expense.id')
$r = $builder->get();
return $r->getResult();
}
function Selectcash()
{
$builder = $this->db->table('t_accountcode')->select('*');
$query = $builder->get();
$result = $query->getResult();
return $result;
}
function Selectadvance($i = "")
{
// echo $i;
$builder = $this->db->table('t_income_expense')
->select('t_supplierdetailsn.SupplierName,t_accountcode.name,cashtype,t_employee_details.FirstName,t_employee_details.LastName,t_income_expense.*')
->join('t_accountcode', 't_income_expense.account_code=t_accountcode.code', 'left')
->join('tbl_users', 't_income_expense.Created_By=tbl_users.userId', 'left')
->join('t_employee_details', 'tbl_users.EmpID=t_employee_details.EmpID', 'left')
->join('t_supplierdetailsn', 't_supplierdetailsn.SupplierID=t_income_expense.Supplier_id')
->orderBy("date", "desc")
->whereIn('t_accountcode.code', [AReceipt, Apayment]);
if (!empty($i)) {
$builder->where('t_income_expense.id', $i);
}
$r = $builder->get();
return $r->getResult();
}
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));
//echo $sql;
return $query->getResult();
}
function deletefile($cashid)
{
//echo $cashid;
$sql = "UPDATE t_income_expense SET document = NULL
WHERE id = ?";
$query = $this->db->query($sql, array($cashid));
//echo $sql;
$r = $this->db->affectedRows();
return $r;
}
function updatedepartment($updateaccount, $id1)
{
$this->db->table('t_income_expense')
->where('id', $id1)
->update($updateaccount);
$res = $this->db->affectedRows();
return $res;
}
function bankfile($FileDetails)
{
$builder = $this->db->table('T_bankingfile');
$builder->insert($FileDetails);
$res = $this->db->affectedRows();
return $res;
}
function bankfiledata($filedataupload)
{
$builder = $this->db->table('t_bankreport')
->select('reportdate,Narration,Balance')
->where('reportdate', $filedataupload['reportdate'])
->where('Narration', $filedataupload['Narration'])
->where('Balance', $filedataupload['Balance']);
$query = $builder->get();
if ($query->getNumRows()() > 0) {
return true;
} else {
$builder = $this->db->table('t_bankreport');
$builder->insert($filedataupload);
$res = $this->db->affectedRows();
return $res;
}
}
function balance($balance)
{
$builder = $this->db->table('t_bankbalance');
$builder->insert($balance);
}
function getbalancedetails()
{
$subquery = "SELECT openingbalance,closingbalance FROM t_bankbalance WHERE balance_keyid in (SELECT MAX(balance_keyid) FROM t_bankbalance)";
$query = $this->db->query($subquery);
return $query->getResult();
}
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->getResult();
}
function report_amountpaid()
{
$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->getResult();
}
function report_cashbook()
{
$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->getResult();
}
function report_finyearunpaid()
{
$sql = "SELECT
CASE WHEN MONTH(MaterialRcvdDate)>=4 THEN
concat(YEAR(MaterialRcvdDate), '-',YEAR(MaterialRcvdDate)+1)
ELSE concat(YEAR(MaterialRcvdDate)-1,'-', YEAR(MaterialRcvdDate)) END AS financial_year
FROM t_igr_master
GROUP BY financial_year";
$query = $this->db->query($sql);
return $query->getResult();
}
function report_finyearamountreceived()
{
$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->getResult();
}
function report_finyearamountunreceived()
{
$sql = "SELECT
CASE WHEN MONTH(invoice_date_created)>=4 THEN
concat(YEAR(invoice_date_created), '-',YEAR(invoice_date_created)+1)
ELSE concat(YEAR(invoice_date_created)-1,'-', YEAR(invoice_date_created)) END AS financial_year
FROM ip_invoices
GROUP BY financial_year";
$query = $this->db->query($sql);
return $query->getResult();
}
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->getResult();
}
function cleareddebitbalance()
{
$sql = "SELECT SUM(Balancetocleared) as debit FROM t_bankreport where Clearbalance >'0'";
$query = $this->db->query($sql);
return $query->getResult();
}
function clearedcreditbalance()
{
$sql = "SELECT SUM(cbalancetocleared) as credit FROM t_bankreport where cclearbalance >'0'";
$query = $this->db->query($sql);
return $query->getResult();
}
function suppliertotalfilter($fa, $aa, $m, $fdate, $tdate)
{
$sql = "select pono,igrn,potype,date_format(created_date,'%d-%m-%Y') as created_date,date_format(materialrcvddate,'%d-%m-%Y') as materialrcvddate,supplier_name,sid,
sum(total) as total,file,ifile
from igr
where status != 'ST030' and PaymentStatus ='ST072'";
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$sql .= " and (MaterialRcvdDate >= '" . $fa . "-04-01' and MaterialRcvdDate <= '" . $aa . "-03-31')";
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$sql .= "and monthname(MaterialRcvdDate) = '" . $m . "'";
}
if ($fdate and $tdate != '') {
$fromd = date("Y-m-d", strtotime($fdate));
$tod = date("Y-m-d", strtotime($tdate));
$sql .= "and date(MaterialRcvdDate) >= '" . $fromd . "'
and date(MaterialRcvdDate) <= '" . $tod . "'";
}
$sql .= "group by sid";
$query = $this->db->query($sql);
return $query->getResult();
}
function amountunpaid($supplierid1, $fa, $aa, $m, $fdate, $tdate)
{
$sql = "select pono,igrn,potype,date_format(created_date,'%d-%m-%Y') as created_date,date_format(materialrcvddate,'%d-%m-%Y') as materialrcvddate,supplier_name,sid,
sum(total) as total,file,ifile
from igr
where status != 'ST030' and PaymentStatus = 'ST072' and sid='" . $supplierid1 . "'";
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$sql .= " and (MaterialRcvdDate >= '" . $fa . "-04-01' and MaterialRcvdDate <= '" . $aa . "-03-31')";
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$sql .= "and monthname(MaterialRcvdDate) = '" . $m . "'";
}
if ($fdate and $tdate != '') {
$fromd = date("Y-m-d", strtotime($fdate));
$tod = date("Y-m-d", strtotime($tdate));
$sql .= "and date(MaterialRcvdDate) >= '" . $fromd . "'
and date(MaterialRcvdDate) <= '" . $tod . "'";
}
$sql .= "group by pono,igrn";
$query = $this->db->query($sql);
return $query->getResult();
}
function amountunpaidfilter($sd, $fa, $aa, $m, $fdate, $tdate)
{
$sql = "select pono,igrn,potype,date_format(created_date,'%d-%m-%Y') as created_date,date_format(materialrcvddate,'%d-%m-%Y') as materialrcvddate,supplier_name,sid,
sum(total) as total,file,ifile
from igr
where status != 'ST030' and PaymentStatus ='ST072' and sid='" . $sd . "'";
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$sql .= " and (MaterialRcvdDate >= '" . $fa . "-04-01' and MaterialRcvdDate <= '" . $aa . "-03-31')";
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$sql .= "and monthname(MaterialRcvdDate) = '" . $m . "'";
}
if ($fdate and $tdate != '') {
$fromd = date("Y-m-d", strtotime($fdate));
$tod = date("Y-m-d", strtotime($tdate));
$sql .= "and date(MaterialRcvdDate) >= '" . $fromd . "'
and date(MaterialRcvdDate) <= '" . $tod . "'";
}
$sql .= "group by pono,igrn";
$query = $this->db->query($sql);
return $query->getResult();
}
function bankinvoice($Customer, $fdate, $tdate)
{
$builder = $this->db->table('ip_invoice_amounts iva')
->select('iva.invoice_id,iva.invoice_total,iv.invoice_date_created,iv.invoice_number,iva.invoice_paid,ic.client_name,ic.client_id,BI.balancetoreceived,BI.amountreceived')
->join('ip_invoices iv', 'iva.invoice_id = iv.invoice_id')
->join('ip_clients ic', 'iv.client_id = ic.client_id', 'left')
->join('t_bankinvoicereport BI', 'iv.invoice_number = BI.invoiceno and BI.IsActive= 1', 'left')
->where('iv.invoice_status_id', '2')
->where('iv.receivedstatus !=', 'ST065');
// ->where('BI.IsActive',1);
if ($fdate and $tdate != '') {
$fromdate = date("Y-m-d", strtotime($fdate));
$todate = date("Y-m-d", strtotime($tdate));
$date = "date(iv.invoice_date_created) >= '" . $fromdate . "'
and date(iv.invoice_date_created) <= '" . $todate . "'";
$builder->where($date);
}
if ($Customer != '') {
$builder->where('ic.client_id', $Customer);
}
$builder->groupBy('iva.invoice_id');
$query = $builder->get();
return $query->getResult();
}
function debitbankstatemet($SupplierName, $fdate, $tdate)
{
$sql = "select pono,igrn,potype,date_format(created_date,'%d-%m-%Y') as created_date,date_format(materialrcvddate,'%d-%m-%Y') as materialrcvddate,supplier_name,sid,Balancetopay,Amountpaid,
sum(total) as total,file,ifile
from bankdebit
where status != 'ST030' and PaymentStatus != 'ST070'";
if ($SupplierName != '') {
$sql .= "and supplier_name = '" . $SupplierName . "'";
}
if ($fdate and $tdate != '') {
$fromd = date("Y-m-d", strtotime($fdate));
$tod = date("Y-m-d", strtotime($tdate));
$sql .= "and date(MaterialRcvdDate) >= '" . $fromd . "'
and date(MaterialRcvdDate) <= '" . $tod . "'";
}
$sql .= "group by igrn";
$query = $this->db->query($sql);
return $query->getResult();
}
function supplierledger($suppliername, $fdate, $tdate, $fa, $aa, $m)
{
$sql = "select date,igrn,ID,narration,sid,supplier_name,amountpaid,
sum(total) as total
from ledgersupplier
where ID != 'null' and Status != 'ST030'";
if ($suppliername != '') {
$sql .= "and sid = '" . $suppliername . "'";
}
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$sql .= " and (date >= '" . $fa . "-04-01' and date <= '" . $aa . "-03-31')";
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$sql .= "and monthname(date) = '" . $m . "'";
}
if ($fdate and $tdate != '') {
$fromd = date("Y-m-d", strtotime($fdate));
$tod = date("Y-m-d", strtotime($tdate));
$sql .= "and date(date) >= '" . $fromd . "'
and date(date) <= '" . $tod . "'";
}
$sql .= "group by date asc";
$query = $this->db->query($sql);
return $query->getResult();
}
function customerledger($customer, $fdate, $tdate, $fa, $aa, $m)
{
$sql = "select date,id,amount,invoice_number,invoice_status_id,customername,customerid,payment
from ledgercustomer
where invoice_number != '' ";
if ($customer != '') {
$sql .= "and customerid = '" . $customer . "'";
}
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$sql .= " and (date >= '" . $fa . "-04-01' and date <= '" . $aa . "-03-31')";
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$sql .= "and monthname(date) = '" . $m . "'";
}
if ($fdate and $tdate != '') {
$fromd = date("Y-m-d", strtotime($fdate));
$tod = date("Y-m-d", strtotime($tdate));
$sql .= "and date(date) >= '" . $fromd . "'
and date(date) <= '" . $tod . "'";
}
$sql .= "order by date asc";
$query = $this->db->query($sql);
return $query->getResult();
}
function openingbalance($customer, $fdate, $tdate, $fa, $aa, $m)
{
$sql = "select date as date,sum(payment) as payment
from ledgercustomer
where invoice_number != 'null' ";
if ($customer != '') {
$sql .= "and customerid = '" . $customer . "'";
}
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$sql .= " and (date >= '" . $fa . "-04-01' and date <= '" . $aa . "-03-31')";
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$sql .= "and monthname(date) >= '" . $m . "'";
}
if ($fdate and $tdate != '') {
$fromd = date("Y-m-d", strtotime($fdate));
$tod = date("Y-m-d", strtotime('01-04-2018'));
$sql .= "and date(date) >= '" . $tod . "'
and date(date) <= '" . $fromd . "'";
//$sql.="and date('2018-04-01') <= '".$fromd."'";
}
$query = $this->db->query($sql);
return $query->getResult();
}
function openingbalancesupplier($customer, $fdate, $tdate, $fa, $aa, $m)
{
$sql = "select date as date,sum(amountpaid) as amountpaid
from ledgersupplier
where ID != 'null' ";
if ($customer != '') {
$sql .= "and customerid = '" . $customer . "'";
}
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$sql .= " and (date >= '" . $fa . "-04-01' and date <= '" . $aa . "-03-31')";
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$sql .= "and monthname(date) >= '" . $m . "'";
}
if ($fdate and $tdate != '') {
$fromd = date("Y-m-d", strtotime($fdate));
$tod = date("Y-m-d", strtotime('01-04-2018'));
$sql .= "and date(date) >= '" . $tod . "'
and date(date) <= '" . $fromd . "'";
//$sql.="and date('2018-04-01') <= '".$fromd."'";
}
$query = $this->db->query($sql);
return $query->getResult();
}
function receivedamount($Customer, $fdate, $tdate)
{
// $status='ST065';
$builder = $this->db->table('t_bankinvoicereport BI')
// ->distinct()
->select('BI.balancetoreceived,BI.amountreceived');
//->where('BI.IsActive',1);
if ($fdate and $tdate != '') {
$fromdate = date("Y-m-d", strtotime($fdate));
$todate = date("Y-m-d", strtotime($tdate));
$date = "date(BI.BankDate) >= '" . $fromdate . "'
and date(BI.BankDate) <= '" . $todate . "'";
$builder->where($date);
}
if ($Customer != '') {
$builder->where('BI.client_id', $Customer);
}
$builder->groupBy('BI.invoiceno');
//$builder->where('inc.type','PAYMENT');
$query = $builder->get();
return $query->getResult();
}
function receiptdata()
{
$builder = $this->db->table('t_income_expense inc')
->distinct()
->select('inc.type,inc.date,inc.account_code,inc.towhom,inc.total')
->where('inc.type', 'RECEIPT');
$query = $builder->get();
return $query->getResult();
}
function paymentdata()
{
$builder = $this->db->table('t_income_expense inc')->distinct()
->select('inc.type,inc.date,inc.account_code,inc.towhom,inc.total');
//->groupBy('inc.account_code')
//->where('inc.type','PAYMENT')
$query = $builder->get();
return $query->getResult();
}
function debitimage($igrno, $pono)
{
$builder = $this->db->table('t_purchaseorder_billupload')
->select('*')
->where('IGRNO != "" ')
->where('IGRNO', $igrno)
->orWhere('PONO', $pono);
$query = $builder->get();
$result = $query->getResult();
// print_r($result);die;
return $result;
}
function debitpolistfilter($supplierID, $fa, $aa, $m, $fdate, $tdate)
{
$builder = $this->db->table('t_bankmappingpo bm')->select('bm.id,bm.mid,bm.PONO,bm.Suppliername,bm.Totalpoamount,bm.Podate,bm.BankDate,
bm.Balancetopay,bm.Amountpaid,bm.IGRNO,bm.IGRLineItemNo,br.Balancetocleared,br.Clearbalance,
inward.FilePath as igrfile,bu.FilePath as pofile')
// ->join('t_igr_details igr','igr.IGRItemNo=bm.IGRLineItemNo')
->join('t_inwardgateregister_fileupload inward', 'inward.IGRNO =bm.IGRNO', 'left')
->join('t_purchaseorder_billupload bu', 'bm.PONO=bu.PONO', 'left')
->join('t_bankreport br', 'br.ID=bm.mid', 'left')
->where('bm.SupplierID', $supplierID)
->where('bm.IsActive', 1)
// ->where('igr.BankStatus !=',ST072)
->orderBy('bm.IGRNO');
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(bm.BankDate >= '" . $fa . "-04-01' and bm.BankDate <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//->where('MONTH(pel.tgl_pembelian)',$bulan);
$month = "monthname(bm.BankDate) = '" . $m . "'";
$builder->where($month);
// $sql.="and monthname(bm.Podate) = '".$m."'";
}
if ($fdate and $tdate != '') {
$fromdate = date("Y-m-d", strtotime($fdate));
$todate = date("Y-m-d", strtotime($tdate));
$date = "date(bm.BankDate) >= '" . $fromdate . "'
and date(bm.BankDate) <= '" . $todate . "'";
$builder->where($date);
}
$builder->groupBy('bm.id');
$query = $builder->get();
return $query->getResult();
}
function igrmastersingle($igrno, $pono)
{
$builder = $this->db->table('t_igr_master')->distinct()
->select('IGRNO,file,PONO as pono');
if (!empty($igrno) && !empty($pono)) {
$builder->where('PONO', $pono);
$builder->where('IGRNO', $igrno);
} else if (!empty($pono)) {
$builder->where('PONO', $pono);
$builder->where('IGRNO != ""');
} else {
$builder->where('IGRNO', $igrno);
}
$query = $builder->get();
return $query->getResult();
}
function igrmastermultiple($igrno, $pono)
{
$builder = $this->db->table('t_inwardgateregister_fileupload')->distinct()
->select('BillNo,IGRNO,FilePath,PONO');
if (!empty($igrno) && !empty($pono)) {
$builder->where('PONO', $pono);
$builder->where('IGRNO', $igrno);
} else if (!empty($pono)) {
$builder->where('PONO', $pono);
$builder->where('IGRNO != ""');
} else {
$builder->where('IGRNO', $igrno);
}
$query = $builder->get();
return $query->getResult();
}
function igrmastermultiple1($igrno, $pono)
{
$builder = $this->db->table('t_inwardgateregister_fileupload')->select('BillNo,IGRNO,FilePath,PONO')
// if(!empty($igrno) && !empty($pono)){
// ->where('PONO',$pono);
->where('IGRNO', $igrno);
// }else if(!empty($pono)){
// ->where('PONO',$pono);
// ->where('IGRNO != ""');
// }else{
//->where('IGRNO',$IGRNO);
// }
$query = $builder->get();
return $query->getResult();
}
function debitpolist($bankid)
{
$builder = $this->db->table('t_bankmappingpo bp')->select('bp.id,bp.mid,igrm.MaterialRcvdDate,bp.PONO,bp.Suppliername,bp.Totalpoamount,br.Debit,bp.Balancetopay,bp.Amountpaid,bp.IGRNO,bp.IGRLineItemNo,igrm.file,bu.FilePath,inward.FilePath as Fpath,bp.IsActive')
->join('t_igr_master igrm', 'bp.IGRNO = igrm.IGRNO', 'left')
->join('t_purchaseorder_billupload bu', 'bu.PONO = bp.PONO', 'left')
->join('t_inwardgateregister_fileupload inward', 'inward.IGRNO =igrm.IGRNO', 'left')
->join('t_bankreport br', 'br.ID=bp.mid')
->where('bp.IsActive', 1)
->where('bp.mid', (int)$bankid)
// ->where('igrde.BankStatus !=','ST072');
->groupBy('bp.id')
->orderBy('bp.IGRNO');
$query = $builder->get();
return $query->getResult();
}
function creditinvoicelist($bankid)
{
$builder = $this->db->table('t_bankmappingiv bm')->select('bm.indate,bm.invoiceno,bm.customername,bm.totinvoiceamount,bm.bankid,
bm.balancetoreceived,bm.amountreceived,bm.ID,br.Credit,br.cclearbalance,br.cbalancetocleared,bm.IsActive')
->join('t_bankreport br', 'br.ID=bm.bankid')
->where('bm.bankid', (int)$bankid)
->where('bm.IsActive', 1)
->groupBy('bm.ID');
//->groupBy('invoiceno');
$query = $builder->get();
//print_r($query);
return $query->getResult();
}
function creditinvoicelistfilter($clientid, $fdate, $tdate, $fa, $aa, $m)
{
$builder = $this->db->table('t_bankmappingiv bm')
->select('bm.ID,bm.indate,bm.invoiceno,bm.customername,bm.totinvoiceamount,bm.bankid,
bm.balancetoreceived,bm.amountreceived,br.cclearbalance,br.cbalancetocleared,bm.BankDate')
->join('ip_invoices iv', 'iv.invoice_number=bm.invoiceno')
->join('ip_clients ic', 'ic.client_name = bm.customername', 'left')
->join('t_bankreport br', 'br.ID = bm.bankid')
->where('bm.IsActive', 1)
->where('bm.customerid', $clientid)
->where('iv.receivedstatus !=', 'ST066');
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(bm.BankDate >= '" . $fa . "-04-01' and bm.BankDate <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$month = "monthname(bm.BankDate) = '" . $m . "'";
$builder->where($month);
}
if ($fdate != '' && $tdate != '') {
$builder->where('bm.BankDate BETWEEN "' . format_date($fdate) . '" and "' . format_date($tdate) . '"');
}
//$builder->groupBy('invoiceno');
$query = $builder->get();
return $query->getResult();
}
function uncreditinvoicelistfilter($client, $fdate, $tdate, $fa, $aa, $m)
{
$builder = $this->db->table('ip_invoice_amounts iva')->select('iva.invoice_id,iva.invoice_total,iv.invoice_date_created,iv.invoice_number,iva.invoice_paid,ic.client_id,ic.client_name,BI.balancetoreceived,BI.amountreceived')
->join('ip_invoices iv', 'iva.invoice_id = iv.invoice_id')
->join('ip_clients ic', 'iv.client_id = ic.client_id', 'left')
->join('t_bankinvoicereport BI', ' iv.invoice_number =BI.invoiceno', 'left')
->where('iv.invoice_status_id', '2')
->where('iv.receivedstatus', 'ST066')
->where('ic.client_id', $client);
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(iv.invoice_date_created >= '" . $fa . "-04-01' and iv.invoice_date_created <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$month = "monthname(iv.invoice_date_created) = '" . $m . "'";
$builder->where($month);
}
if ($fdate != '' && $tdate != '') {
$builder->where('iv.invoice_date_created BETWEEN "' . format_date($fdate) . '" and "' . format_date($tdate). '"');
}
// ->groupBy('iva.invoice_id');
//->where('inc.type','PAYMENT');
$query = $builder->get();
return $query->getResult();
}
//for cashbook edit screen and update bankreport//
function invoiceamonut($bankid)
{
$builder = $this->db->table('t_bankmappingiv bm')->select('sum(bm.amountreceived)as amountreceived')
->where('bm.bankid', (int)$bankid)
->where('bm.IsActive', 1);
//->groupBy('bm.ID');
$query = $builder->get();
return $query->getResult();
}
//for cashbook edit screen and update bankreport//
function poamonut($bankid)
{
$builder = $this->db->table('t_bankmappingpo')
->select('sum(Amountpaid)as amountpaid')
->where('mid', $bankid)
->where('IsActive', 1);
//->groupBy('invoiceno');
$query = $builder->get();
return $query->getResult();
}
function cashbookamount($bankid)
{
$builder = $this->db->table('t_income_expense')
->select('sum(total)as total')
->where('bankid', $bankid)
->where('IsActive', 1);
//->groupBy('invoiceno');
$query = $builder->get();
return $query->getResult();
}
function mappingcash($accountcode, $fa, $aa, $m, $fdate, $tdate)
{
$builder = $this->db->table('t_income_expense as ie')
->select('ie.date,ie.bankid,ie.cashtype,ie.amounttype,ie.total,ac.name,totalbankamount,ie.id,sd.SupplierName')
->join('t_accountcode ac ', 'ac.code = ie.account_code', 'left')
->join('t_supplierdetailsn sd ', 'sd.SupplierID = ie.Supplier_id', 'left')
->where('ie.account_code', $accountcode)
->where('ie.amounttype', 'DEBIT')
->where('ie.IsActive', 1);
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(ie.date >= '" . $fa . "-04-01' and ie.date <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//->where('MONTH(pel.tgl_pembelian)',$bulan);
$month = "monthname(ie.date) = '" . $m . "'";
$builder->where($month);
// $sql.="and monthname(bm.Podate) = '".$m."'";
}
if ($fdate and $tdate != '') {
$fromdate = date("Y-m-d", strtotime($fdate));
$todate = date("Y-m-d", strtotime($tdate));
$date = "date(ie.date) >= '" . $fromdate . "'
and date(ie.date) <= '" . $todate . "'";
$builder->where($date);
}
$query = $builder->get();
return $query->getResult();
}
function mappingcashbankid($bankid)
{
$builder = $this->db->table('t_income_expense as ie')
->select('ie.date,ie.bankid,ie.cashtype,ie.amounttype,ie.total,ac.name,totalbankamount,ie.id')
->join('t_accountcode ac ', 'ac.code = ie.account_code', 'left')
->where('ie.bankid', (int)$bankid)
->where('ie.amounttype', 'DEBIT')
->where('IsActive', 1);
//->groupBy('mid');
$query = $builder->get();
return $query->getResult();
}
function mappingcashcreditbankid($bankid)
{
$builder = $this->db->table('t_income_expense as ie')
->select('ie.date,ie.bankid,ie.cashtype,ie.amounttype,ie.total,ac.name,totalbankamount,ie.id')
->join('t_accountcode ac ', 'ac.code = ie.account_code', 'left')
->where('ie.bankid', (int)$bankid)
->where('ie.amounttype', 'CREDIT')
->where('ie.IsActive', 1);
//->groupBy('mid');
$query = $builder->get();
return $query->getResult();
}
function mappingcashreceived($accountcode, $fa, $aa, $m, $fdate, $tdate)
{
$builder = $this->db->table('t_income_expense as ie')
->select('ie.date,ie.bankid,ie.cashtype,ie.amounttype,ie.total,ac.name,totalbankamount,ie.id,sd.SupplierName')
->join('t_accountcode ac ', 'ac.code = ie.account_code', 'left')
->join('t_supplierdetailsn sd ', 'sd.SupplierID = ie.Supplier_id', 'left')
->where('ie.account_code', $accountcode)
->where('ie.amounttype', 'CREDIT')
->where('ie.IsActive', 1);
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(ie.date >= '" . $fa . "-04-01' and ie.date <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//->where('MONTH(pel.tgl_pembelian)',$bulan);
$month = "monthname(ie.date) = '" . $m . "'";
$builder->where($month);
// $sql.="and monthname(bm.Podate) = '".$m."'";
}
if ($fdate and $tdate != '') {
$fromdate = date("Y-m-d", strtotime($fdate));
$todate = date("Y-m-d", strtotime($tdate));
$date = "date(ie.date) >= '" . $fromdate . "'
and date(ie.date) <= '" . $todate . "'";
$builder->where($date);
}
//->groupBy('mid');
$query = $builder->get();
return $query->getResult();
}
function mappingcashfilter($accountcode, $fa, $aa, $m, $fdate, $tdate)
{
$builder = $this->db->table('t_income_expense as ie')
->select('ie.date,ie.bankid,ie.cashtype,ie.amounttype,ie.total,ac.name,totalbankamount,ie.id')
->join('t_accountcode ac ', 'ac.code = ie.account_code', 'left')
->where('ie.account_code', $accountcode)
->where('ie.amounttype', 'DEBIT')
->where('IsActive', 1);
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(ie.date >= '" . $fa . "-04-01' and ie.date <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//->where('MONTH(pel.tgl_pembelian)',$bulan);
$month = "monthname(ie.date) = '" . $m . "'";
$builder->where($month);
// $sql.="and monthname(bm.Podate) = '".$m."'";
}
if ($fdate and $tdate != '') {
$fromdate = date("Y-m-d", strtotime($fdate));
$todate = date("Y-m-d", strtotime($tdate));
$date = "date(ie.date) >= '" . $fromdate . "'
and date(ie.date) <= '" . $todate . "'";
$builder->where($date);
}
$query = $builder->get();
return $query->getResult();
}
function mappingcashreceivedfilter($accountcode, $fa, $aa, $m, $fdate, $tdate)
{
$builder = $this->db->table('t_income_expense as ie')
->select('ie.date,ie.bankid,ie.cashtype,ie.amounttype,ie.total,ac.name,totalbankamount,ie.id')
->join('t_accountcode ac ', 'ac.code = ie.account_code', 'left')
->where('ie.account_code', $accountcode)
->where('ie.amounttype', 'CREDIT')
->where('IsActive', 1);
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(ie.date >= '" . $fa . "-04-01' and ie.date <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//->where('MONTH(pel.tgl_pembelian)',$bulan);
$month = "monthname(ie.date) = '" . $m . "'";
$builder->where($month);
// $sql.="and monthname(bm.Podate) = '".$m."'";
}
if ($fdate and $tdate != '') {
$fromdate = date("Y-m-d", strtotime($fdate));
$todate = date("Y-m-d", strtotime($tdate));
$date = "date(ie.date) >= '" . $fromdate . "'
and date(ie.date) <= '" . $todate . "'";
$builder->where($date);
}
$query = $builder->get();
return $query->getResult();
}
function newcashbook()
{
$builder = $this->db->table('t_bankmappingcashbook')
->select('cdate,mid,btype,amount,boption,mappingamount,totalamount,amounttype,alreadycreditpaid');
//->where('mid',$bankid);
//->groupBy('mid');
$query = $builder->get();
return $query->getResult();
}
function debitlistpo($pono)
{
$builder = $this->db->table('t_bankmappingpo as bmp')
->select('bmp.mid,bmp.PONO,bmp.IGRLineItemNo,bmp.Amountpaid,br.Narration')
->join('t_bankreport br', 'br.ID = bmp.mid')
->where('bmp.PONO', $pono)
->where('bmp.IsActive', 1);
$query = $builder->get();
return $query->getResult();
}
function creditlistinv($invno)
{
$builder = $this->db->table('t_bankmappingiv as bmp')
->select('bmp.bankid,bmp.invoiceno,bmp.amountreceived,br.Narration')
->join('t_bankreport br', 'br.ID = bmp.bankid')
->where('invoiceno', $invno)
->where('bmp.IsActive', 1);
//->groupBy('invoiceno');
$query = $builder->get();
return $query->getResult();
}
function getsupplier()
{
$builder = $this->db->table('t_supplierdetailsn')->select('SupplierName,SupplierID');
//->join('t_accountcode','t_income_expense.account_code=t_accountcode.code')
//->where('t_income_expense.id')
$r = $builder->get();
return $r->getResult();
}
function checkMerchant($mer)
{
$temp[] = '';
$builder = $this->db->table('t_supplierdetailsn')
->distinct()
->select('SupplierID,SupplierName')
->like('SupplierName', $mer);
$query = $builder->get();
$temparr[] = '';
foreach ($query->getResult() as $arr) {
$temparr[] = $arr->SupplierName;
}
$temp['suggestions'] = $temparr;
return $temp;
}
function getsupp_dtls($s)
{
$builder = $this->db->table('t_supplierdetailsn')
->select('GSTNO')
->where('SupplierName', $s);
$r = $builder->get();
return $r->getResult();
}
function getcustomer()
{
$builder = $this->db->table('ip_clients')
->select('client_name,client_id');
//->join('t_accountcode','t_income_expense.account_code=t_accountcode.code')
//->where('t_income_expense.id')
$r = $builder->get();
return $r->getResult();
}
function invoicedata($invoicedata)
{
$builder = $this->db->table('t_bankinvoicereport');
$builder->insert($invoicedata);
// ->where('PONO',$pono);
$res = $this->db->affectedRows();
return $res;
}
function bankporeportdata($igrdata)
{
$builder = $this->db->table('t_bankporeport');
$builder->insert($igrdata);
$res = $this->db->affectedRows();
return $res;
}
// function invicedata($invoicedata)
// {
// $builder = $this->db->table('t_bankinvoicereport');
// $builder->insert($invoicedata);
// $res = $this->db->affectedRows();
// return $res;
// }
function mappingpo($igrdata1)
{
$builder = $this->db->table('t_bankmappingpo');
$builder->insert($igrdata1);
$res = $this->db->affectedRows();
return $res;
}
function mappinginvoice($invoicedata)
{
$builder = $this->db->table('t_bankmappingiv');
$builder->insert($invoicedata);
$res = $this->db->affectedRows();
return $res;
}
public function getigrno($igrno)
{
$builder = $this->db->table('t_bankporeport')
->select('igrno')
->where('IGRNO', $igrno);
$query = $builder->get();
return $query->getResult();
}
public function invoiceupdate($invid)
{
$builder = $this->db->table('t_bankinvoicereport')
->select('invoiceno')
->where('invoiceno', $invid);
$query = $builder->get();
return $query->getResult();
}
public function bankid($pono)
{
$builder = $this->db->table('t_bankporeport')
->select('PONO')
->where('PONO ', $pono);
$query = $builder->get();
return $query->getResult();
}
public function cashbankupdate($cashbookstatus, $bankid)
{
// echo $bankid;
$this->db->table('t_bankreport')
->where('ID', $bankid)
->update($cashbookstatus);
return TRUE;
}
function cashcreditupdate($cashbookstatus1, $bankid)
{
$this->db->table('t_bankreport')
->where('ID', $bankid)
->update($cashbookstatus1);
return TRUE;
}
public function bankupdate($bankdata, $bankid)
{
$this->db->table('t_bankreport')
->where('ID', $bankid)
->update($bankdata);
return TRUE;
}
public function bankcreditupdate($bankcreditdata, $bankid)
{
$this->db->table('t_bankreport')
->where('ID', $bankid)
->update($bankcreditdata);
return TRUE;
}
public function getearlyamount($igrno)
{
$builder = $this->db->table('t_bankporeport')
->select('Amountpaid')
->where('IGRNO ', $igrno);
$query = $builder->get();
return $query->getResult();
}
public function getearlyamountcredit($invid)
{
$builder = $this->db->table('t_bankinvoicereport')
->select('amountreceived')
->where('invoiceno ', $invid);
$query = $builder->get();
return $query->getResult();
}
public function getearlymappingiv($invid)
{
$builder = $this->db->table('t_bankmappingiv')
->select('sum(amountreceived) as amountreceived')
->where('invoiceno', $invid)
->where('IsActive', 1);
$query = $builder->get();
return $query->getResult();
}
public function getalreadypaid($bankid)
{
$builder = $this->db->table('t_bankreport')->select('Clearbalance')
->where('ID ', $bankid);
$query = $builder->get();
return $query->getResult();
}
public function getalreadyreceived($bankid)
{
$builder = $this->db->table('t_bankreport')->select('cclearbalance')
->where('ID ', $bankid);
$query = $builder->get();
return $query->getResult();
}
public function bankporeportupdate($igrdata, $igrno)
{
$this->db->table('t_bankporeport')
->where('IGRNO', $igrno)
->update($igrdata);
return TRUE;
}
public function invoiceupdate1($invoicedata, $invid)
{
//print_r($invoicedata);
//print_r($invid);
$this->db->table('t_bankinvoicereport')
->where('invoiceno', $invid)
->update($invoicedata);
return TRUE;
}
function paided($supplierid, $fa, $aa, $m, $fdate, $tdate)
{
$builder = $this->db->table('t_bankmappingpo bm')
->select('bm.id,bm.mid,bm.PONO,bm.Suppliername,bm.Totalpoamount,bm.Podate,bm.BankDate,
bm.Balancetopay,bm.Amountpaid,bm.IGRNO,bm.IGRLineItemNo,br.Balancetocleared,br.Clearbalance,
inward.FilePath as igrfile,bu.FilePath pofile')
//->join('t_igr_details igr','igr.IGRItemNo=bm.IGRLineItemNo')
->join('t_inwardgateregister_fileupload inward', 'inward.IGRNO =bm.IGRNO', 'left')
->join('t_purchaseorder_billupload bu', 'bm.PONO=bu.PONO', 'left')
->join('t_bankreport br', 'br.ID=bm.mid', 'left')
->where('bm.SupplierID', $supplierid)
->where('bm.IsActive', 1)
// ->where('igr.BankStatus !=',ST072);
->orderBy('bm.IGRNO');
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(bm.BankDate >= '" . $fa . "-04-01' and bm.BankDate <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//->where('MONTH(pel.tgl_pembelian)',$bulan);
$month = "monthname(bm.BankDate) = '" . $m . "'";
$builder->where($month);
// $sql.="and monthname(bm.Podate) = '".$m."'";
}
if ($fdate and $tdate != '') {
$fromdate = date("Y-m-d", strtotime($fdate));
$todate = date("Y-m-d", strtotime($tdate));
$date = "date(bm.BankDate) >= '" . $fromdate . "'
and date(bm.BankDate) <= '" . $todate . "'";
$builder->where($date);
}
$builder->groupBy('bm.id');
$query = $builder->get();
return $query->getResult();
}
function amountpaidsupplierwise()
{
$builder = $this->db->table('t_bankmappingpo bm')
->select('bm.id,bm.mid,bm.PONO,bm.Suppliername,bm.SupplierID,bm.Totalpoamount,bm.Podate,
bm.Balancetopay,sum(bm.Amountpaid) as Amountpaid,bm.IGRNO,bm.IGRLineItemNo')
//->join('t_igr_details igr','igr.IGRItemNo=bm.IGRLineItemNo')
->where('bm.IsActive', 1)
// ->where('igr.BankStatus !=',ST072)
->groupBy('bm.SupplierID');
$query = $builder->get();
return $query->getResult();
}
function amountpaidcashbook()
{
$builder = $this->db->table('t_income_expense tie')
->select('tac.name,sum(tie.total) as total,tie.account_code')
->join('t_accountcode tac', 'tac.code=tie.account_code')
->where('tie.amounttype', 'DEBIT')
->where('tie.cashtype', 'Bank')
->where('tie.IsActive', 1)
//->where('t_income_expense.account_code !=','ADV001');
->groupBy('tie.account_code');
$query = $builder->get();
return $query->getResult();
}
function amountreceivedcashbook()
{
$builder = $this->db->table('t_income_expense tie')
->select('tac.name,sum(tie.total)as total,tie.account_code')
->join('t_accountcode tac', 'tac.code=tie.account_code')
->where('tie.amounttype', 'CREDIT')
->where('tie.IsActive', 1)
//->where('t_income_expense.account_code !=','ADV001')
->groupBy('tie.account_code');
$query = $builder->get();
return $query->getResult();
}
function amountpaidcashbookfilter($fa, $aa, $m, $fdate, $tdate)
{
//echo $m;
$builder = $this->db->table('t_income_expense tie')
->select('tac.name,sum(tie.total)as total,tie.account_code')
->join('t_accountcode tac', 'tac.code=tie.account_code')
->where('tie.amounttype', 'DEBIT')
->where('tie.cashtype', 'BANK')
->where('tie.IsActive', 1);
//->where('t_income_expense.account_code !=','ADV001')
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(tie.date >= '" . $fa . "-04-01' and tie.date <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//->where('MONTH(pel.tgl_pembelian)',$bulan);
$month = "monthname(tie.date) = '" . $m . "'";
$builder->where($month);
// $sql.="and monthname(bm.Podate) = '".$m."'";
}
if ($fdate and $tdate != '') {
$fromdate = date("Y-m-d", strtotime($fdate));
$todate = date("Y-m-d", strtotime($tdate));
$date = "date(tie.date) >= '" . $fromdate . "'
and date(tie.date) <= '" . $todate . "'";
$builder->where($date);
}
$builder->groupBy('tie.account_code');
$query = $builder->get();
return $query->getResult();
}
function amountreceivedcashbookfilter($fa, $aa, $m, $fdate, $tdate)
{
$builder = $this->db->table('t_income_expense tie')
->select('tac.name,sum(tie.total)as total,tie.account_code')
->join('t_accountcode tac', 'tac.code=tie.account_code')
->where('tie.amounttype', 'CREDIT')
->where('tie.IsActive', 1);
//->where('t_income_expense.account_code !=','ADV001')
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(tie.date >= '" . $fa . "-04-01' and tie.date <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//->where('MONTH(pel.tgl_pembelian)',$bulan);
$month = "monthname(tie.date) = '" . $m . "'";
$builder->where($month);
// $sql.="and monthname(bm.Podate) = '".$m."'";
}
if ($fdate and $tdate != '') {
$fromdate = date("Y-m-d", strtotime($fdate));
$todate = date("Y-m-d", strtotime($tdate));
$date = "date(tie.date) >= '" . $fromdate . "'
and date(tie.date) <= '" . $todate . "'";
$builder->where($date);
}
$builder->groupBy('tie.account_code');
$query = $builder->get();
return $query->getResult();
}
function amountpaidsupplierwisefilter($fa, $aa, $m, $fdate, $tdate)
{
$builder = $this->db->table('t_bankmappingpo bm')
->select('bm.id,bm.mid,bm.PONO,bm.Suppliername,bm.SupplierID,sum(bm.Totalpoamount)as Totalpoamount,
bm.Balancetopay,sum(bm.Amountpaid) as Amountpaid,bm.Podate,bm.IGRLineItemNo,bm.BankDate')
->where('bm.IsActive', 1);
if ($fa and $aa != '') {
$year = "(bm.BankDate >= '" . $fa . "-04-01' and bm.BankDate <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//->where('MONTH(pel.tgl_pembelian)',$bulan);
$month = "monthname(bm.BankDate) = '" . $m . "'";
$builder->where($month);
// $sql.="and monthname(bm.Podate) = '".$m."'";
}
if ($fdate and $tdate != '') {
$fromdate = date("Y-m-d", strtotime($fdate));
$todate = date("Y-m-d", strtotime($tdate));
$date = "date(bm.BankDate) >= '" . $fromdate . "'
and date(bm.BankDate) <= '" . $todate . "'";
$builder->where($date);
}
$builder->groupBy('bm.SupplierID');
$query = $builder->get();
return $query->getResult();
}
// function unpaided()
// {
// // ->select('igd.IGRNO,igd.IGRItemNo,pom.PONO,sm.SupplierName');
// // $builder = $this->db->table('t_igr_details igd');
// // ->join('t_igr_master igm','igm.IGRNO=igd.IGRNO');
// // ->join('t_purchaseorder_lineitem poli','igm.PONO= poli.PONO and igd.MaterialCode=poli.MaterialCode');
// // ->join('t_purchaseorder_master pom','pom.PONO=poli.PONO');
// // ->join('t_supplierdetailsn sm','sm.SupplierID=pom.SupplierID');
// // ->where('igd.BankStatus','ST072');
// // $query =$builder->get();
// // $result = $query->getResult();
// // return $result;
// }
function received($clientid, $fdate, $tdate, $fa, $aa, $m)
{
$builder = $this->db->table('t_bankmappingiv bm')
->select('bm.indate,bm.BankDate,bm.invoiceno,bm.customername,bm.totinvoiceamount,bm.bankid,bm.customerid,
bm.balancetoreceived,bm.amountreceived,bm.ID,br.Credit,br.cclearbalance,br.cbalancetocleared,bm.IsActive')
->join('ip_invoices iv', 'iv.invoice_number=bm.invoiceno')
->join('t_bankreport br', 'br.ID=bm.bankid')
->where('bm.IsActive', 1)
->where('bm.customerid', $clientid)
->where('iv.receivedstatus !=', 'ST066');
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(bm.BankDate >= '" . $fa . "-04-01' and bm.BankDate <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$month = "monthname(bm.BankDate) = '" . $m . "'";
$builder->where($month);
}
if ($fdate != '' && $tdate != '') {
$builder->where('bm.BankDate BETWEEN "' . format_date($fdate) . '" and "' . format_date($tdate) . '"');
}
//$builder->groupBy('invoiceno');
$query = $builder->get();
return $query->getResult();
}
function creditinvoicesupplierwise()
{
$builder = $this->db->table('t_bankmappingiv bm')
->select('bm.indate,bm.invoiceno,bm.customername,bm.totinvoiceamount,bm.bankid,ic.client_id,bm.customerid as customerid,
bm.balancetoreceived,sum(bm.amountreceived)as amountreceived,bm.ID,br.Credit,br.cclearbalance,br.cbalancetocleared')
->join('t_bankreport br', 'br.ID=bm.bankid')
->join('ip_invoices iv', 'iv.invoice_number=bm.invoiceno')
->join('ip_clients ic', 'ic.client_name=bm.customername', 'left')
->where('bm.IsActive', 1)
->groupBy('bm.customerid')
->where('iv.receivedstatus !=', 'ST066');
$query = $builder->get();
return $query->getResult();
}
function creditinvoicewisefilter($fdate, $tdate, $fa, $aa, $m)
{
$builder = $this->db->table('t_bankmappingiv bm')
->select('bm.indate,bm.BankDate,bm.invoiceno,bm.customername,bm.customerid as customerid,bm.totinvoiceamount,bm.bankid,ic.client_id,
bm.balancetoreceived,sum(bm.amountreceived)as amountreceived,bm.ID,br.Credit,br.cclearbalance,br.cbalancetocleared')
->join('ip_invoices iv', 'iv.invoice_number=bm.invoiceno')
->join('t_bankreport br', 'br.ID=bm.bankid')
->join('ip_clients ic', 'ic.client_name=bm.customername', 'left')
->where('bm.IsActive', 1)
->where('iv.receivedstatus !=', 'ST066');
// ->where('bm.customername',$Customer);
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(bm.BankDate >= '" . $fa . "-04-01' and bm.BankDate <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//->where('MONTH(pel.tgl_pembelian)',$bulan);
$month = "monthname(bm.BankDate) = '" . $m . "'";
$builder->where($month);
// $sql.="and monthname(bm.Podate) = '".$m."'";
}
if ($fdate and $tdate != '') {
$fromdate = date("Y-m-d", strtotime($fdate));
$todate = date("Y-m-d", strtotime($tdate));
$date = "date(bm.BankDate) >= '" . $fromdate . "'
and date(bm.BankDate) <= '" . $todate . "'";
$builder->where($date);
}
$builder->groupBy('bm.customerid');
$query = $builder->get();
return $query->getResult();
}
function unreceived($clientname, $fdate, $tdate, $fa, $aa, $m)
{
$builder = $this->db->table('ip_invoice_amounts iva')
->distinct()
->select('iva.invoice_id,iva.invoice_total,iv.invoice_date_created,iv.invoice_number,iva.invoice_paid,ic.client_name,BI.balancetoreceived,BI.amountreceived,ic.client_id')
->join('ip_invoices iv', 'iva.invoice_id = iv.invoice_id', 'left')
->join('ip_clients ic', 'iv.client_id = ic.client_id', 'left')
->join('t_bankinvoicereport BI', ' iv.invoice_number =BI.invoiceno', 'left')
->where('iv.receivedstatus', 'ST066')
->where('iv.invoice_status_id', '2')
->where('ic.client_id', $clientname);
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(iv.invoice_date_created >= '" . $fa . "-04-01' and iv.invoice_date_created <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$month = "monthname(iv.invoice_date_created) = '" . $m . "'";
$builder->where($month);
}
if ($fdate != '' && $tdate != '') {
$builder->where('iv.invoice_date_created BETWEEN "' . date('Y-m-d', strtotime($fdate)) . '" and "' . date('Y-m-d', strtotime($tdate)) . '"');
}
// ->where('iv.receivedstatus','ST066');
$builder->groupBy('iva.invoice_id');
//->where('inc.type','PAYMENT');
$query = $builder->get();
return $query->getResult();
}
function unreceivedsupplier()
{
$builder = $this->db->table('ip_invoice_amounts iva')
->select('iva.invoice_id,sum(iva.invoice_total)as invoice_total,iv.invoice_date_created,iv.invoice_number,iva.invoice_paid,ic.client_id,ic.client_name,BI.balancetoreceived,sum(BI.amountreceived)as amountreceived')
->join('ip_invoices iv', 'iva.invoice_id = iv.invoice_id', 'left')
->join('ip_clients ic', 'iv.client_id = ic.client_id', 'left')
->join('t_bankinvoicereport BI', ' iv.invoice_number =BI.invoiceno', 'left')
->where('iv.receivedstatus', 'ST066')
->where('iv.invoice_status_id', '2')
->groupBy('ic.client_name');
//->where('inc.type','PAYMENT');
$query = $builder->get();
return $query->getResult();
}
function uncreditinvoicewisefilter($fdate, $tdate, $fa, $aa, $m)
{
$builder = $this->db->table('ip_invoice_amounts iva')
->select('iva.invoice_id,sum(iva.invoice_total)as invoice_total,iv.invoice_date_created,iv.invoice_number,iva.invoice_paid,ic.client_id,ic.client_name,BI.balancetoreceived,sum(BI.amountreceived)as amountreceived')
->join('ip_invoices iv', 'iva.invoice_id = iv.invoice_id', 'left')
->join('ip_clients ic', 'iv.client_id = ic.client_id', 'left')
->join('t_bankinvoicereport BI', ' iv.invoice_number =BI.invoiceno', 'left')
->where('iv.receivedstatus', 'ST066')
->where('iv.invoice_status_id', '2');
// ->where('bm.customername',$Customer);
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$year = "(iv.invoice_date_created >= '" . $fa . "-04-01' and iv.invoice_date_created <= '" . $aa . "-03-31')";
$builder->where($year);
}
if ($m != '') {
//->where('MONTH(pel.tgl_pembelian)',$bulan);
$month = "monthname(iv.invoice_date_created) = '" . $m . "'";
$builder->where($month);
// $sql.="and monthname(bm.Podate) = '".$m."'";
}
if ($fdate and $tdate != '') {
$fromdate = date("Y-m-d", strtotime($fdate));
$todate = date("Y-m-d", strtotime($tdate));
$date = "date(iv.invoice_date_created) >= '" . $fromdate . "'
and date(iv.invoice_date_created) <= '" . $todate . "'";
$builder->where($date);
}
$builder->groupBy('ic.client_name');
//->where('inc.type','PAYMENT');
$query = $builder->get();
return $query->getResult();
}
// function podetailstatus($podetails,$pono)
// {
// echo $igrdetails;
// $this->db->table('t_purchaseorder_master')
// ->where('PONO',$pono);
// ->update($podetails);
// $r = ->affectedRows();
// return $r;
// }
function invoiceamountstatus($invoicemaster, $invid)
{
$this->db->table('ip_invoices')
->where('invoice_number', $invid)
->update($invoicemaster);
$count = $this->db->affectedRows();
return $count;
}
function igrstatus($igrmaster, $igrno)
{
$this->db->table('t_igr_master')
->where('IGRNO', $igrno)
->update($igrmaster);
$count = $this->db->affectedRows();
return $count;
}
function Cashbook($cashbookdatas)
{
$code = $cashbookdatas['code'];
$type = $cashbookdatas['type'];
$count = 0;
$builder = $this->db->table('t_accountcode')
->select('count(*) as count')
->where('type', $type)
->where('code', $code);
$isExits = $builder->get();
$res = $isExits->getResultArray();
if (!empty($res)) {
$count = $res[0]['count'];
}
if ($count == 0) //for cashbook_insert
{
$builder = $this->db->table('t_accountcode');
$builder->insert($cashbookdatas);
$res = $this->db->affectedRows();
return $res;
} elseif ($count == 1) //for cashbook_update
{
$this->db->table('t_accountcode')
->where('code', $code)
->update($cashbookdatas);
$count = $this->db->affectedRows();
return $count;
}
}
function deletemapping($Bankid, $updateamount, $updatebalancetoclear, $Status)
{
$this->db->table('t_bankreport')
->set('Clearbalance', $updateamount)
->set('Balancetocleared', $updatebalancetoclear)
->set('Status', $Status)
->where('ID', $Bankid)
->update();
$count = $this->db->affectedRows();
return $count;
}
function updatebankreportiv($bankid, $bankstatement)
{
$this->db->table('t_bankreport')
->where('ID', $bankid)
->update($bankstatement);
$count = $this->db->affectedRows();
return $count;
}
function IGRStatusUpdate($igrno, $PaymentStatus)
{
$this->db->table('t_igr_master')
->set('Paymentstatus', $PaymentStatus)
->where('IGRNO', $igrno)
->update();
$count = $this->db->affectedRows();
return $count;
}
function deleteBankmappingpo($id, $IsActive)
{
$this->db->table('t_bankmappingpo')
->set('IsActive', $IsActive)
->where('id', $id)
->update();
$count = $this->db->affectedRows();
return $count;
}
// function updatemappingamount($igrno,$amountpaid)
// {
// $sql="update t_bankmappingpo set Balancetopay=$amountpaid+Balancetopay where IGRLineItemNo='$igrno' and
// IsActive='1'";
// $query = ->query($sql);
// return $query->getResult();
// $this->db->table('t_bankmappingpo')
// // ->set('Balancetopay',$amountpaid+'Balancetopay');
// // //->set('Balancetopay',$amountpaid);
// // ->where('IGRLineItemNo',$igrno);
// // ->where('IsActive',1);
// // ->update();
// // $r = ->affectedRows();
// // return $r;
// }
function UpdateIpinvoiceStatus($invoiceno, $receivedstatus)
{
$this->db->table('ip_invoices')
->set('receivedstatus', $receivedstatus)
->where('invoice_number', $invoiceno)
->update();
$count = $this->db->affectedRows();
return $count;
}
function deletemappinginvoice($mappingid, $IsActive)
{
$this->db->table('t_bankmappingiv')
->set('IsActive', $IsActive)
->where('ID', $mappingid)
->update();
$count = $this->db->affectedRows();
return $count;
}
// function updatemappinginvoice($invoiceno,$amountreceived)
// {
// ->set('balancetoreceived',$amountreceived+'balancetoreceived');
// ->where('invoiceno',$invoiceno);
// ->where('IsActive',1);
// ->update('t_bankmappingiv');
// $query =$builder->get();
// print_r(this->db->last_query());
// $r = ->affectedRows();
// return $r;
// }
function updateBankporeport($igrno, $balancetopayupdate, $amountpaidupdate, $IsAct)
{
$this->db->table('t_bankporeport')
->set('Balancetopay', $balancetopayupdate)
->set('Amountpaid', $amountpaidupdate)
->set('IsActive', $IsAct)
->where('IGRNO', $igrno)
//->where('mid',$Bankid)
->update();
$count = $this->db->affectedRows();
return $count;
}
function updatebankinvoicereport($invoiceno, $balancetoreceivedupdate, $amountreceivedupdate, $IsAct)
{
$this->db->table('t_bankinvoicereport')
->set('balancetoreceived', $balancetoreceivedupdate)
->set('amountreceived', $amountreceivedupdate)
->set('IsActive', $IsAct)
->where('invoiceno', $invoiceno)
//->where('bankid',$bankid)
->update();
$count = $this->db->affectedRows();
return $count;
}
function gettotalbankmappingpo($id)
{
$builder = $this->db->table('t_bankmappingpo')
->select('sum(Amountpaid)as Amountpaid')
->where('id', $id)
->where('IsActive', 1);
//->groupBy('t_bankmappingpo.IGRLineItemNo');
$query = $builder->get();
return $query->getResult();
}
function gettotalbankmappingpocount($igrno)
{
$builder = $this->db->table('t_bankmappingpo')
->select('count(Amountpaid)as countAmountpaid')
->where('IGRNO', $igrno)
->where('IsActive', 1);
//->groupBy('t_bankmappingpo.IGRLineItemNo');
$query = $builder->get();
return $query->getResult();
}
function gettotalbankmappinginvoicecount($invoiceno)
{
$builder = $this->db->table('t_bankmappingiv')
->select('count(amountreceived)as countamountreceived')
->where('invoiceno', $invoiceno)
->where('IsActive', 1);
//->groupBy('t_bankmappingpo.IGRLineItemNo');
$query = $builder->get();
return $query->getResult();
}
function gettotalbankpoamount($igrno)
{
$builder = $this->db->table('t_bankporeport')
->select('Amountpaid,Balancetopay')
->where('IGRNO', $igrno)
->where('IsActive', 1);
//->groupBy('t_bankmappingpo.IGRLineItemNo');
$query = $builder->get();
return $query->getResult();
}
function gettotalbankreceivedamount($invoiceno)
{
$builder = $this->db->table('t_bankinvoicereport')
->select('amountreceived,balancetoreceived')
->where('invoiceno', $invoiceno)
->where('IsActive', 1);
//->groupBy('t_bankmappingpo.IGRLineItemNo');
$query = $builder->get();
return $query->getResult();
}
function gettotalbankporeport($igrno)
{
$builder = $this->db->table('t_bankporeport')->select('Amountpaid')
->where('IGRLineItemNo', $igrno)
->where('IsActive', 1);
//->groupBy('t_bankmappingpo.IGRLineItemNo');
$query = $builder->get();
return $query->getResult();
}
function getlatestamount($mappingid, $invoiceno)
{
$builder = $this->db->table('t_bankmappingiv')
->select('min(balancetoreceived)as balancetoreceived')
->where('ID', $mappingid)
->where('invoiceno', $invoiceno)
->where('IsActive', 1);
//->groupBy('t_bankmappingpo.IGRLineItemNo');
$query = $builder->get();
return $query->getResult();
}
function getlatest($invoiceno)
{
$sql = "select ID,balancetoreceived from t_bankmappingiv where invoiceno='$invoiceno' and
ID in(select max(ID) from t_bankmappingiv group by invoiceno)";
$query = $this->db->query($sql);
return $query->getResult();
}
function deletecashbookdata($Bankid, $updatebankamount, $clearbalance)
{
$this->db->table('t_bankreport')
->set('Clearbalance', $clearbalance)
->set('Balancetocleared', $updatebankamount)
->where('ID', $Bankid)
->update();
$r = $this->db->affectedRows();
return $r;
}
function deletecashbookdatacredit($Bankid, $updateclearbalance, $updatebalancetoclear)
{
$this->db->table('t_bankreport')
->set('cclearbalance', $updateclearbalance)
->set('cbalancetocleared', $updatebalancetoclear)
->where('ID', $Bankid)
->update();
$r = $this->db->affectedRows();
return $r;
}
function getaccountcode($accountname)
{
$builder = $this->db->table('t_accountcode')->select('code')
->where('name', $accountname);
$query = $builder->get();
return $query->getResult();
}
function StatusUpadateCashbook($id, $IsActive)
{
$this->db->table('t_income_expense')
->set('IsActive', $IsActive)
->where('id', $id)
->update();
$r = $this->db->affectedRows();
return $r;
}
}