<?php
if(isset($_POST["bexp"])) {	
	$varFIni = ($_POST["eini"]=="") ? "NULL" : "'".FechaMySql($_POST["eini"])."'";
	$varFFin = ($_POST["efin"]=="") ? "NULL" : "'".FechaMySql($_POST["efin"])."'";
	$varRuta = ($_POST["rcod"]=="") ? "NULL" : $_POST["rcod"];
	$varCana = ($_POST["tcod"]=="") ? "NULL" : $_POST["tcod"];
	$varVend = ($_POST["vcod"]=="") ? "NULL" : $_POST["vcod"];			
	$varLine = ($_POST["pcod"]=="") ? "NULL" : $_POST["pcod"];			

	$sql = "call spQuery_Cobertura_Linea($varCana, $varFIni, $varFFin);";
	$varCab = array(array("cab"=>"DETALLE", 
						  "det"=>array("COBER","IMPOR"))
					);
	$varNiv = array(0=>array("COD"=>"CRUT","DES"=>"RUTA"),
					1=>array("COD"=>"CVEN","DES"=>"VENDEDOR"),
					2=>array("COD"=>"CPRO" ,"DES"=>"PROVEEDOR"));
	$_SESSION["_varNiv"] = $varNiv;
	$_SESSION["_varPag"] = $_POST[titu];
	$_SESSION["_varCab"] = $varCab;
	$_SESSION["_varSql"] = $sql;
	$dir = "export_grid_combinado.php";
	header("location: $dir");

	}
require_once('clases/xajax/xajax_core/xajax.inc.php');
$xajax = new xajax();
//$xajax->setFlag('debug',true); 
$xajax->configure('javascript URI', 'clases/xajax/');

$xajax->register(XAJAX_FUNCTION, 'seleccionar_proveedor');
$xajax->register(XAJAX_FUNCTION, 'seleccionar_tipo_vendedor');
$xajax->register(XAJAX_FUNCTION, 'seleccionar_vendedor');
$xajax->processRequest();
$xajax->printJavascript("clases/xajax");
		
function MyTable($obj, $titulo, $Opcion, $Valor) {
	$Link = $_SERVER['PHP_SELF'];
	$varFINI = (isset($_POST["eini"]))?$_POST["eini"]:NULL;
	$varFFIN = (isset($_POST["efin"]))?$_POST["efin"]:NULL;
	$vartcod = (isset($_POST["tcod"]))?$_POST["tcod"]:NULL;
	$vartnom = (isset($_POST["tnom"]))?$_POST["tnom"]:NULL;
	$varVCOD = (isset($_POST["vcod"]))?$_POST["vcod"]:NULL;
	$varVNOM = (isset($_POST["vnom"]))?$_POST["vnom"]:NULL;
	?>
	<script language="javascript">
	function valida(e){
		tecla=(document.all) ? e.keyCode : e.which;
		if(tecla == 13)
		document.form.cond.focus();
		}
		
	function pulsar(e, a) {
		tecla=(document.all) ? e.keyCode : e.which;
		var Campo = a.name;		
			
		if(tecla==13) {
			if(Campo == "tcod") {
				cargar("U","C",a.value,document.form.emp.value);
				document.form.cond.focus();
				}
			if(Campo.indexOf("acod")==0) {
				msj_articulo = "NO PRESIONES ENTER\n";
				}
			}
		return(tecla!=13);
	//	document.form.cond.focus();
		}
	
	function select_Cliente(tcod, tnom) {		
		var tcod1 = document.getElementById(tcod);
		var tnom1 = document.getElementById(tnom);
		if(tcod1.value=="") {
			tcod1.value = "";
			tnom1.value = "";
			}
		else {			
			var dato = koolajax.callback(seleccionaCliente(tcod1.value));
			if(dato=="NO EXISTE") {
	//			alert("CLIENTE NO EXISTE");
				tcod1.value = "";
				tnom1.value = dato;
				tcod1.focus();
				}
			else {
				tnom1.value = dato;
				}
			}
		}
	
	function select_Vendedor(vcod, vnom) {		
		var vcod1 = document.getElementById(vcod);
		var vnom1 = document.getElementById(vnom);
		if(vcod1.value=="") {
			vcod1.value = "";
			vnom1.value = "";
			}
		else {			
			var dato = koolajax.callback(seleccionaVendedor(vcod1.value));
			if(dato=="NO EXISTE") {
	//			alert("CLIENTE NO EXISTE");
				vcod1.value = "";
				vnom1.value = dato;
				vcod1.focus();
				}
			else {
				vnom1.value = dato;
				}
			}
		}
</script>
	<?php
	if(!isset($Opcion)) {
		
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"420", "clase"=>"Formtitulo", "titulo"=>$titulo." - BUSQUEDA",
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$titulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$Opcion)
									  ),
						"conte"=>array(array("titulo"=>"Canal :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"tcod", "name"=>"tcod", "valor"=>$_POST["tcod"],
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_tipo_vendedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_tipo_vendedor('tcod', 'tnom')"),
																			   array("tipo"=>"text", "id"=>"tnom", "name"=>"tnom", "valor"=>$_POST["tnom"], 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),/*
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"vcod", "name"=>"vcod", "valor"=>$_POST["vcod"],
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_vendedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_vendedor('vcod', 'vnom')"),
																			   array("tipo"=>"text", "id"=>"vnom", "name"=>"vnom", "valor"=>$_POST["vnom"], 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Proveedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"pcod", "name"=>"pcod", "valor"=>$_POST["pcod"],
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_proveedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_proveedor('pcod', 'pnom')"),
																			   array("tipo"=>"text", "id"=>"pnom", "name"=>"pnom", "valor"=>$_POST["pnom"], 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),	*/								  
									   array("titulo"=>"Fecha Incial :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"fecha", "id"=>"eini", "name"=>"eini", "alinear"=>"center","valor"=>$varFINI) ),
									   array("titulo"=>"Fecha Final :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"fecha", "id"=>"efin", "name"=>"efin", "alinear"=>"center", "valor"=>$varFFIN) )									   
									   ),
						"boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"80", "alto"=>"22", "texto"=>"Consultar"),			  
									   array("tipo"=>"submit", "id"=>"bexp", "name"=>"bexp", "ancho"=>"80", "alto"=>"22", "texto"=>"Exportar")										
									   )
						);
		echo $obj->setTablaForm($varTabla);	
		if(isset($_POST["bcon"])) {		
			$varFIni = ($_POST["eini"]=="") ? "NULL" : "'".FechaMySql($_POST["eini"])."'";
			$varFFin = ($_POST["efin"]=="") ? "NULL" : "'".FechaMySql($_POST["efin"])."'";
			$varRuta = ($_POST["rcod"]=="") ? "NULL" : $_POST["rcod"];
			$varCana = ($_POST["tcod"]=="") ? "NULL" : $_POST["tcod"];
			$varVend = ($_POST["vcod"]=="") ? "NULL" : $_POST["vcod"];			
			$varLine = ($_POST["pcod"]=="") ? "NULL" : $_POST["pcod"];			
	
			$sql = "call spQuery_Cobertura_Linea($varCana, $varFIni, $varFFin);";
			$varCab = array(array("cab"=>"DETALLE", 
								  "det"=>array("COBER","IMPOR"))
							);
			$varNiv = array(0=>array("COD"=>"CRUT","DES"=>"RUTA"),
							1=>array("COD"=>"CVEN","DES"=>"VENDEDOR"),
							2=>array("COD"=>"CPRO" ,"DES"=>"PROVEEDOR"));			
			echo $obj->setGridCombina($varCab, $sql, $varNiv);
			echo "<br>";
			}
		}
	} 
?>