<?php

    $sql4 = "SELECT titulo, SUM(subtotal) AS totalizacaoGrade from grade WHERE grade.id_pedido = '$id' AND grade.dir = 4 GROUP by `titulo` ORDER BY `titulo`";

    $resultado4 = $mysqli->query($sql4);
    $row4 = $resultado4->fetch_array(MYSQLI_ASSOC);
?>
			<div class="row">
				<h3 style="text-align:center">Estatistica Finalização</h3>
			</div>
                <table class="table table-hover">
                    <thead>
                      <tr>
                      </tr>
                    </thead>

                    <tbody>
                        <?php 
                        $resultado4 = $mysqli->query($sql4);
                        while($row4 = $resultado4->fetch_array(MYSQLI_ASSOC)) { 
                        $progresso =  round((($row4['totalizacaoGrade'] * 100) / $totalg)) ;
                        switch ($progresso) {
                            case ($progresso <= 25);
                                $res = "progress-bar progress-bar-danger";
                            break;
                            
                            case ($progresso > 26) && ($progresso < 50);
                                $res = "progress-bar progress-bar-warning";
                            break;
                                
                            case ($progresso > 50) && ($progresso < 75);
                                $res = "progress-bar progress-bar-info";
                            break;
                            
                            default;
                                $res = "progress-bar progress-bar-success";
                           
                        }
                        
                        ?>
                        
                            <input type="hidden" id="id_grade" name="id_grade" value="<?php echo $row4['titulo']; ?>" />
                            <input type="hidden" id="id" name="id" value="<?php echo $row4['totalizacaoGrade']; ?>" />
                            <input type="hidden" id="id2" name="id2" value="<?php echo $totalg ?>" />
                            
                            <tr>
                                <td> <?php echo $row4['titulo']; ?> - <?php echo $row4['totalizacaoGrade'];?> de <?php echo $totalg?>

                                    <div class="progress">
                                        <div class="<?php echo $res ?>" role="progressbar" aria-valuenow="<?php echo $progresso ?>" 
                                        aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $progresso ?>%">
                                        <?php echo $progresso ?>%
                                        </div>
                                    </div>            
                                </td>
                            </tr>

                        <?php } ?>
                    </tbody>
                </table>
