diff --git a/src/plugins/balance/components/BalanceAdd.vue b/src/plugins/balance/components/BalanceAdd.vue index 520ed27..2a0ef95 100644 --- a/src/plugins/balance/components/BalanceAdd.vue +++ b/src/plugins/balance/components/BalanceAdd.vue @@ -21,37 +21,7 @@ -
- -
-
- Rechtsklick um Betrag als Verknüpfung hinzuzufügen - - - - -
-
- -
+
@@ -60,13 +30,14 @@ import { computed, ref, defineComponent, onBeforeMount } from 'vue'; import { hasPermission } from 'src/utils/permission'; import BalanceHeader from '../components/BalanceHeader.vue'; +import BalanceAddBody from 'src/plugins/balance/components/BalanceAddBody.vue'; import PERMISSIONS from '../permissions'; import { useBalanceStore } from '../store'; import { useMainStore } from 'src/stores'; export default defineComponent({ name: 'BalanceAdd', - components: { BalanceHeader }, + components: { BalanceHeader, BalanceAddBody }, emits: { 'open-history': () => true }, setup(_, { emit }) { const store = useBalanceStore(); @@ -76,39 +47,29 @@ export default defineComponent({ void store.getShortcuts(); }); - const amount = ref(0); - const showAddShortcut = ref(false); const user = ref(mainStore.currentUser); const shortCuts = computed(() => store.shortcuts); - const canAddCredit = hasPermission(PERMISSIONS.CREDIT); const showSelector = hasPermission(PERMISSIONS.DEBIT) || hasPermission(PERMISSIONS.CREDIT); - function addShortcut() { - if (amount.value != 0) void store.createShortcut(amount.value * -1); - } function removeShortcut(shortcut: number) { void store.removeShortcut(shortcut); } - async function changeBalance(amount: number) { - await store.changeBalance(amount, user.value); - } function openHistory() { emit('open-history'); } + async function changeBalance(amount: number) { + await store.changeBalance(amount, user.value); + } return { user, - addShortcut, - canAddCredit, removeShortcut, - showAddShortcut, - changeBalance, - amount, showSelector, shortCuts, openHistory, + changeBalance, }; }, }); diff --git a/src/plugins/balance/components/BalanceAddBody.vue b/src/plugins/balance/components/BalanceAddBody.vue new file mode 100644 index 0000000..f8cfb6c --- /dev/null +++ b/src/plugins/balance/components/BalanceAddBody.vue @@ -0,0 +1,78 @@ + + + + + diff --git a/src/plugins/balance/components/BalanceHeader.vue b/src/plugins/balance/components/BalanceHeader.vue index 9190523..ddebcfa 100644 --- a/src/plugins/balance/components/BalanceHeader.vue +++ b/src/plugins/balance/components/BalanceHeader.vue @@ -2,7 +2,7 @@
- Aktueller Stand: {{ balance.balance.toFixed(2) }} € + Aktueller Stand: {{ balance.balance?.toFixed(2) }} € gesperrt
diff --git a/src/plugins/balance/pages/Admin.vue b/src/plugins/balance/pages/Admin.vue index 517e442..398c3ac 100644 --- a/src/plugins/balance/pages/Admin.vue +++ b/src/plugins/balance/pages/Admin.vue @@ -16,6 +16,24 @@
+ @@ -27,8 +45,10 @@ import { ref, defineComponent, computed, onBeforeMount } from 'vue'; import { useBalanceStore } from '../store'; import { useUserStore } from 'src/plugins/user/store'; +import BalanceAddBody from 'src/plugins/balance/components/BalanceAddBody.vue'; export default defineComponent({ + components: { BalanceAddBody }, // name: 'PageName' setup() { const store = useBalanceStore(); @@ -51,7 +71,7 @@ export default defineComponent({ required: true, align: 'left', sortable: true, - format: (val: string) => userStore.users.find((a) => a.userid === val)?.display_name, + format: getName, }, /*{ name: 'credit', @@ -68,18 +88,44 @@ export default defineComponent({ { name: 'limit', label: 'Limit', - format: (_: undefined, row: { userid: string }) => - store.user_limits.find((a) => a.userid === row.userid)?.limit?.toFixed(2), + align: 'right', + format: (_: undefined, row: { userid: string }) => getLimit(row.userid), }, { name: 'balance', label: 'Kontostand', + align: 'right', format: (_: undefined, row: { debit: number; credit: number }) => - (row.credit - row.debit).toFixed(2), + getBalance(row.debit, row.credit), }, ]; - return { rows, columns, limit, setLimits: store.setLimits }; + function getName(val: string) { + return userStore.users.find((a) => a.userid === val)?.display_name; + } + + function getLimit(val: string) { + return store.user_limits.find((a) => a.userid === val)?.limit?.toFixed(2); + } + + function getBalance(debit: number, credit: number) { + return (credit - debit).toFixed(2); + } + + function updateBalance(user: FG.User) { + void store.getBalance(user); + } + + return { + rows, + columns, + limit, + setLimits: store.setLimits, + getName, + getLimit, + getBalance, + updateBalance, + }; }, });