@classytic/ledger 0.2.0 → 0.4.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/README.md +161 -64
- package/dist/{categories-CclX7Q94.mjs → categories-FJlrvzcl.mjs} +0 -2
- package/dist/constants/index.d.mts +2 -2
- package/dist/constants/index.mjs +3 -3
- package/dist/core-8Xfnpn6g.d.mts +1 -2
- package/dist/country/index.d.mts +1 -1
- package/dist/country/index.mjs +0 -2
- package/dist/currencies-W8kQAkm0.mjs +0 -2
- package/dist/{idempotency.plugin-v9NQ_ta-.mjs → date-lock.plugin-C8kqPBjh.mjs} +51 -11
- package/dist/{engine-BzBMpWuy.d.mts → engine-DF-MtsEr.d.mts} +10 -6
- package/dist/{errors-B7yC-Jfw.mjs → errors-BoGUSUYL.mjs} +0 -2
- package/dist/exports/index.d.mts +1 -1
- package/dist/exports/index.mjs +1 -1
- package/dist/{exports-I5Xkq-9_.mjs → exports-DoGQQtMQ.mjs} +96 -77
- package/dist/{fiscal-close-L631E3De.mjs → fiscal-close-DmPV82e4.mjs} +1000 -286
- package/dist/{idempotency.plugin-CPxPt4vX.d.mts → idempotency.plugin-zU-GKJ0-.d.mts} +19 -17
- package/dist/{index-ZnSiqHYV.d.mts → index-CxZqRaOU.d.mts} +20 -6
- package/dist/{index-BPukb3L8.d.mts → index-J-XIbXH-.d.mts} +7 -8
- package/dist/index.d.mts +280 -58
- package/dist/index.mjs +123 -25
- package/dist/journal-entry.schema-B1CzLwC3.d.mts +103 -0
- package/dist/{journals-oH-FK3g8.mjs → journals-BcMn71Cq.mjs} +27 -6
- package/dist/{currencies-4WAbFRlw.d.mts → journals-DTipb_rz.d.mts} +16 -8
- package/dist/logger-UbTdBb1x.d.mts +1 -2
- package/dist/money.d.mts +1 -2
- package/dist/money.mjs +5 -5
- package/dist/plugins/index.d.mts +38 -2
- package/dist/plugins/index.mjs +57 -2
- package/dist/reconciliation.repository-DEybU_Ok.d.mts +135 -0
- package/dist/{account.repository-kDKwDt0I.mjs → reconciliation.repository-DgJEDVS-.mjs} +361 -210
- package/dist/{fiscal-period.schema-BQ5wsAq3.mjs → reconciliation.schema-KScbsXbY.mjs} +235 -90
- package/dist/reports/index.d.mts +2 -2
- package/dist/reports/index.mjs +2 -2
- package/dist/repositories/index.d.mts +2 -2
- package/dist/repositories/index.mjs +2 -2
- package/dist/schemas/index.d.mts +71 -2
- package/dist/schemas/index.mjs +2 -2
- package/dist/tenant-guard-CAxXoWuS.mjs +13 -0
- package/dist/trial-balance-DcQ0xj_4.d.mts +530 -0
- package/docs/reports.md +1 -1
- package/package.json +14 -6
- package/dist/account.repository-C7gwFLfM.d.mts +0 -29
- package/dist/account.repository-C7gwFLfM.d.mts.map +0 -1
- package/dist/account.repository-kDKwDt0I.mjs.map +0 -1
- package/dist/categories-CclX7Q94.mjs.map +0 -1
- package/dist/core-8Xfnpn6g.d.mts.map +0 -1
- package/dist/country/index.mjs.map +0 -1
- package/dist/currencies-4WAbFRlw.d.mts.map +0 -1
- package/dist/currencies-W8kQAkm0.mjs.map +0 -1
- package/dist/engine-BzBMpWuy.d.mts.map +0 -1
- package/dist/errors-B7yC-Jfw.mjs.map +0 -1
- package/dist/exports-I5Xkq-9_.mjs.map +0 -1
- package/dist/fiscal-close-L631E3De.mjs.map +0 -1
- package/dist/fiscal-close-dNlzB37y.d.mts +0 -270
- package/dist/fiscal-close-dNlzB37y.d.mts.map +0 -1
- package/dist/fiscal-period.schema-BQ5wsAq3.mjs.map +0 -1
- package/dist/fiscal-period.schema-BRdKAjrr.d.mts +0 -38
- package/dist/fiscal-period.schema-BRdKAjrr.d.mts.map +0 -1
- package/dist/idempotency.plugin-CPxPt4vX.d.mts.map +0 -1
- package/dist/idempotency.plugin-v9NQ_ta-.mjs.map +0 -1
- package/dist/index-BPukb3L8.d.mts.map +0 -1
- package/dist/index-ZnSiqHYV.d.mts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/journals-oH-FK3g8.mjs.map +0 -1
- package/dist/logger-UbTdBb1x.d.mts.map +0 -1
- package/dist/money.d.mts.map +0 -1
- package/dist/money.mjs.map +0 -1
- package/dist/session-Ba8E3Ufa.mjs +0 -84
- package/dist/session-Ba8E3Ufa.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as getJournalTypeCodes, r as _freezeJournalTypes, t as JOURNAL_CODES } from "./journals-BcMn71Cq.mjs";
|
|
2
2
|
import mongoose from "mongoose";
|
|
3
3
|
//#region src/schemas/currency-field.ts
|
|
4
4
|
/**
|
|
@@ -70,9 +70,8 @@ function createAccountSchema(config, options = {}) {
|
|
|
70
70
|
};
|
|
71
71
|
const schema = new mongoose.Schema(fields, { timestamps: true });
|
|
72
72
|
schema.pre("validate", function() {
|
|
73
|
-
|
|
74
|
-
if (!
|
|
75
|
-
if (!doc.name && doc.accountTypeCode) doc.name = country.getAccountType(doc.accountTypeCode)?.name ?? doc.accountTypeCode;
|
|
73
|
+
if (!this.accountNumber && this.accountTypeCode) this.accountNumber = this.accountTypeCode;
|
|
74
|
+
if (!this.name && this.accountTypeCode) this.name = country.getAccountType(this.accountTypeCode)?.name ?? this.accountTypeCode;
|
|
76
75
|
});
|
|
77
76
|
if (indexes) if (multiTenant) {
|
|
78
77
|
const org = multiTenant.orgField;
|
|
@@ -97,6 +96,175 @@ function createAccountSchema(config, options = {}) {
|
|
|
97
96
|
return schema;
|
|
98
97
|
}
|
|
99
98
|
//#endregion
|
|
99
|
+
//#region src/schemas/budget.schema.ts
|
|
100
|
+
/**
|
|
101
|
+
* Budget Schema Factory
|
|
102
|
+
*
|
|
103
|
+
* Creates a Mongoose schema for budget records.
|
|
104
|
+
* Each record represents a budgeted amount for an account over a specific period.
|
|
105
|
+
* All monetary amounts are in integer cents.
|
|
106
|
+
*/
|
|
107
|
+
function createBudgetSchema(config, options = {}) {
|
|
108
|
+
const { multiTenant } = config;
|
|
109
|
+
const { indexes = true, extraFields = {}, extraIndexes = [] } = options;
|
|
110
|
+
const fields = {
|
|
111
|
+
account: {
|
|
112
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
113
|
+
ref: "Account",
|
|
114
|
+
required: true
|
|
115
|
+
},
|
|
116
|
+
periodStart: {
|
|
117
|
+
type: Date,
|
|
118
|
+
required: true
|
|
119
|
+
},
|
|
120
|
+
periodEnd: {
|
|
121
|
+
type: Date,
|
|
122
|
+
required: true
|
|
123
|
+
},
|
|
124
|
+
amount: {
|
|
125
|
+
type: Number,
|
|
126
|
+
required: true,
|
|
127
|
+
validate: {
|
|
128
|
+
validator: (v) => Number.isInteger(v),
|
|
129
|
+
message: "amount must be an integer (cents)."
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
label: {
|
|
133
|
+
type: String,
|
|
134
|
+
default: null
|
|
135
|
+
},
|
|
136
|
+
...extraFields
|
|
137
|
+
};
|
|
138
|
+
if (multiTenant) fields[multiTenant.orgField] = {
|
|
139
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
140
|
+
ref: multiTenant.orgRef,
|
|
141
|
+
required: true
|
|
142
|
+
};
|
|
143
|
+
const schema = new mongoose.Schema(fields, { timestamps: true });
|
|
144
|
+
schema.pre("validate", function() {
|
|
145
|
+
const doc = this;
|
|
146
|
+
if (doc.periodStart && doc.periodEnd && doc.periodEnd <= doc.periodStart) doc.invalidate("periodEnd", "periodEnd must be after periodStart.", doc.periodEnd, "periodEnd");
|
|
147
|
+
});
|
|
148
|
+
if (indexes) if (multiTenant) {
|
|
149
|
+
const org = multiTenant.orgField;
|
|
150
|
+
schema.index({
|
|
151
|
+
[org]: 1,
|
|
152
|
+
account: 1,
|
|
153
|
+
periodStart: 1,
|
|
154
|
+
periodEnd: 1
|
|
155
|
+
}, { unique: true });
|
|
156
|
+
schema.index({
|
|
157
|
+
[org]: 1,
|
|
158
|
+
periodStart: 1,
|
|
159
|
+
periodEnd: 1
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
schema.index({
|
|
163
|
+
account: 1,
|
|
164
|
+
periodStart: 1,
|
|
165
|
+
periodEnd: 1
|
|
166
|
+
}, { unique: true });
|
|
167
|
+
schema.index({
|
|
168
|
+
periodStart: 1,
|
|
169
|
+
periodEnd: 1
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
for (const idx of extraIndexes) schema.index(idx.fields, idx.options);
|
|
173
|
+
return schema;
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/schemas/fiscal-period.schema.ts
|
|
177
|
+
/**
|
|
178
|
+
* Fiscal Period Schema Factory
|
|
179
|
+
*
|
|
180
|
+
* Creates a Mongoose schema for tracking fiscal periods (months, quarters, years).
|
|
181
|
+
* Supports closing periods to lock entries.
|
|
182
|
+
*/
|
|
183
|
+
function createFiscalPeriodSchema(config, options = {}) {
|
|
184
|
+
const { multiTenant } = config;
|
|
185
|
+
const { indexes = true, extraFields = {}, extraIndexes = [] } = options;
|
|
186
|
+
const fields = {
|
|
187
|
+
name: {
|
|
188
|
+
type: String,
|
|
189
|
+
required: true
|
|
190
|
+
},
|
|
191
|
+
startDate: {
|
|
192
|
+
type: Date,
|
|
193
|
+
required: true
|
|
194
|
+
},
|
|
195
|
+
endDate: {
|
|
196
|
+
type: Date,
|
|
197
|
+
required: true
|
|
198
|
+
},
|
|
199
|
+
closed: {
|
|
200
|
+
type: Boolean,
|
|
201
|
+
default: false
|
|
202
|
+
},
|
|
203
|
+
closedAt: {
|
|
204
|
+
type: Date,
|
|
205
|
+
default: null
|
|
206
|
+
},
|
|
207
|
+
closedBy: {
|
|
208
|
+
type: String,
|
|
209
|
+
default: null
|
|
210
|
+
},
|
|
211
|
+
closingEntryId: {
|
|
212
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
213
|
+
default: null
|
|
214
|
+
},
|
|
215
|
+
reopenedAt: {
|
|
216
|
+
type: Date,
|
|
217
|
+
default: null
|
|
218
|
+
},
|
|
219
|
+
reopenedBy: {
|
|
220
|
+
type: String,
|
|
221
|
+
default: null
|
|
222
|
+
},
|
|
223
|
+
...extraFields
|
|
224
|
+
};
|
|
225
|
+
if (multiTenant) fields[multiTenant.orgField] = {
|
|
226
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
227
|
+
ref: multiTenant.orgRef,
|
|
228
|
+
required: true
|
|
229
|
+
};
|
|
230
|
+
const schema = new mongoose.Schema(fields, { timestamps: true });
|
|
231
|
+
if (indexes) if (multiTenant) {
|
|
232
|
+
const org = multiTenant.orgField;
|
|
233
|
+
schema.index({
|
|
234
|
+
[org]: 1,
|
|
235
|
+
startDate: 1,
|
|
236
|
+
endDate: 1
|
|
237
|
+
}, { unique: true });
|
|
238
|
+
schema.index({
|
|
239
|
+
[org]: 1,
|
|
240
|
+
closed: 1
|
|
241
|
+
});
|
|
242
|
+
} else {
|
|
243
|
+
schema.index({
|
|
244
|
+
startDate: 1,
|
|
245
|
+
endDate: 1
|
|
246
|
+
}, { unique: true });
|
|
247
|
+
schema.index({ closed: 1 });
|
|
248
|
+
}
|
|
249
|
+
for (const idx of extraIndexes) schema.index(idx.fields, idx.options);
|
|
250
|
+
schema.pre("validate", async function() {
|
|
251
|
+
const doc = this;
|
|
252
|
+
if (!doc.startDate || !doc.endDate) return;
|
|
253
|
+
const overlapQuery = {
|
|
254
|
+
_id: { $ne: doc._id },
|
|
255
|
+
startDate: { $lt: doc.endDate },
|
|
256
|
+
endDate: { $gt: doc.startDate }
|
|
257
|
+
};
|
|
258
|
+
if (multiTenant) overlapQuery[multiTenant.orgField] = doc[multiTenant.orgField];
|
|
259
|
+
const overlap = await doc.collection.findOne(overlapQuery);
|
|
260
|
+
if (overlap) {
|
|
261
|
+
const msg = `Fiscal period overlaps with existing period "${overlap.name}" (${new Date(overlap.startDate).toISOString().split("T")[0]} – ${new Date(overlap.endDate).toISOString().split("T")[0]}).`;
|
|
262
|
+
doc.invalidate("startDate", msg, doc.startDate, "overlap");
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return schema;
|
|
266
|
+
}
|
|
267
|
+
//#endregion
|
|
100
268
|
//#region src/schemas/journal-entry.schema.ts
|
|
101
269
|
/**
|
|
102
270
|
* Journal Entry Schema Factory
|
|
@@ -172,11 +340,12 @@ function createJournalEntrySchema(config, accountModelName, options = {}) {
|
|
|
172
340
|
...currencyItemFields,
|
|
173
341
|
...extraItemFields
|
|
174
342
|
}, { _id: false });
|
|
343
|
+
_freezeJournalTypes();
|
|
175
344
|
const fields = {
|
|
176
345
|
journalType: {
|
|
177
346
|
type: String,
|
|
178
347
|
enum: getJournalTypeCodes(),
|
|
179
|
-
default: JOURNAL_CODES
|
|
348
|
+
default: JOURNAL_CODES.MISC,
|
|
180
349
|
required: true
|
|
181
350
|
},
|
|
182
351
|
referenceNumber: { type: String },
|
|
@@ -275,22 +444,21 @@ function createJournalEntrySchema(config, accountModelName, options = {}) {
|
|
|
275
444
|
};
|
|
276
445
|
const schema = new mongoose.Schema(fields, { timestamps: true });
|
|
277
446
|
schema.pre("validate", function() {
|
|
278
|
-
const
|
|
279
|
-
for (
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
const c = doc.journalItems[i].credit || 0;
|
|
447
|
+
for (const item of this.journalItems) if (!item.date) item.date = this.date;
|
|
448
|
+
for (let i = 0; i < this.journalItems.length; i++) {
|
|
449
|
+
const d = this.journalItems[i].debit ?? 0;
|
|
450
|
+
const c = this.journalItems[i].credit ?? 0;
|
|
283
451
|
if (d > 0 && c > 0) throw new Error(`Journal item at index ${i}: cannot have both debit (${d}) and credit (${c}) greater than zero`);
|
|
284
|
-
if (
|
|
452
|
+
if (this.state === "posted" && d === 0 && c === 0) throw new Error(`Journal item at index ${i}: posted entries cannot have zero-value lines (both debit and credit are 0)`);
|
|
285
453
|
}
|
|
286
|
-
const totalDebit =
|
|
287
|
-
const totalCredit =
|
|
288
|
-
if (
|
|
289
|
-
if (
|
|
454
|
+
const totalDebit = this.journalItems.reduce((s, item) => s + (item.debit ?? 0), 0);
|
|
455
|
+
const totalCredit = this.journalItems.reduce((s, item) => s + (item.credit ?? 0), 0);
|
|
456
|
+
if (this.state === "posted") {
|
|
457
|
+
if (this.journalItems.length < 2) throw new Error("Posted entries must have at least 2 journal items");
|
|
290
458
|
if (totalDebit !== totalCredit) throw new Error("Total debit must equal total credit for posted entries");
|
|
291
459
|
}
|
|
292
|
-
|
|
293
|
-
|
|
460
|
+
this.totalDebit = totalDebit;
|
|
461
|
+
this.totalCredit = totalCredit;
|
|
294
462
|
});
|
|
295
463
|
if (autoReference) {
|
|
296
464
|
const generateReferenceNumber = async (doc, Model, session) => {
|
|
@@ -312,16 +480,15 @@ function createJournalEntrySchema(config, accountModelName, options = {}) {
|
|
|
312
480
|
return `${prefix}${String(seq).padStart(4, "0")}`;
|
|
313
481
|
};
|
|
314
482
|
schema.pre("save", async function() {
|
|
315
|
-
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
doc.referenceNumber = await generateReferenceNumber(doc, Model, session);
|
|
483
|
+
if (this.isModified("journalType")) this.referenceNumber = void 0;
|
|
484
|
+
if (!this.referenceNumber) {
|
|
485
|
+
const session = this.$session?.() ?? null;
|
|
486
|
+
const Model = this.constructor;
|
|
487
|
+
this.referenceNumber = await generateReferenceNumber(this, Model, session);
|
|
321
488
|
}
|
|
322
489
|
});
|
|
323
490
|
const MAX_REF_RETRIES = 3;
|
|
324
|
-
schema.post("save", async
|
|
491
|
+
schema.post("save", async (error, doc, next) => {
|
|
325
492
|
const mongoError = error;
|
|
326
493
|
if (mongoError.code === 11e3 && mongoError.keyPattern?.referenceNumber) {
|
|
327
494
|
const entry = doc;
|
|
@@ -424,52 +591,51 @@ function createJournalEntrySchema(config, accountModelName, options = {}) {
|
|
|
424
591
|
return schema;
|
|
425
592
|
}
|
|
426
593
|
//#endregion
|
|
427
|
-
//#region src/schemas/
|
|
594
|
+
//#region src/schemas/reconciliation.schema.ts
|
|
428
595
|
/**
|
|
429
|
-
*
|
|
596
|
+
* Reconciliation Schema Factory
|
|
430
597
|
*
|
|
431
|
-
* Creates a Mongoose schema for
|
|
432
|
-
*
|
|
598
|
+
* Creates a Mongoose schema for reconciliation records that link matched
|
|
599
|
+
* debit/credit journal items. Used to track which journal entries have been
|
|
600
|
+
* reconciled against each other for a given account.
|
|
433
601
|
*/
|
|
434
|
-
function
|
|
602
|
+
function createReconciliationSchema(config, accountModelName, journalEntryModelName, options = {}) {
|
|
435
603
|
const { multiTenant } = config;
|
|
436
604
|
const { indexes = true, extraFields = {}, extraIndexes = [] } = options;
|
|
437
605
|
const fields = {
|
|
438
|
-
|
|
439
|
-
type:
|
|
606
|
+
account: {
|
|
607
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
608
|
+
ref: accountModelName,
|
|
440
609
|
required: true
|
|
441
610
|
},
|
|
442
|
-
|
|
443
|
-
type:
|
|
444
|
-
|
|
611
|
+
journalEntryIds: {
|
|
612
|
+
type: [{
|
|
613
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
614
|
+
ref: journalEntryModelName
|
|
615
|
+
}],
|
|
616
|
+
required: true,
|
|
617
|
+
validate: {
|
|
618
|
+
validator: (v) => Array.isArray(v) && v.length > 0,
|
|
619
|
+
message: "journalEntryIds must contain at least one entry."
|
|
620
|
+
}
|
|
445
621
|
},
|
|
446
|
-
|
|
447
|
-
type:
|
|
622
|
+
debitTotal: {
|
|
623
|
+
type: Number,
|
|
448
624
|
required: true
|
|
449
625
|
},
|
|
450
|
-
|
|
451
|
-
type:
|
|
452
|
-
|
|
453
|
-
},
|
|
454
|
-
closedAt: {
|
|
455
|
-
type: Date,
|
|
456
|
-
default: null
|
|
457
|
-
},
|
|
458
|
-
closedBy: {
|
|
459
|
-
type: String,
|
|
460
|
-
default: null
|
|
626
|
+
creditTotal: {
|
|
627
|
+
type: Number,
|
|
628
|
+
required: true
|
|
461
629
|
},
|
|
462
|
-
|
|
463
|
-
type:
|
|
464
|
-
default:
|
|
630
|
+
difference: {
|
|
631
|
+
type: Number,
|
|
632
|
+
default: 0
|
|
465
633
|
},
|
|
466
|
-
|
|
634
|
+
note: { type: String },
|
|
635
|
+
reconciledBy: { type: String },
|
|
636
|
+
reconciledAt: {
|
|
467
637
|
type: Date,
|
|
468
|
-
default:
|
|
469
|
-
},
|
|
470
|
-
reopenedBy: {
|
|
471
|
-
type: String,
|
|
472
|
-
default: null
|
|
638
|
+
default: Date.now
|
|
473
639
|
},
|
|
474
640
|
...extraFields
|
|
475
641
|
};
|
|
@@ -479,43 +645,22 @@ function createFiscalPeriodSchema(config, options = {}) {
|
|
|
479
645
|
required: true
|
|
480
646
|
};
|
|
481
647
|
const schema = new mongoose.Schema(fields, { timestamps: true });
|
|
482
|
-
if (indexes)
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
648
|
+
if (indexes) {
|
|
649
|
+
if (multiTenant) {
|
|
650
|
+
const org = multiTenant.orgField;
|
|
651
|
+
schema.index({
|
|
652
|
+
[org]: 1,
|
|
653
|
+
account: 1,
|
|
654
|
+
reconciledAt: 1
|
|
655
|
+
});
|
|
656
|
+
} else schema.index({
|
|
657
|
+
account: 1,
|
|
658
|
+
reconciledAt: 1
|
|
492
659
|
});
|
|
493
|
-
|
|
494
|
-
schema.index({
|
|
495
|
-
startDate: 1,
|
|
496
|
-
endDate: 1
|
|
497
|
-
}, { unique: true });
|
|
498
|
-
schema.index({ closed: 1 });
|
|
660
|
+
schema.index({ journalEntryIds: 1 });
|
|
499
661
|
}
|
|
500
662
|
for (const idx of extraIndexes) schema.index(idx.fields, idx.options);
|
|
501
|
-
schema.pre("validate", async function() {
|
|
502
|
-
const doc = this;
|
|
503
|
-
if (!doc.startDate || !doc.endDate) return;
|
|
504
|
-
const overlapQuery = {
|
|
505
|
-
_id: { $ne: doc._id },
|
|
506
|
-
startDate: { $lt: doc.endDate },
|
|
507
|
-
endDate: { $gt: doc.startDate }
|
|
508
|
-
};
|
|
509
|
-
if (multiTenant) overlapQuery[multiTenant.orgField] = doc[multiTenant.orgField];
|
|
510
|
-
const overlap = await doc.collection.findOne(overlapQuery);
|
|
511
|
-
if (overlap) {
|
|
512
|
-
const msg = `Fiscal period overlaps with existing period "${overlap.name}" (${new Date(overlap.startDate).toISOString().split("T")[0]} – ${new Date(overlap.endDate).toISOString().split("T")[0]}).`;
|
|
513
|
-
doc.invalidate("startDate", msg, doc.startDate, "overlap");
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
663
|
return schema;
|
|
517
664
|
}
|
|
518
665
|
//#endregion
|
|
519
|
-
export { createJournalEntrySchema as n,
|
|
520
|
-
|
|
521
|
-
//# sourceMappingURL=fiscal-period.schema-BQ5wsAq3.mjs.map
|
|
666
|
+
export { createAccountSchema as a, createBudgetSchema as i, createJournalEntrySchema as n, createFiscalPeriodSchema as r, createReconciliationSchema as t };
|
package/dist/reports/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { type BalanceSheetOptions, type CashFlowOptions, type FiscalCloseOptions, type FiscalCloseResult, type FiscalReopenResult, type GeneralLedgerOptions, type IncomeStatementOptions, type TrialBalanceOptions, closeFiscalPeriod, generateBalanceSheet, generateCashFlow, generateGeneralLedger, generateIncomeStatement, generateTrialBalance, reopenFiscalPeriod };
|
|
1
|
+
import { $ as AgedBucketConfig, A as BudgetVsActualReport, C as DimensionBreakdownReport, D as generateCashFlow, E as CashFlowOptions, M as generateBudgetVsActual, N as BalanceSheetOptions, O as BudgetVsActualOptions, P as generateBalanceSheet, Q as AgedBalanceRow, S as DimensionBreakdownParams, T as generateDimensionBreakdown, X as AgedBalanceParams, Y as AgedBalanceOptions, Z as AgedBalanceReport, _ as FiscalCloseResult, a as RevaluationReport, b as reopenFiscalPeriod, et as DEFAULT_BUCKETS, f as IncomeStatementOptions, g as FiscalCloseOptions, h as generateGeneralLedger, i as RevaluationParams, j as BudgetVsActualRow, k as BudgetVsActualParams, m as GeneralLedgerOptions, n as generateTrialBalance, o as generateRevaluation, p as generateIncomeStatement, r as RevaluationOptions, t as TrialBalanceOptions, tt as generateAgedBalance, v as FiscalReopenResult, w as DimensionBreakdownRow, x as DimensionBreakdownOptions, y as closeFiscalPeriod } from "../trial-balance-DcQ0xj_4.mjs";
|
|
2
|
+
export { type AgedBalanceOptions, type AgedBalanceParams, type AgedBalanceReport, type AgedBalanceRow, type AgedBucketConfig, type BalanceSheetOptions, type BudgetVsActualOptions, type BudgetVsActualParams, type BudgetVsActualReport, type BudgetVsActualRow, type CashFlowOptions, DEFAULT_BUCKETS, type DimensionBreakdownOptions, type DimensionBreakdownParams, type DimensionBreakdownReport, type DimensionBreakdownRow, type FiscalCloseOptions, type FiscalCloseResult, type FiscalReopenResult, type GeneralLedgerOptions, type IncomeStatementOptions, type RevaluationOptions, type RevaluationParams, type RevaluationReport, type TrialBalanceOptions, closeFiscalPeriod, generateAgedBalance, generateBalanceSheet, generateBudgetVsActual, generateCashFlow, generateDimensionBreakdown, generateGeneralLedger, generateIncomeStatement, generateRevaluation, generateTrialBalance, reopenFiscalPeriod };
|
package/dist/reports/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { closeFiscalPeriod, generateBalanceSheet, generateCashFlow, generateGeneralLedger, generateIncomeStatement, generateTrialBalance, reopenFiscalPeriod };
|
|
1
|
+
import { C as DEFAULT_BUCKETS, d as generateGeneralLedger, f as generateDimensionBreakdown, h as generateBalanceSheet, m as generateBudgetVsActual, n as reopenFiscalPeriod, o as generateTrialBalance, p as generateCashFlow, s as generateRevaluation, t as closeFiscalPeriod, u as generateIncomeStatement, w as generateAgedBalance } from "../fiscal-close-DmPV82e4.mjs";
|
|
2
|
+
export { DEFAULT_BUCKETS, closeFiscalPeriod, generateAgedBalance, generateBalanceSheet, generateBudgetVsActual, generateCashFlow, generateDimensionBreakdown, generateGeneralLedger, generateIncomeStatement, generateRevaluation, generateTrialBalance, reopenFiscalPeriod };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as wireJournalEntryMethods,
|
|
2
|
-
export { wireAccountMethods, wireJournalEntryMethods };
|
|
1
|
+
import { n as wireJournalEntryMethods, r as wireAccountMethods, t as wireReconciliationMethods } from "../reconciliation.repository-DEybU_Ok.mjs";
|
|
2
|
+
export { wireAccountMethods, wireJournalEntryMethods, wireReconciliationMethods };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as wireJournalEntryMethods,
|
|
2
|
-
export { wireAccountMethods, wireJournalEntryMethods };
|
|
1
|
+
import { n as wireJournalEntryMethods, r as wireAccountMethods, t as wireReconciliationMethods } from "../reconciliation.repository-DgJEDVS-.mjs";
|
|
2
|
+
export { wireAccountMethods, wireJournalEntryMethods, wireReconciliationMethods };
|
package/dist/schemas/index.d.mts
CHANGED
|
@@ -1,2 +1,71 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { o as SchemaOptions, t as AccountingEngineConfig } from "../engine-DF-MtsEr.mjs";
|
|
2
|
+
import { n as createFiscalPeriodSchema, r as createAccountSchema, t as createJournalEntrySchema } from "../journal-entry.schema-B1CzLwC3.mjs";
|
|
3
|
+
import mongoose from "mongoose";
|
|
4
|
+
|
|
5
|
+
//#region src/schemas/budget.schema.d.ts
|
|
6
|
+
declare function createBudgetSchema(config: AccountingEngineConfig, options?: SchemaOptions): mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
7
|
+
timestamps: true;
|
|
8
|
+
}, {
|
|
9
|
+
[x: number]: any;
|
|
10
|
+
[x: string]: any;
|
|
11
|
+
} & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
|
|
12
|
+
[x: number]: any;
|
|
13
|
+
[x: string]: any;
|
|
14
|
+
} & mongoose.DefaultTimestampProps, {
|
|
15
|
+
id: string;
|
|
16
|
+
}, Omit<mongoose.DefaultSchemaOptions, "timestamps"> & {
|
|
17
|
+
timestamps: true;
|
|
18
|
+
}> & Omit<{
|
|
19
|
+
[x: number]: any;
|
|
20
|
+
[x: string]: any;
|
|
21
|
+
} & mongoose.DefaultTimestampProps & {
|
|
22
|
+
_id: mongoose.Types.ObjectId;
|
|
23
|
+
} & {
|
|
24
|
+
__v: number;
|
|
25
|
+
}, "id"> & {
|
|
26
|
+
id: string;
|
|
27
|
+
}, unknown, {
|
|
28
|
+
[x: number]: any;
|
|
29
|
+
[x: string]: any;
|
|
30
|
+
createdAt: NativeDate;
|
|
31
|
+
updatedAt: NativeDate;
|
|
32
|
+
} & {
|
|
33
|
+
_id: mongoose.Types.ObjectId;
|
|
34
|
+
} & {
|
|
35
|
+
__v: number;
|
|
36
|
+
}>;
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/schemas/reconciliation.schema.d.ts
|
|
39
|
+
declare function createReconciliationSchema(config: AccountingEngineConfig, accountModelName: string, journalEntryModelName: string, options?: SchemaOptions): mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
40
|
+
timestamps: true;
|
|
41
|
+
}, {
|
|
42
|
+
[x: number]: any;
|
|
43
|
+
[x: string]: any;
|
|
44
|
+
} & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
|
|
45
|
+
[x: number]: any;
|
|
46
|
+
[x: string]: any;
|
|
47
|
+
} & mongoose.DefaultTimestampProps, {
|
|
48
|
+
id: string;
|
|
49
|
+
}, Omit<mongoose.DefaultSchemaOptions, "timestamps"> & {
|
|
50
|
+
timestamps: true;
|
|
51
|
+
}> & Omit<{
|
|
52
|
+
[x: number]: any;
|
|
53
|
+
[x: string]: any;
|
|
54
|
+
} & mongoose.DefaultTimestampProps & {
|
|
55
|
+
_id: mongoose.Types.ObjectId;
|
|
56
|
+
} & {
|
|
57
|
+
__v: number;
|
|
58
|
+
}, "id"> & {
|
|
59
|
+
id: string;
|
|
60
|
+
}, unknown, {
|
|
61
|
+
[x: number]: any;
|
|
62
|
+
[x: string]: any;
|
|
63
|
+
createdAt: NativeDate;
|
|
64
|
+
updatedAt: NativeDate;
|
|
65
|
+
} & {
|
|
66
|
+
_id: mongoose.Types.ObjectId;
|
|
67
|
+
} & {
|
|
68
|
+
__v: number;
|
|
69
|
+
}>;
|
|
70
|
+
//#endregion
|
|
71
|
+
export { createAccountSchema, createBudgetSchema, createFiscalPeriodSchema, createJournalEntrySchema, createReconciliationSchema };
|
package/dist/schemas/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createJournalEntrySchema, r as
|
|
2
|
-
export { createAccountSchema, createFiscalPeriodSchema, createJournalEntrySchema };
|
|
1
|
+
import { a as createAccountSchema, i as createBudgetSchema, n as createJournalEntrySchema, r as createFiscalPeriodSchema, t as createReconciliationSchema } from "../reconciliation.schema-KScbsXbY.mjs";
|
|
2
|
+
export { createAccountSchema, createBudgetSchema, createFiscalPeriodSchema, createJournalEntrySchema, createReconciliationSchema };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { n as Errors } from "./errors-BoGUSUYL.mjs";
|
|
2
|
+
//#region src/utils/tenant-guard.ts
|
|
3
|
+
/**
|
|
4
|
+
* Multi-tenant scope guard.
|
|
5
|
+
*
|
|
6
|
+
* Throws when orgField is configured (multi-tenant mode active) but
|
|
7
|
+
* organizationId is missing — preventing unscoped cross-tenant queries.
|
|
8
|
+
*/
|
|
9
|
+
function requireOrgScope(orgField, organizationId) {
|
|
10
|
+
if (orgField && !organizationId) throw Errors.validation("organizationId is required when multi-tenant mode is configured (orgField: \"" + orgField + "\"). Refusing to run unscoped query.");
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { requireOrgScope as t };
|