@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,590 +0,0 @@
|
|
|
1
|
-
import * as readline from "readline";
|
|
2
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
3
|
-
import { requireAuth } from "../../config.js";
|
|
4
|
-
import {
|
|
5
|
-
fatalError, outputJSON, outputTable, outputTSV, outputCSV, outputIds,
|
|
6
|
-
paginationFooter, EXIT, getWidthTier, hasColor, termWidth, success,
|
|
7
|
-
type ColumnDef,
|
|
8
|
-
} from "../../output.js";
|
|
9
|
-
import {
|
|
10
|
-
formatAmount, formatDate, formatStatus, formatINR,
|
|
11
|
-
fyStart, todayISO, monthStart, monthEnd, currentFY,
|
|
12
|
-
} from "../../format.js";
|
|
13
|
-
import chalk from "chalk";
|
|
14
|
-
|
|
15
|
-
// ── Types ──────────────────────────────────────────────────────────────────
|
|
16
|
-
|
|
17
|
-
export interface DocTypeConfig {
|
|
18
|
-
/** kebab-case CLI command name, e.g. "credit-note" */
|
|
19
|
-
cmd: string;
|
|
20
|
-
/** Human-readable label, e.g. "Credit Note" */
|
|
21
|
-
label: string;
|
|
22
|
-
/** camelCase key on HisaaboClient, e.g. "creditNote" */
|
|
23
|
-
nsKey: keyof HisaaboClient;
|
|
24
|
-
/** Valid status values for this document type */
|
|
25
|
-
statuses: string[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface ListOpts {
|
|
29
|
-
json?: boolean;
|
|
30
|
-
format?: string;
|
|
31
|
-
status?: string;
|
|
32
|
-
party?: string;
|
|
33
|
-
from?: string;
|
|
34
|
-
to?: string;
|
|
35
|
-
thisMonth?: boolean;
|
|
36
|
-
thisFy?: boolean;
|
|
37
|
-
page?: number;
|
|
38
|
-
limit?: number;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface GetOpts {
|
|
42
|
-
json?: boolean;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
interface CreateOpts {
|
|
46
|
-
json?: boolean;
|
|
47
|
-
partyId?: string;
|
|
48
|
-
party?: string;
|
|
49
|
-
date?: string;
|
|
50
|
-
dueDate?: string;
|
|
51
|
-
item?: string[];
|
|
52
|
-
qty?: string[];
|
|
53
|
-
rate?: string[];
|
|
54
|
-
notes?: string;
|
|
55
|
-
discount?: string;
|
|
56
|
-
yes?: boolean;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
interface StatusOpts {
|
|
60
|
-
json?: boolean;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
interface DeleteOpts {
|
|
64
|
-
yes?: boolean;
|
|
65
|
-
json?: boolean;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// ── Helpers ────────────────────────────────────────────────────────────────
|
|
69
|
-
|
|
70
|
-
type DocNamespace = {
|
|
71
|
-
list(input: any): Promise<any>;
|
|
72
|
-
getById(input: any): Promise<any>;
|
|
73
|
-
create(input: any): Promise<any>;
|
|
74
|
-
updateStatus(input: any): Promise<any>;
|
|
75
|
-
delete(input: any): Promise<any>;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
function getNs(client: HisaaboClient, nsKey: keyof HisaaboClient): DocNamespace {
|
|
79
|
-
return client[nsKey] as unknown as DocNamespace;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async function promptLine(rl: readline.Interface, question: string): Promise<string> {
|
|
83
|
-
return new Promise((resolve) => rl.question(question, resolve));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// ── list ───────────────────────────────────────────────────────────────────
|
|
87
|
-
|
|
88
|
-
export async function docListCommand(dt: DocTypeConfig, opts: ListOpts): Promise<void> {
|
|
89
|
-
const cfg = requireAuth();
|
|
90
|
-
const client = new HisaaboClient(cfg);
|
|
91
|
-
const ns = getNs(client, dt.nsKey);
|
|
92
|
-
|
|
93
|
-
let from = opts.from;
|
|
94
|
-
let to = opts.to;
|
|
95
|
-
if (opts.thisFy) { from = fyStart(); to = todayISO(); }
|
|
96
|
-
else if (opts.thisMonth) { from = monthStart(); to = monthEnd(); }
|
|
97
|
-
|
|
98
|
-
const page = opts.page ?? 1;
|
|
99
|
-
const limit = opts.limit ?? 20;
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
const result = await ns.list({
|
|
103
|
-
status: opts.status ?? null,
|
|
104
|
-
partySearch: opts.party ?? null,
|
|
105
|
-
fromDate: from ?? null,
|
|
106
|
-
toDate: to ?? null,
|
|
107
|
-
page,
|
|
108
|
-
limit,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
if (opts.json) {
|
|
112
|
-
outputJSON({
|
|
113
|
-
data: result.data,
|
|
114
|
-
pagination: {
|
|
115
|
-
page: result.page,
|
|
116
|
-
limit: result.limit,
|
|
117
|
-
total: result.total,
|
|
118
|
-
hasMore: result.page * result.limit < result.total,
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const tier = getWidthTier();
|
|
125
|
-
|
|
126
|
-
console.log(`\n ${dt.label}s` + " ".repeat(Math.max(1, 40 - dt.label.length)) + `FY ${currentFY()}`);
|
|
127
|
-
console.log(` ${"═".repeat(68)}\n`);
|
|
128
|
-
|
|
129
|
-
const narrowCols: ColumnDef<any>[] = [
|
|
130
|
-
{ key: "documentNumber", header: "#", width: 12 },
|
|
131
|
-
{ key: "partyName", header: "Party", width: 18 },
|
|
132
|
-
{ key: "totalAmount", header: "Amount (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
133
|
-
{ key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) },
|
|
134
|
-
];
|
|
135
|
-
|
|
136
|
-
const standardCols: ColumnDef<any>[] = [
|
|
137
|
-
{ key: "documentNumber", header: "#", width: 12 },
|
|
138
|
-
{ key: "partyName", header: "Party", width: 18 },
|
|
139
|
-
{ key: "documentDate", header: "Date", width: 12, format: (v) => formatDate(String(v ?? "")) },
|
|
140
|
-
{ key: "totalAmount", header: "Amount (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
141
|
-
{ key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) },
|
|
142
|
-
];
|
|
143
|
-
|
|
144
|
-
const wideCols: ColumnDef<any>[] = [
|
|
145
|
-
{ key: "documentNumber", header: "#", width: 12 },
|
|
146
|
-
{ key: "partyName", header: "Party", width: 20 },
|
|
147
|
-
{ key: "documentDate", header: "Date", width: 12, format: (v) => formatDate(String(v ?? "")) },
|
|
148
|
-
{ key: "dueDate", header: "Due", width: 12, format: (v) => formatDate(v ? String(v) : null) },
|
|
149
|
-
{ key: "totalAmount", header: "Amount (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
150
|
-
{ key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) },
|
|
151
|
-
];
|
|
152
|
-
|
|
153
|
-
const cols = tier === "narrow" ? narrowCols : tier === "wide" ? wideCols : standardCols;
|
|
154
|
-
|
|
155
|
-
if (opts.format === "tsv") {
|
|
156
|
-
outputTSV(result.data, cols);
|
|
157
|
-
} else if (opts.format === "csv") {
|
|
158
|
-
outputCSV(result.data, cols);
|
|
159
|
-
} else if (opts.format === "ids") {
|
|
160
|
-
outputIds(result.data.map((r: any) => r.id));
|
|
161
|
-
} else {
|
|
162
|
-
outputTable(result.data, cols);
|
|
163
|
-
paginationFooter(result.page, result.limit, result.total);
|
|
164
|
-
}
|
|
165
|
-
} catch (e) {
|
|
166
|
-
if (e instanceof HisaaboApiError) {
|
|
167
|
-
const err = e.hisaaboError;
|
|
168
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
169
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
170
|
-
}
|
|
171
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// ── get ────────────────────────────────────────────────────────────────────
|
|
176
|
-
|
|
177
|
-
export async function docGetCommand(dt: DocTypeConfig, id: string, opts: GetOpts): Promise<void> {
|
|
178
|
-
const cfg = requireAuth();
|
|
179
|
-
const client = new HisaaboClient(cfg);
|
|
180
|
-
const ns = getNs(client, dt.nsKey);
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
const doc = await ns.getById({ id });
|
|
184
|
-
|
|
185
|
-
if (opts.json) {
|
|
186
|
-
outputJSON(doc);
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const w = Math.min(termWidth() - 2, 68);
|
|
191
|
-
const inner = w - 2;
|
|
192
|
-
|
|
193
|
-
function line(left: string, right?: string): void {
|
|
194
|
-
if (right !== undefined) {
|
|
195
|
-
const pad = Math.max(1, inner - left.length - right.length - 2);
|
|
196
|
-
process.stdout.write(`│ ${left}${" ".repeat(pad)}${right} │\n`);
|
|
197
|
-
} else {
|
|
198
|
-
const vis = left.length;
|
|
199
|
-
const pad = Math.max(0, inner - vis);
|
|
200
|
-
process.stdout.write(`│ ${left}${" ".repeat(pad)} │\n`);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function divider(): void {
|
|
205
|
-
process.stdout.write(`├${"─".repeat(inner + 2)}┤\n`);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const docNum = doc.documentNumber ?? doc.number ?? id;
|
|
209
|
-
const title = `${dt.label.toUpperCase()} ${docNum}`;
|
|
210
|
-
const statusBadge = formatStatus(doc.status ?? "draft");
|
|
211
|
-
// eslint-disable-next-line no-control-regex
|
|
212
|
-
const statusLen = statusBadge.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
213
|
-
const topPad = Math.max(1, inner - title.length - statusLen);
|
|
214
|
-
|
|
215
|
-
process.stdout.write(`\n ┌${"─".repeat(inner + 2)}┐\n`);
|
|
216
|
-
process.stdout.write(`│ ${hasColor() ? chalk.bold(title) : title}${" ".repeat(topPad)}${statusBadge} │\n`);
|
|
217
|
-
divider();
|
|
218
|
-
if (doc.partyName) line(`Party: ${doc.partyName}`);
|
|
219
|
-
if (doc.documentDate ?? doc.date) line(`Date: ${formatDate(doc.documentDate ?? doc.date)}`);
|
|
220
|
-
if (doc.dueDate) line(`Due: ${formatDate(doc.dueDate)}`);
|
|
221
|
-
if (doc.createdByName) line(`Created: ${doc.createdByName}${doc.createdAt ? ` (${formatDate(doc.createdAt)})` : ""}`);
|
|
222
|
-
divider();
|
|
223
|
-
|
|
224
|
-
// Line items
|
|
225
|
-
const items: any[] = doc.lineItems ?? doc.items ?? [];
|
|
226
|
-
if (items.length > 0) {
|
|
227
|
-
process.stdout.write(`│${"─".repeat(inner + 2)}│\n`);
|
|
228
|
-
process.stdout.write(`│ # ${"Item".padEnd(18)} ${"Qty".padStart(5)} ${"Rate (₹)".padStart(10)} ${"Amount (₹)".padStart(12)} │\n`);
|
|
229
|
-
process.stdout.write(`│ ${"──".padEnd(2)} ${"─".repeat(18)} ${"─".repeat(5)} ${"─".repeat(10)} ${"─".repeat(12)} │\n`);
|
|
230
|
-
|
|
231
|
-
items.forEach((item: any, i: number) => {
|
|
232
|
-
const idx = String(i + 1).padStart(2);
|
|
233
|
-
const desc = (item.description ?? item.name ?? "").slice(0, 18).padEnd(18);
|
|
234
|
-
const qty = String(item.quantity ?? "1").padStart(5);
|
|
235
|
-
const rate = formatAmount(String(item.unitPrice ?? item.rate ?? "0")).padStart(10);
|
|
236
|
-
const amt = formatAmount(String(item.amount ?? "0")).padStart(12);
|
|
237
|
-
process.stdout.write(`│ ${idx} ${desc} ${qty} ${rate} ${amt} │\n`);
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
process.stdout.write(`│${"─".repeat(inner + 2)}│\n`);
|
|
241
|
-
divider();
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// Totals
|
|
245
|
-
if (doc.totalAmount !== undefined) {
|
|
246
|
-
if (doc.subtotal !== undefined) line(`Subtotal:`, formatAmount(String(doc.subtotal)).padStart(16));
|
|
247
|
-
if (doc.totalDiscount !== undefined && parseFloat(String(doc.totalDiscount)) !== 0)
|
|
248
|
-
line(`Discount:`, ("-" + formatAmount(String(doc.totalDiscount))).padStart(16));
|
|
249
|
-
process.stdout.write(`│ ${"─".repeat(inner - 2)} │\n`);
|
|
250
|
-
line(`Total:`, (hasColor() ? chalk.bold(formatAmount(String(doc.totalAmount))) : formatAmount(String(doc.totalAmount))).padStart(16));
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (doc.notes || doc.termsAndConditions) {
|
|
254
|
-
divider();
|
|
255
|
-
if (doc.notes) line(`Notes: ${doc.notes}`);
|
|
256
|
-
if (doc.termsAndConditions) line(`Terms: ${doc.termsAndConditions}`);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
process.stdout.write(` └${"─".repeat(inner + 2)}┘\n\n`);
|
|
260
|
-
|
|
261
|
-
} catch (e) {
|
|
262
|
-
if (e instanceof HisaaboApiError) {
|
|
263
|
-
const err = e.hisaaboError;
|
|
264
|
-
if (err.code === "not_found") fatalError(`${dt.label} not found: ${id}`, EXIT.NOT_FOUND);
|
|
265
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
266
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
267
|
-
}
|
|
268
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// ── create ─────────────────────────────────────────────────────────────────
|
|
273
|
-
|
|
274
|
-
export async function docCreateCommand(dt: DocTypeConfig, opts: CreateOpts): Promise<void> {
|
|
275
|
-
const cfg = requireAuth();
|
|
276
|
-
const client = new HisaaboClient(cfg);
|
|
277
|
-
const ns = getNs(client, dt.nsKey);
|
|
278
|
-
|
|
279
|
-
const isNonInteractive = !process.stdin.isTTY || opts.yes;
|
|
280
|
-
|
|
281
|
-
try {
|
|
282
|
-
// ── Resolve party ──────────────────────────────────────────────
|
|
283
|
-
let partyId = opts.partyId;
|
|
284
|
-
let partyName = opts.party ?? "";
|
|
285
|
-
|
|
286
|
-
if (!partyId) {
|
|
287
|
-
if (!isNonInteractive) {
|
|
288
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
289
|
-
console.log(`\n New ${dt.label}`);
|
|
290
|
-
console.log(" " + "─".repeat(40) + "\n");
|
|
291
|
-
|
|
292
|
-
const search = await promptLine(rl, " Select Party:\n > Search: ");
|
|
293
|
-
const parties = await client.party.list({ search: search.trim(), limit: 5 });
|
|
294
|
-
|
|
295
|
-
if (parties.data.length === 0) {
|
|
296
|
-
rl.close();
|
|
297
|
-
fatalError("No parties found. Create one with: hisaabo party create", EXIT.NOT_FOUND);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
parties.data.forEach((p: any, i: number) => {
|
|
301
|
-
console.log(` ${i + 1} ${p.name.padEnd(20)} ${(p.phone ?? "").padEnd(14)} ${p.type}`);
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
const partyChoice = await promptLine(rl, "\n Party [1]: ");
|
|
305
|
-
const idx = parseInt(partyChoice.trim() || "1", 10) - 1;
|
|
306
|
-
const selected = parties.data[Math.max(0, Math.min(idx, parties.data.length - 1))];
|
|
307
|
-
if (!selected) { rl.close(); fatalError("Invalid selection.", EXIT.USAGE); }
|
|
308
|
-
partyId = selected.id;
|
|
309
|
-
partyName = selected.name;
|
|
310
|
-
console.log(` Party: ${partyName}\n`);
|
|
311
|
-
rl.close();
|
|
312
|
-
} else {
|
|
313
|
-
if (!partyName) fatalError("--party or --party-id is required", EXIT.USAGE);
|
|
314
|
-
const parties = await client.party.list({ search: partyName, limit: 5 });
|
|
315
|
-
if (parties.data.length === 0) fatalError(`Party not found: ${partyName}`, EXIT.NOT_FOUND);
|
|
316
|
-
partyId = parties.data[0]!.id;
|
|
317
|
-
partyName = parties.data[0]!.name;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// ── Build line items ───────────────────────────────────────────
|
|
322
|
-
const lineItems: Array<{ itemId?: string; description: string; quantity: string; unitPrice: string; taxPercent?: string; discountPercent?: string }> = [];
|
|
323
|
-
|
|
324
|
-
if (opts.item && opts.item.length > 0) {
|
|
325
|
-
for (let i = 0; i < opts.item.length; i++) {
|
|
326
|
-
const itemName = opts.item[i]!;
|
|
327
|
-
const qty = opts.qty?.[i] ?? "1";
|
|
328
|
-
let unitPrice = opts.rate?.[i] ?? "";
|
|
329
|
-
|
|
330
|
-
if (!unitPrice) {
|
|
331
|
-
const items = await client.item.list({ search: itemName, limit: 3 });
|
|
332
|
-
if (items.data.length > 0 && items.data[0]?.salePrice) {
|
|
333
|
-
unitPrice = items.data[0].salePrice;
|
|
334
|
-
lineItems.push({
|
|
335
|
-
itemId: items.data[0].id,
|
|
336
|
-
description: items.data[0].name,
|
|
337
|
-
quantity: qty,
|
|
338
|
-
unitPrice,
|
|
339
|
-
taxPercent: items.data[0].taxPercent,
|
|
340
|
-
});
|
|
341
|
-
} else {
|
|
342
|
-
fatalError(`Item not found or has no price: ${itemName}. Use --rate to specify price.`, EXIT.NOT_FOUND);
|
|
343
|
-
}
|
|
344
|
-
} else {
|
|
345
|
-
const items = await client.item.list({ search: itemName, limit: 3 });
|
|
346
|
-
const matched = items.data.find((it: any) =>
|
|
347
|
-
it.name.toLowerCase().includes(itemName.toLowerCase()),
|
|
348
|
-
);
|
|
349
|
-
if (matched) {
|
|
350
|
-
lineItems.push({
|
|
351
|
-
itemId: matched.id,
|
|
352
|
-
description: matched.name,
|
|
353
|
-
quantity: qty,
|
|
354
|
-
unitPrice,
|
|
355
|
-
taxPercent: matched.taxPercent,
|
|
356
|
-
});
|
|
357
|
-
} else {
|
|
358
|
-
lineItems.push({ description: itemName, quantity: qty, unitPrice });
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
} else if (!isNonInteractive) {
|
|
363
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
364
|
-
console.log(" Add Line Items (empty description to finish):\n");
|
|
365
|
-
let itemNum = 1;
|
|
366
|
-
|
|
367
|
-
while (true) {
|
|
368
|
-
console.log(` Item ${itemNum}:`);
|
|
369
|
-
const search = await promptLine(rl, " Search item (or description): ");
|
|
370
|
-
if (!search.trim()) break;
|
|
371
|
-
|
|
372
|
-
let description = search.trim();
|
|
373
|
-
let itemId: string | undefined;
|
|
374
|
-
let defaultPrice = "";
|
|
375
|
-
let defaultTax = "0";
|
|
376
|
-
|
|
377
|
-
const items = await client.item.list({ search: search.trim(), limit: 5 });
|
|
378
|
-
if (items.data.length > 0) {
|
|
379
|
-
items.data.forEach((it: any, i: number) => {
|
|
380
|
-
const stock = it.itemType === "service" ? "-" : String(it.stockQuantity);
|
|
381
|
-
const price = it.salePrice ? formatINR(it.salePrice) : "no price";
|
|
382
|
-
console.log(` ${i + 1} ${it.name.padEnd(20)} ${price.padEnd(12)} Stock: ${stock}`);
|
|
383
|
-
});
|
|
384
|
-
const choice = await promptLine(rl, " Item [1] (or 0 to use as description): ");
|
|
385
|
-
const idx = parseInt(choice.trim() || "1", 10);
|
|
386
|
-
if (idx > 0) {
|
|
387
|
-
const selected = items.data[idx - 1];
|
|
388
|
-
if (selected) {
|
|
389
|
-
itemId = selected.id;
|
|
390
|
-
description = selected.name;
|
|
391
|
-
defaultPrice = selected.salePrice ?? "";
|
|
392
|
-
defaultTax = selected.taxPercent;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
const qtyStr = await promptLine(rl, " Quantity [1]: ");
|
|
398
|
-
const qty = qtyStr.trim() || "1";
|
|
399
|
-
|
|
400
|
-
const rateStr = await promptLine(rl, ` Unit Price [${defaultPrice || "0.00"}]: `);
|
|
401
|
-
const unitPrice = rateStr.trim() || defaultPrice || "0.00";
|
|
402
|
-
|
|
403
|
-
const taxStr = await promptLine(rl, ` Tax % [${defaultTax}]: `);
|
|
404
|
-
const taxPercent = taxStr.trim() || defaultTax;
|
|
405
|
-
|
|
406
|
-
const discStr = await promptLine(rl, " Discount % [0]: ");
|
|
407
|
-
const discountPercent = discStr.trim() || "0";
|
|
408
|
-
|
|
409
|
-
const amount =
|
|
410
|
-
parseFloat(qty) *
|
|
411
|
-
parseFloat(unitPrice) *
|
|
412
|
-
(1 + parseFloat(taxPercent) / 100) *
|
|
413
|
-
(1 - parseFloat(discountPercent) / 100);
|
|
414
|
-
console.log(
|
|
415
|
-
` > ${description} x${qty} @${formatAmount(unitPrice)} ${taxPercent}% tax = ${formatAmount(String(amount))}\n`,
|
|
416
|
-
);
|
|
417
|
-
|
|
418
|
-
lineItems.push({ itemId, description, quantity: qty, unitPrice, taxPercent, discountPercent });
|
|
419
|
-
itemNum++;
|
|
420
|
-
}
|
|
421
|
-
rl.close();
|
|
422
|
-
|
|
423
|
-
if (lineItems.length === 0) fatalError("No line items added.", EXIT.USAGE);
|
|
424
|
-
} else {
|
|
425
|
-
fatalError("No items specified. Use --item flags.", EXIT.USAGE);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// ── Summary & confirm ──────────────────────────────────────────
|
|
429
|
-
const subtotal = lineItems.reduce((s, item) => {
|
|
430
|
-
return s + parseFloat(item.quantity) * parseFloat(item.unitPrice);
|
|
431
|
-
}, 0);
|
|
432
|
-
const taxTotal = lineItems.reduce((s, item) => {
|
|
433
|
-
const amt = parseFloat(item.quantity) * parseFloat(item.unitPrice);
|
|
434
|
-
return s + amt * (parseFloat(item.taxPercent ?? "0") / 100);
|
|
435
|
-
}, 0);
|
|
436
|
-
|
|
437
|
-
let documentDate = opts.date ?? todayISO();
|
|
438
|
-
let dueDate = opts.dueDate;
|
|
439
|
-
let notes = opts.notes;
|
|
440
|
-
|
|
441
|
-
if (!isNonInteractive) {
|
|
442
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
443
|
-
console.log(`\n ─── ${dt.label} Summary ───────────────────────────`);
|
|
444
|
-
console.log(` Subtotal: ${formatAmount(String(subtotal))}`);
|
|
445
|
-
console.log(` Tax: ${formatAmount(String(taxTotal))}`);
|
|
446
|
-
console.log(` Total: ${formatAmount(String(subtotal + taxTotal))}`);
|
|
447
|
-
console.log(" ───────────────────────────────────────────────\n");
|
|
448
|
-
|
|
449
|
-
const dateStr = await promptLine(rl, ` Date [${todayISO()}]: `);
|
|
450
|
-
if (dateStr.trim()) documentDate = dateStr.trim();
|
|
451
|
-
|
|
452
|
-
const dueStr = await promptLine(rl, " Due Date [optional]: ");
|
|
453
|
-
if (dueStr.trim()) dueDate = dueStr.trim();
|
|
454
|
-
|
|
455
|
-
const notesStr = await promptLine(rl, " Notes: ");
|
|
456
|
-
if (notesStr.trim()) notes = notesStr.trim();
|
|
457
|
-
|
|
458
|
-
console.log(" ───────────────────────────────────────────────");
|
|
459
|
-
const confirm = await promptLine(rl, `\n Create this ${dt.label}? (y/n) [y]: `);
|
|
460
|
-
rl.close();
|
|
461
|
-
|
|
462
|
-
if (confirm.trim().toLowerCase() === "n") {
|
|
463
|
-
console.log(" Cancelled.");
|
|
464
|
-
process.exit(EXIT.SUCCESS);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
// ── Create ────────────────────────────────────────────────────
|
|
469
|
-
const doc = await ns.create({
|
|
470
|
-
partyId: partyId!,
|
|
471
|
-
documentDate,
|
|
472
|
-
dueDate,
|
|
473
|
-
notes,
|
|
474
|
-
lineItems,
|
|
475
|
-
...(opts.discount ? { invoiceDiscount: opts.discount } : {}),
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
if (opts.json) {
|
|
479
|
-
outputJSON(doc);
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
const docNum = doc.documentNumber ?? doc.number ?? doc.id;
|
|
484
|
-
const total = doc.totalAmount ?? String(subtotal + taxTotal);
|
|
485
|
-
success(`Created: ${docNum} for ${formatINR(total)}`);
|
|
486
|
-
console.log(` View: hisaabo ${dt.cmd} get ${doc.id}\n`);
|
|
487
|
-
|
|
488
|
-
} catch (e) {
|
|
489
|
-
if (e instanceof HisaaboApiError) {
|
|
490
|
-
const err = e.hisaaboError;
|
|
491
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
492
|
-
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
493
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
494
|
-
}
|
|
495
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
// ── update-status ──────────────────────────────────────────────────────────
|
|
500
|
-
|
|
501
|
-
export async function docStatusCommand(
|
|
502
|
-
dt: DocTypeConfig,
|
|
503
|
-
id: string,
|
|
504
|
-
status: string,
|
|
505
|
-
opts: StatusOpts,
|
|
506
|
-
): Promise<void> {
|
|
507
|
-
const cfg = requireAuth();
|
|
508
|
-
const client = new HisaaboClient(cfg);
|
|
509
|
-
const ns = getNs(client, dt.nsKey);
|
|
510
|
-
|
|
511
|
-
if (!dt.statuses.includes(status)) {
|
|
512
|
-
fatalError(`Invalid status: ${status}. Valid: ${dt.statuses.join(", ")}`, EXIT.USAGE);
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
try {
|
|
516
|
-
const before = await ns.getById({ id });
|
|
517
|
-
const updated = await ns.updateStatus({ id, status });
|
|
518
|
-
|
|
519
|
-
if (opts.json) {
|
|
520
|
-
outputJSON(updated);
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
const fromBadge = formatStatus(before.status ?? "draft");
|
|
525
|
-
const toBadge = formatStatus(status);
|
|
526
|
-
console.log(` ${id} status updated: ${fromBadge} -> ${toBadge}`);
|
|
527
|
-
|
|
528
|
-
} catch (e) {
|
|
529
|
-
if (e instanceof HisaaboApiError) {
|
|
530
|
-
const err = e.hisaaboError;
|
|
531
|
-
if (err.code === "not_found") fatalError(`${dt.label} not found: ${id}`, EXIT.NOT_FOUND);
|
|
532
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
533
|
-
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
534
|
-
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
535
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
536
|
-
}
|
|
537
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
// ── delete ─────────────────────────────────────────────────────────────────
|
|
542
|
-
|
|
543
|
-
export async function docDeleteCommand(
|
|
544
|
-
dt: DocTypeConfig,
|
|
545
|
-
id: string,
|
|
546
|
-
opts: DeleteOpts,
|
|
547
|
-
): Promise<void> {
|
|
548
|
-
const cfg = requireAuth();
|
|
549
|
-
const client = new HisaaboClient(cfg);
|
|
550
|
-
const ns = getNs(client, dt.nsKey);
|
|
551
|
-
|
|
552
|
-
try {
|
|
553
|
-
const doc = await ns.getById({ id });
|
|
554
|
-
const docNum = doc.documentNumber ?? doc.number ?? id;
|
|
555
|
-
|
|
556
|
-
if (!opts.yes && process.stdin.isTTY) {
|
|
557
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
558
|
-
const answer = await new Promise<string>((resolve) => {
|
|
559
|
-
rl.question(
|
|
560
|
-
` Delete ${docNum} (${doc.partyName ?? ""}, ${doc.totalAmount ?? ""})? (y/N): `,
|
|
561
|
-
resolve,
|
|
562
|
-
);
|
|
563
|
-
});
|
|
564
|
-
rl.close();
|
|
565
|
-
if (answer.trim().toLowerCase() !== "y") {
|
|
566
|
-
console.log(" Cancelled.");
|
|
567
|
-
process.exit(0);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
const result = await ns.delete({ id });
|
|
572
|
-
|
|
573
|
-
if (opts.json) {
|
|
574
|
-
outputJSON(result);
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
success(`Deleted: ${docNum}`);
|
|
579
|
-
|
|
580
|
-
} catch (e) {
|
|
581
|
-
if (e instanceof HisaaboApiError) {
|
|
582
|
-
const err = e.hisaaboError;
|
|
583
|
-
if (err.code === "not_found") fatalError(`${dt.label} not found: ${id}`, EXIT.NOT_FOUND);
|
|
584
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
585
|
-
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
586
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
587
|
-
}
|
|
588
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
589
|
-
}
|
|
590
|
-
}
|
|
@@ -1,109 +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
|
-
function handleError(e: unknown): never {
|
|
6
|
-
if (e instanceof HisaaboApiError) {
|
|
7
|
-
const err = e.hisaaboError;
|
|
8
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
9
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
10
|
-
}
|
|
11
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function eInvoiceDashboardCommand(opts: { json?: boolean; from?: string; to?: string }): Promise<void> {
|
|
15
|
-
const cfg = requireAuth();
|
|
16
|
-
const client = new HisaaboClient(cfg);
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const result = await client.eInvoice.dashboard({ fromDate: opts.from, toDate: opts.to });
|
|
20
|
-
|
|
21
|
-
if (opts.json) {
|
|
22
|
-
outputJSON(result);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const r = result as Record<string, unknown>;
|
|
27
|
-
console.log("\n E-Invoice Dashboard\n");
|
|
28
|
-
console.log(` ${"═".repeat(50)}\n`);
|
|
29
|
-
|
|
30
|
-
const generated = String(r["totalGenerated"] ?? r["generated"] ?? "0");
|
|
31
|
-
const cancelled = String(r["totalCancelled"] ?? r["cancelled"] ?? "0");
|
|
32
|
-
const failed = String(r["totalFailed"] ?? r["failed"] ?? "0");
|
|
33
|
-
const pending = String(r["pending"] ?? "0");
|
|
34
|
-
|
|
35
|
-
console.log(` Generated: ${generated.padStart(8)}`);
|
|
36
|
-
console.log(` Cancelled: ${cancelled.padStart(8)}`);
|
|
37
|
-
console.log(` Failed: ${failed.padStart(8)}`);
|
|
38
|
-
console.log(` Pending: ${pending.padStart(8)}`);
|
|
39
|
-
console.log();
|
|
40
|
-
|
|
41
|
-
} catch (e) {
|
|
42
|
-
handleError(e);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function eInvoiceGenerateCommand(invoiceId: string, opts: { json?: boolean }): Promise<void> {
|
|
47
|
-
const cfg = requireAuth();
|
|
48
|
-
const client = new HisaaboClient(cfg);
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
const result = await client.eInvoice.generate({ invoiceId });
|
|
52
|
-
|
|
53
|
-
if (opts.json) {
|
|
54
|
-
outputJSON(result);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const r = result as Record<string, unknown>;
|
|
59
|
-
const irn = String(r["irn"] ?? r["invoiceReferenceNumber"] ?? "-");
|
|
60
|
-
const ackNo = String(r["ackNo"] ?? r["acknowledgementNumber"] ?? "-");
|
|
61
|
-
console.log(` E-Invoice generated.\n`);
|
|
62
|
-
console.log(` IRN: ${irn}`);
|
|
63
|
-
console.log(` ACK: ${ackNo}`);
|
|
64
|
-
console.log();
|
|
65
|
-
|
|
66
|
-
} catch (e) {
|
|
67
|
-
handleError(e);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export async function eInvoiceCancelCommand(invoiceId: string, opts: { json?: boolean; reason?: string }): Promise<void> {
|
|
72
|
-
const cfg = requireAuth();
|
|
73
|
-
const client = new HisaaboClient(cfg);
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const result = await client.eInvoice.cancel({ invoiceId, cancelReason: opts.reason ?? "1" });
|
|
77
|
-
|
|
78
|
-
if (opts.json) {
|
|
79
|
-
outputJSON(result);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
console.log(` E-Invoice for ${invoiceId} cancelled.\n`);
|
|
84
|
-
|
|
85
|
-
} catch (e) {
|
|
86
|
-
handleError(e);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export async function eInvoiceRetryCommand(invoiceId: string, opts: { json?: boolean }): Promise<void> {
|
|
91
|
-
const cfg = requireAuth();
|
|
92
|
-
const client = new HisaaboClient(cfg);
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
const result = await client.eInvoice.retryFailed({ invoiceId });
|
|
96
|
-
|
|
97
|
-
if (opts.json) {
|
|
98
|
-
outputJSON(result);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const r = result as Record<string, unknown>;
|
|
103
|
-
const status = String(r["status"] ?? "queued");
|
|
104
|
-
console.log(` Retry queued for invoice ${invoiceId}. Status: ${status}\n`);
|
|
105
|
-
|
|
106
|
-
} catch (e) {
|
|
107
|
-
handleError(e);
|
|
108
|
-
}
|
|
109
|
-
}
|