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

View File

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

View File

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

View File

@ -7,7 +7,7 @@
<script>
import Chart from 'chart.js'
import { mapGetters } from 'vuex'
import { monthCA, caPersoUntouch, caPerso, remuneration } from '../../lib/months'
import { ca, caPersoUntouch, sum } from '../../lib/months'
export default {
name: 'RevenusChart',
@ -37,7 +37,7 @@ export default {
{
type: "bar",
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",
borderColor: "light-red",
borderWidth: 3
@ -45,7 +45,7 @@ export default {
{
type: "bar",
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)",
borderColor: "#36495d",
borderWidth: 3
@ -79,7 +79,9 @@ export default {
},
untouchEvo: function () {
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: {

View File

@ -1,5 +1,5 @@
export function monthCA(month) {
// Function on a month
export function ca(month) {
// Extract the CA of the month
if (month.caReact) {
return month.caReact
@ -8,76 +8,37 @@ export function monthCA(month) {
}
}
export function count (months) {
// Count how many months there are
return Object.keys(months).length
export function notInvoiced (month) {
// Compute how much has not been invoiced
return month.caTheo - ca(month)
}
export function caTotal (months) {
// Total CA (caReact if sets, caRetro otherwise)
return Object.values(months).map(a => monthCA(a)).reduce(
(acc, v) => acc + v
,0
)
export function caPro (month) {
// Compute the part of the CA to go pro usage
return ca(month) * month.proPercentage
}
export function caMean (months) {
// Mean of CA
return Math.floor(caTotal(months) / count(months))
export function caPerso (month) {
// Compute the part of the CA to go personnal usage
return ca(month) * (1 - month.proPercentage)
}
export function caTheo (months) {
// Total theorical CA
return Object.values(months).map(a => a.caTheo).reduce(
(acc, v) => acc + v,
0
)
export function caPersoUntouch (month) {
// Compute the part of the CA to go personnal usage
return caPerso(month) - month.remuneration
}
export function notInvoiced (months) {
// Total of not invoiced sessions
return caTheo(months) - caTotal(months)
// Function on an array of month
export function sum (array) {
// sum the array
return array.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 mean(array) {
console.log(array)
return Math.floor(array.reduce((acc, v)=> acc + v, 0) / array.length)
}
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',
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
7000,,6747,,893,2000,2021-01
5200,,5183,,665,1500,2021-02
7100,,7088,,855,2000,2021-03
5700,,4194,5630,627,2000,2021-04
6500,,5564,6335,699,2800,2021-05
6725,235,5442,6376,638,2800,2021-06
2176,81,1274,,172,2000,2021-07
caTheo,sessionQty,caRetro,caReact,retro,remuneration,date,proPercentage
7000,,6747,,893,2000,2021-01,0.5
5200,,5183,,665,1500,2021-02,0.5
7100,,7088,,855,2000,2021-03,0.5
5700,,4194,5630,627,2000,2021-04,0.5
6500,,5564,6335,699,2800,2021-05,0.5
6725,235,5442,6376,638,2800,2021-06,0.5
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