refactor xero__net_fees_by_deal
This commit is contained in:
parent
0ffcfca6a8
commit
423457126f
4 changed files with 44 additions and 9 deletions
|
|
@ -661,6 +661,32 @@ models:
|
|||
data_type: character varying
|
||||
description: Xero's unique identifier for the credit note.
|
||||
|
||||
- name: credit_note_issued_at_utc
|
||||
data_type: timestamp with time zone
|
||||
description: Date on which the credit note was issued.
|
||||
|
||||
- name: credit_note_status
|
||||
data_type: character varying
|
||||
description: |
|
||||
The status of the credit note.
|
||||
|
||||
Can be one of: PAID, VOIDED, DRAFT, DELETED, AUTHORISED, SUBMITTED.
|
||||
data_tests:
|
||||
- not_null
|
||||
- accepted_values:
|
||||
values:
|
||||
- PAID
|
||||
- VOIDED
|
||||
- DRAFT
|
||||
- DELETED
|
||||
- AUTHORISED
|
||||
- SUBMITTED
|
||||
|
||||
- name: id_contact
|
||||
data_type: text
|
||||
description: |
|
||||
Xero's unique id for the contact related to this transaction.
|
||||
|
||||
- name: id_line_item
|
||||
data_type: text
|
||||
description: Xero's unique identifier for the line item.
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ with
|
|||
|
||||
select
|
||||
id_credit_note as id_credit_note,
|
||||
credit_note_issued_at_utc as credit_note_issued_at_utc,
|
||||
credit_note_status as credit_note_status,
|
||||
id_contact as id_contact,
|
||||
id_line_item as id_line_item,
|
||||
id_item as id_item,
|
||||
item_code as item_code,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
with
|
||||
xero__invoices as (select * from {{ ref("xero__invoices") }}),
|
||||
xero__credit_notes as (select * from {{ ref("xero__credit_notes") }}),
|
||||
xero__credit_note_line_items as (
|
||||
select * from {{ ref("xero__credit_note_line_items") }}
|
||||
),
|
||||
xero__contacts as (select * from {{ ref("xero__contacts") }}),
|
||||
fees_invoiced as (
|
||||
select
|
||||
|
|
@ -19,14 +21,14 @@ with
|
|||
fees_credited as (
|
||||
select
|
||||
cast(
|
||||
date_trunc('month', cn.credit_note_issued_at_utc) as date
|
||||
date_trunc('month', cnli.credit_note_issued_at_utc) as date
|
||||
) as credit_note_issued_year_month,
|
||||
c.id_deal,
|
||||
sum(cn.subtotal_in_gbp) as fees_credited
|
||||
from xero__credit_notes cn
|
||||
left join xero__contacts c on cn.id_contact = c.id_contact
|
||||
where cn.credit_note_status in {{ relevant_document_statuses }}
|
||||
group by date_trunc('month', cn.credit_note_issued_at_utc), c.id_deal
|
||||
sum(cnli.line_amount_wo_taxes_in_gbp) as fees_credited
|
||||
from xero__credit_note_line_items cnli
|
||||
left join xero__contacts c on cnli.id_contact = c.id_contact
|
||||
where cnli.credit_note_status in {{ relevant_document_statuses }}
|
||||
group by date_trunc('month', cnli.credit_note_issued_at_utc), c.id_deal
|
||||
)
|
||||
select
|
||||
coalesce(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue