|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
|
|
8
|
|
|
class ReportController 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
|
|
|
public function statement() |
|
21
|
|
|
{ |
|
22
|
|
|
$statements = []; |
|
23
|
|
|
return view('report.statement', compact('statements')); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function getStatementByPeriod(Request $request) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->validate($request, [ |
|
29
|
|
|
'dateStart' => 'required|date', |
|
30
|
|
|
'dateEnd' => 'required|date', |
|
31
|
|
|
]); |
|
32
|
|
|
|
|
33
|
|
|
$dateStart = $request->dateStart; |
|
34
|
|
|
$dateEnd = $request->dateEnd; |
|
35
|
|
|
|
|
36
|
|
|
$billPays = auth()->user()->bill_pays()->selectRaw('bill_pays.*, categories.name as category_name') |
|
37
|
|
|
->join('categories', 'categories.id', '=', 'bill_pays.category_id') |
|
38
|
|
|
->whereBetween('date_launch', [$dateStart, $dateEnd]) |
|
39
|
|
|
->get(); |
|
40
|
|
|
|
|
41
|
|
|
$billReceives = auth()->user()->bill_receives()->selectRaw('bill_receives.*, categories.name as category_name') |
|
42
|
|
|
->join('categories', 'categories.id', '=', 'bill_receives.category_id') |
|
43
|
|
|
->whereBetween('date_launch', [$dateStart, $dateEnd]) |
|
44
|
|
|
->get(); |
|
45
|
|
|
|
|
46
|
|
|
$collection = new Collection(array_merge_recursive($billPays->toArray(), $billReceives->toArray())); |
|
47
|
|
|
$statements = $collection->sortByDesc('date_launch'); |
|
48
|
|
|
|
|
49
|
|
|
$total_pays = $billPays->sum('value'); |
|
50
|
|
|
$total_receives = $billReceives->sum('value'); |
|
51
|
|
|
|
|
52
|
|
|
return view('report.statement', compact('billPays','billReceives','total_pays','total_receives','statements')); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function charts() |
|
56
|
|
|
{ |
|
57
|
|
|
$categories = []; |
|
58
|
|
|
return view('report.charts', compact('categories')); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function sumChartsByPeriod(Request $request) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->validate($request, [ |
|
64
|
|
|
'dateStart' => 'required|date', |
|
65
|
|
|
'dateEnd' => 'required|date', |
|
66
|
|
|
]); |
|
67
|
|
|
|
|
68
|
|
|
$dateStart = $request->dateStart; |
|
69
|
|
|
$dateEnd = $request->dateEnd; |
|
70
|
|
|
|
|
71
|
|
|
$categoriesPay = auth()->user()->categories()->selectRaw('categories.name, sum(value) as value') |
|
72
|
|
|
->join('bill_pays', 'bill_pays.category_id', '=', 'categories.id') |
|
73
|
|
|
->whereBetween('date_launch', [$dateStart, $dateEnd]) |
|
74
|
|
|
->whereNotNull('bill_pays.category_id') |
|
75
|
|
|
->groupBy('categories.name') |
|
76
|
|
|
->where('status', '1') |
|
77
|
|
|
->get(); |
|
78
|
|
|
|
|
79
|
|
|
$categoriesReceive = auth()->user()->categories()->selectRaw('categories.name, sum(value) as value') |
|
80
|
|
|
->join('bill_receives', 'bill_receives.category_id', '=', 'categories.id') |
|
81
|
|
|
->whereBetween('date_launch', [$dateStart, $dateEnd]) |
|
82
|
|
|
->whereNotNull('bill_receives.category_id') |
|
83
|
|
|
->groupBy('categories.name') |
|
84
|
|
|
->where('status', '1') |
|
85
|
|
|
->get(); |
|
86
|
|
|
|
|
87
|
|
|
return view('report.charts', compact('categoriesPay','categoriesReceive')); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|