Files
verifikator/app/Models/Verifikator/PengajuanPresensi.php
T
2026-10-02 19:54:23 +07:00

112 lines
2.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',
'file_lampiran',
'siska_id',
'dawai_id',
'status',
'status_id',
];
function setFileAttribute($value): void
{
// Link eksternal (mis. Google Drive pada tugas dinas) disimpan utuh.
if (str_starts_with((string) $value, 'http')) {
$this->attributes['file'] = $value;
return;
}
$file = explode('/', $value);
$this->attributes['file'] = end($file);
}
function getFileAttribute($value): string
{
if (str_starts_with((string) $value, 'http')) {
return $value;
}
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 setFileLampiranAttribute($value): void
{
if ($value === null) {
$this->attributes['file_lampiran'] = null;
return;
}
$file = explode('/', $value);
$this->attributes['file_lampiran'] = end($file);
}
function getFileLampiranAttribute($value): ?string
{
if ($value === null) {
return null;
}
if ($this->bdr_id === null) {
return asset("storage/$this->tipe/presensi/$this->periode/$value");
}
return config('baseUri.presensi') . "storage/izin/" . $value;
}
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');
}
}