- 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>
109 lines
2.3 KiB
PHP
109 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 Receiving extends Model
|
|
{
|
|
use Auditable, BelongsToTenant, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'receiving_number',
|
|
'order_no',
|
|
'order_date',
|
|
'item_id',
|
|
'item_code',
|
|
'item_name',
|
|
'specification',
|
|
'supplier',
|
|
'order_qty',
|
|
'order_unit',
|
|
'due_date',
|
|
'receiving_qty',
|
|
'receiving_date',
|
|
'lot_no',
|
|
'supplier_lot',
|
|
'receiving_location',
|
|
'receiving_manager',
|
|
'status',
|
|
'remark',
|
|
'created_by',
|
|
'updated_by',
|
|
'deleted_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'order_date' => 'date',
|
|
'due_date' => 'date',
|
|
'receiving_date' => 'date',
|
|
'order_qty' => 'decimal:2',
|
|
'receiving_qty' => 'decimal:2',
|
|
'item_id' => 'integer',
|
|
];
|
|
|
|
/**
|
|
* 상태 목록
|
|
*/
|
|
public const STATUSES = [
|
|
'order_completed' => '발주완료',
|
|
'shipping' => '배송중',
|
|
'inspection_pending' => '검사대기',
|
|
'receiving_pending' => '입고대기',
|
|
'completed' => '입고완료',
|
|
];
|
|
|
|
/**
|
|
* 품목 관계
|
|
*/
|
|
public function item(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Models\Items\Item::class);
|
|
}
|
|
|
|
/**
|
|
* 생성자 관계
|
|
*/
|
|
public function creator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Models\Members\User::class, 'created_by');
|
|
}
|
|
|
|
/**
|
|
* 상태 라벨
|
|
*/
|
|
public function getStatusLabelAttribute(): string
|
|
{
|
|
return self::STATUSES[$this->status] ?? $this->status;
|
|
}
|
|
|
|
/**
|
|
* 수정 가능 여부
|
|
*/
|
|
public function canEdit(): bool
|
|
{
|
|
return $this->status !== 'completed';
|
|
}
|
|
|
|
/**
|
|
* 삭제 가능 여부
|
|
*/
|
|
public function canDelete(): bool
|
|
{
|
|
return $this->status !== 'completed';
|
|
}
|
|
|
|
/**
|
|
* 입고처리 가능 여부
|
|
*/
|
|
public function canProcess(): bool
|
|
{
|
|
return in_array($this->status, ['order_completed', 'shipping', 'inspection_pending', 'receiving_pending']);
|
|
}
|
|
}
|