This commit is contained in:
Paul Chavard 2021-11-17 12:53:43 +03:00
parent 2e4635c786
commit df474b60cf
3 changed files with 51 additions and 26 deletions

View file

@ -60,8 +60,11 @@ class Dossier < ApplicationRecord
REMAINING_DAYS_BEFORE_CLOSING = 2 REMAINING_DAYS_BEFORE_CLOSING = 2
INTERVAL_BEFORE_CLOSING = "#{REMAINING_DAYS_BEFORE_CLOSING} days" INTERVAL_BEFORE_CLOSING = "#{REMAINING_DAYS_BEFORE_CLOSING} days"
INTERVAL_BEFORE_EXPIRATION = '2 weeks' REMAINING_WEEKS_BEFORE_EXPIRATION = 2
INTERVAL_EXPIRATION = '1 month 5 days' INTERVAL_BEFORE_EXPIRATION = "#{REMAINING_WEEKS_BEFORE_EXPIRATION} weeks"
MONTHS_AFTER_EXPIRATION = 1
DAYS_AFTER_EXPIRATION = 5
INTERVAL_EXPIRATION = "#{MONTHS_AFTER_EXPIRATION} month #{DAYS_AFTER_EXPIRATION} days"
has_one :etablissement, dependent: :destroy has_one :etablissement, dependent: :destroy
has_one :individual, validate: false, dependent: :destroy has_one :individual, validate: false, dependent: :destroy
@ -304,7 +307,7 @@ class Dossier < ApplicationRecord
scope :termine_close_to_expiration, -> do scope :termine_close_to_expiration, -> do
state_termine state_termine
.joins(:procedure) .joins(:procedure)
.where(id: Traitement.termine_close_to_expiration.select(:dossier_id).distinct) .where("dossiers.processed_at + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
end end
scope :brouillon_expired, -> do scope :brouillon_expired, -> do
@ -522,16 +525,42 @@ class Dossier < ApplicationRecord
!brouillon? && !user_deleted? && !archived !brouillon? && !user_deleted? && !archived
end end
def en_construction_close_to_expiration? def close_to_expiration_at
self.class.en_construction_close_to_expiration.exists?(id: self) if brouillon?
created_at
elsif en_construction?
en_construction
elsif en_instruction?
en_instruction
else
processed_at
end + conservation_extension + duree_conservation_dossiers_dans_ds.months - REMAINING_WEEKS_BEFORE_EXPIRATION.weeks
end end
def brouillon_close_to_expiration? def duration_after_notice
self.class.brouillon_close_to_expiration.exists?(id: self) MONTHS_AFTER_EXPIRATION.month + DAYS_AFTER_EXPIRATION.days
end
def expiration_date
if brouillon? && brouillon_close_to_expiration_notice_sent_at.present?
brouillon_close_to_expiration_notice_sent_at + duration_after_notice
elsif en_construction? && en_construction_close_to_expiration_notice_sent_at.present?
en_construction_close_to_expiration_notice_sent_at + duration_after_notice
elsif termine? && termine_close_to_expiration_notice_sent_at.present?
termine_close_to_expiration_notice_sent_at + duration_after_notice
end
end end
def close_to_expiration? def close_to_expiration?
en_construction_close_to_expiration? || brouillon_close_to_expiration? !en_instruction? && close_to_expiration_at < Time.zone.now
end
def close_to_expiration_notice_sent?
expiration_date.present?
end
def expiration_can_be_extended?
brouillon? || en_construction?
end end
def show_groupe_instructeur_details? def show_groupe_instructeur_details?

View file

@ -17,14 +17,6 @@ class Traitement < ApplicationRecord
scope :en_instruction, -> { where(state: Dossier.states.fetch(:en_instruction)) } scope :en_instruction, -> { where(state: Dossier.states.fetch(:en_instruction)) }
scope :termine, -> { where(state: Dossier::TERMINE) } scope :termine, -> { where(state: Dossier::TERMINE) }
scope :termine_close_to_expiration, -> do
joins(dossier: :procedure)
.termine
.where(process_expired: true)
.where('dossiers.state' => Dossier::TERMINE)
.where("traitements.processed_at + (procedures.duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: Dossier::INTERVAL_BEFORE_EXPIRATION })
end
scope :for_traitement_time_stats, -> (procedure) do scope :for_traitement_time_stats, -> (procedure) do
includes(:dossier) includes(:dossier)
.termine .termine

View file

@ -25,18 +25,22 @@
- if dossier.close_to_expiration? - if dossier.close_to_expiration?
.card.warning .card.warning
.card-title Votre dossier va expirer .card-title Votre dossier va expirer
%p
- if dossier.brouillon? - if dossier.brouillon?
%p Votre dossier est en brouillon, mais va bientôt expirer. Cela signifie quil va bientôt être supprimé sans avoir été déposé.
Votre dossier est en brouillon, mais va bientôt expirer. Cela signifie quil va bientôt être supprimé sans avoir été déposé. Si vous souhaitez le conserver afin de poursuivre la démarche, vous pouvez le conserver
Si vous souhaitez le conserver afin de poursuivre la démarche, vous pouvez le conserver un mois de plus en cliquant sur le bouton ci-dessous.
un mois de plus en cliquant sur le bouton ci-dessous. - elsif dossier.termine?
Le traitement de votre dossier est terminé, mais il va bientôt expirer. Cela signifie quil va bientôt être supprimé.
Si vous souhaitez conserver une trace, vous pouvez le télécharger au format PDF.
- else - else
%p Votre dossier a été déposé, mais va bientôt expirer. Cela signifie quil va bientôt être supprimé sans avoir été traité par ladministration.
Votre dossier a été déposé, mais va bientôt expirer. Cela signifie quil va bientôt être supprimé sans avoir été traité par ladministration. Si vous souhaitez le conserver afin de poursuivre la démarche, vous pouvez le conserver
Si vous souhaitez le conserver afin de poursuivre la démarche, vous pouvez le conserver un mois de plus en cliquant sur le bouton ci-dessous.
un mois de plus en cliquant sur le bouton ci-dessous.
%br - if dossier.expiration_can_be_extended?
= button_to 'Repousser sa suppression', users_dossier_repousser_expiration_path(dossier), class: 'button secondary' %br
= button_to 'Repousser sa suppression', users_dossier_repousser_expiration_path(dossier), class: 'button secondary'
%ul.tabs %ul.tabs
= dynamic_tab_item(t('views.users.dossiers.show.header.summary'), dossier_path(dossier)) = dynamic_tab_item(t('views.users.dossiers.show.header.summary'), dossier_path(dossier))