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'))); |
|
|
|
|
28
|
|
|
$dateEnd = date('Y-m-d', mktime(23, 59, 59, date('m'), date("t"), date('Y'))); |
|
|
|
|
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')); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|