'reports', 'title' => 'Отчёты', 'id' => 'reports', ]; public function index() { $doneStatuses = [5, 7, 8, 9, 10]; $objectTypes = ObjectType::query()->get()->pluck('name', 'id')->toArray(); $this->data['objectTypes'] = $objectTypes; $this->data['totalOrders'] = Order::all()->count(); $this->data['doneOrders'] = Order::query()->whereIn('order_status_id', [9, 10])->count(); $this->data['totalMafs'] = ProductSKU::all()->count(); $this->data['doneMafs'] = ProductSKU::query()-> whereHas('order', function ($query) { $query->whereIn('order_status_id', [9, 10]); })->count(); $this->data['totalSum'] = Price::format( ProductSKU::query()-> whereHas('order', function ($query) use ($doneStatuses) { $query->whereIn('order_status_id', $doneStatuses); }) ->withSum('product', 'total_price') ->get() ->sum('product_sum_total_price') ); foreach ($objectTypes as $objectTypeId => $objectType) { // total by types $this->data['totalOrdersType'][$objectTypeId] = Order::where('object_type_id', '=', $objectTypeId)->count(); $this->data['totalMafsType'][$objectTypeId] = ProductSKU::query()-> whereHas('order', function ($query) use ($objectTypeId) { $query->where('object_type_id', '=', $objectTypeId); })->count(); // со статусами: в монтаже, готова к сдаче, не сдана замечания, сдана замечания, сдана - зеленый цвет $this->data['doneOrdersType'][$objectTypeId] = Order::query() ->where('object_type_id', '=', $objectTypeId) ->whereIn('order_status_id', $doneStatuses) ->count(); $this->data['doneMafsType'][$objectTypeId] = ProductSKU::query()-> whereHas('order', function ($query) use ($objectTypeId, $doneStatuses) { $query->where('object_type_id', '=', $objectTypeId) ->whereIn('order_status_id', $doneStatuses); })->count(); // остальные - не готовы $this->data['notDoneOrdersType'][$objectTypeId] = Order::query() ->where('object_type_id', '=', $objectTypeId) ->whereNotIn('order_status_id', $doneStatuses) ->count(); $this->data['notDoneMafsType'][$objectTypeId] = ProductSKU::query()-> whereHas('order', function ($query) use ($objectTypeId, $doneStatuses) { $query->where('object_type_id', '=', $objectTypeId) ->whereNotIn('order_status_id', $doneStatuses); })->count(); } return view('reports.index', $this->data); } }