<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = 'index.php';
		</script>
		<? 
		exit();
		}
?>
<title>Busqueda Cliente</title>
<style type="text/css">
<!--
.Estilo15 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; }
-->
</style>
<?
$rut = $_GET["rut"];
$cant = $_GET["id"];
$enviar = $_GET["b"];
$folio = $_GET["folio"];
if ($enviar=="")
	{
	$enviar="1";
	}
include "../conex.php";
?>
<table width="100%"align="center" border="0">
  <tr>
    <td width="25%"><div align="center"><img src="../Images/logo.png" width="120" height="120"></div></td>
	<td width="50%"><div align="center"><strong><font size="6">Datos para el documento no.: <?=$folio;?></font></strong></div></td>
    <td width="25%">&nbsp;</td>
  </tr>
</table>


<form name="form1" method="post" action="buscacliente.php?b<? echo "2";?>">
  <table width="79%"align="center" border="0">

    <tr>
      <td width="20%">Razon social:</td>
      <td width="65%"><label>
        <input name="txtcli" type="text" id="txtcli" size="65">
      </label></td>
      <td width="15%"><label>
        <input name="enviar" type="submit" id="enviar" value="Buscar">
      </label></td>
    </tr>
  </table>

</form>
	<?
	$cont=0;
	$caract=$_GET["caracter"];	
	if (isset($caract)) 
		{
		$sql_bc = "SELECT rut_cliente, num_dcto, fecha_emision, total FROM salida where num_dcto='$folio' and tipo_dcto=33 and factor=1";
		$res_bc =mysql_query($sql_bc,$enlace);
		}
	else if ( $txtcli!="" )
		{
		$sql_bc = "SELECT rut_cliente, num_dcto, fecha_emision, total FROM salida where num_dcto='$folio' and tipo_dcto=33 and factor=1";
	$res_bc = mysql_query($sql_bc,$enlace);
		}
	else
		{
		$sql_bc = "SELECT rut_cliente, num_dcto, fecha_emision, total FROM salida where num_dcto='$folio' and tipo_dcto=33 and factor=1";
	$res_bc = mysql_query($sql_bc,$enlace);
		}
	while (mysql_fetch_object ($res_bc))
		{
		$bc_rut = mysql_result($res_bc, $cont, "rut_cliente");
		$bc_rsuc = mysql_result($res_bc, $cont, "num_dcto");
		$bc_rsoc = mysql_result($res_bc, $cont, "fecha_emision");
		$bc_tot = mysql_result($res_bc, $cont, "total");
		$bc_rsoc = date("d/m/Y", strtotime($bc_rsoc));
		
		if ($cont==0)
			{
		?>
		<table width="90%" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr>
			<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="17%" align="center">
				R.U.T.			</td>
<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="30%" align="center">
				Fecha de Emision	</td>
				
<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="25%" align="center">
				Numero Documento	</td>
       

<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="6%" align="center">
				Enviar			</td>
		</tr>
        
		<? 
			}
		?>
		<tr>
	<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="17%" align="right">
				<?=$bc_rut;?></td>
<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="55%" align="left">
		  <?=$bc_rsoc;?></td> 
		  
<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="55%" align="left">
		  <?=$bc_rsuc;?></td> 
             
	<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="6%" align="center">
			<a onClick="JavaScript:enviar('<?=$bc_rut;?>', '<?=$bc_rsuc;?>', '<?=$bc_tot;?>', '<?=$bc_rsoc;?>')">
			<IMG align=top  border=0 src="../Images/ir.gif" style="cursor:pointer" title="Presione aqui para enviar este documento">			</a>		</td>
	</tr>
	
	<?
	$cont=$cont+1;
	}
	?>
</table>



<script languaje="javascript">
	
	function post_letra(letra)
	{
	document.form1.action = "buscacliente.php?b="+<? echo "2";?>+"&caracter="+letra;
	document.form1.submit();
	}
	function enviar(rut, suc, tot, fecha)
		{
		window.opener.document.form1.txtrut.value = rut;
		window.opener.document.form1.lstdcto.value = 61;
		window.opener.document.form1.folioref.value = suc;
		window.opener.document.form1.totref.value = tot;
		window.opener.document.form1.fecharef.value = fecha;
		window.opener.document.form1.tiporef.value = 33;
		window.opener.document.form1.activafun.click();
		window.opener.document.form1.codref.focus();
		window.close();
		}
	</script>
