Statistik-Änderungen 2026-08-19 (dev/2026-07-22/entwicklungsplan-2026-08-19.md, alle 8 Pakete gemäß beantworteten F-Fragen): - N1 Monatsstatistik: Team-Cluster (Firstlines klickbar -> neue Seite user_team_firstlines, Teampartner gesamt/Payline [nur aktive], Abos Payline mit +N) + Level-Kachel (Quali-Stufe, fehlende Payline-/persönliche Punkte, Karriere-Level); LiveCommissionService-Snapshot v3 reicht Level-/Quali-Daten durch - N2 Abo-Kacheln auf Home monatsbezogen (aboStockCount-Rückrechnung über cancel/deleted/Status-Historie; VIP-Statistik bleibt tagesaktuell) - N3 VIP-Statistik 'Recruiter des Monats' (Neupartner-Definition wie KPI, rekursives Ketten-Volumen als Gesamtpunkte inkl. Starterpaket) + Drilldown/CSV-Spalte 'Punkte gesamt' - N4 Prognose-Block 'Level & Provision laut Prognose (Stand 25.)' mit unverbindlich-Kennzeichnung (ebenengenaue offene Abo-Punkte + TP-Laufstände) - N5 Checkout-Herkunft: Dropdown raus, Pflicht-Freitext (lokalisierte Fehlermeldung) - N6 Berater-Profilfoto (user_accounts.profile_image, Einwilligung als Sprachkey-Platzhalter, DSGVO-Löschung) + teaminterne Top-3-Karte (TopResultsService, Scope-Schalter) - N7 USt-Optionen: 'nicht umsatzsteuerpflichtig' zuerst + '§ 19 UStG'-Textfix - N8 Jahresgebühr-Nachfassliste je Berater (AnnualFeeDueService, überfällig/1-3 Monate, Sidenav) Kontroll-Review (8 Perspektiven) angewendet: next-Level-Fallback im Steady-State (resolveNextLevel — sonst 'Höchstes Level erreicht' für Normalfälle), _calculated-Punktebasis bei mehr Paylines, keine Wiederbelebung deaktivierter Abos in der Monatsrückrechnung, Payline-Abo-Kachel monatskonsistent, Top-3-Nachrücker; Performance: BackofficeDashboardService als Singleton mit lineBuckets-Memo (+flushLineBucketsMemo), level_forecast 6h-Cache; Reuse: User-Scopes firstlinesOf/newPartnerIn, SalesVolumePoints::totalPointsByUser, Slim::storeCroppedImage (3 Upload-Kopien vereinigt), activeAbo-Scope statt Inline-Prädikate, Form::open-Konvention, Return-Types Repair-Härtung (Kundenentscheide): VP-Nachtrepair dedupliziert über shopping_order_id (Live-Pfad schreibt sie jetzt mit), zählende Alt-Zeilen-Erkennung, Vormonats-Scan für Monatswechsel, Firmenaccount-Buchungen (config mivita.company_user_id) werden automatisch auf den Berater umgebucht (in place bzw. per Gegenbuchung bei geschlossenem Monat; Echtfall Anna Schall Order 58797 -> Christina Schuder), Berater-zu-Berater nur Warnung; Incentive-Repair: m_sponsor=NULL löscht nicht mehr, FK-Repair vor Stale-Bereinigung, gebatchte Lookups, zentrales Incentive::qualificationWindow(); .env aus dem Git-Tracking entfernt (Pflege per SFTP) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
274 lines
7.2 KiB
PHP
274 lines
7.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Cviebrock\EloquentSluggable\Sluggable;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* Class Incentive
|
|
*
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property array|null $trans_name
|
|
* @property string|null $subtitle
|
|
* @property array|null $trans_subtitle
|
|
* @property string $slug
|
|
* @property string|null $description
|
|
* @property array|null $trans_description
|
|
* @property string|null $image
|
|
* @property string|null $terms
|
|
* @property array|null $trans_terms
|
|
* @property Carbon $qualification_start
|
|
* @property Carbon $qualification_end
|
|
* @property Carbon $calculation_end
|
|
* @property int $points_partner_onetime
|
|
* @property int $points_abo_onetime
|
|
* @property int $min_direct_partners
|
|
* @property int $min_customer_abos
|
|
* @property int $max_winners
|
|
* @property int $status
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
* @property Carbon|null $deleted_at
|
|
* @property-read Collection<int, IncentiveParticipant> $participants
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Incentive newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Incentive newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Incentive query()
|
|
*
|
|
* @mixin \Eloquent
|
|
*/
|
|
class Incentive extends Model
|
|
{
|
|
use HasFactory, Sluggable, SoftDeletes;
|
|
|
|
protected $table = 'incentives';
|
|
|
|
protected $casts = [
|
|
'trans_name' => 'array',
|
|
'trans_subtitle' => 'array',
|
|
'trans_description' => 'array',
|
|
'trans_terms' => 'array',
|
|
'points_partner_onetime' => 'int',
|
|
'points_abo_onetime' => 'int',
|
|
'min_direct_partners' => 'int',
|
|
'min_customer_abos' => 'int',
|
|
'max_winners' => 'int',
|
|
'status' => 'int',
|
|
'qualification_start' => 'date',
|
|
'qualification_end' => 'date',
|
|
'calculation_end' => 'date',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'trans_name',
|
|
'subtitle',
|
|
'trans_subtitle',
|
|
'description',
|
|
'trans_description',
|
|
'image',
|
|
'terms',
|
|
'trans_terms',
|
|
'qualification_start',
|
|
'qualification_end',
|
|
'calculation_end',
|
|
'points_partner_onetime',
|
|
'points_abo_onetime',
|
|
'min_direct_partners',
|
|
'min_customer_abos',
|
|
'max_winners',
|
|
'status',
|
|
];
|
|
|
|
public static $statusTypes = [
|
|
0 => 'draft',
|
|
1 => 'active',
|
|
2 => 'closed',
|
|
];
|
|
|
|
public static $statusColors = [
|
|
0 => 'warning',
|
|
1 => 'success',
|
|
2 => 'secondary',
|
|
];
|
|
|
|
public function sluggable(): array
|
|
{
|
|
return [
|
|
'slug' => [
|
|
'source' => 'name',
|
|
],
|
|
];
|
|
}
|
|
|
|
// Relationships
|
|
|
|
public function participants()
|
|
{
|
|
return $this->hasMany(IncentiveParticipant::class);
|
|
}
|
|
|
|
// Scopes
|
|
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->where('status', 1);
|
|
}
|
|
|
|
public function scopeInQualificationPeriod($query, ?Carbon $date = null)
|
|
{
|
|
$date = $date ?: Carbon::now();
|
|
|
|
return $query->where('qualification_start', '<=', $date)
|
|
->where('qualification_end', '>=', $date);
|
|
}
|
|
|
|
public function scopeInCalculationPeriod($query, ?Carbon $date = null)
|
|
{
|
|
$date = $date ?: Carbon::now();
|
|
|
|
return $query->where('qualification_start', '<=', $date)
|
|
->where('calculation_end', '>=', $date);
|
|
}
|
|
|
|
/**
|
|
* Incentives, deren Qualifikationsfenster das Datum enthaelt (Datumsvergleich auf Tagesebene,
|
|
* damit auch Zeitstempel am letzten Fenstertag zaehlen).
|
|
*/
|
|
public function scopeQualificationWindowContains($query, Carbon $date)
|
|
{
|
|
return $query->whereDate('qualification_start', '<=', $date)
|
|
->whereDate('qualification_end', '>=', $date);
|
|
}
|
|
|
|
// Helpers
|
|
|
|
public function isActive(): bool
|
|
{
|
|
return $this->status === 1;
|
|
}
|
|
|
|
public function isDraft(): bool
|
|
{
|
|
return $this->status === 0;
|
|
}
|
|
|
|
public function isClosed(): bool
|
|
{
|
|
return $this->status === 2;
|
|
}
|
|
|
|
public function isInQualificationPeriod(?Carbon $date = null): bool
|
|
{
|
|
$date = $date ?: Carbon::now();
|
|
|
|
return $date->between($this->qualification_start, $this->qualification_end);
|
|
}
|
|
|
|
public function isInCalculationPeriod(?Carbon $date = null): bool
|
|
{
|
|
$date = $date ?: Carbon::now();
|
|
|
|
return $date->between($this->qualification_start, $this->calculation_end);
|
|
}
|
|
|
|
public function isDateInScope(int $month, int $year): bool
|
|
{
|
|
$date = Carbon::createFromDate($year, $month, 1);
|
|
|
|
return $date->between(
|
|
$this->qualification_start->copy()->startOfMonth(),
|
|
$this->calculation_end->copy()->endOfMonth()
|
|
);
|
|
}
|
|
|
|
public function getStatusType(): string
|
|
{
|
|
return isset(self::$statusTypes[$this->status]) ? __('incentive.status_'.self::$statusTypes[$this->status]) : '';
|
|
}
|
|
|
|
public function getStatusColor(): string
|
|
{
|
|
return self::$statusColors[$this->status] ?? 'default';
|
|
}
|
|
|
|
/**
|
|
* Get specific translation for a field and locale.
|
|
*/
|
|
public function getTrans(string $key, string $lang): string
|
|
{
|
|
$transKey = 'trans_'.$key;
|
|
if (! empty($this->{$transKey}[$lang])) {
|
|
return $this->{$transKey}[$lang];
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* Get translated value for the current locale, falling back to German (default).
|
|
*/
|
|
public function getLang(string $key): string
|
|
{
|
|
$lang = \App::getLocale();
|
|
if ($lang === 'de') {
|
|
return (string) ($this->{$key} ?? '');
|
|
}
|
|
$trans = $this->getTrans($key, $lang);
|
|
if ($trans !== '') {
|
|
return $trans;
|
|
}
|
|
|
|
return (string) ($this->{$key} ?? '');
|
|
}
|
|
|
|
/**
|
|
* Qualifikationsfenster als Zeitstempel-Paar: [Start 00:00:00, Ende 23:59:59].
|
|
* Zentrale Fensterberechnung, damit Bestellungen am letzten Fenstertag ueberall zaehlen.
|
|
*
|
|
* @return array{0: Carbon, 1: Carbon}
|
|
*/
|
|
public function qualificationWindow(): array
|
|
{
|
|
return [
|
|
$this->qualification_start->copy()->startOfDay(),
|
|
$this->qualification_end->copy()->endOfDay(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Liegt der Zeitstempel im Qualifikationsfenster (inkl. des kompletten letzten Tages)?
|
|
*/
|
|
public function qualificationWindowContains(Carbon $date): bool
|
|
{
|
|
[$windowStart, $windowEnd] = $this->qualificationWindow();
|
|
|
|
return $date->between($windowStart, $windowEnd);
|
|
}
|
|
|
|
/**
|
|
* @return array<int, array{month: int, year: int}>
|
|
*/
|
|
public function getCalculationMonths(): array
|
|
{
|
|
$months = [];
|
|
$current = $this->qualification_start->copy()->startOfMonth();
|
|
$end = $this->calculation_end->copy()->startOfMonth();
|
|
|
|
while ($current->lte($end)) {
|
|
$months[] = [
|
|
'month' => $current->month,
|
|
'year' => $current->year,
|
|
];
|
|
$current->addMonth();
|
|
}
|
|
|
|
return $months;
|
|
}
|
|
}
|