@classytic/ledger 0.2.0 → 0.3.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 (66) hide show
  1. package/README.md +161 -64
  2. package/dist/{account.repository-kDKwDt0I.mjs → account.repository-BpkSd6q3.mjs} +189 -38
  3. package/dist/categories-CclX7Q94.mjs +0 -2
  4. package/dist/core-8Xfnpn6g.d.mts +1 -2
  5. package/dist/country/index.d.mts +1 -1
  6. package/dist/country/index.mjs +0 -2
  7. package/dist/currencies-4WAbFRlw.d.mts +1 -2
  8. package/dist/currencies-W8kQAkm0.mjs +0 -2
  9. package/dist/{idempotency.plugin-v9NQ_ta-.mjs → date-lock.plugin-eYAJ9h_u.mjs} +49 -9
  10. package/dist/{engine-BzBMpWuy.d.mts → engine-Cn-9yerQ.d.mts} +11 -7
  11. package/dist/errors-B7yC-Jfw.mjs +0 -2
  12. package/dist/exports-I5Xkq-9_.mjs +0 -2
  13. package/dist/{fiscal-close-L631E3De.mjs → fiscal-close-B6LhQ10f.mjs} +737 -20
  14. package/dist/fiscal-period.schema-BMnlI9H5.d.mts +103 -0
  15. package/dist/{idempotency.plugin-CPxPt4vX.d.mts → idempotency.plugin-B_CNsInz.d.mts} +19 -17
  16. package/dist/index-BPukb3L8.d.mts +1 -2
  17. package/dist/{index-ZnSiqHYV.d.mts → index-CxZqRaOU.d.mts} +20 -6
  18. package/dist/index.d.mts +248 -26
  19. package/dist/index.mjs +119 -21
  20. package/dist/journals-oH-FK3g8.mjs +0 -2
  21. package/dist/{logger-UbTdBb1x.d.mts → logger-CbHWZl7v.d.mts} +1 -2
  22. package/dist/money.d.mts +1 -2
  23. package/dist/money.mjs +3 -3
  24. package/dist/plugins/index.d.mts +38 -2
  25. package/dist/plugins/index.mjs +57 -2
  26. package/dist/reconciliation.repository-CW4-8q90.d.mts +135 -0
  27. package/dist/{fiscal-period.schema-BQ5wsAq3.mjs → reconciliation.schema-BuetvZTd.mjs} +168 -24
  28. package/dist/reports/index.d.mts +2 -2
  29. package/dist/reports/index.mjs +2 -2
  30. package/dist/repositories/index.d.mts +2 -2
  31. package/dist/repositories/index.mjs +2 -2
  32. package/dist/revaluation-D9x0NE8w.d.mts +530 -0
  33. package/dist/schemas/index.d.mts +71 -2
  34. package/dist/schemas/index.mjs +2 -2
  35. package/dist/tenant-guard-Fm6AID_6.mjs +13 -0
  36. package/docs/reports.md +1 -1
  37. package/package.json +2 -2
  38. package/dist/account.repository-C7gwFLfM.d.mts +0 -29
  39. package/dist/account.repository-C7gwFLfM.d.mts.map +0 -1
  40. package/dist/account.repository-kDKwDt0I.mjs.map +0 -1
  41. package/dist/categories-CclX7Q94.mjs.map +0 -1
  42. package/dist/core-8Xfnpn6g.d.mts.map +0 -1
  43. package/dist/country/index.mjs.map +0 -1
  44. package/dist/currencies-4WAbFRlw.d.mts.map +0 -1
  45. package/dist/currencies-W8kQAkm0.mjs.map +0 -1
  46. package/dist/engine-BzBMpWuy.d.mts.map +0 -1
  47. package/dist/errors-B7yC-Jfw.mjs.map +0 -1
  48. package/dist/exports-I5Xkq-9_.mjs.map +0 -1
  49. package/dist/fiscal-close-L631E3De.mjs.map +0 -1
  50. package/dist/fiscal-close-dNlzB37y.d.mts +0 -270
  51. package/dist/fiscal-close-dNlzB37y.d.mts.map +0 -1
  52. package/dist/fiscal-period.schema-BQ5wsAq3.mjs.map +0 -1
  53. package/dist/fiscal-period.schema-BRdKAjrr.d.mts +0 -38
  54. package/dist/fiscal-period.schema-BRdKAjrr.d.mts.map +0 -1
  55. package/dist/idempotency.plugin-CPxPt4vX.d.mts.map +0 -1
  56. package/dist/idempotency.plugin-v9NQ_ta-.mjs.map +0 -1
  57. package/dist/index-BPukb3L8.d.mts.map +0 -1
  58. package/dist/index-ZnSiqHYV.d.mts.map +0 -1
  59. package/dist/index.d.mts.map +0 -1
  60. package/dist/index.mjs.map +0 -1
  61. package/dist/journals-oH-FK3g8.mjs.map +0 -1
  62. package/dist/logger-UbTdBb1x.d.mts.map +0 -1
  63. package/dist/money.d.mts.map +0 -1
  64. package/dist/money.mjs.map +0 -1
  65. package/dist/session-Ba8E3Ufa.mjs +0 -84
  66. package/dist/session-Ba8E3Ufa.mjs.map +0 -1
@@ -0,0 +1,103 @@
1
+ import { o as SchemaOptions, r as JournalSchemaOptions, t as AccountingEngineConfig } from "./engine-Cn-9yerQ.mjs";
2
+ import mongoose from "mongoose";
3
+
4
+ //#region src/schemas/account.schema.d.ts
5
+ declare function createAccountSchema(config: AccountingEngineConfig, options?: SchemaOptions): mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
6
+ timestamps: true;
7
+ }, {
8
+ [x: number]: any;
9
+ [x: string]: any;
10
+ } & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
11
+ [x: number]: any;
12
+ [x: string]: any;
13
+ } & mongoose.DefaultTimestampProps, {
14
+ id: string;
15
+ }, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
16
+ timestamps: true;
17
+ }>> & Omit<{
18
+ [x: number]: any;
19
+ [x: string]: any;
20
+ } & mongoose.DefaultTimestampProps & {
21
+ _id: mongoose.Types.ObjectId;
22
+ } & {
23
+ __v: number;
24
+ }, "id"> & {
25
+ id: string;
26
+ }, unknown, {
27
+ [x: number]: any;
28
+ [x: string]: any;
29
+ createdAt: NativeDate;
30
+ updatedAt: NativeDate;
31
+ } & {
32
+ _id: mongoose.Types.ObjectId;
33
+ } & {
34
+ __v: number;
35
+ }>;
36
+ //#endregion
37
+ //#region src/schemas/journal-entry.schema.d.ts
38
+ declare function createJournalEntrySchema(config: AccountingEngineConfig, accountModelName: string, options?: JournalSchemaOptions): mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
39
+ timestamps: true;
40
+ }, {
41
+ [x: number]: any;
42
+ [x: string]: any;
43
+ } & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
44
+ [x: number]: any;
45
+ [x: string]: any;
46
+ } & mongoose.DefaultTimestampProps, {
47
+ id: string;
48
+ }, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
49
+ timestamps: true;
50
+ }>> & Omit<{
51
+ [x: number]: any;
52
+ [x: string]: any;
53
+ } & mongoose.DefaultTimestampProps & {
54
+ _id: mongoose.Types.ObjectId;
55
+ } & {
56
+ __v: number;
57
+ }, "id"> & {
58
+ id: string;
59
+ }, unknown, {
60
+ [x: number]: any;
61
+ [x: string]: any;
62
+ createdAt: NativeDate;
63
+ updatedAt: NativeDate;
64
+ } & {
65
+ _id: mongoose.Types.ObjectId;
66
+ } & {
67
+ __v: number;
68
+ }>;
69
+ //#endregion
70
+ //#region src/schemas/fiscal-period.schema.d.ts
71
+ declare function createFiscalPeriodSchema(config: AccountingEngineConfig, options?: SchemaOptions): mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
72
+ timestamps: true;
73
+ }, {
74
+ [x: number]: any;
75
+ [x: string]: any;
76
+ } & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
77
+ [x: number]: any;
78
+ [x: string]: any;
79
+ } & mongoose.DefaultTimestampProps, {
80
+ id: string;
81
+ }, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
82
+ timestamps: true;
83
+ }>> & Omit<{
84
+ [x: number]: any;
85
+ [x: string]: any;
86
+ } & mongoose.DefaultTimestampProps & {
87
+ _id: mongoose.Types.ObjectId;
88
+ } & {
89
+ __v: number;
90
+ }, "id"> & {
91
+ id: string;
92
+ }, unknown, {
93
+ [x: number]: any;
94
+ [x: string]: any;
95
+ createdAt: NativeDate;
96
+ updatedAt: NativeDate;
97
+ } & {
98
+ _id: mongoose.Types.ObjectId;
99
+ } & {
100
+ __v: number;
101
+ }>;
102
+ //#endregion
103
+ export { createJournalEntrySchema as n, createAccountSchema as r, createFiscalPeriodSchema as t };
@@ -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 };
@@ -133,5 +133,4 @@ declare const quickbooksFieldMap: ExportFieldMap<FlatJournalRow>;
133
133
  //#region src/exports/field-maps/universal.d.ts
134
134
  declare const universalFieldMap: ExportFieldMap<FlatJournalRow>;
135
135
  //#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
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 };
@@ -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 };
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
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";
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
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";
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
- 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";
6
+ import { $ as BudgetVsActualReport, A as generateGeneralLedger, B as GeneralLedgerAccount, E as reopenFiscalPeriod, G as ReportCategory, H as IncomeStatementReport, I as generateTrialBalance, J as TaxReturnSummary, K as ReportGroup, L as BalanceSheetReport, M as generateIncomeStatement, O as generateCashFlow, P as generateBalanceSheet, R as CashFlowReport, T as closeFiscalPeriod, U as LedgerEntry, V as GeneralLedgerReport, W as ReportAccount, X as TrialBalanceRow, Y as TrialBalanceReport, _ as DimensionBreakdownOptions, a as AccountForeignBalance, b as DimensionBreakdownRow, c as buildRevaluationEntry, d as AgedBalanceParams, f as AgedBalanceReport, g as generateAgedBalance, h as DEFAULT_BUCKETS, i as generateRevaluation, l as computeRevaluation, m as AgedBucketConfig, n as RevaluationParams, o as RevaluationRate, p as AgedBalanceRow, q as TaxReport, r as RevaluationReport, s as RevaluationResult, t as RevaluationOptions, u as AgedBalanceOptions, v as DimensionBreakdownParams, x as generateDimensionBreakdown, y as DimensionBreakdownReport, z as CashFlowSection } from "./revaluation-D9x0NE8w.mjs";
7
+ import { n as defaultLogger, t as Logger } from "./logger-CbHWZl7v.mjs";
8
+ import { a as MultiTenantConfig, i as MultiCurrencyConfig, n as AuditConfig, o as SchemaOptions, r as JournalSchemaOptions, s as StrictnessConfig, t as AccountingEngineConfig } from "./engine-Cn-9yerQ.mjs";
9
+ import { a as BulkCreateInput, c as PostOptions, d as ReverseOptions, f as ReverseResult, i as AccountRepository, l as ReconcileParams, m as SeedResult, n as wireAccountMethods, o as BulkCreateResult, p as SeedOptions, r as wireJournalEntryMethods, s as JournalEntryRepository, t as wireReconciliationMethods, u as ReconciliationRepository } from "./reconciliation.repository-CW4-8q90.mjs";
10
+ import { n as createJournalEntrySchema, r as createAccountSchema, t as createFiscalPeriodSchema } from "./fiscal-period.schema-BMnlI9H5.mjs";
11
+ import { c as dateLockPlugin, i as fiscalLockPlugin, n as idempotencyPlugin, o as doubleEntryPlugin } from "./idempotency.plugin-B_CNsInz.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
+ }, mongoose$1.MergeType<mongoose$1.DefaultSchemaOptions, {
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
+ }, mongoose$1.MergeType<mongoose$1.DefaultSchemaOptions, {
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
+ }, mongoose$1.MergeType<mongoose$1.DefaultSchemaOptions, {
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;
131
+ [x: string]: any;
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
+ }, mongoose$1.MergeType<mongoose$1.DefaultSchemaOptions, {
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
+ }, mongoose$1.MergeType<mongoose$1.DefaultSchemaOptions, {
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;
66
193
  [x: string]: any;
67
- } & Required<{
68
- _id: unknown;
69
- }> & {
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,7 +329,11 @@ 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
@@ -169,6 +341,8 @@ declare function createAccountingEngine(config: AccountingEngineConfig): Account
169
341
  /**
170
342
  * Compute start/end dates from a date option + value.
171
343
  *
344
+ * @throws {Error} If value is null/undefined/invalid for the given option
345
+ *
172
346
  * Examples:
173
347
  * getDateRange('month', '2025-03') → Mar 1 – Mar 31
174
348
  * getDateRange('quarter', { quarter: 2, year: 2025 }) → Apr 1 – Jun 30
@@ -260,6 +434,55 @@ declare function finalizeSession(session: ClientSession | null, ownSession: bool
260
434
  */
261
435
  declare function buildItemFilters(filters?: Record<string, unknown>): Record<string, unknown>;
262
436
  //#endregion
437
+ //#region src/utils/dimensions.d.ts
438
+ /**
439
+ * Analytic Dimensions — Helpers for defining analytic dimensions
440
+ * (department, project, cost center) on journal items.
441
+ *
442
+ * Generates Mongoose schema fields and indexes for dimension queries.
443
+ */
444
+ interface DimensionDefinition {
445
+ /** Field name on the journal item, e.g. 'departmentId' */
446
+ field: string;
447
+ /** Human-readable label, e.g. 'Department' */
448
+ label: string;
449
+ /** Mongoose model ref for population, e.g. 'Department' */
450
+ ref?: string;
451
+ /** Whether the field is required (default: false) */
452
+ required?: boolean;
453
+ }
454
+ /**
455
+ * Build extraItemFields schema definition for a set of dimensions.
456
+ *
457
+ * Returns a Mongoose schema-compatible object suitable for spreading into
458
+ * `extraItemFields` in JournalSchemaOptions.
459
+ *
460
+ * @example
461
+ * ```typescript
462
+ * const fields = buildDimensionFields([
463
+ * { field: 'departmentId', label: 'Department', ref: 'Department' },
464
+ * { field: 'projectId', label: 'Project', ref: 'Project' },
465
+ * ]);
466
+ * // => { departmentId: { type: Schema.Types.ObjectId, ref: 'Department', required: false, default: null }, ... }
467
+ * ```
468
+ */
469
+ declare function buildDimensionFields(dimensions: DimensionDefinition[]): Record<string, unknown>;
470
+ /**
471
+ * Build extra indexes for dimension queries.
472
+ *
473
+ * Each dimension gets a compound index on `journalItems.{field}` + `date`
474
+ * for efficient filtered reporting. When `orgField` is provided, it is
475
+ * prepended to each index for multi-tenant scoping.
476
+ *
477
+ * @param dimensions - Array of dimension definitions
478
+ * @param orgField - Optional org-scoping field name (e.g. 'business')
479
+ * @returns Array of index specifications compatible with `extraIndexes` in JournalSchemaOptions
480
+ */
481
+ declare function buildDimensionIndexes(dimensions: DimensionDefinition[], orgField?: string): Array<{
482
+ fields: Record<string, 1 | -1>;
483
+ options?: Record<string, unknown>;
484
+ }>;
485
+ //#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 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, generateCashFlow, generateDimensionBreakdown, generateGeneralLedger, generateIncomeStatement, generateRevaluation, 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, wireReconciliationMethods };