Class: StaffMailer

Inherits:
ApplicationMailer show all
Includes:
ActionView::Helpers::TextHelper, CountryEmailHelper
Defined in:
app/mailers/staff_mailer.rb

Overview

typed: ignore frozen_string_literal: true

Instance Method Summary collapse

Methods included from CountryEmailHelper

#merchant_email_for_country

Methods inherited from ApplicationMailer

#log_mailer, #switch_locale

Methods included from Workers::Helpers

#parse_json

Instance Method Details

#assist_group_booking(reservation_id) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'app/mailers/staff_mailer.rb', line 177

def assist_group_booking(reservation_id)
  @reservation = Reservation.fetch(reservation_id).decorate
  @restaurant = @reservation.restaurant
  @manage_link_as_admin = edit_admin_reservation_url(@reservation.id)
  @menu_link = menu_link(@reservation)
  @as_qr_code = "#{url_helpers.root_url}id_to_qrcode?id=#{@reservation.id}"
  subject_prefix = if @reservation.use_third_party_reservation?
                     "(#{@reservation.restaurant.inventory_source.inv_source.capitalize})"
                   else
                     ''
                   end
  subject = "Action Needed - Big Group Booking Pending #{subject_prefix}"
  BUSINESS_LOGGER.info subject, body: "there is new group booking asking for help, ID: #{reservation_id}"
  receivers = [SUPPORT_EMAIL, CORPORATE_EMAIL]
   = @reservation.restaurant&.user&.email
  receivers.push() if .present?
  mail(to: receivers, subject: subject, from: BOOKINGS_EMAIL)
  log_mailer({
               reservation_id: reservation_id,
               restaurant_id: @reservation.restaurant_id,
               email: receivers,
               name: 'StaffMailer#assist_group_booking',
               subject: subject,
               from: BOOKINGS_EMAIL,
             })
end

#booking_cancel(reservation_id) ⇒ Object



106
107
108
109
110
111
112
113
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
# File 'app/mailers/staff_mailer.rb', line 106

def booking_cancel(reservation_id)
  reservation = Reservation.find(reservation_id)
  restaurant = reservation.restaurant
  return unless restaurant.active?

  template_name = 'v4-hh-booking-cancel'
  subject = I18n.t('mailer.staff.reservation.cancel', name: restaurant.name, id: reservation.id)
  year = Time.current.year
  reservation_time_v2 = reservation.date.strftime("%A, %B #{ActiveSupport::Inflector.ordinalize(reservation.date.day)}, %Y")

  mail(subject: subject, to: RESERVATION_EMAIL_RECEIVER, from: BOOKINGS_EMAIL, reply_to: SUPPORT_EMAIL) do |format|
    format.html do
      render template: "staff_mailer/#{template_name}", locals: {
        reservation: reservation,
        restaurant: restaurant,
        subject: subject,
        year: year,
        reservation_time_v2: reservation_time_v2,
      }
    end
  end

  log_mailer(
    {
      reservation_id: reservation.id,
      restaurant_id: restaurant.id,
      email: RESERVATION_EMAIL_RECEIVER,
      name: 'StaffMailer#booking_cancel',
      subject: subject,
      from: BOOKINGS_EMAIL,
      reply_to: SUPPORT_EMAIL,
    },
  )
end

#booking_confirm(reservation_id) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/mailers/staff_mailer.rb', line 30

def booking_confirm(reservation_id)
  reservation = Reservation.find(reservation_id)
  return if reservation.restaurant_id == HH_TRAINING_ID

  restaurant = reservation.restaurant
  return unless restaurant.active?

  template_name = if reservation.package?
                    'v6-staff-booking-confirm'
                  else
                    'v4-staff-booking-confirm'
                  end

  owner_mark_as_canceled = url_helpers.reservation_owner_update_url(
    reservation.to_url_hash,
    owner: restaurant.owner.to_url_hash,
    type: 'cancel',
  )
  reservation_show_page_link = url_helpers.manage_my_reservations_url(reservation.to_url_hash)
  owner_reservation_link = url_helpers.owner_confirmation_reservation_url(
    restaurant.owner.to_url_hash,
    reservation.to_url_hash,
  )
  reservation_time_v2 = reservation.date.strftime("%A, %B #{ActiveSupport::Inflector.ordinalize(reservation.date.day)}, %Y")
  subject = I18n.t('mailer.staff.reservation.confirm', name: restaurant.name, id: reservation.id)
  year = Time.current.year
  cancel_link = url_helpers.reservation_cancel_url(reservation.to_url_hash)

  mail(subject: subject, to: RESERVATION_EMAIL_RECEIVER, from: BOOKINGS_EMAIL, reply_to: SUPPORT_EMAIL) do |format|
    format.html do
      render template: "staff_mailer/#{template_name}", locals: {
        reservation: reservation,
        restaurant: restaurant,
        owner_mark_as_canceled: owner_mark_as_canceled,
        reservation_show_page_link: reservation_show_page_link,
        owner_reservation_link: owner_reservation_link,
        reservation_time_v2: reservation_time_v2,
        subject: subject,
        year: year,
        cancel_link: cancel_link,
      }
    end
  end

  log_mailer(
    {
      reservation_id: reservation.id,
      restaurant_id: restaurant.id,
      email: RESERVATION_EMAIL_RECEIVER,
      name: 'StaffMailer#booking_confirmation',
      subject: subject,
      from: BOOKINGS_EMAIL,
      reply_to: SUPPORT_EMAIL,
    },
  )
end

#booking_pending(reservation_id) ⇒ Object



141
142
143
144
145
146
147
148
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
175
# File 'app/mailers/staff_mailer.rb', line 141

def booking_pending(reservation_id)
  reservation = Reservation.find(reservation_id)
  restaurant = reservation.restaurant
  return unless restaurant.active?

  template_name = 'v3-staff-booking-pending'
  reservation_time_v2 = reservation.date.strftime("%A, %B #{ActiveSupport::Inflector.ordinalize(reservation.date.day)}, %Y")
  subject = I18n.t('mailer.staff.reservation.pending', name: restaurant.name, id: reservation.id)
  year = Time.current.year

  mail(subject: subject, to: RESERVATION_EMAIL_RECEIVER, from: BOOKINGS_EMAIL, reply_to: SUPPORT_EMAIL,
       bcc: SUPPORT_EMAIL_SLACK) do |format|
    format.html do
      render template: "staff_mailer/#{template_name}", locals: {
        reservation: reservation,
        restaurant: restaurant,
        reservation_time_v2: reservation_time_v2,
        subject: subject,
        year: year,
      }
    end
  end

  log_mailer(
    {
      reservation_id: reservation.id,
      restaurant_id: restaurant.id,
      email: RESERVATION_EMAIL_RECEIVER,
      name: 'StaffMailer#booking_pending',
      subject: subject,
      from: BOOKINGS_EMAIL,
      reply_to: SUPPORT_EMAIL,
    },
  )
end

#can_not_booking_restaurant(file_url) ⇒ Object



336
337
338
339
340
341
342
343
344
345
346
# File 'app/mailers/staff_mailer.rb', line 336

def can_not_booking_restaurant(file_url)
  @file_url = file_url
  subject = 'Can not booking restaurant'
  mail(to: HELLO_EMAIL, subject: subject)
  log_mailer({
               email: HELLO_EMAIL,
               name: 'StaffMailer#can_not_booking_restaurant',
               subject: subject,
               other: { file_url: file_url },
             })
end

#delivery_csv(emails, attachment_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/mailers/staff_mailer.rb', line 15

def delivery_csv(emails, attachment_id)
  @attachment = Attachment.find attachment_id
  subject = 'Your report is ready for download'
  BUSINESS_LOGGER.info(subject,
                       body: "Report is ready for download, ID: #{attachment_id}",
                       emails: emails)
  mail(subject: subject, to: emails)
  log_mailer({
               email: emails,
               name: 'StaffMailer#delivery_csv',
               subject: subject,
               other: { attachment_id: attachment_id },
             })
end

#empty_inventory(file_url) ⇒ Object



324
325
326
327
328
329
330
331
332
333
334
# File 'app/mailers/staff_mailer.rb', line 324

def empty_inventory(file_url)
  @file_url = file_url
  subject = 'Empty Inventory Alert'
  mail(to: HELLO_EMAIL, subject: subject)
  log_mailer({
               email: HELLO_EMAIL,
               name: 'StaffMailer#empty_inventory',
               subject: subject,
               other: { file_url: file_url },
             })
end

#forgot_password(staff) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
# File 'app/mailers/staff_mailer.rb', line 299

def forgot_password(staff)
  @staff = staff
  cc = [SUPPORT_EMAIL]
  subject = 'hungryhub.com - Forgot Password'
  mail(to: @staff.email, cc: cc, subject: subject)
  log_mailer({
               email: @staff.email,
               cc: cc,
               name: 'StaffMailer#forgot_password',
               subject: subject,
             })
end

#inventory_reporter(start_date, end_date, body) ⇒ Object



348
349
350
351
352
353
354
355
356
357
358
# File 'app/mailers/staff_mailer.rb', line 348

def inventory_reporter(start_date, end_date, body)
  @body = body
  subject = "Inventory report for #{start_date} until #{end_date}"
  mail(subject: subject,
       to: 'support@hungryhub.com')
  log_mailer({
               email: 'support@hungryhub.com',
               name: 'StaffMailer#inventory_reporter',
               subject: subject,
             })
end

#notify(subject, body, receivers) ⇒ Object



402
403
404
405
406
407
408
409
410
411
# File 'app/mailers/staff_mailer.rb', line 402

def notify(subject, body, receivers)
  @body = body
  BUSINESS_LOGGER.info subject, body: body, receivers: receivers
  mail(to: receivers, subject: subject)
  log_mailer({
               email: receivers,
               name: 'StaffMailer#notify',
               subject: subject,
             })
end

#notify_block_restaurant(restaurant_id, date, start_time, end_time, blocked_by) ⇒ Object



448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'app/mailers/staff_mailer.rb', line 448

def notify_block_restaurant(restaurant_id, date, start_time, end_time, blocked_by)
  @restaurant = restaurant = Restaurant.fetch restaurant_id
  subject = "#{restaurant.name} block their seats"
  receiver = restaurant.user.present? ? restaurant.user.email : merchant_email_for_country(restaurant)
  @date = Date.parse(date.to_s)
  @start_time = start_time
  @end_time = end_time
  @blocked_by = blocked_by
  inv_checker = InvCheckerFactory.new(restaurant.id, restaurant.time_zone).create_inv_checker_service
  @seat_lefts = inv_checker.seat_lefts(@date, HhTime.start_time_to_end_time_interval(start_time, end_time))

  mail(to: receiver, subject: subject)
  log_mailer({
               restaurant_id: restaurant_id,
               email: receiver,
               name: 'StaffMailer#notify_block_restaurant',
               subject: subject,
             })
end

#notify_cancel_auto_call_driver_staff(subject, body) ⇒ Object



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'app/mailers/staff_mailer.rb', line 263

def notify_cancel_auto_call_driver_staff(subject, body)
  receivers = []
  emails = AdminSetting.email_receiver_when_failed_order_driver.split(',')
  emails.each do |email|
    receivers.push(email)
  end
  @body = body
  BUSINESS_LOGGER.info subject, body: body
  mail(subject: subject, to: receivers, from: NO_REPLY_EMAIL, reply_to: SUPPORT_EMAIL, bcc: SUPPORT_EMAIL_SLACK)
  log_mailer({
               email: receivers,
               name: 'StaffMailer#notify_cancel_auto_call_driver_staff',
               subject: subject,
               from: NO_REPLY_EMAIL,
               reply_to: SUPPORT_EMAIL,
             })
end

#notify_driver_error_staff(subject, body) ⇒ Object

Parameters:

  • subject (Subject)
  • message (Message)


249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'app/mailers/staff_mailer.rb', line 249

def notify_driver_error_staff(subject, body)
  @body = body
  BUSINESS_LOGGER.info subject, body: body
  mail(to: [DRIVER_ERROR_RECIPIENT_EMAIL], from: NO_REPLY_EMAIL, reply_to: SUPPORT_EMAIL, bcc: SUPPORT_EMAIL_SLACK,
       subject: subject)
  log_mailer({
               email: DRIVER_ERROR_RECIPIENT_EMAIL,
               name: 'StaffMailer#notify_driver_error_staff',
               subject: subject,
               from: NO_REPLY_EMAIL,
               reply_to: SUPPORT_EMAIL,
             })
end

#notify_error_staff(subject, message, opts = {}) ⇒ Object

Parameters:

  • subject (Subject)
  • message (Message)
  • opts (Hash) (defaults to: {})

    receivers: Array of email addresses to receive as primary recipients notes: Hash of additional information about the notification



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
235
236
237
238
239
240
241
242
243
244
245
# File 'app/mailers/staff_mailer.rb', line 209

def notify_error_staff(subject, message, opts = {})
  # Get receivers from opts or default to empty array
  receivers = opts.with_indifferent_access.fetch(:receivers, [])

  # Set up CC recipients - always include ERROR_RECIPIENT_EMAIL
  cc_recipients = [SUPPORT_EMAIL]

  # Determine primary recipients
  to_recipients = receivers.presence || OPS_TEAM_EMAIL

  # If receivers is present and includes ERROR_RECIPIENT_EMAIL addresses, remove them from cc
  if receivers.present? && receivers.is_a?(Array)
    cc_recipients = cc_recipients - receivers
  end

  @message = message
  BUSINESS_LOGGER.info subject, body: message

  mail(
    to: to_recipients,
    cc: cc_recipients,
    subject: subject,
    from: NO_REPLY_EMAIL,
    reply_to: SUPPORT_EMAIL,
    bcc: SUPPORT_EMAIL_SLACK,
  ) do |format|
    format.html { render html: @message.html_safe, layout: false }
  end
  log_mailer({
               email: to_recipients,
               cc: cc_recipients,
               name: 'StaffMailer#notify_error_staff',
               subject: subject,
               from: NO_REPLY_EMAIL,
               reply_to: SUPPORT_EMAIL,
             })
end

#notify_html(subject, body, receivers) ⇒ Object



413
414
415
416
417
418
419
420
421
422
423
424
# File 'app/mailers/staff_mailer.rb', line 413

def notify_html(subject, body, receivers)
  @body = body
  BUSINESS_LOGGER.info subject, body: body, receivers: receivers
  mail(to: receivers, subject: subject) do |format|
    format.html { render html: simple_format(@body), layout: false }
  end
  log_mailer({
               email: receivers,
               name: 'StaffMailer#notify_html',
               subject: subject,
             })
end

#notify_managers(current_staff, restaurant, changes, breadcrumb, partner_portal_url, footer_text) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/mailers/staff_mailer.rb', line 87

def notify_managers(current_staff, restaurant, changes, breadcrumb, partner_portal_url, footer_text)
  @changes = changes
  @restaurant = restaurant
  @staff = current_staff
  @breadcrumb = breadcrumb
  @partner_portal_url = partner_portal_url
  @footer_text = footer_text
  @logo_url = MyImageHelper.new.fix_image_url restaurant.reload..url
  manager_emails = restaurant.owner.managers.map(&:email)
  subject = "Notification for #{restaurant.name}"
  mail(to: manager_emails, subject: subject)
  log_mailer({
               restaurant_id: restaurant.id,
               email: manager_emails,
               name: 'StaffMailer#notify_managers',
               subject: subject,
             })
end

#package_expiry_date(file_url) ⇒ Object



312
313
314
315
316
317
318
319
320
321
322
# File 'app/mailers/staff_mailer.rb', line 312

def package_expiry_date(file_url)
  @file_url = file_url
  subject = 'Expired Package'
  mail(to: HELLO_EMAIL, subject: subject)
  log_mailer({
               email: HELLO_EMAIL,
               name: 'StaffMailer#package_expiry_date',
               subject: subject,
               other: { file_url: file_url },
             })
end

#reservation_report(receivers, download_link, cc = [], subject = nil) ⇒ Object



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'app/mailers/staff_mailer.rb', line 374

def reservation_report(receivers, download_link, cc = [], subject = nil)
  if subject.nil?
    subject = "Download Reservation report - #{Time.zone.now.in_time_zone('Asia/Bangkok')}"
  end
  @body = download_link
  mail(to: receivers, cc: cc, subject: subject) do |format|
    format.html { render inline: @body }
  end
  log_mailer({
               email: receivers,
               cc: cc,
               name: 'StaffMailer#reservation_report',
               subject: subject,
             })
end

#reservation_report_staff(body, subject, receivers) ⇒ Object



390
391
392
393
394
395
396
397
398
399
400
# File 'app/mailers/staff_mailer.rb', line 390

def reservation_report_staff(body, subject, receivers)
  @body = body
  mail(to: receivers, subject: subject) do |format|
    format.html { render inline: @body }
  end
  log_mailer({
               email: receivers,
               name: 'StaffMailer#reservation_report_staff',
               subject: subject,
             })
end

#send_at_staff_validation_report(download_link, receivers) ⇒ Object



437
438
439
440
441
442
443
444
445
446
# File 'app/mailers/staff_mailer.rb', line 437

def send_at_staff_validation_report(download_link, receivers)
  @download_link = download_link
  subject = 'Hungryhub - Validation report'
  mail(to: receivers, subject: subject)
  log_mailer({
               email: receivers,
               name: 'StaffMailer#send_at_staff_validation_report',
               subject: subject,
             })
end

#send_ia_staff_validation_report(download_link, receivers) ⇒ Object



426
427
428
429
430
431
432
433
434
435
# File 'app/mailers/staff_mailer.rb', line 426

def send_ia_staff_validation_report(download_link, receivers)
  @download_link = download_link
  subject = 'Hungryhub - Validation report'
  mail(to: receivers, subject: subject)
  log_mailer({
               email: receivers,
               name: 'StaffMailer#send_ia_staff_validation_report',
               subject: subject,
             })
end

#send_temporary_accessObject



468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'app/mailers/staff_mailer.rb', line 468

def send_temporary_access
  @staff = params[:staff]
  @password = params[:password]
  @admin_email = params[:admin_email]
  @restaurant_name = @staff.restaurants.map(&:name).join(', ')

  subject = "Temporary Access for #{@staff.name || 'Account Name'} at #{@restaurant_name}"
  mail(
    to: @admin_email,
    subject: subject,
  )
  log_mailer({
               email: @admin_email,
               name: 'StaffMailer#send_temporary_access',
               subject: subject,
             })
end

#suggest_us_restaurant(suggestion, receiver) ⇒ Object



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'app/mailers/staff_mailer.rb', line 281

def suggest_us_restaurant(suggestion, receiver)
  message = <<~EOF
    User suggested a restaurant

    message:
    #{suggestion}
  EOF
  @message = message
  BUSINESS_LOGGER.info 'User suggested a restaurant', body: message
  subject = 'Suggest Us a Restaurant'
  mail(subject: subject, to: receiver)
  log_mailer({
               email: receiver,
               name: 'StaffMailer#suggest_us_restaurant',
               subject: subject,
             })
end

#ticket_report(receivers, download_link, cc = []) ⇒ Object



360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'app/mailers/staff_mailer.rb', line 360

def ticket_report(receivers, download_link, cc = [])
  @body = download_link
  subject = "Download Voucher report - #{Time.zone.now.in_time_zone('Asia/Bangkok')}"
  mail(to: receivers,
       cc: cc,
       subject: subject)
  log_mailer({
               email: receivers,
               cc: cc,
               name: 'StaffMailer#ticket_report',
               subject: subject,
             })
end

#welcomeObject



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'app/mailers/staff_mailer.rb', line 486

def welcome
  @staff = params[:staff]
  @password = params[:password]

  subject = 'Access Granted: Welcome to the Hungryhub Partner Portal'
  mail(
    to: @staff.email,
    subject: subject,
  )
  log_mailer({
               email: @staff.email,
               name: 'StaffMailer#welcome',
               subject: subject,
             })
end