@hisaabo/cli 0.1.0 → 0.4.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.
- package/.turbo/turbo-typecheck.log +1 -1
- package/README.md +332 -0
- package/dist/bin/audit-trail-5LOCJ7XZ.js +78 -0
- package/dist/bin/categories-64WWZTND.js +47 -0
- package/dist/bin/check-slug-FLHHUDYS.js +65 -0
- package/dist/bin/chunk-4MEL44QX.js +848 -0
- package/dist/bin/chunk-FIMJZAS4.js +84 -0
- package/dist/bin/chunk-NO4FIFMS.js +176 -0
- package/dist/bin/chunk-T63VQXNM.js +156 -0
- package/dist/bin/client-5NZ23GML.js +11 -0
- package/dist/bin/collection-efficiency-U56XNVEE.js +165 -0
- package/dist/bin/config-335MN4I7.js +18 -0
- package/dist/bin/create-RPDEORDD.js +83 -0
- package/dist/bin/default-account-AE6EXZZR.js +58 -0
- package/dist/bin/expenses-5N2QSG54.js +89 -0
- package/dist/bin/export-QICOQK34.js +59 -0
- package/dist/bin/factory-KOCW2AQM.js +483 -0
- package/dist/bin/get-A43QCI2S.js +66 -0
- package/dist/bin/get-GWH6S5SJ.js +71 -0
- package/dist/bin/hisaabo.js +2302 -1510
- package/dist/bin/invitations-P3EEN5WI.js +66 -0
- package/dist/bin/invite-T3CKX53E.js +53 -0
- package/dist/bin/invoice-breakdown-FN5BEFJD.js +97 -0
- package/dist/bin/items-2OOCQKVF.js +62 -0
- package/dist/bin/items-toggle-SKZWCGJH.js +46 -0
- package/dist/bin/list-A2RKI3ZG.js +79 -0
- package/dist/bin/list-NRMBMKMI.js +90 -0
- package/dist/bin/list-T74SN6IR.js +46 -0
- package/dist/bin/members-W2GW3ODT.js +55 -0
- package/dist/bin/monthly-comparison-T34ZFOHL.js +176 -0
- package/dist/bin/order-cancel-TI27JYYD.js +55 -0
- package/dist/bin/order-confirm-VMRAMNTD.js +53 -0
- package/dist/bin/order-get-C2RBUR4O.js +88 -0
- package/dist/bin/order-update-RE3HATNF.js +60 -0
- package/dist/bin/output-NUOL7KJW.js +35 -0
- package/dist/bin/payment-modes-WOOT22I7.js +126 -0
- package/dist/bin/profit-loss-T4RESJ32.js +135 -0
- package/dist/bin/receivables-aging-6XMENEWS.js +161 -0
- package/dist/bin/remove-6QZI4JCY.js +52 -0
- package/dist/bin/revoke-AVEMPAC7.js +40 -0
- package/dist/bin/revoke-YUCFZFNR.js +52 -0
- package/dist/bin/revoke-all-LFW5WBHO.js +33 -0
- package/dist/bin/revoke-invitation-DTGQRJR4.js +40 -0
- package/dist/bin/sales-trend-ZYBRUDUU.js +71 -0
- package/dist/bin/sequence-FPOJTI2P.js +66 -0
- package/dist/bin/store-IOB4Y67C.js +82 -0
- package/dist/bin/summary-5KYBA4ZO.js +113 -0
- package/dist/bin/top-customers-WSQ2UEJL.js +81 -0
- package/dist/bin/top-items-RWQPDGLN.js +84 -0
- package/dist/bin/top-outstanding-QAMO2E7Y.js +64 -0
- package/dist/bin/unpaid-invoices-WB3TK5B4.js +65 -0
- package/dist/bin/untracked-H733MYJL.js +67 -0
- package/dist/bin/update-H6LPO2Z4.js +61 -0
- package/dist/bin/update-JU2X3XU5.js +54 -0
- package/dist/bin/update-TLBUIC5J.js +57 -0
- package/dist/bin/update-role-QST7BVFX.js +45 -0
- package/dist/bin/update-settings-Q2EGRLKZ.js +56 -0
- package/package.json +7 -6
- package/src/auth.ts +12 -3
- package/src/bin/hisaabo.ts +49 -935
- package/src/bin/registrars/api-key.ts +44 -0
- package/src/bin/registrars/auth.ts +222 -0
- package/src/bin/registrars/automated-invoice.ts +167 -0
- package/src/bin/registrars/bank.ts +124 -0
- package/src/bin/registrars/business.ts +120 -0
- package/src/bin/registrars/dashboard.ts +225 -0
- package/src/bin/registrars/document.ts +184 -0
- package/src/bin/registrars/expense.ts +87 -0
- package/src/bin/registrars/gst.ts +41 -0
- package/src/bin/registrars/import.ts +49 -0
- package/src/bin/registrars/invoice.ts +117 -0
- package/src/bin/registrars/item.ts +112 -0
- package/src/bin/registrars/party.ts +81 -0
- package/src/bin/registrars/payment.ts +128 -0
- package/src/bin/registrars/report.ts +142 -0
- package/src/bin/registrars/session.ts +32 -0
- package/src/bin/registrars/shipment.ts +74 -0
- package/src/bin/registrars/store.ts +128 -0
- package/src/bin/registrars/target.ts +46 -0
- package/src/bin/registrars/tenant.ts +73 -0
- package/src/client.ts +589 -15
- package/src/commands/api-key/create.ts +72 -0
- package/src/commands/api-key/list.ts +71 -0
- package/src/commands/api-key/revoke.ts +46 -0
- package/src/commands/automated-invoice/create.ts +85 -0
- package/src/commands/automated-invoice/delete.ts +42 -0
- package/src/commands/automated-invoice/get.ts +113 -0
- package/src/commands/automated-invoice/history.ts +65 -0
- package/src/commands/automated-invoice/index.ts +11 -0
- package/src/commands/automated-invoice/list.ts +91 -0
- package/src/commands/automated-invoice/pause.ts +29 -0
- package/src/commands/automated-invoice/resume.ts +29 -0
- package/src/commands/automated-invoice/run-now.ts +29 -0
- package/src/commands/automated-invoice/suggestions.ts +68 -0
- package/src/commands/automated-invoice/update.ts +54 -0
- package/src/commands/automated-invoice/usage.ts +68 -0
- package/src/commands/bank/gateway-config.ts +61 -0
- package/src/commands/bank/update-gateway.ts +84 -0
- package/src/commands/business/audit-trail.ts +79 -0
- package/src/commands/business/export.ts +52 -0
- package/src/commands/business/get.ts +55 -0
- package/src/commands/business/sequence.ts +65 -0
- package/src/commands/business/update.ts +64 -0
- package/src/commands/dashboard/collection-efficiency.ts +164 -0
- package/src/commands/dashboard/expenses.ts +76 -0
- package/src/commands/dashboard/invoice-breakdown.ts +89 -0
- package/src/commands/dashboard/monthly-comparison.ts +193 -0
- package/src/commands/dashboard/payment-modes.ts +121 -0
- package/src/commands/dashboard/profit-loss.ts +146 -0
- package/src/commands/dashboard/receivables-aging.ts +169 -0
- package/src/commands/dashboard/sales-trend.ts +68 -0
- package/src/commands/dashboard/summary.ts +105 -0
- package/src/commands/dashboard/top-customers.ts +70 -0
- package/src/commands/dashboard/top-items.ts +74 -0
- package/src/commands/dashboard/top-outstanding.ts +61 -0
- package/src/commands/document/factory.ts +590 -0
- package/src/commands/expense/categories.ts +40 -0
- package/src/commands/expense/update.ts +58 -0
- package/src/commands/import/index.ts +68 -0
- package/src/commands/item/categories.ts +40 -0
- package/src/commands/item/low-stock-count.ts +32 -0
- package/src/commands/item/merge.ts +53 -0
- package/src/commands/item/price-history.ts +59 -0
- package/src/commands/item/rename-unit.ts +39 -0
- package/src/commands/item/sales-stats.ts +44 -0
- package/src/commands/item/stock-history.ts +70 -0
- package/src/commands/item/switch-base-unit.ts +42 -0
- package/src/commands/item/update.ts +59 -0
- package/src/commands/item/variants-create.ts +58 -0
- package/src/commands/item/variants-delete.ts +47 -0
- package/src/commands/item/variants-list.ts +63 -0
- package/src/commands/item/variants-update.ts +61 -0
- package/src/commands/party/ledger-report.ts +81 -0
- package/src/commands/party/merge.ts +50 -0
- package/src/commands/party/stats.ts +40 -0
- package/src/commands/party/top-items.ts +57 -0
- package/src/commands/party/update.ts +65 -0
- package/src/commands/payment/default-account.ts +56 -0
- package/src/commands/payment/get.ts +59 -0
- package/src/commands/payment/unpaid-invoices.ts +69 -0
- package/src/commands/payment/untracked.ts +70 -0
- package/src/commands/payment/update.ts +54 -0
- package/src/commands/report/index.ts +348 -1
- package/src/commands/session/list.ts +91 -0
- package/src/commands/session/revoke-all.ts +20 -0
- package/src/commands/session/revoke.ts +32 -0
- package/src/commands/store/check-slug.ts +48 -0
- package/src/commands/store/items-toggle.ts +41 -0
- package/src/commands/store/items.ts +61 -0
- package/src/commands/store/order-cancel.ts +48 -0
- package/src/commands/store/order-confirm.ts +45 -0
- package/src/commands/store/order-get.ts +66 -0
- package/src/commands/store/order-update.ts +52 -0
- package/src/commands/store/update-settings.ts +52 -0
- package/src/commands/tenant/invitations.ts +62 -0
- package/src/commands/tenant/invite.ts +57 -0
- package/src/commands/tenant/list.ts +46 -0
- package/src/commands/tenant/members.ts +55 -0
- package/src/commands/tenant/remove.ts +47 -0
- package/src/commands/tenant/revoke-invitation.ts +32 -0
- package/src/commands/tenant/update-role.ts +41 -0
- package/src/config.ts +51 -2
- package/src/error-handler.ts +53 -0
- package/src/output.ts +1 -0
- package/src/spinner.ts +39 -0
- package/tsup.config.ts +6 -1
- package/src/components/ErrorDisplay.tsx +0 -16
- package/src/components/Header.tsx +0 -26
- package/src/components/MoneyCell.tsx +0 -16
- package/src/components/Spinner.tsx +0 -12
- package/src/components/StatusBadge.tsx +0 -39
- package/src/components/Table.tsx +0 -63
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, hasColor, termWidth } from "../../output.js";
|
|
4
|
+
import { formatAmount, fyStart, todayISO, monthStart, monthEnd } from "../../format.js";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
|
|
7
|
+
interface CollectionEfficiencyOpts {
|
|
8
|
+
from?: string;
|
|
9
|
+
to?: string;
|
|
10
|
+
thisMonth?: boolean;
|
|
11
|
+
thisFy?: boolean;
|
|
12
|
+
json?: boolean;
|
|
13
|
+
format?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function rateBar(rate: number, width: number): string {
|
|
17
|
+
const clamped = Math.min(100, Math.max(0, rate));
|
|
18
|
+
const filled = Math.round((clamped / 100) * width);
|
|
19
|
+
const bar = "█".repeat(filled) + "░".repeat(width - filled);
|
|
20
|
+
if (!hasColor()) return bar;
|
|
21
|
+
if (clamped >= 80) return chalk.green(bar);
|
|
22
|
+
if (clamped >= 50) return chalk.yellow(bar);
|
|
23
|
+
return chalk.red(bar);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function dashboardCollectionEfficiencyCommand(opts: CollectionEfficiencyOpts): Promise<void> {
|
|
27
|
+
const cfg = requireAuth();
|
|
28
|
+
const client = new HisaaboClient(cfg);
|
|
29
|
+
|
|
30
|
+
let fromDate = opts.from;
|
|
31
|
+
let toDate = opts.to;
|
|
32
|
+
if (opts.thisMonth) { fromDate = monthStart(); toDate = monthEnd(); }
|
|
33
|
+
else if (opts.thisFy) { fromDate = fyStart(); toDate = todayISO(); }
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const data = await client.dashboard.collectionEfficiency({ fromDate, toDate });
|
|
37
|
+
|
|
38
|
+
if (opts.json) {
|
|
39
|
+
outputJSON(data);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const d = (data ?? {}) as Record<string, unknown>;
|
|
44
|
+
|
|
45
|
+
// Top-level metrics
|
|
46
|
+
const totalInvoiced = parseFloat(String(d["totalInvoiced"] ?? d["invoiced"] ?? d["billed"] ?? "0"));
|
|
47
|
+
const totalCollected = parseFloat(String(d["totalCollected"] ?? d["collected"] ?? d["received"] ?? "0"));
|
|
48
|
+
const outstanding = parseFloat(String(d["outstanding"] ?? d["totalOutstanding"] ?? String(totalInvoiced - totalCollected)));
|
|
49
|
+
const collectionRate = parseFloat(String(d["collectionRate"] ?? d["rate"] ?? (totalInvoiced > 0 ? ((totalCollected / totalInvoiced) * 100).toFixed(2) : "0")));
|
|
50
|
+
const dso = parseFloat(String(d["dso"] ?? d["daysSalesOutstanding"] ?? "0"));
|
|
51
|
+
|
|
52
|
+
// Aging breakdown sub-object
|
|
53
|
+
const aging = (d["aging"] ?? d["agingBreakdown"] ?? d["breakdown"] ?? null) as Record<string, unknown> | null;
|
|
54
|
+
|
|
55
|
+
if (opts.format === "tsv" || opts.format === "csv") {
|
|
56
|
+
const rows: Array<Record<string, string>> = [
|
|
57
|
+
{ metric: "Total Invoiced", value: formatAmount(totalInvoiced) },
|
|
58
|
+
{ metric: "Total Collected", value: formatAmount(totalCollected) },
|
|
59
|
+
{ metric: "Outstanding", value: formatAmount(outstanding) },
|
|
60
|
+
{ metric: "Collection Rate", value: `${collectionRate.toFixed(1)}%` },
|
|
61
|
+
{ metric: "DSO (days)", value: dso > 0 ? String(Math.round(dso)) : "-" },
|
|
62
|
+
];
|
|
63
|
+
if (aging) {
|
|
64
|
+
for (const [k, v] of Object.entries(aging)) {
|
|
65
|
+
rows.push({ metric: `Aging: ${k}`, value: formatAmount(String(v)) });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const columns = [
|
|
69
|
+
{ key: "metric", header: "Metric", align: "left" as const },
|
|
70
|
+
{ key: "value", header: "Value", align: "right" as const },
|
|
71
|
+
];
|
|
72
|
+
if (opts.format === "tsv") outputTSV(rows, columns);
|
|
73
|
+
else outputCSV(rows, columns);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Pretty display
|
|
78
|
+
const width = Math.min(termWidth() - 4, 56);
|
|
79
|
+
const innerW = width - 2;
|
|
80
|
+
const barW = Math.max(8, innerW - 22);
|
|
81
|
+
|
|
82
|
+
const line = (label: string, value: string, opts2: { bold?: boolean; color?: (s: string) => string } = {}): void => {
|
|
83
|
+
const lbl = label.padEnd(20).slice(0, 20);
|
|
84
|
+
const val = value.padStart(innerW - 22).slice(0, innerW - 22);
|
|
85
|
+
let out = ` │ ${lbl} ${val} │`;
|
|
86
|
+
if (hasColor()) {
|
|
87
|
+
if (opts2.bold) out = ` │ ${chalk.bold(lbl)} ${val} │`;
|
|
88
|
+
if (opts2.color) out = ` │ ${opts2.bold ? chalk.bold(lbl) : lbl} ${opts2.color(val)} │`;
|
|
89
|
+
}
|
|
90
|
+
process.stdout.write(out + "\n");
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const sep = (): void => { process.stdout.write(" ├" + "─".repeat(innerW) + "┤\n"); };
|
|
94
|
+
|
|
95
|
+
process.stdout.write("\n");
|
|
96
|
+
if (hasColor()) process.stdout.write(" " + chalk.bold("Collection Efficiency") + "\n\n");
|
|
97
|
+
else process.stdout.write(" Collection Efficiency\n\n");
|
|
98
|
+
|
|
99
|
+
process.stdout.write(" ┌" + "─".repeat(innerW) + "┐\n");
|
|
100
|
+
|
|
101
|
+
line("Total Invoiced", `₹${formatAmount(totalInvoiced)}`, { bold: true });
|
|
102
|
+
line("Total Collected", `₹${formatAmount(totalCollected)}`, {
|
|
103
|
+
color: totalCollected >= totalInvoiced * 0.8 ? chalk.green : chalk.yellow,
|
|
104
|
+
});
|
|
105
|
+
line("Outstanding", `₹${formatAmount(outstanding)}`, {
|
|
106
|
+
color: outstanding > 0 ? chalk.red : chalk.green,
|
|
107
|
+
});
|
|
108
|
+
sep();
|
|
109
|
+
|
|
110
|
+
// Collection rate with bar
|
|
111
|
+
const rateStr = `${collectionRate.toFixed(1)}%`;
|
|
112
|
+
const bar = rateBar(collectionRate, barW);
|
|
113
|
+
const rateLabel = "Collection Rate".padEnd(20).slice(0, 20);
|
|
114
|
+
process.stdout.write(` │ ${hasColor() ? chalk.bold(rateLabel) : rateLabel} ${bar} ${rateStr.padStart(6)} │\n`);
|
|
115
|
+
|
|
116
|
+
if (dso > 0) {
|
|
117
|
+
const dsoStr = `${Math.round(dso)} days`;
|
|
118
|
+
const dsoLabel = "DSO".padEnd(20).slice(0, 20);
|
|
119
|
+
const dsoColor = dso <= 30 ? chalk.green : dso <= 60 ? chalk.yellow : chalk.red;
|
|
120
|
+
const dsoVal = hasColor() ? dsoColor(dsoStr) : dsoStr;
|
|
121
|
+
process.stdout.write(` │ ${dsoLabel} ${dsoVal.padStart(innerW - 22)} │\n`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Aging buckets if available
|
|
125
|
+
if (aging && Object.keys(aging).length > 0) {
|
|
126
|
+
sep();
|
|
127
|
+
process.stdout.write(` │ ${hasColor() ? chalk.bold("Aging Breakdown") : "Aging Breakdown"}${" ".repeat(innerW - 16)} │\n`);
|
|
128
|
+
const agingEntries = Object.entries(aging);
|
|
129
|
+
for (const [bucket, val] of agingEntries) {
|
|
130
|
+
const amt = parseFloat(String(val));
|
|
131
|
+
const amtStr = `₹${formatAmount(amt)}`;
|
|
132
|
+
const bucketLabel = bucket.padEnd(20).slice(0, 20);
|
|
133
|
+
const isOld = /90\+|90_plus/i.test(bucket);
|
|
134
|
+
const color = isOld ? chalk.red : /31|61/.test(bucket) ? chalk.yellow : undefined;
|
|
135
|
+
const valStr = color && hasColor() ? color(amtStr) : amtStr;
|
|
136
|
+
process.stdout.write(` │ ${bucketLabel.slice(0, 18)} ${valStr.padStart(innerW - 22)} │\n`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
process.stdout.write(" └" + "─".repeat(innerW) + "┘\n\n");
|
|
141
|
+
|
|
142
|
+
// Also show aging as a table for easy reading
|
|
143
|
+
if (aging && Object.keys(aging).length > 0) {
|
|
144
|
+
const agingRows = Object.entries(aging).map(([bucket, val]) => ({
|
|
145
|
+
bucket,
|
|
146
|
+
amount: formatAmount(String(val)),
|
|
147
|
+
}));
|
|
148
|
+
const agingColumns = [
|
|
149
|
+
{ key: "bucket", header: "Aging Bucket", align: "left" as const },
|
|
150
|
+
{ key: "amount", header: "Amount ₹", align: "right" as const },
|
|
151
|
+
];
|
|
152
|
+
outputTable(agingRows, agingColumns);
|
|
153
|
+
process.stdout.write("\n");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
} catch (e) {
|
|
157
|
+
if (e instanceof HisaaboApiError) {
|
|
158
|
+
const err = e.hisaaboError;
|
|
159
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
160
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
161
|
+
}
|
|
162
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, hasColor } from "../../output.js";
|
|
4
|
+
import { formatAmount, fyStart, todayISO, monthStart, monthEnd } from "../../format.js";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
|
|
7
|
+
interface ExpensesOpts {
|
|
8
|
+
from?: string;
|
|
9
|
+
to?: string;
|
|
10
|
+
thisMonth?: boolean;
|
|
11
|
+
thisFy?: boolean;
|
|
12
|
+
json?: boolean;
|
|
13
|
+
format?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function dashboardExpensesCommand(opts: ExpensesOpts): Promise<void> {
|
|
17
|
+
const cfg = requireAuth();
|
|
18
|
+
const client = new HisaaboClient(cfg);
|
|
19
|
+
|
|
20
|
+
let fromDate = opts.from;
|
|
21
|
+
let toDate = opts.to;
|
|
22
|
+
if (opts.thisMonth) { fromDate = monthStart(); toDate = monthEnd(); }
|
|
23
|
+
else if (opts.thisFy) { fromDate = fyStart(); toDate = todayISO(); }
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const data = await client.dashboard.expensesByCategory({ fromDate, toDate });
|
|
27
|
+
|
|
28
|
+
if (opts.json) {
|
|
29
|
+
outputJSON(data);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const items: Array<Record<string, unknown>> = Array.isArray(data) ? data : [];
|
|
34
|
+
const total = items.reduce((sum, r) => sum + parseFloat(String(r["totalAmount"] ?? r["amount"] ?? "0")), 0);
|
|
35
|
+
|
|
36
|
+
const rows = items.map((r: Record<string, unknown>) => {
|
|
37
|
+
const amt = parseFloat(String(r["totalAmount"] ?? r["amount"] ?? "0"));
|
|
38
|
+
const pct = total > 0 ? ((amt / total) * 100).toFixed(1) + "%" : "-";
|
|
39
|
+
return {
|
|
40
|
+
category: String(r["category"] ?? "-"),
|
|
41
|
+
amount: formatAmount(String(amt)),
|
|
42
|
+
count: String(r["count"] ?? r["expenseCount"] ?? "-"),
|
|
43
|
+
pct,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const columns = [
|
|
48
|
+
{ key: "category", header: "Category", align: "left" as const },
|
|
49
|
+
{ key: "amount", header: "Amount ₹", align: "right" as const },
|
|
50
|
+
{ key: "count", header: "Count", align: "right" as const },
|
|
51
|
+
{ key: "pct", header: "% of Total", align: "right" as const },
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
if (opts.format === "tsv") {
|
|
55
|
+
outputTSV(rows, columns);
|
|
56
|
+
} else if (opts.format === "csv") {
|
|
57
|
+
outputCSV(rows, columns);
|
|
58
|
+
} else {
|
|
59
|
+
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Expenses by Category\n") + "\n");
|
|
60
|
+
else process.stdout.write("\n Expenses by Category\n\n");
|
|
61
|
+
outputTable(rows, columns);
|
|
62
|
+
if (total > 0) {
|
|
63
|
+
const totalStr = ` Total: ₹${formatAmount(String(total))}`;
|
|
64
|
+
process.stdout.write("\n" + (hasColor() ? chalk.bold(totalStr) : totalStr) + "\n");
|
|
65
|
+
}
|
|
66
|
+
process.stdout.write("\n");
|
|
67
|
+
}
|
|
68
|
+
} catch (e) {
|
|
69
|
+
if (e instanceof HisaaboApiError) {
|
|
70
|
+
const err = e.hisaaboError;
|
|
71
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
72
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
73
|
+
}
|
|
74
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, outputJSON, outputTable, EXIT, hasColor } from "../../output.js";
|
|
4
|
+
import { formatAmount, formatStatus, fyStart, todayISO, monthStart, monthEnd } from "../../format.js";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
|
|
7
|
+
interface InvoiceBreakdownOpts {
|
|
8
|
+
from?: string;
|
|
9
|
+
to?: string;
|
|
10
|
+
thisMonth?: boolean;
|
|
11
|
+
thisFy?: boolean;
|
|
12
|
+
json?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function dashboardInvoiceBreakdownCommand(opts: InvoiceBreakdownOpts): Promise<void> {
|
|
16
|
+
const cfg = requireAuth();
|
|
17
|
+
const client = new HisaaboClient(cfg);
|
|
18
|
+
|
|
19
|
+
let fromDate = opts.from;
|
|
20
|
+
let toDate = opts.to;
|
|
21
|
+
if (opts.thisMonth) { fromDate = monthStart(); toDate = monthEnd(); }
|
|
22
|
+
else if (opts.thisFy) { fromDate = fyStart(); toDate = todayISO(); }
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const data = await client.dashboard.invoiceStatusBreakdown({ fromDate, toDate });
|
|
26
|
+
|
|
27
|
+
if (opts.json) {
|
|
28
|
+
outputJSON(data);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// data may be an object like { draft: { count, amount }, sent: { count, amount }, ... }
|
|
33
|
+
// or an array of { status, count, amount }
|
|
34
|
+
const ORDER = ["draft", "sent", "partial", "paid", "overdue", "cancelled"];
|
|
35
|
+
|
|
36
|
+
let rows: Array<{ status: string; count: string; amount: string }>;
|
|
37
|
+
|
|
38
|
+
if (Array.isArray(data)) {
|
|
39
|
+
rows = data.map((r: Record<string, unknown>) => ({
|
|
40
|
+
status: formatStatus(String(r["status"] ?? "-")),
|
|
41
|
+
count: String(r["count"] ?? "-"),
|
|
42
|
+
amount: formatAmount(String(r["totalAmount"] ?? r["amount"] ?? "0")),
|
|
43
|
+
}));
|
|
44
|
+
} else if (data && typeof data === "object") {
|
|
45
|
+
const obj = data as Record<string, unknown>;
|
|
46
|
+
rows = ORDER.flatMap((status) => {
|
|
47
|
+
const entry = obj[status] as Record<string, unknown> | undefined;
|
|
48
|
+
if (!entry) return [];
|
|
49
|
+
return [{
|
|
50
|
+
status: formatStatus(status),
|
|
51
|
+
count: String(entry["count"] ?? "-"),
|
|
52
|
+
amount: formatAmount(String(entry["totalAmount"] ?? entry["amount"] ?? "0")),
|
|
53
|
+
}];
|
|
54
|
+
});
|
|
55
|
+
// Also include any statuses not in ORDER
|
|
56
|
+
for (const key of Object.keys(obj)) {
|
|
57
|
+
if (!ORDER.includes(key)) {
|
|
58
|
+
const entry = obj[key] as Record<string, unknown>;
|
|
59
|
+
rows.push({
|
|
60
|
+
status: formatStatus(key),
|
|
61
|
+
count: String(entry["count"] ?? "-"),
|
|
62
|
+
amount: formatAmount(String(entry["totalAmount"] ?? entry["amount"] ?? "0")),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
rows = [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const columns = [
|
|
71
|
+
{ key: "status", header: "Status", align: "left" as const },
|
|
72
|
+
{ key: "count", header: "Count", align: "right" as const },
|
|
73
|
+
{ key: "amount", header: "Amount ₹", align: "right" as const },
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Invoice Status Breakdown\n") + "\n");
|
|
77
|
+
else process.stdout.write("\n Invoice Status Breakdown\n\n");
|
|
78
|
+
outputTable(rows, columns);
|
|
79
|
+
process.stdout.write("\n");
|
|
80
|
+
|
|
81
|
+
} catch (e) {
|
|
82
|
+
if (e instanceof HisaaboApiError) {
|
|
83
|
+
const err = e.hisaaboError;
|
|
84
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
85
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
86
|
+
}
|
|
87
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, hasColor } from "../../output.js";
|
|
4
|
+
import { formatAmount } from "../../format.js";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
|
|
7
|
+
interface MonthlyComparisonOpts {
|
|
8
|
+
json?: boolean;
|
|
9
|
+
format?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function changeArrow(pct: number): string {
|
|
13
|
+
if (!hasColor()) return pct >= 0 ? `+${pct.toFixed(1)}%` : `${pct.toFixed(1)}%`;
|
|
14
|
+
if (pct > 0) return chalk.green(`▲ +${pct.toFixed(1)}%`);
|
|
15
|
+
if (pct < 0) return chalk.red(`▼ ${pct.toFixed(1)}%`);
|
|
16
|
+
return chalk.dim("─ 0.0%");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function pctChange(current: number, previous: number): number {
|
|
20
|
+
if (previous === 0) return current > 0 ? 100 : 0;
|
|
21
|
+
return ((current - previous) / Math.abs(previous)) * 100;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function dashboardMonthlyComparisonCommand(opts: MonthlyComparisonOpts): Promise<void> {
|
|
25
|
+
const cfg = requireAuth();
|
|
26
|
+
const client = new HisaaboClient(cfg);
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const data = await client.dashboard.monthlyComparison();
|
|
30
|
+
|
|
31
|
+
if (opts.json) {
|
|
32
|
+
outputJSON(data);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// data can be:
|
|
37
|
+
// 1. An array of monthly records: [{ month, year, sales, expenses, profit, collections, ... }]
|
|
38
|
+
// 2. An object: { current: {...}, previous: {...}, ... }
|
|
39
|
+
// 3. An object with month keys: { "2025-03": {...}, "2025-04": {...}, ... }
|
|
40
|
+
|
|
41
|
+
type MonthRecord = {
|
|
42
|
+
period: string;
|
|
43
|
+
sales: number;
|
|
44
|
+
expenses: number;
|
|
45
|
+
profit: number;
|
|
46
|
+
collections: number;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
let months: MonthRecord[] = [];
|
|
50
|
+
|
|
51
|
+
if (Array.isArray(data)) {
|
|
52
|
+
months = data.map((r: Record<string, unknown>) => {
|
|
53
|
+
const month = String(r["month"] ?? r["period"] ?? r["label"] ?? "-");
|
|
54
|
+
const year = r["year"] ? String(r["year"]) : "";
|
|
55
|
+
const period = year ? `${month} ${year}` : month;
|
|
56
|
+
return {
|
|
57
|
+
period,
|
|
58
|
+
sales: parseFloat(String(r["sales"] ?? r["totalSales"] ?? "0")),
|
|
59
|
+
expenses: parseFloat(String(r["expenses"] ?? r["totalExpenses"] ?? "0")),
|
|
60
|
+
profit: parseFloat(String(r["profit"] ?? r["netProfit"] ?? "0")),
|
|
61
|
+
collections: parseFloat(String(r["collections"] ?? r["totalCollections"] ?? "0")),
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
} else if (data && typeof data === "object") {
|
|
65
|
+
const obj = data as Record<string, unknown>;
|
|
66
|
+
// Try current/previous shape
|
|
67
|
+
if ("current" in obj || "previous" in obj) {
|
|
68
|
+
const cur = (obj["current"] ?? {}) as Record<string, unknown>;
|
|
69
|
+
const prev = (obj["previous"] ?? {}) as Record<string, unknown>;
|
|
70
|
+
months = [
|
|
71
|
+
{
|
|
72
|
+
period: "Previous Month",
|
|
73
|
+
sales: parseFloat(String(prev["sales"] ?? prev["totalSales"] ?? "0")),
|
|
74
|
+
expenses: parseFloat(String(prev["expenses"] ?? prev["totalExpenses"] ?? "0")),
|
|
75
|
+
profit: parseFloat(String(prev["profit"] ?? prev["netProfit"] ?? "0")),
|
|
76
|
+
collections: parseFloat(String(prev["collections"] ?? prev["totalCollections"] ?? "0")),
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
period: "Current Month",
|
|
80
|
+
sales: parseFloat(String(cur["sales"] ?? cur["totalSales"] ?? "0")),
|
|
81
|
+
expenses: parseFloat(String(cur["expenses"] ?? cur["totalExpenses"] ?? "0")),
|
|
82
|
+
profit: parseFloat(String(cur["profit"] ?? cur["netProfit"] ?? "0")),
|
|
83
|
+
collections: parseFloat(String(cur["collections"] ?? cur["totalCollections"] ?? "0")),
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
} else {
|
|
87
|
+
// Month-keyed object: sort chronologically
|
|
88
|
+
const entries = Object.entries(obj).sort(([a], [b]) => a.localeCompare(b));
|
|
89
|
+
months = entries.map(([period, val]) => {
|
|
90
|
+
const r = (val ?? {}) as Record<string, unknown>;
|
|
91
|
+
return {
|
|
92
|
+
period,
|
|
93
|
+
sales: parseFloat(String(r["sales"] ?? r["totalSales"] ?? "0")),
|
|
94
|
+
expenses: parseFloat(String(r["expenses"] ?? r["totalExpenses"] ?? "0")),
|
|
95
|
+
profit: parseFloat(String(r["profit"] ?? r["netProfit"] ?? "0")),
|
|
96
|
+
collections: parseFloat(String(r["collections"] ?? r["totalCollections"] ?? "0")),
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (opts.format === "tsv" || opts.format === "csv") {
|
|
103
|
+
const rows = months.map((m, i) => {
|
|
104
|
+
const prev = months[i - 1];
|
|
105
|
+
return {
|
|
106
|
+
period: m.period,
|
|
107
|
+
sales: formatAmount(m.sales),
|
|
108
|
+
salesChg: prev ? `${pctChange(m.sales, prev.sales).toFixed(1)}%` : "-",
|
|
109
|
+
expenses: formatAmount(m.expenses),
|
|
110
|
+
profit: formatAmount(m.profit),
|
|
111
|
+
collections: formatAmount(m.collections),
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
const columns = [
|
|
115
|
+
{ key: "period", header: "Month", align: "left" as const },
|
|
116
|
+
{ key: "sales", header: "Sales ₹", align: "right" as const },
|
|
117
|
+
{ key: "salesChg", header: "Sales Δ%", align: "right" as const },
|
|
118
|
+
{ key: "expenses", header: "Expenses ₹", align: "right" as const },
|
|
119
|
+
{ key: "profit", header: "Profit ₹", align: "right" as const },
|
|
120
|
+
{ key: "collections", header: "Collections ₹", align: "right" as const },
|
|
121
|
+
];
|
|
122
|
+
if (opts.format === "tsv") outputTSV(rows, columns);
|
|
123
|
+
else outputCSV(rows, columns);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Pretty table display
|
|
128
|
+
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Monthly Comparison\n") + "\n");
|
|
129
|
+
else process.stdout.write("\n Monthly Comparison\n\n");
|
|
130
|
+
|
|
131
|
+
// Show month-over-month change for last two months if we have >= 2
|
|
132
|
+
if (months.length >= 2) {
|
|
133
|
+
const last = months[months.length - 1]!;
|
|
134
|
+
const prev = months[months.length - 2]!;
|
|
135
|
+
const salesPct = pctChange(last.sales, prev.sales);
|
|
136
|
+
const expPct = pctChange(last.expenses, prev.expenses);
|
|
137
|
+
const profitPct = pctChange(last.profit, prev.profit);
|
|
138
|
+
const collPct = pctChange(last.collections, prev.collections);
|
|
139
|
+
|
|
140
|
+
process.stdout.write(` ${hasColor() ? chalk.dim("Month-over-month (latest vs previous)") : "Month-over-month (latest vs previous)"}\n\n`);
|
|
141
|
+
const summaryRows = [
|
|
142
|
+
{ metric: "Sales", current: formatAmount(last.sales), change: changeArrow(salesPct) },
|
|
143
|
+
{ metric: "Collections", current: formatAmount(last.collections), change: changeArrow(collPct) },
|
|
144
|
+
{ metric: "Expenses", current: formatAmount(last.expenses), change: changeArrow(-expPct) },
|
|
145
|
+
{ metric: "Profit", current: formatAmount(last.profit), change: changeArrow(profitPct) },
|
|
146
|
+
];
|
|
147
|
+
const summaryColumns = [
|
|
148
|
+
{ key: "metric", header: "Metric", align: "left" as const },
|
|
149
|
+
{ key: "current", header: "Latest ₹", align: "right" as const },
|
|
150
|
+
{ key: "change", header: "vs Prev", align: "right" as const },
|
|
151
|
+
];
|
|
152
|
+
outputTable(summaryRows, summaryColumns);
|
|
153
|
+
process.stdout.write("\n");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Full trend table
|
|
157
|
+
const rows = months.map((m, i) => {
|
|
158
|
+
const prev = months[i - 1];
|
|
159
|
+
const salesChg = prev ? changeArrow(pctChange(m.sales, prev.sales)) : "-";
|
|
160
|
+
const profitColor = m.profit >= 0
|
|
161
|
+
? (hasColor() ? chalk.green(formatAmount(m.profit)) : formatAmount(m.profit))
|
|
162
|
+
: (hasColor() ? chalk.red(formatAmount(m.profit)) : formatAmount(m.profit));
|
|
163
|
+
return {
|
|
164
|
+
period: m.period,
|
|
165
|
+
sales: formatAmount(m.sales),
|
|
166
|
+
salesChg,
|
|
167
|
+
expenses: formatAmount(m.expenses),
|
|
168
|
+
profit: profitColor,
|
|
169
|
+
collections: formatAmount(m.collections),
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const columns = [
|
|
174
|
+
{ key: "period", header: "Month", align: "left" as const },
|
|
175
|
+
{ key: "sales", header: "Sales ₹", align: "right" as const },
|
|
176
|
+
{ key: "salesChg", header: "Δ%", align: "right" as const },
|
|
177
|
+
{ key: "expenses", header: "Expenses ₹", align: "right" as const },
|
|
178
|
+
{ key: "profit", header: "Profit ₹", align: "right" as const },
|
|
179
|
+
{ key: "collections", header: "Collections ₹", align: "right" as const },
|
|
180
|
+
];
|
|
181
|
+
|
|
182
|
+
outputTable(rows, columns);
|
|
183
|
+
process.stdout.write("\n");
|
|
184
|
+
|
|
185
|
+
} catch (e) {
|
|
186
|
+
if (e instanceof HisaaboApiError) {
|
|
187
|
+
const err = e.hisaaboError;
|
|
188
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
189
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
190
|
+
}
|
|
191
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, hasColor } from "../../output.js";
|
|
4
|
+
import { formatAmount, fyStart, todayISO, monthStart, monthEnd } from "../../format.js";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
|
|
7
|
+
interface PaymentModesOpts {
|
|
8
|
+
from?: string;
|
|
9
|
+
to?: string;
|
|
10
|
+
thisMonth?: boolean;
|
|
11
|
+
thisFy?: boolean;
|
|
12
|
+
json?: boolean;
|
|
13
|
+
format?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const MODE_LABELS: Record<string, string> = {
|
|
17
|
+
cash: "Cash",
|
|
18
|
+
upi: "UPI",
|
|
19
|
+
bank_transfer: "Bank Transfer",
|
|
20
|
+
cheque: "Cheque",
|
|
21
|
+
card: "Card",
|
|
22
|
+
neft: "NEFT",
|
|
23
|
+
rtgs: "RTGS",
|
|
24
|
+
imps: "IMPS",
|
|
25
|
+
dd: "Demand Draft",
|
|
26
|
+
credit: "Credit",
|
|
27
|
+
other: "Other",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function modeLabel(raw: string): string {
|
|
31
|
+
return MODE_LABELS[raw.toLowerCase()] ?? raw;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function dashboardPaymentModesCommand(opts: PaymentModesOpts): Promise<void> {
|
|
35
|
+
const cfg = requireAuth();
|
|
36
|
+
const client = new HisaaboClient(cfg);
|
|
37
|
+
|
|
38
|
+
let fromDate = opts.from;
|
|
39
|
+
let toDate = opts.to;
|
|
40
|
+
if (opts.thisMonth) { fromDate = monthStart(); toDate = monthEnd(); }
|
|
41
|
+
else if (opts.thisFy) { fromDate = fyStart(); toDate = todayISO(); }
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const data = await client.dashboard.paymentModeBreakdown({ fromDate, toDate });
|
|
45
|
+
|
|
46
|
+
if (opts.json) {
|
|
47
|
+
outputJSON(data);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// data can be an array of { mode, amount, count } or an object keyed by mode
|
|
52
|
+
type ModeRow = { mode: string; amount: number; count: number };
|
|
53
|
+
let modes: ModeRow[] = [];
|
|
54
|
+
|
|
55
|
+
if (Array.isArray(data)) {
|
|
56
|
+
modes = data.map((r: Record<string, unknown>) => ({
|
|
57
|
+
mode: String(r["mode"] ?? r["paymentMode"] ?? r["method"] ?? "-"),
|
|
58
|
+
amount: parseFloat(String(r["amount"] ?? r["totalAmount"] ?? "0")),
|
|
59
|
+
count: parseInt(String(r["count"] ?? r["paymentCount"] ?? "0"), 10),
|
|
60
|
+
}));
|
|
61
|
+
} else if (data && typeof data === "object") {
|
|
62
|
+
const obj = data as Record<string, unknown>;
|
|
63
|
+
for (const [key, val] of Object.entries(obj)) {
|
|
64
|
+
if (typeof val === "object" && val !== null) {
|
|
65
|
+
const entry = val as Record<string, unknown>;
|
|
66
|
+
modes.push({
|
|
67
|
+
mode: key,
|
|
68
|
+
amount: parseFloat(String(entry["amount"] ?? entry["totalAmount"] ?? "0")),
|
|
69
|
+
count: parseInt(String(entry["count"] ?? "0"), 10),
|
|
70
|
+
});
|
|
71
|
+
} else if (typeof val === "string" || typeof val === "number") {
|
|
72
|
+
modes.push({ mode: key, amount: parseFloat(String(val)), count: 0 });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Sort descending by amount
|
|
78
|
+
modes.sort((a, b) => b.amount - a.amount);
|
|
79
|
+
|
|
80
|
+
const total = modes.reduce((s, r) => s + r.amount, 0);
|
|
81
|
+
|
|
82
|
+
const rows = modes.map((r) => {
|
|
83
|
+
const pct = total > 0 ? ((r.amount / total) * 100).toFixed(1) + "%" : "-";
|
|
84
|
+
return {
|
|
85
|
+
mode: modeLabel(r.mode),
|
|
86
|
+
amount: formatAmount(r.amount),
|
|
87
|
+
count: r.count > 0 ? String(r.count) : "-",
|
|
88
|
+
pct,
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const columns = [
|
|
93
|
+
{ key: "mode", header: "Payment Mode", align: "left" as const },
|
|
94
|
+
{ key: "amount", header: "Amount ₹", align: "right" as const },
|
|
95
|
+
{ key: "count", header: "Count", align: "right" as const },
|
|
96
|
+
{ key: "pct", header: "% of Total", align: "right" as const },
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
if (opts.format === "tsv") {
|
|
100
|
+
outputTSV(rows, columns);
|
|
101
|
+
} else if (opts.format === "csv") {
|
|
102
|
+
outputCSV(rows, columns);
|
|
103
|
+
} else {
|
|
104
|
+
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Payment Mode Breakdown\n") + "\n");
|
|
105
|
+
else process.stdout.write("\n Payment Mode Breakdown\n\n");
|
|
106
|
+
outputTable(rows, columns);
|
|
107
|
+
if (total > 0) {
|
|
108
|
+
const totalStr = ` Total: ₹${formatAmount(total)}`;
|
|
109
|
+
process.stdout.write("\n" + (hasColor() ? chalk.bold(totalStr) : totalStr) + "\n");
|
|
110
|
+
}
|
|
111
|
+
process.stdout.write("\n");
|
|
112
|
+
}
|
|
113
|
+
} catch (e) {
|
|
114
|
+
if (e instanceof HisaaboApiError) {
|
|
115
|
+
const err = e.hisaaboError;
|
|
116
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
117
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
118
|
+
}
|
|
119
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
120
|
+
}
|
|
121
|
+
}
|