lots of currency stuff

This commit is contained in:
Pablo Martin 2024-05-14 12:26:02 +02:00
parent 908ec75d17
commit bc4ca1cbc3
5 changed files with 139 additions and 8 deletions

View file

@ -7,8 +7,38 @@ select
j.item_code,
j.quantity::numeric,
j.unit_amount::numeric,
j.line_amount::numeric,
j.tax_amount::numeric,
j.line_amount_local_curr::numeric,
(j.line_amount_local_curr::numeric * i.exchange_rate_to_gbp)::numeric(
18, 4
) as line_amount_in_gbp,
case
when i.line_amount_tax_inclusiveness = 'Inclusive'
then j.line_amount_local_curr::numeric - j.tax_amount_local_curr::numeric
when i.line_amount_tax_inclusiveness = 'Exclusive'
then j.line_amount_local_curr::numeric
when i.line_amount_tax_inclusiveness = 'NoTax'
then j.line_amount_local_curr::numeric
else null
end as line_amount_wo_taxes_local_curr,
case
when i.line_amount_tax_inclusiveness = 'Inclusive'
then
(j.line_amount_local_curr::numeric * i.exchange_rate_to_gbp)::numeric(18, 4)
- (j.tax_amount_local_curr::numeric * i.exchange_rate_to_gbp)::numeric(
18, 4
)
when i.line_amount_tax_inclusiveness = 'Exclusive'
then
(j.line_amount_local_curr::numeric * i.exchange_rate_to_gbp)::numeric(18, 4)
when i.line_amount_tax_inclusiveness = 'NoTax'
then
(j.line_amount_local_curr::numeric * i.exchange_rate_to_gbp)::numeric(18, 4)
else null
end as line_amount_wo_taxes_in_gbp,
j.tax_amount_local_curr::numeric,
(j.tax_amount_local_curr::numeric * i.exchange_rate_to_gbp)::numeric(
18, 4
) as tax_amount_in_gbp,
j.tax_type,
i.invoice_currency_iso_4217,
j.line_description
@ -22,8 +52,12 @@ cross join
(jsonb_array_elements(i.line_items) -> 'Item') ->> 'Name' as item_name,
(jsonb_array_elements(i.line_items) ->> 'Quantity') as quantity,
(jsonb_array_elements(i.line_items) ->> 'UnitAmount') as unit_amount,
(jsonb_array_elements(i.line_items) ->> 'LineAmount') as line_amount,
(jsonb_array_elements(i.line_items) ->> 'TaxAmount') as tax_amount,
(
jsonb_array_elements(i.line_items) ->> 'LineAmount'
) as line_amount_local_curr,
(
jsonb_array_elements(i.line_items) ->> 'TaxAmount'
) as tax_amount_local_curr,
(jsonb_array_elements(i.line_items) ->> 'TaxType') as tax_type,
(jsonb_array_elements(i.line_items) ->> 'Description') as line_description
) j

View file

@ -12,10 +12,19 @@ select
invoice_currency_iso_4217,
exchange_rate_to_gbp,
total_amount_local_curr,
(total_amount_local_curr * exchange_rate_to_gbp)::numeric(
18, 4
) as total_amount_in_gbp,
total_amount_wo_tax_local_curr,
(total_amount_wo_tax_local_curr * exchange_rate_to_gbp)::numeric(
18, 4
) as total_amount_wo_tax_in_gbp,
total_tax_local_curr,
(total_tax_local_curr * exchange_rate_to_gbp)::numeric(18, 4) as total_tax_in_gbp,
total_due_local_curr,
(total_due_local_curr * exchange_rate_to_gbp)::numeric(18, 4) as total_due_in_gbp,
total_paid_local_curr,
(total_paid_local_curr * exchange_rate_to_gbp)::numeric(18, 4) as total_paid_in_gbp,
invoice_status,
full_contact_details,
payments,