Some checks failed
tests / ci (pull_request) Has been cancelled
- Created sub-namespaces under Admin\Manage for Course, Academic, Announcement, Finance, and Service. - Added new FormRequest classes for handling validation in each sub-namespace. - Implemented Service classes for managing business logic related to each resource. - Updated routes to reflect the new sub-namespace structure. - Enhanced code organization and maintainability by grouping related functionalities.
49 lines
1.8 KiB
PHP
49 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin\Manage\Finance;
|
|
|
|
use App\Models\TuitionInvoice;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
|
|
class TuitionInvoiceService
|
|
{
|
|
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
|
{
|
|
return TuitionInvoice::query()
|
|
->select(['id', 'student_id', 'academic_term_id', 'amount_due', 'due_date'])
|
|
->withSum('payments as paid_total', 'amount_paid')
|
|
->withCount('payments')
|
|
->with(['student.user.profile', 'student.department', 'academicTerm:id,name,semester,start_date,end_date'])
|
|
->when($search, fn ($q) => $q->whereHas('student', fn ($q) => $q->where('student_number', 'like', "%{$search}%")
|
|
->orWhereHas('user.profile', fn ($q) => $q->where('full_name', 'like', "%{$search}%"))))
|
|
->orderBy($sort, $direction)
|
|
->paginate($perPage);
|
|
}
|
|
|
|
public function create(array $data): TuitionInvoice
|
|
{
|
|
return TuitionInvoice::create([
|
|
'student_id' => $data['student_id'],
|
|
'academic_term_id' => $data['academic_term_id'],
|
|
'amount_due' => $data['amount_due'],
|
|
'due_date' => $data['due_date'] ?? null,
|
|
]);
|
|
}
|
|
|
|
public function update(TuitionInvoice $invoice, array $data): TuitionInvoice
|
|
{
|
|
$invoice->student_id = $data['student_id'];
|
|
$invoice->academic_term_id = $data['academic_term_id'];
|
|
$invoice->amount_due = $data['amount_due'];
|
|
$invoice->due_date = $data['due_date'] ?? null;
|
|
$invoice->update();
|
|
|
|
return $invoice;
|
|
}
|
|
|
|
public function delete(TuitionInvoice $invoice): bool
|
|
{
|
|
return $invoice->delete();
|
|
}
|
|
}
|