| Total Complexity | 181 |
| Total Lines | 1333 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like CartController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CartController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 22 | class CartController extends BaseCartController |
||
| 23 | { |
||
| 24 | public $templateController; |
||
| 25 | public $product; |
||
| 26 | public $currency; |
||
| 27 | public $addons; |
||
| 28 | public $addonRelation; |
||
| 29 | public $licence; |
||
| 30 | public $tax_option; |
||
| 31 | public $tax_by_state; |
||
| 32 | public $setting; |
||
| 33 | |||
| 34 | public function __construct() |
||
| 59 | |||
| 60 | // $this->middleware('Inatall'); |
||
| 61 | // $this->middleware('admin'); |
||
| 62 | } |
||
| 63 | |||
| 64 | public function productList(Request $request) |
||
| 65 | { |
||
| 66 | try { |
||
| 67 | $cont = new \App\Http\Controllers\Front\GetPageTemplateController(); |
||
| 68 | $location = $cont->getLocation(); |
||
| 69 | } catch (\Exception $ex) { |
||
| 70 | $location = false; |
||
| 71 | $error = $ex->getMessage(); |
||
| 72 | } |
||
| 73 | |||
| 74 | $country = \App\Http\Controllers\Front\CartController::findCountryByGeoip($location['countryCode']); |
||
|
1 ignored issue
–
show
|
|||
| 75 | $states = \App\Http\Controllers\Front\CartController::findStateByRegionId($location['countryCode']); |
||
| 76 | $states = \App\Model\Common\State::pluck('state_subdivision_name', 'state_subdivision_code')->toArray(); |
||
| 77 | $state_code = $location['countryCode'].'-'.$location['region']; |
||
| 78 | $state = \App\Http\Controllers\Front\CartController::getStateByCode($state_code); |
||
| 79 | $mobile_code = \App\Http\Controllers\Front\CartController::getMobileCodeByIso($location['countryCode']); |
||
| 80 | $currency = $cont->getCurrency($location); |
||
| 81 | |||
| 82 | \Session::put('currency', $currency); |
||
| 83 | if (!\Session::has('currency')) { |
||
| 84 | \Session::put('currency', 'INR'); |
||
| 85 | } |
||
| 86 | |||
| 87 | try { |
||
| 88 | $page_controller = new PageController(); |
||
| 89 | |||
| 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 | |||
| 101 | if ($request->has('subscription')) { |
||
| 102 | $plan = $request->get('subscription'); |
||
| 103 | |||
| 104 | Session::put('plan', $plan); |
||
| 105 | } |
||
| 106 | $id = $request->input('id'); |
||
| 107 | |||
| 108 | if (!array_key_exists($id, Cart::getContent())) { |
||
| 109 | $items = $this->addProduct($id); |
||
| 110 | |||
| 111 | Cart::add($items); |
||
| 112 | } |
||
| 113 | |||
| 114 | return redirect('show/cart'); |
||
| 115 | } catch (\Exception $ex) { |
||
| 116 | // dd($ex); |
||
| 117 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | public function showCart() |
||
| 122 | { |
||
| 123 | try { |
||
| 124 | $currency = 'INR'; |
||
| 125 | $cart_currency = 'INR'; |
||
| 126 | $attributes = []; |
||
| 127 | $cartCollection = Cart::getContent(); |
||
| 128 | foreach ($cartCollection as $item) { |
||
| 129 | $attributes[] = $item->attributes; |
||
| 130 | $cart_currency = $attributes[0]['currency']; |
||
| 131 | $currency = $attributes[0]['currency']; |
||
| 132 | if (\Auth::user()) { |
||
| 133 | $cart_currency = $attributes[0]['currency']; |
||
| 134 | $user_currency = \Auth::user()->currency; |
||
| 135 | $user_country = \Auth::user()->country; |
||
| 136 | $user_state = \Auth::user()->state; |
||
| 137 | $currency = 'INR'; |
||
| 138 | if ($user_currency == 1 || $user_currency == 'USD') { |
||
| 139 | $currency = 'USD'; |
||
| 140 | } |
||
| 141 | if ($cart_currency != $currency) { |
||
| 142 | $id = $item->id; |
||
| 143 | Cart::remove($id); |
||
| 144 | $items = $this->addProduct($id); |
||
| 145 | |||
| 146 | Cart::add($items); |
||
| 147 | // |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 | // if ($cart_currency != $currency) { |
||
| 152 | // return redirect('show/cart'); |
||
| 153 | // } |
||
| 154 | //dd(Cart::getContent()); |
||
| 155 | |||
| 156 | return view('themes.default1.front.cart', compact('cartCollection', 'attributes')); |
||
| 157 | } catch (\Exception $ex) { |
||
| 158 | //dd($ex); |
||
| 159 | |||
| 160 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | |||
| 165 | public function checkTax($productid,$user_state='',$user_country='') |
||
| 166 | |||
| 167 | { |
||
| 168 | try { |
||
| 169 | $tax_condition = []; |
||
| 170 | $tax_attribute = []; |
||
| 171 | $tax_attribute[0] = ['name' => 'null', 'rate' => 0, 'tax_enable' =>0]; |
||
| 172 | $taxCondition[0] = new \Darryldecode\Cart\CartCondition([ |
||
| 173 | 'name' => 'null', |
||
| 174 | 'type' => 'tax', |
||
| 175 | 'target' => 'item', |
||
| 176 | 'value' => '0%', |
||
| 177 | ]); |
||
| 178 | $cont = new \App\Http\Controllers\Front\GetPageTemplateController(); |
||
| 179 | $location = $cont->getLocation(); |
||
| 180 | |||
| 181 | $country = $this->findCountryByGeoip($location['countryCode']); |
||
| 182 | $states = $this->findStateByRegionId($location['countryCode']); |
||
| 183 | $states = \App\Model\Common\State::pluck('state_subdivision_name', 'state_subdivision_code')->toArray(); |
||
| 184 | $state_code = $location['countryCode'].'-'.$location['region']; |
||
| 185 | $state = $this->getStateByCode($state_code); |
||
| 186 | $mobile_code = $this->getMobileCodeByIso($location['countryCode']); |
||
| 187 | $country_iso = $location['countryCode']; |
||
| 188 | |||
| 189 | $geoip_state = $this->getGeoipState($state_code,$user_state); |
||
| 190 | $geoip_country = $this->getGeoipCountry($country_iso,$user_country); |
||
| 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 | $c_gst = $user_state->c_gst; |
||
| 218 | $s_gst = $user_state->s_gst; |
||
| 219 | $i_gst = $user_state->i_gst; |
||
| 220 | $ut_gst = $user_state->ut_gst; |
||
| 221 | $state_code = $user_state->state_code; |
||
| 222 | |||
| 223 | if ($state_code == $origin_state) {//If user and origin state are same |
||
| 224 | $rateForSameState = $this->getTaxWhenIndianSameState($user_state, |
||
| 225 | $origin_state, $productid, $c_gst, $s_gst, $state_code, $status); |
||
| 226 | |||
| 227 | $taxes = $rateForSameState['taxes']; |
||
| 228 | $status = $rateForSameState['status']; |
||
| 229 | $value = $rateForSameState['value']; |
||
| 230 | } elseif ($state_code != $origin_state && $ut_gst == 'NULL') {//If user is from other state |
||
| 231 | $rateForOtherState = $this->getTaxWhenIndianOtherState($user_state, |
||
| 232 | $origin_state, $productid, $i_gst, $state_code, $status); |
||
| 233 | $taxes = $rateForOtherState['taxes']; |
||
| 234 | $status = $rateForOtherState['status']; |
||
| 235 | $value = $rateForOtherState['value']; |
||
| 236 | } elseif ($state_code != $origin_state && $ut_gst != 'NULL') {//if user from Union Territory |
||
| 237 | $rateForUnionTerritory = $this->getTaxWhenUnionTerritory($user_state, |
||
| 238 | $origin_state, $productid, $c_gst, $ut_gst, $state_code, $status); |
||
| 239 | $taxes = $rateForUnionTerritory['taxes']; |
||
| 240 | $status = $rateForUnionTerritory['status']; |
||
| 241 | $value = $rateForUnionTerritory['value']; |
||
| 242 | } |
||
| 243 | } else {//If user from other Country |
||
| 244 | $taxClassId = Tax::where('state', $geoip_state) |
||
| 245 | ->orWhere('country', $geoip_country) |
||
| 246 | ->pluck('tax_classes_id')->first(); |
||
| 247 | if ($taxClassId) { //if state equals the user State or country equals user country |
||
| 248 | $taxForSpecificCountry = $this->getTaxForSpecificCountry($taxClassId, |
||
| 249 | $productid, $status); |
||
| 250 | $taxes = $taxForSpecificCountry['taxes']; |
||
| 251 | $status = $taxForSpecificCountry['status']; |
||
| 252 | $value = $taxForSpecificCountry['value']; |
||
| 253 | $rate = $taxForSpecificCountry['value']; |
||
| 254 | } else {//if Tax is selected for Any Country Any State |
||
| 255 | $taxClassId = Tax::where('country', '') |
||
| 256 | ->where('state', 'Any State') |
||
| 257 | ->pluck('tax_classes_id')->first(); |
||
| 258 | if ($taxClassId) { |
||
| 259 | $taxForAnyCountry = $this->getTaxForAnyCountry($taxClassId, $productid, $status); |
||
| 260 | $taxes = $taxForAnyCountry['taxes']; |
||
| 261 | $status = $taxForAnyCountry['status']; |
||
| 262 | $value = $taxForAnyCountry['value']; |
||
| 263 | $rate = $taxForAnyCountry['value']; |
||
| 264 | } else { |
||
| 265 | $taxes = [0]; |
||
| 266 | } |
||
| 267 | } |
||
| 268 | } |
||
| 269 | foreach ($taxes as $key => $tax) { |
||
| 270 | |||
| 271 | //All the da a attribute that is sent to the checkout Page if tax_compound=0 |
||
| 272 | if ($taxes[0]) { |
||
| 273 | $tax_attribute[$key] = ['name' => $tax->name, 'c_gst'=>$c_gst, |
||
| 274 | 's_gst' => $s_gst, 'i_gst'=>$i_gst, 'ut_gst'=>$ut_gst, |
||
| 275 | 'state' => $state_code, 'origin_state'=>$origin_state, |
||
| 276 | 'tax_enable' => $tax_enable, 'rate'=>$value, 'status'=>$status, ]; |
||
| 277 | |||
| 278 | $taxCondition[0] = new \Darryldecode\Cart\CartCondition([ |
||
| 279 | |||
| 280 | 'name' => 'no compound', |
||
| 281 | 'type' => 'tax', |
||
| 282 | 'target' => 'item', |
||
| 283 | 'value' => $value, |
||
| 284 | ]); |
||
| 285 | } else { |
||
| 286 | $tax_attribute[0] = ['name' => 'null', 'rate' => 0, 'tax_enable' =>0]; |
||
| 287 | $taxCondition[0] = new \Darryldecode\Cart\CartCondition([ |
||
| 288 | 'name' => 'null', |
||
| 289 | 'type' => 'tax', |
||
| 290 | 'target' => 'item', |
||
| 291 | 'value' => '0%', |
||
| 292 | ]); |
||
| 293 | } |
||
| 294 | } |
||
| 295 | } elseif ($tax_enable == 0) {//If Tax enable is 0 |
||
| 296 | $status = 1; |
||
| 297 | if ($this->tax_option->findOrFail(1)->tax_enable == 0) { |
||
| 298 | $taxClassId = Tax::where('country', '') |
||
| 299 | ->where('state', 'Any State') |
||
| 300 | ->pluck('tax_classes_id')->first(); //In case of India when other tax is available and tax is not enabled |
||
| 301 | if ($taxClassId) { |
||
| 302 | $taxes = $this->getTaxByPriority($taxClassId); |
||
| 303 | $value = $this->getValueForOthers($productid, $taxClassId, $taxes); |
||
| 304 | if ($value == 0) { |
||
| 305 | $status = 0; |
||
| 306 | } |
||
| 307 | $rate = $value; |
||
| 308 | foreach ($taxes as $key => $tax) { |
||
| 309 | $tax_attribute[$key] = ['name' => $tax->name, 'rate' => $value, 'tax_enable'=>0, 'status' => $status]; |
||
| 310 | $taxCondition[$key] = new \Darryldecode\Cart\CartCondition([ |
||
| 311 | |||
| 312 | 'name' => $tax->name, |
||
| 313 | 'type' => 'tax', |
||
| 314 | 'target' => 'item', |
||
| 315 | 'value' => $value, |
||
| 316 | ]); |
||
| 317 | } |
||
| 318 | } else {//In case of other country |
||
| 319 | //when tax is available and tax is not enabled |
||
| 320 | //(Applicable when Global Tax class for any country and state is not there) |
||
| 321 | $taxClassId = Tax::where('state', $geoip_state) |
||
| 322 | ->orWhere('country', $geoip_country) |
||
| 323 | ->pluck('tax_classes_id')->first(); |
||
| 324 | if ($taxClassId) { //if state equals the user State |
||
| 325 | $taxes = $this->getTaxByPriority($taxClassId); |
||
| 326 | $value = $this->getValueForOthers($productid, $taxClassId, $taxes); |
||
| 327 | if ($value == '') { |
||
| 328 | $status = 0; |
||
| 329 | } |
||
| 330 | $rate = $value; |
||
| 331 | } |
||
| 332 | foreach ($taxes as $key => $tax) { |
||
| 333 | $tax_attribute[$key] = ['name' => $tax->name, 'rate' => $value, 'tax_enable'=>0, 'status' => $status]; |
||
| 334 | $taxCondition[$key] = new \Darryldecode\Cart\CartCondition([ |
||
| 335 | |||
| 336 | 'name' => $tax->name, |
||
| 337 | 'type' => 'tax', |
||
| 338 | 'target' => 'item', |
||
| 339 | 'value' => $value, |
||
| 340 | ]); |
||
| 341 | } |
||
| 342 | } |
||
| 343 | } |
||
| 344 | } |
||
| 345 | } else { |
||
| 346 | $tax_attribute[0] = ['name' => 'null', 'rate' => 0, 'tax_enable' =>0]; |
||
| 347 | $taxCondition[0] = new \Darryldecode\Cart\CartCondition([ |
||
| 348 | 'name' => 'null', |
||
| 349 | 'type' => 'tax', |
||
| 350 | 'target' => 'item', |
||
| 351 | 'value' => '0%', |
||
| 352 | ]); |
||
| 353 | } |
||
| 354 | } |
||
| 355 | |||
| 356 | $currency_attribute = $this->addCurrencyAttributes($productid); |
||
| 357 | |||
| 358 | return ['conditions' => $taxCondition, |
||
| 359 | 'attributes' => ['tax' => $tax_attribute, |
||
| 360 | 'currency' => $currency_attribute, ], ]; |
||
| 361 | } catch (\Exception $ex) { |
||
| 362 | Bugsnag::notifyException($ex); |
||
| 363 | |||
| 364 | throw new \Exception('Can not check the tax'); |
||
| 365 | } |
||
| 366 | } |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Get tax value for Same State. |
||
| 370 | * |
||
| 371 | * @param type $productid |
||
| 372 | * @param type $c_gst |
||
| 373 | * @param type $s_gst |
||
| 374 | * return type |
||
| 375 | */ |
||
| 376 | public function getValueForSameState($productid, $c_gst, $s_gst, $taxClassId, $taxes) |
||
| 377 | { |
||
| 378 | try { |
||
| 379 | $value = ''; |
||
| 380 | $value = $taxes->toArray()[0]['active'] ? |
||
| 381 | |||
| 382 | (TaxProductRelation::where('product_id', $productid)->where('tax_class_id', $taxClassId)->count() ? |
||
| 383 | $c_gst + $s_gst.'%' : 0) : 0; |
||
| 384 | |||
| 385 | return $value; |
||
| 386 | } catch (Exception $ex) { |
||
| 387 | Bugsnag::notifyException($ex); |
||
| 388 | |||
| 389 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
| 390 | } |
||
| 391 | } |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Get tax value for Other States. |
||
| 395 | * |
||
| 396 | * @param type $productid |
||
| 397 | * @param type $i_gst |
||
| 398 | * return type |
||
| 399 | */ |
||
| 400 | public function getValueForOtherState($productid, $i_gst, $taxClassId, $taxes) |
||
| 401 | { |
||
| 402 | $value = ''; |
||
| 403 | $value = $taxes->toArray()[0]['active'] ? //If the Current Class is active |
||
| 404 | (TaxProductRelation::where('product_id', $productid)->where('tax_class_id', $taxClassId)->count() ? |
||
| 405 | $i_gst.'%' : 0) : 0; //IGST |
||
| 406 | |||
| 407 | return $value; |
||
| 408 | } |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Get tax value for Union Territory States. |
||
| 412 | * |
||
| 413 | * @param type $productid |
||
| 414 | * @param type $c_gst |
||
| 415 | * @param type $ut_gst |
||
| 416 | * return type |
||
| 417 | */ |
||
| 418 | public function getValueForUnionTerritory($productid, $c_gst, $ut_gst, $taxClassId, $taxes) |
||
| 419 | { |
||
| 420 | $value = ''; |
||
| 421 | $value = $taxes->toArray()[0]['active'] ? |
||
| 422 | (TaxProductRelation::where('product_id', $productid)->where('tax_class_id', $taxClassId)->count() ? $ut_gst + $c_gst.'%' : 0) : 0; |
||
| 423 | |||
| 424 | return $value; |
||
| 425 | } |
||
| 426 | |||
| 427 | public function otherRate($productid) |
||
| 428 | { |
||
| 429 | // $taxClassOther = TaxClass::where('name', 'Others')->pluck('id')->toArray(); |
||
| 430 | // $otherRate = TaxProductRelation::where('product_id', $productid)->where('tax_class_id', $taxClassOther)->count() ? Tax::where('tax_classes_id', $taxClassOther)->first()->rate : ''; |
||
| 431 | $otherRate = ''; |
||
| 432 | |||
| 433 | return $otherRate; |
||
| 434 | } |
||
| 435 | |||
| 436 | public function getValueForOthers($productid, $taxClassId, $taxes) |
||
| 437 | { |
||
| 438 | $otherRate = 0; |
||
| 439 | $status = $taxes->toArray()[0]['active']; |
||
| 440 | if ($status && (TaxProductRelation::where('product_id', $productid)->where('tax_class_id', $taxClassId)->count() > 0)) { |
||
| 441 | $otherRate = Tax::where('tax_classes_id', $taxClassId)->first()->rate; |
||
| 442 | } |
||
| 443 | |||
| 444 | // $value= $taxes->toArray()[0]['active'] ? |
||
| 445 | // (TaxProductRelation::where('product_id', $productid)->where('tax_class_id', $taxClassId)->count() != 0) ? |
||
| 446 | // $otherRate = Tax::where('tax_classes_id', $taxClassId)->first()->rate; |
||
| 447 | |||
| 448 | $value = $otherRate.'%'; |
||
| 449 | |||
| 450 | return $value; |
||
| 451 | } |
||
| 452 | |||
| 453 | public function checkTaxOld($isTaxApply, $id) |
||
| 454 | { |
||
| 455 | try { |
||
| 456 | $rate1 = 0; |
||
| 457 | $rate2 = 0; |
||
| 458 | $name1 = 'null'; |
||
| 459 | $name2 = 'null'; |
||
| 460 | |||
| 461 | if ($ruleEnabled) { |
||
| 462 | $enabled = $ruleEnabled->status; |
||
| 463 | $type = $ruleEnabled->type; |
||
| 464 | $compound = $ruleEnabled->compound; |
||
| 465 | if ($enabled == 1 && $type == 'exclusive') { |
||
| 466 | if ($isTaxApply == 1) { |
||
| 467 | $tax1 = $this->tax->where('level', 1)->first(); |
||
| 468 | $tax2 = $this->tax->where('level', 2)->first(); |
||
| 469 | if ($tax1) { |
||
| 470 | $name1 = $tax1->name; |
||
| 471 | $rate1 = $tax1->rate; |
||
| 472 | $taxCondition1 = new \Darryldecode\Cart\CartCondition([ |
||
| 473 | 'name' => $name1, |
||
| 474 | 'type' => 'tax', |
||
| 475 | 'target' => 'item', |
||
| 476 | 'value' => $rate1.'%', |
||
| 477 | ]); |
||
| 478 | } else { |
||
| 479 | $taxCondition1 = new \Darryldecode\Cart\CartCondition([ |
||
| 480 | 'name' => $name1, |
||
| 481 | 'type' => 'tax', |
||
| 482 | 'target' => 'item', |
||
| 483 | 'value' => $rate1, |
||
| 484 | ]); |
||
| 485 | } |
||
| 486 | if ($tax2) { |
||
| 487 | $name2 = $tax2->name; |
||
| 488 | $rate2 = $tax2->rate; |
||
| 489 | $taxCondition2 = new \Darryldecode\Cart\CartCondition([ |
||
| 490 | 'name' => $name2, |
||
| 491 | 'type' => 'tax', |
||
| 492 | 'target' => 'item', |
||
| 493 | 'value' => $rate2.'%', |
||
| 494 | ]); |
||
| 495 | } else { |
||
| 496 | $taxCondition2 = new \Darryldecode\Cart\CartCondition([ |
||
| 497 | 'name' => $name2, |
||
| 498 | 'type' => 'tax', |
||
| 499 | 'target' => 'item', |
||
| 500 | 'value' => $rate2, |
||
| 501 | ]); |
||
| 502 | } |
||
| 503 | } else { |
||
| 504 | $taxCondition1 = new \Darryldecode\Cart\CartCondition([ |
||
| 505 | 'name' => $name1, |
||
| 506 | 'type' => 'tax', |
||
| 507 | 'target' => 'item', |
||
| 508 | 'value' => $rate1, |
||
| 509 | ]); |
||
| 510 | $taxCondition2 = new \Darryldecode\Cart\CartCondition([ |
||
| 511 | 'name' => $name2, |
||
| 512 | 'type' => 'tax', |
||
| 513 | 'target' => 'item', |
||
| 514 | 'value' => $rate2, |
||
| 515 | ]); |
||
| 516 | } |
||
| 517 | $currency_attribute = $this->addCurrencyAttributes($id); |
||
| 518 | if ($compound == 1) { |
||
| 519 | return ['conditions' => [$taxCondition1, $taxCondition2], 'attributes' => ['tax' => [['name' => $name1, 'rate' => $rate1], ['name' => $name2, 'rate' => $rate2]], 'currency' => $currency_attribute]]; |
||
| 520 | } else { |
||
| 521 | return ['conditions' => $taxCondition2, 'attributes' => ['tax' => [['name' => $name2, 'rate' => $rate2]], 'currency' => $currency_attribute]]; |
||
| 522 | } |
||
| 523 | } |
||
| 524 | } |
||
| 525 | } catch (\Exception $ex) { |
||
| 526 | dd($ex); |
||
| 527 | |||
| 528 | throw new \Exception('Can not check the tax'); |
||
| 529 | } |
||
| 530 | } |
||
| 531 | |||
| 532 | public function cartRemove(Request $request) |
||
| 533 | { |
||
| 534 | $id = $request->input('id'); |
||
| 535 | Cart::remove($id); |
||
| 536 | |||
| 537 | return 'success'; |
||
| 538 | } |
||
| 539 | |||
| 540 | public function reduseQty(Request $request) |
||
| 541 | { |
||
| 542 | $id = $request->input('id'); |
||
| 543 | Cart::update($id, [ |
||
| 544 | 'quantity' => -1, // so if the current product has a quantity of 4, it will subtract 1 and will result to 3 |
||
| 545 | ]); |
||
| 546 | |||
| 547 | return 'success'; |
||
| 548 | } |
||
| 549 | |||
| 550 | public function updateQty(Request $request) |
||
| 551 | { |
||
| 552 | $id = $request->input('productid'); |
||
| 553 | $qty = $request->input('qty'); |
||
| 554 | Cart::update($id, [ |
||
| 555 | 'quantity' => [ |
||
| 556 | 'relative' => false, |
||
| 557 | 'value' => $qty, |
||
| 558 | ], |
||
| 559 | ]); |
||
| 560 | |||
| 561 | return 'success'; |
||
| 562 | } |
||
| 563 | |||
| 564 | public function addAddons($id) |
||
| 565 | { |
||
| 566 | $addon = $this->addons->where('id', $id)->first(); |
||
| 567 | $isTaxApply = $addon->tax_addon; |
||
| 568 | $taxConditions = $this->CheckTax($isTaxApply); |
||
| 569 | $items = ['id' => 'addon'.$addon->id, 'name' => $addon->name, 'price' => $addon->selling_price, 'quantity' => 1]; |
||
| 570 | $items = array_merge($items, $taxConditions); |
||
| 571 | |||
| 572 | return $items; |
||
| 573 | } |
||
| 574 | |||
| 575 | public function getProductAddons($productId) |
||
| 576 | { |
||
| 577 | $addons = []; |
||
| 578 | if ($this->addonRelation->where('product_id', $productId)->count() > 0) { |
||
| 579 | $addid = $this->addonRelation->where('product_id', $productId)->pluck('addon_id')->toArray(); |
||
| 580 | $addons = $this->addons->whereIn('id', $addid)->get(); |
||
| 581 | } |
||
| 582 | |||
| 583 | return $addons; |
||
| 584 | } |
||
| 585 | |||
| 586 | public function addProduct($id) |
||
| 587 | { |
||
| 588 | try { |
||
| 589 | $qty = 1; |
||
| 590 | |||
| 591 | $currency = $this->currency(); |
||
| 592 | $product = $this->product->where('id', $id)->first(); |
||
| 593 | if ($product) { |
||
| 594 | $actualPrice = $this->cost($product->id); |
||
| 595 | $currency = $this->currency(); |
||
| 596 | $productName = $product->name; |
||
| 597 | $planid = 0; |
||
| 598 | if ($this->checkPlanSession() == true) { |
||
| 599 | $planid = Session::get('plan'); |
||
| 600 | } |
||
| 601 | $isTaxApply = $product->tax_apply; |
||
| 602 | $taxConditions = $this->checkTax($id); |
||
| 603 | |||
| 604 | /* |
||
| 605 | * Check if this product allow multiple qty |
||
| 606 | */ |
||
| 607 | if ($product->multiple_qty == 1) { |
||
| 608 | // Allow |
||
| 609 | } else { |
||
| 610 | $qty = 1; |
||
| 611 | } |
||
| 612 | $items = ['id' => $id, 'name' => $productName, 'price' => $actualPrice, 'quantity' => $qty, 'attributes' => ['currency' => [[$currency]]]]; |
||
| 613 | $items = array_merge($items, $taxConditions); |
||
| 614 | |||
| 615 | return $items; |
||
| 616 | } |
||
| 617 | } catch (\Exception $e) { |
||
| 618 | dd($e); |
||
| 619 | Bugsnag::notifyException($e); |
||
| 620 | } |
||
| 621 | } |
||
| 622 | |||
| 623 | /** |
||
| 624 | * @return type |
||
| 625 | */ |
||
| 626 | public function clearCart() |
||
| 627 | { |
||
| 628 | foreach (Cart::getContent() as $item) { |
||
| 629 | if (\Session::has('domain'.$item->id)) { |
||
| 630 | \Session::forget('domain'.$item->id); |
||
| 631 | } |
||
| 632 | } |
||
| 633 | $this->removePlanSession(); |
||
| 634 | $renew_control = new \App\Http\Controllers\Order\RenewController(); |
||
| 635 | $renew_control->removeSession(); |
||
| 636 | Cart::clear(); |
||
| 637 | |||
| 638 | return redirect('show/cart'); |
||
| 639 | } |
||
| 640 | |||
| 641 | /** |
||
| 642 | * @param type $id |
||
| 643 | * |
||
| 644 | * @throws \Exception |
||
| 645 | * |
||
| 646 | * @return type |
||
| 647 | */ |
||
| 648 | public function licenceCart($id) |
||
| 649 | { |
||
| 650 | try { |
||
| 651 | $licence = $this->licence->where('id', $id)->first(); |
||
| 652 | $isTaxApply = 0; |
||
| 653 | $taxConditions = $this->CheckTax($isTaxApply); |
||
| 654 | $items = ['id' => $licence->id, 'name' => $licence->name, 'price' => $licence->price, 'quantity' => 1, 'attributes' => ['number_of_sla' => $licence->number_of_sla]]; |
||
| 655 | $items = array_merge($items, $taxConditions); |
||
| 656 | Cart::clear(); |
||
| 657 | Cart::add($items); |
||
| 658 | |||
| 659 | return view('themes.default1.front.cart', compact('cartCollection')); |
||
| 660 | } catch (\Exception $ex) { |
||
| 661 | dd($ex); |
||
| 662 | |||
| 663 | throw new \Exception('Problem while adding licence to cart'); |
||
| 664 | } |
||
| 665 | } |
||
| 666 | |||
| 667 | /** |
||
| 668 | * @param type $id |
||
| 669 | * @param type $key |
||
| 670 | * @param type $value |
||
| 671 | */ |
||
| 672 | public function cartUpdate($id, $key, $value) |
||
| 673 | { |
||
| 674 | try { |
||
| 675 | Cart::update( |
||
| 676 | $id, [ |
||
| 677 | $key => $value, // new item name |
||
| 678 | ] |
||
| 679 | ); |
||
| 680 | } catch (\Exception $ex) { |
||
| 681 | } |
||
| 682 | } |
||
| 683 | |||
| 684 | /** |
||
| 685 | * @param type $id |
||
| 686 | * |
||
| 687 | * @return array |
||
| 688 | */ |
||
| 689 | public function addCurrencyAttributes($id) |
||
| 690 | { |
||
| 691 | try { |
||
| 692 | $currency = $this->currency(); |
||
| 693 | $product = $this->product->where('id', $id)->first(); |
||
| 694 | if ($product) { |
||
| 695 | $productCurrency = $this->currency(); |
||
| 696 | $currency = $this->currency->where('code', $productCurrency)->get()->toArray(); |
||
| 697 | } else { |
||
| 698 | $currency = []; |
||
| 699 | } |
||
| 700 | |||
| 701 | return $currency; |
||
| 702 | } catch (\Exception $ex) { |
||
| 703 | } |
||
| 704 | } |
||
| 705 | |||
| 706 | /** |
||
| 707 | * @return type |
||
| 708 | */ |
||
| 709 | public function addCouponUpdate() |
||
| 710 | { |
||
| 711 | try { |
||
| 712 | $code = \Input::get('coupon'); |
||
| 713 | $cart = Cart::getContent(); |
||
| 714 | foreach ($cart as $item) { |
||
| 715 | $id = $item->id; |
||
| 716 | } |
||
| 717 | $promo_controller = new \App\Http\Controllers\Payment\PromotionController(); |
||
| 718 | $result = $promo_controller->checkCode($code, $id); |
||
|
1 ignored issue
–
show
|
|||
| 719 | if ($result == 'success') { |
||
| 720 | return redirect()->back()->with('success', \Lang::get('message.updated-successfully')); |
||
| 721 | } |
||
| 722 | |||
| 723 | return redirect()->back(); |
||
| 724 | } catch (\Exception $ex) { |
||
| 725 | dd($ex); |
||
| 726 | |||
| 727 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
| 728 | } |
||
| 729 | } |
||
| 730 | |||
| 731 | /** |
||
| 732 | * @param type $tax_class_id |
||
| 733 | * |
||
| 734 | * @throws \Exception |
||
| 735 | * |
||
| 736 | * @return type |
||
| 737 | */ |
||
| 738 | public function getTaxByPriority($taxClassId) |
||
| 748 | } |
||
| 749 | } |
||
| 750 | |||
| 751 | /** |
||
| 752 | * @param type $price |
||
| 753 | * |
||
| 754 | * @throws \Exception |
||
| 755 | * |
||
| 756 | * @return type |
||
| 757 | */ |
||
| 758 | public static function rounding($price) |
||
| 759 | { |
||
| 760 | try { |
||
| 761 | $tax_rule = new \App\Model\Payment\TaxOption(); |
||
| 762 | $rule = $tax_rule->findOrFail(1); |
||
| 763 | $rounding = $rule->rounding; |
||
| 764 | if ($rounding == 1) { |
||
| 765 | // $price = str_replace(',', '', $price); |
||
| 766 | |||
| 767 | return round($price); |
||
| 768 | } else { |
||
| 769 | return $price; |
||
| 770 | } |
||
| 771 | } catch (\Exception $ex) { |
||
| 772 | dd($ex); |
||
| 773 | Bugsnag::notifyException($ex); |
||
| 774 | // throw new \Exception('error in get tax priority'); |
||
| 775 | } |
||
| 776 | } |
||
| 777 | |||
| 778 | /** |
||
| 779 | * @return type |
||
| 780 | */ |
||
| 781 | public function contactUs() |
||
| 782 | { |
||
| 783 | try { |
||
| 784 | return view('themes.default1.front.contact'); |
||
| 785 | } catch (\Exception $ex) { |
||
| 786 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
| 787 | } |
||
| 788 | } |
||
| 789 | |||
| 790 | /** |
||
| 791 | * @param Request $request |
||
| 792 | * |
||
| 793 | * @return type |
||
| 794 | */ |
||
| 795 | public function postContactUs(Request $request) |
||
| 796 | { |
||
| 797 | $this->validate($request, [ |
||
| 798 | 'name' => 'required', |
||
| 799 | 'email' => 'required|email', |
||
| 800 | 'message' => 'required', |
||
| 801 | ]); |
||
| 802 | |||
| 803 | $set = new \App\Model\Common\Setting(); |
||
| 804 | $set = $set->findOrFail(1); |
||
| 805 | |||
| 806 | try { |
||
| 807 | $from = $set->email; |
||
| 808 | $fromname = $set->company; |
||
| 809 | $toname = ''; |
||
| 810 | $to = '[email protected]'; |
||
| 811 | $data = ''; |
||
| 812 | $data .= 'Name: '.$request->input('name').'<br/s>'; |
||
| 813 | $data .= 'Email: '.$request->input('email').'<br/>'; |
||
| 814 | $data .= 'Message: '.$request->input('message').'<br/>'; |
||
| 815 | $data .= 'Mobile: '.$request->input('Mobile').'<br/>'; |
||
| 816 | |||
| 817 | $subject = 'Faveo billing enquiry'; |
||
| 818 | $this->templateController->Mailing($from, $to, $data, $subject, [], $fromname, $toname); |
||
| 819 | //$this->templateController->Mailing($from, $to, $data, $subject); |
||
| 820 | return redirect()->back()->with('success', 'Your message was sent successfully. Thanks.'); |
||
| 821 | } catch (\Exception $ex) { |
||
| 822 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
| 823 | } |
||
| 824 | } |
||
| 825 | |||
| 826 | /** |
||
| 827 | * @param type $slug |
||
| 828 | * |
||
| 829 | * @return type |
||
| 830 | */ |
||
| 831 | public function addCartBySlug($slug) |
||
| 832 | { |
||
| 833 | try { |
||
| 834 | $sub = ''; |
||
| 835 | if ($slug == 'helpdesk-with-kb-pro-edition') { |
||
| 836 | $id = 8; |
||
| 837 | $sub = 13; |
||
| 838 | } |
||
| 839 | if ($slug == 'helpdesk-and-kb-community') { |
||
| 840 | $id = 7; |
||
| 841 | } |
||
| 842 | $url = url("pricing?id=$id&subscription=$sub"); |
||
| 843 | |||
| 844 | return \Redirect::to($url); |
||
| 845 | } catch (\Exception $ex) { |
||
| 846 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
| 847 | } |
||
| 848 | } |
||
| 849 | |||
| 850 | /** |
||
| 851 | * @param type $iso |
||
| 852 | * |
||
| 853 | * @throws \Exception |
||
| 854 | * |
||
| 855 | * @return string |
||
| 856 | */ |
||
| 857 | public static function findCountryByGeoip($iso) |
||
| 868 | } |
||
| 869 | } |
||
| 870 | |||
| 871 | /** |
||
| 872 | * @param type $code |
||
| 873 | * |
||
| 874 | * @throws \Exception |
||
| 875 | * |
||
| 876 | * @return type |
||
| 877 | */ |
||
| 878 | public static function getCountryByCode($code) |
||
| 879 | { |
||
| 880 | try { |
||
| 881 | $country = \App\Model\Common\Country::where('country_code_char2', $code)->first(); |
||
| 882 | if ($country) { |
||
| 883 | return $country->country_name; |
||
| 884 | } |
||
| 885 | } catch (\Exception $ex) { |
||
| 886 | throw new \Exception($ex->getMessage()); |
||
| 887 | } |
||
| 888 | } |
||
| 889 | |||
| 890 | /** |
||
| 891 | * @param type $iso |
||
| 892 | * |
||
| 893 | * @throws \Exception |
||
| 894 | * |
||
| 895 | * @return array |
||
| 896 | */ |
||
| 897 | public static function findStateByRegionId($iso) |
||
| 898 | { |
||
| 899 | try { |
||
| 900 | if ($iso) { |
||
| 901 | $states = \App\Model\Common\State::where('country_code_char2', $iso)->pluck('state_subdivision_name', 'state_subdivision_code')->toArray(); |
||
| 902 | } else { |
||
| 903 | $states = []; |
||
| 904 | } |
||
| 905 | |||
| 906 | return $states; |
||
| 907 | } catch (\Exception $ex) { |
||
| 908 | throw new \Exception($ex->getMessage()); |
||
| 909 | } |
||
| 910 | } |
||
| 911 | |||
| 912 | /** |
||
| 913 | * @param type $name |
||
| 914 | * |
||
| 915 | * @throws \Exception |
||
| 916 | * |
||
| 917 | * @return string |
||
| 918 | */ |
||
| 919 | public static function getTimezoneByName($name) |
||
| 920 | { |
||
| 921 | try { |
||
| 922 | if ($name) { |
||
| 923 | $timezone = \App\Model\Common\Timezone::where('name', $name)->first(); |
||
| 924 | if ($timezone) { |
||
| 925 | $timezone = $timezone->id; |
||
| 926 | } else { |
||
| 927 | $timezone = '114'; |
||
| 928 | } |
||
| 929 | } else { |
||
| 930 | $timezone = '114'; |
||
| 931 | } |
||
| 932 | |||
| 933 | return $timezone; |
||
| 934 | } catch (\Exception $ex) { |
||
| 935 | throw new \Exception($ex->getMessage()); |
||
| 936 | } |
||
| 937 | } |
||
| 938 | |||
| 939 | /** |
||
| 940 | * @param type $code |
||
| 941 | * |
||
| 942 | * @throws \Exception |
||
| 943 | * |
||
| 944 | * @return type |
||
| 945 | */ |
||
| 946 | public static function getStateByCode($code) |
||
| 947 | { |
||
| 948 | try { |
||
| 949 | $result = ['id' => '', 'name' => '']; |
||
| 950 | if ($code) { |
||
| 951 | $subregion = \App\Model\Common\State::where('state_subdivision_code', $code)->first(); |
||
| 952 | if ($subregion) { |
||
| 953 | $result = ['id' => $subregion->state_subdivision_code, 'name' => $subregion->state_subdivision_name]; |
||
| 954 | //return ['id' => $subregion->state_subdivision_code, 'name' => $subregion->state_subdivision_name]; |
||
| 955 | } |
||
| 956 | } |
||
| 957 | |||
| 958 | return $result; |
||
| 959 | } catch (\Exception $ex) { |
||
| 960 | throw new \Exception($ex->getMessage()); |
||
| 961 | } |
||
| 962 | } |
||
| 963 | |||
| 964 | /** |
||
| 965 | * @param type $id |
||
| 966 | * |
||
| 967 | * @throws \Exception |
||
| 968 | * |
||
| 969 | * @return type |
||
| 970 | */ |
||
| 971 | public static function getStateNameById($id) |
||
| 972 | { |
||
| 973 | try { |
||
| 974 | $name = ''; |
||
| 975 | $subregion = \App\Model\Common\State::where('state_subdivision_id', $id)->first(); |
||
| 976 | if ($subregion) { |
||
| 977 | $name = $subregion->state_subdivision_name; |
||
| 978 | } |
||
| 979 | |||
| 980 | return $name; |
||
| 981 | } catch (\Exception $ex) { |
||
| 982 | throw new \Exception($ex->getMessage()); |
||
| 983 | } |
||
| 984 | } |
||
| 985 | |||
| 986 | /** |
||
| 987 | * @param type $productid |
||
| 988 | * @param type $price |
||
| 989 | * @param type $cart |
||
| 990 | * @param type $cart1 |
||
| 991 | * @param type $shop |
||
| 992 | * |
||
| 993 | * @return type |
||
| 994 | */ |
||
| 995 | public static function calculateTax($productid, $price, $cart = 1, $cart1 = 0, $shop = 0) |
||
| 996 | { |
||
| 997 | try { |
||
| 998 | $template_controller = new TemplateController(); |
||
| 999 | $result = $template_controller->checkTax($productid, $price, $cart, $cart1, $shop); |
||
| 1000 | |||
| 1001 | $result = self::rounding($result); |
||
| 1002 | |||
| 1003 | return $result; |
||
| 1004 | } catch (\Exception $ex) { |
||
| 1005 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
| 1006 | } |
||
| 1007 | } |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * @param type $rate |
||
| 1011 | * @param type $price |
||
| 1012 | * |
||
| 1013 | * @return type |
||
| 1014 | */ |
||
| 1015 | public static function taxValue($rate, $price) |
||
| 1016 | { |
||
| 1017 | try { |
||
| 1018 | $tax = $price * ($rate / 100); |
||
| 1019 | $result = $tax; |
||
| 1020 | |||
| 1021 | $result = self::rounding($result); |
||
| 1022 | |||
| 1023 | return $result; |
||
| 1024 | } catch (\Exception $ex) { |
||
| 1025 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
| 1026 | } |
||
| 1027 | } |
||
| 1028 | |||
| 1029 | /** |
||
| 1030 | * @return type |
||
| 1031 | */ |
||
| 1032 | public static function addons() |
||
| 1033 | { |
||
| 1034 | try { |
||
| 1035 | $items = Cart::getContent(); |
||
| 1036 | $cart_productids = []; |
||
| 1037 | if (count($items) > 0) { |
||
| 1038 | foreach ($items as $key => $item) { |
||
| 1039 | $cart_productids[] = $key; |
||
| 1040 | } |
||
| 1041 | } |
||
| 1042 | $_this = new self(); |
||
| 1043 | $products = $_this->products($cart_productids); |
||
| 1044 | |||
| 1045 | return $products; |
||
| 1046 | } catch (\Exception $ex) { |
||
| 1047 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
| 1048 | } |
||
| 1049 | } |
||
| 1050 | |||
| 1051 | /** |
||
| 1052 | * @param type $ids |
||
| 1053 | * |
||
| 1054 | * @throws \Exception |
||
| 1055 | * |
||
| 1056 | * @return type |
||
| 1057 | */ |
||
| 1058 | public function products($ids) |
||
| 1059 | { |
||
| 1060 | $parents_string = []; |
||
| 1061 | $parent = []; |
||
| 1062 | $productid = []; |
||
| 1063 | |||
| 1064 | try { |
||
| 1065 | $parents = $this->product |
||
| 1066 | ->whereNotNull('parent') |
||
| 1067 | ->where('parent', '!=', 0) |
||
| 1068 | ->where('category', 'addon') |
||
| 1069 | ->pluck('parent', 'id') |
||
| 1070 | ->toArray(); |
||
| 1071 | foreach ($parents as $key => $parent) { |
||
| 1072 | if (is_array($parent)) { |
||
| 1073 | $parent = implode(',', $parent); |
||
| 1074 | } |
||
| 1075 | $parents_string[$key] = $parent; |
||
| 1076 | } |
||
| 1077 | if (count($parents_string) > 0) { |
||
| 1078 | foreach ($parents_string as $key => $value) { |
||
| 1079 | if (strpos($value, ',') !== false) { |
||
| 1080 | $value = explode(',', $value); |
||
| 1081 | } |
||
| 1082 | $parent[$key] = $value; |
||
| 1083 | } |
||
| 1084 | } |
||
| 1085 | |||
| 1086 | foreach ($parent as $key => $id) { |
||
| 1087 | if (in_array($id, $ids)) { |
||
| 1088 | $productid[] = $key; |
||
| 1089 | } |
||
| 1090 | if (is_array($id)) { |
||
| 1091 | foreach ($id as $i) { |
||
| 1092 | if (in_array($i, $ids)) { |
||
| 1093 | $productid[] = $key; |
||
| 1094 | } |
||
| 1095 | } |
||
| 1096 | } |
||
| 1097 | } |
||
| 1098 | $parent_products = $this->getProductById($productid); |
||
| 1099 | |||
| 1100 | return $parent_products; |
||
| 1101 | } catch (\Exception $ex) { |
||
| 1102 | Bugsnag::notifyException($ex); |
||
| 1103 | |||
| 1104 | throw new \Exception($ex->getMessage()); |
||
| 1105 | } |
||
| 1106 | } |
||
| 1107 | |||
| 1108 | /** |
||
| 1109 | * @param type $ids |
||
| 1110 | * |
||
| 1111 | * @throws \Exception |
||
| 1112 | * |
||
| 1113 | * @return type |
||
| 1114 | */ |
||
| 1115 | public function getProductById($ids) |
||
| 1116 | { |
||
| 1117 | try { |
||
| 1118 | $products = []; |
||
| 1119 | if (count($ids) > 0) { |
||
| 1120 | $products = $this->product |
||
| 1121 | ->whereIn('id', $ids) |
||
| 1122 | ->get(); |
||
| 1123 | } |
||
| 1124 | |||
| 1125 | return $products; |
||
| 1126 | } catch (\Exception $ex) { |
||
| 1127 | dd($ex); |
||
| 1128 | |||
| 1129 | throw new \Exception($ex->getMessage()); |
||
| 1130 | } |
||
| 1131 | } |
||
| 1132 | |||
| 1133 | /** |
||
| 1134 | * @param type $iso |
||
| 1135 | * |
||
| 1136 | * @throws \Exception |
||
| 1137 | * |
||
| 1138 | * @return type |
||
| 1139 | */ |
||
| 1140 | public static function getMobileCodeByIso($iso) |
||
| 1141 | { |
||
| 1142 | try { |
||
| 1143 | $code = ''; |
||
| 1144 | if ($iso != '') { |
||
| 1145 | $mobile = \DB::table('mobile')->where('iso', $iso)->first(); |
||
| 1146 | if ($mobile) { |
||
| 1147 | $code = $mobile->phonecode; |
||
| 1148 | } |
||
| 1149 | } |
||
| 1150 | |||
| 1151 | return $code; |
||
| 1152 | } catch (\Exception $ex) { |
||
| 1153 | throw new \Exception($ex->getMessage()); |
||
| 1154 | } |
||
| 1155 | } |
||
| 1156 | |||
| 1157 | /** |
||
| 1158 | * @param type $userid |
||
| 1159 | * |
||
| 1160 | * @throws \Exception |
||
| 1161 | * |
||
| 1162 | * @return string |
||
| 1163 | */ |
||
| 1164 | public function currency($userid = '') |
||
| 1165 | { |
||
| 1166 | try { |
||
| 1167 | $currency = 'INR'; |
||
| 1168 | if ($this->checkCurrencySession() == true) { |
||
| 1169 | $currency = Session::get('currency'); |
||
| 1170 | } |
||
| 1171 | |||
| 1172 | if (\Auth::user()) { |
||
| 1173 | $currency = \Auth::user()->currency; |
||
| 1174 | if ($currency == 'USD' || $currency == '1') { |
||
| 1175 | $currency = 'USD'; |
||
| 1176 | } |
||
| 1177 | } |
||
| 1178 | if ($userid != '') { |
||
| 1179 | $user = new \App\User(); |
||
| 1180 | $currency = $user->find($userid)->currency; |
||
| 1181 | if ($currency == 'USD' || $currency == '1') { |
||
| 1182 | $currency = 'USD'; |
||
| 1183 | } else { |
||
| 1184 | $currency = 'INR'; |
||
| 1185 | } |
||
| 1186 | } |
||
| 1187 | // dd($currency); |
||
| 1188 | return $currency; |
||
| 1189 | } catch (\Exception $ex) { |
||
| 1190 | throw new \Exception($ex->getMessage()); |
||
| 1191 | } |
||
| 1192 | } |
||
| 1193 | |||
| 1194 | /** |
||
| 1195 | * @param type $productid |
||
| 1196 | * @param type $userid |
||
| 1197 | * @param type $planid |
||
| 1198 | * |
||
| 1199 | * @return type |
||
| 1200 | */ |
||
| 1201 | public function cost($productid, $userid = '', $planid = '') |
||
| 1202 | { |
||
| 1203 | try { |
||
| 1204 | $cost = $this->planCost($productid, $userid, $planid); |
||
| 1205 | if ($cost == 0) { |
||
| 1206 | $cost = $this->productCost($productid, $userid); |
||
| 1207 | } |
||
| 1208 | |||
| 1209 | return self::rounding($cost); |
||
| 1210 | } catch (\Exception $ex) { |
||
| 1211 | // throw new \Exception($ex->getMessage()); |
||
| 1212 | } |
||
| 1213 | } |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * @param type $productid |
||
| 1217 | * @param type $userid |
||
| 1218 | * |
||
| 1219 | * @throws \Exception |
||
| 1220 | * |
||
| 1221 | * @return type |
||
| 1222 | */ |
||
| 1223 | public function productCost($productid, $userid = '') |
||
| 1224 | { |
||
| 1225 | try { |
||
| 1226 | $sales = 0; |
||
| 1227 | $currency = $this->currency($userid); |
||
| 1228 | $product = $this->product->find($productid); |
||
| 1229 | $price = $product->price()->where('currency', $currency)->first(); |
||
| 1230 | if ($price) { |
||
| 1231 | $sales = $price->sales_price; |
||
| 1232 | if ($sales == 0) { |
||
| 1233 | $sales = $price->price; |
||
| 1234 | } |
||
| 1235 | } |
||
| 1236 | //} |
||
| 1237 | |||
| 1238 | return $sales; |
||
| 1239 | } catch (\Exception $ex) { |
||
| 1240 | throw new \Exception($ex->getMessage()); |
||
| 1241 | } |
||
| 1242 | } |
||
| 1243 | |||
| 1244 | /** |
||
| 1245 | * @param type $productid |
||
| 1246 | * @param type $userid |
||
| 1247 | * @param type $planid |
||
| 1248 | * |
||
| 1249 | * @throws \Exception |
||
| 1250 | * |
||
| 1251 | * @return type |
||
| 1252 | */ |
||
| 1253 | public function planCost($productid, $userid, $planid = '') |
||
| 1281 | } |
||
| 1282 | } |
||
| 1283 | |||
| 1284 | /** |
||
| 1285 | * @throws \Exception |
||
| 1286 | */ |
||
| 1287 | public function removePlanSession() |
||
| 1288 | { |
||
| 1289 | try { |
||
| 1290 | if (Session::has('plan')) { |
||
| 1291 | Session::forget('plan'); |
||
| 1292 | } |
||
| 1293 | } catch (\Exception $ex) { |
||
| 1294 | throw new \Exception($ex->getMessage()); |
||
| 1295 | } |
||
| 1296 | } |
||
| 1297 | |||
| 1298 | /** |
||
| 1299 | * @throws \Exception |
||
| 1300 | * |
||
| 1301 | * @return bool |
||
| 1302 | */ |
||
| 1303 | public function checkPlanSession() |
||
| 1313 | } |
||
| 1314 | } |
||
| 1315 | |||
| 1316 | /** |
||
| 1317 | * @throws \Exception |
||
| 1318 | * |
||
| 1319 | * @return bool |
||
| 1320 | */ |
||
| 1321 | public function checkCurrencySession() |
||
| 1322 | { |
||
| 1323 | try { |
||
| 1324 | if (Session::has('currency')) { |
||
| 1325 | return true; |
||
| 1326 | } |
||
| 1327 | |||
| 1328 | return false; |
||
| 1329 | } catch (\Exception $ex) { |
||
| 1330 | throw new \Exception($ex->getMessage()); |
||
| 1331 | } |
||
| 1332 | } |
||
| 1333 | |||
| 1334 | /** |
||
| 1335 | * @param type $productid |
||
| 1336 | * |
||
| 1337 | * @throws \Exception |
||
| 1338 | * |
||
| 1339 | * @return bool |
||
| 1340 | */ |
||
| 1341 | public function allowSubscription($productid) |
||
| 1355 | } |
||
| 1356 | } |
||
| 1357 | } |
||
| 1358 |
This check looks for accesses to local static members using the fully qualified name instead of
self::.While this is perfectly valid, the fully qualified name of
Certificate::TRIPLEDES_CBCcould just as well be replaced byself::TRIPLEDES_CBC. Referencing local members withself::assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.