1 package ecar.servlet.componente;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.text.DecimalFormat;
6 import java.text.DecimalFormatSymbols;
7 import java.util.Iterator;
8 import java.util.List;
9 import java.util.Locale;
10
11 import javax.servlet.ServletException;
12 import javax.servlet.http.HttpServlet;
13 import javax.servlet.http.HttpServletRequest;
14 import javax.servlet.http.HttpServletResponse;
15
16 import org.apache.log4j.Logger;
17
18 import comum.util.Pagina;
19
20 import ecar.dao.ExercicioDao;
21 import ecar.dao.ItemEstrtIndResultLocalIettirlDao;
22 import ecar.dao.LocalItemDao;
23 import ecar.pojo.ExercicioExe;
24 import ecar.pojo.ItemEstrtIndResulLocalIettirl;
25 import ecar.pojo.LocalItemLit;
26
27 public class PesquisaLocalHierarquiaServlet extends HttpServlet{
28
29 private static final long serialVersionUID = -693849991527194195L;
30 private Logger logger = Logger.getLogger(this.getClass());
31
32 private final Long CONSTANTE_PERIODO_EXERCICIO = Long.valueOf(2);
33
34 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
35 logger.info("request :: GET:: Classe:: " + this.getClass().getName() );
36 execute(request,response);
37 }
38
39 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
40 logger.info("request :: POST:: Classe:: " + this.getClass().getName() );
41 execute(request,response);
42 }
43
44
45 private void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
46
47 final ItemEstrtIndResultLocalIettirlDao dao = new ItemEstrtIndResultLocalIettirlDao(request);
48 final DecimalFormat formatBrasil = new DecimalFormat ("#,##0.00", new DecimalFormatSymbols (new Locale ("pt", "BR")));
49
50 try{
51 StringBuilder responseHTML = new StringBuilder();
52 Long paramLocal = Pagina.getParamLong(request, "local");
53 Long codIettir = Pagina.getParamLong(request, "codIettir");
54
55 LocalItemDao daoItem = new LocalItemDao(request);
56 final ExercicioDao exercicioDao = new ExercicioDao(request);
57 List listaExercicios = exercicioDao.getExercicioByPeriodicidade( CONSTANTE_PERIODO_EXERCICIO );
58
59 List localList = daoItem.getLocaisFilhos(paramLocal);
60
61 if ( !localList.isEmpty() ){
62 responseHTML.append( "<table align=\"left\" width='100%' border='0' >");
63 for (Iterator iter = localList.iterator(); iter.hasNext();) {
64 responseHTML.append( "<tr>");
65 LocalItemLit local = (LocalItemLit) iter.next();
66 responseHTML.append("<td width='30%' align='left' height='25px' valign='top' > ");
67 responseHTML.append("<img src='../../images/icon_seta_ident.gif'/> ");
68 responseHTML.append( local.getIdentificacaoLit() +"</td>");
69
70 for (Iterator iterator = listaExercicios.iterator(); iterator.hasNext();) {
71 ExercicioExe exe = (ExercicioExe) iterator.next();
72
73 ItemEstrtIndResulLocalIettirl item = dao.getQtdePrevistaByLocal( codIettir, exe.getCodExe(), local.getCodLit() );
74
75 responseHTML.append( "<td width='14%' align=\"center\" >");
76 responseHTML.append( "<input type=\"text\" onblur=\"calcularTotalLocal('" );
77 responseHTML.append( local.getCodLit().toString() );
78 responseHTML.append( "');calcularTotalExercicio('"+exe.getCodExe().toString()+"');\" onmouseover=\"calcularTotalExercicio('"+exe.getCodExe().toString()+"');calcularTotalLocal('" +local.getCodLit().toString() + "');\" " );
79 responseHTML.append( " id=\"" );
80 responseHTML.append( "cmp|" + local.getCodLit().toString() + "|" + exe.getCodExe().toString() );
81 responseHTML.append( "\" name=\"" );
82 responseHTML.append( "cmp|" + local.getCodLit().toString() + "|" + exe.getCodExe().toString() );
83 responseHTML.append( "\" value=\"" + formatBrasil.format(item.getQtdPrevistaIettirl().doubleValue()) + "\"" );
84 responseHTML.append( "\" />" );
85
86 responseHTML.append( "<label class=\"dica\" onmouseover=\"montaTooltipMouseOver(this,\'"+ exe.getCodExe().toString() + "\',\'" + exe.getDescricaoExe() +"\',\'"+ local.getCodLit().toString() + "\',\'" + local.getIdentificacaoLit() +"\');\" onmouseout=\"montaTooltipMouseOut(\'"+ exe.getCodExe().toString() + "\',\'" + local.getCodLit().toString() +"\');\" >" );
87 responseHTML.append( "<img src=\"" + request.getContextPath() + "/images/dica.png\" align=\"absmiddle\" border=\"0\" onclick=\"montaTooltipMouseClick(\'"+ exe.getCodExe().toString() + "\',\'" + exe.getDescricaoExe() +"\',\'"+ local.getCodLit().toString() + "\',\'" + local.getIdentificacaoLit() +"\');\" > " );
88 responseHTML.append( "<span id=\"" + local.getCodLit().toString() + "|" + exe.getCodExe().toString() + "\" ></span></label>" );
89 responseHTML.append( "</td>");
90
91 }
92
93 responseHTML.append( "<td width='14%' align=\"center\" >");
94 responseHTML.append( "<input type=\"text\" id=\"" );
95 responseHTML.append( "cmp|" + local.getCodLit().toString() + "|total");
96 responseHTML.append( "\" name=\"" );
97 responseHTML.append( "cmp|" + local.getCodLit().toString() + "|total");
98 responseHTML.append( "\" value=\"0,00\" />" );
99 responseHTML.append( "</td>");
100
101 responseHTML.append( "</tr>");
102
103 }
104 responseHTML.append("</table>");
105 }else{
106 responseHTML.append("Nenhum registro encontrado");
107 }
108
109 responseToHTML(response, responseHTML.toString());
110
111 }catch(Exception e){
112 StringBuilder responseHTML = new StringBuilder();
113 responseHTML.append("Nenhum registro encontrado");
114 responseToHTML(response, responseHTML.toString());
115 }
116
117 }
118
119 private void responseToHTML ( HttpServletResponse response, String conteudo ) throws IOException {
120 response.setContentType("text/html");
121 PrintWriter writer = response.getWriter();
122 writer.append(conteudo);
123 writer.flush();
124 writer.close();
125 }
126 }