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

fix(2120): prise ne compte de la part variable du salaire dans le calcul du SRef #5371

Merged
merged 9 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions packages/code-du-travail-frontend/pages/glossaire/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ function getGlossaryLetters(glossary) {
);
return alphabet.map((letter) => ({
letter,
terms: glossary.filter(
({ slug }) => slug.slice(0, 1).toUpperCase() === letter
),
terms: glossary
.filter(({ slug }) => slug.slice(0, 1).toUpperCase() === letter)
.sort((a, b) => a.term.localeCompare(b.term)),
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Props = {
label: string;
tooltip?: Tooltip;
inputType?: "date" | "number" | "text";
value: string | undefined;
value: string | number | undefined;
m-maillot marked this conversation as resolved.
Show resolved Hide resolved
placeholder?: string;
subLabel?: string;
smallText?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React, { useContext } from "react";
import { icons } from "@socialgouv/cdtn-ui";

import { TextQuestion } from "../../../Components";
import {
IndemniteLicenciementContext,
useIndemniteLicenciementStore,
} from "../../store";

export default function Agreement2120() {
const store = useContext(IndemniteLicenciementContext);
const {
salariesVariablePart,
onChangeSalariesVariablePart,
errorSalariesVariablePart,
isLicenciementDisciplinaire,
init,
} = useIndemniteLicenciementStore(store, (state) => ({
salariesVariablePart: state.agreement2120Data.input.salariesVariablePart,
onChangeSalariesVariablePart:
state.agreement2120Function.onChangeSalariesVariablePart,
errorSalariesVariablePart:
state.agreement2120Data.error.errorSalariesVariablePart,
isLicenciementDisciplinaire:
state.agreement2120Data.input.isLicenciementDisciplinaire,
init: state.agreement2120Function.init,
}));

React.useEffect(() => {
init();
}, []);

if (isLicenciementDisciplinaire) return <></>;
return (
<TextQuestion
label="Montant total des éléments variables perçus au cours des 12 derniers mois précédant la notification du licenciement"
subLabel="Indiquez le montant total des éléments variables, primes (à l’exception du 13ème mois) et avantages en nature perçus au cours des 12 derniers mois précédant la notification du licenciement"
inputType="number"
value={salariesVariablePart}
onChange={onChangeSalariesVariablePart}
error={errorSalariesVariablePart}
id="salariesVariablePart"
showRequired
icon={icons.Euro}
tooltip={{
content: (
<>
<p>
Vous pouvez trouver ces éléments sur votre bulletin de paie.
Renseignez dans ce champ la somme des primes (fixes ou
exceptionnelles, sauf prime ou gratification librement versée par
l’employeur), éléments variables (ex : commissions) et avantages
en nature (ex : mise à disposition d’un logement ou d’un véhicule)
perçus au cours des 12 mois précédant la notification du
licenciement.
</p>
<p>
Le montant renseigné nous permettra de calculer l’indemnité de
licenciement prévue par la convention collective de la banque qui
est calculée sur la base des salaires sans ces éléments de
rémunération. Il sera donc déduit du/des salaires renseigné(s) à
la question précédente. A l’inverse, l’indemnité prévue par le
code du travail est calculée sur la base des salaires avec ces
éléments de rémunération.
</p>
</>
),
}}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useContext } from "react";
import {
IndemniteLicenciementContext,
useIndemniteLicenciementStore,
} from "../../store";

export default function Agreement2120Informations() {
const store = useContext(IndemniteLicenciementContext);
const { salariesVariablePart } = useIndemniteLicenciementStore(
store,
(state) => ({
salariesVariablePart: state.agreement2120Data.input.salariesVariablePart,
})
);

if (salariesVariablePart === undefined) return <></>;

return (
<li>
Montant total des éléments variables, primes (à l’exception du 13ème mois)
et avantages en nature&nbsp;:&nbsp;
{salariesVariablePart}&nbsp;€
</li>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as Agreement2120 } from "./Component";
export * from "./store";
export { default as Agreement2120Informations } from "./Informations";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./types";
export * from "./store";
export { validateAgreement2120 } from "./validator";
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import produce from "immer";
import { GetState, SetState } from "zustand";
import { SalairesStoreSlice } from "../../../steps/Salaires/store";
import { StoreSlice } from "../../../../types";
import {
Agreement2120StoreData,
Agreement2120StoreInput,
Agreement2120StoreSlice,
} from "./types";
import { validateStep } from "./validator";
import { CommonInformationsStoreSlice } from "../../../../CommonSteps/Informations/store";

const initialState: Agreement2120StoreData = {
input: {
salariesVariablePart: undefined,
isLicenciementDisciplinaire: false,
},
error: {},
hasBeenSubmit: false,
isStepValid: false,
};

export const createAgreement2120StoreSalaires: StoreSlice<
Agreement2120StoreSlice,
SalairesStoreSlice & CommonInformationsStoreSlice
> = (set, get) => ({
agreement2120Data: { ...initialState },
agreement2120Function: {
init: () => {
const isLicenciementDisciplinaire =
get()
.informationsData.input.publicodesInformations.find(
(v) =>
v.question.rule.nom ===
"contrat salarié . convention collective . banque . licenciement disciplinaire"
)
?.info?.slice(1, -1) === "Oui";

set(
produce((state: Agreement2120StoreSlice) => {
state.agreement2120Data.input.isLicenciementDisciplinaire =
isLicenciementDisciplinaire;
})
);
},
onChangeSalariesVariablePart: (value: string) => {
const valueNumber = parseInt(value, 10);
applyGenericValidation(
get,
set,
"salariesVariablePart",
isNaN(valueNumber) ? undefined : valueNumber
);
},
},
});

const applyGenericValidation = (
get: GetState<Agreement2120StoreSlice & SalairesStoreSlice>,
set: SetState<Agreement2120StoreSlice & SalairesStoreSlice>,
paramName: keyof Agreement2120StoreInput,
value: any
) => {
if (get().agreement2120Data.hasBeenSubmit) {
const nextState = produce(get(), (draft) => {
draft.agreement2120Data.input[paramName] = value;
});
const { isValid, errorState } = validateStep(
nextState.agreement2120Data.input
);

set(
produce((state: Agreement2120StoreSlice) => {
state.agreement2120Data.error = errorState;
state.agreement2120Data.isStepValid = isValid;
state.agreement2120Data.input[paramName] = value;
})
);
get().salairesFunction.onNextStep();
} else {
set(
produce((state: Agreement2120StoreSlice) => {
state.agreement2120Data.input[paramName] = value;
})
);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { StepData } from "../../../store";

export type Agreement2120StoreInput = {
isLicenciementDisciplinaire?: boolean;
salariesVariablePart?: number;
};

export type Agreement2120StoreError = {
errorSalariesVariablePart?: string;
};

export type Agreement2120StoreData = StepData<
Agreement2120StoreInput,
Agreement2120StoreError
>;

export type Agreement2120StoreFn = {
onChangeSalariesVariablePart: (value: string) => void;
init: () => void;
};

export type Agreement2120StoreSlice = {
agreement2120Data: Agreement2120StoreData;
agreement2120Function: Agreement2120StoreFn;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import produce from "immer";
import { GetState, SetState } from "zustand";
import { MainStore } from "../../../store";
import { Agreement2120StoreInput, Agreement2120StoreSlice } from "./types";

export const validateAgreement2120 = (
get: GetState<MainStore>,
set: SetState<MainStore>
) => {
const { isValid, errorState } = validateStep(get().agreement2120Data.input);
set(
produce((state: Agreement2120StoreSlice) => {
state.agreement2120Data.hasBeenSubmit = !isValid;
state.agreement2120Data.isStepValid = isValid;
state.agreement2120Data.error = errorState;
})
);

return isValid;
};

export const validateStep = (state: Agreement2120StoreInput) => {
const isValid =
state.isLicenciementDisciplinaire ||
state.salariesVariablePart !== undefined;

const errorState = {
errorSalariesVariablePart: !isValid
? "Vous devez répondre à cette question"
: undefined,
};

return {
isValid: isValid,
errorState,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
Agreement1740,
Agreement1740Informations,
} from "./1740-batiment-region-parisienne";
import { Agreement2120, Agreement2120Informations } from "./2120-banques";

type Props = {
idcc: SupportedCcIndemniteLicenciement | null;
Expand Down Expand Up @@ -89,6 +90,12 @@ export default function AgreementsInjector(props: Props) {
case SupportedCcIndemniteLicenciement.IDCC2609 === props.idcc &&
props.step === IndemniteLicenciementStepName.Resultat:
return <Agreement2609Informations />;
case SupportedCcIndemniteLicenciement.IDCC2120 === props.idcc &&
props.step === IndemniteLicenciementStepName.Salaires:
return <Agreement2120 />;
case SupportedCcIndemniteLicenciement.IDCC2120 === props.idcc &&
props.step === IndemniteLicenciementStepName.Resultat:
return <Agreement2120Informations />;
case SupportedCcIndemniteLicenciement.IDCC2148 === props.idcc &&
props.step === IndemniteLicenciementStepName.Salaires:
return <Agreement2148 />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class AgreementSalary2120 implements AgreementSalary {

return sReference.computeReferenceSalary({
salaires: salaryPeriods,
salariesVariablePart:
get().agreement2120Data.input.salariesVariablePart ?? 0,
isLicenciementDisciplinaire: isLicenciementInaptitude
? QuestionOuiNon.non
: isLicenciementDisciplinaire,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,20 @@ import {
Agreement1740StoreSlice,
createAgreement1740StoreSalaires,
} from "./1740-batiment-region-parisienne";
import {
Agreement2120StoreError,
Agreement2120StoreInput,
Agreement2120StoreSlice,
createAgreement2120StoreSalaires,
} from "./2120-banques";

export type AgreementStoreInput = Agreement1516StoreInput &
Agreement1527StoreInput &
Agreement16StoreInput &
Agreement29StoreInput &
Agreement44StoreInput &
Agreement2596StoreInput &
Agreement2120StoreInput &
Agreement2148StoreInput &
Agreement2609StoreInput &
Agreement1702StoreInput &
Expand All @@ -99,6 +106,7 @@ export type AgreementStoreError = Agreement1516StoreError &
Agreement44StoreError &
Agreement29StoreError &
Agreement2596StoreError &
Agreement2120StoreError &
Agreement2148StoreError &
Agreement2609StoreError &
Agreement1702StoreError &
Expand All @@ -114,9 +122,9 @@ export type AgreementStoreSlice = Agreement1516StoreSlice &
Agreement29StoreSlice &
Agreement2614StoreSlice &
Agreement2596StoreSlice &
Agreement2120StoreSlice &
Agreement2148StoreSlice &
Agreement2609StoreSlice &
Agreement1672StoreSlice &
Agreement1483StoreSlice &
Agreement1702StoreSlice &
Agreement1672StoreSlice &
Expand All @@ -133,6 +141,7 @@ export const createRootAgreementsStore = (
...createAgreement29StoreSalaires(set, get, options),
...createAgreement44StoreSalaires(set, get, options),
...createAgreement2596StoreSalaires(set, get, options),
...createAgreement2120StoreSalaires(set, get, options),
...createAgreement2148StoreSalaires(set, get, options),
...createAgreement2609StoreSalaires(set, get, options),
...createAgreement1702StoreSalaires(set, get, options),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { validateAgreement44 } from "./44-industries-chimiques";
import { validateAgreement2609 } from "./2609-batiment-etam";
import { validateAgreement2614 } from "./2614-travaux-public";
import { validateAgreement2596 } from "./2596-coiffure";
import { validateAgreement2120 } from "./2120-banques";
import { validateAgreement2148 } from "./2148-telecommunications";
import { validateAgreement1672 } from "./1672-societes-assurances";
import { validateAgreement1483 } from "./1483-habillement-textiles-commerce-de-detail";
Expand Down Expand Up @@ -44,6 +45,9 @@ const validatorAgreement = (
case SupportedCcIndemniteLicenciement.IDCC2609 === idcc &&
step === IndemniteLicenciementStepName.Salaires:
return validateAgreement2609(get, set);
case SupportedCcIndemniteLicenciement.IDCC2120 === idcc &&
step === IndemniteLicenciementStepName.Salaires:
return validateAgreement2120(get, set);
case SupportedCcIndemniteLicenciement.IDCC2148 === idcc &&
step === IndemniteLicenciementStepName.Salaires:
return validateAgreement2148(get, set);
Expand Down
Loading
Loading