This is an automated email from the git hooks/post-receive script. New commit to branch feature/1233 in repository lima. See http://git.chorem.org/lima.git commit d54b68d4cb2b0c027a332f13b098a2237c05d2c8 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Jun 3 09:44:03 2015 +0200 refs #1233 : test du service des transaction + correction et amélioration du code --- .../business/api/FinancialTransactionService.java | 6 +- .../org/chorem/lima/business/AccountingRules.java | 30 +- .../accountingrules/DefaultAccountingRules.java | 143 ++--- .../ejb/FinancialTransactionServiceImpl.java | 19 +- .../lima/business/ejb/FiscalPeriodServiceImpl.java | 4 +- .../lima/business/ejb/ImportServiceImpl.java | 8 +- .../FinancialTransactionServiceImplTest.java | 631 +++++++++++++++++++++ .../ui/common/FinancialTransactionTableModel.java | 6 +- .../FinancialTransactionViewHandler.java | 17 + .../resources/i18n/lima-swing_en_GB.properties | 3 + .../resources/i18n/lima-swing_fr_FR.properties | 4 +- 11 files changed, 743 insertions(+), 128 deletions(-) diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java b/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java index c53130b..d268005 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java @@ -63,10 +63,10 @@ public interface FinancialTransactionService { Entry createNewEntry(); FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction) - throws LockedFinancialPeriodException, LockedEntryBookException; + throws AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException, LockedFinancialPeriodException, LockedEntryBookException; FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction, Boolean validAccountingRules) - throws LockedFinancialPeriodException, LockedEntryBookException; + throws AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException, LockedFinancialPeriodException, LockedEntryBookException; void updateFinancialTransaction(FinancialTransaction financialtransaction) throws AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException, LockedFinancialPeriodException, LockedEntryBookException; @@ -92,7 +92,7 @@ public interface FinancialTransactionService { Entry createEntry(Entry entry) throws LockedFinancialPeriodException, LockedEntryBookException; - void updateEntry(Entry entry) throws LockedEntryBookException; + void updateEntry(Entry entry) throws LockedEntryBookException, LockedFinancialPeriodException; void removeEntry(Entry entry) throws LockedFinancialPeriodException, LockedEntryBookException; diff --git a/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java b/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java index c53001e..169c77b 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java +++ b/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java @@ -92,26 +92,24 @@ public interface AccountingRules { void deleteFiscalPeriodRules(FiscalPeriod fiscalPeriod) throws NoEmptyFiscalPeriodException; - /** - * Entry rules - * - * @param entry - * @throws org.chorem.lima.business.exceptions.LockedEntryBookException - */ - void updateEntryRules(Entry entry, Entry entryOld) throws LockedEntryBookException; - void updateFinancialTransactionDateRules(FinancialTransaction financialTransaction, FinancialTransaction financialTransactionOld) + void createFinancialTransactionRules(FinancialTransaction financialTransaction) + throws BeforeFirstFiscalPeriodException, AfterLastFiscalPeriodException, + LockedFinancialPeriodException, LockedEntryBookException; + + void updateFinancialTransactionRules(FinancialTransaction financialTransaction, FinancialTransaction financialTransactionOld) throws BeforeFirstFiscalPeriodException, AfterLastFiscalPeriodException, LockedFinancialPeriodException, LockedEntryBookException; - /** - * Financialperiod/entrybook rules - * - * @param financialTransaction - * @throws LockedFinancialPeriodException, LockedEntryBookException - */ - void checkFinancialPeriodBlockedWithFinancialTransaction(FinancialTransaction financialTransaction) throws LockedFinancialPeriodException, LockedEntryBookException; + void deleteFinancialTransactionRules(FinancialTransaction financialTransaction) + throws LockedFinancialPeriodException, LockedEntryBookException; - /** + void createEntryRules(Entry entry) throws LockedFinancialPeriodException, LockedEntryBookException; + + void updateEntryRules(Entry entry, Entry entryOld) throws LockedFinancialPeriodException, LockedEntryBookException; + + void deleteEntryRules(Entry entry) throws LockedFinancialPeriodException, LockedEntryBookException; + + /** * Check if a financial period can be closed. * * @param closedPeriodicEntryBook 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 1bc2c3e..7488063 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 @@ -161,30 +161,6 @@ public class DefaultAccountingRules implements AccountingRules { } /** - * check if financial period of a financial transaction is blocked - * check if entrybook of his financial period are locked - */ - @Override - public void checkFinancialPeriodBlockedWithFinancialTransaction(FinancialTransaction financialTransaction) throws LockedFinancialPeriodException, LockedEntryBookException { - - //check financial period locked - FinancialPeriodTopiaDao financialPeriodTopiaDao = getDaoHelper().getFinancialPeriodDao(); - FinancialPeriod financialPeriod = financialPeriodTopiaDao.findByDate(financialTransaction.getTransactionDate()); - if (financialPeriod.isLocked()) { - throw new LockedFinancialPeriodException(financialPeriod); - } - - ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao = getDaoHelper().getClosedPeriodicEntryBookDao(); - ClosedPeriodicEntryBook closedPeriodicEntryBook = closedPeriodicEntryBookTopiaDao.forProperties( - ClosedPeriodicEntryBook.PROPERTY_FINANCIAL_PERIOD, financialPeriod, - ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, financialTransaction.getEntryBook()).findUnique(); - - if (closedPeriodicEntryBook.isLocked()) { - throw new LockedEntryBookException(closedPeriodicEntryBook); - } - } - - /** * Check if all financial transactions of closedperiodicentrybook are equilibrate * Check if all financial transactions of this closedperiodicentrybook/financialPeriod are well filled in * Check if all financial transactions have EntryBooks @@ -260,54 +236,35 @@ public class DefaultAccountingRules implements AccountingRules { } - /** - * Rules on update entry : - * <p/> - * Two case : - * - second, the actual entry belong to a blocked closedPeriodicEntryBook - * - third, the new choice entrybook belong to a blocked closedPeriodicEntryBook - */ @Override - public void updateEntryRules(Entry entry, Entry entryOld) throws LockedEntryBookException { + public void createFinancialTransactionRules(FinancialTransaction financialTransaction) + throws BeforeFirstFiscalPeriodException, AfterLastFiscalPeriodException, + LockedFinancialPeriodException, LockedEntryBookException { + checkTransactionDate(financialTransaction); + checkTransactionBlock(financialTransaction); - FinancialPeriodTopiaDao financialPeriodTopiaDao = getDaoHelper().getFinancialPeriodDao(); - FinancialPeriod financialPeriod = financialPeriodTopiaDao.findByDate(entry.getFinancialTransaction().getTransactionDate()); + } - ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao = getDaoHelper().getClosedPeriodicEntryBookDao(); + @Override + public void updateFinancialTransactionRules(FinancialTransaction financialTransaction, + FinancialTransaction financialTransactionOld) + throws BeforeFirstFiscalPeriodException, AfterLastFiscalPeriodException, + LockedFinancialPeriodException, LockedEntryBookException { + checkTransactionBlock(financialTransactionOld); + checkTransactionDate(financialTransaction); + checkTransactionBlock(financialTransaction); - if (entryOld != null) { - //second case - ClosedPeriodicEntryBook closedPeriodicEntryBook = - closedPeriodicEntryBookTopiaDao.findByEntryBookAndFinancialPeriod( - entryOld.getFinancialTransaction().getEntryBook(), financialPeriod); - if (closedPeriodicEntryBook.isLocked()) { - throw new LockedEntryBookException(closedPeriodicEntryBook); - } - } + } - //third case - ClosedPeriodicEntryBook closedPeriodicEntryBook2 = - closedPeriodicEntryBookTopiaDao.findByEntryBookAndFinancialPeriod( - entry.getFinancialTransaction().getEntryBook(), financialPeriod); + @Override + public void deleteFinancialTransactionRules(FinancialTransaction financialTransaction) + throws LockedFinancialPeriodException, LockedEntryBookException { + checkTransactionBlock(financialTransaction); - // Check 2 & 3 cases - if (closedPeriodicEntryBook2.isLocked()) { - throw new LockedEntryBookException(closedPeriodicEntryBook2); - } } - - /** - * Check : - * 1. if date are on fiscal period - * 2. if old financialtransaction date are on periodblocked - * 3. if new financialtransaction date are on periodblocked - */ - @Override - public void updateFinancialTransactionDateRules( - FinancialTransaction financialTransaction, - FinancialTransaction financialTransactionOld) - throws BeforeFirstFiscalPeriodException, AfterLastFiscalPeriodException, LockedFinancialPeriodException, LockedEntryBookException { + protected void checkTransactionDate(FinancialTransaction financialTransaction) + throws BeforeFirstFiscalPeriodException, AfterLastFiscalPeriodException { Date financialTransactionDate = financialTransaction.getTransactionDate(); FiscalPeriodTopiaDao fiscalPeriodTopiaDao = getDaoHelper().getFiscalPeriodDao(); @@ -322,7 +279,7 @@ public class DefaultAccountingRules implements AccountingRules { log.debug("Date de transaction modifiée sur l'ui " + financialTransactionDate); log.debug("Date de début du premier exercice : " + beginDateFirstFiscalPeriod); log.debug("Date de fin du dernier exercice : " + endDateLastFiscalPeriod); - } + } //1-date not on a fiscal period if (financialTransactionDate.before(beginDateFirstFiscalPeriod)) { @@ -340,51 +297,53 @@ public class DefaultAccountingRules implements AccountingRules { throw new AfterLastFiscalPeriodException(endDateLastFiscalPeriod); } + } - //date on a fiscal period (and consequently on a financial), now test if financial is open - + protected void checkTransactionBlock(FinancialTransaction financialTransaction) throws LockedFinancialPeriodException, LockedEntryBookException { FinancialPeriodTopiaDao financialPeriodTopiaDao = getDaoHelper().getFinancialPeriodDao(); - FinancialPeriod financialPeriodOld = financialPeriodTopiaDao.findByDate(financialTransactionOld.getTransactionDate()); - - //2. check old financial period locked - if (financialPeriodOld.isLocked()) { - if (log.isDebugEnabled()) { - log.debug("Periode (Old) financière bloquée"); - } - throw new LockedFinancialPeriodException(financialPeriodOld); - } - - //3. check new financial period locked FinancialPeriod financialPeriod = financialPeriodTopiaDao.findByDate(financialTransaction.getTransactionDate()); + if (financialPeriod.isLocked()) { if (log.isDebugEnabled()) { - log.debug("Periode (New) financière bloquée"); + log.debug("Periode financière bloquée"); } throw new LockedFinancialPeriodException(financialPeriod); } ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao = getDaoHelper().getClosedPeriodicEntryBookDao(); - ClosedPeriodicEntryBook closedPeriodicEntryBookOld = closedPeriodicEntryBookTopiaDao.forProperties( - ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, financialTransactionOld.getEntryBook(), - ClosedPeriodicEntryBook.PROPERTY_FINANCIAL_PERIOD, financialPeriodOld).findUnique(); - if (closedPeriodicEntryBookOld.isLocked()) { - if (log.isDebugEnabled()) { - log.debug("Journal (old) bloquée"); - } - throw new LockedEntryBookException(closedPeriodicEntryBookOld); - } - ClosedPeriodicEntryBook closedPeriodicEntryBook = closedPeriodicEntryBookTopiaDao.forProperties( - ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, financialTransaction.getEntryBook(), - ClosedPeriodicEntryBook.PROPERTY_FINANCIAL_PERIOD, financialPeriod).findUnique(); + ClosedPeriodicEntryBook closedPeriodicEntryBook = + closedPeriodicEntryBookTopiaDao.findByEntryBookAndFinancialPeriod( + financialTransaction.getEntryBook(), financialPeriod); if (closedPeriodicEntryBook.isLocked()) { if (log.isDebugEnabled()) { - log.debug("Journal (new) bloquée"); + log.debug("Journal bloquée"); } throw new LockedEntryBookException(closedPeriodicEntryBook); } } + + + + @Override + public void createEntryRules(Entry entry) throws LockedFinancialPeriodException, LockedEntryBookException { + checkTransactionBlock(entry.getFinancialTransaction()); + + } + + @Override + public void updateEntryRules(Entry entry, Entry entryOld) throws LockedFinancialPeriodException, LockedEntryBookException { + checkTransactionBlock(entry.getFinancialTransaction()); + } + + @Override + public void deleteEntryRules(Entry entry) throws LockedFinancialPeriodException, LockedEntryBookException { + checkTransactionBlock(entry.getFinancialTransaction()); + } + + + } diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java index 52e241a..274781a 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java @@ -102,20 +102,20 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme @Override public FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction) - throws LockedFinancialPeriodException, LockedEntryBookException { + throws LockedFinancialPeriodException, LockedEntryBookException, BeforeFirstFiscalPeriodException, AfterLastFiscalPeriodException { FinancialTransaction financialTransaction = createFinancialTransaction(financialtransaction, true); return financialTransaction; } @Override public FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction, Boolean validAccountingRules) - throws LockedFinancialPeriodException, LockedEntryBookException { + throws LockedFinancialPeriodException, LockedEntryBookException, BeforeFirstFiscalPeriodException, AfterLastFiscalPeriodException { AccountingRules accountingRules = LimaBusinessConfig.getInstance().getAccountingRules(); if (validAccountingRules) { //check if the financial period is blocked - accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction(financialtransaction); + accountingRules.createFinancialTransactionRules(financialtransaction); } FinancialTransactionTopiaDao financialtransactionTopiaDao = getDaoHelper().getFinancialTransactionDao(); @@ -494,7 +494,7 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme FinancialTransactionTopiaDao transactionTopiaDao = getDaoHelper().getFinancialTransactionDao(); FinancialTransaction financialTransactionOld = transactionTopiaDao.forTopiaIdEquals(financialTransaction.getTopiaId()).findUnique(); - accountingRules.updateFinancialTransactionDateRules(financialTransaction, financialTransactionOld); + accountingRules.updateFinancialTransactionRules(financialTransaction, financialTransactionOld); financialTransactionOld.setEntryBook(financialTransaction.getEntryBook()); financialTransactionOld.setTransactionDate(financialTransaction.getTransactionDate()); @@ -511,7 +511,7 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme // check if the financial period is blocked AccountingRules accountingRules = LimaBusinessConfig.getInstance().getAccountingRules(); - accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction(financialTransaction); + accountingRules.deleteFinancialTransactionRules(financialTransaction); FinancialTransactionTopiaDao transactionTopiaDao = getDaoHelper().getFinancialTransactionDao(); FinancialTransaction financialTransactionOld = transactionTopiaDao.forTopiaIdEquals(financialTransaction.getTopiaId()).findUnique(); @@ -530,8 +530,7 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme AccountingRules accountingRules = LimaBusinessConfig.getInstance().getAccountingRules(); //check if the financial period is blocked - accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( - entry.getFinancialTransaction()); + accountingRules.createEntryRules(entry); EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); Entry newEntry = entryTopiaDao.create(entry); @@ -543,7 +542,7 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme * update entry, calculate amount of the financial transaction. */ @Override - public void updateEntry(Entry entry) throws LockedEntryBookException { + public void updateEntry(Entry entry) throws LockedEntryBookException, LockedFinancialPeriodException { AccountingRules accountingRules = LimaBusinessConfig.getInstance().getAccountingRules(); @@ -569,10 +568,8 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme AccountingRules accountingRules = LimaBusinessConfig.getInstance().getAccountingRules(); - FinancialTransaction financialTransaction = entry.getFinancialTransaction(); - //check if the financial period is blocked - accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction(financialTransaction); + accountingRules.deleteEntryRules(entry); EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); Entry entryOld = entryTopiaDao.forTopiaIdEquals(entry.getTopiaId()).findUnique(); diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java index 840ff7d..575f972 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java @@ -34,8 +34,10 @@ import org.chorem.lima.business.api.FinancialPeriodService; import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.api.FiscalPeriodService; import org.chorem.lima.business.api.ReportService; +import org.chorem.lima.business.exceptions.AfterLastFiscalPeriodException; import org.chorem.lima.business.exceptions.AlreadyExistAccountException; import org.chorem.lima.business.exceptions.AlreadyLockedFiscalPeriodException; +import org.chorem.lima.business.exceptions.BeforeFirstFiscalPeriodException; import org.chorem.lima.business.exceptions.BeginAfterEndFiscalPeriodException; import org.chorem.lima.business.exceptions.InvalidAccountNumberException; import org.chorem.lima.business.exceptions.LastUnlockedFiscalPeriodException; @@ -415,7 +417,7 @@ public class FiscalPeriodServiceImpl extends AbstractLimaService implements Fisc } } - protected FinancialTransaction createFinancialTransaction(EntryBook entryBook, Date transactionDate) throws LockedFinancialPeriodException, LockedEntryBookException { + protected FinancialTransaction createFinancialTransaction(EntryBook entryBook, Date transactionDate) throws LockedFinancialPeriodException, LockedEntryBookException, AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException { FinancialTransaction endFinancialTransaction = financialTransactionService.createNewFinancialTransaction(); //Sets the endfinancialTransaction endFinancialTransaction.setEntryBook(entryBook); 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 5f116a3..95bf43f 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 @@ -53,10 +53,12 @@ import org.chorem.lima.business.ejb.csv.VatStatementModel; import org.chorem.lima.business.ejb.ebp.AccountEBPModel; import org.chorem.lima.business.ejb.ebp.EntryBookEBPModel; import org.chorem.lima.business.ejb.ebp.EntryEBPModel; +import org.chorem.lima.business.exceptions.AfterLastFiscalPeriodException; import org.chorem.lima.business.exceptions.AlreadyExistAccountException; import org.chorem.lima.business.exceptions.AlreadyExistEntryBookException; import org.chorem.lima.business.exceptions.AlreadyExistFinancialStatementException; 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; @@ -278,7 +280,7 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ // from backup don't check fiscal period close financialTransactionService.createFinancialTransaction(financialTransaction, validAccountingRule); result.increaseCreated(); - } catch (LockedFinancialPeriodException | LockedEntryBookException e) { + } catch (LockedFinancialPeriodException | LockedEntryBookException | BeforeFirstFiscalPeriodException | AfterLastFiscalPeriodException e) { result.addException(e); results.setErrors(true); } @@ -981,7 +983,7 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ // find financial transactions for entry period and entrybook addEntryToFinancialTransaction(entry, entryEBP.getJournal(), indexedEntryBooks, entryBookFinancialTransactionByDate, dateEcr); - } catch (LockedFinancialPeriodException | LockedEntryBookException | AlreadyExistEntryBookException e) { + } catch (LockedFinancialPeriodException | LockedEntryBookException | AlreadyExistEntryBookException | AfterLastFiscalPeriodException | BeforeFirstFiscalPeriodException e) { result.addException(e); continue; } @@ -1023,7 +1025,7 @@ 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, FinancialTransaction>> entryBookFinancialTransactionByDate, Date dateEcr) throws LockedFinancialPeriodException, LockedEntryBookException, AlreadyExistEntryBookException, AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException { EntryBook entryBook = getEntryBook(indexedEntryBooks, entryBookCode); Map<Date, FinancialTransaction> financialTransactionsByDate = entryBookFinancialTransactionByDate.get(entryBook); 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 c44ea97..4f56111 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 @@ -23,22 +23,31 @@ package org.chorem.lima.business; import org.chorem.lima.business.ejb.FinancialTransactionServiceImpl; +import org.chorem.lima.business.exceptions.AfterLastFiscalPeriodException; +import org.chorem.lima.business.exceptions.BeforeFirstFiscalPeriodException; import org.chorem.lima.business.exceptions.LimaException; +import org.chorem.lima.business.exceptions.LockedEntryBookException; +import org.chorem.lima.business.exceptions.LockedFinancialPeriodException; import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryImpl; +import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FinancialTransactionImpl; import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.entity.FiscalPeriodImpl; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.nuiton.util.DateUtil; import java.math.BigDecimal; import java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; /** @@ -60,6 +69,628 @@ public class FinancialTransactionServiceImplTest extends AbstractLimaTest { createFinancialTransaction(); } + @Test + public void createNewFinancialTransactionTest() { + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + Assert.assertNotNull(transaction); + Assert.assertNull(transaction.getEntryBook()); + Assert.assertNull(transaction.getTransactionDate()); + Assert.assertNull(transaction.getEntry()); + + } + + @Test + public void createNewEntryTest() { + + Entry entry = financialTransactionService.createNewEntry(); + + Assert.assertNotNull(entry); + Assert.assertNull(entry.getFinancialTransaction()); + Assert.assertNull(entry.getDescription()); + Assert.assertNull(entry.getDetail()); + Assert.assertNull(entry.getLettering()); + Assert.assertNull(entry.getAccount()); + Assert.assertNull(entry.getLettering()); + Assert.assertNull(entry.getVoucher()); + Assert.assertEquals(BigDecimal.ZERO, entry.getAmount()); + Assert.assertFalse(entry.isDebit()); + + } + + @Test + public void createFinancialTransactionTest() throws Exception { + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBookService.getEntryBookByCode("jdv")); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + FinancialTransaction transactionSave = financialTransactionService.createFinancialTransaction(transaction); + + Assert.assertNotNull(transactionSave); + Assert.assertEquals(transaction.getEntryBook(), transactionSave.getEntryBook()); + Assert.assertEquals(transaction.getTransactionDate(), transactionSave.getTransactionDate()); + Assert.assertTrue(transactionSave.getEntry().isEmpty()); + Assert.assertTrue(transactionSave.isPersisted()); + } + + @Test(expected = LockedFinancialPeriodException.class) + public void createFinancialTransactionFailLockedFinancialPeriodeTest() throws Exception { + + FiscalPeriod fiscalPeriod = fiscalPeriodService.getAllFiscalPeriods().get(0); + + FiscalPeriod nextFiscalPeriod = new FiscalPeriodImpl(); + nextFiscalPeriod.setBeginDate(DateUtil.createDate(01, 01, 2013)); + nextFiscalPeriod.setEndDate(DateUtil.createDate(31, 12, 2013)); + fiscalPeriodService.createFiscalPeriod(nextFiscalPeriod); + + fiscalPeriodService.blockFiscalPeriod(fiscalPeriod); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBookService.getEntryBookByCode("jdv")); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + financialTransactionService.createFinancialTransaction(transaction); + + } + + @Test(expected = LockedEntryBookException.class) + public void createFinancialTransactionFailLockedEntryBookPeriodeTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + List<FinancialPeriod> financialPeriods = financialPeriodService.getAllFinancialPeriods(); + + ClosedPeriodicEntryBook closedPeriodicEntryBook = financialPeriodService.getClosedPeriodicEntryBook(entryBook, financialPeriods.get(0)); + + financialPeriodService.blockClosedPeriodicEntryBook(closedPeriodicEntryBook); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + financialTransactionService.createFinancialTransaction(transaction); + + } + + @Test(expected = AfterLastFiscalPeriodException.class) + public void createFinancialTransactionFailAfterLastFiscalPeriodeTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2014)); + + financialTransactionService.createFinancialTransaction(transaction); + + } + + @Test(expected = BeforeFirstFiscalPeriodException.class) + public void createFinancialTransactionFailBeforeFirstFiscalPeriodeTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2010)); + + financialTransactionService.createFinancialTransaction(transaction); + + } + + @Test + public void updateFinancialTransactionTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + entryBook = entryBookService.getEntryBookByCode("jda"); + + transaction.setEntryBook(entryBook); + Date date = DateUtil.createDate(15, 01, 2012); + transaction.setTransactionDate(date); + + financialTransactionService.updateFinancialTransaction(transaction); + + List<FinancialTransaction> transactions = financialTransactionService.getAllFinancialTransactions(date, date); + + Assert.assertEquals(1, transactions.size()); + Assert.assertTrue(transactions.contains(transaction)); + } + + @Test(expected = AfterLastFiscalPeriodException.class) + public void updateFinancialTransactionFailAfterLastFiscalPeriodTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + Date date = DateUtil.createDate(15, 01, 2014); + transaction.setTransactionDate(date); + + financialTransactionService.updateFinancialTransaction(transaction); + } + + @Test(expected = BeforeFirstFiscalPeriodException.class) + public void updateFinancialTransactionFailBeforeFirstFiscalPeriodTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + Date date = DateUtil.createDate(15, 01, 2010); + transaction.setTransactionDate(date); + + financialTransactionService.updateFinancialTransaction(transaction); + } + + @Test(expected = LockedFinancialPeriodException.class) + public void updateFinancialTransactionFailLockedFinancialPeriodTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + FiscalPeriod fiscalPeriod = fiscalPeriodService.getAllFiscalPeriods().get(0); + + FiscalPeriod nextFiscalPeriod = new FiscalPeriodImpl(); + nextFiscalPeriod.setBeginDate(DateUtil.createDate(01, 01, 2013)); + nextFiscalPeriod.setEndDate(DateUtil.createDate(31, 12, 2013)); + fiscalPeriodService.createFiscalPeriod(nextFiscalPeriod); + + fiscalPeriodService.blockFiscalPeriod(fiscalPeriod); + + Date date = DateUtil.createDate(15, 01, 2012); + transaction.setTransactionDate(date); + + financialTransactionService.updateFinancialTransaction(transaction); + } + + @Test(expected = LockedEntryBookException.class) + public void updateFinancialTransactionFailLockedEntryBookOrigTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + List<FinancialPeriod> financialPeriods = financialPeriodService.getAllFinancialPeriods(); + + ClosedPeriodicEntryBook closedPeriodicEntryBook = financialPeriodService.getClosedPeriodicEntryBook(entryBook, financialPeriods.get(0)); + + financialPeriodService.blockClosedPeriodicEntryBook(closedPeriodicEntryBook); + + entryBook = entryBookService.getEntryBookByCode("jda"); + transaction.setEntryBook(entryBook); + + financialTransactionService.updateFinancialTransaction(transaction); + } + + @Test + public void removeFinancialTransactionTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + Date date = DateUtil.createDate(12, 01, 2012); + transaction.setTransactionDate(date); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + financialTransactionService.removeFinancialTransaction(transaction); + + List<FinancialTransaction> transactions = financialTransactionService.getAllFinancialTransactions(date, date); + + Assert.assertEquals(0, transactions.size()); + } + + @Test(expected = LockedFinancialPeriodException.class) + public void removeFinancialTransactionFailLockedFinancialPeriodTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + FiscalPeriod fiscalPeriod = fiscalPeriodService.getAllFiscalPeriods().get(0); + + FiscalPeriod nextFiscalPeriod = new FiscalPeriodImpl(); + nextFiscalPeriod.setBeginDate(DateUtil.createDate(01, 01, 2013)); + nextFiscalPeriod.setEndDate(DateUtil.createDate(31, 12, 2013)); + fiscalPeriodService.createFiscalPeriod(nextFiscalPeriod); + + fiscalPeriodService.blockFiscalPeriod(fiscalPeriod); + + financialTransactionService.removeFinancialTransaction(transaction); + } + + @Test(expected = LockedEntryBookException.class) + public void removeFinancialTransactionFailLockedEntryBookTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + List<FinancialPeriod> financialPeriods = financialPeriodService.getAllFinancialPeriods(); + + ClosedPeriodicEntryBook closedPeriodicEntryBook = financialPeriodService.getClosedPeriodicEntryBook(entryBook, financialPeriods.get(0)); + + financialPeriodService.blockClosedPeriodicEntryBook(closedPeriodicEntryBook); + + financialTransactionService.removeFinancialTransaction(transaction); + } + + @Test + public void createEntryTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + Entry entry = new EntryImpl(); + entry.setAccount(accountService.getAccountByNumber("511")); + entry.setVoucher("Voucher"); + entry.setDebit(true); + entry.setAmount(BigDecimal.valueOf(14.36)); + transaction.addEntry(entry); + + Entry entry1 = financialTransactionService.createEntry(entry); + + Assert.assertTrue(entry1.isPersisted()); + + } + + @Test(expected = LockedFinancialPeriodException.class) + public void createEntryFailLockedFinancialPeriodTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + FiscalPeriod fiscalPeriod = fiscalPeriodService.getAllFiscalPeriods().get(0); + + FiscalPeriod nextFiscalPeriod = new FiscalPeriodImpl(); + nextFiscalPeriod.setBeginDate(DateUtil.createDate(01, 01, 2013)); + nextFiscalPeriod.setEndDate(DateUtil.createDate(31, 12, 2013)); + fiscalPeriodService.createFiscalPeriod(nextFiscalPeriod); + + fiscalPeriodService.blockFiscalPeriod(fiscalPeriod); + + + Entry entry = new EntryImpl(); + entry.setAccount(accountService.getAccountByNumber("511")); + entry.setVoucher("Voucher"); + entry.setDebit(true); + entry.setAmount(BigDecimal.valueOf(14.36)); + transaction.addEntry(entry); + + financialTransactionService.createEntry(entry); + + } + + @Test(expected = LockedEntryBookException.class) + public void createEntryFailLockedEntryBookTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + List<FinancialPeriod> financialPeriods = financialPeriodService.getAllFinancialPeriods(); + + ClosedPeriodicEntryBook closedPeriodicEntryBook = financialPeriodService.getClosedPeriodicEntryBook(entryBook, financialPeriods.get(0)); + + financialPeriodService.blockClosedPeriodicEntryBook(closedPeriodicEntryBook); + + Entry entry = new EntryImpl(); + entry.setAccount(accountService.getAccountByNumber("511")); + entry.setVoucher("Voucher"); + entry.setDebit(true); + entry.setAmount(BigDecimal.valueOf(14.36)); + transaction.addEntry(entry); + + financialTransactionService.createEntry(entry); + + } + + @Test + public void updateEntryTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + Date date = DateUtil.createDate(12, 01, 2012); + transaction.setTransactionDate(date); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + Entry entry = new EntryImpl(); + entry.setAccount(accountService.getAccountByNumber("511")); + entry.setVoucher("Voucher"); + entry.setDebit(true); + entry.setAmount(BigDecimal.valueOf(14.36)); + transaction.addEntry(entry); + + Entry entry1 = financialTransactionService.createEntry(entry); + + financialTransactionService.updateFinancialTransaction(transaction); + + entry1.setAccount(accountService.getAccountByNumber("501")); + entry1.setVoucher("VoucherBis"); + entry1.setDebit(true); + entry1.setAmount(BigDecimal.valueOf(15.21)); + + financialTransactionService.updateEntry(entry1); + + FinancialTransaction transactionSave = financialTransactionService.getAllFinancialTransactions(date, date).get(0); + + Assert.assertEquals(1, transactionSave.sizeEntry()); + Entry entrySave = transactionSave.getEntry().iterator().next(); + Assert.assertEquals(entry1, entrySave); + Assert.assertEquals("501", entrySave.getAccount().getAccountNumber()); + Assert.assertEquals("VoucherBis", entrySave.getVoucher()); + Assert.assertEquals(true, entrySave.isDebit()); + Assert.assertEquals(BigDecimal.valueOf(15.21), entrySave.getAmount()); + + } + + @Test(expected = LockedFinancialPeriodException.class) + public void updateEntryFailLockedFinancialPeriodTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + Entry entry = new EntryImpl(); + entry.setAccount(accountService.getAccountByNumber("511")); + entry.setVoucher("Voucher"); + entry.setDebit(true); + entry.setAmount(BigDecimal.valueOf(14.36)); + transaction.addEntry(entry); + + Entry entry1 = financialTransactionService.createEntry(entry); + financialTransactionService.updateFinancialTransaction(transaction); + + + FiscalPeriod fiscalPeriod = fiscalPeriodService.getAllFiscalPeriods().get(0); + + FiscalPeriod nextFiscalPeriod = new FiscalPeriodImpl(); + nextFiscalPeriod.setBeginDate(DateUtil.createDate(01, 01, 2013)); + nextFiscalPeriod.setEndDate(DateUtil.createDate(31, 12, 2013)); + fiscalPeriodService.createFiscalPeriod(nextFiscalPeriod); + + fiscalPeriodService.blockFiscalPeriod(fiscalPeriod); + + entry1.setAccount(accountService.getAccountByNumber("501")); + entry1.setVoucher("VoucherBis"); + entry1.setDebit(true); + entry1.setAmount(BigDecimal.valueOf(15.21)); + + financialTransactionService.updateEntry(entry1); + + } + + @Test(expected = LockedEntryBookException.class) + public void updateEntryFailLockedEntryBookTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + Entry entry1 = new EntryImpl(); + entry1.setAccount(accountService.getAccountByNumber("511")); + entry1.setVoucher("Voucher"); + entry1.setDebit(true); + entry1.setAmount(BigDecimal.valueOf(14.36)); + entry1.setDescription("Description"); + transaction.addEntry(entry1); + + Entry entry2 = new EntryImpl(); + entry2.setAccount(accountService.getAccountByNumber("501")); + entry2.setVoucher("Voucher"); + entry2.setDebit(false); + entry2.setAmount(BigDecimal.valueOf(14.36)); + entry2.setDescription("Description"); + transaction.addEntry(entry2); + + Entry entrySave1 = financialTransactionService.createEntry(entry1); + Entry entrySave2 = financialTransactionService.createEntry(entry2); + financialTransactionService.updateFinancialTransaction(transaction); + + List<FinancialPeriod> financialPeriods = financialPeriodService.getAllFinancialPeriods(); + + ClosedPeriodicEntryBook closedPeriodicEntryBook = financialPeriodService.getClosedPeriodicEntryBook(entryBook, financialPeriods.get(0)); + + financialPeriodService.blockClosedPeriodicEntryBook(closedPeriodicEntryBook); + + entrySave1.setAccount(accountService.getAccountByNumber("501")); + entrySave1.setVoucher("VoucherBis"); + entrySave1.setDebit(true); + entrySave1.setAmount(BigDecimal.valueOf(15.21)); + + financialTransactionService.updateEntry(entrySave1); + + } + + @Test + public void removeEntryTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + Date date = DateUtil.createDate(12, 01, 2012); + transaction.setTransactionDate(date); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + Entry entry = new EntryImpl(); + entry.setAccount(accountService.getAccountByNumber("511")); + entry.setVoucher("Voucher"); + entry.setDebit(true); + entry.setAmount(BigDecimal.valueOf(14.36)); + transaction.addEntry(entry); + + Entry entry1 = financialTransactionService.createEntry(entry); + + financialTransactionService.updateFinancialTransaction(transaction); + + financialTransactionService.removeEntry(entry1); + + FinancialTransaction transactionSave = financialTransactionService.getAllFinancialTransactions(date, date).get(0); + + Assert.assertEquals(0, transactionSave.sizeEntry()); + + } + + @Test(expected = LockedFinancialPeriodException.class) + public void removeEntryFailLockedFinancialPeriodTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + Entry entry = new EntryImpl(); + entry.setAccount(accountService.getAccountByNumber("511")); + entry.setVoucher("Voucher"); + entry.setDebit(true); + entry.setAmount(BigDecimal.valueOf(14.36)); + transaction.addEntry(entry); + + Entry entry1 = financialTransactionService.createEntry(entry); + financialTransactionService.updateFinancialTransaction(transaction); + + + FiscalPeriod fiscalPeriod = fiscalPeriodService.getAllFiscalPeriods().get(0); + + FiscalPeriod nextFiscalPeriod = new FiscalPeriodImpl(); + nextFiscalPeriod.setBeginDate(DateUtil.createDate(01, 01, 2013)); + nextFiscalPeriod.setEndDate(DateUtil.createDate(31, 12, 2013)); + fiscalPeriodService.createFiscalPeriod(nextFiscalPeriod); + + fiscalPeriodService.blockFiscalPeriod(fiscalPeriod); + + financialTransactionService.removeEntry(entry1); + + } + + @Test(expected = LockedEntryBookException.class) + public void removeEntryFailLockedEntryBookTest() throws Exception { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + FinancialTransaction transaction = financialTransactionService.createNewFinancialTransaction(); + + transaction.setEntryBook(entryBook); + transaction.setTransactionDate(DateUtil.createDate(12, 01, 2012)); + + transaction = financialTransactionService.createFinancialTransaction(transaction); + + Entry entry1 = new EntryImpl(); + entry1.setAccount(accountService.getAccountByNumber("511")); + entry1.setVoucher("Voucher"); + entry1.setDebit(true); + entry1.setAmount(BigDecimal.valueOf(14.36)); + entry1.setDescription("Description"); + transaction.addEntry(entry1); + + Entry entry2 = new EntryImpl(); + entry2.setAccount(accountService.getAccountByNumber("501")); + entry2.setVoucher("Voucher"); + entry2.setDebit(false); + entry2.setAmount(BigDecimal.valueOf(14.36)); + entry2.setDescription("Description"); + transaction.addEntry(entry2); + + Entry entrySave1 = financialTransactionService.createEntry(entry1); + Entry entrySave2 = financialTransactionService.createEntry(entry2); + financialTransactionService.updateFinancialTransaction(transaction); + + List<FinancialPeriod> financialPeriods = financialPeriodService.getAllFinancialPeriods(); + + ClosedPeriodicEntryBook closedPeriodicEntryBook = financialPeriodService.getClosedPeriodicEntryBook(entryBook, financialPeriods.get(0)); + + financialPeriodService.blockClosedPeriodicEntryBook(closedPeriodicEntryBook); + + financialTransactionService.removeEntry(entrySave1); + + } + + /** * Test to find all unbalanced transactions. * Nothing wrong here. diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/common/FinancialTransactionTableModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/common/FinancialTransactionTableModel.java index c002d8d..543c993 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/common/FinancialTransactionTableModel.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/common/FinancialTransactionTableModel.java @@ -218,11 +218,15 @@ public class FinancialTransactionTableModel extends TableModelWithGroup<Entry> { financialTransactionService.updateEntry(entry); updated = true; } catch (LockedEntryBookException e) { - errorHelper.showErrorMessage(t("lima.entry.update.closed.entryBook.error", + errorHelper.showErrorMessage(t("lima.entry.update.error.closedEntryBook", e.getClosedPeriodicEntryBook().getEntryBook().getCode(), e.getClosedPeriodicEntryBook().getEntryBook().getLabel(), e.getClosedPeriodicEntryBook().getFinancialPeriod().getBeginDate(), e.getClosedPeriodicEntryBook().getFinancialPeriod().getEndDate())); + } catch (LockedFinancialPeriodException e) { + errorHelper.showErrorMessage(t("lima.entry.update.error.lockedFinancialPeriod", + e.getFinancialPeriod().getBeginDate(), + e.getFinancialPeriod().getEndDate())); } return updated; } diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java index 98279e9..c4b7466 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java @@ -862,6 +862,23 @@ public class FinancialTransactionViewHandler implements ServiceListener, TableMo break; } } + } catch (LockedFinancialPeriodException e) { + errorHelper.showErrorMessage(t("lima.entries.assign.error.lockedFinancialPeriod", + e.getFinancialPeriod().getBeginDate(), + e.getFinancialPeriod().getEndDate())); + // restaure prévious values + for (Map.Entry<Entry, String> mapEntry : previousValuesMap.entrySet()) { + Entry entry = mapEntry.getKey(); + String previousValue = mapEntry.getValue(); + switch (selectedColumn) { + case 1: + entry.setVoucher(previousValue); + break; + case 3: + entry.setDescription(previousValue); + break; + } + } } } } 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 1f21268..424b50e 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 @@ -144,6 +144,7 @@ lima.entries.addEntry=New entry lima.entries.addTransaction=New transaction lima.entries.assign.entries=Assign this value in all entries in transaction lima.entries.assign.error.lockedEntryBook= +lima.entries.assign.error.lockedFinancialPeriod= lima.entries.balance=Balance transaction with this entry lima.entries.copy.entry=Copy entry lima.entries.copy.transaction=Copy transaction @@ -185,6 +186,8 @@ lima.entry.description=Description lima.entry.letter=Letter lima.entry.remove.confirm=Do you really want to remove this financial transaction line ? lima.entry.update.closed.entryBook.error= +lima.entry.update.error.closedEntryBook= +lima.entry.update.error.lockedFinancialPeriod= lima.entryBook=EntryBook lima.entryBook.add=Add entry book (Ctrl+A) lima.entryBook.alreadyExistEntryBook=Already existing entry book 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 3655f1b..a0128dd 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 @@ -159,6 +159,7 @@ lima.entries.addEntry=Créer une entrée dans la transaction (Ctrl+N) lima.entries.addTransaction=Créer une transaction (Ctrl+Maj+N) lima.entries.assign.entries=Assigner cette valeur à toutes les écritures de la transaction (Ctrl+Alt+A) lima.entries.assign.error.lockedEntryBook=Impossible d'affecter cette valeur a l'ensemble des écritures de la transaction car le jounal %2$s (%1$s) est cloturé pour la période du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY. +lima.entries.assign.error.lockedFinancialPeriod=Impossible d'affecter cette valeur a l'ensemble des écritures de la transaction car la période fiscale du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY est cloturée. lima.entries.balance=Équilibrer la transaction avec cette écriture (Ctrl+B) lima.entries.copy.entry=Copier l'écritures (Ctrl+Alt+C) lima.entries.copy.transaction=Copier la transaction (Ctrl+Maj+C) @@ -198,7 +199,8 @@ lima.entry.debit=Débit lima.entry.description=Description lima.entry.letter=Lettre lima.entry.remove.confirm=Voulez-vous supprimer cette ligne de transaction? -lima.entry.update.closed.entryBook.error=Impossible de modifier cette écriture car le jounal %2$s (%1$s) est cloturé pour la période du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY. +lima.entry.update.error.closedEntryBook=Impossible de modifier cette écriture car le jounal %2$s (%1$s) est cloturé pour la période du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY. +lima.entry.update.error.lockedFinancialPeriod=Impossilbe de modifier cette écriture car la période fiscale du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY est cloturée. lima.entryBook=Journal lima.entryBook.add=Ajout de journal (Ctrl+A) lima.entryBook.alreadyExistEntryBook=Un journal avec comme code %s existe déjà. -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.