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 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 waiver_items = "('Damage Waver')" %}
|
||||
{% set verification_fee_items = "('Verification Fee')" %}
|
||||
|
||||
with
|
||||
|
|
@ -22,6 +23,8 @@ with
|
|||
then 'listing_fees'
|
||||
when ili.item_code in {{ verification_fee_items }}
|
||||
then 'verification_fees'
|
||||
when ili.item_code in {{ waiver_items }}
|
||||
then 'damager_waiver'
|
||||
else null
|
||||
end as fee_category,
|
||||
sum(ili.line_amount_wo_taxes_in_gbp) as fees_invoiced
|
||||
|
|
@ -33,6 +36,7 @@ with
|
|||
ili.item_code in {{ booking_fee_items }}
|
||||
or ili.item_code in {{ listing_fee_items }}
|
||||
or ili.item_code in {{ verification_fee_items }}
|
||||
or ili.item_code in {{ waiver_items }}
|
||||
)
|
||||
group by
|
||||
date_trunc('month', i.invoice_issued_date_utc),
|
||||
|
|
@ -43,6 +47,8 @@ with
|
|||
then 'listing_fees'
|
||||
when ili.item_code in {{ verification_fee_items }}
|
||||
then 'verification_fees'
|
||||
when ili.item_code in {{ waiver_items }}
|
||||
then 'damager_waiver'
|
||||
else null
|
||||
end
|
||||
),
|
||||
|
|
@ -58,6 +64,8 @@ with
|
|||
then 'listing_fees'
|
||||
when cnli.item_code in {{ verification_fee_items }}
|
||||
then 'verification_fees'
|
||||
when cnli.item_code in {{ waiver_items }}
|
||||
then 'damager_waiver'
|
||||
else null
|
||||
end as fee_category,
|
||||
sum(cnli.line_amount_wo_taxes_in_gbp) as fees_credited
|
||||
|
|
@ -70,6 +78,7 @@ with
|
|||
cnli.item_code in {{ booking_fee_items }}
|
||||
or cnli.item_code in {{ listing_fee_items }}
|
||||
or cnli.item_code in {{ verification_fee_items }}
|
||||
or cnli.item_code in {{ waiver_items }}
|
||||
)
|
||||
group by
|
||||
date_trunc('month', cn.credit_note_issued_date_utc),
|
||||
|
|
@ -80,17 +89,21 @@ with
|
|||
then 'listing_fees'
|
||||
when cnli.item_code in {{ verification_fee_items }}
|
||||
then 'verification_fees'
|
||||
when cnli.item_code in {{ waiver_items }}
|
||||
then 'damager_waiver'
|
||||
else null
|
||||
end
|
||||
)
|
||||
select
|
||||
i.invoice_issued_year_month as issued_year_month,
|
||||
i.fee_category,
|
||||
coalesce(
|
||||
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(c.fees_credited, 0) as fees_credited_in_gbp,
|
||||
(coalesce(i.fees_invoiced, 0) - coalesce(c.fees_credited, 0)) as net_fees_in_gbp
|
||||
from fees_invoiced i
|
||||
left join
|
||||
full outer join
|
||||
fees_credited c
|
||||
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