Class: Contribution
- Inherits:
-
Object
- Object
- Contribution
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion
- Defined in:
- app/models/contribution.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#amount ⇒ Object
Standard for the app is (total_donation_amount = amount + nongift_amount) For example, if someone wrote a check for $100 for event with $25 FMV, amount = $75 and nongift_amount = $25.
-
#contributor ⇒ Object
Returns the value of attribute contributor.
-
#creator_id ⇒ Object
Returns the value of attribute creator_id.
-
#details ⇒ Object
Returns the value of attribute details.
-
#nongift_amount ⇒ Object
Standard for the app is (total_donation_amount = amount + nongift_amount) For example, if someone wrote a check for $100 for event with $25 FMV, amount = $75 and nongift_amount = $25.
-
#occurred_at ⇒ Object
Returns the value of attribute occurred_at.
-
#order ⇒ Object
Returns the value of attribute order.
-
#organization_id ⇒ Object
Returns the value of attribute organization_id.
-
#payment_method ⇒ Object
Returns the value of attribute payment_method.
-
#person_id ⇒ Object
Returns the value of attribute person_id.
-
#subtype ⇒ Object
Returns the value of attribute subtype.
Class Method Summary collapse
Instance Method Summary collapse
- #has_contributor? ⇒ Boolean
-
#id ⇒ Object
hacks to make form_for work.
-
#initialize(params = {}) ⇒ Contribution
constructor
A new instance of Contribution.
- #organization ⇒ Object
- #persisted? ⇒ Boolean
- #save(order_klass = ApplicationOrder) {|_self| ... } ⇒ Object
- #update(new_contribution) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Contribution
Returns a new instance of Contribution.
25 26 27 28 |
# File 'app/models/contribution.rb', line 25 def initialize(params = {}) load(params) @contributor = find_contributor end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
5 6 7 |
# File 'app/models/contribution.rb', line 5 def action @action end |
#amount ⇒ Object
Standard for the app is (total_donation_amount = amount + nongift_amount) For example, if someone wrote a check for $100 for event with $25 FMV, amount = $75 and nongift_amount = $25
20 21 22 |
# File 'app/models/contribution.rb', line 20 def amount @amount end |
#contributor ⇒ Object
Returns the value of attribute contributor.
5 6 7 |
# File 'app/models/contribution.rb', line 5 def contributor @contributor end |
#creator_id ⇒ Object
Returns the value of attribute creator_id.
5 6 7 |
# File 'app/models/contribution.rb', line 5 def creator_id @creator_id end |
#details ⇒ Object
Returns the value of attribute details.
5 6 7 |
# File 'app/models/contribution.rb', line 5 def details @details end |
#nongift_amount ⇒ Object
Standard for the app is (total_donation_amount = amount + nongift_amount) For example, if someone wrote a check for $100 for event with $25 FMV, amount = $75 and nongift_amount = $25
20 21 22 |
# File 'app/models/contribution.rb', line 20 def nongift_amount @nongift_amount end |
#occurred_at ⇒ Object
Returns the value of attribute occurred_at.
5 6 7 |
# File 'app/models/contribution.rb', line 5 def occurred_at @occurred_at end |
#order ⇒ Object
Returns the value of attribute order.
5 6 7 |
# File 'app/models/contribution.rb', line 5 def order @order end |
#organization_id ⇒ Object
Returns the value of attribute organization_id.
5 6 7 |
# File 'app/models/contribution.rb', line 5 def organization_id @organization_id end |
#payment_method ⇒ Object
Returns the value of attribute payment_method.
5 6 7 |
# File 'app/models/contribution.rb', line 5 def payment_method @payment_method end |
#person_id ⇒ Object
Returns the value of attribute person_id.
5 6 7 |
# File 'app/models/contribution.rb', line 5 def person_id @person_id end |
#subtype ⇒ Object
Returns the value of attribute subtype.
5 6 7 |
# File 'app/models/contribution.rb', line 5 def subtype @subtype end |
Class Method Details
.for(order) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/contribution.rb', line 43 def self.for(order) action = GiveAction.where(:subject_id => order.id).where(:subject_type => "Order").first Contribution.new.tap do |contribution| contribution.order = order contribution.contributor = order.person contribution.occurred_at = order.created_at contribution.amount = order.items.first.price contribution.nongift_amount = order.items.first.nongift_amount contribution.payment_method = order.payment_method contribution.subtype = action.subtype contribution.details = action.details contribution.organization_id = order.organization_id contribution.creator_id = action.creator_id contribution.action = action contribution.person_id = contribution.contributor.id end end |
Instance Method Details
#has_contributor? ⇒ Boolean
77 78 79 |
# File 'app/models/contribution.rb', line 77 def has_contributor? contributor.present? end |
#id ⇒ Object
hacks to make form_for work
31 32 33 |
# File 'app/models/contribution.rb', line 31 def id self.order.try(:id) end |
#organization ⇒ Object
39 40 41 |
# File 'app/models/contribution.rb', line 39 def organization @organization ||= Organization.find(self.organization_id) end |
#persisted? ⇒ Boolean
35 36 37 |
# File 'app/models/contribution.rb', line 35 def persisted? !self.order.nil? && self.order.persisted? end |
#save(order_klass = ApplicationOrder) {|_self| ... } ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/contribution.rb', line 62 def save(order_klass = ApplicationOrder, &block) @order = build_order(order_klass) Order.transaction do @order.save! @order.update_attribute(:created_at, @occurred_at) @item = build_item(@order, @amount, @nongift_amount) @item.save! @action = build_action @action.save! end yield(self) if block_given? @order end |
#update(new_contribution) ⇒ Object
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 |
# File 'app/models/contribution.rb', line 81 def update(new_contribution) order = self.order item = self.order.items.first action = self.action item.price = new_contribution.amount item.nongift_amount = new_contribution.nongift_amount item.realized_price = new_contribution.amount item.net = new_contribution.amount action.details = new_contribution.details action.subtype = new_contribution.subtype order.created_at = new_contribution.occurred_at order.payment_method = new_contribution.payment_method order.details = new_contribution.details ActiveRecord::Base.transaction do item.save order.save action.save end true end |