<?php

namespace App\Models;

use App\Models\Concerns\BranchScoped;

use Illuminate\Database\Eloquent\Model;

class JournalEntry extends Model
{
    use BranchScoped;
    protected $fillable = ['journal_no', 'entry_date', 'reference_type', 'reference_id', 'reference_number', 'description', 'total_debit', 'total_credit', 'status', 'branch_id', 'financial_year_id', 'created_by', 'posted_at'];
    protected $casts = ['entry_date' => 'date', 'posted_at' => 'datetime', 'total_debit' => 'decimal:2', 'total_credit' => 'decimal:2'];

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