diff --git a/src/assets/locals/ar.json b/src/assets/locals/ar.json index b1dea44..b0a6ad7 100644 --- a/src/assets/locals/ar.json +++ b/src/assets/locals/ar.json @@ -287,8 +287,8 @@ "cannotSelectPastDate": "لا يمكنك اختيار تاريخ سابق. يرجى اختيار اليوم أو تاريخ مستقبلي.", "checkRequiredFields": "يرجى التحقق من الحقول المطلوبة", "loyalty": "ولاء", - "vatTax": "ضريبة (القيمة المضافة)", - "otherTaxes": "ضريبة (أخرى)" + "vat": "ضريبة القيمة المضافة ({{value}}%))", + "otherTaxes": "{{name}} ({{value}}%)" }, "checkout": { "addCarDetails": "إضافة تفاصيل السيارة", @@ -333,7 +333,8 @@ "change": "تغيير", "pickup": "استلام", "setPickupTime": "تحديد وقت الاستلام", - "carPlateNumber": "رقم لوحة السيارة" + "carPlateNumber": "رقم لوحة السيارة", + "noItems": "لا يوجد عناصر في السلة" }, "address": { "title": "العنوان", diff --git a/src/assets/locals/en.json b/src/assets/locals/en.json index 43996f4..b2f0de4 100644 --- a/src/assets/locals/en.json +++ b/src/assets/locals/en.json @@ -304,8 +304,8 @@ "checkRequiredFields": "Please check required fields", "applyYourAvailableRewardsToGetDiscountsOnItemsInYourCart": "Apply your available rewards to get discounts on items in your cart", "loyalty": "Loyalty", - "vatTax": "Tax (Vat)", - "otherTaxes": "Tax (Other)" + "vat": "Vat ({{value}}%)", + "otherTaxes": "{{name}} ({{value}}%)" }, "checkout": { "addCarDetails": "Add Car Details", @@ -352,7 +352,8 @@ "change": "Change", "pickup": "Pickup", "setPickupTime": "Set Pickup Time", - "carPlateNumber": "Car Plate Number" + "carPlateNumber": "Car Plate Number", + "noItems": "No items in cart" }, "address": { "title": "Address", diff --git a/src/components/OrderSummary/OrderSummary.tsx b/src/components/OrderSummary/OrderSummary.tsx index 3dae530..e721340 100644 --- a/src/components/OrderSummary/OrderSummary.tsx +++ b/src/components/OrderSummary/OrderSummary.tsx @@ -1,4 +1,4 @@ -import { Card, Checkbox, Divider, Space, Tag } from "antd"; +import { Card, Divider, Space, Tag } from "antd"; import ArabicPrice from "components/ArabicPrice"; import { selectCart, @@ -6,7 +6,6 @@ import { selectDiscountTotal, selectGrandTotal, selectHighestPricedLoyaltyItem, - selectTaxAmount, } from "features/order/orderSlice"; import { OrderType } from "pages/checkout/hooks/types"; import { useTranslation } from "react-i18next"; @@ -16,7 +15,7 @@ import { useAppSelector } from "redux/hooks"; import ProText from "../ProText"; import ProTitle from "../ProTitle"; import styles from "./OrderSummary.module.css"; -import { CSSProperties } from "react"; +import { CSSProperties, useMemo } from "react"; export default function OrderSummary() { const { t } = useTranslation(); @@ -26,7 +25,6 @@ export default function OrderSummary() { const { orderType } = useAppSelector(selectCart); const subtotal = useAppSelector(selectCartTotal); const highestLoyaltyItem = useAppSelector(selectHighestPricedLoyaltyItem); - const taxAmount = useAppSelector(selectTaxAmount); const grandTotal = useAppSelector(selectGrandTotal); const discountAmount = useAppSelector(selectDiscountTotal); @@ -44,7 +42,27 @@ export default function OrderSummary() { textAlign: "center", }; - const vat = ((restaurant?.vat ?? 0) / 100) * subtotal || 0; + const vat = ((restaurant?.vat ?? 0) / 100) * (subtotal - discountAmount) || 0; + + // Calculate individual taxes + const taxesList = useMemo(() => { + if (!restaurant?.taxes) return []; + + const subtotalAfterDiscount = subtotal - discountAmount; + + return restaurant.taxes + .filter((tax) => tax.is_active === 1) + .map((tax) => { + const amount = ((Number(tax.percentage) || 0) / 100) * subtotalAfterDiscount; + return { + id: tax.id, + name: tax.name, + name_local: tax.name_local, + percentage: tax.percentage, + amount, + }; + }); + }, [restaurant?.taxes, subtotal, discountAmount]); return ( <> @@ -156,10 +174,10 @@ export default function OrderSummary() { /> )} - {orderType !== OrderType.Redeem && ( + {orderType !== OrderType.Redeem && restaurant?.vat && (