Feat: functionnalize months calculus

This commit is contained in:
2021-08-09 14:43:24 +02:00
parent c47062ce86
commit 78bb4cb1ff
3 changed files with 103 additions and 78 deletions

View File

@@ -1,13 +1,6 @@
import { readFile } from 'fs'
import Papa from 'papaparse'
function monthCA(month) {
if (month.ca_react) {
return month.ca_react
} else {
return month.ca_retro
}
}
const travail = {
namespaced: true,
@@ -109,66 +102,6 @@ const travail = {
// Amount of mounts
return Object.keys(getters.months).length
},
ca: (state, getters) => {
// Total CA (ca_react if sets, ca_retro otherwise)
const a = Object.values(getters.months).map(a => monthCA(a)).reduce(
(acc, v) => acc + v
,0
)
return a
},
caMean: (state, getters) => {
// Mean of CA
if (getters.count > 0) {
return Math.floor(getters.ca / getters.count)
} else {
return "..."
}
},
caTheo: (state, getters) => {
// Total theorical CA
return Object.values(getters.months).map(a => a.ca_theo).reduce(
(acc, v) => acc + v,
0
)
},
remuneration: (state, getters) => {
// Total remuneration
return Object.values(getters.months).map(a => a.remuneration).reduce(
(acc, v) => acc + v,
0
)
},
remunerationMean: (state, getters) => {
// Mean of remuneration
return Math.floor(getters.remuneration / getters.count)
},
retrocession: (state, getters) => {
// Total retrocession
return Object.values(getters.months)
.map(a => a.retro)
.reduce(
(acc, v) => acc + v,
0
)
},
retrocessionMean: (state, getters) => {
// Mean of retrocession
return Math.floor(getters.retrocession / getters.count
)
},
caPro: (state, getters, rootState, rootGetters) => {
// Part of the CA to keep for professional use
return getters.ca * rootGetters['config/caProPercentage']
},
caPerso: (state, getters) => {
// Part of the CA to keep for personal use
return getters.ca - getters.caPro
},
caPersoUntouch: (state, getters) => {
// Part of the personnal use CA that haven't been use
return getters.caPerso - getters.remuneration
},
},
mutations: {
cleanMonths (state) {