This commit is contained in:
James Cole 2020-10-19 18:44:52 +02:00
parent 30f708ba7a
commit 590591f6bd
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
3 changed files with 84 additions and 3 deletions

View File

@ -43,6 +43,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
class IndexController extends Controller
{
use OrganisesObjectGroups;
private BillRepositoryInterface $repository;
/**
@ -140,8 +141,9 @@ class IndexController extends Controller
// summarise per currency / per group.
$sums = $this->getSums($bills);
$totals = $this->getTotals($sums);
return view('bills.index', compact('bills', 'sums', 'total'));
return view('bills.index', compact('bills', 'sums', 'total', 'totals'));
}
@ -250,4 +252,42 @@ class IndexController extends Controller
return response()->json(['data' => 'OK']);
}
/**
* @param array $sums
* @return array
*/
private function getTotals(array $sums): array
{
$totals = [];
if (count($sums) < 2) {
return [];
}
/**
* @var int $objectGroupId
* @var array $array
*/
foreach ($sums as $objectGroupId => $array) {
/**
* @var int $currencyId
* @var array $entry
*/
foreach ($array as $currencyId => $entry) {
$totals[$currencyId] = $totals[$currencyId] ?? [
'currency_id' => $currencyId,
'currency_code' => $entry['currency_code'],
'currency_name' => $entry['currency_name'],
'currency_symbol' => $entry['currency_symbol'],
'currency_decimal_places' => $entry['currency_decimal_places'],
'avg' => '0',
'period' => $entry['period'],
'per_period' => '0',
];
$totals[$currencyId]['avg'] = bcadd($totals[$currencyId]['avg'], $entry['avg']);
$totals[$currencyId]['per_period'] = bcadd($totals[$currencyId]['per_period'], $entry['per_period']);
}
}
return $totals;
}
}

View File

@ -204,7 +204,9 @@ return [
'button_register' => 'Register',
'authorization' => 'Authorization',
'active_bills_only' => 'active bills only',
'active_bills_only_total' => 'all active bills',
'active_exp_bills_only' => 'active and expected bills only',
'active_exp_bills_only_total' => 'all active expected bills only',
'per_period_sum_1D' => 'Expected daily costs',
'per_period_sum_1W' => 'Expected weekly costs',
'per_period_sum_1M' => 'Expected monthly costs',

View File

@ -164,6 +164,45 @@
</tbody>
{% endif %}
{% endfor %}
{% if totals|length > 0 %}
<tfoot>
<tr>
<td colspan="8" style="border-top:1px #777 solid;"></td>
</tr>
{% for sum in totals %}
{% if '0' != sum.avg %}
<tr>
<td class="hidden-sm hidden-xs">&nbsp;</td> <!-- handle -->
<td class="hidden-sm hidden-xs">&nbsp;</td> <!-- buttons -->
<td colspan="2" style="text-align: right;"> <!-- title -->
<small>{{ 'sum'|_ }} ({{ sum.currency_name }}) ({{ 'active_exp_bills_only_total'|_ }})</small>
</td>
<td style="text-align: right;"> <!-- amount -->
{{ formatAmountBySymbol(sum.avg, sum.currency_symbol, sum.currency_decimal_places) }}
</td>
<td>&nbsp;</td> <!-- paid in period -->
<td class="hidden-sm hidden-xs">&nbsp;</td> <!-- next expected match -->
<td class="hidden-sm hidden-xs">&nbsp;</td><!-- repeats -->
</tr>
{% endif %}
{% if '0' != sum.per_period %}
<tr>
<td class="hidden-sm hidden-xs">&nbsp;</td> <!-- handle -->
<td class="hidden-sm hidden-xs">&nbsp;</td> <!-- buttons -->
<td colspan="2" style="text-align: right;"> <!-- title -->
<small>{{ ('per_period_sum_'~sum.period)|_ }} ({{ sum.currency_name }}) ({{ 'active_bills_only_total'|_ }})</small>
</td>
<td style="text-align: right;"> <!-- amount -->
{{ formatAmountBySymbol(sum.per_period, sum.currency_symbol, sum.currency_decimal_places) }}
</td>
<td>&nbsp;</td> <!-- paid in period -->
<td class="hidden-sm hidden-xs">&nbsp;</td> <!-- next expected match -->
<td class="hidden-sm hidden-xs">&nbsp;</td><!-- repeats -->
</tr>
{% endif %}
{% endfor %}
</tfoot>
{% endif %}
</table>
<div style="padding-left:8px;">