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

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 = {}));
@@ -10,7 +10,7 @@ var calculateTotal = function (subtotal, taxRate, discountUnit, discount) {
10
10
  ? (subtotalValue * discountValue) / 100
11
11
  : discountValue;
12
12
  var afterDiscount = subtotalValue - discountedAmount;
13
- var tax = ((afterDiscount * parseFloat(taxRate)) / 100).toFixed(2);
13
+ var tax = taxRate ? ((afterDiscount * parseFloat(taxRate)) / 100).toFixed(2) : Number(0).toFixed(2);
14
14
  var total = (subtotalValue +
15
15
  parseFloat(tax) -
16
16
  discountedAmount).toFixed(2);
@@ -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;
@@ -33,6 +38,12 @@ export declare const tableBodyCols: ({
33
38
  componentType: VISTA_TABLE_CELL_TYPE;
34
39
  key: string[];
35
40
  expression: (text: string) => string;
41
+ } | {
42
+ componentType: VISTA_TABLE_CELL_TYPE;
43
+ key: string;
44
+ expression: (text: string, obj: {
45
+ currency: string;
46
+ }) => string;
36
47
  } | {
37
48
  componentType: VISTA_TABLE_CELL_TYPE;
38
49
  key?: undefined;
@@ -135,10 +135,10 @@ exports.staticCustomerSection = (_b = {},
135
135
  id: 'phone',
136
136
  label: 'Phone',
137
137
  order: 1,
138
- placeholder: '03** - *****',
138
+ placeholder: '+92 300 0000000',
139
139
  required: true,
140
140
  type: 'text',
141
- value: '',
141
+ value: ''
142
142
  },
143
143
  {
144
144
  disabled: false,
@@ -147,7 +147,7 @@ exports.staticCustomerSection = (_b = {},
147
147
  handleOnChange: function () { return void 0; },
148
148
  id: 'firstName',
149
149
  label: 'First Name',
150
- order: 3,
150
+ order: 2,
151
151
  placeholder: 'John',
152
152
  required: true,
153
153
  type: 'text',
@@ -160,7 +160,7 @@ exports.staticCustomerSection = (_b = {},
160
160
  handleOnChange: function () { },
161
161
  id: 'lastName',
162
162
  label: 'Last Name',
163
- order: 4,
163
+ order: 3,
164
164
  placeholder: 'Doe',
165
165
  required: true,
166
166
  type: 'text',
@@ -173,7 +173,7 @@ exports.staticCustomerSection = (_b = {},
173
173
  handleOnChange: function () { },
174
174
  id: 'email',
175
175
  label: 'Email',
176
- order: 2,
176
+ order: 7,
177
177
  placeholder: 'xyz@company.com',
178
178
  required: false,
179
179
  type: 'text',
@@ -223,6 +223,22 @@ exports.staticCustomerSection = (_b = {},
223
223
  selectKey1: 'name',
224
224
  selectedItem: { name: '' },
225
225
  },
226
+ {
227
+ enabled: true,
228
+ handleInputOnChange: function () { return void 0; },
229
+ handleOnBlur: function () { return void 0; },
230
+ handleOnChange: function () { },
231
+ label: 'Currency',
232
+ listItems: [],
233
+ nodeQueryKey: '',
234
+ nodeSelectKey: 'currency',
235
+ order: 7,
236
+ placeholder: '',
237
+ query: '',
238
+ required: true,
239
+ selectKey1: 'code',
240
+ selectedItem: { code: '' },
241
+ },
226
242
  ],
227
243
  _b);
228
244
  exports.staticPricingSection = (_c = {},
@@ -301,8 +317,8 @@ exports.staticPricingSection = (_c = {},
301
317
  handleOnChange: function () { return void 0; },
302
318
  label: 'Tax',
303
319
  listItems: [],
304
- nodeQueryKey: '',
305
- nodeSelectKey: 'taxValue',
320
+ nodeQueryKey: 'taxQuery',
321
+ nodeSelectKey: 'taxRate',
306
322
  order: 5,
307
323
  query: '',
308
324
  required: false,
@@ -501,6 +517,11 @@ exports.INVOICE_API_ROUTES = {
501
517
  INVOICES: '/api/quotes-invoices',
502
518
  INVOICE: '/api/quote-invoice',
503
519
  INVOICE_BY_ID: '/api/quote-invoice/quote-invoice-by-id',
520
+ PRODUCTS: '/api/products',
521
+ CONTACTS: '/api/contacts',
522
+ CUSTOMER_BY_PHONE: '/api/customer/by-phone',
523
+ TAXES: '/api/taxes',
524
+ TAX: '/api/tax',
504
525
  };
505
526
  exports.tableBodyCols = [
506
527
  {
@@ -509,21 +530,13 @@ exports.tableBodyCols = [
509
530
  },
510
531
  {
511
532
  componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.OBJECT,
512
- key: ['company', 'name'],
513
- },
514
- {
515
- componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.TEXT,
516
- key: 'currency',
533
+ key: ['company:customer', 'name:firstName'],
517
534
  },
518
535
  {
519
536
  componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.MULTIPLE_TEXT_LINES,
520
537
  key: ['date', 'expiryDate'],
521
538
  expression: function (text) { return (0, util_functions_1.formatDate)(text, util_functions_1.DATE_FORMATS.LOCALE_DATE); },
522
539
  },
523
- {
524
- componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.TEXT,
525
- key: 'note',
526
- },
527
540
  {
528
541
  componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.TEXT,
529
542
  key: 'ref',
@@ -531,6 +544,7 @@ exports.tableBodyCols = [
531
544
  {
532
545
  componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.TEXT,
533
546
  key: 'subTotal',
547
+ expression: function (text, obj) { return "".concat(obj.currency).concat(text); },
534
548
  },
535
549
  {
536
550
  componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.TEXT,
@@ -543,6 +557,7 @@ exports.tableBodyCols = [
543
557
  {
544
558
  componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.TEXT,
545
559
  key: 'total',
560
+ expression: function (text, obj) { return "".concat(obj.currency).concat(text); },
546
561
  },
547
562
  {
548
563
  componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.TEXT,
@@ -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,33 @@ 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");
110
+ var context_3 = require("@appcorp/stellar-solutions-modules/global-modules/preferences/context");
74
111
  var useInvoiceState = function () {
75
112
  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;
113
+ var companies = (0, context_1.useCompanyStateContext)().companies;
114
+ var taxes = (0, context_2.useTaxStateContext)().taxes;
115
+ var currencies = (0, context_3.usePreferenceStateContext)().currencies;
78
116
  var debouncedQuery = (0, util_functions_1.useDebounce)(state.searchQuery, 800);
117
+ var debouncedProductList = (0, util_functions_1.useDebounce)(state.productQuery, 800);
118
+ var debouncedCustomerList = (0, util_functions_1.useDebounce)(state.phone, 800);
119
+ var debouncedTaxList = (0, util_functions_1.useDebounce)(state.taxQuery, 800);
120
+ var defaultTax = (0, react_1.useMemo)(function () {
121
+ return taxes.filter(function (_a) {
122
+ var isDefault = _a.isDefault;
123
+ return isDefault;
124
+ })[0];
125
+ }, [taxes]);
126
+ var defaultCurrency = (0, react_1.useMemo)(function () {
127
+ return currencies.filter(function (_a) {
128
+ var isDefault = _a.isDefault;
129
+ return isDefault;
130
+ })[0];
131
+ }, [currencies]);
79
132
  var listParams = {
80
133
  category: types_1.QUOTE_INVOICE.INVOICE,
81
134
  currentPage: state.currentPage,
@@ -105,6 +158,12 @@ var useInvoiceState = function () {
105
158
  category: state.category,
106
159
  companyId: state.companyId,
107
160
  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,
108
167
  customerId: state.customerId,
109
168
  date: state.date,
110
169
  discount: state.discount.trim(),
@@ -234,6 +293,96 @@ var useInvoiceState = function () {
234
293
  state.currentPage,
235
294
  state.pageLimit,
236
295
  ]);
296
+ (0, react_1.useEffect)(function () {
297
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
298
+ var data;
299
+ return __generator(this, function (_a) {
300
+ switch (_a.label) {
301
+ case 0: return [4 /*yield*/, (0, util_functions_1.fetchData)({
302
+ url: constants_1.INVOICE_API_ROUTES.PRODUCTS,
303
+ method: util_functions_1.API_METHODS.POST,
304
+ body: JSON.stringify({
305
+ searchQuery: debouncedProductList,
306
+ pageLimit: 100,
307
+ currentPage: 1,
308
+ }),
309
+ })];
310
+ case 1:
311
+ data = (_a.sent()).data;
312
+ if (data === null || data === void 0 ? void 0 : data.items) {
313
+ dispatch({
314
+ type: actions_1.INVOICE_ACTION_TYPES.SET_PRODUCTS_LIST,
315
+ payload: { productsList: data.items },
316
+ });
317
+ }
318
+ return [2 /*return*/];
319
+ }
320
+ });
321
+ }); })();
322
+ }, [debouncedProductList]);
323
+ (0, react_1.useEffect)(function () {
324
+ if (state.drawer === types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER && debouncedCustomerList) {
325
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
326
+ var data;
327
+ return __generator(this, function (_a) {
328
+ switch (_a.label) {
329
+ case 0: return [4 /*yield*/, (0, util_functions_1.fetchData)({
330
+ url: constants_1.INVOICE_API_ROUTES.CUSTOMER_BY_PHONE,
331
+ method: util_functions_1.API_METHODS.POST,
332
+ body: JSON.stringify({
333
+ phone: debouncedCustomerList,
334
+ }),
335
+ })];
336
+ case 1:
337
+ data = (_a.sent()).data;
338
+ if (data) {
339
+ dispatch({
340
+ type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER,
341
+ payload: { customer: __assign(__assign({}, data), { customerId: data.id }) },
342
+ });
343
+ }
344
+ return [2 /*return*/];
345
+ }
346
+ });
347
+ }); })();
348
+ }
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
+ });
354
+ }
355
+ }, [debouncedCustomerList, state.formToRender, state.drawer]);
356
+ (0, react_1.useEffect)(function () {
357
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
358
+ var data;
359
+ return __generator(this, function (_a) {
360
+ switch (_a.label) {
361
+ case 0:
362
+ if (!debouncedTaxList) return [3 /*break*/, 2];
363
+ return [4 /*yield*/, (0, util_functions_1.fetchData)({
364
+ url: constants_1.INVOICE_API_ROUTES.TAXES,
365
+ method: util_functions_1.API_METHODS.POST,
366
+ body: JSON.stringify({
367
+ searchQuery: debouncedTaxList,
368
+ pageLimit: 100,
369
+ currentPage: 1,
370
+ }),
371
+ })];
372
+ case 1:
373
+ data = (_a.sent()).data;
374
+ if (data.items) {
375
+ dispatch({
376
+ type: actions_1.INVOICE_ACTION_TYPES.SET_TAXES,
377
+ payload: { taxes: data.items },
378
+ });
379
+ }
380
+ _a.label = 2;
381
+ case 2: return [2 /*return*/];
382
+ }
383
+ });
384
+ }); })();
385
+ }, [debouncedTaxList]);
237
386
  (0, react_1.useEffect)(function () {
238
387
  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
388
  dispatch({
@@ -294,20 +443,12 @@ var useInvoiceState = function () {
294
443
  type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
295
444
  payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_COMPANY_FORM_DRAWER },
296
445
  });
297
- dispatch({
298
- type: actions_1.INVOICE_ACTION_TYPES.SET_FORM_TO_RENDER,
299
- payload: { formToRender: 'company' },
300
- });
301
446
  }
302
447
  if (text === 'customer') {
303
448
  dispatch({
304
449
  type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
305
450
  payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER },
306
451
  });
307
- dispatch({
308
- type: actions_1.INVOICE_ACTION_TYPES.SET_FORM_TO_RENDER,
309
- payload: { formToRender: 'customer' },
310
- });
311
452
  }
312
453
  };
313
454
  var handleEdit = function (id) {
@@ -326,11 +467,11 @@ var useInvoiceState = function () {
326
467
  payload: { disableSaveButton: true },
327
468
  });
328
469
  (0, util_functions_1.validateForm)({
329
- params: updateParams,
470
+ params: __assign(__assign({}, updateParams), { currency: updateParams.currency || defaultCurrency.code, taxRate: updateParams.taxRate || defaultTax.taxRate }),
330
471
  schema: validate_1.formValidation,
331
472
  successCallback: function () {
332
473
  updateFetchNow(undefined, {
333
- body: JSON.stringify(__assign(__assign({}, updateParams), { products: updateParams.products.filter(function (item) { return item.id; }), services: updateParams.services.filter(function (item) { return item.name; }) })),
474
+ 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 })),
334
475
  });
335
476
  },
336
477
  errorCallback: function (e) {
@@ -340,17 +481,8 @@ var useInvoiceState = function () {
340
481
  });
341
482
  },
342
483
  });
343
- }, [updateFetchNow, updateParams]);
484
+ }, [updateFetchNow, updateParams, defaultCurrency, defaultTax]);
344
485
  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
- }
354
486
  dispatch({
355
487
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
356
488
  payload: { key: key, value: String(value) },
@@ -408,10 +540,11 @@ var useInvoiceState = function () {
408
540
  }, [state.products, state.services]);
409
541
  var handleItemChangeProducts = (0, react_1.useCallback)(function (_a) {
410
542
  var _b, _c, _d;
543
+ var _e;
411
544
  var index = _a.index, key = _a.key, value = _a.value;
412
545
  var updatedItems = __spreadArray([], state.products, true);
413
546
  if (key === 'id' && typeof value === 'string') {
414
- var matchingProduct = products === null || products === void 0 ? void 0 : products.find(function (product) { return product.id === value; });
547
+ var matchingProduct = (_e = state.productsList) === null || _e === void 0 ? void 0 : _e.find(function (product) { return product.id === value; });
415
548
  if (matchingProduct) {
416
549
  var quantity = parseFloat(String(updatedItems[index].quantity)) || 0;
417
550
  var rowTotal = (quantity * parseFloat(matchingProduct.salePrice)).toFixed(2);
@@ -444,52 +577,42 @@ var useInvoiceState = function () {
444
577
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
445
578
  payload: { key: 'products', value: updatedItems },
446
579
  });
447
- }, [state.services, state.products, products]);
580
+ }, [state.services, state.products, state.productsList]);
448
581
  var handlePriceTypeChange = function (k, v) {
449
582
  dispatch({
450
583
  type: actions_1.INVOICE_ACTION_TYPES.SET_DISCOUNT_UNIT,
451
584
  payload: { discountUnit: v },
452
585
  });
453
- // if (e.target.value === 'Percentage(%)') {
454
- // invoiceDispatch({
455
- // type: INVOICE_ACTION_TYPES.SET_DISCOUNT_UNIT,
456
- // payload: '%',
457
- // });
458
- // } else {
459
- // invoiceDispatch({
460
- // type: INVOICE_ACTION_TYPES.SET_DISCOUNT_UNIT,
461
- // payload: '',
462
- // });
463
- // }
464
586
  };
465
- // const handleSelectInputChange = useCallback(async (key: string, value: string) => {
466
- // const response = await fetch(INVOICE_CATEGORY_API_ROUTES.INVOICE_CATEGORIES, {
467
- // method: API_METHODS.POST,
468
- // body: JSON.stringify({
469
- // searchQuery: debouncedList,
470
- // pageLimit: 1000,
471
- // currentPage: 1,
472
- // }),
473
- // });
474
- // const result = await response.json();
475
- // dispatch({
476
- // type: INVOICE_ACTION_TYPES.SET_INVOICE_CATEGORIES,
477
- // payload: { productCategories: result as ProductCategoryBE[] },
478
- // });
479
- // dispatch({
480
- // type: INVOICE_ACTION_TYPES.SET_INVOICE_QUERY,
481
- // payload: { productCategoryQuery: value },
482
- // });
483
- // }, []);
484
587
  var handleSelectChange = function (key, value) {
485
588
  var val = __assign({}, value);
589
+ if (key === 'taxRate') {
590
+ dispatch({
591
+ type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
592
+ payload: {
593
+ key: key,
594
+ value: val.taxRate,
595
+ },
596
+ });
597
+ return;
598
+ }
599
+ if (key === 'country') {
600
+ dispatch({
601
+ type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
602
+ payload: {
603
+ key: key,
604
+ value: val.name,
605
+ },
606
+ });
607
+ return;
608
+ }
486
609
  if (key === 'currency') {
487
610
  dispatch({
488
611
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
489
612
  payload: {
490
613
  key: key,
491
- value: val['option'],
492
- }
614
+ value: val.code,
615
+ },
493
616
  });
494
617
  return;
495
618
  }
@@ -578,36 +701,28 @@ var useInvoiceState = function () {
578
701
  var elements = __assign({}, constants_1.staticCustomerSection);
579
702
  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
703
  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;
704
+ textInputElements.forEach(function (_a, i) {
705
+ var id = _a.id;
706
+ textInputElements[i].error = state.errors[id];
707
+ textInputElements[i].handleOnChange = handleChange;
708
+ textInputElements[i].value = state[id];
709
+ });
599
710
  }
600
711
  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
712
  if (comboboxElements) {
602
- comboboxElements[0].selectedItem = { id: state.country };
713
+ comboboxElements[0].selectedItem = { name: state.country };
603
714
  comboboxElements[0].listItems = util_functions_2.countriesTimeZones;
604
715
  comboboxElements[0].query = state.countryQuery;
605
716
  comboboxElements[0].handleOnChange = handleSelectChange;
606
717
  comboboxElements[0].handleInputOnChange = handleChange;
607
718
  comboboxElements[0].handleOnBlur = handleChange;
719
+ comboboxElements[1].selectedItem = { code: state.currency || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.code) };
720
+ comboboxElements[1].listItems = currencies;
721
+ comboboxElements[1].handleOnChange = handleSelectChange;
722
+ comboboxElements[1].handleInputOnChange = handleChange;
608
723
  }
609
724
  return elements;
610
- }, [state, handleChange]);
725
+ }, [state, handleChange, currencies, defaultCurrency]);
611
726
  var dynamicPricingFormElements = (0, react_1.useMemo)(function () {
612
727
  var _a, _b, _c, _d, _e, _f;
613
728
  var elements = __assign({}, constants_1.staticPricingSection);
@@ -629,8 +744,11 @@ var useInvoiceState = function () {
629
744
  }
630
745
  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
746
  if (comboboxElements) {
632
- comboboxElements[0].selectedItem = { taxName: state.taxRate };
633
- comboboxElements[0].listItems = [];
747
+ comboboxElements[0].selectedItem = { taxName: state.taxRate || (defaultTax === null || defaultTax === void 0 ? void 0 : defaultTax.taxRate) };
748
+ comboboxElements[0].listItems = state.taxes || taxes;
749
+ comboboxElements[0].query = state.taxQuery;
750
+ comboboxElements[0].handleOnChange = handleSelectChange;
751
+ comboboxElements[0].handleInputOnChange = handleChange;
634
752
  }
635
753
  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
754
  if (radioElements) {
@@ -638,7 +756,7 @@ var useInvoiceState = function () {
638
756
  radioElements[0].handleOnChange = handlePriceTypeChange;
639
757
  }
640
758
  return elements;
641
- }, [handleChange, state]);
759
+ }, [handleChange, state, taxes, defaultTax]);
642
760
  var handleDeleteServiceRow = function (i) {
643
761
  if (state.services.length > 1) {
644
762
  var res = state.services.splice(i, 1);
@@ -657,113 +775,6 @@ var useInvoiceState = function () {
657
775
  });
658
776
  }
659
777
  };
660
- // const dynamicServiceFormElements: VistaFormElements[] = useMemo(() => {
661
- // const elements: VistaFormElements = { ...staticServiceSection };
662
- // const servicesElements = state.services.map(() => ({
663
- // ...elements,
664
- // }));
665
- // servicesElements?.map((element, i) => {
666
- // const textInputElements: VistaTextInputV1Props[] | undefined = element[VISTA_FORM_ELEMENTS.TEXT_INPUT_V1]?.sort((a, b) => a.order - b.order);
667
- // if (textInputElements) {
668
- // textInputElements[0].value = state.services[i].name;
669
- // textInputElements[0].handleOnChange = (k, v) => handleItemChangeServices({
670
- // index: i,
671
- // key: k as keyof Service,
672
- // value: v,
673
- // });
674
- // textInputElements[1].value = state.services[i].description;
675
- // textInputElements[1].handleOnChange = (k, v) => handleItemChangeServices({
676
- // index: i,
677
- // key: k as keyof Service,
678
- // value: v,
679
- // });
680
- // textInputElements[2].value = state.services[i].quantity;
681
- // textInputElements[2].handleOnChange = (k, v) => handleItemChangeServices({
682
- // index: i,
683
- // key: k as keyof Service,
684
- // value: v,
685
- // });
686
- // textInputElements[3].value = state.services[i].price;
687
- // textInputElements[3].handleOnChange = (k, v) => handleItemChangeServices({
688
- // index: i,
689
- // key: k as keyof Service,
690
- // value: v,
691
- // });
692
- // textInputElements[4].value = state.services[i].rowTotal;
693
- // }
694
- // // state.services?.forEach((service, i) => {
695
- // // textInputElements[i].error = state.errors[id];
696
- // // textInputElements[i].error = state.errors[id];
697
- // // textInputElements[i].error = state.errors[id];
698
- // // textInputElements[i].error = state.errors[id];
699
- // // textInputElements[i].error = state.errors[id];
700
- // const buttonElements = element[VISTA_FORM_ELEMENTS.BUTTON_V1]?.sort((a, b) => a.order - b.order);
701
- // if (buttonElements) {
702
- // // state.services?.forEach((service, i) => {
703
- // buttonElements[0].handleOnClick = () => {
704
- // if (state.services.length > 1) {
705
- // const res = state.services.splice(i, 1);
706
- // dispatch({
707
- // type: INVOICE_ACTION_TYPES.DELETE_ITEM_SERVICE,
708
- // payload: { services: [...res] },
709
- // });
710
- // }
711
- // }
712
- // // });
713
- // }
714
- // });
715
- // // }
716
- // return servicesElements;
717
- // }, [state.services, handleItemChangeServices]);
718
- // const dynamicProductFormElements: VistaFormElements = useMemo(() => {
719
- // const elements: VistaFormElements = { ...staticProductSection };
720
- // const textInputElements: VistaTextInputV1Props[] | undefined = elements[VISTA_FORM_ELEMENTS.TEXT_INPUT_V1]?.sort((a, b) => a.order - b.order);
721
- // if (textInputElements) {
722
- // state.products?.forEach((product, i) => {
723
- // textInputElements[0].value = String(product.quantity);
724
- // textInputElements[0].handleOnChange = (k, v) => handleItemChangeProducts({
725
- // index: i,
726
- // key: k as keyof Product,
727
- // value: Number(v),
728
- // });
729
- // // textInputElements[i].error = state.errors[id];
730
- // textInputElements[2].value = product.rowTotal;
731
- // });
732
- // }
733
- // const comboboxElements: VistaComboboxV1Props[] | undefined = elements[VISTA_FORM_ELEMENTS.COMBOBOX_V1]?.sort((a, b) => a.order - b.order);
734
- // if (comboboxElements) {
735
- // state.products?.forEach((product, i) => {
736
- // comboboxElements[0].listItems = products;
737
- // comboboxElements[0].query = state.productQuery;
738
- // comboboxElements[0].handleInputOnChange = handleChange;
739
- // comboboxElements[0].handleOnBlur = handleChange;
740
- // comboboxElements[0].handleOnChange = (k, v: object) => {
741
- // console.log('_>>>>>>>>>', k, v);
742
- // const val = { ...v } as { id: string };
743
- // handleItemChangeProducts({
744
- // index: i,
745
- // key: k as keyof Product,
746
- // value: val.id,
747
- // });
748
- // }
749
- // })
750
- // }
751
- // const buttonElements = elements[VISTA_FORM_ELEMENTS.BUTTON_V1]?.sort((a, b) => a.order - b.order);
752
- // if (buttonElements) {
753
- // state.products?.forEach((product, i) => {
754
- // buttonElements[0].handleOnClick = () => {
755
- // if (state.products.length > 1) {
756
- // const res = state.products.splice(i, 1);
757
- // dispatch({
758
- // type: INVOICE_ACTION_TYPES.DELETE_ITEM_PRODUCT,
759
- // payload: { products: [...res] },
760
- // });
761
- // }
762
- // }
763
- // });
764
- // }
765
- // return elements;
766
- // }, [state, handleItemChangeProducts, products, handleChange]);
767
778
  var headerActions = [
768
779
  {
769
780
  enabled: true,
@@ -775,7 +786,7 @@ var useInvoiceState = function () {
775
786
  enabled: true,
776
787
  handleOnClick: function () { return handleCreate('customer'); },
777
788
  label: 'Invoice for Customer',
778
- order: 1,
789
+ order: 2,
779
790
  },
780
791
  ];
781
792
  var rowActions = [
@@ -792,19 +803,9 @@ var useInvoiceState = function () {
792
803
  order: 2,
793
804
  },
794
805
  ];
795
- return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, dynamicCompanyFormElements: dynamicCompanyFormElements, dynamicPricingFormElements: dynamicPricingFormElements,
796
- // dynamicProductFormElements,
797
- // dynamicServiceFormElements,
798
- dynamicCustomerFormElements: dynamicCustomerFormElements, handleChange: handleChange, handleNextClick: handleNextClick, handlePageLimit: handlePageLimit, handlePreviousClick: handlePreviousClick, handleSubmit: handleSubmit,
799
- // handleUploadImage,
800
- 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 });
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 });
801
807
  };
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; },
806
- // handleUploadImage: () => void 0,
807
- 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
+ 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; } }));
808
809
  var InvoiceStateContextProvider = function (_a) {
809
810
  var children = _a.children;
810
811
  var state = useInvoiceState();
@@ -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
  };
@@ -12,11 +12,12 @@ var services_form_section_1 = require("./services-form-section");
12
12
  var company_form_section_1 = require("./company-form-section");
13
13
  var context_1 = require("./context");
14
14
  var customer_form_section_1 = require("./customer-form-section");
15
+ var types_1 = require("./types");
15
16
  var InvoiceForm = function () {
16
- var formToRender = (0, context_1.useInvoiceStateContext)().formToRender;
17
+ var drawer = (0, context_1.useInvoiceStateContext)().drawer;
17
18
  return (react_1.default.createElement("div", { className: "flex flex-col gap-8" },
18
- formToRender === 'customer' && (react_1.default.createElement(customer_form_section_1.CustomerSection, null)),
19
- formToRender === 'company' && (react_1.default.createElement(company_form_section_1.CompanySection, null)),
19
+ drawer === types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER && (react_1.default.createElement(customer_form_section_1.CustomerSection, null)),
20
+ drawer === types_1.INVOICE_DRAWER.INVOICE_COMPANY_FORM_DRAWER && (react_1.default.createElement(company_form_section_1.CompanySection, null)),
20
21
  react_1.default.createElement(services_form_section_1.ServicesSection, null),
21
22
  react_1.default.createElement(products_form_section_1.ProductsSection, null),
22
23
  react_1.default.createElement(add_service_product_section_1.AddServiceProductSection, null),
@@ -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,12 +13,8 @@ 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
- var _a = (0, context_1.useInvoiceStateContext)(), count = _a.count, currentPage = _a.currentPage, pageLimit = _a.pageLimit, handleNextClick = _a.handleNextClick, handlePreviousClick = _a.handlePreviousClick,
20
- // toggleDrawerOpen,
21
- headerActions = _a.headerActions, handlePageLimit = _a.handlePageLimit, searchQuery = _a.searchQuery, searchOnChange = _a.searchOnChange, rowActions = _a.rowActions, invoices = _a.invoices, listLoading = _a.listLoading;
17
+ var _a = (0, context_1.useInvoiceStateContext)(), count = _a.count, currentPage = _a.currentPage, pageLimit = _a.pageLimit, handleNextClick = _a.handleNextClick, handlePreviousClick = _a.handlePreviousClick, headerActions = _a.headerActions, handlePageLimit = _a.handlePageLimit, searchQuery = _a.searchQuery, searchOnChange = _a.searchOnChange, rowActions = _a.rowActions, invoices = _a.invoices, listLoading = _a.listLoading;
22
18
  var t = (0, next_intl_1.useTranslations)('invoicePage');
23
19
  var translationMap = {
24
20
  formLabelName: 'formLabelName',
@@ -40,18 +36,10 @@ var InvoicePage = function () {
40
36
  label: t('tableColumnHeaderName'),
41
37
  width: '10%',
42
38
  },
43
- {
44
- label: t('tableColumnHeaderCurrency'),
45
- width: '5%',
46
- },
47
39
  {
48
40
  label: t('tableColumnHeaderIssueExpiryDate'),
49
41
  width: '10%',
50
42
  },
51
- {
52
- label: t('tableColumnHeaderNote'),
53
- width: '5%',
54
- },
55
43
  {
56
44
  label: t('tableColumnHeaderRef'),
57
45
  width: '5%',
@@ -83,7 +71,7 @@ var InvoicePage = function () {
83
71
  ];
84
72
  var totalPagePerRecord = (0, util_functions_1.calculatePages)(count, pageLimit);
85
73
  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 }),
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 }),
87
75
  react_1.default.createElement(drawer_1.Drawer, { translationMap: translationMap }),
88
76
  react_1.default.createElement(generate_toast_1.VistaToaster, null)));
89
77
  };
@@ -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
- currency: 'PKR',
39
+ currency: '',
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
+ }
@@ -26,9 +26,6 @@ var products = zod_1.z.object({
26
26
  exports.formValidation = zod_1.z.object({
27
27
  companyId: zod_1.z.string().optional(),
28
28
  ref: zod_1.z.string().nonempty(constants_1.validationErrors.ref),
29
- // invoiceStatus: z
30
- // .string()
31
- // .nonempty(formErrors[DASHBOARD_DRAWERS_FORMS.INVOICE].status),
32
29
  date: zod_1.z.string().nonempty(constants_1.validationErrors.date),
33
30
  expiryDate: zod_1.z
34
31
  .string()
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.49",
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,14 +17,14 @@
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.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",
24
24
  "@eslint/eslintrc": "^3",
25
25
  "@headlessui/react": "^2",
26
26
  "@heroicons/react": "^2",
27
- "@react-pakistan/util-functions": "^1.24.38",
27
+ "@react-pakistan/util-functions": "^1.24.39",
28
28
  "@supabase/supabase-js": "^2",
29
29
  "@tailwindcss/forms": "^0.5.10",
30
30
  "@tailwindcss/postcss": "^4",