Class: ReportsManager::NspireDefectExcelReport

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

Instance Method Summary collapse

Methods inherited from ApplicationService

call

Constructor Details

#initialize(user_id, property_id, report_type, inspection_details, inspectable_buildings, inspectable_units, items, defects) ⇒ NspireDefectExcelReport

Returns a new instance of NspireDefectExcelReport.



5
6
7
8
9
10
11
12
13
14
# File 'app/services/reports_manager/nspire_defect_excel_report.rb', line 5

def initialize(user_id, property_id, report_type, inspection_details, inspectable_buildings, inspectable_units, items, defects)
  @user_id = user_id
  @property_id = property_id
  @report_type = report_type
  @inspection_details = inspection_details
  @inspectable_buildings = inspectable_buildings
  @inspectable_units = inspectable_units
  @items = items
  @defects = defects
end

Instance Method Details

#callObject



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
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/services/reports_manager/nspire_defect_excel_report.rb', line 16

def call
  property = Property.find_by_id(@property_id)
  property_name = property['property_name'].upcase
  prop = property['properties']
  inspection_date = prop['inspection_start_date'].to_s + ' - ' + prop['inspection_end_date'].to_s
  details = ::ReportsManager::NspireDefectReport.call(@user_id, @property_id, @report_type, true, @inspection_details, @inspectable_buildings, @inspectable_units, @items, @defects)
  header = [
    'Line',
    'Area',
    'Building No',
    'Unit No',
    'Item',
    'Defect',
    'Defect Type',
    'Point Deduct',
    'Location',
    'Comments',
    'Image Id',
    'Image URL',
  ]

  data = []
  if details
    index = 1
    details.each do |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'] = detail['defect']
      temp['Defect Type'] = detail['definition_type']
      temp['Point Deduct'] = detail['points']
      temp['Location'] = detail['location']
      temp['Comments'] = detail['comments']
      temp['Building Id'] = detail['building_id']
      temp['Unit Id'] = detail['unit_id']
      temp['Image Id'] = detail['image_id']
      url = ''
      if detail['image_id'].present?
        url = 'https://usig-images.s3.us-west-2.amazonaws.com/images/' + detail['image_name'] + ENV["DEFECT_IMAGE_EXT"]
      end
      temp['Image URL'] = url

      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
  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