'date', 'amount' => 'decimal:2', ]; /** * Get the finance document that owns this entry */ public function financeDocument() { return $this->belongsTo(FinanceDocument::class); } /** * Get the income that owns this entry */ public function income() { return $this->belongsTo(Income::class); } /** * Get the chart of account for this entry */ public function chartOfAccount() { return $this->belongsTo(ChartOfAccount::class); } /** * Check if this is a debit entry */ public function isDebit(): bool { return $this->entry_type === self::ENTRY_TYPE_DEBIT; } /** * Check if this is a credit entry */ public function isCredit(): bool { return $this->entry_type === self::ENTRY_TYPE_CREDIT; } /** * Scope to filter debit entries */ public function scopeDebits($query) { return $query->where('entry_type', self::ENTRY_TYPE_DEBIT); } /** * Scope to filter credit entries */ public function scopeCredits($query) { return $query->where('entry_type', self::ENTRY_TYPE_CREDIT); } /** * Scope to filter by account */ public function scopeForAccount($query, $accountId) { return $query->where('chart_of_account_id', $accountId); } /** * Scope to filter by date range */ public function scopeDateRange($query, $startDate, $endDate) { return $query->whereBetween('entry_date', [$startDate, $endDate]); } }