mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Rollback #3382
This commit is contained in:
@@ -25,7 +25,6 @@ namespace FireflyIII\Support\Twig;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DB;
|
use DB;
|
||||||
use FireflyIII\Models\Account;
|
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
@@ -63,7 +62,7 @@ class TransactionGroupTwig extends AbstractExtension
|
|||||||
{
|
{
|
||||||
return new TwigFunction(
|
return new TwigFunction(
|
||||||
'groupAmount',
|
'groupAmount',
|
||||||
function (array $array, Account $account): string {
|
function (array $array): string {
|
||||||
$sums = $array['sums'];
|
$sums = $array['sums'];
|
||||||
$return = [];
|
$return = [];
|
||||||
$first = reset($array['transactions']);
|
$first = reset($array['transactions']);
|
||||||
@@ -79,8 +78,7 @@ class TransactionGroupTwig extends AbstractExtension
|
|||||||
$amount = $sum['amount'];
|
$amount = $sum['amount'];
|
||||||
|
|
||||||
$sourceType = $first['source_account_type'] ?? 'invalid';
|
$sourceType = $first['source_account_type'] ?? 'invalid';
|
||||||
$sourceAccountId = $first['source_account_id'];
|
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||||
$amount = $this->signAmountFromAccountPOV($amount, $type, $sourceType, $sourceAccountId, $account->id);
|
|
||||||
|
|
||||||
$return[] = app('amount')->formatFlat($sum['currency_symbol'], (int)$sum['currency_decimal_places'], $amount, $colored);
|
$return[] = app('amount')->formatFlat($sum['currency_symbol'], (int)$sum['currency_decimal_places'], $amount, $colored);
|
||||||
}
|
}
|
||||||
@@ -172,12 +170,12 @@ class TransactionGroupTwig extends AbstractExtension
|
|||||||
{
|
{
|
||||||
return new TwigFunction(
|
return new TwigFunction(
|
||||||
'journalArrayAmount',
|
'journalArrayAmount',
|
||||||
function (array $journal, Account $account): string {
|
function (array $array): string {
|
||||||
// if is not a withdrawal, amount positive.
|
// if is not a withdrawal, amount positive.
|
||||||
$result = $this->normalJournalArrayAmount($journal, $account);
|
$result = $this->normalJournalArrayAmount($array);
|
||||||
// now append foreign amount, if any.
|
// now append foreign amount, if any.
|
||||||
if (null !== $journal['foreign_amount']) {
|
if (null !== $array['foreign_amount']) {
|
||||||
$foreign = $this->foreignJournalArrayAmount($journal, $account);
|
$foreign = $this->foreignJournalArrayAmount($array);
|
||||||
$result = sprintf('%s (%s)', $result, $foreign);
|
$result = sprintf('%s (%s)', $result, $foreign);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,25 +211,23 @@ class TransactionGroupTwig extends AbstractExtension
|
|||||||
/**
|
/**
|
||||||
* Generate foreign amount for transaction from a transaction group.
|
* Generate foreign amount for transaction from a transaction group.
|
||||||
*
|
*
|
||||||
* @param array $journal
|
* @param array $array
|
||||||
* @param Account $account
|
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function foreignJournalArrayAmount(array $journal, Account $account): string
|
private function foreignJournalArrayAmount(array $array): string
|
||||||
{
|
{
|
||||||
$type = $journal['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
|
$type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
|
||||||
$amount = $journal['foreign_amount'] ?? '0';
|
$amount = $array['foreign_amount'] ?? '0';
|
||||||
$colored = true;
|
$colored = true;
|
||||||
|
|
||||||
$sourceType = $journal['source_account_type'] ?? 'invalid';
|
$sourceType = $array['source_account_type'] ?? 'invalid';
|
||||||
$sourceAccountId = $journal['source_account_id'];
|
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||||
$amount = $this->signAmountFromAccountPOV($amount, $type, $sourceType, $sourceAccountId, $account->id);
|
|
||||||
|
|
||||||
if ($type === TransactionType::TRANSFER) {
|
if ($type === TransactionType::TRANSFER) {
|
||||||
$colored = false;
|
$colored = false;
|
||||||
}
|
}
|
||||||
$result = app('amount')->formatFlat($journal['foreign_currency_symbol'], (int)$journal['foreign_currency_decimal_places'], $amount, $colored);
|
$result = app('amount')->formatFlat($array['foreign_currency_symbol'], (int)$array['foreign_currency_decimal_places'], $amount, $colored);
|
||||||
if ($type === TransactionType::TRANSFER) {
|
if ($type === TransactionType::TRANSFER) {
|
||||||
$result = sprintf('<span class="text-info">%s</span>', $result);
|
$result = sprintf('<span class="text-info">%s</span>', $result);
|
||||||
}
|
}
|
||||||
@@ -277,14 +273,13 @@ class TransactionGroupTwig extends AbstractExtension
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function normalJournalArrayAmount(array $journal, Account $account): string
|
private function normalJournalArrayAmount(array $journal): string
|
||||||
{
|
{
|
||||||
$type = $journal['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
|
$type = $journal['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
|
||||||
$amount = $journal['amount'] ?? '0';
|
$amount = $journal['amount'] ?? '0';
|
||||||
$colored = true;
|
$colored = true;
|
||||||
$sourceType = $journal['source_account_type'] ?? 'invalid';
|
$sourceType = $journal['source_account_type'] ?? 'invalid';
|
||||||
$sourceAccountId = $journal['source_account_id'];
|
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||||
$amount = $this->signAmount($amount, $type, $sourceType, $sourceAccountId, $account->id);
|
|
||||||
|
|
||||||
if ($type === TransactionType::TRANSFER) {
|
if ($type === TransactionType::TRANSFER) {
|
||||||
$colored = false;
|
$colored = false;
|
||||||
@@ -358,16 +353,4 @@ class TransactionGroupTwig extends AbstractExtension
|
|||||||
|
|
||||||
return $amount;
|
return $amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function signAmountFromAccountPOV(string $amount, string $transactionType, string $sourceType, int $sourceAccountId, $displayedAccountId): string {
|
|
||||||
$amount = $this->signAmount( $amount, $transactionType, $sourceType );
|
|
||||||
|
|
||||||
// transfers stay negative from source point of view
|
|
||||||
if ($transactionType === TransactionType::TRANSFER
|
|
||||||
&& $sourceAccountId === $displayedAccountId) {
|
|
||||||
$amount = bcmul($amount, '-1');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $amount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -4,14 +4,14 @@
|
|||||||
{% for transaction in group.transactions %}
|
{% for transaction in group.transactions %}
|
||||||
{{ transaction.description }}
|
{{ transaction.description }}
|
||||||
<span class="pull-right small">
|
<span class="pull-right small">
|
||||||
{{ journalArrayAmount(transaction, account) }}
|
{{ journalArrayAmount(transaction) }}
|
||||||
</span>
|
</span>
|
||||||
<br/>
|
<br/>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if group.count > 1 %}
|
{% if group.count > 1 %}
|
||||||
|
|
||||||
<span class="pull-right small">
|
<span class="pull-right small">
|
||||||
{{ groupAmount(group, account) }}
|
{{ groupAmount(group) }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
|
Reference in New Issue
Block a user