🔥 Réecrit la logique de PaySlip

pull/1312/head
Johan Girod 2020-12-16 17:50:54 +01:00
parent 44058b3bda
commit 300e0c587e
1 changed files with 12 additions and 8 deletions

View File

@ -181,7 +181,7 @@ export default function PaySlip() {
function findReferenceInNode(
dottedName: DottedName,
node: EvaluatedNode
node: ASTNode
): EvaluatedNode | null {
return reduceAST<(EvaluatedNode & { nodeKind: 'reference' }) | null>(
(acc, node) => {
@ -201,16 +201,20 @@ function findReferenceInNode(
function Cotisation({ dottedName }: { dottedName: DottedName }) {
const language = useTranslation().i18n.language
const engine = useContext(EngineContext)
const cotisationsSalariales = engine.evaluate(
engine.getRule('contrat salarié . cotisations . salariales')
const partSalariale = engine.evaluate(
findReferenceInNode(
dottedName,
engine.getRule('contrat salarié . cotisations . salariales')
) ?? '0'
)
const cotisationsPatronales = engine.evaluate(
engine.getRule('contrat salarié . cotisations . patronales')
const partPatronale = engine.evaluate(
findReferenceInNode(
dottedName,
engine.getRule('contrat salarié . cotisations . patronales')
) ?? '0'
)
const partSalariale = findReferenceInNode(dottedName, cotisationsSalariales)
const partPatronale = findReferenceInNode(dottedName, cotisationsPatronales)
if (!partPatronale?.nodeValue && !partSalariale?.nodeValue) {
if (!partPatronale.nodeValue && !partSalariale.nodeValue) {
return null
}
return (