}
private void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final ItemEstrtIndResultLocalIettirlDao dao = new ItemEstrtIndResultLocalIettirlDao(request);
final DecimalFormat formatBrasil = new DecimalFormat ("#,##0.##########", new DecimalFormatSymbols (new Locale ("pt", "BR")));
try{
StringBuilder responseHTML = new StringBuilder();
Long paramGrupo = Pagina.getParamLong(request, "grupo");
Long codIettir = Pagina.getParamLong(request, "codIettir");
Long codIett = Pagina.getParamLong(request, "codIett");
Long itemSelecionado = Pagina.getParamLong(request, "itemSelecionado");
final LocalItemDao daoItem = new LocalItemDao(request);
final ExercicioDao exercicioDao = new ExercicioDao(request);
List localList = daoItem.getLocalItemPorLocalGrupo(paramGrupo);
List listaExercicios = exercicioDao.getExerciciosValidos(Long.valueOf( codIett ));
ItemEstruturaDao itemDao = new ItemEstruturaDao(request);
ItemEstruturaIett item = (ItemEstruturaIett)itemDao.buscar(ItemEstruturaIett.class, Long.valueOf( codIett ));
List locaisItem = new ArrayList(item.getItemEstrutLocalIettls());
LocalGrupoLgp localGrupoItem = ((ItemEstrutLocalIettl)locaisItem.get(0)).getLocalItemLit().getLocalGrupoLgp();
// Se a lista de locais n�o estiver vazia
if (!localList.isEmpty() && !localList.isEmpty()){
final int larguraLocal = 250;
final int larguraCampo = 150;
final int larguraTotal = 200;
final int cont=listaExercicios.size();
final int larguraCaixaTexto;
if (80 / cont > 15) {
larguraCaixaTexto = 15;
}
else{
larguraCaixaTexto = (80 / cont );
}
// Criando a tabela
responseHTML.append( "<table width=" + (larguraLocal + cont*larguraCampo + larguraTotal) + "class='layoutFixo' bgcolor='#EAEEF4' style='table-layout: fixed; text-align: left; margin-left: auto; margin-right: auto;' border='0' cellpadding='0' cellspacing='0' > ");
// Inserindo a checkbox superior
responseHTML.append( " <tr> ");
responseHTML.append( " <td colspan=" + (cont + 2) + "valign='top' height='25px'> ");
responseHTML.append( " <input type='checkbox' name='copiarQtde1' id='copiarQtde1' value='true' onchange='checkboxSincroniza(\"copiarQtde1\",\"copiarQtde2\");' > Copiar Quantidade(s) para o(s) exerc�cio(s) posterior(es)? ");
responseHTML.append( " <label ");
responseHTML.append( " id=\"label|-1|-1\"");
responseHTML.append( " class=\"dica\" ");
responseHTML.append( " onmouseover=\"" );
responseHTML.append( " montaTooltipMouseOver(this,\'-1\', \'\', \'-1\', \'\');" );
responseHTML.append( " \"" );
responseHTML.append( " onmouseout=\"" );
responseHTML.append( " montaTooltipMouseOut(\'-1\', \'-1\');" );
responseHTML.append( " \"" );
responseHTML.append( " />" );
responseHTML.append( " <img " );
responseHTML.append( " src=\"" + request.getContextPath() + "/images/dica.png\" " );
responseHTML.append( " align=\"absmiddle\" " );
responseHTML.append( " border=\"0\" " );
responseHTML.append( " onclick=\"" );
responseHTML.append( " montaTooltipMouseClick(\'-1\', \'\', \'-1\', \'\');" );
responseHTML.append( " \" " );
responseHTML.append( " /> " );
responseHTML.append( " " );
responseHTML.append( " <span id=\"span|-1|-1\" ></span>" );
responseHTML.append( " " );
responseHTML.append( " </label>" );
responseHTML.append( " </td> ");
responseHTML.append( " </tr> ");
// Inserindo o t�tulo Exerc�cio
responseHTML.append( " <tr> ");
responseHTML.append( " <td width=" + larguraLocal + " style='font-size: 14px;color: #003366;font-weight: bold;' align='center' > </td>");
responseHTML.append( " <td colspan=\"" + (cont + 1) + "\" style=\"font-size: 14px;color: #003366;font-weight: bold;\" align=\"center\" >Exercicio</td>");
responseHTML.append( " </tr> ");
// Inserindo os t�tulos Local, exerc�cios e Total por Local
responseHTML.append( " <tr> ");
responseHTML.append( " <td width=" + larguraLocal + " style='font-size: 14px;color: #003366;font-weight: bold;' align='center' >Local</td> ");
for (Iterator iterator = listaExercicios.iterator(); iterator.hasNext();) {
ExercicioExe exe = (ExercicioExe) iterator.next();
responseHTML.append( " <td width=" + larguraCampo + " style=\"font-size: 14px;color: #003366;font-weight: bold;\" align=\"center\" > ");
responseHTML.append(exe.getDescricaoExe().toUpperCase() );
responseHTML.append( " </td> ");
}
responseHTML.append( " <td width=" + larguraTotal + " style='font-size: 14px;color: #003366;font-weight: bold;' align='center' >Total por Local</td> ");
responseHTML.append( " <tr> ");
// Inserindo a caixa de sele��o
Set subgrupo = localGrupoItem.getLocalGrupoHierarquiaLgphsByCodLgpPai();
if ( subgrupo!=null && !subgrupo.isEmpty()){
responseHTML.append( " <tr> ");
responseHTML.append( " <td width=" + larguraLocal + " style='font-size: 12px;color: #003366;' align='left' > ");
responseHTML.append( " <table width='90%'> ");
responseHTML.append( " <tr>" );
responseHTML.append( " <td width='25%' align='right'>" );
responseHTML.append( " <img src='../../images/icon_seta_ident.gif'/>" );
responseHTML.append( " </td>" );
responseHTML.append( " <td width='75%'>" );
responseHTML.append( " <select name='subgrupo' id='subgrupo' onchange='carregarlocal();' > ");
int indice = 1;
responseHTML.append( " <option value=" + localGrupoItem.getCodLgp() + " >Selecione</option> ");
for (Iterator itGrupo = subgrupo.iterator(); itGrupo.hasNext();) {
LocalGrupoLgp grupo = (LocalGrupoLgp) itGrupo.next();
if(indice == itemSelecionado){
responseHTML.append( " <option value='" + grupo.getCodLgp() + "' selected='true'>" + grupo.getIdentificacaoLgp() + "</option>" );
}
else {
responseHTML.append( " <option value='" + grupo.getCodLgp() + "' >" + grupo.getIdentificacaoLgp() + "</option>" );
}
indice++;
}
responseHTML.append( " </select> ");
responseHTML.append( " </td>" );
responseHTML.append( " </tr>" );
responseHTML.append( " </table>" );
responseHTML.append( " </td> ");
responseHTML.append( " <td colspan=" + (cont +1) + "valign='top' height='25px'> </td> ");
responseHTML.append( " </tr> ");
}
// Inserindo o conte�do da tabela
String strTdSeta = null;
String strTdCampo = null;
String strTdTotalPorLocal = null;
Double totalLocal = 0.0;
Double totalExercicio[] = new Double [listaExercicios.size()];
Double totalGeral = 0.0;
int i = 0;
for(i = 0; i < totalExercicio.length; i++){
totalExercicio[i] = 0.0;
}
// Para cada local
for (Iterator iter = localList.iterator(); iter.hasNext();) {
LocalItemLit local = (LocalItemLit) iter.next();
// Criar uma c�lula com a seta e o nome do local
strTdSeta = new String (
"<td align='rigth' width='" + larguraLocal + "' height='25px' valign='top'>" +
" " +
" <table width='100%'> " +
" <tr>" +
" <td width='25%' align='right'>" +
" <img src='../../images/icon_seta_ident.gif'/>" +
" </td>" +
" <td width='75%'>" +
" " + local.getIdentificacaoLit() +
" " +
" </td>" +
" </tr>" +
" </table>" +
"</td>"
);
responseHTML.append("<tr>");
responseHTML.append(strTdSeta);
totalLocal = 0.0;
i = 0;
// Para cada exerc�cio
for (Iterator iterator = listaExercicios.iterator(); iterator.hasNext();) {
ExercicioExe exe = (ExercicioExe) iterator.next();
ItemEstrtIndResulLocalIettirl itemEstrtIndResulLocalIettirl = dao.getQtdePrevistaByLocal( codIettir, exe.getCodExe(), local.getCodLit() );
totalLocal += itemEstrtIndResulLocalIettirl.getQtdPrevistaIettirl().doubleValue();
totalExercicio [i] += itemEstrtIndResulLocalIettirl.getQtdPrevistaIettirl().doubleValue();
i++;