2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-24 19:25:29 +01:00
|
|
|
module DossierHelper
|
2020-04-09 11:31:45 +02:00
|
|
|
include EtablissementHelper
|
|
|
|
|
2017-11-24 19:26:24 +01:00
|
|
|
def button_or_label_class(dossier)
|
2017-12-04 18:00:12 +01:00
|
|
|
if dossier.accepte?
|
2017-11-24 19:25:29 +01:00
|
|
|
'accepted'
|
2017-12-04 20:23:57 +01:00
|
|
|
elsif dossier.sans_suite?
|
2017-11-24 19:25:29 +01:00
|
|
|
'without-continuation'
|
2017-12-04 18:15:40 +01:00
|
|
|
elsif dossier.refuse?
|
2019-07-02 18:31:42 +02:00
|
|
|
'refused'
|
2017-11-24 19:25:29 +01:00
|
|
|
end
|
|
|
|
end
|
2017-12-05 16:07:05 +01:00
|
|
|
|
|
|
|
def highlight_if_unseen_class(seen_at, updated_at)
|
2020-02-26 22:17:55 +01:00
|
|
|
if updated_at.present? && seen_at&.<(updated_at)
|
2017-12-05 16:07:05 +01:00
|
|
|
"highlighted"
|
|
|
|
end
|
|
|
|
end
|
2018-06-25 18:07:16 +02:00
|
|
|
|
2018-06-28 17:19:22 +02:00
|
|
|
def url_for_dossier(dossier)
|
2018-07-04 09:59:35 +02:00
|
|
|
if dossier.brouillon?
|
2018-09-06 09:09:23 +02:00
|
|
|
brouillon_dossier_path(dossier)
|
2018-06-28 17:19:22 +02:00
|
|
|
else
|
2018-10-02 12:23:53 +02:00
|
|
|
dossier_path(dossier)
|
2018-06-28 17:19:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-24 11:57:05 +02:00
|
|
|
def url_for_new_dossier(revision)
|
|
|
|
new_dossier_url(procedure_id: revision.procedure.id, brouillon: revision.draft? ? true : nil)
|
2019-01-16 11:57:58 +01:00
|
|
|
end
|
|
|
|
|
2022-12-01 13:29:08 +01:00
|
|
|
def commencer_dossier_vide_for_revision_path(revision)
|
|
|
|
revision.draft? ? commencer_dossier_vide_test_path(path: revision.procedure.path) : commencer_dossier_vide_path(path: revision.procedure.path)
|
|
|
|
end
|
|
|
|
|
2018-06-25 18:07:16 +02:00
|
|
|
def dossier_submission_is_closed?(dossier)
|
2024-02-13 08:19:05 +01:00
|
|
|
return false if dossier.editing_fork?
|
2019-11-14 09:43:45 +01:00
|
|
|
dossier.brouillon? && dossier.procedure.close?
|
2018-06-25 18:07:16 +02:00
|
|
|
end
|
2018-11-06 18:44:32 +01:00
|
|
|
|
2019-12-19 13:22:40 +01:00
|
|
|
def dossier_display_state(dossier_or_state, lower: false)
|
|
|
|
state = dossier_or_state.is_a?(Dossier) ? dossier_or_state.state : dossier_or_state
|
2021-05-06 12:27:34 +02:00
|
|
|
display_state = Dossier.human_attribute_name("state.#{state}")
|
2019-12-19 13:22:40 +01:00
|
|
|
lower ? display_state.downcase : display_state
|
2018-11-06 18:44:32 +01:00
|
|
|
end
|
2018-11-07 14:46:22 +01:00
|
|
|
|
|
|
|
def dossier_legacy_state(dossier)
|
|
|
|
case dossier.state
|
|
|
|
when Dossier.states.fetch(:en_construction)
|
|
|
|
'initiated'
|
|
|
|
when Dossier.states.fetch(:en_instruction)
|
|
|
|
'received'
|
|
|
|
when Dossier.states.fetch(:accepte)
|
|
|
|
'closed'
|
|
|
|
when Dossier.states.fetch(:refuse)
|
|
|
|
'refused'
|
|
|
|
when Dossier.states.fetch(:sans_suite)
|
|
|
|
'without_continuation'
|
|
|
|
else
|
|
|
|
dossier.state
|
|
|
|
end
|
|
|
|
end
|
2020-01-27 14:28:23 +01:00
|
|
|
|
2023-02-27 11:38:04 +01:00
|
|
|
def class_badge_state(state)
|
|
|
|
case state
|
2023-06-08 10:43:24 +02:00
|
|
|
when Dossier.states.fetch(:en_construction)
|
|
|
|
'fr-badge--purple-glycine'
|
|
|
|
when Dossier.states.fetch(:en_instruction)
|
|
|
|
'fr-badge--new'
|
2023-02-27 11:38:04 +01:00
|
|
|
when Dossier.states.fetch(:accepte)
|
|
|
|
'fr-badge--success'
|
2023-06-08 10:43:24 +02:00
|
|
|
when Dossier.states.fetch(:refuse), Dossier.states.fetch(:sans_suite)
|
2023-02-27 11:38:04 +01:00
|
|
|
'fr-badge--warning'
|
|
|
|
when Dossier.states.fetch(:brouillon)
|
|
|
|
''
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-03-27 11:44:35 +01:00
|
|
|
def status_badge_user(dossier, alignment_class = '')
|
2024-04-03 11:07:40 +02:00
|
|
|
if dossier.hide_info_with_accuse_lecture?
|
2024-04-11 13:00:57 +02:00
|
|
|
tag.span 'traité', role: 'status', class: "fr-badge fr-badge--sm fr-badge--no-icon #{alignment_class}"
|
2024-03-27 11:44:35 +01:00
|
|
|
else
|
|
|
|
status_badge(dossier.state, alignment_class)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-13 15:41:18 +01:00
|
|
|
def status_badge(state, alignment_class = '')
|
2020-03-24 13:53:15 +01:00
|
|
|
status_text = dossier_display_state(state, lower: true)
|
2023-06-08 14:41:42 +02:00
|
|
|
tag.span status_text, role: 'status', class: class_names(
|
|
|
|
'fr-badge fr-badge--sm' => true,
|
2023-06-12 17:46:01 +02:00
|
|
|
'fr-badge--no-icon' => [Dossier.states.fetch(:en_instruction), Dossier.states.fetch(:accepte)].exclude?(state),
|
2023-06-08 14:41:42 +02:00
|
|
|
class_badge_state(state) => true,
|
|
|
|
alignment_class => true
|
|
|
|
)
|
2020-03-20 17:59:16 +01:00
|
|
|
end
|
|
|
|
|
2020-03-25 10:58:26 +01:00
|
|
|
def deletion_reason_badge(reason)
|
|
|
|
if reason.present?
|
2023-04-19 11:57:19 +02:00
|
|
|
status_text = I18n.t(reason, scope: 'activerecord.attributes.deleted_dossier.reason')
|
2020-03-25 10:58:26 +01:00
|
|
|
status_class = reason.tr('_', '-')
|
|
|
|
else
|
2023-04-19 11:57:19 +02:00
|
|
|
status_text = I18n.t('activerecord.attributes.deleted_dossier.reason.unknown')
|
2020-03-25 10:58:26 +01:00
|
|
|
status_class = 'unknown'
|
|
|
|
end
|
|
|
|
|
2024-07-24 14:39:55 +02:00
|
|
|
tag.span(status_text, class: "fr-badge #{status_class} ")
|
2020-03-25 10:58:26 +01:00
|
|
|
end
|
|
|
|
|
2023-03-23 12:47:45 +01:00
|
|
|
def pending_correction_badge(for_profile, html_class: nil)
|
|
|
|
tag.span(Dossier.human_attribute_name("pending_correction.#{for_profile}"), class: ['fr-badge fr-badge--sm fr-badge--warning super', html_class], role: 'status')
|
|
|
|
end
|
|
|
|
|
2024-01-24 17:01:59 +01:00
|
|
|
def correction_resolved_badge(html_class: nil)
|
|
|
|
tag.span(Dossier.human_attribute_name("pending_correction.resolved"), class: ['fr-badge fr-badge--sm fr-badge--success super', html_class], role: 'status')
|
2023-06-02 15:46:23 +02:00
|
|
|
end
|
|
|
|
|
2024-10-10 14:58:38 +02:00
|
|
|
def tags_label(tags)
|
|
|
|
if tags.count > 1
|
2024-10-16 11:39:19 +02:00
|
|
|
tag.ul(class: 'fr-tags-group') do
|
|
|
|
safe_join(tags.map { |t| tag.li(tag_label(t[1], t[2])) })
|
|
|
|
end
|
2024-10-10 14:58:38 +02:00
|
|
|
else
|
|
|
|
tag = tags.first
|
|
|
|
tag_label(tag[1], tag[2])
|
|
|
|
end
|
2024-10-07 16:52:27 +02:00
|
|
|
end
|
|
|
|
|
2024-10-10 14:58:38 +02:00
|
|
|
def tag_label(name, color)
|
2024-10-29 15:39:58 +01:00
|
|
|
tag.span(name, class: "fr-tag fr-tag--sm fr-tag--#{Label.class_name(color)}")
|
2024-10-07 16:52:27 +02:00
|
|
|
end
|
|
|
|
|
2020-04-09 11:31:45 +02:00
|
|
|
def demandeur_dossier(dossier)
|
2023-11-14 16:11:17 +01:00
|
|
|
if dossier.procedure.for_individual? && dossier.for_tiers?
|
|
|
|
return t('shared.dossiers.beneficiaire', mandataire: dossier.mandataire_full_name, beneficiaire: "#{dossier&.individual&.prenom} #{dossier&.individual&.nom}")
|
|
|
|
end
|
|
|
|
|
2020-04-09 11:31:45 +02:00
|
|
|
if dossier.procedure.for_individual?
|
2023-11-23 16:21:44 +01:00
|
|
|
return "#{dossier&.individual&.nom} #{dossier&.individual&.prenom}"
|
|
|
|
end
|
|
|
|
|
|
|
|
return "" if dossier.etablissement.blank?
|
|
|
|
|
|
|
|
if dossier.etablissement.diffusable_commercialement == false
|
|
|
|
"SIRET #{pretty_siret(dossier.etablissement.siret)}"
|
2020-04-09 11:31:45 +02:00
|
|
|
else
|
2023-11-23 16:21:44 +01:00
|
|
|
raison_sociale_or_name(dossier.etablissement)
|
2020-04-09 11:31:45 +02:00
|
|
|
end
|
|
|
|
end
|
2021-05-04 16:08:53 +02:00
|
|
|
|
2021-11-22 14:51:52 +01:00
|
|
|
def safe_expiration_date(dossier)
|
2022-04-08 13:16:08 +02:00
|
|
|
l(dossier.expiration_date, format: '%d/%m/%Y')
|
2021-11-22 14:51:52 +01:00
|
|
|
end
|
|
|
|
|
2022-09-16 00:13:17 +02:00
|
|
|
def annuaire_link(siren_or_siret = nil)
|
2021-05-04 16:08:53 +02:00
|
|
|
base_url = "https://annuaire-entreprises.data.gouv.fr"
|
2022-09-16 00:13:17 +02:00
|
|
|
return base_url if siren_or_siret.blank?
|
|
|
|
"#{base_url}/rechercher?terme=#{siren_or_siret}"
|
2021-05-04 16:08:53 +02:00
|
|
|
end
|
2021-06-16 11:46:25 +02:00
|
|
|
|
2022-09-14 16:19:14 +02:00
|
|
|
def france_connect_informations(user_information)
|
|
|
|
if user_information.full_name.empty?
|
|
|
|
t("shared.dossiers.france_connect_informations.details_no_name")
|
|
|
|
elsif user_information.updated_at.present?
|
|
|
|
t("shared.dossiers.france_connect_informations.details_updated",
|
|
|
|
name: user_information.full_name,
|
|
|
|
date: l(user_information.updated_at.to_date, format: :default))
|
|
|
|
else
|
|
|
|
t("shared.dossiers.france_connect_informations.details", name: user_information.full_name)
|
|
|
|
end
|
|
|
|
end
|
2017-11-24 19:25:29 +01:00
|
|
|
end
|