@appcorp/stellar-solutions-invoice-module 0.1.59 → 0.1.60

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.
@@ -1,8 +1,8 @@
1
- import { ProductTypeBE } from '@appcorp/stellar-solutions-product-module/base-modules/product/types';
2
- import { DISCOUNT_UNIT, INVOICE_DRAWER, InvoiceState, QuoteInvoiceTypeBE, Product, Service, INVOICE_MODAL } from './types';
3
- import { TaxTypeBE } from '@appcorp/stellar-solutions-modules/global-modules/preferences/types';
4
- import { CompanyTypeBE } from '@appcorp/stellar-solutions-company-module/base-modules/company/types';
5
- import { CustomerTypeBE } from '@appcorp/stellar-solutions-company-module/base-modules/customer/types';
1
+ import { ProductTypeBE } from "@appcorp/stellar-solutions-product-module/base-modules/product/types";
2
+ import { DISCOUNT_UNIT, INVOICE_DRAWER, InvoiceState, QuoteInvoiceTypeBE, Product, Service, INVOICE_MODAL } from "./types";
3
+ import { TaxTypeBE } from "@appcorp/stellar-solutions-modules/global-modules/preferences/types";
4
+ import { CompanyTypeBE } from "@appcorp/stellar-solutions-company-module/base-modules/company/types";
5
+ import { CustomerTypeBE } from "@appcorp/stellar-solutions-company-module/base-modules/customer/types";
6
6
  export declare enum INVOICE_ACTION_TYPES {
7
7
  ADD_ITEM_PRODUCT = "ADD_ITEM_PRODUCT",
8
8
  ADD_ITEM_SERVICE = "ADD_ITEM_SERVICE",
@@ -40,7 +40,7 @@ export declare enum INVOICE_ACTION_TYPES {
40
40
  export type InvoiceUpdateFieldAction = {
41
41
  type: INVOICE_ACTION_TYPES.SET_INPUT_FIELD;
42
42
  payload: {
43
- key: keyof QuoteInvoiceTypeBE | 'servicesList' | 'productsList';
43
+ key: keyof QuoteInvoiceTypeBE | "servicesList" | "productsList" | "taxQuery" | "productQuery" | "companyQuery";
44
44
  value: string | string[] | boolean | number | number[] | Service[] | Product[];
45
45
  };
46
46
  };
@@ -750,6 +750,12 @@ var useInvoiceState = function () {
750
750
  payload: { searchQuery: "" },
751
751
  });
752
752
  };
753
+ var handleTaxSearch = function (searchQuery) {
754
+ dispatch({
755
+ type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
756
+ payload: { key: "taxQuery", value: searchQuery },
757
+ });
758
+ };
753
759
  var closeDrawer = function () {
754
760
  dispatch({
755
761
  type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
@@ -814,9 +820,9 @@ var useInvoiceState = function () {
814
820
  order: 3,
815
821
  },
816
822
  ];
817
- return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, handleAddItemProduct: handleAddItemProduct, handleAddItemService: handleAddItemService, handleChange: handleChange, handleDeleteProductRow: handleDeleteProductRow, handleDeleteServiceRow: handleDeleteServiceRow, handleItemChangeProducts: handleItemChangeProducts, handleItemChangeServices: handleItemChangeServices, handleNextClick: handleNextClick, handlePageLimit: handlePageLimit, handlePreviousClick: handlePreviousClick, handleSubmit: handleSubmit, headerActions: headerActions, listError: listError, listFetchNow: listFetchNow, listLoading: listLoading, rowActions: rowActions, searchOnChange: searchOnChange, updateError: updateError, updateLoading: updateLoading });
823
+ return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, handleAddItemProduct: handleAddItemProduct, handleAddItemService: handleAddItemService, handleChange: handleChange, handleDeleteProductRow: handleDeleteProductRow, handleDeleteServiceRow: handleDeleteServiceRow, handleItemChangeProducts: handleItemChangeProducts, handleItemChangeServices: handleItemChangeServices, handleNextClick: handleNextClick, handlePageLimit: handlePageLimit, handlePreviousClick: handlePreviousClick, handleSubmit: handleSubmit, headerActions: headerActions, listError: listError, listFetchNow: listFetchNow, listLoading: listLoading, rowActions: rowActions, searchOnChange: searchOnChange, handleTaxSearch: handleTaxSearch, updateError: updateError, updateLoading: updateLoading });
818
824
  };
819
- exports.InvoiceStateContext = (0, react_1.createContext)(__assign(__assign({}, reducer_1.initialInvoiceState), { byIdError: undefined, byIdLoading: false, clearSearch: function () { return void 0; }, closeDrawer: function () { return void 0; }, deleteError: undefined, deleteLoading: false, dispatch: function () { return void 0; }, handleAddItemProduct: function () { return void 0; }, handleAddItemService: function () { return void 0; }, handleChange: function () { return void 0; }, handleDeleteProductRow: function () { return void 0; }, handleDeleteServiceRow: function () { return void 0; }, handleItemChangeProducts: function () { return void 0; }, handleItemChangeServices: function () { return void 0; }, handleNextClick: function () { return void 0; }, handlePageLimit: function () { return void 0; }, handlePreviousClick: function () { return void 0; }, handleSubmit: function () { return void 0; }, headerActions: [], listError: undefined, listFetchNow: function () { return void 0; }, listLoading: false, rowActions: [], searchOnChange: function () { return void 0; }, updateError: undefined, updateLoading: false }));
825
+ exports.InvoiceStateContext = (0, react_1.createContext)(__assign(__assign({}, reducer_1.initialInvoiceState), { byIdError: undefined, byIdLoading: false, clearSearch: function () { return void 0; }, closeDrawer: function () { return void 0; }, deleteError: undefined, deleteLoading: false, dispatch: function () { return void 0; }, handleAddItemProduct: function () { return void 0; }, handleAddItemService: function () { return void 0; }, handleChange: function () { return void 0; }, handleDeleteProductRow: function () { return void 0; }, handleDeleteServiceRow: function () { return void 0; }, handleItemChangeProducts: function () { return void 0; }, handleItemChangeServices: function () { return void 0; }, handleNextClick: function () { return void 0; }, handlePageLimit: function () { return void 0; }, handlePreviousClick: function () { return void 0; }, handleSubmit: function () { return void 0; }, headerActions: [], listError: undefined, listFetchNow: function () { return void 0; }, listLoading: false, rowActions: [], searchOnChange: function () { return void 0; }, handleTaxSearch: function () { return void 0; }, updateError: undefined, updateLoading: false }));
820
826
  var InvoiceStateContextProvider = function (_a) {
821
827
  var children = _a.children;
822
828
  var state = useInvoiceState();
@@ -5,41 +5,58 @@
5
5
  * Totals calculation section for invoice pricing including tax and discount.
6
6
  * Uses Shadcn UI components with RTL support and i18n.
7
7
  */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
11
41
  Object.defineProperty(exports, "__esModule", { value: true });
12
42
  exports.PricingSection = void 0;
13
- var react_1 = __importDefault(require("react"));
43
+ var react_1 = __importStar(require("react"));
14
44
  var next_intl_1 = require("next-intl");
15
45
  var combobox_1 = require("@appcorp/shadcn/components/combobox");
16
46
  var input_1 = require("@appcorp/shadcn/components/input");
17
47
  var label_1 = require("@appcorp/shadcn/components/label");
18
48
  var button_1 = require("@appcorp/shadcn/components/button");
19
- var context_1 = require("./context");
49
+ var context_1 = require("@appcorp/stellar-solutions-modules/global-modules/tax/context");
50
+ var context_2 = require("./context");
20
51
  var types_1 = require("./types");
21
52
  var PricingSection = function () {
22
53
  var t = (0, next_intl_1.useTranslations)("invoicePage");
23
- var _a = (0, context_1.useInvoiceStateContext)(), afterDiscount = _a.afterDiscount, discount = _a.discount, discountUnit = _a.discountUnit, errors = _a.errors, handleChange = _a.handleChange, subTotal = _a.subTotal, tax = _a.tax, taxes = _a.taxes, total = _a.total;
24
- var handleTaxChange = function (selectedTaxId) {
25
- var selectedTax = taxes === null || taxes === void 0 ? void 0 : taxes.find(function (t) { return t.id === selectedTaxId; });
26
- if (selectedTax) {
27
- handleChange("taxRate", selectedTax.taxRate);
28
- }
29
- };
30
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
- var handleTaxSearch = function (_searchQuery) {
32
- // Tax search functionality placeholder
33
- };
34
- var handleDiscountUnitChange = function (unit) {
35
- handleChange("discountUnit", unit);
36
- };
37
- // Map taxes to have consistent structure for CompanyCombobox
38
- var taxOptions = (taxes || []).map(function (tax) { return ({
39
- id: tax.id,
40
- name: "".concat(tax.taxName, " (").concat(tax.taxRate, "%)"),
41
- }); });
42
- var currentTax = taxes === null || taxes === void 0 ? void 0 : taxes.find(function (t) { return String(t.taxRate) === String(tax); });
54
+ var _a = (0, context_1.useTaxStateContext)(), taxesFromTaxContext = _a.taxes, taxesLoading = _a.listLoading;
55
+ var _b = (0, context_2.useInvoiceStateContext)(), afterDiscount = _b.afterDiscount, discount = _b.discount, discountUnit = _b.discountUnit, errors = _b.errors, handleChange = _b.handleChange, handleTaxSearch = _b.handleTaxSearch, subTotal = _b.subTotal, tax = _b.tax, taxRate = _b.taxRate, total = _b.total;
56
+ // Find the current tax based on taxRate value
57
+ var currentTax = (0, react_1.useMemo)(function () {
58
+ return taxesFromTaxContext === null || taxesFromTaxContext === void 0 ? void 0 : taxesFromTaxContext.find(function (t) { return String(t.taxRate) === String(taxRate); });
59
+ }, [taxesFromTaxContext, taxRate]);
43
60
  return (react_1.default.createElement("div", { className: "flex flex-col gap-6" },
44
61
  react_1.default.createElement("h3", { className: "text-lg font-semibold border-b pb-2" }, t("pricingSectionTitle")),
45
62
  react_1.default.createElement("div", { className: "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6" },
@@ -53,12 +70,12 @@ var PricingSection = function () {
53
70
  react_1.default.createElement("p", { className: "text-sm text-muted-foreground" }, t("discountUnitDescription")),
54
71
  react_1.default.createElement("div", { className: "flex gap-2" },
55
72
  react_1.default.createElement(button_1.Button, { onClick: function () {
56
- return handleDiscountUnitChange(types_1.DISCOUNT_UNIT.FIXED_VALUE);
73
+ return handleChange("discountUnit", types_1.DISCOUNT_UNIT.FIXED_VALUE);
57
74
  }, size: "sm", type: "button", variant: discountUnit === types_1.DISCOUNT_UNIT.FIXED_VALUE
58
75
  ? "default"
59
76
  : "outline" }, t("discountUnitFixedValue")),
60
77
  react_1.default.createElement(button_1.Button, { onClick: function () {
61
- return handleDiscountUnitChange(types_1.DISCOUNT_UNIT.PERCENTAGE_VALUE);
78
+ return handleChange("discountUnit", types_1.DISCOUNT_UNIT.PERCENTAGE_VALUE);
62
79
  }, size: "sm", type: "button", variant: discountUnit === types_1.DISCOUNT_UNIT.PERCENTAGE_VALUE
63
80
  ? "default"
64
81
  : "outline" }, t("discountUnitPercentageValue")))),
@@ -67,7 +84,13 @@ var PricingSection = function () {
67
84
  react_1.default.createElement("div", { className: "space-y-2" },
68
85
  react_1.default.createElement(input_1.Input, { id: "afterDiscount", label: t("formLabelAfterDiscount"), onChange: function (e) { return handleChange("afterDiscount", e.target.value); }, placeholder: "0.00", readOnly: true, type: "text", value: afterDiscount || "0" })),
69
86
  react_1.default.createElement("div", { className: "space-y-2" },
70
- react_1.default.createElement(combobox_1.CompanyCombobox, { companies: taxOptions, id: "taxRate", label: t("formLabelTax"), onSearchChange: handleTaxSearch, onValueChange: handleTaxChange, placeholder: t("formPlaceholderTax"), value: (currentTax === null || currentTax === void 0 ? void 0 : currentTax.id) || "" })),
87
+ react_1.default.createElement(combobox_1.Combobox, { id: "taxRate", label: t("formLabelTax"), value: (currentTax === null || currentTax === void 0 ? void 0 : currentTax.taxRate) || "", onValueChange: function (v) { return handleChange("taxRate", v); }, onSearchChange: handleTaxSearch, loading: taxesLoading, options: (taxesFromTaxContext || [])
88
+ .slice()
89
+ .sort(function (a, b) { return a.taxName.localeCompare(b.taxName); })
90
+ .map(function (tax) { return ({
91
+ label: "".concat(tax.taxName, " (").concat(tax.taxRate, "%)"),
92
+ value: tax.taxRate.toString(),
93
+ }); }), placeholder: t("formPlaceholderTax"), searchPlaceholder: "Search taxes...", info: t("formInfoTax"), error: errors.taxRate, required: true })),
71
94
  react_1.default.createElement("div", { className: "space-y-2" },
72
95
  react_1.default.createElement(input_1.Input, { id: "afterTax", label: t("formLabelAfterTax"), placeholder: "0.00", readOnly: true, type: "text", value: isNaN(Number(tax)) ? "0" : tax || "0" })),
73
96
  react_1.default.createElement("div", { className: "space-y-2" },
@@ -33,6 +33,7 @@ export interface InvoiceContextType {
33
33
  handlePageLimit: (node: string, value: object) => void;
34
34
  handlePreviousClick: () => void;
35
35
  handleSubmit: () => void;
36
+ handleTaxSearch: (searchQuery: string) => void;
36
37
  headerActions: HeaderAction[];
37
38
  listError?: Error;
38
39
  listFetchNow: () => void;
@@ -40,7 +40,7 @@ export declare enum QUOTE_ACTION_TYPES {
40
40
  export type QuoteUpdateFieldAction = {
41
41
  type: QUOTE_ACTION_TYPES.SET_INPUT_FIELD;
42
42
  payload: {
43
- key: keyof QuoteInvoiceTypeBE | "servicesList" | "productsList";
43
+ key: keyof QuoteInvoiceTypeBE | "servicesList" | "productsList" | "taxQuery" | "productQuery" | "companyQuery";
44
44
  value: string | string[] | boolean | number | number[] | Service[] | Product[];
45
45
  };
46
46
  };
@@ -29,7 +29,7 @@ exports.tableBodyCols = [
29
29
  },
30
30
  {
31
31
  componentType: enhanced_table_1.COMPONENT_TYPE.OBJECT,
32
- key: ["company", "name"],
32
+ key: ["company:name"],
33
33
  },
34
34
  {
35
35
  componentType: enhanced_table_1.COMPONENT_TYPE.MULTIPLE_TEXT_LINES,
@@ -638,6 +638,25 @@ var useQuoteState = function () {
638
638
  });
639
639
  return;
640
640
  }
641
+ if (key === "taxRate") {
642
+ dispatch({
643
+ type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
644
+ payload: { key: key, value: Number(value) },
645
+ });
646
+ return;
647
+ }
648
+ if (key === "discountUnit") {
649
+ dispatch({
650
+ type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
651
+ payload: { key: key, value: value },
652
+ });
653
+ return;
654
+ }
655
+ // Dispatch the input field change
656
+ dispatch({
657
+ type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
658
+ payload: { key: key, value: value },
659
+ });
641
660
  dispatch({
642
661
  type: actions_1.QUOTE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
643
662
  payload: { disableSaveButton: false },
@@ -745,6 +764,12 @@ var useQuoteState = function () {
745
764
  payload: { searchQuery: "" },
746
765
  });
747
766
  };
767
+ var handleTaxSearch = function (searchQuery) {
768
+ dispatch({
769
+ type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
770
+ payload: { key: "taxQuery", value: searchQuery },
771
+ });
772
+ };
748
773
  var closeDrawer = function () {
749
774
  dispatch({
750
775
  type: actions_1.QUOTE_ACTION_TYPES.SET_DRAWER,
@@ -803,9 +828,9 @@ var useQuoteState = function () {
803
828
  order: 2,
804
829
  },
805
830
  ];
806
- return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, handleAddItemProduct: handleAddItemProduct, handleAddItemService: handleAddItemService, handleChange: handleChange, handleDeleteProductRow: handleDeleteProductRow, handleDeleteServiceRow: handleDeleteServiceRow, handleItemChangeProducts: handleItemChangeProducts, handleItemChangeServices: handleItemChangeServices, handleNextClick: handleNextClick, handlePageLimit: handlePageLimit, handlePreviousClick: handlePreviousClick, handleSubmit: handleSubmit, headerActions: headerActions, listError: listError, listFetchNow: listFetchNow, listLoading: listLoading, rowActions: rowActions, searchOnChange: searchOnChange, updateError: updateError, updateLoading: updateLoading });
831
+ return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, handleAddItemProduct: handleAddItemProduct, handleAddItemService: handleAddItemService, handleChange: handleChange, handleDeleteProductRow: handleDeleteProductRow, handleDeleteServiceRow: handleDeleteServiceRow, handleItemChangeProducts: handleItemChangeProducts, handleItemChangeServices: handleItemChangeServices, handleNextClick: handleNextClick, handlePageLimit: handlePageLimit, handlePreviousClick: handlePreviousClick, handleSubmit: handleSubmit, handleTaxSearch: handleTaxSearch, headerActions: headerActions, listError: listError, listFetchNow: listFetchNow, listLoading: listLoading, rowActions: rowActions, searchOnChange: searchOnChange, updateError: updateError, updateLoading: updateLoading });
807
832
  };
808
- exports.QuoteStateContext = (0, react_1.createContext)(__assign(__assign({}, reducer_1.initialQuoteState), { byIdError: undefined, byIdLoading: false, clearSearch: function () { return void 0; }, closeDrawer: function () { return void 0; }, deleteError: undefined, deleteLoading: false, dispatch: function () { return void 0; }, handleAddItemProduct: function () { return void 0; }, handleAddItemService: function () { return void 0; }, handleChange: function () { return void 0; }, handleDeleteProductRow: function () { return void 0; }, handleDeleteServiceRow: function () { return void 0; }, handleItemChangeProducts: function () { return void 0; }, handleItemChangeServices: function () { return void 0; }, handleNextClick: function () { return void 0; }, handlePageLimit: function () { return void 0; }, handlePreviousClick: function () { return void 0; }, handleSubmit: function () { return void 0; }, headerActions: [], listError: undefined, listFetchNow: function () { return void 0; }, listLoading: false, rowActions: [], searchOnChange: function () { return void 0; }, updateError: undefined, updateLoading: false }));
833
+ exports.QuoteStateContext = (0, react_1.createContext)(__assign(__assign({}, reducer_1.initialQuoteState), { byIdError: undefined, byIdLoading: false, clearSearch: function () { return void 0; }, closeDrawer: function () { return void 0; }, deleteError: undefined, deleteLoading: false, dispatch: function () { return void 0; }, handleAddItemProduct: function () { return void 0; }, handleAddItemService: function () { return void 0; }, handleChange: function () { return void 0; }, handleDeleteProductRow: function () { return void 0; }, handleDeleteServiceRow: function () { return void 0; }, handleItemChangeProducts: function () { return void 0; }, handleItemChangeServices: function () { return void 0; }, handleNextClick: function () { return void 0; }, handlePageLimit: function () { return void 0; }, handlePreviousClick: function () { return void 0; }, handleSubmit: function () { return void 0; }, handleTaxSearch: function () { return void 0; }, headerActions: [], listError: undefined, listFetchNow: function () { return void 0; }, listLoading: false, rowActions: [], searchOnChange: function () { return void 0; }, updateError: undefined, updateLoading: false }));
809
834
  var QuoteStateContextProvider = function (_a) {
810
835
  var children = _a.children;
811
836
  var state = useQuoteState();
@@ -5,41 +5,58 @@
5
5
  * Totals calculation section for invoice pricing including tax and discount.
6
6
  * Uses Shadcn UI components with RTL support and i18n.
7
7
  */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
11
41
  Object.defineProperty(exports, "__esModule", { value: true });
12
42
  exports.PricingSection = void 0;
13
- var react_1 = __importDefault(require("react"));
43
+ var react_1 = __importStar(require("react"));
14
44
  var next_intl_1 = require("next-intl");
15
45
  var combobox_1 = require("@appcorp/shadcn/components/combobox");
16
46
  var input_1 = require("@appcorp/shadcn/components/input");
17
47
  var label_1 = require("@appcorp/shadcn/components/label");
18
48
  var button_1 = require("@appcorp/shadcn/components/button");
19
- var context_1 = require("./context");
49
+ var context_1 = require("@appcorp/stellar-solutions-modules/global-modules/tax/context");
50
+ var context_2 = require("./context");
20
51
  var types_1 = require("./types");
21
52
  var PricingSection = function () {
22
53
  var t = (0, next_intl_1.useTranslations)("invoicePage");
23
- var _a = (0, context_1.useQuoteStateContext)(), afterDiscount = _a.afterDiscount, discount = _a.discount, discountUnit = _a.discountUnit, errors = _a.errors, handleChange = _a.handleChange, subTotal = _a.subTotal, tax = _a.tax, taxes = _a.taxes, total = _a.total;
24
- var handleTaxChange = function (selectedTaxId) {
25
- var selectedTax = taxes === null || taxes === void 0 ? void 0 : taxes.find(function (t) { return t.id === selectedTaxId; });
26
- if (selectedTax) {
27
- handleChange("taxRate", selectedTax.taxRate);
28
- }
29
- };
30
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
- var handleTaxSearch = function (_searchQuery) {
32
- // Tax search functionality placeholder
33
- };
34
- var handleDiscountUnitChange = function (unit) {
35
- handleChange("discountUnit", unit);
36
- };
37
- // Map taxes to have consistent structure for CompanyCombobox
38
- var taxOptions = (taxes || []).map(function (tax) { return ({
39
- id: tax.id,
40
- name: "".concat(tax.taxName, " (").concat(tax.taxRate, "%)"),
41
- }); });
42
- var currentTax = taxes === null || taxes === void 0 ? void 0 : taxes.find(function (t) { return String(t.taxRate) === String(tax); });
54
+ var _a = (0, context_1.useTaxStateContext)(), taxesFromTaxContext = _a.taxes, taxesLoading = _a.listLoading;
55
+ var _b = (0, context_2.useQuoteStateContext)(), afterDiscount = _b.afterDiscount, discount = _b.discount, discountUnit = _b.discountUnit, errors = _b.errors, handleChange = _b.handleChange, handleTaxSearch = _b.handleTaxSearch, subTotal = _b.subTotal, tax = _b.tax, taxRate = _b.taxRate, total = _b.total;
56
+ // Find the current tax based on taxRate value
57
+ var currentTax = (0, react_1.useMemo)(function () {
58
+ return taxesFromTaxContext === null || taxesFromTaxContext === void 0 ? void 0 : taxesFromTaxContext.find(function (t) { return String(t.taxRate) === String(taxRate); });
59
+ }, [taxesFromTaxContext, taxRate]);
43
60
  return (react_1.default.createElement("div", { className: "flex flex-col gap-6" },
44
61
  react_1.default.createElement("h3", { className: "text-lg font-semibold border-b pb-2" }, t("pricingSectionTitle")),
45
62
  react_1.default.createElement("div", { className: "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6" },
@@ -53,12 +70,12 @@ var PricingSection = function () {
53
70
  react_1.default.createElement("p", { className: "text-sm text-muted-foreground" }, t("discountUnitDescription")),
54
71
  react_1.default.createElement("div", { className: "flex gap-2" },
55
72
  react_1.default.createElement(button_1.Button, { onClick: function () {
56
- return handleDiscountUnitChange(types_1.DISCOUNT_UNIT.FIXED_VALUE);
73
+ return handleChange("discountUnit", types_1.DISCOUNT_UNIT.FIXED_VALUE);
57
74
  }, size: "sm", type: "button", variant: discountUnit === types_1.DISCOUNT_UNIT.FIXED_VALUE
58
75
  ? "default"
59
76
  : "outline" }, t("discountUnitFixedValue")),
60
77
  react_1.default.createElement(button_1.Button, { onClick: function () {
61
- return handleDiscountUnitChange(types_1.DISCOUNT_UNIT.PERCENTAGE_VALUE);
78
+ return handleChange("discountUnit", types_1.DISCOUNT_UNIT.PERCENTAGE_VALUE);
62
79
  }, size: "sm", type: "button", variant: discountUnit === types_1.DISCOUNT_UNIT.PERCENTAGE_VALUE
63
80
  ? "default"
64
81
  : "outline" }, t("discountUnitPercentageValue")))),
@@ -67,7 +84,13 @@ var PricingSection = function () {
67
84
  react_1.default.createElement("div", { className: "space-y-2" },
68
85
  react_1.default.createElement(input_1.Input, { id: "afterDiscount", label: t("formLabelAfterDiscount"), onChange: function (e) { return handleChange("afterDiscount", e.target.value); }, placeholder: "0.00", readOnly: true, type: "text", value: afterDiscount || "0" })),
69
86
  react_1.default.createElement("div", { className: "space-y-2" },
70
- react_1.default.createElement(combobox_1.CompanyCombobox, { companies: taxOptions, id: "taxRate", label: t("formLabelTax"), onSearchChange: handleTaxSearch, onValueChange: handleTaxChange, placeholder: t("formPlaceholderTax"), value: (currentTax === null || currentTax === void 0 ? void 0 : currentTax.id) || "" })),
87
+ react_1.default.createElement(combobox_1.Combobox, { id: "taxRate", label: t("formLabelTax"), value: (currentTax === null || currentTax === void 0 ? void 0 : currentTax.taxRate) || "", onValueChange: function (v) { return handleChange("taxRate", v); }, onSearchChange: handleTaxSearch, loading: taxesLoading, options: (taxesFromTaxContext || [])
88
+ .slice()
89
+ .sort(function (a, b) { return a.taxName.localeCompare(b.taxName); })
90
+ .map(function (tax) { return ({
91
+ label: "".concat(tax.taxName, " (").concat(tax.taxRate, "%)"),
92
+ value: tax.taxRate.toString(),
93
+ }); }), placeholder: t("formPlaceholderTax"), searchPlaceholder: "Search taxes...", info: t("formInfoTax"), error: errors.taxRate, required: true })),
71
94
  react_1.default.createElement("div", { className: "space-y-2" },
72
95
  react_1.default.createElement(input_1.Input, { id: "afterTax", label: t("formLabelAfterTax"), placeholder: "0.00", readOnly: true, type: "text", value: isNaN(Number(tax)) ? "0" : tax || "0" })),
73
96
  react_1.default.createElement("div", { className: "space-y-2" },
@@ -34,6 +34,7 @@ export interface QuoteContextType {
34
34
  handlePageLimit: (node: string, value: object) => void;
35
35
  handlePreviousClick: () => void;
36
36
  handleSubmit: () => void;
37
+ handleTaxSearch: (searchQuery: string) => void;
37
38
  headerActions: HeaderAction[];
38
39
  listError?: Error;
39
40
  listFetchNow: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/stellar-solutions-invoice-module",
3
- "version": "0.1.59",
3
+ "version": "0.1.60",
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",
@@ -21,8 +21,8 @@
21
21
  "devDependencies": {
22
22
  "@appcorp/app-corp-vista": "^0.3.48",
23
23
  "@appcorp/shadcn": "^1.0.32",
24
- "@appcorp/stellar-solutions-company-module": "^0.1.39",
25
- "@appcorp/stellar-solutions-modules": "^0.1.60",
24
+ "@appcorp/stellar-solutions-company-module": "^0.1.40",
25
+ "@appcorp/stellar-solutions-modules": "^0.1.62",
26
26
  "@appcorp/stellar-solutions-product-module": "^0.2.18",
27
27
  "@eslint/eslintrc": "^3",
28
28
  "@headlessui/react": "^2",
@@ -35,7 +35,7 @@
35
35
  "@radix-ui/react-separator": "^1",
36
36
  "@radix-ui/react-slot": "^1",
37
37
  "@radix-ui/react-switch": "^1",
38
- "@react-pakistan/util-functions": "^1.24.79",
38
+ "@react-pakistan/util-functions": "^1.24.80",
39
39
  "@supabase/supabase-js": "^2",
40
40
  "@tailwindcss/forms": "^0",
41
41
  "@tailwindcss/postcss": "^4",