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

<head>
  <meta charset="utf-8">
  <title>Receipt</title>

  <!-- Normalize or reset CSS with your favorite library -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.min.css">

  <!-- Load paper.css for happy printing -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/paper-css/0.4.1/paper.css">


<link href="https://fonts.cdnfonts.com/css/receiptional-receipt" rel="stylesheet">

<style>
url('https://fonts.cdnfonts.com/css/receiptional-receipt');
</style>



  <style>
   *{
       font-family: "Lucida Console", monospace;
       font-size:18px;
   }
   
   img{
       width:200px;
   }
  
  th{
     border-top:1px dotted black;
     border-bottom:1px dotted black;
     border-right:1px solid black;
     text-align:left;
     font-size:16;
  }
  
  td{
      font-size:18; 
     width:100px;
  }
  </style>
</head>



<?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'") 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;" id="recibo">
<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: 20px;">
<?php if($logo!=""){?>
<?php echo "<img src = '../LOGOS/$logo'>";?>
<?php }?>
<br>
<b>
<?php echo $enombre;?></span></b><br>
<b><span class="datos_empres1"><?php echo $etelefono;?> |  <?php echo $eemail;?> </span></b><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>
<hr>

Orden #: <?php echo @mysql_result($sql_venta,0,"folio")?><br>
Fecha : <?php echo  @fecha(mysql_result($sql_venta,0,"fecha"))." |". 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>
RNC/ Cedula: <?php echo @mysql_result($sql_cliente,0,"cedula");?><br>
Telefono: <?php echo @mysql_result($sql_cliente,0,"telefono");?><br>
<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>

<br><br>
<br><br>
<center>
<table class="" style="width:100%">
            

		<th>CANTIDAD</th>
			<th>ARTICULO </th>
		<th>PRECIO </th>
		<th>TOTAL</th>
		
		

</table>

</center>

<?php while($r=mysql_fetch_array($sql_detalle)){?>

<?php echo $r["descripcion"];?>

<table  cellspacing="20" style="margin-top:-20">
<?php
				if($r["tipo_impuesto"]>0 and $ncf!=""){
					$v = 1;
					$v = $v.".".$r["tipo_impuesto"];
                    $precio = $r["precio"] / $v;
					
					
                }else{
					$precio = $r["precio"];
				}
				
				?>
		<td style="width:150px" >		
				<?php  if($r["medida"]>0 AND $r["cantidad"]<1){echo "<span style='font-size:13px; font-weiht:bolder;'>(".round($r["cantidad"] * $r["medida"])." ".$r["unidad"].") </span>"; } echo ($r["cantidad"])."</td><td cellspacing='20'>".decimal($precio)."</td><td cellspacing='20'>".decimal($r["cantidad"] * $precio)?></td>

               
			</tr>
 
</table>
<?php }?>

<hr>

<div>


<?php 
 $sqlDescuento = mysql_query("SELECT sum(total_precio) as tt from detalle_venta where folio='$folio' and descripcion='*descuento*'") or die(mysql_error());
$adescuento =  @decimal(mysql_result($sqlDescuento,0,"tt"));
$itbis = 1.18;
$sub1 = mysql_result($sql_venta,0,"total") + mysql_result($sql_venta,0,"descuento");
$sub2 = $sub1 / $itbis;

$total_itbis = $sub1 - $sub2;
?>

<span style="float: left">SUB-TOTAL: </span> <span style="float: right;"><?php echo @decimal($sub2)?></span><br>
<span style="float: left">DESCUENTO: </span> <span style="float: right;"><?php echo $descuento?></span><br>
<span style="float: left">ITBIS: </span> <span style="float: right;"><?php echo @decimal($total_itbis)?></span><br>
<span style="float: left">TOTAL: </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>

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




Cajero: <b><?php echo @mysql_result($sql_venta,0,"usuario")?></b><br>
Atendido por: <b><?php echo @mysql_result($sql_venta,0,"vendedor")?></b>
<br><br>




<br><br>
<center>
<?php echo $_COOKIE["pie"]?>
</center>
</div>

<a href="_nueva_venta.php"><<<< FACTURA</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)


	window.addEventListener("keydown",tecla,false);
	$("#rv").focus()
	function tecla(e){
		if(e.keyCode=="13"){
			window.location.href="_nueva_venta.php";
		}
	}
</script>