Module: ModelExt::Reservations::PartnerInstanceMethods

Includes:
ProgressStatus
Included in:
Reservation
Defined in:
lib/model_ext/reservations/partner_instance_methods.rb

Overview

actually this is ReservationDecorator previously

Instance Method Summary collapse

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

#customer_icon(custom_url = nil) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 71

def customer_icon(custom_url = nil)
  if corporate_event_id.present? && corporate_event_id != 0
    ActionController::Base.helpers.image_url('corporate_icon.png')
  elsif by_corporate_employee?
    nil
  elsif custom_url.present?
    custom_url
  elsif user_id.present?
    decorate..url
  end
end

#delivery_detailObject



138
139
140
141
142
143
144
145
146
147
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 138

def delivery_detail
  delivery = {}
  if package && package[:package_type].present? && package[:package_type] == 'hah' && (service_type && service_type.to_sym != :pick_up)
    delivery_fee = original_delivery_fee.to_i
    !distance_to_restaurant.nil? && distance_to_restaurant.positive? ? distance_to_restaurant.round(1).to_f : 0
    details = { detail: address&.detail.to_s, gg_link: delivery_address_link }
    delivery = { delivery_fee: delivery_fee, distance_to_restaurant: distance_to_restaurant, address: details }
  end
  delivery
end

#delivery_status_partnerObject



201
202
203
204
205
206
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
234
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 201

def delivery_status_partner
  if paid_charges.present? || (decorate.paid_by_voucher_full? || decorate.paid_by_voucher_partially?)
    if driver.new_record? || driver.status.nil?
      status = I18n.t('partner.reservations.no_driver_yet').to_s
      text_color = '#E40028'
      bg_color = '#FFEAEB'
    elsif driver.status == 'Delivered'
      status = I18n.t('partner.reservations.delivery_completed').to_s
      text_color = '#2EC743'
      bg_color = '#EEFCEF'
    elsif driver.status == 'Driver Is On The Way To Customer'
      status = I18n.t('partner.reservations.driver_is_on_the_way_to_customer').to_s
      text_color = '#FBA400'
      bg_color = '#FAEFD8'
    elsif driver.status == 'On The Way to Restaurant'
      status = I18n.t('partner.reservations.driver_on_the_way_to_restaurant').to_s
      text_color = '#FBA400'
      bg_color = '#FAEFD8'
    else
      status = delivery_status
      text_color = '#FBA400'
      bg_color = '#FAEFD8'
    end
  else
    status = 'Unpaid'
    text_color = '#E40028'
    bg_color = '#FFEAEB'
  end
  {
    'status' => status,
    'text_color' => text_color,
    'bg_color' => bg_color,
  }
end

#dine_in_status_partnerObject



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 236

def dine_in_status_partner
  status = case status_as_symbol.to_sym
           when :waiting_for_payment
             paid_amount.positive? ? I18n.t('views.booking.pending_arrival') : 'Unpaid'
           when :cancel_modified
             I18n.t('views.booking.cancel_modified')
           when :cancelled
             I18n.t('views.booking.canceled')
           when :pending_arrival
             I18n.t('views.booking.pending_arrival')
           when :arrived
             I18n.t('views.booking.arrived')
           when :no_show
             I18n.t('views.booking.no_show')
           when :refund
             I18n.t('views.booking.refund')
           when :pending_confirmation
             I18n.t('views.booking.pending_confirmation')
           when :rejected
             I18n.t('views.booking.rejected')
           when :order_being_prepared
             I18n.t('views.booking.order_being_prepared')
           else
             status_as_symbol ? status_as_symbol.to_s.split('_').join(' ').titleize : '-'
           end

  if %i[waiting_for_payment
        no_show
        cancelled
        rejected
        pending_confirmation
        cancel_modified].include? status_as_symbol.to_sym
    text_color = '#E40028'
    bg_color = '#FFEAEB'
  elsif %i[refund
           order_being_prepared
           pending_arrival].include? status_as_symbol.to_sym
    text_color = '#FBA400'
    bg_color = '#FAEFD8'
  elsif status_as_symbol.to_sym == :arrived
    text_color = '#125EAF'
    bg_color = '#DAECFF'
  else
    text_color = ''
    bg_color = ''
  end
  {
    'status' => status,
    'status_code' => status_as_symbol,
    'text_color' => text_color,
    'bg_color' => bg_color,
  }
end

#driver_detailsObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 115

def driver_details
  driver_details = {}
  reservation_driver = address.present? ? address.driver : nil
  reservation_delivery_address = reservation_driver ? reservation_driver.delivery_address : nil
  if reservation_driver && reservation_delivery_address.delivery_channel.present?
    delivery_channel = reservation_delivery_address.delivery_channel.name
    delivery_channel_id = reservation_delivery_address.delivery_channel_id
    driver_id = reservation_driver.id
    driver_name = reservation_driver.name || '-'
    driver_phone = reservation_driver.phone || '-'
    driving_to_res = "#{reservation_driver.duration || '0'} Minutes"
    tracking_link = reservation_driver.tracking_link ? courier_tracking_link : nil
    driver_details = { delivery_channel: delivery_channel,
                       delivery_channel_id: delivery_channel_id,
                       driver_id: driver_id,
                       driver_name: driver_name,
                       driver_phone: driver_phone,
                       driving_to_res: driving_to_res,
                       tracking_link: tracking_link }
  end
  driver_details
end

#format_percentage(percentage) ⇒ Object



99
100
101
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 99

def format_percentage(percentage)
  percentage % 1 == 0 ? percentage.to_i : percentage.round(2)
end

#note_to_driverObject



111
112
113
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 111

def note_to_driver
  address&.note_for_driver.presence || nil
end

#package_typeObject



62
63
64
65
66
67
68
69
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 62

def package_type
  {
    service_type: { type: service_type, title: service_type_humanize },
    delivery: delivery_detail,
    note_to_driver: note_to_driver,
    driver_details: driver_details,
  }
end


52
53
54
55
56
57
58
59
60
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 52

def paid_by_admin_status
  if paid_amount.to_f == total_price
    'prepaid'
  elsif paid_amount.to_f > 0 && paid_amount.to_f < total_price
    'has_deposit'
  else
    'no_deposit'
  end
end


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 83

def paid_status
  if charge_type.present? && paid_charges.present?
    if (paid_amount.to_i.positive? && decorate.due_amount.to_i.positive? && decorate.due_amount.to_i < decorate.total_amount.to_i) || (charge_percent.to_i.positive? && charge_percent < 100)
      "Deposit #{charge_percent}%"
    else
      "Paid #{charge_percent}%"
    end
  elsif decorate.paid_by_voucher_full?
    'Paid by voucher 100%'
  elsif decorate.paid_by_voucher_partially?
    'Paid by voucher'
  elsif decorate.paid_by_admin_or_owner?
    "Paid (#{format_percentage(decorate.paid_percentage_by_admin_or_owner)}%)"
  end
end

#partner_status_propertyObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 149

def partner_status_property
  driver || build_driver
  if active?
    case service_type.to_sym
    when :delivery
      delivery_status_partner
    when :dine_in
      dine_in_status_partner
    else
      self_pickup_status_partner
    end
  else
    status = if for_locking_system? || is_temporary?
               'Payment Failed'
             else
               'Cancelled'
             end
    text_color = '#E40028'
    bg_color = '#FFEAEB'
    {
      'status' => status,
      'text_color' => text_color,
      'bg_color' => bg_color,
    }
  end
end

#payment_methodObject



103
104
105
106
107
108
109
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 103

def payment_method
  if active_reservation_vouchers.select { |v| v.voucher.voucher_category == :gift_card }.present?
    'gift_card'
  elsif payment_type_provider
    payment_type_provider
  end
end

#payment_statusObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 38

def payment_status
  if decorate.paid_by_admin_or_owner?
    return paid_by_admin_status
  end

  if charges.present? && charge_price == total_price
    'prepaid'
  elsif charges.present? && charge_price != total_price
    'has_deposit'
  elsif charges.blank?
    'no_deposit'
  end
end

#payment_summaryObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 8

def payment_summary
  voucher = []
  active_reservation_vouchers.find_each do |val|
    voucher << {
      name: val.voucher.name,
      discount: ActionController::Base.helpers.humanized_money_with_symbol(val.amount),
    }
  end

  delivery_fee = if package && package[:package_type].present? && package[:package_type] == 'hah'
                   { delivery_fee: format_to_decimal(original_delivery_fee.to_d) }
                 else
                   {}
                 end

  prepaid_amount = if vendor_reservation&.reference_id.present?
                     package? ? package_obj.amount : nil
                   else
                     paid_amount.amount
                   end

  {
    total: format_to_decimal(decorate.total_amount - decorate.original_delivery_fee.to_d),
    voucher: voucher,
    prepaid: format_to_decimal(prepaid_amount),
    method: payment_type_provider || nil,
    due: format_to_decimal(decorate.due_amount.amount),
  }.merge(delivery_fee)
end

#self_pickup_status_partnerObject



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/model_ext/reservations/partner_instance_methods.rb', line 176

def self_pickup_status_partner
  if self_pickup_ack == false
    status = I18n.t('partner.reservations.order_received').to_s
    text_color = '#BC64FF'
    bg_color = '#F1E1FD'
  elsif self_pickup_ack == true && waiting_for_pick_up == false
    status = I18n.t('partner.reservations.your_order_in_the_kitchen').to_s
    text_color = '#FBA400'
    bg_color = '#FAEFD8'
  elsif self_pickup_ack == true && waiting_for_pick_up == true && arrived == false
    status = I18n.t('partner.reservations.waiting_for_pick_up').to_s
    text_color = '#FBA400'
    bg_color = '#FAEFD8'
  elsif self_pickup_ack == true && waiting_for_pick_up == true && arrived == true
    status = I18n.t('partner.reservations.order_completed').to_s
    text_color = '#2EC743'
    bg_color = '#EEFCEF'
  end
  {
    'status' => status,
    'text_color' => text_color,
    'bg_color' => bg_color,
  }
end