Skip to content

Commit

Permalink
fix(indemnite-licenciement): retours de la cc 1516 (#5392)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr authored Oct 19, 2023
1 parent 88ead81 commit c674b32
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Seniority1483,
Seniority1486,
Seniority1505,
Seniority1516,
Seniority1517,
Seniority1518,
Seniority1527,
Expand Down Expand Up @@ -75,6 +76,8 @@ export class SeniorityFactory {
return new Seniority2609();
case SupportedCcIndemniteLicenciement.IDCC413:
return new Seniority413() as ISeniority<T>;
case SupportedCcIndemniteLicenciement.IDCC1516:
return new Seniority1516();
case SupportedCcIndemniteLicenciement.IDCC1517:
return new Seniority1517();
case SupportedCcIndemniteLicenciement.IDCC2614:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
MotifKeys,
SeniorityFactory,
SupportedCcIndemniteLicenciement,
} from "../../../../common";

describe("CC 1516", () => {
describe("Calcul de l'ancienneté", () => {
test.each`
absences | entryDate | exitDate | expectedAnciennete
${[]} | ${"01/01/2020"} | ${"01/01/2021"} | ${1}
${[{ motif: { key: MotifKeys.maladieNonPro } }, { motif: { key: MotifKeys.accidentTrajet } }, { motif: { key: MotifKeys.congesSabbatique } }, { motif: { key: MotifKeys.congesCreationEntreprise } }, { motif: { key: MotifKeys.congesParentalEducation } }, { motif: { key: MotifKeys.congesSansSolde } }, { motif: { key: MotifKeys.greve } }, { motif: { key: MotifKeys.miseAPied } }]} | ${"20/03/2020"} | ${"20/03/2021"} | ${1}
${[{ durationInMonth: "1", motif: { key: MotifKeys.maladieNonPro } }, { durationInMonth: "1", motif: { key: MotifKeys.accidentTrajet } }, { durationInMonth: "1", motif: { key: MotifKeys.congesSabbatique } }, { durationInMonth: "1", motif: { key: MotifKeys.congesCreationEntreprise } }, { durationInMonth: "1", motif: { key: MotifKeys.congesParentalEducation } }, { durationInMonth: "1", motif: { key: MotifKeys.congesSansSolde } }, { durationInMonth: "1", motif: { key: MotifKeys.greve } }, { durationInMonth: "1", motif: { key: MotifKeys.miseAPied } }]} | ${"01/01/2000"} | ${"01/01/2023"} | ${22.416666666666668}
${[{ durationInMonth: "1", motif: { key: MotifKeys.maladieNonPro } }, { durationInMonth: "1", motif: { key: MotifKeys.accidentTrajet } }, { durationInMonth: "1", motif: { key: MotifKeys.congesSabbatique } }, { durationInMonth: "1", motif: { key: MotifKeys.congesCreationEntreprise } }, { durationInMonth: "35", motif: { key: MotifKeys.congesParentalEducation } }, { durationInMonth: "1", motif: { key: MotifKeys.congesSansSolde } }, { durationInMonth: "1", motif: { key: MotifKeys.greve } }, { durationInMonth: "1", motif: { key: MotifKeys.miseAPied } }]} | ${"01/01/2000"} | ${"01/01/2023"} | ${22.416666666666668}
${[{ durationInMonth: "1", motif: { key: MotifKeys.maladieNonPro } }, { durationInMonth: "1", motif: { key: MotifKeys.accidentTrajet } }, { durationInMonth: "1", motif: { key: MotifKeys.congesSabbatique } }, { durationInMonth: "1", motif: { key: MotifKeys.congesCreationEntreprise } }, { durationInMonth: "36", motif: { key: MotifKeys.congesParentalEducation } }, { durationInMonth: "1", motif: { key: MotifKeys.congesSansSolde } }, { durationInMonth: "1", motif: { key: MotifKeys.greve } }, { durationInMonth: "1", motif: { key: MotifKeys.miseAPied } }]} | ${"01/01/2000"} | ${"01/01/2023"} | ${22.416666666666668}
${[{ durationInMonth: "1", motif: { key: MotifKeys.maladieNonPro } }, { durationInMonth: "1", motif: { key: MotifKeys.accidentTrajet } }, { durationInMonth: "1", motif: { key: MotifKeys.congesSabbatique } }, { durationInMonth: "1", motif: { key: MotifKeys.congesCreationEntreprise } }, { durationInMonth: "18", motif: { key: MotifKeys.congesParentalEducation } }, { durationInMonth: "18", motif: { key: MotifKeys.congesParentalEducation } }, { durationInMonth: "1", motif: { key: MotifKeys.congesSansSolde } }, { durationInMonth: "1", motif: { key: MotifKeys.greve } }, { durationInMonth: "1", motif: { key: MotifKeys.miseAPied } }]} | ${"01/01/2000"} | ${"01/01/2023"} | ${22.416666666666668}
${[{ durationInMonth: "1", motif: { key: MotifKeys.maladieNonPro } }, { durationInMonth: "1", motif: { key: MotifKeys.accidentTrajet } }, { durationInMonth: "1", motif: { key: MotifKeys.congesSabbatique } }, { durationInMonth: "1", motif: { key: MotifKeys.congesCreationEntreprise } }, { durationInMonth: "37", motif: { key: MotifKeys.congesParentalEducation } }, { durationInMonth: "1", motif: { key: MotifKeys.congesSansSolde } }, { durationInMonth: "1", motif: { key: MotifKeys.greve } }, { durationInMonth: "1", motif: { key: MotifKeys.miseAPied } }]} | ${"01/01/2000"} | ${"01/01/2023"} | ${22.375}
${[{ durationInMonth: "1", motif: { key: MotifKeys.maladieNonPro } }, { durationInMonth: "1", motif: { key: MotifKeys.accidentTrajet } }, { durationInMonth: "1", motif: { key: MotifKeys.congesSabbatique } }, { durationInMonth: "1", motif: { key: MotifKeys.congesCreationEntreprise } }, { durationInMonth: "18", motif: { key: MotifKeys.congesParentalEducation } }, { durationInMonth: "19", motif: { key: MotifKeys.congesParentalEducation } }, { durationInMonth: "1", motif: { key: MotifKeys.congesSansSolde } }, { durationInMonth: "1", motif: { key: MotifKeys.greve } }, { durationInMonth: "1", motif: { key: MotifKeys.miseAPied } }]} | ${"01/01/2000"} | ${"01/01/2023"} | ${22.375}
`(
"Calcul de l'ancienneté avec $entryDate et $exitDate en attendant $expectedAnciennete an",
({ absences, entryDate, exitDate, expectedAnciennete }) => {
const seniority = new SeniorityFactory().create(
SupportedCcIndemniteLicenciement.IDCC1516
);

const result = seniority.computeSeniority({
absencePeriods: absences,
dateEntree: entryDate,
dateSortie: exitDate,
});

expect(result.value).toEqual(expectedAnciennete);
}
);
});
});
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./salary";
export * from "./seniority";
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { addDays, differenceInMonths } from "date-fns";

import { LEGAL_MOTIFS } from "../../base";
import type {
Absence,
DefaultSeniorityRequiredProps,
ISeniority,
Motif,
RequiredSeniorityResult,
SeniorityProps,
SeniorityResult,
SupportedCcIndemniteLicenciement,
} from "../../common";
import { MotifKeys, parseDate } from "../../common";

export class Seniority1516
implements ISeniority<SupportedCcIndemniteLicenciement.IDCC1516>
{
getMotifs(): Motif[] {
return LEGAL_MOTIFS;
}

computeSeniority({
dateEntree,
dateSortie,
absencePeriods = [],
}: SeniorityProps<SupportedCcIndemniteLicenciement.IDCC1516>): SeniorityResult {
return this.compute(dateEntree, dateSortie, absencePeriods);
}

computeRequiredSeniority({
dateEntree,
dateNotification,
absencePeriods = [],
}: DefaultSeniorityRequiredProps): RequiredSeniorityResult {
return this.compute(dateEntree, dateNotification, absencePeriods);
}

protected compute(
from: string,
to: string,
absences: Absence[]
): SeniorityResult {
const dEntree = parseDate(from);
const dSortie = addDays(parseDate(to), 1);
const MAXIMUM_CONGES_PARENTAL_EN_MOIS = 36;
const totalAbsenceSansCongesParental = absences
.filter((period) => Boolean(period.durationInMonth))
.reduce((total, item) => {
const m = this.getMotifs().find(
(motif) => motif.key === item.motif.key
);
if (
!m ||
!item.durationInMonth ||
m.key === MotifKeys.congesParentalEducation
) {
return total;
}
return total + item.durationInMonth * m.value;
}, 0);
const totalAbsenceAvecCongesParentalSansCoeff = absences
.filter((period) => Boolean(period.durationInMonth))
.reduce((total, item: any) => {
const m = this.getMotifs().find(
(motif) => motif.key === item.motif.key
);
if (
!m ||
!item.durationInMonth ||
m.key !== MotifKeys.congesParentalEducation
) {
return total;
}
return total + parseInt(item.durationInMonth);
}, 0);
const congesMotif = this.getMotifs().find(
(motif) => motif.key === MotifKeys.congesParentalEducation
);
if (!congesMotif) {
throw new Error("Motif congé parental non trouvé");
}

const totalCongesParental =
totalAbsenceAvecCongesParentalSansCoeff >= MAXIMUM_CONGES_PARENTAL_EN_MOIS
? (totalAbsenceAvecCongesParentalSansCoeff -
MAXIMUM_CONGES_PARENTAL_EN_MOIS) *
congesMotif.value
: 0;
const totalAbsence = totalCongesParental + totalAbsenceSansCongesParental;
return {
value: (differenceInMonths(dSortie, dEntree) - totalAbsence) / 12,
};
}
}

0 comments on commit c674b32

Please sign in to comment.