Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Ajout de l'information du ministère pour le template d'attestation PPE2 v2 #2279

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ export type Common = {

export type AttestationCRE4Options = Common & {
template: 'cre4.v0' | 'cre4.v1';
ministère?: undefined;
benjlevesque marked this conversation as resolved.
Show resolved Hide resolved
isFinancementParticipatif: boolean;
isInvestissementParticipatif: boolean;
};

export type AttestationPPE2Options = Common & {
template: 'ppe2.v1' | 'ppe2.v2';
type PPE2BaseOptions = Common & {
actionnariat?: 'financement-collectif' | 'gouvernance-partagée';
};
export type AttestationPPE2V1Options = PPE2BaseOptions & {
template: 'ppe2.v1';
ministère?: undefined;
};
export type AttestationPPE2V2Options = PPE2BaseOptions & {
template: 'ppe2.v2';
ministère: 'MEFSIN' | 'MCE';
};
export type AttestationPPE2Options = AttestationPPE2V1Options | AttestationPPE2V2Options;

export type AttestationCandidatureOptions = AttestationCRE4Options | AttestationPPE2Options;
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { makeCertificate } from './makeCertificate';

const meta = {
title: 'Attestations PDF',
component: ({ appelOffre, isClasse, période }) => {
component: ({ appelOffre, isClasse, periode }) => {
const data = {
...fakeProject(appelOffre, période),
...fakeProject(appelOffre, periode),
isClasse,
};
return makeCertificate({
Expand All @@ -24,14 +24,14 @@ const meta = {
control: 'select',
options: appelsOffreData.map((x) => x.id),
},
période: {
periode: {
control: 'select',
options: [...new Set(appelsOffreData.map((x) => x.periodes.map((p) => p.id)).flat())],
},
},
} satisfies Meta<{
appelOffre: string;
période: string;
periode: string;
isClasse: boolean;
}>;

Expand All @@ -42,8 +42,7 @@ type Story = StoryObj<typeof meta>;
const fakeProject = (appelOffreId: string, périodeId?: string): AttestationCandidatureOptions => {
const appelOffre = appelsOffreData.find((x) => x.id === appelOffreId)!;
const période = appelOffre.periodes.find((x) => x.id === périodeId) ?? appelOffre.periodes[0];
return {
template: période.certificateTemplate ?? 'cre4.v0',
const data = {
appelOffre,
période,
famille: période.familles[0],
Expand All @@ -65,6 +64,17 @@ const fakeProject = (appelOffreId: string, périodeId?: string): AttestationCand
puissance: 42,
potentielId: 'potentielId',
technologie: 'N/A',
} satisfies Partial<AttestationCandidatureOptions>;
if (!période.certificateTemplate || période.certificateTemplate === 'ppe2.v2') {
return {
template: 'ppe2.v2',
ministère: période.certificateTemplate === 'ppe2.v2' ? période.ministère : 'MCE',
...data,
};
}
return {
template: période.certificateTemplate,
...data,
};
};

Expand All @@ -77,6 +87,6 @@ export const Générique: Story = {
args: {
appelOffre: appelsOffreData[0].id,
isClasse: true,
période: '1',
periode: '1',
},
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { AppelOffre } from '@potentiel-domain/appel-offre';
import { Candidature } from '@potentiel-domain/candidature';

const defaultMinistère = 'MCE';
export const getFinancementEtTemplate = ({
période,
candidature,
}: {
période: AppelOffre.Periode;
candidature: Candidature.ConsulterCandidatureReadModel;
}) => {
const ppe2Actionnariat = candidature.actionnariat?.estÉgaleÀ(
Candidature.TypeActionnariat.financementCollectif,
)
? ('financement-collectif' as const)
: candidature.actionnariat?.estÉgaleÀ(Candidature.TypeActionnariat.gouvernancePartagée)
? ('gouvernance-partagée' as const)
: undefined;
switch (période.certificateTemplate) {
case 'cre4.v0':
case 'cre4.v1':
Expand All @@ -17,16 +25,17 @@ export const getFinancementEtTemplate = ({
isInvestissementParticipatif:
candidature.actionnariat?.type === 'investissement-participatif',
};

case 'ppe2.v1':
return {
template: période.certificateTemplate,
actionnariat: ppe2Actionnariat,
};
default:
return {
template: période.certificateTemplate ?? 'ppe2.v2',
actionnariat: candidature.actionnariat?.estÉgaleÀ(
Candidature.TypeActionnariat.financementCollectif,
)
? ('financement-collectif' as const)
: candidature.actionnariat?.estÉgaleÀ(Candidature.TypeActionnariat.gouvernancePartagée)
? ('gouvernance-partagée' as const)
: undefined,
ministère: période.certificateTemplate === 'ppe2.v2' ? période.ministère : defaultMinistère,
actionnariat: ppe2Actionnariat,
};
}
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Image, Text, View } from '@react-pdf/renderer';
import { Text, View } from '@react-pdf/renderer';
import React from 'react';

import { AttestationPPE2Options } from '../../AttestationCandidatureOptions';
import { formatDateForPdf } from '../../helpers/formatDateForPdf';

type HeaderProps = {
project: AttestationPPE2Options;
imagesRootPath: string;
logo: React.ReactNode;
};
export const Header = ({ project, imagesRootPath }: HeaderProps) => {
export const Header = ({ project, logo }: HeaderProps) => {
const { appelOffre, notifiedOn, nomRepresentantLegal, nomCandidat, email, potentielId } = project;
return (
<View style={{ paddingLeft: 15 }}>
Expand All @@ -20,10 +20,7 @@ export const Header = ({ project, imagesRootPath }: HeaderProps) => {
flexDirection: 'column',
}}
>
<Image
style={{ width: 151, height: 85, marginBottom: 40 }}
src={imagesRootPath + `/logo_MEFSIN.png`}
/>
{logo}

<View style={{ width: 165, paddingBottom: 10, fontStyle: 'italic' }}>
<Text>Direction de l’énergie</Text>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Image } from '@react-pdf/renderer';
import React from 'react';

export const LogoMCE = ({ imagesRootPath }: { imagesRootPath: string }) => (
<Image
style={{ maxWidth: 151, maxHeight: 85, marginTop: 15, marginBottom: 40 }}
src={imagesRootPath + `/logo_MCE.png`}
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Image } from '@react-pdf/renderer';
import React from 'react';

export const LogoMEFSIN = ({ imagesRootPath }: { imagesRootPath: string }) => (
<Image
style={{ width: 151, height: 85, marginBottom: 40 }}
src={imagesRootPath + `/logo_MEFSIN.png`}
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';

import { LogoMCE } from './MCE';
import { LogoMEFSIN } from './MEFSIN';

export const Logo = ({
imagesRootPath,
nom,
}: {
imagesRootPath: string;
nom: 'MCE' | 'MEFSIN';
}) => {
switch (nom) {
case 'MCE':
return <LogoMCE imagesRootPath={imagesRootPath} />;
case 'MEFSIN':
return <LogoMEFSIN imagesRootPath={imagesRootPath} />;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import React from 'react';
import { AppelOffre } from '@potentiel-domain/appel-offre';

import { Certificate } from '../components/Certificate';
import { AttestationPPE2Options } from '../../AttestationCandidatureOptions';
import { AttestationPPE2V2Options } from '../../AttestationCandidatureOptions';
import { Objet } from '../components/Objet';
import { Signature } from '../components/Signature';

import { Header } from './Header';
import { buildLauréat } from './Laureat';
import { buildElimine } from './Elimine';
import { Introduction } from './Introduction';
import { Logo } from './Logo/index';

const makeCertificate = (
project: AttestationPPE2Options,
project: AttestationPPE2V2Options,
validateur: AppelOffre.Validateur,
imagesRootPath: string,
): React.JSX.Element => {
Expand All @@ -23,7 +24,12 @@ const makeCertificate = (

return (
<Certificate
header={<Header project={project} imagesRootPath={imagesRootPath} />}
header={
<Header
project={project}
logo={<Logo nom={project.ministère} imagesRootPath={imagesRootPath} />}
/>
}
objet={<Objet text={objet} />}
introduction={<Introduction project={project} />}
content={content}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
} from '@potentiel-domain/inmemory-referential/src/appelOffre/PPE2';
import { AppelOffre } from '@potentiel-domain/appel-offre';

import { AttestationPPE2Options } from '../../AttestationCandidatureOptions';
import { AttestationPPE2V2Options } from '../../AttestationCandidatureOptions';

import { makeCertificate } from './makeCertificate';

const meta = {
title: 'Attestations PDF/PPE2/v2',
component: ({ projet }: { projet: AttestationPPE2Options }) => {
component: ({ projet }: { projet: AttestationPPE2V2Options }) => {
return makeCertificate(
projet,
{
Expand All @@ -29,11 +29,10 @@ export default meta;

type Story = StoryObj<typeof meta>;

const fakeProject: AttestationPPE2Options = {
const fakeProject = {
template: 'ppe2.v2',
appelOffre: {
...eolienPPE2,
} as AppelOffre.AppelOffreReadModel,
ministère: 'MCE',
appelOffre: eolienPPE2 as AppelOffre.AppelOffreReadModel,
période: eolienPPE2.periodes[0],
famille: eolienPPE2.periodes[0].familles[0],
isClasse: true,
Expand All @@ -52,7 +51,7 @@ const fakeProject: AttestationPPE2Options = {
puissance: 42,
potentielId: 'potentielId',
technologie: 'N/A',
};
} satisfies AttestationPPE2V2Options;

export const EliminePPE2AuDessusDePcible: Story = {
args: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import {
solPPE2,
} from '@potentiel-domain/inmemory-referential/src/appelOffre/PPE2';

import { AttestationPPE2Options } from '../../AttestationCandidatureOptions';
import { AttestationPPE2V2Options } from '../../AttestationCandidatureOptions';

import { makeCertificate } from './makeCertificate';

const meta = {
title: 'Attestations PDF/PPE2/v2',
component: ({ projet }: { projet: AttestationPPE2Options }) => {
component: ({ projet }: { projet: AttestationPPE2V2Options }) => {
return makeCertificate(
projet,
{
Expand All @@ -32,8 +32,9 @@ export default meta;

type Story = StoryObj<typeof meta>;

const fakeProject: Omit<AttestationPPE2Options, 'période' | 'appelOffre'> = {
const fakeProject = {
template: 'ppe2.v2',
ministère: 'MCE',
famille: undefined,
isClasse: true,
prixReference: 42,
Expand All @@ -51,7 +52,7 @@ const fakeProject: Omit<AttestationPPE2Options, 'période' | 'appelOffre'> = {
puissance: 42,
potentielId: 'potentielId',
technologie: 'pv',
};
} satisfies Omit<AttestationPPE2V2Options, 'période' | 'appelOffre'>;

export const LaureatPPE2AutoconsommationMétropoleFinancementCollectif: Story = {
args: {
Expand Down
20 changes: 15 additions & 5 deletions packages/domain/appel-offre/src/appelOffre.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ export type Validateur = {
fullName: string;
fonction?: string;
};

export type NotifiedPeriode = {
type?: 'notified';
certificateTemplate: CertificateTemplate;
validateurParDéfaut: Validateur;
} & (
| {
Expand All @@ -155,15 +155,15 @@ export type NotifiedPeriode = {
noteThresholdBy?: undefined;
noteThreshold: number;
}
);
) &
CertificateTemplateProps;

type NotYetNotifiedPeriode = {
type: 'not-yet-notified';
certificateTemplate: CertificateTemplate;
validateurParDéfaut: Validateur;
noteThresholdBy?: undefined;
noteThreshold?: undefined;
};
} & CertificateTemplateProps;

type LegacyPeriode = {
type: 'legacy';
Expand All @@ -172,7 +172,17 @@ type LegacyPeriode = {
noteThreshold?: undefined;
};

export type CertificateTemplate = 'cre4.v0' | 'cre4.v1' | 'ppe2.v1' | 'ppe2.v2';
type CertificateTemplateProps =
| {
certificateTemplate: 'cre4.v0' | 'cre4.v1' | 'ppe2.v1';
ministère?: undefined;
benjlevesque marked this conversation as resolved.
Show resolved Hide resolved
}
| {
certificateTemplate: 'ppe2.v2';
ministère: 'MEFSIN' | 'MCE';
};

export type CertificateTemplate = CertificateTemplateProps['certificateTemplate'];

export type Periode = {
id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ Des délais supplémentaires peuvent être accordés par le Préfet, à son appr
id: '3',
title: 'troisième',
certificateTemplate: 'ppe2.v2',
ministère: 'MEFSIN',
validateurParDéfaut: validateurParDéfaut.nicolas,
noteThreshold: 72.13,
cahierDesCharges: {
Expand All @@ -200,6 +201,7 @@ Des délais supplémentaires peuvent être accordés par le Préfet, à son appr
title: 'quatrième',
validateurParDéfaut: validateurParDéfaut.hermine,
certificateTemplate: 'ppe2.v2',
ministère: 'MEFSIN',
noteThreshold: 76.25,
cahierDesCharges: {
référence: '2023/S 176-551607',
Expand Down
Loading