select trim(to_char(date_trunc('month', i.invoice_date), 'Month')) || to_char(date_trunc('month', i.invoice_date), ' YYYY') AS "Month"
                    , of.code AS "Offer code"
                    , of.description AS "Offer description"
                    , it.code AS "Invoice type code"
                    , it.description AS "Invoice type description"
                    , to_char(sum(rt.amount_without_tax), '9999999990.00') AS "Amount without tax"
                    , to_char(sum(rt.amount_with_tax), '9999999990.00') AS "Amount with tax"  
                from cat_offer_template of
                    INNER JOIN billing_wallet_operation wo on wo.offer_code = OF.code
                    INNER JOIN billing_rated_transaction rt on wo.rated_transaction_id = rt.id
                    INNER JOIN billing_invoice i  on i.id = rt.invoice_id
                    INNER JOIN billing_invoice_type it  on it.id = i.invoice_type_id 
                where i.invoice_date > (date_trunc('month', CURRENT_DATE) - CAST(:MONTH_INTERVAL || ' month' AS INTERVAL))  
                and(  of.code ilike '%' || :SEARCH_CRITERION || '%'  or OF.description ilike '%' || :SEARCH_CRITERION || '%'  )  
                group by date_trunc('month', i.invoice_date)
                    , it.code
                    , it.description
                    , of.code
                    , of.description order by date_trunc('month', i.invoice_date) DESC
                    , it.code DESC
                    , of.code