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>
151 lines
4.9 KiB
PHP
151 lines
4.9 KiB
PHP
<?php
|
|
|
|
use App\Models\UserBusiness;
|
|
use App\Services\BusinessPlan\LiveCommissionService;
|
|
use App\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
Carbon::setTestNow(Carbon::parse('2026-07-22'));
|
|
Cache::flush();
|
|
});
|
|
|
|
afterEach(function () {
|
|
Carbon::setTestNow();
|
|
});
|
|
|
|
function lcsMakeUser(): User
|
|
{
|
|
return User::forceCreate([
|
|
'email' => 'lcs-'.uniqid('', true).'@example.com',
|
|
'password' => bcrypt('secret'),
|
|
'lang' => 'de',
|
|
'm_level' => 1,
|
|
'payment_account' => now()->addYear(),
|
|
]);
|
|
}
|
|
|
|
it('liefert die gespeicherte Provision, wenn der Monats-Batch bereits gelaufen ist', function (): void {
|
|
$user = lcsMakeUser();
|
|
|
|
UserBusiness::forceCreate([
|
|
'user_id' => $user->id,
|
|
'month' => 6,
|
|
'year' => 2026,
|
|
'version' => 2,
|
|
'commission_pp_total' => 120.50,
|
|
'commission_shop_sales' => 30.25,
|
|
'commission_growth_total' => 10.00,
|
|
]);
|
|
|
|
$commission = app(LiveCommissionService::class)->commission($user, 6, 2026);
|
|
|
|
expect($commission['total'])->toBe(160.75)
|
|
->and($commission['pp'])->toBe(120.5)
|
|
->and($commission['shop'])->toBe(30.25)
|
|
->and($commission['growth'])->toBe(10.0)
|
|
->and($commission['is_live'])->toBeFalse();
|
|
});
|
|
|
|
it('berechnet den Live-Snapshot ueber den gemeinsamen Lauf und cached ihn', function (): void {
|
|
$user = lcsMakeUser();
|
|
|
|
$snapshot = app(LiveCommissionService::class)->snapshot($user, 7, 2026);
|
|
|
|
expect($snapshot['is_live'])->toBeTrue()
|
|
->and($snapshot['failed'])->toBeFalse()
|
|
->and($snapshot['payline_points'])->toBe(0.0)
|
|
->and($snapshot['paylines'])->toBe(0)
|
|
->and(Cache::has("live_business_{$user->id}_7_2026"))->toBeTrue();
|
|
});
|
|
|
|
it('faellt bei fehlschlagender Live-Berechnung auf Null-Werte zurueck und cached den Fehler nicht', function (): void {
|
|
$user = lcsMakeUser();
|
|
|
|
// Deterministischer Fehler: ohne user_levels bricht der Baum-Lauf ab
|
|
Schema::drop('user_levels');
|
|
|
|
$commission = app(LiveCommissionService::class)->commission($user, 7, 2026);
|
|
|
|
expect($commission['total'])->toBe(0.0)
|
|
->and($commission['is_live'])->toBeTrue()
|
|
->and(Cache::has("live_business_{$user->id}_7_2026"))->toBeFalse();
|
|
});
|
|
|
|
it('cached die Live-Provision fuer Folgeaufrufe', function (): void {
|
|
$user = lcsMakeUser();
|
|
|
|
Cache::put(
|
|
"live_business_{$user->id}_7_2026",
|
|
['payline_points' => 12.5, 'paylines' => 2, 'pp' => 99.0, 'shop' => 0.0, 'growth' => 0.0, 'is_live' => true, 'failed' => false],
|
|
now()->addHour()
|
|
);
|
|
|
|
$commission = app(LiveCommissionService::class)->commission($user, 7, 2026);
|
|
$snapshot = app(LiveCommissionService::class)->snapshot($user, 7, 2026);
|
|
|
|
expect($commission['total'])->toBe(99.0)
|
|
->and($commission['is_live'])->toBeTrue()
|
|
->and($snapshot['payline_points'])->toBe(12.5)
|
|
->and($snapshot['paylines'])->toBe(2);
|
|
});
|
|
|
|
it('liefert Payline-Punkte und Payline-Tiefe aus dem UserBusiness-Snapshot', function (): void {
|
|
$user = lcsMakeUser();
|
|
|
|
UserBusiness::forceCreate([
|
|
'user_id' => $user->id,
|
|
'month' => 6,
|
|
'year' => 2026,
|
|
'version' => 2,
|
|
'payline_points' => 350.5,
|
|
'qual_user_level' => ['paylines' => 3],
|
|
'commission_pp_total' => 10.0,
|
|
'commission_shop_sales' => 0.0,
|
|
'commission_growth_total' => 0.0,
|
|
]);
|
|
|
|
$snapshot = app(LiveCommissionService::class)->snapshot($user, 6, 2026);
|
|
|
|
expect($snapshot['payline_points'])->toBe(350.5)
|
|
->and($snapshot['paylines'])->toBe(3)
|
|
->and($snapshot['is_live'])->toBeFalse();
|
|
});
|
|
|
|
it('rendert die Provisions-Kachel auf der Monatsstatistik-Card', function (): void {
|
|
URL::resolveMissingNamedRoutesUsing(fn (string $name, $parameters = []) => '/'.$name);
|
|
|
|
$html = view('dashboard._statistics', [
|
|
'monthlyStats' => [
|
|
'month' => 7,
|
|
'year' => 2026,
|
|
'customer_points' => 100.0,
|
|
'team_payline_points' => 400.0,
|
|
'payline_is_live' => true,
|
|
'payline_forecast' => null,
|
|
'commission' => ['total' => 160.75, 'pp' => 120.5, 'shop' => 30.25, 'growth' => 10.0, 'is_live' => true],
|
|
'direct_new_partners' => 0,
|
|
'team_total_abos' => 0,
|
|
'team_partner_abos' => 0,
|
|
'team_partner_abos_new' => 0,
|
|
'team_customer_abos' => 0,
|
|
'team_customer_abos_new' => 0,
|
|
'shop_1000' => 0,
|
|
'new_partners' => 0,
|
|
'own_abos' => 0,
|
|
'own_abos_new' => 0,
|
|
'own_customer_abos' => 0,
|
|
'own_customer_abos_new' => 0,
|
|
],
|
|
])->render();
|
|
|
|
expect($html)
|
|
->toContain(__('home.commission_today'))
|
|
->toContain('160,75 €');
|
|
});
|