@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.
Files changed (294) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +192 -0
  3. package/dist/action-ledger-drift.d.ts +29 -0
  4. package/dist/action-ledger-drift.d.ts.map +1 -0
  5. package/dist/action-ledger-drift.js +166 -0
  6. package/dist/booking-tax.d.ts +124 -0
  7. package/dist/booking-tax.d.ts.map +1 -0
  8. package/dist/booking-tax.js +264 -0
  9. package/dist/checkout-routes.d.ts +1154 -0
  10. package/dist/checkout-routes.d.ts.map +1 -0
  11. package/dist/checkout-routes.js +116 -0
  12. package/dist/checkout-service-plan.d.ts +137 -0
  13. package/dist/checkout-service-plan.d.ts.map +1 -0
  14. package/dist/checkout-service-plan.js +119 -0
  15. package/dist/checkout-service.d.ts +9 -0
  16. package/dist/checkout-service.d.ts.map +1 -0
  17. package/dist/checkout-service.js +324 -0
  18. package/dist/checkout-validation.d.ts +1682 -0
  19. package/dist/checkout-validation.d.ts.map +1 -0
  20. package/dist/checkout-validation.js +228 -0
  21. package/dist/document-download.d.ts +3 -0
  22. package/dist/document-download.d.ts.map +1 -0
  23. package/dist/document-download.js +1 -0
  24. package/dist/fx-money.d.ts +17 -0
  25. package/dist/fx-money.d.ts.map +1 -0
  26. package/dist/fx-money.js +194 -0
  27. package/dist/index.d.ts +65 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +108 -0
  30. package/dist/invoice-fx.d.ts +134 -0
  31. package/dist/invoice-fx.d.ts.map +1 -0
  32. package/dist/invoice-fx.js +240 -0
  33. package/dist/invoice-number-errors.d.ts +2 -0
  34. package/dist/invoice-number-errors.d.ts.map +1 -0
  35. package/dist/invoice-number-errors.js +58 -0
  36. package/dist/markets-ref.d.ts +149 -0
  37. package/dist/markets-ref.d.ts.map +1 -0
  38. package/dist/markets-ref.js +17 -0
  39. package/dist/payment-link.d.ts +23 -0
  40. package/dist/payment-link.d.ts.map +1 -0
  41. package/dist/payment-link.js +30 -0
  42. package/dist/payment-policy.d.ts +113 -0
  43. package/dist/payment-policy.d.ts.map +1 -0
  44. package/dist/payment-policy.js +193 -0
  45. package/dist/route-runtime.d.ts +22 -0
  46. package/dist/route-runtime.d.ts.map +1 -0
  47. package/dist/route-runtime.js +18 -0
  48. package/dist/routes-action-ledger.d.ts +181 -0
  49. package/dist/routes-action-ledger.d.ts.map +1 -0
  50. package/dist/routes-action-ledger.js +142 -0
  51. package/dist/routes-booking-billing.d.ts +852 -0
  52. package/dist/routes-booking-billing.d.ts.map +1 -0
  53. package/dist/routes-booking-billing.js +223 -0
  54. package/dist/routes-booking-create.d.ts +3 -0
  55. package/dist/routes-booking-create.d.ts.map +1 -0
  56. package/dist/routes-booking-create.js +194 -0
  57. package/dist/routes-booking-reads.d.ts +46 -0
  58. package/dist/routes-booking-reads.d.ts.map +1 -0
  59. package/dist/routes-booking-reads.js +20 -0
  60. package/dist/routes-documents.d.ts +195 -0
  61. package/dist/routes-documents.d.ts.map +1 -0
  62. package/dist/routes-documents.js +93 -0
  63. package/dist/routes-invoice-core.d.ts +794 -0
  64. package/dist/routes-invoice-core.d.ts.map +1 -0
  65. package/dist/routes-invoice-core.js +238 -0
  66. package/dist/routes-invoice-documents.d.ts +401 -0
  67. package/dist/routes-invoice-documents.d.ts.map +1 -0
  68. package/dist/routes-invoice-documents.js +91 -0
  69. package/dist/routes-invoice-issue.d.ts +384 -0
  70. package/dist/routes-invoice-issue.d.ts.map +1 -0
  71. package/dist/routes-invoice-issue.js +208 -0
  72. package/dist/routes-payment-processing.d.ts +1193 -0
  73. package/dist/routes-payment-processing.d.ts.map +1 -0
  74. package/dist/routes-payment-processing.js +238 -0
  75. package/dist/routes-payments.d.ts +309 -0
  76. package/dist/routes-payments.d.ts.map +1 -0
  77. package/dist/routes-payments.js +94 -0
  78. package/dist/routes-public.d.ts +1948 -0
  79. package/dist/routes-public.d.ts.map +1 -0
  80. package/dist/routes-public.js +275 -0
  81. package/dist/routes-reference-data.d.ts +977 -0
  82. package/dist/routes-reference-data.d.ts.map +1 -0
  83. package/dist/routes-reference-data.js +191 -0
  84. package/dist/routes-reports.d.ts +344 -0
  85. package/dist/routes-reports.d.ts.map +1 -0
  86. package/dist/routes-reports.js +93 -0
  87. package/dist/routes-runtime.d.ts +71 -0
  88. package/dist/routes-runtime.d.ts.map +1 -0
  89. package/dist/routes-runtime.js +59 -0
  90. package/dist/routes-settlement.d.ts +67 -0
  91. package/dist/routes-settlement.d.ts.map +1 -0
  92. package/dist/routes-settlement.js +23 -0
  93. package/dist/routes-shared.d.ts +35 -0
  94. package/dist/routes-shared.d.ts.map +1 -0
  95. package/dist/routes-shared.js +10 -0
  96. package/dist/routes-supplier-invoices.d.ts +778 -0
  97. package/dist/routes-supplier-invoices.d.ts.map +1 -0
  98. package/dist/routes-supplier-invoices.js +159 -0
  99. package/dist/routes-vouchers.d.ts +228 -0
  100. package/dist/routes-vouchers.d.ts.map +1 -0
  101. package/dist/routes-vouchers.js +54 -0
  102. package/dist/routes.d.ts +5577 -0
  103. package/dist/routes.d.ts.map +1 -0
  104. package/dist/routes.js +44 -0
  105. package/dist/schema/booking-billing.d.ts +1006 -0
  106. package/dist/schema/booking-billing.d.ts.map +1 -0
  107. package/dist/schema/booking-billing.js +106 -0
  108. package/dist/schema/enums.d.ts +48 -0
  109. package/dist/schema/enums.d.ts.map +1 -0
  110. package/dist/schema/enums.js +237 -0
  111. package/dist/schema/invoice-documents.d.ts +1245 -0
  112. package/dist/schema/invoice-documents.d.ts.map +1 -0
  113. package/dist/schema/invoice-documents.js +140 -0
  114. package/dist/schema/payment-instruments.d.ts +418 -0
  115. package/dist/schema/payment-instruments.d.ts.map +1 -0
  116. package/dist/schema/payment-instruments.js +45 -0
  117. package/dist/schema/payment-processing.d.ts +563 -0
  118. package/dist/schema/payment-processing.d.ts.map +1 -0
  119. package/dist/schema/payment-processing.js +65 -0
  120. package/dist/schema/payment-sessions.d.ts +728 -0
  121. package/dist/schema/payment-sessions.d.ts.map +1 -0
  122. package/dist/schema/payment-sessions.js +79 -0
  123. package/dist/schema/receivables.d.ts +1474 -0
  124. package/dist/schema/receivables.d.ts.map +1 -0
  125. package/dist/schema/receivables.js +179 -0
  126. package/dist/schema/relations.d.ts +82 -0
  127. package/dist/schema/relations.d.ts.map +1 -0
  128. package/dist/schema/relations.js +144 -0
  129. package/dist/schema/supplier-invoices.d.ts +1619 -0
  130. package/dist/schema/supplier-invoices.d.ts.map +1 -0
  131. package/dist/schema/supplier-invoices.js +228 -0
  132. package/dist/schema/tax.d.ts +712 -0
  133. package/dist/schema/tax.d.ts.map +1 -0
  134. package/dist/schema/tax.js +98 -0
  135. package/dist/schema/vouchers.d.ts +444 -0
  136. package/dist/schema/vouchers.d.ts.map +1 -0
  137. package/dist/schema/vouchers.js +64 -0
  138. package/dist/schema.d.ts +12 -0
  139. package/dist/schema.d.ts.map +1 -0
  140. package/dist/schema.js +11 -0
  141. package/dist/service-accountant-shares.d.ts +106 -0
  142. package/dist/service-accountant-shares.d.ts.map +1 -0
  143. package/dist/service-accountant-shares.js +331 -0
  144. package/dist/service-action-ledger-accounting.d.ts +104 -0
  145. package/dist/service-action-ledger-accounting.d.ts.map +1 -0
  146. package/dist/service-action-ledger-accounting.js +386 -0
  147. package/dist/service-action-ledger-booking-payments.d.ts +48 -0
  148. package/dist/service-action-ledger-booking-payments.d.ts.map +1 -0
  149. package/dist/service-action-ledger-booking-payments.js +178 -0
  150. package/dist/service-action-ledger-bookings.d.ts +44 -0
  151. package/dist/service-action-ledger-bookings.d.ts.map +1 -0
  152. package/dist/service-action-ledger-bookings.js +81 -0
  153. package/dist/service-action-ledger-payment-authorizations.d.ts +48 -0
  154. package/dist/service-action-ledger-payment-authorizations.d.ts.map +1 -0
  155. package/dist/service-action-ledger-payment-authorizations.js +209 -0
  156. package/dist/service-action-ledger-payment-sessions.d.ts +83 -0
  157. package/dist/service-action-ledger-payment-sessions.d.ts.map +1 -0
  158. package/dist/service-action-ledger-payment-sessions.js +294 -0
  159. package/dist/service-action-ledger-supplier-invoices.d.ts +27 -0
  160. package/dist/service-action-ledger-supplier-invoices.d.ts.map +1 -0
  161. package/dist/service-action-ledger-supplier-invoices.js +111 -0
  162. package/dist/service-action-ledger-supplier-payments.d.ts +21 -0
  163. package/dist/service-action-ledger-supplier-payments.d.ts.map +1 -0
  164. package/dist/service-action-ledger-supplier-payments.js +97 -0
  165. package/dist/service-action-ledger.d.ts +7 -0
  166. package/dist/service-action-ledger.d.ts.map +1 -0
  167. package/dist/service-action-ledger.js +6 -0
  168. package/dist/service-aggregates.d.ts +96 -0
  169. package/dist/service-aggregates.d.ts.map +1 -0
  170. package/dist/service-aggregates.js +294 -0
  171. package/dist/service-booking-billing.d.ts +2322 -0
  172. package/dist/service-booking-billing.d.ts.map +1 -0
  173. package/dist/service-booking-billing.js +8 -0
  174. package/dist/service-booking-create.d.ts +410 -0
  175. package/dist/service-booking-create.d.ts.map +1 -0
  176. package/dist/service-booking-create.js +1256 -0
  177. package/dist/service-booking-guarantees.d.ts +725 -0
  178. package/dist/service-booking-guarantees.d.ts.map +1 -0
  179. package/dist/service-booking-guarantees.js +153 -0
  180. package/dist/service-booking-item-billing.d.ts +1062 -0
  181. package/dist/service-booking-item-billing.d.ts.map +1 -0
  182. package/dist/service-booking-item-billing.js +77 -0
  183. package/dist/service-booking-payment-schedules.d.ts +557 -0
  184. package/dist/service-booking-payment-schedules.d.ts.map +1 -0
  185. package/dist/service-booking-payment-schedules.js +372 -0
  186. package/dist/service-bookings-dual-create.d.ts +308 -0
  187. package/dist/service-bookings-dual-create.d.ts.map +1 -0
  188. package/dist/service-bookings-dual-create.js +131 -0
  189. package/dist/service-boundary-sql.d.ts +6 -0
  190. package/dist/service-boundary-sql.d.ts.map +1 -0
  191. package/dist/service-boundary-sql.js +15 -0
  192. package/dist/service-cost-categories.d.ts +26 -0
  193. package/dist/service-cost-categories.d.ts.map +1 -0
  194. package/dist/service-cost-categories.js +76 -0
  195. package/dist/service-documents.d.ts +80 -0
  196. package/dist/service-documents.d.ts.map +1 -0
  197. package/dist/service-documents.js +228 -0
  198. package/dist/service-invoice-artifacts.d.ts +246 -0
  199. package/dist/service-invoice-artifacts.d.ts.map +1 -0
  200. package/dist/service-invoice-artifacts.js +277 -0
  201. package/dist/service-invoice-core.d.ts +405 -0
  202. package/dist/service-invoice-core.d.ts.map +1 -0
  203. package/dist/service-invoice-core.js +290 -0
  204. package/dist/service-invoice-credit-notes.d.ts +973 -0
  205. package/dist/service-invoice-credit-notes.d.ts.map +1 -0
  206. package/dist/service-invoice-credit-notes.js +142 -0
  207. package/dist/service-invoice-from-booking.d.ts +41 -0
  208. package/dist/service-invoice-from-booking.d.ts.map +1 -0
  209. package/dist/service-invoice-from-booking.js +267 -0
  210. package/dist/service-invoice-line-items.d.ts +432 -0
  211. package/dist/service-invoice-line-items.d.ts.map +1 -0
  212. package/dist/service-invoice-line-items.js +102 -0
  213. package/dist/service-invoice-numbering.d.ts +227 -0
  214. package/dist/service-invoice-numbering.d.ts.map +1 -0
  215. package/dist/service-invoice-numbering.js +260 -0
  216. package/dist/service-invoice-payments.d.ts +673 -0
  217. package/dist/service-invoice-payments.d.ts.map +1 -0
  218. package/dist/service-invoice-payments.js +398 -0
  219. package/dist/service-invoices.d.ts +2501 -0
  220. package/dist/service-invoices.d.ts.map +1 -0
  221. package/dist/service-invoices.js +12 -0
  222. package/dist/service-issue.d.ts +207 -0
  223. package/dist/service-issue.d.ts.map +1 -0
  224. package/dist/service-issue.js +431 -0
  225. package/dist/service-payment-authorizations.d.ts +164 -0
  226. package/dist/service-payment-authorizations.d.ts.map +1 -0
  227. package/dist/service-payment-authorizations.js +227 -0
  228. package/dist/service-payment-instruments.d.ts +116 -0
  229. package/dist/service-payment-instruments.d.ts.map +1 -0
  230. package/dist/service-payment-instruments.js +99 -0
  231. package/dist/service-payment-processing.d.ts +676 -0
  232. package/dist/service-payment-processing.d.ts.map +1 -0
  233. package/dist/service-payment-processing.js +10 -0
  234. package/dist/service-payment-session-completion.d.ts +48 -0
  235. package/dist/service-payment-session-completion.d.ts.map +1 -0
  236. package/dist/service-payment-session-completion.js +238 -0
  237. package/dist/service-payment-sessions.d.ts +361 -0
  238. package/dist/service-payment-sessions.d.ts.map +1 -0
  239. package/dist/service-payment-sessions.js +280 -0
  240. package/dist/service-profitability.d.ts +114 -0
  241. package/dist/service-profitability.d.ts.map +1 -0
  242. package/dist/service-profitability.js +794 -0
  243. package/dist/service-public.d.ts +553 -0
  244. package/dist/service-public.d.ts.map +1 -0
  245. package/dist/service-public.js +583 -0
  246. package/dist/service-reference-data.d.ts +272 -0
  247. package/dist/service-reference-data.d.ts.map +1 -0
  248. package/dist/service-reference-data.js +280 -0
  249. package/dist/service-rendition-wait.d.ts +38 -0
  250. package/dist/service-rendition-wait.d.ts.map +1 -0
  251. package/dist/service-rendition-wait.js +67 -0
  252. package/dist/service-reports.d.ts +37 -0
  253. package/dist/service-reports.d.ts.map +1 -0
  254. package/dist/service-reports.js +62 -0
  255. package/dist/service-settlement.d.ts +46 -0
  256. package/dist/service-settlement.d.ts.map +1 -0
  257. package/dist/service-settlement.js +185 -0
  258. package/dist/service-shared.d.ts +541 -0
  259. package/dist/service-shared.d.ts.map +1 -0
  260. package/dist/service-shared.js +764 -0
  261. package/dist/service-supplier-invoices.d.ts +871 -0
  262. package/dist/service-supplier-invoices.d.ts.map +1 -0
  263. package/dist/service-supplier-invoices.js +744 -0
  264. package/dist/service-supplier-payments.d.ts +69 -0
  265. package/dist/service-supplier-payments.d.ts.map +1 -0
  266. package/dist/service-supplier-payments.js +136 -0
  267. package/dist/service-vouchers-migration.d.ts +44 -0
  268. package/dist/service-vouchers-migration.d.ts.map +1 -0
  269. package/dist/service-vouchers-migration.js +148 -0
  270. package/dist/service-vouchers.d.ts +157 -0
  271. package/dist/service-vouchers.d.ts.map +1 -0
  272. package/dist/service-vouchers.js +191 -0
  273. package/dist/service.d.ts +6490 -0
  274. package/dist/service.d.ts.map +1 -0
  275. package/dist/service.js +29 -0
  276. package/dist/validation-billing.d.ts +2 -0
  277. package/dist/validation-billing.d.ts.map +1 -0
  278. package/dist/validation-billing.js +1 -0
  279. package/dist/validation-payments.d.ts +2 -0
  280. package/dist/validation-payments.d.ts.map +1 -0
  281. package/dist/validation-payments.js +1 -0
  282. package/dist/validation-public.d.ts +2 -0
  283. package/dist/validation-public.d.ts.map +1 -0
  284. package/dist/validation-public.js +1 -0
  285. package/dist/validation-shared.d.ts +2 -0
  286. package/dist/validation-shared.d.ts.map +1 -0
  287. package/dist/validation-shared.js +1 -0
  288. package/dist/validation-vouchers.d.ts +2 -0
  289. package/dist/validation-vouchers.d.ts.map +1 -0
  290. package/dist/validation-vouchers.js +1 -0
  291. package/dist/validation.d.ts +2 -0
  292. package/dist/validation.d.ts.map +1 -0
  293. package/dist/validation.js +1 -0
  294. package/package.json +121 -0
@@ -0,0 +1,405 @@
1
+ import type { CreateInvoiceInput, FinanceServiceRuntime, InvoiceListQuery, PostgresJsDatabase, UpdateInvoiceInput, VoidInvoiceInput } from "./service-shared.js";
2
+ export declare const financeInvoiceCoreService: {
3
+ listInvoices(db: PostgresJsDatabase, query: InvoiceListQuery): Promise<{
4
+ data: {
5
+ bookingPaymentScheduleIds: string[];
6
+ id: string;
7
+ invoiceNumber: string;
8
+ invoiceType: "invoice" | "proforma" | "credit_note";
9
+ convertedFromInvoiceId: string | null;
10
+ seriesId: string | null;
11
+ sequence: number | null;
12
+ templateId: string | null;
13
+ taxRegimeId: string | null;
14
+ language: string | null;
15
+ bookingId: string;
16
+ personId: string | null;
17
+ organizationId: string | null;
18
+ status: "void" | "paid" | "draft" | "pending_external_allocation" | "issued" | "partially_paid" | "overdue";
19
+ currency: string;
20
+ baseCurrency: string | null;
21
+ fxRateSetId: string | null;
22
+ subtotalCents: number;
23
+ baseSubtotalCents: number | null;
24
+ taxCents: number;
25
+ baseTaxCents: number | null;
26
+ totalCents: number;
27
+ baseTotalCents: number | null;
28
+ paidCents: number;
29
+ basePaidCents: number | null;
30
+ balanceDueCents: number;
31
+ baseBalanceDueCents: number | null;
32
+ commissionPercent: number | null;
33
+ commissionAmountCents: number | null;
34
+ issueDate: string;
35
+ dueDate: string;
36
+ notes: string | null;
37
+ voidedAt: Date | null;
38
+ voidReason: string | null;
39
+ createdAt: Date;
40
+ updatedAt: Date;
41
+ }[];
42
+ total: number;
43
+ limit: number;
44
+ offset: number;
45
+ }>;
46
+ createInvoice(db: PostgresJsDatabase, data: CreateInvoiceInput): Promise<{
47
+ subtotalCents: number;
48
+ currency: string;
49
+ id: string;
50
+ createdAt: Date;
51
+ updatedAt: Date;
52
+ taxRegimeId: string | null;
53
+ taxCents: number;
54
+ totalCents: number;
55
+ status: "void" | "paid" | "draft" | "pending_external_allocation" | "issued" | "partially_paid" | "overdue";
56
+ bookingId: string;
57
+ notes: string | null;
58
+ templateId: string | null;
59
+ dueDate: string;
60
+ invoiceNumber: string;
61
+ invoiceType: "invoice" | "proforma" | "credit_note";
62
+ convertedFromInvoiceId: string | null;
63
+ seriesId: string | null;
64
+ sequence: number | null;
65
+ language: string | null;
66
+ personId: string | null;
67
+ organizationId: string | null;
68
+ baseCurrency: string | null;
69
+ fxRateSetId: string | null;
70
+ baseSubtotalCents: number | null;
71
+ baseTaxCents: number | null;
72
+ baseTotalCents: number | null;
73
+ paidCents: number;
74
+ basePaidCents: number | null;
75
+ balanceDueCents: number;
76
+ baseBalanceDueCents: number | null;
77
+ commissionPercent: number | null;
78
+ commissionAmountCents: number | null;
79
+ issueDate: string;
80
+ voidedAt: Date | null;
81
+ voidReason: string | null;
82
+ } | undefined>;
83
+ getInvoiceById(db: PostgresJsDatabase, id: string): Promise<{
84
+ convertedToInvoiceId: string | null;
85
+ convertedToInvoiceNumber: string | null;
86
+ id: string;
87
+ invoiceNumber: string;
88
+ invoiceType: "invoice" | "proforma" | "credit_note";
89
+ convertedFromInvoiceId: string | null;
90
+ seriesId: string | null;
91
+ sequence: number | null;
92
+ templateId: string | null;
93
+ taxRegimeId: string | null;
94
+ language: string | null;
95
+ bookingId: string;
96
+ personId: string | null;
97
+ organizationId: string | null;
98
+ status: "void" | "paid" | "draft" | "pending_external_allocation" | "issued" | "partially_paid" | "overdue";
99
+ currency: string;
100
+ baseCurrency: string | null;
101
+ fxRateSetId: string | null;
102
+ subtotalCents: number;
103
+ baseSubtotalCents: number | null;
104
+ taxCents: number;
105
+ baseTaxCents: number | null;
106
+ totalCents: number;
107
+ baseTotalCents: number | null;
108
+ paidCents: number;
109
+ basePaidCents: number | null;
110
+ balanceDueCents: number;
111
+ baseBalanceDueCents: number | null;
112
+ commissionPercent: number | null;
113
+ commissionAmountCents: number | null;
114
+ issueDate: string;
115
+ dueDate: string;
116
+ notes: string | null;
117
+ voidedAt: Date | null;
118
+ voidReason: string | null;
119
+ createdAt: Date;
120
+ updatedAt: Date;
121
+ } | null>;
122
+ updateInvoice(db: PostgresJsDatabase, id: string, data: UpdateInvoiceInput, runtime?: FinanceServiceRuntime): Promise<{
123
+ id: string;
124
+ invoiceNumber: string;
125
+ invoiceType: "invoice" | "proforma" | "credit_note";
126
+ convertedFromInvoiceId: string | null;
127
+ seriesId: string | null;
128
+ sequence: number | null;
129
+ templateId: string | null;
130
+ taxRegimeId: string | null;
131
+ language: string | null;
132
+ bookingId: string;
133
+ personId: string | null;
134
+ organizationId: string | null;
135
+ status: "void" | "paid" | "draft" | "pending_external_allocation" | "issued" | "partially_paid" | "overdue";
136
+ currency: string;
137
+ baseCurrency: string | null;
138
+ fxRateSetId: string | null;
139
+ subtotalCents: number;
140
+ baseSubtotalCents: number | null;
141
+ taxCents: number;
142
+ baseTaxCents: number | null;
143
+ totalCents: number;
144
+ baseTotalCents: number | null;
145
+ paidCents: number;
146
+ basePaidCents: number | null;
147
+ balanceDueCents: number;
148
+ baseBalanceDueCents: number | null;
149
+ commissionPercent: number | null;
150
+ commissionAmountCents: number | null;
151
+ issueDate: string;
152
+ dueDate: string;
153
+ notes: string | null;
154
+ voidedAt: Date | null;
155
+ voidReason: string | null;
156
+ createdAt: Date;
157
+ updatedAt: Date;
158
+ } | null>;
159
+ deleteInvoice(db: PostgresJsDatabase, id: string, runtime?: FinanceServiceRuntime): Promise<{
160
+ status: "not_found";
161
+ } | {
162
+ status: "not_draft";
163
+ } | {
164
+ status: "deleted";
165
+ }>;
166
+ voidInvoice(db: PostgresJsDatabase, id: string, input?: VoidInvoiceInput, runtime?: FinanceServiceRuntime): Promise<{
167
+ status: "not_found";
168
+ invoice?: undefined;
169
+ } | {
170
+ status: "already_void";
171
+ invoice: {
172
+ id: string;
173
+ invoiceNumber: string;
174
+ invoiceType: "invoice" | "proforma" | "credit_note";
175
+ convertedFromInvoiceId: string | null;
176
+ seriesId: string | null;
177
+ sequence: number | null;
178
+ templateId: string | null;
179
+ taxRegimeId: string | null;
180
+ language: string | null;
181
+ bookingId: string;
182
+ personId: string | null;
183
+ organizationId: string | null;
184
+ status: "void" | "paid" | "draft" | "pending_external_allocation" | "issued" | "partially_paid" | "overdue";
185
+ currency: string;
186
+ baseCurrency: string | null;
187
+ fxRateSetId: string | null;
188
+ subtotalCents: number;
189
+ baseSubtotalCents: number | null;
190
+ taxCents: number;
191
+ baseTaxCents: number | null;
192
+ totalCents: number;
193
+ baseTotalCents: number | null;
194
+ paidCents: number;
195
+ basePaidCents: number | null;
196
+ balanceDueCents: number;
197
+ baseBalanceDueCents: number | null;
198
+ commissionPercent: number | null;
199
+ commissionAmountCents: number | null;
200
+ issueDate: string;
201
+ dueDate: string;
202
+ notes: string | null;
203
+ voidedAt: Date | null;
204
+ voidReason: string | null;
205
+ createdAt: Date;
206
+ updatedAt: Date;
207
+ };
208
+ } | {
209
+ status: "draft";
210
+ invoice: {
211
+ id: string;
212
+ invoiceNumber: string;
213
+ invoiceType: "invoice" | "proforma" | "credit_note";
214
+ convertedFromInvoiceId: string | null;
215
+ seriesId: string | null;
216
+ sequence: number | null;
217
+ templateId: string | null;
218
+ taxRegimeId: string | null;
219
+ language: string | null;
220
+ bookingId: string;
221
+ personId: string | null;
222
+ organizationId: string | null;
223
+ status: "void" | "paid" | "draft" | "pending_external_allocation" | "issued" | "partially_paid" | "overdue";
224
+ currency: string;
225
+ baseCurrency: string | null;
226
+ fxRateSetId: string | null;
227
+ subtotalCents: number;
228
+ baseSubtotalCents: number | null;
229
+ taxCents: number;
230
+ baseTaxCents: number | null;
231
+ totalCents: number;
232
+ baseTotalCents: number | null;
233
+ paidCents: number;
234
+ basePaidCents: number | null;
235
+ balanceDueCents: number;
236
+ baseBalanceDueCents: number | null;
237
+ commissionPercent: number | null;
238
+ commissionAmountCents: number | null;
239
+ issueDate: string;
240
+ dueDate: string;
241
+ notes: string | null;
242
+ voidedAt: Date | null;
243
+ voidReason: string | null;
244
+ createdAt: Date;
245
+ updatedAt: Date;
246
+ };
247
+ } | {
248
+ status: "invalid_status";
249
+ invoice: {
250
+ id: string;
251
+ invoiceNumber: string;
252
+ invoiceType: "invoice" | "proforma" | "credit_note";
253
+ convertedFromInvoiceId: string | null;
254
+ seriesId: string | null;
255
+ sequence: number | null;
256
+ templateId: string | null;
257
+ taxRegimeId: string | null;
258
+ language: string | null;
259
+ bookingId: string;
260
+ personId: string | null;
261
+ organizationId: string | null;
262
+ status: "void" | "paid" | "draft" | "pending_external_allocation" | "issued" | "partially_paid" | "overdue";
263
+ currency: string;
264
+ baseCurrency: string | null;
265
+ fxRateSetId: string | null;
266
+ subtotalCents: number;
267
+ baseSubtotalCents: number | null;
268
+ taxCents: number;
269
+ baseTaxCents: number | null;
270
+ totalCents: number;
271
+ baseTotalCents: number | null;
272
+ paidCents: number;
273
+ basePaidCents: number | null;
274
+ balanceDueCents: number;
275
+ baseBalanceDueCents: number | null;
276
+ commissionPercent: number | null;
277
+ commissionAmountCents: number | null;
278
+ issueDate: string;
279
+ dueDate: string;
280
+ notes: string | null;
281
+ voidedAt: Date | null;
282
+ voidReason: string | null;
283
+ createdAt: Date;
284
+ updatedAt: Date;
285
+ };
286
+ } | {
287
+ status: "has_payments";
288
+ invoice: {
289
+ id: string;
290
+ invoiceNumber: string;
291
+ invoiceType: "invoice" | "proforma" | "credit_note";
292
+ convertedFromInvoiceId: string | null;
293
+ seriesId: string | null;
294
+ sequence: number | null;
295
+ templateId: string | null;
296
+ taxRegimeId: string | null;
297
+ language: string | null;
298
+ bookingId: string;
299
+ personId: string | null;
300
+ organizationId: string | null;
301
+ status: "void" | "paid" | "draft" | "pending_external_allocation" | "issued" | "partially_paid" | "overdue";
302
+ currency: string;
303
+ baseCurrency: string | null;
304
+ fxRateSetId: string | null;
305
+ subtotalCents: number;
306
+ baseSubtotalCents: number | null;
307
+ taxCents: number;
308
+ baseTaxCents: number | null;
309
+ totalCents: number;
310
+ baseTotalCents: number | null;
311
+ paidCents: number;
312
+ basePaidCents: number | null;
313
+ balanceDueCents: number;
314
+ baseBalanceDueCents: number | null;
315
+ commissionPercent: number | null;
316
+ commissionAmountCents: number | null;
317
+ issueDate: string;
318
+ dueDate: string;
319
+ notes: string | null;
320
+ voidedAt: Date | null;
321
+ voidReason: string | null;
322
+ createdAt: Date;
323
+ updatedAt: Date;
324
+ };
325
+ } | {
326
+ status: "has_credit_notes";
327
+ invoice: {
328
+ id: string;
329
+ invoiceNumber: string;
330
+ invoiceType: "invoice" | "proforma" | "credit_note";
331
+ convertedFromInvoiceId: string | null;
332
+ seriesId: string | null;
333
+ sequence: number | null;
334
+ templateId: string | null;
335
+ taxRegimeId: string | null;
336
+ language: string | null;
337
+ bookingId: string;
338
+ personId: string | null;
339
+ organizationId: string | null;
340
+ status: "void" | "paid" | "draft" | "pending_external_allocation" | "issued" | "partially_paid" | "overdue";
341
+ currency: string;
342
+ baseCurrency: string | null;
343
+ fxRateSetId: string | null;
344
+ subtotalCents: number;
345
+ baseSubtotalCents: number | null;
346
+ taxCents: number;
347
+ baseTaxCents: number | null;
348
+ totalCents: number;
349
+ baseTotalCents: number | null;
350
+ paidCents: number;
351
+ basePaidCents: number | null;
352
+ balanceDueCents: number;
353
+ baseBalanceDueCents: number | null;
354
+ commissionPercent: number | null;
355
+ commissionAmountCents: number | null;
356
+ issueDate: string;
357
+ dueDate: string;
358
+ notes: string | null;
359
+ voidedAt: Date | null;
360
+ voidReason: string | null;
361
+ createdAt: Date;
362
+ updatedAt: Date;
363
+ };
364
+ } | {
365
+ status: "voided";
366
+ invoice: {
367
+ id: string;
368
+ invoiceNumber: string;
369
+ invoiceType: "invoice" | "proforma" | "credit_note";
370
+ convertedFromInvoiceId: string | null;
371
+ seriesId: string | null;
372
+ sequence: number | null;
373
+ templateId: string | null;
374
+ taxRegimeId: string | null;
375
+ language: string | null;
376
+ bookingId: string;
377
+ personId: string | null;
378
+ organizationId: string | null;
379
+ status: "void" | "paid" | "draft" | "pending_external_allocation" | "issued" | "partially_paid" | "overdue";
380
+ currency: string;
381
+ baseCurrency: string | null;
382
+ fxRateSetId: string | null;
383
+ subtotalCents: number;
384
+ baseSubtotalCents: number | null;
385
+ taxCents: number;
386
+ baseTaxCents: number | null;
387
+ totalCents: number;
388
+ baseTotalCents: number | null;
389
+ paidCents: number;
390
+ basePaidCents: number | null;
391
+ balanceDueCents: number;
392
+ baseBalanceDueCents: number | null;
393
+ commissionPercent: number | null;
394
+ commissionAmountCents: number | null;
395
+ issueDate: string;
396
+ dueDate: string;
397
+ notes: string | null;
398
+ voidedAt: Date | null;
399
+ voidReason: string | null;
400
+ createdAt: Date;
401
+ updatedAt: Date;
402
+ };
403
+ }>;
404
+ };
405
+ //# sourceMappingURL=service-invoice-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-invoice-core.d.ts","sourceRoot":"","sources":["../src/service-invoice-core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAEhB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,qBAAqB,CAAA;AA4B5B,eAAO,MAAM,yBAAyB;qBACb,kBAAkB,SAAS,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAmH1C,kBAAkB,QAAQ,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAI3C,kBAAkB,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAqBjD,kBAAkB,MAClB,MAAM,QACJ,kBAAkB,YACf,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAwCR,kBAAkB,MAAM,MAAM,YAAW,qBAAqB;;;;;;;oBA8ChF,kBAAkB,MAClB,MAAM,UACH,gBAAgB,YACd,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0IjC,CAAA"}
@@ -0,0 +1,290 @@
1
+ import { and, appendActionLedgerMutation, asc, buildInvoiceDeleteActionLedgerInput, buildInvoiceUpdateActionLedgerInput, creditNotes, desc, eq, gte, InvoiceNumberConflictError, ilike, inArray, invoiceExternalRefs, invoiceLineItems, invoiceNumberSeries, invoices, isInvoiceNumberUniqueConstraintError, isNotNull, lte, ne, or, payments, readStringMetadata, sql, } from "./service-shared.js";
2
+ export const financeInvoiceCoreService = {
3
+ async listInvoices(db, query) {
4
+ const conditions = [];
5
+ if (query.status) {
6
+ conditions.push(eq(invoices.status, query.status));
7
+ }
8
+ if (query.bookingId) {
9
+ conditions.push(eq(invoices.bookingId, query.bookingId));
10
+ }
11
+ if (query.personId) {
12
+ conditions.push(eq(invoices.personId, query.personId));
13
+ }
14
+ if (query.organizationId) {
15
+ conditions.push(eq(invoices.organizationId, query.organizationId));
16
+ }
17
+ if (query.currency) {
18
+ conditions.push(eq(invoices.currency, query.currency));
19
+ }
20
+ if (query.dueDateFrom) {
21
+ conditions.push(gte(invoices.dueDate, query.dueDateFrom));
22
+ }
23
+ if (query.dueDateTo) {
24
+ conditions.push(lte(invoices.dueDate, query.dueDateTo));
25
+ }
26
+ if (query.search) {
27
+ const term = `%${query.search}%`;
28
+ conditions.push(or(ilike(invoices.invoiceNumber, term), ilike(invoices.notes, term)));
29
+ }
30
+ const where = conditions.length > 0 ? and(...conditions) : undefined;
31
+ const sortColumn = (() => {
32
+ switch (query.sortBy) {
33
+ case "invoiceNumber":
34
+ return invoices.invoiceNumber;
35
+ case "status":
36
+ return invoices.status;
37
+ case "totalCents":
38
+ return invoices.totalCents;
39
+ case "paidCents":
40
+ return invoices.paidCents;
41
+ case "balanceDueCents":
42
+ return invoices.balanceDueCents;
43
+ case "issueDate":
44
+ return invoices.issueDate;
45
+ case "dueDate":
46
+ return invoices.dueDate;
47
+ default:
48
+ return invoices.createdAt;
49
+ }
50
+ })();
51
+ const sortFn = query.sortDir === "asc" ? asc : desc;
52
+ const [rows, countResult] = await Promise.all([
53
+ db
54
+ .select()
55
+ .from(invoices)
56
+ .where(where)
57
+ .limit(query.limit)
58
+ .offset(query.offset)
59
+ .orderBy(sortFn(sortColumn), desc(invoices.createdAt)),
60
+ db.select({ count: sql `count(*)::int` }).from(invoices).where(where),
61
+ ]);
62
+ // For each returned invoice, surface the distinct
63
+ // `bookingPaymentScheduleId`s referenced by its line items so the
64
+ // booking-detail payment-schedule table can link rows to invoices
65
+ // without a second roundtrip. Returns `[]` when an invoice covers
66
+ // booking items directly (no schedule link).
67
+ const invoiceIds = rows.map((row) => row.id);
68
+ const scheduleLinks = invoiceIds.length
69
+ ? await db
70
+ .select({
71
+ invoiceId: invoiceLineItems.invoiceId,
72
+ bookingPaymentScheduleId: invoiceLineItems.bookingPaymentScheduleId,
73
+ })
74
+ .from(invoiceLineItems)
75
+ .where(and(inArray(invoiceLineItems.invoiceId, invoiceIds), isNotNull(invoiceLineItems.bookingPaymentScheduleId)))
76
+ : [];
77
+ const scheduleIdsByInvoice = new Map();
78
+ for (const link of scheduleLinks) {
79
+ const scheduleId = link.bookingPaymentScheduleId;
80
+ if (!scheduleId)
81
+ continue;
82
+ const existing = scheduleIdsByInvoice.get(link.invoiceId);
83
+ if (!existing) {
84
+ scheduleIdsByInvoice.set(link.invoiceId, [scheduleId]);
85
+ }
86
+ else if (!existing.includes(scheduleId)) {
87
+ existing.push(scheduleId);
88
+ }
89
+ }
90
+ const data = rows.map((row) => ({
91
+ ...row,
92
+ bookingPaymentScheduleIds: scheduleIdsByInvoice.get(row.id) ?? [],
93
+ }));
94
+ return {
95
+ data,
96
+ total: countResult[0]?.count ?? 0,
97
+ limit: query.limit,
98
+ offset: query.offset,
99
+ };
100
+ },
101
+ async createInvoice(db, data) {
102
+ const [row] = await db.insert(invoices).values(data).returning();
103
+ return row;
104
+ },
105
+ async getInvoiceById(db, id) {
106
+ const [row] = await db.select().from(invoices).where(eq(invoices.id, id)).limit(1);
107
+ if (!row)
108
+ return null;
109
+ // Surface the proforma → final-invoice link so the UI can show
110
+ // "Invoiced" instead of "Void" for proformas that were converted.
111
+ // The reverse direction (`convertedFromInvoiceId`) already lives on
112
+ // the row; this looks up the inverse via the unique
113
+ // `idx_invoices_converted_from` index.
114
+ const [convertedTo] = await db
115
+ .select({ id: invoices.id, invoiceNumber: invoices.invoiceNumber })
116
+ .from(invoices)
117
+ .where(and(eq(invoices.convertedFromInvoiceId, id), ne(invoices.status, "void")))
118
+ .limit(1);
119
+ return {
120
+ ...row,
121
+ convertedToInvoiceId: convertedTo?.id ?? null,
122
+ convertedToInvoiceNumber: convertedTo?.invoiceNumber ?? null,
123
+ };
124
+ },
125
+ async updateInvoice(db, id, data, runtime = {}) {
126
+ const updateInvoiceRow = (writer) => writer
127
+ .update(invoices)
128
+ .set({ ...data, updatedAt: new Date() })
129
+ .where(eq(invoices.id, id))
130
+ .returning();
131
+ try {
132
+ const actionLedgerContext = runtime.actionLedgerContext;
133
+ if (actionLedgerContext) {
134
+ return await db.transaction(async (tx) => {
135
+ const [row] = await updateInvoiceRow(tx);
136
+ if (row) {
137
+ await appendActionLedgerMutation(tx, buildInvoiceUpdateActionLedgerInput(actionLedgerContext, { invoice: row, changes: data }, { authorizationSource: runtime.actionLedgerAuthorizationSource }));
138
+ }
139
+ return row ?? null;
140
+ });
141
+ }
142
+ const [row] = await updateInvoiceRow(db);
143
+ return row ?? null;
144
+ }
145
+ catch (error) {
146
+ if (data.invoiceNumber && isInvoiceNumberUniqueConstraintError(error)) {
147
+ throw new InvoiceNumberConflictError(data.invoiceNumber);
148
+ }
149
+ throw error;
150
+ }
151
+ },
152
+ async deleteInvoice(db, id, runtime = {}) {
153
+ const actionLedgerContext = runtime.actionLedgerContext;
154
+ if (actionLedgerContext) {
155
+ return db.transaction(async (tx) => {
156
+ const [existing] = await tx.select().from(invoices).where(eq(invoices.id, id)).limit(1);
157
+ if (!existing) {
158
+ return { status: "not_found" };
159
+ }
160
+ if (existing.status !== "draft") {
161
+ return { status: "not_draft" };
162
+ }
163
+ await tx.delete(invoices).where(eq(invoices.id, id));
164
+ await appendActionLedgerMutation(tx, buildInvoiceDeleteActionLedgerInput(actionLedgerContext, { invoice: existing }, { authorizationSource: runtime.actionLedgerAuthorizationSource }));
165
+ return { status: "deleted" };
166
+ });
167
+ }
168
+ const [existing] = await db
169
+ .select({ id: invoices.id, status: invoices.status })
170
+ .from(invoices)
171
+ .where(eq(invoices.id, id))
172
+ .limit(1);
173
+ if (!existing) {
174
+ return { status: "not_found" };
175
+ }
176
+ if (existing.status !== "draft") {
177
+ return { status: "not_draft" };
178
+ }
179
+ await db.delete(invoices).where(eq(invoices.id, id));
180
+ return { status: "deleted" };
181
+ },
182
+ async voidInvoice(db, id, input = {}, runtime = {}) {
183
+ const reason = input.reason?.trim() || null;
184
+ const voidedAt = new Date();
185
+ const result = await db.transaction(async (tx) => {
186
+ const [existing] = await tx.select().from(invoices).where(eq(invoices.id, id)).limit(1);
187
+ if (!existing) {
188
+ return { status: "not_found" };
189
+ }
190
+ if (existing.status === "void") {
191
+ return { status: "already_void", invoice: existing };
192
+ }
193
+ if (existing.status === "draft") {
194
+ return { status: "draft", invoice: existing };
195
+ }
196
+ const voidableStatuses = new Set([
197
+ "pending_external_allocation",
198
+ "issued",
199
+ "partially_paid",
200
+ "overdue",
201
+ ]);
202
+ if (!voidableStatuses.has(existing.status)) {
203
+ return { status: "invalid_status", invoice: existing };
204
+ }
205
+ const [payment] = await tx
206
+ .select({ id: payments.id })
207
+ .from(payments)
208
+ .where(eq(payments.invoiceId, id))
209
+ .limit(1);
210
+ if (payment) {
211
+ return { status: "has_payments", invoice: existing };
212
+ }
213
+ const [creditNote] = await tx
214
+ .select({ id: creditNotes.id })
215
+ .from(creditNotes)
216
+ .where(eq(creditNotes.invoiceId, id))
217
+ .limit(1);
218
+ if (creditNote) {
219
+ return { status: "has_credit_notes", invoice: existing };
220
+ }
221
+ const changes = {
222
+ status: "void",
223
+ voidedAt,
224
+ voidReason: reason,
225
+ balanceDueCents: 0,
226
+ baseBalanceDueCents: existing.baseBalanceDueCents == null ? null : 0,
227
+ updatedAt: voidedAt,
228
+ };
229
+ const actionLedgerChanges = {
230
+ status: "void",
231
+ balanceDueCents: changes.balanceDueCents,
232
+ baseBalanceDueCents: changes.baseBalanceDueCents,
233
+ };
234
+ const [invoice] = await tx
235
+ .update(invoices)
236
+ .set(changes)
237
+ .where(eq(invoices.id, id))
238
+ .returning();
239
+ if (!invoice) {
240
+ return { status: "not_found" };
241
+ }
242
+ const actionLedgerContext = runtime.actionLedgerContext;
243
+ if (actionLedgerContext) {
244
+ await appendActionLedgerMutation(tx, buildInvoiceUpdateActionLedgerInput(actionLedgerContext, { invoice, changes: actionLedgerChanges }, { authorizationSource: runtime.actionLedgerAuthorizationSource }));
245
+ }
246
+ return { status: "voided", invoice };
247
+ });
248
+ if (result.status === "voided" && runtime.eventBus) {
249
+ const [smartbillRef] = await db
250
+ .select()
251
+ .from(invoiceExternalRefs)
252
+ .where(and(eq(invoiceExternalRefs.invoiceId, result.invoice.id), eq(invoiceExternalRefs.provider, "smartbill")))
253
+ .orderBy(desc(invoiceExternalRefs.createdAt))
254
+ .limit(1);
255
+ const [externalRef] = smartbillRef
256
+ ? [smartbillRef]
257
+ : await db
258
+ .select()
259
+ .from(invoiceExternalRefs)
260
+ .where(eq(invoiceExternalRefs.invoiceId, result.invoice.id))
261
+ .orderBy(desc(invoiceExternalRefs.createdAt))
262
+ .limit(1);
263
+ const [series] = result.invoice.seriesId
264
+ ? await db
265
+ .select({ name: invoiceNumberSeries.name })
266
+ .from(invoiceNumberSeries)
267
+ .where(eq(invoiceNumberSeries.id, result.invoice.seriesId))
268
+ .limit(1)
269
+ : [];
270
+ const event = {
271
+ invoiceId: result.invoice.id,
272
+ invoiceNumber: result.invoice.invoiceNumber,
273
+ invoiceType: result.invoice.invoiceType,
274
+ bookingId: result.invoice.bookingId,
275
+ totalCents: result.invoice.totalCents,
276
+ currency: result.invoice.currency,
277
+ reason,
278
+ voidedAt: result.invoice.voidedAt?.toISOString() ?? voidedAt.toISOString(),
279
+ externalProvider: externalRef?.provider ?? null,
280
+ externalNumber: externalRef?.externalNumber ?? null,
281
+ externalSeriesName: readStringMetadata(externalRef?.metadata, "seriesName") ??
282
+ readStringMetadata(externalRef?.metadata, "series") ??
283
+ series?.name ??
284
+ null,
285
+ };
286
+ await runtime.eventBus.emit("invoice.voided", event);
287
+ }
288
+ return result;
289
+ },
290
+ };