Select ifnull(tbl_products.code, '' ) as Code_style_10_left 
, ifnull(tbl_products.name
, tbl_sale_invoice_products.service_details ) as Item_style_20_left , 
tbl_products.description as Description_style_20_left,
ifnull(tbl_productcategory.category,'') as Category_style_20_left,
sum(tbl_sale_invoice_products.qty) as Sale_Qty_style_15_right 
,(ifnull( pi.qty_in_stock,0))   Avl_qty_sum_6_style_15_right  
,  ifnull(tbl_products.category_id,-1) as category_id
,ifnull(tbl_productcategory.category,'Custom product') as category

from tbl_sale_invoice 
inner join tbl_sale_invoice_products tbl_sale_invoice_products on tbl_sale_invoice_products.sale_invoice_id = tbl_sale_invoice.id

LEFT join tbl_products on tbl_products.product_id = tbl_sale_invoice_products.product_id
left join tbl_productcategory on tbl_productcategory.productCategory_id =tbl_products.category_id
LEFT JOIN  tbl_inventory pi ON         tbl_products .product_id=pi.product_id
 where date(tbl_sale_invoice.created_on) between date('{from}') and date('{to}')
and (tbl_products.category_id = {category_id} or {category_id} = 0)
 
 and tbl_sale_invoice.status in ('4','102') 


 GROUP by tbl_sale_invoice_products.service_details
ORDER BY   ifnull(tbl_products.category_id,0)