diff --git a/app/helpers/etablissement_helper.rb b/app/helpers/etablissement_helper.rb new file mode 100644 index 000000000..99bfa433e --- /dev/null +++ b/app/helpers/etablissement_helper.rb @@ -0,0 +1,5 @@ +module EtablissementHelper + def pretty_currency(capital_social) + number_to_currency(capital_social, delimiter: ' ', unit: '€', format: '%n %u') + end +end diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb index 840e1aed5..7ea3a94c9 100644 --- a/app/models/etablissement.rb +++ b/app/models/etablissement.rb @@ -36,6 +36,31 @@ class Etablissement < ApplicationRecord attr_accessor :signature + def entreprise_raison_sociale_or_name + entreprise_raison_sociale.presence || "#{entreprise_nom} #{entreprise_prenom}" + end + + def entreprise_effectif + { + 'NN' => "Unités non employeuses (pas de salarié au cours de l'année de référence et pas d'effectif au 31/12).", + '00' => "0 salarié (n'ayant pas d'effectif au 31/12 mais ayant employé des salariés au cours de l'année de référence)", + '01' => '1 ou 2 salariés', + '02' => '3 à 5 salariés', + '03' => '6 à 9 salariés', + '11' => '10 à 19 salariés', + '12' => '20 à 49 salariés', + '21' => '50 à 99 salariés', + '22' => '100 à 199 salariés', + '31' => '200 à 249 salariés', + '32' => '250 à 499 salariés', + '41' => '500 à 999 salariés', + '42' => '1 000 à 1 999 salariés', + '51' => '2 000 à 4 999 salariés', + '52' => '5 000 à 9 999 salariés', + '53' => '10 000 salariés et plus' + }[entreprise_code_effectif_entreprise] + end + private def validate_signature diff --git a/app/views/new_gestionnaire/dossiers/_champs.html.haml b/app/views/new_gestionnaire/dossiers/_champs.html.haml index 4335f9510..e980c11ec 100644 --- a/app/views/new_gestionnaire/dossiers/_champs.html.haml +++ b/app/views/new_gestionnaire/dossiers/_champs.html.haml @@ -46,6 +46,12 @@ %td.rich-text %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } = simple_format(c.value) + - when "siret" + %th.libelle + = "#{c.libelle} :" + %td.rich-text + %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } + = render partial: "new_gestionnaire/dossiers/identite_entreprise", locals: { etablissement: c.etablissement } - else %th.libelle = "#{c.libelle} :" diff --git a/app/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml b/app/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml index ec3c532eb..ff83d56ef 100644 --- a/app/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml +++ b/app/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml @@ -1,70 +1,64 @@ -- entreprise = entreprise.decorate -- etablissement = entreprise.etablissement - %table.table.vertical.dossier-champs %tbody %tr %th.libelle Dénomination : - %td= entreprise.raison_sociale_or_name + %td= etablissement.entreprise_raison_sociale_or_name %tr %th.libelle SIRET : - %td= entreprise.siret_siege_social + %td= etablissement.entreprise_siret_siege_social %tr %th.libelle Forme juridique : - %td= sanitize(entreprise.forme_juridique) - - if etablissement.present? - %tr - %th.libelle Libellé NAF : - %td= etablissement.libelle_naf - %tr - %th.libelle Code NAF : - %td= etablissement.naf + %td= sanitize(etablissement.entreprise_forme_juridique) + %tr + %th.libelle Libellé NAF : + %td= etablissement.libelle_naf + %tr + %th.libelle Code NAF : + %td= etablissement.naf %tr %th.libelle Date de création : - %td= Time.at(entreprise.date_creation).localtime.strftime("%d/%m/%Y") + %td= etablissement.entreprise_date_creation&.strftime("%d/%m/%Y") %tr %th.libelle Effectif de l'organisation : - %td= entreprise.effectif + %td= etablissement.entreprise_effectif %tr %th.libelle Code effectif : - %td= entreprise.code_effectif_entreprise + %td= etablissement.entreprise_code_effectif_entreprise %tr %th.libelle Numéro de TVA intracommunautaire : - %td= entreprise.numero_tva_intracommunautaire - - if etablissement.present? - %tr - %th.libelle Adresse : - %td - - etablissement.adresse.split("\n").each do |line| - = line - %br + %td= etablissement.entreprise_numero_tva_intracommunautaire + %tr + %th.libelle Adresse : + %td + - etablissement.adresse.split("\n").each do |line| + = line + %br %tr %th.libelle Capital social : - %td= entreprise.pretty_capital_social - - if etablissement.present? - %tr - %th.libelle Exercices : - %td - - etablissement.exercices.each_with_index do |exercice, index| - = "#{exercice.date_fin_exercice.year} : " - = number_to_currency(exercice.ca) - %br - - if entreprise.rna_information.present? + %td= pretty_currency(etablissement.entreprise_capital_social) + %tr + %th.libelle Exercices : + %td + - etablissement.exercices.each_with_index do |exercice, index| + = "#{exercice.date_fin_exercice.year} : " + = pretty_currency(exercice.ca) + %br + - if etablissement.association_rna.present? %tr %th.libelle Numéro RNA : - %td= entreprise.rna_information.association_id + %td= etablissement.association_rna %tr %th.libelle Titre : - %td= entreprise.rna_information.titre + %td= etablissement.association_titre %tr %th.libelle Objet : - %td= entreprise.rna_information.objet + %td= etablissement.association_objet %tr %th.libelle Date de création : - %td= entreprise.rna_information.date_creation&.strftime("%d/%m/%Y") + %td= etablissement.association_date_creation&.strftime("%d/%m/%Y") %tr %th.libelle Date de publication : - %td= entreprise.rna_information.date_publication&.strftime("%d/%m/%Y") + %td= etablissement.association_date_publication&.strftime("%d/%m/%Y") %tr %th.libelle Date de déclaration : - %td= entreprise.rna_information.date_declaration&.strftime("%d/%m/%Y") + %td= etablissement.association_date_declaration&.strftime("%d/%m/%Y") diff --git a/app/views/new_gestionnaire/dossiers/print.html.haml b/app/views/new_gestionnaire/dossiers/print.html.haml index 5d9b1b477..0488c29b7 100644 --- a/app/views/new_gestionnaire/dossiers/print.html.haml +++ b/app/views/new_gestionnaire/dossiers/print.html.haml @@ -5,8 +5,8 @@ = render partial: "new_gestionnaire/dossiers/user_infos", locals: { user: @dossier.user } -- if @dossier.entreprise.present? - = render partial: "identite_entreprise", locals: { entreprise: @dossier.entreprise } +- if @dossier.etablissement.present? + = render partial: "identite_entreprise", locals: { etablissement: @dossier.etablissement } - if @dossier.individual.present? = render partial: "identite_individual", locals: { individual: @dossier.individual } diff --git a/app/views/new_gestionnaire/shared/_show.html.haml b/app/views/new_gestionnaire/shared/_show.html.haml index 846dd1796..aee816d8d 100644 --- a/app/views/new_gestionnaire/shared/_show.html.haml +++ b/app/views/new_gestionnaire/shared/_show.html.haml @@ -3,8 +3,8 @@ .card = render partial: "new_gestionnaire/dossiers/user_infos", locals: { user: dossier.user } - - if dossier.entreprise.present? - = render partial: "new_gestionnaire/dossiers/identite_entreprise", locals: { entreprise: dossier.entreprise } + - if dossier.etablissement.present? + = render partial: "new_gestionnaire/dossiers/identite_entreprise", locals: { etablissement: dossier.etablissement } - if dossier.individual.present? = render partial: "new_gestionnaire/dossiers/identite_individual", locals: { individual: dossier.individual } diff --git a/spec/factories/entreprise.rb b/spec/factories/entreprise.rb index 51752b3b8..9598017da 100644 --- a/spec/factories/entreprise.rb +++ b/spec/factories/entreprise.rb @@ -10,11 +10,5 @@ FactoryBot.define do siret_siege_social '44011762001530' code_effectif_entreprise '51' date_creation Time.at(1453976189).to_datetime - - trait :is_association do - after(:create) do |entreprise, _evaluator| - create(:rna_information, entreprise: entreprise) - end - end end end diff --git a/spec/factories/etablissement.rb b/spec/factories/etablissement.rb index 3c4d43be5..c39f86cf5 100644 --- a/spec/factories/etablissement.rb +++ b/spec/factories/etablissement.rb @@ -12,5 +12,25 @@ FactoryBot.define do code_postal '92270' localite 'BOIS COLOMBES' code_insee_localite '92009' + + entreprise_siren '440117620' + entreprise_capital_social 537_100_000 + entreprise_numero_tva_intracommunautaire 'FR27440117620' + entreprise_forme_juridique 'SA à conseil d\'administration (s.a.i.)' + entreprise_forme_juridique_code '5599' + entreprise_nom_commercial 'GRTGAZ' + entreprise_raison_sociale 'GRTGAZ' + entreprise_siret_siege_social '44011762001530' + entreprise_code_effectif_entreprise '51' + entreprise_date_creation "1990-04-24" + end + + trait :is_association do + association_rna "W072000535" + association_titre "ASSOCIATION POUR LA PROMOTION DE SPECTACLES AU CHATEAU DE ROCHEMAURE" + association_objet "mise en oeuvre et réalisation de spectacles au chateau de rochemaure" + association_date_creation "1990-04-24" + association_date_declaration "2014-11-28" + association_date_publication "1990-05-16" end end diff --git a/spec/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml_spec.rb b/spec/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml_spec.rb index a28649fe1..121e08044 100644 --- a/spec/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml_spec.rb +++ b/spec/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml_spec.rb @@ -1,12 +1,11 @@ describe 'new_gestionnaire/dossiers/identite_entreprise.html.haml', type: :view do - before { render 'new_gestionnaire/dossiers/identite_entreprise.html.haml', entreprise: entreprise } + before { render 'new_gestionnaire/dossiers/identite_entreprise.html.haml', etablissement: etablissement } context "there is an association" do - let(:rna_information) { create(:rna_information) } - let(:entreprise) { rna_information.entreprise } + let(:etablissement) { create(:etablissement, :is_association) } context "date_publication is missing on rna" do - before { rna_information.update(date_publication: nil) } + before { etablissement.update(association_date_publication: nil) } it "can render without error" do expect(rendered).to include("Date de publication :") diff --git a/spec/views/new_gestionnaire/dossiers/show.html.haml_spec.rb b/spec/views/new_gestionnaire/dossiers/show.html.haml_spec.rb index 7ac72030c..4ea0f1caa 100644 --- a/spec/views/new_gestionnaire/dossiers/show.html.haml_spec.rb +++ b/spec/views/new_gestionnaire/dossiers/show.html.haml_spec.rb @@ -3,8 +3,8 @@ describe 'new_gestionnaire/dossiers/show.html.haml', type: :view do let(:current_gestionnaire) { create(:gestionnaire) } let(:individual) { nil } - let(:entreprise) { nil } - let(:dossier) { create(:dossier, :en_construction, entreprise: entreprise, individual: individual) } + let(:etablissement) { nil } + let(:dossier) { create(:dossier, :en_construction, etablissement: etablissement, individual: individual) } before do assign(:dossier, dossier) @@ -12,19 +12,19 @@ describe 'new_gestionnaire/dossiers/show.html.haml', type: :view do render end - context "when dossier was created by an entreprise" do - let(:entreprise) { create(:entreprise) } + context "when dossier was created by an etablissement" do + let(:etablissement) { create(:etablissement) } - it { expect(rendered).to include(entreprise.decorate.raison_sociale_or_name) } - it { expect(rendered).to include(entreprise.decorate.siret_siege_social) } - it { expect(rendered).to include(entreprise.decorate.forme_juridique) } + it { expect(rendered).to include(etablissement.entreprise_raison_sociale_or_name) } + it { expect(rendered).to include(etablissement.entreprise_siret_siege_social) } + it { expect(rendered).to include(etablissement.entreprise_forme_juridique) } context "and entreprise is an association" do - let(:entreprise) { create(:entreprise, :is_association) } + let(:etablissement) { create(:etablissement, :is_association) } - it { expect(rendered).to include(entreprise.rna_information.association_id) } - it { expect(rendered).to include(entreprise.rna_information.titre) } - it { expect(rendered).to include(entreprise.rna_information.objet) } + it { expect(rendered).to include(etablissement.association_rna) } + it { expect(rendered).to include(etablissement.association_titre) } + it { expect(rendered).to include(etablissement.association_objet) } end end