From e3b4c4006aa9819086eea4a6d35d0125f9ce5c3d Mon Sep 17 00:00:00 2001 From: rnickles Date: Sun, 28 Apr 2024 11:48:27 -0700 Subject: [PATCH] made winson changes --- app/models/items/recurring_donation.rb | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/app/models/items/recurring_donation.rb b/app/models/items/recurring_donation.rb index 259b2dcd..925f45fb 100644 --- a/app/models/items/recurring_donation.rb +++ b/app/models/items/recurring_donation.rb @@ -9,31 +9,14 @@ def description_for_audit_txn ; end def monthly_amount # Finds the first donation with the recurring_donation_id matching this instance's id donation = Donation.find_by(recurring_donation_id: id) - donation ? donation.amount : 0 # Returns the donation amount if found, otherwise returns 0 + donation ? donation.amount : nil # Returns the donation amount if found, otherwise returns nil end - def first_donation - # Retrieves the earliest donation based on the created_at timestamp - Donation.where(recurring_donation_id: id).order(sold_on: :asc).first - end - def latest_donation - # Retrieves the most recent donation based on the created_at timestamp - Donation.where(recurring_donation_id: id).order(sold_on: :desc).first - end def total_to_date - date1 = first_donation.sold_on.to_date - date2 = latest_donation.sold_on.to_date - - # Calculate the absolute difference in months - difference_in_months = (date2.year * 12 + date2.month) - (date1.year * 12 + date1.month) - - # The abs method ensures the difference is always a positive number - # The +1 includes the first month - months_paid = difference_in_months.abs + 1 - months_paid * monthly_amount + RecurringDonation.find(id).donations.sum(:amount) end def item_description # Finds the first donation with the recurring_donation_id matching this instance's id donation = Donation.find_by(recurring_donation_id: id) - donation ? donation.item_description : "" # Returns the donation item description if found, otherwise returns "" + donation ? donation.item_description : nil # Returns the donation item description if found, otherwise returns nil end end