<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\StockMovement;
use Illuminate\Http\Request;

class AdminStockMovementController extends Controller
{
    public function index(Request $request)
    {
        $query = StockMovement::with('product.category')->orderByDesc('created_at');

        if ($request->filled('product_id')) {
            $query->where('product_id', $request->product_id);
        }
        if ($request->filled('type')) {
            $query->where('type', $request->type);
        }

        $movements = $query->paginate(20)->withQueryString();

        return view('admin.stock-movements.index', compact('movements'));
    }
}
