<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class PurchaseItem extends Model
{
    protected $fillable = ['purchase_id', 'product_id', 'unit_id', 'product_name_en_snapshot', 'product_name_ar_snapshot', 'unit_snapshot', 'conversion_factor', 'quantity', 'free_quantity', 'base_quantity', 'unit_cost', 'gross_amount', 'discount_amount', 'taxable_amount', 'vat_rate_snapshot', 'vat_amount', 'line_total', 'batch_number', 'expiry_date'];
    protected $casts = ['expiry_date' => 'date', 'conversion_factor' => 'decimal:4', 'quantity' => 'decimal:4', 'free_quantity' => 'decimal:4', 'base_quantity' => 'decimal:4', 'unit_cost' => 'decimal:4', 'gross_amount' => 'decimal:2', 'discount_amount' => 'decimal:2', 'taxable_amount' => 'decimal:2', 'vat_rate_snapshot' => 'decimal:2', 'vat_amount' => 'decimal:2', 'line_total' => 'decimal:2'];
    public function purchase() { return $this->belongsTo(Purchase::class); }
    public function product() { return $this->belongsTo(Product::class); }
    public function unit() { return $this->belongsTo(Unit::class); }
    public function purchaseReturnItems() { return $this->hasMany(PurchaseReturnItem::class); }
}
