Some checks failed
tests / ci (pull_request) Has been cancelled
- Implemented academic advising logs functionality with create, edit, and delete capabilities. - Created UI components for displaying academic advising logs in a data table format. - Added letter requests management with similar CRUD operations and UI components. - Refactored routes to organize academic classes, announcements, finances, and services under appropriate namespaces.
59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin\Finances;
|
|
|
|
use App\Models\TuitionInvoice;
|
|
use App\Models\TuitionPayment;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
class TuitionPaymentService
|
|
{
|
|
public function forInvoice(TuitionInvoice $invoice): Collection
|
|
{
|
|
return $invoice->payments()
|
|
->with('recorder.profile')
|
|
->latest('paid_at')
|
|
->get();
|
|
}
|
|
|
|
public function create(TuitionInvoice $invoice, array $data, ?UploadedFile $file): TuitionPayment
|
|
{
|
|
$payment = $invoice->payments()->create([
|
|
'amount_paid' => $data['amount_paid'],
|
|
'paid_at' => $data['paid_at'],
|
|
'payment_method' => $data['payment_method'] ?? null,
|
|
'status' => $data['status'],
|
|
'recorded_by' => auth()->id(),
|
|
'notes' => $data['notes'] ?? null,
|
|
]);
|
|
|
|
if ($file) {
|
|
$payment->addMedia($file)->toMediaCollection('payment_proof');
|
|
}
|
|
|
|
return $payment;
|
|
}
|
|
|
|
public function update(TuitionPayment $payment, array $data, ?UploadedFile $file): TuitionPayment
|
|
{
|
|
$payment->amount_paid = $data['amount_paid'];
|
|
$payment->paid_at = $data['paid_at'];
|
|
$payment->payment_method = $data['payment_method'] ?? null;
|
|
$payment->status = $data['status'];
|
|
$payment->notes = $data['notes'] ?? null;
|
|
$payment->update();
|
|
|
|
if ($file) {
|
|
$payment->addMedia($file)->toMediaCollection('payment_proof');
|
|
}
|
|
|
|
return $payment;
|
|
}
|
|
|
|
public function delete(TuitionPayment $payment): bool
|
|
{
|
|
return $payment->delete();
|
|
}
|
|
}
|