@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,126 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError, type InvoiceSummary } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import {
|
|
4
|
-
fatalError, outputJSON, outputTable, outputTSV, outputCSV, outputIds,
|
|
5
|
-
paginationFooter, EXIT, getWidthTier, type ColumnDef,
|
|
6
|
-
} from "../../output.js";
|
|
7
|
-
import { formatAmount, formatDate, formatStatus, currentFY, fyStart, todayISO, monthStart, monthEnd } from "../../format.js";
|
|
8
|
-
|
|
9
|
-
interface ListOpts {
|
|
10
|
-
json?: boolean;
|
|
11
|
-
format?: string;
|
|
12
|
-
type?: string;
|
|
13
|
-
status?: string;
|
|
14
|
-
party?: string;
|
|
15
|
-
partyId?: string;
|
|
16
|
-
from?: string;
|
|
17
|
-
to?: string;
|
|
18
|
-
thisMonth?: boolean;
|
|
19
|
-
thisQuarter?: boolean;
|
|
20
|
-
thisFy?: boolean;
|
|
21
|
-
page?: number;
|
|
22
|
-
limit?: number;
|
|
23
|
-
search?: string;
|
|
24
|
-
sortBy?: string;
|
|
25
|
-
sortDir?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function invoiceListCommand(opts: ListOpts): Promise<void> {
|
|
29
|
-
const cfg = requireAuth();
|
|
30
|
-
const client = new HisaaboClient(cfg);
|
|
31
|
-
|
|
32
|
-
// Resolve date range
|
|
33
|
-
let from = opts.from;
|
|
34
|
-
let to = opts.to;
|
|
35
|
-
if (opts.thisFy) { from = fyStart(); to = todayISO(); }
|
|
36
|
-
else if (opts.thisMonth) { from = monthStart(); to = monthEnd(); }
|
|
37
|
-
else if (opts.thisQuarter) {
|
|
38
|
-
const now = new Date();
|
|
39
|
-
const month = now.getMonth() + 1;
|
|
40
|
-
const year = now.getFullYear();
|
|
41
|
-
if (month >= 4 && month <= 6) { from = `${year}-04-01`; to = `${year}-06-30`; }
|
|
42
|
-
else if (month >= 7 && month <= 9) { from = `${year}-07-01`; to = `${year}-09-30`; }
|
|
43
|
-
else if (month >= 10 && month <= 12) { from = `${year}-10-01`; to = `${year}-12-31`; }
|
|
44
|
-
else { from = `${year}-01-01`; to = `${year}-03-31`; }
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const page = opts.page ?? 1;
|
|
48
|
-
const limit = opts.limit ?? 20;
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
const result = await client.invoice.list({
|
|
52
|
-
type: opts.type as "sale" | "purchase" | undefined ?? null,
|
|
53
|
-
status: opts.status as InvoiceSummary["status"] | undefined ?? null,
|
|
54
|
-
partyId: opts.partyId ?? null,
|
|
55
|
-
fromDate: from ?? null,
|
|
56
|
-
toDate: to ?? null,
|
|
57
|
-
search: opts.search ?? null,
|
|
58
|
-
sortBy: opts.sortBy as "date" | "amount" | "number" | undefined ?? null,
|
|
59
|
-
sortDir: opts.sortDir as "asc" | "desc" | undefined ?? null,
|
|
60
|
-
page,
|
|
61
|
-
limit,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
if (opts.json) {
|
|
65
|
-
outputJSON({
|
|
66
|
-
data: result.data,
|
|
67
|
-
pagination: { page: result.page, limit: result.limit, total: result.total, hasMore: result.page * result.limit < result.total },
|
|
68
|
-
});
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const tier = getWidthTier();
|
|
73
|
-
|
|
74
|
-
// Title
|
|
75
|
-
const typeLabel = opts.type === "purchase" ? "Purchase Bills" : "Sale Invoices";
|
|
76
|
-
console.log(`\n ${typeLabel}` + " ".repeat(40) + `FY ${currentFY()}`);
|
|
77
|
-
console.log(` ${"═".repeat(68)}\n`);
|
|
78
|
-
|
|
79
|
-
const narrowCols: ColumnDef<InvoiceSummary>[] = [
|
|
80
|
-
{ key: "invoiceNumber", header: "#", width: 10 },
|
|
81
|
-
{ key: "partyName", header: "Party", width: 18 },
|
|
82
|
-
{ key: "totalAmount", header: "Amount (₹)", align: "right", width: 12, format: (v) => formatAmount(String(v ?? "0")) },
|
|
83
|
-
{ key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) },
|
|
84
|
-
];
|
|
85
|
-
|
|
86
|
-
const standardCols: ColumnDef<InvoiceSummary>[] = [
|
|
87
|
-
{ key: "invoiceNumber", header: "#", width: 10 },
|
|
88
|
-
{ key: "partyName", header: "Party", width: 18 },
|
|
89
|
-
{ key: "invoiceDate", header: "Date", width: 12, format: (v) => formatDate(String(v ?? "")) },
|
|
90
|
-
{ key: "totalAmount", header: "Amount (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
91
|
-
{ key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) },
|
|
92
|
-
];
|
|
93
|
-
|
|
94
|
-
const wideCols: ColumnDef<InvoiceSummary>[] = [
|
|
95
|
-
{ key: "invoiceNumber", header: "#", width: 10 },
|
|
96
|
-
{ key: "partyName", header: "Party", width: 18 },
|
|
97
|
-
{ key: "invoiceDate", header: "Date", width: 12, format: (v) => formatDate(String(v ?? "")) },
|
|
98
|
-
{ key: "dueDate", header: "Due", width: 12, format: (v) => formatDate(v ? String(v) : null) },
|
|
99
|
-
{ key: "totalAmount", header: "Amount (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
100
|
-
{ key: "amountPaid", header: "Paid (₹)", align: "right", width: 12, format: (v) => formatAmount(String(v ?? "0")) },
|
|
101
|
-
{ key: "balanceDue", header: "Balance (₹)", align: "right", width: 12, format: (v) => formatAmount(String(v ?? "0")) },
|
|
102
|
-
{ key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) },
|
|
103
|
-
];
|
|
104
|
-
|
|
105
|
-
const cols = tier === "narrow" ? narrowCols : tier === "wide" ? wideCols : standardCols;
|
|
106
|
-
|
|
107
|
-
if (opts.format === "tsv") {
|
|
108
|
-
outputTSV(result.data, cols);
|
|
109
|
-
} else if (opts.format === "csv") {
|
|
110
|
-
outputCSV(result.data, cols);
|
|
111
|
-
} else if (opts.format === "ids") {
|
|
112
|
-
outputIds(result.data.map((r) => r.id));
|
|
113
|
-
} else {
|
|
114
|
-
outputTable(result.data, cols);
|
|
115
|
-
paginationFooter(result.page, result.limit, result.total);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
} catch (e) {
|
|
119
|
-
if (e instanceof HisaaboApiError) {
|
|
120
|
-
const err = e.hisaaboError;
|
|
121
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
122
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
123
|
-
}
|
|
124
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
4
|
-
import { requireAuth } from "../../config.js";
|
|
5
|
-
import { fatalError, EXIT, success } from "../../output.js";
|
|
6
|
-
|
|
7
|
-
interface PdfOpts {
|
|
8
|
-
output?: string;
|
|
9
|
-
open?: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export async function invoicePdfCommand(id: string, opts: PdfOpts): Promise<void> {
|
|
13
|
-
const cfg = requireAuth();
|
|
14
|
-
const client = new HisaaboClient(cfg);
|
|
15
|
-
|
|
16
|
-
// First fetch the invoice to get the invoice number
|
|
17
|
-
let invoiceNumber = id;
|
|
18
|
-
try {
|
|
19
|
-
const inv = await client.invoice.get(id);
|
|
20
|
-
invoiceNumber = inv.invoiceNumber;
|
|
21
|
-
} catch {
|
|
22
|
-
// Use id as-is if fetch fails
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Build PDF URL
|
|
26
|
-
const pdfUrl = `${cfg.apiUrl}/api/invoice/${id}/pdf`;
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const res = await fetch(pdfUrl, {
|
|
30
|
-
headers: {
|
|
31
|
-
"Authorization": `Bearer ${cfg.token}`,
|
|
32
|
-
"x-business-id": cfg.businessId,
|
|
33
|
-
"x-tenant-id": cfg.tenantId,
|
|
34
|
-
"x-client-type": "cli",
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
if (!res.ok) {
|
|
39
|
-
fatalError(`Failed to download PDF: HTTP ${res.status}`, EXIT.GENERAL);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const buffer = await res.arrayBuffer();
|
|
43
|
-
const bytes = Buffer.from(buffer);
|
|
44
|
-
|
|
45
|
-
// Determine output path
|
|
46
|
-
let outputPath: string;
|
|
47
|
-
if (opts.output) {
|
|
48
|
-
// If it's a directory, put the file inside it
|
|
49
|
-
if (fs.existsSync(opts.output) && fs.statSync(opts.output).isDirectory()) {
|
|
50
|
-
outputPath = path.join(opts.output, `${invoiceNumber}.pdf`);
|
|
51
|
-
} else {
|
|
52
|
-
outputPath = opts.output;
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
outputPath = `${invoiceNumber}.pdf`;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
fs.writeFileSync(outputPath, bytes);
|
|
59
|
-
success(`Saved: ${outputPath} (${Math.round(bytes.length / 1024)} KB)`);
|
|
60
|
-
|
|
61
|
-
if (opts.open) {
|
|
62
|
-
const openPkg = await import("open");
|
|
63
|
-
await openPkg.default(outputPath);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
} catch (e) {
|
|
67
|
-
if (e instanceof HisaaboApiError) {
|
|
68
|
-
const err = e.hisaaboError;
|
|
69
|
-
if (err.code === "not_found") fatalError(`Invoice not found: ${id}`, EXIT.NOT_FOUND);
|
|
70
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
71
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
72
|
-
}
|
|
73
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError, type InvoiceStatus } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import { fatalError, outputJSON, EXIT } from "../../output.js";
|
|
4
|
-
import { formatStatus } from "../../format.js";
|
|
5
|
-
|
|
6
|
-
const VALID_STATUSES: InvoiceStatus[] = ["draft", "unfulfilled", "sent", "paid", "partial", "overdue", "cancelled"];
|
|
7
|
-
|
|
8
|
-
export async function invoiceStatusCommand(id: string, status: string, opts: { json?: boolean }): Promise<void> {
|
|
9
|
-
const cfg = requireAuth();
|
|
10
|
-
const client = new HisaaboClient(cfg);
|
|
11
|
-
|
|
12
|
-
if (!VALID_STATUSES.includes(status as InvoiceStatus)) {
|
|
13
|
-
fatalError(`Invalid status: ${status}. Valid: ${VALID_STATUSES.join(", ")}`, EXIT.USAGE);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
// Get current invoice to show before state
|
|
18
|
-
const before = await client.invoice.get(id);
|
|
19
|
-
const updated = await client.invoice.updateStatus(id, status as InvoiceStatus);
|
|
20
|
-
|
|
21
|
-
if (opts.json) {
|
|
22
|
-
outputJSON(updated);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const fromBadge = formatStatus(before.status);
|
|
27
|
-
const toBadge = formatStatus(status);
|
|
28
|
-
console.log(` ${id} status updated: ${fromBadge} -> ${toBadge}`);
|
|
29
|
-
|
|
30
|
-
} catch (e) {
|
|
31
|
-
if (e instanceof HisaaboApiError) {
|
|
32
|
-
const err = e.hisaaboError;
|
|
33
|
-
if (err.code === "not_found") fatalError(`Invoice not found: ${id}`, EXIT.NOT_FOUND);
|
|
34
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
35
|
-
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
36
|
-
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
37
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
38
|
-
}
|
|
39
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,163 +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 { formatAmount } from "../../format.js";
|
|
5
|
-
|
|
6
|
-
interface ItcOpts {
|
|
7
|
-
json?: boolean;
|
|
8
|
-
from?: string;
|
|
9
|
-
to?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function handleError(e: unknown): never {
|
|
13
|
-
if (e instanceof HisaaboApiError) {
|
|
14
|
-
const err = e.hisaaboError;
|
|
15
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
16
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
17
|
-
}
|
|
18
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function itcDashboardCommand(opts: ItcOpts): Promise<void> {
|
|
22
|
-
const cfg = requireAuth();
|
|
23
|
-
const client = new HisaaboClient(cfg);
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const result = await client.itc.dashboard({ fromDate: opts.from, toDate: opts.to });
|
|
27
|
-
|
|
28
|
-
if (opts.json) {
|
|
29
|
-
outputJSON(result);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const r = result as Record<string, unknown>;
|
|
34
|
-
console.log("\n ITC Dashboard\n");
|
|
35
|
-
console.log(` ${"═".repeat(50)}\n`);
|
|
36
|
-
|
|
37
|
-
const eligible = String(r["totalEligible"] ?? r["eligible"] ?? "0");
|
|
38
|
-
const blocked = String(r["totalBlocked"] ?? r["blocked"] ?? "0");
|
|
39
|
-
const utilized = String(r["totalUtilized"] ?? r["utilized"] ?? "0");
|
|
40
|
-
const available = String(r["availableBalance"] ?? r["available"] ?? "0");
|
|
41
|
-
|
|
42
|
-
console.log(` Eligible ITC: ${formatAmount(eligible).padStart(14)}`);
|
|
43
|
-
console.log(` Blocked ITC: ${formatAmount(blocked).padStart(14)}`);
|
|
44
|
-
console.log(` Utilized ITC: ${formatAmount(utilized).padStart(14)}`);
|
|
45
|
-
console.log(` Available Balance:${formatAmount(available).padStart(14)}`);
|
|
46
|
-
console.log();
|
|
47
|
-
|
|
48
|
-
} catch (e) {
|
|
49
|
-
handleError(e);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function itcLedgerCommand(opts: ItcOpts): Promise<void> {
|
|
54
|
-
const cfg = requireAuth();
|
|
55
|
-
const client = new HisaaboClient(cfg);
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
const result = await client.itc.ledger({ fromDate: opts.from, toDate: opts.to });
|
|
59
|
-
|
|
60
|
-
if (opts.json) {
|
|
61
|
-
outputJSON(result);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const entries = Array.isArray(result) ? result
|
|
66
|
-
: Array.isArray(result?.data) ? result.data
|
|
67
|
-
: Array.isArray(result?.entries) ? result.entries
|
|
68
|
-
: [];
|
|
69
|
-
|
|
70
|
-
console.log("\n ITC Ledger\n");
|
|
71
|
-
console.log(` ${"═".repeat(70)}\n`);
|
|
72
|
-
|
|
73
|
-
for (const entry of entries as Array<Record<string, unknown>>) {
|
|
74
|
-
const date = String(entry["date"] ?? "-").slice(0, 10);
|
|
75
|
-
const supplier = String(entry["supplierName"] ?? entry["supplier"] ?? "-").padEnd(22);
|
|
76
|
-
const gstin = String(entry["gstin"] ?? "-").padEnd(16);
|
|
77
|
-
const igst = formatAmount(String(entry["igst"] ?? "0")).padStart(12);
|
|
78
|
-
const cgst = formatAmount(String(entry["cgst"] ?? "0")).padStart(12);
|
|
79
|
-
const sgst = formatAmount(String(entry["sgst"] ?? "0")).padStart(12);
|
|
80
|
-
console.log(` ${date.padEnd(12)} ${supplier} ${gstin} IGST:${igst} CGST:${cgst} SGST:${sgst}`);
|
|
81
|
-
}
|
|
82
|
-
console.log();
|
|
83
|
-
|
|
84
|
-
} catch (e) {
|
|
85
|
-
handleError(e);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export async function itcAgingCommand(opts: { json?: boolean }): Promise<void> {
|
|
90
|
-
const cfg = requireAuth();
|
|
91
|
-
const client = new HisaaboClient(cfg);
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
const result = await client.itc.agingAlerts();
|
|
95
|
-
|
|
96
|
-
if (opts.json) {
|
|
97
|
-
outputJSON(result);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const alerts = Array.isArray(result) ? result
|
|
102
|
-
: Array.isArray(result?.data) ? result.data
|
|
103
|
-
: Array.isArray(result?.alerts) ? result.alerts
|
|
104
|
-
: [];
|
|
105
|
-
|
|
106
|
-
console.log("\n ITC Aging Alerts\n");
|
|
107
|
-
console.log(` ${"═".repeat(60)}\n`);
|
|
108
|
-
|
|
109
|
-
if (alerts.length === 0) {
|
|
110
|
-
console.log(" No aging alerts.\n");
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
for (const alert of alerts as Array<Record<string, unknown>>) {
|
|
115
|
-
const supplier = String(alert["supplierName"] ?? alert["supplier"] ?? "-").padEnd(25);
|
|
116
|
-
const amount = formatAmount(String(alert["amount"] ?? "0")).padStart(14);
|
|
117
|
-
const days = String(alert["daysOld"] ?? alert["age"] ?? "-").padStart(6);
|
|
118
|
-
console.log(` ${supplier} ${amount} ${days} days`);
|
|
119
|
-
}
|
|
120
|
-
console.log();
|
|
121
|
-
|
|
122
|
-
} catch (e) {
|
|
123
|
-
handleError(e);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export async function itcBlockCommand(invoiceId: string, opts: { json?: boolean }): Promise<void> {
|
|
128
|
-
const cfg = requireAuth();
|
|
129
|
-
const client = new HisaaboClient(cfg);
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
const result = await client.itc.markBlocked({ invoiceId });
|
|
133
|
-
|
|
134
|
-
if (opts.json) {
|
|
135
|
-
outputJSON(result);
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
console.log(` ITC for invoice ${invoiceId} marked as blocked.\n`);
|
|
140
|
-
|
|
141
|
-
} catch (e) {
|
|
142
|
-
handleError(e);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export async function itcUnblockCommand(invoiceId: string, opts: { json?: boolean }): Promise<void> {
|
|
147
|
-
const cfg = requireAuth();
|
|
148
|
-
const client = new HisaaboClient(cfg);
|
|
149
|
-
|
|
150
|
-
try {
|
|
151
|
-
const result = await client.itc.markEligible({ invoiceId });
|
|
152
|
-
|
|
153
|
-
if (opts.json) {
|
|
154
|
-
outputJSON(result);
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
console.log(` ITC for invoice ${invoiceId} marked as eligible.\n`);
|
|
159
|
-
|
|
160
|
-
} catch (e) {
|
|
161
|
-
handleError(e);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
@@ -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
|
-
|
|
5
|
-
interface CategoriesOpts {
|
|
6
|
-
json?: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function itemCategoriesCommand(opts: CategoriesOpts): Promise<void> {
|
|
10
|
-
const cfg = requireAuth();
|
|
11
|
-
const client = new HisaaboClient(cfg);
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
const categories = await client.item.categories();
|
|
15
|
-
|
|
16
|
-
if (opts.json) {
|
|
17
|
-
outputJSON(categories);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (!Array.isArray(categories) || categories.length === 0) {
|
|
22
|
-
console.log(" (no categories)\n");
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
console.log();
|
|
27
|
-
for (const cat of categories) {
|
|
28
|
-
process.stdout.write(` ${cat}\n`);
|
|
29
|
-
}
|
|
30
|
-
console.log();
|
|
31
|
-
|
|
32
|
-
} catch (e) {
|
|
33
|
-
if (e instanceof HisaaboApiError) {
|
|
34
|
-
const err = e.hisaaboError;
|
|
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
|
-
}
|
|
@@ -1,98 +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
|
-
name?: string;
|
|
9
|
-
unit?: string;
|
|
10
|
-
salePrice?: string;
|
|
11
|
-
purchasePrice?: string;
|
|
12
|
-
taxPercent?: string;
|
|
13
|
-
stock?: string;
|
|
14
|
-
hsn?: string;
|
|
15
|
-
category?: string;
|
|
16
|
-
type?: 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 itemCreateCommand(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 name = opts.name;
|
|
30
|
-
let unit = opts.unit ?? "pcs";
|
|
31
|
-
let salePrice = opts.salePrice;
|
|
32
|
-
let purchasePrice = opts.purchasePrice;
|
|
33
|
-
let taxPercent = opts.taxPercent ?? "0";
|
|
34
|
-
let stockQuantity = opts.stock;
|
|
35
|
-
let hsn = opts.hsn;
|
|
36
|
-
let category = opts.category;
|
|
37
|
-
let itemType = (opts.type ?? "product") as "product" | "service";
|
|
38
|
-
|
|
39
|
-
if (!isNonInteractive) {
|
|
40
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
41
|
-
console.log("\n New Item\n " + "─".repeat(30) + "\n");
|
|
42
|
-
|
|
43
|
-
if (!name) name = (await prompt(rl, " Name: ")).trim();
|
|
44
|
-
const typeStr = await prompt(rl, " Type (product/service) [product]: ");
|
|
45
|
-
itemType = (typeStr.trim() || "product") as "product" | "service";
|
|
46
|
-
|
|
47
|
-
const unitStr = await prompt(rl, " Unit [pcs]: ");
|
|
48
|
-
unit = unitStr.trim() || "pcs";
|
|
49
|
-
|
|
50
|
-
const spStr = await prompt(rl, " Sale Price: ");
|
|
51
|
-
if (spStr.trim()) salePrice = spStr.trim();
|
|
52
|
-
|
|
53
|
-
const ppStr = await prompt(rl, " Purchase Price: ");
|
|
54
|
-
if (ppStr.trim()) purchasePrice = ppStr.trim();
|
|
55
|
-
|
|
56
|
-
const taxStr = await prompt(rl, " Tax % [0]: ");
|
|
57
|
-
taxPercent = taxStr.trim() || "0";
|
|
58
|
-
|
|
59
|
-
if (itemType === "product") {
|
|
60
|
-
const stockStr = await prompt(rl, " Opening Stock [0]: ");
|
|
61
|
-
stockQuantity = stockStr.trim() || "0";
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const hsnStr = await prompt(rl, " HSN Code: ");
|
|
65
|
-
if (hsnStr.trim()) hsn = hsnStr.trim();
|
|
66
|
-
|
|
67
|
-
const catStr = await prompt(rl, " Category: ");
|
|
68
|
-
if (catStr.trim()) category = catStr.trim();
|
|
69
|
-
|
|
70
|
-
rl.close();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!name) fatalError("--name is required", EXIT.USAGE);
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const item = await client.item.create({
|
|
77
|
-
name, unit, salePrice, purchasePrice, taxPercent,
|
|
78
|
-
stockQuantity, hsn, category, itemType,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
if (opts.json) {
|
|
82
|
-
outputJSON(item);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
success(`Created: ${item.name} (${item.itemType})`);
|
|
87
|
-
console.log(` ID: ${item.id}\n`);
|
|
88
|
-
|
|
89
|
-
} catch (e) {
|
|
90
|
-
if (e instanceof HisaaboApiError) {
|
|
91
|
-
const err = e.hisaaboError;
|
|
92
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
93
|
-
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
94
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
95
|
-
}
|
|
96
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -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 itemDeleteCommand(id: string, opts: { yes?: boolean; json?: boolean }): Promise<void> {
|
|
7
|
-
const cfg = requireAuth();
|
|
8
|
-
const client = new HisaaboClient(cfg);
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
const item = await client.item.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 ${item.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.item.delete(id);
|
|
26
|
-
|
|
27
|
-
if (opts.json) {
|
|
28
|
-
outputJSON(result);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
success(`Deleted: ${item.name}`);
|
|
33
|
-
|
|
34
|
-
} catch (e) {
|
|
35
|
-
if (e instanceof HisaaboApiError) {
|
|
36
|
-
const err = e.hisaaboError;
|
|
37
|
-
if (err.code === "not_found") fatalError(`Item 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,81 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError, type ItemSummary } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import {
|
|
4
|
-
fatalError, outputJSON, outputTable, outputTSV, outputCSV, outputIds,
|
|
5
|
-
paginationFooter, EXIT, hasColor, type ColumnDef,
|
|
6
|
-
} from "../../output.js";
|
|
7
|
-
import { formatAmount } from "../../format.js";
|
|
8
|
-
import chalk from "chalk";
|
|
9
|
-
|
|
10
|
-
interface ListOpts {
|
|
11
|
-
json?: boolean;
|
|
12
|
-
format?: string;
|
|
13
|
-
search?: string;
|
|
14
|
-
category?: string;
|
|
15
|
-
type?: string;
|
|
16
|
-
lowStock?: boolean;
|
|
17
|
-
page?: number;
|
|
18
|
-
limit?: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function itemListCommand(opts: ListOpts): Promise<void> {
|
|
22
|
-
const cfg = requireAuth();
|
|
23
|
-
const client = new HisaaboClient(cfg);
|
|
24
|
-
const page = opts.page ?? 1;
|
|
25
|
-
const limit = opts.limit ?? 20;
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
const result = await client.item.list({
|
|
29
|
-
search: opts.search ?? null,
|
|
30
|
-
category: opts.category ?? null,
|
|
31
|
-
itemType: opts.type as "product" | "service" | undefined ?? null,
|
|
32
|
-
lowStock: opts.lowStock ?? null,
|
|
33
|
-
page,
|
|
34
|
-
limit,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (opts.json) {
|
|
38
|
-
outputJSON({ data: result.data, pagination: { page: result.page, limit: result.limit, total: result.total } });
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
console.log(`\n Items` + " ".repeat(45) + `${result.total} total\n`);
|
|
43
|
-
|
|
44
|
-
const cols: ColumnDef<ItemSummary>[] = [
|
|
45
|
-
{ key: "name", header: "Name", width: 22 },
|
|
46
|
-
{ key: "unit", header: "Unit", width: 6 },
|
|
47
|
-
{ key: "salePrice", header: "Sale (₹)", align: "right", width: 12,
|
|
48
|
-
format: (v) => v ? formatAmount(String(v)) : "-" },
|
|
49
|
-
{ key: "stockQuantity", header: "Stock", width: 8,
|
|
50
|
-
format: (v, row) => {
|
|
51
|
-
const qty = String(v ?? "0");
|
|
52
|
-
const low = row.lowStockAlert;
|
|
53
|
-
const isLow = low && parseFloat(qty) <= parseFloat(low);
|
|
54
|
-
const str = row.itemType === "service" ? "-" : (isLow ? `${qty} !` : qty);
|
|
55
|
-
return isLow && hasColor() ? chalk.red(str) : str;
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
{ key: "taxPercent", header: "Tax%", width: 6, format: (v) => `${v ?? 0}%` },
|
|
59
|
-
{ key: "category", header: "Category", width: 14, format: (v) => String(v ?? "-") },
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
if (opts.format === "tsv") outputTSV(result.data, cols);
|
|
63
|
-
else if (opts.format === "csv") outputCSV(result.data, cols);
|
|
64
|
-
else if (opts.format === "ids") outputIds(result.data.map((r) => r.id));
|
|
65
|
-
else {
|
|
66
|
-
outputTable(result.data, cols);
|
|
67
|
-
paginationFooter(result.page, result.limit, result.total);
|
|
68
|
-
if (result.data.some((i) => i.lowStockAlert && parseFloat(i.stockQuantity) <= parseFloat(i.lowStockAlert))) {
|
|
69
|
-
console.log("\n ! = below low stock alert threshold\n");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
} catch (e) {
|
|
74
|
-
if (e instanceof HisaaboApiError) {
|
|
75
|
-
const err = e.hisaaboError;
|
|
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
|
-
}
|