@hisaabo/cli 0.7.5 → 0.8.4
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,57 +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 } 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
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,131 +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
|
-
import { formatINR, formatAmount, todayISO } from "../../format.js";
|
|
6
|
-
|
|
7
|
-
interface CreateOpts {
|
|
8
|
-
json?: boolean;
|
|
9
|
-
partyId?: string;
|
|
10
|
-
party?: string;
|
|
11
|
-
amount?: string;
|
|
12
|
-
mode?: string;
|
|
13
|
-
invoiceId?: string;
|
|
14
|
-
reference?: string;
|
|
15
|
-
date?: string;
|
|
16
|
-
notes?: string;
|
|
17
|
-
yes?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function prompt(rl: readline.Interface, q: string): Promise<string> {
|
|
21
|
-
return new Promise((resolve) => rl.question(q, resolve));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export async function paymentCreateCommand(opts: CreateOpts): Promise<void> {
|
|
25
|
-
const cfg = requireAuth();
|
|
26
|
-
const client = new HisaaboClient(cfg);
|
|
27
|
-
const isNonInteractive = !process.stdin.isTTY || opts.yes;
|
|
28
|
-
|
|
29
|
-
let partyId = opts.partyId;
|
|
30
|
-
let amount = opts.amount;
|
|
31
|
-
let mode = opts.mode as "cash" | "bank" | "upi" | "cheque" | "other" | undefined;
|
|
32
|
-
let referenceNumber = opts.reference;
|
|
33
|
-
let paymentDate = opts.date ?? todayISO();
|
|
34
|
-
let notes = opts.notes;
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
if (!isNonInteractive) {
|
|
38
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
39
|
-
console.log("\n Record Payment\n " + "─".repeat(30) + "\n");
|
|
40
|
-
|
|
41
|
-
if (!partyId) {
|
|
42
|
-
const search = await prompt(rl, " Select Party:\n > Search: ");
|
|
43
|
-
const parties = await client.party.list({ search: search.trim(), limit: 5 });
|
|
44
|
-
if (parties.data.length === 0) { rl.close(); fatalError("No parties found.", EXIT.NOT_FOUND); }
|
|
45
|
-
|
|
46
|
-
parties.data.forEach((p, i) => {
|
|
47
|
-
const bal = parseFloat(p.balance);
|
|
48
|
-
const balStr = `Balance: ${formatINR(p.balance)} ${bal >= 0 ? "receivable" : "payable"}`;
|
|
49
|
-
console.log(` ${i + 1} ${p.name.padEnd(20)} ${balStr}`);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const choice = await prompt(rl, "\n Party [1]: ");
|
|
53
|
-
const idx = parseInt(choice.trim() || "1", 10) - 1;
|
|
54
|
-
const selected = parties.data[Math.max(0, Math.min(idx, parties.data.length - 1))];
|
|
55
|
-
if (!selected) { rl.close(); fatalError("Invalid selection.", EXIT.USAGE); }
|
|
56
|
-
partyId = selected.id;
|
|
57
|
-
console.log(`\n Party: ${selected.name}\n`);
|
|
58
|
-
|
|
59
|
-
// Show unpaid invoices
|
|
60
|
-
const { data: unpaid } = await client.invoice.list({ partyId, status: ["sent", "partial", "overdue"], limit: 20 });
|
|
61
|
-
|
|
62
|
-
if (unpaid.length > 0) {
|
|
63
|
-
console.log(" Unpaid Invoices:");
|
|
64
|
-
console.log(" " + "─".repeat(65));
|
|
65
|
-
unpaid.forEach((inv, i) => {
|
|
66
|
-
console.log(` ${i + 1} ${inv.invoiceNumber.padEnd(12)} ${inv.totalAmount.padStart(12)} due ${inv.status}`);
|
|
67
|
-
});
|
|
68
|
-
console.log();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (!amount) {
|
|
72
|
-
const amtStr = await prompt(rl, " Amount: ");
|
|
73
|
-
amount = amtStr.trim();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const modeStr = await prompt(rl, " Mode (cash/bank/upi/cheque/other) [upi]: ");
|
|
77
|
-
mode = (modeStr.trim() || "upi") as typeof mode;
|
|
78
|
-
|
|
79
|
-
const refStr = await prompt(rl, " Reference Number: ");
|
|
80
|
-
if (refStr.trim()) referenceNumber = refStr.trim();
|
|
81
|
-
|
|
82
|
-
const dateStr = await prompt(rl, ` Payment Date [${todayISO()}]: `);
|
|
83
|
-
if (dateStr.trim()) paymentDate = dateStr.trim();
|
|
84
|
-
|
|
85
|
-
const notesStr = await prompt(rl, " Notes: ");
|
|
86
|
-
if (notesStr.trim()) notes = notesStr.trim();
|
|
87
|
-
|
|
88
|
-
console.log(`\n Total Payment: ${formatAmount(amount ?? "0")}`);
|
|
89
|
-
const confirm = await prompt(rl, "\n Record this payment? (y/n) [y]: ");
|
|
90
|
-
rl.close();
|
|
91
|
-
|
|
92
|
-
if (confirm.trim().toLowerCase() === "n") {
|
|
93
|
-
console.log(" Cancelled.");
|
|
94
|
-
process.exit(0);
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
-
rl.close();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (!partyId) fatalError("--party-id is required", EXIT.USAGE);
|
|
102
|
-
if (!amount) fatalError("--amount is required", EXIT.USAGE);
|
|
103
|
-
if (!mode) mode = "cash";
|
|
104
|
-
|
|
105
|
-
const payment = await client.payment.create({
|
|
106
|
-
partyId,
|
|
107
|
-
amount,
|
|
108
|
-
mode,
|
|
109
|
-
referenceNumber,
|
|
110
|
-
paymentDate,
|
|
111
|
-
notes,
|
|
112
|
-
invoiceId: opts.invoiceId,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
if (opts.json) {
|
|
116
|
-
outputJSON(payment);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
success(`Recorded: ${payment.paymentNumber} for ${formatINR(payment.amount)}`);
|
|
121
|
-
|
|
122
|
-
} catch (e) {
|
|
123
|
-
if (e instanceof HisaaboApiError) {
|
|
124
|
-
const err = e.hisaaboError;
|
|
125
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
126
|
-
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
127
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
128
|
-
}
|
|
129
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,46 +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
|
-
import { formatINR } from "../../format.js";
|
|
6
|
-
|
|
7
|
-
export async function paymentDeleteCommand(id: string, opts: { yes?: boolean; json?: boolean }): Promise<void> {
|
|
8
|
-
const cfg = requireAuth();
|
|
9
|
-
const client = new HisaaboClient(cfg);
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
const payment = await client.payment.getById(id);
|
|
13
|
-
if (!payment) fatalError(`Payment not found: ${id}`, EXIT.NOT_FOUND);
|
|
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(` Delete ${payment!.paymentNumber} (${formatINR(payment!.amount)})? (y/N): `, resolve);
|
|
19
|
-
});
|
|
20
|
-
rl.close();
|
|
21
|
-
if (answer.trim().toLowerCase() !== "y") {
|
|
22
|
-
console.log(" Cancelled.");
|
|
23
|
-
process.exit(0);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const result = await client.payment.delete(id);
|
|
28
|
-
|
|
29
|
-
if (opts.json) {
|
|
30
|
-
outputJSON(result);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
success(`Deleted: ${payment!.paymentNumber}`);
|
|
35
|
-
|
|
36
|
-
} catch (e) {
|
|
37
|
-
if (e instanceof HisaaboApiError) {
|
|
38
|
-
const err = e.hisaaboError;
|
|
39
|
-
if (err.code === "not_found") fatalError(`Payment not found: ${id}`, EXIT.NOT_FOUND);
|
|
40
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
41
|
-
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
42
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
43
|
-
}
|
|
44
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,59 +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, 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
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError, type PaymentSummary } 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, formatDate } from "../../format.js";
|
|
8
|
-
|
|
9
|
-
interface ListOpts {
|
|
10
|
-
json?: boolean;
|
|
11
|
-
format?: string;
|
|
12
|
-
partyId?: string;
|
|
13
|
-
from?: string;
|
|
14
|
-
to?: string;
|
|
15
|
-
page?: number;
|
|
16
|
-
limit?: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export async function paymentListCommand(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.payment.list({
|
|
27
|
-
partyId: opts.partyId ?? null,
|
|
28
|
-
fromDate: opts.from ?? null,
|
|
29
|
-
toDate: opts.to ?? null,
|
|
30
|
-
page,
|
|
31
|
-
limit,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (opts.json) {
|
|
35
|
-
outputJSON({ data: result.data, pagination: { page: result.page, limit: result.limit, total: result.total } });
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
console.log(`\n Payments ${result.total} total\n`);
|
|
40
|
-
|
|
41
|
-
const cols: ColumnDef<PaymentSummary>[] = [
|
|
42
|
-
{ key: "paymentNumber", header: "#", width: 10 },
|
|
43
|
-
{ key: "partyName", header: "Party", width: 20 },
|
|
44
|
-
{ key: "paymentDate", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
|
|
45
|
-
{ key: "amount", header: "Amount (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
46
|
-
{ key: "mode", header: "Mode", width: 8 },
|
|
47
|
-
{ key: "referenceNumber", header: "Ref#", width: 14, format: (v) => String(v ?? "-") },
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
if (opts.format === "tsv") outputTSV(result.data, cols);
|
|
51
|
-
else if (opts.format === "csv") outputCSV(result.data, cols);
|
|
52
|
-
else if (opts.format === "ids") outputIds(result.data.map((r) => r.id));
|
|
53
|
-
else {
|
|
54
|
-
outputTable(result.data, cols);
|
|
55
|
-
paginationFooter(result.page, result.limit, result.total);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
} catch (e) {
|
|
59
|
-
if (e instanceof HisaaboApiError) {
|
|
60
|
-
const err = e.hisaaboError;
|
|
61
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
62
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
63
|
-
}
|
|
64
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError, type PaymentUpdateInput } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import { fatalError, outputJSON, EXIT, success } from "../../output.js";
|
|
4
|
-
import { formatINR } from "../../format.js";
|
|
5
|
-
|
|
6
|
-
interface UpdateOpts {
|
|
7
|
-
json?: boolean;
|
|
8
|
-
amount?: string;
|
|
9
|
-
mode?: string;
|
|
10
|
-
date?: string;
|
|
11
|
-
reference?: string;
|
|
12
|
-
notes?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export async function paymentUpdateCommand(id: string, opts: UpdateOpts): Promise<void> {
|
|
16
|
-
const cfg = requireAuth();
|
|
17
|
-
const client = new HisaaboClient(cfg);
|
|
18
|
-
|
|
19
|
-
// Build update payload — only send fields explicitly provided
|
|
20
|
-
const input: PaymentUpdateInput = { id };
|
|
21
|
-
|
|
22
|
-
if (opts.amount !== undefined) input.amount = opts.amount;
|
|
23
|
-
if (opts.mode !== undefined) input.mode = opts.mode as PaymentUpdateInput["mode"];
|
|
24
|
-
if (opts.date !== undefined) input.paymentDate = opts.date;
|
|
25
|
-
if (opts.reference !== undefined) input.referenceNumber = opts.reference || null;
|
|
26
|
-
if (opts.notes !== undefined) input.notes = opts.notes || null;
|
|
27
|
-
|
|
28
|
-
const hasUpdates = Object.keys(input).length > 1;
|
|
29
|
-
if (!hasUpdates) {
|
|
30
|
-
fatalError("No fields to update. Provide at least one option: --amount, --mode, --date, --reference, --notes", EXIT.USAGE);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
const payment = await client.payment.update(input);
|
|
35
|
-
|
|
36
|
-
if (opts.json) {
|
|
37
|
-
outputJSON(payment);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
success(`Updated: ${payment.paymentNumber} — ${formatINR(payment.amount)}`);
|
|
42
|
-
|
|
43
|
-
} catch (e) {
|
|
44
|
-
if (e instanceof HisaaboApiError) {
|
|
45
|
-
const err = e.hisaaboError;
|
|
46
|
-
if (err.code === "not_found") fatalError(`Payment not found: ${id}`, EXIT.NOT_FOUND);
|
|
47
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
48
|
-
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
49
|
-
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
50
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
51
|
-
}
|
|
52
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
53
|
-
}
|
|
54
|
-
}
|