Skip to content

Commit

Permalink
fix: prise en compte de la durée minimale indemnite à 8 mois (#259)
Browse files Browse the repository at this point in the history
* fix: gere la durée  minimun sur 8mois cf R12342

* update tests

* rebase fix

* update formula
  • Loading branch information
lionelB authored Nov 14, 2018
1 parent b677a35 commit 869f25e
Showing 9 changed files with 71 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ class Anciennete extends React.Component {
};

render() {
const { value, onChange, onNext, nextDisabled } = this.props;
const { value, onChange, onNext, onPrevious, nextDisabled } = this.props;
return (
<React.Fragment>
<Section light>
@@ -43,7 +43,11 @@ class Anciennete extends React.Component {
</React.Fragment>
</Section>
<Container>
<PrevNextStepper onNext={onNext} nextDisabled={nextDisabled} />
<PrevNextStepper
onPrevious={onPrevious}
onNext={onNext}
nextDisabled={nextDisabled}
/>
</Container>
</React.Fragment>
);
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ class DateFinContrat extends React.Component {
static propTypes = {
onChange: PropTypes.func.isRequired,
value: PropTypes.bool,
onPrevious: PropTypes.func.isRequired,
onNext: PropTypes.func.isRequired,
nextDisabled: PropTypes.bool
};
@@ -19,7 +18,7 @@ class DateFinContrat extends React.Component {
};

render() {
const { onChange, value, onPrevious, onNext, nextDisabled } = this.props;
const { onChange, value, onNext, nextDisabled } = this.props;
return (
<React.Fragment>
<Section light>
@@ -52,11 +51,7 @@ class DateFinContrat extends React.Component {
</React.Fragment>
</Section>
<Container>
<PrevNextStepper
onPrev={onPrevious}
onNext={onNext}
nextDisabled={nextDisabled}
/>
<PrevNextStepper onNext={onNext} nextDisabled={nextDisabled} />
</Container>
</React.Fragment>
);
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ const getJaxFormula = ({
// indemnite = 1 / 5 * c * 10 + 2 / 5 * c * d
return `(1/5 * ${round(meilleurMoyenne)} * 10) + (2/5 * ${round(
meilleurMoyenne
)} * (${Math.floor(anciennete / 12)} - 10))`;
)} * (${round(anciennete / 12)} - 10))`;
}
} else {
if (isSmallAnciennete) {
@@ -53,7 +53,7 @@ const getJaxFormula = ({
//indemnite = 1 / 4 * c * 10 + 1 / 3 * c * d
return `(1/4 * ${round(meilleurMoyenne)} * 10) + (1/3 * ${round(
meilleurMoyenne
)} * (${Math.floor(anciennete / 12)} - 10))`;
)} * (${round(anciennete / 12)} - 10))`;
}
}
};
@@ -104,21 +104,19 @@ class ResultDetail extends React.Component {
);
return (
<React.Fragment>
<div>
{indemnite > 0 && (
<Section light>
<div style={headStyle}>
<h2>Montant indicatif de votre indemnité</h2>
<h3 style={{ fontSize: "2rem" }}>{labelize(indemnite)}</h3>
<p>
<em>
Sur la base du calcul de l'indemnité légale de licenciement.
</em>
</p>
</div>
</Section>
)}
</div>
{indemnite > 0 && (
<Section light>
<div style={headStyle}>
<h2>Montant indicatif de votre indemnité</h2>
<h3 style={{ fontSize: "2rem" }}>{labelize(indemnite)}</h3>
<p>
<em>
Sur la base du calcul de l'indemnité légale de licenciement.
</em>
</p>
</div>
</Section>
)}
<Section light>
<React.Fragment>
<table width="100%" style={{ fontSize: "1.2em" }}>
@@ -129,7 +127,9 @@ class ResultDetail extends React.Component {
<Row value={labelize(moyenne3DerniersMois)}>
Moyenne des 3 derniers sois
</Row>
<Row value={labelize(meilleurMoyenne)}>Salaire retenu</Row>
<Row value={labelize(meilleurMoyenne)}>
Salaire de référence
</Row>
<Row value={isR12342 ? "1 / 5" : "1 / 4"}>{infoFinContrat}</Row>
<Row value={isSmallAnciennete ? "< 10 ans" : "> 10 ans"}>
Ancienneté
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@ class Salaire extends React.Component {
};

static defaultProps = {
value: Array.from({ length: 12 }, () => 0),
nextDisabled: false
};

@@ -105,7 +104,7 @@ class Salaire extends React.Component {
</tr>
</thead>
<tbody>
{times(12).map(i => (
{times(this.props.value.length).map(i => (
<tr key={i} style={{ background: i < 3 ? "#ddd" : "" }}>
<td>{i === 0 ? "Dernier salaire" : `Salaire N-${i}`}</td>
<td style={{ textAlign: "center" }}>
Original file line number Diff line number Diff line change
@@ -6,11 +6,11 @@ import { DateFinContrat } from "./DateFinContrat";
import { ChoixCC } from "./ChoixCCN";

export const steps = [
{ component: DateFinContrat, key: "isR12342", type: "base" },
{ component: Anciennete, key: "anciennete", type: "base" },
{ component: FauteGrave, key: "fauteGrave", type: "base" },
{ component: Salaire, key: "salaires", type: "base" },
{ component: Primes, key: "primes", type: "base" },
{ component: DateFinContrat, key: "isR12342", type: "base" },
{ component: ChoixCC, key: "convention", type: "base" }
];

Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ export function getIndemnite({
formula += `+ ${salaireRef}`;
if (hasOpe && isEco) {
indemniteCC += salaireRef;
formula = `* 2`;
formula += `* 2`;
}
}
// le salarié a entre 50 et 55ans
@@ -150,7 +150,7 @@ export function getIndemnite({
formula += ` + ${salaireRef}`;
if (hasOpe && isEco && age >= 50) {
indemniteCC += salaireRef;
formula = `* 2`;
formula += `* 2`;
}
}
// le salarié a plus de 55ans
Original file line number Diff line number Diff line change
@@ -13,22 +13,22 @@ const sum = arr => arr.reduce((sum, c) => sum + parseFloat(c), 0);

const getIndemnite = data => {
const {
isR12342,
salaires,
primes,
anciennete,
isR12342,
fauteGrave,
calculConvention
} = data;

// a) moyenne des douze derniers mois
// (a)=moyenne((mois1+prime)+(mois2+prime)... (mois 12+prime))
const moyenneSalaires =
(sum(salaires) + (primes || 0)) / salaires.length || 0;
// b) moyenne des 3 derniers mois
// (b)=moyenne((mois10+prime)+(mois11+prime)... (mois 12+prime))
const moyenne3DerniersMois =
(sum(salaires.filter((_, i) => i < 3)) + (primes / 12) * 3) / 3;
(sum(salaires.filter((_, i) => i < 3)) + (primes / salaires.length) * 3) /
3;
// si b>a, (c)=(b) sinon (c)=a
const meilleurMoyenne = Math.max(moyenneSalaires, moyenne3DerniersMois);

@@ -44,8 +44,8 @@ const getIndemnite = data => {
// Si ancienneté supérieur à 10 ans:
// indemnite = 1 / 5 * c * 10 + 2 / 5 * c * d
indemnite =
(1 / 5) * meilleurMoyenne * 10 +
(2 / 5) * meilleurMoyenne * (anciennete / 12 - 10);
((1 / 5) * meilleurMoyenne * anciennete) / 12 +
(2 / 15) * meilleurMoyenne * (anciennete / 12 - 10);
}
} else {
// Si "ancienneté inférieure ou égale à 10 ans
@@ -63,7 +63,7 @@ const getIndemnite = data => {

const errors = [];

if (anciennete < 12) {
if (anciennete < 12 && isR12342) {
errors.push({
type: "warning",
message:
@@ -72,6 +72,15 @@ const getIndemnite = data => {
indemnite = 0;
}

if (anciennete < 8 && !isR12342) {
errors.push({
type: "warning",
message:
"L'indemnité de licenciement est dûe au-delà de 8mois d'ancienneté."
});
indemnite = 0;
}

if (fauteGrave) {
indemnite = 0;
errors.push({
Original file line number Diff line number Diff line change
@@ -109,6 +109,16 @@ const tests = [
},
expected: 2256.9444444444443
},
{
title: "1500, 12ans 9mois, 2016-10-22",
data: {
salaires: Array.from({ length: 12 }).fill(1500),
primes: 0,
anciennete: 12 * 12 + 9,
isR12342: true
},
expected: 4375
},
{
title: "4k+4k, 25 ans, 2016-10-22",
data: {
@@ -117,7 +127,7 @@ const tests = [
anciennete: 25 * 12,
isR12342: true
},
expected: 34666.6666666666667
expected: 30333.333333333336
}
];
describe("getIndemnite", () => {
@@ -134,10 +144,19 @@ describe("getIndemnite", () => {
});
expect(res.indemnite).toEqual(0);
});
it("should return indemnite when anciennete >= 8", () => {
const res = getIndemnite({
...tests[0].data,
salaires: Array.from({ length: 12 }).fill(1500),
anciennete: 8
});
expect(res.indemnite).toEqual(250);
});
it("should return 0 when anciennete < 12", () => {
const res = getIndemnite({
...tests[0].data,
anciennete: 11
anciennete: 11,
isR12342: true
});
expect(res.indemnite).toEqual(0);
});
Original file line number Diff line number Diff line change
@@ -24,6 +24,11 @@ class CalculateurIndemnite extends React.Component {
this.setState({
[key]: value
});
if (key === "anciennete") {
this.setState({
salaires: Array.from({ length: Math.min(value, 12) }).fill(0)
});
}
if (key === "convention") {
if (value.hasCC) {
const { ccId } = value;

0 comments on commit 869f25e

Please sign in to comment.