From b4dda05575c7fb86ae720d62d4453aa82ecc60bf Mon Sep 17 00:00:00 2001 From: Hugo Peixoto Date: Thu, 23 Mar 2023 18:08:25 +0000 Subject: [PATCH] Add page listing due contributions --- app/controllers/contributions_controller.rb | 17 +++++++++++ app/views/contributions/due.html.erb | 31 +++++++++++++++++++++ config/locales/en.yml | 2 ++ config/locales/pt.yml | 2 ++ config/routes.rb | 4 +++ 5 files changed, 56 insertions(+) create mode 100644 app/views/contributions/due.html.erb diff --git a/app/controllers/contributions_controller.rb b/app/controllers/contributions_controller.rb index a65daff..d388c79 100644 --- a/app/controllers/contributions_controller.rb +++ b/app/controllers/contributions_controller.rb @@ -23,6 +23,23 @@ class ContributionsController < ApplicationController 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 def new @contribution = Contribution.new diff --git a/app/views/contributions/due.html.erb b/app/views/contributions/due.html.erb new file mode 100644 index 0000000..5f0762c --- /dev/null +++ b/app/views/contributions/due.html.erb @@ -0,0 +1,31 @@ +

<%= t 'contributions.due.title' %>

+ +<% @due_contributions.each do |(year, contributions)| %> +

<%= year %>

+ + + + + + + + <% contributions.each do |contribution| %> + + + + + + + <% end %> + + + + + + + + +
<%= t('members.attributes.display_name') %><%= t('members.attributes.expires_on') %><%= t('members.attributes.category') %><%= t('contributions.attributes.amount') %>
+ <%= link_to contribution.member do %><%= contribution.member.number %>. <%= contribution.member.display_name %><% end %> + <%= contribution.member.expires_on %><%= contribution.member.category %><%= number_to_currency(contribution.amount, unit: "€") %>
Total<%= number_to_currency(contributions.map(&:amount).sum, unit: "€") %>
+<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 3eee3fb..f004c79 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -48,6 +48,8 @@ en: student: "Student" retired: "Retired" contributions: + due: + title: "Due contributions" new: expires_on_warning: | Adding a contribution will automatically bump the membership expiration diff --git a/config/locales/pt.yml b/config/locales/pt.yml index c8138cb..f4a7245 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -93,6 +93,8 @@ pt: 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 uma data de expiração manualmente usando o próximo campo. + due: + title: "Contribuições em dívida" notification_mailer: expiration_in_60d: subject: "ANSOL - Pagamento anual de quotas" diff --git a/config/routes.rb b/config/routes.rb index cb367c7..6e45388 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,10 @@ Rails.application.routes.draw do end resources :contributions, only: [:index, :edit, :update, :destroy] do + collection do + get :due + end + member do get :delete end