2017-06-29 15:31:29 +02:00
|
|
|
|
module NewGestionnaire
|
|
|
|
|
class DossiersController < ProceduresController
|
2017-12-01 12:57:01 +01:00
|
|
|
|
include ActionView::Helpers::NumberHelper
|
2017-11-29 17:11:50 +01:00
|
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
|
|
2017-12-05 16:07:05 +01:00
|
|
|
|
after_action :mark_demande_as_read, only: :show
|
2017-12-05 17:20:10 +01:00
|
|
|
|
after_action :mark_messagerie_as_read, only: [:messagerie, :create_commentaire]
|
2017-12-07 11:15:51 +01:00
|
|
|
|
after_action :mark_avis_as_read, only: [:avis, :create_avis]
|
2017-12-07 14:37:34 +01:00
|
|
|
|
after_action :mark_annotations_privees_as_read, only: [:annotations_privees, :update_annotations]
|
2017-12-05 16:07:05 +01:00
|
|
|
|
|
2017-06-29 15:31:29 +02:00
|
|
|
|
def attestation
|
|
|
|
|
send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf')
|
|
|
|
|
end
|
|
|
|
|
|
2017-07-06 16:33:36 +02:00
|
|
|
|
def show
|
2017-12-05 16:07:05 +01:00
|
|
|
|
@demande_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.demande_seen_at
|
2017-07-06 16:33:36 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-19 11:08:53 +02:00
|
|
|
|
def messagerie
|
2017-10-30 17:21:05 +01:00
|
|
|
|
@commentaire = Commentaire.new
|
2017-12-05 17:20:10 +01:00
|
|
|
|
@messagerie_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.messagerie_seen_at
|
2017-07-19 11:08:53 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-09-27 12:08:47 +02:00
|
|
|
|
def annotations_privees
|
2017-12-07 14:37:34 +01:00
|
|
|
|
@annotations_privees_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.annotations_privees_seen_at
|
2017-07-19 16:53:31 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-09-26 14:38:16 +02:00
|
|
|
|
def avis
|
2017-12-07 11:15:51 +01:00
|
|
|
|
@avis_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.avis_seen_at
|
2018-02-27 16:58:22 +01:00
|
|
|
|
@avis = Avis.new
|
2017-09-26 14:38:16 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-12-01 15:03:19 +01:00
|
|
|
|
def personnes_impliquees
|
2018-08-29 22:11:38 +02:00
|
|
|
|
@following_instructeurs_emails = dossier.followers_gestionnaires.pluck(:email)
|
2017-12-01 15:03:19 +01:00
|
|
|
|
@avis_emails = dossier.avis.includes(:gestionnaire).map(&:email_to_display)
|
|
|
|
|
@invites_emails = dossier.invites.map(&:email)
|
2018-01-30 19:11:07 +01:00
|
|
|
|
@potential_recipients = procedure.gestionnaires.reject { |g| g == current_gestionnaire }
|
|
|
|
|
end
|
|
|
|
|
|
2018-09-10 17:52:49 +02:00
|
|
|
|
def send_to_instructeurs
|
|
|
|
|
recipients = Gestionnaire.find(params[:recipients])
|
|
|
|
|
|
|
|
|
|
recipients.each do |recipient|
|
|
|
|
|
GestionnaireMailer.send_dossier(current_gestionnaire, dossier, recipient).deliver_later
|
|
|
|
|
end
|
|
|
|
|
|
2018-01-30 19:11:07 +01:00
|
|
|
|
flash.notice = "Dossier envoyé"
|
2018-02-21 13:42:11 +01:00
|
|
|
|
redirect_to(personnes_impliquees_gestionnaire_dossier_path(procedure, dossier))
|
2017-12-01 15:03:19 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-11 15:45:20 +02:00
|
|
|
|
def follow
|
2017-07-17 12:11:33 +02:00
|
|
|
|
current_gestionnaire.follow(dossier)
|
2017-07-17 12:28:09 +02:00
|
|
|
|
flash.notice = 'Dossier suivi'
|
2018-02-21 15:56:41 +01:00
|
|
|
|
redirect_back(fallback_location: gestionnaire_procedures_url)
|
2017-07-11 15:45:20 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def unfollow
|
2017-10-05 14:10:49 +02:00
|
|
|
|
current_gestionnaire.unfollow(dossier)
|
2017-07-17 12:28:09 +02:00
|
|
|
|
flash.notice = "Vous ne suivez plus le dossier nº #{dossier.id}"
|
|
|
|
|
|
2018-02-21 15:56:41 +01:00
|
|
|
|
redirect_back(fallback_location: gestionnaire_procedures_url)
|
2017-07-11 15:45:20 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-11 15:56:23 +02:00
|
|
|
|
def archive
|
2018-03-02 16:27:03 +01:00
|
|
|
|
dossier.update(archived: true)
|
2017-09-25 18:13:10 +02:00
|
|
|
|
current_gestionnaire.unfollow(dossier)
|
2018-02-21 15:56:41 +01:00
|
|
|
|
redirect_back(fallback_location: gestionnaire_procedures_url)
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def unarchive
|
2018-03-02 16:27:03 +01:00
|
|
|
|
dossier.update(archived: false)
|
2018-02-21 15:56:41 +01:00
|
|
|
|
redirect_back(fallback_location: gestionnaire_procedures_url)
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-11-30 17:11:46 +01:00
|
|
|
|
def passer_en_instruction
|
2017-12-14 15:53:02 +01:00
|
|
|
|
dossier.en_instruction!
|
2017-11-30 17:11:46 +01:00
|
|
|
|
current_gestionnaire.follow(dossier)
|
|
|
|
|
flash.notice = 'Dossier passé en instruction.'
|
|
|
|
|
|
2018-09-13 17:13:09 +02:00
|
|
|
|
render partial: 'state_button_refresh', locals: { dossier: dossier }
|
2017-11-30 17:11:46 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-11-30 17:18:06 +01:00
|
|
|
|
def repasser_en_construction
|
2017-12-14 15:51:45 +01:00
|
|
|
|
dossier.en_construction!
|
2017-11-30 17:18:06 +01:00
|
|
|
|
flash.notice = 'Dossier repassé en construction.'
|
|
|
|
|
|
2018-09-13 17:13:09 +02:00
|
|
|
|
render partial: 'state_button_refresh', locals: { dossier: dossier }
|
2017-11-30 17:18:06 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-12-01 12:57:01 +01:00
|
|
|
|
def terminer
|
|
|
|
|
if params[:dossier] && params[:dossier][:motivation].present?
|
2017-12-21 17:21:31 +01:00
|
|
|
|
dossier.motivation = params[:dossier][:motivation]
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
case params[:process_action]
|
2017-11-30 17:29:26 +01:00
|
|
|
|
when "refuser"
|
2017-12-05 17:43:32 +01:00
|
|
|
|
dossier.refuse!
|
2018-05-25 23:08:47 +02:00
|
|
|
|
dossier.save
|
|
|
|
|
flash.notice = "Dossier considéré comme refusé."
|
2018-05-25 18:05:28 +02:00
|
|
|
|
NotificationMailer.send_refused_notification(dossier).deliver_later
|
2017-11-30 17:29:26 +01:00
|
|
|
|
when "classer_sans_suite"
|
2017-12-05 17:43:32 +01:00
|
|
|
|
dossier.sans_suite!
|
2018-05-25 23:08:47 +02:00
|
|
|
|
dossier.save
|
|
|
|
|
flash.notice = "Dossier considéré comme sans suite."
|
2018-05-25 18:05:28 +02:00
|
|
|
|
NotificationMailer.send_without_continuation_notification(dossier).deliver_later
|
2017-11-30 17:29:26 +01:00
|
|
|
|
when "accepter"
|
2017-12-05 17:43:32 +01:00
|
|
|
|
dossier.accepte!
|
2018-07-25 17:16:24 +02:00
|
|
|
|
if dossier.attestation.nil?
|
|
|
|
|
dossier.attestation = dossier.build_attestation
|
|
|
|
|
dossier.save
|
|
|
|
|
end
|
2018-05-25 23:08:47 +02:00
|
|
|
|
flash.notice = "Dossier traité avec succès."
|
2018-05-25 18:05:28 +02:00
|
|
|
|
NotificationMailer.send_closed_notification(dossier).deliver_later
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2018-09-13 17:13:09 +02:00
|
|
|
|
render partial: 'state_button_refresh', locals: { dossier: dossier }
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-19 14:04:49 +02:00
|
|
|
|
def create_commentaire
|
2018-09-04 18:19:29 +02:00
|
|
|
|
@commentaire = CommentaireService.create(current_gestionnaire, dossier, commentaire_params)
|
2017-10-30 17:21:05 +01:00
|
|
|
|
|
|
|
|
|
if @commentaire.save
|
|
|
|
|
current_gestionnaire.follow(dossier)
|
|
|
|
|
flash.notice = "Message envoyé"
|
2018-02-21 13:42:11 +01:00
|
|
|
|
redirect_to messagerie_gestionnaire_dossier_path(procedure, dossier)
|
2017-10-30 17:21:05 +01:00
|
|
|
|
else
|
|
|
|
|
flash.alert = @commentaire.errors.full_messages
|
|
|
|
|
render :messagerie
|
|
|
|
|
end
|
2017-07-19 14:04:49 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-08-28 14:16:13 +02:00
|
|
|
|
def create_avis
|
2018-02-27 16:58:22 +01:00
|
|
|
|
@avis = Avis.new(avis_params.merge(claimant: current_gestionnaire, dossier: dossier))
|
|
|
|
|
if @avis.save
|
|
|
|
|
flash.notice = "Une demande d'avis a été envoyée à #{@avis.email_to_display}"
|
|
|
|
|
redirect_to avis_gestionnaire_dossier_path(procedure, dossier)
|
|
|
|
|
else
|
|
|
|
|
flash.now.alert = @avis.errors.full_messages
|
|
|
|
|
@avis_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.avis_seen_at
|
|
|
|
|
render :avis
|
|
|
|
|
end
|
2017-08-28 14:16:13 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-08-02 15:33:23 +02:00
|
|
|
|
def update_annotations
|
|
|
|
|
dossier = current_gestionnaire.dossiers.includes(champs_private: :type_de_champ).find(params[:dossier_id])
|
2018-01-30 19:17:16 +01:00
|
|
|
|
# FIXME: add attachements validation, cf. Champ#piece_justificative_file_errors
|
2018-03-02 16:27:03 +01:00
|
|
|
|
dossier.update(champs_private_params)
|
2018-02-21 13:42:11 +01:00
|
|
|
|
redirect_to annotations_privees_gestionnaire_dossier_path(procedure, dossier)
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-10-05 23:27:02 +02:00
|
|
|
|
def print
|
|
|
|
|
@dossier = dossier
|
|
|
|
|
render layout: "print"
|
|
|
|
|
end
|
|
|
|
|
|
2017-06-29 15:31:29 +02:00
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def dossier
|
2017-10-30 17:21:05 +01:00
|
|
|
|
@dossier ||= current_gestionnaire.dossiers.find(params[:dossier_id])
|
2017-06-29 15:31:29 +02:00
|
|
|
|
end
|
2017-07-19 14:04:49 +02:00
|
|
|
|
|
|
|
|
|
def commentaire_params
|
2017-10-30 16:16:20 +01:00
|
|
|
|
params.require(:commentaire).permit(:body, :file)
|
2017-07-19 14:04:49 +02:00
|
|
|
|
end
|
2017-08-28 14:16:13 +02:00
|
|
|
|
|
|
|
|
|
def avis_params
|
2017-09-20 10:42:16 +02:00
|
|
|
|
params.require(:avis).permit(:email, :introduction, :confidentiel)
|
2017-08-28 14:16:13 +02:00
|
|
|
|
end
|
2017-08-02 15:33:23 +02:00
|
|
|
|
|
|
|
|
|
def champs_private_params
|
2018-04-03 17:53:14 +02:00
|
|
|
|
params.require(:dossier).permit(champs_private_attributes: [
|
2018-07-12 10:37:27 +02:00
|
|
|
|
:id, :primary_value, :secondary_value, :piece_justificative_file, :value, value: [],
|
2018-04-03 17:53:14 +02:00
|
|
|
|
etablissement_attributes: Champs::SiretChamp::ETABLISSEMENT_ATTRIBUTES
|
|
|
|
|
])
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2017-12-05 16:07:05 +01:00
|
|
|
|
def mark_demande_as_read
|
|
|
|
|
current_gestionnaire.mark_tab_as_seen(dossier, :demande)
|
|
|
|
|
end
|
2017-12-05 17:20:10 +01:00
|
|
|
|
|
|
|
|
|
def mark_messagerie_as_read
|
|
|
|
|
current_gestionnaire.mark_tab_as_seen(dossier, :messagerie)
|
|
|
|
|
end
|
2017-12-07 11:15:51 +01:00
|
|
|
|
|
|
|
|
|
def mark_avis_as_read
|
|
|
|
|
current_gestionnaire.mark_tab_as_seen(dossier, :avis)
|
|
|
|
|
end
|
2017-12-07 14:37:34 +01:00
|
|
|
|
|
|
|
|
|
def mark_annotations_privees_as_read
|
|
|
|
|
current_gestionnaire.mark_tab_as_seen(dossier, :annotations_privees)
|
|
|
|
|
end
|
2017-06-29 15:31:29 +02:00
|
|
|
|
end
|
|
|
|
|
end
|