This commit is contained in:
2024-11-19 12:58:08 +01:00
parent 44fe789f5d
commit 7b07f0861a
3 changed files with 59 additions and 10 deletions
@@ -59,7 +59,7 @@
<tbody> <tbody>
<tr v-for="(item, index) in transaction.transactionItems" :key="index" class="transaction-item"> <tr v-for="(item, index) in transaction.transactionItems" :key="index" class="transaction-item">
<td> <td>
{{ index }} {{ index + 1 }}
</td> </td>
<td> <td>
{{ item.userAccount?.name }} {{ item.userAccount?.name }}
@@ -24,6 +24,7 @@ export default defineComponent({
const accountService = inject<AccountService>('accountService'); const accountService = inject<AccountService>('accountService');
const isFetching = ref(false); const isFetching = ref(false);
const sums: Ref<number[]> = ref([]);
const clear = () => {}; const clear = () => {};
// console.log(props.userAccountId); // console.log(props.userAccountId);
@@ -34,6 +35,7 @@ export default defineComponent({
const res = await transactionService().retrieve(); const res = await transactionService().retrieve();
// const res = await transactionService().retrieveForAccount(props.userAccountId); // const res = await transactionService().retrieveForAccount(props.userAccountId);
transactions.value = res.data; transactions.value = res.data;
sums.value = sumAmountsPerColumn(transactions.value);
} catch (err) { } catch (err) {
alertService.showHttpError(err.response); alertService.showHttpError(err.response);
} finally { } finally {
@@ -71,12 +73,32 @@ export default defineComponent({
} }
}; };
function sumAmountsPerColumn(transactions: ITransaction[]): number[] {
// Jeżeli nie ma transakcji, zwracamy pustą tablicę
if (transactions.length === 0) return [];
// Liczba kolumn to liczba transactionItems w pierwszej transakcji
const columnCount = transactions[0].items.length;
// Inicjalizacja tablicy sum z zerami dla każdej kolumny
const sums = new Array(columnCount).fill(0);
// Iteracja przez każdą transakcję
for (const transaction of transactions) {
for (let i = 0; i < columnCount; i++) {
// Dodajemy amount z każdego transactionItem do odpowiedniej kolumny
sums[i] += transaction.items[i].amount;
}
}
return sums;
}
return { return {
transactions, transactions,
handleSyncList, handleSyncList,
isFetching, isFetching,
retrieveTransactions, retrieveTransactions,
clear, clear,
sums,
removeId, removeId,
accountService, accountService,
hasAnyAuthorityValues, hasAnyAuthorityValues,
@@ -27,26 +27,53 @@
<table class="table table-striped" aria-describedby="transactions"> <table class="table table-striped" aria-describedby="transactions">
<thead> <thead>
<tr> <tr>
<th scope="row"><span>ID</span></th> <!-- <th/>-->
<th scope="row"><span>Type</span></th> <!-- <th/>-->
<th scope="row"><span>Date</span></th> <!-- <th/>-->
<th scope="row"><span>Comment</span></th> <th />
<th />
<th scope="row"><span>Event</span></th>
<th scope="row" v-for="item in transactions[0].items"> <th scope="row" v-for="item in transactions[0].items">
<span>{{ item.userAccount?.name }}</span> <span>{{ item.userAccount?.name }}</span>
</th> </th>
<th scope="row"></th> <th scope="row"></th>
</tr> </tr>
<tr>
<!-- <th/>-->
<!-- <th/>-->
<!-- <th/>-->
<th />
<th>Saldo</th>
<th v-for="amount in sums">
<span class="bold">{{ amount }}</span>
</th>
</tr>
<tr>
<!-- <th scope="row"><span>ID</span></th>-->
<!-- <th scope="row"><span>Type</span></th>-->
<th scope="row"><span>Date</span></th>
<!-- <th scope="row"><span>Comment</span></th>-->
<th scope="row"><span></span></th>
<!-- <th scope="row"><span>Transactions:</span></th>-->
<th scope="row" v-for="item in transactions[0].items">
<span></span>
<!-- <span>{{ item.userAccount?.name }}</span>-->
</th>
<th scope="row"></th>
</tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="transaction in transactions" :key="transaction.id" data-cy="entityTable"> <tr v-for="transaction in transactions" :key="transaction.id" data-cy="entityTable">
<td> <td>
<router-link :to="{ name: 'TransactionView', params: { transactionId: transaction.id } }">{{ transaction.id }}</router-link> <router-link :to="{ name: 'TransactionView', params: { transactionId: transaction.id } }"
>{{ transaction.date }} {{ transaction.type }}
</router-link>
<div v-if="transaction.comment">{{ transaction.comment }}</div>
</td> </td>
<td>{{ transaction.type }}</td> <!-- <td>{{ transaction.type }}</td>-->
<td>{{ transaction.date }}</td> <!-- <td>{{ transaction.date }}</td>-->
<td>{{ transaction.comment }}</td> <!-- <td>{{ transaction.comment }}</td>-->
<td> <td>
<div v-if="transaction.event"> <div v-if="transaction.event">
<router-link :to="{ name: 'EventView', params: { eventId: transaction.event.id } }">{{ <router-link :to="{ name: 'EventView', params: { eventId: transaction.event.id } }">{{