ztechno_core 0.0.129 → 0.0.131
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.
|
@@ -14,6 +14,8 @@ export declare class InvoicesOrm extends ZOrm {
|
|
|
14
14
|
findAll(): Promise<ZInvoice[]>;
|
|
15
15
|
findLastByYear(year: number): Promise<ZInvoice | undefined>;
|
|
16
16
|
updateStatus(id: number, status: ZInvoiceStatus, amount_paid?: number, paid_at?: string | null): Promise<void>;
|
|
17
|
+
/** Transitions status only if the current DB status matches `fromStatus`. Safe against concurrent updates. */
|
|
18
|
+
updateStatusConditional(id: number, status: ZInvoiceStatus, fromStatus: ZInvoiceStatus): Promise<void>;
|
|
17
19
|
updatePaymentRef(
|
|
18
20
|
id: number,
|
|
19
21
|
payload: {
|
|
@@ -89,6 +89,17 @@ class InvoicesOrm extends orm_1.ZOrm {
|
|
|
89
89
|
{ id, status, amount_paid: amount_paid ?? null, paid_at: paid_at ?? null },
|
|
90
90
|
);
|
|
91
91
|
}
|
|
92
|
+
/** Transitions status only if the current DB status matches `fromStatus`. Safe against concurrent updates. */
|
|
93
|
+
async updateStatusConditional(id, status, fromStatus) {
|
|
94
|
+
await this.sqlService.query(
|
|
95
|
+
/*SQL*/ `
|
|
96
|
+
UPDATE \`${this.alias}\`
|
|
97
|
+
SET status=:status, updated_at=NOW()
|
|
98
|
+
WHERE id=:id AND status=:fromStatus
|
|
99
|
+
`,
|
|
100
|
+
{ id, status, fromStatus },
|
|
101
|
+
);
|
|
102
|
+
}
|
|
92
103
|
async updatePaymentRef(id, payload) {
|
|
93
104
|
await this.sqlService.query(
|
|
94
105
|
/*SQL*/ `
|
|
@@ -99,12 +99,6 @@ export declare class InvoiceService {
|
|
|
99
99
|
template: Partial<Omit<ZInvoiceItemTemplate, 'id' | 'created_at' | 'updated_at'>>,
|
|
100
100
|
): Promise<ZInvoiceItemTemplate>;
|
|
101
101
|
deleteItemTemplate(id: number): Promise<void>;
|
|
102
|
-
createInvoiceWithPayment(input: CreateInvoiceInput): Promise<{
|
|
103
|
-
invoice: ZInvoice;
|
|
104
|
-
checkoutUrl: string;
|
|
105
|
-
payment: import('@mollie/api-client/dist/types/data/payments/Payment').default;
|
|
106
|
-
payUrl: string;
|
|
107
|
-
}>;
|
|
108
102
|
createInvoiceFromItems(
|
|
109
103
|
input: CreateInvoiceInput,
|
|
110
104
|
overrides?: CreateInvoiceOverrides,
|
|
@@ -502,6 +502,7 @@ class InvoiceService {
|
|
|
502
502
|
async deleteItemTemplate(id) {
|
|
503
503
|
await this.templateOrm.delete(id);
|
|
504
504
|
}
|
|
505
|
+
/** @internal */
|
|
505
506
|
async createInvoiceWithPayment(input) {
|
|
506
507
|
const draft = await this.createInvoiceDraft(input);
|
|
507
508
|
const payment = await this.createMolliePaymentForInvoice(draft.invoice);
|
|
@@ -524,7 +525,7 @@ class InvoiceService {
|
|
|
524
525
|
const { items, amount_due } = this.calcTotals(input.items);
|
|
525
526
|
const useIdMode = this.invoiceNumberMode === 'id';
|
|
526
527
|
const invoice_number = useIdMode ? `PENDING-${crypto_1.default.randomUUID()}` : await this.generateInvoiceNumber();
|
|
527
|
-
const status = overrides?.status ?? '
|
|
528
|
+
const status = overrides?.status ?? 'draft';
|
|
528
529
|
const issuedAt = (0, orm_1.formatDatetime)(new Date());
|
|
529
530
|
const paidAt = overrides?.paid_at ?? (status === 'paid' ? issuedAt : null);
|
|
530
531
|
const amount_paid = overrides?.amount_paid ?? (status === 'paid' ? amount_due : 0);
|
|
@@ -1009,6 +1010,9 @@ class InvoiceService {
|
|
|
1009
1010
|
],
|
|
1010
1011
|
});
|
|
1011
1012
|
await this.invoicesOrm.incrementTimesSent(invoiceId);
|
|
1013
|
+
if (!isReceipt) {
|
|
1014
|
+
await this.invoicesOrm.updateStatusConditional(invoiceId, 'pending', 'draft');
|
|
1015
|
+
}
|
|
1012
1016
|
return {
|
|
1013
1017
|
invoice_number: invoice.invoice_number,
|
|
1014
1018
|
recipient: to,
|
|
@@ -18,6 +18,7 @@ export type ZCustomer = {
|
|
|
18
18
|
updated_at?: string | Date;
|
|
19
19
|
};
|
|
20
20
|
export type ZInvoiceItemType = 'service' | 'subsidy';
|
|
21
|
+
export type ZInvoiceStatus = 'draft' | 'pending' | 'paid' | 'failed' | 'canceled' | 'expired' | 'refunded' | 'archived';
|
|
21
22
|
export type ZInvoiceItem = {
|
|
22
23
|
id?: number;
|
|
23
24
|
invoice_id: number;
|
|
@@ -53,7 +54,6 @@ export type CreateInvoiceOverrides = {
|
|
|
53
54
|
mollie_payment_id?: string | null;
|
|
54
55
|
checkout_url?: string | null;
|
|
55
56
|
};
|
|
56
|
-
export type ZInvoiceStatus = 'draft' | 'pending' | 'paid' | 'failed' | 'canceled' | 'expired' | 'refunded' | 'archived';
|
|
57
57
|
export type ZInvoice = {
|
|
58
58
|
id?: number;
|
|
59
59
|
invoice_number: string;
|