Sousmargot/src/store/config/index.js

111 lines
3.7 KiB
JavaScript

import path from 'path'
import Papa from 'papaparse'
import { writeFile } from 'fs'
const config = {
namespaced: true,
state() {
return {
//userDir: '~/.config/sousmargot/',
userDir: './userDir/',
dataFile: 'datas.csv',
caProPercentage: 0.5,
monthDesc : [
{
color: '',
desc: 'CA "scéances effectuées"',
type: 'base',
name: 'caTheo',
unit: '€',
hightlight: true,
output: month => month.caTheo,
},
{
color: '',
desc: 'CA "Séances facturées"',
type: 'base',
name: 'caRetro',
unit: '€',
hightlight: false,
output: month => month.caRetro,
},
{
color: '',
desc: 'CA "Séances facturées" réactualisé',
type: 'base',
name: 'caReact',
unit: '€',
hightlight: true,
output: month => month.caReact,
},
{
color: '',
desc: 'Nombre de séances effectuées',
type: 'base',
name: 'sessionQty',
unit: '',
hightlight: false,
output: month => month.sessionQty,
},
{
color: '',
desc: 'Montant de la rétrocession',
type: 'base',
name: 'retro',
unit: '€',
hightlight: false,
output: month => month.retro,
},
{
color: '',
desc: 'Rémuneration',
type: 'base',
name: 'remuneration',
unit: '€',
hightlight: true,
output: month => month.remuneration,
},
{
color: '',
desc: 'Pourcentage du CA pour la partie pro',
type: 'base',
name: 'proPercentage',
unit: '%',
hightlight: false,
output: month => month.proPercentage,
},
],
}
},
getters: {
userDir (state) { return state.userDir },
dataFilePath (state) { return path.join(state.userDir, state.dataFile) },
monthDesc (state) { return state.monthDesc },
monthHightlightDesc (state) { return state.monthDesc.filter(a => a.hightlight) },
caProPercentage (state) { return state.caProPercentage },
},
mutations: {
},
actions: {
loadConfig (context) {
// load config file at ~/.config/sousmargot/config.json
return context.state.userDir
},
writeData (context) {
// overwrite the dataFile with months datas
const months = context.rootGetters['travail/monthsAll']
const unpackMonths = Object.keys(months).map(k => {return { ...months[k], date: k}})
const csv = Papa.unparse(unpackMonths)
writeFile(context.getters.dataFilePath, csv, (err) => {
if (err) {
console.log(err)
} else {
console.log("Datas sauvegardées")
}
})
},
},
}
export default config