|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Common; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use App\Http\Controllers\Controller; |
|
7
|
|
|
use App\Model\Payment\TaxProductRelation; |
|
8
|
|
|
use App\Model\Payment\Tax; |
|
9
|
|
|
use App\Model\Product\Product; |
|
10
|
|
|
use Bugsnag; |
|
11
|
|
|
|
|
12
|
|
|
class ExtendedBaseTemplateController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
public function popup($title, $body, $width = '897', $name = '', $modelid = '', $class = 'null', $trigger = false) |
|
15
|
|
|
{ |
|
16
|
|
|
try { |
|
17
|
|
|
if ($modelid == '') { |
|
18
|
|
|
$modelid = $title; |
|
19
|
|
|
} |
|
20
|
|
|
if ($trigger == true) { |
|
21
|
|
|
$trigger = "<a href=# class=$class data-toggle='modal' data-target=#edit".$modelid.'>'.$name.'</a>'; |
|
22
|
|
|
} else { |
|
23
|
|
|
$trigger = ''; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
return $trigger." |
|
27
|
|
|
<div class='modal fade' id=edit".$modelid."> |
|
28
|
|
|
<div class='modal-dialog' style='width: ".$width."px;'> |
|
29
|
|
|
<div class='modal-content'> |
|
30
|
|
|
<div class='modal-header'> |
|
31
|
|
|
<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>×</span></button> |
|
32
|
|
|
<h4 class='modal-title'>".$title."</h4> |
|
33
|
|
|
</div> |
|
34
|
|
|
<div class='modal-body'> |
|
35
|
|
|
".$body." |
|
36
|
|
|
</div> |
|
37
|
|
|
<div class='modal-footer'> |
|
38
|
|
|
<button type=button id=close class='btn btn-default pull-left' data-dismiss=modal>Close</button> |
|
39
|
|
|
<input type=submit class='btn btn-primary' value="./* @scrutinizer ignore-type */ |
|
40
|
|
|
\Lang::get('message.save').'> |
|
41
|
|
|
</div> |
|
42
|
|
|
'.\Form::close().' |
|
43
|
|
|
</div> |
|
44
|
|
|
</div> |
|
45
|
|
|
</div>'; |
|
46
|
|
|
} catch (\Exception $ex) { |
|
47
|
|
|
Bugsnag::notifyException($ex); |
|
48
|
|
|
|
|
49
|
|
|
throw new \Exception($ex->getMessage()); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
public function calculateTotalcart($rate, $price, $cart, $shop) |
|
55
|
|
|
{ |
|
56
|
|
|
if (($cart == 1 && $shop == 1) || ($cart == 1 && $shop == 0) || ($cart == 0 && $shop == 1)) { |
|
57
|
|
|
$tax_amount = $price * ($rate / 100); |
|
58
|
|
|
$total = $price + $tax_amount; |
|
59
|
|
|
|
|
60
|
|
|
return $total; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $price; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function calculateSub($rate, $price, $cart, $shop) |
|
67
|
|
|
{ |
|
68
|
|
|
if (($cart == 1 && $shop == 1) || ($cart == 1 && $shop == 0) || ($cart == 0 && $shop == 1)) { |
|
69
|
|
|
$total = $price / (($rate / 100) + 1); |
|
70
|
|
|
|
|
71
|
|
|
return $total; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $price; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function checkTax($productid, $price, $cart = 0, $cart1 = 0, $shop = 0) |
|
78
|
|
|
{ |
|
79
|
|
|
try { |
|
80
|
|
|
$product = Product::findOrFail($productid); |
|
81
|
|
|
$controller = new \App\Http\Controllers\Front\CartController(); |
|
82
|
|
|
|
|
83
|
|
|
$currency = $controller->currency(); |
|
84
|
|
|
$tax_relation = TaxProductRelation::where('product_id', $productid)->first(); |
|
85
|
|
|
if (!$tax_relation) { |
|
86
|
|
|
return $this->withoutTaxRelation($productid, $currency); |
|
87
|
|
|
} |
|
88
|
|
|
$taxes = Tax::where('tax_classes_id', $tax_relation->tax_class_id)->where('active', 1)->orderBy('created_at', 'asc')->get(); |
|
89
|
|
|
if (count($taxes) == 0) { |
|
90
|
|
|
throw new \Exception('No taxes is avalable'); |
|
91
|
|
|
} |
|
92
|
|
|
$tax_amount = $this->getTaxAmount($cart, $taxes, $price, $cart1, $shop); |
|
93
|
|
|
} catch (\Exception $ex) { |
|
94
|
|
|
Bugsnag::notifyException($ex); |
|
95
|
|
|
throw new \Exception($ex->getMessage()); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|