<?php
session_start();

require_once 'script_php/conexao.php';
require_once 'gerador/MysqlConsulta.php';
require_once 'gerador/SqlServer.php';

$sql = new SqlServer();
$mysql = new MysqlConsulta();

$dados = $mysql->vendasPorStatusNs($conexao);
?>

<!DOCTYPE html>
<html>
<head>

<?php include_once 'head.html' ?>

<title></title>
</head>

<form>

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




<table  class="table table-striped tabelaindex2">
    <tr class="table-dark" align="center">
        <th scope="col" title="">BAIXAR</th>
        <th scope="col" title="">ID</th>
        <th scope="col" title="">NSU</th>
        <th scope="col" title="">TIPO CARTAO</th>
        <th scope="col" title="">MODALIDADE</th>
        <th scope="col" title="">TOTAL PARCELAS</th>
        <th scope="col" title="">PARCELA</th>
        <th scope="col" title="">VALOR BRUTO</th>
        <th scope="col" title="">TAXA</th>
        <th scope="col" title="">VALOR</th>
        <th scope="col" title="">VENDA</th>          
        <th scope="col" title="">DATAPGT</th>
        <th scope="col" title="">SDATA_VENCIMENTO</th>
        <th scope="col" title="">DF</th>

    </tr>


    <form action="">



<?php

$valorTotalRecebido = 0;

foreach ($dados as $value){
    
    $valorTotalRecebido += $value['valor_parcela'];

    $dataVencimento2 = date("d/m/Y", strtotime($value['data_venda']));
    
    $statusSoft = $sql->buscarRecebimentoPorRest( $dataVencimento2, $value['parcela'], $value['nsu']);
    $dataSoft = date("Y-m-d",strtotime($statusSoft));
    ?>

    <tr align="center">
    <td><input type="checkbox" name="enviar[]" value="<?php echo $dado['id'];  ?>"  class="checkbox" checked>

        <td><?php echo $value['id']; ?></td>
        <td><?php echo $value['nsu']; ?></td>
        <td><?php echo $value['bandeira']; ?></td>   
        <td><?php echo $value['forma_pagamento']; ?></td> 
        <td><?php echo $value['total_parcelas']; ?></td>             
        <td><?php echo $value['parcela']; ?></td>
        <td><?php echo $value['valorbruto']; ?></td>
        <td><?php echo $value['taxa']; ?></td>
        <td><?php echo $value['valor_parcela']; ?></td>

        <td><?= date("d/m/Y", strtotime($value['data_venda'])); ?></td>

        <td><?= date("d/m/Y", strtotime($value['recebimento'])); ?></td>

        <td><?php 

        if (!isset($statusSoft)){
        
        echo  0; 
        
        }else{
            echo  date("d/m/Y", strtotime($statusSoft)) ; 
        }

        if ($dataSoft <> $value['recebimento']){ ?>

<td>
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="currentColor" class="bi bi-asterisk text-danger" viewBox="0 0 16 16">
  <path d="M8 0a1 1 0 0 1 1 1v5.268l4.562-2.634a1 1 0 1 1 1 1.732L10 8l4.562 2.634a1 1 0 1 1-1 1.732L9 9.732V15a1 1 0 1 1-2 0V9.732l-4.562 2.634a1 1 0 1 1-1-1.732L6 8 1.438 5.366a1 1 0 0 1 1-1.732L7 6.268V1a1 1 0 0 1 1-1"/>
</svg>
</td>

<?php } ?>
    
    </td>

        </tr>

<?php } ?>

    </table>

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


        </form>

    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-up-square-fill text-light" viewBox="0 0 16 16">
  <path d="M2 16a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2zm6.5-4.5V5.707l2.146 2.147a.5.5 0 0 0 .708-.708l-3-3a.5.5 0 0 0-.708 0l-3 3a.5.5 0 1 0 .708.708L7.5 5.707V11.5a.5.5 0 0 0 1 0"/>
</svg>



    
    
    Baixar Parcelas Selecionadas</button>
    
    <p></p>


    <td> <h5>   VALOR TOTAL RECEBIDO R$  [ <?php echo number_format($valorTotalRecebido, 2, ',', '.'); ?> ] </h5> </td>
    


<?php include_once 'footer.php' ?>