Skip to content

Commit

Permalink
fix: declaration and repeq receipt pdf formatting (#2109)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturlg authored Feb 7, 2024
1 parent 87982e4 commit bd03376
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ const styles = StyleSheet.create({
},
sectionRowKey: {
fontWeight: "bold",
maxWidth: "70%",
maxWidth: "50%",
lineHeight: 1.25,
},
sectionRowValue: {
textAlign: "right",
maxWidth: "70%",
maxWidth: "50%",
},
});

Expand Down Expand Up @@ -157,7 +157,9 @@ export const BaseReceiptTemplate = ({
<>
<View key={`section-${sectionIdx}-row-${rowIdx}`} style={styles.sectionRow}>
<Text style={styles.sectionRowKey}>{row.key}</Text>
<Text style={styles.sectionRowValue}>{row.value ?? "-"}</Text>
<Text wrap hyphenationCallback={string => [string]} style={styles.sectionRowValue}>
{row.value ?? "-"}
</Text>
</View>
</>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import { isEqual } from "date-fns";

import { BaseReceiptTemplate, type BaseReceiptTemplateProps } from "./BaseReceiptTemplate";

const insertSoftHyphens = (url: string, everyNChars: number) => {
const parts = [];
for (let i = 0; i < url.length; i += everyNChars) {
parts.push(url.substring(i, i + everyNChars));
}
return parts.join(" ");
};

export const DeclarationReceipt = (input: DeclarationOpmc) => {
const declaration = input.declaration;

Expand Down Expand Up @@ -172,6 +180,10 @@ export const DeclarationReceipt = (input: DeclarationOpmc) => {
key: "Nombre de points obtenus sur le résultat final en nombre de salariés",
value: declaration.salaryRaisesAndPromotions?.score?.getValue(),
},
{
key: "Nombre de points obtenus à l'indicateur",
value: declaration.salaryRaisesAndPromotions?.score?.getValue(),
},
],
});
} else {
Expand Down Expand Up @@ -313,7 +325,7 @@ export const DeclarationReceipt = (input: DeclarationOpmc) => {
? [
{
key: "Site Internet de publication",
value: declaration.publication.url,
value: insertSoftHyphens(declaration.publication.url, 50),
},
]
: []),
Expand Down Expand Up @@ -409,15 +421,28 @@ export const DeclarationReceipt = (input: DeclarationOpmc) => {
value: input.measuresPublishDate ? formatDateToFr(input.measuresPublishDate) : "À définir",
});

if (declaration.publication?.url || declaration.index.getValue() < 75) {
if (!declaration.publication?.url && declaration.year.getValue() > 2020) {
rows.push({
key: "Modalités de communication des mesures de correction auprès des salariés",
key: "Modalités de communication auprès des salariés",
value: input.objectivesMeasuresModalities?.getValue() ?? "À définir",
showAsBlock: true,
});
}
}

if (
!declaration.publication?.url &&
declaration.year.getValue() > 2020 &&
declaration.index.getValue() >= 75 &&
declaration.index.getValue() <= 84
) {
rows.push({
key: "Modalités de communication auprès des salariés",
value: input.objectivesMeasuresModalities?.getValue() ?? "À définir",
showAsBlock: true,
});
}

table.push({
title:
declaration.index.getValue() >= 75 && declaration.index.getValue() <= 84
Expand All @@ -430,7 +455,7 @@ export const DeclarationReceipt = (input: DeclarationOpmc) => {
return (
<BaseReceiptTemplate
title="Déclaration"
subject="Récapitulatif de la déclaration de votre index de l'égalité professionnelle entre les femmes et les hommes"
subject="Récapitulatif de la déclaration de l'index de l'égalité professionnelle femmes-hommes"
declaredAt={declaration.declaredAt}
modifiedAt={isEqual(declaration.declaredAt, declaration.modifiedAt) ? undefined : declaration.modifiedAt}
siren={declaration.siren.getValue()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import { isEqual } from "date-fns";

import { BaseReceiptTemplate, type BaseReceiptTemplateProps } from "./BaseReceiptTemplate";

const insertSoftHyphens = (url: string, everyNChars: number) => {
const parts = [];
for (let i = 0; i < url.length; i += everyNChars) {
parts.push(url.substring(i, i + everyNChars));
}
return parts.join(" ");
};

export interface RepresentationEquilibreeReceiptProps {
repEq: RepresentationEquilibree;
}
Expand Down Expand Up @@ -105,7 +113,7 @@ export const RepresentationEquilibreeReceipt = ({ repEq }: RepresentationEquilib

if (repEq.publication) {
table.push({
title: "Publication",
title: "Publication des écarts de représentation",
rows: [
{
key: "Date de publication",
Expand All @@ -114,7 +122,7 @@ export const RepresentationEquilibreeReceipt = ({ repEq }: RepresentationEquilib
repEq.publication.url
? {
key: "Site Internet de publication",
value: repEq.publication.url,
value: insertSoftHyphens(repEq.publication.url, 50),
}
: {
key: "Modalités de communication auprès des salariés",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const RecapPage = async ({ params: { siren, year: strYear } }: NextServerPagePro
<DownloadCard
title="Télécharger le récapitulatif"
endDetail="PDF"
href={`/api/declaration/${siren}/${year}/pdf`}
href={`/index-egapro/declaration/${siren}/${year}/pdf`}
filename={`declaration_egapro_${siren}_${year + 1}.pdf`}
fileType="application/pdf"
desc={`Année ${year + 1} au titre des données ${year}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const ConfirmationPage = () => {

if (formData.commencer?.annéeIndicateurs === undefined || formData.commencer?.siren === undefined) return null;

const année = Number(formData.commencer.annéeIndicateurs);
const year = Number(formData.commencer.annéeIndicateurs);
const siren = formData.commencer.siren;
const index = formData["resultat-global"]?.index;

Expand All @@ -63,13 +63,13 @@ const ConfirmationPage = () => {
};

const sendReceipt = () => {
if (!siren || !année) {
if (!siren || !year) {
return;
}

setReceiptProcessing(true);

sendDeclarationReceipt(siren, année)
sendDeclarationReceipt(siren, year)
.catch(error => {
console.error(error);
setError("Une erreur est survenue, veuillez réessayer ultérieurement.");
Expand Down Expand Up @@ -135,10 +135,10 @@ const ConfirmationPage = () => {
<DownloadCard
title="Télécharger le récapitulatif"
endDetail="PDF"
href={`/api/declaration/${siren}/${année}/pdf`}
filename={`declaration_egapro_${siren}_${Number(année) + 1}.pdf`}
href={`/index-egapro/declaration/${siren}/${year}/pdf`}
filename={`declaration_egapro_${siren}_${Number(year) + 1}.pdf`}
fileType="application/pdf"
desc={`Année ${année + 1} au titre des données ${année}`}
desc={`Année ${year + 1} au titre des données ${year}`}
/>
</GridCol>
</Grid>
Expand All @@ -153,7 +153,7 @@ const ConfirmationPage = () => {
footer={
<ul className="fr-btns-group fr-btns-group--inline-reverse fr-btns-group--inline-lg">
<li>
<ButtonOpMc index={index} siren={siren} year={année} />
<ButtonOpMc index={index} siren={siren} year={year} />
</li>
</ul>
}
Expand Down Expand Up @@ -189,7 +189,7 @@ const ConfirmationPage = () => {
footer={
<ul className="fr-btns-group fr-btns-group--inline-reverse fr-btns-group--inline-lg">
<li>
<ButtonOpMc index={index} siren={siren} year={année} />
<ButtonOpMc index={index} siren={siren} year={year} />
</li>
</ul>
}
Expand Down

0 comments on commit bd03376

Please sign in to comment.