@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,52 @@
|
|
|
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/tenant/remove.ts
|
|
17
|
+
import * as readline from "readline";
|
|
18
|
+
async function tenantRemoveCommand(userId, opts) {
|
|
19
|
+
const cfg = requireAuth();
|
|
20
|
+
const client = new HisaaboClient(cfg);
|
|
21
|
+
try {
|
|
22
|
+
if (!opts.yes && process.stdin.isTTY) {
|
|
23
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
24
|
+
const answer = await new Promise((resolve) => {
|
|
25
|
+
rl.question(` Remove member ${userId} from the organization? (y/N): `, resolve);
|
|
26
|
+
});
|
|
27
|
+
rl.close();
|
|
28
|
+
if (answer.trim().toLowerCase() !== "y") {
|
|
29
|
+
console.log(" Cancelled.");
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const result = await client.tenant.removeMember({ userId });
|
|
34
|
+
if (opts.json) {
|
|
35
|
+
outputJSON(result);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
success(`Removed member: ${userId}`);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
if (e instanceof HisaaboApiError) {
|
|
41
|
+
const err = e.hisaaboError;
|
|
42
|
+
if (err.code === "not_found") fatalError(`Member not found: ${userId}`, EXIT.NOT_FOUND);
|
|
43
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
44
|
+
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
45
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
46
|
+
}
|
|
47
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
tenantRemoveCommand
|
|
52
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
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/api-key/revoke.ts
|
|
17
|
+
import * as readline from "readline";
|
|
18
|
+
async function apiKeyRevokeCommand(id, 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(` Revoke API key ${id}? This cannot be undone. (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.apiKey.revoke({ id });
|
|
34
|
+
if (opts.json) {
|
|
35
|
+
outputJSON(result);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
success(`API key revoked: ${id}`);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
if (e instanceof HisaaboApiError) {
|
|
41
|
+
const err = e.hisaaboError;
|
|
42
|
+
if (err.code === "not_found") fatalError(`API key not found: ${id}`, EXIT.NOT_FOUND);
|
|
43
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
44
|
+
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
45
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
46
|
+
}
|
|
47
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
apiKeyRevokeCommand
|
|
52
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
formatAmount
|
|
4
|
+
} from "./chunk-FFBG6RU4.js";
|
|
5
|
+
import {
|
|
6
|
+
HisaaboApiError,
|
|
7
|
+
HisaaboClient
|
|
8
|
+
} from "./chunk-FTOBDKMO.js";
|
|
9
|
+
import {
|
|
10
|
+
requireAuth
|
|
11
|
+
} from "./chunk-2P35S2C3.js";
|
|
12
|
+
import {
|
|
13
|
+
EXIT,
|
|
14
|
+
fatalError,
|
|
15
|
+
hasColor,
|
|
16
|
+
outputCSV,
|
|
17
|
+
outputJSON,
|
|
18
|
+
outputTSV,
|
|
19
|
+
outputTable
|
|
20
|
+
} from "./chunk-EYNDY7RB.js";
|
|
21
|
+
|
|
22
|
+
// src/commands/dashboard/sales-trend.ts
|
|
23
|
+
import chalk from "chalk";
|
|
24
|
+
async function dashboardSalesTrendCommand(opts) {
|
|
25
|
+
const cfg = requireAuth();
|
|
26
|
+
const client = new HisaaboClient(cfg);
|
|
27
|
+
const input = {};
|
|
28
|
+
if (opts.months) input["months"] = opts.months;
|
|
29
|
+
if (opts.from) input["fromDate"] = opts.from;
|
|
30
|
+
if (opts.to) input["toDate"] = opts.to;
|
|
31
|
+
if (opts.granularity) input["granularity"] = opts.granularity;
|
|
32
|
+
try {
|
|
33
|
+
const data = await client.dashboard.salesTrend(input);
|
|
34
|
+
if (opts.json) {
|
|
35
|
+
outputJSON(data);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const rows = Array.isArray(data) ? data.map((r) => ({
|
|
39
|
+
period: String(r["period"] ?? r["month"] ?? "-"),
|
|
40
|
+
sales: formatAmount(String(r["sales"] ?? r["totalSales"] ?? "0")),
|
|
41
|
+
collections: formatAmount(String(r["collections"] ?? r["totalCollections"] ?? "0")),
|
|
42
|
+
invoices: String(r["invoices"] ?? r["invoiceCount"] ?? "0")
|
|
43
|
+
})) : [];
|
|
44
|
+
const columns = [
|
|
45
|
+
{ key: "period", header: "Period", align: "left" },
|
|
46
|
+
{ key: "sales", header: "Sales \u20B9", align: "right" },
|
|
47
|
+
{ key: "collections", header: "Collection \u20B9", align: "right" },
|
|
48
|
+
{ key: "invoices", header: "Invoices", align: "right" }
|
|
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
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
dashboardSalesTrendCommand
|
|
71
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
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/sequence.ts
|
|
17
|
+
async function businessSequenceCommand(opts) {
|
|
18
|
+
const cfg = requireAuth();
|
|
19
|
+
const client = new HisaaboClient(cfg);
|
|
20
|
+
if (!opts.type) {
|
|
21
|
+
fatalError("--type is required (sale or purchase).", EXIT.USAGE);
|
|
22
|
+
}
|
|
23
|
+
if (opts.type !== "sale" && opts.type !== "purchase") {
|
|
24
|
+
fatalError("--type must be 'sale' or 'purchase'.", EXIT.USAGE);
|
|
25
|
+
}
|
|
26
|
+
const payload = { type: opts.type };
|
|
27
|
+
if (opts.prefix !== void 0) payload["prefix"] = opts.prefix;
|
|
28
|
+
if (opts.nextNumber !== void 0) {
|
|
29
|
+
const n = parseInt(opts.nextNumber, 10);
|
|
30
|
+
if (isNaN(n) || n < 1) {
|
|
31
|
+
fatalError("--next-number must be a positive integer.", EXIT.USAGE);
|
|
32
|
+
}
|
|
33
|
+
payload["nextNumber"] = n;
|
|
34
|
+
}
|
|
35
|
+
if (Object.keys(payload).length === 1) {
|
|
36
|
+
fatalError("Pass at least one of --prefix or --next-number.", EXIT.USAGE);
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const result = await client.business.updateSequenceNumber(payload);
|
|
40
|
+
if (opts.json) {
|
|
41
|
+
outputJSON(result);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const typeLabel = opts.type === "sale" ? "Sales" : "Purchase";
|
|
45
|
+
const parts = [];
|
|
46
|
+
if (opts.prefix !== void 0) parts.push(`prefix \u2192 "${opts.prefix}"`);
|
|
47
|
+
if (opts.nextNumber !== void 0) parts.push(`next number \u2192 ${opts.nextNumber}`);
|
|
48
|
+
success(`${typeLabel} invoice sequence updated: ${parts.join(", ")}.`);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (e instanceof HisaaboApiError) {
|
|
51
|
+
const err = e.hisaaboError;
|
|
52
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
53
|
+
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
54
|
+
if (err.code === "validation_failed") {
|
|
55
|
+
const msgs = Object.entries(err.fields).map(([f, ms]) => ` ${f}: ${ms.join(", ")}`).join("\n");
|
|
56
|
+
fatalError(`Validation failed:
|
|
57
|
+
${msgs}`, EXIT.VALIDATION);
|
|
58
|
+
}
|
|
59
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
60
|
+
}
|
|
61
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
businessSequenceCommand
|
|
66
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
formatAmount,
|
|
4
|
+
formatDate,
|
|
5
|
+
formatStatus
|
|
6
|
+
} from "./chunk-FFBG6RU4.js";
|
|
7
|
+
import {
|
|
8
|
+
HisaaboApiError,
|
|
9
|
+
HisaaboClient
|
|
10
|
+
} from "./chunk-FTOBDKMO.js";
|
|
11
|
+
import {
|
|
12
|
+
requireAuth
|
|
13
|
+
} from "./chunk-2P35S2C3.js";
|
|
14
|
+
import {
|
|
15
|
+
EXIT,
|
|
16
|
+
fatalError,
|
|
17
|
+
outputJSON,
|
|
18
|
+
outputTable,
|
|
19
|
+
paginationFooter
|
|
20
|
+
} from "./chunk-EYNDY7RB.js";
|
|
21
|
+
|
|
22
|
+
// src/commands/store/index.ts
|
|
23
|
+
async function storeSettingsCommand(opts) {
|
|
24
|
+
const cfg = requireAuth();
|
|
25
|
+
const client = new HisaaboClient(cfg);
|
|
26
|
+
try {
|
|
27
|
+
const settings = await client.store.getSettings();
|
|
28
|
+
if (opts.json) {
|
|
29
|
+
outputJSON(settings);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
console.log("\n Store Settings\n " + "\u2500".repeat(35));
|
|
33
|
+
console.log(` Enabled: ${settings.storeEnabled ? "Yes" : "No"}`);
|
|
34
|
+
if (settings.storeSlug) console.log(` Slug: ${settings.storeSlug}`);
|
|
35
|
+
if (settings.storeName) console.log(` Name: ${settings.storeName}`);
|
|
36
|
+
if (settings.storeDescription) console.log(` About: ${settings.storeDescription}`);
|
|
37
|
+
console.log();
|
|
38
|
+
} catch (e) {
|
|
39
|
+
if (e instanceof HisaaboApiError) {
|
|
40
|
+
const err = e.hisaaboError;
|
|
41
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
42
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
43
|
+
}
|
|
44
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async function storeOrdersCommand(opts) {
|
|
48
|
+
const cfg = requireAuth();
|
|
49
|
+
const client = new HisaaboClient(cfg);
|
|
50
|
+
const page = opts.page ?? 1;
|
|
51
|
+
const limit = opts.limit ?? 20;
|
|
52
|
+
try {
|
|
53
|
+
const result = await client.store.listOrders({ status: opts.status ?? null, page, limit });
|
|
54
|
+
if (opts.json) {
|
|
55
|
+
outputJSON({ data: result.data, pagination: { page: result.page, limit: result.limit, total: result.total } });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
console.log(`
|
|
59
|
+
Store Orders ${result.total} total
|
|
60
|
+
`);
|
|
61
|
+
const cols = [
|
|
62
|
+
{ key: "orderNumber", header: "#", width: 12 },
|
|
63
|
+
{ key: "customerName", header: "Customer", width: 20 },
|
|
64
|
+
{ key: "createdAt", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
|
|
65
|
+
{ key: "totalAmount", header: "Amount (\u20B9)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
66
|
+
{ key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) }
|
|
67
|
+
];
|
|
68
|
+
outputTable(result.data, cols);
|
|
69
|
+
paginationFooter(result.page, result.limit, result.total);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
if (e instanceof HisaaboApiError) {
|
|
72
|
+
const err = e.hisaaboError;
|
|
73
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
74
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
75
|
+
}
|
|
76
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
storeOrdersCommand,
|
|
81
|
+
storeSettingsCommand
|
|
82
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
currentFY,
|
|
4
|
+
formatAmount,
|
|
5
|
+
formatRelativeDate,
|
|
6
|
+
formatStatus,
|
|
7
|
+
fyStart,
|
|
8
|
+
todayISO
|
|
9
|
+
} from "./chunk-FFBG6RU4.js";
|
|
10
|
+
import {
|
|
11
|
+
HisaaboApiError,
|
|
12
|
+
HisaaboClient
|
|
13
|
+
} from "./chunk-FTOBDKMO.js";
|
|
14
|
+
import {
|
|
15
|
+
requireAuth
|
|
16
|
+
} from "./chunk-2P35S2C3.js";
|
|
17
|
+
import {
|
|
18
|
+
EXIT,
|
|
19
|
+
fatalError,
|
|
20
|
+
hasColor,
|
|
21
|
+
outputJSON,
|
|
22
|
+
termWidth
|
|
23
|
+
} from "./chunk-EYNDY7RB.js";
|
|
24
|
+
|
|
25
|
+
// src/commands/dashboard/summary.ts
|
|
26
|
+
import chalk from "chalk";
|
|
27
|
+
function box(title, lines, width) {
|
|
28
|
+
const innerW = width - 2;
|
|
29
|
+
const titleStr = `\u2500 ${title} `;
|
|
30
|
+
const border = "\u250C" + titleStr + "\u2500".repeat(Math.max(1, innerW - titleStr.length)) + "\u2510";
|
|
31
|
+
const bottom = "\u2514" + "\u2500".repeat(innerW) + "\u2518";
|
|
32
|
+
const padded = lines.map((l) => {
|
|
33
|
+
const vis = l.length;
|
|
34
|
+
const pad = Math.max(0, innerW - vis - 1);
|
|
35
|
+
return "\u2502 " + l + " ".repeat(pad) + "\u2502";
|
|
36
|
+
});
|
|
37
|
+
return [border, ...padded, bottom];
|
|
38
|
+
}
|
|
39
|
+
function colorMoney(amount, good = true) {
|
|
40
|
+
if (!hasColor()) return formatAmount(amount);
|
|
41
|
+
const num = parseFloat(amount);
|
|
42
|
+
if (isNaN(num) || num === 0) return chalk.dim(formatAmount(amount));
|
|
43
|
+
if (good) return chalk.green(formatAmount(amount));
|
|
44
|
+
return chalk.red(formatAmount(amount));
|
|
45
|
+
}
|
|
46
|
+
async function dashboardCommand(opts) {
|
|
47
|
+
const cfg = requireAuth();
|
|
48
|
+
const client = new HisaaboClient(cfg);
|
|
49
|
+
const from = fyStart();
|
|
50
|
+
const to = todayISO();
|
|
51
|
+
try {
|
|
52
|
+
const summary = await client.dashboard.summary({ fromDate: from, toDate: to });
|
|
53
|
+
if (opts.json) {
|
|
54
|
+
outputJSON(summary);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const width = Math.min(termWidth() - 2, 70);
|
|
58
|
+
const fy = currentFY();
|
|
59
|
+
console.log();
|
|
60
|
+
console.log(` Hisaabo Dashboard` + " ".repeat(Math.max(2, width - 30)) + (cfg.businessName ?? ""));
|
|
61
|
+
console.log(` FY ${fy} (01 Apr ${fy.split("-")[0]} - 31 Mar 20${fy.split("-")[1]})`);
|
|
62
|
+
console.log(` ${"\u2550".repeat(width)}`);
|
|
63
|
+
console.log();
|
|
64
|
+
const halfW = Math.floor((width - 3) / 2);
|
|
65
|
+
const revLines = [
|
|
66
|
+
`Sales ${formatAmount(summary.totalSales).padStart(12)}`,
|
|
67
|
+
`Cash In ${formatAmount(summary.cashInHand).padStart(12)}`
|
|
68
|
+
];
|
|
69
|
+
const expLines = [
|
|
70
|
+
`Purchases ${formatAmount(summary.totalPurchases).padStart(11)}`,
|
|
71
|
+
`Expenses ${formatAmount(summary.totalExpenses).padStart(11)}`
|
|
72
|
+
];
|
|
73
|
+
const revBox = box("Revenue", revLines, halfW);
|
|
74
|
+
const expBox = box("Expenses", expLines, halfW);
|
|
75
|
+
for (let i = 0; i < Math.max(revBox.length, expBox.length); i++) {
|
|
76
|
+
const l = (revBox[i] ?? "").padEnd(halfW);
|
|
77
|
+
const r = expBox[i] ?? "";
|
|
78
|
+
console.log(` ${l} ${r}`);
|
|
79
|
+
}
|
|
80
|
+
console.log();
|
|
81
|
+
const net = parseFloat(summary.receivable) - parseFloat(summary.payable);
|
|
82
|
+
const netLabel = net >= 0 ? "receivable" : "payable";
|
|
83
|
+
const outLines = [
|
|
84
|
+
`Receivable ${colorMoney(summary.receivable)}`,
|
|
85
|
+
`Payable ${colorMoney(summary.payable, false)}`,
|
|
86
|
+
`Net Position ${colorMoney(String(Math.abs(net)))} ${netLabel}`
|
|
87
|
+
];
|
|
88
|
+
const outBox = box("Outstanding", outLines, width);
|
|
89
|
+
outBox.forEach((l) => console.log(` ${l}`));
|
|
90
|
+
console.log();
|
|
91
|
+
const recentLines = summary.recentInvoices.slice(0, 5).map((inv) => {
|
|
92
|
+
const num = inv.invoiceNumber.padEnd(10);
|
|
93
|
+
const party = inv.partyName.slice(0, 16).padEnd(18);
|
|
94
|
+
const amt = formatAmount(inv.totalAmount).padStart(12);
|
|
95
|
+
const status = formatStatus(inv.status).padEnd(10);
|
|
96
|
+
const rel = formatRelativeDate(inv.invoiceDate).padEnd(7);
|
|
97
|
+
return `${num} ${party} ${amt} ${status} ${rel}`;
|
|
98
|
+
});
|
|
99
|
+
const recentBox = box("Recent Invoices", recentLines, width);
|
|
100
|
+
recentBox.forEach((l) => console.log(` ${l}`));
|
|
101
|
+
console.log();
|
|
102
|
+
} catch (e) {
|
|
103
|
+
if (e instanceof HisaaboApiError) {
|
|
104
|
+
const err = e.hisaaboError;
|
|
105
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
106
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
107
|
+
}
|
|
108
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export {
|
|
112
|
+
dashboardCommand
|
|
113
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
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/top-customers.ts
|
|
27
|
+
import chalk from "chalk";
|
|
28
|
+
async function dashboardTopCustomersCommand(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.topCustomers({
|
|
42
|
+
limit: opts.limit,
|
|
43
|
+
fromDate,
|
|
44
|
+
toDate
|
|
45
|
+
});
|
|
46
|
+
if (opts.json) {
|
|
47
|
+
outputJSON(data);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const rows = Array.isArray(data) ? data.map((r) => ({
|
|
51
|
+
party: String(r["partyName"] ?? r["party"] ?? "-"),
|
|
52
|
+
revenue: formatAmount(String(r["revenue"] ?? r["totalRevenue"] ?? r["totalSales"] ?? "0")),
|
|
53
|
+
invoices: String(r["invoiceCount"] ?? r["invoices"] ?? "-")
|
|
54
|
+
})) : [];
|
|
55
|
+
const columns = [
|
|
56
|
+
{ key: "party", header: "Customer", align: "left" },
|
|
57
|
+
{ key: "revenue", header: "Revenue \u20B9", align: "right" },
|
|
58
|
+
{ key: "invoices", header: "Invoices", align: "right" }
|
|
59
|
+
];
|
|
60
|
+
if (opts.format === "tsv") {
|
|
61
|
+
outputTSV(rows, columns);
|
|
62
|
+
} else if (opts.format === "csv") {
|
|
63
|
+
outputCSV(rows, columns);
|
|
64
|
+
} else {
|
|
65
|
+
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Top Customers by Revenue\n") + "\n");
|
|
66
|
+
else process.stdout.write("\n Top Customers by Revenue\n\n");
|
|
67
|
+
outputTable(rows, columns);
|
|
68
|
+
process.stdout.write("\n");
|
|
69
|
+
}
|
|
70
|
+
} catch (e) {
|
|
71
|
+
if (e instanceof HisaaboApiError) {
|
|
72
|
+
const err = e.hisaaboError;
|
|
73
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
74
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
75
|
+
}
|
|
76
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
dashboardTopCustomersCommand
|
|
81
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
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/top-items.ts
|
|
27
|
+
import chalk from "chalk";
|
|
28
|
+
async function dashboardTopItemsCommand(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.topSellingItems({
|
|
42
|
+
limit: opts.limit,
|
|
43
|
+
itemType: opts.type,
|
|
44
|
+
fromDate,
|
|
45
|
+
toDate
|
|
46
|
+
});
|
|
47
|
+
if (opts.json) {
|
|
48
|
+
outputJSON(data);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const rows = Array.isArray(data) ? data.map((r) => ({
|
|
52
|
+
item: String(r["itemName"] ?? r["name"] ?? "-"),
|
|
53
|
+
qty: String(r["totalQuantity"] ?? r["qty"] ?? r["quantity"] ?? "-"),
|
|
54
|
+
revenue: formatAmount(String(r["totalRevenue"] ?? r["revenue"] ?? "0")),
|
|
55
|
+
type: String(r["itemType"] ?? r["type"] ?? "-")
|
|
56
|
+
})) : [];
|
|
57
|
+
const columns = [
|
|
58
|
+
{ key: "item", header: "Item", align: "left" },
|
|
59
|
+
{ key: "type", header: "Type", align: "left" },
|
|
60
|
+
{ key: "qty", header: "Qty Sold", align: "right" },
|
|
61
|
+
{ key: "revenue", header: "Revenue \u20B9", align: "right" }
|
|
62
|
+
];
|
|
63
|
+
if (opts.format === "tsv") {
|
|
64
|
+
outputTSV(rows, columns);
|
|
65
|
+
} else if (opts.format === "csv") {
|
|
66
|
+
outputCSV(rows, columns);
|
|
67
|
+
} else {
|
|
68
|
+
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Top Selling Items\n") + "\n");
|
|
69
|
+
else process.stdout.write("\n Top Selling Items\n\n");
|
|
70
|
+
outputTable(rows, columns);
|
|
71
|
+
process.stdout.write("\n");
|
|
72
|
+
}
|
|
73
|
+
} catch (e) {
|
|
74
|
+
if (e instanceof HisaaboApiError) {
|
|
75
|
+
const err = e.hisaaboError;
|
|
76
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
77
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
78
|
+
}
|
|
79
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
dashboardTopItemsCommand
|
|
84
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
formatAmount
|
|
4
|
+
} from "./chunk-FFBG6RU4.js";
|
|
5
|
+
import {
|
|
6
|
+
HisaaboApiError,
|
|
7
|
+
HisaaboClient
|
|
8
|
+
} from "./chunk-FTOBDKMO.js";
|
|
9
|
+
import {
|
|
10
|
+
requireAuth
|
|
11
|
+
} from "./chunk-2P35S2C3.js";
|
|
12
|
+
import {
|
|
13
|
+
EXIT,
|
|
14
|
+
fatalError,
|
|
15
|
+
hasColor,
|
|
16
|
+
outputCSV,
|
|
17
|
+
outputJSON,
|
|
18
|
+
outputTSV,
|
|
19
|
+
outputTable
|
|
20
|
+
} from "./chunk-EYNDY7RB.js";
|
|
21
|
+
|
|
22
|
+
// src/commands/dashboard/top-outstanding.ts
|
|
23
|
+
import chalk from "chalk";
|
|
24
|
+
async function dashboardTopOutstandingCommand(opts) {
|
|
25
|
+
const cfg = requireAuth();
|
|
26
|
+
const client = new HisaaboClient(cfg);
|
|
27
|
+
try {
|
|
28
|
+
const data = await client.dashboard.topOutstanding({ limit: opts.limit });
|
|
29
|
+
if (opts.json) {
|
|
30
|
+
outputJSON(data);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const rows = Array.isArray(data) ? data.map((r) => ({
|
|
34
|
+
party: String(r["partyName"] ?? r["party"] ?? "-"),
|
|
35
|
+
outstanding: formatAmount(String(r["outstanding"] ?? r["outstandingAmount"] ?? "0")),
|
|
36
|
+
oldestAge: r["oldestInvoiceDays"] != null ? `${r["oldestInvoiceDays"]}d` : r["oldestAge"] != null ? `${r["oldestAge"]}d` : "-"
|
|
37
|
+
})) : [];
|
|
38
|
+
const columns = [
|
|
39
|
+
{ key: "party", header: "Party", align: "left" },
|
|
40
|
+
{ key: "outstanding", header: "Outstanding \u20B9", align: "right" },
|
|
41
|
+
{ key: "oldestAge", header: "Oldest Invoice", align: "right" }
|
|
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
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
dashboardTopOutstandingCommand
|
|
64
|
+
};
|