Added filled gaps to time entry aggregation; Moved aggregation to service

This commit is contained in:
Constantin Graf
2024-05-21 17:31:45 +02:00
parent efd3fef0c5
commit 2a8ab12017
30 changed files with 1017 additions and 218 deletions

View File

@@ -11,8 +11,8 @@ use App\Models\Tag;
use App\Models\Task;
use App\Models\TimeEntry;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
/**
* @extends Factory<TimeEntry>
@@ -67,11 +67,13 @@ class TimeEntryFactory extends Factory
});
}
public function startBetween(Carbon $rangeStart, Carbon $rangeEnd): self
public function startBetween(Carbon $rangeStart, Carbon $rangeEnd, bool $fixedValueForMultiple = false): self
{
$start = Carbon::instance($this->faker->dateTimeBetween($rangeStart, $rangeEnd));
$fixedStart = Carbon::instance($this->faker->dateTimeBetween($rangeStart, $rangeEnd));
return $this->state(function (array $attributes) use ($rangeStart, $rangeEnd, $fixedStart, $fixedValueForMultiple): array {
$start = $fixedValueForMultiple ? $fixedStart : Carbon::instance($this->faker->dateTimeBetween($rangeStart, $rangeEnd));
return $this->state(function (array $attributes) use ($start): array {
return [
'start' => $start->utc(),
'end' => $this->faker->dateTimeBetween($start, 'now'),
@@ -111,6 +113,34 @@ class TimeEntryFactory extends Factory
});
}
public function billable(): self
{
return $this->state(function (array $attributes): array {
return [
'billable' => true,
];
});
}
public function startWithDuration(Carbon $start, int $durationInSeconds): self
{
return $this->state(function (array $attributes) use ($start, $durationInSeconds): array {
return [
'start' => $start->utc(),
'end' => $start->copy()->addSeconds($durationInSeconds),
];
});
}
public function start(Carbon $start): self
{
return $this->state(function (array $attributes) use ($start): array {
return [
'start' => $start->utc(),
];
});
}
public function forOrganization(Organization $organization): self
{
return $this->state(function (array $attributes) use ($organization) {