Class: UserMailer

Inherits:
ApplicationMailer show all
Defined in:
app/mailers/user_mailer.rb

Instance Method Summary collapse

Instance Method Details

#get_lt_report(property_id, user_email, date) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/mailers/user_mailer.rb', line 15

def get_lt_report(property_id, user_email, date)

  inspection_details = InspectionDetail.get_details(property_id)
  items = InspectableItem.get_all
  inspectable_buildings = Building.get_inspectable_buildings(property_id)
  inspectable_units = Unit.get_inspectable_units(property_id)

  @data = ::ReportsManager::NspireLTReport.call(1, property_id, inspection_details, items, inspectable_buildings, inspectable_units, 'PDF', user_email, true, date)
  ac = ActionController::Base.new
  rendered_template = ac.render_to_string(
      'admin/reports/pdf/nspire/lt_defect.pdf.erb',
      layout: 'pdf.html.erb',
      locals: { data: @data }
  )
  report_file = WickedPdf.new.pdf_from_string(
      rendered_template,
      header: {
          content: ac.render_to_string('layouts/header.pdf.erb',
                                       layout: 'pdf.html.erb',
                                       locals: { data: @data }),
          line: true
      },
      footer: {
          content: ac.render_to_string('layouts/footer.pdf.erb',
                                       layout: 'pdf.html.erb',
                                       locals: { data: @data }),
          line: true
      },
      page_size: 'Letter',
      orientation: 'Landscape'
  )
  report_file
end

#lt_defect_reportObject



4
5
6
7
8
9
10
11
12
13
# File 'app/mailers/user_mailer.rb', line 4

def lt_defect_report
  property_id = params[:property_id]
  @property = Property.find(property_id)
  email = params[:email]
  date = params[:date]
  subject = "Notification of Exigent & Fire Safety Hazards for " + @property.property_name
  attachments['EXIGENT-AND-FIRE-SAFETY-HAZARDS-REPORT.pdf'] = get_lt_report(@property.id, email, date)

  mail(to: email, subject: subject)
end