Display graph of daily balance on dashboard
MODIFY
app/Http/Controllers/DashboardController.php
app/Http/Controllers/DashboardController.php
@@ -15,6 +15,7 @@ class DashboardController extends Controller {
$space_id = session('space')->id;
$currentYear = date('Y');
$currentMonth = date('m');
+ $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $currentMonth, $currentYear);
$balance = session('space')->monthlyBalance($currentYear, $currentMonth);
$recurrings = session('space')->monthlyRecurrings($currentYear, $currentMonth);
@@ -41,6 +42,22 @@ class DashboardController extends Controller {
LIMIT 3;
', [$space_id, date('m')]);
+ $balanceTick = 0;
+ $dailyBalance = [];
+ for ($i = 1; $i <= $daysInMonth; $i ++) {
+ $balanceTick -= session('space')
+ ->spendings()
+ ->where('happened_on', $currentYear . '-' . $currentMonth . '-' . $i)
+ ->sum('amount');
+
+ $balanceTick += session('space')
+ ->earnings()
+ ->where('happened_on', $currentYear . '-' . $currentMonth . '-' . $i)
+ ->sum('amount');
+
+ $dailyBalance[$i] = $balanceTick;
+ }
+
return view('dashboard', [
'month' => date('n'),
@@ -49,7 +66,10 @@ class DashboardController extends Controller {
'leftToSpend' => $leftToSpend,
'totalSpent' => $totalSpent,
- 'mostExpensiveTags' => $mostExpensiveTags
+ 'mostExpensiveTags' => $mostExpensiveTags,
+
+ 'daysInMonth' => $daysInMonth,
+ 'dailyBalance' => $dailyBalance
]);
}
}

MODIFY
resources/views/dashboard.blade.php
resources/views/dashboard.blade.php
</div>
</div>
@if (count($mostExpensiveTags))
- <div class="box mb-3">
+ <div class="box mt-3">
<div class="box__section box__section--header">Most Expensive {{ __('models.tags') }}</div>
@foreach ($mostExpensiveTags as $index => $tag)
<div class="box__section row row--seperate">
</div>
@endforeach
</div>
- </div>
@endif
+ <div class="box mt-3">
+ <div class="box__section box__section--header">Daily Balance</div>
+ <div class="box__section">
+ <div class="ct-chart ct-major-twelfth"></div>
+ </div>
+ </div>
</div>
@endsection
+
+@section('scripts')
+ <script>
+ new Chartist.Line('.ct-chart', {
+ labels: [{!! implode(',', range(1, $daysInMonth)) !!}],
+ series: [[{!! implode(',', $dailyBalance) !!}]]
+ }, {
+ showPoint: false,
+ lineSmooth: false
+ });
+ </script>
+@endsection

Display graph of daily balance on dashboard