mivita/tests/Feature/BusinessStoreOptimized/AssignMonthlyQualKpBonusPointsTest.php
Kevin ac3bd6e8ea Statistiken/Abo: Kundenfeedback 2026-07-24 komplett umgesetzt + Steuern: DATEV-Fixes 08+09/2025 (Sammel-Commit Branch-WIP)
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>
2026-07-24 13:56:02 +00:00

121 lines
3.2 KiB
PHP

<?php
use App\Console\Commands\BusinessStoreOptimized;
use App\Models\UserLevel;
use App\Models\UserSalesVolume;
use App\User;
use Illuminate\Console\OutputStyle;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Tests\TestCase;
uses(TestCase::class, RefreshDatabase::class);
function makeCommand(): BusinessStoreOptimized
{
$command = new BusinessStoreOptimized;
$input = new ArrayInput([]);
$output = new OutputStyle($input, new NullOutput);
$command->setOutput($output);
return $command;
}
function callAssignMethod(BusinessStoreOptimized $command): void
{
$method = (new ReflectionClass($command))->getMethod('assignMonthlyQualKpBonusPoints');
$method->setAccessible(true);
$method->invoke($command);
}
function makeUserLevel(int $qualKp, int $pos = 7): UserLevel
{
return UserLevel::create([
'name' => 'Test Level '.$pos,
'qual_kp' => $qualKp,
'active' => 1,
'pos' => $pos,
'default' => 0,
]);
}
function makeLevelUser(int $levelId, ?int $forceId = null): User
{
$attributes = [
'email' => fake()->unique()->safeEmail(),
'password' => bcrypt('secret'),
'lang' => 'de',
'm_level' => $levelId,
];
if ($forceId !== null) {
$attributes['id'] = $forceId;
}
return User::forceCreate($attributes);
}
it('assigns qual_kp points to user 486 when their level has qual_kp > 0', function () {
$level = makeUserLevel(690);
makeLevelUser($level->id, 486);
callAssignMethod(makeCommand());
expect(UserSalesVolume::where('user_id', 486)
->where('month', date('m'))
->where('year', date('Y'))
->where('info', 'qual_kp_bonus')
->where('points', 690)
->exists()
)->toBeTrue();
});
it('does not assign bonus points to users not in the bonus list', function () {
$level = makeUserLevel(690);
$otherUser = makeLevelUser($level->id);
callAssignMethod(makeCommand());
expect(UserSalesVolume::where('user_id', $otherUser->id)->where('info', 'qual_kp_bonus')->exists())
->toBeFalse();
});
it('skips user 486 when their level has qual_kp of zero', function () {
$level = makeUserLevel(0);
makeLevelUser($level->id, 486);
callAssignMethod(makeCommand());
expect(UserSalesVolume::where('user_id', 486)->where('info', 'qual_kp_bonus')->exists())
->toBeFalse();
});
it('skips user 486 when they have no level assigned', function () {
User::forceCreate([
'id' => 486,
'email' => fake()->unique()->safeEmail(),
'password' => bcrypt('secret'),
'lang' => 'de',
'm_level' => null,
]);
callAssignMethod(makeCommand());
expect(UserSalesVolume::where('user_id', 486)->where('info', 'qual_kp_bonus')->exists())
->toBeFalse();
});
it('is idempotent and does not create duplicate entries for the same month', function () {
$level = makeUserLevel(690);
makeLevelUser($level->id, 486);
$command = makeCommand();
callAssignMethod($command);
callAssignMethod($command);
expect(UserSalesVolume::where('user_id', 486)
->where('info', 'qual_kp_bonus')
->count()
)->toBe(1);
});