<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use App\Models\Account;

class JournalEntry extends Model
{
    // Nama tabel sesuai dengan file SQL Anda[cite: 4]
    protected $table = 'journal_entries';

    protected $fillable = [
        'branch_id',
        'entry_date',
        'description',
        'reference',
        'source_type',
        'user_id'
    ];

    /**
     * Relasi ke baris detail Debit/Kredit
     */
    public function items()
{
    return $this->hasMany(JournalItem::class, 'journal_entry_id');
}

    /**
     * Relasi ke Cabang[cite: 4]
     */
    public function branch(): BelongsTo
    {
        return $this->belongsTo(Branch::class, 'branch_id');
    }

    /**
     * Relasi ke Pembuat Jurnal[cite: 8]
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class, 'user_id');
    }
}