@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.
Files changed (146) hide show
  1. package/README.md +332 -0
  2. package/dist/bin/audit-trail-2YGXGUXW.js +78 -0
  3. package/dist/bin/categories-P5VFWD5F.js +47 -0
  4. package/dist/bin/check-slug-4TMOTWUJ.js +65 -0
  5. package/dist/bin/chunk-2P35S2C3.js +46 -0
  6. package/dist/bin/chunk-EYNDY7RB.js +175 -0
  7. package/dist/bin/chunk-FFBG6RU4.js +156 -0
  8. package/dist/bin/chunk-FTOBDKMO.js +804 -0
  9. package/dist/bin/client-QNJ2H5CW.js +11 -0
  10. package/dist/bin/collection-efficiency-WMKEGS6U.js +165 -0
  11. package/dist/bin/config-UKVQYPPR.js +18 -0
  12. package/dist/bin/create-Y22FAVOW.js +83 -0
  13. package/dist/bin/default-account-SA56M66A.js +58 -0
  14. package/dist/bin/expenses-VZAOLYUW.js +89 -0
  15. package/dist/bin/export-QZ6WT6PJ.js +59 -0
  16. package/dist/bin/factory-2DCU3B5T.js +483 -0
  17. package/dist/bin/get-6UYP6UVD.js +71 -0
  18. package/dist/bin/get-EXL44I2X.js +66 -0
  19. package/dist/bin/hisaabo.js +2029 -1450
  20. package/dist/bin/invite-O26SAL72.js +53 -0
  21. package/dist/bin/invoice-breakdown-XEATXVMR.js +97 -0
  22. package/dist/bin/items-3U5USBVG.js +62 -0
  23. package/dist/bin/items-toggle-YEKMI2CM.js +46 -0
  24. package/dist/bin/list-FX2C3NCL.js +46 -0
  25. package/dist/bin/list-VBAHY72W.js +79 -0
  26. package/dist/bin/members-5FPRUAB6.js +55 -0
  27. package/dist/bin/monthly-comparison-JEJ3TTY2.js +176 -0
  28. package/dist/bin/order-cancel-XI2LKYXV.js +55 -0
  29. package/dist/bin/order-confirm-HUFCU6MO.js +53 -0
  30. package/dist/bin/order-get-NSDMPUZR.js +88 -0
  31. package/dist/bin/order-update-C7QYSD5R.js +60 -0
  32. package/dist/bin/output-QFLEKG5W.js +35 -0
  33. package/dist/bin/payment-modes-WI3AWSES.js +126 -0
  34. package/dist/bin/profit-loss-5RIEOBKP.js +135 -0
  35. package/dist/bin/receivables-aging-L6DIQCNE.js +161 -0
  36. package/dist/bin/remove-M2B4TZ37.js +52 -0
  37. package/dist/bin/revoke-H3V2GNCD.js +52 -0
  38. package/dist/bin/sales-trend-TICB3KGF.js +71 -0
  39. package/dist/bin/sequence-XUD6FAKY.js +66 -0
  40. package/dist/bin/store-UQ2DDQ5I.js +82 -0
  41. package/dist/bin/summary-BPNFC7I2.js +113 -0
  42. package/dist/bin/top-customers-WGGJWKCN.js +81 -0
  43. package/dist/bin/top-items-C7ZDDJMR.js +84 -0
  44. package/dist/bin/top-outstanding-MOGWJIQS.js +64 -0
  45. package/dist/bin/unpaid-invoices-ZUPNMQJP.js +65 -0
  46. package/dist/bin/untracked-BCJEVDW4.js +67 -0
  47. package/dist/bin/update-HIU4PANX.js +54 -0
  48. package/dist/bin/update-IG565YIN.js +61 -0
  49. package/dist/bin/update-PVLAX7T3.js +57 -0
  50. package/dist/bin/update-role-Q4ZYJRYT.js +45 -0
  51. package/dist/bin/update-settings-XPC6L5WM.js +56 -0
  52. package/package.json +6 -1
  53. package/src/bin/hisaabo.ts +42 -933
  54. package/src/bin/registrars/api-key.ts +44 -0
  55. package/src/bin/registrars/auth.ts +153 -0
  56. package/src/bin/registrars/automated-invoice.ts +167 -0
  57. package/src/bin/registrars/bank.ts +90 -0
  58. package/src/bin/registrars/business.ts +120 -0
  59. package/src/bin/registrars/dashboard.ts +225 -0
  60. package/src/bin/registrars/document.ts +184 -0
  61. package/src/bin/registrars/expense.ts +87 -0
  62. package/src/bin/registrars/gst.ts +41 -0
  63. package/src/bin/registrars/import.ts +49 -0
  64. package/src/bin/registrars/invoice.ts +117 -0
  65. package/src/bin/registrars/item.ts +112 -0
  66. package/src/bin/registrars/party.ts +81 -0
  67. package/src/bin/registrars/payment.ts +128 -0
  68. package/src/bin/registrars/report.ts +142 -0
  69. package/src/bin/registrars/shipment.ts +74 -0
  70. package/src/bin/registrars/store.ts +128 -0
  71. package/src/bin/registrars/target.ts +46 -0
  72. package/src/bin/registrars/tenant.ts +55 -0
  73. package/src/client.ts +495 -4
  74. package/src/commands/api-key/create.ts +72 -0
  75. package/src/commands/api-key/list.ts +71 -0
  76. package/src/commands/api-key/revoke.ts +46 -0
  77. package/src/commands/automated-invoice/create.ts +85 -0
  78. package/src/commands/automated-invoice/delete.ts +42 -0
  79. package/src/commands/automated-invoice/get.ts +113 -0
  80. package/src/commands/automated-invoice/history.ts +65 -0
  81. package/src/commands/automated-invoice/index.ts +11 -0
  82. package/src/commands/automated-invoice/list.ts +91 -0
  83. package/src/commands/automated-invoice/pause.ts +29 -0
  84. package/src/commands/automated-invoice/resume.ts +29 -0
  85. package/src/commands/automated-invoice/run-now.ts +29 -0
  86. package/src/commands/automated-invoice/suggestions.ts +68 -0
  87. package/src/commands/automated-invoice/update.ts +54 -0
  88. package/src/commands/automated-invoice/usage.ts +68 -0
  89. package/src/commands/business/audit-trail.ts +79 -0
  90. package/src/commands/business/export.ts +52 -0
  91. package/src/commands/business/get.ts +55 -0
  92. package/src/commands/business/sequence.ts +65 -0
  93. package/src/commands/business/update.ts +64 -0
  94. package/src/commands/dashboard/collection-efficiency.ts +164 -0
  95. package/src/commands/dashboard/expenses.ts +76 -0
  96. package/src/commands/dashboard/invoice-breakdown.ts +89 -0
  97. package/src/commands/dashboard/monthly-comparison.ts +193 -0
  98. package/src/commands/dashboard/payment-modes.ts +121 -0
  99. package/src/commands/dashboard/profit-loss.ts +146 -0
  100. package/src/commands/dashboard/receivables-aging.ts +169 -0
  101. package/src/commands/dashboard/sales-trend.ts +68 -0
  102. package/src/commands/dashboard/summary.ts +105 -0
  103. package/src/commands/dashboard/top-customers.ts +70 -0
  104. package/src/commands/dashboard/top-items.ts +74 -0
  105. package/src/commands/dashboard/top-outstanding.ts +61 -0
  106. package/src/commands/document/factory.ts +590 -0
  107. package/src/commands/expense/categories.ts +40 -0
  108. package/src/commands/expense/update.ts +58 -0
  109. package/src/commands/import/index.ts +68 -0
  110. package/src/commands/item/categories.ts +40 -0
  111. package/src/commands/item/low-stock-count.ts +32 -0
  112. package/src/commands/item/merge.ts +53 -0
  113. package/src/commands/item/price-history.ts +59 -0
  114. package/src/commands/item/rename-unit.ts +39 -0
  115. package/src/commands/item/sales-stats.ts +44 -0
  116. package/src/commands/item/stock-history.ts +70 -0
  117. package/src/commands/item/switch-base-unit.ts +42 -0
  118. package/src/commands/item/update.ts +59 -0
  119. package/src/commands/item/variants-create.ts +58 -0
  120. package/src/commands/item/variants-delete.ts +47 -0
  121. package/src/commands/item/variants-list.ts +63 -0
  122. package/src/commands/item/variants-update.ts +61 -0
  123. package/src/commands/party/ledger-report.ts +81 -0
  124. package/src/commands/party/merge.ts +50 -0
  125. package/src/commands/party/stats.ts +40 -0
  126. package/src/commands/party/top-items.ts +57 -0
  127. package/src/commands/party/update.ts +65 -0
  128. package/src/commands/payment/default-account.ts +56 -0
  129. package/src/commands/payment/get.ts +59 -0
  130. package/src/commands/payment/unpaid-invoices.ts +69 -0
  131. package/src/commands/payment/untracked.ts +70 -0
  132. package/src/commands/payment/update.ts +54 -0
  133. package/src/commands/report/index.ts +348 -1
  134. package/src/commands/store/check-slug.ts +48 -0
  135. package/src/commands/store/items-toggle.ts +41 -0
  136. package/src/commands/store/items.ts +61 -0
  137. package/src/commands/store/order-cancel.ts +48 -0
  138. package/src/commands/store/order-confirm.ts +45 -0
  139. package/src/commands/store/order-get.ts +66 -0
  140. package/src/commands/store/order-update.ts +52 -0
  141. package/src/commands/store/update-settings.ts +52 -0
  142. package/src/commands/tenant/invite.ts +57 -0
  143. package/src/commands/tenant/list.ts +46 -0
  144. package/src/commands/tenant/members.ts +55 -0
  145. package/src/commands/tenant/remove.ts +47 -0
  146. package/src/commands/tenant/update-role.ts +41 -0
@@ -0,0 +1,63 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import {
4
+ fatalError, outputJSON, outputTable, outputTSV, outputCSV,
5
+ EXIT, type ColumnDef,
6
+ } from "../../output.js";
7
+ import { formatAmount } from "../../format.js";
8
+
9
+ interface VariantsListOpts {
10
+ json?: boolean;
11
+ format?: string;
12
+ }
13
+
14
+ interface VariantRow {
15
+ id: string;
16
+ sku: string;
17
+ salePrice: string;
18
+ purchasePrice: string;
19
+ stockQuantity: string;
20
+ attributes: string;
21
+ }
22
+
23
+ export async function itemVariantsListCommand(itemId: string, opts: VariantsListOpts): Promise<void> {
24
+ const cfg = requireAuth();
25
+ const client = new HisaaboClient(cfg);
26
+
27
+ try {
28
+ const result = await client.item.listVariants({ itemId });
29
+
30
+ if (opts.json) {
31
+ outputJSON(result);
32
+ return;
33
+ }
34
+
35
+ const variants: VariantRow[] = Array.isArray(result?.variants) ? result.variants : (Array.isArray(result) ? result : []);
36
+
37
+ console.log(`\n Variants for item: ${itemId}\n`);
38
+
39
+ const cols: ColumnDef<VariantRow>[] = [
40
+ { key: "id", header: "ID", width: 12 },
41
+ { key: "sku", header: "SKU", width: 14 },
42
+ { key: "salePrice", header: "Sale (₹)", align: "right", width: 12, format: (v) => v ? formatAmount(String(v)) : "-" },
43
+ { key: "purchasePrice", header: "Purchase (₹)", align: "right", width: 14, format: (v) => v ? formatAmount(String(v)) : "-" },
44
+ { key: "stockQuantity", header: "Stock", align: "right", width: 10, format: (v) => formatAmount(String(v ?? "0")) },
45
+ { key: "attributes", header: "Attributes", width: 20, format: (v) => v ? JSON.stringify(v) : "-" },
46
+ ];
47
+
48
+ if (opts.format === "tsv") outputTSV(variants, cols);
49
+ else if (opts.format === "csv") outputCSV(variants, cols);
50
+ else outputTable(variants, cols);
51
+
52
+ console.log();
53
+
54
+ } catch (e) {
55
+ if (e instanceof HisaaboApiError) {
56
+ const err = e.hisaaboError;
57
+ if (err.code === "not_found") fatalError(`Item not found: ${itemId}`, EXIT.NOT_FOUND);
58
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
59
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
60
+ }
61
+ fatalError(String(e instanceof Error ? e.message : e));
62
+ }
63
+ }
@@ -0,0 +1,61 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import { fatalError, outputJSON, EXIT, success } from "../../output.js";
4
+
5
+ interface VariantsUpdateOpts {
6
+ sku?: string;
7
+ salePrice?: string;
8
+ purchasePrice?: string;
9
+ stock?: string;
10
+ lowStockAlert?: string;
11
+ attributes?: string;
12
+ json?: boolean;
13
+ }
14
+
15
+ export async function itemVariantsUpdateCommand(variantId: string, opts: VariantsUpdateOpts): Promise<void> {
16
+ const cfg = requireAuth();
17
+ const client = new HisaaboClient(cfg);
18
+
19
+ let parsedAttributes: Record<string, unknown> | undefined;
20
+ if (opts.attributes) {
21
+ try {
22
+ parsedAttributes = JSON.parse(opts.attributes) as Record<string, unknown>;
23
+ } catch {
24
+ fatalError("--attributes must be valid JSON", EXIT.USAGE);
25
+ }
26
+ }
27
+
28
+ const data: Record<string, unknown> = { variantId };
29
+ if (opts.sku !== undefined) data["sku"] = opts.sku;
30
+ if (opts.salePrice !== undefined) data["salePrice"] = opts.salePrice;
31
+ if (opts.purchasePrice !== undefined) data["purchasePrice"] = opts.purchasePrice;
32
+ if (opts.stock !== undefined) data["stockQuantity"] = opts.stock;
33
+ if (opts.lowStockAlert !== undefined) data["lowStockAlert"] = opts.lowStockAlert;
34
+ if (parsedAttributes !== undefined) data["attributes"] = parsedAttributes;
35
+
36
+ if (Object.keys(data).length === 1) {
37
+ fatalError("No fields to update. Provide at least one option.", EXIT.USAGE);
38
+ }
39
+
40
+ try {
41
+ const result = await client.item.updateVariant(data);
42
+
43
+ if (opts.json) {
44
+ outputJSON(result);
45
+ return;
46
+ }
47
+
48
+ success(`Updated variant: ${variantId}`);
49
+ console.log();
50
+
51
+ } catch (e) {
52
+ if (e instanceof HisaaboApiError) {
53
+ const err = e.hisaaboError;
54
+ if (err.code === "not_found") fatalError(`Variant not found: ${variantId}`, EXIT.NOT_FOUND);
55
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
56
+ if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
57
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
58
+ }
59
+ fatalError(String(e instanceof Error ? e.message : e));
60
+ }
61
+ }
@@ -0,0 +1,81 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import {
4
+ fatalError, outputJSON, outputTable, outputTSV, outputCSV,
5
+ EXIT, type ColumnDef,
6
+ } from "../../output.js";
7
+ import { formatAmount, formatDate, fyStart, todayISO, monthStart, monthEnd } from "../../format.js";
8
+
9
+ interface LedgerReportOpts {
10
+ json?: boolean;
11
+ format?: string;
12
+ from?: string;
13
+ to?: string;
14
+ thisMonth?: boolean;
15
+ thisFy?: boolean;
16
+ }
17
+
18
+ interface LedgerReportEntry {
19
+ date: string;
20
+ type: string;
21
+ number: string;
22
+ debit: string;
23
+ credit: string;
24
+ balance: string;
25
+ }
26
+
27
+ export async function partyLedgerReportCommand(partyId: string, opts: LedgerReportOpts): Promise<void> {
28
+ const cfg = requireAuth();
29
+ const client = new HisaaboClient(cfg);
30
+
31
+ let from = opts.from;
32
+ let to = opts.to;
33
+ if (opts.thisFy) { from = fyStart(); to = todayISO(); }
34
+ else if (opts.thisMonth) { from = monthStart(); to = monthEnd(); }
35
+
36
+ try {
37
+ const result = await client.party.ledgerReport({ partyId, from, to });
38
+
39
+ if (opts.json) {
40
+ outputJSON(result);
41
+ return;
42
+ }
43
+
44
+ const entries: LedgerReportEntry[] = Array.isArray(result?.entries) ? result.entries : (Array.isArray(result) ? result : []);
45
+
46
+ console.log(`\n Ledger Report: ${result?.partyName ?? partyId}`);
47
+ if (from || to) {
48
+ console.log(` Period: ${from ?? "start"} → ${to ?? "today"}`);
49
+ }
50
+ console.log(" " + "═".repeat(72) + "\n");
51
+
52
+ const cols: ColumnDef<LedgerReportEntry>[] = [
53
+ { key: "date", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
54
+ { key: "type", header: "Type", width: 12 },
55
+ { key: "number", header: "Number", width: 14 },
56
+ { key: "debit", header: "Debit (₹)", align: "right", width: 13, format: (v) => parseFloat(String(v ?? "0")) !== 0 ? formatAmount(String(v)) : "-" },
57
+ { key: "credit", header: "Credit (₹)", align: "right", width: 13, format: (v) => parseFloat(String(v ?? "0")) !== 0 ? formatAmount(String(v)) : "-" },
58
+ { key: "balance", header: "Balance (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
59
+ ];
60
+
61
+ if (opts.format === "tsv") outputTSV(entries, cols);
62
+ else if (opts.format === "csv") outputCSV(entries, cols);
63
+ else outputTable(entries, cols);
64
+
65
+ if (result?.summary) {
66
+ console.log();
67
+ console.log(` Total Debit: ₹${formatAmount(String(result.summary.totalDebit ?? "0"))}`);
68
+ console.log(` Total Credit: ₹${formatAmount(String(result.summary.totalCredit ?? "0"))}`);
69
+ console.log(` Net Balance: ₹${formatAmount(String(result.summary.netBalance ?? "0"))}\n`);
70
+ }
71
+
72
+ } catch (e) {
73
+ if (e instanceof HisaaboApiError) {
74
+ const err = e.hisaaboError;
75
+ if (err.code === "not_found") fatalError(`Party not found: ${partyId}`, EXIT.NOT_FOUND);
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
+ }
@@ -0,0 +1,50 @@
1
+ import * as readline from "readline";
2
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
3
+ import { requireAuth } from "../../config.js";
4
+ import { fatalError, outputJSON, EXIT, success } from "../../output.js";
5
+
6
+ interface MergeOpts {
7
+ yes?: boolean;
8
+ json?: boolean;
9
+ }
10
+
11
+ export async function partyMergeCommand(sourceId: string, targetId: string, opts: MergeOpts): Promise<void> {
12
+ const cfg = requireAuth();
13
+ const client = new HisaaboClient(cfg);
14
+
15
+ if (!opts.yes && process.stdin.isTTY) {
16
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
17
+ const answer = await new Promise<string>((resolve) => {
18
+ rl.question(
19
+ ` Merge party ${sourceId} into ${targetId}? All invoices and payments will be moved. This cannot be undone. (y/n): `,
20
+ resolve,
21
+ );
22
+ });
23
+ rl.close();
24
+ if (answer.trim().toLowerCase() !== "y") {
25
+ console.log(" Cancelled.");
26
+ process.exit(0);
27
+ }
28
+ }
29
+
30
+ try {
31
+ const result = await client.party.merge({ sourceId, targetId });
32
+
33
+ if (opts.json) {
34
+ outputJSON(result);
35
+ return;
36
+ }
37
+
38
+ success(`Merged into ${targetId}`);
39
+
40
+ } catch (e) {
41
+ if (e instanceof HisaaboApiError) {
42
+ const err = e.hisaaboError;
43
+ if (err.code === "not_found") fatalError(`Party not found`, 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
+ }
@@ -0,0 +1,40 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import { fatalError, outputJSON, EXIT } from "../../output.js";
4
+ import { formatINR } from "../../format.js";
5
+
6
+ interface StatsOpts {
7
+ json?: boolean;
8
+ }
9
+
10
+ export async function partyStatsCommand(id: string, opts: StatsOpts): Promise<void> {
11
+ const cfg = requireAuth();
12
+ const client = new HisaaboClient(cfg);
13
+
14
+ try {
15
+ const result = await client.party.getStats({ partyId: id });
16
+
17
+ if (opts.json) {
18
+ outputJSON(result);
19
+ return;
20
+ }
21
+
22
+ console.log(`\n Party Stats: ${result?.partyName ?? id}`);
23
+ console.log(" " + "─".repeat(40));
24
+ console.log(` Invoices: ${result?.invoiceCount ?? 0}`);
25
+ console.log(` Payments: ${result?.paymentCount ?? 0}`);
26
+ console.log(` Invoiced: ${formatINR(String(result?.totalInvoiced ?? "0"))}`);
27
+ console.log(` Paid: ${formatINR(String(result?.totalPaid ?? "0"))}`);
28
+ console.log(` Outstanding: ${formatINR(String(result?.outstanding ?? "0"))}`);
29
+ console.log();
30
+
31
+ } catch (e) {
32
+ if (e instanceof HisaaboApiError) {
33
+ const err = e.hisaaboError;
34
+ if (err.code === "not_found") fatalError(`Party not found: ${id}`, EXIT.NOT_FOUND);
35
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
36
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
37
+ }
38
+ fatalError(String(e instanceof Error ? e.message : e));
39
+ }
40
+ }
@@ -0,0 +1,57 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import {
4
+ fatalError, outputJSON, outputTable, outputTSV, outputCSV,
5
+ EXIT, type ColumnDef,
6
+ } from "../../output.js";
7
+ import { formatAmount } from "../../format.js";
8
+
9
+ interface TopItemsOpts {
10
+ json?: boolean;
11
+ format?: string;
12
+ }
13
+
14
+ interface TopItem {
15
+ itemName: string;
16
+ quantity: string;
17
+ revenue: string;
18
+ }
19
+
20
+ export async function partyTopItemsCommand(id: string, opts: TopItemsOpts): Promise<void> {
21
+ const cfg = requireAuth();
22
+ const client = new HisaaboClient(cfg);
23
+
24
+ try {
25
+ const result = await client.party.topItems({ partyId: id });
26
+
27
+ if (opts.json) {
28
+ outputJSON(result);
29
+ return;
30
+ }
31
+
32
+ const items: TopItem[] = Array.isArray(result?.items) ? result.items : (Array.isArray(result) ? result : []);
33
+
34
+ console.log(`\n Top Items for Party: ${result?.partyName ?? id}\n`);
35
+
36
+ const cols: ColumnDef<TopItem>[] = [
37
+ { key: "itemName", header: "Item", width: 30 },
38
+ { key: "quantity", header: "Quantity", align: "right", width: 12, format: (v) => formatAmount(String(v ?? "0")) },
39
+ { key: "revenue", header: "Revenue (₹)", align: "right", width: 14, format: (v) => formatAmount(String(v ?? "0")) },
40
+ ];
41
+
42
+ if (opts.format === "tsv") outputTSV(items, cols);
43
+ else if (opts.format === "csv") outputCSV(items, cols);
44
+ else outputTable(items, cols);
45
+
46
+ console.log();
47
+
48
+ } catch (e) {
49
+ if (e instanceof HisaaboApiError) {
50
+ const err = e.hisaaboError;
51
+ if (err.code === "not_found") fatalError(`Party not found: ${id}`, EXIT.NOT_FOUND);
52
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
53
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
54
+ }
55
+ fatalError(String(e instanceof Error ? e.message : e));
56
+ }
57
+ }
@@ -0,0 +1,65 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import { fatalError, outputJSON, EXIT, success } from "../../output.js";
4
+
5
+ interface UpdateOpts {
6
+ name?: string;
7
+ phone?: string;
8
+ email?: string;
9
+ gstin?: string;
10
+ type?: string;
11
+ billingAddress?: string;
12
+ city?: string;
13
+ state?: string;
14
+ pincode?: string;
15
+ category?: string;
16
+ creditPeriod?: string;
17
+ creditLimit?: string;
18
+ json?: boolean;
19
+ }
20
+
21
+ export async function partyUpdateCommand(id: string, opts: UpdateOpts): Promise<void> {
22
+ const cfg = requireAuth();
23
+ const client = new HisaaboClient(cfg);
24
+
25
+ // Only send fields that were explicitly provided
26
+ const data: Record<string, unknown> = {};
27
+ if (opts.name !== undefined) data["name"] = opts.name;
28
+ if (opts.phone !== undefined) data["phone"] = opts.phone;
29
+ if (opts.email !== undefined) data["email"] = opts.email;
30
+ if (opts.gstin !== undefined) data["gstin"] = opts.gstin;
31
+ if (opts.type !== undefined) data["type"] = opts.type;
32
+ if (opts.billingAddress !== undefined) data["billingAddress"] = opts.billingAddress;
33
+ if (opts.city !== undefined) data["city"] = opts.city;
34
+ if (opts.state !== undefined) data["state"] = opts.state;
35
+ if (opts.pincode !== undefined) data["pincode"] = opts.pincode;
36
+ if (opts.category !== undefined) data["category"] = opts.category;
37
+ if (opts.creditPeriod !== undefined) data["creditPeriod"] = parseInt(opts.creditPeriod, 10);
38
+ if (opts.creditLimit !== undefined) data["creditLimit"] = opts.creditLimit;
39
+
40
+ if (Object.keys(data).length === 0) {
41
+ fatalError("No fields to update. Provide at least one option.", EXIT.USAGE);
42
+ }
43
+
44
+ try {
45
+ const result = await client.party.update(id, data as Parameters<typeof client.party.update>[1]);
46
+
47
+ if (opts.json) {
48
+ outputJSON(result);
49
+ return;
50
+ }
51
+
52
+ success(`Updated party: ${result.name}`);
53
+ console.log(` ID: ${result.id}\n`);
54
+
55
+ } catch (e) {
56
+ if (e instanceof HisaaboApiError) {
57
+ const err = e.hisaaboError;
58
+ if (err.code === "not_found") fatalError(`Party not found: ${id}`, EXIT.NOT_FOUND);
59
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
60
+ if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
61
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
62
+ }
63
+ fatalError(String(e instanceof Error ? e.message : e));
64
+ }
65
+ }
@@ -0,0 +1,56 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import { fatalError, outputJSON, EXIT } from "../../output.js";
4
+
5
+ interface DefaultAccountOpts {
6
+ json?: boolean;
7
+ partyId?: string;
8
+ }
9
+
10
+ export async function paymentDefaultAccountCommand(opts: DefaultAccountOpts): Promise<void> {
11
+ const cfg = requireAuth();
12
+ const client = new HisaaboClient(cfg);
13
+
14
+ try {
15
+ const input = opts.partyId ? { partyId: opts.partyId } : undefined;
16
+ const result = await client.payment.defaultAccount(input);
17
+
18
+ if (opts.json) {
19
+ outputJSON(result);
20
+ return;
21
+ }
22
+
23
+ if (!result) {
24
+ console.log("\n No recommended bank account found.\n");
25
+ return;
26
+ }
27
+
28
+ const sep = "─".repeat(48);
29
+
30
+ console.log(`\n Recommended Bank Account`);
31
+ console.log(` ${sep}`);
32
+
33
+ if (typeof result === "object" && result !== null) {
34
+ const acct = result as Record<string, unknown>;
35
+ if (acct["id"]) console.log(` ID : ${acct["id"]}`);
36
+ if (acct["accountName"]) console.log(` Account : ${acct["accountName"]}`);
37
+ if (acct["bankName"]) console.log(` Bank : ${acct["bankName"]}`);
38
+ if (acct["accountNumber"]) console.log(` Number : ${acct["accountNumber"]}`);
39
+ if (acct["ifsc"]) console.log(` IFSC : ${acct["ifsc"]}`);
40
+ } else {
41
+ console.log(` ${String(result)}`);
42
+ }
43
+
44
+ console.log();
45
+
46
+ } catch (e) {
47
+ if (e instanceof HisaaboApiError) {
48
+ const err = e.hisaaboError;
49
+ if (err.code === "not_found") fatalError("No bank account configured.", EXIT.NOT_FOUND);
50
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
51
+ if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
52
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
53
+ }
54
+ fatalError(String(e instanceof Error ? e.message : e));
55
+ }
56
+ }
@@ -0,0 +1,59 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import { fatalError, outputJSON, EXIT } from "../../output.js";
4
+ import { formatINR, formatDate } from "../../format.js";
5
+
6
+ export async function paymentGetCommand(id: string, opts: { json?: boolean }): Promise<void> {
7
+ const cfg = requireAuth();
8
+ const client = new HisaaboClient(cfg);
9
+
10
+ try {
11
+ const payment = await client.payment.getById(id);
12
+ if (!payment) {
13
+ fatalError(`Payment not found: ${id}`, EXIT.NOT_FOUND);
14
+ }
15
+
16
+ if (opts.json) {
17
+ outputJSON(payment);
18
+ return;
19
+ }
20
+
21
+ const p = payment!;
22
+ const sep = "─".repeat(48);
23
+
24
+ console.log(`\n Payment: ${p.paymentNumber}`);
25
+ console.log(` ${sep}`);
26
+ console.log(` Party : ${p.partyName}`);
27
+ console.log(` Date : ${formatDate(p.paymentDate)}`);
28
+ console.log(` Amount : ${formatINR(p.amount)}`);
29
+ if (parseFloat(p.discount) > 0) {
30
+ console.log(` Discount : ${formatINR(p.discount)}`);
31
+ }
32
+ console.log(` Mode : ${p.mode}`);
33
+ console.log(` Reference : ${p.referenceNumber ?? "-"}`);
34
+ console.log(` Notes : ${p.notes ?? "-"}`);
35
+ console.log(` Bank Acct : ${p.bankAccountId ?? "-"}`);
36
+
37
+ if (p.linkedInvoices && p.linkedInvoices.length > 0) {
38
+ console.log(`\n Linked Invoices:`);
39
+ console.log(` ${"─".repeat(65)}`);
40
+ for (const inv of p.linkedInvoices) {
41
+ const total = formatINR(inv.totalAmount);
42
+ const applied = formatINR(inv.amount);
43
+ console.log(` ${inv.invoiceNumber.padEnd(14)} ${formatDate(inv.invoiceDate).padEnd(14)} Total: ${total.padStart(11)} Applied: ${applied.padStart(11)} [${inv.status.toUpperCase()}]`);
44
+ }
45
+ }
46
+
47
+ console.log();
48
+
49
+ } catch (e) {
50
+ if (e instanceof HisaaboApiError) {
51
+ const err = e.hisaaboError;
52
+ if (err.code === "not_found") fatalError(`Payment not found: ${id}`, EXIT.NOT_FOUND);
53
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
54
+ if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
55
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
56
+ }
57
+ fatalError(String(e instanceof Error ? e.message : e));
58
+ }
59
+ }
@@ -0,0 +1,69 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import {
4
+ fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, type ColumnDef,
5
+ } from "../../output.js";
6
+ import { formatAmount, formatDate } from "../../format.js";
7
+
8
+ interface UnpaidInvoice {
9
+ id: string;
10
+ invoiceNumber: string;
11
+ invoiceDate: string;
12
+ totalAmount: string;
13
+ paidAmount: string;
14
+ outstandingAmount: string;
15
+ status: string;
16
+ }
17
+
18
+ interface UnpaidOpts {
19
+ json?: boolean;
20
+ format?: string;
21
+ }
22
+
23
+ export async function paymentUnpaidInvoicesCommand(partyId: string, opts: UnpaidOpts): Promise<void> {
24
+ const cfg = requireAuth();
25
+ const client = new HisaaboClient(cfg);
26
+
27
+ try {
28
+ const result = await client.payment.unpaidInvoices({ partyId });
29
+
30
+ if (opts.json) {
31
+ outputJSON(result);
32
+ return;
33
+ }
34
+
35
+ const invoices: UnpaidInvoice[] = Array.isArray(result) ? result : (result?.data ?? []);
36
+
37
+ if (invoices.length === 0) {
38
+ console.log("\n No unpaid invoices for this party.\n");
39
+ return;
40
+ }
41
+
42
+ console.log(`\n Unpaid Invoices (${invoices.length})\n`);
43
+
44
+ const cols: ColumnDef<UnpaidInvoice>[] = [
45
+ { key: "invoiceNumber", header: "Invoice #", width: 14 },
46
+ { key: "invoiceDate", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
47
+ { key: "totalAmount", header: "Total (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
48
+ { key: "paidAmount", header: "Paid (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
49
+ { key: "outstandingAmount", header: "Outstanding (₹)", align: "right", width: 16, format: (v) => formatAmount(String(v ?? "0")) },
50
+ { key: "status", header: "Status", width: 10, format: (v) => String(v ?? "").toUpperCase() },
51
+ ];
52
+
53
+ if (opts.format === "tsv") outputTSV(invoices, cols);
54
+ else if (opts.format === "csv") outputCSV(invoices, cols);
55
+ else outputTable(invoices, cols);
56
+
57
+ console.log();
58
+
59
+ } catch (e) {
60
+ if (e instanceof HisaaboApiError) {
61
+ const err = e.hisaaboError;
62
+ if (err.code === "not_found") fatalError(`Party not found: ${partyId}`, EXIT.NOT_FOUND);
63
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
64
+ if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
65
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
66
+ }
67
+ fatalError(String(e instanceof Error ? e.message : e));
68
+ }
69
+ }
@@ -0,0 +1,70 @@
1
+ import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
+ import { requireAuth } from "../../config.js";
3
+ import {
4
+ fatalError, outputJSON, outputTable, outputTSV, outputCSV, paginationFooter, EXIT, type ColumnDef,
5
+ } from "../../output.js";
6
+ import { formatAmount, formatDate } from "../../format.js";
7
+
8
+ interface UntrackedPayment {
9
+ id: string;
10
+ paymentNumber: string;
11
+ partyName: string;
12
+ paymentDate: string;
13
+ amount: string;
14
+ mode: string;
15
+ referenceNumber: string | null;
16
+ }
17
+
18
+ interface UntrackedOpts {
19
+ json?: boolean;
20
+ format?: string;
21
+ page?: number;
22
+ limit?: number;
23
+ }
24
+
25
+ export async function paymentUntrackedCommand(opts: UntrackedOpts): Promise<void> {
26
+ const cfg = requireAuth();
27
+ const client = new HisaaboClient(cfg);
28
+ const page = opts.page ?? 1;
29
+ const limit = opts.limit ?? 20;
30
+
31
+ try {
32
+ const result = await client.payment.untrackedPayments({ page, limit });
33
+
34
+ if (opts.json) {
35
+ outputJSON(result);
36
+ return;
37
+ }
38
+
39
+ const payments: UntrackedPayment[] = Array.isArray(result) ? result : (result?.data ?? []);
40
+ const total: number = result?.total ?? payments.length;
41
+ const resultPage: number = result?.page ?? page;
42
+ const resultLimit: number = result?.limit ?? limit;
43
+
44
+ console.log(`\n Untracked Payments ${total} total\n`);
45
+
46
+ const cols: ColumnDef<UntrackedPayment>[] = [
47
+ { key: "paymentNumber", header: "#", width: 12 },
48
+ { key: "partyName", header: "Party", width: 22 },
49
+ { key: "paymentDate", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
50
+ { key: "amount", header: "Amount (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
51
+ { key: "mode", header: "Mode", width: 8 },
52
+ { key: "referenceNumber", header: "Ref#", width: 14, format: (v) => String(v ?? "-") },
53
+ ];
54
+
55
+ if (opts.format === "tsv") outputTSV(payments, cols);
56
+ else if (opts.format === "csv") outputCSV(payments, cols);
57
+ else {
58
+ outputTable(payments, cols);
59
+ paginationFooter(resultPage, resultLimit, total);
60
+ }
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
+ }