2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-12 20:03:43 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
2019-02-01 19:40:24 +00:00
|
|
|
class Supporter < ApplicationRecord
|
2019-08-06 14:08:51 +00:00
|
|
|
# :search_vectors,
|
|
|
|
# :profile_id, :profile,
|
|
|
|
# :nonprofit_id, :nonprofit,
|
|
|
|
# :full_contact_info, :full_contact_info_id,
|
|
|
|
# :import_id, :import,
|
|
|
|
# :name,
|
|
|
|
# :first_name,
|
|
|
|
# :last_name,
|
|
|
|
# :email,
|
|
|
|
# :address,
|
|
|
|
# :city,
|
|
|
|
# :state_code,
|
|
|
|
# :country,
|
|
|
|
# :phone,
|
|
|
|
# :organization,
|
|
|
|
# :latitude,
|
|
|
|
# :locale,
|
|
|
|
# :longitude,
|
|
|
|
# :zip_code,
|
|
|
|
# :total_raised,
|
|
|
|
# :notes,
|
|
|
|
# :fields,
|
|
|
|
# :anonymous,
|
|
|
|
# :deleted, # bool (flag for soft delete)
|
|
|
|
# :email_unsubscribe_uuid, #string
|
|
|
|
# :is_unsubscribed_from_emails #bool
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
belongs_to :profile
|
|
|
|
belongs_to :nonprofit
|
|
|
|
belongs_to :import
|
|
|
|
has_many :full_contact_infos
|
|
|
|
has_many :payments
|
|
|
|
has_many :offsite_payments
|
|
|
|
has_many :charges
|
|
|
|
has_many :cards, as: :holder
|
|
|
|
has_many :direct_debit_details
|
|
|
|
has_many :donations
|
|
|
|
has_many :supporter_notes, dependent: :destroy
|
|
|
|
has_many :supporter_emails
|
|
|
|
has_many :activities, dependent: :destroy
|
|
|
|
has_many :tickets
|
|
|
|
has_many :recurring_donations
|
|
|
|
has_many :tag_joins, dependent: :destroy
|
|
|
|
has_many :tag_masters, through: :tag_joins
|
|
|
|
has_many :custom_field_joins, dependent: :destroy
|
|
|
|
has_many :custom_field_masters, through: :custom_field_joins
|
2019-07-30 21:29:24 +00:00
|
|
|
belongs_to :merged_into, class_name: 'Supporter', foreign_key: 'merged_into'
|
2020-06-23 20:31:25 +00:00
|
|
|
has_many :merged_from, class_name: 'Supporter', :foreign_key => "merged_into"
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
validates :nonprofit, presence: true
|
|
|
|
scope :not_deleted, -> { where(deleted: false) }
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
geocoded_by :full_address
|
|
|
|
reverse_geocoded_by :latitude, :longitude do |obj, results|
|
|
|
|
geo = results.first
|
|
|
|
if geo # absorb zip code automatically
|
|
|
|
obj.zip_code = geo.postal_code if obj.zip_code.blank?
|
|
|
|
obj.state_code = geo.state_code if obj.state_code.blank?
|
|
|
|
obj.city = geo.city if obj.city.blank?
|
|
|
|
obj.address = geo.address if obj.address.blank?
|
|
|
|
obj.country = geo.country if obj.country.blank?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def profile_picture(size = :normal)
|
|
|
|
return unless profile
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
profile.get_profile_picture(size)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
def as_json(options = {})
|
|
|
|
h = super(options)
|
2019-07-30 21:29:24 +00:00
|
|
|
h[:pic_tiny] = profile_picture(:tiny)
|
|
|
|
h[:pic_normal] = profile_picture(:normal)
|
|
|
|
h[:url] = profile && Rails.application.routes.url_helpers.profile_path(profile)
|
|
|
|
h
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def full_address
|
2019-07-30 21:29:24 +00:00
|
|
|
Format::Address.full_address(address, city, state_code)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|