select code as Code_style_15_left
,supplier as Supplier_style_45_left
,total as Amount_sum_2_style_10_right
,paid as Paid_sum_2_style_10_right
,(total - paid) as Balance_sum_2_style_10_right
,age as Age_style_10_right
from (
select 
g.code 
,s.name as supplier
,g.total
,ifnull((select sum(ifnull(sg.amount,0)) 
	from tbl_supplier_payments sp
       inner join tbl_supplier_payments_grns sg on sg.supplier_payment_id= sp.id
    where sg.grn_id = g.grn_id  
    and sp.status = '4' 
    ),0) as paid
,DATEDIFF(now(),g.grn_date) as age
from tbl_grns g
inner join tbl_supplier s on s.supplier_id = g.supplier_id
where g.grn_date between '{fromDate}' and '{toDate}'
and g.status = '4' 
and (g.supplier_id  = {sup_id} or {sup_id} = 0 )
order by g.grn_date ) tmp
where total- paid > 0