forked from armandofox/audience1st
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
class RecurringDonationsController < ApplicationController | ||
|
||
before_filter :is_staff_filter | ||
before_filter :load_customer, :only => [:new, :create] | ||
|
||
private | ||
|
||
def load_customer | ||
return redirect_to(donations_path, :alert => 'You must select a customer.') unless @customer = Customer.find(params[:customer_id]) | ||
end | ||
|
||
public | ||
|
||
def index | ||
@total = 0 | ||
@params = {} | ||
@page_title = "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) | ||
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) | ||
@full_name = Customer.find(cid).full_name | ||
end | ||
if params[:use_date] | ||
if params[:dates].blank? | ||
mindate,maxdate = [Time.parse("2007-01-01"), Time.current] | ||
else | ||
mindate,maxdate = Time.range_from_params(params[:dates]) | ||
@header = "#{mindate.to_formatted_s(:compact)}-#{maxdate.to_formatted_s(:compact)}: " | ||
# allow dates to be picked up as default form field for next time | ||
params[:from] = mindate | ||
params[:to] = maxdate | ||
end | ||
@donations = @donations.where(:sold_on => mindate..maxdate) | ||
end | ||
if params[:use_amount] | ||
min,max = params[:donation_min].to_i, params[:donation_max].to_i | ||
return redirect_to(donations_path, :alert => t('donations.errors.invalid_amounts')) if | ||
(max.zero? && min.zero?) || max < 0 || min < 0 | ||
min,max = max,min if min > max | ||
@donations = @donations.where(:amount => min..max) | ||
end | ||
if params[:use_ltr_sent] | ||
@donations = @donations.where(:letter_sent => nil) | ||
end | ||
if !params[:use_fund].blank? && !params[:donation_funds].blank? | ||
@donations = @donations.where(:account_code_id => params[:donation_funds]) | ||
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 | ||
@donations = @donations.paginate(:page => @page) | ||
@header << "#{@donations.total_entries} transactions, " << | ||
ActionController::Base.helpers.number_to_currency(@total) | ||
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 | ||
donation = Donation.find(params[:id]) | ||
comments = params[:comments] | ||
donation.update_attributes!(:comments => comments) | ||
Txn.add_audit_record(:customer_id => donation.customer_id, :logged_in_id => current_user.id, | ||
:order_id => donation.order_id, | ||
:comments => comments, | ||
:txn_type => "don_edit") | ||
# restore "save comment" button to look like a check mark | ||
render :js => %Q{alert('Comment saved')} | ||
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid => e | ||
error = ActionController::Base.helpers.escape_javascript(e.message) | ||
render :js => %Q{alert('There was an error saving the donation comment: #{error}')} | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/views/recurring_donations/_donation_letter_sent.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
%div[donation] | ||
- if donation.letter_sent | ||
= "#{donation.letter_sent.strftime('%D')} by #{Customer.find(donation.processed_by_id).first_name rescue '(???)'}" | ||
- else | ||
= link_to "Mark Sent", donation_path(donation), 'data-remote' => true, 'data-method' => :put, 'data-type' => 'script' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
.form-row | ||
.col-md-5 | ||
= check_box_tag 'use_cid', 1, @params[:use_cid] | ||
%label.col-form-label Only for customer (type first or last name): | ||
.col-md-5#donor_autocomplete | ||
:javascript | ||
$('#use_cid').change(function() { | ||
if (! $(this).is(':checked')) { | ||
$('#show_vouchers').prop('checked',false); | ||
$('#show_vouchers').prop('disabled',true); | ||
} else { | ||
$('#show_vouchers').prop('disabled',false); | ||
$('#cid').val(''); | ||
}; | ||
}); | ||
$('#donor_name').focus(function() { $('#use_cid').prop('checked',true); }) | ||
= text_field_tag 'donor_name', @full_name, :class => '_autocomplete form-control', 'data-resultfield' => 'cid' | ||
= hidden_field_tag 'cid', @params[:cid] | ||
|
||
.form-row | ||
.col-md-5 | ||
= check_box_tag 'use_date', 1, @params[:use_date] | ||
%label.col-form-label Date is in the range: | ||
.col-md-5= select_date_with_shortcuts 'dates', :from => @params[:from], :to => @params[:to], :enables => '#use_date', :class => 'form-control' | ||
|
||
.form-row | ||
.col-md-5 | ||
= check_box_tag 'use_amount', 1, @params[:use_amount] | ||
%label.col-form-label Donation amount between: | ||
.input-group.col-md-2 | ||
.input-group-prepend | ||
%span.input-group-text.form-control $ | ||
= number_field_tag 'donation_min', @params[:donation_min], :class => 'form-control text-right a1-no-spinner' | ||
.input-group-append | ||
%span.input-group-text.form-control .00 | ||
.col-md-1.text-center.form-control-plaintext and | ||
.input-group.col-md-2 | ||
.input-group-prepend | ||
%span.input-group-text.form-control $ | ||
= number_field_tag 'donation_max', @params[:donation_max], :class => 'form-control text-right a1-no-spinner' | ||
.input-group-append | ||
%span.input-group-text.form-control .00 | ||
|
||
.form-row | ||
.col-md-5 | ||
= check_box_tag 'use_fund', 1, @params[:use_fund] | ||
%label.col-form-label Only donations to these funds: | ||
%br | ||
= link_to "Add/Edit Account Codes…".html_safe, account_codes_path, :class => 'btn btn-primary mx-1' | ||
|
||
.col-md-5 | ||
= select_tag 'donation_funds', options_from_collection_for_select(AccountCode.all, :id, :name_with_code), :multiple => true, :class => 'form-control' | ||
|
||
.form-row | ||
.col-md-5 | ||
= check_box_tag 'use_ltr_sent', 1, @params[:use_ltr_sent] | ||
%label.col-form-label Only if letter not yet sent | ||
= popup_help_for :donation_search_by_letter_sent | ||
|
||
.form-row | ||
.col-md-12 | ||
= check_box_tag 'use_repeat_donor', 1, @params[:use_repeat_donor] | ||
%label.col-form-label Only donors who have made at least | ||
= select_tag 'num_donations', options_for_select(2..12) | ||
donations since | ||
= select_date((@params[:donated_since] || Date.today), :prefix => 'since') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$('#donation_<%= @id %>').text('#{result}'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
%h1= @header | ||
= link_to 'Donations', donations_path, class: 'btn btn-primary', style: 'float: right; margin-top: 10px;' | ||
|
||
.pagination-container | ||
.pagination.mx-auto | ||
= will_paginate @donations, :previous_label => '«', :next_label => '»', :container => false | ||
- first,last,total = @donations.offset+1, @[email protected], @donations.total_entries | ||
- if total > @donations.per_page | ||
= form_tag donations_path, :method => :get do | ||
• | ||
%b #{first}-#{last} of #{total} | ||
• Jump to page: | ||
= text_field_tag 'page', '', :size => 4 | ||
= submit_tag 'Go', :class => 'btn btn-outline-primary btn-sm' | ||
|
||
= form_tag donations_path, {:method => :get} do | ||
= render :partial => 'donation_search', :locals => {:params => @params} | ||
.form-row | ||
.col-md-4 | ||
= submit_tag "Search", :class => 'btn btn-success mx-1' | ||
- unless @donations.empty? | ||
= submit_tag 'Download to Excel', :class => 'btn btn-primary mx-1' | ||
= popup_help_for 'download_to_excel' | ||
|
||
- unless @donations.empty? | ||
%table.a1-table.table.table-hover#donations | ||
%thead | ||
%tr | ||
%th Customer | ||
%th Order# | ||
%th Date | ||
%th Item Amount | ||
%th Item Description or Acct Code | ||
%th Thanks Ltr Sent? | ||
%th Comments | ||
%tbody | ||
- @donations.each do |t| | ||
%tr{:id => "donation_row_#{t.id}"} | ||
%td= link_to t.customer.full_name, 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.amount) | ||
%td= t.item_description | ||
%td= render :partial => 'donation_letter_sent', :locals => {:donation => t} | ||
%td | ||
= form_tag update_comment_for_donation_path(t), 'data-remote' => true, 'data-method' => 'put', 'data-type' => 'script', :class => 'form form-inline' do | ||
= text_field_tag 'comments', t.comments, :id => "donation_comment_{t.id}", :class => 'donation-comment form-control form-control-sm' | ||
= submit_tag '✔'.html_safe, :name => 'save', :id => "save_#{t.id}", :class => 'btn btn-sm btn-outline-success' | ||
%br |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
= set_active_tab '#t_donations_index' | ||
|
||
= form_tag customer_donations_path(@customer), :id => '_stripe_payment_form' do | ||
|
||
.form-row | ||
.col-2.text-right | ||
%label.col-form-label{:for => 'amount'} Amount | ||
.col-md-1.col-4= number_field_tag 'amount', number_to_currency(@donation.amount, :unit => ''), :class => 'form-control' | ||
.col-md-2 | ||
.col-md-2.text-right | ||
%label{:for => 'comments'} Comments/Check no. | ||
.col-md-4= text_area_tag 'comments', @donation.comments, :class => 'form-control' | ||
|
||
.form-row | ||
.col-md-2.text-right | ||
%label.col-form-label{:for => 'fund'} Fund | ||
.col-md-3= select_tag 'fund', options_from_collection_for_select(AccountCode.all, :id, :name_with_code, @donation.account_code.try(:id)), :class => 'form-control' | ||
.col-md-2.text-right | ||
%label.col-form-label{:for => 'date'} Date Posted | ||
.col-md-4.form-inline= select_date Date.current, {:order => [:month, :day, :year]}, {:class => 'form-control'} | ||
|
||
.form-row | ||
.col-md-4.offset-2 | ||
.form-check.form-check-inline | ||
= radio_button_tag 'payment', 'check', true, :class => 'form-check-input', :onclick => '$("#credit_card_info").addClass("d-none"); $("#cash_check_info").removeClass("d-none");' | ||
%label.form-check-label{:for => 'payment_check'} Check | ||
.form-check.form-check-inline | ||
= radio_button_tag 'payment', 'cash', false, :class => 'form-check-input', :onclick => '$("#credit_card_info").addClass("d-none"); $("#cash_check_info").removeClass("d-none");' | ||
%label.form-check-label{:for => 'payment_cash'} Cash | ||
.form-check.form-check-inline | ||
= radio_button_tag 'payment', 'credit_card', false, :id => 'enable_cc', :class => 'form-check-input', :onclick => '$("#credit_card_info").removeClass("d-none"); $("#cash_check_info").addClass("d-none");' | ||
%label.col-form-label{:for => 'enable_cc'} Credit Card | ||
= hidden_field_tag 'customer_id', @customer.id | ||
|
||
#credit_card_info.d-none | ||
= render :partial => 'store/credit_card', :locals => {:name => @customer.full_name} | ||
= hidden_field_tag '_stripe_commit' | ||
.form-row | ||
.col-md-2.offset-1= submit_tag 'Charge Credit Card', :id => '_stripe_submit', :onclick => 'A1.stripeSubmit()', :class => 'btn btn-success' | ||
|
||
#cash_check_info | ||
.form-row | ||
.col-md-2.offset-1= submit_tag 'Record', :class => 'btn btn-success' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters