Files
kartoteka/app/Models/ArchiveHistory.php
brusnitsyn c5c1a2b3e1 Новая логика поисковой выдачи
И добавлена кнопка Добавить карту в архив
2025-12-26 17:41:25 +09:00

87 lines
2.0 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use App\Models\Mis\SttMedicalHistory as MisMedicalHistory;
use App\Models\SI\SttMedicalHistory as SiMedicalHistory;
use Illuminate\Database\Eloquent\Model;
class ArchiveHistory extends Model
{
protected $connection = 'pgsql';
protected static function booted()
{
static::created(function ($archiveHistory) {
$archiveHistory->updateArchiveInfoStatus();
});
static::updated(function ($archiveHistory) {
$archiveHistory->updateArchiveInfoStatus();
});
}
public function updateArchiveInfoStatus()
{
if ($this->mis_history_id) {
$this->misHistory->archiveInfo->update([
'status_id' => $this->determineStatusId()
]);
} else {
$this->foxproHistory->archiveInfo->update([
'status_id' => $this->determineStatusId()
]);
}
}
public function determineStatusId()
{
if ($this->has_lost) {
return 4; // Утерян
}
if ($this->issue_at && !$this->return_at) {
return 3; // Выдан
}
if ($this->return_at) {
return 2; // В архиве
}
return 2; // По умолчанию
}
protected $fillable = [
'keyarhiv',
'foxpro_history_id',
'mis_history_id',
'issue_at',
'return_at',
'comment',
'org_id',
'employee_name',
'employee_post',
'has_lost',
];
public function foxproHistory()
{
return $this->belongsTo(SiMedicalHistory::class, 'foxpro_history_id', 'keykarta');
}
public function misHistory()
{
return $this->belongsTo(MisMedicalHistory::class, 'mis_history_id', 'MedicalHistoryID');
}
public function historyType()
{
return $this->mis_history_id !== null ? 'mis' : 'foxpro';
}
public function org(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Org::class);
}
}