Files
verifikator/app/Models/Verifikator/PengajuanPresensi.php
T
2026-08-07 10:47:09 +07:00

73 lines
1.8 KiB
PHP

<?php
namespace App\Models\Verifikator;
use App\Models\DokSiremun\CatatanPengajuan;
use App\Models\DokSiremun\LogPengajuan;
use App\Models\Verifikator\View\Pegawai;
use App\Services\DawaiService;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class PengajuanPresensi extends Model
{
use HasFactory, SoftDeletes;
protected $table = 'verifikator.pengajuan_presensis';
protected $fillable = [
'bdr_id',
'nip',
'periode',
'tipe',
'tanggal_mulai',
'tanggal_selesai',
'kategori',
'keterangan',
'file',
'status',
'status_id',
];
function setFileAttribute($value): void
{
$file = explode('/', $value);
$this->attributes['file'] = end($file);
}
function getFileAttribute($value): string
{
if ($this->bdr_id === null) {
$file = asset("storage/$this->tipe/presensi/$this->periode/$value");
} else {
$file = config('baseUri.presensi') . "storage/izin/" . $value;
}
return $file;
}
function getKategoriAttribute($value): string
{
if ($this->periode < Periode::where('status', true)->first()->id_periode) {
return $value;
}
$dawaiService = new DawaiService();
$kategoris = collect($dawaiService->listStatusPresensi());
return $kategoris->where('id', $value)->first()['nama'];
}
function pegawai()
{
return $this->belongsTo(Pegawai::class, 'nip', 'nip');
}
function logs()
{
return $this->morphMany(LogPengajuan::class, 'logable');
}
function notes()
{
return $this->morphMany(CatatanPengajuan::class, 'noteable');
}
}