select 
e.branch_id as category_id
,concat(b.Code,' - ',b.Name) as category
,e.code as Code_style_10_left
,e.date as Date_style_10_left
,concat(et.code,' - ',et.type) as Type_style_30_left
,e.description as Description_style_40_left
,e.amount as Amount_sum_2_style_10_right
from tbl_expenses e
inner join tbl_expenses_type et on et.id = e.type_id
inner join tbl_branch b on b.branch_id = e.branch_id
where e.status = 4
and e.date between '{from_date}' and '{to_date}'
and (e.type_id = {type_id} or {type_id} = 0)
and (e.branch_id = {branch_id} or {branch_id} = 0)
order by e.branch_id,e.type_id,e.date