<?
session_name('portal_absa');
session_start();
require "../conexion/conectar.php";
$conexion = new CONDB();
$conexion->conectar();

$qRDoce="select rfcemisor,tipodocto,serie,folio,uuid,fechadocto from recibedoce where uuid='".$_REQUEST["uuidIngreso"]."'";
if(!$rRDoce = mysqli_query($conexion->CONEXION,$qRDoce)){
	?><script>$j_6.messager.alert("Error","Ocurrio un error al consultar el documento de pago.","error");</script><?exit;
}

if(mysqli_num_rows($rRDoce) <= 0){

	?><script>$j_6.messager.alert("Error","No se encontro el documento.","error");</script><?exit;
}

$tRDoce = mysqli_fetch_assoc($rRDoce);

$completaQuery = "";
if($_REQUEST["sinserie_check"] != "1"){
	if(trim($_REQUEST["serie"]) != ""){$completaQuery.="and serie='".trim($_REQUEST["serie"])."'";}
}else{
	$completaQuery.="and serie=''";
}
if(trim($_REQUEST["folioI"]) != ""){$completaQuery.="and folio >= '".trim($_REQUEST["folioI"])."'";}
if(trim($_REQUEST["folioF"]) != ""){$completaQuery.="and folio <= '".trim($_REQUEST["folioF"])."'";}
if(trim($_REQUEST["fechaI"]) != ""){$completaQuery.="and fechadocto >= '".$_REQUEST["fechaI"]."'";}
if(trim($_REQUEST["fechaF"]) != ""){$completaQuery.="and fechadocto <= '".$_REQUEST["fechaF"]."'";}
if(trim($_REQUEST["uuid"]) != ""){$completaQuery.="and uuid = '".$_REQUEST["uuid"]."'";}

$queryRDocs="select rfcemisor,tipodocto,uuid,serie,folio,total,fechadocto from recibedoce where status='A' and rfcemisor='".$tRDoce["rfcemisor"]."' and tipodocto='E CFDI 3.3' $completaQuery";

if(!$resultD = mysqli_query($conexion->CONEXION,$queryRDocs)){
	?><script>$j_6.messager.alert("Error","Ocurrio un error al consultar los documentos.","error");</script><?exit;
}

?>
<script language="javascript" src="../libs/js/funciones.js"></script>
<script>
function relacionarDocumento(uuid){
	$j_6.post("formularios/extras/relacionarIngreso.php",{uuidEgreso: uuid,uuidIngreso: '<?=$_REQUEST['uuidIngreso']?>'},function(data){
		$j_6("#result").html(data);
	});
		
}
</script>
<table width="98%">
	<tr style="background-color: #000000; color: #FFFFFF">
		<td></td>
		<td>Emisor</td>
		<td>Tipo Documento</td>
		<td>Serie</td>
		<td>Folio</td>
		<td>UUID</td>
		<td>Fecha</td>
		<td>Total</td>
	</tr>
<?if(mysqli_num_rows($resultD) > 0){
$con=0;
	
	while($tmp = mysqli_fetch_array($resultD,MYSQLI_ASSOC)){
	$con++;
	$res = $con%2;
	$trEstilo="";
	if($res == 0)
		$trEstilo = "style='background-color: #999999'";
?>
	<tr <?=$trEstilo?>>
		<td>
			<img onclick="relacionarDocumento('<?=$tmp['uuid']?>')" src="Imagenes/addDoc.png" style="cursor:pointer" width="32" height="32" />
		</td>
		<td><?=$tmp['rfcemisor']?></td>
		<td><?=$tmp['tipodocto']?></td>
		<td><?=$tmp['serie']?></td>
		<td><?=$tmp['folio']?></td>
		<td><?=$tmp['uuid']?></td>
		<td><?=$tmp['fechadocto']?></td>
		<td><?=$tmp['total']?></td>
	</tr>
<?}}?>
</table>

