This is an automated email from the git hooks/post-receive script. New commit to branch feature/1369-demarage-initial in repository lima. See https://gitlab.nuiton.org/chorem/lima.git commit 328cd94b08837a89fdbe295a80d25c4785efcff2 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) --- .../org/chorem/lima/business/ImportResult.java | 5 +- .../accountingrules/DefaultAccountingRules.java | 6 +- .../lima/business/ejb/AccountServiceImpl.java | 4 + .../lima/business/ejb/ImportServiceImpl.java | 93 ++++++++++++----- .../resources/i18n/lima-business_en_GB.properties | 34 ++++--- .../resources/i18n/lima-business_fr_FR.properties | 51 +++++++--- .../org/chorem/lima/business/AbstractLimaTest.java | 110 ++++++++++++++++++--- .../lima/business/AccountServiceImplTest.java | 8 +- .../lima/business/EntryBookServiceImplTest.java | 6 +- .../business/FinancialPeriodServiceImplTest.java | 6 +- .../FinancialTransactionServiceImplTest.java | 6 +- .../lima/business/FiscalPeriodServiceImplTest.java | 4 +- .../lima/business/ImportExportServiceTest.java | 88 +++++++++-------- .../lima/business/ReportServiceImplTest.java | 8 +- .../lima/entity/FinancialTransactionDAOTest.java | 8 +- .../resources/i18n/lima-swing_en_GB.properties | 3 + .../resources/i18n/lima-swing_fr_FR.properties | 3 + 17 files changed, 305 insertions(+), 138 deletions(-) diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java b/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java index 8cec320..4d0a7b3 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java @@ -22,10 +22,10 @@ package org.chorem.lima.business; * #L% */ +import com.google.common.collect.Maps; import org.chorem.lima.business.exceptions.LimaException; import java.io.Serializable; -import java.util.HashMap; import java.util.Map; /** @@ -50,6 +50,7 @@ public class ImportResult implements Serializable{ nbUpdated = 0; nbIgnored = 0; lineIndex = 2;// line 1 s header + allExceptions = Maps.newHashMap(); this.fromSource = fromSource; } @@ -81,14 +82,12 @@ public class ImportResult implements Serializable{ } public void addException(LimaException e) { - allExceptions = allExceptions == null ? new HashMap<Integer, LimaException>() : allExceptions; allExceptions.put(this.lineIndex, e); nbIgnored++; lineIndex++; } public void addInitException(LimaException e) { - allExceptions = allExceptions == null ? new HashMap<Integer, LimaException>() : allExceptions; allExceptions.put(1, e); nbIgnored++; lineIndex++; diff --git a/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java b/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java index 410bf2b..9c2fafb 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java +++ b/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java @@ -41,7 +41,6 @@ import org.chorem.lima.business.exceptions.NotLockedClosedPeriodicEntryBooksExce import org.chorem.lima.business.exceptions.NotNumberAccountNumberException; import org.chorem.lima.business.exceptions.UnbalancedEntriesException; import org.chorem.lima.business.exceptions.UnbalancedFinancialTransactionsException; -import org.chorem.lima.business.exceptions.UnexistingAccount; import org.chorem.lima.business.exceptions.UnfilledEntriesException; import org.chorem.lima.business.exceptions.UsedAccountException; import org.chorem.lima.business.exceptions.UsedEntryBookException; @@ -176,13 +175,10 @@ public class DefaultAccountingRules implements AccountingRules { * Recursive function */ @Override - public void removeAccountRules(Account account) throws UsedAccountException, UnexistingAccount { + public void removeAccountRules(Account account) throws UsedAccountException { EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); // Check if account have entries - if (!account.isPersisted()) { - throw new UnexistingAccount(account.getAccountNumber(), "Unsaved Account, this account can not be removed"); - } if (entryTopiaDao.forAccountEquals(account).exists()) { throw new UsedAccountException(account.getAccountNumber()); } diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java index 63add0f..7a7cfdd 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java @@ -193,6 +193,10 @@ public class AccountServiceImpl extends AbstractLimaService implements AccountSe @Override public void removeAccount(Account account) throws UsedAccountException, UnexistingAccount { + if (!account.isPersisted()) { + throw new UnexistingAccount(account.getAccountNumber(), "Unsaved Account, this account can not be removed"); + } + AccountingRules accountingRules = LimaBusinessConfig.getInstance().getAccountingRules(); // Check rules for account if have entries 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 173f4e3..11feab7 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,6 +23,7 @@ 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; @@ -60,7 +61,6 @@ import org.chorem.lima.business.exceptions.AlreadyExistFinancialStatementExcepti import org.chorem.lima.business.exceptions.AlreadyExistVatStatementException; import org.chorem.lima.business.exceptions.BeforeFirstFiscalPeriodException; 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.LimaException; @@ -939,12 +939,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; @@ -984,9 +986,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(); @@ -994,7 +996,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 @@ -1005,7 +1007,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 | AfterLastFiscalPeriodException | BeforeFirstFiscalPeriodException e) { result.addException(e); @@ -1049,34 +1051,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, AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException { + protected void addEntryToFinancialTransaction(Entry entry, String entryBookCode, Map<String, EntryBook> indexedEntryBooks, Map<EntryBook, Map<Date, Set<FinancialTransaction>>> entryBookFinancialTransactionsByDate, Date dateEcr) throws LockedFinancialPeriodException, LockedEntryBookException, AlreadyExistEntryBookException, AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException { 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); } - // create transaction - FinancialTransaction financialTransaction = financialTransactionsByDate.get(dateEcr); - if (financialTransaction == null - || !(dateEcr.equals(financialTransaction - .getTransactionDate()) && entryBook + // 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); + } + + 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 @@ -1094,19 +1130,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 89e4c1a..62a13bd 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 @@ -134,24 +134,32 @@ lima.config.scale.label= lima.config.serveraddress.description=Server Address lima.config.thousandSeparator.description= lima.config.thousandSeparator.label= -lima.configFileName.description=Descriontion -lima.financialtransaction.account=Account -lima.fiscalperiod.fiscalperiod=Fiscal period +lima.configFileName.description= +lima.financialtransaction.account= +lima.fiscalperiod.fiscalperiod= lima.host.address.description= lima.host.ejb.port.description= lima.host.http.address.description= lima.host.http.port.description= -lima.importexport.import.alreadyExistFinancialStatement=Same financial statement exists -lima.lettering.accountRegularization=Regulatory account +lima.import.error.entriesOutOfDatesRange= +lima.import.error.invalidAccountNumber= +lima.importexport.import.alreadyExistFinancialStatement= +lima.lettering.accountRegularization= lima.report.fromDateToDate= lima.reports.account.noAccount=Any account present lima.reports.account.noAccountTitle=Any account present -lima.reports.accounts=Accounts -lima.table.credit=Credit -lima.table.date=Date -lima.table.debit=Debit -lima.table.description=Description +lima.reports.account.noaccount= +lima.reports.account.noaccounttitle= +lima.reports.accounts= +lima.services.application.version= +lima.table.credit= +lima.table.date= +lima.table.debit= +lima.table.decription= +lima.table.description= lima.table.entryBook=Entry book -lima.table.letter=Letter -lima.table.number=Account number -lima.table.voucher=Voucher +lima.table.entrybook= +lima.table.letter= +lima.table.number= +lima.table.voucher= +llima.importexport.import.alreadyExistFinancialStatement= 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 17c85be..6496672 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 @@ -100,6 +100,24 @@ lima-business.import.ebpmissingaccount=Échec \: Compte %s inexistant. \nCréer lima-business.import.entries.error.lockedEntryBook= lima-business.import.entries.error.lockedFinancialPeriod= lima-business.import.entriesoutofdatesrange=Attention \: Cette entrée %s ne fait partie d'aucune période ouverte. Entrée non importée. +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 +lima-business.import.entrybooknotexist=Attention \: Le journal %s inexistant a été créé \!\n +lima-business.import.financialstatementadded=Succès \: Mouvement %s ajoutée \n +lima-business.import.financialstatementalnomaster=u00C9chec \: Le mouvement %s possède le master \: %s inexistant \n +lima-business.import.financialstatementalreadyexist=u00C9chec \: Le mouvement %s exist déjà \!\n +lima-business.import.fiscalperiodadded=Succès \: Exercice %s - %s ajoutée \! \n +lima-business.import.fiscalperiodalreadyexist=u00C9chec \: L'exerice %s - %s existe déjà \!\n +lima-business.import.fiscalperiodscloseperiodicentrybooks= +lima-business.import.identityadded=Succès \: Identité %s ajoutée \! \n +lima-business.import.lineformatmismatch=Le format de la ligne est incorrect. +lima-business.import.noaccount=Erreur \: Ce fichier ne contient aucun compte. +lima-business.import.nofiscalperiodopen=u00C9chec \: Aucun exercice ouvert \! \n +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.currency.description= lima.config.currency.label= @@ -138,21 +156,30 @@ lima.config.scale.label= lima.config.thousandSeparator.description= lima.config.thousandSeparator.label= lima.configFileName.description= -lima.financialtransaction.account=compte -lima.fiscalperiod.fiscalperiod=Période fiscale +lima.financialtransaction.account= +lima.fiscalperiod.fiscalperiod= lima.host.address.description=Addresse serveur lima.host.ejb.port.description=Port pour connexion du client au serveur lima.host.http.address.description= lima.host.http.port.description=Port du serveur web de Lima -lima.importexport.import.alreadyExistFinancialStatement=Transaction financière exitante -lima.lettering.accountRegularization=Compte de régulation +lima.import.error.entriesOutOfDatesRange= +lima.import.error.invalidAccountNumber= +lima.importexport.import.alreadyExistFinancialStatement= +lima.lettering.accountRegularization= lima.reports.account.noAccount=Aucun compte présent -lima.reports.accounts=Comptes -lima.table.credit=Credit -lima.table.date=Date -lima.table.debit=Débit -lima.table.description=Description +lima.reports.account.noaccount= +lima.reports.account.noaccounttitle= +lima.reports.accounts= +lima.services.application.version= +lima.table.credit= +lima.table.date= +lima.table.debit= +lima.table.decription= +lima.table.description= lima.table.entryBook=Journal -lima.table.letter=Lettre -lima.table.number=Numéro de compte -lima.table.voucher=Pièce comptable +lima.table.entrybook= +lima.table.letter= +lima.table.number= +lima.table.voucher= +lima.ui.importexport.import.exceptions.reason=Reason\:% +llima.importexport.import.alreadyExistFinancialStatement= 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 bbfeb59..118646d 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 @@ -38,10 +38,6 @@ import org.chorem.lima.business.api.IdentityService; import org.chorem.lima.business.api.ImportService; import org.chorem.lima.business.api.ReportService; import org.chorem.lima.business.api.VatStatementService; -import org.chorem.lima.business.exceptions.AlreadyExistAccountException; -import org.chorem.lima.business.exceptions.InvalidAccountNumberException; -import org.chorem.lima.business.exceptions.NotAllowedLabelException; -import org.chorem.lima.business.exceptions.NotNumberAccountNumberException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountImpl; import org.chorem.lima.entity.Entry; @@ -205,7 +201,7 @@ public abstract class AbstractLimaTest { * @throws org.chorem.lima.business.exceptions.InvalidAccountNumberException * @throws org.chorem.lima.business.exceptions.NotNumberAccountNumberException */ - protected void createAccounts() throws AlreadyExistAccountException, NotAllowedLabelException, InvalidAccountNumberException, NotNumberAccountNumberException { + protected void initTestWithAccounts() throws Exception { // creation d'un plan compatble de test Account classFinancier = new AccountImpl(); @@ -250,7 +246,7 @@ public abstract class AbstractLimaTest { * @throws org.chorem.lima.business.exceptions.LimaException * @throws java.text.ParseException */ - protected void createEntryBooks() throws Exception { + protected void initTestWithEntryBooks() throws Exception { // creation d'un journal EntryBook journalDesVentes = new EntryBookImpl(); journalDesVentes.setLabel("Journal des ventes"); @@ -275,8 +271,7 @@ public abstract class AbstractLimaTest { * @throws org.chorem.lima.business.exceptions.LimaException * @throws java.text.ParseException */ - protected void createFiscalPeriod() throws Exception { - + protected void initTestWithFiscalPeriod() throws Exception { // creation d'un exercice fiscal FiscalPeriod fiscalPeriod = new FiscalPeriodImpl(); fiscalPeriod.setBeginDate(df.parse("January 1, 2012")); @@ -288,15 +283,100 @@ public abstract class AbstractLimaTest { * Create FinancialTransaction with 2 entries * @throws Exception */ - protected void createFinancialTransaction() throws Exception { + protected void initTestWithFinancialTransaction() throws Exception { + + 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("voucher"); + 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("voucher"); + tr1Entry2 = financialTransactionService.createEntry(tr1Entry2); + + transaction1.setEntry(Lists.newArrayList(tr1Entry1, tr1Entry2)); + financialTransactionService.updateFinancialTransaction(transaction1); + } - createFinancialTransaction("jdv", df.parse("April 4, 2012"), "511", "501", BigDecimal.valueOf(42.0)); + + protected void initTestWithSomeFinancialTransaction() throws Exception { + + 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); } - /** - * Create FinancialTransaction with 2 entries - * @throws Exception - */ protected FinancialTransaction createFinancialTransaction(String entryBookCode, Date date, String accountDebitNumber, String accountCreditNumber, BigDecimal amount) throws Exception { @@ -333,4 +413,4 @@ public abstract class AbstractLimaTest { return transaction; } -} +} \ No newline at end of file diff --git a/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java b/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java index 26df6ff..cb02753 100644 --- a/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java +++ b/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java @@ -52,7 +52,7 @@ public class AccountServiceImplTest extends AbstractLimaTest { @Before public void initTest() throws Exception { - createAccounts(); + initTestWithAccounts(); } @Test @@ -362,9 +362,9 @@ public class AccountServiceImplTest extends AbstractLimaTest { */ @Test(expected = UsedAccountException.class) public void removeUsedAccountTest() throws Exception { - createEntryBooks(); - createFiscalPeriod(); - createFinancialTransaction(); + initTestWithEntryBooks(); + initTestWithFiscalPeriod(); + initTestWithFinancialTransaction(); Account account = accountService.getAccountByNumber("511"); accountService.removeAccount(account); } diff --git a/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java b/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java index 8455e99..56b768f 100644 --- a/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java +++ b/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java @@ -48,7 +48,7 @@ public class EntryBookServiceImplTest extends AbstractLimaTest { @Before public void initTest() throws Exception { - createEntryBooks(); + initTestWithEntryBooks(); } @Test @@ -175,8 +175,8 @@ public class EntryBookServiceImplTest extends AbstractLimaTest { */ @Test(expected=UsedEntryBookException.class) public void deleteUsedEntryBook() throws Exception { - createFiscalPeriod(); - createFinancialTransaction(); + initTestWithFiscalPeriod(); + initTestWithFinancialTransaction(); EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); entryBookService.removeEntryBook(entryBook); diff --git a/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java b/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java index 5da0a81..8dbc49c 100644 --- a/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java +++ b/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java @@ -58,9 +58,9 @@ public class FinancialPeriodServiceImplTest extends AbstractLimaTest { @Before public void initTest() throws Exception { - createAccounts(); - createEntryBooks(); - createFiscalPeriod(); + initTestWithAccounts(); + initTestWithEntryBooks(); + initTestWithFiscalPeriod(); } @Test diff --git a/lima-business/src/test/java/org/chorem/lima/business/FinancialTransactionServiceImplTest.java b/lima-business/src/test/java/org/chorem/lima/business/FinancialTransactionServiceImplTest.java index 0ebf319..e4a9e16 100644 --- a/lima-business/src/test/java/org/chorem/lima/business/FinancialTransactionServiceImplTest.java +++ b/lima-business/src/test/java/org/chorem/lima/business/FinancialTransactionServiceImplTest.java @@ -63,9 +63,9 @@ public class FinancialTransactionServiceImplTest extends AbstractLimaTest { @Before public void initTest() throws Exception { - createAccounts(); - createEntryBooks(); - createFiscalPeriod(); + initTestWithAccounts(); + initTestWithEntryBooks(); + initTestWithFiscalPeriod(); } @Test diff --git a/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java b/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java index 08168f9..8f5f9ed 100644 --- a/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java +++ b/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java @@ -72,8 +72,8 @@ public class FiscalPeriodServiceImplTest extends AbstractLimaTest { @Before public void initTest() throws Exception { - createAccounts(); - createEntryBooks(); + initTestWithAccounts(); + initTestWithEntryBooks(); } @Test 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 4e147a7..dbaf7d5 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; @@ -72,9 +73,9 @@ public class ImportExportServiceTest extends AbstractLimaTest { @Test public void testExportImportAccounts() throws Exception { - createAccounts(); - createEntryBooks(); - createFiscalPeriod(); + initTestWithAccounts(); + initTestWithEntryBooks(); + initTestWithFiscalPeriod(); // make sure they are some accounts. List<Account> accounts = accountService.getAllAccounts(); Assert.assertTrue(accountService.getAllAccounts().size() > 0); @@ -105,7 +106,7 @@ public class ImportExportServiceTest extends AbstractLimaTest { // make sure all account have been created Assert.assertEquals(nbEntities, accountService.getAllAccounts().size()); Assert.assertEquals(nbEntities, result.getImportResults().get(0).getNbCreated()); - Assert.assertNull(result.getImportResults().get(0).getAllExceptionsByLine()); + Assert.assertTrue(result.getImportResults().get(0).getAllExceptionsByLine().isEmpty()); } finally { IOUtils.closeQuietly(contentStream); } @@ -117,7 +118,7 @@ public class ImportExportServiceTest extends AbstractLimaTest { ImportExportResults result = importService.importAccountAsCSV(inportStream); Assert.assertNotNull(result); Map<Integer, LimaException> exceptionMap = result.getImportResults().get(0).getAllExceptionsByLine(); - Assert.assertNotNull(exceptionMap); + Assert.assertTrue(!exceptionMap.isEmpty()); Collection<LimaException> exceptions = exceptionMap.values(); Assert.assertEquals(1, exceptions.size()); ImportFileException exception = (ImportFileException) exceptions.iterator().next(); @@ -126,8 +127,8 @@ public class ImportExportServiceTest extends AbstractLimaTest { @Test public void testExportImportEntryBooks() throws Exception { - createAccounts(); - createEntryBooks(); + initTestWithAccounts(); + initTestWithEntryBooks(); String tmpDir = System.getProperty("java.io.tmpdir")+"/"; ImportExportResults export = exportService.exportEntryBooksAsCSV(Charset.defaultCharset().name()); @@ -157,15 +158,15 @@ public class ImportExportServiceTest extends AbstractLimaTest { Assert.assertEquals(nbEntities, entryBookService.getAllEntryBooks().size()); Assert.assertEquals(nbEntities, result.getNbCreated()); - Assert.assertNull(result.getAllExceptionsByLine()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); } @Test public void testExportImportEntries() throws Exception { - createAccounts(); - createEntryBooks(); - createFiscalPeriod(); - createFinancialTransaction(); + initTestWithAccounts(); + initTestWithEntryBooks(); + initTestWithFiscalPeriod(); + initTestWithFinancialTransaction(); List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012")); List<Entry> entries = Lists.newArrayList(); @@ -214,14 +215,14 @@ public class ImportExportServiceTest extends AbstractLimaTest { Assert.assertEquals(nbEntities, entries.size()); Assert.assertEquals(nbEntities, result.getNbCreated()); - Assert.assertNull(result.getAllExceptionsByLine()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); } @Test public void testExportImportFiscalPeriodsAsCSV() throws Exception { - createAccounts(); - createEntryBooks(); - createFiscalPeriod(); + initTestWithAccounts(); + initTestWithEntryBooks(); + initTestWithFiscalPeriod(); String tmpDir = System.getProperty("java.io.tmpdir")+"/"; String export = exportService.exportFiscalPeriodsAsCSV(Charset.defaultCharset().name()).getExportResults().get(0).getExportData(); @@ -249,15 +250,15 @@ public class ImportExportServiceTest extends AbstractLimaTest { Assert.assertEquals(nbFiscalPeriods, fiscalPeriodService.getAllFiscalPeriods().size()); Assert.assertEquals(nbFiscalPeriods, result.getNbCreated()); - Assert.assertNull(result.getAllExceptionsByLine()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); } @Test public void exportImportAllAsCSVTest() throws Exception { - createAccounts(); - createEntryBooks(); - createFiscalPeriod(); - createFinancialTransaction(); + initTestWithAccounts(); + initTestWithEntryBooks(); + initTestWithFiscalPeriod(); + initTestWithFinancialTransaction(); Identity identity = new IdentityImpl(); identity.setName("Code Lutin"); @@ -284,7 +285,7 @@ public class ImportExportServiceTest extends AbstractLimaTest { ImportResult importResult = importResults.get(i); log.info(imported[i] +": created:"+importResult.getNbCreated() + " updated:" + importResult.getNbUpdated() + " ignoded:" + importResult.getNbIgnored()); Assert.assertTrue(importResult.getNbCreated()>0); - Assert.assertNull(importResult.getAllExceptionsByLine()); + Assert.assertTrue(importResult.getAllExceptionsByLine().isEmpty()); } } @@ -444,7 +445,7 @@ public class ImportExportServiceTest extends AbstractLimaTest { result = importService.importFinancialStatementsAsCSV(bcr_developed).getImportResults().get(0); - Assert.assertNull(result.getAllExceptionsByLine()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); Assert.assertEquals(162, result.getNbCreated()); Assert.assertEquals(162, financialStatementService.getAllFinancialStatements().size()); FinancialStatement actifImmobiliseStatement = financialStatementService.getFinancialStatementByLabel("ACTIF IMMOBILISÉ"); @@ -465,7 +466,7 @@ public class ImportExportServiceTest extends AbstractLimaTest { result = importService.importVATStatementsAsCSV(bcr_developed).getImportResults().get(0); - Assert.assertNull(result.getAllExceptionsByLine()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); Assert.assertEquals(55, result.getNbCreated()); Assert.assertEquals(55, vatStatementService.getAllVatStatements().size()); } @@ -506,7 +507,7 @@ public class ImportExportServiceTest extends AbstractLimaTest { InputStream entriesStream = ImportExportServiceTest.class.getResourceAsStream("/ebp/ecritures.txt"); String entriesData = IOUtils.toString(entriesStream, "ISO-8859-1"); ImportResult result = importService.importEntriesFromEbp(entriesData).getImportResults().get(0); - Assert.assertNull(result.getAllExceptionsByLine()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); Assert.assertEquals(28, result.getNbCreated()); entriesStream.close(); @@ -552,10 +553,10 @@ public class ImportExportServiceTest extends AbstractLimaTest { @Test public void testExportImportEntriesEbp() throws Exception { - createAccounts(); - createEntryBooks(); - createFiscalPeriod(); - createFinancialTransaction(); + initTestWithAccounts(); + initTestWithEntryBooks(); + initTestWithFiscalPeriod(); + initTestWithSomeFinancialTransaction(); List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012")); List<Entry> entries = Lists.newArrayList(); @@ -564,7 +565,6 @@ public class ImportExportServiceTest extends AbstractLimaTest { entries.addAll(financialTransaction.getEntry()); } Assert.assertTrue(!entries.isEmpty()); - int nbEntities = entries.size(); //test export String tmpDir = System.getProperty("java.io.tmpdir")+"/"; @@ -590,27 +590,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-business/src/test/java/org/chorem/lima/business/ReportServiceImplTest.java b/lima-business/src/test/java/org/chorem/lima/business/ReportServiceImplTest.java index 6851851..a3e05e0 100644 --- a/lima-business/src/test/java/org/chorem/lima/business/ReportServiceImplTest.java +++ b/lima-business/src/test/java/org/chorem/lima/business/ReportServiceImplTest.java @@ -48,10 +48,10 @@ public class ReportServiceImplTest extends AbstractLimaTest { @Before public void initTest() throws Exception { - createAccounts(); - createEntryBooks(); - createFiscalPeriod(); - createFinancialTransaction(); + initTestWithAccounts(); + initTestWithEntryBooks(); + initTestWithFiscalPeriod(); + initTestWithFinancialTransaction(); } /** diff --git a/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java b/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java index 1ea0b63..a5dba3f 100644 --- a/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java +++ b/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java @@ -54,10 +54,10 @@ public class FinancialTransactionDAOTest extends AbstractLimaTest { @Test public void testFindAllUnbalancedTransactions() throws Exception { - createAccounts(); - createEntryBooks(); - createFiscalPeriod(); - createFinancialTransaction(); + initTestWithAccounts(); + initTestWithEntryBooks(); + initTestWithFiscalPeriod(); + initTestWithFinancialTransaction(); FinancialPeriod financialPeriod = financialPeriodService.getAllFinancialPeriods().get(0); EntryBook journalDesVentes = entryBookService.getEntryBookByCode("jdv"); 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 9022472..363fe27 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 @@ -428,7 +428,10 @@ lima.identity.phoneNumber=Phone number lima.identity.vatNumber=VAT number lima.identity.zipCode=Zip code lima.import.error=Import Failed +lima.import.error.andMoreErrors=And %d more errors +lima.import.error.entriesOutOfDatesRange=Open fiscal period lima.import.error.extractFile=Invalid file +lima.import.error.invalidAccountNumber=None existing account with number '%' lima.import.error.noDataToImport=Any data to import lima.import.error.unknown=Unknown error lima.import.line=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 541d2e3..5d8f7dd 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 @@ -439,7 +439,10 @@ lima.identity.phoneNumber=n° Tel lima.identity.vatNumber=Numéro TVA\: FR 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>.