|
@@ -11,11 +11,30 @@
|
|
|
|
|
|
|
|
class StudentService
|
|
class StudentService
|
|
|
{
|
|
{
|
|
|
- public function getAll(User $user): Collection
|
|
|
|
|
|
|
+ public function getAll(User $user, array $filters = []): Collection
|
|
|
{
|
|
{
|
|
|
$unitId = $this->resolveUnitId($user);
|
|
$unitId = $this->resolveUnitId($user);
|
|
|
|
|
+ $startDate = $filters['contract_start_date'] ?? null;
|
|
|
|
|
+ $endDate = $filters['contract_end_date'] ?? null;
|
|
|
|
|
|
|
|
return Student::where('unit_id', $unitId)
|
|
return Student::where('unit_id', $unitId)
|
|
|
|
|
+ ->when($startDate || $endDate, function ($query) use ($startDate, $endDate) {
|
|
|
|
|
+ $query->whereHas('contracts', function ($contractQuery) use ($startDate, $endDate) {
|
|
|
|
|
+ $contractQuery->where('status', 'active');
|
|
|
|
|
+
|
|
|
|
|
+ if ($endDate) {
|
|
|
|
|
+ $contractQuery->where('started_date', '<=', $endDate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($startDate) {
|
|
|
|
|
+ $contractQuery->where(function ($periodQuery) use ($startDate) {
|
|
|
|
|
+ $periodQuery
|
|
|
|
|
+ ->whereNull('end_date')
|
|
|
|
|
+ ->orWhere('end_date', '>=', $startDate);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ })
|
|
|
->orderBy('created_at', 'desc')
|
|
->orderBy('created_at', 'desc')
|
|
|
->get();
|
|
->get();
|
|
|
}
|
|
}
|