<?php header('Content-type: text/html; charset=utf-8');?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Avalia&ccedil;&atilde;o Liberada2</title>

        <link href="bootstrap.min.css" rel="stylesheet">
            <link href="bootstrap.css" rel="stylesheet">
                </head>
                <form action="" method="post">
                    <input type="password" name="sh"  />
                    <input type="submit" />
                </form>


              

                <?php
                function diasemana($data) {
                $ano = substr("$data", 0, 4);
                $mes = substr("$data", 5, -3);
                $dia = substr("$data", 8, 9);

                $diasemana = date("w", mktime(0, 0, 0, $mes, $dia, $ano) );

                switch($diasemana) {
                case"0": $diasemana = "Domingo";
                break;
                case"1": $diasemana = "Segunda";
                break;
                case"2": $diasemana = "Terça";
                break;
                case"3": $diasemana = "Quarta";
                break;
                case"4": $diasemana = "Quinta";
                break;
                case"5": $diasemana = "Sexta";
                break;
                case"6": $diasemana = "Sábado";
                break;
                }

                return $diasemana;
                }

//Exemplo de uso
//chama o arquivo de conexÃ£o com o bd
                $var = $_POST['sh'];
                $tc = 'beta@657';
                if($var!=$tc){
                exit();
                }

              
                $cont2 = 0;
               
			    $hostname = 'localhost';
				$username = 'imazon_apl';
				$password = '#4Im-20!Bd';
				$dbname = 'imazoncursos';	

				$conn = mysqli_connect( $hostname, $username, $password ) or die ( 'Erro ao tentar conectar ao banco de dados.' );
				mysqli_select_db($conn,$dbname);
			   
			   

                $SQL = "SELECT count(primeiro_dia ) as qt,  primeiro_dia FROM `historico` where  id_avaliacao=1 and  (situacao=1 or situacao=2 or situacao=3 or situacao=9)and observacao is not null and primeiro_dia between '2016-07-01' and curdate() group by  primeiro_dia ORDER BY `historico`.`primeiro_dia` DESC limit 32";
                $SQLBonus = "SELECT count(primeiro_dia ) as qt,  primeiro_dia FROM `historico` where observacao<>'curso bonus' and observacao is not null and  id_avaliacao=1 and  (situacao=1 or situacao=2 or situacao=3 or situacao=9)and primeiro_dia between '2016-07-01' and curdate() group by  primeiro_dia ORDER BY `historico`.`primeiro_dia` DESC limit 32";
                ?>
                <div class=bs-example data-example-id=hoverable-table style="width:20%; float:left;"> 
                    <h5 align="center">Matrículas</h5>
                    <table class="table table-hover" >
                        <thead> <tr> <th>Dia</th> <th>Quantidade</th> </tr> </thead> 
                        <tbody>

                            <?php
                            $RS = mysqli_query($conn,$SQL);
                            while (($RF = mysqli_fetch_array($RS)) && ($cont2 < 30000)) {
                            $c = $c+1;
                                $l[]=$RF;
                            $vaar = diasemana($RF['primeiro_dia']);
                            if($vaar=='Domingo'){
                            echo'<tr bgcolor="#999999"> <th scope=row> </th><th scope=row> </th></tr>';
                            }
                            ?>
<?php if($RF['primeiro_dia']>'2016-07-26'){ ?>
                            <tr> <th scope=row><?= date("d/m/Y", strtotime($RF['primeiro_dia']))."&nbsp&nbsp ". diasemana($RF['primeiro_dia']); ?></th> <td><?= round($RF['qt']) ?></td> </tr> 
                            <? }
                            else{?>
                            <tr> <th scope=row><?= date("d/m/Y", strtotime($RF['primeiro_dia']))."&nbsp&nbsp ". diasemana($RF['primeiro_dia']) ?></th> <td><?= round($RF['qt']) ?></td> </tr> 
                            <?php }


                            }
                            ?>
                        </tbody> </table>
                </div>
                <div class=bs-example data-example-id=hoverable-table style="width:10%; float:left;"> 
                    <h5 align="center">Matrículas</h5>
                    <table class="table table-hover">
                         <thead> <tr> <th>Normais</th> <th>Bônus</th> </tr> </thead> 
                        <tbody>
                           

                            <?php
    // echo 'aqui'; print_r($l);
                            $c=-1;
                            $Rp = mysqli_query($conn,$SQLBonus);
                            while (($RX = mysqli_fetch_array($Rp)) && ($cont2 < 30000)) {
                            $c = $c+1;
                            //echo '<pre>';
                          // printr($l);

                            $vaar = diasemana($RX['primeiro_dia']);
                            if($vaar=='Domingo'){
                            echo'<tr bgcolor="#999999"> <th scope=row> </th><th scope=row> </th></tr>';
                            }
                            ?>
<?php if($RX['primeiro_dia']>'2016-07-26'){ ?>
                            <tr>  <td><?= round($RX['qt']) ?></td><td><?= round($l[$c]['qt'])- round($RX['qt']) ?></td> </tr> 
                            <? }
                            else{?>
                            <tr>  <td><?= round($RX['qt']) ?></td><td><?= round($l[$c]['qt']) ?></td> </tr> 
                            <?php }


                            }
                            ?>
                        </tbody> </table>
                </div>

  
                <?php
				
				
                $SQL = "SELECT count(data_compra) as qt, date(data_compra) as tt FROM `pedido` WHERE situacao=3 and date(data_compra) between '2016-07-01' and curdate() group by date(data_compra) order BY  date(data_compra) DESC limit 32";

                $SQL2 = "SELECT count(data_compra) as qt, date(data_compra) as tt FROM `pedido` WHERE situacao=3 and date(data_compra)=curdate() group by date(data_compra) order BY  date(data_compra) DESC limit 32";
                $RT = mysqli_query($conn,$SQL2);
                $GF = 0;
                while ($RC = mysqli_fetch_array($RT)) {
                $GF = $GF+1;
                }
                ?>

                <div class=bs-example data-example-id=hoverable-table style="width:7%; float:left;"> 



                    <h5 align="center">Pagamentos</h5>
                    <table class="table table-hover">
                        <thead> <tr>  <th>Quantidade</th> </tr> </thead> 
                        <tbody>

                            <?php
                            $c=0;
                            $vaar='';
                            $RS = mysqli_query($conn,$SQL);
                            if($GF==0){
                            echo'<tr>  <td>0</td> </tr> ';
                            $k[0]=0;
                            }
                            while (($RF = mysqli_fetch_array($RS)) && ($cont2 < 30000)) {
                            $c=$c+1;
                            $k[]=$RF['qt'];
                            $vaar=diasemana($RF['tt']);
                            if($vaar=='Domingo'){
                            echo'<tr bgcolor="#999999"> <th scope=row> </th></tr>';
                            }
                            ?>

                            <tr>  <td><?= $RF['qt'] ?></td> </tr> 
                            <?php

                            } ?>


                        </tbody> </table>

                </div>



                <?php


                $SQL = "SELECT count(data_compra) as qt, date(data_compra) as tt FROM `pedido` WHERE situacao>0 and  date(data_compra) between '2016-07-01' and curdate() group by date(data_compra) order BY  date(data_compra) DESC limit 32";?>
                <div class=bs-example data-example-id=hoverable-table style="width:10%; float:left;"> 
                    <h5 align="center">Faturas</h5>
                    <table class="table table-hover">
                        <thead> <tr>  <th>Quantidade</th> </tr> </thead> 
                        <tbody>
                            <?php 
                            $RS = mysqli_query($conn,$SQL);
                            $d=0; 
                            while (($RF = mysqli_fetch_array($RS)) && ($cont2 < 30000)) {
                            $d=$d+1;
                            $l[]=$RF['qt'];
                            $di[]=$RF['tt'];
                            $vaar=diasemana($RF['tt']);

                            if($vaar=='Domingo'){
                            echo'<tr bgcolor="#999999"> <th scope=row> </th></tr>';
                            }
                            ?>

                            <tr>  <td><?= $RF['qt'] ?></td> </tr> 
                            <?php

                            } ?>
                        </tbody> </table>

                </div>



                <?php


                $SQL = "SELECT count(primeiro_dia ) as qt, primeiro_dia FROM `historico` where id_avaliacao=1 and   primeiro_dia between '2016-07-01' and curdate() group by  primeiro_dia ORDER BY `historico`.`primeiro_dia` DESC limit 32";?>
                <div class=bs-example data-example-id=hoverable-table style="width:10%; float:left;"> 
                    <h5 align="center">Incrições</h5>
                    <table class="table table-hover">
                        <thead> <tr>  <th>Quantidade</th> </tr> </thead> 
                        <tbody>
                            <?php
                            $RS = mysqli_query($conn,$SQL); 
                            while (($RF = mysqli_fetch_array($RS)) && ($cont2 < 30000)) {
                            $vaar=diasemana($RF['primeiro_dia']);

                            $ins[]=$RF['qt'];
                            if($vaar=='Domingo'){
                            echo'<tr bgcolor="#999999"> <th scope=row> </th></tr>';
                            }
                            ?>

                            <tr>  <td><?= $RF['qt'] ?></td> </tr> 
                            <?php

                            } ?>
                        </tbody> </table>

                </div>



                <?php
                $SQL = "SELECT count(date(data_cadastro)) as qt,date(data_cadastro),date(data_cadastro) as ac FROM `aluno` where date(data_cadastro) between '2016-07-01' and curdate() group by date(data_cadastro)ORDER BY date(data_cadastro) DESC limit 32";?>
                <div class=bs-example data-example-id=hoverable-table style="width:10%; float:left;"> 
                    <h5 align="center">Cadastros</h5>
                    <table class="table table-hover">
                        <thead> <tr>  <th>Quantidade</th> </tr> </thead> 
                        <tbody>
                            <?php
                            $RS = mysqli_query($conn,$SQL); 
                            while (($RF = mysqli_fetch_array($RS)) && ($cont2 < 30000)) {
                            $vaar=diasemana($RF['ac']);
                            $cd[]=$RF['qt'];
                            if($vaar=='Domingo'){
                            echo'<tr bgcolor="#999999"> <th scope=row> </th></tr>';
                            }
                            ?>
                            <tr>  <td><?= $RF['qt'] ?></td> </tr> 
                            <? } ?>
                        </tbody> </table>
                </div> 


                <?php
                //echo $k1.'aqui';
                //print_r($k);
                //print_r($l);




                ?> 
                <table class="table table-hover" style="width:30%; float:left; margin-top:0px;">
                    <thead><td colspan="4" style="text-align:center; font-weight:bold; font-size:18px;">CONVERSÃO FATURAS</td>  <tr style="text-align:center;"> <th style="text-align:center;">Dia</th> <th style="text-align:center;">Faturas</th> <th  style="text-align:center;">Pagas</th> <th style="text-align:center;">Porcentagem</th> </tr> </thead> 
                    <tbody>
                        <?php
                        $a=-1;
                        $diasq=-1;
                        foreach ($l as $value) {
                        $a=$a+1;
                        $diasq=$diasq+1;
                        ?>

                        <br />
                        <?php
                        $vaar2=diasemana($di[$a]);
                        if($vaar2=='Domingo'){
                        echo'<tr bgcolor="#999999"> <th scope=row> </th><th scope=row style="text-align:center;">'.round($fat/$diasq).' </th><th scope=row style="text-align:center;">'.round($insa/$diasq).' </th><th scope=row style="text-align:center;">'.round($por1/$diasq).'%'.' </th></tr>';
                        $por1=0;
                        $media=0;
                        $diasq=0;
                        $fat=0;
                        $insa=0;
                        }

                        $por1=$por1+round(($k[$a]/$value)*100);
                        $fat=$fat+$value;
                        $insa=$insa+$k[$a];
                        ?>

                        <tr>  <td align="left" ><?= date("d/m/Y", strtotime($di[$a]))." ".diasemana($di[$a]) ?> <td align="center"><?= $value ?></td> <td align="center" ><?= $k[$a] ?></td> <td align="center" ><?= round(($k[$a]/$value)*100)."%" ?></td> </tr> 
                        <?php }
                        ?>
                    </tbody>
                </table>




                <table class="table table-hover" style="width:33%; float:left; margin-left:15px; margin-top:0px;">

                    <thead><td colspan="4" style="text-align:center; font-weight:bold; font-size:18px;">INSCRIÇÕES X FATURAS</td> <tr style="text-align:center;"> <th style="text-align:center;">Dia</th> <th style="text-align:center;">Inscrições</th><th  style="text-align:center;">Faturas</th> <th style="text-align:center;">Porcentagem</th> </tr> </thead> 
                    <tbody>
                        <?php
                        $a=-1;
                        $diasq=-1;
                        foreach ($l as $value) {
                        $a=$a+1;
                        ?>

                        <br />
                        <?php
                        $vaar2=diasemana($di[$a]);
                        $diasq=$diasq+1;
                        if($vaar2=='Domingo'){
                        echo'<tr bgcolor="#999999"> <th scope=row> </th><th scope=row style="text-align:center;">'.round($insa/$diasq).' </th><th scope=row style="text-align:center;">'.round($fat/$diasq).' </th><th scope=row style="text-align:center;">'.round($por/$diasq)."%".' </th></tr>';
                        $por=0;
                        $media=0;
                        $diasq=0;
                        $fat=0;
                        $insa=0;
                        }

                        $por=$por+round(($value/$ins[$a])*100);
                        $fat=$fat+$value;
                        $insa=$insa+$ins[$a];
                        ?>
                        <tr>  <td align="left" ><?= date("d/m/Y", strtotime($di[$a]))." ".diasemana($di[$a]) ?> <td align="center"><?= $ins[$a] ?></td> <td align="center" ><?= $value ?></td> <td align="center" ><?= round(($value/$ins[$a])*100)."%" ?></td> </tr> 
                        <?php }
                        ?>
                    </tbody>
                </table>


                <table class="table table-hover" style="width:33%; float:left; margin-left:15px; float:left; margin-top:-578px;">

                    <thead><td colspan="4" style="text-align:center; font-weight:bold; font-size:18px;">CADASTROS X INSCRIÇÕES</td> <tr style="text-align:center;"> <th style="text-align:center;">Dia</th> <th style="text-align:center;">Inscrições</th><th  style="text-align:center;">Cadastros</th> <th style="text-align:center;">Porcentagem</th> </tr> </thead> 
                    <tbody>
                        <?php
                        $a=-1;
                        $diasq=-1;
                        $por=0;
                        $media=0;
                        $fat=0;
                        $insa=0;

                        foreach ($l as $value) {
                        $a=$a+1;
                        ?>

                        <br />
                        <?php
                        $vaar2 = diasemana($di[$a]);
                        $diasq = $diasq+1;
                        if($vaar2=='Domingo'){
                        echo'<tr bgcolor="#999999"> <th scope=row> </th><th scope=row style="text-align:center;">'.round($insa/$diasq).' </th><th scope=row style="text-align:center;">'.round($fat/$diasq).' </th><th scope=row style="text-align:center;">'.round($por/$diasq)."%".' </th></tr>';
                        $por = 0;
                        $media = 0;
                        $diasq = 0;
                        $fat = 0;
                        $insa = 0;
                        }

                        $por = $por+round(($ins[$a]/$cd[$a])*100);
                        $fat = $fat+$cd[$a];
                        $insa = $insa+$ins[$a];
                        ?>
                        <tr>  <td align="left" ><?= date("d/m/Y", strtotime($di[$a]))." ".diasemana($di[$a]) ?></td> <td align="center"><?= $ins[$a] ?></td> <td align="center" ><?= $cd[$a] ?></td> <td align="center" ><?= round(($ins[$a]/$cd[$a])*100)."%" ?></td> </tr> 
<?php }
?>
                    </tbody>
                </table>


                <?php
                $SQL69 = "SELECT count(date(data_cadastro)) as qt, date(data_cadastro) as dt FROM `aluno` where origem='IMAZON CURSOS M' GROUP BY date(data_cadastro)
                ORDER BY `dt` DESC limit 32";

                $SQL70= "SELECT count(date(data_cadastro)) as qt, date(data_cadastro) as dt FROM `aluno` where origem='IMAZON CURSOS' GROUP BY date(data_cadastro)
                ORDER BY `dt` DESC limit 32";
                $DK = mysqli_query($conn,$SQL70); 
                while ($AS = mysqli_fetch_array($DK))  {
                $deg[]=$AS['qt'];
                }

                $SQL71= "SELECT count(date(data_cadastro)) as qt, date(data_cadastro) as dt FROM `aluno` where origem='Imazon' GROUP BY date(data_cadastro)
                ORDER BY `dt` DESC limit 32";
                $WK = mysqli_query($conn,$SQL71); 
                while ($AT = mysqli_fetch_array($WK)){
                $SER[]=$AT['qt'];
                }

                $SQL72= "SELECT count(date(data_cadastro)) as qt, date(data_cadastro) as dt FROM `aluno` where origem='' GROUP BY date(data_cadastro)
                ORDER BY `dt` DESC limit 32";
                $FK = mysqli_query($conn,$SQL72); 
                while ($BT = mysqli_fetch_array($FK)){
                $VP[]=$BT['qt'];
                }


                
                $SQL75= "SELECT DATE(data_compra) as dia , COUNT( DATE( data_compra)) as qt FROM  `pedido`WHERE situacao>0 and transacao NOT LIKE  'MIM%'GROUP BY DATE( data_compra ) 
ORDER BY DATE(data_compra)  DESC
LIMIT 0 , 32";
                $FA = mysqli_query($conn,$SQL75); 
                
                while ($FE = mysqli_fetch_array($FA)){
                $VFA[]=$FE['qt'];
                $VFAD[]=$FE['dia'];
                }

                $SQL76= "SELECT DATE(data_compra) , COUNT( DATE( data_compra)) as qt FROM  `pedido`WHERE situacao>0 and transacao LIKE  'MIM%'GROUP BY DATE( data_compra ) 
ORDER BY DATE(data_compra)  DESC
LIMIT 0 , 32";
                
                
                $FAP= mysqli_query($conn,$SQL76);
                $n=-1;
                while ($FATP = mysqli_fetch_array($FAP)){
                $VFPA[]=$FATP['qt'];
                $n=$n+1;
                }
                
                 
               
                   
                
                $SQL77= "SELECT DATE(data_compra) as dia , COUNT( DATE( data_compra)) as qt FROM  `pedido`WHERE situacao=3 and transacao NOT LIKE  'MIM%'GROUP BY DATE( data_compra ) 
ORDER BY DATE(data_compra)  DESC
LIMIT 0 , 32";
                $FAPAGA = mysqli_query($conn,$SQL77); 
                
                while ($FEPAGA = mysqli_fetch_array($FAPAGA)){
                $VFAPAGA[]=$FEPAGA['qt'];
                $VFADPAGA[]=$FEPAGA['dia'];
                }

                $SQL78= "SELECT DATE(data_compra) , COUNT( DATE( data_compra)) as qt, DATE(data_compra) dia FROM  `pedido`WHERE situacao=3 and transacao LIKE  'MIM%'GROUP BY DATE( data_compra ) 
ORDER BY DATE(data_compra)  DESC
LIMIT 0 , 32";
                $SQL178= "SELECT DATE(data_compra) , COUNT( DATE( data_compra)) as qt, DATE(data_compra) dia FROM  `pedido`WHERE situacao=3 and DATE(data_compra)=curdate()  and transacao NOT LIKE  'MIM%'GROUP BY DATE( data_compra ) 
ORDER BY DATE(data_compra)  DESC
LIMIT 0 , 32";
              
                
                $FAPPAGA= mysqli_query($conn,$SQL78);
            
                $x=1;
                $diz=date("Y-m-d");
                while ($FATPPAGA = mysqli_fetch_array($FAPPAGA)){
                    $DA=$FATPPAGA['dia'];
                    if($x==1 && $DA!=$diz ){
                        $VFPAPAGA[0]=0;   
                    }
                    
                    $VFPAPAGA[]=$FATPPAGA['qt'];
                      $x=$x+1;
                }
                
               
                 $FAPPAGA178= mysqli_query($conn,$SQL178);
                 $d178=0;
                 while ($C178 = mysqli_fetch_array($FAPPAGA178)){
                  $d178=$d178+1;   
                 }
                 
                 if($d178==0){
                 $VFAPAGA[0]=0;   
                 }

                ?>
                
                <div class=bs-example data-example-id=hoverable-table style="width:100%; float:left;"> 
                    <table class="table table-hover" style="margin-top:20px; float:left; width:50%">
                        <thead><td colspan="4" style="text-align:center; font-weight:bold; font-size:18px;">FATURAS</td> <tr>  
                                <th>Quantidade</th> <th>MÓVEL</th><th>DESKTOP</th><th>MÓVEL PAGAS</th><th>DESKTOP PAGAS</th><th>TOTAL</th> </tr> </thead> 
                        <tbody>
                            <?php
                            $v=-1;
                            $RS = mysqli_query($conn,$SQL69); 
                            while (($RFP = mysqli_fetch_array($RS)) && ($cont2 < 30000)) {
                            $vaar=diasemana($RFP['dt']);
                            $v=$v+1;
                            $ins[]=$RFP['qt'];
                            if($vaar=='Domingo'){
                            echo'<tr bgcolor="#999999"> <th scope=row> </th><th scope=row> </th><th scope=row> </th><th scope=row> </th><th scope=row> </th><th scope=row> </th></tr>';
                            }
                            ?>
                            <tr> <td align="left"><?= date("d/m/Y", strtotime($VFAD[$v])) . " " . diasemana($VFAD[$v]) ?></td> <td><?=$VFPA[$v]." (".round($VFPA[$v]/$l[$v]*100) ."%)"?></td><td><?=$VFA[$v]." (".round($VFA[$v]/$l[$v]*100) ."%)"?></td><td><?=$VFPAPAGA[$v]." (".round($VFPAPAGA[$v]/$l[$v]*100) ."%)"?></td><td><?=$VFAPAGA[$v]." (".round($VFAPAGA[$v]/$l[$v]*100) ."%)"?></td><td><?=$l[$v]?></td> </tr> 
                            <?php
                            } ?>
                        </tbody> </table>                       
                        
                    <table class="table table-hover" style="margin-top:20px; width:35%; margin-left: 20px;  float:left;">
                        <thead><td colspan="4" style="text-align:center; font-weight:bold; font-size:18px;">CADASTROS</td> <tr>  <th>Quantidade</th> <th>MÓVEL</th><th>DESKTOP</th><th>V1</th><th>VIP</th> </tr> </thead> 
                        <tbody>
                            <?php
                            $v=-1;
                            $RS = mysqli_query($conn,$SQL69); 
                            while (($RF = mysqli_fetch_array($RS)) && ($cont2 < 30000)) {
                            $vaar=diasemana($RF['dt']);
                            $v=$v+1;

                            $ins[]=$RF['qt'];
                            if($vaar=='Domingo'){
                            echo'<tr bgcolor="#999999"> <th scope=row> </th><th scope=row> </th><th scope=row> </th><th scope=row> </th><th scope=row> </th></tr>';
                            }
                            ?>

                            <tr> <td align="left" ><?= date("d/m/Y", strtotime($RF['dt'])) . " " . diasemana($RF['dt']) ?></td> <td><?= $RF['qt'] . " (" . round(($RF['qt'] / $cd[$v]) * 100) . "%)" ?></td><td><?= $deg[$v] . " (" . round(($deg[$v] / $cd[$v]) * 100) . "%)" ?></td><td><?= $SER[$v] . " (" . round(($SER[$v] / $cd[$v]) * 100) . "%)" ?></td><td><?= $VP[$v] . " (" . round(($VP[$v] / $cd[$v]) * 100) . "%)" ?></td> </tr> 
                            <?php

                            } ?>
                            
                        </tbody> </table>
                       <? $SQL378= "SELECT COUNT(situacao) as total,situacao FROM `historico` where primeiro_dia BETWEEN DATE_SUB( CURRENT_DATE( ) , INTERVAL 30 DAY ) AND CURRENT_DATE( ) GROUP BY situacao ORDER BY `historico`.`situacao` ASC";
					      
						  $SQL379= "SELECT COUNT(situacao) as total,situacao FROM `historico` where primeiro_dia BETWEEN DATE_SUB( CURRENT_DATE( ) , INTERVAL 120 DAY ) AND CURRENT_DATE( ) GROUP BY situacao ORDER BY `historico`.`situacao` ASC";
						  $JWLMF = mysqli_query($conn,$SQL379);  
						  while ($MLWJF = mysqli_fetch_array($JWLMF )){
						   if($MLWJF[situacao]==4){$quatroa=$MLWJF[total];}
						   if($MLWJF[situacao]==8){$oitocd=$MLWJF[total];}	
						 				 
						  }
						  					   
					    $JWLM = mysqli_query($conn,$SQL378); 
                         while ($MLWJ = mysqli_fetch_array($JWLM )) {
						 
						
						 if($MLWJ[situacao]==0){$zeroa=$MLWJ[total];}
						 if($MLWJ[situacao]==1){$uma=$MLWJ[total];}
						 if($MLWJ[situacao]==2){$doisa=$MLWJ[total];}
						 if($MLWJ[situacao]==3){$tresa=$MLWJ[total];}						   
						if($MLWJ[situacao]==5){$cincoa=$MLWJ[total];}
						if($MLWJ[situacao]==6){$seisa=$MLWJ[total];}
					    if($MLWJ[situacao]==7){$setea=$MLWJ[total];}
							   
							  
						 }
					   ?>
                       
                        <table class="table table-hover" style="margin-top:20px; width:20%; margin-left: 20px;  float:left;">
                        <thead><td colspan="4" style="text-align:center; font-weight:bold; font-size:18px;">Situação Histórico</td> <tr>  <th>Situação</th><th>Quantidade</th><th>%</th></tr> </thead> 
                        <tbody>
                            <? $totalc=$zeroa+$uma+$doisa+$tresa+$quatroa+$cincoa+$seisa+$setea+$oitocd;?>

                            <tr> <td align="left" >Inscrito</td> <td><?=$zeroa?></td><td><?=number_format($zeroa/$totalc*100, 2, ',', ' ')?>%</td></tr>
                            <tr> <td align="left" >Matriculado</td><td><?=$uma?></td><td><?=number_format($uma/$totalc*100, 2, ',', ' ')?>%</td></tr> 
                            <tr> <td align="left" >Aprovado</td><td><?=$doisa?></td><td><?=number_format($doisa/$totalc*100, 2, ',', ' ')?>%</td> </tr> 
                            <tr> <td align="left" >Reprovado</td><td><?=$tresa?></td><td><?=number_format($tresa/$totalc*100, 2, ',', ' ')?>%</td> </tr> 
                            <tr> <td align="left" >Jubilado</td><td><?=$quatroa?></td><td><?=number_format($quatroa/$totalc*100, 2, ',', ' ')?>%</td> </tr> 
                            <tr> <td align="left" >Cancelado</td><td><?=$cincoa?></td><td><?=number_format($cincoa/$totalc*100, 2, ',', ' ')?>%</td> </tr> 
                            <tr> <td align="left" >Arquivado</td><td><?=$seisa?></td><td><?=number_format($seisa/$totalc*100, 2, ',', ' ')?>%</td> </tr>
                            <tr> <td align="left" >Erro</td><td><?=$setea?></td><td><?=number_format($setea/$totalc*100, 2, ',', ' ')?>%</td> </tr>
                            <tr> <td align="left" >Congelado</td><td><?=$oitocd?></td><td><?=number_format($oitocd/$totalc*100, 2, ',', ' ')?>%</td> </tr>  
                            <tr> <td align="left" >Total</td><td><?=$totalc?></td><td></td> </tr>  
                             
                          
                        </tbody> </table>
                        
                        <table class="table table-hover" style="margin-top:20px; width:35%; margin-left: 20px;  float:left;">
                        <thead><td colspan="4" style="text-align:center; font-weight:bold; font-size:18px;">Faturas Por Estado</td> <tr>  <th>Estado</th><th>Quantidade</th><th>Valor</th><th>Média</th></tr> </thead> 
                        <tbody>
                        
                        <?
                         $SQL380= "SELECT COUNT(a.estado) as total ,a.estado, round(sum(valor),2) valor FROM `pedido` p join aluno a on(a.id_fic=p.id_aluno) where p.situacao=3 and p.data_compra BETWEEN DATE_SUB( CURRENT_DATE( ) , INTERVAL 30 DAY ) and CURRENT_DATE( ) GROUP BY a.estado ORDER BY `total` DESC";
						  $cidade = mysqli_query($conn,$SQL380);  
						  while ($cidadeestado = mysqli_fetch_array($cidade)){?>
                          
						   	  <tr> <td align="left" ><?
                              if($cidadeestado['estado']==''){
							  echo "Não Informado";
							  }
							  else{   echo $cidadeestado['estado'];}
							  ?></td><td><?=$cidadeestado['total']?></td>
								     <td>R$ <?=$cidadeestado['valor']?></td>
                                                                      <td>R$   <?=number_format($cidadeestado['valor']/$cidadeestado['total'], 2, '.', '')?></td>
							
							</tr>               
                              				 				 
						  <? 
                                                  $somaestadosvalor=$somaestadosvalor+$cidadeestado['valor'];
						  $somaestado=$cidadeestado['total']+$somaestado;	
						  }
                    	?>
                    
                        <tr> <td align="left" ><b>Total</b></td><td><?=$somaestado?></td><td>R$ <?=$somaestadosvalor?></td><td>R$ <?=number_format($somaestadosvalor/$somaestado, 2, '.', '')?></td>  </tr>  
                        </tbody>
                        </table>
                                           
                        <table class="table table-hover" style="margin-top:20px; width:40%; margin-left: 20px;  float:left;">
                        <thead><td colspan="4" style="text-align:center; font-weight:bold; font-size:18px;">Faturas Cidade SP</td> <tr>  <th>Estado</th><th>Quantidade</th><th>Valor</th><th>Média</th></tr> </thead> 
                        <tbody>
                        
                        <?php
                         $SQL381= "SELECT a.cidade,count(cidade) total,round(sum(valor),2) valor  FROM `pedido` p  join aluno a on(a.id_fic=p.id_aluno) where a.estado='SP' and p.situacao=3 and a.estado='SP' and p.data_compra BETWEEN DATE_SUB( CURRENT_DATE( ) , INTERVAL 30 DAY ) and CURRENT_DATE( ) group by a.cidade
ORDER BY count(cidade)  DESC";
						  $cidade2 = mysqli_query($conn,$SQL381);  
						  while ($cidadeestado2 = mysqli_fetch_array($cidade2)){?>
                          
						   	  <tr> <td align="left" ><?php
                              if($cidadeestado2['cidade']==''){
							  echo "Não Informado";
							  }
							  else{   echo $cidadeestado2['cidade'];}
							  ?></td><td><?=$cidadeestado2['total']?></td>
								     <td>R$ <?=$cidadeestado2['valor']?></td>
                                                                      <td>R$   <?=number_format($cidadeestado2['valor']/$cidadeestado2['total'], 2, '.', '')?></td>
							
							</tr>               
                              				 				 
						  <? 
                                                  $somaestadosvalor2=$somaestadosvalor2+$cidadeestado2['valor'];
						  $somaestado2=$cidadeestado2['total']+$somaestado2;	
						  }
                    	?>
                    
                        <tr> <td align="left" ><b>Total</b></td><td><?=$somaestado2?></td><td>R$ <?=$somaestadosvalor2?></td><td>R$ <?=number_format($somaestadosvalor2/$somaestado2, 2, '.', '')?></td>  </tr>  
                        </tbody>
                        </table>                   
                </div>
               

</html>
