@appcorp/stellar-solutions-invoice-module 0.1.25 → 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.
- package/base-modules/invoice/actions.d.ts +9 -9
- package/base-modules/invoice/actions.js +2 -2
- package/base-modules/invoice/calculate-total.d.ts +6 -4
- package/base-modules/invoice/calculate-total.js +6 -7
- package/base-modules/invoice/constants.js +1 -1
- package/base-modules/invoice/context.js +11 -11
- package/base-modules/invoice/reducer.js +7 -7
- package/base-modules/invoice/types.d.ts +3 -3
- package/package.json +1 -1
|
@@ -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
|
-
|
|
27
|
-
|
|
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
|
|
147
|
-
type: INVOICE_ACTION_TYPES.
|
|
146
|
+
export type InvoiceSetAfterDiscountAction = {
|
|
147
|
+
type: INVOICE_ACTION_TYPES.SET_AFTER_DISCOUNT;
|
|
148
148
|
payload: {
|
|
149
|
-
|
|
149
|
+
afterDiscount: string;
|
|
150
150
|
};
|
|
151
151
|
};
|
|
152
|
-
export type
|
|
153
|
-
type: INVOICE_ACTION_TYPES.
|
|
152
|
+
export type InvoiceSetTaxAction = {
|
|
153
|
+
type: INVOICE_ACTION_TYPES.SET_TAX;
|
|
154
154
|
payload: {
|
|
155
|
-
|
|
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 |
|
|
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["
|
|
30
|
-
INVOICE_ACTION_TYPES["
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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,
|
|
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
|
|
14
|
-
var
|
|
12
|
+
var afterDiscount = subtotalValue - discountedAmount;
|
|
13
|
+
var tax = ((afterDiscount * parseFloat(taxRate)) / 100).toFixed(2);
|
|
15
14
|
var total = (subtotalValue +
|
|
16
|
-
parseFloat(
|
|
15
|
+
parseFloat(tax) -
|
|
17
16
|
discountedAmount).toFixed(2);
|
|
18
17
|
return {
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
tax: tax,
|
|
19
|
+
afterDiscount: afterDiscount,
|
|
21
20
|
total: total,
|
|
22
21
|
};
|
|
23
22
|
};
|
|
@@ -151,7 +151,7 @@ var useInvoiceState = function () {
|
|
|
151
151
|
ref: state.ref,
|
|
152
152
|
services: state.services,
|
|
153
153
|
subTotal: state.subTotal,
|
|
154
|
-
|
|
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.
|
|
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.
|
|
260
|
-
payload: {
|
|
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.
|
|
264
|
-
payload: {
|
|
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.
|
|
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 === '
|
|
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.
|
|
641
|
-
textElements[3].value = isNaN(Number(state.
|
|
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.
|
|
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
|
-
|
|
66
|
+
taxRate: '17',
|
|
67
67
|
total: '',
|
|
68
|
-
|
|
69
|
-
|
|
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.
|
|
142
|
-
return __assign(__assign({}, state), {
|
|
143
|
-
case actions_1.INVOICE_ACTION_TYPES.
|
|
144
|
-
return __assign(__assign({}, state), {
|
|
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
|
-
|
|
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
|
-
|
|
147
|
-
|
|
146
|
+
afterDiscount: string;
|
|
147
|
+
tax: string;
|
|
148
148
|
}
|
|
149
149
|
export interface FetchInvoicesArgs {
|
|
150
150
|
currentPage: number;
|