Skip to content

Commit b954d9f

Browse files
committed
Clarify cost recovery SQL queries
Makes some minor changes to the cost recovery SQL queries. Some minor changes align the output more closely to that required for the cost recovery spreadsheet. The majority of the changes are just to add some additional clarification in the comments.
1 parent b99ac94 commit b954d9f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

sql/cost_recovery.sql

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
-- Export Query 1
66
-- Get all cost_recovery rows with the latest subscription names
7+
-- Outputs sheet cost-recovery_YY-YY_qN
78
select cr."id", finance_id, "month", finance_code, sd.display_name, cr.subscription_id, amount
89
from accounting.cost_recovery cr
910
join (
@@ -14,16 +15,18 @@ join (
1415
on latest_names.subscription_id = cr.subscription_id
1516
join accounting.subscription_details sd
1617
on sd.id = latest_names.max_id
17-
where cr.month >= '2022-04-00'; -- the first day of the recovery period
18+
where cr.month >= '2024-04-00' -- the first day of the recovery period
19+
and cr.month < '2024-07-00'; -- one day after the recovery-period end date, typically three months after the start
1820

1921

2022
-- Export Query 2
2123
-- Get a breakdown of each subscription's usage
24+
-- Outputs usage_YY-YY_qN
2225
select
2326
u.subscription_id,
2427
display_name,
2528
--product,
26-
date_trunc('month', u."date") as the_date,
29+
date(date_trunc('month', u."date")) as date_trunc,
2730
sum(total_cost) as total_cost,
2831
sum(amortised_cost) as amortised_cost,
2932
sum(cost) as cost
@@ -37,8 +40,8 @@ join (
3740
on latest_names.subscription_id = u.subscription_id
3841
join accounting.subscription_details sd
3942
on sd.id = latest_names.max_id
40-
where "date" >= '2022-10-00' -- the recovery-period start date
41-
and "date" < '2023-01-00' -- one day after the recovery-period end date
43+
where "date" >= '2024-04-00' -- the first day of the recovery period
44+
and "date" < '2024-07-00' -- one day after the recovery-period end date, typically three months after the start
4245
and u.subscription_id in (
4346
select distinct subscription_id
4447
from accounting.cost_recovery
@@ -52,6 +55,7 @@ group by
5255

5356
-- Export Query 3
5457
-- Include the finance rows
58+
-- Outputs sheet max-recoverable_YY-YY_qN
5559
select sd.display_name,
5660
f.id,
5761
f.subscription_id,
@@ -70,8 +74,8 @@ join (
7074
on latest_names.subscription_id = f.subscription_id
7175
join accounting.subscription_details sd
7276
on sd.id = latest_names.max_id
73-
where f.date_to >= '2022-10-00' -- the recovery-period start date
74-
and f.date_from < '2023-01-00'; -- one day after the recovery-period end date
77+
where f.date_to >= '2024-04-00' -- the first day of the recovery period
78+
and f.date_from < '2024-07-00'; -- one day after the recovery-period end date, typically three months after the start
7579

7680

7781
-- Data Integrity Query 1

0 commit comments

Comments
 (0)