@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,244 @@
|
|
|
1
|
+
import * as readline from "readline";
|
|
2
|
+
import { HisaaboClient, HisaaboApiError, type BankAccountSummary, type BankTransactionRow } from "../../client.js";
|
|
3
|
+
import { requireAuth } from "../../config.js";
|
|
4
|
+
import {
|
|
5
|
+
fatalError, outputJSON, outputTable, paginationFooter, EXIT, success, type ColumnDef,
|
|
6
|
+
} from "../../output.js";
|
|
7
|
+
import { formatAmount, formatDate, formatINR } from "../../format.js";
|
|
8
|
+
|
|
9
|
+
async function prompt(rl: readline.Interface, q: string): Promise<string> {
|
|
10
|
+
return new Promise((resolve) => rl.question(q, resolve));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function bankListCommand(opts: { json?: boolean }): Promise<void> {
|
|
14
|
+
const cfg = requireAuth();
|
|
15
|
+
const client = new HisaaboClient(cfg);
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const [accounts, summary] = await Promise.all([
|
|
19
|
+
client.bankAccount.list(),
|
|
20
|
+
client.bankAccount.summary(),
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
if (opts.json) {
|
|
24
|
+
outputJSON({ accounts, summary });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
console.log("\n Bank Accounts\n");
|
|
29
|
+
console.log(` ${"═".repeat(60)}\n`);
|
|
30
|
+
|
|
31
|
+
const cols: ColumnDef<BankAccountSummary>[] = [
|
|
32
|
+
{ key: "accountName", header: "Name", width: 22 },
|
|
33
|
+
{ key: "bankName", header: "Bank", width: 16, format: (v) => String(v ?? "-") },
|
|
34
|
+
{ key: "accountType", header: "Type", width: 10 },
|
|
35
|
+
{ key: "accountNumber", header: "Account #", width: 16, format: (v) => String(v ?? "-") },
|
|
36
|
+
{ key: "currentBalance", header: "Balance (₹)", align: "right", width: 14, format: (v) => formatAmount(String(v ?? "0")) },
|
|
37
|
+
{ key: "isDefault", header: "Default", width: 8, format: (v) => v ? "Yes" : "" },
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
outputTable(accounts, cols);
|
|
41
|
+
console.log(`\n Total Balance: ${formatINR(summary.totalBalance)}`);
|
|
42
|
+
console.log(` Cash in Hand: ${formatINR(summary.cashInHand)}`);
|
|
43
|
+
console.log(` Bank Balance: ${formatINR(summary.bankBalance)}\n`);
|
|
44
|
+
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if (e instanceof HisaaboApiError) {
|
|
47
|
+
const err = e.hisaaboError;
|
|
48
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
49
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
50
|
+
}
|
|
51
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function bankGetCommand(id: string, opts: { json?: boolean }): Promise<void> {
|
|
56
|
+
const cfg = requireAuth();
|
|
57
|
+
const client = new HisaaboClient(cfg);
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const account = await client.bankAccount.get(id);
|
|
61
|
+
if (!account) fatalError(`Bank account not found: ${id}`, EXIT.NOT_FOUND);
|
|
62
|
+
|
|
63
|
+
if (opts.json) {
|
|
64
|
+
outputJSON(account);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
console.log(`\n ${account!.accountName} (${account!.accountType})`);
|
|
69
|
+
console.log(" " + "─".repeat(45));
|
|
70
|
+
if (account!.bankName) console.log(` Bank: ${account!.bankName}`);
|
|
71
|
+
if (account!.accountNumber) console.log(` Account: ${account!.accountNumber}`);
|
|
72
|
+
if (account!.ifsc) console.log(` IFSC: ${account!.ifsc}`);
|
|
73
|
+
console.log(` Balance: ${formatINR(account!.currentBalance)}`);
|
|
74
|
+
console.log();
|
|
75
|
+
|
|
76
|
+
} catch (e) {
|
|
77
|
+
if (e instanceof HisaaboApiError) {
|
|
78
|
+
const err = e.hisaaboError;
|
|
79
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
80
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
81
|
+
}
|
|
82
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function bankCreateCommand(opts: {
|
|
87
|
+
json?: boolean;
|
|
88
|
+
name?: string;
|
|
89
|
+
type?: string;
|
|
90
|
+
bank?: string;
|
|
91
|
+
accountNumber?: string;
|
|
92
|
+
ifsc?: string;
|
|
93
|
+
openingBalance?: string;
|
|
94
|
+
default?: boolean;
|
|
95
|
+
yes?: boolean;
|
|
96
|
+
}): Promise<void> {
|
|
97
|
+
const cfg = requireAuth();
|
|
98
|
+
const client = new HisaaboClient(cfg);
|
|
99
|
+
const isNonInteractive = !process.stdin.isTTY || opts.yes;
|
|
100
|
+
|
|
101
|
+
let name = opts.name;
|
|
102
|
+
let accountType = (opts.type ?? "current") as "savings" | "current" | "cash" | "credit" | "other";
|
|
103
|
+
let bankName = opts.bank;
|
|
104
|
+
let accountNumber = opts.accountNumber;
|
|
105
|
+
let ifsc = opts.ifsc;
|
|
106
|
+
let openingBalance = opts.openingBalance;
|
|
107
|
+
|
|
108
|
+
if (!isNonInteractive) {
|
|
109
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
110
|
+
if (!name) name = (await prompt(rl, " Account Name: ")).trim();
|
|
111
|
+
const typeStr = await prompt(rl, " Type (savings/current/cash/credit/other) [current]: ");
|
|
112
|
+
accountType = (typeStr.trim() || "current") as typeof accountType;
|
|
113
|
+
const bankStr = await prompt(rl, " Bank Name: ");
|
|
114
|
+
if (bankStr.trim()) bankName = bankStr.trim();
|
|
115
|
+
const numStr = await prompt(rl, " Account Number: ");
|
|
116
|
+
if (numStr.trim()) accountNumber = numStr.trim();
|
|
117
|
+
const ifscStr = await prompt(rl, " IFSC: ");
|
|
118
|
+
if (ifscStr.trim()) ifsc = ifscStr.trim();
|
|
119
|
+
const balStr = await prompt(rl, " Opening Balance [0]: ");
|
|
120
|
+
openingBalance = balStr.trim() || "0";
|
|
121
|
+
rl.close();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!name) fatalError("--name is required", EXIT.USAGE);
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
const account = await client.bankAccount.create({
|
|
128
|
+
accountName: name,
|
|
129
|
+
accountType,
|
|
130
|
+
bankName,
|
|
131
|
+
accountNumber,
|
|
132
|
+
ifsc,
|
|
133
|
+
openingBalance,
|
|
134
|
+
isDefault: opts.default,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
if (opts.json) {
|
|
138
|
+
outputJSON(account);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
success(`Created: ${account.accountName}`);
|
|
143
|
+
console.log(` ID: ${account.id}\n`);
|
|
144
|
+
|
|
145
|
+
} catch (e) {
|
|
146
|
+
if (e instanceof HisaaboApiError) {
|
|
147
|
+
const err = e.hisaaboError;
|
|
148
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
149
|
+
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
150
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
151
|
+
}
|
|
152
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export async function bankTransferCommand(opts: {
|
|
157
|
+
json?: boolean;
|
|
158
|
+
from?: string;
|
|
159
|
+
to?: string;
|
|
160
|
+
amount?: string;
|
|
161
|
+
description?: string;
|
|
162
|
+
date?: string;
|
|
163
|
+
}): Promise<void> {
|
|
164
|
+
const cfg = requireAuth();
|
|
165
|
+
const client = new HisaaboClient(cfg);
|
|
166
|
+
|
|
167
|
+
if (!opts.from) fatalError("--from account ID is required", EXIT.USAGE);
|
|
168
|
+
if (!opts.to) fatalError("--to account ID is required", EXIT.USAGE);
|
|
169
|
+
if (!opts.amount) fatalError("--amount is required", EXIT.USAGE);
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
const result = await client.bankAccount.transfer({
|
|
173
|
+
fromAccountId: opts.from,
|
|
174
|
+
toAccountId: opts.to,
|
|
175
|
+
amount: opts.amount,
|
|
176
|
+
description: opts.description,
|
|
177
|
+
transactionDate: opts.date,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
if (opts.json) {
|
|
181
|
+
outputJSON(result);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
success(`Transfer recorded: ${formatINR(opts.amount)}`);
|
|
186
|
+
|
|
187
|
+
} catch (e) {
|
|
188
|
+
if (e instanceof HisaaboApiError) {
|
|
189
|
+
const err = e.hisaaboError;
|
|
190
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
191
|
+
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
192
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
193
|
+
}
|
|
194
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export async function bankTransactionsCommand(accountId: string, opts: {
|
|
199
|
+
json?: boolean;
|
|
200
|
+
from?: string;
|
|
201
|
+
to?: string;
|
|
202
|
+
page?: number;
|
|
203
|
+
limit?: number;
|
|
204
|
+
}): Promise<void> {
|
|
205
|
+
const cfg = requireAuth();
|
|
206
|
+
const client = new HisaaboClient(cfg);
|
|
207
|
+
const page = opts.page ?? 1;
|
|
208
|
+
const limit = opts.limit ?? 20;
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
const result = await client.bankAccount.listTransactions({
|
|
212
|
+
bankAccountId: accountId,
|
|
213
|
+
fromDate: opts.from,
|
|
214
|
+
toDate: opts.to,
|
|
215
|
+
page,
|
|
216
|
+
limit,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
if (opts.json) {
|
|
220
|
+
outputJSON(result);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const cols: ColumnDef<BankTransactionRow>[] = [
|
|
225
|
+
{ key: "transactionDate", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
|
|
226
|
+
{ key: "type", header: "Type", width: 12 },
|
|
227
|
+
{ key: "description", header: "Description", width: 25, format: (v) => String(v ?? "-") },
|
|
228
|
+
{ key: "amount", header: "Amount (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
229
|
+
{ key: "balanceAfter", header: "Balance (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
230
|
+
];
|
|
231
|
+
|
|
232
|
+
console.log(`\n Transactions for ${accountId}\n`);
|
|
233
|
+
outputTable(result.data, cols);
|
|
234
|
+
paginationFooter(result.page, result.limit, result.total);
|
|
235
|
+
|
|
236
|
+
} catch (e) {
|
|
237
|
+
if (e instanceof HisaaboApiError) {
|
|
238
|
+
const err = e.hisaaboError;
|
|
239
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
240
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
241
|
+
}
|
|
242
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../client.js";
|
|
2
|
+
import { requireAuth } from "../config.js";
|
|
3
|
+
import { fatalError, outputJSON, EXIT, hasColor, termWidth } from "../output.js";
|
|
4
|
+
import { formatAmount, formatStatus, formatRelativeDate, currentFY, fyStart, todayISO } from "../format.js";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
|
|
7
|
+
function box(title: string, lines: string[], width: number): string[] {
|
|
8
|
+
const innerW = width - 2;
|
|
9
|
+
const titleStr = `─ ${title} `;
|
|
10
|
+
const border = "┌" + titleStr + "─".repeat(Math.max(1, innerW - titleStr.length)) + "┐";
|
|
11
|
+
const bottom = "└" + "─".repeat(innerW) + "┘";
|
|
12
|
+
const padded = lines.map((l) => {
|
|
13
|
+
const vis = l.length;
|
|
14
|
+
const pad = Math.max(0, innerW - vis - 1);
|
|
15
|
+
return "│ " + l + " ".repeat(pad) + "│";
|
|
16
|
+
});
|
|
17
|
+
return [border, ...padded, bottom];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function colorMoney(amount: string, good = true): string {
|
|
21
|
+
if (!hasColor()) return formatAmount(amount);
|
|
22
|
+
const num = parseFloat(amount);
|
|
23
|
+
if (isNaN(num) || num === 0) return chalk.dim(formatAmount(amount));
|
|
24
|
+
if (good) return chalk.green(formatAmount(amount));
|
|
25
|
+
return chalk.red(formatAmount(amount));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function dashboardCommand(opts: { json?: boolean }): Promise<void> {
|
|
29
|
+
const cfg = requireAuth();
|
|
30
|
+
const client = new HisaaboClient(cfg);
|
|
31
|
+
const from = fyStart();
|
|
32
|
+
const to = todayISO();
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const summary = await client.dashboard.summary({ fromDate: from, toDate: to });
|
|
36
|
+
|
|
37
|
+
if (opts.json) {
|
|
38
|
+
outputJSON(summary);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const width = Math.min(termWidth() - 2, 70);
|
|
43
|
+
const fy = currentFY();
|
|
44
|
+
|
|
45
|
+
console.log();
|
|
46
|
+
console.log(` Hisaabo Dashboard` + " ".repeat(Math.max(2, width - 30)) + (cfg.businessName ?? ""));
|
|
47
|
+
console.log(` FY ${fy} (01 Apr ${fy.split("-")[0]} - 31 Mar 20${fy.split("-")[1]})`);
|
|
48
|
+
console.log(` ${"═".repeat(width)}`);
|
|
49
|
+
console.log();
|
|
50
|
+
|
|
51
|
+
// Revenue / Expenses boxes
|
|
52
|
+
const halfW = Math.floor((width - 3) / 2);
|
|
53
|
+
const revLines = [
|
|
54
|
+
`Sales ${formatAmount(summary.totalSales).padStart(12)}`,
|
|
55
|
+
`Cash In ${formatAmount(summary.cashInHand).padStart(12)}`,
|
|
56
|
+
];
|
|
57
|
+
const expLines = [
|
|
58
|
+
`Purchases ${formatAmount(summary.totalPurchases).padStart(11)}`,
|
|
59
|
+
`Expenses ${formatAmount(summary.totalExpenses).padStart(11)}`,
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const revBox = box("Revenue", revLines, halfW);
|
|
63
|
+
const expBox = box("Expenses", expLines, halfW);
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < Math.max(revBox.length, expBox.length); i++) {
|
|
66
|
+
const l = (revBox[i] ?? "").padEnd(halfW);
|
|
67
|
+
const r = expBox[i] ?? "";
|
|
68
|
+
console.log(` ${l} ${r}`);
|
|
69
|
+
}
|
|
70
|
+
console.log();
|
|
71
|
+
|
|
72
|
+
// Outstanding box
|
|
73
|
+
const net = parseFloat(summary.receivable) - parseFloat(summary.payable);
|
|
74
|
+
const netLabel = net >= 0 ? "receivable" : "payable";
|
|
75
|
+
const outLines = [
|
|
76
|
+
`Receivable ${colorMoney(summary.receivable)}`,
|
|
77
|
+
`Payable ${colorMoney(summary.payable, false)}`,
|
|
78
|
+
`Net Position ${colorMoney(String(Math.abs(net)))} ${netLabel}`,
|
|
79
|
+
];
|
|
80
|
+
const outBox = box("Outstanding", outLines, width);
|
|
81
|
+
outBox.forEach((l) => console.log(` ${l}`));
|
|
82
|
+
console.log();
|
|
83
|
+
|
|
84
|
+
// Recent invoices box
|
|
85
|
+
const recentLines = summary.recentInvoices.slice(0, 5).map((inv) => {
|
|
86
|
+
const num = inv.invoiceNumber.padEnd(10);
|
|
87
|
+
const party = inv.partyName.slice(0, 16).padEnd(18);
|
|
88
|
+
const amt = formatAmount(inv.totalAmount).padStart(12);
|
|
89
|
+
const status = formatStatus(inv.status).padEnd(10);
|
|
90
|
+
const rel = formatRelativeDate(inv.invoiceDate).padEnd(7);
|
|
91
|
+
return `${num} ${party} ${amt} ${status} ${rel}`;
|
|
92
|
+
});
|
|
93
|
+
const recentBox = box("Recent Invoices", recentLines, width);
|
|
94
|
+
recentBox.forEach((l) => console.log(` ${l}`));
|
|
95
|
+
console.log();
|
|
96
|
+
|
|
97
|
+
} catch (e) {
|
|
98
|
+
if (e instanceof HisaaboApiError) {
|
|
99
|
+
const err = e.hisaaboError;
|
|
100
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
101
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
102
|
+
}
|
|
103
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, outputJSON, EXIT, success } from "../../output.js";
|
|
4
|
+
import { formatINR, todayISO } from "../../format.js";
|
|
5
|
+
|
|
6
|
+
interface CreateOpts {
|
|
7
|
+
json?: boolean;
|
|
8
|
+
category?: string;
|
|
9
|
+
amount?: string;
|
|
10
|
+
mode?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
date?: string;
|
|
13
|
+
reference?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function expenseCreateCommand(opts: CreateOpts): Promise<void> {
|
|
17
|
+
const cfg = requireAuth();
|
|
18
|
+
const client = new HisaaboClient(cfg);
|
|
19
|
+
|
|
20
|
+
if (!opts.category) fatalError("--category is required", EXIT.USAGE);
|
|
21
|
+
if (!opts.amount) fatalError("--amount is required", EXIT.USAGE);
|
|
22
|
+
|
|
23
|
+
const mode = (opts.mode ?? "cash") as "cash" | "bank" | "upi" | "cheque" | "other";
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const expense = await client.expense.create({
|
|
27
|
+
category: opts.category,
|
|
28
|
+
amount: opts.amount,
|
|
29
|
+
mode,
|
|
30
|
+
description: opts.description,
|
|
31
|
+
expenseDate: opts.date ?? todayISO(),
|
|
32
|
+
referenceNumber: opts.reference,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (opts.json) {
|
|
36
|
+
outputJSON(expense);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
success(`Created: ${expense.category} ${formatINR(expense.amount)}`);
|
|
41
|
+
|
|
42
|
+
} catch (e) {
|
|
43
|
+
if (e instanceof HisaaboApiError) {
|
|
44
|
+
const err = e.hisaaboError;
|
|
45
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
46
|
+
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
47
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
48
|
+
}
|
|
49
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as readline from "readline";
|
|
2
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
3
|
+
import { requireAuth } from "../../config.js";
|
|
4
|
+
import { fatalError, outputJSON, EXIT, success } from "../../output.js";
|
|
5
|
+
|
|
6
|
+
export async function expenseDeleteCommand(id: string, opts: { yes?: boolean; json?: boolean }): Promise<void> {
|
|
7
|
+
const cfg = requireAuth();
|
|
8
|
+
const client = new HisaaboClient(cfg);
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
// Fetch expense first
|
|
12
|
+
const _list = await client.expense.list({ page: 1, limit: 1 });
|
|
13
|
+
// We can't get by ID directly; use delete and check error
|
|
14
|
+
if (!opts.yes && process.stdin.isTTY) {
|
|
15
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
16
|
+
const answer = await new Promise<string>((resolve) => {
|
|
17
|
+
rl.question(` Delete expense ${id}? (y/N): `, resolve);
|
|
18
|
+
});
|
|
19
|
+
rl.close();
|
|
20
|
+
if (answer.trim().toLowerCase() !== "y") {
|
|
21
|
+
console.log(" Cancelled.");
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const result = await client.expense.delete(id);
|
|
27
|
+
|
|
28
|
+
if (opts.json) {
|
|
29
|
+
outputJSON(result);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
success(`Deleted expense: ${id}`);
|
|
34
|
+
|
|
35
|
+
} catch (e) {
|
|
36
|
+
if (e instanceof HisaaboApiError) {
|
|
37
|
+
const err = e.hisaaboError;
|
|
38
|
+
if (err.code === "not_found") fatalError(`Expense not found: ${id}`, EXIT.NOT_FOUND);
|
|
39
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
40
|
+
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
41
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
42
|
+
}
|
|
43
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError, type ExpenseSummary } 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
|
+
category?: string;
|
|
13
|
+
from?: string;
|
|
14
|
+
to?: string;
|
|
15
|
+
page?: number;
|
|
16
|
+
limit?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function expenseListCommand(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.expense.list({
|
|
27
|
+
category: opts.category ?? 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 Expenses ${result.total} total\n`);
|
|
40
|
+
|
|
41
|
+
const cols: ColumnDef<ExpenseSummary>[] = [
|
|
42
|
+
{ key: "expenseDate", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
|
|
43
|
+
{ key: "category", header: "Category", width: 18 },
|
|
44
|
+
{ key: "description", header: "Description", width: 22, format: (v) => 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
|
+
];
|
|
48
|
+
|
|
49
|
+
if (opts.format === "tsv") outputTSV(result.data, cols);
|
|
50
|
+
else if (opts.format === "csv") outputCSV(result.data, cols);
|
|
51
|
+
else if (opts.format === "ids") outputIds(result.data.map((r) => r.id));
|
|
52
|
+
else {
|
|
53
|
+
outputTable(result.data, cols);
|
|
54
|
+
paginationFooter(result.page, result.limit, result.total);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
} catch (e) {
|
|
58
|
+
if (e instanceof HisaaboApiError) {
|
|
59
|
+
const err = e.hisaaboError;
|
|
60
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
61
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
62
|
+
}
|
|
63
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, outputJSON, EXIT } from "../../output.js";
|
|
4
|
+
import { formatAmount, quarterRange } from "../../format.js";
|
|
5
|
+
import * as fs from "fs";
|
|
6
|
+
|
|
7
|
+
interface GstOpts {
|
|
8
|
+
json?: boolean;
|
|
9
|
+
quarter?: string;
|
|
10
|
+
month?: number;
|
|
11
|
+
year?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function resolveMonthYear(opts: GstOpts): { month: number; year: number } {
|
|
15
|
+
if (opts.quarter) {
|
|
16
|
+
const range = quarterRange(opts.quarter);
|
|
17
|
+
return { month: range.month, year: range.year };
|
|
18
|
+
}
|
|
19
|
+
const now = new Date();
|
|
20
|
+
return {
|
|
21
|
+
month: opts.month ?? (now.getMonth() + 1),
|
|
22
|
+
year: opts.year ?? now.getFullYear(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function gstR1Command(opts: GstOpts): Promise<void> {
|
|
27
|
+
const cfg = requireAuth();
|
|
28
|
+
const client = new HisaaboClient(cfg);
|
|
29
|
+
const { month, year } = resolveMonthYear(opts);
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const report = await client.gst.gstr1({ month, year });
|
|
33
|
+
|
|
34
|
+
if (opts.json) {
|
|
35
|
+
outputJSON(report);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const quarterLabel = opts.quarter ? `${opts.quarter} ` : "";
|
|
40
|
+
console.log(`\n GSTR-1 Summary ${quarterLabel}FY ${year}-${String(year + 1).slice(2)}`);
|
|
41
|
+
console.log(` ${"═".repeat(60)}\n`);
|
|
42
|
+
|
|
43
|
+
if (report.summary && typeof report.summary === "object") {
|
|
44
|
+
const s = report.summary as Record<string, unknown>;
|
|
45
|
+
if (s["totalTaxableValue"]) console.log(` Total Taxable: ${formatAmount(String(s["totalTaxableValue"]))}`);
|
|
46
|
+
if (s["totalTax"]) console.log(` Total Tax: ${formatAmount(String(s["totalTax"]))}`);
|
|
47
|
+
if (s["totalInvoices"]) console.log(` Total Invoices: ${s["totalInvoices"]}`);
|
|
48
|
+
}
|
|
49
|
+
console.log();
|
|
50
|
+
console.log(" Use --json for full report data.");
|
|
51
|
+
console.log(" Use: hisaabo gst r1-csv to download GSTN-compatible CSV.\n");
|
|
52
|
+
|
|
53
|
+
} catch (e) {
|
|
54
|
+
if (e instanceof HisaaboApiError) {
|
|
55
|
+
const err = e.hisaaboError;
|
|
56
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
57
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
58
|
+
}
|
|
59
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function gstR3bCommand(opts: GstOpts): Promise<void> {
|
|
64
|
+
const cfg = requireAuth();
|
|
65
|
+
const client = new HisaaboClient(cfg);
|
|
66
|
+
const { month, year } = resolveMonthYear(opts);
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const report = await client.gst.gstr3b({ month, year });
|
|
70
|
+
|
|
71
|
+
if (opts.json) {
|
|
72
|
+
outputJSON(report);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
console.log(`\n GSTR-3B Summary ${month}/${year}`);
|
|
77
|
+
console.log(` ${"═".repeat(60)}\n`);
|
|
78
|
+
|
|
79
|
+
if (report.summary && typeof report.summary === "object") {
|
|
80
|
+
const s = report.summary as Record<string, unknown>;
|
|
81
|
+
Object.entries(s).forEach(([k, v]) => {
|
|
82
|
+
console.log(` ${k.padEnd(28)}: ${String(v ?? "-")}`);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
console.log();
|
|
86
|
+
|
|
87
|
+
} catch (e) {
|
|
88
|
+
if (e instanceof HisaaboApiError) {
|
|
89
|
+
const err = e.hisaaboError;
|
|
90
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
91
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
92
|
+
}
|
|
93
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function gstR1CsvCommand(opts: GstOpts & { output?: string }): Promise<void> {
|
|
98
|
+
const cfg = requireAuth();
|
|
99
|
+
const client = new HisaaboClient(cfg);
|
|
100
|
+
const { month, year } = resolveMonthYear(opts);
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
const result = await client.gst.gstr1CSV({ month, year });
|
|
104
|
+
const outputPath = opts.output ?? result.filename;
|
|
105
|
+
fs.writeFileSync(outputPath, result.csv);
|
|
106
|
+
console.log(` Saved: ${outputPath}`);
|
|
107
|
+
|
|
108
|
+
} catch (e) {
|
|
109
|
+
if (e instanceof HisaaboApiError) {
|
|
110
|
+
const err = e.hisaaboError;
|
|
111
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
112
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
113
|
+
}
|
|
114
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
115
|
+
}
|
|
116
|
+
}
|