@appcorp/stellar-solutions-invoice-module 0.1.24 → 0.1.26

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.
@@ -23,8 +23,8 @@ export declare enum INVOICE_ACTION_TYPES {
23
23
  SET_COUNT = "SET_COUNT",
24
24
  SET_FORM = "SET_FORM",
25
25
  SET_DISABLE_SAVE_BUTTON = "SET_DISABLE_SAVE_BUTTON",
26
- SET_TOTAL_DISCOUNT = "SET_TOTAL_DISCOUNT",
27
- SET_TOTAL_TAX = "SET_TOTAL_TAX"
26
+ SET_AFTER_DISCOUNT = "SET_AFTER_DISCOUNT",
27
+ SET_TAX = "SET_TAX"
28
28
  }
29
29
  export type InvoiceUpdateFieldAction = {
30
30
  type: INVOICE_ACTION_TYPES.SET_INPUT_FIELD;
@@ -143,16 +143,16 @@ export type InvoiceSetFormAction = {
143
143
  form: InvoiceTypeBE;
144
144
  };
145
145
  };
146
- export type InvoiceSetTotalDiscountAction = {
147
- type: INVOICE_ACTION_TYPES.SET_TOTAL_DISCOUNT;
146
+ export type InvoiceSetAfterDiscountAction = {
147
+ type: INVOICE_ACTION_TYPES.SET_AFTER_DISCOUNT;
148
148
  payload: {
149
- totalDiscount: string;
149
+ afterDiscount: string;
150
150
  };
151
151
  };
152
- export type InvoiceSetTotalTaxAction = {
153
- type: INVOICE_ACTION_TYPES.SET_TOTAL_TAX;
152
+ export type InvoiceSetTaxAction = {
153
+ type: INVOICE_ACTION_TYPES.SET_TAX;
154
154
  payload: {
155
- totalTax: string;
155
+ tax: string;
156
156
  };
157
157
  };
158
- export type InvoiceActions = InvoiceAddItemProductAction | InvoiceAddItemServiceAction | InvoiceClearErrorAction | InvoiceDeleteItemProductAction | InvoiceDeleteItemServiceAction | InvoiceResetFormAction | InvoiceSetButtonDisableAction | InvoiceSetCurrentPageAction | InvoiceSetCustomerDataAction | InvoiceSetDiscountUnitAction | InvoiceSetErrorsAction | InvoiceSetFormLoadingAction | InvoiceSetInvoicesAction | InvoiceSetInvoiceFormAction | InvoiceSetIsInvoiceApiSuccessAction | InvoiceSetMaxPageLimitAction | InvoiceSetSearchQueryAction | InvoiceUpdateFieldAction | InvoiceToggleLoadingAction | InvoiceSetDrawerAction | InvoiceSetCountAction | InvoiceSetFormAction | InvoiceSetTotalDiscountAction | InvoiceSetTotalTaxAction;
158
+ export type InvoiceActions = InvoiceAddItemProductAction | InvoiceAddItemServiceAction | InvoiceClearErrorAction | InvoiceDeleteItemProductAction | InvoiceDeleteItemServiceAction | InvoiceResetFormAction | InvoiceSetButtonDisableAction | InvoiceSetCurrentPageAction | InvoiceSetCustomerDataAction | InvoiceSetDiscountUnitAction | InvoiceSetErrorsAction | InvoiceSetFormLoadingAction | InvoiceSetInvoicesAction | InvoiceSetInvoiceFormAction | InvoiceSetIsInvoiceApiSuccessAction | InvoiceSetMaxPageLimitAction | InvoiceSetSearchQueryAction | InvoiceUpdateFieldAction | InvoiceToggleLoadingAction | InvoiceSetDrawerAction | InvoiceSetCountAction | InvoiceSetFormAction | InvoiceSetAfterDiscountAction | InvoiceSetTaxAction;
@@ -26,6 +26,6 @@ var INVOICE_ACTION_TYPES;
26
26
  INVOICE_ACTION_TYPES["SET_COUNT"] = "SET_COUNT";
27
27
  INVOICE_ACTION_TYPES["SET_FORM"] = "SET_FORM";
28
28
  INVOICE_ACTION_TYPES["SET_DISABLE_SAVE_BUTTON"] = "SET_DISABLE_SAVE_BUTTON";
29
- INVOICE_ACTION_TYPES["SET_TOTAL_DISCOUNT"] = "SET_TOTAL_DISCOUNT";
30
- INVOICE_ACTION_TYPES["SET_TOTAL_TAX"] = "SET_TOTAL_TAX";
29
+ INVOICE_ACTION_TYPES["SET_AFTER_DISCOUNT"] = "SET_AFTER_DISCOUNT";
30
+ INVOICE_ACTION_TYPES["SET_TAX"] = "SET_TAX";
31
31
  })(INVOICE_ACTION_TYPES || (exports.INVOICE_ACTION_TYPES = INVOICE_ACTION_TYPES = {}));
@@ -1,6 +1,8 @@
1
1
  import { DISCOUNT_UNIT } from "./types";
2
- export declare const calculateTotal: (subtotal: string, tax: string, discountUnit: DISCOUNT_UNIT, discount: string) => {
3
- totalTaxValue: string;
4
- totalDiscountValue: number;
2
+ interface Return {
3
+ afterDiscount: number;
4
+ tax: string;
5
5
  total: string;
6
- };
6
+ }
7
+ export declare const calculateTotal: (subtotal: string, taxRate: string, discountUnit: DISCOUNT_UNIT, discount: string) => Return;
8
+ export {};
@@ -2,22 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateTotal = void 0;
4
4
  var types_1 = require("./types");
5
- var calculateTotal = function (subtotal, tax, discountUnit, discount) {
5
+ var calculateTotal = function (subtotal, taxRate, discountUnit, discount) {
6
6
  var subtotalValue = parseFloat(subtotal || '0');
7
- var taxValue = ((subtotalValue * parseFloat(tax)) / 100).toFixed(2);
8
7
  var discountType = discountUnit;
9
8
  var discountValue = parseFloat(discount || '0');
10
9
  var discountedAmount = discountType === types_1.DISCOUNT_UNIT.PERCENTAGE_VALUE
11
10
  ? (subtotalValue * discountValue) / 100
12
11
  : discountValue;
13
- var totalTaxValue = taxValue;
14
- var totalDiscountValue = discountedAmount;
12
+ var afterDiscount = subtotalValue - discountedAmount;
13
+ var tax = ((afterDiscount * parseFloat(taxRate)) / 100).toFixed(2);
15
14
  var total = (subtotalValue +
16
- parseFloat(taxValue) -
15
+ parseFloat(tax) -
17
16
  discountedAmount).toFixed(2);
18
17
  return {
19
- totalTaxValue: totalTaxValue,
20
- totalDiscountValue: totalDiscountValue,
18
+ tax: tax,
19
+ afterDiscount: afterDiscount,
21
20
  total: total,
22
21
  };
23
22
  };
@@ -431,7 +431,7 @@ exports.tableBodyCols = [
431
431
  },
432
432
  {
433
433
  componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.TEXT,
434
- key: 'taxValue',
434
+ key: 'taxRate',
435
435
  },
436
436
  {
437
437
  componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.TEXT,
@@ -151,7 +151,7 @@ var useInvoiceState = function () {
151
151
  ref: state.ref,
152
152
  services: state.services,
153
153
  subTotal: state.subTotal,
154
- taxValue: state.taxValue,
154
+ taxRate: state.taxRate,
155
155
  total: state.total,
156
156
  mode: state.mode,
157
157
  }); }, [state]);
@@ -247,7 +247,7 @@ var useInvoiceState = function () {
247
247
  state.pageLimit,
248
248
  ]);
249
249
  (0, react_1.useEffect)(function () {
250
- var _a = (0, calculate_total_1.calculateTotal)(state.subTotal, state.taxValue, state.discountUnit, state.discount), totalTaxValue = _a.totalTaxValue, total = _a.total, totalDiscountValue = _a.totalDiscountValue;
250
+ var _a = (0, calculate_total_1.calculateTotal)(state.subTotal, state.taxRate, state.discountUnit, state.discount), afterDiscount = _a.afterDiscount, tax = _a.tax, total = _a.total;
251
251
  dispatch({
252
252
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
253
253
  payload: {
@@ -256,18 +256,18 @@ var useInvoiceState = function () {
256
256
  },
257
257
  });
258
258
  dispatch({
259
- type: actions_1.INVOICE_ACTION_TYPES.SET_TOTAL_TAX,
260
- payload: { totalTax: totalTaxValue },
259
+ type: actions_1.INVOICE_ACTION_TYPES.SET_TAX,
260
+ payload: { tax: tax },
261
261
  });
262
262
  dispatch({
263
- type: actions_1.INVOICE_ACTION_TYPES.SET_TOTAL_DISCOUNT,
264
- payload: { totalDiscount: String(totalDiscountValue) },
263
+ type: actions_1.INVOICE_ACTION_TYPES.SET_AFTER_DISCOUNT,
264
+ payload: { afterDiscount: String(afterDiscount) },
265
265
  });
266
266
  }, [
267
267
  state.discountUnit,
268
268
  state.discount,
269
269
  state.subTotal,
270
- state.taxValue,
270
+ state.taxRate,
271
271
  ]);
272
272
  var handleAddItemService = function () {
273
273
  var newItem = {
@@ -394,7 +394,7 @@ var useInvoiceState = function () {
394
394
  });
395
395
  }); }, [updateFetchNow, updatedParams]);
396
396
  var handleChange = (0, react_1.useCallback)(function (key, value) {
397
- if (key === 'taxValue') {
397
+ if (key === 'taxRate') {
398
398
  dispatch({
399
399
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
400
400
  payload: {
@@ -637,8 +637,8 @@ var useInvoiceState = function () {
637
637
  textElements[1].value = state.discount;
638
638
  textElements[1].error = (_c = state.errors) === null || _c === void 0 ? void 0 : _c.discount;
639
639
  textElements[1].handleOnChange = handleChange;
640
- textElements[2].value = state.totalDiscount ? String(state.totalDiscount) : '0';
641
- textElements[3].value = isNaN(Number(state.totalTax)) ? '0' : state.totalTax;
640
+ textElements[2].value = state.afterDiscount ? String(state.afterDiscount) : '0';
641
+ textElements[3].value = isNaN(Number(state.tax)) ? '0' : state.tax;
642
642
  textElements[4].value = isNaN(Number(state.total))
643
643
  ? '0'
644
644
  : String(state.total);
@@ -647,7 +647,7 @@ var useInvoiceState = function () {
647
647
  }
648
648
  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; });
649
649
  if (comboboxElements) {
650
- comboboxElements[0].selectedItem = { taxName: state.taxValue };
650
+ comboboxElements[0].selectedItem = { taxName: state.taxRate };
651
651
  comboboxElements[0].listItems = [];
652
652
  }
653
653
  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; });
@@ -63,10 +63,10 @@ exports.initialInvoiceState = {
63
63
  ref: '',
64
64
  searchQuery: '',
65
65
  subTotal: '',
66
- taxValue: '17',
66
+ taxRate: '17',
67
67
  total: '',
68
- totalDiscount: '0',
69
- totalTax: '',
68
+ afterDiscount: '0',
69
+ tax: '',
70
70
  company: {
71
71
  name: '',
72
72
  country: '',
@@ -138,10 +138,10 @@ function invoiceReducer(state, action) {
138
138
  // };
139
139
  case actions_1.INVOICE_ACTION_TYPES.SET_DISCOUNT_UNIT:
140
140
  return __assign(__assign({}, state), { discountUnit: action.payload.discountUnit });
141
- case actions_1.INVOICE_ACTION_TYPES.SET_TOTAL_DISCOUNT:
142
- return __assign(__assign({}, state), { totalDiscount: action.payload.totalDiscount });
143
- case actions_1.INVOICE_ACTION_TYPES.SET_TOTAL_TAX:
144
- return __assign(__assign({}, state), { totalTax: action.payload.totalTax });
141
+ case actions_1.INVOICE_ACTION_TYPES.SET_AFTER_DISCOUNT:
142
+ return __assign(__assign({}, state), { afterDiscount: action.payload.afterDiscount });
143
+ case actions_1.INVOICE_ACTION_TYPES.SET_TAX:
144
+ return __assign(__assign({}, state), { tax: action.payload.tax });
145
145
  case actions_1.INVOICE_ACTION_TYPES.ADD_ITEM_SERVICE:
146
146
  return __assign(__assign({}, state), { services: __spreadArray([], action.payload.services, true) });
147
147
  case actions_1.INVOICE_ACTION_TYPES.ADD_ITEM_PRODUCT:
@@ -114,7 +114,7 @@ export interface InvoiceTypeBE {
114
114
  ref: string;
115
115
  services: Service[];
116
116
  subTotal: string;
117
- taxValue: string;
117
+ taxRate: string;
118
118
  total: string;
119
119
  updatedAt: string;
120
120
  }
@@ -143,8 +143,8 @@ export interface InvoiceState extends Omit<InvoiceTypeBE, 'createdAt' | 'updated
143
143
  phone: string;
144
144
  products: Product[];
145
145
  searchQuery: string;
146
- totalDiscount: string;
147
- totalTax: string;
146
+ afterDiscount: string;
147
+ tax: string;
148
148
  }
149
149
  export interface FetchInvoicesArgs {
150
150
  currentPage: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/stellar-solutions-invoice-module",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "scripts": {
5
5
  "build": "yarn clean && yarn build:ts && cp package.json lib && cp README.md lib",
6
6
  "build:next": "next build",
@@ -26,7 +26,7 @@
26
26
  "@eslint/eslintrc": "^3",
27
27
  "@headlessui/react": "^2.2.0",
28
28
  "@heroicons/react": "^2.2.0",
29
- "@react-pakistan/util-functions": "^1.24.19",
29
+ "@react-pakistan/util-functions": "^1.24.21",
30
30
  "@supabase/supabase-js": "^2.50.0",
31
31
  "@tailwindcss/forms": "^0.5.10",
32
32
  "@tailwindcss/postcss": "^4",