<?php
session_start();
	 include "prph/coneccionfe.php";
	 
	$vusuario= trim($_POST['usuario']);
	
	$fechaini= trim($_POST['dfecha_ini']);
	$fechafin= trim($_POST['dfecha_fin']);
	
	
	

	$caccesogral = "1";	
	$link = pg_connect("host=$dbhost port=$dbport user=$dbuser password=$dbpwd dbname=$dbname")or die(pg_last_error($link));
	
	$sql = "set search_path to 'SHFE'; select a.rucreceptor, a.rznsocreceptor, b.id_febinario_tc, a.tipodoc, a.serie, a.correlativo,
    to_char(to_date(a.fechemision  , 'YYYY-MM-dd'),'dd/MM/YYYY') fechemision, coalesce(b.filearchivoxml,'-1') as filearchivoxml,
    coalesce(b.filecdrxml,'-1') as filecdrxml,a.rucemisor, a.stat_firmado, a.stat_cdr, a.stat_enviado,  rucemisor as cnit, 
	substring(nombre_txt,1,length(trim(nombre_txt))-4) as filetxt, a.stat_zdo from fa_faele_tc a
    inner join fa_febinario_tc b on a.tipodoc = b.tipodoc and a.serie = b.serie and a.correlativo = b.correlativo
    where a.stat_firmado = 'S' and  a.rucreceptor = '$vusuario' and
    to_date(to_char(to_date(a.fechemision  , 'YYYY-MM-dd'),'dd/MM/YYYY'),'dd/MM/YYYY') between '$fechaini' and '$fechafin';";   
 
	//echo $sql ;
	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es">
<head>
<title>FACTURACION ELECTRONICA</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="screen" href="css/main.css" />
<link rel="stylesheet" href="css/w3.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>

<div   style="height:60%;overflow:auto;width:100%;padding-left:0px;margin-left:0px;margin-top:3px;" >
<div class ="contenedor">

	<div style="width:8px;float:left"><input type="hidden"  id="id_fecha_envio"  value="<?php echo $fechaini; ?>"/></div>
	
	
	<div id="files">
		<table class="table table-hover">  
		<tr style="font-size: 11;background: #536f82;">
		    
			<th style="font-size: 11;background: #536f82;width:20px;">RUC</th>
			<th style="font-size: 11;background: #536f82;">Nombre o Raz&oacute;n social</th>
			<th style="font-size: 11;background: #536f82;width:15px;">Tipo</th>
			<th style="font-size: 11;background: #536f82;">Serie</th>
			<th style="font-size: 11;background: #536f82;">Numero</th>
			<th style="font-size: 11;background: #536f82;width:25px;">F.Emision</th>	
			<th style="font-size: 11;background: #536f82;" id="thdes">Descargar</th>
			<th style="font-size: 11;background: #536f82;width:10px;">Firmado</th>
			<th style="font-size: 11;background: #536f82;width:10px;">Envio</th>
			<th style="font-size: 11;background: #536f82;width:5px;">R</th>
		</tr>
		
		<?php
		$result = pg_query($link, $sql);
		
		if($result)
		{
			while ($row=pg_fetch_array($result))
			{
				echo "<tr>";
				
				$cnit = $row["cnit"];
				$filetxt = $row["filetxt"];
								
				$cdr = trim($row["stat_cdr"]);
				$envio = trim($row["stat_enviado"]);
				$firmado  = trim($row["stat_firmado"]);
								
				//$envio = ($envio == "S" ? "✓":"✕");
				$firmado = ($firmado == "S" ? "&#10004":"&#10006");
				$envio = ($envio == "S" ? "&#10004":"&#10006");
				
				$imgsend = ($envio == "S" ? "send.png":"send.png");
				
				
				
				$imgcdr = ($cdr == "S" ? "cdr2.png":"nofile.png");
				echo "<td>" .$row["rucreceptor"]. "</td>" ;
				echo "<td>" .$row["rznsocreceptor"]. "</td>" ;
				echo "<td>" .$row["tipodoc"]. "</td>" ;
				echo "<td>" .$row["serie"]. "</td>" ;
				echo "<td>" .$row["correlativo"]. "</td>" ;
				echo "<td>" .$row["fechemision"]. "</td>" ;
				echo "<td ><div style='width:100px;'>
				<a  href=\"prph/gs_download.php?id=$row[id_febinario_tc]\" title=\"Descargar Archivo XML\">
				<img src=\"img/xml1.png\" width=21 height=22 ></a>
				<a   href=\"prph/fe$row[rucemisor].php?id=$row[id_febinario_tc]\" title=\"Descargar  PDF\">
				<img src=\"img/pdf1.png\" width=21 height=22></a> 
				<a   href=\"prph/gs_downloadcdr.php?id=$row[id_febinario_tc]\" title=\"Descargar Archivo CDR\">
				<img src=\"img/$imgcdr\" width=21 height=22></a>
				</div></td>";
				echo "<td style='font-weight: bold;font-size:16px;' >" .$firmado. "</td>" ;
				echo "<td style='font-weight: bold;font-size:16px;' >" .$envio. "</td>" ;
				echo "<td style='font-weight: bold;font-size:14px;' >" .$row["stat_zdo"]. "</td>" ;
				
				echo "</tr>\n";
				
				
			} 
		}
		pg_free_result($result);	
		pg_close($link);
		?>
		
		</table>
	</div>
	
	
	<div id="pie">
		Derechos Reservados 
	</div>
</div>

<div id="loadingadmfe" style="width:100%;float:left;text-align:center;display:none;" >
	<div style="float:center;">
		<img src="img/loading.gif" width=75 height=70 >
	</div>
</div>
	
</div> 
			
</body>
</html>
 
