2021-06-29 09:42:10 +00:00
|
|
|
<template>
|
|
|
|
<div class="col-sm-4 col-xs-12">
|
2023-05-17 11:46:54 +00:00
|
|
|
<q-input
|
|
|
|
v-model.number="amount"
|
|
|
|
ref="refAmount"
|
|
|
|
type="number"
|
|
|
|
filled
|
|
|
|
label="Eigener Betrag"
|
|
|
|
step="0.1"
|
|
|
|
min="0"
|
|
|
|
suffix="€"
|
|
|
|
:rules="[check_cent_step]"
|
|
|
|
/>
|
2021-06-29 09:42:10 +00:00
|
|
|
</div>
|
|
|
|
<div class="col-sm-4 col-xs-6">
|
2023-05-09 22:27:41 +00:00
|
|
|
<q-btn style="width: 100%" color="primary" label="Anschreiben" @click="changeBalance(amount * -1)">
|
2021-12-14 13:15:40 +00:00
|
|
|
<q-tooltip v-if="canAddShortcut"> Rechtsklick um Betrag als Verknüpfung hinzuzufügen </q-tooltip>
|
2021-06-29 09:42:10 +00:00
|
|
|
<q-menu v-if="canAddShortcut" anchor="bottom middle" self="top middle" context-menu>
|
|
|
|
<q-btn label="neue Verknüpfung" @click="addShortcut"></q-btn>
|
|
|
|
</q-menu>
|
|
|
|
</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>
|
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
2023-05-03 11:18:27 +00:00
|
|
|
import { defineComponent, ref, PropType, computed, watch } from 'vue';
|
2023-05-17 11:46:54 +00:00
|
|
|
import { QInput } from 'quasar';
|
2021-06-29 09:42:10 +00:00
|
|
|
import { useBalanceStore } from '../store';
|
|
|
|
import { hasPermission, useUserStore } from '@flaschengeist/api';
|
|
|
|
import PERMISSIONS from '../permissions';
|
2023-05-17 11:46:54 +00:00
|
|
|
import { check_cent_step } from '../utils';
|
2021-06-29 09:42:10 +00:00
|
|
|
export default defineComponent({
|
|
|
|
name: 'BalanceAddBody',
|
|
|
|
props: {
|
|
|
|
user: {
|
|
|
|
type: [Object, String] as PropType<FG.User | string>,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
canAddShortcut: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
emits: {
|
2023-05-09 22:27:41 +00:00
|
|
|
'change-balance': (user: FG.User) => user,
|
2021-06-29 09:42:10 +00:00
|
|
|
},
|
|
|
|
setup(props, { emit }) {
|
|
|
|
const store = useBalanceStore();
|
|
|
|
const userStore = useUserStore();
|
|
|
|
const amount = ref<number>(0);
|
2023-05-17 11:46:54 +00:00
|
|
|
const refAmount = ref<QInput>();
|
2021-06-29 09:42:10 +00:00
|
|
|
async function changeBalance(amount: number) {
|
2023-05-17 11:46:54 +00:00
|
|
|
await refAmount.value?.validate();
|
|
|
|
if (amount != 0 && !refAmount.value?.hasError) await store.changeBalance(amount, user.value);
|
2023-05-09 22:27:41 +00:00
|
|
|
emit('change-balance', user.value);
|
2021-06-29 09:42:10 +00:00
|
|
|
}
|
2023-05-17 11:46:54 +00:00
|
|
|
async function addShortcut() {
|
|
|
|
await refAmount.value?.validate();
|
|
|
|
if (amount.value != 0 && !refAmount.value?.hasError) void store.createShortcut(amount.value * -1);
|
2021-06-29 09:42:10 +00:00
|
|
|
}
|
|
|
|
const canAddCredit = hasPermission(PERMISSIONS.CREDIT);
|
|
|
|
const user = computed(() =>
|
|
|
|
(<FG.User>props.user).userid
|
|
|
|
? <FG.User>props.user
|
|
|
|
: <FG.User>userStore.users.find((a) => a.userid === <string>props.user)
|
|
|
|
);
|
2023-05-03 11:18:27 +00:00
|
|
|
watch(amount, (a) => {
|
|
|
|
amount.value = Math.abs(a);
|
|
|
|
});
|
2023-05-17 11:46:54 +00:00
|
|
|
return { changeBalance, addShortcut, canAddCredit, amount, check_cent_step, refAmount };
|
2021-06-29 09:42:10 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped></style>
|