Class: ReportsManager::NspireLTReport
- Inherits:
-
ApplicationService
- Object
- ApplicationService
- ReportsManager::NspireLTReport
- Defined in:
- app/services/reports_manager/nspire_lt_report.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(user_id, property_id, inspection_details, items, inspectable_buildings, inspectable_units, report_type, user_email, only_email = false, date = nil) ⇒ NspireLTReport
constructor
A new instance of NspireLTReport.
Methods inherited from ApplicationService
Constructor Details
#initialize(user_id, property_id, inspection_details, items, inspectable_buildings, inspectable_units, report_type, user_email, only_email = false, date = nil) ⇒ NspireLTReport
Returns a new instance of NspireLTReport.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/services/reports_manager/nspire_lt_report.rb', line 5 def initialize(user_id, property_id, inspection_details, items, inspectable_buildings, inspectable_units, report_type, user_email, only_email = false, date = nil) @user_id = user_id @property_id = property_id @report_type = report_type @user_email = user_email @only_email = only_email @date = date ? date : Time.now.in_time_zone('Eastern Time (US & Canada)').to_date.to_s @inspection_details = inspection_details @items= items @inspectable_buildings = inspectable_buildings @inspectable_units = inspectable_units end |
Instance Method Details
#call ⇒ Object
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 78 79 80 81 82 |
# File 'app/services/reports_manager/nspire_lt_report.rb', line 18 def call view_data = {} property = Property.find_by_id(@property_id) inspection_details = @inspection_details inspection_details = ApplicationHelper.key_merge_sort(inspection_details, 'id') areas = InspectionArea.all areas = ApplicationHelper.key_merge_sort(areas, 'id') items = @items defects = DeficiencyDefinition.get_nspire_lt_defects buildings = @inspectable_buildings units = @inspectable_units lt_defects = [] shs_defects = [] inspection_details.each do |_id, inspection_detail| defect_id = inspection_detail['deficiency_definition_id'] prop = JSON.parse(inspection_detail['properties']) defect_date = prop['defect_date'] || nil next unless defects[defect_id].present? && ( @only_email ? defect_date.present? && defect_date == @date : true) building = buildings[inspection_detail['building_id']] inspection_detail['building_name'] = building.building_name if building unit = units[inspection_detail['unit_id']] inspection_detail['unit_name'] = unit.unit_name if unit item = items[inspection_detail['inspectable_item_id']] inspection_detail['item_name'] = item.title if item defect = defects[defect_id] inspection_detail['defect_title'] = defect.title if defect if item area = areas[item.inspection_area_id] inspection_detail['area_name'] = area.area_code.titleize if area inspection_detail['area_name'] = 'Outside' if area.area_code == 'ST' end if defect.present? && defect.definition_type == "Severe-HS" shs_defects.push(inspection_detail) else lt_defects.push(inspection_detail) end end view_data['header_text'] = 'U.S. INSPECTION GROUP, INC.' view_data['sub_header_text'] = 'Corp Office: PO Box 2838, 240 Old Jamestown Hwy, # 2838, Crossville, TN 38557 <br/>PH: 866/863-8744 FX: 866/573-3280 E-mail: hazards@usinspectiongroup.com' view_data['footer_text'] = "<div>Neither the inspector nor U.S. Inspection Group (USIG) assume any liability whatsoever expressed or implied that the above noted health and safety hazards constitute all of the health and safety deficiencies that may be present on the property. Any and all liability for the health and safety hazards noted above, as well as any health and safety hazards that my exist on the property but were not observed by the inspector, are the full and absolute responsibility of the property owner and not the inspector nor USIG. A copy of this form was also sent to USIG's offices.</div>" view_data['property_id'] = @property_id view_data['user_id'] = @user_id view_data['report_type'] = @report_type view_data['property'] = property view_data['lt_defects'] = lt_defects view_data['shs_defects'] = shs_defects view_data['all_defects'] = true view_data['inspector_name'] = UsersHelper.get_inspector_name(@property_id) view_data['user_email'] = @user_email.present? ? @user_email : property['properties']['client_email'] view_data['file_name'] = view_data['property']['property_name'].gsub('[^A-Za-z0-9]', '-') + '-LT_Defects' view_data['getSource'] = 'S' view_data end |