export function monthCA(month) { // Extract the CA of the month if (month.ca_react) { return month.ca_react } else { return month.ca_retro } } export function count (months) { // Count how many months there are return Object.keys(months).length } export function caTotal (months) { // Total CA (ca_react if sets, ca_retro otherwise) return Object.values(months).map(a => monthCA(a)).reduce( (acc, v) => acc + v ,0 ) } export function caMean (months) { return caTotal(months) / count(months) } export function caTheo (months) { // Total theorical CA return Object.values(months).map(a => a.ca_theo).reduce( (acc, v) => acc + v, 0 ) } export function remuneration (months) { // Total remuneration return Object.values(months).map(a => a.remuneration).reduce( (acc, v) => acc + v, 0 ) } export function remunerationMean (months) { // Mean of remuneration return Math.floor(remuneration(months) / count(months)) } export function retrocession (months) { // Total retrocession return Object.values(months) .map(a => a.retro) .reduce( (acc, v) => acc + v, 0 ) } export function retrocessionMean (months) { // Mean of retrocession return Math.floor(retrocession(months) / count(months)) } export function caPro (months, keepPercent) { // Part of the CA to keep for professional use return caTotal(months) * keepPercent } export function caPerso (months, keepPercent) { // Part of the CA to keep for personal use return caTotal(months) - caPro(months, keepPercent) } export function caPersoUntouch (months, keepPercent) { // Part of the personnal use CA that haven't been use return caPerso(months, keepPercent) - remuneration(months) }