fix: make sure calculations in booking flow are correct
This commit is contained in:
committed by
Michael Zetterberg
parent
3e0f503314
commit
a222ecfc5c
@@ -75,6 +75,9 @@ export default function PriceDetailsModal() {
|
||||
return null
|
||||
}
|
||||
|
||||
const checkInDate = dt(fromDate).format("YYYY-MM-DD")
|
||||
const checkOutDate = dt(toDate).format("YYYY-MM-DD")
|
||||
|
||||
const bookingTotal = rooms.reduce(
|
||||
(acc, room) => {
|
||||
if (room) {
|
||||
@@ -89,7 +92,7 @@ export default function PriceDetailsModal() {
|
||||
{ price: 0, priceExVat: 0, vatAmount: 0 }
|
||||
)
|
||||
|
||||
const diff = dt(toDate).diff(fromDate, "days")
|
||||
const diff = dt(checkOutDate).diff(checkInDate, "days")
|
||||
const nights = intl.formatMessage(
|
||||
{ id: "{totalNights, plural, one {# night} other {# nights}}" },
|
||||
{ totalNights: diff }
|
||||
|
||||
@@ -163,21 +163,23 @@ export default function ReceiptRoom({
|
||||
</Body>
|
||||
</div>
|
||||
) : null}
|
||||
<div className={styles.entry}>
|
||||
<Body>{intl.formatMessage({ id: "Breakfast buffet" })}</Body>
|
||||
{(room.rateDefinition.breakfastIncluded ?? room.breakfastIncluded) ? (
|
||||
<Body color="red">{intl.formatMessage({ id: "Included" })}</Body>
|
||||
) : null}
|
||||
{room.breakfast ? (
|
||||
<Body color="uiTextHighContrast">
|
||||
{formatPrice(
|
||||
intl,
|
||||
room.breakfast.totalPrice * room.adults,
|
||||
room.breakfast.currency
|
||||
)}
|
||||
</Body>
|
||||
) : null}
|
||||
</div>
|
||||
{room.breakfast || room.breakfastIncluded ? (
|
||||
<div className={styles.entry}>
|
||||
<Body>{intl.formatMessage({ id: "Breakfast buffet" })}</Body>
|
||||
{(room.rateDefinition.breakfastIncluded ?? room.breakfastIncluded) ? (
|
||||
<Body color="red">{intl.formatMessage({ id: "Included" })}</Body>
|
||||
) : null}
|
||||
{room.breakfast ? (
|
||||
<Body color="uiTextHighContrast">
|
||||
{formatPrice(
|
||||
intl,
|
||||
room.breakfast.totalPrice,
|
||||
room.breakfast.currency
|
||||
)}
|
||||
</Body>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</article>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
type TrackingSDKPaymentInfo,
|
||||
} from "@/types/components/tracking"
|
||||
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||
import { RateEnum } from "@/types/enums/rate"
|
||||
import type { Room } from "@/types/stores/booking-confirmation"
|
||||
import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation"
|
||||
import type { RateDefinition } from "@/types/trpc/routers/hotel/roomAvailability"
|
||||
@@ -19,11 +20,11 @@ import type { Lang } from "@/constants/languages"
|
||||
function getRate(cancellationRule: RateDefinition["cancellationRule"] | null) {
|
||||
switch (cancellationRule) {
|
||||
case "CancellableBefore6PM":
|
||||
return "flex"
|
||||
return RateEnum.flex
|
||||
case "Changeable":
|
||||
return "change"
|
||||
return RateEnum.change
|
||||
case "NotCancellable":
|
||||
return "save"
|
||||
return RateEnum.save
|
||||
default:
|
||||
return "-"
|
||||
}
|
||||
|
||||
@@ -42,13 +42,11 @@ export default function Breakfast() {
|
||||
: undefined
|
||||
|
||||
const methods = useForm<BreakfastFormSchema>({
|
||||
defaultValues: breakfastSelection
|
||||
? { breakfast: breakfastSelection }
|
||||
: undefined,
|
||||
criteriaMode: "all",
|
||||
mode: "all",
|
||||
resolver: zodResolver(breakfastFormSchema),
|
||||
reValidateMode: "onChange",
|
||||
values: breakfastSelection ? { breakfast: breakfastSelection } : undefined,
|
||||
})
|
||||
|
||||
const onSubmit = useCallback(
|
||||
|
||||
@@ -28,6 +28,14 @@ import styles from "./ui.module.css"
|
||||
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
|
||||
import type { RoomRate } from "@/types/components/hotelReservation/enterDetails/details"
|
||||
import type { EnterDetailsSummaryProps } from "@/types/components/hotelReservation/summary"
|
||||
import { CurrencyEnum } from "@/types/enums/currency"
|
||||
|
||||
const notDisplayableCurrencies = [
|
||||
CurrencyEnum.CC,
|
||||
CurrencyEnum.POINTS,
|
||||
CurrencyEnum.Voucher,
|
||||
CurrencyEnum.Unknown,
|
||||
]
|
||||
|
||||
export default function SummaryUI({
|
||||
booking,
|
||||
@@ -81,6 +89,10 @@ export default function SummaryUI({
|
||||
"redemption" in roomOneRoomRate ||
|
||||
"voucher" in roomOneRoomRate
|
||||
|
||||
const isSameCurrency = totalPrice.requested
|
||||
? totalPrice.requested.currency === totalPrice.local.currency
|
||||
: false
|
||||
|
||||
return (
|
||||
<section className={styles.summary}>
|
||||
<header className={styles.header}>
|
||||
@@ -160,6 +172,10 @@ export default function SummaryUI({
|
||||
guestsParts.push(childrenMsg)
|
||||
}
|
||||
|
||||
const hideBedCurrency = notDisplayableCurrencies.includes(
|
||||
room.roomPrice.perStay.local.currency
|
||||
)
|
||||
|
||||
return (
|
||||
<Fragment key={idx}>
|
||||
<div
|
||||
@@ -262,7 +278,9 @@ export default function SummaryUI({
|
||||
{formatPrice(
|
||||
intl,
|
||||
0,
|
||||
room.roomPrice.perStay.local.currency
|
||||
hideBedCurrency
|
||||
? ""
|
||||
: room.roomPrice.perStay.local.currency
|
||||
)}
|
||||
</Body>
|
||||
</div>
|
||||
@@ -418,7 +436,7 @@ export default function SummaryUI({
|
||||
)}
|
||||
</Caption>
|
||||
) : null}
|
||||
{totalPrice.requested && !isSpecialRate && (
|
||||
{totalPrice.requested && !isSpecialRate && !isSameCurrency && (
|
||||
<Caption color="uiTextMediumContrast">
|
||||
{intl.formatMessage(
|
||||
{ id: "Approx. {value}" },
|
||||
|
||||
@@ -31,7 +31,7 @@ import styles from "./rateSummary.module.css"
|
||||
import type { Price } from "@/types/components/hotelReservation/price"
|
||||
import type { RateSummaryProps } from "@/types/components/hotelReservation/selectRate/rateSummary"
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import type { Rate } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||
import { RateEnum } from "@/types/enums/rate"
|
||||
import { RateTypeEnum } from "@/types/enums/rateType"
|
||||
|
||||
export default function RateSummary({ isUserLoggedIn }: RateSummaryProps) {
|
||||
@@ -111,13 +111,13 @@ export default function RateSummary({ isUserLoggedIn }: RateSummaryProps) {
|
||||
const payLater = intl.formatMessage({ id: "Pay later" })
|
||||
const payNow = intl.formatMessage({ id: "Pay now" })
|
||||
|
||||
function getRateDetails(rate: Rate["rate"]) {
|
||||
function getRateDetails(rate: RateEnum) {
|
||||
switch (rate) {
|
||||
case "change":
|
||||
case RateEnum.change:
|
||||
return `${freeBooking}, ${payNow}`
|
||||
case "flex":
|
||||
case RateEnum.flex:
|
||||
return `${freeCancelation}, ${payLater}`
|
||||
case "save":
|
||||
case RateEnum.save:
|
||||
default:
|
||||
return `${nonRefundable}, ${payNow}`
|
||||
}
|
||||
@@ -243,19 +243,29 @@ export default function RateSummary({ isUserLoggedIn }: RateSummaryProps) {
|
||||
total,
|
||||
{ features, packages: roomPackages, product }
|
||||
) => {
|
||||
if (!("member" in product) || !product.member) {
|
||||
return total
|
||||
}
|
||||
const memberPrice =
|
||||
product.member.localPrice.pricePerStay
|
||||
if (!memberPrice) {
|
||||
const memberExists =
|
||||
"member" in product && product.member
|
||||
const publicExists =
|
||||
"public" in product && product.public
|
||||
if (!memberExists) {
|
||||
if (!publicExists) {
|
||||
return total
|
||||
}
|
||||
}
|
||||
|
||||
const price =
|
||||
product.member?.localPrice.pricePerStay ||
|
||||
product.public?.localPrice.pricePerStay
|
||||
|
||||
if (!price) {
|
||||
return total
|
||||
}
|
||||
|
||||
const hasSelectedPetRoom = roomPackages.includes(
|
||||
RoomPackageCodeEnum.PET_ROOM
|
||||
)
|
||||
if (!hasSelectedPetRoom) {
|
||||
return total + memberPrice
|
||||
return total + price
|
||||
}
|
||||
const isPetRoom = features.find(
|
||||
(feature) =>
|
||||
@@ -265,7 +275,7 @@ export default function RateSummary({ isUserLoggedIn }: RateSummaryProps) {
|
||||
isPetRoom && petRoomPackage
|
||||
? Number(petRoomPackage.localPrice.totalPrice)
|
||||
: 0
|
||||
return total + memberPrice + petRoomPrice
|
||||
return total + price + petRoomPrice
|
||||
},
|
||||
0
|
||||
),
|
||||
|
||||
@@ -34,24 +34,32 @@ export function calculateTotalPrice(
|
||||
const isPetRoom = room.features.find(
|
||||
(feature) => feature.code === RoomPackageCodeEnum.PET_ROOM
|
||||
)
|
||||
let petRoomPrice = 0
|
||||
let petRoomPriceLocal = 0
|
||||
if (
|
||||
petRoomPackage &&
|
||||
isPetRoom &&
|
||||
room.packages.includes(RoomPackageCodeEnum.PET_ROOM)
|
||||
) {
|
||||
petRoomPrice = Number(petRoomPackage.localPrice.totalPrice)
|
||||
petRoomPriceLocal = Number(petRoomPackage.localPrice.totalPrice)
|
||||
}
|
||||
let petRoomPriceRequested = 0
|
||||
if (
|
||||
petRoomPackage &&
|
||||
isPetRoom &&
|
||||
room.packages.includes(RoomPackageCodeEnum.PET_ROOM)
|
||||
) {
|
||||
petRoomPriceRequested = Number(petRoomPackage.requestedPrice.totalPrice)
|
||||
}
|
||||
|
||||
total.local.currency = rate.localPrice.currency
|
||||
total.local.price =
|
||||
total.local.price + rate.localPrice.pricePerStay + petRoomPrice
|
||||
total.local.price + rate.localPrice.pricePerStay + petRoomPriceLocal
|
||||
|
||||
if (rate.localPrice.regularPricePerStay) {
|
||||
total.local.regularPrice =
|
||||
(total.local.regularPrice || 0) +
|
||||
rate.localPrice.regularPricePerStay +
|
||||
petRoomPrice
|
||||
petRoomPriceLocal
|
||||
}
|
||||
|
||||
if (rate.requestedPrice) {
|
||||
@@ -69,13 +77,13 @@ export function calculateTotalPrice(
|
||||
total.requested.price =
|
||||
total.requested.price +
|
||||
rate.requestedPrice.pricePerStay +
|
||||
petRoomPrice
|
||||
petRoomPriceRequested
|
||||
|
||||
if (rate.requestedPrice.regularPricePerStay) {
|
||||
total.requested.regularPrice =
|
||||
(total.requested.regularPrice || 0) +
|
||||
rate.requestedPrice.regularPricePerStay +
|
||||
petRoomPrice
|
||||
petRoomPriceRequested
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ import { useRoomContext } from "@/contexts/SelectRate/Room"
|
||||
|
||||
import styles from "./selectedRoomPanel.module.css"
|
||||
|
||||
import type { Rate } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||
import { CurrencyEnum } from "@/types/enums/currency"
|
||||
import { RateEnum } from "@/types/enums/rate"
|
||||
|
||||
export default function SelectedRoomPanel() {
|
||||
const intl = useIntl()
|
||||
@@ -43,13 +43,13 @@ export default function SelectedRoomPanel() {
|
||||
const payLater = intl.formatMessage({ id: "Pay later" })
|
||||
const payNow = intl.formatMessage({ id: "Pay now" })
|
||||
|
||||
function getRateTitle(rate: Rate["rate"]) {
|
||||
function getRateTitle(rate: RateEnum) {
|
||||
switch (rate) {
|
||||
case "change":
|
||||
case RateEnum.change:
|
||||
return `${freeBooking}, ${payNow}`
|
||||
case "flex":
|
||||
case RateEnum.flex:
|
||||
return `${freeCancelation}, ${payLater}`
|
||||
case "save":
|
||||
case RateEnum.save:
|
||||
default:
|
||||
return `${nonRefundable}, ${payNow}`
|
||||
}
|
||||
|
||||
@@ -27,5 +27,5 @@ export function getBreakfastMessage(
|
||||
return msgs.notIncluded
|
||||
}
|
||||
|
||||
return msgs.noSelection
|
||||
return msgs.notIncluded
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import { useIntl } from "react-intl"
|
||||
import CampaignRateCard from "@scandic-hotels/design-system/CampaignRateCard"
|
||||
import NoRateAvailableCard from "@scandic-hotels/design-system/NoRateAvailableCard"
|
||||
|
||||
import { useRatesStore } from "@/stores/select-rate"
|
||||
|
||||
import { useRoomContext } from "@/contexts/SelectRate/Room"
|
||||
import useRateTitles from "@/hooks/booking/useRateTitles"
|
||||
|
||||
@@ -30,7 +28,6 @@ export default function Campaign({
|
||||
const intl = useIntl()
|
||||
const { roomAvailability, roomNr, selectedFilter, selectedRate } =
|
||||
useRoomContext()
|
||||
const bookingCode = useRatesStore((state) => state.booking.bookingCode)
|
||||
const rateTitles = useRateTitles()
|
||||
|
||||
let isCampaignRate = false
|
||||
@@ -85,11 +82,11 @@ export default function Campaign({
|
||||
)
|
||||
|
||||
let bannerText = intl.formatMessage({ id: "Campaign" })
|
||||
if (bookingCode) {
|
||||
bannerText = bookingCode
|
||||
if (product.bookingCode) {
|
||||
bannerText = product.bookingCode
|
||||
}
|
||||
|
||||
if (product.rateDefinition?.breakfastIncluded) {
|
||||
if (product.rateDefinition.breakfastIncluded) {
|
||||
bannerText = `${bannerText} ∙ ${intl.formatMessage({ id: "Breakfast included" })}`
|
||||
} else {
|
||||
bannerText = `${bannerText} ∙ ${intl.formatMessage({ id: "Breakfast excluded" })}`
|
||||
|
||||
@@ -38,7 +38,7 @@ export default function Code({
|
||||
|
||||
return code.map((product) => {
|
||||
let bannerText = ""
|
||||
if (product.breakfastIncluded) {
|
||||
if (product.rateDefinition.breakfastIncluded) {
|
||||
bannerText = `${bookingCode} ∙ ${intl.formatMessage({ id: "Breakfast included" })}`
|
||||
} else {
|
||||
bannerText = `${bookingCode} ∙ ${intl.formatMessage({ id: "Breakfast excluded" })}`
|
||||
@@ -141,12 +141,13 @@ export default function Code({
|
||||
petRoomPackage
|
||||
)
|
||||
|
||||
const comparisonRate = regularPricePerNight.totalPrice
|
||||
? {
|
||||
price: regularPricePerNight.totalPrice,
|
||||
unit: localPrice.currency,
|
||||
}
|
||||
: undefined
|
||||
const comparisonRate =
|
||||
+regularPricePerNight.totalPrice > +pricePerNight.totalPrice
|
||||
? {
|
||||
price: regularPricePerNight.totalPrice,
|
||||
unit: localPrice.currency,
|
||||
}
|
||||
: undefined
|
||||
|
||||
const isSelected = isSelectedPriceProduct(
|
||||
product,
|
||||
|
||||
@@ -72,7 +72,7 @@ export default function Redemptions({
|
||||
|
||||
const notEnoughPoints = rates.every((rate) => rate.isDisabled)
|
||||
const firstRedemption = redemptions[0]
|
||||
const bannerText = firstRedemption.breakfastIncluded
|
||||
const bannerText = firstRedemption.rateDefinition.breakfastIncluded
|
||||
? `${rewardNight} ∙ ${breakfastIncluded}`
|
||||
: `${rewardNight} ∙ ${breakfastExcluded}`
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ export default function Regular({
|
||||
unit: `${standard!.localPrice.currency}/${night}`,
|
||||
}
|
||||
|
||||
if (standardPricePerNight.totalRequestedPrice) {
|
||||
if (standardPricePerNight.totalRequestedPrice && !isUserLoggedIn) {
|
||||
approximateStandardRatePrice = standardPricePerNight.totalRequestedPrice
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,34 +10,29 @@ export function isSelectedPriceProduct(
|
||||
selectedRate: SelectedRate | null,
|
||||
roomTypeCode: string
|
||||
) {
|
||||
if (!selectedRate) {
|
||||
if (!selectedRate || roomTypeCode !== selectedRate.roomTypeCode) {
|
||||
return false
|
||||
}
|
||||
|
||||
const { member, public: standard } = product
|
||||
let selectedRateMember: PriceProduct["member"] = null
|
||||
if ("member" in selectedRate.product) {
|
||||
selectedRateMember = selectedRate.product.member
|
||||
let isSelected = false
|
||||
if (
|
||||
"member" in selectedRate.product &&
|
||||
selectedRate.product.member &&
|
||||
member
|
||||
) {
|
||||
isSelected = selectedRate.product.member.rateCode === member.rateCode
|
||||
}
|
||||
|
||||
let selectedRatePublic: PriceProduct["public"] = null
|
||||
if ("public" in selectedRate.product) {
|
||||
selectedRatePublic = selectedRate.product.public
|
||||
if (
|
||||
"public" in selectedRate.product &&
|
||||
selectedRate.product.public &&
|
||||
standard
|
||||
) {
|
||||
isSelected = selectedRate.product.public.rateCode === standard.rateCode
|
||||
}
|
||||
|
||||
const selectedRateIsMember =
|
||||
member &&
|
||||
selectedRateMember &&
|
||||
member.rateCode === selectedRateMember.rateCode
|
||||
|
||||
const selectedRateIsPublic =
|
||||
standard &&
|
||||
selectedRatePublic &&
|
||||
standard.rateCode === selectedRatePublic.rateCode
|
||||
return !!(
|
||||
(selectedRateIsMember || selectedRateIsPublic) &&
|
||||
selectedRate.roomTypeCode === roomTypeCode
|
||||
)
|
||||
return isSelected
|
||||
}
|
||||
|
||||
export function isSelectedCorporateCheque(
|
||||
|
||||
Reference in New Issue
Block a user