Class: ReportsManager::HouseKeepingReport
- Inherits:
-
ApplicationService
- Object
- ApplicationService
- ReportsManager::HouseKeepingReport
- Defined in:
- app/services/reports_manager/house_keeping_report.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(user_id, property_id, report_type, inspectable_buildings, inspectable_units) ⇒ HouseKeepingReport
constructor
A new instance of HouseKeepingReport.
Methods inherited from ApplicationService
Constructor Details
#initialize(user_id, property_id, report_type, inspectable_buildings, inspectable_units) ⇒ HouseKeepingReport
Returns a new instance of HouseKeepingReport.
5 6 7 8 9 10 11 |
# File 'app/services/reports_manager/house_keeping_report.rb', line 5 def initialize(user_id, property_id, report_type, inspectable_buildings, inspectable_units) @user_id = user_id @property_id = property_id @report_type = report_type @inspectable_buildings = inspectable_buildings @inspectable_units = inspectable_units end |
Instance Method Details
#call ⇒ Object
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 66 |
# File 'app/services/reports_manager/house_keeping_report.rb', line 13 def call view_data = {} view_data['property_id'] = @property_id view_data['user_id'] = @userr view_data['report_type'] = @report_type view_data['property'] = Property.find_by_id(@property_id) details = [] index = 1 item = InspectableItem.find_by_item_code("HK01") defects = DeficiencyDefinition.where(inspectable_item_id: item.id) if item.present? defect_ids = defects.present? ? defects.pluck("id") : [] inspections = InspectionDetail.where(property_id: @property_id).where(deficiency_definition_id: defect_ids) buildings = @inspectable_buildings units = @inspectable_units inspections.each do |insp| temp = {} building = insp['building_id'] != '' && buildings[insp['building_id']].present? ? buildings[insp['building_id']] : nil unit = insp['unit_id'] != '' && units[insp['unit_id']].present? ? units[insp['unit_id']] : nil prop = insp['properties'] level = prop['level'].present? ? prop['level'] : '' temp['line'] = index temp['area'] = item['item_code'][0] + item['item_code'][1] temp['sort_key'] = 0 if temp['area'] == 'UNIT' temp['sort_key'] = 1 temp['area_name'] = 'Unit' end temp['building_name'] = building.present? ? building['building_name'] : 'N/A' temp['unit_name'] = unit.present? ? unit['unit_name'] : 'N/A' temp['item'] = item['title'] temp['level'] = level temp['comments'] = insp['comments'].nil? ? '' : insp['comments'].gsub('?', ' ') temp['location'] = insp['location'].nil? ? '' : insp['location'].gsub('?', ' ') index += 1 details.push(temp) end view_data['details'] = details view_data['report_name'] = 'HOUSEKEEPING REPORT' view_data['orientation'] = 'L' view_data['file_name'] = view_data['property']['property_name'].gsub('[^A-Za-z0-9]', '-') + '-HouseKeeping' view_data end |