Feat: functionnalize months calculus
This commit is contained in:
parent
c47062ce86
commit
78bb4cb1ff
@ -71,6 +71,18 @@
|
||||
|
||||
<script>
|
||||
import { mapGetters } from 'vuex'
|
||||
import { caTotal,
|
||||
caMean,
|
||||
caTheo,
|
||||
remuneration,
|
||||
remunerationMean,
|
||||
retrocession,
|
||||
retrocessionMean,
|
||||
caPro,
|
||||
caPerso,
|
||||
caPersoUntouch
|
||||
} from '../lib/months'
|
||||
|
||||
export default {
|
||||
name: 'Hightlights',
|
||||
components: {
|
||||
@ -83,17 +95,19 @@ export default {
|
||||
caProPercentage: 'caProPercentage',
|
||||
}),
|
||||
...mapGetters('travail', {
|
||||
ca: "ca",
|
||||
caMean: "caMean",
|
||||
caTheo: "caTheo",
|
||||
remuneration: "remuneration",
|
||||
remunerationMean: "remunerationMean",
|
||||
retrocession: "retrocession",
|
||||
retrocessionMean: "retrocessionMean",
|
||||
caPro: "caPro",
|
||||
caPerso: "caPerso",
|
||||
caPersoUntouch: "caPersoUntouch",
|
||||
})
|
||||
months: "months",
|
||||
}),
|
||||
ca: function () {return caTotal(this.months)},
|
||||
caMean: function () {return caMean(this.months)},
|
||||
caTheo: function () {return caTheo(this.months)},
|
||||
remuneration: function () {return remuneration(this.months)},
|
||||
remunerationMean: function () {return remunerationMean(this.months)},
|
||||
retrocession: function () {return retrocession(this.months)},
|
||||
retrocessionMean: function () {return retrocessionMean(this.months)},
|
||||
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 () {
|
||||
},
|
||||
|
78
src/lib/months.js
Normal file
78
src/lib/months.js
Normal 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)
|
||||
}
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user