<table cellspacing="0" style="width: 100%;padding-top: 5px;">
    <tr>
       <td style="width: 70%; vertical-align: top;">

            <table cellspacing="0" style="width: 100%;">
                <tr style="background-color:<?php echo $color; ?>">
                    <td colspan="4" style="width: 100%;color:white;text-align:center;padding:2px;"> 
                        <strong style="font-size:10px;color: #000" >IMPUESTOS</strong>
                    </td>
                </tr>
                <tr>
                    <td style="width: 25%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                       TIPO
                    </td>
                    <td style="width: 25%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        BASE
                    </td>
                    <td style="width: 25%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        %
                    </td>
                    <td style="width: 25%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        VALOR
                    </td>
                </tr>

                 <?PHP       
                    $sqliva=mysqli_query($con,"SELECT * from venta_detalle where ventas_ven_id='$ven_id'and vend_iva<>'00' group by vend_iva") or die(mysqli_error($con)); 
                    while ($iva=mysqli_fetch_array($sqliva))
                    {
                        $iva_porcentaje=$iva['vend_iva'];
                        $iva0=$iva_porcentaje/100; //0.19
                        $iva1=1+$iva0; //1.19

                        $neto_i=0;
                        $total_iva=0;
                        $sqliva1=mysqli_query($con,"SELECT * from venta_detalle where ventas_ven_id='$ven_id' and vend_iva='$iva_porcentaje' order by vend_id asc");
                        while ($rowi=mysqli_fetch_array($sqliva1))
                        {
                            $vend_cantidad=$rowi['vend_cantidad'];
                            $vend_precio=$rowi['vend_precio_real']; //1.000.000
                            $vend_iva=$rowi['vend_iva']; //19%
                            $vend_descuento=$rowi['vend_desc']; //10%

                            $descuento_item=($vend_descuento/100)*$vend_iva; //descuento_item 84.033



                            $precio_total_sin_iva_item=($vend_precio/$iva1)*$vend_cantidad; //precio sin iva  840.336
                            $total_iva_item=($precio_total_sin_iva_item-$descuento_item)*$iva0; // total iva  159.336

                            $neto_i+=$precio_total_sin_iva_item;
                            $total_iva+=$total_iva_item;
                        }
                        ?>
                        <tr>
                            <td style="width: 25%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                               
                            </td>
                            <td style="width: 25%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                                <?php echo number_format($neto_i,0); ?>
                            </td>
                            <td style="width: 25%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                                <?php echo $iva_porcentaje; ?>
                            </td>
                            <td style="width: 25%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                                <?php echo number_format($total_iva,0); ?>
                            </td>
                        </tr>
                    <?PHP } ?>
               
            </table>

           <?php
            // CONSULTA
            $sql = "SELECT t.ret_base, t.ret_importe, t.codigo, t.porcentaje 
                    FROM retencion_venta t
                    WHERE t.empresa = '$empresa' AND t.ventas_ven_id = '$ven_id'";

            $res   = mysqli_query($con, $sql) or die(mysqli_error($con));
            $count = mysqli_num_rows($res);

            // SI NO HAY REGISTROS, NO MOSTRAR LA TABLA
            if ($count > 0) {
            ?>
            <table cellspacing="0" style="width: 100%; padding-top: 5px;">
                <tr style="background-color:<?php echo $color; ?>">
                    <td colspan="4" style="width: 100%;color:white;text-align:center;padding:2px;"> 
                        <strong style="font-size:10px;color:#000">RETENCIONES</strong>
                    </td>
                </tr>

                <tr>
                    <td style="width: 25%;padding:2px;text-align:center;border-bottom:1px solid #bdc3c7;border-left:1px solid #bdc3c7;font-size:10px;text-align:right;">
                        TIPO
                    </td>
                    <td style="width: 25%;padding:2px;text-align:center;border-bottom:1px solid #bdc3c7;border-left:1px solid #bdc3c7;border-right:1px solid #bdc3c7;font-size:10px;text-align:right;">
                        BASE
                    </td>
                    <td style="width: 25%;padding:2px;text-align:center;border-bottom:1px solid #bdc3c7;border-left:1px solid #bdc3c7;border-right:1px solid #bdc3c7;font-size:10px;text-align:right;">
                        %
                    </td>
                    <td style="width: 25%;padding:2px;text-align:center;border-bottom:1px solid #bdc3c7;border-left:1px solid #bdc3c7;border-right:1px solid #bdc3c7;font-size:10px;text-align:right;">
                        VALOR
                    </td>
                </tr>

            <?php
            while ($row = mysqli_fetch_assoc($res)) {
            ?>
                <tr>
                    <td style="width: 25%;padding:2px;text-align:center;border-bottom:1px solid #bdc3c7;border-left:1px solid #bdc3c7;font-size:10px;text-align:right;">
                        <!-- <?php //echo $row['codigo']; ?> -->
                    </td>
                    <td style="width: 25%;padding:2px;text-align:center;border-bottom:1px solid #bdc3c7;border-left:1px solid #bdc3c7;border-right:1px solid #bdc3c7;font-size:10px;text-align:right;">
                        <?php echo number_format($row['ret_base'], 0); ?>
                    </td>
                    <td style="width: 25%;padding:2px;text-align:center;border-bottom:1px solid #bdc3c7;border-left:1px solid #bdc3c7;border-right:1px solid #bdc3c7;font-size:10px;text-align:right;">
                        <?php echo $row['porcentaje']; ?>
                    </td>
                    <td style="width: 25%;padding:2px;text-align:center;border-bottom:1px solid #bdc3c7;border-left:1px solid #bdc3c7;border-right:1px solid #bdc3c7;font-size:10px;text-align:right;">
                        <?php echo number_format($row['ret_importe'], 0); ?>
                    </td>
                </tr>
            <?php } ?>

            </table>
            <?php } // FIN IF ?>
            
        </td>
      
       <td style="width: 30%; vertical-align: top; padding-left: 5px;">
            <table cellspacing="0" style="width: 100%;">
                <tr style="background-color:<?php echo $color; ?>">
                    <td colspan="2" style="width: 100%;color:white;text-align:center;padding:2px;"> 
                        <strong style="font-size:10px;color: #000" >TOTALES</strong>
                    </td>
                </tr>
                <tr>
                    <td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        SUBTOTAL 1
                    </td>
                    <td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        <?php echo number_format($subtotal_global,0); ?>
                    </td>
                </tr>
                <tr>
                    <td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        DESCUENTO
                    </td>
                    <td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        <?php echo number_format($descuento_global,0); ?>
                    </td>
                </tr>
                <tr>
                    <td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        SUBTOTAL 2
                    </td>
                    <td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        <?php echo number_format($subtotal_global-$descuento_global,0); ?>
                    </td>
                </tr>
                <tr>
                    <td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        IMPUESTO
                    </td>
                    <td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        <?php echo number_format($iva_global,0); ?>
                    </td>
                </tr>
                <tr>
                    <td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        RETENCION
                    </td>
                    <td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        <?php echo number_format($total_retencion,0); ?>
                    </td>
                </tr>
                <tr>
                    <td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
                        TOTAL
                    </td>
                    <td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:11px;text-align:right; color: red;"> 
                        <strong><?php echo number_format($sumador_total,0); ?></strong>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<table cellspacing="0" style="width: 99.7%;padding-top: 5px;">
    <tr style="background-color:<?php echo $color; ?>">
        <td style="width: 100%;color:white;padding:2px;text-align:center;"> 
            <strong style="font-size:10px;color: #000" >OBSERVACIONES</strong>
        </td>
    </tr>

    <tr>
        <td style="width: 100%;border-left:solid 1px #bdc3c7;border-bottom:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;"><strong style="font-size:8px;"><?php echo $observaciones;?> </strong>
        </td>
    </tr>
    <tr>
        <td>
            <table cellspacing="0" style="width: 100%;" >
                <tr>
                    <td colspan="3" style="width: 100%;padding-bottom: 36px"></td>
                </tr>
                <tr>
                    <td style="width: 45%;">_______________________________</td>
                    <td style="width: 5%;"></td>
                    <td style="width: 45%;">_____________________________</td>  
                </tr>
                <tr>
                    <td style="width: 45%;font-size:8px;">Cliente C.C</td>
                    <td style="width: 5%;"></td>
                    <td style="width: 45%;font-size:8px;">Vendedor C.C</td>     
                </tr>
            </table>
        </td>
    </tr>
</table>
<table cellspacing="0" style="width: 99.7%;padding-top: 5px">
    <tr style="background-color:<?php echo $color; ?>">
        <td style="width: 100%;color:white;padding:2px;text-align:center;"> 
            <strong style="font-size:10px;color: #000" >CONDICIONES DE GARANTIA</strong>
        </td>
    </tr>
    <tr>
        <td style="width: 100%;border-left:solid 1px #bdc3c7;border-bottom:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;"><strong style="font-size:8px;"><?php echo $condiciones;?> </strong>
        </td>
    </tr>
</table>