Completed
Push — development ( db1c54...00218f )
by Ashutosh
10:15
created

CartController::postContactUs()   A

Complexity

Conditions 2
Paths 7

Size

Total Lines 28
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 28
rs 9.584
c 0
b 0
f 0
cc 2
nc 7
nop 1
1
<?php
2
3
namespace App\Http\Controllers\Front;
4
5
use App\Http\Controllers\Common\TemplateController;
6
use App\Http\Controllers\Controller;
7
use App\Model\Common\Setting;
8
use App\Model\Payment\Currency;
9
use App\Model\Payment\Plan;
10
use App\Model\Payment\PlanPrice;
11
use App\Model\Payment\Tax;
12
use App\Model\Payment\TaxByState;
13
use App\Model\Payment\TaxClass;
14
use App\Model\Payment\TaxOption;
15
use App\Model\Payment\TaxProductRelation;
16
use App\Model\Product\Product;
17
use Bugsnag;
18
use Cart;
19
use Exception;
20
use Illuminate\Http\Request;
21
use Session;
22
23
class CartController extends BaseCartController
24
{
25
    public $templateController;
26
    public $product;
27
    public $currency;
28
    public $addons;
29
    public $addonRelation;
30
    public $licence;
31
    public $tax_option;
32
    public $tax_by_state;
33
    public $setting;
34
35
    public function __construct()
36
    {
37
        $templateController = new TemplateController();
38
        $this->templateController = $templateController;
39
40
        $product = new Product();
41
        $this->product = $product;
42
43
        $plan_price = new PlanPrice();
44
        $this->$plan_price = $plan_price;
45
46
        $currency = new Currency();
47
        $this->currency = $currency;
48
49
        $tax = new Tax();
50
        $this->tax = $tax;
51
52
        $setting = new Setting();
53
        $this->setting = $setting;
54
55
        $tax_option = new TaxOption();
56
        $this->tax_option = $tax_option;
57
58
        $tax_by_state = new TaxByState();
59
        $this->tax_by_state = new $tax_by_state();
60
61
        // $this->middleware('Inatall');
62
        // $this->middleware('admin');
63
    }
64
65
    public function productList(Request $request)
66
    {
67
        try {
68
            $cont = new \App\Http\Controllers\Front\GetPageTemplateController();
69
            $location = $cont->getLocation();
70
        } catch (\Exception $ex) {
71
            $location = false;
72
            $error = $ex->getMessage();
73
        }
74
75
        $country = \App\Http\Controllers\Front\CartController::findCountryByGeoip($location['countryCode']);
76
        $states = \App\Http\Controllers\Front\CartController::findStateByRegionId($location['countryCode']);
77
        $states = \App\Model\Common\State::pluck('state_subdivision_name', 'state_subdivision_code')->toArray();
78
        $state_code = $location['countryCode'].'-'.$location['region'];
79
        $state = \App\Http\Controllers\Front\CartController::getStateByCode($state_code);
80
        $mobile_code = \App\Http\Controllers\Front\CartController::getMobileCodeByIso($location['countryCode']);
81
        $currency = $cont->getCurrency($location);
82
       
83
        \Session::put('currency', $currency);
84
        if (!\Session::has('currency')) {
85
            \Session::put('currency', 'INR');
86
           }
87
88
        try {
89
            $page_controller = new PageController();
90
            return $page_controller->cart();
91
        } catch (\Exception $ex) {
92
            return redirect()->back()->with('fails', $ex->getMessage());
93
        }
94
    }
95
96
    public function cart(Request $request)
97
    {
98
        try {
99
            $plan = '';
100
            if ($request->has('subscription')) {
101
                $plan = $request->get('subscription');
102
                Session::put('plan', $plan);
103
            }
104
            $id = $request->input('id');
105
106
            if (!array_key_exists($id, Cart::getContent())) {
107
                $items = $this->addProduct($id);
108
                Cart::add($items);
109
            }
110
111
            return redirect('show/cart');
112
        } catch (\Exception $ex) {
113
             return redirect()->back()->with('fails', $ex->getMessage());
114
        }
115
    }
116
117
    public function showCart()
118
    {
119
        try {
120
            $cartCollection = [];
121
            $items = (\Session::get('items'));
122
123
            $currency = 'INR';
124
            $cart_currency = 'INR';
125
            $attributes = [];
126
            $cartCollection = $this->getCartCollection($items);
127
            foreach ($cartCollection as $item) {
128
                $attributes[] = $item->attributes;
129
                $cart_currency = $attributes[0]['currency'];
130
                $currency = $attributes[0]['currency'];
131
                if (\Auth::user()) {
132
                    $cart_currency = $attributes[0]['currency'];
133
                    $user_currency = \Auth::user()->currency;
134
                    $user_country = \Auth::user()->country;
135
                    $user_state = \Auth::user()->state;
136
                    $currency = 'INR';
137
                    if ($user_currency == 1 || $user_currency == 'USD') {
138
                        $currency = 'USD';
139
                    }
140
                    if ($cart_currency != $currency) {
141
                        $id = $item->id;
142
                        Cart::remove($id);
143
                        $items = $this->addProduct($id);
144
145
                        Cart::add($items);
146
                    }
147
                }
148
            }
149
150
            return view('themes.default1.front.cart', compact('cartCollection', 'attributes'));
151
        } catch (\Exception $ex) {
152
          return redirect()->back()->with('fails', $ex->getMessage());
153
        }
154
    }
155
156
    public function checkTax($productid)
157
    {
158
        try {
159
            $tax_condition = array();
160
            $tax_attribute = array();
161
            $tax_attribute[0] = ['name' => 'null', 'rate' => 0, 'tax_enable' =>0];
162
            $taxCondition[0] = new \Darryldecode\Cart\CartCondition([
0 ignored issues
show
Comprehensibility Best Practice introduced by
$taxCondition was never initialized. Although not strictly required by PHP, it is generally a good practice to add $taxCondition = array(); before regardless.
Loading history...
163
                'name'   => 'null',
164
                'type'   => 'tax',
165
                'target' => 'item',
166
                'value'  => '0%',
167
            ]);
168
            $cont = new \App\Http\Controllers\Front\GetPageTemplateController();
169
            $location = $cont->getLocation();
170
           
171
            $country = \App\Http\Controllers\Front\CartController::findCountryByGeoip($location['countryCode']);
172
            $states = \App\Http\Controllers\Front\CartController::findStateByRegionId($location['countryCode']);
173
            $states = \App\Model\Common\State::pluck('state_subdivision_name', 'state_subdivision_code')->toArray();
174
            $state_code = $location['countryCode'].'-'.$location['region'];
175
            $state = \App\Http\Controllers\Front\CartController::getStateByCode($state_code);
176
            $mobile_code = \App\Http\Controllers\Front\CartController::getMobileCodeByIso($location['countryCode']);
177
            $country_iso = $location['countryCode'];
178
            $geoip_country = '';
179
            $geoip_state = '';
180
            if (\Auth::user()) {
181
                $geoip_country = \Auth::user()->country;
182
                $geoip_state = \Auth::user()->state;
183
            }
184
            if ($geoip_country == '') {
185
                $geoip_country = \App\Http\Controllers\Front\CartController::findCountryByGeoip($country_iso);
186
            }
187
            $geoip_state_array = \App\Http\Controllers\Front\CartController::getStateByCode($state_code);
188
            if ($geoip_state == '') {
189
                if (array_key_exists('id', $geoip_state_array)) {
190
                    $geoip_state = $geoip_state_array['id'];
191
                }
192
            }
193
194
            if ($this->tax_option->findOrFail(1)->inclusive == 0) {
195
                $tax_rule = $this->tax_option->findOrFail(1);
196
                $shop = $tax_rule->shop_inclusive;
197
                $cart = $tax_rule->cart_inclusive;
198
                $tax_enable = $this->tax_option->findOrFail(1)->tax_enable;
199
                //Check the state of user for calculating GST(cgst,igst,utgst,sgst)
200
                $user_state = TaxByState::where('state_code', $geoip_state)->first();
201
                $origin_state = $this->setting->first()->state; //Get the State of origin
202
                $tax_class_id = TaxProductRelation::where('product_id', $productid)->pluck('tax_class_id')->toArray();
203
204
                if ($tax_class_id) {//If the product is allowed for tax (Check in tax_product relation table)
205
                   if ($tax_enable == 1) {//If GST is Enabled
206
207
                             $state_code = '';
208
                       $c_gst = '';
209
                       $s_gst = '';
210
                       $i_gst = '';
211
                       $ut_gst = '';
212
                       $value = '';
213
                       $rate = '';
214
                       $status = 1;
215
216
                       if ($user_state != '') {//Get the CGST,SGST,IGST,STATE_CODE of the user
217
218
                           $c_gst = $user_state->c_gst;
219
                           $s_gst = $user_state->s_gst;
220
                           $i_gst = $user_state->i_gst;
221
                           $ut_gst = $user_state->ut_gst;
222
                           $state_code = $user_state->state_code;
223
                           if ($state_code == $origin_state) {//If user and origin state are same
224
225
                               $taxClassId = TaxClass::where('name', 'Intra State GST')->pluck('id')->toArray(); //Get the class Id  of state
226
                               if ($taxClassId) {
227
                                   $taxes = $this->getTaxByPriority($taxClassId);
228
                                   $value = $this->getValueForSameState($productid, $c_gst, $s_gst, $taxClassId, $taxes);
229
230
                                   if ($value == '') {
231
                                       $status = 0;
232
                                   }
233
                               } else {
234
                                   $taxes = [0];
235
                               }
236
                           } elseif ($state_code != $origin_state && $ut_gst == 'NULL') {//If user is from other state
237
238
                               $taxClassId = TaxClass::where('name', 'Inter State GST')->pluck('id')->toArray(); //Get the class Id  of state
239
                               if ($taxClassId) {
240
                                   $taxes = $this->getTaxByPriority($taxClassId);
241
                                   $value = $this->getValueForOtherState($productid, $i_gst, $taxClassId, $taxes);
242
                                   if ($value == '') {
243
                                       $status = 0;
244
                                   }
245
                               } else {
246
                                   $taxes = [0];
247
                               }
248
                           } elseif ($state_code != $origin_state && $ut_gst != 'NULL') {//if user from Union Territory
249
                        $taxClassId = TaxClass::where('name', 'Union Territory GST')->pluck('id')->toArray(); //Get the class Id  of state
250
                        if ($taxClassId) {
251
                            $taxes = $this->getTaxByPriority($taxClassId);
252
                            $value = $this->getValueForUnionTerritory($productid, $c_gst, $ut_gst, $taxClassId, $taxes);
253
                            if ($value == '') {
254
                                $status = 0;
255
                            }
256
                        } else {
257
                            $taxes = [0];
258
                        }
259
                           }
260
                       } else {//If user from other Country
261
                           $taxClassId = Tax::where('state', $geoip_state)->orWhere('country', $geoip_country)->pluck('tax_classes_id')->first();
262
263
                           if ($taxClassId) { //if state equals the user State or country equals user country
264
265
                               $taxes = $this->getTaxByPriority($taxClassId);
266
                               $value = $this->getValueForOthers($productid, $taxClassId, $taxes);
267
                               if ($value == '') {
268
                                   $status = 0;
269
                               }
270
                               $rate = $value;
271
                           } else {//if Tax is selected for Any Country Any State
272
                               $taxClassId = Tax::where('country', '')->where('state', 'Any State')->pluck('tax_classes_id')->first();
273
                               if ($taxClassId) {
274
                                   $taxes = $this->getTaxByPriority($taxClassId);
275
                                   $value = $this->getValueForOthers($productid, $taxClassId, $taxes);
276
                                   if ($value == '') {
277
                                       $status = 0;
278
                                   }
279
                                   $rate = $value;
280
                               } else {
281
                                   $taxes = [0];
282
                               }
283
                           }
284
                       }
285
                       foreach ($taxes as $key => $tax) {
286
287
                                    //All the da a attribute that is sent to the checkout Page if tax_compound=0
288
                           if ($taxes[0]) {
289
                               $tax_attribute[$key] = ['name' => $tax->name, 'c_gst'=>$c_gst, 's_gst'=>$s_gst, 'i_gst'=>$i_gst, 'ut_gst'=>$ut_gst, 'state'=>$state_code, 'origin_state'=>$origin_state, 'tax_enable'=>$tax_enable, 'rate'=>$value, 'status'=>$status];
290
291
                               $taxCondition[0] = new \Darryldecode\Cart\CartCondition([
292
293
                                            'name'   => 'no compound',
294
                                            'type'   => 'tax',
295
                                            'target' => 'item',
296
                                            'value'  => $value,
297
                                          ]);
298
                           } else {
299
                               $tax_attribute[0] = ['name' => 'null', 'rate' => 0, 'tax_enable' =>0];
300
                               $taxCondition[0] = new \Darryldecode\Cart\CartCondition([
301
                                           'name'   => 'null',
302
                                           'type'   => 'tax',
303
                                           'target' => 'item',
304
                                           'value'  => '0%',
305
                                         ]);
306
                           }
307
                       }
308
                   } elseif ($tax_enable == 0) {//If Tax enable is 0
309
                       $status = 1;
310
                       if ($this->tax_option->findOrFail(1)->tax_enable == 0) {
311
                           $taxClassId = Tax::where('country', '')->where('state', 'Any State')->pluck('tax_classes_id')->first(); //In case of India when other tax is available and tax is not enabled
312
                           if ($taxClassId) {
313
                               $taxes = $this->getTaxByPriority($taxClassId);
314
                               $value = $this->getValueForOthers($productid, $taxClassId, $taxes);
315
                               if ($value == 0) {
316
                                   $status = 0;
317
                               }
318
                               $rate = $value;
319
                               foreach ($taxes as $key => $tax) {
320
                                   $tax_attribute[$key] = ['name' => $tax->name, 'rate' => $value, 'tax_enable'=>0, 'status' => $status];
321
                                   $taxCondition[$key] = new \Darryldecode\Cart\CartCondition([
322
323
                                            'name'   => $tax->name,
324
                                            'type'   => 'tax',
325
                                            'target' => 'item',
326
                                            'value'  => $value,
327
                                        ]);
328
                               }
329
                           } else {//In case of other country when tax is available and tax is not enabled(Applicable when Global Tax class for any country and state is not there)
330
                               $taxClassId = Tax::where('state', $geoip_state)->orWhere('country', $geoip_country)->pluck('tax_classes_id')->first();
331
                               if ($taxClassId) { //if state equals the user State
332
                                   $taxes = $this->getTaxByPriority($taxClassId);
333
                                   $value = $this->getValueForOthers($productid, $taxClassId, $taxes);
334
                                   if ($value == '') {
335
                                       $status = 0;
336
                                   }
337
                                   $rate = $value;
338
                               }
339
                               foreach ($taxes as $key => $tax) {
340
                                   $tax_attribute[$key] = ['name' => $tax->name, 'rate' => $value, 'tax_enable'=>0, 'status' => $status];
341
                                   $taxCondition[$key] = new \Darryldecode\Cart\CartCondition([
342
343
                                            'name'   => $tax->name,
344
                                            'type'   => 'tax',
345
                                            'target' => 'item',
346
                                            'value'  => $value,
347
                                        ]);
348
                               }
349
                           }
350
                       }
351
                   }
352
                } else {
353
                    $tax_attribute[0] = ['name' => 'null', 'rate' => 0, 'tax_enable' =>0];
354
                    $taxCondition[0] = new \Darryldecode\Cart\CartCondition([
355
                'name'   => 'null',
356
                'type'   => 'tax',
357
                'target' => 'item',
358
                'value'  => '0%',
359
            ]);
360
                }
361
            }
362
363
            $currency_attribute = $this->addCurrencyAttributes($productid);
364
         return ['conditions' => $taxCondition, 'attributes' => ['tax' => $tax_attribute, 'currency' => $currency_attribute]];
365
        } catch (\Exception $ex) {
366
            Bugsnag::notifyException($ex);
367
            throw new \Exception('Can not check the tax');
368
        }
369
    }
370
371
     /**
372
     * @return type
373
     */
374
    public function clearCart()
375
    {
376
        foreach (Cart::getContent() as $item) {
377
            if (\Session::has('domain'.$item->id)) {
378
                \Session::forget('domain'.$item->id);
379
            }
380
        }
381
        $this->removePlanSession();
382
        $renew_control = new \App\Http\Controllers\Order\RenewController();
383
        $renew_control->removeSession();
384
        Cart::clear();
385
386
        return redirect('show/cart');
387
    }
388
389
390
391
    /**
392
     * @return type
393
     */
394
    public function addCouponUpdate()
395
    {
396
        try {
397
            $code = \Input::get('coupon');
398
            $cart = Cart::getContent();
399
            $id = '';
400
            foreach ($cart as $item) {
401
                $id = $item->id;
402
            }
403
            $promo_controller = new \App\Http\Controllers\Payment\PromotionController();
404
            $result = $promo_controller->checkCode($code, $id);
405
            if ($result == 'success') {
406
                return redirect()->back()->with('success', \Lang::get('message.updated-successfully'));
407
            }
408
409
            return redirect()->back();
410
        } catch (\Exception $ex) {
411
            Bugsnag::notifyException($ex);
412
413
            return redirect()->back()->with('fails', $ex->getMessage());
414
        }
415
    }
416
417
    
418
    /**
419
     * @param type $price
420
     *
421
     * @throws \Exception
422
     *
423
     * @return type
424
     */
425
    public static function rounding($price)
426
    {
427
        try {
428
            $tax_rule = new \App\Model\Payment\TaxOption();
429
            $rule = $tax_rule->findOrFail(1);
430
            $rounding = $rule->rounding;
431
            if ($rounding == 1) {
432
                // $price = str_replace(',', '', $price);
433
434
                return round($price);
435
            } else {
436
                return $price;
437
            }
438
        } catch (\Exception $ex) {
439
            Bugsnag::notifyException($ex);
440
      }
441
    }
442
443
    /**
444
     * @return type
445
     */
446
    public function contactUs()
447
    {
448
        try {
449
            return view('themes.default1.front.contact');
450
        } catch (\Exception $ex) {
451
            return redirect()->back()->with('fails', $ex->getMessage());
452
        }
453
    }
454
455
456
   
457
458
    /**
459
     * @param type $code
460
     *
461
     * @throws \Exception
462
     *
463
     * @return type
464
     */
465
    public static function getCountryByCode($code)
466
    {
467
        try {
468
            $country = \App\Model\Common\Country::where('country_code_char2', $code)->first();
469
            if ($country) {
470
                return $country->country_name;
471
            }
472
        } catch (\Exception $ex) {
473
            throw new \Exception($ex->getMessage());
474
        }
475
    }
476
477
478
    /**
479
     * @param type $name
480
     *
481
     * @throws \Exception
482
     *
483
     * @return string
484
     */
485
    public static function getTimezoneByName($name)
486
    {
487
        try {
488
            if ($name) {
489
                $timezone = \App\Model\Common\Timezone::where('name', $name)->first();
490
                if ($timezone) {
491
                    $timezone = $timezone->id;
492
                } else {
493
                    $timezone = '114';
494
                }
495
            } else {
496
                $timezone = '114';
497
            }
498
499
            return $timezone;
500
        } catch (\Exception $ex) {
501
            throw new \Exception($ex->getMessage());
502
        }
503
    }
504
505
    /**
506
     * @param type $code
507
     *
508
     * @throws \Exception
509
     *
510
     * @return type
511
     */
512
    public static function getStateByCode($code)
513
    {
514
        try {
515
            $result = ['id' => '', 'name' => ''];
516
            $subregion = \App\Model\Common\State::where('state_subdivision_code', $code)->first();
517
            if ($subregion) {
518
                $result = ['id' => $subregion->state_subdivision_code, 'name' => $subregion->state_subdivision_name];
519
                //return ['id' => $subregion->state_subdivision_code, 'name' => $subregion->state_subdivision_name];
520
            }
521
522
            return $result;
523
        } catch (\Exception $ex) {
524
            throw new \Exception($ex->getMessage());
525
        }
526
    }
527
528
    /**
529
     * @param type $id
530
     *
531
     * @throws \Exception
532
     *
533
     * @return type
534
     */
535
    public static function getStateNameById($id)
536
    {
537
        try {
538
            $name = '';
539
            $subregion = \App\Model\Common\State::where('state_subdivision_id', $id)->first();
540
            if ($subregion) {
541
                $name = $subregion->state_subdivision_name;
542
            }
543
544
            return $name;
545
        } catch (\Exception $ex) {
546
            throw new \Exception($ex->getMessage());
547
        }
548
    }
549
550
    /**
551
     * @param type $productid
552
     * @param type $price
553
     * @param type $cart
554
     * @param type $cart1
555
     * @param type $shop
556
     *
557
     * @return type
558
     */
559
    public static function calculateTax($productid, $price, $cart = 1, $cart1 = 0, $shop = 0)
560
    {
561
        try {
562
            $template_controller = new TemplateController();
563
            $result = $template_controller->checkTax($productid, $price, $cart, $cart1, $shop);
564
565
            $result = self::rounding($result);
566
567
            return $result;
568
        } catch (\Exception $ex) {
569
            return redirect()->back()->with('fails', $ex->getMessage());
570
        }
571
    }
572
573
    /**
574
     * @param type $rate
575
     * @param type $price
576
     *
577
     * @return type
578
     */
579
    public static function taxValue($rate, $price)
580
    {
581
        try {
582
            $rate = str_replace('%', '', $rate);
583
            $tax = $price * ($rate / 100);
584
            $result = $tax;
585
586
            $result = self::rounding($result);
587
588
            return $result;
589
        } catch (\Exception $ex) {
590
            return redirect()->back()->with('fails', $ex->getMessage());
591
        }
592
    }
593
594
595
596
    /**
597
     * @param type $iso
598
     *
599
     * @throws \Exception
600
     *
601
     * @return type
602
     */
603
    public static function getMobileCodeByIso($iso)
604
    {
605
        try {
606
            $code = '';
607
            if ($iso != '') {
608
                $mobile = \DB::table('mobile')->where('iso', $iso)->first();
609
                if ($mobile) {
610
                    $code = $mobile->phonecode;
611
                }
612
            }
613
614
            return $code;
615
        } catch (\Exception $ex) {
616
            throw new \Exception($ex->getMessage());
617
        }
618
    }
619
620
    /**
621
     * @param type $productid
622
     * @param type $userid
623
     * @param type $planid
624
     *
625
     * @return type
626
     */
627
    public function cost($productid, $userid = '', $planid = '')
628
    {
629
        try {
630
            $cost = $this->planCost($productid, $userid, $planid);
631
            if ($cost == 0) {
632
                $cost = $this->productCost($productid, $userid);
633
            }
634
635
            return self::rounding($cost);
636
        } catch (\Exception $ex) {
637
            // throw new \Exception($ex->getMessage());
638
        }
639
    }
640
641
    /**
642
     * @param type $productid
643
     * @param type $userid
644
     *
645
     * @throws \Exception
646
     *
647
     * @return type
648
     */
649
    public function productCost($productid, $userid = '')
650
    {
651
        try {
652
            $sales = 0;
653
            $currency = $this->currency($userid);
654
            $product = $this->product->find($productid);
655
656
            // $price = $product->price()->where('currency', $currency)->first();
657
            $plan_id = Plan::where('product', $productid)->pluck('id')->first();
658
            $price = PlanPrice::where('plan_id', $plan_id)->where('currency', $currency)->pluck('add_price')->first();
659
            if ($price) {
660
                $sales = $price;
661
                // if ($sales == 0) {
662
                //     $sales = $price->price;
663
                // }
664
            }
665
            //}
666
667
            return $sales;
668
        } catch (\Exception $ex) {
669
            throw new \Exception($ex->getMessage());
670
        }
671
    }
672
673
    /**
674
     * @param type $productid
675
     * @param type $userid
676
     * @param type $planid
677
     *
678
     * @throws \Exception
679
     *
680
     * @return type
681
     */
682
    public function planCost($productid, $userid, $planid = '')
683
    {
684
        try {
685
            $cost = 0;
686
            $subscription = $this->allowSubscription($productid);
687
            if ($this->checkPlanSession() === true) {
688
                $planid = Session::get('plan');
689
            }
690
691
            if ($subscription === true) {
692
                $plan = new \App\Model\Payment\Plan();
693
                $plan = $plan->where('id', $planid)->where('product', $productid)->first();
694
                $items = (\Session::get('items'));
695
696
                if ($plan) {
697
                    $currency = $this->currency($userid);
698
                    $price = $plan->planPrice()
699
                                    ->where('currency', $currency)
700
                                    ->first()
701
                            ->add_price;
702
                    $days = $plan->days;
703
                    $months = $days / 30 / 12;
704
                    if ($items != null) {
705
                        $cost = $items[$productid]['price'];
706
                    } else {
707
                        $cost = round($months) * $price;
708
                    }
709
                }
710
            }
711
712
            return $cost;
713
        } catch (\Exception $ex) {
714
            throw new \Exception($ex->getMessage());
715
        }
716
    }
717
718
    /**
719
     * @throws \Exception
720
     */
721
    public function removePlanSession()
722
    {
723
        try {
724
            if (Session::has('plan')) {
725
                Session::forget('plan');
726
            }
727
        } catch (\Exception $ex) {
728
            throw new \Exception($ex->getMessage());
729
        }
730
    }
731
732
    /**
733
     * @throws \Exception
734
     *
735
     * @return bool
736
     */
737
    public function checkPlanSession()
738
    {
739
        try {
740
            if (Session::has('plan')) {
741
                return true;
742
            }
743
744
            return false;
745
        } catch (\Exception $ex) {
746
            throw new \Exception($ex->getMessage());
747
        }
748
    }
749
750
    /**
751
     * @throws \Exception
752
     *
753
     * @return bool
754
     */
755
    public function checkCurrencySession()
756
    {
757
        try {
758
            if (Session::has('currency')) {
759
                return true;
760
            }
761
762
            return false;
763
        } catch (\Exception $ex) {
764
            throw new \Exception($ex->getMessage());
765
        }
766
    }
767
768
769
}
770