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.5 KiB
PHP
59 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\PaymentStatus;
|
|
use Illuminate\Database\Eloquent\Attributes\Appends;
|
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Spatie\MediaLibrary\HasMedia;
|
|
use Spatie\MediaLibrary\InteractsWithMedia;
|
|
|
|
#[Guarded(['id'])]
|
|
#[Appends(['proof_url', 'proof_name'])]
|
|
class TuitionPayment extends Model implements HasMedia
|
|
{
|
|
use HasFactory, InteractsWithMedia;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'amount_paid' => 'decimal:2',
|
|
'paid_at' => 'datetime',
|
|
'status' => PaymentStatus::class,
|
|
];
|
|
}
|
|
|
|
public function registerMediaCollections(): void
|
|
{
|
|
$this->addMediaCollection('payment_proof')->singleFile();
|
|
}
|
|
|
|
public function invoice(): BelongsTo
|
|
{
|
|
return $this->belongsTo(TuitionInvoice::class, 'invoice_id');
|
|
}
|
|
|
|
public function recorder(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'recorded_by');
|
|
}
|
|
|
|
protected function proofUrl(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->getFirstMediaUrl('payment_proof') ?: null,
|
|
);
|
|
}
|
|
|
|
protected function proofName(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->getFirstMedia('payment_proof')?->file_name,
|
|
);
|
|
}
|
|
}
|