
<head>
	<style>
		.tabela_view tr:nth-child(even) {background-color: #f2f2f2;}
		.tabela_view { border-collapse: collapse;}
		.tabela, td, th {
		  padding: 10px;
		}
		/*#table, td, th {
		  border: 1px solid;
		}*/
	</style>
</head>
<script>
	listaInfoArmazenada = "<?php echo $bi_analise->getColunas_informarcao_analise_vertical(); ?>";
	listaColunaVerticalInfoArmazenada = "<?php echo $bi_analise->getColuna_analise_vertical(); ?>";
	listaInfoValoresArmazenada = "<?php echo $bi_analise->getColunas_valores_analise_vertical(); ?>";
	listaQuebraTotParcialArmazenada = "<?php echo $bi_analise->getColunas_quebrar_parcial_analise_vertical(); ?>";
	listaQuebraMediaParcialArmazenada = "<?php echo $bi_analise->getColunas_quebrar_media_parcial_analise_vertical(); ?>";
	listaQuebraTotFinalArmazenada = "<?php echo $bi_analise->getColunas_total_analise_vertical(); ?>";
	listaQuebraMediaFialArmazenada = "<?php echo $bi_analise->getColunas_media_analise_vertical(); ?>";
	listacolunas_valores_media_parcialArmazenada  = "<?php echo $bi_analise->getColunas_valores_media_parcial(); ?>";
	listacolunas_valores_soma_parcialArmazenada  = "<?php echo $bi_analise->getColunas_valores_soma_parcial(); ?>";
	listaInfoArmazenada = listaInfoArmazenada.replaceAll("`","");
	listaColunaVerticalInfoArmazenada = listaColunaVerticalInfoArmazenada.replaceAll("`","");
	listaInfoValoresArmazenada = listaInfoValoresArmazenada.replaceAll("`","");
	listaQuebraTotParcialArmazenada = listaQuebraTotParcialArmazenada.replaceAll("`","");
	listaQuebraMediaParcialArmazenada = listaQuebraMediaParcialArmazenada.replaceAll("`","");
	listaQuebraTotFinalArmazenada = listaQuebraTotFinalArmazenada.replaceAll("`","").split(",");;
	listaQuebraMediaFialArmazenada = listaQuebraMediaFialArmazenada.replaceAll("`","").split(",");
	listacolunas_valores_media_parcialArmazenada = listacolunas_valores_media_parcialArmazenada.replaceAll("`","").split(",");;
	listacolunas_valores_soma_parcialArmazenada = listacolunas_valores_soma_parcialArmazenada.replaceAll("`","").split(",");;
	tipoConfig = "<?php echo $_GET["tipoConfig"]; ?>";
	

</script>
<script src="js/analise_etapa1.js"></script>
<script src="js/analise_tabela.js"></script>

<div id="etapa3" class="etapas_criar_analise" style="display: none; position: relative;  padding-top: 0px;  padding: 10px; padding-top: 0px; width: 100%; z-index: 999999;">
	<table id="tabelaTemp" border="1" class="tableAnalise" style="width: 100%;" >
		<thead>
		<tr>
			<td style="text-align: left; vertical-align: top; width: 200px;">
				<label>Colunas visualização</label>
				<select class="form" id="select_colunas_info" placeholder="Tipo" onchange="atualiza_select_vertical()"  multiple style="width: 100%; padding: 5px;">
					<option value=""></option>
				</select>
			</td>
			
			<td style="vertical-align: top; width: 250px;">
				<label>Colunas de valores</label>
				<select class="form" id="select_colunas_valores_vertical" onchange="atualiza_select_quebrar_parcial_vertical()" placeholder="Tipo" multiple   style="width: 150px; padding: 5px;">
					<option value=""></option>
				</select> 
				</b>
				<label>Total soma.</label>
				<select class="form" id="select_colunas_total_vertical" onchange="setValoresTotais()" onclick="atualiza_select_quebrar_parcial_vertical()" placeholder="Tipo"  multiple style="width: 150px; padding: 5px;">
					<option value=""></option>
				</select>
				<br>
				<label>Total média.</label>
				<select class="form" id="select_colunas_media_vertical" onchange="setValoresTotais()" onclick="atualiza_select_quebrar_parcial_vertical()" placeholder="Tipo"  multiple style="width: 150px; padding: 5px;">
					<option value=""></option>
				</select>
			</td>
			<td style="vertical-align: top; min-width: 180px;">
				<label>Coluna vertical</label><!--(Exemplo Mes: JAN, FEV, MAR)--><Br>
				<select class="form" id="select_coluna_vertical" placeholder="Tipo" onchange="atualiza_select_valores_vertical()"  style="width: 150px; padding: 5px;">
					<option value=""></option>
				</select>
				
			</td>
			
		</tr>
		</thead>
		<tbody>
			<tr><td>-</td></tr>
			<tr><td style="text-align: left;"><label>Quebrar soma parcial.</label>
				<select class="form" id="select_colunas_quebra_parcial_vertical" placeholder="Tipo"  multiple style="width: 150px; padding: 5px;">
					<option value=""></option>
				</select>
			</td>
			<td>
				<label>Colunas valores soma parcial.</label>
				<select class="form" id="select_colunas_val_soma_parcial" onchange="setValoresTotais()" onclick="atualiza_select_quebrar_parcial_vertical()" placeholder="Tipo"  multiple style="width: 150px; padding: 5px;">
					<option value=""></option>
				</select>
			</td>
			</tr>
			
			<tr><td style="text-align: left;"><label>Quebrar média parcial.</label> 
				<select class="form" id="select_colunas_quebra_media_parcial_vertical" placeholder="Tipo"  multiple style="width: 150px; padding: 5px;">
					<option value=""></option>
				</select>
			</td>
			<td>
				<label>Colunas valores média parcial.</label>
				<select class="form" id="select_colunas_val_media_parcial" onchange="setValoresTotais()" onclick="atualiza_select_quebrar_parcial_vertical()" placeholder="Tipo"  multiple style="width: 150px; padding: 5px;">
					<option value=""></option>
				</select>
			</td>
			</tr>
			<tr><td>-</td></tr>
			
			
		</tbody>
	</table>
</div>
<div id="etapa4"   style=" display: none; width: 100%; max-width: 800px; margin: 0 auto;  padding-top: 0px;">
	<!--<b style="color: #a6a6a6;">Etapa 4 de 4 - Configurar colunas</b> <Br>
	<a href="javaScript:void(0)" style=" font-weight: bold;" onclick="voltar_etapa3()"><i class="fa-solid fa-left-long"></i> Voltar etapa</a>
	<Br>
	-->
	<div id="config_coluna"  style="width: 100%; ">
	
	</div>
	
	<!--<button class="btnSuccess btnSn" onclick="finalizar_analise_tabela()">Finalizar</button>-->
</div>
<center><button class="btnSuccess btnSn" onclick="prever_colunas_tab()">Prever</button></center>
<Br>
<script>
	
	sequenciarColunasIni(listaInfoArmazenada, "#select_colunas_info");
	//sequenciarColunasIni(listaColunaVerticalInfoArmazenada, "#select_colunas_info");
	sequenciarColunasIni(listaInfoValoresArmazenada, "#select_colunas_valores_vertical");
	sequenciarColunasIni(listaQuebraTotParcialArmazenada, "#select_colunas_quebra_parcial_vertical");
	sequenciarColunasIni(listaQuebraMediaParcialArmazenada, "#select_colunas_quebra_media_parcial_vertical");
	sequenciarColunasIni(listaQuebraTotFinalArmazenada, "#select_colunas_total_vertical");
	sequenciarColunasIni(listaQuebraMediaFialArmazenada, "#select_colunas_media_vertical");
	function sequenciarColunasIni(listaArmazenada, select_colunas)
	{
		aColInfos = (listaArmazenada+"").split(",");
		/*for(i =0; i < aColInfos.length; i++)
		{
			if(! $(select_colunas).html().includes(aColInfos[i]))
			{
				$(select_colunas).append($('<option>', {
					value: aColInfos[i],
					text: aColInfos[i],
					"selected": true
				}));
			}
		}*/
		for(i =0; i < aColInfos.length; i++)
		{
			selected = false;
			if(! $(select_colunas).html().includes(aColInfos[i]))
			{
				selected = true;
			}
			$(select_colunas).append($('<option>', {
					value: aColInfos[i],
					text: aColInfos[i],
					"selected": selected
				}));
		}
	}
	colunasTemp = [];
	<?php 
	foreach($listabi_coluna_analise as $coluna_analise)
	{
		//echo $coluna_analise->getColuna()." ".$coluna_analise->getTipo()->getTipo_bd()."<br>";
		echo "colunasTemp.push({nome: '".$coluna_analise->getColuna()."', tipo_dado: '".$coluna_analise->getTipo()->getTipo_bd()."', oculto: '".$coluna_analise->getOculto()."',
		codigo: '".$coluna_analise->getCodigo()."', apelido: '".$coluna_analise->getApelido()."',
		utilizada_para_calculo: '".$coluna_analise->getUtilizada_para_calculo()."',
		mascara: '".$coluna_analise->getMascara()."', cod_agregacao: '".$coluna_analise->getAgregacao()->getCodigo()."', 
		id_tipo_dado: '".$coluna_analise->getTipo()->getCodigo()."',
		ordenar: '".$coluna_analise->getOrdenacao()."',
		regra_calculada: '".$coluna_analise->getRegra_calculada()."'
		});";
	}
	?>
	
	$("#select_colunas_info").select2({ width: '100%' });
	//abaixo codigo para colocar na sequencia de clique
	///$("#select_colunas_info").on("select2:select", function (evt) {var element = evt.params.data.element; var $element = $(element); $element.detach(); $(this).append($element); $(this).trigger("change");});
	//if(tipo_analise == "tabela_vertical")
	//{
	$("#select_coluna_vertical").select2({ width: '100%' });
	$("#select_colunas_quebra_parcial_vertical").select2({ width: '100%' });
	$("#select_colunas_quebra_media_parcial_vertical").select2({ width: '100%' });
	$("#select_colunas_valores_vertical").select2({ width: '100%' });
	$("#select_colunas_total_vertical").select2({ width: '100%' });
	$("#select_colunas_media_vertical").select2({ width: '100%' });
	$("#select_colunas_val_soma_parcial").select2({ width: '100%' });
	$("#select_colunas_val_media_parcial").select2({ width: '100%' });
	//abaixo codigo para colocar na sequencia de clique
	$("#select_colunas_quebra_parcial_vertical").on("select2:select", function (evt) {var element = evt.params.data.element; var $element = $(element); $element.detach(); $(this).append($element); $(this).trigger("change");});
	$("#select_colunas_quebra_media_parcial_vertical").on("select2:select", function (evt) {var element = evt.params.data.element; var $element = $(element); $element.detach(); $(this).append($element); $(this).trigger("change");});
	$("#select_colunas_valores_vertical").on("select2:select", function (evt) {var element = evt.params.data.element; var $element = $(element); $element.detach(); $(this).append($element); $(this).trigger("change");});
	$("#select_colunas_total_vertical").on("select2:select", function (evt) {var element = evt.params.data.element; var $element = $(element); $element.detach(); $(this).append($element); $(this).trigger("change");});
	$("#select_colunas_media_vertical").on("select2:select", function (evt) {var element = evt.params.data.element; var $element = $(element); $element.detach(); $(this).append($element); $(this).trigger("change");});
	$("#select_colunas_val_soma_parcial").on("select2:select", function (evt) {var element = evt.params.data.element; var $element = $(element); $element.detach(); $(this).append($element); $(this).trigger("change");});
	$("#select_colunas_val_media_parcial").on("select2:select", function (evt) {var element = evt.params.data.element; var $element = $(element); $element.detach(); $(this).append($element); $(this).trigger("change");});
			
	tipo_analise = "tabela";//$("#select_tipo_analise").val();
	
	
	for(i =0; i < colunasTemp.length; i++)
	{
		selected = false;
		if(listaInfoArmazenada.includes(colunasTemp[i].nome))
		{
			selected = true;
		}
		if(! listaInfoValoresArmazenada.includes(colunasTemp[i].nome) )
		{
			if(! $("#select_colunas_info").html().includes(colunasTemp[i].nome))
			{
				$("#select_colunas_info").append($('<option>', {
					value: colunasTemp[i].nome,
					text: colunasTemp[i].nome,
					"selected": selected
				}));
			}
		}
		if(colunasTemp[i].tipo_dado == "int" || colunasTemp[i].tipo_dado == "float")
		{
			/*selected = false;
			if(listaQuebraTotFinalArmazenada.includes(colunasTemp[i].nome))
			{
				selected = true;
			}
			$("#select_colunas_total_vertical").append($('<option>', {
				value: colunasTemp[i].nome,
				text: colunasTemp[i].nome,
				"selected": selected
			}));
			selected = false;
			if(listaQuebraMediaFialArmazenada.includes(colunasTemp[i].nome))
			{
				selected = true;
			}
			$("#select_colunas_media_vertical").append($('<option>', {
				value: colunasTemp[i].nome,
				text: colunasTemp[i].nome,
				"selected": selected
			}));*/
		}
		if(listaInfoArmazenada.includes(colunasTemp[i].nome))
		{
			selected = false;
			if(listaQuebraTotParcialArmazenada.includes(colunasTemp[i].nome))
			{
				selected = true;
			}
			if(! $("#select_colunas_quebra_parcial_vertical").html().includes(colunasTemp[i].nome))
			{
				$("#select_colunas_quebra_parcial_vertical").append($('<option>', {
					value: colunasTemp[i].nome,
					text: colunasTemp[i].nome,
					"selected": selected
				}));
			}
			selected = false;
			if(listaQuebraMediaParcialArmazenada.includes(colunasTemp[i].nome))
			{
				selected = true;
			}
			if(! $("#select_colunas_quebra_media_parcial_vertical").html().includes(colunasTemp[i].nome))
			{
				$("#select_colunas_quebra_media_parcial_vertical").append($('<option>', {
					value: colunasTemp[i].nome,
					text: colunasTemp[i].nome,
					"selected": selected
				}));
			}
				
			
		}
		//var newOption = new Option(colunasTemp[i].nome, colunasTemp[i].nome, false, false);
		//$("#select_colunas_info").append(newOption).trigger('change');
	}
	
	if(true)//tipo_analise == "tabela_vertical")
	{
		
		for(i =0; i < colunasTemp.length; i++)
		{
			//if(colunasTemp[i].tipo_dado != "int" && colunasTemp[i].tipo_dado != "float")
			//{
				selected = false;
				if(listaColunaVerticalInfoArmazenada.includes(colunasTemp[i].nome))
				{
					selected = true;
				}
				if(! listaInfoValoresArmazenada.includes(colunasTemp[i].nome) && ! $("#select_coluna_vertical").html().includes(colunasTemp[i].nome))
				{
					$("#select_coluna_vertical").append($('<option>', {
						value: colunasTemp[i].nome,
						text: colunasTemp[i].nome,
						"selected": selected
					}));
				}
				
			//}
			
			if(colunasTemp[i].tipo_dado == "int" || colunasTemp[i].tipo_dado == "float")
			{
				selected = false;
				if(listaInfoValoresArmazenada.includes(colunasTemp[i].nome))
				{
					selected = true;
				}
				if(! $("#select_colunas_valores_vertical").html().includes(colunasTemp[i].nome))
				{
					$("#select_colunas_valores_vertical").append($('<option>', {
						value: colunasTemp[i].nome,
						text: colunasTemp[i].nome,
						"selected": selected
					}));
				}
				
			}
		}
		
	}
	///recriar os select2
	crar_select2_com_todas_as_configs();
	atualiza_select_valores_vertical();
	function prever_colunas_tab()
	{
		colunasSelecionadas = $("#select_colunas_info").val();
		strColunas = "";
		
		colunas_view_vertical = "";
		colunas_valores_vertical = "";
		coluna_vertical = "";
		colunas_quebrar_parcial_analise_vertical = "";
		colunas_quebrar_media_parcial_analise_vertical = "";
		colunas_total_analise_vertical = "";
		colunas_media_analise_vertical = "";
		colunas_valores_media_parcial = "";
		colunas_valores_soma_parcial = "";
		if(true)//tipo_analise == "tabela_vertical")
		{
			if($("#select_colunas_info").val() != null)
			{
				//colunas_view_vertical = $("#select_colunas_info").val().toString();
				for(k =0; k < $("#select_colunas_info").val().length; k++)
				{
					if(colunas_view_vertical != ""){colunas_view_vertical += ",";}
					colunas_view_vertical += "`"+$("#select_colunas_info").val()[k]+"`";
				}
				colunas_view_vertical.replaceAll("``","`");
				
			}
			if($("#select_colunas_valores_vertical").val() != null)
			{
				//colunas_valores_vertical = $("#select_colunas_valores_vertical").val().toString();
				for(k =0; k < $("#select_colunas_valores_vertical").val().length; k++)
				{
					if(colunas_valores_vertical != ""){colunas_valores_vertical += ",";}
					colunas_valores_vertical += "`"+$("#select_colunas_valores_vertical").val()[k]+"`";
				}
				colunas_valores_vertical.replaceAll("``","`");
			}
			coluna_vertical = $("#select_coluna_vertical").val();
			if($("#select_colunas_quebra_parcial_vertical").val() != null)
			{
				//colunas_quebra_parcial_vertical = $("#select_colunas_quebra_parcial_vertical").val().toString();
				for(k =0; k < $("#select_colunas_quebra_parcial_vertical").val().length; k++)
				{
					if(colunas_quebrar_parcial_analise_vertical != ""){colunas_quebrar_parcial_analise_vertical += ",";}
					colunas_quebrar_parcial_analise_vertical += "`"+$("#select_colunas_quebra_parcial_vertical").val()[k]+"`";
				}
				colunas_quebrar_parcial_analise_vertical.replaceAll("``","`");
			}
			if($("#select_colunas_quebra_media_parcial_vertical").val() != null)
			{
				//colunas_quebra_parcial_vertical = $("#select_colunas_quebra_parcial_vertical").val().toString();
				for(k =0; k < $("#select_colunas_quebra_media_parcial_vertical").val().length; k++)
				{
					if(colunas_quebrar_media_parcial_analise_vertical != ""){colunas_quebrar_media_parcial_analise_vertical += ",";}
					colunas_quebrar_media_parcial_analise_vertical += "`"+$("#select_colunas_quebra_media_parcial_vertical").val()[k]+"`";
				}
				colunas_quebrar_media_parcial_analise_vertical.replaceAll("``","`");
			}
			if($("#select_colunas_total_vertical").val() != null)
			{
				//colunas_quebra_parcial_vertical = $("#select_colunas_quebra_parcial_vertical").val().toString();
				for(k =0; k < $("#select_colunas_total_vertical").val().length; k++)
				{
					if(colunas_total_analise_vertical != ""){colunas_total_analise_vertical += ",";}
					colunas_total_analise_vertical += "`"+$("#select_colunas_total_vertical").val()[k]+"`";
				}
				colunas_total_analise_vertical.replaceAll("``","`");
			}
			if($("#select_colunas_media_vertical").val() != null)
			{
				//colunas_quebra_parcial_vertical = $("#select_colunas_quebra_parcial_vertical").val().toString();
				for(k =0; k < $("#select_colunas_media_vertical").val().length; k++)
				{
					if(colunas_media_analise_vertical != ""){colunas_media_analise_vertical += ",";}
					colunas_media_analise_vertical += "`"+$("#select_colunas_media_vertical").val()[k]+"`";
				}
				colunas_media_analise_vertical.replaceAll("``","`");
			}
			if($("#select_colunas_val_soma_parcial").length > 0)
			{
				if($("#select_colunas_val_soma_parcial").val() != null)
				{
					//colunas_quebra_parcial_vertical = $("#select_colunas_quebra_parcial_vertical").val().toString();
					for(k =0; k < $("#select_colunas_val_soma_parcial").val().length; k++)
					{
						if(colunas_valores_soma_parcial != ""){colunas_valores_soma_parcial += ",";}
						colunas_valores_soma_parcial += "`"+$("#select_colunas_val_soma_parcial").val()[k]+"`";
					}
					colunas_valores_soma_parcial.replaceAll("``","`");
				}
				if($("#select_colunas_val_media_parcial").val() != null)
				{
					for(k =0; k < $("#select_colunas_val_media_parcial").val().length; k++)
					{
						if(colunas_valores_media_parcial != ""){colunas_valores_media_parcial += ",";}
						colunas_valores_media_parcial += "`"+$("#select_colunas_val_media_parcial").val()[k]+"`";
					}
					colunas_valores_media_parcial.replaceAll("``","`");
				}
			}
		}
		
		analise = { colunas_view_vertical: colunas_view_vertical, 
				colunas_valores_vertical: colunas_valores_vertical, 
				coluna_vertical: coluna_vertical,
				colunas_quebrar_parcial_analise_vertical: colunas_quebrar_parcial_analise_vertical, 
				colunas_quebrar_media_parcial_analise_vertical: colunas_quebrar_media_parcial_analise_vertical,
				colunas_total_analise_vertical: colunas_total_analise_vertical,
				colunas_media_analise_vertical: colunas_media_analise_vertical,
				analise: <?php echo $bi_analise->getCodigo(); ?>,
				prever: true,
				colunas_valores_soma_parcial: colunas_valores_soma_parcial,
				colunas_valores_media_parcial: colunas_valores_media_parcial,
				colunas: colunasTemp
			};
		fechar_modal_aviso();
		///abrir_modal_aviso("<b>Aguarde ...</b>");	
		//console.log(analise);
		if(colunas_view_vertical == null || colunas_view_vertical == "")
		{
			colunas_view_vertical = "``";
		}
		if(colunas_valores_vertical == null || colunas_valores_vertical == "")
		{
			colunas_valores_vertical = "``";
		}
		if(coluna_vertical == null || coluna_vertical == "")
		{
			coluna_vertical = "``";
		}
		if(colunas_quebrar_parcial_analise_vertical == null || colunas_quebrar_parcial_analise_vertical == "")
		{
			colunas_quebrar_parcial_analise_vertical = "``";
		}
		if(colunas_quebrar_media_parcial_analise_vertical == null || colunas_quebrar_media_parcial_analise_vertical == "")
		{
			colunas_quebrar_media_parcial_analise_vertical = "``";
		}
		if(colunas_total_analise_vertical == null || colunas_total_analise_vertical == "")
		{
			colunas_total_analise_vertical = "``";
		}
		if(colunas_media_analise_vertical == null || colunas_media_analise_vertical == "")
		{
			colunas_media_analise_vertical = "``";
		}
		
		if(colunas_valores_soma_parcial == null || colunas_valores_soma_parcial == "")
		{
			colunas_valores_soma_parcial = "``";
		}
		if(colunas_valores_media_parcial == null || colunas_valores_media_parcial == "")
		{
			colunas_valores_media_parcial = "``";
		}
		//alert(JSON.stringify(colunasTemp))
		//alert(colunas_valores_soma_parcial);
		$('#<?php echo $_GET["nomeForm"]; ?> .filtro_custom').html('');
		$('#<?php echo $_GET["nomeForm"]; ?> .filtro_custom').append('<input type="text" class="inputFiltroBi" name="colunas_view_vertical" value="'+colunas_view_vertical+'" />'); 
		$('#<?php echo $_GET["nomeForm"]; ?> .filtro_custom').append('<input type="text" class="inputFiltroBi" name="colunas_valores_vertical" value="'+colunas_valores_vertical+'" />');
		$('#<?php echo $_GET["nomeForm"]; ?> .filtro_custom').append('<input type="text" class="inputFiltroBi" name="coluna_vertical" value="'+coluna_vertical+'" />');
		$('#<?php echo $_GET["nomeForm"]; ?> .filtro_custom').append('<input type="text" class="inputFiltroBi" name="colunas_quebrar_parcial_analise_vertical" value="'+colunas_quebrar_parcial_analise_vertical+'" />');
		$('#<?php echo $_GET["nomeForm"]; ?> .filtro_custom').append('<input type="text" class="inputFiltroBi" name="colunas_quebrar_media_parcial_analise_vertical" value="'+colunas_quebrar_media_parcial_analise_vertical+'" />');
		$('#<?php echo $_GET["nomeForm"]; ?> .filtro_custom').append('<input type="text" class="inputFiltroBi" name="colunas_total_analise_vertical" value="'+colunas_total_analise_vertical+'" />'); 
		$('#<?php echo $_GET["nomeForm"]; ?> .filtro_custom').append('<input type="text" class="inputFiltroBi" name="colunas_media_analise_vertical" value="'+colunas_media_analise_vertical+'" />'); 
		$('#<?php echo $_GET["nomeForm"]; ?> .filtro_custom').append('<input type="text" class="inputFiltroBi" name="prever" value="true" />'); 
		$('#<?php echo $_GET["nomeForm"]; ?> .filtro_custom').append('<input type="text" class="inputFiltroBi" name="colunas_valores_soma_parcial" value="'+colunas_valores_soma_parcial+'" />'); 
		$('#<?php echo $_GET["nomeForm"]; ?> .filtro_custom').append('<input type="text" class="inputFiltroBi" name="colunas_valores_media_parcial" value="'+colunas_valores_media_parcial+'" />'); 
		$('#<?php echo $_GET["nomeForm"]; ?> .filtro_custom').append('<input type="text" class="inputFiltroBi" name="colunas" value="'+window.btoa(JSON.stringify(colunasTemp))+'" />'); 
		$('#<?php echo $_GET["nomeForm"]; ?>').parent().parent().parent().parent().parent().find('.salvar_analise').css('display', 'inline');
		// $("<input type='text' value='"+colunas_view_vertical+"' />").attr("class", "inputFiltroBi").attr("name", "colunas_view_vertical").appendTo("#formDadosbi_analiseFiltro");
		if(montaTebelaBi('<?php echo $_GET["nomeForm"]; ?>','<?php echo $_GET["seletor"]; ?>')) 
		{  
			
			//$('#btn_abrir_modal_filtro4').click();
		}
		
	}
	monta_tabela_agregacao_user();

	function monta_tabela_agregacao_user()
	{
		//colocar essa parte na etapa1
		//colocar essa parte na etapa1
		html = "<table>	<head> <tr> <td><b>Coluna</b></td> <td><b>Apelido</b></td> <td><b>Mascara</b></td> <td><b>Agregação</b></td><td><b>Ordenar</b></td> </tr> </head>";
		for(i =0; i < colunasTemp.length; i++)
		{
			//valida se a colunas esta sendo usada
			colunasTemp[i].oculto = true;
			if(
			    listaInfoValoresArmazenada.includes(colunasTemp[i].nome.trim()) ||
			    listaColunaVerticalInfoArmazenada.includes(colunasTemp[i].nome.trim()) ||
			    listaQuebraTotFinalArmazenada.includes(colunasTemp[i].nome.trim()) ||
			    listaQuebraMediaFialArmazenada.includes(colunasTemp[i].nome.trim()) ||
			    listaQuebraTotParcialArmazenada.includes(colunasTemp[i].nome.trim()) ||
			    listaQuebraMediaParcialArmazenada.includes(colunasTemp[i].nome.trim()) ||
			    listaInfoArmazenada.includes(colunasTemp[i].nome.trim()
			   ) 
			)
			{
				colunasTemp[i].oculto = false;
			}
			if((! colunasTemp[i].oculto )
				&& (colunasTemp[i].tipo_dado == "datetime" || colunasTemp[i].tipo_dado == "date" || colunasTemp[i].tipo_dado == "float" || colunasTemp[i].tipo_dado == "int")
			)
			{
					html += "<tr>    ";
					html += "<td><b style='top: -6px; position: relative;'>"+colunasTemp[i].nome+"<b></td>";
					html += '<td><input value="'+colunasTemp[i].apelido+'" onchange="alterar_apelido_coluna_user(this, '+i+');"  class="form" name="apelido"  style="width: 80px; padding: 5px;"></td>  ';
					html += "<td>" ;
					//alert(colunasTemp[i].tipo);
					if(colunasTemp[i].tipo_dado == "datetime")
					{
						if(colunasTemp[i].mascara == "" || colunasTemp[i].mascara == null)
						{
							colunasTemp[i].mascara = "d/m/Y H:i";
						}
						html +='<select class="form" name="mascara" onchange="alterar_mascara_coluna_user(this, '+i+');"  style="width: 190px; padding: 4px;">';
						html +='	<option value="d/m/Y H:i" '+(colunasTemp[i].mascara == "d/m/Y H:i" ? "selected='selected'": "")+'>Dia/Mês/Ano Hora:Minuto </option>';
						html +='	<option value="d/m/Y H" '+(colunasTemp[i].mascara == "d/m/Y H" ? "selected='selected'": "")+'>Dia/Mês/Ano Hora </option>';
						html +='	<option value="H:i" '+(colunasTemp[i].mascara == "H:i" ? "selected='selected'": "")+'>Hora:Minuto </option>';
						html +='	<option value="H" '+(colunasTemp[i].mascara == "H" ? "selected='selected'": "")+'>Hora </option>';
						html +='	<option value="i" '+(colunasTemp[i].mascara == "i" ? "selected='selected'": "")+'>Minuto </option>';
						html +='	<option value="d/m/Y" '+(colunasTemp[i].mascara == "d/m/Y" ? "selected='selected'": "")+'>Dia/Mês/Ano</option>';
						html +='	<option value="d/m" '+(colunasTemp[i].mascara == "d/m" ? "selected='selected'": "")+'>Dia/Mês </option>';
						html +='	<option value="d" '+(colunasTemp[i].mascara == "d" ? "selected='selected'": "")+'>Dia </option>';
						html +='	<option value="m/Y" '+(colunasTemp[i].mascara == "m/Y" ? "selected='selected'": "")+'>Mês/Ano </option>';
						html +='	<option value="m" '+(colunasTemp[i].mascara == "m" ? "selected='selected'": "")+'>Mês</option>';
						html +='	<option value="Y" '+(colunasTemp[i].mascara == "Y" ? "selected='selected'": "")+'>Ano</option>';
						
						html +='</select>';
					}
					else if(colunasTemp[i].tipo_dado == "date")
					{
						if(colunasTemp[i].mascara == "" || colunasTemp[i].mascara == null)
						{
							colunasTemp[i].mascara = "d/m/Y";
						}
						html +='<select class="form" name="mascara" onchange="alterar_mascara_coluna_user(this, '+i+');"  style="width: 190px; padding: 4px;" value="'+colunasTemp[i].mascara+'">';
						html +='	<option value="d/m/Y" '+(colunasTemp[i].mascara == "d/m/Y" ? "selected='selected'": "")+'>Dia/Mês/Ano</option>';
						html +='	<option value="d/m" '+(colunasTemp[i].mascara == "d/m" ? "selected='selected'": "")+'>Dia/Mês </option>';
						html +='	<option value="d" '+(colunasTemp[i].mascara == "d" ? "selected='selected'": "")+'>Dia </option>';
						html +='	<option value="m/Y" '+(colunasTemp[i].mascara == "m/Y" ? "selected='selected'": "")+'>Mês/Ano </option>';
						html +='	<option value="m" '+(colunasTemp[i].mascara == "m" ? "selected='selected'": "")+'>Mês</option>';
						html +='	<option value="Y" '+(colunasTemp[i].mascara == "Y" ? "selected='selected'": "")+'>Ano</option>';
						
						html +='</select>';
					}
					else if(colunasTemp[i].tipo_dado == "float")
					{
						if(colunasTemp[i].mascara == "" || colunasTemp[i].mascara == null)
						{
							colunasTemp[i].mascara = "2";
						}
						html +='<b>Casas decimais</b><input value="'+colunasTemp[i].mascara+'" onchange="alterar_mascara_coluna_user(this, '+i+');" class="form" name="mascara"  style="width: 80px; padding: 5px;">';
					}
					html += "</td> ";
					html += "<td>" ;
					//alert(colunasTemp[i].tipo_dado)
					if(colunasTemp[i].tipo_dado == "int" || colunasTemp[i].tipo_dado == "float")
					{
						if(colunasTemp[i].cod_agregacao == "" || colunasTemp[i].cod_agregacao == null)
						{
							colunasTemp[i].cod_agregacao = "1";
						}
						html += '<select class="form" name="agracacao" placeholder="Agregação" value="'+colunasTemp[i].cod_agregacao+'" onchange="alterar_agregacao_coluna_user(this, '+i+');" style="width: 100%;" >';
						html += '	<option value="1" '+(colunasTemp[i].cod_agregacao == "1" ? "selected='selected'": "")+'>Somatório</option>';
						html += '	<option value="2" '+(colunasTemp[i].cod_agregacao == "2" ? "selected='selected'": "")+'>Media</option>';
						html += '	<option value="3" '+(colunasTemp[i].cod_agregacao == "3" ? "selected='selected'": "")+'>Mínimo</option>';
						html += '	<option value="4" '+(colunasTemp[i].cod_agregacao == "4" ? "selected='selected'": "")+'>Máximo</option>';
						html += '	<option value="5" '+(colunasTemp[i].cod_agregacao == "5" ? "selected='selected'": "")+'>Contagem</option>';
						html += '	<option value="6" '+(colunasTemp[i].cod_agregacao == "6" ? "selected='selected'": "")+'>Contagem distinta</option>';
						html += '</select>';
						
					}
					html += "</td> ";
					
					html += "<td>" ;
						if(colunasTemp[i].ordenar == "" || colunasTemp[i].ordenar == null)
						{
							colunasTemp[i].ordenar = "";
						}
						html += '<select class="form" name="ordenar" placeholder="Ordenar" value="'+colunasTemp[i].ordenar+'" onchange="alterar_ordenar_coluna_user(this, '+i+');" style="width: 80px;" >';
						html += '	<option value="" '+(colunasTemp[i].ordenar == "" ? "selected='selected'": "")+'>Crescente</option>';
						html += '	<option value="DESC" '+(colunasTemp[i].ordenar == "DESC" ? "selected='selected'": "")+'>Decrescente</option>';
						html += '</select>';
					html += "</td> ";
					html += "</tr> ";
					
			}
			else if(! colunasTemp[i].oculto )
			{
				html += "<tr>  ";
					html += "<td><b style='top: -6px; position: relative;'>"+colunasTemp[i].nome+"<b></td>";
					html += '<td><input value="'+colunasTemp[i].apelido+'" onchange="alterar_apelido_coluna_user(this, '+i+');"  class="form" name="apelido"  style="width: 80px; padding: 5px;"></td>  ';
					html += "<td> </td>" ;
					html += "<td> </td>" ;
					html += "<td>" ;
						if(colunasTemp[i].ordenar == "" || colunasTemp[i].ordenar == null)
						{
							colunasTemp[i].ordenar = "";
						}
						html += '<select class="form" name="ordenar" placeholder="Ordenar" value="'+colunasTemp[i].ordenar+'" onchange="alterar_ordenar_coluna_user(this, '+i+');" style="width: 80px;" >';
						html += '	<option value="" '+(colunasTemp[i].ordenar == "" ? "selected='selected'": "")+'>Crescente</option>';
						html += '	<option value="DESC" '+(colunasTemp[i].ordenar == "DESC" ? "selected='selected'": "")+'>Decrescente</option>';
						html += '</select>';
					html += "</td> ";
				html += "</tr> ";
			}
		}
		html += "<table>";
		$('#config_coluna').html(html);
		
	}
	
	function alterar_apelido_coluna_user(seletor, indice_colunas)
	{
		//colocar essa parte na etapa1
		colunasTemp[indice_colunas].apelido = $(seletor).val();
	}
	function alterar_agregacao_coluna_user(seletor, indice_colunas)
	{
		//colocar essa parte na etapa1
		colunasTemp[indice_colunas].cod_agregacao = $(seletor).val();
	}
	function alterar_mascara_coluna_user(seletor, indice_colunas)
	{
		//colocar essa parte na etapa1
		colunasTemp[indice_colunas].mascara = $(seletor).val();
	}
	function alterar_ordenar_coluna_user(seletor, indice_colunas)
	{
		colunasTemp[indice_colunas].ordenar = $(seletor).val();
	}
		
</script>
