add net fees
This commit is contained in:
parent
307887126c
commit
7148220061
1 changed files with 16 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
{% set relevant_document_statuses = "('PAID', 'AUTHORISED')" %}
|
{% set relevant_document_statuses = "('PAID', 'AUTHORISED')" %}
|
||||||
{% set booking_fee_items = "('EU Booking Fee','ZAR Bookings','Booking fee - non-UK','USD Bookings','CAD Bookings','Booking fee - UK','AUD Bookings')" %}
|
{% set booking_fee_items = "('EU Booking Fee','ZAR Bookings','Booking fee - non-UK','USD Bookings','CAD Bookings','Booking fee - UK','AUD Bookings')" %}
|
||||||
{% set listing_fee_items = "('USD Listings','Listing fee - non UK','ZAR Listings','CAD Listings','Listing fee - UK','AUD Listings','EU Listings')" %}
|
{% set listing_fee_items = "('USD Listings','Listing fee - non UK','ZAR Listings','CAD Listings','Listing fee - UK','AUD Listings','EU Listings')" %}
|
||||||
|
{% set waiver_items = "('Damage Waver')" %}
|
||||||
{% set verification_fee_items = "('Verification Fee')" %}
|
{% set verification_fee_items = "('Verification Fee')" %}
|
||||||
|
|
||||||
with
|
with
|
||||||
|
|
@ -22,6 +23,8 @@ with
|
||||||
then 'listing_fees'
|
then 'listing_fees'
|
||||||
when ili.item_code in {{ verification_fee_items }}
|
when ili.item_code in {{ verification_fee_items }}
|
||||||
then 'verification_fees'
|
then 'verification_fees'
|
||||||
|
when ili.item_code in {{ waiver_items }}
|
||||||
|
then 'damager_waiver'
|
||||||
else null
|
else null
|
||||||
end as fee_category,
|
end as fee_category,
|
||||||
sum(ili.line_amount_wo_taxes_in_gbp) as fees_invoiced
|
sum(ili.line_amount_wo_taxes_in_gbp) as fees_invoiced
|
||||||
|
|
@ -33,6 +36,7 @@ with
|
||||||
ili.item_code in {{ booking_fee_items }}
|
ili.item_code in {{ booking_fee_items }}
|
||||||
or ili.item_code in {{ listing_fee_items }}
|
or ili.item_code in {{ listing_fee_items }}
|
||||||
or ili.item_code in {{ verification_fee_items }}
|
or ili.item_code in {{ verification_fee_items }}
|
||||||
|
or ili.item_code in {{ waiver_items }}
|
||||||
)
|
)
|
||||||
group by
|
group by
|
||||||
date_trunc('month', i.invoice_issued_date_utc),
|
date_trunc('month', i.invoice_issued_date_utc),
|
||||||
|
|
@ -43,6 +47,8 @@ with
|
||||||
then 'listing_fees'
|
then 'listing_fees'
|
||||||
when ili.item_code in {{ verification_fee_items }}
|
when ili.item_code in {{ verification_fee_items }}
|
||||||
then 'verification_fees'
|
then 'verification_fees'
|
||||||
|
when ili.item_code in {{ waiver_items }}
|
||||||
|
then 'damager_waiver'
|
||||||
else null
|
else null
|
||||||
end
|
end
|
||||||
),
|
),
|
||||||
|
|
@ -58,6 +64,8 @@ with
|
||||||
then 'listing_fees'
|
then 'listing_fees'
|
||||||
when cnli.item_code in {{ verification_fee_items }}
|
when cnli.item_code in {{ verification_fee_items }}
|
||||||
then 'verification_fees'
|
then 'verification_fees'
|
||||||
|
when cnli.item_code in {{ waiver_items }}
|
||||||
|
then 'damager_waiver'
|
||||||
else null
|
else null
|
||||||
end as fee_category,
|
end as fee_category,
|
||||||
sum(cnli.line_amount_wo_taxes_in_gbp) as fees_credited
|
sum(cnli.line_amount_wo_taxes_in_gbp) as fees_credited
|
||||||
|
|
@ -70,6 +78,7 @@ with
|
||||||
cnli.item_code in {{ booking_fee_items }}
|
cnli.item_code in {{ booking_fee_items }}
|
||||||
or cnli.item_code in {{ listing_fee_items }}
|
or cnli.item_code in {{ listing_fee_items }}
|
||||||
or cnli.item_code in {{ verification_fee_items }}
|
or cnli.item_code in {{ verification_fee_items }}
|
||||||
|
or cnli.item_code in {{ waiver_items }}
|
||||||
)
|
)
|
||||||
group by
|
group by
|
||||||
date_trunc('month', cn.credit_note_issued_date_utc),
|
date_trunc('month', cn.credit_note_issued_date_utc),
|
||||||
|
|
@ -80,17 +89,21 @@ with
|
||||||
then 'listing_fees'
|
then 'listing_fees'
|
||||||
when cnli.item_code in {{ verification_fee_items }}
|
when cnli.item_code in {{ verification_fee_items }}
|
||||||
then 'verification_fees'
|
then 'verification_fees'
|
||||||
|
when cnli.item_code in {{ waiver_items }}
|
||||||
|
then 'damager_waiver'
|
||||||
else null
|
else null
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
select
|
select
|
||||||
i.invoice_issued_year_month as issued_year_month,
|
coalesce(
|
||||||
i.fee_category,
|
i.invoice_issued_year_month, c.credit_note_issued_year_month
|
||||||
|
) as issued_year_month,
|
||||||
|
coalesce(i.fee_category, c.fee_category) as fee_category,
|
||||||
coalesce(i.fees_invoiced, 0) as fees_invoiced_in_gbp,
|
coalesce(i.fees_invoiced, 0) as fees_invoiced_in_gbp,
|
||||||
coalesce(c.fees_credited, 0) as fees_credited_in_gbp,
|
coalesce(c.fees_credited, 0) as fees_credited_in_gbp,
|
||||||
(coalesce(i.fees_invoiced, 0) - coalesce(c.fees_credited, 0)) as net_fees_in_gbp
|
(coalesce(i.fees_invoiced, 0) - coalesce(c.fees_credited, 0)) as net_fees_in_gbp
|
||||||
from fees_invoiced i
|
from fees_invoiced i
|
||||||
left join
|
full outer join
|
||||||
fees_credited c
|
fees_credited c
|
||||||
on i.invoice_issued_year_month = c.credit_note_issued_year_month
|
on i.invoice_issued_year_month = c.credit_note_issued_year_month
|
||||||
and i.fee_category = c.fee_category
|
and i.fee_category = c.fee_category
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue