100 lines
2.4 KiB
PHP
100 lines
2.4 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',
|
|
'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 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');
|
|
}
|
|
}
|