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 { Divider } from "@scandic-hotels/design-system/Divider"
|
||||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||||
|
|
||||||
|
import { calculateVat } from "@/components/HotelReservation/utils"
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
|
|
||||||
import styles from "./specification.module.css"
|
import styles from "./specification.module.css"
|
||||||
@@ -51,9 +52,10 @@ export default async function Specification({
|
|||||||
(p) => p.code === RoomPackageCodeEnum.PET_ROOM
|
(p) => p.code === RoomPackageCodeEnum.PET_ROOM
|
||||||
)
|
)
|
||||||
|
|
||||||
const roomPriceExclVat =
|
const { vatAmount, priceExclVat } = calculateVat(
|
||||||
booking.roomPrice - (booking.roomPrice * booking.vatPercentage) / 100
|
booking.roomPrice,
|
||||||
const roomPriceVat = booking.roomPrice - roomPriceExclVat
|
booking.vatPercentage
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
@@ -121,7 +123,7 @@ export default async function Specification({
|
|||||||
<Typography variant="Body/Supporting text (caption)/smRegular">
|
<Typography variant="Body/Supporting text (caption)/smRegular">
|
||||||
<dd className={styles.tertiary}>
|
<dd className={styles.tertiary}>
|
||||||
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
||||||
{`${roomPriceExclVat.toFixed(2)} ${currency}`}
|
{`${priceExclVat.toFixed(2)} ${currency}`}
|
||||||
</dd>
|
</dd>
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
@@ -137,7 +139,7 @@ export default async function Specification({
|
|||||||
<Typography variant="Body/Supporting text (caption)/smRegular">
|
<Typography variant="Body/Supporting text (caption)/smRegular">
|
||||||
<dd className={styles.tertiary}>
|
<dd className={styles.tertiary}>
|
||||||
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
||||||
{`${roomPriceVat.toFixed(2)} ${currency}`}
|
{`${vatAmount.toFixed(2)} ${currency}`}
|
||||||
</dd>
|
</dd>
|
||||||
</Typography>
|
</Typography>
|
||||||
</dl>
|
</dl>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
|
import { calculateVat } from "@/components/HotelReservation/utils"
|
||||||
import { formatPrice } from "@/utils/numberFormatting"
|
import { formatPrice } from "@/utils/numberFormatting"
|
||||||
|
|
||||||
import RegularRow from "./Regular"
|
import RegularRow from "./Regular"
|
||||||
@@ -27,10 +28,7 @@ export default function VatRow({ totalPrice, vat }: VatProps) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const vatPercentage = vat / 100
|
const { vatAmount, priceExclVat } = calculateVat(totalPrice.local.price, vat)
|
||||||
const vatAmount = totalPrice.local.price * vatPercentage
|
|
||||||
|
|
||||||
const priceExclVat = totalPrice.local.price - vatAmount
|
|
||||||
|
|
||||||
return (
|
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