@hisaabo/mcp 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 +14 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/README.md +155 -0
- package/dist/bin/index.js +2682 -0
- package/dist/bin/index.js.map +1 -0
- package/dist/index.js +2681 -0
- package/package.json +26 -0
- package/src/client.ts +1315 -0
- package/src/index.ts +64 -0
- package/src/lib/errors.ts +49 -0
- package/src/lib/pagination.ts +35 -0
- package/src/resources/index.ts +211 -0
- package/src/server.ts +55 -0
- package/src/tools/bankAccount.ts +200 -0
- package/src/tools/dashboard.ts +110 -0
- package/src/tools/expense.ts +175 -0
- package/src/tools/gst.ts +90 -0
- package/src/tools/import.ts +298 -0
- package/src/tools/invoice.ts +256 -0
- package/src/tools/item.ts +262 -0
- package/src/tools/party.ts +266 -0
- package/src/tools/payment.ts +222 -0
- package/src/tools/reports.ts +246 -0
- package/src/tools/shipment.ts +222 -0
- package/src/tools/store.ts +177 -0
- package/src/tools/target.ts +143 -0
- package/tsconfig.json +8 -0
package/src/client.ts
ADDED
|
@@ -0,0 +1,1315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HisaaboClient — thin fetch wrapper over the tRPC HTTP API.
|
|
3
|
+
*
|
|
4
|
+
* This is an inline copy of the client designed in packages/client (ADR-001).
|
|
5
|
+
* When packages/client is built, this file should be replaced with:
|
|
6
|
+
* import { HisaaboClient } from "@hisaabo/client";
|
|
7
|
+
*
|
|
8
|
+
* The tRPC wire format used here:
|
|
9
|
+
* - Queries: GET /api/trpc/<path>?input=<superjson-encoded>
|
|
10
|
+
* - Mutations: POST /api/trpc/<path> body: <superjson-encoded-input>
|
|
11
|
+
* - Response envelope: { result: { data: <superjson-value> } } | { error: ... }
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import superjson from "superjson";
|
|
15
|
+
|
|
16
|
+
export interface ClientConfig {
|
|
17
|
+
/** Base API URL, e.g. "http://localhost:3000" or "https://api.hisaabo.in" */
|
|
18
|
+
apiUrl: string;
|
|
19
|
+
/** Session ID used as Bearer token — from HISAABO_API_KEY env var */
|
|
20
|
+
token: string;
|
|
21
|
+
/** Tenant (organization) UUID — from HISAABO_TENANT_ID env var */
|
|
22
|
+
tenantId: string;
|
|
23
|
+
/** Active business UUID — from HISAABO_BUSINESS_ID env var */
|
|
24
|
+
businessId: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// ── Structured error types ──────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
export type HisaaboError =
|
|
30
|
+
| { code: "unauthorized"; message: string }
|
|
31
|
+
| { code: "forbidden"; message: string }
|
|
32
|
+
| { code: "not_found"; resource: string }
|
|
33
|
+
| { code: "validation_failed"; fields: Record<string, string[]> }
|
|
34
|
+
| { code: "api_error"; message: string };
|
|
35
|
+
|
|
36
|
+
export class HisaaboApiError extends Error {
|
|
37
|
+
constructor(public readonly hisaaboError: HisaaboError) {
|
|
38
|
+
super(formatHisaaboError(hisaaboError));
|
|
39
|
+
this.name = "HisaaboApiError";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function formatHisaaboError(err: HisaaboError): string {
|
|
44
|
+
switch (err.code) {
|
|
45
|
+
case "unauthorized":
|
|
46
|
+
return `Authentication required: ${err.message}. Check that HISAABO_API_KEY is set and not expired.`;
|
|
47
|
+
case "forbidden":
|
|
48
|
+
return `Permission denied: ${err.message}`;
|
|
49
|
+
case "not_found":
|
|
50
|
+
return `Not found: ${err.resource}`;
|
|
51
|
+
case "validation_failed":
|
|
52
|
+
return (
|
|
53
|
+
`Validation failed:\n` +
|
|
54
|
+
Object.entries(err.fields)
|
|
55
|
+
.map(([field, msgs]) => ` ${field}: ${msgs.join(", ")}`)
|
|
56
|
+
.join("\n")
|
|
57
|
+
);
|
|
58
|
+
case "api_error":
|
|
59
|
+
return `API error: ${err.message}`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ── tRPC error normalization ────────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
function normalizeTrpcError(raw: unknown): HisaaboError {
|
|
66
|
+
if (!raw || typeof raw !== "object") {
|
|
67
|
+
return { code: "api_error", message: "Unknown error from API" };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const err = raw as Record<string, unknown>;
|
|
71
|
+
const code = err["code"] as string | undefined;
|
|
72
|
+
const message = (err["message"] as string | undefined) ?? "Unknown error";
|
|
73
|
+
|
|
74
|
+
// tRPC error codes map to HTTP semantics
|
|
75
|
+
if (code === "UNAUTHORIZED") return { code: "unauthorized", message };
|
|
76
|
+
if (code === "FORBIDDEN") return { code: "forbidden", message };
|
|
77
|
+
if (code === "NOT_FOUND") return { code: "not_found", resource: message };
|
|
78
|
+
|
|
79
|
+
// Zod validation errors from tRPC
|
|
80
|
+
if (code === "BAD_REQUEST") {
|
|
81
|
+
const data = err["data"] as Record<string, unknown> | undefined;
|
|
82
|
+
const zodError = data?.["zodError"] as { fieldErrors?: Record<string, string[]> } | undefined;
|
|
83
|
+
if (zodError?.fieldErrors) {
|
|
84
|
+
return { code: "validation_failed", fields: zodError.fieldErrors };
|
|
85
|
+
}
|
|
86
|
+
return { code: "validation_failed", fields: { _: [message] } };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return { code: "api_error", message };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ── HTTP client ────────────────────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
export class HisaaboClient {
|
|
95
|
+
/** Base API URL, exposed for tools that need to construct URLs (e.g. PDF download). */
|
|
96
|
+
readonly apiUrl: string;
|
|
97
|
+
|
|
98
|
+
constructor(private readonly config: ClientConfig) {
|
|
99
|
+
this.apiUrl = config.apiUrl;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private buildHeaders(): Record<string, string> {
|
|
103
|
+
return {
|
|
104
|
+
"Authorization": `Bearer ${this.config.token}`,
|
|
105
|
+
"x-business-id": this.config.businessId,
|
|
106
|
+
"x-tenant-id": this.config.tenantId,
|
|
107
|
+
"x-client-type": "mcp",
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private async unwrap<T>(res: Response): Promise<T> {
|
|
112
|
+
const body = await res.json() as unknown;
|
|
113
|
+
|
|
114
|
+
if (typeof body !== "object" || body === null) {
|
|
115
|
+
throw new HisaaboApiError({ code: "api_error", message: "Unexpected response format from API" });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const envelope = body as Record<string, unknown>;
|
|
119
|
+
|
|
120
|
+
if (!res.ok || "error" in envelope) {
|
|
121
|
+
throw new HisaaboApiError(normalizeTrpcError(envelope["error"] ?? { code: "api_error", message: `HTTP ${res.status}` }));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const result = (envelope["result"] as Record<string, unknown> | undefined);
|
|
125
|
+
if (!result) {
|
|
126
|
+
throw new HisaaboApiError({ code: "api_error", message: "Missing result in API response" });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// tRPC batch format wraps in { data: <superjson-value> }
|
|
130
|
+
const data = result["data"] as unknown;
|
|
131
|
+
return superjson.deserialize(data as Parameters<typeof superjson.deserialize>[0]) as T;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Call a tRPC query procedure.
|
|
136
|
+
* Queries use GET with SuperJSON-serialized input as a URL param.
|
|
137
|
+
*/
|
|
138
|
+
async query<T>(path: string, input?: unknown): Promise<T> {
|
|
139
|
+
const url = new URL(`${this.config.apiUrl}/api/trpc/${path}`);
|
|
140
|
+
if (input !== undefined) {
|
|
141
|
+
url.searchParams.set("input", JSON.stringify(superjson.serialize(input)));
|
|
142
|
+
}
|
|
143
|
+
const res = await fetch(url.toString(), { headers: this.buildHeaders() });
|
|
144
|
+
return this.unwrap<T>(res);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Call a tRPC mutation procedure.
|
|
149
|
+
* Mutations use POST with SuperJSON-serialized body.
|
|
150
|
+
*/
|
|
151
|
+
async mutate<T>(path: string, input: unknown): Promise<T> {
|
|
152
|
+
const res = await fetch(`${this.config.apiUrl}/api/trpc/${path}`, {
|
|
153
|
+
method: "POST",
|
|
154
|
+
headers: { ...this.buildHeaders(), "Content-Type": "application/json" },
|
|
155
|
+
body: JSON.stringify(superjson.serialize(input)),
|
|
156
|
+
});
|
|
157
|
+
return this.unwrap<T>(res);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ── Namespaced procedure accessors ──────────────────────────────────────
|
|
161
|
+
|
|
162
|
+
get invoice() {
|
|
163
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
164
|
+
const c = this;
|
|
165
|
+
return {
|
|
166
|
+
list(input: InvoiceListInput) {
|
|
167
|
+
return c.query<PaginatedResult<InvoiceSummary>>("invoice.list", input);
|
|
168
|
+
},
|
|
169
|
+
create(input: InvoiceCreateInput) {
|
|
170
|
+
return c.mutate<InvoiceDetail>("invoice.create", input);
|
|
171
|
+
},
|
|
172
|
+
get(id: string) {
|
|
173
|
+
return c.query<InvoiceDetail>("invoice.get", { id });
|
|
174
|
+
},
|
|
175
|
+
updateStatus(id: string, status: InvoiceStatus) {
|
|
176
|
+
return c.mutate<InvoiceSummary>("invoice.updateStatus", { id, status });
|
|
177
|
+
},
|
|
178
|
+
delete(id: string) {
|
|
179
|
+
return c.mutate<{ success: boolean }>("invoice.delete", { id });
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
get party() {
|
|
185
|
+
const c = this;
|
|
186
|
+
return {
|
|
187
|
+
list(input: PartyListInput) {
|
|
188
|
+
return c.query<PaginatedResult<PartySummary>>("party.list", input);
|
|
189
|
+
},
|
|
190
|
+
create(input: PartyCreateInput) {
|
|
191
|
+
return c.mutate<PartySummary>("party.create", input);
|
|
192
|
+
},
|
|
193
|
+
get(id: string) {
|
|
194
|
+
return c.query<PartyDetail>("party.get", { id });
|
|
195
|
+
},
|
|
196
|
+
ledger(partyId: string, input?: LedgerInput) {
|
|
197
|
+
return c.query<LedgerResult>("party.ledger", { partyId, ...input });
|
|
198
|
+
},
|
|
199
|
+
update(id: string, data: Partial<PartyCreateInput>) {
|
|
200
|
+
return c.mutate<PartyDetail>("party.update", { id, data });
|
|
201
|
+
},
|
|
202
|
+
delete(id: string) {
|
|
203
|
+
return c.mutate<{ success: boolean }>("party.delete", { id });
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
get item() {
|
|
209
|
+
const c = this;
|
|
210
|
+
return {
|
|
211
|
+
list(input: ItemListInput) {
|
|
212
|
+
return c.query<PaginatedResult<ItemSummary>>("item.list", input);
|
|
213
|
+
},
|
|
214
|
+
create(input: ItemCreateInput) {
|
|
215
|
+
return c.mutate<ItemSummary>("item.create", input);
|
|
216
|
+
},
|
|
217
|
+
get(id: string) {
|
|
218
|
+
return c.query<ItemDetail>("item.get", { id });
|
|
219
|
+
},
|
|
220
|
+
adjustStock(input: StockAdjustInput) {
|
|
221
|
+
return c.mutate<ItemSummary>("item.adjustStock", input);
|
|
222
|
+
},
|
|
223
|
+
update(id: string, data: Partial<ItemCreateInput>) {
|
|
224
|
+
return c.mutate<ItemDetail>("item.update", { id, data });
|
|
225
|
+
},
|
|
226
|
+
delete(id: string) {
|
|
227
|
+
return c.mutate<{ success: boolean }>("item.delete", { id });
|
|
228
|
+
},
|
|
229
|
+
categories() {
|
|
230
|
+
return c.query<string[]>("item.categories");
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
get payment() {
|
|
236
|
+
const c = this;
|
|
237
|
+
return {
|
|
238
|
+
list(input: PaymentListInput) {
|
|
239
|
+
return c.query<PaginatedResult<PaymentSummary>>("payment.list", input);
|
|
240
|
+
},
|
|
241
|
+
create(input: PaymentCreateInput) {
|
|
242
|
+
return c.mutate<PaymentSummary>("payment.create", input);
|
|
243
|
+
},
|
|
244
|
+
getById(id: string) {
|
|
245
|
+
return c.query<PaymentDetail | null>("payment.getById", { id });
|
|
246
|
+
},
|
|
247
|
+
update(input: PaymentUpdateInput) {
|
|
248
|
+
return c.mutate<PaymentSummary>("payment.update", input);
|
|
249
|
+
},
|
|
250
|
+
delete(id: string) {
|
|
251
|
+
return c.mutate<{ success: boolean }>("payment.delete", { id });
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
get expense() {
|
|
257
|
+
const c = this;
|
|
258
|
+
return {
|
|
259
|
+
list(input: ExpenseListInput) {
|
|
260
|
+
return c.query<PaginatedResult<ExpenseSummary>>("expense.list", input);
|
|
261
|
+
},
|
|
262
|
+
create(input: ExpenseCreateInput) {
|
|
263
|
+
return c.mutate<ExpenseSummary>("expense.create", input);
|
|
264
|
+
},
|
|
265
|
+
update(id: string, data: Partial<ExpenseCreateInput>) {
|
|
266
|
+
return c.mutate<ExpenseSummary>("expense.update", { id, data });
|
|
267
|
+
},
|
|
268
|
+
delete(id: string) {
|
|
269
|
+
return c.mutate<{ success: boolean }>("expense.delete", { id });
|
|
270
|
+
},
|
|
271
|
+
categories() {
|
|
272
|
+
return c.query<string[]>("expense.categories");
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
get dashboard() {
|
|
278
|
+
const c = this;
|
|
279
|
+
return {
|
|
280
|
+
summary(input?: DashboardInput) {
|
|
281
|
+
return c.query<DashboardSummary>("dashboard.summary", input);
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
get business() {
|
|
287
|
+
const c = this;
|
|
288
|
+
return {
|
|
289
|
+
get() {
|
|
290
|
+
return c.query<BusinessDetail>("business.get");
|
|
291
|
+
},
|
|
292
|
+
list() {
|
|
293
|
+
return c.query<BusinessSummary[]>("business.list");
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
get gst() {
|
|
299
|
+
const c = this;
|
|
300
|
+
return {
|
|
301
|
+
gstr1(input: GstReportInput) {
|
|
302
|
+
return c.query<GstReportResult>("gst.gstr1", input);
|
|
303
|
+
},
|
|
304
|
+
gstr3b(input: GstReportInput) {
|
|
305
|
+
return c.query<GstReportResult>("gst.gstr3b", input);
|
|
306
|
+
},
|
|
307
|
+
gstr1CSV(input: GstReportInput) {
|
|
308
|
+
return c.query<{ csv: string; filename: string }>("gst.gstr1CSV", input);
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
get shipment() {
|
|
314
|
+
const c = this;
|
|
315
|
+
return {
|
|
316
|
+
list(input: ShipmentListInput) {
|
|
317
|
+
return c.query<PaginatedResult<ShipmentSummary>>("shipment.list", input);
|
|
318
|
+
},
|
|
319
|
+
get(id: string) {
|
|
320
|
+
return c.query<ShipmentDetail | null>("shipment.getById", { id });
|
|
321
|
+
},
|
|
322
|
+
create(input: ShipmentCreateInput) {
|
|
323
|
+
return c.mutate<ShipmentDetail>("shipment.create", input);
|
|
324
|
+
},
|
|
325
|
+
update(input: ShipmentUpdateInput) {
|
|
326
|
+
return c.mutate<ShipmentDetail>("shipment.update", input);
|
|
327
|
+
},
|
|
328
|
+
delete(id: string) {
|
|
329
|
+
return c.mutate<{ success: boolean }>("shipment.delete", { id });
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
get bankAccount() {
|
|
335
|
+
const c = this;
|
|
336
|
+
return {
|
|
337
|
+
list() {
|
|
338
|
+
return c.query<BankAccountSummary[]>("bankAccount.list");
|
|
339
|
+
},
|
|
340
|
+
get(id: string) {
|
|
341
|
+
return c.query<BankAccountDetail | null>("bankAccount.getById", { id });
|
|
342
|
+
},
|
|
343
|
+
create(input: BankAccountCreateInput) {
|
|
344
|
+
return c.mutate<BankAccountSummary>("bankAccount.create", input);
|
|
345
|
+
},
|
|
346
|
+
update(id: string, data: Partial<BankAccountCreateInput>) {
|
|
347
|
+
return c.mutate<BankAccountSummary>("bankAccount.update", { id, data });
|
|
348
|
+
},
|
|
349
|
+
delete(id: string) {
|
|
350
|
+
return c.mutate<{ success: boolean }>("bankAccount.delete", { id });
|
|
351
|
+
},
|
|
352
|
+
transfer(input: BankTransferInput) {
|
|
353
|
+
return c.mutate<BankTransferResult>("bankAccount.transfer", input);
|
|
354
|
+
},
|
|
355
|
+
listTransactions(input: BankTransactionListInput) {
|
|
356
|
+
return c.query<PaginatedResult<BankTransactionRow>>("bankAccount.listTransactions", input);
|
|
357
|
+
},
|
|
358
|
+
summary() {
|
|
359
|
+
return c.query<BankSummary>("bankAccount.summary");
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
get reports() {
|
|
365
|
+
const c = this;
|
|
366
|
+
return {
|
|
367
|
+
daybook(input: DaybookInput) {
|
|
368
|
+
return c.query<DaybookResult>("reports.daybook", input);
|
|
369
|
+
},
|
|
370
|
+
outstanding(input: OutstandingInput) {
|
|
371
|
+
return c.query<OutstandingResult>("reports.outstanding", input);
|
|
372
|
+
},
|
|
373
|
+
taxSummary(input: TaxSummaryInput) {
|
|
374
|
+
return c.query<TaxSummaryResult>("reports.taxSummary", input);
|
|
375
|
+
},
|
|
376
|
+
itemSales(input: ItemSalesInput) {
|
|
377
|
+
return c.query<ItemSalesResult>("reports.itemSales", input);
|
|
378
|
+
},
|
|
379
|
+
stockSummary(input: StockSummaryInput) {
|
|
380
|
+
return c.query<StockSummaryResult>("reports.stockSummary", input);
|
|
381
|
+
},
|
|
382
|
+
partyStatement(input: PartyStatementInput) {
|
|
383
|
+
return c.query<PartyStatementResult>("reports.partyStatement", input);
|
|
384
|
+
},
|
|
385
|
+
paymentSummary(input: PaymentSummaryInput) {
|
|
386
|
+
return c.query<PaymentSummaryResult>("reports.paymentSummary", input);
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
get store() {
|
|
392
|
+
const c = this;
|
|
393
|
+
return {
|
|
394
|
+
getSettings() {
|
|
395
|
+
return c.query<StoreSettings>("store.getSettings");
|
|
396
|
+
},
|
|
397
|
+
updateSettings(input: StoreSettingsUpdateInput) {
|
|
398
|
+
return c.mutate<StoreSettings>("store.updateSettings", input);
|
|
399
|
+
},
|
|
400
|
+
listOrders(input: StoreOrderListInput) {
|
|
401
|
+
return c.query<PaginatedResult<StoreOrderSummary>>("store.listOrders", input);
|
|
402
|
+
},
|
|
403
|
+
getOrder(id: string) {
|
|
404
|
+
return c.query<StoreOrderDetail | null>("store.getOrder", { id });
|
|
405
|
+
},
|
|
406
|
+
updateOrderStatus(input: { orderId: string; status: "preparing" | "ready" | "delivered" }) {
|
|
407
|
+
return c.mutate<{ success: boolean; status: string }>("store.updateOrderStatus", input);
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
get target() {
|
|
413
|
+
const c = this;
|
|
414
|
+
return {
|
|
415
|
+
list(input: TargetListInput) {
|
|
416
|
+
return c.query<TargetRow[]>("target.list", input);
|
|
417
|
+
},
|
|
418
|
+
create(input: TargetCreateInput) {
|
|
419
|
+
return c.mutate<TargetRow>("target.create", input);
|
|
420
|
+
},
|
|
421
|
+
getProgress(id: string) {
|
|
422
|
+
return c.query<TargetWithProgress>("target.getProgress", { id });
|
|
423
|
+
},
|
|
424
|
+
update(input: TargetUpdateInput) {
|
|
425
|
+
return c.mutate<TargetRow>("target.update", input);
|
|
426
|
+
},
|
|
427
|
+
delete(id: string) {
|
|
428
|
+
return c.mutate<{ success: boolean }>("target.delete", { id });
|
|
429
|
+
},
|
|
430
|
+
myTargets() {
|
|
431
|
+
return c.query<TargetWithProgress[]>("target.myTargets");
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
get import() {
|
|
437
|
+
const c = this;
|
|
438
|
+
return {
|
|
439
|
+
importParties(input: ImportPartiesInput) {
|
|
440
|
+
return c.mutate<ImportResult>("import.importParties", input);
|
|
441
|
+
},
|
|
442
|
+
importItems(input: ImportItemsInput) {
|
|
443
|
+
return c.mutate<ImportItemsResult>("import.importItems", input);
|
|
444
|
+
},
|
|
445
|
+
importInvoices(input: ImportInvoicesInput) {
|
|
446
|
+
return c.mutate<ImportResult>("import.importInvoices", input);
|
|
447
|
+
},
|
|
448
|
+
importPayments(input: ImportPaymentsInput) {
|
|
449
|
+
return c.mutate<ImportResult>("import.importPayments", input);
|
|
450
|
+
},
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// ── Shared types ───────────────────────────────────────────────────────────
|
|
456
|
+
// These mirror the API router output shapes — no runtime dependency on @hisaabo/api.
|
|
457
|
+
// Keep in sync with packages/api/src/routers/*.ts return types.
|
|
458
|
+
|
|
459
|
+
export interface PaginatedResult<T> {
|
|
460
|
+
data: T[];
|
|
461
|
+
total: number;
|
|
462
|
+
page: number;
|
|
463
|
+
limit: number;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export type InvoiceStatus =
|
|
467
|
+
| "draft" | "unfulfilled" | "sent" | "paid" | "partial" | "overdue" | "cancelled";
|
|
468
|
+
|
|
469
|
+
export type DocumentType =
|
|
470
|
+
| "invoice" | "quotation" | "credit_note" | "debit_note"
|
|
471
|
+
| "delivery_challan" | "proforma" | "sales_return" | "purchase_return";
|
|
472
|
+
|
|
473
|
+
export interface InvoiceSummary {
|
|
474
|
+
id: string;
|
|
475
|
+
invoiceNumber: string;
|
|
476
|
+
partyName: string;
|
|
477
|
+
partyId: string;
|
|
478
|
+
type: "sale" | "purchase";
|
|
479
|
+
documentType: DocumentType;
|
|
480
|
+
status: InvoiceStatus;
|
|
481
|
+
invoiceDate: string;
|
|
482
|
+
dueDate: string | null;
|
|
483
|
+
totalAmount: string;
|
|
484
|
+
amountPaid: string;
|
|
485
|
+
balanceDue: string;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export interface LineItem {
|
|
489
|
+
id?: string;
|
|
490
|
+
itemId?: string | null;
|
|
491
|
+
description: string;
|
|
492
|
+
quantity: string;
|
|
493
|
+
unitPrice: string;
|
|
494
|
+
taxPercent: string;
|
|
495
|
+
discountPercent: string;
|
|
496
|
+
amount: string;
|
|
497
|
+
selectedUnit?: string | null;
|
|
498
|
+
variantId?: string | null;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export interface InvoiceDetail extends InvoiceSummary {
|
|
502
|
+
notes: string | null;
|
|
503
|
+
termsAndConditions: string | null;
|
|
504
|
+
lineItems: LineItem[];
|
|
505
|
+
charges?: Array<{ label: string; amount: string }>;
|
|
506
|
+
invoiceDiscount: string;
|
|
507
|
+
roundOff: string;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
export interface InvoiceListInput {
|
|
511
|
+
type?: "sale" | "purchase" | null;
|
|
512
|
+
status?: InvoiceStatus | null;
|
|
513
|
+
documentType?: DocumentType;
|
|
514
|
+
partyId?: string | null;
|
|
515
|
+
fromDate?: string | null;
|
|
516
|
+
toDate?: string | null;
|
|
517
|
+
itemId?: string | null;
|
|
518
|
+
search?: string | null;
|
|
519
|
+
sortBy?: "date" | "amount" | "number" | null;
|
|
520
|
+
sortDir?: "asc" | "desc" | null;
|
|
521
|
+
page?: number;
|
|
522
|
+
limit?: number;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
export interface InvoiceLineItemInput {
|
|
526
|
+
itemId?: string;
|
|
527
|
+
description: string;
|
|
528
|
+
quantity: string;
|
|
529
|
+
unitPrice: string;
|
|
530
|
+
taxPercent?: string;
|
|
531
|
+
discountPercent?: string;
|
|
532
|
+
selectedUnit?: string | null;
|
|
533
|
+
variantId?: string | null;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
export interface InvoiceCreateInput {
|
|
537
|
+
partyId: string;
|
|
538
|
+
type: "sale" | "purchase";
|
|
539
|
+
documentType?: DocumentType;
|
|
540
|
+
invoiceDate?: string;
|
|
541
|
+
dueDate?: string;
|
|
542
|
+
notes?: string;
|
|
543
|
+
termsAndConditions?: string;
|
|
544
|
+
additionalCharges?: string;
|
|
545
|
+
charges?: Array<{ label: string; amount: string }>;
|
|
546
|
+
invoiceDiscount?: string;
|
|
547
|
+
invoiceDiscountType?: "amount" | "percent";
|
|
548
|
+
roundOff?: string;
|
|
549
|
+
referenceDocumentId?: string;
|
|
550
|
+
lineItems: InvoiceLineItemInput[];
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
export interface PartySummary {
|
|
554
|
+
id: string;
|
|
555
|
+
name: string;
|
|
556
|
+
type: "customer" | "supplier";
|
|
557
|
+
phone: string | null;
|
|
558
|
+
email: string | null;
|
|
559
|
+
gstin: string | null;
|
|
560
|
+
balance: string;
|
|
561
|
+
city: string | null;
|
|
562
|
+
category: string | null;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export interface PartyDetail extends PartySummary {
|
|
566
|
+
billingAddress: string | null;
|
|
567
|
+
shippingAddress: string | null;
|
|
568
|
+
pan: string | null;
|
|
569
|
+
state: string | null;
|
|
570
|
+
creditPeriodDays: number | null;
|
|
571
|
+
creditLimit: string | null;
|
|
572
|
+
contactPersonName: string | null;
|
|
573
|
+
openingBalance: string;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
export interface PartyListInput {
|
|
577
|
+
type?: "customer" | "supplier" | null;
|
|
578
|
+
filter?: "all" | "customer" | "supplier" | "outstanding" | "overdue" | null;
|
|
579
|
+
search?: string | null;
|
|
580
|
+
category?: string | null;
|
|
581
|
+
sortBy?: "name" | "balance" | null;
|
|
582
|
+
sortDir?: "asc" | "desc" | null;
|
|
583
|
+
page?: number;
|
|
584
|
+
limit?: number;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
export interface PartyCreateInput {
|
|
588
|
+
type: "customer" | "supplier";
|
|
589
|
+
name: string;
|
|
590
|
+
phone?: string;
|
|
591
|
+
email?: string;
|
|
592
|
+
gstin?: string;
|
|
593
|
+
pan?: string;
|
|
594
|
+
billingAddress?: string;
|
|
595
|
+
shippingAddress?: string;
|
|
596
|
+
city?: string;
|
|
597
|
+
state?: string;
|
|
598
|
+
stateCode?: string;
|
|
599
|
+
pincode?: string;
|
|
600
|
+
openingBalance?: string;
|
|
601
|
+
category?: string;
|
|
602
|
+
creditPeriodDays?: number;
|
|
603
|
+
creditLimit?: string;
|
|
604
|
+
contactPersonName?: string;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export interface LedgerEntry {
|
|
608
|
+
date: string;
|
|
609
|
+
description: string;
|
|
610
|
+
debit: string;
|
|
611
|
+
credit: string;
|
|
612
|
+
balance: string;
|
|
613
|
+
referenceType: string;
|
|
614
|
+
referenceId: string;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
export interface LedgerResult {
|
|
618
|
+
partyName: string;
|
|
619
|
+
partyType: string;
|
|
620
|
+
openingBalance: string;
|
|
621
|
+
closingBalance: string;
|
|
622
|
+
entries: LedgerEntry[];
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
export interface LedgerInput {
|
|
626
|
+
fromDate?: string;
|
|
627
|
+
toDate?: string;
|
|
628
|
+
page?: number;
|
|
629
|
+
limit?: number;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
export interface ItemSummary {
|
|
633
|
+
id: string;
|
|
634
|
+
name: string;
|
|
635
|
+
sku: string | null;
|
|
636
|
+
unit: string;
|
|
637
|
+
salePrice: string | null;
|
|
638
|
+
purchasePrice: string | null;
|
|
639
|
+
taxPercent: string;
|
|
640
|
+
stockQuantity: string;
|
|
641
|
+
lowStockAlert: string | null;
|
|
642
|
+
category: string | null;
|
|
643
|
+
itemType: "product" | "service";
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
export interface ItemDetail extends ItemSummary {
|
|
647
|
+
description: string | null;
|
|
648
|
+
hsn: string | null;
|
|
649
|
+
itemMode: "simple" | "alt_units" | "variants";
|
|
650
|
+
taxInclusive: boolean;
|
|
651
|
+
unitVariants?: Array<{
|
|
652
|
+
unit: string;
|
|
653
|
+
conversionFactor: number;
|
|
654
|
+
salePrice: string;
|
|
655
|
+
purchasePrice?: string;
|
|
656
|
+
}>;
|
|
657
|
+
variants?: Array<{
|
|
658
|
+
id: string;
|
|
659
|
+
attributeValues: Record<string, string>;
|
|
660
|
+
sku?: string;
|
|
661
|
+
salePrice?: string;
|
|
662
|
+
purchasePrice?: string;
|
|
663
|
+
stockQuantity: string;
|
|
664
|
+
}>;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
export interface ItemListInput {
|
|
668
|
+
search?: string | null;
|
|
669
|
+
category?: string | null;
|
|
670
|
+
itemType?: "product" | "service" | null;
|
|
671
|
+
lowStock?: boolean | null;
|
|
672
|
+
page?: number;
|
|
673
|
+
limit?: number;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
export interface ItemCreateInput {
|
|
677
|
+
name: string;
|
|
678
|
+
unit?: string;
|
|
679
|
+
salePrice?: string;
|
|
680
|
+
purchasePrice?: string;
|
|
681
|
+
taxPercent?: string;
|
|
682
|
+
stockQuantity?: string;
|
|
683
|
+
lowStockAlert?: string;
|
|
684
|
+
description?: string;
|
|
685
|
+
hsn?: string;
|
|
686
|
+
sku?: string;
|
|
687
|
+
itemType?: "product" | "service";
|
|
688
|
+
category?: string;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
export interface StockAdjustInput {
|
|
692
|
+
itemId: string;
|
|
693
|
+
/** Signed decimal string: "+50", "-3.500", "10" */
|
|
694
|
+
adjustment: string;
|
|
695
|
+
reason?: string;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
export interface PaymentSummary {
|
|
699
|
+
id: string;
|
|
700
|
+
paymentNumber: string;
|
|
701
|
+
amount: string;
|
|
702
|
+
discount: string;
|
|
703
|
+
mode: string;
|
|
704
|
+
paymentDate: string;
|
|
705
|
+
referenceNumber: string | null;
|
|
706
|
+
notes: string | null;
|
|
707
|
+
partyName: string;
|
|
708
|
+
partyId: string;
|
|
709
|
+
invoiceId: string | null;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
export interface PaymentListInput {
|
|
713
|
+
partyId?: string | null;
|
|
714
|
+
invoiceId?: string | null;
|
|
715
|
+
fromDate?: string | null;
|
|
716
|
+
toDate?: string | null;
|
|
717
|
+
search?: string | null;
|
|
718
|
+
page?: number;
|
|
719
|
+
limit?: number;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
export interface PaymentCreateInput {
|
|
723
|
+
partyId: string;
|
|
724
|
+
amount: string;
|
|
725
|
+
mode: "cash" | "bank" | "upi" | "cheque" | "other";
|
|
726
|
+
invoiceId?: string;
|
|
727
|
+
discount?: string;
|
|
728
|
+
referenceNumber?: string;
|
|
729
|
+
paymentDate?: string;
|
|
730
|
+
notes?: string;
|
|
731
|
+
bankAccountId?: string;
|
|
732
|
+
allocations?: Array<{ invoiceId: string; amount: string }>;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
export interface ExpenseSummary {
|
|
736
|
+
id: string;
|
|
737
|
+
category: string;
|
|
738
|
+
description: string | null;
|
|
739
|
+
amount: string;
|
|
740
|
+
mode: string;
|
|
741
|
+
expenseDate: string;
|
|
742
|
+
referenceNumber: string | null;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
export interface ExpenseListInput {
|
|
746
|
+
category?: string | null;
|
|
747
|
+
fromDate?: string | null;
|
|
748
|
+
toDate?: string | null;
|
|
749
|
+
search?: string | null;
|
|
750
|
+
page?: number;
|
|
751
|
+
limit?: number;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
export interface ExpenseCreateInput {
|
|
755
|
+
category: string;
|
|
756
|
+
amount: string;
|
|
757
|
+
mode: "cash" | "bank" | "upi" | "cheque" | "other";
|
|
758
|
+
description?: string;
|
|
759
|
+
expenseDate?: string;
|
|
760
|
+
referenceNumber?: string;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
export interface DashboardInput {
|
|
764
|
+
fromDate?: string;
|
|
765
|
+
toDate?: string;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
export interface DashboardSummary {
|
|
769
|
+
totalSales: string;
|
|
770
|
+
totalPurchases: string;
|
|
771
|
+
totalExpenses: string;
|
|
772
|
+
receivable: string;
|
|
773
|
+
payable: string;
|
|
774
|
+
cashInHand: string;
|
|
775
|
+
recentInvoices: Array<{
|
|
776
|
+
id: string;
|
|
777
|
+
invoiceNumber: string;
|
|
778
|
+
partyName: string;
|
|
779
|
+
totalAmount: string;
|
|
780
|
+
status: string;
|
|
781
|
+
invoiceDate: string;
|
|
782
|
+
}>;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
export interface BusinessSummary {
|
|
786
|
+
id: string;
|
|
787
|
+
name: string;
|
|
788
|
+
legalName: string | null;
|
|
789
|
+
gstin: string | null;
|
|
790
|
+
gstRegistrationType: string;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
export interface BusinessDetail extends BusinessSummary {
|
|
794
|
+
pan: string;
|
|
795
|
+
phone: string;
|
|
796
|
+
email: string | null;
|
|
797
|
+
address: string;
|
|
798
|
+
city: string | null;
|
|
799
|
+
state: string | null;
|
|
800
|
+
stateCode: string | null;
|
|
801
|
+
pincode: string | null;
|
|
802
|
+
invoicePrefix: string;
|
|
803
|
+
currency: string;
|
|
804
|
+
financialYearStart: number;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
export interface GstReportInput {
|
|
808
|
+
month: number;
|
|
809
|
+
year: number;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
export interface GstReportResult {
|
|
813
|
+
period: string;
|
|
814
|
+
b2b?: unknown;
|
|
815
|
+
b2c?: unknown;
|
|
816
|
+
summary?: unknown;
|
|
817
|
+
[key: string]: unknown;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// ── Payment types ──────────────────────────────────────────────
|
|
821
|
+
|
|
822
|
+
export interface PaymentDetail extends PaymentSummary {
|
|
823
|
+
bankAccountId: string | null;
|
|
824
|
+
linkedInvoices: Array<{
|
|
825
|
+
invoiceId: string;
|
|
826
|
+
invoiceNumber: string;
|
|
827
|
+
invoiceDate: string;
|
|
828
|
+
totalAmount: string;
|
|
829
|
+
amountPaid: string;
|
|
830
|
+
status: string;
|
|
831
|
+
amount: string;
|
|
832
|
+
}>;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
export interface PaymentUpdateInput {
|
|
836
|
+
id: string;
|
|
837
|
+
amount?: string;
|
|
838
|
+
mode?: "cash" | "bank" | "upi" | "cheque" | "other";
|
|
839
|
+
discount?: string;
|
|
840
|
+
referenceNumber?: string | null;
|
|
841
|
+
paymentDate?: string;
|
|
842
|
+
notes?: string | null;
|
|
843
|
+
bankAccountId?: string | null;
|
|
844
|
+
allocations?: Array<{ invoiceId: string; amount: string }>;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// ── Shipment types ─────────────────────────────────────────────
|
|
848
|
+
|
|
849
|
+
export type ShipmentStatus = "pending" | "shipped" | "in_transit" | "delivered" | "returned";
|
|
850
|
+
|
|
851
|
+
export interface ShipmentSummary {
|
|
852
|
+
id: string;
|
|
853
|
+
invoiceId: string | null;
|
|
854
|
+
partyId: string | null;
|
|
855
|
+
carrier: string | null;
|
|
856
|
+
mode: string | null;
|
|
857
|
+
trackingNumber: string | null;
|
|
858
|
+
trackingUrl: string | null;
|
|
859
|
+
cost: string;
|
|
860
|
+
weight: string | null;
|
|
861
|
+
status: ShipmentStatus;
|
|
862
|
+
shipmentDate: string | null;
|
|
863
|
+
estimatedDelivery: string | null;
|
|
864
|
+
actualDelivery: string | null;
|
|
865
|
+
notes: string | null;
|
|
866
|
+
createdAt: string;
|
|
867
|
+
invoiceNumber: string | null;
|
|
868
|
+
partyName: string | null;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
export interface ShipmentDetail extends ShipmentSummary {
|
|
872
|
+
businessId: string;
|
|
873
|
+
shippingAddress: string | null;
|
|
874
|
+
shippingCity: string | null;
|
|
875
|
+
shippingPincode: string | null;
|
|
876
|
+
updatedAt: string;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
export interface ShipmentListInput {
|
|
880
|
+
status?: ShipmentStatus | null;
|
|
881
|
+
invoiceId?: string | null;
|
|
882
|
+
partyId?: string | null;
|
|
883
|
+
page?: number;
|
|
884
|
+
limit?: number;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
export interface ShipmentCreateInput {
|
|
888
|
+
invoiceId?: string;
|
|
889
|
+
partyId?: string;
|
|
890
|
+
carrier?: string;
|
|
891
|
+
mode?: string;
|
|
892
|
+
trackingNumber?: string;
|
|
893
|
+
trackingUrl?: string;
|
|
894
|
+
cost?: string;
|
|
895
|
+
weight?: string;
|
|
896
|
+
shippingAddress?: string;
|
|
897
|
+
shippingCity?: string;
|
|
898
|
+
shippingPincode?: string;
|
|
899
|
+
status?: ShipmentStatus;
|
|
900
|
+
shipmentDate?: string;
|
|
901
|
+
estimatedDelivery?: string;
|
|
902
|
+
notes?: string;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
export interface ShipmentUpdateInput {
|
|
906
|
+
id: string;
|
|
907
|
+
carrier?: string;
|
|
908
|
+
mode?: string;
|
|
909
|
+
trackingNumber?: string;
|
|
910
|
+
trackingUrl?: string;
|
|
911
|
+
cost?: string;
|
|
912
|
+
weight?: string;
|
|
913
|
+
status?: ShipmentStatus;
|
|
914
|
+
shipmentDate?: string;
|
|
915
|
+
estimatedDelivery?: string;
|
|
916
|
+
actualDelivery?: string;
|
|
917
|
+
notes?: string;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// ── Bank account types ─────────────────────────────────────────
|
|
921
|
+
|
|
922
|
+
export type BankAccountType = "savings" | "current" | "cash" | "credit" | "other";
|
|
923
|
+
|
|
924
|
+
export interface BankAccountSummary {
|
|
925
|
+
id: string;
|
|
926
|
+
accountName: string;
|
|
927
|
+
accountNumber: string | null;
|
|
928
|
+
ifsc: string | null;
|
|
929
|
+
bankName: string | null;
|
|
930
|
+
accountType: BankAccountType;
|
|
931
|
+
openingBalance: string;
|
|
932
|
+
currentBalance: string;
|
|
933
|
+
isDefault: boolean;
|
|
934
|
+
createdAt: string;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
export interface BankTransactionRow {
|
|
938
|
+
id: string;
|
|
939
|
+
businessId: string;
|
|
940
|
+
bankAccountId: string;
|
|
941
|
+
type: "deposit" | "withdrawal" | "transfer";
|
|
942
|
+
amount: string;
|
|
943
|
+
description: string | null;
|
|
944
|
+
referenceType: string | null;
|
|
945
|
+
referenceId: string | null;
|
|
946
|
+
transactionDate: string;
|
|
947
|
+
createdAt: string;
|
|
948
|
+
balanceAfter: string;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
export interface BankAccountDetail extends BankAccountSummary {
|
|
952
|
+
recentTransactions: BankTransactionRow[];
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
export interface BankAccountCreateInput {
|
|
956
|
+
accountName: string;
|
|
957
|
+
accountNumber?: string;
|
|
958
|
+
ifsc?: string;
|
|
959
|
+
bankName?: string;
|
|
960
|
+
accountType: BankAccountType;
|
|
961
|
+
openingBalance?: string;
|
|
962
|
+
isDefault?: boolean;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
export interface BankTransferInput {
|
|
966
|
+
fromAccountId: string;
|
|
967
|
+
toAccountId: string;
|
|
968
|
+
amount: string;
|
|
969
|
+
description?: string;
|
|
970
|
+
transactionDate?: string;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
export interface BankTransferResult {
|
|
974
|
+
withdrawal: BankTransactionRow;
|
|
975
|
+
deposit: BankTransactionRow;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
export interface BankTransactionListInput {
|
|
979
|
+
bankAccountId: string;
|
|
980
|
+
fromDate?: string;
|
|
981
|
+
toDate?: string;
|
|
982
|
+
type?: "deposit" | "withdrawal" | "transfer";
|
|
983
|
+
page?: number;
|
|
984
|
+
limit?: number;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
export interface BankSummary {
|
|
988
|
+
totalBalance: string;
|
|
989
|
+
cashInHand: string;
|
|
990
|
+
bankBalance: string;
|
|
991
|
+
accountCount: number;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
// ── Reports types ──────────────────────────────────────────────
|
|
995
|
+
|
|
996
|
+
export interface DaybookInput {
|
|
997
|
+
fromDate: string;
|
|
998
|
+
toDate: string;
|
|
999
|
+
typeFilter?: "all" | "invoices" | "payments" | "expenses";
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
export interface DaybookEntry {
|
|
1003
|
+
id: string;
|
|
1004
|
+
time: string;
|
|
1005
|
+
entryType: "invoice" | "payment" | "expense";
|
|
1006
|
+
number: string | null;
|
|
1007
|
+
partyOrCategory: string;
|
|
1008
|
+
debit: string;
|
|
1009
|
+
credit: string;
|
|
1010
|
+
mode: string | null;
|
|
1011
|
+
status: string | null;
|
|
1012
|
+
meta: Record<string, string | null>;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
export interface DaybookResult {
|
|
1016
|
+
entries: DaybookEntry[];
|
|
1017
|
+
summary: {
|
|
1018
|
+
totalSalesInvoiced: string;
|
|
1019
|
+
totalPurchaseInvoiced: string;
|
|
1020
|
+
totalPaymentsReceived: string;
|
|
1021
|
+
totalPaymentsMade: string;
|
|
1022
|
+
totalExpenses: string;
|
|
1023
|
+
netCashMovement: string;
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
export interface OutstandingInput {
|
|
1028
|
+
type?: "receivable" | "payable" | "both";
|
|
1029
|
+
asOfDate?: string;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
export interface OutstandingResult {
|
|
1033
|
+
receivables: unknown | null;
|
|
1034
|
+
payables: unknown | null;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
export interface TaxSummaryInput {
|
|
1038
|
+
fromDate: string;
|
|
1039
|
+
toDate: string;
|
|
1040
|
+
type?: "sales" | "purchases" | "both";
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
export interface TaxSummaryResult {
|
|
1044
|
+
rows: unknown[];
|
|
1045
|
+
summary: unknown;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
export interface ItemSalesInput {
|
|
1049
|
+
fromDate: string;
|
|
1050
|
+
toDate: string;
|
|
1051
|
+
category?: string;
|
|
1052
|
+
itemType?: "product" | "service";
|
|
1053
|
+
sortBy?: "revenue" | "quantity" | "invoices" | "margin";
|
|
1054
|
+
compareToPrevious?: boolean;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
export interface ItemSalesResult {
|
|
1058
|
+
rows: unknown[];
|
|
1059
|
+
summary: unknown;
|
|
1060
|
+
[key: string]: unknown;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
export interface StockSummaryInput {
|
|
1064
|
+
category?: string;
|
|
1065
|
+
showZeroStock?: boolean;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
export interface StockSummaryResult {
|
|
1069
|
+
rows: unknown[];
|
|
1070
|
+
summary: unknown;
|
|
1071
|
+
[key: string]: unknown;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
export interface PartyStatementInput {
|
|
1075
|
+
partyId: string;
|
|
1076
|
+
fromDate?: string;
|
|
1077
|
+
toDate?: string;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
export interface PartyStatementResult {
|
|
1081
|
+
[key: string]: unknown;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
export interface PaymentSummaryInput {
|
|
1085
|
+
fromDate: string;
|
|
1086
|
+
toDate: string;
|
|
1087
|
+
type?: "received" | "made" | "both";
|
|
1088
|
+
bankAccountId?: string;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
export interface PaymentSummaryResult {
|
|
1092
|
+
[key: string]: unknown;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
// ── Store types ────────────────────────────────────────────────
|
|
1096
|
+
|
|
1097
|
+
export interface StoreSettings {
|
|
1098
|
+
storeEnabled: boolean;
|
|
1099
|
+
storeSlug: string | null;
|
|
1100
|
+
storeTagline: string | null;
|
|
1101
|
+
storeAccentColor: string | null;
|
|
1102
|
+
storeMinOrderAmount: string | null;
|
|
1103
|
+
storeDeliveryNote: string | null;
|
|
1104
|
+
storeWhatsappNumber: string | null;
|
|
1105
|
+
storeAllowNegativeStock: boolean;
|
|
1106
|
+
storeOrderPrefix: string;
|
|
1107
|
+
nextStoreOrderNumber: number;
|
|
1108
|
+
currency: string;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
export interface StoreSettingsUpdateInput {
|
|
1112
|
+
storeEnabled?: boolean;
|
|
1113
|
+
storeSlug?: string | null;
|
|
1114
|
+
storeTagline?: string | null;
|
|
1115
|
+
storeAccentColor?: string | null;
|
|
1116
|
+
storeMinOrderAmount?: string | null;
|
|
1117
|
+
storeDeliveryNote?: string | null;
|
|
1118
|
+
storeWhatsappNumber?: string | null;
|
|
1119
|
+
storeAllowNegativeStock?: boolean;
|
|
1120
|
+
storeOrderPrefix?: string;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
export type StoreOrderStatus = "pending" | "confirmed" | "preparing" | "ready" | "delivered" | "cancelled";
|
|
1124
|
+
|
|
1125
|
+
export interface StoreOrderSummary {
|
|
1126
|
+
id: string;
|
|
1127
|
+
orderNumber: string;
|
|
1128
|
+
status: StoreOrderStatus;
|
|
1129
|
+
customerName: string;
|
|
1130
|
+
customerPhone: string | null;
|
|
1131
|
+
customerEmail: string | null;
|
|
1132
|
+
deliveryAddress: string | null;
|
|
1133
|
+
deliveryCity: string | null;
|
|
1134
|
+
deliveryPincode: string | null;
|
|
1135
|
+
totalAmount: string;
|
|
1136
|
+
itemCount: number;
|
|
1137
|
+
invoiceId: string | null;
|
|
1138
|
+
createdAt: string;
|
|
1139
|
+
confirmedAt: string | null;
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
export interface StoreOrderDetail extends StoreOrderSummary {
|
|
1143
|
+
invoice: unknown | null;
|
|
1144
|
+
lineItems: unknown[];
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
export interface StoreOrderListInput {
|
|
1148
|
+
status?: StoreOrderStatus | null;
|
|
1149
|
+
fromDate?: string | null;
|
|
1150
|
+
toDate?: string | null;
|
|
1151
|
+
search?: string | null;
|
|
1152
|
+
page?: number;
|
|
1153
|
+
limit?: number;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
// ── Target types ───────────────────────────────────────────────
|
|
1157
|
+
|
|
1158
|
+
export type TargetType = "order_count" | "order_value" | "item_quantity";
|
|
1159
|
+
export type PeriodType = "daily" | "weekly" | "monthly" | "quarterly" | "custom";
|
|
1160
|
+
|
|
1161
|
+
export interface TargetRow {
|
|
1162
|
+
id: string;
|
|
1163
|
+
businessId: string;
|
|
1164
|
+
userId: string;
|
|
1165
|
+
targetType: TargetType;
|
|
1166
|
+
targetValue: string;
|
|
1167
|
+
itemId: string | null;
|
|
1168
|
+
periodType: PeriodType;
|
|
1169
|
+
periodStart: string;
|
|
1170
|
+
periodEnd: string;
|
|
1171
|
+
notes: string | null;
|
|
1172
|
+
createdAt: string;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
export interface TargetProgress {
|
|
1176
|
+
current: number;
|
|
1177
|
+
target: number;
|
|
1178
|
+
percentage: number;
|
|
1179
|
+
remaining: number;
|
|
1180
|
+
unit: string;
|
|
1181
|
+
onTrack: boolean;
|
|
1182
|
+
daysTotal: number;
|
|
1183
|
+
daysElapsed: number;
|
|
1184
|
+
daysRemaining: number;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
export interface TargetWithProgress extends TargetRow {
|
|
1188
|
+
progress: TargetProgress;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
export interface TargetListInput {
|
|
1192
|
+
userId?: string;
|
|
1193
|
+
periodType?: PeriodType;
|
|
1194
|
+
active?: boolean;
|
|
1195
|
+
withProgress?: boolean;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
export interface TargetCreateInput {
|
|
1199
|
+
userId: string;
|
|
1200
|
+
targetType: TargetType;
|
|
1201
|
+
targetValue: string;
|
|
1202
|
+
itemId?: string | null;
|
|
1203
|
+
periodType: PeriodType;
|
|
1204
|
+
periodStart: string;
|
|
1205
|
+
periodEnd: string;
|
|
1206
|
+
notes?: string | null;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
export interface TargetUpdateInput {
|
|
1210
|
+
id: string;
|
|
1211
|
+
targetValue?: string;
|
|
1212
|
+
itemId?: string | null;
|
|
1213
|
+
periodType?: PeriodType;
|
|
1214
|
+
periodStart?: string;
|
|
1215
|
+
periodEnd?: string;
|
|
1216
|
+
notes?: string | null;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
// ── Import types ───────────────────────────────────────────────
|
|
1220
|
+
|
|
1221
|
+
export interface ImportResult {
|
|
1222
|
+
created: number;
|
|
1223
|
+
skipped: number;
|
|
1224
|
+
total: number;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
export interface ImportItemsResult extends ImportResult {
|
|
1228
|
+
unmappedUnits: string[];
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
export interface ImportPartyRecord {
|
|
1232
|
+
name: string;
|
|
1233
|
+
type?: "customer" | "supplier";
|
|
1234
|
+
phone?: string;
|
|
1235
|
+
email?: string;
|
|
1236
|
+
gstin?: string;
|
|
1237
|
+
pan?: string;
|
|
1238
|
+
openingBalance?: string;
|
|
1239
|
+
billingAddress?: string;
|
|
1240
|
+
shippingAddress?: string;
|
|
1241
|
+
city?: string;
|
|
1242
|
+
state?: string;
|
|
1243
|
+
pincode?: string;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
export interface ImportPartiesInput {
|
|
1247
|
+
source?: string;
|
|
1248
|
+
parties: ImportPartyRecord[];
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
export interface ImportItemRecord {
|
|
1252
|
+
name: string;
|
|
1253
|
+
itemType?: "product" | "service";
|
|
1254
|
+
salePrice?: string;
|
|
1255
|
+
purchasePrice?: string;
|
|
1256
|
+
taxPercent?: string;
|
|
1257
|
+
hsn?: string;
|
|
1258
|
+
unit?: string;
|
|
1259
|
+
stockQuantity?: string;
|
|
1260
|
+
sku?: string;
|
|
1261
|
+
category?: string;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
export interface ImportItemsInput {
|
|
1265
|
+
source?: string;
|
|
1266
|
+
items: ImportItemRecord[];
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
export interface ImportInvoiceRecord {
|
|
1270
|
+
invoiceNumber: string;
|
|
1271
|
+
invoiceDate: string;
|
|
1272
|
+
dueDate?: string;
|
|
1273
|
+
partyName: string;
|
|
1274
|
+
type?: "sale" | "purchase";
|
|
1275
|
+
status?: "draft" | "sent" | "paid" | "partial" | "overdue" | "cancelled";
|
|
1276
|
+
totalAmount: string;
|
|
1277
|
+
amountPaid?: string;
|
|
1278
|
+
subtotal?: string;
|
|
1279
|
+
taxAmount?: string;
|
|
1280
|
+
discountAmount?: string;
|
|
1281
|
+
notes?: string;
|
|
1282
|
+
createdByName?: string;
|
|
1283
|
+
lineItems?: Array<{
|
|
1284
|
+
description: string;
|
|
1285
|
+
quantity?: string;
|
|
1286
|
+
unitPrice: string;
|
|
1287
|
+
taxPercent?: string;
|
|
1288
|
+
discountPercent?: string;
|
|
1289
|
+
itemName?: string;
|
|
1290
|
+
}>;
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
export interface ImportInvoicesInput {
|
|
1294
|
+
source?: string;
|
|
1295
|
+
autoCreatePayments?: boolean;
|
|
1296
|
+
defaultPaymentMode?: "cash" | "bank" | "upi" | "cheque" | "other";
|
|
1297
|
+
invoices: ImportInvoiceRecord[];
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
export interface ImportPaymentRecord {
|
|
1301
|
+
partyName: string;
|
|
1302
|
+
amount: string;
|
|
1303
|
+
mode?: "cash" | "bank" | "upi" | "cheque" | "other";
|
|
1304
|
+
paymentDate?: string;
|
|
1305
|
+
paymentNumber?: string;
|
|
1306
|
+
referenceNumber?: string;
|
|
1307
|
+
notes?: string;
|
|
1308
|
+
invoiceNumbers?: string[];
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
export interface ImportPaymentsInput {
|
|
1312
|
+
source?: string;
|
|
1313
|
+
paidInvoiceNumbers?: string[];
|
|
1314
|
+
payments: ImportPaymentRecord[];
|
|
1315
|
+
}
|