add vat to tax calculations
This commit is contained in:
@@ -662,15 +662,26 @@ export const {
|
|||||||
} = orderSlice.actions;
|
} = orderSlice.actions;
|
||||||
|
|
||||||
// Tax calculation helper functions
|
// 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);
|
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
|
return taxes
|
||||||
.filter((tax) => tax.is_active === 1)
|
.filter((tax) => tax.is_active === 1)
|
||||||
.reduce((total, tax) => total + calculateTaxAmount(subtotal, tax), 0);
|
.reduce(
|
||||||
|
(total, tax) => total + calculateTaxAmount(state, subtotal, tax),
|
||||||
|
0,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Selectors
|
// Selectors
|
||||||
@@ -742,7 +753,7 @@ export const selectTaxes = (state: RootState) => state.order.restaurant.taxes;
|
|||||||
export const selectTaxAmount = (state: RootState) => {
|
export const selectTaxAmount = (state: RootState) => {
|
||||||
const subtotal = selectCartTotal(state) - selectDiscountTotal(state);
|
const subtotal = selectCartTotal(state) - selectDiscountTotal(state);
|
||||||
const taxes = selectTaxes(state);
|
const taxes = selectTaxes(state);
|
||||||
return calculateTotalTax(subtotal, taxes || []);
|
return calculateTotalTax(state, subtotal, taxes || []);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const selectGrandTotal = (state: RootState) => {
|
export const selectGrandTotal = (state: RootState) => {
|
||||||
|
|||||||
@@ -477,7 +477,7 @@
|
|||||||
.openingHours {
|
.openingHours {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 190px;
|
top: 190px;
|
||||||
right: 10px;
|
right: 16px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #666;
|
color: #666;
|
||||||
@@ -706,3 +706,10 @@
|
|||||||
left: 10px;
|
left: 10px;
|
||||||
right: auto;
|
right: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.timeIcon {
|
||||||
|
position: relative;
|
||||||
|
top: 4px;
|
||||||
|
margin: 0 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import MenuSkeleton from "./components/MenuSkeleton/MenuSkeleton";
|
|||||||
import ScrollEventHandler from "./components/ScrollEventHandler";
|
import ScrollEventHandler from "./components/ScrollEventHandler";
|
||||||
import SearchButton from "./components/SearchButton";
|
import SearchButton from "./components/SearchButton";
|
||||||
import styles from "./menu.module.css";
|
import styles from "./menu.module.css";
|
||||||
|
import TimeIcon from "components/Icons/order/TimeIcon";
|
||||||
|
|
||||||
function MenuPage() {
|
function MenuPage() {
|
||||||
const { subdomain } = useParams();
|
const { subdomain } = useParams();
|
||||||
@@ -128,10 +129,8 @@ function MenuPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ProText className={styles.openingHours}>
|
<ProText className={styles.openingHours}>
|
||||||
{t("menu.openingHours", {
|
<TimeIcon className={styles.timeIcon} />
|
||||||
openingTime: restaurant?.openingTime,
|
{restaurant?.openingTime} - {restaurant?.closingTime}
|
||||||
closingTime: restaurant?.closingTime,
|
|
||||||
})}
|
|
||||||
</ProText>
|
</ProText>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user