@voyantjs/finance 0.38.0 → 0.39.0
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/dist/service-issue.d.ts +21 -0
- package/dist/service-issue.d.ts.map +1 -1
- package/dist/service-issue.js +46 -5
- package/package.json +7 -7
package/dist/service-issue.d.ts
CHANGED
|
@@ -22,6 +22,27 @@ export interface InvoiceIssuedEvent {
|
|
|
22
22
|
currency: string;
|
|
23
23
|
/** Linkage when this invoice replaced a proforma. */
|
|
24
24
|
convertedFromInvoiceId?: string | null;
|
|
25
|
+
clientName?: string;
|
|
26
|
+
clientEmail?: string | null;
|
|
27
|
+
clientPhone?: string | null;
|
|
28
|
+
clientAddress?: string | null;
|
|
29
|
+
clientCity?: string | null;
|
|
30
|
+
clientCounty?: string | null;
|
|
31
|
+
clientCountry?: string | null;
|
|
32
|
+
clientVatCode?: string | null;
|
|
33
|
+
clientRegCom?: string | null;
|
|
34
|
+
lineItems?: InvoiceIssuedLineItem[];
|
|
35
|
+
bookingNumber?: string | null;
|
|
36
|
+
issueDate?: string;
|
|
37
|
+
dueDate?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface InvoiceIssuedLineItem {
|
|
40
|
+
description: string;
|
|
41
|
+
quantity: number;
|
|
42
|
+
unitPrice: number;
|
|
43
|
+
currency: string;
|
|
44
|
+
taxPercentage?: number;
|
|
45
|
+
isService?: boolean;
|
|
25
46
|
}
|
|
26
47
|
/**
|
|
27
48
|
* Create + emit an invoice from a booking. Returns the persisted row
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-issue.d.ts","sourceRoot":"","sources":["../src/service-issue.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service-issue.d.ts","sourceRoot":"","sources":["../src/service-issue.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE9C,OAAO,KAAK,EAAE,kBAAkB,EAAE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EAAE,MAAM,CAAA;IAChB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAKD;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,6BAA6B,EACpC,WAAW,EAAE,sBAAsB,EACnC,OAAO,GAAE,mBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAclC;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,6BAA6B,EACpC,WAAW,EAAE,sBAAsB,EACnC,OAAO,GAAE,mBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAclC"}
|
package/dist/service-issue.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { bookings } from "@voyantjs/bookings/schema";
|
|
2
|
+
import { asc, eq } from "drizzle-orm";
|
|
3
|
+
import { invoiceLineItems, invoices } from "./schema.js";
|
|
3
4
|
import { financeService, } from "./service.js";
|
|
4
5
|
const ISSUED_EVENT = "invoice.issued";
|
|
5
6
|
const PROFORMA_ISSUED_EVENT = "invoice.proforma.issued";
|
|
@@ -19,7 +20,7 @@ export async function issueInvoiceFromBooking(db, input, bookingData, runtime =
|
|
|
19
20
|
.where(eq(invoices.id, draft.id))
|
|
20
21
|
.returning();
|
|
21
22
|
const row = issued ?? draft;
|
|
22
|
-
await emitIssued(runtime, ISSUED_EVENT, row);
|
|
23
|
+
await emitIssued(db, runtime, ISSUED_EVENT, row);
|
|
23
24
|
return row;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
@@ -38,12 +39,20 @@ export async function issueProformaFromBooking(db, input, bookingData, runtime =
|
|
|
38
39
|
.where(eq(invoices.id, draft.id))
|
|
39
40
|
.returning();
|
|
40
41
|
const row = issued ?? draft;
|
|
41
|
-
await emitIssued(runtime, PROFORMA_ISSUED_EVENT, row);
|
|
42
|
+
await emitIssued(db, runtime, PROFORMA_ISSUED_EVENT, row);
|
|
42
43
|
return row;
|
|
43
44
|
}
|
|
44
|
-
async function emitIssued(runtime, eventName, invoice) {
|
|
45
|
+
async function emitIssued(db, runtime, eventName, invoice) {
|
|
45
46
|
if (!runtime.eventBus)
|
|
46
47
|
return;
|
|
48
|
+
const [booking] = invoice.bookingId
|
|
49
|
+
? await db.select().from(bookings).where(eq(bookings.id, invoice.bookingId)).limit(1)
|
|
50
|
+
: [];
|
|
51
|
+
const lines = await db
|
|
52
|
+
.select()
|
|
53
|
+
.from(invoiceLineItems)
|
|
54
|
+
.where(eq(invoiceLineItems.invoiceId, invoice.id))
|
|
55
|
+
.orderBy(asc(invoiceLineItems.sortOrder));
|
|
47
56
|
const payload = {
|
|
48
57
|
invoiceId: invoice.id,
|
|
49
58
|
invoiceNumber: invoice.invoiceNumber,
|
|
@@ -52,6 +61,38 @@ async function emitIssued(runtime, eventName, invoice) {
|
|
|
52
61
|
totalCents: invoice.totalCents,
|
|
53
62
|
currency: invoice.currency,
|
|
54
63
|
convertedFromInvoiceId: invoice.convertedFromInvoiceId,
|
|
64
|
+
clientName: buildClientName(booking),
|
|
65
|
+
clientEmail: booking?.contactEmail ?? null,
|
|
66
|
+
clientPhone: booking?.contactPhone ?? null,
|
|
67
|
+
clientAddress: booking?.contactAddressLine1 ?? null,
|
|
68
|
+
clientCity: booking?.contactCity ?? null,
|
|
69
|
+
clientCounty: booking?.contactRegion ?? null,
|
|
70
|
+
clientCountry: booking?.contactCountry ?? null,
|
|
71
|
+
clientVatCode: null,
|
|
72
|
+
clientRegCom: null,
|
|
73
|
+
lineItems: lines.map((line) => ({
|
|
74
|
+
description: line.description,
|
|
75
|
+
quantity: line.quantity,
|
|
76
|
+
unitPrice: centsToMajor(line.unitPriceCents),
|
|
77
|
+
currency: invoice.currency,
|
|
78
|
+
...(line.taxRate == null ? {} : { taxPercentage: line.taxRate }),
|
|
79
|
+
isService: true,
|
|
80
|
+
})),
|
|
81
|
+
bookingNumber: booking?.bookingNumber ?? null,
|
|
82
|
+
issueDate: toDateString(invoice.issueDate),
|
|
83
|
+
dueDate: toDateString(invoice.dueDate),
|
|
55
84
|
};
|
|
56
85
|
await runtime.eventBus.emit(eventName, payload);
|
|
57
86
|
}
|
|
87
|
+
function buildClientName(booking) {
|
|
88
|
+
const name = [booking?.contactFirstName, booking?.contactLastName]
|
|
89
|
+
.filter((part) => typeof part === "string" && part.length > 0)
|
|
90
|
+
.join(" ");
|
|
91
|
+
return name || "Client";
|
|
92
|
+
}
|
|
93
|
+
function centsToMajor(cents) {
|
|
94
|
+
return cents / 100;
|
|
95
|
+
}
|
|
96
|
+
function toDateString(value) {
|
|
97
|
+
return typeof value === "string" ? value : value.toISOString().slice(0, 10);
|
|
98
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voyantjs/finance",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"drizzle-orm": "^0.45.2",
|
|
40
40
|
"hono": "^4.12.10",
|
|
41
41
|
"zod": "^4.3.6",
|
|
42
|
-
"@voyantjs/bookings": "0.
|
|
43
|
-
"@voyantjs/core": "0.
|
|
44
|
-
"@voyantjs/db": "0.
|
|
45
|
-
"@voyantjs/hono": "0.
|
|
46
|
-
"@voyantjs/utils": "0.
|
|
47
|
-
"@voyantjs/storage": "0.
|
|
42
|
+
"@voyantjs/bookings": "0.39.0",
|
|
43
|
+
"@voyantjs/core": "0.39.0",
|
|
44
|
+
"@voyantjs/db": "0.39.0",
|
|
45
|
+
"@voyantjs/hono": "0.39.0",
|
|
46
|
+
"@voyantjs/utils": "0.39.0",
|
|
47
|
+
"@voyantjs/storage": "0.39.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"typescript": "^6.0.2",
|