diff --git a/apps/edr-freight-web/portal/src/services/invoices.service.ts b/apps/edr-freight-web/portal/src/services/invoices.service.ts index f6b11e2ea..99b1d0dee 100644 --- a/apps/edr-freight-web/portal/src/services/invoices.service.ts +++ b/apps/edr-freight-web/portal/src/services/invoices.service.ts @@ -6,53 +6,13 @@ import type { InitiateResponse } from "./payments.service"; const B = URL_CONSTANTS.BILLING; -export interface InvoiceCompany { - id: string; - name: string; -} +/** A customer-facing invoice row, as returned by `GET /billing/my-invoices`. */ +export type PortalInvoice = Freight.IInvoice; -export interface InvoiceCompanyProfile { - id: string; - type: string; - reference: string | null; -} - -/** - * A customer-facing invoice row, as returned by `GET /billing/my-invoices`. - * Mirrors the freight `Invoice` entity (the shared `Freight.IInvoice` type is - * stale and intentionally not reused here). - */ -export interface PortalInvoice { - id: string; - invoiceNumber: string; - totalAmount: number; - currency: string; - status: Freight.InvoiceStatus; - /** Originating subsystem: booking / warehouse / demurrage. */ - source: string; - sourceId: string; - /** What the invoice bills for (e.g. PREPAID). */ - type: string; - issuedAt: string | null; - dueAt: string; - createdAt: string; - company?: InvoiceCompany; - companyProfile?: InvoiceCompanyProfile; -} - -export interface InvoiceLine { - id: string; - chargeType: string; - description?: string | null; - quantity: number; - unitRate: number; - amount: number; - currency: string; -} - -export interface PortalInvoiceDetail extends PortalInvoice { - lines: InvoiceLine[]; -} +/** An invoice plus its line items, as returned by `GET /billing/my-invoices/:id`. */ +export type PortalInvoiceDetail = Freight.IInvoice & { + lines: Freight.IInvoiceLine[]; +}; export interface PayInvoicePayload { method?: string; diff --git a/packages/types/src/freight/index.ts b/packages/types/src/freight/index.ts index e2de4519c..dbfcf655d 100644 --- a/packages/types/src/freight/index.ts +++ b/packages/types/src/freight/index.ts @@ -524,14 +524,57 @@ export interface ClearanceView { allApproved: boolean; } -export interface IInvoice extends BaseEntity { - bookingId: string; - invoiceNumber: string; +/** Company an invoice is billed to (minimal projection). */ +export interface IInvoiceCompany { + id: string; + name: string; +} + +/** Company profile (importer/exporter/forwarder/…) an invoice is billed to. */ +export interface IInvoiceCompanyProfile { + id: string; + type: string; + reference: string | null; +} + +/** A single billed line on an invoice. */ +export interface IInvoiceLine extends BaseEntity { + invoiceId: string; + chargeType: string; + description?: string | null; + /** Units billed (container count, wagon count, tons, …); defaults to 1. */ + quantity: number; + /** Price per unit; `amount` is normally `quantity * unitRate`. */ + unitRate: number; amount: number; currency: string; - status: PaymentStatus; - issuedAt: string; + metadata?: Record | null; +} + +export interface IInvoice extends BaseEntity { + invoiceNumber: string; + /** Customer (company) the invoice is billed to. */ + companyId: string; + company?: IInvoiceCompany; + /** Specific company profile billed. */ + companyProfileId: string; + companyProfile?: IInvoiceCompanyProfile; + totalAmount: number; + currency: string; + status: InvoiceStatus; + /** Originating subsystem: booking / warehouse / demurrage. */ + source: InvoiceSource; + /** Identifier of the source record (e.g. booking id). */ + sourceId: string; + /** What the invoice bills for (e.g. PREPAID). */ + type: string; + /** Set when issued; null while DRAFT. */ + issuedAt?: string | null; + /** Gateway payment that settled the invoice, once paid. */ + paymentId?: string | null; dueAt: string; + /** Present on invoice-detail reads. */ + lines?: IInvoiceLine[]; } // ── Reference Data (booking form catalog) ──────────────────────────────────────