
<?php

session_start();
if (!isset($_SESSION['id'])) { header("Location: ../index/index.php"); exit(); }








include '../config.php';
include '../configuracao/modelo.php';

?>


<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <title>Morfo Engine - Inventário Geral</title>
    <style>
        /* ESTILO RETRO WINDOWS 2000 */
        * { box-sizing: border-box; }
        body { background-color: #d4d0c8; font-family: "Tahoma", sans-serif; font-size: 11px; margin: 0; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
        
        .window { border: 2px solid; border-color: #ffffff #808080 #808080 #ffffff; background: #c0c0c0; flex: 1; display: flex; flex-direction: column; margin: 2px; }
        .title-bar { background: linear-gradient(90deg, #000080, #1084d0); color: white; padding: 4px 8px; font-weight: bold; display: flex; justify-content: space-between; align-items: center; }
        
        .filter-pane { padding: 10px; background: #c0c0c0; border-bottom: 2px inset #fff; display: flex; gap: 8px; align-items: flex-end; }
        fieldset { border: 2px inset #fff; padding: 5px; }
        legend { font-weight: bold; padding: 0 4px; }
        
        input, select { border: 2px inset #fff; padding: 3px; font-family: "Tahoma"; font-size: 11px; background: #fff; }
        .btn-win { padding: 4px 15px; background: #d4d0c8; border: 2px solid; border-color: #ffffff #808080 #808080 #ffffff; cursor: pointer; font-weight: bold; height: 35px; min-width: 100px; }
        .btn-win:active { border-color: #808080 #ffffff #ffffff #808080; padding: 5px 14px 3px 16px; }

        .grid-container { flex: 1; overflow-y: scroll; background: #fff; margin: 5px; border: 2px inset #808080; }
        table { width: 100%; border-collapse: collapse; }
        th { position: sticky; top: 0; background: #d4d0c8; border: 1px solid #808080; padding: 6px; text-align: left; box-shadow: inset 1px 1px #fff; z-index: 10; }
        td { border: 1px solid #dfdfdf; padding: 4px 6px; }
        
        tbody tr:nth-child(even) { background: #f5f5f5; }
        tbody tr:hover { background: #ffffcc; }
    </style>
</head>
<body>

<div class="window">
    <div class="title-bar">
        <span>Morfo Engine - Consulta de Inventário (Cálculo sobre Estoque Geral)</span>
        <span>Papanduva/SC</span>
    </div>
    
    <div class="filter-pane">
        <fieldset>
            <legend>Códigos</legend>
            <input type="text" id="cod_ini" value="000001" style="width: 65px;"> até 
            <input type="text" id="cod_fim" value="999999" style="width: 65px;">
        </fieldset>

        <fieldset style="flex: 1;">
            <legend>Descrição</legend>
            <input type="text" id="busca_txt" placeholder="Pesquisar..." style="width: 100%;">
        </fieldset>

        <fieldset>
            <legend>Saldo (Disponível)</legend>
            <select id="filtro_saldo">
                <option value="T">Todos</option>
                <option value="P">Positivos (+)</option>
                <option value="N">Negativos (-)</option>
            </select>
        </fieldset>

        <button class="btn-win" onclick="consultar()">CONSULTAR</button>
    </div>

    <div class="grid-container">
        <table>
            <thead>
                <tr>
                    <th width="65">Código</th>
                    <th>Descrição</th>
                    <th width="30">UN</th>
                    <th width="35">Tipo</th>
                    <th width="85" style="text-align:right;">Qtd. NF</th>
                    <th width="85" style="text-align:right;">Qtd. Ped.</th>
                    <th width="85" style="text-align:right; background:#e8e8e8;">Disponível</th>
                    <th width="100" style="text-align:right; background:#dcdcdc; font-weight:bold;">ESTOQUE GERAL</th>
                    <th width="95" style="text-align:right;">Vlr. Unit. Inv.</th>
                    <th width="115" style="text-align:right; background:#d4d0c8; font-weight:bold;">Total Bruto</th>
                </tr>
            </thead>
            <tbody id="resultado_corpo">
                <tr><td colspan="10" align="center" style="padding:40px;">Utilize os filtros e clique em Consultar.</td></tr>
            </tbody>
        </table>
    </div>
</div>

<script>
    function consultar() {
        const corpo = document.getElementById('resultado_corpo');
        corpo.innerHTML = "<tr><td colspan='10' align='center'>Processando banco de dados...</td></tr>";

        const params = new URLSearchParams();
        params.append('cod_ini', document.getElementById('cod_ini').value);
        params.append('cod_fim', document.getElementById('cod_fim').value);
        params.append('busca_txt', document.getElementById('busca_txt').value);
        params.append('filtro_saldo', document.getElementById('filtro_saldo').value);

        fetch('processar.php', { method: 'POST', body: params })
        .then(r => r.text())
        .then(html => { corpo.innerHTML = html; });
    }
    window.onload = consultar;
</script>
</body>
</html>