From 1802a391ecafa3b9f953c95b4d9e75b7c04fd8cd Mon Sep 17 00:00:00 2001 From: Arvid Norlin Date: Wed, 25 Jun 2025 11:56:30 +0000 Subject: [PATCH] Merged in fix/SW-2899 (pull request #2433) fix (SW-2899): correct VAT calculations * fix (SW-2899): correct VAT calculations * refactor: add calculateVat util Approved-by: Christian Andolf --- .../MyStay/Receipt/Specification/index.tsx | 12 +++++++----- .../PriceDetailsModal/PriceDetailsTable/Row/Vat.tsx | 6 ++---- .../components/HotelReservation/utils/index.tsx | 10 ++++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/apps/scandic-web/components/HotelReservation/MyStay/Receipt/Specification/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/Receipt/Specification/index.tsx index 91075cb22..02c0500ef 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/Receipt/Specification/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/Receipt/Specification/index.tsx @@ -1,6 +1,7 @@ import { Divider } from "@scandic-hotels/design-system/Divider" import { Typography } from "@scandic-hotels/design-system/Typography" +import { calculateVat } from "@/components/HotelReservation/utils" import { getIntl } from "@/i18n" import styles from "./specification.module.css" @@ -51,9 +52,10 @@ export default async function Specification({ (p) => p.code === RoomPackageCodeEnum.PET_ROOM ) - const roomPriceExclVat = - booking.roomPrice - (booking.roomPrice * booking.vatPercentage) / 100 - const roomPriceVat = booking.roomPrice - roomPriceExclVat + const { vatAmount, priceExclVat } = calculateVat( + booking.roomPrice, + booking.vatPercentage + ) return (
@@ -121,7 +123,7 @@ export default async function Specification({
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */} - {`${roomPriceExclVat.toFixed(2)} ${currency}`} + {`${priceExclVat.toFixed(2)} ${currency}`}
@@ -137,7 +139,7 @@ export default async function Specification({
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */} - {`${roomPriceVat.toFixed(2)} ${currency}`} + {`${vatAmount.toFixed(2)} ${currency}`}
diff --git a/apps/scandic-web/components/HotelReservation/PriceDetailsModal/PriceDetailsTable/Row/Vat.tsx b/apps/scandic-web/components/HotelReservation/PriceDetailsModal/PriceDetailsTable/Row/Vat.tsx index 1141d81b0..5e27fc94f 100644 --- a/apps/scandic-web/components/HotelReservation/PriceDetailsModal/PriceDetailsTable/Row/Vat.tsx +++ b/apps/scandic-web/components/HotelReservation/PriceDetailsModal/PriceDetailsTable/Row/Vat.tsx @@ -1,6 +1,7 @@ "use client" import { useIntl } from "react-intl" +import { calculateVat } from "@/components/HotelReservation/utils" import { formatPrice } from "@/utils/numberFormatting" import RegularRow from "./Regular" @@ -27,10 +28,7 @@ export default function VatRow({ totalPrice, vat }: VatProps) { return null } - const vatPercentage = vat / 100 - const vatAmount = totalPrice.local.price * vatPercentage - - const priceExclVat = totalPrice.local.price - vatAmount + const { vatAmount, priceExclVat } = calculateVat(totalPrice.local.price, vat) return ( <> diff --git a/apps/scandic-web/components/HotelReservation/utils/index.tsx b/apps/scandic-web/components/HotelReservation/utils/index.tsx index 7366d9e42..a6dc9b113 100644 --- a/apps/scandic-web/components/HotelReservation/utils/index.tsx +++ b/apps/scandic-web/components/HotelReservation/utils/index.tsx @@ -94,3 +94,13 @@ export function sumPackagesRequestedPrice(packages: Packages | null) { } ) } + +export function calculateVat(priceInclVat: number, vat: number) { + const vatPercentage = vat / 100 + const priceExclVat = priceInclVat / (1 + vatPercentage) + const vatAmount = priceInclVat - priceExclVat + return { + priceExclVat, + vatAmount, + } +}