From cc0bcc28f63427ee58b85789c800a239d884a782 Mon Sep 17 00:00:00 2001 From: Lionel Date: Mon, 1 Jul 2019 09:37:54 +0200 Subject: [PATCH] feat(frontend): add ccn 2120 to idl (#966) * feat(frontend): add skippable branche steps We add a function condition() which take the finalform values and return a boolean this function is designed to filter steps depending on previous values * feat(frontend): add ccn 2120 to idl fix #931 --- .../outils/indemniteLicenciement/branches.js | 4 + .../indemniteLicenciement/ccn/2120/Result.js | 51 +++++ .../indemniteLicenciement/ccn/2120/Step.js | 92 +++++++++ .../ccn/2120/__tests__/Result.test.js | 20 ++ .../ccn/2120/__tests__/Step.test.js | 14 ++ .../__snapshots__/Result.test.js.snap | 151 ++++++++++++++ .../__tests__/__snapshots__/Step.test.js.snap | 150 ++++++++++++++ .../__snapshots__/indemnite.test.js.snap | 21 ++ .../ccn/2120/__tests__/indemnite.test.js | 195 ++++++++++++++++++ .../ccn/2120/indemnite.js | 125 +++++++++++ .../indemniteLicenciement/ccn/2120/index.js | 16 ++ .../src/outils/indemniteLicenciement/index.js | 16 +- .../__snapshots__/Indemnite.test.js.snap | 5 + 13 files changed, 856 insertions(+), 4 deletions(-) create mode 100644 packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/Result.js create mode 100644 packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/Step.js create mode 100644 packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/Result.test.js create mode 100644 packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/Step.test.js create mode 100644 packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/__snapshots__/Result.test.js.snap create mode 100644 packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/__snapshots__/Step.test.js.snap create mode 100644 packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/__snapshots__/indemnite.test.js.snap create mode 100644 packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/indemnite.test.js create mode 100644 packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/indemnite.js create mode 100644 packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/index.js diff --git a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/branches.js b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/branches.js index ee880f7bee..520947c410 100644 --- a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/branches.js +++ b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/branches.js @@ -37,6 +37,10 @@ export const branches = [ label: "Convention collective nationale Boucherie boucherie-charcuterie triperie" }, + { + value: "2120", + label: "Convention collective nationale des banques" + }, { value: "2344", label: "Convention collective nationale de la Sidérurgie" diff --git a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/Result.js b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/Result.js new file mode 100644 index 0000000000..f00f5889b0 --- /dev/null +++ b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/Result.js @@ -0,0 +1,51 @@ +import React from "react"; +import { getIndemniteFromFinalForm } from "../../indemnite"; + +import { IndemniteCCn } from "../../components/IndemniteConventionnelle"; +import { getIndemnite, getSalaireRef } from "./indemnite"; + +export function Result({ form }) { + const state = form.getState(); + + const { + hasTempsPartiel = false, + hasSameSalaire = false, + salairePeriods = [], + salaires = [], + salaire, + anciennete, + dateEntree, + dateSortie, + branche, + motif, + categorie + } = state.values; + + const { indemniteLegale, formuleLegale } = getIndemniteFromFinalForm(form); + const salaireRef = getSalaireRef({ + hasTempsPartiel, + hasSameSalaire, + salaire, + salairePeriods, + salaires, + anciennete + }); + const { error, indemniteConventionnelle, formula } = getIndemnite({ + salaireRef, + dateEntree, + dateSortie, + anciennete, + categorie, + motif + }); + return ( + + ); +} diff --git a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/Step.js b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/Step.js new file mode 100644 index 0000000000..2780cf69e2 --- /dev/null +++ b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/Step.js @@ -0,0 +1,92 @@ +import React from "react"; +import { Field } from "react-final-form"; +import styled from "styled-components"; +import { Container, theme } from "@cdt/ui"; + +import { SectionTitle, Label } from "../../stepStyles"; + +export const DISCIPLINAIRE = "disciplinaire"; +export const NON_DISCIPLINAIRE = "non-disciplinaire"; +export const ECONOMIQUE = "eco"; + +export const CADRE = "cadre"; +export const NON_CADRE = "non-cadre"; +export const NE_SAIT_PAS = "ne-sais-pas"; + +const optionMotifs = { + [DISCIPLINAIRE]: "Motif disciplinaire", + [NON_DISCIPLINAIRE]: "Motif non disciplinaire", + [ECONOMIQUE]: "Motif économique" +}; + +const optionCategorie = { + [NON_CADRE]: "Non cadre", + [CADRE]: "Cadre", + [NE_SAIT_PAS]: "Ne sait pas" +}; + +function Step() { + return ( + + Motif du licenciement + + {({ input }) => { + return ( + + + + + ); + }} + + + + {({ input }) => { + return ( + + + + + + ); + }} + + + ); +} + +export { Step }; + +const { spacing } = theme; +const Select = styled.select` + max-width: 20rem; +`; + +const FormGroup = styled.div` + display: flex; + flex-direction: column; + align-items: flex-start; + margin-bottom: ${spacing.interComponent}; +`; diff --git a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/Result.test.js b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/Result.test.js new file mode 100644 index 0000000000..c09766d080 --- /dev/null +++ b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/Result.test.js @@ -0,0 +1,20 @@ +import React from "react"; +import { render } from "react-testing-library"; +import { Result } from "../Result"; +import { Form } from "react-final-form"; + +const initialValues = { + branche: "2120" +}; + +describe("", () => { + it("should render", () => { + const onSubmit = jest.fn(); + const { container } = render( +
+ {({ form }) => } + + ); + expect(container).toMatchSnapshot(); + }); +}); diff --git a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/Step.test.js b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/Step.test.js new file mode 100644 index 0000000000..0a7f5b75ea --- /dev/null +++ b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/Step.test.js @@ -0,0 +1,14 @@ +import React from "react"; +import { render } from "react-testing-library"; +import { Step } from "../Step"; +import { Form } from "react-final-form"; + +describe("", () => { + it("should render", () => { + const onSubmit = jest.fn(); + const { container } = render( +
{({ form }) => } + ); + expect(container).toMatchSnapshot(); + }); +}); diff --git a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/__snapshots__/Result.test.js.snap b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/__snapshots__/Result.test.js.snap new file mode 100644 index 0000000000..efe1448050 --- /dev/null +++ b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/__snapshots__/Result.test.js.snap @@ -0,0 +1,151 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` should render 1`] = ` +.c0 { + max-width: 1200px; + margin: 0 auto; + padding: 0 1.25rem; +} + +.c0 > *:first-child { + margin-top: 0; +} + +.c0 > *:last-child { + margin-bottom: 0; +} + +.c4 { + padding: 0.625rem 1rem; + -webkit-appearance: none; + -moz-appearance: none; + appearance: none; + text-align: center; + line-height: inherit; + font-size: 1rem; + font-weight: 600; + vertical-align: middle; + border-style: solid; + border-width: 1px 1px 2px 1px; + border-radius: 0.25rem; + cursor: pointer; + -webkit-transition: background-color 250ms ease; + transition: background-color 250ms ease; + color: #fff; + background: #006be6; + border-color: #006be6; + border-bottom-color: #0053b3; +} + +.c4:not([disabled]):hover, +.c4:not([disabled]):focus { + background: #07f; + color: #fff; +} + +.c4:not([disabled]):active { + color: #fff; + background: #1a85ff; + border-width: 2px 1px 1px 1px; + border-color: #006be6; + outline: none; +} + +.c4[aria-pressed="true"] { + color: #fff; + background: #07f; + border-width: 2px 1px 1px 1px; + border-color: #006be6; + border-top-color: #0053b3; + box-shadow: inset 0 1px 2px 0 #0053b3; +} + +.c4[aria-pressed="true"]:not([disabled]):hover, +.c4[aria-pressed="true"]:not([disabled]):focus { + background-color: #006be6; +} + +.c4[aria-pressed="true"]:not([disabled]):active { + border-top-color: #0053b3; +} + +.c4[disabled] { + cursor: not-allowed; + color: rgba(255,255,255,0.4); +} + +.c1 { + font-size: 1.625rem; + margin-top: 2rem; + margin-bottom: 1.25rem; +} + +.c2 { + font-size: 1.625rem; + font-weight: 700; + color: #0053b3; +} + +.c3 { + color: #434956; + font-style: italic; +} + +@media print { + .c0 { + max-width: 100%; + padding: 0; + } +} + +
+
+

+ Convention collective nationale des banques +

+

+ Le montant de l’indemnité est + + + NaN + € + + + + sur la base du calcul de l’indemnité légale + +

+
+
+ + Voir le detail du calcul + +
+
+ \`undefined\` +
+
+
+
+
+ +
+
+`; diff --git a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/__snapshots__/Step.test.js.snap b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/__snapshots__/Step.test.js.snap new file mode 100644 index 0000000000..be422755f5 --- /dev/null +++ b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/__snapshots__/Step.test.js.snap @@ -0,0 +1,150 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` should render 1`] = ` +.c0 { + max-width: 1200px; + margin: 0 auto; + padding: 0 1.25rem; +} + +.c0 > *:first-child { + margin-top: 0; +} + +.c0 > *:last-child { + margin-bottom: 0; +} + +.c3 { + padding: 0; + text-align: center; + font-size: 1.15rem; + margin-right: 2em; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; +} + +.c1 { + font-size: 1.625rem; + margin-top: 2rem; + margin-bottom: 1.25rem; +} + +.c4 { + max-width: 20rem; +} + +.c2 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; + -webkit-align-items: flex-start; + -webkit-box-align: flex-start; + -ms-flex-align: flex-start; + align-items: flex-start; + margin-bottom: 1.25rem; +} + +@media print { + .c0 { + max-width: 100%; + padding: 0; + } +} + +
+
+

+ Motif du licenciement +

+
+ + +
+
+ + +
+
+
+`; diff --git a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/__snapshots__/indemnite.test.js.snap b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/__snapshots__/indemnite.test.js.snap new file mode 100644 index 0000000000..e57f4c2abc --- /dev/null +++ b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/__snapshots__/indemnite.test.js.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`getIndemnite 2k, 10ans et 8mois d'ancienneté, motif disciplinaire 1`] = `""`; + +exports[`getIndemnite 2k, 10ans et 8mois d'ancienneté, motif disciplinaire 2`] = `"min(1/5 * 1846.15 * 21, 18 * (13 / 14.5) * 1846.15)"`; + +exports[`getIndemnite 2k, 10ans et 8mois d'ancienneté, motif economique 1`] = `"min(1/4 * 1846.15 * 21, 18 * (13 / 14.5) * 1846.15)"`; + +exports[`getIndemnite 2k, 12mois d'ancienneté 1`] = `""`; + +exports[`getIndemnite 2k, 19ans et 8mois d'ancienneté 1`] = `"min(1/5 * 1846.15 * 35, 18 * (13 / 14.5) * 1846.15)"`; + +exports[`getIndemnite 2k, 19ans et 8mois d'ancienneté, motif economique 1`] = `"min(1/4 * 1846.15 * 35, 18 * (13 / 14.5) * 1846.15)"`; + +exports[`getIndemnite 2k, 20ans et 8mois d'ancienneté, cadre, embauche avant le 2000 1`] = `"min(1/5 * 1846.15 * 35, 15 * 1846.15)"`; + +exports[`getIndemnite 2k, 20ans et 8mois d'ancienneté, motif economique, embauche avant le 2000 1`] = `"min(1/4 * 1846.15 * 35, 18 * 1846.15)"`; + +exports[`getIndemnite 2k, 20ans et 8mois d'ancienneté, ne-sait-pas, embauche avant le 2000 1`] = `"min(1/5 * 1846.15 * 35, 15 * 1846.15)"`; + +exports[`getIndemnite 2k, 20ans et 8mois d'ancienneté, non cadre, embauche avant le 2000 1`] = `"min(1/5 * 1846.15 * 35, 15 * 1846.15)"`; diff --git a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/indemnite.test.js b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/indemnite.test.js new file mode 100644 index 0000000000..4abe723f00 --- /dev/null +++ b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/__tests__/indemnite.test.js @@ -0,0 +1,195 @@ +import { + getIndemnite as getIndemniteConventionnelle, + getSalaireRef as getSalaireRefConventionnel +} from "../indemnite"; +import { getIndemnite, getSalaireRef } from "../../../indemnite"; +import { + CADRE, + NON_CADRE, + NE_SAIT_PAS, + DISCIPLINAIRE, + NON_DISCIPLINAIRE, + ECONOMIQUE +} from "../Step"; + +const initialData = { + salaires: Array.from({ length: 12 }).fill({ salary: 2000 }), + hasTempsPartiel: false, + categorie: NE_SAIT_PAS, + motif: NON_DISCIPLINAIRE, + dateEntree: "2018-10-01", + dateSortie: "2019-09-01", + anciennete: 0.91, + branche: "2120", + age: "55" +}; + +const tests = [ + { + title: "2k, 12mois d'ancienneté", + data: { + ...initialData + }, + result: 0 + }, + { + title: "2k, 10ans et 8mois d'ancienneté, motif disciplinaire", + data: { + ...initialData, + dateEntree: "2009-01-01", + dateSortie: "2019-09-01", + motif: DISCIPLINAIRE, + anciennete: 10.667 + }, + result: 0 + }, + { + title: "2k, 10ans et 8mois d'ancienneté, motif disciplinaire", + data: { + ...initialData, + dateEntree: "2009-01-01", + dateSortie: "2019-09-01", + anciennete: 10.667 + }, + result: 7753.84 + }, + { + title: "2k, 10ans et 8mois d'ancienneté, motif economique", + data: { + ...initialData, + dateEntree: "2009-01-01", + dateSortie: "2019-09-01", + anciennete: 10.667, + motif: ECONOMIQUE + }, + result: 9692.3 + }, + { + title: "2k, 19ans et 8mois d'ancienneté", + data: { + ...initialData, + dateEntree: "2000-01-01", + dateSortie: "2019-09-01", + anciennete: 19.667 + }, + result: 16233.42 + }, + { + title: "2k, 19ans et 8mois d'ancienneté, motif economique", + data: { + ...initialData, + dateEntree: "2000-01-01", + dateSortie: "2019-09-01", + anciennete: 19.667, + motif: ECONOMIQUE + }, + result: 19846.15 + }, + { + title: "2k, 20ans et 8mois d'ancienneté, cadre, embauche avant le 2000", + data: { + ...initialData, + dateEntree: "1999-01-01", + dateSortie: "2019-09-01", + anciennete: 20.667, + categorie: CADRE + }, + result: 17888.59 + }, + { + title: + "2k, 20ans et 8mois d'ancienneté, motif economique, embauche avant le 2000", + data: { + ...initialData, + dateEntree: "1999-01-01", + dateSortie: "2019-09-01", + anciennete: 20.667, + motif: ECONOMIQUE, + categorie: CADRE + }, + result: 21692.3 + }, + { + title: "2k, 20ans et 8mois d'ancienneté, non cadre, embauche avant le 2000", + data: { + ...initialData, + dateEntree: "1999-01-01", + dateSortie: "2019-09-01", + anciennete: 20.667, + categorie: NON_CADRE + }, + result: 17888.59 + }, + { + title: + "2k, 20ans et 8mois d'ancienneté, ne-sait-pas, embauche avant le 2000", + data: { + ...initialData, + dateEntree: "1999-01-01", + dateSortie: "2019-09-01", + anciennete: 20.667, + categorie: NE_SAIT_PAS + }, + result: 17888.59 + } +]; +describe("getIndemnite", () => { + tests.forEach(({ title, data, result }) => { + it(title, () => { + const salaireRef = getSalaireRefConventionnel({ + ...data + }); + const res = getIndemniteConventionnelle({ + ...data, + salaireRef + }); + expect(res.indemniteConventionnelle).toBe(result); + expect(res.formula).toMatchSnapshot(); + }); + }); + + it("should return an error for anciennete < 2", () => { + const salaireRef = getSalaireRef({ ...initialData }); + const { indemnite } = getIndemnite({ + salaireRef, + ...initialData + }); + const salaireRefConventionnel = getSalaireRefConventionnel({ + ...initialData + }); + + const res = getIndemniteConventionnelle({ + salaireRef: salaireRefConventionnel, + indemnite, + ...initialData + }); + + expect(res.error).toMatchInlineSnapshot( + `"La convention collective prévoit une indemnité conventionnelle de licenciement à partir d'un an d'ancienneté"` + ); + }); + it("should return an error for motif disciplinaire", () => { + const salaireRef = getSalaireRef({ ...initialData }); + const { indemnite } = getIndemnite({ + salaireRef, + ...initialData + }); + const salaireRefConventionnel = getSalaireRefConventionnel({ + ...initialData + }); + + const res = getIndemniteConventionnelle({ + salaireRef: salaireRefConventionnel, + indemnite, + ...initialData, + dateEntree: "2009-01-01", + dateSortie: "2019-09-01", + anciennete: 10.667, + motif: DISCIPLINAIRE + }); + + expect(res.error).toMatchInlineSnapshot( + `"La convention collective prévoit le droit à l’indemnité légale en cas de licenciement pour motif disciplinaire, sauf pour faute grave ou lourde"` + ); + }); +}); diff --git a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/indemnite.js b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/indemnite.js new file mode 100644 index 0000000000..d69940b5bd --- /dev/null +++ b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/indemnite.js @@ -0,0 +1,125 @@ +import { sum, round } from "../../math"; +import { max, min, isAfter, differenceInMonths } from "date-fns"; +import { + CADRE, + NON_CADRE, + NE_SAIT_PAS, + DISCIPLINAIRE, + NON_DISCIPLINAIRE, + ECONOMIQUE +} from "./Step"; + +function getSalaireRef({ + hasTempsPartiel = false, + hasSameSalaire = false, + salaire, + salairePeriods, + salaires = [], + anciennete +}) { + const salaryValues = salaires.map(a => a.salary); + + // calcul du salaire de reference + if (hasTempsPartiel) { + return salairePeriods.reduce( + (salaire, period) => + salaire + + (parseInt(period.salary, 10) * parseInt(period.duration, 10)) / + 12 / + anciennete, + 0 + ); + } + return hasSameSalaire ? (12 / 13) * salaire : (1 / 13) * sum(salaryValues); +} + +function getIndemnite({ + salaireRef, + dateEntree, + dateSortie, + anciennete, + categorie = NON_CADRE, + motif +}) { + let indemniteConventionnelle = 0; + let formula = ""; + let error; + + if (anciennete < 1) { + return { + indemniteConventionnelle, + formula, + error: + "La convention collective prévoit une indemnité conventionnelle de licenciement à partir d'un an d'ancienneté" + }; + } + if (motif === DISCIPLINAIRE) { + return { + indemniteConventionnelle, + formula, + error: + "La convention collective prévoit le droit à l’indemnité légale en cas de licenciement pour motif disciplinaire, sauf pour faute grave ou lourde" + }; + } + const year2002 = new Date("2002-01-01"); + const nbSemestreAvant2002 = Math.floor( + differenceInMonths(year2002, min(year2002, dateEntree)) / 6 + ); + const nbSemestreApres2002 = Math.floor( + differenceInMonths(dateSortie, max(dateEntree, year2002)) / 6 + ); + + if (motif === NON_DISCIPLINAIRE) { + if (nbSemestreAvant2002 > 0) { + indemniteConventionnelle = + (1 / 2) * (13 / 14.5) * salaireRef * nbSemestreAvant2002; + formula = `1/2 * 13/14.5 * ${round(salaireRef)} * ${round( + nbSemestreAvant2002 + )} + `; + } + + indemniteConventionnelle += (1 / 5) * salaireRef * nbSemestreApres2002; + formula = `1/5 * ${round(salaireRef)} * ${round(nbSemestreApres2002)}`; + } else if (motif === ECONOMIQUE) { + if (nbSemestreAvant2002 > 0) { + indemniteConventionnelle = (1 / 2) * salaireRef * nbSemestreAvant2002; + formula = `1/2 * ${round(salaireRef)} * ${round(nbSemestreAvant2002)} + `; + } + indemniteConventionnelle += (1 / 4) * salaireRef * nbSemestreApres2002; + formula = `1/4 * ${round(salaireRef)} * ${round(nbSemestreApres2002)}`; + } + + const isEmbaucheAfter1999 = isAfter(dateEntree, new Date("1999-12-31")); + + if (isEmbaucheAfter1999) { + let plafond = { + [CADRE]: 24, + [NON_CADRE]: 18, + [NE_SAIT_PAS]: 18 + }; + indemniteConventionnelle = Math.min( + indemniteConventionnelle, + plafond[categorie] * (13 / 14.5) * salaireRef + ); + formula = `min(${formula}, ${plafond[categorie]} * (13 / 14.5) * ${round( + salaireRef + )})`; + } else { + const plafond = { + [ECONOMIQUE]: 18, + [NON_DISCIPLINAIRE]: 15 + }; + indemniteConventionnelle = Math.min( + indemniteConventionnelle, + plafond[motif] * salaireRef + ); + formula = `min(${formula}, ${plafond[motif]} * ${round(salaireRef)})`; + } + + return { + indemniteConventionnelle: round(indemniteConventionnelle), + formula, + error + }; +} +export { getSalaireRef, getIndemnite }; diff --git a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/index.js b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/index.js new file mode 100644 index 0000000000..2bb1640b0c --- /dev/null +++ b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/ccn/2120/index.js @@ -0,0 +1,16 @@ +import { Step } from "./Step"; +import { Result } from "./Result"; + +export const steps = [ + { + component: Step, + name: "branche_infos", + label: "Informations particulières", + condition: ({ inaptitude = false }) => inaptitude === false + }, + { + component: Result, + name: "branche_result", + label: "Indemnité conventionnelle" + } +]; diff --git a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/index.js b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/index.js index be4a1adce5..be048488c4 100644 --- a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/index.js +++ b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/index.js @@ -1,4 +1,4 @@ -import React, { useReducer } from "react"; +import React, { useReducer, useState } from "react"; import PropTypes from "prop-types"; import { OnChange } from "react-final-form-listeners"; import { Section, Container, Wrapper } from "@cdt/ui"; @@ -9,7 +9,7 @@ import { Wizard } from "./Wizard"; function CalculateurIndemnite() { const initialSteps = getInitialSteps(); const [steps, dispatch] = useReducer(StepReducer, initialSteps); - + const [values, setValues] = useState({}); /** * The rules defined here allows to manage additionnal steps to the form */ @@ -25,7 +25,10 @@ function CalculateurIndemnite() { {async value => { if (value) { const module = await import(`./ccn/${value}`); - dispatch({ type: "add_branche", payload: module.steps }); + const steps = module.steps.filter(({ condition = () => true }) => + condition(values) + ); + dispatch({ type: "add_branche", payload: steps }); } else { dispatch({ type: "remove_branche" }); } @@ -47,7 +50,12 @@ function CalculateurIndemnite() {

Calculateur d'indemnités de licenciement

- +
diff --git a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/steps/__tests__/__snapshots__/Indemnite.test.js.snap b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/steps/__tests__/__snapshots__/Indemnite.test.js.snap index 77f8e70851..55b4b0b3bf 100644 --- a/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/steps/__tests__/__snapshots__/Indemnite.test.js.snap +++ b/packages/code-du-travail-frontend/src/outils/indemniteLicenciement/steps/__tests__/__snapshots__/Indemnite.test.js.snap @@ -171,6 +171,11 @@ exports[` should render 1`] = ` > Convention collective nationale Boucherie boucherie-charcuterie triperie +