Sousmargot/src/store/config/index.js

176 lines
5.9 KiB
JavaScript

import path from 'path'
import Papa from 'papaparse'
import { writeFile } from 'fs'
import {
ca,
notInvoiced,
caPro,
caPerso,
caPersoUntouch,
} from '../../lib/months.js'
const config = {
namespaced: true,
state() {
return {
//userDir: '~/.config/sousmargot/',
userDir: './userDir/',
dataFile: 'datas.csv',
caProPercentage: 0.5,
descAll : [
{
name: 'caTheo',
color: '',
label: 'CA "scéances effectuées"',
type: 'editable',
unit: '€',
hightlight: false,
output: month => month.caTheo,
},
{
name: 'caRetro',
color: '',
label: 'CA "Séances facturées"',
type: 'editable',
unit: '€',
hightlight: false,
output: month => month.caRetro,
},
{
name: 'caReact',
color: '',
label: 'CA "Séances facturées" réactualisé',
type: 'editable',
unit: '€',
hightlight: false,
output: month => month.caReact,
},
{
name: 'sessionQty',
color: '',
label: 'Nombre de séances effectuées',
unit: '',
hightlight: false,
output: month => month.sessionQty,
},
{
name: 'retro',
color: '',
label: 'Montant de la rétrocession',
type: 'editable',
unit: '€',
hightlight: false,
output: month => month.retro,
},
{
name: 'remuneration',
color: '',
label: 'Rémuneration',
type: 'editable',
unit: '€',
hightlight: true,
output: month => month.remuneration,
},
{
name: 'proPercentage',
color: '',
label: 'Pourcentage du CA pour la partie pro',
type: 'editable',
unit: '%',
hightlight: false,
output: month => month.proPercentage,
},
{
name: 'ca',
color: '',
label: 'CA',
type: 'compute',
unit: '€',
hightlight: true,
output: month => ca(month),
},
{
name: 'notInvoiced',
color: '',
label: 'Non facturé',
type: 'compute',
unit: '€',
hightlight: true,
output: month => notInvoiced(month),
},
{
name: 'caPro',
color: '',
label: 'CA pour le partie pro',
type: 'compute',
unit: '€',
hightlight: false,
output: month => caPro(month),
},
{
name: 'caPerso',
color: '',
label: 'CA destiné à la rémuneration',
type: 'compute',
unit: '€',
hightlight: false,
output: month => caPerso(month),
},
{
name: 'caPersoUntouch',
color: '',
label: 'Banque 13e mois',
type: 'compute',
unit: '€',
hightlight: false,
output: month => caPersoUntouch(month),
},
],
}
},
getters: {
userDir (state) { return state.userDir },
dataFilePath (state) { return path.join(state.userDir, state.dataFile) },
descAll (state) {
// All description of attributes for months
return state.descAll
},
descEditable (state) {
// All description of attributes for months that are editable
return state.descAll.filter(d => d.type == 'editable')
},
descComputed (state) {
// All description of attributes for months that are computed
return state.descAll.filter(d => d.type != 'editable')
},
descOf: (state) => (desc) => {
return state.descAll.filter(d => d.name == desc)[0]
},
monthHightlightDesc (state) { return state.descAll.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