<div id="verdetalle<?php echo $reg['fac_id']; ?>" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog  modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Detalle de Venta</h4>
            </div>
            <div class="modal-body">
                <div  class="col-md-12">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover table-striped">
                            <thead>
                                <tr>
                                    <th width="10%">REFERENCIA</th>
                                    <th width="5%">CANT</th>
                                    <th width="45%"><span class="pull-center">DESCRIPCIÓN</span></th>
                                    <th width="15%"><span class="pull-right">PRECIO U</span></th>
                                    <th width="5%"><span class="pull-right">DESC.%</span></th>
                                    <th width="20%"><span class="pull-right">PRECIO T</span></th>
                                </tr>
                            </thead>
                            <tbody  class="buscar">
<?php
$sumador_total=0;
$sumador_combo=0;

$neto=0;
$total_descuento=0;
$total_iva=0;
$total_retencion=0;
$sumador_articulos=0;
$sql=mysqli_query($con, "SELECT * from  fac_detalle where fac_periodica_fac_id='$fac_id'");
while ($dato1=mysqli_fetch_array($sql))
{
    $facd_referencia=$dato1['facd_referencia'];            
    $facd_nombre=$dato1['facd_nombre']; 
    $vend_cantidad=$dato1['facd_cantidad'];
    $vend_iva=$dato1['facd_iva'];            
    $vend_descuento=$dato1['facd_desc']; 
    $vend_precio=$dato1['facd_precio'];

    $iva0=$vend_iva/100; //0.19
    $iva1=1+$iva0; //1.19

    $precio_total_item=$vend_precio*$vend_cantidad;//precio normal 1.000.000
    $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*$iva0; // total iva  159.336

    $neto+=$precio_total_sin_iva_item;
    $total_descuento+=$descuento_item;
    $total_iva+=$total_iva_item;
    $sumador_articulos=($neto+$total_iva)-$total_descuento;
    
?>
   
                            <tr>
                                <td ><?php echo $facd_referencia;?></td>
                                <td ><?php echo $vend_cantidad;?></td>
                                <td ><?php echo $facd_nombre;?></td>
                                <td ><span class="pull-right"><?php echo number_format($vend_precio,0);?></span></td>
                                <td ><span class="pull-right"><?php echo number_format($vend_descuento,0);?></span></td>
                                <td style="text-align: right; "><span class="pull-right"><?php echo number_format($precio_total_sin_iva_item,0);?></span></td>
                            </tr>
<?php   } 
$sumador_total=$sumador_articulos+$sumador_combo-$total_retencion;
?>
                            <tr>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td   style="width: 15%; text-align: right;">Subtotal  </td>
                                <td style="width: 15%; text-align: right;">&#36; <?php echo number_format($neto,0);?></td>
                            </tr>
                            <tr>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td   style="width: 15%; text-align: right;">Descuento  </td>
                                <td style="width: 15%; text-align: right;">&#36; <?php echo number_format($total_descuento,0);?></td>
                            </tr>
                            <tr>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  style="width: 15%; text-align: right;">Iva  </td>
                                <td style="width: 15%; text-align: right;">&#36; <?php echo number_format($total_iva,0);?></td>
                            </tr>
                            <tr  style=" border: solid 01px black;  text-align: center; font-size: 10pt;padding:0mm;">
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  border="1" style=" text-align: right;">  </td>
                                <td  style="width: 15%; text-align: right;">TOTAL  </td>
                                <td style="width: 15%; text-align: right;">&#36; <?php echo number_format($sumador_total,0);?></td>
                            </tr>
                            </tbody> 
                        </table>
                    </div> <!-- /.form-group -->
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div> 
    </div>
</div>