Add page listing due contributions

This commit is contained in:
Hugo Peixoto 2023-03-23 18:08:25 +00:00
parent 1f8a04ec5a
commit b4dda05575
5 changed files with 56 additions and 0 deletions

View File

@ -23,6 +23,23 @@ class ContributionsController < ApplicationController
end end
end end
# GET /contributions/due
def due
@due_members = Member.where(status: %i[expired cancelled]).to_a
@due_contributions = (2000..Date.today.year)
.to_a
.map do |year|
[year, @due_members.select {|m| m.expires_on < Date.new(year, 12, 31) }.map { |m|
OpenStruct.new(
member: m,
amount: m.category == 'normal' ? 30 : 6,
)
}]
end
.reject { |(_, m)| m.empty? }
end
# GET /contributions/new # GET /contributions/new
def new def new
@contribution = Contribution.new @contribution = Contribution.new

View File

@ -0,0 +1,31 @@
<h1><%= t 'contributions.due.title' %></h1>
<% @due_contributions.each do |(year, contributions)| %>
<h2><%= year %></h2>
<table class='zebra'>
<tr>
<th><%= t('members.attributes.display_name') %></th>
<th><%= t('members.attributes.expires_on') %></th>
<th><%= t('members.attributes.category') %></th>
<th><%= t('contributions.attributes.amount') %></th>
</tr>
<% contributions.each do |contribution| %>
<tr>
<td>
<%= link_to contribution.member do %><%= contribution.member.number %>. <%= contribution.member.display_name %><% end %>
</td>
<td><%= contribution.member.expires_on %></td>
<td><%= contribution.member.category %></td>
<td><%= number_to_currency(contribution.amount, unit: "€") %></td>
</tr>
<% end %>
<tfoot>
<tr>
<th>Total</th>
<th></th>
<th></th>
<th><%= number_to_currency(contributions.map(&:amount).sum, unit: "€") %></th>
</tr>
</tfoot>
</table>
<% end %>

View File

@ -48,6 +48,8 @@ en:
student: "Student" student: "Student"
retired: "Retired" retired: "Retired"
contributions: contributions:
due:
title: "Due contributions"
new: new:
expires_on_warning: | expires_on_warning: |
Adding a contribution will automatically bump the membership expiration Adding a contribution will automatically bump the membership expiration

View File

@ -93,6 +93,8 @@ pt:
data de inscrição é automaticamente definida como a data de pagamento, data de inscrição é automaticamente definida como a data de pagamento,
e a data de expiração passa a ser um ano após essa data. Podes definir e a data de expiração passa a ser um ano após essa data. Podes definir
uma data de expiração manualmente usando o próximo campo. uma data de expiração manualmente usando o próximo campo.
due:
title: "Contribuições em dívida"
notification_mailer: notification_mailer:
expiration_in_60d: expiration_in_60d:
subject: "ANSOL - Pagamento anual de quotas" subject: "ANSOL - Pagamento anual de quotas"

View File

@ -14,6 +14,10 @@ Rails.application.routes.draw do
end end
resources :contributions, only: [:index, :edit, :update, :destroy] do resources :contributions, only: [:index, :edit, :update, :destroy] do
collection do
get :due
end
member do member do
get :delete get :delete
end end