From 93f1a53dfc1d0017e2646cb80ab9cd8c7d8cd694 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 15 Oct 2018 10:25:25 +0000 Subject: [PATCH] dossier: add page for etablissement --- .../stylesheets/new_design/etablissement.scss | 54 +++++++++++++++++++ .../new_user/dossiers_controller.rb | 10 ++++ .../new_user/dossiers/etablissement.html.haml | 35 ++++++++++++ .../_infos_association.html.haml | 24 +++++++++ .../etablissement/_infos_entreprise.html.haml | 49 +++++++++++++++++ config/routes.rb | 1 + .../new_user/dossiers_controller_spec.rb | 15 ++++++ spec/factories/etablissement.rb | 6 +++ .../dossiers/etablissement.html.haml_spec.rb | 35 ++++++++++++ 9 files changed, 229 insertions(+) create mode 100644 app/assets/stylesheets/new_design/etablissement.scss create mode 100644 app/views/new_user/dossiers/etablissement.html.haml create mode 100644 app/views/new_user/dossiers/etablissement/_infos_association.html.haml create mode 100644 app/views/new_user/dossiers/etablissement/_infos_entreprise.html.haml create mode 100644 spec/views/new_user/dossiers/etablissement.html.haml_spec.rb diff --git a/app/assets/stylesheets/new_design/etablissement.scss b/app/assets/stylesheets/new_design/etablissement.scss new file mode 100644 index 000000000..7b40056d8 --- /dev/null +++ b/app/assets/stylesheets/new_design/etablissement.scss @@ -0,0 +1,54 @@ +@import "constants"; +@import "colors"; + +.etablissement { + margin-top: $default-padding * 2; + margin-bottom: $default-padding * 2; + + h1 { + margin-bottom: $default-padding * 2; + } + + p { + margin-bottom: $default-padding; + } + + .etablissement-infos { + margin-top: $default-padding * 2; + margin-bottom: $default-padding * 2; + + > * { + margin-bottom: $default-padding; + + &:last-child { + margin-bottom: 0; + } + } + + ul { + line-height: 28px; + list-style-type: disc; + list-style-position: inside; + + // Inner lists + ul { + margin-left: $default-padding; + list-style-type: circle; + } + } + + .etablissement-exercices { + font-style: italic; + } + } + + .actions { + display: flex; + flex-wrap: wrap-reverse; + justify-content: space-between; + + .button { + margin-bottom: $default-padding; + } + } +} diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 3ab339981..f93e70967 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -103,6 +103,16 @@ module NewUser redirect_to etablissement_dossier_path end + def etablissement + @dossier = dossier + + # Redirect if the user attempts to access the page URL directly + if !@dossier.etablissement + flash.alert = 'Aucun établissement n’est associé à ce dossier' + return redirect_to siret_dossier_path(@dossier) + end + end + def brouillon @dossier = dossier_with_champs diff --git a/app/views/new_user/dossiers/etablissement.html.haml b/app/views/new_user/dossiers/etablissement.html.haml new file mode 100644 index 000000000..173f40b6e --- /dev/null +++ b/app/views/new_user/dossiers/etablissement.html.haml @@ -0,0 +1,35 @@ +- content_for(:title, "Informations sur l’établissement") + +- content_for :footer do + = render partial: "new_user/dossiers/dossier_footer", locals: { dossier: @dossier } + +.etablissement + .container + %h1 Informations sur l’établissement + + %p + Nous avons récupéré auprès de l’INSEE et d’Infogreffe les informations suivantes concernant votre établissement. + + %p + Ces informations seront jointes à votre dossier. + + .etablissement-infos.card.featured + - etablissement = @dossier.etablissement + %h2.card-title= raison_sociale_or_name(etablissement) + + = render partial: 'new_user/dossiers/etablissement/infos_entreprise', locals: { etablissement: etablissement } + + - if etablissement.association? + = render partial: 'new_user/dossiers/etablissement/infos_association', locals: { etablissement: etablissement } + + .actions + = link_to 'Utiliser un autre numéro SIRET', siret_dossier_path(@dossier), class: 'button' + + - if @dossier.procedure.use_api_carto + / Until the old layout is gone, we need to disable turbolinks + / to avoid the map loading twice (once for the turbolinks preview, + / once when turbolinks notices the layout are differents and reloads + / the page.) + = link_to 'Continuer avec ces informations', users_dossier_carte_path(@dossier), class: 'button primary', data: { turbolinks: false } + - else + = link_to 'Continuer avec ces informations', brouillon_dossier_path(@dossier), class: 'button primary' diff --git a/app/views/new_user/dossiers/etablissement/_infos_association.html.haml b/app/views/new_user/dossiers/etablissement/_infos_association.html.haml new file mode 100644 index 000000000..4fe9b8f91 --- /dev/null +++ b/app/views/new_user/dossiers/etablissement/_infos_association.html.haml @@ -0,0 +1,24 @@ +%ul.etablissement-infos-association + %li + Numéro d’enregistrement au Registre National des Associations : + = etablissement.association_rna + + %li + Titre : + = etablissement.association_titre + + %li + Objet : + = etablissement.association_objet + + %li + Date de création : + = etablissement.association_date_creation&.strftime('%d/%m/%Y') + + %li + Date de déclaration : + = etablissement.association_date_declaration&.strftime('%d/%m/%Y') + + %li + Date de publication : + = etablissement.association_date_publication&.strftime('%d/%m/%Y') diff --git a/app/views/new_user/dossiers/etablissement/_infos_entreprise.html.haml b/app/views/new_user/dossiers/etablissement/_infos_entreprise.html.haml new file mode 100644 index 000000000..54f03b486 --- /dev/null +++ b/app/views/new_user/dossiers/etablissement/_infos_entreprise.html.haml @@ -0,0 +1,49 @@ +%ul.etablissement-infos-entreprise + %li + Siret : + = etablissement.siret + + - if etablissement.siret != etablissement.entreprise.siret_siege_social + %li + SIRET siègle social : + = etablissement.entreprise.siret_siege_social + + %li + Forme juridique : + = etablissement.entreprise.forme_juridique + + %li + Libellé NAF : + = etablissement.libelle_naf + + %li + Code NAF : + = etablissement.naf + + %li + Date de création : + = etablissement.entreprise.date_creation&.strftime('%d/%m/%Y') + + %li + Effectif organisation : + = effectif(etablissement) + + %li + Code effectif : + = etablissement.entreprise.code_effectif_entreprise + + %li + Numéro TVA intracommunautaire : + = etablissement.entreprise.numero_tva_intracommunautaire + + %li + Adresse : + - etablissement.adresse.split("\n").each do |line| + = line + + %li + Capital social : + = pretty_currency(etablissement.entreprise.capital_social) + +- if etablissement.exercices.present? + %p.etablissement-exercices Les exercices comptables des trois dernières années seront joints à votre dossier. diff --git a/config/routes.rb b/config/routes.rb index 737f60fb8..2a8ebd9f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -280,6 +280,7 @@ Rails.application.routes.draw do patch 'update_identite' get 'siret' post 'siret', to: 'dossiers#update_siret' + get 'etablissement' get 'brouillon' patch 'brouillon', to: 'dossiers#update_brouillon' get 'modifier', to: 'dossiers#modifier' diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index cd0d0ab60..3e944ee59 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -335,6 +335,21 @@ describe NewUser::DossiersController, type: :controller do end end + describe '#etablissement' do + let(:dossier) { create(:dossier, :with_entreprise, user: user) } + + before { sign_in(user) } + + subject { get :etablissement, params: { id: dossier.id } } + + it { is_expected.to render_template(:etablissement) } + + context 'when the dossier has no etablissement yet' do + let(:dossier) { create(:dossier, user: user) } + it { is_expected.to redirect_to siret_dossier_path(dossier) } + end + end + describe '#brouillon' do before { sign_in(user) } let!(:dossier) { create(:dossier, user: user, autorisation_donnees: true) } diff --git a/spec/factories/etablissement.rb b/spec/factories/etablissement.rb index ef3f74fc2..1d2040ea8 100644 --- a/spec/factories/etablissement.rb +++ b/spec/factories/etablissement.rb @@ -23,6 +23,12 @@ FactoryBot.define do entreprise_siret_siege_social { '44011762001530' } entreprise_code_effectif_entreprise { '51' } entreprise_date_creation { "1990-04-24" } + + trait :with_exercices do + after(:create) do |etablissement, _evaluator| + create(:exercice, etablissement: etablissement) + end + end end trait :is_association do diff --git a/spec/views/new_user/dossiers/etablissement.html.haml_spec.rb b/spec/views/new_user/dossiers/etablissement.html.haml_spec.rb new file mode 100644 index 000000000..979696a70 --- /dev/null +++ b/spec/views/new_user/dossiers/etablissement.html.haml_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe 'new_user/dossiers/etablissement.html.haml', type: :view do + let(:etablissement) { create(:etablissement, :with_exercices) } + let(:dossier) { create(:dossier, etablissement: etablissement) } + let(:footer) { view.content_for(:footer) } + + before do + sign_in dossier.user + assign(:dossier, dossier) + end + + subject! { render } + + it 'affiche les informations de l’établissement' do + expect(rendered).to have_text(etablissement.entreprise_raison_sociale) + expect(rendered).to have_text(etablissement.siret) + end + + it 'n’affiche pas publiquement les derniers exercices comptables' do + expect(rendered).not_to have_text(number_to_currency(etablissement.exercices.first.ca)) + end + + context 'quand l’établissement est une association' do + let(:etablissement) { create(:etablissement, :is_association) } + + it 'affiche les informations de l’association' do + expect(rendered).to have_text(etablissement.association_titre) + end + end + + it 'prépare le footer' do + expect(footer).to have_selector('footer') + end +end