Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got columns going #19

Draft
wants to merge 4 commits into
base: 187065217-perform-recurring-donation-transaction
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/controllers/recurring_donations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class RecurringDonationsController < ApplicationController

before_filter :is_staff_filter

public

def index
@page_title = "Recurring donation history"
@header = @page_title

@recurring_donations = RecurringDonation.all
end
end
30 changes: 30 additions & 0 deletions app/models/items/recurring_donation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,34 @@ class RecurringDonation < Item

def one_line_description ; end
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
winsonwan marked this conversation as resolved.
Show resolved Hide resolved
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
winsonwan marked this conversation as resolved.
Show resolved Hide resolved
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
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 ""
end
end
2 changes: 2 additions & 0 deletions app/views/donations/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
%h1= @header

= link_to 'Recurring Donations', recurring_donations_path, class: 'btn btn-primary', style: 'float: right; margin-top: 10px;'

.pagination-container
.pagination.mx-auto
= will_paginate @donations, :previous_label => '&laquo;', :next_label => '&raquo;', :container => false
Expand Down
25 changes: 25 additions & 0 deletions app/views/recurring_donations/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
%h1= @header

= link_to 'Donations', donations_path, class: 'btn btn-primary', style: 'float: right; margin-top: 10px;'

%table.a1-table.table.table-hover#recurring_donations
%thead
%tr
%th Customer
%th Order#
%th Start Date
%th Monthly Amount
%th Total to Date
%th End Date
%th Item Description or Acct Code
%tbody
- @recurring_donations.each do |t|
%tr{:id => "donation_row_#{t.id}"}
%td= link_to t.customer.full_name, recurring_donations_path(:use_cid => 1, :cid => t.customer, :show_vouchers => true, :commit => 'Go')
%td= link_to_order_containing t
%td= t.sold_on.strftime '%D'
%td.right= number_to_currency(t.monthly_amount)
%td= number_to_currency(t.total_to_date)
%td= "todo"
%td= t.item_description
%br
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
end
end

resources :recurring_donations, :only => [:index, :update] do
member do
post :update_comment_for
end
end

# RSS

get '/ics/showdates.ics' => 'info#showdates'
Expand Down
Loading