|
1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
use App\Http\Controllers\Controller; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* ClientController |
|
8
|
|
|
* |
|
9
|
|
|
* This is the controller for the shop clients |
|
10
|
|
|
* @author Matthijs Neijenhuijs <[email protected]> |
|
11
|
|
|
* @version 0.1 |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
use Hideyo\Ecommerce\Framework\Services\Client\ClientFacade as ClientService; |
|
15
|
|
|
|
|
16
|
|
|
use Illuminate\Http\Request; |
|
17
|
|
|
use Notification; |
|
18
|
|
|
use Mail; |
|
19
|
|
|
use Excel; |
|
|
|
|
|
|
20
|
|
|
use Form; |
|
21
|
|
|
use Datatables; |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
class ClientController extends Controller |
|
24
|
|
|
{ |
|
25
|
|
|
public function index(Request $request) |
|
26
|
|
|
{ |
|
27
|
|
|
$shop = auth('hideyobackend')->user()->shop; |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
if ($request->wantsJson()) { |
|
30
|
|
|
$shop = auth('hideyobackend')->user()->shop(); |
|
|
|
|
|
|
31
|
|
|
$clients = ClientService::getModel()->select( |
|
32
|
|
|
[ |
|
33
|
|
|
|
|
34
|
|
|
'id', 'confirmed', 'active', |
|
35
|
|
|
'email', 'last_login'] |
|
36
|
|
|
)->where('shop_id', '=', auth('hideyobackend')->user()->selected_shop_id); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$datatables = Datatables::of($clients) |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
->addColumn('last_login', function ($clients) { |
|
42
|
|
|
return date('d F H:i', strtotime($clients->last_login)); |
|
43
|
|
|
}) |
|
44
|
|
|
|
|
45
|
|
|
->addColumn('action', function ($clients) { |
|
46
|
|
|
$deleteLink = Form::deleteajax(url()->route('client.destroy', $clients->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger')); |
|
47
|
|
|
$links = '<a href="'.url()->route('client.edit', $clients->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Show</a> '.$deleteLink; |
|
48
|
|
|
|
|
49
|
|
|
if (!$clients->active || !$clients->confirmed) { |
|
50
|
|
|
$links .= ' <a href="'.url()->route('client.activate', $clients->id).'" class="btn btn-default btn-sm btn-info">activate</a>'; |
|
51
|
|
|
} else { |
|
52
|
|
|
$links .= ' <a href="'.url()->route('client.de-activate', $clients->id).'" class="btn btn-default btn-sm btn-info">block</a>'; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $links; |
|
56
|
|
|
}); |
|
57
|
|
|
|
|
58
|
|
|
return $datatables->make(true); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return view('backend.client.index')->with('client', ClientService::selectAll()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function create() |
|
65
|
|
|
{ |
|
66
|
|
|
return view('backend.client.create')->with(array()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getActivate($clientId) |
|
70
|
|
|
{ |
|
71
|
|
|
return view('backend.client.activate')->with(array('client' => ClientService::find($clientId))); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getDeActivate($clientId) |
|
75
|
|
|
{ |
|
76
|
|
|
return view('backend.client.de-activate')->with(array('client' => ClientService::find($clientId))); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function postActivate(Request $request, $clientId) |
|
80
|
|
|
{ |
|
81
|
|
|
$input = $request->all(); |
|
82
|
|
|
$result = ClientService::activate($clientId); |
|
83
|
|
|
$shop = auth('hideyobackend')->user()->shop; |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
if ($input['send_mail']) { |
|
86
|
|
|
Mail::send('frontend.email.activate-mail', array('user' => $result->toArray(), 'billAddress' => $result->clientBillAddress->toArray()), function ($message) use ($result) { |
|
87
|
|
|
$message->to($result['email'])->from('[email protected]', 'Hideyo')->subject('Toegang tot account.'); |
|
88
|
|
|
}); |
|
89
|
|
|
|
|
90
|
|
|
Notification::container('foundation')->success('Uw account is geactiveerd.'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
Notification::success('The client was activate.'); |
|
94
|
|
|
return redirect()->route('client.index'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function postDeActivate($clientId) |
|
98
|
|
|
{ |
|
99
|
|
|
ClientService::deactivate($clientId); |
|
100
|
|
|
Notification::success('The client was deactivate.'); |
|
101
|
|
|
return redirect()->route('client.index'); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function store(Request $request) |
|
105
|
|
|
{ |
|
106
|
|
|
$result = ClientService::create($request->all()); |
|
107
|
|
|
return ClientService::notificationRedirect('client.index', $result, 'The client was inserted.'); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function edit($clientId) |
|
111
|
|
|
{ |
|
112
|
|
|
$addresses = ClientService::selectAddressesByClientId($clientId); |
|
113
|
|
|
|
|
114
|
|
|
$addressesList = array(); |
|
115
|
|
|
|
|
116
|
|
|
if ($addresses) { |
|
117
|
|
|
foreach ($addresses as $row) { |
|
118
|
|
|
$addressesList[$row->id] = $row->street.' '.$row->housenumber; |
|
119
|
|
|
if ($row->housenumber_suffix) { |
|
120
|
|
|
$addressesList[$row->id] .= $row->housenumber_suffix; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
$addressesList[$row->id] .= ', '.$row->city; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return view('backend.client.edit')->with(array('client' => ClientService::find($clientId), 'addresses' => $addressesList)); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function getExport() |
|
131
|
|
|
{ |
|
132
|
|
|
return view('backend.client.export')->with(array()); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function postExport() |
|
136
|
|
|
{ |
|
137
|
|
|
$result = ClientService::selectAllExport(); |
|
138
|
|
|
Excel::create('export', function ($excel) use ($result) { |
|
139
|
|
|
|
|
140
|
|
|
$excel->sheet('Clients', function ($sheet) use ($result) { |
|
141
|
|
|
$newArray = array(); |
|
142
|
|
|
foreach ($result as $row) { |
|
143
|
|
|
$firstname = null; |
|
144
|
|
|
if($row->clientBillAddress) { |
|
145
|
|
|
$firstname = $row->clientBillAddress->firstname; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
$lastname = null; |
|
149
|
|
|
if($row->clientBillAddress) { |
|
150
|
|
|
$lastname = $row->clientBillAddress->lastname; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
$gender = null; |
|
154
|
|
|
if($row->clientBillAddress) { |
|
155
|
|
|
$gender = $row->clientBillAddress->gender; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
$newArray[$row->id] = array( |
|
159
|
|
|
'email' => $row->email, |
|
160
|
|
|
'company' => $row->company, |
|
161
|
|
|
'firstname' => $firstname, |
|
162
|
|
|
'lastname' => $lastname, |
|
163
|
|
|
'gender' => $gender |
|
164
|
|
|
); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
$sheet->fromArray($newArray); |
|
168
|
|
|
}); |
|
169
|
|
|
})->download('xls'); |
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
Notification::success('The product export is completed.'); |
|
173
|
|
|
return redirect()->route('product.index'); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function update(Request $request, $clientId) |
|
177
|
|
|
{ |
|
178
|
|
|
$result = ClientService::updateById($request->all(), $clientId); |
|
179
|
|
|
$input = $request->all(); |
|
180
|
|
|
if (isset($result->id)) { |
|
181
|
|
|
if ($result->active) { |
|
|
|
|
|
|
182
|
|
|
$shop = auth('hideyobackend')->user()->shop; |
|
|
|
|
|
|
183
|
|
|
|
|
184
|
|
|
if ($input['send_mail']) { |
|
185
|
|
|
Mail::send('frontend.email.activate-mail', array('user' => $result->toArray(), 'billAddress' => $result->clientBillAddress->toArray()), function ($message) use ($result) { |
|
|
|
|
|
|
186
|
|
|
$message->to($result['email'])->from('[email protected]', 'Hideyo')->subject('Toegang tot account.'); |
|
187
|
|
|
}); |
|
188
|
|
|
|
|
189
|
|
|
Notification::container('foundation')->success('Uw account is geactiveerd.'); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
Notification::success('The client was updated.'); |
|
195
|
|
|
return redirect()->route('client.index'); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
foreach ($result->errors()->all() as $error) { |
|
199
|
|
|
Notification::error($error); |
|
200
|
|
|
} |
|
201
|
|
|
return redirect()->back()->withInput(); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
public function destroy($clientId) |
|
205
|
|
|
{ |
|
206
|
|
|
$result = ClientService::destroy($clientId); |
|
207
|
|
|
|
|
208
|
|
|
if ($result) { |
|
209
|
|
|
Notification::success('The client was deleted.'); |
|
210
|
|
|
return redirect()->route('client.index'); |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths