<?php
require '../conexao/conexao.php';
// Receba o ID da requisição da consulta
$requisicaoId = $_GET['id'];
$requisicaoId = $_REQUEST['id'];

//$requisicaoId = 5649;

// Construa a consulta SQL aqui
$query_detalhe_formula = " Select  F.cdfrm,F.descrfrm,F.volume,F.univol,F.tpformafarma
From FC05000 F                              
Left  Join FC03000 P ON (F.CDSAC = P.CDPRO) 
Where  F.CDFRM > 0 
And 
Exists(
  Select C.CDPRO
  From   FC05100 C
  Where  C.CDFRM = F.CDFRM
And C.CDPRO = " . intval($requisicaoId) . "
) 
Order By F.DESCRFRM ";


//echo $query_detalhe_formula;
$result_detalhe_formula = ibase_query($connection, $query_detalhe_formula);
if (!$result_detalhe_formula) {
    die('Erro na consulta: ' . ibase_errmsg());
}
?>

<!-- Tabela de detalhes da requisição -->
<table class="table table-bordered table-hover table-sm">
    <thead class="thead-light">
        <tr>
            <th scope="col">Código Fórmula</th>
            <th scope="col">Fórmula</th>
            <th scope="col">Volume</th>
            <th scope="col">Unidade</th>
            <th scope="col">Forma Farmaceutica</th>
        </tr>
    </thead>
    <tbody>
        <?php while ($row = ibase_fetch_assoc($result_detalhe_formula)) {



        ?>


            <tr>
                <td><?= htmlspecialchars($row['CDFRM']) ?></td>
                <td><?= $row['DESCRFRM'] ?></td>
                <td><?= htmlspecialchars($row['VOLUME']) ?></td>
                <td><?= htmlspecialchars($row['UNIVOL']) ?></td>
                <td><?= htmlspecialchars($row['TPFORMAFARMA']) ?></td>
            </tr>
        <?php } ?>
    </tbody>
</table>