Skip non-existing tags.

This commit is contained in:
James Cole 2023-12-29 20:41:54 +01:00
parent c269be7f07
commit 1e31a1184a
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80

View File

@ -155,6 +155,7 @@ class TagController extends Controller
*/
public function accounts(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
{
$tagIds = $tags->pluck('id')->toArray();
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
$earned = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
$report = [];
@ -184,6 +185,9 @@ class TagController extends Controller
'total_sum' => '0',
];
foreach ($currency['tags'] as $tag) {
if(!array_key_exists($tag['id'], $tagIds)) {
continue;
}
foreach ($tag['transaction_journals'] as $journal) {
$sourceAccountId = $journal['source_account_id'];
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
@ -222,6 +226,9 @@ class TagController extends Controller
'total_sum' => '0',
];
foreach ($currency['tags'] as $tag) {
if(!array_key_exists($tag['id'], $tagIds)) {
continue;
}
foreach ($tag['transaction_journals'] as $journal) {
$destinationAccountId = $journal['destination_account_id'];
$report[$destinationAccountId]['currencies'][$currencyId] ??= [
@ -446,7 +453,6 @@ class TagController extends Controller
}
}
}
Log::info('Temp report', $report);
return view('reports.tag.partials.tags', compact('sums', 'report'));
}