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-11-03 15:27:49 +01:00
|
|
|
|
2015-11-30 15:56:06 +01:00
|
|
|
def index
|
|
|
|
redirect_to users_dossiers_a_traiter_path
|
|
|
|
end
|
|
|
|
|
2015-11-26 12:29:34 +01:00
|
|
|
def show
|
2015-10-09 17:33:33 +02:00
|
|
|
@dossier = current_user_dossier params[:id]
|
2015-09-23 19:20:03 +02:00
|
|
|
|
|
|
|
@etablissement = @dossier.etablissement
|
|
|
|
@entreprise = @dossier.entreprise.decorate
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
flash.alert = t('errors.messages.dossier_not_found')
|
|
|
|
redirect_to url_for(controller: :siret)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params)
|
|
|
|
@entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).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)
|
|
|
|
exercice.etablissement = @etablissement
|
|
|
|
exercice.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-30 17:03:36 +01:00
|
|
|
@dossier = Dossier.create(user: current_user, state: 'draft', procedure_id: params['procedure_id'])
|
2015-09-23 19:20:03 +02:00
|
|
|
|
|
|
|
@entreprise.dossier = @dossier
|
|
|
|
@entreprise.save
|
|
|
|
|
|
|
|
@etablissement.dossier = @dossier
|
|
|
|
@etablissement.entreprise = @entreprise
|
|
|
|
@etablissement.save
|
|
|
|
|
|
|
|
redirect_to url_for(controller: :dossiers, action: :show, id: @dossier.id)
|
|
|
|
|
|
|
|
rescue RestClient::ResourceNotFound
|
|
|
|
flash.alert = t('errors.messages.invalid_siret')
|
|
|
|
redirect_to url_for(controller: :siret, procedure_id: params['procedure_id'])
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
flash.alert = t('errors.messages.dossier_not_found')
|
|
|
|
redirect_to url_for(controller: :siret)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
2015-10-09 17:33:33 +02:00
|
|
|
@dossier = current_user_dossier params[:id]
|
2015-09-23 19:20:03 +02:00
|
|
|
if checked_autorisation_donnees?
|
|
|
|
@dossier.update_attributes(update_params)
|
2015-09-28 18:55:16 +02:00
|
|
|
|
|
|
|
if @dossier.procedure.use_api_carto
|
|
|
|
redirect_to url_for(controller: :carte, action: :show, dossier_id: @dossier.id)
|
|
|
|
else
|
|
|
|
redirect_to url_for(controller: :description, action: :show, dossier_id: @dossier.id)
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
else
|
|
|
|
@etablissement = @dossier.etablissement
|
|
|
|
@entreprise = @dossier.entreprise.decorate
|
|
|
|
flash.now.alert = 'Les conditions sont obligatoires.'
|
|
|
|
render 'show'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-27 13:56:54 +01:00
|
|
|
def archive
|
|
|
|
@dossier = current_user.dossiers.find(params[:dossier_id])
|
|
|
|
@dossier.update_attributes({archived: true})
|
|
|
|
|
|
|
|
flash.notice = 'Dossier archivé'
|
|
|
|
redirect_to users_dossiers_path
|
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
flash.alert = 'Dossier inéxistant'
|
|
|
|
redirect_to users_dossiers_path
|
|
|
|
end
|
|
|
|
|
2015-11-30 14:48:37 +01:00
|
|
|
def a_traiter
|
2015-11-30 15:56:06 +01:00
|
|
|
@dossiers_a_traiter = current_user.dossiers.waiting_for_user 'DESC'
|
2015-11-30 14:48:37 +01:00
|
|
|
@dossiers = @dossiers_a_traiter
|
|
|
|
|
|
|
|
params[:page] = 1 if params[:page].nil?
|
|
|
|
|
2015-11-30 17:03:36 +01:00
|
|
|
@dossiers = @dossiers.paginate(:page => params[:page]).decorate
|
2015-11-30 14:48:37 +01:00
|
|
|
total_dossiers_per_state
|
|
|
|
end
|
|
|
|
|
|
|
|
def en_attente
|
2015-11-30 15:56:06 +01:00
|
|
|
@dossiers_en_attente = current_user.dossiers.waiting_for_gestionnaire 'DESC'
|
2015-11-30 14:48:37 +01:00
|
|
|
@dossiers = @dossiers_en_attente
|
|
|
|
|
|
|
|
params[:page] = 1 if params[:page].nil?
|
|
|
|
|
2015-11-30 17:03:36 +01:00
|
|
|
@dossiers = @dossiers.paginate(:page => params[:page]).decorate
|
2015-11-30 14:48:37 +01:00
|
|
|
total_dossiers_per_state
|
|
|
|
end
|
|
|
|
|
|
|
|
def termine
|
2015-11-30 15:56:06 +01:00
|
|
|
@dossiers_termine = current_user.dossiers.termine 'DESC'
|
2015-11-30 14:48:37 +01:00
|
|
|
@dossiers = @dossiers_termine
|
|
|
|
|
|
|
|
params[:page] = 1 if params[:page].nil?
|
|
|
|
|
2015-11-30 17:03:36 +01:00
|
|
|
@dossiers = @dossiers.paginate(:page => params[:page]).decorate
|
2015-11-30 14:48:37 +01:00
|
|
|
total_dossiers_per_state
|
|
|
|
end
|
|
|
|
|
2015-09-23 19:20:03 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def update_params
|
|
|
|
params.require(:dossier).permit(:autorisation_donnees)
|
|
|
|
end
|
|
|
|
|
|
|
|
def dossier_id_is_present?
|
|
|
|
@dossier_id != ''
|
|
|
|
end
|
|
|
|
|
|
|
|
def checked_autorisation_donnees?
|
|
|
|
update_params[:autorisation_donnees] == '1'
|
|
|
|
end
|
|
|
|
|
|
|
|
def siret
|
|
|
|
params[:siret]
|
|
|
|
end
|
|
|
|
|
|
|
|
def siren
|
|
|
|
siret[0..8]
|
|
|
|
end
|
2015-11-30 14:48:37 +01:00
|
|
|
|
|
|
|
def total_dossiers_per_state
|
2015-11-30 15:56:06 +01:00
|
|
|
@dossiers_a_traiter_total = !@dossiers_a_traiter.nil? ? @dossiers_a_traiter.size : current_user.dossiers.waiting_for_user.size
|
|
|
|
@dossiers_en_attente_total = !@dossiers_en_attente.nil? ? @dossiers_en_attente.size : current_user.dossiers.waiting_for_gestionnaire.size
|
|
|
|
@dossiers_termine_total = !@dossiers_termine.nil? ? @dossiers_termine.size : current_user.dossiers.termine.size
|
2015-11-30 14:48:37 +01:00
|
|
|
end
|
2015-09-23 12:04:57 +02:00
|
|
|
end
|