select name as Supplier_style_55_left
,amount as Total_grn_amount_sum_2_style_15_right
,paidAmount as Paid_amount_sum_2_style_15_right
,amount - paidAmount as Outstanding_sum_2_style_15_right
from (select 
s.name,sum(g.total) as amount,
sum(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 paidAmount
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 )
group by g.supplier_id 
) tmp