<?php
session_start();
require_once 'script_php/conexaoSQL.php';
require_once 'gerador/SqlServer.php';
$sql = new Sqlserver();

$loja = filter_var( $_POST['loja'], FILTER_SANITIZE_STRING);
$quantidade = filter_var( $_POST['quantidade'], FILTER_SANITIZE_STRING);
$ean = filter_var( $_POST['ean'], FILTER_SANITIZE_STRING);
$dados = $sql->dadosNfe($quantidade,$loja,$ean);
?>

<!DOCTYPE html>
<html>
<head>

<?php include_once 'head.html' ?>

<title></title>
</head>

<body>

<?php include_once 'header.php'; ?>

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Consulta SQL Resultados</title>
    <style>
        table {
            border-collapse: collapse;
            width: 100%;
        }

        th, td {
            border: 1px solid #dddddd;
            text-align: left;
            padding: 8px;
        }

        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>

<?php


echo '<table >';
echo '<thead>';
echo '<tr>';
echo '<th>Emissão</th>';
// Adicione ou remova colunas conforme necessário

echo '<th>CFOP</th>';
echo '<th>Qt Item</th>';
echo '<th>P Unit</th>';
echo '<th>P Total</th>';
echo '<th>ICMS Alíq</th>';
echo '<th>BasICMSST</th>';
echo '<th>ValorICMSST</th>';
echo '<th>Nº Nota</th>';
echo '<th>NFeCH</th>';
echo '<th>Loja</th>';
echo '<th>Base STUnit</th>';
echo '<th>ValorSTUnit</th>';
echo '<th>ST_T_INFORMAR</th>';
echo '<th>ST_UNIT_INFORMAR</th>';

echo '<th title="preco do produto unitario com st = preco total + st / quantidade" >UNT + ST</th>';

echo '</tr>';
echo '</thead>';
echo '<tbody>';

$i=1;
// Iterar sobre os dados e popular a tabela
foreach ($dados as $linha) {
    if($i == 1){
    echo "<h4>" . $linha[1];
    $total2 = round($quantidade * $linha[4], 2);

    $valorTotal2 = ($total2 + $linha[15]) / $quantidade;
    $valorTotal3 = str_replace('.', ',', strval($valorTotal2));


    }
    $i++;
?>

<tr>
	<td><?php echo $linha[0];?></td>
	<td><?php echo $linha[2];?></td>
	<td><?php echo round($linha[3]);?></td>
	<td><?php echo round($linha[4] ,2);?></td>
	<td><?php echo round($linha[5],2);?></td>
	<td><?php echo round($linha[6],2);?></td>
	<td><?php echo round($linha[7],2);?></td>
	<td><?php echo round($linha[8],2);?></td>
	<td><?php echo $linha[9];?></td>
	<td><?php echo $linha[10];?></td>
	<td><?php echo $linha[11];?></td>
	<td><?php echo round($linha[12],2);?></td>
	<td><?php echo round($linha[13],2);?></td>
	
	<td><?php echo $linha[14];?></td>
	<td><?php echo $linha[15];?></td>
    
    <td title="preco do produto unitario com st = preco total + st / quantidade"><?php echo $valorTotal3;?></td>
</tr>

<?php } ?>

</tbody>
</table>


</body>
</html>

<?php include_once 'footer.php' ?>