fix: always use totalPrice to display roomCharge
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import { dt } from "@/lib/dt"
|
||||
|
||||
import { sumPackages } from "@/components/HotelReservation/utils"
|
||||
|
||||
import { PriceTypeEnum } from "@/types/components/hotelReservation/myStay/myStay"
|
||||
import type { Price } from "@/types/components/hotelReservation/price"
|
||||
import { CurrencyEnum } from "@/types/enums/currency"
|
||||
@@ -12,7 +10,7 @@ export function mapToPrice(room: Room) {
|
||||
case PriceTypeEnum.cheque:
|
||||
return {
|
||||
corporateCheque: {
|
||||
additionalPricePerStay: room.roomPrice.perStay.local.price,
|
||||
additionalPricePerStay: room.totalPrice,
|
||||
currency: room.roomPrice.perStay.local.currency,
|
||||
numberOfCheques: room.cheques,
|
||||
},
|
||||
@@ -21,8 +19,8 @@ export function mapToPrice(room: Room) {
|
||||
return {
|
||||
regular: {
|
||||
currency: room.currencyCode,
|
||||
pricePerNight: room.roomPrice.perNight,
|
||||
pricePerStay: room.roomPrice.perStay,
|
||||
pricePerNight: room.roomPrice.perNight.local.price,
|
||||
pricePerStay: room.totalPrice,
|
||||
},
|
||||
}
|
||||
case PriceTypeEnum.points:
|
||||
@@ -31,8 +29,8 @@ export function mapToPrice(room: Room) {
|
||||
.diff(dt(room.checkInDate).startOf("day"), "days")
|
||||
return {
|
||||
redemption: {
|
||||
additionalPricePerStay: room.roomPrice.perStay.local.price,
|
||||
currency: room.roomPrice.perStay.local.currency,
|
||||
additionalPricePerStay: room.totalPrice,
|
||||
currency: room.currencyCode,
|
||||
pointsPerNight: room.roomPoints / nights,
|
||||
pointsPerStay: room.roomPoints,
|
||||
},
|
||||
@@ -51,11 +49,6 @@ export function mapToPrice(room: Room) {
|
||||
export function calculateTotalPrice(rooms: Room[], currency: CurrencyEnum) {
|
||||
return rooms.reduce<Price>(
|
||||
(total, room) => {
|
||||
const pkgsSum = sumPackages(room.packages)
|
||||
let breakfastPrice = 0
|
||||
if (room.breakfast && !room.rateDefinition.breakfastIncluded) {
|
||||
breakfastPrice = room.breakfast.localPrice.totalPrice
|
||||
}
|
||||
switch (room.priceType) {
|
||||
case PriceTypeEnum.cheque:
|
||||
{
|
||||
@@ -65,11 +58,7 @@ export function calculateTotalPrice(rooms: Room[], currency: CurrencyEnum) {
|
||||
break
|
||||
case PriceTypeEnum.money:
|
||||
{
|
||||
total.local.price =
|
||||
total.local.price +
|
||||
room.roomPrice.perStay.local.price +
|
||||
pkgsSum.price +
|
||||
breakfastPrice
|
||||
total.local.price = total.local.price + room.totalPrice
|
||||
|
||||
if (!total.local.currency) {
|
||||
total.local.currency = room.currencyCode
|
||||
@@ -93,17 +82,14 @@ export function calculateTotalPrice(rooms: Room[], currency: CurrencyEnum) {
|
||||
case PriceTypeEnum.points:
|
||||
case PriceTypeEnum.voucher:
|
||||
{
|
||||
if (room.roomPrice.perStay.local.price || pkgsSum) {
|
||||
if (room.totalPrice) {
|
||||
total.local.additionalPrice =
|
||||
room.roomPrice.perStay.local.price +
|
||||
pkgsSum.price +
|
||||
breakfastPrice
|
||||
(total.local.additionalPrice || 0) + room.totalPrice
|
||||
}
|
||||
|
||||
if (!total.local.additionalPriceCurrency) {
|
||||
if (room.roomPrice.perStay.local.currency) {
|
||||
total.local.additionalPriceCurrency =
|
||||
room.roomPrice.perStay.local.currency
|
||||
if (room.currencyCode) {
|
||||
total.local.additionalPriceCurrency = room.currencyCode
|
||||
} else {
|
||||
total.local.additionalPriceCurrency = currency
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user