Class: Organization

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Ext::Integrations::Organization, Ext::Resellable::Organization, Valuation::LifetimeFees, Valuation::LifetimeValue
Defined in:
app/models/organization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Ext::Integrations::Organization

#connected?, #fsp, #has_active_fiscally_sponsored_project?, #has_fiscally_sponsored_project?, included, #items_sold_as_reseller_during, #name_for_donations, #refresh_active_fs_project, #shows_with_sales, #sponsored_kit, #update_kits

Methods included from Valuation::LifetimeFees

#calculate_lifetime_fees

Methods included from Valuation::LifetimeValue

#calculate_lifetime_value

Instance Attribute Details

#updating_tax_infoObject

Returns the value of attribute updating_tax_info.



122
123
124
# File 'app/models/organization.rb', line 122

def updating_tax_info
  @updating_tax_info
end

Instance Method Details

#abilityObject



118
119
120
# File 'app/models/organization.rb', line 118

def ability
  OrganizationAbility.new(self)
end

#authorization_hashObject



140
141
142
143
144
145
146
# File 'app/models/organization.rb', line 140

def authorization_hash
  { 
    :authorized   => can?(:receive, Donation),
    :type         => donation_type,
    :fsp_name     => name_for_donations  
  }
end

#available_kitsObject



136
137
138
# File 'app/models/organization.rb', line 136

def available_kits
  Kit.pad_with_new_kits(kits)
end

#donationsObject



148
149
150
# File 'app/models/organization.rb', line 148

def donations
  Item.includes(:order => [:person => :address]).where(:product_type => "Donation", :orders => { :organization_id => id })
end

#dummyObject



101
102
103
# File 'app/models/organization.rb', line 101

def dummy
  Person.dummy_for(self)
end

#has_active_donation_only_storefront?Boolean

Returns:

  • (Boolean)


170
171
172
# File 'app/models/organization.rb', line 170

def has_active_donation_only_storefront?
  self.has_kit?(:regular_donation) && self.kit(:regular_donation).donation_only_storefront == '1'
end

#has_kit?(name) ⇒ Boolean

Returns:

  • (Boolean)


161
162
163
164
# File 'app/models/organization.rb', line 161

def has_kit?(name)
  name = "#{name.to_s.camelize.gsub(/Kit$/, '')}Kit"
  kits.select { |k| k.class.name == name && k.activated? }.any?
end

#has_tax_info?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'app/models/organization.rb', line 132

def has_tax_info?
  !(ein.blank? or legal_organization_name.blank?)
end

#individualsObject



166
167
168
# File 'app/models/organization.rb', line 166

def individuals
  people.where(:type => 'Individual')
end

#kit(name) ⇒ Object



156
157
158
159
# File 'app/models/organization.rb', line 156

def kit(name)
  name = "#{name.to_s.camelize.gsub(/Kit$/, '')}Kit"
  kits.select { |k| k.class.name == name }.first
end

#lifetime_ordersObject

We aren’t interested in FAFS donations, so override lifetime_orders to only include Artfully orders see: Valuation::LifetimeValue



52
53
54
# File 'app/models/organization.rb', line 52

def lifetime_orders
  orders.where('transaction_id is not null')
end

#make_owner(user) ⇒ Object

Will promote user to owner and demote any other owners



86
87
88
# File 'app/models/organization.rb', line 86

def make_owner(user)
  UserMembership.promote(user, self)
end

#membership_kitObject



109
110
111
# File 'app/models/organization.rb', line 109

def membership_kit
  self.kits.where(:type => "MembershipKit").first
end

#ownerObject



97
98
99
# File 'app/models/organization.rb', line 97

def owner
  @owner ||= UserMembership.includes(:user).where(:organization_id => self.id).where(:owner => true).first.try(:user)
end

#passes_kitObject



113
114
115
# File 'app/models/organization.rb', line 113

def passes_kit
  self.kits.where(:type => "PassesKit").first
end

#previous_ownerObject

In service of the user_memberships.owner migration.



93
94
95
# File 'app/models/organization.rb', line 93

def previous_owner
  users.order('user_memberships.id asc').first
end

#tags_for(tagged_association) ⇒ Object

Returns Tag objects. For an array of tag strings, call unique_tag_strings_for

This has been supersceded by tags_on and tag_counts_on in acts_as_taggable_on But those methods have not been added to an acts_as_taggable_on release yet.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/organization.rb', line 62

def tags_for(tagged_association)

  #Yak
  begin
    self.send(tagged_association.to_sym)
  rescue NoMethodError
    raise NoMethodError, "No tagged has_many association found for #{tagged_association.to_sym}"
  end

  table_name = Kernel.const_get(tagged_association.to_s.classify).table_name

  ActsAsTaggableOn::Tag.joins("INNER JOIN taggings ON tags.id = taggings.tag_id")
                       .joins("INNER JOIN #{table_name} ON #{table_name}.id = taggings.taggable_id")
                       .joins("INNER JOIN organizations ON organizations.id = #{table_name}.organization_id")
                       .where("organizations.id = ?", self.id)
end

#ticket_salesObject



152
153
154
# File 'app/models/organization.rb', line 152

def ticket_sales
  Item.includes(:show => [:event => :venue], :order => [:person => :address]).where(:product_type => "Ticket", :orders => { :organization_id => id })
end

#to_paramObject



44
45
46
# File 'app/models/organization.rb', line 44

def to_param
  self.id
end

#to_sObject



105
106
107
# File 'app/models/organization.rb', line 105

def to_s
  name
end

#unique_tag_strings_for(tagged_association) ⇒ Object



79
80
81
# File 'app/models/organization.rb', line 79

def unique_tag_strings_for(tagged_association)
  self.tags_for(tagged_association).all.map(&:name).uniq
end

#update_tax_info(params) ⇒ Object



123
124
125
126
127
128
129
130
# File 'app/models/organization.rb', line 123

def update_tax_info(params)
  @updating_tax_info = true
  update_attributes({
    :ein => params[:ein],
    :legal_organization_name => params[:legal_organization_name],
    :email => params[:email]
  })
end