Class: CabooseRets::Property

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/caboose_rets/property.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.geolocatableObject



15
# File 'app/models/caboose_rets/property.rb', line 15

def self.geolocatable() all(conditions: "latitude IS NOT NULL AND longitude IS NOT NULL") end

Instance Method Details

#agentObject



42
43
44
# File 'app/models/caboose_rets/property.rb', line 42

def agent
    CabooseRets::Agent.where(:mls_id => self.list_agent_mls_id).first
end

#dynamic_photo_url(site) ⇒ Object



36
37
38
39
40
# File 'app/models/caboose_rets/property.rb', line 36

def dynamic_photo_url(site)
    domain = site.primary_domain.domain
    return "http://dev.pmre.com:3000/api/rets-properties/#{self.mls_number}/photo.jpg" if Rails.env.development?
    return "https://#{domain}/api/rets-properties/#{self.mls_number}/photo.jpg"
end


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/caboose_rets/property.rb', line 21

def featured_photo_url
    img_url = "https://cabooseit.s3.amazonaws.com/assets/pmre/house.png" 
    self.images.each do |img|
        m = Caboose::Media.where(:id => img.media_id).first
        if m && m.image && m.image.url(:large)
            img_url = m.image.url(:large)
            img_url = "https:#{img_url}" if !img_url.include?('http')
            return img_url
            break
        end
    end
    img_url = "https:#{img_url}" if !img_url.include?('http')
    return img_url
end

#filesObject



9
# File 'app/models/caboose_rets/property.rb', line 9

def files()   return CabooseRets::Media.where(:media_mui => self.matrix_unique_id, :media_type => 'File' ).reorder(:media_order).all end

#full_addressObject



50
51
52
53
# File 'app/models/caboose_rets/property.rb', line 50

def full_address
    address = "#{self.unit_number.blank? ? '' : 'Unit ' + self.unit_number + ', '}#{self.street_number} #{self.street_dir_prefix.blank? ? '' : self.street_dir_prefix + ' '}#{self.street_name.blank? ? '' : self.street_name.titleize}#{self.street_suffix.blank? ? '' : ' ' + self.street_suffix.titleize}#{self.street_dir_suffix.blank? ? '' : ' ' + self.street_dir_suffix}"
    return address.blank? ? '' : address.gsub('Mc ','Mc').gsub('Mlk',"MLK").gsub(" Us ", " US ").gsub(" Th ", "th ").gsub("Mcfarland","McFarland")
end

#full_address_cityObject



55
56
57
58
# File 'app/models/caboose_rets/property.rb', line 55

def full_address_city
    address = "#{self.unit_number.blank? ? '' : 'Unit ' + self.unit_number + ', '}#{self.street_number} #{self.street_dir_prefix.blank? ? '' : self.street_dir_prefix + ' '}#{self.street_name.blank? ? '' : self.street_name.titleize}#{self.street_suffix.blank? ? '' : ' ' + self.street_suffix.titleize}#{self.street_dir_suffix.blank? ? '' : ' ' + self.street_dir_suffix}#{self.city.blank? ? '' : '<br />' + self.city.titleize + ', ' + self.state_or_province + ' ' + self.postal_code}"
    return address.blank? ? '' : address.gsub('Mc ','Mc').gsub('Mlk',"MLK").gsub(" Us ", " US ").gsub(" Th ", "th ").gsub("Mcfarland","McFarland")
end

#imagesObject



8
# File 'app/models/caboose_rets/property.rb', line 8

def images()  return CabooseRets::Media.where(:media_mui => self.matrix_unique_id, :media_type => 'Photo').reorder(:media_order).all end

#meta_description(site) ⇒ Object



60
61
62
63
# File 'app/models/caboose_rets/property.rb', line 60

def meta_description(site)
    fa = self.full_address_city.blank? ? nil : self.full_address_city.gsub("<br />",", ")
    return "View the property listed for sale at #{fa}. #{site.description}"
end

#officeObject



46
47
48
# File 'app/models/caboose_rets/property.rb', line 46

def office
    CabooseRets::Office.where(:lo_mls_id => self.list_office_mls_id).first
end

#parse(data) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'app/models/caboose_rets/property.rb', line 65

def parse(data)

    old_price = self.list_price
    old_status = self.status

#    puts(data.to_s)
 #   self.access                           = nil
    self.acreage                          = data['LotSizeAcres'].blank? ? nil : data['LotSizeAcres'].to_f
    self.acreage_source                   = data['LotSizeSource']
 #   self.active_open_house_count          = data['ActiveOpenHouseCount']
 #   self.adjoining_land_use               = data['AdjoiningLandUse']
 #   self.age                              = data['Age']
    self.annual_taxes                     = data['TaxAnnualAmount']
    self.appliances                       = data['Appliances']
    self.area                             = data['MLSAreaMajor']
 #   self.attic                            = data['Attic']
    self.available_date                   = data['AvailabilityDate']
    self.basement                         = data['Basement']
#    self.basement_yn                      = data['BasementYN']
    self.baths_full                       = data['BathroomsFull'].blank? ? nil : data['BathroomsFull'].to_i
    self.baths_half                       = data['BathroomsHalf'].blank? ? nil : data['BathroomsHalf'].to_i
    self.baths_total                      = data['BathroomsTotalInteger'].blank? ? nil : data['BathroomsTotalInteger'].to_f
    self.beds_total                       = data['BedroomsTotal'].blank? ? nil : data['BedroomsTotal'].to_i
    self.book_number                      = data['TaxBookNumber']
#    self.book_page                        = data['BookPage']
#    self.book_type                        = data['BookType']
#    self.building_type                    = data['BuildingType']
    self.business_included_yn             = data['BusinessName']
    self.buyer_name                       = data['BuyerAgentFullName']
    self.city                             = data['City']
    self.city_community                   = data['CityRegion']
    self.closing                          = data['CloseDate']
    self.co_list_agent_mui                = data['CoListAgentMlsId']
    self.co_list_agent_direct_work_phone  = data['CoListAgentDirectPhone']
    self.co_list_agent_email              = data['CoListAgentEmail']
    self.co_list_agent_full_name          = data['CoListAgentFullName']
    self.co_list_agent_mls_id             = data['CoListAgentMlsId']
    self.co_list_office_mui               = data['CoListOfficeMlsId']
    self.co_list_office_mls_id            = data['CoListOfficeMlsId']
    self.co_list_office_name              = data['CoListOfficeName']
    self.co_list_office_phone             = data['CoListOfficePhone']
#    self.completion_date                  = data['CompletionDate']
#    self.comp_tenant_rep                  = data['CompTenantRep']
    self.construction                     = data['ConstructionMaterials']
    self.construction_status              = data['DevelopmentStatus']
    self.cooling                          = data['Cooling']
    self.county_or_parish                 = data['CountyOrParish']
 #   self.deposit                          = data['Deposit']
 #   self.dining_room                      = data['DiningRoom']
    self.directions                       = data['Directions']
    self.display_address_on_internet_yn   = data['InternetAddressDisplayYN']
 #   self.dom                              = data['DOM']
 #   self.driveway                         = data['Driveway']
    self.elementary_school                = data['ElementarySchool']
    self.exists_struct                    = data['StructureType']
    # self.expenses_association             = data['ExpensesAssociation'] 
    self.expenses_insurance               = data['InsuranceExpense']
    self.expenses_maintenance             = data['MaintenanceExpense']
    self.expenses_management              = data['ProfessionalManagementExpense']
    self.expenses_other                   = data['OtherExpense']
    self.expenses_tax                     = data['NewTaxesExpense']
    # self.expenses_utility                 = data['ExpensesUtility']
    self.exterior_features                = data['ExteriorFeatures']
    self.fireplace                        = data['FireplaceYN']
    self.fireplace_features               = data['FireplaceFeatures']
 #   self.flood_plain                      = data['FloodPlain']
    self.flooring                         = data['Flooring']
   # self.foreclosure_sale_date            = data['ForeclosureSaleDate']
  #  self.foreclosure_yn                   = data['ForeclosureYN']
  #  self.fsboyn                           = data['FSBOYN']
    self.garage                           = data['GarageYN']
    self.garage_spaces                    = data['GarageSpaces']
    self.heating                          = data['Heating']
    self.high_school                      = data['HighSchool']
    self.hoa_amenities                    = data['AssociationAmenities']
    self.hoa_fee                          = data['AssociationFee']
    self.hoa_included_in_rent_yn          = data['AssociationFeeIncludes']
    self.hoa_term                         = data['AssociationFeeFrequency']
    self.hoa_term_mandatory_yn            = data['AssociationYN']
 #   self.homestead_yn                     = data['HomesteadYN']
 #   self.idx_opt_in_yn                    = data['IDXOptInYN']
    self.income_other                     = data['GrossIncome']
 #   self.income_rental                    = data['GrossIncome']
    self.interior_features                = data['InteriorFeatures']
    self.land_features_extras             = data['LotFeatures']
    self.latitude                         = self.latitude.blank? ? nil : self.latitude
    self.longitude                        = self.longitude.blank? ? nil : self.longitude
    if self.latitude == 0.0 || self.latitude == '0.0' || self.longitude == 0.0 || self.longitude == '0.0' || (self.street_number != data['StreetNumber']) || (self.street_name != data['StreetName']) || (self.city != data['City']) || (self.postal_code != data['PostalCode'])
        self.latitude = nil
        self.longitude = nil
    end
    self.laundry                          = data['LaundryFeatures']
    self.legal_description                = data['TaxLegalDescription']
    self.legal_lot                        = data['TaxLot']
    self.legal_section                    = data['PublicSurveySection']
    self.levels                           = data['Levels']
    self.list_agent_mui                   = data['ListAgentMlsId']
    self.list_agent_direct_work_phone     = data['ListAgentOfficePhone']
    self.list_agent_email                 = data['ListAgentEmail']
    self.list_agent_full_name             = data['ListAgentFullName']
    self.list_agent_mls_id                = data['ListAgentMlsId']
    self.listing_contract_date            = data['ListingContractDate']
    self.list_office_mui                  = data['ListOfficeMlsId']
    self.list_office_mls_id               = data['ListOfficeMlsId']
    self.list_office_name                 = data['ListOfficeName']
    self.list_office_phone                = data['ListOfficePhone']
    self.list_price                       = data['ListPrice'].blank? ? self.list_price : data['ListPrice'].to_i
    
    self.lot_description                  = data['LotFeatures']
    self.lot_dimensions                   = data['LotSizeDimensions']
    self.lot_dim_source                   = data['LotDimensionsSource']
 #   self.management                       = data['Management']
 #   self.master_bed_level                 = data['MasterBedLevel']
    self.matrix_unique_id                 = data['ListingKey']
    self.matrix_modified_dt               = data['ModificationTimestamp']
    self.max_sqft                         = data['LivingArea']
    self.middle_school                    = data['MiddleOrJuniorSchool']
#    self.mineral_rights                   = data['MineralRights']
    self.min_sqft                         = data['LivingArea']
    self.misc_indoor_featuresa            = data['BuildingFeatures']
    self.mls                              = data['ListingService']
    self.mls_number                       = data['ListingId']
 #   self.municipality                     = data['Municipality']
    self.net_op_inc                       = data['NetOperatingIncome']
    # self.open_house_count                 = data['OpenHouseCount']
    # self.open_house_public_count          = data['OpenHousePublicCount']
    # self.open_house_public_upcoming       = data['OpenHousePublicUpcoming']
    # self.open_house_upcoming              = data['OpenHouseUpcoming']
    self.         = data['OriginalEntryTimestamp'].blank? ? data['OnMarketDate'] : data['OriginalEntryTimestamp']
    self.parcel_number                    = data['ParcelNumber']
    self.pending_date                     = data['PendingTimestamp']
    self.pets_allowed_yn                  = data['PetsAllowed']
    self.photo_count                      = data['PhotosCount']
    self.photo_modification_timestamp     = data['PhotosChangeTimestamp']
    self.pool                             = data['PoolFeatures']
    self.porch_patio                      = data['PatioAndPorchFeatures']
    self.possession                       = data['Possession']
    self.possible_uses                    = data['PossibleUse']
    self.postal_code                      = data['PostalCode']
    self.postal_code_plus4                = data['PostalCodePlus4']
 #   self.price_per_acre                   = data['PricePerAcre']
 #   self.price_sqft                       = data['PriceSqft']
#    self.property_name                    = data['PropertyName']
    self.property_subtype                 = data['PropertySubType']
    self.property_type                    = data['PropertyType']
    self.property_use                     = data['CurrentUse']
    self.prop_mgmt_comp                   = data['ParkManagerName']
    self.public_remarks                   = data['PublicRemarks']
   #     self.refrigerator_included_yn         = data['RefrigeratorIncludedYN']
    self.rental_rate_type                 = data['RentControlYN']
    self.rent_incl                        = data['RentIncludes']
    self.res_style                        = data['ArchitecturalStyle']
#    self.restrictions                     = data['Restrictions']
    self.road_frontage                    = data['RoadFrontageType']
    self.roof                             = data['Roof']
   #     self.roofage                          = data['Roofage']
    self.room_count                       = data['RoomsTotal'] 
   #     self.service_type                     = data['ServiceType'] 
    self.security_features                = data['SecurityFeatures']
    self.sewer                            = data['Sewer']
    self.sold_terms                       = data['ListingTerms']
 #   self.sprinkler                        = data['Sprinkler']
 
    self.sqft_source                      = data['LivingAreaSource']
    self.sqft_total                       = data['LivingArea'].blank? ? nil : data['LivingArea'].to_f
    self.state_or_province                = data['StateOrProvince']
    self.status                           = data['MlsStatus']
    self.status_contractual_search_date   = data['ContractStatusChangeDate']
    self.street_dir_prefix                = data['StreetDirPrefix']
    self.street_dir_suffix                = data['StreetDirSuffix']
    self.street_name                      = data['StreetName']
    self.street_number                    = data['StreetNumber']
    self.street_number_numeric            = data['StreetNumberNumeric']
    self.street_suffix                    = data['StreetSuffix']
   #     self.street_view_param                = data['StreetViewParam']
    self.style                            = data['BodyType']
    self.subdivision                      = data['SubdivisionName']
    self.topography                       = data['Topography']
    self.total_num_units                  = data['NumberOfUnitsTotal']
    self.total_num_units_occupied         = data['NumberOfUnitsLeased']
    self.transaction_type                 = data['TransactionBrokerCompensationType']
    self.unit_count                       = data['NumberOfUnitsInCommunity']
    self.unit_number                      = data['UnitNumber']
    self.utilities                        = data['Utilities']
    self.virtual_tour1                    = data['VirtualTourURLBranded'].blank? ? data['VirtualTourURLUnbranded'] : data['VirtualTourURLBranded']
   #     self.vow_allowed_avmyn                = data['VOWAllowAVMYN']
   #     self.vow_allowed_third_party_comm_yn  = data['VOWAllowThirdPartyCommYN']
   #     self.washer_dryer_included            = data['WasherDryerIncludedYN']
    self.water                            = data['WaterSource']
    self.waterfronts                      = data['WaterBodyName']
    self.waterfront_yn                    = data['WaterfrontYN']
#    self.water_heater                     = data['WaterHeater']
    self.windows                          = data['WindowFeatures']
#    self.window_treatments                = data['WindowTreatments']
    self.year_built                       = data['YearBuilt']
    self.yr_blt_source                    = data['YearBuiltSource']
    self.zoning                           = data['Zoning']
    # self.zoning_northport                 = data['ZoningNorthPort']
    # self.zoning_tusc                      = data['ZoningTusc']


    if !old_status.blank? && old_status != self.status # status was changed
        CabooseRets::Notification.delay(:queue => "rets").property_status_changed(self, old_status)
    elsif !old_price.blank? && old_price != self.list_price && self.status == 'Active' # price was changed
        CabooseRets::Notification.delay(:queue => "rets").property_price_changed(self, old_price)
    end


end

#refresh_from_mlsObject



17
18
19
# File 'app/models/caboose_rets/property.rb', line 17

def refresh_from_mls
    CabooseRets::RetsImporter.import_properties(self.mls_number, true)
end

#urlObject



7
# File 'app/models/caboose_rets/property.rb', line 7

def url()     return "/properties/#{self.mls_number}/details" end

#virtual_tourObject



10
11
12
13
14
# File 'app/models/caboose_rets/property.rb', line 10

def virtual_tour
    return nil if !CabooseRets::Media.where(:mls => self.mls.to_s).where(:media_type => 'Virtual Tour').exists?
    media = CabooseRets::Media.where(:mls => self.mls.to_s, :media_type => 'Virtual Tour').first
    return media.url
end