<?php
if(isset($_POST["bexp"])) {	
	$varFIni = ($_POST["fini"]=="") ? "NULL" : "'".FechaMySql($_POST["fini"])."'";
	$varFFin = ($_POST["ffin"]=="") ? "NULL" : "'".FechaMySql($_POST["ffin"])."'";	
	
	$sql = "call spQuery_Efectividad_Vendedor('$_POST[pcod]', $varFIni, $varFFin);";

	$varCab = array(array("cab"=>"VENTA SOLES (S/.)", "det"=>array("PREVEN.","VENTA","RECHAZ", "PARCIAL", "%EFECT.")),
					array("cab"=>"PEDIDOS", "det"=>array("PREVEN.","VENTA","RECHAZ", "PARCIAL", "%EFECT.")),
					array("cab"=>"PUNTOS DE VENTA", "det"=>array("PREVEN.","VENTA","RECHAZ", "PARCIAL", "%EFECT."))
					);
	$varNiv = array(0 =>array("COD"=>"CVEN","DES"=>"VENDEDOR"),
					1 =>array("COD"=>"CTIP","DES"=>"TIPO"),
					2 =>array("COD"=>"CTOT","DES"=>"TOTAL"));
	$varFor = array(10=>array("tipodat"=>"porc", "formula"=>array("valor1"=>6,  "valor2"=>7,  "funcion"=>"porc")),
					15=>array("tipodat"=>"porc", "formula"=>array("valor1"=>11, "valor2"=>12, "funcion"=>"porc")),
					20=>array("tipodat"=>"porc", "formula"=>array("valor1"=>16, "valor2"=>17, "funcion"=>"porc"))
					);
			
	$_SESSION["_varNiv"] = $varNiv;
	$_SESSION["_varFor"] = $varFor;
	$_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->processRequest();
$xajax->printJavascript("clases/xajax");
		
function MyTable($obj, $varTitulo, $Opcion, $Valor) {
	$Link = $_SERVER['PHP_SELF'];
	if(!isset($Opcion)) {
		
		$varTabla=array("id"=>"table", "name"=>"table", "tamano"=>"420", "clase"=>"Formtitulo", "titulo"=>$varTitulo,
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST", "onsubmit"=>"return validaAvanceVentas(this)"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$Opcion)
									  ),
						"conte"=>array(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"=>"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"]) 
											 )
									   ),
						"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_efectividad_vendedor(form.pcod.value, form.fini.value, form.ffin.value)"),		  
									   array("tipo"=>"submit", "id"=>"bexp", "name"=>"bexp", "ancho"=>"80", "alto"=>"22", "texto"=>"Exportar")										
									   )
						);
		echo $obj->setTablaForm($varTabla);	
		if(isset($_POST["bcon"])) {		
			$varFIni = ($_POST["fini"]=="") ? "NULL" : "'".FechaMySql($_POST["fini"])."'";
			$varFFin = ($_POST["ffin"]=="") ? "NULL" : "'".FechaMySql($_POST["ffin"])."'";	
			
			$sql = "call spQuery_Efectividad_Vendedor('$_POST[pcod]', $varFIni, $varFFin);";

			$varCab = array(array("cab"=>"VENTA SOLES (S/.)", "det"=>array("PREVEN.","VENTA","RECHAZ", "PARCIAL", "%EFECT.")),
							array("cab"=>"PEDIDOS", "det"=>array("PREVEN.","VENTA","RECHAZ", "PARCIAL", "%EFECT.")),
							array("cab"=>"PUNTOS DE VENTA", "det"=>array("PREVEN.","VENTA","RECHAZ", "PARCIAL", "%EFECT."))
							);
			$varNiv = array(0 =>array("COD"=>"CVEN","DES"=>"VENDEDOR"),
							1 =>array("COD"=>"CTIP","DES"=>"TIPO"),
							2 =>array("COD"=>"CTOT","DES"=>"TOTAL"));
			$varFor = array(10=>array("tipodat"=>"porc", "formula"=>array("valor1"=>6,  "valor2"=>7,  "funcion"=>"porc")),
							15=>array("tipodat"=>"porc", "formula"=>array("valor1"=>11, "valor2"=>12, "funcion"=>"porc")),
							20=>array("tipodat"=>"porc", "formula"=>array("valor1"=>16, "valor2"=>17, "funcion"=>"porc"))
							);
			echo $obj->setGridCombina($varCab, $sql, $varNiv, NULL, $varFor);
			echo "<br>";
			}
		}
	} 
?>