HomeController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A index() 0 40 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Collection;
7
8
class HomeController extends Controller
9
{
10
    /**
11
     * Create a new controller instance.
12
     *
13
     * @return void
14
     */
15
    public function __construct()
16
    {
17
        $this->middleware('auth');
18
    }
19
20
    /**
21
     * Show the application dashboard.
22
     *
23
     * @return \Illuminate\Http\Response
24
     */
25
    public function index()
26
    {
27
        $dateStart = date('Y-m-d', mktime(0, 0, 0, date('m')-1 , 1 , date('Y')));
0 ignored issues
show
Bug introduced by
date('Y') of type string is incompatible with the type integer expected by parameter $year of mktime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        $dateStart = date('Y-m-d', mktime(0, 0, 0, date('m')-1 , 1 , /** @scrutinizer ignore-type */ date('Y')));
Loading history...
28
        $dateEnd = date('Y-m-d', mktime(23, 59, 59, date('m'), date("t"), date('Y')));
0 ignored issues
show
Bug introduced by
date('t') of type string is incompatible with the type integer expected by parameter $day of mktime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
        $dateEnd = date('Y-m-d', mktime(23, 59, 59, date('m'), /** @scrutinizer ignore-type */ date("t"), date('Y')));
Loading history...
Bug introduced by
date('m') of type string is incompatible with the type integer expected by parameter $month of mktime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
        $dateEnd = date('Y-m-d', mktime(23, 59, 59, /** @scrutinizer ignore-type */ date('m'), date("t"), date('Y')));
Loading history...
29
30
        $billPays = auth()->user()->bill_pays()->selectRaw('bill_pays.*, categories.name as category_name')
31
            ->join('categories', 'categories.id', '=', 'bill_pays.category_id')
32
            ->whereBetween('date_launch', [$dateStart, $dateEnd])
33
            ->where('status', '1')
34
            ->get();
35
36
        $billReceives = auth()->user()->bill_receives()->selectRaw('bill_receives.*, categories.name as category_name')
37
            ->join('categories', 'categories.id', '=', 'bill_receives.category_id')
38
            ->whereBetween('date_launch', [$dateStart, $dateEnd])
39
            ->where('status', '1')
40
            ->get();
41
42
        $collection = new Collection(array_merge_recursive($billPays->toArray(), $billReceives->toArray()));
43
        $statements = $collection->sortByDesc('date_launch');
44
45
        $total_pays = $billPays->sum('value');
46
        $total_receives = $billReceives->sum('value');
47
48
        $categoriesPay = auth()->user()->categories()->selectRaw('categories.name, sum(value) as value')
49
            ->join('bill_pays', 'bill_pays.category_id', '=', 'categories.id')
50
            ->whereBetween('date_launch', [$dateStart, $dateEnd])
51
            ->whereNotNull('bill_pays.category_id')
52
            ->groupBy('categories.name')
53
            ->where('status', '1')
54
            ->get();
55
56
        $categoriesReceive = auth()->user()->categories()->selectRaw('categories.name, sum(value) as value')
57
            ->join('bill_receives', 'bill_receives.category_id', '=', 'categories.id')
58
            ->whereBetween('date_launch', [$dateStart, $dateEnd])
59
            ->whereNotNull('bill_receives.category_id')
60
            ->groupBy('categories.name')
61
            ->where('status', '1')
62
            ->get();
63
64
        return view('home', compact('billPays','billReceives','total_pays','total_receives','categoriesPay','categoriesReceive','dateStart','dateEnd','statements'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('home', comp...ateEnd', 'statements')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
65
    }
66
}
67