commit 08-2025
This commit is contained in:
parent
9ae662f63e
commit
480fdc65ed
404 changed files with 65310 additions and 2600431 deletions
342
app/Http/Controllers/Admin/ProductsSalesController.php
Normal file
342
app/Http/Controllers/Admin/ProductsSalesController.php
Normal file
|
|
@ -0,0 +1,342 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
use Auth;
|
||||
use Request;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use App\Exports\xExport;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Exports\UserTeamExport;
|
||||
use App\Models\ShoppingOrderItem;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Services\BusinessPlan\ExportBot;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class ProductsSalesController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$this->setFilterVars();
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
];
|
||||
return view('admin.payment.salesvolume', $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function download(){
|
||||
|
||||
/*
|
||||
EXCEL EXPORT function */
|
||||
|
||||
if(Request::get('action') === "exportfull_paid"){
|
||||
return $this->exportFullList(1);
|
||||
}
|
||||
if(Request::get('action') === "exportfull_unpaid"){
|
||||
return $this->exportFullList(0);
|
||||
}
|
||||
|
||||
if(Request::get('action') === "exportfull_paid_invoice"){
|
||||
return $this->exportFullListInvoice();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(Request::get('action') === "export"){
|
||||
$objects = $this->initSearch(false);
|
||||
$columns = [];
|
||||
$filename = "mivita-absatzmengen-".session('product_sales_vol_filter_month').'_'.session('product_sales_vol_filter_year')."-export";
|
||||
$headers = array(
|
||||
'#',
|
||||
'Produkt',
|
||||
'Artikelnummer',
|
||||
'Menge',
|
||||
|
||||
);
|
||||
if($objects){
|
||||
foreach ($objects as $key => $obj){
|
||||
$columns[] = array(
|
||||
'id' => $key,
|
||||
'name' => $obj['name'],
|
||||
'number' => $obj['number'],
|
||||
'value' => $obj['value'],
|
||||
);
|
||||
}
|
||||
}
|
||||
return Excel::download(new UserTeamExport($columns, $headers), $filename.'.xls');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function setFilterVars(){
|
||||
|
||||
if(!session('product_sales_vol_filter_month')){
|
||||
session(['product_sales_vol_filter_month' => intval(date('m'))]);
|
||||
}
|
||||
if(!session('product_sales_vol_filter_year')){
|
||||
session(['product_sales_vol_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
|
||||
if(Request::get('product_sales_vol_filter_month')){
|
||||
session(['product_sales_vol_filter_month' => Request::get('product_sales_vol_filter_month')]);
|
||||
}
|
||||
if(Request::get('product_sales_vol_filter_year')){
|
||||
session(['product_sales_vol_filter_year' => Request::get('product_sales_vol_filter_year')]);
|
||||
}
|
||||
}
|
||||
|
||||
public function exportFullList($paid = 1){
|
||||
|
||||
$date_start = Carbon::parse('01.'.session('product_sales_vol_filter_month').'.'.session('product_sales_vol_filter_year'))->format('Y-m-d H:i:s');
|
||||
$date_end = Carbon::parse('01.'.session('product_sales_vol_filter_month').'.'.session('product_sales_vol_filter_year'))->endOfMonth()->format('Y-m-d H:i:s');
|
||||
$ShoppingOrders = ShoppingOrder::where('paid', $paid)->where('mode', 'live')->whereBetween('created_at', [$date_start, $date_end])->get();
|
||||
|
||||
$txActions = ['prev' => 'keine Zahlung', 'appointed' => 'offen', 'failed' => 'abbruch', 'paid' => 'bezahlt'];
|
||||
$headers = array('ID', 'Zahlung', 'Datum', 'EMail', 'ProduktID', 'ProduktNummer', 'ProduktName', 'Anzahl', 'Notiz', 'Gesamt');
|
||||
$objects = [];
|
||||
$columns = [];
|
||||
$hasSOID = [];
|
||||
foreach($ShoppingOrders as $ShoppingOrder){
|
||||
foreach($ShoppingOrder->shopping_order_items as $shopping_order_item){
|
||||
$value = "";
|
||||
if($shopping_order_item->product){
|
||||
if(isset($objects[$shopping_order_item->product->id])){
|
||||
$value = intval($objects[$shopping_order_item->product->id]['value'] + $shopping_order_item->qty);
|
||||
$objects[$shopping_order_item->product->id]['value'] = $value;
|
||||
}else{
|
||||
$objects[$shopping_order_item->product->id] = [
|
||||
'name' => $shopping_order_item->product->name,
|
||||
'number' => $shopping_order_item->product->number,
|
||||
'value' => $shopping_order_item->qty
|
||||
];
|
||||
$value = $shopping_order_item->qty;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
$object = [];
|
||||
if(in_array($ShoppingOrder->id, $hasSOID)){
|
||||
$object['ID'] = '';
|
||||
$object['EMail'] = '';
|
||||
$object['Zahlung'] = '';
|
||||
$object['Datum'] = '';
|
||||
}else{
|
||||
$object['ID'] = $ShoppingOrder->id;
|
||||
$object['EMail'] = $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->billing_email : 'n/a';
|
||||
$object['Zahlung'] = isset($txActions[$ShoppingOrder->txaction]) ? $txActions[$ShoppingOrder->txaction] : $ShoppingOrder->txaction;
|
||||
$object['Datum'] = $ShoppingOrder->created_at->format('d.m.Y');
|
||||
}
|
||||
$object['ProduktID'] = $shopping_order_item->product_id;
|
||||
$object['ProduktNummer'] = $shopping_order_item->product ? $shopping_order_item->product->number : "n/a";
|
||||
$object['ProduktName'] = $shopping_order_item->product ? $shopping_order_item->product->name : "n/a";
|
||||
$object['Anzahl'] = $shopping_order_item->qty;
|
||||
$object['Notiz'] = ($shopping_order_item->comp ? 'Compensation '.$shopping_order_item->comp : '') . ($shopping_order_item->shopping_collect_order_id ? 'Sammelbestellung '.$shopping_order_item->shopping_collect_order_id : '');
|
||||
$object['Gesamt'] = $value;
|
||||
$columns[] = $object;
|
||||
|
||||
$hasSOID[] = $ShoppingOrder->id;
|
||||
}
|
||||
}
|
||||
if($paid){
|
||||
$filename = "mivita-absatzmengen-full-paid-".session('product_sales_vol_filter_month').'_'.session('product_sales_vol_filter_year')."-export";
|
||||
}else{
|
||||
$filename = "mivita-absatzmengen-full-unpaid-".session('product_sales_vol_filter_month').'_'.session('product_sales_vol_filter_year')."-export";
|
||||
}
|
||||
|
||||
return Excel::download(new xExport($columns, $headers), $filename.'.xls');
|
||||
|
||||
/* CSV EXPORT function
|
||||
$headers = array(
|
||||
"Content-type" => "text/csv",
|
||||
"Content-Disposition" => "attachment; filename=$fileName",
|
||||
"Pragma" => "no-cache",
|
||||
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
|
||||
"Expires" => "0"
|
||||
);
|
||||
|
||||
$header = array('ID', 'Zahlung', 'Datum', 'EMail', 'ProduktID', 'ProduktNummer', 'ProduktName', 'Anzahl', 'Notiz', 'Gesamt');
|
||||
|
||||
$callback = function() use($columns, $header) {
|
||||
|
||||
$file = fopen('php://output', 'w');
|
||||
fputcsv($file, $header);
|
||||
$row = [];
|
||||
|
||||
foreach ($columns as $row) {
|
||||
fputcsv($file, $row);
|
||||
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
};
|
||||
|
||||
return response()->stream($callback, 200, $headers);
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
private function initSearch($returnColl = true)
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$date_start = Carbon::parse('01.'.session('product_sales_vol_filter_month').'.'.session('product_sales_vol_filter_year'))->format('Y-m-d H:i:s');
|
||||
$date_end = Carbon::parse('01.'.session('product_sales_vol_filter_month').'.'.session('product_sales_vol_filter_year'))->endOfMonth()->format('Y-m-d H:i:s');
|
||||
$ShoppingOrders = ShoppingOrder::where('paid', 1)->where('mode', 'live')->whereBetween('created_at', [$date_start, $date_end])->get();
|
||||
|
||||
$objects = [];
|
||||
foreach($ShoppingOrders as $ShoppingOrder){
|
||||
foreach($ShoppingOrder->shopping_order_items as $shopping_order_item){
|
||||
if($shopping_order_item->product){
|
||||
if(isset($objects[$shopping_order_item->product->id])){
|
||||
$value = intval($objects[$shopping_order_item->product->id]['value'] + $shopping_order_item->qty);
|
||||
$objects[$shopping_order_item->product->id]['value'] = $value;
|
||||
}else{
|
||||
$objects[$shopping_order_item->product->id] = [
|
||||
'name' => $shopping_order_item->product->name,
|
||||
'number' => $shopping_order_item->product->number,
|
||||
'value' => $shopping_order_item->qty
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($returnColl){
|
||||
$collection = collect();
|
||||
|
||||
foreach($objects as $key => $obj){
|
||||
$collection->push([
|
||||
'id' => $key,
|
||||
'name' => $obj['name'],
|
||||
'number' => $obj['number'],
|
||||
'value' => $obj['value'],
|
||||
]);
|
||||
}
|
||||
return $collection;
|
||||
}
|
||||
return $objects;
|
||||
}
|
||||
|
||||
|
||||
public function datatable(){
|
||||
|
||||
$collection = $this->initSearch(true);
|
||||
|
||||
$collect = collect([
|
||||
['id' => 1, 'name' => 'John', 'number'=>92012, 'value'=>123],
|
||||
['id' => 2, 'name' => 'Jane', 'number'=>92012, 'value'=>123],
|
||||
['id' => 3, 'name' => 'James', 'number'=>92012, 'value'=>123],
|
||||
]);
|
||||
|
||||
return \DataTables::of($collection)->toJson();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*private function export_vp(){
|
||||
|
||||
$query = User::with('account')->select('users.*')->where('users.deleted_at', '=', null)->where('users.admin', "<", 4)->get();
|
||||
$fileName = "GS-VP-export-".date("d-m-Y").".csv";
|
||||
$headers = array(
|
||||
"Content-type" => "text/csv",
|
||||
"Content-Disposition" => "attachment; filename=$fileName",
|
||||
"Pragma" => "no-cache",
|
||||
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
|
||||
"Expires" => "0"
|
||||
);
|
||||
|
||||
$columns = array('ID', 'Email', 'Firma', 'Anrede', 'Vorname', 'Nachname', 'Mitglied', 'Bis');
|
||||
|
||||
$callback = function() use($query, $columns) {
|
||||
|
||||
$file = fopen('php://output', 'w');
|
||||
fputcsv($file, $columns);
|
||||
$row = [];
|
||||
|
||||
foreach ($query as $val) {
|
||||
$row['ID'] = $val->id;
|
||||
$row['Email'] = $val->email;
|
||||
$row['Firma'] = $val->account->company;
|
||||
$row['Anrede'] = $val->account->salutation == 'mr' ? 'Herr' : 'Frau' ;
|
||||
$row['Vorname'] = $val->account->first_name;
|
||||
$row['Nachname'] = $val->account->last_name;
|
||||
$row['Mitglied'] = $val->payment_account ? ($val->isActiveAccount() ? 'JA' : 'Abgelaufen') : "Nein";
|
||||
$row['Bis'] = $val->payment_account ? $val->getPaymentAccountDateFormat(false) : "-";
|
||||
fputcsv($file, $row);
|
||||
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
};
|
||||
|
||||
return response()->stream($callback, 200, $headers);
|
||||
|
||||
//dd("ok");
|
||||
}*/
|
||||
|
||||
/*private function testCheckFunction(){
|
||||
|
||||
//$date_start = Carbon::parse('01.'.session('product_sales_vol_filter_month').'.'.session('product_sales_vol_filter_year'))->format('Y-m-d');
|
||||
//$date_end = Carbon::parse('01.'.session('product_sales_vol_filter_month').'.'.session('product_sales_vol_filter_year'))->endOfMonth()->format('Y-m-d');
|
||||
|
||||
$date_start = Carbon::parse('01.01.2024')->format('Y-m-d H:i:s');
|
||||
$date_end = Carbon::parse('01.01.2024')->endOfMonth()->format('Y-m-d H:i:s');
|
||||
dump($date_start);
|
||||
dump($date_end);
|
||||
|
||||
$ShoppingOrders = ShoppingOrder::where('mode', 'live')->whereBetween('created_at', [$date_start, $date_end])->get();
|
||||
|
||||
$objects = [];
|
||||
$counter = 0;
|
||||
foreach($ShoppingOrders as $ShoppingOrder){
|
||||
foreach($ShoppingOrder->shopping_order_items as $shopping_order_item){
|
||||
|
||||
if($shopping_order_item->product){
|
||||
if($shopping_order_item->product->id === 122){
|
||||
//dump($shopping_order_item->qty);
|
||||
//$counter += $shopping_order_item->qty;
|
||||
if(isset($objects[$shopping_order_item->product->id])){
|
||||
$value = intval($objects[$shopping_order_item->product->id]['value'] + $shopping_order_item->qty);
|
||||
$objects[$shopping_order_item->product->id]['value'] = $value;
|
||||
}else{
|
||||
$objects[$shopping_order_item->product->id] = [
|
||||
'name' => $shopping_order_item->product->name,
|
||||
'number' => $shopping_order_item->product->number,
|
||||
'value' => $shopping_order_item->qty
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$ShoppingOrderItems = ShoppingOrderItem::whereProductId(122)->whereBetween('created_at', [$date_start, $date_end])->get();
|
||||
$counter = 0;
|
||||
foreach($ShoppingOrderItems as $ShoppingOrderItem){
|
||||
$counter += $ShoppingOrderItem->qty;
|
||||
dump($ShoppingOrderItem->id);
|
||||
}
|
||||
// dump($objects);
|
||||
dump($counter);
|
||||
dd("OKAY");
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -65,11 +65,11 @@ class AdminUserController extends Controller
|
|||
$data = Request::all();
|
||||
$user = User::findOrFail($data['id']);
|
||||
|
||||
if(isset($data['user-delete'])){
|
||||
/* if(isset($data['user-delete'])){
|
||||
if(isset($data['realy_delete_user'])){
|
||||
return redirect(route('admin_user_delete', [$user->id]));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if(isset($data['save-admin'])){
|
||||
$user->admin = $data['admin'];
|
||||
SysLog::action('save-admin', 'admin_user', 3)
|
||||
|
|
@ -187,12 +187,19 @@ class AdminUserController extends Controller
|
|||
return redirect('/admin/users');
|
||||
}
|
||||
|
||||
public function deleteUser($user_id)
|
||||
public function deleteUser()
|
||||
{
|
||||
$user = User::findOrFail($user_id);
|
||||
$this->userRepo->deleteUser($user);
|
||||
|
||||
\Session()->flash('alert-success', __('msg.contact_delete'));
|
||||
$data = Request::all();
|
||||
$user = User::withTrashed()->findOrFail($data['id']);
|
||||
if(isset($data['realy_delete_user'])){
|
||||
$this->userRepo->deleteUser($user);
|
||||
\Session()->flash('alert-success', __('msg.contact_delete'));
|
||||
}
|
||||
if(isset($data['realy_delete_user_complete'])){
|
||||
// $this->userRepo->deleteUserComplete($user);
|
||||
$this->userRepo->deleteUser($user, true);
|
||||
\Session()->flash('alert-success', __('msg.contact_delete'));
|
||||
}
|
||||
return redirect('/admin/users');
|
||||
|
||||
}
|
||||
|
|
@ -208,12 +215,28 @@ class AdminUserController extends Controller
|
|||
|
||||
public function getUsers()
|
||||
{
|
||||
$query = User::with('account')->select('users.*')->where('users.deleted_at', '=', null)->where('users.admin', "<", 5);
|
||||
$query = User::withTrashed()
|
||||
->where(function($q) {
|
||||
$q->where('pre_deleted_at', '!=', null)
|
||||
->orWhere(function($query) {
|
||||
$query->whereNull('deleted_at')
|
||||
->whereNull('pre_deleted_at');
|
||||
});
|
||||
})
|
||||
->with('account')
|
||||
->select('users.*')
|
||||
->where('users.admin', "<", 5);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('first_name', function (User $user) {
|
||||
return $user->account ? $user->account->first_name : '';
|
||||
})
|
||||
->addColumn('email', function (User $user) {
|
||||
if($user->pre_deleted_at){
|
||||
return '<span class="badge badge-pill badge-danger">'.$user->email.'</span>';
|
||||
}
|
||||
return $user->email;
|
||||
})
|
||||
->addColumn('last_name', function (User $user) {
|
||||
return $user->account ? $user->account->last_name : '';
|
||||
})
|
||||
|
|
@ -288,11 +311,12 @@ class AdminUserController extends Controller
|
|||
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('email', 'email $1')
|
||||
->orderColumn('confirmed', 'confirmed $1')
|
||||
->orderColumn('active', 'active $1')
|
||||
->orderColumn('shop', 'shop $1')
|
||||
->orderColumn('admin', 'active $1')
|
||||
->rawColumns(['id', 'admin', 'confirmed', 'active', 'account', 'shop', 'my_payment_methods', 'test_mode', 'action_login', 'action_delete'])
|
||||
->rawColumns(['id', 'email', 'admin', 'confirmed', 'active', 'account', 'shop', 'my_payment_methods', 'test_mode', 'action_login', 'action_delete'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,96 +2,60 @@
|
|||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product as ModelsProduct;
|
||||
use Vitalybaev\GoogleMerchant\Feed;
|
||||
use Vitalybaev\GoogleMerchant\Product;
|
||||
use Vitalybaev\GoogleMerchant\Product\Shipping;
|
||||
use Vitalybaev\GoogleMerchant\Product\Availability\Availability;
|
||||
use Illuminate\Http\Response;
|
||||
use Wearepixel\LaravelGoogleShoppingFeed\LaravelGoogleShoppingFeed;
|
||||
use App\Services\Util;
|
||||
|
||||
|
||||
class GoogleMerchantController extends Controller
|
||||
{
|
||||
public function __construct() {}
|
||||
|
||||
|
||||
public function __construct()
|
||||
/**
|
||||
* Generate Google Merchant feed
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function feed()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function feed(){
|
||||
|
||||
$products = ModelsProduct::where('active', true)->whereJsonContains('show_on', '1')->orderBy('pos', 'DESC')->get();
|
||||
|
||||
// Create feed object
|
||||
$feed = new Feed("mivita shop", "https://mivita.shop", "Bio Aloe Vera & Naturkosmetuk");
|
||||
$feed = LaravelGoogleShoppingFeed::init(
|
||||
'mivita shop',
|
||||
'Bio Aloe Vera & Naturkosmetik',
|
||||
'https://mivita.shop'
|
||||
);
|
||||
|
||||
// Put products to the feed ($products - some data from database for example)
|
||||
// Put products to the feed
|
||||
foreach ($products as $product) {
|
||||
$item = new Product();
|
||||
|
||||
// Set common product properties
|
||||
$item->setId($product->id);
|
||||
$item->setTitle($product->name);
|
||||
$item->setDescription($product->copy);
|
||||
$item->setLink($product->getProductUrl());
|
||||
$item->setImage($product->getImageUrl());
|
||||
$item->setAvailability(Availability::IN_STOCK);
|
||||
|
||||
/*if ($product->isAvailable()) {
|
||||
$item->setAvailability(Availability::IN_STOCK);
|
||||
} else {
|
||||
$item->setAvailability(Availability::OUT_OF_STOCK);
|
||||
}*/
|
||||
$item->setPrice("{$product->price} EUR");
|
||||
//$item->setGoogleCategory($product->category_name);
|
||||
$item->setBrand('MIVITA');
|
||||
$item->setGtin($product->ean);
|
||||
$item->setCondition('new');
|
||||
|
||||
// Some additional properties
|
||||
//$item->setColor($product->color);
|
||||
//$item->setSize($product->size);
|
||||
|
||||
// Shipping info
|
||||
/*
|
||||
$shipping = new Shipping();
|
||||
$shipping->setCountry('US');
|
||||
$shipping->setRegion('CA, NSW, 03');
|
||||
$shipping->setPostalCode('94043');
|
||||
$shipping->setLocationId('21137');
|
||||
$shipping->setService('DHL');
|
||||
$shipping->setPrice('1300 USD');
|
||||
$item->setShipping($shipping);
|
||||
*/
|
||||
|
||||
// Set a custom shipping label and weight (optional)
|
||||
//$item->setShippingLabel('ups-ground');
|
||||
//$item->setShippingWeight('2.14');
|
||||
|
||||
// Set a custom label (optional)
|
||||
$item->setCustomLabel($product->weight, 'product_width');
|
||||
$item->setCustomLabel($product->contents_total, 'product_contents_total');
|
||||
$item->setCustomLabel($product->getUnitType(), 'product_contents_unit',);
|
||||
$item->setCustomLabel($product->contents_str, 'product_contents');
|
||||
$item->setCustomLabel($product->ingredients, 'product_ingredients');
|
||||
|
||||
$item->setCustomLabel($product->getBasePriceFormattedFullWith(false, false, null), 'product_base_pricing_unit');
|
||||
|
||||
|
||||
//$item->setCustomLabel('Some Label 2', 1);
|
||||
|
||||
// Add this product to the feed
|
||||
$feed->addProduct($item);
|
||||
$feed->addItem([
|
||||
'id' => $product->id,
|
||||
'title' => $product->name,
|
||||
'description' => $product->copy,
|
||||
'link' => $product->getProductUrl(),
|
||||
'g:image_link' => $product->getImageUrl(),
|
||||
'g:availability' => 'in stock',
|
||||
'g:price' => "{$product->price} EUR",
|
||||
'g:brand' => 'MIVITA',
|
||||
'g:gtin' => $product->ean,
|
||||
'g:condition' => 'new',
|
||||
'g:custom_label_0' => $product->weight,
|
||||
'g:custom_label_1' => $product->contents_total,
|
||||
'g:custom_label_2' => $product->getUnitType(),
|
||||
'g:custom_label_3' => $product->contents_str,
|
||||
'g:custom_label_4' => $product->ingredients,
|
||||
'g:unit_pricing_measure' => $product->getBasePriceFormattedFullWith(false, false, null)
|
||||
]);
|
||||
}
|
||||
|
||||
// Here we get complete XML of the feed, that we could write to file or send directly
|
||||
$feedXml = $feed->build();
|
||||
print ($feedXml);
|
||||
return $feed->generate();
|
||||
// Get the feed XML
|
||||
//$feedXml = $feed->toString();
|
||||
//return response($feedXml)->header('Content-Type', 'application/xml');
|
||||
}
|
||||
|
||||
// http://api.mivita.test/google/merchant/feed
|
||||
|
||||
}
|
||||
// http://api.mivita.test/google/merchant/feed
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
|||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
|
||||
class LoginController extends Controller
|
||||
|
|
@ -40,12 +41,47 @@ class LoginController extends Controller
|
|||
$this->middleware('guest')->except('logout');
|
||||
}
|
||||
|
||||
public function showLoginForm()
|
||||
{
|
||||
//login als Kunde, dann zum Login wechseln
|
||||
if(Auth::guard('customers')->check()){
|
||||
return redirect()->route('change_login');
|
||||
}
|
||||
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
public function showChangeLogin(){
|
||||
if(Auth::guard('customers')->check()){
|
||||
return view('auth.change');
|
||||
}
|
||||
if(Auth::guard('user')->check()){
|
||||
return redirect(route('home'));
|
||||
|
||||
}
|
||||
return redirect(route('login'));
|
||||
|
||||
}
|
||||
|
||||
public function confirmChangeLogin(Request $request)
|
||||
{
|
||||
//$url = Util::getMyMivitaShopUrl();
|
||||
$user_shop_domain = session('user_shop_domain');
|
||||
$locale = session('locale');
|
||||
Auth::guard('customers')->logout();
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
session(['user_shop_domain' => $user_shop_domain]);
|
||||
session(['locale' => $locale]);
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
protected function authenticated(Request $request, $user)
|
||||
{
|
||||
$user->last_login = date('Y-m-d H:i:s');
|
||||
$user->save();
|
||||
}
|
||||
|
||||
protected function handleUserWasAuthenticated(Request $request, $throttles)
|
||||
{
|
||||
|
||||
|
|
|
|||
577
app/Http/Controllers/BusinessControllerOptimized.php
Normal file
577
app/Http/Controllers/BusinessControllerOptimized.php
Normal file
|
|
@ -0,0 +1,577 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\UserBusiness;
|
||||
use App\Models\UserBusinessStructure;
|
||||
use App\Services\BusinessPlan\BusinessUserRepository;
|
||||
use App\Services\BusinessPlan\TreeCalcBotOptimized;
|
||||
use App\Services\BusinessPlan\TreeHelperOptimized;
|
||||
use App\Services\BusinessPlan\TreeHtmlRenderer;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Services\NextLevelBadgeHelper;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Request;
|
||||
|
||||
/**
|
||||
* Optimierte Version des BusinessController
|
||||
*
|
||||
* Verbesserungen:
|
||||
* - Nutzt TreeCalcBotOptimized für bessere Performance
|
||||
* - Optimierte Datenbankabfragen durch Repository Pattern
|
||||
* - Memory-effiziente Verarbeitung großer Datenmengen
|
||||
* - Robuste Fehlerbehandlung mit Logging
|
||||
* - Performance-Monitoring für Debugging
|
||||
*/
|
||||
class BusinessControllerOptimized extends Controller
|
||||
{
|
||||
private $filter_active = [1 => 'aktiv', 2 => 'nicht aktiv', 3 => 'alle'];
|
||||
private $filter_next_level = [
|
||||
0 => 'Alle Status',
|
||||
1 => 'Qualifiziert (grün)',
|
||||
2 => 'In Arbeit (gelb)',
|
||||
3 => 'Kein Level (rot)'
|
||||
];
|
||||
private $month;
|
||||
private $year;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeigt die Business-Übersicht (identisch zur Original-Version)
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(),
|
||||
'filter_active' => $this->filter_active,
|
||||
'filter_levels' => $this->getFilterLevels(),
|
||||
'filter_next_level' => $this->filter_next_level,
|
||||
'optimized' => true, // Flag für View um zu zeigen, dass optimierte Version läuft
|
||||
];
|
||||
|
||||
return view('admin.business_optimized.show', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeigt die Business-Struktur mit optimierter TreeCalcBot-Version
|
||||
*/
|
||||
public function structure()
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
$startMemory = memory_get_usage();
|
||||
|
||||
try {
|
||||
$this->setFilterVars();
|
||||
$this->month = session('business_user_filter_month');
|
||||
$this->year = session('business_user_filter_year');
|
||||
|
||||
Log::info("BusinessControllerOptimized: Building structure for {$this->month}/{$this->year}");
|
||||
|
||||
// Verwende optimierte TreeCalcBot-Version
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'admin');
|
||||
|
||||
// Prüfe ob Live-Berechnung für Struktur erzwungen wird
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) ||
|
||||
Request::get('force_live_structure', false) ||
|
||||
Request::get('live', false);
|
||||
|
||||
if ($forceLiveCalculation) {
|
||||
Log::info("BusinessControllerOptimized: Force live calculation requested");
|
||||
$TreeCalcBot->initStructureAdmin(true, $forceLiveCalculation); // check=true, forceLiveCalculation=true
|
||||
} else {
|
||||
$TreeCalcBot->initStructureAdmin(); // Standard: verwende gespeicherte wenn verfügbar
|
||||
}
|
||||
|
||||
$endTime = microtime(true);
|
||||
$endMemory = memory_get_usage();
|
||||
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$memoryUsed = $this->formatBytes($endMemory - $startMemory);
|
||||
|
||||
$calculationType = $forceLiveCalculation ? " (LIVE)" : " (CACHE)";
|
||||
Log::info("BusinessControllerOptimized: Structure built in {$executionTime}ms, Memory: {$memoryUsed}{$calculationType}");
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(),
|
||||
'TreeCalcBot' => $TreeCalcBot,
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'memory_used' => $memoryUsed,
|
||||
'user_count' => $TreeCalcBot->getTotalUserCount(),
|
||||
'parentless_count' => $TreeCalcBot->isParentless() ? count($TreeCalcBot->__get('parentless')) : 0,
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache'
|
||||
],
|
||||
'optimized' => true,
|
||||
'forceLiveCalculation' => $forceLiveCalculation,
|
||||
];
|
||||
|
||||
return view('admin.business_optimized.structure', $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("BusinessControllerOptimized: Error in structure: " . $e->getMessage());
|
||||
|
||||
return view('admin.business_optimized.error', [
|
||||
'error' => $e->getMessage(),
|
||||
'month' => $this->month,
|
||||
'year' => $this->year
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeigt User-Details mit optimierter Performance
|
||||
*/
|
||||
public function userDetail($user_id)
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
|
||||
try {
|
||||
$user = User::with(['account', 'user_level', 'user_sponsor.account'])->findOrFail($user_id);
|
||||
$this->setFilterVars();
|
||||
|
||||
$data = [];
|
||||
$data['month'] = session('business_user_filter_month');
|
||||
$data['year'] = session('business_user_filter_year');
|
||||
|
||||
Log::info("BusinessControllerOptimized: Building user detail for user {$user_id}");
|
||||
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($data['month'], $data['year'], 'admin');
|
||||
|
||||
// Prüfe ob Live-Berechnung über URL-Parameter erzwungen wird
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) ||
|
||||
Request::get('force_live', false) ||
|
||||
Request::get('live', false);
|
||||
|
||||
if ($forceLiveCalculation) {
|
||||
Log::info("BusinessControllerOptimized: Force live calculation requested for user {$user_id}");
|
||||
}
|
||||
|
||||
$TreeCalcBot->initBusinesslUserDetail($user, $forceLiveCalculation);
|
||||
|
||||
if (!$TreeCalcBot->__get('business_user')) {
|
||||
Log::warning("BusinessControllerOptimized: No business user found for {$user_id}");
|
||||
abort(403, 'No business user found');
|
||||
}
|
||||
|
||||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
|
||||
$data['performance'] = [
|
||||
'execution_time' => $executionTime,
|
||||
'user_id' => $user_id,
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache'
|
||||
];
|
||||
|
||||
$data['forceLiveCalculation'] = $forceLiveCalculation;
|
||||
|
||||
$calculationType = $forceLiveCalculation ? " (LIVE)" : " (CACHE)";
|
||||
Log::info("BusinessControllerOptimized: User detail built in {$executionTime}ms{$calculationType}");
|
||||
|
||||
return view('admin.business_optimized.user_detail', compact('TreeCalcBot', 'user', 'data'));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("BusinessControllerOptimized: Error in userDetail for {$user_id}: " . $e->getMessage());
|
||||
|
||||
return view('admin.business_optimized.error', [
|
||||
'error' => $e->getMessage(),
|
||||
'user_id' => $user_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store-Funktion (identisch zur Original-Version)
|
||||
*/
|
||||
public function userStore($user_id)
|
||||
{
|
||||
dd('function on: App\Console\Commands\BusinessStore');
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimierte DataTable für Users mit besserer Performance
|
||||
*/
|
||||
public function userDatatable(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$this->month = Request::get('business_user_filter_month');
|
||||
$this->year = Request::get('business_user_filter_year');
|
||||
|
||||
Log::info("BusinessControllerOptimized: Building datatable for {$this->month}/{$this->year}");
|
||||
|
||||
// Prüfe ob optimierte Repository-Daten verfügbar sind
|
||||
if (TreeCalcBotOptimized::isFromStored($this->month, $this->year)) {
|
||||
return $this->userStoredDatatableOptimized();
|
||||
} else {
|
||||
return $this->userCurrentlyDatatableOptimized();
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("BusinessControllerOptimized: Error in userDatatable: " . $e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'error' => 'Datatable could not be loaded: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimierte Stored-Datatable mit besserer Query-Performance
|
||||
*/
|
||||
private function userStoredDatatableOptimized(): JsonResponse
|
||||
{
|
||||
$query = $this->initStoredSearchOptimized();
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (UserBusiness $userBusiness) {
|
||||
return TreeHelperOptimized::generateActionButtons($userBusiness->user_id);
|
||||
})
|
||||
->addColumn('m_account', function (UserBusiness $userBusiness) {
|
||||
return e($userBusiness->m_account);
|
||||
})
|
||||
->addColumn('user_level', function (UserBusiness $userBusiness) {
|
||||
return e($userBusiness->user_level_name);
|
||||
})
|
||||
->addColumn('is_qual_kp', function (UserBusiness $userBusiness) {
|
||||
return TreeHelperOptimized::generateQualKPBadge($userBusiness);
|
||||
})
|
||||
->addColumn('sales_volume_KP_points', function (UserBusiness $userBusiness) {
|
||||
return TreeHelperOptimized::generateSalesVolumeDisplay($userBusiness, 'points');
|
||||
})
|
||||
->addColumn('sales_volume_total', function (UserBusiness $userBusiness) {
|
||||
return TreeHelperOptimized::generateSalesVolumeDisplay($userBusiness, 'total');
|
||||
})
|
||||
->addColumn('email', function (UserBusiness $userBusiness) {
|
||||
return e($userBusiness->email);
|
||||
})
|
||||
->addColumn('first_name', function (UserBusiness $userBusiness) {
|
||||
return e($userBusiness->first_name);
|
||||
})
|
||||
->addColumn('last_name', function (UserBusiness $userBusiness) {
|
||||
return e($userBusiness->last_name);
|
||||
})
|
||||
->addColumn('sponsor', function (UserBusiness $userBusiness) {
|
||||
return TreeHelperOptimized::generateSponsorDisplay($userBusiness);
|
||||
})
|
||||
->addColumn('active_account', function (UserBusiness $userBusiness) {
|
||||
return get_active_badge($userBusiness->active_account);
|
||||
})
|
||||
->addColumn('next_level_qualified', function (UserBusiness $userBusiness) {
|
||||
return NextLevelBadgeHelper::generateBadgeFromUserBusiness($userBusiness);
|
||||
})
|
||||
->addColumn('payment_account_date', function (UserBusiness $userBusiness) {
|
||||
return $userBusiness->active_date ? formatDate($userBusiness->active_date) : "-";
|
||||
})
|
||||
->filterColumn('m_account', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("user_businesses.m_account LIKE ?", '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->filterColumn('first_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("user_businesses.first_name LIKE ?", '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->filterColumn('last_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("user_businesses.last_name LIKE ?", '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->filterColumn('email', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("user_businesses.email LIKE ?", '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('m_account', 'm_account $1')
|
||||
->orderColumn('email', 'email $1')
|
||||
->orderColumn('first_name', 'first_name $1')
|
||||
->orderColumn('last_name', 'last_name $1')
|
||||
->orderColumn('active_account', 'payment_account $1')
|
||||
->rawColumns(['id', 'is_qual_kp', 'sales_volume_KP_points', 'sales_volume_total', 'sponsor', 'active_account', 'next_level_qualified'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimierte Currently-Datatable mit Repository Pattern
|
||||
*/
|
||||
private function userCurrentlyDatatableOptimized(): JsonResponse
|
||||
{
|
||||
$repository = new BusinessUserRepository($this->month, $this->year);
|
||||
|
||||
// Nutze Repository für optimierte Abfragen
|
||||
$query = $this->initCurrentlySearchOptimized();
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (User $user) {
|
||||
return TreeHelperOptimized::generateActionButtons($user->id);
|
||||
})
|
||||
->addColumn('m_account', function (User $user) {
|
||||
return $user->account ? e($user->account->m_account) : '';
|
||||
})
|
||||
->addColumn('user_level', function (User $user) {
|
||||
return $user->user_level ? e($user->user_level->getLang('name')) : '';
|
||||
})
|
||||
->addColumn('is_qual_kp', function (User $user) {
|
||||
return TreeHelperOptimized::generateQualKPBadgeForUser($user, $this->month, $this->year);
|
||||
})
|
||||
->addColumn('sales_volume_KP_points', function (User $user) {
|
||||
return TreeHelperOptimized::generateSalesVolumeDisplayForUser($user, 'points', $this->month, $this->year);
|
||||
})
|
||||
->addColumn('sales_volume_total', function (User $user) {
|
||||
return TreeHelperOptimized::generateSalesVolumeDisplayForUser($user, 'total', $this->month, $this->year);
|
||||
})
|
||||
->addColumn('email', function (User $user) {
|
||||
return e($user->email);
|
||||
})
|
||||
->addColumn('first_name', function (User $user) {
|
||||
return $user->account ? e($user->account->first_name) : '';
|
||||
})
|
||||
->addColumn('last_name', function (User $user) {
|
||||
return $user->account ? e($user->account->last_name) : '';
|
||||
})
|
||||
->addColumn('sponsor', function (User $user) {
|
||||
return TreeHelperOptimized::generateSponsorDisplayForUser($user);
|
||||
})
|
||||
->addColumn('active_account', function (User $user) {
|
||||
return get_active_badge($user->isActiveAccount());
|
||||
})
|
||||
->addColumn('next_level_qualified', function (User $user) {
|
||||
// Für Live-DataTable: Verwende bereits berechnete Daten wenn verfügbar
|
||||
$userBusiness = UserBusiness::where('user_id', $user->id)
|
||||
->where('month', $this->month)
|
||||
->where('year', $this->year)
|
||||
->first();
|
||||
|
||||
if ($userBusiness) {
|
||||
return NextLevelBadgeHelper::generateBadgeFromUserBusiness($userBusiness);
|
||||
}
|
||||
|
||||
return NextLevelBadgeHelper::renderNoDataBadge();
|
||||
})
|
||||
->addColumn('payment_account_date', function (User $user) {
|
||||
return $user->payment_account ? $user->getPaymentAccountDateFormat(false) : "-";
|
||||
})
|
||||
->filterColumn('m_account', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("user_businesses.m_account LIKE ?", '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->filterColumn('first_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("user_businesses.first_name LIKE ?", '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->filterColumn('last_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("user_businesses.last_name LIKE ?", '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->filterColumn('email', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("user_businesses.email LIKE ?", '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->orderColumn('id', 'users.id $1')
|
||||
->orderColumn('m_account', 'user_accounts.m_account $1')
|
||||
->orderColumn('first_name', 'first_name $1')
|
||||
->orderColumn('last_name', 'last_name $1')
|
||||
->orderColumn('email', 'users.email $1')
|
||||
->orderColumn('active_account', 'users.payment_account $1')
|
||||
->rawColumns(['id', 'is_qual_kp', 'sales_volume_KP_points', 'sales_volume_total', 'sponsor', 'active_account', 'next_level_qualified'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
// ===== PRIVATE HELPER METHODS =====
|
||||
|
||||
/**
|
||||
* Optimierte Stored Search Query
|
||||
*/
|
||||
private function initStoredSearchOptimized()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$query = UserBusiness::select('user_businesses.*')
|
||||
->where('month', $this->month)
|
||||
->where('year', $this->year);
|
||||
|
||||
$activeFilter = Request::get('business_user_filter_active') ?: session('business_user_filter_active');
|
||||
if ($activeFilter == 1) {
|
||||
$query->where('user_businesses.active_account', 1);
|
||||
} elseif ($activeFilter == 2) {
|
||||
$query->where('user_businesses.active_account', 0);
|
||||
}
|
||||
// activeFilter == 3 bedeutet alle (keine weitere Einschränkung)
|
||||
|
||||
$levelFilter = Request::get('business_user_filter_level') ?: session('business_user_filter_level');
|
||||
if ($levelFilter && $levelFilter != 0) {
|
||||
$query->where('user_businesses.m_level_id', $levelFilter);
|
||||
}
|
||||
|
||||
$nextLevelFilter = Request::get('business_user_filter_next_level') ?: session('business_user_filter_next_level');
|
||||
if ($nextLevelFilter && $nextLevelFilter != 0) {
|
||||
switch ($nextLevelFilter) {
|
||||
case 1: // Qualifiziert (grün) - hat next_qual_user_level
|
||||
$query->whereNotNull('user_businesses.next_qual_user_level')
|
||||
->where('user_businesses.next_qual_user_level', '!=', '[]');
|
||||
break;
|
||||
case 2: // In Arbeit (gelb) - hat next_can_user_level aber kein next_qual_user_level
|
||||
$query->where(function($q) {
|
||||
$q->whereNull('user_businesses.next_qual_user_level')
|
||||
->orWhere('user_businesses.next_qual_user_level', '=', '[]');
|
||||
})
|
||||
->whereNotNull('user_businesses.next_can_user_level')
|
||||
->where('user_businesses.next_can_user_level', '!=', '[]');
|
||||
break;
|
||||
case 3: // Kein Level (rot) - hat weder next_qual noch next_can
|
||||
$query->where(function($q) {
|
||||
$q->where(function($q1) {
|
||||
$q1->whereNull('user_businesses.next_qual_user_level')
|
||||
->orWhere('user_businesses.next_qual_user_level', '=', '[]');
|
||||
})
|
||||
->where(function($q2) {
|
||||
$q2->whereNull('user_businesses.next_can_user_level')
|
||||
->orWhere('user_businesses.next_can_user_level', '=', '[]');
|
||||
});
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimierte Currently Search Query mit besseren Joins
|
||||
*/
|
||||
private function initCurrentlySearchOptimized()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$query = User::with(['account', 'user_level', 'user_sponsor.account'])
|
||||
->select('users.*', 'user_accounts.m_account', 'user_accounts.first_name', 'user_accounts.last_name')
|
||||
->leftJoin('user_accounts', 'users.id', '=', 'user_accounts.id')
|
||||
->where('users.deleted_at', '=', null)
|
||||
->where('users.id', '!=', 1)
|
||||
->where('users.admin', '<', 4)
|
||||
->where('users.m_level', '!=', null)
|
||||
->where('users.payment_account', '!=', null);
|
||||
|
||||
$activeFilter = Request::get('business_user_filter_active') ?: session('business_user_filter_active');
|
||||
if ($activeFilter == 1) {
|
||||
$query->where('users.payment_account', '>=', now());
|
||||
} elseif ($activeFilter == 2) {
|
||||
$query->where('users.payment_account', '<', now());
|
||||
}
|
||||
// activeFilter == 3 bedeutet alle (keine weitere Einschränkung)
|
||||
|
||||
$levelFilter = Request::get('business_user_filter_level') ?: session('business_user_filter_level');
|
||||
if ($levelFilter && $levelFilter != 0) {
|
||||
$query->where('users.m_level', $levelFilter);
|
||||
}
|
||||
|
||||
// Next-Level-Filter wird bei Live-Berechnungen ignoriert (Performance-Gründe)
|
||||
// Dieser Filter funktioniert nur mit gespeicherten Daten
|
||||
$nextLevelFilter = Request::get('business_user_filter_next_level') ?: session('business_user_filter_next_level');
|
||||
if ($nextLevelFilter && $nextLevelFilter != 0) {
|
||||
Log::info("BusinessControllerOptimized: Next-Level-Filter bei Live-Berechnung ignoriert (Performance-Gründe)");
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter-Variablen setzen (identisch zur Original-Version)
|
||||
*/
|
||||
private function setFilterVars()
|
||||
{
|
||||
if (!session('business_user_filter_month')) {
|
||||
session(['business_user_filter_month' => intval(date('m'))]);
|
||||
}
|
||||
if (!session('business_user_filter_year')) {
|
||||
session(['business_user_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
if (!session('business_user_filter_active')) {
|
||||
session(['business_user_filter_active' => 1]);
|
||||
}
|
||||
if (!session('business_user_filter_level')) {
|
||||
session(['business_user_filter_level' => 0]);
|
||||
}
|
||||
if (!session('business_user_filter_next_level')) {
|
||||
session(['business_user_filter_next_level' => 0]);
|
||||
}
|
||||
if (!session('business_user_filter_depiction')) {
|
||||
session(['business_user_filter_depiction' => 'active']);
|
||||
}
|
||||
|
||||
if (Request::get('business_user_filter_depiction')) {
|
||||
session(['business_user_filter_depiction' => Request::get('business_user_filter_depiction')]);
|
||||
}
|
||||
if (Request::get('business_user_filter_name')) {
|
||||
session(['business_user_filter_name' => Request::get('business_user_filter_name')]);
|
||||
} else {
|
||||
session(['business_user_filter_name' => '']);
|
||||
}
|
||||
if (Request::get('business_user_filter_active')) {
|
||||
session(['business_user_filter_active' => Request::get('business_user_filter_active')]);
|
||||
}
|
||||
if (Request::get('business_user_filter_level')) {
|
||||
session(['business_user_filter_level' => Request::get('business_user_filter_level')]);
|
||||
} else {
|
||||
session(['business_user_filter_level' => 0]);
|
||||
}
|
||||
if (Request::get('business_user_filter_next_level')) {
|
||||
session(['business_user_filter_next_level' => Request::get('business_user_filter_next_level')]);
|
||||
} else {
|
||||
session(['business_user_filter_next_level' => 0]);
|
||||
}
|
||||
if (Request::get('business_user_filter_month')) {
|
||||
session(['business_user_filter_month' => Request::get('business_user_filter_month')]);
|
||||
}
|
||||
if (Request::get('business_user_filter_year')) {
|
||||
session(['business_user_filter_year' => Request::get('business_user_filter_year')]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatiert Bytes in lesbare Einheiten
|
||||
*/
|
||||
private function formatBytes(int $bytes, int $precision = 2): string
|
||||
{
|
||||
$units = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
|
||||
for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) {
|
||||
$bytes /= 1024;
|
||||
}
|
||||
|
||||
return round($bytes, $precision) . ' ' . $units[$i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt verfügbare User Level für Filter
|
||||
*/
|
||||
private function getFilterLevels(): array
|
||||
{
|
||||
$levels = [0 => 'Alle Level'];
|
||||
|
||||
$userLevels = \App\Models\UserLevel::orderBy('pos')->get(['id', 'name']);
|
||||
foreach ($userLevels as $level) {
|
||||
$levels[$level->id] = $level->name;
|
||||
}
|
||||
|
||||
return $levels;
|
||||
}
|
||||
|
||||
// Performance-optimierte Badge-Generierung wurde in NextLevelBadgeHelper ausgelagert
|
||||
// Alte performance-lastige Methoden wurden entfernt um die Datatable-Performance zu verbessern
|
||||
}
|
||||
|
|
@ -129,6 +129,21 @@ class HomeController extends Controller
|
|||
return abort(404);
|
||||
}
|
||||
*/
|
||||
public function zahlungsarten(){
|
||||
return view('web.templates.zahlungsarten', [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'isMivitaShop' => Util::isMivitaShop(),
|
||||
'yard_instance' => 'webshop',
|
||||
]);
|
||||
}
|
||||
|
||||
public function versandkosten(){
|
||||
return view('web.templates.versandkosten', [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'isMivitaShop' => Util::isMivitaShop(),
|
||||
'yard_instance' => 'webshop',
|
||||
]);
|
||||
}
|
||||
|
||||
public function legalDataProtected()
|
||||
{
|
||||
|
|
@ -136,6 +151,7 @@ class HomeController extends Controller
|
|||
'modal' => false,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'isMivitaShop' => Util::isMivitaShop(),
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
return view('legal.data_protected', $data);
|
||||
}
|
||||
|
|
@ -145,15 +161,20 @@ class HomeController extends Controller
|
|||
$data = [
|
||||
'modal' => false,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'yard_instance' => 'webshop',
|
||||
'yard_instance' => 'webshop',
|
||||
|
||||
];
|
||||
return view('legal.agb', $data);
|
||||
}
|
||||
|
||||
public function legalImprint()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'modal' => false,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
return view('legal.imprint', $data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class LeadController extends Controller
|
|||
$user->account->shipping_country_id = 1;
|
||||
$user->id = "new";
|
||||
}else{
|
||||
$user = User::findOrFail($id);
|
||||
$user = User::withTrashed()->findOrFail($id);
|
||||
if(!$user->account){
|
||||
$user->account = new UserAccount();
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ class LeadController extends Controller
|
|||
$user->account->shipping_country_id = 1;
|
||||
$user->id = "new";
|
||||
}else{
|
||||
$user = User::findOrFail($id);
|
||||
$user = User::withTrashed()->findOrFail($id);
|
||||
if(!$user->account){
|
||||
$user->account = new UserAccount();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use App\Models\HomepartyUser;
|
|||
use App\Models\ShoppingOrder;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Services\BusinessPlan\TreeCalcBot;
|
||||
use App\Services\BusinessPlan\TreeCalcBotOptimized;
|
||||
|
||||
class ModalController extends Controller
|
||||
{
|
||||
|
|
@ -122,6 +123,8 @@ class ModalController extends Controller
|
|||
$data['month'] = session('team_user_filter_month');
|
||||
$data['year'] = session('team_user_filter_year');
|
||||
}
|
||||
$data['live'] = $data['live'] ?? false;
|
||||
$data['optimized'] = $data['optimized'] ?? false;
|
||||
$TreeCalcBot = $this->getForBusinessUserDetail($user, $data);
|
||||
$route = "";
|
||||
$ret = view("admin.modal.business_user_detail", compact('TreeCalcBot', 'user', 'data'))->render();
|
||||
|
|
@ -176,9 +179,13 @@ class ModalController extends Controller
|
|||
|
||||
//$auth_user = \Auth::user();
|
||||
//if($auth_user->isAdmin() || $auth_user->id === $user->id){
|
||||
if($data['optimized']){
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($data['month'], $data['year'], $data['init_from'], $data['live']);
|
||||
}else{
|
||||
$TreeCalcBot = new TreeCalcBot($data['month'], $data['year'], $data['init_from']);
|
||||
$TreeCalcBot->initBusinesslUserDetail($user);
|
||||
//TODO is not Admin, read is user in Parent tree ...
|
||||
}
|
||||
$TreeCalcBot->initBusinesslUserDetail($user, $data['live']);
|
||||
//TODO is not Admin, read is user in Parent tree ...
|
||||
if(!$TreeCalcBot->business_user){
|
||||
abort(403, 'no user found');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class PaymentMethodController extends Controller
|
|||
'short' => $data['short'],
|
||||
'pos' => $data['pos'],
|
||||
'show_on' => isset($data['show_on']) ? $data['show_on'] : null,
|
||||
'is_abo' => isset($data['is_abo']) ? $data['is_abo'] : null,
|
||||
'is_abo' => isset($data['is_abo']) ? $data['is_abo'] : false,
|
||||
'default' => isset($data['default']) ? true : false,
|
||||
'active' => isset($data['active']) ? true : false,
|
||||
]);
|
||||
|
|
|
|||
311
app/Http/Controllers/Portal/AboController.php
Normal file
311
app/Http/Controllers/Portal/AboController.php
Normal file
|
|
@ -0,0 +1,311 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Portal;
|
||||
|
||||
use Auth;
|
||||
use Yard;
|
||||
use Request;
|
||||
use Validator;
|
||||
use App\Services\Shop;
|
||||
use App\Services\Util;
|
||||
use App\Models\Product;
|
||||
use App\Models\UserAbo;
|
||||
use App\Services\AboHelper;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Services\UserService;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
|
||||
class AboController extends Controller
|
||||
{
|
||||
private $instance = 'subscription';
|
||||
private $yard;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth:customers');
|
||||
$this->yard = Yard::instance($this->instance);
|
||||
}
|
||||
|
||||
|
||||
public function myAbo()
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
|
||||
if (!$user->shopping_user_id) {
|
||||
return view('portal.abo.my_abo_create', [
|
||||
'user' => $user,
|
||||
'no_shopping_user' => true,
|
||||
'step' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$user_abo = UserAbo::where('email', $shopping_user->billing_email)
|
||||
->where('status', '>', 1)
|
||||
->first();
|
||||
|
||||
return $user_abo
|
||||
? view('portal.abo.my_abo', ['user_abo' => $user_abo])
|
||||
: view('portal.abo.my_abo_create', [
|
||||
'shopping_user' => $shopping_user,
|
||||
'step' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function myAboCreate($step)
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
|
||||
if (!$user->shopping_user_id) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$data = $this->prepareAboCreateData($shopping_user, $step);
|
||||
if(isset($data['checkout_url'])){
|
||||
return redirect($data['checkout_url']);
|
||||
}
|
||||
return view('portal.abo.my_abo_create', $data);
|
||||
}
|
||||
|
||||
private function prepareAboCreateData($shopping_user, $step)
|
||||
{
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'basis_products' => Product::where('active', true)
|
||||
->whereJsonContains('show_on', ['12'])
|
||||
->orderBy('pos', 'ASC')
|
||||
->get(),
|
||||
'upgrade_products' => Product::where('active', true)
|
||||
->whereJsonContains('show_on', ['13'])
|
||||
->orderBy('pos', 'ASC')
|
||||
->get(),
|
||||
'step' => 0,
|
||||
];
|
||||
if(Request::get('action') == 'back') {
|
||||
$step = $step - 2;
|
||||
}
|
||||
|
||||
switch ($step) {
|
||||
case 0:
|
||||
$data['step'] = 0;
|
||||
break;
|
||||
case 1:
|
||||
$this->initYard($shopping_user);
|
||||
$data['step'] = 1;
|
||||
break;
|
||||
case 2:
|
||||
UserService::setInstance($this->instance);
|
||||
UserService::initCustomerYard($shopping_user, 'abo-ot-customer');
|
||||
$data['step'] = 2;
|
||||
break;
|
||||
case 3:
|
||||
UserService::setInstance($this->instance);
|
||||
UserService::initCustomerYard($shopping_user, 'abo-ot-customer');
|
||||
if(Request::get('action') == 'next'){
|
||||
if (!$this->checkBasisProduct()) {
|
||||
$data['error'] = __('abo.abo_error_basis_product');
|
||||
$data['step'] = 2;
|
||||
} else {
|
||||
$data['step'] = 3;
|
||||
}
|
||||
}else{
|
||||
$data['step'] = 3;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
UserService::setInstance($this->instance);
|
||||
UserService::initCustomerYard($shopping_user, 'abo-ot-customer');
|
||||
$this->upgradeProductToCart();
|
||||
$data['step'] = 4;
|
||||
break;
|
||||
case 5:
|
||||
//chekout verarbeiten
|
||||
UserService::setInstance($this->instance);
|
||||
UserService::initCustomerYard($shopping_user, 'abo-ot-customer');
|
||||
if(Request::get('action') == 'checkout'){
|
||||
//checkout verarbeiten
|
||||
if (!$this->preCheckCheckout()) {
|
||||
$data['error'] = __('abo.abo_error_basis_product');
|
||||
$data['step'] = 4;
|
||||
} else {
|
||||
$data['checkout_url'] = $this->processCheckout();
|
||||
}
|
||||
}
|
||||
$data['step'] = 4;
|
||||
break;
|
||||
default:
|
||||
abort(404, 'Page not found.');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function initYard($shopping_user)
|
||||
{
|
||||
$delivery_country = $shopping_user->getDeliveryCountry(true);
|
||||
|
||||
if (!$delivery_country) {
|
||||
abort(404, 'No delivery country found, please edit your personal data.');
|
||||
}
|
||||
|
||||
\Session::put('user_init_country', strtolower($delivery_country->code));
|
||||
\Session::forget('user_init_country_options');
|
||||
\Session::put('locale', strtolower(\App::getLocale()));
|
||||
|
||||
Shop::initUserShopLang($delivery_country, $this->instance);
|
||||
}
|
||||
|
||||
private function preCheckCheckout(){
|
||||
$result = false;
|
||||
//alle inhlate des warenkorb
|
||||
$cartItems = $this->yard->content();
|
||||
foreach($cartItems as $item){
|
||||
if(in_array(12, $item->options->show_on)){
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function checkBasisProduct()
|
||||
{
|
||||
$data = Request::all();
|
||||
$result = false;
|
||||
|
||||
if (!isset($data['base_product_qty'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($data['base_product_qty'] as $product_id => $quantity) {
|
||||
$product = Product::find($product_id);
|
||||
|
||||
if (!$product || intval($quantity) <= 0) {
|
||||
continue;
|
||||
}
|
||||
$result = true;
|
||||
$this->addProductToCart($product, $quantity);
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function upgradeProductToCart(){
|
||||
$data = Request::all();
|
||||
$result = false;
|
||||
|
||||
if (!isset($data['upgrade_product_qty'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($data['upgrade_product_qty'] as $product_id => $quantity) {
|
||||
$product = Product::find($product_id);
|
||||
|
||||
if (!$product) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = true;
|
||||
$this->addProductToCart($product, $quantity);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function addProductToCart($product, $quantity)
|
||||
{
|
||||
// Suche nach dem Produkt im Warenkorb
|
||||
$cartItems = $this->yard->search(function($item) use ($product) {
|
||||
return $item->id === $product->id;
|
||||
});
|
||||
|
||||
// Wenn die Menge 0 ist, entferne das Produkt
|
||||
if ($quantity <= 0) {
|
||||
foreach ($cartItems as $item) {
|
||||
$this->yard->remove($item->rowId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$image = $product->images->first()->slug ?? '';
|
||||
$price = $product->getPriceWith(
|
||||
$this->yard->getUserTaxFree(),
|
||||
false,
|
||||
$this->yard->getUserCountry()
|
||||
);
|
||||
|
||||
// Wenn das Produkt bereits im Warenkorb ist, aktualisiere die Menge
|
||||
if ($cartItems->count() > 0) {
|
||||
$cartItem = $cartItems->first();
|
||||
$this->yard->update($cartItem->rowId, $quantity);
|
||||
} else {
|
||||
// Wenn das Produkt noch nicht im Warenkorb ist, füge es hinzu
|
||||
$cartItem = $this->yard->add(
|
||||
$product->id,
|
||||
$product->getLang('name'),
|
||||
$quantity,
|
||||
$price,
|
||||
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
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// $this->setProductTax($cartItem, $product);
|
||||
$this->yard->reCalculateShippingPrice();
|
||||
}
|
||||
|
||||
|
||||
private function processCheckout(){
|
||||
$user_shop = Util::getUserShop();
|
||||
if(!$user_shop){
|
||||
$user_shop = Util::getDefaultUserShop();
|
||||
}
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
|
||||
$data = [];
|
||||
$data['is_from'] = 'shopping';
|
||||
$data['user_price_infos'] = $this->yard->getUserPriceInfos();
|
||||
|
||||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => $user_shop->id,
|
||||
'payment' => 1, //Customer Shop Payment
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => $this->yard->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'shopping_data' => $data,
|
||||
'back' => url()->previous(),
|
||||
|
||||
]);
|
||||
|
||||
$this->yard->store($identifier);
|
||||
//add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
if(strpos($path, 'https') === false){
|
||||
$path = str_replace('http', 'https', $path);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
203
app/Http/Controllers/Portal/Auth/LoginController.php
Executable file
203
app/Http/Controllers/Portal/Auth/LoginController.php
Executable file
|
|
@ -0,0 +1,203 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Portal\Auth;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Services\Util;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\ShoppingUser;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Mail\MailOTPCustomer;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Models\Customer; // Oder User, je nach Setup
|
||||
use App\Models\OtpToken; // Zum Speichern/Prüfen des OTP
|
||||
use Illuminate\Support\Facades\Hash; // Zum Hashen des Tokens
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
// Zeigt das Formular zur Eingabe der E-Mail an
|
||||
public function showLoginForm()
|
||||
{
|
||||
//wenn als Berater eingeloggt, dann zum Login wechseln
|
||||
if(Auth::guard('user')->check()){
|
||||
return redirect()->route('portal.change_login');
|
||||
}
|
||||
//wenn als Kunde eingeloggt, dann direkt zum Dashboard
|
||||
if (Auth::guard('customers')->check()) {
|
||||
return redirect()->route('portal.dashboard');
|
||||
}
|
||||
return view('portal.auth.login'); // Erstelle diese View
|
||||
}
|
||||
|
||||
// Sendet das OTP
|
||||
public function sendOtp(Request $request)
|
||||
{
|
||||
$request->validate(['email' => 'required|email']);
|
||||
$email = $request->input('email');
|
||||
|
||||
// 1. Prüfen, ob die E-Mail im System bekannt ist über Kunden-Tabelle)
|
||||
$customer = Customer::firstOrCreate(['email' => $email]); // Erstellt Kunden, wenn nicht vorhanden
|
||||
if($customer && $customer->language){
|
||||
\App::setLocale($customer->language);
|
||||
}
|
||||
|
||||
// if (!$customerExists && !$orderExists) { // Oder nur eine Prüfung, je nach Logik
|
||||
if (!$customer) { // Prüfung anhand des Customer-Models
|
||||
throw ValidationException::withMessages([
|
||||
'email' => __('auth.failed_customer'), // Generische Fehlermeldung
|
||||
]);
|
||||
}
|
||||
// 2. Alten Token löschen (optional, aber empfohlen)
|
||||
DB::table('otp_tokens')->where('email', $email)->delete();
|
||||
|
||||
// 3. OTP generieren (z.B. 6-stellige Zahl)
|
||||
$otp = random_int(100000, 999999);
|
||||
$expiresAt = Carbon::now()->addMinutes(10); // Gültigkeit z.B. 10 Minuten
|
||||
|
||||
// 4. OTP (gehasht!) speichern
|
||||
DB::table('otp_tokens')->insert([
|
||||
'email' => $email,
|
||||
'token' => Hash::make((string)$otp), // WICHTIG: Token hashen!
|
||||
'expires_at' => $expiresAt,
|
||||
'created_at' => Carbon::now(),
|
||||
]);
|
||||
|
||||
// 5. OTP per E-Mail senden (Notification oder Mailable verwenden)
|
||||
try {
|
||||
Mail::to($email)->locale(\App::getLocale())->send(new MailOTPCustomer($otp, $email));
|
||||
} catch (\Exception $e) {
|
||||
// Logge den Fehler
|
||||
\Log::error('OTP Send Error: ' . $e->getMessage());
|
||||
// Gib eine Fehlermeldung zurück, ohne Details preiszugeben
|
||||
return back()->withErrors(['email' => 'Konnte E-Mail nicht senden. Bitte versuchen Sie es später erneut.'])->withInput();
|
||||
}
|
||||
|
||||
|
||||
// 6. Zum OTP-Eingabeformular weiterleiten (E-Mail in Session speichern oder als Parameter übergeben)
|
||||
session(['otp_email' => $email]); // Explizit in Session speichern
|
||||
return redirect()->route('portal.login.otp.form', ['email' => $email]); // E-Mail auch als Parameter übergeben
|
||||
}
|
||||
|
||||
// Zeigt das Formular zur Eingabe des OTP an
|
||||
public function showOtpForm(Request $request, $email = null, $otp = null)
|
||||
{
|
||||
//wenn als Berater eingeloggt, dann zum Login wechseln
|
||||
if(Auth::guard('user')->check()){
|
||||
return redirect()->route('portal.change_login');
|
||||
}
|
||||
//wenn als Kunde eingeloggt, dann zum Dashboard wechseln
|
||||
if (Auth::guard('customers')->check()) {
|
||||
return redirect()->route('portal.dashboard');
|
||||
}
|
||||
// E-Mail aus der Session holen (oder als Request-Parameter erwarten)
|
||||
if($email) {
|
||||
$email = $email;
|
||||
} else {
|
||||
$email = session('otp_email', $request->query('email'));
|
||||
}
|
||||
if (!$email) {
|
||||
return redirect()->route('portal.login.form')->withErrors(['message' => 'Sitzung abgelaufen oder E-Mail fehlt.']);
|
||||
}
|
||||
|
||||
// CSRF-Token regenerieren für neue Session
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
// Übergebe sowohl 'email' als auch 'otp' an die View
|
||||
return view('portal.auth.verify-otp', ['email' => $email, 'otp_value' => $otp]); // Variable umbenannt zu otp_value für Klarheit
|
||||
}
|
||||
|
||||
// Validiert das OTP und loggt den Kunden ein
|
||||
public function verifyOtpAndLogin(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'email' => 'required|email',
|
||||
'otp' => 'required|numeric|digits:6', // An die Länge deines OTPs anpassen
|
||||
]);
|
||||
|
||||
$email = $request->input('email');
|
||||
$otpInput = $request->input('otp');
|
||||
|
||||
// 1. Gespeicherten OTP-Eintrag finden
|
||||
$otpRecord = DB::table('otp_tokens')->where('email', $email)->first();
|
||||
|
||||
// 2. Prüfen ob Eintrag existiert, nicht abgelaufen ist und das OTP (Hash) übereinstimmt
|
||||
if (!$otpRecord || Carbon::now()->gt($otpRecord->expires_at) || !Hash::check($otpInput, $otpRecord->token)) {
|
||||
// Ungültiges oder abgelaufenes OTP
|
||||
DB::table('otp_tokens')->where('email', $email)->delete(); // Ungültigen Token löschen
|
||||
return back()->withErrors(['otp' => 'Ungültiges oder abgelaufenes Einmalpasswort.'])->withInput(['email' => $email]);
|
||||
}
|
||||
// 3. Kunden-Objekt finden (basierend auf dem Provider-Model)
|
||||
$customer = Customer::where('email', $email)->first(); // Oder User::where('email', $email)->where('role','customer')->first();
|
||||
|
||||
if (!$customer) {
|
||||
// Sollte eigentlich nicht passieren, wenn sendOtp korrekt funktioniert hat
|
||||
DB::table('otp_tokens')->where('email', $email)->delete();
|
||||
return back()->withErrors(['otp' => __('auth.failed')])->withInput(['email' => $email]);
|
||||
}
|
||||
// 4. Kunden einloggen über den 'customers'-Guard
|
||||
Auth::guard('customers')->login($customer); // Loggt den gefundenen Kunden ein
|
||||
|
||||
// 5. Explizite Session-Speicherung
|
||||
$request->session()->save();
|
||||
|
||||
// 6. OTP-Eintrag löschen
|
||||
DB::table('otp_tokens')->where('email', $email)->delete();
|
||||
|
||||
// 7. Session Token regenerieren (statt komplette Session)
|
||||
$request->session()->regenerate();
|
||||
|
||||
// 8. customer DB aktualisieren
|
||||
$shopping_user = ShoppingUser::where('billing_email', $email)->latest()->first();
|
||||
if($shopping_user){
|
||||
$data = [
|
||||
'name' => $shopping_user->billing_firstname . ' ' . $shopping_user->billing_lastname,
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
'member_id' => $shopping_user->member_id,
|
||||
'number' => $shopping_user->number,
|
||||
'language' => session('locale') ?? 'de',
|
||||
];
|
||||
$customer->update($data);
|
||||
}else{
|
||||
$data = [
|
||||
'name' => __('portal.guest'),
|
||||
'shopping_user_id' => null,
|
||||
'member_id' => null,
|
||||
'number' => null,
|
||||
'language' => session('locale') ?? 'de',
|
||||
];
|
||||
$customer->update($data);
|
||||
}
|
||||
|
||||
|
||||
// 10. Zum Kunden-Dashboard weiterleiten
|
||||
return redirect()->intended(route('portal.dashboard')); // intended() leitet zur ursprünglich angefragten Seite weiter
|
||||
}
|
||||
|
||||
// Logout für Kunden
|
||||
public function logout(Request $request)
|
||||
{
|
||||
$url = Util::getMyMivitaShopUrl();
|
||||
Auth::guard('customers')->logout();
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
return redirect($url);
|
||||
}
|
||||
|
||||
// Logout für Berater
|
||||
public function logoutChange(Request $request)
|
||||
{
|
||||
//$url = Util::getMyMivitaShopUrl();
|
||||
$user_shop_domain = session('user_shop_domain');
|
||||
$locale = session('locale');
|
||||
Auth::guard('user')->logout();
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
session(['user_shop_domain' => $user_shop_domain]);
|
||||
session(['locale' => $locale]);
|
||||
return redirect()->route('portal.login.form');
|
||||
}
|
||||
}
|
||||
99
app/Http/Controllers/Portal/CustomerController.php
Normal file
99
app/Http/Controllers/Portal/CustomerController.php
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Portal;
|
||||
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\CustomerPriority;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth:customers');
|
||||
}
|
||||
|
||||
|
||||
public function myDataEdit()
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
if($user->shopping_user_id){
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
}else{
|
||||
$shopping_user = new ShoppingUser();
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'isAdmin' => false,
|
||||
'isView' => 'customer',
|
||||
];
|
||||
return view('portal.customer.edit', $data);
|
||||
|
||||
}
|
||||
|
||||
public function myDataStore(){
|
||||
$user = Auth::guard('customers')->user();
|
||||
$data = Request::all();
|
||||
|
||||
|
||||
if($data['action'] === 'shopping-user-store-new' || $data['action']==='shopping-user-store'){
|
||||
$rules = array(
|
||||
'billing_salutation' => 'required',
|
||||
'billing_firstname'=>'required',
|
||||
'billing_lastname'=>'required',
|
||||
'billing_address'=>'required',
|
||||
'billing_zipcode'=>'required',
|
||||
'billing_city' => 'required',
|
||||
'billing_country_id' => 'required',
|
||||
);
|
||||
|
||||
if(!Request::get('same_as_billing')){
|
||||
$rules = array_merge($rules, [
|
||||
'shipping_firstname'=>'required',
|
||||
'shipping_lastname'=>'required',
|
||||
'shipping_address'=>'required',
|
||||
'shipping_zipcode'=>'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_salutation' => 'required',
|
||||
'shipping_country_id' => 'required'
|
||||
]);
|
||||
}
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
}
|
||||
$data['language'] = \App::getLocale();
|
||||
$data['same_as_billing'] = isset($data['same_as_billing']) ? true : false;
|
||||
$data['shipping_country_id'] = isset($data['shipping_country_id']) ? $data['shipping_country_id'] : $data['billing_country_id'];
|
||||
if($user->shopping_user_id){
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$shopping_user->fill($data);
|
||||
$shopping_user->save();
|
||||
}else{
|
||||
$data['billing_email'] = $user->email;
|
||||
$shopping_user = ShoppingUser::create($data);
|
||||
$user->shopping_user_id = $shopping_user->id;
|
||||
$user->save();
|
||||
//kundenhoheit
|
||||
CustomerPriority::checkOne(ShoppingUser::find($shopping_user->id), true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
\Session()->flash('alert-save', true);
|
||||
|
||||
return redirect(route('portal.my_data.edit'));
|
||||
}
|
||||
|
||||
}
|
||||
132
app/Http/Controllers/Portal/InController.php
Executable file
132
app/Http/Controllers/Portal/InController.php
Executable file
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Portal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use Request;
|
||||
use Storage;
|
||||
use Util;
|
||||
|
||||
class InController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
if(Auth::guard('user')->check()){
|
||||
return redirect(route('portal.change_login'));
|
||||
}
|
||||
if(!Auth::guard('customers')->check()){ // if () {
|
||||
return redirect(route('portal.login.form'));
|
||||
}
|
||||
return redirect(route('portal.dashboard'));
|
||||
|
||||
}
|
||||
|
||||
public function changeLogin(){
|
||||
if(Auth::guard('customers')->check()){
|
||||
return redirect(route('portal.dashboard'));
|
||||
}
|
||||
if(Auth::guard('user')->check()){
|
||||
return view('portal.auth.change');
|
||||
|
||||
}
|
||||
return redirect(route('portal.login.form'));
|
||||
|
||||
}
|
||||
|
||||
public function dashboard()
|
||||
{
|
||||
if(!Auth::guard('customers')->check()){
|
||||
return redirect(route('portal.login.form'));
|
||||
}
|
||||
$data = [
|
||||
'user' => Auth::guard('customers')->user(),
|
||||
'now' => Carbon::now(),
|
||||
];
|
||||
return view('portal.dashboard', $data);
|
||||
}
|
||||
|
||||
public function loadingModal(){
|
||||
|
||||
$data = Request::all();
|
||||
|
||||
|
||||
$response = "";
|
||||
$status = false;
|
||||
|
||||
if(isset($data['action']) && $data['action'] === 'user-order-show-product'){
|
||||
$product = Product::find($data['id']); //current user form order
|
||||
$ret = view("admin.modal.show_product", compact('product', 'data'))->render();
|
||||
return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
|
||||
|
||||
}
|
||||
$data = Request::get('data');
|
||||
$target = Request::get('target');
|
||||
if($data === "data_protection"){
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => true,
|
||||
'isMivitaShop' => false,
|
||||
];
|
||||
$response = view('legal.data_protect_de', $data)->render();
|
||||
}
|
||||
if($data === "imprint"){
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
$response = view('legal.imprint_de', $data)->render();
|
||||
}
|
||||
if($data === "shop_term_of_use"){
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
$response = view('legal.shop_term_of_use_de', $data)->render();
|
||||
}
|
||||
if($data === "agb"){
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
$response = view('legal.agb_de', $data)->render();
|
||||
}
|
||||
if(Request::ajax()) {
|
||||
return response()->json(['response' => $response, 'target'=>$target]);
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* public function goToShop(){
|
||||
|
||||
if(!Auth::guard('customers')->check()){
|
||||
return redirect(config('app.protocol') . config('app.domain') . config('app.tld_shop'));
|
||||
}
|
||||
$customer = Auth::guard('customers')->user();
|
||||
//subdmain for member
|
||||
$member = User::where('email', $customer->email)->first();
|
||||
if($member){
|
||||
return redirect(config('app.protocol') . $member->subdomain . config('app.tld_care'));
|
||||
}
|
||||
// $customer->member_id
|
||||
|
||||
// return redirect(config('app.protocol') . config('app.domain') . config('app.tld_shop'));
|
||||
}*/
|
||||
}
|
||||
116
app/Http/Controllers/Portal/OrderController.php
Normal file
116
app/Http/Controllers/Portal/OrderController.php
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Portal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\Shop;
|
||||
use App\Services\Util;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
use Yard;
|
||||
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
private $instance = 'webshop';
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth:customers');
|
||||
}
|
||||
|
||||
|
||||
public function myOrders()
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
if($user->shopping_user_id){
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$shopping_orders = $shopping_user->getAllOrdersByMember();
|
||||
}else{
|
||||
$shopping_user = new ShoppingUser();
|
||||
$shopping_orders = [];
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'shopping_orders' => $shopping_orders,
|
||||
];
|
||||
return view('portal.order.my_orders', $data);
|
||||
|
||||
}
|
||||
|
||||
public function myOrderShow($id)
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$shopping_order = ShoppingOrder::findOrFail($id);
|
||||
if($shopping_order->shopping_user_id != $user->shopping_user_id){
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
return view('portal.order.my_order_show', [
|
||||
'shopping_order' => $shopping_order,
|
||||
'shopping_user' => $shopping_user,
|
||||
]);
|
||||
}
|
||||
|
||||
public function myOrderCreate($id)
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
$shopping_order = ShoppingOrder::findOrFail($id);
|
||||
if($shopping_order->shopping_user_id != $user->shopping_user_id){
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$delivery_country = $shopping_user->getDeliveryCountry(true);
|
||||
|
||||
\Session::put('user_init_country', strtolower($delivery_country->code));
|
||||
\Session::forget('user_init_country_options');
|
||||
\Session::put('locale', strtolower(\App::getLocale()));
|
||||
|
||||
Shop::initUserShopLang($delivery_country, $this->instance);
|
||||
|
||||
//init Yard
|
||||
|
||||
foreach($shopping_order->shopping_order_items as $shopping_order_item){
|
||||
if($shopping_order_item->product){
|
||||
$this->addToCard($shopping_order_item->product_id, $shopping_order_item->qty);
|
||||
}
|
||||
}
|
||||
$url = Util::getMyMivitaShopUrl("/user/card/show");
|
||||
return redirect($url);
|
||||
}
|
||||
|
||||
|
||||
private function addToCard($id, $quantity = 1)
|
||||
{
|
||||
$product = Product::find($id);
|
||||
if($product){
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$cartItem = Yard::instance($this->instance)
|
||||
->add($product->id, $product->getLang('name'), $quantity,
|
||||
$product->getPriceWith(Yard::instance($this->instance)->getUserTaxFree(), false, Yard::instance($this->instance)->getUserCountry()), 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(Yard::instance($this->instance)->getUserTaxFree()){
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}else{
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance($this->instance)->getUserCountry()));
|
||||
}
|
||||
Yard::instance($this->instance)->reCalculateShippingPrice();
|
||||
|
||||
\Session()->flash('show-card-after-add', true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -59,7 +59,6 @@ class ProductController extends Controller
|
|||
public function store()
|
||||
{
|
||||
$data = Request::all();
|
||||
|
||||
$rules = array(
|
||||
'name' => 'required',
|
||||
);
|
||||
|
|
@ -189,7 +188,7 @@ class ProductController extends Controller
|
|||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
|
||||
}
|
||||
catch (Exception $e) {
|
||||
catch ( \Exception $e) {
|
||||
\Session()->flash('alert-danger', "Fehler".$e);
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
}
|
||||
|
|
|
|||
343
app/Http/Controllers/RevenueReportController.php
Normal file
343
app/Http/Controllers/RevenueReportController.php
Normal file
|
|
@ -0,0 +1,343 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Request;
|
||||
use App\Models\UserInvoice;
|
||||
use App\Models\UserCredit;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Exports\UserTeamExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class RevenueReportController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
'revenue_summary' => $this->getRevenueSummary(),
|
||||
'credit_summary' => $this->getCreditSummary()
|
||||
];
|
||||
|
||||
return view('admin.revenue.index', $data);
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$filter_year = session('revenue_filter_year');
|
||||
|
||||
// Get data like in the HTML view
|
||||
$revenue_summary = $this->getRevenueSummary();
|
||||
$credit_summary = $this->getCreditSummary();
|
||||
|
||||
$filename = "umsatz-gutschrift-bericht-{$filter_year}";
|
||||
|
||||
$columns = [];
|
||||
|
||||
// Umsätze Section Header
|
||||
$columns[] = ['Typ' => 'UMSÄTZE', 'Netto' => '', 'Steuer' => '', 'Brutto' => ''];
|
||||
|
||||
// Yearly Revenue Summary
|
||||
if(isset($revenue_summary['yearly']) && $revenue_summary['yearly']->count() > 0) {
|
||||
foreach($revenue_summary['yearly'] as $item) {
|
||||
$columns[] = [
|
||||
'Typ' => $item->period_label,
|
||||
'Netto' => number_format($item->total_net, 2, ',', '.'),
|
||||
'Steuer' => number_format($item->total_tax, 2, ',', '.'),
|
||||
'Brutto' => number_format($item->total_gross, 2, ',', '.')
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$columns[] = [
|
||||
'Typ' => "Jahr {$filter_year}",
|
||||
'Netto' => '0,00',
|
||||
'Steuer' => '0,00',
|
||||
'Brutto' => '0,00'
|
||||
];
|
||||
}
|
||||
|
||||
// Empty row
|
||||
$columns[] = ['Typ' => '', 'Netto' => '', 'Steuer' => '', 'Brutto' => ''];
|
||||
|
||||
// Monthly Revenue Breakdown
|
||||
$columns[] = ['Typ' => 'MONATLICHE AUFSCHLÜSSELUNG UMSÄTZE', 'Netto' => '', 'Steuer' => '', 'Brutto' => ''];
|
||||
if(isset($revenue_summary['monthly']) && $revenue_summary['monthly']->count() > 0) {
|
||||
foreach($revenue_summary['monthly'] as $item) {
|
||||
$columns[] = [
|
||||
'Typ' => $item->period_label,
|
||||
'Netto' => number_format($item->total_net, 2, ',', '.'),
|
||||
'Steuer' => number_format($item->total_tax, 2, ',', '.'),
|
||||
'Brutto' => number_format($item->total_gross, 2, ',', '.')
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$columns[] = [
|
||||
'Typ' => 'Keine monatlichen Umsätze gefunden',
|
||||
'Netto' => '',
|
||||
'Steuer' => '',
|
||||
'Brutto' => ''
|
||||
];
|
||||
}
|
||||
|
||||
// Two empty rows for separation
|
||||
$columns[] = ['Typ' => '', 'Netto' => '', 'Steuer' => '', 'Brutto' => ''];
|
||||
$columns[] = ['Typ' => '', 'Netto' => '', 'Steuer' => '', 'Brutto' => ''];
|
||||
|
||||
// Gutschriften Section Header
|
||||
$columns[] = ['Typ' => 'GUTSCHRIFTEN', 'Netto' => '', 'Steuer' => '', 'Brutto' => ''];
|
||||
|
||||
// Yearly Credit Summary
|
||||
if(isset($credit_summary['yearly']) && $credit_summary['yearly']->count() > 0) {
|
||||
foreach($credit_summary['yearly'] as $item) {
|
||||
$columns[] = [
|
||||
'Typ' => $item->period_label,
|
||||
'Netto' => number_format($item->total_net, 2, ',', '.'),
|
||||
'Steuer' => number_format($item->total_tax, 2, ',', '.'),
|
||||
'Brutto' => number_format($item->total_gross, 2, ',', '.')
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$columns[] = [
|
||||
'Typ' => "Jahr {$filter_year}",
|
||||
'Netto' => '0,00',
|
||||
'Steuer' => '0,00',
|
||||
'Brutto' => '0,00'
|
||||
];
|
||||
}
|
||||
|
||||
// Empty row
|
||||
$columns[] = ['Typ' => '', 'Netto' => '', 'Steuer' => '', 'Brutto' => ''];
|
||||
|
||||
// Monthly Credit Breakdown
|
||||
$columns[] = ['Typ' => 'MONATLICHE AUFSCHLÜSSELUNG GUTSCHRIFTEN', 'Netto' => '', 'Steuer' => '', 'Brutto' => ''];
|
||||
if(isset($credit_summary['monthly']) && $credit_summary['monthly']->count() > 0) {
|
||||
foreach($credit_summary['monthly'] as $item) {
|
||||
$columns[] = [
|
||||
'Typ' => $item->period_label,
|
||||
'Netto' => number_format($item->total_net, 2, ',', '.'),
|
||||
'Steuer' => number_format($item->total_tax, 2, ',', '.'),
|
||||
'Brutto' => number_format($item->total_gross, 2, ',', '.')
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$columns[] = [
|
||||
'Typ' => 'Keine monatlichen Gutschriften gefunden',
|
||||
'Netto' => '',
|
||||
'Steuer' => '',
|
||||
'Brutto' => ''
|
||||
];
|
||||
}
|
||||
|
||||
$headers = ['Zeitraum', 'Netto (€)', 'Steuer (€)', 'Brutto (€)'];
|
||||
|
||||
return Excel::download(new UserTeamExport($columns, $headers), $filename . '.xlsx');
|
||||
}
|
||||
|
||||
private function setFilterVars()
|
||||
{
|
||||
if (!session('revenue_filter_month')) {
|
||||
session(['revenue_filter_month' => intval(date('m'))]);
|
||||
}
|
||||
if (!session('revenue_filter_year')) {
|
||||
session(['revenue_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
if(!session('revenue_filter_type')){
|
||||
session(['revenue_filter_type' => 'year']);
|
||||
}
|
||||
if (Request::get('revenue_filter_month')) {
|
||||
session(['revenue_filter_month' => Request::get('revenue_filter_month')]);
|
||||
}
|
||||
if (Request::get('revenue_filter_year')) {
|
||||
session(['revenue_filter_year' => Request::get('revenue_filter_year')]);
|
||||
}
|
||||
if (Request::get('revenue_filter_type')) {
|
||||
session(['revenue_filter_type' => Request::get('revenue_filter_type')]);
|
||||
}
|
||||
}
|
||||
|
||||
private function getRevenueSummary()
|
||||
{
|
||||
$year = session('revenue_filter_year');
|
||||
|
||||
return [
|
||||
'yearly' => $this->getRevenueByYear($year),
|
||||
'monthly' => $this->getRevenueByMonthsInYear($year)
|
||||
];
|
||||
}
|
||||
|
||||
private function getCreditSummary()
|
||||
{
|
||||
$year = session('revenue_filter_year');
|
||||
|
||||
return [
|
||||
'yearly' => $this->getCreditByYear($year),
|
||||
'monthly' => $this->getCreditByMonthsInYear($year)
|
||||
];
|
||||
}
|
||||
|
||||
private function getRevenueByYear($year)
|
||||
{
|
||||
return UserInvoice::join('shopping_orders', 'user_invoices.shopping_order_id', '=', 'shopping_orders.id')
|
||||
->selectRaw("
|
||||
{$year} as year,
|
||||
CONCAT('Jahr ', {$year}) as period_label,
|
||||
SUM(shopping_orders.subtotal_ws) as total_net,
|
||||
SUM(shopping_orders.tax) as total_tax,
|
||||
SUM(shopping_orders.total_shipping) as total_gross
|
||||
")
|
||||
->where('user_invoices.year', $year)
|
||||
->where('user_invoices.cancellation', false)
|
||||
->groupBy(DB::raw('1'))
|
||||
->get();
|
||||
}
|
||||
|
||||
private function getRevenueByMonth($year, $month)
|
||||
{
|
||||
return UserInvoice::join('shopping_orders', 'user_invoices.shopping_order_id', '=', 'shopping_orders.id')
|
||||
->selectRaw("
|
||||
{$year} as year,
|
||||
{$month} as month,
|
||||
CONCAT(CASE {$month}
|
||||
WHEN 1 THEN 'Januar'
|
||||
WHEN 2 THEN 'Februar'
|
||||
WHEN 3 THEN 'März'
|
||||
WHEN 4 THEN 'April'
|
||||
WHEN 5 THEN 'Mai'
|
||||
WHEN 6 THEN 'Juni'
|
||||
WHEN 7 THEN 'Juli'
|
||||
WHEN 8 THEN 'August'
|
||||
WHEN 9 THEN 'September'
|
||||
WHEN 10 THEN 'Oktober'
|
||||
WHEN 11 THEN 'November'
|
||||
WHEN 12 THEN 'Dezember'
|
||||
END, ' ', {$year}) as period_label,
|
||||
SUM(shopping_orders.subtotal_ws) as total_net,
|
||||
SUM(shopping_orders.tax) as total_tax,
|
||||
SUM(shopping_orders.total_shipping) as total_gross
|
||||
")
|
||||
->where('user_invoices.year', $year)
|
||||
->where('user_invoices.month', $month)
|
||||
->where('user_invoices.cancellation', false)
|
||||
->groupBy(DB::raw('1'))
|
||||
->get();
|
||||
}
|
||||
|
||||
private function getRevenueByMonthsInYear($year)
|
||||
{
|
||||
return UserInvoice::join('shopping_orders', 'user_invoices.shopping_order_id', '=', 'shopping_orders.id')
|
||||
->selectRaw("
|
||||
user_invoices.year,
|
||||
user_invoices.month,
|
||||
CONCAT(CASE user_invoices.month
|
||||
WHEN 1 THEN 'Januar'
|
||||
WHEN 2 THEN 'Februar'
|
||||
WHEN 3 THEN 'März'
|
||||
WHEN 4 THEN 'April'
|
||||
WHEN 5 THEN 'Mai'
|
||||
WHEN 6 THEN 'Juni'
|
||||
WHEN 7 THEN 'Juli'
|
||||
WHEN 8 THEN 'August'
|
||||
WHEN 9 THEN 'September'
|
||||
WHEN 10 THEN 'Oktober'
|
||||
WHEN 11 THEN 'November'
|
||||
WHEN 12 THEN 'Dezember'
|
||||
END, ' ', user_invoices.year) as period_label,
|
||||
SUM(shopping_orders.subtotal_ws) as total_net,
|
||||
SUM(shopping_orders.tax) as total_tax,
|
||||
SUM(shopping_orders.total_shipping) as total_gross
|
||||
")
|
||||
->where('user_invoices.year', $year)
|
||||
->where('user_invoices.cancellation', false)
|
||||
->groupBy('user_invoices.year', 'user_invoices.month')
|
||||
->orderBy('user_invoices.month')
|
||||
->get();
|
||||
}
|
||||
|
||||
private function getCreditByYear($year)
|
||||
{
|
||||
return UserCredit::selectRaw("
|
||||
{$year} as year,
|
||||
CONCAT('Jahr ', {$year}) as period_label,
|
||||
SUM(net) as total_net,
|
||||
SUM(tax) as total_tax,
|
||||
SUM(total) as total_gross
|
||||
")
|
||||
->where('year', $year)
|
||||
->where('cancellation', false)
|
||||
->groupBy(DB::raw('1'))
|
||||
->get();
|
||||
}
|
||||
|
||||
private function getCreditByMonth($year, $month)
|
||||
{
|
||||
return UserCredit::selectRaw("
|
||||
{$year} as year,
|
||||
{$month} as month,
|
||||
CONCAT(CASE {$month}
|
||||
WHEN 1 THEN 'Januar'
|
||||
WHEN 2 THEN 'Februar'
|
||||
WHEN 3 THEN 'März'
|
||||
WHEN 4 THEN 'April'
|
||||
WHEN 5 THEN 'Mai'
|
||||
WHEN 6 THEN 'Juni'
|
||||
WHEN 7 THEN 'Juli'
|
||||
WHEN 8 THEN 'August'
|
||||
WHEN 9 THEN 'September'
|
||||
WHEN 10 THEN 'Oktober'
|
||||
WHEN 11 THEN 'November'
|
||||
WHEN 12 THEN 'Dezember'
|
||||
END, ' ', {$year}) as period_label,
|
||||
SUM(net) as total_net,
|
||||
SUM(tax) as total_tax,
|
||||
SUM(total) as total_gross
|
||||
")
|
||||
->where('year', $year)
|
||||
->where('month', $month)
|
||||
->where('cancellation', false)
|
||||
->groupBy(DB::raw('1'))
|
||||
->get();
|
||||
}
|
||||
|
||||
private function getCreditByMonthsInYear($year)
|
||||
{
|
||||
return UserCredit::selectRaw("
|
||||
year,
|
||||
month,
|
||||
CONCAT(CASE month
|
||||
WHEN 1 THEN 'Januar'
|
||||
WHEN 2 THEN 'Februar'
|
||||
WHEN 3 THEN 'März'
|
||||
WHEN 4 THEN 'April'
|
||||
WHEN 5 THEN 'Mai'
|
||||
WHEN 6 THEN 'Juni'
|
||||
WHEN 7 THEN 'Juli'
|
||||
WHEN 8 THEN 'August'
|
||||
WHEN 9 THEN 'September'
|
||||
WHEN 10 THEN 'Oktober'
|
||||
WHEN 11 THEN 'November'
|
||||
WHEN 12 THEN 'Dezember'
|
||||
END, ' ', year) as period_label,
|
||||
SUM(net) as total_net,
|
||||
SUM(tax) as total_tax,
|
||||
SUM(total) as total_gross
|
||||
")
|
||||
->where('year', $year)
|
||||
->where('cancellation', false)
|
||||
->groupBy('year', 'month')
|
||||
->orderBy('month')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
|
@ -373,14 +373,14 @@ class SalesController extends Controller
|
|||
if(isset($data['action'])){
|
||||
if($data['action'] === 'create_invoice'){
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
if($shopping_order->mode === 'live'){
|
||||
$invoice_repo = new InvoiceRepository($shopping_order);
|
||||
if($shopping_order->isInvoice()){
|
||||
$invoice_repo->update($data);
|
||||
}else{
|
||||
$invoice_repo->createAndSalesVolume($data);
|
||||
}
|
||||
|
||||
$invoice_repo = new InvoiceRepository($shopping_order);
|
||||
if($shopping_order->isInvoice()){
|
||||
$invoice_repo->update($data);
|
||||
}else{
|
||||
$invoice_repo->createAndSalesVolume($data);
|
||||
}
|
||||
|
||||
if(isset($data['view']) && $data['view'] === 'sales_customer'){
|
||||
return redirect(route('admin_sales_customers_detail', [$shopping_order->id]));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,9 +37,11 @@ class ShippingController extends Controller
|
|||
if($shipping_id === "new"){
|
||||
$shipping = new Shipping();
|
||||
$shipping->active = 1;
|
||||
// For new shipping objects, create an empty collection for countries
|
||||
$shipping->setRelation('countries', collect());
|
||||
|
||||
}else{
|
||||
$shipping = Shipping::findOrFail($shipping_id);
|
||||
$shipping = Shipping::with(['countries.country'])->findOrFail($shipping_id);
|
||||
|
||||
}
|
||||
$data = [
|
||||
|
|
|
|||
|
|
@ -1,153 +0,0 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use Auth;
|
||||
use Request;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Exports\UserTeamExport;
|
||||
use App\Models\ShoppingOrderItem;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Services\BusinessPlan\ExportBot;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class TaxAdvisorController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$this->setFilterVars();
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2023),
|
||||
];
|
||||
return view('admin.payment.taxadvisor', $data);
|
||||
}
|
||||
|
||||
public function download(){
|
||||
|
||||
if(Request::get('action') === "export"){
|
||||
$objects = $this->initSearch(false);
|
||||
$columns = [];
|
||||
$filename = "mivita-absatzmengen-".session('payment_taxadvisor_filter_month').'_'.session('payment_taxadvisor_filter_year')."-export";
|
||||
$headers = array(
|
||||
'#',
|
||||
'Produkt',
|
||||
'Artikelnummer',
|
||||
'Menge',
|
||||
|
||||
);
|
||||
if($objects){
|
||||
foreach ($objects as $key => $obj){
|
||||
$columns[] = array(
|
||||
'id' => $key,
|
||||
'name' => $obj['name'],
|
||||
'number' => $obj['number'],
|
||||
'value' => $obj['value'],
|
||||
);
|
||||
}
|
||||
}
|
||||
return Excel::download(new UserTeamExport($columns, $headers), $filename.'.xls');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function setFilterVars(){
|
||||
|
||||
if(!session('payment_taxadvisor_filter_month')){
|
||||
session(['payment_taxadvisor_filter_month' => intval(date('m'))]);
|
||||
}
|
||||
if(!session('payment_taxadvisor_filter_year')){
|
||||
session(['payment_taxadvisor_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
|
||||
if(Request::get('payment_taxadvisor_filter_month')){
|
||||
session(['payment_taxadvisor_filter_month' => Request::get('payment_taxadvisor_filter_month')]);
|
||||
}
|
||||
if(Request::get('payment_taxadvisor_filter_year')){
|
||||
session(['payment_taxadvisor_filter_year' => Request::get('payment_taxadvisor_filter_year')]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function initSearch($returnColl = true)
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$date_start = Carbon::parse('01.'.session('payment_taxadvisor_filter_month').'.'.session('payment_taxadvisor_filter_year'))->format('Y-m-d');
|
||||
$date_end = Carbon::parse('01.'.session('payment_taxadvisor_filter_month').'.'.session('payment_taxadvisor_filter_year'))->endOfMonth()->format('Y-m-d');
|
||||
|
||||
$ShoppingOrders = ShoppingOrder::where('paid', 1)->where('mode', 'live')->whereBetween('created_at', [$date_start, $date_end])->get();
|
||||
|
||||
$objects = [];
|
||||
foreach($ShoppingOrders as $ShoppingOrder){
|
||||
foreach($ShoppingOrder->shopping_order_items as $shopping_order_item){
|
||||
|
||||
if($shopping_order_item->product){
|
||||
if(isset($objects[$shopping_order_item->product->id])){
|
||||
$value = intval($objects[$shopping_order_item->product->id]['value'] + $shopping_order_item->qty);
|
||||
$objects[$shopping_order_item->product->id]['value'] = $value;
|
||||
}else{
|
||||
$objects[$shopping_order_item->product->id] = [
|
||||
'name' => $shopping_order_item->product->name,
|
||||
'number' => $shopping_order_item->product->number,
|
||||
'value' => $shopping_order_item->qty
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if($returnColl){
|
||||
$collection = collect();
|
||||
|
||||
foreach($objects as $key => $obj){
|
||||
$collection->push([
|
||||
'id' => $key,
|
||||
'name' => $obj['name'],
|
||||
'number' => $obj['number'],
|
||||
'value' => $obj['value'],
|
||||
]);
|
||||
}
|
||||
return $collection;
|
||||
}
|
||||
return $objects;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function datatable(){
|
||||
|
||||
$collection = $this->initSearch(true);
|
||||
|
||||
/*
|
||||
$collect = collect([
|
||||
['id' => 1, 'name' => 'John', 'number'=>92012, 'value'=>123],
|
||||
['id' => 2, 'name' => 'Jane', 'number'=>92012, 'value'=>123],
|
||||
['id' => 3, 'name' => 'James', 'number'=>92012, 'value'=>123],
|
||||
]);
|
||||
*/
|
||||
|
||||
return \DataTables::of($collection)->toJson();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -51,7 +51,6 @@ class CustomerController extends Controller
|
|||
'shopping_user' => $shopping_user,
|
||||
'isAdmin' => false,
|
||||
'isView' => 'customer',
|
||||
|
||||
];
|
||||
return view('user.customer.detail', $data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -232,6 +232,8 @@ class MembershipController extends Controller
|
|||
return back();
|
||||
|
||||
}
|
||||
\Session()->flash('alert-error', __('msg.error_checkbox_not_confirm'));
|
||||
return back();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -344,6 +344,7 @@ class OrderController extends Controller
|
|||
*/
|
||||
private function processUserPayment($user, $identifier, $data, $id, $for)
|
||||
{
|
||||
Shop::deleteCheckoutInstance();
|
||||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => 1, // is first faker shop for buy intern
|
||||
|
|
|
|||
|
|
@ -1,674 +0,0 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\MailCustomPaymet;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserHistory;
|
||||
use App\Services\AboHelper;
|
||||
use App\Services\OrderPaymentService;
|
||||
use App\Services\Payment;
|
||||
use App\Services\Shop;
|
||||
use App\Services\UserService;
|
||||
use App\Services\Util;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Request;
|
||||
use Validator;
|
||||
use Yard;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('active.account');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$data = [
|
||||
];
|
||||
return view('user.order.index', $data);
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$shopping_order = ShoppingOrder::findOrFail($id);
|
||||
if($shopping_order->auth_user_id !== $user->id){
|
||||
abort(404);
|
||||
}
|
||||
if( $shopping_order->payment_for === 6 || $shopping_order->payment_for === 7){
|
||||
return redirect(route('user_shop_order_detail', [$shopping_order->id]));
|
||||
abort(403, 'Kundenbestellung');
|
||||
}
|
||||
$shopping_order->getLastShoppingPayment();
|
||||
|
||||
$data = [
|
||||
'shopping_order' => $shopping_order,
|
||||
'isAdmin' => false,
|
||||
];
|
||||
return view('user.order.detail', $data);
|
||||
}
|
||||
|
||||
public function ordersDatatable(){
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$query = ShoppingOrder::with('shopping_user', 'shopping_payments')->select('shopping_orders.*')->where('auth_user_id', '=', $user->id)->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>';
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
|
||||
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>";
|
||||
})
|
||||
->addColumn('payment', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('getPaymentType');
|
||||
})
|
||||
->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-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>';
|
||||
}
|
||||
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>' : '-';
|
||||
})
|
||||
->addColumn('reference', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('reference');
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
->orderColumn('shipped', 'shipped $1')
|
||||
->orderColumn('total_shipping', 'total_shipping $1')
|
||||
->orderColumn('payment_for', 'payment_for $1')
|
||||
|
||||
->rawColumns(['id', 'txaction', 'payment_for', 'total_shipping', 'invoice', 'shipped'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
/*
|
||||
$for = me, ot-member, ot-customer, abo-ot-member, abo-ot-customer, abo-me
|
||||
*/
|
||||
|
||||
public function delivery($for, $id=null)
|
||||
{
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$shopping_user = null;
|
||||
$delivery_id = null;
|
||||
if(strpos($for, 'ot') !== false){ //ot-member, ot-customer abo-ot-member, abo-ot-customer,
|
||||
$shopping_user = Shop::checkShoppingUser($id, $user);
|
||||
$delivery_id = $shopping_user->id;
|
||||
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'));
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
if($for === 'abo-ot-customer'){
|
||||
//check if user has an Abo
|
||||
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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(Request::get('action') === 'next'){
|
||||
Yard::instance('shopping')->destroy();
|
||||
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]));
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'isAdmin' => false,
|
||||
'isView' => 'customer',
|
||||
'for' => $for,
|
||||
'delivery_id' => $delivery_id,
|
||||
];
|
||||
return view('user.order.delivery', $data);
|
||||
}
|
||||
|
||||
public function list($for, $id=null)
|
||||
{
|
||||
$user = User::find(\Auth::user()->id);
|
||||
if($for === 'abo-me' && AboHelper::userHasAbo($user)){
|
||||
abort(403, 'User has an Abo. Cannot order.');
|
||||
}
|
||||
$shopping_user = null;
|
||||
$delivery_id = null;
|
||||
if(strpos($for, 'ot') !== false){ //ot-member, ot-customer abo-ot-member, abo-ot-customer,
|
||||
$shopping_user = Shop::checkShoppingUser($id, $user);
|
||||
$delivery_id = $shopping_user->id;
|
||||
}
|
||||
if($for === 'ot-customer' || $for === 'abo-ot-customer'){
|
||||
//Liederung an (abo-) ot-customer (Kunden) Zahlung und Rechnung geht an Kunden
|
||||
UserService::initCustomerYard($shopping_user, $for);
|
||||
}else{
|
||||
//Lieferung an user oder (abo-) ot-member (Kunden) rechnung geht an User
|
||||
//lieferland und rechnungsland prüfen
|
||||
$shipping_country_id = Shop::checkShoppingCountry($for, $id);
|
||||
if(!$shipping_country_id){
|
||||
$country = Shop::getDeliveryCountry($for, $id);
|
||||
\Session()->flash('custom-error', $country.": ".__('validation.custom.shipping_not_found'));
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
UserService::initUserYard($user, $shipping_country_id, $for);
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'user' => $user,
|
||||
'isAdmin' => false,
|
||||
'isView' => 'customer',
|
||||
'for' => $for,
|
||||
'template' => str_replace('abo-', '', $for),
|
||||
'delivery_id' => $delivery_id,
|
||||
'is_abo' => strpos($for, 'abo') !== false,
|
||||
'comp_products' => Shop::getCompProducts($for),
|
||||
];
|
||||
return view('user.order.list', $data);
|
||||
}
|
||||
|
||||
public function payment($for, $id=null){
|
||||
$data = Request::all();
|
||||
$user = User::find(Auth::user()->id);
|
||||
$rules = array(
|
||||
'shipping_salutation' => 'required',
|
||||
'shipping_firstname'=>'required',
|
||||
'shipping_lastname'=>'required',
|
||||
'shipping_address'=>'required',
|
||||
'shipping_zipcode'=>'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_state' => 'required',
|
||||
);
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
//hier prüfen, ob versand etc richtig berechnet wurde
|
||||
$this->checkSendYardForPayment($data, $id);
|
||||
|
||||
if(Yard::instance('shopping')->getNumComp() > 0){
|
||||
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'])){
|
||||
$validator->errors()->add('switchers-comp-product', __('msg.please_select_compensation_product'));
|
||||
}else{
|
||||
if(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());
|
||||
}
|
||||
}
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
$data['is_from'] = 'user_order';
|
||||
$data['is_for'] = $for;
|
||||
$data['is_abo'] = $data['is_abo'] ?? 0;
|
||||
$data['abo_interval'] = $data['abo_interval'] ?? 0;
|
||||
$data['shopping_user_id'] = $id;
|
||||
$data['user_price_infos'] = Yard::instance('shopping')->getUserPriceInfos();
|
||||
unset($data['quantity']);
|
||||
unset($data['_token']);
|
||||
$data['mode'] = config('app.mode') === 'test' ? 'test' : 'live';
|
||||
if($for === 'ot-customer' || $for === 'abo-ot-customer'){
|
||||
$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(),
|
||||
'amount' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
|
||||
'status' => 0,
|
||||
'shopping_user_id' => $id,
|
||||
'shopping_data' => $data,
|
||||
'back' => url()->previous(),
|
||||
|
||||
]);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$yard_shopping_items = OrderPaymentService::getRestoredYardShoppingItems($shopping_instance);
|
||||
|
||||
// send Mail to Customer
|
||||
$this->customPaymentSendMail($user, $identifier, $yard_shopping_items, $data);
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'user_order_customer', 'status'=>1, 'product_id'=>null, 'identifier'=>$identifier, 'is_abo'=>$data['is_abo']]);
|
||||
|
||||
//eine Abschließen bestellseite für den User + Link zum Kunden Shop + Mail an den Kunden / Berater
|
||||
return redirect(route('user_order_my_custom_payment', ['identifier'=>$identifier]));
|
||||
}else{
|
||||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => 1, //is first faker shop for buy intern
|
||||
'auth_user_id' => Auth::user()->id,
|
||||
'payment' => 2, //Berater Shop
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'amount' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
|
||||
'status' => 0,
|
||||
'shopping_user_id' => $id,
|
||||
'shopping_data' => $data,
|
||||
'back' => url()->previous(),
|
||||
|
||||
]);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'user_order_payment', 'status'=>1, 'product_id'=>null, 'identifier'=>$identifier, 'is_abo'=>$data['is_abo']]);
|
||||
//$path = str_replace('http', 'https', $path);
|
||||
return redirect()->secure($path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function checkSendYardForPayment($data, $id){
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$shopping_user = null;
|
||||
if(strpos($data['shipping_is_for'], 'ot') !== false){
|
||||
$shopping_user = Shop::checkShoppingUser($id, $user);
|
||||
}
|
||||
|
||||
$shipping_country_id = Shop::checkShoppingCountry($data['shipping_is_for'], $id);
|
||||
if(!$shipping_country_id){
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
$data['shopping_user_id'] = $id;
|
||||
\App\Services\MyLog::writeLog('payment', 'error', 'no shipping_country_id found | Yard identifier: '.$identifier, $data);
|
||||
abort(403, __('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);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
$data['shopping_user_id'] = $id;
|
||||
\App\Services\MyLog::writeLog('payment', 'error', 'shipping_country_id is not the same from Yard | Yard identifier: '.$identifier, $data);
|
||||
abort(403, __('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);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
$data['shopping_user_id'] = $id;
|
||||
\App\Services\MyLog::writeLog('payment', 'error', 'Yard can by not shipping_free | Yard identifier: '.$identifier, $data);
|
||||
abort(403, __('msg.shopping_cart_was_shipping_free'));
|
||||
}
|
||||
}
|
||||
|
||||
if($data['shipping_is_for'] === 'ot-customer'){
|
||||
if(!$user->shop){
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
$data['shopping_user_id'] = $id;
|
||||
\App\Services\MyLog::writeLog('payment', 'error', 'User has no Shop for an User to Customer order| Yard identifier: '.$identifier, $data);
|
||||
abort(403, __('msg.shopping_cart_was_not_user_shop'));
|
||||
}
|
||||
}
|
||||
|
||||
$shipping_price = Shop::getShippingPriceByShippingCountryId($shipping_country_id, Yard::instance('shopping')->weight());
|
||||
dump($shipping_price);
|
||||
//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);
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
$data['shopping_user_id'] = $id;
|
||||
\App\Services\MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is 0 or | Yard identifier: '.$identifier, $data);
|
||||
abort(403, __('msg.shipping_cost_cannot_be_0'));
|
||||
}
|
||||
if(Yard::instance('shopping')->getShippingPrice() != $shipping_price->price){
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
$data['shopping_user_id'] = $id;
|
||||
\App\Services\MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
|
||||
abort(403, __('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);
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
$data['shopping_user_id'] = $id;
|
||||
\App\Services\MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is 0 or | Yard identifier: '.$identifier, $data);
|
||||
abort(403, __('msg.shipping_cost_cannot_be_0'));
|
||||
}
|
||||
dump(Yard::instance('shopping')->getShippingPrice());
|
||||
dump($shipping_price->price_comp);
|
||||
dump(Yard::instance('shopping')->getNumComp());
|
||||
dump($shipping_price->num_comp);
|
||||
dd($data) ;
|
||||
|
||||
if(Yard::instance('shopping')->getShippingPrice() != $shipping_price->price_comp){
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
$data['shopping_user_id'] = $id;
|
||||
\App\Services\MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
|
||||
abort(403, __('msg.shipping_costs_were_not_calculated_correctly'));
|
||||
}
|
||||
|
||||
if(Yard::instance('shopping')->getNumComp() != $shipping_price->num_comp){
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
$data['shopping_user_id'] = $id;
|
||||
\App\Services\MyLog::writeLog('payment', 'error', 'Yard num_comp is 0 | Yard identifier: '.$identifier, $data);
|
||||
abort(403, __('msg.compensation_products_cannot_be_0'));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function datatable(){
|
||||
|
||||
|
||||
if(Request::get('shipping_is_for') === 'me' || Request::get('shipping_is_for') === 'abo-me'){
|
||||
$show_on_ids = Request::get('is_abo') ? ['12', '13'] : ['2'];
|
||||
$query = Product::with('product_buyings')
|
||||
->select('products.*')->where('products.active', true)
|
||||
->where(function($q) use ($show_on_ids) {
|
||||
foreach($show_on_ids as $id) {
|
||||
$q->orWhereJsonContains('show_on', $id);
|
||||
}
|
||||
})
|
||||
->orderByRaw("CASE
|
||||
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 1
|
||||
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 2
|
||||
ELSE 3 END",
|
||||
[$show_on_ids[0], isset($show_on_ids[1]) ? $show_on_ids[1] : $show_on_ids[0]]);
|
||||
}else{
|
||||
$show_on_ids = Request::get('is_abo') ? ['12', '13'] : ['3'];
|
||||
$query = Product::select('products.*')
|
||||
->where('active', true)
|
||||
->where(function($q) use ($show_on_ids) {
|
||||
foreach($show_on_ids as $id) {
|
||||
$q->orWhereJsonContains('show_on', $id);
|
||||
}
|
||||
})
|
||||
->orderByRaw("CASE
|
||||
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 1
|
||||
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 2
|
||||
ELSE 3 END",
|
||||
[$show_on_ids[0], isset($show_on_ids[1]) ? $show_on_ids[1] : $show_on_ids[0]]);
|
||||
}
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('product', function (Product $product) {
|
||||
$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>
|
||||
<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>
|
||||
</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.'">
|
||||
<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>
|
||||
</span>
|
||||
</div>
|
||||
</div>';
|
||||
})
|
||||
->addColumn('abo', function (Product $product) {
|
||||
return AboHelper::getAboTypeBadge(AboHelper::getAboShowOn($product));
|
||||
})
|
||||
/*
|
||||
->addColumn('add_card', function (Product $product) {
|
||||
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="'.$product->id.'">
|
||||
<strong>€ '.$product->getFormattedPriceWith().'</strong> +<span class="ion ion-md-cart"></span>
|
||||
</button>';
|
||||
})
|
||||
->addColumn('quantity', function (Product $product) {
|
||||
$cartItem = Yard::instance('shopping')->getCartItemByProduct($product->id);
|
||||
$qty = isset($cartItem->qty) ? $cartItem->qty : 0;
|
||||
$rowId = isset($cartItem->rowId) ? $cartItem->rowId : '';
|
||||
return '<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>
|
||||
</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.'">
|
||||
<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>
|
||||
</span>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
})*/
|
||||
->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 "";
|
||||
})
|
||||
->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>';
|
||||
})
|
||||
->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>';
|
||||
})
|
||||
->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>';
|
||||
})
|
||||
->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>';
|
||||
})
|
||||
->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>';
|
||||
})
|
||||
->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>';
|
||||
})
|
||||
->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-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.'%');
|
||||
}
|
||||
})
|
||||
->orderColumn('name', 'name $1')
|
||||
->orderColumn('product', 'name $1')
|
||||
->orderColumn('number', 'number $1')
|
||||
->orderColumn('points', 'points $1')
|
||||
->orderColumn('price_net', 'price_net $1')
|
||||
->orderColumn('price_gross', 'price_gross $1')
|
||||
->orderColumn('price_vk_gross', 'price $1')
|
||||
->orderColumn('customer_price_net', 'price $1')
|
||||
->orderColumn('customer_price_gross', 'price $1')
|
||||
->orderColumn('my_commission_net', 'price $1')
|
||||
->orderColumn('contents_total', 'contents_total $1')
|
||||
->orderColumn('weight', 'weight $1')
|
||||
->orderColumn('abo', 'show_on $1')
|
||||
->rawColumns(['add_card', 'price_net', 'price_gross', 'price_vk_gross', 'customer_price_net', 'customer_price_gross', 'my_commission_net', 'product', 'quantity', 'picture', 'abo', 'action'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
public function performRequest(){
|
||||
|
||||
if(Request::ajax()) {
|
||||
$data = Request::all();
|
||||
|
||||
$is_for = isset($data['shipping_is_for']) ? $data['shipping_is_for'] : 'ot-member';
|
||||
$data['for'] = $is_for;
|
||||
$data['comp_products'] = Shop::getCompProducts($is_for);
|
||||
|
||||
if($data['action'] === 'updateCart' && isset($data['product_id'])){
|
||||
if($product = Product::find($data['product_id'])){
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
||||
//get the card item
|
||||
if($is_for === 'ot-customer' || $is_for === 'abo-ot-customer'){
|
||||
$cartItem = Yard::instance('shopping')
|
||||
->add($product->id, $product->getLang('name'), 1,
|
||||
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]);
|
||||
}else{
|
||||
$cartItem = Yard::instance('shopping')
|
||||
->add($product->id, $product->getLang('name'), 1,
|
||||
$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]);
|
||||
}
|
||||
if(Yard::instance('shopping')->getUserTaxFree()){
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}else{
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance('shopping')->getUserCountry()));
|
||||
}
|
||||
if(isset($data['qty']) && $data['qty'] > 0){
|
||||
Yard::instance('shopping')->update($cartItem->rowId, $data['qty']);
|
||||
}else{
|
||||
//if 0 get the item by qty:1 and remove it
|
||||
Yard::instance('shopping')->remove($cartItem->rowId);
|
||||
}
|
||||
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();
|
||||
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
|
||||
}
|
||||
}
|
||||
if($data['action'] === 'clearCart') {
|
||||
Yard::instance('shopping')->destroy();
|
||||
return response()->json(['response' => true, 'data'=>Yard::instance('shopping')->count(), 'html_card'=>'', 'html_comp'=>'']);
|
||||
|
||||
}
|
||||
|
||||
if($data['action'] === 'updateShippingCountry') {
|
||||
if(isset($data['shipping_country_id'])){
|
||||
if($shipping_country = ShippingCountry::find($data['shipping_country_id'])){
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country->id, $is_for);
|
||||
$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();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
|
||||
|
||||
}
|
||||
if($data['action'] === 'updateCompProduct'){
|
||||
// $data['comp_product_id']
|
||||
// $data['comp_num']
|
||||
//count_comp_products
|
||||
$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();
|
||||
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
|
||||
|
||||
}
|
||||
return response()->json(['response' => false, 'data'=>$data]);
|
||||
}
|
||||
}
|
||||
|
||||
private function checkCompProduct($count_comp_products){
|
||||
foreach (Yard::instance('shopping')->content() as $row) {
|
||||
//wenn gleich löschen, da neue Versandkosten
|
||||
if($row->options->comp > $count_comp_products) {
|
||||
Yard::instance('shopping')->remove($row->rowId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function updateCompProduct($data){
|
||||
//clear old
|
||||
foreach (Yard::instance('shopping')->content() as $row) {
|
||||
//wenn kleiner wurde ein produkt entfernt aufgrund der Anzahl
|
||||
//wenn gleich löschen, da neue Versandkosten
|
||||
if($row->options->comp === $data['comp_num'] || $row->options->comp > $data['count_comp_products']) {
|
||||
Yard::instance('shopping')->remove($row->rowId);
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($data['comp_product_id'])) {
|
||||
if ($product = Product::find($data['comp_product_id'])) {
|
||||
$image = "";
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, 0, false, false,
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => 0, 'points' => 0,
|
||||
'comp' => $data['comp_num'], 'product_id' => $product->id]);
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function customPayment($identifier){
|
||||
|
||||
$data = OrderPaymentService::getCustomPayment($identifier);
|
||||
return view('user.order.payment.custom_payment', $data);
|
||||
}
|
||||
|
||||
|
||||
private static function customPaymentSendMail($user, $identifier, $yard_shopping_items, $data){
|
||||
$bcc = [];
|
||||
$shopping_instance = ShoppingInstance::where('identifier', $identifier)->first();
|
||||
if(!$shopping_instance){
|
||||
abort(403, __('msg.shopping_instance_not_found'));
|
||||
}
|
||||
$shopping_user = $data['shopping_user_id'] ? ShoppingUser::find($data['shopping_user_id']) : null;
|
||||
if(!$shopping_user){
|
||||
abort(403, __('msg.shopping_user_not_found'));
|
||||
}
|
||||
|
||||
$route = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
|
||||
$billing_email = $shopping_user->billing_email;
|
||||
if(!$billing_email){
|
||||
$billing_email = $data['mode'] === 'test' ? config('app.checkout_test_mail') : config('app.checkout_mail');
|
||||
}
|
||||
$bcc[] = $data['mode'] === 'test' ? config('app.checkout_test_mail') : config('app.checkout_mail');
|
||||
$bcc[] = $shopping_user->member ? $shopping_user->member->email : $user->email;
|
||||
|
||||
Mail::to($billing_email)->bcc($bcc)->locale(\App::getLocale())
|
||||
->send(new MailCustomPaymet($route, $shopping_user, $shopping_instance, $yard_shopping_items, $data['mode']));
|
||||
}
|
||||
}
|
||||
|
|
@ -3,28 +3,549 @@
|
|||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use Auth;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Exports\UserTeamExport;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Models\UserBusiness;
|
||||
use App\Models\UserLevel;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Services\BusinessPlan\ExportBot;
|
||||
use App\Services\BusinessPlan\TreeCalcBot;
|
||||
use App\Services\BusinessPlan\TreeCalcBotOptimized;
|
||||
use App\Services\BusinessPlan\TreeHelperOptimized;
|
||||
use App\Services\HTMLHelper;
|
||||
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
|
||||
* - Robuste Fehlerbehandlung mit Fallback zur Standard-Implementierung
|
||||
* - Memory- und Performance-Monitoring
|
||||
*/
|
||||
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()
|
||||
{
|
||||
$this->middleware('active.account');
|
||||
}
|
||||
|
||||
public function members()
|
||||
|
||||
|
||||
/**
|
||||
* Zeigt die Team-Übersicht mit optimierter TreeCalcBotOptimized-Datenverarbeitung
|
||||
* Lädt Team-Daten für DataTable-Anzeige
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
$startMemory = memory_get_usage();
|
||||
|
||||
try {
|
||||
$this->setFilterVars();
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$this->month = session('team_user_filter_month');
|
||||
$this->year = session('team_user_filter_year');
|
||||
|
||||
// Prüfe ob Live-Berechnung erzwungen werden soll
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
|
||||
\Log::info("TeamController: Building optimized team overview for user {$user->id} ({$this->month}/{$this->year})" .
|
||||
($forceLiveCalculation ? " with forced live calculation" : ""));
|
||||
|
||||
// Verwende TreeCalcBotOptimized für bessere Performance
|
||||
$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)";
|
||||
\Log::info("TeamController: Optimized team overview built in {$executionTime}ms, Memory: {$memoryUsed}{$calculationType}");
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
'filter_active' => $this->getFilterActive(),
|
||||
'filter_levels' => $this->getFilterLevels(),
|
||||
'filter_next_level' => $this->getFilterNextLevel(),
|
||||
'TreeCalcBot' => $TreeCalcBot,
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'memory_used' => $memoryUsed,
|
||||
'user_id' => $user->id,
|
||||
'user_count' => $TreeCalcBot->getTotalUserCount(),
|
||||
'version' => 'Optimized',
|
||||
'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());
|
||||
|
||||
// Fallback mit minimalen Daten
|
||||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
'filter_active' => $this->getFilterActive(),
|
||||
'filter_levels' => $this->getFilterLevels(),
|
||||
'filter_next_level' => $this->getFilterNextLevel(),
|
||||
'error' => __('team.error_loading_optimized_overview') . $e->getMessage(),
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'memory_used' => 'N/A',
|
||||
'version' => 'Fallback',
|
||||
'calculation_type' => 'Error'
|
||||
],
|
||||
'optimized' => false,
|
||||
];
|
||||
|
||||
return view('user.team.show', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function structure()
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
$startMemory = memory_get_usage();
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
if(config('app.debug')){
|
||||
$user = User::find(454);
|
||||
}
|
||||
$this->setFilterVars();
|
||||
|
||||
// Prüfe ob optimierte Version explizit angefordert wird
|
||||
$useOptimized = Request::get('use_optimized', true);
|
||||
|
||||
// Prüfe ob Live-Berechnung erzwungen werden soll
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
|
||||
try {
|
||||
if ($useOptimized) {
|
||||
// Verwende User-spezifische optimierte Version
|
||||
$TreeCalcBot = new TreeCalcBotOptimized(
|
||||
session('team_user_filter_month'),
|
||||
session('team_user_filter_year'),
|
||||
'member',
|
||||
$forceLiveCalculation
|
||||
);
|
||||
$TreeCalcBot->initStructureUser($user->id, $forceLiveCalculation);
|
||||
$optimizedUsed = true;
|
||||
|
||||
} else {
|
||||
// Standard TreeCalcBot mit Performance-Monitoring
|
||||
$TreeCalcBot = new TreeCalcBot(
|
||||
session('team_user_filter_month'),
|
||||
session('team_user_filter_year'),
|
||||
'member'
|
||||
);
|
||||
|
||||
// Standard TreeCalcBot unterstützt forceLiveCalculation nicht
|
||||
$TreeCalcBot->initStructureUser($user->id);
|
||||
$optimizedUsed = false;
|
||||
}
|
||||
|
||||
$endTime = microtime(true);
|
||||
$endMemory = memory_get_usage();
|
||||
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$memoryUsed = $this->formatBytes($endMemory - $startMemory);
|
||||
|
||||
$versionInfo = ($optimizedUsed ? "OPTIMIZED" : "STANDARD") .
|
||||
($forceLiveCalculation ? " + LIVE" : " + CACHE");
|
||||
|
||||
\Log::info("TeamController: Structure built for user {$user->id} in {$executionTime}ms, Memory: {$memoryUsed} ({$versionInfo})");
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
'TreeCalcBot' => $TreeCalcBot,
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'memory_used' => $memoryUsed,
|
||||
'user_count' => $optimizedUsed && method_exists($TreeCalcBot, 'getTotalUserCount')
|
||||
? $TreeCalcBot->getTotalUserCount()
|
||||
: '-',
|
||||
'version' => $optimizedUsed ? 'Optimized' : 'Standard',
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache'
|
||||
],
|
||||
'optimized' => $optimizedUsed,
|
||||
'forceLiveCalculation' => $forceLiveCalculation,
|
||||
];
|
||||
|
||||
return view('user.team.structure', $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\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');
|
||||
$TreeCalcBot->initStructureUser($user->id);
|
||||
|
||||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
'TreeCalcBot' => $TreeCalcBot,
|
||||
'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')
|
||||
],
|
||||
'optimized' => false,
|
||||
'forceLiveCalculation' => $forceLiveCalculation,
|
||||
];
|
||||
|
||||
return view('user.team.structure', $data);
|
||||
}
|
||||
}
|
||||
public function structureOld()
|
||||
{
|
||||
$user = User::find(\Auth::user()->id);
|
||||
if(config('app.debug')){
|
||||
$user = User::find(454);
|
||||
}
|
||||
$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);
|
||||
$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
|
||||
*/
|
||||
public function datatableOptimized()
|
||||
{
|
||||
try {
|
||||
$startTime = microtime(true);
|
||||
$this->setFilterVars();
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$this->month = Request::get('team_user_filter_month') ?: session('team_user_filter_month');
|
||||
$this->year = Request::get('team_user_filter_year') ?: session('team_user_filter_year');
|
||||
|
||||
// Prüfe ob Live-Berechnung erzwungen werden soll
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
|
||||
\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);
|
||||
$TreeCalcBot->initStructureUser($user->id, $forceLiveCalculation);
|
||||
|
||||
// Extrahiere alle User aus der Struktur
|
||||
$teamUsers = collect($this->getTeamUsersFromStructure($TreeCalcBot));
|
||||
// \Log::info("TeamController: TeamUsers: " . $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");
|
||||
|
||||
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-action="business-user-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="member"
|
||||
data-live="' . $this->forceLiveCalculation . '"
|
||||
data-optimized="1"
|
||||
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);
|
||||
})
|
||||
->addColumn('first_name', function ($teamUser) {
|
||||
return e($teamUser->first_name);
|
||||
})
|
||||
->addColumn('last_name', function ($teamUser) {
|
||||
return e($teamUser->last_name);
|
||||
})
|
||||
->addColumn('user_level', function ($teamUser) {
|
||||
return $teamUser->user_level_name ? TranslationHelper::transUserLevelName($teamUser->user_level_name) : '';
|
||||
|
||||
})
|
||||
->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) {
|
||||
return formatNumber($teamUser->sales_volume_points_KP_sum, 0);
|
||||
})
|
||||
->addColumn('sales_volume_total', function ($teamUser) {
|
||||
|
||||
return formatNumber($teamUser->payline_points_qual_kp, 0);
|
||||
|
||||
})
|
||||
->addColumn('next_level_qualified', function ($teamUser) {
|
||||
|
||||
$userBusiness = UserBusiness::where('user_id', $teamUser->user_id)
|
||||
->where('month', $this->month)
|
||||
->where('year', $this->year)
|
||||
->first();
|
||||
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) : "-";
|
||||
})
|
||||
->rawColumns(['id', '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());
|
||||
|
||||
// Fallback zur Standard-DataTable
|
||||
return $this->datatable();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard DataTable für Team-Übersicht (Fallback-Version)
|
||||
*/
|
||||
public function datatable()
|
||||
{
|
||||
try {
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$query = $this->initTeamSearch($user);
|
||||
|
||||
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-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>';
|
||||
})
|
||||
->addColumn('m_account', function (User $teamUser) {
|
||||
return $teamUser->account ? e($teamUser->account->m_account) : '';
|
||||
})
|
||||
->addColumn('user_level', function (User $teamUser) {
|
||||
return $teamUser->user_level ? e($teamUser->user_level->getLang('name')) : '';
|
||||
})
|
||||
->addColumn('is_qual_kp', function (User $teamUser) {
|
||||
if (!$teamUser->user_level) {
|
||||
return '-';
|
||||
}
|
||||
$qualKP = (int) $teamUser->user_level->qual_kp;
|
||||
$month = Request::get('team_user_filter_month') ?: session('team_user_filter_month');
|
||||
$year = Request::get('team_user_filter_year') ?: session('team_user_filter_year');
|
||||
$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>';
|
||||
})
|
||||
->addColumn('sales_volume_KP_points', function (User $teamUser) {
|
||||
$month = Request::get('team_user_filter_month') ?: session('team_user_filter_month');
|
||||
$year = Request::get('team_user_filter_year') ?: session('team_user_filter_year');
|
||||
$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>';
|
||||
})
|
||||
->addColumn('sales_volume_total', function (User $teamUser) {
|
||||
$month = Request::get('team_user_filter_month') ?: session('team_user_filter_month');
|
||||
$year = Request::get('team_user_filter_year') ?: session('team_user_filter_year');
|
||||
$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>';
|
||||
})
|
||||
->addColumn('email', function (User $teamUser) {
|
||||
return e($teamUser->email);
|
||||
})
|
||||
->addColumn('first_name', function (User $teamUser) {
|
||||
return $teamUser->account ? e($teamUser->account->first_name) : '';
|
||||
})
|
||||
->addColumn('last_name', function (User $teamUser) {
|
||||
return $teamUser->account ? e($teamUser->account->last_name) : '';
|
||||
})
|
||||
->addColumn('sponsor', function (User $teamUser) {
|
||||
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 .= '</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) : "-";
|
||||
})
|
||||
->addColumn('next_level_qualified', function (User $teamUser) {
|
||||
// Verwende bereits berechnete UserBusiness-Daten für bessere Performance
|
||||
$month = Request::get('team_user_filter_month') ?: session('team_user_filter_month');
|
||||
$year = Request::get('team_user_filter_year') ?: session('team_user_filter_year');
|
||||
|
||||
$userBusiness = UserBusiness::where('user_id', $teamUser->id)
|
||||
->where('month', $month)
|
||||
->where('year', $year)
|
||||
->first();
|
||||
|
||||
if ($userBusiness) {
|
||||
return NextLevelBadgeHelper::generateBadgeFromUserBusiness($userBusiness);
|
||||
}
|
||||
|
||||
return NextLevelBadgeHelper::renderNoDataBadge();
|
||||
})
|
||||
->filterColumn('m_account', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereHas('account', function($q) use ($keyword) {
|
||||
$q->where('m_account', 'LIKE', '%' . $keyword . '%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filterColumn('first_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereHas('account', function($q) use ($keyword) {
|
||||
$q->where('first_name', 'LIKE', '%' . $keyword . '%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filterColumn('last_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereHas('account', function($q) use ($keyword) {
|
||||
$q->where('last_name', 'LIKE', '%' . $keyword . '%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filterColumn('email', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->where('email', 'LIKE', '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->orderColumn('id', 'users.id $1')
|
||||
->orderColumn('m_account', 'user_accounts.m_account $1')
|
||||
->orderColumn('first_name', 'user_accounts.first_name $1')
|
||||
->orderColumn('last_name', 'user_accounts.last_name $1')
|
||||
->orderColumn('email', 'users.email $1')
|
||||
->orderColumn('active_account', 'users.payment_account $1')
|
||||
->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());
|
||||
|
||||
return response()->json([
|
||||
'error' => 'Team-Datatable konnte nicht geladen werden: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeigt den Marketingplan für User an
|
||||
* Übersichtliche Darstellung aller Karriere-Level mit wichtigen Informationen
|
||||
*/
|
||||
public function marketingplan()
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
|
||||
try {
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$currentLevel = $user->user_level;
|
||||
|
||||
// Lade alle aktiven User Level, sortiert nach Position
|
||||
$userLevels = \App\Models\UserLevel::where('active', true)
|
||||
->orderBy('pos', 'asc')
|
||||
->get();
|
||||
|
||||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
|
||||
\Log::info("TeamController: Marketingplan loaded for user {$user->id} in {$executionTime}ms");
|
||||
|
||||
$data = [
|
||||
'userLevels' => $userLevels,
|
||||
'currentUser' => $user,
|
||||
'currentLevel' => $currentLevel,
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime
|
||||
]
|
||||
];
|
||||
|
||||
return view('user.team.marketingplan', $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error loading marketingplan: " . $e->getMessage());
|
||||
|
||||
return view('user.team.marketingplan', [
|
||||
'error' => __('marketingplan.loading_error') . ' ' . $e->getMessage(),
|
||||
'userLevels' => collect(),
|
||||
'currentUser' => null,
|
||||
'currentLevel' => null
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Link für neue Mitglieder
|
||||
*/
|
||||
public function addMember()
|
||||
{
|
||||
$user = User::find(\Auth::user()->id);
|
||||
if ($user->isActiveShop() && $user->shop) {
|
||||
|
|
@ -39,22 +560,38 @@ class TeamController extends Controller
|
|||
return view('user.team.members', $data);
|
||||
}
|
||||
|
||||
public function structure()
|
||||
/**
|
||||
* Initialisiert die Team-Suche für den eingeloggten User
|
||||
*/
|
||||
private function initTeamSearch($currentUser)
|
||||
{
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$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);
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
'TreeCalcBot' => $TreeCalcBot,
|
||||
];
|
||||
return view('user.team.structure', $data);
|
||||
}
|
||||
|
||||
// Finde alle Team-Mitglieder des aktuellen Users (direkte und indirekte)
|
||||
$query = User::with(['account', 'user_level', 'user_sponsor.account'])
|
||||
->select('users.*', 'user_accounts.m_account', 'user_accounts.first_name', 'user_accounts.last_name')
|
||||
->leftJoin('user_accounts', 'users.id', '=', 'user_accounts.id')
|
||||
->where('users.deleted_at', '=', null)
|
||||
->where('users.id', '!=', 1)
|
||||
->where('users.admin', '<', 4)
|
||||
->where('users.m_level', '!=', null)
|
||||
->where('users.payment_account', '!=', null);
|
||||
|
||||
// Filtere Team-Mitglieder basierend auf Sponsor-Hierarchie
|
||||
// TODO: Hier müsste die Logik implementiert werden, um nur Team-Mitglieder des aktuellen Users zu finden
|
||||
// Für jetzt zeigen wir alle aktiven User (kann später spezifiziert werden)
|
||||
|
||||
$activeFilter = Request::get('team_user_filter_active') ?: session('team_user_filter_active', 1);
|
||||
if ($activeFilter == 1) {
|
||||
$query->where('users.payment_account', '>=', now());
|
||||
} elseif ($activeFilter == 2) {
|
||||
$query->where('users.payment_account', '<', now());
|
||||
}
|
||||
// activeFilter == 3 bedeutet alle (keine weitere Einschränkung)
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function points()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
|
@ -153,6 +690,15 @@ class TeamController extends Controller
|
|||
if (!session('team_user_points_filter_year')) {
|
||||
session(['team_user_points_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
if (!session('team_user_filter_active')) {
|
||||
session(['team_user_filter_active' => 1]);
|
||||
}
|
||||
if (!session('team_user_filter_level')) {
|
||||
session(['team_user_filter_level' => 0]);
|
||||
}
|
||||
if (!session('team_user_filter_next_level')) {
|
||||
session(['team_user_filter_next_level' => 0]);
|
||||
}
|
||||
|
||||
if (Request::get('team_user_filter_month')) {
|
||||
session(['team_user_filter_month' => Request::get('team_user_filter_month')]);
|
||||
|
|
@ -167,6 +713,19 @@ class TeamController extends Controller
|
|||
if (Request::get('team_user_points_filter_year')) {
|
||||
session(['team_user_points_filter_year' => Request::get('team_user_points_filter_year')]);
|
||||
}
|
||||
if (Request::get('team_user_filter_active')) {
|
||||
session(['team_user_filter_active' => Request::get('team_user_filter_active')]);
|
||||
}
|
||||
if (Request::get('team_user_filter_level')) {
|
||||
session(['team_user_filter_level' => Request::get('team_user_filter_level')]);
|
||||
}else{
|
||||
session(['team_user_filter_level' => 0]);
|
||||
}
|
||||
if (Request::get('team_user_filter_next_level')) {
|
||||
session(['team_user_filter_next_level' => Request::get('team_user_filter_next_level')]);
|
||||
}else{
|
||||
session(['team_user_filter_next_level' => 0]);
|
||||
}
|
||||
}
|
||||
|
||||
private function initSearchPoints()
|
||||
|
|
@ -238,4 +797,206 @@ class TeamController extends Controller
|
|||
$html = view('user.team._points_sum', $data)->render();
|
||||
return response()->json(['response' => true, 'data' => $data, 'html' => $html]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatiert Bytes in lesbare Einheiten (aus BusinessControllerOptimized übernommen)
|
||||
*/
|
||||
private function formatBytes(int $bytes, int $precision = 2): string
|
||||
{
|
||||
$units = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
|
||||
for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) {
|
||||
$bytes /= 1024;
|
||||
}
|
||||
|
||||
return round($bytes, $precision) . ' ' . $units[$i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt verfügbare User Level für Filter
|
||||
*/
|
||||
private function getFilterLevels(): array
|
||||
{
|
||||
$levels = [0 => 'Alle Level'];
|
||||
|
||||
$userLevels = \App\Models\UserLevel::orderBy('pos')->get(['id', 'name']);
|
||||
foreach ($userLevels as $level) {
|
||||
$levels[$level->id] = $level->name;
|
||||
}
|
||||
|
||||
return $levels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt übersetzte Filter für Aktiv-Status
|
||||
*/
|
||||
private function getFilterActive(): array
|
||||
{
|
||||
return [
|
||||
1 => __('team.filter_active'),
|
||||
2 => __('team.filter_not_active'),
|
||||
3 => __('team.filter_all')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt übersetzte Filter für Next Level Status
|
||||
*/
|
||||
private function getFilterNextLevel(): array
|
||||
{
|
||||
return [
|
||||
0 => __('team.all_status'),
|
||||
1 => __('team.qualified_green'),
|
||||
2 => __('team.in_progress_yellow'),
|
||||
3 => __('team.no_level_red')
|
||||
];
|
||||
}
|
||||
|
||||
// Performance-optimierte Badge-Generierung wurde in NextLevelBadgeHelper ausgelagert
|
||||
// Alte performance-lastige Methoden wurden entfernt um die Datatable-Performance zu verbessern
|
||||
|
||||
/**
|
||||
* Extrahiert alle User aus TreeCalcBotOptimized-Struktur für DataTable-Anzeige
|
||||
* Sammelt rekursiv alle User aus der Struktur und macht sie als flache Liste verfügbar
|
||||
*/
|
||||
public function getTeamUsersFromStructure(TreeCalcBotOptimized $treeCalcBot): array
|
||||
{
|
||||
$allUsers = [];
|
||||
$deep = 0;
|
||||
// Debug: Prüfe TreeCalcBot-Inhalt
|
||||
$businessUsers = $treeCalcBot->getItems();
|
||||
\Log::info("TeamController: TreeCalcBot items count: " . count($businessUsers));
|
||||
|
||||
// Sammle alle Root-User
|
||||
foreach ($businessUsers as $businessUser) {
|
||||
\Log::debug("TeamController: Processing businessUser", [
|
||||
'user_id' => ($businessUser->user_id),
|
||||
]);
|
||||
$businessUser->deep = $deep;
|
||||
$allUsers[] = $businessUser;
|
||||
$this->collectUserIdsFromBusinessUser($businessUser, $allUsers, $deep+1, false);
|
||||
}
|
||||
// Sammle parentless User
|
||||
if ($treeCalcBot->isParentless()) {
|
||||
$parentless = $treeCalcBot->__get('parentless');
|
||||
//\Log::info("TeamController: Found " . count($parentless) . " parentless users");
|
||||
|
||||
if (is_array($parentless)) {
|
||||
foreach ($parentless as $businessUser) {
|
||||
if ($businessUser) {
|
||||
$businessUser->deep = 0;
|
||||
$allUsers[] = $businessUser;
|
||||
|
||||
// Sammle rekursiv alle Unter-User
|
||||
$this->collectUserIdsFromBusinessUser($businessUser, $allUsers, 0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
\Log::info("TeamController: AllUsers before filtering: " . count($allUsers));
|
||||
|
||||
// Filter anwenden
|
||||
$filteredUsers = $this->applyTeamFiltersToBusinessUsers($allUsers);
|
||||
\Log::info("TeamController: AllUsers after filtering: " . count($filteredUsers));
|
||||
|
||||
return $filteredUsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wendet Team-Filter auf BusinessUser-Objekte an
|
||||
*/
|
||||
private function applyTeamFiltersToBusinessUsers($businessUsers): array
|
||||
{
|
||||
$activeFilter = Request::get('team_user_filter_active') ?: session('team_user_filter_active', 1);
|
||||
$levelFilter = Request::get('team_user_filter_level') ?: session('team_user_filter_level', 0);
|
||||
$nextLevelFilter = Request::get('team_user_filter_next_level') ?: session('team_user_filter_next_level', 0);
|
||||
|
||||
\Log::info("TeamController: Applying filters - Active: {$activeFilter}, Level: {$levelFilter}, NextLevel: {$nextLevelFilter}");
|
||||
|
||||
// Debug: Zeige verfügbare Eigenschaften des ersten BusinessUsers
|
||||
if (!empty($businessUsers)) {
|
||||
$firstUser = $businessUsers[0];
|
||||
\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',
|
||||
'next_qual_user_level' => isset($firstUser->next_qual_user_level) ? 'set' : 'not set',
|
||||
'next_can_user_level' => isset($firstUser->next_can_user_level) ? 'set' : 'not set',
|
||||
]);
|
||||
}
|
||||
|
||||
$filtered = array_filter($businessUsers, function($businessUser) use ($activeFilter, $levelFilter, $nextLevelFilter) {
|
||||
// Active Filter anwenden
|
||||
if ($activeFilter == 1) { // Nur aktive
|
||||
if (!$businessUser->active_account) {
|
||||
return false;
|
||||
}
|
||||
} elseif ($activeFilter == 2) { // Nur inaktive
|
||||
if ($businessUser->active_account) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// activeFilter == 3 bedeutet alle (keine Einschränkung)
|
||||
|
||||
// Level Filter anwenden
|
||||
if ($levelFilter && $levelFilter != 0) {
|
||||
if ($businessUser->m_level_id != $levelFilter) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Next Level Filter anwenden
|
||||
if ($nextLevelFilter && $nextLevelFilter != 0) {
|
||||
$hasNextQual = ($businessUser->next_qual_user_level) && $businessUser->next_qual_user_level !== '[]';
|
||||
$hasNextCan = ($businessUser->next_can_user_level) && $businessUser->next_can_user_level !== '[]';
|
||||
|
||||
switch ($nextLevelFilter) {
|
||||
case 1: // Qualifiziert (grün) - hat next_qual_user_level
|
||||
if (!$hasNextQual) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 2: // In Arbeit (gelb) - hat next_can_user_level aber kein next_qual_user_level
|
||||
if ($hasNextQual || !$hasNextCan) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 3: // Kein Level (rot) - hat weder next_qual noch next_can
|
||||
if ($hasNextQual || $hasNextCan) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true; // Alle Filter bestanden
|
||||
});
|
||||
|
||||
// Array-Indizes neu setzen für korrekte DataTable-Verarbeitung
|
||||
return array_values($filtered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hilfsmethode zum rekursiven Sammeln von User-IDs aus BusinessUser-Struktur
|
||||
*/
|
||||
private function collectUserIdsFromBusinessUser($businessUser, &$allUsers, $deep, $parentless): void
|
||||
{
|
||||
if (isset($businessUser->businessUserItems) && is_array($businessUser->businessUserItems)) {
|
||||
\Log::debug("TeamController: Collecting from businessUser with " . count($businessUser->businessUserItems) . " sub-items");
|
||||
|
||||
foreach ($businessUser->businessUserItems as $subBusinessUser) {
|
||||
if ($subBusinessUser) {
|
||||
$subBusinessUser->deep = $deep;
|
||||
$allUsers[] = $subBusinessUser;
|
||||
if($subBusinessUser->user_id){
|
||||
\Log::debug("TeamController: Collected user ID: " . $subBusinessUser->user_id);
|
||||
}
|
||||
// Rekursiver Aufruf für weitere Unter-User
|
||||
$newDeep = $parentless ? 0 : $deep+1;
|
||||
$this->collectUserIdsFromBusinessUser($subBusinessUser, $allUsers, $newDeep, $parentless);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Http\Controllers\Api\KasController;
|
||||
use App\Http\Controllers\Api\KasSLLController;
|
||||
use App\Models\UserShop;
|
||||
use App\Models\UserShopOnSite;
|
||||
use App\Repositories\UserRepository;
|
||||
|
|
@ -308,7 +307,7 @@ class UserShopController extends Controller
|
|||
|
||||
if(Request::get('shop_submit') == 'check'){
|
||||
$rules = array(
|
||||
'user_shop_name' => ' required|alpha_dash|profanity|unique:user_shops,name|min:4|max:20|full_word_check',
|
||||
'user_shop_name' => ' required|alpha_dash|unique:user_shops,name|min:4|max:20|full_word_check',
|
||||
);
|
||||
Validator::extend('full_word_check', function ($attribute, $value, $parameters, $validator) {
|
||||
if(in_array($value, config('profanity.full_word_check'))){
|
||||
|
|
@ -329,7 +328,7 @@ class UserShopController extends Controller
|
|||
if(Request::get('shop_submit') == 'action') {
|
||||
|
||||
$rules = array(
|
||||
'user_shop_name' => ' required|alpha_dash|profanity|unique:user_shops,name|min:4|max:20|full_word_check',
|
||||
'user_shop_name' => ' required|alpha_dash|unique:user_shops,name|min:4|max:20|full_word_check',
|
||||
);
|
||||
Validator::extend('full_word_check', function ($attribute, $value, $parameters, $validator) {
|
||||
if(in_array($value, config('profanity.full_word_check'))){
|
||||
|
|
@ -418,7 +417,7 @@ class UserShopController extends Controller
|
|||
public function checkUserShopName(){
|
||||
|
||||
$rules = array(
|
||||
'user_shop_name' => ' required|alpha_dash|profanity|unique:user_shops,name|min:4|max:20|full_word_check',
|
||||
'user_shop_name' => ' required|alpha_dash|unique:user_shops,name|min:4|max:20|full_word_check',
|
||||
);
|
||||
Validator::extend('full_word_check', function ($attribute, $value, $parameters, $validator) {
|
||||
if(in_array($value, config('profanity.full_word_check'))){
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use Carbon\Carbon;
|
|||
use Illuminate\Database\Connection;
|
||||
use App\Mail\MailActivateUser;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
class UserUpdateEmailController extends Controller
|
||||
{
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ class UserUpdateEmailController extends Controller
|
|||
|
||||
protected function getToken()
|
||||
{
|
||||
return hash_hmac('sha256', str_random(40), config('app.key'));
|
||||
return hash_hmac('sha256', Str::random(40), config('app.key'));
|
||||
}
|
||||
|
||||
public function createActivation($user, array $data)
|
||||
|
|
|
|||
|
|
@ -8,11 +8,13 @@ use Request;
|
|||
use App\Services\Shop;
|
||||
use App\Services\Util;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class CardController extends Controller
|
||||
{
|
||||
private $instance = 'webshop';
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
|
|
@ -33,16 +35,16 @@ class CardController extends Controller
|
|||
if($product->images->count()){
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$cartItem = Yard::instance('shopping')
|
||||
$cartItem = Yard::instance($this->instance)
|
||||
->add($product->id, $product->getLang('name'), $quantity,
|
||||
$product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), false, Yard::instance('shopping')->getUserCountry()), false, false,
|
||||
$product->getPriceWith(Yard::instance($this->instance)->getUserTaxFree(), false, Yard::instance($this->instance)->getUserCountry()), 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(Yard::instance('shopping')->getUserTaxFree()){
|
||||
if(Yard::instance($this->instance)->getUserTaxFree()){
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}else{
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance('shopping')->getUserCountry()));
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance($this->instance)->getUserCountry()));
|
||||
}
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
Yard::instance($this->instance)->reCalculateShippingPrice();
|
||||
|
||||
\Session()->flash('show-card-after-add', true);
|
||||
}
|
||||
|
|
@ -62,16 +64,16 @@ class CardController extends Controller
|
|||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$quantity = Request::get('quantity') ? Request::get('quantity') : 1;
|
||||
$cartItem = Yard::instance('shopping')
|
||||
$cartItem = Yard::instance($this->instance)
|
||||
->add($product->id, $product->getLang('name'), $quantity,
|
||||
$product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), false, Yard::instance('shopping')->getUserCountry()), false, false,
|
||||
$product->getPriceWith(Yard::instance($this->instance)->getUserTaxFree(), false, Yard::instance($this->instance)->getUserCountry()), 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(Yard::instance('shopping')->getUserTaxFree()){
|
||||
if(Yard::instance($this->instance)->getUserTaxFree()){
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}else{
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance('shopping')->getUserCountry()));
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance($this->instance)->getUserCountry()));
|
||||
}
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
Yard::instance($this->instance)->reCalculateShippingPrice();
|
||||
|
||||
\Session()->flash('show-card-after-add', true);
|
||||
}
|
||||
|
|
@ -83,15 +85,18 @@ class CardController extends Controller
|
|||
public function showCard(){
|
||||
|
||||
if(Request::get('selected_country')){
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice(Request::get('selected_country'));
|
||||
Yard::instance($this->instance)->setShippingCountryWithPrice(Request::get('selected_country'));
|
||||
}else{
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
Yard::instance($this->instance)->reCalculateShippingPrice();
|
||||
}
|
||||
|
||||
//show konflikt wenn user eingeloggt ist und country nicht gesetzt ist
|
||||
$shipping_error = $this->checkShippingError();
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'mylangs' => Shop::getLangChange(),
|
||||
|
||||
'mylangs' => Shop::getLangChange($this->instance),
|
||||
'yard_instance' => $this->instance,
|
||||
'shipping_error' => $shipping_error ?? false,
|
||||
];
|
||||
return view('web.templates.card', $data);
|
||||
}
|
||||
|
|
@ -101,8 +106,8 @@ class CardController extends Controller
|
|||
$data = Request::all();
|
||||
if(isset($data['quantity'])){
|
||||
foreach ($data['quantity'] as $rowId => $qty){
|
||||
Yard::instance('shopping')->update($rowId, $qty);
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
Yard::instance($this->instance)->update($rowId, $qty);
|
||||
Yard::instance($this->instance)->reCalculateShippingPrice();
|
||||
}
|
||||
}else{
|
||||
$this->deleteCard();
|
||||
|
|
@ -111,31 +116,30 @@ class CardController extends Controller
|
|||
}
|
||||
|
||||
public function checkoutServer(){
|
||||
|
||||
|
||||
|
||||
$user_shop = Util::getUserShop();
|
||||
|
||||
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
|
||||
$data = [];
|
||||
$data['is_from'] = 'shopping';
|
||||
$data['user_price_infos'] = Yard::instance('shopping')->getUserPriceInfos();
|
||||
$data['user_price_infos'] = Yard::instance($this->instance)->getUserPriceInfos();
|
||||
|
||||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => $user_shop->id,
|
||||
'payment' => 1, //Customer Shop Payment
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'country_id' => Yard::instance($this->instance)->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'shopping_data' => $data,
|
||||
'back' => url()->previous(),
|
||||
|
||||
]);
|
||||
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
|
||||
Yard::instance($this->instance)->store($identifier);
|
||||
//add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
if(strpos($path, 'https') === false){
|
||||
|
|
@ -151,19 +155,48 @@ class CardController extends Controller
|
|||
}
|
||||
public function removeCard($rowId){
|
||||
|
||||
Yard::instance('shopping')->remove($rowId);
|
||||
Yard::instance($this->instance)->remove($rowId);
|
||||
return back();
|
||||
}
|
||||
|
||||
public function deleteCard(){
|
||||
|
||||
$setCode = Shop::getUserShopLang();
|
||||
$mylangs = Shop::getLangChange();
|
||||
$setCode = Shop::getUserShopLang(null, $this->instance);
|
||||
$mylangs = Shop::getLangChange($this->instance);
|
||||
foreach($mylangs as $code => $country){
|
||||
if(strtolower($setCode) === strtolower($code)){
|
||||
Shop::initUserShopLang($country);
|
||||
Shop::initUserShopLang($country, $this->instance);
|
||||
return back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function checkShippingError(){
|
||||
$shipping_error = false;
|
||||
if(\Auth::guard('customers')->check()){
|
||||
$user = \Auth::guard('customers')->user();
|
||||
if($user->shopping_user_id){
|
||||
$shopping_user = ShoppingUser::find($user->shopping_user_id);
|
||||
if($shopping_user->same_as_billing){
|
||||
if($shopping_user->billing_country_id != Yard::instance($this->instance)->getUserCountryId()){
|
||||
$user_country = Yard::instance($this->instance)->getUserCountry();
|
||||
$user_country_name = $user_country ? $user_country->getLocated() : '';
|
||||
$billing_country = $shopping_user->billing_country;
|
||||
$country_name = $billing_country ? $billing_country->getLocated() : '';
|
||||
$shipping_error = __('website.shipping_error_billing', ['shipping_country' => $user_country_name, 'billing_country' => $country_name]);
|
||||
}
|
||||
}else{
|
||||
if($shopping_user->shipping_country_id != Yard::instance($this->instance)->getUserCountryId()){
|
||||
$user_country = Yard::instance($this->instance)->getUserCountry();
|
||||
$user_country_name = $user_country ? $user_country->getLocated() : '';
|
||||
$shipping_country = $shopping_user->shipping_country;
|
||||
$country_name = $shipping_country ? $shipping_country->getLocated() : '';
|
||||
$shipping_error = __('website.shipping_error_delivery', ['shipping_country' => $user_country_name, 'billing_country' => $country_name]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return $shipping_error;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ use Yard;
|
|||
class CheckoutController extends Controller
|
||||
{
|
||||
private $checkoutRepo;
|
||||
private $instance = 'checkout';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
|
|
@ -42,7 +43,15 @@ class CheckoutController extends Controller
|
|||
*/
|
||||
public function checkout()
|
||||
{
|
||||
$shopping_data = Yard::instance('shopping')->getYardExtra('shopping_data');
|
||||
/*
|
||||
@if(Auth::guard('customers')->check())
|
||||
<a href="{{ route('portal.logout') }}" class="btn btn-sm btn-default mt-3"><i class="fa fa-power-off"></i> {{ __('navigation.logout') }} </a>
|
||||
@else
|
||||
<a href="{{ Util::getMyMivitaPortalUrl() }}" class="btn btn-primary btn-block mt-3 faa-parent animated-hover"><i class="fa fa-sign-in"></i> {{ __('website.to_customer_portal') }} </a>
|
||||
@endif
|
||||
@if(Auth::guard('user')->check())
|
||||
*/
|
||||
$shopping_data = Yard::instance($this->instance)->getYardExtra('shopping_data');
|
||||
$is_from = $shopping_data['is_from'] ?? 'shopping';
|
||||
$is_for = $shopping_data['is_for'] ?? false;
|
||||
$is_abo = isset($shopping_data['is_abo']) ? (bool) $shopping_data['is_abo'] : false;
|
||||
|
|
@ -53,7 +62,6 @@ class CheckoutController extends Controller
|
|||
if ($is_for === 'ot-customer' || $is_for === 'abo-ot-customer') {
|
||||
$is_from = 'shopping';
|
||||
}
|
||||
|
||||
Util::setInstanceStatus(1, true); // link_check
|
||||
if ($is_abo) {
|
||||
$instance_status = Util::getInstanceStatus();
|
||||
|
|
@ -61,29 +69,11 @@ class CheckoutController extends Controller
|
|||
return $this->redirectToIsFinal($instance_status);
|
||||
}
|
||||
}
|
||||
|
||||
if (Session::has('new_session')) {
|
||||
$this->checkoutRepo->sessionDestroy();
|
||||
Session::forget('new_session');
|
||||
}
|
||||
|
||||
if (!$this->checkoutRepo->getSessionPayments('shopping_user_id')) {
|
||||
if ($shopping_data && $is_from !== 'shopping') {
|
||||
$shopping_user = $this->checkoutRepo->shoppingUserAuthData($is_from, $is_for, $shopping_data);
|
||||
$shopping_user->save();
|
||||
$this->checkoutRepo->putSessionPayments('shopping_user_id', $shopping_user->id);
|
||||
} elseif ($is_from === 'shopping' && ($is_for !== 'ot-customer' && $is_for !== 'abo-ot-customer')) {
|
||||
$shopping_user = $this->initializeShoppingUser($is_for, $is_from, $homeparty_id);
|
||||
} elseif ($is_from === 'shopping' && ($is_for === 'ot-customer' || $is_for === 'abo-ot-customer')) {
|
||||
$shopping_user = $this->checkoutRepo->makeCustomerShoppingUser($shopping_data);
|
||||
$shopping_user->is_for = $is_for;
|
||||
$shopping_user->is_from = $is_from;
|
||||
$shopping_user->mode = 'prev';
|
||||
$shopping_user->language = \App::getLocale();
|
||||
}
|
||||
} else {
|
||||
$shopping_user = $this->getExistingShoppingUser();
|
||||
}
|
||||
}
|
||||
$shopping_user = $this->initializeShoppingUserSession($is_from, $is_for, $shopping_data, $homeparty_id);
|
||||
|
||||
$this->prepareShoppingUserData($shopping_user);
|
||||
$payment_methods = $this->checkoutRepo->getPaymentsMethods($is_from, $is_abo);
|
||||
|
|
@ -101,46 +91,14 @@ class CheckoutController extends Controller
|
|||
'payment_methods_active' => $payment_methods['active'],
|
||||
'payment_data' => $payment_methods['data'],
|
||||
'instance_status' => $instance_status ?? false,
|
||||
'is_checkout' => true,
|
||||
'yard_instance' => $this->instance,
|
||||
];
|
||||
|
||||
return view('web.templates.checkout', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisiert einen neuen ShoppingUser
|
||||
*
|
||||
* @param string $is_for
|
||||
* @param string $is_from
|
||||
* @param int|null $homeparty_id
|
||||
* @return ShoppingUser
|
||||
*/
|
||||
private function initializeShoppingUser($is_for, $is_from, $homeparty_id = null)
|
||||
{
|
||||
$shopping_user = new ShoppingUser();
|
||||
$shopping_user->is_for = $is_for;
|
||||
$shopping_user->is_from = $is_from;
|
||||
$shopping_user->homeparty_id = $homeparty_id;
|
||||
$shopping_user->mode = 'prev';
|
||||
$shopping_user->language = \App::getLocale();
|
||||
|
||||
return $shopping_user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt den existierenden ShoppingUser und bereitet ihn vor
|
||||
*
|
||||
* @return ShoppingUser
|
||||
*/
|
||||
private function getExistingShoppingUser()
|
||||
{
|
||||
$shopping_user = ShoppingUser::findOrFail($this->checkoutRepo->getSessionPayments('shopping_user_id'));
|
||||
$shopping_user->billing_state = Shop::getCountryShippingCountryId($shopping_user->billing_country_id);
|
||||
$shopping_user->shipping_state = Shop::getCountryShippingCountryId($shopping_user->shipping_country_id);
|
||||
$shopping_user->same_as_billing = $shopping_user->same_as_billing ? false : true; // reinvert
|
||||
|
||||
return $shopping_user;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Bereitet die ShoppingUser-Daten vor
|
||||
*
|
||||
|
|
@ -152,25 +110,23 @@ class CheckoutController extends Controller
|
|||
if ($shopping_user->same_as_billing === NULL) {
|
||||
$shopping_user->same_as_billing = false;
|
||||
}
|
||||
|
||||
if (!$shopping_user->billing_country_id) {
|
||||
$shopping_user->billing_country_id = Yard::instance('shopping')->getUserCountryId();
|
||||
$shopping_user->billing_country_id = Yard::instance($this->instance)->getUserCountryId();
|
||||
// Die Zeile unten entfernen, da die Relation automatisch geladen wird
|
||||
// $shopping_user->billing_country = Yard::instance('shopping')->getUserCountry();
|
||||
// $shopping_user->billing_country = Yard::instance($this->instance)->getUserCountry();
|
||||
}
|
||||
|
||||
if (!$shopping_user->shipping_country_id) {
|
||||
$shopping_user->shipping_country_id = Yard::instance('shopping')->getUserCountryId();
|
||||
$shopping_user->shipping_country_id = Yard::instance($this->instance)->getUserCountryId();
|
||||
// Die Zeile unten entfernen, da die Relation automatisch geladen wird
|
||||
// $shopping_user->shipping_country = Yard::instance('shopping')->getUserCountry();
|
||||
// $shopping_user->shipping_country = Yard::instance($this->instance)->getUserCountry();
|
||||
}
|
||||
if (old('selected_country') && old('selected_country') === 'change') {
|
||||
Session::forget('_old_input.selected_country');
|
||||
$shopping_user->billing_state = old('billing_state');
|
||||
$shopping_user->shipping_state = old('shipping_state');
|
||||
} else {
|
||||
$shopping_user->billing_state = Yard::instance('shopping')->getShippingCountryId();
|
||||
$shopping_user->shipping_state = Yard::instance('shopping')->getShippingCountryId();
|
||||
$shopping_user->billing_state = Yard::instance($this->instance)->getShippingCountryId();
|
||||
$shopping_user->shipping_state = Yard::instance($this->instance)->getShippingCountryId();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -228,9 +184,9 @@ class CheckoutController extends Controller
|
|||
private function handleCountryChange($data)
|
||||
{
|
||||
if (!Request::get('same_as_billing')) {
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($data['billing_state'], $data['is_for']);
|
||||
Yard::instance($this->instance)->setShippingCountryWithPrice($data['billing_state'], $data['is_for']);
|
||||
} else {
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($data['shipping_state'], $data['is_for']);
|
||||
Yard::instance($this->instance)->setShippingCountryWithPrice($data['shipping_state'], $data['is_for']);
|
||||
}
|
||||
|
||||
return back()->withInput(Request::all());
|
||||
|
|
@ -300,7 +256,7 @@ class CheckoutController extends Controller
|
|||
// Zahlung vorbereiten
|
||||
$pay = new PayoneController();
|
||||
$pay->init($shopping_user, $shopping_order);
|
||||
$amount = Yard::instance('shopping')->totalWithShipping(2, '.', '') * 100;
|
||||
$amount = Yard::instance($this->instance)->totalWithShipping(2, '.', '') * 100;
|
||||
$reference = $pay->setPrePayment($payment_method, $amount, 'EUR', $result);
|
||||
$this->checkoutRepo->putSessionPayments('payment_reference', $reference);
|
||||
$pay->setPersonalData();
|
||||
|
|
@ -345,7 +301,7 @@ class CheckoutController extends Controller
|
|||
if (is_null(Request::get('mandate_identification'))) {
|
||||
$pay = new PayoneController();
|
||||
$pay->init($shopping_user, $shopping_order);
|
||||
$amount = Yard::instance('shopping')->totalWithShipping(2, '.', '') * 100;
|
||||
$amount = Yard::instance($this->instance)->totalWithShipping(2, '.', '') * 100;
|
||||
$ret['elv'] = $pay->checkBankAccount($data, $amount, 'EUR', $shopping_user);
|
||||
|
||||
if ($ret['elv']['status'] === 'ERROR' || $ret['elv']['status'] === 'INVALID') {
|
||||
|
|
@ -388,6 +344,8 @@ class CheckoutController extends Controller
|
|||
{
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'is_checkout' => true,
|
||||
'yard_instance' => $this->instance,
|
||||
];
|
||||
|
||||
return view('web.templates.checkout-is-final', $data);
|
||||
|
|
@ -444,8 +402,8 @@ class CheckoutController extends Controller
|
|||
*/
|
||||
private function handleSuccessfulTransaction($ShoppingPayment, $reference)
|
||||
{
|
||||
Yard::instance('shopping')->destroy();
|
||||
$this->checkoutRepo->sessionDestroy();
|
||||
Yard::instance($this->instance)->destroy();
|
||||
$this->checkoutRepo->sessionDestroy(true);
|
||||
Util::setInstanceStatus(3, true); // link_pending
|
||||
|
||||
// Abo erstellen, falls nötig
|
||||
|
|
@ -458,6 +416,8 @@ class CheckoutController extends Controller
|
|||
'user_shop' => Util::getUserShop(),
|
||||
'order_reference' => $reference,
|
||||
'pay_trans' => $payt,
|
||||
'is_checkout' => true,
|
||||
'yard_instance' => $this->instance,
|
||||
];
|
||||
|
||||
return view('web.templates.checkout-final', $data);
|
||||
|
|
@ -476,9 +436,8 @@ class CheckoutController extends Controller
|
|||
if ($payt->shopping_payment->reference != $reference) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
Yard::instance('shopping')->destroy();
|
||||
$this->checkoutRepo->sessionDestroy();
|
||||
Yard::instance($this->instance)->destroy();
|
||||
$this->checkoutRepo->sessionDestroy(true);
|
||||
Util::setInstanceStatus(3, true); // link_pending
|
||||
|
||||
// Abo erstellen, falls nötig
|
||||
|
|
@ -495,6 +454,8 @@ class CheckoutController extends Controller
|
|||
'user_shop' => Util::getUserShop(),
|
||||
'order_reference' => $payt->shopping_payment->reference,
|
||||
'pay_trans' => $payt,
|
||||
'is_checkout' => true,
|
||||
'yard_instance' => $this->instance,
|
||||
];
|
||||
|
||||
return view('web.templates.checkout-final', $data);
|
||||
|
|
@ -549,4 +510,57 @@ class CheckoutController extends Controller
|
|||
Payment::paymentStatusSendMail($shopping_order, $shopping_payment, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisiert oder ruft einen Shopping-Benutzer ab
|
||||
*
|
||||
* @param string|null $is_from = shopping | user_order | user_order_ot | user_order_abo | user_order_abo_ot | user_order_ot_customer | user_order_abo_ot_customer
|
||||
* @param string|null $is_for = me | ot | abo-me | abo-ot | ot-customer | abo-ot-customer
|
||||
* @param array|null $shopping_data
|
||||
* @param int|null $homeparty_id
|
||||
* @return \App\Models\ShoppingUser
|
||||
*/
|
||||
private function initializeShoppingUserSession($is_from, $is_for, $shopping_data = null, $homeparty_id = null)
|
||||
{
|
||||
//check if shopping_user_id is set - der user ist bereits angelegt
|
||||
if ($this->checkoutRepo->getSessionPayments('shopping_user_id')) {
|
||||
return $this->getExistingShoppingUser();
|
||||
}
|
||||
//kommt vom Salescenter
|
||||
if ($shopping_data && $is_from !== 'shopping') {
|
||||
$shopping_user = $this->checkoutRepo->shoppingUserAuthData($is_from, $is_for, $shopping_data);
|
||||
$shopping_user->save();
|
||||
$this->checkoutRepo->putSessionPayments('shopping_user_id', $shopping_user->id);
|
||||
return $shopping_user;
|
||||
}
|
||||
|
||||
//kommt aus dem Salescenter mit bestelllink oder aus dem Webshop
|
||||
if ($is_from === 'shopping') {
|
||||
//Bestelllink
|
||||
if ($is_for === 'ot-customer' || $is_for === 'abo-ot-customer') {
|
||||
//customer shop mit den Daten aus dem Salescenter shopping_data
|
||||
return $this->checkoutRepo->makeCustomerShoppingUser($shopping_data, $is_for, $is_from);
|
||||
}
|
||||
//Webshop
|
||||
return $this->checkoutRepo->initShoppingUser($is_for, $is_from, $homeparty_id);
|
||||
}
|
||||
|
||||
return $this->getExistingShoppingUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt den existierenden ShoppingUser und bereitet ihn vor
|
||||
*
|
||||
* @return ShoppingUser
|
||||
*/
|
||||
private function getExistingShoppingUser()
|
||||
{
|
||||
$shopping_user = ShoppingUser::findOrFail($this->checkoutRepo->getSessionPayments('shopping_user_id'));
|
||||
$shopping_user->billing_state = Shop::getCountryShippingCountryId($shopping_user->billing_country_id);
|
||||
$shopping_user->shipping_state = Shop::getCountryShippingCountryId($shopping_user->shipping_country_id);
|
||||
$shopping_user->same_as_billing = $shopping_user->same_as_billing ? false : true; // reinvert
|
||||
|
||||
return $shopping_user;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -34,7 +34,8 @@ class ContactController extends Controller
|
|||
$data = [
|
||||
'GOOGLE_ReCAPTCHA_KEY' => $this->GOOGLE_ReCAPTCHA_KEY,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'mylangs' => Shop::getLangChange(),
|
||||
'mylangs' => Shop::getLangChange('webshop'),
|
||||
'yard_instance' => 'webshop',
|
||||
|
||||
];
|
||||
return view('web.templates.kontakt', $data);
|
||||
|
|
@ -95,7 +96,8 @@ class ContactController extends Controller
|
|||
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'mylangs' => Shop::getLangChange(),
|
||||
'mylangs' => Shop::getLangChange('webshop'),
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
return view('web.templates.contact-final', $data);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ class RegisterController extends Controller
|
|||
$data = [
|
||||
'GOOGLE_ReCAPTCHA_KEY' => $this->GOOGLE_ReCAPTCHA_KEY,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
return view('web.templates.registrierung', $data);
|
||||
}
|
||||
|
|
@ -59,7 +60,8 @@ class RegisterController extends Controller
|
|||
$data = [
|
||||
'GOOGLE_ReCAPTCHA_KEY' => $this->GOOGLE_ReCAPTCHA_KEY,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'from_member_id' => $member_id
|
||||
'from_member_id' => $member_id,
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
return view('web.templates.registrierung', $data);
|
||||
}
|
||||
|
|
@ -129,6 +131,7 @@ class RegisterController extends Controller
|
|||
{
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
return view('web.templates.registrierung_finish', $data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,9 +26,11 @@ class SiteController extends Controller
|
|||
'products' => Product::whereIn('slug', $products)->where('active', true)->whereJsonContains('show_on', '1')->get(),
|
||||
'set_products' => Product::whereIn('slug', $set_products)->where('active', true)->whereJsonContains('show_on', '1')->get(),
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'mylangs' => Shop::getLangChange(),
|
||||
'mylangs' => Shop::getLangChange('webshop'),
|
||||
'site' => IqSite::find(1),
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
|
||||
return view('web.index', $data);
|
||||
}
|
||||
|
||||
|
|
@ -39,13 +41,13 @@ class SiteController extends Controller
|
|||
public function changeLang(){
|
||||
$data = Request::all();
|
||||
if(isset($data['change_country_id'])){
|
||||
$mylangs = Shop::getLangChange();
|
||||
$mylangs = Shop::getLangChange('webshop');
|
||||
foreach($mylangs as $code => $country){
|
||||
if(strtolower($data['change_country_id']) === strtolower($code)){
|
||||
\Session::put('user_init_country', strtolower($code));
|
||||
\Session::forget('user_init_country_options');
|
||||
\Session::put('locale', strtolower($data['change_locale_id']));
|
||||
Shop::initUserShopLang($country);
|
||||
Shop::initUserShopLang($country, 'webshop');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
|
@ -88,33 +90,33 @@ class SiteController extends Controller
|
|||
}
|
||||
|
||||
//bestelland / versandland
|
||||
if(array_key_exists($country, Shop::getLangChange())){
|
||||
if(array_key_exists($country, Shop::getLangChange('webshop'))){
|
||||
\Session::put('user_init_country_options', $country);
|
||||
}else{
|
||||
\Session::put('user_init_country_options', 'de');
|
||||
}
|
||||
|
||||
return redirect(route('home'));
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
public function site($site, $subsite = false, $product_slug = false)
|
||||
{
|
||||
|
||||
$this->setIPInfo();
|
||||
$subsite = trim($subsite, '/');
|
||||
$product_slug = trim($product_slug, '/');
|
||||
if($product_slug){
|
||||
|
||||
$category = Category::where('slug', $subsite)->where('active', true)->first();
|
||||
$product = Product::where('slug', $product_slug)->where('active', true)->whereJsonContains('show_on', '1')->first();
|
||||
if ($category && $product) {
|
||||
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'mylangs' => Shop::getLangChange(),
|
||||
'mylangs' => Shop::getLangChange('webshop'),
|
||||
'subsite' => $subsite,
|
||||
'categories' => Category::where('active', true)->orderBy('pos', 'ASC')->get(),
|
||||
'product' => $product,
|
||||
'p_count' => Product::where('active', true)->whereJsonContains('show_on', '1')->count(),
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
return view('web.templates.produkte-show', $data);
|
||||
}
|
||||
|
|
@ -135,7 +137,7 @@ class SiteController extends Controller
|
|||
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'mylangs' => Shop::getLangChange(),
|
||||
'mylangs' => Shop::getLangChange('webshop'),
|
||||
'subsite' => $subsite,
|
||||
'categories' => Category::where('active', true)->orderBy('pos', 'DESC')->get(),
|
||||
'products' => false,
|
||||
|
|
@ -143,6 +145,7 @@ class SiteController extends Controller
|
|||
'p_count' => Product::where('active', true)->whereJsonContains('show_on', '1')->count(),
|
||||
'headline' => $category->getLang('headline'),
|
||||
'headline_image' => $headline_image,
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
return view('web.templates.' . $site, $data);
|
||||
|
||||
|
|
@ -150,7 +153,7 @@ class SiteController extends Controller
|
|||
}
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'mylangs' => Shop::getLangChange(),
|
||||
'mylangs' => Shop::getLangChange('webshop'),
|
||||
'subsite' => 'alle-produkte',
|
||||
'categories' => Category::where('active', true)->orderBy('pos', 'DESC')->get(),
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', '1')->orderBy('pos', 'DESC')->get(),
|
||||
|
|
@ -158,12 +161,14 @@ class SiteController extends Controller
|
|||
'p_count' => Product::where('active', true)->whereJsonContains('show_on', '1')->count(),
|
||||
'headline' => __('website.productworld'),
|
||||
'headline_image' => false,
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
return view('web.templates.'.$site, $data);
|
||||
}
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'mylangs' => Shop::getLangChange(),
|
||||
'mylangs' => Shop::getLangChange('webshop'),
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
if($subsite){
|
||||
if(!view()->exists('web.templates.'.$subsite)){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue