Add spendings by tag to dashboard
MODIFY
app/Http/Controllers/DashboardController.php
app/Http/Controllers/DashboardController.php
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
+use DB;
class DashboardController extends Controller {
public function index($year = null, $month = null) {
@@ -31,6 +32,19 @@ class DashboardController extends Controller {
$currency = $user->currency;
+ $spendingsByTag = DB::select('
+ SELECT
+ tags.id,
+ tags.name,
+ SUM(spendings.amount) AS spendings
+ FROM tags
+ INNER JOIN spendings
+ ON spendings.tag_id = tags.id
+ WHERE YEAR(spendings.date) = ? AND MONTH(spendings.date) = ?
+ GROUP BY tags.id
+ ORDER BY spendings DESC
+ ', [$year, $month]);
+
$totalEarnings = $user->earnings()
->whereYear('date', $year)
->whereMonth('date', $month)
@@ -80,6 +94,7 @@ class DashboardController extends Controller {
'previousMonth',
'nextMonth',
'currency',
+ '$spendingsByTag',
'totalEarnings',
'totalSpendings',
'balance',

MODIFY
resources/assets/sass/components/box.scss
resources/assets/sass/components/box.scss
padding: 16px 32px;
}
}
+
+ ul.t {
+ li {
+ padding: 12px 0;
+
+ &:first-child {
+ padding-top: 0;
+ }
+
+ &:last-child {
+ padding-bottom: 0;
+ }
+ }
+ }
}

MODIFY
resources/assets/sass/components/spacing.scss
resources/assets/sass/components/spacing.scss
}
}
}
+
+.st-3 {
+ padding-top: 36px;
+}
+
+.sl-1 {
+ padding-left: 12px;
+}

MODIFY
resources/views/dashboard.blade.php
resources/views/dashboard.blade.php
</div>
</div>
</div>
+
<div class="wrapper spacing-top-large spacing-bottom-large">
+ <div class="box spacing-bottom-large">
+ <div class="section">
+ <h3>Spendings by Tag</h3>
+ <ul class="t st-3">
+ @foreach ($spendingsByTag as $tag)
+ <li class="row">
+ <div class="column">
+ {{ $tag->name }}
+ </div>
+ <div class="column tight sl-1">
+ {{ $currency->symbol }} {{ $tag->spendings }}
+ </div>
+ </li>
+ @endforeach
+ </ul>
+ </div>
+ </div>
+
<div class="row gutter spacing-bottom-large">
<div class="column">
<div class="box">

Add spendings by tag to dashboard