<?php
require_once "../configuracao/conexao.php";

$id = (int)($_GET['id'] ?? 0);

if ($id > 0) {
    // Busca os itens vinculados ao código da nota
    $query = "SELECT * FROM nf_itens WHERE nf_itens_nf_cab = $id";
    $result = $mysqli->query($query);

    if ($result && $result->num_rows > 0) {
        echo '<table class="table table-sm mb-0">
                <thead class="table-light">
                    <tr>
                        <th>Cód</th><th>Descrição</th><th>Qtd</th><th>Valor</th><th>Total</th>
                    </tr>
                </thead>
                <tbody>';
        while($i = $result->fetch_assoc()) {
            echo "<tr>
                    <td>{$i['nf_itens_cod_item']}</td>
                    <td>{$i['nf_itens_descr_item']}</td>
                    <td>{$i['nf_itens_qtd_item']} {$i['nf_itens_unid']}</td>
                    <td>R$ ".number_format((float)$i['nf_itens_vl_item'], 2, ',', '.')."</td>
                    <td class='fw-bold'>R$ ".number_format((float)$i['nf_itens_tot_item'], 2, ',', '.')."</td>
                  </tr>";
        }
        echo '</tbody></table>';
    } else {
        echo '<p class="p-3 text-center">Nenhum item.</p>';
    }
}
?>