@hisaabo/cli 0.9.0 → 0.10.0
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/README.md +154 -4
- package/dist/bin/{audit-trail-IJ6SKACR.js → audit-trail-RTPTWZAL.js} +12 -15
- package/dist/bin/{categories-O6TODPAH.js → categories-JJDTOT5T.js} +3 -3
- package/dist/bin/{check-slug-P7RFU6OP.js → check-slug-5L2VDAEN.js} +16 -4
- package/dist/bin/chunk-2DDIXPNI.js +1512 -0
- package/dist/bin/chunk-ALOHN6GR.js +78 -0
- package/dist/bin/{chunk-QUITS2FE.js → chunk-ESX7V56A.js} +95 -20
- package/dist/bin/chunk-M7DVLVD5.js +245 -0
- package/dist/bin/{chunk-WDN7RIE3.js → chunk-VXEEFNIY.js} +133 -47
- package/dist/bin/client-NFYNYEDI.js +17 -0
- package/dist/bin/{collection-efficiency-DA5RWG3V.js → collection-efficiency-UF3AJPQB.js} +12 -56
- package/dist/bin/{config-4LLNT4SH.js → config-7HVBRHL3.js} +2 -2
- package/dist/bin/{create-C5INBPQO.js → create-2BZQLXQA.js} +18 -9
- package/dist/bin/{default-account-2GMQ7ZA4.js → default-account-MR6O5LPT.js} +7 -13
- package/dist/bin/{expenses-S2YVA5UT.js → expenses-CU6JGDVX.js} +12 -11
- package/dist/bin/{export-YOOODNVX.js → export-GFYQIQLT.js} +9 -24
- package/dist/bin/{export-6PMJ2YVL.js → export-WS24LYNH.js} +47 -11
- package/dist/bin/{factory-6MUCSXTL.js → factory-JSEQCPY3.js} +51 -57
- package/dist/bin/{get-GMQRROK2.js → get-HGMB7T6Y.js} +5 -4
- package/dist/bin/{get-ZV3SC2VY.js → get-KAOGGRJR.js} +4 -4
- package/dist/bin/hisaabo.js +2024 -837
- package/dist/bin/{import-UUHMLCKX.js → import-6CEMNCTM.js} +30 -33
- package/dist/bin/{invitations-OVORTTMF.js → invitations-LASABD2X.js} +11 -14
- package/dist/bin/{invite-GGHBZY4U.js → invite-VCBXS7VY.js} +13 -15
- package/dist/bin/{invoice-breakdown-32XXAZDP.js → invoice-breakdown-3XXSYA77.js} +12 -37
- package/dist/bin/{items-6NOIMH6B.js → items-PJPN6ZX3.js} +11 -10
- package/dist/bin/{items-toggle-L6W6QKQD.js → items-toggle-53C35MJU.js} +6 -5
- package/dist/bin/{list-RAR56EMQ.js → list-63EKE6DT.js} +13 -16
- package/dist/bin/{list-OXAVDXH7.js → list-7OSZX6C7.js} +5 -5
- package/dist/bin/{list-FC5JHKHD.js → list-OOROCQR2.js} +11 -12
- package/dist/bin/{members-Y6XJVHHR.js → members-SPHU5F4M.js} +7 -7
- package/dist/bin/monthly-comparison-3FFJT63K.js +79 -0
- package/dist/bin/{order-cancel-QRTCNART.js → order-cancel-RW4NYHKN.js} +8 -18
- package/dist/bin/{order-confirm-LGQOMC4O.js → order-confirm-NXFL2EIQ.js} +7 -15
- package/dist/bin/{order-get-4XAQCRYV.js → order-get-QPSOY2RT.js} +11 -11
- package/dist/bin/{order-update-KZY4H2UR.js → order-update-7DWKEROO.js} +4 -4
- package/dist/bin/{output-NUOL7KJW.js → output-XFDIL3A6.js} +5 -1
- package/dist/bin/{payment-modes-DY2ZEMK7.js → payment-modes-Z5WV3E3O.js} +12 -27
- package/dist/bin/{profit-loss-5GJBG3PL.js → profit-loss-AOISAJ56.js} +14 -13
- package/dist/bin/{receivables-aging-6A7XJKDT.js → receivables-aging-5JHFECGB.js} +13 -66
- package/dist/bin/{remove-ZBX34TIQ.js → remove-TC4UWMOL.js} +7 -15
- package/dist/bin/{revoke-ZTAMW2Q2.js → revoke-QHLNPGI5.js} +7 -3
- package/dist/bin/{revoke-XDNOA2GJ.js → revoke-SXVNALYQ.js} +7 -15
- package/dist/bin/{revoke-all-365NRBOA.js → revoke-all-CYW6A5UE.js} +8 -4
- package/dist/bin/{revoke-invitation-PQH7XNYA.js → revoke-invitation-Z33EUJTS.js} +7 -3
- package/dist/bin/safety-TPD2P7I5.js +18 -0
- package/dist/bin/{sales-trend-D6PQ7MHY.js → sales-trend-WCW6X5BI.js} +16 -16
- package/dist/bin/sequence-HOQ4PQRK.js +56 -0
- package/dist/bin/{store-SVRZBUFO.js → store-DDMHTNTO.js} +15 -8
- package/dist/bin/{summary-H6U7O5GJ.js → summary-TYAL2D3Q.js} +7 -5
- package/dist/bin/{top-customers-ATBN6RDI.js → top-customers-GMIS6GC3.js} +13 -11
- package/dist/bin/{top-items-XXU6KYTC.js → top-items-BK54JO3G.js} +16 -14
- package/dist/bin/{top-outstanding-JTQNGGW4.js → top-outstanding-L4NRJ6NE.js} +9 -11
- package/dist/bin/{unpaid-invoices-BTNQFWCH.js → unpaid-invoices-CEUFEYH7.js} +8 -8
- package/dist/bin/{untracked-PAMEDJ6Y.js → untracked-T6DIDMDQ.js} +9 -9
- package/dist/bin/{update-EK4NJWU4.js → update-EPNB2U74.js} +4 -4
- package/dist/bin/{update-EGHPFXLK.js → update-I2DZRVLR.js} +10 -17
- package/dist/bin/{update-6ZMX2OYX.js → update-MFNOVS6D.js} +4 -4
- package/dist/bin/{update-role-24PDTNFK.js → update-role-D2ETEL2Q.js} +7 -4
- package/dist/bin/{update-settings-AASI6WZX.js → update-settings-UGXLQRYI.js} +15 -9
- package/package.json +8 -7
- package/dist/bin/chunk-NO4FIFMS.js +0 -176
- package/dist/bin/chunk-ZPYC767N.js +0 -157
- package/dist/bin/client-36JX5MR3.js +0 -11
- package/dist/bin/monthly-comparison-IAUZ6SBJ.js +0 -176
- package/dist/bin/sequence-KZWADVD7.js +0 -66
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
apiFrom,
|
|
4
|
+
apiTo,
|
|
3
5
|
formatAmount,
|
|
4
6
|
fyStart,
|
|
5
7
|
monthEnd,
|
|
6
8
|
monthStart,
|
|
7
9
|
todayISO
|
|
8
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-M7DVLVD5.js";
|
|
9
11
|
import {
|
|
10
12
|
HisaaboApiError,
|
|
11
13
|
HisaaboClient
|
|
12
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-VXEEFNIY.js";
|
|
13
15
|
import {
|
|
14
16
|
requireAuth
|
|
15
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-ESX7V56A.js";
|
|
16
18
|
import {
|
|
17
19
|
EXIT,
|
|
18
20
|
fatalError,
|
|
@@ -21,7 +23,7 @@ import {
|
|
|
21
23
|
outputJSON,
|
|
22
24
|
outputTSV,
|
|
23
25
|
outputTable
|
|
24
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-2DDIXPNI.js";
|
|
25
27
|
|
|
26
28
|
// src/commands/dashboard/expenses.ts
|
|
27
29
|
import chalk from "chalk";
|
|
@@ -38,20 +40,19 @@ async function dashboardExpensesCommand(opts) {
|
|
|
38
40
|
toDate = todayISO();
|
|
39
41
|
}
|
|
40
42
|
try {
|
|
41
|
-
const data = await client.dashboard.expensesByCategory({ fromDate, toDate });
|
|
43
|
+
const data = await client.dashboard.expensesByCategory({ fromDate: apiFrom(fromDate), toDate: apiTo(toDate) });
|
|
42
44
|
if (opts.json) {
|
|
43
45
|
outputJSON(data);
|
|
44
46
|
return;
|
|
45
47
|
}
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
const amt = parseFloat(String(r["totalAmount"] ?? r["amount"] ?? "0"));
|
|
48
|
+
const total = data.reduce((sum, r) => sum + parseFloat(r.total), 0);
|
|
49
|
+
const rows = data.map((r) => {
|
|
50
|
+
const amt = parseFloat(r.total);
|
|
50
51
|
const pct = total > 0 ? (amt / total * 100).toFixed(1) + "%" : "-";
|
|
51
52
|
return {
|
|
52
|
-
category:
|
|
53
|
+
category: r.category,
|
|
53
54
|
amount: formatAmount(String(amt)),
|
|
54
|
-
count: String(r
|
|
55
|
+
count: String(r.count),
|
|
55
56
|
pct
|
|
56
57
|
};
|
|
57
58
|
});
|
|
@@ -1,49 +1,34 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
confirmOrExit
|
|
4
|
+
} from "./chunk-ALOHN6GR.js";
|
|
2
5
|
import {
|
|
3
6
|
HisaaboApiError,
|
|
4
7
|
HisaaboClient
|
|
5
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-VXEEFNIY.js";
|
|
6
9
|
import {
|
|
7
10
|
requireAuth
|
|
8
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-ESX7V56A.js";
|
|
9
12
|
import {
|
|
10
13
|
EXIT,
|
|
11
14
|
fatalError,
|
|
12
15
|
outputJSON,
|
|
13
16
|
success
|
|
14
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-2DDIXPNI.js";
|
|
15
18
|
|
|
16
19
|
// src/commands/business/export.ts
|
|
17
|
-
import * as readline from "readline";
|
|
18
20
|
async function businessExportCommand(opts) {
|
|
19
21
|
const cfg = requireAuth();
|
|
20
22
|
const client = new HisaaboClient(cfg);
|
|
21
|
-
|
|
22
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
23
|
-
const answer = await new Promise((resolve) => {
|
|
24
|
-
rl.question(" Export all business data? This may take a moment. (y/N): ", resolve);
|
|
25
|
-
});
|
|
26
|
-
rl.close();
|
|
27
|
-
if (answer.trim().toLowerCase() !== "y") {
|
|
28
|
-
console.log(" Cancelled.");
|
|
29
|
-
process.exit(0);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
23
|
+
await confirmOrExit(" Export all business data? This may take a moment.", opts);
|
|
32
24
|
try {
|
|
33
25
|
const result = await client.business.exportData();
|
|
34
26
|
if (opts.json) {
|
|
35
27
|
outputJSON(result);
|
|
36
28
|
return;
|
|
37
29
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
process.stdout.write(` Download URL: ${result.url}
|
|
41
|
-
`);
|
|
42
|
-
} else if (result?.status === "processing" || result?.queued) {
|
|
43
|
-
success("Export queued. You will be notified when the export is ready.");
|
|
44
|
-
} else {
|
|
45
|
-
success("Export initiated successfully.");
|
|
46
|
-
}
|
|
30
|
+
success(`Export complete: ${Object.keys(result).join(", ")}.`);
|
|
31
|
+
process.stdout.write(" Use --json to output the CSV contents.\n");
|
|
47
32
|
} catch (e) {
|
|
48
33
|
if (e instanceof HisaaboApiError) {
|
|
49
34
|
const err = e.hisaaboError;
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
HisaaboApiError,
|
|
4
|
-
HisaaboClient
|
|
5
|
-
|
|
4
|
+
HisaaboClient,
|
|
5
|
+
transferTimeoutMs
|
|
6
|
+
} from "./chunk-VXEEFNIY.js";
|
|
6
7
|
import {
|
|
7
|
-
requireTenantAuth
|
|
8
|
-
|
|
8
|
+
requireTenantAuth,
|
|
9
|
+
resolveSameOriginUrl
|
|
10
|
+
} from "./chunk-ESX7V56A.js";
|
|
9
11
|
import {
|
|
10
12
|
EXIT,
|
|
11
13
|
fatalError,
|
|
12
14
|
hasColor,
|
|
13
15
|
isInteractive,
|
|
14
16
|
success
|
|
15
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-2DDIXPNI.js";
|
|
16
18
|
|
|
17
19
|
// src/commands/backup/export.ts
|
|
18
20
|
import { createWriteStream } from "fs";
|
|
19
|
-
import { stat, unlink } from "fs/promises";
|
|
21
|
+
import { lstat, stat, unlink } from "fs/promises";
|
|
20
22
|
import { createHash } from "crypto";
|
|
21
23
|
import chalk from "chalk";
|
|
22
24
|
var EXIT_AUTH = 1;
|
|
@@ -31,11 +33,11 @@ async function resolveTenantId(client, slugOrId) {
|
|
|
31
33
|
return slugOrId;
|
|
32
34
|
}
|
|
33
35
|
const tenants = await client.tenant.list();
|
|
34
|
-
const match = tenants.find((t) => t.
|
|
36
|
+
const match = tenants.find((t) => t.tenantSlug === slugOrId);
|
|
35
37
|
if (!match) {
|
|
36
38
|
fatalError(`Tenant "${slugOrId}" not found. Run: hisaabo tenant list`, EXIT.NOT_FOUND);
|
|
37
39
|
}
|
|
38
|
-
return match.
|
|
40
|
+
return match.tenantId;
|
|
39
41
|
}
|
|
40
42
|
function formatBytes(bytes) {
|
|
41
43
|
if (bytes < 1024) return `${bytes} B`;
|
|
@@ -77,7 +79,7 @@ async function exportCommand(opts) {
|
|
|
77
79
|
let exportUrl;
|
|
78
80
|
try {
|
|
79
81
|
const result = await client.selfExport.request({ tenantId });
|
|
80
|
-
exportUrl = result.url
|
|
82
|
+
exportUrl = resolveSameOriginUrl(result.url, cfg.apiUrl);
|
|
81
83
|
} catch (e) {
|
|
82
84
|
if (e instanceof HisaaboApiError) {
|
|
83
85
|
const err = e.hisaaboError;
|
|
@@ -109,13 +111,44 @@ async function exportCommand(opts) {
|
|
|
109
111
|
process.stdout.write(` Downloading backup to ${outPath}...
|
|
110
112
|
`);
|
|
111
113
|
}
|
|
112
|
-
|
|
114
|
+
try {
|
|
115
|
+
const existing = await lstat(outPath);
|
|
116
|
+
if (existing.isSymbolicLink()) {
|
|
117
|
+
fatalError(`Refusing to write to a symlink: ${outPath}`, EXIT.USAGE);
|
|
118
|
+
}
|
|
119
|
+
if (!opts.force) {
|
|
120
|
+
fatalError(`${outPath} already exists. Use --force to overwrite.`, EXIT.USAGE);
|
|
121
|
+
}
|
|
122
|
+
if (!existing.isFile()) {
|
|
123
|
+
fatalError(`${outPath} is not a regular file`, EXIT.USAGE);
|
|
124
|
+
}
|
|
125
|
+
await unlink(outPath);
|
|
126
|
+
} catch (e) {
|
|
127
|
+
if (e?.code !== "ENOENT") throw e;
|
|
128
|
+
}
|
|
129
|
+
const writeStream = createWriteStream(outPath, { flags: "wx", mode: 384 });
|
|
130
|
+
const opened = await new Promise((resolve) => {
|
|
131
|
+
writeStream.once("open", () => resolve(null));
|
|
132
|
+
writeStream.once("error", (err) => resolve(err));
|
|
133
|
+
});
|
|
134
|
+
if (opened) {
|
|
135
|
+
fatalError(`Cannot create ${outPath}: ${opened.message}`, EXIT.USAGE);
|
|
136
|
+
}
|
|
137
|
+
const abort = new AbortController();
|
|
138
|
+
let idleTimer;
|
|
139
|
+
const bumpIdle = () => {
|
|
140
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
141
|
+
idleTimer = setTimeout(() => abort.abort(), transferTimeoutMs());
|
|
142
|
+
};
|
|
143
|
+
bumpIdle();
|
|
113
144
|
try {
|
|
114
145
|
const response = await fetch(exportUrl, {
|
|
115
146
|
headers: {
|
|
116
147
|
"Authorization": `Bearer ${cfg.token}`,
|
|
117
148
|
"x-client-type": "cli"
|
|
118
|
-
}
|
|
149
|
+
},
|
|
150
|
+
redirect: "error",
|
|
151
|
+
signal: abort.signal
|
|
119
152
|
});
|
|
120
153
|
if (!response.ok) {
|
|
121
154
|
writeStream.close();
|
|
@@ -139,6 +172,7 @@ async function exportCommand(opts) {
|
|
|
139
172
|
writeStream.end(() => resolve());
|
|
140
173
|
return;
|
|
141
174
|
}
|
|
175
|
+
bumpIdle();
|
|
142
176
|
sha256.update(value);
|
|
143
177
|
fileSize += value.length;
|
|
144
178
|
if (!writeStream.write(value)) {
|
|
@@ -151,6 +185,7 @@ async function exportCommand(opts) {
|
|
|
151
185
|
pump();
|
|
152
186
|
});
|
|
153
187
|
} catch (e) {
|
|
188
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
154
189
|
if (progressInterval !== void 0) {
|
|
155
190
|
clearInterval(progressInterval);
|
|
156
191
|
}
|
|
@@ -162,6 +197,7 @@ async function exportCommand(opts) {
|
|
|
162
197
|
}
|
|
163
198
|
fatalError(`Download failed: ${String(e instanceof Error ? e.message : e)}`, EXIT_SERVER_ERROR);
|
|
164
199
|
}
|
|
200
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
165
201
|
if (progressInterval !== void 0) {
|
|
166
202
|
clearInterval(progressInterval);
|
|
167
203
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
confirmOrExit
|
|
4
|
+
} from "./chunk-ALOHN6GR.js";
|
|
5
|
+
import {
|
|
6
|
+
apiFrom,
|
|
7
|
+
apiTo,
|
|
3
8
|
currentFY,
|
|
4
9
|
formatAmount,
|
|
5
10
|
formatDate,
|
|
@@ -8,15 +13,16 @@ import {
|
|
|
8
13
|
fyStart,
|
|
9
14
|
monthEnd,
|
|
10
15
|
monthStart,
|
|
16
|
+
toApiDateTime,
|
|
11
17
|
todayISO
|
|
12
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-M7DVLVD5.js";
|
|
13
19
|
import {
|
|
14
20
|
HisaaboApiError,
|
|
15
21
|
HisaaboClient
|
|
16
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-VXEEFNIY.js";
|
|
17
23
|
import {
|
|
18
24
|
requireAuth
|
|
19
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-ESX7V56A.js";
|
|
20
26
|
import {
|
|
21
27
|
EXIT,
|
|
22
28
|
fatalError,
|
|
@@ -30,7 +36,7 @@ import {
|
|
|
30
36
|
paginationFooter,
|
|
31
37
|
success,
|
|
32
38
|
termWidth
|
|
33
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-2DDIXPNI.js";
|
|
34
40
|
|
|
35
41
|
// src/commands/document/factory.ts
|
|
36
42
|
import * as readline from "readline";
|
|
@@ -58,10 +64,10 @@ async function docListCommand(dt, opts) {
|
|
|
58
64
|
const limit = opts.limit ?? 20;
|
|
59
65
|
try {
|
|
60
66
|
const result = await ns.list({
|
|
61
|
-
status: opts.status
|
|
62
|
-
|
|
63
|
-
fromDate: from
|
|
64
|
-
toDate: to
|
|
67
|
+
status: opts.status,
|
|
68
|
+
search: opts.party,
|
|
69
|
+
fromDate: apiFrom(from),
|
|
70
|
+
toDate: apiTo(to),
|
|
65
71
|
page,
|
|
66
72
|
limit
|
|
67
73
|
});
|
|
@@ -83,23 +89,23 @@ async function docListCommand(dt, opts) {
|
|
|
83
89
|
console.log(` ${"\u2550".repeat(68)}
|
|
84
90
|
`);
|
|
85
91
|
const narrowCols = [
|
|
86
|
-
{ key: "
|
|
92
|
+
{ key: "invoiceNumber", header: "#", width: 12 },
|
|
87
93
|
{ key: "partyName", header: "Party", width: 18 },
|
|
88
94
|
{ key: "totalAmount", header: "Amount (\u20B9)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
89
95
|
{ key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) }
|
|
90
96
|
];
|
|
91
97
|
const standardCols = [
|
|
92
|
-
{ key: "
|
|
98
|
+
{ key: "invoiceNumber", header: "#", width: 12 },
|
|
93
99
|
{ key: "partyName", header: "Party", width: 18 },
|
|
94
|
-
{ key: "
|
|
100
|
+
{ key: "invoiceDate", header: "Date", width: 12, format: (v) => formatDate(v) },
|
|
95
101
|
{ key: "totalAmount", header: "Amount (\u20B9)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
96
102
|
{ key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) }
|
|
97
103
|
];
|
|
98
104
|
const wideCols = [
|
|
99
|
-
{ key: "
|
|
105
|
+
{ key: "invoiceNumber", header: "#", width: 12 },
|
|
100
106
|
{ key: "partyName", header: "Party", width: 20 },
|
|
101
|
-
{ key: "
|
|
102
|
-
{ key: "dueDate", header: "Due", width: 12, format: (v) => formatDate(v
|
|
107
|
+
{ key: "invoiceDate", header: "Date", width: 12, format: (v) => formatDate(v) },
|
|
108
|
+
{ key: "dueDate", header: "Due", width: 12, format: (v) => formatDate(v) },
|
|
103
109
|
{ key: "totalAmount", header: "Amount (\u20B9)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
104
110
|
{ key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) }
|
|
105
111
|
];
|
|
@@ -145,15 +151,15 @@ async function docGetCommand(dt, id, opts) {
|
|
|
145
151
|
};
|
|
146
152
|
var line = line2, divider = divider2;
|
|
147
153
|
const doc = await ns.getById({ id });
|
|
154
|
+
if (!doc) fatalError(`${dt.label} not found: ${id}`, EXIT.NOT_FOUND);
|
|
148
155
|
if (opts.json) {
|
|
149
156
|
outputJSON(doc);
|
|
150
157
|
return;
|
|
151
158
|
}
|
|
152
159
|
const w = Math.min(termWidth() - 2, 68);
|
|
153
160
|
const inner = w - 2;
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
const statusBadge = formatStatus(doc.status ?? "draft");
|
|
161
|
+
const title = `${dt.label.toUpperCase()} ${doc.invoiceNumber}`;
|
|
162
|
+
const statusBadge = formatStatus(doc.status);
|
|
157
163
|
const statusLen = statusBadge.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
158
164
|
const topPad = Math.max(1, inner - title.length - statusLen);
|
|
159
165
|
process.stdout.write(`
|
|
@@ -162,12 +168,12 @@ async function docGetCommand(dt, id, opts) {
|
|
|
162
168
|
process.stdout.write(`\u2502 ${hasColor() ? chalk.bold(title) : title}${" ".repeat(topPad)}${statusBadge} \u2502
|
|
163
169
|
`);
|
|
164
170
|
divider2();
|
|
165
|
-
if (doc.
|
|
166
|
-
|
|
171
|
+
if (doc.party) line2(`Party: ${doc.party.name}`);
|
|
172
|
+
line2(`Date: ${formatDate(doc.invoiceDate)}`);
|
|
167
173
|
if (doc.dueDate) line2(`Due: ${formatDate(doc.dueDate)}`);
|
|
168
174
|
if (doc.createdByName) line2(`Created: ${doc.createdByName}${doc.createdAt ? ` (${formatDate(doc.createdAt)})` : ""}`);
|
|
169
175
|
divider2();
|
|
170
|
-
const items = doc.lineItems
|
|
176
|
+
const items = doc.lineItems;
|
|
171
177
|
if (items.length > 0) {
|
|
172
178
|
process.stdout.write(`\u2502${"\u2500".repeat(inner + 2)}\u2502
|
|
173
179
|
`);
|
|
@@ -177,10 +183,10 @@ async function docGetCommand(dt, id, opts) {
|
|
|
177
183
|
`);
|
|
178
184
|
items.forEach((item, i) => {
|
|
179
185
|
const idx = String(i + 1).padStart(2);
|
|
180
|
-
const desc =
|
|
181
|
-
const qty =
|
|
182
|
-
const rate = formatAmount(
|
|
183
|
-
const amt = formatAmount(
|
|
186
|
+
const desc = item.itemName.slice(0, 18).padEnd(18);
|
|
187
|
+
const qty = item.quantity.padStart(5);
|
|
188
|
+
const rate = formatAmount(item.unitPrice).padStart(10);
|
|
189
|
+
const amt = formatAmount(item.totalAmount).padStart(12);
|
|
184
190
|
process.stdout.write(`\u2502 ${idx} ${desc} ${qty} ${rate} ${amt} \u2502
|
|
185
191
|
`);
|
|
186
192
|
});
|
|
@@ -188,14 +194,12 @@ async function docGetCommand(dt, id, opts) {
|
|
|
188
194
|
`);
|
|
189
195
|
divider2();
|
|
190
196
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
process.stdout.write(`\u2502 ${"\u2500".repeat(inner - 2)} \u2502
|
|
197
|
+
line2(`Subtotal:`, formatAmount(doc.subtotal).padStart(16));
|
|
198
|
+
if (parseFloat(doc.discountAmount) !== 0)
|
|
199
|
+
line2(`Discount:`, ("-" + formatAmount(doc.discountAmount)).padStart(16));
|
|
200
|
+
process.stdout.write(`\u2502 ${"\u2500".repeat(inner - 2)} \u2502
|
|
196
201
|
`);
|
|
197
|
-
|
|
198
|
-
}
|
|
202
|
+
line2(`Total:`, (hasColor() ? chalk.bold(formatAmount(doc.totalAmount)) : formatAmount(doc.totalAmount)).padStart(16));
|
|
199
203
|
if (doc.notes || doc.termsAndConditions) {
|
|
200
204
|
divider2();
|
|
201
205
|
if (doc.notes) line2(`Notes: ${doc.notes}`);
|
|
@@ -269,7 +273,7 @@ async function docCreateCommand(dt, opts) {
|
|
|
269
273
|
unitPrice = items.data[0].salePrice;
|
|
270
274
|
lineItems.push({
|
|
271
275
|
itemId: items.data[0].id,
|
|
272
|
-
|
|
276
|
+
itemName: items.data[0].name,
|
|
273
277
|
quantity: qty,
|
|
274
278
|
unitPrice,
|
|
275
279
|
taxPercent: items.data[0].taxPercent
|
|
@@ -285,13 +289,13 @@ async function docCreateCommand(dt, opts) {
|
|
|
285
289
|
if (matched) {
|
|
286
290
|
lineItems.push({
|
|
287
291
|
itemId: matched.id,
|
|
288
|
-
|
|
292
|
+
itemName: matched.name,
|
|
289
293
|
quantity: qty,
|
|
290
294
|
unitPrice,
|
|
291
295
|
taxPercent: matched.taxPercent
|
|
292
296
|
});
|
|
293
297
|
} else {
|
|
294
|
-
lineItems.push({
|
|
298
|
+
lineItems.push({ itemName, quantity: qty, unitPrice });
|
|
295
299
|
}
|
|
296
300
|
}
|
|
297
301
|
}
|
|
@@ -339,7 +343,7 @@ async function docCreateCommand(dt, opts) {
|
|
|
339
343
|
` > ${description} x${qty} @${formatAmount(unitPrice)} ${taxPercent}% tax = ${formatAmount(String(amount))}
|
|
340
344
|
`
|
|
341
345
|
);
|
|
342
|
-
lineItems.push({ itemId, description, quantity: qty, unitPrice, taxPercent, discountPercent });
|
|
346
|
+
lineItems.push({ itemId, itemName: description, quantity: qty, unitPrice, taxPercent, discountPercent });
|
|
343
347
|
itemNum++;
|
|
344
348
|
}
|
|
345
349
|
rl.close();
|
|
@@ -380,21 +384,22 @@ async function docCreateCommand(dt, opts) {
|
|
|
380
384
|
process.exit(EXIT.SUCCESS);
|
|
381
385
|
}
|
|
382
386
|
}
|
|
387
|
+
const type = opts.type ?? "sale";
|
|
388
|
+
if (type !== "sale" && type !== "purchase") fatalError("--type must be sale or purchase", EXIT.USAGE);
|
|
383
389
|
const doc = await ns.create({
|
|
390
|
+
type,
|
|
384
391
|
partyId,
|
|
385
|
-
documentDate,
|
|
386
|
-
dueDate,
|
|
392
|
+
invoiceDate: toApiDateTime(documentDate, "start"),
|
|
393
|
+
dueDate: dueDate ? toApiDateTime(dueDate, "end") : void 0,
|
|
387
394
|
notes,
|
|
388
395
|
lineItems,
|
|
389
|
-
...opts.discount ? { invoiceDiscount: opts.discount } : {}
|
|
396
|
+
...opts.discount ? { invoiceDiscount: opts.discount, invoiceDiscountType: "percent" } : {}
|
|
390
397
|
});
|
|
391
398
|
if (opts.json) {
|
|
392
399
|
outputJSON(doc);
|
|
393
400
|
return;
|
|
394
401
|
}
|
|
395
|
-
|
|
396
|
-
const total = doc.totalAmount ?? String(subtotal + taxTotal);
|
|
397
|
-
success(`Created: ${docNum} for ${formatINR(total)}`);
|
|
402
|
+
success(`Created: ${doc.invoiceNumber} for ${formatINR(doc.totalAmount)}`);
|
|
398
403
|
console.log(` View: hisaabo ${dt.cmd} get ${doc.id}
|
|
399
404
|
`);
|
|
400
405
|
} catch (e) {
|
|
@@ -416,12 +421,13 @@ async function docStatusCommand(dt, id, status, opts) {
|
|
|
416
421
|
}
|
|
417
422
|
try {
|
|
418
423
|
const before = await ns.getById({ id });
|
|
424
|
+
if (!before) fatalError(`${dt.label} not found: ${id}`, EXIT.NOT_FOUND);
|
|
419
425
|
const updated = await ns.updateStatus({ id, status });
|
|
420
426
|
if (opts.json) {
|
|
421
427
|
outputJSON(updated);
|
|
422
428
|
return;
|
|
423
429
|
}
|
|
424
|
-
const fromBadge = formatStatus(before.status
|
|
430
|
+
const fromBadge = formatStatus(before.status);
|
|
425
431
|
const toBadge = formatStatus(status);
|
|
426
432
|
console.log(` ${id} status updated: ${fromBadge} -> ${toBadge}`);
|
|
427
433
|
} catch (e) {
|
|
@@ -442,21 +448,9 @@ async function docDeleteCommand(dt, id, opts) {
|
|
|
442
448
|
const ns = getNs(client, dt.nsKey);
|
|
443
449
|
try {
|
|
444
450
|
const doc = await ns.getById({ id });
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
const answer = await new Promise((resolve) => {
|
|
449
|
-
rl.question(
|
|
450
|
-
` Delete ${docNum} (${doc.partyName ?? ""}, ${doc.totalAmount ?? ""})? (y/N): `,
|
|
451
|
-
resolve
|
|
452
|
-
);
|
|
453
|
-
});
|
|
454
|
-
rl.close();
|
|
455
|
-
if (answer.trim().toLowerCase() !== "y") {
|
|
456
|
-
console.log(" Cancelled.");
|
|
457
|
-
process.exit(0);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
451
|
+
if (!doc) fatalError(`${dt.label} not found: ${id}`, EXIT.NOT_FOUND);
|
|
452
|
+
const docNum = doc.invoiceNumber;
|
|
453
|
+
await confirmOrExit(` Delete ${docNum} (${doc.party?.name ?? ""}, ${doc.totalAmount})?`, opts);
|
|
460
454
|
const result = await ns.delete({ id });
|
|
461
455
|
if (opts.json) {
|
|
462
456
|
outputJSON(result);
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
import {
|
|
3
3
|
HisaaboApiError,
|
|
4
4
|
HisaaboClient
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-VXEEFNIY.js";
|
|
6
6
|
import {
|
|
7
7
|
requireAuth
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ESX7V56A.js";
|
|
9
9
|
import {
|
|
10
10
|
EXIT,
|
|
11
11
|
fatalError,
|
|
12
12
|
hasColor,
|
|
13
13
|
outputJSON
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-2DDIXPNI.js";
|
|
15
15
|
|
|
16
16
|
// src/commands/business/get.ts
|
|
17
17
|
import chalk from "chalk";
|
|
@@ -19,7 +19,8 @@ async function businessGetCommand(opts) {
|
|
|
19
19
|
const cfg = requireAuth();
|
|
20
20
|
const client = new HisaaboClient(cfg);
|
|
21
21
|
try {
|
|
22
|
-
const biz = await client.business.get();
|
|
22
|
+
const biz = await client.business.get(cfg.businessId);
|
|
23
|
+
if (!biz) fatalError(`Business not found: ${cfg.businessId}`, EXIT.NOT_FOUND);
|
|
23
24
|
if (opts.json) {
|
|
24
25
|
outputJSON(biz);
|
|
25
26
|
return;
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
import {
|
|
3
3
|
formatDate,
|
|
4
4
|
formatINR
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-M7DVLVD5.js";
|
|
6
6
|
import {
|
|
7
7
|
HisaaboApiError,
|
|
8
8
|
HisaaboClient
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-VXEEFNIY.js";
|
|
10
10
|
import {
|
|
11
11
|
requireAuth
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-ESX7V56A.js";
|
|
13
13
|
import {
|
|
14
14
|
EXIT,
|
|
15
15
|
fatalError,
|
|
16
16
|
outputJSON
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-2DDIXPNI.js";
|
|
18
18
|
|
|
19
19
|
// src/commands/payment/get.ts
|
|
20
20
|
async function paymentGetCommand(id, opts) {
|