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

View File

@@ -477,7 +477,7 @@
.openingHours {
position: absolute;
top: 190px;
right: 10px;
right: 16px;
font-size: 14px;
font-weight: 600;
color: #666;
@@ -706,3 +706,10 @@
left: 10px;
right: auto;
}
.timeIcon {
position: relative;
top: 4px;
margin: 0 4px;
}

View File

@@ -29,6 +29,7 @@ import MenuSkeleton from "./components/MenuSkeleton/MenuSkeleton";
import ScrollEventHandler from "./components/ScrollEventHandler";
import SearchButton from "./components/SearchButton";
import styles from "./menu.module.css";
import TimeIcon from "components/Icons/order/TimeIcon";
function MenuPage() {
const { subdomain } = useParams();
@@ -128,10 +129,8 @@ function MenuPage() {
</div>
<ProText className={styles.openingHours}>
{t("menu.openingHours", {
openingTime: restaurant?.openingTime,
closingTime: restaurant?.closingTime,
})}
<TimeIcon className={styles.timeIcon} />
{restaurant?.openingTime} - {restaurant?.closingTime}
</ProText>
</div>
</div>