Skip to content

Commit

Permalink
feat(dgfip liasses fiscales): add dgfip liasses fiscales data
Browse files Browse the repository at this point in the history
  • Loading branch information
rmonnier9 committed Dec 30, 2024
1 parent 18f919f commit f20ebea
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 13 deletions.
5 changes: 5 additions & 0 deletions app/(header-default)/donnees-financieres/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HorizontalSeparator } from '#components-ui/horizontal-separator';
import { FinancesAssociationSection } from '#components/finances-section/association';
import { FinancesSocieteSection } from '#components/finances-section/societe';
import { FinancesSocieteLiassesFiscalesSection } from '#components/finances-section/societe-liasses-fiscales';
import { SubventionsAssociationSection } from '#components/subventions-association-section';
import Title from '#components/title-section';
import { FICHE } from '#components/title-section/tabs';
Expand Down Expand Up @@ -45,6 +46,10 @@ const FinancePage = async (props: AppRouterProps) => {
uniteLegale={uniteLegale}
session={session}
/>
<FinancesSocieteLiassesFiscalesSection
uniteLegale={uniteLegale}
session={session}
/>
{isAssociation(uniteLegale) ? (
<>
<FinancesAssociationSection
Expand Down
3 changes: 3 additions & 0 deletions app/api/data-fetching/routes-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getQualibat } from '#models/espace-agent/certificats/qualibat';
import { getQualifelec } from '#models/espace-agent/certificats/qualifelec';
import { getChiffreAffairesProtected } from '#models/espace-agent/chiffre-affaires';
import { getConformiteEntreprise } from '#models/espace-agent/conformite';
import { getLiassesFiscalesProtected } from '#models/espace-agent/dgfip/liasses-fiscales';
import { getDirigeantsProtected } from '#models/espace-agent/dirigeants-protected';
import { getEffectifsAnnuelsProtected } from '#models/espace-agent/effectifs/annuels';
import { getDocumentsRNEProtected } from '#models/espace-agent/rne-protected/documents';
Expand Down Expand Up @@ -38,6 +39,8 @@ export const APIRoutesHandlers = {
getEffectifsAnnuelsProtected,
[APIRoutesPaths.EspaceAgentChiffreAffairesProtected]:
getChiffreAffairesProtected,
[APIRoutesPaths.EspaceAgentLiassesFiscalesProtected]:
getLiassesFiscalesProtected,
[APIRoutesPaths.RneDirigeants]: getDirigeantsRNE,
[APIRoutesPaths.Observations]: getRNEObservations,
[APIRoutesPaths.Association]: getAssociationFromSlug,
Expand Down
1 change: 1 addition & 0 deletions app/api/data-fetching/routes-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum APIRoutesPaths {
EspaceAgentAssociationProtected = 'espace-agent/association-protected',
EspaceAgentEffectifsAnnuelsProtected = 'espace-agent/effectifs-annuels-protected',
EspaceAgentChiffreAffairesProtected = 'espace-agent/chiffre-affaires-protected',
EspaceAgentLiassesFiscalesProtected = 'espace-agent/dgfip-liasses-fiscales-protected',
RneDirigeants = 'rne-dirigeants',
Observations = 'observations',
Association = 'association',
Expand Down
2 changes: 2 additions & 0 deletions app/api/data-fetching/routes-scopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ export const APIRoutesScopes: Record<APIRoutesPaths, ApplicationRights> = {
[APIRoutesPaths.EspaceAgentConformite]: ApplicationRights.conformite,
[APIRoutesPaths.EspaceAgentChiffreAffairesProtected]:
ApplicationRights.chiffreAffaires,
[APIRoutesPaths.EspaceAgentLiassesFiscalesProtected]:
ApplicationRights.protectedCertificats,
};
37 changes: 37 additions & 0 deletions clients/api-entreprise/dgfip/liasses-fiscales.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import routes from '#clients/routes';
import { ILiassesFiscalesProtected } from '#models/espace-agent/dgfip/liasses-fiscales';
import { Siren } from '#utils/helpers';
import clientAPIEntreprise from '../client';
import { IAPIEntrepriseLiassesFiscales } from './types';

/**
* GET association from API Entreprise
*/
export async function clientApiEntrepriseDgfipLiassesFiscales(siren: Siren) {
return await clientAPIEntreprise<
IAPIEntrepriseLiassesFiscales,
ILiassesFiscalesProtected
>(
`${
process.env.API_ENTREPRISE_URL
}${routes.apiEntreprise.dgfip.liassesFiscales(
siren,
//TEMP
2022
)}`,
mapToDomainObject
);
}

const mapToDomainObject = (
response: IAPIEntrepriseLiassesFiscales
): ILiassesFiscalesProtected => {
return response.data.declarations.map((declaration) => ({
dureeExercice: declaration.duree_exercice,
dateFinExercice: declaration.date_fin_exercice,
donnees: declaration.donnees.map((donnee) => ({
intitule: donnee.intitule,
valeurs: donnee.valeurs,
})),
}));
};
39 changes: 39 additions & 0 deletions clients/api-entreprise/dgfip/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { IAPIEntrepriseResponse } from '../client';

type Regime = {
code: string;
libelle: string;
};

type Donnee = {
code_nref: string;
valeurs: string[];
code_absolu: string;
intitule: string;
code_EDI: string;
code: string;
code_type_donnee: string;
};

type Declaration = {
numero_imprime: string;
regime: Regime;
date_declaration: string;
date_fin_exercice: string;
duree_exercice: number;
millesime: number;
donnees: Donnee[];
};

type ObligationFiscale = {
id: string;
code: string;
libelle: string | null;
reference: string | null;
regime: string;
};

export type IAPIEntrepriseLiassesFiscales = IAPIEntrepriseResponse<{
obligations_fiscales: ObligationFiscale[];
declarations: Declaration[];
}>;
2 changes: 2 additions & 0 deletions clients/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const routes = {
dgfip: {
chiffreAffaires: (siret: string) =>
`/v3/dgfip/etablissements/${siret}/chiffres_affaires`,
liassesFiscales: (siren: string, year: number) =>
`/v3/dgfip/unites_legales/${siren}/liasses_fiscales/${year}`,
},
mandatairesRCS: (siren: string) =>
`/v3/infogreffe/rcs/unites_legales/${siren}/mandataires_sociaux`,
Expand Down
78 changes: 78 additions & 0 deletions components/finances-section/societe-liasses-fiscales/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
'use client';

import FAQLink from '#components-ui/faq-link';
import { Select } from '#components-ui/select';
import { AsyncDataSectionClient } from '#components/section/data-section/client';
import { FullTable } from '#components/table/full';
import { EAdministration } from '#models/administrations/EAdministration';
import { IUniteLegale } from '#models/core/types';
import { ISession } from '#models/user/session';
import { APIRoutesPaths } from 'app/api/data-fetching/routes-paths';
import { useAPIRouteData } from 'hooks/fetch/use-API-route-data';
import { ChangeEvent, useMemo, useState } from 'react';

export const FinancesSocieteLiassesFiscalesSection: React.FC<{
uniteLegale: IUniteLegale;
session: ISession | null;
}> = ({ uniteLegale, session }) => {
const currentYear = new Date().getFullYear();
const [selectedYear, setSelectedYear] = useState(currentYear - 1);

const options = useMemo(
() =>
Array.from({ length: 5 }, (_, i) => {
const year = currentYear - i;
return { value: year.toString(), label: year.toString() };
}),
[currentYear]
);

const liassesFiscalesProtected = useAPIRouteData(
APIRoutesPaths.EspaceAgentLiassesFiscalesProtected,
uniteLegale.siren,
session
);

return (
<AsyncDataSectionClient
title="Liasses Fiscales DGFIP"
id="liasses-fiscales-dgfip"
sources={[EAdministration.MEF]}
isProtected
data={liassesFiscalesProtected}
notFoundInfo="Aucune liasse fiscale n’a été retrouvé pour cette structure."
>
{(liassesFiscales) => {
const body = [
['Date de clôture', liassesFiscales[0].dateFinExercice],
...liassesFiscales[0].donnees.map((donnee) => [
donnee.intitule,
donnee.valeurs[0],
]),
];

return (
<>
<Select
options={options}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
setSelectedYear(parseInt(e.target.value, 10));
}}
/>
<FullTable
head={[
<FAQLink
tooltipLabel="Indicateurs"
to="/faq/donnees-financieres"
>
Définition des indicateurs
</FAQLink>,
]}
body={body}
/>
</>
);
}}
</AsyncDataSectionClient>
);
};
48 changes: 48 additions & 0 deletions cypress/fixtures/dgfip-liasses-fiscales.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"data": {
"obligations_fiscales": [
{
"id": "100209496193",
"code": "IS",
"libelle": "Impôt sur les sociétés",
"reference": null,
"regime": "RNMEMBRE"
},
{
"id": "101080892345",
"code": "ISGROUPE",
"libelle": null,
"reference": null,
"regime": "RNGROUPE"
}
],
"declarations": [
{
"numero_imprime": "2050",
"regime": {
"code": "RN",
"libelle": "Réel normal"
},
"date_declaration": "2023-07-24",
"date_fin_exercice": "2022-12-31",
"duree_exercice": 365,
"millesime": 201601,
"donnees": [
{
"code_nref": "300274",
"valeurs": ["222216704"],
"code_absolu": "2000321",
"intitule": "Concessions, brevets et droits similaires, brut",
"code_EDI": "AF:C516:5004:1",
"code": "AF",
"code_type_donnee": "MOA"
}
]
}
]
},
"links": {},
"meta": {
"internal_id_itip": "100008503160"
}
}
14 changes: 2 additions & 12 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// ***********************************************
//
//
import { allAgentScopes } from '#models/user/scopes';
import { ISession } from '#models/user/session';
import { sessionOptions } from '#utils/session';
import { sealData } from 'iron-session';
Expand All @@ -30,18 +31,7 @@ const generateSessionCookie = async () => {
firstName: 'John Doe',
fullName: 'John Doe',
email: '[email protected]',
scopes: [
'conformite',
'beneficiaires',
'cibtp',
'cnetp',
'agent',
'nonDiffusible',
'rne',
'pseudo_opendata',
'effectifs_annuels',
'dgfip',
],
scopes: [...allAgentScopes],
userType: 'Super-agent connecté',
hasHabilitation: true,
},
Expand Down
25 changes: 25 additions & 0 deletions models/espace-agent/dgfip/liasses-fiscales.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { clientApiEntrepriseDgfipLiassesFiscales } from '#clients/api-entreprise/dgfip/liasses-fiscales';
import { IAPINotRespondingError } from '#models/api-not-responding';
import { verifySiren } from '#utils/helpers';
import { handleApiEntrepriseError } from '../utils';

export type ILiassesFiscalesProtected = {
dureeExercice: number;
dateFinExercice: string;
donnees: {
intitule: string;
valeurs: string[];
}[];
}[];

export const getLiassesFiscalesProtected = async (
maybeSiren: string
): Promise<ILiassesFiscalesProtected | IAPINotRespondingError> => {
const siren = verifySiren(maybeSiren);
return clientApiEntrepriseDgfipLiassesFiscales(siren).catch((error) =>
handleApiEntrepriseError(error, {
siren,
apiResource: 'getDgfipLiassesFiscalesProtected',
})
);
};
3 changes: 3 additions & 0 deletions models/user/rights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export enum ApplicationRights {
probtp = 'Accès à l‘attestation PROBTP',
effectifsAnnuels = 'Effectifs annuels (RCD)',
chiffreAffaires = 'Accès aux chiffres d’affaires (DGFiP)',
liassesFiscales = 'Accès aux liasses fiscales (DGFiP)',
}

/**
Expand All @@ -41,6 +42,8 @@ export function hasRights(session: ISession | null, right: ApplicationRights) {
return userScopes.includes('conformite');
case ApplicationRights.chiffreAffaires:
return userScopes.includes('chiffre_affaires');
case ApplicationRights.liassesFiscales:
return userScopes.includes('liasses_fiscales');
case ApplicationRights.effectifsAnnuels:
return userScopes.includes('effectifs_annuels');
case ApplicationRights.protectedCertificats:
Expand Down
3 changes: 2 additions & 1 deletion models/user/scopes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getAdditionnalIAgentScope } from '#clients/authentication/super-agent-scopes';

const allAgentScopes = [
export const allAgentScopes = [
'rne',
'nonDiffusible',
'conformite',
Expand All @@ -12,6 +12,7 @@ const allAgentScopes = [
'probtp',
'effectifs_annuels',
'chiffre_affaires',
'liasses_fiscales',
] as const;

export type IAgentScope = (typeof allAgentScopes)[number];
Expand Down

0 comments on commit f20ebea

Please sign in to comment.