2015-08-10 11:05:06 +02:00
|
|
|
class DossiersController < ApplicationController
|
|
|
|
def show
|
|
|
|
@dossier = Dossier.find(params[:id])
|
|
|
|
|
2015-08-11 15:38:34 +02:00
|
|
|
@etablissement = @dossier.etablissement
|
2015-08-10 11:05:06 +02:00
|
|
|
@entreprise = @dossier.entreprise.decorate
|
2015-08-13 15:55:19 +02:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2015-08-17 16:27:21 +02:00
|
|
|
redirect_to url_for(controller: :start, action: :error_dossier)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
|
|
|
@dossier_id = params[:pro_dossier_id].strip
|
|
|
|
|
2015-08-17 16:27:21 +02:00
|
|
|
if dossier_id_is_present?
|
2015-08-10 11:05:06 +02:00
|
|
|
|
|
|
|
@dossier = Dossier.find(@dossier_id)
|
|
|
|
|
2015-08-17 15:53:35 +02:00
|
|
|
if @dossier.siret == params[:siret]
|
2015-08-17 16:27:21 +02:00
|
|
|
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: @dossier_id)
|
2015-08-10 11:05:06 +02:00
|
|
|
else
|
2015-08-17 16:27:21 +02:00
|
|
|
redirect_to url_for(controller: :start, action: :error_dossier)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
else
|
2015-08-17 15:53:35 +02:00
|
|
|
|
2015-08-17 16:27:21 +02:00
|
|
|
@etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params)
|
|
|
|
@entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params)
|
2015-08-10 11:05:06 +02:00
|
|
|
@dossier = Dossier.create
|
|
|
|
|
|
|
|
@entreprise.dossier = @dossier
|
|
|
|
@entreprise.save
|
|
|
|
|
|
|
|
@etablissement.dossier = @dossier
|
|
|
|
@etablissement.entreprise = @entreprise
|
|
|
|
@etablissement.save
|
|
|
|
|
2015-08-17 16:27:21 +02:00
|
|
|
redirect_to url_for(controller: :dossiers, action: :show, id: @dossier.id)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
2015-08-17 15:53:35 +02:00
|
|
|
|
|
|
|
rescue RestClient::ResourceNotFound
|
2015-08-17 16:27:21 +02:00
|
|
|
redirect_to url_for(controller: :start, action: :error_siret)
|
2015-08-17 15:53:35 +02:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2015-08-17 16:27:21 +02:00
|
|
|
redirect_to url_for(controller: :start, action: :error_dossier)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-08-13 15:55:19 +02:00
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
@dossier = Dossier.find(params[:id])
|
2015-08-17 16:27:21 +02:00
|
|
|
if checked_autorisation_donnees?
|
|
|
|
@dossier.update_attributes(update_params)
|
2015-08-10 11:05:06 +02:00
|
|
|
redirect_to url_for({controller: :demandes, action: :show, dossier_id: @dossier.id})
|
|
|
|
else
|
2015-08-11 15:38:34 +02:00
|
|
|
@etablissement = @dossier.etablissement
|
2015-08-10 11:05:06 +02:00
|
|
|
@entreprise = @dossier.entreprise.decorate
|
2015-08-17 16:27:21 +02:00
|
|
|
flash.now.alert = 'Les conditions sont obligatoires.'
|
|
|
|
render 'show'
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-11 15:22:07 +02:00
|
|
|
private
|
|
|
|
|
2015-08-13 15:55:19 +02:00
|
|
|
def update_params
|
|
|
|
params.require(:dossier).permit(:autorisation_donnees)
|
|
|
|
end
|
|
|
|
|
2015-08-11 15:22:07 +02:00
|
|
|
def dossier_id_is_present?
|
2015-08-17 16:27:21 +02:00
|
|
|
@dossier_id != ""
|
|
|
|
end
|
2015-08-11 15:22:07 +02:00
|
|
|
|
2015-08-17 16:27:21 +02:00
|
|
|
def checked_autorisation_donnees?
|
|
|
|
update_params[:autorisation_donnees] == '1'
|
2015-08-11 15:22:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def siret
|
|
|
|
params[:siret]
|
|
|
|
end
|
|
|
|
|
|
|
|
def siren
|
|
|
|
siret[0..8]
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|