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.ArrayList;
8 import java.util.Collections;
9 import java.util.Comparator;
10 import java.util.Iterator;
11 import java.util.List;
12 import java.util.Locale;
13 import java.util.Set;
14
15 import javax.servlet.ServletException;
16 import javax.servlet.http.HttpServlet;
17 import javax.servlet.http.HttpServletRequest;
18 import javax.servlet.http.HttpServletResponse;
19
20 import org.apache.log4j.Logger;
21
22 import comum.util.Pagina;
23
24 import ecar.dao.AcompRealFisicoDao;
25 import ecar.dao.AcompRealFisicoLocalDao;
26 import ecar.dao.ItemEstruturaDao;
27 import ecar.dao.LocalItemDao;
28 import ecar.pojo.AcompRealFisicoArf;
29 import ecar.pojo.AcompRealFisicoLocalArfl;
30 import ecar.pojo.ItemEstrutLocalIettl;
31 import ecar.pojo.ItemEstruturaIett;
32 import ecar.pojo.LocalGrupoLgp;
33 import ecar.pojo.LocalItemLit;
34
35 public class PesquisaRealizadoFisicoPorLocalServlet extends HttpServlet{
36
37 private static final long serialVersionUID = 2244076567158750862L;
38 private Logger logger = Logger.getLogger(this.getClass());
39
40
41
42
43 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
44
45 execute(request,response);
46 }
47
48 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
49
50 execute(request,response);
51
52 }
53
54
55 private void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
56
57 final DecimalFormat formatBrasil = new DecimalFormat ("#,##0.00", new DecimalFormatSymbols (new Locale ("pt", "BR")));
58
59 try{
60 StringBuilder responseHTML = new StringBuilder();
61 String strTdSeta = null;
62 String strTdCampo = null;
63
64 responseHTML.append( "<table width='100%' id='indicadores' class='locais' > ");
65
66 AcompRealFisicoDao acompRealFisicoDao = new AcompRealFisicoDao(request);
67 Long codARFLong = Long.valueOf(Pagina.getParamStr(request, "codARF"));
68 Long paramGrupo = null;
69
70 if (!Pagina.getParamStr(request, "grupo").equals(""))
71 paramGrupo = Long.valueOf(Pagina.getParamStr(request, "grupo"));
72
73 String podeGravar = String.valueOf(Pagina.getParamStr(request, "podeGravar"));
74 String statusAlteracao = new String("false");
75
76 final LocalItemDao daoItem = new LocalItemDao(request);
77
78 List localList = daoItem.getLocalItemPorLocalGrupo(paramGrupo);
79 ItemEstruturaDao itemDao = new ItemEstruturaDao(request);
80
81 AcompRealFisicoArf arf = (AcompRealFisicoArf) acompRealFisicoDao.buscar(AcompRealFisicoArf.class, codARFLong);
82 ItemEstruturaIett item = arf.getItemEstruturaIett();
83
84 List locaisItem = new ArrayList(item.getItemEstrutLocalIettls());
85
86
87 if (locaisItem.isEmpty()){
88 responseHTML.append( "<tr> ");
89 responseHTML.append( " </td colspan='2'> ");
90 responseHTML.append( " Nenhum local foi encontrado para esse item.");
91 responseHTML.append( " </td> ");
92 responseHTML.append( "</tr> ");
93
94 } else {
95 LocalGrupoLgp localGrupoItem = ((ItemEstrutLocalIettl)locaisItem.get(0)).getLocalItemLit().getLocalGrupoLgp();
96
97
98
99 responseHTML.append("<tr>");
100
101
102 strTdSeta = new String (
103 "<td align='rigth' width='50%' height='45px' valign='center'>" +
104 " <table width='100%' valign='left' border='0'> " +
105 " <tr>" +
106 " <td width='10%' id='indicadores' class='locais' align='left'>" +
107 " <img src='../../images/icon_seta_ident.gif'/>" +
108 " </td>" +
109 " <td width='90%' id='indicadores' class='locais' >" +
110 " " + ((ItemEstrutLocalIettl)locaisItem.get(0)).getLocalItemLit().getLocalGrupoLgp().getIdentificacaoLgp() +
111 " " +
112 " </td>" +
113 " </tr>" +
114 " </table>" +
115 "</td>"
116 );
117 responseHTML.append(strTdSeta);
118 responseHTML.append( " <td width='50%' height='45px' id='indicadores' class='locais' align='center' > ");
119 responseHTML.append( " " + arf.getMesArf().toString() + "/" + arf.getAnoArf().toString());
120 responseHTML.append( " </td> ");
121 responseHTML.append( " </tr> ");
122
123
124 if (localList!= null && !localList.isEmpty()){
125
126
127 responseHTML.append( " <tr> ");
128 responseHTML.append( " <td width='50%' id='indicadores' class='locaisDesc' align='left' > ");
129 Set subgrupo = localGrupoItem.getLocalGrupoHierarquiaLgphsByCodLgpPai();
130 if ( subgrupo!=null && !subgrupo.isEmpty()){
131
132 responseHTML.append( " <table width='90%'> ");
133 responseHTML.append( " <tr>" );
134 responseHTML.append( " <td width='15%' align='right'>" );
135 responseHTML.append( " <img src='../../images/icon_seta_ident.gif'/>" );
136 responseHTML.append( " </td>" );
137 responseHTML.append( " <td width='85%'>" );
138 responseHTML.append( " <select name='subgrupo' id='subgrupo' onchange='carregarlocal();' > ");
139 int indice = 1;
140 responseHTML.append( " <option value=" + localGrupoItem.getCodLgp() + " >"+ localGrupoItem.getIdentificacaoLgp() +"</option> ");
141 int itemSelecionado = Pagina.getParamInt(request, "itemSelecionado");
142 for (Iterator itGrupo = subgrupo.iterator(); itGrupo.hasNext();) {
143 LocalGrupoLgp grupo = (LocalGrupoLgp) itGrupo.next();
144 if(indice == itemSelecionado){
145 responseHTML.append( " <option value='" + grupo.getCodLgp() + "' selected='true'>" + grupo.getIdentificacaoLgp() + "</option>" );
146 }
147 else {
148 responseHTML.append( " <option value='" + grupo.getCodLgp() + "' >" + grupo.getIdentificacaoLgp() + "</option>" );
149 }
150 indice++;
151 }
152 responseHTML.append( " </select> ");
153 } else {
154 responseHTML.append( " <input type=\"hidden\" name=\"subgrupo\" id=\"subgrupo\" value=\""+ localGrupoItem.getCodLgp() +"\" > ");
155 }
156 responseHTML.append( " </td>" );
157 responseHTML.append( " </tr>" );
158 responseHTML.append( " </table>" );
159 responseHTML.append( " </td> ");
160 responseHTML.append( " <td width='50%' valign='top' height='25px'> ");
161 responseHTML.append( " </td> ");
162 responseHTML.append( " </tr> ");
163
164
165
166 List listaLocais = new ArrayList(arf.getAcompRealFisicoLocalArfls());
167 Collections.sort(listaLocais, new Comparator(){
168 public int compare(Object arg1, Object arg2){
169 return ((AcompRealFisicoLocalArfl) arg1).getLocalItemLit().getIdentificacaoLit().compareTo(((AcompRealFisicoLocalArfl) arg2).getLocalItemLit().getIdentificacaoLit());
170 }
171 });
172
173 AcompRealFisicoLocalDao arflDAO = new AcompRealFisicoLocalDao(request);
174
175 for (Iterator iterator = localList.iterator(); iterator.hasNext();) {
176
177 LocalItemLit local = (LocalItemLit) iterator.next();
178 AcompRealFisicoLocalArfl arfl = arflDAO.getAcompRealFisicoLocalByLocal(arf, local);
179 if (arfl.getQuantidadeArfl() == null){
180 arfl.setQuantidadeArfl(0.0);
181 }
182
183
184 responseHTML.append("<tr>");
185
186
187 strTdSeta = new String (
188 "<td align='rigth' width='50%' height='30px' valign='center'>" +
189 " <table width='100%' valign='center'> " +
190 " <tr>" +
191 " <td width='25%' align='right'>" +
192 " <img src='../../images/icon_seta_ident.gif'/>" +
193 " </td>" +
194 " <td width='75%'>" +
195 " " + local.getIdentificacaoLit() +
196 " " +
197 " </td>" +
198 " </tr>" +
199 " </table>" +
200 "</td>"
201 );
202 responseHTML.append(strTdSeta);
203
204
205 if (podeGravar.equals("S")){
206 statusAlteracao = "true";
207 }
208 else{
209 statusAlteracao = "false";
210 }
211
212 strTdCampo = new String (
213 "<td width=\"50%\" align=\"center\" valign=\"center\">" +
214 " <input " +
215 " type=\"text\"" +
216 " size=\"13\"" +
217 " onblur=\"" +
218 " calcularTotal();" +
219 " \"" +
220 " id=\"cmp|" + local.getCodLit().toString() + "\"" +
221 " name=\"cmp|" + local.getCodLit().toString() + "\"" +
222 " value=\"" + formatBrasil.format( arfl.getQuantidadeArfl()) + "\"" +
223
224 " />" +
225 " " +
226 " <label " +
227 " id=\"label|" + local.getCodLit().toString() + "\"" +
228 " class=\"dica\" " +
229 " onmouseover=\"" +
230 " montaTooltipMouseOver(this,\'"+ arf.getMesArf().toString() + "/" + arf.getAnoArf().toString() + "\', \'" + local.getCodLit().toString() + "\',\'" + local.getIdentificacaoLit() + "\');" +
231 " \"" +
232 " onmouseout=\"" +
233 " montaTooltipMouseOut(\'"+ local.getCodLit().toString() + "\');" +
234 " \"" +
235 " />" +
236 " <img " +
237 " src=\"" + request.getContextPath() + "/images/dica.png\" " +
238 " align=\"absmiddle\" " +
239 " border=\"0\" " +
240 " onclick=\"" +
241 " montaTooltipMouseClick(\'" + arf.getMesArf().toString() + "/" + arf.getAnoArf().toString() + "\',\'"+ local.getCodLit().toString() + "\',\'" + local.getIdentificacaoLit() + "\');" +
242 " \" " +
243 " /> " +
244 " " +
245 " <span id=\"spanLocal|" + local.getCodLit().toString() + "\" ></span>" +
246 " " +
247 " </label>" +
248 "</td>"
249 );
250 responseHTML.append(strTdCampo);
251 responseHTML.append( "</tr> ");
252
253 }
254 responseHTML.append( " <tr> ");
255 responseHTML.append( " <td width='50%' height='45px' id='indicadores' class='locais' align='center' > ");
256 responseHTML.append( " Total por Período" );
257 responseHTML.append( " </td> ");
258 responseHTML.append( " <td width='50%' height='45px' id='indicadores' class='locais' align='center' > ");
259 if(arf.getQtdRealizadaArf() == null) {
260 responseHTML.append( " <input type='text' name='total' id='total' class=\"total\" readOnly='true' size='15' value='" + formatBrasil.format( new Double(0.0)) + "'>" );
261 } else {
262 responseHTML.append( " <input type='text' name='total' id='total' class=\"total\" readOnly='true' size='15' value='" + formatBrasil.format( arf.getQtdRealizadaArf()) + "'>" );
263 }
264 responseHTML.append( " </td> ");
265 responseHTML.append( " </tr> ");
266 }
267 else{
268 responseHTML.append( "<tr> ");
269 responseHTML.append( " </td colspan='2'> ");
270 responseHTML.append( " Nenhum local foi encontrado para esse grupo!");
271 responseHTML.append( " </td> ");
272 responseHTML.append( "</tr> ");
273 }
274 }
275 responseHTML.append( "</table> ");
276 responseToHTML(response, responseHTML.toString());
277
278 }catch(Exception e){
279 throw new ServletException(e);
280 }
281 }
282
283
284 private void responseToHTML ( HttpServletResponse response, String conteudo ) throws IOException {
285 response.setContentType("text/html");
286 PrintWriter writer = response.getWriter();
287 writer.append(conteudo);
288 writer.flush();
289 writer.close();
290 }
291
292
293 }