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 <noreply@anthropic.com>
This commit is contained in:
parent
ef19dc2ced
commit
5e55fa63bb
8 changed files with 752 additions and 521 deletions
|
|
@ -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,7 +27,6 @@ class MembershipController extends Controller
|
|||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$user = User::find(Auth::user()->id);
|
||||
|
|
@ -51,20 +47,19 @@ class MembershipController extends Controller
|
|||
'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
|
||||
/*if($action === "remove_abo"){
|
||||
if(Request::get('abo_options_remove')){
|
||||
|
|
@ -82,7 +77,7 @@ class MembershipController extends Controller
|
|||
}*/
|
||||
// #### payment order
|
||||
// #### shop upgrade
|
||||
if($action === "upgrade_order" || $action === "payment_order"){
|
||||
if ($action === 'upgrade_order' || $action === 'payment_order') {
|
||||
if (Request::get('switchers-package-wizard')) {
|
||||
$user = User::find(Auth::user()->id);
|
||||
Yard::instance('shopping')->destroy();
|
||||
|
|
@ -94,7 +89,7 @@ class MembershipController extends Controller
|
|||
$user->save();
|
||||
}*/
|
||||
if ($product && $product->active) {
|
||||
$image = "";
|
||||
$image = '';
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
|
@ -169,7 +164,7 @@ class MembershipController extends Controller
|
|||
}
|
||||
*/
|
||||
|
||||
if($action === "change_level"){
|
||||
if ($action === 'change_level') {
|
||||
if (Request::get('switchers-package-level')) {
|
||||
$user = User::find(Auth::user()->id);
|
||||
// hier wird die nächste Mitgliedschaftsstufe gesetzt
|
||||
|
|
@ -177,13 +172,14 @@ class MembershipController extends Controller
|
|||
$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");
|
||||
\Session()->flash('alert-success', 'Änderung gespeichert');
|
||||
|
||||
return back();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if($action === "delete_membership"){
|
||||
if ($action === 'delete_membership') {
|
||||
if (Request::get('delete_membership')) {
|
||||
// TODO
|
||||
$user = User::find(Auth::user()->id);
|
||||
|
|
@ -194,14 +190,15 @@ class MembershipController extends Controller
|
|||
}
|
||||
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");
|
||||
\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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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,13 +23,14 @@ 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 {
|
||||
|
|
@ -43,23 +40,26 @@ class UserLevelController extends Controller
|
|||
$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['id'] === 'new') {
|
||||
$user_level = UserLevel::create([
|
||||
'name' => $data['name'],
|
||||
'pos' => $data['pos'],
|
||||
'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 {
|
||||
|
|
@ -69,6 +69,8 @@ class UserLevelController extends Controller
|
|||
$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();
|
||||
}
|
||||
|
|
@ -89,13 +91,13 @@ class UserLevelController extends Controller
|
|||
|
||||
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']);
|
||||
|
|
@ -108,6 +110,7 @@ class UserLevelController extends Controller
|
|||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
|
||||
return redirect(route('admin_level_edit', [$user_level->id]));
|
||||
|
||||
}
|
||||
|
|
@ -118,13 +121,13 @@ class UserLevelController extends Controller
|
|||
$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()){
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*
|
||||
|
|
@ -48,6 +46,7 @@ class WizardController extends Controller
|
|||
$account = UserAccount::create([]);
|
||||
$user->account_id = $account->id;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_create'));
|
||||
}
|
||||
|
||||
|
|
@ -84,6 +83,7 @@ class WizardController extends Controller
|
|||
$account = UserAccount::create([]);
|
||||
$user->account_id = $account->id;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_register'));
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ class WizardController extends Controller
|
|||
$data = [
|
||||
'user' => Auth::user(),
|
||||
'step' => $step,
|
||||
'user_levels' => UserLevel::where('active', true)->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(),
|
||||
|
||||
|
|
@ -119,6 +119,7 @@ class WizardController extends Controller
|
|||
$account = UserAccount::create([]);
|
||||
$user->account_id = $account->id;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_payment'));
|
||||
}
|
||||
|
||||
|
|
@ -148,32 +149,34 @@ class WizardController extends Controller
|
|||
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
if (! $user->account) {
|
||||
$user->account = new UserAccount();
|
||||
$user->account = new UserAccount;
|
||||
}
|
||||
|
||||
$data = Request::all();
|
||||
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(),
|
||||
'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;
|
||||
|
|
@ -190,26 +193,29 @@ class WizardController extends Controller
|
|||
|
||||
$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(
|
||||
$rules = [
|
||||
'salutation' => 'required',
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
|
|
@ -221,7 +227,7 @@ 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')) {
|
||||
$rules = array_merge($rules, [
|
||||
|
|
@ -238,19 +244,21 @@ 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) {
|
||||
|
|
@ -285,24 +293,26 @@ class WizardController extends Controller
|
|||
if (Request::get('submit') === 'do') {
|
||||
$data = Request::all();
|
||||
|
||||
if($data['business_license_choose'] === "now"){
|
||||
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 {
|
||||
$user->account->setNotice('business_license_reason', $data['non_business_license_reason']);
|
||||
|
|
@ -319,6 +329,7 @@ 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());
|
||||
}
|
||||
|
||||
|
|
@ -329,6 +340,7 @@ class WizardController extends Controller
|
|||
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());
|
||||
}
|
||||
|
||||
|
|
@ -359,14 +371,14 @@ class WizardController extends Controller
|
|||
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
if (! $user->account) {
|
||||
$user->account = new UserAccount();
|
||||
$user->account = new UserAccount;
|
||||
}
|
||||
|
||||
if ($step == 10) {
|
||||
$rules = array(
|
||||
$rules = [
|
||||
'accepted_data_protection' => 'required',
|
||||
'accepted_active' => 'required',
|
||||
);
|
||||
];
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
$data = [
|
||||
|
|
@ -377,6 +389,7 @@ class WizardController extends Controller
|
|||
];
|
||||
$user->wizard = 10;
|
||||
$user->save();
|
||||
|
||||
return view('user.wizard.create', $data)->withErrors($validator);
|
||||
|
||||
}
|
||||
|
|
@ -401,11 +414,12 @@ class WizardController extends Controller
|
|||
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 = [
|
||||
|
|
@ -414,36 +428,40 @@ class WizardController extends Controller
|
|||
'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) {
|
||||
|
||||
$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"){
|
||||
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(
|
||||
$rules = [
|
||||
'salutation' => 'required',
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
|
|
@ -455,7 +473,7 @@ 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')) {
|
||||
$rules = array_merge($rules, [
|
||||
|
|
@ -464,7 +482,7 @@ class WizardController extends Controller
|
|||
'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,12 +502,14 @@ 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')) {
|
||||
$user = User::find(Auth::user()->id);
|
||||
|
|
@ -503,7 +523,7 @@ class WizardController extends Controller
|
|||
}*/
|
||||
if ($product && $product->active) {
|
||||
// set membership product
|
||||
$image = "";
|
||||
$image = '';
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
|
@ -523,7 +543,7 @@ class WizardController extends Controller
|
|||
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 = "";
|
||||
$image = '';
|
||||
if ($product_on_board->images->count()) {
|
||||
$image = $product_on_board->images->first()->slug;
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -570,18 +589,20 @@ class WizardController extends Controller
|
|||
// 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') {
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
|
|
@ -590,15 +611,15 @@ class WizardController extends Controller
|
|||
// remove file
|
||||
\Storage::disk('user')->delete($file->dir.$file->filename);
|
||||
$file->delete();
|
||||
\Session()->flash('alert-success', "Datei gelöscht");
|
||||
\Session()->flash('alert-success', 'Datei gelöscht');
|
||||
if ($identifier === 'business_license') {
|
||||
$user->wizard = 2;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_register', [2]));
|
||||
}
|
||||
}
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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,18 +29,25 @@ 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
|
||||
|
|
@ -48,14 +58,15 @@ class UserLevel extends Model
|
|||
'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,16 +77,19 @@ 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));
|
||||
}
|
||||
|
|
@ -83,11 +97,12 @@ class UserLevel extends Model
|
|||
public function getFormattedMargin()
|
||||
{
|
||||
if (! isset($this->attributes['margin'])) {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
if(\App::getLocale() === "en"){
|
||||
if (\App::getLocale() === 'en') {
|
||||
return number_format($this->attributes['margin'], 2, '.', ',');
|
||||
}
|
||||
|
||||
return number_format($this->attributes['margin'], 2, ',', '.');
|
||||
}
|
||||
|
||||
|
|
@ -101,6 +116,7 @@ class UserLevel extends Model
|
|||
if (! $trans || $trans == '') {
|
||||
return $this->{$key};
|
||||
}
|
||||
|
||||
return $trans;
|
||||
}
|
||||
|
||||
|
|
@ -114,10 +130,11 @@ class UserLevel extends Model
|
|||
|
||||
public function getTranNames()
|
||||
{
|
||||
$ret = "";
|
||||
$ret = '';
|
||||
foreach ((array) $this->trans_name as $value) {
|
||||
$ret .= $value.', ';
|
||||
}
|
||||
|
||||
return rtrim($ret, ', ');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Country;
|
||||
use App\Models\Product;
|
||||
use App\Models\Setting;
|
||||
use App\Services\UserMarign;
|
||||
use App\Services\UserService;
|
||||
use App\Services\Yard\Margin;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShippingPrice;
|
||||
use App\Services\Yard\Commission;
|
||||
use App\Services\Yard\Margin;
|
||||
use Gloudemans\Shoppingcart\Cart;
|
||||
use App\Services\Yard\MarginItems;
|
||||
use Illuminate\Support\Collection;
|
||||
use Gloudemans\Shoppingcart\CartItem;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/*
|
||||
|
||||
|
|
@ -32,31 +31,51 @@ public function setTaxRate($taxRate)
|
|||
class Yard extends Cart
|
||||
{
|
||||
private $shipping_price = 0;
|
||||
|
||||
private $shipping_price_net = 0;
|
||||
|
||||
private $shipping_tax_rate = 0;
|
||||
|
||||
private $shipping_tax = 0;
|
||||
|
||||
private $shipping_country_id = 0; // default de
|
||||
|
||||
private $shipping_is_for;
|
||||
|
||||
private $num_comp;
|
||||
|
||||
private $ysession;
|
||||
|
||||
private $yinstance;
|
||||
|
||||
private $shopping_data = [];
|
||||
|
||||
private $user;
|
||||
|
||||
private $use_payment_credit;
|
||||
|
||||
private $has_active_promotion;
|
||||
|
||||
private $reduce_payment_credit;
|
||||
|
||||
private $yard_commission;
|
||||
|
||||
private $yard_margin;
|
||||
|
||||
private $global_tax_rate = 0;
|
||||
|
||||
private $shipping_option; // pick_up//dhl_shipping
|
||||
|
||||
private $user_tax_free;
|
||||
|
||||
private $shipping_free;
|
||||
|
||||
private $user_reverse_charge;
|
||||
|
||||
private $user_country_id;
|
||||
|
||||
private $user_country;
|
||||
|
||||
private $events;
|
||||
|
||||
public function __construct(SessionManager $session, Dispatcher $events)
|
||||
|
|
@ -133,7 +152,6 @@ class Yard extends Cart
|
|||
|
||||
$this->events = $events;
|
||||
|
||||
|
||||
parent::__construct($session, $events);
|
||||
|
||||
if (gettype($this->shipping_country_id) !== 'object' && $this->shipping_country_id == 0) {
|
||||
|
|
@ -153,68 +171,83 @@ 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(){
|
||||
public function isQuickShipping()
|
||||
{
|
||||
if ($this->shipping_option === 'pick_up' && $this->totalWithShipping(2, '.', '') == 0.00) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isWithPayments(){
|
||||
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)) {
|
||||
return $content->get($key);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getShippingCountryName(){
|
||||
public function getShippingCountryName()
|
||||
{
|
||||
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
if ($shippingCountry && $shippingCountry->country) {
|
||||
return $shippingCountry->country->getLocated();
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getShippingCountryCountryId()
|
||||
{
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
if ($shippingCountry && $shippingCountry->country) {
|
||||
return $shippingCountry->country->id;
|
||||
}
|
||||
|
||||
return 1; // default DE
|
||||
}
|
||||
|
||||
|
|
@ -233,23 +266,28 @@ class Yard extends Cart
|
|||
if (is_null($this->ysession->get($this->yinstance))) {
|
||||
return new Collection([]);
|
||||
}
|
||||
|
||||
return $this->ysession->get($this->yinstance);
|
||||
}
|
||||
|
||||
public function getCartContent(){
|
||||
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') {
|
||||
return;
|
||||
|
|
@ -261,12 +299,15 @@ class Yard extends Cart
|
|||
|
||||
/* 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) {
|
||||
// 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;
|
||||
$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);
|
||||
|
|
@ -283,6 +324,7 @@ class Yard extends Cart
|
|||
} else {
|
||||
$yard_commission->price_net = $yard_commission->price_net + ($cartItem->qty * $price_net);
|
||||
}
|
||||
|
||||
return $yard_commission;
|
||||
}, $yard_commission);
|
||||
|
||||
|
|
@ -297,7 +339,7 @@ class Yard extends Cart
|
|||
// 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;
|
||||
|
|
@ -351,21 +393,27 @@ class Yard extends Cart
|
|||
// 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,7 +444,8 @@ 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);
|
||||
|
|
@ -408,7 +457,8 @@ 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,
|
||||
|
|
@ -442,43 +492,49 @@ class Yard extends Cart
|
|||
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(){
|
||||
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(){
|
||||
public function reducePaymentCredit()
|
||||
{
|
||||
if (! $this->reduce_payment_credit) {
|
||||
return false;
|
||||
}
|
||||
if ($this->has_active_promotion) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->getPaymentCredit();
|
||||
}
|
||||
|
||||
private function calculateShippingPrice(){
|
||||
private function calculateShippingPrice()
|
||||
{
|
||||
// keine Verandkosten
|
||||
if ($this->shipping_option && $this->shipping_option === 'pick_up') {
|
||||
$this->shipping_price = 0;
|
||||
|
|
@ -486,6 +542,7 @@ class Yard extends Cart
|
|||
$this->shipping_price_net = 0;
|
||||
$this->shipping_tax = 0;
|
||||
$this->putShippingPrices();
|
||||
|
||||
return;
|
||||
}
|
||||
// keine Verandkosten
|
||||
|
|
@ -495,6 +552,7 @@ class Yard extends Cart
|
|||
$this->shipping_price_net = 0;
|
||||
$this->shipping_tax = 0;
|
||||
$this->putShippingPrices();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -516,7 +574,7 @@ class Yard extends Cart
|
|||
if ($this->weight() == 0) {
|
||||
$shipping_price = $shipping->getShippingPricesBy($shipping_price_for)->first();
|
||||
if (! $shipping_price) {
|
||||
$shipping_price = new \App\Models\ShippingPrice();
|
||||
$shipping_price = new ShippingPrice;
|
||||
}
|
||||
$shipping_price->price = 0;
|
||||
$shipping_price->price_comp = 0;
|
||||
|
|
@ -527,7 +585,6 @@ class Yard extends Cart
|
|||
if (! $shipping_price) {
|
||||
$shipping_price = $this->shippingPriceByWeight($shipping->getShippingPricesBy($shipping_price_for), $this->weight());
|
||||
|
||||
|
||||
}
|
||||
// default
|
||||
if (! $shipping_price) {
|
||||
|
|
@ -539,11 +596,11 @@ class Yard extends Cart
|
|||
$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->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;
|
||||
}
|
||||
|
|
@ -557,7 +614,8 @@ class Yard extends Cart
|
|||
}
|
||||
}
|
||||
|
||||
public function preCalcuShippingPrice(){
|
||||
public function preCalcuShippingPrice()
|
||||
{
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
if (! $shippingCountry) {
|
||||
return false;
|
||||
|
|
@ -573,7 +631,7 @@ class Yard extends Cart
|
|||
if ($this->weight() == 0) {
|
||||
$shipping_price = $shipping->getShippingPricesBy($shipping_price_for)->first();
|
||||
if (! $shipping_price) {
|
||||
$shipping_price = new \App\Models\ShippingPrice();
|
||||
$shipping_price = new ShippingPrice;
|
||||
}
|
||||
$shipping_price->price = 0;
|
||||
} else {
|
||||
|
|
@ -592,11 +650,13 @@ class Yard extends Cart
|
|||
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,7 +664,8 @@ class Yard extends Cart
|
|||
$this->putYardExtra('shipping_price_net', $this->shipping_price_net);
|
||||
}
|
||||
|
||||
private function shippingPriceBySubTotal($prices, $total){
|
||||
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) {
|
||||
|
|
@ -612,10 +673,12 @@ class Yard extends Cart
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function shippingPriceByWeight($prices, $weight){
|
||||
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) {
|
||||
|
|
@ -623,6 +686,7 @@ class Yard extends Cart
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -641,6 +705,7 @@ class Yard extends Cart
|
|||
{
|
||||
return $this->numberFormat($this->shipping_price_net, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
//
|
||||
private function shippingTax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
|
|
@ -655,20 +720,20 @@ class Yard extends Cart
|
|||
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;
|
||||
$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;
|
||||
|
|
@ -681,16 +746,17 @@ class Yard extends Cart
|
|||
$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;
|
||||
$subtotal_shipping = $this->subtotalWithShipping(2, '.', '');
|
||||
$tax = $subtotal_shipping / 100 * $this->global_tax_rate;
|
||||
$total = ($subtotal_shipping + $tax);
|
||||
|
||||
return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
|
@ -708,6 +774,7 @@ class Yard extends Cart
|
|||
$rest = $PaymentCredit - $rest;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->numberFormat($rest, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
|
@ -725,6 +792,7 @@ class Yard extends Cart
|
|||
$total = $content->reduce(function ($total, CartItem $cartItem) {
|
||||
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,6 +814,7 @@ 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;
|
||||
}
|
||||
|
||||
|
|
@ -767,11 +837,10 @@ 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.
|
||||
*
|
||||
|
|
@ -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,7 +867,6 @@ class Yard extends Cart
|
|||
return $this->numberFormat($tax, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the subtotal (total - tax) of the items in the cart.
|
||||
*
|
||||
|
|
@ -812,19 +881,21 @@ 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) {
|
||||
$subTotal -= $this->yard_margin->net_discount;
|
||||
}
|
||||
|
||||
return $this->numberFormat($subTotal, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
||||
public function getCartItemByProduct($product_id, $set_price='with', $commission=true){
|
||||
public function getCartItemByProduct($product_id, $set_price = 'with', $commission = true)
|
||||
{
|
||||
if ($product = Product::find($product_id)) {
|
||||
$image = "";
|
||||
$image = '';
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
|
@ -856,14 +927,16 @@ class Yard extends Cart
|
|||
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,47 +955,59 @@ 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){
|
||||
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){
|
||||
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) {
|
||||
return $row->options->product_id;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFreeProductId(){
|
||||
public function getFreeProductId()
|
||||
{
|
||||
foreach ($this->content() as $row) {
|
||||
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) {
|
||||
|
|
@ -935,16 +1021,13 @@ class Yard extends Cart
|
|||
}
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Zwei Steuer-Flags an den Berater-Rollen:
|
||||
* - exclude_single_commission: Rollen (z. B. Barkunde 0 %) ziehen den produktseitigen
|
||||
* Kunden-Einzelrabatt (single_commission/value_commission) NICHT mehr ab.
|
||||
* - hide_registration: interne Rollen (z. B. Mitarbeiter) werden bei der Registrierung
|
||||
* und der Mitgliedschafts-Auswahl ausgeblendet, bleiben aber im Admin zuweisbar.
|
||||
* Default false => 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']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -59,6 +59,22 @@
|
|||
<em>Auch immer die Provision bei den Staffelpreisen eintragen!<br>Die Provision wird beim Käufer berechnet und nur ein Sponsor mit der Rolle wo diese Checkbox aktiv ist bekommt die Provison gutgeschrieben.</em>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-12">
|
||||
<label class="custom-control custom-checkbox m-2">
|
||||
{!! Form::checkbox('exclude_single_commission', 1, $value->exclude_single_commission, ['class'=>'custom-control-input']) !!}
|
||||
<span class="custom-control-label">Produktseitige Einzelprovision nicht abziehen</span>
|
||||
</label>
|
||||
<em>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.</em>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-12">
|
||||
<label class="custom-control custom-checkbox m-2">
|
||||
{!! Form::checkbox('hide_registration', 1, $value->hide_registration, ['class'=>'custom-control-input']) !!}
|
||||
<span class="custom-control-label">Nicht bei Registrierung/Mitgliedschaft anzeigen (interne Rolle)</span>
|
||||
</label>
|
||||
<em>Interne Rollen (z. B. Mitarbeiter) werden bei der Registrierung und der Mitgliedschafts-Auswahl ausgeblendet. Im Admin/Lead-Formular bleibt die Rolle zuweisbar.</em>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-12">
|
||||
<label class="custom-control custom-checkbox m-2">
|
||||
{!! Form::checkbox('payment_year', 1, $value->payment_year, ['class'=>'custom-control-input']) !!}
|
||||
|
|
|
|||
63
tests/Feature/UserLevelSingleCommissionTest.php
Normal file
63
tests/Feature/UserLevelSingleCommissionTest.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
use App\Models\UserLevel;
|
||||
use App\Services\Facade\Yard;
|
||||
use App\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
uses(TestCase::class, RefreshDatabase::class);
|
||||
|
||||
function commissionUser(bool $excludeSingleCommission): User
|
||||
{
|
||||
$level = UserLevel::create([
|
||||
'name' => $excludeSingleCommission ? 'Barkunde 0%' : 'Wiederverkäufer',
|
||||
'active' => true,
|
||||
'partner_provision' => false,
|
||||
'exclude_single_commission' => $excludeSingleCommission,
|
||||
'hide_registration' => false,
|
||||
]);
|
||||
|
||||
$user = User::query()->create([
|
||||
'email' => uniqid('cart_', true).'@test.example',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
$user->forceFill(['m_level' => $level->id])->save();
|
||||
|
||||
return $user->fresh();
|
||||
}
|
||||
|
||||
function cartWithSingleCommissionProduct(User $user)
|
||||
{
|
||||
$cart = Yard::instance('shopping');
|
||||
$cart->destroy();
|
||||
// price 119 brutto @ 19% => 100 netto; Produkt trägt 25% Kunden-Einzelrabatt
|
||||
$cart->add(1, 'Deocreme MINI', 1, 119, 19, [
|
||||
'image' => '',
|
||||
'slug' => 'deocreme-mini',
|
||||
'weight' => 0,
|
||||
'single_commission' => 1,
|
||||
'amount_commission' => 0,
|
||||
'value_commission' => 25,
|
||||
'partner_commission' => 0,
|
||||
]);
|
||||
$cart->setUser($user);
|
||||
$cart->calculateMargins();
|
||||
|
||||
return $cart;
|
||||
}
|
||||
|
||||
test('rolle mit exclude_single_commission zieht keinen produktseitigen einzelrabatt', function () {
|
||||
$cart = cartWithSingleCommissionProduct(commissionUser(true));
|
||||
|
||||
expect((float) $cart->getYardCommission()->single_value_commission)->toBe(0.0);
|
||||
expect((float) $cart->getYardMargin()->net_discount)->toBe(0.0);
|
||||
});
|
||||
|
||||
test('rolle ohne flag zieht den produktseitigen einzelrabatt weiterhin ab', function () {
|
||||
$cart = cartWithSingleCommissionProduct(commissionUser(false));
|
||||
|
||||
// 25% von 100 netto = 25
|
||||
expect((float) $cart->getYardCommission()->single_value_commission)->toBe(25.0);
|
||||
expect((float) $cart->getYardMargin()->net_discount)->toBe(25.0);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue