Author: dcosse Date: 2014-01-17 01:02:30 +0100 (Fri, 17 Jan 2014) New Revision: 3738 Url: http://chorem.org/projects/lima/repository/revisions/3738 Log: refs #429 must be fix but need deeper test Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.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/FinancialTransactionServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2014-01-06 16:50:14 UTC (rev 3737) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2014-01-17 00:02:30 UTC (rev 3738) @@ -555,8 +555,6 @@ BigDecimal currentSoldeDebit = new BigDecimal(0); BigDecimal currentSoldeCredit = new BigDecimal(0); - Identity identity = identityService.getIdentity(); - //create pages int i = 0; int n = list.size(); 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 2014-01-06 16:50:14 UTC (rev 3737) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2014-01-17 00:02:30 UTC (rev 3738) @@ -56,6 +56,7 @@ import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; +import java.io.IOException; import java.io.StringWriter; import java.text.SimpleDateFormat; import java.util.List; @@ -77,81 +78,111 @@ private static final SimpleDateFormat SDATEFORMAT = new SimpleDateFormat("dd,MM,yyyy HH:mm:ss"); + protected final String DATE_PATTERN = "dd/MM/yyyy"; + //############## EXPORT EBP /** * Export entries to EBP - * Struturce example : 1,010101,VE,411ART,, "Ventes d’ordinateur ", "123 ",12548.95,D,010301, - * Can't use opencsv for create export because don't support "" for just some columns + * Structure example : DatEcr,Journal,Compte,Libelle,Piece,Debit,Credit,Lettre + * 01/01/2013,AN,101,Capital,1,0,100000.00,C */ @Override public String exportEntriesAsEBP() throws LimaException { - SimpleDateFormat epbDateFormat = new SimpleDateFormat("ddMMyyyy"); - StringBuilder result = new StringBuilder(); - int num = 0; + SimpleDateFormat epbDateFormat = new SimpleDateFormat(DATE_PATTERN); + StringWriter out = new StringWriter(); + CSVWriter csvWriter = null; try { + csvWriter = new CSVWriter(out, + CSVWriter.DEFAULT_SEPARATOR, + CSVWriter.NO_QUOTE_CHARACTER); //export entries FinancialTransactionDAO financialTransactionDAO = getDaoHelper().getFinancialTransactionDAO(); List<FinancialTransaction> listFinancialTransaction = financialTransactionDAO.findAll(); + + String[] nextLine = new String[8]; + + // Add the header line + if (!listFinancialTransaction.isEmpty()) { + nextLine[0] = "DatEcr"; + nextLine[1] = "Journal"; + nextLine[2] = "Compte"; + nextLine[3] = "Libelle"; + nextLine[4] = "Piece"; + nextLine[5] = "Debit"; + nextLine[6] = "Credit"; + nextLine[7] = "Lettre"; + // Ajoute la ligne au fichier + csvWriter.writeNext(nextLine); + } + + String date, debitcredit, debit, credit, entrybookCode, accountNumber; + EntryBook entryBook; + Account account; + // For all financialTransaction for (FinancialTransaction financialTransaction : listFinancialTransaction) { - String date = epbDateFormat.format(financialTransaction.getTransactionDate()); - String entrybookCode = ""; - EntryBook entryBook = financialTransaction.getEntryBook(); + date = epbDateFormat.format(financialTransaction.getTransactionDate()); + entryBook = financialTransaction.getEntryBook(); + if (entryBook != null) { entrybookCode = entryBook.getCode(); + } else { + entrybookCode = ""; } - String[] nextLine = new String[11]; for (Entry entry : financialTransaction.getEntry()) { - num++; - Account account = entry.getAccount(); + account = entry.getAccount(); - String accountNumber = ""; if (account != null) { accountNumber = entry.getAccount().getAccountNumber(); + } else { + accountNumber = ""; } - String debitcredit = ""; + debit = "0"; + credit = "0"; if (entry.getDebit()) { debitcredit = "D"; + debit = entry.getAmount().toString(); } else { debitcredit = "C"; + credit = entry.getAmount().toString(); } - nextLine[0] = String.valueOf(num); - nextLine[1] = date; - nextLine[2] = entrybookCode; - nextLine[3] = accountNumber; - nextLine[5] = '"' + entry.getDescription() + '"'; - nextLine[6] = '"' + entry.getVoucher() + '"'; - nextLine[7] = entry.getAmount().toString(); - nextLine[8] = debitcredit; + nextLine[0] = date; + nextLine[1] = entrybookCode; + nextLine[2] = accountNumber; + nextLine[3] = entry.getDescription(); + nextLine[4] = entry.getVoucher(); + nextLine[5] = debit; + nextLine[6] = credit; + nextLine[7] = debitcredit; // Ajoute la ligne au fichier - for (int i = 0; i < 9; i++) { - String string = ""; - String nextln = nextLine[i]; - if (nextln != null) { - string = nextln; - } - if (i == 8) { - result.append(string).append("\r\n"); - } else { - result.append(string).append(","); - } - } + csvWriter.writeNext(nextLine); } } + // Write cache in string + csvWriter.flush(); } catch (Exception ex) { throw new LimaException("Can't export", ex); + } finally { + if (csvWriter != null) { + try { + csvWriter.close(); + out.close(); + } catch (IOException e) { + // nothing to do + } + } } - return result.toString(); + return out.getBuffer().toString(); } /** @@ -162,7 +193,7 @@ @Override public String exportAccountsAsEBP() throws LimaException { StringWriter out = new StringWriter(); - CSVWriter csvWriter; + CSVWriter csvWriter = null; try { csvWriter = new CSVWriter(out, @@ -185,6 +216,15 @@ csvWriter.close(); } catch (Exception ex) { throw new LimaException("Can't export", ex); + } finally { + if (csvWriter != null) { + try { + csvWriter.close(); + out.close(); + } catch (IOException e) { + // nothing to do + } + } } return out.getBuffer().toString(); } @@ -196,7 +236,7 @@ @Override public String exportAsCSV() throws LimaException { StringWriter out = new StringWriter(); - CSVWriter csvWriter; + CSVWriter csvWriter = null; try { csvWriter = new CSVWriter(out, ';'); @@ -209,9 +249,17 @@ exportIdentityAsCSV(csvWriter); // Write cache in string csvWriter.flush(); - csvWriter.close(); } catch (Exception ex) { throw new LimaException("Can't export", ex); + } finally { + if (csvWriter != null) { + try { + csvWriter.close(); + out.close(); + } catch (IOException e) { + // nothing to do + } + } } return out.getBuffer().toString(); } @@ -222,16 +270,24 @@ public String exportFinancialStatementChartAsCSV() throws LimaException { StringWriter out = new StringWriter(); - CSVWriter csvWriter; + CSVWriter csvWriter = null; try { csvWriter = new CSVWriter(out, ';'); exportFinancialStatementChartAsCSV(csvWriter); // Write cache in file csvWriter.flush(); - csvWriter.close(); } catch (Exception ex) { throw new LimaException("Can't export", ex); + } finally { + if (csvWriter != null) { + try { + csvWriter.close(); + out.close(); + } catch (IOException e) { + // nothing to do + } + } } return out.getBuffer().toString(); } @@ -298,16 +354,24 @@ public String exportVatStatementChartAsCSV() throws LimaException { StringWriter out = new StringWriter(); - CSVWriter csvWriter; + CSVWriter csvWriter = null; try { csvWriter = new CSVWriter(out, ';'); exportVatStatementChartAsCSV(csvWriter); // Write cache in file csvWriter.flush(); - csvWriter.close(); } catch (Exception ex) { throw new LimaException("Can't export", ex); + } finally { + if (csvWriter != null) { + try { + csvWriter.close(); + out.close(); + } catch (IOException e) { + // nothing to do + } + } } return out.getBuffer().toString(); @@ -360,16 +424,24 @@ public String exportEntryBookChartAsCSV() throws LimaException { StringWriter out = new StringWriter(); - CSVWriter csvWriter; + CSVWriter csvWriter = null; try { csvWriter = new CSVWriter(out, ';'); exportEntryBookChartAsCSV(csvWriter); // Write cache in file csvWriter.flush(); - csvWriter.close(); } catch (Exception ex) { throw new LimaException("Can't export", ex); + } finally { + if (csvWriter != null) { + try { + csvWriter.close(); + out.close(); + } catch (IOException e) { + // nothing to do + } + } } return out.getBuffer().toString(); } @@ -406,16 +478,24 @@ @Override public String exportAccountsChartAsCSV() throws LimaException { StringWriter out = new StringWriter(); - CSVWriter csvWriter; + CSVWriter csvWriter = null; try { csvWriter = new CSVWriter(out, ';'); exportAccountsChartAsCSV(csvWriter); // Write cache in file csvWriter.flush(); - csvWriter.close(); } catch (Exception ex) { throw new LimaException("Can't export", ex); + } finally { + if (csvWriter != null) { + try { + csvWriter.close(); + out.close(); + } catch (IOException e) { + // nothing to do + } + } } return out.getBuffer().toString(); } @@ -539,7 +619,6 @@ * Structure : TYPE | Locked | FinancialPeriod beginDate | FinancialPeriod endDate | EntryBook Code * * @param csvWriter - * @param topiaContext * @throws LimaException */ public void exportClosedPeriodicEntryBooksAsCSV(CSVWriter csvWriter) throws LimaException { Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2014-01-06 16:50:14 UTC (rev 3737) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2014-01-17 00:02:30 UTC (rev 3738) @@ -102,7 +102,7 @@ @Override public FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { - FinancialTransaction fTransaction = null; + FinancialTransaction fTransaction; AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); try { @@ -125,7 +125,7 @@ @Override public List<FinancialTransaction> getAllFinancialTransactions( Date beginDate, Date endDate) throws LimaException { - List<FinancialTransaction> financialTransactions = null; + List<FinancialTransaction> financialTransactions; try { FinancialTransactionDAO transactionDAO = getDaoHelper().getFinancialTransactionDAO(); @@ -142,7 +142,7 @@ @Override public String getNextLetters() throws LimaException { String lastActualLetters; - String nextLetters = ""; + String nextLetters; try { EntryDAO entryDAO = getDaoHelper().getEntryDAO(); @@ -161,7 +161,7 @@ public static String lettersAfter(String letters) { - String letterAfter = null; + String letterAfter; /* "" -> "A" */ if (StringUtils.isEmpty(letters)) { @@ -349,7 +349,7 @@ @Override public List<FinancialTransaction> getAllFinancialTransactions( FiscalPeriod period) throws LimaException { - List<FinancialTransaction> financialTransactions = null; + List<FinancialTransaction> financialTransactions; try { FinancialTransactionDAO transactionDAO = getDaoHelper().getFinancialTransactionDAO(); @@ -366,7 +366,7 @@ @Override public List<FinancialTransaction> getAllFinancialTransactions(FinancialPeriod financialPeriod, EntryBook entryBook) throws LimaException { - List<FinancialTransaction> financialTransactions = null; + List<FinancialTransaction> financialTransactions; try { FinancialTransactionDAO transactionDAO = getDaoHelper().getFinancialTransactionDAO(); @@ -391,7 +391,7 @@ @Override public List<FinancialTransaction> getAllInexactFinancialTransactions(FiscalPeriod fiscalPeriod) throws LimaException { - List<FinancialTransaction> result = null; + List<FinancialTransaction> result; //List<FinancialTransaction> checkedResult = new ArrayList<FinancialTransaction>(); try { @@ -418,15 +418,15 @@ } /** - * Get balanced financialtransaction from selected fiscalperiod + * Get balanced financial transaction from selected fiscal period * - * @param fiscalPeriod - * @return + * @param fiscalPeriod The fiscal period for financial transaction + * @return the balanced financial transaction * @throws LimaException */ @Override public List<FinancialTransaction> getAllFinancialTransactionsBalanced(FiscalPeriod fiscalPeriod) throws LimaException { - List<FinancialTransaction> result = null; + List<FinancialTransaction> result; try { FinancialTransactionDAO financialTransactionDAO = getDaoHelper().getFinancialTransactionDAO(); @@ -489,11 +489,8 @@ accountingRules.updateFinancialTransactionDateRules(financialTransaction, financialTransactionOld); - Date financialTransactionOldDate = financialTransactionOld.getTransactionDate(); - Date financialTransactionDate = financialTransaction.getTransactionDate(); - financialTransactionOld.setEntryBook(financialTransaction.getEntryBook()); - financialTransactionOld.setTransactionDate(financialTransactionDate); + financialTransactionOld.setTransactionDate(financialTransaction.getTransactionDate()); transactionDAO.update(financialTransactionOld); } catch (TopiaException ex) { @@ -527,7 +524,7 @@ public Entry createEntry(Entry entry) throws LimaException { AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); - Entry newEntry = null; + Entry newEntry; try { //check if the financial period is blocked accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( 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 2014-01-06 16:50:14 UTC (rev 3737) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-01-17 00:02:30 UTC (rev 3738) @@ -82,7 +82,6 @@ import org.chorem.lima.business.api.IdentityService; import org.chorem.lima.business.api.ImportService; import org.chorem.lima.business.api.VatStatementService; -import org.chorem.lima.business.utils.AccountEBPComparator; import org.chorem.lima.business.utils.DocumentsEnum; import org.chorem.lima.business.utils.EntryEBPComparator; import org.chorem.lima.business.utils.FiscalPeriodComparator; @@ -131,6 +130,8 @@ private static final Log log = LogFactory.getLog(ImportServiceImpl.class); + protected final String DATE_PATTERN = "dd/MM/yyyy"; + @EJB private AccountService accountService; @@ -163,13 +164,19 @@ @Override public String importEntriesFromEbp(String datas) throws LimaException { + if (datas.isEmpty()) { + throw new LimaBusinessException(_("lima-business.import.ebpnoentry")); + } + + // use for logs long before = System.currentTimeMillis(); - SimpleDateFormat epbDateFormat = new SimpleDateFormat("dd/MM/yyyy"); + SimpleDateFormat epbDateFormat = new SimpleDateFormat(DATE_PATTERN); StringBuilder result = new StringBuilder(); + CSVReader csvReader = null; try { - CSVReader csvReader = new CSVReader(new StringReader(datas)); + csvReader = new CSVReader(new StringReader(datas)); ColumnPositionMappingStrategy<EntryEBPImpl> strat = new ColumnPositionMappingStrategy<EntryEBPImpl>(); strat.setType(EntryEBPImpl.class); // read header to set strategy mapping @@ -177,20 +184,20 @@ // check if file have a good header List<String> headEntry = new ArrayList<String>(); + headEntry.add("DatEcr"); headEntry.add("Journal"); headEntry.add("Compte"); - headEntry.add("DatEcr"); + headEntry.add("Libelle"); headEntry.add("Piece"); - headEntry.add("Libelle"); headEntry.add("Debit"); headEntry.add("Credit"); headEntry.add("Lettre"); - if (!Arrays.asList(strat.getColumnMapping()).containsAll( - headEntry)) { + if (!Arrays.asList(strat.getColumnMapping()).containsAll(headEntry)) { throw new LimaBusinessException( - _("lima-business.import.ebpnoentry")); + _("lima-business.import.ebpnoheader")); } + // Sorts the list according to the entry date CsvToBean<EntryEBPImpl> csv = new CsvToBean<EntryEBPImpl>(); List<EntryEBPImpl> list = csv.parse(strat, csvReader); Collections.sort(list, new EntryEBPComparator()); @@ -198,92 +205,143 @@ // DAOs AccountDAO accountDAO = getDaoHelper().getAccountDAO(); EntryBookDAO entryBookDAO = getDaoHelper().getEntryBookDAO(); - List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllUnblockedFiscalPeriods(); + + // Get all the valid fiscalPeriods Ordered by date. + List<FiscalPeriod> fiscalPeriods = fiscalPeriodService + .getAllUnblockedFiscalPeriods(); Collections.sort(fiscalPeriods, new FiscalPeriodComparator()); + + // There are no valid fiscalPeriods -> exception int nbFiscalPeriods = fiscalPeriods.size(); - FinancialPeriodDAO financialPeriodDAO = getDaoHelper().getFinancialPeriodDAO(); - if (nbFiscalPeriods == 0) { throw new LimaBusinessException( _("lima-business.import.nofiscalperiodopen")); } + // attributes declaration FinancialTransaction financialTransaction = null; + Date dateEcr; + Account account; + Entry entry; + BigDecimal debit; + String entryBookCode; + EntryBook entryBook; + + // For all entries loaded from the file + // the entry is validate (checking for valide FiscalPeriod and existing Account associated to it) + // if valid entry + // the entry entity is created and the association with it's dependant entites (Account are FinancialTransaction) are created + for (EntryEBP entryEBP : list) { - // create entry - Entry entry = new EntryImpl(); - Account account = accountDAO.findByAccountNumber(entryEBP.getCompte()); + dateEcr = epbDateFormat.parse(entryEBP.getDatEcr()); - Date date = epbDateFormat.parse(entryEBP.getDatEcr()); - Date beginDate = fiscalPeriods.get(0).getBeginDate(); - Date endDate = fiscalPeriods.get(nbFiscalPeriods - 1).getEndDate(); + // account loading + account = accountDAO.findByAccountNumber(entryEBP + .getCompte()); - //if entry date have fiscalperiod open - if (date.compareTo(beginDate) < 0 || date.compareTo(endDate) > 0) { + // if entry date have fiscalperiod open + if (dateEcr.compareTo(fiscalPeriods.get(0).getBeginDate()) < 0 + || dateEcr.compareTo(fiscalPeriods.get(nbFiscalPeriods - 1).getEndDate()) > 0) { + result.append(_( + "lima-business.import.entriesoutofdatesrange", dateEcr)); + } - result.append(_("lima-business.import.entriesoutofdatesrange", date)); - } - // if account not exist not export + // if account not exist not export -> exception else if (account == null) { - throw new LimaBusinessException( - _("lima-business.import.ebpmissingaccount", - entryEBP.getCompte())); + throw new LimaBusinessException(_( + "lima-business.import.ebpmissingaccount", + entryEBP.getCompte())); } - //create entry + + // create entry else { - entry.setAccount(account); - BigDecimal debit = new BigDecimal(entryEBP.getDebit()); - BigDecimal credit = new BigDecimal(entryEBP.getCredit()); - if (debit == BigDecimal.ZERO) { + + // creation of the entry + // initialisation of this attributs + + entry = new EntryImpl(); + + // the entry has one amount witch can be Debit or Credit + // regarding the value of the boolean:debit + debit = new BigDecimal(entryEBP.getDebit()); + if (BigDecimal.ZERO.compareTo(debit)==0) { entry.setDebit(false); - entry.setAmount(credit); + entry.setAmount(new BigDecimal(entryEBP.getCredit())); } else { entry.setDebit(true); entry.setAmount(debit); } + entry.setAccount(account); entry.setDescription(entryEBP.getLibelle()); entry.setVoucher(entryEBP.getPiece()); - entry.setLettering(entryEBP.getLettre()); - String entryBookCode = entryEBP.getJournal(); - EntryBook entryBook = entryBookDAO - .findByCode(entryBookCode); + // Association of the entry with the financialTransaction + // Each financialTransaction is associated with an entryBook + // loading of the entryBook from the db according to the entryBookCode + // if the entryBook doesn't exist it's entity is created + // if any financialTransaction exist for the entry + // a financialTransaction entity is created associated with the entryBook + // creation of the entry entity + // association between the entry and the financialTransaction is done. + + entryBookCode = entryEBP.getJournal(); + // entryBook loading + entryBook = entryBookDAO.findByCode(entryBookCode); + // if entrybook not exist create it ! if (entryBook == null) { entryBook = new EntryBookImpl(); entryBook.setCode(entryBookCode); + //financialTransaction = null; // create it - entryBookService.createEntryBook(entryBook); - result.append(_("lima-business.import.entrybooknotexist", entryBook)); + entryBook = entryBookService.createEntryBook(entryBook); + result.append(_( + "lima-business.import.entrybooknotexist", + entryBook)); } - //create transaction + + // create transaction if (financialTransaction == null - || !(date.equals(financialTransaction.getTransactionDate()) - && entryBook.getCode().equals(financialTransaction.getEntryBook().getCode()))) { - + || !(dateEcr.equals(financialTransaction + .getTransactionDate()) && entryBook + .getCode().equals( + financialTransaction.getEntryBook() + .getCode()))) { // create financial transaction financialTransaction = new FinancialTransactionImpl(); financialTransaction.setEntryBook(entryBook); - financialTransaction.setTransactionDate(date); - financialTransactionService + financialTransaction.setTransactionDate(dateEcr); + financialTransaction = financialTransactionService .createFinancialTransaction(financialTransaction); - result.append(_("lima-business.import.transactionadded", date, entryBook.getCode())); + result.append(_( + "lima-business.import.transactionadded", dateEcr, + entryBook.getCode())); + } + // Inside the db, the entries reference the financialTransaction + entry.setFinancialTransaction(financialTransaction); + entry = financialTransactionService.createEntry(entry); + result.append(_("lima-business.import.entryadded", + entry.getDescription(), entry.getAmount())); - } - financialTransaction.addEntry(entry); - financialTransactionService.createEntry(entry); - result.append(_("lima-business.import.entryadded", entry.getDescription(), entry.getAmount())); } } - if (log.isInfoEnabled()) { + long after = System.currentTimeMillis(); - log.info("Imported form EBP : " + list.size() + " entries in " + (after-before) + " ms"); + log.info("Imported form EBP : " + list.size() + " entries in " + + (after - before) + " ms"); } - } catch (Exception ex) { throw new LimaException("Can't import", ex); + } finally { + if (csvReader != null) { + try { + csvReader.close(); + } catch (IOException e) { + // on fait rien + } + } } return result.toString(); } @@ -291,16 +349,14 @@ @Override public String importAccountsChartFromEbp(String datas) throws LimaException { long before = System.currentTimeMillis(); - StringBuilder result = new StringBuilder(); - + CSVReader csvReader = null; try { - CSVReader csvReader = new CSVReader(new StringReader(datas)); + 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()); - // check if file have a good header List<String> headAccount = new ArrayList<String>(); headAccount.add("Numero"); @@ -315,32 +371,41 @@ // creating beans instance CsvToBean<AccountEBPImpl> csv = new CsvToBean<AccountEBPImpl>(); List<AccountEBPImpl> list = csv.parse(strat, csvReader); - Collections.sort(list, new AccountEBPComparator()); AccountDAO accountDAO = getDaoHelper().getAccountDAO(); for (AccountEBP accountEBP : list) { String accountNumber = accountEBP.getNumero(); if (accountDAO.findByAccountNumber(accountNumber) != null) { - result.append(_("lima-business.import.accountalreadyexist", accountNumber)); + result.append(_("lima-business.import.accountalreadyexist", + accountNumber)); } else { String label = accountEBP.getIntitule(); Account account = new AccountImpl(); account.setAccountNumber(accountNumber); account.setLabel(label); accountService.createAccount(account); - result.append(_("lima-business.import.accountadded", accountNumber, label)); + result.append(_("lima-business.import.accountadded", + accountNumber, label)); } } - + if (log.isInfoEnabled()) { long after = System.currentTimeMillis(); - log.info("Imported form EBP : " + list.size() + " accounts in " + (after-before) + " ms"); + log.info("Imported form EBP : " + list.size() + " accounts in " + + (after - before) + " ms"); } } catch (Exception ex) { throw new LimaException("Can't import", ex); + } finally { + if (csvReader != null) { + try { + csvReader.close(); + } catch (IOException e) { + // on fait rien + } + } } - return result.toString(); } @@ -349,9 +414,10 @@ long before = System.currentTimeMillis(); StringBuilder result = new StringBuilder(); + CSVReader csvReader = null; try { - CSVReader csvReader = new CSVReader(new StringReader(datas)); + csvReader = new CSVReader(new StringReader(datas)); // check if file have a good header String[] headers = csvReader.readNext(); @@ -373,9 +439,7 @@ line = csvReader.readNext(); } - - csvReader.close(); - + if (log.isInfoEnabled()) { long after = System.currentTimeMillis(); log.info("Imported form EBP : " + count + " accounts in " + (after-before) + " ms"); @@ -383,6 +447,14 @@ } catch (Exception ex) { throw new LimaException("Can't import", ex); + } finally { + if (csvReader != null) { + try { + csvReader.close(); + } catch (IOException e) { + // on fait rien + } + } } return result.toString(); @@ -413,10 +485,11 @@ Map<Integer, List<EntryImport>> entries = new HashMap<Integer, List<EntryImport>>(); + CSVReader csvReader = null; try { String[] nextLine; - CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); + csvReader = new CSVReader(new StringReader(datas), ';'); while ((nextLine = csvReader.readNext()) != null) { ImportExportEntityEnum importExportEntityEnum = ImportExportEntityEnum @@ -474,6 +547,14 @@ } catch (Exception ex) { throw new LimaException("Can't import", ex); + } finally { + if (csvReader != null) { + try { + csvReader.close(); + } catch (IOException e) { + // on fait rien + } + } } return result.toString(); } @@ -510,11 +591,11 @@ entries = new HashMap<Integer, List<EntryImport>>(); break; } - + CSVReader csvReader = null; try { String[] nextLine; - CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); + csvReader = new CSVReader(new StringReader(datas), ';'); while ((nextLine = csvReader.readNext()) != null) { if (ImportExportEntityEnum.valueOfLabel(nextLine[0]) == importExportEntityEnum @@ -573,6 +654,14 @@ } catch (Exception ex) { throw new LimaException("Can't import", ex); + } finally { + if (csvReader != null) { + try { + csvReader.close(); + } catch (IOException e) { + // on fait rien + } + } } return result.toString(); } @@ -584,6 +673,7 @@ StringBuilder result = new StringBuilder(); + PDDocument doc = null; try { String path = LimaConfig.getInstance().getReportsDir().getAbsolutePath(); @@ -592,7 +682,6 @@ String filePathStructured = path + File.separator + DocumentsEnum.VAT.getFileName() + "_structure.pdf"; - PDDocument doc; InputStream reportsStream = new FileInputStream(datas); //DocumentServiceImpl.class.getResourceAsStream("/reports/vat_form_fr.pdf"); // load the document @@ -618,13 +707,20 @@ if (setMode) { LimaConfig.getInstance().setVatPDFUrl(datas); } - doc.close(); } catch (IOException ex) { log.error("Can't read vat pdf", ex); result.append("Can't read vat pdf"); } catch (COSVisitorException ex) { log.error("Can't save vat pdf", ex); result.append("Can't save vat pdf"); + } finally { + try { + if (doc != null) { + doc.close(); + } + } catch (Exception e) { + // Nothing to do + } } return result.toString(); } @@ -742,7 +838,6 @@ * * @param nextLine * @param closedPeriodicEntryBooks - * @param topiaContext * @throws LimaException */ protected void importClosedPeriodicEntryBookCSV(String[] nextLine, @@ -816,7 +911,7 @@ } else { List<FinancialStatementImport> list = new ArrayList<FinancialStatementImport>(); list.add(financialStatementImport); - financialStatements.put(label, (ArrayList<FinancialStatementImport>) list); + financialStatements.put(label, list); } } else { result.append(_("lima-business.import.financialstatementalreadyexist", label)); @@ -865,7 +960,7 @@ } else { List<VatStatementImport> list = new ArrayList<VatStatementImport>(); list.add(vatStatementImport); - vatStatements.put(label, (ArrayList<VatStatementImport>) list); + vatStatements.put(label, list); } } else { result.append(_("lima-business.import.vatstatementalreadyexist", label)); @@ -1124,7 +1219,7 @@ .findByEntryBookAndFinancialPeriod(entryBook, financialPeriod); try { - closedPeriodicEntryBook = financialPeriodService + financialPeriodService .blockClosedPeriodicEntryBook(closedPeriodicEntryBook); result.append(_("lima-business.import.closedperiodicentrybookupdated", beginDateFinancialPeriod, endDateFinancialPeriod, codeEntryBook)); @@ -1146,11 +1241,9 @@ Map<Integer, FinancialTransactionImport> financialTransactions, Map<Integer, List<EntryImport>> entries) throws LimaException, ParseException, TopiaException { - StringBuilder result = new StringBuilder(); EntryBookDAO entryBookDAO = getDaoHelper().getEntryBookDAO(); EntryDAO entryDAO = getDaoHelper().getEntryDAO(); - FinancialPeriodDAO financialPeriodDAO = getDaoHelper().getFinancialPeriodDAO(); FinancialTransactionDAO financialTransactionDAO = getDaoHelper().getFinancialTransactionDAO(); AccountDAO accountDAO = getDaoHelper().getAccountDAO(); @@ -1190,7 +1283,7 @@ financialTransaction.addEntry(entry); } } - return result.toString(); + return ""; } protected String importIdentity(String[] nextLine) throws LimaException { Modified: trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties 2014-01-06 16:50:14 UTC (rev 3737) +++ trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties 2014-01-17 00:02:30 UTC (rev 3738) @@ -60,10 +60,11 @@ lima-business.document.solde=Solde lima-business.document.soldecredit=Credit solde lima-business.document.soldedebit=Debit solde +lima-business.document.unknow=POA lima-business.document.vat=VAT form lima-business.document.vatnumber=VAT N° lima-business.document.voucher=Voucher -lima-business.document.zipcode= +lima-business.document.zipcode=Zipcode lima-business.entrybook.entrybookalreadyexist=An EntryBook already exists with this code \: %s lima-business.financialstatement.check.nothing=Not found \: %s - %s \n lima-business.financialstatement.check.warn=Warning this function is just an help.\n Many accounts must no calculate on Financial statement.\n Some account marked not found is normally.\n\n @@ -84,6 +85,7 @@ lima-business.import.closedperiodicentrybookupdated=SUCCESS \: The blockClosedPeriodicEntryBook %s - %s - %s is updated \! \n lima-business.import.ebpmissingaccount=FAILED \: Account %s already exist, import aborted. \nCreate all accounts before import entries. lima-business.import.ebpnoentry=FAILED \: This file contains no entries. +lima-business.import.ebpnoheader=FAILED \: This file has no header datas. lima-business.import.entriesoutofdatesrange=WARNING \: %s entries is out of range of opened fiscal periods. Entry was skip \!\n lima-business.import.entryadded=SUCCES \: Entry %s %s added\n" lima-business.import.entrybookalreadyexist=FAILED \: The entrybook %s already exists \!\n Modified: trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2014-01-06 16:50:14 UTC (rev 3737) +++ trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2014-01-17 00:02:30 UTC (rev 3738) @@ -86,6 +86,7 @@ lima-business.import.closedperiodicentrybookupdated=Succès \: La période financière %s - %s - %s est ajoutée \! \n lima-business.import.ebpmissingaccount=Échec \: Compte %s inexistant. \nImportation annulée. \nCréer tous les comptes avant d'importer les écritures. lima-business.import.ebpnoentry=Échec \: Ce fichier ne contient aucune entrée. +lima-business.import.ebpnoheader=Échec \: Ce fichier ne contient aucun entête. lima-business.import.entriesoutofdatesrange=Attention \: Cette entrée %s ne fait partie d'aucune période ouverte. Entrée non importée \!\n lima-business.import.entryadded=Succès \: Entrée %s %s ajoutée \n lima-business.import.entrybookalreadyexist=Échec \: Le journal %s exist déjà \!\n