Feat: add individual percentage and individualize functions on months

This commit is contained in:
Bertrand Benjamin 2021-08-12 14:12:24 +02:00
parent db21bc1275
commit d690bcac56
7 changed files with 63 additions and 102 deletions

View File

@ -24,10 +24,11 @@
<script> <script>
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { caTotal, import {
caMean, ca,
remuneration, caPersoUntouch,
caPersoUntouch sum,
mean,
} from '../lib/months' } from '../lib/months'
import RevenusChart from '../components/graphs/RevenusChart.vue' import RevenusChart from '../components/graphs/RevenusChart.vue'
@ -40,16 +41,13 @@ export default {
return {} return {}
}, },
computed: { computed: {
...mapGetters('config', {
caProPercentage: 'caProPercentage',
}),
...mapGetters('travail', { ...mapGetters('travail', {
months: "months", months: "months",
}), }),
ca: function () {return caTotal(this.months).toLocaleString()}, ca: function () {return sum(Object.values(this.months).map(a => ca(a))).toLocaleString()},
caMean: function () {return caMean(this.months).toLocaleString()}, caMean: function () {return mean(Object.values(this.months).map(a => ca(a))).toLocaleString()},
remuneration: function () {return remuneration(this.months).toLocaleString()}, remuneration: function () {return sum(Object.values(this.months).map(a => a.remuneration)).toLocaleString()},
caPersoUntouch: function () {return caPersoUntouch(this.months, this.caProPercentage).toLocaleString()}, caPersoUntouch: function () {return sum(Object.values(this.months).map(a => caPersoUntouch(a))).toLocaleString()},
}, },
mounted () { mounted () {

View File

@ -25,9 +25,8 @@
<script> <script>
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { import {
caTheo, sum,
notInvoiced, notInvoiced,
retrocession,
} from '../lib/months' } from '../lib/months'
import RepartitionChart from './graphs/RepartitionChart.vue' import RepartitionChart from './graphs/RepartitionChart.vue'
@ -40,16 +39,12 @@ export default {
return {} return {}
}, },
computed: { computed: {
...mapGetters('config', {
caProPercentage: 'caProPercentage',
}),
...mapGetters('travail', { ...mapGetters('travail', {
months: "months", months: "months",
}), }),
caTheo: function () {return caTheo(this.months).toLocaleString()}, caTheo: function () {return sum(Object.values(this.months).map(a => a.caTheo)).toLocaleString()},
notInvoiced: function () {return notInvoiced(this.months).toLocaleString()}, retrocession: function () {return sum(Object.values(this.months).map(a => a.retro)).toLocaleString()},
retrocession: function () {return retrocession(this.months).toLocaleString()}, notInvoiced: function () {return sum(Object.values(this.months).map(a => notInvoiced(a))).toLocaleString()},
}, },
mounted () { mounted () {
}, },

View File

@ -10,9 +10,8 @@ import { mapGetters } from 'vuex'
import { import {
notInvoiced, notInvoiced,
caPro, caPro,
remuneration,
retrocession,
caPersoUntouch, caPersoUntouch,
sum,
} from '../../lib/months' } from '../../lib/months'
export default { export default {
@ -43,11 +42,11 @@ export default {
{ {
label: "Difference CA perso et remuneration", label: "Difference CA perso et remuneration",
data: [ data: [
caPro(this.months, this.caProPercentage), sum(Object.values(this.months).map(a => caPro(a))),
notInvoiced(this.months), sum(Object.values(this.months).map(a => notInvoiced(a))),
retrocession(this.months), sum(Object.values(this.months).map(a => a.retro)),
remuneration(this.months), sum(Object.values(this.months).map(a => a.remuneration)),
caPersoUntouch(this.months, this.caProPercentage), sum(Object.values(this.months).map(a => caPersoUntouch(a))),
], ],
}, },
], ],

View File

@ -7,7 +7,7 @@
<script> <script>
import Chart from 'chart.js' import Chart from 'chart.js'
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { monthCA, caPersoUntouch, caPerso, remuneration } from '../../lib/months' import { ca, caPersoUntouch, sum } from '../../lib/months'
export default { export default {
name: 'RevenusChart', name: 'RevenusChart',
@ -37,7 +37,7 @@ export default {
{ {
type: "bar", type: "bar",
label: "Difference CA perso et remuneration", label: "Difference CA perso et remuneration",
data: Object.values(this.months).map(a => caPerso({bar: a}, this.caProPercentage) - remuneration({bar:a})), data: Object.values(this.months).map(a => caPersoUntouch(a)),
backgroundColor: "red", backgroundColor: "red",
borderColor: "light-red", borderColor: "light-red",
borderWidth: 3 borderWidth: 3
@ -45,7 +45,7 @@ export default {
{ {
type: "bar", type: "bar",
label: "CA", label: "CA",
data: Object.values(this.months).map(a => monthCA(a)), data: Object.values(this.months).map(a => ca(a)),
backgroundColor: "rgba(54,73,93,.5)", backgroundColor: "rgba(54,73,93,.5)",
borderColor: "#36495d", borderColor: "#36495d",
borderWidth: 3 borderWidth: 3
@ -79,7 +79,9 @@ export default {
}, },
untouchEvo: function () { untouchEvo: function () {
const cumulativeArray = (arr => value => {arr.push(value); return [...arr];})([]); const cumulativeArray = (arr => value => {arr.push(value); return [...arr];})([]);
return Object.values(this.months).map(cumulativeArray).map(a => caPersoUntouch(a, this.caProPercentage)) return Object.values(this.months)
.map(cumulativeArray)
.map(a => sum(a.map(m => caPersoUntouch(m))))
}, },
}, },
methods: { methods: {

View File

@ -1,5 +1,5 @@
// Function on a month
export function monthCA(month) { export function ca(month) {
// Extract the CA of the month // Extract the CA of the month
if (month.caReact) { if (month.caReact) {
return month.caReact return month.caReact
@ -8,76 +8,37 @@ export function monthCA(month) {
} }
} }
export function count (months) { export function notInvoiced (month) {
// Count how many months there are // Compute how much has not been invoiced
return Object.keys(months).length return month.caTheo - ca(month)
} }
export function caTotal (months) { export function caPro (month) {
// Total CA (caReact if sets, caRetro otherwise) // Compute the part of the CA to go pro usage
return Object.values(months).map(a => monthCA(a)).reduce( return ca(month) * month.proPercentage
(acc, v) => acc + v
,0
)
} }
export function caMean (months) { export function caPerso (month) {
// Mean of CA // Compute the part of the CA to go personnal usage
return Math.floor(caTotal(months) / count(months)) return ca(month) * (1 - month.proPercentage)
} }
export function caTheo (months) { export function caPersoUntouch (month) {
// Total theorical CA // Compute the part of the CA to go personnal usage
return Object.values(months).map(a => a.caTheo).reduce( return caPerso(month) - month.remuneration
(acc, v) => acc + v,
0
)
} }
export function notInvoiced (months) {
// Total of not invoiced sessions // Function on an array of month
return caTheo(months) - caTotal(months)
export function sum (array) {
// sum the array
return array.reduce((acc, v)=> acc + v, 0)
} }
export function remuneration (months) { export function mean(array) {
// Total remuneration console.log(array)
return Object.values(months).map(a => a.remuneration).reduce( return Math.floor(array.reduce((acc, v)=> acc + v, 0) / array.length)
(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

@ -47,6 +47,12 @@ const config = {
type: 'base', type: 'base',
name: 'remu', name: 'remu',
}, },
{
color: '',
desc: 'Pourcentage du CA pour la partie pro',
type: 'base',
name: 'proPercentage',
},
], ],
} }
}, },

View File

@ -1,8 +1,8 @@
caTheo,sessionQty,caRetro,caReact,retro,remuneration,date caTheo,sessionQty,caRetro,caReact,retro,remuneration,date,proPercentage
7000,,6747,,893,2000,2021-01 7000,,6747,,893,2000,2021-01,0.5
5200,,5183,,665,1500,2021-02 5200,,5183,,665,1500,2021-02,0.5
7100,,7088,,855,2000,2021-03 7100,,7088,,855,2000,2021-03,0.5
5700,,4194,5630,627,2000,2021-04 5700,,4194,5630,627,2000,2021-04,0.5
6500,,5564,6335,699,2800,2021-05 6500,,5564,6335,699,2800,2021-05,0.5
6725,235,5442,6376,638,2800,2021-06 6725,235,5442,6376,638,2800,2021-06,0.5
2176,81,1274,,172,2000,2021-07 2176,81,1274,,172,2000,2021-07,0.5

1 caTheo sessionQty caRetro caReact retro remuneration date proPercentage
2 7000 6747 893 2000 2021-01 0.5
3 5200 5183 665 1500 2021-02 0.5
4 7100 7088 855 2000 2021-03 0.5
5 5700 4194 5630 627 2000 2021-04 0.5
6 6500 5564 6335 699 2800 2021-05 0.5
7 6725 235 5442 6376 638 2800 2021-06 0.5
8 2176 81 1274 172 2000 2021-07 0.5