Feat: functionnalize months calculus

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

View File

@ -71,6 +71,18 @@
<script> <script>
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { caTotal,
caMean,
caTheo,
remuneration,
remunerationMean,
retrocession,
retrocessionMean,
caPro,
caPerso,
caPersoUntouch
} from '../lib/months'
export default { export default {
name: 'Hightlights', name: 'Hightlights',
components: { components: {
@ -83,17 +95,19 @@ export default {
caProPercentage: 'caProPercentage', caProPercentage: 'caProPercentage',
}), }),
...mapGetters('travail', { ...mapGetters('travail', {
ca: "ca", months: "months",
caMean: "caMean", }),
caTheo: "caTheo", ca: function () {return caTotal(this.months)},
remuneration: "remuneration", caMean: function () {return caMean(this.months)},
remunerationMean: "remunerationMean", caTheo: function () {return caTheo(this.months)},
retrocession: "retrocession", remuneration: function () {return remuneration(this.months)},
retrocessionMean: "retrocessionMean", remunerationMean: function () {return remunerationMean(this.months)},
caPro: "caPro", retrocession: function () {return retrocession(this.months)},
caPerso: "caPerso", retrocessionMean: function () {return retrocessionMean(this.months)},
caPersoUntouch: "caPersoUntouch", caPro: function () {return caPro(this.months, this.caProPercentage)},
}) caPerso: function () {return caPerso(this.months, this.caProPercentage)},
caPersoUntouch: function () {return caPersoUntouch(this.months, this.caProPercentage)},
}, },
mounted () { mounted () {
}, },

78
src/lib/months.js Normal file
View File

@ -0,0 +1,78 @@
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)
}

View File

@ -1,13 +1,6 @@
import { readFile } from 'fs' import { readFile } from 'fs'
import Papa from 'papaparse' import Papa from 'papaparse'
function monthCA(month) {
if (month.ca_react) {
return month.ca_react
} else {
return month.ca_retro
}
}
const travail = { const travail = {
namespaced: true, namespaced: true,
@ -109,66 +102,6 @@ const travail = {
// Amount of mounts // Amount of mounts
return Object.keys(getters.months).length 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: { mutations: {
cleanMonths (state) { cleanMonths (state) {