<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class reports extends MX_Controller {

	public function __construct()
	{
		parent::__construct();

		if (!$this->session->userdata('admin')) redirect('admin/login');

		$this->load->model("reports_model");
		$this->load->model("clients_model");
	}

	function index()
	{
		$client_id = $this->input->get('client_id') ?: null;

		// Dados financeiros / honorários
		$data['months']      = $this->reports_model->get_earning_by_month();
		$data['weeks']       = $this->reports_model->get_earning_by_week();
		$data['years']       = $this->reports_model->get_earning_by_year();
		$data['clients']     = $this->reports_model->get_earning_by_client();
		$data['fin_months']  = $this->reports_model->get_financeiro_by_month($client_id);
		$data['fin_clients'] = $this->reports_model->get_financeiro_by_client();
		$data['all_clients'] = $this->clients_model->get_all_clients();
		$data['client_id']   = $client_id;

		// Dados ampliados do dashboard de relatórios
		$data['new_clients']    = $this->reports_model->get_new_clients_by_month();
		$data['new_cases']      = $this->reports_model->get_new_cases_by_month();
		$data['cases_by_stage'] = $this->reports_model->get_cases_by_stage();
		$data['cases_by_cat']   = $this->reports_model->get_cases_by_category();
		$data['productivity']   = $this->reports_model->get_productivity_by_user();
		$data['diligencias']    = $this->reports_model->get_diligencias_by_month();
		$data['appointments']   = $this->reports_model->get_appointments_by_month();
		$data['kpis']           = $this->reports_model->get_kpis();

		$data['page_title'] = lang('reports');
		$data['body']       = 'reports/reports';
		$this->load->view('template/main', $data);
	}
}
