mivita/app/Models/UserAboStatusHistory.php
Kevin ac3bd6e8ea Statistiken/Abo: Kundenfeedback 2026-07-24 komplett umgesetzt + Steuern: DATEV-Fixes 08+09/2025 (Sammel-Commit Branch-WIP)
Feedback-Umsetzung (dev/2026-07-22/feedback-analyse-2026-07-24.md, alle 10 Punkte):
- VIP-Statistik: eigener Berater ('ich', Linie 0) in Neue-Kundenabos- und beiden Top-10-Listen; Top-10-Umsatz sortiert nach abgerechneten Ist-Punkten + Abo-Anzahl-Spalte; Fußnote nicht-payline-wirksame Punkte (SalesVolumePoints::nonPaylinePoints)
- Führungskräfte-Liste: beide Sichten 'direkt' (an nächster FK abgeschnitten, additiv) und 'gesamt' (komplette Downline), Gesamt-Spalte nach Kundenzählweise
- Team-Abos: je Ebene 'abgerechnet (Monat)' und 'bis zum 25. erwartet'; Payline-Karte mit Teamabo-/Kundenabo-Zählern
- Incentive-Live-Ranking: Qualifizierte zuerst nummeriert (fixt auch isWinner rank<=max_winners)
- Porto: Netto-/Brutto-Kennzeichnung (Berater netto, Endkunden inkl. MwSt., portal_view-Flag; auch CRM-/Shop-Warenkorb + Checkout), Yard::shipping_tax-Fix
- Struktur-Ansicht: Abo-Badges 'A' (eigenes Abo) und '(n)' (Kundenabos) je Teampartner, gebatcht
- Abo-Löschung: Softdelete setzt active=0 (UserAbo deleting-Hook) + Bereinigungs-Migration für gelöschte-aber-aktive Abos
- Doku: technische Analyse + Kundinnen-Feedback-Dokument unter dev/2026-07-22/
- Tests: IncentiveRankingTest, TeamStructureAboBadgesTest, YardShippingTaxTest (neu); BackofficeStatisticsListsTest, TeamAboOverviewTest, PaylineForecastServiceTest, AboAdminDeleteTest, AboOneTimeViewTest erweitert

Außerdem enthalten (Branch-WIP vor dem Feedback): DATEV-Abgleich-Fixes 08+09/2025, USt-ID-Live-Validierung sowie restliche unkommittete Stände (u. a. Abo-Pause-Sprachkeys).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-24 13:56:02 +00:00

127 lines
3.8 KiB
PHP

<?php
namespace App\Models;
use App\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
/**
* Protokoll der Status-Aktionen eines Abos (Pause, Kündigung, Reaktivierung):
* wer (view + actor_user_id) hat wann welche Aktion ausgeführt und wie sich das
* Ausführungsdatum dadurch verschoben hat.
*
* @property int $id
* @property int $user_abo_id
* @property string $action
* @property string|null $view
* @property int|null $actor_user_id
* @property Carbon|null $previous_next_date
* @property Carbon|null $new_next_date
*/
class UserAboStatusHistory extends Model
{
public const ACTION_PAUSED = 'paused';
public const ACTION_CANCELLED = 'cancelled';
public const ACTION_DEACTIVATED = 'deactivated';
public const ACTION_REACTIVATED = 'reactivated';
public static $actionLabels = [
self::ACTION_PAUSED => 'abo_history.status_paused',
self::ACTION_CANCELLED => 'abo_history.status_cancelled',
self::ACTION_DEACTIVATED => 'abo_history.status_deactivated',
self::ACTION_REACTIVATED => 'abo_history.status_reactivated',
];
public static $actionColors = [
self::ACTION_PAUSED => 'warning',
self::ACTION_CANCELLED => 'danger',
self::ACTION_DEACTIVATED => 'secondary',
self::ACTION_REACTIVATED => 'success',
];
/**
* Formular-View → Kanal-Label/Farbe der Item-Historie (gleiche Optik im Protokoll).
*/
public static $viewChannelMap = [
'me' => 'user_me',
'ot' => 'user_ot',
'portal' => 'portal',
'admin' => 'admin',
];
protected $fillable = [
'user_abo_id',
'action',
'view',
'actor_user_id',
'previous_next_date',
'new_next_date',
];
protected $casts = [
'user_abo_id' => 'int',
'actor_user_id' => 'int',
'previous_next_date' => 'date',
'new_next_date' => 'date',
];
public function user_abo(): BelongsTo
{
return $this->belongsTo(UserAbo::class);
}
public function actor(): BelongsTo
{
return $this->belongsTo(User::class, 'actor_user_id');
}
public function getActionBadge(): string
{
$label = isset(self::$actionLabels[$this->action]) ? __(self::$actionLabels[$this->action]) : $this->action;
$color = self::$actionColors[$this->action] ?? 'secondary';
return '<span class="badge badge-'.$color.'">'.$label.'</span>';
}
public function getChannelBadge(): string
{
$channel = self::$viewChannelMap[$this->view] ?? 'system';
$label = isset(UserAboItemHistory::$channelLabels[$channel]) ? __(UserAboItemHistory::$channelLabels[$channel]) : $channel;
$color = UserAboItemHistory::$channelColors[$channel] ?? 'secondary';
return '<span class="badge badge-outline-'.$color.'">'.$label.'</span>';
}
public function getDescription(): string
{
if ($this->action === self::ACTION_PAUSED && $this->previous_next_date && $this->new_next_date) {
return __('abo_history.status_shift', [
'from' => $this->previous_next_date->format(\Util::formatDateDB()),
'to' => $this->new_next_date->format(\Util::formatDateDB()),
]);
}
return '';
}
public function getFormattedDate(): string
{
return $this->created_at ? $this->created_at->format(\Util::formatDateDB().' H:i') : '';
}
public function getActorName(): string
{
if (! $this->actor) {
return '-';
}
$name = trim(($this->actor->account?->first_name ?? '').' '.($this->actor->account?->last_name ?? ''));
return $name !== '' ? $name : ($this->actor->email ?? '-');
}
}