diff --git a/app/Http/Controllers/App/InventorySerialController.php b/app/Http/Controllers/App/InventorySerialController.php index 18179d0..055954e 100644 --- a/app/Http/Controllers/App/InventorySerialController.php +++ b/app/Http/Controllers/App/InventorySerialController.php @@ -32,10 +32,13 @@ public function index(Inventory $inventario, Request $request) if ($request->has('warehouse_id')) { $query->where('warehouse_id', $request->warehouse_id); - } else { + } elseif ($request->boolean('main_warehouse')) { $mainWarehouse = Warehouse::where('is_main', true)->first(); if ($mainWarehouse) { - $query->where('warehouse_id', $mainWarehouse->id); + $query->where(function ($q) use ($mainWarehouse) { + $q->where('warehouse_id', $mainWarehouse->id) + ->orWhereNull('warehouse_id'); + }); } } diff --git a/app/Services/SaleService.php b/app/Services/SaleService.php index 86a836d..95ee174 100644 --- a/app/Services/SaleService.php +++ b/app/Services/SaleService.php @@ -134,7 +134,7 @@ public function createSale(array $data) ->first(); if ($serial) { - $serial->markAsSold($saleDetail->id); + $serial->markAsSold($saleDetail->id, $serialWarehouseId); } else { throw new \Exception("Serial {$serialNumber} no disponible en el almacén"); } @@ -152,7 +152,7 @@ public function createSale(array $data) } foreach ($serials as $serial) { - $serial->markAsSold($saleDetail->id); + $serial->markAsSold($saleDetail->id, $serialWarehouseId); } }