cambio logica de productos pedidos
This commit is contained in:
parent
c2a59495be
commit
5703e92f8d
|
@ -117,20 +117,17 @@ private function armarColumnasPedido() : array {
|
|||
private function productosCantidadesPedidas() : array {
|
||||
return $this->pedidos()
|
||||
->where('confirmed',true)
|
||||
->with('products')
|
||||
->with('productos')
|
||||
->get()
|
||||
->flatMap(fn($order) => $order->products->map(
|
||||
fn($product) => [
|
||||
'product_id' => $product->id,
|
||||
'product_name' => $product->name,
|
||||
'total_ordered' => $product->pivot->quantity,
|
||||
->flatMap(fn($pedido) => $pedido->productos->map(
|
||||
fn($producto) => [
|
||||
'producto_id' => $producto->id,
|
||||
'cantidad' => $producto->pivot->cantidad,
|
||||
]
|
||||
))
|
||||
->groupBy('product_id')
|
||||
->map(fn($groupedProducts) => [
|
||||
'product_id' => $groupedProducts->first()['product_id'],
|
||||
'product_name' => $groupedProducts->first()['product_name'],
|
||||
'total_ordered' => $groupedProducts->sum('total_ordered'),
|
||||
->groupBy('producto_id')
|
||||
->map(fn($productosAgrupados) => [
|
||||
$productosAgrupados->first()['producto_id'] => $productosAgrupados->sum('cantidad'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue