-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,452 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
use Maatwebsite\Excel\Excel; | ||
|
||
enum ExportFormat: string | ||
{ | ||
case CSV = 'csv'; | ||
case PDF = 'pdf'; | ||
case XLSX = 'xlsx'; | ||
case ODS = 'ods'; | ||
|
||
public function getFileExtension(): string | ||
{ | ||
return match ($this) { | ||
self::CSV => 'csv', | ||
self::PDF => 'pdf', | ||
self::XLSX => 'xlsx', | ||
self::ODS => 'ods', | ||
}; | ||
} | ||
|
||
public function getExportPackageType(): string | ||
{ | ||
return match ($this) { | ||
self::CSV => Excel::CSV, | ||
self::PDF => Excel::MPDF, | ||
self::XLSX => Excel::XLSX, | ||
self::ODS => Excel::ODS, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
app/Http/Requests/V1/TimeEntry/TimeEntryIndexExportRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Requests\V1\TimeEntry; | ||
|
||
use App\Enums\ExportFormat; | ||
use App\Models\Member; | ||
use App\Models\Organization; | ||
use App\Models\Project; | ||
use App\Models\Tag; | ||
use App\Models\Task; | ||
use Illuminate\Contracts\Validation\ValidationRule; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Validation\Rule; | ||
use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent; | ||
|
||
/** | ||
* @property Organization $organization | ||
*/ | ||
class TimeEntryIndexExportRequest extends TimeEntryIndexRequest | ||
{ | ||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, array<string|ValidationRule|\Illuminate\Contracts\Validation\Rule>> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'format' => [ | ||
'required', | ||
'string', | ||
Rule::enum(ExportFormat::class), | ||
], | ||
// Filter by member ID | ||
'member_id' => [ | ||
'string', | ||
'uuid', | ||
new ExistsEloquent(Member::class, null, function (Builder $builder): Builder { | ||
/** @var Builder<Member> $builder */ | ||
return $builder->whereBelongsTo($this->organization, 'organization'); | ||
}), | ||
], | ||
// Filter by multiple member IDs, member IDs are OR combined, but AND combined with the member_id parameter | ||
'member_ids' => [ | ||
'array', | ||
'min:1', | ||
], | ||
'member_ids.*' => [ | ||
'string', | ||
'uuid', | ||
new ExistsEloquent(Member::class, null, function (Builder $builder): Builder { | ||
/** @var Builder<Member> $builder */ | ||
return $builder->whereBelongsTo($this->organization, 'organization'); | ||
}), | ||
], | ||
// Filter by project IDs, project IDs are OR combined | ||
'project_ids' => [ | ||
'array', | ||
'min:1', | ||
], | ||
'project_ids.*' => [ | ||
'string', | ||
'uuid', | ||
new ExistsEloquent(Project::class, null, function (Builder $builder): Builder { | ||
/** @var Builder<Project> $builder */ | ||
return $builder->whereBelongsTo($this->organization, 'organization'); | ||
}), | ||
], | ||
// Filter by tag IDs, tag IDs are AND combined | ||
'tag_ids' => [ | ||
'array', | ||
'min:1', | ||
], | ||
'tag_ids.*' => [ | ||
'string', | ||
'uuid', | ||
new ExistsEloquent(Tag::class, null, function (Builder $builder): Builder { | ||
/** @var Builder<Tag> $builder */ | ||
return $builder->whereBelongsTo($this->organization, 'organization'); | ||
}), | ||
], | ||
// Filter by task IDs, task IDs are OR combined | ||
'task_ids' => [ | ||
'array', | ||
'min:1', | ||
], | ||
'task_ids.*' => [ | ||
'string', | ||
'uuid', | ||
new ExistsEloquent(Task::class, null, function (Builder $builder): Builder { | ||
/** @var Builder<Task> $builder */ | ||
return $builder->whereBelongsTo($this->organization, 'organization'); | ||
}), | ||
], | ||
// Filter only time entries that have a start date after the given timestamp in UTC (example: 2021-01-01T00:00:00Z) | ||
'start' => [ | ||
'nullable', | ||
'string', | ||
'date_format:Y-m-d\TH:i:s\Z', | ||
'before:end', | ||
], | ||
// Filter only time entries that have a start date before the given timestamp in UTC (example: 2021-01-01T00:00:00Z) | ||
'end' => [ | ||
'nullable', | ||
'string', | ||
'date_format:Y-m-d\TH:i:s\Z', | ||
], | ||
// Filter by active status (active means has no end date, is still running) | ||
'active' => [ | ||
'string', | ||
'in:true,false', | ||
], | ||
// Filter by billable status | ||
'billable' => [ | ||
'string', | ||
'in:true,false', | ||
], | ||
// Limit the number of returned time entries (default: 150) | ||
'limit' => [ | ||
'integer', | ||
'min:1', | ||
'max:500', | ||
], | ||
// Filter makes sure that only time entries of a whole date are returned | ||
'only_full_dates' => [ | ||
'string', | ||
'in:true,false', | ||
], | ||
]; | ||
} | ||
|
||
public function getOnlyFullDates(): bool | ||
{ | ||
return $this->input('only_full_dates', 'false') === 'true'; | ||
} | ||
|
||
public function getFormatValue(): ExportFormat | ||
{ | ||
return ExportFormat::from($this->validated('format')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.