|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Dashboard; |
|
4
|
|
|
|
|
5
|
|
|
use App\Person; |
|
6
|
|
|
use Illuminate\Routing\Controller; |
|
7
|
|
|
use LaravelEnso\Charts\Factories\Bar; |
|
8
|
|
|
use LaravelEnso\Charts\Factories\Bubble; |
|
9
|
|
|
use LaravelEnso\Charts\Factories\Doughnut; |
|
10
|
|
|
use LaravelEnso\Charts\Factories\Line; |
|
11
|
|
|
use LaravelEnso\Charts\Factories\Pie; |
|
12
|
|
|
use LaravelEnso\Charts\Factories\Polar; |
|
13
|
|
|
use LaravelEnso\Charts\Factories\Radar; |
|
14
|
|
|
use Illuminate\Support\Facades\Auth; |
|
15
|
|
|
use LaravelEnso\Multitenancy\Enums\Connections; |
|
16
|
|
|
use LaravelEnso\Multitenancy\Services\Tenant; |
|
17
|
|
|
use App\Traits\ConnectionTrait; |
|
18
|
|
|
use Illuminate\Http\Request; |
|
19
|
|
|
class ChartController extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
use ConnectionTrait; |
|
22
|
|
|
// use SystemConnection; |
|
23
|
|
|
|
|
24
|
|
|
public function line() |
|
25
|
|
|
{ |
|
26
|
|
|
return (new Line()) |
|
27
|
|
|
->title('Income') |
|
28
|
|
|
->labels(['January', 'February', 'March', 'April', 'May', 'June', 'July']) |
|
29
|
|
|
->datasets([ |
|
30
|
|
|
'Sales' => [65, 59, 80, 81, 26, 25, 10], |
|
31
|
|
|
'Revenue' => [15, 29, 60, 31, 56, 65, 44], |
|
32
|
|
|
])->fill() |
|
33
|
|
|
->get(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function bar() |
|
37
|
|
|
{ |
|
38
|
|
|
return (new Bar()) |
|
39
|
|
|
->title('Sales') |
|
40
|
|
|
->labels(['Ian', 'Feb', 'Mar']) |
|
41
|
|
|
->datasets([ |
|
42
|
|
|
'Sales' => [1233, 1231, 3123], |
|
43
|
|
|
'Spendings' => [1250, 1730, 5300], |
|
44
|
|
|
'Profit' => [1250 - 1233, 1730 - 1231, 5300 - 3123], |
|
45
|
|
|
])->get(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function pie() |
|
49
|
|
|
{ |
|
50
|
|
|
// \DB::table('some')->get(); |
|
51
|
|
|
$male = Person::where('sex', 'M')->get()->count(); |
|
52
|
|
|
$female = Person::where('sex', 'F')->get()->count(); |
|
53
|
|
|
$unknown = Person::whereNull('sex')->get()->count(); |
|
54
|
|
|
$sv = \Session::get('db', env('DB_DATABASE')); |
|
|
|
|
|
|
55
|
|
|
$user = Auth::user(); |
|
56
|
|
|
$companies = $user->person->company(); |
|
|
|
|
|
|
57
|
|
|
$current_db = \Session::get('companyId'); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
// return $current_db; |
|
60
|
|
|
// return $sv; |
|
61
|
|
|
return (new Pie()) |
|
62
|
|
|
->title('Genders') |
|
63
|
|
|
->labels(['Male', 'Female', 'Unknown']) |
|
64
|
|
|
->datasets([$male, $female, $unknown]) |
|
65
|
|
|
->get(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function doughnut() |
|
69
|
|
|
{ |
|
70
|
|
|
return (new Doughnut()) |
|
71
|
|
|
->title('Colors Two') |
|
72
|
|
|
->labels(['Green', 'Red', 'Azzure']) |
|
73
|
|
|
->datasets([400, 50, 100]) |
|
74
|
|
|
->get(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function radar() |
|
78
|
|
|
{ |
|
79
|
|
|
return (new Radar()) |
|
80
|
|
|
->title('Habits') |
|
81
|
|
|
->labels([ |
|
82
|
|
|
'Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running', |
|
83
|
|
|
]) |
|
84
|
|
|
->datasets([ |
|
85
|
|
|
'2005' => [65, 59, 90, 81, 56, 55, 40], |
|
86
|
|
|
'2006' => [28, 48, 40, 19, 96, 27, 100], |
|
87
|
|
|
])->get(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function polar() |
|
91
|
|
|
{ |
|
92
|
|
|
return (new Polar()) |
|
93
|
|
|
->title('Again Colors') |
|
94
|
|
|
->labels(['Green', 'Red', 'Azzure', 'Portocaliu', 'Purple']) |
|
95
|
|
|
->datasets([11, 16, 7, 14, 14]) |
|
96
|
|
|
->get(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function bubble() |
|
100
|
|
|
{ |
|
101
|
|
|
return (new Bubble()) |
|
102
|
|
|
->title('City Population by Age') |
|
103
|
|
|
->labels(['Geneva', 'Besel', 'Bucharest']) |
|
104
|
|
|
->datasets([ |
|
105
|
|
|
0 => [[1010, 59, 4800], [2011, 55, 1800], [1012, 45, 2000], [413, 58, 4400]], |
|
106
|
|
|
1 => [[2010, 48, 1700], [1211, 67, 1200], [2012, 96, 1233], [813, 35, 3000]], |
|
107
|
|
|
2 => [[1510, 44, 2000], [811, 62, 1500], [212, 55, 1299], [1213, 39, 4000]], |
|
108
|
|
|
])->get(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
// change database to use |
|
112
|
|
|
public function changedb(Request $request) { |
|
113
|
|
|
$company_id = $request->get('comid'); |
|
114
|
|
|
if(!empty($company_id)){ |
|
115
|
|
|
$db = Connections::Tenant.$company_id; |
|
116
|
|
|
$key = 'database.connections.tenant.database'; |
|
117
|
|
|
config([$key => $db]); |
|
118
|
|
|
$this->setConnection(Connections::Tenant, $db); |
|
119
|
|
|
} else { |
|
120
|
|
|
$this->setConnection('mysql'); |
|
121
|
|
|
} |
|
122
|
|
|
$conn = $this->getConnection(); |
|
123
|
|
|
return $conn; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
// get companies of user. |
|
127
|
|
|
public function getDB(){ |
|
128
|
|
|
$user = Auth::user(); |
|
129
|
|
|
$companies = $user->person->companies()->get(); |
|
|
|
|
|
|
130
|
|
|
$ret = array(); |
|
131
|
|
|
$ret['company'] = $companies; |
|
132
|
|
|
return $ret; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|