belongsTo(Account::class, 'account_number', 'account_number'); } /** * Scope a query to filter by account number. */ public function scopeForAccount($query, $accountNumber) { return $query->where('account_number', $accountNumber); } /** * Scope a query to filter by period. */ public function scopeForPeriod($query, $period) { return $query->where('period', $period); } /** * Get balance for a specific account and period. * * @param string $accountNumber * @param string $period Format: YYYY-MM * @return AccountBalance|null */ public static function getBalance($accountNumber, $period) { return self::where('account_number', $accountNumber) ->where('period', $period) ->first(); } }