Compare commits

..

No commits in common. "1faa6ae5880241c98308fc895c6347db84166dcc" and "82d7b9bb1ed06d66f5e65f4369a9e3f5b528e8db" have entirely different histories.

5 changed files with 8 additions and 35 deletions

View File

@ -22,7 +22,6 @@ public function __construct(
private readonly ?string $gender = null,
private readonly ?int $departmentId = null,
private readonly ?string $status = null,
private readonly ?int $enrollmentYear = null,
) {}
public function title(): string
@ -32,7 +31,7 @@ public function title(): string
public function collection(): Enumerable
{
return app(StudentService::class)->forExport($this->search, $this->gender, $this->departmentId, $this->status, $this->enrollmentYear);
return app(StudentService::class)->forExport($this->search, $this->gender, $this->departmentId, $this->status);
}
public function headings(): array

View File

@ -35,12 +35,10 @@ public function index(PaginatedRequest $request): Response
gender: $request->validated('gender'),
departmentId: $request->validated('department_id'),
status: $request->validated('status'),
enrollmentYear: $request->validated('enrollment_year'),
),
'departments' => $this->departmentService->getAllForSelect(),
'statuses' => StudentStatus::options(),
'enrollmentYears' => $this->service->getEnrollmentYears(),
'filters' => $request->only(['gender', 'department_id', 'status', 'enrollment_year']),
'filters' => $request->only(['gender', 'department_id', 'status']),
]);
}
@ -116,7 +114,6 @@ public function export(PaginatedRequest $request): BinaryFileResponse
gender: $request->validated('gender'),
departmentId: $request->validated('department_id'),
status: $request->validated('status'),
enrollmentYear: $request->validated('enrollment_year'),
), 'mahasiswa.xlsx');
}
}

View File

@ -24,7 +24,6 @@ public function rules(): array
'gender' => ['nullable', 'string', Rule::in(Gender::values())],
'department_id' => ['nullable', 'integer'],
'status' => ['nullable', 'string'],
'enrollment_year' => ['nullable', 'integer'],
'semester' => ['nullable', 'string', Rule::in(Semester::values())],
'is_active' => ['nullable', Rule::in(['true', 'false'])],
'academic_term_id' => ['nullable', 'integer'],

View File

@ -23,31 +23,21 @@ public function getAllForSelect(): Collection
->get();
}
public function getEnrollmentYears(): array
public function paginated(int $perPage = 25, string $search = '', ?string $gender = null, ?int $departmentId = null, ?string $status = null): LengthAwarePaginator
{
return Student::query()
->select('enrollment_year')
->distinct()
->orderByDesc('enrollment_year')
->pluck('enrollment_year')
->all();
}
public function paginated(int $perPage = 25, string $search = '', ?string $gender = null, ?int $departmentId = null, ?string $status = null, ?int $enrollmentYear = null): LengthAwarePaginator
{
return $this->filteredQuery($search, $gender, $departmentId, $status, $enrollmentYear)
return $this->filteredQuery($search, $gender, $departmentId, $status)
->latest()
->paginate($perPage);
}
public function forExport(string $search = '', ?string $gender = null, ?int $departmentId = null, ?string $status = null, ?int $enrollmentYear = null): Collection
public function forExport(string $search = '', ?string $gender = null, ?int $departmentId = null, ?string $status = null): Collection
{
return $this->filteredQuery($search, $gender, $departmentId, $status, $enrollmentYear)
return $this->filteredQuery($search, $gender, $departmentId, $status)
->orderBy('created_at', 'desc')
->get();
}
private function filteredQuery(string $search, ?string $gender, ?int $departmentId, ?string $status, ?int $enrollmentYear = null): Builder
private function filteredQuery(string $search, ?string $gender, ?int $departmentId, ?string $status): Builder
{
return User::select(['id', 'username', 'email', 'is_active'])
->with([
@ -64,8 +54,7 @@ private function filteredQuery(string $search, ?string $gender, ?int $department
}))
->when($gender, fn ($q) => $q->whereHas('profile', fn ($q) => $q->where('gender', $gender)))
->when($departmentId, fn ($q) => $q->whereHas('student', fn ($q) => $q->where('department_id', $departmentId)))
->when($status, fn ($q) => $q->whereHas('student', fn ($q) => $q->where('status', $status)))
->when($enrollmentYear, fn ($q) => $q->whereHas('student', fn ($q) => $q->where('enrollment_year', $enrollmentYear)));
->when($status, fn ($q) => $q->whereHas('student', fn ($q) => $q->where('status', $status)));
}
public function create(array $data): User

View File

@ -37,12 +37,10 @@ type Props = {
};
departments: Department[];
statuses: StatusOption[];
enrollmentYears: number[];
filters: {
gender?: string;
department_id?: string;
status?: string;
enrollment_year?: string;
};
};
@ -50,7 +48,6 @@ export default function StudentIndex({
students,
departments,
statuses,
enrollmentYears,
filters,
}: Props) {
const [deleting, setDeleting] = useState<Student | null>(null);
@ -78,14 +75,6 @@ export default function StudentIndex({
label: 'Status',
options: statuses,
},
{
key: 'enrollment_year',
label: 'Angkatan',
options: enrollmentYears.map((year) => ({
value: String(year),
label: String(year),
})),
},
];
const pagination: PaginationState = {