<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class JournalEntry extends Model
{
    protected $fillable = [
    'reference',
    'expense_id',
    'supplier_id',
    'customer_id', // Add this
    'invoice_id',  // Add this
    'credit_memo_id', // Add this
    'sales_receipt_id', // Add this
    'bill_id',
    'transource',
    'transaction_id', // Now nullable in DB
    'transaction_date', // Added
    'account_id',
    'description',
    'company_id',
    'debit',
    'credit',
    'user_id'
];

    /**
     * Relationship to the Expense (if applicable)
     */
    public function expense(): BelongsTo
    {
        return $this->belongsTo(Expense::class);
    }

    public function transaction(): BelongsTo
    {
        return $this->belongsTo(Transaction::class);
    }

    public function account(): BelongsTo
    {
        return $this->belongsTo(Account::class);
    }

    /**
     * Relationship to the Supplier (if applicable)
     */
    public function supplier(): BelongsTo
    {
        return $this->belongsTo(Supplier::class);
    }
    
    public function creditMemo(){
        
        return $this->belongsTo(CreditMemo::class);
        
    }
    
    
}