<?php
include('php_gene1.php');

$xempr=$_GET['empr'];
$xdocu=$_GET['docu'];
$xptoe=$_GET['ptoe'];
$xnume=$_GET['nume'];

$xdocu=substr($xdocu,0,1);
if($xptoe==''){$xptoe='001001';}
$xptoe=str_pad($xptoe,6,'0',STR_PAD_LEFT);
$xnume=str_pad($xnume,9,'0',STR_PAD_LEFT);

{
	chdir('../'.$xempr.'/_lib');
	include('../_cfg/config.php');
  $tabla='vtas1';
  if(substr($xdocu,0,1)=='R'){$tabla='retp1';}
  if(substr($xdocu,0,1)=='G'){$tabla='guia1';}
  
	$sql_clave ='select * from '.$tabla;
	$sql_clave.=' where status!="O" ';
	$sql_clave.=' and status!="X" ';
	$sql_clave.=' and docu like "'.$xdocu.'%" ';
	$sql_clave.=' and ptoe="'.$xptoe.'" ';
	$sql_clave.=' and numero="'.$xnume.'" ';
	$sql_clave.=' order by idnum1 desc';
	$res_clave=mysql_query($sql_clave,$link_vcrx);
  $clave=mysql_result($res_clave,0,'claveacc');
//   explain_sql($sql_clave);
//   echo $xempr;
//   echo $sql_clave;
  echo $clave;
  
}	


?>