Fix transaction lists.

This commit is contained in:
James Cole
2022-07-17 08:51:53 +02:00
parent 6b6107fb00
commit eb8f595541
4 changed files with 98 additions and 33 deletions

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Transformers\V2; namespace FireflyIII\Transformers\V2;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use Illuminate\Support\Collection;
/** /**
* Class AccountTransformer * Class AccountTransformer
@@ -83,4 +84,11 @@ class AccountTransformer extends AbstractTransformer
]; ];
} }
/**
* @inheritDoc
*/
public function collectMetaData(Collection $objects): void
{
// TODO: Implement collectMetaData() method.
}
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Transformers\V2; namespace FireflyIII\Transformers\V2;
use FireflyIII\Models\Preference; use FireflyIII\Models\Preference;
use Illuminate\Support\Collection;
/** /**
* Class PreferenceTransformer * Class PreferenceTransformer
@@ -49,4 +50,11 @@ class PreferenceTransformer extends AbstractTransformer
} }
/**
* @inheritDoc
*/
public function collectMetaData(Collection $objects): void
{
// TODO: Implement collectMetaData() method.
}
} }

View File

@@ -89,13 +89,13 @@ class TransactionGroupTransformer extends AbstractTransformer
$type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL); $type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL);
$amount = app('steam')->positive((string) ($transaction['amount'] ?? '0')); $amount = app('steam')->positive((string) ($transaction['amount'] ?? '0'));
$foreignAmount = null; $foreignAmount = null;
$foreignNativeAmount = null; $nativeForeignAmount = null;
if (null !== $transaction['foreign_amount']) { if (null !== $transaction['foreign_amount']) {
$foreignAmount = app('steam')->positive($transaction['foreign_amount']); $foreignAmount = app('steam')->positive($transaction['foreign_amount']);
$foreignNativeAmount = $foreignAmount; $nativeForeignAmount = $foreignAmount;
if ($transaction['foreign_currency_id'] !== $this->default->id) { if ($transaction['foreign_currency_id'] !== $this->default->id) {
$rate = $this->getRate($this->currencies[$transaction['foreign_currency_id']], $this->default, $transaction['date']); $rate = $this->getRate($this->currencies[$transaction['foreign_currency_id']], $this->default, $transaction['date']);
$foreignNativeAmount = bcmul($foreignAmount, $rate); $nativeForeignAmount = bcmul($foreignAmount, $rate);
} }
} }
@@ -137,7 +137,7 @@ class TransactionGroupTransformer extends AbstractTransformer
'amount' => $amount, 'amount' => $amount,
'native_amount' => $nativeAmount, 'native_amount' => $nativeAmount,
'foreign_amount' => $foreignAmount, 'foreign_amount' => $foreignAmount,
'foreign_native_amount' => $foreignNativeAmount, 'native_foreign_amount' => $nativeForeignAmount,
'description' => $transaction['description'], 'description' => $transaction['description'],
'source_id' => (string) $transaction['source_account_id'], 'source_id' => (string) $transaction['source_account_id'],
'source_name' => $transaction['source_account_name'], 'source_name' => $transaction['source_account_name'],

View File

@@ -27,37 +27,70 @@
</q-item-section> </q-item-section>
</q-item> </q-item>
<q-separator/> <q-separator/>
<q-markup-table> <q-markup-table>
<thead> <thead>
<tr> <tr>
<th class="text-left">Description</th> <th class="text-left">Description</th>
<th class="text-right">Opposing account</th> <th class="text-right">Opposing account</th>
<th class="text-right">Amount</th> <th class="text-right">Amount</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="transaction in transactions"> <tr v-for="transaction in transactions">
<td class="text-left"> <td class="text-left">
<router-link :to="{ name: 'transactions.show', params: {id: transaction.transactionGroupId} }"> <router-link :to="{ name: 'transactions.show', params: {id: transaction.transactionGroupId} }">
<strong v-if="transaction.transactions.length > 1"> <strong v-if="transaction.transactions.length > 1">
{{ transaction.transactionGroupTitle }}<br /> {{ transaction.transactionGroupTitle }}<br/>
</strong> </strong>
</router-link> </router-link>
<span v-for="tr in transaction.transactions"> <span v-for="tr in transaction.transactions">
<span v-if="transaction.transactions.length > 1"> <span v-if="transaction.transactions.length > 1">
{{tr.description}} {{ tr.description }}
<br /> <br/>
</span> </span>
<router-link :to="{ name: 'transactions.show', params: {id: transaction.transactionGroupId} }" v-if="transaction.transactions.length === 1"> <router-link :to="{ name: 'transactions.show', params: {id: transaction.transactionGroupId} }"
{{tr.description}} v-if="transaction.transactions.length === 1">
{{ tr.description }}
</router-link> </router-link>
</span> </span>
</td> </td>
<td class="text-right">159</td> <td class="text-right">
<td class="text-right">6</td> <!-- withdrawal -->
</tr> <!-- deposit -->
</tbody> <!-- transfer -->
</q-markup-table> <!-- other -->
<span v-if="transaction.transactions.length > 1"><br></span>
<span v-for="tr in transaction.transactions">
<router-link :to="{ name: 'accounts.show', params: {id: tr.destination_id} }">
{{ tr.destination_name }}
</router-link>
<br v-if="transaction.transactions.length > 1"/>
</span>
</td>
<td class="text-right">
<span v-if="transaction.transactions.length > 1"><br></span>
<!-- per transaction -->
<span v-for="tr in transaction.transactions">
<!-- simply show the amount -->
<span v-if="false === tr.native_currency_converted">{{ formatAmount(tr.currency_code, tr.amount) }}</span>
<!-- show amount with original in the title -->
<span v-if="true === tr.native_currency_converted" :title="formatAmount(tr.currency_code, tr.amount)">{{
formatAmount(tr.native_currency_code, tr.native_amount)
}}</span>
<!-- show foreign amount if present and not converted (may lead to double amounts) -->
<span v-if="null !== tr.foreign_amount">
<span v-if="false === tr.foreign_currency_converted"> ({{ formatAmount(tr.foreign_currency_code, tr.foreign_amount) }})</span>
<span v-if="true === tr.foreign_currency_converted" :title="formatAmount(tr.foreign_currency_code, tr.foreign_amount)"> ({{ formatAmount(tr.native_currency_code, tr.native_foreign_amount) }})</span>
</span>
<br v-if="transaction.transactions.length > 1"/>
</span>
</td>
</tr>
</tbody>
</q-markup-table>
</q-card> </q-card>
</div> </div>
</template> </template>
@@ -118,6 +151,10 @@ export default {
}).then((response) => this.parseTransactions(response.data)); }).then((response) => this.parseTransactions(response.data));
} }
}, },
// TODO this method is recycled a lot.
formatAmount: function (currencyCode, amount) {
return Intl.NumberFormat(this.store.getLocale, {style: 'currency', currency: currencyCode}).format(amount);
},
parseTransactions: function (data) { parseTransactions: function (data) {
for (let i in data.data) { for (let i in data.data) {
if (data.data.hasOwnProperty(i)) { if (data.data.hasOwnProperty(i)) {
@@ -133,11 +170,23 @@ export default {
let iic = { let iic = {
journalId: transaction.transaction_journal_id, journalId: transaction.transaction_journal_id,
description: transaction.description, description: transaction.description,
amount: transaction.amount,
currency_code: transaction.currency_code,
destination_name: transaction.destination_name, destination_name: transaction.destination_name,
destination_id: transaction.destination_id, destination_id: transaction.destination_id,
type: transaction.type, type: transaction.type,
amount: transaction.amount,
native_amount: transaction.native_amount,
foreign_amount: transaction.foreign_amount,
native_foreign_amount: transaction.native_foreign_amount,
currency_code: transaction.currency_code,
native_currency_code: transaction.native_currency_code,
foreign_currency_code: transaction.foreign_currency_code,
native_currency_converted: transaction.native_currency_converted,
foreign_currency_converted: transaction.foreign_currency_converted,
}; };
ic.transactions.push(iic); ic.transactions.push(iic);
} }