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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/inspection_detail.rb', line 20 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
58 59 60 61 62 |
# File 'app/models/inspection_detail.rb', line 58 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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/inspection_detail.rb', line 38 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
71 72 73 74 75 76 |
# File 'app/models/inspection_detail.rb', line 71 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
64 65 66 67 68 69 |
# File 'app/models/inspection_detail.rb', line 64 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
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/models/inspection_detail.rb', line 8 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 |