<?php
session_start();

require_once 'script_php/conexaoSQL.php';
require_once  'financeiro/Boleto.php';
require_once 'gerador/Datas.php';
require_once 'script_php/RemotoInterno.php';

$lojaConsultar = $_REQUEST['loja'];
$dataInicio = $_REQUEST['dataInicio'];
$dataFinal = $_REQUEST['dataFinal'];

$datas = new  Data();
$remoto = new  RemotoInterno();

$dataInicioSql =  $remoto->converterDataParaSqlServer($dataInicio);
$dataFinalSql =  $remoto->converterDataParaSqlServer($dataFinal);

$boleto = new Boletos();
$dados = $boleto->boletosVencimentos($lojaConsultar,$dataInicioSql,$dataFinalSql);

$total = 0;

$quantidadeBoletos = 0;
$boletoFaltando = 0;
$valorSubtotal = 0;
$boletosAvulsos = 0;
$valroAvulso = 0;
$valorTotal = 0;

?>

<!DOCTYPE html>
<html>
<head>

<?php include_once 'head.html' ?>

<title></title>
</head>

<body>

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

    <table class="table table-striped">

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

        <th> </th>
        <th scope="col"> FORNECEDOR</th>
        <th scope="col"> VENCIAMENTO</th>
        <th scope="col"> VALOR</th>
        <th scope="col"> PENDENTE</th>
        <th scope="col"> CATEGORIA</th>
        <th scope="col"> SUBCATEGORIA</th>
        <th scope="col"> NUMERO DOC</th>
        <th scope="col"> DATA EMISSAO</th> 
        <th scope="col"> LOJA</th>
        <th scope="col"> TIPO DOCUMENTO</th>
        <th scope="col"> OBSERVAÇÃO</th>
        </thead>

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

            <input type="hidden" name="loja" value='<?=$lojaConsultar; ?>'>

        <?php foreach ($dados as $dado){
            $total = $total + $dado[11];

            $quantidadeBoletos++;

            if($dado[23] > 0){
                $boletoFaltando++;
            }

            if($dado[23] > 0){
                $valorSubtotal = $valorSubtotal + $dado[11];
            }

            if($dado[1] <> 'FORNECEDOR'){
                $boletosAvulsos++;
            }

            if($dado[1] <> 'FORNECEDOR'){
                $valroAvulso = $valroAvulso + $dado[11];
            }
            
            $valorTotal = $valorTotal + $dado[11];?>

        <?php if (($dado[6] == 'PIX') OR ($dado[6] == 'ESPECIE')){ ?>
        <tr class='bg-warning'>
        <?php } ?>



            <td><input type="checkbox" name="enviar[]" value="<?php echo $dado[10];  ?>"  class="checkbox" checked></td>
            
            <td><?=$dado[0] ?></td>
                                    <td><?=$datas->formatarDataPtbr($dado[12]); ?></td>
            <td> R$ <?=number_format($dado[11], 2, ',', '.'); ?></td>
            
            <?php  if($dado[23] > 0){?>
            <td align='center'>

            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-slash-circle text-danger" viewBox="0 0 16 16">
            <path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16"/>
            <path d="M11.354 4.646a.5.5 0 0 0-.708 0l-6 6a.5.5 0 0 0 .708.708l6-6a.5.5 0 0 0 0-.708"/>
            </svg>
            </td>

            <?php }else{ ?>
            <td align='center'>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check-lg text-success" viewBox="0 0 16 16">
            <path d="M12.736 3.97a.733.733 0 0 1 1.047 0c.286.289.29.756.01 1.05L7.88 12.01a.733.733 0 0 1-1.065.02L3.217 8.384a.757.757 0 0 1 0-1.06.733.733 0 0 1 1.047 0l3.052 3.093 5.4-6.425z"/>
            </svg>

            </td>
            <?php } ?>

            <td><?=$dado[1] ?></td>
            <td><?=$dado[2] ?></td>
            <td><?=$dado[3] ?></td>

            <td><?=$datas->formatarDataPtbr($dado[4]); ?></td>

            <td><?=$dado[9] ?></td>
            <td><?=$dado[6] ?></td>
            <td><?=$dado[17] ?></td>            
            
            


        </tr>



    <?php } ?>

    </table>



<p></p>

<!--
<section>

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

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

        <td> DATA</td>
        <td> Q BOLETOS</td>
        <td> FALTA</td>
        <td> VALOR FALTA</td>
        <td>BOLETOS AVULSOS</td>
        <td>VALOR TOTAL</td>
    </tr>

    <tr align='center'>
        <td> <?= $dataInicioSql . ' | ' . $dataFinalSql;?></td>
        <td> <?=$quantidadeBoletos; ?></td>
        <td> <?=$boletoFaltando; ?></td>
        <td> <?php echo $valorSubtotal; ?> </td>
        <td> <?php echo $boletosAvulsos; ?></td>
        <td><?php echo $valorTotal;;?></td>
    </tr>


</table>



</section>

-->



    <h4> TOTAL: R$
<?php echo number_format($total, 2, ',', '.'); ?>
</h4>
</b>


    <input type="submit" value='AVANÇAR >>>' class="form-control btn btn-warning form_data form_forn">

    </form>

<p></p>


    </body>

<?php include_once 'footer.php' ?>