- 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>
102 lines
2.3 KiB
PHP
102 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Tenants;
|
|
|
|
use App\Models\Orders\Client;
|
|
use App\Traits\Auditable;
|
|
use App\Traits\BelongsToTenant;
|
|
use App\Traits\ModelTrait;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* 비용 계정 모델
|
|
*
|
|
* CEO 대시보드용 비용 데이터 (복리후생비, 접대비 등)
|
|
*/
|
|
class ExpenseAccount extends Model
|
|
{
|
|
use Auditable, BelongsToTenant, HasFactory, ModelTrait, SoftDeletes;
|
|
|
|
protected $table = 'expense_accounts';
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'account_type',
|
|
'sub_type',
|
|
'expense_date',
|
|
'amount',
|
|
'description',
|
|
'receipt_no',
|
|
'vendor_id',
|
|
'vendor_name',
|
|
'payment_method',
|
|
'card_no',
|
|
'created_by',
|
|
'updated_by',
|
|
'deleted_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'expense_date' => 'date',
|
|
'amount' => 'decimal:2',
|
|
];
|
|
|
|
// 계정 유형 상수
|
|
public const TYPE_WELFARE = 'welfare';
|
|
|
|
public const TYPE_ENTERTAINMENT = 'entertainment';
|
|
|
|
public const TYPE_TRAVEL = 'travel';
|
|
|
|
public const TYPE_OFFICE = 'office';
|
|
|
|
// 세부 유형 상수 (복리후생)
|
|
public const SUB_TYPE_MEAL = 'meal';
|
|
|
|
public const SUB_TYPE_HEALTH = 'health';
|
|
|
|
public const SUB_TYPE_EDUCATION = 'education';
|
|
|
|
// 결제 수단 상수
|
|
public const PAYMENT_CARD = 'card';
|
|
|
|
public const PAYMENT_CASH = 'cash';
|
|
|
|
public const PAYMENT_TRANSFER = 'transfer';
|
|
|
|
/**
|
|
* 거래처 관계
|
|
*/
|
|
public function vendor(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Client::class, 'vendor_id');
|
|
}
|
|
|
|
/**
|
|
* 복리후생비 스코프
|
|
*/
|
|
public function scopeWelfare($query)
|
|
{
|
|
return $query->where('account_type', self::TYPE_WELFARE);
|
|
}
|
|
|
|
/**
|
|
* 접대비 스코프
|
|
*/
|
|
public function scopeEntertainment($query)
|
|
{
|
|
return $query->where('account_type', self::TYPE_ENTERTAINMENT);
|
|
}
|
|
|
|
/**
|
|
* 기간 필터 스코프
|
|
*/
|
|
public function scopeInPeriod($query, string $startDate, string $endDate)
|
|
{
|
|
return $query->whereBetween('expense_date', [$startDate, $endDate]);
|
|
}
|
|
}
|