#51 Festschreiben der Points, Gutschriftenmodul
This commit is contained in:
parent
dfd049aaa9
commit
3f2fbd6d5b
63 changed files with 4610 additions and 971 deletions
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\BusinessPlan\TreeCalcBot;
|
||||
use Request;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\UserBusiness;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Models\UserBusinessStructure;
|
||||
use App\Services\BusinessPlan\TreeCalcBot;
|
||||
|
||||
|
||||
class BusinessController extends Controller
|
||||
|
|
@ -21,7 +23,6 @@ class BusinessController extends Controller
|
|||
public function show()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::$months,
|
||||
'filter_years' => HTMLHelper::getYearRange(),
|
||||
|
|
@ -31,12 +32,15 @@ class BusinessController extends Controller
|
|||
return view('admin.business.show', $data);
|
||||
}
|
||||
|
||||
|
||||
public function structure()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
$TreeCalcBot = new TreeCalcBot(session('business_user_filter_month'), session('business_user_filter_year'), 'admin');
|
||||
$TreeCalcBot->initMain();
|
||||
$this->month = session('business_user_filter_month');
|
||||
$this->year = session('business_user_filter_year');
|
||||
|
||||
$TreeCalcBot = new TreeCalcBot($this->month, $this->year, 'admin');
|
||||
$TreeCalcBot->initStructureAdmin();
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::$months,
|
||||
'filter_years' => HTMLHelper::getYearRange(),
|
||||
|
|
@ -50,18 +54,31 @@ class BusinessController extends Controller
|
|||
$user = User::findOrFail($user_id);
|
||||
$this->setFilterVars();
|
||||
|
||||
$TreeCalcBot = new TreeCalcBot(session('business_user_filter_month'), session('business_user_filter_year'), 'admin');
|
||||
$TreeCalcBot->initDetailUser($user);
|
||||
if(!$TreeCalcBot->user){
|
||||
$data = [];
|
||||
$data['month'] = session('business_user_filter_month');
|
||||
$data['year'] = session('business_user_filter_year');
|
||||
|
||||
$TreeCalcBot = new TreeCalcBot($data['month'], $data['year'], 'admin');
|
||||
$TreeCalcBot->initBusinesslUserDetail($user);
|
||||
if(!$TreeCalcBot->business_user){
|
||||
abort(403, 'no user found');
|
||||
}
|
||||
$data = [
|
||||
'month' => HTMLHelper::getMonth(session('business_user_filter_month')),
|
||||
'year' => session('business_user_filter_year'),
|
||||
'TreeCalcBot' => $TreeCalcBot,
|
||||
'user' => $user,
|
||||
];
|
||||
return view('admin.business.user_detail', $data);
|
||||
return view('admin.business.user_detail', compact('TreeCalcBot', 'user', 'data'));
|
||||
}
|
||||
|
||||
public function userStore($user_id)
|
||||
{
|
||||
dd('function on: App\Console\Commands\BusinessStore');
|
||||
/*$data = Request::all();
|
||||
$user = User::findOrFail($data['user_id']);
|
||||
$TreeCalcBot = new TreeCalcBot($data['month'], $data['year'], 'admin');
|
||||
$TreeCalcBot->initBusinesslUserDetail($user);
|
||||
if(!$TreeCalcBot->business_user){
|
||||
abort(403, 'no user found');
|
||||
}
|
||||
//$TreeCalcBot->storeBusinesslUser();*/
|
||||
|
||||
//return back();
|
||||
}
|
||||
|
||||
private function setFilterVars(){
|
||||
|
|
@ -90,12 +107,123 @@ class BusinessController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
private function initSearch($archive = false, $request = true)
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
public function userDatatable()
|
||||
{
|
||||
$this->month = Request::get('business_user_filter_month');
|
||||
$this->year = Request::get('business_user_filter_year');
|
||||
|
||||
//only the currently month get from Users -> older month from UserBusiness
|
||||
//return $this->userCurrentlyDatatable();
|
||||
if(TreeCalcBot::isFromStored($this->month, $this->year)){
|
||||
return $this->userStoredDatatable();
|
||||
}else{
|
||||
return $this->userCurrentlyDatatable();
|
||||
}
|
||||
}
|
||||
|
||||
private function initStoredSearch($archive = false, $request = true)
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$query = UserBusiness::select('user_businesses.*')->where('month', $this->month)->where('year', $this->year);
|
||||
if(Request::get('business_user_filter_active')){
|
||||
if(Request::get('business_user_filter_active') == 1){
|
||||
$query->where('user_businesses.active_account', 1);
|
||||
}
|
||||
if(Request::get('business_user_filter_active') == 2){
|
||||
$query->where('user_businesses.active_account', 0);
|
||||
}
|
||||
if(Request::get('business_user_filter_active') == 3){
|
||||
//both -> payment_account only not null
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function userStoredDatatable()
|
||||
{
|
||||
$query = $this->initStoredSearch();
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (UserBusiness $userBusiness) {
|
||||
return '<button type="button" class="btn icon-btn btn-xs btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="'.$userBusiness->user_id.'"
|
||||
data-action="business-user-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="admin"
|
||||
data-route="'.route('modal_load').'"><span class="far fa-calculator"></span></button>';
|
||||
//.'<a href="' . route('admin_business_user_detail', [$userBusiness->user_id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="far fa-calculator"></span></a>';
|
||||
})
|
||||
->addColumn('m_account', function (UserBusiness $userBusiness) {
|
||||
return $userBusiness->m_account;
|
||||
})
|
||||
->addColumn('user_level', function (UserBusiness $userBusiness) {
|
||||
return $userBusiness->user_level_name;
|
||||
})
|
||||
->addColumn('is_qual_kp', function (UserBusiness $userBusiness) {
|
||||
if($userBusiness->m_level_id){
|
||||
$isQualKP = ($userBusiness->sales_volume_points_sum >= $userBusiness->qual_kp) ? true : false;
|
||||
return '<span class="badge '.($isQualKP ? 'badge-outline-success' : 'badge-outline-danger').'"> KD '.$userBusiness->qual_kp.'</span>';
|
||||
}
|
||||
return '-';
|
||||
})
|
||||
->addColumn('sales_volume_points', function (UserBusiness $userBusiness) {
|
||||
return '<div class="no-line-break">'.$userBusiness->sales_volume_points_sum.'</div>'.
|
||||
'<span class="small no-line-break">B: '.$userBusiness->sales_volume_points.' | S: '.$userBusiness->sales_volume_points_shop.'</span>';
|
||||
})
|
||||
->addColumn('sales_volume_total', function (UserBusiness $userBusiness) {
|
||||
return '<div class="no-line-break">'.formatNumber($userBusiness->sales_volume_total_sum).' €</div>'.
|
||||
'<span class="small no-line-break">B: '.formatNumber($userBusiness->sales_volume_total).' | S: '.formatNumber($userBusiness->sales_volume_total_shop).'</span>';
|
||||
})
|
||||
->addColumn('email', function (UserBusiness $userBusiness) {
|
||||
return $userBusiness->email;
|
||||
})
|
||||
->addColumn('first_name', function (UserBusiness $userBusiness) {
|
||||
return $userBusiness->first_name;
|
||||
})
|
||||
->addColumn('last_name', function (UserBusiness $userBusiness) {
|
||||
return $userBusiness->last_name;
|
||||
})
|
||||
->addColumn('sponsor', function (UserBusiness $userBusiness) {
|
||||
if($userBusiness->sponsor){
|
||||
$sponsor = "";
|
||||
if($userBusiness->sponsor->is_sponsor){
|
||||
$sponsor .= $userBusiness->sponsor->first_name." ".$userBusiness->sponsor->last_name;
|
||||
$sponsor .= " ".'<button type="button" class="btn icon-btn btn-xs btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="'.$userBusiness->sponsor->user_id.'"
|
||||
data-action="business-user-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="admin"
|
||||
data-route="'.route('modal_load').'"><span class="far fa-calculator"></span></button><br>';
|
||||
|
||||
$sponsor .= '<span class="small no-line-break">'.$userBusiness->sponsor->email;
|
||||
$sponsor .= ' | '.$userBusiness->sponsor->m_account;
|
||||
$sponsor .= '</span>';
|
||||
}
|
||||
|
||||
return $sponsor;
|
||||
}
|
||||
return '-';
|
||||
})
|
||||
|
||||
->addColumn('active_account', function (UserBusiness $userBusiness) {
|
||||
return get_active_badge($userBusiness->active_account);
|
||||
})
|
||||
->addColumn('payment_account_date', function (UserBusiness $userBusiness) {
|
||||
return $userBusiness->active_date ? formatDate($userBusiness->active_date) : "-";
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('active_account', 'payment_account $1')
|
||||
->rawColumns(['id', 'is_qual_kp', 'sales_volume_points', 'sales_volume_total', 'sponsor', 'active_account'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
private function initCurrentlySearch($archive = false, $request = true)
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$query = User::with('account')->select('users.*')
|
||||
->where('users.deleted_at', '=', null)
|
||||
->where('users.id', '!=', 1)
|
||||
|
|
@ -114,26 +242,12 @@ class BusinessController extends Controller
|
|||
//both -> payment_account only not null
|
||||
}
|
||||
}
|
||||
|
||||
if(Request::get('business_user_filter_name')){
|
||||
//$query->where('users.account.first_name', 'LIKE', '%'.Request::get('business_user_filter_name').'%');
|
||||
//$query->where('users.account.last_name', 'LIKE', '%'.Request::get('business_user_filter_name').'%');
|
||||
//$query->where('users.account.m_account', 'LIKE', '%'.Request::get('business_user_filter_name').'%');
|
||||
//$query->where('users.email', 'LIKE', '%'.Request::get('business_user_filter_name').'%');
|
||||
|
||||
}
|
||||
|
||||
//->orderBy('created_at', 'DESC');
|
||||
/* $query = FlexHour::leftJoin("flex_hour_items", function($join) {
|
||||
$join->on("flex_hour_items.flex_hour_id","=","flex_hours.id");
|
||||
$join->where("flex_hour_items.date","=", FlexHourItemBot::$date);
|
||||
})*/
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function userDatatable()
|
||||
{
|
||||
$query = $this->initSearch();
|
||||
|
||||
private function userCurrentlyDatatable()
|
||||
{
|
||||
$query = $this->initCurrentlySearch();
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (User $user) {
|
||||
return '<button type="button" class="btn icon-btn btn-xs btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
|
|
@ -142,25 +256,40 @@ class BusinessController extends Controller
|
|||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="admin"
|
||||
data-route="'.route('modal_load').'"><span class="far fa-calculator"></span></button>';
|
||||
//<a href="' . route('admin_business_user_detail', [$user->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="far fa-calculator"></span></a>
|
||||
data-route="'.route('modal_load').'"><span class="far fa-calculator"></span></button>'
|
||||
.'<a href="' . route('admin_business_user_detail', [$user->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="far fa-calculator"></span></a>';
|
||||
})
|
||||
->addColumn('m_account', function (User $user) {
|
||||
return $user->account ? $user->account->m_account : '';
|
||||
})
|
||||
->addColumn('user_level', function (User $user) {
|
||||
return $user->user_level ? $user->user_level->name : '';
|
||||
})
|
||||
->addColumn('active_account', function (User $user) {
|
||||
return get_active_badge($user->isActiveAccount());
|
||||
})
|
||||
->addColumn('payment_account_date', function (User $user) {
|
||||
return $user->payment_account ? $user->getPaymentAccountDateFormat(false) : "-";
|
||||
})
|
||||
->addColumn('sales_volume_points', function (User $user) {
|
||||
->addColumn('is_qual_kp', function (User $user) {
|
||||
if($user->user_level){
|
||||
$qual_kp = $user->user_level->qual_kp;
|
||||
$sales_volume_points_sum = $user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_points_sum');
|
||||
$isQualKP = ($sales_volume_points_sum >= $qual_kp) ? true : false;
|
||||
return '<span class="badge '.($isQualKP ? 'badge-outline-success' : 'badge-outline-danger').'"> KD '.$qual_kp.'</span>';
|
||||
}
|
||||
return '-';
|
||||
})
|
||||
->addColumn('sales_volume_points', function (User $user) {
|
||||
return '<div class="no-line-break">'.$user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_points_sum').'</div>'.
|
||||
'<span class="small no-line-break">B: '.$user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_points').' | S: '.$user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_points_shop').'</span>';
|
||||
})
|
||||
->addColumn('sales_volume_total', function (User $user) {
|
||||
return '<div class="no-line-break">'.$user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_total_sum').'</div>'.
|
||||
'<span class="small no-line-break">B: '.$user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_total').' | S: '.$user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_total_shop').'</span>';
|
||||
return '<div class="no-line-break">'.formatNumber($user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_total_sum')).' €</div>'.
|
||||
'<span class="small no-line-break">B: '.formatNumber($user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_total')).' | S: '.formatNumber($user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_total_shop')).'</span>';
|
||||
})
|
||||
->addColumn('email', function (User $user) {
|
||||
return $user->email;
|
||||
})
|
||||
->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('sponsor', function (User $user) {
|
||||
if($user->user_sponsor){
|
||||
|
|
@ -175,7 +304,7 @@ class BusinessController extends Controller
|
|||
data-init_from="admin"
|
||||
data-route="'.route('modal_load').'"><span class="far fa-calculator"></span></button><br>';
|
||||
}
|
||||
$sponsor .= '<span class="small no-line-break">'.$user->email;
|
||||
$sponsor .= '<span class="small no-line-break">'.$user->user_sponsor->email;
|
||||
if($user->user_sponsor->account){
|
||||
$sponsor .= ' | '.$user->user_sponsor->account->m_account;
|
||||
}
|
||||
|
|
@ -184,51 +313,17 @@ class BusinessController extends Controller
|
|||
return $sponsor;
|
||||
}
|
||||
return '-';
|
||||
|
||||
return '<div class="no-line-break">'.$user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_total_sum').'</div>'.
|
||||
'<span class="small no-line-break">B: '.$user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_total').' | S: '.$user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_total_shop').'</span>';
|
||||
})
|
||||
|
||||
->addColumn('is_qual_kp', function (User $user) {
|
||||
if($user->user_level){
|
||||
$qual_kp = $user->user_level->qual_kp;
|
||||
$sales_volume_points_sum = $user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_points_sum');
|
||||
$isQualKP = ($sales_volume_points_sum >= $qual_kp) ? true : false;
|
||||
return '<span class="badge '.($isQualKP ? 'badge-outline-success' : 'badge-outline-danger').'"> KD '.$qual_kp.'</span>';
|
||||
}
|
||||
return '-';
|
||||
->addColumn('active_account', function (User $user) {
|
||||
return get_active_badge($user->isActiveAccount());
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* ->addColumn('sales_volume_points', function (User $user) {
|
||||
return $user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_points');
|
||||
->addColumn('payment_account_date', function (User $user) {
|
||||
return $user->payment_account ? $user->getPaymentAccountDateFormat(false) : "-";
|
||||
})
|
||||
->addColumn('sales_volume_points_shop', function (User $user) {
|
||||
return $user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_points_shop');
|
||||
})
|
||||
->addColumn('sales_volume_points_sum', function (User $user) {
|
||||
return $user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_points_sum');
|
||||
})
|
||||
->addColumn('sales_volume_total', function (User $user) {
|
||||
return $user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_total');
|
||||
})
|
||||
->addColumn('sales_volume_total_shop', function (User $user) {
|
||||
return $user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_total_shop');
|
||||
})
|
||||
->addColumn('sales_volume_total_sum', function (User $user) {
|
||||
return $user->getUserSalesVolumeBy($this->month, $this->year, 'sales_volume_total_sum');
|
||||
})*/
|
||||
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('m_account', 'm_account $1')
|
||||
->orderColumn('first_name', 'first_name $1')
|
||||
->orderColumn('last_name', 'last_name $1')
|
||||
->orderColumn('user_level', 'm_level $1')
|
||||
->orderColumn('active_account', 'payment_account $1')
|
||||
->rawColumns(['id', 'is_qual_kp', 'confirmed', 'sales_volume_points', 'sales_volume_total', 'sponsor', 'active', 'active_account'])
|
||||
->rawColumns(['id', 'is_qual_kp', 'sales_volume_points', 'sales_volume_total', 'sponsor', 'active_account'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ class BusinessPointsController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
private function initSearch($archive = false, $request = true)
|
||||
private function initSearch()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
|
|
@ -184,7 +184,7 @@ class BusinessPointsController extends Controller
|
|||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('order', 'order $1')
|
||||
->orderColumn('status', 'status $1')
|
||||
->orderColumn('status', 'message $1')
|
||||
->orderColumn('message', 'message $1')
|
||||
|
||||
->rawColumns(['id', 'order', 'status', 'message', 'total_net'])
|
||||
->make(true);
|
||||
|
|
|
|||
|
|
@ -17,13 +17,19 @@ class FileController extends Controller
|
|||
{
|
||||
}
|
||||
|
||||
private function isPermission($shopping_order){
|
||||
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;
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
private function isPermissionUserCredit($user_credit){
|
||||
if(Auth::user()->isAdmin() || $user_credit->user_id == Auth::user()->id){
|
||||
return true;
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
public function show($id = null, $disk = null, $do='file')
|
||||
|
|
@ -43,7 +49,7 @@ class FileController extends Controller
|
|||
if ($disk === 'invoice'){
|
||||
$shopping_order = \App\Models\ShoppingOrder::findOrFail($id);
|
||||
if($shopping_order->user_invoice){
|
||||
$this->isPermission($shopping_order);
|
||||
$this->isPermissionShoppingOrder($shopping_order);
|
||||
$user_invoice = $shopping_order->user_invoice;
|
||||
$filename = $user_invoice->filename;
|
||||
$disk = $user_invoice->disk;
|
||||
|
|
@ -52,25 +58,15 @@ class FileController extends Controller
|
|||
return Response::make('File no found.', 404);;
|
||||
}
|
||||
$file = Storage::disk($disk)->get($path);
|
||||
$mime = Storage::disk($disk)->mimeType($path);
|
||||
|
||||
}
|
||||
if($do === 'download'){
|
||||
return Response::make($file, 200)
|
||||
->header("Content-Type", $mime)
|
||||
->header('Content-disposition', 'attachment; filename="'.$filename.'"');
|
||||
}
|
||||
if($do === 'stream'){
|
||||
return Response::make($file, 200)
|
||||
->header("Content-Type", $mime)
|
||||
->header('Content-disposition','inline; filename="'.$filename.'"');
|
||||
$mime = Storage::disk($disk)->mimeType($path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($disk === 'delivery'){
|
||||
$shopping_order = \App\Models\ShoppingOrder::findOrFail($id);
|
||||
if($shopping_order->user_invoice){
|
||||
$this->isPermission($shopping_order);
|
||||
$this->isPermissionShoppingOrder($shopping_order);
|
||||
$user_invoice = $shopping_order->user_invoice;
|
||||
$filename = $user_invoice->delivery_filename;
|
||||
$disk = $user_invoice->disk;
|
||||
|
|
@ -80,8 +76,24 @@ class FileController extends Controller
|
|||
}
|
||||
$file = Storage::disk($disk)->get($path);
|
||||
$mime = Storage::disk($disk)->mimeType($path);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($disk === 'credit'){
|
||||
$user_credit = \App\Models\UserCredit::findOrFail($id);
|
||||
$this->isPermissionUserCredit($user_credit);
|
||||
$filename = $user_credit->filename;
|
||||
$disk = $user_credit->disk;
|
||||
$path = $user_credit->getDownloadPath();
|
||||
if (!Storage::disk($disk)->exists($path)) {
|
||||
return Response::make('File no found.', 404);;
|
||||
}
|
||||
$file = Storage::disk($disk)->get($path);
|
||||
$mime = Storage::disk($disk)->mimeType($path);
|
||||
}
|
||||
|
||||
if(isset($file)){
|
||||
if($do === 'download'){
|
||||
return Response::make($file, 200)
|
||||
->header("Content-Type", $mime)
|
||||
|
|
@ -93,9 +105,9 @@ class FileController extends Controller
|
|||
->header('Content-disposition','inline; filename="'.$filename.'"');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*if ($disk === 'credit'){
|
||||
$UserCredit = \App\Models\UserCredit::findOrFail($id);
|
||||
$this->isPermission($UserCredit->auth_user_id);
|
||||
|
||||
$filename = Credit::getFilename($UserCredit);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use App\Models\Product;
|
|||
use App\Models\Homeparty;
|
||||
use App\Models\UserLevel;
|
||||
|
||||
use App\Models\UserCredit;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Models\HomepartyUser;
|
||||
|
|
@ -116,11 +117,10 @@ class ModalController extends Controller
|
|||
$data['month'] = session('team_user_filter_month');
|
||||
$data['year'] = session('team_user_filter_year');
|
||||
}
|
||||
$TreeCalcBot = $this->getForBusinessUserDetail($user, $data);
|
||||
$TreeCalcBot = $this->getForBusinessUserDetail($user, $data);
|
||||
$route = "";
|
||||
$ret = view("admin.modal.business_user_detail", compact('TreeCalcBot', 'user', 'data'))->render();
|
||||
}
|
||||
|
||||
if($data['action'] === 'edit_user_sales_volume'){
|
||||
$userSalesVolume = UserSalesVolume::findOrFail($data['id']);
|
||||
$route = route('admin_business_points_store', );
|
||||
|
|
@ -130,7 +130,15 @@ class ModalController extends Controller
|
|||
$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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
|
||||
}
|
||||
|
|
@ -140,8 +148,8 @@ class ModalController extends Controller
|
|||
$auth_user = \Auth::user();
|
||||
if($auth_user->isAdmin() || $auth_user->id === $user->id){
|
||||
$TreeCalcBot = new TreeCalcBot($data['month'], $data['year'], $data['init_from']);
|
||||
$TreeCalcBot->initDetailUser($user);
|
||||
if(!$TreeCalcBot->user){
|
||||
$TreeCalcBot->initBusinesslUserDetail($user);
|
||||
if(!$TreeCalcBot->business_user){
|
||||
abort(403, 'no user found');
|
||||
}
|
||||
return $TreeCalcBot;
|
||||
|
|
|
|||
|
|
@ -10,9 +10,15 @@ use App\Services\Util;
|
|||
use App\Services\Credit;
|
||||
use App\Services\Payment;
|
||||
use App\Models\UserCredit;
|
||||
use App\Models\ShoppingOrderMargin;
|
||||
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 stdClass;
|
||||
|
||||
class PaymentCreditController extends Controller
|
||||
{
|
||||
|
|
@ -24,8 +30,8 @@ class PaymentCreditController extends Controller
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->startYear = 2021;
|
||||
$this->middleware('admin');
|
||||
$this->startYear = 2022;
|
||||
$this->endYear = date('Y');
|
||||
$this->rangeYears = range($this->startYear, $this->endYear);
|
||||
$this->activeYear = $this->endYear;
|
||||
|
|
@ -34,36 +40,35 @@ class PaymentCreditController extends Controller
|
|||
|
||||
public function index()
|
||||
{
|
||||
abort(403, "in progress");
|
||||
$data = $this->makeData();
|
||||
return view('admin.payment.credit.index', $data);
|
||||
$this->setFilterVars();
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::$months,
|
||||
'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'){
|
||||
$add_credit_error = false;
|
||||
if(!isset($data['member_id']) || !$user = User::find($data['member_id'])){
|
||||
$add_credit_error = 'Vertriebspartner nicht gefunden';
|
||||
\Session()->flash('alert-error', 'Vertriebspartner nicht gefunden');
|
||||
return back();
|
||||
}
|
||||
if(!isset($data['credit'])){
|
||||
$add_credit_error = 'Bitte Betrag eingeben';
|
||||
\Session()->flash('alert-error', 'Bitte Betrag eingebe');
|
||||
return back();
|
||||
}
|
||||
if(!isset($data['message'])){
|
||||
$add_credit_error = 'Bitte Mitteilung eingeben';
|
||||
}
|
||||
if($add_credit_error){
|
||||
$data = $this->makeData();
|
||||
$data['add_credit_error'] = $add_credit_error;
|
||||
return view('admin.payment.credit.index', $data);
|
||||
\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");
|
||||
}
|
||||
|
|
@ -79,8 +84,8 @@ class PaymentCreditController extends Controller
|
|||
abort(404);
|
||||
}
|
||||
$user = User::findOrFail($data['userid']);
|
||||
$invoice_repo = new CreditRepository($user);
|
||||
$invoice_repo->create($data);
|
||||
$credit_repo = new CreditRepository($user);
|
||||
$credit_repo->create($data);
|
||||
\Session()->flash('alert-success', "Gutschrift erstellt");
|
||||
return redirect($data['back']);
|
||||
}
|
||||
|
|
@ -94,79 +99,52 @@ class PaymentCreditController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
private function makeData(){
|
||||
$this->setActiveYears();
|
||||
//$date1 = Carbon::parse('01.01.'.$this->activeYear." 00:00:00")->format('Y-m-d H:i:s');
|
||||
//$date2 = Carbon::parse('31.12.'.$this->activeYear." 23:59:59")->toDateString();
|
||||
|
||||
$ShoppingOrderMargins = ShoppingOrderMargin::join('users', 'm_sponsor_id', '=', 'users.id')
|
||||
->groupBy('m_sponsor_id')
|
||||
->join('user_accounts', 'account_id', '=', 'user_accounts.id')
|
||||
->select('users.id as user_id', 'users.email', 'user_accounts.first_name', 'user_accounts.last_name')
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->wherePartnerCommissionPaid(false)
|
||||
->where('partner_commission_pending_to', '<', Carbon::now())
|
||||
->get();
|
||||
|
||||
$ShoppingOrderMarginPendings = ShoppingOrderMargin::join('users', 'm_sponsor_id', '=', 'users.id')
|
||||
->groupBy('m_sponsor_id')
|
||||
->join('user_accounts', 'account_id', '=', 'user_accounts.id')
|
||||
->select('users.id as user_id', 'users.email', 'user_accounts.first_name', 'user_accounts.last_name')
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->wherePartnerCommissionPaid(false)
|
||||
->where('partner_commission_pending_to', '>=', Carbon::now())
|
||||
->get();
|
||||
|
||||
$UserCreditMargins = UserCreditMargin::wherePaid(false)->get();
|
||||
$ShoppingOrderMarginUserIds = ShoppingOrderMargin::select('m_sponsor_id')->groupBy('m_sponsor_id')
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->wherePartnerCommissionPaid(false)
|
||||
->where('partner_commission_pending_to', '<', Carbon::now())
|
||||
->get()->pluck('m_sponsor_id')->toArray();
|
||||
|
||||
$onlyUserCreditMargins = [];
|
||||
foreach($UserCreditMargins as $key => $UserCreditMargin){
|
||||
if(!in_array($UserCreditMargin->user_id, $ShoppingOrderMarginUserIds)){
|
||||
if(isset($onlyUserCreditMargins[$UserCreditMargin->user_id])){
|
||||
$onlyUserCreditMargins[$UserCreditMargin->user_id]['sum'] += $UserCreditMargin->credit;
|
||||
$onlyUserCreditMargins[$UserCreditMargin->user_id]['entries'][$UserCreditMargin->id] = $UserCreditMargin;
|
||||
}else{
|
||||
$onlyUserCreditMargins[$UserCreditMargin->user_id] = [
|
||||
'user_id' => $UserCreditMargin->user->id,
|
||||
'first_name' => $UserCreditMargin->user->account->first_name,
|
||||
'last_name' => $UserCreditMargin->user->account->last_name,
|
||||
'email' => $UserCreditMargin->user->email,
|
||||
'sum' => $UserCreditMargin->credit,
|
||||
'entries' => [$UserCreditMargin->id => $UserCreditMargin],
|
||||
];
|
||||
}
|
||||
}
|
||||
private function setFilterVars(){
|
||||
if(!session('credit_filter_month')){
|
||||
session(['credit_filter_month' => intval(date('m'))]);
|
||||
}
|
||||
$data = [
|
||||
'years' => $this->rangeYears,
|
||||
'active_year' => $this->activeYear,
|
||||
'ShoppingOrderMargins' => $ShoppingOrderMargins,
|
||||
'ShoppingOrderMarginPendings' => $ShoppingOrderMarginPendings,
|
||||
'onlyUserCreditMargins' => $onlyUserCreditMargins,
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function setActiveYears(){
|
||||
if(Request::get('filter_sales_year')){
|
||||
$this->activeYear = Request::get('filter_sales_year');
|
||||
if(!session('credit_filter_year')){
|
||||
session(['credit_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
if(Request::get('credit_filter_name')){
|
||||
session(['credit_filter_name' => Request::get('credit_filter_name')]);
|
||||
}
|
||||
if(Request::get('credit_filter_month')){
|
||||
session(['credit_filter_month' => Request::get('credit_filter_month')]);
|
||||
}
|
||||
if(Request::get('credit_filter_year')){
|
||||
session(['credit_filter_year' => Request::get('credit_filter_year')]);
|
||||
}
|
||||
}
|
||||
|
||||
private function makeUserCreditItems(){
|
||||
$ret = [];
|
||||
$UserCreditItems = UserCreditItem::wherePaid(false)->get();
|
||||
foreach($UserCreditItems as $userCreditItem){
|
||||
if(isset($ret[$userCreditItem->user_id])){
|
||||
$ret[$userCreditItem->user_id]['sum'] += $userCreditItem->credit;
|
||||
$ret[$userCreditItem->user_id]['entries'][$userCreditItem->id] = $userCreditItem;
|
||||
}else{
|
||||
$ret[$userCreditItem->user_id] = [
|
||||
'user_id' => $userCreditItem->user_id,
|
||||
'm_account' => $userCreditItem->user->account->m_account,
|
||||
'first_name' => $userCreditItem->user->account->first_name,
|
||||
'last_name' => $userCreditItem->user->account->last_name,
|
||||
'email' => $userCreditItem->user->email,
|
||||
'sum' => $userCreditItem->credit,
|
||||
'entries' => [$userCreditItem->id => $userCreditItem],
|
||||
];
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function delete($id, $del){
|
||||
|
||||
if($del === 'user_credit_margin'){
|
||||
$UserCreditMargin = UserCreditMargin::findOrFail($id);
|
||||
if($deleteTime = $UserCreditMargin->deleteTime()){
|
||||
$UserCreditMargin->delete();
|
||||
if($del === 'user_credit_item'){
|
||||
$UserCreditItem = UserCreditItem::findOrFail($id);
|
||||
if($deleteTime = $UserCreditItem->deleteTime()){
|
||||
$UserCreditItem->delete();
|
||||
\Session()->flash('alert-success', "Guthaben ist gelöscht");
|
||||
}else{
|
||||
\Session()->flash('alert-error', "Guthaben kann nicht gelöscht werden");
|
||||
|
|
@ -177,7 +155,7 @@ class PaymentCreditController extends Controller
|
|||
|
||||
public function datatable(){
|
||||
|
||||
$this->setActiveYears();
|
||||
$this->setFilterVars();
|
||||
$date1 = Carbon::parse('01.01.'.$this->activeYear)->format('Y-m-d');
|
||||
$date2 = Carbon::parse('31.12.'.$this->activeYear)->format('Y-m-d');
|
||||
|
||||
|
|
@ -188,32 +166,9 @@ class PaymentCreditController extends Controller
|
|||
//->orderBy('created_at', 'DESC');
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
|
||||
->addColumn('total', function (UserCredit $UserCredit) {
|
||||
return $UserCredit->getFormattedTotal()." €";
|
||||
})
|
||||
->addColumn('user_margins', function (UserCredit $UserCredit) {
|
||||
->addColumn('view', function (UserCredit $UserCredit) {
|
||||
$ret = "";
|
||||
if($UserCredit->user_margins){
|
||||
foreach($UserCredit->user_margins as $user_margin){
|
||||
$ret .= $user_margin->firstname."/".$user_margin->lastname."/".$user_margin->reference."/".$user_margin->created_at."<br>";
|
||||
}
|
||||
}
|
||||
if($UserCredit->user_credits){
|
||||
foreach($UserCredit->user_credits as $user_credit){
|
||||
$ret .= nl2br($user_credit->message)." / ".$user_credit->created_at."<br>";
|
||||
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
})
|
||||
/* ->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getShoppingOrderBadge($ShoppingOrder);
|
||||
})*/
|
||||
->addColumn('credit', function (UserCredit $UserCredit) {
|
||||
$ret = "";
|
||||
if(Credit::isCredit($UserCredit)){
|
||||
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>';
|
||||
}else{
|
||||
|
|
@ -222,6 +177,19 @@ class PaymentCreditController extends Controller
|
|||
return $ret;
|
||||
})
|
||||
|
||||
->addColumn('total', function (UserCredit $UserCredit) {
|
||||
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->message)." / ".$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="">
|
||||
|
|
@ -233,7 +201,7 @@ class PaymentCreditController extends Controller
|
|||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('status', 'status $1')
|
||||
->orderColumn('total', 'total $1')
|
||||
->rawColumns(['shipping_order', 'total', 'credit', 'status', 'user_margins'])
|
||||
->rawColumns(['total', 'credits', 'status', 'view'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ class PaymentInvoiceController extends Controller
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('admin');
|
||||
}
|
||||
|
||||
public function index()
|
||||
|
|
@ -115,10 +115,8 @@ class PaymentInvoiceController extends Controller
|
|||
$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('txaction', 'txaction $1')
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ use App\Services\SyS\Import;
|
|||
use App\Services\SyS\Cronjobs;
|
||||
use App\Services\SyS\Customers;
|
||||
use App\Services\SyS\DomainSSL;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Services\SyS\Correction;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\SyS\ShoppingOrders;
|
||||
use App\Services\SyS\BusinessStructur;
|
||||
|
||||
class SysController extends Controller
|
||||
{
|
||||
|
|
@ -26,27 +26,16 @@ class SysController extends Controller
|
|||
|
||||
public function index()
|
||||
{
|
||||
$UserSalesVolumes =UserSalesVolume::all();
|
||||
|
||||
foreach($UserSalesVolumes as $UserSalesVolume){
|
||||
if($UserSalesVolume->shopping_order->member_id !== NULL && $UserSalesVolume->user_id !== $UserSalesVolume->shopping_order->member_id){
|
||||
if($UserSalesVolume->shopping_order->member_id !== 6){
|
||||
dump($UserSalesVolume->shopping_order_id);
|
||||
dump($UserSalesVolume->shopping_order->member_id);
|
||||
dump($UserSalesVolume->user_id);
|
||||
|
||||
dump("##");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
dd("ebd");
|
||||
return view('sys.index');
|
||||
}
|
||||
|
||||
public function tool($serve)
|
||||
{
|
||||
switch ($serve) {
|
||||
|
||||
case 'business_structur':
|
||||
return BusinessStructur::show();
|
||||
break;
|
||||
case 'sales_members':
|
||||
return Sales::show();
|
||||
break;
|
||||
|
|
@ -76,6 +65,10 @@ class SysController extends Controller
|
|||
public function store($serve)
|
||||
{
|
||||
switch ($serve) {
|
||||
|
||||
case 'business_structur':
|
||||
return BusinessStructur::show();
|
||||
break;
|
||||
case 'sales_members':
|
||||
return Sales::show();
|
||||
break;
|
||||
|
|
|
|||
133
app/Http/Controllers/User/PaymentController.php
Normal file
133
app/Http/Controllers/User/PaymentController.php
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
<?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;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
|
||||
private $startYear;
|
||||
private $endYear;
|
||||
private $rangeYears;
|
||||
private $activeYear;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
/* $this->startYear = 2021;
|
||||
$this->endYear = date('Y');
|
||||
$this->rangeYears = range($this->startYear, $this->endYear);
|
||||
$this->activeYear = $this->endYear;*/
|
||||
}
|
||||
|
||||
public function credit()
|
||||
{
|
||||
$user = \Auth::user();
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
return view('user.payment.credit', $data);
|
||||
}
|
||||
|
||||
|
||||
public function credit_datatable(){
|
||||
|
||||
$user = \Auth::user();
|
||||
$query = UserCredit::with('user', 'user.account')->select('user_credits.*')->where('user_id', $user->id);
|
||||
|
||||
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>';
|
||||
}else{
|
||||
$ret = "-";
|
||||
}
|
||||
return $ret;
|
||||
})
|
||||
->addColumn('total', function (UserCredit $UserCredit) {
|
||||
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->message)." / ".$user_credit_item->created_at->format('d.m.Y')."<br>";
|
||||
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
})
|
||||
->addColumn('status', function (UserCredit $UserCredit) {
|
||||
return '<span class="badge badge-pill badge-'.$UserCredit->getStatusColor().'">'.$UserCredit->getStatusType().' <span class="ion ion-md-cash"></span></span>';
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('status', 'status $1')
|
||||
->orderColumn('total', 'total $1')
|
||||
->rawColumns(['total', 'credits', 'status', 'view'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
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->message);
|
||||
})
|
||||
->addColumn('credit', function (UserCreditItem $user_credit_item) {
|
||||
return formatNumber($user_credit_item->credit)." €";
|
||||
})
|
||||
->addColumn('created_at', function (UserCreditItem $user_credit_item) {
|
||||
return formatDate($user_credit_item->created_at);
|
||||
})
|
||||
->addColumn('status', function (UserCreditItem $user_credit_item) {
|
||||
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>'
|
||||
: '<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')
|
||||
->orderColumn('status', 'status $1')
|
||||
->rawColumns(['message', 'status', 'paid'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
/*private function setActiveYears(){
|
||||
if(Request::get('filter_year')){
|
||||
$this->activeYear = Request::get('filter_year');
|
||||
}
|
||||
}
|
||||
|
||||
public function revenue()
|
||||
{
|
||||
$this->setActiveYears();
|
||||
|
||||
$user = \Auth::user();
|
||||
$data = [
|
||||
'user' => $user,
|
||||
'years' => $this->rangeYears,
|
||||
'active_year' => $this->activeYear,
|
||||
'months' => range(1, 12),
|
||||
];
|
||||
return view('user.payment.revenue', $data);
|
||||
}*/
|
||||
}
|
||||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\BusinessPlan\TreeCalcBot;
|
||||
use Request;
|
||||
|
||||
|
||||
use Auth;
|
||||
|
||||
class TeamController extends Controller
|
||||
{
|
||||
|
|
@ -38,18 +38,32 @@ class TeamController extends Controller
|
|||
$user = User::find(\Auth::user()->id);
|
||||
$this->setFilterVars();
|
||||
$TreeCalcBot = new TreeCalcBot(session('team_user_filter_month'), session('team_user_filter_year'), 'member');
|
||||
$TreeCalcBot->initUser($user->id);
|
||||
$TreeCalcBot->initStructureUser($user->id);
|
||||
//for testing
|
||||
//$TreeCalcBot->initUser(56);
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::$months,
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
'filter_years' => HTMLHelper::getYearRange(date('Y')),
|
||||
'TreeCalcBot' => $TreeCalcBot,
|
||||
];
|
||||
return view('user.team.structure', $data);
|
||||
}
|
||||
|
||||
|
||||
public function points()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$userSalesVolume = $user->getUserSalesVolume(intval(session('team_user_points_filter_month')), intval(session('team_user_points_filter_year')), 'first');
|
||||
$data = [
|
||||
'userSalesVolume' => $userSalesVolume,
|
||||
'filter_months' => HTMLHelper::$months,
|
||||
'filter_years' => HTMLHelper::getYearRange(date('Y')),
|
||||
];
|
||||
return view('user.team.points', $data);
|
||||
}
|
||||
|
||||
|
||||
private function setFilterVars(){
|
||||
|
||||
if(!session('team_user_filter_month')){
|
||||
|
|
@ -58,13 +72,90 @@ class TeamController extends Controller
|
|||
if(!session('team_user_filter_year')){
|
||||
session(['team_user_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
|
||||
if(!session('team_user_points_filter_month')){
|
||||
session(['team_user_points_filter_month' => intval(date('m'))]);
|
||||
}
|
||||
if(!session('team_user_points_filter_year')){
|
||||
session(['team_user_points_filter_year' => intval(date('Y'))]);
|
||||
}
|
||||
|
||||
if(Request::get('team_user_filter_month')){
|
||||
session(['team_user_filter_month' => Request::get('team_user_filter_month')]);
|
||||
}
|
||||
if(Request::get('team_user_filter_year')){
|
||||
session(['team_user_filter_year' => Request::get('team_user_filter_year')]);
|
||||
if(Request::get('team_user_points_filter_year')){
|
||||
session(['team_user_points_filter_year' => Request::get('team_user_points_filter_year')]);
|
||||
}
|
||||
|
||||
if(Request::get('team_user_points_filter_month')){
|
||||
session(['team_user_points_filter_month' => Request::get('team_user_points_filter_month')]);
|
||||
}
|
||||
if(Request::get('team_user_points_filter_year')){
|
||||
session(['team_user_points_filter_year' => Request::get('team_user_points_filter_year')]);
|
||||
}
|
||||
}
|
||||
|
||||
private function initSearchPoints()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$user_id = \Auth::user()->id;
|
||||
$query = UserSalesVolume::with('user', 'user.account')->with('shopping_order')->select('user_sales_volumes.*')
|
||||
->where('user_sales_volumes.user_id', '=', $user_id)
|
||||
->where('user_sales_volumes.month', '=', Request::get('team_user_points_filter_month'))
|
||||
->where('user_sales_volumes.year', '=', Request::get('team_user_points_filter_year'));
|
||||
|
||||
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>';
|
||||
}
|
||||
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).' €';
|
||||
})
|
||||
|
||||
->addColumn('status', function (UserSalesVolume $UserSalesVolume) {
|
||||
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>';
|
||||
})
|
||||
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('order', 'order $1')
|
||||
->orderColumn('status', 'status $1')
|
||||
->orderColumn('message', 'message $1')
|
||||
|
||||
->rawColumns(['id', 'order', 'status', 'message', 'total_net'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function load(){
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$userSalesVolume = $user->getUserSalesVolume(intval(session('team_user_points_filter_month')), intval(session('team_user_points_filter_year')), 'first');
|
||||
|
||||
$data = [
|
||||
'userSalesVolume' => $userSalesVolume,
|
||||
];
|
||||
$html = view('user.team._points_sum', $data)->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html'=>$html]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue