@appcorp/stellar-solutions-invoice-module 0.1.73 → 0.1.74

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.
@@ -311,7 +311,23 @@ var useInvoiceState = function () {
311
311
  var _a, _b;
312
312
  return (__assign(__assign({}, item), { price: (_a = item === null || item === void 0 ? void 0 : item.product) === null || _a === void 0 ? void 0 : _a.salePrice, id: item === null || item === void 0 ? void 0 : item.productId, quantity: item === null || item === void 0 ? void 0 : item.quantity, rowTotal: parseFloat((_b = item === null || item === void 0 ? void 0 : item.product) === null || _b === void 0 ? void 0 : _b.salePrice) * parseInt(item.quantity) }));
313
313
  });
314
- var updatedData = __assign(__assign(__assign(__assign({}, data), { mode: "Edit", companyId: (data === null || data === void 0 ? void 0 : data.companyId) || "", customerId: (data === null || data === void 0 ? void 0 : data.customerId) || "" }), (((_b = data === null || data === void 0 ? void 0 : data.customer) === null || _b === void 0 ? void 0 : _b.id) && {
314
+ // Normalize currency: API may return currency id or code. Prefer storing id.
315
+ var normalizedCurrency_1 = data.currency;
316
+ if (normalizedCurrency_1) {
317
+ var foundById = currencies.find(function (_a) {
318
+ var id = _a.id;
319
+ return id === normalizedCurrency_1;
320
+ });
321
+ if (!foundById) {
322
+ var foundByCode = currencies.find(function (_a) {
323
+ var code = _a.code;
324
+ return code === normalizedCurrency_1;
325
+ });
326
+ if (foundByCode)
327
+ normalizedCurrency_1 = foundByCode.id;
328
+ }
329
+ }
330
+ var updatedData = __assign(__assign(__assign(__assign(__assign({}, data), (normalizedCurrency_1 && { currency: normalizedCurrency_1 })), { mode: "Edit", companyId: (data === null || data === void 0 ? void 0 : data.companyId) || "", customerId: (data === null || data === void 0 ? void 0 : data.customerId) || "" }), (((_b = data === null || data === void 0 ? void 0 : data.customer) === null || _b === void 0 ? void 0 : _b.id) && {
315
331
  customer: __assign({}, data.customer),
316
332
  })), { servicesList: __spreadArray([], updatedServices, true).filter(function (item) { return item.name; }), productsList: __spreadArray([], updatedProducts, true).filter(function (item) { return item.id; }), companiesList: [__assign({}, data.company)] });
317
333
  if ((_c = updatedData === null || updatedData === void 0 ? void 0 : updatedData.company) === null || _c === void 0 ? void 0 : _c.name) {
@@ -343,7 +359,7 @@ var useInvoiceState = function () {
343
359
  });
344
360
  }
345
361
  }
346
- }, [t, showErrorToast]);
362
+ }, [t, showErrorToast, currencies]);
347
363
  var deleteCallback = (0, react_1.useCallback)(function (_a) {
348
364
  var data = _a.data, error = _a.error;
349
365
  if (error) {
@@ -571,9 +587,9 @@ var useInvoiceState = function () {
571
587
  // CRUD Operation Handlers
572
588
  // ---------------------------------------------------------------------------
573
589
  var handleEdit = (0, react_1.useCallback)(function (id) {
574
- byIdFetchNow(undefined, {
590
+ byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, {
591
+ params: { id: id },
575
592
  body: JSON.stringify({
576
- id: id,
577
593
  includeCompany: true,
578
594
  includeCustomer: true,
579
595
  includePayments: true,
@@ -588,9 +604,7 @@ var useInvoiceState = function () {
588
604
  router.push("/erp/payment");
589
605
  }, [router]);
590
606
  var handleDelete = (0, react_1.useCallback)(function (id) {
591
- deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
592
- body: JSON.stringify({ id: id }),
593
- });
607
+ deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, { params: { id: id } });
594
608
  // eslint-disable-next-line react-hooks/exhaustive-deps
595
609
  }, []);
596
610
  // ---------------------------------------------------------------------------
@@ -609,11 +623,11 @@ var useInvoiceState = function () {
609
623
  payload: { disableSaveButton: true },
610
624
  });
611
625
  (0, util_functions_1.validateForm)({
612
- params: __assign(__assign({}, updateParams), { currency: updateParams.currency || defaultCurrency.code, taxRate: updateParams.taxRate || defaultTax.taxRate }),
626
+ params: __assign(__assign({}, updateParams), { currency: updateParams.currency || defaultCurrency.id, taxRate: updateParams.taxRate || defaultTax.taxRate }),
613
627
  schema: validate_1.formValid,
614
628
  successCallback: function () {
615
629
  updateFetchNow(undefined, {
616
- body: JSON.stringify(__assign(__assign({}, updateParams), { products: state.productsList.filter(function (item) { return item.id; }), services: state.servicesList.filter(function (item) { return item.name; }), currency: updateParams.currency || defaultCurrency.code, taxRate: updateParams.taxRate || defaultTax.taxRate })),
630
+ body: JSON.stringify(__assign(__assign({}, updateParams), { products: state.productsList.filter(function (item) { return item.id; }), services: state.servicesList.filter(function (item) { return item.name; }), currency: updateParams.currency || defaultCurrency.id, taxRate: updateParams.taxRate || defaultTax.taxRate })),
617
631
  });
618
632
  },
619
633
  errorCallback: function (e) {
@@ -23,7 +23,6 @@ var ProductsSection = function () {
23
23
  if (!productsList || productsList.length === 0) {
24
24
  return null;
25
25
  }
26
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
26
  var handleProductSearch = function (_searchQuery) {
28
27
  // Product search is handled by getProducts filter in context
29
28
  // This is a placeholder to satisfy CompanyCombobox props
@@ -83,13 +83,14 @@ var react_1 = __importStar(require("react"));
83
83
  var next_themes_1 = require("next-themes");
84
84
  var next_intl_1 = require("next-intl");
85
85
  var util_functions_1 = require("@react-pakistan/util-functions");
86
+ var context_1 = require("@appcorp/stellar-solutions-modules/global-modules/preferences/context");
86
87
  var actions_1 = require("./actions");
87
88
  var constants_1 = require("./constants");
88
89
  var reducer_1 = require("./reducer");
89
90
  var toast_utils_1 = require("@appcorp/shadcn/lib/toast-utils");
90
91
  var types_1 = require("./types");
91
92
  var validate_1 = require("./validate");
92
- var context_1 = require("../invoice/context");
93
+ var context_2 = require("../invoice/context");
93
94
  // ============================================================================
94
95
  // MAIN HOOK
95
96
  // ============================================================================
@@ -97,10 +98,11 @@ var usePaymentState = function () {
97
98
  // ---------------------------------------------------------------------------
98
99
  // STATE & CORE HOOKS
99
100
  // ---------------------------------------------------------------------------
100
- var invoices = (0, context_1.useInvoiceStateContext)().invoices;
101
+ var invoices = (0, context_2.useInvoiceStateContext)().invoices;
101
102
  var _a = (0, react_1.useReducer)(reducer_1.paymentReducer, reducer_1.initialPaymentState), state = _a[0], dispatch = _a[1];
102
103
  var theme = (0, next_themes_1.useTheme)().theme;
103
104
  var t = (0, next_intl_1.useTranslations)("payment");
105
+ var currencies = (0, context_1.usePreferenceStateContext)().currencies;
104
106
  // const tCommon = useTranslations("common");
105
107
  // ---------------------------------------------------------------------------
106
108
  // DEBOUNCED VALUES
@@ -195,7 +197,23 @@ var usePaymentState = function () {
195
197
  showErrorToast(t("messagesNetworkError"));
196
198
  }
197
199
  if (data) {
198
- var updatedData = __assign({}, data);
200
+ // Normalize currency to id if API returns code
201
+ var normalizedCurrency_1 = data.currency;
202
+ if (normalizedCurrency_1) {
203
+ var foundById = currencies.find(function (_a) {
204
+ var id = _a.id;
205
+ return id === normalizedCurrency_1;
206
+ });
207
+ if (!foundById) {
208
+ var foundByCode = currencies.find(function (_a) {
209
+ var code = _a.code;
210
+ return code === normalizedCurrency_1;
211
+ });
212
+ if (foundByCode)
213
+ normalizedCurrency_1 = foundByCode.id;
214
+ }
215
+ }
216
+ var updatedData = __assign(__assign({}, data), (normalizedCurrency_1 && { currency: normalizedCurrency_1 }));
199
217
  dispatch({
200
218
  payload: { form: updatedData },
201
219
  type: actions_1.PAYMENT_ACTION_TYPES.SET_FORM,
@@ -205,7 +223,7 @@ var usePaymentState = function () {
205
223
  type: actions_1.PAYMENT_ACTION_TYPES.SET_DRAWER,
206
224
  });
207
225
  }
208
- }, [dispatch, showErrorToast, t]);
226
+ }, [dispatch, showErrorToast, t, currencies]);
209
227
  var deleteCallback = (0, react_1.useCallback)(function (_a) {
210
228
  var data = _a.data, error = _a.error;
211
229
  if (error) {
@@ -224,7 +242,7 @@ var usePaymentState = function () {
224
242
  // ---------------------------------------------------------------------------
225
243
  // MODULE ENTITY HOOK
226
244
  // ---------------------------------------------------------------------------
227
- var _b = (0, util_functions_1.useModuleEntity)({
245
+ var _b = (0, util_functions_1.useModuleEntityV2)({
228
246
  byIdCallback: byIdCallback,
229
247
  byIdParams: byIdParams,
230
248
  deleteCallback: deleteCallback,
@@ -245,13 +263,18 @@ var usePaymentState = function () {
245
263
  // ---------------------------------------------------------------------------
246
264
  // EFFECTS
247
265
  // ---------------------------------------------------------------------------
266
+ var defaultCurrency = (0, react_1.useMemo)(function () {
267
+ return currencies.filter(function (_a) {
268
+ var isDefault = _a.isDefault;
269
+ return isDefault;
270
+ })[0];
271
+ }, [currencies]);
248
272
  (0, react_1.useEffect)(function () {
249
273
  listFetchNow();
250
274
  // eslint-disable-next-line
251
275
  }, [debouncedQuery, state.currentPage, state.pageLimit]);
252
276
  (0, react_1.useEffect)(function () {
253
277
  var invoiceId = (0, util_functions_1.getStorageValue)("paymentInvoiceId");
254
- console.log("_>>>", invoiceId);
255
278
  if (invoiceId) {
256
279
  var invoice = invoices.filter(function (_a) {
257
280
  var id = _a.id;
@@ -262,9 +285,28 @@ var usePaymentState = function () {
262
285
  type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
263
286
  payload: { key: "quoteInvoiceId", value: invoiceId },
264
287
  });
288
+ // Normalize invoice currency to id (API may return id or code)
289
+ var invoiceCurrency_1 = invoice === null || invoice === void 0 ? void 0 : invoice.currency;
290
+ if (invoiceCurrency_1) {
291
+ var foundById = currencies.find(function (_a) {
292
+ var id = _a.id;
293
+ return id === invoiceCurrency_1;
294
+ });
295
+ if (!foundById) {
296
+ var foundByCode = currencies.find(function (_a) {
297
+ var code = _a.code;
298
+ return code === invoiceCurrency_1;
299
+ });
300
+ if (foundByCode)
301
+ invoiceCurrency_1 = foundByCode.id;
302
+ }
303
+ }
265
304
  dispatch({
266
305
  type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
267
- payload: { key: "currency", value: invoice === null || invoice === void 0 ? void 0 : invoice.currency },
306
+ payload: {
307
+ key: "currency",
308
+ value: invoiceCurrency_1 || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id),
309
+ },
268
310
  });
269
311
  dispatch({
270
312
  type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
@@ -284,7 +326,8 @@ var usePaymentState = function () {
284
326
  });
285
327
  }
286
328
  }
287
- }, [invoices]);
329
+ }, [invoices, currencies, defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id]);
330
+ // include currencies and defaultCurrency in deps because we read them when initializing form
288
331
  // ---------------------------------------------------------------------------
289
332
  // DRAWER & MODAL HANDLERS
290
333
  // ---------------------------------------------------------------------------
@@ -305,11 +348,11 @@ var usePaymentState = function () {
305
348
  // ---------------------------------------------------------------------------
306
349
  var handleView = (0, react_1.useCallback)(function (id) {
307
350
  byIdFetchNow(undefined, {
308
- body: JSON.stringify({
351
+ params: {
309
352
  id: id,
310
353
  includeQuoteInvoice: true,
311
354
  includePaymentMode: true,
312
- }),
355
+ },
313
356
  });
314
357
  }, [byIdFetchNow]);
315
358
  // const handleDelete = useCallback(
@@ -332,16 +375,16 @@ var usePaymentState = function () {
332
375
  type: actions_1.PAYMENT_ACTION_TYPES.SET_ERRORS,
333
376
  });
334
377
  },
335
- params: updateParams,
378
+ params: __assign(__assign({}, updateParams), { currency: updateParams.currency || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id) }),
336
379
  schema: validate_1.formValidation,
337
380
  successCallback: function () {
338
381
  updateFetchNow(undefined, {
339
- body: JSON.stringify(__assign({}, updateParams)),
382
+ body: JSON.stringify(__assign(__assign({}, updateParams), { currency: updateParams.currency || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id) })),
340
383
  });
341
384
  },
342
385
  });
343
386
  (0, util_functions_1.removeStorageValue)("paymentInvoiceId");
344
- }, [updateFetchNow, updateParams, dispatch]);
387
+ }, [updateFetchNow, updateParams, dispatch, defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id]);
345
388
  // ---------------------------------------------------------------------------
346
389
  // FORM HANDLERS
347
390
  // ---------------------------------------------------------------------------
@@ -428,7 +471,7 @@ var usePaymentState = function () {
428
471
  label: t("actionsButtonView"),
429
472
  order: 1,
430
473
  },
431
- ]; }, []);
474
+ ]; }, [handleView, t]);
432
475
  // ---------------------------------------------------------------------------
433
476
  // RETURN STATE
434
477
  // ---------------------------------------------------------------------------
@@ -306,7 +306,23 @@ var useQuoteState = function () {
306
306
  var _a, _b;
307
307
  return (__assign(__assign({}, item), { price: (_a = item === null || item === void 0 ? void 0 : item.product) === null || _a === void 0 ? void 0 : _a.salePrice, id: item === null || item === void 0 ? void 0 : item.productId, quantity: item === null || item === void 0 ? void 0 : item.quantity, rowTotal: parseFloat((_b = item === null || item === void 0 ? void 0 : item.product) === null || _b === void 0 ? void 0 : _b.salePrice) * parseInt(item.quantity) }));
308
308
  });
309
- var updatedData = __assign(__assign(__assign(__assign({}, data), { mode: "Edit", companyId: (data === null || data === void 0 ? void 0 : data.companyId) || "", customerId: (data === null || data === void 0 ? void 0 : data.customerId) || "" }), (((_b = data === null || data === void 0 ? void 0 : data.customer) === null || _b === void 0 ? void 0 : _b.id) && {
309
+ // Normalize currency: API may return currency id or code. Store id in state.
310
+ var normalizedCurrency_1 = data.currency;
311
+ if (normalizedCurrency_1) {
312
+ var foundById = currencies.find(function (_a) {
313
+ var id = _a.id;
314
+ return id === normalizedCurrency_1;
315
+ });
316
+ if (!foundById) {
317
+ var foundByCode = currencies.find(function (_a) {
318
+ var code = _a.code;
319
+ return code === normalizedCurrency_1;
320
+ });
321
+ if (foundByCode)
322
+ normalizedCurrency_1 = foundByCode.id;
323
+ }
324
+ }
325
+ var updatedData = __assign(__assign(__assign(__assign(__assign({}, data), (normalizedCurrency_1 && { currency: normalizedCurrency_1 })), { mode: "Edit", companyId: (data === null || data === void 0 ? void 0 : data.companyId) || "", customerId: (data === null || data === void 0 ? void 0 : data.customerId) || "" }), (((_b = data === null || data === void 0 ? void 0 : data.customer) === null || _b === void 0 ? void 0 : _b.id) && {
310
326
  customer: __assign({}, data.customer),
311
327
  })), { servicesList: __spreadArray([], updatedServices, true).filter(function (item) { return item.name; }), productsList: __spreadArray([], updatedProducts, true).filter(function (item) { return item.id; }), companiesList: [__assign({}, data.company)] });
312
328
  if ((_c = updatedData === null || updatedData === void 0 ? void 0 : updatedData.company) === null || _c === void 0 ? void 0 : _c.name) {
@@ -338,7 +354,7 @@ var useQuoteState = function () {
338
354
  });
339
355
  }
340
356
  }
341
- }, [t, showErrorToast]);
357
+ }, [t, showErrorToast, currencies]);
342
358
  var deleteCallback = (0, react_1.useCallback)(function (_a) {
343
359
  var data = _a.data, error = _a.error;
344
360
  if (error) {
@@ -572,9 +588,9 @@ var useQuoteState = function () {
572
588
  // CRUD Operation Handlers
573
589
  // ---------------------------------------------------------------------------
574
590
  var handleEdit = (0, react_1.useCallback)(function (id) {
575
- byIdFetchNow(undefined, {
591
+ byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, {
592
+ params: { id: id },
576
593
  body: JSON.stringify({
577
- id: id,
578
594
  includeCompany: true,
579
595
  includeCustomer: true,
580
596
  includePayments: true,
@@ -585,9 +601,7 @@ var useQuoteState = function () {
585
601
  // eslint-disable-next-line react-hooks/exhaustive-deps
586
602
  }, []);
587
603
  var handleDelete = (0, react_1.useCallback)(function (id) {
588
- deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
589
- body: JSON.stringify({ id: id }),
590
- });
604
+ deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, { params: { id: id } });
591
605
  // eslint-disable-next-line react-hooks/exhaustive-deps
592
606
  }, []);
593
607
  // ---------------------------------------------------------------------------
@@ -606,11 +620,11 @@ var useQuoteState = function () {
606
620
  payload: { disableSaveButton: true },
607
621
  });
608
622
  (0, util_functions_1.validateForm)({
609
- params: __assign(__assign({}, updateParams), { currency: updateParams.currency || defaultCurrency.code, taxRate: updateParams.taxRate || defaultTax.taxRate }),
623
+ params: __assign(__assign({}, updateParams), { currency: updateParams.currency || defaultCurrency.id, taxRate: updateParams.taxRate || defaultTax.taxRate }),
610
624
  schema: validate_1.formValid,
611
625
  successCallback: function () {
612
626
  updateFetchNow(undefined, {
613
- body: JSON.stringify(__assign(__assign({}, updateParams), { products: state.productsList.filter(function (item) { return item.id; }), services: state.servicesList.filter(function (item) { return item.name; }), currency: updateParams.currency || defaultCurrency.code, taxRate: updateParams.taxRate || defaultTax.taxRate })),
627
+ body: JSON.stringify(__assign(__assign({}, updateParams), { products: state.productsList.filter(function (item) { return item.id; }), services: state.servicesList.filter(function (item) { return item.name; }), currency: updateParams.currency || defaultCurrency.id, taxRate: updateParams.taxRate || defaultTax.taxRate })),
614
628
  });
615
629
  },
616
630
  errorCallback: function (e) {
@@ -23,7 +23,6 @@ var ProductsSection = function () {
23
23
  if (!productsList || productsList.length === 0) {
24
24
  return null;
25
25
  }
26
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
26
  var handleProductSearch = function (_searchQuery) {
28
27
  // Product search is handled by getProducts filter in context
29
28
  // This is a placeholder to satisfy CompanyCombobox props
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/stellar-solutions-invoice-module",
3
- "version": "0.1.73",
3
+ "version": "0.1.74",
4
4
  "scripts": {
5
5
  "automate": "./automate.sh",
6
6
  "build": "yarn clean && yarn build:ts && cp package.json lib && cp README.md lib && cp yarn.lock lib",
@@ -8,7 +8,8 @@
8
8
  "build:ts": "tsc --project tsconfig.build.json",
9
9
  "clean": "yarn rimraf ./lib",
10
10
  "dev": "next dev",
11
- "lint": "next lint",
11
+ "lint": "eslint . --ext .js,.jsx,.ts,.tsx --max-warnings=0",
12
+ "lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
12
13
  "major": "npm version major",
13
14
  "minor": "npm version minor",
14
15
  "patch": "npm version patch",
@@ -19,11 +20,11 @@
19
20
  "upgrade:own": "ncu -f '@appcorp/app-corp-vista, @appcorp/shadcn, @appcorp/stellar-solutions-company-module, @appcorp/stellar-solutions-modules, @appcorp/stellar-solutions-product-module, @react-pakistan/util-functions' -u"
20
21
  },
21
22
  "devDependencies": {
22
- "@appcorp/app-corp-vista": "^0.3.84",
23
- "@appcorp/shadcn": "^1.1.16",
24
- "@appcorp/stellar-solutions-company-module": "^0.1.45",
25
- "@appcorp/stellar-solutions-modules": "^0.1.68",
26
- "@appcorp/stellar-solutions-product-module": "^0.2.24",
23
+ "@appcorp/app-corp-vista": "^0.3.94",
24
+ "@appcorp/shadcn": "^1.1.33",
25
+ "@appcorp/stellar-solutions-company-module": "^0.1.48",
26
+ "@appcorp/stellar-solutions-modules": "^0.1.75",
27
+ "@appcorp/stellar-solutions-product-module": "^0.2.30",
27
28
  "@eslint/eslintrc": "^3",
28
29
  "@headlessui/react": "^2",
29
30
  "@heroicons/react": "^2",
@@ -36,7 +37,7 @@
36
37
  "@radix-ui/react-separator": "^1",
37
38
  "@radix-ui/react-slot": "^1",
38
39
  "@radix-ui/react-switch": "^1",
39
- "@react-pakistan/util-functions": "^1.24.98",
40
+ "@react-pakistan/util-functions": "^1.25.18",
40
41
  "@supabase/supabase-js": "^2",
41
42
  "@tailwindcss/forms": "^0",
42
43
  "@tailwindcss/postcss": "^4",
@@ -50,11 +51,11 @@
50
51
  "dayjs": "^1",
51
52
  "embla-carousel-react": "^8.6.0",
52
53
  "eslint": "^9",
53
- "eslint-config-next": "^15",
54
+ "eslint-config-next": "^16",
54
55
  "husky": "^9",
55
56
  "libphonenumber-js": "^1",
56
57
  "lucide-react": "^0",
57
- "next": "^15",
58
+ "next": "^16",
58
59
  "next-intl": "^4",
59
60
  "next-themes": "^0",
60
61
  "react": "^19",