@hisaabo/cli 0.7.5 → 0.8.4
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/LICENSE +31 -0
- package/README.md +9 -0
- package/dist/bin/{audit-trail-DLSSSM4T.js → audit-trail-IJ6SKACR.js} +2 -2
- package/dist/bin/{categories-63QR6WCV.js → categories-O6TODPAH.js} +2 -2
- package/dist/bin/{check-slug-NXO55WKH.js → check-slug-P7RFU6OP.js} +2 -2
- package/dist/bin/chunk-NO4FIFMS.js +0 -0
- package/dist/bin/{chunk-7MJDOL6B.js → chunk-QUITS2FE.js} +28 -0
- package/dist/bin/{chunk-M42SETRZ.js → chunk-WDN7RIE3.js} +23 -2
- package/dist/bin/chunk-ZPYC767N.js +0 -0
- package/dist/bin/{client-T32CIZA3.js → client-36JX5MR3.js} +1 -1
- package/dist/bin/{collection-efficiency-T6PWNTZO.js → collection-efficiency-DA5RWG3V.js} +2 -2
- package/dist/bin/{config-V4QFCONN.js → config-4LLNT4SH.js} +3 -1
- package/dist/bin/{create-NUKHDWLK.js → create-C5INBPQO.js} +2 -2
- package/dist/bin/{default-account-JWFPHMRF.js → default-account-2GMQ7ZA4.js} +2 -2
- package/dist/bin/{expenses-2UWUZVLI.js → expenses-S2YVA5UT.js} +2 -2
- package/dist/bin/{export-XSX7WQH7.js → export-YOOODNVX.js} +2 -2
- package/dist/bin/export-ZA43MLWO.js +191 -0
- package/dist/bin/{factory-BWOKRIP4.js → factory-6MUCSXTL.js} +2 -2
- package/dist/bin/{get-CHNTG3IM.js → get-GMQRROK2.js} +2 -2
- package/dist/bin/{get-ZSZ6SL3N.js → get-ZV3SC2VY.js} +2 -2
- package/dist/bin/hisaabo.js +100 -57
- package/dist/bin/import-UUHMLCKX.js +267 -0
- package/dist/bin/{invitations-H2SL3XAD.js → invitations-OVORTTMF.js} +2 -2
- package/dist/bin/{invite-EW73UIBE.js → invite-GGHBZY4U.js} +2 -2
- package/dist/bin/{invoice-breakdown-XP4QATCF.js → invoice-breakdown-32XXAZDP.js} +2 -2
- package/dist/bin/{items-DPD6EFTP.js → items-6NOIMH6B.js} +2 -2
- package/dist/bin/{items-toggle-R4OPSE4W.js → items-toggle-L6W6QKQD.js} +2 -2
- package/dist/bin/{list-PKHBE475.js → list-FC5JHKHD.js} +2 -2
- package/dist/bin/{list-KLEHBMQ2.js → list-OXAVDXH7.js} +2 -2
- package/dist/bin/{list-UR7OOJVF.js → list-RAR56EMQ.js} +2 -2
- package/dist/bin/{members-XA3TF4IQ.js → members-Y6XJVHHR.js} +2 -2
- package/dist/bin/{monthly-comparison-OLVS5HEY.js → monthly-comparison-IAUZ6SBJ.js} +2 -2
- package/dist/bin/{order-cancel-MXMJFFRR.js → order-cancel-QRTCNART.js} +2 -2
- package/dist/bin/{order-confirm-IXU45Q4L.js → order-confirm-LGQOMC4O.js} +2 -2
- package/dist/bin/{order-get-RDXMHLJ7.js → order-get-4XAQCRYV.js} +2 -2
- package/dist/bin/{order-update-KGIPBEJX.js → order-update-KZY4H2UR.js} +2 -2
- package/dist/bin/output-NUOL7KJW.js +0 -0
- package/dist/bin/{payment-modes-CZL35SVS.js → payment-modes-DY2ZEMK7.js} +2 -2
- package/dist/bin/{profit-loss-M332OSC5.js → profit-loss-5GJBG3PL.js} +2 -2
- package/dist/bin/{receivables-aging-OXRHGMBF.js → receivables-aging-6A7XJKDT.js} +2 -2
- package/dist/bin/{remove-I5HD2Y4K.js → remove-ZBX34TIQ.js} +2 -2
- package/dist/bin/{revoke-OC6AOMIZ.js → revoke-XDNOA2GJ.js} +2 -2
- package/dist/bin/{revoke-MFLWGCMP.js → revoke-ZTAMW2Q2.js} +2 -2
- package/dist/bin/{revoke-all-FSAPBB3P.js → revoke-all-365NRBOA.js} +2 -2
- package/dist/bin/{revoke-invitation-JXDPXTOW.js → revoke-invitation-PQH7XNYA.js} +2 -2
- package/dist/bin/{sales-trend-KK63WNDL.js → sales-trend-D6PQ7MHY.js} +2 -2
- package/dist/bin/{sequence-IQ4HUJ3W.js → sequence-KZWADVD7.js} +2 -2
- package/dist/bin/{store-6QT6HKG2.js → store-SVRZBUFO.js} +2 -2
- package/dist/bin/{summary-3FTF5B4A.js → summary-H6U7O5GJ.js} +2 -2
- package/dist/bin/{top-customers-HNYGXBQZ.js → top-customers-ATBN6RDI.js} +2 -2
- package/dist/bin/{top-items-JUDG3BVW.js → top-items-XXU6KYTC.js} +2 -2
- package/dist/bin/{top-outstanding-WK26ZNE5.js → top-outstanding-JTQNGGW4.js} +2 -2
- package/dist/bin/{unpaid-invoices-RYFIIIK7.js → unpaid-invoices-BTNQFWCH.js} +2 -2
- package/dist/bin/{untracked-FAFS3KCK.js → untracked-PAMEDJ6Y.js} +2 -2
- package/dist/bin/{update-5YSPXIWO.js → update-6ZMX2OYX.js} +2 -2
- package/dist/bin/{update-I46XLU77.js → update-EGHPFXLK.js} +2 -2
- package/dist/bin/{update-NAW2JWZS.js → update-EK4NJWU4.js} +2 -2
- package/dist/bin/{update-role-5GV42MSN.js → update-role-24PDTNFK.js} +2 -2
- package/dist/bin/{update-settings-KYSQDIEO.js → update-settings-AASI6WZX.js} +2 -2
- package/package.json +35 -9
- package/.turbo/turbo-build.log +0 -13
- package/.turbo/turbo-typecheck.log +0 -4
- package/CLI-UX-ARCHITECTURE.md +0 -1269
- package/src/auth.ts +0 -221
- package/src/bin/hisaabo.ts +0 -74
- package/src/bin/registrars/api-key.ts +0 -44
- package/src/bin/registrars/auth.ts +0 -222
- package/src/bin/registrars/automated-invoice.ts +0 -167
- package/src/bin/registrars/bank-recon.ts +0 -34
- package/src/bin/registrars/bank.ts +0 -124
- package/src/bin/registrars/business.ts +0 -120
- package/src/bin/registrars/dashboard.ts +0 -225
- package/src/bin/registrars/document.ts +0 -184
- package/src/bin/registrars/einvoice.ts +0 -46
- package/src/bin/registrars/ewb.ts +0 -37
- package/src/bin/registrars/expense.ts +0 -87
- package/src/bin/registrars/gst.ts +0 -57
- package/src/bin/registrars/import.ts +0 -49
- package/src/bin/registrars/invoice.ts +0 -117
- package/src/bin/registrars/itc.ts +0 -56
- package/src/bin/registrars/item.ts +0 -112
- package/src/bin/registrars/journal.ts +0 -47
- package/src/bin/registrars/party.ts +0 -81
- package/src/bin/registrars/payment.ts +0 -128
- package/src/bin/registrars/report.ts +0 -186
- package/src/bin/registrars/session.ts +0 -32
- package/src/bin/registrars/shipment.ts +0 -74
- package/src/bin/registrars/store.ts +0 -128
- package/src/bin/registrars/target.ts +0 -46
- package/src/bin/registrars/tenant.ts +0 -73
- package/src/client.ts +0 -2071
- package/src/commands/api-key/create.ts +0 -72
- package/src/commands/api-key/list.ts +0 -71
- package/src/commands/api-key/revoke.ts +0 -46
- package/src/commands/automated-invoice/create.ts +0 -85
- package/src/commands/automated-invoice/delete.ts +0 -42
- package/src/commands/automated-invoice/get.ts +0 -113
- package/src/commands/automated-invoice/history.ts +0 -65
- package/src/commands/automated-invoice/index.ts +0 -11
- package/src/commands/automated-invoice/list.ts +0 -91
- package/src/commands/automated-invoice/pause.ts +0 -29
- package/src/commands/automated-invoice/resume.ts +0 -29
- package/src/commands/automated-invoice/run-now.ts +0 -29
- package/src/commands/automated-invoice/suggestions.ts +0 -68
- package/src/commands/automated-invoice/update.ts +0 -54
- package/src/commands/automated-invoice/usage.ts +0 -68
- package/src/commands/bank/gateway-config.ts +0 -61
- package/src/commands/bank/index.ts +0 -244
- package/src/commands/bank/update-gateway.ts +0 -84
- package/src/commands/bank-recon/index.ts +0 -127
- package/src/commands/business/audit-trail.ts +0 -79
- package/src/commands/business/export.ts +0 -52
- package/src/commands/business/get.ts +0 -55
- package/src/commands/business/sequence.ts +0 -65
- package/src/commands/business/update.ts +0 -64
- package/src/commands/dashboard/collection-efficiency.ts +0 -164
- package/src/commands/dashboard/expenses.ts +0 -76
- package/src/commands/dashboard/invoice-breakdown.ts +0 -89
- package/src/commands/dashboard/monthly-comparison.ts +0 -193
- package/src/commands/dashboard/payment-modes.ts +0 -121
- package/src/commands/dashboard/profit-loss.ts +0 -146
- package/src/commands/dashboard/receivables-aging.ts +0 -169
- package/src/commands/dashboard/sales-trend.ts +0 -68
- package/src/commands/dashboard/summary.ts +0 -105
- package/src/commands/dashboard/top-customers.ts +0 -70
- package/src/commands/dashboard/top-items.ts +0 -74
- package/src/commands/dashboard/top-outstanding.ts +0 -61
- package/src/commands/dashboard.ts +0 -105
- package/src/commands/document/factory.ts +0 -590
- package/src/commands/einvoice/index.ts +0 -109
- package/src/commands/ewb/index.ts +0 -108
- package/src/commands/expense/categories.ts +0 -40
- package/src/commands/expense/create.ts +0 -51
- package/src/commands/expense/delete.ts +0 -45
- package/src/commands/expense/list.ts +0 -65
- package/src/commands/expense/update.ts +0 -58
- package/src/commands/gst/index.ts +0 -194
- package/src/commands/import/index.ts +0 -168
- package/src/commands/invoice/create.ts +0 -262
- package/src/commands/invoice/delete.ts +0 -44
- package/src/commands/invoice/get.ts +0 -113
- package/src/commands/invoice/list.ts +0 -126
- package/src/commands/invoice/pdf.ts +0 -75
- package/src/commands/invoice/status.ts +0 -41
- package/src/commands/itc/index.ts +0 -163
- package/src/commands/item/categories.ts +0 -40
- package/src/commands/item/create.ts +0 -98
- package/src/commands/item/delete.ts +0 -44
- package/src/commands/item/list.ts +0 -81
- package/src/commands/item/low-stock-count.ts +0 -32
- package/src/commands/item/merge.ts +0 -53
- package/src/commands/item/price-history.ts +0 -59
- package/src/commands/item/rename-unit.ts +0 -39
- package/src/commands/item/sales-stats.ts +0 -44
- package/src/commands/item/stock-history.ts +0 -70
- package/src/commands/item/stock.ts +0 -46
- package/src/commands/item/switch-base-unit.ts +0 -42
- package/src/commands/item/update.ts +0 -59
- package/src/commands/item/variants-create.ts +0 -58
- package/src/commands/item/variants-delete.ts +0 -47
- package/src/commands/item/variants-list.ts +0 -63
- package/src/commands/item/variants-update.ts +0 -61
- package/src/commands/journal/index.ts +0 -156
- package/src/commands/party/create.ts +0 -88
- package/src/commands/party/delete.ts +0 -44
- package/src/commands/party/get.ts +0 -42
- package/src/commands/party/ledger-report.ts +0 -81
- package/src/commands/party/ledger.ts +0 -63
- package/src/commands/party/list.ts +0 -69
- package/src/commands/party/merge.ts +0 -50
- package/src/commands/party/stats.ts +0 -40
- package/src/commands/party/top-items.ts +0 -57
- package/src/commands/party/update.ts +0 -65
- package/src/commands/payment/create.ts +0 -131
- package/src/commands/payment/default-account.ts +0 -56
- package/src/commands/payment/delete.ts +0 -46
- package/src/commands/payment/get.ts +0 -59
- package/src/commands/payment/list.ts +0 -66
- package/src/commands/payment/unpaid-invoices.ts +0 -69
- package/src/commands/payment/untracked.ts +0 -70
- package/src/commands/payment/update.ts +0 -54
- package/src/commands/report/index.ts +0 -736
- package/src/commands/session/list.ts +0 -91
- package/src/commands/session/revoke-all.ts +0 -20
- package/src/commands/session/revoke.ts +0 -32
- package/src/commands/shipment/index.ts +0 -170
- package/src/commands/store/check-slug.ts +0 -48
- package/src/commands/store/index.ts +0 -77
- package/src/commands/store/items-toggle.ts +0 -41
- package/src/commands/store/items.ts +0 -61
- package/src/commands/store/order-cancel.ts +0 -48
- package/src/commands/store/order-confirm.ts +0 -45
- package/src/commands/store/order-get.ts +0 -66
- package/src/commands/store/order-update.ts +0 -52
- package/src/commands/store/update-settings.ts +0 -52
- package/src/commands/target/index.ts +0 -118
- package/src/commands/tenant/invitations.ts +0 -62
- package/src/commands/tenant/invite.ts +0 -57
- package/src/commands/tenant/list.ts +0 -46
- package/src/commands/tenant/members.ts +0 -55
- package/src/commands/tenant/remove.ts +0 -47
- package/src/commands/tenant/revoke-invitation.ts +0 -32
- package/src/commands/tenant/update-role.ts +0 -41
- package/src/config.ts +0 -120
- package/src/error-handler.ts +0 -53
- package/src/format.ts +0 -181
- package/src/output.ts +0 -228
- package/src/spinner.ts +0 -39
- package/tsconfig.json +0 -22
- package/tsup.config.ts +0 -18
|
@@ -1,169 +0,0 @@
|
|
|
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 } from "../../format.js";
|
|
5
|
-
import chalk from "chalk";
|
|
6
|
-
|
|
7
|
-
interface ReceivablesAgingOpts {
|
|
8
|
-
json?: boolean;
|
|
9
|
-
format?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function agingBar(amount: number, maxAmount: number, barWidth: number): string {
|
|
13
|
-
if (maxAmount <= 0 || amount <= 0) return "";
|
|
14
|
-
const filled = Math.round((amount / maxAmount) * barWidth);
|
|
15
|
-
return "█".repeat(filled) + "░".repeat(barWidth - filled);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function dashboardReceivablesAgingCommand(opts: ReceivablesAgingOpts): Promise<void> {
|
|
19
|
-
const cfg = requireAuth();
|
|
20
|
-
const client = new HisaaboClient(cfg);
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const data = await client.dashboard.receivablesAging();
|
|
24
|
-
|
|
25
|
-
if (opts.json) {
|
|
26
|
-
outputJSON(data);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Normalize data: could be an object with bucket keys, or an array of { bucket, amount, count }
|
|
31
|
-
type AgingRow = { bucket: string; amount: number; count: number };
|
|
32
|
-
const BUCKETS = [
|
|
33
|
-
{ key: "current", label: "Current (not due)" },
|
|
34
|
-
{ key: "1_30", label: "1–30 days" },
|
|
35
|
-
{ key: "31_60", label: "31–60 days" },
|
|
36
|
-
{ key: "61_90", label: "61–90 days" },
|
|
37
|
-
{ key: "90_plus", label: "90+ days" },
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
let bucketData: AgingRow[] = [];
|
|
41
|
-
|
|
42
|
-
if (Array.isArray(data)) {
|
|
43
|
-
bucketData = data.map((r: Record<string, unknown>) => ({
|
|
44
|
-
bucket: String(r["bucket"] ?? r["range"] ?? r["label"] ?? "-"),
|
|
45
|
-
amount: parseFloat(String(r["amount"] ?? r["totalAmount"] ?? "0")),
|
|
46
|
-
count: parseInt(String(r["count"] ?? r["invoiceCount"] ?? "0"), 10),
|
|
47
|
-
}));
|
|
48
|
-
} else if (data && typeof data === "object") {
|
|
49
|
-
const obj = data as Record<string, unknown>;
|
|
50
|
-
for (const { key, label } of BUCKETS) {
|
|
51
|
-
const entry = (obj[key] ?? obj[label]) as Record<string, unknown> | undefined;
|
|
52
|
-
if (entry != null) {
|
|
53
|
-
bucketData.push({
|
|
54
|
-
bucket: label,
|
|
55
|
-
amount: parseFloat(String(entry["amount"] ?? entry["totalAmount"] ?? "0")),
|
|
56
|
-
count: parseInt(String(entry["count"] ?? entry["invoiceCount"] ?? "0"), 10),
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
// Fallback: top-level numeric fields keyed by bucket name
|
|
61
|
-
if (bucketData.length === 0) {
|
|
62
|
-
for (const { key, label } of BUCKETS) {
|
|
63
|
-
const val = obj[key];
|
|
64
|
-
if (val != null) {
|
|
65
|
-
bucketData.push({
|
|
66
|
-
bucket: label,
|
|
67
|
-
amount: parseFloat(String(val)),
|
|
68
|
-
count: 0,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (opts.format === "tsv" || opts.format === "csv") {
|
|
76
|
-
const rows = bucketData.map((r) => ({
|
|
77
|
-
bucket: r.bucket,
|
|
78
|
-
amount: formatAmount(r.amount),
|
|
79
|
-
count: String(r.count || "-"),
|
|
80
|
-
}));
|
|
81
|
-
const columns = [
|
|
82
|
-
{ key: "bucket", header: "Aging Bucket", align: "left" as const },
|
|
83
|
-
{ key: "amount", header: "Amount ₹", align: "right" as const },
|
|
84
|
-
{ key: "count", header: "Invoices", align: "right" as const },
|
|
85
|
-
];
|
|
86
|
-
if (opts.format === "tsv") outputTSV(rows, columns);
|
|
87
|
-
else outputCSV(rows, columns);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Pretty box display
|
|
92
|
-
const total = bucketData.reduce((s, r) => s + r.amount, 0);
|
|
93
|
-
const maxAmount = Math.max(...bucketData.map((r) => r.amount), 1);
|
|
94
|
-
const width = Math.min(termWidth() - 4, 60);
|
|
95
|
-
const innerW = width - 2;
|
|
96
|
-
|
|
97
|
-
process.stdout.write("\n");
|
|
98
|
-
if (hasColor()) {
|
|
99
|
-
process.stdout.write(" " + chalk.bold("Receivables Aging Report") + "\n\n");
|
|
100
|
-
} else {
|
|
101
|
-
process.stdout.write(" Receivables Aging Report\n\n");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
process.stdout.write(" ┌" + "─".repeat(innerW) + "┐\n");
|
|
105
|
-
|
|
106
|
-
const labelW = 22;
|
|
107
|
-
const amtW = 16;
|
|
108
|
-
const barW = Math.max(4, innerW - labelW - amtW - 5);
|
|
109
|
-
|
|
110
|
-
for (const row of bucketData) {
|
|
111
|
-
const pct = total > 0 ? ((row.amount / total) * 100).toFixed(1) : "0.0";
|
|
112
|
-
const label = row.bucket.padEnd(labelW).slice(0, labelW);
|
|
113
|
-
const amtStr = formatAmount(row.amount).padStart(amtW);
|
|
114
|
-
const bar = agingBar(row.amount, maxAmount, barW);
|
|
115
|
-
|
|
116
|
-
// Color: current = green, 1-30 = yellow, 31-60 = orange, 61-90 = red, 90+ = bold red
|
|
117
|
-
let coloredBar = bar;
|
|
118
|
-
let coloredLabel = label;
|
|
119
|
-
if (hasColor()) {
|
|
120
|
-
const idx = bucketData.indexOf(row);
|
|
121
|
-
const colors = [chalk.green, chalk.yellow, chalk.yellow, chalk.red, chalk.red];
|
|
122
|
-
const labelColors = [chalk.green, chalk.yellow, chalk.yellow, chalk.red, (s: string) => chalk.bold(chalk.red(s))];
|
|
123
|
-
const colorFn = colors[idx] ?? chalk.white;
|
|
124
|
-
const labelFn = labelColors[idx] ?? chalk.white;
|
|
125
|
-
coloredBar = colorFn(bar);
|
|
126
|
-
coloredLabel = labelFn(label);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const pctStr = `${pct}%`.padStart(6);
|
|
130
|
-
process.stdout.write(` │ ${coloredLabel} ${coloredBar} ${amtStr} ${pctStr} │\n`);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
process.stdout.write(" ├" + "─".repeat(innerW) + "┤\n");
|
|
134
|
-
|
|
135
|
-
const totalLabel = "Total Receivables".padEnd(labelW);
|
|
136
|
-
const totalAmt = formatAmount(total).padStart(amtW);
|
|
137
|
-
const totalLine = ` │ ${hasColor() ? chalk.bold(totalLabel) : totalLabel} ${" ".repeat(barW)} ${hasColor() ? chalk.bold(totalAmt) : totalAmt} │`;
|
|
138
|
-
process.stdout.write(totalLine + "\n");
|
|
139
|
-
process.stdout.write(" └" + "─".repeat(innerW) + "┘\n\n");
|
|
140
|
-
|
|
141
|
-
if (bucketData.length === 0) {
|
|
142
|
-
process.stdout.write(" No receivables data available.\n\n");
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Also show table for invoices count if we have it
|
|
146
|
-
if (bucketData.some((r) => r.count > 0)) {
|
|
147
|
-
const rows = bucketData.map((r) => ({
|
|
148
|
-
bucket: r.bucket,
|
|
149
|
-
amount: formatAmount(r.amount),
|
|
150
|
-
count: String(r.count),
|
|
151
|
-
}));
|
|
152
|
-
const columns = [
|
|
153
|
-
{ key: "bucket", header: "Aging Bucket", align: "left" as const },
|
|
154
|
-
{ key: "amount", header: "Amount ₹", align: "right" as const },
|
|
155
|
-
{ key: "count", header: "Invoices", align: "right" as const },
|
|
156
|
-
];
|
|
157
|
-
outputTable(rows, columns);
|
|
158
|
-
process.stdout.write("\n");
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
} catch (e) {
|
|
162
|
-
if (e instanceof HisaaboApiError) {
|
|
163
|
-
const err = e.hisaaboError;
|
|
164
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
165
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
166
|
-
}
|
|
167
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
168
|
-
}
|
|
169
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
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 SalesTrendOpts {
|
|
8
|
-
months?: number;
|
|
9
|
-
from?: string;
|
|
10
|
-
to?: string;
|
|
11
|
-
granularity?: string;
|
|
12
|
-
json?: boolean;
|
|
13
|
-
format?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function dashboardSalesTrendCommand(opts: SalesTrendOpts): Promise<void> {
|
|
17
|
-
const cfg = requireAuth();
|
|
18
|
-
const client = new HisaaboClient(cfg);
|
|
19
|
-
|
|
20
|
-
const input: Record<string, unknown> = {};
|
|
21
|
-
if (opts.months) input["months"] = opts.months;
|
|
22
|
-
if (opts.from) input["fromDate"] = opts.from;
|
|
23
|
-
if (opts.to) input["toDate"] = opts.to;
|
|
24
|
-
if (opts.granularity) input["granularity"] = opts.granularity;
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const data = await client.dashboard.salesTrend(input as Parameters<typeof client.dashboard.salesTrend>[0]);
|
|
28
|
-
|
|
29
|
-
if (opts.json) {
|
|
30
|
-
outputJSON(data);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const rows: Array<{ period: string; sales: string; collections: string; invoices: string }> = Array.isArray(data)
|
|
35
|
-
? data.map((r: Record<string, unknown>) => ({
|
|
36
|
-
period: String(r["period"] ?? r["month"] ?? "-"),
|
|
37
|
-
sales: formatAmount(String(r["sales"] ?? r["totalSales"] ?? "0")),
|
|
38
|
-
collections: formatAmount(String(r["collections"] ?? r["totalCollections"] ?? "0")),
|
|
39
|
-
invoices: String(r["invoices"] ?? r["invoiceCount"] ?? "0"),
|
|
40
|
-
}))
|
|
41
|
-
: [];
|
|
42
|
-
|
|
43
|
-
const columns = [
|
|
44
|
-
{ key: "period", header: "Period", align: "left" as const },
|
|
45
|
-
{ key: "sales", header: "Sales ₹", align: "right" as const },
|
|
46
|
-
{ key: "collections", header: "Collection ₹", align: "right" as const },
|
|
47
|
-
{ key: "invoices", header: "Invoices", align: "right" as const },
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
if (opts.format === "tsv") {
|
|
51
|
-
outputTSV(rows, columns);
|
|
52
|
-
} else if (opts.format === "csv") {
|
|
53
|
-
outputCSV(rows, columns);
|
|
54
|
-
} else {
|
|
55
|
-
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Sales Trend\n") + "\n");
|
|
56
|
-
else process.stdout.write("\n Sales Trend\n\n");
|
|
57
|
-
outputTable(rows, columns);
|
|
58
|
-
process.stdout.write("\n");
|
|
59
|
-
}
|
|
60
|
-
} catch (e) {
|
|
61
|
-
if (e instanceof HisaaboApiError) {
|
|
62
|
-
const err = e.hisaaboError;
|
|
63
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
64
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
65
|
-
}
|
|
66
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import { fatalError, outputJSON, EXIT, hasColor, termWidth } from "../../output.js";
|
|
4
|
-
import { formatAmount, formatStatus, formatRelativeDate, currentFY, fyStart, todayISO } from "../../format.js";
|
|
5
|
-
import chalk from "chalk";
|
|
6
|
-
|
|
7
|
-
function box(title: string, lines: string[], width: number): string[] {
|
|
8
|
-
const innerW = width - 2;
|
|
9
|
-
const titleStr = `─ ${title} `;
|
|
10
|
-
const border = "┌" + titleStr + "─".repeat(Math.max(1, innerW - titleStr.length)) + "┐";
|
|
11
|
-
const bottom = "└" + "─".repeat(innerW) + "┘";
|
|
12
|
-
const padded = lines.map((l) => {
|
|
13
|
-
const vis = l.length;
|
|
14
|
-
const pad = Math.max(0, innerW - vis - 1);
|
|
15
|
-
return "│ " + l + " ".repeat(pad) + "│";
|
|
16
|
-
});
|
|
17
|
-
return [border, ...padded, bottom];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function colorMoney(amount: string, good = true): string {
|
|
21
|
-
if (!hasColor()) return formatAmount(amount);
|
|
22
|
-
const num = parseFloat(amount);
|
|
23
|
-
if (isNaN(num) || num === 0) return chalk.dim(formatAmount(amount));
|
|
24
|
-
if (good) return chalk.green(formatAmount(amount));
|
|
25
|
-
return chalk.red(formatAmount(amount));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function dashboardCommand(opts: { json?: boolean }): Promise<void> {
|
|
29
|
-
const cfg = requireAuth();
|
|
30
|
-
const client = new HisaaboClient(cfg);
|
|
31
|
-
const from = fyStart();
|
|
32
|
-
const to = todayISO();
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
const summary = await client.dashboard.summary({ fromDate: from, toDate: to });
|
|
36
|
-
|
|
37
|
-
if (opts.json) {
|
|
38
|
-
outputJSON(summary);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const width = Math.min(termWidth() - 2, 70);
|
|
43
|
-
const fy = currentFY();
|
|
44
|
-
|
|
45
|
-
console.log();
|
|
46
|
-
console.log(` Hisaabo Dashboard` + " ".repeat(Math.max(2, width - 30)) + (cfg.businessName ?? ""));
|
|
47
|
-
console.log(` FY ${fy} (01 Apr ${fy.split("-")[0]} - 31 Mar 20${fy.split("-")[1]})`);
|
|
48
|
-
console.log(` ${"═".repeat(width)}`);
|
|
49
|
-
console.log();
|
|
50
|
-
|
|
51
|
-
// Revenue / Expenses boxes
|
|
52
|
-
const halfW = Math.floor((width - 3) / 2);
|
|
53
|
-
const revLines = [
|
|
54
|
-
`Sales ${formatAmount(summary.totalSales).padStart(12)}`,
|
|
55
|
-
`Cash In ${formatAmount(summary.cashInHand).padStart(12)}`,
|
|
56
|
-
];
|
|
57
|
-
const expLines = [
|
|
58
|
-
`Purchases ${formatAmount(summary.totalPurchases).padStart(11)}`,
|
|
59
|
-
`Expenses ${formatAmount(summary.totalExpenses).padStart(11)}`,
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
const revBox = box("Revenue", revLines, halfW);
|
|
63
|
-
const expBox = box("Expenses", expLines, halfW);
|
|
64
|
-
|
|
65
|
-
for (let i = 0; i < Math.max(revBox.length, expBox.length); i++) {
|
|
66
|
-
const l = (revBox[i] ?? "").padEnd(halfW);
|
|
67
|
-
const r = expBox[i] ?? "";
|
|
68
|
-
console.log(` ${l} ${r}`);
|
|
69
|
-
}
|
|
70
|
-
console.log();
|
|
71
|
-
|
|
72
|
-
// Outstanding box
|
|
73
|
-
const net = parseFloat(summary.receivable) - parseFloat(summary.payable);
|
|
74
|
-
const netLabel = net >= 0 ? "receivable" : "payable";
|
|
75
|
-
const outLines = [
|
|
76
|
-
`Receivable ${colorMoney(summary.receivable)}`,
|
|
77
|
-
`Payable ${colorMoney(summary.payable, false)}`,
|
|
78
|
-
`Net Position ${colorMoney(String(Math.abs(net)))} ${netLabel}`,
|
|
79
|
-
];
|
|
80
|
-
const outBox = box("Outstanding", outLines, width);
|
|
81
|
-
outBox.forEach((l) => console.log(` ${l}`));
|
|
82
|
-
console.log();
|
|
83
|
-
|
|
84
|
-
// Recent invoices box
|
|
85
|
-
const recentLines = summary.recentInvoices.slice(0, 5).map((inv) => {
|
|
86
|
-
const num = inv.invoiceNumber.padEnd(10);
|
|
87
|
-
const party = inv.partyName.slice(0, 16).padEnd(18);
|
|
88
|
-
const amt = formatAmount(inv.totalAmount).padStart(12);
|
|
89
|
-
const status = formatStatus(inv.status).padEnd(10);
|
|
90
|
-
const rel = formatRelativeDate(inv.invoiceDate).padEnd(7);
|
|
91
|
-
return `${num} ${party} ${amt} ${status} ${rel}`;
|
|
92
|
-
});
|
|
93
|
-
const recentBox = box("Recent Invoices", recentLines, width);
|
|
94
|
-
recentBox.forEach((l) => console.log(` ${l}`));
|
|
95
|
-
console.log();
|
|
96
|
-
|
|
97
|
-
} catch (e) {
|
|
98
|
-
if (e instanceof HisaaboApiError) {
|
|
99
|
-
const err = e.hisaaboError;
|
|
100
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
101
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
102
|
-
}
|
|
103
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
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 TopCustomersOpts {
|
|
8
|
-
limit?: number;
|
|
9
|
-
from?: string;
|
|
10
|
-
to?: string;
|
|
11
|
-
thisMonth?: boolean;
|
|
12
|
-
thisFy?: boolean;
|
|
13
|
-
json?: boolean;
|
|
14
|
-
format?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function dashboardTopCustomersCommand(opts: TopCustomersOpts): Promise<void> {
|
|
18
|
-
const cfg = requireAuth();
|
|
19
|
-
const client = new HisaaboClient(cfg);
|
|
20
|
-
|
|
21
|
-
let fromDate = opts.from;
|
|
22
|
-
let toDate = opts.to;
|
|
23
|
-
if (opts.thisMonth) { fromDate = monthStart(); toDate = monthEnd(); }
|
|
24
|
-
else if (opts.thisFy) { fromDate = fyStart(); toDate = todayISO(); }
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const data = await client.dashboard.topCustomers({
|
|
28
|
-
limit: opts.limit,
|
|
29
|
-
fromDate,
|
|
30
|
-
toDate,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
if (opts.json) {
|
|
34
|
-
outputJSON(data);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const rows: Array<{ party: string; revenue: string; invoices: string }> = Array.isArray(data)
|
|
39
|
-
? data.map((r: Record<string, unknown>) => ({
|
|
40
|
-
party: String(r["partyName"] ?? r["party"] ?? "-"),
|
|
41
|
-
revenue: formatAmount(String(r["revenue"] ?? r["totalRevenue"] ?? r["totalSales"] ?? "0")),
|
|
42
|
-
invoices: String(r["invoiceCount"] ?? r["invoices"] ?? "-"),
|
|
43
|
-
}))
|
|
44
|
-
: [];
|
|
45
|
-
|
|
46
|
-
const columns = [
|
|
47
|
-
{ key: "party", header: "Customer", align: "left" as const },
|
|
48
|
-
{ key: "revenue", header: "Revenue ₹", align: "right" as const },
|
|
49
|
-
{ key: "invoices", header: "Invoices", align: "right" as const },
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
if (opts.format === "tsv") {
|
|
53
|
-
outputTSV(rows, columns);
|
|
54
|
-
} else if (opts.format === "csv") {
|
|
55
|
-
outputCSV(rows, columns);
|
|
56
|
-
} else {
|
|
57
|
-
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Top Customers by Revenue\n") + "\n");
|
|
58
|
-
else process.stdout.write("\n Top Customers by Revenue\n\n");
|
|
59
|
-
outputTable(rows, columns);
|
|
60
|
-
process.stdout.write("\n");
|
|
61
|
-
}
|
|
62
|
-
} catch (e) {
|
|
63
|
-
if (e instanceof HisaaboApiError) {
|
|
64
|
-
const err = e.hisaaboError;
|
|
65
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
66
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
67
|
-
}
|
|
68
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
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 TopItemsOpts {
|
|
8
|
-
limit?: number;
|
|
9
|
-
type?: string;
|
|
10
|
-
from?: string;
|
|
11
|
-
to?: string;
|
|
12
|
-
thisMonth?: boolean;
|
|
13
|
-
thisFy?: boolean;
|
|
14
|
-
json?: boolean;
|
|
15
|
-
format?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function dashboardTopItemsCommand(opts: TopItemsOpts): Promise<void> {
|
|
19
|
-
const cfg = requireAuth();
|
|
20
|
-
const client = new HisaaboClient(cfg);
|
|
21
|
-
|
|
22
|
-
let fromDate = opts.from;
|
|
23
|
-
let toDate = opts.to;
|
|
24
|
-
if (opts.thisMonth) { fromDate = monthStart(); toDate = monthEnd(); }
|
|
25
|
-
else if (opts.thisFy) { fromDate = fyStart(); toDate = todayISO(); }
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
const data = await client.dashboard.topSellingItems({
|
|
29
|
-
limit: opts.limit,
|
|
30
|
-
itemType: opts.type,
|
|
31
|
-
fromDate,
|
|
32
|
-
toDate,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
if (opts.json) {
|
|
36
|
-
outputJSON(data);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const rows: Array<{ item: string; qty: string; revenue: string; type: string }> = Array.isArray(data)
|
|
41
|
-
? data.map((r: Record<string, unknown>) => ({
|
|
42
|
-
item: String(r["itemName"] ?? r["name"] ?? "-"),
|
|
43
|
-
qty: String(r["totalQuantity"] ?? r["qty"] ?? r["quantity"] ?? "-"),
|
|
44
|
-
revenue: formatAmount(String(r["totalRevenue"] ?? r["revenue"] ?? "0")),
|
|
45
|
-
type: String(r["itemType"] ?? r["type"] ?? "-"),
|
|
46
|
-
}))
|
|
47
|
-
: [];
|
|
48
|
-
|
|
49
|
-
const columns = [
|
|
50
|
-
{ key: "item", header: "Item", align: "left" as const },
|
|
51
|
-
{ key: "type", header: "Type", align: "left" as const },
|
|
52
|
-
{ key: "qty", header: "Qty Sold", align: "right" as const },
|
|
53
|
-
{ key: "revenue", header: "Revenue ₹", align: "right" as const },
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
if (opts.format === "tsv") {
|
|
57
|
-
outputTSV(rows, columns);
|
|
58
|
-
} else if (opts.format === "csv") {
|
|
59
|
-
outputCSV(rows, columns);
|
|
60
|
-
} else {
|
|
61
|
-
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Top Selling Items\n") + "\n");
|
|
62
|
-
else process.stdout.write("\n Top Selling Items\n\n");
|
|
63
|
-
outputTable(rows, columns);
|
|
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 === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
71
|
-
}
|
|
72
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
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 TopOutstandingOpts {
|
|
8
|
-
limit?: number;
|
|
9
|
-
json?: boolean;
|
|
10
|
-
format?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function dashboardTopOutstandingCommand(opts: TopOutstandingOpts): Promise<void> {
|
|
14
|
-
const cfg = requireAuth();
|
|
15
|
-
const client = new HisaaboClient(cfg);
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
const data = await client.dashboard.topOutstanding({ limit: opts.limit });
|
|
19
|
-
|
|
20
|
-
if (opts.json) {
|
|
21
|
-
outputJSON(data);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const rows: Array<{ party: string; outstanding: string; oldestAge: string }> = Array.isArray(data)
|
|
26
|
-
? data.map((r: Record<string, unknown>) => ({
|
|
27
|
-
party: String(r["partyName"] ?? r["party"] ?? "-"),
|
|
28
|
-
outstanding: formatAmount(String(r["outstanding"] ?? r["outstandingAmount"] ?? "0")),
|
|
29
|
-
oldestAge: r["oldestInvoiceDays"] != null
|
|
30
|
-
? `${r["oldestInvoiceDays"]}d`
|
|
31
|
-
: r["oldestAge"] != null
|
|
32
|
-
? `${r["oldestAge"]}d`
|
|
33
|
-
: "-",
|
|
34
|
-
}))
|
|
35
|
-
: [];
|
|
36
|
-
|
|
37
|
-
const columns = [
|
|
38
|
-
{ key: "party", header: "Party", align: "left" as const },
|
|
39
|
-
{ key: "outstanding", header: "Outstanding ₹", align: "right" as const },
|
|
40
|
-
{ key: "oldestAge", header: "Oldest Invoice", align: "right" as const },
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
if (opts.format === "tsv") {
|
|
44
|
-
outputTSV(rows, columns);
|
|
45
|
-
} else if (opts.format === "csv") {
|
|
46
|
-
outputCSV(rows, columns);
|
|
47
|
-
} else {
|
|
48
|
-
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Top Outstanding\n") + "\n");
|
|
49
|
-
else process.stdout.write("\n Top Outstanding\n\n");
|
|
50
|
-
outputTable(rows, columns);
|
|
51
|
-
process.stdout.write("\n");
|
|
52
|
-
}
|
|
53
|
-
} catch (e) {
|
|
54
|
-
if (e instanceof HisaaboApiError) {
|
|
55
|
-
const err = e.hisaaboError;
|
|
56
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
57
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
58
|
-
}
|
|
59
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError } from "../client.js";
|
|
2
|
-
import { requireAuth } from "../config.js";
|
|
3
|
-
import { fatalError, outputJSON, EXIT, hasColor, termWidth } from "../output.js";
|
|
4
|
-
import { formatAmount, formatStatus, formatRelativeDate, currentFY, fyStart, todayISO } from "../format.js";
|
|
5
|
-
import chalk from "chalk";
|
|
6
|
-
|
|
7
|
-
function box(title: string, lines: string[], width: number): string[] {
|
|
8
|
-
const innerW = width - 2;
|
|
9
|
-
const titleStr = `─ ${title} `;
|
|
10
|
-
const border = "┌" + titleStr + "─".repeat(Math.max(1, innerW - titleStr.length)) + "┐";
|
|
11
|
-
const bottom = "└" + "─".repeat(innerW) + "┘";
|
|
12
|
-
const padded = lines.map((l) => {
|
|
13
|
-
const vis = l.length;
|
|
14
|
-
const pad = Math.max(0, innerW - vis - 1);
|
|
15
|
-
return "│ " + l + " ".repeat(pad) + "│";
|
|
16
|
-
});
|
|
17
|
-
return [border, ...padded, bottom];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function colorMoney(amount: string, good = true): string {
|
|
21
|
-
if (!hasColor()) return formatAmount(amount);
|
|
22
|
-
const num = parseFloat(amount);
|
|
23
|
-
if (isNaN(num) || num === 0) return chalk.dim(formatAmount(amount));
|
|
24
|
-
if (good) return chalk.green(formatAmount(amount));
|
|
25
|
-
return chalk.red(formatAmount(amount));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function dashboardCommand(opts: { json?: boolean }): Promise<void> {
|
|
29
|
-
const cfg = requireAuth();
|
|
30
|
-
const client = new HisaaboClient(cfg);
|
|
31
|
-
const from = fyStart();
|
|
32
|
-
const to = todayISO();
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
const summary = await client.dashboard.summary({ fromDate: from, toDate: to });
|
|
36
|
-
|
|
37
|
-
if (opts.json) {
|
|
38
|
-
outputJSON(summary);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const width = Math.min(termWidth() - 2, 70);
|
|
43
|
-
const fy = currentFY();
|
|
44
|
-
|
|
45
|
-
console.log();
|
|
46
|
-
console.log(` Hisaabo Dashboard` + " ".repeat(Math.max(2, width - 30)) + (cfg.businessName ?? ""));
|
|
47
|
-
console.log(` FY ${fy} (01 Apr ${fy.split("-")[0]} - 31 Mar 20${fy.split("-")[1]})`);
|
|
48
|
-
console.log(` ${"═".repeat(width)}`);
|
|
49
|
-
console.log();
|
|
50
|
-
|
|
51
|
-
// Revenue / Expenses boxes
|
|
52
|
-
const halfW = Math.floor((width - 3) / 2);
|
|
53
|
-
const revLines = [
|
|
54
|
-
`Sales ${formatAmount(summary.totalSales).padStart(12)}`,
|
|
55
|
-
`Cash In ${formatAmount(summary.cashInHand).padStart(12)}`,
|
|
56
|
-
];
|
|
57
|
-
const expLines = [
|
|
58
|
-
`Purchases ${formatAmount(summary.totalPurchases).padStart(11)}`,
|
|
59
|
-
`Expenses ${formatAmount(summary.totalExpenses).padStart(11)}`,
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
const revBox = box("Revenue", revLines, halfW);
|
|
63
|
-
const expBox = box("Expenses", expLines, halfW);
|
|
64
|
-
|
|
65
|
-
for (let i = 0; i < Math.max(revBox.length, expBox.length); i++) {
|
|
66
|
-
const l = (revBox[i] ?? "").padEnd(halfW);
|
|
67
|
-
const r = expBox[i] ?? "";
|
|
68
|
-
console.log(` ${l} ${r}`);
|
|
69
|
-
}
|
|
70
|
-
console.log();
|
|
71
|
-
|
|
72
|
-
// Outstanding box
|
|
73
|
-
const net = parseFloat(summary.receivable) - parseFloat(summary.payable);
|
|
74
|
-
const netLabel = net >= 0 ? "receivable" : "payable";
|
|
75
|
-
const outLines = [
|
|
76
|
-
`Receivable ${colorMoney(summary.receivable)}`,
|
|
77
|
-
`Payable ${colorMoney(summary.payable, false)}`,
|
|
78
|
-
`Net Position ${colorMoney(String(Math.abs(net)))} ${netLabel}`,
|
|
79
|
-
];
|
|
80
|
-
const outBox = box("Outstanding", outLines, width);
|
|
81
|
-
outBox.forEach((l) => console.log(` ${l}`));
|
|
82
|
-
console.log();
|
|
83
|
-
|
|
84
|
-
// Recent invoices box
|
|
85
|
-
const recentLines = summary.recentInvoices.slice(0, 5).map((inv) => {
|
|
86
|
-
const num = inv.invoiceNumber.padEnd(10);
|
|
87
|
-
const party = inv.partyName.slice(0, 16).padEnd(18);
|
|
88
|
-
const amt = formatAmount(inv.totalAmount).padStart(12);
|
|
89
|
-
const status = formatStatus(inv.status).padEnd(10);
|
|
90
|
-
const rel = formatRelativeDate(inv.invoiceDate).padEnd(7);
|
|
91
|
-
return `${num} ${party} ${amt} ${status} ${rel}`;
|
|
92
|
-
});
|
|
93
|
-
const recentBox = box("Recent Invoices", recentLines, width);
|
|
94
|
-
recentBox.forEach((l) => console.log(` ${l}`));
|
|
95
|
-
console.log();
|
|
96
|
-
|
|
97
|
-
} catch (e) {
|
|
98
|
-
if (e instanceof HisaaboApiError) {
|
|
99
|
-
const err = e.hisaaboError;
|
|
100
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
101
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
102
|
-
}
|
|
103
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
104
|
-
}
|
|
105
|
-
}
|