select c.code AS "Customer code"
                    , c.description AS "Customer description"
                    , count(DISTINCT wo.id) AS "Transaction count"
                    , to_char(sum(wo.amount_without_tax), '99999999990.00') AS "Amount without tax"
                    , to_char(sum(wo.amount_with_tax), '99999999990.00') AS "Amount with tax"  
                from  billing_wallet_operation wo
                    INNER JOIN billing_wallet wa  on wa.id = wo.wallet_id
                    INNER JOIN billing_user_account ua  on ua.id = wa.user_account_id
                    INNER JOIN billing_billing_account ba  on ba.id = ua.billing_account_id 
                    INNER JOIN ar_customer_account ca  on ca.id = ba.customer_account_id 
                    INNER JOIN crm_customer c  on c.id = ca.customer_id 
                    INNER JOIN crm_seller s  on s.id = c.seller_id 
                where  (  wo.STATUS = 'OPEN'  or (   wo.STATUS = 'TREATED'   
                    and EXISTS (   select 1 from billing_rated_transaction rt where wo.rated_transaction_id = rt.id and rt.STATUS = 'OPEN'   )  )  )  
                and(  c.code ilike '%' || :SEARCH_CRITERION || '%'  or c.description ilike '%' || :SEARCH_CRITERION || '%'  )  
                group by c.code, c.description 
                order by c.code