Expand frontend and API

This commit is contained in:
James Cole
2022-07-05 19:12:22 +02:00
parent 196c504b3d
commit 56ff25285c
5 changed files with 83 additions and 37 deletions

View File

@@ -104,7 +104,7 @@ class UpdatePiggybank implements ActionInterface
) )
); );
return true; return false;
} }
/** /**

View File

@@ -37,13 +37,12 @@ class TransactionGroupTransformer extends AbstractTransformer
public function transform(array $group): array public function transform(array $group): array
{ {
$first = reset($group['transactions']); $first = reset($group['transactions']);
return [ return [
'id' => (string) $group['id'], 'id' => (string) $group['id'],
'created_at' => $first['created_at']->toAtomString(), 'created_at' => $first['created_at']->toAtomString(),
'updated_at' => $first['updated_at']->toAtomString(), 'updated_at' => $first['updated_at']->toAtomString(),
'user' => (string) $first['user_id'], 'user' => (string) $first['user_id'],
'group_title' => $group['group_title'] ?? null, 'group_title' => $group['title'] ?? null,
'transactions' => $this->transformTransactions($group['transactions'] ?? []), 'transactions' => $this->transformTransactions($group['transactions'] ?? []),
'links' => [ 'links' => [
[ [

View File

@@ -104,7 +104,7 @@ export default {
if (!current.converted) { if (!current.converted) {
this.primary = this.primary + parseFloat(current.sum); this.primary = this.primary + parseFloat(current.sum);
} }
if(parseFloat(current.sum) !== 0.0) {
this.netWorth.push( this.netWorth.push(
{ {
sum: current.sum, sum: current.sum,
@@ -116,6 +116,7 @@ export default {
); );
} }
} }
}
}, },
// TODO this method is recycled a lot. // TODO this method is recycled a lot.
formatAmount: function (currencyCode, amount) { formatAmount: function (currencyCode, amount) {

View File

@@ -23,18 +23,41 @@
<q-card bordered> <q-card bordered>
<q-item> <q-item>
<q-item-section> <q-item-section>
<q-item-label><strong>{{ accountName }}</strong></q-item-label> <q-item-label><strong>{{ accountName }}</strong> (balance)</q-item-label>
</q-item-section> </q-item-section>
</q-item> </q-item>
<q-separator/> <q-separator/>
<q-item> <q-markup-table>
<q-card-section horizontal> <thead>
Content <tr>
</q-card-section> <th class="text-left">Description</th>
</q-item> <th class="text-right">Opposing account</th>
<th class="text-right">Amount</th>
</tr>
<!-- X: {{ accountId }} --> </thead>
<tbody>
<tr v-for="transaction in transactions">
<td class="text-left">
<router-link :to="{ name: 'transactions.show', params: {id: transaction.transactionGroupId} }">
<strong v-if="transaction.transactions.length > 1">
{{ transaction.transactionGroupTitle }}<br />
</strong>
</router-link>
<span v-for="tr in transaction.transactions">
<span v-if="transaction.transactions.length > 1">
{{tr.description}}
<br />
</span>
<router-link :to="{ name: 'transactions.show', params: {id: transaction.transactionGroupId} }" v-if="transaction.transactions.length === 1">
{{tr.description}}
</router-link>
</span>
</td>
<td class="text-right">159</td>
<td class="text-right">6</td>
</tr>
</tbody>
</q-markup-table>
</q-card> </q-card>
</div> </div>
</template> </template>
@@ -52,7 +75,8 @@ export default {
data() { data() {
return { return {
store: null, store: null,
accountName: '' accountName: '',
transactions: [],
} }
}, },
mounted() { mounted() {
@@ -86,20 +110,42 @@ export default {
const end = new Date(this.store.getRange.end); const end = new Date(this.store.getRange.end);
let startStr = format(start, 'y-MM-dd'); let startStr = format(start, 'y-MM-dd');
let endStr = format(end, 'y-MM-dd'); let endStr = format(end, 'y-MM-dd');
(new Get).transactions(this.accountId, { (new Get).transactions(this.accountId,
{
start: startStr, start: startStr,
end: endStr end: endStr,
limit: 10
}).then((response) => this.parseTransactions(response.data)); }).then((response) => this.parseTransactions(response.data));
} }
}, },
parseTransactions: function () { parseTransactions: function (data) {
for (let i in data.data) {
if (data.data.hasOwnProperty(i)) {
let group = data.data[i];
let ic = {
transactionGroupId: group.id,
transactionGroupTitle: group.attributes.group_title,
transactions: [],
};
for (let ii in group.attributes.transactions) {
if (group.attributes.transactions.hasOwnProperty(ii)) {
let transaction = group.attributes.transactions[ii];
let iic = {
journalId: transaction.transaction_journal_id,
description: transaction.description,
amount: transaction.amount,
currency_code: transaction.currency_code,
destination_name: transaction.destination_name,
destination_id: transaction.destination_id,
type: transaction.type,
};
ic.transactions.push(iic);
}
}
this.transactions.push(ic);
}
}
} }
}, },
} }
</script> </script>
<style scoped>
</style>

View File

@@ -20,7 +20,7 @@
<template> <template>
<div class="row"> <div class="row">
<div class="col q-mr-sm" v-for="(account, index) in accounts"> <div class="col q-mr-sm" v-for="(account) in accounts">
<TransactionList :account-id="account" /> <TransactionList :account-id="account" />
</div> </div>
</div> </div>