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>
134 lines
4.8 KiB
PHP
134 lines
4.8 KiB
PHP
<?php
|
|
|
|
use App\Models\Incentive;
|
|
use App\Models\IncentiveParticipant;
|
|
use App\Services\Incentive\IncentiveTracker;
|
|
use App\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
$makeIncentiveRankingUser = fn () => User::forceCreate([
|
|
'email' => 'rank-'.uniqid('', true).'@example.com',
|
|
'password' => bcrypt('secret'),
|
|
'lang' => 'de',
|
|
]);
|
|
|
|
it('vergibt Raenge zuerst an Qualifizierte, dann nach Punkten', function () use ($makeIncentiveRankingUser) {
|
|
$incentive = Incentive::factory()->create(['max_winners' => 2]);
|
|
|
|
$notQualifiedTopPoints = IncentiveParticipant::factory()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $makeIncentiveRankingUser()->id,
|
|
'is_qualified' => false,
|
|
'total_points' => 5000,
|
|
]);
|
|
$qualifiedMidPoints = IncentiveParticipant::factory()->qualified()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $makeIncentiveRankingUser()->id,
|
|
'total_points' => 900,
|
|
]);
|
|
$qualifiedLowPoints = IncentiveParticipant::factory()->qualified()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $makeIncentiveRankingUser()->id,
|
|
'total_points' => 400,
|
|
]);
|
|
$zeroPoints = IncentiveParticipant::factory()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $makeIncentiveRankingUser()->id,
|
|
'total_points' => 0,
|
|
'rank' => 7,
|
|
]);
|
|
|
|
IncentiveTracker::updateRanking($incentive);
|
|
|
|
expect($qualifiedMidPoints->refresh()->rank)->toBe(1)
|
|
->and($qualifiedLowPoints->refresh()->rank)->toBe(2)
|
|
->and($notQualifiedTopPoints->refresh()->rank)->toBe(3)
|
|
->and($zeroPoints->refresh()->rank)->toBeNull();
|
|
});
|
|
|
|
it('macht Qualifizierte mit gespeichertem Rang innerhalb max_winners zu Gewinnern', function () use ($makeIncentiveRankingUser) {
|
|
$incentive = Incentive::factory()->create(['max_winners' => 2]);
|
|
|
|
$notQualifiedTopPoints = IncentiveParticipant::factory()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $makeIncentiveRankingUser()->id,
|
|
'is_qualified' => false,
|
|
'total_points' => 5000,
|
|
]);
|
|
$qualifiedA = IncentiveParticipant::factory()->qualified()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $makeIncentiveRankingUser()->id,
|
|
'total_points' => 900,
|
|
]);
|
|
$qualifiedB = IncentiveParticipant::factory()->qualified()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $makeIncentiveRankingUser()->id,
|
|
'total_points' => 400,
|
|
]);
|
|
|
|
IncentiveTracker::updateRanking($incentive);
|
|
|
|
expect($qualifiedA->refresh()->isWinner())->toBeTrue()
|
|
->and($qualifiedB->refresh()->isWinner())->toBeTrue()
|
|
->and($notQualifiedTopPoints->refresh()->isWinner())->toBeFalse();
|
|
});
|
|
|
|
it('sortiert bei Punktgleichstand bestaetigte Teilnehmer vor anonymen', function () use ($makeIncentiveRankingUser) {
|
|
$incentive = Incentive::factory()->create();
|
|
|
|
$anonymous = IncentiveParticipant::factory()->unconfirmed()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $makeIncentiveRankingUser()->id,
|
|
'total_points' => 500,
|
|
]);
|
|
$confirmed = IncentiveParticipant::factory()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $makeIncentiveRankingUser()->id,
|
|
'accepted_terms_at' => now(),
|
|
'total_points' => 500,
|
|
]);
|
|
|
|
IncentiveTracker::updateRanking($incentive);
|
|
|
|
expect($confirmed->refresh()->rank)->toBe(1)
|
|
->and($anonymous->refresh()->rank)->toBe(2);
|
|
});
|
|
|
|
it('stimmt mit der Leaderboard-Anzeigereihenfolge ueberein', function () use ($makeIncentiveRankingUser) {
|
|
$incentive = Incentive::factory()->create();
|
|
|
|
IncentiveParticipant::factory()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $makeIncentiveRankingUser()->id,
|
|
'is_qualified' => false,
|
|
'total_points' => 5000,
|
|
]);
|
|
IncentiveParticipant::factory()->qualified()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $makeIncentiveRankingUser()->id,
|
|
'total_points' => 900,
|
|
]);
|
|
IncentiveParticipant::factory()->qualified()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $makeIncentiveRankingUser()->id,
|
|
'total_points' => 400,
|
|
]);
|
|
IncentiveParticipant::factory()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $makeIncentiveRankingUser()->id,
|
|
'is_qualified' => false,
|
|
'total_points' => 200,
|
|
]);
|
|
|
|
IncentiveTracker::updateRanking($incentive);
|
|
|
|
$displayOrder = IncentiveParticipant::query()
|
|
->where('incentive_id', $incentive->id)
|
|
->orderByIncentiveLeaderboard()
|
|
->pluck('rank')
|
|
->all();
|
|
|
|
expect($displayOrder)->toBe([1, 2, 3, 4]);
|
|
});
|