feat(dossier/pdf): header sections numbering

This commit is contained in:
Colin Darie 2023-02-20 18:48:20 +01:00
parent 3de089d6c7
commit d7880f7e58
3 changed files with 60 additions and 1 deletions

View file

@ -1295,6 +1295,18 @@ class Dossier < ApplicationRecord
sections_for(champ)&.none?(&:libelle_with_section_index?)
end
def index_for_section_header(champ)
champs = champ.private? ? champs_private : champs_public
index = 1
champs.each do |c|
return index if c.stable_id == champ.stable_id
next unless c.visible?
index += 1 if c.type_de_champ.header_section?
end
end
private
def create_missing_traitemets

View file

@ -141,7 +141,13 @@ def add_single_champ(pdf, champ)
when 'Champs::PieceJustificativeChamp', 'Champs::TitreIdentiteChamp'
return
when 'Champs::HeaderSectionChamp'
add_section_title(pdf, tdc.libelle)
libelle = if @dossier.auto_numbering_section_headers_for?(champ)
"#{@dossier.index_for_section_header(champ)}. #{champ.libelle}"
else
champ.libelle
end
add_section_title(pdf, libelle)
when 'Champs::ExplicationChamp'
format_in_2_lines(pdf, tdc.libelle, strip_tags(tdc.description))
when 'Champs::CarteChamp'

View file

@ -2116,6 +2116,47 @@ describe Dossier do
end
end
describe '#index_for_section_header' do
include Logic
let(:number_stable_id) { 99 }
let(:types_de_champ) {
[
{ type: :header_section, libelle: "Infos" }, { type: :integer_number, stable_id: number_stable_id },
{ type: :header_section, libelle: "Details", condition: ds_eq(champ_value(99), constant(5)) }, { type: :header_section, libelle: "Conclusion" }
]
}
let(:procedure) { create(:procedure, :for_individual, types_de_champ_public: types_de_champ) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:headers) { dossier.champs_public.select { _1.header_section? } }
let(:number_value) { nil }
before do
dossier.champs_public.find { _1.stable_id == number_stable_id }.update(value: number_value)
dossier.reload
end
context "when there are invisible sections" do
it "index accordingly header sections" do
expect(dossier.index_for_section_header(headers[0])).to eq(1)
expect(headers[1]).not_to be_visible
expect(dossier.index_for_section_header(headers[2])).to eq(2)
end
end
context "when all headers are visible" do
let(:number_value) { 5 }
it "index accordingly header sections" do
expect(dossier.index_for_section_header(headers[0])).to eq(1)
expect(headers[1]).to be_visible
expect(dossier.index_for_section_header(headers[1])).to eq(2)
expect(dossier.index_for_section_header(headers[2])).to eq(3)
end
end
end
private
def count_for_month(processed_by_month, month)