2020-05-08 10:04:00 +00:00
|
|
|
import { Leaf } from './components/mecanisms/common'
|
|
|
|
import parseRule from './parseRule'
|
2020-03-26 15:03:19 +00:00
|
|
|
import { disambiguateRuleReference } from './ruleUtils'
|
2019-11-11 18:06:49 +00:00
|
|
|
|
2020-09-09 11:31:34 +00:00
|
|
|
export const parseReference = (
|
2019-11-04 13:07:19 +00:00
|
|
|
rules,
|
|
|
|
rule,
|
|
|
|
parsedRules,
|
|
|
|
filter
|
|
|
|
) => partialReference => {
|
2020-09-09 11:31:34 +00:00
|
|
|
const dottedName = disambiguateRuleReference(
|
2020-03-26 15:03:19 +00:00
|
|
|
rules,
|
|
|
|
rule.dottedName,
|
|
|
|
partialReference
|
|
|
|
)
|
2019-10-30 15:52:51 +00:00
|
|
|
|
2020-09-09 11:31:34 +00:00
|
|
|
const inInversionFormula = rule.formule?.['inversion numérique']
|
2019-10-30 15:52:51 +00:00
|
|
|
|
2020-09-09 11:31:34 +00:00
|
|
|
const parsedRule =
|
2019-10-30 15:52:51 +00:00
|
|
|
parsedRules[dottedName] ||
|
2020-11-11 16:36:29 +00:00
|
|
|
// TODO: The 'inversion numérique' formula should not exist. The instructions to
|
|
|
|
// the evaluation should be enough to infer that an inversion is necessary
|
|
|
|
// (assuming it is possible, the client decides this) #767
|
2020-03-26 15:03:19 +00:00
|
|
|
(!inInversionFormula && parseRule(rules, dottedName, parsedRules))
|
2020-11-11 16:36:29 +00:00
|
|
|
|
|
|
|
const contextRuleName = rule.dottedName
|
|
|
|
if (
|
|
|
|
// TODO: At this point in the code, the parsedRule value should never be the
|
|
|
|
// string "being parsed", this is a ordering problem.
|
|
|
|
parsedRule !== 'being parsed' &&
|
|
|
|
parsedRule !== false &&
|
|
|
|
rule.dottedName &&
|
|
|
|
!contextRuleName.startsWith('[evaluation]')
|
|
|
|
) {
|
|
|
|
rule.dependencies?.add(dottedName)
|
|
|
|
}
|
|
|
|
|
2020-04-23 07:30:03 +00:00
|
|
|
const unit = parsedRule.unit
|
2018-06-19 08:25:53 +00:00
|
|
|
return {
|
2020-10-19 15:25:12 +00:00
|
|
|
nodeKind: 'reference',
|
2020-09-09 11:31:34 +00:00
|
|
|
jsx: Leaf,
|
2019-06-13 16:17:22 +00:00
|
|
|
name: partialReference,
|
2019-07-01 15:59:57 +00:00
|
|
|
category: 'reference',
|
2019-10-30 15:52:51 +00:00
|
|
|
partialReference,
|
2019-06-19 09:54:47 +00:00
|
|
|
dottedName,
|
2020-11-11 16:36:29 +00:00
|
|
|
explanation: { ...parsedRule, filter, contextRuleName },
|
2019-11-28 11:03:23 +00:00
|
|
|
unit
|
2018-06-19 08:25:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-28 15:31:50 +00:00
|
|
|
type parseReferenceTransformsParameters = {
|
|
|
|
variable: { fragments: Array<string> }
|
|
|
|
filter?: string
|
|
|
|
unit?: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export const parseReferenceTransforms = (rules, rule, parsedRules) => ({
|
|
|
|
variable,
|
|
|
|
filter,
|
|
|
|
unit
|
|
|
|
}: parseReferenceTransformsParameters) => {
|
|
|
|
const originalNode = parseReference(
|
2019-11-28 11:03:23 +00:00
|
|
|
rules,
|
|
|
|
rule,
|
|
|
|
parsedRules,
|
2020-09-28 15:31:50 +00:00
|
|
|
filter
|
2020-11-05 16:48:19 +00:00
|
|
|
)(variable)
|
2018-06-19 08:25:53 +00:00
|
|
|
|
|
|
|
return {
|
2020-09-28 15:31:50 +00:00
|
|
|
...originalNode,
|
2020-10-19 15:25:12 +00:00
|
|
|
nodeKind: 'referenceWithTransforms',
|
2020-09-28 15:31:50 +00:00
|
|
|
explanation: {
|
|
|
|
originalNode,
|
|
|
|
filter,
|
|
|
|
unit
|
|
|
|
},
|
2018-10-01 15:41:55 +00:00
|
|
|
// Decorate node with the composante filter (either who is paying, either tax free)
|
2020-09-28 15:31:50 +00:00
|
|
|
...(filter
|
2018-10-01 15:41:55 +00:00
|
|
|
? {
|
2019-11-04 13:07:19 +00:00
|
|
|
cotisation: {
|
2020-09-28 15:31:50 +00:00
|
|
|
...(originalNode as any).cotisation,
|
|
|
|
'dû par': filter,
|
|
|
|
'impôt sur le revenu': filter
|
2019-11-04 13:07:19 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-01 15:41:55 +00:00
|
|
|
: {}),
|
2020-09-28 15:31:50 +00:00
|
|
|
unit: unit || originalNode.unit
|
2018-06-19 08:25:53 +00:00
|
|
|
}
|
|
|
|
}
|