Class: InspectionDetail
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- InspectionDetail
- Defined in:
- app/models/inspection_detail.rb
Class Method Summary collapse
- .get_details(property_id) ⇒ Object
- .get_property_defects(property_id) ⇒ Object
- .get_units_inspections(property_id) ⇒ Object
- .property_defects_of_building(property_id) ⇒ Object
- .property_defects_of_unit(property_id) ⇒ Object
- .search(property_id, inspectable_item, deficiency_definition, comments, location) ⇒ Object
Class Method Details
.get_details(property_id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/inspection_detail.rb', line 30 def self.get_details(property_id) query = " SELECT tb1.*, tb2.id AS inspectable_item_id, tb2.item_code, tb2.properties AS item_properties, tb3.definition_type AS type, tb3.code AS deficiency_code, tb3.properties AS defect_properties FROM inspection_details tb1 INNER JOIN inspectable_items tb2 ON tb1.inspectable_item_id = tb2.id LEFT OUTER JOIN deficiency_definitions tb3 ON tb1.deficiency_definition_id = tb3.id WHERE tb1.status is null and tb1.property_id=" + property_id.to_s + " and tb1.deficiency_definition_id IS NOT NULL" ActiveRecord::Base.connection.execute(query) end |
.get_property_defects(property_id) ⇒ Object
68 69 70 71 72 |
# File 'app/models/inspection_detail.rb', line 68 def self.get_property_defects(property_id) where(property_id: property_id) .where("deficiency_definition_id IS NOT NULL") .order(:inspectable_item_id, :deficiency_definition_id) end |
.get_units_inspections(property_id) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/inspection_detail.rb', line 48 def self.get_units_inspections(property_id) query = " SELECT tb1.*, tb2.id AS inspectable_item_id, tb2.item_code, tb2.properties AS item_properties, tb3.definition_type AS type, tb3.code AS deficiency_code, tb3.properties AS defect_properties FROM inspection_details tb1 INNER JOIN inspectable_items tb2 ON tb1.inspectable_item_id = tb2.id LEFT OUTER JOIN deficiency_definitions tb3 ON tb1.deficiency_definition_id = tb3.id WHERE tb1.status IS NULL AND tb1.property_id = #{property_id.to_i} AND tb1.unit_id IS NOT NULL AND tb1.deficiency_definition_id IS NOT NULL" ActiveRecord::Base.connection.execute(query) end |
.property_defects_of_building(property_id) ⇒ Object
81 82 83 84 85 86 |
# File 'app/models/inspection_detail.rb', line 81 def self.property_defects_of_building(property_id) where(property_id: property_id) .where("building_id IS NOT NULL") .where("deficiency_definition_id IS NOT NULL") .order(:building_id, :inspectable_item_id, :deficiency_definition_id) end |
.property_defects_of_unit(property_id) ⇒ Object
74 75 76 77 78 79 |
# File 'app/models/inspection_detail.rb', line 74 def self.property_defects_of_unit(property_id) where(property_id: property_id) .where("unit_id IS NOT NULL") .where("building_id IS NOT NULL") .where("deficiency_definition_id IS NOT NULL").order(:building_id, :unit_id, :inspectable_item_id, :deficiency_definition_id) end |
.search(property_id, inspectable_item, deficiency_definition, comments, location) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/inspection_detail.rb', line 18 def self.search(property_id,inspectable_item,deficiency_definition,comments,location) result = InspectionDetail result = result.where(property_id: property_id) if property_id.present? result = result.where(inspectable_item_id: inspectable_item) if inspectable_item.present? result = result.where(deficiency_definition_id: deficiency_definition) if deficiency_definition.present? result = result.where('comments ILIKE ?', "%#{comments}%") if comments.present? result = result.where('location ILIKE ?', "%#{location}%") if location.present? result.class == Class ? all : result end |