Module: ModelExt::Reservations::InstanceMethods
- Includes:
- ElasticAPM::SpanHelpers, ProgressStatus, RefundGuaranteeHelper
- Included in:
- Reservation
- Defined in:
- lib/model_ext/reservations/instance_methods.rb
Constant Summary collapse
- Rpackage =
ImmutableStruct.new( :type_short, :dynamic_type_short, :type, :formatted_packages, :amount, :currency, :packages_bought, :revenue, :revenue_amount, )
- RAddOn =
ImmutableStruct.new( :formatted_add_ons, :add_ons_bought, :amount, :revenue, :revenue_amount, :currency, )
Instance Method Summary collapse
- #add_on_bought ⇒ Object
-
#add_on_data_for_report ⇒ Array<String>?
Formats add-on data for reports with quantity information.
- #add_on_obj ⇒ Object
- #allowed_to_rectify? ⇒ Boolean
- #aoa_channel? ⇒ Boolean
-
#assign_charged_data ⇒ Object
update total price, charge price, and everything regarding payment amount that made by customer.
- #assign_refund_guarantee_data(calculation_result) ⇒ Object
-
#by_bistrochat? ⇒ Boolean
Checks if the reservation is from Bistrochat vendor.
- #by_corporate_employee? ⇒ Boolean
- #by_marketplace? ⇒ Boolean
-
#by_mymenu? ⇒ Boolean
Checks if the reservation is from MyMenu vendor.
- #by_seven_rooms? ⇒ Boolean
- #by_tablecheck? ⇒ Boolean
- #by_weeloy? ⇒ Boolean
- #call_order_later_driver_at ⇒ Object
- #call_order_now_driver_at ⇒ Object
- #can_request_more_bike? ⇒ Boolean
- #cancel_preparing! ⇒ Object
- #cancelled? ⇒ Boolean
- #channel_group_name ⇒ Object
- #channel_name ⇒ Object
- #channel_uri_name ⇒ Object
- #corporate_order? ⇒ Boolean
- #courier_tracking_link ⇒ Object
- #created_at_format ⇒ Object
-
#created_by_admin_staff_or_owner? ⇒ Boolean
Check if reservation was created by admin, staff, or owner.
- #date_format ⇒ Object
- #date_format_ext ⇒ Object
- #delivery? ⇒ Boolean
- #delivery_address_humanize ⇒ Object
- #delivery_address_link ⇒ Object
-
#delivery_fee_money(perspective: nil) ⇒ Object
if the value is user, then we check whether it's an corporate order or not.
- #delivery_status ⇒ Object
- #delivery_type? ⇒ Boolean
- #dine_in? ⇒ Boolean
- #dine_in_type? ⇒ Boolean
- #dont_mark_as_arrived! ⇒ Object
- #dont_mark_as_no_show! ⇒ Object
-
#eligible_to_get_instant_reward? ⇒ Boolean
for instant reward.
- #eligible_to_get_reward? ⇒ Boolean
- #email ⇒ Object
- #end_time=(value) ⇒ Object
- #end_time_format ⇒ Object
-
#firebase_tracking_key ⇒ String
Returns the Firebase tracking key for this reservation Used for real-time status updates in Firebase Realtime Database.
- #food_ready_by ⇒ Object
- #formatted_menus ⇒ Object
- #full_datetime ⇒ Object
- #generate_tag_list(menu, sub = false, section_name = nil) ⇒ Object
- #get_driving_duration ⇒ Object
- #google_reserve_channel? ⇒ Boolean
-
#has_cancelled_with_refund? ⇒ Boolean
Check if reservation has been cancelled with refund claimed.
-
#inventory_class(is_dine_in = nil) ⇒ String
this method is only a wrapper for inventory_klass use inventory_klass instead.
-
#inventory_klass(new_service_type = service_type) ⇒ Class
service_type of the reservation it is used to determine the inventory class, incase user wants to change the service type from dine_in to take_away or vice versa either Inventory, InventoryTakeAway, InventoryTablecheck, InventoryWeeloy, or InventorySevenRooms.
-
#inventory_reservation_klass(new_service_type = service_type) ⇒ Class
service_type of the reservation either InventoryReservation or InventoryTakeAwayReservation.
- #inventory_times ⇒ Object
-
#is_past? ⇒ Boolean
return true if current time is greater than reservation time.
- #last_minute? ⇒ Boolean
- #mark_as_arrived! ⇒ Object
- #mark_as_canceled! ⇒ Object
- #mark_as_for_locking_system! ⇒ Object
- #mark_as_invalid_temporary_booking!(audit_comment: '') ⇒ Object
- #mark_as_no_show! ⇒ Object
- #mark_as_prepared! ⇒ Object
-
#mark_as_valid_reservation! ⇒ Object
pending arrival.
- #mark_voucher_as_active! ⇒ Object
- #mark_voucher_as_inactive! ⇒ Object
-
#name ⇒ Object
we prioritize the user.name instead of reservation.name when user is present.
- #need_request_choice? ⇒ Boolean
- #new_formatted_menus ⇒ Object
- #no_show? ⇒ Boolean
-
#omise_payment_gateway? ⇒ Boolean
Check if the reservation is using Omise as the payment gateway.
- #openrice_channel? ⇒ Boolean
- #original_delivery_fee_money(perspective: nil) ⇒ Object
- #owner_phone ⇒ Object
- #package_bought ⇒ Object
-
#package_data_for_report ⇒ Array<String>?
Formats package data for reports with quantity information.
- #package_obj ⇒ Object
-
#package_price_currency ⇒ String
Get reservation currency code First get from packages, if not present? Then try to get from restaurant level, if not present? Then return default currency (THB).
- #party_size_changed? ⇒ Boolean
- #payment_failed_url ⇒ Object
- #payment_success_url ⇒ Object
- #pending? ⇒ Boolean
- #phone ⇒ Object
- #phone=(param = nil) ⇒ Object
- #phone_intl ⇒ Object
- #private_channel? ⇒ Boolean
- #qr_code_for_payment ⇒ Object
- #qr_code_for_payment_expired_at ⇒ Object
-
#reached_goal? ⇒ Boolean
arrived.
- #ready_to_cook? ⇒ Boolean
- #redeemed_points ⇒ Object
-
#refund_fee_amount_float ⇒ Float
Get refund fee amount as float refund_fee_amount_float is used for serializer because we need to return Float, BigDecimal will be render as String in JSON.
-
#refundable_amount_float ⇒ Float
Get refundable amount as float refundable_amount_float is used for serializer because we need to return Float, BigDecimal will be render as String in JSON.
- #rejected? ⇒ Boolean
- #reservation_time ⇒ Time
-
#reservation_time_24h_passed? ⇒ Boolean
Checks if the reservation's dining time has passed by more than 24 hours.
-
#revenue_amount ⇒ Integer, BigDecimal
Get total revenue amount from package and add-on.
- #review ⇒ Object
- #self_pickup? ⇒ Boolean
- #service_type_humanize ⇒ Object
- #shopee_pay_url ⇒ Object
-
#skip_sending_netcore_event? ⇒ Boolean
No need to send event for market reservation from openrice, because openrice is using dummy email account that generated by hungryhub, it will waste the quota of email in Netcore if we send the event.
-
#special_request_without_package_menus ⇒ Object
sr.gsub(',', '
') end. - #start_time=(value) ⇒ Object
- #start_time_and_date_changed? ⇒ Boolean
- #start_time_format ⇒ Object
- #status ⇒ Object
- #status_as_symbol ⇒ Object
- #status_changed? ⇒ Boolean
- #status_for_owner ⇒ Object
- #tagthai_channel? ⇒ Boolean
- #temporary_lock? ⇒ Boolean
- #true_wallet_for_payment_expired_at ⇒ Object
- #true_wallet_url ⇒ Object
- #upcoming? ⇒ Boolean
- #use_third_party_reservation? ⇒ Boolean
- #username ⇒ Object
- #valid_to_cancel_temporary_booking? ⇒ Boolean
- #voucher_codes_humanize ⇒ Object
- #voucher_names_humanize ⇒ Object
- #vouchers_amount ⇒ Object
- #web_url ⇒ Object
- #web_v2_host_vendor ⇒ Object
Methods included from RefundGuaranteeHelper
#calculate_min_refund_hours, #calculate_refundable_until_time
Methods included from ProgressStatus
#available_delivery_status, #convert_from_grab_as_symbol, #convert_from_lalamove, #convert_from_lalamove_as_symbol, #convert_from_reservation, #owner_delivery_progress
Instance Method Details
#add_on_bought ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 151 def add_on_bought if add_on.present? && add_on[:add_on_data].present? add_on[:add_on_data].map do |item| add_on = AddOns::AddOn.find_by(id: item['id'].to_i) data = { restaurant_add_on_id: item[:restaurant_add_on_id], add_on: add_on, quantity: item[:quantity], } data end else {} end end |
#add_on_data_for_report ⇒ Array<String>?
Formats add-on data for reports with quantity information. Similar to add_on_obj but uses 'add_on_data_for_report' locale keys.
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 932 def add_on_data_for_report return nil if add_on.blank? || add_on[:add_on_data].blank? prop_cache_key = property.id.nil? ? rand(1000) : property.cache_key res_cache_key = id.nil? ? rand(1000) : cache_key @add_on_data_for_report ||= Rails.cache.fetch("#{res_cache_key}:add_on_data_for_report:#{prop_cache_key}") do add_ons = add_on[:add_on_data].map do |data| get_add_on = AddOns::AddOn.find_by(id: data[:id]) name = get_add_on&.name || '' price = HhMoney.new(data[:price_cents], data[:price_currency]) pricing_type = get_add_on&.pricing&.pricing_type { name: name, net_price: price.default_format, quantity: data[:quantity], pricing_type: pricing_type, } end add_ons.map do |aob| I18n.t("views.booking.add_on_data_for_report.#{aob[:pricing_type]}", name: aob[:name], net_price: aob[:net_price], quantity: aob[:quantity]) end end end |
#add_on_obj ⇒ Object
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 833 def add_on_obj return nil if add_on.blank? || add_on[:add_on_data].blank? prop_cache_key = property.id.nil? ? rand(1000) : property.cache_key res_cache_key = id.nil? ? rand(1000) : cache_key @add_on_obj ||= Rails.cache.fetch("#{res_cache_key}:add_on_obj:#{prop_cache_key}") do add_ons = add_on[:add_on_data].map do |data| get_add_on = AddOns::AddOn.find_by(id: data[:id]) name = get_add_on&.name price = HhMoney.new(data[:price_cents], data[:price_currency]) kids_price = HhMoney.new((data[:kids_price_cents].presence || 0), data[:price_currency]) data[:total_adult_price] = if data[:total_adult_price].present? data[:total_adult_price] % 1 == 0 ? data[:total_adult_price].to_i : data[:total_adult_price] else 0 end data[:total_kids_price] = if data[:total_kids_price].present? data[:total_kids_price] % 1 == 0 ? data[:total_kids_price].to_i : data[:total_kids_price] else 0 end data.merge( add_on_id: data[:id], name: name, net_price: price.default_format, amount: price.amount, kids_amount: kids_price.amount, id: data[:restaurant_add_on_id], pricing_type: get_add_on&.pricing&.pricing_type, ) end mf = HhMoney.new(add_on[:price_cents], add_on[:price_currency]) revenue_amount = HhMoney.new((add_on[:revenue] || 0), add_on[:price_currency]) add_ons_bought = add_ons.map do |aob| get_add_on = AddOns::AddOn.find_by(id: aob[:add_on_id]) customer_type = corporate_order? ? 'add_on_data_for_corporate_customer' : 'add_on_data_for_customer' I18n.t( "views.booking.#{customer_type}.#{get_add_on&.pricing&.pricing_type}", name: aob[:name], net_price: aob[:net_price], quantity: aob[:quantity], ) end RAddOn.new( formatted_add_ons: add_ons, add_ons_bought: add_ons_bought, amount: mf.amount, revenue: add_on[:revenue] || 0, revenue_amount: revenue_amount.amount, currency: mf.currency.iso_code, ) end end |
#allowed_to_rectify? ⇒ Boolean
401 402 403 404 405 406 407 408 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 401 def allowed_to_rectify? r = restaurant now = Time.now_in_tz(r.time_zone) latest_rectify_time = reservation_time - r.time_in_advance_to_rectify.minutes return false if now > latest_rectify_time true end |
#aoa_channel? ⇒ Boolean
1134 1135 1136 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1134 def aoa_channel? channel_uri_name == ApiVendorV1::Constants::AOA_CHANNEL_URI end |
#assign_charged_data ⇒ Object
update total price, charge price, and everything regarding payment amount that made by customer
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 971 def assign_charged_data return if (package.blank? && package_bought.blank?) || restaurant.blank? begin voucher_deductibles.destroy_all if persisted? && voucher_deductibles.present? calculator = HhPackage::ReservationPackages::ChargeCalculator.new calculator.set_delivery_pricing_tiers(restaurant.delivery_pricing_tiers) calculator.assign_voucher(self&.active_vouchers) calculator.set_user(user_id) calculator.set_custom_price_cents(package) calculator.use_dynamic_pricing = booking_channel.support_dynamic_pricing calculator.accept_refund = property.accept_refund? if property.present? calculator.custom_refund_fee_cents = property.custom_refund_fee_cents if property.present? data = calculator.calculate( package_bought, adult, kids, distance_to_restaurant.to_f, restaurant, date, add_on_bought, ) # Override charge_percent if vendor_payment is present, such vendors are saved in ::Channel.payment_handled_by_vendor? # this override is only for update reservations # for create reservation, we set charge_percent to 100% after reservation is created. data[:charge_percent] = 100 if vendor_payment.present? price_fields = { charge_price_v2: Money.new(data[:charge_price_cents], package_price_currency), total_price_v2: Money.new(data[:total_price_cents], package_price_currency), } other_fields = data.slice( :charge_amount_type, :charge_percent, :charge_type, :delivery_fee, :delivery_fee_in_baht, :delivery_fee_per_km_in_baht, :original_delivery_fee, :used_voucher_amount_by_hh, :used_voucher_amount_by_restaurant, ) self.attributes = price_fields.merge(other_fields) self.delivery_subsidize = calculator.subsidize_price if data[:voucher_deductibles].present? data[:voucher_deductibles].map { |vd| vd.reservation_id = id } voucher_deductibles << data[:voucher_deductibles] end property.selected_packages = data[:selected_packages] property.selected_add_ons = data[:selected_add_ons] self.charge_type = HhPackage::Package::CHARGE_TYPE_ON_CHARGE if payment_provider.present? && cc_provider.blank? assign_refund_guarantee_data(data) rescue StandardError => e APMErrorHandler.report e end nil end |
#assign_refund_guarantee_data(calculation_result) ⇒ Object
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1040 def assign_refund_guarantee_data(calculation_result) return if restaurant.blank? || !property.accept_refund? return if calculation_result[:total_refund_price_cents].to_i.zero? refundable_until_time = calculate_refundable_until_time(self) # Create or update the refund guarantee record if id.blank? build_refund_guarantee( refund_fee_cents: calculation_result[:total_refund_price_cents], refund_currency: package_price_currency, refundable_amount_cents: calculation_result[:total_refundable_amount_cents], refundable_until: refundable_until_time, ) else refund_guarantee_record = ReservationRefundGuarantee.find_or_initialize_by(reservation_id: id) refund_guarantee_record.refund_fee_cents = calculation_result[:total_refund_price_cents] refund_guarantee_record.refund_currency = package_price_currency refund_guarantee_record.refundable_amount_cents = calculation_result[:total_refundable_amount_cents] refund_guarantee_record.refundable_until = refundable_until_time refund_guarantee_record.save! end end |
#by_bistrochat? ⇒ Boolean
Checks if the reservation is from Bistrochat vendor.
1163 1164 1165 1166 1167 1168 1169 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1163 def by_bistrochat? vr = vendor_reservation return false if vr.blank? return false unless vr.supplier_reservation_id? vr.inventory_source&.inv_source.to_s == ApiVendorV1::Constants::BISTROCHAT_INV_SOURCE_NAME end |
#by_corporate_employee? ⇒ Boolean
86 87 88 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 86 def by_corporate_employee? user&.externals_company_id.present? end |
#by_marketplace? ⇒ Boolean
1195 1196 1197 1198 1199 1200 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1195 def by_marketplace? return false if vendor_reservation.blank? || vendor_reservation.oauth_application.blank? Channel::VENDOR_NAME_LIST_COMPLETE_INTEGRATIONS.include?(vendor_reservation.oauth_application.name) end |
#by_mymenu? ⇒ Boolean
Checks if the reservation is from MyMenu vendor.
1173 1174 1175 1176 1177 1178 1179 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1173 def vr = vendor_reservation return false if vr.blank? return false unless vr.supplier_reservation_id? vr.inventory_source&.inv_source.to_s == ApiVendorV1::Constants::MYMENU_INV_SOURCE_NAME end |
#by_seven_rooms? ⇒ Boolean
1188 1189 1190 1191 1192 1193 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1188 def by_seven_rooms? return false if vendor_reservation.blank? return false if vendor_reservation.supplier_reservation_id.blank? vendor_reservation.inventory_source&.inv_source.to_s == ApiVendorV1::Constants::SEVEN_ROOMS_INV_SOURCE_NAME end |
#by_tablecheck? ⇒ Boolean
1154 1155 1156 1157 1158 1159 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1154 def by_tablecheck? return false if vendor_reservation.blank? return false if vendor_reservation.supplier_reservation_id.blank? vendor_reservation.inventory_source&.inv_source.to_s == ApiVendorV1::Constants::TABLECHECK_INV_SOURCE_NAME end |
#by_weeloy? ⇒ Boolean
1181 1182 1183 1184 1185 1186 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1181 def by_weeloy? return false if vendor_reservation.blank? return false if vendor_reservation.supplier_reservation_id.blank? vendor_reservation.inventory_source&.inv_source.to_s == ApiVendorV1::Constants::WEELOY_INV_SOURCE_NAME end |
#call_order_later_driver_at ⇒ Object
101 102 103 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 101 def call_order_later_driver_at reservation_time - restaurant.minute_before_delivery_time.to_i.minutes end |
#call_order_now_driver_at ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 90 def call_order_now_driver_at order_time = created_at.in_time_zone(restaurant.time_zone) cooking_time = (restaurant.order_now&.cooking_time || 0).to_i.minutes if restaurant&.order_now.present? call_before = restaurant.order_now.call_driver_before_food_ready.to_i.minutes order_time + cooking_time - call_before else order_time + cooking_time end end |
#can_request_more_bike? ⇒ Boolean
961 962 963 964 965 966 967 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 961 def can_request_more_bike? return false if address.present? && delivery_channel && delivery_channel.courier.self_deliver? delivery? && status_as_symbol == :pending_arrival && !is_past? && !property&.has_requested_bike? && DeliveryChannel.lalamove_instance.available_for?(restaurant) end |
#cancel_preparing! ⇒ Object
732 733 734 735 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 732 def cancel_preparing! self.audit_comment = "#{audit_comment}cancel_preparing! called" self.prepared = 0 end |
#cancelled? ⇒ Boolean
608 609 610 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 608 def cancelled? !active? end |
#channel_group_name ⇒ Object
515 516 517 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 515 def channel_group_name booking_channel&.group_name end |
#channel_name ⇒ Object
507 508 509 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 507 def channel_name booking_channel&.name end |
#channel_uri_name ⇒ Object
511 512 513 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 511 def channel_uri_name booking_channel&.uri_name end |
#corporate_order? ⇒ Boolean
82 83 84 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 82 def corporate_order? corporate_event_id.present? end |
#courier_tracking_link ⇒ Object
598 599 600 601 602 603 604 605 606 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 598 def courier_tracking_link return '' unless service_type == 'delivery' if delivery_channel.present? && driver.present? driver.tracking_link else web_url end end |
#created_at_format ⇒ Object
442 443 444 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 442 def created_at_format created_at&.strftime("#{created_at.day.ordinalize} %B %Y") # 20th December 2013 end |
#created_by_admin_staff_or_owner? ⇒ Boolean
Check if reservation was created by admin, staff, or owner
1246 1247 1248 1249 1250 1251 1252 1253 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1246 def created_by_admin_staff_or_owner? return false if created_by.blank? %i[admin staff owner].include?(created_by.to_sym) rescue StandardError # If created_by is invalid or can't be converted to symbol, treat as user false end |
#date_format ⇒ Object
434 435 436 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 434 def date_format date&.strftime('%d/%m/%Y') end |
#date_format_ext ⇒ Object
438 439 440 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 438 def date_format_ext date&.strftime("#{date.day.ordinalize} %B %Y") end |
#delivery? ⇒ Boolean
167 168 169 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 167 def delivery? service_type.to_sym == :delivery end |
#delivery_address_humanize ⇒ Object
306 307 308 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 306 def delivery_address_humanize [address.detail, address.note_for_driver].reject(&:blank?).compact.join(', ') if address.present? end |
#delivery_address_link ⇒ Object
310 311 312 313 314 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 310 def delivery_address_link return nil if address.blank? "https://www.google.com/maps/search/?api=1&query=#{address.lat},#{address.lon}" if address.lat && address.lon end |
#delivery_fee_money(perspective: nil) ⇒ Object
if the value is user, then we check whether it's an corporate order or not
272 273 274 275 276 277 278 279 280 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 272 def delivery_fee_money(perspective: nil) case perspective when :user df = corporate_order? ? 0 : (delivery_fee.to_f * 100) HhMoney.new(df, restaurant.currency_code) else HhMoney.new(delivery_fee.to_f * 100, restaurant.currency_code) end end |
#delivery_status ⇒ Object
450 451 452 453 454 455 456 457 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 450 def delivery_status return '' unless service_type == 'delivery' status = driver&.status return convert_from_reservation(status) if status.present? '' end |
#delivery_type? ⇒ Boolean
179 180 181 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 179 def delivery_type? %i[delivery pick_up].include?(service_type.to_sym) end |
#dine_in? ⇒ Boolean
175 176 177 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 175 def dine_in? service_type.to_sym == :dine_in end |
#dine_in_type? ⇒ Boolean
183 184 185 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 183 def dine_in_type? service_type.to_sym == :dine_in end |
#dont_mark_as_arrived! ⇒ Object
666 667 668 669 670 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 666 def dont_mark_as_arrived! mark_as_valid_reservation! self.audit_comment = "#{audit_comment}dont_mark_as_arrived! called" self.arrived = false end |
#dont_mark_as_no_show! ⇒ Object
684 685 686 687 688 689 690 691 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 684 def dont_mark_as_no_show! mark_as_valid_reservation! self.audit_comment = "#{audit_comment}dont_mark_as_no_show! called" self.is_valid_reservation = true self.no_show = false self.active = true self.arrived = true end |
#eligible_to_get_instant_reward? ⇒ Boolean
for instant reward
375 376 377 378 379 380 381 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 375 def eligible_to_get_instant_reward? today = Time.now_in_tz(restaurant.time_zone) return false if !restaurant.active || restaurant.date_offer_expired?(today) || !pay_now? !user_id.nil? && reached_goal? end |
#eligible_to_get_reward? ⇒ Boolean
362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 362 def eligible_to_get_reward? today = Time.now_in_tz(restaurant.time_zone) return false if !restaurant.active || restaurant.date_offer_expired?(today) return false unless restaurant.eligible_for_rewards? return !user_id.nil? && reached_goal? if pay_now? !user_id.nil? && is_past? && reached_goal? end |
#email ⇒ Object
558 559 560 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 558 def email user.present? ? user.email : self[:email] end |
#end_time=(value) ⇒ Object
426 427 428 429 430 431 432 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 426 def end_time=(value) self[:end_time] = if value.nil? nil else value.to_s end end |
#end_time_format ⇒ Object
422 423 424 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 422 def end_time_format end_time&.strftime('%H:%M') end |
#firebase_tracking_key ⇒ String
Returns the Firebase tracking key for this reservation Used for real-time status updates in Firebase Realtime Database
1108 1109 1110 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1108 def firebase_tracking_key "reservations/#{id}" end |
#food_ready_by ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 105 def food_ready_by return nil if dine_in? return nil if reservation_time.past? if service_type.pick_up? start_time_format elsif is_order_now? order_time = created_at.in_time_zone(restaurant.time_zone) cooking_time = (restaurant.order_now&.cooking_time || 0).to_i.minutes (order_time + cooking_time).strftime('%H:%M') else (reservation_time - restaurant.minute_before_delivery_time.to_i.minutes + 15.minutes).strftime('%H:%M') end end |
#formatted_menus ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 207 def total_quantity = 0 = .map do |s| [s..map do |m| total_quantity += m.quantity [quantity: m.quantity, name: m..name, submenus: m.subsections.map do |ss| [ss..map do |sm| [name: sm..name, subsection_id: sm..section.id, subsection_name: sm..section.name, quantity: sm.quantity].flatten end].flatten end.flatten].flatten end].flatten end.flatten tag_list = [] .each do || tag_list.push generate_tag_list() end = tag_list.join.presence || nil return "#{}<br> Total quantity: #{total_quantity}" if .present? special_request end |
#full_datetime ⇒ Object
446 447 448 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 446 def full_datetime "#{start_time_format} on #{date.strftime('%A')}, #{date_format_ext}" # 18:00 on Friday, 20th December 2013 end |
#generate_tag_list(menu, sub = false, section_name = nil) ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 235 def generate_tag_list(, sub = false, section_name = nil) ActionController::Base.helpers.content_tag(:ul) do ul_contents = [] section_name = section_name.present? ? "#{section_name} - " : '' show_quantity = sub ? '' : "x#{[:quantity]}" ul_contents.push ActionController::Base.helpers.content_tag(:li, "#{section_name} #{[:name]} #{show_quantity}") = .fetch(:submenus, []) total_sm = .group_by { |sm| sm[:subsection_id] }.count .each do |child| section_name = total_sm > 1 ? child[:subsection_name] : nil ul_contents.push generate_tag_list(child, true, section_name) end ul_contents.join.html_safe end.html_safe end |
#get_driving_duration ⇒ Object
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 576 def get_driving_duration return driving_duration.to_i if driving_duration_checked? destination = { lat: address.lat, lng: address.lon, } calc = DeliveryChannel::DistanceCalculator.new result = calc.find_distance_to_restaurant(destination, restaurant) duration = if result[:success] result[:duration] else 0 end self.driving_duration = duration self.driving_duration_checked = true save driving_duration end |
#google_reserve_channel? ⇒ Boolean
1146 1147 1148 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1146 def google_reserve_channel? channel_uri_name == ApiVendorV1::Constants::GOOGLE_RESERVE_CHANNEL_URI end |
#has_cancelled_with_refund? ⇒ Boolean
Check if reservation has been cancelled with refund claimed
1307 1308 1309 1310 1311 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1307 def has_cancelled_with_refund? return false if refund_guarantee.blank? !active? && refund? && refund_guarantee.status == ReservationRefundGuarantee::STATUS_CLAIMED end |
#inventory_class(is_dine_in = nil) ⇒ String
this method is only a wrapper for inventory_klass use inventory_klass instead
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 33 def inventory_class(is_dine_in = nil) # Deprecated method, use inventory_class_name instead APMErrorHandler.report('inventory_class is deprecated, use inventory_klass instead') if is_dine_in.nil? is_dine_in = service_type.to_sym == :dine_in end new_service_type = is_dine_in ? 'dine_in' : 'take_away' inventory_klass(new_service_type).to_s end |
#inventory_klass(new_service_type = service_type) ⇒ Class
service_type of the reservation it is used to determine the inventory class, incase user wants to change the service type from dine_in to take_away or vice versa either Inventory, InventoryTakeAway, InventoryTablecheck, InventoryWeeloy, or InventorySevenRooms
19 20 21 22 23 24 25 26 27 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 19 def inventory_klass(new_service_type = service_type) @inventory_class ||= {} cache_key = "#{restaurant_id}:#{new_service_type}" @inventory_class[cache_key] ||= InventoryWrapper.new( restaurant_id: restaurant_id, service_type: new_service_type, ).inv_model end |
#inventory_reservation_klass(new_service_type = service_type) ⇒ Class
service_type of the reservation either InventoryReservation or InventoryTakeAwayReservation
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 49 def inventory_reservation_klass(new_service_type = service_type) @inventory_reservation_class ||= {} cache_key = "#{restaurant_id}:#{new_service_type}" @inventory_reservation_class[cache_key] ||= begin klass = inventory_klass(new_service_type) if [Inventory, InventoryTakeAway].include?(klass) "#{klass}Reservation".constantize else # Reservation for third party always use InventoryReservation # Since they only support dine_in service type InventoryReservation end end end |
#inventory_times ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 65 def inventory_times result = [start_time_format] st = start_time.dup loop do break if (st + 15.minutes) >= end_time st += 15.minutes result.push st.strftime('%H:%M') end result end |
#is_past? ⇒ Boolean
return true if current time is greater than reservation time
563 564 565 566 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 563 def is_past? time_zone = restaurant.time_zone Time.now_in_tz(time_zone) > reservation_time end |
#last_minute? ⇒ Boolean
741 742 743 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 741 def last_minute? (reservation_time - created_at.in_time_zone(restaurant.time_zone)).to_f / 60.0 < restaurant.determine_min_booking_time(reservation: self).to_f end |
#mark_as_arrived! ⇒ Object
656 657 658 659 660 661 662 663 664 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 656 def mark_as_arrived! mark_as_valid_reservation! self.audit_comment = if use_third_party_reservation? note else "#{audit_comment}mark_as_arrived! called" end self.arrived = true end |
#mark_as_canceled! ⇒ Object
704 705 706 707 708 709 710 711 712 713 714 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 704 def mark_as_canceled! self.audit_comment = if use_third_party_reservation? note else "#{audit_comment}mark_as_canceled! called" end self.is_valid_reservation = false self.active = false self.no_show = false self.arrived = false end |
#mark_as_for_locking_system! ⇒ Object
636 637 638 639 640 641 642 643 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 636 def mark_as_for_locking_system! self.for_locking_system = true self.active = true self.arrived = false self.no_show = false self.is_valid_reservation = false self.audit_comment = "#{audit_comment}mark_as_for_locking_system! called" end |
#mark_as_invalid_temporary_booking!(audit_comment: '') ⇒ Object
645 646 647 648 649 650 651 652 653 654 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 645 def mark_as_invalid_temporary_booking!(audit_comment: '') self.audit_comment = "#{audit_comment}mark_as_invalid_temporary_booking! called" self.is_valid_reservation = false self.is_temporary = false self.cancelled_by = :system self.for_locking_system = false self.active = false self.arrived = false self.no_show = false end |
#mark_as_no_show! ⇒ Object
672 673 674 675 676 677 678 679 680 681 682 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 672 def mark_as_no_show! self.audit_comment = if use_third_party_reservation? note else "#{audit_comment}mark_as_no_show! called" end self.is_valid_reservation = false self.active = true self.no_show = true self.arrived = false end |
#mark_as_prepared! ⇒ Object
726 727 728 729 730 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 726 def mark_as_prepared! self.audit_comment = "#{audit_comment}mark_as_prepared! called" self.active = 1 self.prepared = 1 end |
#mark_as_valid_reservation! ⇒ Object
pending arrival
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 620 def mark_as_valid_reservation! self.audit_comment = if use_third_party_reservation? note else "#{audit_comment}mark_as_valid_reservation! called" end self.is_valid_reservation = true self.active = true self.ack = true self.no_show = false self.arrived = false self.for_locking_system = false self.is_temporary = false self.cancelled_by = nil end |
#mark_voucher_as_active! ⇒ Object
721 722 723 724 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 721 def mark_voucher_as_active! service = ::VoucherService::Modify.new(self) service.activate! end |
#mark_voucher_as_inactive! ⇒ Object
716 717 718 719 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 716 def mark_voucher_as_inactive! service = ::VoucherService::Modify.new(self) service.inactive! end |
#name ⇒ Object
we prioritize the user.name instead of reservation.name when user is present
533 534 535 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 533 def name user.present? ? user.username : self[:name] end |
#need_request_choice? ⇒ Boolean
612 613 614 615 616 617 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 612 def need_request_choice? return false if restaurant.covers_require_additional.nil? return false unless restaurant.request_question.present? && restaurant.request_choice.present? party_size.to_i > restaurant.covers_require_additional.to_i end |
#new_formatted_menus ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 253 def .map do |s| [s..map do |m| [quantity: m.quantity, name: m..name, submenus: m.subsections.map do |ss| [ss..map do |sm| [name: sm..name, subsection_id: sm..section.id, subsection_name: sm..section.name, quantity: sm.quantity].flatten end].flatten end.flatten].flatten end].flatten end.flatten end |
#no_show? ⇒ Boolean
387 388 389 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 387 def no_show? active && no_show end |
#omise_payment_gateway? ⇒ Boolean
Check if the reservation is using Omise as the payment gateway
1087 1088 1089 1090 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1087 def omise_payment_gateway? # Check if credit card payment is using Omise cc_provider.present? && cc_provider.to_s == 'omise' end |
#openrice_channel? ⇒ Boolean
1142 1143 1144 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1142 def openrice_channel? channel_uri_name == ApiVendorV1::Constants::OPEN_RICE_CHANNEL_URI end |
#original_delivery_fee_money(perspective: nil) ⇒ Object
282 283 284 285 286 287 288 289 290 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 282 def original_delivery_fee_money(perspective: nil) case perspective when :user df = corporate_order? ? 0 : (original_delivery_fee.to_f * 100) HhMoney.new(df, restaurant.currency_code) else HhMoney.new(original_delivery_fee.to_f * 100, restaurant.currency_code) end end |
#owner_phone ⇒ Object
568 569 570 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 568 def owner_phone restaurant.owner.phone end |
#package_bought ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 120 def package_bought if package.present? package[:package_data].map do |item| package = item['type'].constantize.find_by(id: item['id'].to_i) data = { restaurant_package_id: item[:restaurant_package_id], package: package, quantity: item[:quantity], } = SectionTrees.build_section_trees_from_reservation(self) if .present? data = data.merge( menu_sections: .map(&:to_h), ) end group_sections = SectionTrees.build_group_sections_from_reservation(self) if group_sections.present? data = data.merge( group_sections: group_sections.map(&:to_h), ) end data end else {} end end |
#package_data_for_report ⇒ Array<String>?
Formats package data for reports with quantity information. Similar to package_obj but uses 'package_data_for_report' locale keys.
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 894 def package_data_for_report return nil if package.blank? || package[:package_data].blank? prop_cache_key = property.id.nil? ? rand(1000) : property.cache_key res_cache_key = id.nil? ? rand(1000) : cache_key @package_data_for_report ||= Rails.cache.fetch("#{res_cache_key}:package_data_for_report:#{prop_cache_key}") do sym = package[:package_type].to_s.to_sym klass = "HhPackage::Package::#{HhPackage::PACKAGE_SHORT_TO_LIST[sym]}".constantize packages = package[:package_data].map do |data| get_package = klass.find_by(id: data[:id]) name = get_package&.name || '' price = HhMoney.new(data[:price_cents], data[:price_currency]) { name: name, net_price: price.default_format, quantity: data[:quantity], package_type: package[:package_type], } end packages.map do |p| I18n.t("views.booking.package_data_for_report.#{p[:package_type]}", name: p[:name], net_price: p[:net_price], quantity: p[:quantity]) end end end |
#package_obj ⇒ Object
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 757 def package_obj return nil if package.blank? || package[:package_data].blank? prop_cache_key = property.id.nil? ? rand(1000) : property.cache_key res_cache_key = id.nil? ? rand(1000) : cache_key @package_obj ||= Rails.cache.fetch("#{res_cache_key}:package_obj:#{prop_cache_key}") do sym = package[:package_type].to_s.to_sym pkg_type = HhPackage::PACKAGE_SHORT_LIST_AND_LONG_NAME[sym] klass = "HhPackage::Package::#{HhPackage::PACKAGE_SHORT_TO_LIST[sym]}".constantize dynamic_type_short = nil packages = package[:package_data].map do |data| get_package = klass.find_by(id: data[:id]) name = get_package&.name price = HhMoney.new(data[:price_cents], data[:price_currency]) kids_price = HhMoney.new((data[:kids_price_cents].presence || 0), data[:price_currency]) unless data['commision'].is_a?(String) commision = data['commision'] data['commision'] = commision.present? ? commision.to_f.to_s : restaurant.commision end dynamic_type_short = if get_package&.allow_mix_ayce? && get_package&.use_mix_and_match?(package_bought.count) 'pp' else get_package&.type_short end data[:total_adult_price] = data[:total_adult_price].present? && data[:total_adult_price] % 1 == 0 ? data[:total_adult_price].to_i : data[:total_adult_price] data[:total_kids_price] = data[:total_kids_price].present? && data[:total_kids_price] % 1 == 0 ? data[:total_kids_price].to_i : data[:total_kids_price] data.merge(package_id: data[:id], dynamic_pricing_name: data[:dynamic_pricing_name], name: name, net_price: price.default_format, amount: price.amount, kids_amount: kids_price.amount, pay_now: get_package&.pay_now, require_cc: get_package&.require_cc, earn_point: get_package&.earn_point, id: data[:restaurant_package_id]) end mf = HhMoney.new(package[:price_cents], package[:price_currency]) revenue_amount = HhMoney.new((package[:revenue] || 0), package[:price_currency]) packages_bought = packages.map do |p| customer_type = corporate_order? ? 'package_data_for_corporate_customer' : 'package_data_for_customer' I18n.t("views.booking.#{customer_type}.#{package[:package_type]}", name: p[:name], net_price: p[:net_price], quantity: p[:quantity]) end Rpackage.new( type_short: package[:package_type].to_s, dynamic_type_short: dynamic_type_short || package[:package_type].to_s, type: pkg_type, formatted_packages: packages, packages_bought: packages_bought, amount: mf.amount, revenue: package[:revenue] || 0, revenue_amount: revenue_amount.amount, currency: mf.currency.iso_code, ) end end |
#package_price_currency ⇒ String
Get reservation currency code First get from packages, if not present? Then try to get from restaurant level, if not present? Then return default currency (THB)
1239 1240 1241 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1239 def package_price_currency package&.[](:price_currency) || restaurant&.default_currency || Country::THAI_CURRENCY_CODE end |
#party_size_changed? ⇒ Boolean
1225 1226 1227 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1225 def party_size_changed? party_size_will_change! && changed_attributes.include?('party_size') end |
#payment_failed_url ⇒ Object
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1092 def payment_failed_url # payment_failed_url still use sub_domain not web_v2_host url = AdminSetting.sub_domain # if the channel is aoa or tagthai, a redirect_url param is added redirect_url_param = '' if web_v2_host_vendor.present? && (aoa_channel? || tagthai_channel?) redirect_url_param = "?redirect_url=#{web_v2_host_vendor}" end "#{url}/payment-failed#{redirect_url_param}" end |
#payment_success_url ⇒ Object
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1072 def payment_success_url url = web_v2_host_vendor || AdminSetting.web_v2_host # Use 'payment-landing' instead of 'payment-success' when payment gateway is Omise path_segment = if omise_payment_gateway? 'payment-landing' else 'payment-success' end "#{url}/restaurants/#{restaurant.friendly_id}/#{path_segment}/#{to_url_hash}" end |
#pending? ⇒ Boolean
391 392 393 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 391 def pending? ack == false && confirmed_by.blank? && active? end |
#phone ⇒ Object
541 542 543 544 545 546 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 541 def phone return user.phone_v2_full if user_id return self[:phone] if self[:phone].present? nil end |
#phone=(param = nil) ⇒ Object
548 549 550 551 552 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 548 def phone=(param = nil) return if param.nil? || param.blank? self[:phone] = Phonelib.parse(param).e164 end |
#phone_intl ⇒ Object
554 555 556 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 554 def phone_intl ::Phonelib.parse(phone).e164 end |
#private_channel? ⇒ Boolean
572 573 574 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 572 def private_channel? ::Channel.manual.include?(channel) end |
#qr_code_for_payment ⇒ Object
296 297 298 299 300 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 296 def qr_code_for_payment charge = charges.present? && charges.pending_scope.promptpay_source.last charge.source.qr_code.url if charge end |
#qr_code_for_payment_expired_at ⇒ Object
302 303 304 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 302 def qr_code_for_payment_expired_at (payment_start_from.presence || created_at) + AdminSetting.prompt_pay_count_down_in_minute.to_i.minute end |
#reached_goal? ⇒ Boolean
arrived
354 355 356 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 354 def reached_goal? active? && !no_show? && ack? && !is_temporary && !temporary_lock? end |
#ready_to_cook? ⇒ Boolean
358 359 360 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 358 def ready_to_cook? delivery_status.blank? && active? && !arrived? end |
#redeemed_points ⇒ Object
335 336 337 338 339 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 335 def redeemed_points return 0 if vouchers.redeemed_points.blank? vouchers.redeemed_points.sum(&:amount).amount.to_i end |
#refund_fee_amount_float ⇒ Float
Get refund fee amount as float refund_fee_amount_float is used for serializer because we need to return Float, BigDecimal will be render as String in JSON
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1274 def refund_fee_amount_float @refund_fee_amount_float ||= begin return 0 if refund_guarantee.blank? refund_fee_amount = refund_guarantee.refund_fee.amount if refund_fee_amount % 1 == 0 refund_fee_amount.to_i else refund_fee_amount.to_f.round(2) end end end |
#refundable_amount_float ⇒ Float
Get refundable amount as float refundable_amount_float is used for serializer because we need to return Float, BigDecimal will be render as String in JSON
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1291 def refundable_amount_float @refundable_amount_float ||= begin return 0 if refund_guarantee.blank? refundable_amount = refund_guarantee.refundable_amount.amount if refundable_amount % 1 == 0 refundable_amount.to_i else refundable_amount.to_f.round(2) end end end |
#rejected? ⇒ Boolean
383 384 385 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 383 def rejected? confirmed_by.present? && !ack end |
#reservation_time ⇒ Time
520 521 522 523 524 525 526 527 528 529 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 520 def reservation_time time_zone = restaurant.time_zone ::Time.use_zone time_zone do if start_time.blank? ::Time.zone.at(0) else ::Time.zone.parse(start_time_format, date) end end end |
#reservation_time_24h_passed? ⇒ Boolean
Checks if the reservation's dining time has passed by more than 24 hours
Uses existing reservation methods:
-
twenty_four_hours_later: Adds 24 hours to reservation_time
1211 1212 1213 1214 1215 1216 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1211 def reservation_time_24h_passed? current_time = Time.current.in_time_zone(restaurant.time_zone || 'Asia/Bangkok') return false if reservation_time.blank? current_time > reservation_time.twenty_four_hours_later end |
#revenue_amount ⇒ Integer, BigDecimal
Get total revenue amount from package and add-on
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1258 def revenue_amount package_revenue = package_obj&.revenue_amount.to_d || 0 add_on_revenue = add_on_obj&.revenue_amount.to_d || 0 total_revenue = package_revenue + add_on_revenue if total_revenue % 1 == 0 total_revenue.to_i else total_revenue end end |
#review ⇒ Object
737 738 739 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 737 def review @review ||= ::Review.find_or_initialize_by reservation_id: id end |
#self_pickup? ⇒ Boolean
171 172 173 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 171 def self_pickup? service_type.to_sym == :pick_up end |
#service_type_humanize ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 316 def service_type_humanize case service_type.to_sym when :dine_in I18n.t('service_type.dine_in') when :delivery I18n.t('service_type.delivery') when :pick_up I18n.t('service_type.pick_up') else raise NotImplementedError end end |
#shopee_pay_url ⇒ Object
1122 1123 1124 1125 1126 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1122 def shopee_pay_url return '' if shopee_pay_provider.blank? || charges.blank? charges.first.source.content['redirect_url_http'] end |
#skip_sending_netcore_event? ⇒ Boolean
No need to send event for market reservation from openrice, because openrice is using dummy email account that generated by hungryhub, it will waste the quota of email in Netcore if we send the event.
1221 1222 1223 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1221 def skip_sending_netcore_event? by_marketplace? && openrice_channel? end |
#special_request_without_package_menus ⇒ Object
sr.gsub(',', '
') end
194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 194 def sentences = [] special_request.to_s.split(',').each do |sentence| if sentence.include?('(') && sentence.include?('X') sentences.push(sentence.split('(').first.strip) break else sentences.push(sentence.strip) end end sentences.join(',').strip.presence || nil end |
#start_time=(value) ⇒ Object
414 415 416 417 418 419 420 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 414 def start_time=(value) self[:start_time] = if value.nil? nil else value.to_s end end |
#start_time_and_date_changed? ⇒ Boolean
1229 1230 1231 1232 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1229 def start_time_and_date_changed? (date_will_change! && changed_attributes.include?('date')) || (start_time_will_change! && changed_attributes.include?('start_time')) end |
#start_time_format ⇒ Object
410 411 412 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 410 def start_time_format start_time&.strftime('%H:%M') end |
#status ⇒ Object
503 504 505 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 503 def status ::I18n.t("views.booking.#{status_as_symbol}") end |
#status_as_symbol ⇒ Object
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 467 def status_as_symbol if active? && is_temporary? :waiting_for_payment elsif no_show? :no_show elsif arrived? :arrived elsif !active? && !ack? if cancelled_by && cancelled_by.to_sym == :user :cancelled else :rejected end elsif !active? if adjusted? :cancel_modified elsif has_cancelled_with_refund? :cancelled_with_refund elsif refund? :refund else :cancelled end elsif !ack? if confirmed_by.blank? :pending_confirmation else :rejected end elsif prepared? :order_being_prepared else :pending_arrival end end |
#status_changed? ⇒ Boolean
1150 1151 1152 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1150 def status_changed? active_changed? || is_temporary_changed? || no_show_changed? || arrived_changed? || ack_changed? end |
#status_for_owner ⇒ Object
459 460 461 462 463 464 465 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 459 def status_for_owner if service_type == 'delivery' owner_delivery_progress(delivery_status) else status end end |
#tagthai_channel? ⇒ Boolean
1138 1139 1140 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1138 def tagthai_channel? channel_uri_name == ApiVendorV1::Constants::TAG_THAI_CHANNEL_URI end |
#temporary_lock? ⇒ Boolean
78 79 80 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 78 def temporary_lock? for_locking_system? end |
#true_wallet_for_payment_expired_at ⇒ Object
292 293 294 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 292 def true_wallet_for_payment_expired_at (payment_start_from.presence || created_at) + AdminSetting.true_wallet_count_down_in_minute.to_i.minute end |
#true_wallet_url ⇒ Object
1112 1113 1114 1115 1116 1117 1118 1119 1120 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1112 def true_wallet_url # temporary use a random URL because true wallet page is not ready yet Figaro.env.hh_host_url # return '' if true_wallet_provider.blank? # url = Rails.application.routes.url_helpers.true_wallet_page_path(id: to_url_hash) # "#{Figaro.env.hh_host_url}#{url}" end |
#upcoming? ⇒ Boolean
395 396 397 398 399 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 395 def upcoming? now = Time.now_in_tz(restaurant.time_zone) active? && ack? && now < reservation_time end |
#use_third_party_reservation? ⇒ Boolean
1202 1203 1204 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1202 def use_third_party_reservation? restaurant.inventory_source.inv_source != ApiVendorV1::Constants::HUNGRYHUB_INV_SOURCE_NAME end |
#username ⇒ Object
537 538 539 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 537 def username name end |
#valid_to_cancel_temporary_booking? ⇒ Boolean
693 694 695 696 697 698 699 700 701 702 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 693 def valid_to_cancel_temporary_booking? return true if for_locking_system? return true if is_temporary? && (cc_provider.present? || promptpay_provider.present? || alipay_provider.present? || wechat_pay_provider.present?) false end |
#voucher_codes_humanize ⇒ Object
341 342 343 344 345 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 341 def voucher_codes_humanize return '' if vouchers.blank? vouchers.map(&:voucher_code).to_sentence end |
#voucher_names_humanize ⇒ Object
347 348 349 350 351 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 347 def voucher_names_humanize return '' if vouchers.blank? vouchers.map(&:name).to_sentence end |
#vouchers_amount ⇒ Object
329 330 331 332 333 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 329 def vouchers_amount return 0 if vouchers.blank? vouchers.sum(&:amount).amount.to_i end |
#web_url ⇒ Object
1066 1067 1068 1069 1070 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1066 def web_url url = web_v2_host_vendor || AdminSetting.web_v2_host "#{url}/restaurants/#{restaurant.friendly_id}/landing/#{to_url_hash}" end |
#web_v2_host_vendor ⇒ Object
1128 1129 1130 1131 1132 |
# File 'lib/model_ext/reservations/instance_methods.rb', line 1128 def web_v2_host_vendor return aoa_reservation.web_v2_host if aoa_channel? vendor_reservation&.web_v2_host end |