adrema/app/Payment/Payment.php

47 lines
1.2 KiB
PHP
Raw Normal View History

2021-07-04 16:56:07 +02:00
<?php
namespace App\Payment;
use App\Member\Member;
use App\Payment\Status;
use App\Payment\Subscription;
2021-10-29 21:44:23 +02:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
2021-07-04 16:56:07 +02:00
class Payment extends Model
{
use HasFactory;
2021-10-29 21:44:23 +02:00
public $fillable = ['member_id', 'subscription_id', 'nr', 'status_id', 'last_remembered_at'];
2021-07-04 16:56:07 +02:00
public function member() {
return $this->belongsTo(Member::class);
}
public function subscription() {
return $this->belongsTo(Subscription::class);
}
public function status() {
return $this->belongsTo(Status::class);
}
2021-07-04 21:47:20 +02:00
public function scopeWhereNeedsPayment($q) {
return $q->whereHas('status', function($q) {
return $q->needsPayment();
});
}
public function scopeWhereNeedsBill($q) {
return $q->whereHas('status', function($q) {
return $q->where('is_bill', true);
});
}
public function scopeWhereNeedsRemember($q) {
return $q->whereHas('status', function($q) {
return $q->where('is_remember', true);
2021-10-29 21:44:23 +02:00
})->where(fn ($query) => $query->whereNull('last_remembered_at')->orWhere('last_remembered_at', '<=', now()->subMonths(6)));
}
2021-07-04 16:56:07 +02:00
}