-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dgbip and inpi bce finance data comparison
- Loading branch information
Showing
8 changed files
with
350 additions
and
330 deletions.
There are no files selected for viewing
206 changes: 206 additions & 0 deletions
206
app/(header-default)/donnees-financieres/[slug]/_components/finances-societe-content.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
'use client'; | ||
|
||
import { Info } from '#components-ui/alerts'; | ||
import FAQLink from '#components-ui/faq-link'; | ||
import { Tag } from '#components-ui/tag'; | ||
import { LineChart } from '#components/chart/line'; | ||
import { FullTable } from '#components/table/full'; | ||
import constants from '#models/constants'; | ||
import { IUniteLegale } from '#models/core/types'; | ||
import { ApplicationRights, hasRights } from '#models/user/rights'; | ||
import { ISession } from '#models/user/session'; | ||
import { | ||
formatCurrency, | ||
formatDate, | ||
formatDateYear, | ||
pluralize, | ||
} from '#utils/helpers'; | ||
|
||
const ColorCircle = ({ color }: { color: string }) => ( | ||
<span style={{ color }}>◆</span> | ||
); | ||
const colorResultat = constants.chartColors[1]; | ||
const colorCA = constants.chartColors[4]; | ||
|
||
export interface IFusionIndicateursFinanciers { | ||
year: number; | ||
confidentiality: 'Public' | string; | ||
dateClotureExercice: string; | ||
chiffreDAffaires?: number; | ||
chiffreDAffairesDgfip?: number; | ||
margeBrute?: number; | ||
excedentBrutDExploitation?: number; | ||
resultatNet?: number; | ||
} | ||
|
||
export function FinancesSocieteContent({ | ||
financesSociete, | ||
uniteLegale, | ||
session, | ||
}: { | ||
financesSociete: { | ||
bilans: IFusionIndicateursFinanciers[]; | ||
hasBilanConsolide?: boolean; | ||
lastModified: any; | ||
}; | ||
uniteLegale: IUniteLegale; | ||
session: ISession | null; | ||
}) { | ||
const bilans = financesSociete.bilans; | ||
|
||
if ( | ||
bilans.find((e) => e.confidentiality !== 'Public') && | ||
!hasRights(session, ApplicationRights.bilansRne) | ||
) { | ||
return ( | ||
<Info> | ||
Les bilans de cette structure sont accompagnés d’une déclaration de | ||
confidentialité. | ||
<br /> | ||
Seuls les <strong>agents publics</strong> peuvent les consulter sur ce | ||
site. | ||
</Info> | ||
); | ||
} | ||
const body = [ | ||
[ | ||
'Date de clôture', | ||
...bilans.map((a) => formatDate(a?.dateClotureExercice ?? '')), | ||
], | ||
[ | ||
<> | ||
<ColorCircle color={colorCA} /> Chiffre d’affaires | ||
</>, | ||
...bilans.map((a) => | ||
formatCA(a.chiffreDAffaires, a.chiffreDAffairesDgfip) | ||
), | ||
], | ||
['Marge brute', ...bilans.map((a) => formatCurrency(a?.margeBrute ?? ''))], | ||
[ | ||
'Excédent Brut d’Exploitation', | ||
...bilans.map((a) => formatCurrency(a?.excedentBrutDExploitation ?? '')), | ||
], | ||
[ | ||
<> | ||
<ColorCircle color={colorResultat} /> Résultat net | ||
</>, | ||
...bilans.map((a) => formatCurrency(a?.resultatNet ?? '')), | ||
], | ||
]; | ||
const plural = pluralize(bilans); | ||
|
||
return ( | ||
<> | ||
{financesSociete.hasBilanConsolide && ( | ||
<div> | ||
Cette entreprise déclare un <Tag color="info">bilan consolidé</Tag>. | ||
C’est le bilan d’un groupe de sociétés dont {uniteLegale.nomComplet}{' '} | ||
est la société mère. Son{' '} | ||
<FAQLink | ||
tooltipLabel="bilan consolidé" | ||
to="/faq/donnees-financieres#quest-ce-quun-bilan-consolide" | ||
> | ||
Qu’est-ce qu’un bilan consolidé ? | ||
</FAQLink>{' '} | ||
inclut ceux de ses filiales. | ||
</div> | ||
)} | ||
<p> | ||
Voici les résultats financiers | ||
{financesSociete.hasBilanConsolide ? ' consolidés' : ''} publiés par | ||
l’entreprise pour les {bilans.length} dernier | ||
{plural} exercice | ||
{plural} : | ||
</p> | ||
<LineChart | ||
htmlLegendId={'finance-data-legend'} | ||
options={{ | ||
plugins: { | ||
tooltip: { | ||
callbacks: { | ||
label(tooltipItem) { | ||
return formatCurrency(tooltipItem.parsed.y.toString()); | ||
}, | ||
}, | ||
}, | ||
legend: { display: false }, | ||
}, | ||
responsive: true, | ||
maintainAspectRatio: false, | ||
scales: { | ||
y: { | ||
border: { display: false }, | ||
ticks: { | ||
callback: (label) => { | ||
return formatCurrency(label.toString()); | ||
}, | ||
}, | ||
}, | ||
}, | ||
}} | ||
height={250} | ||
data={{ | ||
labels: bilans.map((bilan) => | ||
formatDateYear(bilan.dateClotureExercice) | ||
), | ||
datasets: [ | ||
{ | ||
label: "Chiffre d'affaires", | ||
tension: 0.3, | ||
data: bilans.map((bilan) => bilan.chiffreDAffaires ?? 0), | ||
borderColor: colorCA, | ||
backgroundColor: colorCA, | ||
}, | ||
{ | ||
label: 'Resultat net', | ||
tension: 0.3, | ||
data: bilans.map((bilan) => bilan.resultatNet ?? 0), | ||
borderColor: colorResultat, | ||
backgroundColor: colorResultat, | ||
}, | ||
], | ||
}} | ||
/> | ||
<br /> | ||
<FullTable | ||
head={[ | ||
<FAQLink tooltipLabel="Indicateurs" to="/faq/donnees-financieres"> | ||
Définition des indicateurs | ||
</FAQLink>, | ||
...bilans.map((a) => a?.year.toString()), | ||
]} | ||
body={body} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
function formatCA(ca: number | undefined, caDgfip: number | undefined) { | ||
if (!ca && !caDgfip) { | ||
return 'N/A'; | ||
} else if (ca === caDgfip || !caDgfip) { | ||
return <div>{formatCurrency(ca ?? '')}</div>; | ||
} else if (!ca) { | ||
return ( | ||
<> | ||
{formatCurrency(caDgfip ?? '')}{' '} | ||
<FAQLink tooltipLabel="(DGFiP)"> | ||
Cette donnée provient de la DGFiP, il n‘y avait pas de données | ||
publiques. | ||
</FAQLink> | ||
</> | ||
); | ||
} else { | ||
return ( | ||
<> | ||
<div>{formatCurrency(ca ?? '')} </div> | ||
<div> | ||
{formatCurrency(caDgfip ?? '')}{' '} | ||
<FAQLink tooltipLabel="(incohérence avec DGFiP)"> | ||
Cette donnée provient de la DGFiP. | ||
</FAQLink> | ||
</div> | ||
</> | ||
); | ||
} | ||
} |
137 changes: 0 additions & 137 deletions
137
app/(header-default)/donnees-financieres/[slug]/_components/finances-societe-protected.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.