Merge branch 'dev'

This commit is contained in:
gregoirenovel 2018-04-10 12:11:17 +02:00
commit f94373f791
19 changed files with 201 additions and 68 deletions

View file

@ -103,6 +103,7 @@ Dans le fichier `config/intializers/token.rb`, ajouter
WeeklyOverviewJob.set(cron: "0 8 * * 0").perform_later WeeklyOverviewJob.set(cron: "0 8 * * 0").perform_later
AutoReceiveDossiersForProcedureJob.set(cron: "* * * * *").perform_later(procedure_declaratoire_id, 'en_instruction') AutoReceiveDossiersForProcedureJob.set(cron: "* * * * *").perform_later(procedure_declaratoire_id, 'en_instruction')
FindDubiousProceduresJob.set(cron: "0 0 * * *").perform_later FindDubiousProceduresJob.set(cron: "0 0 * * *").perform_later
Administrateurs::ActivateBeforeExpirationJob.set(cron: "0 8 * * *").perform_later
## Exécution des tests (RSpec) ## Exécution des tests (RSpec)

View file

@ -28,6 +28,8 @@ function on_change_type_de_champ_select (){
parent.removeClass('header-section'); parent.removeClass('header-section');
parent.children(".drop-down-list").removeClass('show-inline'); parent.children(".drop-down-list").removeClass('show-inline');
parent.children(".pj-template").removeClass('show-inline');
$('.mandatory', parent).show(); $('.mandatory', parent).show();
switch(this.value){ switch(this.value){
@ -38,6 +40,9 @@ function on_change_type_de_champ_select (){
case 'multiple_drop_down_list': case 'multiple_drop_down_list':
parent.children(".drop-down-list").addClass('show-inline'); parent.children(".drop-down-list").addClass('show-inline');
break; break;
case 'piece_justificative':
parent.children(".pj-template").addClass('show-inline');
break;
case 'explication': case 'explication':
$('.mandatory', parent).hide(); $('.mandatory', parent).hide();
break; break;

View file

@ -31,7 +31,8 @@
display: inline-block !important; display: inline-block !important;
} }
.form-group.drop-down-list { .form-group.drop-down-list,
.form-group.pj-template {
display: none; display: none;
} }

View file

@ -0,0 +1,5 @@
module EtablissementHelper
def pretty_currency(capital_social)
number_to_currency(capital_social, delimiter: ' ', unit: '€', format: '%n %u')
end
end

View file

@ -36,6 +36,31 @@ class Etablissement < ApplicationRecord
attr_accessor :signature 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 private
def validate_signature def validate_signature

View file

@ -40,12 +40,15 @@ class TypeDeChamp < ApplicationRecord
end end
has_one :drop_down_list has_one :drop_down_list
has_one_attached :piece_justificative_template
accepts_nested_attributes_for :drop_down_list accepts_nested_attributes_for :drop_down_list
validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :type_champ, presence: true, allow_blank: false, allow_nil: false validates :type_champ, presence: true, allow_blank: false, allow_nil: false
before_validation :check_mandatory before_validation :check_mandatory
before_save :remove_piece_justificative_template, if: -> { type_champ_changed? }
def params_for_champ def params_for_champ
{ {
@ -77,4 +80,12 @@ class TypeDeChamp < ApplicationRecord
def self.type_champ_to_class_name(type_champ) def self.type_champ_to_class_name(type_champ)
"TypesDeChamp::#{type_champ.classify}TypeDeChamp" "TypesDeChamp::#{type_champ.classify}TypeDeChamp"
end end
private
def remove_piece_justificative_template
if type_champ != 'piece_justificative' && piece_justificative_template.attached?
piece_justificative_template.purge_later
end
end
end end

View file

@ -13,6 +13,7 @@ class TypesDeChampService
:type_champ, :type_champ,
:id, :id,
:mandatory, :mandatory,
:piece_justificative_template,
drop_down_list_attributes: [:value, :id] drop_down_list_attributes: [:value, :id]
]) ])

View file

@ -21,6 +21,23 @@
~ fff.text_area :value, class: 'form-control drop_down_list', placeholder: "Ecrire une valeur par ligne et --valeur-- pour un séparateur.", rows: 3, cols: 30 ~ fff.text_area :value, class: 'form-control drop_down_list', placeholder: "Ecrire une valeur par ligne et --valeur-- pour un séparateur.", rows: 3, cols: 30
= fff.hidden_field :id = fff.hidden_field :id
.form-group.pj-template{ class: (type_champ == 'piece_justificative') ? 'show-inline' : nil }
%h4 Modèle
- if type_champ == 'piece_justificative'
- template = ff.object.object.piece_justificative_template
- if !template.attached?
= ff.file_field :piece_justificative_template,
direct_upload: true
- else
= link_to template.filename.to_s, url_for(template), target: '_blank'
%br
Modifier :
= ff.file_field :piece_justificative_template,
direct_upload: true
- else
= ff.file_field :piece_justificative_template,
direct_upload: true
- hide_mandatory = (ff.object.object.private? || type_champ == 'explication') - hide_mandatory = (ff.object.object.private? || type_champ == 'explication')
.form-group.mandatory{ style: hide_mandatory ? 'visibility: hidden;' : nil } .form-group.mandatory{ style: hide_mandatory ? 'visibility: hidden;' : nil }
@ -46,7 +63,10 @@
.form-group .form-group
%br &nbsp; %br &nbsp;
- if ff.object.id.nil? - if ff.object.id.nil?
= f.submit "Ajouter le champ", class: 'btn btn-success', id: @types_de_champ_facade.add_button_id = f.button 'Ajouter le champ',
id: @types_de_champ_facade.add_button_id,
class: 'btn btn-success',
data: { disable_with: 'Envoi...' }
- else - else
= link_to("", @types_de_champ_facade.delete_url(ff), method: :delete, remote: true, id: "delete_type_de_champ_#{ff.object.id}", class: %w(form-control btn btn-danger fa fa-trash-o) ) = link_to("", @types_de_champ_facade.delete_url(ff), method: :delete, remote: true, id: "delete_type_de_champ_#{ff.object.id}", class: %w(form-control btn btn-danger fa fa-trash-o) )

View file

@ -1,6 +1,11 @@
= form_for [:admin, @procedure], url: @types_de_champ_facade.url, remote: true do |f| = form_for [:admin, @procedure], url: @types_de_champ_facade.url, remote: true do |f|
= render partial: 'admin/types_de_champ/fields', locals: { types_de_champ: @types_de_champ_facade.types_de_champ, f: f } = render partial: 'admin/types_de_champ/fields', locals: { types_de_champ: @types_de_champ_facade.types_de_champ, f: f }
= f.submit "Enregistrer", class: 'btn btn-success', id: :save
= f.button 'Enregistrer',
id: :save,
class: 'btn btn-success',
data: { disable_with: 'Envoi...' }
%hr %hr
#new_type_de_champ #new_type_de_champ
= render partial: 'admin/types_de_champ/fields', locals: { types_de_champ: @types_de_champ_facade.new_type_de_champ, f: f } = render partial: 'admin/types_de_champ/fields', locals: { types_de_champ: @types_de_champ_facade.new_type_de_champ, f: f }

View file

@ -46,6 +46,12 @@
%td.rich-text %td.rich-text
%span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) }
= simple_format(c.value) = 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 - else
%th.libelle %th.libelle
= "#{c.libelle} :" = "#{c.libelle} :"

View file

@ -1,18 +1,14 @@
- entreprise = entreprise.decorate
- etablissement = entreprise.etablissement
%table.table.vertical.dossier-champs %table.table.vertical.dossier-champs
%tbody %tbody
%tr %tr
%th.libelle Dénomination : %th.libelle Dénomination :
%td= entreprise.raison_sociale_or_name %td= etablissement.entreprise_raison_sociale_or_name
%tr %tr
%th.libelle SIRET : %th.libelle SIRET :
%td= entreprise.siret_siege_social %td= etablissement.entreprise_siret_siege_social
%tr %tr
%th.libelle Forme juridique : %th.libelle Forme juridique :
%td= sanitize(entreprise.forme_juridique) %td= sanitize(etablissement.entreprise_forme_juridique)
- if etablissement.present?
%tr %tr
%th.libelle Libellé NAF : %th.libelle Libellé NAF :
%td= etablissement.libelle_naf %td= etablissement.libelle_naf
@ -21,17 +17,16 @@
%td= etablissement.naf %td= etablissement.naf
%tr %tr
%th.libelle Date de création : %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 %tr
%th.libelle Effectif de l'organisation : %th.libelle Effectif de l'organisation :
%td= entreprise.effectif %td= etablissement.entreprise_effectif
%tr %tr
%th.libelle Code effectif : %th.libelle Code effectif :
%td= entreprise.code_effectif_entreprise %td= etablissement.entreprise_code_effectif_entreprise
%tr %tr
%th.libelle Numéro de TVA intracommunautaire : %th.libelle Numéro de TVA intracommunautaire :
%td= entreprise.numero_tva_intracommunautaire %td= etablissement.entreprise_numero_tva_intracommunautaire
- if etablissement.present?
%tr %tr
%th.libelle Adresse : %th.libelle Adresse :
%td %td
@ -40,31 +35,30 @@
%br %br
%tr %tr
%th.libelle Capital social : %th.libelle Capital social :
%td= entreprise.pretty_capital_social %td= pretty_currency(etablissement.entreprise_capital_social)
- if etablissement.present?
%tr %tr
%th.libelle Exercices : %th.libelle Exercices :
%td %td
- etablissement.exercices.each_with_index do |exercice, index| - etablissement.exercices.each_with_index do |exercice, index|
= "#{exercice.date_fin_exercice.year} : " = "#{exercice.date_fin_exercice.year} : "
= number_to_currency(exercice.ca) = pretty_currency(exercice.ca)
%br %br
- if entreprise.rna_information.present? - if etablissement.association_rna.present?
%tr %tr
%th.libelle Numéro RNA : %th.libelle Numéro RNA :
%td= entreprise.rna_information.association_id %td= etablissement.association_rna
%tr %tr
%th.libelle Titre : %th.libelle Titre :
%td= entreprise.rna_information.titre %td= etablissement.association_titre
%tr %tr
%th.libelle Objet : %th.libelle Objet :
%td= entreprise.rna_information.objet %td= etablissement.association_objet
%tr %tr
%th.libelle Date de création : %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 %tr
%th.libelle Date de publication : %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 %tr
%th.libelle Date de déclaration : %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")

View file

@ -5,8 +5,8 @@
= render partial: "new_gestionnaire/dossiers/user_infos", locals: { user: @dossier.user } = render partial: "new_gestionnaire/dossiers/user_infos", locals: { user: @dossier.user }
- if @dossier.entreprise.present? - if @dossier.etablissement.present?
= render partial: "identite_entreprise", locals: { entreprise: @dossier.entreprise } = render partial: "identite_entreprise", locals: { etablissement: @dossier.etablissement }
- if @dossier.individual.present? - if @dossier.individual.present?
= render partial: "identite_individual", locals: { individual: @dossier.individual } = render partial: "identite_individual", locals: { individual: @dossier.individual }

View file

@ -3,8 +3,8 @@
.card .card
= render partial: "new_gestionnaire/dossiers/user_infos", locals: { user: dossier.user } = render partial: "new_gestionnaire/dossiers/user_infos", locals: { user: dossier.user }
- if dossier.entreprise.present? - if dossier.etablissement.present?
= render partial: "new_gestionnaire/dossiers/identite_entreprise", locals: { entreprise: dossier.entreprise } = render partial: "new_gestionnaire/dossiers/identite_entreprise", locals: { etablissement: dossier.etablissement }
- if dossier.individual.present? - if dossier.individual.present?
= render partial: "new_gestionnaire/dossiers/identite_individual", locals: { individual: dossier.individual } = render partial: "new_gestionnaire/dossiers/identite_individual", locals: { individual: dossier.individual }

View file

@ -1,5 +1,10 @@
- pj = champ.piece_justificative_file - pj = champ.piece_justificative_file
- if champ.type_de_champ.piece_justificative_template.attached?
%p.edit-pj-template.mb-1
Veuillez télécharger, remplir et joindre le
= link_to('le modèle suivant', url_for(champ.type_de_champ.piece_justificative_template), target: '_blank')
- if !pj.attached? - if !pj.attached?
= form.file_field :piece_justificative_file, = form.file_field :piece_justificative_file,
id: "champs_#{champ.id}", id: "champs_#{champ.id}",

View file

@ -10,11 +10,5 @@ FactoryBot.define do
siret_siege_social '44011762001530' siret_siege_social '44011762001530'
code_effectif_entreprise '51' code_effectif_entreprise '51'
date_creation Time.at(1453976189).to_datetime 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
end end

View file

@ -12,5 +12,25 @@ FactoryBot.define do
code_postal '92270' code_postal '92270'
localite 'BOIS COLOMBES' localite 'BOIS COLOMBES'
code_insee_localite '92009' 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
end end

View file

@ -38,5 +38,46 @@ shared_examples 'type_de_champ_spec' do
it { is_expected.to allow_value('').for(:description) } it { is_expected.to allow_value('').for(:description) }
it { is_expected.to allow_value('blabla').for(:description) } it { is_expected.to allow_value('blabla').for(:description) }
end end
context 'remove piece_justificative_template' do
context 'when the tdc is piece_justificative' do
let(:template_double) { double('template', attached?: attached, purge_later: true) }
let(:tdc) { create(:type_de_champ_piece_justificative) }
subject { template_double }
before do
allow(tdc).to receive(:piece_justificative_template).and_return(template_double)
tdc.update_attribute('type_champ', target_type_champ)
end
context 'when the target type_champ is not pj' do
let(:target_type_champ) { 'text' }
context 'calls template.purge_later when a file is attached' do
let(:attached) { true }
it { is_expected.to have_received(:purge_later) }
end
context 'does not call template.purge_later when no file is attached' do
let(:attached) { false }
it { is_expected.not_to have_received(:purge_later) }
end
end
context 'when the target type_champ is pj' do
let(:target_type_champ) { 'piece_justificative' }
context 'does not call template.purge_later when a file is attached' do
let(:attached) { true }
it { is_expected.not_to have_received(:purge_later) }
end
end
end
end
end end
end end

View file

@ -1,12 +1,11 @@
describe 'new_gestionnaire/dossiers/identite_entreprise.html.haml', type: :view do 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 context "there is an association" do
let(:rna_information) { create(:rna_information) } let(:etablissement) { create(:etablissement, :is_association) }
let(:entreprise) { rna_information.entreprise }
context "date_publication is missing on rna" do 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 it "can render without error" do
expect(rendered).to include("Date de publication :") expect(rendered).to include("Date de publication :")

View file

@ -3,8 +3,8 @@ describe 'new_gestionnaire/dossiers/show.html.haml', type: :view do
let(:current_gestionnaire) { create(:gestionnaire) } let(:current_gestionnaire) { create(:gestionnaire) }
let(:individual) { nil } let(:individual) { nil }
let(:entreprise) { nil } let(:etablissement) { nil }
let(:dossier) { create(:dossier, :en_construction, entreprise: entreprise, individual: individual) } let(:dossier) { create(:dossier, :en_construction, etablissement: etablissement, individual: individual) }
before do before do
assign(:dossier, dossier) assign(:dossier, dossier)
@ -12,19 +12,19 @@ describe 'new_gestionnaire/dossiers/show.html.haml', type: :view do
render render
end end
context "when dossier was created by an entreprise" do context "when dossier was created by an etablissement" do
let(:entreprise) { create(:entreprise) } let(:etablissement) { create(:etablissement) }
it { expect(rendered).to include(entreprise.decorate.raison_sociale_or_name) } it { expect(rendered).to include(etablissement.entreprise_raison_sociale_or_name) }
it { expect(rendered).to include(entreprise.decorate.siret_siege_social) } it { expect(rendered).to include(etablissement.entreprise_siret_siege_social) }
it { expect(rendered).to include(entreprise.decorate.forme_juridique) } it { expect(rendered).to include(etablissement.entreprise_forme_juridique) }
context "and entreprise is an association" do 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(etablissement.association_rna) }
it { expect(rendered).to include(entreprise.rna_information.titre) } it { expect(rendered).to include(etablissement.association_titre) }
it { expect(rendered).to include(entreprise.rna_information.objet) } it { expect(rendered).to include(etablissement.association_objet) }
end end
end end