<commit_before><?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Expenses extends CI_Controller {
    
    public function __construct()
    {
        parent::__construct();
        // Your own constructor code
        
        // Load Helpers
        $this->load->helper('url');
        $this->load->helper('uuid_helper');
        
        // Load Database
        $this->load->database();
        
        // Load Models
        $this->load->model('Expenses_model');
    }
    
    public function index()
    {    
        if ( ! $this->session->gorillaUuid)
        {
            redirect('/user');
        }
        
        $data = array(
            'gorillaUuid' => $this->session->gorillaUuid,
        );
        
        $this->load->view('templates/header', $data);
        $this->load->view('expenses/index', $data);
        $this->load->view('templates/footer', $data);
    }
    
    public function add()
    {
        $valid = true;
        $requiredFields = array('uuid', 'amount', 'category', 'merchant', 'location', 'datestamp');
        
        $data = array(
            'uuid'          => $this->session->gorillaUuid,
            'amount'        => number_format((float)$this->input->post('amount'), 2, '.', ''),
            'category'      => ucfirst( $this->input->post('category') ),
            'merchant'      => ucfirst( $this->input->post('merchant') ),
            'location'      => ucfirst( $this->input->post('location') ),
            'description'   => ucfirst( $this->input->post('description') ),
            'datestamp'     => $this->input->post('datestamp'),
            'deductable'    => $this->input->post('deductable'),
        );
        
        foreach ($requiredFields as $field)
        {
            if ( ! array_key_exists($field, $requiredFields) )
            {
                $valid = false;
                break;
            }
        }
        
        if ( $valid )
            echo $this->Expenses_model->add($data);
        else
            echo "error";
    }
    
    public function listing()
    {
        $this->load->library('parser');
        
        // Get all Categories
        $this->db->distinct();
        $this->db->select('category');
        //$this->db->where('timestamp = DATE_SUB(NOW(), INTERVAL 1 MONTH)');
        $this->db->where('uuid', $this->session->gorillaUuid);
        $categories = $this->db->get('expenses');

        if ($categories->num_rows() > 0)
        {
            // Initialize grand total for expenses
            $grandTotal = 0;
            
            // Get categories in an array and then sort it
            $categoriesArray = array();
            foreach ($categories->result() as $result)
            {
                array_push($categoriesArray, $result->category);
            }
            sort($categoriesArray);
            
            // Go through each category and get all the expenses
            foreach ($categoriesArray as $category)
            {
                // Get All Expenses for category
                $this->db->where('category', $category);
                $this->db->where('uuid', $this->session->gorillaUuid);
                //$this->db->where('timestamp = DATE_SUB(NOW(), INTERVAL 1 MONTH)');
                $expenses = $this->db->get('expenses');
                
                $total = 0;
                foreach ($expenses->result() as $expense)
                {
                    $total = $total + $expense->amount;
                }

                $grandTotal = $grandTotal + $total;

                $data = array(
                    'total' => number_format((float)$total, 2, '.', ''),
                    'category' => $category,
                    'expenses_listings' => $expenses->result_array()
                );

                $this->parser->parse('expenses/listing_parser', $data);
            }
    
            $data = array(
                'grandTotal' => number_format((float)$grandTotal, 2, '.', ''),
            );

            $this->parser->parse('expenses/grand_total', $data);
        }
        else
        {
            $data = array(
                'gorillaUuid'   => $this->session->gorillaUuid,
                'message'      => "No expenses listed. You should add some!",
            );

            $this->load->view('expenses/message', $data);
        }
    }
    
}
<commit_msg>haaaands<commit_after><?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Expenses extends CI_Controller {
    
    public function __construct()
    {
        parent::__construct();
        // Your own constructor code
        
        // Load Helpers
        $this->load->helper('url');
        $this->load->helper('uuid_helper');
        
        // Load Database
        $this->load->database();
        
        // Load Models
        $this->load->model('Expenses_model');
    }
    
    public function index()
    {    
        if ( ! $this->session->gorillaUuid)
        {
            redirect('/user');
        }
        
        $data = array(
            'gorillaUuid' => $this->session->gorillaUuid,
        );
        
        $this->load->view('templates/header', $data);
        $this->load->view('expenses/index', $data);
        $this->load->view('templates/footer', $data);
    }
    
    public function add()
    {
        $valid = true;
        $requiredFields = array('uuid', 'amount', 'category', 'merchant', 'location', 'datestamp');
        
        $data = array(
            'uuid'          => $this->session->gorillaUuid,
            'amount'        => number_format((float)$this->input->post('amount'), 2, '.', ''),
            'category'      => ucfirst( $this->input->post('category') ),
            'merchant'      => ucfirst( $this->input->post('merchant') ),
            'location'      => ucfirst( $this->input->post('location') ),
            'description'   => ucfirst( $this->input->post('description') ),
            'datestamp'     => $this->input->post('datestamp'),
            'deductable'    => $this->input->post('deductable'),
        );
        
        /*
        foreach ($requiredFields as $field)
        {
            if ( ! array_key_exists($field, $requiredFields) )
            {
                $valid = false;
                break;
            }
        }
        */
        
        //if ( $valid )
            echo $this->Expenses_model->add($data);
        //else
            //echo "error";
    }
    
    public function listing()
    {
        $this->load->library('parser');
        
        // Get all Categories
        $this->db->distinct();
        $this->db->select('category');
        //$this->db->where('timestamp = DATE_SUB(NOW(), INTERVAL 1 MONTH)');
        $this->db->where('uuid', $this->session->gorillaUuid);
        $categories = $this->db->get('expenses');

        if ($categories->num_rows() > 0)
        {
            // Initialize grand total for expenses
            $grandTotal = 0;
            
            // Get categories in an array and then sort it
            $categoriesArray = array();
            foreach ($categories->result() as $result)
            {
                array_push($categoriesArray, $result->category);
            }
            sort($categoriesArray);
            
            // Go through each category and get all the expenses
            foreach ($categoriesArray as $category)
            {
                // Get All Expenses for category
                $this->db->where('category', $category);
                $this->db->where('uuid', $this->session->gorillaUuid);
                //$this->db->where('timestamp = DATE_SUB(NOW(), INTERVAL 1 MONTH)');
                $expenses = $this->db->get('expenses');
                
                $total = 0;
                foreach ($expenses->result() as $expense)
                {
                    $total = $total + $expense->amount;
                }

                $grandTotal = $grandTotal + $total;

                $data = array(
                    'total' => number_format((float)$total, 2, '.', ''),
                    'category' => $category,
                    'expenses_listings' => $expenses->result_array()
                );

                $this->parser->parse('expenses/listing_parser', $data);
            }
    
            $data = array(
                'grandTotal' => number_format((float)$grandTotal, 2, '.', ''),
            );

            $this->parser->parse('expenses/grand_total', $data);
        }
        else
        {
            $data = array(
                'gorillaUuid'   => $this->session->gorillaUuid,
                'message'      => "No expenses listed. You should add some!",
            );

            $this->load->view('expenses/message', $data);
        }
    }
    
}

{'fraction_non_alphanumeric': 0.15704073527743106, 'fraction_numerical': 0.0018154998297968909, 'mean_word_length': 1.4723702664796634, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 183, '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': '653461', 'n_tokens_mistral': 2426, 'n_tokens_neox': 2329, 'n_words': 436}