2021-04-22 19:24:08 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# An event reservation added to the shopping cart
|
|
|
|
class CartItem::EventReservation < CartItem::Reservation
|
|
|
|
# @param normal_tickets {Number} number of tickets at the normal price
|
|
|
|
# @param other_tickets {Array<{booked: Number, event_price_category_id: Number}>}
|
|
|
|
def initialize(customer, operator, event, slots, normal_tickets: 0, other_tickets: [])
|
|
|
|
raise TypeError unless event.class == Event
|
|
|
|
|
|
|
|
super(customer, operator, event, slots)
|
|
|
|
@normal_tickets = normal_tickets
|
2021-04-23 17:54:59 +02:00
|
|
|
@other_tickets = other_tickets || []
|
2021-04-22 19:24:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def price
|
|
|
|
amount = @reservable.amount * @normal_tickets
|
|
|
|
is_privileged = @operator.admin? || (@operator.manager? && @operator.id != @customer.id)
|
|
|
|
|
|
|
|
@other_tickets.each do |ticket|
|
|
|
|
amount += ticket[:booked] * EventPriceCategory.find(ticket[:event_price_category_id]).amount
|
|
|
|
end
|
|
|
|
|
|
|
|
elements = { slots: [] }
|
|
|
|
|
|
|
|
@slots.each do |slot|
|
|
|
|
amount += get_slot_price(amount,
|
|
|
|
slot,
|
|
|
|
is_privileged,
|
|
|
|
elements: elements,
|
|
|
|
is_division: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
{ elements: elements, amount: amount }
|
|
|
|
end
|
|
|
|
|
2021-04-23 12:52:06 +02:00
|
|
|
def name
|
|
|
|
@reservable.title
|
|
|
|
end
|
2021-04-22 19:24:08 +02:00
|
|
|
end
|