add vat to tax calculations
This commit is contained in:
@@ -662,15 +662,26 @@ export const {
|
||||
} = orderSlice.actions;
|
||||
|
||||
// Tax calculation helper functions
|
||||
const calculateTaxAmount = (amount: number, tax: Tax): number => {
|
||||
const calculateTaxAmount = (
|
||||
state: RootState,
|
||||
amount: number,
|
||||
tax: Tax,
|
||||
): number => {
|
||||
const percentage = parseFloat(tax.percentage);
|
||||
return (percentage * amount) / 100;
|
||||
return (((state.order.restaurant?.vat || 0) + percentage) * amount) / 100;
|
||||
};
|
||||
|
||||
const calculateTotalTax = (subtotal: number, taxes: Tax[]): number => {
|
||||
const calculateTotalTax = (
|
||||
state: RootState,
|
||||
subtotal: number,
|
||||
taxes: Tax[],
|
||||
): number => {
|
||||
return taxes
|
||||
.filter((tax) => tax.is_active === 1)
|
||||
.reduce((total, tax) => total + calculateTaxAmount(subtotal, tax), 0);
|
||||
.reduce(
|
||||
(total, tax) => total + calculateTaxAmount(state, subtotal, tax),
|
||||
0,
|
||||
);
|
||||
};
|
||||
|
||||
// Selectors
|
||||
@@ -742,7 +753,7 @@ export const selectTaxes = (state: RootState) => state.order.restaurant.taxes;
|
||||
export const selectTaxAmount = (state: RootState) => {
|
||||
const subtotal = selectCartTotal(state) - selectDiscountTotal(state);
|
||||
const taxes = selectTaxes(state);
|
||||
return calculateTotalTax(subtotal, taxes || []);
|
||||
return calculateTotalTax(state, subtotal, taxes || []);
|
||||
};
|
||||
|
||||
export const selectGrandTotal = (state: RootState) => {
|
||||
|
||||
Reference in New Issue
Block a user