2015-09-23 19:20:03 +02:00
|
|
|
class Users::DossiersController < UsersController
|
2015-09-23 12:04:57 +02:00
|
|
|
before_action :authenticate_user!
|
2015-12-03 15:02:22 +01:00
|
|
|
before_action :check_siret, only: :create
|
2015-11-03 15:27:49 +01:00
|
|
|
|
2015-11-30 15:56:06 +01:00
|
|
|
def index
|
2015-12-02 16:52:09 +01:00
|
|
|
order = 'DESC'
|
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
@liste = params[:liste] || 'a_traiter'
|
|
|
|
@dossiers = dossiers_to_display.paginate(page: params[:page]).decorate
|
2015-12-02 16:52:09 +01:00
|
|
|
|
|
|
|
total_dossiers_per_state
|
2015-11-30 15:56:06 +01:00
|
|
|
end
|
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
def new
|
|
|
|
procedure = Procedure.where(archived: false).find(params[:procedure_id])
|
|
|
|
|
|
|
|
@dossier = Dossier.new(procedure: procedure)
|
|
|
|
@siret = params[:siret] || current_user.siret
|
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
error_procedure
|
|
|
|
end
|
|
|
|
|
2015-11-26 12:29:34 +01:00
|
|
|
def show
|
2015-12-24 15:10:20 +01:00
|
|
|
@facade = DossierFacades.new params[:id], current_user.email
|
2015-09-23 19:20:03 +02:00
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
flash.alert = t('errors.messages.dossier_not_found')
|
2015-12-03 12:00:22 +01:00
|
|
|
redirect_to url_for users_dossiers_path
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-12-24 15:10:20 +01:00
|
|
|
etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params)
|
|
|
|
entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params)
|
2015-12-11 12:36:44 +01:00
|
|
|
rna_information = SIADE::RNAAdapter.new(siret).to_params
|
2015-11-16 11:23:29 +01:00
|
|
|
exercices = SIADE::ExercicesAdapter.new(siret).to_params
|
|
|
|
|
|
|
|
unless exercices.nil?
|
|
|
|
exercices.each_value do |exercice|
|
|
|
|
exercice = Exercice.new(exercice)
|
2015-12-24 15:10:20 +01:00
|
|
|
exercice.etablissement = etablissement
|
2015-11-16 11:23:29 +01:00
|
|
|
exercice.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
dossier = Dossier.create(user: current_user, state: 'draft', procedure_id: create_params[:procedure_id])
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
entreprise.dossier = dossier
|
|
|
|
entreprise.save
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-11 12:36:44 +01:00
|
|
|
unless rna_information.nil?
|
|
|
|
rna_information = RNAInformation.new(rna_information)
|
2015-12-24 15:10:20 +01:00
|
|
|
rna_information.entreprise = entreprise
|
2015-12-11 12:36:44 +01:00
|
|
|
rna_information.save
|
|
|
|
end
|
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
etablissement.dossier = dossier
|
|
|
|
etablissement.entreprise = entreprise
|
|
|
|
etablissement.save
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
redirect_to url_for(controller: :dossiers, action: :show, id: dossier.id)
|
2015-09-23 19:20:03 +02:00
|
|
|
|
|
|
|
rescue RestClient::ResourceNotFound
|
2015-12-03 15:02:22 +01:00
|
|
|
errors_valid_siret
|
2015-12-03 12:00:22 +01:00
|
|
|
|
2015-09-23 19:20:03 +02:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
flash.alert = t('errors.messages.dossier_not_found')
|
|
|
|
redirect_to url_for(controller: :siret)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-12-24 15:10:20 +01:00
|
|
|
@facade = DossierFacades.new params[:id], current_user.email
|
2015-09-23 19:20:03 +02:00
|
|
|
|
|
|
|
if checked_autorisation_donnees?
|
2015-12-24 15:10:20 +01:00
|
|
|
@facade.dossier.update_attributes(update_params)
|
2015-09-28 18:55:16 +02:00
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
if @facade.dossier.procedure.module_api_carto.use_api_carto
|
|
|
|
redirect_to url_for(controller: :carte, action: :show, dossier_id: @facade.dossier.id)
|
2015-09-28 18:55:16 +02:00
|
|
|
else
|
2015-12-24 15:10:20 +01:00
|
|
|
redirect_to url_for(controller: :description, action: :show, dossier_id: @facade.dossier.id)
|
2015-09-28 18:55:16 +02:00
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
else
|
|
|
|
flash.now.alert = 'Les conditions sont obligatoires.'
|
|
|
|
render 'show'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-27 13:56:54 +01:00
|
|
|
def archive
|
2015-12-24 15:10:20 +01:00
|
|
|
dossier = current_user.dossiers.find(params[:dossier_id])
|
|
|
|
dossier.update_attributes({archived: true})
|
2015-11-27 13:56:54 +01:00
|
|
|
|
|
|
|
flash.notice = 'Dossier archivé'
|
|
|
|
redirect_to users_dossiers_path
|
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
flash.alert = 'Dossier inéxistant'
|
|
|
|
redirect_to users_dossiers_path
|
|
|
|
end
|
|
|
|
|
2015-09-23 19:20:03 +02:00
|
|
|
private
|
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
def dossiers_to_display
|
|
|
|
{'a_traiter' => waiting_for_user,
|
|
|
|
'en_attente' => waiting_for_gestionnaire,
|
|
|
|
'termine' => termine}[@liste]
|
|
|
|
end
|
|
|
|
|
|
|
|
def waiting_for_user
|
|
|
|
@en_attente_class = (@liste == 'a_traiter' ? 'active' : '')
|
|
|
|
@waiting_for_user ||= current_user.dossiers.waiting_for_user 'DESC'
|
|
|
|
end
|
|
|
|
|
|
|
|
def waiting_for_gestionnaire
|
|
|
|
@a_traiter_class = (@liste == 'en_attente' ? 'active' : '')
|
|
|
|
@waiting_for_gestionnaire ||= current_user.dossiers.waiting_for_gestionnaire 'DESC'
|
|
|
|
end
|
|
|
|
|
|
|
|
def termine
|
|
|
|
@termine_class = (@liste == 'termine' ? 'active' : '')
|
|
|
|
@termine ||= current_user.dossiers.termine 'DESC'
|
|
|
|
end
|
|
|
|
|
|
|
|
def total_dossiers_per_state
|
|
|
|
@dossiers_a_traiter_total = waiting_for_gestionnaire.count
|
|
|
|
@dossiers_en_attente_total = waiting_for_user.count
|
|
|
|
@dossiers_termine_total = termine.count
|
|
|
|
end
|
|
|
|
|
2015-12-03 15:02:22 +01:00
|
|
|
def check_siret
|
|
|
|
errors_valid_siret unless Siret.new(siret: siret).valid?
|
|
|
|
end
|
|
|
|
|
|
|
|
def errors_valid_siret
|
|
|
|
flash.alert = t('errors.messages.invalid_siret')
|
|
|
|
redirect_to url_for new_users_dossiers_path(procedure_id: create_params[:procedure_id])
|
|
|
|
end
|
|
|
|
|
2015-09-23 19:20:03 +02:00
|
|
|
def update_params
|
|
|
|
params.require(:dossier).permit(:autorisation_donnees)
|
|
|
|
end
|
|
|
|
|
|
|
|
def checked_autorisation_donnees?
|
|
|
|
update_params[:autorisation_donnees] == '1'
|
|
|
|
end
|
|
|
|
|
|
|
|
def siret
|
2015-12-03 12:00:22 +01:00
|
|
|
create_params[:siret]
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def siren
|
|
|
|
siret[0..8]
|
|
|
|
end
|
2015-11-30 14:48:37 +01:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
def create_params
|
|
|
|
params.require(:dossier).permit(:siret, :procedure_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def error_procedure
|
|
|
|
render :file => "#{Rails.root}/public/404_procedure_not_found.html", :status => 404
|
|
|
|
end
|
2015-09-23 12:04:57 +02:00
|
|
|
end
|