<?php
if(isset($_POST["bexp"])) {			
	$varFIni = (isset($_POST["fini"]))?FechaMySql($_POST["fini"]):NULL;
	$varFFin = (isset($_POST["ffin"]))?FechaMySql($_POST["ffin"]):NULL;
	
	$sql = "call spQuery_Avance_Rebotes_Vendedor('$varFIni','$varFFin','$_POST[vcod]', '$_POST[ccod]')";
	$_SESSION[expor_sql_1] =  $sql;
	$_SESSION[expor_sql_2] = NULL;
	$varTitulo = (isset($_POST["titu"]))?$_POST["titu"]:"Reporte";
	$dir = "export.php?page=$varTitulo";
	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_cliente');
$xajax->register(XAJAX_FUNCTION, 'seleccionar_vendedor');
$xajax->processRequest();
$xajax->printJavascript("clases/xajax");

function MyTable($obj, $titulo, $Opcion, $Valor) {
	$Link = $_SERVER['PHP_SELF'];
	if(!isset($Opcion)) {		
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"420", "clase"=>"Formtitulo", "titulo"=>$titulo,
						"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"=>"Fecha Inicio :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"fecha", "id"=>"fini", "name"=>"fini", "alinear"=>"center",
											 				"valor"=>$_POST["fini"]) 
											 ),
									   array("titulo"=>"Fecha Final	 :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"fecha", "id"=>"ffin", "name"=>"ffin", "alinear"=>"center",
											 				"valor"=>$_POST["ffin"]) 
											 ),
									   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"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ccod", "name"=>"ccod", "valor"=>$_POST["ccod"],
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_cliente(this.value)", 
																					 "dclick"=>"fn_cargar_listado_cliente('vcod', 'vnom')"),
																			   array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom", "valor"=>$_POST["cnom"], 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 )
									   ),
						"boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"80", "alto"=>"22", "texto"=>"Consultar"),
									   array("tipo"=>"button", "id"=>"bimp", "name"=>"bimp", "ancho"=>"80", "alto"=>"22", "texto"=>"Imprimir",
									   		 "click"=>"fn_print_rechazo_ventas_cliente(form.fini.value, form.ffin.value, form.vcod.value, form.ccod.value)"),
									   array("tipo"=>"submit", "id"=>"bexp", "name"=>"bexp", "ancho"=>"80", "alto"=>"22", "texto"=>"Exportar")					
									   )
						);
		echo $obj->setTablaForm($varTabla);	
		if(isset($_POST["bcon"])) {
			$varFIni = (isset($_POST["fini"]))?FechaMySql($_POST["fini"]):NULL;
			$varFFin = (isset($_POST["ffin"]))?FechaMySql($_POST["ffin"]):NULL;
			
			$sql = "call spQuery_Avance_Rebotes_Vendedor('$varFIni','$varFFin','$_POST[vcod]', '$_POST[ccod]')";
			$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"1200", "sql_cab"=>$sql,	"pages"=>100,
							"conte"=>array(array("titulo"=>"FEMI",    	"ancho"=>"20",  "alinear"=>"center", "clase"=>"sortable-date"),
										   array("titulo"=>"PEDIDO",    "ancho"=>"20",  "alinear"=>"center", "oculto"=>"SI"),
										   array("titulo"=>"CTIP",    	"ancho"=>"20",  "alinear"=>"center"),
										   array("titulo"=>"NDOC",    	"ancho"=>"20",  "alinear"=>"center"),
										   array("titulo"=>"CVEN",    	"ancho"=>"20",  "alinear"=>"center", "clase"=>"sortable-numeric"),
										   array("titulo"=>"VENDEDOR", 	"ancho"=>"200", "clase"  =>"sortable", "fijo"=>"SI"),
										   array("titulo"=>"CCLI",      "ancho"=>"40" , "alinear"=>"center", "clase"=>"sortable-numeric"), 
										   array("titulo"=>"CLIENTE",  	"ancho"=>"200", "clase"  =>"sortable", "funcion"=>array("contar")),
										   array("titulo"=>"CRUT",    	"ancho"=>"20",  "alinear"=>"center", "oculto"=>"SI"),
										   array("titulo"=>"RUTA",  	"ancho"=>"100", "clase"  =>"sortable"),
										   array("titulo"=>"TIPO RECHAZO","ancho"=>"20",  "alinear"=>"center"),
										   array("titulo"=>"CMOV",       "ancho"=>"40" , "alinear"=>"center", "clase"=>"sortable-numeric"), 
										   array("titulo"=>"MOTIVO",  	 "ancho"=>"200", "clase"  =>"sortable"),	
										   array("titulo"=>"TOTAL GRL.", "ancho"=>"60",  "alinear"=>"right", "clase"=>"sortable-numeric", "autosuma"=>"SI"),
										   array("titulo"=>"RECHAZO", 	 "ancho"=>"60",  "alinear"=>"right", "clase"=>"sortable-numeric", "autosuma"=>"SI"),
										   array("titulo"=>"EFECTIVO", 	 "ancho"=>"60",  "alinear"=>"right", "clase"=>"sortable-numeric", "autosuma"=>"SI")
										   )
							);
			echo $obj->SetGridTabla($varTabla);				}
		}
	} 
?>