feat: Implement local scopes for report statuses in the Report model and update the TaskRealizationChart to filter by ApprovalStatus enum.
This commit is contained in:
parent
23e19e177a
commit
e4cd88136e
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Filament\Widgets;
|
namespace App\Filament\Widgets;
|
||||||
|
|
||||||
|
use App\Enums\ApprovalStatus;
|
||||||
use App\Models\Report;
|
use App\Models\Report;
|
||||||
use BezhanSalleh\FilamentShield\Traits\HasWidgetShield;
|
use BezhanSalleh\FilamentShield\Traits\HasWidgetShield;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
@ -27,7 +28,7 @@ protected function getData(): array
|
|||||||
$data = Report::query()
|
$data = Report::query()
|
||||||
->select(
|
->select(
|
||||||
DB::raw('COUNT(*) as count'),
|
DB::raw('COUNT(*) as count'),
|
||||||
DB::raw('status'),
|
'status',
|
||||||
DB::raw("DATE_FORMAT(created_at, '%Y-%m') as month")
|
DB::raw("DATE_FORMAT(created_at, '%Y-%m') as month")
|
||||||
)
|
)
|
||||||
->when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
|
->when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
|
||||||
@ -44,9 +45,10 @@ protected function getData(): array
|
|||||||
$rejectedData = [];
|
$rejectedData = [];
|
||||||
|
|
||||||
foreach ($months as $month) {
|
foreach ($months as $month) {
|
||||||
$acceptedData[] = $data->where('month', $month)->accepted()->first()?->count ?? 0;
|
$monthData = $data->where('month', $month);
|
||||||
$pendingData[] = $data->where('month', $month)->pending()->first()?->count ?? 0;
|
$acceptedData[] = $monthData->where('status', ApprovalStatus::ACCEPTED)->first()?->count ?? 0;
|
||||||
$rejectedData[] = $data->where('month', $month)->rejected()->first()?->count ?? 0;
|
$pendingData[] = $monthData->where('status', ApprovalStatus::PENDING)->first()?->count ?? 0;
|
||||||
|
$rejectedData[] = $monthData->where('status', ApprovalStatus::REJECTED)->first()?->count ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|||||||
@ -3,6 +3,8 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Enums\ApprovalStatus;
|
use App\Enums\ApprovalStatus;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
@ -27,6 +29,24 @@ protected function casts(): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Scope]
|
||||||
|
protected function accepted(Builder $query): void
|
||||||
|
{
|
||||||
|
$query->where('status', ApprovalStatus::ACCEPTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Scope]
|
||||||
|
protected function pending(Builder $query): void
|
||||||
|
{
|
||||||
|
$query->where('status', ApprovalStatus::PENDING);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Scope]
|
||||||
|
protected function rejected(Builder $query): void
|
||||||
|
{
|
||||||
|
$query->where('status', ApprovalStatus::REJECTED);
|
||||||
|
}
|
||||||
|
|
||||||
public function mediaTaskAssignment(): BelongsTo
|
public function mediaTaskAssignment(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(MediaTaskAssignment::class);
|
return $this->belongsTo(MediaTaskAssignment::class);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user