Test Setup Failed
Push — development ( 7589fb...de5847 )
by Ashutosh
08:45
created

ClientController::store()   A

Complexity

Conditions 3
Paths 19

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 21
rs 9.7
c 0
b 0
f 0
cc 3
nc 19
nop 1
1
<?php
2
3
namespace App\Http\Controllers\User;
4
5
use App\Http\Controllers\License\LicenseController;
6
use App\Http\Requests\User\ClientRequest;
7
use App\Model\Order\Invoice;
8
use App\Model\Order\Order;
9
use App\Model\Order\Payment;
10
use App\Model\Payment\Currency;
11
use App\Traits\PaymentsAndInvoices;
12
use App\Model\User\AccountActivate;
13
use App\User;
14
use Bugsnag;
15
use DateTime;
16
use DateTimeZone;
17
use Illuminate\Http\Request;
18
use Log;
19
20
class ClientController extends AdvanceSearchController
21
{
22
    use PaymentsAndInvoices;
0 ignored issues
show
introduced by
The trait App\Traits\PaymentsAndInvoices requires some properties which are not provided by App\Http\Controllers\User\ClientController: $grand_total, $first_name, $planPrice, $domain, $user_id, $payment_method, $payment, $product_quantity, $payment_status, $invoice, $id, $amt_to_credit, $planRelation, $invoiceItem, $invoice_id, $no_of_agents
Loading history...
23
24
    public $user;
25
    public $activate;
26
    public $product;
27
28
    public function __construct()
29
    {
30
        $this->middleware('auth');
31
        // $this->middleware('admin');
32
        $user = new User();
33
        $this->user = $user;
34
        $activate = new AccountActivate();
35
        $this->activate = $activate;
36
        $product = new \App\Model\Product\Product();
37
        $this->product = $product;
38
        $license = new LicenseController();
39
        $this->licensing = $license;
40
    }
41
42
    /**
43
     * Display a listing of the resource.
44
     *
45
     * @return \Response
46
     */
47
    public function index(Request $request)
48
    {
49
        $name = $request->input('name');
50
        $username = $request->input('username');
51
        $company = $request->input('company');
52
        $mobile = $request->input('mobile');
53
        $email = $request->input('email');
54
        $country = $request->input('country');
55
        $industry = $request->input('industry');
56
        $company_type = $request->input('company_type');
57
        $company_size = $request->input('company_size');
58
        $role = $request->input('role');
59
        $position = $request->input('position');
60
        $reg_from = $request->input('reg_from');
61
        $reg_till = $request->input('reg_till');
62
63
        return view(
64
            'themes.default1.user.client.index',
65
            compact(
66
                'name',
67
                'username',
68
                'company',
69
                'mobile',
70
                'email',
71
                'country',
72
                'industry',
73
                'company_type',
74
                'company_size',
75
                'role',
76
                'position',
77
                'reg_from',
78
                'reg_till'
79
            )
80
        );
81
    }
82
83
    /**
84
     * Get Clients for yajra datatable.
85
     */
86
    public function getClients(Request $request)
87
    {
88
        $name = $request->input('name');
89
        $username = $request->input('username');
90
        $company = $request->input('company');
91
        $mobile = $request->input('mobile');
92
        $email = $request->input('email');
93
        $country = $request->input('country');
94
        $industry = $request->input('industry');
95
        $company_type = $request->input('company_type');
96
        $company_size = $request->input('company_size');
97
        $role = $request->input('role');
98
        $position = $request->input('position');
99
        $reg_from = $request->input('reg_from');
100
        $reg_till = $request->input('reg_till');
101
        $user = $this->advanceSearch(
102
            $name,
103
            $username,
104
            $company,
105
            $mobile,
106
            $email,
107
            $country,
108
            $industry,
109
            $company_type,
110
            $company_size,
111
            $role,
112
            $position,
113
            $reg_from,
114
            $reg_till
115
        );
116
117
        return\ DataTables::of($user->get())
118
                         ->addColumn('checkbox', function ($model) {
119
                             return "<input type='checkbox' class='user_checkbox' 
120
                            value=".$model->id.' name=select[] id=check>';
121
                         })
122
                        ->addColumn('first_name', function ($model) {
123
                            return '<a href='.url('clients/'.$model->id).'>'
124
                            .ucfirst($model->first_name).' '.ucfirst($model->last_name).'</a>';
125
                        })
126
                         ->addColumn('email', function ($model) {
127
                             return $model->email;
128
                         })
129
                          ->addColumn('created_at', function ($model) {
130
                              $ends = $model->created_at;
131
                            if ($ends) {
132
                                $date1 = new DateTime($ends);
133
                                $tz = \Auth::user()->timezone()->first()->name;
134
                                $date1->setTimezone(new DateTimeZone($tz));
135
                                $end = $date1->format('M j, Y, g:i a ');
136
                            }
137
138
                              return $end;
139
                          })
140
                        // ->showColumns('email', 'created_at')
141
                        ->addColumn('active', function ($model) {
142
                            if ($model->active == 1) {
143
                                $email = "<span class='glyphicon glyphicon-envelope'
144
                                 style='color:green' title='verified email'></span>";
145
                            } else {
146
                                $email = "<span class='glyphicon glyphicon-envelope'
147
                                 style='color:red' title='unverified email'></span>";
148
                            }
149
                            if ($model->mobile_verified == 1) {
150
                                $mobile = "<span class='glyphicon glyphicon-phone' 
151
                                style='color:green' title='verified mobile'></span>";
152
                            } else {
153
                                $mobile = "<span class='glyphicon glyphicon-phone'
154
                                 style='color:red' title='unverified mobile'></span>";
155
                            }
156
157
                            return $email.'&nbsp;&nbsp;'.$mobile;
158
                        })
159
                        ->addColumn('action', function ($model) {
160
                            return '<a href='.url('clients/'.$model->id.'/edit')
161
                            ." class='btn btn-sm btn-primary btn-xs'>
162
                            <i class='fa fa-edit' style='color:white;'> </i>&nbsp;&nbsp;Edit</a>"
163
                                    .'  <a href='.url('clients/'.$model->id)
164
                                    ." class='btn btn-sm btn-primary btn-xs'>
165
                                    <i class='fa fa-eye' style='color:white;'> </i>&nbsp;&nbsp;View</a>";
166
                            // return 'hhhh';
167
                        })
168
                        ->rawColumns(['checkbox', 'first_name', 'email',  'created_at', 'active', 'action'])
169
                        ->make(true);
170
171
        // ->searchColumns('email', 'first_name')
172
                        // ->orderColumns('email', 'first_name', 'created_at')
173
                        // ->make();
174
    }
175
176
    /**
177
     * Show the form for creating a new resource.
178
     *
179
     * @return \Response
180
     */
181
    public function create()
182
    {
183
        $timezones = new \App\Model\Common\Timezone();
184
        $timezones = $timezones->pluck('name', 'id')->toArray();
185
        $bussinesses = \App\Model\Common\Bussiness::pluck('name', 'short')->toArray();
186
        $managers = User::where('role', 'admin')->where('position', 'manager')
187
        ->pluck('first_name', 'id')->toArray();
188
        $timezonesList = \App\Model\Common\Timezone::get();
189
        foreach ($timezonesList as $timezone) {
190
            $location = $timezone->location;
191
            if ($location) {
192
                $start = strpos($location, '(');
193
                $end = strpos($location, ')', $start + 1);
194
                $length = $end - $start;
195
                $result = substr($location, $start + 1, $length - 1);
196
                $display[] = (['id'=>$timezone->id, 'name'=> '('.$result.')'.' '.$timezone->name]);
197
            }
198
        }
199
        $timezones = array_column($display, 'name', 'id');
200
201
        return view('themes.default1.user.client.create', compact('timezones', 'bussinesses', 'managers'));
202
    }
203
204
    /**
205
     * Store a newly created resource in storage.
206
     *
207
     * @return \Response
208
     */
209
    public function store(ClientRequest $request)
210
    {
211
        try {
212
            $user = $this->user;
213
            $str = 'demopass';
214
            $password = \Hash::make($str);
215
            $user->password = $password;
216
            $cont = new \App\Http\Controllers\Front\PageController();
217
            $location = $cont->getLocation();
218
            $user->ip = $location['ip'];
219
            $user->fill($request->input())->save();
220
            $this->sendWelcomeMail($user);
221
            $mailchimp = new \App\Http\Controllers\Common\MailChimpController();
222
            $r = $mailchimp->addSubscriber($user->email);
223
224
            return redirect()->back()->with('success', \Lang::get('message.saved-successfully'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...e.saved-successfully')) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
225
        } catch (\Swift_TransportException $e) {
226
            return redirect()->back()->with('warning', 'User has been created successfully
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...ion has some problem!') also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
227
             But email configuration has some problem!');
228
        } catch (\Exception $e) {
229
            return redirect()->back()->with('fails', $e->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...ils', $e->getMessage()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
230
        }
231
    }
232
233
    /**
234
     * Display the specified resource.
235
     *
236
     * @param int $id
237
     *
238
     * @return \Response
239
     */
240
    public function show($id)
241
    {
242
        try {
243
            $invoice = new Invoice();
244
            $order = new Order();
245
            $invoices = $invoice->where('user_id', $id)->orderBy('created_at', 'desc')->get();
246
            $invoiceSum = $this->getTotalInvoice($invoices);
247
            $amountReceived = $this->getAmountPaid($id);
248
            $pendingAmount = $invoiceSum - $amountReceived;
249
            // $pendingAmount = $invoiceSum - $amountReceived;
250
            // if ($pendingAmount < 0) {
251
            //     $pendingAmount = 0;
252
            // }
253
            $extraAmt = $this->getExtraAmt($id);
254
            $client = $this->user->where('id', $id)->first();
255
256
            // $client = "";
257
            $currency = $client->currency;
258
            $orders = $order->where('client', $id)->get();
259
            $comments = $client->comments()->where('user_id', $client->id)->get();
260
261
            return view(
262
                'themes.default1.user.client.show',
263
                compact(
264
                    'id',
265
                    'client',
266
                    'invoices',
267
                    'model_popup',
268
                    'orders',
269
                    'payments',
270
                    'invoiceSum',
271
                    'amountReceived',
272
                    'pendingAmount',
273
                    'currency',
274
                    'extraAmt',
275
                    'comments'
276
                )
277
            );
278
        } catch (\Exception $ex) {
279
            app('log')->info($ex->getMessage());
280
            Bugsnag::notifyException($ex);
281
282
            return redirect()->back()->with('fails', $ex->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...ls', $ex->getMessage()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
283
        }
284
    }
285
286
    public function getOrderDetail($id)
287
    {
288
        $client = $this->user->where('id', $id)->first();
289
        $responseData = [];
290
        foreach ($client->order()->orderBy('created_at', 'desc')->get() as $order) {
291
            $date = $order->created_at;
292
            $productName = $order->product()->first() && $order->product()->first()->name ?
293
            $order->product()->first()->name : 'Unknown';
294
            $number = $order->number;
295
            $price = $order->price_override;
296
            $status = $order->order_status;
297
            array_push($responseData, (['date'=> $date, 'productName'=>$productName,
298
                'number'                      => $number, 'price' =>$price, 'status'=>$status, ]));
299
        }
300
301
        return $responseData;
302
    }
303
304
    //Get Payment Details on Invoice Page
305
    public function getPaymentDetail($id)
306
    {
307
        $client = $this->user->where('id', $id)->first();
308
        $invoice = new Invoice();
309
        $invoices = $invoice->where('user_id', $id)->orderBy('created_at', 'desc')->get();
310
        $extraAmt = $this->getExtraAmtPaid($id);
311
        $date = '';
312
        $responseData = [];
313
        if ($invoices) {
314
            foreach ($client->payment()->orderBy('created_at', 'desc')->get() as $payment) {
315
                $number = $payment->invoice()->first() ? $payment->invoice()->first()->number : '--';
316
                $date = $payment->created_at;
317
                $date1 = new DateTime($date);
318
                $tz = \Auth::user()->timezone()->first()->name;
319
                $date1->setTimezone(new DateTimeZone($tz));
320
                $date = $date1->format('M j, Y, g:i a ');
321
                $pay_method = $payment->payment_method;
322
                if ($payment->invoice_id == 0) {
323
                    $amount = $extraAmt;
324
                } else {
325
                    $amount = $payment->amount;
326
                }
327
                $status = ucfirst($payment->payment_status);
328
                array_push($responseData, (['number'=>$number, 'pay_method'=>$pay_method, 'amount'=>$amount, 'status'=>$status, 'date'=>$date]));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 145 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
329
            }
330
        }
331
332
        return $responseData;
333
    }
334
335
    public function getClientDetail($id)
336
    {
337
        $client = $this->user->where('id', $id)->first();
338
        $currency = $client->currency;
339
        if (array_key_exists('name', \App\Http\Controllers\Front\CartController::getStateByCode($client->state))) {
340
            $client->state = \App\Http\Controllers\Front\CartController::getStateByCode($client->state)['name'];
341
        }
342
        $client->country = ucwords(strtolower(\App\Http\Controllers\Front\CartController::getCountryByCode($client->country)));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
343
344
        $displayData = (['currency'=>$currency, 'client'=> $client]);
345
346
        return $displayData;
347
    }
348
349
    public function getExtraAmt($userId)
350
    {
351
        try {
352
            $amounts = Payment::where('user_id', $userId)->where('invoice_id', 0)->select('amt_to_credit')->get();
353
            $balance = 0;
354
            foreach ($amounts as $amount) {
355
                if ($amount) {
356
                    $balance = $balance + $amount->amt_to_credit ;
357
                }
358
            }
359
        return $balance;
360
        } catch (\Exception $ex) {
361
            app('log')->info($ex->getMessage());
362
            Bugsnag::notifyException($ex);
363
364
            return redirect()->back()->with('fails', $ex->getMessage());
365
        }
366
    }
367
368
    /**
369
     * Get total Amount paid for a particular invoice.
370
     */
371
    public function getAmountPaid($userId)
372
    {
373
        try {
374
            $amounts = Payment::where('user_id', $userId)->select('amount', 'amt_to_credit')->get();
375
            $paidSum = 0;
376
            foreach ($amounts as $amount) {
377
                if ($amount) {
378
                    $paidSum = $paidSum + $amount->amount;
379
                    // $credit = $paidSum + $amount->amt_to_credit;
380
                }
381
            }
382
            return $paidSum;
383
        } catch (\Exception $ex) {
384
            app('log')->info($ex->getMessage());
385
            Bugsnag::notifyException($ex);
386
387
            return redirect()->back()->with('fails', $ex->getMessage());
388
        }
389
    }
390
391
    /**
392
     * Get total of the Invoices for a User.
393
     */
394
    public function getTotalInvoice($invoices)
395
    {
396
        $sum = 0;
397
        foreach ($invoices as $invoice) {
398
            $sum = $sum + $invoice->grand_total;
399
        }
400
401
        return $sum;
402
    }
403
404
    /**
405
     * Show the form for editing the specified resource.
406
     *
407
     * @param int $id
408
     *
409
     * @return \Response
410
     */
411
    public function edit($id)
412
    {
413
        try {
414
            $user = $this->user->where('id', $id)->first();
415
            $timezonesList = \App\Model\Common\Timezone::get();
416
            foreach ($timezonesList as $timezone) {
417
                $location = $timezone->location;
418
                if ($location) {
419
                    $start = strpos($location, '(');
420
                    $end = strpos($location, ')', $start + 1);
421
                    $length = $end - $start;
422
                    $result = substr($location, $start + 1, $length - 1);
423
                    $display[] = (['id'=>$timezone->id, 'name'=> '('.$result.')'.' '.$timezone->name]);
424
                }
425
            }
426
            //for display
427
            $timezones = array_column($display, 'name', 'id');
428
            $state = \App\Http\Controllers\Front\CartController::getStateByCode($user->state);
429
            $managers = User::where('role', 'admin')
430
            ->where('position', 'manager')
431
            ->pluck('first_name', 'id')->toArray();
432
            $selectedCurrency = Currency::where('code', $user->currency)
433
            ->pluck('name', 'code')->toArray();
434
            $selectedCompany = \DB::table('company_types')->where('short', $user->company_type)
435
            ->pluck('name', 'short')->toArray();
436
            $selectedIndustry = \App\Model\Common\Bussiness::where('short', $user->bussiness)
437
            ->pluck('name', 'short')->toArray();
438
            $selectedCompanySize = \DB::table('company_sizes')->where('short', $user->company_size)
439
            ->pluck('name', 'short')->toArray();
440
            $states = \App\Http\Controllers\Front\CartController::findStateByRegionId($user->country);
441
442
            $bussinesses = \App\Model\Common\Bussiness::pluck('name', 'short')->toArray();
443
444
            return view(
445
                'themes.default1.user.client.edit',
446
                compact(
447
                    'bussinesses',
448
                    'user',
449
                    'timezones',
450
                    'state',
451
                    'states',
452
                    'managers',
453
                    'selectedCurrency',
454
                    'selectedCompany',
455
                    'selectedIndustry',
456
                    'selectedCompanySize'
457
                )
458
            );
459
        } catch (\Exception $ex) {
460
            app('log')->error($ex->getMessage());
461
462
            return redirect()->back()->with('fails', $ex->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...ls', $ex->getMessage()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
463
        }
464
    }
465
466
    /**
467
     * Update the specified resource in storage.
468
     *
469
     * @param int $id
470
     *
471
     * @return \Response
472
     */
473
    public function update($id, Request $request)
474
    {
475
        try {
476
            $user = $this->user->where('id', $id)->first();
477
            $symbol = Currency::where('code', $request->input('currency'))->pluck('symbol')->first();
478
            $user->currency_symbol = $symbol;
479
            $user->fill($request->input())->save();
480
481
            return redirect()->back()->with('success', \Lang::get('message.updated-successfully'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...updated-successfully')) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
482
        } catch (\Exception $ex) {
483
            app('log')->error($ex->getMessage());
484
            Bugsnag::notifyException($ex);
485
486
            return redirect()->back()->with('fails', $ex->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...ls', $ex->getMessage()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
487
        }
488
    }
489
490
    /**
491
     * Remove the specified resource from storage.
492
     *
493
     * @param int $id
494
     *
495
     * @return \Response
496
     */
497
    public function destroy(Request $request)
498
    {
499
        $ids = $request->input('select');
500
        if (!empty($ids)) {
501
            foreach ($ids as $id) {
502
                $user = $this->user->where('id', $id)->first();
503
                if ($user) {
504
                    $user->delete();
505
                } else {
506
                    echo "<div class='alert alert-success alert-dismissable'>
507
                    <i class='fa fa-ban'></i>
508
                    <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '.
509
                    /* @scrutinizer ignore-type */
510
                    \Lang::get('message.success').'
511
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
512
                        './* @scrutinizer ignore-type */\Lang::get('message.no-record').'
513
                </div>';
514
                    //echo \Lang::get('message.no-record') . '  [id=>' . $id . ']';
515
                }
516
            }
517
            echo "<div class='alert alert-success alert-dismissable'>
518
                    <i class='fa fa-ban'></i>
519
                    <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert')
520
                    .'!</b> './* @scrutinizer ignore-type */
521
                    \Lang::get('message.success').'
522
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
523
                        './* @scrutinizer ignore-type */\Lang::get('message.deleted-successfully').'
524
                </div>';
525
        } else {
526
            echo "<div class='alert alert-success alert-dismissable'>
527
                    <i class='fa fa-ban'></i>
528
                    <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '
529
                    ./* @scrutinizer ignore-type */\Lang::get('message.success').'
530
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
531
                        './* @scrutinizer ignore-type */\Lang::get('message.select-a-row').'
532
                </div>';
533
        }
534
    }
535
536
    public function getUsers(Request $request)
537
    {
538
        $options = $this->user
539
//->where('email','LIKE','%'.$s.'%')
540
                ->select('email AS text', 'id AS value')
541
                ->get();
542
543
        return response()->json(compact('options'));
544
    }
545
546
    public function search(Request $request)
547
    {
548
        try {
549
            $term = trim($request->q);
550
            if (empty($term)) {
551
                return \Response::json([]);
552
            }
553
            $users = User::where('email', 'LIKE', '%'.$term.'%')
554
             ->orWhere('first_name', 'LIKE', '%'.$term.'%')
555
             ->orWhere('last_name', 'LIKE', '%'.$term.'%')
556
             ->select('id', 'email', 'profile_pic', 'first_name', 'last_name')->get();
557
            $formatted_tags = [];
558
559
            foreach ($users as $user) {
560
                $formatted_users[] = ['id' => $user->id, 'text' => $user->email, 'profile_pic' => $user->profile_pic,
561
                'first_name'                   => $user->first_name, 'last_name' => $user->last_name, ];
562
            }
563
564
            return \Response::json($formatted_users);
565
        } catch (\Exception $e) {
566
            // returns if try fails with exception meaagse
567
            return redirect()->back()->with('fails', $e->getMessage());
568
        }
569
    }
570
571
    public function advanceSearch(
572
        $name = '',
573
        $username = '',
574
        $company = '',
575
        $mobile = '',
576
        $email = '',
577
        $country = '',
578
        $industry = '',
579
        $company_type = '',
580
        $company_size = '',
581
        $role = '',
582
        $position = '',
583
        $reg_from = '',
584
        $reg_till = ''
585
    ) {
586
        $join = \DB::table('users');
587
        $join = $this->getNamUserCom($join, $name, $username, $company);
588
        $join = $this->getMobEmCoun($join, $mobile, $email, $country);
589
        $join = $this->getInCtCs($join, $industry, $company_type, $company_size);
590
        $join = $this->getRolPos($join, $role, $position);
591
        $join = $this->getregFromTill($join, $reg_from, $reg_till);
592
593
        $join = $join->orderBy('created_at', 'desc')
594
        ->select(
595
            'id',
596
            'first_name',
597
            'last_name',
598
            'email',
599
            'created_at',
600
            'active',
601
            'mobile_verified',
602
            'role',
603
            'position'
604
        );
605
606
        return $join;
607
    }
608
609
    public function sendWelcomeMail($user)
610
    {
611
        $activate_model = new AccountActivate();
612
        $str = str_random(40);
613
        $activate = $activate_model->create(['email' => $user->email, 'token' => $str]);
614
        $token = $activate->token;
615
        $url = url("activate/$token");
616
        //check in the settings
617
        $settings = new \App\Model\Common\Setting();
618
        $setting = $settings->where('id', 1)->first();
619
        //template
620
        $templates = new \App\Model\Common\Template();
621
        $temp_id = $setting->welcome_mail;
622
        $template = $templates->where('id', $temp_id)->first();
623
        $from = $setting->email;
624
        $to = $user->email;
625
        $subject = $template->name;
626
        $data = $template->data;
627
        $replace = ['name' => $user->first_name.' '.$user->last_name,
628
        'username'         => $user->email, 'password' => $str, 'url' => $url, ];
629
        $type = '';
630
        if ($template) {
631
            $type_id = $template->type;
632
            $temp_type = new \App\Model\Common\TemplateType();
633
            $type = $temp_type->where('id', $type_id)->first()->name;
634
        }
635
        //dd($type);
636
        $templateController = new \App\Http\Controllers\Common\TemplateController();
637
        $mail = $templateController->mailing($from, $to, $data, $subject, $replace, $type);
638
639
        return $mail;
640
    }
641
}
642