Skip to content

Commit

Permalink
reduced to minimum needed
Browse files Browse the repository at this point in the history
  • Loading branch information
rnickles committed Apr 18, 2024
1 parent d6612bd commit 52331a2
Showing 1 changed file with 5 additions and 61 deletions.
66 changes: 5 additions & 61 deletions app/controllers/recurring_donations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ def load_customer
def index
@total = 0
@params = {}
@page_title = "Donation history"
@page_title = "Recurring donation history"
@page = (params[:page] || '1').to_i
@header = ''
@donations = Donation.
includes(:order,:customer,:account_code).
where.not(:customer_id => Customer.walkup_customer.id).
order(:sold_on)
@recurringDonations = RecurringDonation.
includes(:order, :customer, :account_code).
where.not(:customer_id => Customer.walkup_customer.id).
order(:sold_on)
if (params[:use_cid] && !params[:cid].blank?) # cust id will be embedded in route in autocomplete field
cid = if params[:cid] =~ /^\d+$/ then params[:cid] else Customer.id_from_route(params[:cid]) end
@donations = @donations.where(:customer_id => cid)
Expand Down Expand Up @@ -53,7 +57,6 @@ def index
end
@total = @donations.sum(:amount)
@params = params

if params[:commit] =~ /download/i
send_data @donations.to_csv, :type => 'text/csv', :filename => 'donations_report.csv'
else
Expand All @@ -63,65 +66,6 @@ def index
end
end

def new
@donation ||= @customer.donations.new(:amount => 0,:comments => '')
end

def create
@order = Order.create(:purchaser => @customer, :customer => @customer, :processed_by => current_user)
@donation = Donation.from_amount_and_account_code_id(
params[:amount].to_f, params[:fund].to_i, params[:comments].to_s)
@order.add_donation(@donation)
@order.processed_by = current_user()

sold_on = Date.from_year_month_day(params[:date])
case params[:payment]
when 'check'
@order.purchasemethod = Purchasemethod.get_type_by_name('box_chk')
when 'cash'
@order.purchasemethod = Purchasemethod.get_type_by_name('box_cash')
when 'credit_card'
@order.purchasemethod = Purchasemethod.get_type_by_name('web_cc')
@order.purchase_args = { :credit_card_token => params[:credit_card_token] }
sold_on = Time.current
end
@order.comments = params[:comments].to_s
unless @order.ready_for_purchase?
flash[:alert] = @order.errors.as_html
render :action => 'new'
return
end
begin
@order.finalize!(sold_on)
redirect_to(customer_path(@customer), :notice => 'Donation recorded.')
rescue Order::PaymentFailedError => e
@order.destroy
redirect_to(new_customer_donation_path(@customer), :alert => e.message)
rescue StandardError => e
@order.destroy
# rescue ActiveRecord::RecordInvalid => e
# rescue Order::OrderFinalizeError => e
# rescue RuntimeError => e
end
end

def update
if (t = Donation.find_by_id(params[:id])).kind_of?(Donation)
now = Time.current
c = current_user.email rescue "(??)"
t.update_attributes(:letter_sent => now,
:processed_by => current_user)
Txn.add_audit_record(:customer_id => t.customer_id,
:logged_in_id => current_user.id,
:txn_type => 'don_ack',
:comments => "Donation ID #{t.id} marked as acknowledged")
result = now.strftime("%D by #{c}")
else
result = '(ERROR)'
end
render :js => %Q{\$('#donation_#{params[:id]}').text('#{result}')}
end

# AJAX handler for updating the text of a donation's comment
def update_comment_for
begin
Expand Down

0 comments on commit 52331a2

Please sign in to comment.