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
This commit is contained in:
@@ -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 (
|
||||
<div className={styles.container}>
|
||||
@@ -121,7 +123,7 @@ export default async function Specification({
|
||||
<Typography variant="Body/Supporting text (caption)/smRegular">
|
||||
<dd className={styles.tertiary}>
|
||||
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
||||
{`${roomPriceExclVat.toFixed(2)} ${currency}`}
|
||||
{`${priceExclVat.toFixed(2)} ${currency}`}
|
||||
</dd>
|
||||
</Typography>
|
||||
|
||||
@@ -137,7 +139,7 @@ export default async function Specification({
|
||||
<Typography variant="Body/Supporting text (caption)/smRegular">
|
||||
<dd className={styles.tertiary}>
|
||||
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
||||
{`${roomPriceVat.toFixed(2)} ${currency}`}
|
||||
{`${vatAmount.toFixed(2)} ${currency}`}
|
||||
</dd>
|
||||
</Typography>
|
||||
</dl>
|
||||
|
||||
@@ -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 (
|
||||
<>
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user