2015-09-23 19:20:03 +02:00
|
|
|
class Users::DossiersController < UsersController
|
2016-01-08 11:39:04 +01:00
|
|
|
include SmartListing::Helper::ControllerExtensions
|
|
|
|
helper SmartListing::Helper
|
|
|
|
|
2016-06-29 17:35:34 +02:00
|
|
|
before_action :authenticate_user!, except: :commencer
|
2016-06-20 13:57:57 +02:00
|
|
|
before_action :check_siret, only: :siret_informations
|
2015-11-03 15:27:49 +01:00
|
|
|
|
2016-01-26 15:52:05 +01:00
|
|
|
before_action only: [:show] do
|
|
|
|
authorized_routes? self.class
|
|
|
|
end
|
2016-01-25 15:54:21 +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'
|
2016-01-08 11:39:04 +01:00
|
|
|
|
|
|
|
@dossiers = smart_listing_create :dossiers,
|
|
|
|
dossiers_to_display,
|
|
|
|
partial: "users/dossiers/list",
|
|
|
|
array: true
|
2015-12-02 16:52:09 +01:00
|
|
|
|
|
|
|
total_dossiers_per_state
|
2015-11-30 15:56:06 +01:00
|
|
|
end
|
|
|
|
|
2016-06-29 17:35:34 +02:00
|
|
|
def commencer
|
|
|
|
unless params[:procedure_path].nil?
|
2016-06-24 16:41:44 +02:00
|
|
|
procedure = ProcedurePath.where(path: params[:procedure_path]).first!.procedure
|
|
|
|
end
|
2015-12-03 12:00:22 +01:00
|
|
|
|
2016-06-29 17:35:34 +02:00
|
|
|
redirect_to new_users_dossier_path(procedure_id: procedure.id)
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
error_procedure
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
procedure = Procedure.where(archived: false, published: true).find(params[:procedure_id])
|
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
dossier = Dossier.create(procedure: procedure, user: current_user, state: 'draft')
|
|
|
|
siret = params[:siret] || current_user.siret
|
2015-12-03 12:00:22 +01:00
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
update_current_user_siret! siret unless siret.nil?
|
|
|
|
|
|
|
|
redirect_to users_dossier_path(id: dossier.id)
|
2015-12-03 12:00:22 +01:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
error_procedure
|
|
|
|
end
|
|
|
|
|
2015-11-26 12:29:34 +01:00
|
|
|
def show
|
2016-06-20 13:57:57 +02:00
|
|
|
@facade = facade
|
|
|
|
@siret = current_user.siret unless current_user.siret.nil?
|
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
|
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
def siret_informations
|
|
|
|
@facade = facade params[:dossier_id]
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
update_current_user_siret! siret
|
2015-12-11 12:36:44 +01:00
|
|
|
|
2016-07-22 11:34:34 +02:00
|
|
|
dossier = DossierService.new(@facade.dossier, siret, current_user.france_connect_information).dossier_informations!
|
|
|
|
|
2016-07-28 10:20:53 +02:00
|
|
|
if dossier.entreprise.nil? || dossier.etablissement.nil?
|
2016-07-22 11:34:34 +02:00
|
|
|
return errors_valid_siret
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
@facade = facade params[:dossier_id]
|
|
|
|
render '/dossiers/new_siret', formats: 'js'
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2016-07-22 11:34:34 +02:00
|
|
|
rescue RestClient::ResourceNotFound, RestClient::BadRequest
|
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')
|
2016-06-20 13:57:57 +02:00
|
|
|
redirect_to url_for users_dossiers_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def change_siret
|
|
|
|
Dossier.find(params[:dossier_id]).reset!
|
|
|
|
|
|
|
|
@facade = facade params[:dossier_id]
|
|
|
|
|
|
|
|
render '/dossiers/new_siret', formats: :js
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2016-06-20 13:57:57 +02:00
|
|
|
@facade = facade params[:dossier][:id]
|
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
|
2016-06-20 13:57:57 +02:00
|
|
|
flash.alert = 'Les conditions sont obligatoires.'
|
|
|
|
redirect_to users_dossier_path(id: @facade.dossier.id)
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-26 15:52:05 +01:00
|
|
|
def self.route_authorization
|
|
|
|
{
|
|
|
|
states: [:draft]
|
|
|
|
}
|
|
|
|
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,
|
2016-02-09 12:23:31 +01:00
|
|
|
'termine' => termine,
|
|
|
|
'invite' => invite}[@liste]
|
2015-12-24 15:10:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def waiting_for_user
|
2016-01-08 11:39:04 +01:00
|
|
|
@a_traiter_class = (@liste == 'a_traiter' ? 'active' : '')
|
2015-12-24 15:10:20 +01:00
|
|
|
@waiting_for_user ||= current_user.dossiers.waiting_for_user 'DESC'
|
|
|
|
end
|
|
|
|
|
|
|
|
def waiting_for_gestionnaire
|
2016-01-08 11:39:04 +01:00
|
|
|
@en_attente_class = (@liste == 'en_attente' ? 'active' : '')
|
2015-12-24 15:10:20 +01:00
|
|
|
@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
|
|
|
|
|
2016-02-09 12:23:31 +01:00
|
|
|
def invite
|
|
|
|
@invite_class = (@liste == 'invite' ? 'active' : '')
|
|
|
|
@invite ||= current_user.invites
|
|
|
|
end
|
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
def total_dossiers_per_state
|
2016-01-04 10:04:16 +01:00
|
|
|
@dossiers_a_traiter_total = waiting_for_user.count
|
|
|
|
@dossiers_en_attente_total = waiting_for_gestionnaire.count
|
2015-12-24 15:10:20 +01:00
|
|
|
@dossiers_termine_total = termine.count
|
2016-02-09 12:23:31 +01:00
|
|
|
@dossiers_invite_total = invite.count
|
2015-12-24 15:10:20 +01:00
|
|
|
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')
|
2016-06-20 13:57:57 +02:00
|
|
|
@facade = facade params[:dossier_id]
|
|
|
|
|
|
|
|
render '/dossiers/new_siret', formats: :js, locals: {invalid_siret: siret}
|
2015-12-03 15:02:22 +01:00
|
|
|
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
|
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
def create_params
|
2016-06-20 13:57:57 +02:00
|
|
|
params.require(:dossier).permit(:siret)
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def error_procedure
|
2015-12-24 15:22:30 +01:00
|
|
|
flash.alert = t('errors.messages.procedure_not_found')
|
2016-06-20 13:57:57 +02:00
|
|
|
|
2015-12-24 15:22:30 +01:00
|
|
|
redirect_to url_for users_dossiers_path
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
2016-01-19 17:19:38 +01:00
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
def update_current_user_siret! siret
|
|
|
|
current_user.update_attributes(siret: siret)
|
|
|
|
end
|
2016-01-19 17:19:38 +01:00
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
def facade id = params[:id]
|
|
|
|
DossierFacades.new id, current_user.email
|
2016-01-19 17:19:38 +01:00
|
|
|
end
|
2016-06-29 17:35:34 +02:00
|
|
|
|
2015-09-23 12:04:57 +02:00
|
|
|
end
|