-
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(dgfip liasses fiscales): add dgfip liasses fiscales data
- Loading branch information
Showing
13 changed files
with
247 additions
and
13 deletions.
There are no files selected for viewing
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
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
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
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
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,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, | ||
})), | ||
})); | ||
}; |
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,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[]; | ||
}>; |
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
78 changes: 78 additions & 0 deletions
78
components/finances-section/societe-liasses-fiscales/index.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,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> | ||
); | ||
}; |
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,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" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -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'; | ||
|
@@ -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, | ||
}, | ||
|
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,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', | ||
}) | ||
); | ||
}; |
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
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