Source Code Cross Referenced for PreverRendimentosAplicacao.java in  » ERP-CRM-Financial » Personal-Finance-Manager » br » com » gfp » features » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Personal Finance Manager » br.com.gfp.features 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 03/11/2004
003:         * 
004:         * Swing Components - visit http://sf.net/projects/gfd
005:         * 
006:         * Copyright (C) 2004  Igor Regis da Silva Simões
007:         * 
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or (at your option) any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:        package br.com.gfp.features;
023:
024:        import java.sql.SQLException;
025:        import java.util.ArrayList;
026:        import java.util.Calendar;
027:        import java.util.Date;
028:
029:        import br.com.gfp.dao.AccountSavingDAO;
030:        import br.com.gfp.dao.IncomePredictionDAO;
031:        import br.com.gfp.data.AccountSaving;
032:        import br.com.gfp.data.ConfigPrevisao;
033:        import br.com.gfp.data.IncomePrediction;
034:        import br.com.gfpshare.config.Propriedades;
035:        import br.com.gfpshare.controllers.PropriedadesController;
036:        import br.com.gfpshare.db.DAOEvent;
037:        import br.com.gfpshare.db.DAOListener;
038:
039:        /**
040:         * Esta classe é responsável por controlar a previsão de rendimentos para as aplicações
041:         * financeiras. <br>
042:         * Sempre que houver movimentação nas contas de aplicação financeira, esta classe será notificada
043:         * e reagirá, fazendo os recalculos e lançamentos de acordo com o novo cenário
044:         * <br>
045:         * @author Igor Regis da Silva Simoes
046:         */
047:        public class PreverRendimentosAplicacao implements  DAOListener {
048:            /**
049:             * Constrrói uma instancia desta classe que irá monitorar as aplicações e resgates
050:             */
051:            public PreverRendimentosAplicacao() {
052:                //Não fazemos nada
053:            }
054:
055:            /**
056:             * 
057:             * @param propriedadesController Controller de propriedade usado para pegar configurações
058:             */
059:            private void preverMovimento(
060:                    final PropriedadesController propriedadesController) {
061:                (new Thread("PreverRendimentoAplicacao") {
062:                    {
063:                        setPriority(Thread.MIN_PRIORITY);
064:                    }
065:
066:                    @Override
067:                    public void run() {
068:                        try {
069:                            IncomePredictionDAO incomePredictionDAO = new IncomePredictionDAO();
070:                            ArrayList<AccountSaving> aplicacoes = new AccountSavingDAO()
071:                                    .getAllBy(new AccountSaving());
072:                            for (AccountSaving accountSaving : aplicacoes) {
073:
074:                                IncomePrediction previsao = new IncomePrediction();
075:                                previsao.setId(accountSaving.getId());
076:                                previsao.setTipoConta(accountSaving
077:                                        .getTipoConta());
078:                                previsao.setDataRendimento(Calendar
079:                                        .getInstance().getTime());
080:                                Integer tipo = accountSaving
081:                                        .getTipoRendimento();
082:                                previsao.setTipoRendimento(tipo != null ? tipo
083:                                        .intValue() : 0);
084:
085:                                //Até quando vamos fazer previsões
086:                                Calendar dataMaxina = Calendar.getInstance();
087:
088:                                //Média de dos lançamentos nos ultimos 12 meses
089:                                Double mediana = incomePredictionDAO
090:                                        .calculaMediana(previsao, 12);
091:
092:                                //TODO Remover debug rendimento
093:                                //                        ((SimpleLog)GFPController.getGFPController().getContexto().get(GFPController.LOG)).log("------ Mediana: " + mediana);
094:
095:                                if (mediana == 0)
096:                                    return;
097:
098:                                //Descobrimos até quando vamos fazer previões
099:                                ConfigPrevisao configPrevisao = (ConfigPrevisao) Propriedades
100:                                        .loadPropiedades(ConfigPrevisao.class);
101:                                try {
102:                                    propriedadesController.getBy(configPrevisao
103:                                            .getPersistentObject());
104:                                } catch (SQLException e2) {
105:                                    //Não fazemos nada
106:                                }
107:                                dataMaxina.setTime(configPrevisao
108:                                        .getPreverAteQueAno());
109:
110:                                //Montamos o tipo de lancamento que queremos alterar...
111:                                Calendar dia = Calendar.getInstance();
112:
113:                                // ...e realizamos as novas previsões mes a mês
114:                                previsao.setValorRendimento(Float.valueOf(""
115:                                        + mediana));
116:                                int vezesRealizar = 1;
117:                                while (dia.get(Calendar.YEAR) != dataMaxina
118:                                        .get(Calendar.YEAR)
119:                                        || dia.get(Calendar.MONTH) != dataMaxina
120:                                                .get(Calendar.MONTH)) {
121:                                    switch (tipo.intValue()) {
122:                                    case AccountSaving.DIARIO:
123:                                        dia.add(Calendar.DATE, 1);
124:                                        if (dia.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
125:                                            dia.add(Calendar.DATE, 1);
126:                                        else if (dia.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
127:                                            dia.add(Calendar.DATE, 2);
128:                                        break;
129:                                    case AccountSaving.MENSAL:
130:                                        dia.add(Calendar.MONTH, 1);
131:                                        break;
132:                                    case AccountSaving.ANUAL:
133:                                        dia.add(Calendar.YEAR, 1);
134:                                        break;
135:                                    }
136:                                    vezesRealizar++;
137:                                }
138:                                previsao.setVezesPraRealizar(vezesRealizar);
139:                                incomePredictionDAO.adicionarNovo(previsao);
140:                            }
141:                        } catch (SQLException sqle) {
142:                            sqle.printStackTrace();
143:                        }
144:                    }
145:                }).start();
146:            }
147:
148:            /**
149:             * @see br.com.gfpshare.db.DAOListener#adicionadoNovo(br.com.gfpshare.db.DAOEvent)
150:             */
151:            public void adicionadoNovo(DAOEvent e) {
152:                // Este evento não nos interessa
153:            }
154:
155:            /**
156:             * @see br.com.gfpshare.db.DAOListener#atualizado(br.com.gfpshare.db.DAOEvent)
157:             */
158:            public void atualizado(DAOEvent e) {
159:                // Este evento não nos interessa
160:            }
161:
162:            /**
163:             * @see br.com.gfpshare.db.DAOListener#deletado(br.com.gfpshare.db.DAOEvent)
164:             */
165:            public void deletado(DAOEvent e) {
166:                // Este evento não nos interessa
167:            }
168:
169:            /**
170:             * @see br.com.gfpshare.db.DAOListener#selecionado(br.com.gfpshare.db.DAOEvent)
171:             */
172:            public void selecionado(DAOEvent e) {
173:                // Este evento não nos interessa
174:            }
175:
176:            /**
177:             * @see br.com.gfpshare.db.DAOListener#filtrado(br.com.gfpshare.db.DAOEvent)
178:             */
179:            public void filtrado(DAOEvent e) {
180:                // Este evento não nos interessa
181:            }
182:
183:            /**
184:             * Verificamos se o evento gerado realmente dispara uma previsão de movimento futuro de contas de aplicação
185:             * @param e
186:             */
187:            public void verSeVaiPreverMovimento(DAOEvent e) {
188:                //if (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) != 1)
189:                //    return;
190:                PropriedadesController propriedadesController = new PropriedadesController();
191:                //Aqui veremos se o GFP esta configurado para realizar previsões
192:                ConfigPrevisao configPrevisao = (ConfigPrevisao) Propriedades
193:                        .loadPropiedades(ConfigPrevisao.class);
194:                try {
195:                    propriedadesController.getBy(configPrevisao
196:                            .getPersistentObject());
197:                } catch (SQLException e2) {
198:                    //Não fazemos nada
199:                }
200:                if (!configPrevisao.getRealizarPrevisoes()
201:                        || !configPrevisao.getPreverRendimentos())
202:                    return;
203:                Calendar data = Calendar.getInstance();
204:                data.setTime(configPrevisao
205:                        .getDataPrevisoesRendimentosRealizada());
206:
207:                if (Calendar.getInstance().get(Calendar.MONTH) == data
208:                        .get(Calendar.MONTH)) {
209:                    return;
210:                }
211:
212:                configPrevisao.setDataPrevisoesRendimentosRealizada(new Date());
213:                try {
214:                    propriedadesController.atualizar(configPrevisao
215:                            .getPersistentObject());
216:                } catch (SQLException e2) {
217:                    //Não fazemos nada
218:                }
219:                preverMovimento(propriedadesController);
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.