<?php
include ('db.php');

session_start();

if (!empty($_POST['idprod'])) {

    $idprod = $_POST['idprod'];
    $result = mysql_query("SELECT entrada,saida,entrada_virtual,saida_virtual,apostado,premiado,leitura.data,"
            . " (SELECT date_format(max(data_hora), '%d/%m%/%Y %H:%i') "
            . " FROM transacoes WHERE idprod = '$idprod')dataorder FROM leitura, "
            . " tablet WHERE leitura.idprod = '$idprod' "
            . " AND leitura.idprod = tablet.idprod");
    $row = mysql_fetch_array($result);
    ?>

    <div class="panel panel-default">
        <div class="panel-heading">
            Informações sobre Total da Leitura
        </div>
        <!-- /.panel-heading -->
        <div class="panel-body">
            <div class="table-responsive">
                <table class="table ">
                    <thead>
                        <tr>
                            <th class=" text-muted text-center"><h4>Tipo</h4></th>
                            <th class=" text-muted text-center"><h4>Data</h4></th>
                            <th class=" text-success text-center"><h4>Entrada</h4></th>
                            <th class=" text-danger text-center"><h4>Saída</h4></th>
                            <th class=" text-info text-center"><h4>Balanço</h4></th>
                            <th class=" text-info text-center"><h4>% Pgto</h4></th>
                        </tr>
                    </thead>
                    <div id='leiturainfo<?= $_POST['idprod'] ?>'>
                        <tbody>
                            <tr>
                                <td class=" text-muted text-center"><h4><b><?= 'Oficial' ?></b></h4></td>
                                <td class=" text-muted text-center"><h4><?php echo $row['dataorder'] ?></h4></td>
                                <td class=" text-success text-center"><h4>$ <?php echo $row['entrada'] ?></h4></td>
                                <td class=" text-danger text-center"><h4>$ <?php echo $row['saida'] ?></h4></td>
                                <td class=" text-info text-center"><h4>$ <?php echo $row['entrada'] - $row['saida'] ?></h4></td>
                                <td class=" text-info text-center"><h4> <?php echo round(($row['saida'] / $row['entrada']) * 100, 2) . '%' ?></h4></td>
                            </tr>

                            <tr>
                                <td class=" text-muted text-center"><h4><b><?= 'Parcial' ?></b></h4></td>
                                <td class=" text-muted text-center"><h4><?php echo $row['dataorder'] ?></h4></td>
                                <td class=" text-success text-center"><h4>$ <?php echo $row['entrada_virtual'] ?></h4></td>
                                <td class=" text-danger text-center"><h4>$ <?php echo $row['saida_virtual'] ?></h4></td>
                                <td class=" text-info text-center"><h4>$ <?php echo $row['entrada_virtual'] - $row['saida_virtual'] ?> </h4></td>
                                <td class=" text-info text-center"><h4> <?php echo round(($row['saida_virtual'] / $row['entrada_virtual'] * 100), 2) . '%' ?></h4></td>
                            </tr>
							
							<tr>
                                <td class=" text-muted text-center"><h4><b><?= 'Rejogo' ?></b></h4></td>
                                <td class=" text-muted text-center"><h4><?php echo $row['dataorder'] ?></h4></td>
                                <td class=" text-success text-center"><h4>$ <?php echo $row['apostado'] / 100 ?></h4></td>
                                <td class=" text-danger text-center"><h4>$ <?php echo $row['premiado'] / 100 ?></h4></td>
                                <td class=" text-info text-center"><h4>$ <?php echo ($row['apostado'] - $row['premiado']) / 100 ?> </h4></td>
                                <td class=" text-info text-center"><h4> <?php echo round(($row['premiado'] / $row['apostado'] * 100), 2) . '%' ?></h4></td>
                            </tr>
                        </tbody>
                    </div>
                </table>
                <?php if ($_SESSION['UsuarioNivel'] != 6) { ?>
                    <div class="text-right">
                        <a href="javascript:void(0)" onclick="zerarLeituraVirtual()" id='zerarLeituraVirtualButton' class='btn btn-danger' role='button' disabled>ZERAR LEITURA VIRTUAL &nbsp;</a>
                    </div>
                <?php } ?>
            </div>
            <!-- /.table-responsive -->
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.panel -->        
    <?php
}
?>