Class: ReportsManager::PropertyPhotosExcelReport
- Inherits:
-
ApplicationService
- Object
- ApplicationService
- ReportsManager::PropertyPhotosExcelReport
- Defined in:
- app/services/reports_manager/property_photos_excel_report.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(user_id, property_id, report_type) ⇒ PropertyPhotosExcelReport
constructor
A new instance of PropertyPhotosExcelReport.
Methods inherited from ApplicationService
Constructor Details
#initialize(user_id, property_id, report_type) ⇒ PropertyPhotosExcelReport
Returns a new instance of PropertyPhotosExcelReport.
5 6 7 8 9 |
# File 'app/services/reports_manager/property_photos_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
#call ⇒ Object
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/services/reports_manager/property_photos_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', 'Location', 'Comments', 'Image Id', 'Image Name', 'Uploaded', 'Image Size' ] data = [] if details index = 1 details.each do |_key, detail| image_path = '/tmp/' + detail['image_name'].to_s + ENV['DEFECT_IMAGE_EXT'] if detail['image_name'].present? begin url = 'https://' + ENV['BUCKET_USIG_IMAGES'] + '.s3.amazonaws.com/images/' + detail['image_name'] + ENV['DEFECT_IMAGE_EXT'] download = open(url, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE) IO.copy_stream(download, image_path) rescue StandardError => e print e end end 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['Location'] = detail['location'] temp['Comments'] = detail['comments'] temp['Image Id'] = detail['image_id'] temp['Image Name'] = detail['image_name'] temp['Image Size'] = '-' if File.exist? image_path temp['Uploaded'] = 'Yes' temp['Image Size'] = FastImage.size(image_path) else temp['Uploaded'] = 'No' end data.push(temp) index += 1 end end view_data = {} view_data['headers'] = header view_data['data'] = 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 |