law-common 10.63.2-beta.13 → 10.63.2-beta.15
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.
|
@@ -45,16 +45,16 @@ export declare class VendorEntityModel extends BaseEntityModel<EntityEnum.VENDOR
|
|
|
45
45
|
static readonly VENDOR_ENTITY_DOCUMENT_TYPES: readonly ["pan", "gst"];
|
|
46
46
|
/**
|
|
47
47
|
* Default number of days added to the Invoice Date to calculate the Due Date,
|
|
48
|
-
* used as a fallback when the Vendor does not have a `
|
|
48
|
+
* used as a fallback when the Vendor does not have a `paymentDueDays` value configured.
|
|
49
49
|
*
|
|
50
50
|
* @formula
|
|
51
|
-
* DueDate = InvoiceDate + (vendor.
|
|
51
|
+
* DueDate = InvoiceDate + (vendor.paymentDueDays ?? VendorEntityModel.DEFAULT_DUE_DAYS)
|
|
52
52
|
*
|
|
53
53
|
* @example
|
|
54
|
-
* vendor.
|
|
55
|
-
* vendor.
|
|
54
|
+
* vendor.paymentDueDays = 30 → DueDate = InvoiceDate + 30
|
|
55
|
+
* vendor.paymentDueDays = null → DueDate = InvoiceDate + 7 (this constant)
|
|
56
56
|
*
|
|
57
|
-
* @see VendorEntityModel.
|
|
57
|
+
* @see VendorEntityModel.paymentDueDays
|
|
58
58
|
*/
|
|
59
59
|
static readonly DEFAULT_DUE_DAYS = 7;
|
|
60
60
|
populateOrganizationTypeModel(organizationTypeEntityModels: OrganizationTypeEntityModel[]): null;
|
|
@@ -119,16 +119,16 @@ exports.VendorEntityModel = VendorEntityModel;
|
|
|
119
119
|
VendorEntityModel.VENDOR_ENTITY_DOCUMENT_TYPES = ["pan", "gst"];
|
|
120
120
|
/**
|
|
121
121
|
* Default number of days added to the Invoice Date to calculate the Due Date,
|
|
122
|
-
* used as a fallback when the Vendor does not have a `
|
|
122
|
+
* used as a fallback when the Vendor does not have a `paymentDueDays` value configured.
|
|
123
123
|
*
|
|
124
124
|
* @formula
|
|
125
|
-
* DueDate = InvoiceDate + (vendor.
|
|
125
|
+
* DueDate = InvoiceDate + (vendor.paymentDueDays ?? VendorEntityModel.DEFAULT_DUE_DAYS)
|
|
126
126
|
*
|
|
127
127
|
* @example
|
|
128
|
-
* vendor.
|
|
129
|
-
* vendor.
|
|
128
|
+
* vendor.paymentDueDays = 30 → DueDate = InvoiceDate + 30
|
|
129
|
+
* vendor.paymentDueDays = null → DueDate = InvoiceDate + 7 (this constant)
|
|
130
130
|
*
|
|
131
|
-
* @see VendorEntityModel.
|
|
131
|
+
* @see VendorEntityModel.paymentDueDays
|
|
132
132
|
*/
|
|
133
133
|
VendorEntityModel.DEFAULT_DUE_DAYS = 7;
|
|
134
134
|
VendorEntityModel.relationConfigs = [];
|
|
@@ -66,4 +66,48 @@ export declare class VendorInvoiceEntityModel extends BaseEntityModel<EntityEnum
|
|
|
66
66
|
static getTotalNetAmount<T extends {
|
|
67
67
|
netAmount: number;
|
|
68
68
|
}>(data: T[]): number;
|
|
69
|
+
/**
|
|
70
|
+
* Generates the next sequential voucher number for a new Vendor Invoice.
|
|
71
|
+
*
|
|
72
|
+
* @format
|
|
73
|
+
* `<FY-1><FY><MM><DD><###>`
|
|
74
|
+
*
|
|
75
|
+
* Where:
|
|
76
|
+
* - `<FY-1><FY>` — 4-digit financial year code (e.g., "2526" for FY 2025–26)
|
|
77
|
+
* - `<MM>` — 2-digit month of today's date (e.g., "03" for March)
|
|
78
|
+
* - `<DD>` — 2-digit day of today's date (e.g., "27" for 27th)
|
|
79
|
+
* - `<###>` — 3-digit sequence number, continuous within the FY (001–999)
|
|
80
|
+
*
|
|
81
|
+
* @sequence
|
|
82
|
+
* The sequence (`###`) is FY-scoped — it does NOT reset daily or monthly.
|
|
83
|
+
* It only resets when the Financial Year changes.
|
|
84
|
+
* The next number is always `max(existing sequences in current FY) + 1`.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* // Today: 27 March 2026 (FY 2025–26 → fyCode = "2526")
|
|
88
|
+
* // Existing vouchers this FY: ["25260326001", "25260326002", "25260120003"]
|
|
89
|
+
* // maxSequence = 3
|
|
90
|
+
* // Result:
|
|
91
|
+
* getNextVoucherNumber(existingInvoices) // → "25260327004"
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* // Today: 27 March 2026, No existing vouchers in FY 2025–26
|
|
95
|
+
* // Result:
|
|
96
|
+
* getNextVoucherNumber([]) // → "25260327001"
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* // FY changes: Today: 01 April 2026 (FY 2026–27 → fyCode = "2627")
|
|
100
|
+
* // Existing vouchers: ["25260327999"] (from previous FY, ignored)
|
|
101
|
+
* // Result:
|
|
102
|
+
* getNextVoucherNumber(existingInvoices) // → "26270401001" (sequence resets)
|
|
103
|
+
*
|
|
104
|
+
* @throws {Error} If the sequence reaches 999 within the same FY
|
|
105
|
+
*
|
|
106
|
+
* @param existingVendorInvoices - All existing VendorInvoiceEntityModel instances.
|
|
107
|
+
* Invoices with undefined/null voucherNo are automatically skipped.
|
|
108
|
+
* Invoices from previous FYs are automatically ignored.
|
|
109
|
+
*
|
|
110
|
+
* @returns The next voucher number string in format `<FY-1><FY><MM><DD><###>`
|
|
111
|
+
*/
|
|
112
|
+
static getNextVoucherNumber(existingVendorInvoices: VendorInvoiceEntityModel[]): string;
|
|
69
113
|
}
|
|
@@ -119,6 +119,85 @@ class VendorInvoiceEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
|
119
119
|
static getTotalNetAmount(data) {
|
|
120
120
|
return data.reduce((acc, item) => acc + item.netAmount, 0);
|
|
121
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Generates the next sequential voucher number for a new Vendor Invoice.
|
|
124
|
+
*
|
|
125
|
+
* @format
|
|
126
|
+
* `<FY-1><FY><MM><DD><###>`
|
|
127
|
+
*
|
|
128
|
+
* Where:
|
|
129
|
+
* - `<FY-1><FY>` — 4-digit financial year code (e.g., "2526" for FY 2025–26)
|
|
130
|
+
* - `<MM>` — 2-digit month of today's date (e.g., "03" for March)
|
|
131
|
+
* - `<DD>` — 2-digit day of today's date (e.g., "27" for 27th)
|
|
132
|
+
* - `<###>` — 3-digit sequence number, continuous within the FY (001–999)
|
|
133
|
+
*
|
|
134
|
+
* @sequence
|
|
135
|
+
* The sequence (`###`) is FY-scoped — it does NOT reset daily or monthly.
|
|
136
|
+
* It only resets when the Financial Year changes.
|
|
137
|
+
* The next number is always `max(existing sequences in current FY) + 1`.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* // Today: 27 March 2026 (FY 2025–26 → fyCode = "2526")
|
|
141
|
+
* // Existing vouchers this FY: ["25260326001", "25260326002", "25260120003"]
|
|
142
|
+
* // maxSequence = 3
|
|
143
|
+
* // Result:
|
|
144
|
+
* getNextVoucherNumber(existingInvoices) // → "25260327004"
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* // Today: 27 March 2026, No existing vouchers in FY 2025–26
|
|
148
|
+
* // Result:
|
|
149
|
+
* getNextVoucherNumber([]) // → "25260327001"
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* // FY changes: Today: 01 April 2026 (FY 2026–27 → fyCode = "2627")
|
|
153
|
+
* // Existing vouchers: ["25260327999"] (from previous FY, ignored)
|
|
154
|
+
* // Result:
|
|
155
|
+
* getNextVoucherNumber(existingInvoices) // → "26270401001" (sequence resets)
|
|
156
|
+
*
|
|
157
|
+
* @throws {Error} If the sequence reaches 999 within the same FY
|
|
158
|
+
*
|
|
159
|
+
* @param existingVendorInvoices - All existing VendorInvoiceEntityModel instances.
|
|
160
|
+
* Invoices with undefined/null voucherNo are automatically skipped.
|
|
161
|
+
* Invoices from previous FYs are automatically ignored.
|
|
162
|
+
*
|
|
163
|
+
* @returns The next voucher number string in format `<FY-1><FY><MM><DD><###>`
|
|
164
|
+
*/
|
|
165
|
+
static getNextVoucherNumber(existingVendorInvoices) {
|
|
166
|
+
// Always use today's date
|
|
167
|
+
const today = new Date();
|
|
168
|
+
// Get FY code e.g. "2526"
|
|
169
|
+
const fyCode = utils_1.DateCodeModel.getFinancialYearCode(today);
|
|
170
|
+
// Get MM and DD from today
|
|
171
|
+
const month = String(today.getMonth() + 1).padStart(2, "0");
|
|
172
|
+
const day = String(today.getDate()).padStart(2, "0");
|
|
173
|
+
// Base prefix e.g. "25260327"
|
|
174
|
+
const basePrefix = `${fyCode}${month}${day}`;
|
|
175
|
+
// Filter out undefined/null voucherNo AND filter only same FY
|
|
176
|
+
const matchingVoucherNumbers = existingVendorInvoices
|
|
177
|
+
.map((invoice) => invoice.voucherNo)
|
|
178
|
+
.filter((voucherNo) => !!voucherNo && voucherNo.startsWith(fyCode));
|
|
179
|
+
if (matchingVoucherNumbers.length === 0) {
|
|
180
|
+
return `${basePrefix}001`;
|
|
181
|
+
}
|
|
182
|
+
// Extract sequence numbers from ALL vouchers in this FY
|
|
183
|
+
const sequences = matchingVoucherNumbers
|
|
184
|
+
.map((voucherNo) => {
|
|
185
|
+
const match = voucherNo.match(/(\d{3})$/);
|
|
186
|
+
return match ? parseInt(match[1], 10) : null;
|
|
187
|
+
})
|
|
188
|
+
.filter((seq) => seq !== null);
|
|
189
|
+
if (sequences.length === 0) {
|
|
190
|
+
return `${basePrefix}001`;
|
|
191
|
+
}
|
|
192
|
+
console.log("sequences", sequences);
|
|
193
|
+
const maxSequence = Math.max(...sequences);
|
|
194
|
+
console.log("maxSequence", maxSequence);
|
|
195
|
+
if (maxSequence >= 999) {
|
|
196
|
+
throw new Error(`Voucher number sequence exhausted for FY ${fyCode}`);
|
|
197
|
+
}
|
|
198
|
+
console.log("nextInSquence", `${basePrefix}${String(maxSequence + 1).padStart(3, "0")}`);
|
|
199
|
+
return `${basePrefix}${String(maxSequence + 1).padStart(3, "0")}`;
|
|
200
|
+
}
|
|
122
201
|
}
|
|
123
202
|
exports.VendorInvoiceEntityModel = VendorInvoiceEntityModel;
|
|
124
203
|
VendorInvoiceEntityModel.relationConfigs = [
|