@classytic/commerce-sdk 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.
Potentially problematic release.
This version of @classytic/commerce-sdk might be problematic. Click here for more details.
- package/LICENSE +14 -0
- package/README.md +104 -0
- package/dist/adjustment-DTSLM7AN.js +5 -0
- package/dist/adjustment-DTSLM7AN.js.map +1 -0
- package/dist/analytics/index.d.ts +27 -0
- package/dist/analytics/index.js +6 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/analytics-DMcD-o8w.d.ts +76 -0
- package/dist/api-factory-B_h4RKBm.d.ts +280 -0
- package/dist/auth/index.d.ts +39 -0
- package/dist/auth/index.js +5 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/catalog/index.d.ts +479 -0
- package/dist/catalog/index.js +9 -0
- package/dist/catalog/index.js.map +1 -0
- package/dist/chunk-4ZQK3FFN.js +40 -0
- package/dist/chunk-4ZQK3FFN.js.map +1 -0
- package/dist/chunk-5L6EXDGH.js +465 -0
- package/dist/chunk-5L6EXDGH.js.map +1 -0
- package/dist/chunk-5ZFW3FEI.js +183 -0
- package/dist/chunk-5ZFW3FEI.js.map +1 -0
- package/dist/chunk-66OQAZSL.js +94 -0
- package/dist/chunk-66OQAZSL.js.map +1 -0
- package/dist/chunk-6RYGA6MF.js +123 -0
- package/dist/chunk-6RYGA6MF.js.map +1 -0
- package/dist/chunk-B6MPVOV7.js +328 -0
- package/dist/chunk-B6MPVOV7.js.map +1 -0
- package/dist/chunk-BDA2WSJA.js +148 -0
- package/dist/chunk-BDA2WSJA.js.map +1 -0
- package/dist/chunk-EIVYT3HM.js +126 -0
- package/dist/chunk-EIVYT3HM.js.map +1 -0
- package/dist/chunk-EPQN7ZKZ.js +27 -0
- package/dist/chunk-EPQN7ZKZ.js.map +1 -0
- package/dist/chunk-FA7QFJ2G.js +177 -0
- package/dist/chunk-FA7QFJ2G.js.map +1 -0
- package/dist/chunk-I5TIKUIQ.js +261 -0
- package/dist/chunk-I5TIKUIQ.js.map +1 -0
- package/dist/chunk-ILQUH444.js +135 -0
- package/dist/chunk-ILQUH444.js.map +1 -0
- package/dist/chunk-IXMWZJLV.js +616 -0
- package/dist/chunk-IXMWZJLV.js.map +1 -0
- package/dist/chunk-KZIGRIQG.js +75 -0
- package/dist/chunk-KZIGRIQG.js.map +1 -0
- package/dist/chunk-OF5M6R2S.js +769 -0
- package/dist/chunk-OF5M6R2S.js.map +1 -0
- package/dist/chunk-PYYLHUV6.js +3 -0
- package/dist/chunk-PYYLHUV6.js.map +1 -0
- package/dist/chunk-QO5AGZFP.js +159 -0
- package/dist/chunk-QO5AGZFP.js.map +1 -0
- package/dist/chunk-QUMTBLNE.js +76 -0
- package/dist/chunk-QUMTBLNE.js.map +1 -0
- package/dist/chunk-R5Z7NYLH.js +126 -0
- package/dist/chunk-R5Z7NYLH.js.map +1 -0
- package/dist/chunk-SZYWG5IB.js +75 -0
- package/dist/chunk-SZYWG5IB.js.map +1 -0
- package/dist/chunk-U3XT35GZ.js +202 -0
- package/dist/chunk-U3XT35GZ.js.map +1 -0
- package/dist/chunk-UGELTUIZ.js +830 -0
- package/dist/chunk-UGELTUIZ.js.map +1 -0
- package/dist/chunk-VR36QVX2.js +122 -0
- package/dist/chunk-VR36QVX2.js.map +1 -0
- package/dist/chunk-WUOQK7BO.js +13 -0
- package/dist/chunk-WUOQK7BO.js.map +1 -0
- package/dist/chunk-X6PV5MHG.js +582 -0
- package/dist/chunk-X6PV5MHG.js.map +1 -0
- package/dist/chunk-ZWLMFLLH.js +534 -0
- package/dist/chunk-ZWLMFLLH.js.map +1 -0
- package/dist/content/index.d.ts +309 -0
- package/dist/content/index.js +6 -0
- package/dist/content/index.js.map +1 -0
- package/dist/core/index.d.ts +107 -0
- package/dist/core/index.js +5 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/react.d.ts +107 -0
- package/dist/core/react.js +5 -0
- package/dist/core/react.js.map +1 -0
- package/dist/coupon-CHFcw7cd.d.ts +632 -0
- package/dist/coupon-zGkvO-Xx.d.ts +129 -0
- package/dist/crud.factory-DyKaPHcU.d.ts +181 -0
- package/dist/finance/index.d.ts +81 -0
- package/dist/finance/index.js +5 -0
- package/dist/finance/index.js.map +1 -0
- package/dist/finance-BJdfKRw0.d.ts +135 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/inventory/index.d.ts +512 -0
- package/dist/inventory/index.js +16 -0
- package/dist/inventory/index.js.map +1 -0
- package/dist/inventory-DCiIZh8P.d.ts +742 -0
- package/dist/logistics/index.d.ts +226 -0
- package/dist/logistics/index.js +7 -0
- package/dist/logistics/index.js.map +1 -0
- package/dist/logistics-V8a9lUN3.d.ts +428 -0
- package/dist/media-CNLJK93J.d.ts +721 -0
- package/dist/movement-7MV3ADY5.js +5 -0
- package/dist/movement-7MV3ADY5.js.map +1 -0
- package/dist/payment-BRboLqvU.d.ts +127 -0
- package/dist/payments/index.d.ts +55 -0
- package/dist/payments/index.js +6 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/platform/index.d.ts +645 -0
- package/dist/platform/index.js +8 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/pos-D1jkkFl0.d.ts +885 -0
- package/dist/product-p09zXkXB.d.ts +260 -0
- package/dist/purchase-24BGT2HA.js +5 -0
- package/dist/purchase-24BGT2HA.js.map +1 -0
- package/dist/request-652PS6VR.js +5 -0
- package/dist/request-652PS6VR.js.map +1 -0
- package/dist/sales/index.d.ts +585 -0
- package/dist/sales/index.js +9 -0
- package/dist/sales/index.js.map +1 -0
- package/dist/server.d.ts +120 -0
- package/dist/server.js +27 -0
- package/dist/server.js.map +1 -0
- package/dist/size-guide-DgjzjM5P.d.ts +554 -0
- package/dist/stock-DEApGC-w.d.ts +632 -0
- package/dist/stock-OOUW57VQ.js +5 -0
- package/dist/stock-OOUW57VQ.js.map +1 -0
- package/dist/supplier-OC6JAWV6.js +5 -0
- package/dist/supplier-OC6JAWV6.js.map +1 -0
- package/dist/transaction/index.d.ts +104 -0
- package/dist/transaction/index.js +8 -0
- package/dist/transaction/index.js.map +1 -0
- package/dist/transaction-BTmoHpWh.d.ts +428 -0
- package/dist/transaction-u5oaNuav.d.ts +84 -0
- package/dist/transfer-7SYSH3RG.js +5 -0
- package/dist/transfer-7SYSH3RG.js.map +1 -0
- package/dist/user-data-DdLjAGwO.d.ts +132 -0
- package/package.json +146 -0
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
import { purchaseApi } from './chunk-6RYGA6MF.js';
|
|
2
|
+
import { transferApi } from './chunk-FA7QFJ2G.js';
|
|
3
|
+
import { requestApi } from './chunk-QO5AGZFP.js';
|
|
4
|
+
import { movementApi } from './chunk-SZYWG5IB.js';
|
|
5
|
+
import { adjustmentApi } from './chunk-R5Z7NYLH.js';
|
|
6
|
+
import { supplierApi } from './chunk-WUOQK7BO.js';
|
|
7
|
+
import { stockApi } from './chunk-KZIGRIQG.js';
|
|
8
|
+
import { posApi } from './chunk-66OQAZSL.js';
|
|
9
|
+
import { createCrudHooks } from './chunk-B6MPVOV7.js';
|
|
10
|
+
import { getToastHandler } from './chunk-U3XT35GZ.js';
|
|
11
|
+
import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
12
|
+
import { useMemo } from 'react';
|
|
13
|
+
|
|
14
|
+
// src/inventory/api/index.ts
|
|
15
|
+
var inventoryApis = {
|
|
16
|
+
stock: () => import('./stock-OOUW57VQ.js').then((m) => m.stockApi),
|
|
17
|
+
purchase: () => import('./purchase-24BGT2HA.js').then((m) => m.purchaseApi),
|
|
18
|
+
transfer: () => import('./transfer-7SYSH3RG.js').then((m) => m.transferApi),
|
|
19
|
+
request: () => import('./request-652PS6VR.js').then((m) => m.requestApi),
|
|
20
|
+
movement: () => import('./movement-7MV3ADY5.js').then((m) => m.movementApi),
|
|
21
|
+
adjustment: () => import('./adjustment-DTSLM7AN.js').then((m) => m.adjustmentApi),
|
|
22
|
+
supplier: () => import('./supplier-OC6JAWV6.js').then((m) => m.supplierApi)
|
|
23
|
+
};
|
|
24
|
+
var INVENTORY_KEYS = {
|
|
25
|
+
all: ["inventory"],
|
|
26
|
+
products: (branchId) => [...INVENTORY_KEYS.all, "products", branchId],
|
|
27
|
+
productsList: (branchId, params) => [...INVENTORY_KEYS.products(branchId), params],
|
|
28
|
+
lookup: (code, branchId) => [...INVENTORY_KEYS.all, "lookup", code, branchId]
|
|
29
|
+
};
|
|
30
|
+
function useInventory(token, branchId, filters = {}, options = {}) {
|
|
31
|
+
const queryKey = INVENTORY_KEYS.productsList(branchId, filters);
|
|
32
|
+
const { data, isLoading, isFetching, error, refetch } = useQuery({
|
|
33
|
+
queryKey,
|
|
34
|
+
queryFn: () => posApi.getProducts({
|
|
35
|
+
token,
|
|
36
|
+
branchId,
|
|
37
|
+
category: filters.category,
|
|
38
|
+
search: filters.search,
|
|
39
|
+
inStockOnly: filters.inStockOnly,
|
|
40
|
+
lowStockOnly: filters.lowStockOnly,
|
|
41
|
+
after: filters.after,
|
|
42
|
+
limit: filters.limit || 50,
|
|
43
|
+
sort: filters.sort || "name"
|
|
44
|
+
}),
|
|
45
|
+
enabled: !!token && options.enabled !== false,
|
|
46
|
+
staleTime: 30 * 1e3,
|
|
47
|
+
// 30 seconds - inventory changes frequently
|
|
48
|
+
refetchOnWindowFocus: true
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
items: data?.docs || [],
|
|
52
|
+
summary: data?.summary || { totalItems: 0, totalQuantity: 0, lowStockCount: 0, outOfStockCount: 0 },
|
|
53
|
+
branch: data?.branch || { _id: "", code: "", name: "" },
|
|
54
|
+
hasMore: data?.hasMore || false,
|
|
55
|
+
nextCursor: data?.next || null,
|
|
56
|
+
isLoading,
|
|
57
|
+
isFetching,
|
|
58
|
+
error,
|
|
59
|
+
refetch
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function useInventoryLookup(token, code, branchId, options = {}) {
|
|
63
|
+
return useQuery({
|
|
64
|
+
queryKey: INVENTORY_KEYS.lookup(code, branchId),
|
|
65
|
+
queryFn: () => posApi.lookup({ token, code, branchId }),
|
|
66
|
+
enabled: !!token && !!code && code.length >= 2 && options.enabled !== false,
|
|
67
|
+
staleTime: 10 * 1e3,
|
|
68
|
+
// 10 seconds
|
|
69
|
+
retry: false
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function useStockActions(token) {
|
|
73
|
+
const queryClient = useQueryClient();
|
|
74
|
+
const toast = getToastHandler();
|
|
75
|
+
const invalidateStockQueries = (branchId) => {
|
|
76
|
+
queryClient.invalidateQueries({
|
|
77
|
+
queryKey: INVENTORY_KEYS.products(branchId)
|
|
78
|
+
});
|
|
79
|
+
queryClient.invalidateQueries({
|
|
80
|
+
queryKey: ["pos", "products", branchId]
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
const adjustMutation = useMutation({
|
|
84
|
+
mutationFn: (data) => adjustmentApi.create({ token, data }),
|
|
85
|
+
onSuccess: (_, variables) => {
|
|
86
|
+
invalidateStockQueries(variables.branchId);
|
|
87
|
+
toast.success("Stock adjusted successfully");
|
|
88
|
+
},
|
|
89
|
+
onError: (error) => {
|
|
90
|
+
toast.error(error.message || "Failed to adjust stock");
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const setStockMutation = useMutation({
|
|
94
|
+
mutationFn: ({
|
|
95
|
+
productId,
|
|
96
|
+
quantity,
|
|
97
|
+
branchId,
|
|
98
|
+
variantSku,
|
|
99
|
+
notes
|
|
100
|
+
}) => adjustmentApi.create({
|
|
101
|
+
token,
|
|
102
|
+
data: {
|
|
103
|
+
productId,
|
|
104
|
+
quantity,
|
|
105
|
+
branchId,
|
|
106
|
+
variantSku,
|
|
107
|
+
mode: "set",
|
|
108
|
+
notes
|
|
109
|
+
}
|
|
110
|
+
}),
|
|
111
|
+
onSuccess: (_, variables) => {
|
|
112
|
+
invalidateStockQueries(variables.branchId);
|
|
113
|
+
toast.success("Stock level updated");
|
|
114
|
+
},
|
|
115
|
+
onError: (error) => {
|
|
116
|
+
toast.error(error.message || "Failed to update stock");
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
const bulkAdjustMutation = useMutation({
|
|
120
|
+
mutationFn: (data) => adjustmentApi.create({
|
|
121
|
+
token,
|
|
122
|
+
data: {
|
|
123
|
+
adjustments: data.adjustments,
|
|
124
|
+
branchId: data.branchId,
|
|
125
|
+
reason: data.reason
|
|
126
|
+
}
|
|
127
|
+
}),
|
|
128
|
+
onSuccess: (_, variables) => {
|
|
129
|
+
invalidateStockQueries(variables.branchId);
|
|
130
|
+
toast.success("Bulk adjustment completed");
|
|
131
|
+
},
|
|
132
|
+
onError: (error) => {
|
|
133
|
+
toast.error(error.message || "Failed to bulk adjust stock");
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
// Adjust stock (add/remove/set)
|
|
138
|
+
adjust: adjustMutation.mutateAsync,
|
|
139
|
+
isAdjusting: adjustMutation.isPending,
|
|
140
|
+
// Set stock directly
|
|
141
|
+
setStock: setStockMutation.mutateAsync,
|
|
142
|
+
isSettingStock: setStockMutation.isPending,
|
|
143
|
+
// Bulk operations
|
|
144
|
+
bulkAdjust: bulkAdjustMutation.mutateAsync,
|
|
145
|
+
isBulkAdjusting: bulkAdjustMutation.isPending,
|
|
146
|
+
// Combined loading state
|
|
147
|
+
isLoading: adjustMutation.isPending || setStockMutation.isPending || bulkAdjustMutation.isPending
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function getStockStatus(quantity, lowThreshold = 10) {
|
|
151
|
+
if (quantity === 0) return "out";
|
|
152
|
+
if (quantity <= lowThreshold) return "low";
|
|
153
|
+
return "ok";
|
|
154
|
+
}
|
|
155
|
+
function getStockStatusBadge(status) {
|
|
156
|
+
switch (status) {
|
|
157
|
+
case "out":
|
|
158
|
+
return { variant: "destructive", label: "Out of Stock" };
|
|
159
|
+
case "low":
|
|
160
|
+
return { variant: "warning", label: "Low Stock" };
|
|
161
|
+
case "ok":
|
|
162
|
+
return { variant: "success", label: "In Stock" };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/inventory/hooks/stock.ts
|
|
167
|
+
var stockHooks = createCrudHooks({
|
|
168
|
+
api: stockApi,
|
|
169
|
+
entityKey: "stock",
|
|
170
|
+
singular: "Stock Entry",
|
|
171
|
+
plural: "Stock Entries",
|
|
172
|
+
defaults: {
|
|
173
|
+
staleTime: 2 * 60 * 1e3
|
|
174
|
+
// 2 minutes
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
var {
|
|
178
|
+
KEYS: STOCK_KEYS,
|
|
179
|
+
useList: useStock,
|
|
180
|
+
useDetail: useStockDetail,
|
|
181
|
+
useActions: useStockActions2,
|
|
182
|
+
useNavigation: useStockNavigation
|
|
183
|
+
} = stockHooks;
|
|
184
|
+
var purchaseHooks = createCrudHooks({
|
|
185
|
+
api: purchaseApi,
|
|
186
|
+
entityKey: "purchases",
|
|
187
|
+
singular: "Purchase",
|
|
188
|
+
plural: "Purchases"
|
|
189
|
+
});
|
|
190
|
+
var {
|
|
191
|
+
KEYS: PURCHASE_KEYS,
|
|
192
|
+
useList: usePurchases,
|
|
193
|
+
useDetail: usePurchaseDetail,
|
|
194
|
+
useActions: usePurchaseActions,
|
|
195
|
+
useNavigation: usePurchaseNavigation
|
|
196
|
+
} = purchaseHooks;
|
|
197
|
+
function usePurchaseStateActions(token) {
|
|
198
|
+
const queryClient = useQueryClient();
|
|
199
|
+
const toast = getToastHandler();
|
|
200
|
+
const invalidateAll = () => {
|
|
201
|
+
queryClient.invalidateQueries({ queryKey: PURCHASE_KEYS.all });
|
|
202
|
+
queryClient.invalidateQueries({ queryKey: ["inventory"] });
|
|
203
|
+
queryClient.invalidateQueries({ queryKey: ["stock"] });
|
|
204
|
+
};
|
|
205
|
+
const receive = useMutation({
|
|
206
|
+
mutationFn: async (id) => {
|
|
207
|
+
const response = await purchaseApi.receive({ token, id });
|
|
208
|
+
return response.data;
|
|
209
|
+
},
|
|
210
|
+
onSuccess: () => {
|
|
211
|
+
invalidateAll();
|
|
212
|
+
toast.success("Purchase received - stock added");
|
|
213
|
+
},
|
|
214
|
+
onError: (err) => {
|
|
215
|
+
toast.error(err.message || "Failed to receive purchase");
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
const pay = useMutation({
|
|
219
|
+
mutationFn: async ({ id, amount, method, reference }) => {
|
|
220
|
+
const response = await purchaseApi.pay({ token, id, amount, method, reference });
|
|
221
|
+
return response.data;
|
|
222
|
+
},
|
|
223
|
+
onSuccess: () => {
|
|
224
|
+
invalidateAll();
|
|
225
|
+
toast.success("Payment recorded");
|
|
226
|
+
},
|
|
227
|
+
onError: (err) => {
|
|
228
|
+
toast.error(err.message || "Failed to record payment");
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
const cancel = useMutation({
|
|
232
|
+
mutationFn: async ({ id, reason }) => {
|
|
233
|
+
const response = await purchaseApi.cancel({ token, id, reason });
|
|
234
|
+
return response.data;
|
|
235
|
+
},
|
|
236
|
+
onSuccess: () => {
|
|
237
|
+
invalidateAll();
|
|
238
|
+
toast.success("Purchase cancelled");
|
|
239
|
+
},
|
|
240
|
+
onError: (err) => {
|
|
241
|
+
toast.error(err.message || "Failed to cancel purchase");
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
return {
|
|
245
|
+
receive,
|
|
246
|
+
pay,
|
|
247
|
+
cancel,
|
|
248
|
+
isReceiving: receive.isPending,
|
|
249
|
+
isPaying: pay.isPending,
|
|
250
|
+
isCancelling: cancel.isPending,
|
|
251
|
+
isLoading: receive.isPending || pay.isPending || cancel.isPending
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
var transferHooks = createCrudHooks({
|
|
255
|
+
api: transferApi,
|
|
256
|
+
entityKey: "transfers",
|
|
257
|
+
singular: "Transfer",
|
|
258
|
+
plural: "Transfers"
|
|
259
|
+
});
|
|
260
|
+
var {
|
|
261
|
+
KEYS: TRANSFER_KEYS,
|
|
262
|
+
useList: useTransfers,
|
|
263
|
+
useDetail: useTransferDetail,
|
|
264
|
+
useActions: useTransferActions,
|
|
265
|
+
useNavigation: useTransferNavigation
|
|
266
|
+
} = transferHooks;
|
|
267
|
+
function useTransferStateActions(token) {
|
|
268
|
+
const queryClient = useQueryClient();
|
|
269
|
+
const toast = getToastHandler();
|
|
270
|
+
const invalidateAll = () => {
|
|
271
|
+
queryClient.invalidateQueries({ queryKey: TRANSFER_KEYS.all });
|
|
272
|
+
queryClient.invalidateQueries({ queryKey: ["inventory"] });
|
|
273
|
+
queryClient.invalidateQueries({ queryKey: ["stock"] });
|
|
274
|
+
};
|
|
275
|
+
const approveMutation = useMutation({
|
|
276
|
+
mutationFn: async (id) => {
|
|
277
|
+
const response = await transferApi.approve({ token, id });
|
|
278
|
+
return response.data;
|
|
279
|
+
},
|
|
280
|
+
onSuccess: () => {
|
|
281
|
+
invalidateAll();
|
|
282
|
+
toast.success("Transfer approved");
|
|
283
|
+
},
|
|
284
|
+
onError: (err) => {
|
|
285
|
+
toast.error(err.message || "Failed to approve transfer");
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
const dispatchMutation = useMutation({
|
|
289
|
+
mutationFn: async ({ id, data }) => {
|
|
290
|
+
const response = await transferApi.dispatch({ token, id, data });
|
|
291
|
+
return response.data;
|
|
292
|
+
},
|
|
293
|
+
onSuccess: () => {
|
|
294
|
+
invalidateAll();
|
|
295
|
+
toast.success("Transfer dispatched - stock deducted");
|
|
296
|
+
},
|
|
297
|
+
onError: (err) => {
|
|
298
|
+
toast.error(err.message || "Failed to dispatch transfer");
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
const inTransitMutation = useMutation({
|
|
302
|
+
mutationFn: async (id) => {
|
|
303
|
+
const response = await transferApi.markInTransit({ token, id });
|
|
304
|
+
return response.data;
|
|
305
|
+
},
|
|
306
|
+
onSuccess: () => {
|
|
307
|
+
invalidateAll();
|
|
308
|
+
toast.success("Transfer marked in transit");
|
|
309
|
+
},
|
|
310
|
+
onError: (err) => {
|
|
311
|
+
toast.error(err.message || "Failed to mark transfer in transit");
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
const receiveMutation = useMutation({
|
|
315
|
+
mutationFn: async ({ id, data }) => {
|
|
316
|
+
const response = await transferApi.receive({ token, id, data });
|
|
317
|
+
return response.data;
|
|
318
|
+
},
|
|
319
|
+
onSuccess: () => {
|
|
320
|
+
invalidateAll();
|
|
321
|
+
toast.success("Transfer received - stock added");
|
|
322
|
+
},
|
|
323
|
+
onError: (err) => {
|
|
324
|
+
toast.error(err.message || "Failed to receive transfer");
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
const cancelMutation = useMutation({
|
|
328
|
+
mutationFn: async ({ id, reason }) => {
|
|
329
|
+
const response = await transferApi.cancel({ token, id, reason });
|
|
330
|
+
return response.data;
|
|
331
|
+
},
|
|
332
|
+
onSuccess: () => {
|
|
333
|
+
invalidateAll();
|
|
334
|
+
toast.success("Transfer cancelled");
|
|
335
|
+
},
|
|
336
|
+
onError: (err) => {
|
|
337
|
+
toast.error(err.message || "Failed to cancel transfer");
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
return {
|
|
341
|
+
approve: async (id) => {
|
|
342
|
+
return approveMutation.mutateAsync(id);
|
|
343
|
+
},
|
|
344
|
+
isApproving: approveMutation.isPending,
|
|
345
|
+
dispatch: async (params) => {
|
|
346
|
+
return dispatchMutation.mutateAsync(params);
|
|
347
|
+
},
|
|
348
|
+
isDispatching: dispatchMutation.isPending,
|
|
349
|
+
inTransit: async (id) => {
|
|
350
|
+
return inTransitMutation.mutateAsync(id);
|
|
351
|
+
},
|
|
352
|
+
isMarkingInTransit: inTransitMutation.isPending,
|
|
353
|
+
receive: async (params) => {
|
|
354
|
+
return receiveMutation.mutateAsync(params);
|
|
355
|
+
},
|
|
356
|
+
isReceiving: receiveMutation.isPending,
|
|
357
|
+
cancel: async (params) => {
|
|
358
|
+
return cancelMutation.mutateAsync(params);
|
|
359
|
+
},
|
|
360
|
+
isCancelling: cancelMutation.isPending,
|
|
361
|
+
isLoading: approveMutation.isPending || dispatchMutation.isPending || inTransitMutation.isPending || receiveMutation.isPending || cancelMutation.isPending
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
var TRANSFER_STATS_KEYS = {
|
|
365
|
+
all: ["transfers", "stats"],
|
|
366
|
+
byBranch: (branchId) => ["transfers", "stats", branchId]
|
|
367
|
+
};
|
|
368
|
+
function useTransferStats(token, branchId, options = {}) {
|
|
369
|
+
return useQuery({
|
|
370
|
+
queryKey: TRANSFER_STATS_KEYS.byBranch(branchId),
|
|
371
|
+
queryFn: () => transferApi.stats({ token, params: branchId ? { branchId } : {} }),
|
|
372
|
+
enabled: !!token && options.enabled !== false,
|
|
373
|
+
staleTime: 30 * 1e3,
|
|
374
|
+
// 30 seconds
|
|
375
|
+
select: (data) => data?.data
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// src/inventory/hooks/adjustment.ts
|
|
380
|
+
var adjustmentHooks = createCrudHooks({
|
|
381
|
+
api: adjustmentApi,
|
|
382
|
+
entityKey: "adjustments",
|
|
383
|
+
singular: "Adjustment",
|
|
384
|
+
plural: "Adjustments"
|
|
385
|
+
});
|
|
386
|
+
var {
|
|
387
|
+
KEYS: ADJUSTMENT_KEYS,
|
|
388
|
+
useList: useAdjustments,
|
|
389
|
+
useDetail: useAdjustmentDetail,
|
|
390
|
+
useActions: useAdjustmentActions,
|
|
391
|
+
useNavigation: useAdjustmentNavigation
|
|
392
|
+
} = adjustmentHooks;
|
|
393
|
+
var MOVEMENT_KEYS = {
|
|
394
|
+
all: ["inventory", "movements"],
|
|
395
|
+
list: (params) => [...MOVEMENT_KEYS.all, "list", params],
|
|
396
|
+
lowStock: (params) => [...MOVEMENT_KEYS.all, "low-stock", params]
|
|
397
|
+
};
|
|
398
|
+
function useMovements(token, params, options = {}) {
|
|
399
|
+
const { data, isLoading, isFetching, error, refetch } = useQuery({
|
|
400
|
+
queryKey: MOVEMENT_KEYS.list(params),
|
|
401
|
+
queryFn: () => movementApi.list({ token, params }),
|
|
402
|
+
enabled: !!token && options.enabled !== false,
|
|
403
|
+
staleTime: options.staleTime ?? 15 * 1e3
|
|
404
|
+
// 15 seconds
|
|
405
|
+
});
|
|
406
|
+
const movements = useMemo(() => {
|
|
407
|
+
if (!data) return [];
|
|
408
|
+
return data.docs || data.data || [];
|
|
409
|
+
}, [data]);
|
|
410
|
+
const pagination = useMemo(() => {
|
|
411
|
+
if (!data) return null;
|
|
412
|
+
const d = data;
|
|
413
|
+
if (d.page === void 0) return null;
|
|
414
|
+
return {
|
|
415
|
+
page: d.page || 1,
|
|
416
|
+
limit: d.limit || 20,
|
|
417
|
+
total: d.total || 0,
|
|
418
|
+
pages: d.pages || 1,
|
|
419
|
+
hasNext: d.hasNext || false,
|
|
420
|
+
hasPrev: d.hasPrev || false
|
|
421
|
+
};
|
|
422
|
+
}, [data]);
|
|
423
|
+
return {
|
|
424
|
+
movements,
|
|
425
|
+
pagination,
|
|
426
|
+
isLoading,
|
|
427
|
+
isFetching,
|
|
428
|
+
error,
|
|
429
|
+
refetch
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
function useLowStock(token, params, options = {}) {
|
|
433
|
+
return useQuery({
|
|
434
|
+
queryKey: MOVEMENT_KEYS.lowStock(params),
|
|
435
|
+
queryFn: () => movementApi.lowStock({ token, params }),
|
|
436
|
+
enabled: !!token && options.enabled !== false,
|
|
437
|
+
staleTime: options.staleTime ?? 60 * 1e3
|
|
438
|
+
// 1 minute
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
function getStockChangeInvalidationKeys() {
|
|
442
|
+
return [
|
|
443
|
+
["inventory"],
|
|
444
|
+
// All inventory product queries
|
|
445
|
+
MOVEMENT_KEYS.all
|
|
446
|
+
// Audit trail (new movements created)
|
|
447
|
+
];
|
|
448
|
+
}
|
|
449
|
+
var REQUEST_KEYS = {
|
|
450
|
+
all: ["inventory", "requests"],
|
|
451
|
+
list: (params) => [...REQUEST_KEYS.all, "list", params],
|
|
452
|
+
pending: () => [...REQUEST_KEYS.all, "pending"],
|
|
453
|
+
detail: (id) => [...REQUEST_KEYS.all, "detail", id]
|
|
454
|
+
};
|
|
455
|
+
function useStockRequests(token, params, options = {}) {
|
|
456
|
+
const { data, isLoading, isFetching, error, refetch } = useQuery({
|
|
457
|
+
queryKey: REQUEST_KEYS.list(params),
|
|
458
|
+
queryFn: () => requestApi.list({ token, params }),
|
|
459
|
+
enabled: !!token && options.enabled !== false,
|
|
460
|
+
staleTime: options.staleTime ?? 15 * 1e3
|
|
461
|
+
});
|
|
462
|
+
const requests = useMemo(() => {
|
|
463
|
+
if (!data) return [];
|
|
464
|
+
return data.docs || data.data || [];
|
|
465
|
+
}, [data]);
|
|
466
|
+
return {
|
|
467
|
+
requests,
|
|
468
|
+
isLoading,
|
|
469
|
+
isFetching,
|
|
470
|
+
error,
|
|
471
|
+
refetch
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
function usePendingStockRequests(token, options = {}) {
|
|
475
|
+
const { data, isLoading, isFetching, error, refetch } = useQuery({
|
|
476
|
+
queryKey: REQUEST_KEYS.pending(),
|
|
477
|
+
queryFn: () => requestApi.listPending({ token }),
|
|
478
|
+
enabled: !!token && options.enabled !== false,
|
|
479
|
+
staleTime: options.staleTime ?? 15 * 1e3
|
|
480
|
+
});
|
|
481
|
+
const requests = useMemo(() => {
|
|
482
|
+
if (!data) return [];
|
|
483
|
+
return data.docs || data.data || [];
|
|
484
|
+
}, [data]);
|
|
485
|
+
return {
|
|
486
|
+
requests,
|
|
487
|
+
isLoading,
|
|
488
|
+
isFetching,
|
|
489
|
+
error,
|
|
490
|
+
refetch
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
function useStockRequestDetail(token, id, options = {}) {
|
|
494
|
+
return useQuery({
|
|
495
|
+
queryKey: REQUEST_KEYS.detail(id || ""),
|
|
496
|
+
queryFn: () => requestApi.getById({ token, id }),
|
|
497
|
+
enabled: !!token && !!id && options.enabled !== false,
|
|
498
|
+
staleTime: options.staleTime ?? 30 * 1e3
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
function useStockRequestActions(token) {
|
|
502
|
+
const queryClient = useQueryClient();
|
|
503
|
+
const toast = getToastHandler();
|
|
504
|
+
const createMutation = useMutation({
|
|
505
|
+
mutationFn: (data) => requestApi.create({ token, data }),
|
|
506
|
+
onSuccess: () => {
|
|
507
|
+
queryClient.invalidateQueries({ queryKey: REQUEST_KEYS.all });
|
|
508
|
+
toast.success("Stock request created");
|
|
509
|
+
},
|
|
510
|
+
onError: (err) => toast.error(err.message || "Failed to create request")
|
|
511
|
+
});
|
|
512
|
+
const approveMutation = useMutation({
|
|
513
|
+
mutationFn: ({
|
|
514
|
+
id,
|
|
515
|
+
items,
|
|
516
|
+
reviewNotes
|
|
517
|
+
}) => requestApi.approve({ token, id, items, reviewNotes }),
|
|
518
|
+
onSuccess: () => {
|
|
519
|
+
queryClient.invalidateQueries({ queryKey: REQUEST_KEYS.all });
|
|
520
|
+
toast.success("Request approved");
|
|
521
|
+
},
|
|
522
|
+
onError: (err) => toast.error(err.message || "Failed to approve request")
|
|
523
|
+
});
|
|
524
|
+
const rejectMutation = useMutation({
|
|
525
|
+
mutationFn: ({ id, reason }) => requestApi.reject({ token, id, reason }),
|
|
526
|
+
onSuccess: () => {
|
|
527
|
+
queryClient.invalidateQueries({ queryKey: REQUEST_KEYS.all });
|
|
528
|
+
toast.success("Request rejected");
|
|
529
|
+
},
|
|
530
|
+
onError: (err) => toast.error(err.message || "Failed to reject request")
|
|
531
|
+
});
|
|
532
|
+
const fulfillMutation = useMutation({
|
|
533
|
+
mutationFn: ({
|
|
534
|
+
id,
|
|
535
|
+
remarks,
|
|
536
|
+
items,
|
|
537
|
+
transport
|
|
538
|
+
}) => requestApi.fulfill({
|
|
539
|
+
token,
|
|
540
|
+
id,
|
|
541
|
+
remarks,
|
|
542
|
+
items,
|
|
543
|
+
transport,
|
|
544
|
+
documentType: "delivery_challan"
|
|
545
|
+
}),
|
|
546
|
+
onSuccess: () => {
|
|
547
|
+
queryClient.invalidateQueries({ queryKey: REQUEST_KEYS.all });
|
|
548
|
+
queryClient.invalidateQueries({ queryKey: TRANSFER_KEYS.all });
|
|
549
|
+
toast.success("Request fulfilled (transfer created)");
|
|
550
|
+
},
|
|
551
|
+
onError: (err) => toast.error(err.message || "Failed to fulfill request")
|
|
552
|
+
});
|
|
553
|
+
const cancelMutation = useMutation({
|
|
554
|
+
mutationFn: ({ id, reason }) => requestApi.cancel({ token, id, reason }),
|
|
555
|
+
onSuccess: () => {
|
|
556
|
+
queryClient.invalidateQueries({ queryKey: REQUEST_KEYS.all });
|
|
557
|
+
toast.success("Request cancelled");
|
|
558
|
+
},
|
|
559
|
+
onError: (err) => toast.error(err.message || "Failed to cancel request")
|
|
560
|
+
});
|
|
561
|
+
return {
|
|
562
|
+
create: async (data) => {
|
|
563
|
+
const result = await createMutation.mutateAsync(data);
|
|
564
|
+
return result.data;
|
|
565
|
+
},
|
|
566
|
+
isCreating: createMutation.isPending,
|
|
567
|
+
approve: async (params) => {
|
|
568
|
+
const result = await approveMutation.mutateAsync(params);
|
|
569
|
+
return result.data;
|
|
570
|
+
},
|
|
571
|
+
isApproving: approveMutation.isPending,
|
|
572
|
+
reject: async (params) => {
|
|
573
|
+
const result = await rejectMutation.mutateAsync(params);
|
|
574
|
+
return result.data;
|
|
575
|
+
},
|
|
576
|
+
isRejecting: rejectMutation.isPending,
|
|
577
|
+
fulfill: async (params) => {
|
|
578
|
+
const result = await fulfillMutation.mutateAsync(params);
|
|
579
|
+
return result.data;
|
|
580
|
+
},
|
|
581
|
+
isFulfilling: fulfillMutation.isPending,
|
|
582
|
+
cancel: async (params) => {
|
|
583
|
+
const result = await cancelMutation.mutateAsync(params);
|
|
584
|
+
return result.data;
|
|
585
|
+
},
|
|
586
|
+
isCancelling: cancelMutation.isPending,
|
|
587
|
+
isLoading: createMutation.isPending || approveMutation.isPending || rejectMutation.isPending || fulfillMutation.isPending || cancelMutation.isPending
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
function getTransferStateInvalidationKeys() {
|
|
591
|
+
return [
|
|
592
|
+
TRANSFER_KEYS.all,
|
|
593
|
+
// Transfer list and details
|
|
594
|
+
REQUEST_KEYS.all
|
|
595
|
+
// If transfer was from request fulfillment
|
|
596
|
+
];
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// src/inventory/hooks/supplier.ts
|
|
600
|
+
var supplierHooks = createCrudHooks({
|
|
601
|
+
api: supplierApi,
|
|
602
|
+
entityKey: "suppliers",
|
|
603
|
+
singular: "Supplier",
|
|
604
|
+
plural: "Suppliers"
|
|
605
|
+
});
|
|
606
|
+
var {
|
|
607
|
+
KEYS: SUPPLIER_KEYS,
|
|
608
|
+
useList: useSuppliers,
|
|
609
|
+
useDetail: useSupplierDetail,
|
|
610
|
+
useActions: useSupplierActions,
|
|
611
|
+
useNavigation: useSupplierNavigation
|
|
612
|
+
} = supplierHooks;
|
|
613
|
+
|
|
614
|
+
export { ADJUSTMENT_KEYS, INVENTORY_KEYS, MOVEMENT_KEYS, PURCHASE_KEYS, REQUEST_KEYS, STOCK_KEYS, SUPPLIER_KEYS, TRANSFER_KEYS, TRANSFER_STATS_KEYS, adjustmentHooks, getStockChangeInvalidationKeys, getStockStatus, getStockStatusBadge, getTransferStateInvalidationKeys, inventoryApis, purchaseHooks, stockHooks, supplierHooks, transferHooks, useAdjustmentActions, useAdjustmentDetail, useAdjustmentNavigation, useAdjustments, useInventory, useInventoryLookup, useLowStock, useMovements, usePendingStockRequests, usePurchaseActions, usePurchaseDetail, usePurchaseNavigation, usePurchaseStateActions, usePurchases, useStock, useStockActions, useStockDetail, useStockNavigation, useStockRequestActions, useStockRequestDetail, useStockRequests, useSupplierActions, useSupplierDetail, useSupplierNavigation, useSuppliers, useTransferActions, useTransferDetail, useTransferNavigation, useTransferStateActions, useTransferStats, useTransfers };
|
|
615
|
+
//# sourceMappingURL=chunk-IXMWZJLV.js.map
|
|
616
|
+
//# sourceMappingURL=chunk-IXMWZJLV.js.map
|