Compare commits

...

4 Commits

Author SHA1 Message Date
Tim Gröger b6275f7478 add big sign for #32
default, there is a negative sign (in color red)
When you click on the sign, the sign change
When the sign is a positive sigen the color ist turquoise
2023-05-14 01:06:37 +02:00
Tim Gröger 4abcedce3a add query for tabs add and transfer, also for show storno 2023-05-13 00:18:50 +02:00
Tim Gröger 345227f5d4 fix notifications, add notification when authorized person do debit or credit 2023-05-10 01:11:09 +02:00
Tim Gröger a876f99e13 fix update balance on adminpage #31 2023-05-10 00:27:41 +02:00
7 changed files with 114 additions and 50 deletions

7
src/balance.d.ts vendored
View File

@ -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);
} }

View File

@ -3,7 +3,7 @@
<q-input v-model.number="amount" type="number" filled label="Eigener Betrag" step="0.1" min="0" suffix="€" /> <q-input v-model.number="amount" type="number" filled label="Eigener Betrag" step="0.1" min="0" suffix="€" />
</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 +13,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"
@ -39,7 +38,7 @@ 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();
@ -47,7 +46,7 @@ export default defineComponent({
const amount = ref<number>(0); const amount = ref<number>(0);
async function changeBalance(amount: number) { async function changeBalance(amount: number) {
await store.changeBalance(amount, user.value); await store.changeBalance(amount, user.value);
emit('changeBalance', user.value); emit('change-balance', user.value);
} }
function addShortcut() { function addShortcut() {
if (amount.value != 0) void store.createShortcut(amount.value * -1); if (amount.value != 0) void store.createShortcut(amount.value * -1);

View File

@ -6,14 +6,7 @@
<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">
@ -31,7 +24,7 @@ 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();
@ -51,7 +44,7 @@ export default defineComponent({
async function sendAmount() { async function sendAmount() {
if (receiver.value) { if (receiver.value) {
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 {

View File

@ -1,12 +1,14 @@
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) {
@ -21,16 +23,20 @@ function transpile(msg: FG_Plugin.Notification) {
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']],

View File

@ -5,17 +5,27 @@
: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 v-model.number="limit" label="Limit" type="number" step="0.01" suffix="€" filled dense>
<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 +45,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 +70,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,8 +106,6 @@
</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 { useBalanceStore } from '../store'; import { useBalanceStore } from '../store';
import { useUserStore } from '@flaschengeist/api'; import { useUserStore } from '@flaschengeist/api';
@ -99,6 +119,8 @@ export default defineComponent({
const store = useBalanceStore(); const store = useBalanceStore();
const userStore = useUserStore(); const userStore = useUserStore();
const showMenu = ref<{ [userid: string]: boolean }>({});
onBeforeMount(() => { onBeforeMount(() => {
void userStore.getUsers(); void userStore.getUsers();
void store.getLimits(); void store.getLimits();
@ -107,6 +129,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 +206,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 +223,26 @@ 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 store.setLimit(l, userid);
function setLimit(userid: string) { limit.value = undefined;
setTimeout(() => {
void store.setLimit(<number>limit.value, userid);
}, 50);
setTimeout(() => {
limit.value = undefined;
}, 100);
} }
function getFirstname(userid: string) { function getFirstname(userid: string) {
@ -226,13 +253,23 @@ 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 === '+' ? '-' : '+';
}
function setLimits(l: number) {
if (sign.value === '-') {
l = -l;
}
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 +282,9 @@ export default defineComponent({
getFirstname, getFirstname,
getLastname, getLastname,
filter, filter,
showMenu,
sign,
changeSign,
}; };
}, },
}); });

View File

@ -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({
@ -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 };
}, },
}); });

View File

@ -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,