'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); } }