feat(billing): filter invoices and manual payments by invoice type

Adds a free-form `types` CSV filter to the invoice list DTO and query
(same treatment as `paymentMethods` — each billing source mints its own
type string, so an IsIn would drop real values), carries it into the
invoices export dataset, and surfaces a Type column plus filter pill on
both the Invoices and Manual Payments tables.
This commit is contained in:
Nathnael
2026-08-28 09:17:41 +00:00
parent 78c6f8be0a
commit a6b2519136
7 changed files with 81 additions and 2 deletions

View File

@@ -19,8 +19,10 @@ import { ExportButton } from "@/components/export/ExportButton";
import { useExchangeSettingsQuery } from "@/hooks/useExchangeSettings";
import { api } from "@/services/api";
import {
INVOICE_TYPE_OPTIONS,
PAYMENT_METHOD_OPTIONS,
invoicePaymentMethod,
invoiceTypeLabel,
paymentMethodLabel,
type Invoice,
type InvoiceListFilter,
@@ -55,6 +57,7 @@ const EIMS_STATUS_OPTIONS = [
const INVOICE_FILTER_DEFS: FilterDef[] = [
{ key: "statuses", label: "Status", type: "enum", options: STATUS_OPTIONS },
{ key: "sources", label: "Source", type: "enum", options: SOURCE_OPTIONS },
{ key: "types", label: "Type", type: "enum", options: INVOICE_TYPE_OPTIONS },
{
key: "currency",
label: "Currency",
@@ -261,6 +264,15 @@ export default function InvoicesPanel() {
size: 220,
cell: ({ row }) => <InvoiceSourceCell invoice={row.original} />,
},
{
id: "type",
header: "Type",
cell: ({ row }) => (
<Text size="sm" c="edr-text" truncate maw={180}>
{invoiceTypeLabel(row.original.type)}
</Text>
),
},
{
id: "status",
header: "Status",
@@ -389,7 +401,7 @@ export default function InvoicesPanel() {
</Box>
<Box style={{ overflowX: "auto" }} w="100%">
<Box miw={1040}>
<Box miw={1200}>
<DataTable
columns={columns}
data={rows}

View File

@@ -44,7 +44,9 @@ import { useManualPaymentSettingsQuery } from "@/hooks/useManualPaymentSettings"
import { FREIGHT_PERMS, hasPermission } from "@/lib/permissions";
import { api } from "@/services/api";
import {
INVOICE_TYPE_OPTIONS,
PAYMENT_METHOD_OPTIONS,
invoiceTypeLabel,
type InvoiceListFilter,
type OfflineUsdInvoice,
} from "@/types/invoice";
@@ -109,6 +111,13 @@ const MANUAL_PAYMENT_FILTER_DEFS: FilterDef[] = [
secondary: true,
options: SOURCE_OPTIONS,
},
{
key: "types",
label: "Type",
type: "enum",
secondary: true,
options: INVOICE_TYPE_OPTIONS,
},
{
key: "paymentMethods",
label: "Payment method",
@@ -424,6 +433,15 @@ export default function UsdPaymentsPanel({
);
},
},
{
id: "type",
header: "Type",
cell: ({ row }) => (
<Text size="sm" c="edr-text" truncate maw={180}>
{invoiceTypeLabel(row.original.type)}
</Text>
),
},
{
id: "status",
header: "Status",
@@ -523,7 +541,7 @@ export default function UsdPaymentsPanel({
</Box>
<Box style={{ overflowX: "auto" }} w="100%">
<Box miw={1160}>
<Box miw={1320}>
<DataTable
columns={columns}
data={rows}

View File

@@ -70,6 +70,8 @@ export interface InvoiceListFilter {
statuses?: string;
/** CSV of `Freight.InvoiceSource` values. */
sources?: string;
/** CSV of invoice types (see `INVOICE_TYPE_OPTIONS`). */
types?: string;
/** CSV of EIMS filing states. */
eimsStatuses?: string;
/** CSV of normalised UPPER_SNAKE payment methods (see `PAYMENT_METHOD_OPTIONS`). */
@@ -171,3 +173,28 @@ export function invoicePaymentMethod(invoice: Invoice): string | null {
/** Human label for a method value; unknown values are shown as-is. */
export const paymentMethodLabel = (method: string): string =>
PAYMENT_METHOD_LABELS.get(method) ?? method;
/**
* What an invoice bills for. Every billing source mints its own `type` string,
* so this list is the known vocabulary, not a closed enum — render an unknown
* value rather than treating it as invalid.
*/
export const INVOICE_TYPE_OPTIONS: { value: string; label: string }[] = [
{ value: "PREPAID", label: "Prepaid freight" },
{ value: "WAGON_CANCEL_FEE", label: "Wagon cancellation fee" },
{ value: "GL_FINAL", label: "General contract final" },
{ value: "ADDITIONAL_CHARGE", label: "Additional charge" },
{ value: "PORT_CHARGES", label: "Port charges" },
{ value: "MISCELLANEOUS", label: "Miscellaneous" },
{ value: "DELIVERY_FEE", label: "Delivery fee" },
{ value: "LAST_MILE_ADVANCE", label: "Last-mile advance" },
{ value: "SHIPPING_LINE_CREDIT", label: "Shipping line credit" },
{ value: "STORAGE_FEE", label: "Storage fee" },
{ value: "DEMURRAGE", label: "Demurrage" },
{ value: "MIXED_WAREHOUSE_FEES", label: "Mixed warehouse fees" },
];
/** Label for an invoice `type`, falling back to the humanised raw value. */
export const invoiceTypeLabel = (type: string): string =>
INVOICE_TYPE_OPTIONS.find((o) => o.value === type)?.label ??
type.replace(/_/g, " ");