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
|
|
|
|
|
2015-09-21 11:36:26 +02:00
|
|
|
@etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params)
|
|
|
|
@entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params)
|
|
|
|
@dossier = Dossier.create
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-09-21 17:59:03 +02:00
|
|
|
@dossier.procedure_id
|
|
|
|
|
2015-09-21 11:36:26 +02:00
|
|
|
@entreprise.dossier = @dossier
|
|
|
|
@entreprise.save
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-09-21 11:36:26 +02:00
|
|
|
@etablissement.dossier = @dossier
|
|
|
|
@etablissement.entreprise = @entreprise
|
|
|
|
@etablissement.save
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-09-21 11:36:26 +02:00
|
|
|
redirect_to url_for(controller: :dossiers, action: :show, id: @dossier.id)
|
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
|
|
|
|
@dossier = Dossier.find(params[:id])
|
2015-08-17 16:27:21 +02:00
|
|
|
if checked_autorisation_donnees?
|
|
|
|
@dossier.update_attributes(update_params)
|
2015-09-21 11:36:26 +02:00
|
|
|
redirect_to url_for(controller: :description, action: :show, dossier_id: @dossier.id)
|
2015-08-10 11:05:06 +02:00
|
|
|
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-20 16:37:40 +02:00
|
|
|
@dossier_id != ''
|
2015-08-17 16:27:21 +02:00
|
|
|
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
|