Update GestionStockPage.php
This commit is contained in:
@@ -45,12 +45,32 @@ class GestionStockPage extends Page
|
||||
'categoria' => $producto->categoria->nombre ?? 'Sin categoría',
|
||||
'stock_actual' => $producto->getStockEfectivo(),
|
||||
'stock_minimo' => $producto->stock_minimo,
|
||||
'distribucion' => $producto->bodegas->map(function ($bodega) {
|
||||
return [
|
||||
'bodega' => $bodega->nombre,
|
||||
'stock' => $bodega->pivot->stock,
|
||||
];
|
||||
})->toArray(),
|
||||
'distribucion' => (function($producto) {
|
||||
// Productos con variantes: agregar stock por bodegas a partir de variantes
|
||||
if ($producto->variants()->exists()) {
|
||||
$bodegaTotals = [];
|
||||
foreach ($producto->variants as $variante) {
|
||||
foreach ($variante->bodegas as $bodega) {
|
||||
$id = $bodega->id;
|
||||
if (! isset($bodegaTotals[$id])) {
|
||||
$bodegaTotals[$id] = ['bodega' => $bodega->nombre, 'stock' => 0];
|
||||
}
|
||||
$bodegaTotals[$id]['stock'] += (int) ($bodega->pivot->stock ?? 0);
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($bodegaTotals);
|
||||
}
|
||||
|
||||
// Productos sin variantes: información directa desde producto_bodega
|
||||
return $producto->bodegas->map(function ($bodega) {
|
||||
return [
|
||||
'bodega' => $bodega->nombre,
|
||||
'stock' => $bodega->pivot->stock,
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
})($producto),
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
|
||||
Reference in New Issue
Block a user