Wer Ende August registriert und am 1. September bezahlt hat, tauchte in keiner
Neupartner-Zaehlung auf: Der August-Snapshot wurde um 04:45 eingefroren, da
fehlte noch das Abrechnungskonto; im September lag active_date im falschen
Monat. Betroffen sind 2026 acht Partner, auch im Recruiting ihrer Sponsoren.
Kundenentscheidung 16.09.2026: der Zeitpunkt der Zahlung ist massgeblich.
Neue Spalte users.partner_paid_at, gesetzt bei der ersten Kontozahlung
(Payment::paymentStatusPaidAction) und bei manueller Freischaltung durch den
Admin — nur, solange sie leer ist; Verlaengerung und Wiederherstellung aendern
sie nicht. Bestehende Partner werden per Migration aus der ersten bezahlten
Registrierungsbestellung rueckgefuellt (Zeitstempel der Punktebuchung, ersatzweise
Bestelldatum, ohne Bestellung das Aktivierungsdatum). Bewusst nicht
payment_account minus ein Jahr: das ergaebe bei Verlaengerern den Jahrestag der
Erstzahlung.
User::scopeNewPartnerIn() und isNewPartnerIn() lesen jetzt partner_paid_at —
damit Kachel, Recruiter-Ranking, Top 3 und Neupartner-Liste gleichermassen.
Die Liste und der CSV-Export zeigen "Bezahlt am" neben "Registriert am".
Unveraendert: die Teamstruktur haengt weiter an active_date (auch im
Provisionsbaum). Wer ist neu dazugekommen und wer gehoert zur Linie sind zwei
verschiedene Fragen.
Die eingefrorenen Monate Januar bis August enthalten sieben dieser Partner
nicht; ob sie per --force neu gebaut werden, ist eine Entscheidung — siehe
dev/2026-07-22/neupartner-zahlungsmonat.md.
Mit drin: die handgebaute SQLite-Tabelle in BackofficeDashboardServiceTest
kannte status_reason aus d6efe56 noch nicht.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
163 lines
5.5 KiB
PHP
163 lines
5.5 KiB
PHP
<?php
|
|
|
|
use App\Models\UserAbo;
|
|
use App\Models\UserSalesVolume;
|
|
use App\Services\Backoffice\BackofficeDashboardService;
|
|
use App\Services\Backoffice\BackofficeDrilldownService;
|
|
use App\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
// September laeuft, August ist abgeschlossen.
|
|
Carbon::setTestNow('2026-09-15 10:00:00');
|
|
});
|
|
|
|
afterEach(fn () => Carbon::setTestNow());
|
|
|
|
function freezeUser(?int $sponsor = null): User
|
|
{
|
|
return User::forceCreate([
|
|
'email' => 'freeze-'.uniqid('', true).'@example.test',
|
|
'password' => bcrypt('secret'),
|
|
'lang' => 'de',
|
|
'm_level' => 1,
|
|
'm_sponsor' => $sponsor,
|
|
'active_date' => '2026-01-01',
|
|
'partner_paid_at' => '2026-01-01',
|
|
'payment_account' => '2027-01-01',
|
|
]);
|
|
}
|
|
|
|
function freezeVolume(User $user, float $points, int $month = 8): UserSalesVolume
|
|
{
|
|
return UserSalesVolume::forceCreate([
|
|
'user_id' => $user->id,
|
|
'month' => $month,
|
|
'year' => 2026,
|
|
'date' => '2026-0'.$month.'-05',
|
|
'points' => $points,
|
|
'total_net' => $points,
|
|
'status' => 1,
|
|
'status_points' => 1,
|
|
'status_turnover' => 1,
|
|
]);
|
|
}
|
|
|
|
function freezeAbo(User $member, string $isFor = 'ot', string $startDate = '2026-08-05'): UserAbo
|
|
{
|
|
return UserAbo::create([
|
|
'user_id' => $member->id,
|
|
'member_id' => $member->id,
|
|
'shopping_user_id' => 0,
|
|
'email' => 'a-'.uniqid('', true).'@example.test',
|
|
'is_for' => $isFor,
|
|
'payone_userid' => 0,
|
|
'clearingtype' => 'cc',
|
|
'amount' => 5000,
|
|
'active' => true,
|
|
'status' => 2,
|
|
'abo_interval' => 5,
|
|
'start_date' => $startDate,
|
|
'next_date' => '2026-10-05',
|
|
]);
|
|
}
|
|
|
|
it('haelt Punkte eines abgeschlossenen Monats nach einer spaeteren Korrektur fest', function () {
|
|
$root = freezeUser();
|
|
$anna = freezeUser($root->id);
|
|
$volume = freezeVolume($anna, 100);
|
|
|
|
app(BackofficeDashboardService::class)->storeSnapshot($root, 8, 2026);
|
|
|
|
$volume->update(['points' => 500]);
|
|
|
|
$overview = app(BackofficeDashboardService::class)->overview($root, 8, 2026);
|
|
|
|
expect($overview['_meta']['source'])->toBe('snapshot')
|
|
->and((float) $overview['totals']['total_points'])->toBe(100.0);
|
|
});
|
|
|
|
it('haelt auch die Abo-Bestaende und Ranglisten fest', function () {
|
|
$root = freezeUser();
|
|
$anna = freezeUser($root->id);
|
|
$abo = freezeAbo($anna);
|
|
|
|
app(BackofficeDashboardService::class)->storeSnapshot($root, 8, 2026);
|
|
|
|
// Kuendigung im September darf den August nicht mehr veraendern.
|
|
$abo->update(['active' => false, 'status' => 4, 'cancel_date' => '2026-09-10']);
|
|
|
|
$overview = app(BackofficeDashboardService::class)->overview($root, 8, 2026);
|
|
|
|
expect((int) $overview['totals']['team_customer_abos'])->toBe(1);
|
|
});
|
|
|
|
it('laesst einen spaeter dazugekommenen Teampartner aus dem abgeschlossenen Monat heraus', function () {
|
|
$root = freezeUser();
|
|
$anna = freezeUser($root->id);
|
|
freezeVolume($anna, 100);
|
|
|
|
app(BackofficeDashboardService::class)->storeSnapshot($root, 8, 2026);
|
|
|
|
// Neuer Teampartner im September, mit einer Buchung, die im August liegt
|
|
// (z. B. nachtraeglich zugeordnet) — der abgeschlossene Monat bleibt unberuehrt.
|
|
$spaeter = freezeUser($root->id);
|
|
freezeVolume($spaeter, 999);
|
|
app(BackofficeDashboardService::class)->flushLineBucketsMemo($root->id);
|
|
|
|
$overview = app(BackofficeDashboardService::class)->overview($root, 8, 2026);
|
|
$details = app(BackofficeDrilldownService::class)->details($root, 0, 'total_points', 8, 2026);
|
|
|
|
expect((float) $overview['totals']['total_points'])->toBe(100.0)
|
|
->and($details['summary']['total_points'])->toBe(100.0)
|
|
->and($details['rows'])->toHaveCount(1)
|
|
->and($details['rows'][0]['user_id'])->toBe($anna->id);
|
|
});
|
|
|
|
it('zeigt in der Abo-Detailliste genau die eingefrorenen Abos', function () {
|
|
$root = freezeUser();
|
|
$anna = freezeUser($root->id);
|
|
$abo = freezeAbo($anna);
|
|
|
|
app(BackofficeDashboardService::class)->storeSnapshot($root, 8, 2026);
|
|
|
|
$abo->update(['active' => false, 'status' => 4, 'cancel_date' => '2026-09-10']);
|
|
$abo->delete();
|
|
|
|
$details = app(BackofficeDrilldownService::class)->details($root, 0, 'team_customer_abos', 8, 2026);
|
|
|
|
expect($details['summary']['abo_count'])->toBe(1);
|
|
});
|
|
|
|
it('haelt Kachel und verlinkte Liste der neuen Abos zusammen', function () {
|
|
$root = freezeUser();
|
|
$anna = freezeUser($root->id);
|
|
$abo = freezeAbo($anna, 'ot', '2026-08-20'); // neu im August
|
|
|
|
app(BackofficeDashboardService::class)->storeSnapshot($root, 8, 2026);
|
|
|
|
$abo->update(['active' => false, 'status' => 4, 'cancel_date' => '2026-09-08']);
|
|
|
|
$overview = app(BackofficeDashboardService::class)->overview($root, 8, 2026);
|
|
$details = app(BackofficeDrilldownService::class)->details($root, 0, 'team_customer_abos', 8, 2026, true);
|
|
|
|
expect((int) $overview['totals']['team_customer_abos_new'])->toBe(1)
|
|
->and($details['summary']['abo_count'])->toBe(1);
|
|
});
|
|
|
|
it('rechnet den laufenden Monat weiterhin live', function () {
|
|
$root = freezeUser();
|
|
$anna = freezeUser($root->id);
|
|
$volume = freezeVolume($anna, 100, 9);
|
|
|
|
$volume->update(['points' => 500]);
|
|
|
|
$overview = app(BackofficeDashboardService::class)->overview($root, 9, 2026);
|
|
|
|
expect($overview['_meta']['source'])->toBe('live')
|
|
->and((float) $overview['totals']['total_points'])->toBe(500.0);
|
|
});
|