Skip to content

Commit

Permalink
fix calcolo statistiche su prenotazioni. ref #187
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Oct 2, 2023
1 parent 8037bdc commit 955dc9f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions code/app/Http/Controllers/StatisticsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 955dc9f

Please sign in to comment.