diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index eab304c96c..9a5a2be73c 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -352,24 +352,54 @@ class TagRepository implements TagRepositoryInterface $collector->setTag($tag)->withAccountInformation(); $journals = $collector->getExtractedJournals(); - $sums = [ - TransactionType::WITHDRAWAL => '0', - TransactionType::DEPOSIT => '0', - TransactionType::TRANSFER => '0', - TransactionType::RECONCILIATION => '0', - TransactionType::OPENING_BALANCE => '0', - ]; + $sums = []; /** @var array $journal */ foreach ($journals as $journal) { - $amount = app('steam')->positive((string)$journal['amount']); + $currencyId = (int) $journal['currency_id']; + $sums[$currencyId] = $sums[$currencyId] ?? [ + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + TransactionType::WITHDRAWAL => '0', + TransactionType::DEPOSIT => '0', + TransactionType::TRANSFER => '0', + TransactionType::RECONCILIATION => '0', + TransactionType::OPENING_BALANCE => '0', + ]; + + // add amount to correct type: + $amount = app('steam')->positive((string) $journal['amount']); $type = $journal['transaction_type_type']; if (TransactionType::WITHDRAWAL === $type) { $amount = bcmul($amount, '-1'); } - $sums[$type] = bcadd($sums[$type], $amount); - } + $sums[$currencyId][$type] = bcadd($sums[$currencyId][$type], $amount); + $foreignCurrencyId = $journal['foreign_currency_id']; + if (null !== $foreignCurrencyId) { + $sums[$foreignCurrencyId] = $sums[$foreignCurrencyId] ?? [ + 'currency_id' => $foreignCurrencyId, + 'currency_name' => $journal['foreign_currency_name'], + 'currency_symbol' => $journal['foreign_currency_symbol'], + 'currency_decimal_places' => $journal['foreign_currency_decimal_places'], + TransactionType::WITHDRAWAL => '0', + TransactionType::DEPOSIT => '0', + TransactionType::TRANSFER => '0', + TransactionType::RECONCILIATION => '0', + TransactionType::OPENING_BALANCE => '0', + ]; + // add foreign amount to correct type: + $amount = app('steam')->positive((string) $journal['foreign_amount']); + $type = $journal['transaction_type_type']; + if (TransactionType::WITHDRAWAL === $type) { + $amount = bcmul($amount, '-1'); + } + $sums[$foreignCurrencyId][$type] = bcadd($sums[$foreignCurrencyId][$type], $amount); + + } + } return $sums; } @@ -404,7 +434,7 @@ class TagRepository implements TagRepositoryInterface Log::debug(sprintf('Each coin in a tag earns it %s points', $pointsPerCoin)); /** @var Tag $tag */ foreach ($tags as $tag) { - $amount = (string)$tag->amount_sum; + $amount = (string) $tag->amount_sum; $amount = '' === $amount ? '0' : $amount; $amountMin = bcsub($amount, $min); $pointsForTag = bcmul($amountMin, $pointsPerCoin); @@ -496,7 +526,7 @@ class TagRepository implements TagRepositoryInterface $max = '0'; /** @var Tag $tag */ foreach ($tags as $tag) { - $amount = (string)$tag->amount_sum; + $amount = (string) $tag->amount_sum; $amount = '' === $amount ? '0' : $amount; $max = 1 === bccomp($amount, $max) ? $amount : $max; @@ -518,7 +548,7 @@ class TagRepository implements TagRepositoryInterface /** @var Tag $tag */ foreach ($tags as $tag) { - $amount = (string)$tag->amount_sum; + $amount = (string) $tag->amount_sum; $amount = '' === $amount ? '0' : $amount; if (null === $min) { @@ -541,7 +571,7 @@ class TagRepository implements TagRepositoryInterface */ public function getAttachments(Tag $tag): Collection { - $set= $tag->attachments()->get(); + $set = $tag->attachments()->get(); /** @var Storage $disk */ $disk = Storage::disk('upload'); diff --git a/resources/views/v1/tags/show.twig b/resources/views/v1/tags/show.twig index 61572b02a8..aeeb84e904 100644 --- a/resources/views/v1/tags/show.twig +++ b/resources/views/v1/tags/show.twig @@ -14,12 +14,15 @@
- +
@@ -44,22 +47,105 @@ {% endif %} - - {{ trans('list.sum') }} - {{ (sums.Withdrawal + sums.Transfer + sums.Deposit)|formatAmount }} - - - {{ trans('list.sum_excluding_transfers') }} - {{ (sums.Withdrawal + sums.Deposit)|formatAmount }} - - - {{ trans('list.sum_withdrawals') }} - {{ sums.Withdrawal|formatAmount }} - - - {{ trans('list.sum_deposits') }} - {{ sums.Deposit|formatAmount }} - + + {# total amount #} + {% set currentSum = 0 %} + {% for set in sums %} + {% set currentSum = currentSum + set.Withdrawal + set.Transfer + set.Deposit %} + {% endfor %} + + {% if currentSum != 0 %} + + {{ trans('list.sum') }} + + {% for set in sums %} + {{ formatAmountBySymbol(set.Withdrawal + set.Transfer + set.Deposit, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %} + {% endfor %} + + + {% endif %} + + {# total expense excl. transfer #} + {% set currentSum = 0 %} + {% for set in sums %} + {% set currentSum = currentSum + set.Withdrawal + set.Deposit %} + {% endfor %} + {% if currentSum != 0 %} + + {{ trans('list.sum_excluding_transfers') }} + + {% for set in sums %} + {{ formatAmountBySymbol(set.Withdrawal + set.Deposit, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %} + {% endfor %} + + + {% endif %} + + {# withdrawals #} + {% set currentSum = 0 %} + {% for set in sums %} + {% set currentSum = currentSum + set.Withdrawal %} + {% endfor %} + {% if currentSum != 0 %} + + {{ trans('list.sum_withdrawals') }} + + {% for set in sums %} + {{ formatAmountBySymbol(set.Withdrawal, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %} + {% endfor %} + + + {% endif %} + + {# deposits #} + {% set currentSum = 0 %} + {% for set in sums %} + {% set currentSum = currentSum + set.Deposit %} + {% endfor %} + {% if currentSum != 0 %} + + {{ trans('list.sum_deposits') }} + + {% for set in sums %} + {{ formatAmountBySymbol(set.Deposit, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %} + {% endfor %} + + + {% endif %} + + {# transfers #} + {% set currentSum = 0 %} + {% for set in sums %} + {% set currentSum = currentSum + set.Transfer %} + {% endfor %} + {% if currentSum != 0 %} + + {{ trans('list.sum_transfers') }} + + {% for set in sums %} + {{ formatAmountBySymbol(set.Transfer, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %} + {% endfor %} + + + {% endif %} + + {# reconciliation #} + {% set currentSum = 0 %} + {% for set in sums %} + {% set currentSum = currentSum + set.Reconciliation %} + {% endfor %} + {% if currentSum != 0 %} + + {{ trans('list.sum_reconciliations') }} + + {% for set in sums %} + {{ formatAmountBySymbol(set.Reconciliation, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %} + {% endfor %} + + + {% endif %} + + {# {% if sums.Transfer != 0 %} {{ trans('list.sum_transfers') }} @@ -72,12 +158,15 @@ {{ sums.Reconciliation|formatAmount }} {% endif %} + #} {% if attachments.count > 0 %} -
-
-
-
-

- {{ 'attachments'|_ }} -

-
-
- {% include 'list.attachments' %} +
+
+
+
+

+ {{ 'attachments'|_ }} +

+
+
+ {% include 'list.attachments' %} +
-
{% endif %} {% if periods|length > 0 %} {% endif %} @@ -144,12 +237,15 @@ @@ -184,7 +280,8 @@ {% if periods|length > 0 %} {% endif %} @@ -197,12 +294,12 @@