Skip to content

Commit

Permalink
Adds finance view for leagues.
Browse files Browse the repository at this point in the history
  • Loading branch information
toomuchpete committed Sep 15, 2024
1 parent 33074a6 commit e443a7a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/controllers/leagues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,9 @@ def missing_spirit_reports
end
end

def finances
end

private

def load_league_from_params
Expand Down
5 changes: 5 additions & 0 deletions app/views/leagues/_navbar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@
= link_to missing_spirit_reports_league_path do
%i.icon-heart-empty
Missing Spirit Reports
- if permitted_to? :finances, @league
%li
= link_to finances_league_path(@league) do
%i.icon-money
Finances
67 changes: 67 additions & 0 deletions app/views/leagues/finances.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<% content_for :title, @league.name %>
<%=render :partial => '/pageheader', :locals => {subtitle: 'Manage Players', breadcrumbs: {'Leagues' => leagues_path, @league.name => league_path(@league), 'League Finances' => nil}} %>

<%
comped_registrations = 0
paid_registrations = 0
total_paid = 0
refunded_registrations = 0
total_refunded = 0
%>
<%
@league.registrations.each do |r|
if r.comped?
comped_registrations += 1
end

pt = r.payment_transactions.first
next if pt.nil?

if pt.amount > 0
paid_registrations += 1
total_paid += pt.amount
end

if pt.refunded_amount
refunded_registrations += 1
total_refunded += pt.refunded_amount
end
end

total_received = total_paid - total_refunded
total_fees = (total_received * 0.0199) + ((paid_registrations - refunded_registrations) * 0.49)
%>
<div>
<h2>League Finances</h2>
<table class="table">
<tr>
<th>&nbsp;</th>
<th>Count</th>
<th>Total Amount</th>
</tr>
<tr>
<td>Comped Registrations</td>
<td><%= comped_registrations %></td>
<td><%=number_to_currency(comped_registrations * @league.price)%></td>
</tr>
<tr>
<td>Paid Registrations</td>
<td><%= paid_registrations %></td>
<td><%=number_to_currency total_paid %></td>
</tr>
<tr>
<td>Refunded Registrations</td>
<td><%= refunded_registrations %></td>
<td><%=number_to_currency total_refunded %></td>
</tr>
<tr>
<td>Merchant Fees (estimated)</td>
<td>&nbsp;</td>
<td>-<%=number_to_currency(total_fees)%></td>
<tr>
<td>&nbsp;</td>
<td><%= comped_registrations + paid_registrations - refunded_registrations %></td>
<td><%=number_to_currency(total_received - total_fees)%></td>
</tr>
</table>
</div>
4 changes: 2 additions & 2 deletions config/authorization_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
if_attribute commissioners: contains { user }
end

has_permission_on :leagues, :to => [:manage_roster, :players, :reg_list, :team_list, :cancel_registration, :add_player_to_team, :update_invites, :edit, :update, :setup_schedule_import, :upload_schedule, :import_schedule, :remove_future_games, :rainout_games, :process_rainout, :upload_roster, :setup_roster_import, :import_roster] do
has_permission_on :leagues, :to => [:manage_roster, :finances, :players, :reg_list, :team_list, :cancel_registration, :add_player_to_team, :update_invites, :edit, :update, :setup_schedule_import, :upload_schedule, :import_schedule, :remove_future_games, :rainout_games, :process_rainout, :upload_roster, :setup_roster_import, :import_roster] do
if_permitted_to :manage
end

Expand Down Expand Up @@ -89,7 +89,7 @@
end

role :'league-manager' do
has_permission_on :leagues, to: [:manage, :upload_roster, :setup_roster_import, :import_roster, :new, :create, :assign_comps]
has_permission_on :leagues, to: [:manage, :finances, :upload_roster, :setup_roster_import, :import_roster, :new, :create, :assign_comps]

has_permission_on :comp_groups, :to => [:index, :show, :new, :create, :edit, :update]
end
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
get 'leave_pair'

get 'missing_spirit_reports'

get 'finances'
end

resources :teams, only: [:new, :create]
Expand Down

0 comments on commit e443a7a

Please sign in to comment.