diff --git a/example.env b/example.env index c6734bf647eb74ae3e2cf0440435954c32631de2..fee13e6f705f063de3fb62207e2823e52777b861 100644 --- a/example.env +++ b/example.env @@ -70,4 +70,7 @@ SHOW_TUTORIAL=true # Directory containing JSON of simulations saved by users SIMULATIONS_DIR="../simulations" +# Key for taxable household (aka "foyer fiscal") entity +TAXABLE_HOUSEHOLD_KEY="foyer_fiscal" + TITLE="Simulateur socio-fiscal" diff --git a/src/app.d.ts b/src/app.d.ts index 3085b91f3e055afb7a84c2c5b5990df3206f4122..e929b7746e59ef587a54927d61fc9c7c93ff3a45 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -28,6 +28,7 @@ declare namespace App { portalUrl: string reformName?: string showTutorial?: boolean + taxableHouseholdEntityKey: string title: string user?: User } diff --git a/src/hooks.ts b/src/hooks.ts index c3cac06a56c27052467df453d16ba2ab784c3f9c..4431860a8d23fbd506a875c80ab3fc8c37477ffe 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -30,6 +30,7 @@ export const getSession: GetSession = async (event): Promise<App.Session> => { portalUrl: config.portalUrl, reformName: config.reformName, showTutorial: config.showTutorial, + taxableHouseholdEntityKey: config.taxableHouseholdEntityKey, title: config.title, user, } diff --git a/src/lib/auditors/config.ts b/src/lib/auditors/config.ts index 444895cfb6dc98c0ff86e0473a04351254b567d3..b2035e494e7274c5ebdc2df9f4f5ba37635a1f36 100644 --- a/src/lib/auditors/config.ts +++ b/src/lib/auditors/config.ts @@ -70,6 +70,7 @@ export function auditConfig( "familyEntityKey", "householdEntityKey", "simulationsDir", + "taxableHouseholdEntityKey", "title", ]) { audit.attribute( diff --git a/src/lib/components/test_cases/TestCaseSummary.svelte b/src/lib/components/test_cases/TestCaseSummary.svelte index cb9ac8f3c17613223a7eb3675fd8a51b167831f9..4335bbc6ddb05d6c299af09563c29a8eb49aa90d 100644 --- a/src/lib/components/test_cases/TestCaseSummary.svelte +++ b/src/lib/components/test_cases/TestCaseSummary.svelte @@ -51,11 +51,10 @@ let isTestCaseCompareModalOpen = false const personEntity = entityByKey[personEntityKey] let slider: Slider | undefined = undefined + const taxableHouseholdEntity = entityByKey[$session.taxableHouseholdEntityKey] $: familySituation = situation[familyEntity.key_plural] - $: householdSituation = situation[householdEntity.key_plural] - $: childrenId = Object.values(familySituation).reduce( (children: string[], family) => [ ...children, @@ -64,12 +63,16 @@ [], ) + $: householdSituation = situation[householdEntity.key_plural] + $: personSituation = situation[personEntity.key_plural] $: personsCount = Object.keys(personSituation).length $: slider = situation.sliders?.[0] + $: taxableHouseholdSituation = situation[taxableHouseholdEntity.key_plural] + function changeVectorIndex(event: Event) { const target = event.target as HTMLInputElement const vectorIndex = parseInt(target.value) @@ -164,7 +167,7 @@ valuesByCalculationNameByVariableName: ValuesByCalculationNameByVariableName, variableName: string, populationId: string, - ): VariableValue | undefined { + ): number | undefined { return getCalculatedVariableValue( situation, valuesByCalculationNameByVariableName, @@ -375,6 +378,7 @@ ? "flex flex-col" : "grid gap-x-8 grid-cols-2 sm:grid-cols-3 md:grid-cols-2 xl:grid-cols-3"} > + <!-- Individus --> {#each Object.keys(personSituation).sort( (populationId1, populationId2) => populationId1.localeCompare(populationId2), ) as populationId} {@const activite = getVariableValue(situation, "activite", populationId)} {@const allocation_retour_emploi = getVariableValue( @@ -538,13 +542,15 @@ </div> {/each} + <!-- Familles --> {#each Object.keys(familySituation).sort( (populationId1, populationId2) => populationId1.localeCompare(populationId2), ) as populationId} - {@const rsa = getCalculatedVariableNumberValue( - situation, - valuesByCalculationNameByVariableName, - "rsa", - populationId, - )} + {@const rsa = + getCalculatedVariableNumberValue( + situation, + valuesByCalculationNameByVariableName, + "rsa", + populationId, + ) ?? 0} <div class="my-2"> {#if rsa !== 0} <abbr @@ -555,6 +561,52 @@ </div> {/each} + <!-- Foyers fiscaux --> + {#each Object.keys(taxableHouseholdSituation).sort( (populationId1, populationId2) => populationId1.localeCompare(populationId2), ) as populationId} + {@const assiette_csg_revenus_capital = + getCalculatedVariableNumberValue( + situation, + valuesByCalculationNameByVariableName, + "assiette_csg_revenus_capital", + populationId, + ) ?? 0} + {@const assiette_csg_plus_values = + getCalculatedVariableNumberValue( + situation, + valuesByCalculationNameByVariableName, + "assiette_csg_plus_values", + populationId, + ) ?? 0} + {@const plus_values_base_large = + getCalculatedVariableNumberValue( + situation, + valuesByCalculationNameByVariableName, + "plus_values_base_large", + populationId, + ) ?? 0} + {@const rente_viagere_titre_onereux_net = + getCalculatedVariableNumberValue( + situation, + valuesByCalculationNameByVariableName, + "rente_viagere_titre_onereux_net", + populationId, + ) ?? 0} + {@const revenus_nets_du_capital = + assiette_csg_revenus_capital - + assiette_csg_plus_values + + plus_values_base_large - + rente_viagere_titre_onereux_net} + <div class="my-2"> + {#if revenus_nets_du_capital !== 0} + <span + class="my-1 rounded-2xl bg-blue-200 py-1 px-2 text-xs text-gray-800 shadow-sm" + >Revenus du capital</span + > + {/if} + </div> + {/each} + + <!-- Ménages --> {#each Object.keys(householdSituation).sort( (populationId1, populationId2) => populationId1.localeCompare(populationId2), ) as populationId} {@const loyer = getVariableValue(situation, "loyer", populationId)} {@const statut_occupation_logement = getVariableValue( diff --git a/src/lib/server/config.ts b/src/lib/server/config.ts index 708ff9c1918812110a6ceba6f146a162a544d6c8..b7c262bd39b4dc554295fb9be1c341ec5c0163c4 100644 --- a/src/lib/server/config.ts +++ b/src/lib/server/config.ts @@ -34,6 +34,7 @@ export interface Config { reformName?: string showTutorial?: boolean simulationsDir: string + taxableHouseholdEntityKey: string title: string } @@ -78,6 +79,7 @@ const [validConfig, error] = validateConfig({ reformName: process.env["REFORM"], showTutorial: process.env["SHOW_TUTORIAL"], simulationsDir: process.env["SIMULATIONS_DIR"], + taxableHouseholdEntityKey: process.env["TAXABLE_HOUSEHOLD_KEY"], title: process.env["TITLE"], }) if (error !== null) { diff --git a/src/lib/variables.ts b/src/lib/variables.ts index 0fa4c732cf907ce710fd0e32728b422dd7863c78..be46d34f95177d511329bc8420f976f2691818cf 100644 --- a/src/lib/variables.ts +++ b/src/lib/variables.ts @@ -31,6 +31,16 @@ export type VariableValue = boolean | number | string export type VariableValues = boolean[] | number[] | string[] +/// Name of variables that must be calculated to be displayed in +/// test case summaries. +export const summaryCalculatedVariablesName = [ + "assiette_csg_revenus_capital", + "assiette_csg_plus_values", + "plus_values_base_large", + "rente_viagere_titre_onereux_net", + "rsa", +] + export const variableSummaryByName = variableSummaryByNameUnknown as VariableByName diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index c694b8a4777695da283ea89caebda462f2be399a..bb328964272970b667224e9f80256542db55a620 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -42,11 +42,12 @@ indexOfSituationPopulationId, testCasesCore, } from "$lib/situations" - import type { - ValuesByCalculationNameByVariableName, - VariableValue, + import { + summaryCalculatedVariablesName, + type ValuesByCalculationNameByVariableName, + variableSummaryByName, + type VariableValue, } from "$lib/variables" - import { variableSummaryByName } from "$lib/variables" import type { WebSocketByName, WebSocketOpenByName } from "$lib/websockets" const axes: Writable<Axis[][]> = writable([]) @@ -328,7 +329,10 @@ situation, title: "law", token, - variables: nonVirtualDecompositionsName, + variables: [ + ...summaryCalculatedVariablesName, + ...nonVirtualDecompositionsName, + ], }), ) } @@ -359,9 +363,11 @@ situation, title: "bill", token, - variables: - nonVirtualDecompositionsNameByReformName[$billName] ?? - nonVirtualDecompositionsName, + variables: [ + ...summaryCalculatedVariablesName, + ...(nonVirtualDecompositionsNameByReformName[$billName] ?? + nonVirtualDecompositionsName), + ], }), ) } @@ -393,9 +399,11 @@ situation, title: "amendment", token, - variables: - nonVirtualDecompositionsNameByReformName[$billName] ?? - nonVirtualDecompositionsName, + variables: [ + ...summaryCalculatedVariablesName, + ...(nonVirtualDecompositionsNameByReformName[$billName] ?? + nonVirtualDecompositionsName), + ], }), ) }