@tailor-platform/erp-kit 0.6.0 → 0.7.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 (290) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +10 -10
  3. package/dist/cli.mjs +407 -69
  4. package/package.json +1 -1
  5. package/skills/erp-kit-app-1-requirements/SKILL.md +33 -17
  6. package/skills/erp-kit-app-2-requirements-review/SKILL.md +12 -0
  7. package/skills/erp-kit-app-3-plan/SKILL.md +18 -4
  8. package/skills/erp-kit-app-3-plan/references/resolver-extraction.md +1 -1
  9. package/skills/erp-kit-app-3-plan/references/screen-extraction.md +1 -1
  10. package/skills/erp-kit-app-4-plan-review/SKILL.md +12 -0
  11. package/skills/erp-kit-app-5-impl-backend/SKILL.md +12 -0
  12. package/skills/erp-kit-app-6-impl-frontend/SKILL.md +12 -0
  13. package/skills/erp-kit-app-7-impl-review/SKILL.md +13 -1
  14. package/skills/erp-kit-app-shared/references/progress-protocol.md +77 -0
  15. package/skills/erp-kit-mock-scenario/SKILL.md +1 -1
  16. package/skills/erp-kit-module-1-requirements/SKILL.md +1 -1
  17. package/skills/erp-kit-module-3-plan/SKILL.md +3 -3
  18. package/skills/erp-kit-module-3-update-plan/SKILL.md +3 -3
  19. package/skills/erp-kit-module-5-impl/SKILL.md +1 -1
  20. package/src/commands/app/index.ts +2 -0
  21. package/src/commands/app/progress/git-context.ts +16 -0
  22. package/src/commands/app/progress/index.ts +45 -0
  23. package/src/commands/app/progress/log.ts +49 -0
  24. package/src/commands/app/progress/progress.test.ts +128 -0
  25. package/src/commands/app/progress/schema-cmd.ts +10 -0
  26. package/src/commands/check.test.ts +4 -4
  27. package/src/commands/lib/discovery.test.ts +5 -7
  28. package/src/commands/lib/discovery.ts +8 -8
  29. package/src/commands/lib/sync-check-source.test.ts +1 -1
  30. package/src/commands/lib/sync-check-source.ts +6 -1
  31. package/src/commands/lib/sync-check-tests.test.ts +43 -0
  32. package/src/commands/lib/sync-check-tests.ts +20 -2
  33. package/src/commands/sync-check.ts +3 -0
  34. package/src/generator/generate-app-code.test.ts +0 -6
  35. package/src/generator/generate-app-code.ts +3 -13
  36. package/src/generator/generate-code.test.ts +10 -40
  37. package/src/generator/generate-code.ts +6 -12
  38. package/src/generator/stub-templates.test.ts +0 -7
  39. package/src/generator/stub-templates.ts +0 -14
  40. package/src/modules/finance-ledger/README.md +50 -0
  41. package/src/modules/finance-ledger/command/.gitkeep +0 -0
  42. package/src/modules/finance-ledger/command/addJournalLine.generated.ts +6 -0
  43. package/src/modules/finance-ledger/command/addJournalLine.test.ts +438 -0
  44. package/src/modules/finance-ledger/command/addJournalLine.ts +122 -0
  45. package/src/modules/finance-ledger/command/approveAndLockPeriod.generated.ts +6 -0
  46. package/src/modules/finance-ledger/command/approveAndLockPeriod.test.ts +107 -0
  47. package/src/modules/finance-ledger/command/approveAndLockPeriod.ts +72 -0
  48. package/src/modules/finance-ledger/command/beginClose.generated.ts +6 -0
  49. package/src/modules/finance-ledger/command/beginClose.test.ts +106 -0
  50. package/src/modules/finance-ledger/command/beginClose.ts +58 -0
  51. package/src/modules/finance-ledger/command/closePeriod.generated.ts +6 -0
  52. package/src/modules/finance-ledger/command/closePeriod.test.ts +87 -0
  53. package/src/modules/finance-ledger/command/closePeriod.ts +44 -0
  54. package/src/modules/finance-ledger/command/createAccountingPeriod.generated.ts +6 -0
  55. package/src/modules/finance-ledger/command/createAccountingPeriod.test.ts +425 -0
  56. package/src/modules/finance-ledger/command/createAccountingPeriod.ts +133 -0
  57. package/src/modules/finance-ledger/command/createFiscalYear.generated.ts +6 -0
  58. package/src/modules/finance-ledger/command/createFiscalYear.test.ts +197 -0
  59. package/src/modules/finance-ledger/command/createFiscalYear.ts +70 -0
  60. package/src/modules/finance-ledger/command/createJournalEntry.generated.ts +6 -0
  61. package/src/modules/finance-ledger/command/createJournalEntry.test.ts +261 -0
  62. package/src/modules/finance-ledger/command/createJournalEntry.ts +121 -0
  63. package/src/modules/finance-ledger/command/deleteAccountingPeriod.generated.ts +6 -0
  64. package/src/modules/finance-ledger/command/deleteAccountingPeriod.test.ts +71 -0
  65. package/src/modules/finance-ledger/command/deleteAccountingPeriod.ts +55 -0
  66. package/src/modules/finance-ledger/command/deleteFiscalYear.generated.ts +6 -0
  67. package/src/modules/finance-ledger/command/deleteFiscalYear.test.ts +38 -0
  68. package/src/modules/finance-ledger/command/deleteFiscalYear.ts +34 -0
  69. package/src/modules/finance-ledger/command/deleteJournalEntry.generated.ts +6 -0
  70. package/src/modules/finance-ledger/command/deleteJournalEntry.test.ts +58 -0
  71. package/src/modules/finance-ledger/command/deleteJournalEntry.ts +43 -0
  72. package/src/modules/finance-ledger/command/executeYearEndClose.generated.ts +6 -0
  73. package/src/modules/finance-ledger/command/executeYearEndClose.test.ts +239 -0
  74. package/src/modules/finance-ledger/command/executeYearEndClose.ts +415 -0
  75. package/src/modules/finance-ledger/command/finalCloseAndLockPeriod.generated.ts +6 -0
  76. package/src/modules/finance-ledger/command/finalCloseAndLockPeriod.test.ts +102 -0
  77. package/src/modules/finance-ledger/command/finalCloseAndLockPeriod.ts +76 -0
  78. package/src/modules/finance-ledger/command/finalizeFinancialStatement.generated.ts +6 -0
  79. package/src/modules/finance-ledger/command/finalizeFinancialStatement.test.ts +73 -0
  80. package/src/modules/finance-ledger/command/finalizeFinancialStatement.ts +73 -0
  81. package/src/modules/finance-ledger/command/generateFinancialStatement.generated.ts +6 -0
  82. package/src/modules/finance-ledger/command/generateFinancialStatement.test.ts +311 -0
  83. package/src/modules/finance-ledger/command/generateFinancialStatement.ts +275 -0
  84. package/src/modules/finance-ledger/command/generatePreliminaryStatements.generated.ts +6 -0
  85. package/src/modules/finance-ledger/command/generatePreliminaryStatements.test.ts +152 -0
  86. package/src/modules/finance-ledger/command/generatePreliminaryStatements.ts +140 -0
  87. package/src/modules/finance-ledger/command/generateTrialBalance.generated.ts +6 -0
  88. package/src/modules/finance-ledger/command/generateTrialBalance.test.ts +439 -0
  89. package/src/modules/finance-ledger/command/generateTrialBalance.ts +268 -0
  90. package/src/modules/finance-ledger/command/initiatePeriodClose.generated.ts +6 -0
  91. package/src/modules/finance-ledger/command/initiatePeriodClose.test.ts +153 -0
  92. package/src/modules/finance-ledger/command/initiatePeriodClose.ts +84 -0
  93. package/src/modules/finance-ledger/command/openForAdvanceEntry.generated.ts +6 -0
  94. package/src/modules/finance-ledger/command/openForAdvanceEntry.test.ts +87 -0
  95. package/src/modules/finance-ledger/command/openForAdvanceEntry.ts +44 -0
  96. package/src/modules/finance-ledger/command/openPeriod.generated.ts +6 -0
  97. package/src/modules/finance-ledger/command/openPeriod.test.ts +90 -0
  98. package/src/modules/finance-ledger/command/openPeriod.ts +44 -0
  99. package/src/modules/finance-ledger/command/permanentlyClosePeriod.generated.ts +6 -0
  100. package/src/modules/finance-ledger/command/permanentlyClosePeriod.test.ts +87 -0
  101. package/src/modules/finance-ledger/command/permanentlyClosePeriod.ts +48 -0
  102. package/src/modules/finance-ledger/command/postAdjustingEntries.generated.ts +6 -0
  103. package/src/modules/finance-ledger/command/postAdjustingEntries.test.ts +392 -0
  104. package/src/modules/finance-ledger/command/postAdjustingEntries.ts +156 -0
  105. package/src/modules/finance-ledger/command/postJournalEntry.generated.ts +6 -0
  106. package/src/modules/finance-ledger/command/postJournalEntry.test.ts +346 -0
  107. package/src/modules/finance-ledger/command/postJournalEntry.ts +160 -0
  108. package/src/modules/finance-ledger/command/processInventoryHandoff.generated.ts +6 -0
  109. package/src/modules/finance-ledger/command/processInventoryHandoff.test.ts +211 -0
  110. package/src/modules/finance-ledger/command/processInventoryHandoff.ts +133 -0
  111. package/src/modules/finance-ledger/command/processManufacturingHandoff.generated.ts +6 -0
  112. package/src/modules/finance-ledger/command/processManufacturingHandoff.test.ts +221 -0
  113. package/src/modules/finance-ledger/command/processManufacturingHandoff.ts +133 -0
  114. package/src/modules/finance-ledger/command/processPurchaseHandoff.generated.ts +6 -0
  115. package/src/modules/finance-ledger/command/processPurchaseHandoff.test.ts +222 -0
  116. package/src/modules/finance-ledger/command/processPurchaseHandoff.ts +133 -0
  117. package/src/modules/finance-ledger/command/processSalesHandoff.generated.ts +6 -0
  118. package/src/modules/finance-ledger/command/processSalesHandoff.test.ts +257 -0
  119. package/src/modules/finance-ledger/command/processSalesHandoff.ts +135 -0
  120. package/src/modules/finance-ledger/command/regenerateFinancialStatement.generated.ts +6 -0
  121. package/src/modules/finance-ledger/command/regenerateFinancialStatement.test.ts +129 -0
  122. package/src/modules/finance-ledger/command/regenerateFinancialStatement.ts +186 -0
  123. package/src/modules/finance-ledger/command/removeJournalLine.generated.ts +6 -0
  124. package/src/modules/finance-ledger/command/removeJournalLine.test.ts +65 -0
  125. package/src/modules/finance-ledger/command/removeJournalLine.ts +39 -0
  126. package/src/modules/finance-ledger/command/reopenPeriod.generated.ts +6 -0
  127. package/src/modules/finance-ledger/command/reopenPeriod.test.ts +87 -0
  128. package/src/modules/finance-ledger/command/reopenPeriod.ts +44 -0
  129. package/src/modules/finance-ledger/command/reverseJournalEntry.generated.ts +6 -0
  130. package/src/modules/finance-ledger/command/reverseJournalEntry.test.ts +337 -0
  131. package/src/modules/finance-ledger/command/reverseJournalEntry.ts +140 -0
  132. package/src/modules/finance-ledger/command/revertSoftLock.generated.ts +6 -0
  133. package/src/modules/finance-ledger/command/revertSoftLock.test.ts +96 -0
  134. package/src/modules/finance-ledger/command/revertSoftLock.ts +67 -0
  135. package/src/modules/finance-ledger/command/updateFiscalYear.generated.ts +6 -0
  136. package/src/modules/finance-ledger/command/updateFiscalYear.test.ts +138 -0
  137. package/src/modules/finance-ledger/command/updateFiscalYear.ts +85 -0
  138. package/src/modules/finance-ledger/command/updateJournalEntry.generated.ts +6 -0
  139. package/src/modules/finance-ledger/command/updateJournalEntry.test.ts +195 -0
  140. package/src/modules/finance-ledger/command/updateJournalEntry.ts +86 -0
  141. package/src/modules/finance-ledger/command/updateJournalLine.generated.ts +6 -0
  142. package/src/modules/finance-ledger/command/updateJournalLine.test.ts +385 -0
  143. package/src/modules/finance-ledger/command/updateJournalLine.ts +155 -0
  144. package/src/modules/finance-ledger/command/verifySubledgerTransfers.generated.ts +6 -0
  145. package/src/modules/finance-ledger/command/verifySubledgerTransfers.test.ts +201 -0
  146. package/src/modules/finance-ledger/command/verifySubledgerTransfers.ts +113 -0
  147. package/src/modules/finance-ledger/command/verifyTrialBalance.generated.ts +6 -0
  148. package/src/modules/finance-ledger/command/verifyTrialBalance.test.ts +136 -0
  149. package/src/modules/finance-ledger/command/verifyTrialBalance.ts +97 -0
  150. package/src/modules/finance-ledger/db/.gitkeep +0 -0
  151. package/src/modules/finance-ledger/db/accountingPeriod.ts +58 -0
  152. package/src/modules/finance-ledger/db/financialStatement.ts +92 -0
  153. package/src/modules/finance-ledger/db/financialStatementLineItem.ts +76 -0
  154. package/src/modules/finance-ledger/db/fiscalYear.ts +41 -0
  155. package/src/modules/finance-ledger/db/journalEntry.ts +101 -0
  156. package/src/modules/finance-ledger/db/journalLine.ts +64 -0
  157. package/src/modules/finance-ledger/db/periodClose.ts +97 -0
  158. package/src/modules/finance-ledger/db/trialBalance.ts +63 -0
  159. package/src/modules/finance-ledger/db/trialBalanceLine.ts +63 -0
  160. package/src/modules/finance-ledger/docs/commands/AddJournalLine.md +74 -0
  161. package/src/modules/finance-ledger/docs/commands/ApproveAndLockPeriod.md +53 -0
  162. package/src/modules/finance-ledger/docs/commands/BeginClose.md +47 -0
  163. package/src/modules/finance-ledger/docs/commands/ClosePeriod.md +45 -0
  164. package/src/modules/finance-ledger/docs/commands/CreateAccountingPeriod.md +69 -0
  165. package/src/modules/finance-ledger/docs/commands/CreateFiscalYear.md +56 -0
  166. package/src/modules/finance-ledger/docs/commands/CreateJournalEntry.md +63 -0
  167. package/src/modules/finance-ledger/docs/commands/DeleteAccountingPeriod.md +46 -0
  168. package/src/modules/finance-ledger/docs/commands/DeleteFiscalYear.md +40 -0
  169. package/src/modules/finance-ledger/docs/commands/DeleteJournalEntry.md +44 -0
  170. package/src/modules/finance-ledger/docs/commands/ExecuteYearEndClose.md +81 -0
  171. package/src/modules/finance-ledger/docs/commands/FinalCloseAndLockPeriod.md +49 -0
  172. package/src/modules/finance-ledger/docs/commands/FinalizeFinancialStatement.md +43 -0
  173. package/src/modules/finance-ledger/docs/commands/GenerateFinancialStatement.md +86 -0
  174. package/src/modules/finance-ledger/docs/commands/GeneratePreliminaryStatements.md +53 -0
  175. package/src/modules/finance-ledger/docs/commands/GenerateTrialBalance.md +75 -0
  176. package/src/modules/finance-ledger/docs/commands/InitiatePeriodClose.md +58 -0
  177. package/src/modules/finance-ledger/docs/commands/OpenForAdvanceEntry.md +44 -0
  178. package/src/modules/finance-ledger/docs/commands/OpenPeriod.md +45 -0
  179. package/src/modules/finance-ledger/docs/commands/PermanentlyClosePeriod.md +45 -0
  180. package/src/modules/finance-ledger/docs/commands/PostAdjustingEntries.md +61 -0
  181. package/src/modules/finance-ledger/docs/commands/PostJournalEntry.md +81 -0
  182. package/src/modules/finance-ledger/docs/commands/ProcessInventoryHandoff.md +72 -0
  183. package/src/modules/finance-ledger/docs/commands/ProcessManufacturingHandoff.md +68 -0
  184. package/src/modules/finance-ledger/docs/commands/ProcessPurchaseHandoff.md +68 -0
  185. package/src/modules/finance-ledger/docs/commands/ProcessSalesHandoff.md +71 -0
  186. package/src/modules/finance-ledger/docs/commands/RegenerateFinancialStatement.md +60 -0
  187. package/src/modules/finance-ledger/docs/commands/RemoveJournalLine.md +42 -0
  188. package/src/modules/finance-ledger/docs/commands/ReopenPeriod.md +45 -0
  189. package/src/modules/finance-ledger/docs/commands/ReverseJournalEntry.md +62 -0
  190. package/src/modules/finance-ledger/docs/commands/RevertSoftLock.md +49 -0
  191. package/src/modules/finance-ledger/docs/commands/UpdateFiscalYear.md +60 -0
  192. package/src/modules/finance-ledger/docs/commands/UpdateJournalEntry.md +50 -0
  193. package/src/modules/finance-ledger/docs/commands/UpdateJournalLine.md +61 -0
  194. package/src/modules/finance-ledger/docs/commands/VerifySubledgerTransfers.md +59 -0
  195. package/src/modules/finance-ledger/docs/commands/VerifyTrialBalance.md +53 -0
  196. package/src/modules/finance-ledger/docs/features/accounting-period-management.md +110 -0
  197. package/src/modules/finance-ledger/docs/features/financial-statement-generation.md +115 -0
  198. package/src/modules/finance-ledger/docs/features/journal-entry-management.md +138 -0
  199. package/src/modules/finance-ledger/docs/features/period-end-close.md +102 -0
  200. package/src/modules/finance-ledger/docs/features/subledger-integration.md +141 -0
  201. package/src/modules/finance-ledger/docs/features/trial-balance.md +99 -0
  202. package/src/modules/finance-ledger/docs/features/year-end-close.md +84 -0
  203. package/src/modules/finance-ledger/docs/models/AccountingPeriod.md +71 -0
  204. package/src/modules/finance-ledger/docs/models/FinancialStatement.md +76 -0
  205. package/src/modules/finance-ledger/docs/models/FinancialStatementLineItem.md +41 -0
  206. package/src/modules/finance-ledger/docs/models/FiscalYear.md +41 -0
  207. package/src/modules/finance-ledger/docs/models/JournalEntry.md +80 -0
  208. package/src/modules/finance-ledger/docs/models/JournalLine.md +47 -0
  209. package/src/modules/finance-ledger/docs/models/PeriodClose.md +83 -0
  210. package/src/modules/finance-ledger/docs/models/TrialBalance.md +56 -0
  211. package/src/modules/finance-ledger/docs/models/TrialBalanceLine.md +37 -0
  212. package/src/modules/finance-ledger/docs/queries/GetAccountingPeriod.md +35 -0
  213. package/src/modules/finance-ledger/docs/queries/GetFinancialStatement.md +38 -0
  214. package/src/modules/finance-ledger/docs/queries/GetFiscalYear.md +35 -0
  215. package/src/modules/finance-ledger/docs/queries/GetJournalEntry.md +37 -0
  216. package/src/modules/finance-ledger/docs/queries/GetPeriodByDate.md +38 -0
  217. package/src/modules/finance-ledger/docs/queries/GetPeriodClose.md +36 -0
  218. package/src/modules/finance-ledger/docs/queries/GetSubledgerTransferStatus.md +45 -0
  219. package/src/modules/finance-ledger/docs/queries/GetTrialBalance.md +38 -0
  220. package/src/modules/finance-ledger/docs/queries/ListAccountingPeriods.md +46 -0
  221. package/src/modules/finance-ledger/docs/queries/ListFinancialStatements.md +46 -0
  222. package/src/modules/finance-ledger/docs/queries/ListFiscalYears.md +42 -0
  223. package/src/modules/finance-ledger/docs/queries/ListJournalEntries.md +48 -0
  224. package/src/modules/finance-ledger/docs/queries/ListPeriodCloses.md +46 -0
  225. package/src/modules/finance-ledger/docs/queries/ListTrialBalances.md +51 -0
  226. package/src/modules/finance-ledger/executor/.gitkeep +0 -0
  227. package/src/modules/finance-ledger/generated/enums.ts +109 -0
  228. package/src/modules/finance-ledger/generated/kysely-tailordb.ts +202 -0
  229. package/src/modules/finance-ledger/index.ts +2 -0
  230. package/src/modules/finance-ledger/lib/_db_deps.ts +56 -0
  231. package/src/modules/finance-ledger/lib/errors.generated.ts +332 -0
  232. package/src/modules/finance-ledger/lib/permissions.generated.ts +41 -0
  233. package/src/modules/finance-ledger/lib/types.ts +66 -0
  234. package/src/modules/finance-ledger/module.ts +262 -0
  235. package/src/modules/finance-ledger/package.json +26 -0
  236. package/src/modules/finance-ledger/permissions.ts +3 -0
  237. package/src/modules/finance-ledger/query/.gitkeep +0 -0
  238. package/src/modules/finance-ledger/query/getAccountingPeriod.generated.ts +5 -0
  239. package/src/modules/finance-ledger/query/getAccountingPeriod.test.ts +31 -0
  240. package/src/modules/finance-ledger/query/getAccountingPeriod.ts +21 -0
  241. package/src/modules/finance-ledger/query/getFinancialStatement.generated.ts +5 -0
  242. package/src/modules/finance-ledger/query/getFinancialStatement.test.ts +35 -0
  243. package/src/modules/finance-ledger/query/getFinancialStatement.ts +29 -0
  244. package/src/modules/finance-ledger/query/getFiscalYear.generated.ts +5 -0
  245. package/src/modules/finance-ledger/query/getFiscalYear.test.ts +31 -0
  246. package/src/modules/finance-ledger/query/getFiscalYear.ts +21 -0
  247. package/src/modules/finance-ledger/query/getJournalEntry.generated.ts +5 -0
  248. package/src/modules/finance-ledger/query/getJournalEntry.test.ts +35 -0
  249. package/src/modules/finance-ledger/query/getJournalEntry.ts +29 -0
  250. package/src/modules/finance-ledger/query/getPeriodByDate.generated.ts +5 -0
  251. package/src/modules/finance-ledger/query/getPeriodByDate.test.ts +53 -0
  252. package/src/modules/finance-ledger/query/getPeriodByDate.ts +27 -0
  253. package/src/modules/finance-ledger/query/getPeriodClose.generated.ts +5 -0
  254. package/src/modules/finance-ledger/query/getPeriodClose.test.ts +31 -0
  255. package/src/modules/finance-ledger/query/getPeriodClose.ts +21 -0
  256. package/src/modules/finance-ledger/query/getSubledgerTransferStatus.generated.ts +5 -0
  257. package/src/modules/finance-ledger/query/getSubledgerTransferStatus.test.ts +101 -0
  258. package/src/modules/finance-ledger/query/getSubledgerTransferStatus.ts +68 -0
  259. package/src/modules/finance-ledger/query/getTrialBalance.generated.ts +5 -0
  260. package/src/modules/finance-ledger/query/getTrialBalance.test.ts +33 -0
  261. package/src/modules/finance-ledger/query/getTrialBalance.ts +30 -0
  262. package/src/modules/finance-ledger/query/listAccountingPeriods.generated.ts +5 -0
  263. package/src/modules/finance-ledger/query/listAccountingPeriods.test.ts +81 -0
  264. package/src/modules/finance-ledger/query/listAccountingPeriods.ts +61 -0
  265. package/src/modules/finance-ledger/query/listFinancialStatements.generated.ts +5 -0
  266. package/src/modules/finance-ledger/query/listFinancialStatements.test.ts +76 -0
  267. package/src/modules/finance-ledger/query/listFinancialStatements.ts +62 -0
  268. package/src/modules/finance-ledger/query/listFiscalYears.generated.ts +5 -0
  269. package/src/modules/finance-ledger/query/listFiscalYears.test.ts +63 -0
  270. package/src/modules/finance-ledger/query/listFiscalYears.ts +45 -0
  271. package/src/modules/finance-ledger/query/listJournalEntries.generated.ts +5 -0
  272. package/src/modules/finance-ledger/query/listJournalEntries.test.ts +91 -0
  273. package/src/modules/finance-ledger/query/listJournalEntries.ts +64 -0
  274. package/src/modules/finance-ledger/query/listPeriodCloses.generated.ts +5 -0
  275. package/src/modules/finance-ledger/query/listPeriodCloses.test.ts +63 -0
  276. package/src/modules/finance-ledger/query/listPeriodCloses.ts +64 -0
  277. package/src/modules/finance-ledger/query/listTrialBalances.generated.ts +5 -0
  278. package/src/modules/finance-ledger/query/listTrialBalances.test.ts +78 -0
  279. package/src/modules/finance-ledger/query/listTrialBalances.ts +56 -0
  280. package/src/modules/finance-ledger/seed/index.ts +19 -0
  281. package/src/modules/finance-ledger/tailor.config.ts +13 -0
  282. package/src/modules/finance-ledger/tailor.d.ts +13 -0
  283. package/src/modules/finance-ledger/testing/commandTestUtils.ts +35 -0
  284. package/src/modules/finance-ledger/testing/fixtures.ts +382 -0
  285. package/src/modules/finance-ledger/tsconfig.json +16 -0
  286. package/src/progress/schema.test.ts +161 -0
  287. package/src/progress/schema.ts +316 -0
  288. package/templates/scaffold/app/backend/package.json +1 -3
  289. package/templates/scaffold/app/backend/vitest.config.ts +4 -21
  290. package/src/generator/generate-stubs.ts +0 -35
@@ -0,0 +1,80 @@
1
+ # JournalEntry
2
+
3
+ ## Description
4
+
5
+ JournalEntry is the core transactional entity of the finance-ledger module, implementing double-entry bookkeeping for all financial postings. A journal entry consists of a header record carrying the entry date, journal type, reference number, status, posting period, description, and optional source document reference, along with one or more JournalLine records. Every journal entry must satisfy the fundamental accounting constraint: total debits must equal total credits in the functional currency before it can be posted. Journal entries follow a lifecycle of DRAFT to POSTED, with posted entries eligible for reversal via a mirror entry that produces a REVERSED status on the original. The feature supports nine journal types (Sales, Purchase, Cash, Bank, Miscellaneous, Opening, Closing, Inventory, Manufacturing) to categorize entries by their business origin.
6
+
7
+ ## Domain Model Definitions
8
+
9
+ ### Model type
10
+
11
+ Stateful
12
+
13
+ #### State Transitions
14
+
15
+ ```mermaid
16
+ stateDiagram-v2
17
+ [*] --> Draft: createJournalEntry
18
+ Draft --> Draft: updateJournalEntry / addJournalLine / updateJournalLine / removeJournalLine
19
+ Draft --> Posted: postJournalEntry
20
+ Posted --> Reversed: reverseJournalEntry
21
+ Draft --> [*]: deleteJournalEntry
22
+ ```
23
+
24
+ ### Command Definitions
25
+
26
+ - [createJournalEntry](../commands/CreateJournalEntry.md) - Create a new journal entry in DRAFT status
27
+ - [updateJournalEntry](../commands/UpdateJournalEntry.md) - Update mutable fields of a DRAFT journal entry
28
+ - [deleteJournalEntry](../commands/DeleteJournalEntry.md) - Delete a DRAFT journal entry and all associated lines
29
+ - [addJournalLine](../commands/AddJournalLine.md) - Add a journal line to a DRAFT journal entry
30
+ - [updateJournalLine](../commands/UpdateJournalLine.md) - Update a journal line on a DRAFT journal entry
31
+ - [removeJournalLine](../commands/RemoveJournalLine.md) - Remove a journal line from a DRAFT journal entry
32
+ - [postJournalEntry](../commands/PostJournalEntry.md) - Post a balanced DRAFT journal entry to the general ledger
33
+ - [reverseJournalEntry](../commands/ReverseJournalEntry.md) - Reverse a posted journal entry via a mirror entry
34
+ - [processPurchaseHandoff](../commands/ProcessPurchaseHandoff.md) - Process a purchase subledger handoff event into a journal entry
35
+ - [processSalesHandoff](../commands/ProcessSalesHandoff.md) - Process a sales subledger handoff event into a journal entry
36
+ - [processInventoryHandoff](../commands/ProcessInventoryHandoff.md) - Process an inventory subledger handoff event into a journal entry
37
+ - [processManufacturingHandoff](../commands/ProcessManufacturingHandoff.md) - Process a manufacturing subledger handoff event into a journal entry
38
+
39
+ ### Query Definitions
40
+
41
+ - [GetJournalEntry](../queries/GetJournalEntry.md) - Retrieve a journal entry by id with all lines
42
+ - [ListJournalEntries](../queries/ListJournalEntries.md) - List journal entries with filters (period, type, status, date range)
43
+
44
+ ### Models
45
+
46
+ - JournalEntry
47
+ - JournalLine
48
+
49
+ ### Invariants
50
+
51
+ - Journal entries can only be created in DRAFT status
52
+ - Journal entry requires a valid journal type (SALES, PURCHASE, CASH, BANK, MISCELLANEOUS, OPENING, CLOSING, INVENTORY, MANUFACTURING)
53
+ - Journal entry requires a valid entry date
54
+ - Journal entry requires a reference number that is unique within the company scope
55
+ - Journal entry must reference a valid companyId; the company must be in ACTIVE status
56
+ - Journal entry must reference a valid accounting period; the period must be in OPEN or FUTURE_ENTERABLE status for posting
57
+ - Journal entry description is optional and can be updated while in DRAFT status
58
+ - Source document reference is optional and can be set on creation or update in DRAFT status
59
+ - A journal entry must have at least two journal lines before it can be posted
60
+ - Total debits must equal total credits in the functional currency for posting to succeed
61
+ - Posted journal entries cannot be modified (no field updates, no line additions or removals)
62
+ - Posted journal entries cannot be deleted; only reversal is permitted
63
+ - DRAFT journal entries can be deleted; deletion removes all associated journal lines
64
+ - Reversing a posted entry creates a new journal entry with all debit/credit amounts inverted
65
+ - The reversal entry references the original entry and is automatically posted
66
+ - The original entry status transitions from POSTED to REVERSED upon successful reversal
67
+ - Reversing an entry that is already REVERSED fails
68
+ - The reversal entry must target a period that is in OPEN or FUTURE_ENTERABLE status
69
+ - Journal type and entry date cannot be changed after the entry is posted
70
+ - Adjusting entries created during period-end close must have a valid adjustingEntryType (ACCRUAL, DEFERRAL, or RECLASSIFICATION)
71
+ - Posting a journal entry to a CLOSED, PERMANENTLY_CLOSED, or NEVER_OPENED period is rejected
72
+ - Balance validation for multi-currency entries is performed on the functional currency amounts, not the foreign currency amounts
73
+ - All journal entry lifecycle operations emit audit events via the audit module recording the acting user, timestamp, and field-level details
74
+
75
+ ### Relationships
76
+
77
+ - **References Company**: Each journal entry is scoped to a Company via companyId (organization module)
78
+ - **References AccountingPeriod**: Each journal entry references an AccountingPeriod via accountingPeriodId
79
+ - **Has Many JournalLine**: A journal entry contains one or more journal lines
80
+ - **References JournalEntry (reversal)**: A reversal entry references the original via reversalOfId
@@ -0,0 +1,47 @@
1
+ # JournalLine
2
+
3
+ ## Description
4
+
5
+ JournalLine represents a single debit or credit entry within a JournalEntry. Each line references a GL account from the coa-management module, specifies either a debit or credit amount (mutually exclusive), includes an optional line-level description, and optionally includes foreign currency details (currency code, exchange rate) with computed functional currency amounts. Journal lines are the atomic units of double-entry bookkeeping — they are always created, modified, and deleted in the context of their parent journal entry's lifecycle. Lines on a POSTED or REVERSED journal entry are immutable.
6
+
7
+ ## Domain Model Definitions
8
+
9
+ ### Model type
10
+
11
+ Standard
12
+
13
+ ### Command Definitions
14
+
15
+ - [addJournalLine](../commands/AddJournalLine.md) - Add a journal line to a DRAFT journal entry
16
+ - [updateJournalLine](../commands/UpdateJournalLine.md) - Update a journal line on a DRAFT journal entry
17
+ - [removeJournalLine](../commands/RemoveJournalLine.md) - Remove a journal line from a DRAFT journal entry
18
+
19
+ ### Query Definitions
20
+
21
+ - [GetJournalEntry](../queries/GetJournalEntry.md) - Journal lines are returned as part of the parent journal entry
22
+
23
+ ### Models
24
+
25
+ - JournalLine
26
+
27
+ ### Invariants
28
+
29
+ - Each journal line must reference a valid GL account from an ACTIVE Chart of Accounts
30
+ - Each journal line must specify either a debit amount or a credit amount (not both, and not zero for both)
31
+ - Debit and credit amounts must be positive values
32
+ - Multi-currency journal lines must specify a currency code and exchange rate
33
+ - The functional currency amount is computed as the foreign amount multiplied by the exchange rate
34
+ - Journal lines without an explicit currency default to the company's functional (base) currency with an exchange rate of 1.0
35
+ - Journal lines referencing an inactive or draft GL account are rejected at posting time
36
+ - Journal lines referencing a deprecated GL account with a successor mapping are redirected to the successor account at posting time
37
+ - If the successor account is itself inactive or deprecated without a further successor, the posting is rejected
38
+ - Journal lines can only be added to, updated on, or removed from a DRAFT journal entry
39
+ - Balance validation for multi-currency entries is performed on the functional currency amounts, not the foreign currency amounts
40
+ - Line-level description is optional and can be updated while the parent journal entry is in DRAFT status
41
+ - RECEIVABLE and PAYABLE classified accounts block direct manual journal postings (control account constraint)
42
+
43
+ ### Relationships
44
+
45
+ - **References JournalEntry**: Each journal line belongs to a JournalEntry via journalEntryId
46
+ - **References Account**: Each journal line references a GL Account via accountId (coa-management module)
47
+ - **References Currency**: Each journal line optionally references a Currency via currencyCode for multi-currency postings (primitives module)
@@ -0,0 +1,83 @@
1
+ # PeriodClose
2
+
3
+ ## Description
4
+
5
+ PeriodClose is a checklist-driven workflow entity that tracks the process of transitioning an accounting period from open to permanently closed. Each close operation is scoped to a single AccountingPeriod and follows a deterministic sequence of steps: initiation, subledger transfer verification, adjusting entry posting, trial balance verification, preliminary statement generation, review and approval, soft lock, and final permanent close. The entity records the initiating user, completion percentage, and current status. For the final period of a fiscal year, the close process extends to include year-end close steps (closing temporary accounts to retained earnings and generating opening balances for the new fiscal year).
6
+
7
+ ## Domain Model Definitions
8
+
9
+ ### Model type
10
+
11
+ Stateful
12
+
13
+ #### State Transitions
14
+
15
+ ```mermaid
16
+ stateDiagram-v2
17
+ [*] --> NotStarted: initiatePeriodClose
18
+ NotStarted --> InProgress: beginClose
19
+ InProgress --> SubledgersVerified: verifySubledgerTransfers
20
+ SubledgersVerified --> AdjustmentsPosted: postAdjustingEntries
21
+ AdjustmentsPosted --> TrialBalanceVerified: verifyTrialBalance
22
+ TrialBalanceVerified --> UnderReview: generatePreliminaryStatements
23
+ UnderReview --> SoftLocked: approveAndLockPeriod
24
+ SoftLocked --> InProgress: revertSoftLock
25
+ SoftLocked --> PermanentlyClosed: finalCloseAndLockPeriod
26
+ PermanentlyClosed --> [*]
27
+ ```
28
+
29
+ ### Command Definitions
30
+
31
+ - [initiatePeriodClose](../commands/InitiatePeriodClose.md) - Initiate the period close process for an accounting period
32
+ - [beginClose](../commands/BeginClose.md) - Begin the close checklist, transitioning from NOT_STARTED to IN_PROGRESS
33
+ - [verifySubledgerTransfers](../commands/VerifySubledgerTransfers.md) - Verify all subledger modules have transferred transactions to GL
34
+ - [postAdjustingEntries](../commands/PostAdjustingEntries.md) - Confirm adjusting entries (accruals, deferrals, reclassifications) are posted
35
+ - [verifyTrialBalance](../commands/VerifyTrialBalance.md) - Verify the period's trial balance is balanced
36
+ - [generatePreliminaryStatements](../commands/GeneratePreliminaryStatements.md) - Generate preliminary financial statements for review
37
+ - [approveAndLockPeriod](../commands/ApproveAndLockPeriod.md) - Approve and soft-lock the period
38
+ - [revertSoftLock](../commands/RevertSoftLock.md) - Revert a soft-locked period back to IN_PROGRESS
39
+ - [finalCloseAndLockPeriod](../commands/FinalCloseAndLockPeriod.md) - Permanently close the period (irreversible)
40
+ - [executeYearEndClose](../commands/ExecuteYearEndClose.md) - Execute year-end close: close temporary accounts to retained earnings and generate opening balances
41
+
42
+ ### Query Definitions
43
+
44
+ - [GetPeriodClose](../queries/GetPeriodClose.md) - Retrieve the period close record for an accounting period
45
+ - [ListPeriodCloses](../queries/ListPeriodCloses.md) - List period close records for a fiscal year or company with optional status filter
46
+ - [GetSubledgerTransferStatus](../queries/GetSubledgerTransferStatus.md) - Retrieve subledger transfer completeness status for an accounting period
47
+
48
+ ### Models
49
+
50
+ - PeriodClose
51
+
52
+ ### Invariants
53
+
54
+ - PeriodClose can only be initiated for an AccountingPeriod that is in OPEN status
55
+ - PeriodClose cannot be initiated for a period that already has an active close in progress
56
+ - PeriodClose lifecycle follows NOT_STARTED → IN_PROGRESS → SUBLEDGERS_VERIFIED → ADJUSTMENTS_POSTED → TRIAL_BALANCE_VERIFIED → UNDER_REVIEW → SOFT_LOCKED → PERMANENTLY_CLOSED
57
+ - PeriodClose cannot skip steps; each transition requires the previous step to be completed
58
+ - Subledger verification fails if any registered subledger module has pending unposted transactions for the period
59
+ - Trial balance verification fails if the period's trial balance has a non-zero difference between total debits and credits
60
+ - Approval step requires a user with the appropriate authorization role (controller or finance manager)
61
+ - Soft-locking prevents the accounting team from posting new journal entries to the period
62
+ - Soft-locked period still allows postings from users with the advisor/auditor role
63
+ - Permanently closing a period makes it fully immutable; no further journal entries can be posted regardless of role
64
+ - Reverting a soft-locked period to IN_PROGRESS is permitted only before permanent close
65
+ - Reverting a permanently closed period is not permitted
66
+ - Each period has at most one active PeriodClose record
67
+ - Concurrent close attempts for the same period are rejected with a conflict error
68
+ - Year-end close can only be initiated for the final period of a fiscal year
69
+ - Year-end close requires the standard close checklist to be completed through the soft-lock stage
70
+ - Year-end close generates a closing journal entry zeroing temporary accounts to retained earnings
71
+ - Year-end close generates opening balance entries for the first period of the new fiscal year
72
+ - Year-end close fails if no retained earnings account exists in the active CoA
73
+ - Year-end close cannot be run twice for the same fiscal year
74
+ - PeriodClose tracks a completionPercentage that increments as each checklist step is completed
75
+ - PeriodClose records the userId of the operator who initiated the close and the userId who completed each checklist step
76
+ - Each state transition emits an audit event recording the acting user, timestamp, previous status, and new status
77
+
78
+ ### Relationships
79
+
80
+ - **References AccountingPeriod**: Each PeriodClose is linked to an AccountingPeriod via accountingPeriodId
81
+ - **References FiscalYear**: The associated AccountingPeriod's fiscal year determines year-end close eligibility (via AccountingPeriod.fiscalYearId)
82
+ - **References User**: Records the initiating user via initiatedByUserId (user-management module)
83
+ - **References Account (retained earnings)**: Year-end close references the retained earnings account from the active CoA for closing temporary accounts
@@ -0,0 +1,56 @@
1
+ # TrialBalance
2
+
3
+ ## Description
4
+
5
+ TrialBalance is a point-in-time snapshot report that summarizes the balances of all GL accounts for a specific accounting period within a company. For each account, the report presents the opening balance, total period debits, total period credits, and the resulting closing balance via TrialBalanceLine records. The trial balance serves as the fundamental verification mechanism in double-entry bookkeeping: total debits across all accounts must equal total credits. The report supports two variants: pre-close (reflecting standard and adjusting entries) and post-close (reflecting closing entries that zero out temporary accounts). The trial balance is the foundational input for financial statement generation.
6
+
7
+ ## Domain Model Definitions
8
+
9
+ ### Model type
10
+
11
+ Standard
12
+
13
+ ### Command Definitions
14
+
15
+ - [generateTrialBalance](../commands/GenerateTrialBalance.md) - Generate a trial balance snapshot for a company, period, and variant
16
+
17
+ ### Query Definitions
18
+
19
+ - [GetTrialBalance](../queries/GetTrialBalance.md) - Retrieve a trial balance snapshot by id with all line items
20
+ - [ListTrialBalances](../queries/ListTrialBalances.md) - List trial balance snapshots for a company with optional filters (period, variant)
21
+
22
+ ### Models
23
+
24
+ - TrialBalance
25
+ - TrialBalanceLine
26
+
27
+ ### Invariants
28
+
29
+ - Trial balance can only be generated for a company with an ACTIVE Chart of Accounts
30
+ - Trial balance can only be generated for a valid accounting period that exists in the system
31
+ - Trial balance must include all GL accounts from the active CoA, even those with zero balances
32
+ - Opening balance for each account equals the closing balance from the immediately preceding period
33
+ - Opening balance for the first period of a new CoA defaults to zero for all accounts
34
+ - Period debits per account equal the sum of all debit amounts from posted journal lines for that account in the period
35
+ - Period credits per account equal the sum of all credit amounts from posted journal lines for that account in the period
36
+ - Closing balance per account equals opening balance plus period debits minus period credits
37
+ - Total debits across all accounts must equal total credits across all accounts (fundamental equilibrium check)
38
+ - Pre-close trial balance excludes closing entries
39
+ - Post-close trial balance includes all closing entries and shows zero balances for all temporary accounts
40
+ - Trial balance is scoped to a single company; accounts from other companies are never included
41
+ - Only posted journal entries are included; draft or voided entries are excluded
42
+ - Trial balance snapshot includes a generation timestamp
43
+ - Trial balance snapshot records the variant type (PRE_CLOSE or POST_CLOSE)
44
+ - Generating a trial balance when total debits do not equal total credits produces an imbalance error with the discrepancy amount
45
+ - Trial balance respects the account group hierarchy from coa-management, providing subtotals at each group level
46
+ - Trial balance accounts are ordered by account code in ascending order within each account group
47
+ - Generating a trial balance for a period with no posted journal entries produces a valid report with zero debits, zero credits, and opening balances carried forward
48
+ - Regenerating a trial balance for the same period and variant produces an updated snapshot reflecting any new postings since the last generation
49
+ - Trial balance generation emits an audit event via the audit module recording the acting user, company, period, variant, and timestamp
50
+
51
+ ### Relationships
52
+
53
+ - **References Company**: Each trial balance is scoped to a Company via companyId (organization module)
54
+ - **References AccountingPeriod**: Each trial balance references an AccountingPeriod via accountingPeriodId
55
+ - **References ChartOfAccounts**: Each trial balance references a ChartOfAccounts via chartOfAccountsId (coa-management module)
56
+ - **Has Many TrialBalanceLine**: A trial balance contains line items for each account
@@ -0,0 +1,37 @@
1
+ # TrialBalanceLine
2
+
3
+ ## Description
4
+
5
+ TrialBalanceLine represents a single account's balance within a TrialBalance snapshot. Each line records the account reference, optional account group for hierarchical aggregation, opening balance, period debits, period credits, and computed closing balance. Lines are always created as part of trial balance generation and are immutable once the snapshot is produced.
6
+
7
+ ## Domain Model Definitions
8
+
9
+ ### Model type
10
+
11
+ Standard
12
+
13
+ ### Command Definitions
14
+
15
+ - [generateTrialBalance](../commands/GenerateTrialBalance.md) - Trial balance lines are created as part of trial balance generation
16
+
17
+ ### Query Definitions
18
+
19
+ - [GetTrialBalance](../queries/GetTrialBalance.md) - Trial balance lines are returned as part of the parent trial balance
20
+
21
+ ### Models
22
+
23
+ - TrialBalanceLine
24
+
25
+ ### Invariants
26
+
27
+ - Each trial balance line must reference a valid GL account from the active CoA
28
+ - Opening balance equals the closing balance from the immediately preceding period for the same account
29
+ - Closing balance equals opening balance plus period debits minus period credits
30
+ - Lines are ordered by account code in ascending order within each account group
31
+ - Lines are immutable once generated as part of a trial balance snapshot
32
+
33
+ ### Relationships
34
+
35
+ - **References TrialBalance**: Each line belongs to a TrialBalance via trialBalanceId
36
+ - **References Account**: Each line references a GL Account via accountId (coa-management module)
37
+ - **References AccountGroup**: Each line optionally references an AccountGroup via accountGroupId (coa-management module)
@@ -0,0 +1,35 @@
1
+ # GetAccountingPeriod
2
+
3
+ ## Overview
4
+
5
+ GetAccountingPeriod retrieves a single accounting period record by id. The period record includes the period name, companyId, fiscalYearId, start date, end date, period type, and current status. This serves as the core period lookup for posting validation, period lifecycle management, and close workflows.
6
+
7
+ ## Business Rules
8
+
9
+ - Accepts a single lookup parameter: `{ id }`
10
+ - Returns the full accounting period record including all fields (id, companyId, fiscalYearId, periodName, startDate, endDate, periodType, status, timestamps)
11
+ - Returns null if no matching accounting period is found
12
+ - Lookup is an exact match on id
13
+
14
+ ## Process Flow
15
+
16
+ ```mermaid
17
+ flowchart TD
18
+ A[Receive input with id] --> B[SELECT from AccountingPeriod where id = input.id]
19
+ B --> C{Period found?}
20
+ C -->|Yes| D[Return accounting period record]
21
+ C -->|No| E[Return null]
22
+ ```
23
+
24
+ ## External Dependencies
25
+
26
+ - None
27
+
28
+ ## Error Scenarios
29
+
30
+ - **ACCOUNTING_PERIOD_NOT_FOUND**: No accounting period matches the given id — caller receives null
31
+
32
+ ## Test Cases
33
+
34
+ - returns accounting period when found by id
35
+ - returns null when not found
@@ -0,0 +1,38 @@
1
+ # GetFinancialStatement
2
+
3
+ ## Overview
4
+
5
+ GetFinancialStatement retrieves a single financial statement record by id, including all line items. The financial statement record contains the generation parameters (companyId, statement type, reporting date or date range, method for cash flow, status) and the full list of line items organized by account group sections. This query supports statement review, finalization workflows, and audit evidence retrieval.
6
+
7
+ ## Business Rules
8
+
9
+ - Accepts a single lookup parameter: `{ id }`
10
+ - Returns the full financial statement record including all line items
11
+ - Line items are structured according to the account group hierarchy from coa-management, with section headings and subtotals
12
+ - Statement types include BALANCE_SHEET, PROFIT_AND_LOSS, and CASH_FLOW
13
+ - Returns null if no matching financial statement is found
14
+ - Lookup is an exact match on id
15
+
16
+ ## Process Flow
17
+
18
+ ```mermaid
19
+ flowchart TD
20
+ A[Receive input with id] --> B[SELECT from FinancialStatement where id = input.id]
21
+ B --> C{Financial statement found?}
22
+ C -->|Yes| D[Load all associated line items]
23
+ D --> E[Return financial statement with line items]
24
+ C -->|No| F[Return null]
25
+ ```
26
+
27
+ ## External Dependencies
28
+
29
+ - None
30
+
31
+ ## Error Scenarios
32
+
33
+ - **FINANCIAL_STATEMENT_NOT_FOUND**: No financial statement matches the given id — caller receives null
34
+
35
+ ## Test Cases
36
+
37
+ - returns financial statement with line items when found by id
38
+ - returns null with empty line items when not found
@@ -0,0 +1,35 @@
1
+ # GetFiscalYear
2
+
3
+ ## Overview
4
+
5
+ GetFiscalYear retrieves a single fiscal year record by id. The fiscal year contains the year name, companyId, start date, end date, and status. This serves as the core fiscal year lookup for period management, year-end close workflows, and calendar structure validation.
6
+
7
+ ## Business Rules
8
+
9
+ - Accepts a single lookup parameter: `{ id }`
10
+ - Returns the full fiscal year record including all fields (id, companyId, yearName, startDate, endDate, status, timestamps)
11
+ - Returns null if no matching fiscal year is found
12
+ - Lookup is an exact match on id
13
+
14
+ ## Process Flow
15
+
16
+ ```mermaid
17
+ flowchart TD
18
+ A[Receive input with id] --> B[SELECT from FiscalYear where id = input.id]
19
+ B --> C{Fiscal year found?}
20
+ C -->|Yes| D[Return fiscal year record]
21
+ C -->|No| E[Return null]
22
+ ```
23
+
24
+ ## External Dependencies
25
+
26
+ - None
27
+
28
+ ## Error Scenarios
29
+
30
+ - **FISCAL_YEAR_NOT_FOUND**: No fiscal year matches the given id — caller receives null
31
+
32
+ ## Test Cases
33
+
34
+ - returns fiscal year when found by id
35
+ - returns null when not found
@@ -0,0 +1,37 @@
1
+ # GetJournalEntry
2
+
3
+ ## Overview
4
+
5
+ GetJournalEntry retrieves a single journal entry record by id, including all associated journal lines. The journal entry record contains the header fields (entry date, journal type, reference number, status, accounting period, description, source document reference) and the full list of journal lines (GL account, debit/credit amounts, currency, exchange rate, functional currency amount, line description). This is the primary query for viewing journal entry details, audit review, and reversal workflows.
6
+
7
+ ## Business Rules
8
+
9
+ - Accepts a single lookup parameter: `{ id }`
10
+ - Returns the full journal entry record including all header fields and all associated journal lines
11
+ - Journal lines include account references, debit and credit amounts, currency details, and line descriptions
12
+ - Returns null if no matching journal entry is found
13
+ - Lookup is an exact match on id
14
+
15
+ ## Process Flow
16
+
17
+ ```mermaid
18
+ flowchart TD
19
+ A[Receive input with id] --> B[SELECT from JournalEntry where id = input.id]
20
+ B --> C{Journal entry found?}
21
+ C -->|Yes| D[Load all associated JournalLine records]
22
+ D --> E[Return journal entry with lines]
23
+ C -->|No| F[Return null]
24
+ ```
25
+
26
+ ## External Dependencies
27
+
28
+ - None
29
+
30
+ ## Error Scenarios
31
+
32
+ - **JOURNAL_ENTRY_NOT_FOUND**: No journal entry matches the given id — caller receives null
33
+
34
+ ## Test Cases
35
+
36
+ - returns journal entry with journal lines when found by id
37
+ - returns null with empty journal lines when not found
@@ -0,0 +1,38 @@
1
+ # GetPeriodByDate
2
+
3
+ ## Overview
4
+
5
+ GetPeriodByDate finds the accounting period that contains a given date for a specific company. It looks up the operating period where the date falls between startDate and endDate (inclusive). This query is the primary mechanism used by upstream modules (purchase, sales, inventory, manufacturing) to determine which accounting period a transaction date maps to and whether posting is permitted.
6
+
7
+ ## Business Rules
8
+
9
+ - Requires `companyId` and `date` as input parameters
10
+ - Searches for an accounting period where `startDate <= date <= endDate` and `periodType = OPERATING`
11
+ - Only OPERATING periods are returned; ADJUSTMENT periods are excluded from date-based lookup
12
+ - Returns the full accounting period record including status, enabling callers to check posting eligibility
13
+ - Returns null if no operating period covers the given date (e.g., date falls outside all defined fiscal year boundaries)
14
+ - If multiple periods could theoretically match (should not occur with properly configured non-overlapping periods), the query returns the first match
15
+
16
+ ## Process Flow
17
+
18
+ ```mermaid
19
+ flowchart TD
20
+ A[Receive input with companyId and date] --> B[SELECT from AccountingPeriod where companyId = input.companyId AND startDate <= input.date AND endDate >= input.date AND periodType = OPERATING]
21
+ B --> C{Period found?}
22
+ C -->|Yes| D[Return accounting period record]
23
+ C -->|No| E[Return null]
24
+ ```
25
+
26
+ ## External Dependencies
27
+
28
+ - None
29
+
30
+ ## Error Scenarios
31
+
32
+ - **PERIOD_NOT_FOUND**: No operating period covers the given date for the specified company — caller receives null
33
+
34
+ ## Test Cases
35
+
36
+ - returns period when date falls within range
37
+ - returns null when no period covers the date
38
+ - only returns OPERATING periods (not ADJUSTMENT)
@@ -0,0 +1,36 @@
1
+ # GetPeriodClose
2
+
3
+ ## Overview
4
+
5
+ GetPeriodClose retrieves the PeriodClose record for a given accounting period. The PeriodClose record tracks the close workflow status, checklist completion percentage, the user who initiated each step, and timestamps for each state transition. This query supports period-end close workflow management, status monitoring, and audit review of the close process.
6
+
7
+ ## Business Rules
8
+
9
+ - Accepts a single lookup parameter: `{ accountingPeriodId }`
10
+ - Returns the full PeriodClose record including close status, completionPercentage, initiator userId, step timestamps, and audit metadata
11
+ - Each accounting period has at most one PeriodClose record
12
+ - Returns null if no close record exists for the given accounting period (i.e., close has not been initiated)
13
+ - Lookup is an exact match on accountingPeriodId
14
+
15
+ ## Process Flow
16
+
17
+ ```mermaid
18
+ flowchart TD
19
+ A[Receive input with accountingPeriodId] --> B[SELECT from PeriodClose where accountingPeriodId = input.accountingPeriodId]
20
+ B --> C{PeriodClose record found?}
21
+ C -->|Yes| D[Return PeriodClose record]
22
+ C -->|No| E[Return null]
23
+ ```
24
+
25
+ ## External Dependencies
26
+
27
+ - None
28
+
29
+ ## Error Scenarios
30
+
31
+ - **PERIOD_CLOSE_NOT_FOUND**: No PeriodClose record exists for the given accounting period — caller receives null
32
+
33
+ ## Test Cases
34
+
35
+ - returns period close when found by accounting period id
36
+ - returns null when not found
@@ -0,0 +1,45 @@
1
+ # GetSubledgerTransferStatus
2
+
3
+ ## Overview
4
+
5
+ GetSubledgerTransferStatus returns the transfer completeness status for all subledger modules for a given accounting period. For each registered subledger module (purchase, sales, inventory, manufacturing), the query reports the total expected handoff events, the number of acknowledged (successfully posted) events, and the number of outstanding (pending) events. This query is a critical input to the period-end close workflow, where subledger transfer verification must pass before the close can proceed.
6
+
7
+ ## Business Rules
8
+
9
+ - Accepts a single lookup parameter: `{ accountingPeriodId }`
10
+ - Returns a status record per subledger module: purchase, sales, inventory, manufacturing
11
+ - Each module status includes:
12
+ - `totalExpected` — total number of handoff events expected for the period
13
+ - `acknowledged` — number of events successfully posted and acknowledged
14
+ - `outstanding` — number of events not yet posted or acknowledged (`totalExpected - acknowledged`)
15
+ - The query aggregates data from subledger handoff event records and their acknowledgment status
16
+ - Returns the status for all registered subledger modules, even if a module has zero expected events
17
+ - Used by the period-end close workflow to determine whether subledger verification can pass
18
+
19
+ ## Process Flow
20
+
21
+ ```mermaid
22
+ flowchart TD
23
+ A[Receive input with accountingPeriodId] --> B[Query handoff events for the accounting period]
24
+ B --> C[Group events by source subledger module]
25
+ C --> D[For each module: count total expected events]
26
+ D --> E[For each module: count acknowledged events]
27
+ E --> F[For each module: compute outstanding = total - acknowledged]
28
+ F --> G[Return status per subledger module]
29
+ ```
30
+
31
+ ## External Dependencies
32
+
33
+ - None
34
+
35
+ ## Error Scenarios
36
+
37
+ - **ACCOUNTING_PERIOD_NOT_FOUND**: The specified accounting period does not exist — caller receives an error
38
+
39
+ ## Test Cases
40
+
41
+ - returns error when accounting period does not exist
42
+ - returns status for all 4 modules
43
+ - returns zero counts when no entries exist
44
+ - correctly counts posted vs draft entries
45
+ - returns correct outstanding counts
@@ -0,0 +1,38 @@
1
+ # GetTrialBalance
2
+
3
+ ## Overview
4
+
5
+ GetTrialBalance retrieves a single trial balance snapshot by id, including all line items. The trial balance record contains the generation parameters (companyId, accounting period, variant type, generation timestamp) and the full list of line items showing each GL account's opening balance, period debits, period credits, and closing balance. This query supports period-end review, financial statement preparation, and audit evidence retrieval.
6
+
7
+ ## Business Rules
8
+
9
+ - Accepts a single lookup parameter: `{ id }`
10
+ - Returns the full trial balance record including all line items
11
+ - Line items include account reference, opening balance, period debits, period credits, and closing balance
12
+ - Line items are organized by account group hierarchy and sorted by account code ascending within each group
13
+ - Returns null if no matching trial balance is found
14
+ - Lookup is an exact match on id
15
+
16
+ ## Process Flow
17
+
18
+ ```mermaid
19
+ flowchart TD
20
+ A[Receive input with id] --> B[SELECT from TrialBalance where id = input.id]
21
+ B --> C{Trial balance found?}
22
+ C -->|Yes| D[Load all associated line items]
23
+ D --> E[Return trial balance with line items]
24
+ C -->|No| F[Return null]
25
+ ```
26
+
27
+ ## External Dependencies
28
+
29
+ - None
30
+
31
+ ## Error Scenarios
32
+
33
+ - **TRIAL_BALANCE_NOT_FOUND**: No trial balance matches the given id — caller receives null
34
+
35
+ ## Test Cases
36
+
37
+ - returns trial balance with lines when found by id
38
+ - returns null with empty lines when not found