Class: C80Estate::Area
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- C80Estate::Area
- Defined in:
- app/models/c80_estate/area.rb
Class Method Summary collapse
- .all_areas ⇒ Object
- .all_areas_sq ⇒ Object
- .busy_areas ⇒ Object
-
.busy_areas_sq ⇒ Object
посчитает кол-во занятых метров.
- .free_areas ⇒ Object
-
.free_areas_sq ⇒ Object
посчитает кол-во свободных метров.
- .import_excel(file) ⇒ Object
- .where_atype(atype_id) ⇒ Object
- .where_floor(v) ⇒ Object
- .where_oenter(v) ⇒ Object
- .where_price_range(range) ⇒ Object
- .where_square_range(range) ⇒ Object
Instance Method Summary collapse
- #assigned_person_title ⇒ Object
- #astatus_id ⇒ Object
- #astatus_tag ⇒ Object
- #astatus_title ⇒ Object
- #atype_title ⇒ Object
- #last_updater ⇒ Object
- #main_image_url ⇒ Object
- #owner_id ⇒ Object
- #power_price_value ⇒ Object
- #price_value ⇒ Object
- #property_title ⇒ Object
- #square_value ⇒ Object
Class Method Details
.all_areas ⇒ Object
32 33 34 |
# File 'app/models/c80_estate/area.rb', line 32 def self.all_areas self.all end |
.all_areas_sq ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/c80_estate/area.rb', line 67 def self.all_areas_sq sum = 0 self.all.each do |area| area_prop_square = area.item_props.where(:prop_name_id => 9) if area_prop_square.present? sum += area_prop_square.first.value.to_i end end sum end |
.busy_areas ⇒ Object
51 52 53 |
# File 'app/models/c80_estate/area.rb', line 51 def self.busy_areas self.joins(:astatuses).where(:c80_estate_astatuses => {tag: 'busy'}) end |
.busy_areas_sq ⇒ Object
посчитает кол-во занятых метров
56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/c80_estate/area.rb', line 56 def self.busy_areas_sq sum = 0 self.busy_areas.each do |area| area_prop_square = area.item_props.where(:prop_name_id => 9) if area_prop_square.present? sum += area_prop_square.first.value.to_i end end sum end |
.free_areas ⇒ Object
36 37 38 |
# File 'app/models/c80_estate/area.rb', line 36 def self.free_areas self.joins(:astatuses).where(:c80_estate_astatuses => {tag: 'free'}) end |
.free_areas_sq ⇒ Object
посчитает кол-во свободных метров
41 42 43 44 45 46 47 48 49 |
# File 'app/models/c80_estate/area.rb', line 41 def self.free_areas_sq sum = 0 self.free_areas.each do |area| # area_prop_square = area.item_props.where(:prop_name_id => 9) area_prop_square = area.square_value sum += area_prop_square.first.value.to_i end sum end |
.import_excel(file) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/c80_estate/area.rb', line 111 def self.import_excel(file) Rails.logger.debug "------------------------------------------------------------- self.import [BEGIN] " import_result = '' spreadsheet = open_spreadsheet(file) header = spreadsheet.row(1) # Rails.logger.debug(header) # ["title", "atype", "square", "price", "status"] (2..spreadsheet.last_row).each do |i| row = Hash[[header, spreadsheet.row(i)].transpose] Rails.logger.debug("---------- #{row} -----------") # {"title"=>"С2-1.18", "atype"=>"Торговое помещение", "square"=>"0", "price"=>800.0, "status"=>"Занята"} # area_where = Area.where(:slug => row["ID"]) # if area_where.count > 0 # # area = Area.where(:slug => row["ID"]).first # puts "--- Обновляем данные для #{area.id}, #{area.slug}: " # puts "--- Хотим вставить данные: " + row.to_hash.to_s # area.price = row["Цена"] # area.space = row["Площадь"] # area.save # puts "." # # else # s = "В базе не найден павильон: #{row.to_hash}" # import_result += s + "\n" # puts s # # end # # area = C80Estate::Area.create!({ title: row['title'], property_id: row['property_id'].to_i, atype_id: row['atype_id'].to_i, owner_type: 'AdminUser', owner_id: 2, assigned_person_type: 'AdminUser', assigned_person_id: 2 }) C80Estate::ItemProp.create!([ {value: row['price'].to_i, area_id: area.id, prop_name_id: 1}, {value: row['square'].to_f, area_id: area.id, prop_name_id: 9}, ]) area.astatuses << C80Estate::Astatus.find(row['astatus'].to_i) area.save end puts "------------------------------------------------------------- self.import [END] " import_result end |
.where_atype(atype_id) ⇒ Object
174 175 176 |
# File 'app/models/c80_estate/area.rb', line 174 def self.where_atype(atype_id) self.where(:atype_id => atype_id) end |
.where_floor(v) ⇒ Object
104 105 106 107 108 109 |
# File 'app/models/c80_estate/area.rb', line 104 def self.where_floor(v) # Rails.logger.debug "\t\t [2]: v = #{v}" C80Estate::Area.joins(:item_props) .where(c80_estate_item_props: {prop_name_id: 5}) .where(c80_estate_item_props: {value: v}) end |
.where_oenter(v) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/models/c80_estate/area.rb', line 92 def self.where_oenter(v) # Rails.logger.debug "\t\t [2]: v = #{v}" r = C80Estate::Area.joins(:item_props) .where(c80_estate_item_props: {prop_name_id: 8}) if v.to_i == 11 r = r.where(c80_estate_item_props: {value: 1}) else r = r.where.not(c80_estate_item_props: {value: 1}) end r end |
.where_price_range(range) ⇒ Object
78 79 80 81 82 83 |
# File 'app/models/c80_estate/area.rb', line 78 def self.where_price_range(range) self.joins(:item_props) .where(c80_estate_item_props: {prop_name_id: 1}) .where('c80_estate_item_props.value > ?', range.split(',')[0].to_i-1) .where('c80_estate_item_props.value < ?', range.split(',')[1].to_i+1) end |
.where_square_range(range) ⇒ Object
85 86 87 88 89 90 |
# File 'app/models/c80_estate/area.rb', line 85 def self.where_square_range(range) C80Estate::Area.joins(:item_props) .where(c80_estate_item_props: {prop_name_id: 9}) .where('c80_estate_item_props.value > ?', range.split(',')[0].to_i-1) .where('c80_estate_item_props.value < ?', range.split(',')[1].to_i+1) end |
Instance Method Details
#assigned_person_title ⇒ Object
218 219 220 221 222 223 224 |
# File 'app/models/c80_estate/area.rb', line 218 def assigned_person_title res = "-" if assigned_person.present? res = assigned_person.email end res end |
#astatus_id ⇒ Object
202 203 204 205 206 207 208 |
# File 'app/models/c80_estate/area.rb', line 202 def astatus_id res = -1 if astatuses.count > 0 res = astatuses.first.id end res end |
#astatus_tag ⇒ Object
210 211 212 213 214 215 216 |
# File 'app/models/c80_estate/area.rb', line 210 def astatus_tag res = -1 if astatuses.count > 0 res = astatuses.first.tag end res end |
#astatus_title ⇒ Object
194 195 196 197 198 199 200 |
# File 'app/models/c80_estate/area.rb', line 194 def astatus_title res = "-" if astatuses.count > 0 res = astatuses.first.title end res end |
#atype_title ⇒ Object
178 179 180 181 182 183 184 |
# File 'app/models/c80_estate/area.rb', line 178 def atype_title res = "-" if atype.present? res = atype.title end res end |
#last_updater ⇒ Object
234 235 236 |
# File 'app/models/c80_estate/area.rb', line 234 def last_updater sevents.last.auser.email end |
#main_image_url ⇒ Object
260 261 262 263 264 265 266 |
# File 'app/models/c80_estate/area.rb', line 260 def main_image_url url = 'no_thumb.png' if aphotos.count > 0 url = aphotos.first.image.thumb512 end url end |
#owner_id ⇒ Object
226 227 228 229 230 231 232 |
# File 'app/models/c80_estate/area.rb', line 226 def owner_id res = -1 if owner.present? res = owner.id end res end |
#power_price_value ⇒ Object
256 257 258 |
# File 'app/models/c80_estate/area.rb', line 256 def power_price_value price_value * 1.0 * square_value end |
#price_value ⇒ Object
238 239 240 241 242 243 244 245 |
# File 'app/models/c80_estate/area.rb', line 238 def price_value res = 0 p = item_props.where(:prop_name_id => 1) if p.count > 0 res = p.first.value.to_i end res end |
#property_title ⇒ Object
186 187 188 189 190 191 192 |
# File 'app/models/c80_estate/area.rb', line 186 def property_title res = "-" if property.present? res = property.title end res end |
#square_value ⇒ Object
247 248 249 250 251 252 253 254 |
# File 'app/models/c80_estate/area.rb', line 247 def square_value res = 0 p = item_props.where(:prop_name_id => 9) if p.count > 0 res = p.first.value.to_f end res end |