@hisaabo/cli 0.5.0 → 0.6.1
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.
- package/dist/bin/{audit-trail-5LOCJ7XZ.js → audit-trail-4AMEFQGB.js} +1 -1
- package/dist/bin/{categories-64WWZTND.js → categories-CLCBRNWC.js} +1 -1
- package/dist/bin/{check-slug-FLHHUDYS.js → check-slug-OKW7KDYG.js} +1 -1
- package/dist/bin/{chunk-4MEL44QX.js → chunk-GXRLFDZW.js} +234 -0
- package/dist/bin/{client-5NZ23GML.js → client-2ZKMLWI6.js} +1 -1
- package/dist/bin/{collection-efficiency-U56XNVEE.js → collection-efficiency-TECE6PVQ.js} +1 -1
- package/dist/bin/{create-RPDEORDD.js → create-AS2YVGRA.js} +1 -1
- package/dist/bin/{default-account-AE6EXZZR.js → default-account-3RVSU7RF.js} +1 -1
- package/dist/bin/{expenses-5N2QSG54.js → expenses-KXFQJKD6.js} +1 -1
- package/dist/bin/{export-QICOQK34.js → export-UHZISG7H.js} +1 -1
- package/dist/bin/{factory-KOCW2AQM.js → factory-OBESY2LG.js} +1 -1
- package/dist/bin/{get-GWH6S5SJ.js → get-GTL556HL.js} +1 -1
- package/dist/bin/{get-A43QCI2S.js → get-WUSYEMG4.js} +1 -1
- package/dist/bin/hisaabo.js +892 -55
- package/dist/bin/{invitations-P3EEN5WI.js → invitations-U4ZNYWY7.js} +1 -1
- package/dist/bin/{invite-T3CKX53E.js → invite-5S4GJKRF.js} +1 -1
- package/dist/bin/{invoice-breakdown-FN5BEFJD.js → invoice-breakdown-PP3BZQLG.js} +1 -1
- package/dist/bin/{items-2OOCQKVF.js → items-CHEFLI7C.js} +1 -1
- package/dist/bin/{items-toggle-SKZWCGJH.js → items-toggle-ETVCDCU6.js} +1 -1
- package/dist/bin/{list-A2RKI3ZG.js → list-3FO4UJKC.js} +1 -1
- package/dist/bin/{list-NRMBMKMI.js → list-LQJGTZB4.js} +1 -1
- package/dist/bin/{list-T74SN6IR.js → list-RJ34MFPR.js} +1 -1
- package/dist/bin/{members-W2GW3ODT.js → members-TE5K5NQC.js} +1 -1
- package/dist/bin/{monthly-comparison-T34ZFOHL.js → monthly-comparison-Q6KPMTPS.js} +1 -1
- package/dist/bin/{order-cancel-TI27JYYD.js → order-cancel-NOQDBL2N.js} +1 -1
- package/dist/bin/{order-confirm-VMRAMNTD.js → order-confirm-6WMKTGPV.js} +1 -1
- package/dist/bin/{order-get-C2RBUR4O.js → order-get-ONWR4GTW.js} +1 -1
- package/dist/bin/{order-update-RE3HATNF.js → order-update-IVO4AFGV.js} +1 -1
- package/dist/bin/{payment-modes-WOOT22I7.js → payment-modes-FXB2G6WP.js} +1 -1
- package/dist/bin/{profit-loss-T4RESJ32.js → profit-loss-XPYELDTH.js} +1 -1
- package/dist/bin/{receivables-aging-6XMENEWS.js → receivables-aging-MU6Q3DZ4.js} +1 -1
- package/dist/bin/{remove-6QZI4JCY.js → remove-DJBOOOR4.js} +1 -1
- package/dist/bin/{revoke-AVEMPAC7.js → revoke-5L5GZ4ZZ.js} +1 -1
- package/dist/bin/{revoke-YUCFZFNR.js → revoke-WRIK7HLY.js} +1 -1
- package/dist/bin/{revoke-all-LFW5WBHO.js → revoke-all-QARW2G6R.js} +1 -1
- package/dist/bin/{revoke-invitation-DTGQRJR4.js → revoke-invitation-ZGLJHYNB.js} +1 -1
- package/dist/bin/{sales-trend-ZYBRUDUU.js → sales-trend-P5HOZJSX.js} +1 -1
- package/dist/bin/{sequence-FPOJTI2P.js → sequence-LK6QLSI5.js} +1 -1
- package/dist/bin/{store-IOB4Y67C.js → store-FU7CEILC.js} +1 -1
- package/dist/bin/{summary-5KYBA4ZO.js → summary-XONLN72I.js} +1 -1
- package/dist/bin/{top-customers-WSQ2UEJL.js → top-customers-U6HQW2GH.js} +1 -1
- package/dist/bin/{top-items-RWQPDGLN.js → top-items-EAOIVZ4P.js} +1 -1
- package/dist/bin/{top-outstanding-QAMO2E7Y.js → top-outstanding-4546FJDH.js} +1 -1
- package/dist/bin/{unpaid-invoices-WB3TK5B4.js → unpaid-invoices-AED55PLC.js} +1 -1
- package/dist/bin/{untracked-H733MYJL.js → untracked-ZEM2CDHC.js} +1 -1
- package/dist/bin/{update-TLBUIC5J.js → update-FO7AAXF5.js} +1 -1
- package/dist/bin/{update-H6LPO2Z4.js → update-OZPBIBME.js} +1 -1
- package/dist/bin/{update-JU2X3XU5.js → update-QCK32XAG.js} +1 -1
- package/dist/bin/{update-role-QST7BVFX.js → update-role-RB35QIA5.js} +1 -1
- package/dist/bin/{update-settings-Q2EGRLKZ.js → update-settings-EUC2FJQJ.js} +1 -1
- package/package.json +1 -1
- package/src/bin/hisaabo.ts +10 -0
- package/src/bin/registrars/bank-recon.ts +34 -0
- package/src/bin/registrars/einvoice.ts +46 -0
- package/src/bin/registrars/ewb.ts +37 -0
- package/src/bin/registrars/gst.ts +17 -1
- package/src/bin/registrars/itc.ts +56 -0
- package/src/bin/registrars/journal.ts +47 -0
- package/src/bin/registrars/report.ts +44 -0
- package/src/client.ts +248 -0
- package/src/commands/bank-recon/index.ts +127 -0
- package/src/commands/einvoice/index.ts +109 -0
- package/src/commands/ewb/index.ts +108 -0
- package/src/commands/gst/index.ts +79 -1
- package/src/commands/itc/index.ts +163 -0
- package/src/commands/journal/index.ts +156 -0
- package/src/commands/report/index.ts +171 -0
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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> {
|