<?php
session_start();
require_once ("../conexion.php");
require_once('../include/sesiones.php');
?>
<table class="table table-bordered table-hover table-striped" style="font-size: 9pt;">
    <thead>
        <tr>
            <th>FACTURA</th>
            <th>CLIENTE</th>
            <th>TOTAL</th>
        </tr>
    </thead>
    <?php
        $ven1=mysqli_query($con,"SELECT * from ventas where ven_forma_de_pago='Tarjeta' and ven_estado<>'anulada' and apertura='$apertura' and usuario='$usu_id'");
        while ($vent1=mysqli_fetch_array($ven1))
        {
            $ven_id=$vent1['ven_id'];

            $total_retencion=0;
            $ret=mysqli_query($con,"SELECT SUM(ret_importe) as ret_importe FROM retencion_venta where empresa='$empresa' and ventas_ven_id='$ven_id'") or die(mysqli_error($con)); 
            $rets=mysqli_fetch_array($ret);
            $total_retencion=$rets['ret_importe'];


            $sumador_combo=0;
            $sumador_total=0;

            $neto=0;
            $total_descuento=0;
            $total_iva=0;
            $sumador_articulos=0;
            include('../include/total_venta.php');

            $sumador_total=$sumador_articulos+$sumador_combo-$total_retencion;

            $sql2=mysqli_query($con, "SELECT * from venta_abonos where ventas_ven_id='$ven_id'");
            $sql3=mysqli_fetch_array($sql2);
            $veab_abono=$sql3['veab_abono']+0;
            $medio_pago=$sql3['medio_pago'];
    ?>
        <tr>
            <td><?php echo $vent1['ven_prefijo']; ?><?php echo $vent1['ven_n_venta']; ?></td>
            <td><?php echo $vent1['ven_nombre']; ?></td>
            <td align="right"><?php echo '<span style="color:red;">('; echo $medio_pago; echo ') </span>'; echo number_format($sumador_total,0);?></td>
        <tr>
        <?php } ?>
         <tr>
            <td colspan="3">
                 <div class="col-md-12">
                    <pre style="font-size:18px;text-align:center"><strong class="text-info">TOTALES</strong></pre>
                </div>
                <?php
                    $ven1=mysqli_query($con,"SELECT *, sum(veab_abono) as total_veab_abono from ventas v,venta_abonos va where v.ven_forma_de_pago='Tarjeta' and v.ven_estado<>'anulada' and v.apertura='$apertura' and v.usuario='$usu_id' and v.ven_id=va.ventas_ven_id group by va.medio_pago ");
                    while ($vent1=mysqli_fetch_array($ven1))
                    { ?>
                <div class="col-md-6">
                    <pre style="font-size:18px;text-align:center"><strong class="text-success"><?php echo $vent1['medio_pago']; ?></strong></pre>
                </div>
                <div class="col-md-6">
                    <pre style="font-size:18px;text-align:center"><strong class="text-danger">$<?php echo number_format($vent1['total_veab_abono'],0); ?></strong></pre>
                </div>
                <?php }  ?>
            </td>
        </tr> 
</table>