select 
concat(si.code,' /date - ',date(si.created_on),' - ',b.Code) as category
,si.id as category_id
,concat(p.code,' - ',p.name)  as Item_style_23_left
,sip.qty as Qty_sum_2_style_10_right
,sip.costPrice as Cost_price_sum_2_style_11_right
,sip.unit_price as Unit_price_sum_2_style_10_right
,sip.discount as Discount_sum_2_style_10_right
,sip.net_total as Net_total_sum_2_style_11_right
,ifnull(rp.value,0.00) as Returns_sum_2_style_10_right
,round(sip.net_total - (sip.costPrice*sip.qty) - ifnull(rp.value,0.00),2) as Profit_sum_2_style_10_right
,round((sip.net_total - (sip.costPrice*sip.qty) - ifnull(rp.value,0.00))/(sip.costPrice*sip.qty)*100,2) as `%_style_5_right`
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
left join tbl_return_products rp on rp.product_id = sip.product_id
and rp.invoice_id = sip.sale_invoice_id
where si.created_on between '{from_date}'  and  '{to_date}'
and (bil.branch_id = {branch_id} or {branch_id} = 0)
and (p.product_id = {item_id} or {item_id} = 0)
order by si.id,si.created_on