<!--Cabecalho -->
<?php $this->load->view('commons/cabecalho'); ?>
<?php $this->load->view('commons/header'); ?>
<?php $this->load->view('commons/menu'); ?>
<!--<style>
    .listas {
        display: none;
    }
</style>-->
<div class="lds-css ng-scope"><div style="width:100%;height:100%" class="lds-cube"></div></div>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->

    <section class="content container-fluid">    

        <br>
        <?php echo $this->session->flashdata('upload'); ?>
        <?php echo $this->session->flashdata('erro-form'); ?>


        <div class="box">
            <div class="box-body">
                <div class="dataTables_wrapper form-inline dt-bootstrap">
                    
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="table-responsive">
                                <section class="content-header">
                                    <h1>Relatório Acadêmico Pela Data da Matrícula últimos 30 dias</h1>
                                    <br>
                                </section>
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <th scope="col" style="min-width: 110px;">Status</th>
                                            <th scope="col">Quantidade</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $sql = "SELECT count(concluido) total, concluido FROM `historico` where primeiro_dia between DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY concluido
ORDER BY `historico`.`primeiro_dia` DESC";
                                        $status = $this->db->query($sql)->result();
                                        
                                        $sql2 = "SELECT  count(*)total FROM `historico` where primeiro_dia between DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND DATE_SUB(CURDATE(), INTERVAL 1 DAY) ";
                                        $total = $this->db->query($sql2)->result();
                                        $tot=$total[0]->total;
                                        

                                        foreach ($status as $value) {
                                            switch ($value->concluido) {
                                                case 0:
                                                    $status_t = "Matriculado";
                                                    break;
                                                case 1:
                                                    $status_t = "Concluído";
                                                    break;
                                                case 2:
                                                    $status_t = "Cancelado";
                                                    break;
                                                
                                                case 3:
                                                    $status_t = "Jubilado";
                                                    break;
                                            }
                                            ?>                              <tr>
                                                <th scope="row"><?= $status_t ?></th>
                                                <td><?php 
                                                $va=$value->total;
                                                $porcentagem= ((($value->total)*100)/$tot);
                                                $porcentagem= number_format($porcentagem, 2, ',', ' ');
                                                       echo $va."( ".$porcentagem."%)";?></td>

                                            </tr> 
                                        <?php }
                                        ?>
                                            <tr><td></td>
                                                <td><?php print_r($tot);?></td>
                                            </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div> 
                <br>
                <div class="dataTables_wrapper form-inline dt-bootstrap">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="table-responsive">
                                <section class="content-header">
                                    <h1>Relatório Acadêmico Pela Data da Alteração do Status últimos 30 dias</h1>
                                    <br>
                                </section>
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <th scope="col" style="min-width: 110px; max-width:110px; ">Status</th>
                                            <th scope="col">Quantidade</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $sql = "select count(concluido) as total, concluido from historico where id_historico in( 
SELECT id_historico FROM `log_historico` where date(data) between DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND DATE_SUB(CURDATE(), INTERVAL 1 DAY) group by id_historico) group by concluido";
                                        $status = $this->db->query($sql)->result();
                                        
                                        $sql2 = "select count(*) as total from historico where id_historico in( 
SELECT id_historico FROM `log_historico` where date(data) between DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND DATE_SUB(CURDATE(), INTERVAL 1 DAY) group by id_historico)";
                                        $total = $this->db->query($sql2)->result();
                                        $tot=$total[0]->total;
                                        
                                        
                                        
                                        

                                        foreach ($status as $value) {
                                            switch ($value->concluido) {
                                                case 0:
                                                    $status_t = "Matriculado";
                                                    break;
                                                case 1:
                                                    $status_t = "Concluído";
                                                    break;
                                                case 2:
                                                    $status_t = "Cancelado";
                                                    break;
                                                
                                                case 3:
                                                    $status_t = "Jubilado";
                                                    break;
                                            }
                                            ?>                              <tr>
                                                <th scope="row"><?= $status_t ?></th>
                                                <td><?php 
                                                $va=$value->total;
                                                $porcentagem= ((($value->total)*100)/$tot);
                                                $porcentagem= number_format($porcentagem, 2, ',', ' ');
                                                       echo $va."( ".$porcentagem."%)";?></td>

                                            </tr> 
                                        <?php }
                                        ?>
                                            <tr><td></td>
                                                <td><?php print_r($tot);?></td>
                                            </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div> 
                <br>
                <div class="dataTables_wrapper form-inline dt-bootstrap">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="table-responsive">
                                <section class="content-header">
                                    <h1>Relatório Acadêmico Financeiro últimos 30 dias</h1>
                                    <br>
                                </section>
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <th scope="col" style="min-width: 110px;">Status</th>
                                            <th scope="col">Quantidade</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $sql = "SELECT count(certificado) total,certificado as concluido FROM `historico` where primeiro_dia between DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY `certificado`
ORDER BY `historico`.`primeiro_dia` DESC";
                                        $status = $this->db->query($sql)->result();
                                        
                                        $sql2 = "SELECT count(*) AS total FROM `historico` where primeiro_dia between DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND DATE_SUB(CURDATE(), INTERVAL 1 DAY) 
ORDER BY `historico`.`primeiro_dia` DESC";
                                        $total = $this->db->query($sql2)->result();
                                        $tot=$total[0]->total;
                                        

                                        foreach ($status as $value) {
                                            switch ($value->concluido) {
                                                case 0:
                                                    $status_t = "NÃO PAGO";
                                                    break;
                                                case 1:
                                                    $status_t = "PAGO";
                                                    break;
                                                
                                            }
                                            ?>                              <tr>
                                                <th scope="row"><?= $status_t ?></th>
                                                <td><?php 
                                                $va=$value->total;
                                                $porcentagem= ((($value->total)*100)/$tot);
                                                $porcentagem= number_format($porcentagem, 2, ',', ' ');
                                                       echo $va."( ".$porcentagem."%)";?></td>

                                            </tr> 
                                        <?php }
                                        ?>
                                            <tr><td></td>
                                                <td><?php print_r($tot);?></td>
                                            </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div> 
                <br>
                <div class="dataTables_wrapper form-inline dt-bootstrap">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="table-responsive">
                                <section class="content-header">
                                    <h1>Relatório Financeiro últimos 30 dias</h1>
                                    <br>
                                </section>
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <th scope="col" style="min-width: 110px;">Status</th>
                                            <th scope="col">Quantidade</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $sql = "SELECT count(situacao) total,situacao
FROM `transacao`
WHERE data_transacao
BETWEEN DATE_SUB( CURDATE( ) , INTERVAL 30
DAY )
AND DATE_SUB( CURDATE( ) , INTERVAL 1
DAY )
GROUP BY `situacao`";
                                        $status = $this->db->query($sql)->result();
                                        
                                        
                                        $sql2 = "SELECT count(*) total
FROM `transacao`
WHERE data_transacao
BETWEEN DATE_SUB( CURDATE( ) , INTERVAL 30
DAY )
AND DATE_SUB( CURDATE( ) , INTERVAL 1
DAY )
";
                                        $totalstatus = $this->db->query($sql2)->result();

                                        foreach ($status as $value) {
                                            switch ($value->situacao) {
                                                case 0:
                                                    $status_t = "PENDENTE";
                                                    break;
                                                case 1:
                                                    $status_t = "PAGO";
                                                    break;
    
                                                case 3:
                                                    $status_t = "INICIADO";
                                                    break;
                                                 case 5:
                                                    $status_t = "CANCELADO";
                                                    break;
                                                case 6:
                                                    $status_t = "PAGO";
                                                    break;
                                            }
                                            ?>                              <tr>
                                                <th scope="row"><?=$status_t ?></th>
                                                <td><?= $value->total ?><?="( ".number_format($value->total*100/$totalstatus[0]->total, 2, ',', ' ')."% )" ?></td>

                                            </tr> 
                                        <?php }
                                        ?>
<tr>
                                                <th scope="row"></th>
                                                <td><?=$totalstatus[0]->total?></td>

                                            </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            
               </div> 
        
             </div>            


    </section>
</div>

<?php $this->load->view('commons/rodape'); ?>
