Compare commits
11 Commits
v.1.0.0-al
...
main
Author | SHA1 | Date |
---|---|---|
|
1350e34fd3 | |
|
9584774d18 | |
|
59a430bea8 | |
|
ebffecd364 | |
|
56b09abeaa | |
|
86a06e8094 | |
|
9120bc9dba | |
|
b6275f7478 | |
|
4abcedce3a | |
|
345227f5d4 | |
|
a876f99e13 |
10
package.json
10
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "1.0.0-alpha.2",
|
"version": "1.0.0",
|
||||||
"name": "@flaschengeist/balance",
|
"name": "@flaschengeist/balance",
|
||||||
"author": "Ferdinand Thiessen <rpm@fthiessen.de>",
|
"author": "Ferdinand Thiessen <rpm@fthiessen.de>",
|
||||||
"homepage": "https://flaschengeist.dev/Flaschengeist",
|
"homepage": "https://flaschengeist.dev/Flaschengeist",
|
||||||
|
@ -19,8 +19,8 @@
|
||||||
"lint": "eslint --ext .js,.ts,.vue ./src"
|
"lint": "eslint --ext .js,.ts,.vue ./src"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@flaschengeist/api": "^1.0.0-alpha.8",
|
"@flaschengeist/api": "^1.0.0",
|
||||||
"@flaschengeist/types": "^1.0.0-alpha.10",
|
"@flaschengeist/types": "^1.0.0",
|
||||||
"@quasar/app-webpack": "^3.7.2",
|
"@quasar/app-webpack": "^3.7.2",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
||||||
"@typescript-eslint/parser": "^5.8.0",
|
"@typescript-eslint/parser": "^5.8.0",
|
||||||
|
@ -37,8 +37,8 @@
|
||||||
"typescript": "^4.5.4"
|
"typescript": "^4.5.4"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@flaschengeist/api": "1.0.0-alpha.8",
|
"@flaschengeist/api": "1.0.0",
|
||||||
"@flaschengeist/users": "1.0.0-alpha.4"
|
"@flaschengeist/users": "1.0.0"
|
||||||
},
|
},
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
|
|
|
@ -2,16 +2,19 @@ import { FG_Plugin } from '@flaschengeist/types';
|
||||||
|
|
||||||
export interface SendFromNotification {
|
export interface SendFromNotification {
|
||||||
receiver_id: string;
|
receiver_id: string;
|
||||||
author_id: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SendToNotification {
|
export interface SendToNotification {
|
||||||
sender_id: string;
|
sender_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TransactionNotification {
|
||||||
|
author_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface BalanceNotification extends FG_Plugin.Notification {
|
export interface BalanceNotification extends FG_Plugin.Notification {
|
||||||
data: {
|
data: {
|
||||||
type: number;
|
type: number;
|
||||||
amount: number;
|
amount: number;
|
||||||
} & (SendFromNotification | SendToNotification);
|
} & (SendFromNotification | SendToNotification | TransactionNotification);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="col-sm-4 col-xs-12">
|
<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" suffix="€" />
|
<q-input
|
||||||
|
v-model.number="amount"
|
||||||
|
ref="refAmount"
|
||||||
|
type="number"
|
||||||
|
filled
|
||||||
|
label="Eigener Betrag"
|
||||||
|
step="0.1"
|
||||||
|
min="0"
|
||||||
|
suffix="€"
|
||||||
|
:rules="[check_cent_step]"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-4 col-xs-6">
|
<div class="col-sm-4 col-xs-6">
|
||||||
<q-btn v-close-popup style="width: 100%" color="primary" label="Anschreiben" @click="changeBalance(amount * -1)">
|
<q-btn style="width: 100%" color="primary" label="Anschreiben" @click="changeBalance(amount * -1)">
|
||||||
<q-tooltip v-if="canAddShortcut"> Rechtsklick um Betrag als Verknüpfung hinzuzufügen </q-tooltip>
|
<q-tooltip v-if="canAddShortcut"> Rechtsklick um Betrag als Verknüpfung hinzuzufügen </q-tooltip>
|
||||||
<q-menu v-if="canAddShortcut" anchor="bottom middle" self="top middle" context-menu>
|
<q-menu v-if="canAddShortcut" anchor="bottom middle" self="top middle" context-menu>
|
||||||
<q-btn label="neue Verknüpfung" @click="addShortcut"></q-btn>
|
<q-btn label="neue Verknüpfung" @click="addShortcut"></q-btn>
|
||||||
|
@ -13,7 +23,6 @@
|
||||||
<div class="col-sm-4 col-xs-6">
|
<div class="col-sm-4 col-xs-6">
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="canAddCredit"
|
v-if="canAddCredit"
|
||||||
v-close-popup
|
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
label="Gutschreiben"
|
label="Gutschreiben"
|
||||||
|
@ -23,9 +32,11 @@
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, ref, PropType, computed, watch } from 'vue';
|
import { defineComponent, ref, PropType, computed, watch } from 'vue';
|
||||||
|
import { QInput } from 'quasar';
|
||||||
import { useBalanceStore } from '../store';
|
import { useBalanceStore } from '../store';
|
||||||
import { hasPermission, useUserStore } from '@flaschengeist/api';
|
import { hasPermission, useUserStore } from '@flaschengeist/api';
|
||||||
import PERMISSIONS from '../permissions';
|
import PERMISSIONS from '../permissions';
|
||||||
|
import { check_cent_step } from '../utils';
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'BalanceAddBody',
|
name: 'BalanceAddBody',
|
||||||
props: {
|
props: {
|
||||||
|
@ -39,18 +50,21 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
emits: {
|
emits: {
|
||||||
changeBalance: (user: FG.User) => user,
|
'change-balance': (user: FG.User) => user,
|
||||||
},
|
},
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
const store = useBalanceStore();
|
const store = useBalanceStore();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const amount = ref<number>(0);
|
const amount = ref<number>(0);
|
||||||
|
const refAmount = ref<QInput>();
|
||||||
async function changeBalance(amount: number) {
|
async function changeBalance(amount: number) {
|
||||||
await store.changeBalance(amount, user.value);
|
await refAmount.value?.validate();
|
||||||
emit('changeBalance', user.value);
|
if (amount != 0 && !refAmount.value?.hasError) await store.changeBalance(amount, user.value);
|
||||||
|
emit('change-balance', user.value);
|
||||||
}
|
}
|
||||||
function addShortcut() {
|
async function addShortcut() {
|
||||||
if (amount.value != 0) void store.createShortcut(amount.value * -1);
|
await refAmount.value?.validate();
|
||||||
|
if (amount.value != 0 && !refAmount.value?.hasError) void store.createShortcut(amount.value * -1);
|
||||||
}
|
}
|
||||||
const canAddCredit = hasPermission(PERMISSIONS.CREDIT);
|
const canAddCredit = hasPermission(PERMISSIONS.CREDIT);
|
||||||
const user = computed(() =>
|
const user = computed(() =>
|
||||||
|
@ -61,7 +75,7 @@ export default defineComponent({
|
||||||
watch(amount, (a) => {
|
watch(amount, (a) => {
|
||||||
amount.value = Math.abs(a);
|
amount.value = Math.abs(a);
|
||||||
});
|
});
|
||||||
return { changeBalance, addShortcut, canAddCredit, amount };
|
return { changeBalance, addShortcut, canAddCredit, amount, check_cent_step, refAmount };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<q-card-section class="fit row justify-left content-center items-center q-col-gutter-sm">
|
<q-card-section class="fit row justify-left content-center items-center q-col-gutter-sm">
|
||||||
<div class="col-5">
|
<div class="col-5">
|
||||||
<div v-if="balance" class="text-h6">
|
<div v-if="balance" class="text-h6">
|
||||||
Aktueller Stand: {{ balance.balance ? balance.balance.toFixed(2) : '' }} €
|
Aktueller Stand: {{ balance.balance ? balance.balance.toFixed(2) : parseInt('0').toFixed(2) }} €
|
||||||
<q-badge v-if="isLocked" color="negative" align="top"> gesperrt </q-badge>
|
<q-badge v-if="isLocked" color="negative" align="top"> gesperrt </q-badge>
|
||||||
</div>
|
</div>
|
||||||
<q-spinner v-else color="primary" size="3em" />
|
<q-spinner v-else color="primary" size="3em" />
|
||||||
|
@ -10,9 +10,11 @@
|
||||||
<div v-if="showSelector" class="col-6">
|
<div v-if="showSelector" class="col-6">
|
||||||
<UserSelector v-model="user" />
|
<UserSelector v-model="user" />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-1 justify-end">
|
<div class="col">
|
||||||
|
<div class="row fit justify-end content-end items-end">
|
||||||
<q-btn round flat icon="mdi-format-list-checks" @click="openHistory" />
|
<q-btn round flat icon="mdi-format-list-checks" @click="openHistory" />
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,30 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="col-sm-4 col-xs-12">
|
<div class="col-sm-4 col-xs-12">
|
||||||
<q-input v-model.number="amount" type="number" filled label="Betrag" step="0.1" min="0" suffix="€" />
|
<q-input
|
||||||
|
v-model.number="amount"
|
||||||
|
ref="refAmount"
|
||||||
|
type="number"
|
||||||
|
filled
|
||||||
|
label="Betrag"
|
||||||
|
step="0.1"
|
||||||
|
min="0"
|
||||||
|
suffix="€"
|
||||||
|
:rules="[check_cent_step]"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-4 col-xs-6">
|
<div class="col-sm-4 col-xs-6">
|
||||||
<UserSelector v-model="receiver" label="Empfänger" />
|
<UserSelector v-model="receiver" label="Empfänger" />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-4 col-xs-6">
|
<div class="col-sm-4 col-xs-6">
|
||||||
<q-btn
|
<q-btn style="width: 100%" color="primary" :disable="sendDisabled" label="Senden" @click="sendAmount" />
|
||||||
v-close-popup
|
|
||||||
style="width: 100%"
|
|
||||||
color="primary"
|
|
||||||
:disable="sendDisabled"
|
|
||||||
label="Senden"
|
|
||||||
@click="sendAmount"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { computed, defineComponent, PropType, ref } from 'vue';
|
import { computed, defineComponent, PropType, ref } from 'vue';
|
||||||
|
import { QInput } from 'quasar';
|
||||||
import UserSelector from '@flaschengeist/users/src/components/UserSelector.vue';
|
import UserSelector from '@flaschengeist/users/src/components/UserSelector.vue';
|
||||||
import { useBalanceStore } from '../store';
|
import { useBalanceStore } from '../store';
|
||||||
|
import { check_cent_step } from '../utils';
|
||||||
import { useUserStore } from '@flaschengeist/api';
|
import { useUserStore } from '@flaschengeist/api';
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'BalanceTransferBody',
|
name: 'BalanceTransferBody',
|
||||||
|
@ -31,13 +36,14 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
emits: {
|
emits: {
|
||||||
changeBalance: (sender: FG.User, receiver: FG.User) => sender && receiver,
|
changeBalance: ({ sender, receiver }: { sender: FG.User; receiver: FG.User }) => sender && receiver,
|
||||||
},
|
},
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
const store = useBalanceStore();
|
const store = useBalanceStore();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const receiver = ref<FG.User | undefined>(undefined);
|
const receiver = ref<FG.User | undefined>(undefined);
|
||||||
const amount = ref<number>(0);
|
const amount = ref<number>(0);
|
||||||
|
const refAmount = ref<QInput>();
|
||||||
const sender = computed(() =>
|
const sender = computed(() =>
|
||||||
(<FG.User>props.user).userid
|
(<FG.User>props.user).userid
|
||||||
? <FG.User>props.user
|
? <FG.User>props.user
|
||||||
|
@ -45,13 +51,20 @@ export default defineComponent({
|
||||||
);
|
);
|
||||||
|
|
||||||
const sendDisabled = computed(() => {
|
const sendDisabled = computed(() => {
|
||||||
return !(receiver.value && sender.value && sender.value.userid != receiver.value.userid && amount.value > 0);
|
return !(
|
||||||
|
receiver.value &&
|
||||||
|
sender.value &&
|
||||||
|
sender.value.userid != receiver.value.userid &&
|
||||||
|
amount.value > 0 &&
|
||||||
|
!refAmount.value?.hasError
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
async function sendAmount() {
|
async function sendAmount() {
|
||||||
if (receiver.value) {
|
await refAmount.value?.validate();
|
||||||
|
if (receiver.value && !refAmount.value?.hasError) {
|
||||||
await store.changeBalance(amount.value, receiver.value, sender.value);
|
await store.changeBalance(amount.value, receiver.value, sender.value);
|
||||||
emit('changeBalance', sender.value, receiver.value);
|
emit('changeBalance', { sender: sender.value, receiver: receiver.value });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
@ -60,6 +73,8 @@ export default defineComponent({
|
||||||
amount,
|
amount,
|
||||||
sendAmount,
|
sendAmount,
|
||||||
sendDisabled,
|
sendDisabled,
|
||||||
|
refAmount,
|
||||||
|
check_cent_step,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,7 +21,7 @@ export default defineComponent({
|
||||||
void store.getBalance(mainStore.currentUser);
|
void store.getBalance(mainStore.currentUser);
|
||||||
});
|
});
|
||||||
|
|
||||||
const balance = computed(() => store.balance?.balance || NaN);
|
const balance = computed(() => store.balance?.balance || 0);
|
||||||
|
|
||||||
return { balance };
|
return { balance };
|
||||||
},
|
},
|
||||||
|
|
19
src/index.ts
19
src/index.ts
|
@ -1,15 +1,17 @@
|
||||||
import { FG_Plugin } from '@flaschengeist/types';
|
import { FG_Plugin } from '@flaschengeist/types';
|
||||||
import { defineAsyncComponent } from 'vue';
|
import { defineAsyncComponent } from 'vue';
|
||||||
import routes from './routes';
|
import routes from './routes';
|
||||||
import { BalanceNotification, SendFromNotification, SendToNotification } from 'app/balance';
|
import { BalanceNotification, SendFromNotification, SendToNotification, TransactionNotification } from 'app/balance';
|
||||||
import { useUserStore } from '@flaschengeist/api';
|
import { useUserStore } from '@flaschengeist/api';
|
||||||
|
|
||||||
const BalanceTypes = {
|
const BalanceTypes = {
|
||||||
send_to: 0x01,
|
send_to: 0x01,
|
||||||
send_from: 0x02,
|
send_from: 0x02,
|
||||||
|
add_from: 0x03,
|
||||||
|
sub_from: 0x04,
|
||||||
};
|
};
|
||||||
|
|
||||||
function transpile(msg: FG_Plugin.Notification) {
|
function transpile (msg: FG_Plugin.Notification) {
|
||||||
console.log('notification:', msg);
|
console.log('notification:', msg);
|
||||||
const message = msg as BalanceNotification;
|
const message = msg as BalanceNotification;
|
||||||
message.icon = 'mdi-cash';
|
message.icon = 'mdi-cash';
|
||||||
|
@ -18,23 +20,26 @@ function transpile(msg: FG_Plugin.Notification) {
|
||||||
if (message.data.type === BalanceTypes.send_from) {
|
if (message.data.type === BalanceTypes.send_from) {
|
||||||
const receiver = <FG.User>store.findUser((<SendFromNotification>message.data).receiver_id);
|
const receiver = <FG.User>store.findUser((<SendFromNotification>message.data).receiver_id);
|
||||||
const author = <FG.User>store.findUser((<SendFromNotification>message.data).author_id);
|
const author = <FG.User>store.findUser((<SendFromNotification>message.data).author_id);
|
||||||
message.text = `${author.display_name} hat ${message.data.amount.toFixed(2)}€ von dir zu ${
|
message.text = `${author.display_name} hat ${message.data.amount.toFixed(2)}€ von dir zu ${receiver.display_name
|
||||||
receiver.display_name
|
|
||||||
} überwiesen.`;
|
} überwiesen.`;
|
||||||
} else {
|
} else if (message.data.type === BalanceTypes.send_to) {
|
||||||
const sender = <FG.User>store.findUser((<SendToNotification>message.data).sender_id);
|
const sender = <FG.User>store.findUser((<SendToNotification>message.data).sender_id);
|
||||||
console.log(sender);
|
console.log(sender);
|
||||||
message.text = `${sender.display_name} hat dir ${message.data.amount.toFixed(2)}€ überwiesen.`;
|
message.text = `${sender.display_name} hat dir ${message.data.amount.toFixed(2)}€ überwiesen.`;
|
||||||
|
} else {
|
||||||
|
const author = <FG.User>store.findUser((<TransactionNotification>message.data).author_id);
|
||||||
|
const abgebucht = message.data.type === BalanceTypes.add_from ? 'aufgeladen' : 'abgebucht';
|
||||||
|
message.text = `${author.display_name} hat ${message.data.amount.toFixed(2)}€ dir ${abgebucht}.`;
|
||||||
}
|
}
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
const plugin: FG_Plugin.Plugin = {
|
const plugin: FG_Plugin.Plugin = {
|
||||||
id: 'dev.flaschengeist.balance',
|
id: 'balance',
|
||||||
name: 'Balance',
|
name: 'Balance',
|
||||||
innerRoutes: routes,
|
innerRoutes: routes,
|
||||||
requiredModules: [['balance']],
|
requiredModules: [['balance']],
|
||||||
version: '0.0.2',
|
version: '1.0.0',
|
||||||
notification: transpile,
|
notification: transpile,
|
||||||
widgets: [
|
widgets: [
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,17 +5,37 @@
|
||||||
:rows="rows"
|
:rows="rows"
|
||||||
row-key="userid"
|
row-key="userid"
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
@request="onRequest"
|
|
||||||
:filter="filter"
|
:filter="filter"
|
||||||
|
@request="onRequest"
|
||||||
>
|
>
|
||||||
<template #top-right>
|
<template #top-right>
|
||||||
<div class="full-width row q-gutter-sm">
|
<div class="full-width row q-gutter-sm">
|
||||||
<q-input v-model="filter" label="Filter" filled dense debounce="300">
|
<q-input v-model="filter" label="Filter" filled dense debounce="300">
|
||||||
<template v-slot:append>
|
<template #append>
|
||||||
<q-icon name="mdi-magnify" />
|
<q-icon name="mdi-magnify" />
|
||||||
</template>
|
</template>
|
||||||
</q-input>
|
</q-input>
|
||||||
<q-input v-model.number="limit" label="Limit" type="number" step="0.01" suffix="€" filled dense />
|
<q-input
|
||||||
|
ref="refLimit"
|
||||||
|
v-model.number="limit"
|
||||||
|
label="Limit"
|
||||||
|
type="number"
|
||||||
|
step="0.01"
|
||||||
|
suffix="€"
|
||||||
|
filled
|
||||||
|
dense
|
||||||
|
:rules="[check_cent_step]"
|
||||||
|
>
|
||||||
|
<template #prepend>
|
||||||
|
<q-btn
|
||||||
|
:icon="sign === '+' ? 'mdi-plus' : 'mdi-minus'"
|
||||||
|
round
|
||||||
|
flat
|
||||||
|
:text-color="sign === '+' ? 'secondary' : 'negative'"
|
||||||
|
@click="changeSign"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</q-input>
|
||||||
<q-btn label="Limits Setzen" color="primary" dense @click="setLimits(limit)" />
|
<q-btn label="Limits Setzen" color="primary" dense @click="setLimits(limit)" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -35,15 +55,24 @@
|
||||||
buttons
|
buttons
|
||||||
label-cancel="Abbrechen"
|
label-cancel="Abbrechen"
|
||||||
label-set="Speichern"
|
label-set="Speichern"
|
||||||
@save="setLimit(props.row.userid)"
|
@save="setLimit($event, props.row.userid)"
|
||||||
@cancel="limit = undefined"
|
@cancel="limit = undefined"
|
||||||
>
|
>
|
||||||
<q-input v-model.number="scope.value" label="Limit" type="number" step="0.01" suffix="€" filled dense />
|
<q-input v-model.number="scope.value" label="Limit" type="number" step="0.01" suffix="€" filled dense>
|
||||||
|
<template #prepend>
|
||||||
|
<q-btn :icon="sign === '+' ? 'mdi-plus' : 'mdi-minus'" round flat @click="changeSign" />
|
||||||
|
</template>
|
||||||
|
</q-input>
|
||||||
</q-popup-edit>
|
</q-popup-edit>
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td key="balance" :props="props">
|
<q-td key="balance" :props="props">
|
||||||
{{ getBalance(props.row.debit, props.row.credit) }}€
|
{{ getBalance(props.row.debit, props.row.credit) }}€
|
||||||
<q-menu anchor="bottom middle" self="top middle" :persistent="$q.platform.is.mobile">
|
<q-menu
|
||||||
|
v-model="showMenu[props.row.userid]"
|
||||||
|
anchor="bottom middle"
|
||||||
|
self="top middle"
|
||||||
|
:persistent="$q.platform.is.mobile"
|
||||||
|
>
|
||||||
<q-card>
|
<q-card>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<q-tab-panels v-model="tab" animated>
|
<q-tab-panels v-model="tab" animated>
|
||||||
|
@ -51,11 +80,14 @@
|
||||||
<balance-add-body
|
<balance-add-body
|
||||||
:user="props.row.userid"
|
:user="props.row.userid"
|
||||||
:can-add-shortcut="false"
|
:can-add-shortcut="false"
|
||||||
@change-balance="updateBalance"
|
@change-balance="updateBalance($event, props.row.userid)"
|
||||||
/>
|
/>
|
||||||
</q-tab-panel>
|
</q-tab-panel>
|
||||||
<q-tab-panel name="transfer" class="fit column q-gutter-sm">
|
<q-tab-panel name="transfer" class="fit column q-gutter-sm">
|
||||||
<balance-transfer-body :user="props.row.userid" @change-balance="updateBalances" />
|
<balance-transfer-body
|
||||||
|
:user="props.row.userid"
|
||||||
|
@change-balance="updateBalances($event, $event, props.row.userid)"
|
||||||
|
/>
|
||||||
</q-tab-panel>
|
</q-tab-panel>
|
||||||
</q-tab-panels>
|
</q-tab-panels>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
@ -84,9 +116,9 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
// TODO: Fill usefull data
|
|
||||||
|
|
||||||
import { ref, defineComponent, computed, onBeforeMount } from 'vue';
|
import { ref, defineComponent, computed, onBeforeMount } from 'vue';
|
||||||
|
import { QInput } from 'quasar';
|
||||||
|
import { check_cent_step } from '../utils';
|
||||||
import { useBalanceStore } from '../store';
|
import { useBalanceStore } from '../store';
|
||||||
import { useUserStore } from '@flaschengeist/api';
|
import { useUserStore } from '@flaschengeist/api';
|
||||||
import BalanceAddBody from '../components/BalanceAddBody.vue';
|
import BalanceAddBody from '../components/BalanceAddBody.vue';
|
||||||
|
@ -99,6 +131,9 @@ export default defineComponent({
|
||||||
const store = useBalanceStore();
|
const store = useBalanceStore();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
|
||||||
|
const showMenu = ref<{ [userid: string]: boolean }>({});
|
||||||
|
const refLimit = ref<QInput>();
|
||||||
|
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
void userStore.getUsers();
|
void userStore.getUsers();
|
||||||
void store.getLimits();
|
void store.getLimits();
|
||||||
|
@ -107,6 +142,7 @@ export default defineComponent({
|
||||||
|
|
||||||
const rows = computed(() => store.balances);
|
const rows = computed(() => store.balances);
|
||||||
const limit = ref<number>();
|
const limit = ref<number>();
|
||||||
|
const sign = ref<'+' | '-'>('-');
|
||||||
const filter = ref<string>();
|
const filter = ref<string>();
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
|
@ -183,7 +219,7 @@ export default defineComponent({
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(error);
|
console.warn(error);
|
||||||
}
|
}
|
||||||
console.log(pagination.value);
|
//console.log(pagination.value);
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,22 +236,30 @@ export default defineComponent({
|
||||||
return (credit - debit).toFixed(2);
|
return (credit - debit).toFixed(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateBalance(user: FG.User) {
|
async function updateBalance(user: FG.User, ref_showMenu?: string) {
|
||||||
void store.getBalance(user);
|
await store.getBalance(user);
|
||||||
|
if (ref_showMenu) {
|
||||||
|
showMenu.value[ref_showMenu] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function updateBalances({ sender, receiver }: { sender: FG.User; receiver: FG.User }, ref_showMenu?: string) {
|
||||||
|
await updateBalance(sender);
|
||||||
|
await updateBalance(receiver);
|
||||||
|
if (ref_showMenu) {
|
||||||
|
showMenu.value[ref_showMenu] = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateBalances(sender: FG.User, receiver: FG.User) {
|
async function setLimit(l: number, userid: string) {
|
||||||
updateBalance(sender);
|
if (sign.value === '-') {
|
||||||
updateBalance(receiver);
|
l = -l;
|
||||||
}
|
}
|
||||||
|
await refLimit.value?.validate();
|
||||||
function setLimit(userid: string) {
|
if (refLimit.value?.hasError) {
|
||||||
setTimeout(() => {
|
return;
|
||||||
void store.setLimit(<number>limit.value, userid);
|
}
|
||||||
}, 50);
|
await store.setLimit(l, userid);
|
||||||
setTimeout(() => {
|
|
||||||
limit.value = undefined;
|
limit.value = undefined;
|
||||||
}, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFirstname(userid: string) {
|
function getFirstname(userid: string) {
|
||||||
|
@ -226,13 +270,27 @@ export default defineComponent({
|
||||||
return userStore.users.find((a) => a.userid === userid)?.lastname;
|
return userStore.users.find((a) => a.userid === userid)?.lastname;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tab = ref('add');
|
function changeSign() {
|
||||||
|
sign.value = sign.value === '+' ? '-' : '+';
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setLimits(l: number) {
|
||||||
|
if (sign.value === '-') {
|
||||||
|
l = -l;
|
||||||
|
}
|
||||||
|
await refLimit.value?.validate();
|
||||||
|
if (refLimit.value?.hasError) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void store.setLimits(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tab = ref('add');
|
||||||
return {
|
return {
|
||||||
rows,
|
rows,
|
||||||
columns,
|
columns,
|
||||||
limit,
|
limit,
|
||||||
setLimits: (l: number) => store.setLimits(l),
|
setLimits,
|
||||||
getName,
|
getName,
|
||||||
getLimit,
|
getLimit,
|
||||||
setLimit,
|
setLimit,
|
||||||
|
@ -245,6 +303,11 @@ export default defineComponent({
|
||||||
getFirstname,
|
getFirstname,
|
||||||
getLastname,
|
getLastname,
|
||||||
filter,
|
filter,
|
||||||
|
showMenu,
|
||||||
|
sign,
|
||||||
|
changeSign,
|
||||||
|
check_cent_step,
|
||||||
|
refLimit,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -38,7 +38,8 @@
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { formatDateTime, useMainStore, useUserStore } from '@flaschengeist/api';
|
import { formatDateTime, useMainStore, useUserStore } from '@flaschengeist/api';
|
||||||
import { computed, defineComponent, onMounted, ref } from 'vue';
|
import { computed, defineComponent, onMounted, ref, watch } from 'vue';
|
||||||
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import { useBalanceStore } from '../store';
|
import { useBalanceStore } from '../store';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
|
@ -47,8 +48,12 @@ export default defineComponent({
|
||||||
const store = useBalanceStore();
|
const store = useBalanceStore();
|
||||||
const mainStore = useMainStore();
|
const mainStore = useMainStore();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
const router = useRouter();
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
|
if (route.query?.showCancelled == 'true') showCancelled.value = true;
|
||||||
|
await router.replace({ query: { showCancelled: showCancelled.value } });
|
||||||
void store.getBalance(mainStore.currentUser);
|
void store.getBalance(mainStore.currentUser);
|
||||||
void userStore.getUsers().then(() =>
|
void userStore.getUsers().then(() =>
|
||||||
onRequest({
|
onRequest({
|
||||||
|
@ -107,7 +112,7 @@ export default defineComponent({
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const balance = computed(() => store.balance?.balance || NaN);
|
const balance = computed(() => store.balance?.balance || 0);
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
|
@ -155,6 +160,14 @@ export default defineComponent({
|
||||||
return userStore.users.find((a) => a.userid === userid)?.display_name;
|
return userStore.users.find((a) => a.userid === userid)?.display_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(showCancelled, async () => {
|
||||||
|
await router.replace({ query: { showCancelled: showCancelled.value } });
|
||||||
|
await onRequest({
|
||||||
|
pagination: pagination.value,
|
||||||
|
filter: undefined,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return { data, pagination, onRequest, loading, balance, columns, showCancelled };
|
return { data, pagination, onRequest, loading, balance, columns, showCancelled };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
</q-list>
|
</q-list>
|
||||||
<q-list v-if="show">
|
<q-list v-if="show">
|
||||||
<div v-for="(transaction, index) in transactions" :key="index" class="col-sm-12">
|
<div v-for="(transaction, index) in transactions" :key="index" class="col-sm-12">
|
||||||
<balance-transaction v-model:transaction="transactions[index]" />
|
<balance-transaction v-model:transaction="transactions[index]" @update:transaction="updateBalance" />
|
||||||
</div>
|
</div>
|
||||||
</q-list>
|
</q-list>
|
||||||
</q-drawer>
|
</q-drawer>
|
||||||
|
@ -54,7 +54,8 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { computed, defineComponent, ref, onMounted } from 'vue';
|
import { computed, defineComponent, ref, onMounted, watch } from 'vue';
|
||||||
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import { hasSomePermissions, useMainStore } from '@flaschengeist/api';
|
import { hasSomePermissions, useMainStore } from '@flaschengeist/api';
|
||||||
import { useBalanceStore } from '../store';
|
import { useBalanceStore } from '../store';
|
||||||
import PERMISSIONS from '../permissions';
|
import PERMISSIONS from '../permissions';
|
||||||
|
@ -69,9 +70,15 @@ export default defineComponent({
|
||||||
setup() {
|
setup() {
|
||||||
const balanceStore = useBalanceStore();
|
const balanceStore = useBalanceStore();
|
||||||
const mainStore = useMainStore();
|
const mainStore = useMainStore();
|
||||||
|
const router = useRouter();
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
|
if (tabs.some((value) => value.name == route.query.q_tab)) {
|
||||||
|
tab.value = route.query.q_tab as string;
|
||||||
|
}
|
||||||
|
await router.replace({ query: { q_tab: tab.value } });
|
||||||
void balanceStore.getTransactions(mainStore.currentUser, {
|
void balanceStore.getTransactions(mainStore.currentUser, {
|
||||||
from: new Date(now.getFullYear(), now.getMonth(), now.getDate()),
|
from: new Date(now.getFullYear(), now.getMonth(), now.getDate()),
|
||||||
});
|
});
|
||||||
|
@ -111,6 +118,9 @@ export default defineComponent({
|
||||||
*/
|
*/
|
||||||
const showDrawer = ref<boolean>(false);
|
const showDrawer = ref<boolean>(false);
|
||||||
const tab = ref<string>(canAdd() ? 'add' : 'transfer');
|
const tab = ref<string>(canAdd() ? 'add' : 'transfer');
|
||||||
|
watch(tab, (val) => {
|
||||||
|
void router.replace({ query: { q_tab: val } });
|
||||||
|
});
|
||||||
const show = ref<boolean>(false);
|
const show = ref<boolean>(false);
|
||||||
return {
|
return {
|
||||||
showDrawer,
|
showDrawer,
|
||||||
|
@ -118,6 +128,7 @@ export default defineComponent({
|
||||||
tabs,
|
tabs,
|
||||||
transactions,
|
transactions,
|
||||||
show,
|
show,
|
||||||
|
updateBalance: () => balanceStore.getBalance(mainStore.currentUser),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -146,7 +146,13 @@ export const useBalanceStore = defineStore({
|
||||||
params: filter,
|
params: filter,
|
||||||
});
|
});
|
||||||
data.transactions.forEach((t) => fixTransaction(t));
|
data.transactions.forEach((t) => fixTransaction(t));
|
||||||
if (data.transactions) this.transactions.push(...data.transactions);
|
if (data.transactions) {
|
||||||
|
data.transactions.forEach((t) => {
|
||||||
|
const idx = this.transactions.findIndex((x) => x.id === t.id);
|
||||||
|
if (idx == -1) this.transactions.push(t);
|
||||||
|
else this.transactions[idx] = t;
|
||||||
|
});
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
export function check_cent_step(value: number): boolean | string {
|
||||||
|
return (value * 100) % 1 === 0 || 'Betrag muss in 1-Cent-Schritten angegeben werden';
|
||||||
|
}
|
Loading…
Reference in New Issue