Statistiken: Kundenfeedback 2026-08-19 komplett (N1-N8) + Review-Fixes + VP-/Incentive-Repair gehärtet
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>
This commit is contained in:
parent
841d87e161
commit
867dc21b57
87 changed files with 4480 additions and 240 deletions
|
|
@ -11,6 +11,7 @@ use App\Models\ShippingCountry;
|
|||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingOrderItem;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Models\UserShop;
|
||||
use App\Services\Incentive\IncentivePointsLogRepairService;
|
||||
use App\Services\Incentive\IncentiveTracker;
|
||||
|
|
@ -188,6 +189,25 @@ it('trackNewPartner zaehlt Bestellungen am letzten Tag des Qualifikationszeitrau
|
|||
expect(IncentiveNewPartner::where('user_id', $partner->id)->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
it('syncMissingTrackingPartners zaehlt Bestellungen am letzten Tag des Qualifikationszeitraums (Randtag-Fall)', function () {
|
||||
Carbon::setTestNow(Carbon::parse('2026-08-01 04:00:00'));
|
||||
|
||||
$incentive = repairTestCreateIncentive();
|
||||
$sponsor = repairTestCreateUser();
|
||||
$participant = IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $sponsor->id,
|
||||
]);
|
||||
|
||||
$partner = repairTestCreateUser($sponsor->id);
|
||||
repairTestCreateStarterKitOrder($partner, $sponsor, '2026-07-31 23:15:00');
|
||||
|
||||
$added = app(IncentivePointsLogRepairService::class)->syncMissingTrackingPartners($participant);
|
||||
|
||||
expect($added)->toBe(1)
|
||||
->and(IncentiveNewPartner::where('participant_id', $participant->id)->where('user_id', $partner->id)->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
it('removeStaleSponsorTrackings verschiebt Partner nach Sponsorwechsel zum aktuellen Sponsor', function () {
|
||||
$incentive = repairTestCreateIncentive();
|
||||
|
||||
|
|
@ -246,6 +266,145 @@ it('removeStaleSponsorTrackings verschiebt Partner nach Sponsorwechsel zum aktue
|
|||
expect((int) $participantNew->fresh()->qualified_partners)->toBe(1);
|
||||
});
|
||||
|
||||
it('removeStaleSponsorTrackings behaelt Tracking und Punkte-Logs bei leerem Sponsor (m_sponsor = NULL)', function () {
|
||||
$incentive = repairTestCreateIncentive();
|
||||
$sponsor = repairTestCreateUser();
|
||||
$participant = IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $sponsor->id,
|
||||
]);
|
||||
|
||||
$partner = repairTestCreateUser($sponsor->id);
|
||||
$tracking = IncentiveNewPartner::create([
|
||||
'participant_id' => $participant->id,
|
||||
'user_id' => $partner->id,
|
||||
'registered_at' => Carbon::parse('2026-05-10 09:00:00'),
|
||||
]);
|
||||
IncentivePointsLog::create([
|
||||
'participant_id' => $participant->id,
|
||||
'type' => 'partner',
|
||||
'source_type' => User::class,
|
||||
'source_id' => $partner->id,
|
||||
'source_label' => 'Partner',
|
||||
'month' => 5,
|
||||
'year' => 2026,
|
||||
'points_onetime' => 600,
|
||||
'points_accumulated' => 0,
|
||||
'incentive_new_partner_id' => $tracking->id,
|
||||
]);
|
||||
|
||||
// Admin-Umbau in Arbeit: Sponsor temporaer entfernt — kein Sponsorwechsel
|
||||
$partner->m_sponsor = null;
|
||||
$partner->save();
|
||||
|
||||
$removed = app(IncentivePointsLogRepairService::class)->removeStaleSponsorTrackings($participant);
|
||||
|
||||
expect($removed)->toBe(0)
|
||||
->and(IncentiveNewPartner::where('participant_id', $participant->id)->where('user_id', $partner->id)->exists())->toBeTrue()
|
||||
->and(IncentivePointsLog::where('participant_id', $participant->id)->count())->toBe(1);
|
||||
|
||||
$participant->recalculateFromTrackingTables()->save();
|
||||
expect((int) $participant->fresh()->total_points)->toBe(600);
|
||||
});
|
||||
|
||||
it('removeStaleSponsorTrackings behaelt Trackings geloeschter User (wie bisher)', function () {
|
||||
$incentive = repairTestCreateIncentive();
|
||||
$sponsor = repairTestCreateUser();
|
||||
$participant = IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $sponsor->id,
|
||||
]);
|
||||
|
||||
$partner = repairTestCreateUser($sponsor->id);
|
||||
IncentiveNewPartner::create([
|
||||
'participant_id' => $participant->id,
|
||||
'user_id' => $partner->id,
|
||||
'registered_at' => now(),
|
||||
]);
|
||||
|
||||
$partner->delete();
|
||||
|
||||
$removed = app(IncentivePointsLogRepairService::class)->removeStaleSponsorTrackings($participant);
|
||||
|
||||
expect($removed)->toBe(0)
|
||||
->and(IncentiveNewPartner::where('participant_id', $participant->id)->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
it('incentive:calculate repariert FKs vor der Stale-Bereinigung — keine Waisen-Logs beim alten Sponsor nach Umhaengen', function () {
|
||||
$incentive = repairTestCreateIncentive();
|
||||
|
||||
$oldSponsor = repairTestCreateUser();
|
||||
$newSponsor = repairTestCreateUser();
|
||||
|
||||
$participantOld = IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $oldSponsor->id,
|
||||
]);
|
||||
$participantNew = IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $newSponsor->id,
|
||||
]);
|
||||
|
||||
// Partner wurde unter dem alten Sponsor getrackt, haengt inzwischen unter dem neuen
|
||||
$partner = repairTestCreateUser($newSponsor->id);
|
||||
repairTestCreateStarterKitOrder($partner, $newSponsor, '2026-05-10 09:00:00');
|
||||
|
||||
$staleTracking = IncentiveNewPartner::create([
|
||||
'participant_id' => $participantOld->id,
|
||||
'user_id' => $partner->id,
|
||||
'registered_at' => Carbon::parse('2026-05-10 09:00:00'),
|
||||
]);
|
||||
IncentivePointsLog::create([
|
||||
'participant_id' => $participantOld->id,
|
||||
'type' => 'partner',
|
||||
'source_type' => User::class,
|
||||
'source_id' => $partner->id,
|
||||
'source_label' => 'Partner',
|
||||
'month' => 5,
|
||||
'year' => 2026,
|
||||
'points_onetime' => 600,
|
||||
'points_accumulated' => 0,
|
||||
'incentive_new_partner_id' => $staleTracking->id,
|
||||
]);
|
||||
|
||||
// Umsatz-Log OHNE FK (Altbestand): ueberlebte frueher die Stale-Bereinigung als Waise
|
||||
$sv = UserSalesVolume::create([
|
||||
'user_id' => $partner->id,
|
||||
'month' => 5,
|
||||
'year' => 2026,
|
||||
'date' => '12.05.2026',
|
||||
'points' => 25,
|
||||
'total_net' => 90,
|
||||
'status_points' => 1,
|
||||
'status' => 2,
|
||||
'message' => 'SV 5/2026',
|
||||
]);
|
||||
IncentivePointsLog::create([
|
||||
'participant_id' => $participantOld->id,
|
||||
'type' => 'partner',
|
||||
'source_type' => UserSalesVolume::class,
|
||||
'source_id' => $sv->id,
|
||||
'source_label' => 'SV 5/2026',
|
||||
'month' => 5,
|
||||
'year' => 2026,
|
||||
'points_onetime' => 0,
|
||||
'points_accumulated' => 25,
|
||||
'user_sales_volume_id' => $sv->id,
|
||||
'incentive_new_partner_id' => null,
|
||||
]);
|
||||
|
||||
$this->artisan('incentive:calculate', ['incentive_id' => $incentive->id])->assertExitCode(0);
|
||||
|
||||
// Alter Sponsor: Tracking + ALLE Logs weg (auch der Waisen-Log ohne FK), Punkte 0
|
||||
expect(IncentiveNewPartner::where('participant_id', $participantOld->id)->exists())->toBeFalse()
|
||||
->and(IncentivePointsLog::where('participant_id', $participantOld->id)->count())->toBe(0)
|
||||
->and((int) $participantOld->fresh()->total_points)->toBe(0);
|
||||
|
||||
// Neuer Sponsor: Partner nachgezogen inkl. Einmal- und Umsatzpunkten (keine Doppelzaehlung)
|
||||
expect((int) $participantNew->fresh()->qualified_partners)->toBe(1)
|
||||
->and((int) $participantNew->fresh()->total_points)->toBe(625);
|
||||
});
|
||||
|
||||
it('removeStaleSponsorTrackings laesst korrekte Trackings unangetastet', function () {
|
||||
$incentive = repairTestCreateIncentive();
|
||||
$sponsor = repairTestCreateUser();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue