@hisaabo/cli 0.1.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/.turbo/turbo-build.log +13 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/CLI-UX-ARCHITECTURE.md +1269 -0
- package/dist/bin/hisaabo.js +3516 -0
- package/package.json +34 -0
- package/src/auth.ts +212 -0
- package/src/bin/hisaabo.ts +950 -0
- package/src/client.ts +1229 -0
- package/src/commands/bank/index.ts +244 -0
- package/src/commands/dashboard.ts +105 -0
- package/src/commands/expense/create.ts +51 -0
- package/src/commands/expense/delete.ts +45 -0
- package/src/commands/expense/list.ts +65 -0
- package/src/commands/gst/index.ts +116 -0
- package/src/commands/import/index.ts +100 -0
- package/src/commands/invoice/create.ts +262 -0
- package/src/commands/invoice/delete.ts +44 -0
- package/src/commands/invoice/get.ts +105 -0
- package/src/commands/invoice/list.ts +126 -0
- package/src/commands/invoice/pdf.ts +75 -0
- package/src/commands/invoice/status.ts +41 -0
- package/src/commands/item/create.ts +98 -0
- package/src/commands/item/delete.ts +44 -0
- package/src/commands/item/list.ts +81 -0
- package/src/commands/item/stock.ts +46 -0
- package/src/commands/party/create.ts +88 -0
- package/src/commands/party/delete.ts +44 -0
- package/src/commands/party/get.ts +42 -0
- package/src/commands/party/ledger.ts +63 -0
- package/src/commands/party/list.ts +69 -0
- package/src/commands/payment/create.ts +133 -0
- package/src/commands/payment/delete.ts +46 -0
- package/src/commands/payment/list.ts +66 -0
- package/src/commands/report/index.ts +218 -0
- package/src/commands/shipment/index.ts +170 -0
- package/src/commands/store/index.ts +77 -0
- package/src/commands/target/index.ts +118 -0
- package/src/components/ErrorDisplay.tsx +16 -0
- package/src/components/Header.tsx +26 -0
- package/src/components/MoneyCell.tsx +16 -0
- package/src/components/Spinner.tsx +12 -0
- package/src/components/StatusBadge.tsx +39 -0
- package/src/components/Table.tsx +63 -0
- package/src/config.ts +47 -0
- package/src/format.ts +180 -0
- package/src/output.ts +227 -0
- package/tsconfig.json +22 -0
- package/tsup.config.ts +13 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError, type PartySummary } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import {
|
|
4
|
+
fatalError, outputJSON, outputTable, outputTSV, outputCSV, outputIds,
|
|
5
|
+
paginationFooter, EXIT, type ColumnDef,
|
|
6
|
+
} from "../../output.js";
|
|
7
|
+
import { formatAmount } from "../../format.js";
|
|
8
|
+
|
|
9
|
+
interface ListOpts {
|
|
10
|
+
json?: boolean;
|
|
11
|
+
format?: string;
|
|
12
|
+
type?: string;
|
|
13
|
+
search?: string;
|
|
14
|
+
category?: string;
|
|
15
|
+
page?: number;
|
|
16
|
+
limit?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function partyListCommand(opts: ListOpts): Promise<void> {
|
|
20
|
+
const cfg = requireAuth();
|
|
21
|
+
const client = new HisaaboClient(cfg);
|
|
22
|
+
const page = opts.page ?? 1;
|
|
23
|
+
const limit = opts.limit ?? 20;
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const result = await client.party.list({
|
|
27
|
+
type: opts.type as "customer" | "supplier" | undefined ?? null,
|
|
28
|
+
search: opts.search ?? null,
|
|
29
|
+
category: opts.category ?? null,
|
|
30
|
+
page,
|
|
31
|
+
limit,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (opts.json) {
|
|
35
|
+
outputJSON({
|
|
36
|
+
data: result.data,
|
|
37
|
+
pagination: { page: result.page, limit: result.limit, total: result.total },
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const typeLabel = opts.type === "supplier" ? "Suppliers" : opts.type === "customer" ? "Customers" : "Parties";
|
|
43
|
+
console.log(`\n ${typeLabel}` + " ".repeat(40) + `${result.total} total\n`);
|
|
44
|
+
|
|
45
|
+
const cols: ColumnDef<PartySummary>[] = [
|
|
46
|
+
{ key: "name", header: "Name", width: 22 },
|
|
47
|
+
{ key: "phone", header: "Phone", width: 16, format: (v) => String(v ?? "-") },
|
|
48
|
+
{ key: "balance", header: "Balance (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
49
|
+
{ key: "gstin", header: "GSTIN", width: 16, format: (v) => String(v ?? "-") },
|
|
50
|
+
{ key: "category", header: "Category", width: 14, format: (v) => String(v ?? "-") },
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
if (opts.format === "tsv") outputTSV(result.data, cols);
|
|
54
|
+
else if (opts.format === "csv") outputCSV(result.data, cols);
|
|
55
|
+
else if (opts.format === "ids") outputIds(result.data.map((r) => r.id));
|
|
56
|
+
else {
|
|
57
|
+
outputTable(result.data, cols);
|
|
58
|
+
paginationFooter(result.page, result.limit, result.total);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
} catch (e) {
|
|
62
|
+
if (e instanceof HisaaboApiError) {
|
|
63
|
+
const err = e.hisaaboError;
|
|
64
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
65
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
66
|
+
}
|
|
67
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import * as readline from "readline";
|
|
2
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
3
|
+
import { requireAuth } from "../../config.js";
|
|
4
|
+
import { fatalError, outputJSON, EXIT, success } from "../../output.js";
|
|
5
|
+
import { formatINR, formatAmount, todayISO } from "../../format.js";
|
|
6
|
+
|
|
7
|
+
interface CreateOpts {
|
|
8
|
+
json?: boolean;
|
|
9
|
+
partyId?: string;
|
|
10
|
+
party?: string;
|
|
11
|
+
amount?: string;
|
|
12
|
+
mode?: string;
|
|
13
|
+
invoiceId?: string;
|
|
14
|
+
reference?: string;
|
|
15
|
+
date?: string;
|
|
16
|
+
notes?: string;
|
|
17
|
+
yes?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function prompt(rl: readline.Interface, q: string): Promise<string> {
|
|
21
|
+
return new Promise((resolve) => rl.question(q, resolve));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function paymentCreateCommand(opts: CreateOpts): Promise<void> {
|
|
25
|
+
const cfg = requireAuth();
|
|
26
|
+
const client = new HisaaboClient(cfg);
|
|
27
|
+
const isNonInteractive = !process.stdin.isTTY || opts.yes;
|
|
28
|
+
|
|
29
|
+
let partyId = opts.partyId;
|
|
30
|
+
let amount = opts.amount;
|
|
31
|
+
let mode = opts.mode as "cash" | "bank" | "upi" | "cheque" | "other" | undefined;
|
|
32
|
+
let referenceNumber = opts.reference;
|
|
33
|
+
let paymentDate = opts.date ?? todayISO();
|
|
34
|
+
let notes = opts.notes;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
if (!isNonInteractive) {
|
|
38
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
39
|
+
console.log("\n Record Payment\n " + "─".repeat(30) + "\n");
|
|
40
|
+
|
|
41
|
+
if (!partyId) {
|
|
42
|
+
const search = await prompt(rl, " Select Party:\n > Search: ");
|
|
43
|
+
const parties = await client.party.list({ search: search.trim(), limit: 5 });
|
|
44
|
+
if (parties.data.length === 0) { rl.close(); fatalError("No parties found.", EXIT.NOT_FOUND); }
|
|
45
|
+
|
|
46
|
+
parties.data.forEach((p, i) => {
|
|
47
|
+
const bal = parseFloat(p.balance);
|
|
48
|
+
const balStr = `Balance: ${formatINR(p.balance)} ${bal >= 0 ? "receivable" : "payable"}`;
|
|
49
|
+
console.log(` ${i + 1} ${p.name.padEnd(20)} ${balStr}`);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const choice = await prompt(rl, "\n Party [1]: ");
|
|
53
|
+
const idx = parseInt(choice.trim() || "1", 10) - 1;
|
|
54
|
+
const selected = parties.data[Math.max(0, Math.min(idx, parties.data.length - 1))];
|
|
55
|
+
if (!selected) { rl.close(); fatalError("Invalid selection.", EXIT.USAGE); }
|
|
56
|
+
partyId = selected.id;
|
|
57
|
+
console.log(`\n Party: ${selected.name}\n`);
|
|
58
|
+
|
|
59
|
+
// Show unpaid invoices
|
|
60
|
+
const invoices = await client.invoice.list({ partyId, status: "sent", limit: 10 });
|
|
61
|
+
const partial = await client.invoice.list({ partyId, status: "partial", limit: 10 });
|
|
62
|
+
const unpaid = [...invoices.data, ...partial.data];
|
|
63
|
+
|
|
64
|
+
if (unpaid.length > 0) {
|
|
65
|
+
console.log(" Unpaid Invoices:");
|
|
66
|
+
console.log(" " + "─".repeat(65));
|
|
67
|
+
unpaid.forEach((inv, i) => {
|
|
68
|
+
console.log(` ${i + 1} ${inv.invoiceNumber.padEnd(12)} ${inv.totalAmount.padStart(12)} due ${inv.status}`);
|
|
69
|
+
});
|
|
70
|
+
console.log();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!amount) {
|
|
74
|
+
const amtStr = await prompt(rl, " Amount: ");
|
|
75
|
+
amount = amtStr.trim();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const modeStr = await prompt(rl, " Mode (cash/bank/upi/cheque/other) [upi]: ");
|
|
79
|
+
mode = (modeStr.trim() || "upi") as typeof mode;
|
|
80
|
+
|
|
81
|
+
const refStr = await prompt(rl, " Reference Number: ");
|
|
82
|
+
if (refStr.trim()) referenceNumber = refStr.trim();
|
|
83
|
+
|
|
84
|
+
const dateStr = await prompt(rl, ` Payment Date [${todayISO()}]: `);
|
|
85
|
+
if (dateStr.trim()) paymentDate = dateStr.trim();
|
|
86
|
+
|
|
87
|
+
const notesStr = await prompt(rl, " Notes: ");
|
|
88
|
+
if (notesStr.trim()) notes = notesStr.trim();
|
|
89
|
+
|
|
90
|
+
console.log(`\n Total Payment: ${formatAmount(amount ?? "0")}`);
|
|
91
|
+
const confirm = await prompt(rl, "\n Record this payment? (y/n) [y]: ");
|
|
92
|
+
rl.close();
|
|
93
|
+
|
|
94
|
+
if (confirm.trim().toLowerCase() === "n") {
|
|
95
|
+
console.log(" Cancelled.");
|
|
96
|
+
process.exit(0);
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
rl.close();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!partyId) fatalError("--party-id is required", EXIT.USAGE);
|
|
104
|
+
if (!amount) fatalError("--amount is required", EXIT.USAGE);
|
|
105
|
+
if (!mode) mode = "cash";
|
|
106
|
+
|
|
107
|
+
const payment = await client.payment.create({
|
|
108
|
+
partyId,
|
|
109
|
+
amount,
|
|
110
|
+
mode,
|
|
111
|
+
referenceNumber,
|
|
112
|
+
paymentDate,
|
|
113
|
+
notes,
|
|
114
|
+
invoiceId: opts.invoiceId,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (opts.json) {
|
|
118
|
+
outputJSON(payment);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
success(`Recorded: ${payment.paymentNumber} for ${formatINR(payment.amount)}`);
|
|
123
|
+
|
|
124
|
+
} catch (e) {
|
|
125
|
+
if (e instanceof HisaaboApiError) {
|
|
126
|
+
const err = e.hisaaboError;
|
|
127
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
128
|
+
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
129
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
130
|
+
}
|
|
131
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as readline from "readline";
|
|
2
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
3
|
+
import { requireAuth } from "../../config.js";
|
|
4
|
+
import { fatalError, outputJSON, EXIT, success } from "../../output.js";
|
|
5
|
+
import { formatINR } from "../../format.js";
|
|
6
|
+
|
|
7
|
+
export async function paymentDeleteCommand(id: string, opts: { yes?: boolean; json?: boolean }): Promise<void> {
|
|
8
|
+
const cfg = requireAuth();
|
|
9
|
+
const client = new HisaaboClient(cfg);
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const payment = await client.payment.getById(id);
|
|
13
|
+
if (!payment) fatalError(`Payment not found: ${id}`, EXIT.NOT_FOUND);
|
|
14
|
+
|
|
15
|
+
if (!opts.yes && process.stdin.isTTY) {
|
|
16
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
17
|
+
const answer = await new Promise<string>((resolve) => {
|
|
18
|
+
rl.question(` Delete ${payment!.paymentNumber} (${formatINR(payment!.amount)})? (y/N): `, resolve);
|
|
19
|
+
});
|
|
20
|
+
rl.close();
|
|
21
|
+
if (answer.trim().toLowerCase() !== "y") {
|
|
22
|
+
console.log(" Cancelled.");
|
|
23
|
+
process.exit(0);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const result = await client.payment.delete(id);
|
|
28
|
+
|
|
29
|
+
if (opts.json) {
|
|
30
|
+
outputJSON(result);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
success(`Deleted: ${payment!.paymentNumber}`);
|
|
35
|
+
|
|
36
|
+
} catch (e) {
|
|
37
|
+
if (e instanceof HisaaboApiError) {
|
|
38
|
+
const err = e.hisaaboError;
|
|
39
|
+
if (err.code === "not_found") fatalError(`Payment not found: ${id}`, EXIT.NOT_FOUND);
|
|
40
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
41
|
+
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
42
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
43
|
+
}
|
|
44
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError, type PaymentSummary } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import {
|
|
4
|
+
fatalError, outputJSON, outputTable, outputTSV, outputCSV, outputIds,
|
|
5
|
+
paginationFooter, EXIT, type ColumnDef,
|
|
6
|
+
} from "../../output.js";
|
|
7
|
+
import { formatAmount, formatDate } from "../../format.js";
|
|
8
|
+
|
|
9
|
+
interface ListOpts {
|
|
10
|
+
json?: boolean;
|
|
11
|
+
format?: string;
|
|
12
|
+
partyId?: string;
|
|
13
|
+
from?: string;
|
|
14
|
+
to?: string;
|
|
15
|
+
page?: number;
|
|
16
|
+
limit?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function paymentListCommand(opts: ListOpts): Promise<void> {
|
|
20
|
+
const cfg = requireAuth();
|
|
21
|
+
const client = new HisaaboClient(cfg);
|
|
22
|
+
const page = opts.page ?? 1;
|
|
23
|
+
const limit = opts.limit ?? 20;
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const result = await client.payment.list({
|
|
27
|
+
partyId: opts.partyId ?? null,
|
|
28
|
+
fromDate: opts.from ?? null,
|
|
29
|
+
toDate: opts.to ?? null,
|
|
30
|
+
page,
|
|
31
|
+
limit,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (opts.json) {
|
|
35
|
+
outputJSON({ data: result.data, pagination: { page: result.page, limit: result.limit, total: result.total } });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log(`\n Payments ${result.total} total\n`);
|
|
40
|
+
|
|
41
|
+
const cols: ColumnDef<PaymentSummary>[] = [
|
|
42
|
+
{ key: "paymentNumber", header: "#", width: 10 },
|
|
43
|
+
{ key: "partyName", header: "Party", width: 20 },
|
|
44
|
+
{ key: "paymentDate", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
|
|
45
|
+
{ key: "amount", header: "Amount (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
46
|
+
{ key: "mode", header: "Mode", width: 8 },
|
|
47
|
+
{ key: "referenceNumber", header: "Ref#", width: 14, format: (v) => String(v ?? "-") },
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
if (opts.format === "tsv") outputTSV(result.data, cols);
|
|
51
|
+
else if (opts.format === "csv") outputCSV(result.data, cols);
|
|
52
|
+
else if (opts.format === "ids") outputIds(result.data.map((r) => r.id));
|
|
53
|
+
else {
|
|
54
|
+
outputTable(result.data, cols);
|
|
55
|
+
paginationFooter(result.page, result.limit, result.total);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
} catch (e) {
|
|
59
|
+
if (e instanceof HisaaboApiError) {
|
|
60
|
+
const err = e.hisaaboError;
|
|
61
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
62
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
63
|
+
}
|
|
64
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError, type DaybookEntry } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import {
|
|
4
|
+
fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, type ColumnDef,
|
|
5
|
+
} from "../../output.js";
|
|
6
|
+
import { formatAmount, formatDate, todayISO, fyStart, monthStart, monthEnd } from "../../format.js";
|
|
7
|
+
|
|
8
|
+
interface ReportOpts {
|
|
9
|
+
json?: boolean;
|
|
10
|
+
format?: string;
|
|
11
|
+
from?: string;
|
|
12
|
+
to?: string;
|
|
13
|
+
thisMonth?: boolean;
|
|
14
|
+
thisFy?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function resolveRange(opts: ReportOpts): { from: string; to: string } {
|
|
18
|
+
if (opts.thisFy) return { from: fyStart(), to: todayISO() };
|
|
19
|
+
if (opts.thisMonth) return { from: monthStart(), to: monthEnd() };
|
|
20
|
+
return { from: opts.from ?? fyStart(), to: opts.to ?? todayISO() };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function reportDaybookCommand(opts: ReportOpts): Promise<void> {
|
|
24
|
+
const cfg = requireAuth();
|
|
25
|
+
const client = new HisaaboClient(cfg);
|
|
26
|
+
const { from, to } = resolveRange(opts);
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const result = await client.reports.daybook({ fromDate: from, toDate: to });
|
|
30
|
+
|
|
31
|
+
if (opts.json) {
|
|
32
|
+
outputJSON(result);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.log(`\n Daybook Report ${from} → ${to}\n`);
|
|
37
|
+
console.log(` ${"═".repeat(70)}\n`);
|
|
38
|
+
|
|
39
|
+
const cols: ColumnDef<DaybookEntry>[] = [
|
|
40
|
+
{ key: "time", header: "Time", width: 20, format: (v) => formatDate(String(v ?? "")) },
|
|
41
|
+
{ key: "entryType", header: "Type", width: 10 },
|
|
42
|
+
{ key: "number", header: "#", width: 12, format: (v) => String(v ?? "-") },
|
|
43
|
+
{ key: "partyOrCategory", header: "Party / Category", width: 22 },
|
|
44
|
+
{ key: "debit", header: "Debit (₹)", align: "right", width: 13, format: (v) => parseFloat(String(v ?? "0")) !== 0 ? formatAmount(String(v)) : "-" },
|
|
45
|
+
{ key: "credit", header: "Credit (₹)", align: "right", width: 13, format: (v) => parseFloat(String(v ?? "0")) !== 0 ? formatAmount(String(v)) : "-" },
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
if (opts.format === "tsv") outputTSV(result.entries, cols);
|
|
49
|
+
else if (opts.format === "csv") outputCSV(result.entries, cols);
|
|
50
|
+
else {
|
|
51
|
+
outputTable(result.entries, cols);
|
|
52
|
+
|
|
53
|
+
const s = result.summary;
|
|
54
|
+
console.log(`\n Sales Invoiced: ${formatAmount(s.totalSalesInvoiced).padStart(14)}`);
|
|
55
|
+
console.log(` Purchases Invoiced: ${formatAmount(s.totalPurchaseInvoiced).padStart(14)}`);
|
|
56
|
+
console.log(` Payments Received: ${formatAmount(s.totalPaymentsReceived).padStart(14)}`);
|
|
57
|
+
console.log(` Payments Made: ${formatAmount(s.totalPaymentsMade).padStart(14)}`);
|
|
58
|
+
console.log(` Expenses: ${formatAmount(s.totalExpenses).padStart(14)}`);
|
|
59
|
+
console.log(` Net Cash Movement: ${formatAmount(s.netCashMovement).padStart(14)}\n`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
} catch (e) {
|
|
63
|
+
if (e instanceof HisaaboApiError) {
|
|
64
|
+
const err = e.hisaaboError;
|
|
65
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
66
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
67
|
+
}
|
|
68
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function reportOutstandingCommand(opts: ReportOpts & { type?: string }): Promise<void> {
|
|
73
|
+
const cfg = requireAuth();
|
|
74
|
+
const client = new HisaaboClient(cfg);
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const result = await client.reports.outstanding({
|
|
78
|
+
type: opts.type as "receivable" | "payable" | "both" | undefined ?? "both",
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (opts.json) {
|
|
82
|
+
outputJSON(result);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log("\n Outstanding Report\n");
|
|
87
|
+
console.log(" " + "═".repeat(60) + "\n");
|
|
88
|
+
|
|
89
|
+
if (result.receivables && Array.isArray(result.receivables)) {
|
|
90
|
+
console.log(" Receivables:");
|
|
91
|
+
(result.receivables as Array<Record<string, unknown>>).forEach((row) => {
|
|
92
|
+
console.log(` ${String(row["partyName"] ?? "").padEnd(25)} ${formatAmount(String(row["balance"] ?? "0")).padStart(14)}`);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (result.payables && Array.isArray(result.payables)) {
|
|
96
|
+
console.log("\n Payables:");
|
|
97
|
+
(result.payables as Array<Record<string, unknown>>).forEach((row) => {
|
|
98
|
+
console.log(` ${String(row["partyName"] ?? "").padEnd(25)} ${formatAmount(String(row["balance"] ?? "0")).padStart(14)}`);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
console.log();
|
|
102
|
+
|
|
103
|
+
} catch (e) {
|
|
104
|
+
if (e instanceof HisaaboApiError) {
|
|
105
|
+
const err = e.hisaaboError;
|
|
106
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
107
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
108
|
+
}
|
|
109
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function reportTaxSummaryCommand(opts: ReportOpts): Promise<void> {
|
|
114
|
+
const cfg = requireAuth();
|
|
115
|
+
const client = new HisaaboClient(cfg);
|
|
116
|
+
const { from, to } = resolveRange(opts);
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const result = await client.reports.taxSummary({ fromDate: from, toDate: to });
|
|
120
|
+
|
|
121
|
+
if (opts.json) {
|
|
122
|
+
outputJSON(result);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
console.log(`\n Tax Summary ${from} → ${to}\n`);
|
|
127
|
+
console.log(" " + "═".repeat(60) + "\n");
|
|
128
|
+
|
|
129
|
+
if (Array.isArray(result.rows)) {
|
|
130
|
+
(result.rows as Array<Record<string, unknown>>).forEach((row) => {
|
|
131
|
+
const rate = String(row["taxPercent"] ?? row["rate"] ?? "-");
|
|
132
|
+
const taxable = formatAmount(String(row["taxableAmount"] ?? "0"));
|
|
133
|
+
const tax = formatAmount(String(row["taxAmount"] ?? "0"));
|
|
134
|
+
console.log(` ${rate.padEnd(6)}% Taxable: ${taxable.padStart(14)} Tax: ${tax.padStart(12)}`);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
console.log();
|
|
138
|
+
|
|
139
|
+
} catch (e) {
|
|
140
|
+
if (e instanceof HisaaboApiError) {
|
|
141
|
+
const err = e.hisaaboError;
|
|
142
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
143
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
144
|
+
}
|
|
145
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function reportItemSalesCommand(opts: ReportOpts): Promise<void> {
|
|
150
|
+
const cfg = requireAuth();
|
|
151
|
+
const client = new HisaaboClient(cfg);
|
|
152
|
+
const { from, to } = resolveRange(opts);
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
const result = await client.reports.itemSales({ fromDate: from, toDate: to });
|
|
156
|
+
|
|
157
|
+
if (opts.json) {
|
|
158
|
+
outputJSON(result);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
console.log(`\n Item Sales ${from} → ${to}\n`);
|
|
163
|
+
console.log(" " + "═".repeat(70) + "\n");
|
|
164
|
+
|
|
165
|
+
if (Array.isArray(result.rows)) {
|
|
166
|
+
(result.rows as Array<Record<string, unknown>>).slice(0, 50).forEach((row) => {
|
|
167
|
+
const name = String(row["itemName"] ?? row["name"] ?? "-").padEnd(25);
|
|
168
|
+
const qty = String(row["totalQuantity"] ?? row["qty"] ?? "-").padStart(8);
|
|
169
|
+
const rev = formatAmount(String(row["totalRevenue"] ?? row["revenue"] ?? "0")).padStart(14);
|
|
170
|
+
console.log(` ${name} ${qty} ${rev}`);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
console.log();
|
|
174
|
+
|
|
175
|
+
} catch (e) {
|
|
176
|
+
if (e instanceof HisaaboApiError) {
|
|
177
|
+
const err = e.hisaaboError;
|
|
178
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
179
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
180
|
+
}
|
|
181
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function reportStockSummaryCommand(opts: { json?: boolean; category?: string }): Promise<void> {
|
|
186
|
+
const cfg = requireAuth();
|
|
187
|
+
const client = new HisaaboClient(cfg);
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
const result = await client.reports.stockSummary({ category: opts.category });
|
|
191
|
+
|
|
192
|
+
if (opts.json) {
|
|
193
|
+
outputJSON(result);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
console.log("\n Stock Summary\n");
|
|
198
|
+
console.log(" " + "═".repeat(60) + "\n");
|
|
199
|
+
|
|
200
|
+
if (Array.isArray(result.rows)) {
|
|
201
|
+
(result.rows as Array<Record<string, unknown>>).forEach((row) => {
|
|
202
|
+
const name = String(row["itemName"] ?? row["name"] ?? "-").padEnd(25);
|
|
203
|
+
const stock = String(row["stockQuantity"] ?? row["stock"] ?? "-").padStart(10);
|
|
204
|
+
const val = formatAmount(String(row["stockValue"] ?? row["value"] ?? "0")).padStart(14);
|
|
205
|
+
console.log(` ${name} ${stock} ${val}`);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
console.log();
|
|
209
|
+
|
|
210
|
+
} catch (e) {
|
|
211
|
+
if (e instanceof HisaaboApiError) {
|
|
212
|
+
const err = e.hisaaboError;
|
|
213
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
214
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
215
|
+
}
|
|
216
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
217
|
+
}
|
|
218
|
+
}
|