<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class InventoryTransaction extends Model
{
    use HasFactory;

    protected $table = "inventory_transactions";
    
    protected $fillable = [
        'transaction_type',
        'code',
        'description',
        'debit_credit',
        'debit_ledger_account_id',
        'credit_ledger_account_id',
        'tax_account_id',
        'always_prompt_credit',
        'always_split_credit',
        'use_tax'
    ];

    protected $casts = [
        'always_prompt_credit' => 'boolean',
        'always_split_credit'  => 'boolean',
        'use_tax'              => 'boolean',
    ];

    public function debitLedgerAccount()
    {
        return $this->belongsTo(GeneralLedger::class, 'debit_ledger_account_id');
    }

    public function creditLedgerAccount()
    {
        return $this->belongsTo(GeneralLedger::class, 'credit_ledger_account_id');
    }

    public function taxAccount()
    {
        return $this->belongsTo(GeneralLedger::class, 'tax_account_id');
    }
}