53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Directories;
|
|
|
|
use App\Contracts\Directories\EmployeeDirectory;
|
|
use App\Models\Employee;
|
|
use Carbon\CarbonInterface;
|
|
|
|
class EloquentEmployeeDirectory implements EmployeeDirectory
|
|
{
|
|
public function find(int $id): ?Employee
|
|
{
|
|
return Employee::query()
|
|
->where('id', $id)
|
|
->first();
|
|
}
|
|
|
|
public function countActiveEmployees(): int
|
|
{
|
|
return Employee::query()
|
|
->active()
|
|
->count();
|
|
}
|
|
|
|
public function countActiveRegisteredEmployees(): int
|
|
{
|
|
return Employee::query()
|
|
->active()
|
|
->whereHas('customer')
|
|
->count();
|
|
}
|
|
|
|
public function countActiveEmployeesWithin(CarbonInterface $start, CarbonInterface $end): int
|
|
{
|
|
return Employee::query()
|
|
->active()
|
|
->whereDate('created_at', '>=', $start)
|
|
->whereDate('created_at', '<=', $end)
|
|
->count();
|
|
}
|
|
|
|
public function countActiveRegisteredEmployeesWithin(CarbonInterface $start, CarbonInterface $end): int
|
|
{
|
|
return Employee::query()
|
|
->active()
|
|
->whereHas('customer')
|
|
->whereDate('created_at', '>=', $start)
|
|
->whereDate('created_at', '<=', $end)
|
|
->count();
|
|
}
|
|
}
|