2016-09-27 17:26:49 +02:00
|
|
|
class Backoffice::DossiersController < Backoffice::DossiersListController
|
2017-06-09 22:29:48 +02:00
|
|
|
include ActionView::Helpers::NumberHelper
|
|
|
|
|
2016-11-07 17:23:58 +01:00
|
|
|
respond_to :html, :xlsx, :ods, :csv
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2017-06-12 10:06:41 +02:00
|
|
|
prepend_before_action :store_current_location, only: :show
|
2017-05-02 15:58:21 +02:00
|
|
|
before_action :ensure_gestionnaire_is_authorized, only: :show
|
|
|
|
|
2015-12-02 18:03:52 +01:00
|
|
|
def index
|
2017-04-27 12:17:50 +02:00
|
|
|
return redirect_to backoffice_invitations_path if current_gestionnaire.avis.any?
|
|
|
|
|
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
|
2017-04-27 12:17:50 +02:00
|
|
|
|
2016-12-14 18:41:33 +01:00
|
|
|
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
|
2017-05-24 17:51:43 +02:00
|
|
|
dossier_id = params[:id]
|
|
|
|
create_dossier_facade dossier_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
|
|
|
|
2017-05-17 11:18:01 +02:00
|
|
|
@headers_private = @champs_private.select { |champ| champ.type_champ == 'header_section' }
|
2016-12-22 11:39:44 +01:00
|
|
|
end
|
2016-12-27 11:23:19 +01:00
|
|
|
|
2017-05-24 17:55:00 +02:00
|
|
|
# if the current_gestionnaire does not own the dossier, it is here to give an advice
|
|
|
|
# and it should not remove the notifications
|
|
|
|
if current_gestionnaire.dossiers.find_by(id: dossier_id).present?
|
|
|
|
Notification.where(dossier_id: dossier_id).update_all(already_read: true)
|
|
|
|
end
|
2017-04-25 17:02:54 +02:00
|
|
|
|
|
|
|
@new_avis = Avis.new(introduction: "Bonjour, merci de me donner votre avis sur ce dossier.")
|
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
|
2017-03-29 14:09:50 +02:00
|
|
|
procedure = Procedure.find_by(id: params[:procedure_id])
|
2017-04-05 11:34:16 +02:00
|
|
|
export = procedure.generate_export
|
2017-03-29 14:09:50 +02:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.csv { send_data(SpreadsheetArchitect.to_csv(data: export[:data], headers: export[:headers]), filename: 'dossiers.csv') }
|
|
|
|
format.xlsx { send_data(SpreadsheetArchitect.to_xlsx(data: export[:data], headers: export[:headers]), filename: 'dossiers.xlsx') }
|
|
|
|
format.ods { send_data(SpreadsheetArchitect.to_ods(data: export[:data], headers: export[:headers]), filename: 'dossiers.ods') }
|
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?
|
2017-02-20 18:07:33 +01:00
|
|
|
if @search_terms.to_i != 0
|
|
|
|
@dossiers = current_gestionnaire.dossiers.where(id: @search_terms.to_i)
|
|
|
|
end
|
|
|
|
|
2016-12-05 16:57:40 +01:00
|
|
|
@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,
|
2017-06-12 13:49:51 +02:00
|
|
|
@dossiers,
|
|
|
|
partial: "backoffice/dossiers/list",
|
|
|
|
array: true,
|
|
|
|
default_sort: dossiers_list_facade.service.default_sort
|
2016-11-29 09:56:11 +01:00
|
|
|
|
2015-11-17 18:21:03 +01:00
|
|
|
rescue RuntimeError
|
2016-11-29 09:56:11 +01:00
|
|
|
smart_listing_create :search,
|
2017-06-12 13:49:51 +02:00
|
|
|
[],
|
|
|
|
partial: "backoffice/dossiers/list",
|
|
|
|
array: true,
|
|
|
|
default_sort: dossiers_list_facade.service.default_sort
|
2015-11-17 18:21:03 +01:00
|
|
|
end
|
|
|
|
|
2016-08-25 15:21:25 +02:00
|
|
|
def receive
|
|
|
|
create_dossier_facade params[:dossier_id]
|
|
|
|
|
2017-03-05 22:14:21 +01:00
|
|
|
dossier = @facade.dossier
|
|
|
|
|
|
|
|
dossier.received!
|
2016-08-25 15:21:25 +02:00
|
|
|
flash.notice = 'Dossier considéré comme reçu.'
|
|
|
|
|
2017-03-06 15:43:38 +01:00
|
|
|
redirect_to backoffice_dossier_path(id: dossier.id)
|
2016-08-25 15:21:25 +02:00
|
|
|
end
|
|
|
|
|
2017-06-01 21:23:47 +02:00
|
|
|
def process_dossier
|
2016-08-25 17:46:26 +02:00
|
|
|
create_dossier_facade params[:dossier_id]
|
|
|
|
|
2017-06-13 11:50:06 +02:00
|
|
|
if params[:dossier] && params[:dossier][:motivation].present?
|
|
|
|
motivation = params[:dossier][:motivation]
|
|
|
|
end
|
|
|
|
|
2017-03-06 15:43:38 +01:00
|
|
|
dossier = @facade.dossier
|
|
|
|
|
2017-06-07 11:42:14 +02:00
|
|
|
case params[:process_action]
|
|
|
|
when "refuse"
|
|
|
|
next_step = "refuse"
|
|
|
|
notice = "Dossier considéré comme refusé."
|
|
|
|
template = dossier.procedure.refused_mail_template
|
|
|
|
when "without_continuation"
|
|
|
|
next_step = "without_continuation"
|
|
|
|
notice = "Dossier considéré comme sans suite."
|
|
|
|
template = dossier.procedure.without_continuation_mail_template
|
|
|
|
when "close"
|
|
|
|
next_step = "close"
|
|
|
|
notice = "Dossier traité avec succès."
|
|
|
|
template = dossier.procedure.closed_mail_template
|
2017-06-13 11:50:06 +02:00
|
|
|
end
|
|
|
|
|
2017-06-07 11:42:14 +02:00
|
|
|
dossier.next_step! 'gestionnaire', next_step, motivation
|
2017-06-16 14:10:08 +02:00
|
|
|
|
|
|
|
attestation_pdf = nil
|
|
|
|
if check_attestation_emailable(dossier)
|
|
|
|
attestation_pdf = dossier.attestation.pdf.read
|
|
|
|
end
|
|
|
|
|
2017-06-07 11:42:14 +02:00
|
|
|
flash.notice = notice
|
2015-10-09 12:05:07 +02:00
|
|
|
|
2017-06-09 22:29:48 +02:00
|
|
|
NotificationMailer.send_notification(dossier, template, attestation_pdf).deliver_now!
|
2016-08-25 18:02:56 +02:00
|
|
|
|
2017-03-06 15:43:38 +01:00
|
|
|
redirect_to backoffice_dossier_path(id: 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
|
2017-01-05 19:07:01 +01:00
|
|
|
@liste = cookies[:liste] || 'all_state'
|
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
|
|
|
|
|
2017-02-08 17:35:28 +01:00
|
|
|
def archive
|
2017-02-28 14:33:05 +01:00
|
|
|
facade = create_dossier_facade params[:id]
|
2017-02-08 17:35:28 +01:00
|
|
|
unless facade.dossier.archived
|
|
|
|
facade.dossier.update(archived: true)
|
|
|
|
flash.notice = 'Dossier archivé'
|
|
|
|
end
|
|
|
|
redirect_to backoffice_dossiers_path
|
|
|
|
end
|
|
|
|
|
2017-02-28 14:33:05 +01:00
|
|
|
def unarchive
|
|
|
|
@dossier = Dossier.find(params[:id])
|
|
|
|
if @dossier.archived
|
|
|
|
@dossier.update(archived: false)
|
|
|
|
flash.notice = 'Dossier désarchivé'
|
|
|
|
end
|
|
|
|
redirect_to backoffice_dossier_path(@dossier)
|
|
|
|
end
|
2017-03-06 15:59:52 +01:00
|
|
|
|
2017-02-28 15:14:27 +01:00
|
|
|
def reopen
|
|
|
|
create_dossier_facade params[:dossier_id]
|
|
|
|
|
2017-03-06 15:59:52 +01:00
|
|
|
@facade.dossier.replied!
|
2017-02-28 15:14:27 +01:00
|
|
|
flash.notice = 'Dossier réouvert.'
|
|
|
|
|
|
|
|
redirect_to backoffice_dossiers_path
|
|
|
|
end
|
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
private
|
|
|
|
|
2017-06-09 22:29:48 +02:00
|
|
|
def check_attestation_emailable(dossier)
|
|
|
|
if dossier&.attestation&.emailable? == false
|
|
|
|
human_size = number_to_human_size(dossier.attestation.pdf.size)
|
|
|
|
msg = "the attestation of the dossier #{dossier.id} cannot be mailed because it is too heavy: #{human_size}"
|
|
|
|
capture_message(msg, level: 'error')
|
|
|
|
end
|
|
|
|
|
|
|
|
dossier&.attestation&.emailable?
|
|
|
|
end
|
|
|
|
|
2017-06-12 10:06:41 +02:00
|
|
|
def store_current_location
|
|
|
|
if !gestionnaire_signed_in?
|
|
|
|
store_location_for(:gestionnaire, request.url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-02 15:58:21 +02:00
|
|
|
def ensure_gestionnaire_is_authorized
|
2017-05-16 15:20:38 +02:00
|
|
|
unless current_gestionnaire.can_view_dossier?(params[:id])
|
|
|
|
flash.alert = t('errors.messages.dossier_not_found')
|
|
|
|
redirect_to url_for(controller: '/backoffice')
|
|
|
|
end
|
2017-05-02 15:58:21 +02:00
|
|
|
end
|
|
|
|
|
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
|