<table cellspacing="0" style="width: 100%; padding-top: 5px;">
    <tr style="background-color:<?php echo $color; ?>">
            <td style="width: 10%;color:white;padding:2px;text-align:center"> 
                <strong style="font-size:10px;color: #000">REF</strong>
            </td>
            
            <td style="width: 4%; color:white;padding:2px;text-align:center"> 
                <strong style="font-size:10px;color: #000">GTIA</strong>
            </td>
            <td style="width: 42%; color:white;padding:2px;text-align:center"> 
                <strong style="font-size:10px;color: #000">DESCRIPCIÓN</strong>
            </td>
            <td style="width: 5%; color:white;padding:2px;text-align:center"> 
                <strong style="font-size:10px;color: #000">UM</strong>
            </td>
            <td style="width: 5%; color:white;padding:2px;text-align:center"> 
                <strong style="font-size:10px;color: #000">CANT</strong>
            </td>
            <td style="width: 7%; color:white;padding:2px;text-align:center"> 
                <strong style="font-size:10px;color: #000">V X UNI</strong>
            </td>
            <td style="width: 8%; color:white;padding:2px;text-align:center"> 
                <strong style="font-size:10px;color: #000">V BRUTO</strong>
            </td>
            <td style="width: 4%; color:white;padding:2px;text-align:center"> 
                <strong style="font-size:10px;color: #000">IMP</strong>
            </td>
            <td style="width: 5%; color:white;padding:2px;text-align:center"> 
                <strong style="font-size:10px;color: #000">DESC</strong>
            </td>
            <!--<td style="width: 5%; color:white;background-color:#bdc3c7;padding:2px;text-align:center"> 
                <strong style="font-size:10px;color: #000">V IMP</strong>
            </td>-->
            <td style="width:9%; color:white;padding:2px;text-align:center"> 
                <strong style="font-size:10px;color: #000">V TOTAL</strong>
            </td>
        </tr>

<?php
    $suma=0;
    $sql=mysqli_query($con, "SELECT * from venta_detalle where ventas_ven_id='$ven_id'");
    while ($row=mysqli_fetch_array($sql))
    {
        $vend_id=$row['vend_id'];
        $vend_art_id=$row['vend_art_id'];
        $vend_referencia=$row['vend_referencia'];
        $vend_nombre=$row['vend_nombre'];
        $vend_unidad=$row['vend_unidad'];
        $vend_cantidad=$row['vend_cantidad'];
        $vend_precio=$row['vend_precio'];
        if ($row['vend_iva']>0){ $vend_iva=$row['vend_iva']; } else { $vend_iva='0';}
        if ($row['vend_desc']>0){ $vend_descuento=$row['vend_desc']; } else { $vend_descuento='0';}
        $iva0=$vend_iva/100; //0.19
        $iva1=1+$iva0; //1.19

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

        $suma+=$vend_cantidad;

        $gar=mysqli_query($con,"SELECT * FROM articulos where art_id='$vend_art_id' and empresa='$empresa'") ;
        $gar=mysqli_fetch_array($gar);
?>
    <tr>
        <td style="padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo $vend_referencia;?>
        </td>
        
        <td style="padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo $gar['art_garantia'];?>
        </td>
        <td style="padding:2px;text-align:left;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo $vend_nombre;?>  <?php  if ($gar['art_referencia2']<>'null') { echo ' - '; echo $gar['art_referencia2'];}?>
            <?php 
                $art0=mysqli_query($con,"SELECT count(*) AS numrows FROM venta_detalle_sabores_productos WHERE vend_id='$vend_id'")or die(mysqli_error($con));
                $row0=mysqli_fetch_array($art0);
                $numrows = $row0['numrows'];
                if($numrows>0)  
                {
                    echo'('; $art=mysqli_query($con,"SELECT * FROM venta_detalle_sabores_productos WHERE vend_id='$vend_id'")or die(mysqli_error($con));
                        while ($row1=mysqli_fetch_array($art))
                        {
                            echo $row1['sab_nombre'];
                            echo '-';
                        }
                    echo')';
                } 

                $sql4=mysqli_query($con,"SELECT * from seriales where venta_detalle_vend_id='$vend_id'");
                $result4=mysqli_num_rows($sql4);
                if($result4>0)
                { 
                    echo '(- ';
                    while ($row4=mysqli_fetch_array($sql4))
                    {
                        echo $row4['ser_codigo'];
                        echo ' - ';
                    }
                    echo ')';
                }
            ?>
        </td>
         <td style="padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo $vend_unidad;?>
        </td>
        <td style="padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo $vend_cantidad;?>
        </td>
        <td style=";padding:2px;text-align:right;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo number_format($precio_unit_sin_iva_item,0);?>
        </td>
        <td style=";padding:2px;text-align:right;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo number_format($precio_total_sin_iva_item,0);?>
        </td>
        <td style="padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo $vend_iva;?>
        </td>
        <td style="padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo $vend_descuento;?>
        </td>
        <!--<td style="padding:2px;text-align:right;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php //echo number_format($precio_total_sin_iva_item,0);?>
        </td>-->
        
        <td style="padding:2px;text-align:right;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo number_format($precio_total_sin_iva_item+$total_iva_item,0);?>
        </td>
    </tr>
       
<?php   }  

    $suma_com=0;
    $sql=mysqli_query($con, "SELECT * from venta_detalle_combo where ven_id='$ven_id'");
    while ($row1=mysqli_fetch_array($sql))
    {
        $combo_referencia=$row1["combo_referencia"];
        $combo_nombre=$row1['combo_nombre'];       
        $combo_cantidad=$row1["combo_cantidad"];
        $combo_precio=$row1['combo_precio'];
        if ($row1['combo_iva']>0){ $combo_iva=$row1['combo_iva']; } else { $combo_iva='0';}
        if ($row1['combo_desc']>0){ $combo_desc=$row1['combo_desc']; } else { $combo_desc='0';}
        $com_iva0=$combo_iva/100; //0.19
        $com_iva1=1+$com_iva0; //1.19

        $precio_total_sin_iva_und_com=($combo_precio/$com_iva1); //precio sin iva  840.336 unidad
        $precio_total_sin_iva_item_com=($combo_precio/$com_iva1)*$combo_cantidad; //precio sin iva  840.336
        $descuento_item_com=($combo_desc/100)*$precio_total_sin_iva_item_com; //descuento_item 84.033
        $total_iva_item_com=($precio_total_sin_iva_item_com-$descuento_item_com)*$com_iva0; // total iva  159.336

        $suma_com+=$combo_cantidad;
?>
     
    <tr>
        <td style="padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo $combo_referencia; ?>
        </td>
        <td style="width: 5%;padding:2px;text-align:left;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
        </td>
        <td style="padding:2px;text-align:left;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo $combo_nombre;?>
        </td>
        <td style="padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            COMB
        </td>
         <td style=";padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo $combo_cantidad;?>
        </td>        
        <td style=";padding:2px;text-align:right;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo number_format($precio_total_sin_iva_und_com,0);?>
        </td>
         <td style=";padding:2px;text-align:right;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo number_format($precio_total_sin_iva_item_com,0);?>
        </td>
        <td style="padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo $combo_iva;?>
        </td>
        <td style=";padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo $combo_desc;?>
        </td>
        <td style="padding:2px;text-align:right;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
            <?php echo number_format($precio_total_sin_iva_item_com+$total_iva_item_com,0);?>
        </td>
    </tr>
<?php    }  ?>

    <tr>
        <td style="padding:2px;text-align:right;border-left:solid 1px #bdc3c7;border-bottom:solid 1px #bdc3c7;font-size:8px">Total Items</td>
        <td style="padding:2px;text-align:center;border-left:solid 1px #bdc3c7;border-bottom:solid 1px #bdc3c7;font-size:8px"><?php echo $total_items; ?></td>
        <td colspan="2" style="padding:2px;text-align:right;border-left:solid 1px #bdc3c7;border-bottom:solid 1px #bdc3c7;font-size:8px">Total Unidades</td>
        <td  style="padding:2px;text-align:center;border-left:solid 1px #bdc3c7;border-bottom:solid 1px #bdc3c7;font-size:8px"><?php echo $suma+$suma_com; ?></td>
        <td colspan="5" style="padding:2px;text-align:le;border-left:solid 1px #bdc3c7;border-bottom:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:8px"></td>
    </tr>
</table>