<? 
require_once('../conf/connection.php');

 $numero=$_GET["num"];
 $efectivo=$_GET["efectivo"];
 $fecha = date("Y-m-d");
 $hora =  date("H:i:s");

  $query_sum="SELECT  sum(valor_total) AS total_venta FROM detalles_pedido  WHERE numero='$numero'";
  $res_sum=mysql_query($query_sum); 
  $total=mysql_result($res_sum,0,"total_venta");
  
  $neto=$total/1.19;
  
  $iva=($neto*0.19)/1.19;
  $vuelto=$total-$efectivo;
  
  if($efectivo<>""){
  
?>
<!DOCTYPE html>
<html dir="ltr" lang="en-US"><head>
    <meta charset="utf-8">
    <title>mod_venta</title>
    <meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">
    <script type='text/javascript' src='jquery-1.7.1.min.js'></script>
    <!--[if lt IE 9]><script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    <link rel="stylesheet" href="../style.css" media="screen">
    <!--[if lte IE 7]><link rel="stylesheet" href="style.ie7.css" media="screen" /><![endif]-->
    <link rel="stylesheet" href="../style.responsive.css" media="all">

    <script src="../jquery.js"></script>
    <script src="../script.js"></script>
    <script src="../script.responsive.js"></script>



<style>.art-content .art-postcontent-0 .layout-item-0 { border-top-width:1px;border-top-style:solid;border-top-color:#B1C9C7;margin-top: 10px;margin-bottom: 10px;  }
.art-content .art-postcontent-0 .layout-item-1 { border-right-style:solid;border-right-width:1px;border-right-color:#B1C9C7; padding-right: 10px;padding-left: 10px;  }
.ie7 .art-post .art-layout-cell {border:none !important; padding:0 !important; }
.ie6 .art-post .art-layout-cell {border:none !important; padding:0 !important; }

</style>
<script>
function valida(){
	  miPopup = window.open("rut.php?rut="+document.getElementById('rut').value+"","","width=950,height=700,top=30,left=200,status=no,  scrollbars=no, toolbars=no, menubar=no,resizable=yes,directories=no");
	  miPopup.focus();
	  window.close();
	
	}
	
function finalizar(){
	  miPopup = window.open("reg_cot.php?numero=<? echo $numero ?>&rut="+document.getElementById('identidad').value+"","fac_","width=950,height=700,top=30,left=200,status=no,  scrollbars=no, toolbars=no, menubar=no,resizable=yes,directories=no");
	  miPopup.focus();
	
	
	}

</script>
  <script type="text/javascript">
$(document).ready(function(){
// Demo 5
$('#identidad').Rut({
  on_error: function(){ alert('Rut incorrecto'); },
  format_on: 'keyup' 
});
$("#content > ul").tabs();
});

function cerrar() {
			window.close();
		}

</script> 
<script type="text/javascript" src="../admin/clientes/js/jquery-1.6.2.js"></script>
   <script src="../admin/clientes/js/jquery.Rut.js" type="text/javascript"></script>
  <script type="text/javascript" src="../admin/clientes/funciones/scripts.js"></script> 
<script type="text/javascript">

function info (elEvento) { 
         evento = elEvento || window.event;
         k=evento.keyCode; //número de código de la tecla.
        
		       //busqueda avanzda.- 
          if (k==13){
			   
			   miPopup = window.open("rut.php?rut="+document.getElementById('identidad').value+"&num=<? echo $numero ?>","cant_","width=300,height=130,top=80,left=200,status=no, scrollbars=no, toolbars=no, menubar=no,resizable=yes,directories=no");
			miPopup.focus();

			  
			  }
		  
		 }
window.onload = function() {
document.onkeydown = info;
}

</script>
</script>
</head>
<body>
<div id="art-main">

<div class="art-sheet clearfix">
            <div class="art-layout-wrapper">
                <div class="art-content-layout">
                    <div class="art-content-layout-row">
                        <div class="art-layout-cell art-content"><article class="art-post art-article">
                                
                                                
                                <div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-1" style="width: 100%" >
       
        <p>
      <div id='suma'>
       
          <table width="867" border="0">
  <tr>
    <td colspan="5" align="right"><h3>Registro de cotizaciones</h3></td>
    </tr>
  <tr>
    <td width="134">RUT:</td>
    <td colspan="3">
    <input type="text" name="identidad" id="identidad"  
    KeyPress="return num(event)" autofocus></td>
    <td><img src="../images/tecla_enter.png" width="37" height="25"></td>
  </tr>
  <tr>
    <td>RAZON SOCIAL:</td>
    <td colspan="4"><input name="razon" type="text" id="razon" readonly="readonly"></td>
  </tr>
  <tr>
    <td>GIRO:</td>
    <td colspan="4"><input name="giro" type="text" id="giro" readonly="readonly"></td>
  </tr>
  <tr>
    <td>DIRECCIÓN:</td>
    <td colspan="4"><input name="dir" type="text" id="dir" readonly="readonly"></td>
  </tr>
  <tr>
    <td>COMUNA:</td>
    <td width="297"><input name="comuna" type="text" id="comuna" readonly="readonly"></td>
    <td width="84">CIUDAD:</td>
    <td colspan="2"><input name="ciudad" type="text" id="ciudad" readonly="readonly"></td>
  </tr>
  <tr>
    <td colspan="5">
    <div style="height:300px; width:100%;  overflow: auto;">
    
      <?  
          $buscar='select * from detalles_pedido inner join articulos ON 
          articulos.referencia=detalles_pedido.codarticulo where numero=\''.$numero.'\'';
		   $r=mysql_query($buscar,$conn) or die("Error en el query: ".mysql_error());
		   $n=mysql_num_rows($r);
		  
		    //si hay registros los procesamos
			if($n>0)
			{
			?>
				<table  width="100%" border="0">
				<tr >
				<td width="165" bgcolor="#46BBD2">CODIGO</td>
				<td width="284" bgcolor="#46BBD2">PRODUCTO</td>
				<td width="114" bgcolor="#46BBD2">CANTIDAD</td>
				<td width="154" bgcolor="#46BBD2">PRECIO UNITARIO</td>
				<td width="120" bgcolor="#46BBD2">TOTAL</td>
              </tr><?
				while($row=mysql_fetch_assoc($r))
				{ //Procesamos cada registro como una fila de tabla
					?>
					<tr><?
					//$row["nomCampo"] estos nomCampo son los campos devueltos por el
					//query en la variable $r que procesa mysql_fetch_assoc
					?>
					 <td height="22"><? echo  $row["codarticulo"] ?></td>
					 <td><? echo  $row["descripcion"] ?></td>
					 <td align="right"><? echo $row["cantidad"] ?></td>
					 <td align="right"><? echo 
					 $format_number = number_format($row["valor_unitario"], 0, ',', '.'); ?></td>
					 <td align="right"><? echo 
					 $format_number = number_format($row["valor_total"], 0, ',', '.');
					 
					 $idplatos=$row["idplatos"];  ?>					   </td>
					 </tr>
				<? }
				
				?>
				</table>
			<? } ?>
    
    </div>
    
    </td>
  </tr>
  <tr>
    <td align="right">&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td width="79" align="right">NETO</td>
    <td width="251" align="right"><input name="neto" type="text" id="neto" style="text-align:right" value="<? 
	echo $format_number = number_format($neto, 0, ',', '.'); ?>" readonly="readonly"></td>
  </tr>
  <tr>
    <td align="right">&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td align="right">IVA</td>
    <td align="right"><input name="iva" type="text" id="iva" style="text-align:right " value="<? echo 
	$format_number = number_format($iva, 0, ',', '.'); ?>" readonly="readonly"></td>
  </tr>
  <tr>
    <td align="right">&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td align="right">TOTAL</td>
    <td align="right"><input name="total" type="text" id="total" style="text-align:right" value="<? echo 
	$format_number = number_format($total, 0, ',', '.'); ?>" readonly="readonly"></td>
  </tr>
  <tr>
    <td colspan="5" align="right">
    <input type="button" name="button" id="button" value="GENERAR DOCUMENTO"
    class="art-button" style="height:50px; width:150px;" onClick="finalizar()">
      <input type="submit" name="button2" id="button2" value="Cancelar"
      class="art-button" style="height:50px; width:120px;" onClick="cerrar()"></td>
  </tr>
  <tr>
    <td colspan="5">&nbsp;</td>
  </tr>
  </table>

        </div>
       
        </p>
    </div>
    </div>
</div>
<div class="art-content-layout-br layout-item-0">
</div></div>


</article></div>
                    </div>
                </div>
            </div>

    </div>
    
</div>


</body></html>
<? }else{?><script>alert("Existen campos vacíos, verifique la información..."); 
miPopup = window.open("final.php?num=<? echo $numero ?>","cant_","width=500,height=500,top=10,left=300,status=no, scrollbars=no, toolbars=no, menubar=no,resizable=yes,directories=no");
miPopup.focus();
window.close();</script> <? } ?>