Class: Dashboard::V2::Group::ReservationsController
Instance Attribute Summary
#reservation
Instance Method Summary
collapse
#apply_voucher, #cancel, #check_reservation, #confirm, #create, #edit, #new, #request_more_bike, #self_checkin, #self_checkin_form, #send_custom_sms, #send_reminder, #send_review_link, #show, #table_number, #update
#history, #history_result
#my_response_cache
#default_fallback_location, #default_url_options, #kiosque_callback
#append_info_to_payload
#stimulus
#current_owner, #group_owner_type?, #request_path_contain_group?, #single_owner_type?
#events_ajax_previous_link, #show_source
#after_sign_in_path_for, #after_sign_out_path_for, #default_url_options, #identity_cache_memoization, #render_not_found, #routing_error, search_params_key=
#check_boolean_param, #get_banners, #inventory_params, #reservation_params
Instance Method Details
#check_inventory_status ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/controllers/dashboard/v2/group/reservations_controller.rb', line 37
def check_inventory_status
query = params.require(:reservation)
date = query.require(:date)
start_time = query.require(:start_time)
adult = query.require(:adult)
kids = query.fetch(:kids, 0)
restaurant_id = query[:reservation_restaurant_id] || query[:restaurant_id]
restaurant = Restaurant.find restaurant_id
date = date.is_a?(Date) ? date : date.to_date
inv_checker = InvCheckerFactory.new(restaurant.id, restaurant.time_zone).create_inv_checker_service
if inv_checker.bookable?(date: date, start_time: start_time, adult: adult.to_i, kids: kids.to_i) &&
current_owner.restaurant_ids.include?(restaurant_id)
render json: { available: true, message: nil }
else
message = inv_checker.check_unavailability_reason(date: date, start_time: start_time)
render json: { available: false, message: message }
end
end
|
#download ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'app/controllers/dashboard/v2/group/reservations_controller.rb', line 61
def download
respond_to do |format|
format.json do
permitted_parameters = params.require(:reservation).permit(:type, :start_date, :end_date, :date_type,
:restaurant_id, :start_time, :end_time, :date_filter_type, emails: [])
date_filter_type = permitted_parameters[:date_filter_type]
emails = (permitted_parameters[:emails].presence || []).to_set.add(current_user.email).to_a
messages = []
start_time = permitted_parameters[:start_time]
end_time = permitted_parameters[:end_time]
if permitted_parameters[:start_date].blank? || permitted_parameters[:end_date].blank?
messages << 'Start date and End date must be present'
end
emails.each do |email|
messages << "Email : #{email} is not valid" unless ::EmailValidator.valid?(email)
end
if date_filter_type == 'single' && (start_time.blank? || end_time.blank?)
messages << "Start time or end time can't be blank"
end
return render json: { status: 'failed', message: messages } if messages.present?
restaurant = if download_by_branch?
current_owner.restaurants.first
else
Restaurant.find Restaurant.decrypt_id(permitted_parameters[:restaurant_id])
end
start_date = Time.use_zone(restaurant.time_zone) do
Time.zone.parse permitted_parameters.require(:start_date)
end
end_date = Time.use_zone(restaurant.time_zone) do
Time.zone.parse permitted_parameters.require(:end_date)
end
data_type = permitted_parameters.require(:type)
NotificationWorkers::ReservationReport.fix_queue_perform_async(
:owner_staff,
{
emails: emails,
restaurant_id: download_by_branch? ? nil : restaurant.id,
restaurant_group_id: download_by_branch? ? current_owner.id : nil,
start_date: start_date,
end_date: end_date,
date_type: permitted_parameters[:date_type],
start_time: start_time,
end_time: end_time,
date_filter_type: date_filter_type,
data_type: data_type,
},
)
render json: { status: 'success', message: 'System will send you an email to download the report file' }
end
format.html do
render layout: nil
end
end
end
|
#email_owner_manager ⇒ Object
123
124
125
126
127
128
129
130
131
|
# File 'app/controllers/dashboard/v2/group/reservations_controller.rb', line 123
def email_owner_manager
restaurant_id = params['restaurant_id']
restaurant_id = if restaurant_id == '0' current_owner.restaurant_ids
else
Restaurant.decrypt_id(restaurant_id)
end
render json: manager_emails(restaurant_id)
end
|
#index ⇒ Object
29
30
31
32
33
34
35
|
# File 'app/controllers/dashboard/v2/group/reservations_controller.rb', line 29
def index
if Flipper.enabled? :owner_dashboard_v2, current_owner
index_v2
else
index_v1
end
end
|
#reservation_history ⇒ Object
133
134
135
136
137
138
139
140
141
|
# File 'app/controllers/dashboard/v2/group/reservations_controller.rb', line 133
def reservation_history
reservation_id = params[:id]
restaurant = Reservation.fetch(reservation_id).restaurant
history(reservation_id)
klass = restaurant.any_offers? ? Dashboard::V2::RsvPackagesGrid : Dashboard::V2::ReservationsGrid
@grid = klass.new { |scope| scope.where(id: history_result.to_a) }
end
|
#restaurants ⇒ Object
57
58
59
|
# File 'app/controllers/dashboard/v2/group/reservations_controller.rb', line 57
def restaurants
render json: current_owner.restaurants.map { |res| { name: res.name, id: res.encrypted_id } }
end
|
#statistic ⇒ Object
12
13
14
15
16
17
18
|
# File 'app/controllers/dashboard/v2/group/reservations_controller.rb', line 12
def statistic
cache_key = [reservation.restaurant_id, reservation.cache_key]
return unless stale? etag: cache_key, template: false
restaurant_ids = current_owner.restaurant_ids
user_reservation_statistic(cache_key, restaurant_ids)
end
|
#summary ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'app/controllers/dashboard/v2/group/reservations_controller.rb', line 20
def summary
respond_to do |format|
format.html format.json do
render json: @reservation.decorate.user_booking_summary(@reservation.user, @reservation.restaurant_id)
end
end
end
|