Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sql/reports/payment/member-payment-accrual.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ recent_payments AS (
JOIN params pr ON TRUE
WHERE w.type = 'PAYMENT'
AND p.created_at >= pr.start_date
AND p.created_at <= pr.end_date
AND p.created_at < (
DATE_TRUNC('day', pr.end_date) + INTERVAL '1 day'
)
),
categorized_payments AS (
SELECT
Expand Down
2 changes: 1 addition & 1 deletion sql/reports/sfdc/ba-fees-monthly.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ WITH filtered_payments AS (
ON w.winning_id = p.winnings_id
WHERE
($1::timestamptz IS NULL OR p.created_at >= $1::timestamptz)
AND ($2::timestamptz IS NULL OR p.created_at <= $2::timestamptz)
AND ($2::timestamptz IS NULL OR p.created_at < (DATE_TRUNC('day', $2::timestamptz) + INTERVAL '1 day'))
AND ($3::text[] IS NULL OR p.billing_account = ANY($3::text[]))
AND ($4::text[] IS NULL OR p.billing_account != ALL($4::text[]))
),
Expand Down
2 changes: 1 addition & 1 deletion sql/reports/sfdc/ba-fees.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ WITH filtered_payments AS (
ON w.winning_id = p.winnings_id
WHERE
($1::timestamptz IS NULL OR p.created_at >= $1::timestamptz)
AND ($2::timestamptz IS NULL OR p.created_at <= $2::timestamptz)
AND ($2::timestamptz IS NULL OR p.created_at < (DATE_TRUNC('day', $2::timestamptz) + INTERVAL '1 day'))
AND ($3::text[] IS NULL OR p.billing_account = ANY($3::text[]))
AND ($4::text[] IS NULL OR p.billing_account != ALL($4::text[]))
),
Expand Down
2 changes: 1 addition & 1 deletion sql/reports/sfdc/payments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ WHERE
))
AND ($6::text IS NULL OR challenge_name ILIKE '%' || $6 || '%')
AND created_at >= COALESCE($7::timestamptz, (NOW() AT TIME ZONE 'UTC') - INTERVAL '45 days')
AND ($8::timestamptz IS NULL OR created_at <= $8::timestamptz)
AND ($8::timestamptz IS NULL OR created_at < (DATE_TRUNC('day', $8::timestamptz) + INTERVAL '1 day'))
AND ($9::numeric IS NULL OR total_amount >= $9::numeric)
AND ($10::numeric IS NULL OR total_amount <= $10::numeric)
AND ($11::text[] IS NULL OR reported_challenge_status::text = ANY($11::text[]))
Expand Down
4 changes: 2 additions & 2 deletions src/reports/payment/dto/member-payment-accrual.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class MemberPaymentAccrualQueryDto {

@ApiPropertyOptional({
description:
"End date (inclusive) for filtering payment creation date in ISO 8601 format",
example: "2024-01-31T23:59:59.000Z",
"End date (inclusive through the full calendar day) for filtering payment creation date in ISO 8601 format",
example: "2024-01-31",
})
@IsOptional()
@IsDateString()
Expand Down
12 changes: 12 additions & 0 deletions src/reports/payment/payment-reports.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,16 @@ describe("PaymentReportsService", () => {
["Challenge Payment"],
]);
});

it("uses the full inclusive end date in the payment SQL", () => {
const paymentSql = new SqlLoaderService().load(
"reports/payment/member-payment-accrual.sql",
);

expect(paymentSql).toContain("p.created_at >= pr.start_date");
expect(paymentSql).toContain(
"DATE_TRUNC('day', pr.end_date) + INTERVAL '1 day'",
);
expect(paymentSql).not.toContain("p.created_at <= pr.end_date");
});
});
10 changes: 6 additions & 4 deletions src/reports/sfdc/sfdc-reports.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ export class PaymentsReportQueryDto {

@ApiProperty({
required: false,
description: "End date for the report query in ISO 8601 format",
example: "2023-01-31T23:59:59.000Z",
description:
"End date (inclusive through the full calendar day) for the report query in ISO 8601 format",
example: "2023-01-31",
})
@IsOptional()
@IsDateString()
Expand Down Expand Up @@ -862,8 +863,9 @@ export class BaFeesReportQueryDto {

@ApiProperty({
required: false,
description: "End date for the report query in ISO 8601 format",
example: "2023-01-31T23:59:59.000Z",
description:
"End date (inclusive through the full calendar day) for the report query in ISO 8601 format",
example: "2023-01-31",
})
@IsOptional()
@IsDateString()
Expand Down
27 changes: 27 additions & 0 deletions src/reports/sfdc/sfdc-reports.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,18 @@ describe("SfdcReportsService - getPaymentsReport", () => {
);
});

it("uses the full inclusive end date in the payments SQL", () => {
const paymentsSql = readFileSync(
join(__dirname, "../../../sql/reports/sfdc/payments.sql"),
"utf8",
);

expect(paymentsSql).toContain(
"DATE_TRUNC('day', $8::timestamptz) + INTERVAL '1 day'",
);
expect(paymentsSql).not.toContain("created_at <= $8::timestamptz");
});

it("returns mixed challenge, engagement, and unresolved challenge payments successfully", async () => {
const result = await service.getPaymentsReport(
mockPaymentQueryDto.billingAccount,
Expand Down Expand Up @@ -1108,6 +1120,21 @@ describe("SfdcReportsService - getBaFeesReport", () => {
);
});

it.each(["ba-fees.sql", "ba-fees-monthly.sql"])(
"uses the full inclusive end date in %s",
(fileName) => {
const baFeesSql = readFileSync(
join(__dirname, `../../../sql/reports/sfdc/${fileName}`),
"utf8",
);

expect(baFeesSql).toContain(
"DATE_TRUNC('day', $2::timestamptz) + INTERVAL '1 day'",
);
expect(baFeesSql).not.toContain("p.created_at <= $2::timestamptz");
},
);

it("runs a basic query successfully", async () => {
const result = await service.getBaFeesReport(
mockBaFeesQueryDto.byBillingAccount,
Expand Down
Loading