@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.
- package/LICENSE +31 -0
- package/README.md +9 -0
- package/dist/bin/{audit-trail-DLSSSM4T.js → audit-trail-IJ6SKACR.js} +2 -2
- package/dist/bin/{categories-63QR6WCV.js → categories-O6TODPAH.js} +2 -2
- package/dist/bin/{check-slug-NXO55WKH.js → check-slug-P7RFU6OP.js} +2 -2
- package/dist/bin/chunk-NO4FIFMS.js +0 -0
- package/dist/bin/{chunk-7MJDOL6B.js → chunk-QUITS2FE.js} +28 -0
- package/dist/bin/{chunk-M42SETRZ.js → chunk-WDN7RIE3.js} +23 -2
- package/dist/bin/chunk-ZPYC767N.js +0 -0
- package/dist/bin/{client-T32CIZA3.js → client-36JX5MR3.js} +1 -1
- package/dist/bin/{collection-efficiency-T6PWNTZO.js → collection-efficiency-DA5RWG3V.js} +2 -2
- package/dist/bin/{config-V4QFCONN.js → config-4LLNT4SH.js} +3 -1
- package/dist/bin/{create-NUKHDWLK.js → create-C5INBPQO.js} +2 -2
- package/dist/bin/{default-account-JWFPHMRF.js → default-account-2GMQ7ZA4.js} +2 -2
- package/dist/bin/{expenses-2UWUZVLI.js → expenses-S2YVA5UT.js} +2 -2
- package/dist/bin/{export-XSX7WQH7.js → export-YOOODNVX.js} +2 -2
- package/dist/bin/export-ZA43MLWO.js +191 -0
- package/dist/bin/{factory-BWOKRIP4.js → factory-6MUCSXTL.js} +2 -2
- package/dist/bin/{get-CHNTG3IM.js → get-GMQRROK2.js} +2 -2
- package/dist/bin/{get-ZSZ6SL3N.js → get-ZV3SC2VY.js} +2 -2
- package/dist/bin/hisaabo.js +100 -57
- package/dist/bin/import-UUHMLCKX.js +267 -0
- package/dist/bin/{invitations-H2SL3XAD.js → invitations-OVORTTMF.js} +2 -2
- package/dist/bin/{invite-EW73UIBE.js → invite-GGHBZY4U.js} +2 -2
- package/dist/bin/{invoice-breakdown-XP4QATCF.js → invoice-breakdown-32XXAZDP.js} +2 -2
- package/dist/bin/{items-DPD6EFTP.js → items-6NOIMH6B.js} +2 -2
- package/dist/bin/{items-toggle-R4OPSE4W.js → items-toggle-L6W6QKQD.js} +2 -2
- package/dist/bin/{list-PKHBE475.js → list-FC5JHKHD.js} +2 -2
- package/dist/bin/{list-KLEHBMQ2.js → list-OXAVDXH7.js} +2 -2
- package/dist/bin/{list-UR7OOJVF.js → list-RAR56EMQ.js} +2 -2
- package/dist/bin/{members-XA3TF4IQ.js → members-Y6XJVHHR.js} +2 -2
- package/dist/bin/{monthly-comparison-OLVS5HEY.js → monthly-comparison-IAUZ6SBJ.js} +2 -2
- package/dist/bin/{order-cancel-MXMJFFRR.js → order-cancel-QRTCNART.js} +2 -2
- package/dist/bin/{order-confirm-IXU45Q4L.js → order-confirm-LGQOMC4O.js} +2 -2
- package/dist/bin/{order-get-RDXMHLJ7.js → order-get-4XAQCRYV.js} +2 -2
- package/dist/bin/{order-update-KGIPBEJX.js → order-update-KZY4H2UR.js} +2 -2
- package/dist/bin/output-NUOL7KJW.js +0 -0
- package/dist/bin/{payment-modes-CZL35SVS.js → payment-modes-DY2ZEMK7.js} +2 -2
- package/dist/bin/{profit-loss-M332OSC5.js → profit-loss-5GJBG3PL.js} +2 -2
- package/dist/bin/{receivables-aging-OXRHGMBF.js → receivables-aging-6A7XJKDT.js} +2 -2
- package/dist/bin/{remove-I5HD2Y4K.js → remove-ZBX34TIQ.js} +2 -2
- package/dist/bin/{revoke-OC6AOMIZ.js → revoke-XDNOA2GJ.js} +2 -2
- package/dist/bin/{revoke-MFLWGCMP.js → revoke-ZTAMW2Q2.js} +2 -2
- package/dist/bin/{revoke-all-FSAPBB3P.js → revoke-all-365NRBOA.js} +2 -2
- package/dist/bin/{revoke-invitation-JXDPXTOW.js → revoke-invitation-PQH7XNYA.js} +2 -2
- package/dist/bin/{sales-trend-KK63WNDL.js → sales-trend-D6PQ7MHY.js} +2 -2
- package/dist/bin/{sequence-IQ4HUJ3W.js → sequence-KZWADVD7.js} +2 -2
- package/dist/bin/{store-6QT6HKG2.js → store-SVRZBUFO.js} +2 -2
- package/dist/bin/{summary-3FTF5B4A.js → summary-H6U7O5GJ.js} +2 -2
- package/dist/bin/{top-customers-HNYGXBQZ.js → top-customers-ATBN6RDI.js} +2 -2
- package/dist/bin/{top-items-JUDG3BVW.js → top-items-XXU6KYTC.js} +2 -2
- package/dist/bin/{top-outstanding-WK26ZNE5.js → top-outstanding-JTQNGGW4.js} +2 -2
- package/dist/bin/{unpaid-invoices-RYFIIIK7.js → unpaid-invoices-BTNQFWCH.js} +2 -2
- package/dist/bin/{untracked-FAFS3KCK.js → untracked-PAMEDJ6Y.js} +2 -2
- package/dist/bin/{update-5YSPXIWO.js → update-6ZMX2OYX.js} +2 -2
- package/dist/bin/{update-I46XLU77.js → update-EGHPFXLK.js} +2 -2
- package/dist/bin/{update-NAW2JWZS.js → update-EK4NJWU4.js} +2 -2
- package/dist/bin/{update-role-5GV42MSN.js → update-role-24PDTNFK.js} +2 -2
- package/dist/bin/{update-settings-KYSQDIEO.js → update-settings-AASI6WZX.js} +2 -2
- package/package.json +35 -9
- package/.turbo/turbo-build.log +0 -13
- package/.turbo/turbo-typecheck.log +0 -4
- package/CLI-UX-ARCHITECTURE.md +0 -1269
- package/src/auth.ts +0 -221
- package/src/bin/hisaabo.ts +0 -74
- package/src/bin/registrars/api-key.ts +0 -44
- package/src/bin/registrars/auth.ts +0 -222
- package/src/bin/registrars/automated-invoice.ts +0 -167
- package/src/bin/registrars/bank-recon.ts +0 -34
- package/src/bin/registrars/bank.ts +0 -124
- package/src/bin/registrars/business.ts +0 -120
- package/src/bin/registrars/dashboard.ts +0 -225
- package/src/bin/registrars/document.ts +0 -184
- package/src/bin/registrars/einvoice.ts +0 -46
- package/src/bin/registrars/ewb.ts +0 -37
- package/src/bin/registrars/expense.ts +0 -87
- package/src/bin/registrars/gst.ts +0 -57
- package/src/bin/registrars/import.ts +0 -49
- package/src/bin/registrars/invoice.ts +0 -117
- package/src/bin/registrars/itc.ts +0 -56
- package/src/bin/registrars/item.ts +0 -112
- package/src/bin/registrars/journal.ts +0 -47
- package/src/bin/registrars/party.ts +0 -81
- package/src/bin/registrars/payment.ts +0 -128
- package/src/bin/registrars/report.ts +0 -186
- package/src/bin/registrars/session.ts +0 -32
- package/src/bin/registrars/shipment.ts +0 -74
- package/src/bin/registrars/store.ts +0 -128
- package/src/bin/registrars/target.ts +0 -46
- package/src/bin/registrars/tenant.ts +0 -73
- package/src/client.ts +0 -2071
- package/src/commands/api-key/create.ts +0 -72
- package/src/commands/api-key/list.ts +0 -71
- package/src/commands/api-key/revoke.ts +0 -46
- package/src/commands/automated-invoice/create.ts +0 -85
- package/src/commands/automated-invoice/delete.ts +0 -42
- package/src/commands/automated-invoice/get.ts +0 -113
- package/src/commands/automated-invoice/history.ts +0 -65
- package/src/commands/automated-invoice/index.ts +0 -11
- package/src/commands/automated-invoice/list.ts +0 -91
- package/src/commands/automated-invoice/pause.ts +0 -29
- package/src/commands/automated-invoice/resume.ts +0 -29
- package/src/commands/automated-invoice/run-now.ts +0 -29
- package/src/commands/automated-invoice/suggestions.ts +0 -68
- package/src/commands/automated-invoice/update.ts +0 -54
- package/src/commands/automated-invoice/usage.ts +0 -68
- package/src/commands/bank/gateway-config.ts +0 -61
- package/src/commands/bank/index.ts +0 -244
- package/src/commands/bank/update-gateway.ts +0 -84
- package/src/commands/bank-recon/index.ts +0 -127
- package/src/commands/business/audit-trail.ts +0 -79
- package/src/commands/business/export.ts +0 -52
- package/src/commands/business/get.ts +0 -55
- package/src/commands/business/sequence.ts +0 -65
- package/src/commands/business/update.ts +0 -64
- package/src/commands/dashboard/collection-efficiency.ts +0 -164
- package/src/commands/dashboard/expenses.ts +0 -76
- package/src/commands/dashboard/invoice-breakdown.ts +0 -89
- package/src/commands/dashboard/monthly-comparison.ts +0 -193
- package/src/commands/dashboard/payment-modes.ts +0 -121
- package/src/commands/dashboard/profit-loss.ts +0 -146
- package/src/commands/dashboard/receivables-aging.ts +0 -169
- package/src/commands/dashboard/sales-trend.ts +0 -68
- package/src/commands/dashboard/summary.ts +0 -105
- package/src/commands/dashboard/top-customers.ts +0 -70
- package/src/commands/dashboard/top-items.ts +0 -74
- package/src/commands/dashboard/top-outstanding.ts +0 -61
- package/src/commands/dashboard.ts +0 -105
- package/src/commands/document/factory.ts +0 -590
- package/src/commands/einvoice/index.ts +0 -109
- package/src/commands/ewb/index.ts +0 -108
- package/src/commands/expense/categories.ts +0 -40
- package/src/commands/expense/create.ts +0 -51
- package/src/commands/expense/delete.ts +0 -45
- package/src/commands/expense/list.ts +0 -65
- package/src/commands/expense/update.ts +0 -58
- package/src/commands/gst/index.ts +0 -194
- package/src/commands/import/index.ts +0 -168
- package/src/commands/invoice/create.ts +0 -262
- package/src/commands/invoice/delete.ts +0 -44
- package/src/commands/invoice/get.ts +0 -113
- package/src/commands/invoice/list.ts +0 -126
- package/src/commands/invoice/pdf.ts +0 -75
- package/src/commands/invoice/status.ts +0 -41
- package/src/commands/itc/index.ts +0 -163
- package/src/commands/item/categories.ts +0 -40
- package/src/commands/item/create.ts +0 -98
- package/src/commands/item/delete.ts +0 -44
- package/src/commands/item/list.ts +0 -81
- package/src/commands/item/low-stock-count.ts +0 -32
- package/src/commands/item/merge.ts +0 -53
- package/src/commands/item/price-history.ts +0 -59
- package/src/commands/item/rename-unit.ts +0 -39
- package/src/commands/item/sales-stats.ts +0 -44
- package/src/commands/item/stock-history.ts +0 -70
- package/src/commands/item/stock.ts +0 -46
- package/src/commands/item/switch-base-unit.ts +0 -42
- package/src/commands/item/update.ts +0 -59
- package/src/commands/item/variants-create.ts +0 -58
- package/src/commands/item/variants-delete.ts +0 -47
- package/src/commands/item/variants-list.ts +0 -63
- package/src/commands/item/variants-update.ts +0 -61
- package/src/commands/journal/index.ts +0 -156
- package/src/commands/party/create.ts +0 -88
- package/src/commands/party/delete.ts +0 -44
- package/src/commands/party/get.ts +0 -42
- package/src/commands/party/ledger-report.ts +0 -81
- package/src/commands/party/ledger.ts +0 -63
- package/src/commands/party/list.ts +0 -69
- package/src/commands/party/merge.ts +0 -50
- package/src/commands/party/stats.ts +0 -40
- package/src/commands/party/top-items.ts +0 -57
- package/src/commands/party/update.ts +0 -65
- package/src/commands/payment/create.ts +0 -131
- package/src/commands/payment/default-account.ts +0 -56
- package/src/commands/payment/delete.ts +0 -46
- package/src/commands/payment/get.ts +0 -59
- package/src/commands/payment/list.ts +0 -66
- package/src/commands/payment/unpaid-invoices.ts +0 -69
- package/src/commands/payment/untracked.ts +0 -70
- package/src/commands/payment/update.ts +0 -54
- package/src/commands/report/index.ts +0 -736
- package/src/commands/session/list.ts +0 -91
- package/src/commands/session/revoke-all.ts +0 -20
- package/src/commands/session/revoke.ts +0 -32
- package/src/commands/shipment/index.ts +0 -170
- package/src/commands/store/check-slug.ts +0 -48
- package/src/commands/store/index.ts +0 -77
- package/src/commands/store/items-toggle.ts +0 -41
- package/src/commands/store/items.ts +0 -61
- package/src/commands/store/order-cancel.ts +0 -48
- package/src/commands/store/order-confirm.ts +0 -45
- package/src/commands/store/order-get.ts +0 -66
- package/src/commands/store/order-update.ts +0 -52
- package/src/commands/store/update-settings.ts +0 -52
- package/src/commands/target/index.ts +0 -118
- package/src/commands/tenant/invitations.ts +0 -62
- package/src/commands/tenant/invite.ts +0 -57
- package/src/commands/tenant/list.ts +0 -46
- package/src/commands/tenant/members.ts +0 -55
- package/src/commands/tenant/remove.ts +0 -47
- package/src/commands/tenant/revoke-invitation.ts +0 -32
- package/src/commands/tenant/update-role.ts +0 -41
- package/src/config.ts +0 -120
- package/src/error-handler.ts +0 -53
- package/src/format.ts +0 -181
- package/src/output.ts +0 -228
- package/src/spinner.ts +0 -39
- package/tsconfig.json +0 -22
- package/tsup.config.ts +0 -18
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import { fatalError, outputJSON, EXIT } from "../../output.js";
|
|
4
|
-
import { formatDate } from "../../format.js";
|
|
5
|
-
|
|
6
|
-
interface JournalOpts {
|
|
7
|
-
json?: boolean;
|
|
8
|
-
page?: number;
|
|
9
|
-
limit?: number;
|
|
10
|
-
from?: string;
|
|
11
|
-
to?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function handleError(e: unknown): never {
|
|
15
|
-
if (e instanceof HisaaboApiError) {
|
|
16
|
-
const err = e.hisaaboError;
|
|
17
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
18
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
19
|
-
}
|
|
20
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function journalListCommand(opts: JournalOpts): Promise<void> {
|
|
24
|
-
const cfg = requireAuth();
|
|
25
|
-
const client = new HisaaboClient(cfg);
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
const result = await client.journal.list({
|
|
29
|
-
page: opts.page ?? 1,
|
|
30
|
-
limit: opts.limit ?? 25,
|
|
31
|
-
fromDate: opts.from,
|
|
32
|
-
toDate: opts.to,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
if (opts.json) {
|
|
36
|
-
outputJSON(result);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const entries = Array.isArray(result) ? result
|
|
41
|
-
: Array.isArray(result?.data) ? result.data
|
|
42
|
-
: [];
|
|
43
|
-
|
|
44
|
-
console.log(`\n Journal Entries\n`);
|
|
45
|
-
console.log(` ${"═".repeat(70)}\n`);
|
|
46
|
-
|
|
47
|
-
if (entries.length === 0) {
|
|
48
|
-
console.log(" No journal entries found.\n");
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
for (const entry of entries as Array<Record<string, unknown>>) {
|
|
53
|
-
const date = formatDate(String(entry["date"] ?? entry["journalDate"] ?? ""));
|
|
54
|
-
const number = String(entry["number"] ?? entry["voucherNumber"] ?? "-");
|
|
55
|
-
const narration = String(entry["narration"] ?? entry["description"] ?? "").slice(0, 40);
|
|
56
|
-
const status = String(entry["status"] ?? "").padEnd(8);
|
|
57
|
-
console.log(` ${date.padEnd(13)} ${number.padEnd(14)} ${status} ${narration}`);
|
|
58
|
-
}
|
|
59
|
-
console.log();
|
|
60
|
-
|
|
61
|
-
} catch (e) {
|
|
62
|
-
handleError(e);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export async function journalGetCommand(id: string, opts: { json?: boolean }): Promise<void> {
|
|
67
|
-
const cfg = requireAuth();
|
|
68
|
-
const client = new HisaaboClient(cfg);
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
const result = await client.journal.getById(id);
|
|
72
|
-
|
|
73
|
-
if (opts.json) {
|
|
74
|
-
outputJSON(result);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const r = result as Record<string, unknown>;
|
|
79
|
-
console.log(`\n Journal Entry — ${String(r["number"] ?? r["voucherNumber"] ?? id)}\n`);
|
|
80
|
-
console.log(` ${"═".repeat(60)}\n`);
|
|
81
|
-
console.log(` Date: ${formatDate(String(r["date"] ?? r["journalDate"] ?? ""))}`);
|
|
82
|
-
console.log(` Narration: ${String(r["narration"] ?? r["description"] ?? "-")}`);
|
|
83
|
-
console.log(` Status: ${String(r["status"] ?? "-")}`);
|
|
84
|
-
console.log();
|
|
85
|
-
|
|
86
|
-
const lines = r["lines"] ?? r["entries"] ?? r["lineItems"];
|
|
87
|
-
if (lines && Array.isArray(lines)) {
|
|
88
|
-
console.log(" Lines:\n");
|
|
89
|
-
for (const line of lines as Array<Record<string, unknown>>) {
|
|
90
|
-
const account = String(line["accountName"] ?? line["account"] ?? "-").padEnd(28);
|
|
91
|
-
const debit = String(line["debit"] ?? "0");
|
|
92
|
-
const credit = String(line["credit"] ?? "0");
|
|
93
|
-
console.log(` ${account} Dr: ${debit.padStart(12)} Cr: ${credit.padStart(12)}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
console.log();
|
|
97
|
-
|
|
98
|
-
} catch (e) {
|
|
99
|
-
handleError(e);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export async function journalVoidCommand(id: string, opts: { json?: boolean }): Promise<void> {
|
|
104
|
-
const cfg = requireAuth();
|
|
105
|
-
const client = new HisaaboClient(cfg);
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
const result = await client.journal.void(id);
|
|
109
|
-
|
|
110
|
-
if (opts.json) {
|
|
111
|
-
outputJSON(result);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
console.log(` Journal entry ${id} voided.\n`);
|
|
116
|
-
|
|
117
|
-
} catch (e) {
|
|
118
|
-
handleError(e);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export async function journalTemplatesCommand(opts: { json?: boolean }): Promise<void> {
|
|
123
|
-
const cfg = requireAuth();
|
|
124
|
-
const client = new HisaaboClient(cfg);
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
const result = await client.journal.templateList();
|
|
128
|
-
|
|
129
|
-
if (opts.json) {
|
|
130
|
-
outputJSON(result);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const templates = Array.isArray(result) ? result
|
|
135
|
-
: Array.isArray(result?.data) ? result.data
|
|
136
|
-
: [];
|
|
137
|
-
|
|
138
|
-
console.log(`\n Journal Templates\n`);
|
|
139
|
-
console.log(` ${"═".repeat(50)}\n`);
|
|
140
|
-
|
|
141
|
-
if (templates.length === 0) {
|
|
142
|
-
console.log(" No templates found.\n");
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
for (const t of templates as Array<Record<string, unknown>>) {
|
|
147
|
-
const id = String(t["id"] ?? "-").slice(0, 8);
|
|
148
|
-
const name = String(t["name"] ?? "-").padEnd(30);
|
|
149
|
-
console.log(` ${id} ${name}`);
|
|
150
|
-
}
|
|
151
|
-
console.log();
|
|
152
|
-
|
|
153
|
-
} catch (e) {
|
|
154
|
-
handleError(e);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
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 CreateOpts {
|
|
7
|
-
json?: boolean;
|
|
8
|
-
type?: string;
|
|
9
|
-
name?: string;
|
|
10
|
-
phone?: string;
|
|
11
|
-
email?: string;
|
|
12
|
-
gstin?: string;
|
|
13
|
-
city?: string;
|
|
14
|
-
category?: string;
|
|
15
|
-
yes?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function prompt(rl: readline.Interface, q: string): Promise<string> {
|
|
19
|
-
return new Promise((resolve) => rl.question(q, resolve));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function partyCreateCommand(opts: CreateOpts): Promise<void> {
|
|
23
|
-
const cfg = requireAuth();
|
|
24
|
-
const client = new HisaaboClient(cfg);
|
|
25
|
-
const isNonInteractive = !process.stdin.isTTY || opts.yes;
|
|
26
|
-
|
|
27
|
-
let type = opts.type as "customer" | "supplier" | undefined;
|
|
28
|
-
let name = opts.name;
|
|
29
|
-
let phone = opts.phone;
|
|
30
|
-
let email = opts.email;
|
|
31
|
-
let gstin = opts.gstin;
|
|
32
|
-
let city = opts.city;
|
|
33
|
-
let category = opts.category;
|
|
34
|
-
|
|
35
|
-
if (!isNonInteractive) {
|
|
36
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
37
|
-
console.log("\n New Party\n " + "─".repeat(30) + "\n");
|
|
38
|
-
|
|
39
|
-
if (!type) {
|
|
40
|
-
const t = await prompt(rl, " Type (customer/supplier) [customer]: ");
|
|
41
|
-
type = (t.trim() || "customer") as "customer" | "supplier";
|
|
42
|
-
}
|
|
43
|
-
if (!name) {
|
|
44
|
-
name = (await prompt(rl, " Name: ")).trim();
|
|
45
|
-
}
|
|
46
|
-
if (!phone) {
|
|
47
|
-
const p = await prompt(rl, " Phone: ");
|
|
48
|
-
phone = p.trim() || undefined;
|
|
49
|
-
}
|
|
50
|
-
if (!email) {
|
|
51
|
-
const e = await prompt(rl, " Email: ");
|
|
52
|
-
email = e.trim() || undefined;
|
|
53
|
-
}
|
|
54
|
-
if (!gstin) {
|
|
55
|
-
const g = await prompt(rl, " GSTIN: ");
|
|
56
|
-
gstin = g.trim() || undefined;
|
|
57
|
-
}
|
|
58
|
-
if (!city) {
|
|
59
|
-
const c = await prompt(rl, " City: ");
|
|
60
|
-
city = c.trim() || undefined;
|
|
61
|
-
}
|
|
62
|
-
rl.close();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (!name) fatalError("--name is required", EXIT.USAGE);
|
|
66
|
-
if (!type) type = "customer";
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
const party = await client.party.create({ type, name, phone, email, gstin, city, category });
|
|
70
|
-
|
|
71
|
-
if (opts.json) {
|
|
72
|
-
outputJSON(party);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
success(`Created: ${party.name} (${party.type})`);
|
|
77
|
-
console.log(` ID: ${party.id}\n`);
|
|
78
|
-
|
|
79
|
-
} catch (e) {
|
|
80
|
-
if (e instanceof HisaaboApiError) {
|
|
81
|
-
const err = e.hisaaboError;
|
|
82
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
83
|
-
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
84
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
85
|
-
}
|
|
86
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
export async function partyDeleteCommand(id: string, opts: { yes?: boolean; json?: boolean }): Promise<void> {
|
|
7
|
-
const cfg = requireAuth();
|
|
8
|
-
const client = new HisaaboClient(cfg);
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
const party = await client.party.get(id);
|
|
12
|
-
|
|
13
|
-
if (!opts.yes && process.stdin.isTTY) {
|
|
14
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
15
|
-
const answer = await new Promise<string>((resolve) => {
|
|
16
|
-
rl.question(` Delete ${party.name}? (y/N): `, resolve);
|
|
17
|
-
});
|
|
18
|
-
rl.close();
|
|
19
|
-
if (answer.trim().toLowerCase() !== "y") {
|
|
20
|
-
console.log(" Cancelled.");
|
|
21
|
-
process.exit(0);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const result = await client.party.delete(id);
|
|
26
|
-
|
|
27
|
-
if (opts.json) {
|
|
28
|
-
outputJSON(result);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
success(`Deleted: ${party.name}`);
|
|
33
|
-
|
|
34
|
-
} catch (e) {
|
|
35
|
-
if (e instanceof HisaaboApiError) {
|
|
36
|
-
const err = e.hisaaboError;
|
|
37
|
-
if (err.code === "not_found") fatalError(`Party not found: ${id}`, EXIT.NOT_FOUND);
|
|
38
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
39
|
-
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
40
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
41
|
-
}
|
|
42
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
export async function partyGetCommand(id: string, opts: { json?: boolean }): Promise<void> {
|
|
7
|
-
const cfg = requireAuth();
|
|
8
|
-
const client = new HisaaboClient(cfg);
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
const party = await client.party.get(id);
|
|
12
|
-
|
|
13
|
-
if (opts.json) {
|
|
14
|
-
outputJSON(party);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
console.log(`\n ${party.name} (${party.type.toUpperCase()})`);
|
|
19
|
-
console.log(" " + "─".repeat(50));
|
|
20
|
-
if (party.phone) console.log(` Phone: ${party.phone}`);
|
|
21
|
-
if (party.email) console.log(` Email: ${party.email}`);
|
|
22
|
-
if (party.gstin) console.log(` GSTIN: ${party.gstin}`);
|
|
23
|
-
if (party.pan) console.log(` PAN: ${party.pan}`);
|
|
24
|
-
if (party.billingAddress) console.log(` Address: ${party.billingAddress}`);
|
|
25
|
-
if (party.city) console.log(` City: ${party.city}`);
|
|
26
|
-
if (party.state) console.log(` State: ${party.state}`);
|
|
27
|
-
if (party.category) console.log(` Category: ${party.category}`);
|
|
28
|
-
if (party.creditPeriodDays) console.log(` Credit Period: ${party.creditPeriodDays} days`);
|
|
29
|
-
if (party.creditLimit && parseFloat(party.creditLimit) > 0) console.log(` Credit Limit: ${formatINR(party.creditLimit)}`);
|
|
30
|
-
console.log(` Balance: ${formatINR(party.balance)}`);
|
|
31
|
-
console.log();
|
|
32
|
-
|
|
33
|
-
} catch (e) {
|
|
34
|
-
if (e instanceof HisaaboApiError) {
|
|
35
|
-
const err = e.hisaaboError;
|
|
36
|
-
if (err.code === "not_found") fatalError(`Party not found: ${id}`, EXIT.NOT_FOUND);
|
|
37
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
38
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
39
|
-
}
|
|
40
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError, type LedgerEntry } 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, formatINR } from "../../format.js";
|
|
8
|
-
|
|
9
|
-
interface LedgerOpts {
|
|
10
|
-
json?: boolean;
|
|
11
|
-
format?: string;
|
|
12
|
-
from?: string;
|
|
13
|
-
to?: string;
|
|
14
|
-
page?: number;
|
|
15
|
-
limit?: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function partyLedgerCommand(partyId: string, opts: LedgerOpts): Promise<void> {
|
|
19
|
-
const cfg = requireAuth();
|
|
20
|
-
const client = new HisaaboClient(cfg);
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const result = await client.party.ledger(partyId, {
|
|
24
|
-
fromDate: opts.from,
|
|
25
|
-
toDate: opts.to,
|
|
26
|
-
page: opts.page ?? 1,
|
|
27
|
-
limit: opts.limit ?? 50,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
if (opts.json) {
|
|
31
|
-
outputJSON(result);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
console.log(`\n Ledger: ${result.partyName} (${result.partyType})`);
|
|
36
|
-
console.log(" " + "═".repeat(60));
|
|
37
|
-
console.log(` Opening Balance: ${formatINR(result.openingBalance)}\n`);
|
|
38
|
-
|
|
39
|
-
const cols: ColumnDef<LedgerEntry>[] = [
|
|
40
|
-
{ key: "date", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
|
|
41
|
-
{ key: "description", header: "Description", width: 25 },
|
|
42
|
-
{ key: "debit", header: "Debit (₹)", align: "right", width: 13, format: (v) => parseFloat(String(v ?? "0")) !== 0 ? formatAmount(String(v)) : "-" },
|
|
43
|
-
{ key: "credit", header: "Credit (₹)", align: "right", width: 13, format: (v) => parseFloat(String(v ?? "0")) !== 0 ? formatAmount(String(v)) : "-" },
|
|
44
|
-
{ key: "balance", header: "Balance (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
45
|
-
{ key: "referenceType", header: "Type", width: 10 },
|
|
46
|
-
];
|
|
47
|
-
|
|
48
|
-
if (opts.format === "tsv") outputTSV(result.entries, cols);
|
|
49
|
-
else if (opts.format === "csv") outputCSV(result.entries, cols);
|
|
50
|
-
else outputTable(result.entries, cols);
|
|
51
|
-
|
|
52
|
-
console.log(`\n Closing Balance: ${formatINR(result.closingBalance)}\n`);
|
|
53
|
-
|
|
54
|
-
} catch (e) {
|
|
55
|
-
if (e instanceof HisaaboApiError) {
|
|
56
|
-
const err = e.hisaaboError;
|
|
57
|
-
if (err.code === "not_found") fatalError(`Party not found: ${partyId}`, 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
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError, type PartySummary } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import {
|
|
4
|
-
fatalError, outputJSON, outputTable, outputTSV, outputCSV, outputIds,
|
|
5
|
-
paginationFooter, EXIT, type ColumnDef,
|
|
6
|
-
} from "../../output.js";
|
|
7
|
-
import { formatAmount } from "../../format.js";
|
|
8
|
-
|
|
9
|
-
interface ListOpts {
|
|
10
|
-
json?: boolean;
|
|
11
|
-
format?: string;
|
|
12
|
-
type?: string;
|
|
13
|
-
search?: string;
|
|
14
|
-
category?: string;
|
|
15
|
-
page?: number;
|
|
16
|
-
limit?: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export async function partyListCommand(opts: ListOpts): Promise<void> {
|
|
20
|
-
const cfg = requireAuth();
|
|
21
|
-
const client = new HisaaboClient(cfg);
|
|
22
|
-
const page = opts.page ?? 1;
|
|
23
|
-
const limit = opts.limit ?? 20;
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const result = await client.party.list({
|
|
27
|
-
type: opts.type as "customer" | "supplier" | undefined ?? null,
|
|
28
|
-
search: opts.search ?? null,
|
|
29
|
-
category: opts.category ?? null,
|
|
30
|
-
page,
|
|
31
|
-
limit,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (opts.json) {
|
|
35
|
-
outputJSON({
|
|
36
|
-
data: result.data,
|
|
37
|
-
pagination: { page: result.page, limit: result.limit, total: result.total },
|
|
38
|
-
});
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const typeLabel = opts.type === "supplier" ? "Suppliers" : opts.type === "customer" ? "Customers" : "Parties";
|
|
43
|
-
console.log(`\n ${typeLabel}` + " ".repeat(40) + `${result.total} total\n`);
|
|
44
|
-
|
|
45
|
-
const cols: ColumnDef<PartySummary>[] = [
|
|
46
|
-
{ key: "name", header: "Name", width: 22 },
|
|
47
|
-
{ key: "phone", header: "Phone", width: 16, format: (v) => String(v ?? "-") },
|
|
48
|
-
{ key: "balance", header: "Balance (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
49
|
-
{ key: "gstin", header: "GSTIN", width: 16, format: (v) => String(v ?? "-") },
|
|
50
|
-
{ key: "category", header: "Category", width: 14, format: (v) => String(v ?? "-") },
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
if (opts.format === "tsv") outputTSV(result.data, cols);
|
|
54
|
-
else if (opts.format === "csv") outputCSV(result.data, cols);
|
|
55
|
-
else if (opts.format === "ids") outputIds(result.data.map((r) => r.id));
|
|
56
|
-
else {
|
|
57
|
-
outputTable(result.data, cols);
|
|
58
|
-
paginationFooter(result.page, result.limit, result.total);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
} catch (e) {
|
|
62
|
-
if (e instanceof HisaaboApiError) {
|
|
63
|
-
const err = e.hisaaboError;
|
|
64
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
65
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
66
|
-
}
|
|
67
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
}
|