<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class StockLedger extends Model
{
    protected $fillable = [
        'transaction_date', 'transaction_type', 'reference_type',
        'reference_id', 'reference_number', 'product_id', 'warehouse_id',
        'unit_id', 'qty_in', 'qty_out', 'base_qty_in', 'base_qty_out',
        'unit_cost', 'total_cost', 'running_quantity', 'batch_id', 'expiry',
        'branch_id', 'financial_year_id', 'created_by',
    ];

    protected $casts = [
        'transaction_date'  => 'date',
        'qty_in'            => 'decimal:4',
        'qty_out'           => 'decimal:4',
        'base_qty_in'       => 'decimal:4',
        'base_qty_out'      => 'decimal:4',
        'unit_cost'         => 'decimal:4',
        'total_cost'        => 'decimal:4',
        'running_quantity'  => 'decimal:4',
        'expiry'            => 'date',
    ];

    public function product()
    {
        return $this->belongsTo(Product::class);
    }

    public function warehouse()
    {
        return $this->belongsTo(Warehouse::class);
    }

    public function unit()
    {
        return $this->belongsTo(Unit::class);
    }

    public function createdBy()
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
