From 955dc9fe420cdbeb58d1dffaf88405e1db0a6d07 Mon Sep 17 00:00:00 2001 From: Roberto Guido Date: Mon, 2 Oct 2023 17:05:06 +0200 Subject: [PATCH] fix calcolo statistiche su prenotazioni. ref #187 --- code/app/Http/Controllers/StatisticsController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/code/app/Http/Controllers/StatisticsController.php b/code/app/Http/Controllers/StatisticsController.php index 503b2274..7cea362f 100644 --- a/code/app/Http/Controllers/StatisticsController.php +++ b/code/app/Http/Controllers/StatisticsController.php @@ -114,7 +114,7 @@ private function getSummary($start, $end, $type, $target) })->join('bookings', 'booked_products.booking_id', '=', 'bookings.id')->join('orders', 'bookings.order_id', '=', 'orders.id')->groupBy('orders.supplier_id'); if ($type == 'all') { - $data_for_suppliers_query->selectRaw('orders.supplier_id, SUM(price) as price')->join('products', 'booked_products.product_id', '=', 'products.id'); + $data_for_suppliers_query->selectRaw('orders.supplier_id, SUM(price * booked_products.quantity) as price')->join('products', 'booked_products.product_id', '=', 'products.id'); } else { $data_for_suppliers_query->selectRaw('orders.supplier_id, SUM(final_price) as price'); @@ -159,11 +159,13 @@ private function getSummary($start, $end, $type, $target) $this->createBookingQuery($query, $type, $start, $end, $target, null); })->join('products', 'booked_products.product_id', '=', 'products.id')->groupBy('product_id', 'category_id')->get(); + $all_categories = Category::all(); + foreach($data_for_categories as $dfc) { $category_id = $dfc->category_id; if (!isset($categories[$category_id])) { - $category = Category::find($category_id); + $category = $all_categories->find($category_id); $categories[$category_id] = (object) [ 'value' => 0, 'name' => $category->printableName(),