From baef14c847e8de01e49c321d63f772907182f8f2 Mon Sep 17 00:00:00 2001 From: Nathnael Date: Mon, 24 Aug 2026 07:12:51 +0000 Subject: [PATCH] style(reports): reformat revenue transactions with prettier Whole-file requote to double quotes plus wrapped column literals. No behaviour change. Kept as its own commit because it is out of step with the rest of reports/definitions, which is single-quoted: bare prettier ignores @edr/prettier-config, so running it on one file requotes that file alone. Drop this commit if the directory should stay consistent. --- .../revenue-transactions.report.ts | 144 +++++++++++------- 1 file changed, 87 insertions(+), 57 deletions(-) diff --git a/apps/edr-freight-api/src/modules/reports/definitions/revenue-transactions.report.ts b/apps/edr-freight-api/src/modules/reports/definitions/revenue-transactions.report.ts index 4f70216e8..9b060659c 100644 --- a/apps/edr-freight-api/src/modules/reports/definitions/revenue-transactions.report.ts +++ b/apps/edr-freight-api/src/modules/reports/definitions/revenue-transactions.report.ts @@ -1,6 +1,6 @@ -import { ObjectLiteral, SelectQueryBuilder } from 'typeorm'; +import { ObjectLiteral, SelectQueryBuilder } from "typeorm"; -import { ReportContext, ReportDefinition } from '../report.types'; +import { ReportContext, ReportDefinition } from "../report.types"; import { PAYMENT_CLASS_EXPR, PAYER_EXPR, @@ -13,7 +13,7 @@ import { currencyOf, periodExpr, revenueLedgerQb, -} from '../revenue-classification'; +} from "../revenue-classification"; /** * The gateway payment behind an invoice, for traceability. `invoices.payment_id` @@ -51,79 +51,109 @@ function baseQuery(ctx: ReportContext): SelectQueryBuilder { } export const revenueTransactionsReport: ReportDefinition = { - key: 'revenue-transactions', - title: 'Revenue Transactions', + key: "revenue-transactions", + title: "Revenue Transactions", description: - 'Every billed revenue line, at transaction level — booking reference, invoice number, ' + - 'charge type, cargo, quantity and the payment reference behind it. This is the ' + - 'drill-down target for the revenue summaries and the audit trail for an export.', - group: 'Finance', + "Every billed revenue line, at transaction level — booking reference, invoice number, " + + "charge type, cargo, quantity and the payment reference behind it. This is the " + + "drill-down target for the revenue summaries and the audit trail for an export.", + group: "Finance", filters: [ PERIOD_FILTER, ...REVENUE_FILTERS, - { key: 'period_value', label: 'Period bucket', type: 'text' }, + { key: "period_value", label: "Period bucket", type: "text" }, { - key: 'categoryKey', - label: 'Category (exact)', - type: 'select', + key: "categoryKey", + label: "Category (exact)", + type: "select", options: REVENUE_CATEGORIES, }, ], columns: [ - { key: 'issuedAt', label: 'Issued', type: 'date', sortable: true, sortExpr: REVENUE_DATE }, - { key: 'invoiceNumber', label: 'Invoice No.', type: 'string', sortable: true, sortExpr: 'i.invoice_number' }, - { key: 'bookingRef', label: 'Booking', type: 'string', sortable: true, sortExpr: 'b.reference' }, - { key: 'payer', label: 'Customer', type: 'string', sortable: true, sortExpr: PAYER_EXPR }, - { key: 'category', label: 'Revenue category', type: 'string', sortable: true, sortExpr: REVENUE_CATEGORY_EXPR }, - { key: 'paymentClass', label: 'Payment class', type: 'string' }, - { key: 'chargeType', label: 'Charge type', type: 'string', sortable: true, sortExpr: 'il.charge_type' }, - { key: 'cargo', label: 'Cargo', type: 'string' }, - { key: 'route', label: 'Route', type: 'string' }, - { key: 'quantity', label: 'Qty', type: 'number' }, - { key: 'unit', label: 'Unit', type: 'string' }, - { key: 'unitRate', label: 'Unit rate', type: 'money' }, - { key: 'amount', label: 'Amount', type: 'money', sortable: true, sortExpr: 'il.amount' }, - { key: 'currency', label: 'Currency', type: 'string' }, - { key: 'invoiceStatus', label: 'Invoice status', type: 'string', sortable: true, sortExpr: 'i.status' }, - { key: 'paymentRef', label: 'Payment ref', type: 'string' }, - { key: 'paymentMethod', label: 'Method', type: 'string' }, - { key: 'paymentStatus', label: 'Payment status', type: 'string' }, + { key: "issuedAt", label: "Issued", type: "date", sortable: true, sortExpr: REVENUE_DATE }, + { + key: "invoiceNumber", + label: "Invoice No.", + type: "string", + sortable: true, + sortExpr: "i.invoice_number", + }, + { + key: "bookingRef", + label: "Booking", + type: "string", + sortable: true, + sortExpr: "b.reference", + }, + { key: "payer", label: "Customer", type: "string", sortable: true, sortExpr: PAYER_EXPR }, + { + key: "category", + label: "Revenue category", + type: "string", + sortable: true, + sortExpr: REVENUE_CATEGORY_EXPR, + }, + { key: "paymentClass", label: "Payment class", type: "string" }, + { + key: "chargeType", + label: "Charge type", + type: "string", + sortable: true, + sortExpr: "il.charge_type", + }, + { key: "cargo", label: "Cargo", type: "string" }, + { key: "route", label: "Route", type: "string" }, + { key: "quantity", label: "Qty", type: "number" }, + { key: "unit", label: "Unit", type: "string" }, + { key: "unitRate", label: "Unit rate", type: "money" }, + { key: "amount", label: "Amount", type: "money", sortable: true, sortExpr: "il.amount" }, + { key: "currency", label: "Currency", type: "string" }, + { + key: "invoiceStatus", + label: "Invoice status", + type: "string", + sortable: true, + sortExpr: "i.status", + }, + { key: "paymentRef", label: "Payment ref", type: "string" }, + { key: "paymentMethod", label: "Method", type: "string" }, + { key: "paymentStatus", label: "Payment status", type: "string" }, ], - defaultSort: { key: 'issuedAt', dir: 'DESC' }, + defaultSort: { key: "issuedAt", dir: "DESC" }, query(ctx) { return baseQuery(ctx) - .select(`to_char(${REVENUE_DATE}, 'YYYY-MM-DD HH24:MI')`, 'issuedAt') - .addSelect('i.invoice_number', 'invoiceNumber') - .addSelect("COALESCE(b.reference, '—')", 'bookingRef') - .addSelect(PAYER_EXPR, 'payer') - .addSelect(REVENUE_CATEGORY_EXPR, 'category') - .addSelect(PAYMENT_CLASS_EXPR, 'paymentClass') - .addSelect('il.charge_type', 'chargeType') - .addSelect("COALESCE(ct.cargo_type_name, b.cargo_free_text, '—')", 'cargo') - .addSelect("COALESCE(oy.label, '?') || ' → ' || COALESCE(dy.label, '?')", 'route') - .addSelect('il.quantity::float8', 'quantity') - .addSelect("COALESCE(il.metadata->>'unit', '')", 'unit') - .addSelect('ROUND(il.unit_rate, 2)::float8', 'unitRate') - .addSelect('ROUND(il.amount, 2)::float8', 'amount') - .addSelect('il.currency', 'currency') - .addSelect('i.status', 'invoiceStatus') + .select(`to_char(${REVENUE_DATE}, 'YYYY-MM-DD HH24:MI')`, "issuedAt") + .addSelect("i.invoice_number", "invoiceNumber") + .addSelect("COALESCE(b.reference, '—')", "bookingRef") + .addSelect(PAYER_EXPR, "payer") + .addSelect(REVENUE_CATEGORY_EXPR, "category") + .addSelect(PAYMENT_CLASS_EXPR, "paymentClass") + .addSelect("il.charge_type", "chargeType") + .addSelect("COALESCE(ct.cargo_type_name, b.cargo_free_text, '—')", "cargo") + .addSelect("COALESCE(oy.label, '?') || ' → ' || COALESCE(dy.label, '?')", "route") + .addSelect("il.quantity::float8", "quantity") + .addSelect("COALESCE(il.metadata->>'unit', '')", "unit") + .addSelect("ROUND(il.unit_rate, 2)::float8", "unitRate") + .addSelect("ROUND(il.amount, 2)::float8", "amount") + .addSelect("il.currency", "currency") + .addSelect("i.status", "invoiceStatus") .addSelect( - `COALESCE(${latestPayment('transaction_id')}, ${latestPayment('merchant_order_id')}, '')`, - 'paymentRef', + `COALESCE(${latestPayment("transaction_id")}, ${latestPayment("merchant_order_id")}, '')`, + "paymentRef", ) - .addSelect(`COALESCE(${latestPayment('method')}, '')`, 'paymentMethod') - .addSelect(`COALESCE(${latestPayment('status')}, '')`, 'paymentStatus'); + .addSelect(`COALESCE(${latestPayment("method")}, '')`, "paymentMethod") + .addSelect(`COALESCE(${latestPayment("status")}, '')`, "paymentStatus"); }, async summary(ctx) { const row = await baseQuery(ctx) - .select(REVENUE_SUM, 'revenue') - .addSelect('COUNT(*)::int', 'lines') - .addSelect('COUNT(DISTINCT i.id)::int', 'invoices') + .select(REVENUE_SUM, "revenue") + .addSelect("COUNT(*)::int", "lines") + .addSelect("COUNT(DISTINCT i.id)::int", "invoices") .getRawOne<{ revenue: number; lines: number; invoices: number }>(); return [ - { label: 'Lines', value: Number(row?.lines ?? 0) }, - { label: 'Invoices', value: Number(row?.invoices ?? 0) }, - { label: 'Revenue', value: Number(row?.revenue ?? 0), unit: currencyOf(ctx.params) }, + { label: "Lines", value: Number(row?.lines ?? 0) }, + { label: "Invoices", value: Number(row?.invoices ?? 0) }, + { label: "Revenue", value: Number(row?.revenue ?? 0), unit: currencyOf(ctx.params) }, ]; }, };