use date field instead of breaking things down
This commit is contained in:
parent
b0528ec2c0
commit
65f5b7377a
1 changed files with 10 additions and 16 deletions
|
|
@ -12,8 +12,9 @@ with
|
|||
xero__credit_notes as (select * from {{ ref("xero__credit_notes") }}),
|
||||
fees_invoiced as (
|
||||
select
|
||||
extract(year from i.invoice_issued_date_utc) as invoice_issued_year,
|
||||
extract(month from i.invoice_issued_date_utc) as invoice_issued_month,
|
||||
cast(
|
||||
date_trunc('month', i.invoice_issued_date_utc) as date
|
||||
) as invoice_issued_year_month,
|
||||
case
|
||||
when ili.item_code in {{ booking_fee_items }}
|
||||
then 'booking_fees'
|
||||
|
|
@ -34,8 +35,7 @@ with
|
|||
or ili.item_code in {{ verification_fee_items }}
|
||||
)
|
||||
group by
|
||||
extract(year from i.invoice_issued_date_utc),
|
||||
extract(month from i.invoice_issued_date_utc),
|
||||
date_trunc('month', i.invoice_issued_date_utc),
|
||||
case
|
||||
when ili.item_code in {{ booking_fee_items }}
|
||||
then 'booking_fees'
|
||||
|
|
@ -48,12 +48,9 @@ with
|
|||
),
|
||||
fees_credited as (
|
||||
select
|
||||
extract(
|
||||
year from cn.credit_note_issued_date_utc
|
||||
) as credit_note_issued_year,
|
||||
extract(
|
||||
month from cn.credit_note_issued_date_utc
|
||||
) as credit_note_issued_month,
|
||||
cast(
|
||||
date_trunc('month', cn.credit_note_issued_date_utc) as date
|
||||
) as credit_note_issued_year_month,
|
||||
case
|
||||
when cnli.item_code in {{ booking_fee_items }}
|
||||
then 'booking_fees'
|
||||
|
|
@ -75,8 +72,7 @@ with
|
|||
or cnli.item_code in {{ verification_fee_items }}
|
||||
)
|
||||
group by
|
||||
extract(year from cn.credit_note_issued_date_utc),
|
||||
extract(month from cn.credit_note_issued_date_utc),
|
||||
date_trunc('month', cn.credit_note_issued_date_utc),
|
||||
case
|
||||
when cnli.item_code in {{ booking_fee_items }}
|
||||
then 'booking_fees'
|
||||
|
|
@ -88,8 +84,7 @@ with
|
|||
end
|
||||
)
|
||||
select
|
||||
i.invoice_issued_year as issued_year,
|
||||
i.invoice_issued_month as issued_month,
|
||||
i.invoice_issued_year_month as issued_year_month,
|
||||
i.fee_category,
|
||||
coalesce(i.fees_invoiced, 0) as fees_invoiced_in_gbp,
|
||||
coalesce(c.fees_credited, 0) as fees_credited_in_gbp,
|
||||
|
|
@ -97,6 +92,5 @@ select
|
|||
from fees_invoiced i
|
||||
left join
|
||||
fees_credited c
|
||||
on i.invoice_issued_year = c.credit_note_issued_year
|
||||
and i.invoice_issued_month = c.credit_note_issued_month
|
||||
on i.invoice_issued_year_month = c.credit_note_issued_year_month
|
||||
and i.fee_category = c.fee_category
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue