Some checks failed
tests / ci (pull_request) Has been cancelled
- Implemented StudentService to retrieve all students for selection. - Created migration for tuition_invoices and tuition_payments tables. - Added seeders for TuitionInvoice and TuitionPayment with sample data. - Updated DatabaseSeeder to include new seeders. - Developed UI components for managing tuition invoices and payments, including forms and data tables. - Introduced RupiahInput component for formatted currency input. - Added routes for tuition invoices and payments management. - Defined TypeScript types for tuition invoices and payments.
59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin\Manage;
|
|
|
|
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();
|
|
}
|
|
}
|