From 102ba4664194a4b2ce79fa1817e00fa34014b675 Mon Sep 17 00:00:00 2001 From: brusnitsyn Date: Tue, 2 Jun 2026 08:41:19 +0900 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B8=D0=BD=D0=B4=D0=B8=D0=BA=D0=B0=D1=82=D0=BE?= =?UTF-8?q?=D1=80=20=D0=B7=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=81=D1=82=D0=B8=D0=BA?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/ReportDuty.php | 20 ++++++++++++++++++++ app/Services/StatisticsService.php | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/Models/ReportDuty.php b/app/Models/ReportDuty.php index b905645..9fb0596 100644 --- a/app/Models/ReportDuty.php +++ b/app/Models/ReportDuty.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; class ReportDuty extends Model @@ -25,6 +26,25 @@ class ReportDuty extends Model 'period_end' => 'datetime:Y-m-d H:i:s', ]; + public function scopeWithinPeriod(Builder $query, string $startAt, string $endAt): Builder + { + return $query + ->where('period_end', '>=', $startAt) + ->where('period_start', '<=', $endAt); + } + + public function scopeExactPeriod(Builder $query, string $startAt, string $endAt): Builder + { + return $query + ->where('period_start', '>=', $startAt) + ->where('period_end', '<=', $endAt); + } + + public function scopeOnlySubmitted(Builder $query): Builder + { + return $query->where('status_id', 2); + } + public function department() { return $this->belongsTo(Department::class, 'rf_department_id', 'department_id'); diff --git a/app/Services/StatisticsService.php b/app/Services/StatisticsService.php index 4ab49df..43ce97e 100644 --- a/app/Services/StatisticsService.php +++ b/app/Services/StatisticsService.php @@ -7,6 +7,7 @@ namespace App\Services; use App\Models\Department; use App\Models\MetrikaResult; use App\Models\Report; +use App\Models\ReportDuty; use App\Models\User; use App\Models\UserDepartment; use Carbon\Carbon; @@ -119,7 +120,7 @@ class StatisticsService foreach ($deptList as $dept) { $deptId = $dept->department_id; - $lastReportQuery = Report::where('rf_department_id', $deptId); + $lastReportQuery = ReportDuty::where('rf_department_id', $deptId); if ($isRangeOneDay) { $lastReportQuery->exactPeriod($startDate, $endDate); } else {