feat: dedicated room pricing calculation for step 1 of create flow
This commit is contained in:
1 parent
df8566e1b5
commit
301b14f518
5 files changed
+79
-20
No files matched your search
@@ -15,6 +15,9 @@ use App\Form\Model\BookingDto;
|
||||
*/
|
||||
class RoomPricingCalculator
|
||||
{
|
||||
public const PRICING_MODE_ASSIGNMENT = 'assignment';
|
||||
public const PRICING_MODE_SELECTION = 'selection';
|
||||
|
||||
/**
|
||||
* Calculates pricing for all selected rooms.
|
||||
*
|
||||
@@ -22,7 +25,10 @@ class RoomPricingCalculator
|
||||
*
|
||||
* @return array Array of room pricing data with labels, quantities, and totals
|
||||
*/
|
||||
public function calculateRoomPricing(BookingDto $bookingDto): array
|
||||
public function calculateRoomPricing(
|
||||
BookingDto $bookingDto,
|
||||
string $pricingMode = self::PRICING_MODE_ASSIGNMENT,
|
||||
): array
|
||||
{
|
||||
// In edit mode, use room data from the booking entity
|
||||
if (BookingDto::MODE_EDIT === $bookingDto->getMode() && null !== $bookingDto->booking) {
|
||||
@@ -30,15 +36,18 @@ class RoomPricingCalculator
|
||||
}
|
||||
|
||||
// In create mode, use room selections from the form
|
||||
return $this->calculateRoomPricingFromSelections($bookingDto);
|
||||
return $this->calculateRoomPricingFromSelections($bookingDto, $pricingMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates total price for all rooms.
|
||||
*/
|
||||
public function calculateRoomTotal(BookingDto $bookingDto): float
|
||||
public function calculateRoomTotal(
|
||||
BookingDto $bookingDto,
|
||||
string $pricingMode = self::PRICING_MODE_ASSIGNMENT,
|
||||
): float
|
||||
{
|
||||
$roomPricing = $this->calculateRoomPricing($bookingDto);
|
||||
$roomPricing = $this->calculateRoomPricing($bookingDto, $pricingMode);
|
||||
|
||||
return array_sum(array_column($roomPricing, 'totalPrice'));
|
||||
}
|
||||
@@ -68,7 +77,7 @@ class RoomPricingCalculator
|
||||
*
|
||||
* @return array Array of room pricing data
|
||||
*/
|
||||
private function calculateRoomPricingFromSelections(BookingDto $bookingDto): array
|
||||
private function calculateRoomPricingFromSelections(BookingDto $bookingDto, string $pricingMode): array
|
||||
{
|
||||
$roomPricing = [];
|
||||
$selectedRooms = $bookingDto->getSelectedRooms();
|
||||
@@ -85,8 +94,13 @@ class RoomPricingCalculator
|
||||
continue;
|
||||
}
|
||||
|
||||
// Pricing in create flow is based on actual participant assignments per room.
|
||||
$participantCount = $assignmentCounts[$room->id] ?? 0;
|
||||
// Step 1 displays intended room pricing based on selected quantity and
|
||||
// minimum room occupancy (minPax). Subsequent steps calculate based on
|
||||
// actual participant assignments.
|
||||
$participantCount = self::PRICING_MODE_SELECTION === $pricingMode
|
||||
? (($room->minPax ?? 1) * $roomSelection->quantity)
|
||||
: ($assignmentCounts[$room->id] ?? 0)
|
||||
;
|
||||
$totalPrice = $participantCount * $room->price;
|
||||
|
||||
$roomPricing[] = [
|
||||
|
||||
Reference in new issue
Block a user