@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,127 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import { fatalError, outputJSON, EXIT } from "../../output.js";
4
+ import { formatAmount, formatDate } from "../../format.js";
5
+
6
+ function handleError(e: unknown): never {
7
+ if (e instanceof HisaaboApiError) {
8
+ const err = e.hisaaboError;
9
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
10
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
11
+ }
12
+ fatalError(String(e instanceof Error ? e.message : e));
13
+ }
14
+
15
+ export async function bankReconImportsCommand(opts: { json?: boolean }): Promise<void> {
16
+ const cfg = requireAuth();
17
+ const client = new HisaaboClient(cfg);
18
+
19
+ try {
20
+ const result = await client.bankRecon.importList();
21
+
22
+ if (opts.json) {
23
+ outputJSON(result);
24
+ return;
25
+ }
26
+
27
+ const imports = Array.isArray(result) ? result
28
+ : Array.isArray(result?.data) ? result.data
29
+ : [];
30
+
31
+ console.log("\n Bank Reconciliation Imports\n");
32
+ console.log(` ${"═".repeat(65)}\n`);
33
+
34
+ if (imports.length === 0) {
35
+ console.log(" No imports found.\n");
36
+ return;
37
+ }
38
+
39
+ for (const imp of imports as Array<Record<string, unknown>>) {
40
+ const id = String(imp["id"] ?? "-").slice(0, 8);
41
+ const date = formatDate(String(imp["createdAt"] ?? imp["importDate"] ?? ""));
42
+ const account = String(imp["accountName"] ?? imp["bankAccount"] ?? "-").padEnd(20);
43
+ const lines = String(imp["totalLines"] ?? imp["lineCount"] ?? "-").padStart(6);
44
+ const matched = String(imp["matchedLines"] ?? imp["matched"] ?? "-").padStart(8);
45
+ const status = String(imp["status"] ?? "-").padEnd(10);
46
+ console.log(` ${id} ${date.padEnd(13)} ${account} Lines:${lines} Matched:${matched} ${status}`);
47
+ }
48
+ console.log();
49
+
50
+ } catch (e) {
51
+ handleError(e);
52
+ }
53
+ }
54
+
55
+ export async function bankReconSummaryCommand(importId: string, opts: { json?: boolean }): Promise<void> {
56
+ const cfg = requireAuth();
57
+ const client = new HisaaboClient(cfg);
58
+
59
+ try {
60
+ const result = await client.bankRecon.summary(importId);
61
+
62
+ if (opts.json) {
63
+ outputJSON(result);
64
+ return;
65
+ }
66
+
67
+ const r = result as Record<string, unknown>;
68
+ console.log(`\n Bank Recon Summary — ${importId}\n`);
69
+ console.log(` ${"═".repeat(55)}\n`);
70
+
71
+ const total = String(r["totalLines"] ?? r["total"] ?? "0");
72
+ const matched = String(r["matchedLines"] ?? r["matched"] ?? "0");
73
+ const unmatched = String(r["unmatchedLines"] ?? r["unmatched"] ?? "0");
74
+ const ignored = String(r["ignoredLines"] ?? r["ignored"] ?? "0");
75
+ const openingBalance = String(r["openingBalance"] ?? "0");
76
+ const closingBalance = String(r["closingBalance"] ?? "0");
77
+
78
+ console.log(` Total Lines: ${total.padStart(8)}`);
79
+ console.log(` Matched: ${matched.padStart(8)}`);
80
+ console.log(` Unmatched: ${unmatched.padStart(8)}`);
81
+ console.log(` Ignored: ${ignored.padStart(8)}`);
82
+ console.log(` Opening Balance: ${formatAmount(openingBalance).padStart(14)}`);
83
+ console.log(` Closing Balance: ${formatAmount(closingBalance).padStart(14)}`);
84
+ console.log();
85
+
86
+ } catch (e) {
87
+ handleError(e);
88
+ }
89
+ }
90
+
91
+ export async function bankReconRulesCommand(opts: { json?: boolean }): Promise<void> {
92
+ const cfg = requireAuth();
93
+ const client = new HisaaboClient(cfg);
94
+
95
+ try {
96
+ const result = await client.bankRecon.ruleList();
97
+
98
+ if (opts.json) {
99
+ outputJSON(result);
100
+ return;
101
+ }
102
+
103
+ const rules = Array.isArray(result) ? result
104
+ : Array.isArray(result?.data) ? result.data
105
+ : [];
106
+
107
+ console.log("\n Bank Recon Rules\n");
108
+ console.log(` ${"═".repeat(60)}\n`);
109
+
110
+ if (rules.length === 0) {
111
+ console.log(" No rules configured.\n");
112
+ return;
113
+ }
114
+
115
+ for (const rule of rules as Array<Record<string, unknown>>) {
116
+ const id = String(rule["id"] ?? "-").slice(0, 8);
117
+ const name = String(rule["name"] ?? "-").padEnd(25);
118
+ const condition = String(rule["condition"] ?? rule["matchPattern"] ?? "-").padEnd(20);
119
+ const action = String(rule["action"] ?? "-").padEnd(12);
120
+ console.log(` ${id} ${name} ${condition} ${action}`);
121
+ }
122
+ console.log();
123
+
124
+ } catch (e) {
125
+ handleError(e);
126
+ }
127
+ }
@@ -0,0 +1,109 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import { fatalError, outputJSON, EXIT } from "../../output.js";
4
+
5
+ function handleError(e: unknown): never {
6
+ if (e instanceof HisaaboApiError) {
7
+ const err = e.hisaaboError;
8
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
9
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
10
+ }
11
+ fatalError(String(e instanceof Error ? e.message : e));
12
+ }
13
+
14
+ export async function eInvoiceDashboardCommand(opts: { json?: boolean; from?: string; to?: string }): Promise<void> {
15
+ const cfg = requireAuth();
16
+ const client = new HisaaboClient(cfg);
17
+
18
+ try {
19
+ const result = await client.eInvoice.dashboard({ fromDate: opts.from, toDate: opts.to });
20
+
21
+ if (opts.json) {
22
+ outputJSON(result);
23
+ return;
24
+ }
25
+
26
+ const r = result as Record<string, unknown>;
27
+ console.log("\n E-Invoice Dashboard\n");
28
+ console.log(` ${"═".repeat(50)}\n`);
29
+
30
+ const generated = String(r["totalGenerated"] ?? r["generated"] ?? "0");
31
+ const cancelled = String(r["totalCancelled"] ?? r["cancelled"] ?? "0");
32
+ const failed = String(r["totalFailed"] ?? r["failed"] ?? "0");
33
+ const pending = String(r["pending"] ?? "0");
34
+
35
+ console.log(` Generated: ${generated.padStart(8)}`);
36
+ console.log(` Cancelled: ${cancelled.padStart(8)}`);
37
+ console.log(` Failed: ${failed.padStart(8)}`);
38
+ console.log(` Pending: ${pending.padStart(8)}`);
39
+ console.log();
40
+
41
+ } catch (e) {
42
+ handleError(e);
43
+ }
44
+ }
45
+
46
+ export async function eInvoiceGenerateCommand(invoiceId: string, opts: { json?: boolean }): Promise<void> {
47
+ const cfg = requireAuth();
48
+ const client = new HisaaboClient(cfg);
49
+
50
+ try {
51
+ const result = await client.eInvoice.generate({ invoiceId });
52
+
53
+ if (opts.json) {
54
+ outputJSON(result);
55
+ return;
56
+ }
57
+
58
+ const r = result as Record<string, unknown>;
59
+ const irn = String(r["irn"] ?? r["invoiceReferenceNumber"] ?? "-");
60
+ const ackNo = String(r["ackNo"] ?? r["acknowledgementNumber"] ?? "-");
61
+ console.log(` E-Invoice generated.\n`);
62
+ console.log(` IRN: ${irn}`);
63
+ console.log(` ACK: ${ackNo}`);
64
+ console.log();
65
+
66
+ } catch (e) {
67
+ handleError(e);
68
+ }
69
+ }
70
+
71
+ export async function eInvoiceCancelCommand(invoiceId: string, opts: { json?: boolean; reason?: string }): Promise<void> {
72
+ const cfg = requireAuth();
73
+ const client = new HisaaboClient(cfg);
74
+
75
+ try {
76
+ const result = await client.eInvoice.cancel({ invoiceId, cancelReason: opts.reason ?? "1" });
77
+
78
+ if (opts.json) {
79
+ outputJSON(result);
80
+ return;
81
+ }
82
+
83
+ console.log(` E-Invoice for ${invoiceId} cancelled.\n`);
84
+
85
+ } catch (e) {
86
+ handleError(e);
87
+ }
88
+ }
89
+
90
+ export async function eInvoiceRetryCommand(invoiceId: string, opts: { json?: boolean }): Promise<void> {
91
+ const cfg = requireAuth();
92
+ const client = new HisaaboClient(cfg);
93
+
94
+ try {
95
+ const result = await client.eInvoice.retryFailed({ invoiceId });
96
+
97
+ if (opts.json) {
98
+ outputJSON(result);
99
+ return;
100
+ }
101
+
102
+ const r = result as Record<string, unknown>;
103
+ const status = String(r["status"] ?? "queued");
104
+ console.log(` Retry queued for invoice ${invoiceId}. Status: ${status}\n`);
105
+
106
+ } catch (e) {
107
+ handleError(e);
108
+ }
109
+ }
@@ -0,0 +1,108 @@
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
+ function handleError(e: unknown): never {
7
+ if (e instanceof HisaaboApiError) {
8
+ const err = e.hisaaboError;
9
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
10
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
11
+ }
12
+ fatalError(String(e instanceof Error ? e.message : e));
13
+ }
14
+
15
+ export async function ewbDashboardCommand(opts: { json?: boolean; from?: string; to?: string }): Promise<void> {
16
+ const cfg = requireAuth();
17
+ const client = new HisaaboClient(cfg);
18
+
19
+ try {
20
+ const result = await client.ewayBill.dashboard({ fromDate: opts.from, toDate: opts.to });
21
+
22
+ if (opts.json) {
23
+ outputJSON(result);
24
+ return;
25
+ }
26
+
27
+ const r = result as Record<string, unknown>;
28
+ console.log("\n E-Way Bill Dashboard\n");
29
+ console.log(` ${"═".repeat(50)}\n`);
30
+
31
+ const generated = String(r["totalGenerated"] ?? r["generated"] ?? "0");
32
+ const cancelled = String(r["totalCancelled"] ?? r["cancelled"] ?? "0");
33
+ const expired = String(r["totalExpired"] ?? r["expired"] ?? "0");
34
+ const active = String(r["active"] ?? "0");
35
+
36
+ console.log(` Generated: ${generated.padStart(8)}`);
37
+ console.log(` Active: ${active.padStart(8)}`);
38
+ console.log(` Cancelled: ${cancelled.padStart(8)}`);
39
+ console.log(` Expired: ${expired.padStart(8)}`);
40
+ console.log();
41
+
42
+ } catch (e) {
43
+ handleError(e);
44
+ }
45
+ }
46
+
47
+ export async function ewbGenerateCommand(invoiceId: string, opts: { json?: boolean }): Promise<void> {
48
+ const cfg = requireAuth();
49
+ const client = new HisaaboClient(cfg);
50
+
51
+ try {
52
+ const result = await client.ewayBill.generate({ invoiceId });
53
+
54
+ if (opts.json) {
55
+ outputJSON(result);
56
+ return;
57
+ }
58
+
59
+ const r = result as Record<string, unknown>;
60
+ const ewbNo = String(r["eWayBillNo"] ?? r["ewbNumber"] ?? r["ewbNo"] ?? "-");
61
+ const validUpto = String(r["validUpto"] ?? r["validTill"] ?? "-");
62
+ console.log(` E-Way Bill generated.\n`);
63
+ console.log(` EWB No: ${ewbNo}`);
64
+ console.log(` Valid Upto: ${validUpto}`);
65
+ console.log();
66
+
67
+ } catch (e) {
68
+ handleError(e);
69
+ }
70
+ }
71
+
72
+ export async function ewbExpiringCommand(opts: { json?: boolean; days?: number }): Promise<void> {
73
+ const cfg = requireAuth();
74
+ const client = new HisaaboClient(cfg);
75
+
76
+ try {
77
+ const result = await client.ewayBill.expiringList({ withinDays: opts.days ?? 3 });
78
+
79
+ if (opts.json) {
80
+ outputJSON(result);
81
+ return;
82
+ }
83
+
84
+ const bills = Array.isArray(result) ? result
85
+ : Array.isArray(result?.data) ? result.data
86
+ : [];
87
+
88
+ console.log(`\n Expiring E-Way Bills (within ${opts.days ?? 3} days)\n`);
89
+ console.log(` ${"═".repeat(65)}\n`);
90
+
91
+ if (bills.length === 0) {
92
+ console.log(" No expiring e-way bills.\n");
93
+ return;
94
+ }
95
+
96
+ for (const bill of bills as Array<Record<string, unknown>>) {
97
+ const ewbNo = String(bill["eWayBillNo"] ?? bill["ewbNumber"] ?? "-").padEnd(14);
98
+ const invoiceNo = String(bill["invoiceNumber"] ?? bill["invoice"] ?? "-").padEnd(14);
99
+ const party = String(bill["partyName"] ?? bill["party"] ?? "-").padEnd(22);
100
+ const validUpto = formatDate(String(bill["validUpto"] ?? bill["validTill"] ?? ""));
101
+ console.log(` ${ewbNo} ${invoiceNo} ${party} Expires: ${validUpto}`);
102
+ }
103
+ console.log();
104
+
105
+ } catch (e) {
106
+ handleError(e);
107
+ }
108
+ }
@@ -1,7 +1,7 @@
1
1
  import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
2
  import { requireAuth } from "../../config.js";
3
3
  import { fatalError, outputJSON, EXIT } from "../../output.js";
4
- import { formatAmount, quarterRange } from "../../format.js";
4
+ import { formatAmount, quarterRange, formatDate } from "../../format.js";
5
5
  import * as fs from "fs";
6
6
 
7
7
  interface GstOpts {
@@ -114,3 +114,81 @@ export async function gstR1CsvCommand(opts: GstOpts & { output?: string }): Prom
114
114
  fatalError(String(e instanceof Error ? e.message : e));
115
115
  }
116
116
  }
117
+
118
+ export async function gstR9Command(financialYear: string, opts: GstOpts): Promise<void> {
119
+ const cfg = requireAuth();
120
+ const client = new HisaaboClient(cfg);
121
+
122
+ try {
123
+ const report = await client.gst.gstr9({ financialYear });
124
+
125
+ if (opts.json) {
126
+ outputJSON(report);
127
+ return;
128
+ }
129
+
130
+ console.log(`\n GSTR-9 Annual Return — FY ${financialYear}`);
131
+ console.log(` ${"═".repeat(60)}\n`);
132
+
133
+ const r = report as Record<string, unknown>;
134
+ if (r["summary"] && typeof r["summary"] === "object") {
135
+ const s = r["summary"] as Record<string, unknown>;
136
+ if (s["totalTurnover"]) console.log(` Total Turnover: ${formatAmount(String(s["totalTurnover"]))}`);
137
+ if (s["totalTax"]) console.log(` Total Tax: ${formatAmount(String(s["totalTax"]))}`);
138
+ if (s["totalITC"]) console.log(` Total ITC: ${formatAmount(String(s["totalITC"]))}`);
139
+ }
140
+ console.log();
141
+ console.log(" Use --json for full GSTR-9 data.\n");
142
+
143
+ } catch (e) {
144
+ if (e instanceof HisaaboApiError) {
145
+ const err = e.hisaaboError;
146
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
147
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
148
+ }
149
+ fatalError(String(e instanceof Error ? e.message : e));
150
+ }
151
+ }
152
+
153
+ export async function gstr2bUploadsCommand(opts: GstOpts): Promise<void> {
154
+ const cfg = requireAuth();
155
+ const client = new HisaaboClient(cfg);
156
+
157
+ try {
158
+ const result = await client.gst.gstr2bUploads();
159
+
160
+ if (opts.json) {
161
+ outputJSON(result);
162
+ return;
163
+ }
164
+
165
+ const uploads = Array.isArray(result) ? result
166
+ : Array.isArray(result?.data) ? result.data
167
+ : [];
168
+
169
+ console.log("\n GSTR-2B Uploads\n");
170
+ console.log(` ${"═".repeat(60)}\n`);
171
+
172
+ if (uploads.length === 0) {
173
+ console.log(" No uploads found.\n");
174
+ return;
175
+ }
176
+
177
+ for (const up of uploads as Array<Record<string, unknown>>) {
178
+ const id = String(up["id"] ?? "-").slice(0, 8);
179
+ const period = String(up["period"] ?? up["returnPeriod"] ?? "-").padEnd(10);
180
+ const date = formatDate(String(up["uploadedAt"] ?? up["createdAt"] ?? ""));
181
+ const records = String(up["totalRecords"] ?? up["records"] ?? "-").padStart(8);
182
+ console.log(` ${id} ${period} ${date.padEnd(13)} Records: ${records}`);
183
+ }
184
+ console.log();
185
+
186
+ } catch (e) {
187
+ if (e instanceof HisaaboApiError) {
188
+ const err = e.hisaaboError;
189
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
190
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
191
+ }
192
+ fatalError(String(e instanceof Error ? e.message : e));
193
+ }
194
+ }
@@ -82,7 +82,15 @@ export async function invoiceGetCommand(id: string, opts: { json?: boolean }): P
82
82
  process.stdout.write(`│ ${"─".repeat(inner - 2)} │\n`);
83
83
  line(`Total:`, (hasColor() ? chalk.bold(formatAmount(inv.totalAmount)) : formatAmount(inv.totalAmount)).padStart(16));
84
84
  line(`Paid:`, formatAmount(inv.amountPaid).padStart(16));
85
- line(`Balance:`, formatAmount(inv.balanceDue).padStart(16));
85
+ if (inv.totalAdjusted && parseFloat(inv.totalAdjusted) > 0)
86
+ line(`Adjusted:`, ("-" + formatAmount(inv.totalAdjusted)).padStart(16));
87
+ const balance = inv.totalAdjusted && parseFloat(inv.totalAdjusted) > 0
88
+ ? String(parseFloat(inv.totalAmount) - parseFloat(inv.amountPaid) - parseFloat(inv.totalAdjusted))
89
+ : inv.balanceDue;
90
+ line(`Balance:`, formatAmount(balance).padStart(16));
91
+ if (inv.status === "adjusted")
92
+ line(`(Settled via credit note / sales return)`);
93
+
86
94
 
87
95
  if (inv.notes || inv.termsAndConditions) {
88
96
  divider();
@@ -0,0 +1,163 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import { fatalError, outputJSON, EXIT } from "../../output.js";
4
+ import { formatAmount } from "../../format.js";
5
+
6
+ interface ItcOpts {
7
+ json?: boolean;
8
+ from?: string;
9
+ to?: string;
10
+ }
11
+
12
+ function handleError(e: unknown): never {
13
+ if (e instanceof HisaaboApiError) {
14
+ const err = e.hisaaboError;
15
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
16
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
17
+ }
18
+ fatalError(String(e instanceof Error ? e.message : e));
19
+ }
20
+
21
+ export async function itcDashboardCommand(opts: ItcOpts): Promise<void> {
22
+ const cfg = requireAuth();
23
+ const client = new HisaaboClient(cfg);
24
+
25
+ try {
26
+ const result = await client.itc.dashboard({ fromDate: opts.from, toDate: opts.to });
27
+
28
+ if (opts.json) {
29
+ outputJSON(result);
30
+ return;
31
+ }
32
+
33
+ const r = result as Record<string, unknown>;
34
+ console.log("\n ITC Dashboard\n");
35
+ console.log(` ${"═".repeat(50)}\n`);
36
+
37
+ const eligible = String(r["totalEligible"] ?? r["eligible"] ?? "0");
38
+ const blocked = String(r["totalBlocked"] ?? r["blocked"] ?? "0");
39
+ const utilized = String(r["totalUtilized"] ?? r["utilized"] ?? "0");
40
+ const available = String(r["availableBalance"] ?? r["available"] ?? "0");
41
+
42
+ console.log(` Eligible ITC: ${formatAmount(eligible).padStart(14)}`);
43
+ console.log(` Blocked ITC: ${formatAmount(blocked).padStart(14)}`);
44
+ console.log(` Utilized ITC: ${formatAmount(utilized).padStart(14)}`);
45
+ console.log(` Available Balance:${formatAmount(available).padStart(14)}`);
46
+ console.log();
47
+
48
+ } catch (e) {
49
+ handleError(e);
50
+ }
51
+ }
52
+
53
+ export async function itcLedgerCommand(opts: ItcOpts): Promise<void> {
54
+ const cfg = requireAuth();
55
+ const client = new HisaaboClient(cfg);
56
+
57
+ try {
58
+ const result = await client.itc.ledger({ fromDate: opts.from, toDate: opts.to });
59
+
60
+ if (opts.json) {
61
+ outputJSON(result);
62
+ return;
63
+ }
64
+
65
+ const entries = Array.isArray(result) ? result
66
+ : Array.isArray(result?.data) ? result.data
67
+ : Array.isArray(result?.entries) ? result.entries
68
+ : [];
69
+
70
+ console.log("\n ITC Ledger\n");
71
+ console.log(` ${"═".repeat(70)}\n`);
72
+
73
+ for (const entry of entries as Array<Record<string, unknown>>) {
74
+ const date = String(entry["date"] ?? "-").slice(0, 10);
75
+ const supplier = String(entry["supplierName"] ?? entry["supplier"] ?? "-").padEnd(22);
76
+ const gstin = String(entry["gstin"] ?? "-").padEnd(16);
77
+ const igst = formatAmount(String(entry["igst"] ?? "0")).padStart(12);
78
+ const cgst = formatAmount(String(entry["cgst"] ?? "0")).padStart(12);
79
+ const sgst = formatAmount(String(entry["sgst"] ?? "0")).padStart(12);
80
+ console.log(` ${date.padEnd(12)} ${supplier} ${gstin} IGST:${igst} CGST:${cgst} SGST:${sgst}`);
81
+ }
82
+ console.log();
83
+
84
+ } catch (e) {
85
+ handleError(e);
86
+ }
87
+ }
88
+
89
+ export async function itcAgingCommand(opts: { json?: boolean }): Promise<void> {
90
+ const cfg = requireAuth();
91
+ const client = new HisaaboClient(cfg);
92
+
93
+ try {
94
+ const result = await client.itc.agingAlerts();
95
+
96
+ if (opts.json) {
97
+ outputJSON(result);
98
+ return;
99
+ }
100
+
101
+ const alerts = Array.isArray(result) ? result
102
+ : Array.isArray(result?.data) ? result.data
103
+ : Array.isArray(result?.alerts) ? result.alerts
104
+ : [];
105
+
106
+ console.log("\n ITC Aging Alerts\n");
107
+ console.log(` ${"═".repeat(60)}\n`);
108
+
109
+ if (alerts.length === 0) {
110
+ console.log(" No aging alerts.\n");
111
+ return;
112
+ }
113
+
114
+ for (const alert of alerts as Array<Record<string, unknown>>) {
115
+ const supplier = String(alert["supplierName"] ?? alert["supplier"] ?? "-").padEnd(25);
116
+ const amount = formatAmount(String(alert["amount"] ?? "0")).padStart(14);
117
+ const days = String(alert["daysOld"] ?? alert["age"] ?? "-").padStart(6);
118
+ console.log(` ${supplier} ${amount} ${days} days`);
119
+ }
120
+ console.log();
121
+
122
+ } catch (e) {
123
+ handleError(e);
124
+ }
125
+ }
126
+
127
+ export async function itcBlockCommand(invoiceId: string, opts: { json?: boolean }): Promise<void> {
128
+ const cfg = requireAuth();
129
+ const client = new HisaaboClient(cfg);
130
+
131
+ try {
132
+ const result = await client.itc.markBlocked({ invoiceId });
133
+
134
+ if (opts.json) {
135
+ outputJSON(result);
136
+ return;
137
+ }
138
+
139
+ console.log(` ITC for invoice ${invoiceId} marked as blocked.\n`);
140
+
141
+ } catch (e) {
142
+ handleError(e);
143
+ }
144
+ }
145
+
146
+ export async function itcUnblockCommand(invoiceId: string, opts: { json?: boolean }): Promise<void> {
147
+ const cfg = requireAuth();
148
+ const client = new HisaaboClient(cfg);
149
+
150
+ try {
151
+ const result = await client.itc.markEligible({ invoiceId });
152
+
153
+ if (opts.json) {
154
+ outputJSON(result);
155
+ return;
156
+ }
157
+
158
+ console.log(` ITC for invoice ${invoiceId} marked as eligible.\n`);
159
+
160
+ } catch (e) {
161
+ handleError(e);
162
+ }
163
+ }