<?php   

    function painelFabricante($dataIinicio,$dataFinal,$lojasec,$fabricante,$frase){
        $data = date('d/m/Y');    
    ?>
    <style>
        .container {

            overflow-y: scroll;
            margin-left: 0px;

        }

    
    </style>

    <section class='2spacobottom'>

        <hr class="linha">
        <h4>




<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" class="bi bi-cart4" viewBox="0 0 16 16">
  <path d="M0 2.5A.5.5 0 0 1 .5 2H2a.5.5 0 0 1 .485.379L2.89 4H14.5a.5.5 0 0 1 .485.621l-1.5 6A.5.5 0 0 1 13 11H4a.5.5 0 0 1-.485-.379L1.61 3H.5a.5.5 0 0 1-.5-.5M3.14 5l.5 2H5V5zM6 5v2h2V5zm3 0v2h2V5zm3 0v2h1.36l.5-2zm1.11 3H12v2h.61zM11 8H9v2h2zM8 8H6v2h2zM5 8H3.89l.5 2H5zm0 5a1 1 0 1 0 0 2 1 1 0 0 0 0-2m-2 1a2 2 0 1 1 4 0 2 2 0 0 1-4 0m9-1a1 1 0 1 0 0 2 1 1 0 0 0 0-2m-2 1a2 2 0 1 1 4 0 2 2 0 0 1-4 0"/>
</svg>









            <?php echo $frase;?>







        </h4>
      

      <p></p>
      <p></p>
        <div class="container">


        <table border="1" class="table tabelaindex2 table-striped">

           <thead>
  <thead class="table-dark " align="center">

                <th>FABRICANTE</th>
                <th>QUANTIDADE </th>
                <th>BRUTO</th>
                <th>DESC</th>
                <th>LIQ</th>
                <th>%</th>
                <!-- <th>BAIXAR</th> -->
  </thead>
  <tbody>

        <?php

        $quantidadeTotal = 0;
        $precoBruto = 0;
        $descontoTotal = 0;
        $vendasTotal = 0;

        //INSTANCIANDO SQL
        $sql = new Sqlserver;
        //BUSCANDO AS VENDAS
        $vendasFabricante = $sql->VendasFabricante($dataIinicio,$dataFinal,$lojasec,$fabricante);


        //PERCORRENDO DADOS
        foreach ($vendasFabricante as $vendas)
        {
            $desconto1 =0;
            $quantidadeTotal += $vendas[1];
           // $precoBruto += $vendas[3];
      
            $vendasTotal += $vendas[2];
            $fabricante = $vendas[0];

            
            //ENCONTRA O VALOR BRUTO
            $valorBrutovenda = $sql->CalcularValorBruto($fabricante,$dataIinicio,$dataFinal,$lojasec);
           
            $desconto = $valorBrutovenda - $vendas[2];
           $descontoTotal += $desconto;
           $precoBruto += $valorBrutovenda;


            $porcentagem = ABS(ROUND(($desconto / $valorBrutovenda) , 4) * 100 );
           
           // $porcentagem = 0;


            ?>

            <tr align="center">

            <td><?php echo $fabricante; ?></td>
                <td><?php echo ROUND($vendas[1]); ?></td>
                <td><?php echo ROUND($valorBrutovenda,2); ?></td>


                <td><?php echo ABS(ROUND($desconto,2)); ?></td>

                <td>R$ <?php echo ROUND($vendas[2],2); ?></td>
                <td><?php echo $porcentagem ; ?> % </td>

                <td>

                <!--<a href="gerador/impressao.php?fabricante=<?php //echo $fabricante?>&inicio=<?php //echo $dataIinicio?>&final=<?php// echo $dataFinal?>&loja=<?php // echo $lojasec ?>&painel=1">-->
 

<!--
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-cloud-arrow-down text-warning" viewBox="0 0 16 16">
  <path fill-rule="evenodd" d="M7.646 10.854a.5.5 0 0 0 .708 0l2-2a.5.5 0 0 0-.708-.708L8.5 9.293V5.5a.5.5 0 0 0-1 0v3.793L6.354 8.146a.5.5 0 1 0-.708.708z"/>
  <path d="M4.406 3.342A5.53 5.53 0 0 1 8 2c2.69 0 4.923 2 5.166 4.579C14.758 6.804 16 8.137 16 9.773 16 11.569 14.502 13 12.687 13H3.781C1.708 13 0 11.366 0 9.318c0-1.763 1.266-3.223 2.942-3.593.143-.863.698-1.723 1.464-2.383m.653.757c-.757.653-1.153 1.44-1.153 2.056v.448l-.445.049C2.064 6.805 1 7.952 1 9.318 1 10.785 2.23 12 3.781 12h8.906C13.98 12 15 10.988 15 9.773c0-1.216-1.02-2.228-2.313-2.228h-.5v-.5C12.188 4.825 10.328 3 8 3a4.53 4.53 0 0 0-2.941 1.1z"/>
</svg>





        -->


</a>
                </td>
        
            </tr>

            <?php }


				$porcentagemDesconto = ($descontoTotal / $precoBruto) * 100 ;

			?>

            <tr align="center" class="cortotal">
                <td></td>
                <td><?php echo ROUND($quantidadeTotal);?></td>
                <td><?php echo "R$ " .  number_format($precoBruto, 2, ',', ' ');?></td>
                <td><?php echo   number_format($descontoTotal, 2, ',', ' ');?></td>
                <td><?php echo "R$ " . number_format($vendasTotal, 2, ',', ' ');?></td>
                 <td><?php echo number_format($porcentagemDesconto, 2, ',', ' ') . ' %';?></td>
                <td></td>
            </tr>

        </table>

        </div>
    </section>

    <?php } 
    
    
    
    
    
    
    ?>



    