Commit 0b50cb7b authored by David F.'s avatar David F.

Merge branch '50-print-adherent-licence' into 'master'

Collaborating club can display the card of a subscription: refs #50.

See merge request !60
parents 47634225 dfbb0d5b
This diff is collapsed.
This diff is collapsed.
......@@ -24,11 +24,11 @@ class SubscriptionsController < ApplicationController
include AuthorizationsHelper
before_action :set_member
before_action :set_subscription, only: [:edit, :update, :destroy, :toggle_billing]
before_action :authorize_member, except: [:destroy, :toggle_billing]
before_action :set_subscription, only: [:edit, :update, :destroy, :card, :toggle_billing]
before_action :authorize_member, except: [:destroy, :toggle_billing, :card]
before_action :authorize, only: [:destroy, :toggle_billing]
before_action :set_medico_social_orgs, except: [:destroy, :toggle_billing]
before_action :set_available_performances, except: [:destroy, :toggle_billing]
before_action :set_medico_social_orgs, except: [:destroy, :card, :toggle_billing]
before_action :set_available_performances, except: [:destroy, :card, :toggle_billing]
def new
@subscription = @member.subscriptions.build
......@@ -97,6 +97,19 @@ class SubscriptionsController < ApplicationController
end
end
def card
respond_to do |format|
format.html do
render :card, layout: false
end
format.pdf do
pdf = PDFKit.new(card_member_subscription_url(@member, @subscription), margin_left: 3, margin_right: 3).to_pdf
send_data pdf, filename: "Carte adhésion #{@subscription.adherent.name} - #{@subscription.season.label}.pdf", type: 'application/pdf'
expires_now
end
end
end
def toggle_billing
@subscription.toggle_billing
redirect_to platform_path, notice: "L'adhésion a bien été #{@subscription.billed_at ? '' : 'dé'}facturée."
......
......@@ -107,6 +107,13 @@ module LinksHelper
custom_link 'fa-files-o', 'Dupliquer', path, version, options
end
def custom_print_card_link(path, version = :normal, options = {})
options[:class] ||= []
options[:class] << 'primary'
custom_link 'fa-id-card-o', 'Imprimer carte', path, version, options
end
def custom_bill_link(path, version = :normal, options = {})
options[:class] ||= []
options[:method] = :patch
......
......@@ -28,4 +28,13 @@ module SubscriptionsHelper
def external_subscription_label(subscription, member)
"#{subscription.adherent.name} (#{subscription.member.name}) → #{subscription.performances.for_member(member).to_a.map(&:full_title).join(', ')}"
end
def card_header(subscription)
label = (subscription.multipass? ? "Pass' Multi-Activités" : "Mono-Activité")
header = ""
4.times do
header << content_tag(:span, label)
end
header.html_safe
end
end
......@@ -12,6 +12,10 @@ class Adherent < ApplicationRecord
"#{first_name} #{last_name}"
end
def medico_social_org_name
self.medico_social_org.try(:name) || self.other_medicosocial_org
end
private
def at_least_one_medicosocial_org
......
#
# OLIGAA - Stands for "Outil en Ligne d'Information et de Gestion des Activités
# des Associations" which is an online tool for associations to manage news,
# actors and activities.
# Copyright (C) 2010-2017 Comité Départemental du Sport Adapté de la Gironde (CDSA
# 33) <contact@cdsa33.org>
#
# This file is part of OLIGAA.
#
# OLIGAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OLIGAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
class Season
FIRST_MONTH = 8
FIRST_DAY = 15
def initialize(date)
year = (date < Date.new(date.year, FIRST_MONTH, FIRST_DAY) ? date.year-1 : date.year)
@begining = Date.new(year, FIRST_MONTH, FIRST_DAY)
return self
end
def shorten
shorten_year = @begining.year.% 100
"#{shorten_year}#{shorten_year+1}"
end
def label
"Saison #{@begining.year}-#{@begining.year+1}"
end
end
......@@ -5,6 +5,8 @@ class Subscription < ApplicationRecord
has_many :performance_subscriptions
has_many :performances, through: :performance_subscriptions
after_create :set_platform_number
scope :for_performances, ->(performance_ids) { joins(:performances).where(performance_subscriptions: {performance_id: performance_ids}).distinct }
scope :by_adherent_name, -> { joins(:adherent).order('adherents.first_name','adherents.last_name') }
scope :billed, -> { where.not(billed_at: nil) }
......@@ -24,6 +26,10 @@ class Subscription < ApplicationRecord
members
end
def season
Season.new(self.created_at)
end
def multipass?
SubscriptionOption.new(self.adherent.medico_social_org,self.performances).send(:multipass_available?)
end
......@@ -35,4 +41,10 @@ class Subscription < ApplicationRecord
def billing_status
billed_at ? 'billed' : 'not-billed'
end
private
def set_platform_number
self.update_attribute(:platform_number, SubscriptionNumber.new(self).label)
end
end
#
# OLIGAA - Stands for "Outil en Ligne d'Information et de Gestion des Activités
# des Associations" which is an online tool for associations to manage news,
# actors and activities.
# Copyright (C) 2010-2017 Comité Départemental du Sport Adapté de la Gironde (CDSA
# 33) <contact@cdsa33.org>
#
# This file is part of OLIGAA.
#
# OLIGAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OLIGAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
class SubscriptionNumber
def initialize(subscription)
@subscription = subscription
end
def label
member = @subscription.member
if (affiliation_number = member.affiliation_number).present?
season_label = @subscription.season.shorten
prefix = "#{affiliation_number.gsub('/','')}/#{season_label}/"
existing_platform_numbers = member.subscriptions.where("platform_number LIKE '#{prefix}%'").pluck(:platform_number)
max_number = existing_platform_numbers.map { |num| num.gsub!(prefix, '') }.map(&:to_i).max || 0
new_number = ( max_number + 1).to_s.rjust(3,'0')
"#{prefix}#{new_number}"
else
"Numéro d'affiliation du membre non renseigné"
end
end
end
#
# OLIGAA - Stands for "Outil en Ligne d'Information et de Gestion des Activités
# des Associations" which is an online tool for associations to manage news,
# actors and activities.
# Copyright (C) 2010-2017 Comité Départemental du Sport Adapté de la Gironde (CDSA
# 33) <contact@cdsa33.org>
#
# This file is part of OLIGAA.
#
# OLIGAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OLIGAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
class SubscriptionOption
def initialize(medicosocial_org,performances)
......
......@@ -35,13 +35,14 @@
<ul id="internal">
<% @internal_subscriptions.each do |subscription| %>
<li>
<%= custom_print_card_link card_member_subscription_path(@member, subscription, format: :pdf), :short, class: %w(tight) %>
<%- if admin? %>
<%= custom_edit_link edit_member_subscription_path(@member, subscription), :short, class: %w(tight) %>
<%= custom_delete_link member_subscription_path(@member, subscription), :short, class: %w(tight) %>
<%- end %>
<%= internal_subscription_label(subscription) %>
</li>
<%- end %>
<%- end if @internal_subscriptions %>
</ul>
<%- unless @member.collaborating_medicosocial_org? %>
<h2>Adhérents extérieurs</h2>
......@@ -50,7 +51,7 @@
<li>
<%= external_subscription_label(subscription, @member) %>
</li>
<%- end %>
<%- end if @external_subscriptions %>
</ul>
<%- end %>
</aside>
......
<%
# OLIGAA - Stands for "Outil en Ligne d'Information et de Gestion des Activités
# des Associations" which is an online tool for associations to manage news,
# actors and activities.
# Copyright (C) 2010-2018 Comité Départemental du Sport Adapté de la Gironde (CDSA
# 33) <contact@cdsa33.org>
#
# This file is part of OLIGAA.
#
# OLIGAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OLIGAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<%= stylesheet_link_tag "subscription-card", media: :all %>
</head>
<body class="subscription_card">
<header>
<h1><%= card_header(@subscription) %></h1>
</header>
<section id="data">
<img class="photo">
<dl>
<dt>Nom</dt>
<dd><%= @subscription.adherent.last_name %></dd>
<dt>Prénom</dt>
<dd><%= @subscription.adherent.first_name %></dd>
<dt>Numéro de licence FFSA</dt>
<dd><%= @subscription.adherent.permit_number %></dd>
<dt>Numéro d'adhérent plateforme</dt>
<dd><%= @subscription.platform_number %></dd>
<dt>Club d'origine</dt>
<dd><%= @member.name %></dd>
<dt>Structure médico-sociale</dt>
<dd><%= @subscription.adherent.medico_social_org_name %></dd>
</dl>
</section>
<section id="cover">
<div>
<%= image_tag "ffsa-hands.svg" %>
<span class="blue">PLATEFORME</span>
<span class="red">SPORTS & TROUBLES PSYCHIQUES</span>
<span class="blue"><%= @subscription.season.label.upcase %></span>
</div>
</section>
</body>
......@@ -32,4 +32,4 @@ Rails.application.config.assets.paths << Rails.root.join('node_modules')
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
Rails.application.config.assets.precompile += %w( print.scss emails.js )
Rails.application.config.assets.precompile += %w( print.scss emails.js subscription-card.scss)
......@@ -21,7 +21,7 @@ environment ENV.fetch("RAILS_ENV") { "development" }
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
workers ENV.fetch("WEB_CONCURRENCY") { 3 }
# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
......@@ -30,7 +30,7 @@ environment ENV.fetch("RAILS_ENV") { "development" }
# you need to make sure to reconnect any threads in the `on_worker_boot`
# block.
#
# preload_app!
preload_app!
# If you are preloading your application and using Active Record, it's
# recommended that you close any connections to the database before workers
......@@ -47,9 +47,9 @@ end
# or connections that may have been created at application boot, Ruby
# cannot share connections between processes.
#
# on_worker_boot do
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# end
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
......@@ -56,6 +56,7 @@ Rails.application.routes.draw do
resources :performances, except: [:index, :show]
resources :subscriptions do
get :option, on: :collection
get :card, on: :member
patch :toggle_billing, on: :member
end
end
......
class AddPlatformNumberToSubscriptions < ActiveRecord::Migration[5.1]
def change
add_column :subscriptions, :platform_number, :string
end
end
......@@ -33,6 +33,7 @@ FactoryGirl.define do
partners "Member partners text"
updating_password true
password 'pass'
affiliation_number { "#{Faker::Lorem.unique.word}" }
after :build do |member, evaluator|
member.contacts << FactoryGirl.build_list(:contact, 1, member: nil)
......
......@@ -453,6 +453,35 @@ feature "Manage subscriptions" do
end
end
scenario "I can print the licence paper" do
@member.update_attribute(:affiliation_number, "3369")
@settings.platform_collaborating_clubs << @member.member_groups
athle = create :activity, title: "Athlétisme"
foot = create :activity, title: "Football"
adherent = build :adherent, last_name: "Dupont", first_name: "Jean",medico_social_org: nil, other_medicosocial_org: "Une structure", permit_number: "142536"
perf1 = create :performance, member: @member, activity: athle
perf2 = create :performance, member: @member, activity: foot
subscription = create :subscription, adherent: adherent, performances: [perf1, perf2], member_id: @member.id, created_at: Date.new(2017,9,19)
visit card_member_subscription_path(@member, subscription)
within "section#data" do
expect(page).to have_selector("dd", text: "Dupont")
expect(page).to have_selector("dd", text: "Jean")
expect(page).to have_selector("dd", text: "Collaborating club")
expect(page).to have_selector("dd", text: "Une structure")
expect(page).to have_selector("dd", text: "142536")
expect(page).to have_selector("dd", text: "3369")
end
within "section#cover" do
expect(page).to have_content "SAISON 2017-2018"
end
visit member_path(@member)
within "aside#subscriptions li", text: "Jean Dupont" do
expect(page).to have_link "Imprimer carte"
end
end
scenario "I can read the number of mono and multi activities ones" do
perf1 = create :performance, member: @member
perf2 = create :performance, member: @member
......
......@@ -48,5 +48,13 @@ RSpec.describe Adherent, type: :model do
adherent = build :adherent, last_name: "Durand", first_name: "Nicolas"
expect(adherent.name).to eq "Nicolas Durand"
end
it "#medico_social_org_name returns the name of the associated medico-social org" do
medico_social_org = create :member, name: "IME one"
adherent = build :adherent, medico_social_org: medico_social_org
expect(adherent.medico_social_org_name).to eq "IME one"
adherent = build :adherent, medico_social_org: nil, other_medicosocial_org: "IME two"
expect(adherent.medico_social_org_name).to eq "IME two"
end
end
end
#
# OLIGAA - Stands for "Outil en Ligne d'Information et de Gestion des Activités
# des Associations" which is an online tool for associations to manage news,
# actors and activities.
# Copyright (C) 2010-2017 Comité Départemental du Sport Adapté de la Gironde (CDSA
# 33) <contact@cdsa33.org>
#
# This file is part of OLIGAA.
#
# OLIGAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OLIGAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
require 'rails_helper'
RSpec.describe Season, type: :model do
context "regarding initialization" do
context "sets the begining ot the season to" do
scenario "15/08/2017 when date 19/09/2017 is given" do
season = Season.new(Date.new(2017,9,19))
expect(season.instance_variable_get(:@begining)).to eq Date.new(2017,8,15)
end
scenario "15/08/2017 when date 15/08/2017 is given" do
season = Season.new(Date.new(2017,8,15))
expect(season.instance_variable_get(:@begining)).to eq Date.new(2017,8,15)
end
scenario "15/08/2016 when date 14/08/2017 is given" do
season = Season.new(Date.new(2017,8,14))
expect(season.instance_variable_get(:@begining)).to eq Date.new(2016,8,15)
end
end
end
scenario "#shorten returns shorten label" do
season = Season.new(Date.new(2017,9,19))
expect(season.shorten).to eq "1718"
season = Season.new(Date.new(2018,9,19))
expect(season.shorten).to eq "1819"
end
scenario "#label returns full description of the season" do
season = Season.new(Date.new(2017,9,19))
expect(season.label).to eq "Saison 2017-2018"
end
end
......@@ -62,10 +62,10 @@ RSpec.describe Statistics::Pass::Unit, type: :model do
end
end
context "the member is a collaborating medicosocial org" do
context "the member is a medicosocial org" do
before do
mg = create :member_group
Settings.instance.reload.platform_collaborating_medicosocial_orgs << mg
Settings.instance.reload.platform_medicosocial_orgs << mg
club = create :member
collaborating_medicosocial_org = create :member, member_groups: [mg]
perf1 = create :performance, member: club
......
#
# OLIGAA - Stands for "Outil en Ligne d'Information et de Gestion des Activités
# des Associations" which is an online tool for associations to manage news,
# actors and activities.
# Copyright (C) 2010-2017 Comité Départemental du Sport Adapté de la Gironde (CDSA
# 33) <contact@cdsa33.org>
#
# This file is part of OLIGAA.
#
# OLIGAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OLIGAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
require 'rails_helper'
RSpec.describe SubscriptionNumber, type: :model do
before do
@member = create :member, affiliation_number: nil
@subscription = create :subscription, member_id: @member.id, created_at: Date.new(2017,9,19)
@subscription.update_attribute(:platform_number, nil)
end
let(:sn) { SubscriptionNumber.new(@subscription) }
context "regarding initialization" do
it "sets @subscription" do
expect(sn.instance_variable_get(:@subscription)).to eq @subscription
end
end
context "#label" do
scenario "returns 'Numéro d\'affiliation du membre non renseigné' when affiliation number not filled" do
expect(sn.label).to eq "Numéro d'affiliation du membre non renseigné"
end
context "for member with 3369 as affiliation number" do
before do
@member.update_attribute(:affiliation_number, "33/69")
@subscription.reload
end
scenario "returns '3369/1718/001' for the first subscription" do
expect(sn.label).to eq '3369/1718/001'
end
scenario "returns '3369/1718/042' fot the 42nd subscription" do
latest_subscription = create :subscription, member_id: @member.id
latest_subscription.update_attribute(:platform_number, '3369/1718/041')
expect(sn.label).to eq '3369/1718/042'
end
end
end
end
#
# OLIGAA - Stands for "Outil en Ligne d'Information et de Gestion des Activités
# des Associations" which is an online tool for associations to manage news,
# actors and activities.
# Copyright (C) 2010-2017 Comité Départemental du Sport Adapté de la Gironde (CDSA
# 33) <contact@cdsa33.org>
#
# This file is part of OLIGAA.
#
# OLIGAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OLIGAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
require 'rails_helper'
RSpec.describe Subscription, type: :model do
......@@ -27,7 +49,7 @@ RSpec.describe Subscription, type: :model do
expect(Subscription.for_performances([perf1,perf3].map(&:id))).to eq [subscription1]
end
it ".by_adherent_name returns susbscriptions ordered by ascending adherent name" do
it ".by_adherent_name returns subscriptions ordered by ascending adherent name" do
member = create :member
activity = create :activity
perf = create :performance, member: member, activity: activity
......@@ -79,6 +101,12 @@ RSpec.describe Subscription, type: :model do
expect(subscription.external_clubs).to eq [other_club1, other_club2]
end
it "#season returns the season the subscription belongs to" do
date = Date.new(2017,9,19)
subscription = create :subscription, created_at: date
expect(subscription.season).to be_a Season
end
describe "#multipass? " do
let(:perf1) { create :performance }
let(:perf2) { create :performance }
......@@ -87,6 +115,7 @@ RSpec.describe Subscription, type: :model do
subscription = create :subscription, performances: [perf1, perf2]
expect(subscription.multipass?).to be_truthy
end
it "returns false if subscription associated to mono activity" do
subscription = create :subscription, performances: [perf1]
expect(subscription.multipass?).to be_falsy
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment