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>
267 lines
9.2 KiB
PHP
267 lines
9.2 KiB
PHP
<?php
|
|
|
|
use App\Models\Incentive;
|
|
use App\Models\IncentiveParticipant;
|
|
use App\Models\IncentivePointsLog;
|
|
use Carbon\Carbon;
|
|
|
|
// === Incentive: Zeitraum-Pruefungen ===
|
|
|
|
it('detects qualification period correctly', function () {
|
|
$incentive = new Incentive([
|
|
'qualification_start' => '2026-04-01',
|
|
'qualification_end' => '2026-07-31',
|
|
'calculation_end' => '2026-08-31',
|
|
]);
|
|
|
|
expect($incentive->isInQualificationPeriod(Carbon::parse('2026-05-15')))->toBeTrue()
|
|
->and($incentive->isInQualificationPeriod(Carbon::parse('2026-04-01')))->toBeTrue()
|
|
->and($incentive->isInQualificationPeriod(Carbon::parse('2026-07-31')))->toBeTrue()
|
|
->and($incentive->isInQualificationPeriod(Carbon::parse('2026-03-31')))->toBeFalse()
|
|
->and($incentive->isInQualificationPeriod(Carbon::parse('2026-08-01')))->toBeFalse();
|
|
});
|
|
|
|
it('detects calculation period correctly', function () {
|
|
$incentive = new Incentive([
|
|
'qualification_start' => '2026-04-01',
|
|
'qualification_end' => '2026-07-31',
|
|
'calculation_end' => '2026-08-31',
|
|
]);
|
|
|
|
expect($incentive->isInCalculationPeriod(Carbon::parse('2026-08-15')))->toBeTrue()
|
|
->and($incentive->isInCalculationPeriod(Carbon::parse('2026-04-01')))->toBeTrue()
|
|
->and($incentive->isInCalculationPeriod(Carbon::parse('2026-09-01')))->toBeFalse()
|
|
->and($incentive->isInCalculationPeriod(Carbon::parse('2026-03-31')))->toBeFalse();
|
|
});
|
|
|
|
it('checks date in scope by month/year', function () {
|
|
$incentive = new Incentive([
|
|
'qualification_start' => '2026-04-01',
|
|
'calculation_end' => '2026-08-31',
|
|
]);
|
|
|
|
expect($incentive->isDateInScope(4, 2026))->toBeTrue()
|
|
->and($incentive->isDateInScope(8, 2026))->toBeTrue()
|
|
->and($incentive->isDateInScope(9, 2026))->toBeFalse()
|
|
->and($incentive->isDateInScope(3, 2026))->toBeFalse();
|
|
});
|
|
|
|
it('returns correct calculation months', function () {
|
|
$incentive = new Incentive([
|
|
'qualification_start' => '2026-04-01',
|
|
'calculation_end' => '2026-08-31',
|
|
]);
|
|
|
|
$months = $incentive->getCalculationMonths();
|
|
|
|
expect($months)->toHaveCount(5)
|
|
->and($months[0])->toBe(['month' => 4, 'year' => 2026])
|
|
->and($months[1])->toBe(['month' => 5, 'year' => 2026])
|
|
->and($months[4])->toBe(['month' => 8, 'year' => 2026]);
|
|
});
|
|
|
|
it('qualificationWindow liefert Fensterstart 00:00:00 und Fensterende 23:59:59', function () {
|
|
$incentive = new Incentive([
|
|
'qualification_start' => '2026-04-01',
|
|
'qualification_end' => '2026-07-31',
|
|
'calculation_end' => '2026-08-31',
|
|
]);
|
|
|
|
[$windowStart, $windowEnd] = $incentive->qualificationWindow();
|
|
|
|
expect($windowStart->format('Y-m-d H:i:s'))->toBe('2026-04-01 00:00:00')
|
|
->and($windowEnd->format('Y-m-d H:i:s'))->toBe('2026-07-31 23:59:59');
|
|
});
|
|
|
|
it('qualificationWindowContains zaehlt Zeitstempel am letzten Fenstertag (Randtag-Fall)', function () {
|
|
$incentive = new Incentive([
|
|
'qualification_start' => '2026-04-01',
|
|
'qualification_end' => '2026-07-31',
|
|
'calculation_end' => '2026-08-31',
|
|
]);
|
|
|
|
expect($incentive->qualificationWindowContains(Carbon::parse('2026-07-31 11:05:52')))->toBeTrue()
|
|
->and($incentive->qualificationWindowContains(Carbon::parse('2026-07-31 23:59:59')))->toBeTrue()
|
|
->and($incentive->qualificationWindowContains(Carbon::parse('2026-04-01 00:00:00')))->toBeTrue()
|
|
->and($incentive->qualificationWindowContains(Carbon::parse('2026-05-15 12:00:00')))->toBeTrue()
|
|
->and($incentive->qualificationWindowContains(Carbon::parse('2026-03-31 23:59:59')))->toBeFalse()
|
|
->and($incentive->qualificationWindowContains(Carbon::parse('2026-08-01 00:00:00')))->toBeFalse();
|
|
});
|
|
|
|
// === Incentive: Status ===
|
|
|
|
it('detects status types correctly', function () {
|
|
$draft = new Incentive(['status' => 0]);
|
|
$active = new Incentive(['status' => 1]);
|
|
$closed = new Incentive(['status' => 2]);
|
|
|
|
expect($draft->isDraft())->toBeTrue()
|
|
->and($draft->isActive())->toBeFalse()
|
|
->and($active->isActive())->toBeTrue()
|
|
->and($active->isDraft())->toBeFalse()
|
|
->and($closed->isClosed())->toBeTrue()
|
|
->and($closed->isActive())->toBeFalse();
|
|
});
|
|
|
|
it('returns correct status colors', function () {
|
|
expect((new Incentive(['status' => 0]))->getStatusColor())->toBe('warning')
|
|
->and((new Incentive(['status' => 1]))->getStatusColor())->toBe('success')
|
|
->and((new Incentive(['status' => 2]))->getStatusColor())->toBe('secondary');
|
|
});
|
|
|
|
// === IncentiveParticipant: Qualifikation ===
|
|
|
|
it('qualifies with enough partners and abos', function () {
|
|
$incentive = new Incentive(['min_direct_partners' => 4, 'min_customer_abos' => 6]);
|
|
|
|
$participant = new IncentiveParticipant([
|
|
'qualified_partners' => 4,
|
|
'qualified_abos' => 6,
|
|
]);
|
|
$participant->setRelation('incentive', $incentive);
|
|
|
|
expect($participant->checkQualification())->toBeTrue()
|
|
->and($participant->is_qualified)->toBeTrue();
|
|
});
|
|
|
|
it('does not qualify with insufficient partners', function () {
|
|
$incentive = new Incentive(['min_direct_partners' => 4, 'min_customer_abos' => 6]);
|
|
|
|
$participant = new IncentiveParticipant([
|
|
'qualified_partners' => 3,
|
|
'qualified_abos' => 6,
|
|
]);
|
|
$participant->setRelation('incentive', $incentive);
|
|
|
|
expect($participant->checkQualification())->toBeFalse()
|
|
->and($participant->is_qualified)->toBeFalse();
|
|
});
|
|
|
|
it('does not qualify with insufficient abos', function () {
|
|
$incentive = new Incentive(['min_direct_partners' => 4, 'min_customer_abos' => 6]);
|
|
|
|
$participant = new IncentiveParticipant([
|
|
'qualified_partners' => 5,
|
|
'qualified_abos' => 5,
|
|
]);
|
|
$participant->setRelation('incentive', $incentive);
|
|
|
|
expect($participant->checkQualification())->toBeFalse();
|
|
});
|
|
|
|
it('does not qualify with zero partners and zero abos', function () {
|
|
$incentive = new Incentive(['min_direct_partners' => 4, 'min_customer_abos' => 6]);
|
|
|
|
$participant = new IncentiveParticipant([
|
|
'qualified_partners' => 0,
|
|
'qualified_abos' => 0,
|
|
]);
|
|
$participant->setRelation('incentive', $incentive);
|
|
|
|
expect($participant->checkQualification())->toBeFalse();
|
|
});
|
|
|
|
it('qualifies with exact minimums', function () {
|
|
$incentive = new Incentive(['min_direct_partners' => 4, 'min_customer_abos' => 6]);
|
|
|
|
$participant = new IncentiveParticipant([
|
|
'qualified_partners' => 4,
|
|
'qualified_abos' => 6,
|
|
]);
|
|
$participant->setRelation('incentive', $incentive);
|
|
|
|
expect($participant->checkQualification())->toBeTrue();
|
|
});
|
|
|
|
it('qualifies with more than minimums', function () {
|
|
$incentive = new Incentive(['min_direct_partners' => 4, 'min_customer_abos' => 6]);
|
|
|
|
$participant = new IncentiveParticipant([
|
|
'qualified_partners' => 10,
|
|
'qualified_abos' => 12,
|
|
]);
|
|
$participant->setRelation('incentive', $incentive);
|
|
|
|
expect($participant->checkQualification())->toBeTrue();
|
|
});
|
|
|
|
// === IncentiveParticipant: Winner ===
|
|
|
|
it('is winner when qualified and rank within max_winners', function () {
|
|
$incentive = new Incentive(['max_winners' => 30]);
|
|
|
|
$participant = new IncentiveParticipant([
|
|
'is_qualified' => true,
|
|
'rank' => 5,
|
|
]);
|
|
$participant->setRelation('incentive', $incentive);
|
|
|
|
expect($participant->isWinner())->toBeTrue();
|
|
});
|
|
|
|
it('is winner at rank boundary', function () {
|
|
$incentive = new Incentive(['max_winners' => 30]);
|
|
|
|
$participant = new IncentiveParticipant([
|
|
'is_qualified' => true,
|
|
'rank' => 30,
|
|
]);
|
|
$participant->setRelation('incentive', $incentive);
|
|
|
|
expect($participant->isWinner())->toBeTrue();
|
|
});
|
|
|
|
it('is not winner when rank exceeds max_winners', function () {
|
|
$incentive = new Incentive(['max_winners' => 30]);
|
|
|
|
$participant = new IncentiveParticipant([
|
|
'is_qualified' => true,
|
|
'rank' => 31,
|
|
]);
|
|
$participant->setRelation('incentive', $incentive);
|
|
|
|
expect($participant->isWinner())->toBeFalse();
|
|
});
|
|
|
|
it('is not winner when not qualified even with good rank', function () {
|
|
$incentive = new Incentive(['max_winners' => 30]);
|
|
|
|
$participant = new IncentiveParticipant([
|
|
'is_qualified' => false,
|
|
'rank' => 1,
|
|
]);
|
|
$participant->setRelation('incentive', $incentive);
|
|
|
|
expect($participant->isWinner())->toBeFalse();
|
|
});
|
|
|
|
it('is not winner when rank is null', function () {
|
|
$incentive = new Incentive(['max_winners' => 30]);
|
|
|
|
$participant = new IncentiveParticipant([
|
|
'is_qualified' => true,
|
|
'rank' => null,
|
|
]);
|
|
$participant->setRelation('incentive', $incentive);
|
|
|
|
expect($participant->isWinner())->toBeFalse();
|
|
});
|
|
|
|
// === IncentivePointsLog: Helpers ===
|
|
|
|
it('calculates total points from onetime and accumulated', function () {
|
|
$log = new IncentivePointsLog([
|
|
'points_onetime' => 600,
|
|
'points_accumulated' => 150,
|
|
]);
|
|
|
|
expect($log->getTotalPoints())->toBe(750);
|
|
});
|
|
|
|
it('formats month/year correctly', function () {
|
|
$log = new IncentivePointsLog(['month' => 4, 'year' => 2026]);
|
|
expect($log->getFormattedMonthYear())->toBe('04/2026');
|
|
|
|
$log2 = new IncentivePointsLog(['month' => 12, 'year' => 2026]);
|
|
expect($log2->getFormattedMonthYear())->toBe('12/2026');
|
|
});
|