wip
This commit is contained in:
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Inertia\Response;
|
||||
@@ -29,10 +28,7 @@ class DashboardController extends Controller
|
||||
$absences = Vacation::query()
|
||||
->with(["user", "vacationRequest"])
|
||||
->whereDate("date", $now)
|
||||
->whereRelation(
|
||||
"vacationRequest",
|
||||
fn(Builder $query) => $query->states(VacationRequestStatesRetriever::successStates()),
|
||||
)
|
||||
->approved()
|
||||
->get();
|
||||
|
||||
if ($user->can("listAll", VacationRequest::class)) {
|
||||
|
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Response;
|
||||
use Toby\Domain\Enums\Month;
|
||||
@@ -26,10 +25,7 @@ class MonthlyUsageController extends Controller
|
||||
$currentUser = $request->user();
|
||||
|
||||
$users = User::query()
|
||||
->whereRelation(
|
||||
"vacationlimits",
|
||||
fn(Builder $query) => $query->where("year_period_id", $currentYearPeriod->id)->whereNotNull("days"),
|
||||
)
|
||||
->withVacationLimitIn($currentYearPeriod)
|
||||
->where("id", "!=", $currentUser->id)
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
|
@@ -8,6 +8,7 @@ use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Response;
|
||||
use Toby\Domain\Actions\CreateUserAction;
|
||||
use Toby\Domain\Enums\EmploymentForm;
|
||||
use Toby\Domain\Enums\Role;
|
||||
use Toby\Eloquent\Models\User;
|
||||
@@ -54,11 +55,11 @@ class UserController extends Controller
|
||||
/**
|
||||
* @throws AuthorizationException
|
||||
*/
|
||||
public function store(UserRequest $request): RedirectResponse
|
||||
public function store(UserRequest $request, CreateUserAction $createUserAction): RedirectResponse
|
||||
{
|
||||
$this->authorize("manageUsers");
|
||||
|
||||
User::query()->create($request->data());
|
||||
$createUserAction->execute($request->data());
|
||||
|
||||
return redirect()
|
||||
->route("users.index")
|
||||
|
@@ -103,10 +103,7 @@ class VacationRequestController extends Controller
|
||||
->paginate();
|
||||
|
||||
$users = User::query()
|
||||
->whereRelation(
|
||||
"vacationlimits",
|
||||
fn(Builder $query) => $query->where("year_period_id", $yearPeriod->id)->whereNotNull("days"),
|
||||
)
|
||||
->withVacationLimitIn($yearPeriod)
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->get();
|
||||
@@ -164,10 +161,7 @@ class VacationRequestController extends Controller
|
||||
$yearPeriod = $yearPeriodRetriever->selected();
|
||||
|
||||
$users = User::query()
|
||||
->whereRelation(
|
||||
"vacationlimits",
|
||||
fn(Builder $query) => $query->where("year_period_id", $yearPeriod->id)->whereNotNull("days"),
|
||||
)
|
||||
->withVacationLimitIn($yearPeriod)
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->get();
|
||||
|
@@ -8,6 +8,7 @@ use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Toby\Domain\Actions\CreateYearPeriodAction;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class CheckYearPeriod implements ShouldQueue
|
||||
@@ -15,30 +16,17 @@ class CheckYearPeriod implements ShouldQueue
|
||||
use Dispatchable;
|
||||
use Queueable;
|
||||
|
||||
public function handle(): void
|
||||
public function handle(CreateYearPeriodAction $createYearPeriodAction): void
|
||||
{
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
$now = Carbon::now();
|
||||
|
||||
if ($currentYearPeriod === null) {
|
||||
$this->createCurrentYearPeriod();
|
||||
$createYearPeriodAction->execute($now->year);
|
||||
}
|
||||
|
||||
if (YearPeriod::query()->max("year") === Carbon::now()->year) {
|
||||
$this->createNextYearPeriod();
|
||||
if (YearPeriod::query()->max("year") === $now->year) {
|
||||
$createYearPeriodAction->execute($now->year + 1);
|
||||
}
|
||||
}
|
||||
|
||||
protected function createCurrentYearPeriod(): void
|
||||
{
|
||||
YearPeriod::query()->create([
|
||||
"year" => Carbon::now()->year,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function createNextYearPeriod(): void
|
||||
{
|
||||
YearPeriod::query()->create([
|
||||
"year" => Carbon::now()->year + 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user