diff --git a/app/Http/Controllers/Admin/Inventory/ProductStockController.php b/app/Http/Controllers/Admin/Inventory/ProductStockController.php index 70b001f..fd31e5b 100644 --- a/app/Http/Controllers/Admin/Inventory/ProductStockController.php +++ b/app/Http/Controllers/Admin/Inventory/ProductStockController.php @@ -96,6 +96,8 @@ class ProductStockController extends Controller return redirect()->route('admin.inventory.product-stock.index'); } + private const HISTORY_LIMIT = 500; + public function history(Request $request): View { $query = ProductStockMovement::query() @@ -124,10 +126,16 @@ class ProductStockController extends Controller } } - $movements = $query->limit(500)->get(); + // Prüfung 08.09.2026 F-13: Kappung sichtbar machen (Gesamtzahl + „Alle anzeigen“), + // statt ältere Buchungen still abzuschneiden — wie bei Produktion/Einkauf. + $limit = $request->boolean('all') ? null : self::HISTORY_LIMIT; + $listTotal = (clone $query)->count(); + $movements = ($limit !== null ? $query->limit($limit) : $query)->get(); return view('admin.inventory.product-stock.history', [ 'movements' => $movements, + 'listLimit' => $limit, + 'listTotal' => $listTotal, 'products' => Product::query()->orderBy('name')->get(['id', 'name']), 'reasonOptions' => ProductStockMovement::query()->distinct()->orderBy('reason')->pluck('reason')->filter()->values(), 'filters' => [ diff --git a/resources/views/admin/inventory/product-stock/history.blade.php b/resources/views/admin/inventory/product-stock/history.blade.php index ceebbde..bc51ef4 100644 --- a/resources/views/admin/inventory/product-stock/history.blade.php +++ b/resources/views/admin/inventory/product-stock/history.blade.php @@ -126,6 +126,14 @@ + @if(($listLimit ?? null) !== null && ($listTotal ?? 0) > $listLimit) +

+ {{ __('Es werden die neuesten :n von :total Buchungen angezeigt.', ['n' => $listLimit, 'total' => $listTotal]) }} + {{ __('Alle anzeigen') }} +

+ @elseif(isset($listTotal)) +

{{ __(':total Buchungen', ['total' => $listTotal]) }}

+ @endif @endsection diff --git a/tests/Feature/ProductStockTest.php b/tests/Feature/ProductStockTest.php index bd6909f..cd8b8bc 100644 --- a/tests/Feature/ProductStockTest.php +++ b/tests/Feature/ProductStockTest.php @@ -285,3 +285,29 @@ test('F-12: verkaufs-gegenbuchungen werden im monatsverbrauch netto verrechnet', expect($service->monthlyConsumptionByProduct([$product->id])[$product->id])->toBe(10.0); }); + +test('F-13: produkthistorie zeigt die kappung mit gesamtzahl und bietet alle anzeigen', function () { + $user = ap11MakeUser(1); + $product = ap11MakeProduct('F13-Historie'); + $service = app(ProductStockService::class); + $service->recordMovement($product, 'in', 1, 'Initialbestand', 'manual', 'F13-ERSTE-BUCHUNG'); + $rows = []; + for ($i = 0; $i < 501; $i++) { + $rows[] = ['product_id' => $product->id, 'direction' => 'out', 'quantity' => 1, 'reason' => 'Verkauf', 'source' => 'sale', 'created_at' => now()->addSeconds($i), 'updated_at' => now()]; + } + foreach (array_chunk($rows, 100) as $chunk) { + ProductStockMovement::query()->insert($chunk); + } + + $this->actingAs($user, 'user'); + $this->get(route('admin.inventory.product-stock.history', ['product_id' => $product->id])) + ->assertOk() + ->assertSee('Es werden die neuesten 500 von 502 Buchungen angezeigt.') + ->assertSee('Alle anzeigen') + ->assertDontSee('F13-ERSTE-BUCHUNG'); + + $this->get(route('admin.inventory.product-stock.history', ['product_id' => $product->id, 'all' => 1])) + ->assertOk() + ->assertSee('502 Buchungen') + ->assertSee('F13-ERSTE-BUCHUNG'); +});