ria/app/Models/Dashboard_model.php

3242 lines
123 KiB
PHP
Executable File

<?php
namespace App\Models;
use App\Models\Rawmaterialdetails_model;
use App\Models\Inwardgateregister_model;
use CodeIgniter\Model;
class Dashboard_model extends Model
{
protected $rawMaterialDetails;
protected $inwardgateregister;
public function __construct(){
parent::__construct();
$this->rawMaterialDetails = new Rawmaterialdetails_model();
$this->inwardgateregister = new Inwardgateregister_model();
}
function getUserCount()
{
$subQuery = "SELECT count(userId) as users FROM tbl_users WHERE isDeleted = ? ";
$query = $this->db->query($subQuery, '0');
return $query->getResult();
}
/* HR DASHBOART Model START*/
function totemp()
{
$yes_date = format_date("-1 days");
$builder = $this->db->table('t_employee_details')
->select('count(*) as totemp')
->where('date(t_employee_details.Created_date)<=', $yes_date)
->where('isActive', 1);
$query = $builder->get();
return $query->getRow();
}
function getfile($PONO)
{
//$this->db->distinct();
$builder = $this->db->table('t_purchaseorder_billupload')
->select('*')->where('PONO', $PONO);
$query = $builder->get();
$result = $query->getResultArray();
return $result;
}
function getfiles($igr, $PONO)
{
//$this->db->distinct();
$builder = $this->db->table('t_inwardgateregister_fileupload')
->select('*')->where('IGRNO', $igr)->where('PONO', $PONO);
$query = $builder->get();
$result = $query->getResultArray();
return $result;
}
function viewIGRFile1($igr, $PONO)
{
$builder = $this->db->table('t_igr_master igrm')
->select('igrm.file,igrm.PONO as pono') //BillNo,IGRNO,FilePath,PONO
->where('igrm.IGRNO', $igr)
->where('igrm.PONO', $PONO);
$query = $builder->get();
$result = $query->getResult();
return $result;
}
function selectigrfiles()
{
$builder = $this->db->table('t_inwardgateregister_fileupload');
$builder->select('*');
//->where('PONO',$PONO);
$query = $builder->get();
$result = $query->getResultArray();
return $result;
}
function totloan()
{
$sql = "select sum(Loan_Amount)as totloan FROM t_loan_master";
$query = $this->db->query($sql);
return $query->getResult();
}
function totpay()
{
$sql = "select sum(Paid_Amount)as totpay FROM t_loan_master";
$query = $this->db->query($sql);
return $query->getResult();
}
function totrec()
{
$sql = "select sum(Loan_Amount), sum(Paid_Amount),sum(Loan_Amount)-sum(Paid_Amount) as totrec FROM t_loan_master";
$query = $this->db->query($sql);
return $query->getResult();
}
function emplist()
{
$sql = "select EmpID,CONCAT(FirstName,' ',LastName) as name FROM t_employee_details where IsActive ='1'";
$query = $this->db->query($sql);
return $query->getResult();
}
function attyesterday($WH, $date)
{
//echo 'model' . $WH.'-'.$date;
// $sql="select EmpID,".$WH." from t_attendance where Month_Year = ? and EmpID in (select EmpID from t_attendance)" ;
$yes_date = format_date("-1 days");
$sql = "select att.EmpID,ifnull(" . $WH . ",0)" . $WH . ",a.FirstName from t_attendance as att
join t_employee_details as a on a.EmpID= att.EmpID
where Month_Year = ? and att.EmpID in (select EmpID from t_attendance) and date(a.Created_date) <= '" . $yes_date . "' and isActive=1";
$query = $this->db->query($sql, array($date));
// print_r($query->result_array());die;
//echo count($query->result());
return $query->getResultArray();
}
function dayAllPersentEmpSalary($WH, $OT, $date)
{
// echo $date;
$sql = "select EmpID," . $WH . "," . $OT . " from t_attendance where Month_Year = ? and EmpID in (select EmpID from t_attendance)";
$query = $this->db->query($sql, array($date));
//return
return $query->getResultArray();
}
function yesterdayAllPersentEmpSalary($WH, $OT, $date)
{
// echo $date;
$sql = "select EmpID," . $WH . "," . $OT . " from t_attendance where Month_Year = ? and EmpID in (select EmpID from t_attendance)";
$query = $this->db->query($sql, array($date));
//return
return $query->getResultArray();
}
function attendance($EmpID, $dates)
{
//echo $EmpID.'-'.$dates;
$sql = "select * from t_attendance where EmpID =? and Month_Year=?";
$query = $this->db->query($sql, array($EmpID, $dates));
return $query->getResult();
}
function getAllAttendance($EmpID, $CURMONTH)
{
$sql = "select * from t_attendance where EmpID =? and month(Month_Year)=?";
// $sql=" select t_attendance.*,emp.FirstName from t_attendance
// join t_employee_details emp on t_attendance.EmpID = emp.EmpID
// where t_attendance.EmpID = ? and month(Month_Year)= ? ";
$query = $this->db->query($sql, array($EmpID, $CURMONTH));
return $query->getResult();
}
function getAllAttendances($EmpID, $JoinedMonth)
{
//$sql="select * from t_attendance where EmpID =? and month(Month_Year)=?";
$sql = " select t_attendance.*,emp.FirstName from t_attendance
join t_employee_details emp on t_attendance.EmpID = emp.EmpID
where t_attendance.EmpID = ? and month(Month_Year)= ? ";
$query = $this->db->query($sql, array($EmpID, $JoinedMonth));
return $query->getResult();
}
function joindate($EmpID)
{
$sql = "select DateofJoining from t_employee_details where EmpID =? ";
$query = $this->db->query($sql, array($EmpID));
return $query->getResult();
}
function daysalary($EmpID, $dates)
{
//print_r($dates);die;
$sql = "select * FROM t_emp_pay_data as pay
join t_attendance att on att.EmpID = pay.EmpID
where att.Month_Year = ? and att.EmpID = ?;";
$query = $this->db->query($sql, array($dates, $EmpID));
return $query->getResult();
}
function persentEmployeeDetails($EmpID)
{
//join t_attendance att on att.EmpID = pay.EmpID
$sql = "select * FROM t_emp_pay_data where EmpID = ?;";
$query = $this->db->query($sql, array($EmpID));
return $query->getResult();
}
function attendanceyear($EmpID, $MONTH)
{
// //print_r($MONTH);
// $sql="select Att.EmpID,Att.Month_Year,Att.*,NoofDays,Days_Worked,emp.DateofJoining from t_attendance Att
// join t_employee_details as emp on emp.EmpID = Att.EmpID
// where Att.Month_Year between ? and Att.EmpID = ?";
// else
// (YEAR(Month_Year) = YEAR(CURRENT_DATE)-1 and MONTH(Month_Year) >= ? ) or ( YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) <= 3 )
// $sql = 'select sum(NoofDays) as TotalWorkingDays,sum(Days_worked) as DaysWorked from t_attendance where
// case
// when (month(Month_Year) >=4) then
// (YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) >= ? ) or ( YEAR(Month_Year) = YEAR(CURRENT_DATE)+1 and MONTH(Month_Year) <= 3 )end and EmpID = ? and month(Month_Year) != month(current_date())
// else
// (YEAR(Month_Year) = YEAR(CURRENT_DATE)-1 and MONTH(Month_Year) >= ? ) or ( YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) <= 3 )';
$sql = ' select sum(NoofDays) as TotalWorkingDays,sum(Days_worked) as DaysWorked from t_attendance where
case
when (MONTH(CURRENT_DATE) >=4) then
((YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) >= ? )) and EmpID = ? and month(Month_Year) != MONTH(CURRENT_DATE)
else
((YEAR(Month_Year) = YEAR(CURRENT_DATE)-1 and MONTH(Month_Year) >=4 and ? >= 4) or ( YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) <= 3 and ? <=3 )) and Month(Month_Year) >= ? and EmpID = ? and month(Month_Year) != MONTH(CURRENT_DATE)
end';
/*$sql='select sum(NoofDays) as TotalWorkingDays,sum(Days_worked) as DaysWorked from t_attendance
where EmpID= ? and (MONTH(Month_Year) >=4) or (MONTH(Month_Year) <3)
and (YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) >= ? )or ( YEAR(Month_Year) = YEAR(CURRENT_DATE)+1 and MONTH(Month_Year) <= 3 )
and MONTH(Month_Year) != MONTH(current_date())';*/
$query = $this->db->query($sql, array($MONTH, $EmpID, $MONTH, $MONTH, $MONTH, $EmpID));
return $query->getResult();
}
function getEmployee()
{
$sql = "select EmpID,FirstName,LastName,IsActive FROM t_employee_details ";
$query = $this->db->query($sql);
return $query->getResult();
}
function get_all_employee($Month)
{
$sql = "select t_attendance.*,emp.EmpID,emp.FirstName,emp.LastName,emp.IsActive from t_attendance
join t_employee_details emp on t_attendance.EmpID = emp.EmpID
where Month_Year=?;";
$query = $this->db->query($sql, array($Month));
return $query->getResult();
}
function get_all_employee1($finStart, $finEnd)
{
$sql = "select att.EmpID,att.*,att.Month_Year,emp.FirstName,emp.DateofJoining from t_attendance att
join t_employee_details emp on emp.EmpID = att.EmpID
where att.Month_Year between ? and ?";
$query = $this->db->query($sql, array($finStart, $finEnd));
return $query->getResult();
}
function holiDaySalaryMonth($month, $year)
{
$sql = "SELECT H_Date FROM t_public_holidays where MONTH(H_Date)= ? and YEAR(H_Date) = ? ";
$query = $this->db->query($sql, array($month, $year));
return $query->getResult();
}
function fy()
{
$sql = "SELECT
CASE WHEN MONTH(Month_year)>=4 THEN
concat(YEAR(Month_year), '-',YEAR(Month_year)+1)
ELSE concat(YEAR(Month_year)-1,'-', YEAR(Month_year)) END AS financial_year
FROM t_attendance
GROUP BY financial_year";
$query = $this->db->query($sql);
return $query->getResult();
}
function get_employee()
{
$yes_date = format_date("-1 days");
$sql = "select * from t_employee_details where date(created_date) <='" . $yes_date . "' and isActive =1";
$query = $this->db->query($sql);
return $query->getResult();
}
function per($fa, $aa, $m)
{
//echo $m;
$cur_month = date('M');
//echo $cur_month;
if ($cur_month == $m) {
$cur_date = date('d');
} else {
$cur_date = date('t', strtotime($m));
}
//echo $cur_date;die;
$sql = "SELECT month.Eid as Eid,month.ename as ename,month.active as active,month.days as monthdays,month.Days_Worked as monthworked,month.percentage as monthpercentage
from (select em.EmpID as Eid,concat(em.FirstName,'.',em.LastName) as ename,em.IsActive as active,at.NoofDays as days,
Days_Worked,round((Days_Worked/" . $cur_date . "*100)) as percentage from
t_employee_details em
join t_attendance at on at.EmpID = em.EmpID
where (Month_Year >= '" . $fa . "-04-01' and Month_Year <= '" . $aa . "-04-01') and monthname(Month_Year) = '" . $m . "'
) as month";
$query = $this->db->query($sql);
return $query->getResult();
}
/* HR DASHBOARD Model END*/
function totalpurchaseorder()
{
$sql = "select count(PONO) as totalpurchaseorder from t_purchaseorder_master pm where Status != 'ST030'
and case
when (month(pm.PODate) >=4) then
(YEAR(pm.PODate) = YEAR(CURRENT_DATE) and MONTH(pm.PODate) >= 4 ) or ( YEAR(pm.PODate) = YEAR(CURRENT_DATE)+1 and MONTH(pm.PODate) <= 3 )
else
(YEAR(pm.PODate) = YEAR(CURRENT_DATE)-1 and MONTH(pm.PODate) >= 4 ) or ( YEAR(pm.PODate) = YEAR(CURRENT_DATE) and MONTH(pm.PODate) <= 3 )
end";
$query = $this->db->query($sql);
return $query->getResult();
}
function totalordervalue()
{
$sql = "select sum(totalordervalue) as totalordervalue from t_purchaseorder_master pm where Status != 'ST030'
and case
when (month(pm.PODate) >=4) then
(YEAR(pm.PODate) = YEAR(CURRENT_DATE) and MONTH(pm.PODate) >= 4 ) or ( YEAR(pm.PODate) = YEAR(CURRENT_DATE)+1 and MONTH(pm.PODate) <= 3 )
else
(YEAR(pm.PODate) = YEAR(CURRENT_DATE)-1 and MONTH(pm.PODate) >= 4 ) or ( YEAR(pm.PODate) = YEAR(CURRENT_DATE) and MONTH(pm.PODate) <= 3 )
end";
$query = $this->db->query($sql);
return $query->getResult();
}
function pendingpo()
{
$sql = "select count(PONO) as pending from t_purchaseorder_master pm where status='ST020' and Status != 'ST030'
and case
when (month(pm.PODate) >=4) then
(YEAR(pm.PODate) = YEAR(CURRENT_DATE) and MONTH(pm.PODate) >= 4 ) or ( YEAR(pm.PODate) = YEAR(CURRENT_DATE)+1 and MONTH(pm.PODate) <= 3 )
else
(YEAR(pm.PODate) = YEAR(CURRENT_DATE)-1 and MONTH(pm.PODate) >= 4 ) or ( YEAR(pm.PODate) = YEAR(CURRENT_DATE) and MONTH(pm.PODate) <= 3 )
end";
$query = $this->db->query($sql);
return $query->getResult();
}
function req_pending()
{
$sql = "SELECT count(Status) as TOTAL_PENDING_REQUESTS FROM t_requestion_master pm where Status = 'ST002'
and case
when (month(pm.ReqDate) >=4) then
(YEAR(pm.ReqDate) = YEAR(CURRENT_DATE) and MONTH(pm.ReqDate) >= 4 ) or ( YEAR(pm.ReqDate) = YEAR(CURRENT_DATE)+1 and MONTH(pm.ReqDate) <= 3 )
else
(YEAR(pm.ReqDate) = YEAR(CURRENT_DATE)-1 and MONTH(pm.ReqDate) >= 4 ) or ( YEAR(pm.ReqDate) = YEAR(CURRENT_DATE) and MONTH(pm.ReqDate) <= 3 )
end";
$query = $this->db->query($sql);
return $query->getResult();
}
function reqdetail()
{
$now = get_current_date();
$sql = "SELECT count(Status) as TODAY_REQUESTS FROM t_requestion_master where date(ReqDate) = '" . $now . "' ";
$query = $this->db->query($sql);
// echo "from Model";
// print_r($query->result());
return $query->getResult();
}
function january()
{
$sql = "select count(PONO) as pending from t_purchaseorder_master where status='ST020'";
$query = $this->db->query($sql);
return $query->getResult();
}
// function totalserviceamount()
// {
// $sql="select sum(BudgetAmount) as totalserviceamount from t_costcenter_budget where BudgetType='SERVICE'";
// $query = $this->db->query($sql);
// return $query->getResult();
// }
// function totalcapitalamount()
// {
// $sql="select sum(BudgetAmount) as totalcapitalamount from t_costcenter_budget where BudgetType='CAPITAL'";
// $query = $this->db->query($sql);
// return $query->getResult();
// }
// function totalimportamount()
// {
// $sql="select sum(BudgetAmount) as totalimportamount from t_costcenter_budget where BudgetType='IMPORT'";
// $query = $this->db->query($sql);
// return $query->getResult();
// }
// function totalrevenueamount()
// {
// $sql="select sum(BudgetAmount) as totalrevenueamount from t_costcenter_budget where BudgetType='REVENUE'";
// $query = $this->db->query($sql);
// return $query->getResult();
// }
//totalservice
function getTotalServicePoCount()
{
$i = 1;
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
while ($i <= 12) {
$sql = "SELECT count(cmast.PONO) as totalService FROM t_purchaseorder_master cmast
where POType='SERVICE' and Status != 'ST030' and month(PODate) = $i
and date(cmast.PODate) >= '" . $fa . "-04-01' and date(cmast.PODate) <= '" . $aa . "-03-31'";
$query = $this->db->query($sql);
$array_result[] = $query->getResult();
$i++;
}
return $array_result;
}
function getTotalimportPoCount()
{
$i = 1;
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
while ($i <= 12) {
$sql = "SELECT count(cmast.PONO) as totalImport FROM t_purchaseorder_master cmast
where POType='IMPORT' and Status != 'ST030' and month(PODate) = $i
and date(cmast.PODate) >= '" . $fa . "-04-01' and date(cmast.PODate) <= '" . $aa . "-03-31'";
$query = $this->db->query($sql);
$array_result[] = $query->getResult();
$i++;
}
return $array_result;
}
function getTotalcapitalPoCount()
{
$i = 1;
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
while ($i <= 12) {
$sql = "SELECT count(cmast.PONO) as totalcapital FROM t_purchaseorder_master cmast
where POType='CAPITAL' and Status != 'ST030' and month(PODate) = $i
and date(cmast.PODate) >= '" . $fa . "-04-01' and date(cmast.PODate) <= '" . $aa . "-03-31'";
$query = $this->db->query($sql);
$array_result[] = $query->getResult();
$i++;
}
return $array_result;
}
function getTotalrevenuePoCount()
{
$i = 1;
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
while ($i <= 12) {
$sql = "SELECT count(cmast.PONO) as totalrevenue FROM t_purchaseorder_master cmast
where POType='REVENUE' and Status != 'ST030' and month(PODate) = $i
and date(cmast.PODate) >= '" . $fa . "-04-01' and date(cmast.PODate) <= '" . $aa . "-03-31'";
$query = $this->db->query($sql);
$array_result[] = $query->getResult();
$i++;
}
return $array_result;
}
function serviceprogress()
{
$sql = "SELECT count(cmast.PONO) as serviceprogress FROM t_purchaseorder_master cmast
join t_purchaseorder_lineitem line on line.PONO=cmast.PONO
join t_requestion_master req on req.ReqNo=line.ReqNo
join t_status sta on sta.statusCode=req.status
where ReqType='SERVICE' and statusCode='ST018'";
$query = $this->db->query($sql);
return $query->getResult();
}
function revenueprogress()
{
$sql = "SELECT count(cmast.PONO) as revenueprogress FROM t_purchaseorder_master cmast
join t_purchaseorder_lineitem line on line.PONO=cmast.PONO
join t_requestion_master req on req.ReqNo=line.ReqNo
join t_status sta on sta.statusCode=req.status
where ReqType='REVENUE' and statusCode='ST018'";
$query = $this->db->query($sql);
return $query->getResult();
}
function importprogress()
{
$sql = "SELECT count(cmast.PONO) as importprogress FROM t_purchaseorder_master cmast
join t_purchaseorder_lineitem line on line.PONO=cmast.PONO
join t_requestion_master req on req.ReqNo=line.ReqNo
join t_status sta on sta.statusCode=req.status
where ReqType='IMPORT' and statusCode='ST018'";
$query = $this->db->query($sql);
return $query->getResult();
}
function capitalprogress()
{
$sql = "SELECT count(cmast.PONO) as capitalprogress FROM t_purchaseorder_master cmast
join t_purchaseorder_lineitem line on line.PONO=cmast.PONO
join t_requestion_master req on req.ReqNo=line.ReqNo
join t_status sta on sta.statusCode=req.status
where ReqType='CAPITAL' and statusCode='ST018'";
$query = $this->db->query($sql);
return $query->getResult();
}
function totalservicepo()
{
$sql = "SELECT count(cmast.PONO) as totalservicepo FROM t_purchaseorder_master cmast
join t_purchaseorder_lineitem line on line.PONO=cmast.PONO
join t_requestion_master req on req.ReqNo=line.ReqNo
join t_status sta on sta.statusCode=req.status
where ReqType='SERVICE'";
$query = $this->db->query($sql);
return $query->getResult();
}
function totalrevenuepo()
{
$sql = "SELECT count(cmast.PONO) as totalrevenuepo FROM t_purchaseorder_master cmast
join t_purchaseorder_lineitem line on line.PONO=cmast.PONO
join t_requestion_master req on req.ReqNo=line.ReqNo
join t_status sta on sta.statusCode=req.status
where ReqType='REVENUE'";
$query = $this->db->query($sql);
return $query->getResult();
}
function totalimportpo()
{
$sql = "SELECT count(cmast.PONO) as totalimportpo FROM t_purchaseorder_master cmast
join t_purchaseorder_lineitem line on line.PONO=cmast.PONO
join t_requestion_master req on req.ReqNo=line.ReqNo
join t_status sta on sta.statusCode=req.status
where ReqType='IMPORT'";
$query = $this->db->query($sql);
return $query->getResult();
}
function importbudgt()
{
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
$sql = "SELECT ROUND(sum(BudgetAmount),2) as totalimportbudget FROM t_costcenter_budget where BudgetType ='IMPORT' and date(CreatedDate) >= '" . $fa . "-04-01' and date(CreatedDate) <= '" . $aa . "-03-31'";
$query = $this->db->query($sql);
return $query->getResult();
}
function capitalbud()
{
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
$sql = "SELECT sum(BudgetAmount) as totalcapitalbudget FROM t_costcenter_budget where BudgetType ='CAPITAL' and date(CreatedDate) >= '" . $fa . "-04-01' and date(CreatedDate) <= '" . $aa . "-03-31' ";
$query = $this->db->query($sql);
return $query->getResult();
}
function servicebudgt()
{
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
$sql = "SELECT ROUND(sum(BudgetAmount),2) as totalservicebudget FROM t_costcenter_budget where BudgetType ='SERVICE' and date(CreatedDate) >= '" . $fa . "-04-01' and date(CreatedDate) <= '" . $aa . "-03-31'";
$query = $this->db->query($sql);
return $query->getResult();
}
function revenuebudgt()
{
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
$sql = "SELECT ROUND(sum(BudgetAmount),2) as totalrevenuebudget FROM t_costcenter_budget where BudgetType ='REVENUE' and date(CreatedDate) >= '" . $fa . "-04-01' and date(CreatedDate) <= '" . $aa . "-03-31'";
$query = $this->db->query($sql);
return $query->getResult();
}
function typebal()
{
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
$sql = "SELECT BudgetYear,
sum(if(BudgetType = 'SERVICE',
Util_Amount,0)) as sr,
sum(if(BudgetType = 'REVENUE',
Util_Amount,0)) as rv,
sum(if(BudgetType = 'IMPORT',
Util_Amount,0)) as im,
sum(if(BudgetType = 'CAPITAL',
Util_Amount,0)) as ca
FROM cost_center where Status !='ST030' and date(PODate) >= '" . $fa . "-04-01' and date(PODate) <= '" . $aa . "-03-31';
";
$query = $this->db->query($sql);
//echo $sql;
return $query->getResult();
}
function req_list($fa, $aa, $m, $frm, $t, $agf, $agt)
{
$sql = "select date_format(mas.ReqDate,'%d-%m-%Y') as ReqDate,mas.ReqNo,emp.FirstName as Requestedby,dep.DepartmentName,mas.ReqType,DATEDIFF(CURDATE(),mas.ReqDate) AS Aging from t_requestion_master as mas
join t_costcenter_master cos on cos.CostCenterCode = mas.CostCenterCode
join t_employee_details emp on emp.EmpID = mas.Requestedby
join t_departmentdetails dep on dep.DEPCode=emp.Departmentcode
where mas.Status = 'ST002'
";
if ($fa and $aa != '') {
$sql .= " and (mas.ReqDate >= '" . $fa . "-04-01' and mas.ReqDate <= '" . $aa . "-03-31')";
}
if ($m != '') {
$sql .= "and monthname(mas.ReqDate) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
$sql .= "and date(mas.ReqDate) >= '" . $fromd . "'
and date(mas.ReqDate) <= '" . $tod . "'";
}
if ($agf and $agt != '') {
$sql .= "and DATEDIFF(CURDATE(),mas.ReqDate) >= '" . $agf . "'
and DATEDIFF(CURDATE(),mas.ReqDate) <= '" . $agt . "'";
}
$query = $this->db->query($sql);
return $query->getResult();
}
function report_relpo($fa, $aa, $m, $frm, $t, $agf, $agt)
{
$sql = "select Mast.PONO,Mast.POType,date_format(Mast.PODate,'%d-%m-%Y') as PODate,date_format(Mast.ReleasedOn,'%d-%m-%Y') as ReleasedDate,Dept_Details.DepartmentName As Dept_Name,Mast.TotalOrderValue
from t_purchaseorder_master Mast
JOIN t_purchaseorder_lineitem Det on Det.PONO=Mast.PONO
left JOIN t_requestion_master as Req on Req.ReqNo=Det.ReqNo
left JOIN t_departmentdetails Dept_Details on Dept_Details.DEPCode=Req.RequestedDept
left JOIN t_costcenter_master as Cost on
Cost.CostCenterCode=Req.CostCenterCode
JOIN t_costcenter_budget as Cost_Center_Bdgt on Cost.CostCenterCode=Cost_Center_Bdgt.CostCenterCode
where Mast.Status='ST026'
";
if ($fa and $aa != '') {
$sql .= " and (Mast.PODate >= '" . $fa . "-04-01' and Mast.PODate <= '" . $aa . "-03-31')";
}
if ($m != '') {
$sql .= "and monthname(Mast.PODate) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
$sql .= "and date(Mast.PODate) >= '" . $fromd . "'
and date(Mast.PODate) <= '" . $tod . "'";
}
if ($agf and $agt != '') {
$sql .= "and Mast.TotalOrderValue >= '" . $agf . "'
and Mast.TotalOrderValue <= '" . $agt . "'";
}
$sql .= " group by Mast.PONO";
$query = $this->db->query($sql);
return $query->getResult();
}
function report_openpending($fa, $aa, $m, $frm, $t, $agf, $agt)
{
$sql = "select Mast.PONO as PONO,Mast.POType as POType,date_format(Mast.PODate,'%d-%m-%Y') as PODate,date_format(Mast.ApprovedOn,'%d-%m-%Y') as ApprovedDate,Dept_Details.DepartmentName As Dept_Name,Mast.TotalOrderValue
from t_purchaseorder_master Mast
left JOIN t_purchaseorder_lineitem Det on Det.PONO=Mast.PONO
left JOIN t_requestion_master as Req on Req.ReqNo=Det.ReqNo
left JOIN t_departmentdetails Dept_Details on Dept_Details.DEPCode=Req.RequestedDept
left JOIN t_costcenter_master as Cost on
Cost.CostCenterCode=Req.CostCenterCode
JOIN t_costcenter_budget as Cost_Center_Bdgt on Cost.CostCenterCode=Cost_Center_Bdgt.CostCenterCode
where (Mast.Status='ST025' or Mast.Status='ST005')
";
if ($fa and $aa != '') {
$sql .= " and (Mast.PODate >= '" . $fa . "-04-01' and Mast.PODate <= '" . $aa . "-03-31')";
}
if ($m != '') {
$sql .= "and monthname(Mast.PODate) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
$sql .= "and date(Mast.PODate) >= '" . $fromd . "'
and date(Mast.PODate) <= '" . $tod . "'";
}
if ($agf and $agt != '') {
$sql .= "and Mast.TotalOrderValue >= '" . $agf . "'
and Mast.TotalOrderValue <= '" . $agt . "'";
}
$sql .= " group by PONO,POType,Dept_Name";
$query = $this->db->query($sql);
//echo $sql;
return $query->getResult();
}
function report_total($fa, $aa)
{
$sql = "select ifnull(Dept_Details.DepartmentName,'-') As Dept_Name,
SUM(CASE WHEN Mast.Status = 'ST015' or Mast.Status = 'ST024' THEN 1 ELSE 0 END) AS PO_Created,
SUM(CASE WHEN Mast.Status = 'ST025' THEN 1 ELSE 0 END) AS Approved,
SUM(CASE WHEN Mast.Status = 'ST051' THEN 1 ELSE 0 END) AS Approver_Onhold,
SUM(CASE WHEN Mast.Status = 'ST052' THEN 1 ELSE 0 END) AS Releaser_Onhold,
SUM(CASE WHEN Mast.Status = 'ST053' THEN 1 ELSE 0 END) AS Service_completed,
SUM(CASE WHEN Mast.Status = 'ST026' THEN 1 ELSE 0 END) AS Released,
SUM(CASE WHEN Mast.Status = 'ST027' THEN 1 ELSE 0 END) AS IGR_Created,
SUM(CASE WHEN Mast.Status = 'ST044' THEN 1 ELSE 0 END) AS MRIR_Approved,
SUM(CASE WHEN Mast.Status = 'ST045' THEN 1 ELSE 0 END) AS MRIR_Rejected,
SUM(CASE WHEN Mast.Status = 'ST056' THEN 1 ELSE 0 END) AS Special_po
from t_po_detail Mast
left JOIN t_requestion_master as Req on Req.ReqNo=Mast.ReqNo
left JOIN t_departmentdetails Dept_Details on Dept_Details.DEPCode=Req.RequestedDept
where Mast.PODate >= '" . $fa . "-04-01' and Mast.PODate <= '" . $aa . "-03-31'
group by Dept_Name";
$query = $this->db->query($sql);
return $query->getResult();
}
function report_ccr($fa, $aa)
{
$sql = "SELECT Cost_Center_Code,Cost_Center_Name,Dept_Name,BudgetType,BudgetYear,sum(Util_Amount) as Util_Amount,
budget - sum(Util_Amount) as Avlbl_Amt
FROM cost_center
where Status !='ST030' and date(PODate) >= '" . $fa . "-04-01' and date(PODate) <= '" . $aa . "-03-31'
group by Cost_Center_Code,BudgetYear,BudgetType";
$query = $this->db->query($sql);
//echo $sql;
return $query->getResult();
}
function report_MMSupplier()
{
$sql = "select po.PODate as Material_Date,po.SupplierID,sup.SupplierName,pl.MaterialCode,mm.MaterialName,mm.MaterialType,mm.UOM,mm.HSNCODE
from t_purchaseorder_master po
join t_purchaseorder_lineitem pl on pl.PONO=po.PONO
join t_materialmaster mm on mm.MaterialCode=pl.MaterialCode
join t_supplierdetailsn sup on sup.SupplierID=po.SupplierID
group by po.SupplierID,pl.MaterialCode";
$query = $this->db->query($sql);
return $query->getResult();
}
function report_MMItem()
{
$sql = "SELECT MaterialCode,MaterialName,UOM, t_configdetails.ConfigValue as Category,HSNCODE FROM t_materialmaster
join t_configdetails on t_configdetails.key = t_materialmaster.Category
group by MaterialCode";
$query = $this->db->query($sql);
return $query->getResult();
}
function report_MMReceiptValue($fa, $aa, $m)
{
$sql = "select
DATE_FORMAT(IF(pm.PODate = '0000-00-00', NOW(), pm.PODate), '%b-%Y') AS Month,
matv.MaterialCode,mat.MaterialName,mat.UOM,ROUND(AVG(matv.Rate),2) as Average_Rate
from t_materialitem_po matv
join t_purchaseorder_master pm on pm.CreatedDate = matv.CreatedDate
join t_materialmaster mat on matv.MaterialCode=mat.MaterialCode
where pm.PODate != 0 ";
if ($fa and $aa != '') {
$sql .= " and (pm.PODate >= '" . $fa . "-04-01' and pm.PODate <= '" . $aa . "-03-31')";
}
if ($m != '') {
$sql .= "and monthname(pm.PODate) = '" . $m . "'";
}
$sql .= " group by matv.MaterialCode";
$sql .= " order by monthname(pm.PODate)";
$query = $this->db->query($sql);
return $query->getResult();
}
function report_purchase($cname, $prod, $fa, $aa, $m, $frm, $t)
{
$sql = "SELECT pm.PONO as pono,pm.POType as potype,date_format(pm.PODate,'%d-%m-%Y') as created_date,
TIME_FORMAT(pm.PODate,'%l:%i %p') as created_time,
mm.MaterialName as material_name,sd.SupplierName as supplier_name,
ifnull(sum(distinct pl.Quantity),0) as quantity,mm.UOM as UOM,ifnull(sum(distinct pl.Rate),0) as rate,
round(ifnull(sum(distinct pl.Quantity * pl.Rate),0),2) as value,
if(POType = 'IMPORT' or POType = 'CAPITAL',sum(distinct pm.ExchangeRate),0) as exchange_rate,
ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterSGST),sum(distinct st.After_SGST)),0) as sgst,
ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterCGST),sum(distinct st.After_CGST)),0) as cgst,
ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterIGST),sum(distinct st.After_IGST)),0) as igst,
ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterDiscount),sum(distinct st.Afterdiscountval)),0) as discount,
ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterFreightValue),sum(distinct st.AfterFreightValue)),0) as freight,
ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterPackagingValue),0),0) as Package,
ifnull(rt.Insurance,0) as insurance,
round((
if(POType = 'IMPORT',sum(distinct pm.ExchangeRate * (pl.Quantity * pl.Rate)),
if(POType = 'CAPITAL' && CapitalRange = 0,sum(distinct pm.ExchangeRate * (pl.Quantity * pl.Rate)),
ifnull(sum(pl.Quantity * pl.Rate),0)))
+ ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterSGST),sum(distinct st.After_SGST)),0)
+ ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterCGST),sum(distinct st.After_CGST)),0)
+ ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterIGST),sum(distinct st.After_IGST)),0)
+ ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterFreightValue),sum(distinct st.AfterFreightValue)),0)
+ ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterPackagingValue),0),0)
+ ifnull(rt.Insurance,0)
- ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterDiscount),sum(distinct st.Afterdiscountval)),0)),2) as total
FROM t_purchaseorder_master pm
join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
left join t_service_tax st on st.LineItemNo = pl.LineItemNo
left join t_revenue_tax rt on rt.LineItemNo = pl.LineItemNo
where
pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027'";
if ($cname != '') {
$sql .= "and sd.SupplierName = '" . $cname . "'";
}
if ($fa and $aa != '') {
$sql .= " and (pm.PODate >= '" . $fa . "-04-01' and pm.PODate <= '" . $aa . "-03-31')";
}
if ($m != '') {
$sql .= "and monthname(pm.PODate) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
$sql .= "and date(pm.PODate) >= '" . $fromd . "'
and date(pm.PODate) <= '" . $tod . "'";
}
if ($prod != '') {
$sql .= " and mm.MaterialName = '" . $prod . "' ";
}
$sql .= "group by pono,material_name,supplier_name";
//echo $sql;
$query = $this->db->query($sql);
return $query->getResult();
}
function report_purchase_link($cname, $prod, $fa, $aa, $m, $frm, $t, $sid, $mid, $d)
{
$sql = "SELECT pm.PONO as pono,pm.POType as potype,date_format(pm.PODate,'%d-%m-%Y') as created_date,
TIME_FORMAT(pm.PODate,'%l:%i %p') as created_time,
mm.MaterialName as material_name,sd.SupplierName as supplier_name,
ifnull(sum(distinct pl.Quantity),0) as quantity,mm.UOM as UOM,ifnull(sum(distinct pl.Rate),0) as rate,
round(ifnull(sum(distinct pl.Quantity * pl.Rate),0),2) as value,
if(POType = 'IMPORT' or POType = 'CAPITAL',sum(distinct pm.ExchangeRate),0) as exchange_rate,
ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterSGST),sum(distinct st.After_SGST)),0) as sgst,
ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterCGST),sum(distinct st.After_CGST)),0) as cgst,
ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterIGST),sum(distinct st.After_IGST)),0) as igst,
ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterDiscount),sum(distinct st.Afterdiscountval)),0) as discount,
ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterFreightValue),sum(distinct st.AfterFreightValue)),0) as freight,
ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterPackagingValue),0),0) as Package,
ifnull(rt.Insurance,0) as insurance,
round((
if(POType = 'IMPORT',sum(distinct pm.ExchangeRate * (pl.Quantity * pl.Rate)),
if(POType = 'CAPITAL' && CapitalRange = 0,sum(distinct pm.ExchangeRate * (pl.Quantity * pl.Rate)),
ifnull(sum(pl.Quantity * pl.Rate),0)))
+ ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterSGST),sum(distinct st.After_SGST)),0)
+ ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterCGST),sum(distinct st.After_CGST)),0)
+ ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterIGST),sum(distinct st.After_IGST)),0)
+ ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterFreightValue),sum(distinct st.AfterFreightValue)),0)
+ ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterPackagingValue),0),0)
+ ifnull(rt.Insurance,0)
- ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterDiscount),sum(distinct st.Afterdiscountval)),0)),2) as total
FROM t_purchaseorder_master pm
left join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
left join t_service_tax st on st.LineItemNo = pl.LineItemNo
left join t_revenue_tax rt on rt.LineItemNo = pl.LineItemNo
where
pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' ";
if ($cname != '') {
$sql .= "and sd.SupplierName = '" . $cname . "'";
}
if ($fa and $aa != '') {
$sql .= " and (pm.PODate >= '" . $fa . "-04-01' and pm.PODate <= '" . $aa . "-03-31')";
}
if ($m != '') {
$sql .= "and monthname(pm.PODate) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
$sql .= "and date(pm.PODate) >= '" . $fromd . "'
and date(pm.PODate) <= '" . $tod . "'";
}
if ($prod != '') {
$sql .= " and mm.MaterialName = '" . $prod . "' ";
}
if ($sid != '') {
$sql .= " and sd.SupplierID = '" . $sid . "' ";
}
if ($mid != '') {
$sql .= " and mm.MaterialCode = '" . $mid . "' ";
}
if ($d != '') {
$sql .= " and date(pm.PODate) = '" . $d . "' ";
}
$sql .= "group by pono,material_name,supplier_name";
//echo $sql;
$query = $this->db->query($sql);
return $query->getResult();
}
function report_finyear()
{
$sql = "SELECT
CASE WHEN MONTH(PODate)>=4 THEN
concat(YEAR(PODate), '-',YEAR(PODate)+1)
ELSE concat(YEAR(PODate)-1,'-', YEAR(PODate)) END AS financial_year
FROM t_purchaseorder_master
GROUP BY financial_year";
$query = $this->db->query($sql);
return $query->getResult();
}
function ireport_finyear()
{
$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_year_wise($a = null, $b = null)
{
$sql = "SELECT sd.SupplierID as sid,mm.MaterialCode as mid,pm.POdate as created_date,ifnull(sum(pl.Quantity),0) as quantity,round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as total
FROM t_purchaseorder_master pm
join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
left join t_service_tax st on st.LineItemNo = pl.LineItemNo
where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and date(pm.POdate) >= '$a-04-01' and date(pm.PODate) <= '$b-03-31'
group by month(created_date)";
$query = $this->db->query($sql);
return $query->getResult();
}
function customer_name()
{
$sql = "SELECT distinct SupplierName FROM t_supplierdetailsn;";
$query = $this->db->query($sql);
return $query->getResult();
}
function material_name()
{
$sql = "SELECT distinct MaterialName FROM t_materialmaster;";
$query = $this->db->query($sql);
return $query->getResult();
}
function category()
{
$sql = "SELECT distinct Category,cd.ConfigValue as Category_name FROM t_materialmaster left join t_configdetails cd on cd.key = t_materialmaster.Category;";
$query = $this->db->query($sql);
return $query->getResult();
}
function report_month_wise($mont)
{
$month = date("m", strtotime($mont));
$year = date("Y", strtotime($mont));
$sql = "SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,ifnull(sum(pl.Quantity),0) as quantity,round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as total
FROM t_purchaseorder_master pm
left join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
left join t_service_tax st on st.LineItemNo = pl.LineItemNo
where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and month(pm.PODate)= ? and year(pm.PODate) = ?
group by supplier_name,material_name";
$query = $this->db->query($sql, array($month, $year));
return $query->getResult();
}
function report_year_wise_total($a, $b)
{
$sql = "SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,ifnull(sum(pl.Quantity),0) as quantity,round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as total
FROM t_purchaseorder_master pm
left join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
left join t_service_tax st on st.LineItemNo = pl.LineItemNo
where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and date(pm.POdate) >= '$a-04-01' and date(pm.PODate) <= '$b-03-31'
group by supplier_name,material_name";
$query = $this->db->query($sql, array());
return $query->getResult();
}
function report_supplier($cname, $fa, $aa, $m, $frm, $t)
{
$sql = "SELECT sd.SupplierID as sid,sd.SupplierName as supplier_name,count(pm.PONO) as counts,ifnull(sum(pl.Quantity),0) as quantity,round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as value,
case pm.POType
when 'IMPORT'
then ifnull((sum(distinct(pl.Quantity * pl.Rate) * pm.ExchangeRate)
),0) + ifnull(rt.Insurance,0)
when 'CAPITAL'
then sum(distinct if(pm.CapitalRange=0,(( pl.Quantity * pl.Rate) * pm.ExchangeRate),( pl.Quantity * pl.Rate)
- st.Afterdiscountval))
+ ifnull(sum(distinct st.After_SGST),0)
+ ifnull(sum(distinct st.After_CGST),0)
+ ifnull(sum(distinct st.After_IGST),0)
+ ifnull(sum(distinct st.AfterFreightValue),0)
+ ifnull(rt.Insurance,0)
when 'SERVICE'
then ifnull(sum(distinct pl.Quantity * pl.Rate),0)
+ ifnull(sum(distinct st.After_SGST),0)
+ ifnull(sum(distinct st.After_CGST),0)
+ ifnull(sum(distinct st.After_IGST),0)
+ ifnull(sum(distinct st.AfterFreightValue),0)
+ ifnull(rt.Insurance,0)
- ifnull(sum(distinct st.Afterdiscountval),0)
when 'REVENUE'
then ifnull(sum(distinct pl.Quantity * pl.Rate),0)
- ifnull(sum(distinct rt.AfterDiscount),0)
+ ifnull(sum(distinct rt.AfterSGST),0)
+ ifnull(sum(distinct rt.AfterCGST),0)
+ ifnull(sum(distinct rt.AfterIGST),0)
+ ifnull(sum(distinct rt.AfterFreightValue),0)
+ ifnull(sum(distinct rt.AfterPackagingValue),0)
+ ifnull(rt.Insurance,0)
end
as total
FROM t_purchaseorder_master pm
left join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
left join t_service_tax st on st.LineItemNo = pl.LineItemNo
left join t_revenue_tax rt on rt.LineItemNo = pl.LineItemNo
where
pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' ";
if ($cname != '') {
$sql .= "and sd.SupplierName = '" . $cname . "'";
}
if ($fa and $aa != '') {
$sql .= " and (pm.PODate >= '" . $fa . "-04-01' and pm.PODate <= '" . $aa . "-03-31')";
}
if ($m != '') {
$sql .= "and monthname(pm.PODate) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
$sql .= "and date(pm.PODate) >= '" . $fromd . "'
and date(pm.PODate) <= '" . $tod . "'";
}
$sql .= "group by supplier_name";
//echo $sql;
$query = $this->db->query($sql);
return $query->getResult();
}
function report_consolidate($cname, $fa, $aa)
{
$sql = "select sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,mm.MaterialName as material_name,
SUM(IF(month(pm.PODate) = 4, pl.Quantity, 0)) AS April,
SUM(IF(month(pm.PODate) = 5, pl.Quantity, 0)) AS May,
SUM(IF(month(pm.PODate) = 6, pl.Quantity, 0)) AS June,
SUM(IF(month(pm.PODate) = 7, pl.Quantity, 0)) AS July,
SUM(IF(month(pm.PODate) = 8, pl.Quantity, 0)) AS August,
SUM(IF(month(pm.PODate) = 9, pl.Quantity, 0)) AS September,
SUM(IF(month(pm.PODate) = 10, pl.Quantity, 0)) AS October,
SUM(IF(month(pm.PODate) = 11, pl.Quantity, 0)) AS November,
SUM(IF(month(pm.PODate) = 12, pl.Quantity, 0)) AS December,
SUM(IF(month(pm.PODate) = 1, pl.Quantity, 0)) AS January,
SUM(IF(month(pm.PODate) = 2, pl.Quantity, 0)) AS February,
SUM(IF(month(pm.PODate) = 3, pl.Quantity, 0)) AS March,
sum(pl.Quantity) as qtotal,
SUM(IF(month(pm.PODate) = 4, pl.Quantity * pl.Rate, 0)) AS vApril,
SUM(IF(month(pm.PODate) = 5, pl.Quantity * pl.Rate, 0)) AS vMay,
SUM(IF(month(pm.PODate) = 6, pl.Quantity * pl.Rate, 0)) AS vJune,
SUM(IF(month(pm.PODate) = 7, pl.Quantity * pl.Rate, 0)) AS vJuly,
SUM(IF(month(pm.PODate) = 8, pl.Quantity * pl.Rate, 0)) AS vAugust,
SUM(IF(month(pm.PODate) = 9, pl.Quantity * pl.Rate, 0)) AS vSeptember,
SUM(IF(month(pm.PODate) = 10, pl.Quantity * pl.Rate, 0)) AS vOctober,
SUM(IF(month(pm.PODate) = 11, pl.Quantity * pl.Rate, 0)) AS vNovember,
SUM(IF(month(pm.PODate) = 12, pl.Quantity * pl.Rate, 0)) AS vDecember,
SUM(IF(month(pm.PODate) = 1, pl.Quantity * pl.Rate, 0)) AS vJanuary,
SUM(IF(month(pm.PODate) = 2, pl.Quantity * pl.Rate, 0)) AS vFebruary,
SUM(IF(month(pm.PODate) = 3, pl.Quantity * pl.Rate, 0)) AS vMarch,
sum(pl.Quantity * pl.Rate) as vtotal
FROM t_purchaseorder_master pm
join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' ";
if ($cname != '') {
$sql .= "and sd.SupplierName = '" . $cname . "'";
}
if ($fa and $aa != '') {
$sql .= " and (pm.PODate >= '" . $fa . "-04-01' and pm.PODate <= '" . $aa . "-03-31')";
}
$sql .= "group by supplier_name,material_name";
//echo $sql;
$query = $this->db->query($sql);
return $query->getResult();
}
function consolidate_month($m = null, $sid = null, $mid = null, $fa = null, $aa = null)
{
$sql = "select mm.Category as category,sd.SupplierID as sid,sd.SupplierName as supplier_name,mm.MaterialCode as mid,mm.MaterialName as material_name,
sum(pl.Quantity) as quantity,
sum(pl.Quantity * pl.Rate) as total
FROM t_purchaseorder_master pm
join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
left join t_service_tax st on st.LineItemNo = pl.LineItemNo
left join t_revenue_tax rt on rt.LineItemNo = pl.LineItemNo
where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and
monthname(pm.PODate) = '" . $m . "' and sd.SupplierID = '" . $sid . "' and mm.MaterialCode = '" . $mid . "' ";
if ($fa and $aa != '') {
$sql .= " and (pm.PODate >= '" . $fa . "-04-01' and pm.PODate <= '" . $aa . "-03-31')";
}
$sql .= "group by supplier_name,material_name";
$query = $this->db->query($sql);
//echo $sql;
return $query->getResult();
}
function consolidate_year($sid = null, $mid = null, $fa = null, $aa = null)
{
$sql = "select mm.Category as category,sd.SupplierID as sid,sd.SupplierName as supplier_name,mm.MaterialCode as mid,mm.MaterialName as material_name,
sum(pl.Quantity) as quantity,
sum(pl.Quantity * pl.Rate) as total
FROM t_purchaseorder_master pm
join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
left join t_service_tax st on st.LineItemNo = pl.LineItemNo
left join t_revenue_tax rt on rt.LineItemNo = pl.LineItemNo
where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierID = '" . $sid . "' and mm.MaterialCode = '" . $mid . "' ";
if ($fa and $aa != '') {
$sql .= " and (pm.PODate >= '" . $fa . "-04-01' and pm.PODate <= '" . $aa . "-03-31')";
}
$sql .= "group by supplier_name,material_name";
$query = $this->db->query($sql);
//echo $sql;
return $query->getResult();
}
function report_cumulative()
{
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
$sql = "SELECT year.sid as sid,year.mid as mid,year.supplier_name as supplier_name,year.material_name as material_name,year.quantity as quantity,year.total as total,month.mquantity as mquantity,month.mtotal as mtotal,today.tquantity as tquantity,today.ttotal as ttotal
FROM (SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,ifnull(sum(pl.Quantity),0) as quantity,round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as total
FROM t_purchaseorder_master pm
left join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and
(pm.PODate >= '" . $fa . "-04-01' and pm.PODate <= '" . $aa . "-03-31')
group by supplier_name,material_name
) as year left join
(SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,ifnull(sum(pl.Quantity),0) as mquantity,round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as mtotal
FROM t_purchaseorder_master pm
left join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and
month(pm.PODate) = month(current_date())
group by supplier_name,material_name
) as month on month.supplier_name=year.supplier_name and month.material_name=year.material_name
left join
(SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,IF(pl.Quantity IS NULL or pl.Quantity = '', 0, sum(pl.Quantity)) as tquantity,ifnull(sum(pl.Quantity * pl.Rate),0) as ttotal
FROM t_purchaseorder_master pm
left join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and
date(pm.PODate) = current_date()
group by supplier_name,material_name
) as today on today.supplier_name=month.supplier_name and today.material_name=month.material_name
group by supplier_name,material_name
";
$query = $this->db->query($sql);
return $query->getResult();
}
function report_cum_month($sup = null, $mat = null)
{
$sql = "SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,IF(pl.Quantity IS NULL or pl.Quantity = '', 0, sum(pl.Quantity)) as tquantity,ifnull(sum(pl.Quantity * pl.Rate),0) as ttotal,
cd.Key as category_id,cd.ConfigValue as category_name
FROM t_purchaseorder_master pm
left join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
left join t_configdetails cd on cd.key = mm.category
where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and month(pm.PODate) = month(current_date()) and sd.SupplierID = '" . $sup . "' and mm.MaterialCode = '" . $mat . "'
group by supplier_name,material_name";
$query = $this->db->query($sql);
return $query->getResult();
}
function report_cum_year($sup = null, $mat = null)
{
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
$sql = "SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,IF(pl.Quantity IS NULL or pl.Quantity = '', 0, sum(pl.Quantity)) as tquantity,ifnull(sum(pl.Quantity * pl.Rate),0) as ttotal
FROM t_purchaseorder_master pm
left join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and
(pm.PODate >= '" . $fa . "-04-01' and pm.PODate <= '" . $aa . "-03-31')
and sd.SupplierID = '" . $sup . "' and mm.MaterialCode = '" . $mat . "'
group by supplier_name,material_name";
$query = $this->db->query($sql);
return $query->getResult();
}
function report_cum_day($sup = null, $mat = null)
{
$sql = "SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,IF(pl.Quantity IS NULL or pl.Quantity = '', 0, sum(pl.Quantity)) as tquantity,ifnull(sum(pl.Quantity * pl.Rate),0) as ttotal
FROM t_purchaseorder_master pm
left join t_purchaseorder_lineitem pl on pl.PONO = pm.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and
date(pm.PODate) = current_date() and sd.SupplierID = '" . $sup . "' and mm.MaterialCode = '" . $mat . "'
group by supplier_name,material_name";
$query = $this->db->query($sql);
return $query->getResult();
}
function ireport_purchase($cname, $prod, $fa, $aa, $m, $frm, $t, $cat)
{
$sql = "select cd.ConfigValue as category_name,im.IGRNO as igrn,pm.POType as potype,im.PONO as pono,date_format(im.CreatedDate,'%d-%m-%Y') as created_date,TIME_FORMAT(im.CreatedDate,'%l:%i %p') as created_time,mm.MaterialName as material_name,mm.Category as category,sd.SupplierName as supplier_name,mm.UOM as UOM, id.QuantityAsPerInvoice as quantity,pl.Rate as rate,round(id.QuantityAsPerInvoice * pl.Rate,2) as value,if(POType = 'IMPORT' or POType = 'CAPITAL',pm.ExchangeRate,0) as exchange_rate,date_format(im.MaterialRcvdDate,'%d-%m-%Y') as materialrcvddate,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) as sgst,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) as cgst,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) as igst,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity),
(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2) as discount,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity),
(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2) as freight,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2) as Package,
round((
if(POType = 'IMPORT',(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)),
if(POType = 'CAPITAL' && CapitalRange = 0,(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)),
ifnull((id.QuantityAsPerInvoice * pl.Rate),0)))
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2)
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2)
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2)
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity),
(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2)
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2)
- round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity),
(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2)),2) as total,
im.file as ifile,pb.FilePath as file,infiles.FilePath as Infiles
from t_igr_master im
left join t_purchaseorder_lineitem pl on pl.PONO = im.PONO
join t_igr_details id on id.IGRNO = im.IGRNO and id.MaterialCode = pl.MaterialCode
join t_purchaseorder_master pm on pm.PONO = pl.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
left join t_service_tax st on st.LineItemNo = pl.LineItemNo
left join t_revenue_tax rt on rt.LineItemNo = pl.LineItemNo
left join t_purchaseorder_billupload pb on pb.IGRNO=im.IGRNO
left join t_inwardgateregister_fileupload infiles on infiles.IGRNO = im.IGRNO
left join t_configdetails cd on cd.key = mm.category
where pm.Status != 'ST030' ";
if ($cname != '') {
$sql .= "and sd.SupplierName = '" . $cname . "'";
}
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$sql .= " and (im.MaterialRcvdDate >= '" . $fa . "-04-01' and im.MaterialRcvdDate <= '" . $aa . "-03-31')";
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$sql .= "and monthname(im.MaterialRcvdDate) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
// $sql.="and date(im.CreatedDate) >= '".$fromd."'
// and date(im.CreatedDate) <= '".$tod."'";
$sql .= "and date(im.MaterialRcvdDate) >= '" . $fromd . "'
and date(im.MaterialRcvdDate) <= '" . $tod . "'";
}
if ($prod != '') {
$sql .= " and mm.MaterialName = '" . $prod . "' ";
}
if ($cat != '') {
$sql .= " and mm.Category = '" . $cat . "' ";
}
$sql .= "group by pono,material_name,category,supplier_name,id.IGRItemNo";
//echo $sql;
$query = $this->db->query($sql);
return $query->getResult();
}
function ireport_purchase_link($cname, $prod, $fa, $aa, $m, $frm, $t, $sid, $mid, $d, $cat, $da, $po)
{
$sql = "select im.IGRNO as igrn,pm.POType as potype,im.PONO as pono,date_format(im.CreatedDate,'%d-%m-%Y') as created_date,TIME_FORMAT(im.CreatedDate,'%l:%i %p') as created_time,mm.MaterialName as material_name,mm.Category as category,sd.SupplierName as supplier_name,mm.UOM as UOM, id.QuantityAsPerInvoice as quantity,pl.Rate as rate,round(id.QuantityAsPerInvoice * pl.Rate,2) as value,if(POType = 'IMPORT' or POType = 'CAPITAL',pm.ExchangeRate,0) as exchange_rate,date_format(im.MaterialRcvdDate,'%d-%m-%Y') as materialrcvddate,cd.ConfigValue as category_name,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) as sgst,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) as cgst,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) as igst,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity),
(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2) as discount,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity),
(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2) as freight,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2) as Package,
round((
if(POType = 'IMPORT',(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)),
if(POType = 'CAPITAL' && CapitalRange = 0,(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)),
ifnull((id.QuantityAsPerInvoice * pl.Rate),0)))
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2)
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2)
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2)
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity),
(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2)
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2)
- round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity),
(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2)),2) as total,
im.file as ifile,pb.FilePath as file,infiles.FilePath as Infiles
from t_igr_master im
left join t_purchaseorder_lineitem pl on pl.PONO = im.PONO
join t_igr_details id on id.IGRNO = im.IGRNO and id.MaterialCode = pl.MaterialCode
join t_purchaseorder_master pm on pm.PONO = pl.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_configdetails cd on cd.Key = mm.category
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
left join t_service_tax st on st.LineItemNo = pl.LineItemNo
left join t_revenue_tax rt on rt.LineItemNo = pl.LineItemNo
left join t_purchaseorder_billupload pb on pb.IGRNO=im.IGRNO
left join t_inwardgateregister_fileupload infiles on infiles.IGRNO = im.IGRNO
where pm.Status != 'ST030' ";
if ($cname != '') {
$sql .= "and sd.SupplierName = '" . $cname . "'";
}
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$sql .= " and (im.MaterialRcvdDate >= '" . $fa . "-04-01' and im.MaterialRcvdDate <= '" . $aa . "-03-31')";
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$sql .= "and monthname(im.MaterialRcvdDate) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
// $sql.="and date(im.CreatedDate) >= '".$fromd."'
// and date(im.CreatedDate) <= '".$tod."'";
$sql .= "and date(im.MaterialRcvdDate) >= '" . $fromd . "'
and date(im.MaterialRcvdDate) <= '" . $tod . "'";
}
if ($prod != '') {
$sql .= " and mm.MaterialName = '" . $prod . "' ";
}
if ($sid != '') {
$sql .= " and sd.SupplierID = '" . $sid . "' ";
}
if ($mid != '') {
$sql .= " and mm.MaterialCode = '" . $mid . "' ";
}
if ($d != '') {
//$sql.=" and date(im.CreatedDate) = '".$d."' ";
$sql .= " and date(im.MaterialRcvdDate) = '" . $d . "' ";
}
if ($cat != '') {
$sql .= " and mm.Category = '" . $cat . "' ";
}
if ($da != '') {
$ddd = date("Y-m-d", strtotime($da));
//$sql.=" and date(im.CreatedDate) = '".$ddd."' ";
$sql .= " and date(im.MaterialRcvdDate) = '" . $ddd . "' ";
}
if ($po != '') {
$sql .= " and im.PONO = '" . $po . "' ";
}
$sql .= "group by pono,material_name,category,supplier_name,id.IGRItemNo";
// echo $m;
// echo $sid;
//echo $sql;
$query = $this->db->query($sql);
return $query->getResult();
}
function ireport_attachment($cname, $fa, $aa, $m, $frm, $t)
{
// $sql="select pono,potype,date_format(created_date,'%d-%m-%Y') as created_date,date_format(materialrcvddate,'%d-%m-%Y') as materialrcvddate,supplier_name,
// sum(total) as total,file,ifile
// from igr
$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,
sum(total) as total,file,ifile
from igr
where status != 'ST030'
";
if ($cname != '') {
$sql .= "and supplier_name = '" . $cname . "'";
}
if ($fa and $aa != '') {
//$sql.=" and (created_date >= '".$fa."-04-01' and created_date <= '".$aa."-03-31')";
$sql .= " and (materialrcvddate >= '" . $fa . "-04-01' and materialrcvddate <= '" . $aa . "-03-31')";
}
if ($m != '') {
//$sql.="and monthname(created_date) = '".$m."'";
$sql .= "and monthname(materialrcvddate) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
// $sql.="and date(created_date) >= '".$fromd."'
// and date(created_date) <= '".$tod."'";
$sql .= "and date(materialrcvddate) >= '" . $fromd . "'
and date(materialrcvddate) <= '" . $tod . "'";
}
$sql .= "group by pono,igrn";
// echo $m;
// echo $sid;
//echo $sql;
$query = $this->db->query($sql);
$filequery = $query->getResult();
$resultArray = array();
foreach ($filequery as $value) {
$tempArray['pono'] = $value->pono;
$tempArray['potype'] = $value->potype;
$tempArray['supplier_name'] = $value->supplier_name;
$tempArray['materialrcvddate'] = $value->materialrcvddate;
$tempArray['total'] = $value->total;
$tempArray['created_date'] = $value->created_date;
$tempArray['file'] = $value->file;
$tempArray['ifile'] = $value->ifile;
$tempArray['igrn'] = $value->igrn;
$sqli = "select FilePath as Infiles from t_inwardgateregister_fileupload where PONO =? and IGRNO =? ";
$querys = $this->db->query($sqli, array($tempArray['pono'], $tempArray['igrn']));
$filepath = $querys->getResult();
$tempArray['Infiles'] = $filepath;
$resultArray[] = $tempArray;
}
return $resultArray;
}
function ireport_year_wise($a, $b)
{
// $sql="select dat as CreatedDate,sum(quantity)as quantity,sum(value) as value, materialrcvddate
// from year_inward
// where status != 'ST030' and date(dat) >= '$a-04-01' and date(dat) <= '$b-03-31'
// group by month(CreatedDate)
// ";
//echo $sql;
$sql = "select materialrcvddate,sum(quantity)as quantity,sum(value) as value
from igr
where status != 'ST030' and date(materialrcvddate) >= '$a-04-01' and date(materialrcvddate) <= '$b-03-31'
group by month(materialrcvddate)";
$query = $this->db->query($sql);
return $query->getResult();
}
function ireport_month_wise($mont)
{
$month = date("m", strtotime($mont));
$year = date("Y", strtotime($mont));
// $sql="select sid,mid,supplier_name,material_name,sum(quantity)as quantity,sum(value) as total
// from year_inward
// where status != 'ST030' and month(dat)= ? and year(dat) = ?
// group by material_name,supplier_name";
$sql = "select sid,mid,supplier_name,material_name,sum(quantity)as quantity,sum(value) as total,materialrcvddate
from igr
where status != 'ST030' and month(materialrcvddate)= ? and year(materialrcvddate) = ?
group by material_name,supplier_name";
$query = $this->db->query($sql, array($month, $year));
return $query->getResult();
}
function ireport_year_wise_total($a, $b)
{
// $sql="select sid,mid,supplier_name,material_name,sum(quantity)as quantity,sum(value) as total
// from year_inward
// where status != 'ST030' and date(dat) >= '$a-04-01' and date(dat) <= '$b-03-31'
// group by material_name,supplier_name";
$sql = "select sid,mid,supplier_name,material_name,sum(quantity)as quantity,sum(value) as total,materialrcvddate
from igr
where status != 'ST030' and date(materialrcvddate) >= '$a-04-01' and date(materialrcvddate) <= '$b-03-31'
group by material_name,supplier_name";
$query = $this->db->query($sql, array());
return $query->getResult();
}
function ireport_supplier($cname, $fa, $aa, $m, $frm, $t)
{
$sql = "SELECT sd.SupplierID as sid,sd.SupplierName as supplier_name,count(im.PONO) as counts,ifnull(sum(id.QuantityAsPerInvoice),0) as quantity,round(ifnull(sum(id.QuantityAsPerInvoice * pl.Rate),0),2) as value,
case pm.POType
when 'IMPORT'
then ifnull((sum((id.QuantityAsPerInvoice * pl.Rate) * pm.ExchangeRate)
+ ifnull(rt.Insurance,0)
),0)
when 'CAPITAL'
then sum( if(pm.CapitalRange=0,(( id.QuantityAsPerInvoice * pl.Rate) * pm.ExchangeRate),( id.QuantityAsPerInvoice * pl.Rate)
- st.Afterdiscountval))
+ ifnull(sum(st.After_SGST),0)
+ ifnull(sum(st.After_CGST),0)
+ ifnull(sum(st.After_IGST),0)
+ ifnull(sum(st.AfterFreightValue),0)
+ ifnull(rt.Insurance,0)
when 'SERVICE'
then ifnull(sum(id.QuantityAsPerInvoice * pl.Rate),0)
+ ifnull(sum(st.After_SGST),0)
+ ifnull(sum(st.After_CGST),0)
+ ifnull(sum(st.After_IGST),0)
+ ifnull(sum(st.AfterFreightValue),0)
+ ifnull(rt.Insurance,0)
- ifnull(sum(st.Afterdiscountval),0)
when 'REVENUE'
then ifnull(sum(id.QuantityAsPerInvoice * pl.Rate),0)
- ifnull(sum(rt.AfterDiscount),0)
+ ifnull(sum(rt.AfterSGST),0)
+ ifnull(sum(rt.AfterCGST),0)
+ ifnull(sum(rt.AfterIGST),0)
+ ifnull(sum(rt.AfterFreightValue),0)
+ ifnull(sum(rt.AfterPackagingValue),0)
+ ifnull(rt.Insurance,0)
end
as total,im.MaterialRcvdDate
from t_igr_master im
left join t_purchaseorder_lineitem pl on pl.PONO = im.PONO
join t_igr_details id on id.IGRNO = im.IGRNO and id.MaterialCode = pl.MaterialCode
join t_purchaseorder_master pm on pm.PONO = pl.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
left join t_service_tax st on st.LineItemNo = pl.LineItemNo
left join t_revenue_tax rt on rt.LineItemNo = pl.LineItemNo
where pm.Status != 'ST030'";
if ($cname != '') {
$sql .= "and sd.SupplierName = '" . $cname . "'";
}
if ($fa and $aa != '') {
//$sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')";
$sql .= " and (im.MaterialRcvdDate >= '" . $fa . "-04-01' and im.MaterialRcvdDate <= '" . $aa . "-03-31')";
}
if ($m != '') {
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
$sql .= "and monthname(im.MaterialRcvdDate) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
// $sql.="and date(im.CreatedDate) >= '".$fromd."'
// and date(im.CreatedDate) <= '".$tod."'";
$sql .= "and date(im.MaterialRcvdDate) >= '" . $fromd . "'
and date(im.MaterialRcvdDate) <= '" . $tod . "'";
}
$sql .= "group by supplier_name";
//echo $sql;
$query = $this->db->query($sql);
return $query->getResult();
}
function ireport_consolidate($cname, $fa, $aa)
{
$sql = "select sid,mid,supplier_name,material_name,
SUM(IF(month(materialrcvddate) = 4, quantity, 0)) AS April,
SUM(IF(month(materialrcvddate) = 5, quantity, 0)) AS May,
SUM(IF(month(materialrcvddate) = 6, quantity, 0)) AS June,
SUM(IF(month(materialrcvddate) = 7, quantity, 0)) AS July,
SUM(IF(month(materialrcvddate) = 8, quantity, 0)) AS August,
SUM(IF(month(materialrcvddate) = 9, quantity, 0)) AS September,
SUM(IF(month(materialrcvddate) = 10, quantity, 0)) AS October,
SUM(IF(month(materialrcvddate) = 11, quantity, 0)) AS November,
SUM(IF(month(materialrcvddate) = 12, quantity, 0)) AS December,
SUM(IF(month(materialrcvddate) = 1, quantity, 0)) AS January,
SUM(IF(month(materialrcvddate) = 2, quantity, 0)) AS February,
SUM(IF(month(materialrcvddate) = 3, quantity, 0)) AS March,
sum(quantity) as qtotal,
SUM(IF(month(materialrcvddate) = 4, value, 0)) AS vApril,
SUM(IF(month(materialrcvddate) = 5, value, 0)) AS vMay,
SUM(IF(month(materialrcvddate) = 6, value, 0)) AS vJune,
SUM(IF(month(materialrcvddate) = 7, value, 0)) AS vJuly,
SUM(IF(month(materialrcvddate) = 8, value, 0)) AS vAugust,
SUM(IF(month(materialrcvddate) = 9, value, 0)) AS vSeptember,
SUM(IF(month(materialrcvddate) = 10, value, 0)) AS vOctober,
SUM(IF(month(materialrcvddate) = 11, value, 0)) AS vNovember,
SUM(IF(month(materialrcvddate) = 12, value, 0)) AS vDecember,
SUM(IF(month(materialrcvddate) = 1, value, 0)) AS vJanuary,
SUM(IF(month(materialrcvddate) = 2, value, 0)) AS vFebruary,
SUM(IF(month(materialrcvddate) = 3, value, 0)) AS vMarch,
sum(value) as vtotal
FROM igr
where status != 'ST030' ";
if ($cname != '') {
$sql .= "and supplier_name = '" . $cname . "'";
}
if ($fa and $aa != '') {
// $sql.=" and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31')";
$sql .= " and (materialrcvddate >= '" . $fa . "-04-01' and materialrcvddate <= '" . $aa . "-03-31')";
}
$sql .= "group by supplier_name,material_name";
// echo $sql;
$query = $this->db->query($sql);
return $query->getResult();
}
function i_consolidate_month($m = null, $sid = null, $mid = null, $fa = null, $aa = null)
{
$sql = "select sid,mid,supplier_name,material_name,sum(quantity) as quantity,sum(value) as total
from igr
where status != 'ST030' and
monthname(materialrcvddate) = '" . $m . "' and sid = '" . $sid . "' and mid = '" . $mid . "' ";
if ($fa and $aa != '') {
//$sql.=" and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31')";
$sql .= " and (materialrcvddate >= '" . $fa . "-04-01' and materialrcvddate <= '" . $aa . "-03-31')";
}
$sql .= "group by supplier_name,material_name";
$query = $this->db->query($sql);
//echo $sql;
return $query->getResult();
}
function i_consolidate_year($sid = null, $mid = null, $fa = null, $aa = null)
{
$sql = "select sid,mid,supplier_name,material_name,sum(quantity) as quantity,sum(value) as total
from igr
where status != 'ST030' and sid = '" . $sid . "' and mid = '" . $mid . "' ";
if ($fa and $aa != '') {
//$sql.=" and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31')";
$sql .= " and (materialrcvddate >= '" . $fa . "-04-01' and materialrcvddate <= '" . $aa . "-03-31')";
}
$sql .= "group by supplier_name,material_name";
$query = $this->db->query($sql);
//echo $sql;
return $query->getResult();
}
function ireport_cumulative()
{
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
$sql = "SELECT year.sid as sid,year.mid as mid,year.supplier_name as supplier_name,year.material_name as material_name,year.quantity as quantity,year.total as total,month.mquantity as mquantity,month.mtotal as mtotal,today.tquantity as tquantity,today.ttotal as ttotal
FROM (SELECT sid,mid,supplier_name,material_name,sum(Quantity) as quantity,sum(value) as total,materialrcvddate
FROM igr
where status != 'ST030' and
(materialrcvddate >= '" . $fa . "-04-01' and materialrcvddate <= '" . $aa . "-03-31')
group by supplier_name,material_name
) as year left join
(SELECT sid,mid,supplier_name,material_name,sum(Quantity) as mquantity,sum(value) as mtotal
FROM igr
where status != 'ST030' and
month(materialrcvddate) = month(current_date())
group by supplier_name,material_name
) as month on month.supplier_name=year.supplier_name and month.material_name=year.material_name
left join
(SELECT sid,mid,supplier_name,material_name,sum(Quantity) as tquantity,sum(value) as ttotal
FROM igr
where status != 'ST030' and
date(materialrcvddate) = current_date()
group by supplier_name,material_name
) as today on today.supplier_name=month.supplier_name and today.material_name=month.material_name
group by supplier_name,material_name
";
$query = $this->db->query($sql);
return $query->getResult();
}
function ireport_cum_month($sup = null, $mat = null)
{
$sql = "SELECT sid,mid,supplier_name,material_name,sum(Quantity) as tquantity,sum(value) as ttotal
FROM igr
where status != 'ST030' and
month(materialrcvddate) = month(current_date()) and sid = '" . $sup . "' and mid = '" . $mat . "'
group by supplier_name,material_name";
$query = $this->db->query($sql);
return $query->getResult();
}
function ireport_cum_year($sup = null, $mat = null)
{
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
$sql = "SELECT sid,mid,supplier_name,material_name,IF(Quantity IS NULL or Quantity = '', 0, sum(Quantity)) as tquantity,sum(value) as ttotal,cd.ConfigValue as category_name
FROM igr
left join t_configdetails cd on cd.key = year.category
where status != 'ST030' and
(materialrcvddate >= '" . $fa . "-04-01' and materialrcvddate <= '" . $aa . "-03-31')
and sid = '" . $sup . "' and mid= '" . $mat . "'
group by supplier_name,material_name
";
$query = $this->db->query($sql);
return $query->getResult();
}
function ireport_cum_day($sup = null, $mat = null)
{
$sql = "SELECT sid,mid,supplier_name,material_name,IF(Quantity IS NULL or Quantity = '', 0, sum(Quantity)) as tquantity,sum(value) as ttotal,cd.ConfigValue as category_name
FROM igr
left join t_configdetails cd on cd.key = year.category
where status != 'ST030' and
date(materialrcvddate) = current_date() and sid = '" . $sup . "' and mid = '" . $mat . "'
group by supplier_name,material_name";
$query = $this->db->query($sql);
return $query->getResult();
}
function rawi_report_cumulative()
{
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
$sql = "SELECT cd.ConfigValue as category_name,cd.key as category_id,
year.category,year.quantity as quantity,year.total as total,month.mquantity as mquantity,month.mtotal as mtotal,today.tquantity as tquantity,today.ttotal as ttotal
FROM (SELECT category,sum(Quantity) as quantity,sum(value) as total
FROM igr
where status != 'ST030' and
(materialrcvddate >= '" . $fa . "-04-01' and materialrcvddate <= '" . $aa . "-03-31')
group by category
) as year left join
(SELECT category,sum(Quantity) as mquantity,sum(value) as mtotal
FROM igr
where status != 'ST030' and
month(materialrcvddate) = month(current_date())
group by category
) as month on month.category=year.category
left join
(SELECT category,sum(Quantity) as tquantity,sum(value) as ttotal
FROM igr
where status != 'ST030' and
date(materialrcvddate) = current_date()
group by category
) as today on today.category=month.category
left join t_configdetails cd on cd.key = year.category
group by category ";
$query = $this->db->query($sql);
return $query->getResult();
}
function rawi_report_cum_year($cat = null)
{
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
$sql = "SELECT category,sid,mid,supplier_name,material_name,IF(Quantity IS NULL or Quantity = '', 0, sum(Quantity)) as tquantity,sum(value) as ttotal,cd.ConfigValue as category_name
FROM igr
left join t_configdetails cd on cd.key = igr.category
where status != 'ST030' and
(materialrcvddate >= '" . $fa . "-04-01' and materialrcvddate <= '" . $aa . "-03-31')
and category = '" . $cat . "'
group by supplier_name,material_name";
$query = $this->db->query($sql);
//echo $sql;
return $query->getResult();
}
function rawi_report_cum_month($cat = null)
{
$sql = "SELECT category,sid,mid,supplier_name,material_name,IF(Quantity IS NULL or Quantity = '', 0, sum(Quantity)) as tquantity,sum(value) as ttotal,cd.ConfigValue as category_name
FROM igr
left join t_configdetails cd on cd.Key = igr.category
where status != 'ST030' and
month(materialrcvddate) = month(current_date()) and category = '" . $cat . "'
group by supplier_name,material_name";
$query = $this->db->query($sql);
return $query->getResult();
}
function rawi_report_cum_day($cat = null)
{
$sql = "SELECT category,sid,mid,supplier_name,material_name,IF(Quantity IS NULL or Quantity = '', 0, sum(Quantity)) as tquantity,sum(value) as ttotal,cd.ConfigValue as category_name
FROM igr
left join t_configdetails cd on cd.Key = igr.category
where status != 'ST030' and
date(materialrcvddate) = current_date() and category = '" . $cat . "'
group by supplier_name,material_name";
$query = $this->db->query($sql);
//echo $sql;
return $query->getResult();
}
function rawi_report_consolidate($cname, $fa, $aa)
{
$sql = "select sid,mid,category,supplier_name,material_name,
SUM(IF(month(materialrcvddate) = 4, quantity, 0)) AS April,
SUM(IF(month(materialrcvddate) = 5, quantity, 0)) AS May,
SUM(IF(month(materialrcvddate) = 6, quantity, 0)) AS June,
SUM(IF(month(materialrcvddate) = 7, quantity, 0)) AS July,
SUM(IF(month(materialrcvddate) = 8, quantity, 0)) AS August,
SUM(IF(month(materialrcvddate) = 9, quantity, 0)) AS September,
SUM(IF(month(materialrcvddate) = 10, quantity, 0)) AS October,
SUM(IF(month(materialrcvddate) = 11, quantity, 0)) AS November,
SUM(IF(month(materialrcvddate) = 12, quantity, 0)) AS December,
SUM(IF(month(materialrcvddate) = 1, quantity, 0)) AS January,
SUM(IF(month(materialrcvddate) = 2, quantity, 0)) AS February,
SUM(IF(month(materialrcvddate) = 3, quantity, 0)) AS March,
sum(quantity) as qtotal,
SUM(IF(month(materialrcvddate) = 4, value, 0)) AS vApril,
SUM(IF(month(materialrcvddate) = 5, value, 0)) AS vMay,
SUM(IF(month(materialrcvddate) = 6, value, 0)) AS vJune,
SUM(IF(month(materialrcvddate) = 7, value, 0)) AS vJuly,
SUM(IF(month(materialrcvddate) = 8, value, 0)) AS vAugust,
SUM(IF(month(materialrcvddate) = 9, value, 0)) AS vSeptember,
SUM(IF(month(materialrcvddate) = 10, value, 0)) AS vOctober,
SUM(IF(month(materialrcvddate) = 11, value, 0)) AS vNovember,
SUM(IF(month(materialrcvddate) = 12, value, 0)) AS vDecember,
SUM(IF(month(materialrcvddate) = 1, value, 0)) AS vJanuary,
SUM(IF(month(materialrcvddate) = 2, value, 0)) AS vFebruary,
SUM(IF(month(materialrcvddate) = 3, value, 0)) AS vMarch,
sum(value) as vtotal,cd.ConfigValue as category_name
FROM igr
left join t_configdetails cd on cd.Key = igr.category
where status != 'ST030' ";
if ($cname != '') {
$sql .= "and Category = '" . $cname . "'";
}
if ($fa and $aa != '') {
//$sql.=" and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31')";
$sql .= " and (materialrcvddate >= '" . $fa . "-04-01' and materialrcvddate <= '" . $aa . "-03-31')";
}
$sql .= "group by category";
//echo $sql;
$query = $this->db->query($sql);
return $query->getResult();
}
function rawi_consolidate_month($m = null, $cat = null, $sup = null, $fa = null, $aa = null)
{
$sql = "select category,sid,supplier_name,mid,material_name,
sum(Quantity) as quantity,
sum(value) as total,cd.ConfigValue as category_name
FROM igr
left join t_configdetails cd on cd.Key = igr.category
where status != 'ST030' and
monthname(materialrcvddate) = '" . $m . "' and category = '" . $cat . "' ";
if ($fa and $aa != '') {
$sql .= " and (materialrcvddate >= '" . $fa . "-04-01' and materialrcvddate <= '" . $aa . "-03-31')";
}
$sql .= "group by category,supplier_name,material_name";
$query = $this->db->query($sql);
//echo $sql;
return $query->getResult();
}
function rawi_consolidate_year($cat = null, $sup = null, $fa = null, $aa = null)
{
$sql = "select category,sid,supplier_name,mid,material_name,
sum(Quantity) as quantity,
sum(value) as total,cd.ConfigValue as category_name
FROM igr
left join t_configdetails cd on cd.Key = igr.category
where status != 'ST030' and
category = '" . $cat . "' ";
if ($fa and $aa != '') {
$sql .= " and (materialrcvddate >= '" . $fa . "-04-01' and materialrcvddate <= '" . $aa . "-03-31')";
}
$sql .= "group by category,supplier_name,material_name";
$query = $this->db->query($sql);
//echo $sql;
return $query->getResult();
}
function pending_purchase($cname, $prod, $fa, $aa, $m, $frm, $t, $purchaseorder_number)
{
$sql = "select po.PONO as po,
date_format(po.PODate,'%d-%m-%Y') as pdate,
sup.SupplierName as supplier,
mm.MaterialName as material,
cd.ConfigValue as category,
pl.Quantity as quantity,
pl.ReceivedQuantity as received,
(pl.Quantity - pl.ReceivedQuantity) as pending
from t_purchaseorder_lineitem pl
join t_purchaseorder_master po on po.PONO = pl.PONO
join t_supplierdetailsn sup on sup.SupplierID=po.SupplierID
join t_materialmaster mm on mm.MaterialCode=pl.MaterialCode
join t_configdetails cd on cd.key = mm.Category
where po.Status != 'ST030' and po.Status = 'ST026'
";
if ($cname != '') {
$sql .= "and sup.SupplierName = '" . $cname . "'";
}
if ($fa and $aa != '') {
$sql .= " and (po.PODate >= '" . $fa . "-04-01' and po.PODate <= '" . $aa . "-03-31')";
}
if ($m != '') {
$sql .= "and monthname(po.PODate) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
$sql .= "and date(po.PODate) >= '" . $fromd . "'
and date(po.PODate) <= '" . $tod . "'";
}
if ($prod != '') {
$sql .= " and mm.MaterialName = '" . $prod . "' ";
}
// if ($cat!= ''){
// $sql.=" and mm.Category = '".$cat."' ";
// }
if ($purchaseorder_number != '') {
$sql .= " and po.PONO = '" . $purchaseorder_number . "' ";
}
$sql .= "order by date(po.PODate) desc";
$query = $this->db->query($sql);
//echo $sql;
return $query->getResult();
}
function monthly_gst_purchase($m, $frm, $t, $fa, $aa)
{
$sql = "select sum(sgst) as sgst,sum(cgst) as cgst,sum(igst) as igst,sum(sgst + cgst + igst) as total from igr
where pono != 'null' ";
if ($m != '') {
$sql .= "and monthname(materialrcvddate) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
$sql .= "and materialrcvddate >= '" . $fromd . "'
and materialrcvddate <= '" . $tod . "'";
}
if ($fa and $aa != '') {
$sql .= " and (materialrcvddate >= '" . $fa . "-04-01' and materialrcvddate <= '" . $aa . "-03-31')";
}
//echo $sql;
$query = $this->db->query($sql);
return $query->getResult();
}
public function monthly_gst_sales($m = null, $frm = null, $t = null, $fa = null, $aa = null)
{
$sql = "select ii.invoice_id as invoice_id,ifnull(iii.invnum,'-') as parent_invoice_id,ii.client_id as client_id,ii.invoice_number as invoice_number,date_format(ii.invoice_date_created,'%d-%m-%Y') as dates,TIME_FORMAT(ii.invoice_time_created,'%l:%i %p') as invoice_time_created,icf.invoice_custom_fieldvalue as vehicle_no,ip.product_description as product_description,concat(ic.client_name,'-',ic.client_surname)as client_name,sum(iit.item_quantity) as item_quantity,sum(iit.item_price) as item_price,sum(iia.item_subtotal) as item_subtotal,
sum(ifnull(((sgst.tax_rate_percent * (iia.item_subtotal))/100),0))
as sgst,
sum(ifnull(((iia.item_subtotal) * cgst.tax_rate_percent)/100,0))
as cgst,
sum(ifnull((igst.tax_rate_percent * (iia.item_subtotal))/100,0))
as igst,
sum((ifnull(((sgst.tax_rate_percent * iia.item_subtotal)/100),0)
+
ifnull(((iia.item_subtotal * cgst.tax_rate_percent)/100),0)
+
ifnull(((igst.tax_rate_percent * iia.item_subtotal)/100),0)))
as total
from ip_invoices ii
join ip_invoice_custom icf on icf.invoice_id = ii.invoice_id
join ip_invoice_items iit on iit.invoice_id = ii.invoice_id
join ip_invoice_item_amounts iia on iia.item_id = iit.item_id
join ip_clients ic on ic.client_id = ii.client_id
join ip_products ip on ip.product_id = iit.item_product_id
left join ip_tax_rates sgst on sgst.tax_rate_id = iit.sgst_item_tax_rate_id
left join ip_tax_rates cgst on cgst.tax_rate_id = iit.cgst_item_tax_rate_id
left join ip_tax_rates igst on igst.tax_rate_id = iit.igst_item_tax_rate_id
left join (select inv.invoice_id as inv_id,inv.invoice_number,iii.invnum from ip_invoices inv
left join
(select ii.invoice_id as ii,ii.invoice_number as invnum,ic.invoice_number as icnum,ic.creditinvoice_parent_id as cp from ip_invoices as ii
left join ip_invoices as ic on ii.invoice_id = ic.creditinvoice_parent_id) as iii
on iii.icnum = inv.invoice_number) as iii on iii.inv_id = ii.invoice_id
where icf.invoice_custom_fieldid = '8' and ii.invoice_status_id != 1 ";
if ($m != '') {
$sql .= "and monthname(ii.invoice_date_created) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromdate = date("Y-m-d", strtotime($frm));
$todate = date("Y-m-d", strtotime($t));
$sql .= "and ii.invoice_date_created >= '" . $fromdate . "'
and ii.invoice_date_created <= '" . $todate . "'";
}
if ($fa and $aa != '') {
$sql .= " and (ii.invoice_date_created >= '" . $fa . "-04-01' and ii.invoice_date_created <= '" . $aa . "-03-31')";
}
//echo $sql;
$query = $this->db->query($sql);
return $query->getResult();
}
function sales_gst($m = null, $frm = null, $t = null, $fa = null, $aa = null)
{
$sql = "select ii.invoice_id as invoice_id,'Sales' as doc_type,ip.product_sku as hsn_code,ifnull(iii.invnum,'-') as parent_invoice_id,ii.client_id as client_id,ii.invoice_number as doc_no,date_format(ii.invoice_date_created,'%d-%m-%Y') as date,TIME_FORMAT(ii.invoice_time_created,'%l:%i %p') as invoice_time_created,icf.invoice_custom_fieldvalue as vehicle_no,ip.product_description as product_description,concat(ic.client_name,'-',ic.client_surname)as client_name,sum(iit.item_quantity) as item_quantity,sum(iit.item_price) as item_price,sum(iia.item_subtotal) as value,
sum(ifnull(((sgst.tax_rate_percent * (iia.item_subtotal))/100),0))
as sgst,
sum(ifnull(((iia.item_subtotal) * cgst.tax_rate_percent)/100,0))
as cgst,
sum(ifnull((igst.tax_rate_percent * (iia.item_subtotal))/100,0))
as igst,
sum((iia.item_subtotal + ifnull(((sgst.tax_rate_percent * iia.item_subtotal)/100),0)
+
ifnull(((iia.item_subtotal * cgst.tax_rate_percent)/100),0)
+
ifnull(((igst.tax_rate_percent * iia.item_subtotal)/100),0)))
as total
from ip_invoices ii
join ip_invoice_custom icf on icf.invoice_id = ii.invoice_id
join ip_invoice_items iit on iit.invoice_id = ii.invoice_id
join ip_invoice_item_amounts iia on iia.item_id = iit.item_id
join ip_clients ic on ic.client_id = ii.client_id
join ip_products ip on ip.product_id = iit.item_product_id
left join ip_tax_rates sgst on sgst.tax_rate_id = iit.sgst_item_tax_rate_id
left join ip_tax_rates cgst on cgst.tax_rate_id = iit.cgst_item_tax_rate_id
left join ip_tax_rates igst on igst.tax_rate_id = iit.igst_item_tax_rate_id
left join (select inv.invoice_id as inv_id,inv.invoice_number,iii.invnum from ip_invoices inv
left join
(select ii.invoice_id as ii,ii.invoice_number as invnum,ic.invoice_number as icnum,ic.creditinvoice_parent_id as cp from ip_invoices as ii
left join ip_invoices as ic on ii.invoice_id = ic.creditinvoice_parent_id) as iii
on iii.icnum = inv.invoice_number) as iii on iii.inv_id = ii.invoice_id
where icf.invoice_custom_fieldid = '8' and ii.invoice_status_id != 1 and ii.invoice_status_id != 1 ";
if ($m != '') {
$sql .= "and monthname(ii.invoice_date_created) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromdate = date("Y-m-d", strtotime($frm));
$todate = date("Y-m-d", strtotime($t));
$sql .= "and ii.invoice_date_created >= '" . $fromdate . "'
and ii.invoice_date_created <= '" . $todate . "'";
}
if ($fa and $aa != '') {
$sql .= " and (ii.invoice_date_created >= '" . $fa . "-04-01' and ii.invoice_date_created <= '" . $aa . "-03-31')";
}
// echo $fromdate;
//echo $sql;
$sql .= "group by doc_no,product_description";
$query = $this->db->query($sql);
return $query->getResult();
}
function purchase_gst($m, $frm, $t, $fa, $aa)
{
$sql = "select im.IGRNO as igrn,pm.POType as potype,im.PONO as doc_no,'Purchase' as doc_type,mm.HSNCODE as hsn_code,mm.MaterialName as material_name,mm.Category as category,sd.SupplierName as supplier_name,mm.UOM as UOM, id.QuantityAsPerInvoice as quantity,pl.Rate as rate,round(id.QuantityAsPerInvoice * pl.Rate,2) as value,if(POType = 'IMPORT' or POType = 'CAPITAL',pm.ExchangeRate,0) as exchange_rate,date_format(im.MaterialRcvdDate,'%d-%m-%Y') as date,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) as sgst,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) as cgst,
round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) as igst,
(round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2)
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity),
(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2)
- round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity),
(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2)) as others,
round((
if(POType = 'IMPORT',(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)),
if(POType = 'CAPITAL' && CapitalRange = 0,(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)),
ifnull((id.QuantityAsPerInvoice * pl.Rate),0)))
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2)
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2)
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity),
(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2)
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity),
(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2)
+ round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2)
- round(ifnull(if(POType = 'REVENUE',
(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity),
(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2)),2) as total,
im.file as ifile,pb.FilePath as file
from t_igr_master im
left join t_purchaseorder_lineitem pl on pl.PONO = im.PONO
join t_igr_details id on id.IGRNO = im.IGRNO and id.MaterialCode = pl.MaterialCode
join t_purchaseorder_master pm on pm.PONO = pl.PONO
left join t_materialmaster mm on mm.MaterialCode = pl.MaterialCode
left join t_supplierdetailsn sd on sd.SupplierID = pm.SupplierID
left join t_service_tax st on st.LineItemNo = pl.LineItemNo
left join t_revenue_tax rt on rt.LineItemNo = pl.LineItemNo
left join t_purchaseorder_billupload pb on pb.IGRNO=im.IGRNO
where pm.Status != 'ST030' ";
if ($m != '') {
$sql .= "and monthname(materialrcvddate) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
$sql .= "and date(materialrcvddate) >= '" . $fromd . "'
and date(materialrcvddate) <= '" . $tod . "'";
}
if ($fa and $aa != '') {
$sql .= " and (materialrcvddate >= '" . $fa . "-04-01' and materialrcvddate <= '" . $aa . "-03-31')";
}
$sql .= "group by doc_no,material_name,category,supplier_name,id.IGRItemNo";
//echo $sql;
$query = $this->db->query($sql);
return $query->getResult();
}
function report_inwardcashbook($cname, $fa, $aa, $m, $frm, $t, $cat)
{
$sql = "select tinex.account_code as AccountCode,date_format(tinex.date,'%d-%m-%Y') as Date,ac.name as AccountName,date_format(tinex.created_on,'%d-%m-%Y') as CreatedDate,
tinex.type as type,tinex.cashtype as category ,tinex.merchant as merchantname,tinex.Supplier_id as Supplierid,sup.SupplierName as Suppliername, tinex.sgst as sgst,
tinex.value_before_gst as Value,tinex.cgst as cgst,tinex.igst as igst,tinex.document as cashbookfile,
tinex.total as Total
FROM t_income_expense tinex
join t_accountcode ac on ac.code = tinex.account_code
join t_supplierdetailsn sup on sup.SupplierID = tinex.Supplier_id
where tinex.gststatus = '1' ";
if ($cname != '') {
// $sql.="and tinex.merchant = '".$cname."'";
$sql .= "and sup.SupplierName = '" . $cname . "'";
}
if ($fa and $aa != '') {
$sql .= " and (tinex.date >= '" . $fa . "-04-01' and tinex.date <= '" . $aa . "-03-31')";
}
if ($m != '') {
$sql .= "and monthname(tinex.date) = '" . $m . "'";
}
if ($frm and $t != '') {
$fromd = date("Y-m-d", strtotime($frm));
$tod = date("Y-m-d", strtotime($t));
$sql .= "and date(tinex.date) >= '" . $fromd . "'
and date(tinex.date) <= '" . $tod . "'";
}
if ($cat != '') {
$sql .= " and tinex.type = '" . $cat . "' ";
}
$query = $this->db->query($sql);
return $query->getResult();
}
function cashbook()
{
$sql = "SELECT date_format(tinc.date,'%d-%m-%Y')as date,
ifnull(case
when tinc.type = 'PAYMENT'
then tinc.total
end,'0') as expense,
ifnull(case
when tinc.type = 'RECEIPT'
then tinc.total
end, '0') as income,
ifnull(case
when tinc.type = 'PAYMENT'
then tinc.towhom
end,'-') as paymentname,
ifnull(case
when tinc.type = 'RECEIPT'
then tinc.towhom
end, '-') as receiptname,
tinc.total,tinc.towhom,tinc.description,tinc.type,tinc.account_code,ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code ";
$query = $this->db->query($sql);
return $query->getResult();
}
//home --this month//
function monthexpensereport($month, $year)
{
$sql = "SELECT date_format(tinc.date,'%d-%m-%Y')as date,
ifnull(case
when tinc.type = 'PAYMENT'
then sum(tinc.total)
end,'0') as expense,
ifnull(case
when tinc.type = 'RECEIPT'
then sum(tinc.total)
end, '0') as income,
ifnull(case
when tinc.type = 'PAYMENT'
then tinc.towhom
end,'-') as paymentname,
ifnull(case
when tinc.type = 'RECEIPT'
then tinc.towhom
end, '-') as receiptname,
tinc.total,tinc.towhom,tinc.description,monthname(tinc.date)as month,tinc.type,tinc.account_code,ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code where month(tinc.date)= " . $month . " and year(tinc.date)=" . $year . " group by tinc.account_code";
//tinc.total,tinc.towhom,tinc.description,monthname(tinc.date)as month,tinc.type,tinc.account_code,ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code where month(tinc.date)= month(current_date())group by tinc.account_code";
$query = $this->db->query($sql);
return $query->getResult();
}
//home--this year//
function yearexpensereport($fa, $aa)
{
$sql = "select monthname(date) as month,
sum(if(type='PAYMENT',total,0)) as exp,
sum(if(type='RECEIPT',total,0)) as inc,
sum(total) as total
from t_income_expense
where date >= '" . $fa . "-04-01' and date <= '" . $aa . "-03-31'
group by month
ORDER BY FIELD(month,'April','May','June','July','August','September','October','November','December','January', 'February', 'March') ";
$query = $this->db->query($sql);
return $query->getResult();
}
/** //home--report--Day Wise Report //
function today_data($value='')
{
$sql="SELECT type,Sum(total) as todaydata FROM t_income_expense WHERE type = ? AND DATE(date) = CURRENT_DATE";
$query = $this->db->query($sql,array($value));
return $query->getResult();
}
function monthwise_data($value='')
{
$sql="SELECT type,Sum(total) as monthlydata FROM t_income_expense WHERE type = ? AND MONTH(date) = MONTH(curdate())";
$query = $this->db->query($sql,array($value));
return $query->getResult();
}
function yearwise_data($value='')
{
if (date('m') >= 4) {
$yearl = date('Y').'-'.(date('Y')+1);
} else {
$yearl = (date('Y')-1).'-'.date('Y');
}
$ab=$yearl;
$fa=substr($ab,0,-5);
$aa=substr($ab,5,5);
$sql="SELECT type,sum(total) as yearlydata from t_income_expense
where
type = ? and (date >= '".$fa."-04-01' and date <= '".$aa."-03-31')";
$query = $this->db->query($sql,array($value));
return $query->getResult();
}**/
//home--report--Day Wise Report //
function today_data()
{
$sql = "SELECT sum(if(type = 'RECEIPT',total,0)) as daily_income_amt,
sum(if(type = 'PAYMENT',total,0)) as daily_expenses_amt
FROM t_income_expense
WHERE DATE(date) = CURRENT_DATE";
$query = $this->db->query($sql);
return $query->getResult();
}
function monthwise_data()
{
//$sql="SELECT type,Sum(total) as monthlydata FROM t_income_expense WHERE type = ? AND MONTH(date) = MONTH(curdate())";
$sql = "SELECT sum(if(type = 'RECEIPT',total,0)) as monthly_income_amt,
sum(if(type = 'PAYMENT',total,0)) as monthly_expenses_amt
FROM t_income_expense
WHERE YEAR(date) = YEAR(curdate()) AND MONTH(date) = MONTH(curdate())";
$query = $this->db->query($sql);
//,array($value));
return $query->getResult();
}
function yearwise_data()
{
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
$sql = "SELECT sum(if(type = 'RECEIPT',total,0)) as yearly_income_amt,
sum(if(type = 'PAYMENT',total,0)) as yearly_expenses_amt
FROM t_income_expense
WHERE (date >= '" . $fa . "-04-01' and date <= '" . $aa . "-03-31')";
$query = $this->db->query($sql);
return $query->getResult();
}
function departmentwise($sid, $d, $c = '', $fy = null, $ty = null)
{
$sql = "SELECT date_format(tinc.date,'%d-%m-%Y')as date,
ifnull(case
when tinc.type = 'PAYMENT'
then tinc.total
end,'0') as expense,
ifnull(case
when tinc.type = 'RECEIPT'
then tinc.total
end, '0') as income,
ifnull(case
when tinc.type = 'PAYMENT'
then tinc.towhom
end,'-') as paymentname,
ifnull(case
when tinc.type = 'RECEIPT'
then tinc.towhom
end, '-') as receiptname,
date_format(tinc.date,'%d-%m-%Y')as date,tinc.type,tinc.total,tinc.document,tinc.towhom,.tinc.description, ac.name FROM
t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code
WHERE tinc.type='$c'";
if ($sid != '') {
$sql .= "and account_code = '" . $sid . "'";
}
if ($d != '') {
$sql .= "and monthname(date)='" . $d . "'";
}
if ($fy and $ty != '') {
$sql .= " and (tinc.date >= '" . $fy . "-04-01' and tinc.date <= '" . $ty . "-03-31')";
}
// -- WHERE account_code = '$sid' and monthname(date)='$d' and tinc.type='$c'";
$query = $this->db->query($sql);
return $query->getResult();
}
//yearwise/month//
function yearmonthwise($sid = '')
{
$sql = "SELECT date_format(tinc.date,'%d-%m-%Y')as date,
ifnull(case
when tinc.type = 'PAYMENT'
then sum(tinc.total)
end,'0') as expense,
ifnull(case
when tinc.type = 'RECEIPT'
then sum(tinc.total)
end, '0') as income,
ifnull(case
when tinc.type = 'PAYMENT'
then tinc.towhom
end,'-') as paymentname,
ifnull(case
when tinc.type = 'RECEIPT'
then tinc.towhom
end, '-') as receiptname,
date_format(tinc.date,'%d-%m-%Y')as date,tinc.type,tinc.account_code,sum(tinc.total)as total,monthname(tinc.date)as month,tinc.description,tinc.towhom,tinc.account_code,ac.name FROM t_income_expense tinc
join t_accountcode ac on ac.code=tinc.account_code
WHERE monthname(date) = ? group by tinc.account_code";
$query = $this->db->query($sql, array($sid));
return $query->getResult();
}
//for dashboard graph in cashbook//
function gettoptotal()
{
$i = 1;
while ($i <= 12) {
$sql = "SELECT sum(total) as tot FROM t_income_expense where month(date)= $i";
// $sql="SELECT sum(total)as ttl,concat(sum(total),'-',account_code)as atotal FROM t_income_expense where month(date)= $i
// group by account_code order by ttl desc limit 4";
$query = $this->db->query($sql);
//return $query->getResult();
$array_result[] = $query->getResult();
$i++;
}
return $array_result;
}
function INRSymbol()
{
$sql = 'select FontCode2000 from t_currency_details where Currency_Code="INR"';
$query = $this->db->query($sql);
return $query->getResult();
}
function cashbookfinyear()
{
$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 today()
{
$sql = "SELECT date_format(tinc.date,'%d-%m-%Y')as date,
ifnull(case
when tinc.type = 'PAYMENT'
then tinc.total
end,'0') as expense,
ifnull(case
when tinc.type = 'RECEIPT'
then tinc.total
end, '0') as income,
ifnull(case
when tinc.type = 'PAYMENT'
then tinc.towhom
end,'-') as paymentname,
ifnull(case
when tinc.type = 'RECEIPT'
then tinc.towhom
end, '-') as receiptname,
tinc.total,tinc.towhom,tinc.description,tinc.document,tinc.type,tinc.account_code,ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code WHERE DATE(date) = CURRENT_DATE";
$query = $this->db->query($sql);
return $query->getResult();
}
// $sql="SELECT date_format(tinc.date,'%d-%m-%Y')as date,tinc.type,tinc.total,tinc.towhom,tinc.description,tinc.account_code,tac.name FROM t_income_expense tinc
// LEFT JOIN t_accountcode tac ON tac.code = tinc.account_code
// WHERE DATE(date) = CURRENT_DATE";
// $query = $this->db->query($sql);
// return $query->getResult();
//}
function monthlypayments()
{
$sql = "SELECT date_format(tinc.date,'%d-%m-%Y')as date,tinc.type,tinc.total,tinc.towhom,.tinc.description, ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code WHERE MONTH(date) = MONTH(curdate()) group by account_code";
$query = $this->db->query($sql);
return $query->getResult();
}
//home page --Reports//
function departmentmenu($fdate, $tdate, $fa, $aa)
{
$sql = "SELECT date_format(tinc.date,'%d-%m-%Y')as date,
ifnull(case
when tinc.type = 'PAYMENT'
then tinc.total
end,'0') as expense,
ifnull(case
when tinc.type = 'RECEIPT'
then tinc.total
end, '0') as income,
ifnull(case
when tinc.type = 'PAYMENT'
then tinc.towhom
end,'-') as paymentname,
ifnull(case
when tinc.type = 'RECEIPT'
then tinc.towhom
end, '-') as receiptname,
tinc.total,tinc.towhom,tinc.description,tinc.type,tinc.document,tinc.account_code,ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code where tinc.date !=0 ";
if ($fdate and $tdate != '') {
$fdate = date("Y-m-d", strtotime($fdate));
$tdate = date("Y-m-d", strtotime($tdate));
$sql .= "and date(tinc.date) >= '" . $fdate . "'
and date(tinc.date) <= '" . $tdate . "'";
}
if ($fa and $aa != '') {
$sql .= " and (tinc.date >= '" . $fa . "-04-01' and tinc.date <= '" . $aa . "-03-31')";
}
$query = $this->db->query($sql);
//echo $fdate;
//echo $sql;
return $query->getResult();
}
function menudepartmentwise($sid = '')
{
$sql = "SELECT date_format(tinc.date,'%d-%m-%Y')as date,tinc.type,tinc.total,tinc.document,tinc.towhom,tinc.description, ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code
WHERE account_code = '$sid'";
$query = $this->db->query($sql);
//echo $sql;
return $query->getResult();
}
function report_cumulative_cashbook()
{
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
$sql = "SELECT year.name as name,year.yearexpense as yexp,year.yearincome as yinc,month.monthexpense as mexp,month.monthincome as minc,today.todayexpense as texp,today.todayincome as tinc
FROM (select ac1.name, ifnull(case
when tinc1.type = 'PAYMENT'
then sum(tinc1.total)
end,'0') as yearexpense,
ifnull(case
when tinc1.type = 'RECEIPT'
then sum(tinc1.total)
end, '0') as yearincome
FROM t_income_expense tinc1
join t_accountcode ac1 on ac1.code = tinc1.account_code
WHERE (tinc1.date >= '" . $fa . "-04-01' and tinc1.date <= '" . $aa . "-03-31')
group by ac1.name ) as year
left join
(select ac2.name ,ifnull(case
when tinc2.type = 'PAYMENT'
then sum(tinc2.total)
end,'0') as monthexpense,
ifnull(case
when tinc2.type = 'RECEIPT'
then sum(tinc2.total)
end, '0') as monthincome
FROM t_income_expense tinc2
join t_accountcode ac2 on ac2.code = tinc2.account_code
where month(tinc2.date) = month(current_date())
group by ac2.name) as month on month.name = year.name
left join
(select ac3.name ,ifnull(case
when tinc3.type = 'PAYMENT'
then sum(tinc3.total)
end,'0') as todayexpense,
ifnull(case
when tinc3.type = 'RECEIPT'
then sum(tinc3.total)
end, '0') as todayincome
FROM t_income_expense tinc3
join t_accountcode ac3 on ac3.code = tinc3.account_code
where date(tinc3.date) = current_date()
group by ac3.name ) as today on today.name=month.name
group by name ";
$query = $this->db->query($sql);
return $query->getResult();
}
/** function monthbeforetotal($month,$year){
$sql="SELECT month(date) as monthnum ,year(date) as yearnum,
sum(if(type = 'PAYMENT',total,0)) as payment_amt,
sum(if(type = 'RECEIPT',total,0)) as receipt_amt
FROM t_income_expense
WHERE
month(date) = '".$month."'and year(date) = '".$year."'";
$query = $this->db->query($sql);
return $query->getResult();
}
function yearbeforetotal($pre,$curr){
$sql="SELECT
sum(if(type = 'PAYMENT',total,0)) as payment_amt,
sum(if(type = 'RECEIPT',total,0)) as receipt_amt
FROM t_income_expense
where date >= '".$pre."-04-01' and date <= '".$curr."-03-31'";
$query = $this->db->query($sql);
return $query->getResult();
//print_r($query->result());
}
function daybeforetotal($yesterday){
$sql="select date,
sum(if(type = 'PAYMENT',total,0)) as payment_amt,
sum(if(type = 'RECEIPT',total,0)) as receipt_amt
from t_income_expense
where date = ? ";
$query = $this->db->query($sql,array($yesterday));
return $query->getResult();
}**/
function getYearlyOpeningAmt($prev_year)
{
$sql = "SELECT min(date),(sum(if(type = 'RECEIPT',total,0)) - sum(if(type = 'PAYMENT',total,0)) ) as opening_amt
FROM t_income_expense
WHERE date >= (select min(date) from t_income_expense) and date <= '" . $prev_year . "-03-31' ";
$query = $this->db->query($sql);
return $query->getResult();
//print_r($query->result());
}
//function monthbeforetotal($month,$year){
function getMonthlyOpeningAmt($dateformat)
{
$sql = "SELECT month('" . $dateformat . "') as monthnum ,year('" . $dateformat . "') as yearnum,
(sum(if(type = 'RECEIPT',total,0)) - sum(if(type = 'PAYMENT',total,0))) as opening_amt
FROM t_income_expense
WHERE date >= (select min(date) from t_income_expense) and date <= '" . $dateformat . "'";
//WHERE month(date) between (select month(min(date)) from t_income_expense) and '".$month."' and year(date) = '".$year."'";
$query = $this->db->query($sql);
return $query->getResult();
}
//function daybeforetotal($yesterday){
function getDailyOpeningAmt($yesterday)
{
$sql = "select date,(sum(if(type = 'RECEIPT',total,0)) - sum(if(type = 'PAYMENT',total,0))) as opening_amt
from t_income_expense
where date between (select min(date) from t_income_expense) and '" . $yesterday . "'";
$query = $this->db->query($sql);
return $query->getResult();
}
function accountname()
{
$sql = "SELECT name from t_accountcode ";
$query = $this->db->query($sql);
return $query->getResult();
}
function cashbook_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 report_cumulative_month_cashbook(){
function report_cumulative_month_cashbook($cname, $yr1, $yr2)
{
if ($yr1 == '' && $yr2 == '') {
if (date('m') >= 4) {
$yearl = date('Y') . '-' . (date('Y') + 1);
} else {
$yearl = (date('Y') - 1) . '-' . date('Y');
}
$ab = $yearl;
$fa = substr($ab, 0, -5);
$aa = substr($ab, 5, 5);
} else {
$fa = $yr1;
$aa = $yr2;
}
$sql = "select tinc.account_code,ac.name,tinc.type,
SUM(IF(month(tinc.date) = 4, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS AprilExpense,
SUM(IF(month(tinc.date) = 4, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS AprilIncome,
SUM(IF(month(tinc.date) = 5, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS MayExpense,
SUM(IF(month(tinc.date) = 5, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS MayIncome,
SUM(IF(month(tinc.date) = 6, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS JuneExpense,
SUM(IF(month(tinc.date) = 6, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS JuneIncome,
SUM(IF(month(tinc.date) = 7, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS JulyExpense,
SUM(IF(month(tinc.date) = 7, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS JulyIncome,
SUM(IF(month(tinc.date) = 8, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS AugustExpense,
SUM(IF(month(tinc.date) = 8, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS AugustIncome,
SUM(IF(month(tinc.date) = 9, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS SepExpense,
SUM(IF(month(tinc.date) = 9, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS SepIncome,
SUM(IF(month(tinc.date) = 10, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS OctExpense,
SUM(IF(month(tinc.date) = 10, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS OctIncome,
SUM(IF(month(tinc.date) = 11, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS NovExpense,
SUM(IF(month(tinc.date) = 11, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS NovIncome,
SUM(IF(month(tinc.date) = 12, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS DecExpense,
SUM(IF(month(tinc.date) = 12, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS DecIncome,
SUM(IF(month(tinc.date) = 1, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS JanExpense,
SUM(IF(month(tinc.date) = 1, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS JanIncome,
SUM(IF(month(tinc.date) = 2, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS FebExpense,
SUM(IF(month(tinc.date) = 2, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS FebIncome,
SUM(IF(month(tinc.date) = 3, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS MarExpense,
SUM(IF(month(tinc.date) = 3, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS MarIncome,
SUM(IF(tinc.type = 'RECEIPT', tinc.total, 0)) AS receiptoverall,
SUM(IF(tinc.type = 'PAYMENT', tinc.total, 0)) AS paymentoverall,
SUM(tinc.total) as overalltotal
from t_income_expense tinc
join t_accountcode ac on ac.code = tinc.account_code
where (tinc.date >='" . $fa . "-04-01' and tinc.date <= '" . $aa . "-03-31')";
if ($cname != '') {
$sql .= "and ac.name = '" . $cname . "'";
}
$sql .= " group by tinc.account_code";
$query = $this->db->query($sql);
return $query->getResult();
}
function purchase_order_list()
{
$sql = "select po.PONO as po,po.POType as type,date(po.PODate) as podate
from t_purchaseorder_master po
where po.Status != 'ST030' and po.Status = 'ST026'
order by podate desc";
$query = $this->db->query($sql);
return $query->getResult();
}
function stockFinancialYear(){
$financialYear = ['2025','2026'];
return $financialYear;
}
function smrySilicaSandReport($month,$year){
$monthNum = date('m', strtotime($month));
$startDate = $year . "-" . $monthNum . "-01";
$endDate = $year . "-" . $monthNum . "-" . date('t', strtotime($startDate));
$sql = "";
$materialCodes = $this->rawMaterialDetails->getAllSilicaRawMaterialCode();
$supplierWiseSilicaSand = $this->inwardgateregister->findIgrDetailsForSandReport($materialCodes, $startDate, "noRemark");
dd($supplierWiseSilicaSand);
$query = $this->db->query($sql);
$result = $query->getResult();
dd($this->db->getLastQuery());
return $result;
}
function smryWasteCoreSandReport($month,$year){
$sql = "";
$query = $this->db->query($sql);
$result = $query->getResult();
dd($this->db->getLastQuery());
return $result;
}
function smryDustQtyReport($month,$year){
$sql = "";
$query = $this->db->query($sql);
$result = $query->getResult();
dd($this->db->getLastQuery());
return $result;
}
function smryCoatedSandReport($month,$year){
$sql = "";
$query = $this->db->query($sql);
$result = $query->getResult();
dd($this->db->getLastQuery());
return $result;
}
function smryPackingMaterialReport($month, $year) {
$monthNum = date('m', strtotime($month));
$startDate = $year . "-" . $monthNum . "-01";
$endDate = $year . "-" . $monthNum . "-" . date('t', strtotime($startDate));
$sql = "SELECT
GROUP_CONCAT(DISTINCT ts.SupplierName) as supplierName,
tmm.MaterialName,
tbg.customer,
SUM(CASE WHEN date = '$startDate' THEN opening ELSE 0 END) as opening,
SUM(receipt) as purchase,
SUM(CASE WHEN date = '$startDate' THEN opening ELSE 0 END) + SUM(receipt) as total,
SUM(used) as used,
SUM(CASE WHEN date = '$startDate' THEN opening ELSE 0 END) + SUM(receipt) - SUM(used) as closing
FROM t_bagstockdetails tbg
INNER JOIN t_materialmaster tmm ON tmm.MaterialCode = tbg.materialCode
INNER JOIN t_igr_details tigrd ON tigrd.MaterialCode = tbg.materialCode AND Date(tigrd.CreatedDate) >= '$startDate' AND Date(tigrd.CreatedDate) <= '$endDate'
INNER JOIN t_igr_master tigrm ON tigrd.IGRNO = tigrm.IGRNO
INNER JOIN t_purchaseorder_master tpom ON tpom.PONO = tigrm.PONO
INNER JOIN t_supplierdetailsn ts ON ts.SupplierID = tpom.SupplierID
WHERE date >= '$startDate' AND date <= '$endDate'
GROUP BY tbg.materialCode, tmm.MaterialName, tbg.customer";
$query = $this->db->query($sql);
$result = $query->getResultArray();
return $result;
}
function smryDieselReport($month,$year){
$sql = "";
$query = $this->db->query($sql);
$result = $query->getResult();
dd($this->db->getLastQuery());
return $result;
}
function smryGasReport($month,$year){
$sql = "";
$query = $this->db->query($sql);
$result = $query->getResult();
dd($result);
return $result;
}
function smryResinReport($month,$year){
$monthNum = date('m', strtotime($month));
$startDate = $year . "-" . $monthNum . "-01";
$endDate = $year . "-" . $monthNum . "-" . date('t', strtotime($startDate));
$sql = "SELECT
GROUP_CONCAT(DISTINCT ts.SupplierName) as supplierName,
tmm.MaterialName,
SUM(CASE WHEN date = '$startDate' THEN opening ELSE 0 END) as opening,
SUM(receipt) as purchase,
SUM(CASE WHEN date = '$startDate' THEN opening ELSE 0 END) + SUM(receipt) as total,
SUM(used) as used,
SUM(CASE WHEN date = '$startDate' THEN opening ELSE 0 END) + SUM(receipt) - SUM(used) as closing
FROM t_resinStockDetails tbg
INNER JOIN t_materialmaster tmm ON tmm.MaterialCode = tbg.materialCode
INNER JOIN t_igr_details tigrd ON tigrd.MaterialCode = tbg.materialCode AND Date(tigrd.CreatedDate) >= '$startDate' AND Date(tigrd.CreatedDate) <= '$endDate'
INNER JOIN t_igr_master tigrm ON tigrd.IGRNO = tigrm.IGRNO
INNER JOIN t_purchaseorder_master tpom ON tpom.PONO = tigrm.PONO
INNER JOIN t_supplierdetailsn ts ON ts.SupplierID = tpom.SupplierID
WHERE tbg.date >= '$startDate' AND tbg.date <= '$endDate'
GROUP BY tbg.materialCode, tmm.MaterialName, tbg.customer";
$query = $this->db->query($sql);
$result = $query->getResultArray();
return $result;
}
}