<?php
session_start();
include("cls_conexion.php");
$CNN=new ClsMySQL();
include("conexion23.php");
include("phpmnu_fun.php");
//++
if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
//++
$Lot=V($_SESSION['FAC_XLM_IMP_LOT']);
$Dex=V($_SESSION['FAC_XLM_IMP_DEX']);
$Hax=V($_SESSION['FAC_XLM_IMP_HAX']);
$EmiRuc=V($_SESSION['FAC_XLM_IMP_EMI_RUC']);
$EmiNom=V($_SESSION['FAC_XLM_IMP_EMI_NOM']);
$CliRuc=V($_SESSION['FAC_XLM_IMP_CLI_RUC']);
$CliNom=V($_SESSION['FAC_XLM_IMP_CLI_NOM']);
//
if(strlen($Dex)==0)$Dex=date("d-m-Y");
if(strlen($Hax)==0)$Hax=date("d-m-Y");
//+++
$Lot_=$Lot."%";
$Dex_=ToDateEx($Dex);
$Hax_=ToDateEx($Hax);
$EmiRuc_=$EmiRuc."%";
$EmiNom_=$EmiNom."%";
$CliRuc_=$CliRuc."%";
$CliNom_=$CliNom."%";
//
$FF="id_xml>0 AND xml_nom_tmp LIKE '$Lot_' AND fec>='$Dex_' AND fec<='$Hax_' AND 
	 xml_emi_ruc LIKE '$EmiRuc_' AND xml_emi_nom LIKE '$EmiNom_' AND 
	 xml_cli_ruc LIKE '$CliRuc_' AND xml_cli_nom LIKE '$CliNom_'  ";
//
$LIS_LOT="";
$s="SELECT xml_nom_tmp as LOTE FROM ges_xml WHERE $FF GROUP BY 1 ORDER BY 1";
$rs=grs($s);
while($r=$rs->fetch_assoc()){
	$r['LOTE']=trim($r['LOTE']);
	if(strlen($r['LOTE'])>0){
		$LIS_LOT=$LIS_LOT.$r['LOTE']." , ";
	}
}
if(strlen($LIS_LOT)>0){
	$LIS_LOT=substr($LIS_LOT,0,strlen($LIS_LOT)-3);
}
//
$LIS_FEC="";
$s="SELECT fec as FECHA FROM ges_xml WHERE $FF GROUP BY 1 ORDER BY 1";
$rs=grs($s);
while($r=$rs->fetch_assoc()){
	$r['FECHA']=trim($r['FECHA']);
	if(strlen($r['FECHA'])>0){
		$LIS_FEC=$LIS_FEC.FEP($r['FECHA'])." , ";
	}
}
if(strlen($LIS_FEC)>0){
	$LIS_FEC=substr($LIS_FEC,0,strlen($LIS_FEC)-3);
}
//
if(strlen($LIS_FEC)==0)$LIS_FEC="-";
if(strlen($LIS_LOT)==0)$LIS_LOT="-";
//
/*
echo "LOTES=".$LIS_LOT."<br>";
echo "FECHAS=".$LIS_FEC."<br>";
*/
?>
<head>
<style type="text/css">
@media print {
    @page {
        size: landscape;
    }
}
#TdDatos {
    border-collapse: collapse;
    width: 100%;
}

#TdDatos th,
#TdDatos td {
    border: 1px solid #d0d0d0;
    padding: 4px 6px;
    white-space: nowrap;
}

#TdDatos th {
    background: #f3f3f3;
    font-weight: bold;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>
<body>
	<center>
    <table width="100%" border="0" style="border-collapse:collapse;  max-width:28cm; font-family:Tahoma, Geneva, sans-serif; font-size:12px">
    <tr>
    <td width="1%">&nbsp;</td>
    <td width="98%">&nbsp;</td>
    <td width="1%">&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td style="font-size:14px"><b>CONSTANCIA DE FACTURAS XMLs IMPORTADOS</b></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>
    <input name="" id="CmdPrint" type="button" value="Imprimir" onClick="fxImprimir()">
    <script>
	function fxImprimir(){
		document.getElementById("CmdPrint").style.display="none";
		window.print();
	}
	</script>
    </td>
    <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>
      
        <table width="100%" border="0" style="border-collapse:collapse; font-family:Tahoma, Geneva, sans-serif; font-size:12px">
        
        <tr>
        <td width="20%">FECHA DE IMPRESION</td>
        <td width="2%">:</td>
        <td width="78%"><?php echo date("d-m-Y");?></td>
        </tr>
        <tr>
        <td width="20%">HOR.IMPRESION</td>
        <td width="2%">:</td>
        <td width="78%"><?php echo date("h:i A");?></td>
        </tr>
        
        <tr>
        <td colspan="3">&nbsp;</td>
        </tr>
        
        <tr>
        <td colspan="3">CONTIENE LOS SIGUIENTES DATOS</td>
        </tr>
        <tr>
        <td width="20%"> LOTES</td>
        <td width="2%">:</td>
        <td width="78%"><?php echo $LIS_LOT;?></td>
        </tr>
        <tr>
        <td> FECHAS</td>
        <td>:</td>
        <td><?php echo $LIS_FEC;?></td>
        </tr>
        </table>
      
      </td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>
            <table id="TdDatos" width="100%" border="0" style="border-collapse:collapse;   font-family:Tahoma, Geneva, sans-serif; font-size:12px">
            <tr>
            <td style="white-space: nowrap;"><b>SERIE</b></td>
            <td style="white-space: nowrap;"><b>NUMERO</b></td>
            <td style="white-space: nowrap;"><b>F.EMISION</b></td>
            <td style="white-space: nowrap;"><b>RUC EMISOR</b></td>
            <td style="white-space: nowrap;"><b>NOMBRE EMISOR</b></td>
            <td style="white-space: nowrap;"><b>RUC CLIENTE</b></td>
            <td style="white-space: nowrap;"><b>NOMBRE CLIENTE</b></td>
            <td align="right"><b>TOTAL</b></td>
            </tr>
            <?php
			$s="SELECT * FROM ges_xml WHERE $FF ORDER BY id_xml";
			$rs=grs($s);
			while($r=$rs->fetch_assoc()){
			?>
            <tr>
            <td style="white-space: nowrap;"><?php echo $r['xml_ser'];?></td>
            <td style="white-space: nowrap;"><?php echo $r['xml_num'];?></td>
            <td style="white-space: nowrap;"><?php echo FEP($r['xml_fec']);?></td>
            <td style="white-space: nowrap;"><?php echo $r['xml_emi_ruc'];?></td>
            <td style="white-space: nowrap;"><?php echo $r['xml_emi_nom'];?></td>            
            <td style="white-space: nowrap;"><?php echo $r['xml_cli_ruc'];?></td>
            <td style="white-space: nowrap;"><?php echo $r['xml_cli_nom'];?></td>
            <td align="right"><?php echo NF2($r['xml_tot'],2);?></td>
            </tr>
            <?php
			}
			?>
            </table>
      
      </td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    </table>
	</center>
</body>
</html>