mivita/dev/app-bak/Services/BusinessPlan/SalesPointsVolumeHelper.php
2025-10-20 17:42:08 +02:00

178 lines
6.3 KiB
PHP
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Services\BusinessPlan;
use App\Models\UserSalesVolume;
class SalesPointsVolumeHelper
{
//protected static $business_users_table = [];
/*
$sort = 'structur' || 'line'
structur: nach baumstruktur sortiert, wird übergeben
line: nach reihenfolge sortiert,
*/
private static $business_users_line = [];
private static $totalcommission = [];
private static $totalpoints = [];
private static $cbot = null;
public static function getBusinessUsersTable($cbot, $sort = 'structur'){
self::$cbot = $cbot;
if($sort == 'structur'){
return self::getBusinessUsersTableStructur();
}
if($sort == 'line'){
return self::getBusinessUsersTableLine();
}
}
/* getBusinessUsersTableStructur */
private static function getBusinessUsersTableStructur(){
$deep = 0;
$ret = "";
foreach(self::$cbot->business_users as $business_user){
$ret .= self::addTableItemStructur($business_user, $deep);
}
return $ret;
}
private static function addTableItemStructur($item, $deep) {
$ret = self::setTableHTMLItemStructur($item, $deep);
if($item->businessUserItems){
foreach($item->businessUserItems as $parent){
$ret .= self::addTableItemStructur($parent, $deep+1);
}
}
return $ret;
}
private static function setTableHTMLItemStructur($item, $deep){
$pp = '';
$margin = 0;
$points = $item->sales_volume_points_KP_sum;
$commission = 0;
if($deep > 0){
$pp = str_repeat('&nbsp;&nbsp;&nbsp;', $deep-1).'<div class=" line-height-1 my-2 badge badge-outline-success text-dark font-weight-bolder">'.$deep.'. '.__('team.PP').'</div>';
$margin = self::$cbot->getKeybyLine($deep, 'margin');
$commission = $points / 100 * $margin;
}
$ret = '<tr>
<td><div class="no-line-break">'.$pp.'</div></td>
<td><span class="mr-1 ion ion-ios-contact '.($item->active_account ? 'text-primary' : 'text-danger').'"></span>'.$item->first_name.' '.$item->last_name.'
</td>
<td><div class="no-line-break">'.formatNumber($points, 0).'</span></td>
<td>'.formatNumber($margin, 1).' %</td>
<td><div class="no-line-break">'.formatNumber($commission, 2).' &euro;</span></td>
<td><span class="small">'.$item->user_level_name.'</span></td>
</tr>';
return $ret;
}
private static function getBusinessUsersTableLine(){
$deep = 0;
$ret = "";
foreach(self::$cbot->business_users as $business_user){
self::addTableItemLine($business_user, $deep);
}
foreach(self::$business_users_line as $deep => $items){
self::$totalcommission[$deep] = 0;
self::$totalpoints[$deep] = 0;
foreach($items as $item){
$ret .= self::setTableHTMLItemLine($item, $deep);
}
if($deep > 0){
$ret .= self::addTableHTMLTotalItemLine($deep, 'line');
}
}
$ret .= self::addTableHTMLTotalItemLine($deep, 'end');
return $ret;
}
private static function addTableItemLine($item, $deep) {
$item->deep = $deep;
self::$business_users_line[$deep][] = $item;
if($item->businessUserItems){
foreach($item->businessUserItems as $parent){
self::addTableItemLine($parent, $deep+1);
}
}
}
private static function addTableHTMLTotalItemLine($deep, $type){
$points = 0;
$commission = 0;
if($type == 'end'){
$pp = '<div class=" line-height-1 my-2 badge badge-outline-success text-dark font-weight-bolder">'.__('team.PP').'</div>';
$style = ' style="background-color:#d7d700;"';
$text = __('order.total');
foreach(self::$totalpoints as $key => $value){
$points += $value;
$commission += self::$totalcommission[$key];
}
}else{
$pp = '<div class=" line-height-1 my-2 badge badge-outline-success text-dark font-weight-bolder">'.$deep.'. '.__('team.PP').'</div>';
$style = 'style="background-color:#e5e4e4"';
$text = __('order.sum');
$points = self::$totalpoints[$deep];
$commission = self::$totalcommission[$deep];
}
$ret = '<tr '.$style.'>
<td><div class="no-line-break">'.$pp.'</div></td>
<td><b>'.$text.'</b></td>
<td><div class="no-line-break"><b>'.formatNumber($points, 0).'</b></span></td>
<td>&nbsp;</td>
<td><div class="no-line-break"><b>'.formatNumber($commission, 2).' &euro;</b></span></td>
<td>&nbsp;</td>
</tr>';
return $ret;
}
private static function setTableHTMLItemLine($item, $deep){
$pp = '';
$margin = 0;
$points = $item->sales_volume_points_KP_sum;
$commission = 0;
if($deep > 0){
$pp = '<div class=" line-height-1 my-2 badge badge-outline-success text-dark font-weight-bolder">'.$deep.'. '.__('team.PP').'</div>';
$margin = self::$cbot->getKeybyLine($deep, 'margin');
$commission = $points / 100 * $margin;
self::$totalcommission[$deep] += $commission;
self::$totalpoints[$deep] += $points;
}
//
/*
<th>{{__('tables.line')}}</th>
<th>{{ __('shop.name') }}</th>
<th>{{__('tables.points')}}</th>
<th>{{__('tables.commission')}} %</th>
<th>{{__('tables.commission')}} &euro;</th>
<th>{{ __('tables.level') }}</th>
*/
$ret = '<tr>
<td><div class="no-line-break">'.$pp.'</div></td>
<td><span class="mr-1 ion ion-ios-contact '.($item->active_account ? 'text-primary' : 'text-danger').'"></span>'.$item->first_name.' '.$item->last_name.'
</td>
<td><div class="no-line-break">'.formatNumber($points, 0).'</span></td>
<td>'.formatNumber($margin, 1).' %</td>
<td><div class="no-line-break">'.formatNumber($commission, 2).' &euro;</span></td>
<td><span class="small">'.$item->user_level_name.'</span></td>
</tr>';
return $ret;
}
}