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>
156 lines
5.4 KiB
PHP
156 lines
5.4 KiB
PHP
<?php
|
||
|
||
use App\Http\Controllers\Api\ShoppingUserController;
|
||
use App\Models\Country;
|
||
use App\Models\Product;
|
||
use App\Models\Shipping;
|
||
use App\Models\ShippingCountry;
|
||
use App\Models\ShippingPrice;
|
||
use App\Models\ShoppingUser;
|
||
use App\Models\UserAccount;
|
||
use App\Models\UserShop;
|
||
use App\User;
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Illuminate\Support\Facades\Mail;
|
||
use Tests\TestCase;
|
||
|
||
uses(TestCase::class, RefreshDatabase::class);
|
||
|
||
/**
|
||
* Versandumgebung für API-Bestellungen: DE mit Gewichtsstufe 1–1000 g (4,90 €)
|
||
* und optionalem Versandkostenfrei-Schwellenwert auf der Shipping-Konfiguration.
|
||
*/
|
||
function makeApiShopEnv(?int $freeThreshold): array
|
||
{
|
||
$country = Country::create([
|
||
'code' => 'DE', 'phone' => '49', 'en' => 'Germany', 'de' => 'Deutschland',
|
||
'es' => 'Alemania', 'fr' => 'Allemagne', 'it' => 'Germania', 'ru' => 'Германия',
|
||
]);
|
||
$shipping = Shipping::create(['name' => 'DEUTSCHLAND', 'active' => true, 'free' => $freeThreshold ?? '']);
|
||
ShippingPrice::create([
|
||
'shipping_id' => $shipping->id, 'price' => 4.90, 'price_comp' => 0, 'num_comp' => 0,
|
||
'tax_rate' => 19, 'weight_from' => 1, 'weight_to' => 1000,
|
||
]);
|
||
$shippingCountry = ShippingCountry::create(['shipping_id' => $shipping->id, 'country_id' => $country->id]);
|
||
|
||
return [$country, $shippingCountry];
|
||
}
|
||
|
||
function makeApiOrderEnv(?int $freeThreshold = 80): ShoppingUser
|
||
{
|
||
[$country] = makeApiShopEnv($freeThreshold);
|
||
|
||
$account = UserAccount::create(['m_first_name' => 'Mia', 'm_last_name' => 'Vita', 'country_id' => $country->id]);
|
||
$member = User::forceCreate([
|
||
'email' => 'member-'.uniqid('', true).'@example.com',
|
||
'password' => bcrypt('secret'),
|
||
'lang' => 'de',
|
||
'account_id' => $account->id,
|
||
]);
|
||
UserShop::create(['user_id' => $member->id, 'name' => 'Shop-'.uniqid('', true), 'active' => true]);
|
||
|
||
$apiUser = User::forceCreate([
|
||
'email' => 'api-'.uniqid('', true).'@example.com',
|
||
'password' => bcrypt('secret'),
|
||
'lang' => 'de',
|
||
'm_sponsor' => $member->id,
|
||
]);
|
||
test()->actingAs($apiUser);
|
||
|
||
return ShoppingUser::create([
|
||
'member_id' => $member->id,
|
||
'auth_user_id' => 0,
|
||
'number' => 1,
|
||
'billing_firstname' => 'Max',
|
||
'billing_lastname' => 'Muster',
|
||
'billing_address' => 'Musterstr. 1',
|
||
'billing_zipcode' => '12345',
|
||
'billing_city' => 'Berlin',
|
||
'billing_country_id' => $country->id,
|
||
'billing_email' => 'kunde@example.com',
|
||
'shipping_country_id' => $country->id,
|
||
'same_as_billing' => true,
|
||
'wp_order_number' => 424242,
|
||
'mode' => 'dev',
|
||
]);
|
||
}
|
||
|
||
function makeApiProduct(float $price, int $weight = 500, bool $noFreeShipping = false): Product
|
||
{
|
||
$now = now();
|
||
$id = (int) DB::table('products')->insertGetId([
|
||
'name' => 'P-'.uniqid('', true),
|
||
'title' => 'Produkt',
|
||
'active' => true,
|
||
'price' => $price,
|
||
'tax' => 19,
|
||
'weight' => $weight,
|
||
'points' => 7,
|
||
'wp_number' => random_int(10000, 99999999),
|
||
'no_free_shipping' => $noFreeShipping,
|
||
'show_on' => json_encode(['2']),
|
||
'created_at' => $now,
|
||
'updated_at' => $now,
|
||
]);
|
||
|
||
return Product::findOrFail($id);
|
||
}
|
||
|
||
function callApiPrepareOrder(ShoppingUser $shoppingUser, array $items): void
|
||
{
|
||
Mail::fake();
|
||
$wpOrder = array_map(fn (Product $product) => [
|
||
'article' => $product->wp_number,
|
||
'qty' => 1,
|
||
'price' => (int) round($product->price * 100),
|
||
], $items);
|
||
|
||
$method = new ReflectionMethod(ShoppingUserController::class, 'prepareOrder');
|
||
$method->invoke(new ShoppingUserController, $wpOrder, $shoppingUser, null, []);
|
||
}
|
||
|
||
describe('API-Bestellung Versandkostenfrei-Schwellenwert', function () {
|
||
it('berechnet keine Versandkosten, wenn der Schwellenwert (DE 80 €) erreicht ist', function () {
|
||
$shoppingUser = makeApiOrderEnv(80);
|
||
$product = makeApiProduct(80.00);
|
||
|
||
callApiPrepareOrder($shoppingUser, [$product]);
|
||
|
||
$order = $shoppingUser->shopping_orders()->first();
|
||
expect((float) $order->shipping)->toBe(0.0)
|
||
->and((float) $order->total_shipping)->toBe(80.0);
|
||
});
|
||
|
||
it('berechnet Versandkosten, wenn der Schwellenwert nicht erreicht ist', function () {
|
||
$shoppingUser = makeApiOrderEnv(80);
|
||
$product = makeApiProduct(79.00);
|
||
|
||
callApiPrepareOrder($shoppingUser, [$product]);
|
||
|
||
$order = $shoppingUser->shopping_orders()->first();
|
||
expect((float) $order->shipping)->toBe(4.90)
|
||
->and((float) $order->total_shipping)->toBe(83.90);
|
||
});
|
||
|
||
it('berechnet Versandkosten, wenn kein Schwellenwert konfiguriert ist', function () {
|
||
$shoppingUser = makeApiOrderEnv(null);
|
||
$product = makeApiProduct(200.00);
|
||
|
||
callApiPrepareOrder($shoppingUser, [$product]);
|
||
|
||
$order = $shoppingUser->shopping_orders()->first();
|
||
expect((float) $order->shipping)->toBe(4.90);
|
||
});
|
||
|
||
it('berechnet Versandkosten nach Gewicht der no_free_shipping-Produkte trotz erreichtem Schwellenwert', function () {
|
||
$shoppingUser = makeApiOrderEnv(80);
|
||
$normal = makeApiProduct(80.00);
|
||
$excluded = makeApiProduct(20.00, 500, true);
|
||
|
||
callApiPrepareOrder($shoppingUser, [$normal, $excluded]);
|
||
|
||
$order = $shoppingUser->shopping_orders()->first();
|
||
expect((float) $order->shipping)->toBe(4.90);
|
||
});
|
||
});
|