Skip to content

Commit

Permalink
Added more info including stripe fee and totals to billing center
Browse files Browse the repository at this point in the history
  • Loading branch information
Broken-Wind committed May 13, 2012
1 parent fde8c88 commit 1d8c105
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
22 changes: 19 additions & 3 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ def billingcenter
end
@charges = []
12.times { |i|
total_amount_month = 0
total_fee_month = 0
seed = Time.now.utc - i.month
end_date = seed - seed.mday.days + 1.month
start_date = end_date - end_date.mday.days + 1.day
Expand All @@ -214,10 +216,24 @@ def billingcenter
{ month: seed.strftime('%B %Y'),
seed: seed.to_i,
charges: charges.map{|charge|
amount = Stripe::Charge.retrieve(charge.stripe_id).amount * 0.021
stripe = Stripe::Charge.retrieve(charge.stripe_id)
amount = stripe.amount
enrollex_fee = amount * 0.021 / 100
stripe_fee = stripe.fee.to_f / 100
course = Course.find(charge.course_id)
{ stripe_id: charge.stripe_id, charged_at: charge.charged_at, amount: amount.to_f / 100, description: course.name, month: seed.strftime('%B %Y'), seed: seed.to_i }
}
user = User.find charge.user_id
email =
if user.parent
user.parent.email
else
user.email
end
total_amount_month += amount
total_fee_month += enrollex_fee + stripe_fee
{ stripe_id: charge.stripe_id, charged_at: charge.charged_at, amount: amount.to_f / 100, enrollex_fee: enrollex_fee, description: course.name, month: seed.strftime('%B %Y'), seed: seed.to_i, user_email: email, stripe_fee: stripe_fee}
},
total_fee_month: total_fee_month,
total_amount_month: total_amount_month / 100
})
end
}
Expand Down
37 changes: 23 additions & 14 deletions app/views/admin/billingcenter.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,31 @@
- @charges.each do |charges|
%option{value: charges[:seed]}= charges[:month]
- @charges.each_with_index do |charges, index|
%table.table.table-striped.table-bordered{id: "seed_#{charges[:seed]}", style: "display:#{index == 0 && '' || 'none'}"}
%thead
%th Date
%th Description
%th Amount
%th Stripe ID
%tbody
- charges[:charges].each do |charge|
%tr
%td= charge[:charged_at]
%td= charge[:description]
%td= number_with_precision charge[:amount], precision: 2
%td= charge[:stripe_id]
.billingDisplay{id: "seed_#{charges[:seed]}", style: "display:#{index == 0 && '' || 'none'}"}
%table.table.table-striped.table-bordered
%thead
%th Date
%th Description
%th Amount
%th Enrollex Fee
%th Stripe Fee
%th User Email
%th Stripe ID
%tbody
- charges[:charges].each do |charge|
%tr
%td= charge[:charged_at]
%td= charge[:description]
%td $#{number_with_precision charge[:amount], precision: 2}
%td -$#{number_with_precision charge[:enrollex_fee], precision: 3}
%td -$#{number_with_precision charge[:stripe_fee], precision: 3}
%td= charge[:user_email]
%td= charge[:stripe_id]
%h2 Total Processed This Month: #{number_with_precision charges[:total_amount_month], precision: 2}
%h2 Total Fees This Month: #{number_with_precision charges[:total_fee_month], precision: 2}

:javascript
$('select').change(function(){
$('table').css('display', 'none')
$('.billingDisplay').css('display', 'none')
$('#seed_' + $(this).val()).css('display', '')
})

0 comments on commit 1d8c105

Please sign in to comment.