@voyant-travel/finance 0.119.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +192 -0
- package/dist/action-ledger-drift.d.ts +29 -0
- package/dist/action-ledger-drift.d.ts.map +1 -0
- package/dist/action-ledger-drift.js +166 -0
- package/dist/booking-tax.d.ts +124 -0
- package/dist/booking-tax.d.ts.map +1 -0
- package/dist/booking-tax.js +264 -0
- package/dist/checkout-routes.d.ts +1154 -0
- package/dist/checkout-routes.d.ts.map +1 -0
- package/dist/checkout-routes.js +116 -0
- package/dist/checkout-service-plan.d.ts +137 -0
- package/dist/checkout-service-plan.d.ts.map +1 -0
- package/dist/checkout-service-plan.js +119 -0
- package/dist/checkout-service.d.ts +9 -0
- package/dist/checkout-service.d.ts.map +1 -0
- package/dist/checkout-service.js +324 -0
- package/dist/checkout-validation.d.ts +1682 -0
- package/dist/checkout-validation.d.ts.map +1 -0
- package/dist/checkout-validation.js +228 -0
- package/dist/document-download.d.ts +3 -0
- package/dist/document-download.d.ts.map +1 -0
- package/dist/document-download.js +1 -0
- package/dist/fx-money.d.ts +17 -0
- package/dist/fx-money.d.ts.map +1 -0
- package/dist/fx-money.js +194 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/invoice-fx.d.ts +134 -0
- package/dist/invoice-fx.d.ts.map +1 -0
- package/dist/invoice-fx.js +240 -0
- package/dist/invoice-number-errors.d.ts +2 -0
- package/dist/invoice-number-errors.d.ts.map +1 -0
- package/dist/invoice-number-errors.js +58 -0
- package/dist/markets-ref.d.ts +149 -0
- package/dist/markets-ref.d.ts.map +1 -0
- package/dist/markets-ref.js +17 -0
- package/dist/payment-link.d.ts +23 -0
- package/dist/payment-link.d.ts.map +1 -0
- package/dist/payment-link.js +30 -0
- package/dist/payment-policy.d.ts +113 -0
- package/dist/payment-policy.d.ts.map +1 -0
- package/dist/payment-policy.js +193 -0
- package/dist/route-runtime.d.ts +22 -0
- package/dist/route-runtime.d.ts.map +1 -0
- package/dist/route-runtime.js +18 -0
- package/dist/routes-action-ledger.d.ts +181 -0
- package/dist/routes-action-ledger.d.ts.map +1 -0
- package/dist/routes-action-ledger.js +142 -0
- package/dist/routes-booking-billing.d.ts +852 -0
- package/dist/routes-booking-billing.d.ts.map +1 -0
- package/dist/routes-booking-billing.js +223 -0
- package/dist/routes-booking-create.d.ts +3 -0
- package/dist/routes-booking-create.d.ts.map +1 -0
- package/dist/routes-booking-create.js +194 -0
- package/dist/routes-booking-reads.d.ts +46 -0
- package/dist/routes-booking-reads.d.ts.map +1 -0
- package/dist/routes-booking-reads.js +20 -0
- package/dist/routes-documents.d.ts +195 -0
- package/dist/routes-documents.d.ts.map +1 -0
- package/dist/routes-documents.js +93 -0
- package/dist/routes-invoice-core.d.ts +794 -0
- package/dist/routes-invoice-core.d.ts.map +1 -0
- package/dist/routes-invoice-core.js +238 -0
- package/dist/routes-invoice-documents.d.ts +401 -0
- package/dist/routes-invoice-documents.d.ts.map +1 -0
- package/dist/routes-invoice-documents.js +91 -0
- package/dist/routes-invoice-issue.d.ts +384 -0
- package/dist/routes-invoice-issue.d.ts.map +1 -0
- package/dist/routes-invoice-issue.js +208 -0
- package/dist/routes-payment-processing.d.ts +1193 -0
- package/dist/routes-payment-processing.d.ts.map +1 -0
- package/dist/routes-payment-processing.js +238 -0
- package/dist/routes-payments.d.ts +309 -0
- package/dist/routes-payments.d.ts.map +1 -0
- package/dist/routes-payments.js +94 -0
- package/dist/routes-public.d.ts +1948 -0
- package/dist/routes-public.d.ts.map +1 -0
- package/dist/routes-public.js +275 -0
- package/dist/routes-reference-data.d.ts +977 -0
- package/dist/routes-reference-data.d.ts.map +1 -0
- package/dist/routes-reference-data.js +191 -0
- package/dist/routes-reports.d.ts +344 -0
- package/dist/routes-reports.d.ts.map +1 -0
- package/dist/routes-reports.js +93 -0
- package/dist/routes-runtime.d.ts +71 -0
- package/dist/routes-runtime.d.ts.map +1 -0
- package/dist/routes-runtime.js +59 -0
- package/dist/routes-settlement.d.ts +67 -0
- package/dist/routes-settlement.d.ts.map +1 -0
- package/dist/routes-settlement.js +23 -0
- package/dist/routes-shared.d.ts +35 -0
- package/dist/routes-shared.d.ts.map +1 -0
- package/dist/routes-shared.js +10 -0
- package/dist/routes-supplier-invoices.d.ts +778 -0
- package/dist/routes-supplier-invoices.d.ts.map +1 -0
- package/dist/routes-supplier-invoices.js +159 -0
- package/dist/routes-vouchers.d.ts +228 -0
- package/dist/routes-vouchers.d.ts.map +1 -0
- package/dist/routes-vouchers.js +54 -0
- package/dist/routes.d.ts +5577 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +44 -0
- package/dist/schema/booking-billing.d.ts +1006 -0
- package/dist/schema/booking-billing.d.ts.map +1 -0
- package/dist/schema/booking-billing.js +106 -0
- package/dist/schema/enums.d.ts +48 -0
- package/dist/schema/enums.d.ts.map +1 -0
- package/dist/schema/enums.js +237 -0
- package/dist/schema/invoice-documents.d.ts +1245 -0
- package/dist/schema/invoice-documents.d.ts.map +1 -0
- package/dist/schema/invoice-documents.js +140 -0
- package/dist/schema/payment-instruments.d.ts +418 -0
- package/dist/schema/payment-instruments.d.ts.map +1 -0
- package/dist/schema/payment-instruments.js +45 -0
- package/dist/schema/payment-processing.d.ts +563 -0
- package/dist/schema/payment-processing.d.ts.map +1 -0
- package/dist/schema/payment-processing.js +65 -0
- package/dist/schema/payment-sessions.d.ts +728 -0
- package/dist/schema/payment-sessions.d.ts.map +1 -0
- package/dist/schema/payment-sessions.js +79 -0
- package/dist/schema/receivables.d.ts +1474 -0
- package/dist/schema/receivables.d.ts.map +1 -0
- package/dist/schema/receivables.js +179 -0
- package/dist/schema/relations.d.ts +82 -0
- package/dist/schema/relations.d.ts.map +1 -0
- package/dist/schema/relations.js +144 -0
- package/dist/schema/supplier-invoices.d.ts +1619 -0
- package/dist/schema/supplier-invoices.d.ts.map +1 -0
- package/dist/schema/supplier-invoices.js +228 -0
- package/dist/schema/tax.d.ts +712 -0
- package/dist/schema/tax.d.ts.map +1 -0
- package/dist/schema/tax.js +98 -0
- package/dist/schema/vouchers.d.ts +444 -0
- package/dist/schema/vouchers.d.ts.map +1 -0
- package/dist/schema/vouchers.js +64 -0
- package/dist/schema.d.ts +12 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +11 -0
- package/dist/service-accountant-shares.d.ts +106 -0
- package/dist/service-accountant-shares.d.ts.map +1 -0
- package/dist/service-accountant-shares.js +331 -0
- package/dist/service-action-ledger-accounting.d.ts +104 -0
- package/dist/service-action-ledger-accounting.d.ts.map +1 -0
- package/dist/service-action-ledger-accounting.js +386 -0
- package/dist/service-action-ledger-booking-payments.d.ts +48 -0
- package/dist/service-action-ledger-booking-payments.d.ts.map +1 -0
- package/dist/service-action-ledger-booking-payments.js +178 -0
- package/dist/service-action-ledger-bookings.d.ts +44 -0
- package/dist/service-action-ledger-bookings.d.ts.map +1 -0
- package/dist/service-action-ledger-bookings.js +81 -0
- package/dist/service-action-ledger-payment-authorizations.d.ts +48 -0
- package/dist/service-action-ledger-payment-authorizations.d.ts.map +1 -0
- package/dist/service-action-ledger-payment-authorizations.js +209 -0
- package/dist/service-action-ledger-payment-sessions.d.ts +83 -0
- package/dist/service-action-ledger-payment-sessions.d.ts.map +1 -0
- package/dist/service-action-ledger-payment-sessions.js +294 -0
- package/dist/service-action-ledger-supplier-invoices.d.ts +27 -0
- package/dist/service-action-ledger-supplier-invoices.d.ts.map +1 -0
- package/dist/service-action-ledger-supplier-invoices.js +111 -0
- package/dist/service-action-ledger-supplier-payments.d.ts +21 -0
- package/dist/service-action-ledger-supplier-payments.d.ts.map +1 -0
- package/dist/service-action-ledger-supplier-payments.js +97 -0
- package/dist/service-action-ledger.d.ts +7 -0
- package/dist/service-action-ledger.d.ts.map +1 -0
- package/dist/service-action-ledger.js +6 -0
- package/dist/service-aggregates.d.ts +96 -0
- package/dist/service-aggregates.d.ts.map +1 -0
- package/dist/service-aggregates.js +294 -0
- package/dist/service-booking-billing.d.ts +2322 -0
- package/dist/service-booking-billing.d.ts.map +1 -0
- package/dist/service-booking-billing.js +8 -0
- package/dist/service-booking-create.d.ts +410 -0
- package/dist/service-booking-create.d.ts.map +1 -0
- package/dist/service-booking-create.js +1256 -0
- package/dist/service-booking-guarantees.d.ts +725 -0
- package/dist/service-booking-guarantees.d.ts.map +1 -0
- package/dist/service-booking-guarantees.js +153 -0
- package/dist/service-booking-item-billing.d.ts +1062 -0
- package/dist/service-booking-item-billing.d.ts.map +1 -0
- package/dist/service-booking-item-billing.js +77 -0
- package/dist/service-booking-payment-schedules.d.ts +557 -0
- package/dist/service-booking-payment-schedules.d.ts.map +1 -0
- package/dist/service-booking-payment-schedules.js +372 -0
- package/dist/service-bookings-dual-create.d.ts +308 -0
- package/dist/service-bookings-dual-create.d.ts.map +1 -0
- package/dist/service-bookings-dual-create.js +131 -0
- package/dist/service-boundary-sql.d.ts +6 -0
- package/dist/service-boundary-sql.d.ts.map +1 -0
- package/dist/service-boundary-sql.js +15 -0
- package/dist/service-cost-categories.d.ts +26 -0
- package/dist/service-cost-categories.d.ts.map +1 -0
- package/dist/service-cost-categories.js +76 -0
- package/dist/service-documents.d.ts +80 -0
- package/dist/service-documents.d.ts.map +1 -0
- package/dist/service-documents.js +228 -0
- package/dist/service-invoice-artifacts.d.ts +246 -0
- package/dist/service-invoice-artifacts.d.ts.map +1 -0
- package/dist/service-invoice-artifacts.js +277 -0
- package/dist/service-invoice-core.d.ts +405 -0
- package/dist/service-invoice-core.d.ts.map +1 -0
- package/dist/service-invoice-core.js +290 -0
- package/dist/service-invoice-credit-notes.d.ts +973 -0
- package/dist/service-invoice-credit-notes.d.ts.map +1 -0
- package/dist/service-invoice-credit-notes.js +142 -0
- package/dist/service-invoice-from-booking.d.ts +41 -0
- package/dist/service-invoice-from-booking.d.ts.map +1 -0
- package/dist/service-invoice-from-booking.js +267 -0
- package/dist/service-invoice-line-items.d.ts +432 -0
- package/dist/service-invoice-line-items.d.ts.map +1 -0
- package/dist/service-invoice-line-items.js +102 -0
- package/dist/service-invoice-numbering.d.ts +227 -0
- package/dist/service-invoice-numbering.d.ts.map +1 -0
- package/dist/service-invoice-numbering.js +260 -0
- package/dist/service-invoice-payments.d.ts +673 -0
- package/dist/service-invoice-payments.d.ts.map +1 -0
- package/dist/service-invoice-payments.js +398 -0
- package/dist/service-invoices.d.ts +2501 -0
- package/dist/service-invoices.d.ts.map +1 -0
- package/dist/service-invoices.js +12 -0
- package/dist/service-issue.d.ts +207 -0
- package/dist/service-issue.d.ts.map +1 -0
- package/dist/service-issue.js +431 -0
- package/dist/service-payment-authorizations.d.ts +164 -0
- package/dist/service-payment-authorizations.d.ts.map +1 -0
- package/dist/service-payment-authorizations.js +227 -0
- package/dist/service-payment-instruments.d.ts +116 -0
- package/dist/service-payment-instruments.d.ts.map +1 -0
- package/dist/service-payment-instruments.js +99 -0
- package/dist/service-payment-processing.d.ts +676 -0
- package/dist/service-payment-processing.d.ts.map +1 -0
- package/dist/service-payment-processing.js +10 -0
- package/dist/service-payment-session-completion.d.ts +48 -0
- package/dist/service-payment-session-completion.d.ts.map +1 -0
- package/dist/service-payment-session-completion.js +238 -0
- package/dist/service-payment-sessions.d.ts +361 -0
- package/dist/service-payment-sessions.d.ts.map +1 -0
- package/dist/service-payment-sessions.js +280 -0
- package/dist/service-profitability.d.ts +114 -0
- package/dist/service-profitability.d.ts.map +1 -0
- package/dist/service-profitability.js +794 -0
- package/dist/service-public.d.ts +553 -0
- package/dist/service-public.d.ts.map +1 -0
- package/dist/service-public.js +583 -0
- package/dist/service-reference-data.d.ts +272 -0
- package/dist/service-reference-data.d.ts.map +1 -0
- package/dist/service-reference-data.js +280 -0
- package/dist/service-rendition-wait.d.ts +38 -0
- package/dist/service-rendition-wait.d.ts.map +1 -0
- package/dist/service-rendition-wait.js +67 -0
- package/dist/service-reports.d.ts +37 -0
- package/dist/service-reports.d.ts.map +1 -0
- package/dist/service-reports.js +62 -0
- package/dist/service-settlement.d.ts +46 -0
- package/dist/service-settlement.d.ts.map +1 -0
- package/dist/service-settlement.js +185 -0
- package/dist/service-shared.d.ts +541 -0
- package/dist/service-shared.d.ts.map +1 -0
- package/dist/service-shared.js +764 -0
- package/dist/service-supplier-invoices.d.ts +871 -0
- package/dist/service-supplier-invoices.d.ts.map +1 -0
- package/dist/service-supplier-invoices.js +744 -0
- package/dist/service-supplier-payments.d.ts +69 -0
- package/dist/service-supplier-payments.d.ts.map +1 -0
- package/dist/service-supplier-payments.js +136 -0
- package/dist/service-vouchers-migration.d.ts +44 -0
- package/dist/service-vouchers-migration.d.ts.map +1 -0
- package/dist/service-vouchers-migration.js +148 -0
- package/dist/service-vouchers.d.ts +157 -0
- package/dist/service-vouchers.d.ts.map +1 -0
- package/dist/service-vouchers.js +191 -0
- package/dist/service.d.ts +6490 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +29 -0
- package/dist/validation-billing.d.ts +2 -0
- package/dist/validation-billing.d.ts.map +1 -0
- package/dist/validation-billing.js +1 -0
- package/dist/validation-payments.d.ts +2 -0
- package/dist/validation-payments.d.ts.map +1 -0
- package/dist/validation-payments.js +1 -0
- package/dist/validation-public.d.ts +2 -0
- package/dist/validation-public.d.ts.map +1 -0
- package/dist/validation-public.js +1 -0
- package/dist/validation-shared.d.ts +2 -0
- package/dist/validation-shared.d.ts.map +1 -0
- package/dist/validation-shared.js +1 -0
- package/dist/validation-vouchers.d.ts +2 -0
- package/dist/validation-vouchers.d.ts.map +1 -0
- package/dist/validation-vouchers.js +1 -0
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +1 -0
- package/package.json +121 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supplier-invoices.d.ts","sourceRoot":"","sources":["../../src/schema/supplier-invoices.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;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,GAAG,OAAO,uBAAuB,CAAC,YAAY,CAAA;AAOnF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuBtC,CAAA;AAED,MAAM,MAAM,yBAAyB,GAAG,OAAO,0BAA0B,CAAC,YAAY,CAAA;AACtF,MAAM,MAAM,4BAA4B,GAAG,OAAO,0BAA0B,CAAC,YAAY,CAAA"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { typeId, typeIdRef } from "@voyant-travel/db/lib/typeid-column";
|
|
2
|
+
import { sql } from "drizzle-orm";
|
|
3
|
+
import { check, date, index, integer, jsonb, pgTable, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
|
|
4
|
+
import { apServiceTypeEnum, costAllocationSplitMethodEnum, costAllocationTargetTypeEnum, paymentMethodEnum, paymentStatusEnum, supplierInvoiceStatusEnum, } from "./enums.js";
|
|
5
|
+
import { paymentInstruments } from "./payment-instruments.js";
|
|
6
|
+
// ---------- supplier_payments ----------
|
|
7
|
+
export const supplierPayments = pgTable("supplier_payments", {
|
|
8
|
+
id: typeId("supplier_payments"),
|
|
9
|
+
// AP payments may settle a whole supplier invoice (no single booking) or a
|
|
10
|
+
// booking-scoped supplier service. At least one of bookingId /
|
|
11
|
+
// supplierInvoiceId must be set (check below). See §5.4.
|
|
12
|
+
bookingId: text("booking_id"),
|
|
13
|
+
supplierId: text("supplier_id"),
|
|
14
|
+
bookingSupplierStatusId: text("booking_supplier_status_id"),
|
|
15
|
+
// Finance-local → REAL FK. The supplier invoice this payment settles.
|
|
16
|
+
supplierInvoiceId: typeIdRef("supplier_invoice_id").references(() => supplierInvoices.id, {
|
|
17
|
+
onDelete: "set null",
|
|
18
|
+
}),
|
|
19
|
+
amountCents: integer("amount_cents").notNull(),
|
|
20
|
+
currency: text("currency").notNull(),
|
|
21
|
+
baseCurrency: text("base_currency"),
|
|
22
|
+
baseAmountCents: integer("base_amount_cents"),
|
|
23
|
+
fxRateSetId: text("fx_rate_set_id"),
|
|
24
|
+
paymentMethod: paymentMethodEnum("payment_method").notNull(),
|
|
25
|
+
paymentInstrumentId: typeIdRef("payment_instrument_id").references(() => paymentInstruments.id, {
|
|
26
|
+
onDelete: "set null",
|
|
27
|
+
}),
|
|
28
|
+
status: paymentStatusEnum("status").notNull().default("pending"),
|
|
29
|
+
referenceNumber: text("reference_number"),
|
|
30
|
+
paymentDate: date("payment_date").notNull(),
|
|
31
|
+
notes: text("notes"),
|
|
32
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
33
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
34
|
+
}, (table) => [
|
|
35
|
+
index("idx_supplier_payments_booking").on(table.bookingId),
|
|
36
|
+
index("idx_supplier_payments_booking_created").on(table.bookingId, table.createdAt),
|
|
37
|
+
index("idx_supplier_payments_supplier").on(table.supplierId),
|
|
38
|
+
index("idx_supplier_payments_supplier_created").on(table.supplierId, table.createdAt),
|
|
39
|
+
index("idx_supplier_payments_fx_rate_set").on(table.fxRateSetId),
|
|
40
|
+
index("idx_supplier_payments_instrument").on(table.paymentInstrumentId),
|
|
41
|
+
index("idx_supplier_payments_status").on(table.status),
|
|
42
|
+
index("idx_supplier_payments_status_created").on(table.status, table.createdAt),
|
|
43
|
+
index("idx_supplier_payments_date").on(table.paymentDate),
|
|
44
|
+
index("idx_supplier_payments_supplier_invoice").on(table.supplierInvoiceId),
|
|
45
|
+
// A payment must attach to a booking and/or a supplier invoice (§5.4).
|
|
46
|
+
check("ck_supplier_payments_target",
|
|
47
|
+
// agent-quality: raw-sql reviewed -- owner: finance; dynamic SQL interpolation uses Drizzle parameter binding or vetted SQL identifiers.
|
|
48
|
+
sql `${table.bookingId} IS NOT NULL OR ${table.supplierInvoiceId} IS NOT NULL`),
|
|
49
|
+
]);
|
|
50
|
+
// ---------- supplier_invoices (accounts payable) ----------
|
|
51
|
+
// Sibling of `invoices` (AR), NOT a direction flag on it — see
|
|
52
|
+
// docs/architecture/supplier-invoices-profitability.md §4.1 / §5.1.
|
|
53
|
+
export const supplierInvoices = pgTable("supplier_invoices", {
|
|
54
|
+
id: typeId("supplier_invoices"),
|
|
55
|
+
// Cross-module reference → plain indexed text (§4.3). Which supplier billed us.
|
|
56
|
+
supplierId: text("supplier_id").notNull(),
|
|
57
|
+
// The SUPPLIER's invoice number (their document). Unique per supplier, not global.
|
|
58
|
+
supplierInvoiceNo: text("supplier_invoice_no").notNull(),
|
|
59
|
+
// Optional internal AP reference / our own series, when an operator wants one.
|
|
60
|
+
internalRef: text("internal_ref"),
|
|
61
|
+
status: supplierInvoiceStatusEnum("status").notNull().default("draft"),
|
|
62
|
+
currency: text("currency").notNull(),
|
|
63
|
+
baseCurrency: text("base_currency"),
|
|
64
|
+
fxRateSetId: text("fx_rate_set_id"),
|
|
65
|
+
subtotalCents: integer("subtotal_cents").notNull().default(0),
|
|
66
|
+
taxCents: integer("tax_cents").notNull().default(0),
|
|
67
|
+
totalCents: integer("total_cents").notNull().default(0),
|
|
68
|
+
// Operator accounting-base amounts, snapshotted at the FX rate effective on
|
|
69
|
+
// `issueDate` (end-to-end FX §). Null for pre-feature rows (lazy/forward-only)
|
|
70
|
+
// and when the invoice currency has no resolvable rate.
|
|
71
|
+
baseSubtotalCents: integer("base_subtotal_cents"),
|
|
72
|
+
baseTaxCents: integer("base_tax_cents"),
|
|
73
|
+
baseTotalCents: integer("base_total_cents"),
|
|
74
|
+
paidCents: integer("paid_cents").notNull().default(0),
|
|
75
|
+
balanceDueCents: integer("balance_due_cents").notNull().default(0),
|
|
76
|
+
// Reuses tax_regimes — supports reverse_charge for cross-border supply.
|
|
77
|
+
taxRegimeId: typeIdRef("tax_regime_id"),
|
|
78
|
+
issueDate: date("issue_date").notNull(),
|
|
79
|
+
dueDate: date("due_date"),
|
|
80
|
+
receivedAt: timestamp("received_at", { withTimezone: true }),
|
|
81
|
+
approvedAt: timestamp("approved_at", { withTimezone: true }),
|
|
82
|
+
approvedBy: text("approved_by"),
|
|
83
|
+
// Attached PDF — matches the invoices/invoice_attachments `storageKey`
|
|
84
|
+
// convention (§5.1), NOT a media id.
|
|
85
|
+
storageKey: text("storage_key"),
|
|
86
|
+
// FK to a future invoice_extractions row (PR5); plain text for now.
|
|
87
|
+
extractionId: text("extraction_id"),
|
|
88
|
+
notes: text("notes"),
|
|
89
|
+
voidedAt: timestamp("voided_at", { withTimezone: true }),
|
|
90
|
+
voidReason: text("void_reason"),
|
|
91
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
92
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
93
|
+
deletedAt: timestamp("deleted_at", { withTimezone: true }),
|
|
94
|
+
}, (table) => [
|
|
95
|
+
// Every supplier-invoice read path filters `deleted_at IS NULL`
|
|
96
|
+
// (soft delete), so the hot list/filter indexes are partial — smaller
|
|
97
|
+
// and the planner can use them for all of those queries.
|
|
98
|
+
index("idx_supplier_invoices_supplier")
|
|
99
|
+
.on(table.supplierId)
|
|
100
|
+
// agent-quality: raw-sql reviewed -- owner: finance; dynamic SQL interpolation uses Drizzle parameter binding or vetted SQL identifiers.
|
|
101
|
+
.where(sql `${table.deletedAt} IS NULL`),
|
|
102
|
+
index("idx_supplier_invoices_supplier_created")
|
|
103
|
+
.on(table.supplierId, table.createdAt)
|
|
104
|
+
// agent-quality: raw-sql reviewed -- owner: finance; dynamic SQL interpolation uses Drizzle parameter binding or vetted SQL identifiers.
|
|
105
|
+
.where(sql `${table.deletedAt} IS NULL`),
|
|
106
|
+
// agent-quality: raw-sql reviewed -- owner: finance; dynamic SQL interpolation uses Drizzle parameter binding or vetted SQL identifiers.
|
|
107
|
+
index("idx_supplier_invoices_status").on(table.status).where(sql `${table.deletedAt} IS NULL`),
|
|
108
|
+
index("idx_supplier_invoices_status_created")
|
|
109
|
+
.on(table.status, table.createdAt)
|
|
110
|
+
// agent-quality: raw-sql reviewed -- owner: finance; dynamic SQL interpolation uses Drizzle parameter binding or vetted SQL identifiers.
|
|
111
|
+
.where(sql `${table.deletedAt} IS NULL`),
|
|
112
|
+
index("idx_supplier_invoices_due_date")
|
|
113
|
+
.on(table.dueDate)
|
|
114
|
+
// agent-quality: raw-sql reviewed -- owner: finance; dynamic SQL interpolation uses Drizzle parameter binding or vetted SQL identifiers.
|
|
115
|
+
.where(sql `${table.deletedAt} IS NULL`),
|
|
116
|
+
index("idx_supplier_invoices_fx_rate_set").on(table.fxRateSetId),
|
|
117
|
+
// The supplier's number is unique per supplier (AP convention), ignoring voids.
|
|
118
|
+
uniqueIndex("supplier_invoices_supplier_number_active_idx")
|
|
119
|
+
.on(table.supplierId, table.supplierInvoiceNo)
|
|
120
|
+
// agent-quality: raw-sql reviewed -- owner: finance; dynamic SQL interpolation uses Drizzle parameter binding or vetted SQL identifiers.
|
|
121
|
+
.where(sql `${table.status} <> 'void' AND ${table.deletedAt} IS NULL`),
|
|
122
|
+
// If any base amount is present, base_currency must be set (mirrors invoices).
|
|
123
|
+
check("ck_supplier_invoices_base_currency",
|
|
124
|
+
// agent-quality: raw-sql reviewed -- owner: finance; dynamic SQL interpolation uses Drizzle parameter binding or vetted SQL identifiers.
|
|
125
|
+
sql `${table.baseCurrency} IS NOT NULL OR ${table.fxRateSetId} IS NULL`),
|
|
126
|
+
]);
|
|
127
|
+
// ---------- supplier_invoice_lines ----------
|
|
128
|
+
export const supplierInvoiceLines = pgTable("supplier_invoice_lines", {
|
|
129
|
+
id: typeId("supplier_invoice_lines"),
|
|
130
|
+
// Finance-local → REAL FK (§4.3).
|
|
131
|
+
supplierInvoiceId: typeIdRef("supplier_invoice_id")
|
|
132
|
+
.notNull()
|
|
133
|
+
.references(() => supplierInvoices.id, { onDelete: "cascade" }),
|
|
134
|
+
description: text("description").notNull(),
|
|
135
|
+
serviceType: apServiceTypeEnum("service_type").notNull().default("other"),
|
|
136
|
+
// Operator-configurable cost category (finance-local → real FK). The
|
|
137
|
+
// user-facing classification; `serviceType` is kept for back-compat.
|
|
138
|
+
costCategoryId: typeIdRef("cost_category_id").references(() => costCategories.id, {
|
|
139
|
+
onDelete: "set null",
|
|
140
|
+
}),
|
|
141
|
+
// Cross-module → plain text ref to supplier_services (no FK).
|
|
142
|
+
supplierServiceId: text("supplier_service_id"),
|
|
143
|
+
quantity: integer("quantity").notNull().default(1),
|
|
144
|
+
unitAmountCents: integer("unit_amount_cents").notNull(),
|
|
145
|
+
taxRateBps: integer("tax_rate_bps"),
|
|
146
|
+
taxAmountCents: integer("tax_amount_cents").notNull().default(0),
|
|
147
|
+
totalAmountCents: integer("total_amount_cents").notNull(),
|
|
148
|
+
sortOrder: integer("sort_order").notNull().default(0),
|
|
149
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
150
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
151
|
+
}, (table) => [
|
|
152
|
+
index("idx_supplier_invoice_lines_invoice").on(table.supplierInvoiceId),
|
|
153
|
+
index("idx_supplier_invoice_lines_invoice_sort").on(table.supplierInvoiceId, table.sortOrder),
|
|
154
|
+
index("idx_supplier_invoice_lines_service_type").on(table.serviceType),
|
|
155
|
+
]);
|
|
156
|
+
// ---------- cost_categories ----------
|
|
157
|
+
// Operator-configurable cost categories (transportation, accommodation,
|
|
158
|
+
// guides/touristic services, …). Selected on supplier-invoice lines and used
|
|
159
|
+
// for the per-category cost breakdown in profitability.
|
|
160
|
+
export const costCategories = pgTable("cost_categories", {
|
|
161
|
+
id: typeId("cost_categories"),
|
|
162
|
+
name: text("name").notNull(),
|
|
163
|
+
sortOrder: integer("sort_order").notNull().default(0),
|
|
164
|
+
archivedAt: timestamp("archived_at", { withTimezone: true }),
|
|
165
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
166
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
167
|
+
}, (table) => [index("idx_cost_categories_sort").on(table.sortOrder)]);
|
|
168
|
+
// ---------- supplier_cost_allocations ----------
|
|
169
|
+
// Attributes a line (or whole invoice) to a departure / product / booking /
|
|
170
|
+
// traveller. A line may split across many allocations (§6). Invariants are
|
|
171
|
+
// enforced in the service layer (§6.1).
|
|
172
|
+
export const supplierCostAllocations = pgTable("supplier_cost_allocations", {
|
|
173
|
+
id: typeId("supplier_cost_allocations"),
|
|
174
|
+
// Finance-local → REAL FKs (§4.3).
|
|
175
|
+
supplierInvoiceId: typeIdRef("supplier_invoice_id")
|
|
176
|
+
.notNull()
|
|
177
|
+
.references(() => supplierInvoices.id, { onDelete: "cascade" }),
|
|
178
|
+
// Null = allocates the whole invoice (line-less mode).
|
|
179
|
+
supplierInvoiceLineId: typeIdRef("supplier_invoice_line_id").references(() => supplierInvoiceLines.id, { onDelete: "cascade" }),
|
|
180
|
+
targetType: costAllocationTargetTypeEnum("target_type").notNull(),
|
|
181
|
+
// Cross-module target refs → plain indexed text (§4.3). Exactly one is set
|
|
182
|
+
// per row to match `targetType` (check constraint below + service guard).
|
|
183
|
+
departureId: text("departure_id"),
|
|
184
|
+
productId: text("product_id"),
|
|
185
|
+
bookingId: text("booking_id"),
|
|
186
|
+
bookingItemId: text("booking_item_id"),
|
|
187
|
+
travelerId: text("traveler_id"),
|
|
188
|
+
amountCents: integer("amount_cents").notNull(),
|
|
189
|
+
baseAmountCents: integer("base_amount_cents"),
|
|
190
|
+
splitMethod: costAllocationSplitMethodEnum("split_method").notNull().default("manual"),
|
|
191
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
192
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
193
|
+
}, (table) => [
|
|
194
|
+
index("idx_supplier_cost_allocations_invoice").on(table.supplierInvoiceId),
|
|
195
|
+
index("idx_supplier_cost_allocations_line").on(table.supplierInvoiceLineId),
|
|
196
|
+
index("idx_supplier_cost_allocations_departure").on(table.departureId),
|
|
197
|
+
index("idx_supplier_cost_allocations_product").on(table.productId),
|
|
198
|
+
index("idx_supplier_cost_allocations_booking").on(table.bookingId),
|
|
199
|
+
// Exactly one target id is set, and it matches `target_type` (§6.1 rule 2).
|
|
200
|
+
check("ck_supplier_cost_allocations_one_target", sql `(
|
|
201
|
+
(${table.targetType} = 'departure' AND ${table.departureId} IS NOT NULL AND ${table.productId} IS NULL AND ${table.bookingId} IS NULL AND ${table.bookingItemId} IS NULL AND ${table.travelerId} IS NULL)
|
|
202
|
+
OR (${table.targetType} = 'product' AND ${table.productId} IS NOT NULL AND ${table.departureId} IS NULL AND ${table.bookingId} IS NULL AND ${table.bookingItemId} IS NULL AND ${table.travelerId} IS NULL)
|
|
203
|
+
OR (${table.targetType} = 'booking' AND ${table.bookingId} IS NOT NULL AND ${table.departureId} IS NULL AND ${table.productId} IS NULL AND ${table.travelerId} IS NULL)
|
|
204
|
+
OR (${table.targetType} = 'traveler' AND ${table.travelerId} IS NOT NULL AND ${table.departureId} IS NULL AND ${table.productId} IS NULL)
|
|
205
|
+
OR (${table.targetType} = 'unattributed' AND ${table.departureId} IS NULL AND ${table.productId} IS NULL AND ${table.bookingId} IS NULL AND ${table.bookingItemId} IS NULL AND ${table.travelerId} IS NULL)
|
|
206
|
+
)`),
|
|
207
|
+
]);
|
|
208
|
+
// ---------- supplier_invoice_attachments ----------
|
|
209
|
+
// Mirrors invoice_attachments: metadata + storageKey for supporting files
|
|
210
|
+
// (the received PDF, contracts, proof of payment, …). Bytes live in R2;
|
|
211
|
+
// the template owns the upload endpoint.
|
|
212
|
+
export const supplierInvoiceAttachments = pgTable("supplier_invoice_attachments", {
|
|
213
|
+
id: typeId("supplier_invoice_attachments"),
|
|
214
|
+
supplierInvoiceId: typeIdRef("supplier_invoice_id")
|
|
215
|
+
.notNull()
|
|
216
|
+
.references(() => supplierInvoices.id, { onDelete: "cascade" }),
|
|
217
|
+
kind: text("kind").notNull().default("supporting_document"),
|
|
218
|
+
name: text("name").notNull(),
|
|
219
|
+
mimeType: text("mime_type"),
|
|
220
|
+
fileSize: integer("file_size"),
|
|
221
|
+
storageKey: text("storage_key"),
|
|
222
|
+
checksum: text("checksum"),
|
|
223
|
+
metadata: jsonb("metadata"),
|
|
224
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
225
|
+
}, (table) => [
|
|
226
|
+
index("idx_supplier_invoice_attachments_invoice").on(table.supplierInvoiceId),
|
|
227
|
+
index("idx_supplier_invoice_attachments_invoice_created").on(table.supplierInvoiceId, table.createdAt),
|
|
228
|
+
]);
|