This commit is contained in:
James Cole
2020-09-11 21:06:10 +02:00
parent e2ad5c60c6
commit 098eac8bab
2 changed files with 187 additions and 60 deletions

View File

@@ -352,24 +352,54 @@ class TagRepository implements TagRepositoryInterface
$collector->setTag($tag)->withAccountInformation(); $collector->setTag($tag)->withAccountInformation();
$journals = $collector->getExtractedJournals(); $journals = $collector->getExtractedJournals();
$sums = [ $sums = [];
TransactionType::WITHDRAWAL => '0',
TransactionType::DEPOSIT => '0',
TransactionType::TRANSFER => '0',
TransactionType::RECONCILIATION => '0',
TransactionType::OPENING_BALANCE => '0',
];
/** @var array $journal */ /** @var array $journal */
foreach ($journals as $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']; $type = $journal['transaction_type_type'];
if (TransactionType::WITHDRAWAL === $type) { if (TransactionType::WITHDRAWAL === $type) {
$amount = bcmul($amount, '-1'); $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; return $sums;
} }
@@ -404,7 +434,7 @@ class TagRepository implements TagRepositoryInterface
Log::debug(sprintf('Each coin in a tag earns it %s points', $pointsPerCoin)); Log::debug(sprintf('Each coin in a tag earns it %s points', $pointsPerCoin));
/** @var Tag $tag */ /** @var Tag $tag */
foreach ($tags as $tag) { foreach ($tags as $tag) {
$amount = (string)$tag->amount_sum; $amount = (string) $tag->amount_sum;
$amount = '' === $amount ? '0' : $amount; $amount = '' === $amount ? '0' : $amount;
$amountMin = bcsub($amount, $min); $amountMin = bcsub($amount, $min);
$pointsForTag = bcmul($amountMin, $pointsPerCoin); $pointsForTag = bcmul($amountMin, $pointsPerCoin);
@@ -496,7 +526,7 @@ class TagRepository implements TagRepositoryInterface
$max = '0'; $max = '0';
/** @var Tag $tag */ /** @var Tag $tag */
foreach ($tags as $tag) { foreach ($tags as $tag) {
$amount = (string)$tag->amount_sum; $amount = (string) $tag->amount_sum;
$amount = '' === $amount ? '0' : $amount; $amount = '' === $amount ? '0' : $amount;
$max = 1 === bccomp($amount, $max) ? $amount : $max; $max = 1 === bccomp($amount, $max) ? $amount : $max;
@@ -518,7 +548,7 @@ class TagRepository implements TagRepositoryInterface
/** @var Tag $tag */ /** @var Tag $tag */
foreach ($tags as $tag) { foreach ($tags as $tag) {
$amount = (string)$tag->amount_sum; $amount = (string) $tag->amount_sum;
$amount = '' === $amount ? '0' : $amount; $amount = '' === $amount ? '0' : $amount;
if (null === $min) { if (null === $min) {
@@ -541,7 +571,7 @@ class TagRepository implements TagRepositoryInterface
*/ */
public function getAttachments(Tag $tag): Collection public function getAttachments(Tag $tag): Collection
{ {
$set= $tag->attachments()->get(); $set = $tag->attachments()->get();
/** @var Storage $disk */ /** @var Storage $disk */
$disk = Storage::disk('upload'); $disk = Storage::disk('upload');

View File

@@ -14,12 +14,15 @@
<div class="box-tools pull-right"> <div class="box-tools pull-right">
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown"><i class="fa fa-ellipsis-v"></i></button> <button class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown"><i
class="fa fa-ellipsis-v"></i></button>
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<li><a href="{{ route('tags.edit',tag.id) }}"><i class="fa fa-pencil fa-fw"></i> {{ trans('firefly.edit_tag',{tag: tag.tag}) }} <li><a href="{{ route('tags.edit',tag.id) }}"><i
class="fa fa-pencil fa-fw"></i> {{ trans('firefly.edit_tag',{tag: tag.tag}) }}
</a></li> </a></li>
<li><a href="{{ route('tags.delete',tag.id) }}"><i <li><a href="{{ route('tags.delete',tag.id) }}"><i
class="fa fa-trash fa-fw"></i> {{ trans('firefly.delete_tag',{tag: tag.tag}) }}</a></li> class="fa fa-trash fa-fw"></i> {{ trans('firefly.delete_tag',{tag: tag.tag}) }}
</a></li>
</ul> </ul>
</div> </div>
</div> </div>
@@ -44,22 +47,105 @@
</td> </td>
</tr> </tr>
{% endif %} {% endif %}
<tr>
<td>{{ trans('list.sum') }}</td> {# total amount #}
<td> {{ (sums.Withdrawal + sums.Transfer + sums.Deposit)|formatAmount }}</td> {% set currentSum = 0 %}
</tr> {% for set in sums %}
<tr> {% set currentSum = currentSum + set.Withdrawal + set.Transfer + set.Deposit %}
<td>{{ trans('list.sum_excluding_transfers') }}</td> {% endfor %}
<td> {{ (sums.Withdrawal + sums.Deposit)|formatAmount }}</td>
</tr> {% if currentSum != 0 %}
<tr> <tr>
<td>{{ trans('list.sum_withdrawals') }}</td> <td style="width:40%;">{{ trans('list.sum') }}</td>
<td> {{ sums.Withdrawal|formatAmount }}</td> <td>
</tr> {% for set in sums %}
<tr> {{ formatAmountBySymbol(set.Withdrawal + set.Transfer + set.Deposit, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %}
<td>{{ trans('list.sum_deposits') }}</td> {% endfor %}
<td> {{ sums.Deposit|formatAmount }}</td> </td>
</tr> </tr>
{% endif %}
{# total expense excl. transfer #}
{% set currentSum = 0 %}
{% for set in sums %}
{% set currentSum = currentSum + set.Withdrawal + set.Deposit %}
{% endfor %}
{% if currentSum != 0 %}
<tr>
<td style="width:40%;">{{ trans('list.sum_excluding_transfers') }}</td>
<td>
{% for set in sums %}
{{ formatAmountBySymbol(set.Withdrawal + set.Deposit, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %}
{% endfor %}
</td>
</tr>
{% endif %}
{# withdrawals #}
{% set currentSum = 0 %}
{% for set in sums %}
{% set currentSum = currentSum + set.Withdrawal %}
{% endfor %}
{% if currentSum != 0 %}
<tr>
<td style="width:40%;">{{ trans('list.sum_withdrawals') }}</td>
<td>
{% for set in sums %}
{{ formatAmountBySymbol(set.Withdrawal, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %}
{% endfor %}
</td>
</tr>
{% endif %}
{# deposits #}
{% set currentSum = 0 %}
{% for set in sums %}
{% set currentSum = currentSum + set.Deposit %}
{% endfor %}
{% if currentSum != 0 %}
<tr>
<td style="width:40%;">{{ trans('list.sum_deposits') }}</td>
<td>
{% for set in sums %}
{{ formatAmountBySymbol(set.Deposit, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %}
{% endfor %}
</td>
</tr>
{% endif %}
{# transfers #}
{% set currentSum = 0 %}
{% for set in sums %}
{% set currentSum = currentSum + set.Transfer %}
{% endfor %}
{% if currentSum != 0 %}
<tr>
<td style="width:40%;">{{ trans('list.sum_transfers') }}</td>
<td>
{% for set in sums %}
{{ formatAmountBySymbol(set.Transfer, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %}
{% endfor %}
</td>
</tr>
{% endif %}
{# reconciliation #}
{% set currentSum = 0 %}
{% for set in sums %}
{% set currentSum = currentSum + set.Reconciliation %}
{% endfor %}
{% if currentSum != 0 %}
<tr>
<td style="width:40%;">{{ trans('list.sum_reconciliations') }}</td>
<td>
{% for set in sums %}
{{ formatAmountBySymbol(set.Reconciliation, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %}
{% endfor %}
</td>
</tr>
{% endif %}
{#
{% if sums.Transfer != 0 %} {% if sums.Transfer != 0 %}
<tr> <tr>
<td>{{ trans('list.sum_transfers') }}</td> <td>{{ trans('list.sum_transfers') }}</td>
@@ -72,12 +158,15 @@
<td> {{ sums.Reconciliation|formatAmount }}</td> <td> {{ sums.Reconciliation|formatAmount }}</td>
</tr> </tr>
{% endif %} {% endif %}
#}
</table> </table>
</div> </div>
<div class="box-footer"> <div class="box-footer">
<div class="btn-group btn-group-sm"> <div class="btn-group btn-group-sm">
<a href="{{ route('tags.edit',tag.id) }}" class="btn btn-default"><i class="fa fa-pencil fa-fw"></i></a> <a href="{{ route('tags.edit',tag.id) }}" class="btn btn-default"><i
<a href="{{ route('tags.delete',tag.id) }}" class="btn btn-danger"><i class="fa fa-trash fa-fw"></i></a> class="fa fa-pencil fa-fw"></i></a>
<a href="{{ route('tags.delete',tag.id) }}" class="btn btn-danger"><i
class="fa fa-trash fa-fw"></i></a>
</div> </div>
<p class="text-muted"> <p class="text-muted">
<small>{{ 'sums_apply_to_range'|_ }}</small> <small>{{ 'sums_apply_to_range'|_ }}</small>
@@ -91,12 +180,15 @@
<h3 class="box-title">{{ 'location'|_ }}</h3> <h3 class="box-title">{{ 'location'|_ }}</h3>
<div class="box-tools pull-right"> <div class="box-tools pull-right">
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown"><i class="fa fa-ellipsis-v"></i></button> <button class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown"><i
class="fa fa-ellipsis-v"></i></button>
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<li><a href="{{ route('tags.edit',tag.id) }}"><i class="fa fa-pencil fa-fw"></i> {{ trans('firefly.edit_tag',{tag: tag.tag}) }} <li><a href="{{ route('tags.edit',tag.id) }}"><i
class="fa fa-pencil fa-fw"></i> {{ trans('firefly.edit_tag',{tag: tag.tag}) }}
</a></li> </a></li>
<li><a href="{{ route('tags.delete',tag.id) }}"><i <li><a href="{{ route('tags.delete',tag.id) }}"><i
class="fa fa-trash fa-fw"></i> {{ trans('firefly.delete_tag',{tag: tag.tag}) }}</a></li> class="fa fa-trash fa-fw"></i> {{ trans('firefly.delete_tag',{tag: tag.tag}) }}
</a></li>
</ul> </ul>
</div> </div>
</div> </div>
@@ -112,26 +204,27 @@
</div> </div>
</div> </div>
{% if attachments.count > 0 %} {% if attachments.count > 0 %}
<div class="row"> <div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title"> <h3 class="box-title">
{{ 'attachments'|_ }} {{ 'attachments'|_ }}
</h3> </h3>
</div> </div>
<div class="box-body no-padding"> <div class="box-body no-padding">
{% include 'list.attachments' %} {% include 'list.attachments' %}
</div>
</div> </div>
</div> </div>
</div> </div>
</div>
{% endif %} {% endif %}
{% if periods|length > 0 %} {% if periods|length > 0 %}
<div class="row"> <div class="row">
<div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12"> <div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12">
<p class="small text-center"><a href="{{ route('tags.show',[tag.id,'all']) }}">{{ 'showEverything'|_ }}</a></p> <p class="small text-center"><a
href="{{ route('tags.show',[tag.id,'all']) }}">{{ 'showEverything'|_ }}</a></p>
</div> </div>
</div> </div>
{% endif %} {% endif %}
@@ -144,12 +237,15 @@
<div class="box-tools pull-right"> <div class="box-tools pull-right">
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown"><i class="fa fa-ellipsis-v"></i></button> <button class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown"><i
class="fa fa-ellipsis-v"></i></button>
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<li><a href="{{ route('tags.edit',tag.id) }}"><i class="fa fa-pencil fa-fw"></i> {{ trans('firefly.edit_tag',{tag: tag.tag}) }} <li><a href="{{ route('tags.edit',tag.id) }}"><i
class="fa fa-pencil fa-fw"></i> {{ trans('firefly.edit_tag',{tag: tag.tag}) }}
</a></li> </a></li>
<li><a href="{{ route('tags.delete',tag.id) }}"><i <li><a href="{{ route('tags.delete',tag.id) }}"><i
class="fa fa-trash fa-fw"></i> {{ trans('firefly.delete_tag',{tag: tag.tag}) }}</a></li> class="fa fa-trash fa-fw"></i> {{ trans('firefly.delete_tag',{tag: tag.tag}) }}
</a></li>
</ul> </ul>
</div> </div>
</div> </div>
@@ -184,7 +280,8 @@
{% if periods|length > 0 %} {% if periods|length > 0 %}
<div class="row"> <div class="row">
<div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12"> <div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12">
<p class="small text-center"><a href="{{ route('tags.show',[tag.id]) }}">{{ 'showEverything'|_ }}</a></p> <p class="small text-center"><a href="{{ route('tags.show',[tag.id]) }}">{{ 'showEverything'|_ }}</a>
</p>
</div> </div>
</div> </div>
{% endif %} {% endif %}
@@ -197,12 +294,12 @@
<script type="text/javascript" nonce="{{ JS_NONCE }}"> <script type="text/javascript" nonce="{{ JS_NONCE }}">
// location stuff // location stuff
{% if location %} {% if location %}
var latitude = {{ location.latitude|default("52.3167") }}; var latitude = {{ location.latitude|default("52.3167") }};
var longitude = {{ location.longitude|default("5.5500") }}; var longitude = {{ location.longitude|default("5.5500") }};
var zoomLevel = {{ location.zoom_level|default("6") }}; var zoomLevel = {{ location.zoom_level|default("6") }};
var doPlaceMarker = true; var doPlaceMarker = true;
// token for Mapbox: // token for Mapbox:
var mapboxToken = "{{ config('firefly.mapbox_api_key') }}"; var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";
{% endif %} {% endif %}
</script> </script>
<script src="v1/lib/leaflet/leaflet.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script> <script src="v1/lib/leaflet/leaflet.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>