mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
compute right nb of free seats for event reservation
also: copy nb_total_places to n+1 instances when creating recurrent availabilities
This commit is contained in:
parent
ce366beaa2
commit
bbd613f2a5
@ -98,7 +98,7 @@ class Event < ActiveRecord::Base
|
||||
else
|
||||
nil
|
||||
end
|
||||
r = Recurrence.new(every: recurrence, on: on, starts: availability.start_at+1.day, until: recurrence_end_at)
|
||||
r = Recurrence.new(every: recurrence, on: on, starts: availability.start_at + 1.day, until: recurrence_end_at)
|
||||
r.events.each do |date|
|
||||
days_diff = availability.end_at.day - availability.start_at.day
|
||||
start_at = DateTime.new(
|
||||
@ -110,7 +110,7 @@ class Event < ActiveRecord::Base
|
||||
availability.start_at.sec,
|
||||
availability.start_at.zone
|
||||
)
|
||||
start_at = dst_correction(availability.start_at,start_at)
|
||||
start_at = dst_correction(availability.start_at, start_at)
|
||||
end_date = date + days_diff.days
|
||||
end_at = DateTime.new(
|
||||
end_date.year,
|
||||
@ -121,7 +121,7 @@ class Event < ActiveRecord::Base
|
||||
availability.end_at.sec,
|
||||
availability.end_at.zone
|
||||
)
|
||||
end_at = dst_correction(availability.start_at,end_at)
|
||||
end_at = dst_correction(availability.start_at, end_at)
|
||||
ei = EventImage.new(attachment: event_image.attachment) if event_image
|
||||
efs = event_files.map do |f|
|
||||
EventFile.new(attachment: f.attachment)
|
||||
|
@ -244,8 +244,11 @@ class Reservation < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def total_booked_seats
|
||||
total = 0
|
||||
total = nb_reserve_places if slots.first.canceled_at
|
||||
# cases:
|
||||
# - machine/training/space reservation => 1 slot = 1 seat (currently not covered by this function)
|
||||
# - event reservation => seats = nb_reserve_place (normal price) + tickets.booked (other prices)
|
||||
total = nb_reserve_places
|
||||
total = 0 if slots.first.canceled_at
|
||||
total += tickets.map(&:booked).map(&:to_i).reduce(:+) if tickets.count.positive?
|
||||
|
||||
total
|
||||
|
@ -20,7 +20,8 @@ class Availabilities::CreateAvailabilitiesService
|
||||
machine_ids: availability.machine_ids,
|
||||
training_ids: availability.training_ids,
|
||||
space_ids: availability.space_ids,
|
||||
tag_ids: availability.tag_ids
|
||||
tag_ids: availability.tag_ids,
|
||||
nb_total_places: availability.nb_total_places
|
||||
).save!
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user