mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-15 19:52:15 +01:00
Added is_imported flag to time entries
This commit is contained in:
committed by
Constantin Graf
parent
802d9558a3
commit
20f9b344f6
77
app/Filament/Widgets/TimeEntriesImported.php
Normal file
77
app/Filament/Widgets/TimeEntriesImported.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\TimeEntry;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Flowframe\Trend\Trend;
|
||||
use Flowframe\Trend\TrendValue;
|
||||
|
||||
class TimeEntriesImported extends ChartWidget
|
||||
{
|
||||
protected static ?string $heading = 'Time Entries Imported';
|
||||
|
||||
public ?string $filter = 'week';
|
||||
|
||||
protected static ?int $sort = 4;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$filter = $this->filter;
|
||||
if ($filter === 'week') {
|
||||
$start = now()->subWeek();
|
||||
} elseif ($filter === 'month') {
|
||||
$start = now()->subMonth();
|
||||
} elseif ($filter === 'year') {
|
||||
$start = now()->subYear();
|
||||
} else {
|
||||
$start = now()->subWeek();
|
||||
}
|
||||
$trend = Trend::query(
|
||||
TimeEntry::query()->where('is_imported', '=', true)
|
||||
)
|
||||
->between(
|
||||
start: $start,
|
||||
end: now(),
|
||||
)
|
||||
->perDay();
|
||||
|
||||
if ($filter === 'week') {
|
||||
$trend->perDay();
|
||||
} elseif ($filter === 'month') {
|
||||
$trend->perDay();
|
||||
} elseif ($filter === 'year') {
|
||||
$trend->perMonth();
|
||||
} else {
|
||||
$trend->perDay();
|
||||
}
|
||||
|
||||
$data = $trend->count();
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => self::$heading,
|
||||
'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
|
||||
],
|
||||
],
|
||||
'labels' => $data->map(fn (TrendValue $value) => $value->date),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getFilters(): ?array
|
||||
{
|
||||
return [
|
||||
'week' => 'Last week',
|
||||
'month' => 'Last month',
|
||||
'year' => 'Last year',
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user