@hisaabo/cli 0.1.0 → 0.3.2
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/README.md +332 -0
- package/dist/bin/audit-trail-2YGXGUXW.js +78 -0
- package/dist/bin/categories-P5VFWD5F.js +47 -0
- package/dist/bin/check-slug-4TMOTWUJ.js +65 -0
- package/dist/bin/chunk-2P35S2C3.js +46 -0
- package/dist/bin/chunk-EYNDY7RB.js +175 -0
- package/dist/bin/chunk-FFBG6RU4.js +156 -0
- package/dist/bin/chunk-FTOBDKMO.js +804 -0
- package/dist/bin/client-QNJ2H5CW.js +11 -0
- package/dist/bin/collection-efficiency-WMKEGS6U.js +165 -0
- package/dist/bin/config-UKVQYPPR.js +18 -0
- package/dist/bin/create-Y22FAVOW.js +83 -0
- package/dist/bin/default-account-SA56M66A.js +58 -0
- package/dist/bin/expenses-VZAOLYUW.js +89 -0
- package/dist/bin/export-QZ6WT6PJ.js +59 -0
- package/dist/bin/factory-2DCU3B5T.js +483 -0
- package/dist/bin/get-6UYP6UVD.js +71 -0
- package/dist/bin/get-EXL44I2X.js +66 -0
- package/dist/bin/hisaabo.js +2029 -1450
- package/dist/bin/invite-O26SAL72.js +53 -0
- package/dist/bin/invoice-breakdown-XEATXVMR.js +97 -0
- package/dist/bin/items-3U5USBVG.js +62 -0
- package/dist/bin/items-toggle-YEKMI2CM.js +46 -0
- package/dist/bin/list-FX2C3NCL.js +46 -0
- package/dist/bin/list-VBAHY72W.js +79 -0
- package/dist/bin/members-5FPRUAB6.js +55 -0
- package/dist/bin/monthly-comparison-JEJ3TTY2.js +176 -0
- package/dist/bin/order-cancel-XI2LKYXV.js +55 -0
- package/dist/bin/order-confirm-HUFCU6MO.js +53 -0
- package/dist/bin/order-get-NSDMPUZR.js +88 -0
- package/dist/bin/order-update-C7QYSD5R.js +60 -0
- package/dist/bin/output-QFLEKG5W.js +35 -0
- package/dist/bin/payment-modes-WI3AWSES.js +126 -0
- package/dist/bin/profit-loss-5RIEOBKP.js +135 -0
- package/dist/bin/receivables-aging-L6DIQCNE.js +161 -0
- package/dist/bin/remove-M2B4TZ37.js +52 -0
- package/dist/bin/revoke-H3V2GNCD.js +52 -0
- package/dist/bin/sales-trend-TICB3KGF.js +71 -0
- package/dist/bin/sequence-XUD6FAKY.js +66 -0
- package/dist/bin/store-UQ2DDQ5I.js +82 -0
- package/dist/bin/summary-BPNFC7I2.js +113 -0
- package/dist/bin/top-customers-WGGJWKCN.js +81 -0
- package/dist/bin/top-items-C7ZDDJMR.js +84 -0
- package/dist/bin/top-outstanding-MOGWJIQS.js +64 -0
- package/dist/bin/unpaid-invoices-ZUPNMQJP.js +65 -0
- package/dist/bin/untracked-BCJEVDW4.js +67 -0
- package/dist/bin/update-HIU4PANX.js +54 -0
- package/dist/bin/update-IG565YIN.js +61 -0
- package/dist/bin/update-PVLAX7T3.js +57 -0
- package/dist/bin/update-role-Q4ZYJRYT.js +45 -0
- package/dist/bin/update-settings-XPC6L5WM.js +56 -0
- package/package.json +6 -1
- package/src/bin/hisaabo.ts +42 -933
- package/src/bin/registrars/api-key.ts +44 -0
- package/src/bin/registrars/auth.ts +153 -0
- package/src/bin/registrars/automated-invoice.ts +167 -0
- package/src/bin/registrars/bank.ts +90 -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/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 +55 -0
- package/src/client.ts +495 -4
- 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/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/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/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/update-role.ts +41 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
formatAmount,
|
|
4
|
+
fyStart,
|
|
5
|
+
monthEnd,
|
|
6
|
+
monthStart,
|
|
7
|
+
todayISO
|
|
8
|
+
} from "./chunk-FFBG6RU4.js";
|
|
9
|
+
import {
|
|
10
|
+
HisaaboApiError,
|
|
11
|
+
HisaaboClient
|
|
12
|
+
} from "./chunk-FTOBDKMO.js";
|
|
13
|
+
import {
|
|
14
|
+
requireAuth
|
|
15
|
+
} from "./chunk-2P35S2C3.js";
|
|
16
|
+
import {
|
|
17
|
+
EXIT,
|
|
18
|
+
fatalError,
|
|
19
|
+
hasColor,
|
|
20
|
+
outputCSV,
|
|
21
|
+
outputJSON,
|
|
22
|
+
outputTSV,
|
|
23
|
+
outputTable,
|
|
24
|
+
termWidth
|
|
25
|
+
} from "./chunk-EYNDY7RB.js";
|
|
26
|
+
|
|
27
|
+
// src/commands/dashboard/collection-efficiency.ts
|
|
28
|
+
import chalk from "chalk";
|
|
29
|
+
function rateBar(rate, width) {
|
|
30
|
+
const clamped = Math.min(100, Math.max(0, rate));
|
|
31
|
+
const filled = Math.round(clamped / 100 * width);
|
|
32
|
+
const bar = "\u2588".repeat(filled) + "\u2591".repeat(width - filled);
|
|
33
|
+
if (!hasColor()) return bar;
|
|
34
|
+
if (clamped >= 80) return chalk.green(bar);
|
|
35
|
+
if (clamped >= 50) return chalk.yellow(bar);
|
|
36
|
+
return chalk.red(bar);
|
|
37
|
+
}
|
|
38
|
+
async function dashboardCollectionEfficiencyCommand(opts) {
|
|
39
|
+
const cfg = requireAuth();
|
|
40
|
+
const client = new HisaaboClient(cfg);
|
|
41
|
+
let fromDate = opts.from;
|
|
42
|
+
let toDate = opts.to;
|
|
43
|
+
if (opts.thisMonth) {
|
|
44
|
+
fromDate = monthStart();
|
|
45
|
+
toDate = monthEnd();
|
|
46
|
+
} else if (opts.thisFy) {
|
|
47
|
+
fromDate = fyStart();
|
|
48
|
+
toDate = todayISO();
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const data = await client.dashboard.collectionEfficiency({ fromDate, toDate });
|
|
52
|
+
if (opts.json) {
|
|
53
|
+
outputJSON(data);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const d = data ?? {};
|
|
57
|
+
const totalInvoiced = parseFloat(String(d["totalInvoiced"] ?? d["invoiced"] ?? d["billed"] ?? "0"));
|
|
58
|
+
const totalCollected = parseFloat(String(d["totalCollected"] ?? d["collected"] ?? d["received"] ?? "0"));
|
|
59
|
+
const outstanding = parseFloat(String(d["outstanding"] ?? d["totalOutstanding"] ?? String(totalInvoiced - totalCollected)));
|
|
60
|
+
const collectionRate = parseFloat(String(d["collectionRate"] ?? d["rate"] ?? (totalInvoiced > 0 ? (totalCollected / totalInvoiced * 100).toFixed(2) : "0")));
|
|
61
|
+
const dso = parseFloat(String(d["dso"] ?? d["daysSalesOutstanding"] ?? "0"));
|
|
62
|
+
const aging = d["aging"] ?? d["agingBreakdown"] ?? d["breakdown"] ?? null;
|
|
63
|
+
if (opts.format === "tsv" || opts.format === "csv") {
|
|
64
|
+
const rows = [
|
|
65
|
+
{ metric: "Total Invoiced", value: formatAmount(totalInvoiced) },
|
|
66
|
+
{ metric: "Total Collected", value: formatAmount(totalCollected) },
|
|
67
|
+
{ metric: "Outstanding", value: formatAmount(outstanding) },
|
|
68
|
+
{ metric: "Collection Rate", value: `${collectionRate.toFixed(1)}%` },
|
|
69
|
+
{ metric: "DSO (days)", value: dso > 0 ? String(Math.round(dso)) : "-" }
|
|
70
|
+
];
|
|
71
|
+
if (aging) {
|
|
72
|
+
for (const [k, v] of Object.entries(aging)) {
|
|
73
|
+
rows.push({ metric: `Aging: ${k}`, value: formatAmount(String(v)) });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const columns = [
|
|
77
|
+
{ key: "metric", header: "Metric", align: "left" },
|
|
78
|
+
{ key: "value", header: "Value", align: "right" }
|
|
79
|
+
];
|
|
80
|
+
if (opts.format === "tsv") outputTSV(rows, columns);
|
|
81
|
+
else outputCSV(rows, columns);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const width = Math.min(termWidth() - 4, 56);
|
|
85
|
+
const innerW = width - 2;
|
|
86
|
+
const barW = Math.max(8, innerW - 22);
|
|
87
|
+
const line = (label, value, opts2 = {}) => {
|
|
88
|
+
const lbl = label.padEnd(20).slice(0, 20);
|
|
89
|
+
const val = value.padStart(innerW - 22).slice(0, innerW - 22);
|
|
90
|
+
let out = ` \u2502 ${lbl} ${val} \u2502`;
|
|
91
|
+
if (hasColor()) {
|
|
92
|
+
if (opts2.bold) out = ` \u2502 ${chalk.bold(lbl)} ${val} \u2502`;
|
|
93
|
+
if (opts2.color) out = ` \u2502 ${opts2.bold ? chalk.bold(lbl) : lbl} ${opts2.color(val)} \u2502`;
|
|
94
|
+
}
|
|
95
|
+
process.stdout.write(out + "\n");
|
|
96
|
+
};
|
|
97
|
+
const sep = () => {
|
|
98
|
+
process.stdout.write(" \u251C" + "\u2500".repeat(innerW) + "\u2524\n");
|
|
99
|
+
};
|
|
100
|
+
process.stdout.write("\n");
|
|
101
|
+
if (hasColor()) process.stdout.write(" " + chalk.bold("Collection Efficiency") + "\n\n");
|
|
102
|
+
else process.stdout.write(" Collection Efficiency\n\n");
|
|
103
|
+
process.stdout.write(" \u250C" + "\u2500".repeat(innerW) + "\u2510\n");
|
|
104
|
+
line("Total Invoiced", `\u20B9${formatAmount(totalInvoiced)}`, { bold: true });
|
|
105
|
+
line("Total Collected", `\u20B9${formatAmount(totalCollected)}`, {
|
|
106
|
+
color: totalCollected >= totalInvoiced * 0.8 ? chalk.green : chalk.yellow
|
|
107
|
+
});
|
|
108
|
+
line("Outstanding", `\u20B9${formatAmount(outstanding)}`, {
|
|
109
|
+
color: outstanding > 0 ? chalk.red : chalk.green
|
|
110
|
+
});
|
|
111
|
+
sep();
|
|
112
|
+
const rateStr = `${collectionRate.toFixed(1)}%`;
|
|
113
|
+
const bar = rateBar(collectionRate, barW);
|
|
114
|
+
const rateLabel = "Collection Rate".padEnd(20).slice(0, 20);
|
|
115
|
+
process.stdout.write(` \u2502 ${hasColor() ? chalk.bold(rateLabel) : rateLabel} ${bar} ${rateStr.padStart(6)} \u2502
|
|
116
|
+
`);
|
|
117
|
+
if (dso > 0) {
|
|
118
|
+
const dsoStr = `${Math.round(dso)} days`;
|
|
119
|
+
const dsoLabel = "DSO".padEnd(20).slice(0, 20);
|
|
120
|
+
const dsoColor = dso <= 30 ? chalk.green : dso <= 60 ? chalk.yellow : chalk.red;
|
|
121
|
+
const dsoVal = hasColor() ? dsoColor(dsoStr) : dsoStr;
|
|
122
|
+
process.stdout.write(` \u2502 ${dsoLabel} ${dsoVal.padStart(innerW - 22)} \u2502
|
|
123
|
+
`);
|
|
124
|
+
}
|
|
125
|
+
if (aging && Object.keys(aging).length > 0) {
|
|
126
|
+
sep();
|
|
127
|
+
process.stdout.write(` \u2502 ${hasColor() ? chalk.bold("Aging Breakdown") : "Aging Breakdown"}${" ".repeat(innerW - 16)} \u2502
|
|
128
|
+
`);
|
|
129
|
+
const agingEntries = Object.entries(aging);
|
|
130
|
+
for (const [bucket, val] of agingEntries) {
|
|
131
|
+
const amt = parseFloat(String(val));
|
|
132
|
+
const amtStr = `\u20B9${formatAmount(amt)}`;
|
|
133
|
+
const bucketLabel = bucket.padEnd(20).slice(0, 20);
|
|
134
|
+
const isOld = /90\+|90_plus/i.test(bucket);
|
|
135
|
+
const color = isOld ? chalk.red : /31|61/.test(bucket) ? chalk.yellow : void 0;
|
|
136
|
+
const valStr = color && hasColor() ? color(amtStr) : amtStr;
|
|
137
|
+
process.stdout.write(` \u2502 ${bucketLabel.slice(0, 18)} ${valStr.padStart(innerW - 22)} \u2502
|
|
138
|
+
`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
process.stdout.write(" \u2514" + "\u2500".repeat(innerW) + "\u2518\n\n");
|
|
142
|
+
if (aging && Object.keys(aging).length > 0) {
|
|
143
|
+
const agingRows = Object.entries(aging).map(([bucket, val]) => ({
|
|
144
|
+
bucket,
|
|
145
|
+
amount: formatAmount(String(val))
|
|
146
|
+
}));
|
|
147
|
+
const agingColumns = [
|
|
148
|
+
{ key: "bucket", header: "Aging Bucket", align: "left" },
|
|
149
|
+
{ key: "amount", header: "Amount \u20B9", align: "right" }
|
|
150
|
+
];
|
|
151
|
+
outputTable(agingRows, agingColumns);
|
|
152
|
+
process.stdout.write("\n");
|
|
153
|
+
}
|
|
154
|
+
} catch (e) {
|
|
155
|
+
if (e instanceof HisaaboApiError) {
|
|
156
|
+
const err = e.hisaaboError;
|
|
157
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
158
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
159
|
+
}
|
|
160
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export {
|
|
164
|
+
dashboardCollectionEfficiencyCommand
|
|
165
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
clearConfig,
|
|
4
|
+
getConfig,
|
|
5
|
+
getConfigPath,
|
|
6
|
+
isAuthenticated,
|
|
7
|
+
requireAuth,
|
|
8
|
+
setConfig
|
|
9
|
+
} from "./chunk-2P35S2C3.js";
|
|
10
|
+
import "./chunk-EYNDY7RB.js";
|
|
11
|
+
export {
|
|
12
|
+
clearConfig,
|
|
13
|
+
getConfig,
|
|
14
|
+
getConfigPath,
|
|
15
|
+
isAuthenticated,
|
|
16
|
+
requireAuth,
|
|
17
|
+
setConfig
|
|
18
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
HisaaboApiError,
|
|
4
|
+
HisaaboClient
|
|
5
|
+
} from "./chunk-FTOBDKMO.js";
|
|
6
|
+
import {
|
|
7
|
+
requireAuth
|
|
8
|
+
} from "./chunk-2P35S2C3.js";
|
|
9
|
+
import {
|
|
10
|
+
EXIT,
|
|
11
|
+
fatalError,
|
|
12
|
+
hasColor,
|
|
13
|
+
outputJSON
|
|
14
|
+
} from "./chunk-EYNDY7RB.js";
|
|
15
|
+
|
|
16
|
+
// src/commands/api-key/create.ts
|
|
17
|
+
import chalk from "chalk";
|
|
18
|
+
async function apiKeyCreateCommand(opts) {
|
|
19
|
+
const cfg = requireAuth();
|
|
20
|
+
const client = new HisaaboClient(cfg);
|
|
21
|
+
if (!opts.name || opts.name.trim().length === 0) {
|
|
22
|
+
fatalError("--name is required.", EXIT.USAGE);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const result = await client.apiKey.create({ name: opts.name.trim() });
|
|
26
|
+
if (opts.json) {
|
|
27
|
+
outputJSON(result);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const key = String(result?.key ?? result?.apiKey ?? result?.token ?? "");
|
|
31
|
+
const id = String(result?.id ?? "");
|
|
32
|
+
if (hasColor()) {
|
|
33
|
+
process.stdout.write("\n");
|
|
34
|
+
process.stdout.write(chalk.bold.green(" \u2713 API key created successfully!\n"));
|
|
35
|
+
process.stdout.write("\n");
|
|
36
|
+
process.stdout.write(chalk.bold.yellow(" \u26A0 IMPORTANT: Copy this key now \u2014 it will NOT be shown again.\n"));
|
|
37
|
+
process.stdout.write("\n");
|
|
38
|
+
if (key) {
|
|
39
|
+
process.stdout.write(" " + chalk.bold("Your API key:") + "\n");
|
|
40
|
+
process.stdout.write("\n");
|
|
41
|
+
process.stdout.write(" " + chalk.cyan.bold(key) + "\n");
|
|
42
|
+
process.stdout.write("\n");
|
|
43
|
+
}
|
|
44
|
+
process.stdout.write(chalk.dim(" Use it with: hisaabo login --token <key>\n"));
|
|
45
|
+
process.stdout.write(chalk.dim(" Or set env: HISAABO_TOKEN=" + (key ? key : "<key>") + "\n"));
|
|
46
|
+
if (id) process.stdout.write(chalk.dim(`
|
|
47
|
+
Key ID: ${id}
|
|
48
|
+
`));
|
|
49
|
+
process.stdout.write("\n");
|
|
50
|
+
} else {
|
|
51
|
+
process.stdout.write("\nAPI key created successfully!\n\n");
|
|
52
|
+
process.stdout.write("IMPORTANT: Copy this key now \u2014 it will NOT be shown again.\n\n");
|
|
53
|
+
if (key) {
|
|
54
|
+
process.stdout.write(`Your API key:
|
|
55
|
+
|
|
56
|
+
${key}
|
|
57
|
+
|
|
58
|
+
`);
|
|
59
|
+
process.stdout.write(`Usage: hisaabo login --token ${key}
|
|
60
|
+
`);
|
|
61
|
+
}
|
|
62
|
+
if (id) process.stdout.write(`Key ID: ${id}
|
|
63
|
+
`);
|
|
64
|
+
process.stdout.write("\n");
|
|
65
|
+
}
|
|
66
|
+
} catch (e) {
|
|
67
|
+
if (e instanceof HisaaboApiError) {
|
|
68
|
+
const err = e.hisaaboError;
|
|
69
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
70
|
+
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
71
|
+
if (err.code === "validation_failed") {
|
|
72
|
+
const msgs = Object.entries(err.fields).map(([f, ms]) => ` ${f}: ${ms.join(", ")}`).join("\n");
|
|
73
|
+
fatalError(`Validation failed:
|
|
74
|
+
${msgs}`, EXIT.VALIDATION);
|
|
75
|
+
}
|
|
76
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
77
|
+
}
|
|
78
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
apiKeyCreateCommand
|
|
83
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
HisaaboApiError,
|
|
4
|
+
HisaaboClient
|
|
5
|
+
} from "./chunk-FTOBDKMO.js";
|
|
6
|
+
import {
|
|
7
|
+
requireAuth
|
|
8
|
+
} from "./chunk-2P35S2C3.js";
|
|
9
|
+
import {
|
|
10
|
+
EXIT,
|
|
11
|
+
fatalError,
|
|
12
|
+
outputJSON
|
|
13
|
+
} from "./chunk-EYNDY7RB.js";
|
|
14
|
+
|
|
15
|
+
// src/commands/payment/default-account.ts
|
|
16
|
+
async function paymentDefaultAccountCommand(opts) {
|
|
17
|
+
const cfg = requireAuth();
|
|
18
|
+
const client = new HisaaboClient(cfg);
|
|
19
|
+
try {
|
|
20
|
+
const input = opts.partyId ? { partyId: opts.partyId } : void 0;
|
|
21
|
+
const result = await client.payment.defaultAccount(input);
|
|
22
|
+
if (opts.json) {
|
|
23
|
+
outputJSON(result);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (!result) {
|
|
27
|
+
console.log("\n No recommended bank account found.\n");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const sep = "\u2500".repeat(48);
|
|
31
|
+
console.log(`
|
|
32
|
+
Recommended Bank Account`);
|
|
33
|
+
console.log(` ${sep}`);
|
|
34
|
+
if (typeof result === "object" && result !== null) {
|
|
35
|
+
const acct = result;
|
|
36
|
+
if (acct["id"]) console.log(` ID : ${acct["id"]}`);
|
|
37
|
+
if (acct["accountName"]) console.log(` Account : ${acct["accountName"]}`);
|
|
38
|
+
if (acct["bankName"]) console.log(` Bank : ${acct["bankName"]}`);
|
|
39
|
+
if (acct["accountNumber"]) console.log(` Number : ${acct["accountNumber"]}`);
|
|
40
|
+
if (acct["ifsc"]) console.log(` IFSC : ${acct["ifsc"]}`);
|
|
41
|
+
} else {
|
|
42
|
+
console.log(` ${String(result)}`);
|
|
43
|
+
}
|
|
44
|
+
console.log();
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if (e instanceof HisaaboApiError) {
|
|
47
|
+
const err = e.hisaaboError;
|
|
48
|
+
if (err.code === "not_found") fatalError("No bank account configured.", EXIT.NOT_FOUND);
|
|
49
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
50
|
+
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
51
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
52
|
+
}
|
|
53
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
paymentDefaultAccountCommand
|
|
58
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
formatAmount,
|
|
4
|
+
fyStart,
|
|
5
|
+
monthEnd,
|
|
6
|
+
monthStart,
|
|
7
|
+
todayISO
|
|
8
|
+
} from "./chunk-FFBG6RU4.js";
|
|
9
|
+
import {
|
|
10
|
+
HisaaboApiError,
|
|
11
|
+
HisaaboClient
|
|
12
|
+
} from "./chunk-FTOBDKMO.js";
|
|
13
|
+
import {
|
|
14
|
+
requireAuth
|
|
15
|
+
} from "./chunk-2P35S2C3.js";
|
|
16
|
+
import {
|
|
17
|
+
EXIT,
|
|
18
|
+
fatalError,
|
|
19
|
+
hasColor,
|
|
20
|
+
outputCSV,
|
|
21
|
+
outputJSON,
|
|
22
|
+
outputTSV,
|
|
23
|
+
outputTable
|
|
24
|
+
} from "./chunk-EYNDY7RB.js";
|
|
25
|
+
|
|
26
|
+
// src/commands/dashboard/expenses.ts
|
|
27
|
+
import chalk from "chalk";
|
|
28
|
+
async function dashboardExpensesCommand(opts) {
|
|
29
|
+
const cfg = requireAuth();
|
|
30
|
+
const client = new HisaaboClient(cfg);
|
|
31
|
+
let fromDate = opts.from;
|
|
32
|
+
let toDate = opts.to;
|
|
33
|
+
if (opts.thisMonth) {
|
|
34
|
+
fromDate = monthStart();
|
|
35
|
+
toDate = monthEnd();
|
|
36
|
+
} else if (opts.thisFy) {
|
|
37
|
+
fromDate = fyStart();
|
|
38
|
+
toDate = todayISO();
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const data = await client.dashboard.expensesByCategory({ fromDate, toDate });
|
|
42
|
+
if (opts.json) {
|
|
43
|
+
outputJSON(data);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const items = Array.isArray(data) ? data : [];
|
|
47
|
+
const total = items.reduce((sum, r) => sum + parseFloat(String(r["totalAmount"] ?? r["amount"] ?? "0")), 0);
|
|
48
|
+
const rows = items.map((r) => {
|
|
49
|
+
const amt = parseFloat(String(r["totalAmount"] ?? r["amount"] ?? "0"));
|
|
50
|
+
const pct = total > 0 ? (amt / total * 100).toFixed(1) + "%" : "-";
|
|
51
|
+
return {
|
|
52
|
+
category: String(r["category"] ?? "-"),
|
|
53
|
+
amount: formatAmount(String(amt)),
|
|
54
|
+
count: String(r["count"] ?? r["expenseCount"] ?? "-"),
|
|
55
|
+
pct
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
const columns = [
|
|
59
|
+
{ key: "category", header: "Category", align: "left" },
|
|
60
|
+
{ key: "amount", header: "Amount \u20B9", align: "right" },
|
|
61
|
+
{ key: "count", header: "Count", align: "right" },
|
|
62
|
+
{ key: "pct", header: "% of Total", align: "right" }
|
|
63
|
+
];
|
|
64
|
+
if (opts.format === "tsv") {
|
|
65
|
+
outputTSV(rows, columns);
|
|
66
|
+
} else if (opts.format === "csv") {
|
|
67
|
+
outputCSV(rows, columns);
|
|
68
|
+
} else {
|
|
69
|
+
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Expenses by Category\n") + "\n");
|
|
70
|
+
else process.stdout.write("\n Expenses by Category\n\n");
|
|
71
|
+
outputTable(rows, columns);
|
|
72
|
+
if (total > 0) {
|
|
73
|
+
const totalStr = ` Total: \u20B9${formatAmount(String(total))}`;
|
|
74
|
+
process.stdout.write("\n" + (hasColor() ? chalk.bold(totalStr) : totalStr) + "\n");
|
|
75
|
+
}
|
|
76
|
+
process.stdout.write("\n");
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
if (e instanceof HisaaboApiError) {
|
|
80
|
+
const err = e.hisaaboError;
|
|
81
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
82
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
83
|
+
}
|
|
84
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
dashboardExpensesCommand
|
|
89
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
HisaaboApiError,
|
|
4
|
+
HisaaboClient
|
|
5
|
+
} from "./chunk-FTOBDKMO.js";
|
|
6
|
+
import {
|
|
7
|
+
requireAuth
|
|
8
|
+
} from "./chunk-2P35S2C3.js";
|
|
9
|
+
import {
|
|
10
|
+
EXIT,
|
|
11
|
+
fatalError,
|
|
12
|
+
outputJSON,
|
|
13
|
+
success
|
|
14
|
+
} from "./chunk-EYNDY7RB.js";
|
|
15
|
+
|
|
16
|
+
// src/commands/business/export.ts
|
|
17
|
+
import * as readline from "readline";
|
|
18
|
+
async function businessExportCommand(opts) {
|
|
19
|
+
const cfg = requireAuth();
|
|
20
|
+
const client = new HisaaboClient(cfg);
|
|
21
|
+
if (!opts.yes && process.stdin.isTTY) {
|
|
22
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
23
|
+
const answer = await new Promise((resolve) => {
|
|
24
|
+
rl.question(" Export all business data? This may take a moment. (y/N): ", resolve);
|
|
25
|
+
});
|
|
26
|
+
rl.close();
|
|
27
|
+
if (answer.trim().toLowerCase() !== "y") {
|
|
28
|
+
console.log(" Cancelled.");
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const result = await client.business.exportData();
|
|
34
|
+
if (opts.json) {
|
|
35
|
+
outputJSON(result);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (result?.url) {
|
|
39
|
+
success("Export complete.");
|
|
40
|
+
process.stdout.write(` Download URL: ${result.url}
|
|
41
|
+
`);
|
|
42
|
+
} else if (result?.status === "processing" || result?.queued) {
|
|
43
|
+
success("Export queued. You will be notified when the export is ready.");
|
|
44
|
+
} else {
|
|
45
|
+
success("Export initiated successfully.");
|
|
46
|
+
}
|
|
47
|
+
} catch (e) {
|
|
48
|
+
if (e instanceof HisaaboApiError) {
|
|
49
|
+
const err = e.hisaaboError;
|
|
50
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
51
|
+
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
52
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
53
|
+
}
|
|
54
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
businessExportCommand
|
|
59
|
+
};
|