Compare commits
2 Commits
5683b57e24
...
b266e9de9b
Author | SHA1 | Date | |
---|---|---|---|
b266e9de9b | |||
4d77e61b25 |
@ -4,12 +4,12 @@
|
|||||||
<h2>Période</h2>
|
<h2>Période</h2>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<input type="month" v-model="range.start">
|
<input type="month" @input="updateStart" v-model="start">
|
||||||
<input type="month" v-model="range.end">
|
<input type="month" @input="updateEnd" v-model="end">
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<button @click="setRange6months" :active='selected=="month"'>6 mois</button>
|
<button @click="setRangeFromJanuary" :active='selected=="january"'>Depuis le début de l'année</button>
|
||||||
<button @click="setRange1year" :active='selected=="year"'>1 an</button>
|
<button @click="setRange1year" :active='selected=="year"'>Sur 1 an</button>
|
||||||
<button @click="setRangeAll" :active='selected=="all"'>Tout</button>
|
<button @click="setRangeAll" :active='selected=="all"'>Tout</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -19,7 +19,7 @@
|
|||||||
<script>
|
<script>
|
||||||
|
|
||||||
import { mapGetters, mapActions } from 'vuex'
|
import { mapGetters, mapActions } from 'vuex'
|
||||||
import { addMonths, format, parseISO } from 'date-fns'
|
import { setMonth, addMonths, format, parseISO } from 'date-fns'
|
||||||
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
|
|
||||||
@ -30,25 +30,46 @@ export default {
|
|||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
selected: "",
|
selected: "",
|
||||||
|
start: "",
|
||||||
|
end: "",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters('travail', {
|
...mapGetters('travail', {
|
||||||
range: "Range",
|
range: "range",
|
||||||
monthsDate: "MonthsDate",
|
monthsDate: "MonthsDate",
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
range: function (newRange, oldRange) {
|
||||||
|
this.start = this.range.start
|
||||||
|
this.end = this.range.end
|
||||||
|
},
|
||||||
|
},
|
||||||
|
mounted () {
|
||||||
|
this.setRangeFromJanuary()
|
||||||
|
this.start = this.range.start
|
||||||
|
this.end = this.range.end
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions('travail', {
|
...mapActions('travail', {
|
||||||
setRange: "setRange",
|
setRange: "setRange",
|
||||||
}),
|
}),
|
||||||
setRange6months: function () {
|
updateStart: function () {
|
||||||
const start = addMonths(new Date(), -6)
|
this.selected = "custom"
|
||||||
|
this.setRange({start: this.start, end: this.end})
|
||||||
|
},
|
||||||
|
updateEnd: function () {
|
||||||
|
this.selected = "custom"
|
||||||
|
this.setRange({start: this.start, end: this.end})
|
||||||
|
},
|
||||||
|
setRangeFromJanuary: function () {
|
||||||
|
const start = setMonth(today, 0)
|
||||||
const range = {
|
const range = {
|
||||||
start: format(start, 'yyyy-MM'),
|
start: format(start, 'yyyy-MM'),
|
||||||
end: format(today, 'yyyy-MM'),
|
end: format(today, 'yyyy-MM'),
|
||||||
}
|
}
|
||||||
this.selected = "month"
|
this.selected = "january"
|
||||||
this.setRange(range)
|
this.setRange(range)
|
||||||
},
|
},
|
||||||
setRange1year: function () {
|
setRange1year: function () {
|
||||||
@ -111,5 +132,4 @@ button {
|
|||||||
background-color: white;
|
background-color: white;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
@ -76,7 +76,7 @@ const travail = {
|
|||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
TheEmptyMonth(state) { return { ...state.empty } },
|
TheEmptyMonth(state) { return { ...state.empty } },
|
||||||
Range(state) { return state.range },
|
range(state) { return state.range },
|
||||||
MonthsDate(state) {
|
MonthsDate(state) {
|
||||||
// Get months inside the range
|
// Get months inside the range
|
||||||
return Object.keys(state.months).filter(date => (date >= state.range.start) && (date <= state.range.end)).sort().reverse()
|
return Object.keys(state.months).filter(date => (date >= state.range.start) && (date <= state.range.end)).sort().reverse()
|
||||||
@ -101,9 +101,9 @@ const travail = {
|
|||||||
// Amount of mounts
|
// Amount of mounts
|
||||||
return Object.keys(getters.months).length
|
return Object.keys(getters.months).length
|
||||||
},
|
},
|
||||||
ca: (state) => {
|
ca: (state, getters) => {
|
||||||
// Total CA (ca_react if sets, ca_retro otherwise)
|
// Total CA (ca_react if sets, ca_retro otherwise)
|
||||||
return Object.values(state.months).map(a => monthCA(a)).reduce(
|
return Object.values(getters.months).map(a => monthCA(a)).reduce(
|
||||||
(acc, v) => acc + v,
|
(acc, v) => acc + v,
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
@ -115,30 +115,30 @@ const travail = {
|
|||||||
0
|
0
|
||||||
) / getters.count)
|
) / getters.count)
|
||||||
},
|
},
|
||||||
caTheo: (state) => {
|
caTheo: (state, getters) => {
|
||||||
// Total theorical CA
|
// Total theorical CA
|
||||||
return Object.values(state.months).map(a => a.ca_theo).reduce(
|
return Object.values(getters.months).map(a => a.ca_theo).reduce(
|
||||||
(acc, v) => acc + v,
|
(acc, v) => acc + v,
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
remuneration: (state) => {
|
remuneration: (state, getters) => {
|
||||||
// Total remuneration
|
// Total remuneration
|
||||||
return Object.values(state.months).map(a => a.remuneration).reduce(
|
return Object.values(getters.months).map(a => a.remuneration).reduce(
|
||||||
(acc, v) => acc + v,
|
(acc, v) => acc + v,
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
remunerationMean: (state, getters) => {
|
remunerationMean: (state, getters) => {
|
||||||
// Mean of remuneration
|
// Mean of remuneration
|
||||||
return Math.floor(Object.values(state.months).map(a => a.remuneration).reduce(
|
return Math.floor(Object.values(getters.months).map(a => a.remuneration).reduce(
|
||||||
(acc, v) => acc + v,
|
(acc, v) => acc + v,
|
||||||
0
|
0
|
||||||
) / getters.count)
|
) / getters.count)
|
||||||
},
|
},
|
||||||
retrocession: (state) => {
|
retrocession: (state, getters) => {
|
||||||
// Total retrocession
|
// Total retrocession
|
||||||
return Object.values(state.months)
|
return Object.values(getters.months)
|
||||||
.map(a => a.retro)
|
.map(a => a.retro)
|
||||||
.reduce(
|
.reduce(
|
||||||
(acc, v) => acc + v,
|
(acc, v) => acc + v,
|
||||||
@ -148,7 +148,7 @@ const travail = {
|
|||||||
retrocessionMean: (state, getters) => {
|
retrocessionMean: (state, getters) => {
|
||||||
// Mean of retrocession
|
// Mean of retrocession
|
||||||
return Math.floor(
|
return Math.floor(
|
||||||
Object.values(state.months)
|
Object.values(getters.months)
|
||||||
.map(a => a.retro)
|
.map(a => a.retro)
|
||||||
.reduce(
|
.reduce(
|
||||||
(acc, v) => acc + v,
|
(acc, v) => acc + v,
|
||||||
|
Loading…
Reference in New Issue
Block a user