47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Services\Billing\DunningSchedule;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* Eine Rückstands-Episode: von der ersten gescheiterten Abbuchung bis zur
|
|
* Begleichung oder zur Sperre.
|
|
*/
|
|
class DunningCase extends Model
|
|
{
|
|
protected $fillable = [
|
|
'subscription_id', 'stripe_invoice_id', 'level',
|
|
'opened_at', 'next_step_at', 'settled_at', 'fee_invoice_ids', 'note',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'level' => 'integer',
|
|
'opened_at' => 'datetime',
|
|
'next_step_at' => 'datetime',
|
|
'settled_at' => 'datetime',
|
|
'fee_invoice_ids' => 'array',
|
|
];
|
|
}
|
|
|
|
public function subscription(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Subscription::class);
|
|
}
|
|
|
|
/** Läuft noch — weder beglichen noch von Hand geschlossen. */
|
|
public function isOpen(): bool
|
|
{
|
|
return $this->settled_at === null;
|
|
}
|
|
|
|
public function isSuspended(): bool
|
|
{
|
|
return $this->level >= DunningSchedule::SUSPENDED;
|
|
}
|
|
}
|