Много всего
This commit is contained in:
@@ -6,6 +6,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ArchiveHistory extends Model
|
||||
{
|
||||
protected $connection = 'pgsql';
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::created(function ($archiveHistory) {
|
||||
|
||||
@@ -6,6 +6,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ArchiveInfo extends Model
|
||||
{
|
||||
protected $connection = 'pgsql';
|
||||
protected $table = 'archive_infos';
|
||||
protected $fillable = [
|
||||
'historyable_type',
|
||||
'historyable_id',
|
||||
|
||||
58
app/Models/Mis/SttMedicalHistory.php
Normal file
58
app/Models/Mis/SttMedicalHistory.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Mis;
|
||||
|
||||
use App\Models\ArchiveHistory;
|
||||
use App\Models\ArchiveInfo;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SttMedicalHistory extends Model
|
||||
{
|
||||
protected $primaryKey = 'MedicalHistoryID';
|
||||
protected $table = 'stt_medicalhistory';
|
||||
protected $connection = 'mis';
|
||||
|
||||
public function getFullNameAttribute()
|
||||
{
|
||||
return "$this->FAMILY $this->Name $this->OT";
|
||||
}
|
||||
|
||||
public function archiveHistory()
|
||||
{
|
||||
return $this->morphMany(ArchiveHistory::class, 'historyable');
|
||||
}
|
||||
|
||||
public function archiveInfo()
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -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