- 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>
107 lines
2.3 KiB
PHP
107 lines
2.3 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;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Withdrawal extends Model
|
|
{
|
|
use Auditable, BelongsToTenant, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'withdrawal_date',
|
|
'used_at',
|
|
'client_id',
|
|
'client_name',
|
|
'merchant_name',
|
|
'bank_account_id',
|
|
'card_id',
|
|
'amount',
|
|
'payment_method',
|
|
'account_code',
|
|
'description',
|
|
'reference_type',
|
|
'reference_id',
|
|
'created_by',
|
|
'updated_by',
|
|
'deleted_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'withdrawal_date' => 'date',
|
|
'used_at' => 'datetime',
|
|
'amount' => 'decimal:2',
|
|
'client_id' => 'integer',
|
|
'bank_account_id' => 'integer',
|
|
'card_id' => 'integer',
|
|
'reference_id' => 'integer',
|
|
];
|
|
|
|
/**
|
|
* 결제수단 목록
|
|
*/
|
|
public const PAYMENT_METHODS = [
|
|
'cash' => '현금',
|
|
'transfer' => '계좌이체',
|
|
'card' => '카드',
|
|
'check' => '수표',
|
|
];
|
|
|
|
/**
|
|
* 거래처 관계
|
|
*/
|
|
public function client(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Models\Orders\Client::class);
|
|
}
|
|
|
|
/**
|
|
* 출금 계좌 관계
|
|
*/
|
|
public function bankAccount(): BelongsTo
|
|
{
|
|
return $this->belongsTo(BankAccount::class);
|
|
}
|
|
|
|
/**
|
|
* 카드 관계
|
|
*/
|
|
public function card(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Card::class);
|
|
}
|
|
|
|
/**
|
|
* 생성자 관계
|
|
*/
|
|
public function creator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Models\Members\User::class, 'created_by');
|
|
}
|
|
|
|
/**
|
|
* 거래처명 조회 (회원/비회원 통합)
|
|
*/
|
|
public function getDisplayClientNameAttribute(): string
|
|
{
|
|
if ($this->client) {
|
|
return $this->client->name;
|
|
}
|
|
|
|
return $this->client_name ?? '';
|
|
}
|
|
|
|
/**
|
|
* 결제수단 라벨
|
|
*/
|
|
public function getPaymentMethodLabelAttribute(): string
|
|
{
|
|
return self::PAYMENT_METHODS[$this->payment_method] ?? $this->payment_method;
|
|
}
|
|
}
|