<?
session_name('portal_absa');
session_start();
if(!isset($_SESSION['usuario_p_prov_absa']) || trim($_SESSION['usuario_p_prov_absa']) == "" || trim(strtoupper($_SESSION["URL_PORTAL"]."admin.php")) != trim(strtoupper($_SERVER['HTTP_REFERER']))){
	?><script>window.location.href="<?=$_SESSION["URL_PORTAL"]."index.php"?>"</script><?
	exit;
}
require_once "../conexion/conectar.php";
require "../libs/funciones.php";

$conexion = new CONDB();
$conexion->conectar();

$rfc=$_REQUEST['id'];
$tipodocto=$_REQUEST['id2'];
$serie=$_REQUEST['id3'];
$folio=$_REQUEST['id4'];
$uuid=$_REQUEST['id5'];

$completaQuery="";

if(trim($_REQUEST['id3']) != "")
	$completaQuery.=" and serie='$serie'";
if(trim($_REQUEST['id4']) != "")
	$completaQuery.=" and folio='$folio'";
if(trim($_REQUEST['id5']) != "")
	$completaQuery.=" and uuid='$uuid'";

$query="select id,concepto_pago,fecha_pago,referencia,monto from pago_doc_detalle where rfcemisor='$rfc' and tipodocto='$tipodocto' $completaQuery";
$result = mysqli_query($conexion->CONEXION,$query);

$query="select id,total from recibedoce where rfcemisor='$rfc' and tipodocto='$tipodocto' and serie='$serie' and folio='$folio' and uuid='$uuid' limit 1";
$rDoc = mysqli_query($conexion->CONEXION,$query);
if(mysqli_num_rows($rDoc) > 0){
	$tDoc = mysqli_fetch_array($rDoc,MYSQLI_ASSOC);
}


$body='
<table>
	<tr>
		<th align="left">RFC:</th>
		<td>'.$rfc.'</td>
		<th>Serie:</th>
		<td>'.$serie.'</td>
		<th>Folio:</th>
		<td>'.$folio.'</td>
	</tr>
	<tr>
		<th align="left">UUID:</th>
		<td colspan="3">'.$uuid.'</td>
		<th>No. Interno:</th>
		<td>'.$tDoc['id'].'</td>
	</tr>
	<tr>
		<th align="left">Total factura:</th>
		<td colspan="5">'.$tDoc['total'].'</td>
	</tr>
</table>';

$body.='<table class="td_general">
	<tr style="background-color: #999999">
		<th width="150">Referencia</th>
		<th width="200">Concepto</th>
		<th width="150">Fecha de pago</th>
		<th width="150">Monto</th>
	</tr>';


if(mysqli_num_rows($result) > 0){
	$total=0;
	while($temp=mysqli_fetch_array($result,MYSQLI_ASSOC)){
		$total+=$temp['monto'];
		$body.='
	<tr>
		<td>'.$temp['referencia'].'</td>
		<td>'.$temp['concepto_pago'].'</td>
		<td>'.$temp['fecha_pago'].'</td>
		<td align="right">'.$temp['monto'].'</td>
	</tr>';
	}
}


	$body.='<tr>
		<td style="border-top: 1px solid; padding: 10px 10px 10px 10px" align="right" colspan="3">Total</td>
		<th style="border-top: 1px solid; padding: 10px 10px 10px 10px" align="right" >'.$total.'</th>
	</tr>
</table>';

echo $body;

?>
<script>
function enviaAcuse(){
	$j_6.messager.prompt("Enviar","Indique el correo a enviar.",function(r){
		if(r){
			$j_6.post("formularios/extras/envia_acuse_pago.php",{id: '<?=$_REQUEST['id']?>', id2: '<?=$_REQUEST['id2']?>', id3: '<?=$_REQUEST['id3']?>', id4: '<?=$_REQUEST['id4']?>', id5: '<?=$_REQUEST['id5']?>', correo: r},function(data){
				$j_6("#result").html(data);
			});
		}
	});
}

</script>
<a href="javascript: enviaAcuse();" style="cursor: pointer">Enviar por correo.</a>