import R from 'ramda' import React, { Component } from 'react' import { connect } from 'react-redux' import { withRouter } from 'react-router' import './Results.css' import '../engine/mecanismViews/Somme.css' import { humanFigure } from './rule/RuleValueVignette' import { capitalise0 } from '../utils' // Filtered variables and rules can't be filtered in a uniform way, for now let paidBy = which => R.pathEq(['explanation', 'cotisation', 'dû par'], which) let filteredBy = which => R.pathEq(['cotisation', 'dû par'], which) export let byName = branch => R.groupBy(R.prop('dottedName'), branch) export let cell = (branch, payer, analysis) => { let row = byBranch(analysis)[branch], items = R.filter( item => paidBy(payer)(item) || filteredBy(payer)(item), row ), values = R.map(R.prop('nodeValue'), items) return R.sum(values) } export let subCell = (row, name, payer) => { let cells = row[name], items = R.filter( item => paidBy(payer)(item) || filteredBy(payer)(item), cells ), values = R.map(R.prop('nodeValue'), items) return R.sum(values) } export let byBranch = analysis => { let sal = analysis.dict['contrat salarié . cotisations salariales'] let pat = analysis.dict['contrat salarié . cotisations patronales'] let l1 = sal ? sal.explanation.formule.explanation.explanation : [], l2 = pat ? pat.explanation.formule.explanation.explanation : [], explanations = R.concat(l1, l2), byBranch = R.groupBy( R.pathOr('autre', ['explanation', 'cotisation', 'branche']), explanations ) return byBranch } @withRouter @connect(state => ({ analysis: state.analysis, targetNames: state.targetNames, situationGate: state.situationGate })) export default class ResultsGrid extends Component { render() { let { analysis, situationGate } = this.props if (!analysis) return null let extract = x => (x && x.nodeValue) || 0, fromSituation = name => situationGate(name), fromEval = name => R.find(R.propEq('dottedName', name), analysis.targets), fromDict = name => analysis.dict[name], get = name => extract(fromSituation(name) || fromEval(name) || fromDict(name)) let results = byBranch(analysis), brut = get('contrat salarié . salaire brut'), net = get('contrat salarié . salaire net'), total = get('contrat salarié . salaire total') return (
{humanFigure(2)(brut)} (salaire brut) | {humanFigure(2)(brut)} (salaire brut) | |||
= | {humanFigure(2)(net)} (salaire net) | = | {humanFigure(2)(total)} (salaire total) |