@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.
Files changed (70) hide show
  1. package/README.md +161 -64
  2. package/dist/{categories-CclX7Q94.mjs → categories-FJlrvzcl.mjs} +0 -2
  3. package/dist/constants/index.d.mts +2 -2
  4. package/dist/constants/index.mjs +3 -3
  5. package/dist/core-8Xfnpn6g.d.mts +1 -2
  6. package/dist/country/index.d.mts +1 -1
  7. package/dist/country/index.mjs +0 -2
  8. package/dist/currencies-W8kQAkm0.mjs +0 -2
  9. package/dist/{idempotency.plugin-v9NQ_ta-.mjs → date-lock.plugin-C8kqPBjh.mjs} +51 -11
  10. package/dist/{engine-BzBMpWuy.d.mts → engine-DF-MtsEr.d.mts} +10 -6
  11. package/dist/{errors-B7yC-Jfw.mjs → errors-BoGUSUYL.mjs} +0 -2
  12. package/dist/exports/index.d.mts +1 -1
  13. package/dist/exports/index.mjs +1 -1
  14. package/dist/{exports-I5Xkq-9_.mjs → exports-DoGQQtMQ.mjs} +96 -77
  15. package/dist/{fiscal-close-L631E3De.mjs → fiscal-close-DmPV82e4.mjs} +1000 -286
  16. package/dist/{idempotency.plugin-CPxPt4vX.d.mts → idempotency.plugin-zU-GKJ0-.d.mts} +19 -17
  17. package/dist/{index-ZnSiqHYV.d.mts → index-CxZqRaOU.d.mts} +20 -6
  18. package/dist/{index-BPukb3L8.d.mts → index-J-XIbXH-.d.mts} +7 -8
  19. package/dist/index.d.mts +280 -58
  20. package/dist/index.mjs +123 -25
  21. package/dist/journal-entry.schema-B1CzLwC3.d.mts +103 -0
  22. package/dist/{journals-oH-FK3g8.mjs → journals-BcMn71Cq.mjs} +27 -6
  23. package/dist/{currencies-4WAbFRlw.d.mts → journals-DTipb_rz.d.mts} +16 -8
  24. package/dist/logger-UbTdBb1x.d.mts +1 -2
  25. package/dist/money.d.mts +1 -2
  26. package/dist/money.mjs +5 -5
  27. package/dist/plugins/index.d.mts +38 -2
  28. package/dist/plugins/index.mjs +57 -2
  29. package/dist/reconciliation.repository-DEybU_Ok.d.mts +135 -0
  30. package/dist/{account.repository-kDKwDt0I.mjs → reconciliation.repository-DgJEDVS-.mjs} +361 -210
  31. package/dist/{fiscal-period.schema-BQ5wsAq3.mjs → reconciliation.schema-KScbsXbY.mjs} +235 -90
  32. package/dist/reports/index.d.mts +2 -2
  33. package/dist/reports/index.mjs +2 -2
  34. package/dist/repositories/index.d.mts +2 -2
  35. package/dist/repositories/index.mjs +2 -2
  36. package/dist/schemas/index.d.mts +71 -2
  37. package/dist/schemas/index.mjs +2 -2
  38. package/dist/tenant-guard-CAxXoWuS.mjs +13 -0
  39. package/dist/trial-balance-DcQ0xj_4.d.mts +530 -0
  40. package/docs/reports.md +1 -1
  41. package/package.json +14 -6
  42. package/dist/account.repository-C7gwFLfM.d.mts +0 -29
  43. package/dist/account.repository-C7gwFLfM.d.mts.map +0 -1
  44. package/dist/account.repository-kDKwDt0I.mjs.map +0 -1
  45. package/dist/categories-CclX7Q94.mjs.map +0 -1
  46. package/dist/core-8Xfnpn6g.d.mts.map +0 -1
  47. package/dist/country/index.mjs.map +0 -1
  48. package/dist/currencies-4WAbFRlw.d.mts.map +0 -1
  49. package/dist/currencies-W8kQAkm0.mjs.map +0 -1
  50. package/dist/engine-BzBMpWuy.d.mts.map +0 -1
  51. package/dist/errors-B7yC-Jfw.mjs.map +0 -1
  52. package/dist/exports-I5Xkq-9_.mjs.map +0 -1
  53. package/dist/fiscal-close-L631E3De.mjs.map +0 -1
  54. package/dist/fiscal-close-dNlzB37y.d.mts +0 -270
  55. package/dist/fiscal-close-dNlzB37y.d.mts.map +0 -1
  56. package/dist/fiscal-period.schema-BQ5wsAq3.mjs.map +0 -1
  57. package/dist/fiscal-period.schema-BRdKAjrr.d.mts +0 -38
  58. package/dist/fiscal-period.schema-BRdKAjrr.d.mts.map +0 -1
  59. package/dist/idempotency.plugin-CPxPt4vX.d.mts.map +0 -1
  60. package/dist/idempotency.plugin-v9NQ_ta-.mjs.map +0 -1
  61. package/dist/index-BPukb3L8.d.mts.map +0 -1
  62. package/dist/index-ZnSiqHYV.d.mts.map +0 -1
  63. package/dist/index.d.mts.map +0 -1
  64. package/dist/index.mjs.map +0 -1
  65. package/dist/journals-oH-FK3g8.mjs.map +0 -1
  66. package/dist/logger-UbTdBb1x.d.mts.map +0 -1
  67. package/dist/money.d.mts.map +0 -1
  68. package/dist/money.mjs.map +0 -1
  69. package/dist/session-Ba8E3Ufa.mjs +0 -84
  70. package/dist/session-Ba8E3Ufa.mjs.map +0 -1
@@ -1,10 +1,21 @@
1
- import { Model } from "mongoose";
1
+ import { ClientSession, Model } from "mongoose";
2
+ import { RepositoryInstance } from "@classytic/mongokit";
2
3
 
3
- //#region src/plugins/double-entry.plugin.d.ts
4
- /** Minimal interface matching @classytic/mongokit RepositoryInstance */
5
- interface RepositoryInstance$2 {
6
- on(event: string, listener: (data: unknown) => void | Promise<void>): unknown;
4
+ //#region src/plugins/date-lock.plugin.d.ts
5
+ interface DateLockPluginOptions {
6
+ /** Async function to resolve the lock date for a given org. Return null for no lock. */
7
+ getLockDate: (orgId?: unknown, session?: ClientSession) => Promise<Date | null>;
8
+ /** Mongoose model for journal entries (needed for partial updates) */
9
+ JournalEntryModel: Model<unknown>;
10
+ /** Org field name */
11
+ orgField?: string;
7
12
  }
13
+ declare function dateLockPlugin(options: DateLockPluginOptions): {
14
+ name: string;
15
+ apply(repo: RepositoryInstance): void;
16
+ };
17
+ //#endregion
18
+ //#region src/plugins/double-entry.plugin.d.ts
8
19
  interface DoubleEntryPluginOptions {
9
20
  /** Only enforce on posted entries (default: true) */
10
21
  onlyOnPost?: boolean;
@@ -17,14 +28,10 @@ interface DoubleEntryPluginOptions {
17
28
  }
18
29
  declare function doubleEntryPlugin(options?: DoubleEntryPluginOptions): {
19
30
  name: string;
20
- apply(repo: RepositoryInstance$2): void;
31
+ apply(repo: RepositoryInstance): void;
21
32
  };
22
33
  //#endregion
23
34
  //#region src/plugins/fiscal-lock.plugin.d.ts
24
- /** Minimal interface matching @classytic/mongokit RepositoryInstance */
25
- interface RepositoryInstance$1 {
26
- on(event: string, listener: (data: unknown) => void | Promise<void>): unknown;
27
- }
28
35
  interface FiscalLockPluginOptions {
29
36
  /** Mongoose model for fiscal periods */
30
37
  FiscalPeriodModel: Model<unknown>;
@@ -35,14 +42,10 @@ interface FiscalLockPluginOptions {
35
42
  }
36
43
  declare function fiscalLockPlugin(options: FiscalLockPluginOptions): {
37
44
  name: string;
38
- apply(repo: RepositoryInstance$1): void;
45
+ apply(repo: RepositoryInstance): void;
39
46
  };
40
47
  //#endregion
41
48
  //#region src/plugins/idempotency.plugin.d.ts
42
- /** Minimal interface matching @classytic/mongokit RepositoryInstance */
43
- interface RepositoryInstance {
44
- on(event: string, listener: (data: unknown) => void | Promise<void>): unknown;
45
- }
46
49
  interface IdempotencyPluginOptions {
47
50
  /** Mongoose model for journal entries */
48
51
  JournalEntryModel: Model<unknown>;
@@ -54,5 +57,4 @@ declare function idempotencyPlugin(options: IdempotencyPluginOptions): {
54
57
  apply(repo: RepositoryInstance): void;
55
58
  };
56
59
  //#endregion
57
- export { DoubleEntryPluginOptions as a, fiscalLockPlugin as i, idempotencyPlugin as n, doubleEntryPlugin as o, FiscalLockPluginOptions as r, IdempotencyPluginOptions as t };
58
- //# sourceMappingURL=idempotency.plugin-CPxPt4vX.d.mts.map
60
+ export { DoubleEntryPluginOptions as a, dateLockPlugin as c, fiscalLockPlugin as i, idempotencyPlugin as n, doubleEntryPlugin as o, FiscalLockPluginOptions as r, DateLockPluginOptions as s, IdempotencyPluginOptions as t };
@@ -49,9 +49,23 @@ interface CountryPack {
49
49
  readonly regions: readonly string[];
50
50
  /** Tax report template (e.g., CRA GST/HST return) */
51
51
  readonly taxReport?: TaxReportTemplate;
52
- /** Account code for prior retained earnings (e.g. '3660' CA, '3200' US) */
53
- readonly retainedEarningsCode?: string;
54
- /** Account code for current year net income (e.g. '3680' CA, '3210' US) */
52
+ /**
53
+ * The retained earnings account code — the account that holds accumulated
54
+ * retained earnings (e.g. '3600' CA, '3310' BD).
55
+ *
56
+ * On the balance sheet, this account is excluded from normal equity grouping
57
+ * and its balance is folded into the computed "Retained Earnings" section
58
+ * (opening RE = RE account balance + prior-year unclosed P&L).
59
+ *
60
+ * Inspired by Odoo's `equity_unaffected` account type.
61
+ */
62
+ readonly retainedEarningsAccountCode?: string;
63
+ /**
64
+ * Display code for the "Previous Years Retained Earnings" line on the
65
+ * balance sheet (e.g. '3660' for CA GIFI). Defaults to retainedEarningsAccountCode.
66
+ */
67
+ readonly retainedEarningsDisplayCode?: string;
68
+ /** Display code for current year net income line (e.g. '3680' CA, '3311' BD) */
55
69
  readonly currentYearEarningsCode?: string;
56
70
  /** Group label code used to identify Cost of Sales in the income statement */
57
71
  readonly cogsGroupCode?: string;
@@ -85,7 +99,8 @@ interface CountryPackInput {
85
99
  taxCodesByRegion: TaxCodesByRegion;
86
100
  regions: readonly string[];
87
101
  taxReport?: TaxReportTemplate;
88
- retainedEarningsCode?: string;
102
+ retainedEarningsAccountCode?: string;
103
+ retainedEarningsDisplayCode?: string;
89
104
  currentYearEarningsCode?: string;
90
105
  cogsGroupCode?: string;
91
106
  reportLabels?: {
@@ -101,5 +116,4 @@ interface CountryPackInput {
101
116
  */
102
117
  declare function defineCountryPack(input: CountryPackInput): CountryPack;
103
118
  //#endregion
104
- export { TaxReportLine as a, TaxCodesByRegion as i, CountryPackInput as n, TaxReportTemplate as o, TaxCode as r, defineCountryPack as s, CountryPack as t };
105
- //# sourceMappingURL=index-ZnSiqHYV.d.mts.map
119
+ export { TaxReportLine as a, TaxCodesByRegion as i, CountryPackInput as n, TaxReportTemplate as o, TaxCode as r, defineCountryPack as s, CountryPack as t };
@@ -121,17 +121,16 @@ declare function extractAllRows<TRow>(fieldMap: ExportFieldMap<TRow>, rows: read
121
121
  /** One-shot: map + serialize to CSV string. */
122
122
  declare function exportToCsv<TRow>(fieldMap: ExportFieldMap<TRow>, rows: readonly TRow[], options?: CsvOptions): string;
123
123
  //#endregion
124
- //#region src/exports/flatten-journal.d.ts
125
- /** Flatten a single journal entry into one FlatJournalRow per journal item. */
126
- declare function flattenJournalEntry(entry: PopulatedJournalEntry): FlatJournalRow[];
127
- /** Flatten multiple journal entries into a single flat row array. */
128
- declare function flattenJournalEntries(entries: readonly PopulatedJournalEntry[]): FlatJournalRow[];
129
- //#endregion
130
124
  //#region src/exports/field-maps/quickbooks.d.ts
131
125
  declare const quickbooksFieldMap: ExportFieldMap<FlatJournalRow>;
132
126
  //#endregion
133
127
  //#region src/exports/field-maps/universal.d.ts
134
128
  declare const universalFieldMap: ExportFieldMap<FlatJournalRow>;
135
129
  //#endregion
136
- export { PopulatedJournalEntry as _, exportToCsv as a, getHeaders as c, serializeCsv as d, CsvOptions as f, PopulatedAccount as g, FlatJournalRow as h, flattenJournalEntry as i, buildCsv as l, ExportFieldMap as m, quickbooksFieldMap as n, extractAllRows as o, ExportField as p, flattenJournalEntries as r, extractRow as s, universalFieldMap as t, escapeCell as u, PopulatedJournalItem as v };
137
- //# sourceMappingURL=index-BPukb3L8.d.mts.map
130
+ //#region src/exports/flatten-journal.d.ts
131
+ /** Flatten a single journal entry into one FlatJournalRow per journal item. */
132
+ declare function flattenJournalEntry(entry: PopulatedJournalEntry): FlatJournalRow[];
133
+ /** Flatten multiple journal entries into a single flat row array. */
134
+ declare function flattenJournalEntries(entries: readonly PopulatedJournalEntry[]): FlatJournalRow[];
135
+ //#endregion
136
+ export { PopulatedJournalEntry as _, exportToCsv as a, getHeaders as c, serializeCsv as d, CsvOptions as f, PopulatedAccount as g, FlatJournalRow as h, quickbooksFieldMap as i, buildCsv as l, ExportFieldMap as m, flattenJournalEntry as n, extractAllRows as o, ExportField as p, universalFieldMap as r, extractRow as s, flattenJournalEntries as t, escapeCell as u, PopulatedJournalItem as v };
package/dist/index.d.mts CHANGED
@@ -1,16 +1,17 @@
1
1
  import { _ as TaxMetadata, a as Cents, c as DateRange, d as JournalType, f as MainType, g as TaxDetail, h as StatementType, i as CategoryKey, l as EntryState, m as ObjectId, n as CashFlowCategory, o as Currency, p as NormalBalance, s as DateOption, t as AccountType, u as JournalItem, v as TotalAccountOp } from "./core-8Xfnpn6g.mjs";
2
- import { _ as getNormalBalance, a as JOURNAL_CODES, b as isValidCategory, c as getJournalTypeCodes, d as CATEGORY_KEYS, i as isValidCurrency, l as isValidJournalType, n as getCurrency, o as JOURNAL_TYPES, r as getMinorUnit, t as CURRENCIES, u as CATEGORIES, v as isBalanceSheet, y as isIncomeStatement } from "./currencies-4WAbFRlw.mjs";
3
- import { a as TaxReportLine, i as TaxCodesByRegion, n as CountryPackInput, o as TaxReportTemplate, r as TaxCode, s as defineCountryPack, t as CountryPack } from "./index-ZnSiqHYV.mjs";
4
- import { _ as PopulatedJournalEntry, a as exportToCsv, h as FlatJournalRow, m as ExportFieldMap, n as quickbooksFieldMap, p as ExportField, r as flattenJournalEntries, t as universalFieldMap } from "./index-BPukb3L8.mjs";
2
+ import { S as isValidCategory, a as getJournalTypeCodes, b as isBalanceSheet, c as CURRENCIES, d as isValidCurrency, f as CATEGORIES, i as getJournalType, l as getCurrency, n as JOURNAL_TYPES, o as isValidJournalType, p as CATEGORY_KEYS, r as getCustomJournalTypes, s as registerJournalType, t as JOURNAL_CODES, u as getMinorUnit, x as isIncomeStatement, y as getNormalBalance } from "./journals-DTipb_rz.mjs";
3
+ import { a as TaxReportLine, i as TaxCodesByRegion, n as CountryPackInput, o as TaxReportTemplate, r as TaxCode, s as defineCountryPack, t as CountryPack } from "./index-CxZqRaOU.mjs";
4
+ import { _ as PopulatedJournalEntry, a as exportToCsv, h as FlatJournalRow, i as quickbooksFieldMap, m as ExportFieldMap, p as ExportField, r as universalFieldMap, t as flattenJournalEntries } from "./index-J-XIbXH-.mjs";
5
5
  import { Money, abs, add, allocate, equals, format, formatPlain, fromDecimal, isNegative, isPositive, isValid, isZero, max, min, multiply, negate, parseCents, percentage, round, splitTaxExclusive, splitTaxInclusive, subtract, toDecimal } from "./money.mjs";
6
6
  import { n as defaultLogger, t as Logger } from "./logger-UbTdBb1x.mjs";
7
- import { a as MultiTenantConfig, i as MultiCurrencyConfig, n as AuditConfig, o as SchemaOptions, r as JournalSchemaOptions, s as StrictnessConfig, t as AccountingEngineConfig } from "./engine-BzBMpWuy.mjs";
8
- import { n as createJournalEntrySchema, r as createAccountSchema, t as createFiscalPeriodSchema } from "./fiscal-period.schema-BRdKAjrr.mjs";
9
- import { i as fiscalLockPlugin, n as idempotencyPlugin, o as doubleEntryPlugin } from "./idempotency.plugin-CPxPt4vX.mjs";
10
- import { C as ReportAccount, D as TaxReturnSummary, E as TaxReport, O as TrialBalanceReport, S as LedgerEntry, T as ReportGroup, _ as CashFlowReport, a as reopenFiscalPeriod, b as GeneralLedgerReport, d as generateIncomeStatement, g as BalanceSheetReport, h as generateTrialBalance, i as closeFiscalPeriod, k as TrialBalanceRow, l as generateGeneralLedger, p as generateBalanceSheet, s as generateCashFlow, v as CashFlowSection, w as ReportCategory, x as IncomeStatementReport, y as GeneralLedgerAccount } from "./fiscal-close-dNlzB37y.mjs";
11
- import { n as wireJournalEntryMethods, t as wireAccountMethods } from "./account.repository-C7gwFLfM.mjs";
7
+ import { a as MultiTenantConfig, i as MultiCurrencyConfig, n as AuditConfig, o as SchemaOptions, r as JournalSchemaOptions, s as StrictnessConfig, t as AccountingEngineConfig } from "./engine-DF-MtsEr.mjs";
8
+ import { a as BulkCreateInput, c as PostOptions, d as ReverseOptions, f as ReverseResult, i as AccountRepository, l as ReconcileParams, m as SeedResult, n as wireJournalEntryMethods, o as BulkCreateResult, p as SeedOptions, r as wireAccountMethods, s as JournalEntryRepository, t as wireReconciliationMethods, u as ReconciliationRepository } from "./reconciliation.repository-DEybU_Ok.mjs";
9
+ import { n as createFiscalPeriodSchema, r as createAccountSchema, t as createJournalEntrySchema } from "./journal-entry.schema-B1CzLwC3.mjs";
10
+ import { c as dateLockPlugin, i as fiscalLockPlugin, n as idempotencyPlugin, o as doubleEntryPlugin } from "./idempotency.plugin-zU-GKJ0-.mjs";
11
+ import { $ as AgedBucketConfig, A as BudgetVsActualReport, B as IncomeStatementReport, C as DimensionBreakdownReport, D as generateCashFlow, F as BalanceSheetReport, G as TaxReport, H as ReportAccount, I as CashFlowReport, J as TrialBalanceRow, K as TaxReturnSummary, L as CashFlowSection, M as generateBudgetVsActual, O as BudgetVsActualOptions, P as generateBalanceSheet, Q as AgedBalanceRow, R as GeneralLedgerAccount, S as DimensionBreakdownParams, T as generateDimensionBreakdown, U as ReportCategory, V as LedgerEntry, W as ReportGroup, X as AgedBalanceParams, Y as AgedBalanceOptions, Z as AgedBalanceReport, a as RevaluationReport, b as reopenFiscalPeriod, c as RevaluationRate, d as computeRevaluation, et as DEFAULT_BUCKETS, h as generateGeneralLedger, i as RevaluationParams, j as BudgetVsActualRow, k as BudgetVsActualParams, l as RevaluationResult, n as generateTrialBalance, o as generateRevaluation, p as generateIncomeStatement, q as TrialBalanceReport, r as RevaluationOptions, s as AccountForeignBalance, tt as generateAgedBalance, u as buildRevaluationEntry, w as DimensionBreakdownRow, x as DimensionBreakdownOptions, y as closeFiscalPeriod, z as GeneralLedgerReport } from "./trial-balance-DcQ0xj_4.mjs";
12
12
  import * as mongoose$1 from "mongoose";
13
13
  import { ClientSession, Connection, Model } from "mongoose";
14
+ import { PluginType, Repository } from "@classytic/mongokit";
14
15
 
15
16
  //#region src/engine.d.ts
16
17
  declare class AccountingEngine {
@@ -44,34 +45,163 @@ declare class AccountingEngine {
44
45
  constructor(config: AccountingEngineConfig);
45
46
  createAccountSchema(options?: SchemaOptions): mongoose$1.Schema<any, Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
46
47
  timestamps: true;
47
- }, any, any, unknown, {
48
+ }, {
49
+ [x: number]: any;
48
50
  [x: string]: any;
49
- } & Required<{
50
- _id: unknown;
51
- }> & {
51
+ } & mongoose$1.DefaultTimestampProps, mongoose$1.Document<unknown, {}, {
52
+ [x: number]: any;
53
+ [x: string]: any;
54
+ } & mongoose$1.DefaultTimestampProps, {
55
+ id: string;
56
+ }, Omit<mongoose$1.DefaultSchemaOptions, "timestamps"> & {
57
+ timestamps: true;
58
+ }> & Omit<{
59
+ [x: number]: any;
60
+ [x: string]: any;
61
+ } & mongoose$1.DefaultTimestampProps & {
62
+ _id: mongoose$1.Types.ObjectId;
63
+ } & {
64
+ __v: number;
65
+ }, "id"> & {
66
+ id: string;
67
+ }, unknown, {
68
+ [x: number]: any;
69
+ [x: string]: any;
70
+ createdAt: NativeDate;
71
+ updatedAt: NativeDate;
72
+ } & {
73
+ _id: mongoose$1.Types.ObjectId;
74
+ } & {
52
75
  __v: number;
53
76
  }>;
54
77
  createJournalEntrySchema(accountModelName: string, options?: JournalSchemaOptions): mongoose$1.Schema<any, Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
55
78
  timestamps: true;
56
- }, any, any, unknown, {
79
+ }, {
80
+ [x: number]: any;
81
+ [x: string]: any;
82
+ } & mongoose$1.DefaultTimestampProps, mongoose$1.Document<unknown, {}, {
83
+ [x: number]: any;
84
+ [x: string]: any;
85
+ } & mongoose$1.DefaultTimestampProps, {
86
+ id: string;
87
+ }, Omit<mongoose$1.DefaultSchemaOptions, "timestamps"> & {
88
+ timestamps: true;
89
+ }> & Omit<{
90
+ [x: number]: any;
57
91
  [x: string]: any;
58
- } & Required<{
59
- _id: unknown;
60
- }> & {
92
+ } & mongoose$1.DefaultTimestampProps & {
93
+ _id: mongoose$1.Types.ObjectId;
94
+ } & {
95
+ __v: number;
96
+ }, "id"> & {
97
+ id: string;
98
+ }, unknown, {
99
+ [x: number]: any;
100
+ [x: string]: any;
101
+ createdAt: NativeDate;
102
+ updatedAt: NativeDate;
103
+ } & {
104
+ _id: mongoose$1.Types.ObjectId;
105
+ } & {
61
106
  __v: number;
62
107
  }>;
63
108
  createFiscalPeriodSchema(options?: SchemaOptions): mongoose$1.Schema<any, Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
64
109
  timestamps: true;
65
- }, any, any, unknown, {
110
+ }, {
111
+ [x: number]: any;
112
+ [x: string]: any;
113
+ } & mongoose$1.DefaultTimestampProps, mongoose$1.Document<unknown, {}, {
114
+ [x: number]: any;
115
+ [x: string]: any;
116
+ } & mongoose$1.DefaultTimestampProps, {
117
+ id: string;
118
+ }, Omit<mongoose$1.DefaultSchemaOptions, "timestamps"> & {
119
+ timestamps: true;
120
+ }> & Omit<{
121
+ [x: number]: any;
122
+ [x: string]: any;
123
+ } & mongoose$1.DefaultTimestampProps & {
124
+ _id: mongoose$1.Types.ObjectId;
125
+ } & {
126
+ __v: number;
127
+ }, "id"> & {
128
+ id: string;
129
+ }, unknown, {
130
+ [x: number]: any;
66
131
  [x: string]: any;
67
- } & Required<{
68
- _id: unknown;
69
- }> & {
132
+ createdAt: NativeDate;
133
+ updatedAt: NativeDate;
134
+ } & {
135
+ _id: mongoose$1.Types.ObjectId;
136
+ } & {
137
+ __v: number;
138
+ }>;
139
+ createBudgetSchema(options?: SchemaOptions): mongoose$1.Schema<any, Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
140
+ timestamps: true;
141
+ }, {
142
+ [x: number]: any;
143
+ [x: string]: any;
144
+ } & mongoose$1.DefaultTimestampProps, mongoose$1.Document<unknown, {}, {
145
+ [x: number]: any;
146
+ [x: string]: any;
147
+ } & mongoose$1.DefaultTimestampProps, {
148
+ id: string;
149
+ }, Omit<mongoose$1.DefaultSchemaOptions, "timestamps"> & {
150
+ timestamps: true;
151
+ }> & Omit<{
152
+ [x: number]: any;
153
+ [x: string]: any;
154
+ } & mongoose$1.DefaultTimestampProps & {
155
+ _id: mongoose$1.Types.ObjectId;
156
+ } & {
157
+ __v: number;
158
+ }, "id"> & {
159
+ id: string;
160
+ }, unknown, {
161
+ [x: number]: any;
162
+ [x: string]: any;
163
+ createdAt: NativeDate;
164
+ updatedAt: NativeDate;
165
+ } & {
166
+ _id: mongoose$1.Types.ObjectId;
167
+ } & {
168
+ __v: number;
169
+ }>;
170
+ createReconciliationSchema(accountModelName: string, journalEntryModelName: string, options?: SchemaOptions): mongoose$1.Schema<any, Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
171
+ timestamps: true;
172
+ }, {
173
+ [x: number]: any;
174
+ [x: string]: any;
175
+ } & mongoose$1.DefaultTimestampProps, mongoose$1.Document<unknown, {}, {
176
+ [x: number]: any;
177
+ [x: string]: any;
178
+ } & mongoose$1.DefaultTimestampProps, {
179
+ id: string;
180
+ }, Omit<mongoose$1.DefaultSchemaOptions, "timestamps"> & {
181
+ timestamps: true;
182
+ }> & Omit<{
183
+ [x: number]: any;
184
+ [x: string]: any;
185
+ } & mongoose$1.DefaultTimestampProps & {
186
+ _id: mongoose$1.Types.ObjectId;
187
+ } & {
188
+ __v: number;
189
+ }, "id"> & {
190
+ id: string;
191
+ }, unknown, {
192
+ [x: number]: any;
193
+ [x: string]: any;
194
+ createdAt: NativeDate;
195
+ updatedAt: NativeDate;
196
+ } & {
197
+ _id: mongoose$1.Types.ObjectId;
198
+ } & {
70
199
  __v: number;
71
200
  }>;
72
201
  createReports(models: {
73
202
  Account: Model<unknown>;
74
203
  JournalEntry: Model<unknown>;
204
+ Budget?: Model<unknown>;
75
205
  }): {
76
206
  trialBalance: (params: {
77
207
  organizationId?: unknown;
@@ -108,6 +238,44 @@ declare class AccountingEngine {
108
238
  businessName?: string;
109
239
  filters?: Record<string, unknown>;
110
240
  }) => Promise<CashFlowReport>;
241
+ agedBalance: (params: {
242
+ organizationId?: unknown;
243
+ asOfDate?: Date;
244
+ type: "receivable" | "payable";
245
+ accountIds?: unknown[];
246
+ dueDateField?: string;
247
+ contactField?: string;
248
+ buckets?: Array<{
249
+ label: string;
250
+ minDays: number;
251
+ maxDays: number;
252
+ }>;
253
+ }) => Promise<AgedBalanceReport>;
254
+ dimensionBreakdown: (params: {
255
+ organizationId?: unknown;
256
+ dateOption: "month" | "quarter" | "year" | "custom";
257
+ dateValue: unknown;
258
+ dimension: string;
259
+ accountCategory?: string;
260
+ filters?: Record<string, unknown>;
261
+ }) => Promise<DimensionBreakdownReport>;
262
+ budgetVsActual: (params: {
263
+ organizationId?: unknown;
264
+ dateOption: "month" | "quarter" | "year" | "custom";
265
+ dateValue: unknown;
266
+ accountIds?: unknown[];
267
+ filters?: Record<string, unknown>;
268
+ }) => Promise<BudgetVsActualReport>;
269
+ revaluation: (params: {
270
+ organizationId?: unknown;
271
+ asOfDate: Date;
272
+ rates: Array<{
273
+ currency: string;
274
+ rate: number;
275
+ }>;
276
+ unrealizedGainLossAccountId: unknown;
277
+ generateEntry?: boolean;
278
+ }) => Promise<RevaluationReport>;
111
279
  };
112
280
  /** Get all posting account types (accounts you can post transactions to) */
113
281
  getPostingAccountTypes(): readonly AccountType[];
@@ -133,11 +301,11 @@ declare class AccountingEngine {
133
301
  * @param additionalPlugins - Extra plugins to include (e.g. timestampPlugin)
134
302
  * @returns A wired repository with post(), unpost(), reverse(), duplicate(), and all plugins configured
135
303
  */
136
- createJournalEntryRepository(createRepository: (model: Model<unknown>, plugins: any[]) => any, models: {
137
- JournalEntryModel: Model<unknown>;
304
+ createJournalEntryRepository<TDoc = unknown>(createRepository: (model: Model<TDoc>, plugins: PluginType[]) => Repository<TDoc>, models: {
305
+ JournalEntryModel: Model<TDoc>;
138
306
  AccountModel: Model<unknown>;
139
307
  FiscalPeriodModel?: Model<unknown>;
140
- }, additionalPlugins?: any[]): any;
308
+ }, additionalPlugins?: PluginType[]): JournalEntryRepository<TDoc>;
141
309
  /**
142
310
  * Wire post/reverse domain methods onto a mongokit Repository
143
311
  * for journal entries. The repository must already be created via
@@ -151,7 +319,7 @@ declare class AccountingEngine {
151
319
  * @param JournalEntryModel - The Mongoose model for journal entries
152
320
  * @returns The same repository, now with `.post()` and `.reverse()`
153
321
  */
154
- wireJournalEntryRepository(repository: any, JournalEntryModel: Model<unknown>): any;
322
+ wireJournalEntryRepository<TDoc = unknown>(repository: Repository<TDoc>, JournalEntryModel: Model<unknown>): JournalEntryRepository<TDoc>;
155
323
  /**
156
324
  * Wire seedAccounts/bulkCreate and posting-account validation onto a
157
325
  * mongokit Repository for accounts. The repository must already be
@@ -161,24 +329,14 @@ declare class AccountingEngine {
161
329
  * @param AccountModel - The Mongoose model for accounts
162
330
  * @returns The same repository, now with `.seedAccounts()` and `.bulkCreate()`
163
331
  */
164
- wireAccountRepository(repository: any, AccountModel: Model<unknown>): any;
332
+ wireAccountRepository<TDoc = unknown>(repository: Repository<TDoc>, AccountModel: Model<unknown>): AccountRepository<TDoc>;
333
+ /**
334
+ * Wire reconcile/unreconcile/getUnreconciled methods onto a mongokit Repository.
335
+ */
336
+ wireReconciliationRepository<TDoc = unknown>(repository: Repository<TDoc>, ReconciliationModel: Model<unknown>, JournalEntryModel: Model<unknown>): ReconciliationRepository<TDoc>;
165
337
  }
166
338
  declare function createAccountingEngine(config: AccountingEngineConfig): AccountingEngine;
167
339
  //#endregion
168
- //#region src/utils/date-range.d.ts
169
- /**
170
- * Compute start/end dates from a date option + value.
171
- *
172
- * Examples:
173
- * getDateRange('month', '2025-03') → Mar 1 – Mar 31
174
- * getDateRange('quarter', { quarter: 2, year: 2025 }) → Apr 1 – Jun 30
175
- * getDateRange('year', 2025) → Jan 1 – Dec 31
176
- * getDateRange('custom', { startDate, endDate })
177
- */
178
- declare function getDateRange(option: DateOption, value: unknown): DateRange;
179
- /** Get fiscal year start date for a given date and fiscal start month */
180
- declare function getFiscalYearStart(date: Date, fiscalStartMonth?: number): Date;
181
- //#endregion
182
340
  //#region src/utils/account-helpers.d.ts
183
341
  /**
184
342
  * Check if an account type is a virtual tax sub-account.
@@ -205,6 +363,71 @@ declare function computeEndingBalance(category: CategoryKey, totalDebit: number,
205
363
  */
206
364
  declare function buildAccountTypeMap(accountTypes: readonly AccountType[]): Map<string, AccountType>;
207
365
  //#endregion
366
+ //#region src/utils/date-range.d.ts
367
+ /**
368
+ * Compute start/end dates from a date option + value.
369
+ *
370
+ * @throws {Error} If value is null/undefined/invalid for the given option
371
+ *
372
+ * Examples:
373
+ * getDateRange('month', '2025-03') → Mar 1 – Mar 31
374
+ * getDateRange('quarter', { quarter: 2, year: 2025 }) → Apr 1 – Jun 30
375
+ * getDateRange('year', 2025) → Jan 1 – Dec 31
376
+ * getDateRange('custom', { startDate, endDate })
377
+ */
378
+ declare function getDateRange(option: DateOption, value: unknown): DateRange;
379
+ /** Get fiscal year start date for a given date and fiscal start month */
380
+ declare function getFiscalYearStart(date: Date, fiscalStartMonth?: number): Date;
381
+ //#endregion
382
+ //#region src/utils/dimensions.d.ts
383
+ /**
384
+ * Analytic Dimensions — Helpers for defining analytic dimensions
385
+ * (department, project, cost center) on journal items.
386
+ *
387
+ * Generates Mongoose schema fields and indexes for dimension queries.
388
+ */
389
+ interface DimensionDefinition {
390
+ /** Field name on the journal item, e.g. 'departmentId' */
391
+ field: string;
392
+ /** Human-readable label, e.g. 'Department' */
393
+ label: string;
394
+ /** Mongoose model ref for population, e.g. 'Department' */
395
+ ref?: string;
396
+ /** Whether the field is required (default: false) */
397
+ required?: boolean;
398
+ }
399
+ /**
400
+ * Build extraItemFields schema definition for a set of dimensions.
401
+ *
402
+ * Returns a Mongoose schema-compatible object suitable for spreading into
403
+ * `extraItemFields` in JournalSchemaOptions.
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * const fields = buildDimensionFields([
408
+ * { field: 'departmentId', label: 'Department', ref: 'Department' },
409
+ * { field: 'projectId', label: 'Project', ref: 'Project' },
410
+ * ]);
411
+ * // => { departmentId: { type: Schema.Types.ObjectId, ref: 'Department', required: false, default: null }, ... }
412
+ * ```
413
+ */
414
+ declare function buildDimensionFields(dimensions: DimensionDefinition[]): Record<string, unknown>;
415
+ /**
416
+ * Build extra indexes for dimension queries.
417
+ *
418
+ * Each dimension gets a compound index on `journalItems.{field}` + `date`
419
+ * for efficient filtered reporting. When `orgField` is provided, it is
420
+ * prepended to each index for multi-tenant scoping.
421
+ *
422
+ * @param dimensions - Array of dimension definitions
423
+ * @param orgField - Optional org-scoping field name (e.g. 'business')
424
+ * @returns Array of index specifications compatible with `extraIndexes` in JournalSchemaOptions
425
+ */
426
+ declare function buildDimensionIndexes(dimensions: DimensionDefinition[], orgField?: string): Array<{
427
+ fields: Record<string, 1 | -1>;
428
+ options?: Record<string, unknown>;
429
+ }>;
430
+ //#endregion
208
431
  //#region src/utils/errors.d.ts
209
432
  /**
210
433
  * Typed error for the accounting package.
@@ -225,6 +448,23 @@ declare const Errors: {
225
448
  readonly fiscal: (msg: string) => AccountingError;
226
449
  };
227
450
  //#endregion
451
+ //#region src/utils/filter-builder.d.ts
452
+ /**
453
+ * Filter Builder — Sanitizes user-supplied dimension filters for aggregation pipelines.
454
+ *
455
+ * Prevents injection of dangerous MongoDB operators while allowing
456
+ * standard equality and comparison filters on custom dimension fields.
457
+ */
458
+ /**
459
+ * Build a sanitized filter object from user-supplied dimension filters.
460
+ * Blocks dangerous operators ($where, $expr, $function, etc.).
461
+ *
462
+ * @param filters - Key-value filters (e.g. { 'journalItems.departmentId': 'dept-1' })
463
+ * @returns Sanitized filter object safe for $match stages
464
+ * @throws Error if a blocked operator is used
465
+ */
466
+ declare function buildItemFilters(filters?: Record<string, unknown>): Record<string, unknown>;
467
+ //#endregion
228
468
  //#region src/utils/session.d.ts
229
469
  interface SessionResult {
230
470
  session: ClientSession | null;
@@ -243,23 +483,6 @@ declare function acquireSession(db: Connection, externalSession: ClientSession |
243
483
  */
244
484
  declare function finalizeSession(session: ClientSession | null, ownSession: boolean, success: boolean): Promise<void>;
245
485
  //#endregion
246
- //#region src/utils/filter-builder.d.ts
247
- /**
248
- * Filter Builder — Sanitizes user-supplied dimension filters for aggregation pipelines.
249
- *
250
- * Prevents injection of dangerous MongoDB operators while allowing
251
- * standard equality and comparison filters on custom dimension fields.
252
- */
253
- /**
254
- * Build a sanitized filter object from user-supplied dimension filters.
255
- * Blocks dangerous operators ($where, $expr, $function, etc.).
256
- *
257
- * @param filters - Key-value filters (e.g. { 'journalItems.departmentId': 'dept-1' })
258
- * @returns Sanitized filter object safe for $match stages
259
- * @throws Error if a blocked operator is used
260
- */
261
- declare function buildItemFilters(filters?: Record<string, unknown>): Record<string, unknown>;
262
- //#endregion
263
486
  //#region src/types/contracts.d.ts
264
487
  /** A single line produced by a subledger for posting */
265
488
  interface SubledgerJournalItem {
@@ -304,5 +527,4 @@ interface PostingResult {
304
527
  idempotencyKeys?: string[];
305
528
  }
306
529
  //#endregion
307
- export { type AccountType, AccountingEngine, type AccountingEngineConfig, AccountingError, type AuditConfig, type BalanceSheetReport, CATEGORIES, CATEGORY_KEYS, CURRENCIES, type CashFlowCategory, type CashFlowReport, type CashFlowSection, type CategoryKey, type Cents, type CountryPack, type CountryPackInput, type Currency, type DateOption, type DateRange, type EntryState, Errors, type ExportField, type ExportFieldMap, type FlatJournalRow, type GeneralLedgerAccount, type GeneralLedgerReport, type IncomeStatementReport, JOURNAL_CODES, JOURNAL_TYPES, type JournalItem, type JournalSchemaOptions, type JournalType, type LedgerEntry, type Logger, type MainType, Money, type MultiCurrencyConfig, type MultiTenantConfig, type NormalBalance, type PopulatedJournalEntry, type PostingContract, type PostingResult, type ReportAccount, type ReportCategory, type ReportGroup, type SchemaOptions, type SessionResult, type StatementType, type StrictnessConfig, type SubledgerJournalItem, type SubledgerPostingInput, type TaxCode, type TaxCodesByRegion, type TaxDetail, type TaxMetadata, type TaxReport, type TaxReportLine, type TaxReportTemplate, type TaxReturnSummary, type TotalAccountOp, type TrialBalanceReport, type TrialBalanceRow, acquireSession, add, allocate, buildAccountTypeMap, buildItemFilters, calculateTotal, closeFiscalPeriod, computeEndingBalance, createAccountSchema, createAccountingEngine, createFiscalPeriodSchema, createJournalEntrySchema, defaultLogger, defineCountryPack, doubleEntryPlugin, exportToCsv, finalizeSession, fiscalLockPlugin, flattenJournalEntries, format, formatPlain, fromDecimal, generateBalanceSheet, generateCashFlow, generateGeneralLedger, generateIncomeStatement, generateTrialBalance, getCurrency, getDateRange, getFiscalYearStart, getJournalTypeCodes, getMinorUnit, getNormalBalance, idempotencyPlugin, isBalanceSheet, isIncomeStatement, isValidCategory, isValidCurrency, isValidJournalType, isVirtualTaxAccount, multiply, parseCents, percentage, quickbooksFieldMap, reopenFiscalPeriod, splitTaxExclusive, splitTaxInclusive, subtract, toDecimal, universalFieldMap, wireAccountMethods, wireJournalEntryMethods };
308
- //# sourceMappingURL=index.d.mts.map
530
+ export { type AccountForeignBalance, type AccountRepository, type AccountType, AccountingEngine, type AccountingEngineConfig, AccountingError, type AgedBalanceOptions, type AgedBalanceParams, type AgedBalanceReport, type AgedBalanceRow, type AgedBucketConfig, type AuditConfig, type BalanceSheetReport, type BudgetVsActualOptions, type BudgetVsActualParams, type BudgetVsActualReport, type BudgetVsActualRow, type BulkCreateInput, type BulkCreateResult, CATEGORIES, CATEGORY_KEYS, CURRENCIES, type CashFlowCategory, type CashFlowReport, type CashFlowSection, type CategoryKey, type Cents, type CountryPack, type CountryPackInput, type Currency, DEFAULT_BUCKETS, type DateOption, type DateRange, type DimensionBreakdownOptions, type DimensionBreakdownParams, type DimensionBreakdownReport, type DimensionBreakdownRow, type DimensionDefinition, type EntryState, Errors, type ExportField, type ExportFieldMap, type FlatJournalRow, type GeneralLedgerAccount, type GeneralLedgerReport, type IncomeStatementReport, JOURNAL_CODES, JOURNAL_TYPES, type JournalEntryRepository, type JournalItem, type JournalSchemaOptions, type JournalType, type LedgerEntry, type Logger, type MainType, Money, type MultiCurrencyConfig, type MultiTenantConfig, type NormalBalance, type PopulatedJournalEntry, type PostOptions, type PostingContract, type PostingResult, type ReconcileParams, type ReconciliationRepository, type ReportAccount, type ReportCategory, type ReportGroup, type RevaluationOptions, type RevaluationParams, type RevaluationRate, type RevaluationReport, type RevaluationResult, type ReverseOptions, type ReverseResult, type SchemaOptions, type SeedOptions, type SeedResult, type SessionResult, type StatementType, type StrictnessConfig, type SubledgerJournalItem, type SubledgerPostingInput, type TaxCode, type TaxCodesByRegion, type TaxDetail, type TaxMetadata, type TaxReport, type TaxReportLine, type TaxReportTemplate, type TaxReturnSummary, type TotalAccountOp, type TrialBalanceReport, type TrialBalanceRow, acquireSession, add, allocate, buildAccountTypeMap, buildDimensionFields, buildDimensionIndexes, buildItemFilters, buildRevaluationEntry, calculateTotal, closeFiscalPeriod, computeEndingBalance, computeRevaluation, createAccountSchema, createAccountingEngine, createFiscalPeriodSchema, createJournalEntrySchema, dateLockPlugin, defaultLogger, defineCountryPack, doubleEntryPlugin, exportToCsv, finalizeSession, fiscalLockPlugin, flattenJournalEntries, format, formatPlain, fromDecimal, generateAgedBalance, generateBalanceSheet, generateBudgetVsActual, generateCashFlow, generateDimensionBreakdown, generateGeneralLedger, generateIncomeStatement, generateRevaluation, generateTrialBalance, getCurrency, getCustomJournalTypes, getDateRange, getFiscalYearStart, getJournalType, getJournalTypeCodes, getMinorUnit, getNormalBalance, idempotencyPlugin, isBalanceSheet, isIncomeStatement, isValidCategory, isValidCurrency, isValidJournalType, isVirtualTaxAccount, multiply, parseCents, percentage, quickbooksFieldMap, registerJournalType, reopenFiscalPeriod, splitTaxExclusive, splitTaxInclusive, subtract, toDecimal, universalFieldMap, wireAccountMethods, wireJournalEntryMethods, wireReconciliationMethods };