Class: PendingTransaction
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- PendingTransaction
- Defined in:
- app/models/pending_transaction.rb
Overview
Schema Information
Table name: pending_transactions
id :bigint not null, primary key
adult :integer
charge_amount_type :string(191)
charge_percent :integer default(0)
charge_price :integer default(0)
charge_type :string(191)
date :date
delivery_fee :string(191)
delivery_fee_in_baht :string(191)
delivery_fee_per_km_in_baht :string(191)
delivery_time :string(191)
distance_to_restaurant :decimal(10, 6) default(0.0)
email :string(191)
end_time :time
group_booking :boolean default(FALSE)
is_order_now :boolean default(FALSE)
kids :integer default(0)
name :string(255)
note :text(16777215)
package_data :json
party_size :integer
phone :string(191)
service_type :string(191)
special_request :text(16777215)
start_time :time
total_price :integer default(0)
created_at :datetime not null
updated_at :datetime not null
address_id :bigint
dining_occasion_id :bigint
restaurant_id :bigint
user_id :bigint
Indexes
index_pending_transactions_on_address_id (address_id)
index_pending_transactions_on_date (date)
index_pending_transactions_on_dining_occasion_id (dining_occasion_id)
index_pending_transactions_on_restaurant_id (restaurant_id)
index_pending_transactions_on_service_type (service_type)
index_pending_transactions_on_start_time (start_time)
index_pending_transactions_on_user_id (user_id)
Constant Summary collapse
- Rpackage =
ImmutableStruct.new(:type_short, :type, :formatted_packages, :amount, :currency, :packages_bought, :revenue, :revenue_amount)
Instance Method Summary collapse
- #delivery? ⇒ Boolean
- #dine_in? ⇒ Boolean
- #package_bought ⇒ Object
- #package_obj ⇒ Object
- #self_pickup? ⇒ Boolean
- #voucher ⇒ Object
- #vouchers ⇒ Object
Methods inherited from ApplicationRecord
Instance Method Details
#delivery? ⇒ Boolean
78 79 80 |
# File 'app/models/pending_transaction.rb', line 78 def delivery? service_type.to_sym == :delivery end |
#dine_in? ⇒ Boolean
86 87 88 |
# File 'app/models/pending_transaction.rb', line 86 def dine_in? service_type.to_sym == :dine_in end |
#package_bought ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/pending_transaction.rb', line 90 def package_bought if package.present? package[:package_data].map do |item| package = HhPackage::RestaurantPackage.find(item[:restaurant_package_id]).package 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 data end else {} end end |
#package_obj ⇒ Object
114 115 116 117 118 119 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 |
# File 'app/models/pending_transaction.rb', line 114 def package_obj return nil if package.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}", expires_in: 1.hour) 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 packages = package[:package_data].map do |data| name = klass.find_by(id: data[:id])&.name price = HhMoney.new(data[:price_cents], data[:price_currency]) data.merge(name: name, net_price: price.format_rounded, amount: price.amount, 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| I18n.t("views.booking.package_data_for_customer.#{package[:package_type]}", name: p[:name], net_price: p[:net_price], quantity: p[:quantity]) end Rpackage.new(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 |
#self_pickup? ⇒ Boolean
82 83 84 |
# File 'app/models/pending_transaction.rb', line 82 def self_pickup? service_type.to_sym == :pick_up end |
#voucher ⇒ Object
70 71 72 |
# File 'app/models/pending_transaction.rb', line 70 def voucher Voucher.new end |
#vouchers ⇒ Object
74 75 76 |
# File 'app/models/pending_transaction.rb', line 74 def vouchers Voucher.where('1 = 0') end |