Source Code Cross Referenced for ImportUtils.java in  » ERP-CRM-Financial » Personal-Finance-Manager » br » com » gfp » ofc » tools » 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.ofc.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 23/03/2007
003:         * 
004:         * Swing Components - visit http://sf.net/projects/gfd
005:         * 
006:         * Copyright (C) 2007  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:         */
023:        package br.com.gfp.ofc.tools;
024:
025:        import java.sql.SQLException;
026:        import java.util.ArrayList;
027:        import java.util.Calendar;
028:
029:        import javax.swing.JFrame;
030:        import javax.swing.JOptionPane;
031:
032:        import br.com.gfp.dao.GFPController;
033:        import br.com.gfp.dao.ImportByHistoryMappingDAO;
034:        import br.com.gfp.dao.TransactionDAO;
035:        import br.com.gfp.dao.TransactionTypeDAO;
036:        import br.com.gfp.data.ImportByHistoryMapping;
037:        import br.com.gfp.data.PendingTransaction;
038:        import br.com.gfp.data.Transaction;
039:        import br.com.gfp.internationalization.ActionsMessages;
040:        import br.com.gfp.util.SimpleLog;
041:
042:        public class ImportUtils {
043:            /**
044:             * We use it to discover the code for expenses, revenues and transfers
045:             */
046:            private static TransactionTypeDAO transactionTypeDAO = new TransactionTypeDAO();
047:
048:            public static void conciliate(
049:                    ArrayList<PendingTransaction> lancamentos) {
050:                Transaction transaction = new Transaction();
051:                TransactionDAO<Transaction> lancamentoController = new TransactionDAO<Transaction>();
052:                TransactionDAO<PendingTransaction> lancamentoPendenteController = new TransactionDAO<PendingTransaction>();
053:                boolean erro = false;
054:                for (PendingTransaction lancamentoPendente : lancamentos) {
055:                    transaction.setTipoConta(lancamentoPendente.getTipoConta());
056:                    transaction.setConta(lancamentoPendente.getConta());
057:                    transaction.setValor(lancamentoPendente.getValor());
058:                    transaction.setDia(lancamentoPendente.getDia());
059:                    if (existTransaction(lancamentoController,
060:                            lancamentoPendente, 0)
061:                            || existTransaction(lancamentoController,
062:                                    lancamentoPendente, -1)
063:                            || existTransaction(lancamentoController,
064:                                    lancamentoPendente, -2))
065:                        continue;
066:                    lancamentoPendente.setEfetivar(false);
067:                    lancamentoPendente.setEhDeSistema(false);
068:                    lancamentoPendente.setEhPrevisao(false);
069:                    try {
070:                        lancamentoPendenteController
071:                                .adicionarNovo(lancamentoPendente);
072:                    } catch (SQLException e) {
073:                        erro = true;
074:                        ((SimpleLog) GFPController.getGFPController()
075:                                .getContexto().get(GFPController.LOG))
076:                                .log("Error on add temporary transaction");
077:                        ((SimpleLog) GFPController.getGFPController()
078:                                .getContexto().get(GFPController.LOG)).log(e
079:                                .getLocalizedMessage());
080:                        ((SimpleLog) GFPController.getGFPController()
081:                                .getContexto().get(GFPController.LOG)).log(e);
082:                    }
083:                }
084:                if (erro)
085:                    JOptionPane.showMessageDialog((JFrame) GFPController
086:                            .getGFPController().getContexto().get(
087:                                    GFPController.FRAME_PRINCIPAL),
088:                            ActionsMessages.getMessages().getString(
089:                                    "ErroAoRegistrarLancamentosPendentes"));
090:            }
091:
092:            /**
093:             * This method check the existence of a transaction
094:             * @param desvioDia Days that will be added to the actual search day.
095:             * @return
096:             */
097:            public static boolean existTransaction(
098:                    TransactionDAO<Transaction> lancamentoController,
099:                    PendingTransaction lancamentoPendente, int desvioDia) {
100:                Transaction filtro = new Transaction();
101:                Calendar calendar = Calendar.getInstance();
102:                calendar.setTime(lancamentoPendente.getDia());
103:                calendar.add(Calendar.DAY_OF_MONTH, desvioDia);
104:
105:                filtro.setDia(calendar.getTime());
106:                filtro.setConta(lancamentoPendente.getConta());
107:                filtro.setTipoConta(lancamentoPendente.getTipoConta());
108:                filtro.setValor(lancamentoPendente.getValor());
109:                try {
110:                    if (lancamentoController.getBy(filtro) != null) {
111:                        //                filtro.setDados(null); Not needed for now
112:                        return true;
113:                    }
114:                } catch (SQLException e) {
115:                }
116:                return false;
117:            }
118:
119:            /**
120:             * Here we set the default type for the temporary transaction
121:             * @param pendingTransaction
122:             */
123:            public static void setDefaultType(
124:                    PendingTransaction pendingTransaction) {
125:                try {
126:                    if (pendingTransaction.getValor() < 0)
127:                        pendingTransaction.setTipo(transactionTypeDAO
128:                                .getExpense().getId());
129:                    else
130:                        pendingTransaction.setTipo(transactionTypeDAO
131:                                .getRevenues().getId());
132:                } catch (SQLException e) {
133:                    ((SimpleLog) GFPController.getGFPController().getContexto()
134:                            .get(GFPController.LOG))
135:                            .log("Error when defining a default type of transaction for account mapping");
136:                    ((SimpleLog) GFPController.getGFPController().getContexto()
137:                            .get(GFPController.LOG)).log(e
138:                            .getLocalizedMessage());
139:                    ((SimpleLog) GFPController.getGFPController().getContexto()
140:                            .get(GFPController.LOG)).log(e);
141:                    pendingTransaction.setTipo(0);
142:                }
143:            }
144:
145:            /**
146:             * This method will define the type of each transaction that was
147:             * parsed from ofc file. We will look at database to see what mapping
148:             * definition user have made.
149:             * The default is to set negative transactions as expense 
150:             * and positive as revenue.
151:             * 
152:             * This method don't return data, it manipulates date from parser 
153:             * @throws SQLException 
154:             */
155:            public static void defineTypeForTransactions(
156:                    ArrayList<PendingTransaction> transactions) {
157:                ImportByHistoryMappingDAO importByHistoryMappingDAO = new ImportByHistoryMappingDAO();
158:                ImportByHistoryMapping importByHistoryMapping = new ImportByHistoryMapping();
159:
160:                for (PendingTransaction lancamentoPendente : transactions) {
161:                    importByHistoryMapping
162:                            .setStringAMapear(parseDescription(lancamentoPendente
163:                                    .getDescricao()));
164:                    importByHistoryMapping.setContaValido(lancamentoPendente
165:                            .getConta());
166:                    importByHistoryMapping.setTipoContaValido(Integer
167:                            .parseInt(lancamentoPendente.getTipoConta()));
168:                    ImportByHistoryMapping mapeamento = null;
169:                    try {
170:                        mapeamento = importByHistoryMappingDAO
171:                                .getBy(importByHistoryMapping);
172:                    } catch (SQLException e) {
173:                        //Type not mapped, we ignore this error since we will take the default value
174:                    }
175:                    //So we try to get a mapping that is valid for any other account to use as default
176:                    importByHistoryMapping.setTipoContaValido(null);
177:                    importByHistoryMapping.setContaValido(null);
178:                    try {
179:                        mapeamento = importByHistoryMappingDAO
180:                                .getBy(importByHistoryMapping);
181:                    } catch (SQLException e) {
182:                        //Type not mapped, we ignore this error since we will take the default value
183:                    }
184:
185:                    if (mapeamento != null) {
186:                        lancamentoPendente.setEntidadeEnvolvida(mapeamento
187:                                .getContatoComOQualMapear());
188:                        lancamentoPendente.setTipo(mapeamento
189:                                .getTipoLancamentoComQueMapear());
190:                    } else {
191:                        setDefaultType(lancamentoPendente);
192:                        mapeamento = new ImportByHistoryMapping();
193:                        mapeamento.setStringAMapear(importByHistoryMapping
194:                                .getStringAMapear());
195:                        mapeamento
196:                                .setTipoLancamentoComQueMapear(lancamentoPendente
197:                                        .getTipo());
198:                        mapeamento
199:                                .setContaValido(lancamentoPendente.getConta());
200:                        mapeamento.setTipoContaValido(Integer
201:                                .parseInt(lancamentoPendente.getTipoConta()));
202:                        try {
203:                            importByHistoryMappingDAO.adicionarNovo(mapeamento);
204:                        } catch (SQLException e) {
205:                            ((SimpleLog) GFPController.getGFPController()
206:                                    .getContexto().get(GFPController.LOG))
207:                                    .log("Error when registering a new import mapping");
208:                            ((SimpleLog) GFPController.getGFPController()
209:                                    .getContexto().get(GFPController.LOG))
210:                                    .log(e.getLocalizedMessage());
211:                            ((SimpleLog) GFPController.getGFPController()
212:                                    .getContexto().get(GFPController.LOG))
213:                                    .log(e);
214:                        }
215:                    }
216:                }
217:            }
218:
219:            private static String parseDescription(String description) {
220:                //This if is useful for OFC, OFX files from BB
221:                if (description.startsWith("Compra com Cartao")) {
222:                    description = description.substring(description
223:                            .indexOf(':') + 4);
224:                }
225:                return description;
226:            }
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.