r2968 - in trunk: . lima-business/src/main/java/org/chorem/lima/business lima-business/src/main/java/org/chorem/lima/business/accountingrules lima-business/src/main/java/org/chorem/lima/business/ejb lima-callao lima-callao/src/main/xmi lima-swing/src/main/java/org/chorem/lima/ui/celleditor lima-swing/src/main/java/org/chorem/lima/ui/combobox lima-swing/src/main/java/org/chorem/lima/ui/importexport lima-swing/src/main/java/org/chorem/lima/util lima-swing/src/main/resources/icons
Author: jpepin Date: 2010-07-13 16:29:30 +0200 (Tue, 13 Jul 2010) New Revision: 2968 Url: http://chorem.org/repositories/revision/lima/2968 Log: Import entries from EBP. Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ImportService.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-callao/pom.xml trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/SubAccountComboBoxModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java trunk/lima-swing/src/main/java/org/chorem/lima/util/AccountToString.java trunk/lima-swing/src/main/resources/icons/action-closeTab.png trunk/pom.xml Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ImportService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ImportService.java 2010-07-12 13:08:29 UTC (rev 2967) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ImportService.java 2010-07-13 14:29:30 UTC (rev 2968) @@ -41,7 +41,7 @@ * @param data * @throws LimaException */ - public void importAsEbpCSV(byte[] data) throws LimaException; + public String importAsEbpCSV(String datas) throws LimaException; /** * Import data as Sage Maestria export. Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2010-07-12 13:08:29 UTC (rev 2967) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2010-07-13 14:29:30 UTC (rev 2968) @@ -328,8 +328,8 @@ FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(topiaContext); FiscalPeriod fiscalPeriod = - fiscalPeriodDAO.findContainsFinancialPeriod( - financialTransaction.getFinancialPeriod()); + fiscalPeriodDAO.findContainsFinancialPeriod( + financialTransaction.getFinancialPeriod()); Date beginDateFiscalPeriod = fiscalPeriod.getBeginDate(); Date endDateFiscalPeriod = fiscalPeriod.getEndDate(); Date financialTransactionDate = Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2010-07-12 13:08:29 UTC (rev 2967) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2010-07-13 14:29:30 UTC (rev 2968) @@ -4,7 +4,6 @@ import java.util.Calendar; import java.util.Date; import java.util.List; - import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateUtils; import org.apache.commons.logging.Log; @@ -17,7 +16,6 @@ import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialPeriodImpl; -import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FiscalPeriodDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-07-12 13:08:29 UTC (rev 2967) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-07-13 14:29:30 UTC (rev 2968) @@ -314,13 +314,12 @@ // Check rules for account if have entries accountingRules.removeAccountRules(account, transaction); - + // remove account Account accountToDelete = accountDAO.findByTopiaId(account.getTopiaId()); - accountDAO.delete(accountToDelete); //get all subaccounts - List<Account> accounts = getAllChildrenAccounts(account, new ArrayList<Account>()); + List<Account> accounts = getAllChildrenAccounts(accountToDelete, new ArrayList<Account>()); //if account have sub accounts if (accounts.size() > 0){ for (Account subAccount : accounts) { @@ -330,9 +329,10 @@ accountDAO.delete(subAccountToDelete); } } - //commit - commitTransaction(transaction); - + + accountDAO.delete(accountToDelete); + //commit + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -375,9 +375,8 @@ LimaCallaoDAOHelper.getAccountDAO(transaction); Account subAccount = accountDAO.findByTopiaId(account.getTopiaId()); //check rules account if ledger or account - if (account.getGeneralLedger()==null){ + if (account.getGeneralLedger() == null){ Account master = accountDAO.findContainsSubAccounts(subAccount); - log.debug(master); accountingRules.updateAccountRules(master, account); subAccount.setMasterAccount(account.getMasterAccount()); subAccount.setSubAccounts(account.getSubAccounts()); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2010-07-12 13:08:29 UTC (rev 2967) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2010-07-13 14:29:30 UTC (rev 2968) @@ -24,7 +24,6 @@ import java.text.SimpleDateFormat; import java.util.List; import javax.ejb.Stateless; - import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -51,8 +50,6 @@ import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; -import org.omg.CORBA.portable.ValueOutputStream; - import au.com.bytecode.opencsv.CSVWriter; /** Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2010-07-12 13:08:29 UTC (rev 2967) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2010-07-13 14:29:30 UTC (rev 2968) @@ -39,6 +39,8 @@ import org.chorem.lima.beans.AccountImportImpl; import org.chorem.lima.beans.ClosedPeriodicEntryBookImport; import org.chorem.lima.beans.ClosedPeriodicEntryBookImportImpl; +import org.chorem.lima.beans.EntriesEBP; +import org.chorem.lima.beans.EntriesEBPImpl; import org.chorem.lima.beans.EntryImport; import org.chorem.lima.beans.EntryImportImpl; import org.chorem.lima.beans.FinancialStatementImport; @@ -53,6 +55,7 @@ import org.chorem.lima.business.FiscalPeriodServiceLocal; import org.chorem.lima.business.ImportService; import org.chorem.lima.business.ImportServiceLocal; +import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; import org.chorem.lima.business.utils.FiscalPeriodComparator; @@ -85,6 +88,8 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; import au.com.bytecode.opencsv.CSVReader; +import au.com.bytecode.opencsv.bean.ColumnPositionMappingStrategy; +import au.com.bytecode.opencsv.bean.CsvToBean; /** * CSV import export service. @@ -140,8 +145,110 @@ //################ IMPORT THIRD PART ACCOUNTING SOFTWARE ################ @Override - public void importAsEbpCSV(byte[] data) throws LimaException { - + public String importAsEbpCSV(String datas) throws LimaException { + SimpleDateFormat epbDateFormat = new SimpleDateFormat("dd/MM/yyyy"); + String result = ""; + + TopiaContext topiaContext = null; + try { + topiaContext = beginTransaction(); + + CSVReader csvReader = new CSVReader(new StringReader(datas)); + ColumnPositionMappingStrategy<EntriesEBPImpl> strat = new ColumnPositionMappingStrategy<EntriesEBPImpl>(); + strat.setType(EntriesEBPImpl.class); + //read header to set strategy mapping + strat.setColumnMapping(csvReader.readNext()); + CsvToBean<EntriesEBPImpl> csv = new CsvToBean<EntriesEBPImpl>(); + List<EntriesEBPImpl> list = csv.parse(strat, csvReader); + + //DAOs + AccountDAO accountDAO = + LimaCallaoDAOHelper.getAccountDAO(topiaContext); + EntryBookDAO entryBookDAO = + LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); + FinancialPeriodDAO financialPeriodDAO = + LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); + FinancialTransactionDAO financialTransactionDAO = + LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); + EntryDAO entryDAO = + LimaCallaoDAOHelper.getEntryDAO(topiaContext); + + FinancialTransaction financialTransaction = null; + for (EntriesEBP entryEBP : list) { + //create entry + Entry entry = new EntryImpl(); + Account account = accountDAO.findByAccountNumber(entryEBP.getCompte()); + //if account not exist not export + if (account == null){ + throw new LimaBusinessException("FAILED : Account " + entryEBP.getCompte() + " not exist !\n" + + "Import or create all accounts before import entries"); + } + else { + entry.setAccount(account); + Double debit = new Double(entryEBP.getDebit()); + Double credit = new Double(entryEBP.getCredit()); + if (debit == 0){ + entry.setDebit(false); + entry.setAmount(credit); + } + else { + entry.setDebit(true); + entry.setAmount(debit); + } + entry.setDescription(entryEBP.getLibelle()); + entry.setLettering(entryEBP.getLettre()); + entryDAO.create(entry); + Date date = epbDateFormat.parse(entryEBP.getDatEcr()); + String entryBookCode = entryEBP.getJournal(); + EntryBook entryBook = entryBookDAO.findByCode(entryBookCode); + + //if entrybook not exist create it ! + if (entryBook==null){ + entryBook = new EntryBookImpl(); + entryBook.setCode(entryBookCode); + //create it + entryBookService.createEntryBook(entryBook); + result += "WARNING : Entrybook " + entryBook + "not exist was created !\n"; + } + + + if (financialTransaction == null || !(date.equals(financialTransaction.getTransactionDate()) && entryBook.getCode().equals(financialTransaction.getEntryBook().getCode()))){ + //create financial transaction + financialTransaction = new FinancialTransactionImpl(); + financialTransaction.setEntryBook(entryBook); + financialTransaction.setTransactionDate(date); + FinancialPeriod financialPeriod = financialPeriodDAO.findByDate(date); + financialTransaction.setFinancialPeriod(financialPeriod); + financialTransactionDAO.create(financialTransaction); + result += "SUCCES : FinancialTransaction" + date + " " + entryBook.getCode() + " added\n"; + + } + financialTransaction.addEntry(entry); + result += "SUCCES : Entry" + entry.getDescription() + " " + entry.getAmount() + " added\n"; + } + } + //commit + commitTransaction(topiaContext); + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + catch (IOException eeeIO) { + if (log.isDebugEnabled()){ + log.debug("Can't read string", eeeIO); + } + } + catch (ParseException eeePE) { + if (log.isDebugEnabled()){ + log.debug("Can't parse date", eeePE); + } + } + finally { + doFinally(topiaContext, log); + } + return result; + + } @Override Modified: trunk/lima-callao/pom.xml =================================================================== --- trunk/lima-callao/pom.xml 2010-07-12 13:08:29 UTC (rev 2967) +++ trunk/lima-callao/pom.xml 2010-07-13 14:29:30 UTC (rev 2968) @@ -65,7 +65,7 @@ <phase>generate-sources</phase> <configuration> <inputs>zargo</inputs> - <templates>org.nuiton.topia.generator.TopiaMetaTransformer, org.nuiton.topia.generator.EntityTransformer, org.nuiton.eugene.java.JavaBeanTransformer, org.nuiton.topia.generator.QueryHelperTransformer</templates> + <templates>org.nuiton.topia.generator.TopiaMetaTransformer, org.nuiton.topia.generator.EntityTransformer, org.nuiton.eugene.java.JavaBeanTransformer</templates> <excludeTemplates> <excludeTemplate>org.nuiton.topia.generator.EntityAbstractTransformer</excludeTemplate> <excludeTemplate>org.nuiton.topia.generator.EntityImplTransformer</excludeTemplate> Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java 2010-07-12 13:08:29 UTC (rev 2967) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java 2010-07-13 14:29:30 UTC (rev 2968) @@ -24,13 +24,11 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.util.EventObject; - import javax.swing.AbstractCellEditor; import javax.swing.JTable; import javax.swing.SwingUtilities; import javax.swing.table.TableCellEditor; import javax.swing.text.JTextComponent; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Account; @@ -46,14 +44,16 @@ private final JWideComboBox comboBox; private static final long serialVersionUID = 2580476608066111095L; private static AccountTableCellEditor editor; + private static SubAccountComboBoxModel accountComboBoxModel; private static boolean keyPressed = false; /** * constructor */ public AccountTableCellEditor() { + super(); comboBox = new JWideComboBox(); - SubAccountComboBoxModel accountComboBoxModel = new SubAccountComboBoxModel(); + accountComboBoxModel = new SubAccountComboBoxModel(); comboBox.setModel(accountComboBoxModel); AccountRenderer accountRenderer = new AccountRenderer(); comboBox.setRenderer(accountRenderer); @@ -81,8 +81,9 @@ // Validate editing with enter key if ( e.getKeyChar() == KeyEvent.VK_ENTER ) { - - stopCellEditing(); + //FIXME pepin 13072010 enter not save the modification + log.debug(comboBox.getEditor().getItem()); + stopCellEditing(); } } }); @@ -90,16 +91,15 @@ @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - if (value instanceof Account){ - comboBox.setSelectedItem((Account) value); - - } + if (value instanceof Account){ + comboBox.setSelectedItem((Account) value); + } return comboBox; } @Override public Object getCellEditorValue() { - return comboBox.getSelectedItem(); + return comboBox.getSelectedItem(); } /** @@ -135,6 +135,7 @@ return ( !(evt instanceof MouseEvent) || ((MouseEvent) evt).getClickCount() == 2 ); } + public static AccountTableCellEditor getInstance() { if (editor == null) { editor = new AccountTableCellEditor(); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountRenderer.java 2010-07-12 13:08:29 UTC (rev 2967) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountRenderer.java 2010-07-13 14:29:30 UTC (rev 2968) @@ -31,12 +31,7 @@ private static final long serialVersionUID = -2756100193253351274L; @Override - public Component getListCellRendererComponent(JList list, - Object value, - int index, - boolean isSelected, - boolean cellHasFocus) { - // TODO Auto-generated method stub + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = new JLabel(); Account account = (Account) value; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/SubAccountComboBoxModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/SubAccountComboBoxModel.java 2010-07-12 13:08:29 UTC (rev 2967) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/SubAccountComboBoxModel.java 2010-07-13 14:29:30 UTC (rev 2968) @@ -20,10 +20,8 @@ import java.util.ArrayList; import java.util.List; - import javax.swing.ComboBoxModel; import javax.swing.event.ListDataListener; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.AccountService; @@ -36,7 +34,7 @@ * Account combo box model. */ -public class SubAccountComboBoxModel implements ComboBoxModel { +public class SubAccountComboBoxModel implements ComboBoxModel { private static final Log log = LogFactory.getLog(FinancialPeriodTableModel.class); @@ -50,7 +48,7 @@ accountService = LimaServiceFactory.getInstance().getAccountService(); datasCache = getDataList(); } - + @Override public Object getSelectedItem() { return selectedAccount; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2010-07-12 13:08:29 UTC (rev 2967) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2010-07-13 14:29:30 UTC (rev 2968) @@ -126,6 +126,7 @@ case EBP_ENTRIES_IMPORT: filePath = chooseFile(true); datas = extractFile(filePath); + result = importService.importAsEbpCSV(datas); break; } if (!result.equals("")){ @@ -138,6 +139,7 @@ catch (LimaException eee) { if (log.isDebugEnabled()){ log.debug("Can't call export import service ", eee); + DialogHelper.showMessageDialog(eee.getMessage()); } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/util/AccountToString.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/util/AccountToString.java 2010-07-12 13:08:29 UTC (rev 2967) +++ trunk/lima-swing/src/main/java/org/chorem/lima/util/AccountToString.java 2010-07-13 14:29:30 UTC (rev 2968) @@ -19,7 +19,7 @@ return result; } - public static AccountToString getInstance() { + public static AccountToString getInstance() { if (converter == null) { converter = new AccountToString(); } Modified: trunk/lima-swing/src/main/resources/icons/action-closeTab.png =================================================================== (Binary files differ) Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-07-12 13:08:29 UTC (rev 2967) +++ trunk/pom.xml 2010-07-13 14:29:30 UTC (rev 2968) @@ -251,8 +251,8 @@ <!-- customized libs version --> <nuiton-utils.version>1.3.2-SNAPSHOT</nuiton-utils.version> - <eugene.version>2.1-SNAPSHOT</eugene.version> - <topia.version>2.3.5-SNAPSHOT</topia.version> + <eugene.version>2.0.2</eugene.version> + <topia.version>2.3.4</topia.version> <jaxx.version>2.0.2</jaxx.version> <i18n.version>1.2.2</i18n.version>
participants (1)
-
jpepin@users.chorem.org