From e443a7a4e1d70c29fab1b284ab1ffafc5e0dcfc8 Mon Sep 17 00:00:00 2001 From: Pete Holiday Date: Sun, 15 Sep 2024 15:06:08 -0400 Subject: [PATCH] Adds finance view for leagues. --- app/controllers/leagues_controller.rb | 3 ++ app/views/leagues/_navbar.html.haml | 5 ++ app/views/leagues/finances.html.erb | 67 +++++++++++++++++++++++++++ config/authorization_rules.rb | 4 +- config/routes.rb | 2 + 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 app/views/leagues/finances.html.erb diff --git a/app/controllers/leagues_controller.rb b/app/controllers/leagues_controller.rb index 41edded..6440b71 100644 --- a/app/controllers/leagues_controller.rb +++ b/app/controllers/leagues_controller.rb @@ -958,6 +958,9 @@ def missing_spirit_reports end end + def finances + end + private def load_league_from_params diff --git a/app/views/leagues/_navbar.html.haml b/app/views/leagues/_navbar.html.haml index c74eab2..8d1df59 100644 --- a/app/views/leagues/_navbar.html.haml +++ b/app/views/leagues/_navbar.html.haml @@ -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 diff --git a/app/views/leagues/finances.html.erb b/app/views/leagues/finances.html.erb new file mode 100644 index 0000000..51e63fc --- /dev/null +++ b/app/views/leagues/finances.html.erb @@ -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) +%> +
+

League Finances

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 CountTotal Amount
Comped Registrations<%= comped_registrations %><%=number_to_currency(comped_registrations * @league.price)%>
Paid Registrations<%= paid_registrations %><%=number_to_currency total_paid %>
Refunded Registrations<%= refunded_registrations %><%=number_to_currency total_refunded %>
Merchant Fees (estimated) -<%=number_to_currency(total_fees)%>
 <%= comped_registrations + paid_registrations - refunded_registrations %><%=number_to_currency(total_received - total_fees)%>
+
diff --git a/config/authorization_rules.rb b/config/authorization_rules.rb index 4ab1a1b..72e5a00 100644 --- a/config/authorization_rules.rb +++ b/config/authorization_rules.rb @@ -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 @@ -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 diff --git a/config/routes.rb b/config/routes.rb index b1d8850..698ba2d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -59,6 +59,8 @@ get 'leave_pair' get 'missing_spirit_reports' + + get 'finances' end resources :teams, only: [:new, :create]