CREATE OR REPLACE VIEW public.vw_utility_monthly_trade_ifrs_adjustments AS WITH books AS ( SELECT adv.id AS "intBookId", adv.code AS "BookCode", adv.name AS "BookName", "right"((adv.name)::text, 4) AS "BookYear" FROM (analytic_dimension ad JOIN analytic_dimension_value adv ON ((ad.id = adv.dimension))) WHERE (((ad.code)::text = 'book'::text) AND ((adv.name)::text !~~ '%Projection%'::text)) ) SELECT apti.id AS "intAdjustmentId", apti.date AS "dtmAdjustmentDate", apti.amount AS "dblAmount", cur.name AS "strCurrency", apti.comment AS "strComments", books."intBookId" FROM ((account_physical_trade_ifrs apti JOIN currency_currency cur ON ((cur.id = apti.currency))) LEFT JOIN books ON ((books."BookYear" = (((EXTRACT(year FROM apti.date))::integer - CASE WHEN ((EXTRACT(month FROM apti.date))::integer < 4) THEN 1 ELSE 0 END))::text)));;