@appcorp/stellar-solutions-invoice-module 0.1.49 → 0.1.50

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,6 +1,7 @@
1
1
  import { ProductTypeBE } from '@appcorp/stellar-solutions-product-module/base-modules/product/types';
2
2
  import { CustomerTypeBE, DISCOUNT_UNIT, INVOICE_DRAWER, InvoiceState, InvoiceTypeBE, Product, Service } from './types';
3
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';
4
5
  export declare enum INVOICE_ACTION_TYPES {
5
6
  ADD_ITEM_PRODUCT = "ADD_ITEM_PRODUCT",
6
7
  ADD_ITEM_SERVICE = "ADD_ITEM_SERVICE",
@@ -29,8 +30,10 @@ export declare enum INVOICE_ACTION_TYPES {
29
30
  SET_SKELTON_LOADING = "SET_SKELTON_LOADING",
30
31
  SET_TAX = "SET_TAX",
31
32
  SET_PRODUCTS_LIST = "SET_PRODUCTS_LIST",
33
+ SET_COMPANIES_LIST = "SET_COMPANIES_LIST",
32
34
  SET_CUSTOMER = "SET_CUSTOMER",
33
- SET_TAXES = "SET_TAXES"
35
+ SET_TAXES = "SET_TAXES",
36
+ SET_CUSTOMER_FORM = "SET_CUSTOMER_FORM"
34
37
  }
35
38
  export type InvoiceUpdateFieldAction = {
36
39
  type: INVOICE_ACTION_TYPES.SET_INPUT_FIELD;
@@ -175,10 +178,24 @@ export type InvoiceSetProductsListAction = {
175
178
  productsList: ProductTypeBE[];
176
179
  };
177
180
  };
181
+ export type InvoiceSetCompaniesListAction = {
182
+ type: INVOICE_ACTION_TYPES.SET_COMPANIES_LIST;
183
+ payload: {
184
+ companiesList: CompanyTypeBE[];
185
+ };
186
+ };
178
187
  export type InvoiceSetCustomerAction = {
179
188
  type: INVOICE_ACTION_TYPES.SET_CUSTOMER;
180
189
  payload: {
181
190
  customer: CustomerTypeBE;
191
+ customerId: string;
192
+ };
193
+ };
194
+ export type InvoiceSetCustomerFormAction = {
195
+ type: INVOICE_ACTION_TYPES.SET_CUSTOMER_FORM;
196
+ payload: {
197
+ key: keyof CustomerTypeBE;
198
+ value: string;
182
199
  };
183
200
  };
184
201
  export type InvoiceSetTaxesAction = {
@@ -187,4 +204,4 @@ export type InvoiceSetTaxesAction = {
187
204
  taxes: TaxTypeBE[];
188
205
  };
189
206
  };
190
- 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;
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;
@@ -30,6 +30,8 @@ var INVOICE_ACTION_TYPES;
30
30
  INVOICE_ACTION_TYPES["SET_SKELTON_LOADING"] = "SET_SKELTON_LOADING";
31
31
  INVOICE_ACTION_TYPES["SET_TAX"] = "SET_TAX";
32
32
  INVOICE_ACTION_TYPES["SET_PRODUCTS_LIST"] = "SET_PRODUCTS_LIST";
33
+ INVOICE_ACTION_TYPES["SET_COMPANIES_LIST"] = "SET_COMPANIES_LIST";
33
34
  INVOICE_ACTION_TYPES["SET_CUSTOMER"] = "SET_CUSTOMER";
34
35
  INVOICE_ACTION_TYPES["SET_TAXES"] = "SET_TAXES";
36
+ INVOICE_ACTION_TYPES["SET_CUSTOMER_FORM"] = "SET_CUSTOMER_FORM";
35
37
  })(INVOICE_ACTION_TYPES || (exports.INVOICE_ACTION_TYPES = INVOICE_ACTION_TYPES = {}));
@@ -25,6 +25,7 @@ export declare const INVOICE_API_ROUTES: {
25
25
  CUSTOMER_BY_PHONE: string;
26
26
  TAXES: string;
27
27
  TAX: string;
28
+ COMPANIES: string;
28
29
  };
29
30
  export declare const tableBodyCols: ({
30
31
  componentType: VISTA_TABLE_CELL_TYPE;
@@ -108,8 +108,8 @@ exports.staticCompanySection = (_a = {},
108
108
  order: 4,
109
109
  query: '',
110
110
  required: true,
111
- selectKey1: 'option',
112
- selectedItem: { option: 'PKR' },
111
+ selectKey1: 'code',
112
+ selectedItem: { code: '' },
113
113
  },
114
114
  // {
115
115
  // enabled: false,
@@ -157,7 +157,7 @@ exports.staticCustomerSection = (_b = {},
157
157
  disabled: false,
158
158
  enabled: true,
159
159
  error: '',
160
- handleOnChange: function () { },
160
+ handleOnChange: function () { return void 0; },
161
161
  id: 'lastName',
162
162
  label: 'Last Name',
163
163
  order: 3,
@@ -170,11 +170,11 @@ exports.staticCustomerSection = (_b = {},
170
170
  disabled: false,
171
171
  enabled: true,
172
172
  error: '',
173
- handleOnChange: function () { },
173
+ handleOnChange: function () { return void 0; },
174
174
  id: 'email',
175
175
  label: 'Email',
176
176
  order: 7,
177
- placeholder: 'xyz@company.com',
177
+ placeholder: 'name@company.com',
178
178
  required: false,
179
179
  type: 'text',
180
180
  value: '',
@@ -183,7 +183,7 @@ exports.staticCustomerSection = (_b = {},
183
183
  disabled: false,
184
184
  enabled: true,
185
185
  error: '',
186
- handleOnChange: function () { },
186
+ handleOnChange: function () { return void 0; },
187
187
  id: 'city',
188
188
  label: 'City',
189
189
  order: 6,
@@ -196,11 +196,11 @@ exports.staticCustomerSection = (_b = {},
196
196
  disabled: false,
197
197
  enabled: true,
198
198
  error: '',
199
- handleOnChange: function () { },
199
+ handleOnChange: function () { return void 0; },
200
200
  id: 'address',
201
201
  label: 'Address',
202
202
  order: 5,
203
- placeholder: 'xyz street .....',
203
+ placeholder: '123 Street',
204
204
  required: false,
205
205
  type: 'text',
206
206
  value: '',
@@ -522,6 +522,7 @@ exports.INVOICE_API_ROUTES = {
522
522
  CUSTOMER_BY_PHONE: '/api/customer/by-phone',
523
523
  TAXES: '/api/taxes',
524
524
  TAX: '/api/tax',
525
+ COMPANIES: '/api/companies'
525
526
  };
526
527
  exports.tableBodyCols = [
527
528
  {
@@ -102,21 +102,20 @@ var types_1 = require("./types");
102
102
  var validate_1 = require("./validate");
103
103
  var generate_toast_1 = require("@appcorp/app-corp-vista/utils/generate-toast");
104
104
  var calculate_subtotal_1 = require("./calculate-subtotal");
105
- var context_1 = require("@appcorp/stellar-solutions-company-module/base-modules/company/context");
106
105
  var date_fns_1 = require("date-fns");
107
106
  var calculate_total_1 = require("./calculate-total");
108
107
  var util_functions_2 = require("@react-pakistan/util-functions");
109
- var context_2 = require("@appcorp/stellar-solutions-modules/global-modules/tax/context");
110
- var context_3 = require("@appcorp/stellar-solutions-modules/global-modules/preferences/context");
108
+ var context_1 = require("@appcorp/stellar-solutions-modules/global-modules/tax/context");
109
+ var context_2 = require("@appcorp/stellar-solutions-modules/global-modules/preferences/context");
111
110
  var useInvoiceState = function () {
112
111
  var _a = (0, react_1.useReducer)(reducer_1.invoiceReducer, reducer_1.initialInvoiceState), state = _a[0], dispatch = _a[1];
113
- var companies = (0, context_1.useCompanyStateContext)().companies;
114
- var taxes = (0, context_2.useTaxStateContext)().taxes;
115
- var currencies = (0, context_3.usePreferenceStateContext)().currencies;
112
+ var taxes = (0, context_1.useTaxStateContext)().taxes;
113
+ var currencies = (0, context_2.usePreferenceStateContext)().currencies;
116
114
  var debouncedQuery = (0, util_functions_1.useDebounce)(state.searchQuery, 800);
117
115
  var debouncedProductList = (0, util_functions_1.useDebounce)(state.productQuery, 800);
118
- var debouncedCustomerList = (0, util_functions_1.useDebounce)(state.phone, 800);
116
+ var debouncedCustomer = (0, util_functions_1.useDebounce)(state.phone, 800);
119
117
  var debouncedTaxList = (0, util_functions_1.useDebounce)(state.taxQuery, 800);
118
+ var debouncedCompanyList = (0, util_functions_1.useDebounce)(state.companyQuery, 800);
120
119
  var defaultTax = (0, react_1.useMemo)(function () {
121
120
  return taxes.filter(function (_a) {
122
121
  var isDefault = _a.isDefault;
@@ -130,7 +129,7 @@ var useInvoiceState = function () {
130
129
  })[0];
131
130
  }, [currencies]);
132
131
  var listParams = {
133
- category: types_1.QUOTE_INVOICE.INVOICE,
132
+ category: types_1.QUOTE_INVOICE_CATEGORY.INVOICE,
134
133
  currentPage: state.currentPage,
135
134
  pageLimit: state.pageLimit,
136
135
  searchQuery: state.searchQuery,
@@ -158,12 +157,6 @@ var useInvoiceState = function () {
158
157
  category: state.category,
159
158
  companyId: state.companyId,
160
159
  currency: state.currency,
161
- city: state.city,
162
- country: state.country,
163
- firstName: state.firstName,
164
- lastName: state.lastName,
165
- address: state.address,
166
- phone: state.phone,
167
160
  customerId: state.customerId,
168
161
  date: state.date,
169
162
  discount: state.discount.trim(),
@@ -173,6 +166,7 @@ var useInvoiceState = function () {
173
166
  invoiceStatus: state.invoiceStatus,
174
167
  mode: state.mode,
175
168
  note: state.note.trim(),
169
+ phone: state.phone,
176
170
  products: state.products,
177
171
  quoteStatus: state.quoteStatus,
178
172
  ref: state.ref,
@@ -211,7 +205,7 @@ var useInvoiceState = function () {
211
205
  id: state.id,
212
206
  };
213
207
  var byIdCallback = function (_a) {
214
- var _b, _c;
208
+ var _b, _c, _d, _e, _f, _g, _h;
215
209
  var data = _a.data, error = _a.error;
216
210
  if (error) {
217
211
  (0, generate_toast_1.generateToast)({
@@ -225,27 +219,37 @@ var useInvoiceState = function () {
225
219
  return (__assign(__assign({}, item), { rowTotal: Number(item.quantity) * Number(item.price) }));
226
220
  });
227
221
  var updatedProducts = __spreadArray([], data.products, true).map(function (item) { return (__assign(__assign({}, item), { price: item.product.salePrice, id: item.productId, quantity: item.quantity, rowTotal: parseFloat(item.product.salePrice) * parseInt(item.quantity) })); });
228
- var updatedData = __assign(__assign({}, data), { mode: 'Edit', companyId: data.company.id, services: __spreadArray([], updatedServices, true).filter(function (item) { return item.name; }), products: __spreadArray([], updatedProducts, true).filter(function (item) { return item.id; }) });
229
- if ((_b = updatedData === null || updatedData === void 0 ? void 0 : updatedData.company) === null || _b === void 0 ? void 0 : _b.name) {
222
+ var updatedData = __assign(__assign(__assign(__assign({}, data), { mode: 'Edit', companyId: ((_b = data === null || data === void 0 ? void 0 : data.company) === null || _b === void 0 ? void 0 : _b.id) || '', customerId: ((_c = data === null || data === void 0 ? void 0 : data.customer) === null || _c === void 0 ? void 0 : _c.id) || '' }), (((_d = data === null || data === void 0 ? void 0 : data.customer) === null || _d === void 0 ? void 0 : _d.id) && {
223
+ customer: __assign({}, data.customer),
224
+ })), { services: __spreadArray([], updatedServices, true).filter(function (item) { return item.name; }), products: __spreadArray([], updatedProducts, true).filter(function (item) { return item.id; }) });
225
+ if ((_e = updatedData === null || updatedData === void 0 ? void 0 : updatedData.company) === null || _e === void 0 ? void 0 : _e.name) {
230
226
  dispatch({
231
- type: actions_1.INVOICE_ACTION_TYPES.SET_FORM_TO_RENDER,
232
- payload: { formToRender: 'company' },
227
+ type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
228
+ payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_COMPANY_FORM_DRAWER },
233
229
  });
234
230
  }
235
- if ((_c = updatedData === null || updatedData === void 0 ? void 0 : updatedData.customer) === null || _c === void 0 ? void 0 : _c.name) {
231
+ if ((_f = updatedData === null || updatedData === void 0 ? void 0 : updatedData.customer) === null || _f === void 0 ? void 0 : _f.firstName) {
236
232
  dispatch({
237
- type: actions_1.INVOICE_ACTION_TYPES.SET_FORM_TO_RENDER,
238
- payload: { formToRender: 'customer' },
233
+ type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
234
+ payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER },
239
235
  });
240
236
  }
241
237
  dispatch({
242
238
  type: actions_1.INVOICE_ACTION_TYPES.SET_FORM,
243
239
  payload: { form: updatedData },
244
240
  });
245
- dispatch({
246
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
247
- payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_COMPANY_FORM_DRAWER },
248
- });
241
+ if ((_g = updatedData === null || updatedData === void 0 ? void 0 : updatedData.company) === null || _g === void 0 ? void 0 : _g.name) {
242
+ dispatch({
243
+ type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
244
+ payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_COMPANY_FORM_DRAWER },
245
+ });
246
+ }
247
+ if ((_h = updatedData === null || updatedData === void 0 ? void 0 : updatedData.customer) === null || _h === void 0 ? void 0 : _h.firstName) {
248
+ dispatch({
249
+ type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
250
+ payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER },
251
+ });
252
+ }
249
253
  }
250
254
  };
251
255
  var deleteParams = {
@@ -321,7 +325,7 @@ var useInvoiceState = function () {
321
325
  }); })();
322
326
  }, [debouncedProductList]);
323
327
  (0, react_1.useEffect)(function () {
324
- if (state.drawer === types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER && debouncedCustomerList) {
328
+ if (state.drawer === types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER && debouncedCustomer) {
325
329
  (function () { return __awaiter(void 0, void 0, void 0, function () {
326
330
  var data;
327
331
  return __generator(this, function (_a) {
@@ -330,7 +334,7 @@ var useInvoiceState = function () {
330
334
  url: constants_1.INVOICE_API_ROUTES.CUSTOMER_BY_PHONE,
331
335
  method: util_functions_1.API_METHODS.POST,
332
336
  body: JSON.stringify({
333
- phone: debouncedCustomerList,
337
+ phone: debouncedCustomer,
334
338
  }),
335
339
  })];
336
340
  case 1:
@@ -338,7 +342,7 @@ var useInvoiceState = function () {
338
342
  if (data) {
339
343
  dispatch({
340
344
  type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER,
341
- payload: { customer: __assign(__assign({}, data), { customerId: data.id }) },
345
+ payload: { customer: __assign({}, data), customerId: data.id },
342
346
  });
343
347
  }
344
348
  return [2 /*return*/];
@@ -346,13 +350,36 @@ var useInvoiceState = function () {
346
350
  });
347
351
  }); })();
348
352
  }
349
- else {
350
- dispatch({
351
- type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER,
352
- payload: { customer: { phone: '', firstName: '', lastName: '', email: '', address: '', city: '', country: '', createdAt: '', updatedAt: '', id: '', invoices: [] } },
353
- });
353
+ }, [debouncedCustomer, state.drawer]);
354
+ (0, react_1.useEffect)(function () {
355
+ if (state.drawer === types_1.INVOICE_DRAWER.INVOICE_COMPANY_FORM_DRAWER && debouncedCompanyList) {
356
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
357
+ var data;
358
+ return __generator(this, function (_a) {
359
+ switch (_a.label) {
360
+ case 0: return [4 /*yield*/, (0, util_functions_1.fetchData)({
361
+ url: constants_1.INVOICE_API_ROUTES.COMPANIES,
362
+ method: util_functions_1.API_METHODS.POST,
363
+ body: JSON.stringify({
364
+ searchQuery: debouncedCompanyList,
365
+ pageLimit: 100,
366
+ currentPage: 1,
367
+ }),
368
+ })];
369
+ case 1:
370
+ data = (_a.sent()).data;
371
+ if (data === null || data === void 0 ? void 0 : data.items) {
372
+ dispatch({
373
+ type: actions_1.INVOICE_ACTION_TYPES.SET_COMPANIES_LIST,
374
+ payload: { companiesList: data.items },
375
+ });
376
+ }
377
+ return [2 /*return*/];
378
+ }
379
+ });
380
+ }); })();
354
381
  }
355
- }, [debouncedCustomerList, state.formToRender, state.drawer]);
382
+ }, [debouncedCompanyList, state.drawer]);
356
383
  (0, react_1.useEffect)(function () {
357
384
  (function () { return __awaiter(void 0, void 0, void 0, function () {
358
385
  var data;
@@ -483,8 +510,24 @@ var useInvoiceState = function () {
483
510
  });
484
511
  }, [updateFetchNow, updateParams, defaultCurrency, defaultTax]);
485
512
  var handleChange = (0, react_1.useCallback)(function (key, value) {
513
+ var _a;
514
+ if (key === 'phone') {
515
+ var formattedNumber = (_a = (0, util_functions_1.formatPhone)(value)) === null || _a === void 0 ? void 0 : _a.international;
516
+ dispatch({
517
+ type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER_FORM,
518
+ payload: { key: key, value: formattedNumber || value },
519
+ });
520
+ return;
521
+ }
522
+ if (key === 'companyQuery') {
523
+ dispatch({
524
+ type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
525
+ payload: { key: key, value: value },
526
+ });
527
+ return;
528
+ }
486
529
  dispatch({
487
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
530
+ type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER_FORM,
488
531
  payload: { key: key, value: String(value) },
489
532
  });
490
533
  dispatch({
@@ -598,7 +641,7 @@ var useInvoiceState = function () {
598
641
  }
599
642
  if (key === 'country') {
600
643
  dispatch({
601
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
644
+ type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER_FORM,
602
645
  payload: {
603
646
  key: key,
604
647
  value: val.name,
@@ -686,31 +729,34 @@ var useInvoiceState = function () {
686
729
  var comboboxElements = (_b = elements[form_schema_1.VISTA_FORM_ELEMENTS.COMBOBOX_V1]) === null || _b === void 0 ? void 0 : _b.sort(function (a, b) { return a.order - b.order; });
687
730
  if (comboboxElements) {
688
731
  comboboxElements[0].selectedItem = { id: state.companyId };
689
- comboboxElements[0].listItems = companies;
732
+ comboboxElements[0].listItems = state.companiesList;
690
733
  comboboxElements[0].query = state.companyQuery;
691
734
  comboboxElements[0].handleOnChange = handleSelectChange;
692
735
  comboboxElements[0].handleInputOnChange = handleChange;
693
736
  comboboxElements[0].handleOnBlur = handleChange;
694
- comboboxElements[1].selectedItem = { option: state.currency };
695
- comboboxElements[1].listItems = [];
737
+ comboboxElements[1].selectedItem = { code: state.currency || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.code) };
738
+ comboboxElements[1].listItems = currencies;
739
+ comboboxElements[1].handleOnChange = handleSelectChange;
740
+ comboboxElements[1].handleInputOnChange = handleChange;
696
741
  }
697
742
  return elements;
698
- }, [state, handleChange, companies]);
743
+ }, [state, handleChange, currencies, defaultCurrency]);
699
744
  var dynamicCustomerFormElements = (0, react_1.useMemo)(function () {
700
- var _a, _b;
745
+ var _a, _b, _c;
701
746
  var elements = __assign({}, constants_1.staticCustomerSection);
702
747
  var textInputElements = (_a = elements[form_schema_1.VISTA_FORM_ELEMENTS.TEXT_INPUT_V1]) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) { return a.order - b.order; });
703
748
  if (textInputElements) {
704
749
  textInputElements.forEach(function (_a, i) {
750
+ var _b;
705
751
  var id = _a.id;
706
752
  textInputElements[i].error = state.errors[id];
707
753
  textInputElements[i].handleOnChange = handleChange;
708
- textInputElements[i].value = state[id];
754
+ textInputElements[i].value = (_b = state === null || state === void 0 ? void 0 : state.customer) === null || _b === void 0 ? void 0 : _b[id];
709
755
  });
710
756
  }
711
757
  var comboboxElements = (_b = elements[form_schema_1.VISTA_FORM_ELEMENTS.COMBOBOX_V1]) === null || _b === void 0 ? void 0 : _b.sort(function (a, b) { return a.order - b.order; });
712
758
  if (comboboxElements) {
713
- comboboxElements[0].selectedItem = { name: state.country };
759
+ comboboxElements[0].selectedItem = { name: (_c = state === null || state === void 0 ? void 0 : state.customer) === null || _c === void 0 ? void 0 : _c.country };
714
760
  comboboxElements[0].listItems = util_functions_2.countriesTimeZones;
715
761
  comboboxElements[0].query = state.countryQuery;
716
762
  comboboxElements[0].handleOnChange = handleSelectChange;
@@ -803,9 +849,9 @@ var useInvoiceState = function () {
803
849
  order: 2,
804
850
  },
805
851
  ];
806
- return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, dynamicCompanyFormElements: dynamicCompanyFormElements, dynamicPricingFormElements: dynamicPricingFormElements, dynamicCustomerFormElements: dynamicCustomerFormElements, handleChange: handleChange, handleNextClick: handleNextClick, handlePageLimit: handlePageLimit, handlePreviousClick: handlePreviousClick, handleSubmit: handleSubmit, headerActions: headerActions, listError: listError, listFetchNow: listFetchNow, listLoading: listLoading, rowActions: rowActions, searchOnChange: searchOnChange, updateError: updateError, updateLoading: updateLoading, handleAddItemService: handleAddItemService, handleAddItemProduct: handleAddItemProduct, handleItemChangeServices: handleItemChangeServices, handleDeleteServiceRow: handleDeleteServiceRow, handleItemChangeProducts: handleItemChangeProducts, handleDeleteProductRow: handleDeleteProductRow });
852
+ return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, dynamicCompanyFormElements: dynamicCompanyFormElements, dynamicCustomerFormElements: dynamicCustomerFormElements, dynamicPricingFormElements: dynamicPricingFormElements, 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 });
807
853
  };
808
- 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; }, dynamicCompanyFormElements: {}, dynamicPricingFormElements: {}, dynamicCustomerFormElements: {}, handleChange: 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, handleAddItemService: function () { return void 0; }, handleAddItemProduct: function () { return void 0; }, handleItemChangeServices: function () { return void 0; }, handleDeleteServiceRow: function () { return void 0; }, handleItemChangeProducts: function () { return void 0; }, handleDeleteProductRow: function () { return void 0; } }));
854
+ 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; }, dynamicCompanyFormElements: {}, dynamicCustomerFormElements: {}, dynamicPricingFormElements: {}, 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 }));
809
855
  var InvoiceStateContextProvider = function (_a) {
810
856
  var children = _a.children;
811
857
  var state = useInvoiceState();
@@ -71,7 +71,7 @@ var InvoicePage = function () {
71
71
  ];
72
72
  var totalPagePerRecord = (0, util_functions_1.calculatePages)(count, pageLimit);
73
73
  return (react_1.default.createElement(react_1.default.Fragment, null,
74
- react_1.default.createElement(vista_table_v1_1.VistaTableV1, { currentPage: currentPage, handleNextOnClick: handleNextClick, handleOnSelect: handlePageLimit, handlePreviousOnClick: handlePreviousClick, handleSearchInput: searchOnChange, headerActions: headerActions, isNextDisabled: (0, util_functions_1.isNextButtonDisabled)(currentPage, totalPagePerRecord), isPreviousDisabled: (0, util_functions_1.isPreviousButtonDisabled)(currentPage), listOptions: (0, util_functions_1.getAvailablePageLimits)(count), loading: listLoading, nodeSelectKey: "pageLimit", pageLimit: pageLimit, rowActions: rowActions, searchDisabled: false, searchEnabled: true, searchId: "inventory-search", searchPlaceholder: "Enter ID or Name...", searchValue: searchQuery, selectKey1: "option", selectedItem: { option: String(pageLimit) }, tableBodyCols: constants_1.tableBodyCols, tableBodyRows: invoices, tableDescription: t('subTitle'), tableHeadItems: tableHeadItems, tableHeading: t('title'), totalPages: totalPagePerRecord }),
74
+ react_1.default.createElement(vista_table_v1_1.VistaTableV1, { currentPage: currentPage, handleNextOnClick: handleNextClick, handleOnSelect: handlePageLimit, handlePreviousOnClick: handlePreviousClick, handleSearchInput: searchOnChange, headerActions: headerActions, isNextDisabled: (0, util_functions_1.isNextButtonDisabled)(currentPage, totalPagePerRecord), isPreviousDisabled: (0, util_functions_1.isPreviousButtonDisabled)(currentPage), listOptions: (0, util_functions_1.getAvailablePageLimits)(count), loading: listLoading, nodeSelectKey: "pageLimit", pageLimit: pageLimit, rowActions: rowActions, searchDisabled: false, searchEnabled: true, searchId: "invoice-search", searchPlaceholder: "Enter ID or Name...", searchValue: searchQuery, selectKey1: "option", selectedItem: { option: String(pageLimit) }, tableBodyCols: constants_1.tableBodyCols, tableBodyRows: invoices, tableDescription: t('subTitle'), tableHeadItems: tableHeadItems, tableHeading: t('title'), totalPages: totalPagePerRecord }),
75
75
  react_1.default.createElement(drawer_1.Drawer, { translationMap: translationMap }),
76
76
  react_1.default.createElement(generate_toast_1.VistaToaster, null)));
77
77
  };
@@ -27,16 +27,25 @@ var types_1 = require("./types");
27
27
  var constants_1 = require("./constants");
28
28
  var date_fns_1 = require("date-fns");
29
29
  exports.initialInvoiceState = {
30
- address: '',
31
30
  afterDiscount: '0',
32
- category: types_1.QUOTE_INVOICE.INVOICE,
33
- city: '',
31
+ category: types_1.QUOTE_INVOICE_CATEGORY.INVOICE,
34
32
  companyId: '',
35
33
  companyQuery: '',
36
34
  count: 0,
37
- country: '',
38
35
  countryQuery: '',
39
36
  currency: '',
37
+ customer: {
38
+ address: '',
39
+ city: '',
40
+ country: '',
41
+ createdAt: '',
42
+ email: '',
43
+ firstName: '',
44
+ id: '',
45
+ lastName: '',
46
+ phone: '',
47
+ updatedAt: '',
48
+ },
40
49
  contactsList: [],
41
50
  currentPage: 1,
42
51
  customerId: '',
@@ -45,15 +54,11 @@ exports.initialInvoiceState = {
45
54
  discount: '0',
46
55
  discountUnit: types_1.DISCOUNT_UNIT.FIXED_VALUE,
47
56
  drawer: null,
48
- email: '',
49
57
  errors: {},
50
58
  expiryDate: (0, date_fns_1.addDays)(new Date(), 7).toISOString(),
51
- firstName: '',
52
- formToRender: '',
53
59
  id: '',
54
60
  invoiceStatus: types_1.INVOICE_STATUS.UNPAID,
55
61
  invoices: [],
56
- lastName: '',
57
62
  loading: true,
58
63
  modal: null,
59
64
  mode: 'Create',
@@ -63,6 +68,7 @@ exports.initialInvoiceState = {
63
68
  payments: [],
64
69
  phone: '',
65
70
  productsList: [],
71
+ companiesList: [],
66
72
  productQuery: '',
67
73
  quoteStatus: types_1.QUOTE_STATUS.DRAFT,
68
74
  ref: '',
@@ -104,7 +110,7 @@ exports.initialInvoiceState = {
104
110
  ],
105
111
  };
106
112
  function invoiceReducer(state, action) {
107
- var _a;
113
+ var _a, _b;
108
114
  switch (action.type) {
109
115
  case actions_1.INVOICE_ACTION_TYPES.SET_DRAWER:
110
116
  return __assign(__assign({}, state), { drawer: action.payload.drawer });
@@ -122,11 +128,6 @@ function invoiceReducer(state, action) {
122
128
  return __assign(__assign({}, state), { disableSaveButton: false, errors: __assign({}, action.payload.errors) });
123
129
  case actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD:
124
130
  return __assign(__assign({}, state), (_a = {}, _a[action.payload.key] = action.payload.value, _a));
125
- // case INVOICE_ACTION_TYPES.SET_INPUT_IMAGES:
126
- // return {
127
- // ...state,
128
- // [action.payload.key]: [...action.payload.value],
129
- // };
130
131
  case actions_1.INVOICE_ACTION_TYPES.SET_PAGE_LIMIT:
131
132
  return __assign(__assign({}, state), { pageLimit: action.payload.pageLimit });
132
133
  case actions_1.INVOICE_ACTION_TYPES.SET_INVOICES:
@@ -156,14 +157,18 @@ function invoiceReducer(state, action) {
156
157
  return __assign(__assign({}, state), { services: __spreadArray([], action.payload.services, true) });
157
158
  case actions_1.INVOICE_ACTION_TYPES.DELETE_ITEM_PRODUCT:
158
159
  return __assign(__assign({}, state), { products: __spreadArray([], action.payload.products, true) });
159
- case actions_1.INVOICE_ACTION_TYPES.SET_FORM_TO_RENDER:
160
- return __assign(__assign({}, state), { formToRender: action.payload.formToRender });
161
160
  case actions_1.INVOICE_ACTION_TYPES.SET_PRODUCTS_LIST:
162
161
  return __assign(__assign({}, state), { productsList: __spreadArray([], action.payload.productsList, true) });
163
162
  case actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER:
164
- return __assign(__assign({}, state), action.payload.customer);
163
+ return __assign(__assign({}, state), { customerId: state.customerId, customer: __assign(__assign({}, state.customer), action.payload.customer) });
164
+ case actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER_FORM:
165
+ return __assign(__assign({}, state), (state.customer && ({
166
+ customer: __assign(__assign({}, state.customer), (_b = {}, _b[action.payload.key] = action.payload.value, _b)),
167
+ })));
165
168
  case actions_1.INVOICE_ACTION_TYPES.SET_TAXES:
166
169
  return __assign(__assign({}, state), { taxes: __spreadArray([], action.payload.taxes, true) });
170
+ case actions_1.INVOICE_ACTION_TYPES.SET_COMPANIES_LIST:
171
+ return __assign(__assign({}, state), { companiesList: __spreadArray([], action.payload.companiesList, true) });
167
172
  default:
168
173
  return state;
169
174
  }
@@ -70,7 +70,7 @@ export interface CustomerTypeBE {
70
70
  email?: string;
71
71
  firstName: string;
72
72
  id: string;
73
- invoices: InvoiceTypeBE[];
73
+ invoices?: InvoiceTypeBE[];
74
74
  lastName: string;
75
75
  phone: string;
76
76
  updatedAt: string;
@@ -96,13 +96,13 @@ export interface PaymentTypeBE {
96
96
  updatedAt: string;
97
97
  }
98
98
  export interface InvoiceTypeBE {
99
- category: QUOTE_INVOICE;
100
- company: CompanyTypeBE;
101
- companyId: string;
99
+ category: QUOTE_INVOICE_CATEGORY;
100
+ company?: CompanyTypeBE;
101
+ companyId?: string;
102
102
  createdAt: string;
103
103
  currency: string;
104
104
  customer?: CustomerTypeBE;
105
- customerId: string;
105
+ customerId?: string;
106
106
  date: string;
107
107
  discount: string;
108
108
  discountUnit: DISCOUNT_UNIT;
@@ -110,7 +110,7 @@ export interface InvoiceTypeBE {
110
110
  id: string;
111
111
  invoiceStatus: INVOICE_STATUS;
112
112
  note: string;
113
- payments: PaymentTypeBE[] | [];
113
+ payments: PaymentTypeBE[];
114
114
  products: Product[];
115
115
  quoteStatus: QUOTE_STATUS;
116
116
  ref: string;
@@ -121,25 +121,20 @@ export interface InvoiceTypeBE {
121
121
  updatedAt: string;
122
122
  }
123
123
  export interface InvoiceState extends Omit<InvoiceTypeBE, 'createdAt' | 'updatedAt'> {
124
- address: string;
125
124
  afterDiscount: string;
126
- city: string;
127
125
  companyQuery: string;
128
126
  contactsList: ContactTypeBE[];
129
127
  count: number;
130
- country: string;
131
128
  countryQuery: string;
132
129
  currentPage: number;
130
+ customer?: CustomerTypeBE;
131
+ customerId?: string;
133
132
  disableSaveButton: boolean;
134
133
  drawer: null | INVOICE_DRAWER;
135
- email: string;
136
134
  errors: {
137
135
  [key: string]: string;
138
136
  };
139
- firstName: string;
140
- formToRender: string;
141
137
  invoices: InvoiceTypeBE[];
142
- lastName: string;
143
138
  loading: boolean;
144
139
  modal: null | PRODUCT_MODAL;
145
140
  mode: 'Create' | 'Edit';
@@ -149,6 +144,7 @@ export interface InvoiceState extends Omit<InvoiceTypeBE, 'createdAt' | 'updated
149
144
  productQuery: string;
150
145
  products: Product[];
151
146
  productsList: ProductTypeBE[];
147
+ companiesList: CompanyTypeBE[];
152
148
  searchQuery: string;
153
149
  tax: string;
154
150
  taxQuery: string;
@@ -166,7 +162,7 @@ export declare enum INVOICE_DRAWER {
166
162
  export declare enum PRODUCT_MODAL {
167
163
  DUMMY = "DUMMY"
168
164
  }
169
- export declare enum QUOTE_INVOICE {
165
+ export declare enum QUOTE_INVOICE_CATEGORY {
170
166
  QUOTE = "QUOTE",
171
167
  INVOICE = "INVOICE"
172
168
  }
@@ -201,16 +197,3 @@ export declare enum DISCOUNT_UNIT {
201
197
  FIXED_VALUE = "FIXED_VALUE",
202
198
  PERCENTAGE_VALUE = "PERCENTAGE_VALUE"
203
199
  }
204
- export interface CustomerTypeBE {
205
- address?: string;
206
- city: string;
207
- country: string;
208
- createdAt: string;
209
- email?: string;
210
- firstName: string;
211
- id: string;
212
- invoices: InvoiceTypeBE[];
213
- lastName: string;
214
- phone: string;
215
- updatedAt: string;
216
- }
@@ -1,6 +1,6 @@
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 = 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.CURRENCY = exports.QUOTE_INVOICE_CATEGORY = exports.PRODUCT_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 = {}));
@@ -16,11 +16,11 @@ var PRODUCT_MODAL;
16
16
  (function (PRODUCT_MODAL) {
17
17
  PRODUCT_MODAL["DUMMY"] = "DUMMY";
18
18
  })(PRODUCT_MODAL || (exports.PRODUCT_MODAL = PRODUCT_MODAL = {}));
19
- var QUOTE_INVOICE;
20
- (function (QUOTE_INVOICE) {
21
- QUOTE_INVOICE["QUOTE"] = "QUOTE";
22
- QUOTE_INVOICE["INVOICE"] = "INVOICE";
23
- })(QUOTE_INVOICE || (exports.QUOTE_INVOICE = QUOTE_INVOICE = {}));
19
+ var QUOTE_INVOICE_CATEGORY;
20
+ (function (QUOTE_INVOICE_CATEGORY) {
21
+ QUOTE_INVOICE_CATEGORY["QUOTE"] = "QUOTE";
22
+ QUOTE_INVOICE_CATEGORY["INVOICE"] = "INVOICE";
23
+ })(QUOTE_INVOICE_CATEGORY || (exports.QUOTE_INVOICE_CATEGORY = QUOTE_INVOICE_CATEGORY = {}));
24
24
  var CURRENCY;
25
25
  (function (CURRENCY) {
26
26
  CURRENCY["AUD"] = "AUD";
@@ -56,3 +56,16 @@ var DISCOUNT_UNIT;
56
56
  DISCOUNT_UNIT["FIXED_VALUE"] = "FIXED_VALUE";
57
57
  DISCOUNT_UNIT["PERCENTAGE_VALUE"] = "PERCENTAGE_VALUE";
58
58
  })(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.49",
3
+ "version": "0.1.50",
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",
@@ -18,13 +18,13 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@appcorp/app-corp-vista": "^0.2.99",
21
- "@appcorp/stellar-solutions-company-module": "^0.1.29",
22
- "@appcorp/stellar-solutions-modules": "^0.1.28",
23
- "@appcorp/stellar-solutions-product-module": "^0.2.5",
21
+ "@appcorp/stellar-solutions-company-module": "^0.1.30",
22
+ "@appcorp/stellar-solutions-modules": "^0.1.29",
23
+ "@appcorp/stellar-solutions-product-module": "^0.2.6",
24
24
  "@eslint/eslintrc": "^3",
25
25
  "@headlessui/react": "^2",
26
26
  "@heroicons/react": "^2",
27
- "@react-pakistan/util-functions": "^1.24.39",
27
+ "@react-pakistan/util-functions": "^1.24.41",
28
28
  "@supabase/supabase-js": "^2",
29
29
  "@tailwindcss/forms": "^0.5.10",
30
30
  "@tailwindcss/postcss": "^4",
@@ -37,6 +37,7 @@
37
37
  "eslint": "^9",
38
38
  "eslint-config-next": "^15",
39
39
  "husky": "^9",
40
+ "libphonenumber-js": "^1",
40
41
  "next": "^15",
41
42
  "next-intl": "^4",
42
43
  "react": "^19",