This is an automated email from the git hooks/post-receive script. New commit to branch feature/1317-les-ecritures-de-regulations-vont-dans-le-journal-Extourne in repository lima. See https://gitlab.nuiton.org/chorem/lima.git commit 767129104f51d3c4be2c3cca6e036780c1edc3df Author: dcosse <cosse@codelutin.com> Date: Sun Feb 21 00:43:12 2016 +0100 refs #1317 Crée une transaction Extourne ou placer les écritures créer pour équilibrer un lettrage --- .../business/api/FinancialTransactionService.java | 5 ++- .../ejb/FinancialTransactionServiceImpl.java | 45 ++++++++++++++++++---- .../lima/ui/lettering/LetteringViewHandler.java | 8 ++++ 3 files changed, 48 insertions(+), 10 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 d653bc8..43eb782 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 @@ -110,13 +110,14 @@ public interface FinancialTransactionService { /** * From to selected entries, create one with same account and * difference between the amounts, and another one with - * account 658 or 758 and an amount conversely of the first created + * account 658 or 758 and entrybook Extourne + * and an amount conversely of the first created * @param firstEntrySelected first entry selected * @param secondEntrySelected second entry selected * @return table of the two new entries * */ Entry[] getEntriesFromEqualizing(Entry firstEntrySelected, Entry secondEntrySelected) - throws LockedFinancialPeriodException, LockedEntryBookException; + throws LockedFinancialPeriodException, LockedEntryBookException, AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException; /** * Retourne toutes les entrées d'une transaction 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 71f5d0d..cd0d9c2 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 @@ -33,6 +33,7 @@ import org.chorem.lima.beans.LetteringFilter; import org.chorem.lima.business.AccountingRules; import org.chorem.lima.business.LimaBusinessConfig; import org.chorem.lima.business.api.AccountService; +import org.chorem.lima.business.api.EntryBookService; import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.exceptions.AfterLastFiscalPeriodException; import org.chorem.lima.business.exceptions.BeforeFirstFiscalPeriodException; @@ -81,10 +82,17 @@ import static org.nuiton.i18n.I18n.t; @TransactionAttribute public class FinancialTransactionServiceImpl extends AbstractLimaService implements FinancialTransactionService { + protected static final Log log = LogFactory.getLog(FinancialTransactionServiceImpl.class); + public static final String EXTOURNE = "EXT"; + @EJB protected AccountService accountService; - protected static final Log log = LogFactory.getLog(FinancialTransactionServiceImpl.class); + @EJB + protected EntryBookService entryBookService; + + @EJB + protected FinancialTransactionService financialTransactionService; @Override public FinancialTransaction createNewFinancialTransaction(){ @@ -198,7 +206,7 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme @Override public Entry[] getEntriesFromEqualizing(Entry firstEntrySelected, Entry secondEntrySelected) - throws LockedFinancialPeriodException, LockedEntryBookException { + throws LockedFinancialPeriodException, LockedEntryBookException, AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException { Entry newSameAccountEntry = null; Entry newCostOrProductEntry = null; @@ -223,13 +231,15 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme Entry costOrProductEntry; /*Set result in the amount of the new entries*/ + FinancialTransaction newFinancialTransaction = createNewExtourneFinantialTransaction(firstEntrySelected, secondEntrySelected); + if (firstEntryDebitSubtract.compareTo(BigDecimal.ZERO) != 0) { - sameAccountEntry = copyEntryWithoutAmount(firstEntrySelected); - costOrProductEntry = copyEntryWithoutAmount(firstEntrySelected); + sameAccountEntry = copyEntryWithoutAmount(firstEntrySelected, newFinancialTransaction); + costOrProductEntry = copyEntryWithoutAmount(firstEntrySelected, newFinancialTransaction); amountsCalculation(firstEntryDebitSubtract, sameAccountEntry, costOrProductEntry); } else { - sameAccountEntry = copyEntryWithoutAmount(secondEntrySelected); - costOrProductEntry = copyEntryWithoutAmount(secondEntrySelected); + sameAccountEntry = copyEntryWithoutAmount(secondEntrySelected, newFinancialTransaction); + costOrProductEntry = copyEntryWithoutAmount(secondEntrySelected, newFinancialTransaction); amountsCalculation(secondEntryDebitSubtract, sameAccountEntry, costOrProductEntry); } @@ -252,6 +262,21 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme return entries; } + protected FinancialTransaction createNewExtourneFinantialTransaction(Entry firstEntrySelected, Entry secondEntrySelected) throws AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException, LockedFinancialPeriodException, LockedEntryBookException { + FinancialTransaction newFinancialTransaction = financialTransactionService.createNewFinancialTransaction(); + EntryBook entryBook = entryBookService.getEntryBookByCode(EXTOURNE); + if (entryBook == null) { + entryBook = firstEntrySelected.getFinancialTransaction().getEntryBook(); + } + newFinancialTransaction.setEntryBook(entryBook); + + Date lastTransactionDate = secondEntrySelected.getFinancialTransaction().getTransactionDate().after(firstEntrySelected.getFinancialTransaction().getTransactionDate()) ? + secondEntrySelected.getFinancialTransaction().getTransactionDate() : firstEntrySelected.getFinancialTransaction().getTransactionDate(); + newFinancialTransaction.setTransactionDate(lastTransactionDate); + newFinancialTransaction = financialTransactionService.createFinancialTransaction(newFinancialTransaction); + return newFinancialTransaction; + } + /**Debit and credit calculation for one entry, with its amount * @param entry Entry for calculation * @return table of two big decimal, representing respectively debit and credit @@ -270,13 +295,14 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme } /**Copy parametrised entry, without amount*/ - protected Entry copyEntryWithoutAmount(Entry entryToCopy) { + protected Entry copyEntryWithoutAmount(Entry entryToCopy, FinancialTransaction newFinancialTransaction) { Entry copiedEntry = new EntryImpl(); + newFinancialTransaction.addEntry(copiedEntry); + copiedEntry.setFinancialTransaction(newFinancialTransaction); copiedEntry.setAccount(entryToCopy.getAccount()); copiedEntry.setDescription(entryToCopy.getDescription()); copiedEntry.setDetail(entryToCopy.getDetail()); - copiedEntry.setFinancialTransaction(entryToCopy.getFinancialTransaction()); copiedEntry.setVoucher(entryToCopy.getVoucher()); return copiedEntry; @@ -561,6 +587,9 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); Entry newEntry = entryTopiaDao.create(entry); + if (log.isDebugEnabled()) { + log.debug("Nex "); + } return newEntry; } diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java index bfb9238..5c2df81 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java @@ -37,6 +37,8 @@ import org.chorem.lima.business.api.EntryBookService; 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.exceptions.AfterLastFiscalPeriodException; +import org.chorem.lima.business.exceptions.BeforeFirstFiscalPeriodException; import org.chorem.lima.business.exceptions.LockedEntryBookException; import org.chorem.lima.business.exceptions.LockedFinancialPeriodException; import org.chorem.lima.business.exceptions.UnbalancedEntriesException; @@ -498,6 +500,12 @@ public class LetteringViewHandler{ e.getClosedPeriodicEntryBook().getEntryBook().getLabel(), e.getClosedPeriodicEntryBook().getFinancialPeriod().getBeginDate(), e.getClosedPeriodicEntryBook().getFinancialPeriod().getEndDate())); + } catch (AfterLastFiscalPeriodException e) { + errorHelper.showErrorMessage(t("lima.entries.add.entry.error.afterLastFiscalPeriod", + e.getDate())); + } catch (BeforeFirstFiscalPeriodException e) { + errorHelper.showErrorMessage(t("lima.entries.add.entry.error.beforeFirstFiscalPeriod", + e.getDate())); } } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.