Exemplo n.º 1
0
    public function relatorio_diario()
    {
        $msg = null;
        $data = $this->getParametroVisao();
        $data['page'] = 'home';
        $data['tema'] != '' ? $this->load->setTheme($data['tema']) : '';
        $data['msg'] = $msg;
        $data['abaAtiva'] = 24;
        $data['abaPage'] = 'relatorio_diario';
        $data['alias'] = 'relatorio_diario';
        $data['total'] = 0;
        $config['base_url'] = base_url() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/' . $this->uri->segment(3) . '/';
        $querystring = $_SERVER['QUERY_STRING'] != '' ? '?' . $_SERVER['QUERY_STRING'] : '';
        if (!empty($data['unidades'])) {
            if (count($data['unidades']) == 1) {
                $pk_unidade = $data['unidades'][0];
                $data['atendente_unidade'] = 1;
            } else {
                $pk_unidade = isset($_GET['pk_unidade']) && $_GET['pk_unidade'] != '' ? $_GET['pk_unidade'] : 0;
                $data['atendente_unidade'] = 0;
            }
        } else {
            $pk_unidade = isset($_GET['pk_unidade']) && $_GET['pk_unidade'] != '' ? $_GET['pk_unidade'] : 0;
            $data['atendente_unidade'] = 0;
        }
        // Relatório de inscrições por dia
        $sqlAtendimento = new SqlAtendimento();
        $resultado = $sqlAtendimento->get_relatorio_dias($pk_unidade);
        $result = array();
        foreach ($resultado as $row) {
            $result[] = array('data_cadastro' => $row['data_cadastro'], 'total' => $row['total']);
        }
        $data['total'] = count($result);
        $html = '';
        if ($data['total'] > 0) {
            $html .= '<script type="text/javascript" src="https://www.google.com/jsapi"></script>';
            $html .= '<script type="text/javascript">';
            $html .= 'google.load("visualization", "1", {packages:["corechart"]});
                        google.setOnLoadCallback(drawChart);
                        function drawChart() {';
            $html .= '    var data = google.visualization.arrayToDataTable([';
            $html .= '      [\'Sequência\', \'\'],';
            $media = 0;
            $registros = '';
            $i = 0;
            foreach (array_reverse($result) as $dado) {
                $i++;
                $registros .= '      [\'' . View::converteDataBr($dado['data_cadastro']) . '\',  ' . $dado['total'] . '],';
            }
            $html .= substr($registros, 0, -1);
            $html .= '    ]);';
            $html .= '
                        var options = {
                          title: \'Inscrições diárias\',
                          hAxis: {title: \'\', titleTextStyle: {color: \'red\'}}
                        };

                        var chart = new google.visualization.ColumnChart(document.getElementById(\'chart_div\'));

                        chart.draw(data, options);';
            $html .= '  }';
            $html .= '</script>';
            $html .= '<div id="chart_div" style="width: 900px; height: 300px;"></div>';
            $data['html'] = $html;
        } else {
            $data['html'] = "";
        }
        // Relatório distribuição
        $sqlAtendimento = new SqlAtendimento();
        $result = $sqlAtendimento->get_relatorio_distribuição($pk_unidade);
        $total = count($result);
        $html2 = '';
        if ($total > 0) {
            $html2 .= '<script type="text/javascript">
                        google.load("visualization", "1", {packages:["corechart"]});
                        google.setOnLoadCallback(drawChart);
                        function drawChart() {

                            var data = google.visualization.arrayToDataTable([
                            [\'Task\', \'Hours per Day\'],';
            $media = 0;
            $registros = '';
            $i = 0;
            foreach (array_reverse($result) as $dado) {
                $i++;
                $registros .= '      [\'' . $dado['serie_nome'] . '\',  ' . $dado['total'] . '],';
            }
            $html2 .= substr($registros, 0, -1);
            $html2 .= '    ]);';
            $html2 .= '    var options = {
                                title: \'Distribuição por séries\',
                                fontSize:12
                            };';
            $html2 .= '    var chart = new google.visualization.PieChart(document.getElementById(\'piechart\'));';
            $html2 .= '    chart.draw(data, options);';
            $html2 .= '    }';
            $html2 .= '    ';
            $html2 .= '    </script>';
            $html2 .= '<div id="piechart" style="width: 900px; height: 500px;"></div>';
            $data['html2'] = $html2;
        } else {
            $data['html2'] = '';
        }
        // Relatório distribuição
        $sqlAtendimento = new SqlAtendimento();
        $result = $sqlAtendimento->get_relatorio_distribuição_status($pk_unidade);
        $total = count($result);
        $html3 = '';
        if ($total > 0) {
            $html3 .= '<script type="text/javascript">
                        google.load("visualization", "1", {packages:["corechart"]});
                        google.setOnLoadCallback(drawChart);
                        function drawChart() {

                            var data = google.visualization.arrayToDataTable([
                            [\'Task\', \'Hours per Day\'],';
            $media = 0;
            $registros = '';
            $i = 0;
            foreach ($result as $dado) {
                $i++;
                if ($dado['status'] == 1) {
                    $status_nome = 'Potencial';
                } else {
                    if ($dado['status'] == 2) {
                        $status_nome = 'Sondagem';
                    } else {
                        if ($dado['status'] == 3) {
                            $status_nome = 'Matriculado';
                        } else {
                            if ($dado['status'] == 4) {
                                $status_nome = 'Desistente';
                            }
                        }
                    }
                }
                $registros .= '      [\'' . $status_nome . '\',  ' . $dado['total'] . '],';
            }
            $html3 .= substr($registros, 0, -1);
            $html3 .= '    ]);';
            $html3 .= '    var options = {
                                title: \'Distribuição por status\',
                                fontSize:12
                            };';
            $html3 .= '    var chart = new google.visualization.PieChart(document.getElementById(\'piechart2\'));';
            $html3 .= '    chart.draw(data, options);';
            $html3 .= '    }';
            $html3 .= '    </script>';
            $html3 .= '<div id="piechart2" style="width: 900px; height: 500px;"></div>';
            $data['html3'] = $html3;
        } else {
            $data['html3'] = '';
        }
        // Relatório distribuição de desistências
        $sqlAtendimento = new SqlAtendimento();
        $result = $sqlAtendimento->get_relatorio_distribuição_desistencias($pk_unidade);
        $total = count($result);
        $html4 = '';
        if ($total > 0) {
            $html4 .= '<script type="text/javascript">
                        google.load("visualization", "1", {packages:["corechart"]});
                        google.setOnLoadCallback(drawChart);
                        function drawChart() {

                            var data = google.visualization.arrayToDataTable([
                            [\'Task\', \'Hours per Day\'],';
            $media = 0;
            $registros = '';
            $i = 0;
            foreach ($result as $dado) {
                $i++;
                $registros .= '      [\'' . $dado['motivo_desistencia'] . '\',  ' . $dado['total'] . '],';
            }
            $html4 .= substr($registros, 0, -1);
            $html4 .= '    ]);';
            $html4 .= '    var options = {
                                title: \'Motivos de desistência\',
                                fontSize:12
                            };';
            $html4 .= '    var chart = new google.visualization.PieChart(document.getElementById(\'piechart3\'));';
            $html4 .= '    chart.draw(data, options);';
            $html4 .= '    }';
            $html4 .= '    </script>';
            $html4 .= '<div id="piechart3" style="width: 900px; height: 500px;"></div>';
            $data['html4'] = $html4;
        } else {
            $data['html4'] = '';
        }
        // Select filtro de unidade
        $sqlUsuario = new SqlUsuario();
        $data['unidade'] = $sqlUsuario->unidade();
        $unidade = explode("&pk_unidade=", $_SERVER['QUERY_STRING']);
        $data['unidade_url'] = $config['base_url'] . '?' . $unidade[0];
        if ($this->input->is_ajax_request()) {
            echo json_encode(array('content' => $this->load->view($this->uri->segment(3), $data, true)));
        } else {
            $this->load->view($this->load->getUrlTema(), $data);
        }
    }