@appcorp/stellar-solutions-invoice-module 0.1.72 → 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,17 +197,33 @@ 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,
202
220
  });
203
221
  dispatch({
204
- payload: { drawer: types_1.PAYMENT_DRAWER.PAYMENT_FORM_DRAWER },
222
+ payload: { drawer: types_1.PAYMENT_DRAWER.PAYMENT_VIEW_DRAWER },
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,
@@ -239,21 +257,24 @@ var usePaymentState = function () {
239
257
  updateCallback: updateCallback,
240
258
  updateDeps: [state],
241
259
  updateParams: updateParams,
242
- }), byIdError = _b.byIdError,
243
- // byIdFetchNow,
244
- byIdLoading = _b.byIdLoading, deleteError = _b.deleteError,
260
+ }), byIdError = _b.byIdError, byIdFetchNow = _b.byIdFetchNow, byIdLoading = _b.byIdLoading, deleteError = _b.deleteError,
245
261
  // deleteFetchNow,
246
262
  deleteLoading = _b.deleteLoading, listError = _b.listError, listFetchNow = _b.listFetchNow, listLoading = _b.listLoading, updateError = _b.updateError, updateFetchNow = _b.updateFetchNow, updateLoading = _b.updateLoading;
247
263
  // ---------------------------------------------------------------------------
248
264
  // EFFECTS
249
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]);
250
272
  (0, react_1.useEffect)(function () {
251
273
  listFetchNow();
252
274
  // eslint-disable-next-line
253
275
  }, [debouncedQuery, state.currentPage, state.pageLimit]);
254
276
  (0, react_1.useEffect)(function () {
255
277
  var invoiceId = (0, util_functions_1.getStorageValue)("paymentInvoiceId");
256
- console.log("_>>>", invoiceId);
257
278
  if (invoiceId) {
258
279
  var invoice = invoices.filter(function (_a) {
259
280
  var id = _a.id;
@@ -264,9 +285,28 @@ var usePaymentState = function () {
264
285
  type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
265
286
  payload: { key: "quoteInvoiceId", value: invoiceId },
266
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
+ }
267
304
  dispatch({
268
305
  type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
269
- 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
+ },
270
310
  });
271
311
  dispatch({
272
312
  type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
@@ -286,7 +326,8 @@ var usePaymentState = function () {
286
326
  });
287
327
  }
288
328
  }
289
- }, [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
290
331
  // ---------------------------------------------------------------------------
291
332
  // DRAWER & MODAL HANDLERS
292
333
  // ---------------------------------------------------------------------------
@@ -305,14 +346,15 @@ var usePaymentState = function () {
305
346
  // ---------------------------------------------------------------------------
306
347
  // CRUD OPERATION HANDLERS
307
348
  // ---------------------------------------------------------------------------
308
- // const handleEdit = useCallback(
309
- // (id: string) => {
310
- // byIdFetchNow(undefined, {
311
- // body: JSON.stringify({ id }),
312
- // });
313
- // },
314
- // [byIdFetchNow]
315
- // );
349
+ var handleView = (0, react_1.useCallback)(function (id) {
350
+ byIdFetchNow(undefined, {
351
+ params: {
352
+ id: id,
353
+ includeQuoteInvoice: true,
354
+ includePaymentMode: true,
355
+ },
356
+ });
357
+ }, [byIdFetchNow]);
316
358
  // const handleDelete = useCallback(
317
359
  // (id: string) => {
318
360
  // deleteFetchNow?.(undefined, {
@@ -333,16 +375,16 @@ var usePaymentState = function () {
333
375
  type: actions_1.PAYMENT_ACTION_TYPES.SET_ERRORS,
334
376
  });
335
377
  },
336
- params: updateParams,
378
+ params: __assign(__assign({}, updateParams), { currency: updateParams.currency || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id) }),
337
379
  schema: validate_1.formValidation,
338
380
  successCallback: function () {
339
381
  updateFetchNow(undefined, {
340
- body: JSON.stringify(__assign({}, updateParams)),
382
+ body: JSON.stringify(__assign(__assign({}, updateParams), { currency: updateParams.currency || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id) })),
341
383
  });
342
384
  },
343
385
  });
344
386
  (0, util_functions_1.removeStorageValue)("paymentInvoiceId");
345
- }, [updateFetchNow, updateParams, dispatch]);
387
+ }, [updateFetchNow, updateParams, dispatch, defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id]);
346
388
  // ---------------------------------------------------------------------------
347
389
  // FORM HANDLERS
348
390
  // ---------------------------------------------------------------------------
@@ -422,7 +464,14 @@ var usePaymentState = function () {
422
464
  // TABLE ACTIONS
423
465
  // ---------------------------------------------------------------------------
424
466
  var headerActions = (0, react_1.useMemo)(function () { return []; }, []);
425
- var rowActions = (0, react_1.useMemo)(function () { return []; }, []);
467
+ var rowActions = (0, react_1.useMemo)(function () { return [
468
+ {
469
+ enabled: true,
470
+ handleAction: handleView,
471
+ label: t("actionsButtonView"),
472
+ order: 1,
473
+ },
474
+ ]; }, [handleView, t]);
426
475
  // ---------------------------------------------------------------------------
427
476
  // RETURN STATE
428
477
  // ---------------------------------------------------------------------------
@@ -12,25 +12,30 @@ var context_1 = require("./context");
12
12
  var form_1 = require("./form");
13
13
  var types_1 = require("./types");
14
14
  var next_intl_1 = require("next-intl");
15
+ var view_1 = require("./view");
15
16
  var Drawer = function (_a) {
16
17
  var isRTL = _a.isRTL;
17
18
  var t = (0, next_intl_1.useTranslations)("payment");
18
19
  var _b = (0, context_1.usePaymentStateContext)(), closeDrawer = _b.closeDrawer, disableSaveButton = _b.disableSaveButton, drawer = _b.drawer, handleSubmit = _b.handleSubmit;
19
20
  var isFormDrawer = drawer === types_1.PAYMENT_DRAWER.PAYMENT_FORM_DRAWER;
20
- var drawerTitle = isFormDrawer
21
- ? t("drawerTitlePayment")
22
- : t("drawerTitleFilter");
21
+ var isFilterDrawer = drawer === types_1.PAYMENT_DRAWER.PAYMENT_FILTER_DRAWER;
22
+ var isViewDrawer = drawer === types_1.PAYMENT_DRAWER.PAYMENT_VIEW_DRAWER;
23
23
  var drawerWidth = "w-[400px] sm:w-[540px]";
24
24
  var drawerDirection = isRTL ? "left" : "right";
25
25
  return (react_1.default.createElement(drawer_1.Drawer, { open: !!drawer, onOpenChange: function (open) { return !open && closeDrawer(); }, direction: drawerDirection },
26
- react_1.default.createElement(drawer_1.DrawerContent, { className: "h-full ".concat(drawerWidth, " ").concat(isRTL ? "rtl" : "ltr"), dir: isRTL ? "rtl" : "ltr" },
26
+ react_1.default.createElement(drawer_1.DrawerContent, { className: "h-full ".concat(drawerWidth, " ").concat(isRTL ? "rtl" : "ltr"), dir: isRTL ? "rtl" : "ltr", "aria-describedby": "drawer-description", "aria-description": "drawer-description" },
27
27
  react_1.default.createElement(drawer_1.DrawerHeader, { className: "flex flex-row items-center justify-between border-b pb-4 ".concat(isRTL ? "flex-row-reverse" : "") },
28
- react_1.default.createElement(drawer_1.DrawerTitle, { className: "text-xl font-semibold flex items-center ".concat(isRTL ? "flex-row-reverse gap-2" : "gap-2") }, drawerTitle),
28
+ react_1.default.createElement(drawer_1.DrawerTitle, { className: "text-xl font-semibold flex items-center ".concat(isRTL ? "flex-row-reverse gap-2" : "gap-2") },
29
+ isFormDrawer && t("drawerTitlePayment"),
30
+ isFilterDrawer && t("drawerTitleFilter"),
31
+ isViewDrawer && t("drawerTitleView")),
29
32
  react_1.default.createElement(drawer_1.DrawerClose, { asChild: true },
30
33
  react_1.default.createElement(button_1.Button, { variant: "ghost", size: "icon", className: "h-8 w-8" },
31
34
  react_1.default.createElement(lucide_react_1.X, { className: "h-4 w-4" }),
32
35
  react_1.default.createElement("span", { className: "sr-only" }, t("drawerButtonClose"))))),
33
- react_1.default.createElement("div", { className: "flex-1 overflow-y-auto px-4 py-6 ".concat(isRTL ? "text-right" : "text-left") }, isFormDrawer && react_1.default.createElement(form_1.PaymentForm, { isRTL: isRTL })),
36
+ react_1.default.createElement("div", { className: "flex-1 overflow-y-auto px-4 py-6 ".concat(isRTL ? "text-right" : "text-left") },
37
+ isFormDrawer && react_1.default.createElement(form_1.PaymentForm, { isRTL: isRTL }),
38
+ isViewDrawer && react_1.default.createElement(view_1.PaymentView, { isRTL: isRTL })),
34
39
  react_1.default.createElement(drawer_1.DrawerFooter, { className: "border-t pt-4" },
35
40
  react_1.default.createElement("div", { className: "flex gap-2 ".concat(isRTL ? "flex-row-reverse" : "") },
36
41
  react_1.default.createElement(button_1.Button, { variant: "outline", onClick: closeDrawer, className: "flex-1" }, t("drawerButtonCancel")),
@@ -8,7 +8,9 @@ export declare enum PAYMENT_TYPE {
8
8
  PARTIAL_AMOUNT = "PARTIAL_AMOUNT"
9
9
  }
10
10
  export declare enum PAYMENT_DRAWER {
11
- PAYMENT_FORM_DRAWER = "PAYMENT_FORM_DRAWER"
11
+ PAYMENT_FILTER_DRAWER = "PAYMENT_FILTER_DRAWER",
12
+ PAYMENT_FORM_DRAWER = "PAYMENT_FORM_DRAWER",
13
+ PAYMENT_VIEW_DRAWER = "PAYMENT_VIEW_DRAWER"
12
14
  }
13
15
  export declare enum PAYMENT_MODAL {
14
16
  DUMMY = "DUMMY"
@@ -11,7 +11,9 @@ var PAYMENT_TYPE;
11
11
  })(PAYMENT_TYPE || (exports.PAYMENT_TYPE = PAYMENT_TYPE = {}));
12
12
  var PAYMENT_DRAWER;
13
13
  (function (PAYMENT_DRAWER) {
14
+ PAYMENT_DRAWER["PAYMENT_FILTER_DRAWER"] = "PAYMENT_FILTER_DRAWER";
14
15
  PAYMENT_DRAWER["PAYMENT_FORM_DRAWER"] = "PAYMENT_FORM_DRAWER";
16
+ PAYMENT_DRAWER["PAYMENT_VIEW_DRAWER"] = "PAYMENT_VIEW_DRAWER";
15
17
  })(PAYMENT_DRAWER || (exports.PAYMENT_DRAWER = PAYMENT_DRAWER = {}));
16
18
  var PAYMENT_MODAL;
17
19
  (function (PAYMENT_MODAL) {
@@ -0,0 +1,6 @@
1
+ import { FC } from "react";
2
+ interface Props {
3
+ isRTL: boolean;
4
+ }
5
+ export declare const PaymentView: FC<Props>;
6
+ export {};
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PaymentView = void 0;
7
+ var react_1 = __importDefault(require("react"));
8
+ var context_1 = require("./context");
9
+ var card_1 = require("@appcorp/shadcn/components/ui/card");
10
+ var separator_1 = require("@appcorp/shadcn/components/ui/separator");
11
+ var badge_1 = require("@appcorp/shadcn/components/ui/badge");
12
+ var Row = function (_a) {
13
+ var label = _a.label, value = _a.value;
14
+ return (react_1.default.createElement("div", { className: "flex w-full items-start justify-between py-2" },
15
+ react_1.default.createElement("div", { className: "text-sm text-muted-foreground" }, label),
16
+ react_1.default.createElement("div", { className: "text-sm text-foreground ml-4" }, value !== null && value !== void 0 ? value : "—")));
17
+ };
18
+ var PaymentView = function (_a) {
19
+ var isRTL = _a.isRTL;
20
+ var _b = (0, context_1.usePaymentStateContext)(), amount = _b.amount, attachment = _b.attachment, balance = _b.balance, currency = _b.currency, date = _b.date, description = _b.description, id = _b.id, paymentMode = _b.paymentMode, paymentType = _b.paymentType, quoteInvoice = _b.quoteInvoice, ref = _b.ref;
21
+ return (react_1.default.createElement(card_1.Card, { className: "w-full" },
22
+ react_1.default.createElement(card_1.CardHeader, { className: "flex ".concat(isRTL ? "flex-row-reverse" : "flex-row", " items-center justify-between") },
23
+ react_1.default.createElement(card_1.CardTitle, null, "Payment"),
24
+ react_1.default.createElement("div", { className: "flex items-center gap-2" },
25
+ react_1.default.createElement(badge_1.Badge, { variant: "secondary" }, paymentType !== null && paymentType !== void 0 ? paymentType : "N/A"))),
26
+ react_1.default.createElement(card_1.CardContent, null,
27
+ react_1.default.createElement("div", { className: "space-y-2" },
28
+ react_1.default.createElement(Row, { label: "ID", value: id }),
29
+ react_1.default.createElement(separator_1.Separator, null),
30
+ react_1.default.createElement(Row, { label: "Amount", value: "".concat(amount !== null && amount !== void 0 ? amount : "0.00", " ").concat(currency !== null && currency !== void 0 ? currency : "") }),
31
+ react_1.default.createElement(Row, { label: "Balance", value: "".concat(balance !== null && balance !== void 0 ? balance : "0.00", " ").concat(currency !== null && currency !== void 0 ? currency : "") }),
32
+ react_1.default.createElement(separator_1.Separator, null),
33
+ react_1.default.createElement(Row, { label: "Date", value: date ? new Date(date).toLocaleString() : "-" }),
34
+ react_1.default.createElement(Row, { label: "Reference", value: ref }),
35
+ react_1.default.createElement(separator_1.Separator, null),
36
+ react_1.default.createElement(Row, { label: "Payment Mode", value: (paymentMode === null || paymentMode === void 0 ? void 0 : paymentMode.label) || "-" }),
37
+ react_1.default.createElement(Row, { label: "Invoice", value: quoteInvoice ? quoteInvoice === null || quoteInvoice === void 0 ? void 0 : quoteInvoice.id : "-" }),
38
+ react_1.default.createElement(separator_1.Separator, null),
39
+ react_1.default.createElement("div", null,
40
+ react_1.default.createElement("div", { className: "text-sm text-muted-foreground" }, "Description"),
41
+ react_1.default.createElement("div", { className: "mt-1 text-sm text-foreground" }, description || "—")),
42
+ attachment && (react_1.default.createElement("div", null,
43
+ react_1.default.createElement("div", { className: "text-sm text-muted-foreground" }, "Attachment"),
44
+ react_1.default.createElement("a", { className: "text-sm text-primary underline mt-1 block", href: attachment, target: "_blank", rel: "noreferrer" }, "View attachment")))))));
45
+ };
46
+ exports.PaymentView = PaymentView;
@@ -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.72",
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.13",
24
- "@appcorp/stellar-solutions-company-module": "^0.1.44",
25
- "@appcorp/stellar-solutions-modules": "^0.1.67",
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.94",
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",