2020-10-31 16:33:40 +00:00
|
|
|
<template>
|
2021-01-29 03:37:56 +00:00
|
|
|
<q-card>
|
2021-03-18 16:23:57 +00:00
|
|
|
<BalanceHeader
|
|
|
|
@update:user="userUpdated"
|
2021-01-31 16:09:29 +00:00
|
|
|
:show-selector="showSelector"
|
2021-03-18 16:23:57 +00:00
|
|
|
@open-history="openHistory"
|
|
|
|
/>
|
2021-01-29 03:37:56 +00:00
|
|
|
<q-separator />
|
2021-01-21 13:24:46 +00:00
|
|
|
|
2021-01-29 03:37:56 +00:00
|
|
|
<q-card-section class="row q-col-gutter-md" v-if="shortCuts">
|
|
|
|
<div :key="index" v-for="(shortcut, index) in shortCuts" class="col-4">
|
|
|
|
<q-btn
|
|
|
|
push
|
|
|
|
v-if="shortcut"
|
|
|
|
color="primary"
|
|
|
|
style="width: 100%"
|
|
|
|
:label="shortcut.toFixed(2).toString() + ' €'"
|
|
|
|
@click="changeBalance(shortcut)"
|
2021-01-21 23:17:03 +00:00
|
|
|
>
|
2021-01-29 03:37:56 +00:00
|
|
|
<q-popup-proxy context-menu>
|
|
|
|
<q-btn label="Entfernen" @click="removeShortcut(shortcut)" />
|
|
|
|
</q-popup-proxy>
|
|
|
|
<q-tooltip>Rechtsklick um Verknüpfung zu entfernen</q-tooltip>
|
|
|
|
</q-btn>
|
|
|
|
</div></q-card-section
|
|
|
|
>
|
|
|
|
<q-card-section class="row q-col-gutter-md items-center">
|
|
|
|
<div class="col-sm-4 col-xs-12">
|
|
|
|
<q-input
|
|
|
|
v-model.number="amount"
|
|
|
|
type="number"
|
|
|
|
filled
|
|
|
|
label="Eigener Betrag"
|
|
|
|
step="0.1"
|
|
|
|
min="0"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="col-sm-4 col-xs-6">
|
|
|
|
<q-btn
|
|
|
|
style="width: 100%"
|
|
|
|
color="primary"
|
|
|
|
label="Anschreiben"
|
|
|
|
@click="changeBalance(amount * -1)"
|
|
|
|
><q-tooltip>Rechtsklick um Betrag als Verknüpfung hinzuzufügen</q-tooltip>
|
|
|
|
<q-popup-proxy context-menu v-model="showAddShortcut">
|
|
|
|
<q-btn label="neue Verknüpfung" @click="addShortcut"></q-btn>
|
|
|
|
</q-popup-proxy>
|
|
|
|
</q-btn>
|
|
|
|
</div>
|
|
|
|
<div class="col-sm-4 col-xs-6">
|
|
|
|
<q-btn
|
|
|
|
v-if="canAddCredit"
|
|
|
|
style="width: 100%"
|
|
|
|
color="secondary"
|
|
|
|
label="Gutschreiben"
|
|
|
|
@click="changeBalance(amount)"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</q-card-section>
|
|
|
|
</q-card>
|
2020-10-31 16:33:40 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-01-30 03:16:17 +00:00
|
|
|
import { computed, ref, defineComponent, onBeforeMount } from 'vue';
|
2021-01-21 13:24:46 +00:00
|
|
|
import { hasPermission } from 'src/utils/permission';
|
2021-01-31 19:40:18 +00:00
|
|
|
import { BalanceInterface, StateInterfaceBalance } from '../store/balance';
|
|
|
|
import { Store, useStore, mapGetters } from 'vuex';
|
2021-01-21 13:24:46 +00:00
|
|
|
import BalanceHeader from '../components/BalanceHeader.vue';
|
|
|
|
import PERMISSIONS from '../permissions';
|
2021-01-31 19:40:18 +00:00
|
|
|
import { UserStateInterface } from 'src/plugins/user/store/user';
|
|
|
|
import { StateInterface } from 'src/store';
|
2020-10-31 20:30:02 +00:00
|
|
|
|
2020-10-31 16:33:40 +00:00
|
|
|
export default defineComponent({
|
2021-01-21 13:24:46 +00:00
|
|
|
name: 'BalanceAdd',
|
2021-01-29 03:37:56 +00:00
|
|
|
components: { BalanceHeader },
|
2021-01-31 19:40:18 +00:00
|
|
|
setup(_, { emit }) {
|
2021-01-29 03:37:56 +00:00
|
|
|
onBeforeMount(() => {
|
|
|
|
void store.dispatch('balance/getShortcuts');
|
2021-01-31 19:40:18 +00:00
|
|
|
if ((<FG.Transaction[]>balanceGatters.transactions())?.length == 0)
|
2021-01-29 03:37:56 +00:00
|
|
|
// No transaction, load at most six since yesterday
|
|
|
|
void store.dispatch('balance/getTransactions', {
|
2021-03-18 16:23:57 +00:00
|
|
|
filter: { limit: 6, from: new Date(new Date().setDate(new Date().getDate() - 1)) },
|
2021-01-29 03:37:56 +00:00
|
|
|
});
|
|
|
|
});
|
2021-01-31 19:40:18 +00:00
|
|
|
//const store = <Store<StateInterfaceBalance>>root.$store;
|
|
|
|
const store = useStore<Store<StateInterface>>();
|
|
|
|
const userStore = useStore<Store<UserStateInterface>>();
|
|
|
|
//const userState = <UserStateInterface>store.state.user;
|
|
|
|
//const balanceState = <BalanceInterface>store.state.balance;
|
|
|
|
const userGetters = mapGetters('users', ['currentUser', 'roles', 'users']);
|
|
|
|
const balanceGatters = mapGetters('balance', ['balances', 'transactions', 'shortcuts']);
|
2020-10-31 20:30:02 +00:00
|
|
|
|
2021-01-21 13:24:46 +00:00
|
|
|
const amount = ref<number>(0);
|
|
|
|
const showAddShortcut = ref(false);
|
2021-01-31 19:40:18 +00:00
|
|
|
//const user = ref(userState.currentUser);
|
|
|
|
const user = computed(() => <FG.User>userGetters.currentUser());
|
|
|
|
//const shortCuts = ref(balanceState.shortcuts);
|
|
|
|
const shortCuts = computed(() => <number[]>balanceGatters.shortcuts());
|
2020-10-31 20:30:02 +00:00
|
|
|
|
2021-01-31 19:40:18 +00:00
|
|
|
const canAddCredit = computed(() => hasPermission(PERMISSIONS.CREDIT));
|
2021-01-21 13:24:46 +00:00
|
|
|
const showSelector = computed(
|
2021-01-31 19:40:18 +00:00
|
|
|
() => hasPermission(PERMISSIONS.DEBIT) || hasPermission(PERMISSIONS.CREDIT)
|
2021-01-21 13:24:46 +00:00
|
|
|
);
|
2020-10-31 20:30:02 +00:00
|
|
|
|
2021-01-21 13:24:46 +00:00
|
|
|
function addShortcut() {
|
2021-01-27 01:40:47 +00:00
|
|
|
if (amount.value != 0) void store.dispatch('balance/addShortcut', amount.value * -1);
|
2021-01-21 23:17:03 +00:00
|
|
|
}
|
|
|
|
function removeShortcut(shortcut: number) {
|
|
|
|
void store.dispatch('balance/removeShortcut', shortcut);
|
2021-01-21 13:24:46 +00:00
|
|
|
}
|
|
|
|
function userUpdated(selectedUser: FG.User) {
|
2021-01-31 19:40:18 +00:00
|
|
|
//TODO:
|
|
|
|
//user.value = selectedUser;
|
2021-01-21 13:24:46 +00:00
|
|
|
}
|
2020-10-31 20:30:02 +00:00
|
|
|
function changeBalance(amount: number) {
|
|
|
|
store
|
2021-01-21 13:24:46 +00:00
|
|
|
.dispatch('balance/changeBalance', { amount: amount, user: user.value?.userid })
|
2021-03-18 16:23:57 +00:00
|
|
|
.catch((err) => console.log(err));
|
2020-10-31 20:30:02 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 21:57:10 +00:00
|
|
|
function openHistory() {
|
2021-03-18 16:23:57 +00:00
|
|
|
emit('open-history');
|
2021-01-29 21:57:10 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 13:24:46 +00:00
|
|
|
return {
|
|
|
|
user,
|
|
|
|
addShortcut,
|
2021-01-28 22:09:19 +00:00
|
|
|
canAddCredit,
|
2021-01-21 23:17:03 +00:00
|
|
|
removeShortcut,
|
2021-01-21 13:24:46 +00:00
|
|
|
showAddShortcut,
|
|
|
|
changeBalance,
|
|
|
|
amount,
|
|
|
|
showSelector,
|
|
|
|
shortCuts,
|
2021-01-29 21:57:10 +00:00
|
|
|
userUpdated,
|
2021-03-18 16:23:57 +00:00
|
|
|
openHistory,
|
2021-01-21 13:24:46 +00:00
|
|
|
};
|
2021-03-18 16:23:57 +00:00
|
|
|
},
|
2020-10-31 20:30:02 +00:00
|
|
|
});
|
2020-10-31 16:33:40 +00:00
|
|
|
</script>
|