/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.siso.asistenciaAniversario.Servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import pe.siso.asistenciaAniversario.Beans.Asistencia;
import pe.siso.asistenciaAniversario.Beans.Conteo;
import pe.siso.asistenciaAniversario.Services.AsistenciaServices;
import pe.siso.asistenciaAniversario.Services.ConteoServices;

/**
 *
 * @author fcelestino
 */
public class ServletAsistencia extends HttpServlet {

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String param = request.getParameter("accion");
		if ("consultarAsistencia".equals(param)) {
			consultarAsistencia(request, response);
		} else if ("mostrarAsistencia".equals(param)) {
			mostrarAsistencia(request, response);
		} else if ("registrarAlimento".equals(param)) {
			registrarAlimento(request, response);
		} else if ("consultarReporte".equals(param)) {
			consultarReporte(request, response);
		} else if ("quitarAsistencia".equals(param)) {
			quitarAsistencia(request, response);
		} else if ("quitarAlimentacion".equals(param)) {
			quitarAlimentacion(request, response);
		} else if ("listarReporteGeneral".equals(param)) {
			listarReporteGeneral(request, response);
		} else if ("verReportes".equals(param)) {
			verReportes(request, response);
		} else if ("AsistenciaPorComision".equals(param)) {
			AsistenciaPorComision(request, response);
		} else if ("AlimentacionPorComision".equals(param)) {
			AlimentacionPorComision(request, response);
		} else if ("AsistenciaPorComisionImp".equals(param)) {
			AsistenciaPorComisionImp(request, response);
		} else if ("AlimentacionPorComisionImp".equals(param)) {
			AlimentacionPorComisionImp(request, response);
		} else if ("extras".equals(param)) {
			extras(request, response);
		} else if ("registrarExtras".equals(param)) {
			registrarExtras(request, response);
		} else if ("reporteExtrasAlimentacion".equals(param)) {
			reporteExtrasAlimentacion(request, response);
		} else if ("reporteExtrasAlimentacionImp".equals(param)) {
			reporteExtrasAlimentacionImp(request, response);
		} else if ("filtroPersonalReg".equals(param)) {
			filtroPersonalReg(request, response);
		}
	}

	private void consultarAsistencia(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String busqueda = request.getParameter("busqueda").toUpperCase();
		AsistenciaServices servicos = new AsistenciaServices();
		ArrayList<Asistencia> lista = new ArrayList<Asistencia>();
		lista = servicos.consultarExistencia(busqueda);
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		if (lista.size() == 0) {
			pw.println("NO EXISTE PERSONAL CON ESOS DATOS"
				+ "<script>setTimeout('refrescar();',3000)</script>");
		} else {
			if (lista.size() > 1) {

				pw.println("<div style=\"border: 1px solid #CCCCCC; font-size:12px; \">"
					+ "                       <div class=\"table-header\">Listado de colaboradores"
					+ "                       </div>"
					+ "                       <div>"
					+ "                           <div class=\"dataTables_wrapper form-inline no-footer\" id=\"sample-table-2_wrapper\">"
					+ "                               <table class=\"table table-striped table-bordered table-hover dataTable no-footer\" id=\"sample-table-2\" role=\"grid\" aria-describedby=\"sample-table-2_info\" >"
					+ "                                   <thead>"
					+ "                                       <tr role=\"row\">"
					+ "                                           <th width='30' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\" >N°</th>"
					//					+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">CÓDIGO</th>" +
					+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">APELLIDOS Y NOMBRES</th>"
					+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">DNI</th>"
					+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">CANTIDAD DE NIÑOS</th>"
					+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">ACCIÓN</th>"
					+ "                                       </tr>"
					+ "                                   </thead>"
					+ "                                   <tbody>");
				for (int i = 0; i < lista.size(); i++) {
					int cont = i + 1;
					String codPerAsi = lista.get(i).getCodigoPersonal();
					String apellido = lista.get(i).getApellidos();
					Asistencia estados = new Asistencia();
					estados = servicos.consultarEstadosAsistencia(codPerAsi);
					String apellidoSelect = apellido.replaceAll(busqueda, "<span style='background-color:#F0C869;'><b>" + busqueda + "</b></span>");
					pw.println("<tr>");
					pw.println("<td align='center' style='vertical-align:middle'>" + cont + "</td>");
//                    pw.println("<td>"+lista.get(i).getCodigoPersonal()+"</td>");
					pw.println("<td style='vertical-align:middle'>" + apellidoSelect + ", " + lista.get(i).getNombres() + "</td>");
					pw.println("<td align='center' style='vertical-align:middle'>" + lista.get(i).getDni() + "</td>");
					pw.println("<td align='center' style='vertical-align:middle'>" + lista.get(i).getCantidadNinios() + "</td>");
					pw.println("<td align='center' style='vertical-align:middle'>");
					if (estados.getEstadoAsistencia() == null) {
						pw.println("     <button class=\"btn btn-white btn-success btn-sm\" type=\"button\" onclick=\"resgistrarAsistencia(" + codPerAsi + ")\">Registrar</button>");
					} else {
						if (estados.getEstadoAsistencia().equals("1")) {
							pw.println("<a href='javascript:resgistrarAsistencia(" + codPerAsi + ")' onmouseover=\"this.style.cssText='color:red; text-decoration:none;'\"    onmouseout=\"this.style.cssText='color:#428BCA;'\"  title='Ver marcación'>REGISTRADO</a>");
						} else {
							pw.println("     <button class=\"btn btn-white btn-success btn-sm\" type=\"button\" onclick=\"resgistrarAsistencia(" + codPerAsi + ")\">Registrar</button>");
						}
					}
					pw.println("</td>");
					pw.println("<tr>");
				}
				pw.println("            </tbody>"
					+ "         <table>"
					+ "     </div>"
					+ " </div>"
					+ "</div>");
			} else {
				//REGISTRAR ASISTENCIA
				for (int i = 0; i < lista.size(); i++) {
					String codPer = lista.get(i).getCodigoPersonal();
					String apellidos = lista.get(i).getApellidos();
					String nombres = lista.get(i).getNombres();
					String ninios = lista.get(i).getCantidadNinios();
					int dato = servicos.registrarAsistencia(codPer);
					if (dato == 1) {
						Asistencia datosAsis = new Asistencia();
						datosAsis = servicos.consultarEstadosAsistencia(codPer);
						String codAsis = datosAsis.getCodigoAsistencia();
						String marcaion = datosAsis.getHoraMarcacion();
						String alimentacion = datosAsis.getEstadoAlimentacion();
						pw.println("<script>verAsistencia( " + codAsis + ", " + codPer + ",'  " + marcaion + " '," + alimentacion + ",' " + apellidos + " ',' " + nombres + " '  , '" + ninios + "');</script>");
					}
				}
			}
		}
	}

	private void mostrarAsistencia(HttpServletRequest request, HttpServletResponse response) throws IOException {
		AsistenciaServices servicios = new AsistenciaServices();
		String codAsis = request.getParameter("codAsis");
		String codper = request.getParameter("codper");
		String marcacion = request.getParameter("marcacion");
		String alimentacion = request.getParameter("alimentacion");
		String apellidos = request.getParameter("apellidos");
		String nombres = request.getParameter("nombres");
		String ninios = request.getParameter("ninios");
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		String regalos = "";
		if (Integer.parseInt(ninios) > 0) {
			for (int i = 0; i < Integer.parseInt(ninios); i++) {
				regalos += "&nbsp; <img src='imagenes/caja-de-regalo.png' alt=REGALO' style='width:30px' >";
			}
		} else {
			regalos = " [NO TIENE]";
		}

		pw.println("<table border='0' style='width: 100%; font-size: 16px; color: #4F4D4D;'>"
			+ "                       <tr>"
			+ "                           <td colspan='2'>"
			+ "                               <input id='estAli' type='hidden' value='-1'>"
			+ "                               <i class='ace-icon fa fa-user bigger-140'></i> "
			+ "                               <b style=' color:#37729F;'>COLABORADOR: </b> " + apellidos + ", " + nombres + " "
			+ "                           </td>"
			+ "                       </tr>"
			+ "                       <tr>"
			+ "                           <td colspan='2' style='height: 10px'></td>"
			+ "                       </tr>"
			+ "                       <tr>"
			+ "                           <td>"
			+ "                               <i class='ace-icon fa fa-clock-o bigger-140'></i> "
			+ "                               <b style='color:#37729F;'>HORARIO DE MARCACIÓN: </b> <b style='color:red;'>" + marcacion + "</b> "
			+ "                           </td>"
			+ "                           <td>"
			+ "                               <i class='ace-icon fa fa-group bigger-140'></i> "
			+ "                               <b style='color:#37729F;'>NIÑOS: </b> " + ninios
			+ "                           </td>"
			+ "                       </tr>"
			+ "                       <tr>"
			+ "                           <td colspan='2' style='height: 5px'>"
			+ "                               <h6 class='header blue lighter'></h6>"
			+ "                           </td>"
			+ "                       </tr>");

		pw.println(
			"                       <tr>"
			+ "                           <td colspan='2' style='height: 10px'></td>"
			+ "                       </tr>"
			+ "                       <tr>"
			+ "                           <td style='vertical-align:middle;'>"
			+ "                               <i class='ace-icon fa fa-asterisk bigger-140'></i> "
			+ "                               <b style='color:#37729F;'>REGALOS: </b>   " + regalos
			+ "                           </td>"
			+ "                           <td style='text-align: right'>");

		if (Integer.parseInt(ninios) > 0) {
			if (alimentacion.equals("1")) {
				pw.println("<span style='color:green'>[ENTREGADO]</span>");
			} else {
				pw.println("<button class=\"btn btn-xs btn-primary\" id='boton' onClick='registrarAlimento(" + codAsis + "," + codper + ");'>  "
					+ "    <i class=\"ace-icon fa fa-cutlery bigger-110\"></i>ENTREGAR  "
					+ "</button>");
			}
		}

		pw.println("                </td>"
			+ "                       </tr>"
			+ "                   </table>");

	}

	private void registrarAlimento(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String codAsis = request.getParameter("codAsis");
		String codper = request.getParameter("codper");
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		AsistenciaServices servicios = new AsistenciaServices();
		int dato = servicios.registrarEntragaAlimentacion(codAsis);
		pw.println(dato);
	}

	private void consultarReporte(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String busqueda = request.getParameter("busqueda").toUpperCase();
		AsistenciaServices servicos = new AsistenciaServices();
		ArrayList<Asistencia> lista = new ArrayList<Asistencia>();
		lista = servicos.consultarExistencia(busqueda);
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		if (lista.size() == 0) {
			pw.println("NO EXISTE PERSONAL CON ESOS DATOS"
				+ "<script>setTimeout('refrescar();',3000)</script>");
		} else {

			pw.println("<center><h3>REPORTE DE ASISTENCIA Y ALIMENTACIÓN</h3></center>"
				+ "<div style=\"border: 1px solid #CCCCCC; font-size:12px; \">"
				+ "                       <div class=\"table-header\">Listado de colaboradores"
				+ "                       </div>"
				+ "                       <div>"
				+ "                           <div class=\"dataTables_wrapper form-inline no-footer\" id=\"sample-table-2_wrapper\">"
				+ "                               <table class=\"table table-striped table-bordered table-hover dataTable no-footer\" id=\"sample-table-2\" role=\"grid\" aria-describedby=\"sample-table-2_info\" >"
				+ "                                   <thead>"
				+ "                                       <tr role=\"row\">"
				+ "                                           <th width='30' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\" >N°</th>"
				+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">APELLIDOS Y NOMBRES</th>"
				+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"2\">MARCACIÓN</th>"
				+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"3\">REGALO(S)</th>"
				+ "                                       </tr>"
				+ "                                   </thead>"
				+ "                                   <tbody>");

			for (int i = 0; i < lista.size(); i++) {
				int cont = i + 1;
				String codPerAsi = lista.get(i).getCodigoPersonal();
				String apellido = lista.get(i).getApellidos();
				Asistencia estados = new Asistencia();
				estados = servicos.consultarEstadosAsistencia(codPerAsi);
				String codAsis = estados.getCodigoAsistencia();
				String apellidoSelect = apellido.replaceAll(busqueda, "<span style='background-color:yellow;'><b>" + busqueda + "</b></span>");

				if (estados.getHoraMarcacion() != null) {
					if (estados.getEstadoAlimentacion().equals("0")) {
						pw.println("<tr style='background-color:#FFFF99; height:35px;'>");
					} else {
						pw.println("<tr style='height:35px;'>");
					}
				} else {
					pw.println("<tr style='height:35px;'>");
				}
				pw.println("<td align='center' style='vertical-align:middle'>" + cont + "</td>");
				pw.println("<td style='vertical-align:middle'>" + apellidoSelect + ", " + lista.get(i).getNombres() + "</td>");

				if (estados.getHoraMarcacion() != null) {
					pw.println("<td align='center' style='vertical-align:middle'>");
					pw.println(estados.getHoraMarcacion());
					pw.println("</td>");
					pw.println("<td align='center' style='vertical-align:middle'>");
					pw.println("<a href='javascript:popup_quitarAsis(" + codAsis + ",\"" + busqueda + "\");' title='Quitar marcación'><i class='fa fa-times red bigger-200 '></i></a>");
					pw.println("</td>");
				} else {
					pw.println("<td colspan='2' align='center' style='vertical-align:middle'>");
					pw.println("SIN MARCACIÓN");
					pw.println("</td>");
				}
				if (estados.getHoraMarcacion() != null) {
					if (estados.getEstadoAlimentacion().equals("1")) {
						pw.println("<td align='center' style='vertical-align:middle'>");
						pw.println(" " + lista.get(i).getCantidadNinios() + " NIÑOS(S) ");
						pw.println("</td>");
						pw.println("<td align='center' style='vertical-align:middle'>");
						pw.println("ENTREGADO");
						pw.println("</td>");
						pw.println("<td align='center' style='vertical-align:middle'>");
						pw.println("<a href='javascript:popup_quitarAlim(" + codAsis + ",\"" + busqueda + "\");' title='Quitar alimentación'><i class='fa fa-times red bigger-200 '></i></a>");
						pw.println("</td>");
					} else {
						pw.println("<td align='center' style='vertical-align:middle'>");
						pw.println(" " + lista.get(i).getCantidadNinios() + " NIÑOS(S) ");
						pw.println("</td>");
						pw.println("<td colspan='2' align='center' style='vertical-align:middle'>");
						pw.println("SIN ENTREGAR");
						pw.println("</td>");
					}
				} else {
					pw.println("<td align='center' style='vertical-align:middle'>");
					pw.println(" " + lista.get(i).getCantidadNinios() + " NIÑOS(S) ");
					pw.println("</td>");
					pw.println("<td colspan='2' align='center' style='vertical-align:middle'>");
					pw.println("SIN ENTREGAR");
					pw.println("</td>");
				}
				pw.println("<tr>");
			}
			pw.println("            </tbody>"
				+ "         <table>"
				+ "     </div>"
				+ " </div>"
				+ "</div>"
				+ "<br>");
		}
	}

	private void quitarAsistencia(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String codAsis = request.getParameter("codAsis");
		AsistenciaServices servicos = new AsistenciaServices();
		int dato = servicos.quitarAsistencia(codAsis);
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		pw.println(dato);
	}

	private void quitarAlimentacion(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String codAsis = request.getParameter("codAsis");
		AsistenciaServices servicos = new AsistenciaServices();
		int dato = servicos.quitarAlimentacion(codAsis);
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		pw.println(dato);
	}

	private void listarReporteGeneral(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String busqueda = request.getParameter("busqueda").toUpperCase();
		int pagina = Integer.parseInt(request.getParameter("pagina"));
		int cantidad = Integer.parseInt(request.getParameter("cantidad"));

		int inicio = (pagina - 1) * cantidad;
		int cantRegistro = 0;

		AsistenciaServices servicos = new AsistenciaServices();
		ArrayList<Asistencia> lista = new ArrayList<Asistencia>();
		lista = servicos.consultarExistenciaAsistencia(busqueda, inicio, cantidad);
		cantRegistro = servicos.cantidadExistenciaAsistencia(busqueda);

		//--------------CALCULO DE PAGINADO---------
		int numero = cantRegistro / cantidad;
		int resto = cantRegistro % cantidad;
		if (resto > 0) {
			numero = numero + 1;
		}

		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		if (lista.size() == 0) {
			pw.println("NO HAY PERSONAL CON ASISTENCIA PARA ESTE DÍA HASTA EL MOMENTO");
		} else {

			pw.println("<!--<center><h3>REPORTE GENERAL</h3></center>-->"
				+ "<div style=\"border: 1px solid #CCCCCC; font-size:12px; \">"
				+ "                       <div class=\"table-header\">Listado de colaboradores"
				+ "                       </div>"
				+ "                       <div>"
				+ "                           <div class=\"dataTables_wrapper form-inline no-footer\" id=\"sample-table-2_wrapper\">"
				+ "                               <table class=\"table table-striped table-bordered table-hover dataTable no-footer\" id=\"sample-table-2\" role=\"grid\" aria-describedby=\"sample-table-2_info\" >"
				+ "                                   <thead>"
				+ "                                       <tr role=\"row\">"
				+ "                                           <th width='30' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\" >N°</th>"
				+ //"                                         <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">CÓDIGO</th>" +
				"                                           <th tabindex=\"0\"  rowspan=\"1\" colspan=\"1\">"
				+ "                     <span id=\"ap\"> APELLIDOS Y NOMBRES </span>"
				+ "                     <span class=\"action-buttons\"> "
				+ "                         <a href='javascript:busquedaPersonal()'>"
				+ "                             <i title=\"Buscar por apellidos y/o nombres\" class=\"ace-icon fa fa-search icon-on-right bigger-130 blue\"></i>"
				+ "                         </a>"
				+ "                         <a href=\"javascript:restaurar()\">"
				+ "                             <i title=\"Rstaurar listado\" class=\"ace-icon fa fa-refresh icon-on-right bigger-130 green\"></i>"
				+ "                         </a>  "
				+ "                     </span>"
				+ "                 </th>"
				+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"2\">MARCACIÓN</th>"
				+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"3\">REGALOS</th>"
				+ "                                       </tr>"
				+ "                                   </thead>"
				+ "                                   <tbody>");

			int cont_ini = 0;
			int cont_fin = 0;
			int cont = inicio + 1;
			for (int i = 0; i < lista.size(); i++) {
				if (i == 0) {
					cont_ini = cont;
				}
				String codPerAsi = lista.get(i).getCodigoPersonal();
				String apellido = lista.get(i).getApellidos();
				Asistencia estados = new Asistencia();
				estados = servicos.consultarEstadosAsistencia(codPerAsi);
				String codAsis = estados.getCodigoAsistencia();
				String apellidoSelect = apellido.replaceAll(busqueda, "<span style='background-color:yellow;'><b>" + busqueda + "</b></span>");

				if (estados.getHoraMarcacion() != null) {
					if (estados.getEstadoAlimentacion().equals("0")) {
						pw.println("<tr style='background-color:#FFFF99; height:35px;'>");
					} else {
						pw.println("<tr style='height:35px;'>");
					}
				} else {
					pw.println("<tr style='height:35px;'>");
				}

				pw.println("<td align='center' style='vertical-align:middle'>" + cont + "</td>");
				pw.println("<td style='vertical-align:middle'>" + apellidoSelect + ", " + lista.get(i).getNombres() + " </td>");

				if (estados.getHoraMarcacion() != null) {
					pw.println("<td colspan='2' align='center' style='vertical-align:middle; width:90px;'>");
					pw.println(estados.getHoraMarcacion());
					pw.println("</td>");
				} else {
					pw.println("<td colspan='2' align='center' style='vertical-align:middle; width:90px;'>");
					pw.println("</td>");
				}

				if (estados.getEstadoAlimentacion() != null) {
					if (estados.getEstadoAlimentacion().equals("1")) {
						pw.println("<td align='center' style='vertical-align:middle; width:100px;'>");
						pw.println(" " + lista.get(i).getCantidadNinios() + " NIÑO(S) ");
						pw.println("</td>");
						pw.println("<td  colspan='2' align='center' style='vertical-align:middle; width:95px;'>");
						pw.println("ENTREGADO");
						pw.println("</td>");
					} else {
						pw.println("<td align='center' style='vertical-align:middle; width:100px;'>");
						pw.println(" " + lista.get(i).getCantidadNinios() + " NIÑO(S) ");
						pw.println("</td>");
						pw.println("<td colspan='2' align='center' style='vertical-align:middle; width:95px;'>");
						pw.println("SIN ENTREGAR");
						pw.println("</td>");
					}
				} else {
					pw.println("<td align='center' style='vertical-align:middle; width:100px;'>");
					pw.println(" " + lista.get(i).getCantidadNinios() + " NIÑO(S) ");
					pw.println("</td>");
					pw.println("<td colspan='2' align='center' style='vertical-align:middle; width:95px;'>");
					pw.println("SIN ENTREGAR");
					pw.println("</td>");

				}

				pw.println("<tr>");
				cont++;
			}
			cont_fin = cont - 1;
			pw.println("            </tbody>"
				+ "         </table>");

			//::::::::::::::: PIE ::::::::::::::::
			if (cantRegistro >= cantidad) {

				pw.println("<div class='row'>"
					+ "<div class='col-xs-6'>"
					+ "<div class='dataTables_info' id='sample-table-2_info' role='status' aria-live='polite'> "
					+ "Mostrando del " + cont_ini + " al " + cont_fin + " de " + cantRegistro + " colaboradores"
					+ "</div> "
					+ "</div> "
					+ "<div class='col-xs-6'> "
					+ "<div class='dataTables_paginate paging_simple_numbers' id='sample-table-2_paginate'>"
					+ "<ul class='pagination'>");

				int anterior = pagina - 1;
				int siguiente = pagina + 1;
				if (pagina > 1) {
					pw.println("<li tabindex='0' class='paginate_button previous' id='sample-table-2_previous' aria-controls='sample-table-2'> "
						+ "<a href='javascript:listarReporteGeneral(" + 1 + ");'> << </a>"
						+ "</li>");
					pw.println("<li tabindex='0' class='paginate_button previous' id='sample-table-2_previous' aria-controls='sample-table-2'> "
						+ "<a href='javascript:listarReporteGeneral(" + anterior + ");'>Anterior</a>"
						+ "</li>");

					//pw.println("<li><a href=\"javascript:listarReporteGeneral(" + anterior + ");\"><span>Anterior</span></a></li>");
				} else {
					pw.println("<li tabindex='0' class='paginate_button previous disabled' id='sample-table-2_previous' aria-controls='sample-table-2'> "
						+ "<a> << </a>"
						+ "</li>");
					pw.println("<li tabindex='0' class='paginate_button previous disabled' id='sample-table-2_previous' aria-controls='sample-table-2'> "
						+ "<a>Anterior</a>"
						+ "</li>");
				}

				//for(int i = 1; i<=numero; i++){
				if (numero > 5) {
					if (pagina > 2) {
						if (numero >= pagina + 5) {
							for (int i = pagina - 2; i < pagina + 3; i++) {
								if (pagina == i) {
									pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>"
										+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
										+ "</li>");
									//pw.println("<li ><a href=\"javascript:listarReporteGeneral(" + i + ");\" style='background-color:#00A9FB'><span>" + i + "</span></a></li>");
								} else {
									pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>"
										+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
										+ "</li>");
									//pw.println("<li><a href=\"javascript:listarReporteGeneral(" + i + ");\" ><span>" + i + "</span></a></li>");
								}
							}
						} else {
							if (pagina == numero) {
								for (int i = pagina - 4; i <= numero; i++) {
									if (pagina == i) {
										pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>"
											+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
											+ "</li>");
									} else {
										pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>"
											+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
											+ "</li>");
									}
								}
							} else if (pagina == numero - 1) {
								for (int i = pagina - 3; i <= numero; i++) {
									if (pagina == i) {
										pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>"
											+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
											+ "</li>");
									} else {
										pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>"
											+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
											+ "</li>");
									}
								}
							} else if (pagina == numero - 2) {
								for (int i = pagina - 2; i <= numero; i++) {
									if (pagina == i) {
										pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>"
											+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
											+ "</li>");
									} else {
										pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>"
											+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
											+ "</li>");
									}
								}
							} else if (pagina == numero - 3) {
								for (int i = pagina - 1; i <= numero; i++) {
									if (pagina == i) {
										pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>"
											+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
											+ "</li>");
									} else {
										pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>"
											+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
											+ "</li>");
									}
								}
							} else if (pagina == numero - 4) {
								for (int i = pagina; i <= numero; i++) {
									if (pagina == i) {
										pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>"
											+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
											+ "</li>");
									} else {
										pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>"
											+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
											+ "</li>");
									}
								}
							}
						}
					} else {
						if (pagina == 1) {
							for (int i = pagina; i < pagina + 5; i++) {
								if (pagina == i) {
									pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>"
										+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
										+ "</li>");
								} else {
									pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>"
										+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
										+ "</li>");
								}
							}
						} else {
							for (int i = pagina - 1; i < pagina + 4; i++) {
								if (pagina == i) {
									pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>"
										+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
										+ "</li>");
								} else {
									pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>"
										+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
										+ "</li>");
								}
							}
						}
					}
				} else {
					for (int i = 1; i <= numero; i++) {
						if (pagina == i) {
							pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>"
								+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
								+ "</li>");
						} else {
							pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>"
								+ "<a href='javascript:listarReporteGeneral(" + i + ");'>" + i + "</a>"
								+ "</li>");
						}
					}
				}
				//}

				if (pagina < numero) {
					pw.println("<li tabindex='0' class='paginate_button next' id='sample-table-2_next' aria-controls='sample-table-2'>"
						+ "<a href='javascript:listarReporteGeneral(" + siguiente + ");'>Siguiente</a>"
						+ "</li>");
					pw.println("<li tabindex='0' class='paginate_button next' id='sample-table-2_next' aria-controls='sample-table-2'>"
						+ "<a href='javascript:listarReporteGeneral(" + numero + ");'> >> </a>"
						+ "</li>");
				} else {
					pw.println("<li tabindex='0' class='paginate_button next disabled' id='sample-table-2_next' aria-controls='sample-table-2'>"
						+ "<a>Siguiente</a>"
						+ "</li>");
					pw.println("<li tabindex='0' class='paginate_button next disabled' id='sample-table-2_next' aria-controls='sample-table-2'>"
						+ "<a> >> </a>"
						+ "</li>");
				}
				pw.println("</ul>"
					+ "</div>"
					+ "</div>"
					+ "</div>");
			}

			//:::::::: PIE        
			pw.println("     </div>"
				+ " </div>"
				+ "</div>"
				+ "<br>");

		}
	}

	private void verReportes(HttpServletRequest request, HttpServletResponse response) throws IOException {
		ConteoServices servicios = new ConteoServices();
		int cantidad = 0;
		String cantidadFinal = "00000000";
		cantidad = servicios.totalTicket();
		cantidadFinal = String.format("%08d", cantidad);

		ArrayList<Conteo> lista = new ArrayList<Conteo>();
		lista = servicios.consultarTotalEntradasPorTipo();
		String cantidad_contesia = "";
		String cantidad_general = "";
		String cantidad_ninguno = "";

		for (int i = 0; i < lista.size(); i++) {
			if (i == 0) {
				cantidad_contesia = String.format("%08d", lista.get(i).getCantidad());
			} else if (i == 1) {
				cantidad_general = String.format("%08d", lista.get(i).getCantidad());
			} else {
				cantidad_ninguno = String.format("%08d", lista.get(i).getCantidad());
			}
		}

		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		pw.println("<div><div class=\"tabbable\">  "
			+ "    <ul class=\"nav nav-tabs padding-12 tab-color-blue background-blue\" id=\"myTab4\">  "
			+ "        <li class=\"active\">  "
			+ "            <a href=\"#div1\" data-toggle=\"tab\">ASISTENCIA GENERAL</a>  "
			+ "        </li>  "
			+ "    </ul>  "
			+ "    <div class=\"tab-content\">  "
			+ "        <div class=\"tab-pane in active\" id=\"div1\">  "
			+ "            <div id='divReporteAsistencia'></div>  "
			+ "        </div>  "
			+ "        <div class=\"tab-pane\" id=\"div2\">  "
			+ "            <div id='divAsistenciaPorComision'></div>  "
			+ "            <div id='divAsistenciaPorComisionImp' style='display:none;'></div><br>  "
			+ "            <center>"
			+ "               <button class=\"btn btn-sm btn-primary\" onclick=\"imprimirAsistencia();\" type=\"button\">\n"
			+ "                   <i class=\"ace-icon fa fa fa-print icon-on-right bigger-110\"></i>\n"
			+ "                   IMPRIMIR\n"
			+ "               </button>  "
			+ "           </center>  "
			+ "        </div>  "
			+ "    </div>  "
			+ "</div></div>");
	}

	private void AsistenciaPorComision(HttpServletRequest request, HttpServletResponse response) throws IOException {
		AsistenciaServices servicos = new AsistenciaServices();
		ArrayList<Asistencia> lista = new ArrayList<Asistencia>();
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		lista = servicos.reporteAsistenciaAlimentacion();
		pw.println("<div style=\"border: 1px solid #CCCCCC; font-size:12px; \">"
			+ "                       <div class=\"table-header\">ASISTENCIAS"
			+ "                       </div>"
			+ "                       <div>"
			+ "                           <div class=\"dataTables_wrapper form-inline no-footer\" id=\"sample-table-2_wrapper\">"
			+ "                               <table class=\"table table-striped table-bordered table-hover dataTable no-footer\" id=\"sample-table-2\" role=\"grid\" aria-describedby=\"sample-table-2_info\" >"
			+ "                                   <thead>"
			+ "                                       <tr role=\"row\">"
			+ "                                           <th width='30' tabindex=\"0\" class=\"center\" rowspan=\"2\" colspan=\"1\" >N°</th>"
			+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"2\" colspan=\"1\">COMISIÓN</th>"
			+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"3\">CANTIDAD DE COLABORADORES</th>"
			+ "                                       </tr>"
			+ "                                       <tr>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">TOTAL</th>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">PRESENTES</th>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">AUSENTES</th>"
			+ "                                       </tr>"
			+ "                                   </thead>"
			+ "                                   <tbody>");
		int ttotal = 0;
		int tasis = 0;
		int tfalta = 0;
		for (int i = 0; i < lista.size(); i++) {
			int cont = i + 1;
			String total = "";
			String asis = "";
			String falta = "";
			if (!lista.get(i).getCantidadColaboradores().equals("0")) {
				total = "<b style='font-size:14px;'>" + lista.get(i).getCantidadColaboradores() + "</b>";
			} else {
				total = lista.get(i).getCantidadColaboradores();
			}
			if (!lista.get(i).getCantidadAsistentes().equals("0")) {
				asis = "<b style='font-size:14px;'>" + lista.get(i).getCantidadAsistentes() + "</b>";
			} else {
				asis = lista.get(i).getCantidadAsistentes();
			}
			if (!lista.get(i).getCantidadFaltantes().equals("0")) {
				falta = "<b style='font-size:14px;'>" + lista.get(i).getCantidadFaltantes() + "</b>";
			} else {
				falta = lista.get(i).getCantidadFaltantes();
			}

			ttotal = ttotal + Integer.parseInt(lista.get(i).getCantidadColaboradores());
			tasis = tasis + Integer.parseInt(lista.get(i).getCantidadAsistentes());
			tfalta = tfalta + Integer.parseInt(lista.get(i).getCantidadFaltantes());

			pw.println("<tr>");
			pw.println("    <td align='center' style=' vertical-align: middle;'>" + cont + "</td>");
			pw.println("    <td style=' vertical-align: middle;'>" + lista.get(i).getComision() + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle;'>" + total + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle;'>" + asis + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle;'>" + falta + "</td>");
			pw.println("</tr>");
		}

		pw.println("<tr style='background-color:#00517C; color:#FFFFFF;'>");
		pw.println("    <td colspan='2' align='center'>TOTALES</td>");
		pw.println("    <td align='center' style='width: 95px; vertical-align: middle;'>" + ttotal + "</td>");
		pw.println("    <td align='center' style='width: 95px; vertical-align: middle;'>" + tasis + "</td>");
		pw.println("    <td align='center' style='width: 95px; vertical-align: middle;'>" + tfalta + "</td>");
		pw.println("</tr>");

		pw.println("            </tbody>"
			+ "        </table>"
			+ "      </div>"
			+ "   </div>"
			+ "</div>");
	}

	private void AlimentacionPorComision(HttpServletRequest request, HttpServletResponse response) throws IOException {
		AsistenciaServices servicos = new AsistenciaServices();
		ArrayList<Asistencia> lista = new ArrayList<Asistencia>();
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		lista = servicos.reporteAlimentacion();
		pw.println("<div style=\"border: 1px solid #CCCCCC; font-size:12px; \">"
			+ "                       <div class=\"table-header\">ALIMENTACIÓN"
			+ "                       </div>"
			+ "                       <div>"
			+ "                           <div class=\"dataTables_wrapper form-inline no-footer\" id=\"sample-table-2_wrapper\">"
			+ "                               <table class=\"table table-striped table-bordered table-hover dataTable no-footer\" id=\"sample-table-2\" role=\"grid\" aria-describedby=\"sample-table-2_info\" >"
			+ "                                   <thead>"
			+ "                                       <tr role=\"row\">"
			+ "                                           <th width='30' tabindex=\"0\" class=\"center\" rowspan=\"2\" colspan=\"1\" >N°</th>"
			+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"2\" colspan=\"1\">COMISIÓN</th>"
			+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"2\" colspan=\"1\">PRESENTES</th>"
			+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"2\" colspan=\"1\">ALIMENTOS<BR>ENTREGADOS</th>"
			+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"4\">CANTIDAD TOTAL</th>"
			+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"4\">CANTIDAD ENTREGADA</th>"
			+ "                                       </tr>"
			+ "                                       <tr>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">D</th>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">A</th>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">L</th>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">C</th>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">D</th>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">A</th>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">L</th>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">C</th>"
			+ "                                       </tr>"
			+ "                                   </thead>"
			+ "                                   <tbody>");
		int CantAsis = 0;
		int CantEnt = 0;
		int desTo = 0;
		int almTo = 0;
		int lonTo = 0;
		int cenTo = 0;
		int desToE = 0;
		int almToE = 0;
		int lonToE = 0;
		int cenToE = 0;
		for (int i = 0; i < lista.size(); i++) {
			int cont = i + 1;
			CantAsis = CantAsis + Integer.parseInt(lista.get(i).getCantidadAsistentes());
			CantEnt = CantEnt + Integer.parseInt(lista.get(i).getCantidadEntregados());
			desTo = desTo + Integer.parseInt(lista.get(i).getDesayuno());
			almTo = almTo + Integer.parseInt(lista.get(i).getAlmuerzo());
			lonTo = lonTo + Integer.parseInt(lista.get(i).getLonche());
			cenTo = cenTo + Integer.parseInt(lista.get(i).getCena());
			desToE = desToE + Integer.parseInt(lista.get(i).getDesayunoEn());
			almToE = almToE + Integer.parseInt(lista.get(i).getAlmuerzoEn());
			lonToE = lonToE + Integer.parseInt(lista.get(i).getLoncheEn());
			cenToE = cenToE + Integer.parseInt(lista.get(i).getCenaEn());

			pw.println("<tr>");
			pw.println("    <td align='center'>" + cont + "</td>");
			pw.println("    <td>" + lista.get(i).getComision() + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle;'>" + lista.get(i).getCantidadAsistentes() + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle;'>" + lista.get(i).getCantidadEntregados() + "</td>");
			pw.println("    <td align='center' style='width: 95px; background-color:#FAEDCF; vertical-align: middle;'>" + lista.get(i).getDesayuno() + "</td>");
			pw.println("    <td align='center' style='width: 95px; background-color:#FAEDCF; vertical-align: middle;'>" + lista.get(i).getAlmuerzo() + "</td>");
			pw.println("    <td align='center' style='width: 95px; background-color:#FAEDCF; vertical-align: middle;'>" + lista.get(i).getLonche() + "</td>");
			pw.println("    <td align='center' style='width: 95px; background-color:#FAEDCF; vertical-align: middle;'>" + lista.get(i).getCena() + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle;'>" + lista.get(i).getDesayunoEn() + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle;'>" + lista.get(i).getAlmuerzoEn() + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle;'>" + lista.get(i).getLoncheEn() + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle;'>" + lista.get(i).getCenaEn() + "</td>");
			pw.println("</tr>");
		}

		pw.println("<tr>");
		pw.println("    <td colspan='2' align='center' style='background-color:#006699; color:#FFFFFF; vertical-align: middle;'><b>TOTALES</b></td>");
		pw.println("    <td align='center' style='width: 95px; background-color:#006699; color:#FFFFFF; vertical-align: middle;'><b>" + CantAsis + "</b></td>");
		pw.println("    <td align='center' style='width: 95px; background-color:#006699; color:#FFFFFF; vertical-align: middle;'><b>" + CantEnt + "</b></td>");
		pw.println("    <td align='center' style='width: 95px; background-color:#006699; color:#FFFFFF; vertical-align: middle;'><b>" + desTo + "</b></td>");
		pw.println("    <td align='center' style='width: 95px; background-color:#006699; color:#FFFFFF; vertical-align: middle;'><b>" + almTo + "</b></td>");
		pw.println("    <td align='center' style='width: 95px; background-color:#006699; color:#FFFFFF; vertical-align: middle;'><b>" + lonTo + "</b></td>");
		pw.println("    <td align='center' style='width: 95px; background-color:#006699; color:#FFFFFF; vertical-align: middle;'><b>" + cenTo + "</b></td>");
		pw.println("    <td align='center' style='width: 95px; background-color:#006699; color:#FFFFFF; vertical-align: middle;'><b>" + desToE + "</b></td>");
		pw.println("    <td align='center' style='width: 95px; background-color:#006699; color:#FFFFFF; vertical-align: middle;'><b>" + almToE + "</b></td>");
		pw.println("    <td align='center' style='width: 95px; background-color:#006699; color:#FFFFFF; vertical-align: middle;'><b>" + lonToE + "</b></td>");
		pw.println("    <td align='center' style='width: 95px; background-color:#006699; color:#FFFFFF; vertical-align: middle;'><b>" + cenToE + "</b></td>");
		pw.println("</tr>");

		pw.println("            </tbody>"
			+ "        </table>"
			+ "      </div>"
			+ "   </div>"
			+ "</div>");
	}

	private void AsistenciaPorComisionImp(HttpServletRequest request, HttpServletResponse response) throws IOException {
		AsistenciaServices servicos = new AsistenciaServices();
		ArrayList<Asistencia> lista = new ArrayList<Asistencia>();
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		lista = servicos.reporteAsistenciaAlimentacion();
		pw.println("<center><H2 style='font-family:arial;'>REPORTE POR ASISTENCIA<H2><BR><table border='1' cellspacing='0' cellpadding='0' >"
			+ "                       <thead>"
			+ "                           <tr>"
			+ "                               <th width='30' align='center'rowspan=\"2\" colspan=\"1\" style='font-family:arial;' > N° </th>"
			+ "                               <th align='center'rowspan=\"2\" colspan=\"1\" style='font-family:arial;'> COMISIÓN </th>"
			+ "                               <th align='center'rowspan=\"1\" colspan=\"3\" style='font-family:arial;'> CANTIDAD DE COLABORADORES </th>"
			+ "                           </tr>"
			+ "                           <tr>"
			+ "                               <th style='width: 100px; font-family:arial;' align='center' rowspan=\"1\" colspan=\"1\" > TOTAL </th>"
			+ "                               <th style='width: 100px; font-family:arial;' align='center' rowspan=\"1\" colspan=\"1\" > PRESENTES </th>"
			+ "                               <th style='width: 100px; font-family:arial;' align='center' rowspan=\"1\" colspan=\"1\" > AUSENTES </th>"
			+ "                           </tr>"
			+ "                       </thead>"
			+ "                       <tbody>");
		int ttotal = 0;
		int tasis = 0;
		int tfalta = 0;
		for (int i = 0; i < lista.size(); i++) {
			int cont = i + 1;
			String total = "";
			String asis = "";
			String falta = "";
			if (!lista.get(i).getCantidadColaboradores().equals("0")) {
				total = "<b style='font-size:14px;'>" + lista.get(i).getCantidadColaboradores() + "</b>";
			} else {
				total = lista.get(i).getCantidadColaboradores();
			}
			if (!lista.get(i).getCantidadAsistentes().equals("0")) {
				asis = "<div style='font-size:14px; background-color:#FFFF00;'>" + lista.get(i).getCantidadAsistentes() + "</div>";
			} else {
				asis = lista.get(i).getCantidadAsistentes();
			}
			if (!lista.get(i).getCantidadFaltantes().equals("0")) {
				falta = "<b style='font-size:14px;'>" + lista.get(i).getCantidadFaltantes() + "</b>";
			} else {
				falta = lista.get(i).getCantidadFaltantes();
			}

			ttotal = ttotal + Integer.parseInt(lista.get(i).getCantidadColaboradores());
			tasis = tasis + Integer.parseInt(lista.get(i).getCantidadAsistentes());
			tfalta = tfalta + Integer.parseInt(lista.get(i).getCantidadFaltantes());

			pw.println("<tr>");
			pw.println("    <td align='center' style=' vertical-align: middle;  font-family:arial;'> " + cont + " </td>");
			pw.println("    <td style=' vertical-align: middle; font-family:arial; font-size:12px;'> " + lista.get(i).getComision() + " </td>");
			pw.println("    <td align='center' style='width: 100px; vertical-align: middle; font-family:arial;'> " + total + "</td>");
			pw.println("    <td align='center' style='width: 100px; vertical-align: middle; font-family:arial;'> " + asis + "</td>");
			pw.println("    <td align='center' style='width: 100px; vertical-align: middle; font-family:arial;'> " + falta + "</td>");
			pw.println("</tr>");
		}

		pw.println("<tr>");
		pw.println("    <td colspan='2' align='center' style='font-family:arial;'><b>TOTALES</b></td>");
		pw.println("    <td align='center' style='width: 100px; vertical-align:middle; font-family:arial;'><b>" + ttotal + "</b></td>");
		pw.println("    <td align='center' style='width: 100px; vertical-align:middle; font-family:arial;'><b>" + tasis + "</b></td>");
		pw.println("    <td align='center' style='width: 100px; vertical-align:middle; font-family:arial;'><b>" + tfalta + "</b></td>");
		pw.println("</tr>");

		pw.println("            </tbody>"
			+ "        </table></center>");
	}

	private void AlimentacionPorComisionImp(HttpServletRequest request, HttpServletResponse response) throws IOException {
		AsistenciaServices servicos = new AsistenciaServices();
		ArrayList<Asistencia> lista = new ArrayList<Asistencia>();
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		lista = servicos.reporteAlimentacion();
		pw.println("<center><H2 style='font-family:arial;'>REPORTE POR ALIMENTACIÓN</H2></center><BR>"
			+ "            <table   border='1' cellspacing='0' cellpadding='0'>"
			+ "                                   <thead>"
			+ "                                       <tr>"
			+ "                                           <th  align='center'rowspan=\"2\" colspan=\"1\" style='font-size:10px; font-family:arial;' >N°</th>"
			+ "                                           <th align='center'rowspan=\"2\" colspan=\"1\" style='font-family:arial;'>COMISIÓN</th>"
			+ "                                           <th align='center'rowspan=\"2\" colspan=\"1\" style='font-family:arial;'>PRESENTES</th>"
			+ "                                           <th align='center'rowspan=\"2\" colspan=\"1\" style='font-family:arial;'>ALIMENTOS<BR>ENTREGADOS</th>"
			+ "                                           <th align='center'rowspan=\"1\" colspan=\"4\" style='font-family:arial;'>CANTIDAD TOTAL</th>"
			+ "                                           <th align='center'rowspan=\"1\" colspan=\"4\" style='font-family:arial;'>CANTIDAD ENTREGADA</th>"
			+ "                                       </tr>"
			+ "                                       <tr>"
			+ "                                           <th align='center'rowspan=\"1\" colspan=\"1\" style='font-family:arial;'>D</th>"
			+ "                                           <th align='center'rowspan=\"1\" colspan=\"1\" style='font-family:arial;'>A</th>"
			+ "                                           <th align='center'rowspan=\"1\" colspan=\"1\" style='font-family:arial;'>L</th>"
			+ "                                           <th align='center'rowspan=\"1\" colspan=\"1\" style='font-family:arial;'>C</th>"
			+ "                                           <th align='center'rowspan=\"1\" colspan=\"1\" style='font-family:arial;'>D</th>"
			+ "                                           <th align='center'rowspan=\"1\" colspan=\"1\" style='font-family:arial;'>A</th>"
			+ "                                           <th align='center'rowspan=\"1\" colspan=\"1\" style='font-family:arial;'>L</th>"
			+ "                                           <th align='center'rowspan=\"1\" colspan=\"1\" style='font-family:arial;'>C</th>"
			+ "                                       </tr>"
			+ "                                   </thead>"
			+ "                                   <tbody>");
		int CantAsis = 0;
		int CantEnt = 0;
		int desTo = 0;
		int almTo = 0;
		int lonTo = 0;
		int cenTo = 0;
		int desToE = 0;
		int almToE = 0;
		int lonToE = 0;
		int cenToE = 0;
		for (int i = 0; i < lista.size(); i++) {
			int cont = i + 1;
			CantAsis = CantAsis + Integer.parseInt(lista.get(i).getCantidadAsistentes());
			CantEnt = CantEnt + Integer.parseInt(lista.get(i).getCantidadEntregados());
			desTo = desTo + Integer.parseInt(lista.get(i).getDesayuno());
			almTo = almTo + Integer.parseInt(lista.get(i).getAlmuerzo());
			lonTo = lonTo + Integer.parseInt(lista.get(i).getLonche());
			cenTo = cenTo + Integer.parseInt(lista.get(i).getCena());
			desToE = desToE + Integer.parseInt(lista.get(i).getDesayunoEn());
			almToE = almToE + Integer.parseInt(lista.get(i).getAlmuerzoEn());
			lonToE = lonToE + Integer.parseInt(lista.get(i).getLoncheEn());
			cenToE = cenToE + Integer.parseInt(lista.get(i).getCenaEn());

			pw.println("<tr>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle; font-family:arial; '>" + cont + "</td>");
			pw.println("    <td style='font-family:arial; vertical-align: middle; font-size:12px;'  >" + lista.get(i).getComision() + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle; font-family:arial;'>" + lista.get(i).getCantidadAsistentes() + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle; font-family:arial;'>" + lista.get(i).getCantidadEntregados() + "</td>");
			pw.println("    <td align='center' style='width: 95px; background-color:#FAEDCF; vertical-align: middle; font-family:arial;'>" + lista.get(i).getDesayuno() + "</td>");
			pw.println("    <td align='center' style='width: 95px; background-color:#FAEDCF; vertical-align: middle; font-family:arial;'>" + lista.get(i).getAlmuerzo() + "</td>");
			pw.println("    <td align='center' style='width: 95px; background-color:#FAEDCF; vertical-align: middle; font-family:arial;'>" + lista.get(i).getLonche() + "</td>");
			pw.println("    <td align='center' style='width: 95px; background-color:#FAEDCF; vertical-align: middle; font-family:arial;'>" + lista.get(i).getCena() + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle; font-family:arial;'>" + lista.get(i).getDesayunoEn() + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle; font-family:arial;'>" + lista.get(i).getAlmuerzoEn() + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle; font-family:arial;'>" + lista.get(i).getLoncheEn() + "</td>");
			pw.println("    <td align='center' style='width: 95px; vertical-align: middle; font-family:arial;'>" + lista.get(i).getCenaEn() + "</td>");
			pw.println("</tr>");
		}

		pw.println("<tr>");
		pw.println("    <td colspan='2' align='center' rowspan=\"1\" colspan=\"1\" style='background-color:#FAEDCF;vertical-align: middle; font-family:arial;'><b>TOTALES</b></td>");
		pw.println("    <td align='center' rowspan=\"1\" colspan=\"1\" style='background-color:#FAEDCF;vertical-align: middle; font-family:arial;'><b>" + CantAsis + "</b></td>");
		pw.println("    <td align='center' rowspan=\"1\" colspan=\"1\" style='background-color:#FAEDCF;vertical-align: middle; font-family:arial;'><b>" + CantEnt + "</b></td>");
		pw.println("    <td align='center' rowspan=\"1\" colspan=\"1\" style='background-color:#FAEDCF;vertical-align: middle; font-family:arial;'><b>" + desTo + "</b></td>");
		pw.println("    <td align='center' rowspan=\"1\" colspan=\"1\" style='background-color:#FAEDCF;vertical-align: middle; font-family:arial;'><b>" + almTo + "</b></td>");
		pw.println("    <td align='center' rowspan=\"1\" colspan=\"1\" style='background-color:#FAEDCF;vertical-align: middle; font-family:arial;'><b>" + lonTo + "</b></td>");
		pw.println("    <td align='center' rowspan=\"1\" colspan=\"1\" style='background-color:#FAEDCF;vertical-align: middle; font-family:arial;'><b>" + cenTo + "</b></td>");
		pw.println("    <td align='center' rowspan=\"1\" colspan=\"1\" style='background-color:#FAEDCF;vertical-align: middle; font-family:arial;'><b>" + desToE + "</b></td>");
		pw.println("    <td align='center' rowspan=\"1\" colspan=\"1\" style='background-color:#FAEDCF;vertical-align: middle; font-family:arial;'><b>" + almToE + "</b></td>");
		pw.println("    <td align='center' rowspan=\"1\" colspan=\"1\" style='background-color:#FAEDCF;vertical-align: middle; font-family:arial;'><b>" + lonToE + "</b></td>");
		pw.println("    <td align='center' rowspan=\"1\" colspan=\"1\" style='background-color:#FAEDCF;vertical-align: middle; font-family:arial;'><b>" + cenToE + "</b></td>");
		pw.println("</tr>");

		pw.println("            </tbody>"
			+ "        </table>");
	}

	private void extras(HttpServletRequest request, HttpServletResponse response) throws IOException {
		AsistenciaServices servicios = new AsistenciaServices();
		int codDia = servicios.codigoDia();
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		pw.println("<center>\n"
			+ "            <table>\n"
			+ "                <tr>\n"
			+ "                    <td>RESPONSABLE:</td>\n"
			+ "                    <td style='width: 10px'></td>\n"
			+ "                    <td>"
			+ "                           <input type='hidden' class='form-control' id='codDia' value='" + codDia + "'>"
			+ "                           <input type='text' class='form-control' id='resp'>"
			+ "                    </td>\n"
			+ "                </tr>\n"
			+ "                <tr>\n"
			+ "                    <td colspan='3' style='height: 5px;'></td>\n"
			+ "                </tr>\n"
			+ "                <tr>\n"
			+ "                    <td>DESAYUNO:</td>\n"
			+ "                    <td style='width: 10px'></td>\n"
			+ "                    <td>"
			+ "                       <select id='des' class='form-control'>");
		for (int i = 0; i < 31; i++) {
			pw.println("<option value='" + i + "'>" + i + " Unidad de ticket</option>");
		}
		pw.println("            </select>"
			+ "                    </td>\n"
			+ "                </tr>\n"
			+ "                <tr>\n"
			+ "                    <td colspan='3' style='height: 5px;'></td>\n"
			+ "                </tr>\n"
			+ "                <tr>\n"
			+ "                    <td>ALMUERZO:</td>\n"
			+ "                    <td style='width: 10px'></td>\n"
			+ "                    <td>"
			+ "                       <select id='alm' class='form-control'>");
		for (int i = 0; i < 31; i++) {
			pw.println("<option value='" + i + "'>" + i + " Unidad de ticket</option>");
		}
		pw.println("            </select>"
			+ "                    </td>\n"
			+ "                </tr>\n"
			+ "                <tr>\n"
			+ "                    <td colspan='3' style='height: 5px;'></td>\n"
			+ "                </tr>\n"
			+ "                <tr>\n"
			+ "                    <td>LONCE:</td>\n"
			+ "                    <td style='width: 10px'></td>\n"
			+ "                    <td>"
			+ "                       <select id='lon' class='form-control'>");
		for (int i = 0; i < 31; i++) {
			pw.println("<option value='" + i + "'>" + i + " Unidad de ticket</option>");
		}
		pw.println("            </select>"
			+ "                    </td>\n"
			+ "                </tr>\n"
			+ "                <tr>\n"
			+ "                    <td colspan='3' style='height: 5px;'></td>\n"
			+ "                </tr>\n"
			+ "                <tr>\n"
			+ "                    <td>CENA:</td>\n"
			+ "                    <td style='width: 10px'></td>\n"
			+ "                    <td>"
			+ "                       <select id='cen' class='form-control'>");
		for (int i = 0; i < 31; i++) {
			pw.println("<option value='" + i + "'>" + i + " Unidad de ticket</option>");
		}
		pw.println("            </select>"
			+ "                    </td>\n"
			+ "                </tr>\n"
			+ "            </table>\n"
			+ "        </center>");
	}

	private void registrarExtras(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String codDia = request.getParameter("codDia");
		String resp = request.getParameter("resp").toUpperCase();
		String des = request.getParameter("des");
		String alm = request.getParameter("alm");
		String lon = request.getParameter("lon");
		String cen = request.getParameter("cen");
		AsistenciaServices servicios = new AsistenciaServices();
		int dato = servicios.registrarExtras(codDia, resp, des, alm, lon, cen);
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		pw.println(dato);
	}

	private void reporteExtrasAlimentacion(HttpServletRequest request, HttpServletResponse response) throws IOException {
		AsistenciaServices servicos = new AsistenciaServices();
		ArrayList<Asistencia> lista = new ArrayList<Asistencia>();
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		lista = servicos.reporteExtras();
		pw.println("<div style=\"border: 1px solid #CCCCCC; font-size:12px; \">"
			+ "                       <div class=\"table-header\">ALIMENTACIÓN"
			+ "                       </div>"
			+ "                       <div>"
			+ "                           <div class=\"dataTables_wrapper form-inline no-footer\" id=\"sample-table-2_wrapper\">"
			+ "                               <table class=\"table table-striped table-bordered table-hover dataTable no-footer\" id=\"sample-table-2\" role=\"grid\" aria-describedby=\"sample-table-2_info\" >"
			+ "                                   <thead>"
			+ "                                       <tr role=\"row\">"
			+ "                                           <th width='30' tabindex=\"0\" class=\"center\" rowspan=\"2\" colspan=\"1\" >N°</th>"
			+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"2\" colspan=\"1\">RESPONSABLE</th>"
			+ "                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"4\">CANTIDAD ALIMENTOS</th>"
			+ "                                       </tr>"
			+ "                                       <tr>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">D</th>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">A</th>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">L</th>"
			+ "                                           <th style='width: 95px;' tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">C</th>"
			+ "                                       </tr>"
			+ "                                   </thead>"
			+ "                                   <tbody>");
		int tdes = 0;
		int talm = 0;
		int tlon = 0;
		int tcen = 0;
		for (int i = 0; i < lista.size(); i++) {
			int cont = i + 1;
			tdes = tdes + Integer.parseInt(lista.get(i).getDesayuno());
			talm = talm + Integer.parseInt(lista.get(i).getAlmuerzo());
			tlon = tlon + Integer.parseInt(lista.get(i).getLonche());
			tcen = tcen + Integer.parseInt(lista.get(i).getCena());
			pw.println("<tr>");
			pw.println("    <td class='center'>" + cont + "</td>");
			pw.println("    <td >" + lista.get(i).getNombres() + "</td>");
			pw.println("    <td class='center'>" + lista.get(i).getDesayuno() + "</td>");
			pw.println("    <td class='center'>" + lista.get(i).getAlmuerzo() + "</td>");
			pw.println("    <td class='center'>" + lista.get(i).getLonche() + "</td>");
			pw.println("    <td class='center'>" + lista.get(i).getCena() + "</td>");
			pw.println("</tr>");
		}

		pw.println("<tr style='background-color:#006699; color:#E9EFF8'>");
		pw.println("    <td class='center' colspan='2'> TOTALES</td>");
		pw.println("    <td class='center'>" + tdes + "</td>");
		pw.println("    <td class='center'>" + talm + "</td>");
		pw.println("    <td class='center'>" + tlon + "</td>");
		pw.println("    <td class='center'>" + tcen + "</td>");
		pw.println("</tr>");

		pw.println("            </tbody>"
			+ "         <table>"
			+ "     </div>"
			+ " </div>"
			+ "</div>");

	}

	private void reporteExtrasAlimentacionImp(HttpServletRequest request, HttpServletResponse response) throws IOException {
		AsistenciaServices servicos = new AsistenciaServices();
		ArrayList<Asistencia> lista = new ArrayList<Asistencia>();
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		lista = servicos.reporteExtras();

		pw.println("<center><H2 style='font-family:arial;'>REPORTE POR ALIMENTACIÓN</H2></center><BR>"
			+ "                       <table  border='1' cellspacing='0' cellpadding='0' >"
			+ "                           <thead>"
			+ "                               <tr>"
			+ "                                   <th align='center' rowspan=\"2\" colspan=\"1\" style='font-size:10px; font-family:arial;' >N°</th>"
			+ "                                   <th align='center' rowspan=\"2\" colspan=\"1\" style='font-family:arial;'>RESPONSABLE</th>"
			+ "                                   <th align='center' rowspan=\"1\" colspan=\"4\" style='font-family:arial;'>CANTIDAD ALIMENTOS</th>"
			+ "                               </tr>"
			+ "                               <tr>"
			+ "                                   <th align='center' rowspan=\"1\" colspan=\"1\" style='font-family:arial;'>DESAYUNO</th>"
			+ "                                   <th align='center' rowspan=\"1\" colspan=\"1\" style='font-family:arial;'>ALMUERZO</th>"
			+ "                                   <th align='center' rowspan=\"1\" colspan=\"1\" style='font-family:arial;'>LONCHE</th>"
			+ "                                   <th align='center' rowspan=\"1\" colspan=\"1\" style='font-family:arial;'>CENA</th>"
			+ "                               </tr>"
			+ "                           </thead>"
			+ "                           <tbody>");
		int tdes = 0;
		int talm = 0;
		int tlon = 0;
		int tcen = 0;
		for (int i = 0; i < lista.size(); i++) {
			int cont = i + 1;
			tdes = tdes + Integer.parseInt(lista.get(i).getDesayuno());
			talm = talm + Integer.parseInt(lista.get(i).getAlmuerzo());
			tlon = tlon + Integer.parseInt(lista.get(i).getLonche());
			tcen = tcen + Integer.parseInt(lista.get(i).getCena());
			pw.println("<tr>");
			pw.println("    <td align='center' style='font-family:arial;'>" + cont + "</td>");
			pw.println("    <td style='font-family:arial;'>" + lista.get(i).getNombres() + "</td>");
			pw.println("    <td align='center' style='font-family:arial;'>" + lista.get(i).getDesayuno() + "</td>");
			pw.println("    <td align='center' style='font-family:arial;'>" + lista.get(i).getAlmuerzo() + "</td>");
			pw.println("    <td align='center' style='font-family:arial;'>" + lista.get(i).getLonche() + "</td>");
			pw.println("    <td align='center' style='font-family:arial;'>" + lista.get(i).getCena() + "</td>");
			pw.println("</tr>");
		}

		pw.println("<tr style='background-color:#006699; color:#E9EFF8'>");
		pw.println("    <td align='center' colspan='2' style='font-family:arial;'> TOTALES</td>");
		pw.println("    <td align='center' style='font-family:arial;'>" + tdes + "</td>");
		pw.println("    <td align='center' style='font-family:arial;'>" + talm + "</td>");
		pw.println("    <td align='center' style='font-family:arial;'>" + tlon + "</td>");
		pw.println("    <td align='center' style='font-family:arial;'>" + tcen + "</td>");
		pw.println("</tr>");

		pw.println("            </tbody>"
			+ "         <table>"
			+ "     </div>"
			+ " </div>"
			+ "</div>");
	}

	private void filtroPersonalReg(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String busqueda = request.getParameter("busqueda").toUpperCase();

		AsistenciaServices servicos = new AsistenciaServices();
		ArrayList<Asistencia> lista = null;
		lista = servicos.consultarExistenciaAsistencia(busqueda);

		String accion = request.getParameter("Accion");
		String nombre = request.getParameter("nombre");

		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();

		pw.println("<select style='max-width:240px' id ='" + nombre + "' onchange='" + accion + "' class='validate[required] chosen-select form-control' data-placeholder='::: SELECCIONE :::'>");
		pw.println("<option value=''></option>");

		for (int i = 0; i < lista.size(); i++) {
			pw.println("<option value='" + lista.get(i).getCodigoPersonal() + "'>" + lista.get(i).getApellidos() + " " + lista.get(i).getNombres() + "</option>");
		}
		pw.println("</select>");
		pw.close();

	}

}
