From 274697767175f0da53124d85193e28d86f2ccbc6 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 3 Jun 2025 10:53:22 +0200 Subject: [PATCH] commit wip --- .../xero/int_xero__deals_due_amounts.sql | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/models/intermediate/xero/int_xero__deals_due_amounts.sql b/models/intermediate/xero/int_xero__deals_due_amounts.sql index 142e1c5..828c4b6 100644 --- a/models/intermediate/xero/int_xero__deals_due_amounts.sql +++ b/models/intermediate/xero/int_xero__deals_due_amounts.sql @@ -1,11 +1,5 @@ with - int_xero__invoice_line_items as ( - select * from {{ ref("int_xero__invoice_line_items") }} - ), - int_xero__invoices as (select * from {{ ref("int_xero__invoices") }}), - int_xero__credit_note_line_items as ( - select * from {{ ref("int_xero__credit_note_line_items") }} - ), + int_xero__invoices as (select * from {{ ref("int_xero__invoices") }}), int_xero__credit_notes as (select * from {{ ref("int_xero__credit_notes") }}), int_xero__contacts as (select * from {{ ref("int_xero__contacts") }}), stg_seed__accounting_aggregations as ( @@ -13,7 +7,7 @@ with ), amount_due_deals as ( select c.id_contact as id_contact, - c.id_deal as id_deal, + c.id_deal as id_deal, c.contact_name as contact_name, i.total_due_in_gbp from int_xero__invoices i @@ -28,7 +22,9 @@ with where cn.credit_note_status = 'AUTHORISED' and c.id_deal is not null ) select + id_contact, id_deal, + contact_name, sum(total_due_in_gbp) as total_outstanding_in_gbp, case when sum(total_due_in_gbp) < 0 @@ -37,4 +33,6 @@ with then 'Outstanding Invoices' end as outstanding_type from amount_due_deals - group by id_deal \ No newline at end of file + group by id_contact, + id_deal, + contact_name \ No newline at end of file