Create report for most expensive tags
MODIFY
app/Http/Controllers/ReportController.php
app/Http/Controllers/ReportController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
class ReportController extends Controller {
public function index() {
@@ -34,6 +35,31 @@ class ReportController extends Controller {
]);
}
+ if ($slug == 'most-expensive-tags') {
+ $mostExpensiveTags = DB::select('
+ SELECT
+ tags.name AS name,
+ tags.color AS color,
+ SUM(spendings.amount) AS amount
+ FROM
+ tags
+ LEFT OUTER JOIN
+ spendings ON tags.id = spendings.tag_id AND spendings.deleted_at IS NULL
+ WHERE
+ tags.space_id = ?
+ GROUP BY
+ tags.id
+ # HAVING
+ # SUM(spendings.amount) > 0
+ ORDER BY
+ SUM(spendings.amount) DESC;
+ ', [session('space')->id]);
+
+ $totalSpent = session('space')->spendings()->sum('amount');
+
+ return view('reports.most_expensive_tags', compact('mostExpensiveTags', 'totalSpent'));
+ }
+
return '404';
}
}

MODIFY
resources/views/reports/index.blade.php
resources/views/reports/index.blade.php
<div class="box__section">
<a href="/reports/weekly-report-2018">Weekly Balance 2018</a>
</div>
+ <div class="box__section">
+ <a href="/reports/most-expensive-tags">Most Expensive Tags</a>
+ </div>
</div>
</div>
@endsection

ADD
resources/views/reports/most_expensive_tags.blade.php
+@extends('layout')
+
+@section('body')
+ <div class="wrapper my-3">
+ <h2>Most Expensive Tags</h2>
+ @if (count($mostExpensiveTags))
+ <div class="box mt-3">
+ @foreach ($mostExpensiveTags as $index => $tag)
+ <div class="box__section row row--seperate">
+ <div class="row__column row__column--middle color-dark">
+ @include('partials.tag', ['payload' => $tag])
+ </div>
+ <div class="row__column row__column--middle">
+ <progress max="{{ $totalSpent }}" value="{{ $tag->amount }}"></progress>
+ </div>
+ <div class="row__column row__column--middle text-right">{!! $currency !!} {{ number_format($tag->amount / 100, 2) }} / {!! $currency !!} {{ number_format($totalSpent / 100, 2) }}</div>
+ </div>
+ @endforeach
+ </div>
+ @endif
+ </div>
+@endsection

Create report for most expensive tags