<?php

defined('BASEPATH') or exit('No direct script access allowed');

class Propertybase_reports extends AdminController
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('propertybase_model');
        $this->load->model('propertyreports_model');

        hooks()->do_action('propertybase_init');
    }

    public function index()
    {
        if (!has_permission('propertybase_reports', '', 'view')) {
            access_denied('propertybase_reports');
        }

        $data['property_location_map_chart'] = $this->propertyreports_model->propertyLocationOnMapChart();
        $data['category_distribution'] = $this->propertyreports_model->getPropertyCategoryDistribution();
        $data['leads_by_month'] = $this->propertyreports_model->getPropertyLeadsByMonth();
        $data['leads_monthly'] = $this->propertyreports_model->getLeadsPerMonthCurrentYear();
        $data['property_ownership_distribution'] = $this->propertyreports_model->getPropertyOwnershipDistribution();
        $data['maintenance_requests_by_property'] = $this->propertyreports_model->getMaintenanceRequestsByProperty();

        $data['property_summary_data'] = $this->propertyreports_model->getPropertySummaryData();

        $data['title'] = _l('propertybase_properties') . ' - ' . _l('propertybase_reports');

        $data = hooks()->apply_filters('propertybase_reports_manage_data', $data);

        $this->load->view('admin/reports/manage', $data);
    }
}