391 lines
No EOL
13 KiB
PHP
391 lines
No EOL
13 KiB
PHP
<?php
|
|
|
|
namespace App\Services\BusinessPlan;
|
|
|
|
use App\Services\TranslationHelper;
|
|
|
|
/**
|
|
* Klasse für die HTML-Darstellung von Business-Trees
|
|
* Trennt Präsentationslogik von Geschäftslogik
|
|
*/
|
|
class TreeHtmlRenderer
|
|
{
|
|
private string $initFrom;
|
|
private bool $forceLiveCalculation;
|
|
|
|
public function __construct(string $initFrom = 'member', bool $forceLiveCalculation = false)
|
|
{
|
|
$this->initFrom = $initFrom;
|
|
$this->forceLiveCalculation = $forceLiveCalculation;
|
|
}
|
|
|
|
/**
|
|
* Rendert den kompletten Business-Tree als HTML
|
|
*/
|
|
public function renderTree(array $businessUsers): string
|
|
{
|
|
if (empty($businessUsers)) {
|
|
return '<div class="alert alert-info">Keine Business-User gefunden.</div>';
|
|
}
|
|
|
|
$html = '<ol class="dd-list">';
|
|
foreach ($businessUsers as $businessUser) {
|
|
$html .= $this->renderUserItem($businessUser, 0);
|
|
}
|
|
$html .= '</ol>';
|
|
|
|
return $html;
|
|
}
|
|
|
|
/**
|
|
* Rendert parentlose User als HTML
|
|
*/
|
|
public function renderParentless(array $parentless): string
|
|
{
|
|
if (empty($parentless)) {
|
|
return '<div class="alert alert-info">Keine parentlosen User gefunden.</div>';
|
|
}
|
|
|
|
$html = '';
|
|
foreach ($parentless as $item) {
|
|
$html .= $this->renderParentlessItem($item);
|
|
}
|
|
|
|
return $html;
|
|
}
|
|
|
|
/**
|
|
* Rendert Sponsor-Information als HTML
|
|
*/
|
|
public function renderSponsor($sponsor): string
|
|
{
|
|
if (!$sponsor) {
|
|
return '<div class="alert alert-warning">' . __('team.no_sponsor_assigned') . '</div>';
|
|
}
|
|
|
|
return '<li class="dd-item dd-nodrag" data-id="">' .
|
|
'<div class="dd-handle">' .
|
|
$this->renderUserInfo($sponsor, false, true) .
|
|
'</div>' .
|
|
'</li>';
|
|
}
|
|
|
|
/**
|
|
* Rendert User Team Tree (für UserTeamCalcBot)
|
|
*/
|
|
public function renderUserTeamTree(array $teamMembers): string
|
|
{
|
|
if (empty($teamMembers)) {
|
|
return '<div class="alert alert-info">Keine Team-Mitglieder gefunden.</div>';
|
|
}
|
|
|
|
$html = '<ol class="dd-list">';
|
|
foreach ($teamMembers as $member) {
|
|
$html .= $this->renderTeamMemberItem($member, 0);
|
|
}
|
|
$html .= '</ol>';
|
|
|
|
return $html;
|
|
}
|
|
|
|
/**
|
|
* Rendert User Sponsor (für UserTeamCalcBot)
|
|
*/
|
|
public function renderUserSponsor(\App\User $sponsor): string
|
|
{
|
|
if (!$sponsor || !$sponsor->account) {
|
|
return '<div class="alert alert-info">Kein Sponsor gefunden.</div>';
|
|
}
|
|
|
|
$html = '<div class="dd-item">';
|
|
$html .= '<div class="dd-handle">';
|
|
$html .= '<div class="row">';
|
|
|
|
// Sponsor Info
|
|
$html .= '<div class="col-md-3">';
|
|
$html .= '<strong>' . e($sponsor->account->first_name . ' ' . $sponsor->account->last_name) . '</strong><br>';
|
|
$html .= '<small>' . e($sponsor->email) . '</small>';
|
|
$html .= '</div>';
|
|
|
|
// Account Info
|
|
$html .= '<div class="col-md-2">';
|
|
$html .= '<span class="badge badge-secondary">' . e($sponsor->account->m_account ?? '') . '</span>';
|
|
$html .= '</div>';
|
|
|
|
// Level Info
|
|
$html .= '<div class="col-md-2">';
|
|
if ($sponsor->user_level) {
|
|
$html .= '<span class="badge badge-primary">' . e($sponsor->user_level->getLang('name')) . '</span>';
|
|
}
|
|
$html .= '</div>';
|
|
|
|
// Status
|
|
$html .= '<div class="col-md-2">';
|
|
$html .= get_active_badge($sponsor->isActiveAccount());
|
|
$html .= '</div>';
|
|
|
|
$html .= '</div>';
|
|
$html .= '</div>';
|
|
$html .= '</div>';
|
|
|
|
return $html;
|
|
}
|
|
|
|
/**
|
|
* Rendert einzelnes Team-Mitglied
|
|
*/
|
|
private function renderTeamMemberItem($member, int $depth): string
|
|
{
|
|
$html = '<li class="dd-item" data-id="' . ($member->user_id ?? 0) . '">';
|
|
$html .= '<div class="dd-handle">';
|
|
$html .= '<div class="row">';
|
|
|
|
// Einrückung basierend auf Tiefe
|
|
$indent = str_repeat(' ', $depth);
|
|
|
|
// Name und Email
|
|
$html .= '<div class="col-md-3">';
|
|
$html .= $indent;
|
|
$html .= '<strong>' . e(($member->first_name ?? '') . ' ' . ($member->last_name ?? '')) . '</strong><br>';
|
|
$html .= $indent . '<small>' . e($member->email ?? '') . '</small>';
|
|
$html .= '</div>';
|
|
|
|
// Account ID
|
|
$html .= '<div class="col-md-2">';
|
|
$html .= '<span class="badge badge-secondary">' . e($member->m_account ?? '') . '</span>';
|
|
$html .= '</div>';
|
|
|
|
// Level
|
|
$html .= '<div class="col-md-2">';
|
|
if (!empty($member->user_level_name)) {
|
|
$html .= '<span class="badge badge-primary">' . e($member->user_level_name) . '</span>';
|
|
|
|
if ($member->next_qual_user_level) {
|
|
$html .= '<span class="badge badge-outline-success ml-2"><i class="fa fa-arrow-up text-success" title="Karriere-Level erreicht!"></i></span>';
|
|
}
|
|
}
|
|
$html .= '</div>';
|
|
|
|
// Qualifikation
|
|
$html .= '<div class="col-md-2">';
|
|
if (!empty($member->qual_kp)) {
|
|
$pointsSum = (int) ($member->sales_volume_points_KP_sum ?? 0);
|
|
$qualKP = (int) $member->qual_kp;
|
|
$isQual = $pointsSum >= $qualKP;
|
|
$badgeClass = $isQual ? 'badge-success' : 'badge-warning';
|
|
$html .= '<span class="badge ' . $badgeClass . '">KU ' . $qualKP . '</span>';
|
|
}
|
|
$html .= '</div>';
|
|
|
|
// Status
|
|
$html .= '<div class="col-md-2">';
|
|
$html .= get_active_badge($member->active_account ?? 0);
|
|
$html .= '</div>';
|
|
|
|
$html .= '</div>';
|
|
$html .= '</div>';
|
|
|
|
// Kinder rendern
|
|
if (!empty($member->businessUserItems) && is_array($member->businessUserItems)) {
|
|
$html .= '<ol class="dd-list">';
|
|
foreach ($member->businessUserItems as $child) {
|
|
$html .= $this->renderTeamMemberItem($child, $depth + 1);
|
|
}
|
|
$html .= '</ol>';
|
|
}
|
|
|
|
$html .= '</li>';
|
|
|
|
return $html;
|
|
}
|
|
|
|
/**
|
|
* Rendert einen einzelnen User-Item mit Hierarchie
|
|
*/
|
|
private function renderUserItem($item, int $deep): string
|
|
{
|
|
$childrenHtml = '';
|
|
if ($item->businessUserItems && count($item->businessUserItems) > 0) {
|
|
$childrenHtml = '<ol class="dd-list dd-nodrag">';
|
|
foreach ($item->businessUserItems as $child) {
|
|
$childrenHtml .= $this->renderUserItem($child, $deep + 1);
|
|
}
|
|
$childrenHtml .= '</ol>';
|
|
}
|
|
|
|
return '<li class="dd-item dd-nodrag" data-id="' . $item->user_id . '">' .
|
|
'<div class="dd-handle">' .
|
|
$this->renderUserCardWithDepth($item, $deep) .
|
|
'</div>' .
|
|
$childrenHtml .
|
|
'</li>';
|
|
}
|
|
|
|
/**
|
|
* Rendert parentlosen User-Item
|
|
*/
|
|
private function renderParentlessItem($item): string
|
|
{
|
|
return '<li class="dd-item dd-nodrag" data-id="' . $item->user_id . '">' .
|
|
'<div class="dd-handle">' .
|
|
$this->renderUserInfo($item, true, false) .
|
|
'</div>' .
|
|
'</li>';
|
|
}
|
|
|
|
/**
|
|
* Rendert User-Card mit Tiefe-Anzeige
|
|
*/
|
|
private function renderUserCardWithDepth($item, int $deep): string
|
|
{
|
|
$depthBadge = '';
|
|
if ($deep > 0) {
|
|
$depthBadge = '<div class="d-flex flex-column justify-content-center align-items-center">' .
|
|
'<div class="text-large font-weight-bolder line-height-1 my-2 text-secondary badge badge-outline-secondary">' . $deep . '</div>' .
|
|
'</div>';
|
|
}
|
|
|
|
return '<div class="media align-items-center">' .
|
|
$depthBadge .
|
|
'<div class="media-body ml-2">' .
|
|
$this->renderUserInfo($item, false, false) .
|
|
'</div>' .
|
|
'</div>';
|
|
}
|
|
|
|
/**
|
|
* Rendert die Basis-User-Informationen
|
|
*/
|
|
private function renderUserInfo($item, bool $showSponsor = false, bool $isSponsor = false): string
|
|
{
|
|
$statusClass = $item->active_account ? '' : 'text-muted';
|
|
$iconClass = $item->active_account ? 'text-primary' : 'text-danger';
|
|
|
|
\Log::debug("TreeHtmlRenderer: Rendering user info for user {$item->user_id}");
|
|
|
|
$html = '<span class="' . $statusClass . '">';
|
|
|
|
// User Link
|
|
$html .= '<a href="#" class="text-black" data-toggle="modal" data-target="#modals-load-content" ' .
|
|
'data-id="' . $item->user_id . '" data-action="business-user-show" data-back="" ' .
|
|
'data-modal="modal-md" data-init_from="' . $this->initFrom . '" data-route="' . route('modal_load') . '">' .
|
|
'<span class="mr-1 ion ion-ios-contact ' . $iconClass . '"></span> ' .
|
|
'<strong>' . e($item->first_name . ' ' . $item->last_name) . '</strong>' .
|
|
'</a>';
|
|
|
|
// Email
|
|
$html .= ' <a href="mailto:' . e($item->email) . '">' . e($item->email) . '</a>';
|
|
|
|
// Optional: Geburtstag
|
|
$birthday = $item->user_birthday; // Magic Method __get() verwenden
|
|
if ($birthday && trim($birthday) !== '') {
|
|
$html .= ' | <i class="ion ion-ios-gift text-primary"></i> ' . e($birthday);
|
|
}
|
|
|
|
// Optional: Telefon
|
|
$phone = $item->user_phone; // Magic Method __get() verwenden
|
|
if ($phone && trim($phone) !== '') {
|
|
$html .= ' | <i class="ion ion-ios-call text-primary"></i> ' . e($phone);
|
|
}
|
|
|
|
// Level Badge
|
|
$levelName = $item->user_level_name ? TranslationHelper::transUserLevelName($item->user_level_name) : '';
|
|
$account = $item->m_account ?: '';
|
|
$html .= ' <span class="badge badge-outline-default ' . $statusClass . '">' . e($levelName . ' | ' . $account) . '</span>';
|
|
|
|
// Karriere-Aufstiegs-Icon für qualifizierte User (nur in Struktur-Ansicht)#
|
|
|
|
if ($item->next_qual_user_level) {
|
|
$html .= '<span class="badge badge-outline-success ml-2"><i class="fa fa-arrow-up text-success" title="Karriere-Level erreicht!"></i></span>';
|
|
}
|
|
|
|
// Details für aktive Accounts
|
|
if ($item->active_account) {
|
|
$html .= '<br><span class="small">';
|
|
if(!$isSponsor){
|
|
$html .= $this->renderAccountDetails($item);
|
|
}
|
|
|
|
// Action Button (außer für Sponsor-Ansicht)
|
|
if (!$isSponsor && $this->shouldShowActionButton()) {
|
|
$html .= $this->renderActionButton($item->user_id);
|
|
}
|
|
|
|
$html .= '</span>';
|
|
} else {
|
|
// Inaktive Accounts
|
|
$paymentDate = $item->payment_account_date ?: '';
|
|
$html .= '<br><span class="small">' . __('team.account_to') . ': ' . e($paymentDate) . '</span>';
|
|
}
|
|
|
|
// Sponsor für parentlose User
|
|
if ($showSponsor && $item->m_sponsor_name) {
|
|
$html .= '<br>' . e($item->m_sponsor_name);
|
|
}
|
|
|
|
$html .= '</span>';
|
|
|
|
return $html;
|
|
}
|
|
|
|
/**
|
|
* Rendert Account-Details (Punkte, Umsatz)
|
|
*/
|
|
private function renderAccountDetails($item): string
|
|
{
|
|
$totalPoints = $item->sales_volume_points_KP_sum ?: 0;
|
|
$ePoints = $item->sales_volume_KP_points ?: 0;
|
|
$sPoints = $item->sales_volume_points_shop ?: 0;
|
|
|
|
$totalSum = $item->sales_volume_total_sum ?: 0;
|
|
$eSum = $item->sales_volume_total ?: 0;
|
|
$sSum = $item->sales_volume_total_shop ?: 0;
|
|
|
|
return '<strong>' . __('team.total_points') . ': ' . $totalPoints . '</strong> | ' .
|
|
__('team.e') . ': ' . $ePoints . ' | ' .
|
|
__('team.s') . ': ' . $sPoints . ' <strong> | ' .
|
|
__('team.net_turnover') . ': ' . formatNumber($totalSum) . ' €</strong> | ' .
|
|
__('team.e') . ': ' . formatNumber($eSum) . ' € | ' .
|
|
__('team.s') . ': ' . formatNumber($sSum) . ' €';
|
|
}
|
|
|
|
/**
|
|
* Rendert Action-Button für User-Details
|
|
*/
|
|
private function renderActionButton(int $userId): string
|
|
{
|
|
return ' | <button type="button" class="btn icon-btn btn-xs btn-secondary" ' .
|
|
'data-toggle="modal" data-target="#modals-load-content" ' .
|
|
'data-id="' . $userId . '" data-action="business-user-detail" ' .
|
|
'data-back="" data-modal="modal-xl" ' .
|
|
'data-init_from="' . $this->initFrom . '" ' .
|
|
'data-live="' . $this->forceLiveCalculation . '" ' .
|
|
'data-optimized="1" ' .
|
|
'data-route="' . route('modal_load') . '">' .
|
|
'<span class="fa fa-calculator"></span>' .
|
|
'</button>';
|
|
}
|
|
|
|
/**
|
|
* Prüft ob Action-Button angezeigt werden soll
|
|
*/
|
|
private function shouldShowActionButton(): bool
|
|
{
|
|
try {
|
|
return ($this->initFrom === 'admin' && \Auth::check() && \Auth::user()->isAdmin()) ||
|
|
($this->initFrom === 'member');
|
|
} catch (\Exception $e) {
|
|
// Fallback for tests or when no user is authenticated
|
|
return $this->initFrom === 'member';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Setzt den Kontext für die Darstellung
|
|
*/
|
|
public function setInitFrom(string $initFrom): self
|
|
{
|
|
$this->initFrom = $initFrom;
|
|
return $this;
|
|
}
|
|
} |