 <body id="salescomplete" class="my-poscol sales">
        <div id="content_area_wrapper">
            <div id="content_area">
                <?php
                $sql = mysqli_query($con, "SELECT * from factura where empresa='$empresa'");
                $row = mysqli_fetch_array($sql);
                $fac_tam = $row['fac_cm'];
                $fac_msj = $row['fac_msj'];
                ?>
                <style type="text/css">
                    #receipt_wrapper { width: <?php echo $fac_tam; ?>cm; }
                </style>

                <?php
                $sqlv = mysqli_query($con, "SELECT * from ventas where ven_id='$ven_id'");
                $serv = mysqli_fetch_array($sqlv);
                $vendedor = $serv['vendedor'];
                $Cliente_clie_id = $serv['Cliente_clie_id'];
                $ven_ser_id = $serv['ven_ser_id'];
                $ven_tipo = $serv['ven_tipo'];
                $ven_propina = $serv['ven_propina'];

                $caja = $serv['caja'];
                $caj = mysqli_query($con, "SELECT * FROM cajas where caja_id='$caja' ") or die(mysqli_error($con));
                $res_ca = mysqli_fetch_array($caj);
                $caja_nombre = $res_ca['caja_nombre'];

                $resol = mysqli_query($con, "SELECT * FROM serie_factura where  ser_id='$ven_ser_id' and empresa='$empresa'") or die(mysqli_error($con));
                $res = mysqli_fetch_array($resol);
                $ser_inicio = $res['ser_inicio'];
                $ser_resolucion = $res['ser_resolucion'];
                $ser_fecha = $res['ser_fecha'];
                $ser_fin = $res['ser_fin'];
                $ser_fecha_ven = $res['ser_fecha_ven'];

                $dir = mysqli_query($con, "SELECT * FROM cliente where clie_id='$Cliente_clie_id'") or die(mysqli_error($con));
                $dire = mysqli_fetch_array($dir);
                $clie_cc = $dire['clie_cc'];
                $clie_direccion = $dire['clie_direccion'];
                $clie_telefono = $dire['clie_telefono'];
                $clie_barrio = $dire['clie_barrio'];

                $us = mysqli_query($con, "SELECT * from usuario where  usu_id='$vendedor'");
                $us = mysqli_fetch_array($us);
                $vendedor_nombre = $us['usu_nombre'];
                $usu_telefono = $us['usu_tel'];
                ?>

                <div id="receipt_wrapper">
                    <div id="receipt_header">
                        <?php if ($logo == 'si') { ?>
                            <?php $nu = rand(1, 1000); ?>
                            <div id="customer"><img src="..\img\<?php echo $empresa . '.png?' . $nu . ''; ?>" style="width: <?php echo $fac_tam; ?>cm;"></div>
                        <?php } else { ?>
                            <div id="company_name"><?php echo $emp_nombre; ?></div>
                        <?php } ?>
                        <div id="company_nit"><strong><?php echo $emp_representante; ?></strong></div>
                        <div id="company_nit"><strong>NIT:<?php echo $emp_nit; ?></strong></div>
                        <div id="company_address"><?php echo $emp_direccion; ?></div>
                        <div id="company_phone"><?php echo $emp_telefono; ?></div>
                        
                        <?php if ($ven_tipo == 'pos electronico' || $ven_tipo == 'electronica') { ?>
                            <div id="regimen"><?php echo $emp_regimen; ?></div>
                            <div style="text-align: center;font-size:10px;padding-bottom:0px;">
                                <p>Resolucion de Facturación No. <?php echo $ser_resolucion; ?> de <?php echo $ser_fecha; ?>, Rango <?php echo $ser_inicio; ?> Al <?php echo $ser_fin; ?> - Vigencia Desde: <?php echo $ser_fecha ?> Hasta: <?php echo $ser_fecha_ven; ?></p>
                            </div>
                        <?php } ?>
                        
                        <div id="sale_time"><?php echo $serv['ven_fecha']; ?> - <?php echo $serv['ven_hora']; ?>
                            <h6 style="font-size: 10px; margin: 2px 0;"><?php echo $texto_cabeza; ?> </h6>
                        </div>
                    </div>

                    <div id="receipt_general_info">
                        <div id="sale_id" class="receipt-numero-factura">
                            <?php 
                            if ($ven_tipo == 'pos electronico') echo "DOCUMENTO EQUIVALENTE POS # ";
                            else if ($ven_tipo == 'electronica') echo "FACTURA ELECTRONICA DE VENTA # ";
                            else if ($ven_tipo == 'pos') echo "FACTURA POS # ";
                            else if ($ven_tipo == 'remision') echo "REMISION # ";
                            
                            echo $serv['ven_prefijo'] . $serv['ven_n_venta']; 
                            ?>
                        </div>
                        <div id="customer">Cliente: <?php echo $serv['ven_nombre']; ?></div>
                        <div id="customer">Documento: <?php echo $clie_cc; ?> Telefono: <?php echo $clie_telefono; ?> </div>
                        <div id="customer">Dirección: <?php echo $clie_direccion; ?></div>
                        <?php if ($negocio_neg_id == 7) { ?>
                            <div id="customer">Barrio: <?php echo $clie_barrio; ?></div>
                            <div id="customer">Negocio: <?php echo $dire['clie_empresa']; ?></div>
                        <?php } ?>
                        <div id="employee">Vendedor: <?php echo $vendedor_nombre; ?></div>
                        <div id="employee">Caja: <?php echo $caja_nombre; ?></div>
                        <?php if ($negocio_neg_id == 7) { ?>
                            <div id="employee">Telefono: <?php echo $usu_telefono; ?></div>
                        <?php } ?>
                        <div id="employee">Forma de Pago: <?php echo $serv['ven_forma_de_pago']; ?></div>
                    </div>

                    <table id="receipt_items">
                        <thead>
                            <tr>
                                <th class="my-text-align-left">Ref</th>
                                <th class="receipt-item-cell-description my-text-align-left">Artículo</th>
                                <th class="receipt-item-cell-quantity my-text-align-center">Cant</th>
                                <th class="receipt-item-cell-price my-text-align-right">Total</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $suma = 0;
                            $sumador_combo = 0;
                            $sumador_total = 0;
                            $neto = 0;
                            $total_descuento = 0;
                            $total_iva = 0;
                            $sumador_articulos = 0;

                            $sql = mysqli_query($con, "SELECT *,RIGHT(vend_referencia,6) as vend_referencia 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_cantidad = $row['vend_cantidad'];
                                $vend_unidad = $row['vend_unidad'];
                                $vend_precio = $row['vend_precio']; 
                                $suma += $row['vend_cantidad'];

                                $precio_total_item = $vend_precio * $vend_cantidad;

                                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;
                                $iva1 = 1 + $iva0;

                                $precio_total_sin_iva_item = ($vend_precio / $iva1) * $vend_cantidad;
                                $descuento_item = ($vend_descuento / 100) * $precio_total_sin_iva_item;
                                $total_iva_item = ($precio_total_sin_iva_item - $descuento_item) * $iva0;

                                $neto += $precio_total_sin_iva_item;
                                $total_descuento += $descuento_item;
                                $total_iva += $total_iva_item;

                                $sumador_articulos = ($neto + $total_iva) - $total_descuento;
                            ?>
                                <tr class="receipt-item-row">
                                    <td><?php echo $vend_referencia; ?></td>
                                    <td class="receipt-item-cell-description">
                                        <?php echo $vend_nombre; ?>
                                        <?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);
                                        if ($row0['numrows'] > 0) {
                                            echo '(';
                                            $art = mysqli_query($con, "SELECT * FROM venta_detalle_sabores_productos WHERE vend_id='$vend_id'");
                                            while ($row1 = mysqli_fetch_array($art)) {
                                                echo $row1['sab_nombre'] . '-';
                                            }
                                            echo ')';
                                        }

                                        if ($negocio_neg_id == 1) {
                                            $sql3 = mysqli_query($con, "SELECT count(*) AS numrows from seriales where venta_detalle_vend_id='$vend_id' and venta_detalle_ventas_ven_id='$ven_id' ");
                                            $row1 = mysqli_fetch_array($sql3);
                                            if ($row1['numrows'] > 0) {
                                                echo '(<strong style="font-size:9px">SN: </strong>';
                                                $sql4 = mysqli_query($con, "SELECT * from seriales where venta_detalle_vend_id='$vend_id' and venta_detalle_ventas_ven_id='$ven_id' ");
                                                while ($row4 = mysqli_fetch_array($sql4))
                                                    echo $row4['ser_codigo'];
                                                echo ')';
                                            }
                                            $gar = mysqli_query($con, "SELECT * FROM articulos where art_id='$vend_art_id' and empresa='$empresa'");
                                            $gar = mysqli_fetch_array($gar);
                                            echo '<br><span style="font-size:9px">Gtia: ' . $gar['art_garantia'] . ' meses.</span>';
                                        } else if ($negocio_neg_id == 4) {
                                            $gar = mysqli_query($con, "SELECT * FROM articulos where art_id='$vend_art_id' and empresa='$empresa'");
                                            $gar = mysqli_fetch_array($gar);
                                            echo '<br><span style="font-size:9px">Gtia: ' . $gar['art_garantia'] . ' meses.</span>';
                                        }
                                        ?>
                                        <br><strong>Precio Und: <?php echo number_format($vend_precio, 0); ?></strong>
                                    </td>
                                    <td class="receipt-item-cell-quantity"><?php echo $vend_cantidad; ?></td>
                                    <td class="receipt-item-cell-price"><?php echo number_format($precio_total_item, 0); ?></td>
                                </tr>
                            <?php } ?>

                            <?php
                            $sumador_combo = 0;
                            $sql2 = mysqli_query($con, "SELECT * from venta_detalle_combo where ven_id='$ven_id'");
                            while ($row2 = mysqli_fetch_array($sql2)) {
                                $precio = ($row2['combo_cantidad'] * $row2['combo_precio']);
                                $sumador_combo += $precio;
                            ?>
                                <tr class="receipt-item-row">
                                    <td><?php echo $row2['combo_referencia']; ?></td>
                                    <td><?php echo $row2['combo_nombre']; ?></td>
                                    <td class="receipt-item-cell-quantity"><?php echo $row2['combo_cantidad']; ?></td>
                                    <td class="receipt-item-cell-price"><?php echo number_format($precio, 0); ?></td>
                                </tr>
                            <?php }
                            $sumador_total += $sumador_articulos + $sumador_combo;
                            ?>

                            <tr class="receipt-row-line">
                                <td colspan="4"></td>
                            </tr>
                            <tr class="receipt-row-totales">
                                <td colspan="2">Subtotal:</td>
                                <td colspan="2">$<?php echo number_format($neto + $sumador_combo, 0); ?></td>
                            </tr>
                            <tr class="receipt-row-totales">
                                <td colspan="2">Descuento:</td>
                                <td colspan="2">$<?php echo number_format($total_descuento, 0); ?></td>
                            </tr>
                            <tr class="receipt-row-totales">
                                <td colspan="2">Impuesto:</td>
                                <td colspan="2">$<?php echo number_format($total_iva, 0); ?></td>
                            </tr>

                            <tr class="receipt-row-total">
                                <td colspan="2">Total</td>
                                <td colspan="2">$ <?php echo number_format($sumador_total, 0); ?></td>
                            </tr>
                            <?php if ($ven_propina > 0) { ?>
                                <tr class="receipt-row-totales">
                                    <td colspan="2">Propina:</td>
                                    <td colspan="2">$<?php echo number_format($ven_propina, 0); ?></td>
                                </tr>
                            <?php } ?>

                            <?php
                            if ($serv['ven_forma_de_pago'] == 'Contado') {
                                if ($serv['efectivo'] <> null) {
                            ?>
                                    <tr class="receipt-row-totales">
                                        <td colspan="2">Efectivo</td>
                                        <td colspan="2">$ <?php echo number_format($serv['efectivo'], 0); ?></td>
                                    </tr>
                                    <tr class="receipt-row-totales">
                                        <td colspan="2">Cambio</td>
                                        <td colspan="2">$ <?php echo number_format($serv['efectivo'] - ($sumador_total + $ven_propina), 0); ?></td>
                                    </tr>
                            <?php }
                            } ?>

                            <?php
                            if ($serv['ven_forma_de_pago'] == 'Credito') {
                                $sql = mysqli_query($con, "SELECT sum(veab_abono) as total from venta_abonos where ventas_ven_id='$ven_id' ");
                                $sql = mysqli_fetch_array($sql);
                                $total_abono = $sql['total'] + 0;
                            ?>
                                <tr class="receipt-row-totales">
                                    <td colspan="2">Abono</td>
                                    <td colspan="2">$ <?php echo number_format($total_abono, 0); ?></td>
                                </tr>
                                <tr class="receipt-row-totales">
                                    <td colspan="2">Saldo</td>
                                    <td colspan="2">$ <?php echo number_format($sumador_total - $total_abono, 0); ?></td>
                                </tr>
                            <?php } ?>

                            <?php if ($negocio_neg_id <> 2) { ?>
                                <tr class="receipt-row-totales">
                                    <td colspan="4" style="padding-top: 30px;">
                                        <div align="right">____________________________ <br> Firma del Cliente </div>
                                    </td>
                                </tr>
                            <?php } ?>
                        </tbody>
                    </table>

                    <div id="observaciones">
                        <strong>Observaciones:</strong><br>
                        <pre style="font-family: inherit; font-size: inherit; white-space: pre-wrap;"><?php echo $serv['observaciones']; ?></pre>
                    </div>
                    <div>
                        <h6 style="font-size: 11px; margin: 5px 0;"><?php echo $condiciones; ?></h6>
                    </div>

                    <?php
                    // Generación del QR
                    $dir = 'temp/';
                    if (!file_exists($dir)) mkdir($dir);
                    $filename = $dir . 'test.png';
                    $numfac = $serv['ven_prefijo'] . $serv['ven_n_venta'];
                    $fecfac = $serv['ven_fecha'];
                    $nitfac = $emp_nit;
                    $docadq = $serv['ven_cc'];
                    $valfac = round($neto, 2);
                    $valiva = round($total_iva, 2);
                    $valotroim = round($total_descuento, 2);
                    $valfaclm = round($sumador_total, 2);
                    $cufe = $serv['cufe'];
                    $contenido = 'NumFac: ' . $numfac . PHP_EOL . 'FecFac: ' . $fecfac . PHP_EOL . 'NitFac: ' . $nitfac . PHP_EOL . 'DocAdq: ' . $docadq . PHP_EOL . 'ValFac: ' . $valfac . PHP_EOL . 'ValIva: ' . $valiva . PHP_EOL . 'ValOtroIm: ' . $valotroim . PHP_EOL . 'ValTotal: ' . $valfaclm . PHP_EOL . 'CUFE: ' . $cufe . PHP_EOL . 'https://catalogo-vpfe.dian.gov.co/document/searchqr?documentkey=' . $cufe;
                    
                    QRcode::png($contenido, $filename, 'L', 10, 3);
                    $qr = $dir . basename($filename);
                    ?>

                    <?php if ($ven_tipo == 'pos electronico' || $ven_tipo == 'electronica') { ?>
                        <div style="text-align: center; margin: 10px 0;">
                            <img style="width: 70%;" src="<?php echo $qr; ?>" alt="QR Code">
                        </div>
                    <?php } ?>

                    <div id="sale_return_policy">
                        <h3><?php echo $fac_msj; ?></h3>
                    </div>
                    
                    <div id="signature">
                        .........................<br>
                        <?php if ($ven_tipo == 'pos electronico' || $ven_tipo == 'electronica') { ?>
                            Elaborado por Grupo Empresarial Technópolis S.A.S <br>Nit 901466156-9<br>
                        <?php } ?>
                        VICPOS software de facturación
                    </div>

                    <?php if ($ven_tipo == 'pos electronico' || $ven_tipo == 'electronica') { ?>
                        <div style="word-break: break-all; font-size: 8px; text-align: center; margin-top: 5px;">
                            <?php echo $serv['cufe']; ?>
                        </div>
                    <?php } ?>
                </div>
            </div>
        </div>

        <?php if ($info["os"] == 'WIN') { ?>
            <script language="Javascript">
                window.print();
                window.onafterprint = function() {
                    window.close();
                }
            </script>
        <?php } else { ?>
            <button class="oculto-impresion btn-cerrar" onclick="cerrar()">CERRAR</button>
            <script language="Javascript">
                window.print();
                function cerrar() {
                    window.close();
                }
            </script>
        <?php } ?>
    </body>