Some checks are pending
offline / test (push) Waiting to run
Account-balance stores display names and looks up by name. Edge writes names on customer create/edit; staff UIs join from edge when needed. New verae-staff-session issues a host cookie; department HTML redirects when STAFF_AUTH=1. JOBS_EVENTS_EXCLUSIVE lets jobs-events own the durable consumer. Catalog index is cards; disabled fleet machines are grey.
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { CreditAdjustment } from './credits';
|
|
import { Invoice } from './invoicing';
|
|
import { UsageEntry } from './usage';
|
|
|
|
export function composeStatement(args: {
|
|
customerId: string;
|
|
name?: string;
|
|
veraeUserId?: string;
|
|
prepaidCents: number;
|
|
credits: CreditAdjustment[];
|
|
usage: UsageEntry[];
|
|
invoices: Invoice[];
|
|
}) {
|
|
const payments = args.invoices
|
|
.filter((i) => i.customerId === args.customerId && (i.status === 'paid' || i.status === 'issued'))
|
|
.map((i) => ({
|
|
id: i.id,
|
|
customerId: i.customerId,
|
|
cents: i.billableCents,
|
|
kind: i.status === 'paid' ? 'invoice-paid' : 'invoice-issued',
|
|
reason: i.period,
|
|
at: new Date(i.paidAtMs || i.issuedAtMs || Date.now()).toISOString(),
|
|
}));
|
|
return {
|
|
customerId: args.customerId,
|
|
name: args.name,
|
|
veraeUserId: args.veraeUserId,
|
|
prepaidCents: args.prepaidCents,
|
|
credits: args.credits.filter((c) => c.customerId === args.customerId),
|
|
usage: args.usage
|
|
.filter((u) => u.customerId === args.customerId)
|
|
.slice(-50)
|
|
.reverse()
|
|
.map((u) => ({
|
|
customerId: u.customerId,
|
|
endpointId: u.endpointId,
|
|
cents: u.cents,
|
|
at: u.timestamp.toISOString(),
|
|
})),
|
|
payments,
|
|
};
|
|
}
|