Files
sam-api/app/Models/Items/ItemReceipt.php
권혁성 189b38c936 feat: Auditable 트레이트 구현 및 97개 모델 적용
- 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>
2026-01-29 15:33:54 +09:00

110 lines
2.6 KiB
PHP

<?php
namespace App\Models\Items;
use App\Models\Members\User;
use App\Traits\Auditable;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 품목 입고 모델
*
* @property int $id
* @property int|null $item_id 품목 ID
* @property int $tenant_id 테넌트 ID
* @property string $receipt_date 입고일
* @property string $lot_number LOT번호
* @property float $received_qty 입고수량
* @property string $unit 단위
* @property string|null $supplier_name 공급업체명
* @property string|null $manufacturer_name 제조업체명
* @property float|null $purchase_price_excl_vat 매입단가(부가세 제외)
* @property float|null $weight_kg 중량(kg)
* @property string $status_code 상태코드
* @property string $is_inspection 검사여부 (Y/N)
* @property string|null $inspection_date 검사일
* @property string|null $remarks 비고
*
* @mixin IdeHelperItemReceipt
*/
class ItemReceipt extends Model
{
use Auditable, BelongsToTenant, SoftDeletes;
protected $table = 'item_receipts';
protected $fillable = [
'item_id',
'tenant_id',
'receipt_date',
'lot_number',
'received_qty',
'unit',
'supplier_name',
'manufacturer_name',
'purchase_price_excl_vat',
'weight_kg',
'status_code',
'is_inspection',
'inspection_date',
'remarks',
'created_by',
'updated_by',
];
protected $casts = [
'receipt_date' => 'date',
'inspection_date' => 'date',
'received_qty' => 'decimal:2',
'purchase_price_excl_vat' => 'decimal:2',
'weight_kg' => 'decimal:2',
];
// ===== Relationships =====
/**
* 품목
*/
public function item()
{
return $this->belongsTo(Item::class, 'item_id');
}
/**
* 생성자
*/
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
// ===== Scopes =====
/**
* 특정 품목의 입고 내역
*/
public function scopeForItem($query, int $itemId)
{
return $query->where('item_id', $itemId);
}
/**
* 특정 일자 이전 입고
*/
public function scopeBeforeDate($query, string $date)
{
return $query->where('receipt_date', '<=', $date);
}
/**
* 단가가 있는 입고만
*/
public function scopeWithPrice($query)
{
return $query->whereNotNull('purchase_price_excl_vat')
->where('purchase_price_excl_vat', '>', 0);
}
}