<commit_before><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Auth;
use DB;

class ReportsController extends Controller {
    public function get() {
        $user = Auth::user();

        $currentYear = date('Y');

        //
        $monthlyEarnings = [];

        for ($i = 1; $i <= 12; $i ++) {
            $monthlyEarnings[] = $user->earnings()->whereRaw('MONTH(date) = ?', [$i])->sum('amount');
        }

        $monthlySpendings = [];

        for ($i = 1; $i <= 12; $i ++) {
            $monthlySpendings[] = $user->spendings()->whereRaw('MONTH(date) = ?', [$i])->sum('amount');
        }

        //
        $tl = [];
        $tc = [];
        $td = [];

        foreach ($user->spendings()->whereNotNull('tag_id')->get() as $spending) {
            $hit = null;

            for ($i = 0; $i < count($tl); $i ++) {
                if ($tl[$i] == $spending->tag->name) {
                    $hit = $i;

                    break;
                }
            }

            if (!is_numeric($hit)) {
                $tl[] = $spending->tag->name;
                $tc[] = '#' . dechex(rand(0x000000, 0xFFFFFF));
                $td[] = $spending->amount;
            } else {
                $td[$i] += $spending->amount;
            }
        }

        //
        return view('reports', compact('currentYear', 'monthlyEarnings', 'monthlySpendings', 'tl', 'tc', 'td'));
    }
}<commit_msg>Update queries in ReportsController to only return results from current year<commit_after><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Auth;
use DB;

class ReportsController extends Controller {
    public function get() {
        $user = Auth::user();

        $currentYear = date('Y');

        //
        $monthlyEarnings = [];

        for ($i = 1; $i <= 12; $i ++) {
            $monthlyEarnings[] = $user
                ->earnings()
                ->whereRaw('MONTH(date) = ?', [$i])
                ->whereRaw('YEAR(date) = ?', [$currentYear])
                ->sum('amount');
        }

        $monthlySpendings = [];

        for ($i = 1; $i <= 12; $i ++) {
            $monthlySpendings[] = $user
                ->spendings()
                ->whereRaw('MONTH(date) = ?', [$i])
                ->whereRaw('YEAR(date) = ?', [$currentYear])
                ->sum('amount');
        }

        //
        $tl = [];
        $tc = [];
        $td = [];

        foreach ($user->spendings()->whereRaw('YEAR(date)', [$currentYear])->whereNotNull('tag_id')->get() as $spending) {
            $hit = null;

            for ($i = 0; $i < count($tl); $i ++) {
                if ($tl[$i] == $spending->tag->name) {
                    $hit = $i;

                    break;
                }
            }

            if (!is_numeric($hit)) {
                $tl[] = $spending->tag->name;
                $tc[] = '#' . dechex(rand(0x000000, 0xFFFFFF));
                $td[] = $spending->amount;
            } else {
                $td[$i] += $spending->amount;
            }
        }

        //
        return view('reports', compact('currentYear', 'monthlyEarnings', 'monthlySpendings', 'tl', 'tc', 'td'));
    }
}
{'fraction_non_alphanumeric': 0.1938936103242052, 'fraction_numerical': 0.009442870632672332, 'mean_word_length': 1.5122529644268774, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5702732', 'n_tokens_mistral': 1047, 'n_tokens_neox': 963, 'n_words': 183}