20-02-2026
This commit is contained in:
parent
a8b395e20d
commit
a00c42e770
252 changed files with 28785 additions and 8907 deletions
|
|
@ -4,14 +4,13 @@ namespace App\Http\Controllers\User;
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserAbo;
|
||||
use App\Models\UserAboItem;
|
||||
use App\Repositories\AboRepository;
|
||||
use App\Services\AboHelper;
|
||||
use App\Services\AboItemHistoryService;
|
||||
use App\Services\AboOrderCart;
|
||||
use App\Services\Shop;
|
||||
use App\Services\UserService;
|
||||
use App\User;
|
||||
use Request;
|
||||
use Yard;
|
||||
|
|
@ -41,7 +40,7 @@ class AboController extends Controller
|
|||
return view('user.abo.index', [
|
||||
'user_abos' => [],
|
||||
'view' => 'me',
|
||||
'isAdmin' => false
|
||||
'isAdmin' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +54,7 @@ class AboController extends Controller
|
|||
return view('user.abo.index', [
|
||||
'user_abos' => $user_abos,
|
||||
'view' => 'ot',
|
||||
'isAdmin' => false
|
||||
'isAdmin' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -63,22 +62,19 @@ class AboController extends Controller
|
|||
return view('user.abo.index', [
|
||||
'user_abos' => [],
|
||||
'view' => 'me',
|
||||
'isAdmin' => false
|
||||
'isAdmin' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function detail($view, $id)
|
||||
{
|
||||
$data = Request::all();
|
||||
$user_abo = UserAbo::findOrFail($id);
|
||||
|
||||
|
||||
$this->checkPermissions($view, $user_abo);
|
||||
|
||||
//init Yard
|
||||
// init Yard
|
||||
AboOrderCart::initYard($user_abo);
|
||||
//holt die aktuellen UserAccount Daten oder die Userdaten des Abo
|
||||
// holt die aktuellen UserAccount Daten oder die Userdaten des Abo
|
||||
$customer_detail = AboOrderCart::getCustomerDetail();
|
||||
AboOrderCart::makeOrderYard($user_abo);
|
||||
|
||||
|
|
@ -94,113 +90,129 @@ class AboController extends Controller
|
|||
'view' => $view,
|
||||
'comp_products' => $comp_products,
|
||||
];
|
||||
|
||||
return view('user.abo.detail', $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function update($view, $id)
|
||||
{
|
||||
$data = Request::all();
|
||||
$user_abo = UserAbo::findOrFail($id);
|
||||
|
||||
$this->checkPermissions($view, $user_abo);
|
||||
$isAddOnlyMode = AboHelper::isAddOnlyMode($user_abo, $view);
|
||||
|
||||
if (isset($data['action'])) {
|
||||
if ($data['action'] === 'abo_update_settings') {
|
||||
$user_abo = UserAbo::findOrFail($data['id']);
|
||||
$this->aboRepository->setModel($user_abo);
|
||||
$this->aboRepository->update($data);
|
||||
|
||||
return redirect(route('user_abos_detail', [$view, $id]));
|
||||
}
|
||||
|
||||
if (Request::ajax()) {
|
||||
$message = false;
|
||||
//addProduct
|
||||
// addProduct
|
||||
if ($data['action'] === 'addProduct') {
|
||||
if ($product = Product::find($data['product_id'])) {
|
||||
if ($UserAboItem = UserAboItem::where('user_abo_id', $user_abo->id)->where('product_id', $product->id)->where('comp', 0)->first()) {
|
||||
$qtyBefore = $UserAboItem->qty;
|
||||
$UserAboItem->qty = $UserAboItem->qty + 1;
|
||||
$UserAboItem->save();
|
||||
AboItemHistoryService::logProductAdded($user_abo, $UserAboItem, $qtyBefore, $view);
|
||||
} else {
|
||||
UserAboItem::create([
|
||||
$newItem = UserAboItem::create([
|
||||
'user_abo_id' => $user_abo->id,
|
||||
'product_id' => $product->id,
|
||||
'comp' => 0,
|
||||
'qty' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
AboItemHistoryService::logProductAdded($user_abo, $newItem, 0, $view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//updateCart
|
||||
// updateCart
|
||||
if ($data['action'] === 'updateCart') {
|
||||
//product_id | order_item_id | cart_order_id | qty
|
||||
// product_id | order_item_id | cart_order_id | qty
|
||||
if (isset($data['product_id']) && $product = Product::find($data['product_id'])) {
|
||||
if (isset($data['order_item_id']) && $UserAboItem = UserAboItem::find($data['order_item_id'])) {
|
||||
if (isset($data['qty'])) {
|
||||
$qtyBefore = $UserAboItem->qty;
|
||||
$qty = (int) $data['qty'];
|
||||
$qty = $qty < 1 ? 1 : $qty;
|
||||
$qty = $qty > 100 ? 100 : $qty;
|
||||
if ($isAddOnlyMode && $qty < $UserAboItem->qty) {
|
||||
$qty = $UserAboItem->qty;
|
||||
}
|
||||
$UserAboItem->qty = $qty;
|
||||
$UserAboItem->save();
|
||||
AboItemHistoryService::logQtyChanged($user_abo, $UserAboItem, $qtyBefore, $qty, $view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//removeFromCart
|
||||
// removeFromCart
|
||||
if ($data['action'] === 'removeFromCart') {
|
||||
if (!isset($data['product_id']) || !($product = Product::find($data['product_id']))) {
|
||||
if ($isAddOnlyMode) {
|
||||
return response()->json([
|
||||
'response' => false,
|
||||
'message' => __('abo.error_add_only_no_remove'),
|
||||
], 403);
|
||||
}
|
||||
if (! isset($data['product_id']) || ! ($product = Product::find($data['product_id']))) {
|
||||
$message = __('abo.product_not_found');
|
||||
}
|
||||
if (!isset($data['order_item_id']) || !($userAboItem = UserAboItem::find($data['order_item_id']))) {
|
||||
if (! isset($data['order_item_id']) || ! ($userAboItem = UserAboItem::find($data['order_item_id']))) {
|
||||
$message = __('abo.abo_item_not_found');
|
||||
}
|
||||
$has_basis_product = $this->check_need_basis_product($user_abo, $product, $data['order_item_id']);
|
||||
if (!$has_basis_product) {
|
||||
if (! $has_basis_product) {
|
||||
$message = __('abo.need_basis_product');
|
||||
}
|
||||
if (!$message) {
|
||||
|
||||
|
||||
if (! $message) {
|
||||
AboItemHistoryService::logProductRemoved($user_abo, $userAboItem, $view);
|
||||
$userAboItem->delete();
|
||||
$user_abo->refresh(); // Abo neu laden um die aktualisierten Items zu erhalten
|
||||
}
|
||||
}
|
||||
//updateCompProduct
|
||||
// updateCompProduct
|
||||
if ($data['action'] === 'updateCompProduct') {
|
||||
if ($UserAboItem = UserAboItem::where('user_abo_id', $user_abo->id)->where('comp', $data['comp_num'])->first()) {
|
||||
$oldProduct = $UserAboItem->product;
|
||||
$UserAboItem->product_id = $data['comp_product_id'];
|
||||
$UserAboItem->save();
|
||||
$UserAboItem->load('product');
|
||||
AboItemHistoryService::logCompProductChanged($user_abo, $UserAboItem, $oldProduct, $UserAboItem->product, $view);
|
||||
} else {
|
||||
UserAboItem::create([
|
||||
$newItem = UserAboItem::create([
|
||||
'user_abo_id' => $user_abo->id,
|
||||
'product_id' => $data['comp_product_id'],
|
||||
'comp' => $data['comp_num'],
|
||||
'qty' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
AboItemHistoryService::logProductAdded($user_abo, $newItem, 0, $view);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AboOrderCart::initYard($user_abo);
|
||||
AboOrderCart::makeOrderYard($user_abo); //reCalculateShippingPrice
|
||||
AboOrderCart::checkNumOfCompProducts($user_abo); //after reCalculateShippingPrice check it and remove or add comp product
|
||||
AboOrderCart::makeOrderYard($user_abo); // reCalculateShippingPrice
|
||||
AboOrderCart::checkNumOfCompProducts($user_abo); // after reCalculateShippingPrice check it and remove or add comp product
|
||||
|
||||
if ($user_abo->is_for === 'me') {
|
||||
$data['comp_products'] = Shop::getCompProducts('abo-me');
|
||||
}
|
||||
$error_message = $message ? $message : false;
|
||||
$html_cart = view("admin.abo._order_abo_show", ['user_abo' => $user_abo, 'error_message' => $error_message])->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
$html_cart = view('admin.abo._order_abo_show', ['user_abo' => $user_abo, 'error_message' => $error_message, 'add_only_mode' => $isAddOnlyMode])->render();
|
||||
$html_comp = view('user.order.comp_product', $data)->render();
|
||||
|
||||
$amount = $user_abo->getFormattedAmount();
|
||||
|
||||
// $html_total = view("user.homeparty.show_total_order", ['homeparty' => $homeparty])->render();
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_cart' => $html_cart, 'html_comp' => $html_comp, 'amount' => $amount]);
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_cart' => $html_cart, 'html_comp' => $html_comp, 'amount' => $amount]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -212,11 +224,14 @@ class AboController extends Controller
|
|||
return true;
|
||||
}
|
||||
|
||||
// Prüfe ob noch ein anderes Basis-Produkt vorhanden ist
|
||||
// Prüfe ob noch ein anderes Basis-Produkt vorhanden ist (nur reguläre Items, keine Comp-Produkte)
|
||||
foreach ($user_abo->user_abo_items as $user_abo_item) {
|
||||
if ($user_abo_item->id == $order_item_id) {
|
||||
continue;
|
||||
}
|
||||
if ($user_abo_item->comp) {
|
||||
continue;
|
||||
}
|
||||
if (AboHelper::getAboShowOn($user_abo_item->product) === 'base') {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -228,11 +243,11 @@ class AboController extends Controller
|
|||
public function datatable($user_abo_id)
|
||||
{
|
||||
$user_abo = UserAbo::findOrFail($user_abo_id);
|
||||
if (!$user_abo) {
|
||||
if (! $user_abo) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
//$user_abo->is_for === 'me'
|
||||
// $user_abo->is_for === 'me'
|
||||
|
||||
$show_on_ids = ['12', '13'];
|
||||
$query = Product::select('products.*')
|
||||
|
|
@ -250,45 +265,49 @@ class AboController extends Controller
|
|||
[$show_on_ids[0], isset($show_on_ids[1]) ? $show_on_ids[1] : $show_on_ids[0]]
|
||||
);
|
||||
|
||||
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('add_card', function (Product $product) use ($user_abo) {
|
||||
$ufactor = $user_abo->is_for === 'me' ? true : false;
|
||||
$tax_free = $user_abo->is_for === 'me' ? true : Yard::instance('shopping')->getUserTaxFree();
|
||||
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="' . $product->id . '">
|
||||
<strong>€ ' . $product->getFormattedPriceWith($tax_free, $ufactor, Yard::instance('shopping')->getUserCountry()) . '</strong> +<span class="ion ion-md-cart"></span>
|
||||
$tax_free = $user_abo->is_for === 'me' ? true : Yard::instance('shopping')->getUserTaxFree();
|
||||
|
||||
$price = $product->getFormattedPriceWith($tax_free, $ufactor, Yard::instance('shopping')->getUserCountry());
|
||||
|
||||
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="'.$product->id.'" data-product-name="'.e($product->getLang('name')).'" data-product-price="'.$price.' €">
|
||||
<strong>€ '.$price.'</strong> +<span class="ion ion-md-cart"></span>
|
||||
</button>';
|
||||
})
|
||||
->addColumn('picture', function (Product $product) {
|
||||
if (count($product->images)) {
|
||||
return '<img class="img-fluid img-extra" alt="" src="' . route('product_image', [$product->images->first()->slug]) . '">';
|
||||
return '<img class="img-fluid img-extra" alt="" src="'.route('product_image', [$product->images->first()->slug]).'">';
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
})
|
||||
->addColumn('name', function (Product $product) use ($user_abo) {
|
||||
return '<strong>' . $product->getLang('name') . '</strong><br>' . get_abo_type_badge_by_product($product);
|
||||
->addColumn('name', function (Product $product) {
|
||||
return '<strong>'.$product->getLang('name').'</strong><br>'.get_abo_type_badge_by_product($product);
|
||||
})
|
||||
->addColumn('points', function (Product $product) use ($user_abo) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPoints() . '</span>';
|
||||
->addColumn('points', function (Product $product) {
|
||||
return '<span class="no-line-break">'.$product->getFormattedPoints().'</span>';
|
||||
})
|
||||
->addColumn('price_net', function (Product $product) use ($user_abo) {
|
||||
$ufactor = $user_abo->is_for === 'me' ? true : false;
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(true, $ufactor, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, $ufactor, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('price_gross', function (Product $product) use ($user_abo) {
|
||||
$ufactor = $user_abo->is_for === 'me' ? true : false;
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(false, $ufactor, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, $ufactor, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('action', function (Product $product) {
|
||||
return '<button class="btn btn-default btn-sm icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="' . $product->id . '" data-route="' . route('modal_load') . '"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="'.$product->id.'" data-route="'.route('modal_load').'"
|
||||
data-action="user-order-show-product" data-view="customer"><i class="ion ion-md-eye"></i></button>';
|
||||
})
|
||||
->filterColumn('product', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->where('name', 'LIKE', '%' . $keyword . '%');
|
||||
if ($keyword != '') {
|
||||
$query->where('name', 'LIKE', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->orderColumn('name', 'name $1')
|
||||
|
|
@ -304,20 +323,26 @@ class AboController extends Controller
|
|||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function checkPermissions($view, $user_abo)
|
||||
{
|
||||
\Log::info('checkPermissions', ['view' => $view, 'user_abo' => $user_abo]);
|
||||
$user = \Auth::user();
|
||||
|
||||
// Admins dürfen alle Abos bearbeiten
|
||||
if ($user && $user->isAdmin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($view === 'me' && $user_abo->is_for !== 'me') {
|
||||
abort(403, 'Unauthorized action. Is not for me');
|
||||
}
|
||||
if ($view === 'ot' && $user_abo->is_for !== 'ot') {
|
||||
abort(403, 'Unauthorized action. Is not your customer');
|
||||
}
|
||||
if ($view === 'me' && $user_abo->user_id !== \Auth::user()->id) {
|
||||
if ($view === 'me' && $user_abo->user_id !== $user->id) {
|
||||
abort(403, 'Unauthorized action. Is not my abo');
|
||||
}
|
||||
if ($view === 'ot' && $user_abo->member_id !== \Auth::user()->id) {
|
||||
if ($view === 'ot' && $user_abo->member_id !== $user->id) {
|
||||
abort(403, 'Unauthorized action. Is not my customer abo');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,23 +2,22 @@
|
|||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use Auth;
|
||||
use Util;
|
||||
use Yard;
|
||||
use Carbon;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\MailInfo;
|
||||
use App\Models\Product;
|
||||
use App\Services\Payment;
|
||||
use App\Models\UserHistory;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Services\UserService;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\UserHistory;
|
||||
use App\Services\Payment;
|
||||
use App\Services\UserService;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Carbon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
use Request;
|
||||
use Util;
|
||||
use Yard;
|
||||
|
||||
class MembershipController extends Controller
|
||||
{
|
||||
|
|
@ -32,19 +31,18 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
$userShoppingOrders = ShoppingOrder::with('shopping_user', 'shopping_payments')->select('shopping_orders.*')
|
||||
->where('auth_user_id', '=', $user->id)
|
||||
->where('txaction', '!=', NULL)
|
||||
->where('txaction', '!=', null)
|
||||
->whereIn('payment_for', [1, 2])
|
||||
->orderBy('created_at', 'DESC')
|
||||
->get();
|
||||
|
|
@ -52,34 +50,33 @@ class MembershipController extends Controller
|
|||
$userHistoryPaymentOrder = null;
|
||||
$userHistoryUpgradeOrder = null;
|
||||
|
||||
/* Bezhalung ist nur 29 Tage vor ablauf möglich */
|
||||
/* Bezhalung ist nur 29 Tage vor ablauf möglich */
|
||||
/* isRenewalAccount payment_account date - config('mivita.renewal_days') Vertragsverlängerung */
|
||||
if($user->isRenewalAccount()){
|
||||
//Acount ist noch nicht verlängert / bezahlt
|
||||
if ($user->isRenewalAccount()) {
|
||||
// Acount ist noch nicht verlängert / bezahlt
|
||||
if ($user->payment_account) {
|
||||
//Die Order muss größer als das Datum sein.
|
||||
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days')+1).' days');
|
||||
// Die Order muss größer als das Datum sein.
|
||||
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days') + 1).' days');
|
||||
$userHistoryPaymentOrder = UserHistory::whereUserId($user->id)->whereAction('payment_order')->where('created_at', '>=', $payment_greaterThan)->get()->last();
|
||||
}
|
||||
}
|
||||
if($user->isActiveAccount() && !$user->isActiveShop()){
|
||||
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days')+1).' days');
|
||||
if ($user->isActiveAccount() && ! $user->isActiveShop()) {
|
||||
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days') + 1).' days');
|
||||
$userHistoryUpgradeOrder = UserHistory::whereUserId($user->id)->whereAction('upgrade_order')->where('created_at', '>=', $payment_greaterThan)->get()->last();
|
||||
|
||||
}
|
||||
$userHistoryDeleteMembership = UserHistory::whereUserId($user->id)->whereAction('delete_membership')->whereStatus(50)->get()->last();
|
||||
|
||||
|
||||
$shipping_country_id = $this->checkShoppingCountry($user);
|
||||
if(!$shipping_country_id){
|
||||
if (! $shipping_country_id) {
|
||||
abort(403, __('validation.custom.shipping_not_found'));
|
||||
}
|
||||
|
||||
UserService::checkUserTaxShippingCountry($user, $shipping_country_id);
|
||||
|
||||
|
||||
$data = [
|
||||
'user' => $user,
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'upgrade' => Product::where('active', true)->whereJsonContains('show_on', '8')->where('identifier', 'upgrade')->get(),
|
||||
'diff_months' => $diff_months,
|
||||
'userHistoryPaymentOrder' => $userHistoryPaymentOrder,
|
||||
|
|
@ -88,86 +85,90 @@ class MembershipController extends Controller
|
|||
'yard_info' => UserService::getYardInfo(),
|
||||
'userShoppingOrders' => $userShoppingOrders,
|
||||
];
|
||||
|
||||
return view('user.membership.index', $data);
|
||||
|
||||
}
|
||||
|
||||
private function checkShoppingCountry($user ){
|
||||
private function checkShoppingCountry($user)
|
||||
{
|
||||
|
||||
$country_id = null;
|
||||
if($user->account->same_as_billing){
|
||||
if ($user->account->same_as_billing) {
|
||||
$country_id = $user->account->country_id;
|
||||
}else{
|
||||
} else {
|
||||
$country_id = $user->account->shipping_country_id;
|
||||
}
|
||||
if($country_id){
|
||||
if($shipping_country = ShippingCountry::whereCountryId($country_id)->first()){
|
||||
if ($country_id) {
|
||||
if ($shipping_country = ShippingCountry::whereCountryId($country_id)->first()) {
|
||||
return $shipping_country->id;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function storePayment($action){
|
||||
|
||||
public function storePayment($action)
|
||||
{
|
||||
|
||||
$data = Request::all();
|
||||
|
||||
//#### remove_abo
|
||||
if($action === "remove_abo"){
|
||||
if(Request::get('abo_options_remove')){
|
||||
// #### remove_abo
|
||||
if ($action === 'remove_abo') {
|
||||
if (Request::get('abo_options_remove')) {
|
||||
$user = User::find(Auth::user()->id);
|
||||
$user->abo_options = false;
|
||||
$user->save();
|
||||
$user->account->payment_data = null;
|
||||
$user->account->save();
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'abo_options_remove', 'status'=>10]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => 'abo_options_remove', 'status' => 10]);
|
||||
\Session()->flash('alert-success', __('msg.abo_deaktivert'));
|
||||
|
||||
return back();
|
||||
}
|
||||
\Session()->flash('alert-error', __('msg.error_checkbox_not_confirm'));
|
||||
|
||||
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 = false; //true Abo Option deaktivert
|
||||
$user->abo_options = false; //true Abo Option deaktivert
|
||||
if (Request::get('abo_options')) {
|
||||
$showAboOptions = false; // true Abo Option deaktivert
|
||||
$user->abo_options = false; // true Abo Option deaktivert
|
||||
$user->save();
|
||||
}
|
||||
|
||||
$shipping_country_id = $this->checkShoppingCountry($user);
|
||||
if(!$shipping_country_id){
|
||||
if (! $shipping_country_id) {
|
||||
abort(403, __('validation.custom.shipping_not_found'));
|
||||
}
|
||||
|
||||
|
||||
UserService::checkUserTaxShippingCountry($user, $shipping_country_id);
|
||||
Yard::instance('shopping')->setUserPriceInfos(UserService::getYardInfo());
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id);
|
||||
|
||||
|
||||
if($product && $product->active){
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
if ($product && $product->active) {
|
||||
$image = '';
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$qty = Request::get('qty') ? Request::get('qty') : 1;
|
||||
$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, 'show_on' => $product->show_on]);
|
||||
if(\App\Services\UserService::getTaxFree()){
|
||||
$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, 'no_free_shipping' => $product->no_free_shipping, 'show_on' => $product->show_on]);
|
||||
if (\App\Services\UserService::getTaxFree()) {
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}else{
|
||||
} else {
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(\App\Services\UserService::$user_country));
|
||||
}
|
||||
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
} while (ShoppingInstance::where('identifier', $identifier)->count());
|
||||
|
||||
$data = [];
|
||||
$data['is_from'] = 'membership';
|
||||
|
|
@ -176,9 +177,9 @@ class MembershipController extends Controller
|
|||
|
||||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => 1, //is first faker shop for nuy intern
|
||||
'user_shop_id' => 1, // is first faker shop for nuy intern
|
||||
'auth_user_id' => Auth::user()->id,
|
||||
'payment' => 3, //Berater Membership
|
||||
'payment' => 3, // Berater Membership
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
|
|
@ -187,54 +188,59 @@ class MembershipController extends Controller
|
|||
|
||||
]);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
//add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>1, 'product_id'=>$product->id, 'identifier'=>$identifier, 'abo_options'=>$showAboOptions]);
|
||||
//$path = str_replace('http', 'https', $path);
|
||||
// add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier' => $identifier]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => $action, 'status' => 1, 'product_id' => $product->id, 'identifier' => $identifier, 'abo_options' => $showAboOptions]);
|
||||
|
||||
// $path = str_replace('http', 'https', $path);
|
||||
return redirect()->secure($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($action === "change_order"){
|
||||
if(Request::get('switchers-package-wizard')){
|
||||
if ($action === 'change_order') {
|
||||
if (Request::get('switchers-package-wizard')) {
|
||||
$user = User::find(Auth::user()->id);
|
||||
$product = Product::find(Request::get('switchers-package-wizard'));
|
||||
if($user->payment_order_id == $product->id){
|
||||
if ($user->payment_order_id == $product->id) {
|
||||
\Session()->flash('alert-success', __('msg.no_change_made'));
|
||||
|
||||
return back();
|
||||
}
|
||||
if($product && $product->active){
|
||||
if ($product && $product->active) {
|
||||
$user->payment_order_id = $product->id;
|
||||
$user->save();
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>10, 'product_id'=>$product->id]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => $action, 'status' => 10, 'product_id' => $product->id]);
|
||||
\Session()->flash('alert-success', __('msg.booked_package_has_been_changed'));
|
||||
|
||||
return back();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if($action === "delete_membership"){
|
||||
if(Request::get('delete_membership_mivita')){
|
||||
//TODO
|
||||
if ($action === 'delete_membership') {
|
||||
if (Request::get('delete_membership_mivita')) {
|
||||
// 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]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => $action, 'status' => 50]);
|
||||
\Session()->flash('alert-success', __('msg.cancel_membership_is_requested'));
|
||||
|
||||
return back();
|
||||
}
|
||||
\Session()->flash('alert-error', __('msg.error_checkbox_not_confirm'));
|
||||
|
||||
return back();
|
||||
|
||||
}
|
||||
\Session()->flash('alert-error', __('msg.error_checkbox_not_confirm'));
|
||||
|
||||
return back();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,15 +11,14 @@ use App\Models\ShoppingOrder;
|
|||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserHistory;
|
||||
use App\Services\AboHelper;
|
||||
use App\Services\MyLog;
|
||||
use App\Services\OrderPaymentService;
|
||||
use App\Services\Payment;
|
||||
use App\Services\Shop;
|
||||
use App\Services\UserService;
|
||||
use App\Services\Util;
|
||||
use App\Services\MyLog;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request as IlluminateRequest;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Request;
|
||||
|
|
@ -68,20 +67,20 @@ class OrderController extends Controller
|
|||
$query = ShoppingOrder::with('shopping_user', 'shopping_payments')
|
||||
->select('shopping_orders.*')
|
||||
->where('auth_user_id', '=', $user->id)
|
||||
->where('txaction', '!=', NULL);
|
||||
->where('txaction', '!=', null);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<a href="' . route('user_order_detail', [$ShoppingOrder->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
return '<a href="'.route('user_order_detail', [$ShoppingOrder->id]).'" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->created_at->format("d.m.Y");
|
||||
return $ShoppingOrder->created_at->format('d.m.Y');
|
||||
})
|
||||
->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getShoppingOrderBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="no-line-break">' . $ShoppingOrder->getFormattedTotalShipping() . " €</span>";
|
||||
return '<span class="no-line-break">'.$ShoppingOrder->getFormattedTotalShipping().' €</span>';
|
||||
})
|
||||
->addColumn('payment', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('getPaymentType');
|
||||
|
|
@ -89,21 +88,22 @@ class OrderController extends Controller
|
|||
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
|
||||
if ($ShoppingOrder->payment_for === 8) {
|
||||
return '<button type="button" class="btn btn-xs btn-info btn-round" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="' . $ShoppingOrder->id . '"
|
||||
data-id="'.$ShoppingOrder->id.'"
|
||||
data-action="shop-user-order-shipping-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="user"
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-eye"></span></button>';
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-eye"></span></button>';
|
||||
}
|
||||
return '<span class="badge badge-pill badge-' . $ShoppingOrder->getShippedColor() . '">' . $ShoppingOrder->getShippedType() . '</span>';
|
||||
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>';
|
||||
})
|
||||
->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getPaymentForBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="' . route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']) . '" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="' . route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']) . '" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
})
|
||||
->addColumn('reference', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('reference');
|
||||
|
|
@ -130,16 +130,18 @@ class OrderController extends Controller
|
|||
$shopping_user = Shop::checkShoppingUser($id, $user);
|
||||
$delivery_id = $shopping_user->id;
|
||||
|
||||
if (!Shop::checkShoppingCountry($for, $delivery_id) && !\Session()->has('custom-error')) {
|
||||
if (! Shop::checkShoppingCountry($for, $delivery_id) && ! \Session()->has('custom-error')) {
|
||||
$country = Shop::getDeliveryCountry($for, $delivery_id);
|
||||
\Session()->flash('custom-error', $country . ": " . __('validation.custom.shipping_not_found'));
|
||||
\Session()->flash('custom-error', $country.': '.__('validation.custom.shipping_not_found'));
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping country not found for user #{$user->id}, country: {$country}");
|
||||
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
|
||||
if ($for === 'abo-ot-customer') {
|
||||
if (AboHelper::hasAboByEmail($shopping_user->billing_email) && !\Session()->has('custom-error')) {
|
||||
if (AboHelper::hasAboByEmail($shopping_user->billing_email) && ! \Session()->has('custom-error')) {
|
||||
\Session()->flash('custom-error', __('abo.error_email_has_abo', ['email' => $shopping_user->billing_email]));
|
||||
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
}
|
||||
|
|
@ -150,6 +152,7 @@ class OrderController extends Controller
|
|||
if (strpos(Request::get('switchers-radio-is-for'), 'ot') !== false) {
|
||||
$delivery_id = $id;
|
||||
}
|
||||
|
||||
return redirect(route('user_order_my_list', [Request::get('switchers-radio-is-for'), $delivery_id]));
|
||||
}
|
||||
|
||||
|
|
@ -183,10 +186,11 @@ class OrderController extends Controller
|
|||
UserService::initCustomerYard($shopping_user, $for);
|
||||
} else {
|
||||
$shipping_country_id = Shop::checkShoppingCountry($for, $id);
|
||||
if (!$shipping_country_id) {
|
||||
if (! $shipping_country_id) {
|
||||
$country = Shop::getDeliveryCountry($for, $id);
|
||||
\Session()->flash('custom-error', $country . ": " . __('validation.custom.shipping_not_found'));
|
||||
\Session()->flash('custom-error', $country.': '.__('validation.custom.shipping_not_found'));
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Shipping country not found for user #{$user->id}, country: {$country}");
|
||||
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
UserService::initUserYard($user, $shipping_country_id, $for);
|
||||
|
|
@ -221,7 +225,6 @@ class OrderController extends Controller
|
|||
];
|
||||
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
|
|
@ -229,23 +232,23 @@ class OrderController extends Controller
|
|||
try {
|
||||
$this->checkSendYardForPayment($data, $id);
|
||||
} catch (\Exception $e) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Error checking yard for payment: " . $e->getMessage(), [
|
||||
Log::channel(self::LOG_CHANNEL)->error('Error checking yard for payment: '.$e->getMessage(), [
|
||||
'user_id' => $user->id,
|
||||
'for' => $for,
|
||||
'id' => $id
|
||||
'id' => $id,
|
||||
]);
|
||||
return back()->with('error', $e->getMessage());
|
||||
|
||||
return back()->withErrors(['error' => $e->getMessage()])->withInput(Request::all());
|
||||
}
|
||||
|
||||
if (Yard::instance('shopping')->getNumComp() > 0) {
|
||||
if (!isset($data['switchers-comp-product'])) {
|
||||
if (! isset($data['switchers-comp-product'])) {
|
||||
$validator->errors()->add('switchers-comp-product', __('msg.please_select_compensation_product'));
|
||||
} else if (!is_array($data['switchers-comp-product'])) {
|
||||
} elseif (! is_array($data['switchers-comp-product'])) {
|
||||
$validator->errors()->add('switchers-comp-product', __('msg.please_select_compensation_product'));
|
||||
} else if (count($data['switchers-comp-product']) !== Yard::instance('shopping')->getNumComp()) {
|
||||
} elseif (count($data['switchers-comp-product']) !== Yard::instance('shopping')->getNumComp()) {
|
||||
$validator->errors()->add('switchers-comp-product', __('mdg.please_select_count_compensation_products', ['count' => Yard::instance('shopping')->getNumComp()]));
|
||||
}
|
||||
|
||||
if ($validator->errors()->count()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
|
|
@ -268,7 +271,6 @@ class OrderController extends Controller
|
|||
// Remove unnecessary data
|
||||
unset($data['quantity']);
|
||||
unset($data['_token']);
|
||||
|
||||
if ($for === 'ot-customer' || $for === 'abo-ot-customer') {
|
||||
return $this->processCustomerPayment($user, $identifier, $data, $id, $for);
|
||||
} else {
|
||||
|
|
@ -281,13 +283,14 @@ class OrderController extends Controller
|
|||
*/
|
||||
private function processCustomerPayment($user, $identifier, $data, $id, $for)
|
||||
{
|
||||
$shopping_user = ShoppingUser::find($id);
|
||||
$shopping_instance = ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => $user->shop->id,
|
||||
'payment' => 6, // Berater Shop to Customer Shop
|
||||
'subdomain' => $user->shop->getSubdomain(),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'language' => $shopping_user->getLocale(), // hier wird die Sprache des Kunden verwendet
|
||||
'amount' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
|
||||
'status' => 0,
|
||||
'shopping_user_id' => $id,
|
||||
|
|
@ -302,9 +305,9 @@ class OrderController extends Controller
|
|||
try {
|
||||
$this->customPaymentSendMail($user, $identifier, $yard_shopping_items, $data);
|
||||
} catch (\Exception $e) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Failed to send custom payment email: " . $e->getMessage(), [
|
||||
Log::channel(self::LOG_CHANNEL)->error('Failed to send custom payment email: '.$e->getMessage(), [
|
||||
'identifier' => $identifier,
|
||||
'user_id' => $user->id
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -314,7 +317,7 @@ class OrderController extends Controller
|
|||
'status' => 1,
|
||||
'product_id' => null,
|
||||
'identifier' => $identifier,
|
||||
'is_abo' => $data['is_abo']
|
||||
'is_abo' => $data['is_abo'],
|
||||
]);
|
||||
|
||||
return redirect(route('user_order_my_custom_payment', ['identifier' => $identifier]));
|
||||
|
|
@ -333,7 +336,7 @@ class OrderController extends Controller
|
|||
'payment' => 2, // Berater Shop
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'language' => \App::getLocale(), // das ist richtig, hier wird die App-Locale verwendet da es vom user kommt
|
||||
'amount' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
|
||||
'status' => 0,
|
||||
'shopping_user_id' => $id,
|
||||
|
|
@ -349,10 +352,11 @@ class OrderController extends Controller
|
|||
'status' => 1,
|
||||
'product_id' => null,
|
||||
'identifier' => $identifier,
|
||||
'is_abo' => $data['is_abo']
|
||||
'is_abo' => $data['is_abo'],
|
||||
]);
|
||||
|
||||
$path = route('checkout.checkout_card', ['identifier' => $identifier]);
|
||||
|
||||
return redirect()->secure($path);
|
||||
}
|
||||
|
||||
|
|
@ -369,68 +373,68 @@ class OrderController extends Controller
|
|||
}
|
||||
|
||||
$shipping_country_id = Shop::checkShoppingCountry($data['shipping_is_for'], $id);
|
||||
if (!$shipping_country_id) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
if (! $shipping_country_id) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier
|
||||
'yard_identifier' => $identifier,
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'no shipping_country_id found | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping country not found", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'no shipping_country_id found | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping country not found', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_country_was_not_found'));
|
||||
}
|
||||
|
||||
// Must be the same shipping country
|
||||
if ($shipping_country_id != Yard::instance('shopping')->getShippingCountryId()) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_country_id,
|
||||
'actual' => Yard::instance('shopping')->getShippingCountryId()
|
||||
'actual' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'shipping_country_id is not the same from Yard | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping country mismatch", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'shipping_country_id is not the same from Yard | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping country mismatch', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_country_was_not_correctly'));
|
||||
}
|
||||
|
||||
if ($data['shipping_is_for'] !== 'ot-customer') {
|
||||
if (Yard::instance('shopping')->shipping_free) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier
|
||||
'yard_identifier' => $identifier,
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard can by not shipping_free | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Yard cannot be shipping free", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'Yard can by not shipping_free | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Yard cannot be shipping free', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shopping_cart_was_shipping_free'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['shipping_is_for'] === 'ot-customer') {
|
||||
if (!$user->shop) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
if (! $user->shop) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier
|
||||
'yard_identifier' => $identifier,
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'User has no Shop for an User to Customer order| Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("User has no shop for customer order", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'User has no Shop for an User to Customer order| Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('User has no shop for customer order', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shopping_cart_was_not_user_shop'));
|
||||
}
|
||||
|
|
@ -438,107 +442,130 @@ class OrderController extends Controller
|
|||
|
||||
$shipping_price = Shop::getShippingPriceByShippingCountryId($shipping_country_id, Yard::instance('shopping')->weight());
|
||||
|
||||
// For other and has weight - check
|
||||
// For other and has weight - check
|
||||
if (strpos($data['shipping_is_for'], 'ot') !== false && $data['shipping_is_for'] !== 'ot-customer' && Yard::instance('shopping')->weight() > 0) {
|
||||
if (!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'weight' => Yard::instance('shopping')->weight()
|
||||
];
|
||||
// Prüfe ob Versandkostenfreiheit durch Freigrenze legitimiert ist
|
||||
$shipping_free = Yard::instance('shopping')->getShippingFree();
|
||||
$total = Yard::instance('shopping')->total(2, '.', '');
|
||||
$isFreeDueToThreshold = $shipping_free && $total >= $shipping_free && Yard::instance('shopping')->weightByFreeShipping() == 0;
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is 0 | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price cannot be zero for order with weight", $logData);
|
||||
if (! Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
|
||||
// Nur Fehler werfen, wenn Versandpreis 0 NICHT durch Freigrenze legitimiert ist
|
||||
if (! $isFreeDueToThreshold) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'weight' => Yard::instance('shopping')->weight(),
|
||||
'total' => $total,
|
||||
'shipping_free' => $shipping_free,
|
||||
];
|
||||
|
||||
throw new \Exception(__('msg.shipping_cost_cannot_be_0'));
|
||||
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is 0 | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping price cannot be zero for order with weight', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_cost_cannot_be_0'));
|
||||
}
|
||||
}
|
||||
|
||||
if (Yard::instance('shopping')->getShippingPrice() != $shipping_price->price) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
// Preisvergleich nur durchführen, wenn NICHT versandkostenfrei durch Freigrenze
|
||||
if (! $isFreeDueToThreshold && Yard::instance('shopping')->getShippingPrice() != $shipping_price->price) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_price->price,
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice()
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice(),
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is not the same from shipping_price | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price mismatch", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping price mismatch', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_costs_were_not_calculated_correctly'));
|
||||
}
|
||||
}
|
||||
|
||||
if (($data['shipping_is_for'] == 'me' || $data['shipping_is_for'] == 'abo-me') && Yard::instance('shopping')->weight() > 0) {
|
||||
if (!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'weight' => Yard::instance('shopping')->weight()
|
||||
];
|
||||
// Prüfe ob Versandkostenfreiheit durch Freigrenze legitimiert ist
|
||||
$shipping_free = Yard::instance('shopping')->getShippingFree();
|
||||
$total = Yard::instance('shopping')->total(2, '.', '');
|
||||
$isFreeDueToThreshold = $shipping_free && $total >= $shipping_free && Yard::instance('shopping')->weightByFreeShipping() == 0;
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is 0 | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price cannot be zero for personal order with weight", $logData);
|
||||
if (! Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
|
||||
// Nur Fehler werfen, wenn Versandpreis 0 NICHT durch Freigrenze legitimiert ist
|
||||
if (! $isFreeDueToThreshold) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'weight' => Yard::instance('shopping')->weight(),
|
||||
'total' => $total,
|
||||
'shipping_free' => $shipping_free,
|
||||
];
|
||||
|
||||
throw new \Exception(__('msg.shipping_cost_cannot_be_0'));
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is 0 | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping price cannot be zero for personal order with weight', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_cost_cannot_be_0'));
|
||||
}
|
||||
}
|
||||
|
||||
if (Shop::isCompProducts($data['shipping_is_for'])) {
|
||||
if (Yard::instance('shopping')->getShippingPrice() != $shipping_price->price_comp) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
// Preisvergleich nur durchführen, wenn NICHT versandkostenfrei durch Freigrenze
|
||||
if (! $isFreeDueToThreshold && Yard::instance('shopping')->getShippingPrice() != $shipping_price->price_comp) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_price->price_comp,
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice()
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice(),
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price with comp products | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price mismatch for personal order", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price with comp products | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping price mismatch for personal order', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_costs_were_not_calculated_correctly'));
|
||||
}
|
||||
|
||||
if (Yard::instance('shopping')->getNumComp() != $shipping_price->num_comp) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_price->num_comp,
|
||||
'actual' => Yard::instance('shopping')->getNumComp()
|
||||
'actual' => Yard::instance('shopping')->getNumComp(),
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard num_comp is not correct | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Compensation product count mismatch", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'Yard num_comp is not correct | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Compensation product count mismatch', $logData);
|
||||
|
||||
throw new \Exception(__('msg.compensation_products_cannot_be_0'));
|
||||
}
|
||||
} else {
|
||||
if (Yard::instance('shopping')->getShippingPrice() != $shipping_price->price) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
// Preisvergleich nur durchführen, wenn NICHT versandkostenfrei durch Freigrenze
|
||||
if (! $isFreeDueToThreshold && Yard::instance('shopping')->getShippingPrice() != $shipping_price->price) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_price->price,
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice()
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice(),
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price without comp products | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price mismatch for personal order", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price without comp products | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping price mismatch for personal order', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_costs_were_not_calculated_correctly'));
|
||||
}
|
||||
|
|
@ -593,15 +620,16 @@ class OrderController extends Controller
|
|||
$cartItem = Yard::instance('shopping')->getCartItemByProduct($product->id);
|
||||
$qty = isset($cartItem->qty) ? $cartItem->qty : 0;
|
||||
$rowId = isset($cartItem->rowId) ? $cartItem->rowId : '';
|
||||
return '<strong>' . $product->getLang('name') . '</strong><br>
|
||||
|
||||
return '<strong>'.$product->getLang('name').'</strong><br>
|
||||
<div class="no-line-break input-group-min-w">
|
||||
<div class="input-group d-inline-flex w-auto">
|
||||
<span class="input-group-prepend">
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra remove-product-basket" data-row-id="' . $rowId . '" data-product-id="' . $product->id . '">-</button>
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra remove-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">-</button>
|
||||
</span>
|
||||
<input type="text" class="form-control text-center input-extra table-input-event-onchange" name="product_qty_' . $product->id . '" data-row-id="' . $rowId . '" data-product-id="' . $product->id . '" value="' . $qty . '">
|
||||
<input type="text" class="form-control text-center input-extra table-input-event-onchange" name="product_qty_'.$product->id.'" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'" value="'.$qty.'">
|
||||
<span class="input-group-append">
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra add-product-basket" data-row-id="' . $rowId . '" data-product-id="' . $product->id . '">+</button>
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra add-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">+</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>';
|
||||
|
|
@ -611,39 +639,40 @@ class OrderController extends Controller
|
|||
})
|
||||
->addColumn('picture', function (Product $product) {
|
||||
if (count($product->images)) {
|
||||
return '<img class="img-fluid img-extra" alt="" src="' . route('product_image', [$product->images->first()->slug]) . '">';
|
||||
return '<img class="img-fluid img-extra" alt="" src="'.route('product_image', [$product->images->first()->slug]).'">';
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
})
|
||||
->addColumn('points', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPoints() . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPoints().'</span>';
|
||||
})
|
||||
->addColumn('price_net', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(true, true, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, true, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('price_gross', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(false, true, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(false, true, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, true, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, true, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('price_vk_gross', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(false, false, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(false, false, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, false, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, false, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('customer_price_net', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(true, false, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, false, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, false, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, false, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('customer_price_gross', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(false, false, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(false, false, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, false, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, false, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('my_commission_net', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(true, false, Yard::instance('shopping')->getUserCountry(), true) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, false, Yard::instance('shopping')->getUserCountry(), true) . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, false, Yard::instance('shopping')->getUserCountry(), true).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, false, Yard::instance('shopping')->getUserCountry(), true).'</span>';
|
||||
})
|
||||
->addColumn('action', function (Product $product) {
|
||||
return '<button class="btn btn-default btn-sm icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="' . $product->id . '" data-route="' . route('modal_load') . '"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="'.$product->id.'" data-route="'.route('modal_load').'"
|
||||
data-action="user-order-show-product" data-view="customer"><i class="ion ion-md-eye"></i></button>';
|
||||
})
|
||||
->filterColumn('product', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->where('name', 'LIKE', '%' . $keyword . '%');
|
||||
if ($keyword != '') {
|
||||
$query->where('name', 'LIKE', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->orderColumn('name', 'name $1')
|
||||
|
|
@ -668,8 +697,9 @@ class OrderController extends Controller
|
|||
*/
|
||||
public function performRequest()
|
||||
{
|
||||
if (!Request::ajax()) {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Non-AJAX request to performRequest method");
|
||||
if (! Request::ajax()) {
|
||||
Log::channel(self::LOG_CHANNEL)->warning('Non-AJAX request to performRequest method');
|
||||
|
||||
return response()->json(['response' => false, 'message' => 'Only AJAX requests are allowed']);
|
||||
}
|
||||
|
||||
|
|
@ -678,9 +708,9 @@ class OrderController extends Controller
|
|||
$data['for'] = $is_for;
|
||||
$data['comp_products'] = Shop::getCompProducts($is_for);
|
||||
|
||||
Log::channel(self::LOG_CHANNEL)->info("Performing cart action", [
|
||||
Log::channel(self::LOG_CHANNEL)->info('Performing cart action', [
|
||||
'action' => $data['action'] ?? 'unknown',
|
||||
'is_for' => $is_for
|
||||
'is_for' => $is_for,
|
||||
]);
|
||||
|
||||
if ($data['action'] === 'updateCart' && isset($data['product_id'])) {
|
||||
|
|
@ -689,6 +719,7 @@ class OrderController extends Controller
|
|||
|
||||
if ($data['action'] === 'clearCart') {
|
||||
Yard::instance('shopping')->destroy();
|
||||
|
||||
return response()->json(['response' => true, 'data' => Yard::instance('shopping')->count(), 'html_card' => '', 'html_comp' => '']);
|
||||
}
|
||||
|
||||
|
|
@ -700,7 +731,8 @@ class OrderController extends Controller
|
|||
return $this->handleUpdateCompProduct($data, $is_for);
|
||||
}
|
||||
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Unknown action in performRequest", ['action' => $data['action'] ?? 'not set']);
|
||||
Log::channel(self::LOG_CHANNEL)->warning('Unknown action in performRequest', ['action' => $data['action'] ?? 'not set']);
|
||||
|
||||
return response()->json(['response' => false, 'data' => $data]);
|
||||
}
|
||||
|
||||
|
|
@ -710,12 +742,13 @@ class OrderController extends Controller
|
|||
private function handleUpdateCart($data, $is_for)
|
||||
{
|
||||
$product = Product::find($data['product_id']);
|
||||
if (!$product) {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Product not found for cart update", ['product_id' => $data['product_id']]);
|
||||
if (! $product) {
|
||||
Log::channel(self::LOG_CHANNEL)->warning('Product not found for cart update', ['product_id' => $data['product_id']]);
|
||||
|
||||
return response()->json(['response' => false, 'message' => 'Product not found']);
|
||||
}
|
||||
|
||||
$image = "";
|
||||
$image = '';
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
|
@ -730,7 +763,7 @@ class OrderController extends Controller
|
|||
round($product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), false, Yard::instance('shopping')->getUserCountry()), 1),
|
||||
false,
|
||||
false,
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'show_on' => $product->show_on]
|
||||
);
|
||||
} else {
|
||||
$cartItem = Yard::instance('shopping')
|
||||
|
|
@ -741,7 +774,7 @@ class OrderController extends Controller
|
|||
$product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), true, Yard::instance('shopping')->getUserCountry()),
|
||||
false,
|
||||
false,
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'show_on' => $product->show_on]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -761,8 +794,8 @@ class OrderController extends Controller
|
|||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
|
||||
|
||||
$html_card = view("user.order.yard_view_form", $data)->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
$html_card = view('user.order.yard_view_form', $data)->render();
|
||||
$html_comp = view('user.order.comp_product', $data)->render();
|
||||
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
|
||||
}
|
||||
|
|
@ -778,14 +811,14 @@ class OrderController extends Controller
|
|||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country->id, $is_for);
|
||||
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
|
||||
} else {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Shipping country not found", [
|
||||
'shipping_country_id' => $data['shipping_country_id']
|
||||
Log::channel(self::LOG_CHANNEL)->warning('Shipping country not found', [
|
||||
'shipping_country_id' => $data['shipping_country_id'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$html_card = view("user.order.yard_view_form", $data)->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
$html_card = view('user.order.yard_view_form', $data)->render();
|
||||
$html_comp = view('user.order.comp_product', $data)->render();
|
||||
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
|
||||
}
|
||||
|
|
@ -798,8 +831,8 @@ class OrderController extends Controller
|
|||
$this->updateCompProduct($data);
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
|
||||
$html_card = view("user.order.yard_view_form", $data)->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
$html_card = view('user.order.yard_view_form', $data)->render();
|
||||
$html_comp = view('user.order.comp_product', $data)->render();
|
||||
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
|
||||
}
|
||||
|
|
@ -826,8 +859,8 @@ class OrderController extends Controller
|
|||
foreach (Yard::instance('shopping')->content() as $row) {
|
||||
// If count_comp_products is smaller, the product was removed due to quantity
|
||||
// if comp_num equals the comp product, the product was removed due to new shipping costs
|
||||
//count_comp_products wie viele comp products werden gebraucht
|
||||
//comp_num welches comp product wird hinzugefügt
|
||||
// count_comp_products wie viele comp products werden gebraucht
|
||||
// comp_num welches comp product wird hinzugefügt
|
||||
if ($row->options->comp && ($row->options->comp == intval($data['comp_num']) || $row->options->comp > intval($data['count_comp_products']))) {
|
||||
Yard::instance('shopping')->remove($row->rowId);
|
||||
}
|
||||
|
|
@ -836,7 +869,7 @@ class OrderController extends Controller
|
|||
if (isset($data['comp_product_id'])) {
|
||||
$product = Product::find($data['comp_product_id']);
|
||||
if ($product) {
|
||||
$image = "";
|
||||
$image = '';
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
|
@ -853,14 +886,14 @@ class OrderController extends Controller
|
|||
'weight' => 0,
|
||||
'points' => 0,
|
||||
'comp' => intval($data['comp_num']),
|
||||
'product_id' => $product->id
|
||||
'product_id' => $product->id,
|
||||
]
|
||||
);
|
||||
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
} else {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Compensation product not found", [
|
||||
'comp_product_id' => $data['comp_product_id']
|
||||
Log::channel(self::LOG_CHANNEL)->warning('Compensation product not found', [
|
||||
'comp_product_id' => $data['comp_product_id'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -873,9 +906,10 @@ class OrderController extends Controller
|
|||
{
|
||||
try {
|
||||
$data = OrderPaymentService::getCustomPayment($identifier);
|
||||
|
||||
return view('user.order.payment.custom_payment', $data);
|
||||
} catch (\Exception $e) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Error accessing custom payment: " . $e->getMessage(), ['identifier' => $identifier]);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Error accessing custom payment: '.$e->getMessage(), ['identifier' => $identifier]);
|
||||
abort(404, 'Custom payment not found');
|
||||
}
|
||||
}
|
||||
|
|
@ -888,22 +922,22 @@ class OrderController extends Controller
|
|||
$bcc = [];
|
||||
$shopping_instance = ShoppingInstance::where('identifier', $identifier)->first();
|
||||
|
||||
if (!$shopping_instance) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shopping instance not found for email", ['identifier' => $identifier]);
|
||||
if (! $shopping_instance) {
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shopping instance not found for email', ['identifier' => $identifier]);
|
||||
throw new \Exception(__('msg.shopping_instance_not_found'));
|
||||
}
|
||||
|
||||
$shopping_user = $data['shopping_user_id'] ? ShoppingUser::find($data['shopping_user_id']) : null;
|
||||
|
||||
if (!$shopping_user) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shopping user not found for email", ['shopping_user_id' => $data['shopping_user_id']]);
|
||||
if (! $shopping_user) {
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shopping user not found for email', ['shopping_user_id' => $data['shopping_user_id']]);
|
||||
throw new \Exception(__('msg.shopping_user_not_found'));
|
||||
}
|
||||
|
||||
$route = route('checkout.checkout_card', ['identifier' => $identifier]);
|
||||
|
||||
$billing_email = $shopping_user->billing_email;
|
||||
if (!$billing_email) {
|
||||
if (! $billing_email) {
|
||||
$billing_email = $data['mode'] === 'test' ? config('app.checkout_test_mail') : config('app.checkout_mail');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
use Carbon;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Services\Credit;
|
||||
use App\Models\UserCredit;
|
||||
use App\Models\UserPayCredit;
|
||||
use App\Models\UserCreditItem;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
use App\Models\UserCredit;
|
||||
use App\Models\UserCreditItem;
|
||||
use App\Services\Credit;
|
||||
use App\User;
|
||||
use Request;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
|
||||
private $startYear;
|
||||
|
||||
private $endYear;
|
||||
|
||||
private $rangeYears;
|
||||
|
||||
private $activeYear;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
/* $this->startYear = 2021;
|
||||
/* $this->startYear = 2021;
|
||||
$this->endYear = date('Y');
|
||||
$this->rangeYears = range($this->startYear, $this->endYear);
|
||||
$this->activeYear = $this->endYear;*/
|
||||
|
|
@ -34,11 +34,12 @@ class PaymentController extends Controller
|
|||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
|
||||
return view('user.payment.credit', $data);
|
||||
}
|
||||
|
||||
|
||||
public function credit_datatable(){
|
||||
public function credit_datatable()
|
||||
{
|
||||
|
||||
$user = \Auth::user();
|
||||
$query = UserCredit::with('user', 'user.account')->select('user_credits.*')->where('user_id', $user->id);
|
||||
|
|
@ -46,29 +47,35 @@ class PaymentController extends Controller
|
|||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('view', function (UserCredit $UserCredit) {
|
||||
$ret = "";
|
||||
if(Credit::isCredit($UserCredit)){
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a><br>';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'html']).'" target="_blank" class="btn btn-secondary btn-xs mt-2"><i class="fa fa-eye"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'pdf']).'" target="_blank" class="btn btn-secondary btn-xs mt-2"><i class="fa fa-file-pdf" style="min-width:13.5px"></i></a> ';
|
||||
|
||||
}else{
|
||||
$ret = "-";
|
||||
$ret = '';
|
||||
if (Credit::isCredit($UserCredit)) {
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'download']).'" class="btn btn-primary btn-xs mb-2 mr-1"><i class="fa fa-download"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'stream']).'" target="_blank" class="btn btn-warning btn-xs mb-2 mr-1"><i class="fa fa-eye"></i></a>';
|
||||
$availableLocales = $UserCredit->getAvailableLocales();
|
||||
foreach ($availableLocales as $locale) {
|
||||
$ret .= ' <a href="'.route('storage_file', [$UserCredit->id, 'credit', 'download', $locale]).'" class="btn btn-outline-primary btn-xs mb-2 mr-1" title="Gutschrift '.strtoupper($locale).'"><i class="fa fa-download"></i> '.strtoupper($locale).'</a>';
|
||||
$ret .= ' <a href="'.route('storage_file', [$UserCredit->id, 'credit', 'stream', $locale]).'" class="btn btn-outline-warning btn-xs mb-2 mr-1" title="Gutschrift '.strtoupper($locale).'"><i class="fa fa-eye"></i> '.strtoupper($locale).'</a>';
|
||||
}
|
||||
$ret .= '<br>';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'html']).'" target="_blank" class="btn btn-secondary btn-xs mb-2 mr-1 "><i class="fa fa-eye"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'pdf']).'" target="_blank" class="btn btn-secondary btn-xs mb-2 mr-1"><i class="fa fa-file-pdf" style="min-width:13.5px"></i></a> ';
|
||||
} else {
|
||||
$ret = '-';
|
||||
}
|
||||
|
||||
return $ret;
|
||||
})
|
||||
->addColumn('total', function (UserCredit $UserCredit) {
|
||||
return $UserCredit->getFormattedTotal()." €";
|
||||
return $UserCredit->getFormattedTotal().' €';
|
||||
})
|
||||
->addColumn('credits', function (UserCredit $UserCredit) {
|
||||
$ret = "";
|
||||
if($UserCredit->user_credit_items){
|
||||
foreach($UserCredit->user_credit_items as $user_credit_item){
|
||||
$ret .= nl2br($user_credit_item->getTransMessage())." / ".$user_credit_item->created_at->format('d.m.Y')."<br>";
|
||||
|
||||
$ret = '';
|
||||
if ($UserCredit->user_credit_items) {
|
||||
foreach ($UserCredit->user_credit_items as $user_credit_item) {
|
||||
$ret .= nl2br($user_credit_item->getTransMessage()).' / '.$user_credit_item->created_at->format('d.m.Y').'<br>';
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
})
|
||||
->addColumn('status', function (UserCredit $UserCredit) {
|
||||
|
|
@ -81,18 +88,19 @@ class PaymentController extends Controller
|
|||
->make(true);
|
||||
}
|
||||
|
||||
public function credit_item_datatable(){
|
||||
public function credit_item_datatable()
|
||||
{
|
||||
|
||||
$user = \Auth::user();
|
||||
$query = UserCreditItem::select('user_credit_items.*')->where('user_id', $user->id);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
|
||||
->addColumn('message', function (UserCreditItem $user_credit_item) {
|
||||
return nl2br($user_credit_item->getTransMessage());
|
||||
})
|
||||
->addColumn('credit', function (UserCreditItem $user_credit_item) {
|
||||
return formatNumber($user_credit_item->credit)." €";
|
||||
return formatNumber($user_credit_item->credit).' €';
|
||||
})
|
||||
->addColumn('created_at', function (UserCreditItem $user_credit_item) {
|
||||
return formatDate($user_credit_item->created_at);
|
||||
|
|
@ -101,11 +109,11 @@ class PaymentController extends Controller
|
|||
return '<span class="badge badge-pill badge-'.$user_credit_item->getStatusColor().'">'.$user_credit_item->getStatusType().'</span> ';
|
||||
})
|
||||
->addColumn('paid', function (UserCreditItem $user_credit_item) {
|
||||
return ($user_credit_item->paid && $user_credit_item->user_credit) ?
|
||||
'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$user_credit_item->user_credit->full_number.'</span>'
|
||||
return ($user_credit_item->paid && $user_credit_item->user_credit) ?
|
||||
'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$user_credit_item->user_credit->full_number.'</span>'
|
||||
: '<span class="badge badge-pill badge-warning"><i class="fa fa-times"></i></span>';
|
||||
})
|
||||
|
||||
|
||||
->orderColumn('message', 'message $1')
|
||||
->orderColumn('credit', 'credit $1')
|
||||
->orderColumn('created_at', 'created_at $1')
|
||||
|
|
@ -114,13 +122,12 @@ class PaymentController extends Controller
|
|||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
/*private function setActiveYears(){
|
||||
if(Request::get('filter_year')){
|
||||
$this->activeYear = Request::get('filter_year');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function revenue()
|
||||
{
|
||||
$this->setActiveYears();
|
||||
|
|
@ -134,4 +141,4 @@ class PaymentController extends Controller
|
|||
];
|
||||
return view('user.payment.revenue', $data);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Exports\UserTeamExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\UserBusiness;
|
||||
use App\Models\UserLevel;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Services\AboHelper;
|
||||
use App\Services\BusinessPlan\ExportBot;
|
||||
use App\Services\BusinessPlan\TreeCalcBot;
|
||||
use App\Services\BusinessPlan\TreeCalcBotOptimized;
|
||||
|
|
@ -17,16 +16,12 @@ use App\Services\LevelReportService;
|
|||
use App\Services\NextLevelBadgeHelper;
|
||||
use App\Services\TranslationHelper;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use function Ramsey\Uuid\v1;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Request;
|
||||
|
||||
/**
|
||||
* Team Controller für User-Bereich
|
||||
*
|
||||
*
|
||||
* Erweitert um optimierte Versionen:
|
||||
* - show(): Optimierte Team-Übersicht mit Performance-Monitoring
|
||||
* - structure(): Nutzt TreeCalcBotOptimized für bessere Performance
|
||||
|
|
@ -36,9 +31,13 @@ use Request;
|
|||
class TeamController extends Controller
|
||||
{
|
||||
private $filter_active = [1 => '', 2 => '', 3 => '']; // Wird in getFilterActive() übersetzt
|
||||
|
||||
private $filter_next_level = [0 => '', 1 => '', 2 => '', 3 => '']; // Wird in getFilterNextLevel() übersetzt
|
||||
|
||||
private $month;
|
||||
|
||||
private $year;
|
||||
|
||||
private $forceLiveCalculation;
|
||||
|
||||
public function __construct()
|
||||
|
|
@ -46,8 +45,6 @@ class TeamController extends Controller
|
|||
$this->middleware('active.account');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Zeigt die Team-Übersicht mit optimierter TreeCalcBotOptimized-Datenverarbeitung
|
||||
* Lädt Team-Daten für DataTable-Anzeige
|
||||
|
|
@ -67,19 +64,19 @@ class TeamController extends Controller
|
|||
$forceLiveCalculation = Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
$forceLiveCalculation = false;
|
||||
|
||||
\Log::info("TeamController: Building optimized team overview for user {$user->id} ({$this->month}/{$this->year})" .
|
||||
($forceLiveCalculation === true ? " with forced live calculation" : "not live calculation"));
|
||||
\Log::info("TeamController: Building optimized team overview for user {$user->id} ({$this->month}/{$this->year})".
|
||||
($forceLiveCalculation === true ? ' with forced live calculation' : 'not live calculation'));
|
||||
|
||||
// Verwende TreeCalcBotOptimized für bessere Performance
|
||||
//$TreeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'member', $forceLiveCalculation);
|
||||
//$TreeCalcBot->initStructureUser($user->id);
|
||||
// $TreeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'member', $forceLiveCalculation);
|
||||
// $TreeCalcBot->initStructureUser($user->id);
|
||||
$endTime = microtime(true);
|
||||
$endMemory = memory_get_usage();
|
||||
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$memoryUsed = $this->formatBytes($endMemory - $startMemory);
|
||||
|
||||
$calculationType = $forceLiveCalculation ? " (LIVE)" : " (CACHE)";
|
||||
$calculationType = $forceLiveCalculation ? ' (LIVE)' : ' (CACHE)';
|
||||
\Log::info("TeamController: Optimized team overview built in {$executionTime}ms, Memory: {$memoryUsed}{$calculationType}");
|
||||
|
||||
$data = [
|
||||
|
|
@ -88,21 +85,22 @@ class TeamController extends Controller
|
|||
'filter_active' => $this->getFilterActive(),
|
||||
'filter_levels' => $this->getFilterLevels(),
|
||||
'filter_next_level' => $this->getFilterNextLevel(),
|
||||
//'TreeCalcBot' => $TreeCalcBot,
|
||||
// 'TreeCalcBot' => $TreeCalcBot,
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'memory_used' => $memoryUsed,
|
||||
'user_id' => $user->id,
|
||||
'user_count' => 0, //$TreeCalcBot->getTotalUserCount(),
|
||||
'user_count' => 0, // $TreeCalcBot->getTotalUserCount(),
|
||||
'version' => 'Optimized',
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache'
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache',
|
||||
],
|
||||
'optimized' => true,
|
||||
'forceLiveCalculation' => $forceLiveCalculation,
|
||||
];
|
||||
|
||||
return view('user.team.show', $data);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error in optimized show for user {$user->id}: " . $e->getMessage());
|
||||
\Log::error("TeamController: Error in optimized show for user {$user->id}: ".$e->getMessage());
|
||||
|
||||
// Fallback mit minimalen Daten
|
||||
$endTime = microtime(true);
|
||||
|
|
@ -114,12 +112,12 @@ class TeamController extends Controller
|
|||
'filter_active' => $this->getFilterActive(),
|
||||
'filter_levels' => $this->getFilterLevels(),
|
||||
'filter_next_level' => $this->getFilterNextLevel(),
|
||||
'error' => __('team.error_loading_optimized_overview') . $e->getMessage(),
|
||||
'error' => __('team.error_loading_optimized_overview').$e->getMessage(),
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'memory_used' => 'N/A',
|
||||
'version' => 'Fallback',
|
||||
'calculation_type' => 'Error'
|
||||
'calculation_type' => 'Error',
|
||||
],
|
||||
'optimized' => false,
|
||||
];
|
||||
|
|
@ -175,8 +173,8 @@ class TeamController extends Controller
|
|||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$memoryUsed = $this->formatBytes($endMemory - $startMemory);
|
||||
|
||||
$versionInfo = ($optimizedUsed ? "OPTIMIZED" : "STANDARD") .
|
||||
($forceLiveCalculation ? " + LIVE" : " + CACHE");
|
||||
$versionInfo = ($optimizedUsed ? 'OPTIMIZED' : 'STANDARD').
|
||||
($forceLiveCalculation ? ' + LIVE' : ' + CACHE');
|
||||
|
||||
\Log::info("TeamController: Structure built for user {$user->id} in {$executionTime}ms, Memory: {$memoryUsed} ({$versionInfo})");
|
||||
|
||||
|
|
@ -191,7 +189,7 @@ class TeamController extends Controller
|
|||
? $TreeCalcBot->getTotalUserCount()
|
||||
: '-',
|
||||
'version' => $optimizedUsed ? 'Optimized' : 'Standard',
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache'
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache',
|
||||
],
|
||||
'optimized' => $optimizedUsed,
|
||||
'forceLiveCalculation' => $forceLiveCalculation,
|
||||
|
|
@ -199,7 +197,7 @@ class TeamController extends Controller
|
|||
|
||||
return view('user.team.structure', $data);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error in structure for user {$user->id}: " . $e->getMessage());
|
||||
\Log::error("TeamController: Error in structure for user {$user->id}: ".$e->getMessage());
|
||||
|
||||
// Fallback zur Standard-Implementierung
|
||||
$TreeCalcBot = new TreeCalcBot(session('team_user_filter_month'), session('team_user_filter_year'), 'member');
|
||||
|
|
@ -212,13 +210,13 @@ class TeamController extends Controller
|
|||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
'TreeCalcBot' => $TreeCalcBot,
|
||||
'error' => 'Fehler aufgetreten, Standard-Version wird verwendet: ' . $e->getMessage(),
|
||||
'error' => 'Fehler aufgetreten, Standard-Version wird verwendet: '.$e->getMessage(),
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'memory_used' => 'N/A',
|
||||
'user_count' => '-',
|
||||
'version' => 'Fallback',
|
||||
'calculation_type' => $forceLiveCalculation ? __('team.live_not_supported_fallback') : __('team.cache')
|
||||
'calculation_type' => $forceLiveCalculation ? __('team.live_not_supported_fallback') : __('team.cache'),
|
||||
],
|
||||
'optimized' => false,
|
||||
'forceLiveCalculation' => $forceLiveCalculation,
|
||||
|
|
@ -227,6 +225,7 @@ class TeamController extends Controller
|
|||
return view('user.team.structure', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function structureOld()
|
||||
{
|
||||
abort(403, 'This page is removed');
|
||||
|
|
@ -237,17 +236,17 @@ class TeamController extends Controller
|
|||
$this->setFilterVars();
|
||||
$TreeCalcBot = new TreeCalcBot(session('team_user_filter_month'), session('team_user_filter_year'), 'member');
|
||||
$TreeCalcBot->initStructureUser($user->id);
|
||||
//for testing
|
||||
//$TreeCalcBot->initUser(56);
|
||||
// for testing
|
||||
// $TreeCalcBot->initUser(56);
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
'TreeCalcBot' => $TreeCalcBot,
|
||||
];
|
||||
|
||||
return view('user.team.structure', $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Optimierte DataTable für Team-Übersicht mit TreeCalcBotOptimized-Daten
|
||||
* Nutzt bereits berechnete Business-Daten für bessere Performance
|
||||
|
|
@ -265,8 +264,8 @@ class TeamController extends Controller
|
|||
// Prüfe ob Live-Berechnung erzwungen werden soll
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
$forceLiveCalculation = false;
|
||||
\Log::info("TeamController: Building optimized datatable for user {$user->id} ({$this->month}/{$this->year})" .
|
||||
($forceLiveCalculation == true ? " with forced live calculation" : ""));
|
||||
\Log::info("TeamController: Building optimized datatable for user {$user->id} ({$this->month}/{$this->year})".
|
||||
($forceLiveCalculation == true ? ' with forced live calculation' : ''));
|
||||
|
||||
// Lade TreeCalcBotOptimized-Daten
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'member', $forceLiveCalculation);
|
||||
|
|
@ -277,30 +276,36 @@ class TeamController extends Controller
|
|||
// KRITISCH: Bereinige die Objekte für DataTables (entferne zirkuläre Referenzen)
|
||||
$teamUsers = collect($this->cleanBusinessUserItemsForDataTable($teamUsersRaw));
|
||||
|
||||
\Log::info("TeamController: TeamUsers cleaned for DataTable: " . $teamUsers->count());
|
||||
\Log::info('TeamController: TeamUsers cleaned for DataTable: '.$teamUsers->count());
|
||||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$this->forceLiveCalculation = $forceLiveCalculation;
|
||||
|
||||
\Log::info("TeamController: Optimized datatable data prepared in {$executionTime}ms for " . $teamUsers->count() . " users");
|
||||
\Log::info("TeamController: Optimized datatable data prepared in {$executionTime}ms for ".$teamUsers->count().' users');
|
||||
|
||||
return \DataTables::of($teamUsers)
|
||||
->addColumn('id', function ($teamUser) {
|
||||
return '<button type="button" class="btn icon-btn btn-xs btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="' . $teamUser->user_id . '"
|
||||
data-id="'.$teamUser->user_id.'"
|
||||
data-action="business-user-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="member"
|
||||
data-live="' . $this->forceLiveCalculation . '"
|
||||
data-live="'.$this->forceLiveCalculation.'"
|
||||
data-optimized="1"
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-calculator"></span></button>';
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-calculator"></span></button>';
|
||||
})
|
||||
->addColumn('m_account', function ($teamUser) {
|
||||
return $teamUser->m_account;
|
||||
})
|
||||
->addColumn('email', function ($teamUser) {
|
||||
return e($teamUser->email);
|
||||
$button = '<a href="#" class="text-black" data-toggle="modal" data-target="#modals-load-content" '.
|
||||
'data-id="'.$teamUser->user_id.'" data-action="business-user-show" data-back="" '.
|
||||
'data-modal="modal-md" data-init_from="member" data-route="'.route('modal_load').'">'.
|
||||
'<span class="mr-1 ion ion-ios-contact"></span> '.
|
||||
'</a>';
|
||||
|
||||
return $button.e($teamUser->email);
|
||||
})
|
||||
->addColumn('first_name', function ($teamUser) {
|
||||
return e($teamUser->first_name);
|
||||
|
|
@ -313,6 +318,7 @@ class TeamController extends Controller
|
|||
})
|
||||
->addColumn('is_qual_kp', function ($teamUser) {
|
||||
$user = User::find($teamUser->user_id);
|
||||
|
||||
return TreeHelperOptimized::generateQualKPBadgeForUser($user, $this->month, $this->year);
|
||||
})
|
||||
->addColumn('sales_volume_KP_points', function ($teamUser) {
|
||||
|
|
@ -331,18 +337,19 @@ class TeamController extends Controller
|
|||
if ($userBusiness) {
|
||||
return NextLevelBadgeHelper::generateBadgeFromUserBusiness($userBusiness);
|
||||
}
|
||||
|
||||
return NextLevelBadgeHelper::renderNoDataBadge();
|
||||
})
|
||||
->addColumn('active_account', function ($teamUser) {
|
||||
return get_active_badge($teamUser->active_account);
|
||||
})
|
||||
->addColumn('payment_account_date', function ($teamUser) {
|
||||
return $teamUser->active_date ? formatDate($teamUser->active_date) : "-";
|
||||
return $teamUser->active_date ? formatDate($teamUser->active_date) : '-';
|
||||
})
|
||||
->rawColumns(['id', 'next_level_qualified', 'active_account', 'is_qual_kp', 'sales_volume_KP_points', 'sales_volume_total'])
|
||||
->rawColumns(['id', 'email', 'next_level_qualified', 'active_account', 'is_qual_kp', 'sales_volume_KP_points', 'sales_volume_total'])
|
||||
->make(true);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error in optimized datatable: " . $e->getMessage());
|
||||
\Log::error('TeamController: Error in optimized datatable: '.$e->getMessage());
|
||||
|
||||
// Fallback zur Standard-DataTable
|
||||
return $this->datatable();
|
||||
|
|
@ -361,12 +368,12 @@ class TeamController extends Controller
|
|||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (User $teamUser) {
|
||||
return '<button type="button" class="btn icon-btn btn-xs btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="' . $teamUser->id . '"
|
||||
data-id="'.$teamUser->id.'"
|
||||
data-action="team-user-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="member"
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-eye"></span></button>';
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-eye"></span></button>';
|
||||
})
|
||||
->addColumn('m_account', function (User $teamUser) {
|
||||
return $teamUser->account ? e($teamUser->account->m_account) : '';
|
||||
|
|
@ -375,7 +382,7 @@ class TeamController extends Controller
|
|||
return $teamUser->user_level ? e($teamUser->user_level->getLang('name')) : '';
|
||||
})
|
||||
->addColumn('is_qual_kp', function (User $teamUser) {
|
||||
if (!$teamUser->user_level) {
|
||||
if (! $teamUser->user_level) {
|
||||
return '-';
|
||||
}
|
||||
$qualKP = (int) $teamUser->user_level->qual_kp;
|
||||
|
|
@ -384,7 +391,8 @@ class TeamController extends Controller
|
|||
$pointsSum = (int) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_points_KP_sum');
|
||||
$isQual = $pointsSum >= $qualKP;
|
||||
$badgeClass = $isQual ? 'badge-outline-success' : 'badge-outline-warning-dark';
|
||||
return '<span class="badge ' . $badgeClass . '"> KU ' . $qualKP . '</span>';
|
||||
|
||||
return '<span class="badge '.$badgeClass.'"> KU '.$qualKP.'</span>';
|
||||
})
|
||||
->addColumn('sales_volume_KP_points', function (User $teamUser) {
|
||||
$month = Request::get('team_user_filter_month') ?: session('team_user_filter_month');
|
||||
|
|
@ -392,8 +400,9 @@ class TeamController extends Controller
|
|||
$total = (int) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_points_KP_sum');
|
||||
$individual = (int) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_KP_points');
|
||||
$shop = (int) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_points_shop');
|
||||
return '<div class="no-line-break">' . $total . '</div>' .
|
||||
'<span class="small no-line-break">E: ' . $individual . ' | S: ' . $shop . '</span>';
|
||||
|
||||
return '<div class="no-line-break">'.$total.'</div>'.
|
||||
'<span class="small no-line-break">E: '.$individual.' | S: '.$shop.'</span>';
|
||||
})
|
||||
->addColumn('sales_volume_total', function (User $teamUser) {
|
||||
$month = Request::get('team_user_filter_month') ?: session('team_user_filter_month');
|
||||
|
|
@ -401,8 +410,9 @@ class TeamController extends Controller
|
|||
$total = (float) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_total_sum');
|
||||
$individual = (float) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_total');
|
||||
$shop = (float) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_total_shop');
|
||||
return '<div class="no-line-break">' . formatNumber($total) . ' €</div>' .
|
||||
'<span class="small no-line-break">E: ' . formatNumber($individual) . ' | S: ' . formatNumber($shop) . ' €</span>';
|
||||
|
||||
return '<div class="no-line-break">'.formatNumber($total).' €</div>'.
|
||||
'<span class="small no-line-break">E: '.formatNumber($individual).' | S: '.formatNumber($shop).' €</span>';
|
||||
})
|
||||
->addColumn('email', function (User $teamUser) {
|
||||
return e($teamUser->email);
|
||||
|
|
@ -414,24 +424,25 @@ class TeamController extends Controller
|
|||
return $teamUser->account ? e($teamUser->account->last_name) : '';
|
||||
})
|
||||
->addColumn('sponsor', function (User $teamUser) {
|
||||
if (!$teamUser->user_sponsor) {
|
||||
if (! $teamUser->user_sponsor) {
|
||||
return '-';
|
||||
}
|
||||
$sponsor = $teamUser->user_sponsor;
|
||||
$html = '';
|
||||
if ($sponsor->account) {
|
||||
$html .= e($sponsor->account->first_name . ' ' . $sponsor->account->last_name);
|
||||
$html .= '<br><span class="small no-line-break">' . e($sponsor->email);
|
||||
$html .= ' | ' . e($sponsor->account->m_account);
|
||||
$html .= e($sponsor->account->first_name.' '.$sponsor->account->last_name);
|
||||
$html .= '<br><span class="small no-line-break">'.e($sponsor->email);
|
||||
$html .= ' | '.e($sponsor->account->m_account);
|
||||
$html .= '</span>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
})
|
||||
->addColumn('active_account', function (User $teamUser) {
|
||||
return get_active_badge($teamUser->isActiveAccount());
|
||||
})
|
||||
->addColumn('payment_account_date', function (User $teamUser) {
|
||||
return $teamUser->payment_account ? $teamUser->getPaymentAccountDateFormat(false) : "-";
|
||||
return $teamUser->payment_account ? $teamUser->getPaymentAccountDateFormat(false) : '-';
|
||||
})
|
||||
->addColumn('next_level_qualified', function (User $teamUser) {
|
||||
// Verwende bereits berechnete UserBusiness-Daten für bessere Performance
|
||||
|
|
@ -450,29 +461,29 @@ class TeamController extends Controller
|
|||
return NextLevelBadgeHelper::renderNoDataBadge();
|
||||
})
|
||||
->filterColumn('m_account', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
if ($keyword != '') {
|
||||
$query->whereHas('account', function ($q) use ($keyword) {
|
||||
$q->where('m_account', 'LIKE', '%' . $keyword . '%');
|
||||
$q->where('m_account', 'LIKE', '%'.$keyword.'%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filterColumn('first_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
if ($keyword != '') {
|
||||
$query->whereHas('account', function ($q) use ($keyword) {
|
||||
$q->where('first_name', 'LIKE', '%' . $keyword . '%');
|
||||
$q->where('first_name', 'LIKE', '%'.$keyword.'%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filterColumn('last_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
if ($keyword != '') {
|
||||
$query->whereHas('account', function ($q) use ($keyword) {
|
||||
$q->where('last_name', 'LIKE', '%' . $keyword . '%');
|
||||
$q->where('last_name', 'LIKE', '%'.$keyword.'%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filterColumn('email', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->where('email', 'LIKE', '%' . $keyword . '%');
|
||||
if ($keyword != '') {
|
||||
$query->where('email', 'LIKE', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->orderColumn('id', 'users.id $1')
|
||||
|
|
@ -484,10 +495,10 @@ class TeamController extends Controller
|
|||
->rawColumns(['id', 'is_qual_kp', 'sales_volume_KP_points', 'sales_volume_total', 'sponsor', 'active_account', 'next_level_qualified'])
|
||||
->make(true);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error in userDatatable: " . $e->getMessage());
|
||||
\Log::error('TeamController: Error in userDatatable: '.$e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'error' => 'Team-Datatable konnte nicht geladen werden: ' . $e->getMessage()
|
||||
'error' => 'Team-Datatable konnte nicht geladen werden: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
|
@ -510,7 +521,7 @@ class TeamController extends Controller
|
|||
$onlyNotUpdated = Request::boolean('not_updated', false);
|
||||
|
||||
// Prüfe ob Live-Berechnung erzwungen werden soll
|
||||
$forceLiveCalculation = false; //Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
$forceLiveCalculation = false; // Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
|
||||
\Log::info("TeamController: Building level reports for user {$user->id} ({$month}/{$year})");
|
||||
|
||||
|
|
@ -519,7 +530,7 @@ class TeamController extends Controller
|
|||
$treeCalcBot->initStructureUser($user->id, $forceLiveCalculation);
|
||||
|
||||
// Lade Level-Reports für Team
|
||||
$levelReportService = new LevelReportService();
|
||||
$levelReportService = new LevelReportService;
|
||||
$filters = ['only_not_updated' => $onlyNotUpdated];
|
||||
$promotions = $levelReportService->getTeamLevelPromotions($treeCalcBot, $month, $year, $filters);
|
||||
$statistics = $levelReportService->getStatistics($promotions);
|
||||
|
|
@ -527,7 +538,7 @@ class TeamController extends Controller
|
|||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
|
||||
\Log::info("TeamController: Level reports loaded for user {$user->id} in {$executionTime}ms - " . $promotions->count() . " promotions found");
|
||||
\Log::info("TeamController: Level reports loaded for user {$user->id} in {$executionTime}ms - ".$promotions->count().' promotions found');
|
||||
|
||||
$availableYears = range(date('Y'), date('Y') - 5);
|
||||
$availableMonths = [
|
||||
|
|
@ -542,7 +553,7 @@ class TeamController extends Controller
|
|||
9 => __('cal.months.September'),
|
||||
10 => __('cal.months.October'),
|
||||
11 => __('cal.months.November'),
|
||||
12 => __('cal.months.December')
|
||||
12 => __('cal.months.December'),
|
||||
];
|
||||
|
||||
$data = [
|
||||
|
|
@ -551,22 +562,22 @@ class TeamController extends Controller
|
|||
'filters' => [
|
||||
'month' => $month,
|
||||
'year' => $year,
|
||||
'only_not_updated' => $onlyNotUpdated
|
||||
'only_not_updated' => $onlyNotUpdated,
|
||||
],
|
||||
'availableYears' => $availableYears,
|
||||
'availableMonths' => $availableMonths,
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'user_id' => $user->id
|
||||
]
|
||||
'user_id' => $user->id,
|
||||
],
|
||||
];
|
||||
|
||||
return view('user.team.level-reports', $data);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error loading level reports: " . $e->getMessage());
|
||||
\Log::error('TeamController: Error loading level reports: '.$e->getMessage());
|
||||
|
||||
return view('user.team.level-reports', [
|
||||
'error' => 'Fehler beim Laden der Level-Reports: ' . $e->getMessage(),
|
||||
'error' => 'Fehler beim Laden der Level-Reports: '.$e->getMessage(),
|
||||
'promotions' => collect([]),
|
||||
'statistics' => ['total_count' => 0, 'level_stats' => [], 'period_stats' => []],
|
||||
'filters' => ['month' => date('m'), 'year' => date('Y'), 'only_not_updated' => false],
|
||||
|
|
@ -583,8 +594,8 @@ class TeamController extends Controller
|
|||
9 => __('cal.months.September'),
|
||||
10 => __('cal.months.October'),
|
||||
11 => __('cal.months.November'),
|
||||
12 => __('cal.months.December')
|
||||
]
|
||||
12 => __('cal.months.December'),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -608,7 +619,7 @@ class TeamController extends Controller
|
|||
$treeCalcBot->initStructureUser($user->id, $forceLiveCalculation);
|
||||
|
||||
// Lade Level-Reports
|
||||
$levelReportService = new LevelReportService();
|
||||
$levelReportService = new LevelReportService;
|
||||
$filters = ['only_not_updated' => $onlyNotUpdated];
|
||||
$promotions = $levelReportService->getTeamLevelPromotions($treeCalcBot, $month, $year, $filters);
|
||||
|
||||
|
|
@ -617,13 +628,14 @@ class TeamController extends Controller
|
|||
}
|
||||
|
||||
// CSV erstellen
|
||||
$filename = 'team_level_promotions_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
$filename = 'team_level_promotions_'.date('Y-m-d_H-i-s').'.csv';
|
||||
$filepath = $levelReportService->exportToCsv($promotions, $filename);
|
||||
|
||||
return response()->download($filepath, $filename)->deleteFileAfterSend(true);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error exporting level reports: " . $e->getMessage());
|
||||
return redirect()->back()->with('error', 'Fehler beim Export: ' . $e->getMessage());
|
||||
\Log::error('TeamController: Error exporting level reports: '.$e->getMessage());
|
||||
|
||||
return redirect()->back()->with('error', 'Fehler beim Export: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -654,19 +666,19 @@ class TeamController extends Controller
|
|||
'currentUser' => $user,
|
||||
'currentLevel' => $currentLevel,
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime
|
||||
]
|
||||
'execution_time' => $executionTime,
|
||||
],
|
||||
];
|
||||
|
||||
return view('user.team.marketingplan', $data);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error loading marketingplan: " . $e->getMessage());
|
||||
\Log::error('TeamController: Error loading marketingplan: '.$e->getMessage());
|
||||
|
||||
return view('user.team.marketingplan', [
|
||||
'error' => __('marketingplan.loading_error') . ' ' . $e->getMessage(),
|
||||
'error' => __('marketingplan.loading_error').' '.$e->getMessage(),
|
||||
'userLevels' => collect(),
|
||||
'currentUser' => null,
|
||||
'currentLevel' => null
|
||||
'currentLevel' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -678,14 +690,15 @@ class TeamController extends Controller
|
|||
{
|
||||
$user = User::find(\Auth::user()->id);
|
||||
if ($user->isActiveShop() && $user->shop) {
|
||||
$shop_register_link = $user->shop->getSubdomain(false) . "/reg";
|
||||
$shop_register_link = $user->shop->getSubdomain(false).'/reg';
|
||||
} else {
|
||||
$member_id = 'm' . ($user->id + config('mivita.add_number_id'));
|
||||
$shop_register_link = config('app.protocol') . config('app.domain') . config('app.tld_care') . '/reg/' . $member_id;
|
||||
$member_id = 'm'.($user->id + config('mivita.add_number_id'));
|
||||
$shop_register_link = config('app.protocol').config('app.domain').config('app.tld_care').'/reg/'.$member_id;
|
||||
}
|
||||
$data = [
|
||||
'shop_register_link' => $shop_register_link
|
||||
'shop_register_link' => $shop_register_link,
|
||||
];
|
||||
|
||||
return view('user.team.members', $data);
|
||||
}
|
||||
|
||||
|
|
@ -697,24 +710,8 @@ class TeamController extends Controller
|
|||
$user = User::find(\Auth::user()->id);
|
||||
$this->setFilterVars();
|
||||
|
||||
// Nutze TreeCalcBotOptimized um das Team zu bekommen
|
||||
$month = session('team_user_filter_month');
|
||||
$year = session('team_user_filter_year');
|
||||
|
||||
// Lade Team-Struktur
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($month, $year, 'member', false);
|
||||
$TreeCalcBot->initStructureUser($user->id, false);
|
||||
|
||||
// Hole flache Liste aller Team-Mitglieder
|
||||
$teamUsersRaw = $this->getTeamUsersFromStructure($TreeCalcBot);
|
||||
|
||||
// Sammle User-IDs für Abo-Abfrage
|
||||
$teamUserIds = [];
|
||||
foreach ($teamUsersRaw as $teamUser) {
|
||||
if ($teamUser->user_id && $teamUser->user_id != $user->id) {
|
||||
$teamUserIds[] = $teamUser->user_id;
|
||||
}
|
||||
}
|
||||
// Hole Team-Mitglieder-IDs effizient via Sponsor-Hierarchie
|
||||
$teamUserIds = AboHelper::getTeamUserIds($user->id);
|
||||
|
||||
// Hole Abos der Team-Mitglieder
|
||||
$abos = \App\Models\UserAbo::whereIn('user_id', $teamUserIds)
|
||||
|
|
@ -740,24 +737,8 @@ class TeamController extends Controller
|
|||
$user = User::find(\Auth::user()->id);
|
||||
$user_abo = \App\Models\UserAbo::findOrFail($id);
|
||||
|
||||
// Prüfe ob das Abo zu einem Team-Mitglied gehört
|
||||
$this->setFilterVars();
|
||||
$month = session('team_user_filter_month');
|
||||
$year = session('team_user_filter_year');
|
||||
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($month, $year, 'member', false);
|
||||
$TreeCalcBot->initStructureUser($user->id, false);
|
||||
|
||||
$teamUsersRaw = $this->getTeamUsersFromStructure($TreeCalcBot);
|
||||
$teamUserIds = [];
|
||||
foreach ($teamUsersRaw as $teamUser) {
|
||||
if ($teamUser->user_id) {
|
||||
$teamUserIds[] = $teamUser->user_id;
|
||||
}
|
||||
}
|
||||
|
||||
// Prüfe Berechtigung
|
||||
if (!in_array($user_abo->user_id, $teamUserIds)) {
|
||||
// Prüfe ob das Abo zu einem Team-Mitglied gehört (effizient via Sponsor-Kette)
|
||||
if (! AboHelper::isUserInTeam($user->id, $user_abo->user_id)) {
|
||||
abort(403, 'Unauthorized action. This subscription does not belong to your team.');
|
||||
}
|
||||
|
||||
|
|
@ -819,6 +800,7 @@ class TeamController extends Controller
|
|||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
];
|
||||
|
||||
return view('user.team.points', $data);
|
||||
}
|
||||
|
||||
|
|
@ -826,27 +808,28 @@ class TeamController extends Controller
|
|||
{
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
if (!$user->isVIP()) {
|
||||
if (! $user->isVIP()) {
|
||||
abort(404);
|
||||
}
|
||||
$ExportBot = new ExportBot('member');
|
||||
$ExportBot->initStructureUser($user, 'list'); //tree or list
|
||||
$ExportBot->initStructureUser($user, 'list'); // tree or list
|
||||
$data = [
|
||||
'ExportBot' => $ExportBot,
|
||||
];
|
||||
|
||||
return view('user.team.export', $data);
|
||||
}
|
||||
|
||||
public function userTeamExport()
|
||||
{
|
||||
|
||||
if (Request::get('action') === "export") {
|
||||
if (Request::get('action') === 'export') {
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$ExportBot = new ExportBot('member');
|
||||
$ExportBot->initStructureUser($user, 'list'); //tree or list
|
||||
$ExportBot->initStructureUser($user, 'list'); // tree or list
|
||||
$columns = [];
|
||||
$filename = __('team.filename_export') . date('Y-m-d-H-i-s');
|
||||
$headers = array(
|
||||
$filename = __('team.filename_export').date('Y-m-d-H-i-s');
|
||||
$headers = [
|
||||
__('tables.line'),
|
||||
__('tables.level'),
|
||||
__('tables.email'),
|
||||
|
|
@ -864,10 +847,10 @@ class TeamController extends Controller
|
|||
__('tables.account'),
|
||||
__('tables.account_to'),
|
||||
__('tables.sponsor'),
|
||||
);
|
||||
];
|
||||
if (isset($ExportBot->user_list->childs)) {
|
||||
foreach ($ExportBot->user_list->childs as $child) {
|
||||
$columns[] = array(
|
||||
$columns[] = [
|
||||
__('tables.line') => $child->line,
|
||||
__('tables.level') => $child->level_name,
|
||||
__('tables.email') => $child->email,
|
||||
|
|
@ -885,38 +868,39 @@ class TeamController extends Controller
|
|||
__('tables.account') => ($child->active_account == 1 ? __('yes') : __('no')),
|
||||
__('tables.account_to') => $child->payment_account_date,
|
||||
__('tables.sponsor') => $child->sponsor_name,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
return Excel::download(new UserTeamExport($columns, $headers), $filename . '.xls');
|
||||
|
||||
return Excel::download(new UserTeamExport($columns, $headers), $filename.'.xls');
|
||||
}
|
||||
}
|
||||
|
||||
private function setFilterVars()
|
||||
{
|
||||
|
||||
if (!session('team_user_filter_month')) {
|
||||
if (! session('team_user_filter_month')) {
|
||||
session(['team_user_filter_month' => intval(date('m'))]);
|
||||
}
|
||||
if (!session('team_user_filter_month_prev')) {
|
||||
if (! session('team_user_filter_month_prev')) {
|
||||
session(['team_user_filter_month_prev' => intval(date('m') - 1)]);
|
||||
}
|
||||
if (!session('team_user_filter_year')) {
|
||||
if (! session('team_user_filter_year')) {
|
||||
session(['team_user_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
if (!session('team_user_points_filter_month')) {
|
||||
if (! session('team_user_points_filter_month')) {
|
||||
session(['team_user_points_filter_month' => intval(date('m'))]);
|
||||
}
|
||||
if (!session('team_user_points_filter_year')) {
|
||||
if (! session('team_user_points_filter_year')) {
|
||||
session(['team_user_points_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
if (!session('team_user_filter_active')) {
|
||||
if (! session('team_user_filter_active')) {
|
||||
session(['team_user_filter_active' => 1]);
|
||||
}
|
||||
if (!session('team_user_filter_level')) {
|
||||
if (! session('team_user_filter_level')) {
|
||||
session(['team_user_filter_level' => 0]);
|
||||
}
|
||||
if (!session('team_user_filter_next_level')) {
|
||||
if (! session('team_user_filter_next_level')) {
|
||||
session(['team_user_filter_next_level' => 0]);
|
||||
}
|
||||
|
||||
|
|
@ -964,38 +948,39 @@ class TeamController extends Controller
|
|||
return $query;
|
||||
}
|
||||
|
||||
|
||||
public function datatablePoints()
|
||||
{
|
||||
|
||||
$query = $this->initSearchPoints();
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('order', function (UserSalesVolume $UserSalesVolume) {
|
||||
if ($UserSalesVolume->shopping_order) {
|
||||
if ($UserSalesVolume->status === 1 && $UserSalesVolume->shopping_order->auth_user_id === $UserSalesVolume->user_id) {
|
||||
return '<a href="' . route('user_order_detail', [$UserSalesVolume->shopping_order->id]) . '" class="btn btn-xs btn-primary">' . $UserSalesVolume->shopping_order->id . '</a>';
|
||||
return '<a href="'.route('user_order_detail', [$UserSalesVolume->shopping_order->id]).'" class="btn btn-xs btn-primary">'.$UserSalesVolume->shopping_order->id.'</a>';
|
||||
}
|
||||
if (($UserSalesVolume->status === 2 || $UserSalesVolume->status === 3) && $UserSalesVolume->shopping_order->member_id === $UserSalesVolume->user_id) {
|
||||
return '<a href="' . route('user_shop_order_detail', [$UserSalesVolume->shopping_order->id]) . '" class="btn btn-xs btn-secondary">' . $UserSalesVolume->shopping_order->id . '</a>';
|
||||
if (($UserSalesVolume->status === 2 || $UserSalesVolume->status === 3) && $UserSalesVolume->shopping_order->member_id === $UserSalesVolume->user_id) {
|
||||
return '<a href="'.route('user_shop_order_detail', [$UserSalesVolume->shopping_order->id]).'" class="btn btn-xs btn-secondary">'.$UserSalesVolume->shopping_order->id.'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
})
|
||||
->addColumn('total_net', function (UserSalesVolume $UserSalesVolume) {
|
||||
return formatNumber($UserSalesVolume->total_net) . ' €';
|
||||
return formatNumber($UserSalesVolume->total_net).' €';
|
||||
})
|
||||
->addColumn('status_turnover', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<span class="badge badge-pill badge-' . $UserSalesVolume->getStatusTurnoverColor() . '">' . $UserSalesVolume->getStatusTurnoverType() . '</span>';
|
||||
return '<span class="badge badge-pill badge-'.$UserSalesVolume->getStatusTurnoverColor().'">'.$UserSalesVolume->getStatusTurnoverType().'</span>';
|
||||
})
|
||||
->addColumn('status', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<span class="badge badge-pill badge-' . $UserSalesVolume->getStatusColor() . '">' . $UserSalesVolume->getStatusType() . '</span>';
|
||||
return '<span class="badge badge-pill badge-'.$UserSalesVolume->getStatusColor().'">'.$UserSalesVolume->getStatusType().'</span>';
|
||||
})
|
||||
->addColumn('message', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<span class="no-line-break">' . $UserSalesVolume->message . '</span>';
|
||||
return '<span class="no-line-break">'.$UserSalesVolume->message.'</span>';
|
||||
})
|
||||
->addColumn('info', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<span class="no-line-break">' . $UserSalesVolume->info . '</span>';
|
||||
return '<span class="no-line-break">'.$UserSalesVolume->info.'</span>';
|
||||
})
|
||||
|
||||
->orderColumn('id', 'id $1')
|
||||
|
|
@ -1018,7 +1003,8 @@ class TeamController extends Controller
|
|||
'userSalesVolume' => $userSalesVolume,
|
||||
];
|
||||
$html = view('user.team._points_sum', $data)->render();
|
||||
return response()->json(['response' => true, 'data' => $data, 'html' => $html]);
|
||||
|
||||
return response()->json(['response' => true, 'data' => $data, 'html' => $html]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1026,13 +1012,13 @@ class TeamController extends Controller
|
|||
*/
|
||||
private function formatBytes(int $bytes, int $precision = 2): string
|
||||
{
|
||||
$units = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
|
||||
for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) {
|
||||
$bytes /= 1024;
|
||||
}
|
||||
|
||||
return round($bytes, $precision) . ' ' . $units[$i];
|
||||
return round($bytes, $precision).' '.$units[$i];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1058,7 +1044,7 @@ class TeamController extends Controller
|
|||
return [
|
||||
1 => __('team.filter_active'),
|
||||
2 => __('team.filter_not_active'),
|
||||
3 => __('team.filter_all')
|
||||
3 => __('team.filter_all'),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -1071,7 +1057,7 @@ class TeamController extends Controller
|
|||
0 => __('team.all_status'),
|
||||
1 => __('team.qualified_green'),
|
||||
2 => __('team.in_progress_yellow'),
|
||||
3 => __('team.no_level_red')
|
||||
3 => __('team.no_level_red'),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -1089,20 +1075,20 @@ class TeamController extends Controller
|
|||
|
||||
// Debug: Prüfe TreeCalcBot-Inhalt
|
||||
$businessUsers = $treeCalcBot->getItems();
|
||||
\Log::info("TeamController: TreeCalcBot root items count: " . count($businessUsers));
|
||||
\Log::info('TeamController: TreeCalcBot root items count: '.count($businessUsers));
|
||||
|
||||
// Sammle alle Root-User UND deren verschachtelte businessUserItems
|
||||
foreach ($businessUsers as $businessUser) {
|
||||
// WICHTIG: user_id korrekt über b_user abrufen (Magic Method Problem mit isset())
|
||||
$userId = $businessUser->user_id; // Über __get() Method
|
||||
|
||||
\Log::debug("TeamController: Processing root businessUser", [
|
||||
\Log::debug('TeamController: Processing root businessUser', [
|
||||
'user_id' => $userId,
|
||||
'businessUserItems_count' => count($businessUser->businessUserItems ?? []),
|
||||
]);
|
||||
// WICHTIG: Root-User selbst hinzufügen (korrigierte user_id Prüfung)
|
||||
//nur User können auch children haben - businessUserItems
|
||||
if ($userId && !isset($processedIds[$userId])) {
|
||||
// nur User können auch children haben - businessUserItems
|
||||
if ($userId && ! isset($processedIds[$userId])) {
|
||||
$processedIds[$userId] = true;
|
||||
$businessUser->deep = 0;
|
||||
$allUsers[] = $businessUser;
|
||||
|
|
@ -1121,7 +1107,7 @@ class TeamController extends Controller
|
|||
|
||||
if ($userId) {
|
||||
// Prüfe ob dieser parentless User bereits gesammelt wurde
|
||||
if (!isset($processedIds[$userId])) {
|
||||
if (! isset($processedIds[$userId])) {
|
||||
$processedIds[$userId] = true;
|
||||
$businessUser->deep = 0;
|
||||
$allUsers[] = $businessUser;
|
||||
|
|
@ -1134,17 +1120,17 @@ class TeamController extends Controller
|
|||
\Log::debug("TeamController: Parentless-User übersprungen: {$userId} (bereits verarbeitet)");
|
||||
}
|
||||
} else {
|
||||
\Log::warning("TeamController: Parentless BusinessUser ohne user_id übersprungen");
|
||||
\Log::warning('TeamController: Parentless BusinessUser ohne user_id übersprungen');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\Log::info("TeamController: AllUsers before filtering: " . count($allUsers));
|
||||
\Log::info('TeamController: AllUsers before filtering: '.count($allUsers));
|
||||
// Filter anwenden
|
||||
$filteredUsers = $this->applyTeamFiltersToBusinessUsers($allUsers);
|
||||
\Log::info("TeamController: AllUsers after filtering: " . count($filteredUsers));
|
||||
\Log::info('TeamController: AllUsers after filtering: '.count($filteredUsers));
|
||||
|
||||
return $filteredUsers;
|
||||
}
|
||||
|
|
@ -1161,9 +1147,9 @@ class TeamController extends Controller
|
|||
\Log::info("TeamController: Applying filters - Active: {$activeFilter}, Level: {$levelFilter}, NextLevel: {$nextLevelFilter}");
|
||||
|
||||
// Debug: Zeige verfügbare Eigenschaften des ersten BusinessUsers
|
||||
if (!empty($businessUsers)) {
|
||||
if (! empty($businessUsers)) {
|
||||
$firstUser = $businessUsers[0];
|
||||
\Log::debug("TeamController: First BusinessUser properties", [
|
||||
\Log::debug('TeamController: First BusinessUser properties', [
|
||||
'user_id' => $firstUser->user_id ?? 'not set',
|
||||
'active_account' => $firstUser->active_account ?? 'not set',
|
||||
'm_level_id' => $firstUser->m_level_id ?? 'not set',
|
||||
|
|
@ -1175,7 +1161,7 @@ class TeamController extends Controller
|
|||
$filtered = array_filter($businessUsers, function ($businessUser) use ($activeFilter, $levelFilter, $nextLevelFilter) {
|
||||
// Active Filter anwenden
|
||||
if ($activeFilter == 1) { // Nur aktive
|
||||
if (!$businessUser->active_account) {
|
||||
if (! $businessUser->active_account) {
|
||||
return false;
|
||||
}
|
||||
} elseif ($activeFilter == 2) { // Nur inaktive
|
||||
|
|
@ -1199,12 +1185,12 @@ class TeamController extends Controller
|
|||
|
||||
switch ($nextLevelFilter) {
|
||||
case 1: // Qualifiziert (grün) - hat next_qual_user_level
|
||||
if (!$hasNextQual) {
|
||||
if (! $hasNextQual) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 2: // In Arbeit (gelb) - hat next_can_user_level aber kein next_qual_user_level
|
||||
if ($hasNextQual || !$hasNextCan) {
|
||||
if ($hasNextQual || ! $hasNextCan) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1233,6 +1219,7 @@ class TeamController extends Controller
|
|||
$maxDepth = 20;
|
||||
if ($depth > $maxDepth) {
|
||||
\Log::warning("TeamController: Maximale Sammlungstiefe ({$maxDepth}) erreicht bei Tiefe {$depth}");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1244,6 +1231,7 @@ class TeamController extends Controller
|
|||
// KRITISCHER SCHUTZ: Prüfe ob User bereits gesammelt wurde
|
||||
if (isset($processedIds[$userId])) {
|
||||
\Log::debug("TeamController: Überspringe bereits gesammelten User {$userId} (Duplikat verhindert)");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -1255,8 +1243,8 @@ class TeamController extends Controller
|
|||
\Log::debug("TeamController: Flach gesammelt - User ID: {$userId} at depth {$depth}");
|
||||
|
||||
// Rekursiv ALLE verschachtelten businessUserItems sammeln
|
||||
if (isset($businessUserItem->businessUserItems) && is_array($businessUserItem->businessUserItems) && !empty($businessUserItem->businessUserItems)) {
|
||||
\Log::debug("TeamController: Sammle " . count($businessUserItem->businessUserItems) . " verschachtelte Items von User {$userId}");
|
||||
if (isset($businessUserItem->businessUserItems) && is_array($businessUserItem->businessUserItems) && ! empty($businessUserItem->businessUserItems)) {
|
||||
\Log::debug('TeamController: Sammle '.count($businessUserItem->businessUserItems)." verschachtelte Items von User {$userId}");
|
||||
$this->collectAllBusinessUserItemsFlat($businessUserItem->businessUserItems, $allUsers, $processedIds, $depth + 1);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1276,11 +1264,12 @@ class TeamController extends Controller
|
|||
$maxDepth = 20;
|
||||
if ($deep > $maxDepth) {
|
||||
\Log::warning("TeamController: Maximale Sammlungstiefe ({$maxDepth}) erreicht");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($businessUser->businessUserItems) && is_array($businessUser->businessUserItems)) {
|
||||
\Log::debug("TeamController: Collecting from businessUser with " . count($businessUser->businessUserItems) . " sub-items at depth {$deep}");
|
||||
\Log::debug('TeamController: Collecting from businessUser with '.count($businessUser->businessUserItems)." sub-items at depth {$deep}");
|
||||
|
||||
foreach ($businessUser->businessUserItems as $subBusinessUser) {
|
||||
if ($subBusinessUser) {
|
||||
|
|
@ -1291,6 +1280,7 @@ class TeamController extends Controller
|
|||
// KRITISCHER BUGFIX: Prüfe ob User bereits gesammelt wurde
|
||||
if (isset($processedIds[$userId])) {
|
||||
\Log::debug("TeamController: Überspringe bereits gesammelten User {$userId} (zirkuläre Referenz verhindert)");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -1320,13 +1310,13 @@ class TeamController extends Controller
|
|||
$cleanedUsers = [];
|
||||
|
||||
foreach ($businessUserItems as $businessUserItem) {
|
||||
if (!$businessUserItem) {
|
||||
if (! $businessUserItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
// Extrahiere nur die Properties, die für DataTable benötigt werden
|
||||
$cleanedUser = new \stdClass();
|
||||
$cleanedUser = new \stdClass;
|
||||
|
||||
// Basis Properties (direkt über Magic Method __get)
|
||||
$cleanedUser->user_id = $businessUserItem->user_id;
|
||||
|
|
@ -1354,13 +1344,14 @@ class TeamController extends Controller
|
|||
|
||||
\Log::debug("TeamController: Cleaned user {$cleanedUser->user_id} for DataTable");
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error cleaning BusinessUserItem for DataTable: " . $e->getMessage());
|
||||
\Log::error('TeamController: Error cleaning BusinessUserItem for DataTable: '.$e->getMessage());
|
||||
|
||||
// Skip diesen User, statt alles abzubrechen
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
\Log::info("TeamController: Cleaned " . count($cleanedUsers) . " users for DataTable (from " . count($businessUserItems) . " raw items)");
|
||||
\Log::info('TeamController: Cleaned '.count($cleanedUsers).' users for DataTable (from '.count($businessUserItems).' raw items)');
|
||||
|
||||
return $cleanedUsers;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue