This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository lima. See http://git.chorem.org/lima.git commit 43a92d4f84d15e80e568526e7a40137624c6f7e9 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Jun 3 15:17:52 2015 +0200 refs #1233 : test du service des exercices --- .../lima/business/api/FiscalPeriodService.java | 22 +- .../lima/business/ejb/FiscalPeriodServiceImpl.java | 11 +- .../lima/business/FiscalPeriodServiceImplTest.java | 426 ++++++++++++++++++--- .../ui/fiscalperiod/FiscalPeriodViewHandler.java | 2 +- 4 files changed, 385 insertions(+), 76 deletions(-) diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java b/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java index 77692bc..2ce8af4 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java @@ -22,9 +22,11 @@ package org.chorem.lima.business.api; +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.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; @@ -100,7 +102,9 @@ public interface FiscalPeriodService { * @throws LastUnlockedFiscalPeriodException */ FiscalPeriod blockFiscalPeriod(FiscalPeriod fiscalPeriod) - throws AlreadyLockedFiscalPeriodException, LastUnlockedFiscalPeriodException, UnbalancedFinancialTransactionsException, WithoutEntryBookFinancialTransactionsException, UnfilledEntriesException; + throws AlreadyLockedFiscalPeriodException, LastUnlockedFiscalPeriodException, + UnbalancedFinancialTransactionsException, WithoutEntryBookFinancialTransactionsException, + UnfilledEntriesException; /** * Remove the given fiscal period @@ -114,18 +118,14 @@ public interface FiscalPeriodService { * and in any case, block fiscal period * @param fiscalPeriod fiscal period selected, and to block * @param entryBook entry book where entries will be save in new fiscal period - * @param retainedEarnings to know if user want retained earnings * @return fiscal period blocked * */ - FiscalPeriod retainedEarningsAndBlockFiscalPeriod(FiscalPeriod fiscalPeriod, EntryBook entryBook, - boolean retainedEarnings) - throws LockedFinancialPeriodException, - LockedEntryBookException, - NoFoundFinancialPeriodException, - LastUnlockedFiscalPeriodException, - AlreadyLockedFiscalPeriodException, - AlreadyExistAccountException, - InvalidAccountNumberException, NotNumberAccountNumberException, NotAllowedLabelException, AlreadyExistEntryBookException, UnfilledEntriesException, UnbalancedFinancialTransactionsException, WithoutEntryBookFinancialTransactionsException; + FiscalPeriod retainedEarningsAndBlockFiscalPeriod(FiscalPeriod fiscalPeriod, EntryBook entryBook) + throws LockedFinancialPeriodException, LockedEntryBookException, NoFoundFinancialPeriodException, + LastUnlockedFiscalPeriodException, AlreadyLockedFiscalPeriodException, AlreadyExistAccountException, + InvalidAccountNumberException, NotNumberAccountNumberException, NotAllowedLabelException, + AlreadyExistEntryBookException, UnfilledEntriesException, UnbalancedFinancialTransactionsException, + WithoutEntryBookFinancialTransactionsException, AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException; /** * Test if we have retained earnings on a fiscal period 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 33098a5..64b2346 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 @@ -251,6 +251,9 @@ public class FiscalPeriodServiceImpl extends AbstractLimaService implements Fisc // locked all financialperiod of the fiscalperiod for (FinancialPeriod financialPeriod : oldFiscalPeriod.getFinancialPeriod()) { financialPeriod.setLocked(true); + for (ClosedPeriodicEntryBook closedPeriodicEntryBook : financialPeriod.getEntryBookClosedPeriodicEntryBook()) { + closedPeriodicEntryBook.setLocked(true); + } } FiscalPeriod result = fiscalPeriodTopiaDao.update(oldFiscalPeriod); @@ -293,15 +296,15 @@ public class FiscalPeriodServiceImpl extends AbstractLimaService implements Fisc } @Override - public FiscalPeriod retainedEarningsAndBlockFiscalPeriod(FiscalPeriod fiscalPeriod, EntryBook entryBook, - boolean retainedEarnings) + public FiscalPeriod retainedEarningsAndBlockFiscalPeriod(FiscalPeriod fiscalPeriod, EntryBook entryBook) throws AlreadyExistEntryBookException, AlreadyExistAccountException, NotAllowedLabelException, InvalidAccountNumberException, NotNumberAccountNumberException, NoFoundFinancialPeriodException, LockedFinancialPeriodException, LockedEntryBookException, UnfilledEntriesException, UnbalancedFinancialTransactionsException, LastUnlockedFiscalPeriodException, - WithoutEntryBookFinancialTransactionsException, AlreadyLockedFiscalPeriodException { + WithoutEntryBookFinancialTransactionsException, AlreadyLockedFiscalPeriodException, + AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException { - if (entryBook != null && retainedEarnings) { + if (entryBook != null) { // re-attach entities to current session 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 721f76e..7a74550 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 @@ -22,12 +22,25 @@ package org.chorem.lima.business; +import com.google.common.collect.Maps; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.exceptions.AlreadyLockedFiscalPeriodException; import org.chorem.lima.business.exceptions.BeginAfterEndFiscalPeriodException; +import org.chorem.lima.business.exceptions.LastUnlockedFiscalPeriodException; import org.chorem.lima.business.exceptions.MoreOneUnlockFiscalPeriodException; +import org.chorem.lima.business.exceptions.NoEmptyFiscalPeriodException; import org.chorem.lima.business.exceptions.NotBeginNextDayOfLastFiscalPeriodException; +import org.chorem.lima.business.exceptions.UnbalancedFinancialTransactionsException; +import org.chorem.lima.business.exceptions.UnfilledEntriesException; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.AccountImpl; +import org.chorem.lima.entity.ClosedPeriodicEntryBook; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.EntryBookImpl; import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FiscalPeriodImpl; import org.junit.Assert; @@ -35,8 +48,10 @@ import org.junit.Before; import org.junit.Test; import org.nuiton.util.DateUtil; +import java.math.BigDecimal; import java.util.Date; import java.util.List; +import java.util.Map; /** * Tests pour la gestion des périodes @@ -246,69 +261,360 @@ public class FiscalPeriodServiceImplTest extends AbstractLimaTest { @Test public void blockFiscalPeriodTest() throws Exception { - /*TopiaContext transaction = null; - FiscalPeriod recentFiscalPeriod = new FiscalPeriodImpl(); - FiscalPeriod oldestFiscalPeriod = new FiscalPeriodImpl(); - - try { - - transaction = beginTransaction(); - - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); - - FinancialPeriodServiceImpl financialPeriodService = - new FinancialPeriodServiceImpl(); - - //On crée deux période, une récente - - FinancialPeriod financialPeriod = new FinancialPeriodImpl(); - Calendar beginCalendar = Calendar.getInstance(); - recentFiscalPeriod.setBeginDate(beginCalendar.getTime()); - Calendar endCalendar = beginCalendar; - endCalendar.add(Calendar.MONTH, 12); - recentFiscalPeriod.setEndDate(endCalendar.getTime()); - fiscalPeriodDAO.create(recentFiscalPeriod); - recentFiscalPeriod.addFinancialPeriod(financialPeriod); - - List<FinancialPeriod> financialPeriodsList = new ArrayList<FinancialPeriod>(); - financialPeriodsList.add(financialPeriod); - financialPeriodService.createFinancialPeriods(financialPeriodsList); - - - //une plus ancienne - beginCalendar.add(Calendar.YEAR, -2); - oldestFiscalPeriod.setBeginDate(beginCalendar.getTime()); - endCalendar.add(Calendar.YEAR, -2); - oldestFiscalPeriod.setEndDate(endCalendar.getTime()); - fiscalPeriodDAO.create(oldestFiscalPeriod); - oldestFiscalPeriod.addFinancialPeriod(financialPeriod); - - transaction.commitTransaction(); - - } finally { - transaction.closeContext(); + FiscalPeriod period1 = new FiscalPeriodImpl(); + Date bedingDate1 = DateUtil.createDate(01, 01, 2012); + period1.setBeginDate(bedingDate1); + Date endDate1 = DateUtil.createDate(31, 12, 2012); + period1.setEndDate(endDate1); + + FiscalPeriod periodSave1 = fiscalPeriodService.createFiscalPeriod(period1); + + FiscalPeriod period2 = new FiscalPeriodImpl(); + Date bedingDate2 = DateUtil.createDate(01, 01, 2013); + period2.setBeginDate(bedingDate2); + Date endDate2 = DateUtil.createDate(31, 12, 2013); + period2.setEndDate(endDate2); + + fiscalPeriodService.createFiscalPeriod(period2); + + fiscalPeriodService.blockFiscalPeriod(periodSave1); + + List<FiscalPeriod> allFiscalPeriods = fiscalPeriodService.getAllFiscalPeriods(); + periodSave1 = allFiscalPeriods.get(0); + FiscalPeriod periodSave2 = allFiscalPeriods.get(1); + + Assert.assertEquals(true, periodSave1.isLocked()); + List<FiscalPeriod> blockedFiscalPeriods = fiscalPeriodService.getAllBlockedFiscalPeriods(); + Assert.assertEquals(1, blockedFiscalPeriods.size()); + Assert.assertEquals(true, blockedFiscalPeriods.contains(periodSave1)); + + + List<FiscalPeriod> unblockedFiscalPeriods = fiscalPeriodService.getAllUnblockedFiscalPeriods(); + Assert.assertEquals(1, unblockedFiscalPeriods.size()); + Assert.assertEquals(true, unblockedFiscalPeriods.contains(periodSave2)); + + for (FinancialPeriod financialPeriod : financialPeriodService.getFinancialPeriods(periodSave1.getBeginDate(), periodSave1.getEndDate())) { + Assert.assertEquals(true, financialPeriod.isLocked()); + for (EntryBook entryBook : entryBookService.getAllEntryBooks()) { + ClosedPeriodicEntryBook closedPeriodicEntryBook = + financialPeriodService.getClosedPeriodicEntryBook(entryBook, financialPeriod); + + Assert.assertEquals(true, closedPeriodicEntryBook.isLocked()); + } } - - Assert.assertNotSame(recentFiscalPeriod.getTopiaId(), - oldestFiscalPeriod.getTopiaId()); - - FiscalPeriodService fiscalPeriodService = new FiscalPeriodServiceImpl(); - - - try{ - fiscalPeriodService.blockFiscalPeriod(oldestFiscalPeriod); - } catch (Exception ex){ - log.debug("Error test block Period", ex); - Assert.assertEquals(LimaBusinessException.class, ex.getClass()); + } + + @Test(expected = AlreadyLockedFiscalPeriodException.class) + public void blockFiscalPeriodFailAlreadyLockedTest() throws Exception { + + FiscalPeriod period1 = new FiscalPeriodImpl(); + Date bedingDate1 = DateUtil.createDate(01, 01, 2012); + period1.setBeginDate(bedingDate1); + Date endDate1 = DateUtil.createDate(31, 12, 2012); + period1.setEndDate(endDate1); + + FiscalPeriod periodSave1 = fiscalPeriodService.createFiscalPeriod(period1); + + FiscalPeriod period2 = new FiscalPeriodImpl(); + Date bedingDate2 = DateUtil.createDate(01, 01, 2013); + period2.setBeginDate(bedingDate2); + Date endDate2 = DateUtil.createDate(31, 12, 2013); + period2.setEndDate(endDate2); + + fiscalPeriodService.createFiscalPeriod(period2); + + fiscalPeriodService.blockFiscalPeriod(periodSave1); + + FiscalPeriod periodBlockSave1 = fiscalPeriodService.getAllBlockedFiscalPeriods().get(0); + + fiscalPeriodService.blockFiscalPeriod(periodBlockSave1); + + } + + @Test(expected = LastUnlockedFiscalPeriodException.class) + public void blockFiscalPeriodFailNotNextTest() throws Exception { + + FiscalPeriod period1 = new FiscalPeriodImpl(); + Date bedingDate1 = DateUtil.createDate(01, 01, 2012); + period1.setBeginDate(bedingDate1); + Date endDate1 = DateUtil.createDate(31, 12, 2012); + period1.setEndDate(endDate1); + + FiscalPeriod periodSave1 = fiscalPeriodService.createFiscalPeriod(period1); + + fiscalPeriodService.blockFiscalPeriod(periodSave1); + + } + + @Test(expected = UnbalancedFinancialTransactionsException.class) + public void blockFiscalPeriodFailUnbalancedFinancialTransactionsTest() throws Exception { + + FiscalPeriod period1 = new FiscalPeriodImpl(); + Date bedingDate1 = DateUtil.createDate(01, 01, 2012); + period1.setBeginDate(bedingDate1); + Date endDate1 = DateUtil.createDate(31, 12, 2012); + period1.setEndDate(endDate1); + + FiscalPeriod periodSave1 = fiscalPeriodService.createFiscalPeriod(period1); + + FiscalPeriod period2 = new FiscalPeriodImpl(); + Date bedingDate2 = DateUtil.createDate(01, 01, 2013); + period2.setBeginDate(bedingDate2); + Date endDate2 = DateUtil.createDate(31, 12, 2013); + period2.setEndDate(endDate2); + + fiscalPeriodService.createFiscalPeriod(period2); + + FinancialTransaction transaction = createFinancialTransaction("jdv", DateUtil.createDate(04, 04, 2012), "511", "501", BigDecimal.valueOf(42.0)); + Entry entry = transaction.getEntry().iterator().next(); + entry.setAmount(BigDecimal.valueOf(12.36)); + financialTransactionService.updateEntry(entry); + + fiscalPeriodService.blockFiscalPeriod(periodSave1); + } + + @Test(expected = UnfilledEntriesException.class) + public void blockFiscalPeriodFailUnfilledVoucherTest() throws Exception { + + FiscalPeriod period1 = new FiscalPeriodImpl(); + Date bedingDate1 = DateUtil.createDate(01, 01, 2012); + period1.setBeginDate(bedingDate1); + Date endDate1 = DateUtil.createDate(31, 12, 2012); + period1.setEndDate(endDate1); + + FiscalPeriod periodSave1 = fiscalPeriodService.createFiscalPeriod(period1); + + FiscalPeriod period2 = new FiscalPeriodImpl(); + Date bedingDate2 = DateUtil.createDate(01, 01, 2013); + period2.setBeginDate(bedingDate2); + Date endDate2 = DateUtil.createDate(31, 12, 2013); + period2.setEndDate(endDate2); + + fiscalPeriodService.createFiscalPeriod(period2); + + FinancialTransaction transaction = createFinancialTransaction("jdv", DateUtil.createDate(04, 04, 2012), "511", "501", BigDecimal.valueOf(42.0)); + Entry entry = transaction.getEntry().iterator().next(); + entry.setVoucher(""); + financialTransactionService.updateEntry(entry); + + fiscalPeriodService.blockFiscalPeriod(periodSave1); + } + + @Test(expected = UnfilledEntriesException.class) + public void blockFiscalPeriodFailUnfilledDescriptionTest() throws Exception { + + FiscalPeriod period1 = new FiscalPeriodImpl(); + Date bedingDate1 = DateUtil.createDate(01, 01, 2012); + period1.setBeginDate(bedingDate1); + Date endDate1 = DateUtil.createDate(31, 12, 2012); + period1.setEndDate(endDate1); + + FiscalPeriod periodSave1 = fiscalPeriodService.createFiscalPeriod(period1); + + FiscalPeriod period2 = new FiscalPeriodImpl(); + Date bedingDate2 = DateUtil.createDate(01, 01, 2013); + period2.setBeginDate(bedingDate2); + Date endDate2 = DateUtil.createDate(31, 12, 2013); + period2.setEndDate(endDate2); + + fiscalPeriodService.createFiscalPeriod(period2); + + FinancialTransaction transaction = createFinancialTransaction("jdv", DateUtil.createDate(04, 04, 2012), "511", "501", BigDecimal.valueOf(42.0)); + Entry entry = transaction.getEntry().iterator().next(); + entry.setDescription(""); + financialTransactionService.updateEntry(entry); + + fiscalPeriodService.blockFiscalPeriod(periodSave1); + } + + @Test + public void deleteFiscalPeriodTest() throws Exception { + + FiscalPeriod period1 = new FiscalPeriodImpl(); + Date bedingDate1 = DateUtil.createDate(01, 01, 2012); + period1.setBeginDate(bedingDate1); + Date endDate1 = DateUtil.createDate(31, 12, 2012); + period1.setEndDate(endDate1); + + FiscalPeriod periodSave1 = fiscalPeriodService.createFiscalPeriod(period1); + + fiscalPeriodService.deleteFiscalPeriod(periodSave1); + + List<FiscalPeriod> allFiscalPeriods = fiscalPeriodService.getAllFiscalPeriods(); + Assert.assertEquals(0, allFiscalPeriods.size()); + + } + + @Test(expected = NoEmptyFiscalPeriodException.class) + public void deleteFiscalPeriodFailNoEmptyFiscalPeriodTest() throws Exception { + + FiscalPeriod period1 = new FiscalPeriodImpl(); + Date bedingDate1 = DateUtil.createDate(01, 01, 2012); + period1.setBeginDate(bedingDate1); + Date endDate1 = DateUtil.createDate(31, 12, 2012); + period1.setEndDate(endDate1); + + FiscalPeriod periodSave1 = fiscalPeriodService.createFiscalPeriod(period1); + + createFinancialTransaction("jdv", DateUtil.createDate(04, 04, 2012), "511", "501", BigDecimal.valueOf(42.0)); + + fiscalPeriodService.deleteFiscalPeriod(periodSave1); + } + + + @Test + public void retainedEarningsAndBlockFiscalPeriod() throws Exception { + + EntryBook atNew = new EntryBookImpl(); + atNew.setCode("an"); + atNew.setCode("A nouveau"); + + atNew = entryBookService.createEntryBook(atNew); + + + FiscalPeriod period1 = new FiscalPeriodImpl(); + Date bedingDate1 = DateUtil.createDate(01, 01, 2012); + period1.setBeginDate(bedingDate1); + Date endDate1 = DateUtil.createDate(31, 12, 2012); + period1.setEndDate(endDate1); + + FiscalPeriod periodSave1 = fiscalPeriodService.createFiscalPeriod(period1); + + FiscalPeriod period2 = new FiscalPeriodImpl(); + Date bedingDate2 = DateUtil.createDate(01, 01, 2013); + period2.setBeginDate(bedingDate2); + Date endDate2 = DateUtil.createDate(31, 12, 2013); + period2.setEndDate(endDate2); + + fiscalPeriodService.createFiscalPeriod(period2); + + BigDecimal amount = BigDecimal.valueOf(42.14); + createFinancialTransaction("jdv", DateUtil.createDate(04, 04, 2012), "511", "501", amount); + + fiscalPeriodService.retainedEarningsAndBlockFiscalPeriod(periodSave1, atNew); + + + List<FiscalPeriod> allFiscalPeriods = fiscalPeriodService.getAllFiscalPeriods(); + periodSave1 = allFiscalPeriods.get(0); + FiscalPeriod periodSave2 = allFiscalPeriods.get(1); + + Assert.assertEquals(true, periodSave1.isLocked()); + List<FiscalPeriod> blockedFiscalPeriods = fiscalPeriodService.getAllBlockedFiscalPeriods(); + Assert.assertEquals(1, blockedFiscalPeriods.size()); + Assert.assertEquals(true, blockedFiscalPeriods.contains(periodSave1)); + + + List<FiscalPeriod> unblockedFiscalPeriods = fiscalPeriodService.getAllUnblockedFiscalPeriods(); + Assert.assertEquals(1, unblockedFiscalPeriods.size()); + Assert.assertEquals(true, unblockedFiscalPeriods.contains(periodSave2)); + + for (FinancialPeriod financialPeriod : financialPeriodService.getFinancialPeriods(periodSave1.getBeginDate(), periodSave1.getEndDate())) { + Assert.assertEquals(true, financialPeriod.isLocked()); + for (EntryBook entryBook : entryBookService.getAllEntryBooks()) { + ClosedPeriodicEntryBook closedPeriodicEntryBook = + financialPeriodService.getClosedPeriodicEntryBook(entryBook, financialPeriod); + + Assert.assertEquals(true, closedPeriodicEntryBook.isLocked()); + } + } + + List<FinancialTransaction> transactionsAtNew = + financialTransactionService.getAllFinancialTransactions(endDate1, DateUtil.getEndOfDay(endDate1)); + Assert.assertEquals(1, transactionsAtNew.size()); + FinancialTransaction transactionAtNew = transactionsAtNew.get(0); + Assert.assertEquals(atNew, transactionAtNew.getEntryBook()); + Assert.assertEquals(4, transactionAtNew.sizeEntry()); + Map<String, BigDecimal> amountByAccount = Maps.newHashMap(); + + for (Entry entry : transactionAtNew.getEntry()) { + BigDecimal amountAccount = amountByAccount.get(entry.getAccount().getAccountNumber()); + if (amountAccount == null) { + amountAccount = BigDecimal.ZERO; + } + if (entry.isDebit()) { + amountAccount = amountAccount.subtract(entry.getAmount()); + } else { + amountAccount = amountAccount.add(entry.getAmount()); + } + amountByAccount.put(entry.getAccount().getAccountNumber(), amountAccount); + } + + Assert.assertEquals(3, amountByAccount.size()); + Assert.assertEquals(true, amountByAccount.containsKey("501")); + Assert.assertEquals(0, amount.compareTo(amountByAccount.get("501").multiply(BigDecimal.valueOf(-1)))); + + Assert.assertEquals(true, amountByAccount.containsKey("511")); + Assert.assertEquals(0, amount.compareTo(amountByAccount.get("511"))); + + Assert.assertEquals(true, amountByAccount.containsKey("891")); + Assert.assertEquals(0, BigDecimal.ZERO.compareTo(amountByAccount.get("891"))); + + + List<FinancialTransaction> transactionsAtNew2 = + financialTransactionService.getAllFinancialTransactions(bedingDate2, DateUtil.getEndOfDay(bedingDate2)); + Assert.assertEquals(1, transactionsAtNew2.size()); + FinancialTransaction transactionAtNew2 = transactionsAtNew2.get(0); + Assert.assertEquals(atNew, transactionAtNew2.getEntryBook()); + Assert.assertEquals(4, transactionAtNew2.sizeEntry()); + amountByAccount.clear(); + + for (Entry entry : transactionAtNew2.getEntry()) { + BigDecimal amountAccount = amountByAccount.get(entry.getAccount().getAccountNumber()); + if (amountAccount == null) { + amountAccount = BigDecimal.ZERO; + } + if (entry.isDebit()) { + amountAccount = amountAccount.subtract(entry.getAmount()); + } else { + amountAccount = amountAccount.add(entry.getAmount()); + } + amountByAccount.put(entry.getAccount().getAccountNumber(), amountAccount); } - try { - fiscalPeriodService.blockFiscalPeriod(recentFiscalPeriod); - } catch (Exception ex){ - log.debug("Error test block Period", ex); - Assert.assertEquals(LimaBusinessException.class, ex.getClass()); - }*/ + + Assert.assertEquals(3, amountByAccount.size()); + Assert.assertEquals(true, amountByAccount.containsKey("501")); + Assert.assertEquals(0, amount.compareTo(amountByAccount.get("501"))); + + Assert.assertEquals(true, amountByAccount.containsKey("511")); + Assert.assertEquals(0, amount.compareTo(amountByAccount.get("511").multiply(BigDecimal.valueOf(-1)))); + + Assert.assertEquals(true, amountByAccount.containsKey("891")); + Assert.assertEquals(0, BigDecimal.ZERO.compareTo(amountByAccount.get("891"))); + } + + @Test + public void isRetainedEarningsTest() throws Exception { + + Account accountAchat = new AccountImpl(); + accountAchat.setAccountNumber("60111"); + accountAchat.setLabel("achat"); + accountService.createAccount(accountAchat); + + Account accountPrestation = new AccountImpl(); + accountPrestation.setAccountNumber("70611"); + accountPrestation.setLabel("prestation"); + accountService.createAccount(accountPrestation); + + FiscalPeriod period1 = new FiscalPeriodImpl(); + Date bedingDate1 = DateUtil.createDate(01, 01, 2012); + period1.setBeginDate(bedingDate1); + Date endDate1 = DateUtil.createDate(31, 12, 2012); + period1.setEndDate(endDate1); + + FiscalPeriod periodSave1 = fiscalPeriodService.createFiscalPeriod(period1); + + Assert.assertEquals(false, fiscalPeriodService.isRetainedEarnings(periodSave1)); + + BigDecimal amount = BigDecimal.valueOf(42.14); + createFinancialTransaction("jdv", DateUtil.createDate(04, 04, 2012), "60111", "70611", amount); + + Assert.assertEquals(false, fiscalPeriodService.isRetainedEarnings(periodSave1)); + + createFinancialTransaction("jdv", DateUtil.createDate(04, 04, 2012), "501", "511", amount); + + Assert.assertEquals(true, fiscalPeriodService.isRetainedEarnings(periodSave1)); + } /** diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java index 19f6ccd..ba31827 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java @@ -413,7 +413,7 @@ public class FiscalPeriodViewHandler implements ServiceListener { new SwingWorker<FiscalPeriod, Void>() { @Override protected FiscalPeriod doInBackground() throws Exception { - FiscalPeriod fiscalPeriodBlocked = fiscalPeriodService.retainedEarningsAndBlockFiscalPeriod(selectedFiscalPeriod, entryBook, true); + FiscalPeriod fiscalPeriodBlocked = fiscalPeriodService.retainedEarningsAndBlockFiscalPeriod(selectedFiscalPeriod, entryBook); tableModel.setValue(selectedRow, fiscalPeriodBlocked); view.setBlockEnabled(false); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.