20-02-2026
This commit is contained in:
parent
a8b395e20d
commit
a00c42e770
252 changed files with 28785 additions and 8907 deletions
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Request;
|
||||
use App\Services\Shop;
|
||||
use App\Models\UserAbo;
|
||||
use App\Services\AboOrderCart;
|
||||
use App\Repositories\AboRepository;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Models\UserAbo;
|
||||
use App\Repositories\AboRepository;
|
||||
use App\Services\AboItemHistoryService;
|
||||
use App\Services\AboOrderCart;
|
||||
use App\Services\Shop;
|
||||
use Request;
|
||||
|
||||
class AboController extends Controller
|
||||
{
|
||||
|
|
@ -26,26 +26,27 @@ class AboController extends Controller
|
|||
set_user_attr('filter_user_shop_id', null);
|
||||
set_user_attr('filter_status', null);
|
||||
set_user_attr('filter_member_id', null);
|
||||
|
||||
return redirect(route('admin_sales_customers'));
|
||||
}
|
||||
|
||||
//$filter_user_shops = UserAbo::join('user_shops', 'user_shop_id', '=', 'user_shops.id')->orderBy('slug')->get()->pluck('slug', 'id')->unique()->toArray();
|
||||
// $filter_user_shops = UserAbo::join('user_shops', 'user_shop_id', '=', 'user_shops.id')->orderBy('slug')->get()->pluck('slug', 'id')->unique()->toArray();
|
||||
$filter_members = UserAbo::join('users', 'user_id', '=', 'users.id')->groupBy('user_id')->join('user_accounts', 'account_id', '=', 'user_accounts.id')->select('users.id', 'users.email', 'user_accounts.first_name', 'user_accounts.last_name')->get();
|
||||
|
||||
$data = [
|
||||
//'filter_user_shops' => $filter_user_shops,
|
||||
// 'filter_user_shops' => $filter_user_shops,
|
||||
'filter_members' => $filter_members,
|
||||
];
|
||||
|
||||
return view('admin.abo.index', $data);
|
||||
}
|
||||
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
$data = Request::all();
|
||||
$user_abo = UserAbo::findOrFail($id);
|
||||
|
||||
//init Yard
|
||||
// init Yard
|
||||
AboOrderCart::initYard($user_abo);
|
||||
$customer_detail = AboOrderCart::getCustomerDetail();
|
||||
AboOrderCart::makeOrderYard($user_abo);
|
||||
|
|
@ -62,10 +63,10 @@ class AboController extends Controller
|
|||
'view' => $user_abo->is_for,
|
||||
'comp_products' => $comp_products,
|
||||
];
|
||||
|
||||
return view('admin.abo.detail', $data);
|
||||
}
|
||||
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$data = Request::all();
|
||||
|
|
@ -74,29 +75,51 @@ class AboController extends Controller
|
|||
$user_abo = UserAbo::findOrFail($data['id']);
|
||||
$this->aboRepository->setModel($user_abo);
|
||||
$this->aboRepository->update($data);
|
||||
|
||||
return redirect(route('admin_abos_detail', [$id]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function rollback($id)
|
||||
{
|
||||
$user_abo = UserAbo::findOrFail($id);
|
||||
|
||||
AboOrderCart::initYard($user_abo);
|
||||
|
||||
$success = AboItemHistoryService::rollbackToInitial($user_abo);
|
||||
|
||||
if ($success) {
|
||||
$user_abo->refresh();
|
||||
AboOrderCart::makeOrderYard($user_abo);
|
||||
AboOrderCart::checkNumOfCompProducts($user_abo);
|
||||
|
||||
\Session()->flash('alert-success', __('abo_history.rollback_success'));
|
||||
} else {
|
||||
\Session()->flash('alert-error', __('abo_history.rollback_no_data'));
|
||||
}
|
||||
|
||||
return redirect(route('admin_abos_detail', [$id]));
|
||||
}
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
|
||||
$query = UserAbo::with('user_abo_orders')->with('shopping_user')->select('user_abos.*');
|
||||
|
||||
set_user_attr('filter_member_id', Request::get('filter_member_id'));
|
||||
if (Request::get('filter_member_id') != "") {
|
||||
if (Request::get('filter_member_id') != '') {
|
||||
$query->where('user_id', '=', Request::get('filter_member_id'));
|
||||
}
|
||||
|
||||
set_user_attr('filter_status', Request::get('filter_status'));
|
||||
if (Request::get('filter_status') != "") {
|
||||
if (Request::get('filter_status') != '') {
|
||||
$query->where('status', '=', Request::get('filter_status'));
|
||||
}
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (UserAbo $user_abo) {
|
||||
return '<a href="' . route('admin_abos_detail', [$user_abo->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
return '<a href="'.route('admin_abos_detail', [$user_abo->id]).'" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('start_date', function (UserAbo $user_abo) {
|
||||
return $user_abo->start_date;
|
||||
|
|
@ -121,14 +144,14 @@ class AboController extends Controller
|
|||
return $user_abo->getCountOrders();
|
||||
})
|
||||
->addColumn('amount', function (UserAbo $user_abo) {
|
||||
return $user_abo->getFormattedAmount() . ' €';
|
||||
return $user_abo->getFormattedAmount().' €';
|
||||
})
|
||||
->addColumn('payment', function (UserAbo $user_abo) {
|
||||
return $user_abo->getPaymentType();
|
||||
})
|
||||
->addColumn('member', function (UserAbo $user_abo) {
|
||||
if (isset($user_abo->shopping_user) && $user_abo->shopping_user->member_id > 0) {
|
||||
return '<a href="' . route('admin_lead_edit', [$user_abo->shopping_user->member_id]) . '">' . $user_abo->shopping_user->member->getFullName() . '</a>';
|
||||
return '<a href="'.route('admin_lead_edit', [$user_abo->shopping_user->member_id]).'">'.$user_abo->shopping_user->member->getFullName().'</a>';
|
||||
}
|
||||
})
|
||||
->addColumn('payone_userid', function (UserAbo $user_abo) {
|
||||
|
|
|
|||
|
|
@ -2,21 +2,20 @@
|
|||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
|
||||
|
||||
use Util;
|
||||
use Response;
|
||||
use Request;
|
||||
use App\Models\DcTag;
|
||||
use App\Models\DcFile;
|
||||
use App\Models\DcCategory;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\DC\TagRepository;
|
||||
use App\Models\DcCategory;
|
||||
use App\Models\DcFile;
|
||||
use App\Models\DcTag;
|
||||
use App\Repositories\DC\FileRepository;
|
||||
use App\Repositories\DC\TagRepository;
|
||||
use Request;
|
||||
use Response;
|
||||
use Util;
|
||||
|
||||
class DownloadController extends Controller
|
||||
{
|
||||
protected $tagRepository;
|
||||
|
||||
protected $fileRepository;
|
||||
|
||||
public function __construct(TagRepository $tagRepository, FileRepository $fileRepository)
|
||||
|
|
@ -26,139 +25,160 @@ class DownloadController extends Controller
|
|||
$this->fileRepository = $fileRepository;
|
||||
}
|
||||
|
||||
public function files(){
|
||||
$q = DcFile::orderBy('id', 'desc')->get(); //File::all();
|
||||
public function files()
|
||||
{
|
||||
$q = DcFile::orderBy('id', 'desc')->get(); // File::all();
|
||||
$data = [
|
||||
'files' => $q,
|
||||
];
|
||||
|
||||
return view('admin.downloadcenter.files', $data);
|
||||
}
|
||||
|
||||
public function fileEdit($id = null){
|
||||
public function fileEdit($id = null)
|
||||
{
|
||||
$file = $id ? DcFile::find($id) : new DcFile;
|
||||
$data = [
|
||||
'file' => $file,
|
||||
'categories' => DcCategory::where('active', true)->orderBy('pos')->get(),
|
||||
'tags' => DcTag::orderBy('pos')->get(),
|
||||
];
|
||||
|
||||
return view('admin.downloadcenter.file_edit', $data);
|
||||
}
|
||||
|
||||
public function fileUpdate($do, $id){
|
||||
|
||||
if($do === 'make_thumb'){
|
||||
public function fileUpdate($do, $id)
|
||||
{
|
||||
|
||||
if ($do === 'make_thumb') {
|
||||
$this->fileRepository->makeThumb($id);
|
||||
\Session()->flash('alert-success', 'Vorschaubild erstellt!');
|
||||
|
||||
return back();
|
||||
}
|
||||
if($do === 'delete'){
|
||||
if ($do === 'delete') {
|
||||
$this->fileRepository->deleteFile($id);
|
||||
\Session()->flash('alert-success', 'Datei gelöscht!');
|
||||
|
||||
return redirect(route('admin_downloadcenter_files'));
|
||||
}
|
||||
if($do === 'delete_thumb'){
|
||||
if ($do === 'delete_thumb') {
|
||||
$this->fileRepository->deleteThumb($id);
|
||||
\Session()->flash('alert-success', 'Vorschaubild gelöscht!');
|
||||
|
||||
return back();
|
||||
}
|
||||
if($do === 'deactivate'){
|
||||
if ($do === 'deactivate') {
|
||||
$file = DcFile::findOrFail($id);
|
||||
$file->active = false;
|
||||
$file->save();
|
||||
\Session()->flash('alert-success', 'Datei nicht anzeigen!');
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
if($do === 'activate'){
|
||||
if ($do === 'activate') {
|
||||
$file = DcFile::findOrFail($id);
|
||||
$file->active = true;
|
||||
$file->save();
|
||||
\Session()->flash('alert-success', 'Datei wird angezeigt!');
|
||||
|
||||
return back();
|
||||
}
|
||||
if($do === 'file_tags_update'){
|
||||
if ($do === 'file_tags_update') {
|
||||
$file = DcFile::findOrFail($id);
|
||||
$this->fileRepository->tagsUpdate($id, Request::get('nestable_check'));
|
||||
$tags = Request::get('nestable_check', []);
|
||||
$this->fileRepository->tagsUpdate($id, is_array($tags) ? $tags : []);
|
||||
\Session()->flash('alert-success', 'Tags aktualisiert!');
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function upload(){
|
||||
public function upload()
|
||||
{
|
||||
return view('admin.downloadcenter.file_upload');
|
||||
}
|
||||
|
||||
public function uploadFile(){
|
||||
public function uploadFile()
|
||||
{
|
||||
$data = Request::all();
|
||||
$file = $this->fileRepository->uploadFile($data);
|
||||
|
||||
|
||||
return Response::json([
|
||||
'error' => false,
|
||||
'filename' => $file->filename,
|
||||
'filedata' => '',
|
||||
'code' => 200
|
||||
'code' => 200,
|
||||
], 200);
|
||||
|
||||
//return response()->json(['success'=>basename($file)]);
|
||||
|
||||
// return response()->json(['success'=>basename($file)]);
|
||||
}
|
||||
|
||||
public function tags($flash = false){
|
||||
|
||||
public function tags($flash = false)
|
||||
{
|
||||
|
||||
$active = DcCategory::orderBy('pos')->get();
|
||||
$inactive = DcTag::where('category_id', null)->get();
|
||||
$data = [
|
||||
'category_active' => $active,
|
||||
'tags_inactive' => $inactive,
|
||||
];
|
||||
if($flash){
|
||||
if ($flash) {
|
||||
\Session()->flash('alert-success', 'gespeichert!');
|
||||
}
|
||||
|
||||
return view('admin.downloadcenter.tags', $data);
|
||||
}
|
||||
|
||||
public function storeItem($obj = false){
|
||||
public function storeItem($obj = false)
|
||||
{
|
||||
$data = Request::all();
|
||||
|
||||
return $this->tagRepository->storeItem($obj, $data);
|
||||
|
||||
return redirect(route('admin_downloadcenter_tags'));
|
||||
}
|
||||
|
||||
|
||||
public function deleteItem($obj, $id){
|
||||
public function deleteItem($obj, $id)
|
||||
{
|
||||
$this->tagRepository->deleteItem($obj, $id);
|
||||
|
||||
return redirect(route('admin_downloadcenter_tags'));
|
||||
}
|
||||
|
||||
public function datatable(){
|
||||
public function datatable()
|
||||
{
|
||||
|
||||
$query = DcFile::with('tags')->select('dc_files.*');
|
||||
|
||||
$query = DcFile::with('tags')->select('dc_files.*');
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (DcFile $file) {
|
||||
return '<a href="'.route('admin_downloadcenter_file_edit', [$file->id]).'" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('image', function (DcFile $file) {
|
||||
return ($file->hasThumb() && $file->hasBig()) ?
|
||||
'<img src="' .route('storage_file', [$file->id, 'dc_thumb', 'image']) . '" class="img-fluid img-responsive" style="max-width: 100px;">' :
|
||||
return ($file->hasThumb() && $file->hasBig()) ?
|
||||
'<img src="'.route('storage_file', [$file->id, 'dc_thumb', 'image']).'" class="img-fluid img-responsive" style="max-width: 100px;">' :
|
||||
'<a href="'.route('admin_downloadcenter_file', ['make_thumb', $file->id]).'" class="btn btn-sm btn-warning"> Vorschaubild<br>erstellen <i class="ion ion-md-refresh-circle"></i></a>';
|
||||
})
|
||||
->addColumn('name', function (DcFile $file) {
|
||||
//Storage::disk('local')->url($file->filename) }}
|
||||
// Storage::disk('local')->url($file->filename) }}
|
||||
return '<a target="_blank" href="'.route('storage_file', [$file->id, 'dc_file', 'stream']).'">'.$file->original_name.'</a>';
|
||||
// return '<a target="_blank" href="">'.$file->original_name.'</a>';
|
||||
// return '<a target="_blank" href="">'.$file->original_name.'</a>';
|
||||
})
|
||||
->addColumn('category', function (DcFile $file) {
|
||||
//return $file->category ? $file->category->name : '';
|
||||
// return $file->category ? $file->category->name : '';
|
||||
})
|
||||
->addColumn('tags', function (DcFile $file) {
|
||||
//return $file->hasTags() ? '<span class="badge badge-pill badge-success">('.$file->fileTag()->count().')</span>' : '<span class="badge badge-pill badge-dange">X</span>';
|
||||
// return $file->hasTags() ? '<span class="badge badge-pill badge-success">('.$file->fileTag()->count().')</span>' : '<span class="badge badge-pill badge-dange">X</span>';
|
||||
return $file->tags->implode('name', '<br>');
|
||||
})
|
||||
->addColumn('size', function (DcFile $file) {
|
||||
return Util::formatBytes($file->size);
|
||||
})
|
||||
})
|
||||
->addColumn('active', function (DcFile $file) {
|
||||
return get_active_badge($file->active);
|
||||
//return $file->active ? '<span class="badge badge-pill badge-success"><i class="fa fa-check-circle"></i> aktiv</span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times-circle"></i> inaktiv</span>';
|
||||
// return $file->active ? '<span class="badge badge-pill badge-success"><i class="fa fa-check-circle"></i> aktiv</span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times-circle"></i> inaktiv</span>';
|
||||
})
|
||||
->addColumn('created_at', function (DcFile $file) {
|
||||
return $file->created_at->format('d.m.Y H:i');
|
||||
|
|
@ -169,8 +189,8 @@ class DownloadController extends Controller
|
|||
->addColumn('action', function (DcFile $file) {
|
||||
return '<a onclick="return confirm(\'Diese Datei wirklich löschen?\');" class="btn btn-sm btn-danger" href="'.route('admin_downloadcenter_file', ['delete', $file->id]).'"><i class="fa fa-trash"></i></a>';
|
||||
})
|
||||
->filterColumn('name', function($query, $keyword) {
|
||||
if($keyword != ""){
|
||||
->filterColumn('name', function ($query, $keyword) {
|
||||
if ($keyword != '') {
|
||||
$query->where('original_name', 'LIKE', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
|
|
@ -184,5 +204,4 @@ class DownloadController extends Controller
|
|||
->rawColumns(['id', 'image', 'name', 'active', 'tags', 'action'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
708
app/Http/Controllers/AdminUserCleanupController.php
Normal file
708
app/Http/Controllers/AdminUserCleanupController.php
Normal file
|
|
@ -0,0 +1,708 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\ShoppingUserMemberLog;
|
||||
use App\Models\UserCleanUpLog;
|
||||
use App\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AdminUserCleanupController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('superadmin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Übersicht deaktivierter und gelöschter User
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('admin.user.cleanup.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protokoll der User-Cleanup-Logs (Downline-Übertragungen)
|
||||
*/
|
||||
public function logs()
|
||||
{
|
||||
return view('admin.user.cleanup.logs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protokoll der Shopping-User-Member-Logs (Kunden-Übertragungen)
|
||||
*/
|
||||
public function shoppingLogs()
|
||||
{
|
||||
return view('admin.user.cleanup.shopping_logs');
|
||||
}
|
||||
|
||||
/**
|
||||
* DataTable für deaktivierte/gelöschte User
|
||||
*/
|
||||
public function getInactiveUsers()
|
||||
{
|
||||
// Deaktivierte User (active=false) ODER gelöschte User (mit pre_deleted_at)
|
||||
$query = User::withTrashed()
|
||||
->where(function ($q) {
|
||||
$q->where('active', false)
|
||||
->orWhere('pre_deleted_at', '!=', null);
|
||||
})
|
||||
->with('account')
|
||||
->select('users.*')
|
||||
->where('users.admin', '<', 5);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('user_id', function (User $user) {
|
||||
return $user->id;
|
||||
})
|
||||
->addColumn('first_name', function (User $user) {
|
||||
return $user->account ? $user->account->first_name : '';
|
||||
})
|
||||
->addColumn('last_name', function (User $user) {
|
||||
return $user->account ? $user->account->last_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('m_account', function (User $user) {
|
||||
return $user->account ? $user->account->m_account : '';
|
||||
})
|
||||
->addColumn('status', function (User $user) {
|
||||
if ($user->pre_deleted_at) {
|
||||
return '<span class="badge badge-danger">Gelöscht</span>';
|
||||
}
|
||||
if (! $user->active) {
|
||||
return '<span class="badge badge-warning">Deaktiviert</span>';
|
||||
}
|
||||
|
||||
return '<span class="badge badge-success">Aktiv</span>';
|
||||
})
|
||||
->addColumn('deleted_at', function (User $user) {
|
||||
if ($user->pre_deleted_at) {
|
||||
return \Carbon\Carbon::parse($user->pre_deleted_at)->format('d.m.Y H:i');
|
||||
}
|
||||
|
||||
return '-';
|
||||
})
|
||||
->addColumn('payment_account', function (User $user) {
|
||||
return $user->getPaymentAccountDateFormat();
|
||||
})
|
||||
->addColumn('m_sponsor', function (User $user) {
|
||||
if ($user->m_sponsor) {
|
||||
$sponsor = User::find($user->m_sponsor);
|
||||
|
||||
return $sponsor ? $sponsor->email : 'ID: '.$user->m_sponsor;
|
||||
}
|
||||
|
||||
return '-';
|
||||
})
|
||||
->addColumn('pre_sponsor', function (User $user) {
|
||||
if ($user->pre_sponsor) {
|
||||
$sponsor = User::withTrashed()->find($user->pre_sponsor);
|
||||
|
||||
return $sponsor ? $sponsor->email : 'ID: '.$user->pre_sponsor;
|
||||
}
|
||||
|
||||
return '-';
|
||||
})
|
||||
->addColumn('childs_count', function (User $user) {
|
||||
$count = User::where('m_sponsor', $user->id)->count();
|
||||
|
||||
return $count > 0 ? '<span class="badge badge-info">'.$count.'</span>' : '0';
|
||||
})
|
||||
->addColumn('shopping_users_count', function (User $user) {
|
||||
$count = ShoppingUser::where('member_id', $user->id)->count();
|
||||
|
||||
return $count > 0 ? '<span class="badge badge-info">'.$count.'</span>' : '0';
|
||||
})
|
||||
->addColumn('action', function (User $user) {
|
||||
$html = '';
|
||||
if ($user->pre_deleted_at) {
|
||||
$html .= '<a href="'.route('admin_lead_edit', [$user->id]).'" class="btn btn-sm btn-info" title="Details"><i class="fa fa-eye"></i></a> ';
|
||||
} else {
|
||||
$html .= '<a href="'.route('admin_lead_edit', [$user->id]).'" class="btn btn-sm btn-primary" title="Bearbeiten"><i class="fa fa-edit"></i></a> ';
|
||||
}
|
||||
|
||||
// Historie-Button
|
||||
$html .= ' <button class="btn btn-sm btn-secondary btn-user-history" data-id="'.$user->id.'" data-email="'.$user->email.'" title="Historie & Details"><i class="fa fa-history"></i></button>';
|
||||
|
||||
// Restore-Button für gelöschte User
|
||||
if ($user->pre_deleted_at) {
|
||||
$html .= ' <button class="btn btn-sm btn-success" data-toggle="modal" data-target="#modal-restore-user" data-id="'.$user->id.'" data-email="'.str_replace('delete-', '', $user->email).'" title="Wiederherstellen"><i class="fa fa-undo"></i></button>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
})
|
||||
->orderColumn('user_id', 'id $1')
|
||||
->orderColumn('email', 'email $1')
|
||||
->orderColumn('status', 'active $1')
|
||||
->rawColumns(['email', 'status', 'childs_count', 'shopping_users_count', 'action'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* DataTable für UserCleanUpLogs (Downline-Übertragungen)
|
||||
*/
|
||||
public function getCleanupLogs()
|
||||
{
|
||||
$query = UserCleanUpLog::with(['inactive_sponsor.account', 'child_user.account', 'new_sponsor.account'])
|
||||
->select('user_clean_up_logs.*');
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (UserCleanUpLog $log) {
|
||||
return $log->id;
|
||||
})
|
||||
->addColumn('inactive_sponsor', function (UserCleanUpLog $log) {
|
||||
if ($log->inactive_sponsor && $log->inactive_sponsor->account) {
|
||||
$name = trim($log->inactive_sponsor->account->first_name.' '.$log->inactive_sponsor->account->last_name);
|
||||
|
||||
return ($name ?: 'N/A').'<br><small>'.$log->inactive_sponsor->email.'</small>';
|
||||
}
|
||||
|
||||
return 'ID: '.$log->inactive_sponsor_id;
|
||||
})
|
||||
->addColumn('child_user', function (UserCleanUpLog $log) {
|
||||
if ($log->child_user && $log->child_user->account) {
|
||||
$name = trim($log->child_user->account->first_name.' '.$log->child_user->account->last_name);
|
||||
|
||||
return ($name ?: 'N/A').'<br><small>'.$log->child_user->email.'</small>';
|
||||
}
|
||||
|
||||
return 'ID: '.$log->child_user_id;
|
||||
})
|
||||
->addColumn('new_sponsor', function (UserCleanUpLog $log) {
|
||||
$html = '';
|
||||
|
||||
// Original-Sponsor aus dem Log
|
||||
if ($log->new_sponsor && $log->new_sponsor->account) {
|
||||
$name = trim($log->new_sponsor->account->first_name.' '.$log->new_sponsor->account->last_name);
|
||||
$html .= '<span class="text-muted"><small>Damals:</small></span><br>';
|
||||
$html .= ($name ?: 'N/A').'<br><small>'.$log->new_sponsor->email.'</small>';
|
||||
} else {
|
||||
$html .= 'ID: '.$log->new_sponsor_id;
|
||||
}
|
||||
|
||||
// Prüfe aktuellen Sponsor des child_user
|
||||
if ($log->child_user) {
|
||||
$currentSponsorId = $log->child_user->m_sponsor;
|
||||
|
||||
// Wenn aktueller Sponsor ANDERS ist als im Log
|
||||
if ($currentSponsorId && $currentSponsorId != $log->new_sponsor_id) {
|
||||
$currentSponsor = User::with('account')->find($currentSponsorId);
|
||||
|
||||
if ($currentSponsor) {
|
||||
$html .= '<hr class="my-1">';
|
||||
$html .= '<span class="badge badge-warning">Geändert!</span><br>';
|
||||
$html .= '<span class="text-success"><small>Aktuell:</small></span><br>';
|
||||
|
||||
if ($currentSponsor->account) {
|
||||
$currentName = trim($currentSponsor->account->first_name.' '.$currentSponsor->account->last_name);
|
||||
$html .= '<strong>'.($currentName ?: 'N/A').'</strong><br>';
|
||||
}
|
||||
|
||||
$html .= '<small>'.$currentSponsor->email.'</small>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
})
|
||||
->addColumn('created_at', function (UserCleanUpLog $log) {
|
||||
return \Carbon\Carbon::parse($log->created_at)->format('d.m.Y H:i');
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->rawColumns(['inactive_sponsor', 'child_user', 'new_sponsor'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* DataTable für ShoppingUserMemberLogs (Kunden-Übertragungen)
|
||||
*/
|
||||
public function getShoppingLogs()
|
||||
{
|
||||
$query = ShoppingUserMemberLog::with(['pre_member.account', 'shopping_user', 'new_member.account'])
|
||||
->select('shopping_user_member_logs.*');
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (ShoppingUserMemberLog $log) {
|
||||
return $log->id;
|
||||
})
|
||||
->addColumn('pre_member', function (ShoppingUserMemberLog $log) {
|
||||
if ($log->pre_member && $log->pre_member->account) {
|
||||
$name = trim($log->pre_member->account->first_name.' '.$log->pre_member->account->last_name);
|
||||
|
||||
return ($name ?: 'N/A').'<br><small>'.$log->pre_member->email.'</small>';
|
||||
}
|
||||
|
||||
return 'ID: '.$log->pre_member_id;
|
||||
})
|
||||
->addColumn('shopping_user', function (ShoppingUserMemberLog $log) {
|
||||
if ($log->shopping_user) {
|
||||
$name = trim($log->shopping_user->billing_firstname.' '.$log->shopping_user->billing_lastname);
|
||||
|
||||
return ($name ?: 'N/A').'<br><small>'.$log->shopping_user->billing_email.'</small>';
|
||||
}
|
||||
|
||||
return 'ID: '.$log->shopping_user_id;
|
||||
})
|
||||
->addColumn('new_member', function (ShoppingUserMemberLog $log) {
|
||||
$html = '';
|
||||
|
||||
// Original-Berater aus dem Log
|
||||
if ($log->new_member && $log->new_member->account) {
|
||||
$name = trim($log->new_member->account->first_name.' '.$log->new_member->account->last_name);
|
||||
$html .= '<span class="text-muted"><small>Damals:</small></span><br>';
|
||||
$html .= ($name ?: 'N/A').'<br><small>'.$log->new_member->email.'</small>';
|
||||
} else {
|
||||
$html .= 'ID: '.$log->new_member_id;
|
||||
}
|
||||
|
||||
// Prüfe aktuellen Berater des Kunden
|
||||
if ($log->shopping_user) {
|
||||
$currentMemberId = $log->shopping_user->member_id;
|
||||
|
||||
// Wenn aktueller Berater ANDERS ist als im Log
|
||||
if ($currentMemberId && $currentMemberId != $log->new_member_id) {
|
||||
$currentMember = User::with('account')->find($currentMemberId);
|
||||
|
||||
if ($currentMember) {
|
||||
$html .= '<hr class="my-1">';
|
||||
$html .= '<span class="badge badge-warning">Geändert!</span><br>';
|
||||
$html .= '<span class="text-success"><small>Aktuell:</small></span><br>';
|
||||
|
||||
if ($currentMember->account) {
|
||||
$currentName = trim($currentMember->account->first_name.' '.$currentMember->account->last_name);
|
||||
$html .= '<strong>'.($currentName ?: 'N/A').'</strong><br>';
|
||||
}
|
||||
|
||||
$html .= '<small>'.$currentMember->email.'</small>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingUserMemberLog $log) {
|
||||
return \Carbon\Carbon::parse($log->created_at)->format('d.m.Y H:i');
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->rawColumns(['pre_member', 'shopping_user', 'new_member'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* User über Artisan Command wiederherstellen
|
||||
*/
|
||||
public function restore(\Illuminate\Http\Request $request)
|
||||
{
|
||||
$userId = $request->input('user_id');
|
||||
|
||||
if (! $userId) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Keine User-ID angegeben',
|
||||
], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
// Führe Artisan Command aus
|
||||
\Artisan::call('user:restore', ['user_id' => $userId]);
|
||||
|
||||
$output = \Artisan::output();
|
||||
|
||||
// Prüfe ob Command erfolgreich war (Exit Code 0)
|
||||
$exitCode = \Artisan::call('user:restore', ['user_id' => $userId]);
|
||||
|
||||
\Log::channel('cleanup')->info('AdminUserCleanupController restore via web: user_id='.$userId.' | exitCode='.$exitCode);
|
||||
|
||||
if ($exitCode === 0) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'User wurde erfolgreich wiederhergestellt',
|
||||
'output' => $output,
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Fehler beim Wiederherstellen (Exit Code: '.$exitCode.')',
|
||||
'output' => $output,
|
||||
], 500);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::channel('cleanup')->error('AdminUserCleanupController restore failed: '.$e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Exception: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Suche nach aktiven Sponsoren für Select2
|
||||
*/
|
||||
public function searchSponsors(\Illuminate\Http\Request $request)
|
||||
{
|
||||
$search = $request->input('q');
|
||||
$userId = $request->input('exclude_user_id'); // User selbst ausschließen
|
||||
$loadAll = $request->input('load_all', false); // Alle Sponsoren laden
|
||||
|
||||
$query = User::where('active', true)
|
||||
->where('admin', '<', 5)
|
||||
->where('blocked', false)
|
||||
->where('payment_account', '>=', now())
|
||||
->with('account')
|
||||
->orderBy('email', 'asc');
|
||||
|
||||
if ($userId) {
|
||||
$query->where('id', '!=', $userId);
|
||||
}
|
||||
|
||||
// Nur filtern wenn Suche vorhanden und nicht load_all
|
||||
if ($search && ! $loadAll) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('email', 'like', '%'.$search.'%')
|
||||
->orWhereHas('account', function ($q2) use ($search) {
|
||||
$q2->where('first_name', 'like', '%'.$search.'%')
|
||||
->orWhere('last_name', 'like', '%'.$search.'%')
|
||||
->orWhere('m_account', 'like', '%'.$search.'%');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Limit nur wenn nicht alle geladen werden sollen
|
||||
if (! $loadAll) {
|
||||
$query->limit(20);
|
||||
}
|
||||
|
||||
$users = $query->get()->map(function ($user) {
|
||||
$name = '';
|
||||
if ($user->account) {
|
||||
$name = trim($user->account->first_name.' '.$user->account->last_name);
|
||||
if ($name) {
|
||||
$name .= ' | ';
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $user->id,
|
||||
'text' => $name.$user->email.($user->account && $user->account->m_account ? ' #'.$user->account->m_account : ''),
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json(['results' => $users]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sponsor manuell neu zuweisen
|
||||
*/
|
||||
public function reassignSponsor(\Illuminate\Http\Request $request)
|
||||
{
|
||||
$userId = $request->input('user_id');
|
||||
$newSponsorId = $request->input('new_sponsor_id');
|
||||
// Boolean-Werte korrekt konvertieren (auch wenn sie als String ankommen)
|
||||
$transferDownline = filter_var($request->input('transfer_downline', false), FILTER_VALIDATE_BOOLEAN);
|
||||
$transferCustomers = filter_var($request->input('transfer_customers', false), FILTER_VALIDATE_BOOLEAN);
|
||||
|
||||
if (! $userId || ! $newSponsorId) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'User-ID und neuer Sponsor sind erforderlich',
|
||||
], 400);
|
||||
}
|
||||
|
||||
$user = User::withTrashed()->find($userId);
|
||||
$newSponsor = User::find($newSponsorId);
|
||||
|
||||
if (! $user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'User nicht gefunden',
|
||||
], 404);
|
||||
}
|
||||
|
||||
if (! $newSponsor || ! $newSponsor->active) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Neuer Sponsor nicht gefunden oder nicht aktiv',
|
||||
], 404);
|
||||
}
|
||||
|
||||
\DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$oldSponsorId = $user->m_sponsor;
|
||||
$logs = [];
|
||||
|
||||
// 1. Downline neu zuweisen (aus Logs - bereits übertragene)
|
||||
$childrenTransferred = 0;
|
||||
if ($transferDownline) {
|
||||
// Hole die Kinder aus den vorherigen Cleanup-Logs (die bereits VON diesem User weg übertragen wurden)
|
||||
$cleanupLogs = UserCleanUpLog::where('inactive_sponsor_id', $userId)->get();
|
||||
|
||||
\Log::channel('cleanup')->info('Reassigning downline from logs: found '.$cleanupLogs->count().' log entries for user_id='.$userId);
|
||||
|
||||
foreach ($cleanupLogs as $oldLog) {
|
||||
$child = User::find($oldLog->child_user_id);
|
||||
|
||||
if (! $child) {
|
||||
\Log::channel('cleanup')->warning('Child user not found: '.$oldLog->child_user_id);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Neuen Log erstellen für die Neu-Zuweisung
|
||||
UserCleanUpLog::create([
|
||||
'inactive_sponsor_id' => $child->m_sponsor, // Aktueller Sponsor (wohin es vorher übertragen wurde)
|
||||
'child_user_id' => $child->id,
|
||||
'new_sponsor_id' => $newSponsorId, // Neuer Sponsor
|
||||
]);
|
||||
|
||||
// Sponsor ändern
|
||||
$child->m_sponsor = $newSponsorId;
|
||||
$child->save();
|
||||
|
||||
$childrenTransferred++;
|
||||
|
||||
$logs[] = 'Downline: '.$child->email.' → Neuer Sponsor: '.$newSponsor->email;
|
||||
}
|
||||
|
||||
\Log::channel('cleanup')->info('Children reassigned: '.$childrenTransferred);
|
||||
}
|
||||
|
||||
// 2. Shopping-Kunden neu zuweisen (aus Logs - bereits übertragene)
|
||||
$customersTransferred = 0;
|
||||
if ($transferCustomers) {
|
||||
// Hole die Kunden aus den vorherigen Shopping-Logs (die bereits VON diesem User weg übertragen wurden)
|
||||
$shoppingLogs = ShoppingUserMemberLog::where('pre_member_id', $userId)->get();
|
||||
|
||||
\Log::channel('cleanup')->info('Reassigning customers from logs: found '.$shoppingLogs->count().' log entries for user_id='.$userId);
|
||||
|
||||
foreach ($shoppingLogs as $oldLog) {
|
||||
$customer = ShoppingUser::find($oldLog->shopping_user_id);
|
||||
|
||||
if (! $customer) {
|
||||
\Log::channel('cleanup')->warning('Shopping user not found: '.$oldLog->shopping_user_id);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Neuen Log erstellen für die Neu-Zuweisung
|
||||
ShoppingUserMemberLog::create([
|
||||
'pre_member_id' => $customer->member_id, // Aktueller Berater (wohin es vorher übertragen wurde)
|
||||
'shopping_user_id' => $customer->id,
|
||||
'new_member_id' => $newSponsorId, // Neuer Berater
|
||||
]);
|
||||
|
||||
// Member ändern
|
||||
$customer->member_id = $newSponsorId;
|
||||
$customer->save();
|
||||
|
||||
$customersTransferred++;
|
||||
|
||||
$logs[] = 'Kunde: '.$customer->billing_email.' → Neuer Berater: '.$newSponsor->email;
|
||||
}
|
||||
|
||||
\Log::channel('cleanup')->info('Customers reassigned: '.$customersTransferred);
|
||||
}
|
||||
|
||||
// 3. User selbst dem neuen Sponsor zuweisen
|
||||
$user->m_sponsor = $newSponsorId;
|
||||
$user->save();
|
||||
|
||||
\DB::commit();
|
||||
|
||||
// Cleanup-Log
|
||||
\Log::channel('cleanup')->info('Manual reassign sponsor: user_id='.$userId.' | old_sponsor='.$oldSponsorId.' | new_sponsor='.$newSponsorId.' | transfer_downline='.(int) $transferDownline.' | transfer_customers='.(int) $transferCustomers.' | by_admin='.Auth::id());
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Sponsor erfolgreich neu zugewiesen',
|
||||
'logs' => $logs,
|
||||
'transferred' => [
|
||||
'downline' => $childrenTransferred,
|
||||
'customers' => $customersTransferred,
|
||||
],
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
\DB::rollBack();
|
||||
\Log::channel('cleanup')->error('Manual reassign sponsor failed: user_id='.$userId.' | error='.$e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Fehler beim Neu-Zuweisen: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lade User-Historie: Downline-Position und Shopping-Kunden
|
||||
*/
|
||||
public function getUserHistory($userId)
|
||||
{
|
||||
$user = User::withTrashed()->with('account')->find($userId);
|
||||
|
||||
if (! $user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'User nicht gefunden',
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Aktueller/Vorheriger Sponsor
|
||||
$sponsor = null;
|
||||
$preSponsor = null;
|
||||
|
||||
if ($user->m_sponsor) {
|
||||
$sponsor = User::withTrashed()->with('account')->find($user->m_sponsor);
|
||||
}
|
||||
|
||||
if ($user->pre_sponsor) {
|
||||
$preSponsor = User::withTrashed()->with('account')->find($user->pre_sponsor);
|
||||
}
|
||||
|
||||
// Direkte Downline (Kinder) - nur die, die aktuell m_sponsor haben
|
||||
// pre_sponsor sind bereits deaktiviert und würden doppelt gezählt
|
||||
$children = User::withTrashed()
|
||||
->with('account')
|
||||
->where('m_sponsor', $userId)
|
||||
->get()
|
||||
->map(function ($child) use ($userId) {
|
||||
return [
|
||||
'id' => $child->id,
|
||||
'name' => $child->account ? trim($child->account->first_name.' '.$child->account->last_name) : 'N/A',
|
||||
'email' => $child->email,
|
||||
'active' => $child->active,
|
||||
'deleted' => $child->pre_deleted_at ? true : false,
|
||||
'is_pre_sponsor' => $child->pre_sponsor == $userId,
|
||||
];
|
||||
});
|
||||
|
||||
// Shopping-Kunden
|
||||
$shoppingUsers = ShoppingUser::where('member_id', $userId)
|
||||
->get()
|
||||
->map(function ($customer) {
|
||||
return [
|
||||
'id' => $customer->id,
|
||||
'name' => trim($customer->billing_firstname.' '.$customer->billing_lastname),
|
||||
'email' => $customer->billing_email,
|
||||
'city' => $customer->billing_city,
|
||||
'created_at' => \Carbon\Carbon::parse($customer->created_at)->format('d.m.Y'),
|
||||
];
|
||||
});
|
||||
|
||||
// Downline-Übertragungen (wo dieser User betroffen war)
|
||||
$cleanupLogs = UserCleanUpLog::with(['inactive_sponsor.account', 'child_user.account', 'new_sponsor.account'])
|
||||
->where(function ($query) use ($userId) {
|
||||
$query->where('inactive_sponsor_id', $userId)
|
||||
->orWhere('child_user_id', $userId);
|
||||
})
|
||||
->orderBy('created_at', 'desc')
|
||||
->get()
|
||||
->map(function ($log) use ($userId) {
|
||||
$data = [
|
||||
'type' => $log->inactive_sponsor_id == $userId ? 'as_inactive' : 'as_child',
|
||||
'child_user' => $log->child_user ? [
|
||||
'id' => $log->child_user->id,
|
||||
'name' => $log->child_user->account ? trim($log->child_user->account->first_name.' '.$log->child_user->account->last_name) : 'N/A',
|
||||
'email' => $log->child_user->email,
|
||||
'active' => $log->child_user->active,
|
||||
'deleted' => $log->child_user->pre_deleted_at ? true : false,
|
||||
] : null,
|
||||
'inactive_sponsor' => $log->inactive_sponsor ? [
|
||||
'id' => $log->inactive_sponsor->id,
|
||||
'name' => $log->inactive_sponsor->account ? trim($log->inactive_sponsor->account->first_name.' '.$log->inactive_sponsor->account->last_name) : 'N/A',
|
||||
'email' => $log->inactive_sponsor->email,
|
||||
] : null,
|
||||
'new_sponsor' => $log->new_sponsor ? [
|
||||
'id' => $log->new_sponsor->id,
|
||||
'name' => $log->new_sponsor->account ? trim($log->new_sponsor->account->first_name.' '.$log->new_sponsor->account->last_name) : 'N/A',
|
||||
'email' => $log->new_sponsor->email,
|
||||
] : null,
|
||||
'created_at' => \Carbon\Carbon::parse($log->created_at)->format('d.m.Y H:i'),
|
||||
];
|
||||
|
||||
// Prüfe aktuellen Sponsor des child_user (falls geändert)
|
||||
if ($log->child_user && $log->child_user->m_sponsor && $log->child_user->m_sponsor != $log->new_sponsor_id) {
|
||||
$currentSponsor = User::with('account')->find($log->child_user->m_sponsor);
|
||||
if ($currentSponsor) {
|
||||
$data['current_sponsor'] = [
|
||||
'id' => $currentSponsor->id,
|
||||
'name' => $currentSponsor->account ? trim($currentSponsor->account->first_name.' '.$currentSponsor->account->last_name) : 'N/A',
|
||||
'email' => $currentSponsor->email,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
});
|
||||
|
||||
// Kunden-Übertragungen
|
||||
$shoppingLogs = ShoppingUserMemberLog::with(['shopping_user', 'new_member.account'])
|
||||
->where('pre_member_id', $userId)
|
||||
->orderBy('created_at', 'desc')
|
||||
->get()
|
||||
->map(function ($log) {
|
||||
$data = [
|
||||
'customer_name' => $log->shopping_user ? trim($log->shopping_user->billing_firstname.' '.$log->shopping_user->billing_lastname) : 'N/A',
|
||||
'customer_email' => $log->shopping_user ? $log->shopping_user->billing_email : 'N/A',
|
||||
'new_member' => $log->new_member ? [
|
||||
'id' => $log->new_member->id,
|
||||
'name' => $log->new_member->account ? trim($log->new_member->account->first_name.' '.$log->new_member->account->last_name) : 'N/A',
|
||||
'email' => $log->new_member->email,
|
||||
] : null,
|
||||
'created_at' => \Carbon\Carbon::parse($log->created_at)->format('d.m.Y H:i'),
|
||||
];
|
||||
|
||||
// Prüfe aktuellen Berater des Kunden (falls geändert)
|
||||
if ($log->shopping_user && $log->shopping_user->member_id && $log->shopping_user->member_id != $log->new_member_id) {
|
||||
$currentMember = User::with('account')->find($log->shopping_user->member_id);
|
||||
if ($currentMember) {
|
||||
$data['current_member'] = [
|
||||
'id' => $currentMember->id,
|
||||
'name' => $currentMember->account ? trim($currentMember->account->first_name.' '.$currentMember->account->last_name) : 'N/A',
|
||||
'email' => $currentMember->email,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'user' => [
|
||||
'id' => $user->id,
|
||||
'name' => $user->account ? trim($user->account->first_name.' '.$user->account->last_name) : 'N/A',
|
||||
'email' => $user->email,
|
||||
'm_account' => $user->account ? $user->account->m_account : 'N/A',
|
||||
'active' => $user->active,
|
||||
'deleted' => $user->pre_deleted_at ? true : false,
|
||||
'deleted_at' => $user->pre_deleted_at ? \Carbon\Carbon::parse($user->pre_deleted_at)->format('d.m.Y H:i') : null,
|
||||
],
|
||||
'sponsor' => $sponsor ? [
|
||||
'id' => $sponsor->id,
|
||||
'name' => $sponsor->account ? trim($sponsor->account->first_name.' '.$sponsor->account->last_name) : 'N/A',
|
||||
'email' => $sponsor->email,
|
||||
'active' => $sponsor->active,
|
||||
] : null,
|
||||
'pre_sponsor' => $preSponsor ? [
|
||||
'id' => $preSponsor->id,
|
||||
'name' => $preSponsor->account ? trim($preSponsor->account->first_name.' '.$preSponsor->account->last_name) : 'N/A',
|
||||
'email' => $preSponsor->email,
|
||||
'active' => $preSponsor->active,
|
||||
] : null,
|
||||
'children' => $children,
|
||||
'shopping_users' => $shoppingUsers,
|
||||
'cleanup_logs' => $cleanupLogs,
|
||||
'shopping_logs' => $shoppingLogs,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,27 +2,19 @@
|
|||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
|
||||
use App\Services\Shop;
|
||||
use App\Services\Util;
|
||||
use App\Models\UserAbo;
|
||||
use App\Services\MyLog;
|
||||
use App\Services\Payment;
|
||||
use App\Services\AboHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\PaymentTransaction;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\Models\PaymentTransaction;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\MyLog;
|
||||
use App\Services\Payment;
|
||||
use App\Services\ShoppingUserService;
|
||||
|
||||
use App\Services\Util;
|
||||
|
||||
class PayoneController extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
|
||||
public function paymentStatus()
|
||||
{
|
||||
|
||||
|
|
@ -42,14 +34,14 @@ class PayoneController extends Controller
|
|||
|
||||
*/
|
||||
|
||||
if (!isset($data['key']) || !isset($data['param']) || !isset($data['userid']) || !isset($data['txid']) || !isset($data['reference']) || !isset($data['price'])) {
|
||||
if (! isset($data['key']) || ! isset($data['param']) || ! isset($data['userid']) || ! isset($data['txid']) || ! isset($data['reference']) || ! isset($data['price'])) {
|
||||
MyLog::writeLog(
|
||||
'payone',
|
||||
'error',
|
||||
'Error:2001 App\Http\Controllers\Api\PayoneController::paymentStatus parameter incomplete',
|
||||
$data
|
||||
);
|
||||
print("TSOK");
|
||||
echo 'TSOK';
|
||||
exit;
|
||||
}
|
||||
|
||||
|
|
@ -60,31 +52,31 @@ class PayoneController extends Controller
|
|||
'Error:2002 App\Http\Controllers\Api\PayoneController::paymentStatus Key error',
|
||||
$data
|
||||
);
|
||||
print("TSOK");
|
||||
echo 'TSOK';
|
||||
exit;
|
||||
}
|
||||
|
||||
$shopping_order = ShoppingOrder::find($data['param']);
|
||||
if (!$shopping_order) {
|
||||
if (! $shopping_order) {
|
||||
MyLog::writeLog(
|
||||
'payone',
|
||||
'error',
|
||||
'Error:2003 App\Http\Controllers\Api\PayoneController::paymentStatus ShoppingOrder not found:',
|
||||
$data
|
||||
);
|
||||
print("TSOK");
|
||||
echo 'TSOK';
|
||||
exit;
|
||||
}
|
||||
|
||||
$shopping_payment = ShoppingPayment::where('reference', $data['reference'])->first();
|
||||
if (!$shopping_payment) {
|
||||
if (! $shopping_payment) {
|
||||
MyLog::writeLog(
|
||||
'payone',
|
||||
'error',
|
||||
'Error:2004 App\Http\Controllers\Api\PayoneController::paymentStatus ShoppingPayment not found',
|
||||
$data
|
||||
);
|
||||
print("TSOK");
|
||||
echo 'TSOK';
|
||||
exit;
|
||||
}
|
||||
|
||||
|
|
@ -95,11 +87,11 @@ class PayoneController extends Controller
|
|||
'Error:2005 App\Http\Controllers\Api\PayoneController::paymentStatus ShoppingPayment no realation ShoppingOrder',
|
||||
$data
|
||||
);
|
||||
print("TSOK");
|
||||
echo 'TSOK';
|
||||
exit;
|
||||
}
|
||||
|
||||
$price = number_format((round($data['price'], 2) * 100), 0, '.', '');
|
||||
$price = number_format((round($data['price'], 2) * 100), 0, '.', '');
|
||||
$price_amount = number_format($shopping_payment->amount, 0, '.', '');
|
||||
if ($price_amount != $price) {
|
||||
$data['shopping_payment-amount'] = $price_amount;
|
||||
|
|
@ -110,7 +102,7 @@ class PayoneController extends Controller
|
|||
'Error:2006 App\Http\Controllers\Api\PayoneController::paymentStatus Price error',
|
||||
$data
|
||||
);
|
||||
print("TSOK");
|
||||
echo 'TSOK';
|
||||
exit;
|
||||
}
|
||||
|
||||
|
|
@ -125,8 +117,8 @@ class PayoneController extends Controller
|
|||
$data,
|
||||
false
|
||||
);
|
||||
//was already paid
|
||||
print("TSOK");
|
||||
// was already paid
|
||||
echo 'TSOK';
|
||||
exit;
|
||||
} else {
|
||||
MyLog::writeLog(
|
||||
|
|
@ -139,7 +131,7 @@ class PayoneController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
//create transaction
|
||||
// create transaction
|
||||
PaymentTransaction::create([
|
||||
'shopping_payment_id' => $shopping_payment->id,
|
||||
'request' => 'transaction',
|
||||
|
|
@ -152,10 +144,32 @@ class PayoneController extends Controller
|
|||
'mode' => $data['mode'],
|
||||
]);
|
||||
|
||||
$shopping_order->txaction = $data['txaction'];
|
||||
$shopping_order->save();
|
||||
$shopping_payment->txaction = $data['txaction'];
|
||||
$shopping_payment->save();
|
||||
// Define txaction priority (higher number = higher priority)
|
||||
$txaction_priority = [
|
||||
'appointed' => 1,
|
||||
'pending' => 2,
|
||||
'failed' => 3,
|
||||
'paid' => 10, // highest priority - final state
|
||||
];
|
||||
|
||||
$current_priority = isset($txaction_priority[$shopping_order->txaction]) ? $txaction_priority[$shopping_order->txaction] : 0;
|
||||
$new_priority = isset($txaction_priority[$data['txaction']]) ? $txaction_priority[$data['txaction']] : 0;
|
||||
|
||||
// Only update txaction if new priority is higher than current
|
||||
if ($new_priority > $current_priority) {
|
||||
$shopping_order->txaction = $data['txaction'];
|
||||
$shopping_order->save();
|
||||
$shopping_payment->txaction = $data['txaction'];
|
||||
$shopping_payment->save();
|
||||
} else {
|
||||
MyLog::writeLog(
|
||||
'payone',
|
||||
'info',
|
||||
'App\Http\Controllers\Api\PayoneController::paymentStatus - txaction not updated (current: '.$shopping_order->txaction.' has higher/equal priority than new: '.$data['txaction'].')',
|
||||
$data,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
$send_link = false;
|
||||
$send_mail = true;
|
||||
|
|
@ -170,17 +184,38 @@ class PayoneController extends Controller
|
|||
}
|
||||
|
||||
if ($data['txaction'] === 'paid') {
|
||||
if (!$shopping_order->paid) {
|
||||
$send_link = Payment::paymentStatusPaidAction($shopping_order, true, $shopping_payment);
|
||||
} else {
|
||||
$send_mail = false;
|
||||
// Use DB transaction and row locking to prevent race conditions
|
||||
\DB::beginTransaction();
|
||||
try {
|
||||
// Lock the shopping order row to prevent concurrent processing
|
||||
$locked_order = ShoppingOrder::where('id', $shopping_order->id)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
// Double-check if payment was already processed
|
||||
if (! $locked_order->paid) {
|
||||
$send_link = Payment::paymentStatusPaidAction($locked_order, true, $shopping_payment);
|
||||
\DB::commit();
|
||||
} else {
|
||||
$send_mail = false;
|
||||
\DB::commit();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\DB::rollBack();
|
||||
MyLog::writeLog(
|
||||
'payone',
|
||||
'error',
|
||||
'Error:2008 App\Http\Controllers\Api\PayoneController::paymentStatus Transaction failed',
|
||||
['error' => $e->getMessage(), 'data' => $data]
|
||||
);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
$data['send_link'] = $send_link;
|
||||
if ($send_mail) {
|
||||
Payment::paymentStatusSendMail($shopping_order, $shopping_payment, $data);
|
||||
}
|
||||
print("TSOK");
|
||||
echo 'TSOK';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\MailCheckout;
|
||||
use App\Models\Country;
|
||||
use App\Models\Product;
|
||||
|
|
@ -10,28 +11,23 @@ use App\Models\ShoppingOrder;
|
|||
use App\Models\ShoppingOrderItem;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\CustomerPriority;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use PHPUnit\Framework\Constraint\Count;
|
||||
use Yard;
|
||||
|
||||
|
||||
class ShoppingUserController extends Controller
|
||||
{
|
||||
|
||||
//protected static API_MAIL = 'api.thomas.krummel@gmail.com';
|
||||
//protected static API_PASS = 'UF(Q<9knap!ev3vH?5~!b8DP';
|
||||
|
||||
// protected static API_MAIL = 'api.thomas.krummel@gmail.com';
|
||||
// protected static API_PASS = 'UF(Q<9knap!ev3vH?5~!b8DP';
|
||||
|
||||
protected $successStatus = 200;
|
||||
protected $member_id = 3; //service@aloe-vera.bio
|
||||
|
||||
protected $member_id = 3; // service@aloe-vera.bio
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* wp_order_numbers[1234, 1234]
|
||||
* @param Request $request
|
||||
* wp_order_numbers[1234, 1234]
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function status(Request $request)
|
||||
|
|
@ -41,23 +37,23 @@ class ShoppingUserController extends Controller
|
|||
'wp_order_numbers' => 'required',
|
||||
]);
|
||||
|
||||
if(!is_array($request->wp_order_numbers)){
|
||||
if (! is_array($request->wp_order_numbers)) {
|
||||
$wp_order_numbers = json_decode($request->wp_order_numbers);
|
||||
|
||||
}else{
|
||||
$wp_order_numbers = $request->wp_order_numbers;
|
||||
} else {
|
||||
$wp_order_numbers = $request->wp_order_numbers;
|
||||
}
|
||||
|
||||
if(!$wp_order_numbers || !is_array($wp_order_numbers)){
|
||||
if (! $wp_order_numbers || ! is_array($wp_order_numbers)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'wp_order_numbers need as json [1234, 1234] ',
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
|
||||
$status = [];
|
||||
foreach ($wp_order_numbers as $wp_order_number){
|
||||
foreach ($wp_order_numbers as $wp_order_number) {
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $wp_order_number)->first();
|
||||
$status[] = [
|
||||
'wp_order_number' => $wp_order_number,
|
||||
|
|
@ -70,14 +66,14 @@ class ShoppingUserController extends Controller
|
|||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $status,
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* wp_order_number [1234]
|
||||
* @param Request $request
|
||||
* wp_order_number [1234]
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function cancel(Request $request)
|
||||
|
|
@ -86,31 +82,31 @@ class ShoppingUserController extends Controller
|
|||
'wp_order_number' => 'required|int',
|
||||
]);
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->first();
|
||||
if (!$shopping_user) {
|
||||
if (! $shopping_user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' not found',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' not found',
|
||||
'order' => false,
|
||||
'status' => false,
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
if(!$shopping_user->shopping_order){
|
||||
if (! $shopping_user->shopping_order) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' has no order',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' has no order',
|
||||
'order' => false,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
if($shopping_user->shopping_order->shipped > 0){
|
||||
if ($shopping_user->shopping_order->shipped > 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' can not cancel',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' can not cancel',
|
||||
'order' => true,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
|
||||
|
|
@ -119,18 +115,17 @@ class ShoppingUserController extends Controller
|
|||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' is cancel',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' is cancel',
|
||||
'order' => true,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* wp_order_number [1234]
|
||||
* @param Request $request
|
||||
* wp_order_number [1234]
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function open(Request $request)
|
||||
|
|
@ -139,31 +134,31 @@ class ShoppingUserController extends Controller
|
|||
'wp_order_number' => 'required|int',
|
||||
]);
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->first();
|
||||
if (!$shopping_user) {
|
||||
if (! $shopping_user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' not found',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' not found',
|
||||
'order' => false,
|
||||
'status' => false,
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
if(!$shopping_user->shopping_order){
|
||||
if (! $shopping_user->shopping_order) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' has no order',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' has no order',
|
||||
'order' => false,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
if($shopping_user->shopping_order->shipped !== 10){
|
||||
if ($shopping_user->shopping_order->shipped !== 10) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' can not open',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' can not open',
|
||||
'order' => true,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
|
||||
|
|
@ -172,45 +167,44 @@ class ShoppingUserController extends Controller
|
|||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' is open',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' is open',
|
||||
'order' => true,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* wp_order_numbers [1234, 1234]
|
||||
* @param Request $request
|
||||
* wp_order_numbers [1234, 1234]
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(Request $request)
|
||||
{
|
||||
//$this->member_id = auth()->user()->m_sponsor;
|
||||
// $this->member_id = auth()->user()->m_sponsor;
|
||||
$request->validate([
|
||||
'wp_order_numbers' => 'required',
|
||||
]);
|
||||
|
||||
if(!is_array($request->wp_order_numbers)){
|
||||
if (! is_array($request->wp_order_numbers)) {
|
||||
$wp_order_numbers = json_decode($request->wp_order_numbers);
|
||||
|
||||
}else{
|
||||
$wp_order_numbers = $request->wp_order_numbers;
|
||||
} else {
|
||||
$wp_order_numbers = $request->wp_order_numbers;
|
||||
}
|
||||
|
||||
if(!$wp_order_numbers || !is_array($wp_order_numbers)){
|
||||
if (! $wp_order_numbers || ! is_array($wp_order_numbers)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'wp_order_numbers need as json [1234, 1234] ',
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
$data = [];
|
||||
|
||||
foreach ($wp_order_numbers as $wp_order_number){
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $wp_order_number)->first();
|
||||
foreach ($wp_order_numbers as $wp_order_number) {
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $wp_order_number)->first();
|
||||
$user = false;
|
||||
$order = false;
|
||||
if ($shopping_user) {
|
||||
|
|
@ -220,21 +214,21 @@ class ShoppingUserController extends Controller
|
|||
$data[] = [
|
||||
'wp_order_number' => $wp_order_number,
|
||||
'user' => $user,
|
||||
'order' => $order,
|
||||
'order' => $order,
|
||||
'customer_number' => $shopping_user ? $shopping_user->number : false,
|
||||
'member_email' => ($shopping_user && $shopping_user->member) ? $shopping_user->member->email : false,
|
||||
'status' => $shopping_user ? $shopping_user->getAPIShippedType() : false, ];
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $data,
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
|
|
@ -254,7 +248,7 @@ class ShoppingUserController extends Controller
|
|||
$this->member_id = auth()->user()->m_sponsor;
|
||||
|
||||
$data = $this->prepareForStore($request->all());
|
||||
$data['member_id'] = $this->member_id ;
|
||||
$data['member_id'] = $this->member_id;
|
||||
$data['number'] = ShoppingUser::max('number') + 1;
|
||||
$data['mode'] = $request->mode ? $request->mode : 'live';
|
||||
$data['is_from'] = 'extern';
|
||||
|
|
@ -262,11 +256,12 @@ class ShoppingUserController extends Controller
|
|||
|
||||
$shopping_user = ShoppingUser::create($data);
|
||||
|
||||
//Kundenhoheit prüfen
|
||||
// Kundenhoheit prüfen
|
||||
$priority = CustomerPriority::checkOne($shopping_user, true, false, true);
|
||||
\App\Services\Shop::newUserOrder($shopping_user->number);
|
||||
//exists //like //update
|
||||
// exists //like //update
|
||||
$user = $this->prepareForShow($shopping_user);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
|
|
@ -276,13 +271,12 @@ class ShoppingUserController extends Controller
|
|||
'customer_number' => $shopping_user->number,
|
||||
'member_email' => ($shopping_user && $shopping_user->member) ? $shopping_user->member->email : false,
|
||||
],
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(Request $request)
|
||||
|
|
@ -291,40 +285,42 @@ class ShoppingUserController extends Controller
|
|||
'wp_order_number' => 'required|int',
|
||||
]);
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->first();
|
||||
if (!$shopping_user) {
|
||||
if (! $shopping_user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' not found',
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' not found',
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
|
||||
$data = $this->prepareForUpdate($request->all());
|
||||
//Kundenhoheit prüfen
|
||||
// Kundenhoheit prüfen
|
||||
$priority = CustomerPriority::checkChangeOne($shopping_user, $data, true);
|
||||
$updated = $shopping_user->fill($data)->save();
|
||||
\App\Services\Shop::newUserOrder($shopping_user->number);
|
||||
|
||||
if ($updated){
|
||||
if ($updated) {
|
||||
$user = $this->prepareForShow($shopping_user);
|
||||
$order = $this->prepareForShowOrder($shopping_user->shopping_order);
|
||||
return response()->json([
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'wp_order_number' => $shopping_user->wp_order_number,
|
||||
'user' => $user,
|
||||
'order' => $order,
|
||||
'order' => $order,
|
||||
'customer_priority' => $priority,
|
||||
'customer_number' => $shopping_user ? $shopping_user->number : false,
|
||||
'member_email' => ($shopping_user && $shopping_user->member) ? $shopping_user->member->email : false,
|
||||
'status' => $shopping_user ? $shopping_user->getAPIShippedType() : false,
|
||||
],
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry could not be updated'
|
||||
'message' => 'Entry could not be updated',
|
||||
], 500);
|
||||
}
|
||||
|
||||
|
|
@ -335,28 +331,27 @@ class ShoppingUserController extends Controller
|
|||
'wp_order' => 'required',
|
||||
]);
|
||||
|
||||
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->first();
|
||||
if (!$shopping_user) {
|
||||
if (! $shopping_user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' not found',
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' not found',
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
|
||||
if($shopping_user->shopping_order){
|
||||
if ($shopping_user->shopping_order) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Order with wp_order_number ' . $request->wp_order_number . ' exists',
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'message' => 'Order with wp_order_number '.$request->wp_order_number.' exists',
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
if(!is_array($request->wp_order)){
|
||||
if (! is_array($request->wp_order)) {
|
||||
$wp_order = json_decode($request->wp_order);
|
||||
|
||||
}else{
|
||||
$wp_order = $request->wp_order;
|
||||
} else {
|
||||
$wp_order = $request->wp_order;
|
||||
}
|
||||
|
||||
$wp_invoice_path = isset($request->wp_invoice_path) ? $request->wp_invoice_path : null;
|
||||
|
|
@ -370,9 +365,10 @@ class ShoppingUserController extends Controller
|
|||
|
||||
$wp_order = $this->prepareOrder($wp_order, $shopping_user, $wp_invoice_path, $api_notice);
|
||||
|
||||
if ($wp_order){
|
||||
if ($wp_order) {
|
||||
$user = $this->prepareForShow($shopping_user);
|
||||
$order = $this->prepareForShowOrder($shopping_user->shopping_order);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
|
|
@ -387,166 +383,175 @@ class ShoppingUserController extends Controller
|
|||
'member_email' => ($shopping_user && $shopping_user->member) ? $shopping_user->member->email : false,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
],
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Order could not be stored'
|
||||
'message' => 'Order could not be stored',
|
||||
], 500);
|
||||
}
|
||||
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'wp_order_number' => 'required|int',
|
||||
]);
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->where('mode', '=', 'dev')->first();
|
||||
if (!$shopping_user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' not found or mode != dev',
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
], 400);
|
||||
}
|
||||
$shopping_order = $shopping_user->shopping_order;
|
||||
if($shopping_order){
|
||||
foreach ($shopping_order->shopping_order_items as $shopping_order_item){
|
||||
$shopping_order_item->delete();
|
||||
}
|
||||
$shopping_order->delete();
|
||||
}
|
||||
$shopping_user->wp_order_number = time();
|
||||
$shopping_user->save();
|
||||
if ($shopping_user->delete()) {
|
||||
return response()->json([
|
||||
'success' => true
|
||||
]);
|
||||
}
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry could not be deleted'
|
||||
], 500);
|
||||
}
|
||||
{
|
||||
$request->validate([
|
||||
'wp_order_number' => 'required|int',
|
||||
]);
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->where('mode', '=', 'dev')->first();
|
||||
if (! $shopping_user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' not found or mode != dev',
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
$shopping_order = $shopping_user->shopping_order;
|
||||
if ($shopping_order) {
|
||||
foreach ($shopping_order->shopping_order_items as $shopping_order_item) {
|
||||
$shopping_order_item->delete();
|
||||
}
|
||||
$shopping_order->delete();
|
||||
}
|
||||
$shopping_user->wp_order_number = time();
|
||||
$shopping_user->save();
|
||||
if ($shopping_user->delete()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
private function prepareForShow($shopping_user){
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry could not be deleted',
|
||||
], 500);
|
||||
}
|
||||
|
||||
if(!$shopping_user){
|
||||
private function prepareForShow($shopping_user)
|
||||
{
|
||||
|
||||
if (! $shopping_user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$shopping_user_data = $shopping_user->toArray();
|
||||
$needs = ['wp_order_number', 'wp_order_date', 'billing_company', 'billing_firstname', 'billing_lastname', 'billing_address', 'billing_address_2', 'billing_zipcode', 'billing_city', 'billing_phone', 'billing_email',
|
||||
'same_as_billing', 'shipping_company', 'shipping_firstname', 'shipping_lastname', 'shipping_address', 'shipping_address_2', 'shipping_zipcode', 'shipping_city', 'shipping_phone',
|
||||
'created_at', 'updated_at', 'user_deleted_at']; //'has_buyed', 'subscribed',
|
||||
'created_at', 'updated_at', 'user_deleted_at']; // 'has_buyed', 'subscribed',
|
||||
|
||||
//$salutation = array('mr' => 1, 'ms' => 2);
|
||||
// $salutation = array('mr' => 1, 'ms' => 2);
|
||||
$ret = [];
|
||||
foreach ($shopping_user_data as $key=>$value){
|
||||
foreach ($shopping_user_data as $key => $value) {
|
||||
|
||||
if($key === 'billing_country_id'){
|
||||
if ($key === 'billing_country_id') {
|
||||
$ret['billing_country_code'] = $shopping_user->billing_country_id ? $shopping_user->billing_country->code : null;
|
||||
}
|
||||
if($key === 'shipping_country_id'){
|
||||
if ($key === 'shipping_country_id') {
|
||||
$ret['shipping_country_code'] = $shopping_user->shipping_country_id ? $shopping_user->shipping_country->code : null;
|
||||
}
|
||||
if($key === 'billing_salutation'){
|
||||
if ($key === 'billing_salutation') {
|
||||
$ret['billing_salutation'] = $shopping_user->billing_salutation === 'ms' ? 2 : 1;
|
||||
}
|
||||
if($key === 'shipping_salutation'){
|
||||
if ($key === 'shipping_salutation') {
|
||||
$ret['shipping_salutation'] = $shopping_user->shipping_salutation === 'ms' ? 2 : 1;
|
||||
}
|
||||
|
||||
if(in_array($key, $needs)){
|
||||
if (in_array($key, $needs)) {
|
||||
$ret[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function prepareForShowOrder($shopping_order){
|
||||
private function prepareForShowOrder($shopping_order)
|
||||
{
|
||||
|
||||
if(!$shopping_order){
|
||||
if (! $shopping_order) {
|
||||
return false;
|
||||
}
|
||||
$ret = [
|
||||
'country' => isset($shopping_order->shipping_country->country->code) ? $shopping_order->shipping_country->country->code : '',
|
||||
'wp_invoice_path' => $shopping_order->wp_invoice_path,
|
||||
'total' => ($shopping_order->total*100),
|
||||
'shipping' => ($shopping_order->shipping*100),
|
||||
'total_net' => ($shopping_order->subtotal*100),
|
||||
'tax_rate' => ($shopping_order->tax_rate*100),
|
||||
'tax' => ($shopping_order->tax*100),
|
||||
'total_with_shipping' => ($shopping_order->total_shipping*100),
|
||||
'total' => ($shopping_order->total * 100),
|
||||
'shipping' => ($shopping_order->shipping * 100),
|
||||
'total_net' => ($shopping_order->subtotal * 100),
|
||||
'tax_rate' => ($shopping_order->tax_rate * 100),
|
||||
'tax' => ($shopping_order->tax * 100),
|
||||
'total_with_shipping' => ($shopping_order->total_shipping * 100),
|
||||
'weight' => $shopping_order->weight,
|
||||
];
|
||||
$ret['items'] = [];
|
||||
foreach ($shopping_order->shopping_order_items as $item){
|
||||
foreach ($shopping_order->shopping_order_items as $item) {
|
||||
$ret['items'][] = [
|
||||
'article' => $item->product->wp_number,
|
||||
'name' => $item->product->getLang('name'),
|
||||
'qty' => $item->qty,
|
||||
'price' => ($item->price * 100),
|
||||
'article' => $item->product->wp_number,
|
||||
'name' => $item->product->getLang('name'),
|
||||
'qty' => $item->qty,
|
||||
'price' => ($item->price * 100),
|
||||
];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function prepareForUpdate($data){
|
||||
private function prepareForUpdate($data)
|
||||
{
|
||||
|
||||
//$salutation = array(1 => 'mr', 2 => 'ms', 3=>null);
|
||||
// $salutation = array(1 => 'mr', 2 => 'ms', 3=>null);
|
||||
|
||||
if(isset($data['billing_salutation'])){
|
||||
$data['billing_salutation'] = (int) $data['billing_salutation'];
|
||||
if (isset($data['billing_salutation'])) {
|
||||
$data['billing_salutation'] = (int) $data['billing_salutation'];
|
||||
$data['billing_salutation'] = $data['billing_salutation'] == 2 ? 'ms' : 'mr';
|
||||
}
|
||||
if(isset($data['shipping_salutation'])){
|
||||
$data['shipping_salutation'] = (int) $data['shipping_salutation'];
|
||||
$data['shipping_salutation'] = $data['shipping_salutation'] == 2 ? 'ms' : 'mr';
|
||||
if (isset($data['shipping_salutation'])) {
|
||||
$data['shipping_salutation'] = (int) $data['shipping_salutation'];
|
||||
$data['shipping_salutation'] = $data['shipping_salutation'] == 2 ? 'ms' : 'mr';
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
$needs = [ 'billing_salutation', 'billing_company', 'billing_firstname', 'billing_lastname', 'billing_address', 'billing_address_2', 'billing_zipcode', 'billing_city', 'billing_phone', 'billing_email', 'same_as_billing',
|
||||
$needs = ['billing_salutation', 'billing_company', 'billing_firstname', 'billing_lastname', 'billing_address', 'billing_address_2', 'billing_zipcode', 'billing_city', 'billing_phone', 'billing_email', 'same_as_billing',
|
||||
'shipping_salutation', 'shipping_company', 'shipping_firstname', 'shipping_lastname', 'shipping_address', 'shipping_address_2', 'shipping_zipcode', 'shipping_city', 'shipping_phone'];
|
||||
|
||||
foreach ($data as $key=>$value){
|
||||
if($key === 'billing_country_code' && isset($data['billing_country_code'])) {
|
||||
$ret['billing_country_id'] = Country::getCountryIdByCodeOrOne($data['billing_country_code']);
|
||||
foreach ($data as $key => $value) {
|
||||
if ($key === 'billing_country_code' && isset($data['billing_country_code'])) {
|
||||
$ret['billing_country_id'] = Country::getCountryIdByCodeOrOne($data['billing_country_code']);
|
||||
}
|
||||
if($key === 'shipping_country_code' && isset($data['shipping_country_code']) ) {
|
||||
if ($key === 'shipping_country_code' && isset($data['shipping_country_code'])) {
|
||||
$ret['shipping_country_id'] = Country::getCountryIdByCodeOrOne($data['shipping_country_code']);
|
||||
}
|
||||
if($key === 'billing_phone') {
|
||||
if ($key === 'billing_phone') {
|
||||
$ret['billing_phone'] = strlen($data['billing_phone']) <= 3 ? '' : $data['billing_phone'];
|
||||
}
|
||||
if($key === 'shipping_phone') {
|
||||
if ($key === 'shipping_phone') {
|
||||
$ret['shipping_phone'] = strlen($data['shipping_phone']) <= 3 ? '' : $data['shipping_phone'];
|
||||
}
|
||||
if(in_array($key, $needs)){
|
||||
if (in_array($key, $needs)) {
|
||||
$ret[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function prepareForStore($data){
|
||||
private function prepareForStore($data)
|
||||
{
|
||||
|
||||
//$salutation = array(1 => 'mr', 2 => 'ms', 3=>null);
|
||||
if(isset($data['billing_salutation'])){
|
||||
$data['billing_salutation'] = (int) $data['billing_salutation'];
|
||||
// $salutation = array(1 => 'mr', 2 => 'ms', 3=>null);
|
||||
if (isset($data['billing_salutation'])) {
|
||||
$data['billing_salutation'] = (int) $data['billing_salutation'];
|
||||
$data['billing_salutation'] = $data['billing_salutation'] == 2 ? 'ms' : 'mr';
|
||||
}
|
||||
if(isset($data['shipping_salutation'])){
|
||||
$data['shipping_salutation'] = (int) $data['shipping_salutation'];
|
||||
$data['shipping_salutation'] = $data['shipping_salutation'] == 2 ? 'ms' : 'mr';
|
||||
if (isset($data['shipping_salutation'])) {
|
||||
$data['shipping_salutation'] = (int) $data['shipping_salutation'];
|
||||
$data['shipping_salutation'] = $data['shipping_salutation'] == 2 ? 'ms' : 'mr';
|
||||
}
|
||||
$ret = [];
|
||||
$needs = [ 'billing_salutation', 'billing_company', 'billing_firstname', 'billing_lastname', 'billing_address', 'billing_address_2', 'billing_zipcode', 'billing_city', 'billing_country_id', 'billing_phone', 'billing_email',
|
||||
$needs = ['billing_salutation', 'billing_company', 'billing_firstname', 'billing_lastname', 'billing_address', 'billing_address_2', 'billing_zipcode', 'billing_city', 'billing_country_id', 'billing_phone', 'billing_email',
|
||||
'shipping_salutation', 'shipping_company', 'shipping_firstname', 'shipping_lastname', 'shipping_address', 'shipping_address_2', 'shipping_zipcode', 'shipping_city', 'shipping_country_id', 'shipping_phone',
|
||||
'same_as_billing', //'has_buyed', 'subscribed',
|
||||
'same_as_billing', // 'has_buyed', 'subscribed',
|
||||
'wp_order_number', 'wp_order_date'];
|
||||
|
||||
foreach ($needs as $need){
|
||||
foreach ($needs as $need) {
|
||||
|
||||
$ret[$need] = isset($data[$need]) ? $data[$need] : null;
|
||||
if ($need === 'billing_country_id') {
|
||||
|
|
@ -565,35 +570,37 @@ class ShoppingUserController extends Controller
|
|||
$ret['wp_order_date'] = Carbon::parse($ret['wp_order_date'])->toDateTimeString();
|
||||
}
|
||||
if ($need === 'same_as_billing') {
|
||||
$ret['same_as_billing'] = isset($data['same_as_billing']) ? $data['same_as_billing'] : true;
|
||||
$ret['same_as_billing'] = isset($data['same_as_billing']) ? $data['same_as_billing'] : true;
|
||||
}
|
||||
}
|
||||
$ret['has_buyed'] = true;
|
||||
$ret['subscribed'] = false;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function prepareOrder($wp_shopping_order, $shopping_user, $wp_invoice_path, $api_notice){
|
||||
private function prepareOrder($wp_shopping_order, $shopping_user, $wp_invoice_path, $api_notice)
|
||||
{
|
||||
Yard::instance('shopping')->destroy();
|
||||
$ret = [];
|
||||
|
||||
if(is_array($wp_shopping_order)){
|
||||
if (is_array($wp_shopping_order)) {
|
||||
foreach ($wp_shopping_order as $order) {
|
||||
//$object = json_decode(json_encode($order), FALSE);
|
||||
// $object = json_decode(json_encode($order), FALSE);
|
||||
$order = (object) $order;
|
||||
$error = [];
|
||||
if (!isset($order->article) || !isset($order->qty) || !isset($order->price)) {
|
||||
$error[] = "article parameter is missing";
|
||||
if (! isset($order->article) || ! isset($order->qty) || ! isset($order->price)) {
|
||||
$error[] = 'article parameter is missing';
|
||||
} else {
|
||||
|
||||
$product = Product::whereWpNumber($order->article)->first();
|
||||
if (!$product) {
|
||||
$error[] = "article not found";
|
||||
if (! $product) {
|
||||
$error[] = 'article not found';
|
||||
} else {
|
||||
if ($order->price != ($product->price * 100)) {
|
||||
$error[] = "different price: " . ($product->price * 100);
|
||||
$error[] = 'different price: '.($product->price * 100);
|
||||
}
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), (int) $order->qty, $product->price, false, false, ['image' => [], 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), (int) $order->qty, $product->price, false, false, ['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]);
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith());
|
||||
}
|
||||
}
|
||||
|
|
@ -602,7 +609,7 @@ class ShoppingUserController extends Controller
|
|||
}
|
||||
|
||||
$ShippingCountry = ShippingCountry::whereCountryId($shopping_user->shipping_country_id)->first();
|
||||
if($ShippingCountry){
|
||||
if ($ShippingCountry) {
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($ShippingCountry->id);
|
||||
}
|
||||
$shopping_order = $this->makeShoppingOrder($shopping_user, $wp_invoice_path, $api_notice);
|
||||
|
|
@ -611,11 +618,13 @@ class ShoppingUserController extends Controller
|
|||
$shopping_user->shopping_order = $shopping_order;
|
||||
Yard::instance('shopping')->destroy();
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function makeShoppingOrder($shopping_user, $wp_invoice_path, $api_notice){
|
||||
|
||||
private function makeShoppingOrder($shopping_user, $wp_invoice_path, $api_notice)
|
||||
{
|
||||
|
||||
$data = [
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
'auth_user_id' => $shopping_user->auth_user_id,
|
||||
|
|
@ -641,23 +650,22 @@ class ShoppingUserController extends Controller
|
|||
'mode' => $shopping_user->mode,
|
||||
];
|
||||
$shopping_order = $shopping_user->shopping_order;
|
||||
if($shopping_order){
|
||||
if ($shopping_order) {
|
||||
$shopping_order->fill($data);
|
||||
$shopping_order->save();
|
||||
}else{
|
||||
$shopping_order= ShoppingOrder::create($data);
|
||||
} else {
|
||||
$shopping_order = ShoppingOrder::create($data);
|
||||
}
|
||||
$items = Yard::instance('shopping')->content();
|
||||
|
||||
|
||||
$shopping_order->shopping_order_items()->each(function($model) use ($items, $shopping_order) {
|
||||
$shopping_order->shopping_order_items()->each(function ($model) use ($items, $shopping_order) {
|
||||
foreach ($items as $item) {
|
||||
$price_net = Yard::instance('shopping')->rowPriceNet($item, 2, '.', '');
|
||||
$tax = $item->price - $price_net;
|
||||
if ($model->row_id === $item->rowId) {
|
||||
$model->fill([
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'row_id' => $item->rowId,
|
||||
'row_id' => $item->rowId,
|
||||
'product_id' => $item->id,
|
||||
'qty' => $item->qty,
|
||||
'price' => $item->price,
|
||||
|
|
@ -669,20 +677,21 @@ class ShoppingUserController extends Controller
|
|||
'points' => $item->options->points,
|
||||
'slug' => $item->options->slug,
|
||||
])->save();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $model->delete();
|
||||
});
|
||||
|
||||
|
||||
foreach ($items as $item) {
|
||||
if (!ShoppingOrderItem::where('shopping_order_id', $shopping_order->id)->where('row_id', $item->rowId)->count()){
|
||||
if (! ShoppingOrderItem::where('shopping_order_id', $shopping_order->id)->where('row_id', $item->rowId)->count()) {
|
||||
$price_net = Yard::instance('shopping')->rowPriceNet($item, 2, '.', '');
|
||||
$tax = $item->price - $price_net;
|
||||
ShoppingOrderItem::create([
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'row_id' => $item->rowId,
|
||||
'row_id' => $item->rowId,
|
||||
'product_id' => $item->id,
|
||||
'qty' => $item->qty,
|
||||
'price' => $item->price,
|
||||
|
|
@ -692,27 +701,27 @@ class ShoppingUserController extends Controller
|
|||
'price_vk_net' => $shopping_order->getPriceVkNetBy($item->id),
|
||||
'discount' => $item->options->no_commission ? 0 : $shopping_order->getUserDiscount(),
|
||||
'points' => $item->options->points,
|
||||
'slug' => $item->options->slug
|
||||
'slug' => $item->options->slug,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$shopping_order->makeTaxSplit();
|
||||
|
||||
return $shopping_order;
|
||||
}
|
||||
|
||||
|
||||
public function orderStatusSendMail(ShoppingOrder $shopping_order){
|
||||
public function orderStatusSendMail(ShoppingOrder $shopping_order)
|
||||
{
|
||||
|
||||
$bcc = [];
|
||||
$user_mail = $shopping_order->shopping_user->member->email;
|
||||
if($shopping_order->mode === 'dev'){
|
||||
if ($shopping_order->mode === 'dev') {
|
||||
$bcc[] = config('app.checkout_test_mail');
|
||||
}else{
|
||||
} else {
|
||||
$bcc[] = config('app.checkout_mail');
|
||||
}
|
||||
|
||||
Mail::to($user_mail)->bcc($bcc)->locale($shopping_order->getLocale())->send(new MailCheckout($shopping_order->txaction, $shopping_order, null, false, $shopping_order->mode));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,14 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Carbon;
|
||||
use Request;
|
||||
use App\Services\Payment;
|
||||
use App\Models\UserInvoice;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Services\BusinessPlan\SalesPointsVolume;
|
||||
use App\Services\HTMLHelper;
|
||||
use Request;
|
||||
|
||||
class BusinessPointsController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
|
|
@ -26,7 +21,6 @@ class BusinessPointsController extends Controller
|
|||
->groupBy('user_id')->join('user_accounts', 'account_id', '=', 'user_accounts.id')
|
||||
->select('users.id', 'users.email', 'user_accounts.first_name', 'user_accounts.last_name')->get();
|
||||
|
||||
|
||||
$this->setFilterVars();
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
|
|
@ -34,37 +28,40 @@ class BusinessPointsController extends Controller
|
|||
'filter_members' => $filter_members,
|
||||
'filter_status_types' => UserSalesVolume::getTransStatusType(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
return view('admin.business.points', $data);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$data = Request::all();
|
||||
if (!isset($data['action'])) {
|
||||
if (! isset($data['action'])) {
|
||||
return back();
|
||||
}
|
||||
if (!isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) {
|
||||
if (! isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) {
|
||||
\Session()->flash('alert-error', 'Das Passwort ist falsch.');
|
||||
|
||||
return back();
|
||||
}
|
||||
if (!isset($data['is_checked_action'])) {
|
||||
if (! isset($data['is_checked_action'])) {
|
||||
\Session()->flash('alert-error', 'Änderung nicht bestätigt');
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
if ($data['action'] === 'add_user_sales_volume') {
|
||||
SalesPointsVolume::addSalesPointsVolume($data);
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
if ($data['action'] === 'edit_user_sales_volume') {
|
||||
SalesPointsVolume::editSalesPointsVolume($data);
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
|
||||
return redirect(route('admin_business_points'));
|
||||
}
|
||||
|
||||
|
|
@ -74,34 +71,35 @@ class BusinessPointsController extends Controller
|
|||
$month = Request::get('points_filter_month');
|
||||
$year = Request::get('points_filter_year');
|
||||
|
||||
if (!$user_id) {
|
||||
if (! $user_id) {
|
||||
\Session()->flash('alert-error', 'Kein Berater ausgewählt.');
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
if (!$month || !$year) {
|
||||
if (! $month || ! $year) {
|
||||
\Session()->flash('alert-error', 'Monat und Jahr müssen angegeben sein.');
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
try {
|
||||
SalesPointsVolume::reCalculateSalesPointsVolume($user_id, $month, $year);
|
||||
\Session()->flash('alert-success', 'Punkte für den ausgewählten Berater im Monat ' . str_pad($month, 2, "0", STR_PAD_LEFT) . '/' . $year . ' wurden erfolgreich neu berechnet.');
|
||||
\Session()->flash('alert-success', 'Punkte für den ausgewählten Berater im Monat '.str_pad($month, 2, '0', STR_PAD_LEFT).'/'.$year.' wurden erfolgreich neu berechnet.');
|
||||
} catch (\Exception $e) {
|
||||
\Session()->flash('alert-error', 'Fehler bei der Neuberechnung: ' . $e->getMessage());
|
||||
\Session()->flash('alert-error', 'Fehler bei der Neuberechnung: '.$e->getMessage());
|
||||
}
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
|
||||
private function setFilterVars()
|
||||
{
|
||||
|
||||
if (!session('points_filter_month')) {
|
||||
if (! session('points_filter_month')) {
|
||||
session(['points_filter_month' => intval(date('m'))]);
|
||||
}
|
||||
if (!session('points_filter_year')) {
|
||||
if (! session('points_filter_year')) {
|
||||
session(['points_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +118,7 @@ class BusinessPointsController extends Controller
|
|||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
//$query = UserSalesVolume::with('user', 'user.account')->with('shopping_order')->select('user_sales_volumes.*')
|
||||
// $query = UserSalesVolume::with('user', 'user.account')->with('shopping_order')->select('user_sales_volumes.*')
|
||||
$query = UserSalesVolume::join('users', 'user_id', '=', 'users.id')->join('user_accounts', 'account_id', '=', 'user_accounts.id')
|
||||
->select('user_sales_volumes.*', 'users.email', 'user_accounts.m_account', 'user_accounts.first_name', 'user_accounts.last_name')
|
||||
->where('user_sales_volumes.month', '=', Request::get('points_filter_month'))
|
||||
|
|
@ -132,6 +130,7 @@ class BusinessPointsController extends Controller
|
|||
if (Request::get('points_filter_status_type_id')) {
|
||||
$query->where('user_sales_volumes.status', '=', Request::get('points_filter_status_type_id'));
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
|
@ -141,10 +140,10 @@ class BusinessPointsController extends Controller
|
|||
$month = Request::get('points_filter_month');
|
||||
$year = Request::get('points_filter_year');
|
||||
|
||||
if (!$user_id || !$month || !$year) {
|
||||
if (! $user_id || ! $month || ! $year) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'data' => null
|
||||
'data' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -155,10 +154,10 @@ class BusinessPointsController extends Controller
|
|||
->orderBy('id', 'DESC')
|
||||
->first();
|
||||
|
||||
if (!$lastEntry) {
|
||||
if (! $lastEntry) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'data' => null
|
||||
'data' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +172,7 @@ class BusinessPointsController extends Controller
|
|||
'total_KP_points' => ($lastEntry->month_KP_points ?? 0) + ($lastEntry->month_shop_points ?? 0),
|
||||
'total_TP_points' => ($lastEntry->month_TP_points ?? 0) + ($lastEntry->month_shop_points ?? 0),
|
||||
'total_net' => ($lastEntry->month_total_net ?? 0) + ($lastEntry->month_shop_total_net ?? 0),
|
||||
]
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -181,67 +180,80 @@ class BusinessPointsController extends Controller
|
|||
{
|
||||
|
||||
$query = $this->initSearch();
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<button type="button" class="btn btn-xs btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="' . $UserSalesVolume->id . '"
|
||||
data-id="'.$UserSalesVolume->id.'"
|
||||
data-action="edit_user_sales_volume"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="user"
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-eye"></span></button>';
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-eye"></span></button>';
|
||||
})
|
||||
->addColumn('order', function (UserSalesVolume $UserSalesVolume) {
|
||||
if ($UserSalesVolume->shopping_order) {
|
||||
// Status 1 = Beraterbestellung
|
||||
if ($UserSalesVolume->status === 1) {
|
||||
return '<a href="' . route('admin_sales_users_detail', [$UserSalesVolume->shopping_order->id]) . '" class="btn btn-xs btn-primary">' . $UserSalesVolume->shopping_order->id . '</a>';
|
||||
return '<a href="'.route('admin_sales_users_detail', [$UserSalesVolume->shopping_order->id]).'" class="btn btn-xs btn-primary">'.$UserSalesVolume->shopping_order->id.'</a>';
|
||||
}
|
||||
// Status 2/3 = Shop-Bestellung
|
||||
if ($UserSalesVolume->status === 2 || $UserSalesVolume->status === 3) {
|
||||
return '<a href="' . route('admin_sales_customers_detail', [$UserSalesVolume->shopping_order->id]) . '" class="btn btn-xs btn-secondary">' . $UserSalesVolume->shopping_order->id . '</a>';
|
||||
return '<a href="'.route('admin_sales_customers_detail', [$UserSalesVolume->shopping_order->id]).'" class="btn btn-xs btn-secondary">'.$UserSalesVolume->shopping_order->id.'</a>';
|
||||
}
|
||||
// Status 6 = Storno - Link zur ursprünglichen Bestellung mit Storno-Icon
|
||||
if ($UserSalesVolume->status === 6) {
|
||||
// Prüfen ob Berater- oder Shop-Bestellung anhand des payment_for Feldes
|
||||
$route = ($UserSalesVolume->shopping_order->payment_for === 6 || $UserSalesVolume->shopping_order->payment_for === 7)
|
||||
? route('admin_sales_customers_detail', [$UserSalesVolume->shopping_order->id])
|
||||
: route('admin_sales_users_detail', [$UserSalesVolume->shopping_order->id]);
|
||||
|
||||
return '<a href="'.$route.'" class="btn btn-xs btn-danger" title="Storno-Eintrag"><i class="fa fa-undo"></i> '.$UserSalesVolume->shopping_order->id.'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
})
|
||||
->addColumn('points', function (UserSalesVolume $UserSalesVolume) {
|
||||
return formatNumber($UserSalesVolume->points);
|
||||
})
|
||||
->addColumn('total_net', function (UserSalesVolume $UserSalesVolume) {
|
||||
return formatNumber($UserSalesVolume->total_net) . ' €';
|
||||
return formatNumber($UserSalesVolume->total_net).' €';
|
||||
})
|
||||
->addColumn('status_turnover', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<span class="badge badge-pill badge-' . $UserSalesVolume->getStatusTurnoverColor() . '">' . $UserSalesVolume->getStatusTurnoverType() . '</span>';
|
||||
return '<span class="badge badge-pill badge-'.$UserSalesVolume->getStatusTurnoverColor().'">'.$UserSalesVolume->getStatusTurnoverType().'</span>';
|
||||
})
|
||||
->addColumn('status', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<span class="badge badge-pill badge-' . $UserSalesVolume->getStatusColor() . '">' . $UserSalesVolume->getStatusType() . '</span>';
|
||||
return '<span class="badge badge-pill badge-'.$UserSalesVolume->getStatusColor().'">'.$UserSalesVolume->getStatusType().'</span>';
|
||||
})
|
||||
->addColumn('status_points', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<span class="badge badge-pill badge-' . $UserSalesVolume->getStatusPointsColor() . '">' . $UserSalesVolume->getStatusPointsType() . '</span>';
|
||||
return '<span class="badge badge-pill badge-'.$UserSalesVolume->getStatusPointsColor().'">'.$UserSalesVolume->getStatusPointsType().'</span>';
|
||||
})
|
||||
->addColumn('message', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<span class="no-line-break">' . $UserSalesVolume->message . '</span>';
|
||||
return '<span class="no-line-break">'.$UserSalesVolume->message.'</span>';
|
||||
})
|
||||
->addColumn('info', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<span class="no-line-break">' . $UserSalesVolume->info . '</span>';
|
||||
return '<span class="no-line-break">'.$UserSalesVolume->info.'</span>';
|
||||
})
|
||||
|
||||
->filterColumn('m_account', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("m_account LIKE ?", '%' . $keyword . '%');
|
||||
if ($keyword != '') {
|
||||
$query->whereRaw('m_account LIKE ?', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->filterColumn('first_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("first_name LIKE ?", '%' . $keyword . '%');
|
||||
if ($keyword != '') {
|
||||
$query->whereRaw('first_name LIKE ?', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->filterColumn('last_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("last_name LIKE ?", '%' . $keyword . '%');
|
||||
if ($keyword != '') {
|
||||
$query->whereRaw('last_name LIKE ?', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->filterColumn('email', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("email LIKE ?", '%' . $keyword . '%');
|
||||
if ($keyword != '') {
|
||||
$query->whereRaw('email LIKE ?', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ class DhlShipmentController extends Controller
|
|||
// Get DHL configuration with admin settings
|
||||
$settingController = new \App\Http\Controllers\SettingController;
|
||||
$dhlConfig = $settingController->getDhlConfig();
|
||||
|
||||
// Create DhlClient with merged configuration
|
||||
$dhlClient = new \Acme\Dhl\Support\DhlClient(
|
||||
$dhlConfig['base_url'],
|
||||
|
|
@ -67,7 +66,7 @@ class DhlShipmentController extends Controller
|
|||
if ($connectionTest) {
|
||||
$result = [
|
||||
'success' => true,
|
||||
'message' => 'DHL API Verbindung erfolgreich getestet!',
|
||||
'message' => 'DHL API Verbindung erfolgreich getestet! '.config('dhl.config_source').' '.$dhlConfig['base_url'],
|
||||
'details' => [
|
||||
'base_url' => $dhlConfig['base_url'],
|
||||
'using_admin_config' => ! empty($dhlConfig['api_key']),
|
||||
|
|
@ -88,7 +87,7 @@ class DhlShipmentController extends Controller
|
|||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'DHL API Test fehlgeschlagen: ' . $e->getMessage(),
|
||||
'message' => 'DHL API Test fehlgeschlagen: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
|
@ -148,12 +147,13 @@ class DhlShipmentController extends Controller
|
|||
|
||||
return DataTables::eloquent($query)
|
||||
->addColumn('checkbox', function ($shipment) {
|
||||
return '<label class="custom-control custom-checkbox mb-0"><input type="checkbox" class="custom-control-input shipment-checkbox" value="' . $shipment->id . '"><span class="custom-control-label"></span></label>';
|
||||
return '<label class="custom-control custom-checkbox mb-0"><input type="checkbox" class="custom-control-input shipment-checkbox" value="'.$shipment->id.'"><span class="custom-control-label"></span></label>';
|
||||
})
|
||||
->editColumn('id', function ($shipment) {
|
||||
$class = $shipment->type === 'return' ? 'text-warning font-weight-bold' : 'text-primary font-weight-semibold';
|
||||
$icon = $shipment->type === 'return' ? '<i class="fas fa-undo mr-1"></i>' : '';
|
||||
return '<a href="' . route('admin.dhl.show', $shipment) . '" class="' . $class . '">' . $icon . '#' . $shipment->id . '</a>';
|
||||
|
||||
return '<a href="'.route('admin.dhl.show', $shipment).'" class="'.$class.'">'.$icon.'#'.$shipment->id.'</a>';
|
||||
})
|
||||
->addColumn('type', function ($shipment) {
|
||||
if ($shipment->type == 'outbound') {
|
||||
|
|
@ -164,16 +164,16 @@ class DhlShipmentController extends Controller
|
|||
})
|
||||
->addColumn('order', function ($shipment) {
|
||||
if ($shipment->order_id) {
|
||||
return '<a href="' . route('admin_sales_customers_detail', $shipment->order_id) . '" class="text-primary">#' . $shipment->order_id . '</a>';
|
||||
return '<a href="'.route('admin_sales_customers_detail', $shipment->order_id).'" class="text-primary">#'.$shipment->order_id.'</a>';
|
||||
}
|
||||
|
||||
return '<span class="text-muted">N/A</span>';
|
||||
})
|
||||
->addColumn('customer', function ($shipment) {
|
||||
return $shipment->firstname . ' ' . $shipment->lastname;
|
||||
return $shipment->firstname.' '.$shipment->lastname;
|
||||
})
|
||||
->editColumn('dhl_shipment_no', function ($shipment) {
|
||||
return $shipment->dhl_shipment_no ? '<code class="text-success">' . e($shipment->dhl_shipment_no) . '</code>' : '<span class="text-muted">-</span>';
|
||||
return $shipment->dhl_shipment_no ? '<code class="text-success">'.e($shipment->dhl_shipment_no).'</code>' : '<span class="text-muted">-</span>';
|
||||
})
|
||||
->addColumn('status', function ($shipment) {
|
||||
$statusMap = [
|
||||
|
|
@ -186,43 +186,43 @@ class DhlShipmentController extends Controller
|
|||
];
|
||||
$statusInfo = $statusMap[$shipment->status] ?? ['class' => 'light', 'text' => e($shipment->status)];
|
||||
|
||||
return '<span class="badge badge-' . $statusInfo['class'] . '">' . $statusInfo['text'] . '</span>';
|
||||
return '<span class="badge badge-'.$statusInfo['class'].'">'.$statusInfo['text'].'</span>';
|
||||
})
|
||||
->addColumn('tracking_status', function ($shipment) {
|
||||
if ($shipment->tracking_status) {
|
||||
return '<small class="text-muted">' . e($shipment->tracking_status) . '</small>' .
|
||||
($shipment->last_tracked_at ? '<br><small class="text-muted">' . $shipment->last_tracked_at->format('d.m.Y H:i') . '</small>' : '');
|
||||
return '<small class="text-muted">'.e($shipment->tracking_status).'</small>'.
|
||||
($shipment->last_tracked_at ? '<br><small class="text-muted">'.$shipment->last_tracked_at->format('d.m.Y H:i').'</small>' : '');
|
||||
}
|
||||
|
||||
return '<span class="text-muted">-</span>';
|
||||
})
|
||||
->editColumn('weight_kg', function ($shipment) {
|
||||
return number_format($shipment->weight_kg, 2) . ' kg';
|
||||
return number_format($shipment->weight_kg, 2).' kg';
|
||||
})
|
||||
->editColumn('created_at', function ($shipment) {
|
||||
return $shipment->created_at->format('d.m.Y H:i');
|
||||
})
|
||||
->addColumn('actions', function ($shipment) {
|
||||
$buttons = '<div class="btn-group" role="group">';
|
||||
$buttons .= '<a href="' . route('admin.dhl.show', $shipment) . '" class="btn btn-sm btn-outline-primary" data-toggle="tooltip" title="Details anzeigen"><i class="fas fa-eye"></i></a>';
|
||||
$buttons .= '<a href="'.route('admin.dhl.show', $shipment).'" class="btn btn-sm btn-outline-primary" data-toggle="tooltip" title="Details anzeigen"><i class="fas fa-eye"></i></a>';
|
||||
if ($shipment->label_path) {
|
||||
$buttons .= '<a href="' . route('admin.dhl.download-label', $shipment) . '" class="btn btn-sm btn-outline-success" data-toggle="tooltip" title="Label herunterladen"><i class="fas fa-download"></i></a>';
|
||||
$buttons .= '<a href="'.route('admin.dhl.download-label', $shipment).'" class="btn btn-sm btn-outline-success" data-toggle="tooltip" title="Label herunterladen"><i class="fas fa-download"></i></a>';
|
||||
}
|
||||
// Email button
|
||||
if ($shipment->dhl_shipment_no && $shipment->canSendTrackingEmail()) {
|
||||
$emailTitle = $shipment->wasTrackingEmailSent()
|
||||
? 'Tracking-E-Mail erneut senden (gesendet: ' . $shipment->tracking_email_sent_at->format('d.m.Y H:i') . ')'
|
||||
? 'Tracking-E-Mail erneut senden (gesendet: '.$shipment->tracking_email_sent_at->format('d.m.Y H:i').')'
|
||||
: 'Tracking-E-Mail senden';
|
||||
$emailClass = $shipment->wasTrackingEmailSent() ? 'btn-success' : 'btn-outline-info';
|
||||
$buttons .= '<button type="button" class="btn btn-sm ' . $emailClass . ' send-tracking-email-btn" data-shipment-id="' . $shipment->id . '" data-toggle="tooltip" title="' . $emailTitle . '"><i class="fas fa-envelope"></i></button>';
|
||||
$buttons .= '<button type="button" class="btn btn-sm '.$emailClass.' send-tracking-email-btn" data-shipment-id="'.$shipment->id.'" data-toggle="tooltip" title="'.$emailTitle.'"><i class="fas fa-envelope"></i></button>';
|
||||
}
|
||||
// Cancel button
|
||||
if ($shipment->canCancel()) {
|
||||
$buttons .= '<button type="button" class="btn btn-sm btn-outline-danger cancel-shipment-btn" data-shipment-id="' . $shipment->id . '" data-toggle="tooltip" title="Sendung stornieren"><i class="fas fa-ban"></i></button>';
|
||||
$buttons .= '<button type="button" class="btn btn-sm btn-outline-danger cancel-shipment-btn" data-shipment-id="'.$shipment->id.'" data-toggle="tooltip" title="Sendung stornieren"><i class="fas fa-ban"></i></button>';
|
||||
}
|
||||
// Return label button
|
||||
// Return label button (for outbound shipments without existing return)
|
||||
if ($shipment->type == 'outbound' && ! $shipment->returns()->count()) {
|
||||
$buttons .= '<button type="button" class="btn btn-sm btn-outline-info create-return-btn" data-shipment-id="' . $shipment->id . '" data-toggle="tooltip" title="Retourenlabel erstellen"><i class="fas fa-undo"></i></button>';
|
||||
$buttons .= '<button type="button" class="btn btn-sm btn-outline-info create-return-btn" data-shipment-id="'.$shipment->id.'" data-toggle="tooltip" title="Retourenlabel erstellen"><i class="fas fa-undo"></i></button>';
|
||||
}
|
||||
$buttons .= '</div>';
|
||||
|
||||
|
|
@ -268,7 +268,7 @@ class DhlShipmentController extends Controller
|
|||
if (! $validationResult['valid']) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validierungsfehler: ' . implode(', ', $validationResult['errors']),
|
||||
'message' => 'Validierungsfehler: '.implode(', ', $validationResult['errors']),
|
||||
], 422);
|
||||
}
|
||||
|
||||
|
|
@ -341,7 +341,7 @@ class DhlShipmentController extends Controller
|
|||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Fehler beim Erstellen der Sendung: ' . $e->getMessage(),
|
||||
'message' => 'Fehler beim Erstellen der Sendung: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
|
@ -351,7 +351,11 @@ class DhlShipmentController extends Controller
|
|||
*/
|
||||
public function show(DhlShipment $shipment): View
|
||||
{
|
||||
$shipment->load(['shoppingOrder.shopping_user', 'relatedShipment']);
|
||||
$shipment->load([
|
||||
'shoppingOrder.shopping_user',
|
||||
'relatedShipment',
|
||||
'trackingEvents' => fn ($q) => $q->orderBy('event_time', 'desc'),
|
||||
]);
|
||||
|
||||
return view('admin.dhl.show', compact('shipment'));
|
||||
}
|
||||
|
|
@ -394,7 +398,7 @@ class DhlShipmentController extends Controller
|
|||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Fehler beim Stornieren der Sendung: ' . $e->getMessage(),
|
||||
'message' => 'Fehler beim Stornieren der Sendung: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
|
@ -426,7 +430,7 @@ class DhlShipmentController extends Controller
|
|||
}
|
||||
|
||||
// Check DHL_USE_QUEUE configuration
|
||||
$settingController = new SettingController();
|
||||
$settingController = new SettingController;
|
||||
$dhlConfig = $settingController->getDhlConfig();
|
||||
$useQueue = $dhlConfig['use_queue'] ?? false;
|
||||
|
||||
|
|
@ -462,11 +466,59 @@ class DhlShipmentController extends Controller
|
|||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Fehler beim Erstellen des Retourenlabels: ' . $e->getMessage(),
|
||||
'message' => 'Fehler beim Erstellen des Retourenlabels: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get billing address for return label (used when original delivery was to Packstation)
|
||||
*/
|
||||
private function getBillingAddressForReturn($shippingUser, array $recipient): array
|
||||
{
|
||||
if (! $shippingUser) {
|
||||
Log::warning('[DHL Controller] No shipping user found, using recipient data', [
|
||||
'recipient' => $recipient,
|
||||
]);
|
||||
|
||||
// Fallback: use recipient data but without Packstation fields
|
||||
return [
|
||||
'name' => trim(($recipient['firstname'] ?? '').' '.($recipient['lastname'] ?? '')),
|
||||
'name2' => $recipient['company'] ?? '',
|
||||
'street' => 'Adresse fehlt',
|
||||
'houseNumber' => '',
|
||||
'postalCode' => $recipient['postalCode'] ?? '',
|
||||
'city' => $recipient['city'] ?? '',
|
||||
'country' => $recipient['country'] ?? 'DEU',
|
||||
'email' => $recipient['email'] ?? '',
|
||||
'phone' => $recipient['phone'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
// Parse billing address to extract street and house number
|
||||
$billingAddress = trim($shippingUser->billing_address ?? '');
|
||||
$street = $billingAddress;
|
||||
$houseNumber = '';
|
||||
|
||||
// Try to extract house number from address
|
||||
if (preg_match('/^(.+?)\s+(\d+[a-zA-Z]?[-\/\d]*)$/u', $billingAddress, $matches)) {
|
||||
$street = trim($matches[1]);
|
||||
$houseNumber = trim($matches[2]);
|
||||
}
|
||||
|
||||
return [
|
||||
'name' => trim(($shippingUser->billing_firstname ?? '').' '.($shippingUser->billing_lastname ?? '')),
|
||||
'name2' => $shippingUser->billing_company ?? '',
|
||||
'street' => $street,
|
||||
'houseNumber' => $houseNumber,
|
||||
'postalCode' => $shippingUser->billing_zipcode ?? '',
|
||||
'city' => $shippingUser->billing_city ?? '',
|
||||
'country' => $shippingUser->billing_country?->code ?? 'DEU',
|
||||
'email' => $shippingUser->billing_email ?? '',
|
||||
'phone' => $shippingUser->billing_phone ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create return label synchronously
|
||||
*/
|
||||
|
|
@ -478,7 +530,7 @@ class DhlShipmentController extends Controller
|
|||
]);
|
||||
|
||||
// Get DHL configuration
|
||||
$settingController = new SettingController();
|
||||
$settingController = new SettingController;
|
||||
$dhlConfig = $settingController->getDhlConfig();
|
||||
|
||||
// Initialize DHL client
|
||||
|
|
@ -496,15 +548,22 @@ class DhlShipmentController extends Controller
|
|||
$order = $shipment->shoppingOrder;
|
||||
$recipient = $shipment->recipient ?? [];
|
||||
|
||||
$returnData = [
|
||||
'order_id' => $order->id,
|
||||
'original_shipment_id' => $shipment->id,
|
||||
'weight_kg' => $shipment->weight_kg,
|
||||
'label_format' => $shipment->label_format ?? 'PDF',
|
||||
// Check if this is a Packstation delivery - use billing address as return sender
|
||||
$hasPostNumber = ! empty($recipient['postnumber'] ?? $recipient['postNumber'] ?? '');
|
||||
|
||||
// Shipper: Customer sends back to us (swap addresses)
|
||||
'shipper' => [
|
||||
'name' => trim(($recipient['firstname'] ?? '') . ' ' . ($recipient['lastname'] ?? '')),
|
||||
if ($hasPostNumber) {
|
||||
Log::info('[DHL Controller] Packstation detected - using billing address for return sender', [
|
||||
'shipment_id' => $shipment->id,
|
||||
'order_id' => $order->id,
|
||||
]);
|
||||
|
||||
// Load billing address from order
|
||||
$shippingUser = $order->shopping_user;
|
||||
$shipperAddress = $this->getBillingAddressForReturn($shippingUser, $recipient);
|
||||
} else {
|
||||
// Use original recipient address (normal delivery)
|
||||
$shipperAddress = [
|
||||
'name' => trim(($recipient['firstname'] ?? '').' '.($recipient['lastname'] ?? '')),
|
||||
'name2' => $recipient['company'] ?? '',
|
||||
'street' => $recipient['street'] ?? '',
|
||||
'houseNumber' => $recipient['houseNumber'] ?? '',
|
||||
|
|
@ -513,7 +572,17 @@ class DhlShipmentController extends Controller
|
|||
'country' => $recipient['country'] ?? 'DEU',
|
||||
'email' => $recipient['email'] ?? '',
|
||||
'phone' => $recipient['phone'] ?? '',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$returnData = [
|
||||
'order_id' => $order->id,
|
||||
'original_shipment_id' => $shipment->id,
|
||||
'weight_kg' => $shipment->weight_kg,
|
||||
'label_format' => $shipment->label_format ?? 'PDF',
|
||||
|
||||
// Shipper: Customer sends back to us (using billing address for Packstation)
|
||||
'shipper' => $shipperAddress,
|
||||
|
||||
// Consignee: Our warehouse
|
||||
'consignee' => [
|
||||
|
|
@ -551,7 +620,7 @@ class DhlShipmentController extends Controller
|
|||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Fehler beim Erstellen des Retourenlabels: ' . $e->getMessage(),
|
||||
'message' => 'Fehler beim Erstellen des Retourenlabels: '.$e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -589,7 +658,7 @@ class DhlShipmentController extends Controller
|
|||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Fehler beim Aktualisieren der Tracking-Informationen: ' . $e->getMessage(),
|
||||
'message' => 'Fehler beim Aktualisieren der Tracking-Informationen: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
|
@ -679,7 +748,7 @@ class DhlShipmentController extends Controller
|
|||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Fehler beim Senden der Tracking-E-Mail: ' . $e->getMessage(),
|
||||
'message' => 'Fehler beim Senden der Tracking-E-Mail: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
|
@ -721,7 +790,7 @@ class DhlShipmentController extends Controller
|
|||
private function generateLabelFilename(DhlShipment $shipment): string
|
||||
{
|
||||
// Load order with customer data
|
||||
$customerName = $shipment->firstname . '_' . $shipment->lastname;
|
||||
$customerName = $shipment->firstname.'_'.$shipment->lastname;
|
||||
if ($shipment->company) {
|
||||
$customerName = $shipment->company;
|
||||
}
|
||||
|
|
@ -747,7 +816,7 @@ class DhlShipmentController extends Controller
|
|||
|
||||
// Ensure filename is not too long (max 255 characters)
|
||||
if (strlen($filename) > 255) {
|
||||
$maxCustomerLength = 255 - strlen('DHL--' . $shipmentNumber . '-' . $date . '.pdf');
|
||||
$maxCustomerLength = 255 - strlen('DHL--'.$shipmentNumber.'-'.$date.'.pdf');
|
||||
$customerName = substr($customerName, 0, max(10, $maxCustomerLength));
|
||||
$filename = sprintf(
|
||||
'DHL-%s-%s-%s.pdf',
|
||||
|
|
@ -802,7 +871,7 @@ class DhlShipmentController extends Controller
|
|||
if ($trackingResult['success']) {
|
||||
$processed++;
|
||||
} else {
|
||||
$errors[] = "Sendung #{$shipment->id}: " . $trackingResult['message'];
|
||||
$errors[] = "Sendung #{$shipment->id}: ".$trackingResult['message'];
|
||||
}
|
||||
} else {
|
||||
$errors[] = "Sendung #{$shipment->id} hat keine DHL-Sendungsnummer.";
|
||||
|
|
@ -823,7 +892,7 @@ class DhlShipmentController extends Controller
|
|||
break;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$errors[] = "Fehler bei Sendung {$shipmentId}: " . $e->getMessage();
|
||||
$errors[] = "Fehler bei Sendung {$shipmentId}: ".$e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -852,7 +921,7 @@ class DhlShipmentController extends Controller
|
|||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Fehler bei der Stapelverarbeitung: ' . $e->getMessage(),
|
||||
'message' => 'Fehler bei der Stapelverarbeitung: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
|
@ -917,8 +986,8 @@ class DhlShipmentController extends Controller
|
|||
{
|
||||
try {
|
||||
$zip = new ZipArchive;
|
||||
$zipFilename = 'dhl_labels_' . date('Y-m-d_H-i-s') . '.zip';
|
||||
$zipPath = storage_path('app/temp/' . $zipFilename);
|
||||
$zipFilename = 'dhl_labels_'.date('Y-m-d_H-i-s').'.zip';
|
||||
$zipPath = storage_path('app/temp/'.$zipFilename);
|
||||
|
||||
// Ensure temp directory exists
|
||||
if (! file_exists(storage_path('app/temp'))) {
|
||||
|
|
@ -963,7 +1032,7 @@ class DhlShipmentController extends Controller
|
|||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Fehler beim Erstellen der ZIP-Datei: ' . $e->getMessage(),
|
||||
'message' => 'Fehler beim Erstellen der ZIP-Datei: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Storage;
|
||||
use Response;
|
||||
use App\Models\UserCredit;
|
||||
use App\Repositories\CreditRepository;
|
||||
use Auth;
|
||||
use Response;
|
||||
use Storage;
|
||||
|
||||
class FileController extends Controller
|
||||
{
|
||||
|
|
@ -19,16 +19,37 @@ class FileController extends Controller
|
|||
|
||||
private function isPermissionShoppingOrder($shopping_order)
|
||||
{
|
||||
$user_id = $shopping_order->auth_user_id ? $shopping_order->auth_user_id : $shopping_order->member_id;
|
||||
if (Auth::user()->isAdmin() || $user_id == Auth::user()->id) {
|
||||
return true;
|
||||
// Portal-Kunden (auth:customers) – Prüfung über shopping_user (billing_email + member_id)
|
||||
if (Auth::guard('customers')->check()) {
|
||||
$customer = Auth::guard('customers')->user();
|
||||
if ($customer->shopping_user_id) {
|
||||
$member = $customer->shoppingUser;
|
||||
if ($member && $shopping_order->shopping_user) {
|
||||
$orderUser = $shopping_order->shopping_user;
|
||||
if (
|
||||
$orderUser->billing_email === $member->billing_email
|
||||
&& $orderUser->member_id === $member->member_id
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Admin / Berater (auth:user)
|
||||
if (Auth::check()) {
|
||||
$user_id = $shopping_order->auth_user_id ?: $shopping_order->member_id;
|
||||
if (Auth::user()->isAdmin() || $user_id == Auth::user()->id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
abort(404);
|
||||
}
|
||||
|
||||
private function isPermissionUserCredit($user_credit)
|
||||
{
|
||||
if (Auth::user()->isAdmin() || $user_credit->user_id == Auth::user()->id) {
|
||||
if (Auth::user()->isAdmin() || $user_credit->user_id == Auth::user()->id) {
|
||||
return true;
|
||||
}
|
||||
abort(404);
|
||||
|
|
@ -39,16 +60,15 @@ class FileController extends Controller
|
|||
if (Auth::check()) {
|
||||
return true;
|
||||
}
|
||||
abort(403, "Nicht autorisiert");
|
||||
abort(403, 'Nicht autorisiert');
|
||||
}
|
||||
|
||||
public function show($id = null, $from = null, $do = 'file')
|
||||
public function show($id = null, $from = null, $do = 'file', $locale = null)
|
||||
{
|
||||
|
||||
$path = "";
|
||||
$filename = "";
|
||||
$disk = "public";
|
||||
|
||||
$path = '';
|
||||
$filename = '';
|
||||
$disk = 'public';
|
||||
/*if($disk === 'user'){
|
||||
$file = \App\Models\File::findOrFail($id);
|
||||
$this->isPermission($file->user_id);
|
||||
|
|
@ -62,9 +82,15 @@ class FileController extends Controller
|
|||
if ($shopping_order->user_invoice) {
|
||||
$this->isPermissionShoppingOrder($shopping_order);
|
||||
$user_invoice = $shopping_order->user_invoice;
|
||||
$filename = $user_invoice->filename;
|
||||
$disk = $user_invoice->disk;
|
||||
$path = $user_invoice->getDownloadPath();
|
||||
// Lokalisierte Version wenn angegeben
|
||||
if ($locale && $locale !== 'de') {
|
||||
$filename = $user_invoice->getFilenameLocale($locale);
|
||||
$path = $user_invoice->getDownloadPathLocale($locale);
|
||||
} else {
|
||||
$filename = $user_invoice->filename;
|
||||
$path = $user_invoice->getDownloadPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73,18 +99,65 @@ class FileController extends Controller
|
|||
if ($shopping_order->user_invoice) {
|
||||
$this->isPermissionShoppingOrder($shopping_order);
|
||||
$user_invoice = $shopping_order->user_invoice;
|
||||
$filename = $user_invoice->delivery_filename;
|
||||
$disk = $user_invoice->disk;
|
||||
$path = $user_invoice->getDownloadPathDelivery();
|
||||
// Lokalisierte Version wenn angegeben
|
||||
if ($locale && $locale !== 'de') {
|
||||
$filename = $user_invoice->getFilenameLocale($locale);
|
||||
// Für Lieferschein den lokalisierten Pfad ermitteln
|
||||
$localizedDeliveryFilename = str_replace('.pdf', '-'.$locale.'.pdf', $user_invoice->delivery_filename);
|
||||
$localizedPath = $user_invoice->delivery_dir.$localizedDeliveryFilename;
|
||||
if (Storage::disk($disk)->exists($localizedPath)) {
|
||||
$filename = $localizedDeliveryFilename;
|
||||
$path = $localizedPath;
|
||||
} else {
|
||||
$filename = $user_invoice->delivery_filename;
|
||||
$path = $user_invoice->getDownloadPathDelivery();
|
||||
}
|
||||
} else {
|
||||
$filename = $user_invoice->delivery_filename;
|
||||
$path = $user_invoice->getDownloadPathDelivery();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($from === 'cancellation') {
|
||||
$shopping_order = \App\Models\ShoppingOrder::findOrFail($id);
|
||||
$this->isPermissionShoppingOrder($shopping_order);
|
||||
|
||||
// Stornorechnung finden: cancellation=true UND cancellation_id=null
|
||||
// (Die Original-Rechnung hat auch cancellation=true, aber MIT cancellation_id)
|
||||
$cancellation_invoice = \App\Models\UserInvoice::where('shopping_order_id', $shopping_order->id)
|
||||
->where('cancellation', true)
|
||||
->whereNull('cancellation_id')
|
||||
->first();
|
||||
|
||||
if ($cancellation_invoice) {
|
||||
$disk = $cancellation_invoice->disk;
|
||||
// Lokalisierte Version wenn angegeben
|
||||
if ($locale && $locale !== 'de') {
|
||||
$filename = $cancellation_invoice->getFilenameLocale($locale);
|
||||
$path = $cancellation_invoice->getDownloadPathLocale($locale);
|
||||
} else {
|
||||
$filename = $cancellation_invoice->filename;
|
||||
$path = $cancellation_invoice->getDownloadPath();
|
||||
}
|
||||
} else {
|
||||
return Response::make('Stornorechnung nicht gefunden.', 404);
|
||||
}
|
||||
}
|
||||
|
||||
if ($from === 'credit') {
|
||||
$user_credit = \App\Models\UserCredit::findOrFail($id);
|
||||
$this->isPermissionUserCredit($user_credit);
|
||||
$filename = $user_credit->filename;
|
||||
$disk = $user_credit->disk;
|
||||
$path = $user_credit->getDownloadPath();
|
||||
// Lokalisierte Version wenn angegeben
|
||||
if ($locale && $locale !== 'de') {
|
||||
$filename = $user_credit->getFilenameLocale($locale);
|
||||
$path = $user_credit->getDownloadPathLocale($locale);
|
||||
} else {
|
||||
$filename = $user_credit->filename;
|
||||
$path = $user_credit->getDownloadPath();
|
||||
}
|
||||
}
|
||||
|
||||
if ($from === 'credit_detail') {
|
||||
|
|
@ -93,15 +166,13 @@ class FileController extends Controller
|
|||
|
||||
return $this->create_credit_detail($user_credit, $do);
|
||||
|
||||
|
||||
/*
|
||||
$filename = $user_credit->filename;
|
||||
$disk = $user_credit->disk;
|
||||
$path = $user_credit->getDownloadPath();
|
||||
/*
|
||||
$filename = $user_credit->filename;
|
||||
$disk = $user_credit->disk;
|
||||
$path = $user_credit->getDownloadPath();
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
if ($from === 'dc_file') {
|
||||
// $this->isPermissionAuth();
|
||||
$dc_file = \App\Models\DcFile::findOrFail($id);
|
||||
|
|
@ -125,9 +196,14 @@ class FileController extends Controller
|
|||
$path = $dc_file->getBig();
|
||||
}
|
||||
|
||||
if ($from === 'user') {
|
||||
$file = \App\Models\File::findOrFail($id);
|
||||
$filename = $file->filename;
|
||||
$disk = 'user';
|
||||
$path = $file->dir.$file->filename;
|
||||
}
|
||||
|
||||
|
||||
if (!Storage::disk($disk)->exists($path)) {
|
||||
if (! Storage::disk($disk)->exists($path)) {
|
||||
return Response::make('Datei nicht gefunden.', 404);
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +213,6 @@ class FileController extends Controller
|
|||
|
||||
$file = Storage::disk($disk)->get($path);
|
||||
$mime = Storage::disk($disk)->mimeType($path);
|
||||
|
||||
if (isset($file)) {
|
||||
if ($do === 'stream') {
|
||||
return Storage::disk($disk)->response($path, $filename);
|
||||
|
|
@ -145,22 +220,22 @@ class FileController extends Controller
|
|||
|
||||
if ($do === 'file') {
|
||||
return Response::make($file, 200)
|
||||
->header("Content-Type", $mime)
|
||||
->header("Content-Length", strlen($file))
|
||||
->header('Content-disposition', 'filename="' . $filename . '"');
|
||||
->header('Content-Type', $mime)
|
||||
->header('Content-Length', strlen($file))
|
||||
->header('Content-disposition', 'filename="'.$filename.'"');
|
||||
}
|
||||
if ($do === 'image') {
|
||||
return Response::make($file, 200)
|
||||
->header("Content-Type", $mime);
|
||||
->header('Content-Type', $mime);
|
||||
}
|
||||
if ($do === 'pdf') {
|
||||
$path = storage_path() . '/app/public/' . $path;
|
||||
$path = storage_path().'/app/public/'.$path;
|
||||
|
||||
$headers = array(
|
||||
'Content-Type:' . $mime,
|
||||
$headers = [
|
||||
'Content-Type:'.$mime,
|
||||
// 'Content-Length: ' . $file->size
|
||||
// 'Content-Disposition: ' . $stream . '; filename=' . $file->original_name
|
||||
);
|
||||
];
|
||||
|
||||
return Response::download($path, $filename, $headers);
|
||||
}
|
||||
|
|
@ -171,8 +246,9 @@ class FileController extends Controller
|
|||
{
|
||||
|
||||
$credit_repo = new CreditRepository($user_credit->user);
|
||||
|
||||
return $credit_repo->create_report($user_credit, $do);
|
||||
//\Session()->flash('alert-success', "Gutschrift erstellt");
|
||||
// \Session()->flash('alert-success', "Gutschrift erstellt");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Request;
|
||||
use Util;
|
||||
|
||||
|
|
@ -19,20 +18,28 @@ class HomeController extends Controller
|
|||
*/
|
||||
public function __construct() {}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
if (! Auth::check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
|
||||
return redirect('home');
|
||||
}
|
||||
|
||||
//login / Dashboard
|
||||
public function newsArchive(): \Illuminate\View\View
|
||||
{
|
||||
return view('dashboard.news_archive', [
|
||||
'currentNews' => \App\Models\DashboardNews::getActiveNews(),
|
||||
'archiveNews' => \App\Models\DashboardNews::getArchiveNews(),
|
||||
]);
|
||||
}
|
||||
|
||||
// login / Dashboard
|
||||
public function show()
|
||||
{
|
||||
|
||||
if (!Auth::check()) {
|
||||
if (! Auth::check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
|
||||
|
|
@ -41,17 +48,17 @@ class HomeController extends Controller
|
|||
'now' => Carbon::now(),
|
||||
'dashboardNews' => \App\Models\DashboardNews::getActiveNews(),
|
||||
];
|
||||
|
||||
return view('home', $data);
|
||||
}
|
||||
|
||||
|
||||
public function loadingModal()
|
||||
{
|
||||
|
||||
$data = Request::get('data');
|
||||
$target = Request::get('target');
|
||||
$response = "";
|
||||
if ($data === "data_protection") {
|
||||
$response = '';
|
||||
if ($data === 'data_protection') {
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => true,
|
||||
|
|
@ -59,21 +66,21 @@ class HomeController extends Controller
|
|||
];
|
||||
$response = view('legal.data_protect_de', $data)->render();
|
||||
}
|
||||
if ($data === "imprint") {
|
||||
if ($data === 'imprint') {
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
$response = view('legal.imprint_de', $data)->render();
|
||||
}
|
||||
if ($data === "shop_term_of_use") {
|
||||
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") {
|
||||
if ($data === 'agb') {
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
|
|
@ -81,7 +88,7 @@ class HomeController extends Controller
|
|||
$response = view('legal.agb_de', $data)->render();
|
||||
}
|
||||
if (Request::ajax()) {
|
||||
return response()->json(['response' => $response, 'target' => $target]);
|
||||
return response()->json(['response' => $response, 'target' => $target]);
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
|
@ -154,6 +161,7 @@ class HomeController extends Controller
|
|||
'isMivitaShop' => Util::isMivitaShop(),
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
|
||||
return view('legal.data_protected', $data);
|
||||
}
|
||||
|
||||
|
|
@ -166,6 +174,7 @@ class HomeController extends Controller
|
|||
'yard_instance' => 'webshop',
|
||||
|
||||
];
|
||||
|
||||
return view('legal.agb', $data);
|
||||
}
|
||||
|
||||
|
|
@ -177,6 +186,7 @@ class HomeController extends Controller
|
|||
'user_shop' => Util::getUserShop(),
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
|
||||
return view('legal.imprint', $data);
|
||||
}
|
||||
|
||||
|
|
@ -195,19 +205,20 @@ class HomeController extends Controller
|
|||
$user->confirmed = 1;
|
||||
$user->confirmation_date = now();
|
||||
$user_auto_login = true;
|
||||
//nur bei der ersten Verifizierung den user auto login
|
||||
// nur bei der ersten Verifizierung den user auto login
|
||||
}
|
||||
//wird nun in WizardController::releaseAccount() auf null gesetzt
|
||||
//$user->confirmation_code = null;
|
||||
//$user->confirmation_code_to = null;
|
||||
//$user->confirmation_code_remider = 0;
|
||||
// wird nun in WizardController::releaseAccount() auf null gesetzt
|
||||
// $user->confirmation_code = null;
|
||||
// $user->confirmation_code_to = null;
|
||||
// $user->confirmation_code_remider = 0;
|
||||
$user->save();
|
||||
|
||||
//Login!
|
||||
// Login!
|
||||
if ($user_auto_login) {
|
||||
Auth::login($user);
|
||||
}
|
||||
$url = Util::getMyMivitaUrl();
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
|
||||
|
|
@ -215,20 +226,22 @@ class HomeController extends Controller
|
|||
{
|
||||
return view('status.status_register');
|
||||
}
|
||||
|
||||
public function statusVerify()
|
||||
{
|
||||
return view('status.status_verify');
|
||||
}
|
||||
|
||||
public function statusError()
|
||||
{
|
||||
return view('status.status_error');
|
||||
}
|
||||
|
||||
public function notFound()
|
||||
{
|
||||
return view('status.not_found');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -236,7 +249,7 @@ class HomeController extends Controller
|
|||
{
|
||||
|
||||
$data = Request::all();
|
||||
if ($data['user_id'] === "new") {
|
||||
if ($data['user_id'] === 'new') {
|
||||
if (User::where('email', $data['email'])->count()) {
|
||||
return json_encode(false);
|
||||
}
|
||||
|
|
@ -245,6 +258,7 @@ class HomeController extends Controller
|
|||
return json_encode(false);
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode(true);
|
||||
}
|
||||
|
||||
|
|
@ -253,21 +267,23 @@ class HomeController extends Controller
|
|||
return view('status.user_blocked');
|
||||
}
|
||||
|
||||
public function backToShop($reference = "")
|
||||
public function backToShop($reference = '')
|
||||
{
|
||||
|
||||
if ($reference) {
|
||||
$ShoppingPayment = ShoppingPayment::where('reference', $reference)->first();
|
||||
if ($ShoppingPayment && $ShoppingPayment->status === 'success') {
|
||||
$user = Auth::user();
|
||||
//is form wizard create payment
|
||||
// is form wizard create payment
|
||||
if ($user && ($user->wizard == 13 || $user->wizard == 20)) {
|
||||
$user->wizard = 15; //realese Payments
|
||||
$user->wizard = 15; // realese Payments
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_create', [15]));
|
||||
}
|
||||
} else {
|
||||
\Session()->flash('alert-error', __('msg.error_occurred_with_order'));
|
||||
|
||||
return redirect(url('/'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,21 +2,23 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Request;
|
||||
use App\User;
|
||||
use Validator;
|
||||
use App\Services\SysLog;
|
||||
use App\Models\UserAccount;
|
||||
use App\Models\UserHistory;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Services\UserService;
|
||||
use App\Mail\MailAccountActive;
|
||||
use App\Mail\MailCustomMessage;
|
||||
use App\Mail\MailVerifyAccount;
|
||||
use App\Mail\MailVerifyContact;
|
||||
use App\Repositories\UserRepository;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Models\File;
|
||||
use App\Models\UserAccount;
|
||||
use App\Models\UserHistory;
|
||||
use App\Repositories\ContractPDFRepository;
|
||||
use App\Repositories\UserRepository;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Services\SysLog;
|
||||
use App\Services\UserService;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
class LeadController extends Controller
|
||||
{
|
||||
|
|
@ -34,8 +36,7 @@ class LeadController extends Controller
|
|||
public function index()
|
||||
{
|
||||
|
||||
|
||||
$filter_sponsor = User::join('user_accounts', 'account_id', '=', 'user_accounts.id')->select('users.id', 'users.email', 'user_accounts.first_name', 'user_accounts.last_name')->where('users.deleted_at', '=', null)->where('users.admin', "<", 4)->get();
|
||||
$filter_sponsor = User::join('user_accounts', 'account_id', '=', 'user_accounts.id')->select('users.id', 'users.email', 'user_accounts.first_name', 'user_accounts.last_name')->where('users.deleted_at', '=', null)->where('users.admin', '<', 4)->get();
|
||||
|
||||
$this->setFilterVars();
|
||||
$data = [
|
||||
|
|
@ -47,7 +48,6 @@ class LeadController extends Controller
|
|||
return view('admin.lead.index', $data);
|
||||
}
|
||||
|
||||
|
||||
private function setFilterVars()
|
||||
{
|
||||
|
||||
|
|
@ -68,25 +68,22 @@ class LeadController extends Controller
|
|||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if ($id === "new") {
|
||||
$user = new User();
|
||||
$user->account = new UserAccount();
|
||||
if ($id === 'new') {
|
||||
$user = new User;
|
||||
$user->account = new UserAccount;
|
||||
$user->account->same_as_billing = 1;
|
||||
$user->account->country_id = 1;
|
||||
$user->account->shipping_country_id = 1;
|
||||
$user->id = "new";
|
||||
$user->id = 'new';
|
||||
} else {
|
||||
$user = User::withTrashed()->findOrFail($id);
|
||||
if (!$user->account) {
|
||||
$user->account = new UserAccount();
|
||||
if (! $user->account) {
|
||||
$user->account = new UserAccount;
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
|
|
@ -96,11 +93,11 @@ class LeadController extends Controller
|
|||
'm_data_load' => false,
|
||||
'm_data_error' => false,
|
||||
];
|
||||
|
||||
return view('admin.lead.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function editPost($id)
|
||||
|
|
@ -108,23 +105,23 @@ class LeadController extends Controller
|
|||
$m_data_load = false;
|
||||
$m_data_error = false;
|
||||
$data = Request::all();
|
||||
if (!isset($data['edit_m_data_key']) || $data['edit_m_data_key'] !== config('mivita.edit_data_pass')) {
|
||||
$m_data_error = "Das Passwort ist falsch.";
|
||||
if (! isset($data['edit_m_data_key']) || $data['edit_m_data_key'] !== config('mivita.edit_data_pass')) {
|
||||
$m_data_error = 'Das Passwort ist falsch.';
|
||||
} else {
|
||||
$m_data_load = true;
|
||||
}
|
||||
|
||||
if ($id === "new") {
|
||||
$user = new User();
|
||||
$user->account = new UserAccount();
|
||||
if ($id === 'new') {
|
||||
$user = new User;
|
||||
$user->account = new UserAccount;
|
||||
$user->account->same_as_billing = 1;
|
||||
$user->account->country_id = 1;
|
||||
$user->account->shipping_country_id = 1;
|
||||
$user->id = "new";
|
||||
$user->id = 'new';
|
||||
} else {
|
||||
$user = User::withTrashed()->findOrFail($id);
|
||||
if (!$user->account) {
|
||||
$user->account = new UserAccount();
|
||||
if (! $user->account) {
|
||||
$user->account = new UserAccount;
|
||||
}
|
||||
}
|
||||
$next_account_id = UserAccount::withTrashed()->max('m_account') + 1;
|
||||
|
|
@ -138,13 +135,13 @@ class LeadController extends Controller
|
|||
'm_data_load' => $m_data_load,
|
||||
'm_data_error' => $m_data_error,
|
||||
'can_change_mail' => true,
|
||||
'next_account_id' => $next_account_id
|
||||
'next_account_id' => $next_account_id,
|
||||
];
|
||||
|
||||
return view('admin.lead.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
*/
|
||||
public function store(Request $request)
|
||||
|
|
@ -152,16 +149,27 @@ class LeadController extends Controller
|
|||
|
||||
$data = Request::all();
|
||||
$show = Request::get('show');
|
||||
if (isset($data['action']) && $data['action'] == "reverse_charge_validate" && isset($data['user_id'])) {
|
||||
if (! isset($data['user_id'])) {
|
||||
return redirect()->back()->with('error', 'User ID is required');
|
||||
}
|
||||
if (isset($data['action']) && $data['action'] == 'reverse_charge_validate' && isset($data['user_id'])) {
|
||||
$user = User::findOrFail($data['user_id']);
|
||||
|
||||
return $this->userRepo->reverse_charge_validate($data, $user, route('admin_lead_edit', [$user->id]));
|
||||
}
|
||||
|
||||
if (isset($data['action']) && $data['action'] == "reverse_charge_delete" && isset($data['user_id'])) {
|
||||
if (isset($data['action']) && $data['action'] == 'reverse_charge_delete' && isset($data['user_id'])) {
|
||||
$user = User::findOrFail($data['user_id']);
|
||||
|
||||
return $this->userRepo->reverse_charge_delete($data, $user, route('admin_lead_edit', [$user->id]));
|
||||
}
|
||||
|
||||
if (isset($data['action']) && $data['action'] == 'recreate_contract' && isset($data['user_id'])) {
|
||||
$user = User::findOrFail($data['user_id']);
|
||||
$useCurrentDate = isset($data['use_current_date']) && $data['use_current_date'] == '1';
|
||||
|
||||
return $this->recreateContract($user, $useCurrentDate);
|
||||
}
|
||||
|
||||
/*
|
||||
if(isset($data['reverse_charge_validate']) && isset($data['user_id'])){
|
||||
|
|
@ -171,7 +179,7 @@ class LeadController extends Controller
|
|||
$userRepo = new UserRepository($user);
|
||||
return $userRepo->reverse_charge_validate($data, $user);
|
||||
}
|
||||
|
||||
|
||||
if(isset($data['reverse_charge_delete']) && isset($data['user_id'])){
|
||||
$user = User::findOrFail($data['user_id']);
|
||||
$user->wizard = 1;
|
||||
|
|
@ -180,16 +188,16 @@ class LeadController extends Controller
|
|||
return $userRepo->reverse_charge_delete($data, $user);
|
||||
}*/
|
||||
|
||||
if ($data['user_id'] === "new" || $data['user_id'] == 0) {
|
||||
$rules = array(
|
||||
if ($data['user_id'] === 'new' || $data['user_id'] == 0) {
|
||||
$rules = [
|
||||
'salutation' => 'required',
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
'email' => 'required|string|email|max:255|unique:users',
|
||||
'email-confirm' => 'required|same:email',
|
||||
);
|
||||
];
|
||||
} else {
|
||||
$rules = array(
|
||||
$rules = [
|
||||
'salutation' => 'required',
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
|
|
@ -201,15 +209,15 @@ class LeadController extends Controller
|
|||
'bank_owner' => 'required',
|
||||
'bank_iban' => 'required',
|
||||
'bank_bic' => 'required',
|
||||
);
|
||||
if (!Request::get('same_as_billing')) {
|
||||
];
|
||||
if (! Request::get('same_as_billing')) {
|
||||
$rules = array_merge($rules, [
|
||||
'shipping_firstname' => 'required',
|
||||
'shipping_lastname' => 'required',
|
||||
'shipping_address' => 'required',
|
||||
'shipping_zipcode' => 'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_salutation' => 'required'
|
||||
'shipping_salutation' => 'required',
|
||||
|
||||
]);
|
||||
}
|
||||
|
|
@ -217,53 +225,54 @@ class LeadController extends Controller
|
|||
|
||||
if (isset($data['m_account']) && $data['m_account']) {
|
||||
$user = User::findOrFail($data['user_id']);
|
||||
$rules['m_account'] = 'unique:user_accounts,m_account,' . $user->account->id . ',id';
|
||||
$rules['m_account'] = 'unique:user_accounts,m_account,'.$user->account->id.',id';
|
||||
}
|
||||
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
|
||||
if ($data['user_id'] === "new" || $data['user_id'] == 0) {
|
||||
$user_id = "new";
|
||||
if ($data['user_id'] === 'new' || $data['user_id'] == 0) {
|
||||
$user_id = 'new';
|
||||
} else {
|
||||
$user = User::findOrFail($data['user_id']);
|
||||
$user_id = $user->id;
|
||||
}
|
||||
return redirect(route('admin_lead_edit', [$user_id]) . "?show=" . $show)->withErrors($validator)->withRequest(Request::all());
|
||||
|
||||
return redirect(route('admin_lead_edit', [$user_id]).'?show='.$show)->withErrors($validator)->withRequest(Request::all());
|
||||
}
|
||||
|
||||
if ($data['user_id'] === "new" || $data['user_id'] == 0) {
|
||||
$user = new User();
|
||||
$user->id = "new";
|
||||
$user->account = new UserAccount();
|
||||
if ($data['user_id'] === 'new' || $data['user_id'] == 0) {
|
||||
$user = new User;
|
||||
$user->id = 'new';
|
||||
$user->account = new UserAccount;
|
||||
} else {
|
||||
$user = User::findOrFail($data['user_id']);
|
||||
if (!$user->account) {
|
||||
$user->account = new UserAccount();
|
||||
if (! $user->account) {
|
||||
$user->account = new UserAccount;
|
||||
}
|
||||
}
|
||||
|
||||
$this->userRepo->update($data);
|
||||
|
||||
if (isset($data['m_data_edit']) && $data['m_data_edit'] === "TSOK") {
|
||||
//syslog
|
||||
if (isset($data['m_data_edit']) && $data['m_data_edit'] === 'TSOK') {
|
||||
// syslog
|
||||
if (isset($data['m_sponsor'])) {
|
||||
if ($user->m_sponsor != $data['m_sponsor']) {
|
||||
$from_user = isset($user->user_sponsor->email) ? $user->user_sponsor->email : "empty";
|
||||
$from_user = isset($user->user_sponsor->email) ? $user->user_sponsor->email : 'empty';
|
||||
$t_user = User::find($data['m_sponsor']);
|
||||
$to_user = isset($t_user->email) ? $t_user->email : "empty";
|
||||
$to_user = isset($t_user->email) ? $t_user->email : 'empty';
|
||||
|
||||
SysLog::action('save-m_sponsor', 'lead_edit_sponsor', 3)
|
||||
->setUserId(\Auth::user()->id)
|
||||
->setModel($user->id, User::class)
|
||||
->setMessage('Set user new sponsor from: ' . $from_user . " | to: " . $to_user)
|
||||
->setMessage('Set user new sponsor from: '.$from_user.' | to: '.$to_user)
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
$user = $this->userRepo->getModel();
|
||||
$user->m_level = isset($data['m_level']) ? $data['m_level'] : NULL;
|
||||
$user->m_sponsor = isset($data['m_sponsor']) ? $data['m_sponsor'] : NULL;
|
||||
$user->m_level = isset($data['m_level']) ? $data['m_level'] : null;
|
||||
$user->m_sponsor = isset($data['m_sponsor']) ? $data['m_sponsor'] : null;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
|
|
@ -275,19 +284,22 @@ class LeadController extends Controller
|
|||
|
||||
$user->lang = $user->getLandByCountry();
|
||||
$user->confirmation_code = $confirmation_code;
|
||||
//10 == start wizard form create Lead
|
||||
// 10 == start wizard form create Lead
|
||||
$user->wizard = 10;
|
||||
$user->save();
|
||||
Mail::to($user->email)->locale($user->getLocale())->send(new MailVerifyContact($confirmation_code, $user));
|
||||
|
||||
\Session()->flash('alert-save', true);
|
||||
|
||||
return redirect(route('admin_leads'));
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', true);
|
||||
return redirect(route('admin_lead_edit', [$user->id]) . "?show=" . $show);
|
||||
|
||||
return redirect(route('admin_lead_edit', [$user->id]).'?show='.$show);
|
||||
}
|
||||
//user released when register is complete
|
||||
|
||||
// user released when register is complete
|
||||
public function released($action, $id)
|
||||
{
|
||||
|
||||
|
|
@ -295,31 +307,31 @@ class LeadController extends Controller
|
|||
|
||||
if ($action === 'completed') {
|
||||
$validator = Validator::make(Request::all(), []);
|
||||
if (!$user->m_sponsor) {
|
||||
if (! $user->m_sponsor) {
|
||||
$validator->errors()->add('m_sponsor', __('Berater hat keinen Sponsor.'));
|
||||
}
|
||||
if (!$user->account->m_first_name) {
|
||||
if (! $user->account->m_first_name) {
|
||||
$validator->errors()->add('m_first_name', __('Berater hat keinen Vornamen.'));
|
||||
}
|
||||
if (!$user->account->m_last_name) {
|
||||
if (! $user->account->m_last_name) {
|
||||
$validator->errors()->add('m_last_name', __('Berater hat keinen Nachnamen.'));
|
||||
}
|
||||
if (!$user->account->m_account) {
|
||||
if (! $user->account->m_account) {
|
||||
$validator->errors()->add('m_account', __('Berater hat keine Account ID'));
|
||||
}
|
||||
if ($validator->errors()->count()) {
|
||||
return back()->withErrors($validator)->withRequest(Request::all());
|
||||
}
|
||||
|
||||
//create PDF
|
||||
// create PDF
|
||||
$pdf = new ContractPDFRepository($user);
|
||||
$pdf->_set('disk', 'user');
|
||||
$pdf->_set('dir', '/' . $user->id . '/documents/');
|
||||
$pdf->_set('dir', '/'.$user->id.'/documents/');
|
||||
$pdf->_set('user_id', $user->id);
|
||||
$pdf->_set('identifier', 'contract');
|
||||
$pdf->createContractPDF();
|
||||
|
||||
//set wizard tp payments
|
||||
// set wizard tp payments
|
||||
$user->wizard = 20;
|
||||
$user->active = 1;
|
||||
$user->active_date = now();
|
||||
|
|
@ -328,16 +340,15 @@ class LeadController extends Controller
|
|||
$user->confirmation_code_remider = 0;
|
||||
$user->save();
|
||||
|
||||
//mail with code to user?
|
||||
// mail with code to user?
|
||||
Mail::to($user->email)->locale($user->getLocale())->send(new MailAccountActive($user));
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => 'released_completed', 'status' => 0]);
|
||||
\Session()->flash('alert-success', "Berater freigeschaltet!");
|
||||
\Session()->flash('alert-success', 'Berater freigeschaltet!');
|
||||
}
|
||||
|
||||
if ($action === 'incomplete') {
|
||||
|
||||
|
||||
//reset release
|
||||
// reset release
|
||||
$confirmation_code = UserService::createConfirmationCode();
|
||||
$user->confirmation_code = $confirmation_code;
|
||||
$user->confirmation_code_to = date('Y-m-d H:i:s', strtotime('+1 week'));
|
||||
|
|
@ -356,16 +367,16 @@ class LeadController extends Controller
|
|||
Mail::to($user->email)->locale($user->getLocale())->send(new MailCustomMessage($user, $data, \Auth::user(), true));
|
||||
} catch (\Exception $e) {
|
||||
dump($e->getMessage());
|
||||
dd("error");
|
||||
dd('error');
|
||||
}
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => 'released_incomplete', 'status' => 0]);
|
||||
\Session()->flash('alert-success', "E-Mail an Berater gesendet.");
|
||||
\Session()->flash('alert-success', 'E-Mail an Berater gesendet.');
|
||||
}
|
||||
|
||||
return redirect(route('admin_lead_edit', [$user->id]));
|
||||
}
|
||||
|
||||
|
||||
//send new verfified mail to user
|
||||
// send new verfified mail to user
|
||||
public function newMailVerified($id)
|
||||
{
|
||||
|
||||
|
|
@ -381,15 +392,15 @@ class LeadController extends Controller
|
|||
Mail::to($user->email)->locale($user->getLocale())->send(new MailVerifyAccount($confirmation_code, $user));
|
||||
} catch (\Exception $e) {
|
||||
dump($e->getMessage());
|
||||
dd("error");
|
||||
dd('error');
|
||||
}
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => 'new_mail_verified', 'status' => 0]);
|
||||
|
||||
\Session()->flash('alert-success', "E-Mail erneut gesendet");
|
||||
\Session()->flash('alert-success', 'E-Mail erneut gesendet');
|
||||
|
||||
return redirect(route('admin_lead_edit', [$user->id]));
|
||||
}
|
||||
|
||||
|
||||
public function deleteFile($user_id, $file_id, $relation)
|
||||
{
|
||||
|
||||
|
|
@ -399,11 +410,12 @@ class LeadController extends Controller
|
|||
if ($file->identifier === 'business_license') {
|
||||
$user->account->setNotice('business_license', '');
|
||||
}
|
||||
//remove file
|
||||
\Storage::disk('user')->delete($file->dir . $file->filename);
|
||||
// remove file
|
||||
\Storage::disk('user')->delete($file->dir.$file->filename);
|
||||
$file->delete();
|
||||
\Session()->flash('alert-success', __('msg.file_deleted'));
|
||||
}
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
|
|
@ -411,22 +423,21 @@ class LeadController extends Controller
|
|||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
//$query = UserSalesVolume::with('user', 'user.account')->with('shopping_order')->select('user_sales_volumes.*')
|
||||
// $query = UserSalesVolume::with('user', 'user.account')->with('shopping_order')->select('user_sales_volumes.*')
|
||||
|
||||
$query = User::with('account')->select('users.*')->where('users.deleted_at', '=', null)->where('users.admin', "<", 5);
|
||||
$query = User::with('account')->select('users.*')->where('users.deleted_at', '=', null)->where('users.admin', '<', 5);
|
||||
if (Request::get('leads_filter_sponsor_id')) {
|
||||
$query->where('users.m_sponsor', '=', Request::get('leads_filter_sponsor_id'));
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
public function getLeads()
|
||||
{
|
||||
|
||||
$query = $this->initSearch();
|
||||
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('first_name', function (User $user) {
|
||||
return $user->account ? $user->account->first_name : '';
|
||||
|
|
@ -435,14 +446,14 @@ class LeadController extends Controller
|
|||
return $user->account ? $user->account->last_name : '';
|
||||
})
|
||||
->addColumn('user_level', function (User $user) {
|
||||
return $user->user_level ? '<span class="badge badge-outline-success">' . $user->user_level->name . '</span>' : '';
|
||||
return $user->user_level ? '<span class="badge badge-outline-success">'.$user->user_level->name.'</span>' : '';
|
||||
})
|
||||
->addColumn('user_sponsor', function (User $user) {
|
||||
return $user->user_sponsor ?
|
||||
'<span class="badge badge-outline-warning-dark">' . $user->user_sponsor->account->first_name . " " . $user->user_sponsor->account->last_name . '</span>' : "-";
|
||||
'<span class="badge badge-outline-warning-dark">'.$user->user_sponsor->account->first_name.' '.$user->user_sponsor->account->last_name.'</span>' : '-';
|
||||
})
|
||||
->addColumn('id', function (User $user) {
|
||||
return '<a href="' . route('admin_lead_edit', [$user->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
return '<a href="'.route('admin_lead_edit', [$user->id]).'" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('confirmed', function (User $user) {
|
||||
return $user->confirmed ? '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
|
||||
|
|
@ -456,54 +467,58 @@ class LeadController extends Controller
|
|||
|
||||
->addColumn('useractive', function (User $user) {
|
||||
$date = $user->getActiveDateFormat();
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-active" data-id="' . $user->id . '" data-email="' . $user->email . '" data-active="' . $user->active . '" data-active_date="' . $date . '">';
|
||||
return $user->active ? $link . '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> ' . $date . '</span></a>' : $link . '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-active" data-id="'.$user->id.'" data-email="'.$user->email.'" data-active="'.$user->active.'" data-active_date="'.$date.'">';
|
||||
|
||||
return $user->active ? $link.'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$date.'</span></a>' : $link.'<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
})
|
||||
->addColumn('payaccount', function (User $user) {
|
||||
$date = $user->getPaymentAccountDateFormat();
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-account" data-id="' . $user->id . '" data-email="' . $user->email . '" data-payment_account="' . $date . '">';
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-account" data-id="'.$user->id.'" data-email="'.$user->email.'" data-payment_account="'.$date.'">';
|
||||
if ($user->payment_account) {
|
||||
if ($user->isActiveAccount()) {
|
||||
return $link . '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> ' . $date . '</span></a>';
|
||||
return $link.'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$date.'</span></a>';
|
||||
}
|
||||
return $link . '<span class="badge badge-pill badge-warning"><i class="fa fa-ban"></i> ' . $date . '</span></a>';
|
||||
|
||||
return $link.'<span class="badge badge-pill badge-warning"><i class="fa fa-ban"></i> '.$date.'</span></a>';
|
||||
}
|
||||
return $link . '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
|
||||
return $link.'<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
})
|
||||
->addColumn('payshop', function (User $user) {
|
||||
$date = $user->getPaymentShopDateFormat();
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-shop" data-id="' . $user->id . '" data-email="' . $user->email . '" data-payment_shop="' . $date . '">';
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-shop" data-id="'.$user->id.'" data-email="'.$user->email.'" data-payment_shop="'.$date.'">';
|
||||
if ($user->payment_shop) {
|
||||
if ($user->isActiveShop()) {
|
||||
return $link . '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> ' . $date . '</span></a>';
|
||||
return $link.'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$date.'</span></a>';
|
||||
}
|
||||
return $link . '<span class="badge badge-pill badge-warning"><i class="fa fa-ban"></i> ' . $date . '</span></a>';
|
||||
}
|
||||
return $link . '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
})
|
||||
|
||||
return $link.'<span class="badge badge-pill badge-warning"><i class="fa fa-ban"></i> '.$date.'</span></a>';
|
||||
}
|
||||
|
||||
return $link.'<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
})
|
||||
|
||||
->addColumn('payment_account', function (User $user) {
|
||||
return $user->payment_account ? ' <span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
|
||||
})
|
||||
->addColumn('payment_account_date', function (User $user) {
|
||||
return $user->payment_account ? $user->getPaymentAccountDateFormat(false) : "-";
|
||||
return $user->payment_account ? $user->getPaymentAccountDateFormat(false) : '-';
|
||||
})
|
||||
->addColumn('payment_shop', function (User $user) {
|
||||
return $user->payment_shop ? ' <span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
|
||||
})
|
||||
|
||||
->addColumn('payment_shop_date', function (User $user) {
|
||||
return $user->payment_shop ? $user->getPaymentShopDateFormat(false) : "-";
|
||||
return $user->payment_shop ? $user->getPaymentShopDateFormat(false) : '-';
|
||||
})
|
||||
->addColumn('shop_domain', function (User $user) {
|
||||
return $user->shop ? ' <span class="small"><a href="' . $user->shop->getSubdomain(false) . '" target="_blank">' . $user->shop->getSubdomain(false) . '</a></span>' : '';
|
||||
return $user->shop ? ' <span class="small"><a href="'.$user->shop->getSubdomain(false).'" target="_blank">'.$user->shop->getSubdomain(false).'</a></span>' : '';
|
||||
})
|
||||
->addColumn('turnover', function (User $user) {
|
||||
return "-";
|
||||
return '-';
|
||||
})
|
||||
->addColumn('sales_total', function (User $user) {
|
||||
return "-";
|
||||
return '-';
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('confirmed', 'confirmed $1')
|
||||
|
|
@ -514,4 +529,37 @@ class LeadController extends Controller
|
|||
->rawColumns(['id', 'user_level', 'user_sponsor', 'confirmed', 'useractive', 'payaccount', 'payshop', 'agreement', 'active', 'payment_account', 'payment_shop', 'shop_domain'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt den Beratervertrag neu (überschreibt bestehende Verträge)
|
||||
* Verwendet für mehrsprachige Verträge
|
||||
*/
|
||||
public function recreateContract($user, $useCurrentDate = true)
|
||||
{
|
||||
if (! Auth::user()->isAdmin()) {
|
||||
abort(403, 'Nicht autorisiert');
|
||||
}
|
||||
|
||||
// Datum ermitteln
|
||||
$contractDate = $useCurrentDate ? now() : ($user->active_date ? \Carbon\Carbon::parse($user->active_date) : now());
|
||||
|
||||
// Alten Vertrag löschen
|
||||
File::where('user_id', $user->id)
|
||||
->where('identifier', 'contract')
|
||||
->delete();
|
||||
|
||||
// Neue Verträge erstellen (DE + Benutzersprache)
|
||||
$pdf = new ContractPDFRepository($user);
|
||||
$pdf->_set('disk', 'user');
|
||||
$pdf->_set('dir', '/'.$user->id.'/documents/');
|
||||
$pdf->_set('user_id', $user->id);
|
||||
$pdf->_set('identifier', 'contract');
|
||||
$pdf->_set('contract_date', $contractDate);
|
||||
$pdf->createContractPDF();
|
||||
|
||||
$dateInfo = $useCurrentDate ? 'mit aktuellem Datum' : 'mit bestehendem Datum ('.$contractDate->format('d.m.Y').')';
|
||||
\Session()->flash('alert-success', 'Beratervertrag wurde neu erstellt (DE + '.strtoupper($user->account->language ?? 'de').') '.$dateInfo);
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,26 +2,23 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Models\Product;
|
||||
use App\Models\UserAbo;
|
||||
use App\Models\Homeparty;
|
||||
|
||||
use App\Models\UserLevel;
|
||||
use App\Models\UserCredit;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Models\HomepartyUser;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserAbo;
|
||||
use App\Models\UserCredit;
|
||||
use App\Models\UserLevel;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Services\BusinessPlan\TreeCalcBot;
|
||||
use App\Services\BusinessPlan\TreeCalcBotOptimized;
|
||||
use App\Services\DhlModalService;
|
||||
use App\User;
|
||||
use Request;
|
||||
|
||||
class ModalController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
|
|
@ -30,21 +27,21 @@ class ModalController extends Controller
|
|||
public function load()
|
||||
{
|
||||
$data = Request::all();
|
||||
$ret = "";
|
||||
$ret = '';
|
||||
$status = false;
|
||||
if (Request::ajax()) {
|
||||
if ($data['action'] === 'shopping-order-change-member') {
|
||||
$value = ShoppingOrder::find($data['id']);
|
||||
$route = route('admin_sales_customers_detail', [$value->id]);
|
||||
$ret = view("admin.modal.member", compact('value', 'data', 'route'))->render();
|
||||
$ret = view('admin.modal.member', compact('value', 'data', 'route'))->render();
|
||||
}
|
||||
if ($data['action'] === 'shopping-user-change-member') {
|
||||
$value = ShoppingUser::find($data['id']);
|
||||
$route = route('admin_customer_edit', [$value->id]);
|
||||
$ret = view("admin.modal.member", compact('value', 'data', 'route'))->render();
|
||||
$ret = view('admin.modal.member', compact('value', 'data', 'route'))->render();
|
||||
}
|
||||
if ($data['action'] === 'shopping-user-is-like-member') {
|
||||
$current = ShoppingUser::find($data['id']); //current user form order
|
||||
$current = ShoppingUser::find($data['id']); // current user form order
|
||||
$possibles = [];
|
||||
if ($current->is_like) {
|
||||
$likes = $current->getNotice('like');
|
||||
|
|
@ -52,46 +49,46 @@ class ModalController extends Controller
|
|||
$possibles[] = ShoppingUser::find($like_id);
|
||||
}
|
||||
}
|
||||
$ret = view("admin.modal.is_like_member", compact('current', 'possibles', 'data'))->render();
|
||||
$ret = view('admin.modal.is_like_member', compact('current', 'possibles', 'data'))->render();
|
||||
}
|
||||
if ($data['action'] === 'shopping-order-change-points') {
|
||||
$value = ShoppingOrder::find($data['id']);
|
||||
$route = route('admin_sales_customers_detail', [$value->id]);
|
||||
$ret = view("admin.modal.change_points", compact('value', 'data', 'route'))->render();
|
||||
$ret = view('admin.modal.change_points', compact('value', 'data', 'route'))->render();
|
||||
}
|
||||
if ($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();
|
||||
$product = Product::find($data['id']); // current user form order
|
||||
$ret = view('admin.modal.show_product', compact('product', 'data'))->render();
|
||||
}
|
||||
|
||||
if ($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();
|
||||
$product = Product::find($data['id']); // current user form order
|
||||
$ret = view('admin.modal.show_product', compact('product', 'data'))->render();
|
||||
}
|
||||
|
||||
if ($data['action'] === 'shop-user-order-detail') {
|
||||
$user = \Auth::user();
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
if (!$user->isAdmin() && $shopping_order->member_id !== $user->id) {
|
||||
if (! $user->isAdmin() && $shopping_order->member_id !== $user->id) {
|
||||
abort(404);
|
||||
}
|
||||
$isAdmin = false;
|
||||
$ret = view("user.shop.sales.modal_api_order_detail", compact('shopping_order', 'isAdmin', 'data'))->render();
|
||||
$ret = view('user.shop.sales.modal_api_order_detail', compact('shopping_order', 'isAdmin', 'data'))->render();
|
||||
}
|
||||
|
||||
if ($data['action'] === 'shop-user-order-shipping-detail') {
|
||||
$user = \Auth::user();
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
if (!$user->isAdmin() && $shopping_order->auth_user_id !== $user->id) {
|
||||
if (! $user->isAdmin() && $shopping_order->auth_user_id !== $user->id) {
|
||||
abort(404);
|
||||
}
|
||||
$isAdmin = false;
|
||||
$ret = view("user.shop.sales.modal_api_order_shipping_detail", compact('shopping_order', 'isAdmin', 'data'))->render();
|
||||
$ret = view('user.shop.sales.modal_api_order_shipping_detail', compact('shopping_order', 'isAdmin', 'data'))->render();
|
||||
}
|
||||
|
||||
if ($data['action'] === 'user-order-my-delivery-show') {
|
||||
$user = \Auth::user();
|
||||
$ret = view("admin.modal.show_user_customers", compact('user', 'data'))->render();
|
||||
$ret = view('admin.modal.show_user_customers', compact('user', 'data'))->render();
|
||||
}
|
||||
|
||||
if ($data['action'] === 'user-order-my-delivery-add') {
|
||||
|
|
@ -103,60 +100,62 @@ class ModalController extends Controller
|
|||
$homeparty = Homeparty::find($data['id']);
|
||||
$homeparty_user = HomepartyUser::find($data['user_id']);
|
||||
$data['homeparty'] = $homeparty;
|
||||
$ret = view("user.homeparty.modal_hp_show_products", compact('data', 'homeparty', 'homeparty_user'))->render();
|
||||
$ret = view('user.homeparty.modal_hp_show_products', compact('data', 'homeparty', 'homeparty_user'))->render();
|
||||
}
|
||||
|
||||
if ($data['action'] === 'user-level-edit') {
|
||||
$value = UserLevel::find($data['id']);
|
||||
$route = route('admin_level_store', [$value->id]);
|
||||
$ret = view("admin.modal.user_level_edit", compact('value', 'data', 'route'))->render();
|
||||
$ret = view('admin.modal.user_level_edit', compact('value', 'data', 'route'))->render();
|
||||
}
|
||||
if ($data['action'] === 'user-level-add') {
|
||||
$value = new UserLevel();
|
||||
$value = new UserLevel;
|
||||
$route = route('admin_level_store', ['new']);
|
||||
$ret = view("admin.modal.user_level_edit", compact('value', 'data', 'route'))->render();
|
||||
$ret = view('admin.modal.user_level_edit', compact('value', 'data', 'route'))->render();
|
||||
}
|
||||
if ($data['action'] === 'business-user-detail') {
|
||||
$user = User::findOrFail($data['id']);
|
||||
if ($data['init_from'] === 'admin') {
|
||||
$data['month'] = session('business_user_filter_month');
|
||||
$data['year'] = session('business_user_filter_year');
|
||||
$data['year'] = session('business_user_filter_year');
|
||||
} else {
|
||||
$data['month'] = session('team_user_filter_month');
|
||||
$data['year'] = session('team_user_filter_year');
|
||||
$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();
|
||||
$route = '';
|
||||
$ret = view('admin.modal.business_user_detail', compact('TreeCalcBot', 'user', 'data'))->render();
|
||||
}
|
||||
|
||||
if ($data['action'] === 'business-user-show') {
|
||||
$user = User::find($data['id']);
|
||||
if ($user && $user->account) {
|
||||
$route = "";
|
||||
$ret = view("admin.modal.business_user_show", compact('user', 'data'))->render();
|
||||
$user = User::with(['account', 'account.country', 'account.shipping_country', 'user_level', 'user_sponsor.account'])->find($data['id']);
|
||||
\Log::info('business-user-show', ['user' => $user]);
|
||||
if ($user) {
|
||||
$route = '';
|
||||
$ret = view('admin.modal.business_user_show', compact('user', 'data'))->render();
|
||||
} else {
|
||||
$ret = view('admin.modal.business_user_notfound', compact('data'))->render();
|
||||
}
|
||||
$ret = view("admin.modal.business_user_notfound", compact('data'))->render();
|
||||
}
|
||||
if ($data['action'] === 'edit_user_sales_volume') {
|
||||
$userSalesVolume = UserSalesVolume::findOrFail($data['id']);
|
||||
$route = route('admin_business_points_store',);
|
||||
$ret = view("admin.business.modal_edit_points", compact('userSalesVolume', 'data', 'route'))->render();
|
||||
$route = route('admin_business_points_store');
|
||||
$ret = view('admin.business.modal_edit_points', compact('userSalesVolume', 'data', 'route'))->render();
|
||||
}
|
||||
if ($data['action'] === 'add_user_sales_volume') {
|
||||
$userSalesVolume = new UserSalesVolume();
|
||||
$route = route('admin_business_points_store',);
|
||||
$ret = view("admin.business.modal_add_points", compact('userSalesVolume', 'data', 'route'))->render();
|
||||
$userSalesVolume = new UserSalesVolume;
|
||||
$route = route('admin_business_points_store');
|
||||
$ret = view('admin.business.modal_add_points', compact('userSalesVolume', 'data', 'route'))->render();
|
||||
}
|
||||
if ($data['action'] === 'add-user-credit') {
|
||||
$value = [];
|
||||
$ret = view("admin.payment.modal_add_credit", compact('value', 'data'))->render();
|
||||
$ret = view('admin.payment.modal_add_credit', compact('value', 'data'))->render();
|
||||
}
|
||||
if ($data['action'] === 'user-credit-status') {
|
||||
$UserCredit = UserCredit::find($data['id']); //current user form order
|
||||
$ret = view("admin.payment.modal_credit_status", compact('UserCredit', 'data'))->render();
|
||||
$UserCredit = UserCredit::find($data['id']); // current user form order
|
||||
$ret = view('admin.payment.modal_credit_status', compact('UserCredit', 'data'))->render();
|
||||
}
|
||||
if ($data['action'] === 'abo_update_settings') {
|
||||
$user_abo = UserAbo::find($data['id']);
|
||||
|
|
@ -165,11 +164,11 @@ class ModalController extends Controller
|
|||
} else {
|
||||
$route = route('user_abos_update', [$data['view'], $user_abo->id]);
|
||||
}
|
||||
$ret = view("admin.abo.modal_abo_update", compact('user_abo', 'data', 'route'))->render();
|
||||
$ret = view('admin.abo.modal_abo_update', compact('user_abo', 'data', 'route'))->render();
|
||||
}
|
||||
if ($data['action'] === 'abo-add-product') {
|
||||
$user_abo = UserAbo::find($data['id']);
|
||||
$ret = view("user.abo.modal_abo_show_products", compact('data', 'user_abo'))->render();
|
||||
$ret = view('user.abo.modal_abo_show_products', compact('data', 'user_abo'))->render();
|
||||
}
|
||||
|
||||
if ($data['action'] === 'create-dhl-shipment') {
|
||||
|
|
@ -177,54 +176,57 @@ class ModalController extends Controller
|
|||
$ret = $this->handleDhlShipmentModal($id, $data);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json(['response' => $data, 'html' => $ret, 'status' => $status]);
|
||||
}
|
||||
|
||||
private function getForBusinessUserDetail(User $user, $data)
|
||||
{
|
||||
|
||||
//$auth_user = \Auth::user();
|
||||
//if($auth_user->isAdmin() || $auth_user->id === $user->id){
|
||||
// $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, $data['live']);
|
||||
//TODO is not Admin, read is user in Parent tree ...
|
||||
if (!$TreeCalcBot->business_user) {
|
||||
// TODO is not Admin, read is user in Parent tree ...
|
||||
if (! $TreeCalcBot->business_user) {
|
||||
abort(403, 'no user found');
|
||||
}
|
||||
|
||||
return $TreeCalcBot;
|
||||
//}
|
||||
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle DHL shipment modal preparation
|
||||
*
|
||||
* @param mixed $id Order ID or 'new'
|
||||
* @param array $data Request data
|
||||
*
|
||||
* @param mixed $id Order ID or 'new'
|
||||
* @param array $data Request data
|
||||
* @return string Rendered view
|
||||
*/
|
||||
private function handleDhlShipmentModal($id, array $data): string
|
||||
{
|
||||
try {
|
||||
$dhlModalService = new DhlModalService();
|
||||
$dhlModalService = new DhlModalService;
|
||||
$modalData = $dhlModalService->prepareModalData($id, $data);
|
||||
|
||||
// Merge the prepared data with the original request data
|
||||
$viewData = array_merge($data, $modalData, [
|
||||
'id' => $id,
|
||||
'data' => $data
|
||||
'data' => $data,
|
||||
]);
|
||||
|
||||
return view("admin.dhl.modal_create_shipment", $viewData)->render();
|
||||
return view('admin.dhl.modal_create_shipment', $viewData)->render();
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('[ModalController] Error in DHL shipment modal', [
|
||||
'order_id' => $id,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
'trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
|
||||
// Return error view or fallback
|
||||
|
|
@ -239,17 +241,15 @@ class ModalController extends Controller
|
|||
'V01PAK' => 'DHL Paket (National)',
|
||||
'V53WPAK' => 'DHL Paket International',
|
||||
],
|
||||
'errors' => ['Fehler beim Laden der Daten: ' . $e->getMessage()],
|
||||
'warnings' => []
|
||||
'errors' => ['Fehler beim Laden der Daten: '.$e->getMessage()],
|
||||
'warnings' => [],
|
||||
];
|
||||
|
||||
return view("admin.dhl.modal_create_shipment", $errorData)->render();
|
||||
return view('admin.dhl.modal_create_shipment', $errorData)->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* <button type="button" class="btn btn-sm btn-primary" data-toggle="modal"
|
||||
data-target="#modals-load-content"
|
||||
data-id="{{ $value->id }}"
|
||||
|
|
@ -257,4 +257,4 @@ class ModalController extends Controller
|
|||
data-action="modal-email-template"
|
||||
data-url=""
|
||||
data-redirect="back"
|
||||
data-route="{{ route('modal_load') }}"><span class="fa fa-edit"></span></button>*/
|
||||
data-route="{{ route('modal_load') }}"><span class="fa fa-edit"></span></button>*/
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ fnc Financing
|
|||
'pref' => 'Vorauskasse',
|
||||
];*/
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Pay;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
|
|
@ -31,36 +30,39 @@ use App\Services\MyLog;
|
|||
use App\Services\Payone;
|
||||
use Util;
|
||||
|
||||
|
||||
class PayoneController extends Controller
|
||||
{
|
||||
|
||||
const PREAUTHORIZATION = 'preauthorization';
|
||||
|
||||
const AUTHORIZATION = 'authorization';
|
||||
|
||||
const CAPTURE = 'capture';
|
||||
|
||||
const REFUND = 'refund';
|
||||
|
||||
const DEBIT = 'debit';
|
||||
|
||||
private $default = [];
|
||||
|
||||
private $personalData = [];
|
||||
|
||||
private $aboInitPayment = [];
|
||||
|
||||
private $method = [];
|
||||
|
||||
private $prepayment = [];
|
||||
|
||||
/* private $onlineTransfer = [];
|
||||
private $creditCard = []; */
|
||||
private $deliveryData = [];
|
||||
|
||||
|
||||
|
||||
|
||||
// private $payment_method;
|
||||
private $urls = [];
|
||||
|
||||
private $shopping_user;
|
||||
|
||||
private $shopping_order;
|
||||
|
||||
private $shopping_payment;
|
||||
|
||||
private $reference;
|
||||
|
|
@ -82,40 +84,40 @@ class PayoneController extends Controller
|
|||
{
|
||||
return $this->shopping_payment;
|
||||
}
|
||||
|
||||
public function setAboPayment($user_abo, $amount, $currency)
|
||||
{
|
||||
$this->reference = substr(uniqid('m', false), 0, 16);
|
||||
|
||||
$amount = intval($amount);
|
||||
$this->method = [
|
||||
"clearingtype" => $user_abo->clearingtype,
|
||||
"wallettype" => $user_abo->wallettype,
|
||||
"pseudocardpan" => isset($user_abo->carddata['pseudocardpan']) ? $user_abo->carddata['pseudocardpan'] : '',
|
||||
"cardexpiredate" => isset($user_abo->carddata['cardexpiredate']) ? $user_abo->carddata['cardexpiredate'] : '',
|
||||
'clearingtype' => $user_abo->clearingtype,
|
||||
'wallettype' => $user_abo->wallettype,
|
||||
'pseudocardpan' => isset($user_abo->carddata['pseudocardpan']) ? $user_abo->carddata['pseudocardpan'] : '',
|
||||
'cardexpiredate' => isset($user_abo->carddata['cardexpiredate']) ? $user_abo->carddata['cardexpiredate'] : '',
|
||||
'userid' => $user_abo->payone_userid,
|
||||
'onlinebanktransfertype' => '',
|
||||
"request" => "authorization",
|
||||
'request' => 'authorization',
|
||||
];
|
||||
|
||||
|
||||
$this->aboInitPayment = [
|
||||
'recurrence' => 'recurring',
|
||||
'customer_is_present' => 'no',
|
||||
'request' => 'authorization',
|
||||
'amount' => $amount
|
||||
'amount' => $amount,
|
||||
];
|
||||
|
||||
$this->prepayment = [
|
||||
"reference" => $this->reference, // a unique reference, e.g. order number
|
||||
"amount" => $amount, // amount in smallest currency unit, i.e. cents
|
||||
"currency" => $currency,
|
||||
"param" => $this->shopping_order->id,
|
||||
'reference' => $this->reference, // a unique reference, e.g. order number
|
||||
'amount' => $amount, // amount in smallest currency unit, i.e. cents
|
||||
'currency' => $currency,
|
||||
'param' => $this->shopping_order->id,
|
||||
];
|
||||
|
||||
$this->shopping_payment = ShoppingPayment::create([
|
||||
'shopping_order_id' => $this->shopping_order->id,
|
||||
'clearingtype' => $this->method["clearingtype"],
|
||||
'wallettype' => $this->method["wallettype"],
|
||||
'onlinebanktransfertype' => $this->method["onlinebanktransfertype"],
|
||||
'clearingtype' => $this->method['clearingtype'],
|
||||
'wallettype' => $this->method['wallettype'],
|
||||
'onlinebanktransfertype' => $this->method['onlinebanktransfertype'],
|
||||
'carddata' => $user_abo->carddata,
|
||||
'reference' => $this->reference,
|
||||
'amount' => $amount,
|
||||
|
|
@ -125,9 +127,11 @@ class PayoneController extends Controller
|
|||
'mode' => $this->shopping_order->mode,
|
||||
]);
|
||||
}
|
||||
//make Payone payment
|
||||
|
||||
// make Payone payment
|
||||
public function setPrePayment($payment_method, $amount, $currency, $ret = [])
|
||||
{
|
||||
$amount = intval($amount);
|
||||
|
||||
$this->reference = substr(uniqid('m', false), 0, 16);
|
||||
$this->setMethod($payment_method, $ret);
|
||||
|
|
@ -139,30 +143,30 @@ class PayoneController extends Controller
|
|||
];
|
||||
|
||||
$this->prepayment = [
|
||||
"reference" => $this->reference, // a unique reference, e.g. order number
|
||||
"amount" => $amount, // amount in smallest currency unit, i.e. cents
|
||||
"currency" => $currency,
|
||||
"param" => $this->shopping_order->id,
|
||||
'reference' => $this->reference, // a unique reference, e.g. order number
|
||||
'amount' => $amount, // amount in smallest currency unit, i.e. cents
|
||||
'currency' => $currency,
|
||||
'param' => $this->shopping_order->id,
|
||||
];
|
||||
//init Abo
|
||||
// init Abo
|
||||
if ($this->shopping_order->is_abo) {
|
||||
if ($this->method["clearingtype"] === "cc") {
|
||||
if ($this->method['clearingtype'] === 'cc') {
|
||||
$this->aboInitPayment = [
|
||||
'recurrence' => 'recurring',
|
||||
'customer_is_present' => 'yes',
|
||||
'request' => 'authorization',
|
||||
'amount' => $amount,
|
||||
'amount' => $amount,
|
||||
];
|
||||
$this->method['request'] = 'authorization';
|
||||
}
|
||||
|
||||
if ($this->method["clearingtype"] === "wlt") {
|
||||
//payment for Abo PayPal
|
||||
if ($this->method['clearingtype'] === 'wlt') {
|
||||
// payment for Abo PayPal
|
||||
$this->aboInitPayment = [
|
||||
'recurrence' => 'recurring',
|
||||
'customer_is_present' => 'yes',
|
||||
'request' => 'authorization',
|
||||
'amount' => $amount,
|
||||
'amount' => $amount,
|
||||
'add_paydata[redirection_mode]' => 'DIRECT_TO_MERCHANT',
|
||||
];
|
||||
$this->setDeliverylData($this->shopping_user);
|
||||
|
|
@ -172,9 +176,9 @@ class PayoneController extends Controller
|
|||
|
||||
$this->shopping_payment = ShoppingPayment::create([
|
||||
'shopping_order_id' => $this->shopping_order->id,
|
||||
'clearingtype' => $this->method["clearingtype"],
|
||||
'wallettype' => $this->method["wallettype"],
|
||||
'onlinebanktransfertype' => $this->method["onlinebanktransfertype"],
|
||||
'clearingtype' => $this->method['clearingtype'],
|
||||
'wallettype' => $this->method['wallettype'],
|
||||
'onlinebanktransfertype' => $this->method['onlinebanktransfertype'],
|
||||
'carddata' => isset($ret['cc']) ? $ret['cc'] : null,
|
||||
'reference' => $this->reference,
|
||||
'amount' => $amount,
|
||||
|
|
@ -186,21 +190,22 @@ class PayoneController extends Controller
|
|||
]);
|
||||
|
||||
$this->default['mode'] = $this->shopping_order->mode;
|
||||
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
public function setPersonalData()
|
||||
{
|
||||
$this->personalData = [
|
||||
"firstname" => $this->shopping_user->billing_firstname,
|
||||
"lastname" => $this->shopping_user->billing_lastname, // mandatory
|
||||
"street" => $this->shopping_user->billing_address,
|
||||
"zip" => $this->shopping_user->billing_zipcode,
|
||||
"city" => $this->shopping_user->billing_city,
|
||||
"country" => ($this->shopping_user->billing_country) ? $this->shopping_user->billing_country->code : "DE", // mandatory
|
||||
"email" => $this->shopping_user->billing_email,
|
||||
'firstname' => $this->shopping_user->billing_firstname,
|
||||
'lastname' => $this->shopping_user->billing_lastname, // mandatory
|
||||
'street' => $this->shopping_user->billing_address,
|
||||
'zip' => $this->shopping_user->billing_zipcode,
|
||||
'city' => $this->shopping_user->billing_city,
|
||||
'country' => ($this->shopping_user->billing_country) ? $this->shopping_user->billing_country->code : 'DE', // mandatory
|
||||
'email' => $this->shopping_user->billing_email,
|
||||
// "language" => ($this->shopping_user->billing_country) ? strtoupper($this->shopping_user->billing_country->code) : "DE", // mandatory
|
||||
"language" => "DE",
|
||||
'language' => 'DE',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -222,38 +227,38 @@ class PayoneController extends Controller
|
|||
if ($payment_method) {
|
||||
if (strpos($payment_method, '#')) {
|
||||
$payment_method = explode('#', $payment_method);
|
||||
//wallet Paypal
|
||||
// wallet Paypal
|
||||
if ($payment_method[0] === 'wlt') {
|
||||
$this->method = [
|
||||
"clearingtype" => "wlt",
|
||||
"wallettype" => $payment_method[1],
|
||||
'onlinebanktransfertype' => "",
|
||||
"request" => "authorization"
|
||||
'clearingtype' => 'wlt',
|
||||
'wallettype' => $payment_method[1],
|
||||
'onlinebanktransfertype' => '',
|
||||
'request' => 'authorization',
|
||||
];
|
||||
}
|
||||
//Online-Überweisung
|
||||
// Online-Überweisung
|
||||
if ($payment_method[0] === 'sb') {
|
||||
$this->method = [
|
||||
"clearingtype" => "sb",
|
||||
"wallettype" => "",
|
||||
"onlinebanktransfertype" => $payment_method[1], // this is the type for Sofort.com
|
||||
"bankcountry" => "DE", // we need to know the country of the customer's bank, i.e. of the invoice address
|
||||
"request" => "authorization",
|
||||
'clearingtype' => 'sb',
|
||||
'wallettype' => '',
|
||||
'onlinebanktransfertype' => $payment_method[1], // this is the type for Sofort.com
|
||||
'bankcountry' => 'DE', // we need to know the country of the customer's bank, i.e. of the invoice address
|
||||
'request' => 'authorization',
|
||||
];
|
||||
}
|
||||
|
||||
//Rechnungskauf
|
||||
// Rechnungskauf
|
||||
if ($payment_method[0] === 'fnc') {
|
||||
//MIVITA
|
||||
// MIVITA
|
||||
if (isset($payment_method[1]) && $payment_method[1] === 'MIV') {
|
||||
$this->method = [
|
||||
"clearingtype" => "fnc",
|
||||
"wallettype" => "",
|
||||
'onlinebanktransfertype' => "MIV",
|
||||
"request" => "authorization",
|
||||
'clearingtype' => 'fnc',
|
||||
'wallettype' => '',
|
||||
'onlinebanktransfertype' => 'MIV',
|
||||
'request' => 'authorization',
|
||||
];
|
||||
}
|
||||
//PAYONE
|
||||
// PAYONE
|
||||
/* $this->method = [
|
||||
"clearingtype" => "fnc",
|
||||
"wallettype" => "",
|
||||
|
|
@ -265,41 +270,41 @@ class PayoneController extends Controller
|
|||
];*/
|
||||
}
|
||||
}
|
||||
//vorkasse
|
||||
// vorkasse
|
||||
if ($payment_method === 'elv') {
|
||||
$this->method = [
|
||||
"clearingtype" => "elv",
|
||||
"wallettype" => "",
|
||||
'onlinebanktransfertype' => "",
|
||||
"request" => "authorization",
|
||||
"mandate_identification" => $ret['elv']['mandate_identification'],
|
||||
"iban" => $ret['elv']['iban'],
|
||||
"bic" => $ret['elv']['bic'],
|
||||
"bankaccountholder" => $ret['elv']['bankaccountholder'],
|
||||
'clearingtype' => 'elv',
|
||||
'wallettype' => '',
|
||||
'onlinebanktransfertype' => '',
|
||||
'request' => 'authorization',
|
||||
'mandate_identification' => $ret['elv']['mandate_identification'],
|
||||
'iban' => $ret['elv']['iban'],
|
||||
'bic' => $ret['elv']['bic'],
|
||||
'bankaccountholder' => $ret['elv']['bankaccountholder'],
|
||||
// "bankcountry" => "DE",
|
||||
];
|
||||
}
|
||||
|
||||
//vorkasse
|
||||
// vorkasse
|
||||
if ($payment_method === 'vor') {
|
||||
$this->method = [
|
||||
"clearingtype" => "vor",
|
||||
"wallettype" => "",
|
||||
'onlinebanktransfertype' => "",
|
||||
"request" => "authorization",
|
||||
'clearingtype' => 'vor',
|
||||
'wallettype' => '',
|
||||
'onlinebanktransfertype' => '',
|
||||
'request' => 'authorization',
|
||||
];
|
||||
}
|
||||
|
||||
//CreditCard
|
||||
// CreditCard
|
||||
if ($payment_method === 'cc') {
|
||||
//need the $cc_ret
|
||||
// need the $cc_ret
|
||||
$this->method = [
|
||||
"clearingtype" => "cc",
|
||||
"wallettype" => "",
|
||||
'onlinebanktransfertype' => "",
|
||||
"request" => "authorization",
|
||||
"pseudocardpan" => $ret['cc']['pseudocardpan'],
|
||||
//"xid" => "3-D Secure transaction ID"
|
||||
'clearingtype' => 'cc',
|
||||
'wallettype' => '',
|
||||
'onlinebanktransfertype' => '',
|
||||
'request' => 'authorization',
|
||||
'pseudocardpan' => $ret['cc']['pseudocardpan'],
|
||||
// "xid" => "3-D Secure transaction ID"
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -309,6 +314,7 @@ class PayoneController extends Controller
|
|||
{
|
||||
$request = array_merge($this->default, $this->personalData, $this->deliveryData, $this->method, $this->prepayment, $this->aboInitPayment, $this->urls);
|
||||
$response = Payone::sendRequest($request);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
|
@ -316,11 +322,10 @@ class PayoneController extends Controller
|
|||
{
|
||||
|
||||
$request = array_merge($this->default, $this->personalData, $this->deliveryData, $this->method, $this->prepayment, $this->aboInitPayment, $this->urls);
|
||||
//RECHNUNG MIV
|
||||
if ($this->shopping_payment->clearingtype === 'fnc' && $this->shopping_payment->onlinebanktransfertype === 'MIV') {
|
||||
$payt = PaymentTransaction::create([
|
||||
'shopping_payment_id' => $this->shopping_payment->id,
|
||||
'request' => $this->method['request'],
|
||||
'request' => $this->method['request'],
|
||||
'txid' => 0,
|
||||
'userid' => 0,
|
||||
'status' => 'FNCMIV',
|
||||
|
|
@ -332,6 +337,7 @@ class PayoneController extends Controller
|
|||
if ($is_abo) {
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
return redirect(route('checkout.transaction_approved', [$payt->id, $this->reference]));
|
||||
exit;
|
||||
}
|
||||
|
|
@ -343,7 +349,7 @@ class PayoneController extends Controller
|
|||
MyLog::writeLog(
|
||||
'payone',
|
||||
'error',
|
||||
'PayPal Preauthorization Fehler: ' . $response['errormessage'],
|
||||
'PayPal Preauthorization Fehler: '.$response['errormessage'],
|
||||
$response
|
||||
);
|
||||
PaymentTransaction::create([
|
||||
|
|
@ -352,6 +358,7 @@ class PayoneController extends Controller
|
|||
'errorcode' => $response['errorcode'],
|
||||
'errormessage' => $response['errormessage'],
|
||||
'customermessage' => $response['customermessage'],
|
||||
'transmitted_data' => $request,
|
||||
'status' => $response['status'],
|
||||
'mode' => $this->shopping_payment->mode,
|
||||
]);
|
||||
|
|
@ -361,10 +368,10 @@ class PayoneController extends Controller
|
|||
}
|
||||
\Session::flash('errormessage', $response['errormessage']);
|
||||
\Session::flash('customermessage', $response['customermessage']);
|
||||
|
||||
return redirect(route('checkout.checkout_card'));
|
||||
}
|
||||
|
||||
|
||||
if ($response['status'] === 'REDIRECT') {
|
||||
PaymentTransaction::create([
|
||||
'shopping_payment_id' => $this->shopping_payment->id,
|
||||
|
|
@ -379,7 +386,8 @@ class PayoneController extends Controller
|
|||
if ($is_abo) {
|
||||
return $response;
|
||||
}
|
||||
return redirect()->away($response["redirecturl"]);
|
||||
|
||||
return redirect()->away($response['redirecturl']);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
|
@ -387,7 +395,7 @@ class PayoneController extends Controller
|
|||
// header("Location: " . $response["redirecturl"]); // or other redirect method
|
||||
$payt = PaymentTransaction::create([
|
||||
'shopping_payment_id' => $this->shopping_payment->id,
|
||||
'request' => $this->method['request'],
|
||||
'request' => $this->method['request'],
|
||||
'txid' => $response['txid'],
|
||||
'userid' => $response['userid'],
|
||||
'status' => $response['status'],
|
||||
|
|
@ -400,33 +408,32 @@ class PayoneController extends Controller
|
|||
return $response;
|
||||
}
|
||||
|
||||
if ($payt->shopping_payment->clearingtype === "vor") {
|
||||
//vorkasse
|
||||
if ($payt->shopping_payment->clearingtype === 'vor') {
|
||||
// vorkasse
|
||||
return redirect(route('checkout.transaction_approved', [$payt->id, $this->reference]));
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($payt->shopping_payment->clearingtype === "cc") {
|
||||
//creditcard
|
||||
if ($payt->shopping_payment->clearingtype === 'cc') {
|
||||
// creditcard
|
||||
return redirect(route('checkout.transaction_approved', [$payt->id, $this->reference]));
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($payt->shopping_payment->clearingtype === "elv") {
|
||||
//sepa
|
||||
if ($payt->shopping_payment->clearingtype === 'elv') {
|
||||
// sepa
|
||||
return redirect(route('checkout.transaction_approved', [$payt->id, $this->reference]));
|
||||
exit;
|
||||
}
|
||||
|
||||
var_dump($response);
|
||||
die();
|
||||
//txid
|
||||
//Payment process ID (PAYONE)
|
||||
//userid
|
||||
//Debtor ID (PAYONE)
|
||||
exit();
|
||||
// txid
|
||||
// Payment process ID (PAYONE)
|
||||
// userid
|
||||
// Debtor ID (PAYONE)
|
||||
}
|
||||
|
||||
|
||||
if ($response['status'] === 'PENDING') {
|
||||
MyLog::writeLog(
|
||||
'payone',
|
||||
|
|
@ -434,11 +441,11 @@ class PayoneController extends Controller
|
|||
'Error:1000 Status PENDING App\Http\Controllers\Pay\PayoneController::ResponseData response status PENDING',
|
||||
$response
|
||||
);
|
||||
die();
|
||||
//txid
|
||||
//Payment process ID (PAYONE)
|
||||
//userid
|
||||
//Debtor ID (PAYONE)
|
||||
exit();
|
||||
// txid
|
||||
// Payment process ID (PAYONE)
|
||||
// userid
|
||||
// Debtor ID (PAYONE)
|
||||
}
|
||||
MyLog::writeLog(
|
||||
'payone',
|
||||
|
|
@ -449,22 +456,20 @@ class PayoneController extends Controller
|
|||
abort(403, 'Der Zahlungsanbieter ist nicht erreichbar, die Zahlung konnte nicht durchgeführt werden. Bitte versuchen Sie es später erneut. Fehlercode: 1001');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function checkCreditCard($data)
|
||||
{
|
||||
$this->prepayment = [
|
||||
"request" => "creditcardcheck", // create account receivable and instantly book the amount
|
||||
"cardholder" => $data['cc_cardholder_first'] . " " . $data['cc_cardholder_last'],
|
||||
"cardpan" => $data['cc_cardpan'],
|
||||
"cardexpiredate" => substr($data['cc_cardexpireyear'], -2) . $data['cc_cardexpiremonth'],
|
||||
"cardtype" => $data['cc_cardtype'],
|
||||
"cardcvc2" => $data['cc_cardcvc2'],
|
||||
"storecarddata" => 'yes',
|
||||
"language" => 'de',
|
||||
'request' => 'creditcardcheck', // create account receivable and instantly book the amount
|
||||
'cardholder' => $data['cc_cardholder_first'].' '.$data['cc_cardholder_last'],
|
||||
'cardpan' => $data['cc_cardpan'],
|
||||
'cardexpiredate' => substr($data['cc_cardexpireyear'], -2).$data['cc_cardexpiremonth'],
|
||||
'cardtype' => $data['cc_cardtype'],
|
||||
'cardcvc2' => $data['cc_cardcvc2'],
|
||||
'storecarddata' => 'yes',
|
||||
'language' => 'de',
|
||||
];
|
||||
$request = array_merge($this->default, $this->prepayment);
|
||||
|
||||
return Payone::sendRequest($request);
|
||||
}
|
||||
|
||||
|
|
@ -474,18 +479,19 @@ class PayoneController extends Controller
|
|||
$this->setPersonalData();
|
||||
|
||||
$this->prepayment = [
|
||||
"clearingtype" => "elv",
|
||||
"amount" => $amount, // amount in smallest currency unit, i.e. cents
|
||||
"currency" => $currency,
|
||||
"request" => "managemandate", // create account receivable and instantly book the amount
|
||||
"bankaccountholder" => $data['elv_bankaccountholder'],
|
||||
"iban" => $data['elv_iban'],
|
||||
"bic" => $data['elv_bic'],
|
||||
'clearingtype' => 'elv',
|
||||
'amount' => $amount, // amount in smallest currency unit, i.e. cents
|
||||
'currency' => $currency,
|
||||
'request' => 'managemandate', // create account receivable and instantly book the amount
|
||||
'bankaccountholder' => $data['elv_bankaccountholder'],
|
||||
'iban' => $data['elv_iban'],
|
||||
'bic' => $data['elv_bic'],
|
||||
|
||||
// "language" => 'de',
|
||||
];
|
||||
|
||||
$request = array_merge($this->default, $this->personalData, $this->deliveryData, $this->method, $this->prepayment, $this->urls);
|
||||
|
||||
return Payone::sendRequest($request);
|
||||
}
|
||||
|
||||
|
|
@ -524,9 +530,6 @@ class PayoneController extends Controller
|
|||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/* public function checkStatus(){
|
||||
// again, the default values will be needed
|
||||
$capture = array(
|
||||
|
|
@ -541,9 +544,8 @@ class PayoneController extends Controller
|
|||
|
||||
} */
|
||||
|
||||
|
||||
//set for clearingtype
|
||||
//debit payment
|
||||
// set for clearingtype
|
||||
// debit payment
|
||||
/*
|
||||
*
|
||||
*
|
||||
|
|
@ -596,6 +598,6 @@ class PayoneController extends Controller
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,20 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\UserCredit;
|
||||
use App\Models\UserCreditItem;
|
||||
use App\Repositories\CreditRepository;
|
||||
use App\Services\Credit;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Services\Payment;
|
||||
use App\Services\Util;
|
||||
use App\User;
|
||||
use Carbon;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Services\Util;
|
||||
use App\Services\Credit;
|
||||
use App\Services\Payment;
|
||||
use App\Models\UserCredit;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Models\UserCreditItem;
|
||||
use App\Models\UserCreditMargin;
|
||||
use Illuminate\Support\Collection;
|
||||
use App\Models\ShoppingOrderMargin;
|
||||
|
||||
use App\Repositories\CreditRepository;
|
||||
use App\Models\Models\UserCreditMargin as ModelsUserCreditMargin;
|
||||
use App\Models\UserAccount;
|
||||
use stdClass;
|
||||
|
||||
class PaymentCreditController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
|
|
@ -37,31 +28,34 @@ class PaymentCreditController extends Controller
|
|||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
'user_credit_items' => $this->makeUserCreditItems(),
|
||||
];
|
||||
|
||||
return view('admin.payment.credit', $data);
|
||||
}
|
||||
|
||||
|
||||
public function store()
|
||||
{
|
||||
$data = Request::all();
|
||||
if (isset($data['action']) && $data['action'] === 'add-user-credit') {
|
||||
if (!isset($data['member_id']) || !$user = User::find($data['member_id'])) {
|
||||
if (! isset($data['member_id']) || ! $user = User::find($data['member_id'])) {
|
||||
\Session()->flash('alert-error', 'Vertriebspartner nicht gefunden');
|
||||
|
||||
return back();
|
||||
}
|
||||
if (!isset($data['credit'])) {
|
||||
if (! isset($data['credit'])) {
|
||||
\Session()->flash('alert-error', 'Bitte Betrag eingeben');
|
||||
|
||||
return back();
|
||||
}
|
||||
if (!isset($data['message'])) {
|
||||
if (! isset($data['message'])) {
|
||||
\Session()->flash('alert-error', 'Bitte Betreff eingeben');
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
$credit = Util::reFormatNumber($data['credit']);
|
||||
$credit = number_format($credit, 2, '.', '');
|
||||
Payment::addUserCreditMargin($user, $credit, 3, $data['message']);
|
||||
\Session()->flash('alert-success', "Guthaben hinzugefügt");
|
||||
\Session()->flash('alert-success', 'Guthaben hinzugefügt');
|
||||
}
|
||||
|
||||
return redirect(route('admin_payments_credit'));
|
||||
|
|
@ -72,20 +66,22 @@ class PaymentCreditController extends Controller
|
|||
$data = Request::all();
|
||||
if (isset($data['action'])) {
|
||||
if ($data['action'] === 'create_credit') {
|
||||
if (!isset($data['userid'])) {
|
||||
if (! isset($data['userid'])) {
|
||||
abort(404);
|
||||
}
|
||||
$user = User::findOrFail($data['userid']);
|
||||
$credit_repo = new CreditRepository($user);
|
||||
$credit_repo->create($data);
|
||||
\Session()->flash('alert-success', "Gutschrift erstellt");
|
||||
\Session()->flash('alert-success', 'Gutschrift erstellt');
|
||||
|
||||
return redirect($data['back']);
|
||||
}
|
||||
if ($data['action'] === 'user-credit-status') {
|
||||
$UserCredit = UserCredit::findOrFail($data['id']);
|
||||
$UserCredit->status = $data['status'];
|
||||
$UserCredit->save();
|
||||
\Session()->flash('alert-success', "Status gespeichert");
|
||||
\Session()->flash('alert-success', 'Status gespeichert');
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
|
@ -93,10 +89,10 @@ class PaymentCreditController extends Controller
|
|||
|
||||
private function setFilterVars()
|
||||
{
|
||||
if (!session('credit_filter_month')) {
|
||||
if (! session('credit_filter_month')) {
|
||||
session(['credit_filter_month' => intval(date('m'))]);
|
||||
}
|
||||
if (!session('credit_filter_year')) {
|
||||
if (! session('credit_filter_year')) {
|
||||
session(['credit_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
if (Request::get('credit_filter_name')) {
|
||||
|
|
@ -121,7 +117,7 @@ class PaymentCreditController extends Controller
|
|||
$ret[$userCreditItem->user_id]['sum'] += $userCreditItem->credit;
|
||||
$ret[$userCreditItem->user_id]['entries'][$userCreditItem->id] = $userCreditItem;
|
||||
} else {
|
||||
if (!isset($userCreditItem->user)) {
|
||||
if (! isset($userCreditItem->user)) {
|
||||
/* gelöschte User nicht anzeigen
|
||||
$user = User::withTrashed()->with(['account' => fn($q) => $q->withTrashed()])->where('id', $userCreditItem->user_id)->first();
|
||||
$ret[$userCreditItem->user_id] = [
|
||||
|
|
@ -147,6 +143,7 @@ class PaymentCreditController extends Controller
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
|
@ -157,11 +154,12 @@ class PaymentCreditController extends Controller
|
|||
$UserCreditItem = UserCreditItem::findOrFail($id);
|
||||
if ($deleteTime = $UserCreditItem->deleteTime()) {
|
||||
$UserCreditItem->delete();
|
||||
\Session()->flash('alert-success', "Guthaben ist gelöscht");
|
||||
\Session()->flash('alert-success', 'Guthaben ist gelöscht');
|
||||
} else {
|
||||
\Session()->flash('alert-error', "Guthaben kann nicht gelöscht werden");
|
||||
\Session()->flash('alert-error', 'Guthaben kann nicht gelöscht werden');
|
||||
}
|
||||
}
|
||||
|
||||
return redirect(route('admin_payments_credit'));
|
||||
}
|
||||
|
||||
|
|
@ -170,17 +168,18 @@ class PaymentCreditController extends Controller
|
|||
|
||||
$this->setFilterVars();
|
||||
|
||||
$date_start = Carbon::parse('01.' . Request::get('credit_filter_month') . '.' . Request::get('credit_filter_year'))->format('Y-m-d');
|
||||
$date_end = Carbon::parse('01.' . Request::get('credit_filter_month') . '.' . Request::get('credit_filter_year'))->endOfMonth()->format('Y-m-d');
|
||||
$date_start = Carbon::parse('01.'.Request::get('credit_filter_month').'.'.Request::get('credit_filter_year'))->format('Y-m-d');
|
||||
$date_end = Carbon::parse('01.'.Request::get('credit_filter_month').'.'.Request::get('credit_filter_year'))->endOfMonth()->format('Y-m-d');
|
||||
$query = UserCredit::with('user', 'user.account')->select('user_credits.*')
|
||||
->whereBetween('date', [$date_start, $date_end]);
|
||||
|
||||
if (Request::get('credit_filter_name')) {
|
||||
$query->whereHas('user.account', function ($query) {
|
||||
return $query->where('first_name', 'LIKE', '%' . Request::get('credit_filter_name') . '%')
|
||||
->orWhere('last_name', 'LIKE', '%' . Request::get('credit_filter_name') . '%');
|
||||
return $query->where('first_name', 'LIKE', '%'.Request::get('credit_filter_name').'%')
|
||||
->orWhere('last_name', 'LIKE', '%'.Request::get('credit_filter_name').'%');
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
|
@ -192,64 +191,75 @@ class PaymentCreditController extends Controller
|
|||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('user.account.first_name', function (UserCredit $UserCredit) {
|
||||
return isset($UserCredit->user->account) ? $UserCredit->user->account->first_name : "gelöscht";
|
||||
return isset($UserCredit->user->account) ? $UserCredit->user->account->first_name : 'gelöscht';
|
||||
})
|
||||
->addColumn('user.account.last_name', function (UserCredit $UserCredit) {
|
||||
return isset($UserCredit->user->account) ? $UserCredit->user->account->last_name : "gelöscht";
|
||||
return isset($UserCredit->user->account) ? $UserCredit->user->account->last_name : 'gelöscht';
|
||||
})
|
||||
->addColumn('user.email', function (UserCredit $UserCredit) {
|
||||
return isset($UserCredit->user) ? $UserCredit->user->email : "gelöscht";
|
||||
return isset($UserCredit->user) ? $UserCredit->user->email : 'gelöscht';
|
||||
})
|
||||
->addColumn('view', function (UserCredit $UserCredit) {
|
||||
$ret = "";
|
||||
$ret = '';
|
||||
if ($UserCredit->isCredit()) {
|
||||
$ret .= '<a href="' . route('storage_file', [$UserCredit->id, 'credit', 'download']) . '" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a> ';
|
||||
$ret .= '<a href="' . route('storage_file', [$UserCredit->id, 'credit', 'stream']) . '" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a><br>';
|
||||
// Deutsches Original (ausgefüllter Button)
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'download']).'" class="btn btn-primary btn-xs mb-2 mr-1" title="Gutschrift DE"><i class="fa fa-download"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'stream']).'" target="_blank" class="btn btn-warning btn-xs mb-2 mr-1" title="Vorschau DE"><i class="fa fa-eye"></i></a>';
|
||||
|
||||
$ret .= '<a href="' . route('storage_file', [$UserCredit->id, 'credit_detail', 'html']) . '" target="_blank" class="btn btn-secondary btn-xs mt-2"><i class="fa fa-eye"></i></a> ';
|
||||
$ret .= '<a href="' . route('storage_file', [$UserCredit->id, 'credit_detail', 'pdf']) . '" target="_blank" class="btn btn-secondary btn-xs mt-2"><i class="fa fa-file-pdf" style="min-width:13.5px"></i></a> ';
|
||||
// Lokalisierte Versionen (outline Buttons)
|
||||
$availableLocales = $UserCredit->getAvailableLocales();
|
||||
foreach ($availableLocales as $locale) {
|
||||
$ret .= ' <a href="'.route('storage_file', [$UserCredit->id, 'credit', 'download', $locale]).'" class="btn btn-outline-primary btn-xs mb-2 mr-1" title="Gutschrift '.strtoupper($locale).'"><i class="fa fa-download"></i> '.strtoupper($locale).'</a>';
|
||||
$ret .= ' <a href="'.route('storage_file', [$UserCredit->id, 'credit', 'stream', $locale]).'" class="btn btn-outline-warning btn-xs mb-2 mr-1" title="Gutschrift '.strtoupper($locale).'"><i class="fa fa-eye"></i> '.strtoupper($locale).'</a>';
|
||||
}
|
||||
$ret .= '<br>';
|
||||
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'html']).'" target="_blank" class="btn btn-secondary btn-xs mb-2 mr-1"><i class="fa fa-eye"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'pdf']).'" target="_blank" class="btn btn-secondary btn-xs mb-2 mr-1"><i class="fa fa-file-pdf" style="min-width:13.5px"></i></a> ';
|
||||
} else {
|
||||
$ret = "-";
|
||||
$ret = '-';
|
||||
}
|
||||
|
||||
return $ret;
|
||||
})
|
||||
|
||||
->addColumn('total', function (UserCredit $UserCredit) {
|
||||
return '<span class="no-line-break">' . $UserCredit->getFormattedTotal() . " €</span>";
|
||||
return '<span class="no-line-break">'.$UserCredit->getFormattedTotal().' €</span>';
|
||||
})
|
||||
->addColumn('credits', function (UserCredit $UserCredit) {
|
||||
$ret = "";
|
||||
$ret = '';
|
||||
if ($UserCredit->user_credit_items) {
|
||||
foreach ($UserCredit->user_credit_items as $user_credit_item) {
|
||||
$ret .= nl2br($user_credit_item->getTransMessage()) . " / " . $user_credit_item->created_at->format('d.m.Y') . "<br>";
|
||||
$ret .= nl2br($user_credit_item->getTransMessage()).' / '.$user_credit_item->created_at->format('d.m.Y').'<br>';
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
})
|
||||
->addColumn('status', function (UserCredit $UserCredit) {
|
||||
return '<a href="#" data-toggle="modal" data-target="#modals-load-content" data-modal="modal-lg"
|
||||
data-id="' . $UserCredit->id . '" data-route="' . route('modal_load') . '" data-action="user-credit-status" data-view="">
|
||||
<span class="badge badge-pill badge-' . $UserCredit->getStatusColor() . '">' . $UserCredit->getStatusType() . ' <span class="ion ion-md-cash"></span></span>
|
||||
data-id="'.$UserCredit->id.'" data-route="'.route('modal_load').'" data-action="user-credit-status" data-view="">
|
||||
<span class="badge badge-pill badge-'.$UserCredit->getStatusColor().'">'.$UserCredit->getStatusType().' <span class="ion ion-md-cash"></span></span>
|
||||
</a>';
|
||||
})
|
||||
->filterColumn('user.account.first_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
if ($keyword != '') {
|
||||
$query->whereHas('user.account', function ($query) use ($keyword) {
|
||||
return $query->where('first_name', 'LIKE', '%' . $keyword . '%');
|
||||
return $query->where('first_name', 'LIKE', '%'.$keyword.'%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filterColumn('user.account.last_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
if ($keyword != '') {
|
||||
$query->whereHas('user.account', function ($query) use ($keyword) {
|
||||
return $query->where('last_name', 'LIKE', '%' . $keyword . '%');
|
||||
return $query->where('last_name', 'LIKE', '%'.$keyword.'%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filterColumn('user.email', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
if ($keyword != '') {
|
||||
$query->whereHas('user', function ($query) use ($keyword) {
|
||||
return $query->where('email', 'LIKE', '%' . $keyword . '%');
|
||||
return $query->where('email', 'LIKE', '%'.$keyword.'%');
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,246 +1,277 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use Auth;
|
||||
use Request;
|
||||
use ZipArchive;
|
||||
use App\Models\UserInvoice;
|
||||
|
||||
use App\Models\DatevExport;
|
||||
use App\Models\DatevExportLine;
|
||||
use App\Services\DatevExportService;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Exports\UserTeamExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PaymentTaxAdvisorController extends Controller
|
||||
{
|
||||
|
||||
private $BUKey = [
|
||||
1 => 8120, //für Kunden aus der Schweiz
|
||||
11 => 8125, //Steuerfreie EU-Lieferungen
|
||||
2 => 8300, //Erlöse mit 7 % meistens für Käufe mit Aloe Vera
|
||||
3 => 8400, //Regulär mit 19 %
|
||||
];
|
||||
|
||||
private DatevExportService $datevService;
|
||||
|
||||
private $accountKey = [
|
||||
'A'=>'10000',
|
||||
'B'=>'10100',
|
||||
'C'=>'10200',
|
||||
'D'=>'10300',
|
||||
'E'=>'10400',
|
||||
'F'=>'10500',
|
||||
'G'=>'10600',
|
||||
'H'=>'10700',
|
||||
'I'=>'10800',
|
||||
'J'=>'10900',
|
||||
'K'=>'11000',
|
||||
'L'=>'11100',
|
||||
'M'=>'11200',
|
||||
'N'=>'11300',
|
||||
'O'=>'11400',
|
||||
'P'=>'11500',
|
||||
'Q'=>'11600',
|
||||
'R'=>'11700',
|
||||
'S'=>'11800',
|
||||
'SCH'=>'11900',
|
||||
'T'=>'12000',
|
||||
'U'=>'12100',
|
||||
'V'=>'12200',
|
||||
'W'=>'12300',
|
||||
'X'=>'12400',
|
||||
'Y'=>'12500',
|
||||
'Z'=>'12600'
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
public function __construct(DatevExportService $datevService)
|
||||
{
|
||||
$this->middleware('admin');
|
||||
$this->datevService = $datevService;
|
||||
}
|
||||
|
||||
public function index()
|
||||
/**
|
||||
* Hauptseite: Periodenauswahl + Export-Übersicht
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
||||
$this->setFilterVars();
|
||||
$this->setFilterVars($request);
|
||||
|
||||
$month = intval(session('payment_taxadvisor_filter_month'));
|
||||
$year = intval(session('payment_taxadvisor_filter_year'));
|
||||
|
||||
// Letzter Export für diese Periode
|
||||
$currentExport = DatevExport::forPeriod($month, $year)
|
||||
->generated()
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
// Letzte 10 Exports für die Historie
|
||||
$recentExports = DatevExport::generated()
|
||||
->latest()
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2023),
|
||||
'current_month' => $month,
|
||||
'current_year' => $year,
|
||||
'current_export' => $currentExport,
|
||||
'recent_exports' => $recentExports,
|
||||
];
|
||||
|
||||
return view('admin.payment.taxadvisor', $data);
|
||||
}
|
||||
|
||||
|
||||
public function createZip($filesToZip)
|
||||
/**
|
||||
* AJAX: Vorschau der Daten für die gewählte Periode.
|
||||
*/
|
||||
public function preview(Request $request)
|
||||
{
|
||||
$zip = new ZipArchive;
|
||||
$zipFileName = 'mysample.zip';
|
||||
$path = storage_path().'/app/public/zip/';
|
||||
if ($zip->open($path.$zipFileName, ZipArchive::CREATE) === TRUE) {
|
||||
foreach ($filesToZip as $file) {
|
||||
$zip->addFile($file, basename($file));
|
||||
}
|
||||
$month = intval($request->get('month', session('payment_taxadvisor_filter_month')));
|
||||
$year = intval($request->get('year', session('payment_taxadvisor_filter_year')));
|
||||
|
||||
$zip->close();
|
||||
return response()->download($path.$zipFileName)->deleteFileAfterSend(true);
|
||||
try {
|
||||
$preview = $this->datevService->getPreview($month, $year);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $preview,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Fehler bei der Vorschau: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Export generieren und speichern.
|
||||
*/
|
||||
public function generate(Request $request)
|
||||
{
|
||||
$month = intval($request->get('month', session('payment_taxadvisor_filter_month')));
|
||||
$year = intval($request->get('year', session('payment_taxadvisor_filter_year')));
|
||||
|
||||
try {
|
||||
$export = $this->datevService->generateExport($month, $year);
|
||||
|
||||
return redirect()
|
||||
->route('admin_payments_taxadvisor')
|
||||
->with('success', "DATEV-Export für {$month}/{$year} erfolgreich generiert. {$export->total_lines} Buchungszeilen erstellt.");
|
||||
} catch (\RuntimeException $e) {
|
||||
return redirect()
|
||||
->route('admin_payments_taxadvisor')
|
||||
->with('error', $e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
return redirect()
|
||||
->route('admin_payments_taxadvisor')
|
||||
->with('error', 'Fehler beim Generieren: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CSV-Datei herunterladen.
|
||||
*/
|
||||
public function download($id)
|
||||
{
|
||||
$export = DatevExport::findOrFail($id);
|
||||
|
||||
if (! $export->isGenerated()) {
|
||||
return redirect()
|
||||
->route('admin_payments_taxadvisor')
|
||||
->with('error', 'Export wurde noch nicht generiert.');
|
||||
}
|
||||
|
||||
$disk = config('datev.storage_disk', 'local');
|
||||
$path = $export->file_path;
|
||||
|
||||
if (! Storage::disk($disk)->exists($path)) {
|
||||
// CSV neu generieren falls Datei nicht mehr vorhanden
|
||||
$csvContent = $this->datevService->buildCsv($export);
|
||||
Storage::disk($disk)->makeDirectory($export->getStoragePath());
|
||||
Storage::disk($disk)->put($path, $csvContent);
|
||||
}
|
||||
|
||||
// Status auf "heruntergeladen" setzen
|
||||
$export->markAsDownloaded();
|
||||
|
||||
return Storage::disk($disk)->download($path, $export->filename, [
|
||||
'Content-Type' => 'text/csv; charset=utf-8',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* DataTable: Export-Lines eines bestimmten Exports.
|
||||
*/
|
||||
public function datatable(Request $request)
|
||||
{
|
||||
$exportId = $request->get('export_id');
|
||||
|
||||
$query = DatevExportLine::select('datev_export_lines.*');
|
||||
|
||||
if ($exportId) {
|
||||
$query->where('datev_export_id', $exportId);
|
||||
} else {
|
||||
return "Failed to create the zip file.";
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: Lines des aktuellen Perioden-Exports
|
||||
$month = intval(session('payment_taxadvisor_filter_month', date('m')));
|
||||
$year = intval(session('payment_taxadvisor_filter_year', date('Y')));
|
||||
|
||||
public function download(){
|
||||
$export = DatevExport::forPeriod($month, $year)
|
||||
->generated()
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
|
||||
$query = $this->initSearch();
|
||||
|
||||
$files = [];
|
||||
|
||||
$user_invoices = $query->get();
|
||||
foreach ($user_invoices as $user_invoice) {
|
||||
$filename = $user_invoice->filename;
|
||||
$disk = $user_invoice->disk;
|
||||
$path = $user_invoice->getDownloadPath();
|
||||
if (Storage::disk($disk)->exists($path)) {
|
||||
$file = Storage::disk($disk)->get($path);
|
||||
$pdf_path = storage_path().'/app/public/'.$path;
|
||||
$files[] = $pdf_path;
|
||||
if ($export) {
|
||||
$query->where('datev_export_id', $export->id);
|
||||
} else {
|
||||
$query->where('datev_export_id', 0); // Leere Ergebnismenge
|
||||
}
|
||||
}
|
||||
|
||||
return $this->createZip($files);
|
||||
|
||||
dd("asd");
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->editColumn('line_number', function (DatevExportLine $line) {
|
||||
return $line->line_number;
|
||||
})
|
||||
->addColumn('source_type_label', function (DatevExportLine $line) {
|
||||
return $line->source_type_label;
|
||||
})
|
||||
->addColumn('amount_display', function (DatevExportLine $line) {
|
||||
return '<span class="no-line-break">'.$line->formatted_amount.'</span>';
|
||||
})
|
||||
->editColumn('soll_haben', function (DatevExportLine $line) {
|
||||
$badge = $line->soll_haben === 'H' ? 'success' : 'warning';
|
||||
|
||||
return '<span class="badge badge-'.$badge.'">'.$line->soll_haben.'</span>';
|
||||
})
|
||||
->editColumn('konto', function (DatevExportLine $line) {
|
||||
return $line->konto;
|
||||
})
|
||||
->editColumn('gegenkonto', function (DatevExportLine $line) {
|
||||
return $line->gegenkonto;
|
||||
})
|
||||
->editColumn('bu_schluessel', function (DatevExportLine $line) {
|
||||
return $line->bu_schluessel;
|
||||
})
|
||||
->addColumn('belegdatum_display', function (DatevExportLine $line) {
|
||||
return $line->formatted_belegdatum;
|
||||
})
|
||||
->editColumn('belegfeld1', function (DatevExportLine $line) {
|
||||
return $line->belegfeld1;
|
||||
})
|
||||
->editColumn('buchungstext', function (DatevExportLine $line) {
|
||||
return $line->buchungstext;
|
||||
})
|
||||
->editColumn('eu_ustid', function (DatevExportLine $line) {
|
||||
return $line->eu_ustid ?: '-';
|
||||
})
|
||||
->filterColumn('source_type_label', function ($query, $keyword) {
|
||||
$typeMap = ['rechnung' => 'invoice', 'gutschrift' => 'credit', 'storno' => 'cancellation'];
|
||||
foreach ($typeMap as $label => $type) {
|
||||
if (stripos($label, $keyword) !== false) {
|
||||
$query->where('source_type', $type);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Excel::download(new UserTeamExport($columns, $headers), $filename.'.xls');
|
||||
}
|
||||
$query->where('source_type', 'like', "%{$keyword}%");
|
||||
})
|
||||
->orderColumn('line_number', 'line_number $1')
|
||||
->rawColumns(['amount_display', 'soll_haben'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
private function setFilterVars(){
|
||||
/**
|
||||
* Export sperren (Lock).
|
||||
*/
|
||||
public function lock($id)
|
||||
{
|
||||
$export = DatevExport::findOrFail($id);
|
||||
|
||||
if(!session('payment_taxadvisor_filter_month')){
|
||||
if ($export->isLocked()) {
|
||||
return redirect()
|
||||
->route('admin_payments_taxadvisor')
|
||||
->with('info', 'Export ist bereits gesperrt.');
|
||||
}
|
||||
|
||||
$export->lock();
|
||||
|
||||
return redirect()
|
||||
->route('admin_payments_taxadvisor')
|
||||
->with('success', "Export {$export->period_label} wurde gesperrt.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Export löschen (soft delete).
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$export = DatevExport::findOrFail($id);
|
||||
|
||||
if ($export->isLocked()) {
|
||||
return redirect()
|
||||
->route('admin_payments_taxadvisor')
|
||||
->with('error', 'Gesperrte Exports können nicht gelöscht werden.');
|
||||
}
|
||||
|
||||
$export->delete();
|
||||
|
||||
return redirect()
|
||||
->route('admin_payments_taxadvisor')
|
||||
->with('success', "Export {$export->period_label} wurde gelöscht.");
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Private Hilfsmethoden
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private function setFilterVars(Request $request): void
|
||||
{
|
||||
if (! session('payment_taxadvisor_filter_month')) {
|
||||
session(['payment_taxadvisor_filter_month' => intval(date('m'))]);
|
||||
}
|
||||
if(!session('payment_taxadvisor_filter_year')){
|
||||
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_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')]);
|
||||
if ($request->get('payment_taxadvisor_filter_year')) {
|
||||
session(['payment_taxadvisor_filter_year' => $request->get('payment_taxadvisor_filter_year')]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function initSearch()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$query = UserInvoice::with('shopping_order')->with('shopping_order.shopping_user')->select('user_invoices.*')
|
||||
->where('user_invoices.month', '=', Request::get('payment_taxadvisor_filter_month'))
|
||||
->where('user_invoices.year', '=', Request::get('payment_taxadvisor_filter_year'));
|
||||
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
public function datatable(){
|
||||
|
||||
$query = $this->initSearch();
|
||||
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (UserInvoice $UserInvoice) {
|
||||
return $UserInvoice->id;
|
||||
|
||||
})
|
||||
|
||||
->addColumn('turnover', function (UserInvoice $UserInvoice) {
|
||||
return '<span class="no-line-break">'.$UserInvoice->shopping_order->getFormattedTotalShipping()." €</span>";
|
||||
})
|
||||
->addColumn('debit_credit_indicator', function (UserInvoice $UserInvoice) {
|
||||
return "H";
|
||||
})
|
||||
->addColumn('account', function (UserInvoice $UserInvoice) {
|
||||
if($UserInvoice->shopping_order && $UserInvoice->shopping_order->shopping_user){
|
||||
$key = strtoupper(substr($UserInvoice->shopping_order->shopping_user->billing_lastname, 0, 1));
|
||||
if($key === "S"){
|
||||
if(strtoupper(substr($UserInvoice->shopping_order->shopping_user->billing_lastname, 0, 3)) === "SCH"){
|
||||
return $this->accountKey['SCH'];
|
||||
}
|
||||
}
|
||||
return isset($this->accountKey[$key]) ? $this->accountKey[$key] : $key;
|
||||
}
|
||||
return "-";
|
||||
})
|
||||
->addColumn('contra_account', function (UserInvoice $UserInvoice) {
|
||||
return "-";
|
||||
})
|
||||
->addColumn('bu_key', function (UserInvoice $UserInvoice) {
|
||||
if($UserInvoice->shopping_order){
|
||||
return $UserInvoice->shopping_order->country_id;
|
||||
}
|
||||
})
|
||||
->addColumn('voucher_date', function (UserInvoice $UserInvoice) {
|
||||
// 101 -> für 01 Januar
|
||||
return $UserInvoice->month."01";
|
||||
})
|
||||
->addColumn('document_field_1', function (UserInvoice $UserInvoice) {
|
||||
//Rechnungsnummer
|
||||
return $UserInvoice->full_number;
|
||||
})
|
||||
->addColumn('posting_text', function (UserInvoice $UserInvoice) {
|
||||
//Buchungstext – hier wäre es toll wenn der Name des Kunden steht.
|
||||
if($UserInvoice->shopping_order && $UserInvoice->shopping_order->shopping_user){
|
||||
return $UserInvoice->shopping_order->shopping_user->billing_firstname." ".$UserInvoice->shopping_order->shopping_user->billing_lastname;
|
||||
}
|
||||
return "-";
|
||||
})
|
||||
->addColumn('invoice', function (UserInvoice $UserInvoice) {
|
||||
$ret = "";
|
||||
$ret .= '<a href="'.route('storage_file', [$UserInvoice->shopping_order->id, 'invoice', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserInvoice->shopping_order->id, 'invoice', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a>';
|
||||
return $ret;
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('invoice_number', 'invoice_number $1')
|
||||
->orderColumn('turnover', 'turnover $1')
|
||||
->orderColumn('shipped', 'shipped $1')
|
||||
->orderColumn('total_shipping', 'total_shipping $1')
|
||||
->rawColumns(['id', 'shipping_order', 'turnover', 'total_shipping', 'status', 'txaction', 'invoice'])
|
||||
->make(true);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,25 +2,27 @@
|
|||
|
||||
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;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserAbo;
|
||||
use App\Models\UserAboItem;
|
||||
use App\Repositories\AboRepository;
|
||||
use App\Services\AboHelper;
|
||||
use App\Services\AboItemHistoryService;
|
||||
use App\Services\AboOrderCart;
|
||||
use App\Services\Shop;
|
||||
use App\Services\UserService;
|
||||
use App\Services\Util;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Yard;
|
||||
|
||||
class AboController extends Controller
|
||||
{
|
||||
private $instance = 'subscription';
|
||||
|
||||
private $yard;
|
||||
|
||||
/**
|
||||
|
|
@ -34,12 +36,11 @@ class AboController extends Controller
|
|||
$this->yard = Yard::instance($this->instance);
|
||||
}
|
||||
|
||||
|
||||
public function myAbo()
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
|
||||
if (!$user->shopping_user_id) {
|
||||
|
||||
if (! $user->shopping_user_id) {
|
||||
return view('portal.abo.my_abo_create', [
|
||||
'user' => $user,
|
||||
'no_shopping_user' => true,
|
||||
|
|
@ -49,30 +50,304 @@ class AboController extends Controller
|
|||
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$user_abo = UserAbo::where('email', $shopping_user->billing_email)
|
||||
->where('status', '>', 1)
|
||||
->first();
|
||||
->where('status', '>', 1)
|
||||
->first();
|
||||
|
||||
return $user_abo
|
||||
? view('portal.abo.my_abo', ['user_abo' => $user_abo])
|
||||
: view('portal.abo.my_abo_create', [
|
||||
if (! $user_abo) {
|
||||
return view('portal.abo.my_abo_create', [
|
||||
'shopping_user' => $shopping_user,
|
||||
'step' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->checkPortalPermission($user_abo);
|
||||
|
||||
$view = 'portal';
|
||||
|
||||
// Init Yard und Customer-Detail
|
||||
AboOrderCart::initYard($user_abo);
|
||||
$customer_detail = AboOrderCart::getCustomerDetail();
|
||||
AboOrderCart::makeOrderYard($user_abo);
|
||||
|
||||
return view('portal.abo.my_abo', [
|
||||
'user_abo' => $user_abo,
|
||||
'customer_detail' => $customer_detail,
|
||||
'view' => $view,
|
||||
'comp_products' => [],
|
||||
'isAdmin' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($view, $id)
|
||||
{
|
||||
$data = Request::all();
|
||||
$user_abo = UserAbo::findOrFail($id);
|
||||
$this->checkPortalPermission($user_abo);
|
||||
$isAddOnlyMode = AboHelper::isAddOnlyMode($user_abo, $view);
|
||||
|
||||
if (isset($data['action'])) {
|
||||
if ($data['action'] === 'abo_update_settings') {
|
||||
$user_abo = UserAbo::findOrFail($data['id']);
|
||||
$this->checkPortalPermission($user_abo);
|
||||
$aboRepository = new AboRepository;
|
||||
$aboRepository->setModel($user_abo);
|
||||
$aboRepository->update($data);
|
||||
|
||||
return redirect(route('portal.my_subscriptions'));
|
||||
}
|
||||
|
||||
if (Request::ajax()) {
|
||||
$message = false;
|
||||
|
||||
// addProduct
|
||||
if ($data['action'] === 'addProduct') {
|
||||
if ($product = Product::find($data['product_id'])) {
|
||||
if ($UserAboItem = UserAboItem::where('user_abo_id', $user_abo->id)->where('product_id', $product->id)->where('comp', 0)->first()) {
|
||||
$qtyBefore = $UserAboItem->qty;
|
||||
$UserAboItem->qty = $UserAboItem->qty + 1;
|
||||
$UserAboItem->save();
|
||||
AboItemHistoryService::logProductAdded($user_abo, $UserAboItem, $qtyBefore, $view);
|
||||
} else {
|
||||
$newItem = UserAboItem::create([
|
||||
'user_abo_id' => $user_abo->id,
|
||||
'product_id' => $product->id,
|
||||
'comp' => 0,
|
||||
'qty' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
AboItemHistoryService::logProductAdded($user_abo, $newItem, 0, $view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// updateCart
|
||||
if ($data['action'] === 'updateCart') {
|
||||
if (isset($data['product_id']) && $product = Product::find($data['product_id'])) {
|
||||
if (isset($data['order_item_id']) && $UserAboItem = UserAboItem::find($data['order_item_id'])) {
|
||||
if (isset($data['qty'])) {
|
||||
$qtyBefore = $UserAboItem->qty;
|
||||
$qty = (int) $data['qty'];
|
||||
$qty = $qty < 1 ? 1 : $qty;
|
||||
$qty = $qty > 100 ? 100 : $qty;
|
||||
if ($isAddOnlyMode && $qty < $UserAboItem->qty) {
|
||||
$qty = $UserAboItem->qty;
|
||||
}
|
||||
$UserAboItem->qty = $qty;
|
||||
$UserAboItem->save();
|
||||
AboItemHistoryService::logQtyChanged($user_abo, $UserAboItem, $qtyBefore, $qty, $view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// removeFromCart
|
||||
if ($data['action'] === 'removeFromCart') {
|
||||
if ($isAddOnlyMode) {
|
||||
return response()->json([
|
||||
'response' => false,
|
||||
'message' => __('abo.error_add_only_no_remove'),
|
||||
], 403);
|
||||
}
|
||||
if (! isset($data['product_id']) || ! ($product = Product::find($data['product_id']))) {
|
||||
$message = __('abo.product_not_found');
|
||||
}
|
||||
if (! isset($data['order_item_id']) || ! ($userAboItem = UserAboItem::find($data['order_item_id']))) {
|
||||
$message = __('abo.abo_item_not_found');
|
||||
}
|
||||
$has_basis_product = $this->checkNeedBasisProduct($user_abo, $product, $data['order_item_id']);
|
||||
if (! $has_basis_product) {
|
||||
$message = __('abo.need_basis_product');
|
||||
}
|
||||
if (! $message) {
|
||||
AboItemHistoryService::logProductRemoved($user_abo, $userAboItem, $view);
|
||||
$userAboItem->delete();
|
||||
$user_abo->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
// updateCompProduct
|
||||
if ($data['action'] === 'updateCompProduct') {
|
||||
if ($UserAboItem = UserAboItem::where('user_abo_id', $user_abo->id)->where('comp', $data['comp_num'])->first()) {
|
||||
$oldProduct = $UserAboItem->product;
|
||||
$UserAboItem->product_id = $data['comp_product_id'];
|
||||
$UserAboItem->save();
|
||||
$UserAboItem->load('product');
|
||||
AboItemHistoryService::logCompProductChanged($user_abo, $UserAboItem, $oldProduct, $UserAboItem->product, $view);
|
||||
} else {
|
||||
$newItem = UserAboItem::create([
|
||||
'user_abo_id' => $user_abo->id,
|
||||
'product_id' => $data['comp_product_id'],
|
||||
'comp' => $data['comp_num'],
|
||||
'qty' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
AboItemHistoryService::logProductAdded($user_abo, $newItem, 0, $view);
|
||||
}
|
||||
}
|
||||
|
||||
AboOrderCart::initYard($user_abo);
|
||||
AboOrderCart::makeOrderYard($user_abo);
|
||||
AboOrderCart::checkNumOfCompProducts($user_abo);
|
||||
|
||||
$error_message = $message ? $message : false;
|
||||
$html_cart = view('admin.abo._order_abo_show', ['user_abo' => $user_abo, 'error_message' => $error_message, 'add_only_mode' => $isAddOnlyMode])->render();
|
||||
$html_comp = view('user.order.comp_product', $data)->render();
|
||||
|
||||
$amount = $user_abo->getFormattedAmount();
|
||||
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_cart' => $html_cart, 'html_comp' => $html_comp, 'amount' => $amount]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function datatable($user_abo_id)
|
||||
{
|
||||
$user_abo = UserAbo::findOrFail($user_abo_id);
|
||||
$this->checkPortalPermission($user_abo);
|
||||
|
||||
$show_on_ids = ['12', '13'];
|
||||
$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('add_card', function (Product $product) {
|
||||
$tax_free = Yard::instance('shopping')->getUserTaxFree();
|
||||
$price = $product->getFormattedPriceWith($tax_free, false, Yard::instance('shopping')->getUserCountry());
|
||||
|
||||
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="'.$product->id.'" data-product-name="'.e($product->getLang('name')).'" data-product-price="'.$price.' €">
|
||||
<strong>€ '.$price.'</strong> +<span class="ion ion-md-cart"></span>
|
||||
</button>';
|
||||
})
|
||||
->addColumn('picture', function (Product $product) {
|
||||
if (count($product->images)) {
|
||||
return '<img class="img-fluid img-extra" alt="" src="'.route('product_image', [$product->images->first()->slug]).'">';
|
||||
}
|
||||
|
||||
return '';
|
||||
})
|
||||
->addColumn('name', function (Product $product) {
|
||||
return '<strong>'.$product->getLang('name').'</strong><br>'.get_abo_type_badge_by_product($product);
|
||||
})
|
||||
->addColumn('points', function (Product $product) {
|
||||
return '<span class="no-line-break">'.$product->getFormattedPoints().'</span>';
|
||||
})
|
||||
->addColumn('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, true, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('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(true, true, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('action', function (Product $product) {
|
||||
return '<button class="btn btn-default btn-sm icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="'.$product->id.'" data-route="'.route('portal.loading_modal').'"
|
||||
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('contents_total', 'contents_total $1')
|
||||
->orderColumn('weight', 'weight $1')
|
||||
->rawColumns(['add_card', 'points', 'product', 'name', 'quantity', 'picture', 'price_net', 'price_gross', 'action'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function modalLoad()
|
||||
{
|
||||
$data = Request::all();
|
||||
$ret = '';
|
||||
|
||||
if (isset($data['action'])) {
|
||||
if ($data['action'] === 'abo-add-product') {
|
||||
$user_abo = UserAbo::find($data['id']);
|
||||
$this->checkPortalPermission($user_abo);
|
||||
$ret = view('user.abo.modal_abo_show_products', compact('data', 'user_abo'))->render();
|
||||
}
|
||||
if ($data['action'] === 'abo_update_settings') {
|
||||
$user_abo = UserAbo::find($data['id']);
|
||||
$this->checkPortalPermission($user_abo);
|
||||
$route = route('user_abos_update', [$data['view'], $user_abo->id]);
|
||||
$ret = view('admin.abo.modal_abo_update', compact('user_abo', 'data', 'route'))->render();
|
||||
}
|
||||
if ($data['action'] === 'user-order-show-product') {
|
||||
$product = Product::find($data['id']);
|
||||
$ret = view('admin.modal.show_product', compact('product', 'data'))->render();
|
||||
}
|
||||
}
|
||||
|
||||
if (Request::ajax()) {
|
||||
return response()->json(['response' => $data, 'html' => $ret, 'status' => true]);
|
||||
}
|
||||
|
||||
abort(404);
|
||||
}
|
||||
|
||||
public function checkNeedBasisProduct($user_abo, $product, $order_item_id)
|
||||
{
|
||||
if (AboHelper::getAboShowOn($product) !== 'base') {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($user_abo->user_abo_items as $user_abo_item) {
|
||||
if ($user_abo_item->id == $order_item_id) {
|
||||
continue;
|
||||
}
|
||||
if ($user_abo_item->comp) {
|
||||
continue;
|
||||
}
|
||||
if (AboHelper::getAboShowOn($user_abo_item->product) === 'base') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkPortalPermission($user_abo)
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
if (! $user || ! $user->shopping_user_id) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
$shopping_user = ShoppingUser::find($user->shopping_user_id);
|
||||
if (! $shopping_user || $user_abo->email !== $shopping_user->billing_email) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
}
|
||||
|
||||
public function myAboCreate($step)
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
|
||||
if (!$user->shopping_user_id) {
|
||||
|
||||
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'])){
|
||||
if (isset($data['checkout_url'])) {
|
||||
return redirect($data['checkout_url']);
|
||||
}
|
||||
|
||||
return view('portal.abo.my_abo_create', $data);
|
||||
}
|
||||
|
||||
|
|
@ -81,16 +356,16 @@ class AboController extends Controller
|
|||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'basis_products' => Product::where('active', true)
|
||||
->whereJsonContains('show_on', ['12'])
|
||||
->orderBy('pos', 'ASC')
|
||||
->get(),
|
||||
->whereJsonContains('show_on', ['12'])
|
||||
->orderBy('pos', 'ASC')
|
||||
->get(),
|
||||
'upgrade_products' => Product::where('active', true)
|
||||
->whereJsonContains('show_on', ['13'])
|
||||
->orderBy('pos', 'ASC')
|
||||
->get(),
|
||||
->whereJsonContains('show_on', ['13'])
|
||||
->orderBy('pos', 'ASC')
|
||||
->get(),
|
||||
'step' => 0,
|
||||
];
|
||||
if(Request::get('action') == 'back') {
|
||||
if (Request::get('action') == 'back') {
|
||||
$step = $step - 2;
|
||||
}
|
||||
|
||||
|
|
@ -110,14 +385,14 @@ class AboController extends Controller
|
|||
case 3:
|
||||
UserService::setInstance($this->instance);
|
||||
UserService::initCustomerYard($shopping_user, 'abo-ot-customer');
|
||||
if(Request::get('action') == 'next'){
|
||||
if (!$this->checkBasisProduct()) {
|
||||
if (Request::get('action') == 'next') {
|
||||
if (! $this->checkBasisProduct()) {
|
||||
$data['error'] = __('abo.abo_error_basis_product');
|
||||
$data['step'] = 2;
|
||||
} else {
|
||||
$data['step'] = 3;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
$data['step'] = 3;
|
||||
}
|
||||
break;
|
||||
|
|
@ -128,12 +403,12 @@ class AboController extends Controller
|
|||
$data['step'] = 4;
|
||||
break;
|
||||
case 5:
|
||||
//chekout verarbeiten
|
||||
// chekout verarbeiten
|
||||
UserService::setInstance($this->instance);
|
||||
UserService::initCustomerYard($shopping_user, 'abo-ot-customer');
|
||||
if(Request::get('action') == 'checkout'){
|
||||
//checkout verarbeiten
|
||||
if (!$this->preCheckCheckout()) {
|
||||
if (Request::get('action') == 'checkout') {
|
||||
// checkout verarbeiten
|
||||
if (! $this->preCheckCheckout()) {
|
||||
$data['error'] = __('abo.abo_error_basis_product');
|
||||
$data['step'] = 4;
|
||||
} else {
|
||||
|
|
@ -152,8 +427,8 @@ class AboController extends Controller
|
|||
private function initYard($shopping_user)
|
||||
{
|
||||
$delivery_country = $shopping_user->getDeliveryCountry(true);
|
||||
|
||||
if (!$delivery_country) {
|
||||
|
||||
if (! $delivery_country) {
|
||||
abort(404, 'No delivery country found, please edit your personal data.');
|
||||
}
|
||||
|
||||
|
|
@ -164,55 +439,55 @@ class AboController extends Controller
|
|||
Shop::initUserShopLang($delivery_country, $this->instance);
|
||||
}
|
||||
|
||||
private function preCheckCheckout(){
|
||||
private function preCheckCheckout()
|
||||
{
|
||||
$result = false;
|
||||
//alle inhlate des warenkorb
|
||||
// alle inhlate des warenkorb
|
||||
$cartItems = $this->yard->content();
|
||||
foreach($cartItems as $item){
|
||||
if(in_array(12, $item->options->show_on)){
|
||||
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'])) {
|
||||
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) {
|
||||
|
||||
if (! $product || intval($quantity) <= 0) {
|
||||
continue;
|
||||
}
|
||||
$result = true;
|
||||
$this->addProductToCart($product, $quantity);
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function upgradeProductToCart(){
|
||||
private function upgradeProductToCart()
|
||||
{
|
||||
$data = Request::all();
|
||||
$result = false;
|
||||
|
||||
if (!isset($data['upgrade_product_qty'])) {
|
||||
if (! isset($data['upgrade_product_qty'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($data['upgrade_product_qty'] as $product_id => $quantity) {
|
||||
$product = Product::find($product_id);
|
||||
|
||||
if (!$product) {
|
||||
|
||||
if (! $product) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -226,7 +501,7 @@ class AboController extends Controller
|
|||
private function addProductToCart($product, $quantity)
|
||||
{
|
||||
// Suche nach dem Produkt im Warenkorb
|
||||
$cartItems = $this->yard->search(function($item) use ($product) {
|
||||
$cartItems = $this->yard->search(function ($item) use ($product) {
|
||||
return $item->id === $product->id;
|
||||
});
|
||||
|
||||
|
|
@ -235,13 +510,14 @@ class AboController extends Controller
|
|||
foreach ($cartItems as $item) {
|
||||
$this->yard->remove($item->rowId);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$image = $product->images->first()->slug ?? '';
|
||||
$price = $product->getPriceWith(
|
||||
$this->yard->getUserTaxFree(),
|
||||
false,
|
||||
$this->yard->getUserTaxFree(),
|
||||
false,
|
||||
$this->yard->getUserCountry()
|
||||
);
|
||||
|
||||
|
|
@ -265,7 +541,7 @@ class AboController extends Controller
|
|||
'points' => $product->points,
|
||||
'no_commission' => $product->no_commission,
|
||||
'no_free_shipping' => $product->no_free_shipping,
|
||||
'show_on' => $product->show_on
|
||||
'show_on' => $product->show_on,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
@ -274,15 +550,15 @@ class AboController extends Controller
|
|||
$this->yard->reCalculateShippingPrice();
|
||||
}
|
||||
|
||||
|
||||
private function processCheckout(){
|
||||
private function processCheckout()
|
||||
{
|
||||
$user_shop = Util::getUserShop();
|
||||
if(!$user_shop){
|
||||
if (! $user_shop) {
|
||||
$user_shop = Util::getDefaultUserShop();
|
||||
}
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
} while (ShoppingInstance::where('identifier', $identifier)->count());
|
||||
|
||||
$data = [];
|
||||
$data['is_from'] = 'shopping';
|
||||
|
|
@ -291,7 +567,7 @@ class AboController extends Controller
|
|||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => $user_shop->id,
|
||||
'payment' => 1, //Customer Shop Payment
|
||||
'payment' => 1, // Customer Shop Payment
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => $this->yard->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
|
|
@ -299,13 +575,14 @@ class AboController extends Controller
|
|||
'back' => url()->previous(),
|
||||
|
||||
]);
|
||||
|
||||
|
||||
$this->yard->store($identifier);
|
||||
//add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
if(strpos($path, 'https') === false){
|
||||
// add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier' => $identifier]);
|
||||
if (strpos($path, 'https') === false) {
|
||||
$path = str_replace('http', 'https', $path);
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,12 @@
|
|||
|
||||
namespace App\Http\Controllers\Portal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\CustomerPriority;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\CustomerPriority;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
|
|
@ -22,49 +21,48 @@ class CustomerController extends Controller
|
|||
$this->middleware('auth:customers');
|
||||
}
|
||||
|
||||
|
||||
public function myDataEdit()
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
if($user->shopping_user_id){
|
||||
if ($user->shopping_user_id) {
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
}else{
|
||||
$shopping_user = new ShoppingUser();
|
||||
} else {
|
||||
$shopping_user = new ShoppingUser;
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'isAdmin' => false,
|
||||
'isView' => 'customer',
|
||||
];
|
||||
return view('portal.customer.edit', $data);
|
||||
|
||||
return view('portal.customer.edit', $data);
|
||||
}
|
||||
|
||||
public function myDataStore(){
|
||||
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(
|
||||
if ($data['action'] === 'shopping-user-store-new' || $data['action'] === 'shopping-user-store') {
|
||||
$rules = [
|
||||
'billing_salutation' => 'required',
|
||||
'billing_firstname'=>'required',
|
||||
'billing_lastname'=>'required',
|
||||
'billing_address'=>'required',
|
||||
'billing_zipcode'=>'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')){
|
||||
if (! Request::get('same_as_billing')) {
|
||||
$rules = array_merge($rules, [
|
||||
'shipping_firstname'=>'required',
|
||||
'shipping_lastname'=>'required',
|
||||
'shipping_address'=>'required',
|
||||
'shipping_zipcode'=>'required',
|
||||
'shipping_firstname' => 'required',
|
||||
'shipping_lastname' => 'required',
|
||||
'shipping_address' => 'required',
|
||||
'shipping_zipcode' => 'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_salutation' => 'required',
|
||||
'shipping_country_id' => 'required'
|
||||
'shipping_country_id' => 'required',
|
||||
]);
|
||||
}
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
|
|
@ -72,28 +70,31 @@ class CustomerController extends Controller
|
|||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
}
|
||||
$data['language'] = \App::getLocale();
|
||||
$data['language'] = $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){
|
||||
if ($user->shopping_user_id) {
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$shopping_user->fill($data);
|
||||
$shopping_user->save();
|
||||
}else{
|
||||
// Sprachpräferenz auch im Customer-Modell für Portal-UI synchronisieren
|
||||
if (isset($data['language'])) {
|
||||
$user->update(['language' => $data['language']]);
|
||||
}
|
||||
} else {
|
||||
$data['billing_email'] = $user->email;
|
||||
$shopping_user = ShoppingUser::create($data);
|
||||
$user->shopping_user_id = $shopping_user->id;
|
||||
if (isset($data['language'])) {
|
||||
$user->language = $data['language'];
|
||||
}
|
||||
$user->save();
|
||||
//kundenhoheit
|
||||
// kundenhoheit
|
||||
CustomerPriority::checkOne(ShoppingUser::find($shopping_user->id), true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
\Session()->flash('alert-save', true);
|
||||
|
||||
return redirect(route('portal.my_data.edit'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,68 +5,202 @@ namespace App\Http\Controllers\Portal;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\Payment;
|
||||
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
|
||||
*/
|
||||
private string $instance = 'webshop';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth:customers');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Bestellübersicht anzeigen.
|
||||
*/
|
||||
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);
|
||||
|
||||
return view('portal.order.my_orders');
|
||||
}
|
||||
|
||||
public function myOrderShow($id)
|
||||
/**
|
||||
* DataTable-Daten für Bestellübersicht (server-side).
|
||||
*/
|
||||
public function ordersDatatable()
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
|
||||
if (! $user->shopping_user_id) {
|
||||
return \DataTables::of(collect())->make(true);
|
||||
}
|
||||
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$shopping_order = ShoppingOrder::findOrFail($id);
|
||||
if($shopping_order->shopping_user_id != $user->shopping_user_id){
|
||||
$userIds = ShoppingUser::where('billing_email', $shopping_user->billing_email)
|
||||
->where('member_id', $shopping_user->member_id)
|
||||
->pluck('id');
|
||||
|
||||
$query = ShoppingOrder::with('shopping_user')
|
||||
->select('shopping_orders.*')
|
||||
->whereIn('shopping_user_id', $userIds)
|
||||
->whereNotNull('txaction');
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (ShoppingOrder $order) {
|
||||
return '<a href="'.route('portal.my_orders.show', $order->id).'" '
|
||||
.'class="btn icon-btn btn-sm btn-primary"><span class="fa fa-eye"></span></a>';
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingOrder $order) {
|
||||
return $order->created_at->format('d.m.Y');
|
||||
})
|
||||
->addColumn('total_shipping', function (ShoppingOrder $order) {
|
||||
return '<span class="no-line-break">'.$order->getFormattedTotalShipping().' €</span>';
|
||||
})
|
||||
->addColumn('txaction', function (ShoppingOrder $order) {
|
||||
return Payment::getShoppingOrderBadge($order);
|
||||
})
|
||||
->addColumn('shipped', function (ShoppingOrder $order) {
|
||||
return '<span class="badge badge-pill badge-'.$order->getShippedColor().'">'
|
||||
.$order->getShippedType().'</span>';
|
||||
})
|
||||
->addColumn('firstname', function (ShoppingOrder $order) {
|
||||
return $order->shopping_user->billing_firstname ?? '-';
|
||||
})
|
||||
->addColumn('lastname', function (ShoppingOrder $order) {
|
||||
return $order->shopping_user->billing_lastname ?? '-';
|
||||
})
|
||||
->addColumn('email', function (ShoppingOrder $order) {
|
||||
return $order->shopping_user->billing_email ?? '-';
|
||||
})
|
||||
->addColumn('invoice', function (ShoppingOrder $order) {
|
||||
if ($order->isInvoice()) {
|
||||
return '<span class="no-line-break">'
|
||||
.'<a href="'.route('storage_file', [$order->id, 'invoice', 'download']).'" '
|
||||
.'class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a> '
|
||||
.'<a href="'.route('storage_file', [$order->id, 'invoice', 'stream']).'" '
|
||||
.'target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a>'
|
||||
.'</span>';
|
||||
}
|
||||
|
||||
return '-';
|
||||
})
|
||||
->addColumn('payment_for', function (ShoppingOrder $order) {
|
||||
return Payment::getPaymentForBadge($order);
|
||||
})
|
||||
->orderColumn('id', 'shopping_orders.id $1')
|
||||
->orderColumn('created_at', 'shopping_orders.created_at $1')
|
||||
->orderColumn('total_shipping', 'shopping_orders.total_shipping $1')
|
||||
->orderColumn('txaction', 'shopping_orders.txaction $1')
|
||||
->orderColumn('shipped', 'shopping_orders.shipped $1')
|
||||
->rawColumns(['id', 'txaction', 'payment_for', 'total_shipping', 'invoice', 'shipped'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bestelldetail anzeigen.
|
||||
*/
|
||||
public function myOrderShow(int $id)
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
|
||||
if (! $user->shopping_user_id) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
$shopping_order = ShoppingOrder::with('shopping_user', 'shopping_order_items.product.images')
|
||||
->findOrFail($id);
|
||||
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
if (! $this->orderBelongsToMember($shopping_order, $shopping_user)) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
return view('portal.order.my_order_show', [
|
||||
'shopping_order' => $shopping_order,
|
||||
'shopping_user' => $shopping_user,
|
||||
]);
|
||||
}
|
||||
|
||||
public function myOrderCreate($id)
|
||||
/**
|
||||
* DataTable-Daten für Zahlungen einer Bestellung (server-side).
|
||||
*/
|
||||
public function paymentsDatatable(int $id)
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
|
||||
if (! $user->shopping_user_id) {
|
||||
return \DataTables::of(collect())->make(true);
|
||||
}
|
||||
|
||||
$shopping_order = ShoppingOrder::findOrFail($id);
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
|
||||
if (! $this->orderBelongsToMember($shopping_order, $shopping_user)) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
$query = ShoppingPayment::where('shopping_order_id', $id);
|
||||
|
||||
$counter = 0;
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('line_number', function (ShoppingPayment $payment) use (&$counter) {
|
||||
$counter++;
|
||||
|
||||
return $counter;
|
||||
})
|
||||
->addColumn('payment_type', function (ShoppingPayment $payment) {
|
||||
return $payment->getPaymentType();
|
||||
})
|
||||
->addColumn('amount', function (ShoppingPayment $payment) {
|
||||
return $payment->getPaymentAmount();
|
||||
})
|
||||
->addColumn('status', function (ShoppingPayment $payment) {
|
||||
return Payment::getShoppingPaymentBadge($payment);
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingPayment $payment) {
|
||||
return $payment->created_at->format('d.m.Y H:i');
|
||||
})
|
||||
->addColumn('reference', function (ShoppingPayment $payment) {
|
||||
return $payment->reference;
|
||||
})
|
||||
->rawColumns(['status'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob Bestellung zum Mitglied gehört (billing_email + member_id).
|
||||
*/
|
||||
private function orderBelongsToMember(ShoppingOrder $order, ShoppingUser $member): bool
|
||||
{
|
||||
$orderUser = $order->shopping_user;
|
||||
|
||||
return $orderUser
|
||||
&& $orderUser->billing_email === $member->billing_email
|
||||
&& $orderUser->member_id === $member->member_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bestellung erneut in den Warenkorb legen.
|
||||
*/
|
||||
public function myOrderCreate(int $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.');
|
||||
|
||||
if ($shopping_order->shopping_user_id != $user->shopping_user_id) {
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
if (! $this->orderBelongsToMember($shopping_order, $shopping_user)) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
}
|
||||
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$delivery_country = $shopping_user->getDeliveryCountry(true);
|
||||
|
||||
|
|
@ -76,41 +210,50 @@ class OrderController extends Controller
|
|||
|
||||
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);
|
||||
foreach ($shopping_order->shopping_order_items as $item) {
|
||||
if ($item->product) {
|
||||
$this->addToCart($item->product_id, $item->qty);
|
||||
}
|
||||
}
|
||||
$url = Util::getMyMivitaShopUrl("/user/card/show");
|
||||
return redirect($url);
|
||||
|
||||
return redirect(Util::getMyMivitaShopUrl('/user/card/show'));
|
||||
}
|
||||
|
||||
|
||||
private function addToCard($id, $quantity = 1)
|
||||
private function addToCart(int $productId, int $quantity = 1): void
|
||||
{
|
||||
$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);
|
||||
$product = Product::find($productId);
|
||||
if (! $product) {
|
||||
return;
|
||||
}
|
||||
|
||||
$image = $product->images->first()?->slug ?? '';
|
||||
$yard = Yard::instance($this->instance);
|
||||
|
||||
$cartItem = $yard->add(
|
||||
$product->id,
|
||||
$product->getLang('name'),
|
||||
$quantity,
|
||||
$product->getPriceWith($yard->getUserTaxFree(), false, $yard->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->getUserTaxFree()) {
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
} else {
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith($yard->getUserCountry()));
|
||||
}
|
||||
|
||||
$yard->reCalculateShippingPrice();
|
||||
\Session()->flash('show-card-after-add', true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,20 +2,19 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Request;
|
||||
use App\Models\UserShop;
|
||||
use App\Services\Payment;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\PaymentTransaction;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\Models\PaymentTransaction;
|
||||
use App\Services\CustomerPriority;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserShop;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use App\Services\BusinessPlan\SalesPointsVolume;
|
||||
use App\Services\CustomerPriority;
|
||||
use App\Services\Payment;
|
||||
use Request;
|
||||
|
||||
class SalesController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
|
|
@ -28,6 +27,7 @@ class SalesController extends Controller
|
|||
return redirect(route('admin_sales_users'));
|
||||
}
|
||||
$data = [];
|
||||
|
||||
return view('admin.sales.users', $data);
|
||||
}
|
||||
|
||||
|
|
@ -48,36 +48,38 @@ class SalesController extends Controller
|
|||
'isAdmin' => true,
|
||||
'isView' => 'sales_user',
|
||||
];
|
||||
|
||||
return view('admin.sales.user_detail', $data);
|
||||
}
|
||||
|
||||
public function usersStore($id)
|
||||
{
|
||||
die("keine funktion");
|
||||
exit('keine funktion');
|
||||
$data = [
|
||||
'shopping_order' => ShoppingOrder::find($id),
|
||||
'isAdmin' => true,
|
||||
];
|
||||
|
||||
return view('admin.sales.user_detail', $data);
|
||||
}
|
||||
|
||||
public function usersDatatable()
|
||||
{
|
||||
|
||||
$query = ShoppingOrder::with('shopping_user', 'user_shop', 'shopping_payments')->select('shopping_orders.*')->where('shopping_orders.auth_user_id', '!=', NULL);
|
||||
$query = ShoppingOrder::with('shopping_user', 'user_shop', 'shopping_payments')->select('shopping_orders.*')->where('shopping_orders.auth_user_id', '!=', null);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<a href="' . route('admin_sales_users_detail', [$ShoppingOrder->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
return '<a href="'.route('admin_sales_users_detail', [$ShoppingOrder->id]).'" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->created_at->format("d.m.Y");
|
||||
return $ShoppingOrder->created_at->format('d.m.Y');
|
||||
})
|
||||
->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getShoppingOrderBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="no-line-break">' . $ShoppingOrder->getFormattedTotalShipping() . " €</span>";
|
||||
return '<span class="no-line-break">'.$ShoppingOrder->getFormattedTotalShipping().' €</span>';
|
||||
})
|
||||
->addColumn('payment', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('getPaymentType');
|
||||
|
|
@ -85,27 +87,28 @@ class SalesController extends Controller
|
|||
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
|
||||
if ($ShoppingOrder->payment_for === 8) {
|
||||
return '<button type="button" class="btn btn-xs btn-info btn-round" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="' . $ShoppingOrder->id . '"
|
||||
data-id="'.$ShoppingOrder->id.'"
|
||||
data-action="shop-user-order-shipping-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="user"
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-eye"></span></button>';
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-eye"></span></button>';
|
||||
}
|
||||
return '<span class="badge badge-pill badge-' . $ShoppingOrder->getShippedColor() . '">' . $ShoppingOrder->getShippedType() . '</span>';
|
||||
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>';
|
||||
})
|
||||
->addColumn('dhl_button', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<button type="button" class="btn btn-xs btn-' . ($ShoppingOrder->hasDhlShipments() ? 'primary' : 'secondary') . '" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="' . $ShoppingOrder->id . '"
|
||||
return '<button type="button" class="btn btn-xs btn-'.($ShoppingOrder->hasDhlShipments() ? 'primary' : 'secondary').'" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="'.$ShoppingOrder->id.'"
|
||||
data-action="create-dhl-shipment"
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-shipping-fast"></span></button>';
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-shipping-fast"></span></button>';
|
||||
})
|
||||
->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getPaymentForBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="' . route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']) . '" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="' . route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']) . '" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
})
|
||||
->addColumn('reference', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('reference');
|
||||
|
|
@ -114,11 +117,12 @@ class SalesController extends Controller
|
|||
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->orders : '';
|
||||
})
|
||||
->addColumn('user_shop_id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->user_shop ? '<a href="' . $ShoppingOrder->user_shop->getSubdomain(false) . '" target="_blank">' . $ShoppingOrder->user_shop->getSubdomain(false) . '</span>' : '';
|
||||
return $ShoppingOrder->user_shop ? '<a href="'.$ShoppingOrder->user_shop->getSubdomain(false).'" target="_blank">'.$ShoppingOrder->user_shop->getSubdomain(false).'</span>' : '';
|
||||
})
|
||||
->addColumn('auth_user_shop', function (ShoppingOrder $ShoppingOrder) {
|
||||
$auth_user_shop = UserShop::whereUserId($ShoppingOrder->auth_user_id)->first();
|
||||
return $auth_user_shop ? '<a href="' . $auth_user_shop->getSubdomain(false) . '" target="_blank">' . $auth_user_shop->getSubdomain(false) . '</span>' : '-';
|
||||
|
||||
return $auth_user_shop ? '<a href="'.$auth_user_shop->getSubdomain(false).'" target="_blank">'.$auth_user_shop->getSubdomain(false).'</span>' : '-';
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
|
|
@ -137,6 +141,7 @@ class SalesController extends Controller
|
|||
set_user_attr('filter_user_shop_id', null);
|
||||
set_user_attr('filter_txaction', null);
|
||||
set_user_attr('filter_member_id', null);
|
||||
|
||||
return redirect(route('admin_sales_customers'));
|
||||
}
|
||||
$filter_user_shops = ShoppingOrder::select('user_shops.id', 'user_shops.slug')
|
||||
|
|
@ -146,28 +151,27 @@ class SalesController extends Controller
|
|||
->pluck('slug', 'id')
|
||||
->toArray();
|
||||
$filter_members = ShoppingOrder::join('users', 'member_id', '=', 'users.id')->groupBy('member_id')->join('user_accounts', 'account_id', '=', 'user_accounts.id')->select('users.id', 'users.email', 'user_accounts.first_name', 'user_accounts.last_name')->get();
|
||||
//->pluck('email', 'id')->unique()->toArray();
|
||||
|
||||
|
||||
// ->pluck('email', 'id')->unique()->toArray();
|
||||
|
||||
$data = [
|
||||
'filter_user_shops' => $filter_user_shops,
|
||||
'filter_members' => $filter_members,
|
||||
];
|
||||
|
||||
return view('admin.sales.customers', $data);
|
||||
}
|
||||
|
||||
public function customersDetail($id)
|
||||
{
|
||||
$ShoppingOrder = ShoppingOrder::find($id);
|
||||
if (!$ShoppingOrder) {
|
||||
if (! $ShoppingOrder) {
|
||||
abort(404);
|
||||
}
|
||||
if ($ShoppingOrder->payment_for !== 6 && $ShoppingOrder->payment_for !== 7) {
|
||||
return redirect(route('admin_sales_users_detail', [$ShoppingOrder->id]));
|
||||
abort(403, 'Beraterbestellung');
|
||||
}
|
||||
/*
|
||||
/*
|
||||
if($ShoppingOrder->shipped === 0){
|
||||
$ShoppingOrder->shipped = 1;
|
||||
$ShoppingOrder->save();
|
||||
|
|
@ -178,6 +182,7 @@ class SalesController extends Controller
|
|||
'isAdmin' => true,
|
||||
'isView' => 'sales_customer',
|
||||
];
|
||||
|
||||
return view('admin.sales.customer_detail', $data);
|
||||
}
|
||||
|
||||
|
|
@ -186,46 +191,53 @@ class SalesController extends Controller
|
|||
$data = Request::all();
|
||||
$change_member_error = false;
|
||||
if ($data['action'] === 'shopping-order-change-member') {
|
||||
if (!isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) {
|
||||
$change_member_error = "Das Passwort ist falsch.";
|
||||
if (! isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) {
|
||||
$change_member_error = 'Das Passwort ist falsch.';
|
||||
} else {
|
||||
//change
|
||||
// change
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
CustomerPriority::newMemberForOrder($shopping_order, $data['change_member_id'], $data['customer_set_member_for']);
|
||||
\Session()->flash('alert-save', true);
|
||||
|
||||
return redirect(route('admin_sales_customers_detail', [$shopping_order->id]));
|
||||
}
|
||||
}
|
||||
if ($data['action'] === 'shopping-user-is-like-member') {
|
||||
if (!isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) {
|
||||
if (! isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) {
|
||||
\Session()->flash('alert-error', 'Das Passwort ist falsch.');
|
||||
|
||||
return redirect($data['back']);
|
||||
} else {
|
||||
if (!isset($data['is_like_shopping_user_id'])) {
|
||||
if (! isset($data['is_like_shopping_user_id'])) {
|
||||
\Session()->flash('alert-error', 'Keine Änderung ausgewählt');
|
||||
|
||||
return redirect($data['back']);
|
||||
}
|
||||
$shopping_user = ShoppingUser::findOrFail($data['id']);
|
||||
$set_like_shopping_user = ShoppingUser::findOrFail($data['is_like_shopping_user_id']);
|
||||
$send_member_mail = isset($data['send_member_mail']) ? true : false;
|
||||
$change_shopping_user = isset($data['change_shopping_user']) ? true : false;
|
||||
//Mail send in setIsLike
|
||||
// Mail send in setIsLike
|
||||
CustomerPriority::setIsLike($shopping_user, $set_like_shopping_user, $send_member_mail, $change_shopping_user);
|
||||
\Session()->flash('alert-save', true);
|
||||
|
||||
return redirect($data['back']);
|
||||
}
|
||||
}
|
||||
if ($data['action'] === 'shopping-order-change-points') {
|
||||
if (!isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) {
|
||||
if (! isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) {
|
||||
\Session()->flash('alert-error', 'Das Passwort ist falsch.');
|
||||
|
||||
return back();
|
||||
} else {
|
||||
if (!isset($data['change_points'])) {
|
||||
if (! isset($data['change_points'])) {
|
||||
\Session()->flash('alert-error', 'Keine Änderung ausgewählt');
|
||||
|
||||
return back();
|
||||
}
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
SalesPointsVolume::changeSalesPointsVolumeUser($shopping_order, $data['change_member_id']);
|
||||
|
||||
return redirect(route('admin_sales_customers_detail', [$shopping_order->id]));
|
||||
}
|
||||
}
|
||||
|
|
@ -235,90 +247,94 @@ class SalesController extends Controller
|
|||
'isAdmin' => true,
|
||||
'isView' => 'sales_customer',
|
||||
];
|
||||
|
||||
return view('admin.sales.customer_detail', $data);
|
||||
}
|
||||
|
||||
public function customersDatatable()
|
||||
{
|
||||
|
||||
$query = ShoppingOrder::with('shopping_user')->select('shopping_orders.*')->where('shopping_orders.auth_user_id', NULL);
|
||||
$query = ShoppingOrder::with('shopping_user')->select('shopping_orders.*')->where('shopping_orders.auth_user_id', null);
|
||||
set_user_attr('filter_user_shop_id', Request::get('filter_user_shop_id'));
|
||||
if (Request::get('filter_user_shop_id') != "") {
|
||||
if (Request::get('filter_user_shop_id') != '') {
|
||||
$query->where('user_shop_id', '=', Request::get('filter_user_shop_id'));
|
||||
}
|
||||
set_user_attr('filter_txaction', Request::get('filter_txaction'));
|
||||
if (Request::get('filter_txaction') != "") {
|
||||
if (Request::get('filter_txaction') != '') {
|
||||
if (Request::get('filter_txaction') === 'NULL') {
|
||||
$query->where('txaction', '=', NULL);
|
||||
$query->where('txaction', '=', null);
|
||||
} else {
|
||||
$query->where('txaction', '=', Request::get('filter_txaction'));
|
||||
}
|
||||
}
|
||||
set_user_attr('filter_member_id', Request::get('filter_member_id'));
|
||||
if (Request::get('filter_member_id') != "") {
|
||||
if (Request::get('filter_member_id') != '') {
|
||||
$query->where('member_id', '=', Request::get('filter_member_id'));
|
||||
}
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<a href="' . route('admin_sales_customers_detail', [$ShoppingOrder->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
return '<a href="'.route('admin_sales_customers_detail', [$ShoppingOrder->id]).'" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->created_at->format("d.m.Y");
|
||||
return $ShoppingOrder->created_at->format('d.m.Y');
|
||||
})
|
||||
->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getShoppingOrderBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="no-line-break">' . $ShoppingOrder->getFormattedTotalShipping() . " €</span>";
|
||||
return '<span class="no-line-break">'.$ShoppingOrder->getFormattedTotalShipping().' €</span>';
|
||||
})
|
||||
->addColumn('payment', function (ShoppingOrder $ShoppingOrder) {
|
||||
if ($ShoppingOrder->txaction === 'extern_paid') {
|
||||
$shopping_oder_id = isset($ShoppingOrder->api_notice['shopping_order_id']) ? $ShoppingOrder->api_notice['shopping_order_id'] : null;
|
||||
if ($shopping_oder_id) {
|
||||
return '<a class="btn btn-xs btn-default btn-round" href="' . route('admin_sales_users_detail', [$shopping_oder_id]) . '"><i class="fa fa-check fa-check-circle-o"> ' . $shopping_oder_id . '</a>';
|
||||
return '<a class="btn btn-xs btn-default btn-round" href="'.route('admin_sales_users_detail', [$shopping_oder_id]).'"><i class="fa fa-check fa-check-circle-o"> '.$shopping_oder_id.'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
return $ShoppingOrder->getLastShoppingPayment('getPaymentType');
|
||||
})
|
||||
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="badge badge-pill badge-' . $ShoppingOrder->getShippedColor() . '">' . $ShoppingOrder->getShippedType() . '</span>';
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>';
|
||||
})
|
||||
->addColumn('dhl_button', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<button type="button" class="btn btn-xs btn-' . ($ShoppingOrder->hasDhlShipments() ? 'primary' : 'secondary') . '" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="' . $ShoppingOrder->id . '"
|
||||
return '<button type="button" class="btn btn-xs btn-'.($ShoppingOrder->hasDhlShipments() ? 'primary' : 'secondary').'" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="'.$ShoppingOrder->id.'"
|
||||
data-action="create-dhl-shipment"
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-shipping-fast"></span></button>';
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-shipping-fast"></span></button>';
|
||||
})
|
||||
->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getPaymentForBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) {
|
||||
if (($ShoppingOrder->txaction === 'extern' || $ShoppingOrder->txaction === 'extern_paid') && $ShoppingOrder->wp_invoice_path) {
|
||||
return '<span class="no-line-break"><a href="' . $ShoppingOrder->wp_invoice_path . '" class="btn btn-secondary btn-xs"><i class="fa fa-external-link-alt"></i> <i class="fa fa-download"></i></a> </div>';
|
||||
return '<span class="no-line-break"><a href="'.$ShoppingOrder->wp_invoice_path.'" class="btn btn-secondary btn-xs"><i class="fa fa-external-link-alt"></i> <i class="fa fa-download"></i></a> </div>';
|
||||
}
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="' . route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']) . '" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="' . route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']) . '" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
})
|
||||
->addColumn('reference', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('reference');
|
||||
})
|
||||
->addColumn('member_id', function (ShoppingOrder $ShoppingOrder) {
|
||||
if ($ShoppingOrder->member_id && $ShoppingOrder->member) {
|
||||
return $ShoppingOrder->member ? '<a href="' . route('admin_lead_edit', [$ShoppingOrder->member_id]) . '">' . $ShoppingOrder->member->getFullName() . '</a>' : 'gelöscht';
|
||||
return $ShoppingOrder->member ? '<a href="'.route('admin_lead_edit', [$ShoppingOrder->member_id]).'">'.$ShoppingOrder->member->getFullName().'</a>' : 'gelöscht';
|
||||
}
|
||||
if ($ShoppingOrder->shopping_user && $ShoppingOrder->shopping_user->is_like) {
|
||||
return '<button type="button" class="btn btn-xs btn-outline-info" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="' . $ShoppingOrder->shopping_user->id . '"
|
||||
data-id="'.$ShoppingOrder->shopping_user->id.'"
|
||||
data-action="shopping-user-is-like-member"
|
||||
data-back="' . route('admin_sales_customers') . '"
|
||||
data-back="'.route('admin_sales_customers').'"
|
||||
data-modal="modal-xl"
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-edit"></span> Berater zuordnen</button>';
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-edit"></span> Berater zuordnen</button>';
|
||||
}
|
||||
|
||||
return '';
|
||||
})
|
||||
->addColumn('user_shop_id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->user_shop ? '<a href="' . $ShoppingOrder->user_shop->getSubdomain(false) . '" target="_blank">' . $ShoppingOrder->user_shop->getSubdomain(false) . '</span>' : '';
|
||||
return $ShoppingOrder->user_shop ? '<a href="'.$ShoppingOrder->user_shop->getSubdomain(false).'" target="_blank">'.$ShoppingOrder->user_shop->getSubdomain(false).'</span>' : '';
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
|
|
@ -334,7 +350,7 @@ class SalesController extends Controller
|
|||
public function store()
|
||||
{
|
||||
$data = Request::all();
|
||||
if (!isset($data['id'])) {
|
||||
if (! isset($data['id'])) {
|
||||
abort(404);
|
||||
}
|
||||
if (isset($data['action'])) {
|
||||
|
|
@ -350,11 +366,11 @@ class SalesController extends Controller
|
|||
|
||||
PaymentTransaction::create([
|
||||
'shopping_payment_id' => $shopping_payment->id,
|
||||
'request' => 'transaction',
|
||||
'request' => 'transaction',
|
||||
'txid' => 0,
|
||||
'userid' => 0,
|
||||
'status' => 'FNCMIV',
|
||||
'transmitted_data' => NULL,
|
||||
'transmitted_data' => null,
|
||||
'txaction' => $data['txaction'],
|
||||
'mode' => $shopping_payment->mode,
|
||||
]);
|
||||
|
|
@ -365,10 +381,10 @@ class SalesController extends Controller
|
|||
$shopping_payment->txaction = $data['txaction'];
|
||||
$shopping_payment->save();
|
||||
|
||||
//TODO can send MAIL
|
||||
//Bei Zahlung auf Rechnung wurde die Rechnung schon erstellt,
|
||||
//wenn muss hier die Storno erstellt werden
|
||||
//Payment::paymentStatusSendMail($shopping_order, $shopping_payment, $data);
|
||||
// TODO can send MAIL
|
||||
// Bei Zahlung auf Rechnung wurde die Rechnung schon erstellt,
|
||||
// wenn muss hier die Storno erstellt werden
|
||||
// Payment::paymentStatusSendMail($shopping_order, $shopping_payment, $data);
|
||||
}
|
||||
}
|
||||
if (isset($data['back'])) {
|
||||
|
|
@ -381,7 +397,7 @@ class SalesController extends Controller
|
|||
public function invoice()
|
||||
{
|
||||
$data = Request::all();
|
||||
if (!isset($data['id'])) {
|
||||
if (! isset($data['id'])) {
|
||||
abort(404);
|
||||
}
|
||||
if (isset($data['action'])) {
|
||||
|
|
@ -398,8 +414,56 @@ class SalesController extends Controller
|
|||
if (isset($data['view']) && $data['view'] === 'sales_customer') {
|
||||
return redirect(route('admin_sales_customers_detail', [$shopping_order->id]));
|
||||
}
|
||||
|
||||
return redirect(route('admin_sales_users_detail', [$shopping_order->id]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stornorechnung erstellen mit Punktekorrektur
|
||||
*/
|
||||
public function invoiceCancellation()
|
||||
{
|
||||
$data = Request::all();
|
||||
|
||||
if (! isset($data['id'])) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if (isset($data['action']) && $data['action'] === 'create_cancellation_invoice') {
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
|
||||
// Prüfen ob Rechnung existiert
|
||||
if (! $shopping_order->isInvoice()) {
|
||||
\Session()->flash('alert-error', 'Es existiert keine Rechnung für diese Bestellung.');
|
||||
|
||||
return redirect($data['back'] ?? route('admin_sales_users_detail', [$shopping_order->id]));
|
||||
}
|
||||
|
||||
// Prüfen ob bereits storniert
|
||||
if ($shopping_order->isCancellationInvoice()) {
|
||||
\Session()->flash('alert-error', 'Diese Rechnung wurde bereits storniert.');
|
||||
|
||||
return redirect($data['back'] ?? route('admin_sales_users_detail', [$shopping_order->id]));
|
||||
}
|
||||
|
||||
try {
|
||||
$invoice_repo = new InvoiceRepository($shopping_order);
|
||||
$cancellation_invoice = $invoice_repo->createCancellation($data);
|
||||
|
||||
\Session()->flash('alert-success', 'Stornorechnung wurde erfolgreich erstellt und Punkte wurden korrigiert.');
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Fehler beim Erstellen der Stornorechnung: '.$e->getMessage(), [
|
||||
'order_id' => $shopping_order->id,
|
||||
'exception' => $e,
|
||||
]);
|
||||
\Session()->flash('alert-error', 'Fehler beim Erstellen der Stornorechnung: '.$e->getMessage());
|
||||
}
|
||||
|
||||
return redirect($data['back'] ?? route('admin_sales_users_detail', [$shopping_order->id]));
|
||||
}
|
||||
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,8 @@ namespace App\Http\Controllers;
|
|||
use App\Models\Setting;
|
||||
use Request;
|
||||
|
||||
|
||||
class SettingController extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
|
|
@ -21,10 +18,10 @@ class SettingController extends Controller
|
|||
$data = [
|
||||
'values' => [],
|
||||
];
|
||||
|
||||
return view('admin.settings.index', $data);
|
||||
}
|
||||
|
||||
|
||||
public function store()
|
||||
{
|
||||
$data = Request::all();
|
||||
|
|
@ -50,7 +47,9 @@ class SettingController extends Controller
|
|||
|
||||
/**
|
||||
* Get DHL configuration merged from database settings and .env values
|
||||
* Database settings override .env values
|
||||
* Priority is controlled by DHL_CONFIG_SOURCE environment variable:
|
||||
* - 'database' (default): Database settings override .env values
|
||||
* - 'env': Environment/Config values override database settings
|
||||
*/
|
||||
public function getDhlConfig()
|
||||
{
|
||||
|
|
@ -58,44 +57,49 @@ class SettingController extends Controller
|
|||
$isTestMode = config('dhl.legacy.test_mode', false) || config('dhl.legacy.sandbox', false);
|
||||
$baseUrl = $isTestMode ? config('dhl.sandbox_url') : config('dhl.base_url');
|
||||
|
||||
// Determine configuration priority
|
||||
$useEnvPriority = config('dhl.config_source') === 'env';
|
||||
|
||||
return [
|
||||
// API Settings
|
||||
'base_url' => $isTestMode ? $baseUrl : (Setting::getContentBySlug('dhl_base_url') ?: $baseUrl),
|
||||
'api_key' => Setting::getContentBySlug('dhl_api_key') ?: config('dhl.api_key'),
|
||||
'username' => Setting::getContentBySlug('dhl_username') ?: config('dhl.username'),
|
||||
'password' => Setting::getContentBySlug('dhl_password') ?: config('dhl.password'),
|
||||
'billing_number' => Setting::getContentBySlug('dhl_billing_number') ?: config('dhl.billing_number'),
|
||||
'base_url' => $isTestMode ? $baseUrl : $this->getConfigValue('dhl_base_url', $baseUrl, $useEnvPriority),
|
||||
'api_key' => $this->getConfigValue('dhl_api_key', config('dhl.api_key'), $useEnvPriority),
|
||||
'api_secret' => config('dhl.legacy.api_secret'), // Used by Tracking API
|
||||
'username' => $this->getConfigValue('dhl_username', config('dhl.username'), $useEnvPriority),
|
||||
'password' => $this->getConfigValue('dhl_password', config('dhl.password'), $useEnvPriority),
|
||||
'billing_number' => $this->getConfigValue('dhl_billing_number', config('dhl.billing_number'), $useEnvPriority),
|
||||
'sandbox' => config('dhl.legacy.sandbox', true), // Used by Tracking Service
|
||||
'test_mode' => config('dhl.legacy.test_mode', true),
|
||||
|
||||
// Product Settings
|
||||
'default_product' => Setting::getContentBySlug('dhl_product') ?: config('dhl.default_product'),
|
||||
'label_format' => Setting::getContentBySlug('dhl_label_format') ?: config('dhl.label_format'),
|
||||
'print_format' => Setting::getContentBySlug('dhl_print_format') ?: config('dhl.print_format'),
|
||||
'retoure_print_format' => Setting::getContentBySlug('dhl_retoure_print_format') ?: config('dhl.retoure_print_format'),
|
||||
'use_queue' => Setting::getContentBySlug('dhl_use_queue') ?: config('dhl.use_queue'),
|
||||
'default_product' => $this->getConfigValue('dhl_product', config('dhl.default_product'), $useEnvPriority),
|
||||
'label_format' => $this->getConfigValue('dhl_label_format', config('dhl.label_format'), $useEnvPriority),
|
||||
'print_format' => $this->getConfigValue('dhl_print_format', config('dhl.print_format'), $useEnvPriority),
|
||||
'retoure_print_format' => $this->getConfigValue('dhl_retoure_print_format', config('dhl.retoure_print_format'), $useEnvPriority),
|
||||
'use_queue' => $this->getConfigValue('dhl_use_queue', config('dhl.use_queue'), $useEnvPriority),
|
||||
|
||||
// Sender Address
|
||||
'sender' => [
|
||||
'company' => Setting::getContentBySlug('dhl_sender_company') ?: config('dhl.sender.company'),
|
||||
'name' => Setting::getContentBySlug('dhl_sender_name') ?: config('dhl.sender.name'),
|
||||
'street' => Setting::getContentBySlug('dhl_sender_street') ?: config('dhl.sender.street'),
|
||||
'houseNumber' => Setting::getContentBySlug('dhl_sender_house_number') ?: config('dhl.sender.houseNumber'),
|
||||
'postalCode' => Setting::getContentBySlug('dhl_sender_postal_code') ?: config('dhl.sender.postalCode'),
|
||||
'city' => Setting::getContentBySlug('dhl_sender_city') ?: config('dhl.sender.city'),
|
||||
'country' => Setting::getContentBySlug('dhl_sender_country') ?: config('dhl.sender.country'),
|
||||
'email' => Setting::getContentBySlug('dhl_sender_email') ?: config('dhl.sender.email'),
|
||||
'phone' => Setting::getContentBySlug('dhl_sender_phone') ?: config('dhl.sender.phone'),
|
||||
'company' => $this->getConfigValue('dhl_sender_company', config('dhl.sender.company'), $useEnvPriority),
|
||||
'name' => $this->getConfigValue('dhl_sender_name', config('dhl.sender.name'), $useEnvPriority),
|
||||
'street' => $this->getConfigValue('dhl_sender_street', config('dhl.sender.street'), $useEnvPriority),
|
||||
'houseNumber' => $this->getConfigValue('dhl_sender_house_number', config('dhl.sender.houseNumber'), $useEnvPriority),
|
||||
'postalCode' => $this->getConfigValue('dhl_sender_postal_code', config('dhl.sender.postalCode'), $useEnvPriority),
|
||||
'city' => $this->getConfigValue('dhl_sender_city', config('dhl.sender.city'), $useEnvPriority),
|
||||
'country' => $this->getConfigValue('dhl_sender_country', config('dhl.sender.country'), $useEnvPriority),
|
||||
'email' => $this->getConfigValue('dhl_sender_email', config('dhl.sender.email'), $useEnvPriority),
|
||||
'phone' => $this->getConfigValue('dhl_sender_phone', config('dhl.sender.phone'), $useEnvPriority),
|
||||
],
|
||||
|
||||
// Account Numbers
|
||||
'account_numbers' => [
|
||||
'V01PAK' => Setting::getContentBySlug('dhl_account_v01pak') ?: config('dhl.account_numbers.V01PAK'),
|
||||
'V62WP' => Setting::getContentBySlug('dhl_account_v62wp') ?: config('dhl.account_numbers.V62WP'),
|
||||
'V53PAK' => Setting::getContentBySlug('dhl_account_v53pak') ?: config('dhl.account_numbers.V53PAK'),
|
||||
'V07PAK' => Setting::getContentBySlug('dhl_account_v07pak') ?: config('dhl.account_numbers.V07PAK'),
|
||||
'V01PAK' => $this->getConfigValue('dhl_account_v01pak', config('dhl.account_numbers.V01PAK'), $useEnvPriority),
|
||||
'V62WP' => $this->getConfigValue('dhl_account_v62wp', config('dhl.account_numbers.V62WP'), $useEnvPriority),
|
||||
'V53PAK' => $this->getConfigValue('dhl_account_v53pak', config('dhl.account_numbers.V53PAK'), $useEnvPriority),
|
||||
'V07PAK' => $this->getConfigValue('dhl_account_v07pak', config('dhl.account_numbers.V07PAK'), $useEnvPriority),
|
||||
'default' => config('dhl.account_numbers.default'),
|
||||
],
|
||||
|
||||
|
||||
// Dimensions
|
||||
'dimensions' => [
|
||||
'V01PAK' => config('dhl.dimensions.V01PAK'),
|
||||
|
|
@ -111,6 +115,27 @@ class SettingController extends Controller
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration value based on priority setting
|
||||
*
|
||||
* @param string $settingSlug The database setting slug
|
||||
* @param mixed $configValue The config/env fallback value
|
||||
* @param bool $useEnvPriority Whether to prioritize env over database
|
||||
* @return mixed
|
||||
*/
|
||||
private function getConfigValue(string $settingSlug, $configValue, bool $useEnvPriority)
|
||||
{
|
||||
$dbValue = Setting::getContentBySlug($settingSlug);
|
||||
|
||||
if ($useEnvPriority) {
|
||||
// ENV priority: Use config value if available, otherwise fall back to database
|
||||
return $configValue ?: $dbValue;
|
||||
} else {
|
||||
// Database priority (default): Use database value if available, otherwise fall back to config
|
||||
return $dbValue ?: $configValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update DHL configuration cache after saving settings
|
||||
*/
|
||||
|
|
@ -125,7 +150,7 @@ class SettingController extends Controller
|
|||
// You could add a connection test here if needed
|
||||
\Log::info('DHL configuration updated successfully');
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('DHL configuration update failed: ' . $e->getMessage());
|
||||
\Log::error('DHL configuration update failed: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,14 +4,13 @@ namespace App\Http\Controllers\User;
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserAbo;
|
||||
use App\Models\UserAboItem;
|
||||
use App\Repositories\AboRepository;
|
||||
use App\Services\AboHelper;
|
||||
use App\Services\AboItemHistoryService;
|
||||
use App\Services\AboOrderCart;
|
||||
use App\Services\Shop;
|
||||
use App\Services\UserService;
|
||||
use App\User;
|
||||
use Request;
|
||||
use Yard;
|
||||
|
|
@ -41,7 +40,7 @@ class AboController extends Controller
|
|||
return view('user.abo.index', [
|
||||
'user_abos' => [],
|
||||
'view' => 'me',
|
||||
'isAdmin' => false
|
||||
'isAdmin' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +54,7 @@ class AboController extends Controller
|
|||
return view('user.abo.index', [
|
||||
'user_abos' => $user_abos,
|
||||
'view' => 'ot',
|
||||
'isAdmin' => false
|
||||
'isAdmin' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -63,22 +62,19 @@ class AboController extends Controller
|
|||
return view('user.abo.index', [
|
||||
'user_abos' => [],
|
||||
'view' => 'me',
|
||||
'isAdmin' => false
|
||||
'isAdmin' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function detail($view, $id)
|
||||
{
|
||||
$data = Request::all();
|
||||
$user_abo = UserAbo::findOrFail($id);
|
||||
|
||||
|
||||
$this->checkPermissions($view, $user_abo);
|
||||
|
||||
//init Yard
|
||||
// init Yard
|
||||
AboOrderCart::initYard($user_abo);
|
||||
//holt die aktuellen UserAccount Daten oder die Userdaten des Abo
|
||||
// holt die aktuellen UserAccount Daten oder die Userdaten des Abo
|
||||
$customer_detail = AboOrderCart::getCustomerDetail();
|
||||
AboOrderCart::makeOrderYard($user_abo);
|
||||
|
||||
|
|
@ -94,113 +90,129 @@ class AboController extends Controller
|
|||
'view' => $view,
|
||||
'comp_products' => $comp_products,
|
||||
];
|
||||
|
||||
return view('user.abo.detail', $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function update($view, $id)
|
||||
{
|
||||
$data = Request::all();
|
||||
$user_abo = UserAbo::findOrFail($id);
|
||||
|
||||
$this->checkPermissions($view, $user_abo);
|
||||
$isAddOnlyMode = AboHelper::isAddOnlyMode($user_abo, $view);
|
||||
|
||||
if (isset($data['action'])) {
|
||||
if ($data['action'] === 'abo_update_settings') {
|
||||
$user_abo = UserAbo::findOrFail($data['id']);
|
||||
$this->aboRepository->setModel($user_abo);
|
||||
$this->aboRepository->update($data);
|
||||
|
||||
return redirect(route('user_abos_detail', [$view, $id]));
|
||||
}
|
||||
|
||||
if (Request::ajax()) {
|
||||
$message = false;
|
||||
//addProduct
|
||||
// addProduct
|
||||
if ($data['action'] === 'addProduct') {
|
||||
if ($product = Product::find($data['product_id'])) {
|
||||
if ($UserAboItem = UserAboItem::where('user_abo_id', $user_abo->id)->where('product_id', $product->id)->where('comp', 0)->first()) {
|
||||
$qtyBefore = $UserAboItem->qty;
|
||||
$UserAboItem->qty = $UserAboItem->qty + 1;
|
||||
$UserAboItem->save();
|
||||
AboItemHistoryService::logProductAdded($user_abo, $UserAboItem, $qtyBefore, $view);
|
||||
} else {
|
||||
UserAboItem::create([
|
||||
$newItem = UserAboItem::create([
|
||||
'user_abo_id' => $user_abo->id,
|
||||
'product_id' => $product->id,
|
||||
'comp' => 0,
|
||||
'qty' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
AboItemHistoryService::logProductAdded($user_abo, $newItem, 0, $view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//updateCart
|
||||
// updateCart
|
||||
if ($data['action'] === 'updateCart') {
|
||||
//product_id | order_item_id | cart_order_id | qty
|
||||
// product_id | order_item_id | cart_order_id | qty
|
||||
if (isset($data['product_id']) && $product = Product::find($data['product_id'])) {
|
||||
if (isset($data['order_item_id']) && $UserAboItem = UserAboItem::find($data['order_item_id'])) {
|
||||
if (isset($data['qty'])) {
|
||||
$qtyBefore = $UserAboItem->qty;
|
||||
$qty = (int) $data['qty'];
|
||||
$qty = $qty < 1 ? 1 : $qty;
|
||||
$qty = $qty > 100 ? 100 : $qty;
|
||||
if ($isAddOnlyMode && $qty < $UserAboItem->qty) {
|
||||
$qty = $UserAboItem->qty;
|
||||
}
|
||||
$UserAboItem->qty = $qty;
|
||||
$UserAboItem->save();
|
||||
AboItemHistoryService::logQtyChanged($user_abo, $UserAboItem, $qtyBefore, $qty, $view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//removeFromCart
|
||||
// removeFromCart
|
||||
if ($data['action'] === 'removeFromCart') {
|
||||
if (!isset($data['product_id']) || !($product = Product::find($data['product_id']))) {
|
||||
if ($isAddOnlyMode) {
|
||||
return response()->json([
|
||||
'response' => false,
|
||||
'message' => __('abo.error_add_only_no_remove'),
|
||||
], 403);
|
||||
}
|
||||
if (! isset($data['product_id']) || ! ($product = Product::find($data['product_id']))) {
|
||||
$message = __('abo.product_not_found');
|
||||
}
|
||||
if (!isset($data['order_item_id']) || !($userAboItem = UserAboItem::find($data['order_item_id']))) {
|
||||
if (! isset($data['order_item_id']) || ! ($userAboItem = UserAboItem::find($data['order_item_id']))) {
|
||||
$message = __('abo.abo_item_not_found');
|
||||
}
|
||||
$has_basis_product = $this->check_need_basis_product($user_abo, $product, $data['order_item_id']);
|
||||
if (!$has_basis_product) {
|
||||
if (! $has_basis_product) {
|
||||
$message = __('abo.need_basis_product');
|
||||
}
|
||||
if (!$message) {
|
||||
|
||||
|
||||
if (! $message) {
|
||||
AboItemHistoryService::logProductRemoved($user_abo, $userAboItem, $view);
|
||||
$userAboItem->delete();
|
||||
$user_abo->refresh(); // Abo neu laden um die aktualisierten Items zu erhalten
|
||||
}
|
||||
}
|
||||
//updateCompProduct
|
||||
// updateCompProduct
|
||||
if ($data['action'] === 'updateCompProduct') {
|
||||
if ($UserAboItem = UserAboItem::where('user_abo_id', $user_abo->id)->where('comp', $data['comp_num'])->first()) {
|
||||
$oldProduct = $UserAboItem->product;
|
||||
$UserAboItem->product_id = $data['comp_product_id'];
|
||||
$UserAboItem->save();
|
||||
$UserAboItem->load('product');
|
||||
AboItemHistoryService::logCompProductChanged($user_abo, $UserAboItem, $oldProduct, $UserAboItem->product, $view);
|
||||
} else {
|
||||
UserAboItem::create([
|
||||
$newItem = UserAboItem::create([
|
||||
'user_abo_id' => $user_abo->id,
|
||||
'product_id' => $data['comp_product_id'],
|
||||
'comp' => $data['comp_num'],
|
||||
'qty' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
AboItemHistoryService::logProductAdded($user_abo, $newItem, 0, $view);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AboOrderCart::initYard($user_abo);
|
||||
AboOrderCart::makeOrderYard($user_abo); //reCalculateShippingPrice
|
||||
AboOrderCart::checkNumOfCompProducts($user_abo); //after reCalculateShippingPrice check it and remove or add comp product
|
||||
AboOrderCart::makeOrderYard($user_abo); // reCalculateShippingPrice
|
||||
AboOrderCart::checkNumOfCompProducts($user_abo); // after reCalculateShippingPrice check it and remove or add comp product
|
||||
|
||||
if ($user_abo->is_for === 'me') {
|
||||
$data['comp_products'] = Shop::getCompProducts('abo-me');
|
||||
}
|
||||
$error_message = $message ? $message : false;
|
||||
$html_cart = view("admin.abo._order_abo_show", ['user_abo' => $user_abo, 'error_message' => $error_message])->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
$html_cart = view('admin.abo._order_abo_show', ['user_abo' => $user_abo, 'error_message' => $error_message, 'add_only_mode' => $isAddOnlyMode])->render();
|
||||
$html_comp = view('user.order.comp_product', $data)->render();
|
||||
|
||||
$amount = $user_abo->getFormattedAmount();
|
||||
|
||||
// $html_total = view("user.homeparty.show_total_order", ['homeparty' => $homeparty])->render();
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_cart' => $html_cart, 'html_comp' => $html_comp, 'amount' => $amount]);
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_cart' => $html_cart, 'html_comp' => $html_comp, 'amount' => $amount]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -212,11 +224,14 @@ class AboController extends Controller
|
|||
return true;
|
||||
}
|
||||
|
||||
// Prüfe ob noch ein anderes Basis-Produkt vorhanden ist
|
||||
// Prüfe ob noch ein anderes Basis-Produkt vorhanden ist (nur reguläre Items, keine Comp-Produkte)
|
||||
foreach ($user_abo->user_abo_items as $user_abo_item) {
|
||||
if ($user_abo_item->id == $order_item_id) {
|
||||
continue;
|
||||
}
|
||||
if ($user_abo_item->comp) {
|
||||
continue;
|
||||
}
|
||||
if (AboHelper::getAboShowOn($user_abo_item->product) === 'base') {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -228,11 +243,11 @@ class AboController extends Controller
|
|||
public function datatable($user_abo_id)
|
||||
{
|
||||
$user_abo = UserAbo::findOrFail($user_abo_id);
|
||||
if (!$user_abo) {
|
||||
if (! $user_abo) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
//$user_abo->is_for === 'me'
|
||||
// $user_abo->is_for === 'me'
|
||||
|
||||
$show_on_ids = ['12', '13'];
|
||||
$query = Product::select('products.*')
|
||||
|
|
@ -250,45 +265,49 @@ class AboController extends Controller
|
|||
[$show_on_ids[0], isset($show_on_ids[1]) ? $show_on_ids[1] : $show_on_ids[0]]
|
||||
);
|
||||
|
||||
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('add_card', function (Product $product) use ($user_abo) {
|
||||
$ufactor = $user_abo->is_for === 'me' ? true : false;
|
||||
$tax_free = $user_abo->is_for === 'me' ? true : Yard::instance('shopping')->getUserTaxFree();
|
||||
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="' . $product->id . '">
|
||||
<strong>€ ' . $product->getFormattedPriceWith($tax_free, $ufactor, Yard::instance('shopping')->getUserCountry()) . '</strong> +<span class="ion ion-md-cart"></span>
|
||||
$tax_free = $user_abo->is_for === 'me' ? true : Yard::instance('shopping')->getUserTaxFree();
|
||||
|
||||
$price = $product->getFormattedPriceWith($tax_free, $ufactor, Yard::instance('shopping')->getUserCountry());
|
||||
|
||||
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="'.$product->id.'" data-product-name="'.e($product->getLang('name')).'" data-product-price="'.$price.' €">
|
||||
<strong>€ '.$price.'</strong> +<span class="ion ion-md-cart"></span>
|
||||
</button>';
|
||||
})
|
||||
->addColumn('picture', function (Product $product) {
|
||||
if (count($product->images)) {
|
||||
return '<img class="img-fluid img-extra" alt="" src="' . route('product_image', [$product->images->first()->slug]) . '">';
|
||||
return '<img class="img-fluid img-extra" alt="" src="'.route('product_image', [$product->images->first()->slug]).'">';
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
})
|
||||
->addColumn('name', function (Product $product) use ($user_abo) {
|
||||
return '<strong>' . $product->getLang('name') . '</strong><br>' . get_abo_type_badge_by_product($product);
|
||||
->addColumn('name', function (Product $product) {
|
||||
return '<strong>'.$product->getLang('name').'</strong><br>'.get_abo_type_badge_by_product($product);
|
||||
})
|
||||
->addColumn('points', function (Product $product) use ($user_abo) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPoints() . '</span>';
|
||||
->addColumn('points', function (Product $product) {
|
||||
return '<span class="no-line-break">'.$product->getFormattedPoints().'</span>';
|
||||
})
|
||||
->addColumn('price_net', function (Product $product) use ($user_abo) {
|
||||
$ufactor = $user_abo->is_for === 'me' ? true : false;
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(true, $ufactor, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, $ufactor, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('price_gross', function (Product $product) use ($user_abo) {
|
||||
$ufactor = $user_abo->is_for === 'me' ? true : false;
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(false, $ufactor, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, $ufactor, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('action', function (Product $product) {
|
||||
return '<button class="btn btn-default btn-sm icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="' . $product->id . '" data-route="' . route('modal_load') . '"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="'.$product->id.'" data-route="'.route('modal_load').'"
|
||||
data-action="user-order-show-product" data-view="customer"><i class="ion ion-md-eye"></i></button>';
|
||||
})
|
||||
->filterColumn('product', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->where('name', 'LIKE', '%' . $keyword . '%');
|
||||
if ($keyword != '') {
|
||||
$query->where('name', 'LIKE', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->orderColumn('name', 'name $1')
|
||||
|
|
@ -304,20 +323,26 @@ class AboController extends Controller
|
|||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function checkPermissions($view, $user_abo)
|
||||
{
|
||||
\Log::info('checkPermissions', ['view' => $view, 'user_abo' => $user_abo]);
|
||||
$user = \Auth::user();
|
||||
|
||||
// Admins dürfen alle Abos bearbeiten
|
||||
if ($user && $user->isAdmin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($view === 'me' && $user_abo->is_for !== 'me') {
|
||||
abort(403, 'Unauthorized action. Is not for me');
|
||||
}
|
||||
if ($view === 'ot' && $user_abo->is_for !== 'ot') {
|
||||
abort(403, 'Unauthorized action. Is not your customer');
|
||||
}
|
||||
if ($view === 'me' && $user_abo->user_id !== \Auth::user()->id) {
|
||||
if ($view === 'me' && $user_abo->user_id !== $user->id) {
|
||||
abort(403, 'Unauthorized action. Is not my abo');
|
||||
}
|
||||
if ($view === 'ot' && $user_abo->member_id !== \Auth::user()->id) {
|
||||
if ($view === 'ot' && $user_abo->member_id !== $user->id) {
|
||||
abort(403, 'Unauthorized action. Is not my customer abo');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,23 +2,22 @@
|
|||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use Auth;
|
||||
use Util;
|
||||
use Yard;
|
||||
use Carbon;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\MailInfo;
|
||||
use App\Models\Product;
|
||||
use App\Services\Payment;
|
||||
use App\Models\UserHistory;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Services\UserService;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\UserHistory;
|
||||
use App\Services\Payment;
|
||||
use App\Services\UserService;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Carbon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
use Request;
|
||||
use Util;
|
||||
use Yard;
|
||||
|
||||
class MembershipController extends Controller
|
||||
{
|
||||
|
|
@ -32,19 +31,18 @@ class MembershipController extends Controller
|
|||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$user = User::find(Auth::user()->id);
|
||||
$diff_months = 0;
|
||||
|
||||
if($user->payment_account){
|
||||
$diff_months = Carbon::now()->diffInMonths(Carbon::parse($user->payment_account)) +1;
|
||||
if ($user->payment_account) {
|
||||
$diff_months = Carbon::now()->diffInMonths(Carbon::parse($user->payment_account)) + 1;
|
||||
}
|
||||
|
||||
|
||||
$userShoppingOrders = ShoppingOrder::with('shopping_user', 'shopping_payments')->select('shopping_orders.*')
|
||||
->where('auth_user_id', '=', $user->id)
|
||||
->where('txaction', '!=', NULL)
|
||||
->where('txaction', '!=', null)
|
||||
->whereIn('payment_for', [1, 2])
|
||||
->orderBy('created_at', 'DESC')
|
||||
->get();
|
||||
|
|
@ -52,34 +50,33 @@ class MembershipController extends Controller
|
|||
$userHistoryPaymentOrder = null;
|
||||
$userHistoryUpgradeOrder = null;
|
||||
|
||||
/* Bezhalung ist nur 29 Tage vor ablauf möglich */
|
||||
/* Bezhalung ist nur 29 Tage vor ablauf möglich */
|
||||
/* isRenewalAccount payment_account date - config('mivita.renewal_days') Vertragsverlängerung */
|
||||
if($user->isRenewalAccount()){
|
||||
//Acount ist noch nicht verlängert / bezahlt
|
||||
if ($user->isRenewalAccount()) {
|
||||
// Acount ist noch nicht verlängert / bezahlt
|
||||
if ($user->payment_account) {
|
||||
//Die Order muss größer als das Datum sein.
|
||||
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days')+1).' days');
|
||||
// Die Order muss größer als das Datum sein.
|
||||
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days') + 1).' days');
|
||||
$userHistoryPaymentOrder = UserHistory::whereUserId($user->id)->whereAction('payment_order')->where('created_at', '>=', $payment_greaterThan)->get()->last();
|
||||
}
|
||||
}
|
||||
if($user->isActiveAccount() && !$user->isActiveShop()){
|
||||
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days')+1).' days');
|
||||
if ($user->isActiveAccount() && ! $user->isActiveShop()) {
|
||||
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days') + 1).' days');
|
||||
$userHistoryUpgradeOrder = UserHistory::whereUserId($user->id)->whereAction('upgrade_order')->where('created_at', '>=', $payment_greaterThan)->get()->last();
|
||||
|
||||
}
|
||||
$userHistoryDeleteMembership = UserHistory::whereUserId($user->id)->whereAction('delete_membership')->whereStatus(50)->get()->last();
|
||||
|
||||
|
||||
$shipping_country_id = $this->checkShoppingCountry($user);
|
||||
if(!$shipping_country_id){
|
||||
if (! $shipping_country_id) {
|
||||
abort(403, __('validation.custom.shipping_not_found'));
|
||||
}
|
||||
|
||||
UserService::checkUserTaxShippingCountry($user, $shipping_country_id);
|
||||
|
||||
|
||||
$data = [
|
||||
'user' => $user,
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'upgrade' => Product::where('active', true)->whereJsonContains('show_on', '8')->where('identifier', 'upgrade')->get(),
|
||||
'diff_months' => $diff_months,
|
||||
'userHistoryPaymentOrder' => $userHistoryPaymentOrder,
|
||||
|
|
@ -88,86 +85,90 @@ class MembershipController extends Controller
|
|||
'yard_info' => UserService::getYardInfo(),
|
||||
'userShoppingOrders' => $userShoppingOrders,
|
||||
];
|
||||
|
||||
return view('user.membership.index', $data);
|
||||
|
||||
}
|
||||
|
||||
private function checkShoppingCountry($user ){
|
||||
private function checkShoppingCountry($user)
|
||||
{
|
||||
|
||||
$country_id = null;
|
||||
if($user->account->same_as_billing){
|
||||
if ($user->account->same_as_billing) {
|
||||
$country_id = $user->account->country_id;
|
||||
}else{
|
||||
} else {
|
||||
$country_id = $user->account->shipping_country_id;
|
||||
}
|
||||
if($country_id){
|
||||
if($shipping_country = ShippingCountry::whereCountryId($country_id)->first()){
|
||||
if ($country_id) {
|
||||
if ($shipping_country = ShippingCountry::whereCountryId($country_id)->first()) {
|
||||
return $shipping_country->id;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function storePayment($action){
|
||||
|
||||
public function storePayment($action)
|
||||
{
|
||||
|
||||
$data = Request::all();
|
||||
|
||||
//#### remove_abo
|
||||
if($action === "remove_abo"){
|
||||
if(Request::get('abo_options_remove')){
|
||||
// #### remove_abo
|
||||
if ($action === 'remove_abo') {
|
||||
if (Request::get('abo_options_remove')) {
|
||||
$user = User::find(Auth::user()->id);
|
||||
$user->abo_options = false;
|
||||
$user->save();
|
||||
$user->account->payment_data = null;
|
||||
$user->account->save();
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'abo_options_remove', 'status'=>10]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => 'abo_options_remove', 'status' => 10]);
|
||||
\Session()->flash('alert-success', __('msg.abo_deaktivert'));
|
||||
|
||||
return back();
|
||||
}
|
||||
\Session()->flash('alert-error', __('msg.error_checkbox_not_confirm'));
|
||||
|
||||
return back();
|
||||
}
|
||||
//#### payment order
|
||||
//#### shop upgrade
|
||||
if($action === "upgrade_order" || $action === "payment_order"){
|
||||
if(Request::get('switchers-package-wizard')){
|
||||
// #### payment order
|
||||
// #### shop upgrade
|
||||
if ($action === 'upgrade_order' || $action === 'payment_order') {
|
||||
if (Request::get('switchers-package-wizard')) {
|
||||
$user = User::find(Auth::user()->id);
|
||||
Yard::instance('shopping')->destroy();
|
||||
$product = Product::find(Request::get('switchers-package-wizard'));
|
||||
$showAboOptions = false;
|
||||
if(Request::get('abo_options')){
|
||||
$showAboOptions = false; //true Abo Option deaktivert
|
||||
$user->abo_options = false; //true Abo Option deaktivert
|
||||
if (Request::get('abo_options')) {
|
||||
$showAboOptions = false; // true Abo Option deaktivert
|
||||
$user->abo_options = false; // true Abo Option deaktivert
|
||||
$user->save();
|
||||
}
|
||||
|
||||
$shipping_country_id = $this->checkShoppingCountry($user);
|
||||
if(!$shipping_country_id){
|
||||
if (! $shipping_country_id) {
|
||||
abort(403, __('validation.custom.shipping_not_found'));
|
||||
}
|
||||
|
||||
|
||||
UserService::checkUserTaxShippingCountry($user, $shipping_country_id);
|
||||
Yard::instance('shopping')->setUserPriceInfos(UserService::getYardInfo());
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id);
|
||||
|
||||
|
||||
if($product && $product->active){
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
if ($product && $product->active) {
|
||||
$image = '';
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$qty = Request::get('qty') ? Request::get('qty') : 1;
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), $qty, $product->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
|
||||
if(\App\Services\UserService::getTaxFree()){
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), $qty, $product->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'show_on' => $product->show_on]);
|
||||
if (\App\Services\UserService::getTaxFree()) {
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}else{
|
||||
} else {
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(\App\Services\UserService::$user_country));
|
||||
}
|
||||
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
} while (ShoppingInstance::where('identifier', $identifier)->count());
|
||||
|
||||
$data = [];
|
||||
$data['is_from'] = 'membership';
|
||||
|
|
@ -176,9 +177,9 @@ class MembershipController extends Controller
|
|||
|
||||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => 1, //is first faker shop for nuy intern
|
||||
'user_shop_id' => 1, // is first faker shop for nuy intern
|
||||
'auth_user_id' => Auth::user()->id,
|
||||
'payment' => 3, //Berater Membership
|
||||
'payment' => 3, // Berater Membership
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
|
|
@ -187,54 +188,59 @@ class MembershipController extends Controller
|
|||
|
||||
]);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
//add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>1, 'product_id'=>$product->id, 'identifier'=>$identifier, 'abo_options'=>$showAboOptions]);
|
||||
//$path = str_replace('http', 'https', $path);
|
||||
// add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier' => $identifier]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => $action, 'status' => 1, 'product_id' => $product->id, 'identifier' => $identifier, 'abo_options' => $showAboOptions]);
|
||||
|
||||
// $path = str_replace('http', 'https', $path);
|
||||
return redirect()->secure($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($action === "change_order"){
|
||||
if(Request::get('switchers-package-wizard')){
|
||||
if ($action === 'change_order') {
|
||||
if (Request::get('switchers-package-wizard')) {
|
||||
$user = User::find(Auth::user()->id);
|
||||
$product = Product::find(Request::get('switchers-package-wizard'));
|
||||
if($user->payment_order_id == $product->id){
|
||||
if ($user->payment_order_id == $product->id) {
|
||||
\Session()->flash('alert-success', __('msg.no_change_made'));
|
||||
|
||||
return back();
|
||||
}
|
||||
if($product && $product->active){
|
||||
if ($product && $product->active) {
|
||||
$user->payment_order_id = $product->id;
|
||||
$user->save();
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>10, 'product_id'=>$product->id]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => $action, 'status' => 10, 'product_id' => $product->id]);
|
||||
\Session()->flash('alert-success', __('msg.booked_package_has_been_changed'));
|
||||
|
||||
return back();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if($action === "delete_membership"){
|
||||
if(Request::get('delete_membership_mivita')){
|
||||
//TODO
|
||||
if ($action === 'delete_membership') {
|
||||
if (Request::get('delete_membership_mivita')) {
|
||||
// TODO
|
||||
$user = User::find(Auth::user()->id);
|
||||
if($user->isTestMode()){
|
||||
if ($user->isTestMode()) {
|
||||
$mail = config('app.info_test_mail');
|
||||
}else{
|
||||
} else {
|
||||
$mail = config('app.info_mail');
|
||||
}
|
||||
Mail::to($mail)->send(new MailInfo($user, 'delete_membership'));
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>50]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => $action, 'status' => 50]);
|
||||
\Session()->flash('alert-success', __('msg.cancel_membership_is_requested'));
|
||||
|
||||
return back();
|
||||
}
|
||||
\Session()->flash('alert-error', __('msg.error_checkbox_not_confirm'));
|
||||
|
||||
return back();
|
||||
|
||||
}
|
||||
\Session()->flash('alert-error', __('msg.error_checkbox_not_confirm'));
|
||||
|
||||
return back();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,15 +11,14 @@ use App\Models\ShoppingOrder;
|
|||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserHistory;
|
||||
use App\Services\AboHelper;
|
||||
use App\Services\MyLog;
|
||||
use App\Services\OrderPaymentService;
|
||||
use App\Services\Payment;
|
||||
use App\Services\Shop;
|
||||
use App\Services\UserService;
|
||||
use App\Services\Util;
|
||||
use App\Services\MyLog;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request as IlluminateRequest;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Request;
|
||||
|
|
@ -68,20 +67,20 @@ class OrderController extends Controller
|
|||
$query = ShoppingOrder::with('shopping_user', 'shopping_payments')
|
||||
->select('shopping_orders.*')
|
||||
->where('auth_user_id', '=', $user->id)
|
||||
->where('txaction', '!=', NULL);
|
||||
->where('txaction', '!=', null);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<a href="' . route('user_order_detail', [$ShoppingOrder->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
return '<a href="'.route('user_order_detail', [$ShoppingOrder->id]).'" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->created_at->format("d.m.Y");
|
||||
return $ShoppingOrder->created_at->format('d.m.Y');
|
||||
})
|
||||
->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getShoppingOrderBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="no-line-break">' . $ShoppingOrder->getFormattedTotalShipping() . " €</span>";
|
||||
return '<span class="no-line-break">'.$ShoppingOrder->getFormattedTotalShipping().' €</span>';
|
||||
})
|
||||
->addColumn('payment', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('getPaymentType');
|
||||
|
|
@ -89,21 +88,22 @@ class OrderController extends Controller
|
|||
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
|
||||
if ($ShoppingOrder->payment_for === 8) {
|
||||
return '<button type="button" class="btn btn-xs btn-info btn-round" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="' . $ShoppingOrder->id . '"
|
||||
data-id="'.$ShoppingOrder->id.'"
|
||||
data-action="shop-user-order-shipping-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="user"
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-eye"></span></button>';
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-eye"></span></button>';
|
||||
}
|
||||
return '<span class="badge badge-pill badge-' . $ShoppingOrder->getShippedColor() . '">' . $ShoppingOrder->getShippedType() . '</span>';
|
||||
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>';
|
||||
})
|
||||
->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getPaymentForBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="' . route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']) . '" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="' . route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']) . '" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
})
|
||||
->addColumn('reference', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('reference');
|
||||
|
|
@ -130,16 +130,18 @@ class OrderController extends Controller
|
|||
$shopping_user = Shop::checkShoppingUser($id, $user);
|
||||
$delivery_id = $shopping_user->id;
|
||||
|
||||
if (!Shop::checkShoppingCountry($for, $delivery_id) && !\Session()->has('custom-error')) {
|
||||
if (! Shop::checkShoppingCountry($for, $delivery_id) && ! \Session()->has('custom-error')) {
|
||||
$country = Shop::getDeliveryCountry($for, $delivery_id);
|
||||
\Session()->flash('custom-error', $country . ": " . __('validation.custom.shipping_not_found'));
|
||||
\Session()->flash('custom-error', $country.': '.__('validation.custom.shipping_not_found'));
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping country not found for user #{$user->id}, country: {$country}");
|
||||
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
|
||||
if ($for === 'abo-ot-customer') {
|
||||
if (AboHelper::hasAboByEmail($shopping_user->billing_email) && !\Session()->has('custom-error')) {
|
||||
if (AboHelper::hasAboByEmail($shopping_user->billing_email) && ! \Session()->has('custom-error')) {
|
||||
\Session()->flash('custom-error', __('abo.error_email_has_abo', ['email' => $shopping_user->billing_email]));
|
||||
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
}
|
||||
|
|
@ -150,6 +152,7 @@ class OrderController extends Controller
|
|||
if (strpos(Request::get('switchers-radio-is-for'), 'ot') !== false) {
|
||||
$delivery_id = $id;
|
||||
}
|
||||
|
||||
return redirect(route('user_order_my_list', [Request::get('switchers-radio-is-for'), $delivery_id]));
|
||||
}
|
||||
|
||||
|
|
@ -183,10 +186,11 @@ class OrderController extends Controller
|
|||
UserService::initCustomerYard($shopping_user, $for);
|
||||
} else {
|
||||
$shipping_country_id = Shop::checkShoppingCountry($for, $id);
|
||||
if (!$shipping_country_id) {
|
||||
if (! $shipping_country_id) {
|
||||
$country = Shop::getDeliveryCountry($for, $id);
|
||||
\Session()->flash('custom-error', $country . ": " . __('validation.custom.shipping_not_found'));
|
||||
\Session()->flash('custom-error', $country.': '.__('validation.custom.shipping_not_found'));
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Shipping country not found for user #{$user->id}, country: {$country}");
|
||||
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
UserService::initUserYard($user, $shipping_country_id, $for);
|
||||
|
|
@ -221,7 +225,6 @@ class OrderController extends Controller
|
|||
];
|
||||
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
|
|
@ -229,23 +232,23 @@ class OrderController extends Controller
|
|||
try {
|
||||
$this->checkSendYardForPayment($data, $id);
|
||||
} catch (\Exception $e) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Error checking yard for payment: " . $e->getMessage(), [
|
||||
Log::channel(self::LOG_CHANNEL)->error('Error checking yard for payment: '.$e->getMessage(), [
|
||||
'user_id' => $user->id,
|
||||
'for' => $for,
|
||||
'id' => $id
|
||||
'id' => $id,
|
||||
]);
|
||||
return back()->with('error', $e->getMessage());
|
||||
|
||||
return back()->withErrors(['error' => $e->getMessage()])->withInput(Request::all());
|
||||
}
|
||||
|
||||
if (Yard::instance('shopping')->getNumComp() > 0) {
|
||||
if (!isset($data['switchers-comp-product'])) {
|
||||
if (! isset($data['switchers-comp-product'])) {
|
||||
$validator->errors()->add('switchers-comp-product', __('msg.please_select_compensation_product'));
|
||||
} else if (!is_array($data['switchers-comp-product'])) {
|
||||
} elseif (! is_array($data['switchers-comp-product'])) {
|
||||
$validator->errors()->add('switchers-comp-product', __('msg.please_select_compensation_product'));
|
||||
} else if (count($data['switchers-comp-product']) !== Yard::instance('shopping')->getNumComp()) {
|
||||
} elseif (count($data['switchers-comp-product']) !== Yard::instance('shopping')->getNumComp()) {
|
||||
$validator->errors()->add('switchers-comp-product', __('mdg.please_select_count_compensation_products', ['count' => Yard::instance('shopping')->getNumComp()]));
|
||||
}
|
||||
|
||||
if ($validator->errors()->count()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
|
|
@ -268,7 +271,6 @@ class OrderController extends Controller
|
|||
// Remove unnecessary data
|
||||
unset($data['quantity']);
|
||||
unset($data['_token']);
|
||||
|
||||
if ($for === 'ot-customer' || $for === 'abo-ot-customer') {
|
||||
return $this->processCustomerPayment($user, $identifier, $data, $id, $for);
|
||||
} else {
|
||||
|
|
@ -281,13 +283,14 @@ class OrderController extends Controller
|
|||
*/
|
||||
private function processCustomerPayment($user, $identifier, $data, $id, $for)
|
||||
{
|
||||
$shopping_user = ShoppingUser::find($id);
|
||||
$shopping_instance = ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => $user->shop->id,
|
||||
'payment' => 6, // Berater Shop to Customer Shop
|
||||
'subdomain' => $user->shop->getSubdomain(),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'language' => $shopping_user->getLocale(), // hier wird die Sprache des Kunden verwendet
|
||||
'amount' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
|
||||
'status' => 0,
|
||||
'shopping_user_id' => $id,
|
||||
|
|
@ -302,9 +305,9 @@ class OrderController extends Controller
|
|||
try {
|
||||
$this->customPaymentSendMail($user, $identifier, $yard_shopping_items, $data);
|
||||
} catch (\Exception $e) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Failed to send custom payment email: " . $e->getMessage(), [
|
||||
Log::channel(self::LOG_CHANNEL)->error('Failed to send custom payment email: '.$e->getMessage(), [
|
||||
'identifier' => $identifier,
|
||||
'user_id' => $user->id
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -314,7 +317,7 @@ class OrderController extends Controller
|
|||
'status' => 1,
|
||||
'product_id' => null,
|
||||
'identifier' => $identifier,
|
||||
'is_abo' => $data['is_abo']
|
||||
'is_abo' => $data['is_abo'],
|
||||
]);
|
||||
|
||||
return redirect(route('user_order_my_custom_payment', ['identifier' => $identifier]));
|
||||
|
|
@ -333,7 +336,7 @@ class OrderController extends Controller
|
|||
'payment' => 2, // Berater Shop
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'language' => \App::getLocale(), // das ist richtig, hier wird die App-Locale verwendet da es vom user kommt
|
||||
'amount' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
|
||||
'status' => 0,
|
||||
'shopping_user_id' => $id,
|
||||
|
|
@ -349,10 +352,11 @@ class OrderController extends Controller
|
|||
'status' => 1,
|
||||
'product_id' => null,
|
||||
'identifier' => $identifier,
|
||||
'is_abo' => $data['is_abo']
|
||||
'is_abo' => $data['is_abo'],
|
||||
]);
|
||||
|
||||
$path = route('checkout.checkout_card', ['identifier' => $identifier]);
|
||||
|
||||
return redirect()->secure($path);
|
||||
}
|
||||
|
||||
|
|
@ -369,68 +373,68 @@ class OrderController extends Controller
|
|||
}
|
||||
|
||||
$shipping_country_id = Shop::checkShoppingCountry($data['shipping_is_for'], $id);
|
||||
if (!$shipping_country_id) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
if (! $shipping_country_id) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier
|
||||
'yard_identifier' => $identifier,
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'no shipping_country_id found | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping country not found", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'no shipping_country_id found | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping country not found', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_country_was_not_found'));
|
||||
}
|
||||
|
||||
// Must be the same shipping country
|
||||
if ($shipping_country_id != Yard::instance('shopping')->getShippingCountryId()) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_country_id,
|
||||
'actual' => Yard::instance('shopping')->getShippingCountryId()
|
||||
'actual' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'shipping_country_id is not the same from Yard | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping country mismatch", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'shipping_country_id is not the same from Yard | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping country mismatch', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_country_was_not_correctly'));
|
||||
}
|
||||
|
||||
if ($data['shipping_is_for'] !== 'ot-customer') {
|
||||
if (Yard::instance('shopping')->shipping_free) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier
|
||||
'yard_identifier' => $identifier,
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard can by not shipping_free | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Yard cannot be shipping free", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'Yard can by not shipping_free | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Yard cannot be shipping free', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shopping_cart_was_shipping_free'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['shipping_is_for'] === 'ot-customer') {
|
||||
if (!$user->shop) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
if (! $user->shop) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier
|
||||
'yard_identifier' => $identifier,
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'User has no Shop for an User to Customer order| Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("User has no shop for customer order", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'User has no Shop for an User to Customer order| Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('User has no shop for customer order', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shopping_cart_was_not_user_shop'));
|
||||
}
|
||||
|
|
@ -438,107 +442,130 @@ class OrderController extends Controller
|
|||
|
||||
$shipping_price = Shop::getShippingPriceByShippingCountryId($shipping_country_id, Yard::instance('shopping')->weight());
|
||||
|
||||
// For other and has weight - check
|
||||
// For other and has weight - check
|
||||
if (strpos($data['shipping_is_for'], 'ot') !== false && $data['shipping_is_for'] !== 'ot-customer' && Yard::instance('shopping')->weight() > 0) {
|
||||
if (!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'weight' => Yard::instance('shopping')->weight()
|
||||
];
|
||||
// Prüfe ob Versandkostenfreiheit durch Freigrenze legitimiert ist
|
||||
$shipping_free = Yard::instance('shopping')->getShippingFree();
|
||||
$total = Yard::instance('shopping')->total(2, '.', '');
|
||||
$isFreeDueToThreshold = $shipping_free && $total >= $shipping_free && Yard::instance('shopping')->weightByFreeShipping() == 0;
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is 0 | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price cannot be zero for order with weight", $logData);
|
||||
if (! Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
|
||||
// Nur Fehler werfen, wenn Versandpreis 0 NICHT durch Freigrenze legitimiert ist
|
||||
if (! $isFreeDueToThreshold) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'weight' => Yard::instance('shopping')->weight(),
|
||||
'total' => $total,
|
||||
'shipping_free' => $shipping_free,
|
||||
];
|
||||
|
||||
throw new \Exception(__('msg.shipping_cost_cannot_be_0'));
|
||||
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is 0 | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping price cannot be zero for order with weight', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_cost_cannot_be_0'));
|
||||
}
|
||||
}
|
||||
|
||||
if (Yard::instance('shopping')->getShippingPrice() != $shipping_price->price) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
// Preisvergleich nur durchführen, wenn NICHT versandkostenfrei durch Freigrenze
|
||||
if (! $isFreeDueToThreshold && Yard::instance('shopping')->getShippingPrice() != $shipping_price->price) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_price->price,
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice()
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice(),
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is not the same from shipping_price | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price mismatch", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping price mismatch', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_costs_were_not_calculated_correctly'));
|
||||
}
|
||||
}
|
||||
|
||||
if (($data['shipping_is_for'] == 'me' || $data['shipping_is_for'] == 'abo-me') && Yard::instance('shopping')->weight() > 0) {
|
||||
if (!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'weight' => Yard::instance('shopping')->weight()
|
||||
];
|
||||
// Prüfe ob Versandkostenfreiheit durch Freigrenze legitimiert ist
|
||||
$shipping_free = Yard::instance('shopping')->getShippingFree();
|
||||
$total = Yard::instance('shopping')->total(2, '.', '');
|
||||
$isFreeDueToThreshold = $shipping_free && $total >= $shipping_free && Yard::instance('shopping')->weightByFreeShipping() == 0;
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is 0 | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price cannot be zero for personal order with weight", $logData);
|
||||
if (! Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
|
||||
// Nur Fehler werfen, wenn Versandpreis 0 NICHT durch Freigrenze legitimiert ist
|
||||
if (! $isFreeDueToThreshold) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'weight' => Yard::instance('shopping')->weight(),
|
||||
'total' => $total,
|
||||
'shipping_free' => $shipping_free,
|
||||
];
|
||||
|
||||
throw new \Exception(__('msg.shipping_cost_cannot_be_0'));
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is 0 | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping price cannot be zero for personal order with weight', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_cost_cannot_be_0'));
|
||||
}
|
||||
}
|
||||
|
||||
if (Shop::isCompProducts($data['shipping_is_for'])) {
|
||||
if (Yard::instance('shopping')->getShippingPrice() != $shipping_price->price_comp) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
// Preisvergleich nur durchführen, wenn NICHT versandkostenfrei durch Freigrenze
|
||||
if (! $isFreeDueToThreshold && Yard::instance('shopping')->getShippingPrice() != $shipping_price->price_comp) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_price->price_comp,
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice()
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice(),
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price with comp products | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price mismatch for personal order", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price with comp products | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping price mismatch for personal order', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_costs_were_not_calculated_correctly'));
|
||||
}
|
||||
|
||||
if (Yard::instance('shopping')->getNumComp() != $shipping_price->num_comp) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_price->num_comp,
|
||||
'actual' => Yard::instance('shopping')->getNumComp()
|
||||
'actual' => Yard::instance('shopping')->getNumComp(),
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard num_comp is not correct | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Compensation product count mismatch", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'Yard num_comp is not correct | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Compensation product count mismatch', $logData);
|
||||
|
||||
throw new \Exception(__('msg.compensation_products_cannot_be_0'));
|
||||
}
|
||||
} else {
|
||||
if (Yard::instance('shopping')->getShippingPrice() != $shipping_price->price) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
// Preisvergleich nur durchführen, wenn NICHT versandkostenfrei durch Freigrenze
|
||||
if (! $isFreeDueToThreshold && Yard::instance('shopping')->getShippingPrice() != $shipping_price->price) {
|
||||
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_price->price,
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice()
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice(),
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price without comp products | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price mismatch for personal order", $logData);
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price without comp products | Yard identifier: '.$identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shipping price mismatch for personal order', $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_costs_were_not_calculated_correctly'));
|
||||
}
|
||||
|
|
@ -593,15 +620,16 @@ class OrderController extends Controller
|
|||
$cartItem = Yard::instance('shopping')->getCartItemByProduct($product->id);
|
||||
$qty = isset($cartItem->qty) ? $cartItem->qty : 0;
|
||||
$rowId = isset($cartItem->rowId) ? $cartItem->rowId : '';
|
||||
return '<strong>' . $product->getLang('name') . '</strong><br>
|
||||
|
||||
return '<strong>'.$product->getLang('name').'</strong><br>
|
||||
<div class="no-line-break input-group-min-w">
|
||||
<div class="input-group d-inline-flex w-auto">
|
||||
<span class="input-group-prepend">
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra remove-product-basket" data-row-id="' . $rowId . '" data-product-id="' . $product->id . '">-</button>
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra remove-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">-</button>
|
||||
</span>
|
||||
<input type="text" class="form-control text-center input-extra table-input-event-onchange" name="product_qty_' . $product->id . '" data-row-id="' . $rowId . '" data-product-id="' . $product->id . '" value="' . $qty . '">
|
||||
<input type="text" class="form-control text-center input-extra table-input-event-onchange" name="product_qty_'.$product->id.'" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'" value="'.$qty.'">
|
||||
<span class="input-group-append">
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra add-product-basket" data-row-id="' . $rowId . '" data-product-id="' . $product->id . '">+</button>
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra add-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">+</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>';
|
||||
|
|
@ -611,39 +639,40 @@ class OrderController extends Controller
|
|||
})
|
||||
->addColumn('picture', function (Product $product) {
|
||||
if (count($product->images)) {
|
||||
return '<img class="img-fluid img-extra" alt="" src="' . route('product_image', [$product->images->first()->slug]) . '">';
|
||||
return '<img class="img-fluid img-extra" alt="" src="'.route('product_image', [$product->images->first()->slug]).'">';
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
})
|
||||
->addColumn('points', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPoints() . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPoints().'</span>';
|
||||
})
|
||||
->addColumn('price_net', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(true, true, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, true, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('price_gross', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(false, true, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(false, true, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, true, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, true, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('price_vk_gross', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(false, false, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(false, false, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, false, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, false, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('customer_price_net', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(true, false, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, false, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, false, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, false, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('customer_price_gross', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(false, false, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(false, false, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, false, Yard::instance('shopping')->getUserCountry()).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, false, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('my_commission_net', function (Product $product) {
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(true, false, Yard::instance('shopping')->getUserCountry(), true) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, false, Yard::instance('shopping')->getUserCountry(), true) . '</span>';
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, false, Yard::instance('shopping')->getUserCountry(), true).' €</span>'.'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, false, Yard::instance('shopping')->getUserCountry(), true).'</span>';
|
||||
})
|
||||
->addColumn('action', function (Product $product) {
|
||||
return '<button class="btn btn-default btn-sm icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="' . $product->id . '" data-route="' . route('modal_load') . '"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="'.$product->id.'" data-route="'.route('modal_load').'"
|
||||
data-action="user-order-show-product" data-view="customer"><i class="ion ion-md-eye"></i></button>';
|
||||
})
|
||||
->filterColumn('product', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->where('name', 'LIKE', '%' . $keyword . '%');
|
||||
if ($keyword != '') {
|
||||
$query->where('name', 'LIKE', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->orderColumn('name', 'name $1')
|
||||
|
|
@ -668,8 +697,9 @@ class OrderController extends Controller
|
|||
*/
|
||||
public function performRequest()
|
||||
{
|
||||
if (!Request::ajax()) {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Non-AJAX request to performRequest method");
|
||||
if (! Request::ajax()) {
|
||||
Log::channel(self::LOG_CHANNEL)->warning('Non-AJAX request to performRequest method');
|
||||
|
||||
return response()->json(['response' => false, 'message' => 'Only AJAX requests are allowed']);
|
||||
}
|
||||
|
||||
|
|
@ -678,9 +708,9 @@ class OrderController extends Controller
|
|||
$data['for'] = $is_for;
|
||||
$data['comp_products'] = Shop::getCompProducts($is_for);
|
||||
|
||||
Log::channel(self::LOG_CHANNEL)->info("Performing cart action", [
|
||||
Log::channel(self::LOG_CHANNEL)->info('Performing cart action', [
|
||||
'action' => $data['action'] ?? 'unknown',
|
||||
'is_for' => $is_for
|
||||
'is_for' => $is_for,
|
||||
]);
|
||||
|
||||
if ($data['action'] === 'updateCart' && isset($data['product_id'])) {
|
||||
|
|
@ -689,6 +719,7 @@ class OrderController extends Controller
|
|||
|
||||
if ($data['action'] === 'clearCart') {
|
||||
Yard::instance('shopping')->destroy();
|
||||
|
||||
return response()->json(['response' => true, 'data' => Yard::instance('shopping')->count(), 'html_card' => '', 'html_comp' => '']);
|
||||
}
|
||||
|
||||
|
|
@ -700,7 +731,8 @@ class OrderController extends Controller
|
|||
return $this->handleUpdateCompProduct($data, $is_for);
|
||||
}
|
||||
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Unknown action in performRequest", ['action' => $data['action'] ?? 'not set']);
|
||||
Log::channel(self::LOG_CHANNEL)->warning('Unknown action in performRequest', ['action' => $data['action'] ?? 'not set']);
|
||||
|
||||
return response()->json(['response' => false, 'data' => $data]);
|
||||
}
|
||||
|
||||
|
|
@ -710,12 +742,13 @@ class OrderController extends Controller
|
|||
private function handleUpdateCart($data, $is_for)
|
||||
{
|
||||
$product = Product::find($data['product_id']);
|
||||
if (!$product) {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Product not found for cart update", ['product_id' => $data['product_id']]);
|
||||
if (! $product) {
|
||||
Log::channel(self::LOG_CHANNEL)->warning('Product not found for cart update', ['product_id' => $data['product_id']]);
|
||||
|
||||
return response()->json(['response' => false, 'message' => 'Product not found']);
|
||||
}
|
||||
|
||||
$image = "";
|
||||
$image = '';
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
|
@ -730,7 +763,7 @@ class OrderController extends Controller
|
|||
round($product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), false, Yard::instance('shopping')->getUserCountry()), 1),
|
||||
false,
|
||||
false,
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'show_on' => $product->show_on]
|
||||
);
|
||||
} else {
|
||||
$cartItem = Yard::instance('shopping')
|
||||
|
|
@ -741,7 +774,7 @@ class OrderController extends Controller
|
|||
$product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), true, Yard::instance('shopping')->getUserCountry()),
|
||||
false,
|
||||
false,
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'show_on' => $product->show_on]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -761,8 +794,8 @@ class OrderController extends Controller
|
|||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
|
||||
|
||||
$html_card = view("user.order.yard_view_form", $data)->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
$html_card = view('user.order.yard_view_form', $data)->render();
|
||||
$html_comp = view('user.order.comp_product', $data)->render();
|
||||
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
|
||||
}
|
||||
|
|
@ -778,14 +811,14 @@ class OrderController extends Controller
|
|||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country->id, $is_for);
|
||||
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
|
||||
} else {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Shipping country not found", [
|
||||
'shipping_country_id' => $data['shipping_country_id']
|
||||
Log::channel(self::LOG_CHANNEL)->warning('Shipping country not found', [
|
||||
'shipping_country_id' => $data['shipping_country_id'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$html_card = view("user.order.yard_view_form", $data)->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
$html_card = view('user.order.yard_view_form', $data)->render();
|
||||
$html_comp = view('user.order.comp_product', $data)->render();
|
||||
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
|
||||
}
|
||||
|
|
@ -798,8 +831,8 @@ class OrderController extends Controller
|
|||
$this->updateCompProduct($data);
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
|
||||
$html_card = view("user.order.yard_view_form", $data)->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
$html_card = view('user.order.yard_view_form', $data)->render();
|
||||
$html_comp = view('user.order.comp_product', $data)->render();
|
||||
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
|
||||
}
|
||||
|
|
@ -826,8 +859,8 @@ class OrderController extends Controller
|
|||
foreach (Yard::instance('shopping')->content() as $row) {
|
||||
// If count_comp_products is smaller, the product was removed due to quantity
|
||||
// if comp_num equals the comp product, the product was removed due to new shipping costs
|
||||
//count_comp_products wie viele comp products werden gebraucht
|
||||
//comp_num welches comp product wird hinzugefügt
|
||||
// count_comp_products wie viele comp products werden gebraucht
|
||||
// comp_num welches comp product wird hinzugefügt
|
||||
if ($row->options->comp && ($row->options->comp == intval($data['comp_num']) || $row->options->comp > intval($data['count_comp_products']))) {
|
||||
Yard::instance('shopping')->remove($row->rowId);
|
||||
}
|
||||
|
|
@ -836,7 +869,7 @@ class OrderController extends Controller
|
|||
if (isset($data['comp_product_id'])) {
|
||||
$product = Product::find($data['comp_product_id']);
|
||||
if ($product) {
|
||||
$image = "";
|
||||
$image = '';
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
|
@ -853,14 +886,14 @@ class OrderController extends Controller
|
|||
'weight' => 0,
|
||||
'points' => 0,
|
||||
'comp' => intval($data['comp_num']),
|
||||
'product_id' => $product->id
|
||||
'product_id' => $product->id,
|
||||
]
|
||||
);
|
||||
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
} else {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Compensation product not found", [
|
||||
'comp_product_id' => $data['comp_product_id']
|
||||
Log::channel(self::LOG_CHANNEL)->warning('Compensation product not found', [
|
||||
'comp_product_id' => $data['comp_product_id'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -873,9 +906,10 @@ class OrderController extends Controller
|
|||
{
|
||||
try {
|
||||
$data = OrderPaymentService::getCustomPayment($identifier);
|
||||
|
||||
return view('user.order.payment.custom_payment', $data);
|
||||
} catch (\Exception $e) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Error accessing custom payment: " . $e->getMessage(), ['identifier' => $identifier]);
|
||||
Log::channel(self::LOG_CHANNEL)->error('Error accessing custom payment: '.$e->getMessage(), ['identifier' => $identifier]);
|
||||
abort(404, 'Custom payment not found');
|
||||
}
|
||||
}
|
||||
|
|
@ -888,22 +922,22 @@ class OrderController extends Controller
|
|||
$bcc = [];
|
||||
$shopping_instance = ShoppingInstance::where('identifier', $identifier)->first();
|
||||
|
||||
if (!$shopping_instance) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shopping instance not found for email", ['identifier' => $identifier]);
|
||||
if (! $shopping_instance) {
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shopping instance not found for email', ['identifier' => $identifier]);
|
||||
throw new \Exception(__('msg.shopping_instance_not_found'));
|
||||
}
|
||||
|
||||
$shopping_user = $data['shopping_user_id'] ? ShoppingUser::find($data['shopping_user_id']) : null;
|
||||
|
||||
if (!$shopping_user) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shopping user not found for email", ['shopping_user_id' => $data['shopping_user_id']]);
|
||||
if (! $shopping_user) {
|
||||
Log::channel(self::LOG_CHANNEL)->error('Shopping user not found for email', ['shopping_user_id' => $data['shopping_user_id']]);
|
||||
throw new \Exception(__('msg.shopping_user_not_found'));
|
||||
}
|
||||
|
||||
$route = route('checkout.checkout_card', ['identifier' => $identifier]);
|
||||
|
||||
$billing_email = $shopping_user->billing_email;
|
||||
if (!$billing_email) {
|
||||
if (! $billing_email) {
|
||||
$billing_email = $data['mode'] === 'test' ? config('app.checkout_test_mail') : config('app.checkout_mail');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
use Carbon;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Services\Credit;
|
||||
use App\Models\UserCredit;
|
||||
use App\Models\UserPayCredit;
|
||||
use App\Models\UserCreditItem;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
use App\Models\UserCredit;
|
||||
use App\Models\UserCreditItem;
|
||||
use App\Services\Credit;
|
||||
use App\User;
|
||||
use Request;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
|
||||
private $startYear;
|
||||
|
||||
private $endYear;
|
||||
|
||||
private $rangeYears;
|
||||
|
||||
private $activeYear;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
/* $this->startYear = 2021;
|
||||
/* $this->startYear = 2021;
|
||||
$this->endYear = date('Y');
|
||||
$this->rangeYears = range($this->startYear, $this->endYear);
|
||||
$this->activeYear = $this->endYear;*/
|
||||
|
|
@ -34,11 +34,12 @@ class PaymentController extends Controller
|
|||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
|
||||
return view('user.payment.credit', $data);
|
||||
}
|
||||
|
||||
|
||||
public function credit_datatable(){
|
||||
public function credit_datatable()
|
||||
{
|
||||
|
||||
$user = \Auth::user();
|
||||
$query = UserCredit::with('user', 'user.account')->select('user_credits.*')->where('user_id', $user->id);
|
||||
|
|
@ -46,29 +47,35 @@ class PaymentController extends Controller
|
|||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('view', function (UserCredit $UserCredit) {
|
||||
$ret = "";
|
||||
if(Credit::isCredit($UserCredit)){
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a><br>';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'html']).'" target="_blank" class="btn btn-secondary btn-xs mt-2"><i class="fa fa-eye"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'pdf']).'" target="_blank" class="btn btn-secondary btn-xs mt-2"><i class="fa fa-file-pdf" style="min-width:13.5px"></i></a> ';
|
||||
|
||||
}else{
|
||||
$ret = "-";
|
||||
$ret = '';
|
||||
if (Credit::isCredit($UserCredit)) {
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'download']).'" class="btn btn-primary btn-xs mb-2 mr-1"><i class="fa fa-download"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'stream']).'" target="_blank" class="btn btn-warning btn-xs mb-2 mr-1"><i class="fa fa-eye"></i></a>';
|
||||
$availableLocales = $UserCredit->getAvailableLocales();
|
||||
foreach ($availableLocales as $locale) {
|
||||
$ret .= ' <a href="'.route('storage_file', [$UserCredit->id, 'credit', 'download', $locale]).'" class="btn btn-outline-primary btn-xs mb-2 mr-1" title="Gutschrift '.strtoupper($locale).'"><i class="fa fa-download"></i> '.strtoupper($locale).'</a>';
|
||||
$ret .= ' <a href="'.route('storage_file', [$UserCredit->id, 'credit', 'stream', $locale]).'" class="btn btn-outline-warning btn-xs mb-2 mr-1" title="Gutschrift '.strtoupper($locale).'"><i class="fa fa-eye"></i> '.strtoupper($locale).'</a>';
|
||||
}
|
||||
$ret .= '<br>';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'html']).'" target="_blank" class="btn btn-secondary btn-xs mb-2 mr-1 "><i class="fa fa-eye"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'pdf']).'" target="_blank" class="btn btn-secondary btn-xs mb-2 mr-1"><i class="fa fa-file-pdf" style="min-width:13.5px"></i></a> ';
|
||||
} else {
|
||||
$ret = '-';
|
||||
}
|
||||
|
||||
return $ret;
|
||||
})
|
||||
->addColumn('total', function (UserCredit $UserCredit) {
|
||||
return $UserCredit->getFormattedTotal()." €";
|
||||
return $UserCredit->getFormattedTotal().' €';
|
||||
})
|
||||
->addColumn('credits', function (UserCredit $UserCredit) {
|
||||
$ret = "";
|
||||
if($UserCredit->user_credit_items){
|
||||
foreach($UserCredit->user_credit_items as $user_credit_item){
|
||||
$ret .= nl2br($user_credit_item->getTransMessage())." / ".$user_credit_item->created_at->format('d.m.Y')."<br>";
|
||||
|
||||
$ret = '';
|
||||
if ($UserCredit->user_credit_items) {
|
||||
foreach ($UserCredit->user_credit_items as $user_credit_item) {
|
||||
$ret .= nl2br($user_credit_item->getTransMessage()).' / '.$user_credit_item->created_at->format('d.m.Y').'<br>';
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
})
|
||||
->addColumn('status', function (UserCredit $UserCredit) {
|
||||
|
|
@ -81,18 +88,19 @@ class PaymentController extends Controller
|
|||
->make(true);
|
||||
}
|
||||
|
||||
public function credit_item_datatable(){
|
||||
public function credit_item_datatable()
|
||||
{
|
||||
|
||||
$user = \Auth::user();
|
||||
$query = UserCreditItem::select('user_credit_items.*')->where('user_id', $user->id);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
|
||||
->addColumn('message', function (UserCreditItem $user_credit_item) {
|
||||
return nl2br($user_credit_item->getTransMessage());
|
||||
})
|
||||
->addColumn('credit', function (UserCreditItem $user_credit_item) {
|
||||
return formatNumber($user_credit_item->credit)." €";
|
||||
return formatNumber($user_credit_item->credit).' €';
|
||||
})
|
||||
->addColumn('created_at', function (UserCreditItem $user_credit_item) {
|
||||
return formatDate($user_credit_item->created_at);
|
||||
|
|
@ -101,11 +109,11 @@ class PaymentController extends Controller
|
|||
return '<span class="badge badge-pill badge-'.$user_credit_item->getStatusColor().'">'.$user_credit_item->getStatusType().'</span> ';
|
||||
})
|
||||
->addColumn('paid', function (UserCreditItem $user_credit_item) {
|
||||
return ($user_credit_item->paid && $user_credit_item->user_credit) ?
|
||||
'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$user_credit_item->user_credit->full_number.'</span>'
|
||||
return ($user_credit_item->paid && $user_credit_item->user_credit) ?
|
||||
'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$user_credit_item->user_credit->full_number.'</span>'
|
||||
: '<span class="badge badge-pill badge-warning"><i class="fa fa-times"></i></span>';
|
||||
})
|
||||
|
||||
|
||||
->orderColumn('message', 'message $1')
|
||||
->orderColumn('credit', 'credit $1')
|
||||
->orderColumn('created_at', 'created_at $1')
|
||||
|
|
@ -114,13 +122,12 @@ class PaymentController extends Controller
|
|||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
/*private function setActiveYears(){
|
||||
if(Request::get('filter_year')){
|
||||
$this->activeYear = Request::get('filter_year');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function revenue()
|
||||
{
|
||||
$this->setActiveYears();
|
||||
|
|
@ -134,4 +141,4 @@ class PaymentController extends Controller
|
|||
];
|
||||
return view('user.payment.revenue', $data);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Exports\UserTeamExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\UserBusiness;
|
||||
use App\Models\UserLevel;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Services\AboHelper;
|
||||
use App\Services\BusinessPlan\ExportBot;
|
||||
use App\Services\BusinessPlan\TreeCalcBot;
|
||||
use App\Services\BusinessPlan\TreeCalcBotOptimized;
|
||||
|
|
@ -17,16 +16,12 @@ use App\Services\LevelReportService;
|
|||
use App\Services\NextLevelBadgeHelper;
|
||||
use App\Services\TranslationHelper;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use function Ramsey\Uuid\v1;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Request;
|
||||
|
||||
/**
|
||||
* Team Controller für User-Bereich
|
||||
*
|
||||
*
|
||||
* Erweitert um optimierte Versionen:
|
||||
* - show(): Optimierte Team-Übersicht mit Performance-Monitoring
|
||||
* - structure(): Nutzt TreeCalcBotOptimized für bessere Performance
|
||||
|
|
@ -36,9 +31,13 @@ use Request;
|
|||
class TeamController extends Controller
|
||||
{
|
||||
private $filter_active = [1 => '', 2 => '', 3 => '']; // Wird in getFilterActive() übersetzt
|
||||
|
||||
private $filter_next_level = [0 => '', 1 => '', 2 => '', 3 => '']; // Wird in getFilterNextLevel() übersetzt
|
||||
|
||||
private $month;
|
||||
|
||||
private $year;
|
||||
|
||||
private $forceLiveCalculation;
|
||||
|
||||
public function __construct()
|
||||
|
|
@ -46,8 +45,6 @@ class TeamController extends Controller
|
|||
$this->middleware('active.account');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Zeigt die Team-Übersicht mit optimierter TreeCalcBotOptimized-Datenverarbeitung
|
||||
* Lädt Team-Daten für DataTable-Anzeige
|
||||
|
|
@ -67,19 +64,19 @@ class TeamController extends Controller
|
|||
$forceLiveCalculation = Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
$forceLiveCalculation = false;
|
||||
|
||||
\Log::info("TeamController: Building optimized team overview for user {$user->id} ({$this->month}/{$this->year})" .
|
||||
($forceLiveCalculation === true ? " with forced live calculation" : "not live calculation"));
|
||||
\Log::info("TeamController: Building optimized team overview for user {$user->id} ({$this->month}/{$this->year})".
|
||||
($forceLiveCalculation === true ? ' with forced live calculation' : 'not live calculation'));
|
||||
|
||||
// Verwende TreeCalcBotOptimized für bessere Performance
|
||||
//$TreeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'member', $forceLiveCalculation);
|
||||
//$TreeCalcBot->initStructureUser($user->id);
|
||||
// $TreeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'member', $forceLiveCalculation);
|
||||
// $TreeCalcBot->initStructureUser($user->id);
|
||||
$endTime = microtime(true);
|
||||
$endMemory = memory_get_usage();
|
||||
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$memoryUsed = $this->formatBytes($endMemory - $startMemory);
|
||||
|
||||
$calculationType = $forceLiveCalculation ? " (LIVE)" : " (CACHE)";
|
||||
$calculationType = $forceLiveCalculation ? ' (LIVE)' : ' (CACHE)';
|
||||
\Log::info("TeamController: Optimized team overview built in {$executionTime}ms, Memory: {$memoryUsed}{$calculationType}");
|
||||
|
||||
$data = [
|
||||
|
|
@ -88,21 +85,22 @@ class TeamController extends Controller
|
|||
'filter_active' => $this->getFilterActive(),
|
||||
'filter_levels' => $this->getFilterLevels(),
|
||||
'filter_next_level' => $this->getFilterNextLevel(),
|
||||
//'TreeCalcBot' => $TreeCalcBot,
|
||||
// 'TreeCalcBot' => $TreeCalcBot,
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'memory_used' => $memoryUsed,
|
||||
'user_id' => $user->id,
|
||||
'user_count' => 0, //$TreeCalcBot->getTotalUserCount(),
|
||||
'user_count' => 0, // $TreeCalcBot->getTotalUserCount(),
|
||||
'version' => 'Optimized',
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache'
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache',
|
||||
],
|
||||
'optimized' => true,
|
||||
'forceLiveCalculation' => $forceLiveCalculation,
|
||||
];
|
||||
|
||||
return view('user.team.show', $data);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error in optimized show for user {$user->id}: " . $e->getMessage());
|
||||
\Log::error("TeamController: Error in optimized show for user {$user->id}: ".$e->getMessage());
|
||||
|
||||
// Fallback mit minimalen Daten
|
||||
$endTime = microtime(true);
|
||||
|
|
@ -114,12 +112,12 @@ class TeamController extends Controller
|
|||
'filter_active' => $this->getFilterActive(),
|
||||
'filter_levels' => $this->getFilterLevels(),
|
||||
'filter_next_level' => $this->getFilterNextLevel(),
|
||||
'error' => __('team.error_loading_optimized_overview') . $e->getMessage(),
|
||||
'error' => __('team.error_loading_optimized_overview').$e->getMessage(),
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'memory_used' => 'N/A',
|
||||
'version' => 'Fallback',
|
||||
'calculation_type' => 'Error'
|
||||
'calculation_type' => 'Error',
|
||||
],
|
||||
'optimized' => false,
|
||||
];
|
||||
|
|
@ -175,8 +173,8 @@ class TeamController extends Controller
|
|||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$memoryUsed = $this->formatBytes($endMemory - $startMemory);
|
||||
|
||||
$versionInfo = ($optimizedUsed ? "OPTIMIZED" : "STANDARD") .
|
||||
($forceLiveCalculation ? " + LIVE" : " + CACHE");
|
||||
$versionInfo = ($optimizedUsed ? 'OPTIMIZED' : 'STANDARD').
|
||||
($forceLiveCalculation ? ' + LIVE' : ' + CACHE');
|
||||
|
||||
\Log::info("TeamController: Structure built for user {$user->id} in {$executionTime}ms, Memory: {$memoryUsed} ({$versionInfo})");
|
||||
|
||||
|
|
@ -191,7 +189,7 @@ class TeamController extends Controller
|
|||
? $TreeCalcBot->getTotalUserCount()
|
||||
: '-',
|
||||
'version' => $optimizedUsed ? 'Optimized' : 'Standard',
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache'
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache',
|
||||
],
|
||||
'optimized' => $optimizedUsed,
|
||||
'forceLiveCalculation' => $forceLiveCalculation,
|
||||
|
|
@ -199,7 +197,7 @@ class TeamController extends Controller
|
|||
|
||||
return view('user.team.structure', $data);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error in structure for user {$user->id}: " . $e->getMessage());
|
||||
\Log::error("TeamController: Error in structure for user {$user->id}: ".$e->getMessage());
|
||||
|
||||
// Fallback zur Standard-Implementierung
|
||||
$TreeCalcBot = new TreeCalcBot(session('team_user_filter_month'), session('team_user_filter_year'), 'member');
|
||||
|
|
@ -212,13 +210,13 @@ class TeamController extends Controller
|
|||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
'TreeCalcBot' => $TreeCalcBot,
|
||||
'error' => 'Fehler aufgetreten, Standard-Version wird verwendet: ' . $e->getMessage(),
|
||||
'error' => 'Fehler aufgetreten, Standard-Version wird verwendet: '.$e->getMessage(),
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'memory_used' => 'N/A',
|
||||
'user_count' => '-',
|
||||
'version' => 'Fallback',
|
||||
'calculation_type' => $forceLiveCalculation ? __('team.live_not_supported_fallback') : __('team.cache')
|
||||
'calculation_type' => $forceLiveCalculation ? __('team.live_not_supported_fallback') : __('team.cache'),
|
||||
],
|
||||
'optimized' => false,
|
||||
'forceLiveCalculation' => $forceLiveCalculation,
|
||||
|
|
@ -227,6 +225,7 @@ class TeamController extends Controller
|
|||
return view('user.team.structure', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function structureOld()
|
||||
{
|
||||
abort(403, 'This page is removed');
|
||||
|
|
@ -237,17 +236,17 @@ class TeamController extends Controller
|
|||
$this->setFilterVars();
|
||||
$TreeCalcBot = new TreeCalcBot(session('team_user_filter_month'), session('team_user_filter_year'), 'member');
|
||||
$TreeCalcBot->initStructureUser($user->id);
|
||||
//for testing
|
||||
//$TreeCalcBot->initUser(56);
|
||||
// for testing
|
||||
// $TreeCalcBot->initUser(56);
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
'TreeCalcBot' => $TreeCalcBot,
|
||||
];
|
||||
|
||||
return view('user.team.structure', $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Optimierte DataTable für Team-Übersicht mit TreeCalcBotOptimized-Daten
|
||||
* Nutzt bereits berechnete Business-Daten für bessere Performance
|
||||
|
|
@ -265,8 +264,8 @@ class TeamController extends Controller
|
|||
// Prüfe ob Live-Berechnung erzwungen werden soll
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
$forceLiveCalculation = false;
|
||||
\Log::info("TeamController: Building optimized datatable for user {$user->id} ({$this->month}/{$this->year})" .
|
||||
($forceLiveCalculation == true ? " with forced live calculation" : ""));
|
||||
\Log::info("TeamController: Building optimized datatable for user {$user->id} ({$this->month}/{$this->year})".
|
||||
($forceLiveCalculation == true ? ' with forced live calculation' : ''));
|
||||
|
||||
// Lade TreeCalcBotOptimized-Daten
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'member', $forceLiveCalculation);
|
||||
|
|
@ -277,30 +276,36 @@ class TeamController extends Controller
|
|||
// KRITISCH: Bereinige die Objekte für DataTables (entferne zirkuläre Referenzen)
|
||||
$teamUsers = collect($this->cleanBusinessUserItemsForDataTable($teamUsersRaw));
|
||||
|
||||
\Log::info("TeamController: TeamUsers cleaned for DataTable: " . $teamUsers->count());
|
||||
\Log::info('TeamController: TeamUsers cleaned for DataTable: '.$teamUsers->count());
|
||||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$this->forceLiveCalculation = $forceLiveCalculation;
|
||||
|
||||
\Log::info("TeamController: Optimized datatable data prepared in {$executionTime}ms for " . $teamUsers->count() . " users");
|
||||
\Log::info("TeamController: Optimized datatable data prepared in {$executionTime}ms for ".$teamUsers->count().' users');
|
||||
|
||||
return \DataTables::of($teamUsers)
|
||||
->addColumn('id', function ($teamUser) {
|
||||
return '<button type="button" class="btn icon-btn btn-xs btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="' . $teamUser->user_id . '"
|
||||
data-id="'.$teamUser->user_id.'"
|
||||
data-action="business-user-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="member"
|
||||
data-live="' . $this->forceLiveCalculation . '"
|
||||
data-live="'.$this->forceLiveCalculation.'"
|
||||
data-optimized="1"
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-calculator"></span></button>';
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-calculator"></span></button>';
|
||||
})
|
||||
->addColumn('m_account', function ($teamUser) {
|
||||
return $teamUser->m_account;
|
||||
})
|
||||
->addColumn('email', function ($teamUser) {
|
||||
return e($teamUser->email);
|
||||
$button = '<a href="#" class="text-black" data-toggle="modal" data-target="#modals-load-content" '.
|
||||
'data-id="'.$teamUser->user_id.'" data-action="business-user-show" data-back="" '.
|
||||
'data-modal="modal-md" data-init_from="member" data-route="'.route('modal_load').'">'.
|
||||
'<span class="mr-1 ion ion-ios-contact"></span> '.
|
||||
'</a>';
|
||||
|
||||
return $button.e($teamUser->email);
|
||||
})
|
||||
->addColumn('first_name', function ($teamUser) {
|
||||
return e($teamUser->first_name);
|
||||
|
|
@ -313,6 +318,7 @@ class TeamController extends Controller
|
|||
})
|
||||
->addColumn('is_qual_kp', function ($teamUser) {
|
||||
$user = User::find($teamUser->user_id);
|
||||
|
||||
return TreeHelperOptimized::generateQualKPBadgeForUser($user, $this->month, $this->year);
|
||||
})
|
||||
->addColumn('sales_volume_KP_points', function ($teamUser) {
|
||||
|
|
@ -331,18 +337,19 @@ class TeamController extends Controller
|
|||
if ($userBusiness) {
|
||||
return NextLevelBadgeHelper::generateBadgeFromUserBusiness($userBusiness);
|
||||
}
|
||||
|
||||
return NextLevelBadgeHelper::renderNoDataBadge();
|
||||
})
|
||||
->addColumn('active_account', function ($teamUser) {
|
||||
return get_active_badge($teamUser->active_account);
|
||||
})
|
||||
->addColumn('payment_account_date', function ($teamUser) {
|
||||
return $teamUser->active_date ? formatDate($teamUser->active_date) : "-";
|
||||
return $teamUser->active_date ? formatDate($teamUser->active_date) : '-';
|
||||
})
|
||||
->rawColumns(['id', 'next_level_qualified', 'active_account', 'is_qual_kp', 'sales_volume_KP_points', 'sales_volume_total'])
|
||||
->rawColumns(['id', 'email', 'next_level_qualified', 'active_account', 'is_qual_kp', 'sales_volume_KP_points', 'sales_volume_total'])
|
||||
->make(true);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error in optimized datatable: " . $e->getMessage());
|
||||
\Log::error('TeamController: Error in optimized datatable: '.$e->getMessage());
|
||||
|
||||
// Fallback zur Standard-DataTable
|
||||
return $this->datatable();
|
||||
|
|
@ -361,12 +368,12 @@ class TeamController extends Controller
|
|||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (User $teamUser) {
|
||||
return '<button type="button" class="btn icon-btn btn-xs btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="' . $teamUser->id . '"
|
||||
data-id="'.$teamUser->id.'"
|
||||
data-action="team-user-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="member"
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-eye"></span></button>';
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-eye"></span></button>';
|
||||
})
|
||||
->addColumn('m_account', function (User $teamUser) {
|
||||
return $teamUser->account ? e($teamUser->account->m_account) : '';
|
||||
|
|
@ -375,7 +382,7 @@ class TeamController extends Controller
|
|||
return $teamUser->user_level ? e($teamUser->user_level->getLang('name')) : '';
|
||||
})
|
||||
->addColumn('is_qual_kp', function (User $teamUser) {
|
||||
if (!$teamUser->user_level) {
|
||||
if (! $teamUser->user_level) {
|
||||
return '-';
|
||||
}
|
||||
$qualKP = (int) $teamUser->user_level->qual_kp;
|
||||
|
|
@ -384,7 +391,8 @@ class TeamController extends Controller
|
|||
$pointsSum = (int) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_points_KP_sum');
|
||||
$isQual = $pointsSum >= $qualKP;
|
||||
$badgeClass = $isQual ? 'badge-outline-success' : 'badge-outline-warning-dark';
|
||||
return '<span class="badge ' . $badgeClass . '"> KU ' . $qualKP . '</span>';
|
||||
|
||||
return '<span class="badge '.$badgeClass.'"> KU '.$qualKP.'</span>';
|
||||
})
|
||||
->addColumn('sales_volume_KP_points', function (User $teamUser) {
|
||||
$month = Request::get('team_user_filter_month') ?: session('team_user_filter_month');
|
||||
|
|
@ -392,8 +400,9 @@ class TeamController extends Controller
|
|||
$total = (int) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_points_KP_sum');
|
||||
$individual = (int) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_KP_points');
|
||||
$shop = (int) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_points_shop');
|
||||
return '<div class="no-line-break">' . $total . '</div>' .
|
||||
'<span class="small no-line-break">E: ' . $individual . ' | S: ' . $shop . '</span>';
|
||||
|
||||
return '<div class="no-line-break">'.$total.'</div>'.
|
||||
'<span class="small no-line-break">E: '.$individual.' | S: '.$shop.'</span>';
|
||||
})
|
||||
->addColumn('sales_volume_total', function (User $teamUser) {
|
||||
$month = Request::get('team_user_filter_month') ?: session('team_user_filter_month');
|
||||
|
|
@ -401,8 +410,9 @@ class TeamController extends Controller
|
|||
$total = (float) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_total_sum');
|
||||
$individual = (float) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_total');
|
||||
$shop = (float) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_total_shop');
|
||||
return '<div class="no-line-break">' . formatNumber($total) . ' €</div>' .
|
||||
'<span class="small no-line-break">E: ' . formatNumber($individual) . ' | S: ' . formatNumber($shop) . ' €</span>';
|
||||
|
||||
return '<div class="no-line-break">'.formatNumber($total).' €</div>'.
|
||||
'<span class="small no-line-break">E: '.formatNumber($individual).' | S: '.formatNumber($shop).' €</span>';
|
||||
})
|
||||
->addColumn('email', function (User $teamUser) {
|
||||
return e($teamUser->email);
|
||||
|
|
@ -414,24 +424,25 @@ class TeamController extends Controller
|
|||
return $teamUser->account ? e($teamUser->account->last_name) : '';
|
||||
})
|
||||
->addColumn('sponsor', function (User $teamUser) {
|
||||
if (!$teamUser->user_sponsor) {
|
||||
if (! $teamUser->user_sponsor) {
|
||||
return '-';
|
||||
}
|
||||
$sponsor = $teamUser->user_sponsor;
|
||||
$html = '';
|
||||
if ($sponsor->account) {
|
||||
$html .= e($sponsor->account->first_name . ' ' . $sponsor->account->last_name);
|
||||
$html .= '<br><span class="small no-line-break">' . e($sponsor->email);
|
||||
$html .= ' | ' . e($sponsor->account->m_account);
|
||||
$html .= e($sponsor->account->first_name.' '.$sponsor->account->last_name);
|
||||
$html .= '<br><span class="small no-line-break">'.e($sponsor->email);
|
||||
$html .= ' | '.e($sponsor->account->m_account);
|
||||
$html .= '</span>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
})
|
||||
->addColumn('active_account', function (User $teamUser) {
|
||||
return get_active_badge($teamUser->isActiveAccount());
|
||||
})
|
||||
->addColumn('payment_account_date', function (User $teamUser) {
|
||||
return $teamUser->payment_account ? $teamUser->getPaymentAccountDateFormat(false) : "-";
|
||||
return $teamUser->payment_account ? $teamUser->getPaymentAccountDateFormat(false) : '-';
|
||||
})
|
||||
->addColumn('next_level_qualified', function (User $teamUser) {
|
||||
// Verwende bereits berechnete UserBusiness-Daten für bessere Performance
|
||||
|
|
@ -450,29 +461,29 @@ class TeamController extends Controller
|
|||
return NextLevelBadgeHelper::renderNoDataBadge();
|
||||
})
|
||||
->filterColumn('m_account', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
if ($keyword != '') {
|
||||
$query->whereHas('account', function ($q) use ($keyword) {
|
||||
$q->where('m_account', 'LIKE', '%' . $keyword . '%');
|
||||
$q->where('m_account', 'LIKE', '%'.$keyword.'%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filterColumn('first_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
if ($keyword != '') {
|
||||
$query->whereHas('account', function ($q) use ($keyword) {
|
||||
$q->where('first_name', 'LIKE', '%' . $keyword . '%');
|
||||
$q->where('first_name', 'LIKE', '%'.$keyword.'%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filterColumn('last_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
if ($keyword != '') {
|
||||
$query->whereHas('account', function ($q) use ($keyword) {
|
||||
$q->where('last_name', 'LIKE', '%' . $keyword . '%');
|
||||
$q->where('last_name', 'LIKE', '%'.$keyword.'%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filterColumn('email', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->where('email', 'LIKE', '%' . $keyword . '%');
|
||||
if ($keyword != '') {
|
||||
$query->where('email', 'LIKE', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->orderColumn('id', 'users.id $1')
|
||||
|
|
@ -484,10 +495,10 @@ class TeamController extends Controller
|
|||
->rawColumns(['id', 'is_qual_kp', 'sales_volume_KP_points', 'sales_volume_total', 'sponsor', 'active_account', 'next_level_qualified'])
|
||||
->make(true);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error in userDatatable: " . $e->getMessage());
|
||||
\Log::error('TeamController: Error in userDatatable: '.$e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'error' => 'Team-Datatable konnte nicht geladen werden: ' . $e->getMessage()
|
||||
'error' => 'Team-Datatable konnte nicht geladen werden: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
|
@ -510,7 +521,7 @@ class TeamController extends Controller
|
|||
$onlyNotUpdated = Request::boolean('not_updated', false);
|
||||
|
||||
// Prüfe ob Live-Berechnung erzwungen werden soll
|
||||
$forceLiveCalculation = false; //Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
$forceLiveCalculation = false; // Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
|
||||
\Log::info("TeamController: Building level reports for user {$user->id} ({$month}/{$year})");
|
||||
|
||||
|
|
@ -519,7 +530,7 @@ class TeamController extends Controller
|
|||
$treeCalcBot->initStructureUser($user->id, $forceLiveCalculation);
|
||||
|
||||
// Lade Level-Reports für Team
|
||||
$levelReportService = new LevelReportService();
|
||||
$levelReportService = new LevelReportService;
|
||||
$filters = ['only_not_updated' => $onlyNotUpdated];
|
||||
$promotions = $levelReportService->getTeamLevelPromotions($treeCalcBot, $month, $year, $filters);
|
||||
$statistics = $levelReportService->getStatistics($promotions);
|
||||
|
|
@ -527,7 +538,7 @@ class TeamController extends Controller
|
|||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
|
||||
\Log::info("TeamController: Level reports loaded for user {$user->id} in {$executionTime}ms - " . $promotions->count() . " promotions found");
|
||||
\Log::info("TeamController: Level reports loaded for user {$user->id} in {$executionTime}ms - ".$promotions->count().' promotions found');
|
||||
|
||||
$availableYears = range(date('Y'), date('Y') - 5);
|
||||
$availableMonths = [
|
||||
|
|
@ -542,7 +553,7 @@ class TeamController extends Controller
|
|||
9 => __('cal.months.September'),
|
||||
10 => __('cal.months.October'),
|
||||
11 => __('cal.months.November'),
|
||||
12 => __('cal.months.December')
|
||||
12 => __('cal.months.December'),
|
||||
];
|
||||
|
||||
$data = [
|
||||
|
|
@ -551,22 +562,22 @@ class TeamController extends Controller
|
|||
'filters' => [
|
||||
'month' => $month,
|
||||
'year' => $year,
|
||||
'only_not_updated' => $onlyNotUpdated
|
||||
'only_not_updated' => $onlyNotUpdated,
|
||||
],
|
||||
'availableYears' => $availableYears,
|
||||
'availableMonths' => $availableMonths,
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'user_id' => $user->id
|
||||
]
|
||||
'user_id' => $user->id,
|
||||
],
|
||||
];
|
||||
|
||||
return view('user.team.level-reports', $data);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error loading level reports: " . $e->getMessage());
|
||||
\Log::error('TeamController: Error loading level reports: '.$e->getMessage());
|
||||
|
||||
return view('user.team.level-reports', [
|
||||
'error' => 'Fehler beim Laden der Level-Reports: ' . $e->getMessage(),
|
||||
'error' => 'Fehler beim Laden der Level-Reports: '.$e->getMessage(),
|
||||
'promotions' => collect([]),
|
||||
'statistics' => ['total_count' => 0, 'level_stats' => [], 'period_stats' => []],
|
||||
'filters' => ['month' => date('m'), 'year' => date('Y'), 'only_not_updated' => false],
|
||||
|
|
@ -583,8 +594,8 @@ class TeamController extends Controller
|
|||
9 => __('cal.months.September'),
|
||||
10 => __('cal.months.October'),
|
||||
11 => __('cal.months.November'),
|
||||
12 => __('cal.months.December')
|
||||
]
|
||||
12 => __('cal.months.December'),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -608,7 +619,7 @@ class TeamController extends Controller
|
|||
$treeCalcBot->initStructureUser($user->id, $forceLiveCalculation);
|
||||
|
||||
// Lade Level-Reports
|
||||
$levelReportService = new LevelReportService();
|
||||
$levelReportService = new LevelReportService;
|
||||
$filters = ['only_not_updated' => $onlyNotUpdated];
|
||||
$promotions = $levelReportService->getTeamLevelPromotions($treeCalcBot, $month, $year, $filters);
|
||||
|
||||
|
|
@ -617,13 +628,14 @@ class TeamController extends Controller
|
|||
}
|
||||
|
||||
// CSV erstellen
|
||||
$filename = 'team_level_promotions_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
$filename = 'team_level_promotions_'.date('Y-m-d_H-i-s').'.csv';
|
||||
$filepath = $levelReportService->exportToCsv($promotions, $filename);
|
||||
|
||||
return response()->download($filepath, $filename)->deleteFileAfterSend(true);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error exporting level reports: " . $e->getMessage());
|
||||
return redirect()->back()->with('error', 'Fehler beim Export: ' . $e->getMessage());
|
||||
\Log::error('TeamController: Error exporting level reports: '.$e->getMessage());
|
||||
|
||||
return redirect()->back()->with('error', 'Fehler beim Export: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -654,19 +666,19 @@ class TeamController extends Controller
|
|||
'currentUser' => $user,
|
||||
'currentLevel' => $currentLevel,
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime
|
||||
]
|
||||
'execution_time' => $executionTime,
|
||||
],
|
||||
];
|
||||
|
||||
return view('user.team.marketingplan', $data);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error loading marketingplan: " . $e->getMessage());
|
||||
\Log::error('TeamController: Error loading marketingplan: '.$e->getMessage());
|
||||
|
||||
return view('user.team.marketingplan', [
|
||||
'error' => __('marketingplan.loading_error') . ' ' . $e->getMessage(),
|
||||
'error' => __('marketingplan.loading_error').' '.$e->getMessage(),
|
||||
'userLevels' => collect(),
|
||||
'currentUser' => null,
|
||||
'currentLevel' => null
|
||||
'currentLevel' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -678,14 +690,15 @@ class TeamController extends Controller
|
|||
{
|
||||
$user = User::find(\Auth::user()->id);
|
||||
if ($user->isActiveShop() && $user->shop) {
|
||||
$shop_register_link = $user->shop->getSubdomain(false) . "/reg";
|
||||
$shop_register_link = $user->shop->getSubdomain(false).'/reg';
|
||||
} else {
|
||||
$member_id = 'm' . ($user->id + config('mivita.add_number_id'));
|
||||
$shop_register_link = config('app.protocol') . config('app.domain') . config('app.tld_care') . '/reg/' . $member_id;
|
||||
$member_id = 'm'.($user->id + config('mivita.add_number_id'));
|
||||
$shop_register_link = config('app.protocol').config('app.domain').config('app.tld_care').'/reg/'.$member_id;
|
||||
}
|
||||
$data = [
|
||||
'shop_register_link' => $shop_register_link
|
||||
'shop_register_link' => $shop_register_link,
|
||||
];
|
||||
|
||||
return view('user.team.members', $data);
|
||||
}
|
||||
|
||||
|
|
@ -697,24 +710,8 @@ class TeamController extends Controller
|
|||
$user = User::find(\Auth::user()->id);
|
||||
$this->setFilterVars();
|
||||
|
||||
// Nutze TreeCalcBotOptimized um das Team zu bekommen
|
||||
$month = session('team_user_filter_month');
|
||||
$year = session('team_user_filter_year');
|
||||
|
||||
// Lade Team-Struktur
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($month, $year, 'member', false);
|
||||
$TreeCalcBot->initStructureUser($user->id, false);
|
||||
|
||||
// Hole flache Liste aller Team-Mitglieder
|
||||
$teamUsersRaw = $this->getTeamUsersFromStructure($TreeCalcBot);
|
||||
|
||||
// Sammle User-IDs für Abo-Abfrage
|
||||
$teamUserIds = [];
|
||||
foreach ($teamUsersRaw as $teamUser) {
|
||||
if ($teamUser->user_id && $teamUser->user_id != $user->id) {
|
||||
$teamUserIds[] = $teamUser->user_id;
|
||||
}
|
||||
}
|
||||
// Hole Team-Mitglieder-IDs effizient via Sponsor-Hierarchie
|
||||
$teamUserIds = AboHelper::getTeamUserIds($user->id);
|
||||
|
||||
// Hole Abos der Team-Mitglieder
|
||||
$abos = \App\Models\UserAbo::whereIn('user_id', $teamUserIds)
|
||||
|
|
@ -740,24 +737,8 @@ class TeamController extends Controller
|
|||
$user = User::find(\Auth::user()->id);
|
||||
$user_abo = \App\Models\UserAbo::findOrFail($id);
|
||||
|
||||
// Prüfe ob das Abo zu einem Team-Mitglied gehört
|
||||
$this->setFilterVars();
|
||||
$month = session('team_user_filter_month');
|
||||
$year = session('team_user_filter_year');
|
||||
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($month, $year, 'member', false);
|
||||
$TreeCalcBot->initStructureUser($user->id, false);
|
||||
|
||||
$teamUsersRaw = $this->getTeamUsersFromStructure($TreeCalcBot);
|
||||
$teamUserIds = [];
|
||||
foreach ($teamUsersRaw as $teamUser) {
|
||||
if ($teamUser->user_id) {
|
||||
$teamUserIds[] = $teamUser->user_id;
|
||||
}
|
||||
}
|
||||
|
||||
// Prüfe Berechtigung
|
||||
if (!in_array($user_abo->user_id, $teamUserIds)) {
|
||||
// Prüfe ob das Abo zu einem Team-Mitglied gehört (effizient via Sponsor-Kette)
|
||||
if (! AboHelper::isUserInTeam($user->id, $user_abo->user_id)) {
|
||||
abort(403, 'Unauthorized action. This subscription does not belong to your team.');
|
||||
}
|
||||
|
||||
|
|
@ -819,6 +800,7 @@ class TeamController extends Controller
|
|||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
];
|
||||
|
||||
return view('user.team.points', $data);
|
||||
}
|
||||
|
||||
|
|
@ -826,27 +808,28 @@ class TeamController extends Controller
|
|||
{
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
if (!$user->isVIP()) {
|
||||
if (! $user->isVIP()) {
|
||||
abort(404);
|
||||
}
|
||||
$ExportBot = new ExportBot('member');
|
||||
$ExportBot->initStructureUser($user, 'list'); //tree or list
|
||||
$ExportBot->initStructureUser($user, 'list'); // tree or list
|
||||
$data = [
|
||||
'ExportBot' => $ExportBot,
|
||||
];
|
||||
|
||||
return view('user.team.export', $data);
|
||||
}
|
||||
|
||||
public function userTeamExport()
|
||||
{
|
||||
|
||||
if (Request::get('action') === "export") {
|
||||
if (Request::get('action') === 'export') {
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$ExportBot = new ExportBot('member');
|
||||
$ExportBot->initStructureUser($user, 'list'); //tree or list
|
||||
$ExportBot->initStructureUser($user, 'list'); // tree or list
|
||||
$columns = [];
|
||||
$filename = __('team.filename_export') . date('Y-m-d-H-i-s');
|
||||
$headers = array(
|
||||
$filename = __('team.filename_export').date('Y-m-d-H-i-s');
|
||||
$headers = [
|
||||
__('tables.line'),
|
||||
__('tables.level'),
|
||||
__('tables.email'),
|
||||
|
|
@ -864,10 +847,10 @@ class TeamController extends Controller
|
|||
__('tables.account'),
|
||||
__('tables.account_to'),
|
||||
__('tables.sponsor'),
|
||||
);
|
||||
];
|
||||
if (isset($ExportBot->user_list->childs)) {
|
||||
foreach ($ExportBot->user_list->childs as $child) {
|
||||
$columns[] = array(
|
||||
$columns[] = [
|
||||
__('tables.line') => $child->line,
|
||||
__('tables.level') => $child->level_name,
|
||||
__('tables.email') => $child->email,
|
||||
|
|
@ -885,38 +868,39 @@ class TeamController extends Controller
|
|||
__('tables.account') => ($child->active_account == 1 ? __('yes') : __('no')),
|
||||
__('tables.account_to') => $child->payment_account_date,
|
||||
__('tables.sponsor') => $child->sponsor_name,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
return Excel::download(new UserTeamExport($columns, $headers), $filename . '.xls');
|
||||
|
||||
return Excel::download(new UserTeamExport($columns, $headers), $filename.'.xls');
|
||||
}
|
||||
}
|
||||
|
||||
private function setFilterVars()
|
||||
{
|
||||
|
||||
if (!session('team_user_filter_month')) {
|
||||
if (! session('team_user_filter_month')) {
|
||||
session(['team_user_filter_month' => intval(date('m'))]);
|
||||
}
|
||||
if (!session('team_user_filter_month_prev')) {
|
||||
if (! session('team_user_filter_month_prev')) {
|
||||
session(['team_user_filter_month_prev' => intval(date('m') - 1)]);
|
||||
}
|
||||
if (!session('team_user_filter_year')) {
|
||||
if (! session('team_user_filter_year')) {
|
||||
session(['team_user_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
if (!session('team_user_points_filter_month')) {
|
||||
if (! session('team_user_points_filter_month')) {
|
||||
session(['team_user_points_filter_month' => intval(date('m'))]);
|
||||
}
|
||||
if (!session('team_user_points_filter_year')) {
|
||||
if (! session('team_user_points_filter_year')) {
|
||||
session(['team_user_points_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
if (!session('team_user_filter_active')) {
|
||||
if (! session('team_user_filter_active')) {
|
||||
session(['team_user_filter_active' => 1]);
|
||||
}
|
||||
if (!session('team_user_filter_level')) {
|
||||
if (! session('team_user_filter_level')) {
|
||||
session(['team_user_filter_level' => 0]);
|
||||
}
|
||||
if (!session('team_user_filter_next_level')) {
|
||||
if (! session('team_user_filter_next_level')) {
|
||||
session(['team_user_filter_next_level' => 0]);
|
||||
}
|
||||
|
||||
|
|
@ -964,38 +948,39 @@ class TeamController extends Controller
|
|||
return $query;
|
||||
}
|
||||
|
||||
|
||||
public function datatablePoints()
|
||||
{
|
||||
|
||||
$query = $this->initSearchPoints();
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('order', function (UserSalesVolume $UserSalesVolume) {
|
||||
if ($UserSalesVolume->shopping_order) {
|
||||
if ($UserSalesVolume->status === 1 && $UserSalesVolume->shopping_order->auth_user_id === $UserSalesVolume->user_id) {
|
||||
return '<a href="' . route('user_order_detail', [$UserSalesVolume->shopping_order->id]) . '" class="btn btn-xs btn-primary">' . $UserSalesVolume->shopping_order->id . '</a>';
|
||||
return '<a href="'.route('user_order_detail', [$UserSalesVolume->shopping_order->id]).'" class="btn btn-xs btn-primary">'.$UserSalesVolume->shopping_order->id.'</a>';
|
||||
}
|
||||
if (($UserSalesVolume->status === 2 || $UserSalesVolume->status === 3) && $UserSalesVolume->shopping_order->member_id === $UserSalesVolume->user_id) {
|
||||
return '<a href="' . route('user_shop_order_detail', [$UserSalesVolume->shopping_order->id]) . '" class="btn btn-xs btn-secondary">' . $UserSalesVolume->shopping_order->id . '</a>';
|
||||
if (($UserSalesVolume->status === 2 || $UserSalesVolume->status === 3) && $UserSalesVolume->shopping_order->member_id === $UserSalesVolume->user_id) {
|
||||
return '<a href="'.route('user_shop_order_detail', [$UserSalesVolume->shopping_order->id]).'" class="btn btn-xs btn-secondary">'.$UserSalesVolume->shopping_order->id.'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
})
|
||||
->addColumn('total_net', function (UserSalesVolume $UserSalesVolume) {
|
||||
return formatNumber($UserSalesVolume->total_net) . ' €';
|
||||
return formatNumber($UserSalesVolume->total_net).' €';
|
||||
})
|
||||
->addColumn('status_turnover', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<span class="badge badge-pill badge-' . $UserSalesVolume->getStatusTurnoverColor() . '">' . $UserSalesVolume->getStatusTurnoverType() . '</span>';
|
||||
return '<span class="badge badge-pill badge-'.$UserSalesVolume->getStatusTurnoverColor().'">'.$UserSalesVolume->getStatusTurnoverType().'</span>';
|
||||
})
|
||||
->addColumn('status', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<span class="badge badge-pill badge-' . $UserSalesVolume->getStatusColor() . '">' . $UserSalesVolume->getStatusType() . '</span>';
|
||||
return '<span class="badge badge-pill badge-'.$UserSalesVolume->getStatusColor().'">'.$UserSalesVolume->getStatusType().'</span>';
|
||||
})
|
||||
->addColumn('message', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<span class="no-line-break">' . $UserSalesVolume->message . '</span>';
|
||||
return '<span class="no-line-break">'.$UserSalesVolume->message.'</span>';
|
||||
})
|
||||
->addColumn('info', function (UserSalesVolume $UserSalesVolume) {
|
||||
return '<span class="no-line-break">' . $UserSalesVolume->info . '</span>';
|
||||
return '<span class="no-line-break">'.$UserSalesVolume->info.'</span>';
|
||||
})
|
||||
|
||||
->orderColumn('id', 'id $1')
|
||||
|
|
@ -1018,7 +1003,8 @@ class TeamController extends Controller
|
|||
'userSalesVolume' => $userSalesVolume,
|
||||
];
|
||||
$html = view('user.team._points_sum', $data)->render();
|
||||
return response()->json(['response' => true, 'data' => $data, 'html' => $html]);
|
||||
|
||||
return response()->json(['response' => true, 'data' => $data, 'html' => $html]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1026,13 +1012,13 @@ class TeamController extends Controller
|
|||
*/
|
||||
private function formatBytes(int $bytes, int $precision = 2): string
|
||||
{
|
||||
$units = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
|
||||
for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) {
|
||||
$bytes /= 1024;
|
||||
}
|
||||
|
||||
return round($bytes, $precision) . ' ' . $units[$i];
|
||||
return round($bytes, $precision).' '.$units[$i];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1058,7 +1044,7 @@ class TeamController extends Controller
|
|||
return [
|
||||
1 => __('team.filter_active'),
|
||||
2 => __('team.filter_not_active'),
|
||||
3 => __('team.filter_all')
|
||||
3 => __('team.filter_all'),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -1071,7 +1057,7 @@ class TeamController extends Controller
|
|||
0 => __('team.all_status'),
|
||||
1 => __('team.qualified_green'),
|
||||
2 => __('team.in_progress_yellow'),
|
||||
3 => __('team.no_level_red')
|
||||
3 => __('team.no_level_red'),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -1089,20 +1075,20 @@ class TeamController extends Controller
|
|||
|
||||
// Debug: Prüfe TreeCalcBot-Inhalt
|
||||
$businessUsers = $treeCalcBot->getItems();
|
||||
\Log::info("TeamController: TreeCalcBot root items count: " . count($businessUsers));
|
||||
\Log::info('TeamController: TreeCalcBot root items count: '.count($businessUsers));
|
||||
|
||||
// Sammle alle Root-User UND deren verschachtelte businessUserItems
|
||||
foreach ($businessUsers as $businessUser) {
|
||||
// WICHTIG: user_id korrekt über b_user abrufen (Magic Method Problem mit isset())
|
||||
$userId = $businessUser->user_id; // Über __get() Method
|
||||
|
||||
\Log::debug("TeamController: Processing root businessUser", [
|
||||
\Log::debug('TeamController: Processing root businessUser', [
|
||||
'user_id' => $userId,
|
||||
'businessUserItems_count' => count($businessUser->businessUserItems ?? []),
|
||||
]);
|
||||
// WICHTIG: Root-User selbst hinzufügen (korrigierte user_id Prüfung)
|
||||
//nur User können auch children haben - businessUserItems
|
||||
if ($userId && !isset($processedIds[$userId])) {
|
||||
// nur User können auch children haben - businessUserItems
|
||||
if ($userId && ! isset($processedIds[$userId])) {
|
||||
$processedIds[$userId] = true;
|
||||
$businessUser->deep = 0;
|
||||
$allUsers[] = $businessUser;
|
||||
|
|
@ -1121,7 +1107,7 @@ class TeamController extends Controller
|
|||
|
||||
if ($userId) {
|
||||
// Prüfe ob dieser parentless User bereits gesammelt wurde
|
||||
if (!isset($processedIds[$userId])) {
|
||||
if (! isset($processedIds[$userId])) {
|
||||
$processedIds[$userId] = true;
|
||||
$businessUser->deep = 0;
|
||||
$allUsers[] = $businessUser;
|
||||
|
|
@ -1134,17 +1120,17 @@ class TeamController extends Controller
|
|||
\Log::debug("TeamController: Parentless-User übersprungen: {$userId} (bereits verarbeitet)");
|
||||
}
|
||||
} else {
|
||||
\Log::warning("TeamController: Parentless BusinessUser ohne user_id übersprungen");
|
||||
\Log::warning('TeamController: Parentless BusinessUser ohne user_id übersprungen');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\Log::info("TeamController: AllUsers before filtering: " . count($allUsers));
|
||||
\Log::info('TeamController: AllUsers before filtering: '.count($allUsers));
|
||||
// Filter anwenden
|
||||
$filteredUsers = $this->applyTeamFiltersToBusinessUsers($allUsers);
|
||||
\Log::info("TeamController: AllUsers after filtering: " . count($filteredUsers));
|
||||
\Log::info('TeamController: AllUsers after filtering: '.count($filteredUsers));
|
||||
|
||||
return $filteredUsers;
|
||||
}
|
||||
|
|
@ -1161,9 +1147,9 @@ class TeamController extends Controller
|
|||
\Log::info("TeamController: Applying filters - Active: {$activeFilter}, Level: {$levelFilter}, NextLevel: {$nextLevelFilter}");
|
||||
|
||||
// Debug: Zeige verfügbare Eigenschaften des ersten BusinessUsers
|
||||
if (!empty($businessUsers)) {
|
||||
if (! empty($businessUsers)) {
|
||||
$firstUser = $businessUsers[0];
|
||||
\Log::debug("TeamController: First BusinessUser properties", [
|
||||
\Log::debug('TeamController: First BusinessUser properties', [
|
||||
'user_id' => $firstUser->user_id ?? 'not set',
|
||||
'active_account' => $firstUser->active_account ?? 'not set',
|
||||
'm_level_id' => $firstUser->m_level_id ?? 'not set',
|
||||
|
|
@ -1175,7 +1161,7 @@ class TeamController extends Controller
|
|||
$filtered = array_filter($businessUsers, function ($businessUser) use ($activeFilter, $levelFilter, $nextLevelFilter) {
|
||||
// Active Filter anwenden
|
||||
if ($activeFilter == 1) { // Nur aktive
|
||||
if (!$businessUser->active_account) {
|
||||
if (! $businessUser->active_account) {
|
||||
return false;
|
||||
}
|
||||
} elseif ($activeFilter == 2) { // Nur inaktive
|
||||
|
|
@ -1199,12 +1185,12 @@ class TeamController extends Controller
|
|||
|
||||
switch ($nextLevelFilter) {
|
||||
case 1: // Qualifiziert (grün) - hat next_qual_user_level
|
||||
if (!$hasNextQual) {
|
||||
if (! $hasNextQual) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 2: // In Arbeit (gelb) - hat next_can_user_level aber kein next_qual_user_level
|
||||
if ($hasNextQual || !$hasNextCan) {
|
||||
if ($hasNextQual || ! $hasNextCan) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1233,6 +1219,7 @@ class TeamController extends Controller
|
|||
$maxDepth = 20;
|
||||
if ($depth > $maxDepth) {
|
||||
\Log::warning("TeamController: Maximale Sammlungstiefe ({$maxDepth}) erreicht bei Tiefe {$depth}");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1244,6 +1231,7 @@ class TeamController extends Controller
|
|||
// KRITISCHER SCHUTZ: Prüfe ob User bereits gesammelt wurde
|
||||
if (isset($processedIds[$userId])) {
|
||||
\Log::debug("TeamController: Überspringe bereits gesammelten User {$userId} (Duplikat verhindert)");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -1255,8 +1243,8 @@ class TeamController extends Controller
|
|||
\Log::debug("TeamController: Flach gesammelt - User ID: {$userId} at depth {$depth}");
|
||||
|
||||
// Rekursiv ALLE verschachtelten businessUserItems sammeln
|
||||
if (isset($businessUserItem->businessUserItems) && is_array($businessUserItem->businessUserItems) && !empty($businessUserItem->businessUserItems)) {
|
||||
\Log::debug("TeamController: Sammle " . count($businessUserItem->businessUserItems) . " verschachtelte Items von User {$userId}");
|
||||
if (isset($businessUserItem->businessUserItems) && is_array($businessUserItem->businessUserItems) && ! empty($businessUserItem->businessUserItems)) {
|
||||
\Log::debug('TeamController: Sammle '.count($businessUserItem->businessUserItems)." verschachtelte Items von User {$userId}");
|
||||
$this->collectAllBusinessUserItemsFlat($businessUserItem->businessUserItems, $allUsers, $processedIds, $depth + 1);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1276,11 +1264,12 @@ class TeamController extends Controller
|
|||
$maxDepth = 20;
|
||||
if ($deep > $maxDepth) {
|
||||
\Log::warning("TeamController: Maximale Sammlungstiefe ({$maxDepth}) erreicht");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($businessUser->businessUserItems) && is_array($businessUser->businessUserItems)) {
|
||||
\Log::debug("TeamController: Collecting from businessUser with " . count($businessUser->businessUserItems) . " sub-items at depth {$deep}");
|
||||
\Log::debug('TeamController: Collecting from businessUser with '.count($businessUser->businessUserItems)." sub-items at depth {$deep}");
|
||||
|
||||
foreach ($businessUser->businessUserItems as $subBusinessUser) {
|
||||
if ($subBusinessUser) {
|
||||
|
|
@ -1291,6 +1280,7 @@ class TeamController extends Controller
|
|||
// KRITISCHER BUGFIX: Prüfe ob User bereits gesammelt wurde
|
||||
if (isset($processedIds[$userId])) {
|
||||
\Log::debug("TeamController: Überspringe bereits gesammelten User {$userId} (zirkuläre Referenz verhindert)");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -1320,13 +1310,13 @@ class TeamController extends Controller
|
|||
$cleanedUsers = [];
|
||||
|
||||
foreach ($businessUserItems as $businessUserItem) {
|
||||
if (!$businessUserItem) {
|
||||
if (! $businessUserItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
// Extrahiere nur die Properties, die für DataTable benötigt werden
|
||||
$cleanedUser = new \stdClass();
|
||||
$cleanedUser = new \stdClass;
|
||||
|
||||
// Basis Properties (direkt über Magic Method __get)
|
||||
$cleanedUser->user_id = $businessUserItem->user_id;
|
||||
|
|
@ -1354,13 +1344,14 @@ class TeamController extends Controller
|
|||
|
||||
\Log::debug("TeamController: Cleaned user {$cleanedUser->user_id} for DataTable");
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error cleaning BusinessUserItem for DataTable: " . $e->getMessage());
|
||||
\Log::error('TeamController: Error cleaning BusinessUserItem for DataTable: '.$e->getMessage());
|
||||
|
||||
// Skip diesen User, statt alles abzubrechen
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
\Log::info("TeamController: Cleaned " . count($cleanedUsers) . " users for DataTable (from " . count($businessUserItems) . " raw items)");
|
||||
\Log::info('TeamController: Cleaned '.count($cleanedUsers).' users for DataTable (from '.count($businessUserItems).' raw items)');
|
||||
|
||||
return $cleanedUsers;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ use App\Models\ShoppingUser;
|
|||
use App\Repositories\CheckoutRepository;
|
||||
use App\Services\AboHelper;
|
||||
use App\Services\CustomerPriority;
|
||||
use App\Services\OrderPaymentService;
|
||||
use App\Services\Payment;
|
||||
use App\Services\Shop;
|
||||
use App\Services\Util;
|
||||
|
|
@ -24,6 +23,7 @@ use Yard;
|
|||
class CheckoutController extends Controller
|
||||
{
|
||||
private $checkoutRepo;
|
||||
|
||||
private $instance = 'checkout';
|
||||
|
||||
/**
|
||||
|
|
@ -38,18 +38,18 @@ class CheckoutController extends Controller
|
|||
|
||||
/**
|
||||
* Zeigt die Checkout-Seite an
|
||||
*
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function checkout()
|
||||
{
|
||||
/*
|
||||
@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())
|
||||
<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';
|
||||
|
|
@ -97,28 +97,26 @@ class CheckoutController extends Controller
|
|||
'is_checkout' => true,
|
||||
'yard_instance' => $this->instance,
|
||||
];
|
||||
|
||||
return view('web.templates.checkout', $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Bereitet die ShoppingUser-Daten vor
|
||||
*
|
||||
* @param ShoppingUser $shopping_user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function prepareShoppingUserData(ShoppingUser $shopping_user)
|
||||
{
|
||||
if ($shopping_user->same_as_billing === NULL) {
|
||||
if ($shopping_user->same_as_billing === null) {
|
||||
$shopping_user->same_as_billing = false;
|
||||
}
|
||||
if (!$shopping_user->billing_country_id) {
|
||||
if (! $shopping_user->billing_country_id) {
|
||||
$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($this->instance)->getUserCountry();
|
||||
}
|
||||
if (!$shopping_user->shipping_country_id) {
|
||||
if (! $shopping_user->shipping_country_id) {
|
||||
$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($this->instance)->getUserCountry();
|
||||
|
|
@ -135,7 +133,7 @@ class CheckoutController extends Controller
|
|||
|
||||
/**
|
||||
* Verarbeitet den Checkout-Prozess
|
||||
*
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function checkoutFinal()
|
||||
|
|
@ -180,13 +178,13 @@ class CheckoutController extends Controller
|
|||
|
||||
/**
|
||||
* Verarbeitet den Länderwechsel
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
private function handleCountryChange($data)
|
||||
{
|
||||
if (!Request::get('same_as_billing')) {
|
||||
if (! Request::get('same_as_billing')) {
|
||||
Yard::instance($this->instance)->setShippingCountryWithPrice($data['billing_state'], $data['is_for']);
|
||||
} else {
|
||||
Yard::instance($this->instance)->setShippingCountryWithPrice($data['shipping_state'], $data['is_for']);
|
||||
|
|
@ -197,7 +195,7 @@ class CheckoutController extends Controller
|
|||
|
||||
/**
|
||||
* Validiert die Checkout-Daten
|
||||
*
|
||||
*
|
||||
* @return \Illuminate\Validation\Validator
|
||||
*/
|
||||
private function validateCheckoutData()
|
||||
|
|
@ -220,7 +218,7 @@ class CheckoutController extends Controller
|
|||
'shipping_address' => 'required',
|
||||
'shipping_zipcode' => 'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_salutation' => 'required'
|
||||
'shipping_salutation' => 'required',
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -229,10 +227,10 @@ class CheckoutController extends Controller
|
|||
|
||||
/**
|
||||
* Verarbeitet die Zahlungsmethode
|
||||
*
|
||||
* @param array $data
|
||||
* @param ShoppingUser $shopping_user
|
||||
* @param ShoppingOrder $shopping_order
|
||||
*
|
||||
* @param array $data
|
||||
* @param ShoppingUser $shopping_user
|
||||
* @param ShoppingOrder $shopping_order
|
||||
* @return mixed
|
||||
*/
|
||||
private function processPaymentMethod($data, $shopping_user, $shopping_order)
|
||||
|
|
@ -243,7 +241,7 @@ class CheckoutController extends Controller
|
|||
// Kreditkarte prüfen
|
||||
if ($payment_method === 'cc') {
|
||||
$result = $this->checkCreditCard($data, $shopping_user, $shopping_order);
|
||||
if (!is_array($result) || !isset($result['returnstatus']) || $result['returnstatus'] !== 'VALID') {
|
||||
if (! is_array($result) || ! isset($result['returnstatus']) || $result['returnstatus'] !== 'VALID') {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
@ -251,13 +249,13 @@ class CheckoutController extends Controller
|
|||
// SEPA prüfen
|
||||
if ($payment_method === 'elv') {
|
||||
$result = $this->checkSepaAccount($data, $shopping_user, $shopping_order);
|
||||
if (!is_array($result) || !isset($result['returnstatus']) || $result['returnstatus'] !== 'VALID') {
|
||||
if (! is_array($result) || ! isset($result['returnstatus']) || $result['returnstatus'] !== 'VALID') {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// Zahlung vorbereiten
|
||||
$pay = new PayoneController();
|
||||
$pay = new PayoneController;
|
||||
$pay->init($shopping_user, $shopping_order);
|
||||
$amount = Yard::instance($this->instance)->totalWithShipping(2, '.', '') * 100;
|
||||
$reference = $pay->setPrePayment($payment_method, $amount, 'EUR', $result);
|
||||
|
|
@ -269,15 +267,15 @@ class CheckoutController extends Controller
|
|||
|
||||
/**
|
||||
* Prüft die Kreditkartendaten
|
||||
*
|
||||
* @param array $data
|
||||
* @param ShoppingUser $shopping_user
|
||||
* @param ShoppingOrder $shopping_order
|
||||
*
|
||||
* @param array $data
|
||||
* @param ShoppingUser $shopping_user
|
||||
* @param ShoppingOrder $shopping_order
|
||||
* @return bool|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
private function checkCreditCard($data, $shopping_user, $shopping_order)
|
||||
{
|
||||
$pay = new PayoneController();
|
||||
$pay = new PayoneController;
|
||||
$pay->init($shopping_user, $shopping_order);
|
||||
$ret['cc'] = $pay->checkCreditCard($data);
|
||||
|
||||
|
|
@ -285,24 +283,26 @@ class CheckoutController extends Controller
|
|||
Session::flash('cc-error', 1);
|
||||
Session::flash('errormessage', $ret['cc']['errormessage']);
|
||||
Session::flash('customermessage', $ret['cc']['customermessage']);
|
||||
|
||||
return redirect(route('checkout.checkout_card'))->withInput(Request::all());
|
||||
}
|
||||
$ret['returnstatus'] = 'VALID';
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft die SEPA-Kontodaten
|
||||
*
|
||||
* @param array $data
|
||||
* @param ShoppingUser $shopping_user
|
||||
* @param ShoppingOrder $shopping_order
|
||||
*
|
||||
* @param array $data
|
||||
* @param ShoppingUser $shopping_user
|
||||
* @param ShoppingOrder $shopping_order
|
||||
* @return bool|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
private function checkSepaAccount($data, $shopping_user, $shopping_order)
|
||||
{
|
||||
if (is_null(Request::get('mandate_identification'))) {
|
||||
$pay = new PayoneController();
|
||||
$pay = new PayoneController;
|
||||
$pay->init($shopping_user, $shopping_order);
|
||||
$amount = Yard::instance($this->instance)->totalWithShipping(2, '.', '') * 100;
|
||||
$ret['elv'] = $pay->checkBankAccount($data, $amount, 'EUR', $shopping_user);
|
||||
|
|
@ -311,14 +311,16 @@ class CheckoutController extends Controller
|
|||
Session::flash('elv-error', 1);
|
||||
Session::flash('errormessage', $ret['elv']['errormessage']);
|
||||
Session::flash('customermessage', $ret['elv']['customermessage']);
|
||||
|
||||
return redirect(route('checkout.checkout_card'))->withInput(Request::all());
|
||||
}
|
||||
|
||||
if ($ret['elv']['status'] === 'APPROVED' && $ret['elv']['mandate_status'] !== "active") {
|
||||
if ($ret['elv']['status'] === 'APPROVED' && $ret['elv']['mandate_status'] !== 'active') {
|
||||
Session::flash('elv-managemandate', 1);
|
||||
Session::flash('elv-mandate_identification', $ret['elv']['mandate_identification']);
|
||||
Session::flash('elv-mandate_text', $ret['elv']['mandate_text']);
|
||||
Session::flash('elv-creditor_identifier', $ret['elv']['creditor_identifier']);
|
||||
|
||||
return redirect(route('checkout.checkout_card'))->withInput(Request::all());
|
||||
}
|
||||
|
||||
|
|
@ -329,18 +331,19 @@ class CheckoutController extends Controller
|
|||
'creditor_identifier' => Request::get('creditor_identifier'),
|
||||
'iban' => $data['elv_iban'],
|
||||
'bic' => $data['elv_bic'],
|
||||
'bankaccountholder' => $data['elv_bankaccountholder']
|
||||
'bankaccountholder' => $data['elv_bankaccountholder'],
|
||||
];
|
||||
|
||||
$this->storeUserPaymentsData($shopping_user, $ret);
|
||||
}
|
||||
$ret['returnstatus'] = 'VALID';
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Leitet zur Abschlussseite weiter
|
||||
*
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function redirectToIsFinal()
|
||||
|
|
@ -354,53 +357,105 @@ class CheckoutController extends Controller
|
|||
return view('web.templates.checkout-is-final', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verarbeitet den Transaktionsstatus (POST-Anfragen)
|
||||
* Einige Zahlungsanbieter senden POST-Anfragen zurück
|
||||
*
|
||||
* @param string $status
|
||||
* @param string $reference
|
||||
* @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function transactionStatusPost($status, $reference)
|
||||
{
|
||||
return $this->transactionStatus($status, $reference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verarbeitet den Transaktionsstatus
|
||||
*
|
||||
* @param string $status
|
||||
* @param string $reference
|
||||
*
|
||||
* @param string $status
|
||||
* @param string $reference
|
||||
* @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function transactionStatus($status, $reference)
|
||||
{
|
||||
$shopping_order_id = $this->checkoutRepo->getSessionPayments('shopping_order_id');
|
||||
$ShoppingPayment = ShoppingPayment::where('shopping_order_id', $shopping_order_id)
|
||||
->where('reference', $reference)
|
||||
->first();
|
||||
// Suche ShoppingPayment nur über reference (nicht Session-abhängig)
|
||||
// Dies ist wichtig, da die Session bei Redirect-Zahlungen verloren gehen kann
|
||||
$ShoppingPayment = ShoppingPayment::where('reference', $reference)->first();
|
||||
|
||||
if (!$ShoppingPayment) {
|
||||
if (! $ShoppingPayment) {
|
||||
Util::setUserHistoryValue(['status' => 21]);
|
||||
Session::flash('checkout-error', 'Der Zahlungsvorgang konnte nicht abgeschlossen werden, die Zahlung wurde nicht gefunden: ' . $reference);
|
||||
return redirect(route('checkout.checkout_card'));
|
||||
\Log::warning('CheckoutController::transactionStatus - ShoppingPayment nicht gefunden', [
|
||||
'reference' => $reference,
|
||||
'status' => $status,
|
||||
]);
|
||||
|
||||
// Zeige eine dedizierte Fehlerseite anstatt zur Hauptseite weiterzuleiten
|
||||
return $this->showTransactionError(
|
||||
__('payment.payment_not_found'),
|
||||
__('payment.payment_not_found_description', ['reference' => $reference])
|
||||
);
|
||||
}
|
||||
|
||||
$ShoppingPayment->status = $status;
|
||||
$ShoppingPayment->save();
|
||||
|
||||
if ($status === "success") {
|
||||
if ($status === 'success') {
|
||||
return $this->handleSuccessfulTransaction($ShoppingPayment, $reference);
|
||||
}
|
||||
|
||||
if ($status === "cancel") {
|
||||
if ($status === 'cancel') {
|
||||
Util::setUserHistoryValue(['status' => 22]);
|
||||
Util::setInstanceStatus(5); // link_canceled
|
||||
Session::flash('checkout-error', 'Der Zahlungsvorgang wurde abgebrochen, die Bestellung konnte nicht ausgeführt werden.');
|
||||
return redirect(route('checkout.checkout_card'));
|
||||
Util::setInstanceStatusByPayment($ShoppingPayment, 6); // link_canceled
|
||||
|
||||
return $this->showTransactionError(
|
||||
__('payment.payment_canceled'),
|
||||
__('payment.payment_canceled_description')
|
||||
);
|
||||
}
|
||||
|
||||
if ($status === "error") {
|
||||
if ($status === 'error') {
|
||||
Util::setUserHistoryValue(['status' => 23]);
|
||||
Util::setInstanceStatus(6); // link_failed
|
||||
Session::flash('checkout-error', 'Der Zahlungsvorgang wurde abgebrochen, die Bestellung konnte nicht ausgeführt werden.');
|
||||
return redirect(route('checkout.checkout_card'));
|
||||
Util::setInstanceStatusByPayment($ShoppingPayment, 5); // link_failed
|
||||
|
||||
return $this->showTransactionError(
|
||||
__('payment.payment_error'),
|
||||
__('payment.payment_error_description')
|
||||
);
|
||||
}
|
||||
|
||||
// Fallback für unbekannte Status
|
||||
return $this->showTransactionError(
|
||||
__('payment.payment_unknown_status'),
|
||||
__('payment.payment_unknown_status_description')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeigt eine Transaktionsfehlerseite an
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $message
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
private function showTransactionError($title, $message)
|
||||
{
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'is_checkout' => true,
|
||||
'yard_instance' => $this->instance,
|
||||
'error_title' => $title,
|
||||
'error_message' => $message,
|
||||
];
|
||||
|
||||
return view('web.templates.checkout-error', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verarbeitet eine erfolgreiche Transaktion
|
||||
*
|
||||
* @param ShoppingPayment $ShoppingPayment
|
||||
* @param string $reference
|
||||
*
|
||||
* @param ShoppingPayment $ShoppingPayment
|
||||
* @param string $reference
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
private function handleSuccessfulTransaction($ShoppingPayment, $reference)
|
||||
|
|
@ -428,9 +483,9 @@ class CheckoutController extends Controller
|
|||
|
||||
/**
|
||||
* Verarbeitet eine genehmigte Transaktion
|
||||
*
|
||||
* @param int $transactionId
|
||||
* @param string $reference
|
||||
*
|
||||
* @param int $transactionId
|
||||
* @param string $reference
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function transactionApproved($transactionId, $reference)
|
||||
|
|
@ -466,9 +521,9 @@ class CheckoutController extends Controller
|
|||
|
||||
/**
|
||||
* Speichert die Zahlungsdaten des Benutzers
|
||||
*
|
||||
* @param ShoppingUser $shopping_user
|
||||
* @param array $ret
|
||||
*
|
||||
* @param ShoppingUser $shopping_user
|
||||
* @param array $ret
|
||||
* @return void
|
||||
*/
|
||||
private function storeUserPaymentsData($shopping_user, $ret)
|
||||
|
|
@ -486,8 +541,7 @@ class CheckoutController extends Controller
|
|||
|
||||
/**
|
||||
* Verarbeitet den direkten Zahlungsstatus (Rechnung MIV)
|
||||
*
|
||||
* @param PaymentTransaction $payt
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function directPaymentStatus(PaymentTransaction $payt)
|
||||
|
|
@ -517,34 +571,36 @@ class CheckoutController extends Controller
|
|||
/**
|
||||
* 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
|
||||
* @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
|
||||
// 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
|
||||
// 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
|
||||
// kommt aus dem Salescenter mit bestelllink oder aus dem Webshop
|
||||
if ($is_from === 'shopping') {
|
||||
//Bestelllink
|
||||
// Bestelllink
|
||||
if ($is_for === 'ot-customer' || $is_for === 'abo-ot-customer') {
|
||||
//customer shop mit den Daten aus dem Salescenter shopping_data
|
||||
// customer shop mit den Daten aus dem Salescenter shopping_data
|
||||
return $this->checkoutRepo->makeCustomerShoppingUser($shopping_data, $is_for, $is_from);
|
||||
}
|
||||
//Webshop
|
||||
|
||||
// Webshop
|
||||
return $this->checkoutRepo->initShoppingUser($is_for, $is_from, $homeparty_id);
|
||||
}
|
||||
|
||||
|
|
@ -553,7 +609,7 @@ class CheckoutController extends Controller
|
|||
|
||||
/**
|
||||
* Holt den existierenden ShoppingUser und bereitet ihn vor
|
||||
*
|
||||
*
|
||||
* @return ShoppingUser
|
||||
*/
|
||||
private function getExistingShoppingUser()
|
||||
|
|
|
|||
|
|
@ -2,34 +2,32 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Hash;
|
||||
use Yard;
|
||||
use Request;
|
||||
use App\User;
|
||||
use Validator;
|
||||
use App\Mail\MailAccountActive;
|
||||
use App\Mail\MailAutoReleaseAccount;
|
||||
use App\Mail\MailReleaseAccount;
|
||||
use App\Models\File;
|
||||
use App\Services\Util;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Models\UserAccount;
|
||||
use App\Models\UserHistory;
|
||||
use App\Services\UserService;
|
||||
use App\Mail\MailAccountActive;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Mail\MailReleaseAccount;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Mail\MailAutoReleaseAccount;
|
||||
use App\Repositories\ContractPDFRepository;
|
||||
use App\Repositories\FileRepository;
|
||||
use App\Repositories\UserRepository;
|
||||
use App\Services\UserService;
|
||||
use App\Services\Util;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Repositories\ContractPDFRepository;
|
||||
use Request;
|
||||
use Validator;
|
||||
use Yard;
|
||||
|
||||
class WizardController extends Controller
|
||||
{
|
||||
|
||||
protected $fileRepo;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
|
|
@ -42,19 +40,20 @@ class WizardController extends Controller
|
|||
|
||||
public function create()
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
if (! Auth::check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
if (!$user->account) {
|
||||
if (! $user->account) {
|
||||
$account = UserAccount::create([]);
|
||||
$user->account_id = $account->id;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_create'));
|
||||
}
|
||||
|
||||
$step = !$user->wizard ? 0 : $user->wizard;
|
||||
$step = ! $user->wizard ? 0 : $user->wizard;
|
||||
|
||||
if ($step >= 20) {
|
||||
return redirect('/home');
|
||||
|
|
@ -64,8 +63,12 @@ class WizardController extends Controller
|
|||
$data = [
|
||||
'user' => Auth::user(),
|
||||
'step' => $step,
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '9')->orderBy('pos', 'ASC')->get(),
|
||||
'products' => Product::where('active', true)->where(function ($q) {
|
||||
$q->whereJsonContains('show_on', '7')
|
||||
->orWhereJsonContains('show_on', '8')
|
||||
->orWhereJsonContains('show_on', '9');
|
||||
})->orderBy('pos', 'ASC')->get(),
|
||||
'products_on_board' => collect(),
|
||||
'userHistoryWizardPayment' => $userHistoryWizardPayment,
|
||||
];
|
||||
|
||||
|
|
@ -79,18 +82,19 @@ class WizardController extends Controller
|
|||
public function register()
|
||||
{
|
||||
|
||||
if (!Auth::check()) {
|
||||
if (! Auth::check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
if (!$user->account) {
|
||||
if (! $user->account) {
|
||||
$account = UserAccount::create([]);
|
||||
$user->account_id = $account->id;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_register'));
|
||||
}
|
||||
|
||||
$step = !$user->wizard ? 0 : $user->wizard;
|
||||
$step = ! $user->wizard ? 0 : $user->wizard;
|
||||
|
||||
if ($step >= 10) {
|
||||
return redirect('/home');
|
||||
|
|
@ -99,14 +103,19 @@ class WizardController extends Controller
|
|||
$data = [
|
||||
'user' => Auth::user(),
|
||||
'step' => $step,
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '9')->orderBy('pos', 'ASC')->get(),
|
||||
'products' => Product::where('active', true)->where(function ($q) {
|
||||
$q->whereJsonContains('show_on', '7')
|
||||
->orWhereJsonContains('show_on', '8')
|
||||
->orWhereJsonContains('show_on', '9');
|
||||
})->orderBy('pos', 'ASC')->get(),
|
||||
'products_on_board' => collect(),
|
||||
];
|
||||
if ($step == 5) {
|
||||
if ($user->active) {
|
||||
$user->active = false;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
return view('user.wizard.register_release', $data);
|
||||
}
|
||||
|
||||
|
|
@ -115,39 +124,43 @@ class WizardController extends Controller
|
|||
|
||||
public function payment()
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
if (! Auth::check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
if (!$user->account) {
|
||||
if (! $user->account) {
|
||||
$account = UserAccount::create([]);
|
||||
$user->account_id = $account->id;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_payment'));
|
||||
}
|
||||
|
||||
$userHistoryWizardPayment = UserHistory::whereUserId($user->id)->whereAction('wizard_payment')->get()->last();
|
||||
|
||||
$shipping_country_id = $this->checkShoppingCountry($user);
|
||||
if (!$shipping_country_id) {
|
||||
if (! $shipping_country_id) {
|
||||
abort(403, __('validation.custom.shipping_not_found'));
|
||||
}
|
||||
|
||||
UserService::checkUserTaxShippingCountry($user, $shipping_country_id);
|
||||
//Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id, $for);
|
||||
//Yard::instance('shopping')->setUserPriceInfos(UserService::getYardInfo());
|
||||
// Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id, $for);
|
||||
// Yard::instance('shopping')->setUserPriceInfos(UserService::getYardInfo());
|
||||
|
||||
$data = [
|
||||
'user' => Auth::user(),
|
||||
'step' => 0,
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '9')->orderBy('pos', 'ASC')->get(),
|
||||
'products' => Product::where('active', true)->where(function ($q) {
|
||||
$q->whereJsonContains('show_on', '7')
|
||||
->orWhereJsonContains('show_on', '8')
|
||||
->orWhereJsonContains('show_on', '9');
|
||||
})->orderBy('pos', 'ASC')->get(),
|
||||
'products_on_board' => collect(),
|
||||
'userHistoryWizardPayment' => $userHistoryWizardPayment,
|
||||
'yard_info' => UserService::getYardInfo(),
|
||||
];
|
||||
|
||||
|
||||
if ($user->wizard == 20) {
|
||||
return view('user.wizard.register_payment', $data);
|
||||
}
|
||||
|
|
@ -169,43 +182,45 @@ class WizardController extends Controller
|
|||
return $shipping_country->id;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function storeRegister($step = false)
|
||||
{
|
||||
|
||||
if (!Auth::check()) {
|
||||
if (! Auth::check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
if (!$user->account) {
|
||||
$user->account = new UserAccount();
|
||||
if (! $user->account) {
|
||||
$user->account = new UserAccount;
|
||||
}
|
||||
|
||||
|
||||
$data = Request::all();
|
||||
if ($step == 7 && Request::get('user_country_id')) {
|
||||
$user->account->country_id = Request::get('user_country_id');
|
||||
$user->account->save();
|
||||
|
||||
return redirect(route('wizard_register', [1]));
|
||||
}
|
||||
if ($step == 0) {
|
||||
$rules = array(
|
||||
$rules = [
|
||||
'accepted_data_protection' => 'required',
|
||||
'accepted_active' => 'required',
|
||||
'accepted_contract' => 'required'
|
||||
);
|
||||
'accepted_contract' => 'required',
|
||||
];
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
$data = [
|
||||
'user' => Auth::user(),
|
||||
'step' => $step,
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '9')->orderBy('pos', 'ASC')->get(),
|
||||
];
|
||||
$user->wizard = 0;
|
||||
$user->save();
|
||||
|
||||
return view('user.wizard.register', $data)->withErrors($validator);
|
||||
}
|
||||
$account = $user->account;
|
||||
|
|
@ -222,26 +237,29 @@ class WizardController extends Controller
|
|||
|
||||
$user->wizard = 1;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_register'));
|
||||
}
|
||||
if ($step == 1) {
|
||||
|
||||
$data = Request::all();
|
||||
if (isset($data['action']) && $data['action'] == "reverse_charge_validate") {
|
||||
if (isset($data['action']) && $data['action'] == 'reverse_charge_validate') {
|
||||
$user->wizard = 1;
|
||||
$user->save();
|
||||
$userRepo = new UserRepository($user);
|
||||
|
||||
return $userRepo->reverse_charge_validate($data, $user, route('wizard_register', [0]));
|
||||
}
|
||||
|
||||
if (isset($data['action']) && $data['action'] == "reverse_charge_delete") {
|
||||
if (isset($data['action']) && $data['action'] == 'reverse_charge_delete') {
|
||||
$user->wizard = 1;
|
||||
$user->save();
|
||||
$userRepo = new UserRepository($user);
|
||||
|
||||
return $userRepo->reverse_charge_delete($data, $user, route('wizard_register', [0]));
|
||||
}
|
||||
|
||||
$rules = array(
|
||||
$rules = [
|
||||
'salutation' => 'required',
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
|
|
@ -255,9 +273,9 @@ class WizardController extends Controller
|
|||
'bank_owner' => 'required',
|
||||
'bank_iban' => 'required',
|
||||
'bank_bic' => 'required',
|
||||
);
|
||||
];
|
||||
|
||||
if (!Request::get('same_as_billing')) {
|
||||
if (! Request::get('same_as_billing')) {
|
||||
$rules = array_merge($rules, [
|
||||
'shipping_firstname' => 'required',
|
||||
'shipping_lastname' => 'required',
|
||||
|
|
@ -272,12 +290,14 @@ class WizardController extends Controller
|
|||
if ($validator->fails()) {
|
||||
$user->wizard = 1;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_register', [1]))->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
$data['same_as_billing'] = Request::get('same_as_billing') == NULL ? 0 : 1;
|
||||
$data['same_as_billing'] = Request::get('same_as_billing') == null ? 0 : 1;
|
||||
$user->account->fill($data)->save();
|
||||
$user->wizard = 2;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_register'));
|
||||
}
|
||||
|
||||
|
|
@ -288,40 +308,45 @@ class WizardController extends Controller
|
|||
$validator->errors()->add('field', __('msg.no_id_card_deposited_please_upload_first'));
|
||||
$user->wizard = 2;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_register'))->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
$user->wizard = 3;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_register'));
|
||||
}
|
||||
$this->fileRepo->_set('disk', 'user');
|
||||
$this->fileRepo->_set('dir', '/' . $user->id . '/verification/');
|
||||
$this->fileRepo->_set('dir', '/'.$user->id.'/verification/');
|
||||
$this->fileRepo->_set('user_id', $user->id);
|
||||
$this->fileRepo->_set('identifier', 'id_card');
|
||||
return $this->fileRepo->uploadFile(Request::all());
|
||||
|
||||
return $this->fileRepo->uploadFile(Request::all());
|
||||
}
|
||||
|
||||
if ($step == 3) {
|
||||
if (Request::get('submit') === 'do') {
|
||||
$data = Request::all();
|
||||
|
||||
if ($data['business_license_choose'] === "now") {
|
||||
if ($data['business_license_choose'] === 'now') {
|
||||
if (File::whereUserId($user->id)->whereIdentifier('business_license')->count() == 0) {
|
||||
$validator = Validator::make(Request::all(), []);
|
||||
$validator->errors()->add('field', __('msg.no_trade_licence_deposited_please_upload_first'));
|
||||
$user->wizard = 3;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_register'))->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
}
|
||||
if ($data['business_license_choose'] === "later") {
|
||||
if ($data['business_license_choose'] === 'later') {
|
||||
}
|
||||
if ($data['business_license_choose'] === "non") {
|
||||
if (!$data['non_business_license_reason'] || $data['non_business_license_reason'] == "") {
|
||||
if ($data['business_license_choose'] === 'non') {
|
||||
if (! $data['non_business_license_reason'] || $data['non_business_license_reason'] == '') {
|
||||
$validator = Validator::make(Request::all(), []);
|
||||
$validator->errors()->add('field', __('msg.please_enter_reason_why_you_not_need_trade_licence'));
|
||||
$user->wizard = 3;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_register'))->withErrors($validator)->withInput(Request::all());
|
||||
} else {
|
||||
$user->account->setNotice('business_license_reason', $data['non_business_license_reason']);
|
||||
|
|
@ -335,10 +360,11 @@ class WizardController extends Controller
|
|||
return redirect(route('wizard_register'));
|
||||
}
|
||||
$this->fileRepo->_set('disk', 'user');
|
||||
$this->fileRepo->_set('dir', '/' . $user->id . '/verification/');
|
||||
$this->fileRepo->_set('dir', '/'.$user->id.'/verification/');
|
||||
$this->fileRepo->_set('user_id', $user->id);
|
||||
$this->fileRepo->_set('identifier', 'business_license');
|
||||
return $this->fileRepo->uploadFile(Request::all());
|
||||
|
||||
return $this->fileRepo->uploadFile(Request::all());
|
||||
}
|
||||
|
||||
if ($step == 4) {
|
||||
|
|
@ -363,7 +389,7 @@ class WizardController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
//auto release account
|
||||
// auto release account
|
||||
public function releaseAccount($user)
|
||||
{
|
||||
|
||||
|
|
@ -373,15 +399,15 @@ class WizardController extends Controller
|
|||
$user->account->m_account = UserAccount::withTrashed()->max('m_account') + 1;
|
||||
$user->account->save();
|
||||
$user->save();
|
||||
//create PDF
|
||||
// create PDF
|
||||
$pdf = new ContractPDFRepository($user);
|
||||
$pdf->_set('disk', 'user');
|
||||
$pdf->_set('dir', '/' . $user->id . '/documents/');
|
||||
$pdf->_set('dir', '/'.$user->id.'/documents/');
|
||||
$pdf->_set('user_id', $user->id);
|
||||
$pdf->_set('identifier', 'contract');
|
||||
$pdf->createContractPDF();
|
||||
|
||||
//set wizard tp payments
|
||||
// set wizard tp payments
|
||||
$user->wizard = 20;
|
||||
$user->active = 1;
|
||||
$user->active_date = now();
|
||||
|
|
@ -391,7 +417,7 @@ class WizardController extends Controller
|
|||
$user->confirmation_code_remider = 0;
|
||||
$user->save();
|
||||
|
||||
//mail with code to user?
|
||||
// mail with code to user?
|
||||
if ($user->isTestMode()) {
|
||||
$mail = config('app.info_test_mail');
|
||||
} else {
|
||||
|
|
@ -402,36 +428,38 @@ class WizardController extends Controller
|
|||
Mail::to($user->email)->locale($user->getLocale())->send(new MailAccountActive($user));
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => 'released_completed', 'status' => 0]);
|
||||
\Session()->flash('alert-success', __('msg.account_released'));
|
||||
|
||||
return redirect(route('wizard_payment'));
|
||||
}
|
||||
|
||||
public function storeCreate($step = 0)
|
||||
{
|
||||
|
||||
if (!Auth::check()) {
|
||||
if (! Auth::check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
if (!$user->account) {
|
||||
$user->account = new UserAccount();
|
||||
if (! $user->account) {
|
||||
$user->account = new UserAccount;
|
||||
}
|
||||
|
||||
if ($step == 10) {
|
||||
$rules = array(
|
||||
$rules = [
|
||||
'accepted_data_protection' => 'required',
|
||||
'accepted_active' => 'required',
|
||||
);
|
||||
];
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
$data = [
|
||||
'user' => Auth::user(),
|
||||
'step' => $step,
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '9')->orderBy('pos', 'ASC')->get(),
|
||||
];
|
||||
$user->wizard = 10;
|
||||
$user->save();
|
||||
|
||||
return view('user.wizard.create', $data)->withErrors($validator);
|
||||
}
|
||||
$account = $user->account;
|
||||
|
|
@ -455,50 +483,54 @@ class WizardController extends Controller
|
|||
if ($user->isPasswort()) {
|
||||
$user->wizard = 12;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_create', [12]));
|
||||
}
|
||||
$rules = array(
|
||||
$rules = [
|
||||
'password' => 'required|string|min:6|confirmed',
|
||||
);
|
||||
];
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
$data = [
|
||||
'user' => Auth::user(),
|
||||
'step' => $step,
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '9')->orderBy('pos', 'ASC')->get(),
|
||||
];
|
||||
|
||||
return view('user.wizard.create', $data)->withErrors($validator);
|
||||
}
|
||||
|
||||
$user->fill([
|
||||
'password' => Hash::make(Request::get('password'))
|
||||
'password' => Hash::make(Request::get('password')),
|
||||
])->save();
|
||||
$user->wizard = 12;
|
||||
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_create', [12]));
|
||||
}
|
||||
if ($step == 12) {
|
||||
|
||||
$data = Request::all();
|
||||
|
||||
if (isset($data['action']) && $data['action'] == "reverse_charge_validate") {
|
||||
if (isset($data['action']) && $data['action'] == 'reverse_charge_validate') {
|
||||
$user->wizard = 12;
|
||||
$user->save();
|
||||
$userRepo = new UserRepository($user);
|
||||
|
||||
return $userRepo->reverse_charge_validate($data, $user, route('wizard_create', [12]));
|
||||
}
|
||||
|
||||
if (isset($data['action']) && $data['action'] == "reverse_charge_delete") {
|
||||
if (isset($data['action']) && $data['action'] == 'reverse_charge_delete') {
|
||||
$user->wizard = 12;
|
||||
$user->save();
|
||||
$userRepo = new UserRepository($user);
|
||||
|
||||
return $userRepo->reverse_charge_delete($data, $user, route('wizard_create', [12]));
|
||||
}
|
||||
|
||||
|
||||
$rules = array(
|
||||
$rules = [
|
||||
'salutation' => 'required',
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
|
|
@ -509,16 +541,16 @@ class WizardController extends Controller
|
|||
'mobil' => 'required_without:phone',
|
||||
'country_id' => 'required|integer|min:1',
|
||||
'birthday' => 'required',
|
||||
);
|
||||
];
|
||||
|
||||
if (!Request::get('same_as_billing')) {
|
||||
if (! Request::get('same_as_billing')) {
|
||||
$rules = array_merge($rules, [
|
||||
'shipping_firstname' => 'required',
|
||||
'shipping_lastname' => 'required',
|
||||
'shipping_address' => 'required',
|
||||
'shipping_zipcode' => 'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_salutation' => 'required'
|
||||
'shipping_salutation' => 'required',
|
||||
|
||||
]);
|
||||
}
|
||||
|
|
@ -528,7 +560,7 @@ class WizardController extends Controller
|
|||
}
|
||||
|
||||
$data = Request::all();
|
||||
$data['same_as_billing'] = Request::get('same_as_billing') == NULL ? 0 : 1;
|
||||
$data['same_as_billing'] = Request::get('same_as_billing') == null ? 0 : 1;
|
||||
$user->account->fill($data)->save();
|
||||
|
||||
$user->wizard = 13;
|
||||
|
|
@ -538,11 +570,11 @@ class WizardController extends Controller
|
|||
$user->confirmation_code_to = null;
|
||||
$user->confirmation_code_remider = 0;
|
||||
$user->save();
|
||||
|
||||
return redirect(route('wizard_create', [13]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function storePayment($step = 0)
|
||||
{
|
||||
|
||||
|
|
@ -552,13 +584,13 @@ class WizardController extends Controller
|
|||
$product = Product::find(Request::get('switchers-package-wizard'));
|
||||
$showAboOptions = false;
|
||||
if (Request::get('abo_options')) {
|
||||
$showAboOptions = false; //true Abo Option deaktivert
|
||||
$user->abo_options = false; //true Abo Option deaktivert
|
||||
$showAboOptions = false; // true Abo Option deaktivert
|
||||
$user->abo_options = false; // true Abo Option deaktivert
|
||||
$user->save();
|
||||
}
|
||||
|
||||
$shipping_country_id = $this->checkShoppingCountry($user);
|
||||
if (!$shipping_country_id) {
|
||||
if (! $shipping_country_id) {
|
||||
abort(403, __('validation.custom.shipping_not_found'));
|
||||
}
|
||||
|
||||
|
|
@ -566,37 +598,19 @@ class WizardController extends Controller
|
|||
Yard::instance('shopping')->setUserPriceInfos(UserService::getYardInfo());
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id);
|
||||
|
||||
|
||||
if ($product && $product->active) {
|
||||
//set membership product
|
||||
$image = "";
|
||||
// set membership product
|
||||
$image = '';
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'free_shipping_consultant' => $product->free_shipping_consultant, 'show_on' => $product->show_on]);
|
||||
if (\App\Services\UserService::getTaxFree()) {
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
} else {
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(\App\Services\UserService::$user_country));
|
||||
}
|
||||
|
||||
//set onboarding products
|
||||
if (Request::get('products_on_board')) {
|
||||
foreach (Request::get('products_on_board') as $product_on_board_id) {
|
||||
$product_on_board = Product::find($product_on_board_id);
|
||||
$image = "";
|
||||
if ($product_on_board->images->count()) {
|
||||
$image = $product_on_board->images->first()->slug;
|
||||
}
|
||||
$cartItem = Yard::instance('shopping')->add($product_on_board->id, $product_on_board->getLang('name'), 1, $product_on_board->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product_on_board->slug, 'weight' => $product_on_board->weight, 'points' => $product_on_board->points, 'no_commission' => $product_on_board->no_commission, 'show_on' => $product_on_board->show_on]);
|
||||
if (\App\Services\UserService::getTaxFree()) {
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
} else {
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(\App\Services\UserService::$user_country));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while (ShoppingInstance::where('identifier', $identifier)->count());
|
||||
|
|
@ -608,9 +622,9 @@ class WizardController extends Controller
|
|||
|
||||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => 1, //is first faker shop for buy intern
|
||||
'user_shop_id' => 1, // is first faker shop for buy intern
|
||||
'auth_user_id' => Auth::user()->id,
|
||||
'payment' => 4, //Berater Wizard
|
||||
'payment' => 4, // Berater Wizard
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
|
|
@ -619,14 +633,16 @@ class WizardController extends Controller
|
|||
|
||||
]);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
//add to DB
|
||||
// add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier' => $identifier]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => 'wizard_payment', 'status' => 1, 'product_id' => $product->id, 'identifier' => $identifier, 'abo_options' => $showAboOptions]);
|
||||
//$path = str_replace('http', 'https', $path);
|
||||
|
||||
// $path = str_replace('http', 'https', $path);
|
||||
return redirect()->secure($path);
|
||||
}
|
||||
}
|
||||
\Session()->flash('alert-error', "Fehler beim Produkt");
|
||||
\Session()->flash('alert-error', 'Fehler beim Produkt');
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
|
|
@ -636,11 +652,12 @@ class WizardController extends Controller
|
|||
if ($relation === 'upload') {
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
$file = $user->files()->findOrFail($id);
|
||||
//remove file
|
||||
\Storage::disk('user')->delete($file->dir . $file->filename);
|
||||
// remove file
|
||||
\Storage::disk('user')->delete($file->dir.$file->filename);
|
||||
$file->delete();
|
||||
\Session()->flash('alert-success', __('msg.file_deleted'));
|
||||
}
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Auth;
|
||||
use Closure;
|
||||
|
||||
class ActiveAccount
|
||||
{
|
||||
|
|
@ -11,16 +11,14 @@ class ActiveAccount
|
|||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if ( Auth::check() && Auth::user()->isActiveAccount() )
|
||||
{
|
||||
if (Auth::check() && (Auth::user()->isAdmin() || Auth::user()->isActiveAccount())) {
|
||||
return $next($request);
|
||||
}
|
||||
return redirect('/home');
|
||||
|
||||
return redirect('/home');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue