1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\User; |
4
|
|
|
|
5
|
|
|
use App\Comment; |
6
|
|
|
use App\Http\Controllers\License\LicenseController; |
7
|
|
|
use App\Http\Requests\User\ClientRequest; |
8
|
|
|
use App\Model\Common\Country; |
9
|
|
|
use App\Model\Common\StatusSetting; |
10
|
|
|
use App\Model\Order\Invoice; |
11
|
|
|
use App\Model\Order\Order; |
12
|
|
|
use App\Model\Payment\Currency; |
13
|
|
|
use App\Model\User\AccountActivate; |
14
|
|
|
use App\Traits\PaymentsAndInvoices; |
15
|
|
|
use App\User; |
16
|
|
|
use Bugsnag; |
17
|
|
|
use Illuminate\Http\Request; |
18
|
|
|
|
19
|
|
|
class ClientController extends AdvanceSearchController |
20
|
|
|
{ |
21
|
|
|
use PaymentsAndInvoices; |
|
|
|
|
22
|
|
|
|
23
|
|
|
public $user; |
24
|
|
|
public $activate; |
25
|
|
|
public $product; |
26
|
|
|
|
27
|
|
|
public function __construct() |
28
|
|
|
{ |
29
|
|
|
$this->middleware('auth'); |
30
|
|
|
$this->middleware('admin'); |
31
|
|
|
$user = new User(); |
32
|
|
|
$this->user = $user; |
33
|
|
|
$activate = new AccountActivate(); |
34
|
|
|
$this->activate = $activate; |
35
|
|
|
$product = new \App\Model\Product\Product(); |
36
|
|
|
$this->product = $product; |
37
|
|
|
$license = new LicenseController(); |
38
|
|
|
$this->licensing = $license; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Display a listing of the resource. |
43
|
|
|
* |
44
|
|
|
* @param Request $request |
45
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
46
|
|
|
*/ |
47
|
|
|
public function index(Request $request) |
48
|
|
|
{ |
49
|
|
|
$validator = \Validator::make($request->all(), [ |
50
|
|
|
'reg_from' => 'nullable', |
51
|
|
|
'reg_till' => 'nullable|after:reg_from', |
52
|
|
|
|
53
|
|
|
]); |
54
|
|
|
if ($validator->fails()) { |
55
|
|
|
$request->reg_from = ''; |
|
|
|
|
56
|
|
|
$request->reg_till = ''; |
|
|
|
|
57
|
|
|
|
58
|
|
|
return redirect('clients')->with('fails', 'Registered from should be before registered till date'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return view('themes.default1.user.client.index', compact('request')); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get Clients for yajra datatable. |
66
|
|
|
* @param Request $request |
67
|
|
|
* @return |
68
|
|
|
* @throws \Exception |
69
|
|
|
*/ |
70
|
|
|
public function getClients(Request $request) |
71
|
|
|
{ |
72
|
|
|
$baseQuery = $this->getBaseQueryForUserSearch($request); |
73
|
|
|
|
74
|
|
|
return\ DataTables::of($baseQuery) |
75
|
|
|
->addColumn('checkbox', function ($model) { |
76
|
|
|
$isAccountManager = User::where('account_manager', $model->id)->get(); |
77
|
|
|
$isSalesManager = User::where('manager', $model->id)->get(); |
78
|
|
|
if (count($isSalesManager)) { |
79
|
|
|
return "<input type='checkbox' disabled> |
80
|
|
|
<i class='fa fa-info-circle' style='cursor: help; font-size: small; color: rgb(60, 141, 188);' ".'<label data-toggle="tooltip" style="font-weight:500;" data-placement="top" title="This user cannot be deleted as he/she is existing sales manager for certain clients. Please replace Sales Manager from settings and then try deleting."> |
81
|
|
|
</label>'.'</i>'; |
82
|
|
|
} elseif (count($isAccountManager)) { |
83
|
|
|
// dd("<input type='checkbox' ".tooltip('dsf')."'disabled'"); |
84
|
|
|
return "<input type='checkbox' disabled> |
85
|
|
|
<i class='fa fa-info-circle' style='cursor: help; font-size: small; color: rgb(60, 141, 188);' ".'<label data-toggle="tooltip" style="font-weight:500;" data-placement="top" title="This user cannot be deleted as he/she is existing account manager for certain clients. Please replace Account Manager from settings and then try deleting."> |
86
|
|
|
</label>'.'</i>'; |
87
|
|
|
} else { |
88
|
|
|
return "<input type='checkbox' class='user_checkbox' value=".$model->id.' name=select[] id=check>'; |
89
|
|
|
} |
90
|
|
|
}) |
91
|
|
|
->addColumn('name', function ($model) { |
92
|
|
|
return '<a href='.url('clients/'.$model->id).'>'.ucfirst($model->name).'</a>'; |
93
|
|
|
}) |
94
|
|
|
->addColumn('email', function ($model) { |
95
|
|
|
return $model->email; |
96
|
|
|
}) |
97
|
|
|
->addColumn('mobile', function ($model) { |
98
|
|
|
return $model->mobile; |
99
|
|
|
}) |
100
|
|
|
->addColumn('country', function ($model) { |
101
|
|
|
return ucfirst(strtolower($model->country)); |
102
|
|
|
}) |
103
|
|
|
->addColumn('company', function ($model) { |
104
|
|
|
return $model->company; |
105
|
|
|
}) |
106
|
|
|
->addColumn('created_at', function ($model) { |
107
|
|
|
return getDateHtml($model->created_at); |
108
|
|
|
}) |
109
|
|
|
->addColumn('active', function ($model) { |
110
|
|
|
return $this->getActiveLabel($model->mobile_verified, $model->active, $model->is_2fa_enabled); |
111
|
|
|
}) |
112
|
|
|
->addColumn('action', function ($model) { |
113
|
|
|
return '<a href='.url('clients/'.$model->id.'/edit') |
114
|
|
|
." class='btn btn-sm btn-secondary btn-xs'".tooltip('Edit')." |
115
|
|
|
<i class='fa fa-edit' style='color:white;'> </i></a>" |
116
|
|
|
.' <a href='.url('clients/'.$model->id) |
117
|
|
|
." class='btn btn-sm btn-secondary btn-xs'".tooltip('View')." |
118
|
|
|
<i class='fa fa-eye' style='color:white;'> </i></a>"; |
119
|
|
|
}) |
120
|
|
|
|
121
|
|
|
->filterColumn('name', function ($model, $keyword) { |
122
|
|
|
// removing all white spaces so that it can be searched irrespective of number of spaces |
123
|
|
|
$model->whereRaw("CONCAT(first_name, ' ',last_name) like ?", ["%$keyword%"]); |
124
|
|
|
}) |
125
|
|
|
->filterColumn('email', function ($model, $keyword) { |
126
|
|
|
$model->whereRaw('email like ?', ["%$keyword%"]); |
127
|
|
|
}) |
128
|
|
|
->filterColumn('mobile', function ($model, $keyword) { |
129
|
|
|
// removing all white spaces so that it can be searched in a single query |
130
|
|
|
$searchQuery = str_replace(' ', '', $keyword); |
131
|
|
|
$model->whereRaw("CONCAT('+', mobile_code, mobile) like ?", ["%$searchQuery%"]); |
132
|
|
|
}) |
133
|
|
|
->filterColumn('country', function ($model, $keyword) { |
134
|
|
|
// removing all white spaces so that it can be searched in a single query |
135
|
|
|
$searchQuery = str_replace(' ', '', $keyword); |
136
|
|
|
$model->whereRaw('country_name like ?', ["%$searchQuery%"]); |
137
|
|
|
}) |
138
|
|
|
->orderColumn('name', 'name $1') |
139
|
|
|
->orderColumn('email', 'email $1') |
140
|
|
|
->orderColumn('mobile', 'mobile $1') |
141
|
|
|
->orderColumn('country', 'country $1') |
142
|
|
|
->orderColumn('created_at', 'created_at $1') |
143
|
|
|
|
144
|
|
|
->rawColumns(['checkbox', 'name', 'email', 'created_at', 'active', 'action']) |
145
|
|
|
->make(true); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function getActiveLabel($mobileActive, $emailActive, $twoFaActive) |
149
|
|
|
{ |
150
|
|
|
$emailLabel = "<i class='fas fa-envelope' style='color:red' <label data-toggle='tooltip' style='font-weight:500;' data-placement='top' title='Unverified email'> </label></i>"; |
151
|
|
|
$mobileLabel = "<i class='fas fa-phone' style='color:red' <label data-toggle='tooltip' style='font-weight:500;' data-placement='top' title='Unverified mobile'> </label></i>"; |
152
|
|
|
$twoFalabel = "<i class='fas fa-qrcode' style='color:red' <label data-toggle='tooltip' style='font-weight:500;' data-placement='top' title='2FA not enabled'> </label></i>"; |
153
|
|
|
if ($mobileActive) { |
154
|
|
|
$mobileLabel = "<i class='fas fa-phone' style='color:green' <label data-toggle='tooltip' style='font-weight:500;' data-placement='top' title='Mobile verified'></label></i>"; |
155
|
|
|
} |
156
|
|
|
if ($emailActive) { |
157
|
|
|
$emailLabel = "<i class='fas fa-envelope' style='color:green' <label data-toggle='tooltip' style='font-weight:500;' data-placement='top' title='Email verified'> </label></i>"; |
158
|
|
|
} |
159
|
|
|
if ($twoFaActive) { |
160
|
|
|
$twoFalabel = "<i class='fas fa-qrcode' style='color:green' <label data-toggle='tooltip' style='font-weight:500;' data-placement='top' title='2FA Enabled'> </label></i>"; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
return $emailLabel.' '.$mobileLabel.' '.$twoFalabel; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Show the form for creating a new resource. |
168
|
|
|
* |
169
|
|
|
* @return \Response |
170
|
|
|
*/ |
171
|
|
|
public function create() |
172
|
|
|
{ |
173
|
|
|
$timezones = new \App\Model\Common\Timezone(); |
174
|
|
|
$timezones = $timezones->pluck('name', 'id')->toArray(); |
175
|
|
|
$bussinesses = \App\Model\Common\Bussiness::pluck('name', 'short')->toArray(); |
176
|
|
|
$managers = User::where('role', 'admin')->where('position', 'manager') |
177
|
|
|
->pluck('first_name', 'id')->toArray(); |
178
|
|
|
$accountManager = User::where('role', 'admin')->where('position', 'account_manager') |
179
|
|
|
->pluck('first_name', 'id')->toArray(); |
180
|
|
|
$timezonesList = \App\Model\Common\Timezone::get(); |
181
|
|
|
foreach ($timezonesList as $timezone) { |
182
|
|
|
$location = $timezone->location; |
183
|
|
|
if ($location) { |
184
|
|
|
$start = strpos($location, '('); |
185
|
|
|
$end = strpos($location, ')', $start + 1); |
186
|
|
|
$length = $end - $start; |
187
|
|
|
$result = substr($location, $start + 1, $length - 1); |
188
|
|
|
$display[] = (['id'=>$timezone->id, 'name'=> '('.$result.')'.' '.$timezone->name]); |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
$timezones = array_column($display, 'name', 'id'); |
192
|
|
|
|
193
|
|
|
return view('themes.default1.user.client.create', compact('timezones', 'bussinesses', 'managers', 'accountManager')); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Store a newly created resource in storage. |
198
|
|
|
* |
199
|
|
|
* @return \Response |
200
|
|
|
*/ |
201
|
|
|
public function store(ClientRequest $request) |
202
|
|
|
{ |
203
|
|
|
try { |
204
|
|
|
$user = $this->user; |
205
|
|
|
$str = 'demopass'; |
206
|
|
|
$password = \Hash::make($str); |
207
|
|
|
$user->password = $password; |
208
|
|
|
if ($request->input('mobile_code') == '') { |
209
|
|
|
$country = new Country(); |
210
|
|
|
$mobile_code = $country->where('country_code_char2', $request->input('country'))->pluck('phonecode')->first(); |
211
|
|
|
} else { |
212
|
|
|
$mobile_code = str_replace('+', '', $request->input('mobile_code')); |
213
|
|
|
} |
214
|
|
|
$currency_symbol = Currency::where('code', $request->input('currency'))->pluck('symbol')->first(); |
215
|
|
|
$location = getLocation(); |
216
|
|
|
$user->user_name = $request->input('user_name'); |
217
|
|
|
$user->first_name = $request->input('first_name'); |
218
|
|
|
$user->last_name = $request->input('last_name'); |
219
|
|
|
$user->email = $request->input('email'); |
220
|
|
|
$user->password = $password; |
221
|
|
|
$user->company = $request->input('company'); |
222
|
|
|
$user->bussiness = $request->input('bussiness'); |
223
|
|
|
$user->active = $request->input('active'); |
224
|
|
|
$user->mobile_verified = $request->input('mobile_verified'); |
225
|
|
|
$user->role = $request->input('role'); |
226
|
|
|
$user->position = $request->input('position'); |
227
|
|
|
$user->company_type = $request->input('company_type'); |
228
|
|
|
$user->company_size = $request->input('company_size'); |
229
|
|
|
$user->address = $request->input('address'); |
230
|
|
|
$user->town = $request->input('town'); |
231
|
|
|
$user->country = $request->input('country'); |
232
|
|
|
$user->state = $request->input('state'); |
233
|
|
|
$user->zip = $request->input('zip'); |
234
|
|
|
$user->timezone_id = $request->input('timezone_id'); |
235
|
|
|
$user->currency = $request->input('currency'); |
236
|
|
|
$user->mobile_code = $mobile_code; |
237
|
|
|
$user->mobile = $request->input('mobile'); |
238
|
|
|
$user->skype = $request->input('skype'); |
239
|
|
|
$user->manager = $request->input('manager'); |
240
|
|
|
$user->account_manager = $request->input('account_manager'); |
241
|
|
|
$user->currency_symbol = $currency_symbol; |
242
|
|
|
$user->ip = $location['ip']; |
243
|
|
|
|
244
|
|
|
$user->save(); |
245
|
|
|
if (emailSendingStatus() && ! $user->active) { |
246
|
|
|
$this->sendWelcomeMail($user); |
247
|
|
|
} |
248
|
|
|
$mailchimpStatus = StatusSetting::first()->value('mailchimp_status'); |
249
|
|
|
if ($mailchimpStatus == 1) { |
250
|
|
|
$mailchimp = new \App\Http\Controllers\Common\MailChimpController(); |
251
|
|
|
$r = $mailchimp->addSubscriber($user->email); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
return redirect()->back()->with('success', \Lang::get('message.saved-successfully')); |
255
|
|
|
} catch (\Swift_TransportException $e) { |
256
|
|
|
return redirect()->back()->with('warning', 'User has been created successfully |
257
|
|
|
But email configuration has some problem!'); |
258
|
|
|
} catch (\Exception $e) { |
259
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Display the specified resource. |
265
|
|
|
* |
266
|
|
|
* @param int $id |
267
|
|
|
* |
268
|
|
|
* @return \Response |
269
|
|
|
*/ |
270
|
|
|
public function show($id) |
271
|
|
|
{ |
272
|
|
|
try { |
273
|
|
|
if (User::onlyTrashed()->find($id)) { |
274
|
|
|
throw new \Exception('This user is suspended from system. Restore the user to view details.'); |
275
|
|
|
} |
276
|
|
|
$invoice = new Invoice(); |
277
|
|
|
$order = new Order(); |
278
|
|
|
$invoices = $invoice->where('user_id', $id)->orderBy('created_at', 'desc')->get(); |
279
|
|
|
$invoiceSum = $this->getTotalInvoice($invoices); |
280
|
|
|
$amountReceived = $this->getAmountPaid($id); |
281
|
|
|
$pendingAmount = $invoiceSum - $amountReceived; |
282
|
|
|
// $pendingAmount = $invoiceSum - $amountReceived; |
283
|
|
|
// if ($pendingAmount < 0) { |
284
|
|
|
// $pendingAmount = 0; |
285
|
|
|
// } |
286
|
|
|
$extraAmt = $this->getExtraAmt($id); |
287
|
|
|
$client = $this->user->where('id', $id)->first(); |
288
|
|
|
|
289
|
|
|
if (User::onlyTrashed()->find($id)) { |
290
|
|
|
$client = User::onlyTrashed()->find($id); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
$is2faEnabled = $client->is_2fa_enabled; |
294
|
|
|
// $client = ""; |
295
|
|
|
$currency = $client->currency; |
296
|
|
|
$orders = $order->where('client', $id)->get(); |
297
|
|
|
$comments = Comment::where('user_id', $client->id)->get(); |
298
|
|
|
|
299
|
|
|
return view( |
300
|
|
|
'themes.default1.user.client.show', |
301
|
|
|
compact('id','client','invoices','orders','invoiceSum','amountReceived','pendingAmount','currency','extraAmt','comments', |
302
|
|
|
'is2faEnabled') |
303
|
|
|
); |
304
|
|
|
} catch (\Exception $ex) { |
305
|
|
|
app('log')->info($ex->getMessage()); |
306
|
|
|
Bugsnag::notifyException($ex); |
307
|
|
|
|
308
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
309
|
|
|
} |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Show the form for editing the specified resource. |
314
|
|
|
* |
315
|
|
|
* @param int $id |
316
|
|
|
* |
317
|
|
|
* @return \Response |
318
|
|
|
*/ |
319
|
|
|
public function edit($id) |
320
|
|
|
{ |
321
|
|
|
try { |
322
|
|
|
$user = $this->user->where('id', $id)->first(); |
323
|
|
|
$timezonesList = \App\Model\Common\Timezone::get(); |
324
|
|
|
foreach ($timezonesList as $timezone) { |
325
|
|
|
$location = $timezone->location; |
326
|
|
|
if ($location) { |
327
|
|
|
$start = strpos($location, '('); |
328
|
|
|
$end = strpos($location, ')', $start + 1); |
329
|
|
|
$length = $end - $start; |
330
|
|
|
$result = substr($location, $start + 1, $length - 1); |
331
|
|
|
$display[] = (['id'=>$timezone->id, 'name'=> '('.$result.')'.' '.$timezone->name]); |
332
|
|
|
} |
333
|
|
|
} |
334
|
|
|
//for display |
335
|
|
|
$timezones = array_column($display, 'name', 'id'); |
336
|
|
|
$state = getStateByCode($user->state); |
337
|
|
|
$managers = User::where('role', 'admin') |
338
|
|
|
->where('position', 'manager') |
339
|
|
|
->pluck('first_name', 'id')->toArray(); |
340
|
|
|
$acc_managers = User::where('role', 'admin') |
341
|
|
|
->where('position', 'account_manager') |
342
|
|
|
->pluck('first_name', 'id')->toArray(); |
343
|
|
|
$selectedCurrency = Currency::where('code', $user->currency) |
344
|
|
|
->pluck('name', 'code')->toArray(); |
345
|
|
|
$selectedCompany = \DB::table('company_types')->where('name', $user->company_type) |
346
|
|
|
->pluck('name', 'short')->toArray(); |
347
|
|
|
$selectedIndustry = \App\Model\Common\Bussiness::where('name', $user->bussiness) |
348
|
|
|
->pluck('name', 'short')->toArray(); |
349
|
|
|
$selectedCompanySize = \DB::table('company_sizes')->where('short', $user->company_size) |
350
|
|
|
->pluck('name', 'short')->toArray(); |
351
|
|
|
$states = findStateByRegionId($user->country); |
352
|
|
|
|
353
|
|
|
$bussinesses = \App\Model\Common\Bussiness::pluck('name', 'short')->toArray(); |
354
|
|
|
|
355
|
|
|
return view( |
356
|
|
|
'themes.default1.user.client.edit', |
357
|
|
|
compact( |
358
|
|
|
'bussinesses', |
359
|
|
|
'user', |
360
|
|
|
'timezones', |
361
|
|
|
'state', |
362
|
|
|
'states', |
363
|
|
|
'managers', |
364
|
|
|
'selectedCurrency', |
365
|
|
|
'selectedCompany', |
366
|
|
|
'selectedIndustry', |
367
|
|
|
'selectedCompanySize', |
368
|
|
|
'acc_managers' |
369
|
|
|
) |
370
|
|
|
); |
371
|
|
|
} catch (\Exception $ex) { |
372
|
|
|
app('log')->error($ex->getMessage()); |
373
|
|
|
|
374
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Update the specified resource in storage. |
380
|
|
|
* |
381
|
|
|
* @param int $id |
382
|
|
|
* |
383
|
|
|
* @return \Response |
384
|
|
|
*/ |
385
|
|
|
public function update($id, ClientRequest $request) |
386
|
|
|
{ |
387
|
|
|
try { |
388
|
|
|
$user = $this->user->where('id', $id)->first(); |
389
|
|
|
$symbol = Currency::where('code', $request->input('currency'))->pluck('symbol')->first(); |
390
|
|
|
$user->currency_symbol = $symbol; |
391
|
|
|
$user->fill($request->input())->save(); |
392
|
|
|
// \Session::put('test', 1000); |
393
|
|
|
return redirect()->back()->with('success', \Lang::get('message.updated-successfully')); |
394
|
|
|
} catch (\Exception $ex) { |
395
|
|
|
app('log')->error($ex->getMessage()); |
396
|
|
|
Bugsnag::notifyException($ex); |
397
|
|
|
|
398
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
399
|
|
|
} |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* Remove the specified resource from storage. |
404
|
|
|
* |
405
|
|
|
* @param int $id |
406
|
|
|
* |
407
|
|
|
* @return \Response |
408
|
|
|
*/ |
409
|
|
|
public function destroy(Request $request) |
410
|
|
|
{ |
411
|
|
|
try { |
412
|
|
|
$ids = $request->input('select'); |
413
|
|
|
if (! empty($ids)) { |
414
|
|
|
foreach ($ids as $id) { |
415
|
|
|
$user = $this->user->where('id', $id)->first(); |
416
|
|
|
//Check if this admin is account manager and is assigned as account manager to other clients |
417
|
|
|
$isAccountManager = User::where('account_manager', $id)->get(); |
418
|
|
|
$isSalesManager = User::where('manager', $id)->get(); |
419
|
|
|
if (count($isSalesManager) > 0) { |
420
|
|
|
throw new \Exception('Admin'.' '.$user->first_name.' '.$user->last_name.' '.'cannot be deleted as he/she is existing sales manager for certain clients. Please replace Sales Manager from settings and then try deleting.'); |
421
|
|
|
} |
422
|
|
|
if (count($isAccountManager) > 0) { |
423
|
|
|
throw new \Exception('Admin'.' '.$user->first_name.' '.$user->last_name.' '.'cannot be deleted as he/she is existing account manager for certain clients. Please replace Account Manager from settings and then try deleting.'); |
424
|
|
|
} |
425
|
|
|
if ($user) { |
426
|
|
|
$user->delete(); |
427
|
|
|
} else { |
428
|
|
|
echo "<div class='alert alert-success alert-dismissable'> |
429
|
|
|
<i class='fa fa-ban'></i> |
430
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
431
|
|
|
/* @scrutinizer ignore-type */ |
432
|
|
|
\Lang::get('message.success').' |
433
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
434
|
|
|
'./* @scrutinizer ignore-type */\Lang::get('message.no-record').' |
435
|
|
|
</div>'; |
436
|
|
|
//echo \Lang::get('message.no-record') . ' [id=>' . $id . ']'; |
437
|
|
|
} |
438
|
|
|
} |
439
|
|
|
echo "<div class='alert alert-success alert-dismissable'> |
440
|
|
|
<i class='fa fa-ban'></i> |
441
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert') |
442
|
|
|
.'!</b> './* @scrutinizer ignore-type */ |
443
|
|
|
\Lang::get('message.success').' |
444
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
445
|
|
|
'./* @scrutinizer ignore-type */\Lang::get('message.deleted-successfully').' |
446
|
|
|
</div>'; |
447
|
|
|
} else { |
448
|
|
|
echo "<div class='alert alert-success alert-dismissable'> |
449
|
|
|
<i class='fa fa-ban'></i> |
450
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> ' |
451
|
|
|
./* @scrutinizer ignore-type */\Lang::get('message.success').' |
452
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
453
|
|
|
'./* @scrutinizer ignore-type */\Lang::get('message.select-a-row').' |
454
|
|
|
</div>'; |
455
|
|
|
} |
456
|
|
|
} catch (\Exception $e) { |
457
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
458
|
|
|
<i class='fa fa-ban'></i> |
459
|
|
|
<b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
460
|
|
|
/* @scrutinizer ignore-type */' |
461
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
462
|
|
|
'.$e->getMessage().' |
463
|
|
|
</div>'; |
464
|
|
|
} |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
public function sendWelcomeMail($user) |
468
|
|
|
{ |
469
|
|
|
$activate_model = new AccountActivate(); |
470
|
|
|
$str = str_random(40); |
471
|
|
|
$activate = $activate_model->create(['email' => $user->email, 'token' => $str]); |
472
|
|
|
$token = $activate->token; |
473
|
|
|
$url = url("activate/$token"); |
474
|
|
|
//check in the settings |
475
|
|
|
$settings = new \App\Model\Common\Setting(); |
476
|
|
|
$setting = $settings->where('id', 1)->first(); |
477
|
|
|
//template |
478
|
|
|
$templates = new \App\Model\Common\Template(); |
479
|
|
|
$temp_id = $setting->welcome_mail; |
480
|
|
|
$template = $templates->where('id', $temp_id)->first(); |
481
|
|
|
$from = $setting->email; |
482
|
|
|
$to = $user->email; |
483
|
|
|
$subject = $template->name; |
484
|
|
|
$data = $template->data; |
485
|
|
|
$replace = ['name' => $user->first_name.' '.$user->last_name, |
486
|
|
|
'username' => $user->email, 'password' => $str, 'url' => $url, ]; |
487
|
|
|
$type = ''; |
488
|
|
|
if ($template) { |
489
|
|
|
$type_id = $template->type; |
490
|
|
|
$temp_type = new \App\Model\Common\TemplateType(); |
491
|
|
|
$type = $temp_type->where('id', $type_id)->first()->name; |
492
|
|
|
} |
493
|
|
|
$mail = new \App\Http\Controllers\Common\PhpMailController(); |
494
|
|
|
$mail->sendEmail($from, $to, $data, $subject, $replace, $type); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* Gets baseQuery for user search by appending all the allowed filters. |
499
|
|
|
* @param $request |
500
|
|
|
* @return mixed |
501
|
|
|
*/ |
502
|
|
|
private function getBaseQueryForUserSearch(Request $request) |
503
|
|
|
{ |
504
|
|
|
$baseQuery = User::leftJoin('countries', 'users.country', '=', 'countries.country_code_char2') |
505
|
|
|
->select('id', 'first_name', 'last_name', 'email', |
506
|
|
|
\DB::raw("CONCAT('+', mobile_code, ' ', mobile) as mobile"), |
507
|
|
|
\DB::raw("CONCAT(first_name, ' ', last_name) as name"), |
508
|
|
|
'country_name as country', 'created_at', 'active', 'mobile_verified', 'is_2fa_enabled', 'role', 'position' |
509
|
|
|
)->when($request->company, function ($query) use ($request) { |
510
|
|
|
$query->where('company', 'LIKE', '%'.$request->company.'%'); |
511
|
|
|
})->when($request->country, function ($query) use ($request) { |
512
|
|
|
$query->where('country', $request->country); |
513
|
|
|
})->when($request->industry, function ($query) use ($request) { |
514
|
|
|
$query->where('bussiness', $request->industry); |
515
|
|
|
})->when($request->role, function ($query) use ($request) { |
516
|
|
|
$query->where('role', $request->role); |
517
|
|
|
})->when($request->position, function ($query) use ($request) { |
518
|
|
|
$query->where('position', $request->position); |
519
|
|
|
})->when($request->actmanager, function ($query) use ($request) { |
520
|
|
|
$query->where('account_manager', $request->actmanager); |
521
|
|
|
})->when($request->salesmanager, function ($query) use ($request) { |
522
|
|
|
$query->where('manager', $request->salesmanager); |
523
|
|
|
}); |
524
|
|
|
|
525
|
|
|
$baseQuery = $this->getregFromTill($baseQuery, $request->reg_from, $request->reg_till); |
526
|
|
|
|
527
|
|
|
return $baseQuery; |
528
|
|
|
} |
529
|
|
|
} |
530
|
|
|
|