finanzer can add useres to DB

in usercontent for finanzer, he can add amount or credit too
bug fixes
This commit is contained in:
Tim Gröger 2019-12-29 21:35:32 +01:00
parent da26270a61
commit 88abb2599a
8 changed files with 178 additions and 21 deletions

View File

@ -79,8 +79,6 @@
}
},
created() {
// eslint-disable-next-line no-console
console.log(this.users)
},
methods: {
addAmount(username, amount) {

View File

@ -45,6 +45,14 @@
</v-row>
</v-col>
<v-col align-self="center">
<v-row>
<v-col>
<v-label>Status: </v-label>
</v-col>
<v-col>
<v-chip outlined :text-color="getLockedColor(user.locked)">{{user.locked ? 'Gesperrt': 'nicht Gesperrt'}}</v-chip>
</v-col>
</v-row>
<v-card outlined>
<v-row>
<v-card-title class="subtitle-2">Geld transferieren</v-card-title>
@ -144,7 +152,7 @@
return lastYear + sum
},
createYears() {
for (let year = 2000; year <= new Date().getFullYear(); year++) {
for (let year = new Date().getFullYear(); year >= 2000; year--) {
this.years.push({value: year, text: year})
}
},
@ -185,6 +193,9 @@
this.filteredUsers = [...this.filteredUsers.filter(user => {
return user.firstname.toLowerCase().includes(this.filter.toLowerCase()) || user.lastname.toLowerCase().includes(this.filter.toLowerCase())
})]
},
getLockedColor (value) {
return value ? 'red' : 'green'
}
},
computed: {

View File

@ -34,6 +34,37 @@
</v-form>
</v-card-text>
</v-card>
<v-card style="margin-top: 3px;">
<v-card-title>Geld transferieren</v-card-title>
<v-card-text>
<v-form style="margin-left: 15px; margin-right: 15px">
<v-row>
<v-col>
<v-text-field :rules="[isNumber]" label="Betrag"
v-model="amount"></v-text-field>
</v-col>
<v-col>
<v-select return-object v-model="type" label="Typ"
:items="[{value: 'amount', text: 'Schulden'}, {value: 'credit', text: 'Guthaben'}]"
item-text="text" item-value="value"></v-select>
</v-col>
</v-row>
<v-row>
<v-col>
<v-select return-object v-model="selectedYear" label="Jahr"
:items="selectYears" item-text="text"
item-value="value"></v-select>
</v-col>
<v-col>
<v-select return-object v-model="selectedMonth" label="Monat"
:items="months" item-text="text"
item-value="value"></v-select>
</v-col>
</v-row>
</v-form>
<v-btn block @click="add">Hinzufügen</v-btn>
</v-card-text>
</v-card>
<div v-for="year in years" :key="years.indexOf(year)">
<v-card style="margin-top: 3px;">
<v-card-title>{{year}}</v-card-title>
@ -80,12 +111,36 @@
isNumber: value => !isNaN(value) || 'Betrag muss eine Zahl sein.',
limit: null,
autoLock: null,
amount: null,
selectYears: [],
months: [
{value: 1, text: 'Januar'},
{value: 2, text: 'Februar'},
{value: 3, text: 'März'},
{value: 4, text:'April'},
{value: 5, text: 'Mai'},
{value: 6, text: 'Juni'},
{value: 7, text: 'Juli'},
{value: 8, text: 'August'},
{value: 9, text: 'September'},
{value: 10, text: 'Oktober'},
{value: 11, text: 'November'},
{value: 12, text: 'Dezember'}
],
type: {value: 'credit', text: 'Guthaben'},
selectedYear: {value: new Date().getFullYear(), text: new Date().getFullYear()},
selectedMonth: {value: new Date().getMonth() + 1, text: ["Januar", "Februar", "März", "April", "Mai", "Juni",
"Juli", "August", "September", "Oktober", "November", "Dezember"
][new Date().getMonth()]}
}
},
created() {
this.limit = (this.user.limit / 100).toFixed(2)
this.autoLock = {value: this.user.autoLock, text: this.user.autoLock? "Aktiviert" : "Deaktiviert"}
for (let year = new Date().getFullYear(); year >= 2000; year--) {
this.selectYears.push({value: year, text: year})
}
},
methods: {
getLastColor (value) {
@ -103,6 +158,29 @@
},
saveConfig() {
this.$emit("save:config", {user: this.user, limit: this.limit, autoLock: this.autoLock.value})
},
add() {
if (this.type.value === 'amount') {
this.$emit("add:amount", {user: this.user, amount: this.amount, year: this.selectedYear.value, month: this.selectedMonth.value})
}
if (this.type.value === 'credit') {
this.$emit("add:credit", {user: this.user, credit: this.amount, year: this.selectedYear.value, month: this.selectedMonth.value})
}
this.createDefault()
},
createDefault() {
// eslint-disable-next-line no-unused-vars
let year = new Date().getFullYear()
// eslint-disable-next-line no-unused-vars
let month = new Date().getMonth()
this.amount = null
this.type = {value: 'credit', text: 'Guthaben'}
this.selectedYear = {value: new Date().getFullYear(), text: new Date().getFullYear()}
this.selectedMonth = {value: new Date().getMonth() + 1, text: ["Januar", "Februar", "März", "April", "Mai", "Juni",
"Juli", "August", "September", "Oktober", "November", "Dezember"
][new Date().getMonth()]}
}
},
computed: {

View File

@ -38,6 +38,9 @@ class Service {
finanzerSetConfig(token, data) {
return axios.post(this.url+'finanzerSetConfig', {...data}, {headers: {Token: token}})
}
finanzerAddUser(token, data) {
return axios.post(this.url+'finanzerAddUser', {...data}, {headers: {Token: token}})
}
}
const httpClient = new Service("http://localhost:5000/")

View File

@ -22,7 +22,6 @@ export default new Vuex.Store({
state.loginError = errorMessage;
},
updateAccessToken (state, data) {
// eslint-disable-next-line no-console
if (typeof(data) === typeof("")) {
data = JSON.parse(data)
}

View File

@ -28,7 +28,6 @@
},
methods: {
getUser() {
// eslint-disable-next-line no-console
this. users = []
httpClient.getUserBar(this.$store.getters.getToken)
.then(response => {

View File

@ -19,12 +19,32 @@
<v-list-item-title>{{user.lastname}}, {{user.firstname}}</v-list-item-title>
</v-list-item>
</v-list>
<template v-slot:append>
<v-list>
<v-list-item>
<v-list-item-icon><v-icon>search</v-icon></v-list-item-icon>
<v-list-item-title>
<v-autocomplete outlined return-object v-model="user" style="margin-top: 3px"
placeholder="Suche Person" :items="allUsers" item-text="fullName"
prepend-inner-icon="search" full-width/>
</v-list-item-title>
</v-list-item>
<v-list-item>
<v-list-item-icon><v-icon>person_add</v-icon></v-list-item-icon>
<v-list-item-title>
<v-btn text block @click="addUser">Hinzufügen</v-btn>
</v-list-item-title>
</v-list-item>
</v-list>
</template>
</v-navigation-drawer>
<v-content v-if="!activeUser.username">
<Overview v-bind:users="users" @add:amount="addAmount" @add:credit="addCredit"/>
</v-content>
<v-content v-else>
<User v-bind:user="activeUser" @do:lock="doLock" @save:config="saveConfig"/>
<User v-bind:user="activeUser"
@add:amount="addAmount" @add:credit="addCredit"
@do:lock="doLock" @save:config="saveConfig"/>
</v-content>
</div>
</template>
@ -40,6 +60,14 @@
components: {User, Overview, TitleBar},
created() {
this.getUser()
httpClient.searchUser(this.$store.getters.getToken, {searchString: ""})
.then(response => {
this.allUsers = response.data
for (let i = 0; i < this.allUsers.length; i++) {
this.allUsers[i].fullName = this.allUsers[i].firstname + " " + this.allUsers[i].lastname
}
})
},
data () {
return {
@ -47,6 +75,8 @@
activeUser: {
username: null,
},
allUsers: [],
user: null
}
},
methods: {
@ -54,7 +84,7 @@
if (this.activeUser.username === e.username) {
this.activeUser = {username: null}
} else {
this.activeUser = {...e}
this.activeUser = e
}
},
createAmount(creditList) {
@ -159,9 +189,6 @@
if (a.firstname < b.firstname) return -1
return 0
})
// eslint-disable-next-line no-console
console.log(this.users)
},
addAmount(data) {
httpClient.addAmountFinanzer(this.$store.getters.getToken, {userId: data.user.username, amount: data.amount * 100, year: data.year, month: data.month})
@ -171,13 +198,15 @@
let index = this.users.indexOf(user)
let list = {}
for (let creditList in response.data) {
let amount = this.createAmount(response.data[creditList])
let credit = this.createCredit(response.data[creditList])
let sum = this.createSum(credit, amount)
list[creditList] = [{...credit}, {...amount}, {...sum}]
if (creditList !== 'locked') {
let amount = this.createAmount(response.data[creditList])
let credit = this.createCredit(response.data[creditList])
let sum = this.createSum(credit, amount)
list[creditList] = [{...credit}, {...amount}, {...sum}]
}
}
this.users[index].creditList = list
this.users[index].locked = response.data.locked
})
.catch(error => {
if (error.response) {
@ -187,6 +216,7 @@
}
this.users = []
})
this.users.find(a => {return a.username === this.activeUser.username})
},
addCredit(data) {
@ -197,13 +227,15 @@
let index = this.users.indexOf(user)
let list = {}
for (let creditList in response.data) {
let amount = this.createAmount(response.data[creditList])
let credit = this.createCredit(response.data[creditList])
let sum = this.createSum(credit, amount)
list[creditList] = [{...credit}, {...amount}, {...sum}]
if (creditList !== 'locked') {
let amount = this.createAmount(response.data[creditList])
let credit = this.createCredit(response.data[creditList])
let sum = this.createSum(credit, amount)
list[creditList] = [{...credit}, {...amount}, {...sum}]
}
}
this.users[index].creditList = list
this.users[index].locked = response.data.locked
})
.catch(error => {
if (error.response) {
@ -213,6 +245,7 @@
}
this.users = []
})
this.users.find(a => {return a.username === this.activeUser.username})
},
deactivateAllUser() {
for (let user in this.users) {
@ -249,6 +282,43 @@
}
}
})
},
addUser() {
httpClient.finanzerAddUser(this.$store.getters.getToken, {userId: this.user.username})
.then(response => {
for (let username in response.data) {
let existUser = this.users.find(a => {return a.username === username})
let list = {}
for (let creditList in response.data[username]['creditList']) {
let amount = this.createAmount(response.data[username]['creditList'][creditList])
let credit = this.createCredit(response.data[username]['creditList'][creditList])
let sum = this.createSum(credit, amount)
list[creditList] = [{...credit}, {...amount}, {...sum}]
}
if (existUser) {
existUser.firstname = response.data[username].firstname
existUser.lastname = response.data[username].lastname
existUser.limit = response.data[username].limit
existUser.locked = response.data[username].locked
existUser.autoLock = response.data[username].autoLock
existUser.creditList = list
} else {
const lastId = this.users.length > 0 ? this.users[this.users.length - 1].id : 0
this.users.push({
id: lastId + 1,
username: response.data[username].username,
firstname: response.data[username].firstname,
lastname: response.data[username].lastname,
limit: response.data[username].limit,
locked: response.data[username].locked,
autoLock: response.data[username].autoLock,
creditList: list,
expand: false,
active: false
})
}
}
})
}
}

View File

@ -75,7 +75,6 @@
},
methods: {
login() {
// eslint-disable-next-line no-console
let o = {username: this.username, password: this.password}
this.$store.dispatch("doLogin", o)
},