#51 Festschreiben der Points, Gutschriftenmodul
This commit is contained in:
parent
dfd049aaa9
commit
3f2fbd6d5b
63 changed files with 4610 additions and 971 deletions
78
app/Console/Commands/BusinessStore.php
Normal file
78
app/Console/Commands/BusinessStore.php
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Cron\BusinessUsersStore;
|
||||
|
||||
class BusinessStore extends Command
|
||||
{
|
||||
/**
|
||||
* php artisan business:store month year
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'business:store {month} {year}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create Business Structur and UserDetails';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$day = (int) Setting::getContentBySlug('day-exectute-business-structur');
|
||||
$this->info('RUN Command BusinessStore on Day '. $day);
|
||||
|
||||
$timeStart = microtime(true);
|
||||
$this->info('RUN Command BusinessStore');
|
||||
|
||||
$month = $this->argument('month');
|
||||
$year = $this->argument('year');
|
||||
if(!$month || !$year){
|
||||
$this->info('need arguments month & year');
|
||||
return 0;
|
||||
}
|
||||
|
||||
//$this->info('month: '.$month.' year:'.$year);
|
||||
for($i = 1; $i<=6; $i++){
|
||||
$month = $i;
|
||||
$this->info('month: '.$month.' year:'.$year);
|
||||
$businessUsersStore = new BusinessUsersStore($month, $year);
|
||||
$businessUsersStore->storeUserBusinessStructure();
|
||||
$businessUsersStore->storeBusinessUsersDetail();
|
||||
$bool = $businessUsersStore->storeBusinessCompleted();
|
||||
|
||||
$diff = microtime(true) - $timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
$this->info('BusinessStore: '.$bool. ' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
|
||||
}
|
||||
|
||||
|
||||
//$this->info('END Command BusinessStore: '.$bool. ' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
|
||||
// \Log::info('Cron is running');
|
||||
//return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Console\Commands\BusinessStore;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
|
|
@ -13,7 +14,7 @@ class Kernel extends ConsoleKernel
|
|||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
//
|
||||
BusinessStore::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
159
app/Cron/BusinessUsersStore.php
Normal file
159
app/Cron/BusinessUsersStore.php
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
namespace App\Cron;
|
||||
|
||||
use App\User;
|
||||
use stdClass;
|
||||
use App\Models\UserBusinessStructure;
|
||||
use App\Services\BusinessPlan\TreeCalcBot;
|
||||
|
||||
class BusinessUsersStore
|
||||
{
|
||||
private $month;
|
||||
private $year;
|
||||
|
||||
private $user_business_structure;
|
||||
private $users_structure = [];
|
||||
|
||||
|
||||
public function __construct($month, $year)
|
||||
{
|
||||
$this->month = $month;
|
||||
$this->year = $year;
|
||||
}
|
||||
|
||||
|
||||
public function getStoreUserBusinessStructure(){
|
||||
return UserBusinessStructure::where('year', $this->year)->where('month', $this->month)->first();
|
||||
}
|
||||
|
||||
public function storeUserBusinessStructure()
|
||||
{
|
||||
if($this->user_business_structure = $this->getStoreUserBusinessStructure()){
|
||||
return $this->user_business_structure;
|
||||
}
|
||||
$treeCalcBot = new TreeCalcBot($this->month, $this->year, 'admin');
|
||||
//only load, when no structur is save
|
||||
$treeCalcBot->initStructureAdmin(false);
|
||||
$this->storeStructure($treeCalcBot);
|
||||
}
|
||||
|
||||
public function storeBusinessUsersDetail()
|
||||
{
|
||||
if(!$this->user_business_structure){
|
||||
$this->user_business_structure = $this->getStoreUserBusinessStructure();
|
||||
if(!$this->user_business_structure){
|
||||
abort(403, 'not found UserBusinessStructure');
|
||||
}
|
||||
}
|
||||
foreach($this->user_business_structure->users as $user_id=>$completed){
|
||||
if($completed === 0){
|
||||
$user = User::findOrFail($user_id);
|
||||
$TreeCalcBot = new TreeCalcBot($this->month, $this->year, 'admin');
|
||||
$TreeCalcBot->initBusinesslUserDetail($user);
|
||||
if(!$TreeCalcBot->business_user){
|
||||
abort(403, 'not found TreeCalcBot->business_user');
|
||||
}
|
||||
$this->storeBusinesslUser($TreeCalcBot->business_user);
|
||||
$users = $this->user_business_structure->users;
|
||||
$users[$user_id] = 1;
|
||||
$this->user_business_structure->users = $users;
|
||||
$this->user_business_structure->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function storeBusinesslUser($business_user){
|
||||
$b_user = $business_user->getBUser();
|
||||
$b_user->user_items = $this->storeUserItems($business_user->businessUserItems, 1);
|
||||
$b_user->b_structure_id = $this->user_business_structure->id;
|
||||
$b_user->save();
|
||||
}
|
||||
|
||||
|
||||
public function storeBusinessCompleted(){
|
||||
if(!$this->user_business_structure){
|
||||
$this->user_business_structure = $this->getStoreUserBusinessStructure();
|
||||
}
|
||||
foreach($this->user_business_structure->users as $user_id=>$completed){
|
||||
if($completed === 0){
|
||||
return false;
|
||||
}
|
||||
$this->user_business_structure->completed = 1;
|
||||
$this->user_business_structure->save();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private function storeUserItems($userItems, $line){
|
||||
$ret = [];
|
||||
foreach($userItems as $userItem){
|
||||
$temp = null;
|
||||
if(count($userItem->businessUserItems) > 0){
|
||||
$temp = $this->storeUserItems($userItem->businessUserItems, $line+1);
|
||||
}
|
||||
$obj = new stdClass();
|
||||
$obj->user_id = $userItem->user_id;
|
||||
$obj->line = $line;
|
||||
$obj->points = $userItem->sales_volume_points_sum;
|
||||
$obj->parents = $temp;
|
||||
$ret[] = $obj;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
private function storeStructure($treeCalcBot)
|
||||
{
|
||||
/*if($this->user_business_structure = $this->getStoreUserBusinessStructure()){
|
||||
return $this->user_business_structure;
|
||||
}*/
|
||||
|
||||
$structure = [];
|
||||
foreach($treeCalcBot->business_users as $business_user){
|
||||
$structure[] = $this->storeStructureItem($business_user, 0);
|
||||
}
|
||||
|
||||
$parentless = [];
|
||||
if($treeCalcBot->parentless){
|
||||
foreach($treeCalcBot->parentless as $pless){
|
||||
$parentless[] = $this->storeStructureItem($pless, 0);
|
||||
}
|
||||
}
|
||||
$fill = [
|
||||
'month' => $this->month,
|
||||
'year' => $this->year,
|
||||
'structure' => $structure,
|
||||
'parentless' => $parentless,
|
||||
'users' => $this->users_structure,
|
||||
'completed' => false,
|
||||
'status' => 0
|
||||
];
|
||||
$this->user_business_structure = UserBusinessStructure::create($fill);
|
||||
return $this->user_business_structure;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function storeStructureItem($item, $deep){
|
||||
$temp = null;
|
||||
if($item->businessUserItems){
|
||||
foreach($item->businessUserItems as $parent){
|
||||
$temp[] = $this->storeStructureItem($parent, $deep+1);
|
||||
}
|
||||
}
|
||||
$this->users_structure[$item->user_id] = 0;
|
||||
$obj = new stdClass();
|
||||
$obj->user_id = $item->user_id;
|
||||
//$obj->name = $item->first_name .' '. $item->last_name ;
|
||||
$obj->email = $item->email;
|
||||
$obj->deep = $deep;
|
||||
//$obj->points = $item->sales_volume_points_sum;
|
||||
$obj->parents = $temp;
|
||||
return $obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
54
app/Mail/MailCredit.php
Normal file
54
app/Mail/MailCredit.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
namespace App\Mail;
|
||||
|
||||
use Storage;
|
||||
use App\User;
|
||||
use App\Services\Credit;
|
||||
use App\Services\Invoice;
|
||||
use App\Models\UserCredit;
|
||||
use App\Models\ShoppingOrder;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class MailCredit extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
protected $user_credit;
|
||||
|
||||
public $subject;
|
||||
|
||||
|
||||
public function __construct(UserCredit $user_credit)
|
||||
{
|
||||
$this->user_credit = $user_credit;
|
||||
$this->subject = 'Deine Gutschrift auf mivita.care';
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
$title = __('email.credit_title');
|
||||
$copy1line = __('email.credit_copy1line');
|
||||
|
||||
$filename = $this->user_credit->filename;
|
||||
$disk = $this->user_credit->disk;
|
||||
$path = $this->user_credit->getDownloadPath();
|
||||
|
||||
if (!Storage::disk($disk)->exists($path)) {
|
||||
return;
|
||||
}
|
||||
$file = Storage::disk($disk)->path($path);
|
||||
$file = str_replace('//', '/', $file);
|
||||
$mime = Storage::disk($disk)->mimeType($path);
|
||||
|
||||
return $this->view('emails.blank')->with([
|
||||
'title' => $title,
|
||||
'copy1line' => $copy1line,
|
||||
])->attach($file,[
|
||||
'as' => $filename,
|
||||
'mime' => $mime,
|
||||
]); // attach file;
|
||||
}
|
||||
}
|
||||
104
app/Models/UserBusiness.php
Normal file
104
app/Models/UserBusiness.php
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
|
||||
|
||||
class UserBusiness extends Model
|
||||
{
|
||||
protected $table = 'user_businesses';
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => 'int',
|
||||
'month' => 'int',
|
||||
'year' => 'int',
|
||||
'b_structure_id' => 'int',
|
||||
'm_level_id' => 'int',
|
||||
'active_account' => 'bool',
|
||||
'm_account' => 'int',
|
||||
'sales_volume_points' => 'int',
|
||||
'sales_volume_points_shop' => 'int',
|
||||
'sales_volume_points_sum' => 'int',
|
||||
'sales_volume_total' => 'float',
|
||||
'sales_volume_total_shop' => 'float',
|
||||
'sales_volume_total_sum' => 'float',
|
||||
'margin' => 'int',
|
||||
'margin_shop' => 'int',
|
||||
'qual_kp' => 'int',
|
||||
'qual_tp' => 'int',
|
||||
'total_tp' => 'int',
|
||||
'total_qual_tp' => 'int',
|
||||
'commission_team_total' => 'float',
|
||||
'commission_shop_sales' => 'float',
|
||||
'qual_user_level' => 'array',
|
||||
'sponsor' => 'object',
|
||||
'business_lines' => AsArrayObject::class,
|
||||
'user_items' => AsArrayObject::class
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'payment_account_date',
|
||||
'active_date'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'month',
|
||||
'year',
|
||||
'b_structure_id',
|
||||
'm_level_id',
|
||||
'sponsor',
|
||||
'user_level_name',
|
||||
'active_account',
|
||||
'payment_account_date',
|
||||
'active_date',
|
||||
'm_account',
|
||||
'email',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'sales_volume_points',
|
||||
'sales_volume_points_shop',
|
||||
'sales_volume_points_sum',
|
||||
'sales_volume_total',
|
||||
'sales_volume_total_shop',
|
||||
'sales_volume_total_sum',
|
||||
'margin',
|
||||
'margin_shop',
|
||||
'qual_kp',
|
||||
'qual_tp',
|
||||
'qual_user_level',
|
||||
'total_tp',
|
||||
'total_qual_tp',
|
||||
'commission_team_total',
|
||||
'commission_shop_sales',
|
||||
'business_lines',
|
||||
'user_items',
|
||||
];
|
||||
|
||||
public function user_business_structure()
|
||||
{
|
||||
return $this->belongsTo(UserBusinessStructure::class, 'b_structure_id');
|
||||
}
|
||||
|
||||
public function isSave(){
|
||||
return $this->id !== null ? true : false;
|
||||
}
|
||||
|
||||
public function setPaymentAccountDateAttribute( $value ) {
|
||||
$this->attributes['payment_account_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
|
||||
}
|
||||
|
||||
|
||||
public function setActiveDateAttribute( $value ) {
|
||||
$this->attributes['active_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
73
app/Models/UserBusinessStructure.php
Normal file
73
app/Models/UserBusinessStructure.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
|
||||
|
||||
|
||||
/**
|
||||
* Class UserBusinessStructure
|
||||
*
|
||||
* @property int $id
|
||||
* @property int|null $month
|
||||
* @property int|null $year
|
||||
* @property object|null $structure
|
||||
* @property object|null $parentless
|
||||
* @property array|null $users
|
||||
* @property bool $completed
|
||||
* @property int $status
|
||||
* @package App\Models
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserBusiness[] $user_businesses
|
||||
* @property-read int|null $user_businesses_count
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserBusinessStructure newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserBusinessStructure newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserBusinessStructure query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserBusinessStructure whereCompleted($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserBusinessStructure whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserBusinessStructure whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserBusinessStructure whereMonth($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserBusinessStructure whereParentless($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserBusinessStructure whereStatus($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserBusinessStructure whereStructure($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserBusinessStructure whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserBusinessStructure whereUsers($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserBusinessStructure whereYear($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class UserBusinessStructure extends Model
|
||||
{
|
||||
protected $table = 'user_business_structures';
|
||||
|
||||
protected $casts = [
|
||||
'month' => 'int',
|
||||
'year' => 'int',
|
||||
'completed' => 'bool',
|
||||
'status' => 'int',
|
||||
'structure' => 'object',
|
||||
'parentless' => 'object',
|
||||
'users' => 'array',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'month',
|
||||
'year',
|
||||
'structure',
|
||||
'parentless',
|
||||
'users',
|
||||
'completed',
|
||||
'status'
|
||||
];
|
||||
|
||||
|
||||
public function user_businesses()
|
||||
{
|
||||
return $this->hasMany(UserBusiness::class, 'b_structure_id');
|
||||
}
|
||||
}
|
||||
172
app/Models/UserCredit.php
Normal file
172
app/Models/UserCredit.php
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* Class UserCredit
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int|null $month
|
||||
* @property int|null $year
|
||||
* @property Carbon|null $date
|
||||
* @property string|null $full_number
|
||||
* @property int|null $number
|
||||
* @property float|null $net
|
||||
* @property float|null $tax_rate
|
||||
* @property float|null $tax
|
||||
* @property float|null $total
|
||||
* @property string|null $filename
|
||||
* @property string|null $dir
|
||||
* @property string|null $disk
|
||||
* @property array|null $infos
|
||||
* @property bool $paid_out
|
||||
* @property Carbon|null $paid_out_date
|
||||
* @property bool $cancellation
|
||||
* @property int|null $cancellation_id
|
||||
* @property Carbon|null $cancellation_date
|
||||
* @property int $status
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property string|null $deleted_at
|
||||
*
|
||||
* @property User $user
|
||||
* @property Collection|UserCreditItem[] $user_credit_items
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class UserCredit extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
protected $table = 'user_credits';
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => 'int',
|
||||
'month' => 'int',
|
||||
'year' => 'int',
|
||||
'number' => 'int',
|
||||
'net' => 'float',
|
||||
'tax_rate' => 'float',
|
||||
'tax' => 'float',
|
||||
'taxable' => 'bool',
|
||||
'total' => 'float',
|
||||
'paid_out' => 'bool',
|
||||
'cancellation' => 'bool',
|
||||
'cancellation_id' => 'int',
|
||||
'status' => 'int',
|
||||
'infos' => 'array'
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'date',
|
||||
'paid_out_date',
|
||||
'cancellation_date'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'month',
|
||||
'year',
|
||||
'date',
|
||||
'full_number',
|
||||
'number',
|
||||
'net',
|
||||
'tax_rate',
|
||||
'tax',
|
||||
'total',
|
||||
'taxable',
|
||||
'filename',
|
||||
'dir',
|
||||
'disk',
|
||||
'infos',
|
||||
'paid_out',
|
||||
'paid_out_date',
|
||||
'cancellation',
|
||||
'cancellation_id',
|
||||
'cancellation_date',
|
||||
'status'
|
||||
];
|
||||
|
||||
public static $statusTypes = [
|
||||
0 => 'offen',
|
||||
1 => 'bezahlt',
|
||||
2 => 'prüfen',
|
||||
10 => 'storniert'
|
||||
];
|
||||
|
||||
public static $statusColors = [
|
||||
0 => 'warning',
|
||||
1 => 'success',
|
||||
2 => 'secondary',
|
||||
10 => 'danger',
|
||||
];
|
||||
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function user_credit_items()
|
||||
{
|
||||
return $this->hasMany(UserCreditItem::class);
|
||||
}
|
||||
|
||||
public function isCredit(){
|
||||
return $this->filename ? true : false;
|
||||
}
|
||||
|
||||
public function getDateAttribute($value)
|
||||
{
|
||||
return $value ? Carbon::parse($value)->format(\Util::formatDateDB()) : "";
|
||||
}
|
||||
|
||||
|
||||
public function setDateAttribute( $value ) {
|
||||
$this->attributes['date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
|
||||
}
|
||||
public function getDateRaw(){
|
||||
return isset($this->attributes['date']) ? $this->attributes['date'] : NULL;
|
||||
}
|
||||
|
||||
public function getFormattedTax()
|
||||
{
|
||||
return formatNumber($this->attributes['tax']);
|
||||
}
|
||||
|
||||
public function getFormattedNet()
|
||||
{
|
||||
return formatNumber($this->attributes['net']);
|
||||
}
|
||||
|
||||
public function getFormattedTotal()
|
||||
{
|
||||
return formatNumber($this->attributes['total']);
|
||||
}
|
||||
|
||||
|
||||
public function getStatusType(){
|
||||
return isset(self::$statusTypes[$this->status]) ? self::$statusTypes[$this->status] : "";
|
||||
}
|
||||
|
||||
public function getStatusColor(){
|
||||
return isset(self::$statusColors[$this->status]) ? self::$statusColors[$this->status] : "default";
|
||||
}
|
||||
|
||||
public function getDownloadPath($full = false){
|
||||
if(!$full){
|
||||
return $this->dir.$this->filename;
|
||||
}
|
||||
return \Storage::disk($this->disk)->path($this->dir.$this->filename);
|
||||
}
|
||||
}
|
||||
99
app/Models/UserCreditItem.php
Normal file
99
app/Models/UserCreditItem.php
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class UserCreditItem
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int|null $user_credit_id
|
||||
* @property float|null $credit
|
||||
* @property string|null $message
|
||||
* @property int $status
|
||||
* @property bool $paid
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @property UserCredit|null $user_credit
|
||||
* @property User $user
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class UserCreditItem extends Model
|
||||
{
|
||||
|
||||
|
||||
public static $statusTypes = [
|
||||
1 => 'Provision Shop',
|
||||
2 => 'Provision Team',
|
||||
3 => 'Guthaben hinzugefügt',
|
||||
4 => 'commission ...',
|
||||
];
|
||||
|
||||
public static $statusColors = [
|
||||
0 => 'warning',
|
||||
1 => 'success',
|
||||
2 => 'secondary',
|
||||
3 => 'warning',
|
||||
4 => 'info',
|
||||
10 => 'danger',
|
||||
];
|
||||
|
||||
|
||||
protected $table = 'user_credit_items';
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => 'int',
|
||||
'user_credit_id' => 'int',
|
||||
'credit' => 'float',
|
||||
'status' => 'int',
|
||||
'paid' => 'bool'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'user_credit_id',
|
||||
'credit',
|
||||
'message',
|
||||
'status',
|
||||
'paid'
|
||||
];
|
||||
|
||||
public function user_credit()
|
||||
{
|
||||
return $this->belongsTo(UserCredit::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
|
||||
public function deleteTime(){
|
||||
$time = '+100 min';
|
||||
if(Carbon::parse($this->created_at)->modify($time)->gt(Carbon::now())){
|
||||
return Carbon::now()->diffInMinutes(Carbon::parse($this->created_at)->modify($time));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getStatusType(){
|
||||
return isset(self::$statusTypes[$this->status]) ? self::$statusTypes[$this->status] : "";
|
||||
}
|
||||
|
||||
public function getStatusColor(){
|
||||
return isset(self::$statusColors[$this->status]) ? self::$statusColors[$this->status] : "default";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -56,6 +56,8 @@ use App\User;
|
|||
* @method static \Illuminate\Database\Eloquent\Builder|UserSalesVolume whereUserInvoiceId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserSalesVolume whereYear($value)
|
||||
* @mixin \Eloquent
|
||||
* @property array|null $syslog
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserSalesVolume whereSyslog($value)
|
||||
*/
|
||||
class UserSalesVolume extends Model
|
||||
{
|
||||
|
|
|
|||
125
app/Repositories/CreditRepository.php
Normal file
125
app/Repositories/CreditRepository.php
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use PDF;
|
||||
use Storage;
|
||||
use App\User;
|
||||
use App\Services\Credit;
|
||||
use App\Models\UserCredit;
|
||||
use App\Services\UserMarign;
|
||||
|
||||
use App\Services\MyPDFMerger;
|
||||
use App\Models\UserCreditItem;
|
||||
|
||||
class CreditRepository extends BaseRepository {
|
||||
|
||||
private $user_credit;
|
||||
public function __construct(User $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function create($request = [])
|
||||
{
|
||||
//need invoice $data
|
||||
$number = Credit::getCreditNumber();
|
||||
$credit_date = isset($request['credit_date']) ? $request['credit_date'] : \Carbon::now()->format("d.m.Y");
|
||||
$credit_send_mail = isset($request['credit_send_mail']) ? true: false;
|
||||
$credit_number = Credit::createCreditNumber($number, $credit_date);
|
||||
|
||||
$this->user_credit = new UserCredit();
|
||||
$user_credit_items = $this->makeUserCredit();
|
||||
$data = [
|
||||
'user' => $this->model,
|
||||
'credit_date' => $credit_date,
|
||||
'credit_number' => $credit_number,
|
||||
'user_credits' => $this->user_credit,
|
||||
'user_credit_items' => $user_credit_items,
|
||||
];
|
||||
$pdf = PDF::loadView('pdf.credit', $data);
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
|
||||
$dir = Credit::getCreditStorageDir($credit_date);
|
||||
if(!Storage::disk('public')->exists( $dir )){
|
||||
Storage::disk('public')->makeDirectory($dir); //creates directory
|
||||
}
|
||||
$path = Storage::disk('public')->getAdapter()->getPathPrefix();
|
||||
$filename = Credit::makeCreditFilename($credit_number);
|
||||
|
||||
$pdf->save($path.$dir.$filename);
|
||||
|
||||
$pdfMerger = new MyPDFMerger();
|
||||
$pdfMerger->addPDF($path.$dir.$filename);
|
||||
$file = $pdfMerger->myMerge('string', $filename, 'template_invoice_de');
|
||||
Storage::disk('public')->put($dir.$filename, $file);
|
||||
|
||||
|
||||
|
||||
$this->user_credit->user_id = $this->model->id;
|
||||
$this->user_credit->year = \Carbon::parse($credit_date)->format('Y');
|
||||
$this->user_credit->month = \Carbon::parse($credit_date)->format('n');
|
||||
$this->user_credit->date = $credit_date;
|
||||
$this->user_credit->filename = $filename;
|
||||
$this->user_credit->dir = $dir;
|
||||
$this->user_credit->disk = 'public';
|
||||
$this->user_credit->number = $number;
|
||||
$this->user_credit->full_number = $credit_number;
|
||||
$this->user_credit->save();
|
||||
|
||||
if($credit_send_mail){
|
||||
Credit::sendCreditMail($this->user_credit);
|
||||
}
|
||||
$this->finishUserCredit($this->user_credit->id, $user_credit_items);
|
||||
return true;
|
||||
}
|
||||
|
||||
private function finishUserCredit($user_credit_id, $user_credit_items){
|
||||
//next credits
|
||||
Credit::makeNextCreditNumber();
|
||||
//mark as payed
|
||||
//$UserCreditItems = UserCreditItem::where('user_id', $this->model->id)->wherePaid(false)->get();
|
||||
foreach($user_credit_items as $user_credit_item){
|
||||
$user_credit_item->paid = true;
|
||||
$user_credit_item->user_credit_id = $user_credit_id;
|
||||
$user_credit_item->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function makeUserCredit(){
|
||||
|
||||
$this->user_credit->net = 0;
|
||||
$this->user_credit->infos = [];
|
||||
$infos = [];
|
||||
$user_credit_items = [];
|
||||
|
||||
|
||||
$UserCreditItems = UserCreditItem::where('user_id', $this->model->id)->wherePaid(false)->get();
|
||||
foreach($UserCreditItems as $userCreditItem){
|
||||
$user_credit_items[] = $userCreditItem;
|
||||
$infos[] = ['id' => $userCreditItem->id, 'credit' => $userCreditItem->credit];
|
||||
$this->user_credit->net += $userCreditItem->credit;
|
||||
}
|
||||
/* taxable_sales //user tax
|
||||
1 //umsatzsteuerpflichtig
|
||||
2 // nicht umsatzsteuerpflichtig
|
||||
*/
|
||||
if($this->model->account){
|
||||
$this->user_credit->taxable = $this->model->account->taxable_sales == 2 ? false : true;
|
||||
if($this->user_credit->taxable){
|
||||
$this->user_credit->tax_rate = config('app.main_tax_rate');
|
||||
$this->user_credit->total = round($this->user_credit->net * config('app.main_tax'), 2);
|
||||
$this->user_credit->tax = $this->user_credit->total - $this->user_credit->net;
|
||||
|
||||
}else{
|
||||
$this->user_credit->tax_rate = 0;
|
||||
$this->user_credit->total = $this->user_credit->net;
|
||||
$this->user_credit->tax = 0;
|
||||
}
|
||||
}
|
||||
$this->user_credit->infos = $infos;
|
||||
return $user_credit_items;
|
||||
}
|
||||
|
||||
}
|
||||
172
app/Services/BusinessPlan/BusinessTreeUserItem.php
Normal file
172
app/Services/BusinessPlan/BusinessTreeUserItem.php
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
namespace App\Services\BusinessPlan;
|
||||
|
||||
use App\User;
|
||||
use stdClass;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\UserLevel;
|
||||
use App\Models\UserBusiness;
|
||||
|
||||
|
||||
class TreeUserItem
|
||||
{
|
||||
public $items = [];
|
||||
private $date;
|
||||
public $lines = [];
|
||||
|
||||
public $user_level_active;
|
||||
|
||||
|
||||
|
||||
public function __construct($date)
|
||||
{
|
||||
$this->date = $date;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function makeUser(User $user){
|
||||
|
||||
$this->user_level_active = $user->user_level ? $user->user_level : null;
|
||||
$this->b_user = new UserBusiness();
|
||||
$fill = [
|
||||
'user_id' => $user->id,
|
||||
'month' => $this->date->month,
|
||||
'year' => $this->date->year,
|
||||
'm_level' => $user->m_level,
|
||||
'm_sponsor' => $user->m_sponsor,
|
||||
'user_level_name' => $user->user_level ? $user->user_level->name : '',
|
||||
'active_account' => $user->payment_account ? Carbon::parse($user->payment_account)->gt(Carbon::parse($this->date->start_date)) : false,
|
||||
'payment_account_date' => $user->payment_account ? $user->getPaymentAccountDateFormat(false) : NULL,
|
||||
'active_date' => $user->active_date ? $user->active_date : NULL,
|
||||
'm_account' => $user->account->m_account,
|
||||
'email' => $user->email,
|
||||
'first_name' => $user->account->first_name,
|
||||
'last_name' => $user->account->last_name,
|
||||
'sales_volume_points' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_points'),
|
||||
'sales_volume_points_shop' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_points_shop'),
|
||||
'sales_volume_points_sum' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_points_sum'),
|
||||
'sales_volume_total' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_total'),
|
||||
'sales_volume_total_shop' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_total_shop'),
|
||||
'sales_volume_total_sum' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_total_sum'),
|
||||
'margin' => $user->user_level_active ? $user->user_level_active->margin : 0,
|
||||
'margin_shop' => $user->user_level_active ? $user->user_level_active->margin_shop : 0,
|
||||
'qual_kp' => $user->user_level_active ? $user->user_level_active->qual_kp : 0,
|
||||
'qual_tp' => $user->user_level_active ? $user->user_level_active->qual_tp : 0,
|
||||
];
|
||||
$this->b_user->fill($fill);
|
||||
}
|
||||
|
||||
public function addUserID(){
|
||||
TreeCalcBot::addUserID($this->user_id);
|
||||
}
|
||||
|
||||
public function isQualKP(){
|
||||
return ($this->sales_volume_points_sum >= $this->qual_kp) ? true : false;
|
||||
}
|
||||
|
||||
public function getRestQualKP(){
|
||||
return $this->sales_volume_points_sum - $this->qual_kp;
|
||||
}
|
||||
|
||||
public function checkSponsor(){
|
||||
if($this->m_sponsor === null){
|
||||
$this->m_sponsor_name = 'Keinen Sponsor zugewiesen';
|
||||
return;
|
||||
}
|
||||
$user = User::find($this->m_sponsor);
|
||||
if($user){
|
||||
if($user->account){
|
||||
$this->m_sponsor_name = substr('Sponsor: '.$user->account->first_name.' '.$user->account->last_name.' | '.$user->email.' | '.$user->account->m_account, 0, 190);
|
||||
}else{
|
||||
$this->m_sponsor_name = 'Sponsor: '.$user->email;
|
||||
}
|
||||
return;
|
||||
}
|
||||
$this->m_sponsor_name = 'Sponsor wurde gelöscht.';
|
||||
return;
|
||||
}
|
||||
/*
|
||||
|
||||
'total_tp' => ,
|
||||
'total_qual_tp' => ,
|
||||
'commission_total' => ,
|
||||
'lines',
|
||||
'items',
|
||||
'qual_user_level_id'
|
||||
*/
|
||||
public function readParentsUser(){
|
||||
|
||||
$users = User::with('account')->select('users.*')
|
||||
->where('users.deleted_at', '=', null)
|
||||
->where('users.id', '!=', 1)
|
||||
->where('users.admin', "<", 4)
|
||||
->where('users.m_level', "!=", null)
|
||||
->where('users.m_sponsor', "=", $this->user_id) //<- need the id for parents / sponsors
|
||||
->where('users.payment_account', "!=", null)
|
||||
->where('users.active_date', "<=", $this->date->end_date)
|
||||
->get();
|
||||
dd($users);
|
||||
if($users){
|
||||
foreach($users as $user){
|
||||
$TreeUserItem = new TreeUserItem($this->date);
|
||||
$TreeUserItem->makeUser($user);
|
||||
$TreeUserItem->addUserID();
|
||||
$this->items[] = $TreeUserItem;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->items as $item){
|
||||
$item->readParentsUser();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function calcUserTP($line){
|
||||
if(!isset($this->lines[$line])){
|
||||
$this->lines[$line] = new stdClass();
|
||||
$this->lines[$line]->points = 0;
|
||||
}
|
||||
foreach($this->items as $item){
|
||||
if(count($item->items) > 0){
|
||||
$this->calcUserTP($line+1);
|
||||
}
|
||||
$this->lines[$line]->points += $item->sales_volume_points_sum;
|
||||
$this->total_tp += $item->sales_volume_points_sum;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function calcQualTP(){
|
||||
if($this->isQualKP()){
|
||||
$this->total_qual_tp = $this->total_tp + $this->getRestQualKP();
|
||||
$this->qual_user_level = UserLevel::where('qual_tp', '<=', $this->total_qual_tp)->where('pos', '<=', $this->user->user_level->pos)->orderBy('qual_tp', 'desc')->first();
|
||||
$this->commission_total = 0;
|
||||
if($this->qual_user_level){
|
||||
foreach($this->lines as $line => $values){
|
||||
$values->margin = $this->qual_user_level->{'pr_line_'.$line};
|
||||
if($line > 6){
|
||||
//wachstumsbonus
|
||||
$values->margin = $this->qual_user_level->growth_bonus;
|
||||
}
|
||||
$values->commission = round($values->points / 100 * $values->margin, 2);
|
||||
|
||||
$this->commission_total += $values->commission;
|
||||
$this->lines[$line] = $values;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function __get($property) {
|
||||
if (property_exists($this->b_user, $property)) {
|
||||
return $this->b_user->$property;
|
||||
}
|
||||
if (isset($this->b_user->{$property})) {
|
||||
return $this->b_user->{$property};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
257
app/Services/BusinessPlan/BusinessUserItem.php
Normal file
257
app/Services/BusinessPlan/BusinessUserItem.php
Normal file
|
|
@ -0,0 +1,257 @@
|
|||
<?php
|
||||
namespace App\Services\BusinessPlan;
|
||||
|
||||
use App\User;
|
||||
use stdClass;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\UserLevel;
|
||||
use App\Models\UserBusiness;
|
||||
use App\Models\UserBusinessStructure;
|
||||
|
||||
|
||||
class BusinessUserItem
|
||||
{
|
||||
public $businessUserItems = [];
|
||||
|
||||
private $date;
|
||||
private $b_user;
|
||||
private $user_level_active_pos;
|
||||
|
||||
|
||||
|
||||
public function __construct($date)
|
||||
{
|
||||
$this->date = $date;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function makeUser($user_id){
|
||||
|
||||
//check for user an load
|
||||
$this->b_user = UserBusiness::where('user_id', $user_id)->where('month', $this->date->month)->where('year', $this->date->year)->first();
|
||||
if($this->b_user !== null){
|
||||
return;
|
||||
}
|
||||
//read User here, can delete in stored data.
|
||||
$user = User::find($user_id);
|
||||
$user_level_active = $user->user_level ? $user->user_level : null;
|
||||
$this->user_level_active_pos = $user_level_active ? $user_level_active->pos : 0;
|
||||
$this->b_user = new UserBusiness();
|
||||
$fill = [
|
||||
'user_id' => $user->id,
|
||||
'month' => $this->date->month,
|
||||
'year' => $this->date->year,
|
||||
'm_level_id' => $user->m_level,
|
||||
'user_level_name' => $user_level_active ? $user_level_active->name : '',
|
||||
'active_account' => $user->payment_account ? Carbon::parse($user->payment_account)->gt(Carbon::parse($this->date->start_date)) : false,
|
||||
'payment_account_date' => $user->payment_account ? $user->getPaymentAccountDateFormat(false) : NULL,
|
||||
'active_date' => $user->active_date ? $user->active_date : NULL,
|
||||
'm_account' => $user->account->m_account,
|
||||
'email' => $user->email,
|
||||
'first_name' => $user->account->first_name,
|
||||
'last_name' => $user->account->last_name,
|
||||
'sales_volume_points' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_points'),
|
||||
'sales_volume_points_shop' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_points_shop'),
|
||||
'sales_volume_points_sum' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_points_sum'),
|
||||
'sales_volume_total' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_total'),
|
||||
'sales_volume_total_shop' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_total_shop'),
|
||||
'sales_volume_total_sum' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_total_sum'),
|
||||
'margin' => $user_level_active ? $user_level_active->margin : 0,
|
||||
'margin_shop' => $user_level_active ? $user_level_active->margin_shop : 0,
|
||||
'qual_kp' => $user_level_active ? $user_level_active->qual_kp : 0,
|
||||
'qual_tp' => $user_level_active ? $user_level_active->qual_tp : 0,
|
||||
'commission_team_total' => 0,
|
||||
'commission_shop_sales' => 0,
|
||||
];
|
||||
$this->b_user->fill($fill);
|
||||
$this->b_user->business_lines = [];
|
||||
$this->b_user->user_items = [];
|
||||
$this->b_user->commission_shop_sales = round($this->b_user->sales_volume_total_shop / 100 * $this->b_user->margin_shop, 2);
|
||||
|
||||
}
|
||||
|
||||
public function addUserID(){
|
||||
TreeCalcBot::addUserID($this->b_user->user_id);
|
||||
}
|
||||
public function getBUser(){
|
||||
return $this->b_user;
|
||||
}
|
||||
|
||||
public function addBusinessLineToUser($line, $obj){
|
||||
$this->b_user->business_lines[$line] = $obj;
|
||||
}
|
||||
|
||||
public function addBusinessLinePoints($line, $points){
|
||||
$obj = $this->business_lines[$line];
|
||||
$obj->points += $points;
|
||||
$this->b_user->business_lines[$line] = $obj;
|
||||
}
|
||||
|
||||
public function addTotalTP($points){
|
||||
$this->b_user->total_tp += $points;
|
||||
|
||||
}
|
||||
|
||||
public function isQualKP(){
|
||||
return ($this->sales_volume_points_sum >= $this->qual_kp) ? true : false;
|
||||
}
|
||||
|
||||
public function getRestQualKP(){
|
||||
return $this->sales_volume_points_sum - $this->qual_kp;
|
||||
}
|
||||
|
||||
public function getCommissionTotal(){
|
||||
return round($this->commission_shop_sales + $this->commission_team_total, 2);
|
||||
}
|
||||
|
||||
public function calcQualTP(){
|
||||
if($this->isQualKP()){
|
||||
$this->b_user->total_qual_tp = $this->total_tp + $this->getRestQualKP();
|
||||
$commission_total = 0;
|
||||
$qualUserLevel = UserLevel::where('qual_tp', '<=', $this->total_qual_tp)->where('pos', '<=', $this->user_level_active_pos)->orderBy('qual_tp', 'desc')->first();
|
||||
if($qualUserLevel){
|
||||
$this->b_user->qual_user_level = $qualUserLevel->toArray();
|
||||
foreach($this->business_lines as $line => $object){
|
||||
//growth_bonus = ab ebene 6 wachstumsbonus
|
||||
$object->margin = ($line <= 6) ? $this->qual_user_level['pr_line_'.$line] : $this->qual_user_level['growth_bonus'];
|
||||
$object->commission = round($object->points / 100 * $object->margin, 2);
|
||||
$commission_total += $object->commission;
|
||||
$this->b_user->business_lines[$line] = $object;
|
||||
}
|
||||
}
|
||||
$this->b_user->commission_team_total = $commission_total;
|
||||
}
|
||||
}
|
||||
|
||||
/*public function storeUser(){
|
||||
$this->b_user->user_items = $this->storeUserItems($this->businessUserItems, 1);
|
||||
$this->b_user->save();
|
||||
}
|
||||
|
||||
private function storeUserItems($userItems, $line){
|
||||
$ret = [];
|
||||
foreach($userItems as $userItem){
|
||||
$temp = null;
|
||||
if(count($userItem->businessUserItems) > 0){
|
||||
$temp = $this->storeUserItems($userItem->businessUserItems, $line+1);
|
||||
}
|
||||
$obj = new stdClass();
|
||||
$obj->user_id = $userItem->user_id;
|
||||
$obj->line = $line;
|
||||
$obj->points = $userItem->sales_volume_points_sum;
|
||||
$obj->parents = $temp;
|
||||
$ret[] = $obj;
|
||||
}
|
||||
return $ret;
|
||||
}*/
|
||||
|
||||
public function readParentsBusinessUsers(){
|
||||
|
||||
$users = User::with('account')->select('users.*')
|
||||
->where('users.deleted_at', '=', null)
|
||||
->where('users.id', '!=', 1)
|
||||
->where('users.admin', "<", 4)
|
||||
->where('users.m_level', "!=", null)
|
||||
->where('users.m_sponsor', "=", $this->b_user->user_id) //<- need the id for parents / sponsors
|
||||
->where('users.payment_account', "!=", null)
|
||||
->where('users.active_date', "<=", $this->date->end_date)
|
||||
->get();
|
||||
|
||||
if($users){
|
||||
foreach($users as $user){
|
||||
$BusinessUserItem = new BusinessUserItem($this->date);
|
||||
$BusinessUserItem->makeUser($user->id);
|
||||
$BusinessUserItem->addUserID();
|
||||
$this->businessUserItems[] = $BusinessUserItem;
|
||||
}
|
||||
}
|
||||
foreach($this->businessUserItems as $businessUserItem){
|
||||
$businessUserItem->readParentsBusinessUsers();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function readStoredParentsBusinessUsers($structure){
|
||||
|
||||
$parents = $this->findParentsBusinessOnStored($this->b_user->user_id, $structure);
|
||||
if($parents){
|
||||
foreach($parents as $obj){
|
||||
$BusinessUserItem = new BusinessUserItem($this->date);
|
||||
$BusinessUserItem->makeUser($obj->user_id);
|
||||
$BusinessUserItem->addUserID();
|
||||
$this->businessUserItems[] = $BusinessUserItem;
|
||||
}
|
||||
foreach($this->businessUserItems as $businessUserItem){
|
||||
$businessUserItem->readStoredParentsBusinessUsers($parents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function findParentsBusinessOnStored($user_id, $structures){
|
||||
if($structures){
|
||||
foreach($structures as $obj){
|
||||
if($user_id === $obj->user_id){
|
||||
return $obj->parents;
|
||||
}
|
||||
if($obj->parents){
|
||||
if($ret = $this->findParentsBusinessOnStored($user_id, $obj->parents)){
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function checkSponsor($user){
|
||||
|
||||
//check is store? has ID
|
||||
if($this->b_user->isSave()){
|
||||
return;
|
||||
}
|
||||
$sponsor = new stdClass();
|
||||
|
||||
$sponsor->is_sponsor = false;
|
||||
$sponsor->user_id = false;
|
||||
$sponsor->first_name = '';
|
||||
$sponsor->last_name = '';
|
||||
$sponsor->email = '';
|
||||
$sponsor->m_account = '';
|
||||
$sponsor->full_name = 'Keinen Sponsor zugewiesen';
|
||||
|
||||
if($user->m_sponsor){
|
||||
|
||||
if($user->user_sponsor){
|
||||
$sponsor->is_sponsor = true;
|
||||
$sponsor->user_id = $user->user_sponsor->id;
|
||||
if($user->user_sponsor->account){
|
||||
$sponsor->full_name = substr('Sponsor: '.$user->user_sponsor->account->first_name.' '.$user->user_sponsor->account->last_name.' | '.$user->user_sponsor->email.' | '.$user->user_sponsor->account->m_account, 0, 250);
|
||||
$sponsor->first_name = $user->user_sponsor->account->last_name;
|
||||
$sponsor->last_name = $user->user_sponsor->account->first_name;
|
||||
$sponsor->m_account = $user->user_sponsor->account->m_account;
|
||||
}else{
|
||||
$sponsor->full_name = 'Sponsor: '.$user->user_sponsor->email;
|
||||
}
|
||||
$sponsor->email = $user->user_sponsor->email;
|
||||
}else{
|
||||
$sponsor->full_name = 'Sponsor wurde gelöscht.';
|
||||
}
|
||||
}
|
||||
$this->b_user->sponsor = $sponsor;
|
||||
return;
|
||||
}
|
||||
|
||||
public function isSave(){
|
||||
return $this->b_user->isSave();
|
||||
}
|
||||
|
||||
public function __get($property) {
|
||||
if (property_exists($this->b_user, $property)) {
|
||||
return $this->b_user->$property;
|
||||
}
|
||||
if (isset($this->b_user->{$property})) {
|
||||
return $this->b_user->{$property};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,27 +1,20 @@
|
|||
<?php
|
||||
namespace App\Services\BusinessPlan;
|
||||
|
||||
use App\Models\UserLevel;
|
||||
use App\Models\UserBusinessStructure;
|
||||
use App\User;
|
||||
use stdClass;
|
||||
|
||||
class TreeCalcBot
|
||||
{
|
||||
private $items = [];
|
||||
private $parentless = [];
|
||||
public $date;
|
||||
public $business_user;
|
||||
|
||||
public $business_users = [];
|
||||
public $parentless = [];
|
||||
|
||||
private $sponsor;
|
||||
private $date;
|
||||
public $user;
|
||||
public $lines = [];
|
||||
public $total_tp = 0;
|
||||
public $total_qual_tp = 0;
|
||||
public $commission_total = 0;
|
||||
public $qual_user_level = null;
|
||||
private $init_from;
|
||||
|
||||
|
||||
|
||||
|
||||
private static $userIDs = [];
|
||||
|
||||
public static function addUserID($id){
|
||||
|
|
@ -39,82 +32,121 @@ class TreeCalcBot
|
|||
$this->init_from = $init_from;
|
||||
}
|
||||
|
||||
public function initMain()
|
||||
public function initStructureAdmin($check = true)
|
||||
{
|
||||
$this->readMain();
|
||||
$this->readParentsUser();
|
||||
$this->readParentlessUser();
|
||||
}
|
||||
|
||||
public function initUser($user_id)
|
||||
{
|
||||
$user = User::find($user_id);
|
||||
$TreeUserItem = new TreeUserItem($this->date);
|
||||
$TreeUserItem->makeUser($user);
|
||||
$TreeUserItem->addUserID();
|
||||
$this->items[] = $TreeUserItem;
|
||||
|
||||
$this->readParentsUser();
|
||||
$this->readSponsorUser($user->m_sponsor);
|
||||
}
|
||||
|
||||
|
||||
public function initDetailUser($user)
|
||||
{
|
||||
$this->user = new TreeUserItem($this->date);
|
||||
$this->user->makeUser($user);
|
||||
$this->user->readParentsUser();
|
||||
|
||||
|
||||
//calculate Lines
|
||||
if(count($this->user->items) > 0){
|
||||
$this->calcUserTP($this->user->items, 1);
|
||||
//check is month is saved.
|
||||
if($check && $UserBusinessStructure = self::isFromStored($this->date->month, $this->date->year)){
|
||||
$this->readStoredRootUsers($UserBusinessStructure);
|
||||
$this->readStoredParentsUsers($UserBusinessStructure);
|
||||
$this->readStoredParentlessUser($UserBusinessStructure);
|
||||
}else{
|
||||
$this->readRootUsers();
|
||||
$this->readParentsUsers();
|
||||
$this->readParentlessUser();
|
||||
}
|
||||
$this->calcQualTP();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function calcUserTP($items, $line){
|
||||
if(!isset($this->lines[$line])){
|
||||
$this->lines[$line] = new stdClass();
|
||||
$this->lines[$line]->points = 0;
|
||||
}
|
||||
foreach($items as $item){
|
||||
if(count($item->items) > 0){
|
||||
$this->calcUserTP($item->items, $line+1);
|
||||
public function initStructureUser($user_id)
|
||||
{
|
||||
|
||||
$BusinessUserItem = new BusinessUserItem($this->date);
|
||||
$BusinessUserItem->makeUser($user_id);
|
||||
$BusinessUserItem->addUserID();
|
||||
$this->business_users[] = $BusinessUserItem;
|
||||
|
||||
//check is month is saved.
|
||||
if($UserBusinessStructure = self::isFromStored($this->date->month, $this->date->year)){
|
||||
$this->readStoredParentsUsers($UserBusinessStructure);
|
||||
|
||||
if(isset($this->business_users[0]) && $this->business_users[0]->sponsor){
|
||||
$this->readStoredSponsorUser($this->business_users[0]->sponsor->user_id);
|
||||
}
|
||||
$this->lines[$line]->points += $item->sales_volume_points_sum;
|
||||
$this->total_tp += $item->sales_volume_points_sum;
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
$this->readParentsUsers();
|
||||
$this->readSponsorUser($user_id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function initBusinesslUserDetail($user)
|
||||
{
|
||||
$this->business_user = new BusinessUserItem($this->date);
|
||||
$this->business_user->makeUser($user->id);
|
||||
$this->business_user->checkSponsor($user);
|
||||
if(!$this->business_user->isSave()){
|
||||
$this->business_user->readParentsBusinessUsers();
|
||||
//calculate Lines
|
||||
if(count($this->business_user->businessUserItems) > 0){
|
||||
$this->calcUserTP($this->business_user->businessUserItems, 1);
|
||||
}
|
||||
$this->business_user->calcQualTP();
|
||||
}
|
||||
}
|
||||
|
||||
/*public function storeBusinesslUser()
|
||||
{
|
||||
$this->business_user->storeUser();
|
||||
}*/
|
||||
|
||||
public static function isFromStored($month, $year){
|
||||
//when is stored an completed
|
||||
$UserBusinessStructure = UserBusinessStructure::where('year', $year)->where('month', $month)->first();
|
||||
if($UserBusinessStructure && $UserBusinessStructure->completed){
|
||||
return $UserBusinessStructure;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function calcUserTP($businessUserItems, $line){
|
||||
if(!isset($this->business_user->business_lines[$line])){
|
||||
$obj = new stdClass();
|
||||
$obj->points = 0;
|
||||
$this->business_user->addBusinessLineToUser($line, $obj);
|
||||
}
|
||||
foreach($businessUserItems as $business_user_item){
|
||||
if(count($business_user_item->businessUserItems) > 0){
|
||||
$this->calcUserTP($business_user_item->businessUserItems, $line+1);
|
||||
}
|
||||
$this->business_user->addBusinessLinePoints($line, $business_user_item->sales_volume_points_sum);
|
||||
$this->business_user->addTotalTP($business_user_item->sales_volume_points_sum);
|
||||
}
|
||||
}
|
||||
|
||||
public function getGrowthBonus(){
|
||||
if(count($this->business_user->business_lines) > 6){
|
||||
$b_lines = $this->business_user->business_lines->toArray();
|
||||
return array_slice($b_lines, 6);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
public function getKeybyLine($line, $key){
|
||||
if(!isset($this->lines[$line])){
|
||||
return 0;
|
||||
}
|
||||
return isset($this->lines[$line]->{$key}) ? $this->lines[$line]->{$key} : 0;
|
||||
|
||||
}
|
||||
|
||||
public function calcQualTP(){
|
||||
if($this->user->isQualKP()){
|
||||
$this->total_qual_tp = $this->total_tp + $this->user->getRestQualKP();
|
||||
$this->qual_user_level = UserLevel::where('qual_tp', '<=', $this->total_qual_tp)->orderBy('qual_tp', 'desc')->first();
|
||||
$this->commission_total = 0;
|
||||
if($this->qual_user_level){
|
||||
foreach($this->lines as $line => $values){
|
||||
$values->margin = $this->qual_user_level->{'pr_line_'.$line};
|
||||
$values->commission = round($values->points / 100 * $values->margin, 2);
|
||||
$this->commission_total += $values->commission;
|
||||
$this->lines[$line] = $values;
|
||||
if($this->business_user->business_lines){
|
||||
$b_lines = $this->business_user->business_lines;
|
||||
if(isset($b_lines[$line])){
|
||||
if($b_lines[$line] instanceof stdClass){
|
||||
if(isset($b_lines[$line]->{$key})){
|
||||
return $b_lines[$line]->{$key};
|
||||
}
|
||||
}else{
|
||||
if(isset($b_lines[$line][$key])){
|
||||
return $b_lines[$line][$key];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function readMain(){
|
||||
|
||||
//* reading from current*//
|
||||
private function readRootUsers(){
|
||||
$users = User::with('account')->select('users.*')
|
||||
->where('users.deleted_at', '=', null)
|
||||
->where('users.id', '!=', 1)
|
||||
|
|
@ -126,18 +158,17 @@ class TreeCalcBot
|
|||
->get();
|
||||
if($users){
|
||||
foreach($users as $user){
|
||||
$TreeUserItem = new TreeUserItem($this->date);
|
||||
$TreeUserItem->makeUser($user);
|
||||
$TreeUserItem->addUserID();
|
||||
$this->items[] = $TreeUserItem;
|
||||
$BusinessUserItem = new BusinessUserItem($this->date);
|
||||
$BusinessUserItem->makeUser($user->id);
|
||||
$BusinessUserItem->addUserID();
|
||||
$this->business_users[] = $BusinessUserItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function readParentsUser(){
|
||||
foreach($this->items as $item){
|
||||
$item->readParentsUser();
|
||||
private function readParentsUsers(){
|
||||
foreach($this->business_users as $business_user){
|
||||
$business_user->readParentsBusinessUsers();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -149,34 +180,77 @@ class TreeCalcBot
|
|||
->where('users.payment_account', "!=", null)
|
||||
->where('users.active_date', "<=", $this->date->end_date)
|
||||
->get();
|
||||
|
||||
foreach($users as $user){
|
||||
if(!isset(self::$userIDs[$user->id])){
|
||||
$TreeUserItem = new TreeUserItem($this->date);
|
||||
$TreeUserItem->makeUser($user);
|
||||
$TreeUserItem->checkSponsor();
|
||||
|
||||
$this->parentless[] = $TreeUserItem;
|
||||
$BusinessUserItem = new BusinessUserItem($this->date);
|
||||
$BusinessUserItem->makeUser($user->id);
|
||||
$this->parentless[] = $BusinessUserItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function readSponsorUser($m_sponsor_id){
|
||||
$sponsor = User::find($m_sponsor_id);
|
||||
if($sponsor){
|
||||
$this->sponsor = new TreeUserItem($this->date);
|
||||
$this->sponsor->makeUser($sponsor);
|
||||
|
||||
//* reading from stored*//
|
||||
private function readStoredRootUsers(UserBusinessStructure $userBusinessStructure){
|
||||
//first level is root
|
||||
if($userBusinessStructure->structure){
|
||||
foreach($userBusinessStructure->structure as $obj){
|
||||
$BusinessUserItem = new BusinessUserItem($this->date);
|
||||
$BusinessUserItem->makeUser($obj->user_id);
|
||||
$BusinessUserItem->addUserID();
|
||||
$this->business_users[] = $BusinessUserItem;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function readStoredParentsUsers(UserBusinessStructure $userBusinessStructure){
|
||||
foreach($this->business_users as $business_user){
|
||||
$business_user->readStoredParentsBusinessUsers($userBusinessStructure->structure);
|
||||
}
|
||||
}
|
||||
|
||||
private function readStoredParentlessUser(UserBusinessStructure $userBusinessStructure){
|
||||
if($userBusinessStructure->parentless){
|
||||
foreach($userBusinessStructure->parentless as $obj){
|
||||
if(!isset(self::$userIDs[$obj->user_id])){
|
||||
$BusinessUserItem = new BusinessUserItem($this->date);
|
||||
$BusinessUserItem->makeUser($obj->user_id);
|
||||
$this->parentless[] = $BusinessUserItem;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function readSponsorUser($user_id){
|
||||
$user = User::find($user_id);
|
||||
$userSponsor = User::find($user->m_sponsor);
|
||||
if($userSponsor){
|
||||
$this->sponsor = new BusinessUserItem($this->date);
|
||||
$this->sponsor->makeUser($userSponsor->id);
|
||||
}
|
||||
}
|
||||
|
||||
public function readStoredSponsorUser($user_id){
|
||||
|
||||
$this->sponsor = new BusinessUserItem($this->date);
|
||||
$this->sponsor->makeUser($user_id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getItems(){
|
||||
return $this->items;
|
||||
return $this->business_users;
|
||||
}
|
||||
|
||||
public function makeHtmlTree(){
|
||||
$deep = 0;
|
||||
$ret = '<ol class="dd-list">';
|
||||
foreach($this->items as $item){
|
||||
$ret .= $this->addItem($item, $deep);
|
||||
foreach($this->business_users as $business_user){
|
||||
$ret .= $this->addItem($business_user, $deep);
|
||||
}
|
||||
$ret .= '</ol>';
|
||||
return $ret;
|
||||
|
|
@ -185,16 +259,16 @@ class TreeCalcBot
|
|||
private function addItem($item, $deep){
|
||||
|
||||
$button = '';
|
||||
if(($this->init_from === 'admin' && \Auth::user()->isAdmin()) || ($this->init_from === 'member' && \Auth::user()->id === $item->id)){
|
||||
if(($this->init_from === 'admin' && \Auth::user()->isAdmin()) || ($this->init_from === 'member' && \Auth::user()->id === $item->user_id)){
|
||||
$button = ' | <button type="button" class="btn icon-btn btn-xs btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="'.$item->id.'"
|
||||
data-id="'.$item->user_id.'"
|
||||
data-action="business-user-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="'.$this->init_from .'"
|
||||
data-route="'.route('modal_load').'"><span class="far fa-calculator"></span></button>';
|
||||
}
|
||||
return '<li class="dd-item dd-nodrag" data-id="'.$item->id.'">'.
|
||||
return '<li class="dd-item dd-nodrag" data-id="'.$item->user_id.'">'.
|
||||
'<div class="dd-handle">
|
||||
<div class="media align-items-center">
|
||||
<div class="d-flex flex-column justify-content-center align-items-center">
|
||||
|
|
@ -203,10 +277,11 @@ class TreeCalcBot
|
|||
<div class="media-body ml-2">
|
||||
<span class="'.($item->active_account ? '' : 'text-muted').'">
|
||||
<span class="mr-1 ion ion-ios-contact '.($item->active_account ? 'text-primary' : 'text-danger').'"></span>
|
||||
<strong>'.$item->first_name.' '.$item->last_name.'</strong> <a href="mailto: '.$item->email.'">'.$item->email.'</a> <span class="badge badge-outline-default '.($item->active_account ? '' : 'text-muted').'">'.$item->user_level.' | '.$item->m_account.'</span>
|
||||
<strong>'.$item->first_name.' '.$item->last_name.'</strong> <a href="mailto: '.$item->email.'">'.$item->email.'</a> <span class="badge badge-outline-default '.($item->active_account ? '' : 'text-muted').'">'.$item->user_level_name.' | '.$item->m_account.'</span>
|
||||
<br><span class="small">'.
|
||||
($item->active_account ?
|
||||
'<strong>Points: '.$item->sales_volume_points_sum.'</strong> | B: '.$item->sales_volume_points.' | S: '.$item->sales_volume_points_shop.' <strong> | Umsatz: '.$item->sales_volume_total_sum.' €</strong> | B: '.$item->sales_volume_total.' € | S: '.$item->sales_volume_total_shop.' €'.
|
||||
'<strong>Gesamte Points: '.$item->sales_volume_points_sum.'</strong> | B: '.$item->sales_volume_points.' | S: '.$item->sales_volume_points_shop.' <strong>
|
||||
| Umsatz netto: '.formatNumber($item->sales_volume_total_sum).' €</strong> | B: '.formatNumber($item->sales_volume_total).' € | S: '.formatNumber($item->sales_volume_total_shop).' €'.
|
||||
$button
|
||||
:
|
||||
'Account bis: '.$item->payment_account_date).
|
||||
|
|
@ -223,9 +298,9 @@ class TreeCalcBot
|
|||
}
|
||||
|
||||
private function addParentItem($item, $deep){
|
||||
if($item->items){
|
||||
if($item->businessUserItems){
|
||||
$ret = '<ol class="dd-list dd-nodrag">';
|
||||
foreach($item->items as $parent){
|
||||
foreach($item->businessUserItems as $parent){
|
||||
$ret .= $this->addItem($parent, $deep+1);
|
||||
}
|
||||
$ret .='</ol>';
|
||||
|
|
@ -242,16 +317,17 @@ class TreeCalcBot
|
|||
public function makeParentlessHtml(){
|
||||
$ret = "";
|
||||
foreach($this->parentless as $item){
|
||||
$ret .= '<li class="dd-item dd-nodrag" data-id="'.$item->id.'">'.
|
||||
$ret .= '<li class="dd-item dd-nodrag" data-id="'.$item->user_id.'">'.
|
||||
'<div class="dd-handle">
|
||||
<span class="'.($item->active_account ? '' : 'text-muted').'">
|
||||
<span class="mr-1 ion ion-ios-contact '.($item->active_account ? 'text-primary' : 'text-danger').'"></span>
|
||||
<strong>'.$item->first_name.' '.$item->last_name.'</strong> <a href="mailto: '.$item->email.'">'.$item->email.'</a> <span class="badge badge-outline-default '.($item->active_account ? '' : 'text-muted').'">'.$item->user_level.' | '.$item->m_account.'</span>
|
||||
<strong>'.$item->first_name.' '.$item->last_name.'</strong> <a href="mailto: '.$item->email.'">'.$item->email.'</a> <span class="badge badge-outline-default '.($item->active_account ? '' : 'text-muted').'">'.$item->user_level_name.' | '.$item->m_account.'</span>
|
||||
<br><span class="small">'.
|
||||
($item->active_account ?
|
||||
'<strong>Points: '.$item->sales_volume_points_sum.'</strong> | B: '.$item->sales_volume_points.' | S: '.$item->sales_volume_points_shop.' <strong> | Umsatz: '.$item->sales_volume_total_sum.' €</strong> | B: '.$item->sales_volume_total.' € | S: '.$item->sales_volume_total_shop.' €'.
|
||||
'<strong>Gesamte Points: '.$item->sales_volume_points_sum.'</strong> | B: '.$item->sales_volume_points.' | S: '.$item->sales_volume_points_shop.' <strong>
|
||||
| Umsatz netto: '.formatNumber($item->sales_volume_total_sum).' €</strong> | B: '.formatNumber($item->sales_volume_total).' € | S: '.formatNumber($item->sales_volume_total_shop).' €'.
|
||||
' | <button type="button" class="btn icon-btn btn-xs btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="'.$item->id.'"
|
||||
data-id="'.$item->user_id.'"
|
||||
data-action="business-user-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
|
|
@ -275,12 +351,13 @@ class TreeCalcBot
|
|||
'<div class="dd-handle">
|
||||
<span class="'.($this->sponsor->active_account ? '' : 'text-muted').'">
|
||||
<span class="mr-1 ion ion-ios-contact '.($this->sponsor->active_account ? 'text-primary' : 'text-danger').'"></span>
|
||||
<strong>'.$this->sponsor->first_name.' '.$this->sponsor->last_name.'</strong> <a href="mailto: '.$this->sponsor->email.'">'.$this->sponsor->email.'</a> <span class="badge badge-outline-default '.($this->sponsor->active_account ? '' : 'text-muted').'">'.$this->sponsor->user_level.' | '.$this->sponsor->m_account.'</span>';
|
||||
<strong>'.$this->sponsor->first_name.' '.$this->sponsor->last_name.'</strong> <a href="mailto: '.$this->sponsor->email.'">'.$this->sponsor->email.'</a> <span class="badge badge-outline-default '.($this->sponsor->active_account ? '' : 'text-muted').'">'.$this->sponsor->user_level_name.' | '.$this->sponsor->m_account.'</span>';
|
||||
|
||||
if($this->init_from === 'admin'){
|
||||
$ret .= '<br><span class="small">'.
|
||||
($this->sponsor->active_account ?
|
||||
'<strong>Points: '.$this->sponsor->sales_volume_points_sum.'</strong> | B: '.$this->sponsor->sales_volume_points.' | S: '.$this->sponsor->sales_volume_points_shop.' <strong> | Umsatz: '.$this->sponsor->sales_volume_total_sum.' €</strong> | B: '.$this->sponsor->sales_volume_total.' € | S: '.$this->sponsor->sales_volume_total_shop.' €'
|
||||
'<strong>Gesamte Points: '.$this->sponsor->sales_volume_points_sum.'</strong> | B: '.$this->sponsor->sales_volume_points.' | S: '.$this->sponsor->sales_volume_points_shop.' <strong>
|
||||
| Umsatz netto: '.formatNumber($this->sponsor->sales_volume_total_sum).' €</strong> | B: '.formatNumber($this->sponsor->sales_volume_total).' € | S: '.formatNumber($this->sponsor->sales_volume_total_shop).' €'
|
||||
:
|
||||
'Account bis: '.$this->sponsor->payment_account_date).
|
||||
'</span>';
|
||||
|
|
|
|||
|
|
@ -2,17 +2,22 @@
|
|||
namespace App\Services\BusinessPlan;
|
||||
|
||||
use App\User;
|
||||
use stdClass;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\UserLevel;
|
||||
use App\Models\UserBusiness;
|
||||
|
||||
|
||||
class TreeUserItem
|
||||
{
|
||||
public $items = [];
|
||||
private $date;
|
||||
public $lines = [];
|
||||
|
||||
public $user_level_active;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function __construct($date)
|
||||
{
|
||||
$this->date = $date;
|
||||
|
|
@ -21,41 +26,38 @@ class TreeUserItem
|
|||
|
||||
public function makeUser(User $user){
|
||||
|
||||
$this->id = $user->id;
|
||||
$this->m_level = $user->m_level;
|
||||
$this->m_sponsor = $user->m_sponsor;
|
||||
|
||||
$this->user_level = $user->user_level ? $user->user_level->name : '';
|
||||
$this->active_account = $user->payment_account ? Carbon::parse($user->payment_account)->gt(Carbon::parse($this->date->start_date)) : false;
|
||||
$this->payment_account_date = $user->payment_account ? $user->getPaymentAccountDateFormat(false) : "-";
|
||||
$this->active_date = $user->active_date ? $user->getActiveDateFormat() : "-";
|
||||
|
||||
$this->m_account = $user->account->m_account;
|
||||
$this->email = $user->email;
|
||||
$this->first_name = $user->account->first_name;
|
||||
$this->last_name = $user->account->last_name;
|
||||
$this->sales_volume_points = $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_points');
|
||||
$this->sales_volume_points_shop = $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_points_shop');
|
||||
$this->sales_volume_points_sum = $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_points_sum');
|
||||
$this->sales_volume_total = $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_total');
|
||||
$this->sales_volume_total_shop = $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_total_shop');
|
||||
$this->sales_volume_total_sum = $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_total_sum');
|
||||
|
||||
if($user->user_level){
|
||||
$this->margin = $user->user_level->margin;
|
||||
$this->margin_shop = $user->user_level->margin_shop;
|
||||
$this->qual_kp = $user->user_level->qual_kp;
|
||||
$this->qual_tp = $user->user_level->qual_tp;
|
||||
}else{
|
||||
$this->margin = 0;
|
||||
$this->margin_shop = 0;
|
||||
$this->qual_kp = 0;
|
||||
$this->qual_tp = 0;
|
||||
}
|
||||
$this->user_level_active = $user->user_level ? $user->user_level : null;
|
||||
$this->b_user = new UserBusiness();
|
||||
$fill = [
|
||||
'user_id' => $user->id,
|
||||
'month' => $this->date->month,
|
||||
'year' => $this->date->year,
|
||||
'm_level' => $user->m_level,
|
||||
'm_sponsor' => $user->m_sponsor,
|
||||
'user_level_name' => $user->user_level ? $user->user_level->name : '',
|
||||
'active_account' => $user->payment_account ? Carbon::parse($user->payment_account)->gt(Carbon::parse($this->date->start_date)) : false,
|
||||
'payment_account_date' => $user->payment_account ? $user->getPaymentAccountDateFormat(false) : NULL,
|
||||
'active_date' => $user->active_date ? $user->active_date : NULL,
|
||||
'm_account' => $user->account->m_account,
|
||||
'email' => $user->email,
|
||||
'first_name' => $user->account->first_name,
|
||||
'last_name' => $user->account->last_name,
|
||||
'sales_volume_points' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_points'),
|
||||
'sales_volume_points_shop' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_points_shop'),
|
||||
'sales_volume_points_sum' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_points_sum'),
|
||||
'sales_volume_total' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_total'),
|
||||
'sales_volume_total_shop' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_total_shop'),
|
||||
'sales_volume_total_sum' => $user->getUserSalesVolumeBy($this->date->month, $this->date->year, 'sales_volume_total_sum'),
|
||||
'margin' => $user->user_level_active ? $user->user_level_active->margin : 0,
|
||||
'margin_shop' => $user->user_level_active ? $user->user_level_active->margin_shop : 0,
|
||||
'qual_kp' => $user->user_level_active ? $user->user_level_active->qual_kp : 0,
|
||||
'qual_tp' => $user->user_level_active ? $user->user_level_active->qual_tp : 0,
|
||||
];
|
||||
$this->b_user->fill($fill);
|
||||
}
|
||||
|
||||
public function addUserID(){
|
||||
TreeCalcBot::addUserID($this->id);
|
||||
TreeCalcBot::addUserID($this->user_id);
|
||||
}
|
||||
|
||||
public function isQualKP(){
|
||||
|
|
@ -74,7 +76,7 @@ class TreeUserItem
|
|||
$user = User::find($this->m_sponsor);
|
||||
if($user){
|
||||
if($user->account){
|
||||
$this->m_sponsor_name = 'Sponsor: '.$user->account->first_name.' '.$user->account->last_name.' | '.$user->email.' | '.$user->account->m_account;
|
||||
$this->m_sponsor_name = substr('Sponsor: '.$user->account->first_name.' '.$user->account->last_name.' | '.$user->email.' | '.$user->account->m_account, 0, 190);
|
||||
}else{
|
||||
$this->m_sponsor_name = 'Sponsor: '.$user->email;
|
||||
}
|
||||
|
|
@ -83,7 +85,15 @@ class TreeUserItem
|
|||
$this->m_sponsor_name = 'Sponsor wurde gelöscht.';
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
'total_tp' => ,
|
||||
'total_qual_tp' => ,
|
||||
'commission_total' => ,
|
||||
'lines',
|
||||
'items',
|
||||
'qual_user_level_id'
|
||||
*/
|
||||
public function readParentsUser(){
|
||||
|
||||
$users = User::with('account')->select('users.*')
|
||||
|
|
@ -91,17 +101,18 @@ class TreeUserItem
|
|||
->where('users.id', '!=', 1)
|
||||
->where('users.admin', "<", 4)
|
||||
->where('users.m_level', "!=", null)
|
||||
->where('users.m_sponsor', "=", $this->id) //<- need the id for parents / sponsors
|
||||
->where('users.m_sponsor', "=", $this->user_id) //<- need the id for parents / sponsors
|
||||
->where('users.payment_account', "!=", null)
|
||||
->where('users.active_date', "<=", $this->date->end_date)
|
||||
->get();
|
||||
|
||||
dd($users);
|
||||
if($users){
|
||||
foreach($users as $user){
|
||||
$TreeUserItem = new TreeUserItem($this->date);
|
||||
$TreeUserItem->makeUser($user);
|
||||
$TreeUserItem->addUserID();
|
||||
$this->items[] = $TreeUserItem; }
|
||||
$this->items[] = $TreeUserItem;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->items as $item){
|
||||
|
|
@ -110,5 +121,52 @@ class TreeUserItem
|
|||
|
||||
}
|
||||
|
||||
|
||||
public function calcUserTP($line){
|
||||
if(!isset($this->lines[$line])){
|
||||
$this->lines[$line] = new stdClass();
|
||||
$this->lines[$line]->points = 0;
|
||||
}
|
||||
foreach($this->items as $item){
|
||||
if(count($item->items) > 0){
|
||||
$this->calcUserTP($line+1);
|
||||
}
|
||||
$this->lines[$line]->points += $item->sales_volume_points_sum;
|
||||
$this->total_tp += $item->sales_volume_points_sum;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function calcQualTP(){
|
||||
if($this->isQualKP()){
|
||||
$this->total_qual_tp = $this->total_tp + $this->getRestQualKP();
|
||||
$this->qual_user_level = UserLevel::where('qual_tp', '<=', $this->total_qual_tp)->where('pos', '<=', $this->user->user_level->pos)->orderBy('qual_tp', 'desc')->first();
|
||||
$this->commission_total = 0;
|
||||
if($this->qual_user_level){
|
||||
foreach($this->lines as $line => $values){
|
||||
$values->margin = $this->qual_user_level->{'pr_line_'.$line};
|
||||
if($line > 6){
|
||||
//wachstumsbonus
|
||||
$values->margin = $this->qual_user_level->growth_bonus;
|
||||
}
|
||||
$values->commission = round($values->points / 100 * $values->margin, 2);
|
||||
|
||||
$this->commission_total += $values->commission;
|
||||
$this->lines[$line] = $values;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function __get($property) {
|
||||
if (property_exists($this->b_user, $property)) {
|
||||
return $this->b_user->$property;
|
||||
}
|
||||
if (isset($this->b_user->{$property})) {
|
||||
return $this->b_user->{$property};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
82
app/Services/Credit.php
Normal file
82
app/Services/Credit.php
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
use App\Services\Util;
|
||||
use App\Models\Setting;
|
||||
use App\Mail\MailCredit;
|
||||
use App\Models\UserCredit;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class Credit
|
||||
{
|
||||
|
||||
public static function getCreditNumber(){
|
||||
return (int) Setting::getContentBySlug('credit-number');
|
||||
}
|
||||
|
||||
|
||||
public static function makeNextCreditNumber(){
|
||||
$credit_number = self::getCreditNumber();
|
||||
$credit_number = $credit_number+1;
|
||||
Setting::setContentBySlug('credit-number', $credit_number, 'int');
|
||||
return $credit_number;
|
||||
}
|
||||
|
||||
public static function createCreditNumber($credit_number, $credit_date){
|
||||
|
||||
$prefix = "GS".\Carbon::parse($credit_date)->format('Y');
|
||||
$credit_number = str_pad($credit_number, 5, '0', STR_PAD_LEFT);
|
||||
return $prefix.$credit_number;
|
||||
}
|
||||
|
||||
public static function getCreditStorageDir($credit_date){
|
||||
return "/credit/".\Carbon::parse($credit_date)->format('Y/m/');
|
||||
}
|
||||
|
||||
public static function makeCreditFilename($credit_number){
|
||||
return $credit_number."-MIVITA-Gutschrift.pdf";
|
||||
}
|
||||
|
||||
public static function isCredit(UserCredit $user_credit){
|
||||
return $user_credit->isCredit();
|
||||
}
|
||||
|
||||
/*public static function getFilename(UserCredit $user_credit){
|
||||
return $user_credit->filename;
|
||||
}
|
||||
|
||||
|
||||
public static function getDir(UserCredit $user_credit){
|
||||
return $user_credit->dir;
|
||||
}
|
||||
|
||||
public static function getDownloadURL(UserCredit $user_credit, $do = false){
|
||||
return route('storage_file', [$user_credit->id, 'cms_download_file', $do]);
|
||||
}
|
||||
|
||||
public static function getDownloadPath(UserCredit $user_credit, $full = false){
|
||||
$dir = self::getDir($user_credit);
|
||||
$filename = self::getFilename($user_credit);
|
||||
if(!$full){
|
||||
return $dir.$filename;
|
||||
}
|
||||
return \Storage::disk('public')->path($dir.$filename);
|
||||
}*/
|
||||
|
||||
public static function sendCreditMail(UserCredit $user_credit){
|
||||
$bcc = [];
|
||||
$email = $user_credit->user->email;
|
||||
if(!$email){
|
||||
if($user_credit->user->mode === 'test'){
|
||||
}else{
|
||||
$email = config('app.checkout_mail');
|
||||
}
|
||||
}
|
||||
if($user_credit->user->mode === 'test'){
|
||||
$bcc[] = config('app.checkout_test_mail');
|
||||
}else{
|
||||
$bcc[] = config('app.checkout_mail');
|
||||
}
|
||||
Mail::to($email)->bcc($bcc)->send(new MailCredit($user_credit));
|
||||
}
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ class HomepartyCart
|
|||
private static $voucher_price = 0;
|
||||
public static $voucher_name = "";
|
||||
|
||||
|
||||
|
||||
private static $bonus_diff = 0;
|
||||
private static $bonus_points_diff = 0;
|
||||
private static $bonus_coupon_fault = 0;
|
||||
|
|
@ -74,9 +74,12 @@ class HomepartyCart
|
|||
self::addCart(self::$userCarts[$homeparty_user->id]);
|
||||
|
||||
}
|
||||
self::caluclateShipping();
|
||||
self::caluclateBonus();
|
||||
self::calculateBonusHost();
|
||||
self::caluclateShipping();
|
||||
self::recalculate();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static function addCart(HomepartyUserCart $homepartyUserCart){
|
||||
|
|
@ -92,6 +95,22 @@ class HomepartyCart
|
|||
return isset(self::$userCarts[$id]) ? self::$userCarts[$id] : null;
|
||||
}
|
||||
|
||||
private static function recalculate(){
|
||||
self::$points =0;
|
||||
self::$price = 0;
|
||||
self::$price_net = 0;
|
||||
self::$ek_price = 0;
|
||||
self::$ek_price_net = 0;
|
||||
self::$income_price = 0;
|
||||
foreach(self::$userCarts as $user_cart){
|
||||
self::$points += $user_cart->points;
|
||||
self::$price += $user_cart->price;
|
||||
self::$price_net += $user_cart->price_net;
|
||||
self::$ek_price += $user_cart->ek_price;
|
||||
self::$ek_price_net += $user_cart->ek_price_net;
|
||||
self::$income_price += $user_cart->income_price;
|
||||
}
|
||||
}
|
||||
|
||||
private static function caluclateBonus(){
|
||||
|
||||
|
|
@ -138,28 +157,52 @@ class HomepartyCart
|
|||
$bonus_total = self::$bonus_value + self::$bonus_coupon;
|
||||
$user_cart = self::getUserCart(self::$user_host_id);
|
||||
//cart lower the bonus
|
||||
|
||||
if($user_cart->price <= $bonus_total){
|
||||
self::$bonus_points_diff = $user_cart->points;
|
||||
$user_cart->points = 0;
|
||||
$user_cart->price = 0;
|
||||
return;
|
||||
$user_cart->price_net = 0;
|
||||
|
||||
//$price_bonus_total = $bonus_total - ($bonus_total - $user_cart->price);
|
||||
/* self::$price -= $price_bonus_total;
|
||||
self::$price_net -= ($price_bonus_total / config('app.main_tax'));
|
||||
self::$ek_price -= $price_bonus_total;
|
||||
self::$ek_price_net -= ($price_bonus_total / config('app.main_tax'));
|
||||
self::$income_price -= $user_cart->income_price;*/
|
||||
$user_cart->income_price = 0;
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
$bonus_percent = (100/$user_cart->price*$bonus_total);
|
||||
self::$bonus_points_diff = round($user_cart->points/100*$bonus_percent);
|
||||
$user_cart->points -= self::$bonus_points_diff;
|
||||
//sub bonus on host
|
||||
$user_cart->price -= $bonus_total;
|
||||
$user_cart->price_net -= ($bonus_total / config('app.main_tax'));
|
||||
|
||||
|
||||
/*self::$price -= $bonus_total;
|
||||
self::$price_net -= ($bonus_total / config('app.main_tax'));
|
||||
self::$ek_price -= $bonus_total;
|
||||
self::$ek_price_net -= ($bonus_total / config('app.main_tax'));*/
|
||||
|
||||
}
|
||||
|
||||
$bonus_percent = (100/$user_cart->price*$bonus_total);
|
||||
self::$bonus_points_diff = round($user_cart->points/100*$bonus_percent);
|
||||
$user_cart->points -= self::$bonus_points_diff;
|
||||
if($user_cart->ek_price <= $bonus_total){
|
||||
$user_cart->ek_price = 0;
|
||||
$user_cart->ek_price_net = 0;
|
||||
$user_cart->income_price = $user_cart->price - $user_cart->ek_price;
|
||||
|
||||
//sub bonus on host
|
||||
$user_cart->price -= $bonus_total;
|
||||
$user_cart->price_net -= ($bonus_total / config('app.main_tax'));
|
||||
$user_cart->ek_price -= $bonus_total;
|
||||
$user_cart->ek_price_net -= ($bonus_total / config('app.main_tax'));
|
||||
|
||||
self::$price -= $bonus_total;
|
||||
self::$price_net -= ($bonus_total / config('app.main_tax'));
|
||||
self::$ek_price -= $bonus_total;
|
||||
self::$ek_price_net -= ($bonus_total / config('app.main_tax'));
|
||||
}else{
|
||||
$user_cart->ek_price -= $bonus_total;
|
||||
$user_cart->ek_price_net -= ($bonus_total / config('app.main_tax'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App\Services;
|
|||
use App\User;
|
||||
use App\Mail\MailCheckout;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\UserCreditItem;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\Services\ShopApiOrderCart;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
|
@ -86,6 +87,15 @@ class Payment
|
|||
return '<span class="badge badge-pill badge-'.self::getFormattedTxactionColor($shopping_payment->txaction).'">'.self::getFormattedTxaction($shopping_payment->txaction).'</span>';
|
||||
}
|
||||
|
||||
public static function addUserCreditMargin(User $user, $credit, $status, $message){
|
||||
UserCreditItem::create([
|
||||
'user_id' => $user->id,
|
||||
'credit' => $credit,
|
||||
'message' => $message,
|
||||
'status' => $status,
|
||||
]);
|
||||
}
|
||||
|
||||
/*
|
||||
Wir bei Zahlung aufgerufen.
|
||||
Betätigung durch Payone oder Zahlung auf MIVITA Rechnung
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class ShopApiOrderCart
|
|||
$this->shoppingCollectOrder->shipping_tax = round($this->shoppingCollectOrder->shipping - $this->shoppingCollectOrder->shipping_net, 2);
|
||||
$this->shoppingCollectOrder->tax_total += $this->shoppingCollectOrder->shipping_tax;
|
||||
//add shipping tax to split
|
||||
$this->shoppingCollectOrder->addTaxToSplit(config('app.shipping_tax'), $this->shoppingCollectOrder->shipping_tax);
|
||||
$this->shoppingCollectOrder->addTaxToSplit(config('app.main_tax_rate'), $this->shoppingCollectOrder->shipping_tax);
|
||||
|
||||
$this->shoppingCollectOrder->price_total_net += $this->shoppingCollectOrder->shipping_net;
|
||||
$this->shoppingCollectOrder->price_total = round($this->shoppingCollectOrder->tax_total + $this->shoppingCollectOrder->price_total_net, 2);
|
||||
|
|
|
|||
51
app/Services/SyS/BusinessStructur.php
Normal file
51
app/Services/SyS/BusinessStructur.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
namespace App\Services\SyS;
|
||||
|
||||
use App\Cron\BusinessUsersStore;
|
||||
use Carbon;
|
||||
use Request;
|
||||
use App\Models\SySetting;
|
||||
|
||||
class BusinessStructur
|
||||
{
|
||||
|
||||
public static function show()
|
||||
{
|
||||
$month = 2;
|
||||
$year = 2021;
|
||||
dd("function on: php artisan business:store month year");
|
||||
|
||||
/*$businessUsersStore = new BusinessUsersStore($month, $year);
|
||||
$businessUsersStore->storeUserBusinessStructure();
|
||||
$businessUsersStore->storeBusinessUsersDetail();
|
||||
$businessUsersStore->storeBusinessCompleted();*/
|
||||
|
||||
|
||||
$data = [
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
];
|
||||
|
||||
return view('sys.tools.business_structur', $data);
|
||||
}
|
||||
|
||||
|
||||
public static function store()
|
||||
{
|
||||
|
||||
$data = Request::all();
|
||||
|
||||
$data['active'] = isset($data['active']) ? true : false;
|
||||
if($data['id'] === "new"){
|
||||
$model = SySetting::create($data);
|
||||
}else{
|
||||
$model = SySetting::find($data['id']);
|
||||
$model->fill($data);
|
||||
$model->save();
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('sysadmin_tool', ['sales_members']));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -491,19 +491,19 @@ class User extends Authenticatable
|
|||
break;
|
||||
|
||||
case 'sales_volume_points_sum':
|
||||
return $this->userSalesVolume->month_points + $this->userSalesVolume->month_shop_points;
|
||||
return $this->userSalesVolume->getPointsSum();
|
||||
break;
|
||||
|
||||
case 'sales_volume_total':
|
||||
return formatNumber($this->userSalesVolume->month_total_net);
|
||||
return $this->userSalesVolume->month_total_net;
|
||||
break;
|
||||
|
||||
case 'sales_volume_total_shop':
|
||||
return formatNumber($this->userSalesVolume->month_shop_total_net);
|
||||
return $this->userSalesVolume->month_shop_total_net;
|
||||
break;
|
||||
|
||||
case 'sales_volume_total_sum':
|
||||
return formatNumber($this->userSalesVolume->month_total_net + $this->userSalesVolume->month_shop_total_net);
|
||||
return $this->userSalesVolume->getTotalNetSum();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ if (! function_exists('get_active_badge')) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (! function_exists('formatNumber')) {
|
||||
function formatNumber($number, $dec=2)
|
||||
{
|
||||
|
|
@ -75,5 +74,9 @@ if (! function_exists('cleanNumberFormat')) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (! function_exists('formatDate')) {
|
||||
function formatDate($date)
|
||||
{
|
||||
return Carbon::parse($date)->format(\Util::formatDateDB());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue