Class: ReportsManager::DefectExcelReport

Inherits:
ApplicationService show all
Defined in:
app/services/reports_manager/defect_excel_report.rb

Instance Method Summary collapse

Methods inherited from ApplicationService

call

Constructor Details

#initialize(user_id, property_id, report_type) ⇒ DefectExcelReport

Returns a new instance of DefectExcelReport.



5
6
7
8
9
# File 'app/services/reports_manager/defect_excel_report.rb', line 5

def initialize(user_id, property_id, report_type)
  @user_id = user_id
  @property_id = property_id
  @report_type = report_type
end

Instance Method Details

#callObject



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
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
# File 'app/services/reports_manager/defect_excel_report.rb', line 11

def call
  property = Property.find_by_id(@property_id)
  property_name = property['property_name'].upcase
  inspection_date = ApplicationHelper.inspection_date_for_reports(property)
  details = ::ReportsManager::DefectReport.call(@user_id, @property_id, @report_type, true)
  header = [
    'Line',
    'Area',
    'Building No',
    'Unit No',
    'Item',
    'Defect Type',
    'Severity',
    'Point Deduct',
    'Photo',
    'Location',
    'Comments'
  ]

  data = []
  if details
    index = 1
    details.each do |_key, detail|
      temp = {}
      temp['Line'] = index
      temp['Area'] = detail['area_name']
      temp['Building No'] = detail['building_name']
      temp['Unit No'] = detail['unit_name']
      temp['Item'] = detail['item']
      temp['Defect Type'] = detail['defect']
      temp['Severity'] = detail['level']
      temp['Point Deduct'] = detail['points']
      temp['Photo'] = detail['image_id']
      temp['Location'] = detail['location']
      temp['Comments'] = detail['comments']
      temp['Building Id'] = detail['building_id']
      temp['Unit Id'] = detail['unit_id']

      data.push(temp)
      index += 1
    end
  end

  view_data = {}
  view_data['headers'] = header
  view_data['property'] = property_name
  view_data['details'] = data
  view_data['report_title'] = property_name
  view_data['report_sub_title'] = 'Inspection Date: ' + inspection_date.to_s
  view_data['report_filename'] = property['property_name'] + '-Excel_Defect'
  view_data['work_sheet_name'] = 'excel-defect'
  view_data['user_id'] = @user_id
  view_data['freeze_header'] = true
  view_data
end