<?php
$StrCmd=V($_POST['TxtAc']);
//-------------------------++++
$EmiRuc=V($_POST['EmiRuc']);			
$EmiNom=V($_POST['EmiNom']);		
$FacSer=V($_POST['FacSer']);		
$FacNum=V($_POST['FacNum']);		
$Dex=V($_POST['Dex']);
$Hax=V($_POST['Hax']);
$CliRuc=V($_POST['CliRuc']);
$CliNom=V($_POST['CliNom']);
$CuoFecVenDex=V($_POST['CuoFecVenDex']);
$CuoFecVenHax=V($_POST['CuoFecVenHax']);
$CuoPro=V($_POST['CuoPro']);
$CuoProDex=V($_POST['CuoProDex']);
$CuoProHax=V($_POST['CuoProHax']);
$CuoPag=V($_POST['CuoPag']);
$PagFecDes=V($_POST['PagFecDes']);
$PagFecHas=V($_POST['PagFecHas']);
$PagNroOpe=V($_POST['PagNroOpe']);
//+++
if(strlen($CuoPro)==0)$CuoPro="TODOS";
if(strlen($CuoPag)==0)$CuoPag="TODOS";
//+++
$EmiRuc_=$EmiRuc."%";
$EmiNom_=$EmiNom."%";
$FacSer_=$FacSer."%";
$FacNum_="%".$FacNum;
$Dex_=Xmldex_($Dex);
$Hax_=Xmlhax_($Hax);
$CliRuc_=$CliRuc."%";
$CliNom_=$CliNom."%";
$CuoFecVenDex_=Xmldex_($CuoFecVenDex);
$CuoFecVenHax_=Xmlhax_($CuoFecVenHax);
$CuoPag_=LIKE($CuoPag);
$PagNroOpe_=$PagNroOpe."%";
//
$FF="ID_XML>0 AND 
	 EMI_RUC LIKE '$EmiRuc_' AND EMI_NOM LIKE '$EmiNom_' AND 
	 SER LIKE '$FacSer_' AND NUM LIKE '$FacNum_' AND 
	 FEC>='$Dex_' AND FEC<='$Hax_' AND 
	 CLI_RUC LIKE '$CliRuc_' AND CLI_NOM LIKE '$CliNom_' AND 
	 C_FEC>='$CuoFecVenDex_' AND C_FEC<='$CuoFecVenHax_' AND 
	 CUO_PAG_NRO_OPE LIKE '$PagNroOpe_' ";
//
if($CuoPro=="TODOS"){
	if(strlen($CuoProDex)==0 && strlen($CuoProHax)==0){
		$FF=$FF;
	}
	if(strlen($CuoProDex)>0 && strlen($CuoProHax)==0){
		$FF=$FF." AND ( FEP='1900-01-01' OR FEP>='".ToDateEx($CuoProDex)."' )";
	}
	if(strlen($CuoProDex)==0 && strlen($CuoProHax)>0){
		$FF=$FF." AND ( FEP='1900-01-01' OR FEP<='".ToDateEx($CuoProHax)."' )";
	}
	if(strlen($CuoProDex)>0 && strlen($CuoProHax)>0){
		$FF=$FF." AND ( FEP='1900-01-01' OR ( FEP>='".ToDateEx($CuoProDex)."' AND FEP<='".ToDateEx($CuoProHax)."') )";
	}
}else{
	if($CuoPro=="NO"){
		$FF=$FF." AND FEP='1900-01-01' ";
	}else{
		if($CuoPro=="SI"){
			$FF=$FF." AND FEP<>'1900-01-01' ";
			if(strlen($CuoProDex)>0){
				$FF=$FF." AND FEP>='".ToDateEx($CuoProDex)."' ";
			}
			if(strlen($CuoProHax)>0){
				$FF=$FF." AND FEP<='".ToDateEx($CuoProHax)."' ";
			}
		}
	}
}
//
if($CuoPag=="TODOS"){
	if(strlen($PagFecDes)==0 && strlen($PagFecHas)==0){
		$FF=$FF;
	}
	if(strlen($PagFecDes)>0 && strlen($PagFecHas)==0){
		$FF=$FF." AND ( CUO_PAG_TOT>=0 OR C_PAG_FEC>='".ToDateEx($CuoProDex)."' )";
	}
	if(strlen($PagFecDes)==0 && strlen($PagFecHas)>0){
		$FF=$FF." AND ( CUO_PAG_TOT>=0 OR C_PAG_FEC<='".ToDateEx($CuoProHax)."' )";
	}
	if(strlen($PagFecDes)>0 && strlen($PagFecHas)>0){
		$FF=$FF." AND ( CUO_PAG_TOT>=0 OR ( C_PAG_FEC>='".ToDateEx($CuoProDex)."' AND C_PAG_FEC<='".ToDateEx($CuoProHax)."') )";
	}
}else{
	if($CuoPag=="NO"){
		$FF=$FF." AND CUO_PAG_TOT=0 ";
	}else{
		if($CuoPag=="SI"){
			$FF=$FF." AND CUO_PAG_TOT>0 ";
			if(strlen($PagFecDes)>0){
				$FF=$FF." AND C_PAG_FEC>='".ToDateEx($PagFecDes)."' ";
			}
			if(strlen($PagFecHas)>0){
				$FF=$FF." AND C_PAG_FEC<='".ToDateEx($PagFecHas)."' ";
			}
		}
	}
}
//++
$LStrTR=gn("count(*)","vis_ges_xml_cuo",$FF);
$LStrPag=V($_POST['TxtPag']);
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=19;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
?>