@rfc0/patty 0.0.0-stage → 1.0.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 (465) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +214 -2
  3. package/dist/adapters/access-tokens.js +7 -0
  4. package/dist/adapters/accounts.js +37 -0
  5. package/dist/adapters/auth.js +11 -0
  6. package/dist/adapters/bills.js +32 -0
  7. package/dist/adapters/budgets.js +29 -0
  8. package/dist/adapters/categories.js +32 -0
  9. package/dist/adapters/client-grants.js +7 -0
  10. package/dist/adapters/credit-cards.js +33 -0
  11. package/dist/adapters/currencies.js +2 -0
  12. package/dist/adapters/currency-rates.js +18 -0
  13. package/dist/adapters/dashboards.js +43 -0
  14. package/dist/adapters/demo.js +13 -0
  15. package/dist/adapters/instance-settings.js +7 -0
  16. package/dist/adapters/invites.js +7 -0
  17. package/dist/adapters/recurring.js +55 -0
  18. package/dist/adapters/sessions.js +7 -0
  19. package/dist/adapters/settings.js +4 -0
  20. package/dist/adapters/setup-codes.js +7 -0
  21. package/dist/adapters/tags.js +9 -0
  22. package/dist/adapters/transactions.js +95 -0
  23. package/dist/adapters/users.js +7 -0
  24. package/dist/common/build-version.js +5 -0
  25. package/dist/common/errors.js +118 -0
  26. package/dist/common/net.js +71 -0
  27. package/dist/common/result.js +7 -0
  28. package/dist/composition/auth.js +106 -0
  29. package/dist/composition/boot.js +27 -0
  30. package/dist/composition/cli.js +86 -0
  31. package/dist/composition/demo/seed.js +92 -0
  32. package/dist/composition/demo/shell.js +107 -0
  33. package/dist/composition/export.js +89 -0
  34. package/dist/composition/http.js +110 -0
  35. package/dist/composition/import.js +55 -0
  36. package/dist/composition/lazy-modules.js +2 -0
  37. package/dist/composition/runtime.js +115 -0
  38. package/dist/composition/sign-in/interpreter.js +154 -0
  39. package/dist/composition/sign-in/server.js +36 -0
  40. package/dist/composition/sign-in/wiring.js +23 -0
  41. package/dist/composition/stdio.js +69 -0
  42. package/dist/config.js +136 -0
  43. package/dist/controllers/account/account.js +88 -0
  44. package/dist/controllers/account/transaction.js +119 -0
  45. package/dist/controllers/account/transfer.js +34 -0
  46. package/dist/controllers/aggregate.js +40 -0
  47. package/dist/controllers/auth/access-tokens.js +61 -0
  48. package/dist/controllers/auth/grants.js +136 -0
  49. package/dist/controllers/auth/key-export.js +20 -0
  50. package/dist/controllers/auth/owner.js +80 -0
  51. package/dist/controllers/auth/password.js +35 -0
  52. package/dist/controllers/auth/session.js +50 -0
  53. package/dist/controllers/auth/step-up.js +8 -0
  54. package/dist/controllers/auth/users.js +183 -0
  55. package/dist/controllers/budgets.js +87 -0
  56. package/dist/controllers/categories.js +67 -0
  57. package/dist/controllers/correlations.js +112 -0
  58. package/dist/controllers/credit-card/bill.js +105 -0
  59. package/dist/controllers/credit-card/credit-card.js +129 -0
  60. package/dist/controllers/credit-card/transaction.js +181 -0
  61. package/dist/controllers/currencies.js +1 -0
  62. package/dist/controllers/currency-rates.js +40 -0
  63. package/dist/controllers/dashboards.js +68 -0
  64. package/dist/controllers/demo/seed.js +31 -0
  65. package/dist/controllers/demo/tour.js +12 -0
  66. package/dist/controllers/deps.js +6 -0
  67. package/dist/controllers/instance.js +6 -0
  68. package/dist/controllers/merchants.js +12 -0
  69. package/dist/controllers/recurring.js +70 -0
  70. package/dist/controllers/resolve.js +37 -0
  71. package/dist/controllers/settings.js +47 -0
  72. package/dist/controllers/status.js +19 -0
  73. package/dist/controllers/summary.js +21 -0
  74. package/dist/controllers/tags.js +19 -0
  75. package/dist/controllers/transaction/bulk.js +6 -0
  76. package/dist/controllers/transaction/core.js +49 -0
  77. package/dist/controllers/transaction/read.js +28 -0
  78. package/dist/diplomat/auth/credentials.js +58 -0
  79. package/dist/diplomat/auth/sign-in-store.js +18 -0
  80. package/dist/diplomat/cli/commands/auth.js +100 -0
  81. package/dist/diplomat/cli/commands/db.js +72 -0
  82. package/dist/diplomat/cli/commands/demo.js +68 -0
  83. package/dist/diplomat/cli/commands/key.js +119 -0
  84. package/dist/diplomat/cli/commands/login.js +151 -0
  85. package/dist/diplomat/cli/commands/setup.js +132 -0
  86. package/dist/diplomat/cli/commands/users.js +123 -0
  87. package/dist/diplomat/cli/commands.js +61 -0
  88. package/dist/diplomat/cli/export-file.js +37 -0
  89. package/dist/diplomat/cli/import-file.js +44 -0
  90. package/dist/diplomat/cli/io.js +61 -0
  91. package/dist/diplomat/cli/key-export-approval.js +37 -0
  92. package/dist/diplomat/cli/messages.js +96 -0
  93. package/dist/diplomat/cli/prompt.js +74 -0
  94. package/dist/diplomat/cli/terminal.js +81 -0
  95. package/dist/diplomat/client-config/clients.js +150 -0
  96. package/dist/diplomat/client-config/merge.js +41 -0
  97. package/dist/diplomat/db/bootstrap.js +98 -0
  98. package/dist/diplomat/db/database-files.js +147 -0
  99. package/dist/diplomat/db/driver.js +167 -0
  100. package/dist/diplomat/db/effects.js +101 -0
  101. package/dist/diplomat/db/engine.js +9 -0
  102. package/dist/diplomat/db/export.js +22 -0
  103. package/dist/diplomat/db/file-lock.js +82 -0
  104. package/dist/diplomat/db/key-lock.js +14 -0
  105. package/dist/diplomat/db/locale-cache.js +23 -0
  106. package/dist/diplomat/db/migration-barrier.js +57 -0
  107. package/dist/diplomat/db/migration-journal.js +18 -0
  108. package/dist/diplomat/db/migration-lock.js +15 -0
  109. package/dist/diplomat/db/migrations.js +11 -0
  110. package/dist/diplomat/db/present.js +17 -0
  111. package/dist/diplomat/db/queries/aggregate-whitelist.js +35 -0
  112. package/dist/diplomat/db/queries/filters.js +59 -0
  113. package/dist/diplomat/db/queries/fts.js +18 -0
  114. package/dist/diplomat/db/queries/scope.js +8 -0
  115. package/dist/diplomat/db/queries/transaction-select.js +26 -0
  116. package/dist/diplomat/db/queries/tx-predicates.js +13 -0
  117. package/dist/diplomat/db/repos/access-tokens.js +27 -0
  118. package/dist/diplomat/db/repos/accounts.js +91 -0
  119. package/dist/diplomat/db/repos/bills.js +93 -0
  120. package/dist/diplomat/db/repos/budgets.js +72 -0
  121. package/dist/diplomat/db/repos/categories.js +53 -0
  122. package/dist/diplomat/db/repos/client-grants.js +67 -0
  123. package/dist/diplomat/db/repos/correlations.js +66 -0
  124. package/dist/diplomat/db/repos/credit-cards.js +67 -0
  125. package/dist/diplomat/db/repos/currencies.js +8 -0
  126. package/dist/diplomat/db/repos/currency-rates.js +40 -0
  127. package/dist/diplomat/db/repos/dashboards.js +123 -0
  128. package/dist/diplomat/db/repos/health.js +12 -0
  129. package/dist/diplomat/db/repos/instance-settings.js +14 -0
  130. package/dist/diplomat/db/repos/instance.js +58 -0
  131. package/dist/diplomat/db/repos/invites.js +43 -0
  132. package/dist/diplomat/db/repos/merchants.js +121 -0
  133. package/dist/diplomat/db/repos/recurring.js +29 -0
  134. package/dist/diplomat/db/repos/sessions.js +19 -0
  135. package/dist/diplomat/db/repos/settings.js +41 -0
  136. package/dist/diplomat/db/repos/setup-codes.js +28 -0
  137. package/dist/diplomat/db/repos/sub-categories.js +67 -0
  138. package/dist/diplomat/db/repos/tags.js +51 -0
  139. package/dist/diplomat/db/repos/transaction-tags.js +57 -0
  140. package/dist/diplomat/db/repos/transactions.js +163 -0
  141. package/dist/diplomat/db/repos/users.js +47 -0
  142. package/dist/diplomat/db/safety-copy.js +87 -0
  143. package/dist/diplomat/db/schema.js +348 -0
  144. package/dist/diplomat/db/seed/categories.js +112 -0
  145. package/dist/diplomat/db/seed/currencies.js +9 -0
  146. package/dist/diplomat/db/seed/demo/br.js +98 -0
  147. package/dist/diplomat/db/seed/demo/co.js +89 -0
  148. package/dist/diplomat/db/seed/demo/index.js +12 -0
  149. package/dist/diplomat/db/seed/demo/mx.js +90 -0
  150. package/dist/diplomat/db/seed/demo/shared.js +39 -0
  151. package/dist/diplomat/db/seed/demo/us.js +90 -0
  152. package/dist/diplomat/db/seed/merchant-rules.js +188 -0
  153. package/dist/diplomat/db/sqlite-errors.js +40 -0
  154. package/dist/diplomat/db/tenancy-integrity.js +45 -0
  155. package/dist/diplomat/db/version-guard.js +16 -0
  156. package/dist/diplomat/http/auth-pages.js +41 -0
  157. package/dist/diplomat/http/auth-paths.js +46 -0
  158. package/dist/diplomat/http/bearer.js +15 -0
  159. package/dist/diplomat/http/connect-pages.js +51 -0
  160. package/dist/diplomat/http/context.js +17 -0
  161. package/dist/diplomat/http/cookies.js +27 -0
  162. package/dist/diplomat/http/form-pages.js +38 -0
  163. package/dist/diplomat/http/hooks/auth.js +106 -0
  164. package/dist/diplomat/http/hooks/demo-marker.js +59 -0
  165. package/dist/diplomat/http/openapi.js +73 -0
  166. package/dist/diplomat/http/principal.js +1 -0
  167. package/dist/diplomat/http/rate-limiter.js +78 -0
  168. package/dist/diplomat/http/remedy.js +26 -0
  169. package/dist/diplomat/http/respond.js +50 -0
  170. package/dist/diplomat/http/routes/account.js +226 -0
  171. package/dist/diplomat/http/routes/aggregate.js +28 -0
  172. package/dist/diplomat/http/routes/auth.js +105 -0
  173. package/dist/diplomat/http/routes/budget.js +34 -0
  174. package/dist/diplomat/http/routes/category.js +109 -0
  175. package/dist/diplomat/http/routes/connect.js +124 -0
  176. package/dist/diplomat/http/routes/credit-card.js +263 -0
  177. package/dist/diplomat/http/routes/currency-rates.js +60 -0
  178. package/dist/diplomat/http/routes/currency.js +16 -0
  179. package/dist/diplomat/http/routes/dashboard.js +93 -0
  180. package/dist/diplomat/http/routes/invite.js +63 -0
  181. package/dist/diplomat/http/routes/recurring.js +65 -0
  182. package/dist/diplomat/http/routes/settings.js +38 -0
  183. package/dist/diplomat/http/routes/summary.js +23 -0
  184. package/dist/diplomat/http/routes/system.js +29 -0
  185. package/dist/diplomat/http/routes/tag.js +51 -0
  186. package/dist/diplomat/http/routes/tokens.js +72 -0
  187. package/dist/diplomat/http/routes/transaction.js +55 -0
  188. package/dist/diplomat/http/routes/transfer.js +35 -0
  189. package/dist/diplomat/http/routes/ui.js +110 -0
  190. package/dist/diplomat/http/routes/users.js +156 -0
  191. package/dist/diplomat/http/routes/well-known.js +26 -0
  192. package/dist/diplomat/http/routes.js +85 -0
  193. package/dist/diplomat/http/session.js +34 -0
  194. package/dist/diplomat/http/token-pages.js +75 -0
  195. package/dist/diplomat/http/ui-files.js +21 -0
  196. package/dist/diplomat/http/user-pages.js +93 -0
  197. package/dist/diplomat/mcp/annotations.js +8 -0
  198. package/dist/diplomat/mcp/auth-info.js +20 -0
  199. package/dist/diplomat/mcp/context.js +14 -0
  200. package/dist/diplomat/mcp/definition.js +3 -0
  201. package/dist/diplomat/mcp/gate.js +15 -0
  202. package/dist/diplomat/mcp/instructions.js +19 -0
  203. package/dist/diplomat/mcp/prompts.js +125 -0
  204. package/dist/diplomat/mcp/register.js +12 -0
  205. package/dist/diplomat/mcp/remedy.js +17 -0
  206. package/dist/diplomat/mcp/resources.js +93 -0
  207. package/dist/diplomat/mcp/respond.js +20 -0
  208. package/dist/diplomat/mcp/route.js +62 -0
  209. package/dist/diplomat/mcp/scopes.js +53 -0
  210. package/dist/diplomat/mcp/server.js +26 -0
  211. package/dist/diplomat/mcp/shared.js +5 -0
  212. package/dist/diplomat/mcp/stdio-session.js +94 -0
  213. package/dist/diplomat/mcp/stdio.js +23 -0
  214. package/dist/diplomat/mcp/tool-name.js +59 -0
  215. package/dist/diplomat/mcp/tools/account.js +218 -0
  216. package/dist/diplomat/mcp/tools/aggregate.js +32 -0
  217. package/dist/diplomat/mcp/tools/budget.js +99 -0
  218. package/dist/diplomat/mcp/tools/category.js +103 -0
  219. package/dist/diplomat/mcp/tools/correlations.js +70 -0
  220. package/dist/diplomat/mcp/tools/credit-card.js +239 -0
  221. package/dist/diplomat/mcp/tools/currency-rates.js +62 -0
  222. package/dist/diplomat/mcp/tools/dashboard.js +75 -0
  223. package/dist/diplomat/mcp/tools/index.js +31 -0
  224. package/dist/diplomat/mcp/tools/recurring.js +62 -0
  225. package/dist/diplomat/mcp/tools/summary.js +30 -0
  226. package/dist/diplomat/mcp/tools/system.js +83 -0
  227. package/dist/diplomat/mcp/tools/tag.js +48 -0
  228. package/dist/diplomat/mcp/tools/transaction.js +53 -0
  229. package/dist/diplomat/mcp/tools/transfer.js +28 -0
  230. package/dist/diplomat/mcp/tour.js +87 -0
  231. package/dist/logic/account.js +79 -0
  232. package/dist/logic/aggregate.js +37 -0
  233. package/dist/logic/auth/bearer.js +35 -0
  234. package/dist/logic/auth/grant.js +126 -0
  235. package/dist/logic/auth/key-export.js +10 -0
  236. package/dist/logic/auth/keychain.js +3 -0
  237. package/dist/logic/auth/message.js +22 -0
  238. package/dist/logic/auth/origin.js +57 -0
  239. package/dist/logic/auth/owner.js +22 -0
  240. package/dist/logic/auth/password.js +3 -0
  241. package/dist/logic/auth/redact.js +25 -0
  242. package/dist/logic/auth/revoke.js +28 -0
  243. package/dist/logic/auth/scope.js +17 -0
  244. package/dist/logic/auth/session.js +30 -0
  245. package/dist/logic/auth/sign-in-flow.js +305 -0
  246. package/dist/logic/auth/time.js +2 -0
  247. package/dist/logic/auth/token.js +74 -0
  248. package/dist/logic/auth/user-plans.js +84 -0
  249. package/dist/logic/auth/users.js +78 -0
  250. package/dist/logic/balance.js +2 -0
  251. package/dist/logic/bill.js +74 -0
  252. package/dist/logic/budget.js +78 -0
  253. package/dist/logic/category.js +37 -0
  254. package/dist/logic/classify.js +21 -0
  255. package/dist/logic/correlations.js +147 -0
  256. package/dist/logic/credit-card.js +2 -0
  257. package/dist/logic/currency-rate.js +69 -0
  258. package/dist/logic/dashboard.js +40 -0
  259. package/dist/logic/demo/database.js +30 -0
  260. package/dist/logic/demo/plan.js +308 -0
  261. package/dist/logic/demo/tour.js +33 -0
  262. package/dist/logic/export-destination.js +12 -0
  263. package/dist/logic/key-import.js +15 -0
  264. package/dist/logic/locale.js +5 -0
  265. package/dist/logic/localize.js +12 -0
  266. package/dist/logic/merchant.js +31 -0
  267. package/dist/logic/migration.js +1 -0
  268. package/dist/logic/money.js +12 -0
  269. package/dist/logic/period.js +45 -0
  270. package/dist/logic/persistence.js +48 -0
  271. package/dist/logic/recurring.js +51 -0
  272. package/dist/logic/resolve.js +44 -0
  273. package/dist/logic/summary.js +29 -0
  274. package/dist/logic/tag.js +13 -0
  275. package/dist/logic/transaction.js +197 -0
  276. package/dist/main.js +42 -0
  277. package/dist/models/account.js +197 -0
  278. package/dist/models/aggregate.js +61 -0
  279. package/dist/models/auth/bearer.js +11 -0
  280. package/dist/models/auth/entity.js +17 -0
  281. package/dist/models/auth/errors.js +42 -0
  282. package/dist/models/auth/grant.js +58 -0
  283. package/dist/models/auth/key-export.js +11 -0
  284. package/dist/models/auth/message.js +50 -0
  285. package/dist/models/auth/mode.js +7 -0
  286. package/dist/models/auth/origin.js +16 -0
  287. package/dist/models/auth/owner.js +36 -0
  288. package/dist/models/auth/password.js +24 -0
  289. package/dist/models/auth/principal.js +26 -0
  290. package/dist/models/auth/redact.js +4 -0
  291. package/dist/models/auth/scope.js +9 -0
  292. package/dist/models/auth/session.js +19 -0
  293. package/dist/models/auth/sign-in-flow.js +102 -0
  294. package/dist/models/auth/sign-in.js +41 -0
  295. package/dist/models/auth/time.js +5 -0
  296. package/dist/models/auth/token.js +50 -0
  297. package/dist/models/auth/users.js +52 -0
  298. package/dist/models/bill.js +55 -0
  299. package/dist/models/budget.js +106 -0
  300. package/dist/models/category.js +52 -0
  301. package/dist/models/client-config.js +18 -0
  302. package/dist/models/correlations.js +215 -0
  303. package/dist/models/credit-card.js +156 -0
  304. package/dist/models/currency-rate.js +83 -0
  305. package/dist/models/dashboard.js +54 -0
  306. package/dist/models/database.js +16 -0
  307. package/dist/models/date.js +8 -0
  308. package/dist/models/demo/core.js +58 -0
  309. package/dist/models/demo/tour.js +41 -0
  310. package/dist/models/encryption-key.js +2 -0
  311. package/dist/models/error.js +13 -0
  312. package/dist/models/export.js +9 -0
  313. package/dist/models/id.js +2 -0
  314. package/dist/models/instance.js +7 -0
  315. package/dist/models/key-import.js +6 -0
  316. package/dist/models/locale.js +25 -0
  317. package/dist/models/merchant.js +12 -0
  318. package/dist/models/money.js +14 -0
  319. package/dist/models/package.js +12 -0
  320. package/dist/models/page.js +56 -0
  321. package/dist/models/persistence.js +1 -0
  322. package/dist/models/prompts.js +5 -0
  323. package/dist/models/recurring.js +54 -0
  324. package/dist/models/remedy.js +17 -0
  325. package/dist/models/resolution.js +1 -0
  326. package/dist/models/startup.js +7 -0
  327. package/dist/models/summary.js +24 -0
  328. package/dist/models/tag.js +14 -0
  329. package/dist/models/tenancy.js +10 -0
  330. package/dist/models/transaction-tag.js +6 -0
  331. package/dist/models/transaction.js +275 -0
  332. package/dist/wire/db/access-tokens.js +1 -0
  333. package/dist/wire/db/accounts.js +7 -0
  334. package/dist/wire/db/aggregate.js +16 -0
  335. package/dist/wire/db/bills.js +14 -0
  336. package/dist/wire/db/budgets.js +33 -0
  337. package/dist/wire/db/categories.js +14 -0
  338. package/dist/wire/db/client-grants.js +1 -0
  339. package/dist/wire/db/correlations.js +49 -0
  340. package/dist/wire/db/credit-cards.js +1 -0
  341. package/dist/wire/db/currencies.js +1 -0
  342. package/dist/wire/db/currency-rates.js +1 -0
  343. package/dist/wire/db/dashboards.js +1 -0
  344. package/dist/wire/db/instance-settings.js +1 -0
  345. package/dist/wire/db/invites.js +1 -0
  346. package/dist/wire/db/merchants.js +18 -0
  347. package/dist/wire/db/recurring.js +19 -0
  348. package/dist/wire/db/sessions.js +1 -0
  349. package/dist/wire/db/settings.js +1 -0
  350. package/dist/wire/db/setup-codes.js +1 -0
  351. package/dist/wire/db/tags.js +1 -0
  352. package/dist/wire/db/tenancy.js +1 -0
  353. package/dist/wire/db/transactions.js +89 -0
  354. package/dist/wire/db/users.js +1 -0
  355. package/dist/wire/in/accounts.js +26 -0
  356. package/dist/wire/in/aggregate.js +10 -0
  357. package/dist/wire/in/auth.js +107 -0
  358. package/dist/wire/in/bills.js +11 -0
  359. package/dist/wire/in/budgets.js +11 -0
  360. package/dist/wire/in/categories.js +9 -0
  361. package/dist/wire/in/cli.js +106 -0
  362. package/dist/wire/in/coerce.js +6 -0
  363. package/dist/wire/in/common.js +17 -0
  364. package/dist/wire/in/credit-cards.js +16 -0
  365. package/dist/wire/in/currency-rates.js +8 -0
  366. package/dist/wire/in/period.js +7 -0
  367. package/dist/wire/in/recurring.js +6 -0
  368. package/dist/wire/in/settings.js +5 -0
  369. package/dist/wire/in/summary.js +5 -0
  370. package/dist/wire/in/tags.js +2 -0
  371. package/dist/wire/in/transactions.js +31 -0
  372. package/dist/wire/out/bills.js +9 -0
  373. package/dist/wire/out/budgets.js +10 -0
  374. package/dist/wire/out/client-config.js +2 -0
  375. package/dist/wire/out/common.js +4 -0
  376. package/dist/wire/out/credit-cards.js +15 -0
  377. package/dist/wire/out/currency-rates.js +11 -0
  378. package/dist/wire/out/errors.js +58 -0
  379. package/dist/wire/out/recurring.js +6 -0
  380. package/dist/wire/out/status.js +10 -0
  381. package/dist/wire/out/summary.js +9 -0
  382. package/dist/wire/out/transactions.js +52 -0
  383. package/drizzle/0000_futuristic_umar.sql +124 -0
  384. package/drizzle/0001_fts5_search.sql +23 -0
  385. package/drizzle/0002_rename_graph_to_history.sql +7 -0
  386. package/drizzle/0003_lyrical_hairball.sql +2 -0
  387. package/drizzle/0004_misty_ikaris.sql +7 -0
  388. package/drizzle/0005_credit-liability-accounts.sql +14 -0
  389. package/drizzle/0006_smart_aqueduct.sql +1 -0
  390. package/drizzle/0007_add_dashboards.sql +5 -0
  391. package/drizzle/0008_yummy_madripoor.sql +1 -0
  392. package/drizzle/0009_version_groundwork.sql +9 -0
  393. package/drizzle/0010_category_merchant_association_cascade.sql +16 -0
  394. package/drizzle/0011_dashboard_id_normalization.sql +16 -0
  395. package/drizzle/0012_hot_the_spike.sql +12 -0
  396. package/drizzle/0013_recurring_rules_merchant.sql +1 -0
  397. package/drizzle/0014_dashboard_source_discriminator.sql +17 -0
  398. package/drizzle/0015_currencies_decimals.sql +1 -0
  399. package/drizzle/0016_unusual_zaran.sql +13 -0
  400. package/drizzle/0017_premium_blur.sql +1 -0
  401. package/drizzle/0018_auth_identity.sql +39 -0
  402. package/drizzle/0019_access_tokens.sql +16 -0
  403. package/drizzle/0020_stdio_sign_in.sql +27 -0
  404. package/drizzle/0021_tenancy_data.sql +289 -0
  405. package/drizzle/0022_user_management.sql +17 -0
  406. package/drizzle/0023_instance_settings_row.sql +2 -0
  407. package/drizzle/0024_credentials_changed_at.sql +2 -0
  408. package/drizzle/0025_instance_kind.sql +2 -0
  409. package/drizzle/0026_demo_seeded_at.sql +2 -0
  410. package/drizzle/0027_demo_country.sql +2 -0
  411. package/drizzle/0028_reset_sign_ins.sql +2 -0
  412. package/drizzle/meta/0000_snapshot.json +894 -0
  413. package/drizzle/meta/0003_snapshot.json +910 -0
  414. package/drizzle/meta/0004_snapshot.json +951 -0
  415. package/drizzle/meta/0005_snapshot.json +991 -0
  416. package/drizzle/meta/0006_snapshot.json +998 -0
  417. package/drizzle/meta/0007_snapshot.json +1029 -0
  418. package/drizzle/meta/0008_snapshot.json +1049 -0
  419. package/drizzle/meta/0009_snapshot.json +1121 -0
  420. package/drizzle/meta/0010_snapshot.json +1121 -0
  421. package/drizzle/meta/0011_snapshot.json +1136 -0
  422. package/drizzle/meta/0012_snapshot.json +1227 -0
  423. package/drizzle/meta/0013_snapshot.json +1247 -0
  424. package/drizzle/meta/0014_snapshot.json +1267 -0
  425. package/drizzle/meta/0015_snapshot.json +1275 -0
  426. package/drizzle/meta/0016_snapshot.json +1371 -0
  427. package/drizzle/meta/0017_snapshot.json +1392 -0
  428. package/drizzle/meta/0018_snapshot.json +1603 -0
  429. package/drizzle/meta/0019_snapshot.json +1713 -0
  430. package/drizzle/meta/0020_snapshot.json +1904 -0
  431. package/drizzle/meta/0021_snapshot.json +2186 -0
  432. package/drizzle/meta/0022_snapshot.json +2311 -0
  433. package/drizzle/meta/0023_snapshot.json +2311 -0
  434. package/drizzle/meta/0024_snapshot.json +2318 -0
  435. package/drizzle/meta/0025_snapshot.json +2326 -0
  436. package/drizzle/meta/0026_snapshot.json +2333 -0
  437. package/drizzle/meta/0027_snapshot.json +2340 -0
  438. package/drizzle/meta/0028_snapshot.json +2340 -0
  439. package/drizzle/meta/_journal.json +209 -0
  440. package/package.json +106 -4
  441. package/skills/dashboard-building/SKILL.md +201 -0
  442. package/skills/patty-tour/SKILL.md +34 -0
  443. package/ui/app.css +758 -0
  444. package/ui/app.js +493 -0
  445. package/ui/connect-result.html +16 -0
  446. package/ui/connect.html +53 -0
  447. package/ui/dashboards/accounts.html +3189 -0
  448. package/ui/dashboards/budget.html +1716 -0
  449. package/ui/dashboards/cards.html +4032 -0
  450. package/ui/dashboards/categories.html +4694 -0
  451. package/ui/dashboards/comparative.html +2464 -0
  452. package/ui/dashboards/dashboards.html +839 -0
  453. package/ui/dashboards/overview.html +2405 -0
  454. package/ui/dashboards/pending.html +2973 -0
  455. package/ui/dashboards/projections.html +2517 -0
  456. package/ui/dashboards/tags.html +1365 -0
  457. package/ui/invite.html +44 -0
  458. package/ui/login.html +26 -0
  459. package/ui/money.js +175 -0
  460. package/ui/setup.html +29 -0
  461. package/ui/shell.html +96 -0
  462. package/ui/token-created.html +24 -0
  463. package/ui/tokens.html +58 -0
  464. package/ui/user-invited.html +27 -0
  465. package/ui/users.html +60 -0
@@ -0,0 +1,2464 @@
1
+ <style>
2
+ .dashboard-container {
3
+ max-width: 1400px;
4
+ margin: 0 auto;
5
+ display: flex;
6
+ flex-direction: column;
7
+ gap: 1.5rem;
8
+ }
9
+
10
+ .controls-area {
11
+ display: flex;
12
+ align-items: center;
13
+ gap: 1rem;
14
+ background: var(--panel-bg);
15
+ border: 1px solid var(--panel-border);
16
+ padding: 0.5rem 1rem;
17
+ border-radius: 14px;
18
+ backdrop-filter: blur(12px);
19
+ }
20
+
21
+ .controls-area label {
22
+ font-size: 0.85rem;
23
+ font-weight: 600;
24
+ color: var(--text-muted);
25
+ text-transform: uppercase;
26
+ letter-spacing: 0.05em;
27
+ }
28
+
29
+ .select-custom {
30
+ background: rgba(255, 255, 255, 0.05);
31
+ border: 1px solid var(--panel-border);
32
+ color: var(--text-main);
33
+ padding: 0.5rem 1.5rem 0.5rem 0.75rem;
34
+ border-radius: 8px;
35
+ font-family: var(--font-family);
36
+ font-weight: 500;
37
+ cursor: pointer;
38
+ outline: none;
39
+ transition: var(--transition-smooth);
40
+ appearance: none;
41
+ background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
42
+ background-repeat: no-repeat;
43
+ background-position: right 8px center;
44
+ background-size: 16px;
45
+ }
46
+
47
+ .select-custom:focus {
48
+ border-color: var(--accent-primary);
49
+ box-shadow: 0 0 0 2px var(--accent-primary-glow);
50
+ }
51
+
52
+ /* KPI summary cards */
53
+ .kpis-row {
54
+ display: grid;
55
+ grid-template-columns: repeat(3, 1fr);
56
+ gap: 1.5rem;
57
+ }
58
+
59
+ /* base: ui/app.css (#164) */
60
+ .kpi-card {
61
+ flex-direction: column;
62
+ gap: 0.75rem;
63
+ position: relative;
64
+ overflow: hidden;
65
+ }
66
+
67
+ .kpi-income::before { background: var(--income-color); }
68
+ .kpi-expense::before { background: var(--expense-color); }
69
+ .kpi-balance::before { background: var(--accent-primary); }
70
+
71
+ .kpi-title {
72
+ font-size: 0.85rem;
73
+ font-weight: 600;
74
+ color: var(--text-muted);
75
+ text-transform: uppercase;
76
+ letter-spacing: 0.05em;
77
+ display: flex;
78
+ align-items: center;
79
+ gap: 0.5rem;
80
+ }
81
+
82
+ .kpi-value {
83
+ font-size: 1.8rem;
84
+ font-weight: 800;
85
+ color: #fff;
86
+ }
87
+
88
+ .kpi-income .kpi-value {
89
+ color: var(--income-color) !important;
90
+ }
91
+
92
+ .kpi-expense .kpi-value {
93
+ color: var(--expense-color) !important;
94
+ }
95
+
96
+ .kpi-income .kpi-details span strong {
97
+ color: var(--income-color);
98
+ }
99
+
100
+ .kpi-expense .kpi-details span strong {
101
+ color: var(--expense-color);
102
+ }
103
+
104
+ .kpi-details {
105
+ font-size: 0.8rem;
106
+ color: var(--text-muted);
107
+ display: flex;
108
+ gap: 1rem;
109
+ }
110
+
111
+ .kpi-details span strong {
112
+ color: #fff;
113
+ }
114
+
115
+ /* Chart grids */
116
+ .charts-grid {
117
+ display: grid;
118
+ grid-template-columns: repeat(3, 1fr);
119
+ gap: 1.5rem;
120
+ }
121
+
122
+ @media (max-width: 1024px) {
123
+ .charts-grid {
124
+ grid-template-columns: 1fr;
125
+ }
126
+ }
127
+
128
+ .chart-card {
129
+ background: var(--panel-bg);
130
+ border: 1px solid var(--panel-border);
131
+ border-radius: 20px;
132
+ padding: 1.5rem;
133
+ box-shadow: var(--card-shadow);
134
+ backdrop-filter: blur(16px);
135
+ display: flex;
136
+ flex-direction: column;
137
+ gap: 1rem;
138
+ min-height: 320px;
139
+ }
140
+
141
+ .chart-card-title {
142
+ font-size: 1rem;
143
+ font-weight: 600;
144
+ color: var(--text-main);
145
+ display: flex;
146
+ align-items: center;
147
+ gap: 0.5rem;
148
+ }
149
+
150
+ .chart-container-inner {
151
+ position: relative;
152
+ flex: 1;
153
+ width: 100%;
154
+ height: 100%;
155
+ min-height: 240px;
156
+ }
157
+
158
+ /* Category panels */
159
+ .categories-grid {
160
+ display: grid;
161
+ grid-template-columns: 1fr 1fr;
162
+ gap: 1.5rem;
163
+ }
164
+
165
+ @media (max-width: 900px) {
166
+ .categories-grid {
167
+ grid-template-columns: 1fr;
168
+ }
169
+ }
170
+
171
+ .category-panel {
172
+ background: var(--panel-bg);
173
+ border: 1px solid var(--panel-border);
174
+ border-radius: 24px;
175
+ padding: 1.5rem;
176
+ box-shadow: var(--card-shadow);
177
+ backdrop-filter: blur(16px);
178
+ display: flex;
179
+ flex-direction: column;
180
+ gap: 1.25rem;
181
+ }
182
+
183
+ .category-panel-header {
184
+ display: flex;
185
+ justify-content: space-between;
186
+ align-items: center;
187
+ border-bottom: 1px solid var(--panel-border);
188
+ padding-bottom: 0.75rem;
189
+ }
190
+
191
+ .category-panel-title {
192
+ font-size: 1.1rem;
193
+ font-weight: 700;
194
+ display: flex;
195
+ align-items: center;
196
+ gap: 0.5rem;
197
+ }
198
+
199
+ .category-panel-title.income { color: var(--income-color); }
200
+ .category-panel-title.expense { color: var(--expense-color); }
201
+
202
+ .category-total-badge {
203
+ font-size: 1rem;
204
+ font-weight: 800;
205
+ color: #fff;
206
+ background: rgba(255, 255, 255, 0.05);
207
+ padding: 0.25rem 0.75rem;
208
+ border-radius: 12px;
209
+ border: 1px solid var(--panel-border);
210
+ }
211
+
212
+ .categories-list {
213
+ display: flex;
214
+ flex-direction: column;
215
+ gap: 0.75rem;
216
+ }
217
+
218
+ /* Category Row Accordion */
219
+ .category-row-container {
220
+ border: 1px solid var(--panel-border);
221
+ border-radius: 14px;
222
+ overflow: hidden;
223
+ background: rgba(0,0,0,0.1);
224
+ transition: var(--transition-smooth);
225
+ }
226
+
227
+ .category-row-container:hover {
228
+ border-color: rgba(255, 255, 255, 0.15);
229
+ }
230
+
231
+ .category-row-header {
232
+ padding: 1rem;
233
+ cursor: pointer;
234
+ display: flex;
235
+ flex-direction: column;
236
+ gap: 0.5rem;
237
+ user-select: none;
238
+ }
239
+
240
+ .cat-meta-info {
241
+ display: flex;
242
+ justify-content: space-between;
243
+ align-items: center;
244
+ }
245
+
246
+ .cat-name-label {
247
+ font-size: 0.95rem;
248
+ font-weight: 600;
249
+ color: #fff;
250
+ display: flex;
251
+ align-items: center;
252
+ gap: 0.5rem;
253
+ }
254
+
255
+ .cat-name-label i {
256
+ font-size: 0.8rem;
257
+ color: var(--text-muted);
258
+ transition: transform 0.3s ease;
259
+ }
260
+
261
+ .category-row-container.open .cat-name-label i {
262
+ transform: rotate(180deg);
263
+ color: var(--accent-primary);
264
+ }
265
+
266
+ .cat-val-label {
267
+ font-size: 0.95rem;
268
+ font-weight: 700;
269
+ color: #fff;
270
+ display: inline-flex;
271
+ align-items: center;
272
+ }
273
+
274
+ .cat-pct-label {
275
+ font-size: 0.72rem;
276
+ color: var(--text-muted);
277
+ margin-left: 0.5rem;
278
+ font-weight: 600;
279
+ background: rgba(255, 255, 255, 0.06);
280
+ padding: 2px 6px;
281
+ border-radius: 4px;
282
+ letter-spacing: 0.02em;
283
+ }
284
+
285
+ /* Progress Bar Proportions styling */
286
+ .proportion-bar-container {
287
+ width: 100%;
288
+ height: 8px;
289
+ background: rgba(255, 255, 255, 0.04);
290
+ border-radius: 4px;
291
+ overflow: hidden;
292
+ display: flex;
293
+ }
294
+
295
+ .bar-segment {
296
+ height: 100%;
297
+ transition: width 0.5s ease;
298
+ }
299
+
300
+ .bar-segment.effective-inc { background: var(--income-color); }
301
+ .bar-segment.pending-inc {
302
+ background: repeating-linear-gradient(
303
+ 45deg,
304
+ rgba(16, 185, 129, 0.25) 0px,
305
+ rgba(16, 185, 129, 0.25) 8px,
306
+ rgba(16, 185, 129, 0.45) 8px,
307
+ rgba(16, 185, 129, 0.45) 16px
308
+ );
309
+ }
310
+
311
+ .bar-segment.effective-exp { background: var(--expense-color); }
312
+ .bar-segment.pending-exp {
313
+ background: repeating-linear-gradient(
314
+ 45deg,
315
+ rgba(244, 63, 94, 0.25) 0px,
316
+ rgba(244, 63, 94, 0.25) 8px,
317
+ rgba(244, 63, 94, 0.45) 8px,
318
+ rgba(244, 63, 94, 0.45) 16px
319
+ );
320
+ }
321
+
322
+ .cat-breakdown-text {
323
+ display: flex;
324
+ justify-content: space-between;
325
+ font-size: 0.72rem;
326
+ color: var(--text-muted);
327
+ padding: 0 0.1rem;
328
+ }
329
+ .cat-breakdown-text span strong {
330
+ color: var(--text-main);
331
+ }
332
+
333
+ /* Expanded transaction list inside categories */
334
+ .category-tx-details {
335
+ display: none;
336
+ border-top: 1px solid var(--panel-border);
337
+ background: rgba(0, 0, 0, 0.25);
338
+ padding: 0.75rem 1rem;
339
+ overflow-x: auto;
340
+ }
341
+
342
+ .category-tx-table {
343
+ width: 100%;
344
+ border-collapse: collapse;
345
+ font-size: 0.82rem;
346
+ text-align: left;
347
+ }
348
+
349
+ .category-tx-table th {
350
+ padding: 0.4rem 0.6rem;
351
+ color: var(--text-dark);
352
+ text-transform: uppercase;
353
+ font-size: 0.7rem;
354
+ border-bottom: 1px solid var(--panel-border);
355
+ }
356
+
357
+ .category-tx-table td {
358
+ padding: 0.5rem 0.6rem;
359
+ border-bottom: 1px solid rgba(255, 255, 255, 0.02);
360
+ color: var(--text-main);
361
+ }
362
+
363
+ .category-tx-table tr:last-child td {
364
+ border-bottom: none;
365
+ }
366
+
367
+ .badge-status {
368
+ padding: 0.15rem 0.4rem;
369
+ border-radius: 4px;
370
+ font-size: 0.7rem;
371
+ font-weight: 600;
372
+ }
373
+ .status-eff {
374
+ background: rgba(16, 185, 129, 0.1);
375
+ color: var(--income-color);
376
+ border: 1px solid rgba(16, 185, 129, 0.2);
377
+ }
378
+ .status-pend {
379
+ background: rgba(245, 158, 11, 0.1);
380
+ color: var(--warning-color);
381
+ border: 1px solid rgba(245, 158, 11, 0.2);
382
+ }
383
+
384
+ /* Projections Heat Map Grid styling */
385
+ .heatmap-card {
386
+ background: var(--panel-bg);
387
+ border: 1px solid var(--panel-border);
388
+ border-radius: 24px;
389
+ padding: 1.75rem;
390
+ box-shadow: var(--card-shadow);
391
+ backdrop-filter: blur(16px);
392
+ display: flex;
393
+ flex-direction: column;
394
+ gap: 1.5rem;
395
+ }
396
+
397
+ .heatmap-title-area {
398
+ display: flex;
399
+ justify-content: space-between;
400
+ align-items: center;
401
+ border-bottom: 1px solid var(--panel-border);
402
+ padding-bottom: 0.75rem;
403
+ }
404
+
405
+ .heatmap-title {
406
+ font-size: 1.1rem;
407
+ font-weight: 700;
408
+ display: flex;
409
+ align-items: center;
410
+ gap: 0.5rem;
411
+ }
412
+
413
+ .heatmap-title i {
414
+ color: var(--accent-primary);
415
+ }
416
+
417
+ .heatmap-table-container {
418
+ overflow-x: auto;
419
+ border-radius: 12px;
420
+ border: 1px solid var(--panel-border);
421
+ background: rgba(0,0,0,0.1);
422
+ }
423
+
424
+ .heatmap-table {
425
+ width: 100%;
426
+ border-collapse: collapse;
427
+ text-align: center;
428
+ font-size: 0.85rem;
429
+ }
430
+
431
+ .heatmap-table th {
432
+ padding: 0.75rem 1rem;
433
+ color: var(--text-muted);
434
+ text-transform: uppercase;
435
+ font-size: 0.75rem;
436
+ letter-spacing: 0.05em;
437
+ border-bottom: 1px solid var(--panel-border);
438
+ background: rgba(255,255,255,0.01);
439
+ }
440
+
441
+ .heatmap-table th:first-child,
442
+ .heatmap-table td:first-child {
443
+ text-align: left;
444
+ font-weight: 600;
445
+ width: 250px;
446
+ }
447
+
448
+ .heatmap-table td {
449
+ padding: 0.75rem 1rem;
450
+ border-bottom: 1px solid rgba(255, 255, 255, 0.03);
451
+ border-right: 1px solid rgba(255, 255, 255, 0.02);
452
+ color: var(--text-main);
453
+ transition: var(--transition-smooth);
454
+ }
455
+
456
+ .heatmap-table td:last-child {
457
+ border-right: none;
458
+ font-weight: 700;
459
+ background: rgba(255, 255, 255, 0.01);
460
+ }
461
+
462
+ .heatmap-cell-value {
463
+ cursor: pointer;
464
+ border-radius: 6px;
465
+ padding: 0.35rem 0.5rem;
466
+ display: block;
467
+ font-weight: 500;
468
+ transition: var(--transition-smooth);
469
+ }
470
+
471
+ .heatmap-cell-value:hover {
472
+ transform: scale(1.05);
473
+ box-shadow: 0 4px 12px rgba(0,0,0,0.25);
474
+ }
475
+
476
+ .heatmap-table tfoot {
477
+ font-weight: 700;
478
+ background: rgba(255, 255, 255, 0.03);
479
+ border-top: 2px solid var(--panel-border);
480
+ }
481
+
482
+ .heatmap-table tfoot td {
483
+ padding: 0.75rem 1rem;
484
+ color: #fff;
485
+ border-top: 1px solid rgba(255, 255, 255, 0.1);
486
+ }
487
+
488
+ .heatmap-empty {
489
+ color: var(--text-dark);
490
+ font-size: 0.8rem;
491
+ font-style: italic;
492
+ }
493
+
494
+ /* Overlay loader (.loading-overlay/.spinner base: ui/app.css, #164) */
495
+ .loading-overlay {
496
+ width: 100%; height: 100%;
497
+ z-index: 100;
498
+ border-radius: 24px;
499
+ opacity: 0; pointer-events: none;
500
+ transition: opacity 0.25s ease;
501
+ }
502
+ .loading-overlay.active { opacity: 1; pointer-events: all; }
503
+
504
+ /* Modal heat map cell details (.modal-overlay/.modal-box/.modal-title base: ui/app.css, #164) */
505
+ .modal-overlay {
506
+ width: 100%; height: 100%;
507
+ }
508
+ .modal-overlay.open {
509
+ display: flex;
510
+ }
511
+
512
+ .modal-box {
513
+ max-width: 600px;
514
+ }
515
+
516
+ .modal-close-btn {
517
+ position: absolute;
518
+ top: 1.25rem;
519
+ right: 1.25rem;
520
+ background: none;
521
+ border: none;
522
+ color: var(--text-dark);
523
+ cursor: pointer;
524
+ font-size: 1.2rem;
525
+ transition: var(--transition-smooth);
526
+ }
527
+ .modal-close-btn:hover {
528
+ color: var(--text-main);
529
+ }
530
+
531
+ .modal-title {
532
+ font-size: 1.2rem;
533
+ margin-bottom: 1.25rem;
534
+ color: #fff;
535
+ }
536
+
537
+ .modal-desc-text {
538
+ color: var(--text-muted);
539
+ font-size: 0.85rem;
540
+ margin-bottom: 1rem;
541
+ }
542
+
543
+ /* Custom Select component styling */
544
+ .select-container-custom {
545
+ position: relative;
546
+ display: inline-block;
547
+ min-width: 120px;
548
+ user-select: none;
549
+ }
550
+
551
+ .select-trigger-custom {
552
+ background: rgba(255, 255, 255, 0.05);
553
+ border: 1px solid var(--panel-border);
554
+ color: var(--text-main);
555
+ padding: 0.5rem 2.2rem 0.5rem 0.75rem;
556
+ border-radius: 8px;
557
+ cursor: pointer;
558
+ font-size: 0.85rem;
559
+ font-weight: 600;
560
+ display: flex;
561
+ align-items: center;
562
+ justify-content: space-between;
563
+ transition: var(--transition-smooth);
564
+ min-height: 36px;
565
+ box-sizing: border-box;
566
+ }
567
+
568
+ .select-trigger-custom:hover {
569
+ border-color: rgba(255, 255, 255, 0.15);
570
+ background: rgba(255, 255, 255, 0.08);
571
+ }
572
+
573
+ .select-container-custom.open .select-trigger-custom {
574
+ border-color: var(--accent-primary);
575
+ box-shadow: 0 0 0 2px var(--accent-primary-glow);
576
+ }
577
+
578
+ .select-trigger-custom::after {
579
+ content: '\f078';
580
+ font-family: 'Font Awesome 6 Free';
581
+ font-weight: 900;
582
+ font-size: 0.7rem;
583
+ color: var(--text-muted);
584
+ position: absolute;
585
+ right: 12px;
586
+ transition: transform 0.3s ease;
587
+ }
588
+
589
+ .select-container-custom.open .select-trigger-custom::after {
590
+ transform: rotate(180deg);
591
+ color: var(--accent-primary);
592
+ }
593
+
594
+ .select-options-custom {
595
+ display: none;
596
+ position: absolute;
597
+ top: calc(100% + 6px);
598
+ left: 0;
599
+ width: 100%;
600
+ background: rgba(22, 22, 34, 0.98); /* Opaque dark background to prevent bleed-through */
601
+ border: 1px solid var(--panel-border);
602
+ border-radius: 12px;
603
+ box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
604
+ z-index: 1000;
605
+ max-height: 250px;
606
+ overflow-y: auto;
607
+ padding: 4px;
608
+ backdrop-filter: blur(20px);
609
+ box-sizing: border-box;
610
+ animation: selectFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
611
+ }
612
+
613
+ @keyframes selectFadeIn {
614
+ from { opacity: 0; transform: translateY(-8px); }
615
+ to { opacity: 1; transform: translateY(0); }
616
+ }
617
+
618
+ .select-container-custom.open .select-options-custom {
619
+ display: block;
620
+ }
621
+
622
+ .select-option-custom {
623
+ padding: 0.5rem 0.75rem;
624
+ color: var(--text-muted); /* Highly readable text color on dark backgrounds */
625
+ font-size: 0.82rem;
626
+ font-weight: 500;
627
+ border-radius: 6px;
628
+ cursor: pointer;
629
+ transition: var(--transition-smooth);
630
+ }
631
+
632
+ .select-option-custom:hover {
633
+ background: rgba(255, 255, 255, 0.08);
634
+ color: #fff;
635
+ }
636
+
637
+ .select-option-custom.selected {
638
+ background: var(--accent-primary-glow);
639
+ color: var(--accent-primary);
640
+ font-weight: 700;
641
+ }
642
+
643
+ .select-options-custom::-webkit-scrollbar {
644
+ width: 6px;
645
+ }
646
+ .select-options-custom::-webkit-scrollbar-track {
647
+ background: transparent;
648
+ }
649
+ .select-options-custom::-webkit-scrollbar-thumb {
650
+ background: rgba(255, 255, 255, 0.1);
651
+ border-radius: 3px;
652
+ }
653
+ </style>
654
+
655
+ <div class="dashboard-container">
656
+ <!-- Header -->
657
+ <header>
658
+ <div class="header-title-area">
659
+ <h1><i class="fa-solid fa-chart-line"></i> Comparativo de Resultados</h1>
660
+ <p>Análise de receitas vs despesas por categorias e projeção de lançamentos futuros</p>
661
+ </div>
662
+ <div class="controls-area">
663
+ <label for="month-select" data-i18n="reference_label">Reference:</label>
664
+ <select id="month-select" class="select-custom">
665
+ <option value="1">Janeiro</option>
666
+ <option value="2">Fevereiro</option>
667
+ <option value="3">Março</option>
668
+ <option value="4">Abril</option>
669
+ <option value="5">Maio</option>
670
+ <option value="6">Junho</option>
671
+ <option value="7" selected>Julho</option>
672
+ <option value="8">Agosto</option>
673
+ <option value="9">Setembro</option>
674
+ <option value="10">Outubro</option>
675
+ <option value="11">Novembro</option>
676
+ <option value="12">Dezembro</option>
677
+ </select>
678
+ <select id="year-select" class="select-custom">
679
+ <option value="2025">2025</option>
680
+ <option value="2026" selected>2026</option>
681
+ <option value="2027">2027</option>
682
+ </select>
683
+ </div>
684
+ </header>
685
+
686
+ <!-- KPI summary cards -->
687
+ <div class="kpis-row">
688
+ <!-- Incomes card -->
689
+ <div class="kpi-card kpi-income">
690
+ <div class="kpi-title">
691
+ <i class="fa-solid fa-circle-arrow-up" style="color: var(--income-color);"></i>
692
+ Receitas Totais
693
+ </div>
694
+ <div class="kpi-value" id="kpi-income-val">—</div>
695
+ <div class="kpi-details">
696
+ <span>Efetivado: <strong id="kpi-income-eff">—</strong></span>
697
+ <span>Pendente: <strong id="kpi-income-pend">—</strong></span>
698
+ </div>
699
+ </div>
700
+ <!-- Expenses card -->
701
+ <div class="kpi-card kpi-expense">
702
+ <div class="kpi-title">
703
+ <i class="fa-solid fa-circle-arrow-down" style="color: var(--expense-color);"></i>
704
+ Despesas Totais
705
+ </div>
706
+ <div class="kpi-value" id="kpi-expense-val">—</div>
707
+ <div class="kpi-details">
708
+ <span>Efetivado: <strong id="kpi-expense-eff">—</strong></span>
709
+ <span>Pendente: <strong id="kpi-expense-pend">—</strong></span>
710
+ </div>
711
+ </div>
712
+ <!-- Balance card -->
713
+ <div class="kpi-card kpi-balance">
714
+ <div class="kpi-title">
715
+ <i class="fa-solid fa-scale-balanced" style="color: var(--accent-primary);"></i>
716
+ Saldo Resultante
717
+ </div>
718
+ <div class="kpi-value" id="kpi-balance-val">—</div>
719
+ <div class="kpi-details">
720
+ <span id="kpi-balance-pct">Resultado mensal líquido</span>
721
+ </div>
722
+ </div>
723
+ </div>
724
+
725
+ <!-- Charts row -->
726
+ <div class="charts-grid">
727
+ <div class="chart-card">
728
+ <div class="chart-card-title">
729
+ <i class="fa-solid fa-chart-bar" style="color: var(--accent-primary);"></i>
730
+ Comparativo Mensal (Receitas x Despesas)
731
+ </div>
732
+ <div class="chart-container-inner">
733
+ <canvas id="barChart"></canvas>
734
+ </div>
735
+ </div>
736
+ <div class="chart-card">
737
+ <div class="chart-card-title">
738
+ <i class="fa-solid fa-chart-pie" style="color: var(--income-color);"></i>
739
+ Receitas por Categoria
740
+ </div>
741
+ <div class="chart-container-inner">
742
+ <canvas id="incomePieChart"></canvas>
743
+ </div>
744
+ </div>
745
+ <div class="chart-card">
746
+ <div class="chart-card-title">
747
+ <i class="fa-solid fa-chart-pie" style="color: var(--expense-color);"></i>
748
+ Despesas por Categoria
749
+ </div>
750
+ <div class="chart-container-inner">
751
+ <canvas id="expensePieChart"></canvas>
752
+ </div>
753
+ </div>
754
+ </div>
755
+
756
+ <!-- Category split breakdown -->
757
+ <div class="categories-grid" style="position: relative;">
758
+ <div class="loading-overlay" id="panels-loading">
759
+ <div class="spinner"></div>
760
+ </div>
761
+
762
+ <!-- Incomes breakdown -->
763
+ <div class="category-panel">
764
+ <div class="category-panel-header">
765
+ <div class="category-panel-title income">
766
+ <i class="fa-solid fa-circle-arrow-up"></i> Receitas por Categoria
767
+ </div>
768
+ <div class="category-total-badge" id="income-categories-total">—</div>
769
+ </div>
770
+ <div class="categories-list" id="income-categories-list">
771
+ <!-- Dynamic categories -->
772
+ </div>
773
+ </div>
774
+
775
+ <!-- Expenses breakdown -->
776
+ <div class="category-panel">
777
+ <div class="category-panel-header">
778
+ <div class="category-panel-title expense">
779
+ <i class="fa-solid fa-circle-arrow-down"></i> Despesas por Categoria
780
+ </div>
781
+ <div class="category-total-badge" id="expense-categories-total">—</div>
782
+ </div>
783
+ <div class="categories-list" id="expense-categories-list">
784
+ <!-- Dynamic categories -->
785
+ </div>
786
+ </div>
787
+ </div>
788
+
789
+ </div>
790
+ </div>
791
+ </div>
792
+
793
+
794
+ </div>
795
+
796
+
797
+
798
+ <script>
799
+ // State
800
+ var categories = [];
801
+ var allTransactions = []; // Holds all transactions fetched for the selected year
802
+ var now = new Date();
803
+ var params = new URLSearchParams(window.location.search);
804
+ var queryMonth = parseInt(params.get('month'));
805
+ var queryYear = parseInt(params.get('year'));
806
+ var selectedMonth = !isNaN(queryMonth) ? queryMonth : (now.getMonth() + 1);
807
+ var selectedYear = !isNaN(queryYear) ? queryYear : now.getFullYear();
808
+ // Holds list of calculated projection months dynamically
809
+
810
+ // Charts references
811
+ var barChartInstance = null;
812
+ var incomePieChartInstance = null;
813
+ var expensePieChartInstance = null;
814
+
815
+ // Elements
816
+ var monthSelect = document.getElementById('month-select');
817
+ var yearSelect = document.getElementById('year-select');
818
+ if (monthSelect) monthSelect.value = String(selectedMonth);
819
+ if (yearSelect) yearSelect.value = String(selectedYear);
820
+ var panelsLoading = document.getElementById('panels-loading');
821
+ var heatmapLoading = document.getElementById('heatmap-loading');
822
+
823
+ // Money formatting — per currency, never blended (issue #174 fix). Every accumulator below
824
+ // is keyed by currency; formatMultiCurrency renders each currency's own amount side by side
825
+ // instead of collapsing them into a single mislabeled total. addMultiCurrency/valueIn/
826
+ // primaryCurrencyOf/magnitudeOf/mergeCurrencyMaps/formatMultiCurrencyWith/DEFAULT_CURRENCY
827
+ // are shared globals from ui/money.js (loaded before this fragment's script — see
828
+ // docs/ui.md) rather than defined here. formatCurrency stays local — and formatMultiCurrency
829
+ // is just a 1-line delegate to formatMultiCurrencyWith passing it — because they need this
830
+ // fragment's own resolved currentLocale, which the shell-loaded, load-once money.js has no
831
+ // access to.
832
+ function formatCurrency(val, currency) {
833
+ const loc = currentLocale === 'pt' ? 'pt-BR' : (currentLocale === 'es' ? 'es-ES' : 'en-US');
834
+ return window.formatMoney(val || 0, currency || DEFAULT_CURRENCY, { locale: loc });
835
+ }
836
+
837
+ function formatMultiCurrency(map, delimiter) {
838
+ return window.formatMultiCurrencyWith(map, formatCurrency, delimiter);
839
+ }
840
+
841
+ function escapeHtml(str) {
842
+ if (!str) return '';
843
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
844
+ }
845
+
846
+ function openModal(id) {
847
+ document.getElementById(id).classList.add('open');
848
+ }
849
+
850
+ function closeModal(id) {
851
+ document.getElementById(id).classList.remove('open');
852
+ }
853
+
854
+ // Close modal on ESC key
855
+ document.addEventListener('keydown', (e) => {
856
+ if (e.key === 'Escape') {
857
+ const activeModal = document.querySelector('.modal-overlay.open');
858
+ if (activeModal) {
859
+ closeModal(activeModal.id);
860
+ }
861
+ }
862
+ });
863
+
864
+ // Toggle accordion drawer for category transactions
865
+ function toggleCategoryAccordion(elementId) {
866
+ const container = document.getElementById(elementId);
867
+ if (!container) return;
868
+
869
+ const isOpen = container.classList.contains('open');
870
+
871
+ // Close all others inside the SAME list only
872
+ const parentList = container.closest('.categories-list');
873
+ if (parentList) {
874
+ parentList.querySelectorAll('.category-row-container').forEach(el => {
875
+ el.classList.remove('open');
876
+ el.querySelector('.category-tx-details').style.display = 'none';
877
+ });
878
+ }
879
+
880
+ if (!isOpen) {
881
+ container.classList.add('open');
882
+ container.querySelector('.category-tx-details').style.display = 'block';
883
+ }
884
+ }
885
+
886
+ // Bootstrap data fetch
887
+ async function initDashboard() {
888
+ if (panelsLoading) panelsLoading.classList.add('active');
889
+ if (heatmapLoading) heatmapLoading.classList.add('active');
890
+ try {
891
+ // Fetch categories
892
+ const catsRes = await fetch('/api/categories');
893
+ if (catsRes.ok) {
894
+ categories = await catsRes.json();
895
+ }
896
+ categories = Array.isArray(categories) ? categories : [];
897
+
898
+ await loadTransactionsData();
899
+ } catch (err) {
900
+ console.error("Error initializing comparative dashboard:", err);
901
+ } finally {
902
+ if (panelsLoading) panelsLoading.classList.remove('active');
903
+ if (heatmapLoading) heatmapLoading.classList.remove('active');
904
+ }
905
+ }
906
+
907
+
908
+
909
+ // Fetch transactions for selected month using safe pagination
910
+ async function loadTransactionsData() {
911
+ if (panelsLoading) panelsLoading.classList.add('active');
912
+
913
+ const mSel = document.getElementById('month-select');
914
+ const ySel = document.getElementById('year-select');
915
+
916
+ selectedMonth = mSel ? parseInt(mSel.value) : 7;
917
+ selectedYear = ySel ? parseInt(ySel.value) : 2026;
918
+
919
+ try {
920
+ async function fetchMonthTransactions(year, month) {
921
+ let allItems = [];
922
+ let cursor = null;
923
+
924
+ while (true) {
925
+ const queryParams = new URLSearchParams({
926
+ month: String(month),
927
+ year: String(year),
928
+ sort: 'date',
929
+ dir: 'desc'
930
+ });
931
+ if (cursor) {
932
+ queryParams.set('cursor', cursor);
933
+ }
934
+
935
+ const url = `/api/transactions?${queryParams.toString()}`;
936
+ const res = await fetch(url);
937
+ if (!res.ok) throw new Error(`HTTP error ${res.status}`);
938
+
939
+ const data = await res.json();
940
+
941
+ let items = [];
942
+ let nextCursor = null;
943
+ if (data && typeof data === 'object') {
944
+ if (Array.isArray(data.items)) {
945
+ items = data.items;
946
+ nextCursor = data.nextCursor;
947
+ } else if (Array.isArray(data)) {
948
+ items = data;
949
+ }
950
+ }
951
+
952
+ allItems.push(...items);
953
+
954
+ if (!nextCursor) {
955
+ break;
956
+ }
957
+ cursor = nextCursor;
958
+ }
959
+
960
+ return allItems;
961
+ }
962
+
963
+ allTransactions = await fetchMonthTransactions(selectedYear, selectedMonth);
964
+ calculateAndRenderAll();
965
+ } catch (err) {
966
+ console.error("Error loading transactions:", err);
967
+ } finally {
968
+ if (panelsLoading) panelsLoading.classList.remove('active');
969
+ }
970
+ }
971
+
972
+ // Core processing function
973
+ function calculateAndRenderAll() {
974
+ // 1. FILTER FOR CURRENT MONTH
975
+ const currentMonthStr = `${selectedYear}-${String(selectedMonth).padStart(2, '0')}`;
976
+ const monthTxs = allTransactions.filter(t => t.date && typeof t.date === 'string' && t.date.startsWith(currentMonthStr));
977
+
978
+ // Calculate KPIs — every accumulator is a currency -> amount map (never a blended
979
+ // scalar), so a month mixing BRL/USD/BTC activity keeps each currency's own total.
980
+ const totalIncome = {};
981
+ const effIncome = {};
982
+ const pendIncome = {};
983
+
984
+ const totalExpense = {};
985
+ const effExpense = {};
986
+ const pendExpense = {};
987
+
988
+ // Group transactions by category for current month
989
+ const categorySums = {}; // categoryId -> { effective: {currency: amount}, pending: {...}, txs: [] }
990
+
991
+ monthTxs.forEach(t => {
992
+ // Ignore all transfers (including bill payments)
993
+ if (t.type === 'transfer') return;
994
+
995
+ const amount = parseFloat(t.amount) || 0;
996
+ const currency = t.currency || DEFAULT_CURRENCY;
997
+ const isEffective = t.status === 'effective';
998
+
999
+ if (t.type === 'income') {
1000
+ addMultiCurrency(totalIncome, currency, amount);
1001
+ addMultiCurrency(isEffective ? effIncome : pendIncome, currency, amount);
1002
+ } else if (t.type === 'expense') {
1003
+ addMultiCurrency(totalExpense, currency, amount);
1004
+ addMultiCurrency(isEffective ? effExpense : pendExpense, currency, amount);
1005
+ }
1006
+
1007
+ // Group by category name or fallback
1008
+ const catName = t.categoryName || 'Sem Categoria';
1009
+ const catId = t.categoryId || 'cat-none';
1010
+
1011
+ if (!categorySums[catId]) {
1012
+ categorySums[catId] = { id: catId, name: catName, kind: t.type === 'income' ? 'income' : 'expense', effective: {}, pending: {}, txs: [] };
1013
+ }
1014
+
1015
+ addMultiCurrency(isEffective ? categorySums[catId].effective : categorySums[catId].pending, currency, amount);
1016
+ categorySums[catId].txs.push(t);
1017
+ });
1018
+
1019
+ // Update KPI elements
1020
+ document.getElementById('kpi-income-val').textContent = formatMultiCurrency(totalIncome);
1021
+ document.getElementById('kpi-income-eff').textContent = formatMultiCurrency(effIncome);
1022
+ document.getElementById('kpi-income-pend').textContent = formatMultiCurrency(pendIncome);
1023
+
1024
+ document.getElementById('kpi-expense-val').textContent = formatMultiCurrency(totalExpense);
1025
+ document.getElementById('kpi-expense-eff').textContent = formatMultiCurrency(effExpense);
1026
+ document.getElementById('kpi-expense-pend').textContent = formatMultiCurrency(pendExpense);
1027
+
1028
+ const netBalance = {};
1029
+ new Set([...Object.keys(totalIncome), ...Object.keys(totalExpense)]).forEach(c => {
1030
+ netBalance[c] = valueIn(totalIncome, c) - valueIn(totalExpense, c);
1031
+ });
1032
+ const balElement = document.getElementById('kpi-balance-val');
1033
+ balElement.textContent = formatMultiCurrency(netBalance);
1034
+ const netBalanceCurrency = primaryCurrencyOf(netBalance);
1035
+ if (valueIn(netBalance, netBalanceCurrency) >= 0) {
1036
+ balElement.style.color = 'var(--income-color)';
1037
+ } else {
1038
+ balElement.style.color = 'var(--expense-color)';
1039
+ }
1040
+
1041
+ // 2. RENDER CHARTS
1042
+ // Chart.js needs a single numeric series, so charts show ONE real currency (never a
1043
+ // blended/converted total) — the KPI cards above already show every currency correctly.
1044
+ try {
1045
+ if (typeof Chart !== 'undefined') {
1046
+ const chartCurrency = primaryCurrencyOf(mergeCurrencyMaps(effIncome, pendIncome, effExpense, pendExpense));
1047
+ renderComparativeCharts(
1048
+ valueIn(effIncome, chartCurrency),
1049
+ valueIn(pendIncome, chartCurrency),
1050
+ valueIn(effExpense, chartCurrency),
1051
+ valueIn(pendExpense, chartCurrency),
1052
+ categorySums,
1053
+ chartCurrency
1054
+ );
1055
+ } else {
1056
+ console.warn("Chart.js was not loaded.");
1057
+ }
1058
+ } catch (chartErr) {
1059
+ console.error("Error rendering charts:", chartErr);
1060
+ }
1061
+
1062
+ // 3. RENDER CATEGORIES COLUMNS
1063
+ renderCategoryColumns(categorySums, totalIncome, totalExpense);
1064
+
1065
+
1066
+ }
1067
+
1068
+ // Render charts via Chart.js — all values passed in already belong to a single `currency`
1069
+ // (see call site), so this function never mixes amounts across currencies.
1070
+ function renderComparativeCharts(effInc, pendInc, effExp, pendExp, categorySums, currency) {
1071
+ // Destroy existing charts to prevent hover glitching
1072
+ if (barChartInstance) barChartInstance.destroy();
1073
+ if (incomePieChartInstance) incomePieChartInstance.destroy();
1074
+ if (expensePieChartInstance) expensePieChartInstance.destroy();
1075
+
1076
+ // Bar Chart: Comparative Incomes vs Expenses
1077
+ const ctxBar = document.getElementById('barChart').getContext('2d');
1078
+ barChartInstance = new Chart(ctxBar, {
1079
+ type: 'bar',
1080
+ data: {
1081
+ labels: ['Receitas', 'Despesas'],
1082
+ datasets: [
1083
+ {
1084
+ label: 'Efetivado',
1085
+ data: [effInc, effExp],
1086
+ backgroundColor: ['#10b981', '#f43f5e'],
1087
+ borderRadius: 6
1088
+ },
1089
+ {
1090
+ label: 'Pendente',
1091
+ data: [pendInc, pendExp],
1092
+ backgroundColor: ['rgba(16, 185, 129, 0.45)', 'rgba(244, 63, 94, 0.45)'],
1093
+ borderRadius: 6
1094
+ }
1095
+ ]
1096
+ },
1097
+ options: {
1098
+ responsive: true,
1099
+ maintainAspectRatio: false,
1100
+ plugins: {
1101
+ legend: { labels: { color: '#9ca3af', font: { family: 'Plus Jakarta Sans' } } },
1102
+ tooltip: {
1103
+ callbacks: {
1104
+ label: function(ctx) {
1105
+ return `${ctx.dataset.label}: ${formatCurrency(ctx.raw, currency)}`;
1106
+ }
1107
+ }
1108
+ }
1109
+ },
1110
+ scales: {
1111
+ x: { stacked: true, grid: { color: 'rgba(255,255,255,0.03)' }, ticks: { color: '#9ca3af' } },
1112
+ y: {
1113
+ stacked: true,
1114
+ grid: { color: 'rgba(255,255,255,0.03)' },
1115
+ ticks: { color: '#9ca3af', callback: function(val) { return formatCurrency(val, currency); } }
1116
+ }
1117
+ }
1118
+ }
1119
+ });
1120
+
1121
+ // Parse categories for pies
1122
+ const incomeCategories = [];
1123
+ const expenseCategories = [];
1124
+
1125
+ Object.values(categorySums).forEach(cat => {
1126
+ const total = valueIn(cat.effective, currency) + valueIn(cat.pending, currency);
1127
+ if (total <= 0) return;
1128
+
1129
+ if (cat.kind === 'income') {
1130
+ incomeCategories.push({ name: cat.name, total });
1131
+ } else {
1132
+ expenseCategories.push({ name: cat.name, total });
1133
+ }
1134
+ });
1135
+
1136
+ // Donut 1: Incomes by Category
1137
+ const ctxIncPie = document.getElementById('incomePieChart').getContext('2d');
1138
+ incomePieChartInstance = new Chart(ctxIncPie, {
1139
+ type: 'doughnut',
1140
+ data: {
1141
+ labels: incomeCategories.map(c => c.name),
1142
+ datasets: [{
1143
+ data: incomeCategories.map(c => c.total),
1144
+ backgroundColor: ['#10b981', '#34d399', '#6ee7b7', '#a7f3d0', '#047857', '#065f46'],
1145
+ borderWidth: 1,
1146
+ borderColor: '#111322'
1147
+ }]
1148
+ },
1149
+ options: {
1150
+ responsive: true,
1151
+ maintainAspectRatio: false,
1152
+ plugins: {
1153
+ legend: { display: false }, // Hide legend to look premium
1154
+ tooltip: {
1155
+ callbacks: {
1156
+ label: function(ctx) {
1157
+ return `${ctx.label}: ${formatCurrency(ctx.raw, currency)}`;
1158
+ }
1159
+ }
1160
+ }
1161
+ },
1162
+ cutout: '65%'
1163
+ }
1164
+ });
1165
+
1166
+ // Donut 2: Expenses by Category
1167
+ const ctxExpPie = document.getElementById('expensePieChart').getContext('2d');
1168
+ expensePieChartInstance = new Chart(ctxExpPie, {
1169
+ type: 'doughnut',
1170
+ data: {
1171
+ labels: expenseCategories.map(c => c.name),
1172
+ datasets: [{
1173
+ data: expenseCategories.map(c => c.total),
1174
+ backgroundColor: ['#f43f5e', '#fb7185', '#fca5a5', '#ffe4e6', '#be123c', '#9f1239'],
1175
+ borderWidth: 1,
1176
+ borderColor: '#111322'
1177
+ }]
1178
+ },
1179
+ options: {
1180
+ responsive: true,
1181
+ maintainAspectRatio: false,
1182
+ plugins: {
1183
+ legend: { display: false },
1184
+ tooltip: {
1185
+ callbacks: {
1186
+ label: function(ctx) {
1187
+ return `${ctx.label}: ${formatCurrency(ctx.raw, currency)}`;
1188
+ }
1189
+ }
1190
+ }
1191
+ },
1192
+ cutout: '65%'
1193
+ }
1194
+ });
1195
+ }
1196
+
1197
+ // Render side-by-side categories layout
1198
+ function renderCategoryColumns(categorySums, totalIncome, totalExpense) {
1199
+ const incListEl = document.getElementById('income-categories-list');
1200
+ const expListEl = document.getElementById('expense-categories-list');
1201
+
1202
+ incListEl.innerHTML = '';
1203
+ expListEl.innerHTML = '';
1204
+
1205
+ // Group by category type
1206
+ const listCats = Object.values(categorySums);
1207
+
1208
+ // Add any other categories that exist in DB but have no transactions in current month
1209
+ categories.forEach(c => {
1210
+ const found = listCats.some(lc => lc.id === c.id);
1211
+ if (!found) {
1212
+ listCats.push({
1213
+ id: c.id,
1214
+ name: c.name,
1215
+ kind: c.kind,
1216
+ effective: {},
1217
+ pending: {},
1218
+ txs: []
1219
+ });
1220
+ }
1221
+ });
1222
+
1223
+ // Sort lists by total value descending (raw cross-currency magnitude — display order
1224
+ // only, see magnitudeOf)
1225
+ listCats.sort((a, b) => magnitudeOf(mergeCurrencyMaps(b.effective, b.pending)) - magnitudeOf(mergeCurrencyMaps(a.effective, a.pending)));
1226
+
1227
+ const incTotalSum = {};
1228
+ const expTotalSum = {};
1229
+
1230
+ listCats.forEach(cat => {
1231
+ const totalByCurrency = mergeCurrencyMaps(cat.effective, cat.pending);
1232
+
1233
+ if (cat.kind === 'income') {
1234
+ Object.keys(totalByCurrency).forEach(c => addMultiCurrency(incTotalSum, c, totalByCurrency[c]));
1235
+ } else {
1236
+ Object.keys(totalByCurrency).forEach(c => addMultiCurrency(expTotalSum, c, totalByCurrency[c]));
1237
+ }
1238
+
1239
+ if (magnitudeOf(totalByCurrency) === 0) {
1240
+ return;
1241
+ }
1242
+
1243
+ // Render progress bar widths relative to total income/expense of the month — a
1244
+ // percentage can only compare amounts in the same currency, so the row's own
1245
+ // primary currency drives both the numerator and denominator.
1246
+ const rowCurrency = primaryCurrencyOf(totalByCurrency);
1247
+ const rowEffective = valueIn(cat.effective, rowCurrency);
1248
+ const rowPending = valueIn(cat.pending, rowCurrency);
1249
+ let pctEff = 0;
1250
+ let pctPend = 0;
1251
+ if (cat.kind === 'income') {
1252
+ const rowTotalIncome = valueIn(totalIncome, rowCurrency);
1253
+ if (rowTotalIncome > 0) {
1254
+ pctEff = (rowEffective / rowTotalIncome) * 100;
1255
+ pctPend = (rowPending / rowTotalIncome) * 100;
1256
+ }
1257
+ } else {
1258
+ const rowTotalExpense = valueIn(totalExpense, rowCurrency);
1259
+ if (rowTotalExpense > 0) {
1260
+ pctEff = (rowEffective / rowTotalExpense) * 100;
1261
+ pctPend = (rowPending / rowTotalExpense) * 100;
1262
+ }
1263
+ }
1264
+
1265
+ // Create container element
1266
+ const rowId = `cat-row-${cat.id}`;
1267
+ const div = document.createElement('div');
1268
+ div.className = 'category-row-container';
1269
+ div.id = rowId;
1270
+
1271
+ // Sort transactions inside drawer
1272
+ cat.txs.sort((a,b) => b.date.localeCompare(a.date));
1273
+
1274
+ div.innerHTML = `
1275
+ <div class="category-row-header" onclick="toggleCategoryAccordion('${rowId}')">
1276
+ <div class="cat-meta-info">
1277
+ <div class="cat-name-label">
1278
+ <i class="fa-solid fa-chevron-down"></i>
1279
+ ${escapeHtml(cat.name)}
1280
+ </div>
1281
+ <div class="cat-val-label">
1282
+ ${formatMultiCurrency(totalByCurrency)}
1283
+ <span class="cat-pct-label">${(pctEff + pctPend).toFixed(1)}%</span>
1284
+ </div>
1285
+ </div>
1286
+
1287
+ <div class="proportion-bar-container">
1288
+ <div class="bar-segment ${cat.kind === 'income' ? 'effective-inc' : 'effective-exp'}" style="width: ${pctEff}%;"></div>
1289
+ <div class="bar-segment ${cat.kind === 'income' ? 'pending-inc' : 'pending-exp'}" style="width: ${pctPend}%;"></div>
1290
+ </div>
1291
+
1292
+ <div class="cat-breakdown-text">
1293
+ <span>Efetivado: <strong>${formatMultiCurrency(cat.effective)}</strong></span>
1294
+ <span>Pendente: <strong>${formatMultiCurrency(cat.pending)}</strong></span>
1295
+ </div>
1296
+ </div>
1297
+
1298
+ <div class="category-tx-details">
1299
+ ${cat.txs.length === 0 ? '<div style="font-size:0.75rem; color:var(--text-dark); font-style:italic; padding:0.25rem;">Nenhum lançamento no mês.</div>' : `
1300
+ <table class="category-tx-table">
1301
+ <colgroup>
1302
+ <col style="width: 14%;">
1303
+ <col style="width: 44%;">
1304
+ <col style="width: 22%;">
1305
+ <col style="width: 8%;">
1306
+ <col style="width: 12%;">
1307
+ </colgroup>
1308
+ <thead>
1309
+ <tr>
1310
+ <th>Data</th>
1311
+ <th>Descrição</th>
1312
+ <th>Conta</th>
1313
+ <th>St.</th>
1314
+ <th style="text-align:right;">Valor</th>
1315
+ </tr>
1316
+ </thead>
1317
+ <tbody>
1318
+ ${cat.txs.map(t => {
1319
+ const dtObj = new Date(t.date + 'T12:00:00');
1320
+ const dtFmt = dtObj.toLocaleDateString('pt-BR', { day: '2-digit', month: '2-digit' });
1321
+ return `
1322
+ <tr>
1323
+ <td>${dtFmt}</td>
1324
+ <td>${escapeHtml(t.description)}</td>
1325
+ <td>${escapeHtml(t.accountName)}</td>
1326
+ <td style="text-align: center;">
1327
+ ${t.status === 'effective'
1328
+ ? `<span title="Efetivado"><i class="fa-solid fa-circle-check" style="color: var(--income-color); font-size: 0.95rem;"></i></span>`
1329
+ : `<span title="Pendente"><i class="fa-solid fa-clock" style="color: var(--accent-primary); font-size: 0.95rem;"></i></span>`
1330
+ }
1331
+ </td>
1332
+ <td style="text-align:right; font-weight:700; color:${t.type === 'income' ? 'var(--income-color)' : 'var(--expense-color)'}; white-space: nowrap;">
1333
+ ${t.type === 'income' ? '+' : '-'} ${formatCurrency(t.amount, t.currency || DEFAULT_CURRENCY)}
1334
+ </td>
1335
+ </tr>
1336
+ `;
1337
+ }).join('')}
1338
+ </tbody>
1339
+ </table>
1340
+ `}
1341
+ </div>
1342
+ `;
1343
+
1344
+ if (cat.kind === 'income') {
1345
+ incListEl.appendChild(div);
1346
+ } else {
1347
+ expListEl.appendChild(div);
1348
+ }
1349
+ });
1350
+
1351
+ document.getElementById('income-categories-total').textContent = formatMultiCurrency(incTotalSum);
1352
+ document.getElementById('expense-categories-total').textContent = formatMultiCurrency(expTotalSum);
1353
+ }
1354
+
1355
+ // Render Recurring & Installment Heat Map
1356
+ function renderHeatMap() {
1357
+ // We use global projectionMonths array
1358
+ const monthsNamesShort = {
1359
+ 1: 'Jan', 2: 'Fev', 3: 'Mar', 4: 'Abr', 5: 'Mai', 6: 'Jun',
1360
+ 7: 'Jul', 8: 'Ago', 9: 'Set', 10: 'Out', 11: 'Nov', 12: 'Dez'
1361
+ };
1362
+
1363
+ const incBody = document.getElementById('heatmap-income-body');
1364
+ const expBody = document.getElementById('heatmap-expense-body');
1365
+
1366
+ incBody.innerHTML = '';
1367
+ expBody.innerHTML = '';
1368
+
1369
+ // Render table headers dynamically
1370
+ const incHeadRow = document.getElementById('heatmap-income-header-row');
1371
+ const expHeadRow = document.getElementById('heatmap-expense-header-row');
1372
+
1373
+ const headerHtml = `
1374
+ <th>Categoria</th>
1375
+ ${projectionMonths.map(p => `<th>${monthsNamesShort[p.month]} ${String(p.year).substring(2)}</th>`).join('')}
1376
+ <th>Total Projetado</th>
1377
+ `;
1378
+ if (incHeadRow) incHeadRow.innerHTML = headerHtml;
1379
+ if (expHeadRow) expHeadRow.innerHTML = headerHtml;
1380
+
1381
+ // Group all transactions in the projectionMonths
1382
+ // Row key: categoryId -> { categoryName, kind, monthValues: { "YYYY-MM": [] } }
1383
+ const heatMatrix = {};
1384
+
1385
+ // Initialize all categories in the matrix
1386
+ categories.forEach(c => {
1387
+ heatMatrix[c.id] = {
1388
+ categoryId: c.id,
1389
+ categoryName: c.name,
1390
+ kind: c.kind,
1391
+ months: {}
1392
+ };
1393
+ projectionMonths.forEach(p => {
1394
+ const key = `${p.year}-${p.month}`;
1395
+ heatMatrix[c.id].months[key] = [];
1396
+ });
1397
+ });
1398
+
1399
+ // Filter year transactions that fall in the projection range
1400
+ allTransactions.forEach(t => {
1401
+ // Ignore all transfers (including bill payments)
1402
+ if (t.type === 'transfer') return;
1403
+
1404
+ if (!t.date || typeof t.date !== 'string') return;
1405
+
1406
+ const tDateObj = new Date(t.date + 'T12:00:00');
1407
+ const tYear = tDateObj.getFullYear();
1408
+ const tMonth = tDateObj.getMonth() + 1; // 1-indexed
1409
+
1410
+ // Check if this month/year matches any of the projection months
1411
+ const isInProjection = projectionMonths.some(p => p.month === tMonth && p.year === tYear);
1412
+ if (!isInProjection) return;
1413
+
1414
+ const catId = t.categoryId || 'cat-none';
1415
+ if (!heatMatrix[catId]) {
1416
+ // Fallback create category
1417
+ heatMatrix[catId] = {
1418
+ categoryId: catId,
1419
+ categoryName: t.categoryName || 'Sem Categoria',
1420
+ kind: t.type === 'income' ? 'income' : 'expense',
1421
+ months: {}
1422
+ };
1423
+ projectionMonths.forEach(p => {
1424
+ const key = `${p.year}-${p.month}`;
1425
+ heatMatrix[catId].months[key] = [];
1426
+ });
1427
+ }
1428
+
1429
+ const key = `${tYear}-${tMonth}`;
1430
+ heatMatrix[catId].months[key].push(t);
1431
+ });
1432
+
1433
+ // Determine max cell value to calculate color opacity relative range (heat map effect)
1434
+ let maxCellValue = 100; // default min divisor
1435
+ Object.values(heatMatrix).forEach(row => {
1436
+ projectionMonths.forEach(p => {
1437
+ const key = `${p.year}-${p.month}`;
1438
+ const sum = row.months[key].reduce((acc, t) => acc + t.amount, 0);
1439
+ if (sum > maxCellValue) {
1440
+ maxCellValue = sum;
1441
+ }
1442
+ });
1443
+ });
1444
+
1445
+ // Accumulators for column totals
1446
+ const colSums = {};
1447
+ projectionMonths.forEach(p => {
1448
+ const key = `${p.year}-${p.month}`;
1449
+ colSums[key] = { income: 0, expense: 0 };
1450
+ });
1451
+ let totalIncomeSum = 0;
1452
+ let totalExpenseSum = 0;
1453
+ let hasIncomeData = false;
1454
+ let hasExpenseData = false;
1455
+
1456
+ // Render Rows
1457
+ Object.values(heatMatrix).forEach(row => {
1458
+ // Calculate row total sum
1459
+ let rowTotal = 0;
1460
+ projectionMonths.forEach(p => {
1461
+ const key = `${p.year}-${p.month}`;
1462
+ rowTotal += row.months[key].reduce((acc, t) => acc + t.amount, 0);
1463
+ });
1464
+
1465
+ // Skip category row if it has no recurrings/installments in these months
1466
+ if (rowTotal === 0) return;
1467
+
1468
+ // Update column sums
1469
+ if (row.kind === 'income') {
1470
+ hasIncomeData = true;
1471
+ totalIncomeSum += rowTotal;
1472
+ projectionMonths.forEach(p => {
1473
+ const key = `${p.year}-${p.month}`;
1474
+ colSums[key].income += row.months[key].reduce((acc, t) => acc + t.amount, 0);
1475
+ });
1476
+ } else {
1477
+ hasExpenseData = true;
1478
+ totalExpenseSum += rowTotal;
1479
+ projectionMonths.forEach(p => {
1480
+ const key = `${p.year}-${p.month}`;
1481
+ colSums[key].expense += row.months[key].reduce((acc, t) => acc + t.amount, 0);
1482
+ });
1483
+ }
1484
+
1485
+ const tr = document.createElement('tr');
1486
+
1487
+ // Column 1: Category Name
1488
+ let cellsHtml = `<td>${escapeHtml(row.categoryName)}</td>`;
1489
+
1490
+ // Columns: Months
1491
+ projectionMonths.forEach(p => {
1492
+ const key = `${p.year}-${p.month}`;
1493
+ const monthTxs = row.months[key];
1494
+ const sum = monthTxs.reduce((acc, t) => acc + t.amount, 0);
1495
+
1496
+ if (sum === 0) {
1497
+ cellsHtml += `<td class="heatmap-empty">-</td>`;
1498
+ } else {
1499
+ // Calculate opacity relative to max value in grid
1500
+ const opacity = Math.min(1, Math.max(0.1, sum / maxCellValue));
1501
+ const bgColor = row.kind === 'income'
1502
+ ? `rgba(16, 185, 129, ${opacity})`
1503
+ : `rgba(244, 63, 94, ${opacity})`;
1504
+
1505
+ const textColor = opacity > 0.65 ? '#fff' : 'var(--text-main)';
1506
+
1507
+ const cellId = `hc-${row.categoryId}-${key}`;
1508
+
1509
+ cellsHtml += `
1510
+ <td style="padding:0.4rem;">
1511
+ <span class="heatmap-cell-value" id="${cellId}"
1512
+ style="background:${bgColor}; color:${textColor};"
1513
+ onclick="showHeatmapCellDetails('${row.categoryId}', ${p.month}, ${p.year}, '${escapeJsAttr(row.categoryName)}')">
1514
+ ${formatCurrency(sum, DEFAULT_CURRENCY)}
1515
+ </span>
1516
+ </td>
1517
+ `;
1518
+ }
1519
+ });
1520
+
1521
+ // Row Total
1522
+ cellsHtml += `<td>${formatCurrency(rowTotal, DEFAULT_CURRENCY)}</td>`;
1523
+ tr.innerHTML = cellsHtml;
1524
+
1525
+ if (row.kind === 'income') {
1526
+ incBody.appendChild(tr);
1527
+ } else {
1528
+ expBody.appendChild(tr);
1529
+ }
1530
+ });
1531
+
1532
+ // Fallback for empty tables
1533
+ const colspan = projectionMonths.length + 2;
1534
+ if (incBody.innerHTML === '') {
1535
+ incBody.innerHTML = `<tr><td colspan="${colspan}" class="heatmap-empty" style="text-align:center;">Nenhuma receita recorrente/parcelada ativa no semestre.</td></tr>`;
1536
+ }
1537
+ if (expBody.innerHTML === '') {
1538
+ expBody.innerHTML = `<tr><td colspan="${colspan}" class="heatmap-empty" style="text-align:center;">Nenhuma despesa recorrente/parcelada ativa no semestre.</td></tr>`;
1539
+ }
1540
+
1541
+ // Render Footers with Column Totals
1542
+ const incFoot = document.getElementById('heatmap-income-foot');
1543
+ if (incFoot) {
1544
+ if (!hasIncomeData) {
1545
+ incFoot.innerHTML = '';
1546
+ } else {
1547
+ let cellsHtml = `<td style="text-align:left; font-weight:700;">TOTAL</td>`;
1548
+ projectionMonths.forEach(p => {
1549
+ const key = `${p.year}-${p.month}`;
1550
+ cellsHtml += `<td style="font-weight:700; color:var(--income-color);">${formatCurrency(colSums[key].income, DEFAULT_CURRENCY)}</td>`;
1551
+ });
1552
+ cellsHtml += `<td style="font-weight:700; color:var(--income-color);">${formatCurrency(totalIncomeSum, DEFAULT_CURRENCY)}</td>`;
1553
+ incFoot.innerHTML = `<tr>${cellsHtml}</tr>`;
1554
+ }
1555
+ }
1556
+
1557
+ const expFoot = document.getElementById('heatmap-expense-foot');
1558
+ if (expFoot) {
1559
+ if (!hasExpenseData) {
1560
+ expFoot.innerHTML = '';
1561
+ } else {
1562
+ let cellsHtml = `<td style="text-align:left; font-weight:700;">TOTAL</td>`;
1563
+ projectionMonths.forEach(p => {
1564
+ const key = `${p.year}-${p.month}`;
1565
+ cellsHtml += `<td style="font-weight:700; color:var(--expense-color);">${formatCurrency(colSums[key].expense, DEFAULT_CURRENCY)}</td>`;
1566
+ });
1567
+ cellsHtml += `<td style="font-weight:700; color:var(--expense-color);">${formatCurrency(totalExpenseSum, DEFAULT_CURRENCY)}</td>`;
1568
+ expFoot.innerHTML = `<tr>${cellsHtml}</tr>`;
1569
+ }
1570
+ }
1571
+ }
1572
+
1573
+ // Show projected details inside modal on cell click
1574
+ function showHeatmapCellDetails(categoryId, month, year, categoryName) {
1575
+ const monthsNames = {
1576
+ 1: 'Janeiro', 2: 'Fevereiro', 3: 'Março', 4: 'Abril', 5: 'Maio', 6: 'Junho',
1577
+ 7: 'Julho', 8: 'Agosto', 9: 'Setembro', 10: 'Outubro', 11: 'Novembro', 12: 'Dezembro'
1578
+ };
1579
+
1580
+ const title = document.getElementById('modal-details-title');
1581
+ const subtitle = document.getElementById('modal-details-subtitle');
1582
+ const body = document.getElementById('modal-details-table-body');
1583
+
1584
+ title.textContent = "Detalhamento de Projeções";
1585
+ subtitle.textContent = `Categoria: ${categoryName} | Mês: ${monthsNames[month]} de ${year}`;
1586
+ body.innerHTML = '';
1587
+
1588
+ // Filter year transactions in state
1589
+ const currentMonthStr = `${year}-${String(month).padStart(2, '0')}`;
1590
+ const matches = allTransactions.filter(t => {
1591
+ // Ignore all transfers (including bill payments)
1592
+ if (t.type === 'transfer') return false;
1593
+
1594
+ const catMatch = t.categoryId === categoryId || (!t.categoryId && categoryId === 'cat-none');
1595
+ return catMatch && t.date && t.date.startsWith(currentMonthStr);
1596
+ });
1597
+
1598
+ matches.sort((a,b) => a.date.localeCompare(b.date));
1599
+
1600
+ matches.forEach(t => {
1601
+ const tr = document.createElement('tr');
1602
+ const dtObj = new Date(t.date + 'T12:00:00');
1603
+ const dtFmt = dtObj.toLocaleDateString('pt-BR');
1604
+
1605
+ tr.innerHTML = `
1606
+ <td style="padding:0.5rem 0.75rem;">${dtFmt}</td>
1607
+ <td style="padding:0.5rem 0.75rem; font-weight:500;">${escapeHtml(t.description)}</td>
1608
+ <td style="padding:0.5rem 0.75rem;">${escapeHtml(t.accountName)}</td>
1609
+ <td style="padding:0.5rem 0.75rem; text-align:right; font-weight:700; color:${t.type === 'income' ? 'var(--income-color)' : 'var(--text-main)'}">
1610
+ ${t.type === 'income' ? '+' : '-'} ${formatCurrency(t.amount, DEFAULT_CURRENCY)}
1611
+ </td>
1612
+ `;
1613
+ body.appendChild(tr);
1614
+ });
1615
+
1616
+ openModal('modal-cell-details');
1617
+ }
1618
+
1619
+ // JS escaping helper
1620
+ // Escapes a value for safe embedding as a single-quoted JS string literal *inside* an
1621
+ // HTML attribute (e.g. onclick="fn('${escapeJsAttr(value)}')"). JS-escaping backslash+quote
1622
+ // alone is not enough: the outer onclick="..." attribute is double-quoted, and the HTML
1623
+ // parser (which finds the attribute's closing quote before any JS is parsed) doesn't
1624
+ // understand a JS \" escape — a raw '"' still ends the attribute early. HTML-escaping the
1625
+ // JS-escaped result closes that gap too.
1626
+ function escapeJsAttr(str) {
1627
+ if (!str) return '';
1628
+ return escapeHtml(String(str).replace(/\\/g, '\\\\').replace(/'/g, "\\'"));
1629
+ }
1630
+
1631
+ // Load bootstrap - try direct execution first, and bind to onload as fallback.
1632
+ // Locale must resolve before the first render: formatCurrency reads currentLocale, and
1633
+ // checkLocale() only re-translates static data-i18n text afterward — it never re-renders
1634
+ // the KPI/category/chart money values initDashboard() already painted, so those would be
1635
+ // stuck showing en-US formatting for a pt/es user if initDashboard() won the race. The
1636
+ // month/year/heatmap-months change listeners must wait for the same reason: registering them
1637
+ // early would let a user interaction call loadTransactionsData() (and therefore
1638
+ // calculateAndRenderAll()'s formatCurrency calls) before checkLocale() resolves.
1639
+ //
1640
+ // If the user navigates away while checkLocale()'s /api/status request is still in flight,
1641
+ // app.js's renderFragment() tears this fragment's DOM down for the next one — the stale
1642
+ // continuation must not resume into initDashboard() (or attach listeners) afterward, since
1643
+ // document.getElementById(...) calls could reach into whatever dashboard loaded next
1644
+ // (mirrors overview.html's initOverview guard). panelsLoading itself can't be the marker:
1645
+ // it's a top-level `var`, so it lives on the shared global `window` every fragment script
1646
+ // executes in, and projections.html declares the very same name — a later-loaded fragment's
1647
+ // script would silently overwrite it out from under this still-pending continuation. Capture
1648
+ // it into a function-local const instead, which no other script can ever reach or reassign.
1649
+ var hasInitialized = false;
1650
+ async function runInit() {
1651
+ if (hasInitialized) return;
1652
+ hasInitialized = true;
1653
+ const ownFragmentMarker = panelsLoading;
1654
+ await checkLocale();
1655
+ if (!ownFragmentMarker || !ownFragmentMarker.isConnected) return;
1656
+
1657
+ const mSel = document.getElementById('month-select');
1658
+ const ySel = document.getElementById('year-select');
1659
+ const hmSel = document.getElementById('heatmap-months-select');
1660
+ if (mSel) mSel.addEventListener('change', loadTransactionsData);
1661
+ if (ySel) ySel.addEventListener('change', loadTransactionsData);
1662
+ if (hmSel) hmSel.addEventListener('change', loadTransactionsData);
1663
+
1664
+ await initDashboard();
1665
+ }
1666
+
1667
+ // Run immediately since DOM is already parsed (script is at bottom of body)
1668
+ runInit();
1669
+
1670
+ // Fallback for full page loads or wrapper injections
1671
+ runInit();
1672
+
1673
+ // Translation engine and dictionaries
1674
+ var TRANSLATIONS = {
1675
+ en: {
1676
+ // Sidebar Menu
1677
+ tooltip_overview: "Overview",
1678
+ tooltip_pending: "Pending",
1679
+ tooltip_comparative: "Comparative",
1680
+ tooltip_projections: "Projections",
1681
+ tooltip_accounts: "Bank Accounts",
1682
+ tooltip_cards: "Credit Cards",
1683
+ menu_categories: "Categories",
1684
+ menu_dashboards: "Dashboards",
1685
+
1686
+ // Month names
1687
+ january: "January", february: "February", march: "March", april: "April", may: "May", june: "June",
1688
+ july: "July", august: "August", september: "September", october: "October", november: "November", december: "December",
1689
+
1690
+ // General UI terms
1691
+ reference_label: "Reference:",
1692
+ day_sun: "Sun", day_mon: "Mon", day_tue: "Tue", day_wed: "Wed", day_thu: "Thu", day_fri: "Fri", day_sat: "Sat",
1693
+ paid: "Paid", unpaid: "Unpaid", active: "Active", inactive: "Inactive",
1694
+
1695
+ // Overview Dashboard
1696
+ overview_title: "Overview",
1697
+ overview_subtitle: "Monthly financial summary, calendar, and quick shortcuts",
1698
+ accounts_balance: "Accounts Balance",
1699
+ expenses_month: "Expenses this Month",
1700
+ card_bills: "Credit Card Bills",
1701
+ incomes_month: "Incomes this Month",
1702
+ final_projection: "Final Projection:",
1703
+ recent_transactions: "Recent Transactions",
1704
+ due_calendar: "Daily Flow & Dues",
1705
+ expenses_distribution: "Expenses Distribution",
1706
+ quick_shortcuts: "Quick Shortcuts",
1707
+ new_transaction: "New Transaction",
1708
+ new_transfer: "New Transfer",
1709
+ new_category: "New Category",
1710
+ new_card: "New Card",
1711
+ new_account: "New Account",
1712
+ no_expenses_month: "No expenses recorded this month.",
1713
+ no_recent_transactions: "No recent transactions found.",
1714
+ no_dues_period: "No transactions due in this period.",
1715
+ income: "Income",
1716
+ expense: "Expense",
1717
+ paid_reconciled: "Paid / Reconciled",
1718
+
1719
+ // Projections / Heatmap Dashboard
1720
+ projections_title: "Recurring & Installment Projections",
1721
+ projections_subtitle: "Advanced visual mapping and projection of active recurrences and installments for the next months",
1722
+ projection_label: "Projection:",
1723
+ months_3: "3 Months",
1724
+ months_6: "6 Months",
1725
+ months_9: "9 Months",
1726
+ months_12: "12 Months",
1727
+ heatmap_income_title: "Recurrent / Installment Incomes",
1728
+ heatmap_expense_title: "Recurrent / Installment Expenses",
1729
+ total: "Total",
1730
+ no_recurrent_incomes: "No active recurrent or installment incomes in the selected semester.",
1731
+ no_recurrent_expenses: "No active recurrent or installment expenses in the selected semester.",
1732
+ modal_details_title: "Projection Breakdown",
1733
+ modal_details_subtitle: "Details of projected transactions for the category and month",
1734
+ col_date: "Date",
1735
+ col_desc: "Description",
1736
+ col_value: "Value",
1737
+ col_status: "Status",
1738
+ btn_close: "Close",
1739
+
1740
+ // Comparative Dashboard
1741
+ comparative_title: "Comparative Dashboard",
1742
+ comparative_subtitle: "Analysis and comparison of monthly incomes vs expenses, and category limits",
1743
+ month_summary_title: "Month Summary",
1744
+ cat_spending_title: "Spending by Category",
1745
+ card_limits_title: "Category Budgets & Limits",
1746
+ col_category: "Category",
1747
+ col_limit: "Budget Limit",
1748
+ col_spent: "Spent",
1749
+ col_status_limit: "Status",
1750
+ col_percentage: "Percentage",
1751
+ within_limit: "Within Limit",
1752
+ exceeded: "Exceeded",
1753
+ reception: "Incomes",
1754
+ deduction: "Expenses",
1755
+ net_balance: "Net Balance",
1756
+ performance: "Financial Health",
1757
+ no_spending_month: "No category spend recorded this month.",
1758
+
1759
+ // Accounts Dashboard
1760
+ accounts_title: "Bank Accounts",
1761
+ accounts_subtitle: "Manage accounts, checking balances, and reviewing statements",
1762
+ active_account_statement: "Account Statement",
1763
+ btn_new_transaction: "New Transaction",
1764
+ btn_new_transfer: "New Transfer",
1765
+ search_description_placeholder: "Type to search...",
1766
+ filter_type_label: "Type",
1767
+ filter_type_all: "All",
1768
+ filter_type_income: "Incomes",
1769
+ filter_type_expense: "Expenses",
1770
+ col_actions: "Actions",
1771
+ action_confirm: "Confirm",
1772
+ action_edit: "Edit",
1773
+ action_delete: "Delete",
1774
+ no_transactions_account: "No transactions recorded for this account in the selected month.",
1775
+ confirm_delete_title: "Are you sure you want to permanently delete this transaction?",
1776
+ modal_new_tx_title: "New Transaction",
1777
+ modal_new_transfer_title: "New Transfer",
1778
+ label_account: "Account",
1779
+ label_description: "Description",
1780
+ label_value: "Value",
1781
+ label_date: "Date",
1782
+ label_category: "Category / Subcategory",
1783
+ label_type: "Type",
1784
+ label_status: "Status",
1785
+ status_pending: "Pending",
1786
+ status_confirmed: "Paid / Confirmed",
1787
+ btn_cancel: "Cancel",
1788
+ btn_save: "Save",
1789
+ label_origin: "Origin Account",
1790
+ label_destination: "Destination Account",
1791
+
1792
+ // Pending Dashboard
1793
+ pending_title: "Pending Transactions",
1794
+ pending_subtitle: "Monitoring and quick confirmation of pending or future transactions",
1795
+ pending_kpi_total: "Total Pending",
1796
+ pending_kpi_incomes: "Pending Incomes",
1797
+ pending_kpi_expenses: "Pending Expenses",
1798
+ pending_chart_incomes: "Pending Incomes Trend",
1799
+ pending_chart_expenses: "Pending Expenses Trend",
1800
+ btn_confirm: "Confirm",
1801
+ btn_edit: "Edit",
1802
+ btn_delete: "Delete",
1803
+ no_pending_transactions: "No pending transactions found for this period.",
1804
+ toast_success_confirm: "Transaction confirmed successfully!",
1805
+
1806
+ // Categories Dashboard
1807
+ categories_title: "Category Management",
1808
+ categories_subtitle: "Visualize, search, and manage categories and subcategories in a clean tree list",
1809
+ btn_new_category: "New Category",
1810
+ search_category_placeholder: "Search categories...",
1811
+ col_type: "Type",
1812
+ col_actions_cat: "Actions",
1813
+ subcategories_label: "Subcategories",
1814
+ no_subcategories: "No subcategories registered.",
1815
+ modal_new_cat_title: "New Category",
1816
+ modal_new_subcat_title: "New Subcategory",
1817
+ label_name: "Name",
1818
+ label_color: "Color",
1819
+ label_parent_category: "Parent Category (Read-Only)",
1820
+ toast_success_cat: "Category created successfully!",
1821
+ toast_success_subcat: "Subcategory created successfully!",
1822
+
1823
+ // Cards Dashboard
1824
+ cards_title: "Credit Cards",
1825
+ cards_subtitle: "Manage credit cards, credit limits, and statement history",
1826
+ card_bill_details: "Card Bill Details",
1827
+ btn_pay_bill: "Pay Bill",
1828
+ btn_revert_payment: "Revert Payment",
1829
+ bill_status: "Bill Status:",
1830
+ status_open: "Open",
1831
+ status_closed: "Closed",
1832
+ status_paid: "Paid",
1833
+ no_card_transactions: "No transactions recorded for this card bill in the selected cycle.",
1834
+
1835
+ // Dashboards Manager Dashboard
1836
+ dashboards_title: "Dashboards Monitor",
1837
+ dashboards_subtitle: "List, view source, and upload patty dashboards",
1838
+ col_dashboard: "Dashboard",
1839
+ col_last_update: "Last Updated",
1840
+ btn_view_source: "View Source",
1841
+ btn_download: "Download",
1842
+ upload_new_dashboard: "Upload New Dashboard",
1843
+ placeholder_dashboard_name: "Dashboard Name (e.g. pending)",
1844
+ upload_instructions: "Select or drop HTML file here to upload",
1845
+ btn_upload: "Upload",
1846
+ modal_source_title: "HTML Source Code",
1847
+
1848
+ // Tags Management
1849
+ menu_tags: "Tags",
1850
+ tags_title: "Tag Management",
1851
+ tags_subtitle: "Manage tags to label and organize your transactions",
1852
+ panel_title_tags: "Active Tags",
1853
+ btn_new_tag: "New Tag",
1854
+ label_tag_name: "Tag Name",
1855
+ placeholder_tag_name: "E.g. work, travel, refund",
1856
+ empty_tags_message: "No tags registered.",
1857
+ btn_save: "Save",
1858
+ btn_cancel: "Cancel",
1859
+ toast_success_tag_created: 'Tag "{name}" created successfully!',
1860
+ toast_success_tag_deleted: 'Tag "{name}" deleted successfully!',
1861
+ confirm_delete_tag: 'Are you sure you want to delete tag "{name}"?\n(This action will remove the tag from all linked transactions)'
1862
+ },
1863
+ pt: {
1864
+ // Sidebar Menu
1865
+ tooltip_overview: "Visão Geral",
1866
+ tooltip_pending: "Pendentes",
1867
+ tooltip_comparative: "Comparativo",
1868
+ tooltip_projections: "Projeções",
1869
+ tooltip_accounts: "Contas Bancárias",
1870
+ tooltip_cards: "Cartões de Crédito",
1871
+ menu_categories: "Categorias",
1872
+ menu_dashboards: "Dashboards",
1873
+
1874
+ // Month names
1875
+ january: "Janeiro", february: "Fevereiro", march: "Março", april: "Abril", may: "Maio", june: "Junho",
1876
+ july: "Julho", august: "Agosto", september: "Setembro", october: "Outubro", november: "Novembro", december: "Dezembro",
1877
+
1878
+ // General UI terms
1879
+ reference_label: "Referência:",
1880
+ day_sun: "Dom", day_mon: "Seg", day_tue: "Ter", day_wed: "Qua", day_thu: "Qui", day_fri: "Sex", day_sat: "Sáb",
1881
+ paid: "Pago", unpaid: "Não Pago", active: "Ativo", inactive: "Inativo",
1882
+
1883
+ // Overview Dashboard
1884
+ overview_title: "Visão Geral",
1885
+ overview_subtitle: "Consolidado financeiro mensal, calendário e atalhos rápidos",
1886
+ accounts_balance: "Saldo em Contas",
1887
+ expenses_month: "Despesas do Mês",
1888
+ card_bills: "Faturas de Cartão",
1889
+ incomes_month: "Receitas do Mês",
1890
+ final_projection: "Projeção Final:",
1891
+ recent_transactions: "Lançamentos Recentes",
1892
+ due_calendar: "Fluxo Diário",
1893
+ expenses_distribution: "Distribuição de Despesas",
1894
+ quick_shortcuts: "Atalhos Rápidos",
1895
+ new_transaction: "Novo Lançamento",
1896
+ new_transfer: "Nova Transferência",
1897
+ new_category: "Nova Categoria",
1898
+ new_card: "Novo Cartão",
1899
+ new_account: "Nova Conta",
1900
+ no_expenses_month: "Sem despesas registradas neste mês.",
1901
+ no_recent_transactions: "Nenhuma transação recente encontrada.",
1902
+ no_dues_period: "Sem vencimentos neste período.",
1903
+ income: "Receita",
1904
+ expense: "Despesa",
1905
+ paid_reconciled: "Pago / Conciliado",
1906
+
1907
+ // Projections / Heatmap Dashboard
1908
+ projections_title: "Projeção de Recorrências e Parcelas",
1909
+ projections_subtitle: "Mapeamento visual avançado e projeção de recorrências e parcelas ativas para os próximos meses",
1910
+ projection_label: "Projeção:",
1911
+ months_3: "3 Meses",
1912
+ months_6: "6 Meses",
1913
+ months_9: "9 Meses",
1914
+ months_12: "12 Meses",
1915
+ heatmap_income_title: "Receitas Recorrentes / Parceladas",
1916
+ heatmap_expense_title: "Despesas Recorrentes / Parceladas",
1917
+ total: "Total",
1918
+ no_recurrent_incomes: "Nenhuma receita recorrente/parcelada ativa no semestre.",
1919
+ no_recurrent_expenses: "Nenhuma despesa recorrente/parcelada ativa no semestre.",
1920
+ modal_details_title: "Detalhamento de Projeções",
1921
+ modal_details_subtitle: "Detalhes das transações projetadas para a categoria e mês",
1922
+ col_date: "Data",
1923
+ col_desc: "Descrição",
1924
+ col_value: "Valor",
1925
+ col_status: "Status",
1926
+ btn_close: "Fechar",
1927
+
1928
+ // Comparative Dashboard
1929
+ comparative_title: "Dashboard Comparativo",
1930
+ comparative_subtitle: "Análise e comparação mensal de receitas vs despesas e limites por categoria",
1931
+ month_summary_title: "Resumo do Mês",
1932
+ cat_spending_title: "Gastos por Categoria",
1933
+ card_limits_title: "Orçamentos e Limites de Categorias",
1934
+ col_category: "Categoria",
1935
+ col_limit: "Limite de Orçamento",
1936
+ col_spent: "Gasto",
1937
+ col_status_limit: "Status",
1938
+ col_percentage: "Porcentagem",
1939
+ within_limit: "Dentro do Limite",
1940
+ exceeded: "Excedido",
1941
+ reception: "Receitas",
1942
+ deduction: "Despesas",
1943
+ net_balance: "Saldo Líquido",
1944
+ performance: "Saúde Financeira",
1945
+ no_spending_month: "Sem despesas registradas por categoria neste mês.",
1946
+
1947
+ // Accounts Dashboard
1948
+ accounts_title: "Minhas Contas",
1949
+ accounts_subtitle: "Gerencie contas, consulte saldos e revise extratos",
1950
+ active_account_statement: "Extrato de Conta",
1951
+ btn_new_transaction: "Novo Lançamento",
1952
+ btn_new_transfer: "Nova Transferência",
1953
+ search_description_placeholder: "Digite para filtrar...",
1954
+ filter_type_label: "Tipo",
1955
+ filter_type_all: "Todos",
1956
+ filter_type_income: "Receitas",
1957
+ filter_type_expense: "Despesas",
1958
+ col_actions: "Ações",
1959
+ action_confirm: "Confirmar",
1960
+ action_edit: "Editar",
1961
+ action_delete: "Excluir",
1962
+ no_transactions_account: "Nenhum lançamento nesta conta para o mês selecionado.",
1963
+ confirm_delete_title: "Deseja excluir definitivamente a transação?",
1964
+ modal_new_tx_title: "Novo Lançamento",
1965
+ modal_new_transfer_title: "Nova Transferência",
1966
+ label_account: "Conta",
1967
+ label_description: "Descrição",
1968
+ label_value: "Valor",
1969
+ label_date: "Data",
1970
+ label_category: "Categoria / Subcategoria",
1971
+ label_type: "Tipo",
1972
+ label_status: "Status",
1973
+ status_pending: "Pendente",
1974
+ status_confirmed: "Pago / Confirmado",
1975
+ btn_cancel: "Cancelar",
1976
+ btn_save: "Salvar",
1977
+ label_origin: "Conta Origem",
1978
+ label_destination: "Conta Destino",
1979
+
1980
+ // Pending Dashboard
1981
+ pending_title: "Transações Pendentes",
1982
+ pending_subtitle: "Monitoramento e confirmação rápida de lançamentos pendentes ou futuros",
1983
+ pending_kpi_total: "Total Pendente",
1984
+ pending_kpi_incomes: "Receitas Pendentes",
1985
+ pending_kpi_expenses: "Despesas Pendentes",
1986
+ pending_chart_incomes: "Tendência de Receitas Pendentes",
1987
+ pending_chart_expenses: "Tendência de Despesas Pendentes",
1988
+ btn_confirm: "Confirmar",
1989
+ btn_edit: "Editar",
1990
+ btn_delete: "Excluir",
1991
+ no_pending_transactions: "Nenhuma transação pendente encontrada para este período.",
1992
+ toast_success_confirm: "Transação confirmada com sucesso!",
1993
+
1994
+ // Categories Dashboard
1995
+ categories_title: "Gerenciamento de Categorias",
1996
+ categories_subtitle: "Visualize, pesquise e gerencie categorias e subcategorias em árvore",
1997
+ btn_new_category: "Nova Categoria",
1998
+ search_category_placeholder: "Pesquisar categorias...",
1999
+ col_type: "Tipo",
2000
+ col_actions_cat: "Ações",
2001
+ subcategories_label: "Subcategorias",
2002
+ no_subcategories: "Nenhuma subcategoria cadastrada.",
2003
+ modal_new_cat_title: "Nova Categoria",
2004
+ modal_new_subcat_title: "Nova Subcategoria",
2005
+ label_name: "Nome",
2006
+ label_color: "Cor",
2007
+ label_parent_category: "Categoria Pai (Somente Leitura)",
2008
+ toast_success_cat: "Categoria criada com sucesso!",
2009
+ toast_success_subcat: "Subcategoria criada com sucesso!",
2010
+
2011
+ // Cards Dashboard
2012
+ cards_title: "Cartões de Crédito",
2013
+ cards_subtitle: "Gerencie cartões de crédito, limites e histórico de faturas",
2014
+ card_bill_details: "Detalhamento de Fatura",
2015
+ btn_pay_bill: "Pagar Fatura",
2016
+ btn_revert_payment: "Estornar Pagamento",
2017
+ bill_status: "Status da Fatura:",
2018
+ status_open: "Aberta",
2019
+ status_closed: "Fechada",
2020
+ status_paid: "Paga",
2021
+ no_card_transactions: "Nenhuma transação registrada nesta fatura para o ciclo selecionado.",
2022
+
2023
+ // Dashboards Manager Dashboard
2024
+ dashboards_title: "Monitor de Dashboards",
2025
+ dashboards_subtitle: "Liste, visualize o código fonte e envie dashboards para o servidor do patty",
2026
+ col_dashboard: "Dashboard",
2027
+ col_last_update: "Última Atualização",
2028
+ btn_view_source: "Ver Código",
2029
+ btn_download: "Baixar HTML",
2030
+ upload_new_dashboard: "Enviar Novo Dashboard",
2031
+ placeholder_dashboard_name: "Nome do Dashboard (ex: pending)",
2032
+ upload_instructions: "Selecione ou solte o arquivo HTML aqui para upload",
2033
+ btn_upload: "Fazer Upload",
2034
+ modal_source_title: "Código Fonte HTML",
2035
+
2036
+ // Tags Management
2037
+ menu_tags: "Tags",
2038
+ tags_title: "Gerenciar Tags",
2039
+ tags_subtitle: "Gerencie as tags utilizadas para rotular e categorizar suas transações",
2040
+ panel_title_tags: "Tags Ativas",
2041
+ btn_new_tag: "Nova Tag",
2042
+ label_tag_name: "Nome da Tag",
2043
+ placeholder_tag_name: "Ex: trabalho, viagem, reembolso",
2044
+ empty_tags_message: "Nenhuma tag cadastrada.",
2045
+ btn_save: "Salvar",
2046
+ btn_cancel: "Cancelar",
2047
+ toast_success_tag_created: 'Tag "{name}" criada com sucesso!',
2048
+ toast_success_tag_deleted: 'Tag "{name}" excluída com sucesso!',
2049
+ confirm_delete_tag: 'Deseja realmente excluir a tag "{name}"?\n(Esta ação removerá a tag de todas as transações vinculadas)'
2050
+ },
2051
+ es: {
2052
+ // Sidebar Menu
2053
+ tooltip_overview: "Vista General",
2054
+ tooltip_pending: "Pendientes",
2055
+ tooltip_comparative: "Comparativo",
2056
+ tooltip_projections: "Proyecciones",
2057
+ tooltip_accounts: "Cuentas Bancárias",
2058
+ tooltip_cards: "Tarjetas de Crédito",
2059
+ menu_categories: "Categorías",
2060
+ menu_dashboards: "Dashboards",
2061
+
2062
+ // Month names
2063
+ january: "Enero", february: "Febrero", march: "Marzo", april: "Abril", may: "Mayo", june: "Junio",
2064
+ july: "Julio", august: "Agosto", september: "Septiembre", october: "Octubre", november: "Noviembre", december: "Diciembre",
2065
+
2066
+ // General UI terms
2067
+ reference_label: "Referencia:",
2068
+ day_sun: "Dom", day_mon: "Lun", day_tue: "Mar", day_wed: "Mié", day_thu: "Jue", day_fri: "Vie", day_sat: "Sáb",
2069
+ paid: "Pagado", unpaid: "No Pagado", active: "Activo", inactive: "Inactivo",
2070
+
2071
+ // Overview Dashboard
2072
+ overview_title: "Vista General",
2073
+ overview_subtitle: "Resumen financiero mensual, calendario y accesos rápidos",
2074
+ accounts_balance: "Saldo en Cuentas",
2075
+ expenses_month: "Gastos del Mes",
2076
+ card_bills: "Facturas de Tarjeta",
2077
+ incomes_month: "Ingresos del Mes",
2078
+ final_projection: "Proyección Final:",
2079
+ recent_transactions: "Transacciones Recientes",
2080
+ due_calendar: "Calendario de Pagos",
2081
+ expenses_distribution: "Distribución de Gastos",
2082
+ quick_shortcuts: "Accesos Rápidos",
2083
+ new_transaction: "Nueva Transacción",
2084
+ new_transfer: "Nueva Transferencia",
2085
+ new_category: "Nueva Categoría",
2086
+ new_card: "Nueva Tarjeta",
2087
+ new_account: "Nueva Cuenta",
2088
+ no_expenses_month: "No hay gastos registrados este mes.",
2089
+ no_recent_transactions: "No se encontraron transacciones recientes.",
2090
+ no_dues_period: "Sin vencimientos en este período.",
2091
+ income: "Ingreso",
2092
+ expense: "Gasto",
2093
+ paid_reconciled: "Pagado / Conciliado",
2094
+
2095
+ // Projections / Heatmap Dashboard
2096
+ projections_title: "Proyección de Recurrencias y Cuotas",
2097
+ projections_subtitle: "Mapeo visual avanzado y proyección de recurrencias y cuotas activas para los próximos meses",
2098
+ projection_label: "Proyección:",
2099
+ months_3: "3 Meses",
2100
+ months_6: "6 Meses",
2101
+ months_9: "9 Meses",
2102
+ months_12: "12 Meses",
2103
+ heatmap_income_title: "Ingresos Recurrentes / Cuotas",
2104
+ heatmap_expense_title: "Gastos Recurrentes / Cuotas",
2105
+ total: "Total",
2106
+ no_recurrent_incomes: "Ningún ingreso recurrente o en cuotas activo en el semestre seleccionado.",
2107
+ no_recurrent_expenses: "Ningún gasto recurrente o en cuotas activo en el semestre seleccionado.",
2108
+ modal_details_title: "Detalle de Proyecciones",
2109
+ modal_details_subtitle: "Detalles de transacciones proyectadas para la categoría y mes",
2110
+ col_date: "Fecha",
2111
+ col_desc: "Descripción",
2112
+ col_value: "Valor",
2113
+ col_status: "Estado",
2114
+ btn_close: "Cerrar",
2115
+
2116
+ // Comparative Dashboard
2117
+ comparative_title: "Dashboard Comparativo",
2118
+ comparative_subtitle: "Análisis y comparación mensual de ingresos vs gastos y límites por categoría",
2119
+ month_summary_title: "Resumen del Mes",
2120
+ cat_spending_title: "Gastos por Categoría",
2121
+ card_limits_title: "Presupuestos y Límites de Categorías",
2122
+ col_category: "Categoría",
2123
+ col_limit: "Límite de Presupuesto",
2124
+ col_spent: "Gastado",
2125
+ col_status_limit: "Estado",
2126
+ col_percentage: "Porcentaje",
2127
+ within_limit: "Dentro del Límite",
2128
+ exceeded: "Excedido",
2129
+ reception: "Ingresos",
2130
+ deduction: "Gastos",
2131
+ net_balance: "Saldo Neto",
2132
+ performance: "Salud Financiera",
2133
+ no_spending_month: "No hay gastos registrados por categoría este mes.",
2134
+
2135
+ // Accounts Dashboard
2136
+ accounts_title: "Cuentas Bancarias",
2137
+ accounts_subtitle: "Administre cuentas, consulte saldos y revise extractos",
2138
+ active_account_statement: "Extracto de Cuenta",
2139
+ btn_new_transaction: "Nueva Transacción",
2140
+ btn_new_transfer: "Nueva Transferencia",
2141
+ search_description_placeholder: "Escriba para filtrar...",
2142
+ filter_type_label: "Tipo",
2143
+ filter_type_all: "Todos",
2144
+ filter_type_income: "Ingresos",
2145
+ filter_type_expense: "Gastos",
2146
+ col_actions: "Acciones",
2147
+ action_confirm: "Confirmar",
2148
+ action_edit: "Editar",
2149
+ action_delete: "Eliminar",
2150
+ no_transactions_account: "No hay transacciones registradas en esta cuenta en el mes seleccionado.",
2151
+ confirm_delete_title: "¿Está seguro de eliminar definitivamente esta transacción?",
2152
+ modal_new_tx_title: "Nueva Transacción",
2153
+ modal_new_transfer_title: "Nueva Transferencia",
2154
+ label_account: "Cuenta",
2155
+ label_description: "Descripción",
2156
+ label_value: "Valor",
2157
+ label_date: "Fecha",
2158
+ label_category: "Categoría / Subcategoría",
2159
+ label_type: "Tipo",
2160
+ label_status: "Estado",
2161
+ status_pending: "Pendiente",
2162
+ status_confirmed: "Pagado / Confirmado",
2163
+ btn_cancel: "Cancelar",
2164
+ btn_save: "Guardar",
2165
+ label_origin: "Cuenta Origen",
2166
+ label_destination: "Cuenta Destino",
2167
+
2168
+ // Pending Dashboard
2169
+ pending_title: "Transacciones Pendientes",
2170
+ pending_subtitle: "Monitoreo y confirmación rápida de transacciones pendientes o futuras",
2171
+ pending_kpi_total: "Total Pendiente",
2172
+ pending_kpi_incomes: "Ingresos Pendientes",
2173
+ pending_kpi_expenses: "Gastos Pendientes",
2174
+ pending_chart_incomes: "Tendencia de Ingresos Pendientes",
2175
+ pending_chart_expenses: "Tendencia de Gastos Pendientes",
2176
+ btn_confirm: "Confirmar",
2177
+ btn_edit: "Editar",
2178
+ btn_delete: "Eliminar",
2179
+ no_pending_transactions: "No se encontraron transacciones pendientes en este período.",
2180
+ toast_success_confirm: "¡Transacción confirmada con éxito!",
2181
+
2182
+ // Categories Dashboard
2183
+ categories_title: "Gestión de Categorías",
2184
+ categories_subtitle: "Visualice, busque y gestione categorías y subcategorías en árbol",
2185
+ btn_new_category: "Nueva Categoría",
2186
+ search_category_placeholder: "Buscar categorías...",
2187
+ col_type: "Tipo",
2188
+ col_actions_cat: "Acciones",
2189
+ subcategories_label: "Subcategorías",
2190
+ no_subcategories: "Ninguna subcategoría registrada.",
2191
+ modal_new_cat_title: "Nueva Categoría",
2192
+ modal_new_subcat_title: "Nueva Subcategoría",
2193
+ label_name: "Nombre",
2194
+ label_color: "Color",
2195
+ label_parent_category: "Categoría Padre (Solo Lectura)",
2196
+ toast_success_cat: "¡Categoría creada con éxito!",
2197
+ toast_success_subcat: "¡Subcategoría creada con éxito!",
2198
+
2199
+ // Cards Dashboard
2200
+ cards_title: "Tarjetas de Crédito",
2201
+ cards_subtitle: "Gestione tarjetas de crédito, límites y facturas",
2202
+ card_bill_details: "Detalle de Factura",
2203
+ btn_pay_bill: "Pagar Factura",
2204
+ btn_revert_payment: "Revertir Pago",
2205
+ bill_status: "Estado de la Factura:",
2206
+ status_open: "Abierta",
2207
+ status_closed: "Cerrada",
2208
+ status_paid: "Pagada",
2209
+ no_card_transactions: "Ninguna transacción registrada en esta factura para el ciclo seleccionado.",
2210
+
2211
+ // Dashboards Manager Dashboard
2212
+ dashboards_title: "Gestor de Dashboards",
2213
+ dashboards_subtitle: "Liste, vea el código fuente y suba dashboards al servidor de patty",
2214
+ col_dashboard: "Dashboard",
2215
+ col_last_update: "Última Actualización",
2216
+ btn_view_source: "Ver Código",
2217
+ btn_download: "Descargar HTML",
2218
+ upload_new_dashboard: "Subir Nuevo Dashboard",
2219
+ placeholder_dashboard_name: "Nombre del Dashboard (ej: pending)",
2220
+ upload_instructions: "Seleccione o arrastre el archivo HTML aquí para subir",
2221
+ btn_upload: "Subir Dashboard",
2222
+ modal_source_title: "Código Fuente HTML",
2223
+
2224
+ // Tags Management
2225
+ menu_tags: "Etiquetas",
2226
+ tags_title: "Administrar Etiquetas",
2227
+ tags_subtitle: "Administre las etiquetas utilizadas para etiquetar y organizar sus transacciones",
2228
+ panel_title_tags: "Etiquetas Activas",
2229
+ btn_new_tag: "Nueva Etiqueta",
2230
+ label_tag_name: "Nombre de la Etiqueta",
2231
+ placeholder_tag_name: "Ej: trabajo, viaje, reembolso",
2232
+ empty_tags_message: "No hay etiquetas registradas.",
2233
+ btn_save: "Guardar",
2234
+ btn_cancel: "Cancelar",
2235
+ toast_success_tag_created: '¡Etiqueta "{name}" creada con éxito!',
2236
+ toast_success_tag_deleted: '¡Etiqueta "{name}" eliminada con éxito!',
2237
+ confirm_delete_tag: '¿Realmente deseja eliminar la etiqueta "{name}"?\n(Esta acción eliminará la etiqueta de todas las transacciones vinculadas)'
2238
+ }
2239
+ };
2240
+
2241
+ var currentLocale = 'en'; // English as default
2242
+
2243
+ // Helper to translate in JS
2244
+ function t(key) {
2245
+ const tDict = TRANSLATIONS[currentLocale] || TRANSLATIONS['en'];
2246
+ return tDict[key] || key;
2247
+ }
2248
+
2249
+ async function checkLocale() {
2250
+ try {
2251
+ const res = await fetch('/api/status');
2252
+ if (res.ok) {
2253
+ const data = await res.json();
2254
+ if (data.locale && TRANSLATIONS[data.locale]) {
2255
+ currentLocale = data.locale;
2256
+ }
2257
+ }
2258
+ } catch (err) {
2259
+ console.error("Failed to read locale preferences:", err);
2260
+ }
2261
+ translatePage();
2262
+ }
2263
+
2264
+ function translatePage() {
2265
+ const tDict = TRANSLATIONS[currentLocale] || TRANSLATIONS['en'];
2266
+
2267
+ // 1. Static texts
2268
+ document.querySelectorAll('[data-i18n]').forEach(el => {
2269
+ const key = el.getAttribute('data-i18n');
2270
+ if (tDict[key]) {
2271
+ const icon = el.querySelector('i');
2272
+ if (icon) {
2273
+ const iconOuter = icon.outerHTML;
2274
+ el.innerHTML = iconOuter + ' ' + tDict[key];
2275
+ } else {
2276
+ el.textContent = tDict[key];
2277
+ }
2278
+ }
2279
+ });
2280
+
2281
+ // 2. Placeholders
2282
+ document.querySelectorAll('[data-i18n-placeholder]').forEach(el => {
2283
+ const key = el.getAttribute('data-i18n-placeholder');
2284
+ if (tDict[key]) {
2285
+ el.placeholder = tDict[key];
2286
+ }
2287
+ });
2288
+
2289
+ // 3. Tooltips
2290
+ document.querySelectorAll('[data-i18n-tooltip]').forEach(el => {
2291
+ const key = el.getAttribute('data-i18n-tooltip');
2292
+ if (tDict[key]) {
2293
+ el.setAttribute('data-tooltip', tDict[key]);
2294
+ }
2295
+ });
2296
+
2297
+ // 4. Document title translation
2298
+ if (tDict['overview_title'] && document.title.includes("Overview") || document.title.includes("Visão")) {
2299
+ // dynamic title update fallback if needed
2300
+ }
2301
+
2302
+ // 5. Translate select months
2303
+ const monthSelects = [
2304
+ document.getElementById('month-select'),
2305
+ document.getElementById('start-month-select')
2306
+ ];
2307
+ monthSelects.forEach(monthSelect => {
2308
+ if (monthSelect) {
2309
+ const monthKeys = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"];
2310
+ Array.from(monthSelect.options).forEach((opt, idx) => {
2311
+ const key = monthKeys[idx];
2312
+ if (tDict[key]) {
2313
+ opt.textContent = tDict[key];
2314
+ }
2315
+ });
2316
+ }
2317
+ });
2318
+
2319
+ // 6. Translate projection months select options (3, 6, 9, 12 months)
2320
+ const hmSelect = document.getElementById('heatmap-months-select');
2321
+ if (hmSelect) {
2322
+ Array.from(hmSelect.options).forEach(opt => {
2323
+ const val = opt.value;
2324
+ const key = `months_${val}`;
2325
+ if (tDict[key]) {
2326
+ opt.textContent = tDict[key];
2327
+ }
2328
+ });
2329
+ }
2330
+
2331
+ // Automatically initialize/refresh custom selects on all pages
2332
+ if (typeof initCustomSelects === 'function') {
2333
+ initCustomSelects();
2334
+ }
2335
+ }
2336
+
2337
+ // Custom Select Component implementation
2338
+ function initCustomSelects() {
2339
+ document.querySelectorAll('select.select-custom').forEach(select => {
2340
+ if (select.nextElementSibling && select.nextElementSibling.classList.contains('select-container-custom')) {
2341
+ // Already initialized, just sync selected value
2342
+ const container = select.nextElementSibling;
2343
+ const triggerSpan = container.querySelector('.select-trigger-custom span');
2344
+ const selectedOpt = select.options[select.selectedIndex];
2345
+ if (selectedOpt && triggerSpan) {
2346
+ triggerSpan.textContent = selectedOpt.textContent;
2347
+ }
2348
+ return;
2349
+ }
2350
+ select.style.display = 'none';
2351
+ const container = document.createElement('div');
2352
+ container.className = 'select-container-custom';
2353
+
2354
+ // Match specific element custom min-widths
2355
+ if (select.id === 'heatmap-months-select') {
2356
+ container.style.minWidth = '110px';
2357
+ } else if (select.id === 'year-select') {
2358
+ container.style.minWidth = '90px';
2359
+ } else if (select.id === 'filter-type') {
2360
+ container.style.minWidth = '130px';
2361
+ }
2362
+
2363
+ const trigger = document.createElement('div');
2364
+ trigger.className = 'select-trigger-custom';
2365
+ const triggerSpan = document.createElement('span');
2366
+ trigger.appendChild(triggerSpan);
2367
+ container.appendChild(trigger);
2368
+ const optionsContainer = document.createElement('div');
2369
+ optionsContainer.className = 'select-options-custom';
2370
+ container.appendChild(optionsContainer);
2371
+
2372
+ function syncSelected() {
2373
+ const selectedOpt = select.options[select.selectedIndex] || select.options[0];
2374
+ if (selectedOpt) {
2375
+ triggerSpan.textContent = selectedOpt.textContent;
2376
+ Array.from(optionsContainer.children).forEach(child => {
2377
+ if (child.getAttribute('data-value') === select.value) {
2378
+ child.classList.add('selected');
2379
+ } else {
2380
+ child.classList.remove('selected');
2381
+ }
2382
+ });
2383
+ }
2384
+ }
2385
+
2386
+ function populateOptions() {
2387
+ optionsContainer.innerHTML = '';
2388
+ Array.from(select.options).forEach(opt => {
2389
+ const optDiv = document.createElement('div');
2390
+ optDiv.className = 'select-option-custom';
2391
+ optDiv.textContent = opt.textContent;
2392
+ optDiv.setAttribute('data-value', opt.value);
2393
+ optDiv.addEventListener('click', (e) => {
2394
+ e.stopPropagation();
2395
+ select.value = opt.value;
2396
+ select.dispatchEvent(new Event('change'));
2397
+ syncSelected();
2398
+ container.classList.remove('open');
2399
+ });
2400
+ optionsContainer.appendChild(optDiv);
2401
+ });
2402
+ }
2403
+
2404
+ populateOptions();
2405
+ syncSelected();
2406
+
2407
+ trigger.addEventListener('click', (e) => {
2408
+ e.stopPropagation();
2409
+ const isOpen = container.classList.contains('open');
2410
+ document.querySelectorAll('.select-container-custom').forEach(el => {
2411
+ el.classList.remove('open');
2412
+ });
2413
+ if (!isOpen) {
2414
+ populateOptions();
2415
+ syncSelected();
2416
+ container.classList.add('open');
2417
+ setTimeout(() => {
2418
+ const selectedEl = optionsContainer.querySelector('.select-option-custom.selected');
2419
+ if (selectedEl) {
2420
+ const itemHeight = selectedEl.offsetHeight || 36;
2421
+ optionsContainer.scrollTop = Math.max(0, selectedEl.offsetTop - itemHeight);
2422
+ }
2423
+ }, 10);
2424
+ }
2425
+ });
2426
+
2427
+ select.parentNode.insertBefore(container, select.nextSibling);
2428
+ select.addEventListener('change', syncSelected);
2429
+
2430
+ // Watch for dynamic options updates
2431
+ const observer = new MutationObserver(() => {
2432
+ syncSelected();
2433
+ });
2434
+ observer.observe(select, { childList: true, subtree: true });
2435
+
2436
+ setTimeout(syncSelected, 200);
2437
+ setTimeout(syncSelected, 1000);
2438
+ });
2439
+
2440
+ // Global click listener to close options dropdowns when clicking outside
2441
+ if (!window.customSelectGlobalBound) {
2442
+ window.customSelectGlobalBound = true;
2443
+ document.addEventListener('click', () => {
2444
+ document.querySelectorAll('.select-container-custom').forEach(el => {
2445
+ el.classList.remove('open');
2446
+ });
2447
+ });
2448
+ }
2449
+ }
2450
+
2451
+ runInit();
2452
+
2453
+ // ADR-027 Live-update listener
2454
+ window.onAppDataChanged = function(entities) {
2455
+ var affected = entities.some(function(tag) {
2456
+ return ['transaction', 'category'].indexOf(tag) !== -1;
2457
+ });
2458
+ if (affected) {
2459
+ console.log("comparative refetching due to entity change:", entities);
2460
+ runInit();
2461
+ }
2462
+ };
2463
+
2464
+ </script>