Class: C2eCore::Drops::OrderDrop

Inherits:
BaseDrop
  • Object
show all
Defined in:
/build/app/mailers/c2e_core/drops/order_drop.rb

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ OrderDrop

Returns a new instance of OrderDrop.



6
7
8
9
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 6

def initialize(order)
  super()
  @order = order
end

Instance Method Details

#accepted_atDateTime

Returns - Datetime object containing value when order was submitted by customer. E.g.: "2020-11-16T11:38:56+01:00".

Returns:

  • (DateTime)
    • Datetime object containing value when order was submitted by customer.

    E.g.: "2020-11-16T11:38:56+01:00"



32
33
34
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 32

def accepted_at
  @order.accepted_at
end

#admin_customer_detail_urlString

Returns - URL redirecting to current customer detail in staff admin application.

Returns:

  • (String)
    • URL redirecting to current customer detail in staff admin application.



133
134
135
136
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 133

def admin_customer_detail_url
  url = URI.join(URI(Rails.application.config.options.admin_app_url), "overview/customer")
  "#{url}?phone=#{CGI.escape(customer.phone)}"
end

#admin_order_detail_urlString

Returns - URL redirecting to order detail in staff admin application.

Returns:

  • (String)
    • URL redirecting to order detail in staff admin application.



127
128
129
130
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 127

def admin_order_detail_url
  url = URI.join(URI(Rails.application.config.options.admin_app_url), "order/detail")
  "#{url}?orderId=#{@order.id}"
end

#canceled?Boolean

Returns - Returns true if the order is canceled, and false otherwise.

Returns:

  • (Boolean)
    • Returns true if the order is canceled, and false otherwise.



233
234
235
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 233

def canceled?
  @order.canceled?
end

#cash_boxCashBoxDrop

Returns - Returns orders cash box as drop object if it is present.

Returns:

  • (CashBoxDrop)
    • Returns orders cash box as drop object if it is present.



218
219
220
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 218

def cash_box
  CashBoxDrop.new(@order.cash_box) if @order.cash_box_id.present?
end

#company_branchCompanyBranchDrop

Returns - Company branch to which order belongs as drop object.

Returns:



58
59
60
61
62
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 58

def company_branch
  stored_value __method__ do
    CompanyBranchDrop.new @order.company_branch
  end
end

#credits_rewardCreditsRewardDrop?

Returns - The credits reward as a drop object, if it is present. Otherwise, null.

Returns:

  • (CreditsRewardDrop, nil)
    • The credits reward as a drop object, if it is present.

    Otherwise, null.



239
240
241
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 239

def credits_reward
  CreditsRewardDrop.new(@order.credits_reward) if @order.credits_reward.present?
end

#credits_walletsArray[CreditsWalletDrop]

Returns - An array of credit wallets as drop objects.

Returns:



262
263
264
265
266
267
268
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 262

def credits_wallets
  stored_value __method__ do
    @order.credits_wallets.map do |credit_wallet|
      CreditsWalletDrop.new(credit_wallet)
    end
  end
end

#currencyCurrencyDrop

Returns - Orders currency object. By default it is taken from company branch.

Returns:

  • (CurrencyDrop)
    • Orders currency object. By default it is taken from company branch.



37
38
39
40
41
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 37

def currency
  stored_value __method__ do
    CurrencyDrop.new @order.currency
  end
end

#customerCustomerDrop

Returns - Customer as drop object.

Returns:



44
45
46
47
48
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 44

def customer
  stored_value __method__ do
    CustomerDrop.new @order
  end
end

#customer_track_urlString

Returns - URL redirecting to finish screen of customers application. URL format is https://some_customer.app.speedlo_service.domain/finish?orderId=[Integer]&userToken=[String].

Returns:

  • (String)
    • URL redirecting to finish screen of customers application.

    URL format is https://some_customer.app.speedlo_service.domain/finish?orderId=[Integer]&userToken=[String]



117
118
119
120
121
122
123
124
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 117

def customer_track_url
  stored_value __method__ do
    finish_path = @order.legacy_application? ? "finish" : "order-tracking"
    url = URI.join(URI(@order.base_url), finish_path)
    token = Base64.urlsafe_encode64(@order.confirmation_token)
    "#{url}?orderId=#{@order.id}&userToken=#{token}"
  end
end

#data_from_terminalString?

Returns - Returns the data we received from the terminal after a successful transaction, if present.

Returns:

  • (String, nil)
    • Returns the data we received from the terminal after

    a successful transaction, if present.



245
246
247
248
249
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 245

def data_from_terminal
  return @order.terminal_transaction_records.successful.last&.data unless @order.canceled?

  @order.terminal_transaction_records.successful.refund.last&.data
end

#delayed_delivery_timeDateTime

Returns - Returns time which customer specifically chosen. Can differ from #deliver_at and always has same value.

Returns:

  • (DateTime)
    • Returns time which customer specifically chosen. Can differ from #deliver_at and

    always has same value.



106
107
108
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 106

def delayed_delivery_time
  @order.delayed_delivery_time
end

#deliver_atTime

Returns - Returns current time of expected delivery. Can be changed by staff. E.g.: 2022-10-31 15:56:02 +0100.

Returns:

  • (Time)
    • Returns current time of expected delivery. Can be changed by staff.

    E.g.: 2022-10-31 15:56:02 +0100



94
95
96
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 94

def deliver_at
  @order.deliver_at
end

#deliver_at_minutesInteger

Returns - Returns number of minutes remaining to current deliver_at time. Result is rounded to multiples of 5.

Returns:

  • (Integer)
    • Returns number of minutes remaining to current deliver_at time. Result is rounded

    to multiples of 5.



77
78
79
80
81
82
83
84
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 77

def deliver_at_minutes
  stored_value __method__ do
    minutes = (@order.deliver_at - DateTime.now) / 60
    remainder = minutes % 5
    minutes = minutes - remainder + 5 if remainder > 0
    minutes.to_i
  end
end

#delivered_atTime?

Returns - Returns current time of delivery. Can be changed by staff. E.g.: 2022-10-31 15:56:02 +0100.

Returns:

  • (Time, nil)
    • Returns current time of delivery. Can be changed by staff.

    E.g.: 2022-10-31 15:56:02 +0100



100
101
102
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 100

def delivered_at
  @order.delivered_at
end

#delivery_today?Boolean

Returns - Returns true when deliver_at time is today.

Returns:

  • (Boolean)
    • Returns true when deliver_at time is today.



111
112
113
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 111

def delivery_today?
  @order.deliver_at.today?
end

#delivery_type_enumString

Returns - DeliveryType.enum value. E.g.: MESSENGER, PICKUP. Returns nil for inhouse order.

Returns:

  • (String)
    • DeliveryType.enum value. E.g.: MESSENGER, PICKUP. Returns nil for inhouse

    order.



71
72
73
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 71

def delivery_type_enum
  @order.delivery_type&.code&.upcase
end

#flat_itemsArray[OrderRecipeFlatDrop]

Returns - Returns a flat array of main order recipes as drop objects. Doesn’t group the same recipes with side dishes.

Returns:

  • (Array[OrderRecipeFlatDrop])
    • Returns a flat array of main order recipes as drop objects.

    Doesn’t group the same recipes with side dishes.



183
184
185
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 183

def flat_items
  @order.flat_order_recipes.map { |flat_item| OrderRecipeFlatDrop.new flat_item, @order }
end

#flat_ware_category_itemsArray[OrderWareCategoryFlatDrop]

Returns - Returns a flat array of orders ware categories as drop objects ordered by recipes where this ware category was first.

Returns:

  • (Array[OrderWareCategoryFlatDrop])
    • Returns a flat array of orders ware categories as drop objects

    ordered by recipes where this ware category was first.



189
190
191
192
193
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 189

def flat_ware_category_items
  @order.flat_order_recipes
        .group_by { |flat_item| flat_item[:recipe].ware_categories_in.order(created_at: :asc).first }
        .map { |ware_category, flat_recipes| OrderWareCategoryFlatDrop.new ware_category, flat_recipes, @order }
end

#has_delivery?Boolean

Returns - Returns true when order is supposed to be delivered by messenger.

Returns:

  • (Boolean)
    • Returns true when order is supposed to be delivered by messenger.



65
66
67
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 65

def has_delivery?
  @order.delivery_type_id == DeliveryType.the_messenger.id
end

#idInteger

Returns - ID of order.

Returns:

  • (Integer)
    • ID of order



15
16
17
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 15

def id
  @order.id
end

#invoice_promosArray<InvoicePromoDrop>

Returns - An array of invoice promos as drop objects.

Returns:



280
281
282
283
284
285
286
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 280

def invoice_promos
  stored_value __method__ do
    @order.invoice_promos.map do |invoice_promo|
      InvoicePromoDrop.new(invoice_promo)
    end
  end
end

#main_itemsArray[OrderRecipeDrop]

Returns - Returns an array of main orders’ recipes with name and price as drop objects.

Returns:

  • (Array[OrderRecipeDrop])
    • Returns an array of main orders’ recipes with name and price as drop objects.



196
197
198
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 196

def main_items
  @order.order_recipes.mains.map { |main_item| OrderRecipeDrop.new main_item, @order }
end

#noteString

Returns - text of first info note. E.g.: "Pozor pes, počkat venku!".

Returns:

  • (String)
    • text of first info note. E.g.: "Pozor pes, počkat venku!"



51
52
53
54
55
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 51

def note
  stored_value __method__ do
    @order.notes.info.first&.text.to_s
  end
end

#online?Boolean

Returns - Returns true when order was paid by card in online gate.

Returns:

  • (Boolean)
    • Returns true when order was paid by card in online gate.



139
140
141
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 139

def online?
  @order.online?
end

#online_payment_idInteger

Returns - Returns id from customer_json gopay hash.

Returns:

  • (Integer)
    • Returns id from customer_json gopay hash



223
224
225
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 223

def online_payment_id
  @order.online_payment_id
end

#order_originOrderOriginDrop

Returns - Returns order origin as drop object with name. E.g.: "Web", "Staff", "foodora"..

Returns:

  • (OrderOriginDrop)
    • Returns order origin as drop object with name.

    E.g.: "Web", "Staff", "foodora".



208
209
210
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 208

def order_origin
  OrderOriginDrop.new(@order.order_origin)
end

#order_payment_methodsArray[OrderPaymentMethodDrop]

Returns - An array of order payment methods as drop objects.

Returns:



252
253
254
255
256
257
258
259
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 252

def order_payment_methods
  stored_value __method__ do
    records = @order.order_payment_methods.includes(payment_method: [:payment_gate, :payment_type, :country])
    records.map do |order_payment_method|
      OrderPaymentMethodDrop.new(order_payment_method)
    end
  end
end

#payment_method_enumsArray

Returns - An array containing the concatenation of PaymentType.enum and PaymentGate.enum values for all orders’ payment methods. E.g.: ["CREDIT_CSOB", "WALLET_CREDIT_WALLET_CREDIT"].

Returns:

  • (Array)
    • An array containing the concatenation of PaymentType.enum and PaymentGate.enum values

    for all orders’ payment methods. E.g.: ["CREDIT_CSOB", "WALLET_CREDIT_WALLET_CREDIT"].



157
158
159
160
161
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 157

def payment_method_enums
  stored_value __method__ do
    @order.payment_methods.includes(:payment_gate, :payment_type).map(&:enum_description)
  end
end

#payment_method_enums_without_wallet_creditArray

Returns - An array containing the concatenation of PaymentType.enum and PaymentGate.enum values for all orders’ payment methods, excluding credit payments. If an order is fully paid using credits, an empty array is returned. E.g.: ["CREDIT_CSOB", "CASH_CASH"].

Returns:

  • (Array)
    • An array containing the concatenation of PaymentType.enum and PaymentGate.enum values

    for all orders’ payment methods, excluding credit payments. If an order is fully paid using credits, an empty array is returned. E.g.: ["CREDIT_CSOB", "CASH_CASH"].



167
168
169
170
171
172
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 167

def payment_method_enums_without_wallet_credit
  payment_methods = @order.payment_methods.without_payment_type(PaymentType.the_wallet_credit)
    .includes(:payment_gate, :payment_type)

  payment_methods.map(&:enum_description)
end

#priceOrderPriceDrop

Returns - Returns orders price as drop object.

Returns:



175
176
177
178
179
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 175

def price
  stored_value __method__ do
    OrderPriceDrop.new @order
  end
end

#purchased_credits_walletCreditsWalletDrop?

Returns - A credit wallet that was purchased with the order as a drop object or nil.

Returns:

  • (CreditsWalletDrop, nil)
    • A credit wallet that was purchased with the order as a drop object or nil.



271
272
273
274
275
276
277
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 271

def purchased_credits_wallet
  stored_value __method__ do
    next if @order.purchased_credits_wallet.nil?

    CreditsWalletDrop.new(@order.purchased_credits_wallet)
  end
end

#qr_with_idString

Returns - QR code including Order#id as data-URL. E.g.: "data:image/png;base64,iVBO.....". Current width of image is 400px.

Returns:

  • (String)
    • QR code including Order#id as data-URL. E.g.:

    "data:image/png;base64,iVBO.....". Current width of image is 400px.



21
22
23
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 21

def qr_with_id
  RQRCode::QRCode.new(@order.id.to_s).as_png(size: 400, border_modules: 0).to_data_url
end

#ratingsArray[OrderRatingDrop]

Returns - Returns an array of order rating notes as drop objects with quality evaluation from customer and text message e.g.: "Dobra, ale těsto bylo trochu tuhé.".

Returns:

  • (Array[OrderRatingDrop])
    • Returns an array of order rating notes as drop objects with

    quality evaluation from customer and text message e.g.: "Dobra, ale těsto bylo trochu tuhé."



202
203
204
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 202

def ratings
  @order.rating_notes.map { |rating| OrderRatingDrop.new rating }
end

#require_age_control?Boolean

Returns - Returns true when order contains a recipe that requires age control, and false otherwise.

Returns:

  • (Boolean)
    • Returns true when order contains a recipe that requires age control, and false otherwise.



228
229
230
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 228

def require_age_control?
  @order.require_age_control?
end

#resettable_idInteger

Returns - Resettable ID of order. E.g.: 142.

Returns:

  • (Integer)
    • Resettable ID of order. E.g.: 142



26
27
28
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 26

def resettable_id
  @order.final&.dig("invoice", "resettable_sequence")
end

#simplified_payment_methodString

Deprecated.

This method is deprecated and will be removed in future versions. Use #payment_method_enums instead. Reason: This method may return incorrect values for orders paid using multiple payment methods.

Returns - Cotains concatenation of PaymentType.enum and PaymentGate.enum E.g.: CREDIT_CREDIT, CREDIT_CSOB, CASH_CASH, etc.

Returns:

  • (String)
    • Cotains concatenation of PaymentType.enum and PaymentGate.enum

    E.g.: CREDIT_CREDIT, CREDIT_CSOB, CASH_CASH, etc.



148
149
150
151
152
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 148

def simplified_payment_method
  stored_value __method__ do
    @order.payment_methods.first.enum_description
  end
end

#time_deliver_atDateTime

Returns - Returns current date and time of expected delivery. Can be changed by staff. E.g.: 14:51.

Returns:

  • (DateTime)
    • Returns current date and time of expected delivery. Can be changed by staff.

    E.g.: 14:51



88
89
90
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 88

def time_deliver_at
  I18n.l(@order.deliver_at, format: :just_time) if @order.deliver_at.present?
end

#userUserDrop

Returns - Returns user who created order as drop object.

Returns:

  • (UserDrop)
    • Returns user who created order as drop object.



213
214
215
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 213

def user
  UserDrop.new(@order.user)
end