_checkProjects(); if (!$projects->count()) { return $this->error($this->noProjects); } $project_id = request()->project_id ?? $projects->first()->id; $project = Project::find($project_id); $month = request()->month ?? date("Y-m"); $months = (new StatisticsController())->_getMonths(); $start_timestamp = strtotime($month); $end_timestamp = strtotime("+1 month", strtotime($month)); $this->model = $this->model->whereRaw("UNIX_TIMESTAMP(`created_at`) >= " . $start_timestamp . " and UNIX_TIMESTAMP(`created_at`) < " . $end_timestamp); $this->model = $this->model->where("project_id", $project_id); $data = $this->model ->with([ "orderItems", "firstItem", "lastItem", "project", "product", "customer", "manager", "bed" => function ($query) { $query->with(["room", "building"]); } ]) ->orderBy("id", "desc") ->paginate(10); foreach ($data as $order) { $order = $order->refreshTotal(); } return view($this->bladePath . ".index", compact("data", "project_id", "month", "project")); } }