Allow reports to be generated through newly created ReportController
ADD
app/Http/Controllers/ReportController.php
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+class ReportController extends Controller {
+ public function index() {
+ return view('reports.index');
+ }
+
+ public function show($slug) {
+ if ($slug == 'weekly-report-2018') {
+ $weeks = [];
+ $balance = 0;
+
+ for ($i = 1; $i <= 52; $i ++) {
+ $balance += session('space')
+ ->earnings()
+ ->whereRaw('YEARWEEK(happened_on) = ?', [2018 . sprintf('%02d', $i)])
+ ->sum('amount');
+
+ $balance -= session('space')
+ ->spendings()
+ ->whereRaw('YEARWEEK(happened_on) = ?', [2018 . sprintf('%02d', $i)])
+ ->sum('amount');
+
+ $weeks[$i] = number_format($balance / 100, 2, '.', '');
+ }
+
+ return view('reports.weekly_report', [
+ 'year' => 2018,
+ 'weeks' => $weeks
+ ]);
+ }
+
+ return '404';
+ }
+}

MODIFY
resources/views/layout.blade.php
resources/views/layout.blade.php
.ct-series-b .ct-slice-donut-solid {
fill: #E4E8EB;
}
+
+ .ct-series-a .ct-line {
+ stroke-width: 2px;
+ stroke: #179BD1;
+ }
</style>
</head>
<body class="theme-{{ Auth::check() ? Auth::user()->theme : 'light' }}">
<li>
<a href="/tags" {!! (Request::path() == 'tags') ? 'class="active"' : '' !!}><i class="far fa-tag fa-sm color-red"></i> <span class="hidden ml-05">{{ __('models.tags') }}</span></a>
</li>
+ <li>
+ <a href="/reports" {!! (Request::path() == 'reports') ? 'class="active"' : '' !!}><i class="far fa-chart-line fa-sm color-blue"></i> <span class="hidden ml-05">Reports</span></a>
+ </li>
</ul>
<ul class="navigation__menu">
<li>

ADD
resources/views/reports/index.blade.php
+@extends('layout')
+
+@section('title', 'Reports')
+
+@section('body')
+ <div class="wrapper my-3">
+ <h2>Reports</h2>
+ <div class="box mt-3">
+ <div class="box__section">
+ <a href="/reports/weekly-report-2018">Weekly Balance 2018</a>
+ </div>
+ </div>
+ </div>
+@endsection

ADD
resources/views/reports/weekly_report.blade.php
+@extends('layout')
+
+@section('body')
+ <div class="wrapper my-3">
+ <h2>Weekly Report {{ $year }}</h2>
+ <div class="box mt-3">
+ <div class="box__section">
+ <div class="ct-chart ct-major-twelfth"></div>
+ </div>
+ </div>
+ </div>
+@endsection
+
+@section('scripts')
+ <script>
+ var data = {
+ labels: [{!! implode(',', array_keys($weeks)) !!}],
+ series: [[{!! '"' . implode('","', $weeks) . '"' !!}]]
+ };
+
+ new Chartist.Line('.ct-chart', data, {
+ showPoint: false,
+ lineSmooth: false
+ });
+ </script>
+@endsection

MODIFY
routes/web.php
routes/web.php
@@ -50,6 +50,9 @@ Route::group(['middleware' => ['auth']], function () {
'destroy'
]);
+ Route::get('/reports', 'ReportController@index')->name('reports.index');
+ Route::get('/reports/{slug}', 'ReportController@show');
+
Route::name('imports.')->group(function () {
Route::get('/imports', 'ImportController@index')->name('index');
Route::get('/imports/create', 'ImportController@create')->name('create');

Allow reports to be generated through newly created ReportController