@hisaabo/cli 0.5.0 → 0.7.5

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 (74) hide show
  1. package/.turbo/turbo-typecheck.log +1 -1
  2. package/dist/bin/{audit-trail-5LOCJ7XZ.js → audit-trail-DLSSSM4T.js} +3 -3
  3. package/dist/bin/{categories-64WWZTND.js → categories-63QR6WCV.js} +2 -2
  4. package/dist/bin/{check-slug-FLHHUDYS.js → check-slug-NXO55WKH.js} +2 -2
  5. package/dist/bin/{chunk-FIMJZAS4.js → chunk-7MJDOL6B.js} +18 -1
  6. package/dist/bin/{chunk-4MEL44QX.js → chunk-M42SETRZ.js} +243 -0
  7. package/dist/bin/{chunk-T63VQXNM.js → chunk-ZPYC767N.js} +1 -0
  8. package/dist/bin/{client-5NZ23GML.js → client-T32CIZA3.js} +1 -1
  9. package/dist/bin/{collection-efficiency-U56XNVEE.js → collection-efficiency-T6PWNTZO.js} +3 -3
  10. package/dist/bin/{config-335MN4I7.js → config-V4QFCONN.js} +3 -1
  11. package/dist/bin/{create-RPDEORDD.js → create-NUKHDWLK.js} +2 -2
  12. package/dist/bin/{default-account-AE6EXZZR.js → default-account-JWFPHMRF.js} +2 -2
  13. package/dist/bin/{expenses-5N2QSG54.js → expenses-2UWUZVLI.js} +3 -3
  14. package/dist/bin/{export-QICOQK34.js → export-XSX7WQH7.js} +2 -2
  15. package/dist/bin/{factory-KOCW2AQM.js → factory-BWOKRIP4.js} +3 -3
  16. package/dist/bin/{get-A43QCI2S.js → get-CHNTG3IM.js} +2 -2
  17. package/dist/bin/{get-GWH6S5SJ.js → get-ZSZ6SL3N.js} +3 -3
  18. package/dist/bin/hisaabo.js +901 -59
  19. package/dist/bin/{invitations-P3EEN5WI.js → invitations-H2SL3XAD.js} +2 -2
  20. package/dist/bin/{invite-T3CKX53E.js → invite-EW73UIBE.js} +2 -2
  21. package/dist/bin/{invoice-breakdown-FN5BEFJD.js → invoice-breakdown-XP4QATCF.js} +3 -3
  22. package/dist/bin/{items-2OOCQKVF.js → items-DPD6EFTP.js} +3 -3
  23. package/dist/bin/{items-toggle-SKZWCGJH.js → items-toggle-R4OPSE4W.js} +2 -2
  24. package/dist/bin/{list-T74SN6IR.js → list-KLEHBMQ2.js} +2 -2
  25. package/dist/bin/{list-A2RKI3ZG.js → list-PKHBE475.js} +3 -3
  26. package/dist/bin/{list-NRMBMKMI.js → list-UR7OOJVF.js} +2 -2
  27. package/dist/bin/{members-W2GW3ODT.js → members-XA3TF4IQ.js} +3 -3
  28. package/dist/bin/{monthly-comparison-T34ZFOHL.js → monthly-comparison-OLVS5HEY.js} +3 -3
  29. package/dist/bin/{order-cancel-TI27JYYD.js → order-cancel-MXMJFFRR.js} +2 -2
  30. package/dist/bin/{order-confirm-VMRAMNTD.js → order-confirm-IXU45Q4L.js} +2 -2
  31. package/dist/bin/{order-get-C2RBUR4O.js → order-get-RDXMHLJ7.js} +3 -3
  32. package/dist/bin/{order-update-RE3HATNF.js → order-update-KGIPBEJX.js} +3 -3
  33. package/dist/bin/{payment-modes-WOOT22I7.js → payment-modes-CZL35SVS.js} +3 -3
  34. package/dist/bin/{profit-loss-T4RESJ32.js → profit-loss-M332OSC5.js} +3 -3
  35. package/dist/bin/{receivables-aging-6XMENEWS.js → receivables-aging-OXRHGMBF.js} +3 -3
  36. package/dist/bin/{remove-6QZI4JCY.js → remove-I5HD2Y4K.js} +2 -2
  37. package/dist/bin/{revoke-AVEMPAC7.js → revoke-MFLWGCMP.js} +2 -2
  38. package/dist/bin/{revoke-YUCFZFNR.js → revoke-OC6AOMIZ.js} +2 -2
  39. package/dist/bin/{revoke-all-LFW5WBHO.js → revoke-all-FSAPBB3P.js} +2 -2
  40. package/dist/bin/{revoke-invitation-DTGQRJR4.js → revoke-invitation-JXDPXTOW.js} +2 -2
  41. package/dist/bin/{sales-trend-ZYBRUDUU.js → sales-trend-KK63WNDL.js} +3 -3
  42. package/dist/bin/{sequence-FPOJTI2P.js → sequence-IQ4HUJ3W.js} +2 -2
  43. package/dist/bin/{store-IOB4Y67C.js → store-6QT6HKG2.js} +3 -3
  44. package/dist/bin/{summary-5KYBA4ZO.js → summary-3FTF5B4A.js} +3 -3
  45. package/dist/bin/{top-customers-WSQ2UEJL.js → top-customers-HNYGXBQZ.js} +3 -3
  46. package/dist/bin/{top-items-RWQPDGLN.js → top-items-JUDG3BVW.js} +3 -3
  47. package/dist/bin/{top-outstanding-QAMO2E7Y.js → top-outstanding-WK26ZNE5.js} +3 -3
  48. package/dist/bin/{unpaid-invoices-WB3TK5B4.js → unpaid-invoices-RYFIIIK7.js} +3 -3
  49. package/dist/bin/{untracked-H733MYJL.js → untracked-FAFS3KCK.js} +3 -3
  50. package/dist/bin/{update-TLBUIC5J.js → update-5YSPXIWO.js} +3 -3
  51. package/dist/bin/{update-H6LPO2Z4.js → update-I46XLU77.js} +2 -2
  52. package/dist/bin/{update-JU2X3XU5.js → update-NAW2JWZS.js} +3 -3
  53. package/dist/bin/{update-role-QST7BVFX.js → update-role-5GV42MSN.js} +2 -2
  54. package/dist/bin/{update-settings-Q2EGRLKZ.js → update-settings-KYSQDIEO.js} +2 -2
  55. package/package.json +1 -1
  56. package/src/bin/hisaabo.ts +10 -0
  57. package/src/bin/registrars/bank-recon.ts +34 -0
  58. package/src/bin/registrars/einvoice.ts +46 -0
  59. package/src/bin/registrars/ewb.ts +37 -0
  60. package/src/bin/registrars/gst.ts +17 -1
  61. package/src/bin/registrars/itc.ts +56 -0
  62. package/src/bin/registrars/journal.ts +47 -0
  63. package/src/bin/registrars/report.ts +44 -0
  64. package/src/client.ts +269 -1
  65. package/src/commands/bank-recon/index.ts +127 -0
  66. package/src/commands/einvoice/index.ts +109 -0
  67. package/src/commands/ewb/index.ts +108 -0
  68. package/src/commands/gst/index.ts +79 -1
  69. package/src/commands/invoice/get.ts +9 -1
  70. package/src/commands/itc/index.ts +163 -0
  71. package/src/commands/journal/index.ts +156 -0
  72. package/src/commands/report/index.ts +171 -0
  73. package/src/config.ts +24 -0
  74. package/src/format.ts +1 -0
@@ -0,0 +1,156 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import { fatalError, outputJSON, EXIT } from "../../output.js";
4
+ import { formatDate } from "../../format.js";
5
+
6
+ interface JournalOpts {
7
+ json?: boolean;
8
+ page?: number;
9
+ limit?: number;
10
+ from?: string;
11
+ to?: string;
12
+ }
13
+
14
+ function handleError(e: unknown): never {
15
+ if (e instanceof HisaaboApiError) {
16
+ const err = e.hisaaboError;
17
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
18
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
19
+ }
20
+ fatalError(String(e instanceof Error ? e.message : e));
21
+ }
22
+
23
+ export async function journalListCommand(opts: JournalOpts): Promise<void> {
24
+ const cfg = requireAuth();
25
+ const client = new HisaaboClient(cfg);
26
+
27
+ try {
28
+ const result = await client.journal.list({
29
+ page: opts.page ?? 1,
30
+ limit: opts.limit ?? 25,
31
+ fromDate: opts.from,
32
+ toDate: opts.to,
33
+ });
34
+
35
+ if (opts.json) {
36
+ outputJSON(result);
37
+ return;
38
+ }
39
+
40
+ const entries = Array.isArray(result) ? result
41
+ : Array.isArray(result?.data) ? result.data
42
+ : [];
43
+
44
+ console.log(`\n Journal Entries\n`);
45
+ console.log(` ${"═".repeat(70)}\n`);
46
+
47
+ if (entries.length === 0) {
48
+ console.log(" No journal entries found.\n");
49
+ return;
50
+ }
51
+
52
+ for (const entry of entries as Array<Record<string, unknown>>) {
53
+ const date = formatDate(String(entry["date"] ?? entry["journalDate"] ?? ""));
54
+ const number = String(entry["number"] ?? entry["voucherNumber"] ?? "-");
55
+ const narration = String(entry["narration"] ?? entry["description"] ?? "").slice(0, 40);
56
+ const status = String(entry["status"] ?? "").padEnd(8);
57
+ console.log(` ${date.padEnd(13)} ${number.padEnd(14)} ${status} ${narration}`);
58
+ }
59
+ console.log();
60
+
61
+ } catch (e) {
62
+ handleError(e);
63
+ }
64
+ }
65
+
66
+ export async function journalGetCommand(id: string, opts: { json?: boolean }): Promise<void> {
67
+ const cfg = requireAuth();
68
+ const client = new HisaaboClient(cfg);
69
+
70
+ try {
71
+ const result = await client.journal.getById(id);
72
+
73
+ if (opts.json) {
74
+ outputJSON(result);
75
+ return;
76
+ }
77
+
78
+ const r = result as Record<string, unknown>;
79
+ console.log(`\n Journal Entry — ${String(r["number"] ?? r["voucherNumber"] ?? id)}\n`);
80
+ console.log(` ${"═".repeat(60)}\n`);
81
+ console.log(` Date: ${formatDate(String(r["date"] ?? r["journalDate"] ?? ""))}`);
82
+ console.log(` Narration: ${String(r["narration"] ?? r["description"] ?? "-")}`);
83
+ console.log(` Status: ${String(r["status"] ?? "-")}`);
84
+ console.log();
85
+
86
+ const lines = r["lines"] ?? r["entries"] ?? r["lineItems"];
87
+ if (lines && Array.isArray(lines)) {
88
+ console.log(" Lines:\n");
89
+ for (const line of lines as Array<Record<string, unknown>>) {
90
+ const account = String(line["accountName"] ?? line["account"] ?? "-").padEnd(28);
91
+ const debit = String(line["debit"] ?? "0");
92
+ const credit = String(line["credit"] ?? "0");
93
+ console.log(` ${account} Dr: ${debit.padStart(12)} Cr: ${credit.padStart(12)}`);
94
+ }
95
+ }
96
+ console.log();
97
+
98
+ } catch (e) {
99
+ handleError(e);
100
+ }
101
+ }
102
+
103
+ export async function journalVoidCommand(id: string, opts: { json?: boolean }): Promise<void> {
104
+ const cfg = requireAuth();
105
+ const client = new HisaaboClient(cfg);
106
+
107
+ try {
108
+ const result = await client.journal.void(id);
109
+
110
+ if (opts.json) {
111
+ outputJSON(result);
112
+ return;
113
+ }
114
+
115
+ console.log(` Journal entry ${id} voided.\n`);
116
+
117
+ } catch (e) {
118
+ handleError(e);
119
+ }
120
+ }
121
+
122
+ export async function journalTemplatesCommand(opts: { json?: boolean }): Promise<void> {
123
+ const cfg = requireAuth();
124
+ const client = new HisaaboClient(cfg);
125
+
126
+ try {
127
+ const result = await client.journal.templateList();
128
+
129
+ if (opts.json) {
130
+ outputJSON(result);
131
+ return;
132
+ }
133
+
134
+ const templates = Array.isArray(result) ? result
135
+ : Array.isArray(result?.data) ? result.data
136
+ : [];
137
+
138
+ console.log(`\n Journal Templates\n`);
139
+ console.log(` ${"═".repeat(50)}\n`);
140
+
141
+ if (templates.length === 0) {
142
+ console.log(" No templates found.\n");
143
+ return;
144
+ }
145
+
146
+ for (const t of templates as Array<Record<string, unknown>>) {
147
+ const id = String(t["id"] ?? "-").slice(0, 8);
148
+ const name = String(t["name"] ?? "-").padEnd(30);
149
+ console.log(` ${id} ${name}`);
150
+ }
151
+ console.log();
152
+
153
+ } catch (e) {
154
+ handleError(e);
155
+ }
156
+ }
@@ -522,6 +522,177 @@ export async function reportCashFlowCommand(opts: { json?: boolean }): Promise<v
522
522
  }
523
523
  }
524
524
 
525
+ // ── Trial Balance ──────────────────────────────────────────────────────────
526
+
527
+ export async function reportTrialBalanceCommand(opts: ReportOpts): Promise<void> {
528
+ const cfg = requireAuth();
529
+ const client = new HisaaboClient(cfg);
530
+ const { from: _from, to } = resolveRange(opts);
531
+
532
+ try {
533
+ const result = await client.reports.trialBalance({ asOfDate: to });
534
+
535
+ if (opts.json) {
536
+ outputJSON(result);
537
+ return;
538
+ }
539
+
540
+ console.log(`\n Trial Balance as of ${to}\n`);
541
+ console.log(` ${"═".repeat(70)}\n`);
542
+
543
+ const rows = Array.isArray(result?.accounts) ? result.accounts
544
+ : Array.isArray(result?.rows) ? result.rows
545
+ : Array.isArray(result) ? result
546
+ : [];
547
+
548
+ for (const row of rows as Array<Record<string, unknown>>) {
549
+ const name = String(row["accountName"] ?? row["name"] ?? "-").padEnd(30);
550
+ const debit = String(row["debit"] ?? "0");
551
+ const credit = String(row["credit"] ?? "0");
552
+ const dr = parseFloat(debit) !== 0 ? formatAmount(debit) : "-";
553
+ const cr = parseFloat(credit) !== 0 ? formatAmount(credit) : "-";
554
+ console.log(` ${name} ${dr.padStart(14)} ${cr.padStart(14)}`);
555
+ }
556
+ console.log();
557
+
558
+ } catch (e) {
559
+ if (e instanceof HisaaboApiError) {
560
+ const err = e.hisaaboError;
561
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
562
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
563
+ }
564
+ fatalError(String(e instanceof Error ? e.message : e));
565
+ }
566
+ }
567
+
568
+ // ── Balance Sheet ──────────────────────────────────────────────────────────
569
+
570
+ export async function reportBalanceSheetCommand(opts: ReportOpts): Promise<void> {
571
+ const cfg = requireAuth();
572
+ const client = new HisaaboClient(cfg);
573
+ const { to } = resolveRange(opts);
574
+
575
+ try {
576
+ const result = await client.reports.balanceSheet({ asOfDate: to });
577
+
578
+ if (opts.json) {
579
+ outputJSON(result);
580
+ return;
581
+ }
582
+
583
+ const r = result as Record<string, unknown>;
584
+ console.log(`\n Balance Sheet as of ${to}\n`);
585
+ console.log(` ${"═".repeat(60)}\n`);
586
+
587
+ const assets = String(r["totalAssets"] ?? r["assets"] ?? "0");
588
+ const liabilities = String(r["totalLiabilities"] ?? r["liabilities"] ?? "0");
589
+ const equity = String(r["totalEquity"] ?? r["equity"] ?? "0");
590
+
591
+ console.log(` Total Assets: ${formatAmount(assets).padStart(14)}`);
592
+ console.log(` Total Liabilities: ${formatAmount(liabilities).padStart(14)}`);
593
+ console.log(` Total Equity: ${formatAmount(equity).padStart(14)}`);
594
+ console.log();
595
+ console.log(" Use --json for full balance sheet breakdown.\n");
596
+
597
+ } catch (e) {
598
+ if (e instanceof HisaaboApiError) {
599
+ const err = e.hisaaboError;
600
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
601
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
602
+ }
603
+ fatalError(String(e instanceof Error ? e.message : e));
604
+ }
605
+ }
606
+
607
+ // ── Cash Flow Statement ────────────────────────────────────────────────────
608
+
609
+ export async function reportCashFlowStatementCommand(opts: ReportOpts): Promise<void> {
610
+ const cfg = requireAuth();
611
+ const client = new HisaaboClient(cfg);
612
+ const { from, to } = resolveRange(opts);
613
+
614
+ try {
615
+ const result = await client.reports.cashFlowStatement({ fromDate: from, toDate: to });
616
+
617
+ if (opts.json) {
618
+ outputJSON(result);
619
+ return;
620
+ }
621
+
622
+ const r = result as Record<string, unknown>;
623
+ console.log(`\n Cash Flow Statement ${from} → ${to}\n`);
624
+ console.log(` ${"═".repeat(60)}\n`);
625
+
626
+ const operating = String(r["operatingActivities"] ?? r["operations"] ?? "0");
627
+ const investing = String(r["investingActivities"] ?? r["investing"] ?? "0");
628
+ const financing = String(r["financingActivities"] ?? r["financing"] ?? "0");
629
+ const net = String(r["netCashFlow"] ?? r["net"] ?? "0");
630
+
631
+ console.log(` Operating Activities: ${formatAmount(operating).padStart(14)}`);
632
+ console.log(` Investing Activities: ${formatAmount(investing).padStart(14)}`);
633
+ console.log(` Financing Activities: ${formatAmount(financing).padStart(14)}`);
634
+ console.log(` Net Cash Flow: ${formatAmount(net).padStart(14)}`);
635
+ console.log();
636
+
637
+ } catch (e) {
638
+ if (e instanceof HisaaboApiError) {
639
+ const err = e.hisaaboError;
640
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
641
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
642
+ }
643
+ fatalError(String(e instanceof Error ? e.message : e));
644
+ }
645
+ }
646
+
647
+ // ── General Ledger ─────────────────────────────────────────────────────────
648
+
649
+ export async function reportGeneralLedgerCommand(accountId: string, opts: ReportOpts): Promise<void> {
650
+ const cfg = requireAuth();
651
+ const client = new HisaaboClient(cfg);
652
+ const { from, to } = resolveRange(opts);
653
+
654
+ try {
655
+ const result = await client.reports.generalLedger({ accountId, fromDate: from, toDate: to });
656
+
657
+ if (opts.json) {
658
+ outputJSON(result);
659
+ return;
660
+ }
661
+
662
+ const r = result as Record<string, unknown>;
663
+ const accountName = String(r["accountName"] ?? r["account"] ?? accountId);
664
+ console.log(`\n General Ledger — ${accountName} ${from} → ${to}\n`);
665
+ console.log(` ${"═".repeat(75)}\n`);
666
+
667
+ const opening = String(r["openingBalance"] ?? "0");
668
+ console.log(` Opening Balance: ${formatAmount(opening).padStart(14)}\n`);
669
+
670
+ const entries = Array.isArray(r["entries"]) ? r["entries"]
671
+ : Array.isArray(r["rows"]) ? r["rows"]
672
+ : [];
673
+
674
+ for (const entry of entries as Array<Record<string, unknown>>) {
675
+ const date = formatDate(String(entry["date"] ?? "")).padEnd(13);
676
+ const narration = String(entry["narration"] ?? entry["description"] ?? "-").slice(0, 25).padEnd(25);
677
+ const debit = parseFloat(String(entry["debit"] ?? "0")) !== 0 ? formatAmount(String(entry["debit"])) : "-";
678
+ const credit = parseFloat(String(entry["credit"] ?? "0")) !== 0 ? formatAmount(String(entry["credit"])) : "-";
679
+ const balance = formatAmount(String(entry["balance"] ?? "0"));
680
+ console.log(` ${date} ${narration} ${debit.padStart(12)} ${credit.padStart(12)} ${balance.padStart(14)}`);
681
+ }
682
+
683
+ const closing = String(r["closingBalance"] ?? r["balance"] ?? "0");
684
+ console.log(`\n Closing Balance: ${formatAmount(closing).padStart(14)}\n`);
685
+
686
+ } catch (e) {
687
+ if (e instanceof HisaaboApiError) {
688
+ const err = e.hisaaboError;
689
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
690
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
691
+ }
692
+ fatalError(String(e instanceof Error ? e.message : e));
693
+ }
694
+ }
695
+
525
696
  // ── Collection Efficiency ──────────────────────────────────────────────────
526
697
 
527
698
  export async function reportCollectionEfficiencyCommand(opts: ReportOpts): Promise<void> {
package/src/config.ts CHANGED
@@ -2,6 +2,7 @@ import Conf from "conf";
2
2
  import { hostname, userInfo } from "os";
3
3
  import { createHash } from "crypto";
4
4
  import { fatalError, warn } from "./output.js";
5
+ import type { HisaaboClient } from "./client.js";
5
6
 
6
7
  interface ConfigSchema {
7
8
  apiUrl: string;
@@ -94,3 +95,26 @@ export function requireAuth(): ConfigSchema {
94
95
  export function getConfigPath(): string {
95
96
  return conf.path;
96
97
  }
98
+
99
+ /**
100
+ * Check if the system is under maintenance and warn the user.
101
+ * Called after requireAuth() in command handlers.
102
+ * Non-fatal — prints warning and continues (the API will block tenant ops anyway).
103
+ */
104
+ export async function checkMaintenance(client: HisaaboClient): Promise<void> {
105
+ try {
106
+ const status = await client.system.maintenanceStatus();
107
+ if (status.enabled) {
108
+ warn(`System is under maintenance: ${status.message || "Please try again later."}`);
109
+ if (status.endsAt) {
110
+ const end = new Date(status.endsAt).toLocaleString();
111
+ warn(`Estimated end: ${end}`);
112
+ }
113
+ } else if (status.startsAt && new Date(status.startsAt) > new Date()) {
114
+ const start = new Date(status.startsAt).toLocaleString();
115
+ warn(`Scheduled maintenance: ${start}${status.message ? ` — ${status.message}` : ""}`);
116
+ }
117
+ } catch {
118
+ // Silently ignore — don't block CLI startup if status check fails
119
+ }
120
+ }
package/src/format.ts CHANGED
@@ -82,6 +82,7 @@ const STATUS_CONFIG: Record<string, { label: string; color: (s: string) => strin
82
82
  partial: { label: "PARTIAL", color: (s) => chalk.yellow(s) },
83
83
  overdue: { label: "OVERDUE", color: (s) => chalk.red(s) },
84
84
  cancelled: { label: "CANCEL", color: (s) => chalk.dim(chalk.strikethrough(s)) },
85
+ adjusted: { label: "ADJUST", color: (s) => chalk.magenta(s) },
85
86
  unfulfilled: { label: "UNFUL", color: (s) => chalk.blue(s) },
86
87
  pending: { label: "PEND", color: (s) => chalk.yellow(s) },
87
88
  confirmed: { label: "CONF", color: (s) => chalk.blue(s) },