add vat to tax calculations

This commit is contained in:
2025-11-17 00:28:44 +03:00
parent 8263be3ae3
commit c9a7cc1b0e
3 changed files with 27 additions and 10 deletions

View File

@@ -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) => {