@appcorp/stellar-solutions-invoice-module 0.1.47 → 0.1.48

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,4 +1,6 @@
1
- import { DISCOUNT_UNIT, INVOICE_DRAWER, InvoiceState, InvoiceTypeBE, Product, Service } from './types';
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';
3
+ import { TaxTypeBE } from '@appcorp/stellar-solutions-modules/global-modules/preferences/types';
2
4
  export declare enum INVOICE_ACTION_TYPES {
3
5
  ADD_ITEM_PRODUCT = "ADD_ITEM_PRODUCT",
4
6
  ADD_ITEM_SERVICE = "ADD_ITEM_SERVICE",
@@ -25,7 +27,10 @@ export declare enum INVOICE_ACTION_TYPES {
25
27
  SET_PAGE_LIMIT = "SET_PAGE_LIMIT",
26
28
  SET_SEARCH_QUERY = "SET_SEARCH_QUERY",
27
29
  SET_SKELTON_LOADING = "SET_SKELTON_LOADING",
28
- SET_TAX = "SET_TAX"
30
+ SET_TAX = "SET_TAX",
31
+ SET_PRODUCTS_LIST = "SET_PRODUCTS_LIST",
32
+ SET_CUSTOMER = "SET_CUSTOMER",
33
+ SET_TAXES = "SET_TAXES"
29
34
  }
30
35
  export type InvoiceUpdateFieldAction = {
31
36
  type: INVOICE_ACTION_TYPES.SET_INPUT_FIELD;
@@ -164,4 +169,22 @@ export type InvoiceSetFormToRenderAction = {
164
169
  formToRender: string;
165
170
  };
166
171
  };
167
- 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;
172
+ export type InvoiceSetProductsListAction = {
173
+ type: INVOICE_ACTION_TYPES.SET_PRODUCTS_LIST;
174
+ payload: {
175
+ productsList: ProductTypeBE[];
176
+ };
177
+ };
178
+ export type InvoiceSetCustomerAction = {
179
+ type: INVOICE_ACTION_TYPES.SET_CUSTOMER;
180
+ payload: {
181
+ customer: CustomerTypeBE;
182
+ };
183
+ };
184
+ export type InvoiceSetTaxesAction = {
185
+ type: INVOICE_ACTION_TYPES.SET_TAXES;
186
+ payload: {
187
+ taxes: TaxTypeBE[];
188
+ };
189
+ };
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;
@@ -29,4 +29,7 @@ var INVOICE_ACTION_TYPES;
29
29
  INVOICE_ACTION_TYPES["SET_SEARCH_QUERY"] = "SET_SEARCH_QUERY";
30
30
  INVOICE_ACTION_TYPES["SET_SKELTON_LOADING"] = "SET_SKELTON_LOADING";
31
31
  INVOICE_ACTION_TYPES["SET_TAX"] = "SET_TAX";
32
+ INVOICE_ACTION_TYPES["SET_PRODUCTS_LIST"] = "SET_PRODUCTS_LIST";
33
+ INVOICE_ACTION_TYPES["SET_CUSTOMER"] = "SET_CUSTOMER";
34
+ INVOICE_ACTION_TYPES["SET_TAXES"] = "SET_TAXES";
32
35
  })(INVOICE_ACTION_TYPES || (exports.INVOICE_ACTION_TYPES = INVOICE_ACTION_TYPES = {}));
@@ -20,6 +20,11 @@ export declare const INVOICE_API_ROUTES: {
20
20
  INVOICES: string;
21
21
  INVOICE: string;
22
22
  INVOICE_BY_ID: string;
23
+ PRODUCTS: string;
24
+ CONTACTS: string;
25
+ CUSTOMER_BY_PHONE: string;
26
+ TAXES: string;
27
+ TAX: string;
23
28
  };
24
29
  export declare const tableBodyCols: ({
25
30
  componentType: VISTA_TABLE_CELL_TYPE;
@@ -128,6 +128,7 @@ exports.staticCompanySection = (_a = {},
128
128
  exports.staticCustomerSection = (_b = {},
129
129
  _b[form_schema_1.VISTA_FORM_ELEMENTS.TEXT_INPUT_V1] = [
130
130
  {
131
+ className: 'col-span-2',
131
132
  disabled: false,
132
133
  enabled: true,
133
134
  error: '',
@@ -135,10 +136,10 @@ exports.staticCustomerSection = (_b = {},
135
136
  id: 'phone',
136
137
  label: 'Phone',
137
138
  order: 1,
138
- placeholder: '03** - *****',
139
+ placeholder: '03** *****',
139
140
  required: true,
140
141
  type: 'text',
141
- value: '',
142
+ value: ''
142
143
  },
143
144
  {
144
145
  disabled: false,
@@ -147,7 +148,7 @@ exports.staticCustomerSection = (_b = {},
147
148
  handleOnChange: function () { return void 0; },
148
149
  id: 'firstName',
149
150
  label: 'First Name',
150
- order: 3,
151
+ order: 2,
151
152
  placeholder: 'John',
152
153
  required: true,
153
154
  type: 'text',
@@ -160,7 +161,7 @@ exports.staticCustomerSection = (_b = {},
160
161
  handleOnChange: function () { },
161
162
  id: 'lastName',
162
163
  label: 'Last Name',
163
- order: 4,
164
+ order: 3,
164
165
  placeholder: 'Doe',
165
166
  required: true,
166
167
  type: 'text',
@@ -173,7 +174,7 @@ exports.staticCustomerSection = (_b = {},
173
174
  handleOnChange: function () { },
174
175
  id: 'email',
175
176
  label: 'Email',
176
- order: 2,
177
+ order: 7,
177
178
  placeholder: 'xyz@company.com',
178
179
  required: false,
179
180
  type: 'text',
@@ -301,8 +302,8 @@ exports.staticPricingSection = (_c = {},
301
302
  handleOnChange: function () { return void 0; },
302
303
  label: 'Tax',
303
304
  listItems: [],
304
- nodeQueryKey: '',
305
- nodeSelectKey: 'taxValue',
305
+ nodeQueryKey: 'taxQuery',
306
+ nodeSelectKey: 'taxRate',
306
307
  order: 5,
307
308
  query: '',
308
309
  required: false,
@@ -501,6 +502,11 @@ exports.INVOICE_API_ROUTES = {
501
502
  INVOICES: '/api/quotes-invoices',
502
503
  INVOICE: '/api/quote-invoice',
503
504
  INVOICE_BY_ID: '/api/quote-invoice/quote-invoice-by-id',
505
+ PRODUCTS: '/api/products',
506
+ CONTACTS: '/api/contacts',
507
+ CUSTOMER_BY_PHONE: '/api/customer/by-phone',
508
+ TAXES: '/api/taxes',
509
+ TAX: '/api/tax',
504
510
  };
505
511
  exports.tableBodyCols = [
506
512
  {
@@ -44,6 +44,42 @@ var __importStar = (this && this.__importStar) || (function () {
44
44
  return result;
45
45
  };
46
46
  })();
47
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
48
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
49
+ return new (P || (P = Promise))(function (resolve, reject) {
50
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
51
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
52
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
53
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
54
+ });
55
+ };
56
+ var __generator = (this && this.__generator) || function (thisArg, body) {
57
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
58
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
59
+ function verb(n) { return function (v) { return step([n, v]); }; }
60
+ function step(op) {
61
+ if (f) throw new TypeError("Generator is already executing.");
62
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
63
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
64
+ if (y = 0, t) op = [op[0] & 2, t.value];
65
+ switch (op[0]) {
66
+ case 0: case 1: t = op; break;
67
+ case 4: _.label++; return { value: op[1], done: false };
68
+ case 5: _.label++; y = op[1]; op = [0]; continue;
69
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
70
+ default:
71
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
72
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
73
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
74
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
75
+ if (t[2]) _.ops.pop();
76
+ _.trys.pop(); continue;
77
+ }
78
+ op = body.call(thisArg, _);
79
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
80
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
81
+ }
82
+ };
47
83
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
48
84
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
49
85
  if (ar || !(i in from)) {
@@ -66,16 +102,25 @@ var types_1 = require("./types");
66
102
  var validate_1 = require("./validate");
67
103
  var generate_toast_1 = require("@appcorp/app-corp-vista/utils/generate-toast");
68
104
  var calculate_subtotal_1 = require("./calculate-subtotal");
69
- var context_1 = require("@appcorp/stellar-solutions-product-module/base-modules/product/context");
70
- var context_2 = require("@appcorp/stellar-solutions-company-module/base-modules/company/context");
105
+ var context_1 = require("@appcorp/stellar-solutions-company-module/base-modules/company/context");
71
106
  var date_fns_1 = require("date-fns");
72
107
  var calculate_total_1 = require("./calculate-total");
73
108
  var util_functions_2 = require("@react-pakistan/util-functions");
109
+ var context_2 = require("@appcorp/stellar-solutions-modules/global-modules/tax/context");
74
110
  var useInvoiceState = function () {
75
111
  var _a = (0, react_1.useReducer)(reducer_1.invoiceReducer, reducer_1.initialInvoiceState), state = _a[0], dispatch = _a[1];
76
- var products = (0, context_1.useProductStateContext)().products;
77
- var companies = (0, context_2.useCompanyStateContext)().companies;
112
+ var companies = (0, context_1.useCompanyStateContext)().companies;
113
+ var taxes = (0, context_2.useTaxStateContext)().taxes;
78
114
  var debouncedQuery = (0, util_functions_1.useDebounce)(state.searchQuery, 800);
115
+ var debouncedProductList = (0, util_functions_1.useDebounce)(state.productQuery, 800);
116
+ var debouncedCustomerList = (0, util_functions_1.useDebounce)(state.phone, 800);
117
+ var debouncedTaxList = (0, util_functions_1.useDebounce)(state.taxQuery, 800);
118
+ var defaultTax = (0, react_1.useMemo)(function () {
119
+ return taxes.filter(function (_a) {
120
+ var isDefault = _a.isDefault;
121
+ return isDefault;
122
+ })[0];
123
+ }, [taxes]);
79
124
  var listParams = {
80
125
  category: types_1.QUOTE_INVOICE.INVOICE,
81
126
  currentPage: state.currentPage,
@@ -234,6 +279,96 @@ var useInvoiceState = function () {
234
279
  state.currentPage,
235
280
  state.pageLimit,
236
281
  ]);
282
+ (0, react_1.useEffect)(function () {
283
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
284
+ var data;
285
+ return __generator(this, function (_a) {
286
+ switch (_a.label) {
287
+ case 0: return [4 /*yield*/, (0, util_functions_1.fetchData)({
288
+ url: constants_1.INVOICE_API_ROUTES.PRODUCTS,
289
+ method: util_functions_1.API_METHODS.POST,
290
+ body: JSON.stringify({
291
+ searchQuery: debouncedProductList,
292
+ pageLimit: 100,
293
+ currentPage: 1,
294
+ }),
295
+ })];
296
+ case 1:
297
+ data = (_a.sent()).data;
298
+ if (data === null || data === void 0 ? void 0 : data.items) {
299
+ dispatch({
300
+ type: actions_1.INVOICE_ACTION_TYPES.SET_PRODUCTS_LIST,
301
+ payload: { productsList: data.items },
302
+ });
303
+ }
304
+ return [2 /*return*/];
305
+ }
306
+ });
307
+ }); })();
308
+ }, [debouncedProductList]);
309
+ (0, react_1.useEffect)(function () {
310
+ if (state.formToRender === 'customer' && debouncedCustomerList) {
311
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
312
+ var data;
313
+ return __generator(this, function (_a) {
314
+ switch (_a.label) {
315
+ case 0: return [4 /*yield*/, (0, util_functions_1.fetchData)({
316
+ url: constants_1.INVOICE_API_ROUTES.CUSTOMER_BY_PHONE,
317
+ method: util_functions_1.API_METHODS.POST,
318
+ body: JSON.stringify({
319
+ phone: debouncedCustomerList,
320
+ }),
321
+ })];
322
+ case 1:
323
+ data = (_a.sent()).data;
324
+ if (data) {
325
+ dispatch({
326
+ type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER,
327
+ payload: { customer: __assign({}, data.data) },
328
+ });
329
+ }
330
+ return [2 /*return*/];
331
+ }
332
+ });
333
+ }); })();
334
+ }
335
+ else {
336
+ dispatch({
337
+ type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER,
338
+ payload: { customer: { phone: '', firstName: '', lastName: '', email: '', address: '', city: '', country: '', createdAt: '', updatedAt: '', id: '', invoices: [] } },
339
+ });
340
+ }
341
+ }, [debouncedCustomerList, state.formToRender]);
342
+ (0, react_1.useEffect)(function () {
343
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
344
+ var data;
345
+ return __generator(this, function (_a) {
346
+ switch (_a.label) {
347
+ case 0:
348
+ if (!debouncedTaxList) return [3 /*break*/, 2];
349
+ return [4 /*yield*/, (0, util_functions_1.fetchData)({
350
+ url: constants_1.INVOICE_API_ROUTES.TAXES,
351
+ method: util_functions_1.API_METHODS.POST,
352
+ body: JSON.stringify({
353
+ searchQuery: debouncedTaxList,
354
+ pageLimit: 100,
355
+ currentPage: 1,
356
+ }),
357
+ })];
358
+ case 1:
359
+ data = (_a.sent()).data;
360
+ if (data.items) {
361
+ dispatch({
362
+ type: actions_1.INVOICE_ACTION_TYPES.SET_TAXES,
363
+ payload: { taxes: data.items },
364
+ });
365
+ }
366
+ _a.label = 2;
367
+ case 2: return [2 /*return*/];
368
+ }
369
+ });
370
+ }); })();
371
+ }, [debouncedTaxList]);
237
372
  (0, react_1.useEffect)(function () {
238
373
  var _a = (0, calculate_total_1.calculateTotal)(state.subTotal, state.taxRate, state.discountUnit, state.discount), afterDiscount = _a.afterDiscount, tax = _a.tax, total = _a.total;
239
374
  dispatch({
@@ -342,15 +477,16 @@ var useInvoiceState = function () {
342
477
  });
343
478
  }, [updateFetchNow, updateParams]);
344
479
  var handleChange = (0, react_1.useCallback)(function (key, value) {
345
- if (key === 'taxRate') {
346
- dispatch({
347
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
348
- payload: {
349
- key: key,
350
- value: value,
351
- },
352
- });
353
- }
480
+ console.log({ key: key, value: value });
481
+ // if (key === 'taxRate') {
482
+ // dispatch({
483
+ // type: INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
484
+ // payload: {
485
+ // key: key as keyof InvoiceTypeBE,
486
+ // value: value,
487
+ // },
488
+ // });
489
+ // }
354
490
  dispatch({
355
491
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
356
492
  payload: { key: key, value: String(value) },
@@ -408,10 +544,11 @@ var useInvoiceState = function () {
408
544
  }, [state.products, state.services]);
409
545
  var handleItemChangeProducts = (0, react_1.useCallback)(function (_a) {
410
546
  var _b, _c, _d;
547
+ var _e;
411
548
  var index = _a.index, key = _a.key, value = _a.value;
412
549
  var updatedItems = __spreadArray([], state.products, true);
413
550
  if (key === 'id' && typeof value === 'string') {
414
- var matchingProduct = products === null || products === void 0 ? void 0 : products.find(function (product) { return product.id === value; });
551
+ var matchingProduct = (_e = state.productsList) === null || _e === void 0 ? void 0 : _e.find(function (product) { return product.id === value; });
415
552
  if (matchingProduct) {
416
553
  var quantity = parseFloat(String(updatedItems[index].quantity)) || 0;
417
554
  var rowTotal = (quantity * parseFloat(matchingProduct.salePrice)).toFixed(2);
@@ -444,7 +581,7 @@ var useInvoiceState = function () {
444
581
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
445
582
  payload: { key: 'products', value: updatedItems },
446
583
  });
447
- }, [state.services, state.products, products]);
584
+ }, [state.services, state.products, state.productsList]);
448
585
  var handlePriceTypeChange = function (k, v) {
449
586
  dispatch({
450
587
  type: actions_1.INVOICE_ACTION_TYPES.SET_DISCOUNT_UNIT,
@@ -483,6 +620,17 @@ var useInvoiceState = function () {
483
620
  // }, []);
484
621
  var handleSelectChange = function (key, value) {
485
622
  var val = __assign({}, value);
623
+ console.log('seleect', key, value);
624
+ if (key === 'taxRate') {
625
+ dispatch({
626
+ type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
627
+ payload: {
628
+ key: key,
629
+ value: val[key],
630
+ }
631
+ });
632
+ return;
633
+ }
486
634
  if (key === 'currency') {
487
635
  dispatch({
488
636
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
@@ -578,28 +726,16 @@ var useInvoiceState = function () {
578
726
  var elements = __assign({}, constants_1.staticCustomerSection);
579
727
  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; });
580
728
  if (textInputElements) {
581
- textInputElements[0].value = state.phone;
582
- textInputElements[0].handleOnChange = handleChange;
583
- textInputElements[0].error = state.errors.phone;
584
- textInputElements[1].value = state.email;
585
- textInputElements[1].handleOnChange = handleChange;
586
- textInputElements[1].error = state.errors.email;
587
- textInputElements[2].value = state.firstName;
588
- textInputElements[2].handleOnChange = handleChange;
589
- textInputElements[2].error = state.errors.firstName;
590
- textInputElements[3].value = state.lastName;
591
- textInputElements[3].handleOnChange = handleChange;
592
- textInputElements[3].error = state.errors.lastName;
593
- textInputElements[4].value = state.address;
594
- textInputElements[4].handleOnChange = handleChange;
595
- textInputElements[4].error = state.errors.address;
596
- textInputElements[5].value = state.city;
597
- textInputElements[5].handleOnChange = handleChange;
598
- textInputElements[5].error = state.errors.city;
729
+ textInputElements.forEach(function (_a, i) {
730
+ var id = _a.id;
731
+ textInputElements[i].error = state.errors[id];
732
+ textInputElements[i].handleOnChange = handleChange;
733
+ textInputElements[i].value = state[id];
734
+ });
599
735
  }
600
736
  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; });
601
737
  if (comboboxElements) {
602
- comboboxElements[0].selectedItem = { id: state.country };
738
+ comboboxElements[0].selectedItem = { name: state.country };
603
739
  comboboxElements[0].listItems = util_functions_2.countriesTimeZones;
604
740
  comboboxElements[0].query = state.countryQuery;
605
741
  comboboxElements[0].handleOnChange = handleSelectChange;
@@ -629,8 +765,11 @@ var useInvoiceState = function () {
629
765
  }
630
766
  var comboboxElements = (_e = elements[form_schema_1.VISTA_FORM_ELEMENTS.COMBOBOX_V1]) === null || _e === void 0 ? void 0 : _e.sort(function (a, b) { return a.order - b.order; });
631
767
  if (comboboxElements) {
632
- comboboxElements[0].selectedItem = { taxName: state.taxRate };
633
- comboboxElements[0].listItems = [];
768
+ comboboxElements[0].selectedItem = { taxName: state.taxRate || (defaultTax === null || defaultTax === void 0 ? void 0 : defaultTax.taxRate) };
769
+ comboboxElements[0].listItems = state.taxes || taxes;
770
+ comboboxElements[0].query = state.taxQuery;
771
+ comboboxElements[0].handleOnChange = handleSelectChange;
772
+ comboboxElements[0].handleInputOnChange = handleChange;
634
773
  }
635
774
  var radioElements = (_f = elements[form_schema_1.VISTA_FORM_ELEMENTS.RADIO_V1]) === null || _f === void 0 ? void 0 : _f.sort(function (a, b) { return a.order - b.order; });
636
775
  if (radioElements) {
@@ -638,7 +777,7 @@ var useInvoiceState = function () {
638
777
  radioElements[0].handleOnChange = handlePriceTypeChange;
639
778
  }
640
779
  return elements;
641
- }, [handleChange, state]);
780
+ }, [handleChange, state, taxes, defaultTax]);
642
781
  var handleDeleteServiceRow = function (i) {
643
782
  if (state.services.length > 1) {
644
783
  var res = state.services.splice(i, 1);
@@ -799,10 +938,7 @@ var useInvoiceState = function () {
799
938
  // handleUploadImage,
800
939
  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 });
801
940
  };
802
- 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: {},
803
- // dynamicProductFormElements: {},
804
- // dynamicServiceFormElements: [],
805
- 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; },
941
+ 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; },
806
942
  // handleUploadImage: () => void 0,
807
943
  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; } }));
808
944
  var InvoiceStateContextProvider = function (_a) {
@@ -34,7 +34,7 @@ var renderCustomerFormElements = function (elementProps) {
34
34
  })) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) { return a.order - b.order; });
35
35
  return (react_1.default.createElement("div", { className: "grid grid-cols-4 gap-4" }, elementsArray === null || elementsArray === void 0 ? void 0 : elementsArray.map(function (_a, index) {
36
36
  var key = _a.key, Component = _a.Component, props = _a.props;
37
- return (react_1.default.createElement("div", { key: "".concat(key, "-").concat(index) },
37
+ return (react_1.default.createElement("div", { key: "".concat(key, "-").concat(index), className: props.className },
38
38
  react_1.default.createElement(Component, __assign({}, props))));
39
39
  })));
40
40
  };
@@ -1,6 +1,4 @@
1
1
  import { FC } from 'react';
2
- import "slick-carousel/slick/slick.css";
3
- import "slick-carousel/slick/slick-theme.css";
4
2
  interface Props {
5
3
  params: Promise<{
6
4
  locale: 'en' | 'ur';
@@ -13,8 +13,6 @@ var vista_table_v1_1 = require("@appcorp/app-corp-vista/organisms/vista-table-v1
13
13
  var constants_1 = require("./constants");
14
14
  var drawer_1 = require("./drawer");
15
15
  var generate_toast_1 = require("@appcorp/app-corp-vista/utils/generate-toast");
16
- require("slick-carousel/slick/slick.css");
17
- require("slick-carousel/slick/slick-theme.css");
18
16
  var InvoicePage = function () {
19
17
  var _a = (0, context_1.useInvoiceStateContext)(), count = _a.count, currentPage = _a.currentPage, pageLimit = _a.pageLimit, handleNextClick = _a.handleNextClick, handlePreviousClick = _a.handlePreviousClick,
20
18
  // toggleDrawerOpen,
@@ -83,7 +81,7 @@ var InvoicePage = function () {
83
81
  ];
84
82
  var totalPagePerRecord = (0, util_functions_1.calculatePages)(count, pageLimit);
85
83
  return (react_1.default.createElement(react_1.default.Fragment, null,
86
- react_1.default.createElement(vista_table_v1_1.VistaTableV1, { currentPage: count, 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 }),
84
+ 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 }),
87
85
  react_1.default.createElement(drawer_1.Drawer, { translationMap: translationMap }),
88
86
  react_1.default.createElement(generate_toast_1.VistaToaster, null)));
89
87
  };
@@ -23,10 +23,8 @@ var vista_button_v1_1 = require("@appcorp/app-corp-vista/molecules/vista-button-
23
23
  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
- var context_2 = require("@appcorp/stellar-solutions-product-module/base-modules/product/context");
27
26
  var ProductsSection = function () {
28
- var _a = (0, context_1.useInvoiceStateContext)(), products = _a.products, handleItemChangeProducts = _a.handleItemChangeProducts, handleDeleteServiceRow = _a.handleDeleteServiceRow, handleChange = _a.handleChange;
29
- var productList = (0, context_2.useProductStateContext)().products;
27
+ var _a = (0, context_1.useInvoiceStateContext)(), products = _a.products, handleItemChangeProducts = _a.handleItemChangeProducts, handleDeleteServiceRow = _a.handleDeleteServiceRow, handleChange = _a.handleChange, productsList = _a.productsList;
30
28
  return (react_1.default.createElement("div", { className: "flex flex-col gap-4" },
31
29
  react_1.default.createElement(vista_vertical_divider_v4_1.VistaVerticalDividerV4, { label: "Products" }),
32
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' },
@@ -38,7 +36,7 @@ var ProductsSection = function () {
38
36
  key: k,
39
37
  value: val.id,
40
38
  });
41
- }, handleOnBlur: handleChange, handleInputOnChange: handleChange, label: "Product", listItems: productList, nodeQueryKey: 'productQuery', nodeSelectKey: 'id', query: '', selectKey1: 'name', selectedItem: { id: products[index].id } })),
39
+ }, handleOnBlur: handleChange, handleInputOnChange: handleChange, label: "Product", listItems: productsList, nodeQueryKey: 'productQuery', nodeSelectKey: 'id', query: '', selectKey1: 'name', selectedItem: { id: products[index].id } })),
42
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' }),
43
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' }),
44
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 }),
@@ -28,16 +28,16 @@ var constants_1 = require("./constants");
28
28
  var date_fns_1 = require("date-fns");
29
29
  exports.initialInvoiceState = {
30
30
  address: '',
31
+ afterDiscount: '0',
31
32
  category: types_1.QUOTE_INVOICE.INVOICE,
32
33
  city: '',
33
- formToRender: '',
34
34
  companyId: '',
35
35
  companyQuery: '',
36
- productQuery: '',
37
36
  count: 0,
38
37
  country: '',
39
38
  countryQuery: '',
40
39
  currency: 'PKR',
40
+ contactsList: [],
41
41
  currentPage: 1,
42
42
  customerId: '',
43
43
  date: new Date().toISOString(),
@@ -49,6 +49,7 @@ exports.initialInvoiceState = {
49
49
  errors: {},
50
50
  expiryDate: (0, date_fns_1.addDays)(new Date(), 7).toISOString(),
51
51
  firstName: '',
52
+ formToRender: '',
52
53
  id: '',
53
54
  invoiceStatus: types_1.INVOICE_STATUS.UNPAID,
54
55
  invoices: [],
@@ -61,14 +62,17 @@ exports.initialInvoiceState = {
61
62
  pageLimit: constants_1.pageLimit,
62
63
  payments: [],
63
64
  phone: '',
65
+ productsList: [],
66
+ productQuery: '',
64
67
  quoteStatus: types_1.QUOTE_STATUS.DRAFT,
65
68
  ref: '',
66
69
  searchQuery: '',
67
70
  subTotal: '',
68
- taxRate: '17',
69
- total: '',
70
- afterDiscount: '0',
71
71
  tax: '',
72
+ taxRate: '',
73
+ taxQuery: '',
74
+ taxes: [],
75
+ total: '',
72
76
  company: {
73
77
  name: '',
74
78
  country: '',
@@ -107,7 +111,7 @@ function invoiceReducer(state, action) {
107
111
  case actions_1.INVOICE_ACTION_TYPES.RESET_ERRORS:
108
112
  return __assign(__assign({}, state), { errors: {} });
109
113
  case actions_1.INVOICE_ACTION_TYPES.RESET_FORM:
110
- return __assign(__assign({}, state), exports.initialInvoiceState);
114
+ return __assign({}, state);
111
115
  case actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON:
112
116
  return __assign(__assign({}, state), { disableSaveButton: action.payload.disableSaveButton });
113
117
  case actions_1.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE:
@@ -154,6 +158,12 @@ function invoiceReducer(state, action) {
154
158
  return __assign(__assign({}, state), { products: __spreadArray([], action.payload.products, true) });
155
159
  case actions_1.INVOICE_ACTION_TYPES.SET_FORM_TO_RENDER:
156
160
  return __assign(__assign({}, state), { formToRender: action.payload.formToRender });
161
+ case actions_1.INVOICE_ACTION_TYPES.SET_PRODUCTS_LIST:
162
+ return __assign(__assign({}, state), { productsList: __spreadArray([], action.payload.productsList, true) });
163
+ case actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER:
164
+ return __assign(__assign({}, state), action.payload.customer);
165
+ case actions_1.INVOICE_ACTION_TYPES.SET_TAXES:
166
+ return __assign(__assign({}, state), { taxes: __spreadArray([], action.payload.taxes, true) });
157
167
  default:
158
168
  return state;
159
169
  }
@@ -4,6 +4,9 @@ import { VistaFormElements } from '@appcorp/app-corp-vista/type/vista-form-eleme
4
4
  import { CompanyTypeBE } from '@appcorp/stellar-solutions-company-module/base-modules/company/types';
5
5
  import { Dispatch } from 'react';
6
6
  import { InvoiceActions } from './actions';
7
+ import { ProductTypeBE } from '@appcorp/stellar-solutions-product-module/base-modules/product/types';
8
+ import { ContactTypeBE } from '@appcorp/stellar-solutions-company-module/base-modules/contact/types';
9
+ import { TaxTypeBE } from '@appcorp/stellar-solutions-modules/global-modules/preferences/types';
7
10
  export interface InvoiceContextType {
8
11
  byIdError?: Error;
9
12
  byIdLoading: boolean;
@@ -17,7 +20,7 @@ export interface InvoiceContextType {
17
20
  dynamicPricingFormElements: VistaFormElements;
18
21
  handleAddItemProduct: () => void;
19
22
  handleAddItemService: () => void;
20
- handleChange: (field: string, value: string | number | number[]) => void;
23
+ handleChange: (field: string, value: string) => void;
21
24
  handleDeleteProductRow: (i: number) => void;
22
25
  handleDeleteServiceRow: (i: number) => void;
23
26
  handleItemChangeProducts: ({ index, key, value }: {
@@ -122,6 +125,7 @@ export interface InvoiceState extends Omit<InvoiceTypeBE, 'createdAt' | 'updated
122
125
  afterDiscount: string;
123
126
  city: string;
124
127
  companyQuery: string;
128
+ contactsList: ContactTypeBE[];
125
129
  count: number;
126
130
  country: string;
127
131
  countryQuery: string;
@@ -144,8 +148,11 @@ export interface InvoiceState extends Omit<InvoiceTypeBE, 'createdAt' | 'updated
144
148
  phone: string;
145
149
  productQuery: string;
146
150
  products: Product[];
151
+ productsList: ProductTypeBE[];
147
152
  searchQuery: string;
148
153
  tax: string;
154
+ taxQuery: string;
155
+ taxes: TaxTypeBE[];
149
156
  }
150
157
  export interface FetchInvoicesArgs {
151
158
  currentPage: number;
@@ -194,3 +201,16 @@ export declare enum DISCOUNT_UNIT {
194
201
  FIXED_VALUE = "FIXED_VALUE",
195
202
  PERCENTAGE_VALUE = "PERCENTAGE_VALUE"
196
203
  }
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/stellar-solutions-invoice-module",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
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",
@@ -17,10 +17,10 @@
17
17
  "upgrade": "ncu -u"
18
18
  },
19
19
  "devDependencies": {
20
- "@appcorp/app-corp-vista": "^0.2.85",
21
- "@appcorp/stellar-solutions-company-module": "^0.1.28",
22
- "@appcorp/stellar-solutions-modules": "^0.1.27",
23
- "@appcorp/stellar-solutions-product-module": "^0.2.4",
20
+ "@appcorp/app-corp-vista": "^0.2.88",
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",
24
24
  "@eslint/eslintrc": "^3",
25
25
  "@headlessui/react": "^2",
26
26
  "@heroicons/react": "^2",