select 
b.Code as Branch_style_12_left 
,si.code as invoice_style_10_left
 ,si.sub_total as Sub_total_sum_2_style_12_right
 ,si.total_discount as Discount_sum_2_style_12_right
 ,si.net_total as Net_total_sum_2_style_12_right 
,sum(sip.costPrice*sip.qty) as Total_cost_sum_2_style_12_right
 ,si.rpt_returns_amount as Return_sum_2_style_12_right
 ,round(si.net_total-sum(sip.costPrice*sip.qty)-si.rpt_returns_amount,2) as Profit_sum_2_style_12_right 
 ,round(((si.net_total-sum(sip.costPrice*sip.qty)-si.rpt_returns_amount)/sum(sip.costPrice*sip.qty))*100,2) as `%_style_6_right` 
,'' as category 
,0 as category_id 
from tbl_sale_invoice_products sip 
inner join tbl_products p on p.product_id = sip.product_id 
inner join tbl_sale_invoice si on si.id = sip.sale_invoice_id 
inner join tbl_branch_inventory_locations bil on bil.id = si.location_id 
inner join tbl_branch b on b.branch_id = bil.branch_id 
where si.created_on between '{from_date}' and '{to_date}' 
and (bil.branch_id = {branch_id} or {branch_id} = 0) 
group by sip.sale_invoice_id 
order by si.id