This is an automated email from the git hooks/post-receive script. New change to branch feature/1174-Import_EBP_Transactions in repository lima. See http://git.chorem.org/lima.git at 866bcc2 refs #1174 création de transaction pour chaque changement de date puis de pièce comptable (déplacement de branche) This branch includes the following new commits: new 866bcc2 refs #1174 création de transaction pour chaque changement de date puis de pièce comptable (déplacement de branche) The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 866bcc2a5df3170524abe27deb16d95335fbee36 Author: dcosse <japbiw74> Date: Wed Feb 25 22:37:58 2015 +0100 refs #1174 création de transaction pour chaque changement de date puis de pièce comptable (déplacement de branche) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/1174-Import_EBP_Transactions in repository lima. See http://git.chorem.org/lima.git commit 866bcc2a5df3170524abe27deb16d95335fbee36 Author: dcosse <japbiw74> Date: Wed Feb 25 22:37:58 2015 +0100 refs #1174 création de transaction pour chaque changement de date puis de pièce comptable (déplacement de branche) --- .../lima/business/ejb/ImportServiceImpl.java | 99 ++++++++++++++++------ .../resources/i18n/lima-business_en_GB.properties | 3 + .../resources/i18n/lima-business_fr_FR.properties | 3 + .../org/chorem/lima/business/AbstractLimaTest.java | 63 ++++++++++++++ .../lima/business/ImportExportServiceTest.java | 31 ++++--- .../chorem/lima/ui/importexport/ImportExport.java | 93 ++++++++++---------- .../resources/i18n/lima-swing_en_GB.properties | 3 + .../resources/i18n/lima-swing_fr_FR.properties | 3 + 8 files changed, 215 insertions(+), 83 deletions(-) diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java index 188cd3f..27d5bca 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java @@ -23,8 +23,10 @@ package org.chorem.lima.business.ejb; */ import com.google.common.base.Function; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Ordering; +import com.google.common.collect.Sets; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.chorem.lima.beans.EntryEBP; @@ -57,7 +59,6 @@ import org.chorem.lima.business.exceptions.AlreadyExistEntryBookException; import org.chorem.lima.business.exceptions.AlreadyExistFinancialStatement; import org.chorem.lima.business.exceptions.AlreadyExistVatStatementException; import org.chorem.lima.business.exceptions.BeginAfterEndFiscalPeriodException; -import org.chorem.lima.business.exceptions.ImportEbpException; import org.chorem.lima.business.exceptions.ImportFileException; import org.chorem.lima.business.exceptions.InvalidAccountNumberException; import org.chorem.lima.business.exceptions.LockedEntryBookException; @@ -97,6 +98,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import static org.nuiton.i18n.I18n.t; @@ -815,7 +817,7 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ @Override public ImportExportResults importEntryBookFromEbp(String contents) { ImportExportResults results = new ImportExportResults(); - ImportResult result = results.createAddAndGetImportResult(Account.class); + ImportResult result = results.createAddAndGetImportResult(EntryBook.class); if (StringUtils.isBlank(contents)) { result.addException(new NoDataToImportException()); @@ -879,12 +881,14 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ // if entry date have fiscalperiod open if (dateEcr.compareTo(fiscalPeriodsBiginDate) < 0 || dateEcr.compareTo(fiscalPeriodsEndingDate) > 0) { - importResult.addException(new ImportEbpException(t("lima-business.import.entriesoutofdatesrange", dateEcr))); + importResult.addException(new ImportFileException(t("lima.import.error.entriesOutOfDatesRange", dateEcr))); + importResult.increaseIgnored(); result = false; } // if account not exist not export -> exception else if (account == null) { - importResult.addException(new ImportEbpException(t("lima-business.import.ebpmissingaccount", targetedAccount))); + importResult.addException(new ImportFileException(t("lima.import.error.invalidAccountNumber", targetedAccount))); + importResult.increaseIgnored(); result =false; } return result; @@ -893,7 +897,7 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ @Override public ImportExportResults importEntriesFromEbp(String contents) { ImportExportResults results = new ImportExportResults(); - ImportResult result = results.createAddAndGetImportResult(Account.class); + ImportResult result = results.createAddAndGetImportResult(Entry.class); // use for logs long before = System.currentTimeMillis(); @@ -924,9 +928,9 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ // 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 - Date fiscalPeriodsBiginDate = fiscalPeriods.get(0).getBeginDate(); + Date fiscalPeriodsBeginDate = fiscalPeriods.get(0).getBeginDate(); Date fiscalPeriodsEndingDate = fiscalPeriods.get(fiscalPeriods.size() - 1).getEndDate(); - Map<EntryBook, Map<Date, FinancialTransaction>> entryBookFinancialTransactionByDate = getEntryBookFinancialTransactionOrderedByDate(fiscalPeriodsBiginDate, fiscalPeriodsEndingDate); + Map<EntryBook, Map<Date, Set<FinancialTransaction>>> entryBookFinancialTransactionsByDate = getEntryBookFinancialTransactionOrderedByDate(fiscalPeriodsBeginDate, fiscalPeriodsEndingDate); for (EntryEBP entryEBP : entryEBPs) { Date dateEcr = entryEBP.getDatEcr(); @@ -934,7 +938,7 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ // account loading Account account = indexedAccounts.get(entryEBP.getCompte()); - if (!validEntry(result, dateEcr, fiscalPeriodsBiginDate, fiscalPeriodsEndingDate, account, entryEBP.getCompte())) { + if (!validEntry(result, dateEcr, fiscalPeriodsBeginDate, fiscalPeriodsEndingDate, account, entryEBP.getCompte())) { continue; } // create entry @@ -945,7 +949,7 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ try { // find financial transactions for entry period and entrybook - addEntryToFinancialTransaction(entry, entryEBP.getJournal(), indexedEntryBooks, entryBookFinancialTransactionByDate, dateEcr); + addEntryToFinancialTransaction(entry, entryEBP.getJournal(), indexedEntryBooks, entryBookFinancialTransactionsByDate, dateEcr); } catch (LockedFinancialPeriodException | LockedEntryBookException | AlreadyExistEntryBookException e) { result.addException(e); @@ -989,34 +993,68 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ return entry; } - protected void addEntryToFinancialTransaction(Entry entry, String entryBookCode, Map<String, EntryBook> indexedEntryBooks, Map<EntryBook, Map<Date, FinancialTransaction>> entryBookFinancialTransactionByDate, Date dateEcr) throws LockedFinancialPeriodException, LockedEntryBookException, AlreadyExistEntryBookException { + protected void addEntryToFinancialTransaction(Entry entry, String entryBookCode, Map<String, EntryBook> indexedEntryBooks, Map<EntryBook, Map<Date, Set<FinancialTransaction>>> entryBookFinancialTransactionsByDate, Date dateEcr) throws LockedFinancialPeriodException, LockedEntryBookException, AlreadyExistEntryBookException { EntryBook entryBook = getEntryBook(indexedEntryBooks, entryBookCode); - Map<Date, FinancialTransaction> financialTransactionsByDate = entryBookFinancialTransactionByDate.get(entryBook); + Map<Date, Set<FinancialTransaction>> financialTransactionsByDate = entryBookFinancialTransactionsByDate.get(entryBook); if (financialTransactionsByDate == null) { financialTransactionsByDate = new HashMap<>(); - entryBookFinancialTransactionByDate.put(entryBook, financialTransactionsByDate); + entryBookFinancialTransactionsByDate.put(entryBook, financialTransactionsByDate); + } + + // find financial transaction for this required date and required voucher. + Set<FinancialTransaction> financialTransactionsForDate = financialTransactionsByDate.get(dateEcr); + if (financialTransactionsForDate == null) { + financialTransactionsForDate = Sets.newHashSet(); + financialTransactionsByDate.put(dateEcr, financialTransactionsForDate); } - // create transaction - FinancialTransaction financialTransaction = financialTransactionsByDate.get(dateEcr); - if (financialTransaction == null - || !(dateEcr.equals(financialTransaction - .getTransactionDate()) && entryBook + String voucher = entry.getVoucher(); + + // look for an existing one + FinancialTransaction financialTransactionForDateAndVoucher = getFinancialTransactionForVoucher(financialTransactionsForDate, voucher); + + // if none exist a new one is created + if (financialTransactionForDateAndVoucher == null + || !(dateEcr.equals(financialTransactionForDateAndVoucher.getTransactionDate()) && entryBook .getCode().equals( - financialTransaction.getEntryBook() + financialTransactionForDateAndVoucher.getEntryBook() .getCode()))) { // create financial transaction - financialTransaction = financialTransactionService.createNewFinancialTransaction(); - financialTransaction.setEntryBook(entryBook); - financialTransaction.setTransactionDate(dateEcr); - financialTransaction = financialTransactionService.createFinancialTransaction(financialTransaction); - financialTransactionsByDate.put(financialTransaction.getTransactionDate(), financialTransaction); + financialTransactionForDateAndVoucher = financialTransactionService.createNewFinancialTransaction(); + financialTransactionForDateAndVoucher.setEntryBook(entryBook); + financialTransactionForDateAndVoucher.setTransactionDate(dateEcr); + financialTransactionForDateAndVoucher = financialTransactionService.createFinancialTransaction(financialTransactionForDateAndVoucher); + financialTransactionsForDate.add(financialTransactionForDateAndVoucher); } - financialTransaction.addEntry(entry); + + // add entry to financial transaction + financialTransactionForDateAndVoucher.addEntry(entry); financialTransactionService.createEntry(entry); } + private FinancialTransaction getFinancialTransactionForVoucher(Set<FinancialTransaction> financialTransactions, String voucher) { + FinancialTransaction financialTransactionForEntry = null; + if (financialTransactions != null) { + for (FinancialTransaction financialTransaction : financialTransactions) { + Collection<Entry> entries = financialTransaction.getEntry(); + if (entries != null && entries.iterator().hasNext()) { + Entry firstEntry = entries.iterator().next(); + if (firstEntry.getVoucher().contentEquals(voucher)) { + financialTransactionForEntry = financialTransaction; + break; + } + } else { + entries = Lists.newArrayList(); + financialTransaction.setEntry(entries); + financialTransactionForEntry = financialTransaction; + break; + } + } + } + return financialTransactionForEntry; + } + protected EntryBook getEntryBook(Map<String, EntryBook> indexedEntryBooks, String entryBookCode) throws AlreadyExistEntryBookException { EntryBook entryBook; // entryBook loading @@ -1034,19 +1072,24 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ return entryBook; } - protected Map<EntryBook, Map<Date, FinancialTransaction>> getEntryBookFinancialTransactionOrderedByDate(Date fiscalPeriodsBiginDate, Date fiscalPeriodsEndingDate) { - Map<EntryBook, Map<Date, FinancialTransaction>> entryBookFinancialTransactionByDate = new HashMap<>(); + protected Map<EntryBook, Map<Date, Set<FinancialTransaction>>> getEntryBookFinancialTransactionOrderedByDate(Date fiscalPeriodsBiginDate, Date fiscalPeriodsEndingDate) { + Map<EntryBook, Map<Date, Set<FinancialTransaction>>> entryBookFinancialTransactionByDate = new HashMap<>(); List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(fiscalPeriodsBiginDate, fiscalPeriodsEndingDate); for (FinancialTransaction ft : financialTransactions) { EntryBook eb = ft.getEntryBook(); - Map<Date, FinancialTransaction> entryBooksFTs = entryBookFinancialTransactionByDate.get(eb); + Map<Date, Set<FinancialTransaction>> entryBooksFTs = entryBookFinancialTransactionByDate.get(eb); if (entryBooksFTs == null) { entryBooksFTs = new HashMap<>(); entryBookFinancialTransactionByDate.put(eb, entryBooksFTs); } // maybe not unique financial transaction for one date. // is there a way to know wich one to take ? - entryBooksFTs.put(ft.getTransactionDate(), ft); + Set<FinancialTransaction> financialTransactionsForEntryBook = entryBooksFTs.get(ft.getTransactionDate()); + if (financialTransactionsForEntryBook == null) { + financialTransactionsForEntryBook = Sets.newHashSet(); + } + financialTransactionsForEntryBook.add(ft); + entryBooksFTs.put(ft.getTransactionDate(), financialTransactionsForEntryBook); } return entryBookFinancialTransactionByDate; } diff --git a/lima-business/src/main/resources/i18n/lima-business_en_GB.properties b/lima-business/src/main/resources/i18n/lima-business_en_GB.properties index 7fd8ad5..150a777 100644 --- a/lima-business/src/main/resources/i18n/lima-business_en_GB.properties +++ b/lima-business/src/main/resources/i18n/lima-business_en_GB.properties @@ -125,6 +125,7 @@ lima-business.import.transactionadded=SUCCES \: FinancialTransaction, %s - %s, a lima-business.import.vatstatementadded=SUCCESS \: The vatStatement %s is created \n lima-business.import.vatstatementalnomaster=FAILED \: The vatStatement %s has master \: %s which not exist \n lima-business.import.vatstatementalreadyexist=FAILED \: The vatStatement %s already exists \!\n +lima.account.error.invalidAccountNumber= lima.config.configFileName.description=Filename of Lima's configuration lima.config.data.dir.description=Data directory of Lima lima.config.documentReport.account.documentReportModelPath.description= @@ -149,6 +150,8 @@ lima.config.serveraddress.description=Server Address lima.configFileName.description= lima.financialtransaction.account= lima.fiscalperiod.fiscalperiod= +lima.import.error.entriesOutOfDatesRange= +lima.import.error.invalidAccountNumber= lima.importexport.import.alreadyExistFinancialStatement= lima.lettering.accountRegularization= lima.reports.account.noaccount= diff --git a/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties b/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties index fe80f59..c050317 100644 --- a/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties +++ b/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties @@ -120,6 +120,7 @@ lima-business.import.transactionadded=Succès \: Transaction, %s, %s, ajoutée\n lima-business.import.vatstatementadded=Succès \: Plan de TVA %s ajoutée \n lima-business.import.vatstatementalnomaster=u00C9chec \: Le plan %s possède le master \: %s inexsitant \n lima-business.import.vatstatementalreadyexist=u00C9chec \: Le plan %s exist déjà \!\n +lima.account.error.invalidAccountNumber= lima.config.configFileName.description=Nom du fichier de configuration de Lima lima.config.data.dir.description=Répertoire des données de Lima lima.config.documentReport.account.accountModelPath.description=fichier source (.jrxml) généré par Jasper Report gérant les beans 'account' @@ -149,6 +150,8 @@ lima.config.serveraddress.description=Addresse serveur lima.configFileName.description= lima.financialtransaction.account= lima.fiscalperiod.fiscalperiod= +lima.import.error.entriesOutOfDatesRange= +lima.import.error.invalidAccountNumber= lima.importexport.import.alreadyExistFinancialStatement= lima.lettering.accountRegularization= lima.reports.account.noaccount= diff --git a/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java b/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java index dab04ce..7357605 100644 --- a/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java +++ b/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java @@ -808,4 +808,67 @@ public abstract class AbstractLimaTest { transaction1.setEntry(Lists.newArrayList(tr1Entry1, tr1Entry2)); financialTransactionService.updateFinancialTransaction(transaction1); } + + protected void initTestWithSomeFinancialTransaction() throws Exception { + + initTestWithFiscalPeriod(); + Account accountVmpVae = accountService.getAccountByNumber("511"); + EntryBook journalDesVentes = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction1 = new FinancialTransactionImpl(); + transaction1.setTransactionDate(df.parse("April 4, 2012")); + transaction1.setEntryBook(journalDesVentes); + transaction1 = financialTransactionService.createFinancialTransaction(transaction1); + + Entry tr1Entry1 = new EntryImpl(); + tr1Entry1.setAmount(BigDecimal.valueOf(42.0)); + tr1Entry1.setAccount(accountVmpVae); + tr1Entry1.setFinancialTransaction(transaction1); + tr1Entry1.setDescription("test desc"); + tr1Entry1.setVoucher("voucherA"); + tr1Entry1 = financialTransactionService.createEntry(tr1Entry1); + + Entry tr1Entry2 = new EntryImpl(); + tr1Entry2.setAmount(BigDecimal.valueOf(42.0)); + tr1Entry2.setDebit(true); + tr1Entry2.setAccount(accountVmpVae); + tr1Entry2.setFinancialTransaction(transaction1); + tr1Entry2.setDescription("test desc"); + tr1Entry2.setVoucher("voucherA"); + tr1Entry2 = financialTransactionService.createEntry(tr1Entry2); + + transaction1.setEntry(Lists.newArrayList(tr1Entry1, tr1Entry2)); + financialTransactionService.updateFinancialTransaction(transaction1); + + FinancialTransaction transaction2 = new FinancialTransactionImpl(); + transaction2.setTransactionDate(df.parse("April 4, 2012")); + transaction2.setEntryBook(journalDesVentes); + transaction2 = financialTransactionService.createFinancialTransaction(transaction2); + + Entry tr1Entry1b = new EntryImpl(); + tr1Entry1b.setAmount(BigDecimal.valueOf(12.0)); + tr1Entry1b.setAccount(accountVmpVae); + tr1Entry1b.setFinancialTransaction(transaction2); + tr1Entry1b.setDescription("test desc"); + tr1Entry1b.setVoucher("voucherB"); + financialTransactionService.createEntry(tr1Entry1b); + + Entry tr1Entry2b = new EntryImpl(); + tr1Entry2b.setAmount(BigDecimal.valueOf(6.0)); + tr1Entry2b.setDebit(true); + tr1Entry2b.setAccount(accountVmpVae); + tr1Entry2b.setFinancialTransaction(transaction2); + tr1Entry2b.setDescription("test desc"); + tr1Entry2b.setVoucher("voucherB"); + financialTransactionService.createEntry(tr1Entry2b); + + Entry tr1Entry3b = new EntryImpl(); + tr1Entry3b.setAmount(BigDecimal.valueOf(6.0)); + tr1Entry3b.setDebit(true); + tr1Entry3b.setAccount(accountVmpVae); + tr1Entry3b.setFinancialTransaction(transaction2); + tr1Entry3b.setDescription("test desc"); + tr1Entry3b.setVoucher("voucherB"); + financialTransactionService.createEntry(tr1Entry3b); + } } diff --git a/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java b/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java index 92d6e08..05420e0 100644 --- a/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java +++ b/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java @@ -55,6 +55,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; +import java.math.BigDecimal; import java.nio.charset.Charset; import java.text.ParseException; import java.util.ArrayList; @@ -542,7 +543,7 @@ public class ImportExportServiceTest extends AbstractLimaTest { @Test public void testExportImportEntriesEbp() throws Exception { - initTestWithFinancialTransaction(); + initTestWithSomeFinancialTransaction(); List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012")); List<Entry> entries = Lists.newArrayList(); @@ -577,27 +578,33 @@ public class ImportExportServiceTest extends AbstractLimaTest { // test import FileInputStream contentStream = null; - ImportResult result; try { contentStream = new FileInputStream(tmpDir + "export-entries-EBP.csv"); String inputStream = IOUtils.toString(contentStream); - result = importService.importEntriesFromEbp(inputStream).getImportResults().get(0); + importService.importEntriesFromEbp(inputStream).getImportResults().get(0); } finally { IOUtils.closeQuietly(contentStream); } // valid import financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012")); - Assert.assertEquals(1, financialTransactions.size()); + Assert.assertEquals(2, financialTransactions.size()); for (FinancialTransaction financialTransaction : financialTransactions) { - entries.addAll(financialTransaction.getEntry()); - } - - Assert.assertEquals(nbEntities, entries.size()); - Assert.assertEquals(nbEntities, result.getNbCreated()); - Assert.assertNull(result.getAllExceptionsByLine()); - for (Entry entry : entries) { - Assert.assertTrue(42.0 == entry.getAmount().doubleValue()); + if (financialTransaction.getAmountDebit().compareTo(BigDecimal.valueOf(42.0)) == 0) { + Collection<Entry> voucherAEntries = financialTransaction.getEntry(); + Assert.assertEquals(2L, voucherAEntries.size()); + for (Entry entry : voucherAEntries) { + Assert.assertTrue(entry.getVoucher().contentEquals("voucherA")); + } + } else if (financialTransaction.getAmountDebit().compareTo(BigDecimal.valueOf(12.0)) == 0) { + Collection<Entry> voucherBEntries = financialTransaction.getEntry(); + Assert.assertEquals(3L, voucherBEntries.size()); + for (Entry entry : voucherBEntries) { + Assert.assertTrue(entry.getVoucher().contentEquals("voucherB")); + } + } else { + Assert.fail("Fail to import financial transactions"); + } } } diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java b/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java index 1d13f18..2d47e5e 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java @@ -77,8 +77,10 @@ import java.nio.charset.Charset; import java.rmi.server.ExportException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -343,51 +345,56 @@ public class ImportExport { protected StringBuilder displayErrorMessage(Map<Integer, LimaException> exceptionsByLine) { StringBuilder result = new StringBuilder(); if (exceptionsByLine != null) { - for (Map.Entry<Integer, LimaException> e:exceptionsByLine.entrySet()) { - result.append(t("lima.import.line", e.getKey()) + "\n"); - LimaException importException = e.getValue(); - if (importException instanceof InvalidAccountNumberException) { - result.append(t("lima.account.error.invalidAccountNumber", ((InvalidAccountNumberException) importException).getAccountNumber()) + "\n"); - } else if (importException instanceof NotNumberAccountNumberException) { - result.append(t("lima.account.error.notNumberAccountNumber", ((NotNumberAccountNumberException) importException).getAccountNumber()) + "\n"); - } else if (importException instanceof NotAllowedLabelException) { - result.append(t("lima.error.notAllowedLabel", ((NotAllowedLabelException) importException).getLabel()) + "\n"); - } else if (importException instanceof MoreOneUnlockFiscalPeriodException) { - result.append(t("lima.fiscalPeriod.error.moreOneUnlockFiscalPeriod", ((MoreOneUnlockFiscalPeriodException) importException).getBeginDate(), ((MoreOneUnlockFiscalPeriodException) importException).getEndDate()) + "\n"); - } else if (importException instanceof BeginAfterEndFiscalPeriodException) { - result.append(t("lima.fiscalPeriod.error.beginAfterEndFiscalPeriod", ((BeginAfterEndFiscalPeriodException) importException).getFiscalPeriod().getBeginDate(), ((BeginAfterEndFiscalPeriodException) importException).getFiscalPeriod().getEndDate()) + "\n"); - } else if (importException instanceof NotBeginNextDayOfLastFiscalPeriodException) { - result.append(t("lima.fiscalPeriod.error.notBeginNextDayOfLastFiscalPeriod", ((NotBeginNextDayOfLastFiscalPeriodException) importException).getFiscalPeriod().getBeginDate(), ((NotBeginNextDayOfLastFiscalPeriodException) importException).getFiscalPeriod().getEndDate()) + "\n"); - } else if (importException instanceof LockedFinancialPeriodException) { - result.append(t("lima.fiscalPeriod.error.lockedFinancialPeriod") + "\n"); - } else if (importException instanceof LockedEntryBookException) { - result.append(t("lima.entryBook.error.lockedEntryBook", ((LockedEntryBookException) importException).getClosedPeriodicEntryBook().getFinancialPeriod().getBeginDate(), ((LockedEntryBookException) importException).getClosedPeriodicEntryBook().getFinancialPeriod().getEndDate()) + "\n"); - } else if (importException instanceof AlreadyExistFinancialStatement) { - result.append(t("lima.financialStatement.error.alreadyExistFinancialStatement", ((AlreadyExistFinancialStatement) importException).getFinancialStatementLabel()) + "\n"); - } else if (importException instanceof AlreadyExistVatStatementException) { - result.append(t("lima.vatStatement.error.alreadyExistVatStatement", ((AlreadyExistVatStatementException) importException).getVatStatementLabel()) + "\n"); - } else if (importException instanceof NoFiscalPeriodFoundException) { - result.append(t("lima.error.noFiscalPeriodFound") + "\n"); - } else if (importException instanceof NoDataToImportException) { - errorHelper.showErrorMessage(t("lima.import.error.noDataToImport")); - log.warn(t("lima.import.error.noDataToImport")); - result = null; - break; - } else if (importException instanceof ImportFileException){ - errorHelper.showErrorMessage(((ImportFileException) importException).getDetailMessage()); - log.warn(((ImportFileException) importException).getDetailMessage()); - result = null; - break; - } else { - result.append(t("lima.import.error.unknown") + "\n"); - } - try { - throw importException; - } catch (LimaException ex) { - log.error(ex); + Set<Map.Entry<Integer, LimaException>> errors = exceptionsByLine.entrySet(); + int nbMessageToDisplay = errors.size() <= 40 ? errors.size(): 40; + int nbNotDisplayedMessage = errors.size() > 40 ? errors.size() - 40 : 0; + Iterator<Map.Entry<Integer, LimaException>> itError = errors.iterator(); + for (int i = 0; i < nbMessageToDisplay; i++) { + if (itError.hasNext()) { + Map.Entry<Integer, LimaException> messages = itError.next(); + result.append(t("lima.import.line", messages.getKey()) + "\n"); + LimaException importException = messages.getValue(); + if (importException instanceof InvalidAccountNumberException) { + result.append(t("lima.account.error.invalidAccountNumber", ((InvalidAccountNumberException) importException).getAccountNumber()) + "\n"); + } else if (importException instanceof NotNumberAccountNumberException) { + result.append(t("lima.account.error.notNumberAccountNumber", ((NotNumberAccountNumberException) importException).getAccountNumber()) + "\n"); + } else if (importException instanceof NotAllowedLabelException) { + result.append(t("lima.error.notAllowedLabel", ((NotAllowedLabelException) importException).getLabel()) + "\n"); + } else if (importException instanceof MoreOneUnlockFiscalPeriodException) { + result.append(t("lima.fiscalPeriod.error.moreOneUnlockFiscalPeriod", ((MoreOneUnlockFiscalPeriodException) importException).getBeginDate(), ((MoreOneUnlockFiscalPeriodException) importException).getEndDate()) + "\n"); + } else if (importException instanceof BeginAfterEndFiscalPeriodException) { + result.append(t("lima.fiscalPeriod.error.beginAfterEndFiscalPeriod", ((BeginAfterEndFiscalPeriodException) importException).getFiscalPeriod().getBeginDate(), ((BeginAfterEndFiscalPeriodException) importException).getFiscalPeriod().getEndDate()) + "\n"); + } else if (importException instanceof NotBeginNextDayOfLastFiscalPeriodException) { + result.append(t("lima.fiscalPeriod.error.notBeginNextDayOfLastFiscalPeriod", ((NotBeginNextDayOfLastFiscalPeriodException) importException).getFiscalPeriod().getBeginDate(), ((NotBeginNextDayOfLastFiscalPeriodException) importException).getFiscalPeriod().getEndDate()) + "\n"); + } else if (importException instanceof LockedFinancialPeriodException) { + result.append(t("lima.fiscalPeriod.error.lockedFinancialPeriod") + "\n"); + } else if (importException instanceof LockedEntryBookException) { + result.append(t("lima.entryBook.error.lockedEntryBook", ((LockedEntryBookException) importException).getClosedPeriodicEntryBook().getFinancialPeriod().getBeginDate(), ((LockedEntryBookException) importException).getClosedPeriodicEntryBook().getFinancialPeriod().getEndDate()) + "\n"); + } else if (importException instanceof AlreadyExistFinancialStatement) { + result.append(t("lima.financialStatement.error.alreadyExistFinancialStatement", ((AlreadyExistFinancialStatement) importException).getFinancialStatementLabel()) + "\n"); + } else if (importException instanceof AlreadyExistVatStatementException) { + result.append(t("lima.vatStatement.error.alreadyExistVatStatement", ((AlreadyExistVatStatementException) importException).getVatStatementLabel()) + "\n"); + } else if (importException instanceof NoFiscalPeriodFoundException) { + result.append(t("lima.error.noFiscalPeriodFound") + "\n"); + } else if (importException instanceof NoDataToImportException) { + errorHelper.showErrorMessage(t("lima.import.error.noDataToImport")); + break; + } else if (importException instanceof ImportFileException){ + result.append(((ImportFileException) importException).getDetailMessage()); + } else { + result.append(t("lima.import.error.unknown") + "\n"); + } + try { + throw importException; + } catch (LimaException ex) { + log.error(ex); + } } - } + if (nbNotDisplayedMessage > 0) { + result.append(String.format(t("lima.import.error.andMoreErrors"), nbNotDisplayedMessage)); + } + } return result; } diff --git a/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties b/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties index 0142911..dab46e2 100644 --- a/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties +++ b/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties @@ -366,7 +366,10 @@ lima.identity.phoneNumber=Phone number lima.identity.vatNumber=VAT number lima.identity.zipCode=Zip code lima.import.error= +lima.import.error.andMoreErrors=And %d more errors +lima.import.error.entriesOutOfDatesRange=Open fiscal period lima.import.error.extractFile= +lima.import.error.invalidAccountNumber=None existing account with number '%' lima.import.error.noDataToImport= lima.import.error.unknown= lima.import.line= diff --git a/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties b/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties index 7480da3..36dee45 100644 --- a/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties +++ b/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties @@ -379,7 +379,10 @@ lima.identity.phoneNumber=n° Tel lima.identity.vatNumber=n° TVA lima.identity.zipCode=Code Postal lima.import.error=Une erreur est survenue lors de l'import +lima.import.error.andMoreErrors=Et %d autres erreurs... +lima.import.error.entriesOutOfDatesRange=Periode fiscale non authorisé lima.import.error.extractFile=Le fichier n'est correct +lima.import.error.invalidAccountNumber=Le compte '%s' n'existe pas. lima.import.error.noDataToImport=Aucune donnée à importer. lima.import.error.unknown=Erreur inconnue. lima.import.line=Ligne %d\: -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm