Skip to content

Commit

Permalink
fill out RecurringDonation model with basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
winsonwan committed Apr 29, 2024
1 parent b50b74b commit 3819548
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions app/models/items/recurring_donation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ class RecurringDonation < Item
belongs_to :customer
has_many :donations, foreign_key: :recurring_donation_id

def one_line_description ; end
def description_for_audit_txn ; end
def first_donation
Donation.where(recurring_donation_id: id).order(sold_on: :asc).first
end

def monthly_amount
donation = first_donation
donation ? donation.amount : nil
end

def total_amount_received
Donation.where(recurring_donation_id: id).sum(:amount)
end

def one_line_description(opts={})
if opts[:suppress_price]
"Recurring Donation to #{account_code.name}"
else
sprintf("$%6.2f Recurring Donation to %s ($%6.2f received in total)", monthly_amount, account_code.name, total_amount_received)
end
end

def description_for_audit_txn
sprintf("%.2f %s recurring donation [%d]", monthly_amount, account_code.name, id)
end
end

0 comments on commit 3819548

Please sign in to comment.