- Auditable 트레이트 신규 생성 (bootAuditable 패턴) - creating: created_by/updated_by 자동 채우기 - updating: updated_by 자동 채우기 - deleting: deleted_by 채우기 + saveQuietly() - created/updated/deleted: audit_logs 자동 기록 - 기존 AuditLogger 패턴과 동일한 try/catch 조용한 실패 - 변경된 필드만 before/after 기록 (updated 이벤트) - auditExclude 프로퍼티로 모델별 제외 필드 설정 가능 - 제외 대상: Attendance, StockTransaction, TodayIssue 등 고빈도/시스템 모델 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
129 lines
3.5 KiB
PHP
129 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Tenants;
|
|
|
|
use App\Traits\Auditable;
|
|
use App\Traits\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* 휴가 정책 모델
|
|
*
|
|
* @property int $id
|
|
* @property int $tenant_id
|
|
* @property string $standard_type
|
|
* @property int $fiscal_start_month
|
|
* @property int $fiscal_start_day
|
|
* @property int $default_annual_leave
|
|
* @property int $additional_leave_per_year
|
|
* @property int $max_annual_leave
|
|
* @property bool $carry_over_enabled
|
|
* @property int $carry_over_max_days
|
|
* @property int $carry_over_expiry_months
|
|
* @property int|null $created_by
|
|
* @property int|null $updated_by
|
|
*/
|
|
class LeavePolicy extends Model
|
|
{
|
|
use Auditable, BelongsToTenant;
|
|
|
|
protected $table = 'leave_policies';
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'standard_type',
|
|
'fiscal_start_month',
|
|
'fiscal_start_day',
|
|
'default_annual_leave',
|
|
'additional_leave_per_year',
|
|
'max_annual_leave',
|
|
'carry_over_enabled',
|
|
'carry_over_max_days',
|
|
'carry_over_expiry_months',
|
|
'created_by',
|
|
'updated_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'fiscal_start_month' => 'integer',
|
|
'fiscal_start_day' => 'integer',
|
|
'default_annual_leave' => 'integer',
|
|
'additional_leave_per_year' => 'integer',
|
|
'max_annual_leave' => 'integer',
|
|
'carry_over_enabled' => 'boolean',
|
|
'carry_over_max_days' => 'integer',
|
|
'carry_over_expiry_months' => 'integer',
|
|
];
|
|
|
|
// =========================================================================
|
|
// 상수 정의
|
|
// =========================================================================
|
|
|
|
public const TYPE_FISCAL = 'fiscal';
|
|
|
|
public const TYPE_HIRE = 'hire';
|
|
|
|
public const STANDARD_TYPES = [
|
|
self::TYPE_FISCAL,
|
|
self::TYPE_HIRE,
|
|
];
|
|
|
|
// =========================================================================
|
|
// 관계 정의
|
|
// =========================================================================
|
|
|
|
/**
|
|
* 테넌트
|
|
*/
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
// =========================================================================
|
|
// 헬퍼 메서드
|
|
// =========================================================================
|
|
|
|
/**
|
|
* 기준 유형 라벨
|
|
*/
|
|
public function getStandardTypeLabelAttribute(): string
|
|
{
|
|
return match ($this->standard_type) {
|
|
self::TYPE_FISCAL => '회계연도',
|
|
self::TYPE_HIRE => '입사일',
|
|
default => $this->standard_type,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 기준일 문자열
|
|
*/
|
|
public function getFiscalStartDateStringAttribute(): string
|
|
{
|
|
return "{$this->fiscal_start_month}월 {$this->fiscal_start_day}일";
|
|
}
|
|
|
|
/**
|
|
* 기본 설정 생성
|
|
*/
|
|
public static function createDefault(int $tenantId, ?int $userId = null): self
|
|
{
|
|
return self::create([
|
|
'tenant_id' => $tenantId,
|
|
'standard_type' => self::TYPE_FISCAL,
|
|
'fiscal_start_month' => 1,
|
|
'fiscal_start_day' => 1,
|
|
'default_annual_leave' => 15,
|
|
'additional_leave_per_year' => 1,
|
|
'max_annual_leave' => 25,
|
|
'carry_over_enabled' => true,
|
|
'carry_over_max_days' => 10,
|
|
'carry_over_expiry_months' => 3,
|
|
'created_by' => $userId,
|
|
'updated_by' => $userId,
|
|
]);
|
|
}
|
|
}
|