mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
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.
This commit is contained in:
@@ -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 {
|
import {
|
||||||
PAYMENT_CLASS_EXPR,
|
PAYMENT_CLASS_EXPR,
|
||||||
PAYER_EXPR,
|
PAYER_EXPR,
|
||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
currencyOf,
|
currencyOf,
|
||||||
periodExpr,
|
periodExpr,
|
||||||
revenueLedgerQb,
|
revenueLedgerQb,
|
||||||
} from '../revenue-classification';
|
} from "../revenue-classification";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The gateway payment behind an invoice, for traceability. `invoices.payment_id`
|
* The gateway payment behind an invoice, for traceability. `invoices.payment_id`
|
||||||
@@ -51,79 +51,109 @@ function baseQuery(ctx: ReportContext): SelectQueryBuilder<ObjectLiteral> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const revenueTransactionsReport: ReportDefinition = {
|
export const revenueTransactionsReport: ReportDefinition = {
|
||||||
key: 'revenue-transactions',
|
key: "revenue-transactions",
|
||||||
title: 'Revenue Transactions',
|
title: "Revenue Transactions",
|
||||||
description:
|
description:
|
||||||
'Every billed revenue line, at transaction level — booking reference, invoice number, ' +
|
"Every billed revenue line, at transaction level — booking reference, invoice number, " +
|
||||||
'charge type, cargo, quantity and the payment reference behind it. This is the ' +
|
"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.',
|
"drill-down target for the revenue summaries and the audit trail for an export.",
|
||||||
group: 'Finance',
|
group: "Finance",
|
||||||
filters: [
|
filters: [
|
||||||
PERIOD_FILTER,
|
PERIOD_FILTER,
|
||||||
...REVENUE_FILTERS,
|
...REVENUE_FILTERS,
|
||||||
{ key: 'period_value', label: 'Period bucket', type: 'text' },
|
{ key: "period_value", label: "Period bucket", type: "text" },
|
||||||
{
|
{
|
||||||
key: 'categoryKey',
|
key: "categoryKey",
|
||||||
label: 'Category (exact)',
|
label: "Category (exact)",
|
||||||
type: 'select',
|
type: "select",
|
||||||
options: REVENUE_CATEGORIES,
|
options: REVENUE_CATEGORIES,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
columns: [
|
columns: [
|
||||||
{ key: 'issuedAt', label: 'Issued', type: 'date', sortable: true, sortExpr: REVENUE_DATE },
|
{ 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: "invoiceNumber",
|
||||||
{ key: 'payer', label: 'Customer', type: 'string', sortable: true, sortExpr: PAYER_EXPR },
|
label: "Invoice No.",
|
||||||
{ key: 'category', label: 'Revenue category', type: 'string', sortable: true, sortExpr: REVENUE_CATEGORY_EXPR },
|
type: "string",
|
||||||
{ key: 'paymentClass', label: 'Payment class', type: 'string' },
|
sortable: true,
|
||||||
{ key: 'chargeType', label: 'Charge type', type: 'string', sortable: true, sortExpr: 'il.charge_type' },
|
sortExpr: "i.invoice_number",
|
||||||
{ key: 'cargo', label: 'Cargo', type: 'string' },
|
},
|
||||||
{ key: 'route', label: 'Route', type: 'string' },
|
{
|
||||||
{ key: 'quantity', label: 'Qty', type: 'number' },
|
key: "bookingRef",
|
||||||
{ key: 'unit', label: 'Unit', type: 'string' },
|
label: "Booking",
|
||||||
{ key: 'unitRate', label: 'Unit rate', type: 'money' },
|
type: "string",
|
||||||
{ key: 'amount', label: 'Amount', type: 'money', sortable: true, sortExpr: 'il.amount' },
|
sortable: true,
|
||||||
{ key: 'currency', label: 'Currency', type: 'string' },
|
sortExpr: "b.reference",
|
||||||
{ key: 'invoiceStatus', label: 'Invoice status', type: 'string', sortable: true, sortExpr: 'i.status' },
|
},
|
||||||
{ key: 'paymentRef', label: 'Payment ref', type: 'string' },
|
{ key: "payer", label: "Customer", type: "string", sortable: true, sortExpr: PAYER_EXPR },
|
||||||
{ key: 'paymentMethod', label: 'Method', type: 'string' },
|
{
|
||||||
{ key: 'paymentStatus', label: 'Payment status', type: 'string' },
|
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) {
|
query(ctx) {
|
||||||
return baseQuery(ctx)
|
return baseQuery(ctx)
|
||||||
.select(`to_char(${REVENUE_DATE}, 'YYYY-MM-DD HH24:MI')`, 'issuedAt')
|
.select(`to_char(${REVENUE_DATE}, 'YYYY-MM-DD HH24:MI')`, "issuedAt")
|
||||||
.addSelect('i.invoice_number', 'invoiceNumber')
|
.addSelect("i.invoice_number", "invoiceNumber")
|
||||||
.addSelect("COALESCE(b.reference, '—')", 'bookingRef')
|
.addSelect("COALESCE(b.reference, '—')", "bookingRef")
|
||||||
.addSelect(PAYER_EXPR, 'payer')
|
.addSelect(PAYER_EXPR, "payer")
|
||||||
.addSelect(REVENUE_CATEGORY_EXPR, 'category')
|
.addSelect(REVENUE_CATEGORY_EXPR, "category")
|
||||||
.addSelect(PAYMENT_CLASS_EXPR, 'paymentClass')
|
.addSelect(PAYMENT_CLASS_EXPR, "paymentClass")
|
||||||
.addSelect('il.charge_type', 'chargeType')
|
.addSelect("il.charge_type", "chargeType")
|
||||||
.addSelect("COALESCE(ct.cargo_type_name, b.cargo_free_text, '—')", 'cargo')
|
.addSelect("COALESCE(ct.cargo_type_name, b.cargo_free_text, '—')", "cargo")
|
||||||
.addSelect("COALESCE(oy.label, '?') || ' → ' || COALESCE(dy.label, '?')", 'route')
|
.addSelect("COALESCE(oy.label, '?') || ' → ' || COALESCE(dy.label, '?')", "route")
|
||||||
.addSelect('il.quantity::float8', 'quantity')
|
.addSelect("il.quantity::float8", "quantity")
|
||||||
.addSelect("COALESCE(il.metadata->>'unit', '')", 'unit')
|
.addSelect("COALESCE(il.metadata->>'unit', '')", "unit")
|
||||||
.addSelect('ROUND(il.unit_rate, 2)::float8', 'unitRate')
|
.addSelect("ROUND(il.unit_rate, 2)::float8", "unitRate")
|
||||||
.addSelect('ROUND(il.amount, 2)::float8', 'amount')
|
.addSelect("ROUND(il.amount, 2)::float8", "amount")
|
||||||
.addSelect('il.currency', 'currency')
|
.addSelect("il.currency", "currency")
|
||||||
.addSelect('i.status', 'invoiceStatus')
|
.addSelect("i.status", "invoiceStatus")
|
||||||
.addSelect(
|
.addSelect(
|
||||||
`COALESCE(${latestPayment('transaction_id')}, ${latestPayment('merchant_order_id')}, '')`,
|
`COALESCE(${latestPayment("transaction_id")}, ${latestPayment("merchant_order_id")}, '')`,
|
||||||
'paymentRef',
|
"paymentRef",
|
||||||
)
|
)
|
||||||
.addSelect(`COALESCE(${latestPayment('method')}, '')`, 'paymentMethod')
|
.addSelect(`COALESCE(${latestPayment("method")}, '')`, "paymentMethod")
|
||||||
.addSelect(`COALESCE(${latestPayment('status')}, '')`, 'paymentStatus');
|
.addSelect(`COALESCE(${latestPayment("status")}, '')`, "paymentStatus");
|
||||||
},
|
},
|
||||||
async summary(ctx) {
|
async summary(ctx) {
|
||||||
const row = await baseQuery(ctx)
|
const row = await baseQuery(ctx)
|
||||||
.select(REVENUE_SUM, 'revenue')
|
.select(REVENUE_SUM, "revenue")
|
||||||
.addSelect('COUNT(*)::int', 'lines')
|
.addSelect("COUNT(*)::int", "lines")
|
||||||
.addSelect('COUNT(DISTINCT i.id)::int', 'invoices')
|
.addSelect("COUNT(DISTINCT i.id)::int", "invoices")
|
||||||
.getRawOne<{ revenue: number; lines: number; invoices: number }>();
|
.getRawOne<{ revenue: number; lines: number; invoices: number }>();
|
||||||
return [
|
return [
|
||||||
{ label: 'Lines', value: Number(row?.lines ?? 0) },
|
{ label: "Lines", value: Number(row?.lines ?? 0) },
|
||||||
{ label: 'Invoices', value: Number(row?.invoices ?? 0) },
|
{ label: "Invoices", value: Number(row?.invoices ?? 0) },
|
||||||
{ label: 'Revenue', value: Number(row?.revenue ?? 0), unit: currencyOf(ctx.params) },
|
{ label: "Revenue", value: Number(row?.revenue ?? 0), unit: currencyOf(ctx.params) },
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user