<?php

namespace App\Models\Stats;

use Illuminate\Database\Eloquent\Model;

class StatFinanceMonthly extends Model
{
    protected $connection = 'sam_stat';

    protected $table = 'stat_finance_monthly';

    protected $casts = [
        'stat_year' => 'integer',
        'stat_month' => 'integer',
        'deposit_total' => 'decimal:2',
        'withdrawal_total' => 'decimal:2',
        'net_cashflow' => 'decimal:2',
        'bank_balance_end' => 'decimal:2',
        'receivable_end' => 'decimal:2',
        'payable_end' => 'decimal:2',
    ];

    public function scopeForTenant($query, ?int $tenantId)
    {
        if ($tenantId) {
            return $query->where('tenant_id', $tenantId);
        }

        return $query;
    }

    public function scopeForMonth($query, int $year, int $month)
    {
        return $query->where('stat_year', $year)->where('stat_month', $month);
    }
}
