@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,53 @@
|
|
|
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/store/order-confirm.ts
|
|
17
|
+
import * as readline from "readline";
|
|
18
|
+
async function storeOrderConfirmCommand(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(` Confirm order ${id}? (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.store.confirmOrder({ orderId: id });
|
|
34
|
+
if (opts.json) {
|
|
35
|
+
outputJSON(result);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
success(`Order ${id} confirmed`);
|
|
39
|
+
console.log();
|
|
40
|
+
} catch (e) {
|
|
41
|
+
if (e instanceof HisaaboApiError) {
|
|
42
|
+
const err = e.hisaaboError;
|
|
43
|
+
if (err.code === "not_found") fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
|
|
44
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
45
|
+
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
46
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
47
|
+
}
|
|
48
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
storeOrderConfirmCommand
|
|
53
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
hasColor,
|
|
18
|
+
outputJSON
|
|
19
|
+
} from "./chunk-EYNDY7RB.js";
|
|
20
|
+
|
|
21
|
+
// src/commands/store/order-get.ts
|
|
22
|
+
import chalk from "chalk";
|
|
23
|
+
async function storeOrderGetCommand(id, opts) {
|
|
24
|
+
const cfg = requireAuth();
|
|
25
|
+
const client = new HisaaboClient(cfg);
|
|
26
|
+
try {
|
|
27
|
+
const order = await client.store.getOrder(id);
|
|
28
|
+
if (!order) {
|
|
29
|
+
fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
|
|
30
|
+
}
|
|
31
|
+
if (opts.json) {
|
|
32
|
+
outputJSON(order);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const sep = "\u2500".repeat(40);
|
|
36
|
+
const title = `Order #${order.orderNumber}`;
|
|
37
|
+
if (hasColor()) {
|
|
38
|
+
process.stdout.write(`
|
|
39
|
+
${chalk.bold(title)}
|
|
40
|
+
`);
|
|
41
|
+
} else {
|
|
42
|
+
process.stdout.write(`
|
|
43
|
+
${title}
|
|
44
|
+
`);
|
|
45
|
+
}
|
|
46
|
+
process.stdout.write(` ${sep}
|
|
47
|
+
`);
|
|
48
|
+
process.stdout.write(` Customer: ${order.customerName}
|
|
49
|
+
`);
|
|
50
|
+
process.stdout.write(` Date: ${formatDate(order.createdAt)}
|
|
51
|
+
`);
|
|
52
|
+
process.stdout.write(` Status: ${formatStatus(order.status)}
|
|
53
|
+
`);
|
|
54
|
+
process.stdout.write(` Total: \u20B9${formatAmount(order.totalAmount)}
|
|
55
|
+
`);
|
|
56
|
+
if (order.shippingAddress) {
|
|
57
|
+
process.stdout.write(` Address: ${order.shippingAddress}
|
|
58
|
+
`);
|
|
59
|
+
}
|
|
60
|
+
if (order.notes) {
|
|
61
|
+
process.stdout.write(` Notes: ${order.notes}
|
|
62
|
+
`);
|
|
63
|
+
}
|
|
64
|
+
if (order.items && order.items.length > 0) {
|
|
65
|
+
process.stdout.write(`
|
|
66
|
+
Items:
|
|
67
|
+
`);
|
|
68
|
+
for (const item of order.items) {
|
|
69
|
+
process.stdout.write(
|
|
70
|
+
` \u2022 ${item.name} qty: ${item.quantity} \u20B9${formatAmount(item.price)}
|
|
71
|
+
`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
process.stdout.write("\n");
|
|
76
|
+
} catch (e) {
|
|
77
|
+
if (e instanceof HisaaboApiError) {
|
|
78
|
+
const err = e.hisaaboError;
|
|
79
|
+
if (err.code === "not_found") fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
|
|
80
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
81
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
82
|
+
}
|
|
83
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
storeOrderGetCommand
|
|
88
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
formatStatus
|
|
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
|
+
outputJSON,
|
|
16
|
+
success
|
|
17
|
+
} from "./chunk-EYNDY7RB.js";
|
|
18
|
+
|
|
19
|
+
// src/commands/store/order-update.ts
|
|
20
|
+
var VALID_STATUSES = ["preparing", "ready", "delivered"];
|
|
21
|
+
async function storeOrderUpdateCommand(id, opts) {
|
|
22
|
+
const cfg = requireAuth();
|
|
23
|
+
const client = new HisaaboClient(cfg);
|
|
24
|
+
if (!opts.status) {
|
|
25
|
+
fatalError(
|
|
26
|
+
`--status is required. Valid values: ${VALID_STATUSES.join(", ")}`,
|
|
27
|
+
EXIT.USAGE
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
if (!VALID_STATUSES.includes(opts.status)) {
|
|
31
|
+
fatalError(
|
|
32
|
+
`Invalid status "${opts.status}". Valid values: ${VALID_STATUSES.join(", ")}`,
|
|
33
|
+
EXIT.VALIDATION
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const result = await client.store.updateOrder({
|
|
38
|
+
orderId: id,
|
|
39
|
+
status: opts.status
|
|
40
|
+
});
|
|
41
|
+
if (opts.json) {
|
|
42
|
+
outputJSON(result);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
success(`Order ${id} status updated to ${formatStatus(result.status ?? opts.status)}`);
|
|
46
|
+
console.log();
|
|
47
|
+
} catch (e) {
|
|
48
|
+
if (e instanceof HisaaboApiError) {
|
|
49
|
+
const err = e.hisaaboError;
|
|
50
|
+
if (err.code === "not_found") fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
|
|
51
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
52
|
+
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
53
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
54
|
+
}
|
|
55
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
storeOrderUpdateCommand
|
|
60
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
EXIT,
|
|
4
|
+
fatalError,
|
|
5
|
+
getWidthTier,
|
|
6
|
+
hasColor,
|
|
7
|
+
isInteractive,
|
|
8
|
+
outputCSV,
|
|
9
|
+
outputIds,
|
|
10
|
+
outputJSON,
|
|
11
|
+
outputTSV,
|
|
12
|
+
outputTable,
|
|
13
|
+
paginationFooter,
|
|
14
|
+
stripAnsi,
|
|
15
|
+
success,
|
|
16
|
+
termWidth,
|
|
17
|
+
warn
|
|
18
|
+
} from "./chunk-EYNDY7RB.js";
|
|
19
|
+
export {
|
|
20
|
+
EXIT,
|
|
21
|
+
fatalError,
|
|
22
|
+
getWidthTier,
|
|
23
|
+
hasColor,
|
|
24
|
+
isInteractive,
|
|
25
|
+
outputCSV,
|
|
26
|
+
outputIds,
|
|
27
|
+
outputJSON,
|
|
28
|
+
outputTSV,
|
|
29
|
+
outputTable,
|
|
30
|
+
paginationFooter,
|
|
31
|
+
stripAnsi,
|
|
32
|
+
success,
|
|
33
|
+
termWidth,
|
|
34
|
+
warn
|
|
35
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
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/payment-modes.ts
|
|
27
|
+
import chalk from "chalk";
|
|
28
|
+
var MODE_LABELS = {
|
|
29
|
+
cash: "Cash",
|
|
30
|
+
upi: "UPI",
|
|
31
|
+
bank_transfer: "Bank Transfer",
|
|
32
|
+
cheque: "Cheque",
|
|
33
|
+
card: "Card",
|
|
34
|
+
neft: "NEFT",
|
|
35
|
+
rtgs: "RTGS",
|
|
36
|
+
imps: "IMPS",
|
|
37
|
+
dd: "Demand Draft",
|
|
38
|
+
credit: "Credit",
|
|
39
|
+
other: "Other"
|
|
40
|
+
};
|
|
41
|
+
function modeLabel(raw) {
|
|
42
|
+
return MODE_LABELS[raw.toLowerCase()] ?? raw;
|
|
43
|
+
}
|
|
44
|
+
async function dashboardPaymentModesCommand(opts) {
|
|
45
|
+
const cfg = requireAuth();
|
|
46
|
+
const client = new HisaaboClient(cfg);
|
|
47
|
+
let fromDate = opts.from;
|
|
48
|
+
let toDate = opts.to;
|
|
49
|
+
if (opts.thisMonth) {
|
|
50
|
+
fromDate = monthStart();
|
|
51
|
+
toDate = monthEnd();
|
|
52
|
+
} else if (opts.thisFy) {
|
|
53
|
+
fromDate = fyStart();
|
|
54
|
+
toDate = todayISO();
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const data = await client.dashboard.paymentModeBreakdown({ fromDate, toDate });
|
|
58
|
+
if (opts.json) {
|
|
59
|
+
outputJSON(data);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
let modes = [];
|
|
63
|
+
if (Array.isArray(data)) {
|
|
64
|
+
modes = data.map((r) => ({
|
|
65
|
+
mode: String(r["mode"] ?? r["paymentMode"] ?? r["method"] ?? "-"),
|
|
66
|
+
amount: parseFloat(String(r["amount"] ?? r["totalAmount"] ?? "0")),
|
|
67
|
+
count: parseInt(String(r["count"] ?? r["paymentCount"] ?? "0"), 10)
|
|
68
|
+
}));
|
|
69
|
+
} else if (data && typeof data === "object") {
|
|
70
|
+
const obj = data;
|
|
71
|
+
for (const [key, val] of Object.entries(obj)) {
|
|
72
|
+
if (typeof val === "object" && val !== null) {
|
|
73
|
+
const entry = val;
|
|
74
|
+
modes.push({
|
|
75
|
+
mode: key,
|
|
76
|
+
amount: parseFloat(String(entry["amount"] ?? entry["totalAmount"] ?? "0")),
|
|
77
|
+
count: parseInt(String(entry["count"] ?? "0"), 10)
|
|
78
|
+
});
|
|
79
|
+
} else if (typeof val === "string" || typeof val === "number") {
|
|
80
|
+
modes.push({ mode: key, amount: parseFloat(String(val)), count: 0 });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
modes.sort((a, b) => b.amount - a.amount);
|
|
85
|
+
const total = modes.reduce((s, r) => s + r.amount, 0);
|
|
86
|
+
const rows = modes.map((r) => {
|
|
87
|
+
const pct = total > 0 ? (r.amount / total * 100).toFixed(1) + "%" : "-";
|
|
88
|
+
return {
|
|
89
|
+
mode: modeLabel(r.mode),
|
|
90
|
+
amount: formatAmount(r.amount),
|
|
91
|
+
count: r.count > 0 ? String(r.count) : "-",
|
|
92
|
+
pct
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
const columns = [
|
|
96
|
+
{ key: "mode", header: "Payment Mode", align: "left" },
|
|
97
|
+
{ key: "amount", header: "Amount \u20B9", align: "right" },
|
|
98
|
+
{ key: "count", header: "Count", align: "right" },
|
|
99
|
+
{ key: "pct", header: "% of Total", align: "right" }
|
|
100
|
+
];
|
|
101
|
+
if (opts.format === "tsv") {
|
|
102
|
+
outputTSV(rows, columns);
|
|
103
|
+
} else if (opts.format === "csv") {
|
|
104
|
+
outputCSV(rows, columns);
|
|
105
|
+
} else {
|
|
106
|
+
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Payment Mode Breakdown\n") + "\n");
|
|
107
|
+
else process.stdout.write("\n Payment Mode Breakdown\n\n");
|
|
108
|
+
outputTable(rows, columns);
|
|
109
|
+
if (total > 0) {
|
|
110
|
+
const totalStr = ` Total: \u20B9${formatAmount(total)}`;
|
|
111
|
+
process.stdout.write("\n" + (hasColor() ? chalk.bold(totalStr) : totalStr) + "\n");
|
|
112
|
+
}
|
|
113
|
+
process.stdout.write("\n");
|
|
114
|
+
}
|
|
115
|
+
} catch (e) {
|
|
116
|
+
if (e instanceof HisaaboApiError) {
|
|
117
|
+
const err = e.hisaaboError;
|
|
118
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
119
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
120
|
+
}
|
|
121
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
dashboardPaymentModesCommand
|
|
126
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
formatDate,
|
|
4
|
+
formatINR,
|
|
5
|
+
fyStart,
|
|
6
|
+
monthEnd,
|
|
7
|
+
monthStart,
|
|
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/profit-loss.ts
|
|
26
|
+
import chalk from "chalk";
|
|
27
|
+
function plLine(label, value, innerW, opts = {}) {
|
|
28
|
+
const indent = opts.indent ?? 0;
|
|
29
|
+
const indentStr = " ".repeat(indent * 2);
|
|
30
|
+
const fullLabel = indentStr + label;
|
|
31
|
+
const rightPad = 2;
|
|
32
|
+
const maxValueLen = 18;
|
|
33
|
+
const labelWidth = innerW - maxValueLen - rightPad;
|
|
34
|
+
const truncLabel = fullLabel.length > labelWidth ? fullLabel.slice(0, labelWidth - 1) + "\u2026" : fullLabel;
|
|
35
|
+
const paddedLabel = truncLabel.padEnd(labelWidth);
|
|
36
|
+
const paddedValue = value.padStart(maxValueLen - rightPad) + " ".repeat(rightPad);
|
|
37
|
+
let line = `\u2502 ${paddedLabel}${paddedValue}\u2502`;
|
|
38
|
+
if (!hasColor()) return line;
|
|
39
|
+
if (opts.bold) line = line.replace(paddedLabel, chalk.bold(truncLabel.padEnd(labelWidth)));
|
|
40
|
+
if (opts.dim) line = chalk.dim(line);
|
|
41
|
+
return line;
|
|
42
|
+
}
|
|
43
|
+
function plSeparator(innerW) {
|
|
44
|
+
const dashLen = 18;
|
|
45
|
+
const leftPad = innerW - dashLen;
|
|
46
|
+
const line = `\u2502 ${" ".repeat(leftPad - 1)}${"\u2500".repeat(dashLen)} \u2502`;
|
|
47
|
+
return hasColor() ? chalk.dim(line) : line;
|
|
48
|
+
}
|
|
49
|
+
function plBlank(innerW) {
|
|
50
|
+
return `\u2502 ${" ".repeat(innerW)} \u2502`;
|
|
51
|
+
}
|
|
52
|
+
function plBorder(innerW, char) {
|
|
53
|
+
const side = char === "\u250C" ? "\u2510" : "\u2518";
|
|
54
|
+
return char + "\u2500".repeat(innerW) + side;
|
|
55
|
+
}
|
|
56
|
+
function plTitle(title, innerW) {
|
|
57
|
+
const pad = Math.max(0, innerW - title.length - 2);
|
|
58
|
+
const line = `\u2502 ${hasColor() ? chalk.bold(title) : title}${" ".repeat(pad)} \u2502`;
|
|
59
|
+
return line;
|
|
60
|
+
}
|
|
61
|
+
function formatPL(amount) {
|
|
62
|
+
if (amount < 0) return `(${formatINR(Math.abs(amount))})`;
|
|
63
|
+
return formatINR(amount);
|
|
64
|
+
}
|
|
65
|
+
function colorPL(formatted, isProfit) {
|
|
66
|
+
if (!hasColor()) return formatted;
|
|
67
|
+
const num = parseFloat(formatted.replace(/[₹,()]/g, ""));
|
|
68
|
+
if (isNaN(num) || num === 0) return chalk.dim(formatted);
|
|
69
|
+
return isProfit ? chalk.green(formatted) : chalk.red(formatted);
|
|
70
|
+
}
|
|
71
|
+
async function dashboardProfitLossCommand(opts) {
|
|
72
|
+
const cfg = requireAuth();
|
|
73
|
+
const client = new HisaaboClient(cfg);
|
|
74
|
+
let fromDate = opts.from ?? fyStart();
|
|
75
|
+
let toDate = opts.to ?? todayISO();
|
|
76
|
+
if (opts.thisMonth) {
|
|
77
|
+
fromDate = monthStart();
|
|
78
|
+
toDate = monthEnd();
|
|
79
|
+
} else if (opts.thisFy) {
|
|
80
|
+
fromDate = fyStart();
|
|
81
|
+
toDate = todayISO();
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const data = await client.dashboard.profitAndLoss({ fromDate, toDate });
|
|
85
|
+
if (opts.json) {
|
|
86
|
+
outputJSON(data);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const pl = data;
|
|
90
|
+
const revenue = parseFloat(String(pl["revenue"] ?? pl["totalRevenue"] ?? pl["sales"] ?? "0"));
|
|
91
|
+
const cogs = parseFloat(String(pl["cogs"] ?? pl["costOfGoodsSold"] ?? pl["purchases"] ?? "0"));
|
|
92
|
+
const grossProfit = parseFloat(String(pl["grossProfit"] ?? String(revenue - cogs)));
|
|
93
|
+
const opex = parseFloat(String(pl["operatingExpenses"] ?? pl["expenses"] ?? pl["totalExpenses"] ?? "0"));
|
|
94
|
+
const netProfit = parseFloat(String(pl["netProfit"] ?? pl["profit"] ?? String(grossProfit - opex)));
|
|
95
|
+
const grossMargin = revenue > 0 ? (grossProfit / revenue * 100).toFixed(1) + "%" : "-";
|
|
96
|
+
const netMargin = revenue > 0 ? (netProfit / revenue * 100).toFixed(1) + "%" : "-";
|
|
97
|
+
const width = Math.min(termWidth() - 2, 52);
|
|
98
|
+
const innerW = width - 2;
|
|
99
|
+
const lines = [];
|
|
100
|
+
lines.push(plBorder(innerW, "\u250C"));
|
|
101
|
+
lines.push(plTitle("PROFIT & LOSS STATEMENT", innerW));
|
|
102
|
+
lines.push(plTitle(`${formatDate(fromDate)} \u2013 ${formatDate(toDate)}`, innerW));
|
|
103
|
+
lines.push(`\u251C${"\u2500".repeat(innerW)}\u2524`);
|
|
104
|
+
lines.push(plBlank(innerW));
|
|
105
|
+
lines.push(plLine("Revenue", formatPL(revenue), innerW, { bold: true }));
|
|
106
|
+
lines.push(plLine("Cost of Goods Sold", formatPL(-cogs), innerW));
|
|
107
|
+
lines.push(plSeparator(innerW));
|
|
108
|
+
const gpFormatted = formatPL(grossProfit);
|
|
109
|
+
lines.push(plLine("Gross Profit", colorPL(gpFormatted, grossProfit >= 0), innerW, { bold: true }));
|
|
110
|
+
lines.push(plLine("Gross Margin", grossMargin, innerW, { dim: true }));
|
|
111
|
+
lines.push(plBlank(innerW));
|
|
112
|
+
lines.push(plLine("Operating Expenses", formatPL(-opex), innerW));
|
|
113
|
+
lines.push(plSeparator(innerW));
|
|
114
|
+
const npFormatted = formatPL(netProfit);
|
|
115
|
+
lines.push(plLine("Net Profit", colorPL(npFormatted, netProfit >= 0), innerW, { bold: true }));
|
|
116
|
+
lines.push(plLine("Net Margin", netMargin, innerW, { dim: true }));
|
|
117
|
+
lines.push(plBlank(innerW));
|
|
118
|
+
lines.push(plBorder(innerW, "\u2514"));
|
|
119
|
+
process.stdout.write("\n");
|
|
120
|
+
for (const l of lines) {
|
|
121
|
+
process.stdout.write(" " + l + "\n");
|
|
122
|
+
}
|
|
123
|
+
process.stdout.write("\n");
|
|
124
|
+
} catch (e) {
|
|
125
|
+
if (e instanceof HisaaboApiError) {
|
|
126
|
+
const err = e.hisaaboError;
|
|
127
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
128
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
129
|
+
}
|
|
130
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export {
|
|
134
|
+
dashboardProfitLossCommand
|
|
135
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
termWidth
|
|
21
|
+
} from "./chunk-EYNDY7RB.js";
|
|
22
|
+
|
|
23
|
+
// src/commands/dashboard/receivables-aging.ts
|
|
24
|
+
import chalk from "chalk";
|
|
25
|
+
function agingBar(amount, maxAmount, barWidth) {
|
|
26
|
+
if (maxAmount <= 0 || amount <= 0) return "";
|
|
27
|
+
const filled = Math.round(amount / maxAmount * barWidth);
|
|
28
|
+
return "\u2588".repeat(filled) + "\u2591".repeat(barWidth - filled);
|
|
29
|
+
}
|
|
30
|
+
async function dashboardReceivablesAgingCommand(opts) {
|
|
31
|
+
const cfg = requireAuth();
|
|
32
|
+
const client = new HisaaboClient(cfg);
|
|
33
|
+
try {
|
|
34
|
+
const data = await client.dashboard.receivablesAging();
|
|
35
|
+
if (opts.json) {
|
|
36
|
+
outputJSON(data);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const BUCKETS = [
|
|
40
|
+
{ key: "current", label: "Current (not due)" },
|
|
41
|
+
{ key: "1_30", label: "1\u201330 days" },
|
|
42
|
+
{ key: "31_60", label: "31\u201360 days" },
|
|
43
|
+
{ key: "61_90", label: "61\u201390 days" },
|
|
44
|
+
{ key: "90_plus", label: "90+ days" }
|
|
45
|
+
];
|
|
46
|
+
let bucketData = [];
|
|
47
|
+
if (Array.isArray(data)) {
|
|
48
|
+
bucketData = data.map((r) => ({
|
|
49
|
+
bucket: String(r["bucket"] ?? r["range"] ?? r["label"] ?? "-"),
|
|
50
|
+
amount: parseFloat(String(r["amount"] ?? r["totalAmount"] ?? "0")),
|
|
51
|
+
count: parseInt(String(r["count"] ?? r["invoiceCount"] ?? "0"), 10)
|
|
52
|
+
}));
|
|
53
|
+
} else if (data && typeof data === "object") {
|
|
54
|
+
const obj = data;
|
|
55
|
+
for (const { key, label } of BUCKETS) {
|
|
56
|
+
const entry = obj[key] ?? obj[label];
|
|
57
|
+
if (entry != null) {
|
|
58
|
+
bucketData.push({
|
|
59
|
+
bucket: label,
|
|
60
|
+
amount: parseFloat(String(entry["amount"] ?? entry["totalAmount"] ?? "0")),
|
|
61
|
+
count: parseInt(String(entry["count"] ?? entry["invoiceCount"] ?? "0"), 10)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (bucketData.length === 0) {
|
|
66
|
+
for (const { key, label } of BUCKETS) {
|
|
67
|
+
const val = obj[key];
|
|
68
|
+
if (val != null) {
|
|
69
|
+
bucketData.push({
|
|
70
|
+
bucket: label,
|
|
71
|
+
amount: parseFloat(String(val)),
|
|
72
|
+
count: 0
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (opts.format === "tsv" || opts.format === "csv") {
|
|
79
|
+
const rows = bucketData.map((r) => ({
|
|
80
|
+
bucket: r.bucket,
|
|
81
|
+
amount: formatAmount(r.amount),
|
|
82
|
+
count: String(r.count || "-")
|
|
83
|
+
}));
|
|
84
|
+
const columns = [
|
|
85
|
+
{ key: "bucket", header: "Aging Bucket", align: "left" },
|
|
86
|
+
{ key: "amount", header: "Amount \u20B9", align: "right" },
|
|
87
|
+
{ key: "count", header: "Invoices", align: "right" }
|
|
88
|
+
];
|
|
89
|
+
if (opts.format === "tsv") outputTSV(rows, columns);
|
|
90
|
+
else outputCSV(rows, columns);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const total = bucketData.reduce((s, r) => s + r.amount, 0);
|
|
94
|
+
const maxAmount = Math.max(...bucketData.map((r) => r.amount), 1);
|
|
95
|
+
const width = Math.min(termWidth() - 4, 60);
|
|
96
|
+
const innerW = width - 2;
|
|
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
|
+
process.stdout.write(" \u250C" + "\u2500".repeat(innerW) + "\u2510\n");
|
|
104
|
+
const labelW = 22;
|
|
105
|
+
const amtW = 16;
|
|
106
|
+
const barW = Math.max(4, innerW - labelW - amtW - 5);
|
|
107
|
+
for (const row of bucketData) {
|
|
108
|
+
const pct = total > 0 ? (row.amount / total * 100).toFixed(1) : "0.0";
|
|
109
|
+
const label = row.bucket.padEnd(labelW).slice(0, labelW);
|
|
110
|
+
const amtStr = formatAmount(row.amount).padStart(amtW);
|
|
111
|
+
const bar = agingBar(row.amount, maxAmount, barW);
|
|
112
|
+
let coloredBar = bar;
|
|
113
|
+
let coloredLabel = label;
|
|
114
|
+
if (hasColor()) {
|
|
115
|
+
const idx = bucketData.indexOf(row);
|
|
116
|
+
const colors = [chalk.green, chalk.yellow, chalk.yellow, chalk.red, chalk.red];
|
|
117
|
+
const labelColors = [chalk.green, chalk.yellow, chalk.yellow, chalk.red, (s) => chalk.bold(chalk.red(s))];
|
|
118
|
+
const colorFn = colors[idx] ?? chalk.white;
|
|
119
|
+
const labelFn = labelColors[idx] ?? chalk.white;
|
|
120
|
+
coloredBar = colorFn(bar);
|
|
121
|
+
coloredLabel = labelFn(label);
|
|
122
|
+
}
|
|
123
|
+
const pctStr = `${pct}%`.padStart(6);
|
|
124
|
+
process.stdout.write(` \u2502 ${coloredLabel} ${coloredBar} ${amtStr} ${pctStr} \u2502
|
|
125
|
+
`);
|
|
126
|
+
}
|
|
127
|
+
process.stdout.write(" \u251C" + "\u2500".repeat(innerW) + "\u2524\n");
|
|
128
|
+
const totalLabel = "Total Receivables".padEnd(labelW);
|
|
129
|
+
const totalAmt = formatAmount(total).padStart(amtW);
|
|
130
|
+
const totalLine = ` \u2502 ${hasColor() ? chalk.bold(totalLabel) : totalLabel} ${" ".repeat(barW)} ${hasColor() ? chalk.bold(totalAmt) : totalAmt} \u2502`;
|
|
131
|
+
process.stdout.write(totalLine + "\n");
|
|
132
|
+
process.stdout.write(" \u2514" + "\u2500".repeat(innerW) + "\u2518\n\n");
|
|
133
|
+
if (bucketData.length === 0) {
|
|
134
|
+
process.stdout.write(" No receivables data available.\n\n");
|
|
135
|
+
}
|
|
136
|
+
if (bucketData.some((r) => r.count > 0)) {
|
|
137
|
+
const rows = bucketData.map((r) => ({
|
|
138
|
+
bucket: r.bucket,
|
|
139
|
+
amount: formatAmount(r.amount),
|
|
140
|
+
count: String(r.count)
|
|
141
|
+
}));
|
|
142
|
+
const columns = [
|
|
143
|
+
{ key: "bucket", header: "Aging Bucket", align: "left" },
|
|
144
|
+
{ key: "amount", header: "Amount \u20B9", align: "right" },
|
|
145
|
+
{ key: "count", header: "Invoices", align: "right" }
|
|
146
|
+
];
|
|
147
|
+
outputTable(rows, columns);
|
|
148
|
+
process.stdout.write("\n");
|
|
149
|
+
}
|
|
150
|
+
} catch (e) {
|
|
151
|
+
if (e instanceof HisaaboApiError) {
|
|
152
|
+
const err = e.hisaaboError;
|
|
153
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
154
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
155
|
+
}
|
|
156
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
export {
|
|
160
|
+
dashboardReceivablesAgingCommand
|
|
161
|
+
};
|