Give ability to filter spendings by import_id
MODIFY
app/Http/Controllers/SpendingController.php
app/Http/Controllers/SpendingController.php
@@ -11,14 +11,24 @@ use Auth;
class SpendingController extends Controller {
public function index(Request $request) {
+ $filter = false;
+
$spendingsByMonth = [];
for ($month = 12; $month >= 1; $month --) {
- $spendingsThisMonth = session('space')
+ $query = session('space')
->spendings()
->whereYear('happened_on', date('Y'))
- ->whereMonth('happened_on', $month)
- ->orderBy('happened_on', 'DESC')
+ ->whereMonth('happened_on', $month);
+
+
+ if ($import_id = $request->get('filter_by_import')) {
+ $filter = 'import';
+
+ $query->where('import_id', $import_id);
+ }
+
+ $spendingsThisMonth = $query->orderBy('happened_on', 'DESC')
->get();
if (count($spendingsThisMonth)) {
@@ -26,7 +36,7 @@ class SpendingController extends Controller {
}
}
- return view('spendings.index', compact('spendingsByMonth'));
+ return view('spendings.index', compact('filter', 'spendingsByMonth'));
}
public function create() {

MODIFY
resources/views/spendings/index.blade.php
resources/views/spendings/index.blade.php
<div class="row">
<div class="row__column row__column--middle">
<h2>{{ __('models.spendings') }}</h2>
+ @if ($filter)
+ <div class="mt-1">Only showing spendings for selected {{ strtolower(__('models.' . $filter)) }}</div>
+ @endif
</div>
+ @if (!$filter)
<div class="row__column row__column--compact row__column--middle">
<a href="/spendings/create" class="button">{{ __('actions.create') }} {{ __('models.spending') }}</a>
</div>
+ @endif
</div>
@if (count($spendingsByMonth))
@foreach ($spendingsByMonth as $index => $spendings)

Give ability to filter spendings by import_id