package custom.senior.regras; import org.joda.time.LocalDate; import java.awt.Container; import org.joda.time.Days; import com.senior.ContextoGeralRH; import com.senior.dataset.IBookmark; import com.senior.dataset.ICursor; import com.senior.dataset.IFieldAccessor; import com.senior.dataset.MappedParamProvider; import com.senior.dataset.SearchMode; import com.senior.email.Email; import com.senior.entity.IHistoricoAfastamento; import com.senior.entitysession.IEntitySession; import com.senior.rh.entities.readonly.IR034FUN; import com.senior.sc.AbstractSystemComponentExtension; import com.senior.sc.annotation.SystemComponentExtension; import custom.senior.apuracao.HelperContextoGeral; @SystemComponentExtension("br.com.senior.rh.gp.sc.historico.afastamento.SCHistoricoAfastamento") public class SCValidaHistoricoAfastamento extends AbstractSystemComponentExtension { private ContextoGeralRH contextoGeral; //LIMITES TREINAMENTOS private static final int DUAS_HORAS = 120; private static final int QUATRO_HORAS = 240; private static final int OITO_HORAS = 480; private static final int DEZESSEIS_HORAS = 960; private static final int TRINTA_DUAS_HORAS = 1920; private static final int NOVENTA_SEIS_HORAS = 5760; public SCValidaHistoricoAfastamento(IEntitySession entitySession) { super(entitySession); HelperContextoGeral instance = HelperContextoGeral.getInstance(); contextoGeral = instance.getContextoGeral(); } public String validarAfastamentoInsert(IFieldAccessor field, IHistoricoAfastamento historicoAfastamento, IBookmark bookmark) { String retorno = "True"; int numEmp = historicoAfastamento.getNumEmp(); int tipCol = historicoAfastamento.getTipCol(); int numCad = historicoAfastamento.getNumCad(); LocalDate datAfa = historicoAfastamento.getDatAfa(); LocalDate datTer = historicoAfastamento.getDatTer(); int codigoFilial = retornaFilial(numEmp, tipCol, numCad); boolean isCodSitNull = historicoAfastamento.isCodSitNull(); short codSit = 0; if(!isCodSitNull){ codSit = historicoAfastamento.getCodSit(); } else { return retorno; } if (codSit == 14 || codSit == 32){ if(datTer == null){ retorno = "Para afastamento por atestado a data final deve ser preenchida."; } else{ int diferencaEmDias = Days.daysBetween(datAfa, datTer).getDays(); diferencaEmDias++; if (diferencaEmDias > 15){ retorno = "Afastamento por atestado não pode ser superior a 15 dias, " + "pois o execedente deve ser inserido como auxilio doença ou acidente de trabalho"; } else{ if (diferencaEmDias >= 3){ Email email = new Email(); //remetente email.setSender("fopag.ubr@unicred.com.br"); //assunto email.setSubject("Gestão do Ponto - Controle de atestados"); //destinatário email.addRecipient("matheus.henn@unicred.com.br"); //destinatário cópia // email.addCCRecipient("destinatariocopia@servidor.com"); //anexo // email.addAttachment(new File("../anexo.txt")); //texto email.setTextBody("Texto do corpo do email."); container.sendMail(email); // retorno = "Afastamento por atestado maior que 3 dias "; } } } return retorno; } if (codSit == 134){ if (consisteCamposAfastamento(historicoAfastamento)){ retorno = "Não é permitido lançar afastamentos na situação 134 sem os seguintes campos: Hora Afastamento, Data Término e Hora Término."; } int limiteSemanal = 0; int limiteMensal = 0; int limiteAnual = 0; switch (numEmp) { case 6033: limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; break; case 9008: if ((codigoFilial == 111) || (codigoFilial == 2)){ limiteSemanal = DUAS_HORAS; limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; } else{ limiteMensal = OITO_HORAS; limiteAnual = TRINTA_DUAS_HORAS; } break; case 1538: limiteSemanal = DUAS_HORAS; limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; break; case 4006: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4014: if (codigoFilial == 5){ limiteSemanal = DUAS_HORAS; limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; } else{ limiteMensal = QUATRO_HORAS; limiteAnual = DEZESSEIS_HORAS; } break; case 4022: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4030: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4049: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4065: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4073: limiteSemanal = DUAS_HORAS; limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; break; case 4081: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4090: limiteSemanal = DUAS_HORAS; limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; break; case 4103: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4111: limiteSemanal = DUAS_HORAS; limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; break; case 4120: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; // case 124: // limiteSemanal = DUAS_HORAS; // break; // case 159: // limiteSemanal = DUAS_HORAS; // break; default: limiteMensal = OITO_HORAS; limiteAnual = TRINTA_DUAS_HORAS; break; } // if (numEmp == 6033){ // limiteMensal = OITO_HORAS; // limiteAnual = NOVENTA_SEIS_HORAS; // } else // if (((numEmp == 9008) && (codigoFilial == 111)) || (numEmp == 1538) || // ((numEmp == 9008) && (codigoFilial == 2))){ // limiteSemanal = DUAS_HORAS; // limiteMensal = OITO_HORAS; // limiteAnual = NOVENTA_SEIS_HORAS; // } else // if ((numEmp == 4006)){ // limiteSemanal = QUATRO_HORAS; // limiteMensal = DEZESSEIS_HORAS; // } else{ // limiteMensal = OITO_HORAS; // limiteAnual = TRINTA_DUAS_HORAS; // } // Consiste limite semanal (Somente empresa 6033) (Eliminado em 24/05/2016 - Gabriel Becker) if (limiteSemanal > 0){ int diaSemana = datAfa.dayOfWeek().get(); int xTemp = 6 - diaSemana; LocalDate dataInicial = datAfa.minusDays(diaSemana); LocalDate dataFinal = datAfa.plusDays(xTemp); int totalHorasTreinamento = verificaHistoricosAfastamento(numEmp, tipCol, numCad, dataInicial, dataFinal, codSit); int horas = 0; int minutos = 0; if (totalHorasTreinamento > limiteSemanal){ horas = (int)totalHorasTreinamento / 60; minutos = (totalHorasTreinamento - (horas * 60)); if ((numEmp == 4006)||(numEmp == 4022)||(numEmp == 4030)||(numEmp == 4049)|| (numEmp == 4065)||(numEmp == 4081)||(numEmp == 4103)||(numEmp == 4120)|| ((numEmp == 4014) && (codigoFilial == 5))){ return "Colaborador " + numCad + " atingiu o limite semanal de 4 horas de treinamento: " + String.format("%02d:%02d", horas, minutos); } else{ return "Colaborador " + numCad + " atingiu o limite semanal de 2 horas de treinamento: " + String.format("%02d:%02d", horas, minutos); } } } // Consiste limite mensal int diaInicial = 1; int diaFinal = 31; int mes = datAfa.monthOfYear().get(); int ano = datAfa.year().get(); LocalDate dataInicial = new LocalDate(ano,mes,diaInicial); diaFinal = buscaDiaFinal(mes, ano); LocalDate dataFinal = new LocalDate(ano,mes,diaFinal); int totalHorasTreinamento = verificaHistoricosAfastamento(numEmp, tipCol, numCad, dataInicial, dataFinal, codSit); int horAfa = historicoAfastamento.getHorAfa(); int horTer = historicoAfastamento.getHorTer(); int horas = 0; int minutos = 0; //totalHorasTreinamento = totalHorasTreinamento + (horTer - horAfa); if (limiteMensal > 0){ if (totalHorasTreinamento > limiteMensal){ horas = (int)totalHorasTreinamento / 60; minutos = (totalHorasTreinamento - (horas * 60)); if ((numEmp == 4006)||(numEmp == 4022)||(numEmp == 4030)||(numEmp == 4049)|| (numEmp == 4065)||(numEmp == 4081)||(numEmp == 4103)||(numEmp == 4120)|| ((numEmp == 4014) && (codigoFilial == 5))){ return "Colaborador " + numCad + " atingiu o limite mensal de 16 horas de treinamento: " + String.format("%02d:%02d", horas, minutos); } else{ return "Colaborador " + numCad + " atingiu o limite mensal de 8 horas de treinamento: " + String.format("%02d:%02d", horas, minutos); } } } // Consiste limite anual ano = datAfa.year().get(); dataInicial = new LocalDate(ano,1,1); dataFinal = new LocalDate(ano,12,31); totalHorasTreinamento = verificaHistoricosAfastamento(numEmp, tipCol, numCad, dataInicial, dataFinal, codSit); horAfa = historicoAfastamento.getHorAfa(); horTer = historicoAfastamento.getHorTer(); //totalHorasTreinamento = totalHorasTreinamento + (horTer - horAfa); if (limiteAnual > 0){ if (totalHorasTreinamento > limiteAnual){ horas = (int)totalHorasTreinamento / 60; minutos = (totalHorasTreinamento - (horas * 60)); if ((numEmp == 6033) || ((numEmp == 9008) && (codigoFilial == 111)) || (numEmp == 1538) || ((numEmp == 9008) && (codigoFilial == 2)) || (numEmp == 4014) || (numEmp == 4073) || (numEmp == 4090) || (numEmp == 4111)){ return "Colaborador " + numCad + " atingiu o limite anual de 96 horas de treinamento: " + String.format("%02d:%02d", horas, minutos); } else{ return "Colaborador " + numCad + " atingiu o limite anual de 32 horas de treinamento: " + String.format("%02d:%02d", horas, minutos); } } } } return retorno; } public String validarAfastamentoUpdate(IFieldAccessor field, IHistoricoAfastamento historicoAfastamento, IBookmark bookmark) { String retorno = "True"; int numEmp = historicoAfastamento.getNumEmp(); int tipCol = historicoAfastamento.getTipCol(); int numCad = historicoAfastamento.getNumCad(); LocalDate datAfa = historicoAfastamento.getDatAfa(); LocalDate datTer = historicoAfastamento.getDatTer(); int codigoFilial = retornaFilial(numEmp, tipCol, numCad); boolean isCodSitNull = historicoAfastamento.isCodSitNull(); short codSit = 0; if(!isCodSitNull){ codSit = historicoAfastamento.getCodSit(); } else { return retorno; } if (codSit == 14 || codSit == 32){ if(datTer == null){ retorno = "Para afastamento por atestado a data final deve ser preenchida."; } else{ int diferencaEmDias = Days.daysBetween(datAfa, datTer).getDays(); diferencaEmDias++; if (diferencaEmDias > 15){ retorno = "Afastamento por atestado não pode ser superior a 15 dias, " + "pois o execedente deve ser inserido como auxilio doença ou acidente de trabalho"; } else{ if (diferencaEmDias > 3){ retorno = "Afastamento por atestado maior que 3 dias "; } } } return retorno; } if (codSit == 134){ if (consisteCamposAfastamento (historicoAfastamento)){ retorno = "Não é permitido lançar afastamentos na situação 134 sem os seguintes campos: Hora Afastamento, Data Término e Hora Término."; } int limiteSemanal = 0; int limiteMensal = 0; int limiteAnual = 0; switch (numEmp) { case 6033: limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; break; case 9008: if ((codigoFilial == 111) || (codigoFilial == 2)){ limiteSemanal = DUAS_HORAS; limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; } else{ limiteMensal = OITO_HORAS; limiteAnual = TRINTA_DUAS_HORAS; } break; case 1538: limiteSemanal = DUAS_HORAS; limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; break; case 4006: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4014: if (codigoFilial == 5){ limiteSemanal = DUAS_HORAS; limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; } else{ limiteMensal = QUATRO_HORAS; limiteAnual = DEZESSEIS_HORAS; } break; case 4022: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4030: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4049: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4065: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4073: limiteSemanal = DUAS_HORAS; limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; break; case 4081: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4090: limiteSemanal = DUAS_HORAS; limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; break; case 4103: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; case 4111: limiteSemanal = DUAS_HORAS; limiteMensal = OITO_HORAS; limiteAnual = NOVENTA_SEIS_HORAS; break; case 4120: limiteSemanal = QUATRO_HORAS; limiteMensal = DEZESSEIS_HORAS; break; // case 124: // limiteSemanal = DUAS_HORAS; // break; // case 159: // limiteSemanal = DUAS_HORAS; // break; default: limiteMensal = OITO_HORAS; limiteAnual = TRINTA_DUAS_HORAS; break; } // if (numEmp == 6033){ // limiteMensal = OITO_HORAS; // limiteAnual = NOVENTA_SEIS_HORAS; // } else // if (((numEmp == 9008) && (codigoFilial == 111)) || (numEmp == 1538) || // ((numEmp == 9008) && (codigoFilial == 2))){ // limiteSemanal = DUAS_HORAS; // limiteMensal = OITO_HORAS; // limiteAnual = NOVENTA_SEIS_HORAS; // } else // if ((numEmp == 4006)){ // limiteSemanal = QUATRO_HORAS; // limiteMensal = DEZESSEIS_HORAS; // } else{ // limiteMensal = OITO_HORAS; // limiteAnual = TRINTA_DUAS_HORAS; // } // Consiste limite semanal (Somente empresa 6033) (Eliminado em 24/05/2016 - Gabriel Becker) if (limiteSemanal > 0){ int diaSemana = datAfa.dayOfWeek().get(); int xTemp = 6 - diaSemana; LocalDate dataInicial = datAfa.minusDays(diaSemana); LocalDate dataFinal = datAfa.plusDays(xTemp); int totalHorasTreinamento = verificaHistoricosAfastamento(numEmp, tipCol, numCad, dataInicial, dataFinal, codSit); int horas = 0; int minutos = 0; if (totalHorasTreinamento > limiteSemanal){ horas = (int)totalHorasTreinamento / 60; minutos = (totalHorasTreinamento - (horas * 60)); if ((numEmp == 4006)||(numEmp == 4022)||(numEmp == 4030)||(numEmp == 4049)|| (numEmp == 4065)||(numEmp == 4081)||(numEmp == 4103)||(numEmp == 4120)|| ((numEmp == 4014) && (codigoFilial == 5))){ return "Colaborador " + numCad + " atingiu o limite semanal de 4 horas de treinamento: " + String.format("%02d:%02d", horas, minutos); } else{ return "Colaborador " + numCad + " atingiu o limite semanal de 2 horas de treinamento: " + String.format("%02d:%02d", horas, minutos); } } } // Consiste limite mensal int diaInicial = 1; int diaFinal = 31; int mes = datAfa.monthOfYear().get(); int ano = datAfa.year().get(); LocalDate dataInicial = new LocalDate(ano,mes,diaInicial); diaFinal = buscaDiaFinal(mes, ano); LocalDate dataFinal = new LocalDate(ano,mes,diaFinal); int totalHorasTreinamento = verificaHistoricosAfastamento(numEmp, tipCol, numCad, dataInicial, dataFinal, codSit); int horAfa = historicoAfastamento.getHorAfa(); int horTer = historicoAfastamento.getHorTer(); int horas = 0; int minutos = 0; //totalHorasTreinamento = totalHorasTreinamento + (horTer - horAfa); if (limiteMensal > 0){ if (totalHorasTreinamento > limiteMensal){ horas = (int)totalHorasTreinamento / 60; minutos = (totalHorasTreinamento - (horas * 60)); if ((numEmp == 4006)||(numEmp == 4022)||(numEmp == 4030)||(numEmp == 4049)|| (numEmp == 4065)||(numEmp == 4081)||(numEmp == 4103)||(numEmp == 4120)|| ((numEmp == 4014) && (codigoFilial == 5))){ return "Colaborador " + numCad + " atingiu o limite mensal de 16 horas de treinamento: " + String.format("%02d:%02d", horas, minutos); } else{ return "Colaborador " + numCad + " atingiu o limite mensal de 8 horas de treinamento: " + String.format("%02d:%02d", horas, minutos); } } } // Consiste limite anual ano = datAfa.year().get(); dataInicial = new LocalDate(ano,1,1); dataFinal = new LocalDate(ano,12,31); totalHorasTreinamento = verificaHistoricosAfastamento(numEmp, tipCol, numCad, dataInicial, dataFinal, codSit); horAfa = historicoAfastamento.getHorAfa(); horTer = historicoAfastamento.getHorTer(); //totalHorasTreinamento = totalHorasTreinamento + (horTer - horAfa); if (limiteAnual > 0){ if (totalHorasTreinamento > limiteAnual){ horas = (int)totalHorasTreinamento / 60; minutos = (totalHorasTreinamento - (horas * 60)); if ((numEmp == 6033) || ((numEmp == 9008) && (codigoFilial == 111)) || (numEmp == 1538) || ((numEmp == 9008) && (codigoFilial == 2)) || (numEmp == 4014) || (numEmp == 4073) || (numEmp == 4090) || (numEmp == 4111)){ return "Colaborador " + numCad + " atingiu o limite anual de 96 horas de treinamento: " + String.format("%02d:%02d", horas, minutos); } else{ return "Colaborador " + numCad + " atingiu o limite anual de 32 horas de treinamento: " + String.format("%02d:%02d", horas, minutos); } } } } return retorno; } public String validarAfastamentoRemove(IFieldAccessor field, IHistoricoAfastamento historicoAfastamento, IBookmark bookmark) { String retorno = "True"; return retorno; } /** * Busca o dia final para montagem da data final do mês. * @param mes, - mês * @param ano, - ano * @return diaFinal - Dia final para montar a data */ public int buscaDiaFinal(int mes, int ano){ int diaFinal = 31; if ((mes==1)||(mes==3)||(mes==5)||(mes==7)||(mes==8)||(mes==10)||(mes==12)) { diaFinal = 31; } else { if ((mes==4)||(mes==6)||(mes==9)||(mes==11)) { diaFinal = 30; } else { if ((mes==2) && ((ano==2016)||(ano==2020)||(ano==2024)||(ano==2028))) { diaFinal = 29; } else { diaFinal = 28; } } } return diaFinal; } /** * Verifica históricos de afastamento do colaborador no período. * @param numemp, - Empresa do colaborador * @param tipcol, - Tipo do colaborador * @param numcad, - Cadastro do colaborador * @param dataInicial - Data inicial do período de afastamentos * @param dataFinal - Data final do período de afastamentos * @param codigoSituacao - Código da situação dos afastamentos * @return totalHorasTreinamento - Total de horas na situação, no período */ public int verificaHistoricosAfastamento(int numEmp, int tipCol, int numCad, LocalDate dataInicial, LocalDate dataFinal, short codigoSituacao) { MappedParamProvider mapa = new MappedParamProvider(); mapa.setParam("NumEmp", numEmp); mapa.setParam("TipCol", tipCol); mapa.setParam("NumCad", numCad); mapa.setParam("DatAfa", dataInicial); mapa.setParam("DatTer", dataFinal); mapa.setParam("CodSit", codigoSituacao); int totalHorasTreinamento = 0; ICursor crR038AFA = getEntitySession().newCursor(IHistoricoAfastamento.class); crR038AFA.addFilter("NumEmp = :NumEmp AND TipCol = :TipCol AND NumCad = :NumCad " + "AND DatAfa>= :DatAfa AND DatAfa<=:DatTer AND CodSit=:CodSit", mapa); crR038AFA.open(); try { while (crR038AFA.next()) { IHistoricoAfastamento horTre = crR038AFA.read(); totalHorasTreinamento = totalHorasTreinamento + (horTre.getHorTer() - horTre.getHorAfa()); } return totalHorasTreinamento; } finally { crR038AFA.close(); } } /** * Verifica histórico de afastamento que está sendo alterado. * @param numemp, - Empresa do colaborador * @param tipcol, - Tipo do colaborador * @param numcad, - Cadastro do colaborador * @param dataInicial - Data inicial do afastamento * @param horaInicial - Hora inicial do afastamento * @param codigoSituacao - Código da situação do afastamento * @return totalHorasTreinamento - Total de horas na situação, no período */ public int verificaHistoricoAfastamentoAlterado(int numEmp, int tipCol, int numCad, LocalDate dataInicial, int horaInicial, short codigoSituacao) { ICursor crR038AFA = getEntitySession().newCursor(IHistoricoAfastamento.class); IHistoricoAfastamento buffer = crR038AFA.newBuffer(); buffer.setNumEmp(numEmp); buffer.setTipCol(tipCol); buffer.setNumCad(numCad); buffer.setDatAfa(dataInicial); buffer.setHorAfa(horaInicial); buffer.setCodSit(codigoSituacao); int totalHorasTreinamento = 0; crR038AFA.open(); try { if (crR038AFA.search(buffer, SearchMode.EXACT_MATCH)) { crR038AFA.read(buffer); totalHorasTreinamento = buffer.getHorTer() - buffer.getHorAfa(); } return totalHorasTreinamento; } finally { crR038AFA.close(); } } /** * Consiste os campos do Histórico de Afastamento. * @param hisAfastamento, - Histórico de afastamento * @return boolean - True - inconsistentes / False - consistentes */ private boolean consisteCamposAfastamento(IHistoricoAfastamento hisAfastamento) { int horAfa = hisAfastamento.getHorAfa(); int horTer = hisAfastamento.getHorTer(); LocalDate datTer = hisAfastamento.getDatTer(); LocalDate dataZero = new LocalDate(); if ((horAfa == 0) || (horTer == 0) || (datTer.isEqual(dataZero))){ return true; } return false; } /** * Retorna código da Filial * @param numemp - Empresa do colaborador * @param tipcol - Tipo do colaborador * @param numcad - Cadastro do colaborador * @return int - Código da Filial */ public int retornaFilial(int numEmp, int tipCol, int numCad) { MappedParamProvider mapa_usu = new MappedParamProvider(); mapa_usu.setParam("NumEmp", numEmp); mapa_usu.setParam("TipCol", tipCol); mapa_usu.setParam("NumCad", numCad); ICursor crR034FUN = getEntitySession().newCursor(IR034FUN.class); crR034FUN.addFilter("NumEmp = :NumEmp AND TipCol = :TipCol AND NumCad = :NumCad", mapa_usu); crR034FUN.open(); try { if (crR034FUN.first()) { IR034FUN filial = crR034FUN.read(); if (!filial.isCodFilNull()){ return filial.getCodFil(); } } } finally { crR034FUN.close(); } return 0; } }