Merge pull request 'feat: simplify academic term selection logic and clean up imports in TuitionInvoiceIndex' (#69) from feat/default-academic-term-for-cummary-card-tuition into dev
Reviewed-on: #69
This commit is contained in:
commit
1e30a74072
@ -35,9 +35,7 @@ public function index(PaginatedRequest $request): Response
|
|||||||
$academicTerms = $this->academicTermService->getAllForSelect();
|
$academicTerms = $this->academicTermService->getAllForSelect();
|
||||||
|
|
||||||
$requestedTermId = $request->validated('academic_term_id');
|
$requestedTermId = $request->validated('academic_term_id');
|
||||||
$defaultTermId = $academicTerms->firstWhere('is_active', true)?->id
|
$summaryTermId = $requestedTermId ?? $this->academicTermService->getActive()?->id;
|
||||||
?? $academicTerms->sortByDesc('start_date')->first()?->id;
|
|
||||||
$summaryTermId = $requestedTermId ?? $defaultTermId;
|
|
||||||
|
|
||||||
return Inertia::render('admin/finances/tuition-invoices/index', [
|
return Inertia::render('admin/finances/tuition-invoices/index', [
|
||||||
'invoices' => $this->service->paginated(
|
'invoices' => $this->service->paginated(
|
||||||
|
|||||||
@ -14,6 +14,16 @@ public function getAllForSelect(): Collection
|
|||||||
return AcademicTerm::select(['id', 'name', 'semester', 'start_date', 'end_date', 'is_active'])->latest()->get();
|
return AcademicTerm::select(['id', 'name', 'semester', 'start_date', 'end_date', 'is_active'])->latest()->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The academic term currently marked active, falling back to the one with
|
||||||
|
* the latest start date if none is explicitly active.
|
||||||
|
*/
|
||||||
|
public function getActive(): ?AcademicTerm
|
||||||
|
{
|
||||||
|
return AcademicTerm::where('is_active', true)->first()
|
||||||
|
?? AcademicTerm::orderByDesc('start_date')->first();
|
||||||
|
}
|
||||||
|
|
||||||
public function paginated(int $perPage = 25, string $search = '', ?string $semester = null, ?bool $isActive = null): LengthAwarePaginator
|
public function paginated(int $perPage = 25, string $search = '', ?string $semester = null, ?bool $isActive = null): LengthAwarePaginator
|
||||||
{
|
{
|
||||||
return AcademicTerm::query()
|
return AcademicTerm::query()
|
||||||
|
|||||||
@ -1,3 +1,14 @@
|
|||||||
|
import { Head, router } from '@inertiajs/react';
|
||||||
|
import { format } from 'date-fns';
|
||||||
|
import type { LucideIcon } from 'lucide-react';
|
||||||
|
import {
|
||||||
|
CircleDollarSign,
|
||||||
|
FileText,
|
||||||
|
Plus,
|
||||||
|
UserRoundX,
|
||||||
|
Wallet,
|
||||||
|
} from 'lucide-react';
|
||||||
|
import { useState } from 'react';
|
||||||
import type { PaginationState } from '@/components/data-table';
|
import type { PaginationState } from '@/components/data-table';
|
||||||
import { DataTable } from '@/components/data-table';
|
import { DataTable } from '@/components/data-table';
|
||||||
import { DatePicker } from '@/components/date-picker';
|
import { DatePicker } from '@/components/date-picker';
|
||||||
@ -55,17 +66,6 @@ import {
|
|||||||
PaymentStatusLabels,
|
PaymentStatusLabels,
|
||||||
PaymentStatuses,
|
PaymentStatuses,
|
||||||
} from '@/types/tuition-payment';
|
} from '@/types/tuition-payment';
|
||||||
import { Head, router } from '@inertiajs/react';
|
|
||||||
import { format } from 'date-fns';
|
|
||||||
import type { LucideIcon } from 'lucide-react';
|
|
||||||
import {
|
|
||||||
CircleDollarSign,
|
|
||||||
FileText,
|
|
||||||
Plus,
|
|
||||||
UserRoundX,
|
|
||||||
Wallet,
|
|
||||||
} from 'lucide-react';
|
|
||||||
import { useState } from 'react';
|
|
||||||
import { createTuitionInvoiceColumns } from './columns';
|
import { createTuitionInvoiceColumns } from './columns';
|
||||||
|
|
||||||
type AcademicTermOption = { id: number; name: string; semester: string };
|
type AcademicTermOption = { id: number; name: string; semester: string };
|
||||||
@ -208,8 +208,8 @@ export default function TuitionInvoiceIndex({
|
|||||||
Ringkasan berikut hanya menampilkan periode{' '}
|
Ringkasan berikut hanya menampilkan periode{' '}
|
||||||
{summaryAcademicTerm
|
{summaryAcademicTerm
|
||||||
? formatAcademicTermLabel(summaryAcademicTerm)
|
? formatAcademicTermLabel(summaryAcademicTerm)
|
||||||
: '-'}
|
: '-'}{' '}
|
||||||
{' '} dan bisa disesuaikan lewat filter.
|
dan bisa disesuaikan lewat filter.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
||||||
@ -362,9 +362,9 @@ function CreateForm({
|
|||||||
|
|
||||||
const availableStudents = academicTermId
|
const availableStudents = academicTermId
|
||||||
? students.filter(
|
? students.filter(
|
||||||
(student) =>
|
(student) =>
|
||||||
!student.invoiced_term_ids?.includes(Number(academicTermId)),
|
!student.invoiced_term_ids?.includes(Number(academicTermId)),
|
||||||
)
|
)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
@ -441,7 +441,7 @@ function CreateForm({
|
|||||||
>
|
>
|
||||||
{selectedStudents.length ===
|
{selectedStudents.length ===
|
||||||
availableStudents.length &&
|
availableStudents.length &&
|
||||||
availableStudents.length > 0
|
availableStudents.length > 0
|
||||||
? 'Batalkan Semua'
|
? 'Batalkan Semua'
|
||||||
: 'Pilih Semua'}
|
: 'Pilih Semua'}
|
||||||
</button>
|
</button>
|
||||||
@ -478,8 +478,8 @@ function CreateForm({
|
|||||||
selectedStudents.length > 0
|
selectedStudents.length > 0
|
||||||
? ''
|
? ''
|
||||||
: academicTermId
|
: academicTermId
|
||||||
? 'Pilih mahasiswa (aktif)'
|
? 'Pilih mahasiswa (aktif)'
|
||||||
: 'Pilih periode akademik terlebih dahulu'
|
: 'Pilih periode akademik terlebih dahulu'
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</ComboboxChips>
|
</ComboboxChips>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user