Nouvelles fonctionnalités : posibilité d'upload plusieurs pièces jointes pour un dossier.
This commit is contained in:
parent
77fe251d8a
commit
587081ff2f
5 changed files with 266 additions and 118 deletions
File diff suppressed because one or more lines are too long
|
@ -2,6 +2,14 @@ class DescriptionController < ApplicationController
|
|||
def show
|
||||
@dossier = Dossier.find(params[:dossier_id])
|
||||
@dossier = @dossier.decorate
|
||||
|
||||
@array_id_pj_valides = Array.new
|
||||
|
||||
DossierPdf.where(dossier_id: @dossier.id).each do |pj_valide|
|
||||
@array_id_pj_valides << pj_valide.ref_pieces_jointes_id
|
||||
end
|
||||
|
||||
@liste_pieces_jointes = get_liste_piece_jointe
|
||||
rescue
|
||||
redirect_to url_for({controller: :start, action: :error_dossier})
|
||||
end
|
||||
|
@ -14,23 +22,28 @@ class DescriptionController < ApplicationController
|
|||
|
||||
def create
|
||||
@dossier = Dossier.find(params[:dossier_id])
|
||||
@dossier.update_attributes(create_params)
|
||||
|
||||
@dossier.nom_projet = params[:nom_projet]
|
||||
@dossier.description = params[:description]
|
||||
@dossier.montant_projet = params[:montant_projet]
|
||||
@dossier.montant_aide_demande = params[:montant_aide_demande]
|
||||
@dossier.date_previsionnelle = params[:date_previsionnelle]
|
||||
@dossier.lien_plus_infos = params[:lien_plus_infos]
|
||||
@dossier.mail_contact = params[:mail_contact]
|
||||
if params[:cerfa_pdf] != nil
|
||||
DossierPdf.destroy_all(dossier_id: @dossier.id, ref_pieces_jointes_id: 0)
|
||||
@dossier_pdf = DossierPdf.new
|
||||
@dossier_pdf.ref_dossier_pdf = params[:cerfa_pdf]
|
||||
@dossier_pdf.ref_pieces_jointes_id = 0
|
||||
@dossier_pdf.dossier = @dossier
|
||||
@dossier_pdf.save
|
||||
end
|
||||
|
||||
@dossier.save
|
||||
get_liste_piece_jointe.each do |pj|
|
||||
if params["piece_jointe_#{pj.id}"] != nil
|
||||
DossierPdf.destroy_all(dossier_id: @dossier.id, ref_pieces_jointes_id: pj.id)
|
||||
|
||||
#upload dossier pdf
|
||||
|
||||
@dossier_pdf = DossierPdf.new
|
||||
@dossier_pdf.ref_dossier_pdf = params[:dossier_pdf]
|
||||
@dossier_pdf.dossier = @dossier
|
||||
@dossier_pdf.save!
|
||||
@dossier_pdf = DossierPdf.new
|
||||
@dossier_pdf.ref_dossier_pdf = params["piece_jointe_#{pj.id}"]
|
||||
@dossier_pdf.ref_pieces_jointes_id = pj.id
|
||||
@dossier_pdf.dossier = @dossier
|
||||
@dossier_pdf.save
|
||||
end
|
||||
end
|
||||
|
||||
if check_missing_attributes(params)||check_format_email(@dossier.mail_contact) == nil
|
||||
redirect_to url_for({controller: :description, action: :error})
|
||||
|
@ -49,11 +62,22 @@ class DescriptionController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def create_params
|
||||
params.permit(:nom_projet, :description, :montant_projet, :montant_aide_demande, :date_previsionnelle, :lien_plus_infos, :mail_contact)
|
||||
end
|
||||
|
||||
#TODO dans un validateur, dans le model
|
||||
def check_missing_attributes params
|
||||
params[:nom_projet].strip == '' || params[:description].strip == '' || params[:montant_projet].strip == '' || params[:montant_aide_demande].strip == '' || params[:date_previsionnelle].strip == '' || params[:mail_contact].strip == ''
|
||||
end
|
||||
|
||||
#TODO dans un validateur, dans le model
|
||||
def check_format_email email
|
||||
/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/.match(email)
|
||||
end
|
||||
|
||||
def get_liste_piece_jointe
|
||||
@formulaire = RefFormulaire.find(@dossier.ref_formulaire)
|
||||
RefPiecesJointe.where ("\"CERFA\" = '#{@formulaire.ref_demarche}'")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -44,20 +44,42 @@
|
|||
%h3 Documents administratifs
|
||||
|
||||
%br
|
||||
%table{class:'table', style:'width:50%; margin-left:5%'}
|
||||
//TODO a refactorer DO
|
||||
%table{class:'table', style:'width:55%; margin-left:5%'}
|
||||
%tr
|
||||
%th{class:'col-lg-4'} Charger votre dossier (.pdf)
|
||||
%td{class:'col-lg-6'}
|
||||
%input{type: 'file',name:'dossier_pdf', id:'dossier_pdf', accept: ".pdf"}
|
||||
%th{class:'col-lg-6'}
|
||||
='Charger votre CERFA (.pdf)'
|
||||
|
||||
%br
|
||||
%p
|
||||
='Afin de facilité votre démarche, nous avons récupéré pour vous :'
|
||||
%ul
|
||||
%li
|
||||
='Votre déclaration sociale'
|
||||
%li
|
||||
='Votre déclaration fiscale'
|
||||
-if @formulaire.lien_demarche != nil
|
||||
%a{style:'font-size:0.9em; padding-left:3px', id: 'lien_cerfa' ,href: "#{@formulaire.lien_demarche}", :target => '_blank'} Lien CERFA
|
||||
|
||||
%td{class:'col-lg-5'}
|
||||
-if @array_id_pj_valides.include?(0)
|
||||
%span.btn.btn-sm.btn-file.btn-success
|
||||
="Modifier"
|
||||
%input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: ".pdf"}
|
||||
-else
|
||||
%span.btn.btn-sm.btn-file.btn-info
|
||||
="Choisir"
|
||||
%input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: ".pdf"}
|
||||
|
||||
-@liste_pieces_jointes.each do |pj|
|
||||
%tr
|
||||
%th{class:'col-lg-6'}
|
||||
=pj.libelle
|
||||
%td{class:'col-lg-5'}
|
||||
-if pj.api_entreprise
|
||||
%span.text-success{id: "piece_jointe_#{pj.id}"} Nous l'avons récupéré pour vous.
|
||||
-else
|
||||
-if @array_id_pj_valides.include?(pj.id)
|
||||
%span.btn.btn-sm.btn-file.btn-success
|
||||
="Modifier"
|
||||
%input{type: 'file', name:"piece_jointe_#{pj.id}", id:"piece_jointe_#{pj.id}", accept: ".pdf"}
|
||||
-else
|
||||
%span.btn.btn-sm.btn-file.btn-info
|
||||
="Choisir"
|
||||
%input{type: 'file', name:"piece_jointe_#{pj.id}", id:"piece_jointe_#{pj.id}", accept: ".pdf"}
|
||||
//END
|
||||
|
||||
%div{style: 'text-align:right'}
|
||||
%h6 Tous les champs portant un * sont obligatoires.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe DescriptionController, type: :controller do
|
||||
describe DescriptionController, type: :controller do
|
||||
let (:dossier_id){10000}
|
||||
let (:bad_dossier_id){1000}
|
||||
|
||||
|
@ -24,22 +24,31 @@ RSpec.describe DescriptionController, type: :controller do
|
|||
let(:montant_aide_demande){3000}
|
||||
let(:date_previsionnelle){'20/01/2016'}
|
||||
let(:mail_contact){'test@test.com'}
|
||||
let(:dossier_pdf) {''}
|
||||
|
||||
let(:name_dossier_pdf){'dossierPDF.pdf'}
|
||||
let(:name_piece_jointe_103){'piece_jointe_103.pdf'}
|
||||
let(:name_piece_jointe_692){'piece_jointe_692.pdf'}
|
||||
|
||||
let(:cerfa_pdf) {Rack::Test::UploadedFile.new("./spec/support/files/#{name_dossier_pdf}", 'application/pdf')}
|
||||
let(:piece_jointe_103) {Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_jointe_103}", 'application/pdf')}
|
||||
let(:piece_jointe_692) {Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_jointe_692}", 'application/pdf')}
|
||||
|
||||
|
||||
context 'Tous les attributs sont bons' do
|
||||
#TODO separer en deux tests : check donnees et check redirect
|
||||
it 'Premier enregistrement des données' do
|
||||
post :create, :dossier_id => dossier_id, :nom_projet => nom_projet, :description => description, :montant_projet => montant_projet, :montant_aide_demande => montant_aide_demande, :date_previsionnelle => date_previsionnelle, :mail_contact => mail_contact
|
||||
expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif")
|
||||
end
|
||||
|
||||
#TODO changer les valeurs des champs et check in bdd
|
||||
context 'En train de modifier les données de description du projet' do
|
||||
before do
|
||||
post :create, :dossier_id => dossier_id, :nom_projet => nom_projet, :description => description, :montant_projet => montant_projet, :montant_aide_demande => montant_aide_demande, :date_previsionnelle => date_previsionnelle, :mail_contact => mail_contact, :back_url => 'recapitulatif'
|
||||
@last_commentaire_id = ActiveRecord::Base.connection.execute("SELECT currval('commentaires_id_seq')").getvalue(0,0)
|
||||
end
|
||||
|
||||
context 'Enregistrement d\'un commentaire informant la modification' do
|
||||
subject{Commentaire.find(@last_commentaire_id)}
|
||||
subject{Commentaire.last}
|
||||
|
||||
it 'champs email' do
|
||||
expect(subject.email).to eq('Modification détails')
|
||||
|
@ -98,5 +107,66 @@ RSpec.describe DescriptionController, type: :controller do
|
|||
expect(response).to redirect_to("/dossiers/#{dossier_id}/description/error")
|
||||
end
|
||||
end
|
||||
|
||||
context 'Sauvegarde du CERFA PDF' do
|
||||
before do
|
||||
post :create, :dossier_id => dossier_id, :nom_projet => nom_projet, :description => description, :montant_projet => montant_projet, :montant_aide_demande => montant_aide_demande, :date_previsionnelle => date_previsionnelle, :mail_contact => mail_contact, :cerfa_pdf => cerfa_pdf
|
||||
end
|
||||
|
||||
context 'un CERFA PDF est envoyé' do
|
||||
subject{DossierPdf.last}
|
||||
it 'ref_dossier_pdf' do
|
||||
expect(subject['ref_dossier_pdf']).to eq(name_dossier_pdf)
|
||||
end
|
||||
|
||||
it 'dossier_id' do
|
||||
expect(subject.dossier_id).to eq(dossier_id)
|
||||
end
|
||||
|
||||
it 'ref_pieces_jointes_id' do
|
||||
expect(subject.ref_pieces_jointes_id).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context 'les anciens CERFA PDF sont écrasées à chaque fois' do
|
||||
it 'il n\'y a qu\'un CERFA PDF par dossier' do
|
||||
post :create, :dossier_id => dossier_id, :nom_projet => nom_projet, :description => description, :montant_projet => montant_projet, :montant_aide_demande => montant_aide_demande, :date_previsionnelle => date_previsionnelle, :mail_contact => mail_contact, :cerfa_pdf => cerfa_pdf
|
||||
cerfa = DossierPdf.where(ref_pieces_jointes_id: '0', dossier_id: dossier_id)
|
||||
expect(cerfa.many?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'pas de CERFA PDF' do
|
||||
#TODO à écrire
|
||||
end
|
||||
end
|
||||
|
||||
context 'Sauvegarde des pièces jointes' do
|
||||
before do
|
||||
post :create, :dossier_id => dossier_id, :nom_projet => nom_projet, :description => description, :montant_projet => montant_projet, :montant_aide_demande => montant_aide_demande, :date_previsionnelle => date_previsionnelle, :mail_contact => mail_contact, :piece_jointe_692 => piece_jointe_692, :piece_jointe_103 => piece_jointe_103
|
||||
end
|
||||
|
||||
context 'sauvegarde de 2 pieces jointes' do
|
||||
it 'les deux pièces sont présentes en base' do
|
||||
piece_jointe_1 = DossierPdf.where(ref_pieces_jointes_id: '103', dossier_id: dossier_id)
|
||||
piece_jointe_2 = DossierPdf.where(ref_pieces_jointes_id: '692', dossier_id: dossier_id)
|
||||
|
||||
expect(piece_jointe_1.first['ref_dossier_pdf']).to eq(name_piece_jointe_103)
|
||||
expect(piece_jointe_2.first['ref_dossier_pdf']).to eq(name_piece_jointe_692)
|
||||
end
|
||||
|
||||
context 'les pièces sont ecrasées à chaque fois' do
|
||||
it 'il n\'y a qu\'une pièce jointe par type par dossier' do
|
||||
post :create, :dossier_id => dossier_id, :nom_projet => nom_projet, :description => description, :montant_projet => montant_projet, :montant_aide_demande => montant_aide_demande, :date_previsionnelle => date_previsionnelle, :mail_contact => mail_contact, :piece_jointe_692 => piece_jointe_692, :piece_jointe_103 => piece_jointe_103
|
||||
|
||||
piece_jointe_1 = DossierPdf.where(ref_pieces_jointes_id: '103', dossier_id: dossier_id)
|
||||
piece_jointe_2 = DossierPdf.where(ref_pieces_jointes_id: '692', dossier_id: dossier_id)
|
||||
|
||||
expect(piece_jointe_1.many?).to eq(false)
|
||||
expect(piece_jointe_2.many?).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -52,12 +52,12 @@ feature 'Description#Show Page' do
|
|||
expect(page).to have_selector('input[type=email][id=mail_contact]')
|
||||
end
|
||||
|
||||
scenario 'Charger un dossier pdf' do
|
||||
expect(page).to have_selector('input[id=dossier_pdf][name=dossier_pdf]')
|
||||
scenario 'Charger votre CERFA (PDF)' do
|
||||
expect(page).to have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]')
|
||||
end
|
||||
|
||||
scenario 'Charger un dossier pdf est de type file' do
|
||||
expect(page).to have_selector('input[type=file][id=dossier_pdf]')
|
||||
scenario 'Lien CERFA' do
|
||||
expect(page).to have_selector('#lien_cerfa')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -121,4 +121,38 @@ feature 'Description#Show Page' do
|
|||
expect(page).to have_selector("input[id=mail_contact][value='#{mail_contact}']")
|
||||
end
|
||||
end
|
||||
|
||||
context 'Pièces jointes' do
|
||||
context 'la liste des pièces jointes a envoyé est affichée' do
|
||||
it 'Attestation RDI' do
|
||||
expect(page).to have_selector('input[type=file][name=piece_jointe_103][id=piece_jointe_103]')
|
||||
end
|
||||
|
||||
it 'Devis' do
|
||||
expect(page).to have_selector('input[type=file][name=piece_jointe_388][id=piece_jointe_388]')
|
||||
end
|
||||
|
||||
it 'Pièce d\'identité' do
|
||||
expect(page).to have_selector('input[type=file][name=piece_jointe_692][id=piece_jointe_692]')
|
||||
end
|
||||
|
||||
it 'Plan de transmission du capital social' do
|
||||
expect(page).to have_selector('input[type=file][name=piece_jointe_764][id=piece_jointe_764]')
|
||||
end
|
||||
|
||||
it 'RIB ou RIP' do
|
||||
expect(page).to have_selector('input[type=file][name=piece_jointe_849][id=piece_jointe_849]')
|
||||
end
|
||||
end
|
||||
|
||||
context 'la liste des pièces récupérées automatiquement est signaliée' do
|
||||
it 'Attestation MSA' do
|
||||
expect(page.find_by_id('piece_jointe_93')).to have_content('Nous l\'avons récupéré pour vous.')
|
||||
end
|
||||
|
||||
it 'KBIS' do
|
||||
expect(page.find_by_id('piece_jointe_571')).to have_content('Nous l\'avons récupéré pour vous.')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue