@hisaabo/cli 0.7.5 → 0.8.6

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 (210) hide show
  1. package/LICENSE +31 -0
  2. package/README.md +9 -0
  3. package/dist/bin/{audit-trail-DLSSSM4T.js → audit-trail-IJ6SKACR.js} +2 -2
  4. package/dist/bin/{categories-63QR6WCV.js → categories-O6TODPAH.js} +2 -2
  5. package/dist/bin/{check-slug-NXO55WKH.js → check-slug-P7RFU6OP.js} +2 -2
  6. package/dist/bin/chunk-NO4FIFMS.js +0 -0
  7. package/dist/bin/{chunk-7MJDOL6B.js → chunk-QUITS2FE.js} +28 -0
  8. package/dist/bin/{chunk-M42SETRZ.js → chunk-WDN7RIE3.js} +23 -2
  9. package/dist/bin/chunk-ZPYC767N.js +0 -0
  10. package/dist/bin/{client-T32CIZA3.js → client-36JX5MR3.js} +1 -1
  11. package/dist/bin/{collection-efficiency-T6PWNTZO.js → collection-efficiency-DA5RWG3V.js} +2 -2
  12. package/dist/bin/{config-V4QFCONN.js → config-4LLNT4SH.js} +3 -1
  13. package/dist/bin/{create-NUKHDWLK.js → create-C5INBPQO.js} +2 -2
  14. package/dist/bin/{default-account-JWFPHMRF.js → default-account-2GMQ7ZA4.js} +2 -2
  15. package/dist/bin/{expenses-2UWUZVLI.js → expenses-S2YVA5UT.js} +2 -2
  16. package/dist/bin/{export-XSX7WQH7.js → export-YOOODNVX.js} +2 -2
  17. package/dist/bin/export-ZA43MLWO.js +191 -0
  18. package/dist/bin/{factory-BWOKRIP4.js → factory-6MUCSXTL.js} +2 -2
  19. package/dist/bin/{get-CHNTG3IM.js → get-GMQRROK2.js} +2 -2
  20. package/dist/bin/{get-ZSZ6SL3N.js → get-ZV3SC2VY.js} +2 -2
  21. package/dist/bin/hisaabo.js +100 -57
  22. package/dist/bin/import-UUHMLCKX.js +267 -0
  23. package/dist/bin/{invitations-H2SL3XAD.js → invitations-OVORTTMF.js} +2 -2
  24. package/dist/bin/{invite-EW73UIBE.js → invite-GGHBZY4U.js} +2 -2
  25. package/dist/bin/{invoice-breakdown-XP4QATCF.js → invoice-breakdown-32XXAZDP.js} +2 -2
  26. package/dist/bin/{items-DPD6EFTP.js → items-6NOIMH6B.js} +2 -2
  27. package/dist/bin/{items-toggle-R4OPSE4W.js → items-toggle-L6W6QKQD.js} +2 -2
  28. package/dist/bin/{list-PKHBE475.js → list-FC5JHKHD.js} +2 -2
  29. package/dist/bin/{list-KLEHBMQ2.js → list-OXAVDXH7.js} +2 -2
  30. package/dist/bin/{list-UR7OOJVF.js → list-RAR56EMQ.js} +2 -2
  31. package/dist/bin/{members-XA3TF4IQ.js → members-Y6XJVHHR.js} +2 -2
  32. package/dist/bin/{monthly-comparison-OLVS5HEY.js → monthly-comparison-IAUZ6SBJ.js} +2 -2
  33. package/dist/bin/{order-cancel-MXMJFFRR.js → order-cancel-QRTCNART.js} +2 -2
  34. package/dist/bin/{order-confirm-IXU45Q4L.js → order-confirm-LGQOMC4O.js} +2 -2
  35. package/dist/bin/{order-get-RDXMHLJ7.js → order-get-4XAQCRYV.js} +2 -2
  36. package/dist/bin/{order-update-KGIPBEJX.js → order-update-KZY4H2UR.js} +2 -2
  37. package/dist/bin/output-NUOL7KJW.js +0 -0
  38. package/dist/bin/{payment-modes-CZL35SVS.js → payment-modes-DY2ZEMK7.js} +2 -2
  39. package/dist/bin/{profit-loss-M332OSC5.js → profit-loss-5GJBG3PL.js} +2 -2
  40. package/dist/bin/{receivables-aging-OXRHGMBF.js → receivables-aging-6A7XJKDT.js} +2 -2
  41. package/dist/bin/{remove-I5HD2Y4K.js → remove-ZBX34TIQ.js} +2 -2
  42. package/dist/bin/{revoke-OC6AOMIZ.js → revoke-XDNOA2GJ.js} +2 -2
  43. package/dist/bin/{revoke-MFLWGCMP.js → revoke-ZTAMW2Q2.js} +2 -2
  44. package/dist/bin/{revoke-all-FSAPBB3P.js → revoke-all-365NRBOA.js} +2 -2
  45. package/dist/bin/{revoke-invitation-JXDPXTOW.js → revoke-invitation-PQH7XNYA.js} +2 -2
  46. package/dist/bin/{sales-trend-KK63WNDL.js → sales-trend-D6PQ7MHY.js} +2 -2
  47. package/dist/bin/{sequence-IQ4HUJ3W.js → sequence-KZWADVD7.js} +2 -2
  48. package/dist/bin/{store-6QT6HKG2.js → store-SVRZBUFO.js} +2 -2
  49. package/dist/bin/{summary-3FTF5B4A.js → summary-H6U7O5GJ.js} +2 -2
  50. package/dist/bin/{top-customers-HNYGXBQZ.js → top-customers-ATBN6RDI.js} +2 -2
  51. package/dist/bin/{top-items-JUDG3BVW.js → top-items-XXU6KYTC.js} +2 -2
  52. package/dist/bin/{top-outstanding-WK26ZNE5.js → top-outstanding-JTQNGGW4.js} +2 -2
  53. package/dist/bin/{unpaid-invoices-RYFIIIK7.js → unpaid-invoices-BTNQFWCH.js} +2 -2
  54. package/dist/bin/{untracked-FAFS3KCK.js → untracked-PAMEDJ6Y.js} +2 -2
  55. package/dist/bin/{update-5YSPXIWO.js → update-6ZMX2OYX.js} +2 -2
  56. package/dist/bin/{update-I46XLU77.js → update-EGHPFXLK.js} +2 -2
  57. package/dist/bin/{update-NAW2JWZS.js → update-EK4NJWU4.js} +2 -2
  58. package/dist/bin/{update-role-5GV42MSN.js → update-role-24PDTNFK.js} +2 -2
  59. package/dist/bin/{update-settings-KYSQDIEO.js → update-settings-AASI6WZX.js} +2 -2
  60. package/package.json +35 -9
  61. package/.turbo/turbo-build.log +0 -13
  62. package/.turbo/turbo-typecheck.log +0 -4
  63. package/CLI-UX-ARCHITECTURE.md +0 -1269
  64. package/src/auth.ts +0 -221
  65. package/src/bin/hisaabo.ts +0 -74
  66. package/src/bin/registrars/api-key.ts +0 -44
  67. package/src/bin/registrars/auth.ts +0 -222
  68. package/src/bin/registrars/automated-invoice.ts +0 -167
  69. package/src/bin/registrars/bank-recon.ts +0 -34
  70. package/src/bin/registrars/bank.ts +0 -124
  71. package/src/bin/registrars/business.ts +0 -120
  72. package/src/bin/registrars/dashboard.ts +0 -225
  73. package/src/bin/registrars/document.ts +0 -184
  74. package/src/bin/registrars/einvoice.ts +0 -46
  75. package/src/bin/registrars/ewb.ts +0 -37
  76. package/src/bin/registrars/expense.ts +0 -87
  77. package/src/bin/registrars/gst.ts +0 -57
  78. package/src/bin/registrars/import.ts +0 -49
  79. package/src/bin/registrars/invoice.ts +0 -117
  80. package/src/bin/registrars/itc.ts +0 -56
  81. package/src/bin/registrars/item.ts +0 -112
  82. package/src/bin/registrars/journal.ts +0 -47
  83. package/src/bin/registrars/party.ts +0 -81
  84. package/src/bin/registrars/payment.ts +0 -128
  85. package/src/bin/registrars/report.ts +0 -186
  86. package/src/bin/registrars/session.ts +0 -32
  87. package/src/bin/registrars/shipment.ts +0 -74
  88. package/src/bin/registrars/store.ts +0 -128
  89. package/src/bin/registrars/target.ts +0 -46
  90. package/src/bin/registrars/tenant.ts +0 -73
  91. package/src/client.ts +0 -2071
  92. package/src/commands/api-key/create.ts +0 -72
  93. package/src/commands/api-key/list.ts +0 -71
  94. package/src/commands/api-key/revoke.ts +0 -46
  95. package/src/commands/automated-invoice/create.ts +0 -85
  96. package/src/commands/automated-invoice/delete.ts +0 -42
  97. package/src/commands/automated-invoice/get.ts +0 -113
  98. package/src/commands/automated-invoice/history.ts +0 -65
  99. package/src/commands/automated-invoice/index.ts +0 -11
  100. package/src/commands/automated-invoice/list.ts +0 -91
  101. package/src/commands/automated-invoice/pause.ts +0 -29
  102. package/src/commands/automated-invoice/resume.ts +0 -29
  103. package/src/commands/automated-invoice/run-now.ts +0 -29
  104. package/src/commands/automated-invoice/suggestions.ts +0 -68
  105. package/src/commands/automated-invoice/update.ts +0 -54
  106. package/src/commands/automated-invoice/usage.ts +0 -68
  107. package/src/commands/bank/gateway-config.ts +0 -61
  108. package/src/commands/bank/index.ts +0 -244
  109. package/src/commands/bank/update-gateway.ts +0 -84
  110. package/src/commands/bank-recon/index.ts +0 -127
  111. package/src/commands/business/audit-trail.ts +0 -79
  112. package/src/commands/business/export.ts +0 -52
  113. package/src/commands/business/get.ts +0 -55
  114. package/src/commands/business/sequence.ts +0 -65
  115. package/src/commands/business/update.ts +0 -64
  116. package/src/commands/dashboard/collection-efficiency.ts +0 -164
  117. package/src/commands/dashboard/expenses.ts +0 -76
  118. package/src/commands/dashboard/invoice-breakdown.ts +0 -89
  119. package/src/commands/dashboard/monthly-comparison.ts +0 -193
  120. package/src/commands/dashboard/payment-modes.ts +0 -121
  121. package/src/commands/dashboard/profit-loss.ts +0 -146
  122. package/src/commands/dashboard/receivables-aging.ts +0 -169
  123. package/src/commands/dashboard/sales-trend.ts +0 -68
  124. package/src/commands/dashboard/summary.ts +0 -105
  125. package/src/commands/dashboard/top-customers.ts +0 -70
  126. package/src/commands/dashboard/top-items.ts +0 -74
  127. package/src/commands/dashboard/top-outstanding.ts +0 -61
  128. package/src/commands/dashboard.ts +0 -105
  129. package/src/commands/document/factory.ts +0 -590
  130. package/src/commands/einvoice/index.ts +0 -109
  131. package/src/commands/ewb/index.ts +0 -108
  132. package/src/commands/expense/categories.ts +0 -40
  133. package/src/commands/expense/create.ts +0 -51
  134. package/src/commands/expense/delete.ts +0 -45
  135. package/src/commands/expense/list.ts +0 -65
  136. package/src/commands/expense/update.ts +0 -58
  137. package/src/commands/gst/index.ts +0 -194
  138. package/src/commands/import/index.ts +0 -168
  139. package/src/commands/invoice/create.ts +0 -262
  140. package/src/commands/invoice/delete.ts +0 -44
  141. package/src/commands/invoice/get.ts +0 -113
  142. package/src/commands/invoice/list.ts +0 -126
  143. package/src/commands/invoice/pdf.ts +0 -75
  144. package/src/commands/invoice/status.ts +0 -41
  145. package/src/commands/itc/index.ts +0 -163
  146. package/src/commands/item/categories.ts +0 -40
  147. package/src/commands/item/create.ts +0 -98
  148. package/src/commands/item/delete.ts +0 -44
  149. package/src/commands/item/list.ts +0 -81
  150. package/src/commands/item/low-stock-count.ts +0 -32
  151. package/src/commands/item/merge.ts +0 -53
  152. package/src/commands/item/price-history.ts +0 -59
  153. package/src/commands/item/rename-unit.ts +0 -39
  154. package/src/commands/item/sales-stats.ts +0 -44
  155. package/src/commands/item/stock-history.ts +0 -70
  156. package/src/commands/item/stock.ts +0 -46
  157. package/src/commands/item/switch-base-unit.ts +0 -42
  158. package/src/commands/item/update.ts +0 -59
  159. package/src/commands/item/variants-create.ts +0 -58
  160. package/src/commands/item/variants-delete.ts +0 -47
  161. package/src/commands/item/variants-list.ts +0 -63
  162. package/src/commands/item/variants-update.ts +0 -61
  163. package/src/commands/journal/index.ts +0 -156
  164. package/src/commands/party/create.ts +0 -88
  165. package/src/commands/party/delete.ts +0 -44
  166. package/src/commands/party/get.ts +0 -42
  167. package/src/commands/party/ledger-report.ts +0 -81
  168. package/src/commands/party/ledger.ts +0 -63
  169. package/src/commands/party/list.ts +0 -69
  170. package/src/commands/party/merge.ts +0 -50
  171. package/src/commands/party/stats.ts +0 -40
  172. package/src/commands/party/top-items.ts +0 -57
  173. package/src/commands/party/update.ts +0 -65
  174. package/src/commands/payment/create.ts +0 -131
  175. package/src/commands/payment/default-account.ts +0 -56
  176. package/src/commands/payment/delete.ts +0 -46
  177. package/src/commands/payment/get.ts +0 -59
  178. package/src/commands/payment/list.ts +0 -66
  179. package/src/commands/payment/unpaid-invoices.ts +0 -69
  180. package/src/commands/payment/untracked.ts +0 -70
  181. package/src/commands/payment/update.ts +0 -54
  182. package/src/commands/report/index.ts +0 -736
  183. package/src/commands/session/list.ts +0 -91
  184. package/src/commands/session/revoke-all.ts +0 -20
  185. package/src/commands/session/revoke.ts +0 -32
  186. package/src/commands/shipment/index.ts +0 -170
  187. package/src/commands/store/check-slug.ts +0 -48
  188. package/src/commands/store/index.ts +0 -77
  189. package/src/commands/store/items-toggle.ts +0 -41
  190. package/src/commands/store/items.ts +0 -61
  191. package/src/commands/store/order-cancel.ts +0 -48
  192. package/src/commands/store/order-confirm.ts +0 -45
  193. package/src/commands/store/order-get.ts +0 -66
  194. package/src/commands/store/order-update.ts +0 -52
  195. package/src/commands/store/update-settings.ts +0 -52
  196. package/src/commands/target/index.ts +0 -118
  197. package/src/commands/tenant/invitations.ts +0 -62
  198. package/src/commands/tenant/invite.ts +0 -57
  199. package/src/commands/tenant/list.ts +0 -46
  200. package/src/commands/tenant/members.ts +0 -55
  201. package/src/commands/tenant/remove.ts +0 -47
  202. package/src/commands/tenant/revoke-invitation.ts +0 -32
  203. package/src/commands/tenant/update-role.ts +0 -41
  204. package/src/config.ts +0 -120
  205. package/src/error-handler.ts +0 -53
  206. package/src/format.ts +0 -181
  207. package/src/output.ts +0 -228
  208. package/src/spinner.ts +0 -39
  209. package/tsconfig.json +0 -22
  210. package/tsup.config.ts +0 -18
@@ -1,89 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, outputTable, EXIT, hasColor } from "../../output.js";
4
- import { formatAmount, formatStatus, fyStart, todayISO, monthStart, monthEnd } from "../../format.js";
5
- import chalk from "chalk";
6
-
7
- interface InvoiceBreakdownOpts {
8
- from?: string;
9
- to?: string;
10
- thisMonth?: boolean;
11
- thisFy?: boolean;
12
- json?: boolean;
13
- }
14
-
15
- export async function dashboardInvoiceBreakdownCommand(opts: InvoiceBreakdownOpts): Promise<void> {
16
- const cfg = requireAuth();
17
- const client = new HisaaboClient(cfg);
18
-
19
- let fromDate = opts.from;
20
- let toDate = opts.to;
21
- if (opts.thisMonth) { fromDate = monthStart(); toDate = monthEnd(); }
22
- else if (opts.thisFy) { fromDate = fyStart(); toDate = todayISO(); }
23
-
24
- try {
25
- const data = await client.dashboard.invoiceStatusBreakdown({ fromDate, toDate });
26
-
27
- if (opts.json) {
28
- outputJSON(data);
29
- return;
30
- }
31
-
32
- // data may be an object like { draft: { count, amount }, sent: { count, amount }, ... }
33
- // or an array of { status, count, amount }
34
- const ORDER = ["draft", "sent", "partial", "paid", "overdue", "cancelled"];
35
-
36
- let rows: Array<{ status: string; count: string; amount: string }>;
37
-
38
- if (Array.isArray(data)) {
39
- rows = data.map((r: Record<string, unknown>) => ({
40
- status: formatStatus(String(r["status"] ?? "-")),
41
- count: String(r["count"] ?? "-"),
42
- amount: formatAmount(String(r["totalAmount"] ?? r["amount"] ?? "0")),
43
- }));
44
- } else if (data && typeof data === "object") {
45
- const obj = data as Record<string, unknown>;
46
- rows = ORDER.flatMap((status) => {
47
- const entry = obj[status] as Record<string, unknown> | undefined;
48
- if (!entry) return [];
49
- return [{
50
- status: formatStatus(status),
51
- count: String(entry["count"] ?? "-"),
52
- amount: formatAmount(String(entry["totalAmount"] ?? entry["amount"] ?? "0")),
53
- }];
54
- });
55
- // Also include any statuses not in ORDER
56
- for (const key of Object.keys(obj)) {
57
- if (!ORDER.includes(key)) {
58
- const entry = obj[key] as Record<string, unknown>;
59
- rows.push({
60
- status: formatStatus(key),
61
- count: String(entry["count"] ?? "-"),
62
- amount: formatAmount(String(entry["totalAmount"] ?? entry["amount"] ?? "0")),
63
- });
64
- }
65
- }
66
- } else {
67
- rows = [];
68
- }
69
-
70
- const columns = [
71
- { key: "status", header: "Status", align: "left" as const },
72
- { key: "count", header: "Count", align: "right" as const },
73
- { key: "amount", header: "Amount ₹", align: "right" as const },
74
- ];
75
-
76
- if (hasColor()) process.stdout.write("\n" + chalk.bold(" Invoice Status Breakdown\n") + "\n");
77
- else process.stdout.write("\n Invoice Status Breakdown\n\n");
78
- outputTable(rows, columns);
79
- process.stdout.write("\n");
80
-
81
- } catch (e) {
82
- if (e instanceof HisaaboApiError) {
83
- const err = e.hisaaboError;
84
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
85
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
86
- }
87
- fatalError(String(e instanceof Error ? e.message : e));
88
- }
89
- }
@@ -1,193 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, hasColor } from "../../output.js";
4
- import { formatAmount } from "../../format.js";
5
- import chalk from "chalk";
6
-
7
- interface MonthlyComparisonOpts {
8
- json?: boolean;
9
- format?: string;
10
- }
11
-
12
- function changeArrow(pct: number): string {
13
- if (!hasColor()) return pct >= 0 ? `+${pct.toFixed(1)}%` : `${pct.toFixed(1)}%`;
14
- if (pct > 0) return chalk.green(`▲ +${pct.toFixed(1)}%`);
15
- if (pct < 0) return chalk.red(`▼ ${pct.toFixed(1)}%`);
16
- return chalk.dim("─ 0.0%");
17
- }
18
-
19
- function pctChange(current: number, previous: number): number {
20
- if (previous === 0) return current > 0 ? 100 : 0;
21
- return ((current - previous) / Math.abs(previous)) * 100;
22
- }
23
-
24
- export async function dashboardMonthlyComparisonCommand(opts: MonthlyComparisonOpts): Promise<void> {
25
- const cfg = requireAuth();
26
- const client = new HisaaboClient(cfg);
27
-
28
- try {
29
- const data = await client.dashboard.monthlyComparison();
30
-
31
- if (opts.json) {
32
- outputJSON(data);
33
- return;
34
- }
35
-
36
- // data can be:
37
- // 1. An array of monthly records: [{ month, year, sales, expenses, profit, collections, ... }]
38
- // 2. An object: { current: {...}, previous: {...}, ... }
39
- // 3. An object with month keys: { "2025-03": {...}, "2025-04": {...}, ... }
40
-
41
- type MonthRecord = {
42
- period: string;
43
- sales: number;
44
- expenses: number;
45
- profit: number;
46
- collections: number;
47
- };
48
-
49
- let months: MonthRecord[] = [];
50
-
51
- if (Array.isArray(data)) {
52
- months = data.map((r: Record<string, unknown>) => {
53
- const month = String(r["month"] ?? r["period"] ?? r["label"] ?? "-");
54
- const year = r["year"] ? String(r["year"]) : "";
55
- const period = year ? `${month} ${year}` : month;
56
- return {
57
- period,
58
- sales: parseFloat(String(r["sales"] ?? r["totalSales"] ?? "0")),
59
- expenses: parseFloat(String(r["expenses"] ?? r["totalExpenses"] ?? "0")),
60
- profit: parseFloat(String(r["profit"] ?? r["netProfit"] ?? "0")),
61
- collections: parseFloat(String(r["collections"] ?? r["totalCollections"] ?? "0")),
62
- };
63
- });
64
- } else if (data && typeof data === "object") {
65
- const obj = data as Record<string, unknown>;
66
- // Try current/previous shape
67
- if ("current" in obj || "previous" in obj) {
68
- const cur = (obj["current"] ?? {}) as Record<string, unknown>;
69
- const prev = (obj["previous"] ?? {}) as Record<string, unknown>;
70
- months = [
71
- {
72
- period: "Previous Month",
73
- sales: parseFloat(String(prev["sales"] ?? prev["totalSales"] ?? "0")),
74
- expenses: parseFloat(String(prev["expenses"] ?? prev["totalExpenses"] ?? "0")),
75
- profit: parseFloat(String(prev["profit"] ?? prev["netProfit"] ?? "0")),
76
- collections: parseFloat(String(prev["collections"] ?? prev["totalCollections"] ?? "0")),
77
- },
78
- {
79
- period: "Current Month",
80
- sales: parseFloat(String(cur["sales"] ?? cur["totalSales"] ?? "0")),
81
- expenses: parseFloat(String(cur["expenses"] ?? cur["totalExpenses"] ?? "0")),
82
- profit: parseFloat(String(cur["profit"] ?? cur["netProfit"] ?? "0")),
83
- collections: parseFloat(String(cur["collections"] ?? cur["totalCollections"] ?? "0")),
84
- },
85
- ];
86
- } else {
87
- // Month-keyed object: sort chronologically
88
- const entries = Object.entries(obj).sort(([a], [b]) => a.localeCompare(b));
89
- months = entries.map(([period, val]) => {
90
- const r = (val ?? {}) as Record<string, unknown>;
91
- return {
92
- period,
93
- sales: parseFloat(String(r["sales"] ?? r["totalSales"] ?? "0")),
94
- expenses: parseFloat(String(r["expenses"] ?? r["totalExpenses"] ?? "0")),
95
- profit: parseFloat(String(r["profit"] ?? r["netProfit"] ?? "0")),
96
- collections: parseFloat(String(r["collections"] ?? r["totalCollections"] ?? "0")),
97
- };
98
- });
99
- }
100
- }
101
-
102
- if (opts.format === "tsv" || opts.format === "csv") {
103
- const rows = months.map((m, i) => {
104
- const prev = months[i - 1];
105
- return {
106
- period: m.period,
107
- sales: formatAmount(m.sales),
108
- salesChg: prev ? `${pctChange(m.sales, prev.sales).toFixed(1)}%` : "-",
109
- expenses: formatAmount(m.expenses),
110
- profit: formatAmount(m.profit),
111
- collections: formatAmount(m.collections),
112
- };
113
- });
114
- const columns = [
115
- { key: "period", header: "Month", align: "left" as const },
116
- { key: "sales", header: "Sales ₹", align: "right" as const },
117
- { key: "salesChg", header: "Sales Δ%", align: "right" as const },
118
- { key: "expenses", header: "Expenses ₹", align: "right" as const },
119
- { key: "profit", header: "Profit ₹", align: "right" as const },
120
- { key: "collections", header: "Collections ₹", align: "right" as const },
121
- ];
122
- if (opts.format === "tsv") outputTSV(rows, columns);
123
- else outputCSV(rows, columns);
124
- return;
125
- }
126
-
127
- // Pretty table display
128
- if (hasColor()) process.stdout.write("\n" + chalk.bold(" Monthly Comparison\n") + "\n");
129
- else process.stdout.write("\n Monthly Comparison\n\n");
130
-
131
- // Show month-over-month change for last two months if we have >= 2
132
- if (months.length >= 2) {
133
- const last = months[months.length - 1]!;
134
- const prev = months[months.length - 2]!;
135
- const salesPct = pctChange(last.sales, prev.sales);
136
- const expPct = pctChange(last.expenses, prev.expenses);
137
- const profitPct = pctChange(last.profit, prev.profit);
138
- const collPct = pctChange(last.collections, prev.collections);
139
-
140
- process.stdout.write(` ${hasColor() ? chalk.dim("Month-over-month (latest vs previous)") : "Month-over-month (latest vs previous)"}\n\n`);
141
- const summaryRows = [
142
- { metric: "Sales", current: formatAmount(last.sales), change: changeArrow(salesPct) },
143
- { metric: "Collections", current: formatAmount(last.collections), change: changeArrow(collPct) },
144
- { metric: "Expenses", current: formatAmount(last.expenses), change: changeArrow(-expPct) },
145
- { metric: "Profit", current: formatAmount(last.profit), change: changeArrow(profitPct) },
146
- ];
147
- const summaryColumns = [
148
- { key: "metric", header: "Metric", align: "left" as const },
149
- { key: "current", header: "Latest ₹", align: "right" as const },
150
- { key: "change", header: "vs Prev", align: "right" as const },
151
- ];
152
- outputTable(summaryRows, summaryColumns);
153
- process.stdout.write("\n");
154
- }
155
-
156
- // Full trend table
157
- const rows = months.map((m, i) => {
158
- const prev = months[i - 1];
159
- const salesChg = prev ? changeArrow(pctChange(m.sales, prev.sales)) : "-";
160
- const profitColor = m.profit >= 0
161
- ? (hasColor() ? chalk.green(formatAmount(m.profit)) : formatAmount(m.profit))
162
- : (hasColor() ? chalk.red(formatAmount(m.profit)) : formatAmount(m.profit));
163
- return {
164
- period: m.period,
165
- sales: formatAmount(m.sales),
166
- salesChg,
167
- expenses: formatAmount(m.expenses),
168
- profit: profitColor,
169
- collections: formatAmount(m.collections),
170
- };
171
- });
172
-
173
- const columns = [
174
- { key: "period", header: "Month", align: "left" as const },
175
- { key: "sales", header: "Sales ₹", align: "right" as const },
176
- { key: "salesChg", header: "Δ%", align: "right" as const },
177
- { key: "expenses", header: "Expenses ₹", align: "right" as const },
178
- { key: "profit", header: "Profit ₹", align: "right" as const },
179
- { key: "collections", header: "Collections ₹", align: "right" as const },
180
- ];
181
-
182
- outputTable(rows, columns);
183
- process.stdout.write("\n");
184
-
185
- } catch (e) {
186
- if (e instanceof HisaaboApiError) {
187
- const err = e.hisaaboError;
188
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
189
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
190
- }
191
- fatalError(String(e instanceof Error ? e.message : e));
192
- }
193
- }
@@ -1,121 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, hasColor } from "../../output.js";
4
- import { formatAmount, fyStart, todayISO, monthStart, monthEnd } from "../../format.js";
5
- import chalk from "chalk";
6
-
7
- interface PaymentModesOpts {
8
- from?: string;
9
- to?: string;
10
- thisMonth?: boolean;
11
- thisFy?: boolean;
12
- json?: boolean;
13
- format?: string;
14
- }
15
-
16
- const MODE_LABELS: Record<string, string> = {
17
- cash: "Cash",
18
- upi: "UPI",
19
- bank_transfer: "Bank Transfer",
20
- cheque: "Cheque",
21
- card: "Card",
22
- neft: "NEFT",
23
- rtgs: "RTGS",
24
- imps: "IMPS",
25
- dd: "Demand Draft",
26
- credit: "Credit",
27
- other: "Other",
28
- };
29
-
30
- function modeLabel(raw: string): string {
31
- return MODE_LABELS[raw.toLowerCase()] ?? raw;
32
- }
33
-
34
- export async function dashboardPaymentModesCommand(opts: PaymentModesOpts): Promise<void> {
35
- const cfg = requireAuth();
36
- const client = new HisaaboClient(cfg);
37
-
38
- let fromDate = opts.from;
39
- let toDate = opts.to;
40
- if (opts.thisMonth) { fromDate = monthStart(); toDate = monthEnd(); }
41
- else if (opts.thisFy) { fromDate = fyStart(); toDate = todayISO(); }
42
-
43
- try {
44
- const data = await client.dashboard.paymentModeBreakdown({ fromDate, toDate });
45
-
46
- if (opts.json) {
47
- outputJSON(data);
48
- return;
49
- }
50
-
51
- // data can be an array of { mode, amount, count } or an object keyed by mode
52
- type ModeRow = { mode: string; amount: number; count: number };
53
- let modes: ModeRow[] = [];
54
-
55
- if (Array.isArray(data)) {
56
- modes = data.map((r: Record<string, unknown>) => ({
57
- mode: String(r["mode"] ?? r["paymentMode"] ?? r["method"] ?? "-"),
58
- amount: parseFloat(String(r["amount"] ?? r["totalAmount"] ?? "0")),
59
- count: parseInt(String(r["count"] ?? r["paymentCount"] ?? "0"), 10),
60
- }));
61
- } else if (data && typeof data === "object") {
62
- const obj = data as Record<string, unknown>;
63
- for (const [key, val] of Object.entries(obj)) {
64
- if (typeof val === "object" && val !== null) {
65
- const entry = val as Record<string, unknown>;
66
- modes.push({
67
- mode: key,
68
- amount: parseFloat(String(entry["amount"] ?? entry["totalAmount"] ?? "0")),
69
- count: parseInt(String(entry["count"] ?? "0"), 10),
70
- });
71
- } else if (typeof val === "string" || typeof val === "number") {
72
- modes.push({ mode: key, amount: parseFloat(String(val)), count: 0 });
73
- }
74
- }
75
- }
76
-
77
- // Sort descending by amount
78
- modes.sort((a, b) => b.amount - a.amount);
79
-
80
- const total = modes.reduce((s, r) => s + r.amount, 0);
81
-
82
- const rows = modes.map((r) => {
83
- const pct = total > 0 ? ((r.amount / total) * 100).toFixed(1) + "%" : "-";
84
- return {
85
- mode: modeLabel(r.mode),
86
- amount: formatAmount(r.amount),
87
- count: r.count > 0 ? String(r.count) : "-",
88
- pct,
89
- };
90
- });
91
-
92
- const columns = [
93
- { key: "mode", header: "Payment Mode", align: "left" as const },
94
- { key: "amount", header: "Amount ₹", align: "right" as const },
95
- { key: "count", header: "Count", align: "right" as const },
96
- { key: "pct", header: "% of Total", align: "right" as const },
97
- ];
98
-
99
- if (opts.format === "tsv") {
100
- outputTSV(rows, columns);
101
- } else if (opts.format === "csv") {
102
- outputCSV(rows, columns);
103
- } else {
104
- if (hasColor()) process.stdout.write("\n" + chalk.bold(" Payment Mode Breakdown\n") + "\n");
105
- else process.stdout.write("\n Payment Mode Breakdown\n\n");
106
- outputTable(rows, columns);
107
- if (total > 0) {
108
- const totalStr = ` Total: ₹${formatAmount(total)}`;
109
- process.stdout.write("\n" + (hasColor() ? chalk.bold(totalStr) : totalStr) + "\n");
110
- }
111
- process.stdout.write("\n");
112
- }
113
- } catch (e) {
114
- if (e instanceof HisaaboApiError) {
115
- const err = e.hisaaboError;
116
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
117
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
118
- }
119
- fatalError(String(e instanceof Error ? e.message : e));
120
- }
121
- }
@@ -1,146 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, EXIT, hasColor, termWidth } from "../../output.js";
4
- import { formatINR, formatDate, fyStart, todayISO, monthStart, monthEnd } from "../../format.js";
5
- import chalk from "chalk";
6
-
7
- interface ProfitLossOpts {
8
- from?: string;
9
- to?: string;
10
- thisMonth?: boolean;
11
- thisFy?: boolean;
12
- json?: boolean;
13
- }
14
-
15
- function plLine(
16
- label: string,
17
- value: string,
18
- innerW: number,
19
- opts: { bold?: boolean; dim?: boolean; separator?: boolean; indent?: number } = {}
20
- ): string {
21
- const indent = opts.indent ?? 0;
22
- const indentStr = " ".repeat(indent * 2);
23
- const fullLabel = indentStr + label;
24
- const rightPad = 2;
25
- const maxValueLen = 18;
26
- const labelWidth = innerW - maxValueLen - rightPad;
27
- const truncLabel = fullLabel.length > labelWidth ? fullLabel.slice(0, labelWidth - 1) + "…" : fullLabel;
28
- const paddedLabel = truncLabel.padEnd(labelWidth);
29
- const paddedValue = value.padStart(maxValueLen - rightPad) + " ".repeat(rightPad);
30
-
31
- let line = `│ ${paddedLabel}${paddedValue}│`;
32
-
33
- if (!hasColor()) return line;
34
- if (opts.bold) line = line.replace(paddedLabel, chalk.bold(truncLabel.padEnd(labelWidth)));
35
- if (opts.dim) line = chalk.dim(line);
36
- return line;
37
- }
38
-
39
- function plSeparator(innerW: number): string {
40
- // Right-aligned dashes inside the box
41
- const dashLen = 18;
42
- const leftPad = innerW - dashLen;
43
- const line = `│ ${" ".repeat(leftPad - 1)}${"─".repeat(dashLen)} │`;
44
- return hasColor() ? chalk.dim(line) : line;
45
- }
46
-
47
- function plBlank(innerW: number): string {
48
- return `│ ${" ".repeat(innerW)} │`;
49
- }
50
-
51
- function plBorder(innerW: number, char: "┌" | "└"): string {
52
- const side = char === "┌" ? "┐" : "┘";
53
- return char + "─".repeat(innerW) + side;
54
- }
55
-
56
- function plTitle(title: string, innerW: number): string {
57
- const pad = Math.max(0, innerW - title.length - 2);
58
- const line = `│ ${hasColor() ? chalk.bold(title) : title}${" ".repeat(pad)} │`;
59
- return line;
60
- }
61
-
62
- function formatPL(amount: number): string {
63
- if (amount < 0) return `(${formatINR(Math.abs(amount))})`;
64
- return formatINR(amount);
65
- }
66
-
67
- function colorPL(formatted: string, isProfit: boolean): string {
68
- if (!hasColor()) return formatted;
69
- const num = parseFloat(formatted.replace(/[₹,()]/g, ""));
70
- if (isNaN(num) || num === 0) return chalk.dim(formatted);
71
- return isProfit ? chalk.green(formatted) : chalk.red(formatted);
72
- }
73
-
74
- export async function dashboardProfitLossCommand(opts: ProfitLossOpts): Promise<void> {
75
- const cfg = requireAuth();
76
- const client = new HisaaboClient(cfg);
77
-
78
- let fromDate = opts.from ?? fyStart();
79
- let toDate = opts.to ?? todayISO();
80
- if (opts.thisMonth) { fromDate = monthStart(); toDate = monthEnd(); }
81
- else if (opts.thisFy) { fromDate = fyStart(); toDate = todayISO(); }
82
-
83
- try {
84
- const data = await client.dashboard.profitAndLoss({ fromDate, toDate });
85
-
86
- if (opts.json) {
87
- outputJSON(data);
88
- return;
89
- }
90
-
91
- const pl = data as Record<string, unknown>;
92
-
93
- const revenue = parseFloat(String(pl["revenue"] ?? pl["totalRevenue"] ?? pl["sales"] ?? "0"));
94
- const cogs = parseFloat(String(pl["cogs"] ?? pl["costOfGoodsSold"] ?? pl["purchases"] ?? "0"));
95
- const grossProfit = parseFloat(String(pl["grossProfit"] ?? String(revenue - cogs)));
96
- const opex = parseFloat(String(pl["operatingExpenses"] ?? pl["expenses"] ?? pl["totalExpenses"] ?? "0"));
97
- const netProfit = parseFloat(String(pl["netProfit"] ?? pl["profit"] ?? String(grossProfit - opex)));
98
-
99
- const grossMargin = revenue > 0 ? ((grossProfit / revenue) * 100).toFixed(1) + "%" : "-";
100
- const netMargin = revenue > 0 ? ((netProfit / revenue) * 100).toFixed(1) + "%" : "-";
101
-
102
- const width = Math.min(termWidth() - 2, 52);
103
- const innerW = width - 2;
104
-
105
- const lines: string[] = [];
106
-
107
- lines.push(plBorder(innerW, "┌"));
108
- lines.push(plTitle("PROFIT & LOSS STATEMENT", innerW));
109
- lines.push(plTitle(`${formatDate(fromDate)} – ${formatDate(toDate)}`, innerW));
110
- lines.push(`├${"─".repeat(innerW)}┤`);
111
- lines.push(plBlank(innerW));
112
-
113
- lines.push(plLine("Revenue", formatPL(revenue), innerW, { bold: true }));
114
- lines.push(plLine("Cost of Goods Sold", formatPL(-cogs), innerW));
115
- lines.push(plSeparator(innerW));
116
-
117
- const gpFormatted = formatPL(grossProfit);
118
- lines.push(plLine("Gross Profit", colorPL(gpFormatted, grossProfit >= 0), innerW, { bold: true }));
119
- lines.push(plLine("Gross Margin", grossMargin, innerW, { dim: true }));
120
- lines.push(plBlank(innerW));
121
-
122
- lines.push(plLine("Operating Expenses", formatPL(-opex), innerW));
123
- lines.push(plSeparator(innerW));
124
-
125
- const npFormatted = formatPL(netProfit);
126
- lines.push(plLine("Net Profit", colorPL(npFormatted, netProfit >= 0), innerW, { bold: true }));
127
- lines.push(plLine("Net Margin", netMargin, innerW, { dim: true }));
128
- lines.push(plBlank(innerW));
129
-
130
- lines.push(plBorder(innerW, "└"));
131
-
132
- process.stdout.write("\n");
133
- for (const l of lines) {
134
- process.stdout.write(" " + l + "\n");
135
- }
136
- process.stdout.write("\n");
137
-
138
- } catch (e) {
139
- if (e instanceof HisaaboApiError) {
140
- const err = e.hisaaboError;
141
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
142
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
143
- }
144
- fatalError(String(e instanceof Error ? e.message : e));
145
- }
146
- }