@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,53 @@
1
+ # ApproveAndLockPeriod
2
+
3
+ ## Overview
4
+
5
+ approveAndLockPeriod transitions a PeriodClose from UNDER_REVIEW to SOFT_LOCKED status, indicating that the accounting team has approved the period's financial data. A soft-locked period prevents the accounting team from posting new journal entries while still allowing users with the advisor/auditor role to post final adjustments. This supports segregation of duties in the close workflow.
6
+
7
+ ## Business Rules
8
+
9
+ - PeriodClose record must exist and be in UNDER_REVIEW status
10
+ - Only UNDER_REVIEW records can transition to SOFT_LOCKED
11
+ - Approval requires a user with the appropriate authorization role (e.g., controller or finance manager)
12
+ - Soft-locking a period prevents the accounting team from posting new journal entries to that period
13
+ - Soft-locked period still allows postings from users with the advisor/auditor role
14
+ - Updates completionPercentage to reflect progress
15
+ - Records the userId of the approver who locked the period
16
+ - Emits an audit event recording the acting user, timestamp, approval details, and status transition
17
+
18
+ ## Process Flow
19
+
20
+ ```mermaid
21
+ flowchart TD
22
+ A[Receive approve and lock request] --> B{PeriodClose record exists?}
23
+ B -->|No| C[Return error: period close not found]
24
+ B -->|Yes| D{PeriodClose in UNDER_REVIEW status?}
25
+ D -->|No| E[Return error: invalid status transition]
26
+ D -->|Yes| F{User has authorization role?}
27
+ F -->|No| G[Return error: insufficient permissions]
28
+ F -->|Yes| H[Transition PeriodClose to SOFT_LOCKED]
29
+ H --> I[Block accounting team postings for the period]
30
+ I --> J[Update completionPercentage]
31
+ J --> K[Emit audit event]
32
+ K --> L[Return updated PeriodClose]
33
+ ```
34
+
35
+ ## External Dependencies
36
+
37
+ - [user-management::listUserRolesByUser](../../../user-management/docs/queries/ListUserRolesByUser.md) - Validates that the acting user has the required authorization role (controller or finance manager)
38
+
39
+ ## Error Scenarios
40
+
41
+ - **PERIOD_CLOSE_NOT_FOUND**: No PeriodClose record matches the given id
42
+ - **INVALID_STATUS_TRANSITION**: PeriodClose is not in UNDER_REVIEW status; only UNDER_REVIEW can transition to SOFT_LOCKED
43
+ - **INSUFFICIENT_PERMISSIONS**: Acting user does not have the required authorization role (controller or finance manager)
44
+
45
+ ## Test Cases
46
+
47
+ - returns error when PeriodClose record does not exist
48
+ - returns error when PeriodClose is in NOT_STARTED status
49
+ - returns error when PeriodClose is in IN_PROGRESS status
50
+ - returns error when PeriodClose is already SOFT_LOCKED
51
+ - returns error when user lacks required permissions
52
+ - transitions UNDER_REVIEW PeriodClose to SOFT_LOCKED with approvedByUserId and completionPercentage
53
+ - emits audit event recording status transition from UNDER_REVIEW to SOFT_LOCKED
@@ -0,0 +1,47 @@
1
+ # BeginClose
2
+
3
+ ## Overview
4
+
5
+ beginClose transitions a PeriodClose record from NOT_STARTED to IN_PROGRESS status, indicating that the close checklist execution has begun. This is the first step after initiating the close and signals that the accounting team is actively working through the close workflow.
6
+
7
+ ## Business Rules
8
+
9
+ - PeriodClose record must exist and be identified by the period close `id`
10
+ - PeriodClose must be in NOT_STARTED status
11
+ - Only NOT_STARTED records can transition to IN_PROGRESS
12
+ - Records the userId of the operator who began the close
13
+ - Updates completionPercentage to reflect progress
14
+ - Emits an audit event via the audit module recording the acting user, timestamp, previous status (NOT_STARTED), and new status (IN_PROGRESS)
15
+
16
+ ## Process Flow
17
+
18
+ ```mermaid
19
+ flowchart TD
20
+ A[Receive begin close request] --> B{PeriodClose record exists?}
21
+ B -->|No| C[Return error: period close not found]
22
+ B -->|Yes| D{PeriodClose in NOT_STARTED status?}
23
+ D -->|No| E[Return error: invalid status transition]
24
+ D -->|Yes| F[Transition PeriodClose to IN_PROGRESS]
25
+ F --> G[Record acting user]
26
+ G --> H[Emit audit event]
27
+ H --> I[Return updated PeriodClose]
28
+ ```
29
+
30
+ ## External Dependencies
31
+
32
+ - None (same-module read for period close lookup)
33
+
34
+ ## Error Scenarios
35
+
36
+ - **PERIOD_CLOSE_NOT_FOUND**: No PeriodClose record matches the given id
37
+ - **INVALID_STATUS_TRANSITION**: PeriodClose is not in NOT_STARTED status; only NOT_STARTED can transition to IN_PROGRESS
38
+
39
+ ## Test Cases
40
+
41
+ - returns error when PeriodClose record does not exist
42
+ - returns error when PeriodClose is already IN_PROGRESS
43
+ - returns error when PeriodClose is in SUBLEDGERS_VERIFIED status
44
+ - returns error when PeriodClose is in PERMANENTLY_CLOSED status
45
+ - transitions NOT_STARTED PeriodClose to IN_PROGRESS
46
+ - records the acting user who began the close
47
+ - emits audit event recording status transition from NOT_STARTED to IN_PROGRESS and acting user
@@ -0,0 +1,45 @@
1
+ # ClosePeriod
2
+
3
+ ## Overview
4
+
5
+ closePeriod transitions an accounting period from OPEN to CLOSED status. A closed period no longer accepts routine journal entry postings. The transition is reversible -- a closed period can be reopened if adjustments are needed before permanent close. This supports the month-end close workflow where periods are closed after reconciliation but may need to be reopened for late-arriving transactions.
6
+
7
+ ## Business Rules
8
+
9
+ - Period must exist and be in OPEN status
10
+ - Only OPEN periods can transition to CLOSED
11
+ - After transition, journal entry postings to this period are rejected
12
+ - The transition is reversible via reopenPeriod
13
+ - Emits an audit event recording the status transition from OPEN to CLOSED, acting user, and timestamp
14
+
15
+ ## Process Flow
16
+
17
+ ```mermaid
18
+ flowchart TD
19
+ A[Receive closePeriod request] --> B{Period exists?}
20
+ B -->|No| C[Return error: period not found]
21
+ B -->|Yes| D{Period status is OPEN?}
22
+ D -->|No| E[Return error: invalid status transition]
23
+ D -->|Yes| F[Transition period to CLOSED]
24
+ F --> G[Emit audit event]
25
+ G --> H[Return updated period]
26
+ ```
27
+
28
+ ## External Dependencies
29
+
30
+ - None
31
+
32
+ ## Error Scenarios
33
+
34
+ - **ACCOUNTING_PERIOD_NOT_FOUND**: Referenced accounting period does not exist
35
+ - **INVALID_STATUS_TRANSITION**: Period is not in OPEN status; only OPEN periods can transition to CLOSED
36
+
37
+ ## Test Cases
38
+
39
+ - returns error when accounting period does not exist
40
+ - returns error when period is in NEVER_OPENED status
41
+ - returns error when period is in FUTURE_ENTERABLE status
42
+ - returns error when period is in CLOSED status
43
+ - returns error when period is in PERMANENTLY_CLOSED status
44
+ - transitions OPEN period to CLOSED
45
+ - emits audit event recording status transition from OPEN to CLOSED and acting user
@@ -0,0 +1,69 @@
1
+ # CreateAccountingPeriod
2
+
3
+ ## Overview
4
+
5
+ createAccountingPeriod establishes a new accounting period in NEVER_OPENED status within a fiscal year. Each period carries a name, start date, end date, period type (e.g., monthly, quarterly, adjustment), and is linked to a fiscal year via `fiscalYearId`. Periods represent the discrete time segments within a fiscal year that control when journal entries can be posted. The system validates that the period does not overlap with existing periods and that there are no gaps in coverage within the fiscal year.
6
+
7
+ ## Business Rules
8
+
9
+ - Period must reference a valid `fiscalYearId` belonging to the same company
10
+ - Period name is required and must be non-empty
11
+ - Start date and end date are required, with start date strictly before end date
12
+ - Period type is required (e.g., monthly, quarterly, adjustment)
13
+ - Periods within the same fiscal year must not have overlapping date ranges
14
+ - Periods within the same fiscal year must cover the full fiscal year date range without gaps
15
+ - Two periods in the same fiscal year cannot have identical start and end dates unless one is an adjustment period
16
+ - Adjustment periods share the same end date as the final regular period but are typed as adjustment
17
+ - Period is always created in NEVER_OPENED status
18
+ - Period must reference a valid `companyId`; the period is scoped to the same company as its fiscal year
19
+ - Emits an audit event via the audit module recording the acting user, timestamp, period details, and fiscal year reference
20
+
21
+ ## Process Flow
22
+
23
+ ```mermaid
24
+ flowchart TD
25
+ A[Receive create period request] --> B{Fiscal year exists and belongs to company?}
26
+ B -->|No| C[Return error: fiscal year not found]
27
+ B -->|Yes| D{Name non-empty?}
28
+ D -->|No| E[Return error: name required]
29
+ D -->|Yes| F{Start date before end date?}
30
+ F -->|No| G[Return error: invalid date range]
31
+ F -->|Yes| H{Overlaps with existing period in fiscal year?}
32
+ H -->|Yes| I[Return error: overlapping period]
33
+ H -->|No| J{Valid period type?}
34
+ J -->|No| K[Return error: invalid period type]
35
+ J -->|Yes| L[Create period in NEVER_OPENED status]
36
+ L --> M[Emit audit event]
37
+ M --> N[Return created period]
38
+ ```
39
+
40
+ ## External Dependencies
41
+
42
+ - [organization::getCompany](../../../organization/docs/queries/GetCompany.md) - Validates that the referenced company exists and is ACTIVE
43
+
44
+ ## Error Scenarios
45
+
46
+ - **FISCAL_YEAR_NOT_FOUND**: Referenced fiscal year does not exist or does not belong to the specified company
47
+ - **NAME_REQUIRED**: Period name is empty or not provided
48
+ - **INVALID_DATE_RANGE**: Start date is not strictly before end date
49
+ - **OVERLAPPING_PERIOD**: The date range overlaps with an existing period within the same fiscal year
50
+ - **INVALID_PERIOD_TYPE**: Period type is not a recognized value
51
+ - **DUPLICATE_PERIOD_DATES**: Two periods have identical start and end dates and neither is an adjustment period
52
+
53
+ ## Test Cases
54
+
55
+ - returns error when fiscal year does not exist
56
+ - returns error when fiscal year belongs to a different company
57
+ - returns error when name is empty
58
+ - returns error when start date is not before end date
59
+ - returns error when start date equals end date
60
+ - returns error when period type is invalid
61
+ - returns error when period overlaps with an existing period in the same fiscal year
62
+ - returns error when two periods have identical dates and neither is adjustment type
63
+ - creates period in NEVER_OPENED status with valid inputs
64
+ - creates 12 monthly periods with correct date boundaries for a calendar fiscal year
65
+ - creates 13 periods (12 operating + 1 adjustment) for a fiscal year
66
+ - adjustment period shares the same end date as the final regular period
67
+ - creates periods for a non-calendar fiscal year with correct boundaries
68
+ - periods are scoped to a company; periods from different companies are isolated
69
+ - emits audit event recording acting user, timestamp, and period details
@@ -0,0 +1,56 @@
1
+ # CreateFiscalYear
2
+
3
+ ## Overview
4
+
5
+ createFiscalYear establishes a new fiscal year record for a company. The fiscal year carries a name, start date, end date, and is scoped to a single company via `companyId`. Fiscal years serve as the top-level temporal grouping under which accounting periods are created. The system validates that the fiscal year does not overlap with any existing fiscal year for the same company.
6
+
7
+ ## Business Rules
8
+
9
+ - Fiscal year requires a valid `companyId` referencing an ACTIVE company from the organization module
10
+ - Fiscal year name is required and must be non-empty
11
+ - Start date and end date are required, with start date strictly before end date
12
+ - Fiscal year date range must not overlap with any existing fiscal year for the same company
13
+ - Supports non-calendar fiscal years (e.g., April-to-March, February-to-January)
14
+ - Supports 4-4-5 week structures and 13-period fiscal calendars
15
+ - Fiscal years are scoped to a company; records from different companies are isolated
16
+ - Emits an audit event via the audit module recording the acting user, timestamp, company reference, and fiscal year details
17
+
18
+ ## Process Flow
19
+
20
+ ```mermaid
21
+ flowchart TD
22
+ A[Receive create fiscal year request] --> B{Company exists and is ACTIVE?}
23
+ B -->|No| C[Return error: company not found or inactive]
24
+ B -->|Yes| D{Name non-empty?}
25
+ D -->|No| E[Return error: name required]
26
+ D -->|Yes| F{Start date before end date?}
27
+ F -->|No| G[Return error: invalid date range]
28
+ F -->|Yes| H{Overlaps with existing fiscal year?}
29
+ H -->|Yes| I[Return error: overlapping fiscal year]
30
+ H -->|No| J[Create fiscal year record]
31
+ J --> K[Emit audit event]
32
+ K --> L[Return created fiscal year]
33
+ ```
34
+
35
+ ## External Dependencies
36
+
37
+ - [organization::getCompany](../../../organization/docs/queries/GetCompany.md) - Validates that the referenced company exists and is ACTIVE
38
+
39
+ ## Error Scenarios
40
+
41
+ - **COMPANY_NOT_FOUND**: Referenced company does not exist or is not in ACTIVE status
42
+ - **NAME_REQUIRED**: Fiscal year name is empty or not provided
43
+ - **INVALID_DATE_RANGE**: Start date is not strictly before end date
44
+ - **OVERLAPPING_FISCAL_YEAR**: The date range overlaps with an existing fiscal year for the same company
45
+
46
+ ## Test Cases
47
+
48
+ - returns error when company does not exist
49
+ - returns error when company is not ACTIVE
50
+ - returns error when name is empty
51
+ - returns error when start date is not before end date
52
+ - returns error when fiscal year overlaps with an existing fiscal year for the same company
53
+ - creates fiscal year with valid name, start date, and end date
54
+ - creates non-calendar fiscal year (e.g., April-to-March) with correct date boundaries
55
+ - fiscal years from different companies are isolated
56
+ - emits audit event recording acting user, timestamp, company reference, and fiscal year details
@@ -0,0 +1,63 @@
1
+ # CreateJournalEntry
2
+
3
+ ## Overview
4
+
5
+ createJournalEntry establishes a new journal entry in DRAFT status within the general ledger. The journal entry header carries a company reference, accounting period reference, journal type (Sales, Purchase, Cash, Bank, Miscellaneous, Opening), reference number, entry date, optional description, and optional source document reference. Journal entries are the fundamental transactional unit of double-entry bookkeeping; lines are added separately via addJournalLine before the entry can be posted.
6
+
7
+ ## Business Rules
8
+
9
+ - Journal entry is always created in DRAFT status
10
+ - Requires a valid `companyId` referencing an ACTIVE company from the organization module
11
+ - Requires a valid `accountingPeriodId` referencing an existing accounting period
12
+ - Requires a valid journal type: Sales, Purchase, Cash, Bank, Miscellaneous, or Opening
13
+ - Requires a reference number that is unique within the company scope
14
+ - Requires a valid entry date
15
+ - Description is optional and can be set on creation
16
+ - Source document reference is optional and can be set on creation
17
+ - Journal entries are scoped to a company; entries from different companies are fully isolated
18
+ - Emits an audit event via the audit module recording the acting user, timestamp, and initial field values
19
+
20
+ ## Process Flow
21
+
22
+ ```mermaid
23
+ flowchart TD
24
+ A[Receive create journal entry request] --> B{Company exists and is ACTIVE?}
25
+ B -->|No| C[Return error: company not found]
26
+ B -->|Yes| D{Accounting period exists?}
27
+ D -->|No| E[Return error: period not found]
28
+ D -->|Yes| F{Valid journal type?}
29
+ F -->|No| G[Return error: invalid journal type]
30
+ F -->|Yes| H{Reference number unique within company?}
31
+ H -->|No| I[Return error: duplicate reference number]
32
+ H -->|Yes| J{Valid entry date?}
33
+ J -->|No| K[Return error: invalid entry date]
34
+ J -->|Yes| L[Create journal entry in DRAFT status]
35
+ L --> M[Emit audit event]
36
+ M --> N[Return created journal entry]
37
+ ```
38
+
39
+ ## External Dependencies
40
+
41
+ - [organization::getCompany](../../../organization/docs/queries/GetCompany.md) - Validates that the referenced company exists and is ACTIVE
42
+
43
+ ## Error Scenarios
44
+
45
+ - **COMPANY_NOT_FOUND**: Referenced company does not exist or is not in ACTIVE status
46
+ - **ACCOUNTING_PERIOD_NOT_FOUND**: Referenced accounting period does not exist
47
+ - **INVALID_JOURNAL_TYPE**: Journal type is not one of the recognized values (Sales, Purchase, Cash, Bank, Miscellaneous, Opening)
48
+ - **DUPLICATE_REFERENCE_NUMBER**: A journal entry with the same reference number already exists within the company
49
+ - **INVALID_ENTRY_DATE**: Entry date is not a valid date
50
+
51
+ ## Test Cases
52
+
53
+ - returns error when company does not exist
54
+ - returns error when company is not ACTIVE
55
+ - returns error when accounting period does not exist
56
+ - returns error when journal type is invalid
57
+ - returns error when reference number already exists within the company
58
+ - returns error when entry date is invalid
59
+ - creates journal entry in DRAFT status with required fields
60
+ - creates journal entry with optional description
61
+ - creates journal entry with optional source document reference
62
+ - journal entries from different companies are isolated
63
+ - emits audit event recording acting user, timestamp, and initial field values
@@ -0,0 +1,46 @@
1
+ # DeleteAccountingPeriod
2
+
3
+ ## Overview
4
+
5
+ deleteAccountingPeriod permanently removes an accounting period record. Deletion is only permitted when the period has no associated journal entries, regardless of their status (DRAFT, POSTED, or REVERSED). This prevents orphaned financial data and maintains referential integrity within the general ledger.
6
+
7
+ ## Business Rules
8
+
9
+ - Accounting period must exist and be identified by `id`
10
+ - Accounting period cannot be deleted if it has any associated journal entries regardless of status
11
+ - Accounting period cannot be deleted if it has an active PeriodClose record
12
+ - Deletion is a hard delete — the record is permanently removed
13
+ - Emits an audit event via the audit module recording the acting user, timestamp, and deleted period details
14
+
15
+ ## Process Flow
16
+
17
+ ```mermaid
18
+ flowchart TD
19
+ A[Receive delete accounting period request] --> B{Accounting period exists?}
20
+ B -->|No| C[Return error: period not found]
21
+ B -->|Yes| D{Journal entries exist for this period?}
22
+ D -->|Yes| E[Return error: has associated journal entries]
23
+ D -->|No| F{Active PeriodClose exists?}
24
+ F -->|Yes| G[Return error: has active close in progress]
25
+ F -->|No| H[Delete accounting period record]
26
+ H --> I[Emit audit event]
27
+ I --> J[Return success]
28
+ ```
29
+
30
+ ## External Dependencies
31
+
32
+ - None (same-module read for period, journal entry, and period close lookup)
33
+
34
+ ## Error Scenarios
35
+
36
+ - **ACCOUNTING_PERIOD_NOT_FOUND**: No accounting period matches the given id
37
+ - **HAS_ASSOCIATED_JOURNAL_ENTRIES**: Accounting period has one or more journal entries and cannot be deleted
38
+ - **HAS_ACTIVE_PERIOD_CLOSE**: Accounting period has an active period close record in progress
39
+
40
+ ## Test Cases
41
+
42
+ - returns error when accounting period does not exist
43
+ - returns error when accounting period has associated journal entries
44
+ - returns error when accounting period has an active period close record
45
+ - deletes accounting period with no associated journal entries or period close
46
+ - emits audit event recording acting user, timestamp, and deleted period details
@@ -0,0 +1,40 @@
1
+ # DeleteFiscalYear
2
+
3
+ ## Overview
4
+
5
+ deleteFiscalYear permanently removes a fiscal year record. Deletion is only permitted when the fiscal year has no associated accounting periods, ensuring that period data and any downstream journal entries are never orphaned.
6
+
7
+ ## Business Rules
8
+
9
+ - Fiscal year must exist and be identified by `id`
10
+ - Fiscal year cannot be deleted if it has any associated accounting periods
11
+ - Deletion is a hard delete — the record is permanently removed
12
+ - Emits an audit event via the audit module recording the acting user, timestamp, and deleted fiscal year details
13
+
14
+ ## Process Flow
15
+
16
+ ```mermaid
17
+ flowchart TD
18
+ A[Receive delete fiscal year request] --> B{Fiscal year exists?}
19
+ B -->|No| C[Return error: fiscal year not found]
20
+ B -->|Yes| D{Accounting periods exist for this fiscal year?}
21
+ D -->|Yes| E[Return error: has associated periods]
22
+ D -->|No| F[Delete fiscal year record]
23
+ F --> G[Emit audit event]
24
+ G --> H[Return success]
25
+ ```
26
+
27
+ ## External Dependencies
28
+
29
+ - None (same-module read for fiscal year and period lookup)
30
+
31
+ ## Error Scenarios
32
+
33
+ - **FISCAL_YEAR_NOT_FOUND**: No fiscal year matches the given id
34
+ - **HAS_ASSOCIATED_PERIODS**: Fiscal year has one or more accounting periods and cannot be deleted
35
+
36
+ ## Test Cases
37
+
38
+ - returns error when fiscal year does not exist
39
+ - returns error when fiscal year has associated accounting periods
40
+ - deletes fiscal year with no associated accounting periods
@@ -0,0 +1,44 @@
1
+ # DeleteJournalEntry
2
+
3
+ ## Overview
4
+
5
+ deleteJournalEntry removes a journal entry and all its associated journal lines from the system. Only DRAFT entries can be deleted. Posted entries must be reversed rather than deleted to preserve the audit trail. Reversed entries also cannot be deleted. This ensures that all financial transactions that have affected the general ledger remain traceable.
6
+
7
+ ## Business Rules
8
+
9
+ - Journal entry must exist and be in DRAFT status
10
+ - Only DRAFT entries can be deleted; POSTED and REVERSED entries cannot be deleted
11
+ - Deleting a DRAFT entry removes all associated journal lines
12
+ - Posted entries must be reversed via reverseJournalEntry instead of deleted
13
+ - Emits an audit event recording the deletion, acting user, and timestamp
14
+
15
+ ## Process Flow
16
+
17
+ ```mermaid
18
+ flowchart TD
19
+ A[Receive delete journal entry request] --> B{Journal entry exists?}
20
+ B -->|No| C[Return error: journal entry not found]
21
+ B -->|Yes| D{Entry status is DRAFT?}
22
+ D -->|No| E[Return error: cannot delete non-draft entry]
23
+ D -->|Yes| F[Delete all associated journal lines]
24
+ F --> G[Delete journal entry]
25
+ G --> H[Emit audit event]
26
+ H --> I[Return success]
27
+ ```
28
+
29
+ ## External Dependencies
30
+
31
+ - None
32
+
33
+ ## Error Scenarios
34
+
35
+ - **JOURNAL_ENTRY_NOT_FOUND**: Referenced journal entry does not exist
36
+ - **INVALID_STATUS_FOR_DELETE**: Journal entry is not in DRAFT status; POSTED and REVERSED entries cannot be deleted
37
+
38
+ ## Test Cases
39
+
40
+ - returns error when journal entry does not exist
41
+ - returns error when journal entry is in POSTED status
42
+ - returns error when journal entry is in REVERSED status
43
+ - deletes DRAFT journal entry and all associated journal lines
44
+ - emits audit event recording the deletion and acting user
@@ -0,0 +1,81 @@
1
+ # ExecuteYearEndClose
2
+
3
+ ## Overview
4
+
5
+ executeYearEndClose runs the fiscal year-end close process on the final period of a fiscal year. It generates a closing journal entry that zeroes out all temporary accounts (REVENUE and EXPENSE types) and transfers the net income or net loss to the retained earnings account. It then generates opening balance entries for the first period of the new fiscal year, carrying forward all permanent account balances (ASSET, LIABILITY, EQUITY). This command can only be executed after the final period's standard close checklist has been completed.
6
+
7
+ ## Business Rules
8
+
9
+ - Can only be initiated for the final period of a fiscal year
10
+ - Initiating year-end close for a non-final period is rejected
11
+ - Requires the final period's standard close checklist to be completed through the soft-lock or permanent close stage
12
+ - Identifies all temporary accounts (REVENUE and EXPENSE types) with posted journal lines during the fiscal year
13
+ - Calculates net income or net loss: total revenue minus total expenses
14
+ - Looks up the retained earnings account from the CoA configuration (account with RETAINED_EARNINGS operational classification)
15
+ - Fails if no account with RETAINED_EARNINGS operational classification exists in the active CoA
16
+ - Generates a closing journal entry that debits all revenue accounts to zero and credits all expense accounts to zero
17
+ - Posts the net difference (net income/loss) to the retained earnings account
18
+ - The closing journal entry must be balanced (total debits equal total credits)
19
+ - The closing journal entry is flagged with a distinct journal type (CLOSING)
20
+ - The closing entry is posted to the final period of the fiscal year
21
+ - Only accounts with posted journal lines during the fiscal year are included in the closing entry (zero-balance temporary accounts are excluded)
22
+ - Generates opening balance entries for all permanent accounts (ASSET, LIABILITY, EQUITY types)
23
+ - Opening balance entries carry the correct closing balance from each permanent account, including updated retained earnings
24
+ - Opening balance entries are posted to the first period of the new fiscal year
25
+ - Opening balance entries are flagged with a distinct journal type (OPENING)
26
+ - The sum of all opening balance debits equals the sum of all opening balance credits
27
+ - Opening balances are only generated if the new fiscal year's periods exist
28
+ - Fails gracefully if the new fiscal year has not been defined
29
+ - Year-end close cannot be run twice for the same fiscal year; duplicate attempts are rejected
30
+ - After year-end close, the final period of the old fiscal year is permanently closed
31
+ - Year-end close is scoped to a single company
32
+ - Emits audit events recording each step: closing entry generation, retained earnings posting, opening balance generation
33
+
34
+ ## Process Flow
35
+
36
+ ```mermaid
37
+ flowchart TD
38
+ A[Receive execute year-end close request] --> B{Period is the final period of a fiscal year?}
39
+ B -->|No| C[Return error: not final period]
40
+ B -->|Yes| D{Standard close checklist completed?}
41
+ D -->|No| E[Return error: standard close not complete]
42
+ D -->|Yes| F{Already run for this fiscal year?}
43
+ F -->|Yes| G[Return error: duplicate year-end close]
44
+ F -->|No| H[Identify all REVENUE and EXPENSE accounts with activity]
45
+ H --> I[Calculate net income/loss]
46
+ I --> J{Retained earnings account configured in CoA?}
47
+ J -->|No| K[Return error: retained earnings account required]
48
+ J -->|Yes| L[Generate closing journal entry]
49
+ L --> M[Debit revenue accounts to zero, credit expense accounts to zero]
50
+ M --> N[Post net difference to retained earnings]
51
+ N --> O{New fiscal year periods exist?}
52
+ O -->|No| P[Return error: new fiscal year not defined]
53
+ O -->|Yes| Q[Generate opening balance entries for permanent accounts]
54
+ Q --> R[Post opening balances to first period of new fiscal year]
55
+ R --> S[Permanently close final period]
56
+ S --> T[Emit audit events]
57
+ T --> U[Return year-end close result]
58
+ ```
59
+
60
+ ## External Dependencies
61
+
62
+ - [coa-management::getChartOfAccounts](../../../coa-management/docs/queries/GetChartOfAccounts.md) - Retrieves the active CoA, account types, and retained earnings account configuration
63
+ - [coa-management::getAccount](../../../coa-management/docs/queries/GetAccount.md) - Retrieves individual GL accounts for closing and opening entries
64
+
65
+ ## Error Scenarios
66
+
67
+ - **NOT_FINAL_PERIOD**: The specified period is not the final period of its fiscal year
68
+ - **STANDARD_CLOSE_NOT_COMPLETE**: The final period's standard close checklist has not been completed through soft-lock or permanent close
69
+ - **DUPLICATE_YEAR_END_CLOSE**: Year-end close has already been executed for this fiscal year
70
+ - **RETAINED_EARNINGS_ACCOUNT_NOT_FOUND**: No account with RETAINED_EARNINGS operational classification exists in the active CoA
71
+ - **NEW_FISCAL_YEAR_NOT_DEFINED**: The new fiscal year has not been defined; opening balance entries cannot be generated
72
+
73
+ ## Test Cases
74
+
75
+ - returns error when accounting period does not exist
76
+ - returns error when period is not the final period of its fiscal year
77
+ - returns error when standard close checklist is not complete
78
+ - returns error when year-end close has already been executed
79
+ - returns error when no retained earnings account exists
80
+ - returns error when no new fiscal year is defined
81
+ - successfully executes year-end close
@@ -0,0 +1,49 @@
1
+ # FinalCloseAndLockPeriod
2
+
3
+ ## Overview
4
+
5
+ finalCloseAndLockPeriod transitions a PeriodClose from SOFT_LOCKED to PERMANENTLY_CLOSED status. This is the final step in the period-end close workflow. Once permanently closed, the accounting period becomes fully immutable — no further journal entries can be posted regardless of user role, and the period cannot be reopened. The underlying AccountingPeriod is also transitioned to PERMANENTLY_CLOSED status.
6
+
7
+ ## Business Rules
8
+
9
+ - PeriodClose record must exist and be in SOFT_LOCKED status
10
+ - Only SOFT_LOCKED records can transition to PERMANENTLY_CLOSED
11
+ - Permanently closing a period makes it fully immutable; no further journal entries can be posted regardless of role
12
+ - The underlying AccountingPeriod is transitioned to PERMANENTLY_CLOSED status
13
+ - A permanently closed period cannot be reverted
14
+ - Updates completionPercentage to 100%
15
+ - Records the userId of the operator who finalized the close
16
+ - Emits an audit event recording the acting user, timestamp, and irreversible status transition
17
+
18
+ ## Process Flow
19
+
20
+ ```mermaid
21
+ flowchart TD
22
+ A[Receive final close and lock request] --> B{PeriodClose record exists?}
23
+ B -->|No| C[Return error: period close not found]
24
+ B -->|Yes| D{PeriodClose in SOFT_LOCKED status?}
25
+ D -->|No| E[Return error: invalid status transition]
26
+ D -->|Yes| F[Transition PeriodClose to PERMANENTLY_CLOSED]
27
+ F --> G[Transition AccountingPeriod to PERMANENTLY_CLOSED]
28
+ G --> H[Set completionPercentage to 100%]
29
+ H --> I[Emit audit event]
30
+ I --> J[Return finalized PeriodClose]
31
+ ```
32
+
33
+ ## External Dependencies
34
+
35
+ - None (same-module mutation for accounting period status transition)
36
+
37
+ ## Error Scenarios
38
+
39
+ - **PERIOD_CLOSE_NOT_FOUND**: No PeriodClose record matches the given id
40
+ - **INVALID_STATUS_TRANSITION**: PeriodClose is not in SOFT_LOCKED status; only SOFT_LOCKED can transition to PERMANENTLY_CLOSED
41
+
42
+ ## Test Cases
43
+
44
+ - returns error when PeriodClose record does not exist
45
+ - returns error when PeriodClose is in UNDER_REVIEW status
46
+ - returns error when PeriodClose is in IN_PROGRESS status
47
+ - transitions SOFT_LOCKED PeriodClose to PERMANENTLY_CLOSED with completionPercentage 100
48
+ - also updates the associated AccountingPeriod to PERMANENTLY_CLOSED
49
+ - emits audit event recording status transition from SOFT_LOCKED to PERMANENTLY_CLOSED
@@ -0,0 +1,43 @@
1
+ # FinalizeFinancialStatement
2
+
3
+ ## Overview
4
+
5
+ finalizeFinancialStatement transitions a financial statement from DRAFT to FINALIZED status, making it immutable. Once finalized, the statement's line items, parameters, and output cannot be modified or regenerated. This ensures that published financial statements maintain their integrity for audit and regulatory purposes.
6
+
7
+ ## Business Rules
8
+
9
+ - Financial statement must exist and be identified by `id`
10
+ - Financial statement must be in DRAFT status
11
+ - FINALIZED statements cannot be finalized again (no-op / invalid status transition)
12
+ - Once finalized, the statement is immutable — line items, parameters, and output cannot be modified
13
+ - A FINALIZED statement cannot be regenerated
14
+ - Emits an audit event via the audit module recording the status transition from DRAFT to FINALIZED, acting user, and timestamp
15
+
16
+ ## Process Flow
17
+
18
+ ```mermaid
19
+ flowchart TD
20
+ A[Receive finalize statement request] --> B{Financial statement exists?}
21
+ B -->|No| C[Return error: statement not found]
22
+ B -->|Yes| D{Statement in DRAFT status?}
23
+ D -->|No| E[Return error: invalid status transition]
24
+ D -->|Yes| F[Transition statement to FINALIZED]
25
+ F --> G[Emit audit event]
26
+ G --> H[Return finalized statement]
27
+ ```
28
+
29
+ ## External Dependencies
30
+
31
+ - None (same-module read for financial statement lookup)
32
+
33
+ ## Error Scenarios
34
+
35
+ - **FINANCIAL_STATEMENT_NOT_FOUND**: No financial statement matches the given id
36
+ - **INVALID_STATUS_TRANSITION**: Financial statement is not in DRAFT status; only DRAFT statements can be finalized. Also applies when attempting to finalize an already FINALIZED statement
37
+
38
+ ## Test Cases
39
+
40
+ - returns error when financial statement does not exist
41
+ - returns error when financial statement is already FINALIZED
42
+ - transitions DRAFT statement to FINALIZED with finalizedAt set
43
+ - emits audit event recording status transition from DRAFT to FINALIZED