From 5e55fa63bb9faac9d23d2df118011901fb062839 Mon Sep 17 00:00:00 2001 From: Kevin Adametz Date: Mon, 14 Sep 2026 08:57:42 +0000 Subject: [PATCH] Partnercenter: Rollen-Flags fuer Einzelprovision und interne Rollen - exclude_single_commission: Rollen (z. B. Barkunde 0 %) ziehen den produktseitigen Kunden-Einzelrabatt (single_commission/value_commission) nicht mehr ab. Behebt: 0-%-Rolle zog trotzdem die Produktprovision. - hide_registration: interne Rollen (z. B. Mitarbeiter) werden im Wizard und der Mitgliedschafts-Auswahl ausgeblendet, bleiben im Admin/Lead (HTMLHelper) weiter zuweisbar. - Migration 2026_09_11_100000 (beide Flags, Default false), Model-casts/ fillable, Admin-Formular (2 Checkboxen), Warenkorb-Gate in Yard. - Test tests/Feature/UserLevelSingleCommissionTest.php. Co-Authored-By: Claude Opus 4.8 --- app/Http/Controllers/MembershipController.php | 121 ++-- app/Http/Controllers/UserLevelController.php | 45 +- app/Http/Controllers/WizardController.php | 343 +++++----- app/Models/UserLevel.php | 63 +- app/Services/Yard.php | 591 ++++++++++-------- ...00_add_role_flags_to_user_levels_table.php | 31 + resources/views/admin/level/edit.blade.php | 16 + .../Feature/UserLevelSingleCommissionTest.php | 63 ++ 8 files changed, 752 insertions(+), 521 deletions(-) create mode 100644 database/migrations/2026_09_11_100000_add_role_flags_to_user_levels_table.php create mode 100644 tests/Feature/UserLevelSingleCommissionTest.php diff --git a/app/Http/Controllers/MembershipController.php b/app/Http/Controllers/MembershipController.php index cd13b15..cc36e50 100755 --- a/app/Http/Controllers/MembershipController.php +++ b/app/Http/Controllers/MembershipController.php @@ -10,13 +10,10 @@ use App\Models\UserLevel; use App\User; use Auth; use Carbon; -use Config; -use Illuminate\Validation\Rules\In; +use Illuminate\Support\Facades\Mail; use Request; use Util; use Yard; -use Illuminate\Support\Facades\Mail; - class MembershipController extends Controller { @@ -30,14 +27,13 @@ class MembershipController extends Controller $this->middleware('auth'); } - public function index() { $user = User::find(Auth::user()->id); $diff_months = 0; - if($user->payment_account){ - $diff_months = Carbon::now()->diffInMonths(Carbon::parse($user->payment_account)) +1; + if ($user->payment_account) { + $diff_months = Carbon::now()->diffInMonths(Carbon::parse($user->payment_account)) + 1; } $userHistoryPaymentOrder = UserHistory::whereUserId($user->id)->whereAction('payment_order')->get()->last(); @@ -45,27 +41,26 @@ class MembershipController extends Controller $userHistoryDeleteMembership = UserHistory::whereUserId($user->id)->whereAction('delete_membership')->whereStatus(50)->get()->last(); $data = [ 'user' => $user, - 'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), + 'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), 'upgrade' => Product::where('active', true)->whereJsonContains('show_on', '5')->where('identifier', 'upgrade')->get(), 'diff_months' => $diff_months, 'userHistoryPaymentOrder' => $userHistoryPaymentOrder, 'userHistoryUpgradeOrder' => $userHistoryUpgradeOrder, 'userHistoryDeleteMembership' => $userHistoryDeleteMembership, - 'user_levels' => UserLevel::where('active', true)->orderBy('pos')->get(), + 'user_levels' => UserLevel::where('active', true)->where('hide_registration', false)->orderBy('pos')->get(), ]; + return view('user.membership.index', $data); } - public function storePayment($action){ - + public function storePayment($action) + { $data = Request::all(); - - - //#### remove_abo + // #### remove_abo /*if($action === "remove_abo"){ if(Request::get('abo_options_remove')){ $user = User::find(Auth::user()->id); @@ -80,28 +75,28 @@ class MembershipController extends Controller \Session()->flash('alert-error', "Fehler, Checkbox nicht bestätigt."); return back(); }*/ - //#### payment order - //#### shop upgrade - if($action === "upgrade_order" || $action === "payment_order"){ - if(Request::get('switchers-package-wizard')){ + // #### payment order + // #### shop upgrade + if ($action === 'upgrade_order' || $action === 'payment_order') { + if (Request::get('switchers-package-wizard')) { $user = User::find(Auth::user()->id); Yard::instance('shopping')->destroy(); $product = Product::find(Request::get('switchers-package-wizard')); - // $showAboOptions = false; - /* if(Request::get('abo_options')){ - $showAboOptions = true; - $user->abo_options = true; - $user->save(); - }*/ - if($product && $product->active){ - $image = ""; - if($product->images->count()){ + // $showAboOptions = false; + /* if(Request::get('abo_options')){ + $showAboOptions = true; + $user->abo_options = true; + $user->save(); + }*/ + if ($product && $product->active) { + $image = ''; + if ($product->images->count()) { $image = $product->images->first()->slug; } $qty = Request::get('qty') ? Request::get('qty') : 1; /* //need setGlobalTaxRate - + $cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), $qty, $product->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission]); if(\App\Services\UserService::getTaxFree()){ Yard::setTax($cartItem->rowId, 0); @@ -109,7 +104,7 @@ class MembershipController extends Controller Yard::setTax($cartItem->rowId, $product->getTaxWith(\App\Services\UserService::$user_country)); } */ - //Keine steuer + // Keine steuer Yard::instance('shopping')->add($product->id, $product->getLang('name'), $qty, $product->price, $product->tax, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]); Yard::instance('shopping')->setGlobalTaxRate(0); /* @@ -122,27 +117,27 @@ class MembershipController extends Controller $data['is_from'] = 'membership'; $data['is_for'] = 'me'; - /* ShoppingInstance::create([ - 'identifier' => $identifier, - 'user_shop_id' => 1, //is first faker shop for nuy intern - 'auth_user_id' => Auth::user()->id, - 'payment' => 3, //Vertriebspartner Membership - 'subdomain' => url('/'), - 'country_id' => Yard::instance('shopping')->getShippingCountryId(), - 'shopping_data' => $data, - 'back' => url()->previous(), + /* ShoppingInstance::create([ + 'identifier' => $identifier, + 'user_shop_id' => 1, //is first faker shop for nuy intern + 'auth_user_id' => Auth::user()->id, + 'payment' => 3, //Vertriebspartner Membership + 'subdomain' => url('/'), + 'country_id' => Yard::instance('shopping')->getShippingCountryId(), + 'shopping_data' => $data, + 'back' => url()->previous(), - ]);*/ + ]);*/ Yard::instance('shopping')->putYardExtra('shopping_data', $data); - //Yard::instance('shopping')->store($identifier); - //add to DB - UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>1, 'product_id'=>$product->id, 'identifier'=>$identifier]); + // Yard::instance('shopping')->store($identifier); + // add to DB + UserHistory::create(['user_id' => $user->id, 'action' => $action, 'status' => 1, 'product_id' => $product->id, 'identifier' => $identifier]); - //$path = route('checkout.checkout_card', ['identifier'=>$identifier]); - //$path = str_replace('http', 'https', $path); - // return redirect()->secure($path); - return redirect(route('user_checkout', [$identifier])); + // $path = route('checkout.checkout_card', ['identifier'=>$identifier]); + // $path = str_replace('http', 'https', $path); + // return redirect()->secure($path); + return redirect(route('user_checkout', [$identifier])); } } @@ -169,39 +164,41 @@ class MembershipController extends Controller } */ - if($action === "change_level"){ - if(Request::get('switchers-package-level')){ + if ($action === 'change_level') { + if (Request::get('switchers-package-level')) { $user = User::find(Auth::user()->id); - //hier wird die nächste Mitgliedschaftsstufe gesetzt - //wird im Cronjob UserCheckPaymentsAccounts.php verwendet und gesetzt + // hier wird die nächste Mitgliedschaftsstufe gesetzt + // wird im Cronjob UserCheckPaymentsAccounts.php verwendet und gesetzt $user->next_m_level = Request::get('switchers-package-level'); $user->save(); - UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>10, 'referenz'=>Request::get('switchers-package-level')]); - \Session()->flash('alert-success', "Änderung gespeichert"); + UserHistory::create(['user_id' => $user->id, 'action' => $action, 'status' => 10, 'referenz' => Request::get('switchers-package-level')]); + \Session()->flash('alert-success', 'Änderung gespeichert'); + return back(); } } - if($action === "delete_membership"){ - if(Request::get('delete_membership')){ - //TODO + if ($action === 'delete_membership') { + if (Request::get('delete_membership')) { + // TODO $user = User::find(Auth::user()->id); - if($user->isTestMode()){ + if ($user->isTestMode()) { $mail = config('app.info_test_mail'); - }else{ + } else { $mail = config('app.info_mail'); } Mail::to($mail)->send(new MailInfo($user, 'delete_membership')); - UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>50]); - \Session()->flash('alert-success', "Mitgliedschaft beenden ist beantragt"); + UserHistory::create(['user_id' => $user->id, 'action' => $action, 'status' => 50]); + \Session()->flash('alert-success', 'Mitgliedschaft beenden ist beantragt'); + return back(); } - \Session()->flash('alert-error', "Fehler, Checkbox nicht bestätigt."); + \Session()->flash('alert-error', 'Fehler, Checkbox nicht bestätigt.'); + return back(); } } - -} \ No newline at end of file +} diff --git a/app/Http/Controllers/UserLevelController.php b/app/Http/Controllers/UserLevelController.php index 729924f..83ce9b0 100755 --- a/app/Http/Controllers/UserLevelController.php +++ b/app/Http/Controllers/UserLevelController.php @@ -2,19 +2,15 @@ namespace App\Http\Controllers; - use App\Models\Attribute; use App\Models\ProductAttribute; -use App\Models\Shipping; use App\Models\UserLevel; use App\Models\UserLevelMargin; use Request; use Validator; - class UserLevelController extends Controller { - public function __construct() { $this->middleware('admin'); @@ -27,53 +23,59 @@ class UserLevelController extends Controller 'values' => UserLevel::orderBy('pos')->get(), 'trans' => array_keys(config('localization.supportedLocales')), ]; + return view('admin.level.index', $data); } public function edit($id) { - if($id === "new"){ - $user_level = new UserLevel(); + if ($id === 'new') { + $user_level = new UserLevel; $user_level->active = 1; - }else{ + } else { $user_level = UserLevel::findOrFail($id); } $data = [ 'value' => $user_level, ]; + return view('admin.level.edit', $data); - } + public function store() { $data = Request::all(); - if($data['action'] === 'user_level') { - if ($data['id'] === "new") { + if ($data['action'] === 'user_level') { + if ($data['id'] === 'new') { $user_level = UserLevel::create([ 'name' => $data['name'], 'pos' => $data['pos'], - 'payment_year' => isset($data['payment_year']) ? true : false, + 'payment_year' => isset($data['payment_year']) ? true : false, 'content' => $data['content'], 'partner_provision' => isset($data['partner_provision']) ? true : false, + 'exclude_single_commission' => isset($data['exclude_single_commission']) ? true : false, + 'hide_registration' => isset($data['hide_registration']) ? true : false, 'active' => isset($data['active']) ? true : false, ]); } else { $user_level = UserLevel::find($data['id']); $user_level->name = $data['name']; $user_level->pos = $data['pos']; - $user_level->payment_year =isset($data['payment_year']) ? true : false; + $user_level->payment_year = isset($data['payment_year']) ? true : false; $user_level->content = $data['content']; $user_level->partner_provision = isset($data['partner_provision']) ? true : false; + $user_level->exclude_single_commission = isset($data['exclude_single_commission']) ? true : false; + $user_level->hide_registration = isset($data['hide_registration']) ? true : false; $user_level->active = isset($data['active']) ? true : false; $user_level->save(); } - if (!empty($data['trans'])) { + if (! empty($data['trans'])) { $trans = []; foreach ($data['trans'] as $lang => $value) { if ($value && $value != null) { @@ -87,19 +89,19 @@ class UserLevelController extends Controller } } - if($data['action'] === 'user_level_margin') { + if ($data['action'] === 'user_level_margin') { $user_level = UserLevel::findOrFail($data['user_level_id']); - $rules = array('price_from' => 'required'); + $rules = ['price_from' => 'required']; $ret = ['value' => $user_level]; $validator = Validator::make(Request::all(), $rules); if ($validator->fails()) { return view('admin.level.edit', $ret)->withErrors($validator); } - if ($data['id'] === "new") { + if ($data['id'] === 'new') { $user_level_margin = UserLevelMargin::create($data); } else { $user_level_margin = UserLevelMargin::findOrFail($data['id']); - if($user_level_margin->user_level_id != $user_level->id){ + if ($user_level_margin->user_level_id != $user_level->id) { abort(404); } $user_level_margin->fill($data); @@ -108,23 +110,24 @@ class UserLevelController extends Controller } \Session()->flash('alert-save', '1'); + return redirect(route('admin_level_edit', [$user_level->id])); } public function delete($do, $id) { - if($do === 'user_level_margin'){ + if ($do === 'user_level_margin') { $model = UserLevelMargin::findOrFail($id); $id = $model->user_level->id; $model->delete(); - \Session()->flash('alert-success', "Eintrag gelöscht"); + \Session()->flash('alert-success', 'Eintrag gelöscht'); + return redirect(route('admin_level_edit', [$id])); } } - /*public function delete($id){ if(ProductAttribute::where('attribute_id', $id)->count()){ @@ -139,4 +142,4 @@ class UserLevelController extends Controller } */ -} \ No newline at end of file +} diff --git a/app/Http/Controllers/WizardController.php b/app/Http/Controllers/WizardController.php index e0b15aa..c4faeab 100755 --- a/app/Http/Controllers/WizardController.php +++ b/app/Http/Controllers/WizardController.php @@ -2,30 +2,28 @@ namespace App\Http\Controllers; -use Auth; -use Hash; -use Yard; -use Request; -use App\User; -use Validator; +use App\Mail\MailReleaseAccount; use App\Models\File; -use App\Services\Util; use App\Models\Product; -use App\Models\UserLevel; +use App\Models\ShoppingInstance; use App\Models\UserAccount; use App\Models\UserHistory; -use App\Mail\MailReleaseAccount; -use App\Models\ShoppingInstance; +use App\Models\UserLevel; use App\Repositories\FileRepository; use App\Repositories\UserRepository; +use App\Services\Util; +use App\User; +use Auth; +use Hash; use Illuminate\Support\Facades\Mail; +use Request; +use Validator; +use Yard; class WizardController extends Controller { - protected $fileRepo; - /** * Create a new controller instance. * @@ -39,21 +37,22 @@ class WizardController extends Controller public function create() { - if(!Auth::check()){ + if (! Auth::check()) { return redirect('login'); } $user = User::findOrFail(Auth::user()->id); - if(!$user->account){ + if (! $user->account) { $account = UserAccount::create([]); $user->account_id = $account->id; $user->save(); + return redirect(route('wizard_create')); } - $step = !$user->wizard ? 0 : $user->wizard; + $step = ! $user->wizard ? 0 : $user->wizard; - if($step >= 20){ + if ($step >= 20) { return redirect('/home'); } $userHistoryWizardPayment = UserHistory::whereUserId($user->id)->whereAction('wizard_payment')->get()->last(); @@ -61,12 +60,12 @@ class WizardController extends Controller $data = [ 'user' => Auth::user(), 'step' => $step, - 'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), + 'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), 'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(), 'userHistoryWizardPayment' => $userHistoryWizardPayment, ]; - if($step == 15){ + if ($step == 15) { return view('user.wizard.create_release', $data); } @@ -76,32 +75,33 @@ class WizardController extends Controller public function register() { - if(!Auth::check()){ + if (! Auth::check()) { return redirect('login'); } $user = User::findOrFail(Auth::user()->id); - if(!$user->account){ + if (! $user->account) { $account = UserAccount::create([]); $user->account_id = $account->id; $user->save(); + return redirect(route('wizard_register')); } - $step = !$user->wizard ? 0 : $user->wizard; + $step = ! $user->wizard ? 0 : $user->wizard; - if($step >= 10){ + if ($step >= 10) { return redirect('/home'); } $data = [ 'user' => Auth::user(), 'step' => $step, - 'user_levels' => UserLevel::where('active', true)->orderBy('pos', 'ASC')->get(), - //'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), - //'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(), - + 'user_levels' => UserLevel::where('active', true)->where('hide_registration', false)->orderBy('pos', 'ASC')->get(), + // 'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), + // 'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(), + ]; - if($step == 5){ + if ($step == 5) { return view('user.wizard.register_release', $data); } @@ -110,15 +110,16 @@ class WizardController extends Controller public function payment() { - if(!Auth::check()){ + if (! Auth::check()) { return redirect('login'); } $user = User::findOrFail(Auth::user()->id); - if(!$user->account){ + if (! $user->account) { $account = UserAccount::create([]); $user->account_id = $account->id; $user->save(); + return redirect(route('wizard_payment')); } @@ -127,12 +128,12 @@ class WizardController extends Controller $data = [ 'user' => Auth::user(), 'step' => 0, - 'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), + 'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), 'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(), 'userHistoryWizardPayment' => $userHistoryWizardPayment, ]; - if($user->wizard == 20){ + if ($user->wizard == 20) { return view('user.wizard.register_payment', $data); } @@ -142,74 +143,79 @@ class WizardController extends Controller public function storeRegister($step = false) { - if (!Auth::check()) { + if (! Auth::check()) { return redirect('login'); } $user = User::findOrFail(Auth::user()->id); - if (!$user->account) { - $user->account = new UserAccount(); + if (! $user->account) { + $user->account = new UserAccount; } - + $data = Request::all(); - if($step == 7 && Request::get('user_country_id')){ + if ($step == 7 && Request::get('user_country_id')) { $user->account->country_id = Request::get('user_country_id'); $user->account->save(); + return redirect(route('wizard_register', [1])); } if ($step == 0) { - $rules = array( + $rules = [ 'accepted_data_protection' => 'required', 'accepted_active' => 'required', - 'accepted_contract' => 'required' - ); + 'accepted_contract' => 'required', + ]; $validator = Validator::make(Request::all(), $rules); if ($validator->fails()) { $data = [ 'user' => Auth::user(), 'step' => $step, - 'user_levels' => UserLevel::where('active', true)->orderBy('pos', 'ASC')->get(), - //'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), - //'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),, + 'user_levels' => UserLevel::where('active', true)->where('hide_registration', false)->orderBy('pos', 'ASC')->get(), + // 'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), + // 'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),, ]; $user->wizard = 0; $user->save(); + return view('user.wizard.register', $data)->withErrors($validator); } $account = $user->account; - if($account->accepted_contract === null){ + if ($account->accepted_contract === null) { $account->accepted_contract = now(); } - if($account->data_protection === null){ + if ($account->data_protection === null) { $account->data_protection = now(); } $account->save(); - if($user->agreement === null){ + if ($user->agreement === null) { $user->agreement = now(); } $user->wizard = 1; $user->save(); + return redirect(route('wizard_register')); } if ($step == 1) { $data = Request::all(); - if(isset($data['action']) && $data['action'] == "reverse_charge_validate"){ + if (isset($data['action']) && $data['action'] == 'reverse_charge_validate') { $user->wizard = 1; $user->save(); $userRepo = new UserRepository($user); + return $userRepo->reverse_charge_validate($data, $user, route('wizard_register', [1])); } - - if(isset($data['action']) && $data['action'] == "reverse_charge_delete"){ + + if (isset($data['action']) && $data['action'] == 'reverse_charge_delete') { $user->wizard = 1; $user->save(); $userRepo = new UserRepository($user); - return $userRepo->reverse_charge_delete($data, $user, route('wizard_register', [1])); - } - $rules = array( + return $userRepo->reverse_charge_delete($data, $user, route('wizard_register', [1])); + } + + $rules = [ 'salutation' => 'required', 'first_name' => 'required', 'last_name' => 'required', @@ -221,9 +227,9 @@ class WizardController extends Controller 'tax_number' => 'required_without:tax_identification_number', 'tax_identification_number' => 'required_without:tax_number', 'country_id' => 'required|integer|min:1', - ); + ]; - if (!Request::get('same_as_billing')) { + if (! Request::get('same_as_billing')) { $rules = array_merge($rules, [ 'shipping_firstname' => 'required', 'shipping_lastname' => 'required', @@ -238,73 +244,77 @@ class WizardController extends Controller if ($validator->fails()) { $user->wizard = 1; $user->save(); + return redirect(route('wizard_register', [1]))->withErrors($validator)->withInput(Request::all()); } - + $data = Request::all(); - $data['same_as_billing'] = Request::get('same_as_billing') == NULL ? 0 : 1; + $data['same_as_billing'] = Request::get('same_as_billing') == null ? 0 : 1; $data['birthday_day'] = isset($data['birthday_day']) ? $data['birthday_day'] : 1; $data['birthday_month'] = isset($data['birthday_month']) ? $data['birthday_month'] : 1; $data['birthday_year'] = isset($data['birthday_year']) ? $data['birthday_year'] : 1900; - $data['birthday'] = $data['birthday_day'].".".$data['birthday_month'].".".$data['birthday_year']; - $data['birthday'] = $data['birthday'] == "1.1.1900" ? null : $data['birthday']; + $data['birthday'] = $data['birthday_day'].'.'.$data['birthday_month'].'.'.$data['birthday_year']; + $data['birthday'] = $data['birthday'] == '1.1.1900' ? null : $data['birthday']; $user->account->fill($data)->save(); $user->wizard = 2; $user->save(); + return redirect(route('wizard_register')); } - /* if ($step == 2) { - //kein Ausweis hochladen - deaktiviert - dd("deaktiviert"); - $user->wizard = 3; - $user->save(); - return redirect(route('wizard_register')); - /* - if(Request::get('submit') === 'do'){ - if(File::whereUserId($user->id)->whereIdentifier('id_card')->count() == 0){ - $validator = Validator::make(Request::all(), []); - $validator->errors()->add('field', __('Kein Ausweis hinterlegt, bitte erst hochladen.')); - $user->wizard = 2; - $user->save(); - return redirect(route('wizard_register'))->withErrors($validator)->withInput(Request::all()); - } - $user->wizard = 3; - $user->save(); - return redirect(route('wizard_register')); - } - $this->fileRepo->_set('disk', 'user'); - $this->fileRepo->_set('dir', '/'.$user->id.'/verification/'); - $this->fileRepo->_set('user_id', $user->id); - $this->fileRepo->_set('identifier', 'id_card'); - return $this->fileRepo->uploadFile(Request::all()); - } - */ + /* if ($step == 2) { + //kein Ausweis hochladen - deaktiviert + dd("deaktiviert"); + $user->wizard = 3; + $user->save(); + return redirect(route('wizard_register')); + /* + if(Request::get('submit') === 'do'){ + if(File::whereUserId($user->id)->whereIdentifier('id_card')->count() == 0){ + $validator = Validator::make(Request::all(), []); + $validator->errors()->add('field', __('Kein Ausweis hinterlegt, bitte erst hochladen.')); + $user->wizard = 2; + $user->save(); + return redirect(route('wizard_register'))->withErrors($validator)->withInput(Request::all()); + } + $user->wizard = 3; + $user->save(); + return redirect(route('wizard_register')); + } + $this->fileRepo->_set('disk', 'user'); + $this->fileRepo->_set('dir', '/'.$user->id.'/verification/'); + $this->fileRepo->_set('user_id', $user->id); + $this->fileRepo->_set('identifier', 'id_card'); + return $this->fileRepo->uploadFile(Request::all()); + } + */ if ($step == 2) { $data = Request::all(); - if(Request::get('submit') === 'do'){ + if (Request::get('submit') === 'do') { $data = Request::all(); - if($data['business_license_choose'] === "now"){ - if(File::whereUserId($user->id)->whereIdentifier('business_license')->count() == 0){ + if ($data['business_license_choose'] === 'now') { + if (File::whereUserId($user->id)->whereIdentifier('business_license')->count() == 0) { $validator = Validator::make(Request::all(), []); $validator->errors()->add('field', __('Kein Gewerbeschein hinterlegt, bitte erst hochladen.')); $user->wizard = 2; $user->save(); + return redirect(route('wizard_register'))->withErrors($validator)->withInput(Request::all()); } } - if($data['business_license_choose'] === "later"){ + if ($data['business_license_choose'] === 'later') { } - if($data['business_license_choose'] === "non"){ - if(!$data['non_business_license_reason'] || $data['non_business_license_reason'] == ""){ + if ($data['business_license_choose'] === 'non') { + if (! $data['non_business_license_reason'] || $data['non_business_license_reason'] == '') { $validator = Validator::make(Request::all(), []); $validator->errors()->add('field', __('Bitte gib eine Begründung ein, warum Du keinen Gewerbeschein benötigst.')); $user->wizard = 2; $user->save(); + return redirect(route('wizard_register'))->withErrors($validator)->withInput(Request::all()); - }else{ + } else { $user->account->setNotice('business_license_reason', $data['non_business_license_reason']); } } @@ -319,16 +329,18 @@ class WizardController extends Controller $this->fileRepo->_set('dir', '/'.$user->id.'/verification/'); $this->fileRepo->_set('user_id', $user->id); $this->fileRepo->_set('identifier', 'business_license'); - return $this->fileRepo->uploadFile(Request::all()); + + return $this->fileRepo->uploadFile(Request::all()); } if ($step == 3) { $data = Request::all(); - if(!isset($data['switchers-package-wizard'])){ + if (! isset($data['switchers-package-wizard'])) { $validator = Validator::make(Request::all(), []); $validator->errors()->add('field', __('Bitte wähle erst Deine Mitgildschaft aus.')); + return redirect(route('wizard_register'))->withErrors($validator)->withInput(Request::all()); } @@ -336,12 +348,12 @@ class WizardController extends Controller $user->next_m_level = $data['switchers-package-wizard']; $user->wizard = 5; $user->release_account = now(); - UserHistory::create(['user_id' => $user->id, 'action'=>'release_account', 'status'=>0]); + UserHistory::create(['user_id' => $user->id, 'action' => 'release_account', 'status' => 0]); $user->save(); - if($user->isTestMode()){ + if ($user->isTestMode()) { $mail = config('app.info_test_mail'); - }else{ + } else { $mail = config('app.info_mail'); } Mail::to($mail)->send(new MailReleaseAccount($user)); @@ -353,42 +365,43 @@ class WizardController extends Controller public function storeCreate($step = 0) { - if(!Auth::check()){ + if (! Auth::check()) { return redirect('login'); } $user = User::findOrFail(Auth::user()->id); - if(!$user->account){ - $user->account = new UserAccount(); + if (! $user->account) { + $user->account = new UserAccount; } - if($step == 10){ - $rules = array( + if ($step == 10) { + $rules = [ 'accepted_data_protection' => 'required', 'accepted_active' => 'required', - ); + ]; $validator = Validator::make(Request::all(), $rules); if ($validator->fails()) { $data = [ 'user' => Auth::user(), 'step' => $step, - 'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), + 'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), 'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(), ]; $user->wizard = 10; $user->save(); + return view('user.wizard.create', $data)->withErrors($validator); } $account = $user->account; - if($account->accepted_contract === null){ + if ($account->accepted_contract === null) { $account->accepted_contract = now(); } - if($account->data_protection === null){ + if ($account->data_protection === null) { $account->data_protection = now(); } $account->save(); - if($user->agreement === null){ + if ($user->agreement === null) { $user->agreement = now(); } $user->wizard = 11; @@ -396,54 +409,59 @@ class WizardController extends Controller return redirect(route('wizard_create', [11])); } - if($step == 11){ + if ($step == 11) { - if($user->isPasswort()){ + if ($user->isPasswort()) { $user->wizard = 12; $user->save(); + return redirect(route('wizard_create', [12])); } - $rules = array( + $rules = [ 'password' => 'required|string|min:6|confirmed', - ); + ]; $validator = Validator::make(Request::all(), $rules); if ($validator->fails()) { $data = [ 'user' => Auth::user(), 'step' => $step, - 'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), + 'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(), 'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(), ]; + return view('user.wizard.create', $data)->withErrors($validator); } $user->fill([ - 'password' => Hash::make(Request::get('password')) + 'password' => Hash::make(Request::get('password')), ])->save(); $user->wizard = 12; $user->save(); + return redirect(route('wizard_create', [12])); } - if($step == 12){ + if ($step == 12) { $data = Request::all(); - if(isset($data['action']) && $data['action'] == "reverse_charge_validate"){ + if (isset($data['action']) && $data['action'] == 'reverse_charge_validate') { $user->wizard = 12; $user->save(); $userRepo = new UserRepository($user); + return $userRepo->reverse_charge_validate($data, $user, route('wizard_create', [12])); } - - if(isset($data['action']) && $data['action'] == "reverse_charge_delete"){ - $user->wizard = 12; - $user->save(); - $userRepo = new UserRepository($user); - return $userRepo->reverse_charge_delete($data, $user, route('wizard_create', [12])); - } - $rules = array( + if (isset($data['action']) && $data['action'] == 'reverse_charge_delete') { + $user->wizard = 12; + $user->save(); + $userRepo = new UserRepository($user); + + return $userRepo->reverse_charge_delete($data, $user, route('wizard_create', [12])); + } + + $rules = [ 'salutation' => 'required', 'first_name' => 'required', 'last_name' => 'required', @@ -455,16 +473,16 @@ class WizardController extends Controller 'tax_number' => 'required_without:tax_identification_number', 'tax_identification_number' => 'required_without:tax_number', 'country_id' => 'required|integer|min:1', - ); + ]; - if(!Request::get('same_as_billing')){ + if (! Request::get('same_as_billing')) { $rules = array_merge($rules, [ - 'shipping_firstname'=>'required', - 'shipping_lastname'=>'required', - 'shipping_address'=>'required', - 'shipping_zipcode'=>'required', + 'shipping_firstname' => 'required', + 'shipping_lastname' => 'required', + 'shipping_address' => 'required', + 'shipping_zipcode' => 'required', 'shipping_city' => 'required', - 'shipping_salutation' => 'required' + 'shipping_salutation' => 'required', ]); } @@ -474,7 +492,7 @@ class WizardController extends Controller } $data = Request::all(); - $data['same_as_billing'] = Request::get('same_as_billing') == NULL ? 0 : 1; + $data['same_as_billing'] = Request::get('same_as_billing') == null ? 0 : 1; $user->account->fill($data)->save(); $user->wizard = 13; @@ -484,14 +502,16 @@ class WizardController extends Controller $user->confirmation_code_to = null; $user->confirmation_code_remider = 0; $user->save(); + return redirect(route('wizard_create', [13])); } } - public function storePayment($step = 0){ + public function storePayment($step = 0) + { - if(Request::get('switchers-package-wizard')){ + if (Request::get('switchers-package-wizard')) { $user = User::find(Auth::user()->id); Yard::instance('shopping')->destroy(); $product = Product::find(Request::get('switchers-package-wizard')); @@ -501,10 +521,10 @@ class WizardController extends Controller $user->abo_options = true; $user->save(); }*/ - if($product && $product->active){ - //set membership product - $image = ""; - if($product->images->count()){ + if ($product && $product->active) { + // set membership product + $image = ''; + if ($product->images->count()) { $image = $product->images->first()->slug; } /*need setGlobalTaxRate @@ -515,23 +535,23 @@ class WizardController extends Controller Yard::setTax($cartItem->rowId, $product->getTaxWith(\App\Services\UserService::$user_country)); } */ - //Keine steuer + // Keine steuer Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->price, $product->tax, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]); Yard::instance('shopping')->setGlobalTaxRate(0); - //set onboarding products - if(Request::get('products_on_board')){ - foreach (Request::get('products_on_board') as $product_on_board_id){ + // set onboarding products + if (Request::get('products_on_board')) { + foreach (Request::get('products_on_board') as $product_on_board_id) { $product_on_board = Product::find($product_on_board_id); - $image = ""; - if($product_on_board->images->count()){ + $image = ''; + if ($product_on_board->images->count()) { $image = $product_on_board->images->first()->slug; } - /* + /* need? - $cartItem = Yard::instance('shopping')->add($product_on_board->id, $product_on_board->getLang('name'), 1, - $product_on_board->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), + $cartItem = Yard::instance('shopping')->add($product_on_board->id, $product_on_board->getLang('name'), 1, + $product_on_board->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product_on_board->slug, 'weight' => $product_on_board->weight, 'points' => $product_on_board->points, 'no_commission' => $product_on_board->no_commission]); if(\App\Services\UserService::getTaxFree()){ Yard::setTax($cartItem->rowId, 0); @@ -553,7 +573,6 @@ class WizardController extends Controller $data['is_from'] = 'wizard'; $data['is_for'] = 'me'; - /*ShoppingInstance::create([ 'identifier' => $identifier, 'user_shop_id' => 1, //is first faker shop for buy intern @@ -566,39 +585,41 @@ class WizardController extends Controller ]);*/ Yard::instance('shopping')->putYardExtra('shopping_data', $data); - //Yard::instance('shopping')->store($identifier); - //add to DB - //$path = route('checkout.checkout_card', ['identifier'=>$identifier]); - UserHistory::create(['user_id' => $user->id, 'action'=>'wizard_payment', 'status'=>1, 'product_id'=>$product->id, 'identifier'=>$identifier]); - //$path = str_replace('http', 'https', $path); - //return redirect()->secure($path); - return redirect(route('user_checkout', [$identifier])); + // Yard::instance('shopping')->store($identifier); + // add to DB + // $path = route('checkout.checkout_card', ['identifier'=>$identifier]); + UserHistory::create(['user_id' => $user->id, 'action' => 'wizard_payment', 'status' => 1, 'product_id' => $product->id, 'identifier' => $identifier]); + // $path = str_replace('http', 'https', $path); + // return redirect()->secure($path); + return redirect(route('user_checkout', [$identifier])); } } - \Session()->flash('alert-error', "Fehler beim Produkt"); + \Session()->flash('alert-error', 'Fehler beim Produkt'); + return back(); } - public function delete($id, $relation){ + public function delete($id, $relation) + { - if($relation === 'upload'){ + if ($relation === 'upload') { $user = User::findOrFail(Auth::user()->id); $file = $user->files()->findOrFail($id); $identifier = $file->identifier; - //remove file + // remove file \Storage::disk('user')->delete($file->dir.$file->filename); $file->delete(); - \Session()->flash('alert-success', "Datei gelöscht"); - if($identifier === 'business_license'){ + \Session()->flash('alert-success', 'Datei gelöscht'); + if ($identifier === 'business_license') { $user->wizard = 2; $user->save(); + return redirect(route('wizard_register', [2])); } } + return back(); } - - -} \ No newline at end of file +} diff --git a/app/Models/UserLevel.php b/app/Models/UserLevel.php index 636b992..0b3db14 100644 --- a/app/Models/UserLevel.php +++ b/app/Models/UserLevel.php @@ -2,7 +2,9 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Carbon; /** * App\Models\UserLevel @@ -13,8 +15,9 @@ use Illuminate\Database\Eloquent\Model; * @property float|null $margin * @property int|null $pos * @property int $active - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel newQuery() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel query() @@ -26,36 +29,44 @@ use Illuminate\Database\Eloquent\Model; * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel wherePos($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel whereTransName($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel whereUpdatedAt($value) + * * @property string|null $content * @property array|null $trans_content + * * @method static \Illuminate\Database\Eloquent\Builder|UserLevel whereContent($value) * @method static \Illuminate\Database\Eloquent\Builder|UserLevel whereTransContent($value) + * * @property bool $partner_provision - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserLevelMargin[] $user_level_margins + * @property-read Collection|UserLevelMargin[] $user_level_margins * @property-read int|null $user_level_margins_count - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserLevelMargin[] $user_level_margins_re + * @property-read Collection|UserLevelMargin[] $user_level_margins_re * @property-read int|null $user_level_margins_re_count + * * @method static \Illuminate\Database\Eloquent\Builder|UserLevel wherePartnerProvision($value) + * * @property bool $payment_year + * * @method static \Illuminate\Database\Eloquent\Builder|UserLevel wherePaymentYear($value) + * * @mixin \Eloquent */ class UserLevel extends Model { protected $table = 'user_levels'; - protected $casts = ['trans_name' => 'array', - 'trans_content' => 'array', - 'partner_provision'=>'bool', - 'payment_year' => 'bool', - ]; + protected $casts = ['trans_name' => 'array', + 'trans_content' => 'array', + 'partner_provision' => 'bool', + 'payment_year' => 'bool', + 'exclude_single_commission' => 'bool', + 'hide_registration' => 'bool', + ]; protected $fillable = [ 'name', 'content', 'pos', 'payment_year', 'active', 'partner_provision', + 'exclude_single_commission', 'hide_registration', ]; - - public function user_level_margins() { return $this->hasMany('App\Models\UserLevelMargin', 'user_level_id', 'id'); @@ -66,28 +77,32 @@ class UserLevel extends Model return $this->hasMany('App\Models\UserLevelMargin', 'user_level_id', 'id')->orderBy('price_from', 'DESC'); } - public function setPosAttribute($value){ + public function setPosAttribute($value) + { $this->attributes['pos'] = is_numeric($value) ? $value : null; } - public function _format_number($value){ - return preg_replace("/[^0-9,]/", "", $value); + public function _format_number($value) + { + return preg_replace('/[^0-9,]/', '', $value); } - public function setMarginAttribute( $value ) { + public function setMarginAttribute($value) + { $value = $this->_format_number($value); $this->attributes['margin'] = floatval(str_replace(',', '.', $value)); } public function getFormattedMargin() { - if(!isset($this->attributes['margin'])){ - return ""; + if (! isset($this->attributes['margin'])) { + return ''; } - if(\App::getLocale() === "en"){ + if (\App::getLocale() === 'en') { return number_format($this->attributes['margin'], 2, '.', ','); } + return number_format($this->attributes['margin'], 2, ',', '.'); } @@ -98,26 +113,28 @@ class UserLevel extends Model return $this->{$key}; } $trans = $this->getTrans($key, $lang); - if (!$trans || $trans == '') { + if (! $trans || $trans == '') { return $this->{$key}; } + return $trans; } public function getTrans($key, $lang) { - $key = 'trans_' . $key; - if (!empty($this->{$key}[$lang])) { + $key = 'trans_'.$key; + if (! empty($this->{$key}[$lang])) { return $this->{$key}[$lang]; } } public function getTranNames() { - $ret = ""; - foreach ((array) $this->trans_name as $value){ + $ret = ''; + foreach ((array) $this->trans_name as $value) { $ret .= $value.', '; } + return rtrim($ret, ', '); } } diff --git a/app/Services/Yard.php b/app/Services/Yard.php index 4e84288..1cb61a0 100644 --- a/app/Services/Yard.php +++ b/app/Services/Yard.php @@ -1,21 +1,20 @@ ysession = $session; $this->yinstance = sprintf('%s.%s', 'cart', 'shipping_extras'); - if($this->getYardExtra('shipping_price')){ + if ($this->getYardExtra('shipping_price')) { $this->shipping_price = (float) ($this->getYardExtra('shipping_price')); } - if($this->getYardExtra('shipping_price_net')){ + if ($this->getYardExtra('shipping_price_net')) { $this->shipping_price_net = (float) ($this->getYardExtra('shipping_price_net')); } - if($this->getYardExtra('shipping_tax_rate')){ + if ($this->getYardExtra('shipping_tax_rate')) { $this->shipping_tax_rate = (float) ($this->getYardExtra('shipping_tax_rate')); } - if($this->getYardExtra('shipping_tax')){ + if ($this->getYardExtra('shipping_tax')) { $this->shipping_tax = (float) ($this->getYardExtra('shipping_tax')); } - if($this->getYardExtra('shipping_country_id')){ - $this->shipping_country_id = $this->getYardExtra('shipping_country_id'); + if ($this->getYardExtra('shipping_country_id')) { + $this->shipping_country_id = $this->getYardExtra('shipping_country_id'); } - if($this->getYardExtra('shipping_is_for')){ - $this->shipping_is_for = $this->getYardExtra('shipping_is_for'); + if ($this->getYardExtra('shipping_is_for')) { + $this->shipping_is_for = $this->getYardExtra('shipping_is_for'); } - if($this->getYardExtra('shopping_user')){ - $this->user = $this->getYardExtra('shopping_user'); + if ($this->getYardExtra('shopping_user')) { + $this->user = $this->getYardExtra('shopping_user'); } - if($this->getYardExtra('user')){ - $this->user = $this->getYardExtra('user'); + if ($this->getYardExtra('user')) { + $this->user = $this->getYardExtra('user'); } - if($this->getYardExtra('use_payment_credit')){ - $this->use_payment_credit = $this->getYardExtra('use_payment_credit'); + if ($this->getYardExtra('use_payment_credit')) { + $this->use_payment_credit = $this->getYardExtra('use_payment_credit'); } - if($this->getYardExtra('has_active_promotion')){ - $this->has_active_promotion = $this->getYardExtra('has_active_promotion'); + if ($this->getYardExtra('has_active_promotion')) { + $this->has_active_promotion = $this->getYardExtra('has_active_promotion'); } - if($this->getYardExtra('reduce_payment_credit')){ - $this->reduce_payment_credit = $this->getYardExtra('reduce_payment_credit'); + if ($this->getYardExtra('reduce_payment_credit')) { + $this->reduce_payment_credit = $this->getYardExtra('reduce_payment_credit'); } - if($this->getYardExtra('yard_commission')){ - $this->yard_commission = $this->getYardExtra('yard_commission'); + if ($this->getYardExtra('yard_commission')) { + $this->yard_commission = $this->getYardExtra('yard_commission'); } - if($this->getYardExtra('yard_margin')){ - $this->yard_margin = $this->getYardExtra('yard_margin'); + if ($this->getYardExtra('yard_margin')) { + $this->yard_margin = $this->getYardExtra('yard_margin'); } - if($this->getYardExtra('global_tax_rate') || $this->getYardExtra('global_tax_rate') === 0.0){ + if ($this->getYardExtra('global_tax_rate') || $this->getYardExtra('global_tax_rate') === 0.0) { $this->global_tax_rate = $this->getYardExtra('global_tax_rate'); - }else{ + } else { $this->global_tax_rate = config('cart.tax'); } - if($this->getYardExtra('num_comp')){ + if ($this->getYardExtra('num_comp')) { $this->num_comp = $this->getYardExtra('num_comp'); } - if($this->getYardExtra('shipping_option')){ + if ($this->getYardExtra('shipping_option')) { $this->shipping_option = $this->getYardExtra('shipping_option'); } - if($this->getYardExtra('user_tax_free')){ - $this->user_tax_free = $this->getYardExtra('user_tax_free'); + if ($this->getYardExtra('user_tax_free')) { + $this->user_tax_free = $this->getYardExtra('user_tax_free'); } - if($this->getYardExtra('shipping_free')){ - $this->shipping_free = $this->getYardExtra('shipping_free'); + if ($this->getYardExtra('shipping_free')) { + $this->shipping_free = $this->getYardExtra('shipping_free'); } - if($this->getYardExtra('user_reverse_charge')){ - $this->user_reverse_charge = $this->getYardExtra('user_reverse_charge'); + if ($this->getYardExtra('user_reverse_charge')) { + $this->user_reverse_charge = $this->getYardExtra('user_reverse_charge'); } - if($this->getYardExtra('user_country_id')){ - $this->user_country_id = $this->getYardExtra('user_country_id'); + if ($this->getYardExtra('user_country_id')) { + $this->user_country_id = $this->getYardExtra('user_country_id'); } - if($this->getYardExtra('user_country')){ - $this->user_country = $this->getYardExtra('user_country'); + if ($this->getYardExtra('user_country')) { + $this->user_country = $this->getYardExtra('user_country'); } $this->events = $events; - parent::__construct($session, $events); - if(gettype($this->shipping_country_id) !== 'object' && $this->shipping_country_id == 0){ + if (gettype($this->shipping_country_id) !== 'object' && $this->shipping_country_id == 0) { $shippingCountry = ShippingCountry::first(); - if($shippingCountry){ + if ($shippingCountry) { $this->shipping_country_id = $shippingCountry->id; } } - if($this->shipping_price == 0){ + if ($this->shipping_price == 0) { self::instance('shopping')->setShippingCountryWithPrice($this->shipping_country_id, $this->shipping_is_for); } } @@ -153,76 +171,91 @@ class Yard extends Cart return config('cart.tax'); } - public function setGlobalTaxRate($value){ + public function setGlobalTaxRate($value) + { $this->global_tax_rate = floatval($value); $this->putYardExtra('global_tax_rate', $this->global_tax_rate); } - public function getGlobalTaxRate(){ + public function getGlobalTaxRate() + { $this->global_tax_rate; - + } - public function setShippingOption($value){ + public function setShippingOption($value) + { $this->shipping_option = $value; $this->putYardExtra('shipping_option', $this->shipping_option); } - public function getShippingOption(){ + public function getShippingOption() + { return $this->shipping_option; } - public function isQuickShipping(){ - if($this->shipping_option === 'pick_up' && $this->totalWithShipping(2, '.', '') == 0.00){ + public function isQuickShipping() + { + if ($this->shipping_option === 'pick_up' && $this->totalWithShipping(2, '.', '') == 0.00) { return true; } + return false; } - public function isWithPayments(){ - if($this->totalWithShipping(2, '.', '') == 0.00){ + public function isWithPayments() + { + if ($this->totalWithShipping(2, '.', '') == 0.00) { return false; } + return true; } - - public function putYardExtra($key, $value){ + + public function putYardExtra($key, $value) + { $content = $this->getYContent(); $content->put($key, $value); $this->ysession->put($this->yinstance, $content); } - public function getYardExtra($key){ + public function getYardExtra($key) + { $content = $this->getYContent(); - if ($content->has($key)){ + if ($content->has($key)) { return $content->get($key); } + return false; } - public function getShippingCountryName(){ + public function getShippingCountryName() + { $shippingCountry = ShippingCountry::find($this->shipping_country_id); - if($shippingCountry && $shippingCountry->country){ + if ($shippingCountry && $shippingCountry->country) { return $shippingCountry->country->getLocated(); } - return ""; + + return ''; } + public function getShippingCountryCountryId() { $shippingCountry = ShippingCountry::find($this->shipping_country_id); - if($shippingCountry && $shippingCountry->country){ + if ($shippingCountry && $shippingCountry->country) { return $shippingCountry->country->id; } - return 1; //default DE + + return 1; // default DE } public function getShippingCountryId() { return $this->shipping_country_id; } - + public function getShippingPrice() { return $this->shipping_price; @@ -233,92 +266,101 @@ class Yard extends Cart if (is_null($this->ysession->get($this->yinstance))) { return new Collection([]); } + return $this->ysession->get($this->yinstance); } - public function getCartContent(){ - return $this->getContent(); + public function getCartContent() + { + return $this->getContent(); } - public function reCalculateShippingPrice(){ + public function reCalculateShippingPrice() + { $this->calculateShippingPrice(); } - - public function reCalculate(){ + + public function reCalculate() + { $this->calculateShippingPrice(); } /* * ***** */ - public function calculateMargins(){ + public function calculateMargins() + { - if($this->shipping_is_for === 'cr'){ + if ($this->shipping_is_for === 'cr') { return; } - //get user monthy amount + // get user monthy amount $monthy_amount = UserMarign::getMontlyAmount($this->user); $content = $this->getContent(); - /*single + partner Commissions */ - //get price net commission, add amount, partner (total) from products is single_commission - $yard_commission = new Commission(); - $yard_commission = $content->reduce(function ($yard_commission, CartItem $cartItem) { + /* single + partner Commissions */ + // get price net commission, add amount, partner (total) from products is single_commission + // Rolle des Users kann den produktseitigen Kunden-Einzelrabatt komplett unterdrücken (z. B. Barkunde 0 %) + $exclude_single_commission = $this->user && $this->user->user_level && $this->user->user_level->exclude_single_commission; + + $yard_commission = new Commission; + $yard_commission = $content->reduce(function ($yard_commission, CartItem $cartItem) use ($exclude_single_commission) { $price_net = $cartItem->price / ((100 + $cartItem->taxRate) / 100); - //nicht vom Staffelrabatt -> extra Rabatt / Provision - if($cartItem->options->single_commission){ - $value_commission = $price_net / 100 * $cartItem->options->value_commission; - $partner_commission = $price_net / 100 * $cartItem->options->partner_commission; + // nicht vom Staffelrabatt -> extra Rabatt / Provision + if ($cartItem->options->single_commission) { + $value_commission = $exclude_single_commission ? 0 : $price_net / 100 * $cartItem->options->value_commission; + $partner_commission = $price_net / 100 * $cartItem->options->partner_commission; $price_net_commission = ($cartItem->qty * $price_net) - ($cartItem->qty * $value_commission); $yard_commission->single_price_net += ($cartItem->qty * $price_net); $yard_commission->single_value_commission += ($cartItem->qty * $value_commission); - if($this->user->sponsorHasCommisson()){ + if ($this->user->sponsorHasCommisson()) { $yard_commission->single_partner_commission += ($cartItem->qty * $partner_commission); } $yard_commission->single_price_net_commission += $price_net_commission; // - if($cartItem->options->amount_commission){ + if ($cartItem->options->amount_commission) { $yard_commission->single_amount_commission += $price_net_commission; } - }else{ + } else { $yard_commission->price_net = $yard_commission->price_net + ($cartItem->qty * $price_net); } + return $yard_commission; }, $yard_commission); $this->yard_commission = $yard_commission; $this->putYardExtra('yard_commission', $this->yard_commission); - //dump($monthy_amount); - //add to $monthy_amount für max level margins + // dump($monthy_amount); + // add to $monthy_amount für max level margins $start_monthy_amount = $monthy_amount + $yard_commission->single_amount_commission; $end_monthy_amount = $start_monthy_amount + $yard_commission->price_net; - //dump($start_monthy_amount); - //dump($end_monthy_amount); + // dump($start_monthy_amount); + // dump($end_monthy_amount); - $margin = new Margin(); + $margin = new Margin; $rest_amount = 0; $range = 0; $price_net = $yard_commission->price_net; - if($yard_commission->price_net > 0 && $this->user && $this->user->user_level && $this->user->user_level->user_level_margins){ + if ($yard_commission->price_net > 0 && $this->user && $this->user->user_level && $this->user->user_level->user_level_margins) { foreach ($this->user->user_level->user_level_margins_re as $user_level_margin) { - //total split? + // total split? if ($end_monthy_amount >= $user_level_margin->price_from) { - if(!isset($balance)){ - if($start_monthy_amount >= $user_level_margin->price_from){ + if (! isset($balance)) { + if ($start_monthy_amount >= $user_level_margin->price_from) { $balance = $yard_commission->price_net; $rest_amount = 0; - }else{ + } else { $balance = $end_monthy_amount - $user_level_margin->price_from; $rest_amount = $end_monthy_amount - ($start_monthy_amount + $balance); } - }else{ - if(isset($last_limit)){ + } else { + if (isset($last_limit)) { $range = $last_limit - $user_level_margin->price_from; - if($rest_amount >= $range){ + if ($rest_amount >= $range) { $balance = $range; - }else{ + } else { $balance = $rest_amount; } $rest_amount = $rest_amount - $balance; @@ -326,9 +368,9 @@ class Yard extends Cart } $last_limit = $user_level_margin->price_from; - if($balance != 0){ + if ($balance != 0) { $commission = 0; - if($this->user->sponsorHasCommisson()){ + if ($this->user->sponsorHasCommisson()) { $commission = $user_level_margin->commission; } $margin->add($user_level_margin->price_from, [ @@ -348,24 +390,30 @@ class Yard extends Cart $margin->calculate(); $this->yard_margin = $margin; $this->putYardExtra('yard_margin', $this->yard_margin); - //dump($margin); + // dump($margin); } - public function setUser($user){ + public function setUser($user) + { $this->user = $user; $this->putYardExtra('user', $user); } - public function sponsorHasCommisson(){ + public function sponsorHasCommisson() + { return $this->user->sponsorHasCommisson(); } - public function getYardMargin(){ + public function getYardMargin() + { return $this->yard_margin; } - public function getYardCommission(){ + + public function getYardCommission() + { return $this->yard_commission; } + /* * ***** */ public function setShippingCountryWithPrice($shipping_country_id, $shipping_is_for = 'ot') { @@ -396,11 +444,12 @@ class Yard extends Cart $this->putYardExtra('user_country', $this->user_country); } - public function setShoppingUser($user, $use_payment_credit = false){ + public function setShoppingUser($user, $use_payment_credit = false) + { $this->user = $user; $this->use_payment_credit = $use_payment_credit; $this->has_active_promotion = UserService::hasActivePromotion($user); - $this->reduce_payment_credit = true; //default set true, checkbox on yard_view_from ist checked + $this->reduce_payment_credit = true; // default set true, checkbox on yard_view_from ist checked $this->putYardExtra('user', $user); $this->putYardExtra('use_payment_credit', $use_payment_credit); $this->putYardExtra('has_active_promotion', $this->has_active_promotion); @@ -408,11 +457,12 @@ class Yard extends Cart } - public function getUserPriceInfos(){ + public function getUserPriceInfos() + { return [ - 'user_tax_free' =>$this->user_tax_free, - 'user_reverse_charge' =>$this->user_reverse_charge, - 'user_country_id' =>$this->user_country_id, + 'user_tax_free' => $this->user_tax_free, + 'user_reverse_charge' => $this->user_reverse_charge, + 'user_country_id' => $this->user_country_id, 'shipping_free' => $this->shipping_free, ]; } @@ -439,164 +489,174 @@ class Yard extends Cart public function getShippingFreeMissingValue() { - if($this->shipping_free && $this->total(2, '.', '') < $this->shipping_free){ + if ($this->shipping_free && $this->total(2, '.', '') < $this->shipping_free) { return $this->shipping_free - $this->total(2, '.', ''); - } + } + return 0; } - - - public function setReducePaymentCredit($reduce_payment_credit){ + public function setReducePaymentCredit($reduce_payment_credit) + { $this->reduce_payment_credit = $reduce_payment_credit; $this->putYardExtra('reduce_payment_credit', $reduce_payment_credit); } - public function getReducePaymentCredit(){ + public function getReducePaymentCredit() + { return $this->reduce_payment_credit; } - - public function getPaymentCredit(){ - if($this->use_payment_credit && $this->user->payment_credit > 0){ + public function getPaymentCredit() + { + if ($this->use_payment_credit && $this->user->payment_credit > 0) { return $this->user->payment_credit; } + return false; } - public function hasActivePromotion(){ + public function hasActivePromotion() + { return $this->has_active_promotion; } - public function reducePaymentCredit(){ - if(!$this->reduce_payment_credit){ + public function reducePaymentCredit() + { + if (! $this->reduce_payment_credit) { return false; } - if($this->has_active_promotion){ + if ($this->has_active_promotion) { return false; } + return $this->getPaymentCredit(); } - private function calculateShippingPrice(){ - //keine Verandkosten - if($this->shipping_option && $this->shipping_option === 'pick_up'){ + private function calculateShippingPrice() + { + // keine Verandkosten + if ($this->shipping_option && $this->shipping_option === 'pick_up') { $this->shipping_price = 0; $this->shipping_tax_rate = 0; $this->shipping_price_net = 0; $this->shipping_tax = 0; $this->putShippingPrices(); + return; - } - //keine Verandkosten - if($this->shipping_is_for === 'cr' || $this->shipping_is_for === 'mp'){ + } + // keine Verandkosten + if ($this->shipping_is_for === 'cr' || $this->shipping_is_for === 'mp') { $this->shipping_price = 0; $this->shipping_tax_rate = 0; $this->shipping_price_net = 0; $this->shipping_tax = 0; $this->putShippingPrices(); - return; + + return; } $shippingCountry = ShippingCountry::find($this->shipping_country_id); - if(!$shippingCountry){ + if (! $shippingCountry) { return; } $shipping = $shippingCountry->shipping; $shipping_price_for = 1; - if($this->shipping_is_for === 'me' || $this->shipping_is_for === 'ot'){ + if ($this->shipping_is_for === 'me' || $this->shipping_is_for === 'ot') { $shipping_price_for = 1; } - if($this->shipping_is_for === 'prom'){ + if ($this->shipping_is_for === 'prom') { $shipping_price_for = 2; } - if($this->shipping_is_for === 'shop'){ + if ($this->shipping_is_for === 'shop') { $shipping_price_for = 3; } - if($this->weight() == 0){ + if ($this->weight() == 0) { $shipping_price = $shipping->getShippingPricesBy($shipping_price_for)->first(); - if(!$shipping_price){ - $shipping_price = new \App\Models\ShippingPrice(); + if (! $shipping_price) { + $shipping_price = new ShippingPrice; } $shipping_price->price = 0; $shipping_price->price_comp = 0; - }else{ - //first by price + } else { + // first by price $shipping_price = $this->shippingPriceBySubTotal($shipping->getShippingPricesBy($shipping_price_for), $this->subtotal(2, '.', '')); - //sec by weight - if(!$shipping_price){ + // sec by weight + if (! $shipping_price) { $shipping_price = $this->shippingPriceByWeight($shipping->getShippingPricesBy($shipping_price_for), $this->weight()); - } - //default - if(!$shipping_price){ + // default + if (! $shipping_price) { $shipping_price = $shipping->getShippingPricesBy($shipping_price_for)->first(); } } - if($shipping_price){ + if ($shipping_price) { $price = $shipping_price->price; $this->num_comp = 0; - if($this->weight() > 0){ - if($this->shipping_is_for === 'me' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_me')){ + if ($this->weight() > 0) { + if ($this->shipping_is_for === 'me' && Setting::getContentBySlug('order_partner_is_comp_me')) { $price = $shipping_price->price_comp; $this->num_comp = $shipping_price->num_comp; } - if($this->shipping_is_for === 'ot' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_ot')){ + if ($this->shipping_is_for === 'ot' && Setting::getContentBySlug('order_partner_is_comp_ot')) { $price = $shipping_price->price_comp; $this->num_comp = $shipping_price->num_comp; } } $this->shipping_price = $price; $this->shipping_tax_rate = $shipping_price->tax_rate; - $this->shipping_price_net = round($price / ((100+$shipping_price->tax_rate) / 100), 2); - $this->shipping_tax = round($price / (100+$shipping_price->tax_rate) * 100, 2); + $this->shipping_price_net = round($price / ((100 + $shipping_price->tax_rate) / 100), 2); + $this->shipping_tax = round($price / (100 + $shipping_price->tax_rate) * 100, 2); $this->putShippingPrices(); } } - public function preCalcuShippingPrice(){ + public function preCalcuShippingPrice() + { $shippingCountry = ShippingCountry::find($this->shipping_country_id); - if(!$shippingCountry){ + if (! $shippingCountry) { return false; } $shipping = $shippingCountry->shipping; $shipping_price_for = 1; - if($this->shipping_is_for === 'prom'){ + if ($this->shipping_is_for === 'prom') { $shipping_price_for = 2; } - if($this->shipping_is_for === 'shop'){ + if ($this->shipping_is_for === 'shop') { $shipping_price_for = 3; } - if($this->weight() == 0){ + if ($this->weight() == 0) { $shipping_price = $shipping->getShippingPricesBy($shipping_price_for)->first(); - if(!$shipping_price){ - $shipping_price = new \App\Models\ShippingPrice(); + if (! $shipping_price) { + $shipping_price = new ShippingPrice; } $shipping_price->price = 0; - }else{ - //first by price + } else { + // first by price $shipping_price = $this->shippingPriceBySubTotal($shipping->getShippingPricesBy($shipping_price_for), $this->subtotal(2, '.', '')); - //sec by weight - if(!$shipping_price){ + // sec by weight + if (! $shipping_price) { $shipping_price = $this->shippingPriceByWeight($shipping->getShippingPricesBy($shipping_price_for), $this->weight()); } - //default - if(!$shipping_price){ + // default + if (! $shipping_price) { $shipping_price = $shipping->getShippingPricesBy($shipping_price_for)->first(); } } - if($shipping_price){ + if ($shipping_price) { return $shipping_price->price; } + return false; - + } - private function putShippingPrices(){ + private function putShippingPrices() + { $this->putYardExtra('num_comp', $this->num_comp); $this->putYardExtra('shipping_price', $this->shipping_price); $this->putYardExtra('shipping_tax_rate', $this->shipping_tax_rate); @@ -604,32 +664,36 @@ class Yard extends Cart $this->putYardExtra('shipping_price_net', $this->shipping_price_net); } - private function shippingPriceBySubTotal($prices, $total){ - foreach ($prices as $price){ - if($price->total_from > 0 && $price->total_to > 0){ - if($total >= $price->total_from && $total <= $price->total_to){ + private function shippingPriceBySubTotal($prices, $total) + { + foreach ($prices as $price) { + if ($price->total_from > 0 && $price->total_to > 0) { + if ($total >= $price->total_from && $total <= $price->total_to) { return $price; } } } + return false; } - private function shippingPriceByWeight($prices, $weight){ - foreach ($prices as $price){ - if($price->weight_from > 0 && $price->weight_to > 0){ - if($weight >= $price->weight_from && $weight <= $price->weight_to){ + private function shippingPriceByWeight($prices, $weight) + { + foreach ($prices as $price) { + if ($price->weight_from > 0 && $price->weight_to > 0) { + if ($weight >= $price->weight_from && $weight <= $price->weight_to) { return $price; } } } + return false; } /** - * @param null $decimals - * @param null $decimalPoint - * @param null $thousandSeperator + * @param null $decimals + * @param null $decimalPoint + * @param null $thousandSeperator * @return string */ public function shipping($decimals = null, $decimalPoint = null, $thousandSeperator = null) @@ -641,56 +705,58 @@ class Yard extends Cart { return $this->numberFormat($this->shipping_price_net, $decimals, $decimalPoint, $thousandSeperator); } + // private function shippingTax($decimals = null, $decimalPoint = null, $thousandSeperator = null) { return $this->numberFormat($this->shipping_tax, $decimals, $decimalPoint, $thousandSeperator); } - /* private function subShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null){ - $subShipping = $this->shipping_price_net - return $this->numberFormat($subShipping, $decimals, $decimalPoint, $thousandSeperator); - }*/ - //netto + /* private function subShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null){ + $subShipping = $this->shipping_price_net + return $this->numberFormat($subShipping, $decimals, $decimalPoint, $thousandSeperator); + }*/ + // netto public function subtotalWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null) { $subtotal = (float) $this->shipping_price_net + $this->subtotal(2, '.', ''); + return $this->numberFormat($subtotal, $decimals, $decimalPoint, $thousandSeperator); } - public function taxWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null) { - // $total = $this->totalWithShipping(2, '.', ''); - // $totalTax = (float) $this->tax(2, '.', '') + $this->shipping_tax; + // $total = $this->totalWithShipping(2, '.', ''); + // $totalTax = (float) $this->tax(2, '.', '') + $this->shipping_tax; $subtotal_shipping = $this->subtotalWithShipping(2, '.', ''); + return $this->numberFormat(($subtotal_shipping / 100 * $this->global_tax_rate), $decimals, $decimalPoint, $thousandSeperator); } - public function totalWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null) { - //$total = (float) ($this->total(2, '.', '')) + $this->shipping_price; + // $total = (float) ($this->total(2, '.', '')) + $this->shipping_price; $subtotal_shipping = $this->subtotalWithShipping(2, '.', ''); $tax = $subtotal_shipping / 100 * $this->global_tax_rate; $total = ($subtotal_shipping + $tax); - if($PaymentCredit = $this->reducePaymentCredit()){ + if ($PaymentCredit = $this->reducePaymentCredit()) { $total = $total - $PaymentCredit; - if($total < 0){ + if ($total < 0) { $total = 0; } } + return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator); } - public function totalWithShippingWithoutCredit($decimals = null, $decimalPoint = null, $thousandSeperator = null) { - //$total = (float) ($this->total(2, '.', '')) + $this->shipping_price; + // $total = (float) ($this->total(2, '.', '')) + $this->shipping_price; $subtotal_shipping = $this->subtotalWithShipping(2, '.', ''); $tax = $subtotal_shipping / 100 * $this->global_tax_rate; $total = ($subtotal_shipping + $tax); + return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator); } @@ -698,33 +764,35 @@ class Yard extends Cart { $rest = 0; if ($PaymentCredit = $this->reducePaymentCredit()) { - $subtotal_shipping= $this->subtotalWithShipping(2, '.', ''); - $tax = $subtotal_shipping/ 100 * $this->global_tax_rate; - $total = ($subtotal_shipping+ $tax); + $subtotal_shipping = $this->subtotalWithShipping(2, '.', ''); + $tax = $subtotal_shipping / 100 * $this->global_tax_rate; + $total = ($subtotal_shipping + $tax); $rest = $PaymentCredit - $total; - if($rest < 0){ + if ($rest < 0) { $rest = $PaymentCredit; - }else{ + } else { $rest = $PaymentCredit - $rest; } } + return $this->numberFormat($rest, $decimals, $decimalPoint, $thousandSeperator); } /** * Get the total price of the items in the cart. * - * @param int $decimals - * @param string $decimalPoint - * @param string $thousandSeperator + * @param int $decimals + * @param string $decimalPoint + * @param string $thousandSeperator * @return string */ public function weight($decimals = null, $decimalPoint = null, $thousandSeperator = null) { $content = $this->getContent(); $total = $content->reduce(function ($total, CartItem $cartItem) { - return $total + ($cartItem->options->weight ? ($cartItem->options->weight*$cartItem->qty) : 0); + return $total + ($cartItem->options->weight ? ($cartItem->options->weight * $cartItem->qty) : 0); }, 0); + return $total; } @@ -734,6 +802,7 @@ class Yard extends Cart $total = $content->reduce(function ($total, CartItem $cartItem) { return $total + ($cartItem->options->points ? ($cartItem->options->points * $cartItem->qty) : 0); }, 0); + return $total; } @@ -745,15 +814,16 @@ class Yard extends Cart $comp_count = $content->reduce(function ($comp_count, CartItem $cartItem) { return $cartItem->options->comp ? $comp_count + 1 : $comp_count; }, 0); - return $count-$comp_count; + + return $count - $comp_count; } /** * Get the total price of the items in the cart. * - * @param int $decimals - * @param string $decimalPoint - * @param string $thousandSeperator + * @param int $decimals + * @param string $decimalPoint + * @param string $thousandSeperator * @return string */ public function total($decimals = null, $decimalPoint = null, $thousandSeperator = null, $withFees = false) @@ -767,17 +837,16 @@ class Yard extends Cart $fees = $this->feeTotal(null, null, null, true); $total = $total + $fees; } + return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator); } - - /** * Get the total tax of the items in the cart. * - * @param int $decimals - * @param string $decimalPoint - * @param string $thousandSeperator + * @param int $decimals + * @param string $decimalPoint + * @param string $thousandSeperator * @return float */ public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = null, $withFees = false) @@ -786,6 +855,7 @@ class Yard extends Cart $tax = $content->reduce(function ($tax, CartItem $cartItem) { $priceTax = $cartItem->price / (100 + $cartItem->taxRate) * $cartItem->taxRate; + return $tax + ($cartItem->qty * $priceTax); }, 0); @@ -797,13 +867,12 @@ class Yard extends Cart return $this->numberFormat($tax, $decimals, $decimalPoint, $thousandSeperator); } - /** * Get the subtotal (total - tax) of the items in the cart. * - * @param int $decimals - * @param string $decimalPoint - * @param string $thousandSeperator + * @param int $decimals + * @param string $decimalPoint + * @param string $thousandSeperator * @return float */ public function subtotal($decimals = null, $decimalPoint = null, $thousandSeperator = null, $discount = true) @@ -812,27 +881,29 @@ class Yard extends Cart $subTotal = $content->reduce(function ($subTotal, CartItem $cartItem) { $price_net = $cartItem->price / ((100 + $cartItem->taxRate) / 100); + return $subTotal + ($cartItem->qty * $price_net); }, 0); - if($discount && $this->yard_margin){ + if ($discount && $this->yard_margin) { $subTotal -= $this->yard_margin->net_discount; } + return $this->numberFormat($subTotal, $decimals, $decimalPoint, $thousandSeperator); } - - public function getCartItemByProduct($product_id, $set_price='with', $commission=true){ - if($product = Product::find($product_id)) { - $image = ""; + public function getCartItemByProduct($product_id, $set_price = 'with', $commission = true) + { + if ($product = Product::find($product_id)) { + $image = ''; if ($product->images->count()) { $image = $product->images->first()->slug; } $price = $product->price; - if($set_price === 'with'){ + if ($set_price === 'with') { $price = $product->getPriceWith(false, true); } - if($commission){ + if ($commission) { $options = [ 'image' => $image, 'slug' => $product->slug, @@ -842,28 +913,30 @@ class Yard extends Cart 'value_commission' => $product->value_commission, 'partner_commission' => $product->partner_commission, ]; - }else{ + } else { $options = [ 'image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, ]; } - + $cartItem = $this->getCartItem($product->id, $product->getLang('name'), 1, $price, $options); $content = $this->getContent(); - if ($content->has($cartItem->rowId)){ + if ($content->has($cartItem->rowId)) { return $content->get($cartItem->rowId); } + return $cartItem; } + return null; } - - public function getCartItem($id, $name = null, $qty = null, $price = null, array $options = []){ + public function getCartItem($id, $name = null, $qty = null, $price = null, array $options = []) + { if ($id instanceof Buyable) { $cartItem = CartItem::fromBuyable($id, $qty ?: []); } elseif (is_array($id)) { @@ -871,6 +944,7 @@ class Yard extends Cart } else { $cartItem = CartItem::fromAttributes($id, $name, $price, $options); } + return $cartItem; } @@ -881,81 +955,90 @@ class Yard extends Cart } - public function rowPrice(CartItem $row, $decimals = null, $decimalPoint = null, $thousandSeperator = null){ + public function rowPrice(CartItem $row, $decimals = null, $decimalPoint = null, $thousandSeperator = null) + { return $this->numberFormat($row->price, $decimals, $decimalPoint, $thousandSeperator); } - public function rowPriceNet(CartItem $row, $decimals = null, $decimalPoint = null, $thousandSeperator = null){ - $price = round($row->price / ((100 + $row->taxRate) /100), 4); + public function rowPriceNet(CartItem $row, $decimals = null, $decimalPoint = null, $thousandSeperator = null) + { + $price = round($row->price / ((100 + $row->taxRate) / 100), 4); + return $this->numberFormat($price, $decimals, $decimalPoint, $thousandSeperator); } - public function rowSubtotal(CartItem $row, $decimals = null, $decimalPoint = null, $thousandSeperator = null){ + public function rowSubtotal(CartItem $row, $decimals = null, $decimalPoint = null, $thousandSeperator = null) + { return $this->numberFormat(($row->price * $row->qty), $decimals, $decimalPoint, $thousandSeperator); } - public function rowSubtotalNet(CartItem $row, $decimals = null, $decimalPoint = null, $thousandSeperator = null){ - $price = round($row->price / ((100 + $row->taxRate) /100), 4); + public function rowSubtotalNet(CartItem $row, $decimals = null, $decimalPoint = null, $thousandSeperator = null) + { + $price = round($row->price / ((100 + $row->taxRate) / 100), 4); + return $this->numberFormat(($price * $row->qty), $decimals, $decimalPoint, $thousandSeperator); } - public function getNumComp(){ + public function getNumComp() + { return $this->num_comp; } - public function getCompProductBy($comp, $product_id=false){ + public function getCompProductBy($comp, $product_id = false) + { foreach ($this->content() as $row) { - if($row->options->comp == $comp) { + if ($row->options->comp == $comp) { return $row->options->product_id; } } + return false; } - public function getFreeProductId(){ + public function getFreeProductId() + { foreach ($this->content() as $row) { - if($row->options->free_product_id) { + if ($row->options->free_product_id) { return $row->options->free_product_id; } } + return false; } - public function getContentByOrder(){ + public function getContentByOrder() + { $ret = []; $comp = []; - foreach ($this->content() as $row) { - if($row->options->comp){ - $comp[100+$row->options->comp] = $row; - }elseif($row->options->free_product_id){ + foreach ($this->content() as $row) { + if ($row->options->comp) { + $comp[100 + $row->options->comp] = $row; + } elseif ($row->options->free_product_id) { $comp[200] = $row; - }else{ + } else { $ret[] = $row; } } ksort($comp); $ret = array_merge($ret, $comp); + return $ret; } /** * Get the Formated number * - * @param $value - * @param $decimals - * @param $decimalPoint - * @param $thousandSeperator * @return string */ protected function numberFormat($value, $decimals, $decimalPoint, $thousandSeperator) { - if(is_null($decimals)){ + if (is_null($decimals)) { $decimals = is_null(config('cart.format.decimals')) ? 2 : config('cart.format.decimals'); } - if(is_null($decimalPoint)){ + if (is_null($decimalPoint)) { $decimalPoint = is_null(config('cart.format.decimal_point')) ? '.' : config('cart.format.decimal_point'); } - if(is_null($thousandSeperator)){ + if (is_null($thousandSeperator)) { $thousandSeperator = is_null(config('cart.format.thousand_seperator')) ? ',' : config('cart.format.thousand_seperator'); } diff --git a/database/migrations/2026_09_11_100000_add_role_flags_to_user_levels_table.php b/database/migrations/2026_09_11_100000_add_role_flags_to_user_levels_table.php new file mode 100644 index 0000000..d46ed81 --- /dev/null +++ b/database/migrations/2026_09_11_100000_add_role_flags_to_user_levels_table.php @@ -0,0 +1,31 @@ + bestehende Rollen verhalten sich unverändert. + */ +return new class extends Migration +{ + public function up(): void + { + Schema::table('user_levels', function (Blueprint $table) { + $table->boolean('exclude_single_commission')->default(false)->after('partner_provision'); + $table->boolean('hide_registration')->default(false)->after('exclude_single_commission'); + }); + } + + public function down(): void + { + Schema::table('user_levels', function (Blueprint $table) { + $table->dropColumn(['exclude_single_commission', 'hide_registration']); + }); + } +}; diff --git a/resources/views/admin/level/edit.blade.php b/resources/views/admin/level/edit.blade.php index 32436d3..c17fad4 100755 --- a/resources/views/admin/level/edit.blade.php +++ b/resources/views/admin/level/edit.blade.php @@ -59,6 +59,22 @@ Auch immer die Provision bei den Staffelpreisen eintragen!
Die Provision wird beim Käufer berechnet und nur ein Sponsor mit der Rolle wo diese Checkbox aktiv ist bekommt die Provison gutgeschrieben.
+
+ + Für Rollen ohne Rabatt (z. B. Barkunde 0 %): Der am Produkt hinterlegte Kunden-Einzelrabatt (Einzelprovision) wird im Warenkorb NICHT abgezogen. Staffelrabatt und Sponsor-Provision bleiben davon unberührt. +
+ +
+ + Interne Rollen (z. B. Mitarbeiter) werden bei der Registrierung und der Mitgliedschafts-Auswahl ausgeblendet. Im Admin/Lead-Formular bleibt die Rolle zuweisbar. +
+