<commit_before><?php

namespace MyBudget\BackendBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;


class DefaultController extends Controller
{
    
    /*
     * index() action (Dashboard)
     * @desc Renders the dashboard
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getEntityManager();
        $entryRepository = $em->getRepository('EntryBundle:Entry');
        $categoryRepository = $em->getRepository('CategoryBundle:Category');
        $request = $this->get('request');

        $oldest = $entryRepository->getOldest();
        $newest = $entryRepository->getNewest();
        $balance = $entryRepository->getBalance();
        $balance_class = ($balance < 0)? 'negative' : 'positive';

        $today = new \DateTime();
        $aux = new \DateTime();
        $prevMonth = $aux->modify('-1 month');
        $entries = $entryRepository->getFromTo(
            new \DateTime($prevMonth->format('Y-m-01')),
            new \DateTime($today->format('Y-m-t'))
        );
        
        $ing = $out = array(
            'current' => 0,
            'previous' => 0,
        );
        if (count($entries)) {
            foreach ($entries as $entry) {
                $key = ($entry->getDateEntry()->format('m') == $today->format('m'))? 'current' : 'previous';
                if ($entry->getHaber())
                    $ing[$key] += $entry->getValue();
                else
                    $out[$key] += $entry->getValue();
            }
        }

        //Get targets from last two months
        $targetRepository = $em->getRepository('BackendBundle:Target');
        $targets = $targetRepository->findBy(
            array(), //Criteria (Filtering)
            array('month' => 'desc'), //OrderBy (Sortering)
            2,
            0
        );

        return $this->render('BackendBundle:Default:index.html.twig', array(
        	'since' => $oldest->getDateEntry(),
        	'until' => $newest->getDateEntry(),
        	'balance' => $balance,
            'balance_class' => $balance_class,
            'today' => $today,
            'prevMonth' => $prevMonth,
            'ing' => $ing,
            'out' => $out,
            'targets' => $targets
    	));
    }

    /*
     * categoryStats() action (Component shown on Dashboard)
     * @desc Renders the category stats (and chart)
     */
    public function categoryStatsAction($category_id, $today)
    {
        $em = $this->getDoctrine()->getEntityManager();
        $categoryRepository = $em->getRepository('CategoryBundle:Category');
        $request = $this->get('request');
        $inflation = array(
            'monthly' => 0,
            'quarterly' => 0,
            'biannually' => 0,
            'annual' => 0
        );

        if (is_null($today)) {
            $today = new \DateTime();
        }
        $todayTimestamp = $today->getTimestamp();
        $thisYear = date('Y', $todayTimestamp);
        $thisMonth = date('n', $todayTimestamp);
        $lastMonthTimestamp = $today->modify('-1 month')->getTimestamp();
        $lastYear = date('Y', $lastMonthTimestamp);
        $lastMonth = date('n', $lastMonthTimestamp);
        $startYear = ($lastMonth == 12)? $thisYear : $thisYear - 1;
        $startMonth = ($lastMonth == 12)? 1 : $lastMonth + 1;

        //Get categories
        $categories = $categoryRepository->findBy(
            array(), //Criteria (Filtering)<commit_msg>Fixed minor bug on charts when we change the year<commit_after><?php

namespace MyBudget\BackendBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;


class DefaultController extends Controller
{
    
    /*
     * index() action (Dashboard)
     * @desc Renders the dashboard
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getEntityManager();
        $entryRepository = $em->getRepository('EntryBundle:Entry');
        $categoryRepository = $em->getRepository('CategoryBundle:Category');
        $request = $this->get('request');

        $oldest = $entryRepository->getOldest();
        $newest = $entryRepository->getNewest();
        $balance = $entryRepository->getBalance();
        $balance_class = ($balance < 0)? 'negative' : 'positive';

        $today = new \DateTime();
        $aux = new \DateTime();
        $prevMonth = $aux->modify('-1 month');
        $entries = $entryRepository->getFromTo(
            new \DateTime($prevMonth->format('Y-m-01')),
            new \DateTime($today->format('Y-m-t'))
        );
        
        $ing = $out = array(
            'current' => 0,
            'previous' => 0,
        );
        if (count($entries)) {
            foreach ($entries as $entry) {
                $key = ($entry->getDateEntry()->format('m') == $today->format('m'))? 'current' : 'previous';
                if ($entry->getHaber())
                    $ing[$key] += $entry->getValue();
                else
                    $out[$key] += $entry->getValue();
            }
        }

        //Get targets from last two months
        $targetRepository = $em->getRepository('BackendBundle:Target');
        $targets = $targetRepository->findBy(
            array(), //Criteria (Filtering)
            array('month' => 'desc'), //OrderBy (Sortering)
            2,
            0
        );

        return $this->render('BackendBundle:Default:index.html.twig', array(
        	'since' => $oldest->getDateEntry(),
        	'until' => $newest->getDateEntry(),
        	'balance' => $balance,
            'balance_class' => $balance_class,
            'today' => $today,
            'prevMonth' => $prevMonth,
            'ing' => $ing,
            'out' => $out,
            'targets' => $targets
    	));
    }

    /*
     * categoryStats() action (Component shown on Dashboard)
     * @desc Renders the category stats (and chart)
     */
    public function categoryStatsAction($category_id, $today)
    {
        $em = $this->getDoctrine()->getEntityManager();
        $categoryRepository = $em->getRepository('CategoryBundle:Category');
        $request = $this->get('request');
        $inflation = array(
            'monthly' => 0,
            'quarterly' => 0,
            'biannually' => 0,
            'annual' => 0
        );

        if (is_null($today)) {
            $today = new \DateTime();
        }
        $todayTimestamp = $today->getTimestamp();
        $thisYear = date('Y', $todayTimestamp);
        $thisMonth = date('n', $todayTimestamp);
        $lastMonthTimestamp = $today->modify('-1 month')->getTimestamp();
        $lastYear = date('Y', $lastMonthTimestamp);
        $lastMonth = date('n', $lastMonthTimestamp);
        $startYear = ($lastMonth == 12)? $thisYear - 1 : $thisYear;
        $startMonth = ($lastMonth == 12)? 1 : $lastMonth + 1;

        //Get categories
        $categories = $categoryRepository->findBy(
            array(), //Criteria (Filtering)
{'fraction_non_alphanumeric': 0.16291161178509533, 'fraction_numerical': 0.005777007510109763, 'mean_word_length': 2.086007130124777, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 97, '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': '2766685', 'n_tokens_mistral': 1996, 'n_tokens_neox': 1912, 'n_words': 392}