Module: ReservationsHelper

Defined in:
app/helpers/reservations_helper.rb

Overview

typed: ignore encoding: utf-8 frozen_string_literal: true

Instance Method Summary collapse

Instance Method Details

#default_date_selectObject



27
28
29
# File 'app/helpers/reservations_helper.rb', line 27

def default_date_select
  Time.current_time.strftime '%Y-%m-%d'
end

#format_adult_count(adult, locale = :th) ⇒ Object



76
77
78
# File 'app/helpers/reservations_helper.rb', line 76

def format_adult_count(adult, locale = :th)
  "#{adult} #{locale == :th ? 'ผู้ใหญ่' : 'Adult'.pluralize(adult.to_i)}"
end

#format_kids_count(kids, locale = :th) ⇒ Object



72
73
74
# File 'app/helpers/reservations_helper.rb', line 72

def format_kids_count(kids, locale = :th)
  "#{kids} #{locale == :th ? 'เด็ก' : 'Kid'.pluralize(kids.to_i)}"
end

#format_total_package_packs(reservation, locale = :th) ⇒ Object



67
68
69
70
# File 'app/helpers/reservations_helper.rb', line 67

def format_total_package_packs(reservation, locale = :th)
  total_packs = total_package_packs(reservation)
  "#{total_packs} #{locale == :th ? 'แพ็กเกจ' : 'Pack'.pluralize(total_packs.to_i)}"
end

#get_reservation_status(status) ⇒ Object



21
22
23
24
25
# File 'app/helpers/reservations_helper.rb', line 21

def get_reservation_status(status)
  reservation_status_select.each do |options|
    return options.last if options.first.downcase[0..4].include?(status.downcase[0..4])
  end
end

#grouped_channel_nameObject



31
32
33
# File 'app/helpers/reservations_helper.rb', line 31

def grouped_channel_name
  ::Channel.grouped_channel.keys
end

#hotline(reservation) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/reservations_helper.rb', line 39

def hotline(reservation)
  restaurant = reservation.restaurant
  return AdminSetting.hotline_channel unless reservation.present?

  booking_channel = reservation.booking_channel
  return '' unless booking_channel.present?

  if booking_channel.using_restaurant_phone?
    return restaurant.phone if restaurant

    AdminSetting.hotline_channel

  elsif booking_channel.using_custom_phone?
    reservation.booking_channel.custom_phone

  elsif booking_channel.using_default_phone?
    AdminSetting.hotline_channel

  else
    APMErrorHandler.report 'Undefined phone type', channel: reservation.channel
    AdminSetting.hotline_channel
  end
end

#mtime(time) ⇒ Object



6
7
8
9
# File 'app/helpers/reservations_helper.rb', line 6

def mtime(time)
  time = Time.zone.parse(time) if time.is_a? String
  time.strftime('%H:%M')
end

#red_starObject



35
36
37
# File 'app/helpers/reservations_helper.rb', line 35

def red_star
  raw('<span style="color: #FF0000; ">*</span>')
end

#reservation_status_selectObject

used in select tag



12
13
14
15
16
17
18
19
# File 'app/helpers/reservations_helper.rb', line 12

def reservation_status_select
  [
    [I18n.t('views.booking.pending_arrival'), 'pending'],
    [I18n.t('views.d.arrive').titleize, 'arrive'],
    [I18n.t('views.booking.cancel'), 'cancel'],
    [I18n.t('views.booking.no_show'), 'no_show'],
  ]
end

#total_package_packs(reservation) ⇒ Object



63
64
65
# File 'app/helpers/reservations_helper.rb', line 63

def total_package_packs(reservation)
  reservation.package_obj.formatted_packages.pluck('quantity').sum
end