Много всего
This commit is contained in:
@@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class SttMedicalHistory extends Model
|
||||
{
|
||||
protected $table = 'si_stt_patients';
|
||||
protected $connection = 'pgsql';
|
||||
|
||||
protected $fillable = [
|
||||
'family', // Фамилия
|
||||
@@ -39,6 +40,34 @@ class SttMedicalHistory extends Model
|
||||
return $this->morphOne(ArchiveInfo::class, 'historyable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет, можно ли выдать эту карту
|
||||
*/
|
||||
public function canBeIssued(): bool
|
||||
{
|
||||
// Проверяем, есть ли открытые выдачи
|
||||
$hasOpenIssue = $this->archiveHistory()
|
||||
->whereNotNull('issue_at')
|
||||
->whereNull('return_at')
|
||||
->where('has_lost', false)
|
||||
->exists();
|
||||
|
||||
return !$hasOpenIssue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает текущую открытую выдачу (если есть)
|
||||
*/
|
||||
public function getCurrentIssue(): ?ArchiveHistory
|
||||
{
|
||||
return $this->archiveHistory()
|
||||
->whereNotNull('issue_at')
|
||||
->whereNull('return_at')
|
||||
->where('has_lost', false)
|
||||
->latest('issue_at')
|
||||
->first();
|
||||
}
|
||||
|
||||
public function scopeSearch($query, $searchText)
|
||||
{
|
||||
return $query->where(function($q) use ($searchText) {
|
||||
|
||||
Reference in New Issue
Block a user