<?php
session_start();

require 'script_php/Softcom.php';
require_once 'script_php/conexao.php';

// Cria um objeto DateTime com a data atual
$dataAtual = new DateTime();
$dataAtual->modify('first day of -3 months');
$primeiroDiaTresMesesAtras = $dataAtual->format('Y-m-d');

$dataAtual = new DateTime();
$dataAtual->modify('last day of previous month');
$ultimoDiaMesAnterior = $dataAtual->format('Y-m-d');
?>

<!DOCTYPE html>
<html>
<head>
    <?php include_once 'head.html'; ?>
    <title>Período de análise</title>

    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
    
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>

    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script>
    
</head>

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

    
 <!--mensagens na tela-->
  <?php if (isset($_SESSION["msg"])) {
      echo $_SESSION["msg"];
      unset($_SESSION["msg"]);
 }?>

    <h4>
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" class="bi bi-ui-checks-grid" viewBox="0 0 16 16">
  <path d="M2 10h3a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1v-3a1 1 0 0 1 1-1m9-9h3a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1h-3a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1m0 9a1 1 0 0 0-1 1v3a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1zm0-10a2 2 0 0 0-2 2v3a2 2 0 0 0 2 2h3a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2zM2 9a2 2 0 0 0-2 2v3a2 2 0 0 0 2 2h3a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2zm7 2a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2h-3a2 2 0 0 1-2-2zM0 2a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zm5.354.854a.5.5 0 1 0-.708-.708L3 3.793l-.646-.647a.5.5 0 1 0-.708.708l1 1a.5.5 0 0 0 .708 0z"/>
</svg>

 Pedido de compra

    </h4>
    <p></p>

    <hr class="tabelaindex">
    <p></p>

    <form action="listar_vendasMes.php" method="post">

    <fieldset class="fieldset"> <legend> Período de vendas</legend>

        <br>
        <input type="date" placeholder="Data início" value="<?= $primeiroDiaTresMesesAtras ?>" name="datainicio" class="form-control form_data form_forn">

        <input type="date" placeholder="Data Final" value="<?= $ultimoDiaMesAnterior ?>" name="datafinal" class="form-control form_data form_forn">
        <br>

</fieldset>

<fieldset class="fieldset"> <legend>Fabricante/Fornecedor</legend>

    <label for=""> Escolha um fabricante </label>  <p></p>
       <!--  <p>* Fabricante<br><small>*Para todos os fabricantes, use o fabricante "todos".</small></p> -->
       
        <select id="fabricantes" class="form-control" name="fabricante[]" multiple>

            <?php
            $fabricante = new Softcom();
            $dados = $fabricante->BuscarFabricante();

            foreach ($dados as $novo) {
                
                echo "<option value='{$novo[0]}'>{$novo[0]}</option>";
            }
            ?>

        </select>

        <ul id="selected-fabricantes"></ul>



        <label for=""> Escolha um fornecedor </label>  <p></p>
       <!--  <p>* Fabricante<br><small>*Para todos os fabricantes, use o fabricante "todos".</small></p> -->
       
        <select id="fornecedor" class="form-control" name="fornecedor[]" multiple>

            <?php
            $fabricante = new Softcom();
            $dados = $fabricante->BuscarFornecedor();

            foreach ($dados as $novo) {
                
                echo "<option value='{$novo[1]}'>{$novo[1]}</option>";
            }
            ?>

        </select>

        <ul id="selected-fabricantes"></ul>

<p></p>

</fieldset>

    <fieldset class="fieldset"> <legend>Empresa</legend>

        <p>Loja<br></p>
        <select class="form-control form_forn" name="loja">
            <?php
            $todas = 0;
            $result = "SELECT * FROM usuarios WHERE usuario = '$usuario'";
            $resultado = mysqli_query($conexao, $result);
            while ($linha = mysqli_fetch_array($resultado)) {
                $matriz = $linha['matriz'];
                $loja02 = $linha['loja02'];
                $loja03 = $linha['loja03'];
                $loja04 = $linha['loja04'];
                $loja05 = $linha['loja05'];
                $loja06 = $linha['loja06'];

                if ($matriz == 'sim') { $todas++; }
                if ($loja02 == 'sim') { $todas++; }
                if ($loja03 == 'sim') { $todas++; }
                if ($loja04 == 'sim') { $todas++; }
                if ($loja05 == 'sim') { $todas++; }
                if ($loja06 == 'sim') { $todas++; }
            ?>
                <?php if ($matriz == 'sim') { ?><option value="MATRIZ">LOJA 01</option><?php } ?>
                <?php if ($loja02 == 'sim') { ?><option value="LOJA 02">LOJA 02</option><?php } ?>
                <?php if ($loja03 == 'sim') { ?><option value="LOJA 03">LOJA 03</option><?php } ?>
                <?php if ($loja04 == 'sim') { ?><option value="LOJA 04">LOJA 04</option><?php } ?>
                <?php if ($loja05 == 'sim') { ?><option value="LOJA 05">LOJA 05</option><?php } ?>
                <?php if ($loja06 == 'sim') { ?><option value="LOJA 06">LOJA 06</option><?php } ?>
            <?php } ?>
           
        </select>

         <input type="hidden" name="sugestao" value="nao" checked>
         <input type="hidden" name="mostrasemovimento" value="nao" checked>
<p></p>
   </fieldset>


<button type="submit" class="btn btn-warning">

<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-database-up" viewBox="0 0 16 16">
  <path d="M12.5 16a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7m.354-5.854 1.5 1.5a.5.5 0 0 1-.708.708L13 11.707V14.5a.5.5 0 0 1-1 0v-2.793l-.646.647a.5.5 0 0 1-.708-.708l1.5-1.5a.5.5 0 0 1 .708 0"/>
  <path d="M12.096 6.223A5 5 0 0 0 13 5.698V7c0 .289-.213.654-.753 1.007a4.5 4.5 0 0 1 1.753.25V4c0-1.007-.875-1.755-1.904-2.223C11.022 1.289 9.573 1 8 1s-3.022.289-4.096.777C2.875 2.245 2 2.993 2 4v9c0 1.007.875 1.755 1.904 2.223C4.978 15.71 6.427 16 8 16c.536 0 1.058-.034 1.555-.097a4.5 4.5 0 0 1-.813-.927Q8.378 15 8 15c-1.464 0-2.766-.27-3.682-.687C3.356 13.875 3 13.373 3 13v-1.302c.271.202.58.378.904.525C4.978 12.71 6.427 13 8 13h.027a4.6 4.6 0 0 1 0-1H8c-1.464 0-2.766-.27-3.682-.687C3.356 10.875 3 10.373 3 10V8.698c.271.202.58.378.904.525C4.978 9.71 6.427 10 8 10q.393 0 .774-.024a4.5 4.5 0 0 1 1.102-1.132C9.298 8.944 8.666 9 8 9c-1.464 0-2.766-.27-3.682-.687C3.356 7.875 3 7.373 3 7V5.698c.271.202.58.378.904.525C4.978 6.711 6.427 7 8 7s3.022-.289 4.096-.777M3 4c0-.374.356-.875 1.318-1.313C5.234 2.271 6.536 2 8 2s2.766.27 3.682.687C12.644 3.125 13 3.627 13 4c0 .374-.356.875-1.318 1.313C10.766 5.729 9.464 6 8 6s-2.766-.27-3.682-.687C3.356 4.875 3 4.373 3 4"/>
</svg>


 Continuar


</button>
    
    </form>

    <script src="js/buscarFabricante.js"></script>
 
        <script src="js/buscarFornecedor.js"></script>


    <?php include_once 'footer.php'; ?>
</body>
</html>
