Author: jpepin Date: 2010-07-15 11:47:22 +0200 (Thu, 15 Jul 2010) New Revision: 2969 Url: http://chorem.org/repositories/revision/lima/2969 Log: Debug import entries EBP + import accounts chart EBP. Added: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountEBPComparator.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionImpl.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionServiceLocal.java 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/ejb/EntryBookServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionServiceLocal.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionServiceLocal.java 2010-07-13 14:29:30 UTC (rev 2968) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionServiceLocal.java 2010-07-15 09:47:22 UTC (rev 2969) @@ -20,11 +20,8 @@ package org.chorem.lima.business; import java.util.List; - import javax.ejb.Local; - import org.chorem.lima.entity.FinancialTransaction; -import org.chorem.lima.entity.FiscalPeriod; import org.nuiton.topia.TopiaContext; /** 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-13 14:29:30 UTC (rev 2968) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ImportService.java 2010-07-15 09:47:22 UTC (rev 2969) @@ -41,7 +41,9 @@ * @param data * @throws LimaException */ - public String importAsEbpCSV(String datas) throws LimaException; + public String importEntriesFromEbp(String datas) throws LimaException; + public String importAccountsChartFromEbp(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-13 14:29:30 UTC (rev 2968) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2010-07-15 09:47:22 UTC (rev 2969) @@ -153,7 +153,7 @@ */ @Override public void checkFinancialPeriodBlockedWithFinancialTransaction(FinancialTransaction financialTransaction, TopiaContext topiaContext) throws LimaException { - //check financial period locked + //check financial period locked if (financialTransaction.getFinancialPeriod().getLocked()){ throw new LimaBusinessException("The financial period is blocked"); } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-07-13 14:29:30 UTC (rev 2968) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-07-15 09:47:22 UTC (rev 2969) @@ -87,7 +87,7 @@ EntryBookDAO entryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(transaction); EntryBook existingEntryBook = - entryBookDAO.findByLabel(entryBook.getLabel()); + entryBookDAO.findByLabel(entryBook.getCode()); if (existingEntryBook != null) { throw new LimaBusinessException( _("An EntryBook already exists with this label : %s", 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-13 14:29:30 UTC (rev 2968) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2010-07-15 09:47:22 UTC (rev 2969) @@ -33,14 +33,18 @@ import java.util.TreeMap; import javax.ejb.EJB; import javax.ejb.Stateless; + +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.beans.AccountEBP; +import org.chorem.lima.beans.AccountEBPImpl; import org.chorem.lima.beans.AccountImport; 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.EntryEBP; +import org.chorem.lima.beans.EntryEBPImpl; import org.chorem.lima.beans.EntryImport; import org.chorem.lima.beans.EntryImportImpl; import org.chorem.lima.beans.FinancialStatementImport; @@ -58,6 +62,7 @@ import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.utils.AccountEBPComparator; import org.chorem.lima.business.utils.FiscalPeriodComparator; import org.chorem.lima.business.utils.ImportExportEntityEnum; import org.chorem.lima.entity.Account; @@ -145,7 +150,7 @@ //################ IMPORT THIRD PART ACCOUNTING SOFTWARE ################ @Override - public String importAsEbpCSV(String datas) throws LimaException { + public String importEntriesFromEbp(String datas) throws LimaException { SimpleDateFormat epbDateFormat = new SimpleDateFormat("dd/MM/yyyy"); String result = ""; @@ -154,12 +159,12 @@ topiaContext = beginTransaction(); CSVReader csvReader = new CSVReader(new StringReader(datas)); - ColumnPositionMappingStrategy<EntriesEBPImpl> strat = new ColumnPositionMappingStrategy<EntriesEBPImpl>(); - strat.setType(EntriesEBPImpl.class); + ColumnPositionMappingStrategy<EntryEBPImpl> strat = new ColumnPositionMappingStrategy<EntryEBPImpl>(); + strat.setType(EntryEBPImpl.class); //read header to set strategy mapping strat.setColumnMapping(csvReader.readNext()); - CsvToBean<EntriesEBPImpl> csv = new CsvToBean<EntriesEBPImpl>(); - List<EntriesEBPImpl> list = csv.parse(strat, csvReader); + CsvToBean<EntryEBPImpl> csv = new CsvToBean<EntryEBPImpl>(); + List<EntryEBPImpl> list = csv.parse(strat, csvReader); //DAOs AccountDAO accountDAO = @@ -168,13 +173,13 @@ LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); - FinancialTransactionDAO financialTransactionDAO = - LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); - EntryDAO entryDAO = - LimaCallaoDAOHelper.getEntryDAO(topiaContext); + if (financialPeriodDAO.findAll().size() == 0){ + throw new LimaBusinessException("Can't import entries, no fiscalperiod is open"); + } + FinancialTransaction financialTransaction = null; - for (EntriesEBP entryEBP : list) { + for (EntryEBP entryEBP : list) { //create entry Entry entry = new EntryImpl(); Account account = accountDAO.findByAccountNumber(entryEBP.getCompte()); @@ -197,7 +202,7 @@ } entry.setDescription(entryEBP.getLibelle()); entry.setLettering(entryEBP.getLettre()); - entryDAO.create(entry); + entry.setVoucher(entryEBP.getPiece()); Date date = epbDateFormat.parse(entryEBP.getDatEcr()); String entryBookCode = entryEBP.getJournal(); EntryBook entryBook = entryBookDAO.findByCode(entryBookCode); @@ -213,20 +218,31 @@ if (financialTransaction == null || !(date.equals(financialTransaction.getTransactionDate()) && entryBook.getCode().equals(financialTransaction.getEntryBook().getCode()))){ + //update previous financial transaction before create new + if (financialTransaction != null){ + financialTransaction.setAmounts(); + financialTransactionService.updateFinancialTransaction(financialTransaction); + } //create financial transaction financialTransaction = new FinancialTransactionImpl(); financialTransaction.setEntryBook(entryBook); financialTransaction.setTransactionDate(date); FinancialPeriod financialPeriod = financialPeriodDAO.findByDate(date); financialTransaction.setFinancialPeriod(financialPeriod); - financialTransactionDAO.create(financialTransaction); + financialTransactionService.createFinancialTransaction(financialTransaction); result += "SUCCES : FinancialTransaction" + date + " " + entryBook.getCode() + " added\n"; } - financialTransaction.addEntry(entry); + financialTransaction.addEntry(entry); + financialTransactionService.createEntry(entry); result += "SUCCES : Entry" + entry.getDescription() + " " + entry.getAmount() + " added\n"; } } + //update last financial transaction + if (financialTransaction != null){ + financialTransaction.setAmounts(); + financialTransactionService.updateFinancialTransaction(financialTransaction); + } //commit commitTransaction(topiaContext); } @@ -247,10 +263,72 @@ doFinally(topiaContext, log); } return result; - - } + @Override + public String importAccountsChartFromEbp(String datas) throws LimaException{ + String result = ""; + TopiaContext topiaContext = null; + + try { + topiaContext = beginTransaction(); + CSVReader csvReader = new CSVReader(new StringReader(datas)); + ColumnPositionMappingStrategy<AccountEBPImpl> strat = new ColumnPositionMappingStrategy<AccountEBPImpl>(); + strat.setType(AccountEBPImpl.class); + //read header to set strategy mapping + strat.setColumnMapping(csvReader.readNext()); + CsvToBean<AccountEBPImpl> csv = new CsvToBean<AccountEBPImpl>(); + List<AccountEBPImpl> list = csv.parse(strat, csvReader); + Collections.sort(list, new AccountEBPComparator()); + + AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaContext); + for (AccountEBP accountEBP : list) { + String accountNumber = accountEBP.getNumero(); + if (accountDAO.findByAccountNumber(accountNumber) != null){ + result += "FAILED : Account" + accountNumber + " already exist \n"; + } + else { + String label = accountEBP.getIntitule(); + Account account = new AccountImpl(); + account.setAccountNumber(accountNumber); + account.setLabel(label); + + // if account is class account : 1, 2, 3, 4, 5, 6, 7,… + int nbCharAccountNumber = accountNumber.length(); + if (nbCharAccountNumber == 1){ + accountService.createAccount(null, account); + result += "SUCCES : Account" + accountNumber + " " + label + " added\n"; + } + else { + Account masterAccount = null; + int i = 1; + while (masterAccount == null){ + String masterAccountNumber = accountNumber.substring(0, accountNumber.length()-i); + masterAccount = accountDAO.findByAccountNumber(masterAccountNumber); + i++; + } + accountService.createAccount(masterAccount, account); + result += "SUCCES : Account" + accountNumber + " " + label + " added\n"; + } + } + } + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + catch (IOException eeeIO) { + if (log.isDebugEnabled()){ + log.debug("Can't read string", eeeIO); + } + } + finally { + doFinally(topiaContext, log); + } + + return result; + } + + @Override public void importAsCiel(byte[] data) throws LimaException { // TODO Auto-generated method stub Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java 2010-07-13 14:29:30 UTC (rev 2968) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java 2010-07-15 09:47:22 UTC (rev 2969) @@ -20,7 +20,6 @@ package org.chorem.lima.business.utils; import java.util.Comparator; - import org.chorem.lima.entity.Account; public class AccountComparator implements Comparator<Account>{ Added: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountEBPComparator.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountEBPComparator.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountEBPComparator.java 2010-07-15 09:47:22 UTC (rev 2969) @@ -0,0 +1,14 @@ +package org.chorem.lima.business.utils; + +import java.util.Comparator; + +import org.chorem.lima.beans.AccountEBP; + +public class AccountEBPComparator implements Comparator<AccountEBP> { + + @Override + public int compare(AccountEBP o1, AccountEBP o2) { + return o1.getNumero().compareTo(o2.getNumero()); + } + +} Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java 2010-07-13 14:29:30 UTC (rev 2968) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java 2010-07-15 09:47:22 UTC (rev 2969) @@ -1,8 +1,24 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + package org.chorem.lima.entity; -import java.util.ArrayList; import java.util.List; - import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; @@ -14,7 +30,6 @@ */ @Override public List<Account> findAllSubAccounts() throws TopiaException { - List<Account> accountsList = new ArrayList<Account>(); TopiaQuery query = createQuery(); String subAccountsProperty = TopiaQuery.getProperty(Account.SUB_ACCOUNTS); String subLedgersProperty = TopiaQuery.getProperty(Account.SUB_LEDGERS); Added: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionImpl.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionImpl.java 2010-07-15 09:47:22 UTC (rev 2969) @@ -0,0 +1,19 @@ +package org.chorem.lima.entity; + + +public class FinancialTransactionImpl extends FinancialTransactionAbstract { + + @Override + public void setAmounts() { + + for (Entry entryFT : entry) { + if (entryFT.getDebit()){ + amountDebit += entryFT.getAmount(); + } + else { + amountCredit += entryFT.getAmount(); + } + } + } + +} Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) 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-13 14:29:30 UTC (rev 2968) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2010-07-15 09:47:22 UTC (rev 2969) @@ -22,11 +22,13 @@ import static org.nuiton.i18n.I18n._; import java.awt.Component; import java.io.BufferedInputStream; +import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStreamReader; import java.io.OutputStreamWriter; import javax.swing.JFileChooser; import org.apache.commons.logging.Log; @@ -101,32 +103,37 @@ break; case LIMA_ALL_IMPORT: filePath = chooseFile(true); - datas = extractFile(filePath); + datas = extractFile(filePath, charset); result = importService.importCSV(datas); break; case LIMA_ACCOUNTCHARTS_IMPORT: filePath = chooseFile(true); - datas = extractFile(filePath); + datas = extractFile(filePath, charset); result = importService.importAccountsChartAsCSV(datas); break; case LIMA_ENTRYBOOKS_IMPORT: filePath = chooseFile(true); - datas = extractFile(filePath); + datas = extractFile(filePath, charset); result = importService.importEntryBooksChartAsCSV(datas); break; case LIMA_FINANCIALSTATEMENTS_IMPORT: filePath = chooseFile(true); - datas = extractFile(filePath); + datas = extractFile(filePath, charset); result = importService.importFinancialStatementsChartAsCSV(datas); break; case EBP_ACCOUNTCHARTS_IMPORT: + //For windows ebp + charset = "ISO-8859-1"; filePath = chooseFile(true); - datas = extractFile(filePath); + datas = extractFile(filePath, charset); + result = importService.importAccountsChartFromEbp(datas); break; case EBP_ENTRIES_IMPORT: + //For windows ebp + charset = "ISO-8859-1"; filePath = chooseFile(true); - datas = extractFile(filePath); - result = importService.importAsEbpCSV(datas); + datas = extractFile(filePath, charset); + result = importService.importEntriesFromEbp(datas); break; } if (!result.equals("")){ @@ -195,19 +202,19 @@ * Open csv file and get his datas on a string * */ - public String extractFile(String path){ - byte[] buffer = new byte[(int) new File(path).length()]; + public String extractFile(String filePath, String charset){ + char[] datas = new char[(int) new File(filePath).length()]; try { - BufferedInputStream f = new BufferedInputStream(new FileInputStream(path)); - f.read(buffer); - f.close(); + BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), charset)); + in.read(datas); + in.close(); } catch (IOException eee) { if (log.isDebugEnabled()){ - log.debug("Can't read file "+path, eee); + log.debug("Can't read file "+filePath, eee); } } - return new String(buffer); + return new String(datas); } Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-07-13 14:29:30 UTC (rev 2968) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-07-15 09:47:22 UTC (rev 2969) @@ -102,7 +102,7 @@ lima.importexport.export=Export lima.importexport.financialstatements=Plan BCR lima.importexport.import=Import -lima.importexport.import.terminated=Import +lima.importexport.import.terminated=Import termin\u00E9 lima.importexport.lima=Import/Export Lima lima.init.closed=Lima ferm\u00E9 \u00E0 %1$s lima.init.errorclosing=