@appcorp/stellar-solutions-invoice-module 0.1.51 → 0.1.53

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,7 +1,8 @@
1
1
  import { ProductTypeBE } from '@appcorp/stellar-solutions-product-module/base-modules/product/types';
2
- import { CustomerTypeBE, DISCOUNT_UNIT, INVOICE_DRAWER, InvoiceState, InvoiceTypeBE, Product, Service } from './types';
2
+ import { DISCOUNT_UNIT, INVOICE_DRAWER, InvoiceState, QuoteInvoiceTypeBE, Product, Service, INVOICE_MODAL } from './types';
3
3
  import { TaxTypeBE } from '@appcorp/stellar-solutions-modules/global-modules/preferences/types';
4
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';
5
6
  export declare enum INVOICE_ACTION_TYPES {
6
7
  ADD_ITEM_PRODUCT = "ADD_ITEM_PRODUCT",
7
8
  ADD_ITEM_SERVICE = "ADD_ITEM_SERVICE",
@@ -11,9 +12,12 @@ export declare enum INVOICE_ACTION_TYPES {
11
12
  RESET_FORM = "RESET_FORM",
12
13
  SET_AFTER_DISCOUNT = "SET_AFTER_DISCOUNT",
13
14
  SET_BUTTON_DISABLE = "SET_BUTTON_DISABLE",
15
+ SET_COMPANIES_LIST = "SET_COMPANIES_LIST",
14
16
  SET_COUNT = "SET_COUNT",
15
17
  SET_CURRENT_PAGE = "SET_CURRENT_PAGE",
18
+ SET_CUSTOMER = "SET_CUSTOMER",
16
19
  SET_CUSTOMER_DATA = "SET_CUSTOMER_DATA",
20
+ SET_CUSTOMER_FORM = "SET_CUSTOMER_FORM",
17
21
  SET_DISABLE_SAVE_BUTTON = "SET_DISABLE_SAVE_BUTTON",
18
22
  SET_DISCOUNT_UNIT = "SET_DISCOUNT_UNIT",
19
23
  SET_DRAWER = "SET_DRAWER",
@@ -25,20 +29,18 @@ export declare enum INVOICE_ACTION_TYPES {
25
29
  SET_INVOICES = "SET_INVOICES",
26
30
  SET_INVOICE_FORM = "SET_INVOICE_FORM",
27
31
  SET_IS_INVOICE_API_SUCCESS = "SET_IS_INVOICE_API_SUCCESS",
32
+ SET_MODAL = "SET_MODAL",
28
33
  SET_PAGE_LIMIT = "SET_PAGE_LIMIT",
34
+ SET_PRODUCTS_LIST = "SET_PRODUCTS_LIST",
29
35
  SET_SEARCH_QUERY = "SET_SEARCH_QUERY",
30
36
  SET_SKELTON_LOADING = "SET_SKELTON_LOADING",
31
37
  SET_TAX = "SET_TAX",
32
- SET_PRODUCTS_LIST = "SET_PRODUCTS_LIST",
33
- SET_COMPANIES_LIST = "SET_COMPANIES_LIST",
34
- SET_CUSTOMER = "SET_CUSTOMER",
35
- SET_TAXES = "SET_TAXES",
36
- SET_CUSTOMER_FORM = "SET_CUSTOMER_FORM"
38
+ SET_TAXES = "SET_TAXES"
37
39
  }
38
40
  export type InvoiceUpdateFieldAction = {
39
41
  type: INVOICE_ACTION_TYPES.SET_INPUT_FIELD;
40
42
  payload: {
41
- key: keyof InvoiceTypeBE;
43
+ key: keyof QuoteInvoiceTypeBE | 'servicesList' | 'productsList';
42
44
  value: string | string[] | boolean | number | number[] | Service[] | Product[];
43
45
  };
44
46
  };
@@ -87,7 +89,7 @@ export type InvoiceSetSearchQueryAction = {
87
89
  export type InvoiceSetInvoicesAction = {
88
90
  type: INVOICE_ACTION_TYPES.SET_INVOICES;
89
91
  payload: {
90
- invoices: InvoiceTypeBE[];
92
+ invoices: QuoteInvoiceTypeBE[];
91
93
  };
92
94
  };
93
95
  export type InvoiceSetCountAction = {
@@ -98,7 +100,7 @@ export type InvoiceSetCountAction = {
98
100
  };
99
101
  export type InvoiceSetInvoiceFormAction = {
100
102
  type: INVOICE_ACTION_TYPES.SET_INVOICE_FORM;
101
- payload: InvoiceTypeBE;
103
+ payload: QuoteInvoiceTypeBE;
102
104
  };
103
105
  export type InvoiceToggleLoadingAction = {
104
106
  type: INVOICE_ACTION_TYPES.SET_SKELTON_LOADING;
@@ -107,25 +109,25 @@ export type InvoiceToggleLoadingAction = {
107
109
  export type InvoiceAddItemServiceAction = {
108
110
  type: INVOICE_ACTION_TYPES.ADD_ITEM_SERVICE;
109
111
  payload: {
110
- services: Service[];
112
+ servicesList: Service[];
111
113
  };
112
114
  };
113
115
  export type InvoiceAddItemProductAction = {
114
116
  type: INVOICE_ACTION_TYPES.ADD_ITEM_PRODUCT;
115
117
  payload: {
116
- products: Product[];
118
+ productsList: Product[];
117
119
  };
118
120
  };
119
121
  export type InvoiceDeleteItemProductAction = {
120
122
  type: INVOICE_ACTION_TYPES.DELETE_ITEM_PRODUCT;
121
123
  payload: {
122
- products: Product[];
124
+ productsList: Product[];
123
125
  };
124
126
  };
125
127
  export type InvoiceDeleteItemServiceAction = {
126
128
  type: INVOICE_ACTION_TYPES.DELETE_ITEM_SERVICE;
127
129
  payload: {
128
- services: Service[];
130
+ servicesList: Service[];
129
131
  };
130
132
  };
131
133
  export type InvoiceSetDiscountUnitAction = {
@@ -151,7 +153,7 @@ export type InvoiceSetDrawerAction = {
151
153
  export type InvoiceSetFormAction = {
152
154
  type: INVOICE_ACTION_TYPES.SET_FORM;
153
155
  payload: {
154
- form: InvoiceTypeBE;
156
+ form: QuoteInvoiceTypeBE;
155
157
  };
156
158
  };
157
159
  export type InvoiceSetAfterDiscountAction = {
@@ -175,7 +177,7 @@ export type InvoiceSetFormToRenderAction = {
175
177
  export type InvoiceSetProductsListAction = {
176
178
  type: INVOICE_ACTION_TYPES.SET_PRODUCTS_LIST;
177
179
  payload: {
178
- productsList: ProductTypeBE[];
180
+ list: ProductTypeBE[];
179
181
  };
180
182
  };
181
183
  export type InvoiceSetCompaniesListAction = {
@@ -204,4 +206,10 @@ export type InvoiceSetTaxesAction = {
204
206
  taxes: TaxTypeBE[];
205
207
  };
206
208
  };
207
- export type InvoiceActions = InvoiceAddItemProductAction | InvoiceAddItemServiceAction | InvoiceResetErrorAction | InvoiceDeleteItemProductAction | InvoiceDeleteItemServiceAction | InvoiceResetFormAction | InvoiceSetButtonDisableAction | InvoiceSetCurrentPageAction | InvoiceSetCustomerDataAction | InvoiceSetDiscountUnitAction | InvoiceSetErrorsAction | InvoiceSetFormLoadingAction | InvoiceSetInvoicesAction | InvoiceSetInvoiceFormAction | InvoiceSetIsInvoiceApiSuccessAction | InvoiceSetMaxPageLimitAction | InvoiceSetSearchQueryAction | InvoiceUpdateFieldAction | InvoiceToggleLoadingAction | InvoiceSetDrawerAction | InvoiceSetCountAction | InvoiceSetFormAction | InvoiceSetAfterDiscountAction | InvoiceSetTaxAction | InvoiceSetFormToRenderAction | InvoiceSetProductsListAction | InvoiceSetCustomerAction | InvoiceSetTaxesAction | InvoiceSetCustomerFormAction | InvoiceSetCompaniesListAction;
209
+ export type InvoiceSetModalAction = {
210
+ type: INVOICE_ACTION_TYPES.SET_MODAL;
211
+ payload: {
212
+ modal: INVOICE_MODAL;
213
+ };
214
+ };
215
+ export type InvoiceActions = InvoiceAddItemProductAction | InvoiceAddItemServiceAction | InvoiceResetErrorAction | InvoiceDeleteItemProductAction | InvoiceDeleteItemServiceAction | InvoiceResetFormAction | InvoiceSetButtonDisableAction | InvoiceSetCurrentPageAction | InvoiceSetCustomerDataAction | InvoiceSetDiscountUnitAction | InvoiceSetErrorsAction | InvoiceSetFormLoadingAction | InvoiceSetInvoicesAction | InvoiceSetInvoiceFormAction | InvoiceSetIsInvoiceApiSuccessAction | InvoiceSetMaxPageLimitAction | InvoiceSetSearchQueryAction | InvoiceUpdateFieldAction | InvoiceToggleLoadingAction | InvoiceSetDrawerAction | InvoiceSetCountAction | InvoiceSetFormAction | InvoiceSetAfterDiscountAction | InvoiceSetTaxAction | InvoiceSetFormToRenderAction | InvoiceSetProductsListAction | InvoiceSetCustomerAction | InvoiceSetTaxesAction | InvoiceSetCustomerFormAction | InvoiceSetCompaniesListAction | InvoiceSetModalAction;
@@ -11,9 +11,12 @@ var INVOICE_ACTION_TYPES;
11
11
  INVOICE_ACTION_TYPES["RESET_FORM"] = "RESET_FORM";
12
12
  INVOICE_ACTION_TYPES["SET_AFTER_DISCOUNT"] = "SET_AFTER_DISCOUNT";
13
13
  INVOICE_ACTION_TYPES["SET_BUTTON_DISABLE"] = "SET_BUTTON_DISABLE";
14
+ INVOICE_ACTION_TYPES["SET_COMPANIES_LIST"] = "SET_COMPANIES_LIST";
14
15
  INVOICE_ACTION_TYPES["SET_COUNT"] = "SET_COUNT";
15
16
  INVOICE_ACTION_TYPES["SET_CURRENT_PAGE"] = "SET_CURRENT_PAGE";
17
+ INVOICE_ACTION_TYPES["SET_CUSTOMER"] = "SET_CUSTOMER";
16
18
  INVOICE_ACTION_TYPES["SET_CUSTOMER_DATA"] = "SET_CUSTOMER_DATA";
19
+ INVOICE_ACTION_TYPES["SET_CUSTOMER_FORM"] = "SET_CUSTOMER_FORM";
17
20
  INVOICE_ACTION_TYPES["SET_DISABLE_SAVE_BUTTON"] = "SET_DISABLE_SAVE_BUTTON";
18
21
  INVOICE_ACTION_TYPES["SET_DISCOUNT_UNIT"] = "SET_DISCOUNT_UNIT";
19
22
  INVOICE_ACTION_TYPES["SET_DRAWER"] = "SET_DRAWER";
@@ -25,13 +28,11 @@ var INVOICE_ACTION_TYPES;
25
28
  INVOICE_ACTION_TYPES["SET_INVOICES"] = "SET_INVOICES";
26
29
  INVOICE_ACTION_TYPES["SET_INVOICE_FORM"] = "SET_INVOICE_FORM";
27
30
  INVOICE_ACTION_TYPES["SET_IS_INVOICE_API_SUCCESS"] = "SET_IS_INVOICE_API_SUCCESS";
31
+ INVOICE_ACTION_TYPES["SET_MODAL"] = "SET_MODAL";
28
32
  INVOICE_ACTION_TYPES["SET_PAGE_LIMIT"] = "SET_PAGE_LIMIT";
33
+ INVOICE_ACTION_TYPES["SET_PRODUCTS_LIST"] = "SET_PRODUCTS_LIST";
29
34
  INVOICE_ACTION_TYPES["SET_SEARCH_QUERY"] = "SET_SEARCH_QUERY";
30
35
  INVOICE_ACTION_TYPES["SET_SKELTON_LOADING"] = "SET_SKELTON_LOADING";
31
36
  INVOICE_ACTION_TYPES["SET_TAX"] = "SET_TAX";
32
- INVOICE_ACTION_TYPES["SET_PRODUCTS_LIST"] = "SET_PRODUCTS_LIST";
33
- INVOICE_ACTION_TYPES["SET_COMPANIES_LIST"] = "SET_COMPANIES_LIST";
34
- INVOICE_ACTION_TYPES["SET_CUSTOMER"] = "SET_CUSTOMER";
35
37
  INVOICE_ACTION_TYPES["SET_TAXES"] = "SET_TAXES";
36
- INVOICE_ACTION_TYPES["SET_CUSTOMER_FORM"] = "SET_CUSTOMER_FORM";
37
38
  })(INVOICE_ACTION_TYPES || (exports.INVOICE_ACTION_TYPES = INVOICE_ACTION_TYPES = {}));
@@ -3,14 +3,6 @@ import { VISTA_TABLE_CELL_TYPE } from '@appcorp/app-corp-vista/type/vista-table-
3
3
  export declare const pageLimit: number;
4
4
  export declare const handleSplitId: (value: string) => string[];
5
5
  export declare const changeActionsMap: Record<string, (val: string | number | number[]) => string | number | number[]>;
6
- export declare const toastErrors: {
7
- fetchInvoiceError: string;
8
- submitFormError: string;
9
- networkError: string;
10
- genericError: string;
11
- validationError: string;
12
- formSubmittedSuccess: string;
13
- };
14
6
  export declare const staticCompanySection: VistaFormElements;
15
7
  export declare const staticCustomerSection: VistaFormElements;
16
8
  export declare const staticPricingSection: VistaFormElements;
@@ -50,6 +42,10 @@ export declare const tableBodyCols: ({
50
42
  key?: undefined;
51
43
  expression?: undefined;
52
44
  })[];
45
+ export declare const networkMessages: {
46
+ error: string;
47
+ success: string;
48
+ };
53
49
  export declare const validationErrors: {
54
50
  companyId: string;
55
51
  ref: string;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  var _a, _b, _c, _d, _e;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.validationErrors = exports.tableBodyCols = exports.INVOICE_API_ROUTES = exports.staticProductSection = exports.staticServiceSection = exports.staticPricingSection = exports.staticCustomerSection = exports.staticCompanySection = exports.toastErrors = exports.changeActionsMap = exports.handleSplitId = exports.pageLimit = void 0;
7
+ exports.validationErrors = exports.networkMessages = exports.tableBodyCols = exports.INVOICE_API_ROUTES = exports.staticProductSection = exports.staticServiceSection = exports.staticPricingSection = exports.staticCustomerSection = exports.staticCompanySection = exports.changeActionsMap = exports.handleSplitId = exports.pageLimit = void 0;
8
8
  var react_1 = __importDefault(require("react"));
9
9
  var util_functions_1 = require("@react-pakistan/util-functions");
10
10
  var form_schema_1 = require("@appcorp/app-corp-vista/utils/form-schema");
@@ -20,14 +20,6 @@ exports.handleSplitId = handleSplitId;
20
20
  exports.changeActionsMap = {
21
21
  companyId: function (val) { return (0, exports.handleSplitId)(val)[1]; },
22
22
  };
23
- exports.toastErrors = {
24
- fetchInvoiceError: 'Error Fetching Invoice',
25
- submitFormError: 'Error Submitting Form',
26
- networkError: 'Network Error Occurred',
27
- genericError: 'Something Went Wrong',
28
- validationError: 'Validation Failed',
29
- formSubmittedSuccess: 'Form Submitted Successfully',
30
- };
31
23
  exports.staticCompanySection = (_a = {},
32
24
  _a[form_schema_1.VISTA_FORM_ELEMENTS.TEXT_INPUT_V1] = [
33
25
  {
@@ -568,6 +560,10 @@ exports.tableBodyCols = [
568
560
  componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.ACTIONS,
569
561
  },
570
562
  ];
563
+ exports.networkMessages = {
564
+ error: 'Error occurred, please, try again',
565
+ success: 'Operation successful!',
566
+ };
571
567
  exports.validationErrors = {
572
568
  companyId: 'Please select Company',
573
569
  ref: 'Please enter ref',
@@ -108,12 +108,13 @@ var util_functions_2 = require("@react-pakistan/util-functions");
108
108
  var context_1 = require("@appcorp/stellar-solutions-modules/global-modules/tax/context");
109
109
  var context_2 = require("@appcorp/stellar-solutions-modules/global-modules/preferences/context");
110
110
  var useInvoiceState = function () {
111
- var _a = (0, react_1.useReducer)(reducer_1.invoiceReducer, reducer_1.initialInvoiceState), state = _a[0], dispatch = _a[1];
111
+ var _a;
112
+ var _b = (0, react_1.useReducer)(reducer_1.invoiceReducer, reducer_1.initialInvoiceState), state = _b[0], dispatch = _b[1];
112
113
  var taxes = (0, context_1.useTaxStateContext)().taxes;
113
114
  var currencies = (0, context_2.usePreferenceStateContext)().currencies;
114
115
  var debouncedQuery = (0, util_functions_1.useDebounce)(state.searchQuery, 800);
115
116
  var debouncedProductList = (0, util_functions_1.useDebounce)(state.productQuery, 800);
116
- var debouncedCustomer = (0, util_functions_1.useDebounce)(state.phone, 800);
117
+ var debouncedCustomer = (0, util_functions_1.useDebounce)((_a = state === null || state === void 0 ? void 0 : state.customer) === null || _a === void 0 ? void 0 : _a.phone, 800);
117
118
  var debouncedTaxList = (0, util_functions_1.useDebounce)(state.taxQuery, 800);
118
119
  var debouncedCompanyList = (0, util_functions_1.useDebounce)(state.companyQuery, 800);
119
120
  var defaultTax = (0, react_1.useMemo)(function () {
@@ -139,7 +140,7 @@ var useInvoiceState = function () {
139
140
  if (error) {
140
141
  (0, generate_toast_1.generateToast)({
141
142
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
142
- description: constants_1.toastErrors.fetchInvoiceError,
143
+ description: constants_1.networkMessages.error,
143
144
  });
144
145
  }
145
146
  if (data === null || data === void 0 ? void 0 : data.items) {
@@ -153,39 +154,41 @@ var useInvoiceState = function () {
153
154
  });
154
155
  }
155
156
  };
156
- var updateParams = (0, react_1.useMemo)(function () { return ({
157
- category: state.category,
158
- companyId: state.companyId,
159
- currency: state.currency,
160
- customerId: state.customerId,
161
- date: state.date,
162
- discount: state.discount.trim(),
163
- discountUnit: state.discountUnit,
164
- expiryDate: state.expiryDate,
165
- id: state.id,
166
- invoiceStatus: state.invoiceStatus,
167
- mode: state.mode,
168
- note: state.note.trim(),
169
- phone: state.phone,
170
- products: state.products,
171
- quoteStatus: state.quoteStatus,
172
- ref: state.ref,
173
- services: state.services,
174
- subTotal: state.subTotal,
175
- taxRate: state.taxRate,
176
- total: state.total,
177
- }); }, [state]);
157
+ var updateParams = (0, react_1.useMemo)(function () {
158
+ var _a;
159
+ return ({
160
+ category: state.category,
161
+ companyId: state.companyId,
162
+ currency: state.currency,
163
+ customerId: state.customerId,
164
+ date: state.date,
165
+ discount: (_a = state === null || state === void 0 ? void 0 : state.discount) === null || _a === void 0 ? void 0 : _a.trim(),
166
+ discountUnit: state.discountUnit,
167
+ expiryDate: state.expiryDate,
168
+ id: state.id,
169
+ invoiceStatus: state.invoiceStatus,
170
+ mode: state.mode,
171
+ note: state.note.trim(),
172
+ products: state.products,
173
+ quoteStatus: state.quoteStatus,
174
+ ref: state.ref,
175
+ services: state.services,
176
+ subTotal: state.subTotal,
177
+ taxRate: state.taxRate,
178
+ total: state.total,
179
+ });
180
+ }, [state]);
178
181
  var updateCallback = function (_a) {
179
182
  var data = _a.data, error = _a.error;
180
183
  if (error) {
181
184
  (0, generate_toast_1.generateToast)({
182
- description: constants_1.toastErrors.networkError,
185
+ description: constants_1.networkMessages.error,
183
186
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
184
187
  });
185
188
  }
186
189
  if (data) {
187
190
  (0, generate_toast_1.generateToast)({
188
- description: constants_1.toastErrors.networkError,
191
+ description: constants_1.networkMessages.success,
189
192
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.SUCCESS,
190
193
  });
191
194
  dispatch({
@@ -209,7 +212,7 @@ var useInvoiceState = function () {
209
212
  var data = _a.data, error = _a.error;
210
213
  if (error) {
211
214
  (0, generate_toast_1.generateToast)({
212
- description: constants_1.toastErrors.networkError,
215
+ description: constants_1.networkMessages.error,
213
216
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
214
217
  });
215
218
  }
@@ -259,13 +262,13 @@ var useInvoiceState = function () {
259
262
  var data = _a.data, error = _a.error;
260
263
  if (error) {
261
264
  (0, generate_toast_1.generateToast)({
262
- description: constants_1.toastErrors.networkError,
265
+ description: constants_1.networkMessages.error,
263
266
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
264
267
  });
265
268
  }
266
269
  if (data) {
267
270
  (0, generate_toast_1.generateToast)({
268
- description: constants_1.toastErrors.networkError,
271
+ description: constants_1.networkMessages.success,
269
272
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.SUCCESS,
270
273
  });
271
274
  dispatch({
@@ -274,7 +277,7 @@ var useInvoiceState = function () {
274
277
  listFetchNow();
275
278
  }
276
279
  };
277
- var _b = (0, util_functions_1.useModuleEntity)({
280
+ var _c = (0, util_functions_1.useModuleEntity)({
278
281
  byIdCallback: byIdCallback,
279
282
  byIdParams: byIdParams,
280
283
  deleteCallback: deleteCallback,
@@ -288,7 +291,7 @@ var useInvoiceState = function () {
288
291
  updateCallback: updateCallback,
289
292
  updateDeps: [state],
290
293
  updateParams: __assign(__assign({}, updateParams), { mode: 'Create' }),
291
- }), byIdError = _b.byIdError, byIdFetchNow = _b.byIdFetchNow, byIdLoading = _b.byIdLoading, deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError, listFetchNow = _b.listFetchNow, listLoading = _b.listLoading, updateError = _b.updateError, updateFetchNow = _b.updateFetchNow, updateLoading = _b.updateLoading;
294
+ }), byIdError = _c.byIdError, byIdFetchNow = _c.byIdFetchNow, byIdLoading = _c.byIdLoading, deleteError = _c.deleteError, deleteFetchNow = _c.deleteFetchNow, deleteLoading = _c.deleteLoading, listError = _c.listError, listFetchNow = _c.listFetchNow, listLoading = _c.listLoading, updateError = _c.updateError, updateFetchNow = _c.updateFetchNow, updateLoading = _c.updateLoading;
292
295
  (0, react_1.useEffect)(function () {
293
296
  listFetchNow();
294
297
  // eslint-disable-next-line
@@ -316,7 +319,7 @@ var useInvoiceState = function () {
316
319
  if (data === null || data === void 0 ? void 0 : data.items) {
317
320
  dispatch({
318
321
  type: actions_1.INVOICE_ACTION_TYPES.SET_PRODUCTS_LIST,
319
- payload: { productsList: data.items },
322
+ payload: { list: data.items },
320
323
  });
321
324
  }
322
325
  return [2 /*return*/];
@@ -411,7 +414,7 @@ var useInvoiceState = function () {
411
414
  }); })();
412
415
  }, [debouncedTaxList]);
413
416
  (0, react_1.useEffect)(function () {
414
- var _a = (0, calculate_total_1.calculateTotal)(state.subTotal, state.taxRate, state.discountUnit, state.discount), afterDiscount = _a.afterDiscount, tax = _a.tax, total = _a.total;
417
+ var _a = (0, calculate_total_1.calculateTotal)(state.subTotal, state.taxRate, state.discountUnit, state.discount || '0'), afterDiscount = _a.afterDiscount, tax = _a.tax, total = _a.total;
415
418
  dispatch({
416
419
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
417
420
  payload: {
@@ -444,7 +447,7 @@ var useInvoiceState = function () {
444
447
  };
445
448
  dispatch({
446
449
  type: actions_1.INVOICE_ACTION_TYPES.ADD_ITEM_SERVICE,
447
- payload: { services: __spreadArray(__spreadArray([], state.services, true), [newItem], false) },
450
+ payload: { servicesList: __spreadArray(__spreadArray([], state.servicesList, true), [newItem], false) },
448
451
  });
449
452
  };
450
453
  var handleAddItemProduct = function () {
@@ -457,7 +460,7 @@ var useInvoiceState = function () {
457
460
  };
458
461
  dispatch({
459
462
  type: actions_1.INVOICE_ACTION_TYPES.ADD_ITEM_PRODUCT,
460
- payload: { products: __spreadArray(__spreadArray([], state.products, true), [newItem], false) },
463
+ payload: { productsList: __spreadArray(__spreadArray([], state.productsList, true), [newItem], false) },
461
464
  });
462
465
  };
463
466
  var handleCreate = function (text) {
@@ -498,7 +501,7 @@ var useInvoiceState = function () {
498
501
  schema: validate_1.formValidation,
499
502
  successCallback: function () {
500
503
  updateFetchNow(undefined, {
501
- body: JSON.stringify(__assign(__assign({}, updateParams), { products: updateParams.products.filter(function (item) { return item.id; }), services: updateParams.services.filter(function (item) { return item.name; }), currency: updateParams.currency || defaultCurrency.code, taxRate: updateParams.taxRate || defaultTax.taxRate })),
504
+ 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 })),
502
505
  });
503
506
  },
504
507
  errorCallback: function (e) {
@@ -508,8 +511,8 @@ var useInvoiceState = function () {
508
511
  });
509
512
  },
510
513
  });
511
- }, [updateFetchNow, updateParams, defaultCurrency, defaultTax]);
512
- var handleChange = (0, react_1.useCallback)(function (key, value) {
514
+ }, [updateFetchNow, updateParams, defaultCurrency, defaultTax, state.productsList, state.servicesList]);
515
+ var handleCustomerChange = (0, react_1.useCallback)(function (key, value) {
513
516
  var _a;
514
517
  if (key === 'phone') {
515
518
  var formattedNumber = (_a = (0, util_functions_1.formatPhone)(value)) === null || _a === void 0 ? void 0 : _a.international;
@@ -519,6 +522,19 @@ var useInvoiceState = function () {
519
522
  });
520
523
  return;
521
524
  }
525
+ dispatch({
526
+ type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER_FORM,
527
+ payload: { key: key, value: value },
528
+ });
529
+ dispatch({
530
+ type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
531
+ payload: { disableSaveButton: false },
532
+ });
533
+ dispatch({
534
+ type: actions_1.INVOICE_ACTION_TYPES.RESET_ERRORS,
535
+ });
536
+ }, []);
537
+ var handleChange = (0, react_1.useCallback)(function (key, value) {
522
538
  if (key === 'companyQuery') {
523
539
  dispatch({
524
540
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
@@ -526,10 +542,6 @@ var useInvoiceState = function () {
526
542
  });
527
543
  return;
528
544
  }
529
- dispatch({
530
- type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER_FORM,
531
- payload: { key: key, value: String(value) },
532
- });
533
545
  dispatch({
534
546
  type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
535
547
  payload: { disableSaveButton: false },
@@ -564,13 +576,13 @@ var useInvoiceState = function () {
564
576
  var handleItemChangeServices = (0, react_1.useCallback)(function (_a) {
565
577
  var _b;
566
578
  var index = _a.index, key = _a.key, value = _a.value;
567
- var updatedItems = __spreadArray([], state.services, true);
579
+ var updatedItems = __spreadArray([], state.servicesList, true);
568
580
  updatedItems[index] = __assign(__assign({}, updatedItems[index]), (_b = {}, _b[key] = value, _b.mode = updatedItems[index].mode === 'Create' ? 'Create' : 'Edit', _b));
569
581
  var quantity = parseFloat(updatedItems[index].quantity) || 0;
570
582
  var price = parseFloat(updatedItems[index].price) || 0;
571
583
  var rowTotal = (quantity * price).toFixed(2);
572
584
  updatedItems[index].rowTotal = rowTotal;
573
- var allProducts = state.products;
585
+ var allProducts = state.productsList;
574
586
  var subtotal = (0, calculate_subtotal_1.calculateSubtotal)(updatedItems, allProducts);
575
587
  dispatch({
576
588
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
@@ -578,21 +590,21 @@ var useInvoiceState = function () {
578
590
  });
579
591
  dispatch({
580
592
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
581
- payload: { key: 'services', value: updatedItems },
593
+ payload: { key: 'servicesList', value: updatedItems },
582
594
  });
583
- }, [state.products, state.services]);
595
+ }, [state.productsList, state.servicesList]);
584
596
  var handleItemChangeProducts = (0, react_1.useCallback)(function (_a) {
585
597
  var _b, _c, _d;
586
598
  var _e;
587
599
  var index = _a.index, key = _a.key, value = _a.value;
588
- var updatedItems = __spreadArray([], state.products, true);
600
+ var updatedItems = __spreadArray([], state.productsList, true);
589
601
  if (key === 'id' && typeof value === 'string') {
590
- var matchingProduct = (_e = state.productsList) === null || _e === void 0 ? void 0 : _e.find(function (product) { return product.id === value; });
602
+ var matchingProduct = (_e = state.getProducts) === null || _e === void 0 ? void 0 : _e.find(function (product) { return product.id === value; });
591
603
  if (matchingProduct) {
592
604
  var quantity = parseFloat(String(updatedItems[index].quantity)) || 0;
593
605
  var rowTotal = (quantity * parseFloat(matchingProduct.salePrice)).toFixed(2);
594
606
  updatedItems[index] = __assign(__assign({}, updatedItems[index]), (_b = {}, _b[key] = value, _b.price = matchingProduct.salePrice, _b.mode = updatedItems[index].mode === 'Create' ? 'Create' : 'Edit', _b.rowTotal = rowTotal, _b));
595
- var allServices = state.services;
607
+ var allServices = state.servicesList;
596
608
  var subtotal = (0, calculate_subtotal_1.calculateSubtotal)(allServices, updatedItems);
597
609
  dispatch({
598
610
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
@@ -609,7 +621,7 @@ var useInvoiceState = function () {
609
621
  var price = parseFloat(updatedItems[index].price) || 0;
610
622
  var rowTotal = (quantity * price).toFixed(2);
611
623
  updatedItems[index] = __assign(__assign({}, updatedItems[index]), { rowTotal: rowTotal });
612
- var allServices = state.services;
624
+ var allServices = state.servicesList;
613
625
  var subtotal = (0, calculate_subtotal_1.calculateSubtotal)(allServices, updatedItems);
614
626
  dispatch({
615
627
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
@@ -618,9 +630,9 @@ var useInvoiceState = function () {
618
630
  }
619
631
  dispatch({
620
632
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
621
- payload: { key: 'products', value: updatedItems },
633
+ payload: { key: 'productsList', value: updatedItems },
622
634
  });
623
- }, [state.services, state.products, state.productsList]);
635
+ }, [state.servicesList, state.productsList, state.getProducts]);
624
636
  var handlePriceTypeChange = function (k, v) {
625
637
  dispatch({
626
638
  type: actions_1.INVOICE_ACTION_TYPES.SET_DISCOUNT_UNIT,
@@ -750,7 +762,7 @@ var useInvoiceState = function () {
750
762
  var _b;
751
763
  var id = _a.id;
752
764
  textInputElements[i].error = state.errors[id];
753
- textInputElements[i].handleOnChange = handleChange;
765
+ textInputElements[i].handleOnChange = handleCustomerChange;
754
766
  textInputElements[i].value = (_b = state === null || state === void 0 ? void 0 : state.customer) === null || _b === void 0 ? void 0 : _b[id];
755
767
  });
756
768
  }
@@ -760,15 +772,15 @@ var useInvoiceState = function () {
760
772
  comboboxElements[0].listItems = util_functions_2.countriesTimeZones;
761
773
  comboboxElements[0].query = state.countryQuery;
762
774
  comboboxElements[0].handleOnChange = handleSelectChange;
763
- comboboxElements[0].handleInputOnChange = handleChange;
764
- comboboxElements[0].handleOnBlur = handleChange;
775
+ comboboxElements[0].handleInputOnChange = handleCustomerChange;
776
+ comboboxElements[0].handleOnBlur = handleCustomerChange;
765
777
  comboboxElements[1].selectedItem = { code: state.currency || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.code) };
766
778
  comboboxElements[1].listItems = currencies;
767
779
  comboboxElements[1].handleOnChange = handleSelectChange;
768
- comboboxElements[1].handleInputOnChange = handleChange;
780
+ comboboxElements[1].handleInputOnChange = handleCustomerChange;
769
781
  }
770
782
  return elements;
771
- }, [state, handleChange, currencies, defaultCurrency]);
783
+ }, [state, currencies, handleCustomerChange, defaultCurrency]);
772
784
  var dynamicPricingFormElements = (0, react_1.useMemo)(function () {
773
785
  var _a, _b, _c, _d, _e, _f;
774
786
  var elements = __assign({}, constants_1.staticPricingSection);
@@ -777,7 +789,7 @@ var useInvoiceState = function () {
777
789
  textElements[0].value = state.subTotal;
778
790
  textElements[0].error = (_b = state.errors) === null || _b === void 0 ? void 0 : _b.subTotal;
779
791
  textElements[0].handleOnChange = handleChange;
780
- textElements[1].value = state.discount;
792
+ textElements[1].value = state.discount || '0';
781
793
  textElements[1].error = (_c = state.errors) === null || _c === void 0 ? void 0 : _c.discount;
782
794
  textElements[1].handleOnChange = handleChange;
783
795
  textElements[2].value = state.afterDiscount ? String(state.afterDiscount) : '0';
@@ -804,20 +816,20 @@ var useInvoiceState = function () {
804
816
  return elements;
805
817
  }, [handleChange, state, taxes, defaultTax]);
806
818
  var handleDeleteServiceRow = function (i) {
807
- if (state.services.length > 1) {
808
- var res = state.services.splice(i, 1);
819
+ if (state.servicesList.length > 1) {
820
+ var res = state.servicesList.splice(i, 1);
809
821
  dispatch({
810
822
  type: actions_1.INVOICE_ACTION_TYPES.DELETE_ITEM_SERVICE,
811
- payload: { services: __spreadArray([], res, true) },
823
+ payload: { servicesList: __spreadArray([], res, true) },
812
824
  });
813
825
  }
814
826
  };
815
827
  var handleDeleteProductRow = function (i) {
816
- if (state.products.length > 1) {
817
- var res = state.products.splice(i, 1);
828
+ if (state.productsList.length > 1) {
829
+ var res = state.productsList.splice(i, 1);
818
830
  dispatch({
819
831
  type: actions_1.INVOICE_ACTION_TYPES.DELETE_ITEM_PRODUCT,
820
- payload: { products: __spreadArray([], res, true) },
832
+ payload: { productsList: __spreadArray([], res, true) },
821
833
  });
822
834
  }
823
835
  };
@@ -13,7 +13,7 @@ var form_1 = require("./form");
13
13
  var Drawer = function (_a) {
14
14
  var translationMap = _a.translationMap;
15
15
  var _b = (0, context_1.useInvoiceStateContext)(), closeDrawer = _b.closeDrawer, disableSaveButton = _b.disableSaveButton, drawer = _b.drawer, handleSubmit = _b.handleSubmit;
16
- return (react_1.default.createElement(vista_drawer_v1_1.VistaDrawerV1, { cancelLabel: "Cancel", cancelRounded: vista_button_type_1.VISTA_BUTTON_ROUNDED.MD, cancelSize: vista_button_type_1.VISTA_BUTTON_SIZE.LG, handleCancelOnClick: closeDrawer, handleSaveOnClick: handleSubmit, handleSetIsOpen: closeDrawer, isOpen: !!drawer, saveDisabled: disableSaveButton, saveLabel: 'Save', saveRounded: vista_button_type_1.VISTA_BUTTON_ROUNDED.MD, saveSize: vista_button_type_1.VISTA_BUTTON_SIZE.LG, size: vista_drawer_type_1.VISTA_DRAWER_SIZE.XL, title: 'Product' },
16
+ return (react_1.default.createElement(vista_drawer_v1_1.VistaDrawerV1, { cancelLabel: "Cancel", cancelRounded: vista_button_type_1.VISTA_BUTTON_ROUNDED.MD, cancelSize: vista_button_type_1.VISTA_BUTTON_SIZE.LG, handleCancelOnClick: closeDrawer, handleSaveOnClick: handleSubmit, handleSetIsOpen: closeDrawer, isOpen: !!drawer, saveDisabled: disableSaveButton, saveLabel: 'Save', saveRounded: vista_button_type_1.VISTA_BUTTON_ROUNDED.MD, saveSize: vista_button_type_1.VISTA_BUTTON_SIZE.LG, size: vista_drawer_type_1.VISTA_DRAWER_SIZE.XL, title: 'Invoice' },
17
17
  react_1.default.createElement(form_1.InvoiceForm, { translationMap: translationMap })));
18
18
  };
19
19
  exports.Drawer = Drawer;
@@ -24,10 +24,10 @@ var solid_1 = require("@heroicons/react/24/solid");
24
24
  var vista_button_type_1 = require("@appcorp/app-corp-vista/type/vista-button-type");
25
25
  var vista_combobox_v1_1 = require("@appcorp/app-corp-vista/molecules/vista-combobox-v1/vista-combobox-v1");
26
26
  var ProductsSection = function () {
27
- var _a = (0, context_1.useInvoiceStateContext)(), products = _a.products, handleItemChangeProducts = _a.handleItemChangeProducts, handleDeleteServiceRow = _a.handleDeleteServiceRow, handleChange = _a.handleChange, productsList = _a.productsList;
27
+ var _a = (0, context_1.useInvoiceStateContext)(), handleChange = _a.handleChange, handleDeleteServiceRow = _a.handleDeleteServiceRow, handleItemChangeProducts = _a.handleItemChangeProducts, productsList = _a.productsList, getProducts = _a.getProducts;
28
28
  return (react_1.default.createElement("div", { className: "flex flex-col gap-4" },
29
29
  react_1.default.createElement(vista_vertical_divider_v4_1.VistaVerticalDividerV4, { label: "Products" }),
30
- products.map(function (row, index) { return (react_1.default.createElement("div", { key: index, className: 'grid grid-cols-[17.5%_17.5%_17.5%_17.5%_17.5%_auto] items-end justify-between gap-4' },
30
+ productsList.length > 0 && (productsList === null || productsList === void 0 ? void 0 : productsList.map(function (row, index) { return (react_1.default.createElement("div", { key: index, className: 'grid grid-cols-[17.5%_17.5%_17.5%_17.5%_17.5%_auto] items-end justify-between gap-4' },
31
31
  react_1.default.createElement("div", { className: 'col-span-2' },
32
32
  react_1.default.createElement(vista_combobox_v1_1.VistaComboboxV1, { handleOnChange: function (k, v) {
33
33
  var val = __assign({}, v);
@@ -36,10 +36,10 @@ var ProductsSection = function () {
36
36
  key: k,
37
37
  value: val.id,
38
38
  });
39
- }, handleOnBlur: handleChange, handleInputOnChange: handleChange, label: "Product", listItems: productsList, nodeQueryKey: 'productQuery', nodeSelectKey: 'id', query: '', selectKey1: 'name', selectedItem: { id: products[index].id } })),
40
- react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeProducts({ index: index, key: k, value: v }); }, id: 'quantity', label: 'Quantity', placeholder: '1', value: String(products[index].quantity), type: 'text' }),
41
- react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeProducts({ index: index, key: k, value: v }); }, id: 'price', label: 'Price', placeholder: '0.00', value: products[index].price, type: 'number' }),
42
- react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeProducts({ index: index, key: k, value: v }); }, id: 'rowTotal', label: 'Row Total', placeholder: '0.00', value: products[index].rowTotal, type: 'number', readOnly: true }),
43
- react_1.default.createElement(vista_button_v1_1.VistaButtonV1, { className: 'flex justify-center items-end', handleOnClick: function () { return handleDeleteServiceRow(index); }, icon: react_1.default.createElement(solid_1.TrashIcon, { className: "size-6" }), variant: vista_button_type_1.VISTA_BUTTON_VARIANT.ICON }))); })));
39
+ }, handleOnBlur: handleChange, handleInputOnChange: handleChange, label: "Product", listItems: getProducts, nodeQueryKey: 'productQuery', nodeSelectKey: 'id', query: '', selectKey1: 'name', selectedItem: { id: productsList[index].id } })),
40
+ react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeProducts({ index: index, key: k, value: v }); }, id: 'quantity', label: 'Quantity', placeholder: '1', value: String(productsList[index].quantity), type: 'number' }),
41
+ react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeProducts({ index: index, key: k, value: v }); }, id: 'price', label: 'Price', placeholder: '0.00', value: productsList[index].price, type: 'number' }),
42
+ react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeProducts({ index: index, key: k, value: v }); }, id: 'rowTotal', label: 'Row Total', placeholder: '0.00', value: productsList[index].rowTotal, type: 'number', readOnly: true }),
43
+ react_1.default.createElement(vista_button_v1_1.VistaButtonV1, { className: 'flex justify-center items-end', handleOnClick: function () { return handleDeleteServiceRow(index); }, icon: react_1.default.createElement(solid_1.TrashIcon, { className: "size-6" }), variant: vista_button_type_1.VISTA_BUTTON_VARIANT.ICON }))); }))));
44
44
  };
45
45
  exports.ProductsSection = ProductsSection;
@@ -34,6 +34,7 @@ exports.initialInvoiceState = {
34
34
  count: 0,
35
35
  countryQuery: '',
36
36
  currency: '',
37
+ services: [],
37
38
  customer: {
38
39
  address: '',
39
40
  city: '',
@@ -54,20 +55,21 @@ exports.initialInvoiceState = {
54
55
  discount: '0',
55
56
  discountUnit: types_1.DISCOUNT_UNIT.FIXED_VALUE,
56
57
  drawer: null,
57
- errors: {},
58
+ errors: {
59
+ phone: 'Phone number is not well formatted',
60
+ },
58
61
  expiryDate: (0, date_fns_1.addDays)(new Date(), 7).toISOString(),
59
62
  id: '',
60
63
  invoiceStatus: types_1.INVOICE_STATUS.UNPAID,
61
64
  invoices: [],
62
65
  loading: true,
66
+ getProducts: [],
63
67
  modal: null,
64
68
  mode: 'Create',
65
69
  netTotal: '',
66
70
  note: '',
67
71
  pageLimit: constants_1.pageLimit,
68
72
  payments: [],
69
- phone: '',
70
- productsList: [],
71
73
  companiesList: [],
72
74
  productQuery: '',
73
75
  quoteStatus: types_1.QUOTE_STATUS.DRAFT,
@@ -79,6 +81,7 @@ exports.initialInvoiceState = {
79
81
  taxQuery: '',
80
82
  taxes: [],
81
83
  total: '',
84
+ products: [],
82
85
  company: {
83
86
  name: '',
84
87
  country: '',
@@ -89,7 +92,7 @@ exports.initialInvoiceState = {
89
92
  email: '',
90
93
  website: '',
91
94
  },
92
- services: [
95
+ servicesList: [
93
96
  {
94
97
  mode: 'Create',
95
98
  name: '',
@@ -99,7 +102,7 @@ exports.initialInvoiceState = {
99
102
  rowTotal: '',
100
103
  },
101
104
  ],
102
- products: [
105
+ productsList: [
103
106
  {
104
107
  mode: 'Create',
105
108
  price: '',
@@ -117,7 +120,11 @@ function invoiceReducer(state, action) {
117
120
  case actions_1.INVOICE_ACTION_TYPES.RESET_ERRORS:
118
121
  return __assign(__assign({}, state), { errors: {} });
119
122
  case actions_1.INVOICE_ACTION_TYPES.RESET_FORM:
120
- return __assign({}, state);
123
+ return __assign(__assign(__assign(__assign({}, state), (state.customer && ({
124
+ customer: __assign({}, exports.initialInvoiceState.customer),
125
+ }))), (state.company && ({
126
+ company: __assign({}, exports.initialInvoiceState.company),
127
+ }))), { productsList: __assign({}, exports.initialInvoiceState.productsList), servicesList: __assign({}, exports.initialInvoiceState.servicesList), subTotal: exports.initialInvoiceState.subTotal, discount: exports.initialInvoiceState.discount, discountUnit: exports.initialInvoiceState.discountUnit, afterDiscount: exports.initialInvoiceState.afterDiscount, tax: exports.initialInvoiceState.tax, total: exports.initialInvoiceState.total, category: exports.initialInvoiceState.category, companyId: exports.initialInvoiceState.companyId, companyQuery: exports.initialInvoiceState.companyQuery, countryQuery: exports.initialInvoiceState.companyQuery, currency: exports.initialInvoiceState.currency, contactsList: exports.initialInvoiceState.contactsList, customerId: exports.initialInvoiceState.customerId, date: exports.initialInvoiceState.date, disableSaveButton: exports.initialInvoiceState.disableSaveButton, expiryDate: exports.initialInvoiceState.expiryDate, id: exports.initialInvoiceState.id, invoiceStatus: exports.initialInvoiceState.invoiceStatus, loading: exports.initialInvoiceState.loading, getProducts: exports.initialInvoiceState.getProducts, mode: exports.initialInvoiceState.mode, netTotal: exports.initialInvoiceState.netTotal, note: exports.initialInvoiceState.note, payments: exports.initialInvoiceState.payments, companiesList: exports.initialInvoiceState.companiesList, productQuery: exports.initialInvoiceState.productQuery, taxRate: exports.initialInvoiceState.taxRate, taxQuery: exports.initialInvoiceState.taxQuery, taxes: exports.initialInvoiceState.taxes });
121
128
  case actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON:
122
129
  return __assign(__assign({}, state), { disableSaveButton: action.payload.disableSaveButton });
123
130
  case actions_1.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE:
@@ -138,11 +145,8 @@ function invoiceReducer(state, action) {
138
145
  return __assign(__assign({}, state), action.payload.form);
139
146
  case actions_1.INVOICE_ACTION_TYPES.SET_DRAWER:
140
147
  return __assign(__assign({}, state), { drawer: action.payload.drawer });
141
- // case INVOICE_ACTION_TYPES.SET_MODAL:
142
- // return {
143
- // ...state,
144
- // modal: action.payload.modal,
145
- // };
148
+ case actions_1.INVOICE_ACTION_TYPES.SET_MODAL:
149
+ return __assign(__assign({}, state), { modal: action.payload.modal });
146
150
  case actions_1.INVOICE_ACTION_TYPES.SET_DISCOUNT_UNIT:
147
151
  return __assign(__assign({}, state), { discountUnit: action.payload.discountUnit });
148
152
  case actions_1.INVOICE_ACTION_TYPES.SET_AFTER_DISCOUNT:
@@ -150,17 +154,17 @@ function invoiceReducer(state, action) {
150
154
  case actions_1.INVOICE_ACTION_TYPES.SET_TAX:
151
155
  return __assign(__assign({}, state), { tax: action.payload.tax });
152
156
  case actions_1.INVOICE_ACTION_TYPES.ADD_ITEM_SERVICE:
153
- return __assign(__assign({}, state), { services: __spreadArray([], action.payload.services, true) });
157
+ return __assign(__assign({}, state), { servicesList: __spreadArray([], action.payload.servicesList, true) });
154
158
  case actions_1.INVOICE_ACTION_TYPES.ADD_ITEM_PRODUCT:
155
- return __assign(__assign({}, state), { products: __spreadArray([], action.payload.products, true) });
159
+ return __assign(__assign({}, state), { productsList: __spreadArray([], action.payload.productsList, true) });
156
160
  case actions_1.INVOICE_ACTION_TYPES.DELETE_ITEM_SERVICE:
157
- return __assign(__assign({}, state), { services: __spreadArray([], action.payload.services, true) });
161
+ return __assign(__assign({}, state), { servicesList: __spreadArray([], action.payload.servicesList, true) });
158
162
  case actions_1.INVOICE_ACTION_TYPES.DELETE_ITEM_PRODUCT:
159
- return __assign(__assign({}, state), { products: __spreadArray([], action.payload.products, true) });
160
- case actions_1.INVOICE_ACTION_TYPES.SET_PRODUCTS_LIST:
161
163
  return __assign(__assign({}, state), { productsList: __spreadArray([], action.payload.productsList, true) });
164
+ case actions_1.INVOICE_ACTION_TYPES.SET_PRODUCTS_LIST:
165
+ return __assign(__assign({}, state), { getProducts: __spreadArray([], action.payload.list, true) });
162
166
  case actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER:
163
- return __assign(__assign({}, state), { customerId: state.customerId, customer: __assign(__assign({}, state.customer), action.payload.customer) });
167
+ return __assign(__assign({}, state), { customerId: action.payload.customerId, customer: __assign(__assign({}, state.customer), action.payload.customer) });
164
168
  case actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER_FORM:
165
169
  return __assign(__assign({}, state), (state.customer && ({
166
170
  customer: __assign(__assign({}, state.customer), (_b = {}, _b[action.payload.key] = action.payload.value, _b)),
@@ -12,15 +12,15 @@ var vista_button_type_1 = require("@appcorp/app-corp-vista/type/vista-button-typ
12
12
  var solid_1 = require("@heroicons/react/24/solid");
13
13
  var context_1 = require("./context");
14
14
  var ServicesSection = function () {
15
- var _a = (0, context_1.useInvoiceStateContext)(), services = _a.services, handleItemChangeServices = _a.handleItemChangeServices, handleDeleteServiceRow = _a.handleDeleteServiceRow;
15
+ var _a = (0, context_1.useInvoiceStateContext)(), servicesList = _a.servicesList, handleItemChangeServices = _a.handleItemChangeServices, handleDeleteServiceRow = _a.handleDeleteServiceRow;
16
16
  return (react_1.default.createElement("div", { className: "flex flex-col gap-4" },
17
17
  react_1.default.createElement(vista_vertical_divider_v4_1.VistaVerticalDividerV4, { label: "Services" }),
18
- services.map(function (row, index) { return (react_1.default.createElement("div", { key: index, className: 'grid grid-cols-[17.5%_17.5%_17.5%_17.5%_17.5%_auto] items-end justify-between gap-4' },
19
- react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'name', label: 'Service Name', placeholder: 'Service Name', value: services[index].name, type: 'text' }),
20
- react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'description', label: 'Service Description', placeholder: 'Service Description', value: services[index].description, type: 'text' }),
21
- react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'quantity', label: 'Quantity', placeholder: '1', value: services[index].quantity, type: 'number' }),
22
- react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'price', label: 'Price', placeholder: '0.00', value: services[index].price, type: 'number' }),
23
- react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'rowTotal', label: 'Row Total', placeholder: '0.00', value: services[index].rowTotal, type: 'number', readOnly: true }),
24
- react_1.default.createElement(vista_button_v1_1.VistaButtonV1, { className: 'flex justify-center items-end', handleOnClick: function () { return handleDeleteServiceRow(index); }, icon: react_1.default.createElement(solid_1.TrashIcon, { className: "size-6" }), variant: vista_button_type_1.VISTA_BUTTON_VARIANT.ICON }))); })));
18
+ servicesList.length > 0 && (servicesList === null || servicesList === void 0 ? void 0 : servicesList.map(function (row, index) { return (react_1.default.createElement("div", { key: index, className: 'grid grid-cols-[17.5%_17.5%_17.5%_17.5%_17.5%_auto] items-end justify-between gap-4' },
19
+ react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'name', label: 'Service Name', placeholder: 'Service Name', value: servicesList[index].name, type: 'text' }),
20
+ react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'description', label: 'Service Description', placeholder: 'Service Description', value: servicesList[index].description, type: 'text' }),
21
+ react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'quantity', label: 'Quantity', placeholder: '1', value: servicesList[index].quantity, type: 'number' }),
22
+ react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'price', label: 'Price', placeholder: '0.00', value: servicesList[index].price, type: 'number' }),
23
+ react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'rowTotal', label: 'Row Total', placeholder: '0.00', value: servicesList[index].rowTotal, type: 'number', readOnly: true }),
24
+ react_1.default.createElement(vista_button_v1_1.VistaButtonV1, { className: 'flex justify-center items-end', handleOnClick: function () { return handleDeleteServiceRow(index); }, icon: react_1.default.createElement(solid_1.TrashIcon, { className: "size-6" }), variant: vista_button_type_1.VISTA_BUTTON_VARIANT.ICON }))); }))));
25
25
  };
26
26
  exports.ServicesSection = ServicesSection;
@@ -7,6 +7,7 @@ import { InvoiceActions } from './actions';
7
7
  import { ProductTypeBE } from '@appcorp/stellar-solutions-product-module/base-modules/product/types';
8
8
  import { ContactTypeBE } from '@appcorp/stellar-solutions-company-module/base-modules/contact/types';
9
9
  import { TaxTypeBE } from '@appcorp/stellar-solutions-modules/global-modules/preferences/types';
10
+ import { CustomerTypeBE } from '@appcorp/stellar-solutions-company-module/base-modules/customer/types';
10
11
  export interface InvoiceContextType {
11
12
  byIdError?: Error;
12
13
  byIdLoading: boolean;
@@ -62,22 +63,11 @@ export interface Service {
62
63
  mode: 'Create' | 'Edit' | '';
63
64
  rowTotal: string;
64
65
  }
65
- export interface CustomerTypeBE {
66
- address?: string;
67
- city: string;
68
- country: string;
69
- createdAt: string;
70
- email?: string;
71
- firstName: string;
72
- id: string;
73
- invoices?: InvoiceTypeBE[];
74
- lastName: string;
75
- phone: string;
76
- updatedAt: string;
77
- }
78
66
  export declare enum PAYMENT_MODE {
79
67
  }
80
68
  export declare enum PAYMENT_TYPE {
69
+ FULL_AMOUNT = "FULL_AMOUNT",
70
+ PARTIAL_AMOUNT = "PARTIAL_AMOUNT"
81
71
  }
82
72
  export interface PaymentTypeBE {
83
73
  amount: string;
@@ -90,12 +80,23 @@ export interface PaymentTypeBE {
90
80
  id: string;
91
81
  mode: PAYMENT_MODE;
92
82
  paymentType: PAYMENT_TYPE;
93
- quoteInvoice: InvoiceTypeBE;
83
+ quoteInvoice: QuoteInvoiceTypeBE;
94
84
  quoteInvoiceId: string;
95
85
  ref?: string;
96
86
  updatedAt: string;
97
87
  }
98
- export interface InvoiceTypeBE {
88
+ export interface ServiceTypeBE {
89
+ createdAt: string;
90
+ description?: string;
91
+ id: string;
92
+ name: string;
93
+ price: string;
94
+ quantity: string;
95
+ quoteInvoice?: QuoteInvoiceTypeBE;
96
+ quoteInvoiceId?: string;
97
+ updatedAt: string;
98
+ }
99
+ export interface QuoteInvoiceTypeBE {
99
100
  category: QUOTE_INVOICE_CATEGORY;
100
101
  company?: CompanyTypeBE;
101
102
  companyId?: string;
@@ -104,48 +105,54 @@ export interface InvoiceTypeBE {
104
105
  customer?: CustomerTypeBE;
105
106
  customerId?: string;
106
107
  date: string;
107
- discount: string;
108
+ discount?: string;
108
109
  discountUnit: DISCOUNT_UNIT;
109
110
  expiryDate: string;
110
111
  id: string;
111
112
  invoiceStatus: INVOICE_STATUS;
112
113
  note: string;
113
114
  payments: PaymentTypeBE[];
114
- products: Product[];
115
+ products: QuoteInvoiceProduct[];
115
116
  quoteStatus: QUOTE_STATUS;
116
117
  ref: string;
117
- services: Service[];
118
+ services: ServiceTypeBE[];
118
119
  subTotal: string;
119
120
  taxRate: string;
120
121
  total: string;
121
122
  updatedAt: string;
122
123
  }
123
- export interface InvoiceState extends Omit<InvoiceTypeBE, 'createdAt' | 'updatedAt'> {
124
+ export interface QuoteInvoiceProduct {
125
+ quoteInvoiceId: string;
126
+ productId: string;
127
+ product: ProductTypeBE;
128
+ quoteInvoice: QuoteInvoiceTypeBE;
129
+ quantity: string;
130
+ }
131
+ export interface InvoiceState extends Omit<QuoteInvoiceTypeBE, 'createdAt' | 'updatedAt'> {
124
132
  afterDiscount: string;
133
+ companiesList: CompanyTypeBE[];
125
134
  companyQuery: string;
126
135
  contactsList: ContactTypeBE[];
127
136
  count: number;
128
137
  countryQuery: string;
129
138
  currentPage: number;
130
- customer?: CustomerTypeBE;
131
139
  customerId?: string;
132
140
  disableSaveButton: boolean;
133
141
  drawer: null | INVOICE_DRAWER;
134
142
  errors: {
135
143
  [key: string]: string;
136
144
  };
137
- invoices: InvoiceTypeBE[];
145
+ getProducts: ProductTypeBE[];
146
+ invoices: QuoteInvoiceTypeBE[];
138
147
  loading: boolean;
139
- modal: null | PRODUCT_MODAL;
148
+ modal: null | INVOICE_MODAL;
140
149
  mode: 'Create' | 'Edit';
141
150
  netTotal: string;
142
151
  pageLimit: number;
143
- phone: string;
144
152
  productQuery: string;
145
- products: Product[];
146
- productsList: ProductTypeBE[];
147
- companiesList: CompanyTypeBE[];
153
+ productsList: Product[];
148
154
  searchQuery: string;
155
+ servicesList: Service[];
149
156
  tax: string;
150
157
  taxQuery: string;
151
158
  taxes: TaxTypeBE[];
@@ -159,29 +166,13 @@ export declare enum INVOICE_DRAWER {
159
166
  INVOICE_COMPANY_FORM_DRAWER = "INVOICE_COMPANY_FORM_DRAWER",
160
167
  INVOICE_CUSTOMER_FORM_DRAWER = "INVOICE_CUSTOMER_FORM_DRAWER"
161
168
  }
162
- export declare enum PRODUCT_MODAL {
169
+ export declare enum INVOICE_MODAL {
163
170
  DUMMY = "DUMMY"
164
171
  }
165
172
  export declare enum QUOTE_INVOICE_CATEGORY {
166
173
  QUOTE = "QUOTE",
167
174
  INVOICE = "INVOICE"
168
175
  }
169
- export declare enum CURRENCY {
170
- AUD = "AUD",
171
- BHD = "BHD",
172
- CAD = "CAD",
173
- CNY = "CNY",
174
- EUR = "EUR",
175
- GBP = "GBP",
176
- JOD = "JOD",
177
- JPY = "JPY",
178
- KWD = "KWD",
179
- MYR = "MYR",
180
- OMR = "OMR",
181
- PKR = "PKR",
182
- SAR = "SAR",
183
- USD = "USD"
184
- }
185
176
  export declare enum INVOICE_STATUS {
186
177
  UNPAID = "UNPAID",
187
178
  PAID = "PAID"
@@ -1,43 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DISCOUNT_UNIT = exports.QUOTE_STATUS = exports.INVOICE_STATUS = exports.CURRENCY = exports.QUOTE_INVOICE_CATEGORY = exports.PRODUCT_MODAL = exports.INVOICE_DRAWER = exports.PAYMENT_TYPE = exports.PAYMENT_MODE = void 0;
3
+ exports.DISCOUNT_UNIT = exports.QUOTE_STATUS = exports.INVOICE_STATUS = exports.QUOTE_INVOICE_CATEGORY = exports.INVOICE_MODAL = exports.INVOICE_DRAWER = exports.PAYMENT_TYPE = exports.PAYMENT_MODE = void 0;
4
4
  var PAYMENT_MODE;
5
5
  (function (PAYMENT_MODE) {
6
6
  })(PAYMENT_MODE || (exports.PAYMENT_MODE = PAYMENT_MODE = {}));
7
7
  var PAYMENT_TYPE;
8
8
  (function (PAYMENT_TYPE) {
9
+ PAYMENT_TYPE["FULL_AMOUNT"] = "FULL_AMOUNT";
10
+ PAYMENT_TYPE["PARTIAL_AMOUNT"] = "PARTIAL_AMOUNT";
9
11
  })(PAYMENT_TYPE || (exports.PAYMENT_TYPE = PAYMENT_TYPE = {}));
10
12
  var INVOICE_DRAWER;
11
13
  (function (INVOICE_DRAWER) {
12
14
  INVOICE_DRAWER["INVOICE_COMPANY_FORM_DRAWER"] = "INVOICE_COMPANY_FORM_DRAWER";
13
15
  INVOICE_DRAWER["INVOICE_CUSTOMER_FORM_DRAWER"] = "INVOICE_CUSTOMER_FORM_DRAWER";
14
16
  })(INVOICE_DRAWER || (exports.INVOICE_DRAWER = INVOICE_DRAWER = {}));
15
- var PRODUCT_MODAL;
16
- (function (PRODUCT_MODAL) {
17
- PRODUCT_MODAL["DUMMY"] = "DUMMY";
18
- })(PRODUCT_MODAL || (exports.PRODUCT_MODAL = PRODUCT_MODAL = {}));
17
+ var INVOICE_MODAL;
18
+ (function (INVOICE_MODAL) {
19
+ INVOICE_MODAL["DUMMY"] = "DUMMY";
20
+ })(INVOICE_MODAL || (exports.INVOICE_MODAL = INVOICE_MODAL = {}));
19
21
  var QUOTE_INVOICE_CATEGORY;
20
22
  (function (QUOTE_INVOICE_CATEGORY) {
21
23
  QUOTE_INVOICE_CATEGORY["QUOTE"] = "QUOTE";
22
24
  QUOTE_INVOICE_CATEGORY["INVOICE"] = "INVOICE";
23
25
  })(QUOTE_INVOICE_CATEGORY || (exports.QUOTE_INVOICE_CATEGORY = QUOTE_INVOICE_CATEGORY = {}));
24
- var CURRENCY;
25
- (function (CURRENCY) {
26
- CURRENCY["AUD"] = "AUD";
27
- CURRENCY["BHD"] = "BHD";
28
- CURRENCY["CAD"] = "CAD";
29
- CURRENCY["CNY"] = "CNY";
30
- CURRENCY["EUR"] = "EUR";
31
- CURRENCY["GBP"] = "GBP";
32
- CURRENCY["JOD"] = "JOD";
33
- CURRENCY["JPY"] = "JPY";
34
- CURRENCY["KWD"] = "KWD";
35
- CURRENCY["MYR"] = "MYR";
36
- CURRENCY["OMR"] = "OMR";
37
- CURRENCY["PKR"] = "PKR";
38
- CURRENCY["SAR"] = "SAR";
39
- CURRENCY["USD"] = "USD";
40
- })(CURRENCY || (exports.CURRENCY = CURRENCY = {}));
41
26
  var INVOICE_STATUS;
42
27
  (function (INVOICE_STATUS) {
43
28
  INVOICE_STATUS["UNPAID"] = "UNPAID";
@@ -56,16 +41,3 @@ var DISCOUNT_UNIT;
56
41
  DISCOUNT_UNIT["FIXED_VALUE"] = "FIXED_VALUE";
57
42
  DISCOUNT_UNIT["PERCENTAGE_VALUE"] = "PERCENTAGE_VALUE";
58
43
  })(DISCOUNT_UNIT || (exports.DISCOUNT_UNIT = DISCOUNT_UNIT = {}));
59
- // export interface CustomerTypeBE {
60
- // address?: string;
61
- // city: string;
62
- // country: string;
63
- // createdAt: string;
64
- // email?: string;
65
- // firstName: string;
66
- // id: string;
67
- // invoices?: InvoiceTypeBE[]
68
- // lastName: string;
69
- // phone: string;
70
- // updatedAt: string;
71
- // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/stellar-solutions-invoice-module",
3
- "version": "0.1.51",
3
+ "version": "0.1.53",
4
4
  "scripts": {
5
5
  "build": "yarn clean && yarn build:ts && cp package.json lib && cp README.md lib && cp yarn.lock lib",
6
6
  "build:next": "next build",
@@ -24,7 +24,7 @@
24
24
  "@eslint/eslintrc": "^3",
25
25
  "@headlessui/react": "^2",
26
26
  "@heroicons/react": "^2",
27
- "@react-pakistan/util-functions": "^1.24.41",
27
+ "@react-pakistan/util-functions": "^1.24.46",
28
28
  "@supabase/supabase-js": "^2",
29
29
  "@tailwindcss/forms": "^0.5.10",
30
30
  "@tailwindcss/postcss": "^4",
File without changes
@@ -1,32 +0,0 @@
1
- // /* eslint-disable */
2
- // import React from 'react';
3
- // import { vistaFormSchema } from '@appcorp/app-corp-vista/utils/form-schema';
4
- // import { VistaFormElements } from '@appcorp/app-corp-vista/type/vista-form-elements';
5
- // import { Product } from './types';
6
- // export const renderProductsFormElements = (
7
- // elementProps: VistaFormElements,
8
- // row: Product,
9
- // ) => {
10
- // const elementsArray = Object.entries(vistaFormSchema)
11
- // .flatMap(([key, config]) => {
12
- // const Component = config;
13
- // return (elementProps[key as keyof VistaFormElements] || [])
14
- // ?.filter((props: any) => props.enabled)
15
- // ?.map((props: any) => ({
16
- // Component,
17
- // key,
18
- // order: props.order,
19
- // props,
20
- // }));
21
- // })
22
- // ?.sort((a, b) => a.order - b.order);
23
- // return (
24
- // <div className="grid grid-cols-[17.5%_17.5%_17.5%_17.5%_17.5%_auto] gap-4">
25
- // {elementsArray?.map(({ key, Component, props }, index) => (
26
- // <div key={`${key}-${index}`} className={props.className}>
27
- // <Component {...props} {...row} />
28
- // </div>
29
- // ))}
30
- // </div>
31
- // );
32
- // };
File without changes
@@ -1,38 +0,0 @@
1
- // /* eslint-disable */
2
- // import React from 'react';
3
- // import { vistaFormSchema } from '@appcorp/app-corp-vista/utils/form-schema';
4
- // import { Service } from './types';
5
- // import { VistaFormElements } from '@appcorp/app-corp-vista/type/vista-form-elements';
6
- // export const renderServicesFormElements = (
7
- // elementProps: VistaFormElements,
8
- // row: Service,
9
- // ) => {
10
- // const elementsArray = Object.entries(vistaFormSchema)
11
- // .flatMap(([key, config]) => {
12
- // const Component = config;
13
- // return (elementProps[key as keyof VistaFormElements] || [])
14
- // ?.filter((props: any) => props.enabled)
15
- // ?.map((props: any) => ({
16
- // Component,
17
- // key,
18
- // order: props.order,
19
- // props,
20
- // }));
21
- // })
22
- // ?.sort((a, b) => a.order - b.order);
23
- // return (
24
- // <div className="grid grid-cols-[17.5%_17.5%_17.5%_17.5%_17.5%_auto] gap-4">
25
- // {elementsArray?.map(({ key, Component, props }, index) => {
26
- // // console.log('_>>', props);
27
- // return (
28
- // <div key={`${key}-${index}`} className={props.className}>
29
- // <Component
30
- // {...props}
31
- // {...row}
32
- // value={row[props.id as keyof Service]}
33
- // />
34
- // </div>
35
- // )})}
36
- // </div>
37
- // );
38
- // };