2020-10-31 16:33:40 +00:00
|
|
|
<template>
|
2021-01-21 13:24:46 +00:00
|
|
|
<q-page padding class="fit row justify-left q-col-gutter-sm">
|
|
|
|
<div class="col-12">
|
|
|
|
<q-card>
|
|
|
|
<BalanceHeader @update:user="userUpdated" :showSelector="showSelector" />
|
|
|
|
<q-separator />
|
|
|
|
|
|
|
|
<q-card-section class="row q-col-gutter-md" v-if="shortCuts">
|
|
|
|
<div v-for="(amount, index) in shortCuts" v-bind:key="index" class="col-4">
|
|
|
|
<q-btn
|
|
|
|
color="primary"
|
|
|
|
style="width: 100%"
|
|
|
|
:label="amount.toFixed(2).toString() + ' €'"
|
|
|
|
@click="changeBalance(amount)"
|
|
|
|
/>
|
|
|
|
</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-popup-proxy
|
|
|
|
></q-btn>
|
|
|
|
</div>
|
|
|
|
<div class="col-sm-4 col-xs-6">
|
|
|
|
<q-btn
|
|
|
|
style="width: 100%"
|
|
|
|
color="secondary"
|
|
|
|
label="Gutschreiben"
|
|
|
|
@click="changeBalance(amount)"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</q-card-section>
|
|
|
|
</q-card>
|
|
|
|
</div>
|
|
|
|
<div v-for="(transaction, index) in transactions" v-bind:key="index" class="col-sm-4 col-xs-6">
|
|
|
|
<Transaction :transaction="transaction" @reversed="reversed" />
|
|
|
|
</div>
|
2020-10-31 16:33:40 +00:00
|
|
|
</q-page>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-01-21 13:24:46 +00:00
|
|
|
// TODO: Shortcuts are not displayed when first loaded
|
|
|
|
|
|
|
|
import { computed, ref, defineComponent, onBeforeMount } from '@vue/composition-api';
|
|
|
|
import { hasPermission } from 'src/utils/permission';
|
|
|
|
import { StateInterfaceBalance } from '../store/balance';
|
2020-10-31 20:30:02 +00:00
|
|
|
import { Store } from 'vuex';
|
2021-01-21 13:24:46 +00:00
|
|
|
import Transaction from '../components/Transaction.vue';
|
|
|
|
import BalanceHeader from '../components/BalanceHeader.vue';
|
|
|
|
import PERMISSIONS from '../permissions';
|
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',
|
|
|
|
components: { Transaction, BalanceHeader },
|
2020-10-31 20:30:02 +00:00
|
|
|
setup(_, { root }) {
|
2021-01-21 13:24:46 +00:00
|
|
|
onBeforeMount(() => void store.dispatch('balance/getShortcuts'));
|
|
|
|
const store = <Store<StateInterfaceBalance>>root.$store;
|
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);
|
|
|
|
const transactions = ref<FG.Transaction[]>([]);
|
|
|
|
const user = ref(store.state.user.currentUser);
|
|
|
|
const shortCuts = ref(store.state.balance.shortcuts);
|
2020-10-31 20:30:02 +00:00
|
|
|
|
2021-01-21 13:24:46 +00:00
|
|
|
const showSelector = computed(
|
|
|
|
() => hasPermission(PERMISSIONS.DEBIT, store) || hasPermission(PERMISSIONS.CREDIT, store)
|
|
|
|
);
|
2020-10-31 20:30:02 +00:00
|
|
|
|
2021-01-21 13:24:46 +00:00
|
|
|
function addShortcut() {
|
|
|
|
// TODO: Save shortcuts on backend
|
|
|
|
showAddShortcut.value = false;
|
|
|
|
console.log(amount);
|
|
|
|
}
|
|
|
|
function userUpdated(selectedUser: FG.User) {
|
|
|
|
user.value = selectedUser;
|
|
|
|
}
|
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 })
|
|
|
|
.then((transaction: FG.Transaction) => {
|
|
|
|
if (transactions.value.length > 5) transactions.value.pop();
|
|
|
|
transaction.time = new Date(transaction.time);
|
|
|
|
transactions.value.unshift(transaction);
|
|
|
|
console.log(transactions.value);
|
|
|
|
})
|
2020-10-31 20:30:02 +00:00
|
|
|
.catch(err => console.log(err));
|
|
|
|
}
|
|
|
|
|
2021-01-21 13:24:46 +00:00
|
|
|
function reversed(id: number) {
|
|
|
|
transactions.value = transactions.value.filter(t => t.id != id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
user,
|
|
|
|
addShortcut,
|
|
|
|
showAddShortcut,
|
|
|
|
changeBalance,
|
|
|
|
transactions,
|
|
|
|
amount,
|
|
|
|
showSelector,
|
|
|
|
shortCuts,
|
|
|
|
reversed,
|
|
|
|
userUpdated
|
|
|
|
};
|
2020-10-31 20:30:02 +00:00
|
|
|
}
|
|
|
|
});
|
2020-10-31 16:33:40 +00:00
|
|
|
</script>
|