<?php
declare(strict_types=1);

namespace App\Modules\Accounting\Models;

use App\Core\Model;

class DailyTransaction extends Model
{
    protected static string $table = 'daily_transactions';
    protected static array $fillable = [
        'transaction_date', 'journal_type_id', 'account_id', 'cost_center_id',
        'amount', 'direction', 'description', 'document_number', 'currency',
        'is_consolidated', 'consolidated_entry_id', 'branch_id', 'created_by',
    ];
    protected static bool $timestamps = false;
    protected static bool $softDelete = false;

    public static function getUnconsolidated(?string $date = null): array
    {
        $qb = static::query()->where('is_consolidated', '=', 0);
        if ($date) {
            $qb->where('transaction_date', '=', $date);
        }
        return $qb->orderBy('transaction_date', 'ASC')->get();
    }

    public static function getByDate(string $date): array
    {
        return static::query()
            ->where('transaction_date', '=', $date)
            ->orderBy('id', 'ASC')
            ->get();
    }
}
