Class: Vendors::RestaurantPackages::SerializerHelper
- Inherits:
-
Object
- Object
- Vendors::RestaurantPackages::SerializerHelper
- Defined in:
- app/my_lib/vendors/restaurant_packages/serializer_helper.rb
Instance Method Summary collapse
- #currency_code_for(object) ⇒ Object
- #date_query ⇒ Object
- #find_tnc_link(package) ⇒ Object
- #get_vendor_commission_excluded_price_percentage(restaurant_id) ⇒ Object
- #is_openrice?(vendor_name) ⇒ Boolean
- #original_kid_price_v2(object, params) ⇒ Object
- #original_price_calc(object) ⇒ Object
- #package ⇒ Object
- #restaurant ⇒ Object
- #time_slots_data_v1(_date, _inv_checker) ⇒ Object
- #time_slots_data_v2(_date, _inv_checker) ⇒ Object
- #vendor_net_price_format(object, price_cents) ⇒ Object
- #we_travel_together ⇒ Object
Instance Method Details
#currency_code_for(object) ⇒ Object
52 53 54 55 |
# File 'app/my_lib/vendors/restaurant_packages/serializer_helper.rb', line 52 def currency_code_for(object) restaurant_package = object.package.restaurant_packages.first restaurant_package&.restaurant&.currency_code || 'THB' end |
#date_query ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/my_lib/vendors/restaurant_packages/serializer_helper.rb', line 34 def date_query @date_query ||= begin date = [:time_slots_date].presence || Time.use_zone(restaurant.time_zone) do Time.zone.today end date = date.to_date unless date.is_a?(Date) date end end |
#find_tnc_link(package) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/my_lib/vendors/restaurant_packages/serializer_helper.rb', line 7 def find_tnc_link(package) return package.tnc_image_url if package.tnc_image_url.present? # if package is xperience and don't have tnc will use from image menu url xp_tnc_url = if package.type_short == 'xp' && package..present? package..order(index_number: :desc).first.image_url end link = xp_tnc_url || AdminSetting.send("term_condition_link_#{package.route_name}".to_sym).presence || nil return nil if link.blank? link = "#{Figaro.env.CDN_URL!}#{link}" unless link.include?('http') link end |
#get_vendor_commission_excluded_price_percentage(restaurant_id) ⇒ Object
95 96 97 |
# File 'app/my_lib/vendors/restaurant_packages/serializer_helper.rb', line 95 def get_vendor_commission_excluded_price_percentage(restaurant_id) [4503, 837].include?(restaurant_id) ? 0.945 : 0.93 end |
#is_openrice?(vendor_name) ⇒ Boolean
3 4 5 |
# File 'app/my_lib/vendors/restaurant_packages/serializer_helper.rb', line 3 def is_openrice?(vendor_name) vendor_name == ApiVendorV1::Constants::OPEN_RICE_VENDOR_NAME end |
#original_kid_price_v2(object, params) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'app/my_lib/vendors/restaurant_packages/serializer_helper.rb', line 86 def original_kid_price_v2(object, params) price_finder = HhPackage::ReservationPackages::PriceFinder.new use_dynamic_pricing: params[:support_dynamic_pricing] pricing = price_finder.kids_price_list(object.package) pricing.map do |price| price_float = (price[:price_cents].to_d / 100.to_d).round(2, BigDecimal::ROUND_CEILING).to_f price.merge(price_float: price_float) end end |
#original_price_calc(object) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/my_lib/vendors/restaurant_packages/serializer_helper.rb', line 57 def original_price_calc(object) price = (object.package.package_attr&.original_price&.amount&.ceil || 0).to_i price_cents = object.package.package_attr&.original_price_cents.to_i currency_code = currency_code_for(object) if price.zero? { price: nil, price_float: nil, price_cents: nil, currency: currency_code.presence || 'THB', format: '', } else price_currency = object.package.package_attr&.price_currency.presence || currency_code_for(object) { price: price, price_float: (price_cents.to_d / 100.to_d).round(2, BigDecimal::ROUND_CEILING).to_f, price_cents: price_cents, currency: price_currency, format: HhMoney.new(price_cents, price_currency).format_rounded(round: :up), } end end |
#package ⇒ Object
48 49 50 |
# File 'app/my_lib/vendors/restaurant_packages/serializer_helper.rb', line 48 def package @package ||= object.fetch_package end |
#restaurant ⇒ Object
44 45 46 |
# File 'app/my_lib/vendors/restaurant_packages/serializer_helper.rb', line 44 def restaurant @restaurant ||= Restaurant.includes(primary_tags: :restaurant_tag).find(object.restaurant_id).decorate end |
#time_slots_data_v1(_date, _inv_checker) ⇒ Object
26 27 28 |
# File 'app/my_lib/vendors/restaurant_packages/serializer_helper.rb', line 26 def time_slots_data_v1(_date, _inv_checker) [] end |
#time_slots_data_v2(_date, _inv_checker) ⇒ Object
22 23 24 |
# File 'app/my_lib/vendors/restaurant_packages/serializer_helper.rb', line 22 def time_slots_data_v2(_date, _inv_checker) [] end |
#vendor_net_price_format(object, price_cents) ⇒ Object
81 82 83 84 |
# File 'app/my_lib/vendors/restaurant_packages/serializer_helper.rb', line 81 def vendor_net_price_format(object, price_cents) price_currency = object.package.package_attr&.price_currency.presence || currency_code_for(object) HhMoney.new(price_cents, price_currency).to_s end |
#we_travel_together ⇒ Object
30 31 32 |
# File 'app/my_lib/vendors/restaurant_packages/serializer_helper.rb', line 30 def we_travel_together { name: 'We travel together', icon_url: AdminSetting.wtt_image_url.strip } end |