<script src="../src/jquery.js"></script>
<meta name="viewport" content="width=device-width">

<meta name="mobile-web-app-capable" content="yes">

<link rel="icon" sizes="192x192" href="../img/cloud3.png">
<style type="text/css" media="print">
* {
  font-family:"Arial";
  
  font-size:12px;
}

@page{
   @margin: 2px;
}


* {
  font-family:"Arial";
  
  font-size:12px;
}
h3{
	font-size:12px;
	font-weight:100;
}
h5{
	font-size:12px
}
th{
	background: green;
	color:white;
	text-align: center;

}
td,b{
	font-size:10px;
}
.datos_empres2{
	font-size: 20px;
	@font-weight: 100;
	
}

img{
	width:300px;
	height:300px;
}


</style>

<style>
	img{
	width:150px;
	height:150px;
	}
</style>
<?php
$folio = $_GET['folio'];
include_once("../php/config.php");
$sql_venta = mysql_query("select * from ventas where id_venta='$folio'") or die (mysql_error());

$sql_detalle = mysql_query("select * from detalle_venta where folio='$folio'") or die (mysql_error());

$cliente = @mysql_result($sql_venta,0,"cliente");
$sql_balance = mysql_query("select sum(balance) as total from ventas where cliente='$cliente' and estado!='Anulada'") or die (mysql_error());
$sql_cliente = mysql_query("select * from clientes where nombre='$cliente'") or die (mysql_error());
$prefijo = @mysql_result($sql_venta,0,"tipo_ncf");
$miBalance = @mysql_result($sql_balance,0,"total");
$termino = @mysql_result($sql_venta,0,"termino");
$ncf = @mysql_result($sql_venta,0,"ncf");
$descuento = @mysql_result($sql_venta,0,"descuento");

?>
<div style="margin-left: 5px; margin-right: 20px;">
<center>

<?php
$parametros = mysql_query("select * from parametros") or die (mysql_error());
$tax_option= @mysql_result($parametros,0,"impuestos_no_incluido");
$mostrar_itbis= @mysql_result($parametros,0,"mostrar_itbis");
$sql_empresa = mysql_query("SELECT * FROM empresa") or die(mysql_error());
$sql_ncf = mysql_query("SELECT * FROM ncf where prefijo='$prefijo'") or die(mysql_error());

$enombre= @mysql_result($sql_empresa,0,"nombre");
$etelefono= @mysql_result($sql_empresa,0,"telefono");	
$edireccion= @mysql_result($sql_empresa,0,"direccion");	
$ernc= @mysql_result($sql_empresa,0,"rnc");	
$eemail= @mysql_result($sql_empresa,0,"email");	
$logo= @mysql_result($sql_empresa,0,"logo");	
$nota= @mysql_result($sql_venta,0,"nota");	

	
?>

<span class="datos_empres2" style="font-size: 18px;">
<?php if($logo!=""){?>
<?php echo "<img src = '../LOGOS/$logo'>";?>
<?php }?>
<br>
<?php echo $enombre;?></span><br>
<span class="datos_empres1"><?php echo $etelefono;?> |  <?php echo $eemail;?> </span><br>
<span class="datos_empres1"><?php echo $edireccion;?> </span><br>
<span class="datos_empres1"><?php echo $ernc;?></span><br>
<?php 
	if(@mysql_result($sql_venta,0,"termino")=="Conduce"){
?>
	<h2>CONDUCE</h2>
<?php }else{?>
	
<?php }?>
</center>


Orden #: <?php echo @mysql_result($sql_venta,0,"folio")?><br>
Fecha : <?php echo  @mysql_result($sql_venta,0,"hora");?><br>
Termino: <?php echo @mysql_result($sql_venta,0,"termino");?><br>


Cliente: <?php echo $cliente?><br>
Informacion: <?php echo $nota?><br>
Ticket: <?php echo @mysql_result($sql_venta,0,"ticket");?><br>
RNC/ Cedula: <?php echo @mysql_result($sql_cliente,0,"cedula");?><br>
Telefono: <?php echo @mysql_result($sql_cliente,0,"telefono");?><br>
Direccion: <?php echo @mysql_result($sql_cliente,0,"direccion");?><br>

<div style="float: right;">
<?php if($ncf!="00000000"){?>
<?php echo @mysql_result($sql_venta,0,"tipo_ncf");?><br>
NCF:  <?php echo @mysql_result($sql_venta,0,"ncf");?><br>
Valido hasta:  31/12/2024<br>
<?php }?>
</div>


<table class="" style="width:100%">
	<thead>             
		<th>ITEM | CANTIDAD | TOTALES</th>
		<th></th>
		
		
	</thead>
<tbody>
<?php while($r=mysql_fetch_array($sql_detalle)){?>
			<tr>
			
                
				<td><?php echo $r["descripcion"];?> 
				<br>
				<?php
				if($r["tipo_impuesto"]>0 and $ncf!=""){
					$v = 1;
					$v = $v.".".$r["tipo_impuesto"];
                    ////$precio = $r["precio"] / $v;
					$precio = $r["precio"];
					
                }else{
					$precio = $r["precio"];
				}
				
				?>
				<?php echo decimal($r["cantidad"])." X ".decimal($precio)." = ".decimal($r["cantidad"] * $precio)?>
                <br>
               <?php 
				
				if($r["tipo_impuesto"]>0 and $ncf!=""){
					$v = 1;
					$v = $v.".".$r["tipo_impuesto"];
                    $sin_itbis = $r["total_precio"] / $v;
					$vItbis0 = $r["total_precio"] -  $sin_itbis;
					///echo "<small style='font-size:10px;'>ITBIS: ".decimal($vItbis0)."</small><br>";
                }
			
                ?>
                
                </td>
				
             
               
			</tr>
         <?php }?>
	</tbody>
</table>
<hr>

<div style="width:70%">




<?php if($ncf!="00000000"){
	 $sinItb = mysql_result($sql_venta,0,"total") / 1.18;
	 $tt = mysql_result($sql_venta,0,"total");
	 $itb = $tt - $sinItb;
	?>
<span style="float: left">SUBTOTAL: </span> <span style="float: right;"><?php echo @decimal(mysql_result($sql_venta,0,"total") / 1.18)?></span><br>

<span style="float: left">ITBIS: </span> <span style="float: right;"><?php echo @decimal($itb)?></span><br>

<?php }?>


<span style="float: left">DESCUENTO </span> <span style="float: right;"><?php echo @decimal(mysql_result($sql_venta,0,"descuento"))?></span><br>
<span style="float: left">TOTAL VENTA: </span> <span style="float: right;"><?php echo @decimal(mysql_result($sql_venta,0,"total"))?></span><br>


	<b><span style="float: left">Efectivo: </span> <span style="float: right;"><?php echo @decimal(mysql_result($sql_venta,0,"efectivo"))?></span></b><br><br>
	<span style="float: left">Tarjeta: </span> <span style="float: right;"><?php echo @decimal(mysql_result($sql_venta,0,"monto_tarjeta"))?></span><br>
	<span style="float: left">Cheque: </span> <span style="float: right;"><?php echo @decimal(mysql_result($sql_venta,0,"cheque")."#: ".@mysql_result($sql_venta,0,"numero_cheque"))?></span><br>
	
	<span style="float: left">Su cambio: </span> <span style="float: right;"><?php echo @decimal(mysql_result($sql_venta,0,"devuelta")."#: ".@mysql_result($sql_venta,0,"numero_cheque"))?></span><br>


	<hr>
	<?php if($cliente!="Generico"){?>
<span style="float: left">Balance pendiente: </span> <span style="float: right;"><?php echo @decimal($miBalance)?></span><br>
	<?php }?>
</div>
<br>

<br>
<br>
<br>
<center>
	________________________<br>
	Firma cliente
</center>




Le atendio: <b><?php echo @mysql_result($sql_venta,0,"usuario")?></b>
<br><br>




<br><br>
<center>
<?php echo $_COOKIE["pie"]?>
</center>
</div>
<br><br>
<a href="_nueva_venta.php"> Nueva venta</a>

<script>
var myLevel = localStorage.getItem("nivel");

	window.print()

	
	

	
	setTimeout(function(){
		var termino = "<?php echo $termino;?>";
		var id_venta = "<?php echo $folio;?>";
		window.location.href="_nueva_venta.php";
				
	},3000)
</script>