|
@@ -0,0 +1,39 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * Created by IntelliJ IDEA.
|
|
|
+ * User: kelyliang
|
|
|
+ * Date: 2024/3/4
|
|
|
+ * Time: 下午 03:09
|
|
|
+ */
|
|
|
+
|
|
|
+namespace App\Http\Resources\API;
|
|
|
+
|
|
|
+use App\Models\Asset;
|
|
|
+use App\Models\AssetGroup;
|
|
|
+use Carbon\Carbon;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
+
|
|
|
+class AssetReportResource extends JsonResource
|
|
|
+{
|
|
|
+ public function toArray(Request $request): array
|
|
|
+ {
|
|
|
+ $now = Carbon::now();
|
|
|
+ return[
|
|
|
+ 'requirement_total' => $this->requirements()->count(),
|
|
|
+ 'plan_total' => $this->plans()->count(),
|
|
|
+ 'prject_total' => $this->projects()->count(),
|
|
|
+ 'plan_unexpired_total' => $planTotalCount = $this->plans()->where('begin', '<=', $now)
|
|
|
+ ->where('end', '>=', $now)
|
|
|
+ ->get()
|
|
|
+ ->count(),
|
|
|
+ 'project_unexpired_total' => $planTotalCount = $this->projects()->where('begin', '<=', $now)
|
|
|
+ ->where('end', '>=', $now)
|
|
|
+ ->get()
|
|
|
+ ->count(),
|
|
|
+ 'asset_total'=>Asset::query()->where('company_id',Auth::user()->company_id)->where('parent_id',0)->count(),
|
|
|
+ 'asset_closed_total'=>Asset::query()->where('company_id',Auth::user()->company_id)->where('parent_id',0)->where('status','closed')->count(),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+}
|