<?
$qDoce="select rfcreceptor,tipodocto,serie,folio,adicionalA as uuid from doce where adicionalA='".$_REQUEST["uuid"]."'";
if(!$rDoce = mysqli_query($conexion->CONEXION,$qDoce)){
	?><script>$j_7.messager.alert("Error","Ocurrio un error al consultar el documento de pago.","error");</script><?exit;
}

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

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

$tDoce = mysqli_fetch_assoc($rDoce);

$queryDocs="select rd.rfcemisor,rd.tipodocto,rd.uuid,rd.serie,rd.folio,rd.uuid,rd.fechadocto,rdp.monedap,
rdp.tipocambiop,rdp.monto,rdp.recibedoce_pagos_ID,rdp.fechapago,rdp.formadepago
from recibedoce_pagos_docto_relacionado rdpdr inner join recibedoce_pagos rdp 
ON rdpdr.recibedoce_pagos_ID=rdp.recibedoce_pagos_ID inner join recibedoce rd ON rdp.recibedoce_uuid=rd.uuid 
where rd.rfcemisor='".$tDoce["rfcreceptor"]."' and (rdpdr.doce_uuid='' or rdpdr.doce_uuid is null) and rd.status <> 'C' group by rdp.recibedoce_pagos_ID,rd.uuid";

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

?>
<script language="javascript" src="../libs/js/funciones.js"></script>

<script>
function expandCollapse(elemento){
	if(elemento.src.indexOf("expand.png") != -1){
		elemento.src="../Imagenes/collapse.png";
		$j_7("#div_pago_"+elemento.id.replace("img_pago_","")).show();
	}else{
		elemento.src="../Imagenes/expand.png";
		$j_7("#div_pago_"+elemento.id.replace("img_pago_","")).hide();
	}
}
</script>

<table width="98%">
	<tr style="background-color: #000000; color: #FFFFFF">
		<td></td>
		<td></td>
		<td>Proveedor</td>
		<td>Serie</td>
		<td>Folio</td>
		<td>UUID</td>
		<td>Fecha de Pago</td>
		<td>Moneda</td>
		<td>Tipo Cambio</td>
		<td>Monto</td>
		<td>Forma de Pago</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 id="img_pago_<?=$tmp["recibedoce_pagos_ID"]?>" onclick="expandCollapse(this)" src="../Imagenes/expand.png" style="cursor:pointer" width="32" height="32" />
		</td>
		<td>
			<img onclick="agregarPCFDI(<?=$tmp["recibedoce_pagos_ID"]?>)" src="../Imagenes/addDoc.png" style="cursor:pointer" width="32" height="32" />
		</td>
		<td><?=$tmp['rfcemisor']?></td>
		<td><?=$tmp['serie']?></td>
		<td><?=$tmp['folio']?></td>
		<td><?=$tmp['uuid']?></td>
		<td><?=$tmp['fechapago']?></td>
		<td><?=$tmp['monedap']?></td>
		<td><?=$tmp['tipocambiop']?></td>
		<td><?=$tmp['monto']?></td>
		<td><?=$tmp['formadepago']?></td>
	</tr>
	<?
		$queryCFDIRelacionados="select rd.rfcemisor,rd.tipodocto,rd.uuid,rd.serie,rd.folio,rd.fechadocto,rdpdr.monedadr,rdpdr.tipocambiodr,rdpdr.imppagado,rdpdr.numparcialidad
		from recibedoce_pagos_docto_relacionado rdpdr inner join recibedoce rd ON rdpdr.uuidcfdirelacionado=rd.uuid
		where rdpdr.recibedoce_pagos_ID=".$tmp["recibedoce_pagos_ID"];
	if(!$rCFDIRel = mysqli_query($conexion->CONEXION,$queryCFDIRelacionados)){
		?><script>$j_7.messager.alert("Error","Ocurrio un error al consultar los documentos recibidos.","error");</script><?exit;
	}
	if(mysqli_num_rows($rCFDIRel) <= 0){
		continue;
	}?>
		<tr>
			<td colspan="10" style="padding-left: 50px">
				<div style="display: none" id="div_pago_<?=$tmp["recibedoce_pagos_ID"]?>">
				<table>
					<tr style="background-color: #000000; color: #FFFFFF">
						<td>Serie</td>
						<td>Folio</td>
						<td>UUID</td>
						<td>Fecha</td>
						<td>Moneda</td>
						<td>Tipo Cambio</td>
						<td>Monto</td>
						<td>Parcialidad</td>
					</tr>
	<?$con2=0;while($tCFDI = mysqli_fetch_array($rCFDIRel,MYSQLI_ASSOC)){
		$con2++;
		$res2 = $con2%2;
		$trEstilo2="";
		if($res2 == 0)
			$trEstilo2 = "style='background-color: #999999'";
		?>
					<tr <?=$trEstilo2?>>
						<td><?=$tCFDI["serie"]?></td>
						<td><?=$tCFDI["folio"]?></td>
						<td><?=$tCFDI["uuid"]?></td>
						<td><?=$tCFDI["fechadocto"]?></td>
						<td><?=$tCFDI["monedadr"]?></td>
						<td><?=$tCFDI["tipocambiodr"]?></td>
						<td><?=$tCFDI["imppagado"]?></td>
						<td><?=$tCFDI["numparcialidad"]?></td>
					</tr>
	<?}?>
				</table>
				</div>
			</td>
		</tr>
<?}}?>
</table>

<div id="resultD" style="display: none;"></div>

