2016-09-27 17:26:49 +02:00
|
|
|
class Backoffice::DossiersController < Backoffice::DossiersListController
|
2016-11-07 17:23:58 +01:00
|
|
|
respond_to :html, :xlsx, :ods, :csv
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-12-02 18:03:52 +01:00
|
|
|
def index
|
2016-12-14 18:41:33 +01:00
|
|
|
procedure = current_gestionnaire.procedure_filter
|
|
|
|
|
|
|
|
if procedure.nil?
|
|
|
|
procedure_list = dossiers_list_facade.gestionnaire_procedures_name_and_id_list
|
|
|
|
if procedure_list.count == 0
|
|
|
|
flash.alert = "Vous n'avez aucune procédure d'affectée."
|
|
|
|
return redirect_to root_path
|
|
|
|
end
|
|
|
|
|
|
|
|
procedure = procedure_list.first[:id]
|
|
|
|
end
|
2016-12-05 16:17:24 +01:00
|
|
|
|
|
|
|
redirect_to backoffice_dossiers_procedure_path(id: procedure)
|
2015-11-13 15:23:21 +01:00
|
|
|
end
|
|
|
|
|
2015-12-02 18:03:52 +01:00
|
|
|
def show
|
2015-12-24 15:10:20 +01:00
|
|
|
create_dossier_facade params[:id]
|
2016-12-27 11:23:19 +01:00
|
|
|
|
2016-12-22 11:55:24 +01:00
|
|
|
unless @facade.nil?
|
|
|
|
@champs_private = @facade.champs_private
|
2016-12-22 11:39:44 +01:00
|
|
|
|
2016-12-22 11:55:24 +01:00
|
|
|
@headers_private = @champs_private.inject([]) do |acc, champ|
|
|
|
|
acc.push(champ) if champ.type_champ == 'header_section'
|
|
|
|
acc
|
|
|
|
end
|
2016-12-22 11:39:44 +01:00
|
|
|
end
|
2016-12-27 11:23:19 +01:00
|
|
|
|
|
|
|
Notification.where(dossier_id: params[:id].to_i).update_all already_read: true
|
2015-12-02 18:03:52 +01:00
|
|
|
end
|
|
|
|
|
2016-10-04 19:19:03 +02:00
|
|
|
def filter
|
|
|
|
super
|
|
|
|
|
|
|
|
redirect_to backoffice_dossiers_path(liste: param_liste)
|
|
|
|
end
|
|
|
|
|
2016-08-25 12:30:15 +02:00
|
|
|
def download_dossiers_tps
|
2016-11-09 09:19:57 +01:00
|
|
|
if procedure = Procedure.find_by(id: params[:procedure_id])
|
2016-11-15 17:06:40 +01:00
|
|
|
dossiers = dossiers_list_facade(param_liste).dossiers_to_display
|
2017-01-03 15:50:44 +01:00
|
|
|
respond_with Dossier.export_full_generation(dossiers, request.format) unless dossiers.empty?
|
2016-11-09 09:19:57 +01:00
|
|
|
else
|
2016-11-15 17:06:40 +01:00
|
|
|
dossiers = dossiers_list_facade(param_liste).dossiers_to_display
|
2016-11-09 09:19:57 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.xlsx { render xlsx: dossiers }
|
2016-12-14 18:41:33 +01:00
|
|
|
format.ods { render ods: dossiers }
|
|
|
|
format.csv { render csv: dossiers }
|
2016-11-09 09:19:57 +01:00
|
|
|
end
|
2016-11-07 17:23:58 +01:00
|
|
|
end
|
2016-08-25 12:30:15 +02:00
|
|
|
end
|
|
|
|
|
2015-11-17 18:21:03 +01:00
|
|
|
def search
|
2015-11-26 15:47:31 +01:00
|
|
|
@search_terms = params[:q]
|
2016-10-25 18:45:05 +02:00
|
|
|
|
2016-11-17 19:18:24 +01:00
|
|
|
# exact id match?
|
2016-12-05 16:57:40 +01:00
|
|
|
@dossiers = Dossier.where(id: @search_terms.to_i) if @search_terms.to_i < 2147483647
|
|
|
|
@dossiers = Dossier.none if @dossiers.nil?
|
2016-11-17 19:18:24 +01:00
|
|
|
|
|
|
|
# full text search
|
2016-11-29 09:56:11 +01:00
|
|
|
unless @dossiers.any?
|
|
|
|
@dossiers = Search.new(
|
2016-12-14 18:41:33 +01:00
|
|
|
gestionnaire: current_gestionnaire,
|
|
|
|
query: @search_terms,
|
|
|
|
page: params[:page]
|
2016-11-17 19:18:24 +01:00
|
|
|
).results
|
|
|
|
end
|
2015-11-26 15:47:31 +01:00
|
|
|
|
2016-11-29 09:56:11 +01:00
|
|
|
smart_listing_create :search,
|
|
|
|
@dossiers,
|
|
|
|
partial: "backoffice/dossiers/list",
|
|
|
|
array: true,
|
|
|
|
default_sort: dossiers_list_facade.service.default_sort
|
|
|
|
|
2015-11-17 18:21:03 +01:00
|
|
|
rescue RuntimeError
|
2016-11-29 09:56:11 +01:00
|
|
|
smart_listing_create :search,
|
|
|
|
[],
|
|
|
|
partial: "backoffice/dossiers/list",
|
|
|
|
array: true,
|
|
|
|
default_sort: dossiers_list_facade.service.default_sort
|
2015-11-17 18:21:03 +01:00
|
|
|
end
|
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
def valid
|
2015-12-24 15:10:20 +01:00
|
|
|
create_dossier_facade params[:dossier_id]
|
2015-09-24 16:51:14 +02:00
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
@facade.dossier.next_step! 'gestionnaire', 'valid'
|
2015-09-24 16:51:14 +02:00
|
|
|
flash.notice = 'Dossier confirmé avec succès.'
|
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
NotificationMailer.dossier_validated(@facade.dossier).deliver_now!
|
2015-12-15 15:37:46 +01:00
|
|
|
|
2016-11-22 16:30:35 +01:00
|
|
|
redirect_to backoffice_dossier_path(id: @facade.dossier.id)
|
2015-09-24 16:51:14 +02:00
|
|
|
end
|
2015-10-09 12:05:07 +02:00
|
|
|
|
2016-08-25 15:21:25 +02:00
|
|
|
def receive
|
|
|
|
create_dossier_facade params[:dossier_id]
|
|
|
|
|
|
|
|
@facade.dossier.next_step! 'gestionnaire', 'receive'
|
|
|
|
flash.notice = 'Dossier considéré comme reçu.'
|
|
|
|
|
2016-09-01 10:27:22 +02:00
|
|
|
NotificationMailer.dossier_received(@facade.dossier).deliver_now!
|
|
|
|
|
2016-12-19 17:11:26 +01:00
|
|
|
redirect_to backoffice_dossier_path(id: @facade.dossier.id)
|
2016-08-25 15:21:25 +02:00
|
|
|
end
|
|
|
|
|
2016-08-25 17:46:26 +02:00
|
|
|
def refuse
|
|
|
|
create_dossier_facade params[:dossier_id]
|
|
|
|
|
|
|
|
@facade.dossier.next_step! 'gestionnaire', 'refuse'
|
|
|
|
flash.notice = 'Dossier considéré comme refusé.'
|
|
|
|
|
2016-08-25 18:02:56 +02:00
|
|
|
NotificationMailer.dossier_refused(@facade.dossier).deliver_now!
|
|
|
|
|
2016-12-19 17:11:26 +01:00
|
|
|
redirect_to backoffice_dossier_path(id: @facade.dossier.id)
|
2016-08-25 17:46:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def without_continuation
|
|
|
|
create_dossier_facade params[:dossier_id]
|
|
|
|
|
|
|
|
@facade.dossier.next_step! 'gestionnaire', 'without_continuation'
|
|
|
|
flash.notice = 'Dossier considéré comme sans suite.'
|
|
|
|
|
2016-08-25 18:02:56 +02:00
|
|
|
NotificationMailer.dossier_without_continuation(@facade.dossier).deliver_now!
|
|
|
|
|
2016-12-19 17:11:26 +01:00
|
|
|
redirect_to backoffice_dossier_path(id: @facade.dossier.id)
|
2016-08-25 17:46:26 +02:00
|
|
|
end
|
|
|
|
|
2015-11-02 15:00:28 +01:00
|
|
|
def close
|
2015-12-24 15:10:20 +01:00
|
|
|
create_dossier_facade params[:dossier_id]
|
2015-10-09 12:05:07 +02:00
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
@facade.dossier.next_step! 'gestionnaire', 'close'
|
2015-10-09 12:05:07 +02:00
|
|
|
flash.notice = 'Dossier traité avec succès.'
|
|
|
|
|
2016-08-25 18:02:56 +02:00
|
|
|
NotificationMailer.dossier_closed(@facade.dossier).deliver_now!
|
|
|
|
|
2016-12-19 17:11:26 +01:00
|
|
|
redirect_to backoffice_dossier_path(id: @facade.dossier.id)
|
2015-10-09 12:05:07 +02:00
|
|
|
end
|
2015-11-02 16:36:52 +01:00
|
|
|
|
2016-07-18 18:24:29 +02:00
|
|
|
def follow
|
|
|
|
follow = current_gestionnaire.toggle_follow_dossier params[:dossier_id]
|
|
|
|
|
2016-09-09 15:55:03 +02:00
|
|
|
current_gestionnaire.dossiers.find(params[:dossier_id]).next_step! 'gestionnaire', 'follow'
|
|
|
|
|
2016-07-18 18:24:29 +02:00
|
|
|
flash.notice = (follow.class == Follow ? 'Dossier suivi' : 'Dossier relaché')
|
|
|
|
redirect_to request.referer
|
|
|
|
end
|
|
|
|
|
2016-08-01 18:10:32 +02:00
|
|
|
def reload_smartlisting
|
|
|
|
begin
|
|
|
|
@liste = URI(request.referer).query.split('=').second
|
|
|
|
rescue NoMethodError
|
2016-09-27 17:26:49 +02:00
|
|
|
@liste = cookies[:liste] || 'a_traiter'
|
2016-08-01 18:10:32 +02:00
|
|
|
end
|
2016-08-11 15:27:35 +02:00
|
|
|
|
2016-09-27 17:26:49 +02:00
|
|
|
smartlisting_dossier
|
2016-08-01 18:10:32 +02:00
|
|
|
|
|
|
|
render 'backoffice/dossiers/index', formats: :js
|
|
|
|
end
|
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
private
|
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
def create_dossier_facade dossier_id
|
|
|
|
@facade = DossierFacades.new dossier_id, current_gestionnaire.email
|
2015-11-02 16:36:52 +01:00
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
flash.alert = t('errors.messages.dossier_not_found')
|
|
|
|
redirect_to url_for(controller: '/backoffice')
|
|
|
|
end
|
2016-09-08 16:21:54 +02:00
|
|
|
|
|
|
|
def retrieve_procedure
|
|
|
|
return if params[:procedure_id].blank?
|
|
|
|
current_gestionnaire.procedures.find params[:procedure_id]
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|