diff --git a/trunk/PlanosActuacao/src/db/providers/PlanosDataProvider.java b/trunk/PlanosActuacao/src/db/providers/PlanosDataProvider.java index 0cc0439b..5f69e45a 100644 --- a/trunk/PlanosActuacao/src/db/providers/PlanosDataProvider.java +++ b/trunk/PlanosActuacao/src/db/providers/PlanosDataProvider.java @@ -17,6 +17,7 @@ import com.evolute.utils.sql.Select2; import com.evolute.utils.sql.Update; import com.evolute.utils.sql.expression.Par; import com.evolute.utils.strings.StringPlainer; +import com.sun.webui.jsf.model.Option; import db.data.siprp.outer.EstadoMedidasData; import db.data.siprp.outer.PlanoAreasData; import db.data.siprp.outer.PlanoMedidasData; @@ -24,6 +25,8 @@ import db.data.siprp.outer.PlanoPostosTrabalhoData; import db.data.siprp.outer.PlanoRiscosData; import db.data.siprp.outer.PlanoValoresQualitativosData; import db.data.siprp.outer.PlanosActuacaoData; +import db.data.siprp_local.outer.EmpresasData; +import db.data.siprp_local.outer.EstabelecimentosData; import db.entidades.Area; import db.entidades.EstadoMedida; import db.entidades.LinhaEstatistica; @@ -69,6 +72,84 @@ public class PlanosDataProvider extends GenericDataProvider } return INSTANCE; } + + public Option[] getEstabelecimentos( Integer selectedEmpresa ) throws Exception + { + Option[] options = null; + + Expression where = new Field( db.data.siprp_local.outer.EstabelecimentosData.INACTIVO_FULL ).isDifferent( "y" ); + + if( selectedEmpresa != null ) + { + where = where.and( new Field( EstabelecimentosData.EMPRESA_ID_FULL ).isEqual( selectedEmpresa ) ); + } + + Select2 query = new Select2( + new String[] { db.data.siprp_local.outer.EstabelecimentosData.TABLENAME }, + new Integer[] { }, + new Expression[] {}, + new String[] { + db.data.siprp_local.outer.EstabelecimentosData.ID_FULL, db.data.siprp_local.outer.EstabelecimentosData.NOME_FULL + }, + where, + new String[] { db.data.siprp_local.outer.EstabelecimentosData.NOME_FULL }, + null, null, null ); + Virtual2DArray array = getLocalExecuter().executeQuery( query ); + if ( array != null ) + { + options = new Option[ array.rowCount() + 1 ]; + options[ 0 ] = new Option( "", "" ); + for ( int i = 0; i < array.rowCount(); i++ ) + { + Integer estabelecimentoID = array.get( i, 0 ); + String estabelecimentoNome = array.get( i, 1 ); + options[ ( i + 1 ) ] = new Option( estabelecimentoID, estabelecimentoNome ); + } + } + return options; + } + + public String getEstabelecimentoByID( Integer estabelecimentoID ) throws Exception + { + String estabelecimento = ""; + db.data.siprp_local.outer.EstabelecimentosData estabelecimentoData = getLocalProvider().load( db.data.siprp_local.outer.EstabelecimentosData.class, estabelecimentoID, db.data.siprp_local.outer.EstabelecimentosData.ID, null ); + if ( estabelecimentoData != null ) + { + estabelecimento = estabelecimentoData.getNome(); + } + return estabelecimento; + } + + public Option[] getEmpresas( ) throws Exception + { + Option[] options = null; + + Expression where = new Field( db.data.siprp_local.outer.EmpresasData.INACTIVO_FULL ).isDifferent( "y" ) + .and( new Field( EmpresasData.ID_FULL ).in( new Integer[] { 142, 85, 219, 32 } ) ); + + Select2 query = new Select2( + new String[] { db.data.siprp_local.outer.EmpresasData.TABLENAME }, + new Integer[] { }, + new Expression[] {}, + new String[] { + db.data.siprp_local.outer.EmpresasData.ID_FULL, EmpresasData.DESIGNACAO_SOCIAL_FULL + }, + where, + new String[] { EmpresasData.DESIGNACAO_SOCIAL_FULL }, + null, null, null ); + Virtual2DArray array = getLocalExecuter().executeQuery( query ); + if ( array != null ) + { + options = new Option[ array.rowCount() ]; + for ( int i = 0; i < array.rowCount(); i++ ) + { + Integer empresaID = array.get( i, 0 ); + String empresaNome = array.get( i, 1 ); + options[i] = new Option( empresaID, empresaNome ); + } + } + return options; + } public void updatePlano( PlanoActuacao p ) throws Exception { @@ -208,7 +289,8 @@ public class PlanosDataProvider extends GenericDataProvider private enum SECTION { ACTIVOS, SEGUIMENTO, CONCLUIDOS } - private Select2 getExpression( SECTION section, Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano ) + private Select2 getExpression( SECTION section, Utilizador u, String nome, Integer empresa, String estabelecimento, + String dataVisita, Integer ano ) { Expression where = getWhereExpression( nome, estabelecimento, dataVisita ); Expression faseExpression = null; @@ -232,6 +314,12 @@ public class PlanosDataProvider extends GenericDataProvider { where = where.and( new Field( "EXTRACT( year FROM " + PlanosActuacaoData.DATA_VISITA_FULL + " )" ).isEqual( ano) ); } + + if( empresa != null ) + { + where = where.and( new Field( PlanosActuacaoData.EMPRESA_ID_FULL ).isEqual( empresa ) ); + } + Select2 query = new Select2( new String[] { PlanosActuacaoData.TABLENAME, PlanoAreasData.TABLENAME, PlanoRiscosData.TABLENAME }, new Integer[] { Select2.JOIN_INNER, Select2.JOIN_INNER }, @@ -315,12 +403,13 @@ public class PlanosDataProvider extends GenericDataProvider } - public List< PlanoActuacao > searchPlanosActivos( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano ) + public List< PlanoActuacao > searchPlanosActivos( Utilizador u, String nome, Integer empresa, String estabelecimento, + String dataVisita, Integer ano ) throws Exception { System.out.println( "\nPlanosDataProvider . searchPlanosActivos() : " ); - Select2 query = getExpression( SECTION.ACTIVOS, u, nome, estabelecimento, dataVisita, ano ); + Select2 query = getExpression( SECTION.ACTIVOS, u, nome, empresa, estabelecimento, dataVisita, ano ); System.out.println( "\tSQL : " + query ); Virtual2DArray array = getExecuter().executeQuery( query ); @@ -328,24 +417,27 @@ public class PlanosDataProvider extends GenericDataProvider } - public List< PlanoActuacao > searchPlanosSeguimento( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano ) + public List< PlanoActuacao > searchPlanosSeguimento( Utilizador u, String nome, Integer empresa, String + estabelecimento, String dataVisita, Integer ano ) throws Exception { System.out.println( "\nPlanosDataProvider . searchPlanosSeguimento() : " ); - Select2 query = getExpression( SECTION.SEGUIMENTO, u, nome, estabelecimento, dataVisita, ano ); + Select2 query = getExpression( SECTION.SEGUIMENTO, u, nome, empresa, estabelecimento, dataVisita, ano ); System.out.println( "\tSQL : " + query ); Virtual2DArray array = getExecuter().executeQuery( query ); return getFullPlanos( array ); } - public List< PlanoActuacao > searchPlanosConcluidos( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano ) + public List< PlanoActuacao > searchPlanosConcluidos( Utilizador u, String nome, Integer empresa, String + estabelecimento, + String dataVisita, Integer ano ) throws Exception { System.out.println( "\nPlanosDataProvider . searchPlanosConcluidos() : " ); - Select2 query = getExpression( SECTION.CONCLUIDOS, u, nome, estabelecimento, dataVisita, ano ); + Select2 query = getExpression( SECTION.CONCLUIDOS, u, nome, empresa, estabelecimento, dataVisita, ano ); System.out.println( "\tSQL : " + query ); Virtual2DArray array = getExecuter().executeQuery( query ); @@ -946,7 +1038,9 @@ public class PlanosDataProvider extends GenericDataProvider return linhas; } - public List getEstatisticaForEstabelecimentoIdAndDateInterval( Integer estabelecimentoId, Date dataInicio, Date dataFim ) + public List getEstatisticaForEstabelecimentoIdAndDateInterval( Integer empresa, + Integer estabelecimentoId, + Date dataInicio, Date dataFim ) throws Exception { Expression expr = null; @@ -954,6 +1048,12 @@ public class PlanosDataProvider extends GenericDataProvider { expr = new Field( PlanosActuacaoData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoId); } + + if( empresa != null ) + { + expr = new Field( PlanosActuacaoData.EMPRESA_ID_FULL ).isEqual( empresa ); + } + if( dataInicio != null ) { Expression diExpr = new Field( PlanosActuacaoData.DATA_VISITA_FULL ).isGreaterOrEqual( dataInicio); diff --git a/trunk/PlanosActuacao/src/db/providers/UtilizadoresDataProvider.java b/trunk/PlanosActuacao/src/db/providers/UtilizadoresDataProvider.java index ad171db6..c6bbd927 100644 --- a/trunk/PlanosActuacao/src/db/providers/UtilizadoresDataProvider.java +++ b/trunk/PlanosActuacao/src/db/providers/UtilizadoresDataProvider.java @@ -15,6 +15,8 @@ import db.data.siprp.outer.EmpresasData; import db.data.siprp.outer.UtilizadoresData; import db.entidades.Utilizador; import utils.Global; + +import java.text.MessageFormat; import java.util.LinkedList; import java.util.List; @@ -155,13 +157,18 @@ public class UtilizadoresDataProvider extends GenericDataProvider public Boolean isSiprp( Utilizador utilizador ) throws DBException { Select select = new Select2( EmpresasData.TABLENAME, new Field( EmpresasData.DESIGNACAO_SOCIAL_FULL ).isILike( "siprp%" ) - .and( new Field( EmpresasData.ID_FULL ).isEqual( utilizador.getEmpresa_id() ) ), "1" ); + .and( new Field( EmpresasData.ID_FULL ).isEqual( utilizador.getEmpresa_id() ) ), "1" ); - Select outer = new Select( "select exists( " + select.toString() + " )" ); + Select outer = new Select( MessageFormat.format( "select exists( {0} )", select.toString() ) ); Virtual2DArray array = getExecuter().executeQuery( outer ); - return array.rowCount() > 0 ? ( Boolean ) array.get( 0, 1 ) : Boolean.FALSE; + Boolean result = Boolean.FALSE; + if( array.rowCount() > 0 ) + { + result = array.get( 0, 0 ); + } + return result; } } diff --git a/trunk/PlanosActuacao/src/planosactuacao/Estatistica.java b/trunk/PlanosActuacao/src/planosactuacao/Estatistica.java index 3931a827..a11b24aa 100644 --- a/trunk/PlanosActuacao/src/planosactuacao/Estatistica.java +++ b/trunk/PlanosActuacao/src/planosactuacao/Estatistica.java @@ -15,10 +15,14 @@ import com.sun.webui.jsf.component.TableRowGroup; import com.sun.webui.jsf.model.Option; import db.entidades.LinhaEstatistica; import db.providers.PlanosDataProvider; +import utils.Global; +import utils.Utils; + import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.faces.FacesException; +import javax.faces.event.ValueChangeEvent; /** *

Page bean that corresponds to a similarly named JSP page. This @@ -83,7 +87,22 @@ public class Estatistica extends AbstractPageBean { // *Note* - this logic should NOT be modified try { _init(); - fillEstabelecimentosDrop(); + + siprp = getSessionBean1().isSiprp(); + + Utils.fillEmpresas( dropEmpresas ); + + if( !siprp ) + { + Utils.fillEstabelecimentos( getSessionBean1().getCurrentUser().getEmpresa_id(), dropEstabelecimento ); + dropEmpresas.setSelected( getSessionBean1().getCurrentUser().getEmpresa_id() ); + } + else + { + Utils.fillEstabelecimentos( Global.AUCHAN, dropEstabelecimento ); + dropEmpresas.setSelected( Global.AUCHAN ); + } + } catch (Exception e) { log("Estatistica Initialization Failure", e); throw e instanceof FacesException ? (FacesException) e: new FacesException(e); @@ -222,6 +241,48 @@ public class Estatistica extends AbstractPageBean { this.tableRowGroupEstatisticas = tableRowGroupEstatisticas; } + private DropDown dropEmpresas = new DropDown(); + + public void setDropEmpresas( DropDown dropEmpresas ) + { + this.dropEmpresas = dropEmpresas; + } + + public void dropEmpresas_valueChangeListener( ValueChangeEvent event ) + { + Integer _old; + Integer _new; + if( event.getNewValue() != null && event.getNewValue() instanceof Integer ) + { + _new = ( Integer ) event.getNewValue(); + _old = event.getOldValue() != null && + event.getOldValue() instanceof Integer ? ( Integer ) event.getOldValue() : null; + + if( _old == null || !_new.equals( _old ) ) + { + Utils.fillEstabelecimentos( _new, dropEstabelecimento ); + dropEstabelecimento.setSelected( null ); + } + } + } + + public DropDown getDropEmpresas() + { + return dropEmpresas; + } + + private Boolean siprp = Boolean.FALSE; + + public Boolean getSiprp() + { + return siprp; + } + + public void setSiprp( Boolean siprp ) + { + this.siprp = siprp; + } + public String buttonPesquisar_action() { System.out.println( "ACTION" ); @@ -229,21 +290,33 @@ public class Estatistica extends AbstractPageBean { try { Integer estabelecimentoId = null; - if ( dropEstabelecimento.getSelected() != null ) + + Integer selectedEmpresa; + if( dropEmpresas.getSelected() instanceof Integer ) + { + selectedEmpresa = ( Integer ) dropEmpresas.getSelected(); + } + else { - String estabelecimento = ( String ) dropEstabelecimento.getSelected(); - if ( estabelecimento != null ) - { - try { - estabelecimentoId = Integer.parseInt( estabelecimento ); - } - catch ( Exception e ) - { - e.printStackTrace(); - } - } + selectedEmpresa = Utils.getSelectedID( dropEmpresas ); } - linhasEstatistica = PlanosDataProvider.getInstance().getEstatisticaForEstabelecimentoIdAndDateInterval( estabelecimentoId, calInicioDate, calFimDate ); + + if( selectedEmpresa == null ) + { + selectedEmpresa = getSessionBean1().getCurrentUser().getEmpresa_id(); + } + + if( dropEstabelecimento.getSelected() instanceof Integer ) + { + estabelecimentoId = ( Integer ) dropEstabelecimento.getSelected(); + } + else + { + estabelecimentoId = Utils.getSelectedID( dropEstabelecimento ); + } + + linhasEstatistica = PlanosDataProvider.getInstance().getEstatisticaForEstabelecimentoIdAndDateInterval( + selectedEmpresa, estabelecimentoId, calInicioDate, calFimDate ); System.out.println( "LINHAS: " + linhasEstatistica.size() ); } catch( Exception ex ) diff --git a/trunk/PlanosActuacao/src/planosactuacao/ListaPlanos.java b/trunk/PlanosActuacao/src/planosactuacao/ListaPlanos.java index 7f39f3a9..3dc46631 100644 --- a/trunk/PlanosActuacao/src/planosactuacao/ListaPlanos.java +++ b/trunk/PlanosActuacao/src/planosactuacao/ListaPlanos.java @@ -486,6 +486,9 @@ public class ListaPlanos extends AbstractPageBean // Perform application initialization that must complete // *after* managed components are initialized // TODO - add your own initialization code here + + siprp = getSessionBean1().isSiprp(); + } /** @@ -500,6 +503,138 @@ public class ListaPlanos extends AbstractPageBean { } + private Boolean siprp = Boolean.FALSE; + + public Boolean getSiprp() + { + return siprp; + } + + public void setSiprp( Boolean siprp ) + { + this.siprp = siprp; + } + + private DropDown dropEmpresasActuais = new DropDown(); + + public void setDropEmpresasActuais( DropDown dropEmpresasActuais ) + { + this.dropEmpresasActuais = dropEmpresasActuais; + } + + public void dropEmpresasActuais_valueChangeListener( ValueChangeEvent event ) + { + Integer _old; + Integer _new; + if( event.getNewValue() != null && event.getNewValue() instanceof Integer ) + { + _new = ( Integer ) event.getNewValue(); + _old = event.getOldValue() != null && + event.getOldValue() instanceof Integer ? ( Integer ) event.getOldValue() : null; + + if( _old == null || !_new.equals( _old ) ) + { + Utils.fillEstabelecimentos( _new, dropEstabelecimentosActuais ); + dropEstabelecimentosActuais.setSelected( null ); + } + } + } + + public DropDown getDropEmpresasActuais() + { + return dropEmpresasActuais; + } + + private DropDown dropEstabelecimentosActuais = new DropDown(); + public DropDown getDropEstabelecimentosActuais() + { + return dropEstabelecimentosActuais; + } + public void setDropEstabelecimentosActuais( DropDown dropEstabelecimentos ) + { + this.dropEstabelecimentosActuais = dropEstabelecimentos; + } + + private DropDown dropEmpresasSeguimento = new DropDown(); + + public void setDropEmpresasSeguimento( DropDown dropEmpresasSeguimento ) + { + this.dropEmpresasSeguimento = dropEmpresasSeguimento; + } + + public void dropEmpresasSeguimento_valueChangeListener( ValueChangeEvent event ) + { + Integer _old; + Integer _new; + if( event.getNewValue() != null && event.getNewValue() instanceof Integer ) + { + _new = ( Integer ) event.getNewValue(); + _old = event.getOldValue() != null && + event.getOldValue() instanceof Integer ? ( Integer ) event.getOldValue() : null; + + if( _old == null || !_new.equals( _old ) ) + { + Utils.fillEstabelecimentos( _new, dropEstabelecimentosSeguimento ); + dropEstabelecimentosSeguimento.setSelected( null ); + } + } + } + + public DropDown getDropEmpresasSeguimento() + { + return dropEmpresasSeguimento; + } + + private DropDown dropEstabelecimentosSeguimento = new DropDown(); + public DropDown getDropEstabelecimentosSeguimento() + { + return dropEstabelecimentosSeguimento; + } + public void setDropEstabelecimentosSeguimento( DropDown dropEstabelecimentos ) + { + this.dropEstabelecimentosSeguimento = dropEstabelecimentos; + } + + private DropDown dropEmpresasConclusao = new DropDown(); + + public void setDropEmpresasConclusao( DropDown dropEmpresasConclusao ) + { + this.dropEmpresasConclusao = dropEmpresasConclusao; + } + + public void dropEmpresasConclusao_valueChangeListener( ValueChangeEvent event ) + { + Integer _old; + Integer _new; + if( event.getNewValue() != null && event.getNewValue() instanceof Integer ) + { + _new = ( Integer ) event.getNewValue(); + _old = event.getOldValue() != null && + event.getOldValue() instanceof Integer ? ( Integer ) event.getOldValue() : null; + + if( _old == null || !_new.equals( _old ) ) + { + Utils.fillEstabelecimentos( _new, dropEstabelecimentosConclusao ); + dropEstabelecimentosConclusao.setSelected( null ); + } + } + } + + public DropDown getDropEmpresasConclusao() + { + return dropEmpresasConclusao; + } + + private DropDown dropEstabelecimentosConclusao = new DropDown(); + public DropDown getDropEstabelecimentosConclusao() + { + return dropEstabelecimentosConclusao; + } + public void setDropEstabelecimentosConclusao( DropDown dropEstabelecimentos ) + { + this.dropEstabelecimentosConclusao = dropEstabelecimentos; + } + /** *

Callback method that is called just before rendering takes place. * This method will only be called for the page that @@ -515,10 +650,30 @@ public class ListaPlanos extends AbstractPageBean HttpServletRequest request = ( HttpServletRequest ) getExternalContext().getRequest(); String referer = request.getRequestURI(); String pageFrom = Utils.getPageFrom( referer ); - if ( !pageFrom.matches( "FormMedico.jsp" ) - || dropCurrentYear.getItems() == null ) + + if ( !pageFrom.matches( "ListaPlanos.jsp" ) || dropCurrentYear.getItems() == null ) { fillCurrentYearDrop(); + + Utils.fillEmpresas( dropEmpresasActuais, dropEmpresasSeguimento, dropEmpresasConclusao ); + + if( !siprp ) + { + dropEmpresasActuais.setSelected( getSessionBean1().getCurrentUser().getEmpresa_id() ); + dropEmpresasSeguimento.setSelected( getSessionBean1().getCurrentUser().getEmpresa_id() ); + dropEmpresasConclusao.setSelected( getSessionBean1().getCurrentUser().getEmpresa_id() ); + Utils.fillEstabelecimentos( getSessionBean1().getCurrentUser().getEmpresa_id(), + dropEstabelecimentosActuais, dropEstabelecimentosSeguimento, dropEstabelecimentosConclusao ); + } + else + { + dropEmpresasActuais.setSelected( Global.AUCHAN ); + dropEmpresasSeguimento.setSelected( Global.AUCHAN ); + dropEmpresasConclusao.setSelected( Global.AUCHAN ); + Utils.fillEstabelecimentos( Global.AUCHAN, + dropEstabelecimentosActuais, dropEstabelecimentosSeguimento, dropEstabelecimentosConclusao ); + } + fillInitialForm(); } } @@ -886,7 +1041,8 @@ public class ListaPlanos extends AbstractPageBean } - private List< PlanoActuacao > searchPlanosActivos( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano ) + private List< PlanoActuacao > searchPlanosActivos( Utilizador u, String nome, Integer empresa, String + estabelecimento, String dataVisita, Integer ano ) { List< PlanoActuacao > list = null; try @@ -894,7 +1050,7 @@ public class ListaPlanos extends AbstractPageBean if ( u.getTipo().intValue() != Global.DIRECTOR_SIPRP && u.getTipo().intValue() != Global.GESTOR && u.getTipo().intValue() != Global.DIRECTOR_GERAL_RH ) { PlanosDataProvider pdp = PlanosDataProvider.getInstance(); - list = pdp.searchPlanosActivos( u, nome, estabelecimento, dataVisita, ano ); + list = pdp.searchPlanosActivos( u, nome, empresa, estabelecimento, dataVisita, ano ); } } catch ( Exception e ) @@ -906,16 +1062,17 @@ public class ListaPlanos extends AbstractPageBean private List getPlanosActivos( Utilizador u, Integer ano ) { - return searchPlanosActivos( u, null, null, null, ano ); + return searchPlanosActivos( u, null, u.getEmpresa_id(), null, null, ano ); } - private List< PlanoActuacao > searchPlanosSeguimento( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano ) + private List< PlanoActuacao > searchPlanosSeguimento( Utilizador u, String nome, Integer empresa, + String estabelecimento, String dataVisita, Integer ano ) { List< PlanoActuacao > list = null; try { PlanosDataProvider pdp = PlanosDataProvider.getInstance(); - list = pdp.searchPlanosSeguimento( u, nome, estabelecimento, dataVisita, ano ); + list = pdp.searchPlanosSeguimento( u, nome, empresa, estabelecimento, dataVisita, ano ); } catch ( Exception ex ) { @@ -926,16 +1083,17 @@ public class ListaPlanos extends AbstractPageBean private List< PlanoActuacao > getPlanosSeguimento( Utilizador u, Integer ano ) { - return searchPlanosSeguimento( u, null, null, null, ano ); + return searchPlanosSeguimento( u, null, u.getEmpresa_id(), null, null, ano ); } - private List< PlanoActuacao > searchPlanosConcluidos( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano ) + private List< PlanoActuacao > searchPlanosConcluidos( Utilizador u, String nome, Integer empresa, + String estabelecimento, String dataVisita, Integer ano ) { List< PlanoActuacao > list = null; try { PlanosDataProvider pdp = PlanosDataProvider.getInstance(); - list = pdp.searchPlanosConcluidos( u, nome, estabelecimento, dataVisita, ano ); + list = pdp.searchPlanosConcluidos( u, nome, empresa, estabelecimento, dataVisita, ano ); } catch ( Exception ex ) { @@ -946,7 +1104,7 @@ public class ListaPlanos extends AbstractPageBean private List< PlanoActuacao > getPlanosConcluidos( Utilizador u, Integer ano ) { - return searchPlanosConcluidos( u, null, null, null, ano ); + return searchPlanosConcluidos( u, null, u.getEmpresa_id(), null, null, ano ); } public String buttonFilterActual_action() @@ -962,13 +1120,39 @@ public class ListaPlanos extends AbstractPageBean } String estabelecimento = null; - if ( textFilterEstabelecimentoActual.getText() != null ) + + Integer selectedEmpresa; + if( dropEmpresasActuais.getSelected() instanceof Integer ) { - estabelecimento = ( ( String ) textFilterEstabelecimentoActual.getText() ).trim(); - if ( estabelecimento.length() == 0 ) - { - estabelecimento = null; - } + selectedEmpresa = ( Integer ) dropEmpresasActuais.getSelected(); + } + else + { + selectedEmpresa = Utils.getSelectedID( dropEmpresasActuais ); + } + + if( selectedEmpresa == null ) + { + selectedEmpresa = getSessionBean1().getCurrentUser().getEmpresa_id(); + } + + Integer estabelecimentoID; + if( dropEstabelecimentosActuais.getSelected() instanceof Integer ) + { + estabelecimentoID = ( Integer ) dropEstabelecimentosActuais.getSelected(); + } + else + { + estabelecimentoID = Utils.getSelectedID( dropEstabelecimentosActuais ); + } + + try + { + estabelecimento = PlanosDataProvider.getInstance().getEstabelecimentoByID( estabelecimentoID ); + } + catch( Exception e ) + { + ErrorLogger.logException( e ); } String visitaDateStr = calFilterDate == null ? null : D_F.format( calFilterDate ); @@ -977,7 +1161,8 @@ public class ListaPlanos extends AbstractPageBean getSessionBean1().setIsSearchingPlanosActuacao( Boolean.TRUE ); getSessionBean1().getPlanosActualDataProvider().setList( - searchPlanosActivos( getSessionBean1().getCurrentUser(), nome, estabelecimento, visitaDateStr, ano ) ); + searchPlanosActivos( getSessionBean1().getCurrentUser(), nome, selectedEmpresa, estabelecimento, visitaDateStr, + ano ) ); return null; } @@ -995,13 +1180,39 @@ public class ListaPlanos extends AbstractPageBean } String estabelecimento = null; - if ( textFilterEstabelecimentoSeg.getText() != null ) + + Integer selectedEmpresa; + if( dropEmpresasSeguimento.getSelected() instanceof Integer ) { - estabelecimento = ( ( String ) textFilterEstabelecimentoSeg.getText() ).trim(); - if ( estabelecimento.length() == 0 ) - { - estabelecimento = null; - } + selectedEmpresa = ( Integer ) dropEmpresasSeguimento.getSelected(); + } + else + { + selectedEmpresa = Utils.getSelectedID( dropEmpresasSeguimento ); + } + + if( selectedEmpresa == null ) + { + selectedEmpresa = getSessionBean1().getCurrentUser().getEmpresa_id(); + } + + Integer estabelecimentoID; + if( dropEstabelecimentosSeguimento.getSelected() instanceof Integer ) + { + estabelecimentoID = ( Integer ) dropEstabelecimentosSeguimento.getSelected(); + } + else + { + estabelecimentoID = Utils.getSelectedID( dropEstabelecimentosSeguimento ); + } + + try + { + estabelecimento = PlanosDataProvider.getInstance().getEstabelecimentoByID( estabelecimentoID ); + } + catch( Exception e ) + { + ErrorLogger.logException( e ); } String visitaDateStr = calFilterDateSeguimento == null ? null : D_F.format( calFilterDateSeguimento ); @@ -1010,7 +1221,8 @@ public class ListaPlanos extends AbstractPageBean getSessionBean1().setIsSearchingPlanosActuacao( Boolean.TRUE ); getSessionBean1().getPlanosSeguimentoDataProvider().setList( - searchPlanosSeguimento( getSessionBean1().getCurrentUser(), nome, estabelecimento, visitaDateStr, ano ) ); + searchPlanosSeguimento( getSessionBean1().getCurrentUser(), nome, selectedEmpresa, estabelecimento, + visitaDateStr, ano ) ); return null; } @@ -1028,13 +1240,39 @@ public class ListaPlanos extends AbstractPageBean } String estabelecimento = null; - if ( textFilterEstabelecimentoConc.getText() != null ) + + Integer selectedEmpresa; + if( dropEmpresasConclusao.getSelected() instanceof Integer ) { - estabelecimento = ( ( String ) textFilterEstabelecimentoConc.getText() ).trim(); - if ( estabelecimento.length() == 0 ) - { - estabelecimento = null; - } + selectedEmpresa = ( Integer ) dropEmpresasConclusao.getSelected(); + } + else + { + selectedEmpresa = Utils.getSelectedID( dropEmpresasConclusao ); + } + + if( selectedEmpresa == null ) + { + selectedEmpresa = getSessionBean1().getCurrentUser().getEmpresa_id(); + } + + Integer estabelecimentoID; + if( dropEstabelecimentosConclusao.getSelected() instanceof Integer ) + { + estabelecimentoID = ( Integer ) dropEstabelecimentosConclusao.getSelected(); + } + else + { + estabelecimentoID = Utils.getSelectedID( dropEstabelecimentosConclusao ); + } + + try + { + estabelecimento = PlanosDataProvider.getInstance().getEstabelecimentoByID( estabelecimentoID ); + } + catch( Exception e ) + { + ErrorLogger.logException( e ); } String visitaDateStr = calFilterDateConcluidos == null ? null : D_F.format( calFilterDateConcluidos ); @@ -1043,7 +1281,8 @@ public class ListaPlanos extends AbstractPageBean getSessionBean1().setIsSearchingPlanosActuacao( Boolean.TRUE ); getSessionBean1().getPlanosConcluidosDataProvider().setList( - searchPlanosConcluidos( getSessionBean1().getCurrentUser(), nome, estabelecimento, visitaDateStr, ano ) ); + searchPlanosConcluidos( getSessionBean1().getCurrentUser(), nome, selectedEmpresa, estabelecimento, + visitaDateStr, ano ) ); return null; } diff --git a/trunk/PlanosActuacao/src/planosactuacao/Login.java b/trunk/PlanosActuacao/src/planosactuacao/Login.java index d483ac1d..f20c3392 100644 --- a/trunk/PlanosActuacao/src/planosactuacao/Login.java +++ b/trunk/PlanosActuacao/src/planosactuacao/Login.java @@ -231,6 +231,8 @@ public class Login extends AbstractPageBean getSessionBean1().setCurrentUser( u ); getSessionBean1().setLoggedIn( true ); + getSessionBean1().setSiprp( udp.isSiprp( u ) ); + sRet = "lista_planos"; } } diff --git a/trunk/PlanosActuacao/src/planosactuacao/SessionBean1.java b/trunk/PlanosActuacao/src/planosactuacao/SessionBean1.java index 8737a21d..622421f7 100644 --- a/trunk/PlanosActuacao/src/planosactuacao/SessionBean1.java +++ b/trunk/PlanosActuacao/src/planosactuacao/SessionBean1.java @@ -482,4 +482,16 @@ public class SessionBean1 extends AbstractSessionBean { this.anoChoice = anoChoice; } + private Boolean siprp; + + public Boolean isSiprp() + { + return siprp; + } + + public void setSiprp( Boolean siprp ) + { + this.siprp = siprp; + } + } diff --git a/trunk/PlanosActuacao/src/utils/Global.java b/trunk/PlanosActuacao/src/utils/Global.java index 542797a3..b1c27d0f 100644 --- a/trunk/PlanosActuacao/src/utils/Global.java +++ b/trunk/PlanosActuacao/src/utils/Global.java @@ -49,8 +49,9 @@ public class Global // public static final String ANALISE_ACIDENTES_URL = "http://localhost:8084/AnaliseAcidentesTrabalho/faces/"; //testes // public static final String PLANOS_ACTUACAO_URL = "http://localhost:8084/PlanosActuacao/faces/"; //testes // public static final String ANALISE_ACIDENTES_URL = "http://192.168.111.24:8084/AnaliseAcidentesTrabalho/faces/"; //testes portatil - public static final String ANALISE_ACIDENTES_URL = "https://www.siprp.pt/AnaliseAcidentesTrabalho/faces/"; //real - public static final String PLANOS_ACTUACAO_URL = "https://www.siprp.pt/PlanosActuacao/faces/"; + //public static final String ANALISE_ACIDENTES_URL = "https://www.siprp.pt/AnaliseAcidentesTrabalho/faces/"; //real + public static final String ANALISE_ACIDENTES_URL = "http://localhost:8080/PlanosActuacao/faces/"; + public static final String PLANOS_ACTUACAO_URL = "http://localhost:8080/PlanosActuacao/faces/"; public static final String LOGOS_FOLDER = "/resources/images"; public static final String PDF_FOLDER_URL = "/resources/pdf"; @@ -65,4 +66,5 @@ public class Global public static final String VALOR_INDETERMINADO = "IND"; + public static final int AUCHAN = 32; } diff --git a/trunk/PlanosActuacao/src/utils/Utils.java b/trunk/PlanosActuacao/src/utils/Utils.java index b1145e95..847b573d 100644 --- a/trunk/PlanosActuacao/src/utils/Utils.java +++ b/trunk/PlanosActuacao/src/utils/Utils.java @@ -7,6 +7,7 @@ package utils; import com.evolute.utils.Singleton; import com.evolute.utils.error.ErrorLogger; +import com.sun.webui.jsf.component.DropDown; import com.sun.webui.jsf.model.Option; import db.entidades.Utilizador; import db.providers.PlanosDataProvider; @@ -169,5 +170,82 @@ public class Utils { String pageFrom = referer.substring(referer.lastIndexOf("/")+1); return pageFrom; - } + } + + public static void fillEstabelecimentos( Integer empresaId, DropDown... drops ) + { + try + { + Option[] estabelecimentos = PlanosDataProvider.getInstance().getEstabelecimentos( empresaId ); + if ( estabelecimentos != null ) + { + Integer selected = null; + for ( DropDown drop : drops ) + { + if( drop.getSelected() != null ) + { + if( drop.getSelected() instanceof Integer ) + { + selected = ( Integer ) drop.getSelected(); + } + else + { + selected = getSelectedID( drop ); + } + } + drop.setItems( estabelecimentos ); + drop.setSelected( selected ); + } + } + } + catch ( Exception e ) + { + ErrorLogger.logException( e ); + } + } + + public static Integer getSelectedID( DropDown drop ) + { + Integer selectedID = null; + if ( drop.getSelected() != null ) + { + String value = ( String ) drop.getSelected(); + try { selectedID = Integer.parseInt( value ); } + catch ( Exception ignored ) { } + } + return selectedID; + } + + public static void fillEmpresas( DropDown ... drops ) + { + try + { + Option[] empresas = PlanosDataProvider.getInstance().getEmpresas(); + if ( empresas != null ) + { + Integer selected = null; + for ( DropDown drop : drops ) + { + if( drop.getSelected() != null ) + { + if( drop.getSelected() instanceof Integer ) + { + selected = ( Integer ) drop.getSelected(); + } + else + { + selected = getSelectedID( drop ); + } + } + drop.setItems( empresas ); + drop.setSelected( selected ); + } + } + } + catch ( Exception e ) + { + ErrorLogger.logException( e ); + } + } + } diff --git a/trunk/PlanosActuacao/web/Estatistica.jsp b/trunk/PlanosActuacao/web/Estatistica.jsp index 8885773c..7f65a2b7 100644 --- a/trunk/PlanosActuacao/web/Estatistica.jsp +++ b/trunk/PlanosActuacao/web/Estatistica.jsp @@ -22,6 +22,14 @@ + + + + diff --git a/trunk/PlanosActuacao/web/ListaPlanos.jsp b/trunk/PlanosActuacao/web/ListaPlanos.jsp index 7b697870..46855c3b 100644 --- a/trunk/PlanosActuacao/web/ListaPlanos.jsp +++ b/trunk/PlanosActuacao/web/ListaPlanos.jsp @@ -1,17 +1,9 @@ - - @@ -23,7 +15,7 @@ @@ -53,7 +45,7 @@ - + @@ -62,9 +54,21 @@ - - - + + + + + + + + + @@ -86,7 +90,7 @@ - + @@ -120,7 +124,7 @@ - + @@ -129,9 +133,21 @@ - - - + + + + + + + + + @@ -152,7 +168,7 @@ - + @@ -185,7 +201,7 @@ - + @@ -194,9 +210,21 @@ - - - + + + + + + + + + @@ -217,7 +245,7 @@ - + @@ -234,7 +262,7 @@ -