<?php

namespace App\Models;

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

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

    protected $fillable = [
        'journal_entry_id',
        'account_id',
        'debit',
        'credit'
    ];

    /**
     * Relasi balik ke Header Jurnal[cite: 8]
     */
    public function header(): BelongsTo
    {
        return $this->belongsTo(JournalEntry::class, 'journal_entry_id');
    }

    /**
     * Relasi ke Master Akun (COA)[cite: 8]
     */
    public function account(): BelongsTo
    {
        return $this->belongsTo(Account::class, 'account_id');
    }
}