r3840 - in trunk: lima-business/src/main/java/org/chorem/lima/business lima-business/src/main/java/org/chorem/lima/business/accountingrules lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/main/resources/i18n lima-business/src/test/java/org/chorem/lima/entity lima-business-api/src/main/java/org/chorem/lima/business lima-business-api/src/main/java/org/chorem/lima/business/api lima-callao/src/main/java/org/chorem/lima/entity lima-swing/src/main/java/org/chorem/lima/ui/
Author: sbavencoff Date: 2014-07-09 15:13:18 +0200 (Wed, 09 Jul 2014) New Revision: 3840 Url: http://forge.chorem.org/projects/lima/repository/revisions/3840 Log: refs #557 : fix exception when lock periodic entry book Added: trunk/lima-business-api/src/main/java/org/chorem/lima/business/ClosedPeriodicEntryBooksException.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/EntriesException.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/FinancialTransactionsException.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/NotLockedClosedPeriodicEntryBooksException.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/UnbalancedFinancialTransactionsException.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/UnfilledEntriesException.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/WithoutEntryBookFinancialTransactionsException.java Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodService.java trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties trunk/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionTopiaDao.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -25,7 +25,6 @@ package org.chorem.lima.business; -import org.chorem.lima.business.utils.ClosedPeriodicEntryBookException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.Entry; @@ -97,7 +96,11 @@ * Check if a financial period can be closed. * * @param closedPeriodicEntryBook - * @throws LimaException + * @throws UnfilledEntriesException, WithoutEntryBookFinancialTransactionsException, UnbalancedFinancialTransactionsException, NotLockedClosedPeriodicEntryBooksException */ - void blockClosedPeriodicEntryBookRules(ClosedPeriodicEntryBook closedPeriodicEntryBook) throws ClosedPeriodicEntryBookException; + void blockClosedPeriodicEntryBookRules(ClosedPeriodicEntryBook closedPeriodicEntryBook) + throws UnfilledEntriesException, + WithoutEntryBookFinancialTransactionsException, + UnbalancedFinancialTransactionsException, + NotLockedClosedPeriodicEntryBooksException; } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -29,14 +29,17 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.AccountingRules; -import org.chorem.lima.business.LockedEntryBookException; import org.chorem.lima.business.FinancialTransactionException; import org.chorem.lima.business.FiscalPeriodException; import org.chorem.lima.business.InvalidAccountNumberException; import org.chorem.lima.business.LimaInterceptor; +import org.chorem.lima.business.LockedEntryBookException; +import org.chorem.lima.business.NotLockedClosedPeriodicEntryBooksException; +import org.chorem.lima.business.UnbalancedFinancialTransactionsException; +import org.chorem.lima.business.UnfilledEntriesException; import org.chorem.lima.business.UsedAccountException; import org.chorem.lima.business.UsedEntryBookException; -import org.chorem.lima.business.utils.ClosedPeriodicEntryBookException; +import org.chorem.lima.business.WithoutEntryBookFinancialTransactionsException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.ClosedPeriodicEntryBookTopiaDao; @@ -199,7 +202,7 @@ */ @Override public void blockClosedPeriodicEntryBookRules(ClosedPeriodicEntryBook closedPeriodicEntryBook) - throws ClosedPeriodicEntryBookException { + throws UnbalancedFinancialTransactionsException, UnfilledEntriesException, WithoutEntryBookFinancialTransactionsException, NotLockedClosedPeriodicEntryBooksException { FinancialTransactionTopiaDao financialTransactionTopiaDao = getDaoHelper().getFinancialTransactionDao(); EntryTopiaDao entryDao = getDaoHelper().getEntryDao(); @@ -209,26 +212,29 @@ // Check if all financial transactions of closedperiodicentrybook are equilibrate FinancialPeriod period = closedPeriodicEntryBook.getFinancialPeriod(); - if (financialTransactionTopiaDao.isExistUnbalancedTransaction( + List<FinancialTransaction> allUnbalancedTransaction = financialTransactionTopiaDao.getAllUnbalancedTransaction( period.getBeginDate(), period.getEndDate(), - closedPeriodicEntryBook.getEntryBook())) { - throw new ClosedPeriodicEntryBookException(closedPeriodicEntryBook, "lima-business.defaultaccountingrules.blockerrorequillibrate"); + closedPeriodicEntryBook.getEntryBook()); + if (!allUnbalancedTransaction.isEmpty()) { + throw new UnbalancedFinancialTransactionsException(allUnbalancedTransaction); } // Check if all financial transactions of this closedperiodicentrybook/financialPeriod are well filled in - if (entryDao.isExistUnfilledEntry( + List<Entry> allUnfilledEntry = entryDao.findAllUnfilledEntry( period.getBeginDate(), period.getEndDate(), - closedPeriodicEntryBook.getEntryBook())) { - throw new ClosedPeriodicEntryBookException(closedPeriodicEntryBook, "lima-business.defaultaccountingrules.missingelements"); + closedPeriodicEntryBook.getEntryBook()); + if (!allUnfilledEntry.isEmpty()) { + throw new UnfilledEntriesException(allUnfilledEntry); } // Check if all financial transactions have EntryBooks - if (financialTransactionTopiaDao.isExistTransactionWithoutEntryBook( + List<FinancialTransaction> allTransactionWithoutEntryBook = financialTransactionTopiaDao.findAllTransactionWithoutEntryBook( period.getBeginDate(), - period.getEndDate())) { - throw new ClosedPeriodicEntryBookException(closedPeriodicEntryBook, "lima-business.defaultaccountingrules.missingentrybook"); + period.getEndDate()); + if (!allTransactionWithoutEntryBook.isEmpty()) { + throw new WithoutEntryBookFinancialTransactionsException(allTransactionWithoutEntryBook); } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -31,7 +31,10 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.FiscalPeriodException; import org.chorem.lima.business.InvalidAccountNumberException; -import org.chorem.lima.business.utils.ClosedPeriodicEntryBookException; +import org.chorem.lima.business.NotLockedClosedPeriodicEntryBooksException; +import org.chorem.lima.business.UnbalancedFinancialTransactionsException; +import org.chorem.lima.business.UnfilledEntriesException; +import org.chorem.lima.business.WithoutEntryBookFinancialTransactionsException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.ClosedPeriodicEntryBookTopiaDao; @@ -204,17 +207,20 @@ * Check if all previous financial period for a an entrybook are closed before bock the asked closedperiodicentrybook */ @Override - public void blockClosedPeriodicEntryBookRules(ClosedPeriodicEntryBook closedPeriodicEntryBook) throws ClosedPeriodicEntryBookException { + public void blockClosedPeriodicEntryBookRules(ClosedPeriodicEntryBook closedPeriodicEntryBook) + throws UnbalancedFinancialTransactionsException, WithoutEntryBookFinancialTransactionsException, + UnfilledEntriesException, NotLockedClosedPeriodicEntryBooksException { + super.blockClosedPeriodicEntryBookRules(closedPeriodicEntryBook); ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookDao = getDaoHelper().getClosedPeriodicEntryBookDao(); - boolean existPrevousNotClosed = closedPeriodicEntryBookDao - .existPreviousClosedPeriodicEntryBooksNotClosed(closedPeriodicEntryBook); + List<ClosedPeriodicEntryBook> allPreviousClosedPeriodicEntryBooksNotLocked = + closedPeriodicEntryBookDao.findAllPreviousClosedPeriodicEntryBooksNotLocked(closedPeriodicEntryBook); //Check if the fiscal period to block is the oldest - if (existPrevousNotClosed) { - throw new ClosedPeriodicEntryBookException(closedPeriodicEntryBook, "lima-business.franceaccountingrules.antefinancialperiodnotblockedentrybook"); + if (!allPreviousClosedPeriodicEntryBooksNotLocked.isEmpty()) { + throw new NotLockedClosedPeriodicEntryBooksException(allPreviousClosedPeriodicEntryBooksNotLocked); } } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -27,8 +27,11 @@ import org.chorem.lima.business.AccountingRules; import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.business.NotLockedClosedPeriodicEntryBooksException; +import org.chorem.lima.business.UnbalancedFinancialTransactionsException; +import org.chorem.lima.business.UnfilledEntriesException; +import org.chorem.lima.business.WithoutEntryBookFinancialTransactionsException; import org.chorem.lima.business.api.FinancialPeriodService; -import org.chorem.lima.business.utils.ClosedPeriodicEntryBookException; import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.ClosedPeriodicEntryBookTopiaDao; import org.chorem.lima.entity.EntryBook; @@ -91,7 +94,7 @@ } @Override - public ClosedPeriodicEntryBook blockClosedPeriodicEntryBook(ClosedPeriodicEntryBook closedPeriodicEntryBook) throws ClosedPeriodicEntryBookException { + public ClosedPeriodicEntryBook blockClosedPeriodicEntryBook(ClosedPeriodicEntryBook closedPeriodicEntryBook) throws UnbalancedFinancialTransactionsException, UnfilledEntriesException, WithoutEntryBookFinancialTransactionsException, NotLockedClosedPeriodicEntryBooksException { AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); ClosedPeriodicEntryBook result; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -55,6 +55,10 @@ import org.chorem.lima.business.FiscalPeriodException; import org.chorem.lima.business.ImportEbpException; import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.business.NotLockedClosedPeriodicEntryBooksException; +import org.chorem.lima.business.UnbalancedFinancialTransactionsException; +import org.chorem.lima.business.UnfilledEntriesException; +import org.chorem.lima.business.WithoutEntryBookFinancialTransactionsException; import org.chorem.lima.business.api.AccountService; import org.chorem.lima.business.api.ClosedPeriodicEntryBookService; import org.chorem.lima.business.api.EntryBookService; @@ -66,7 +70,6 @@ import org.chorem.lima.business.api.IdentityService; import org.chorem.lima.business.api.ImportService; import org.chorem.lima.business.api.VatStatementService; -import org.chorem.lima.business.utils.ClosedPeriodicEntryBookException; import org.chorem.lima.business.utils.DocumentsEnum; import org.chorem.lima.business.utils.EntryEBPComparator; import org.chorem.lima.business.utils.FiscalPeriodComparator; @@ -1262,8 +1265,14 @@ beginDateFinancialPeriod, endDateFinancialPeriod, codeEntryBook)); } catch (ParseException e) { result.append(t("lima-business.common.failed", e.getMessage())); - } catch (ClosedPeriodicEntryBookException e) { - result.append(t("lima-business.common.failed", e.getMessage())); + } catch (UnbalancedFinancialTransactionsException e) { + result.append(t("lima-business.common.failed", t("lima-business.import.closedPeriodicEntryBook.error.unbalanced"))); + } catch (UnfilledEntriesException e) { + result.append(t("lima-business.common.failed", t("lima-business.import.closedPeriodicEntryBook.error.unfilled"))); + } catch (WithoutEntryBookFinancialTransactionsException e) { + result.append(t("lima-business.common.failed", t("lima-business.import.closedPeriodicEntryBook.error.withoutEntryBook"))); + } catch (NotLockedClosedPeriodicEntryBooksException e) { + result.append(t("lima-business.common.failed", t("lima-business.import.closedPeriodicEntryBook.error.NotLockedPreviousEntryBook"))); } } Modified: trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2014-07-09 13:13:18 UTC (rev 3840) @@ -5,7 +5,6 @@ lima-business.account.accountalreardyexist=Un compte existe déjà avec ce numéro \: %s lima-business.common.failed=Échec \: %s \n lima-business.defaultaccountingrules.allentrybookclosed=Tous les journaux de cette période financière sont fermés -lima-business.defaultaccountingrules.blockerrorequillibrate=Impossible de bloquer la période financière / le journal, il contient des transactions non équilibrées lima-business.defaultaccountingrules.dateaftererror=La date est postérieure à la période fiscale lima-business.defaultaccountingrules.datebeforeerror=La date est antérieure à la période fiscale lima-business.defaultaccountingrules.deleteaccounterror=Impossible de supprimer un comte contenant des entrées @@ -15,8 +14,6 @@ lima-business.defaultaccountingrules.financialperiodblocked=La période financière est bloquée lima-business.defaultaccountingrules.financialtransactionblocked=La période financière de cette transaction est bloquée lima-business.defaultaccountingrules.invalidaccountnumber=Numéro de compte invalide \: %d -lima-business.defaultaccountingrules.missingelements=Impossible de bloquer la période financière / il manque des éléments dans des transactions -lima-business.defaultaccountingrules.missingentrybook=Impossible de bloquer la période financière / il manque un journal dans une transaction (%1$te/%1$tm/%1$tY) lima-business.document.account=Compte lima-business.document.accountnumber=N° Compte lima-business.document.accounts=Comptes @@ -81,13 +78,16 @@ lima-business.fiscalperiod.previousfiscalperiodalreadyblocked=La dernière période financière de la période fiscale est bloquée lima-business.franceaccountingrules.accountnumbernotnumeric=Le numéro de compte n'est pas numérique \: %s lima-business.franceaccountingrules.accountstartnumbererror=Le numéro du compte général n'est pas compris entre 1 et 8 \: %s -lima-business.franceaccountingrules.antefinancialperiodnotblockedentrybook=Les périodes financières précédentes pour ce journal doivent être bloquées avant lima-business.franceaccountingrules.antefiscalperiodnotblocked=Le nombre maximal d'exercices ouverts est déjà ateint lima-business.franceaccountingrules.fiscalperiodnotempty=La période fiscale à supprimer n'est pas vide \! lima-business.franceaccountingrules.lastFiscalPeriodCantBlocked=Impossible de clore la dernière période fiscale ouverte lima-business.franceaccountingrules.newfiscalperiodadjoiningerror=La nouvelle période fiscale doit suivre la précédente lima-business.import.accountadded=Succès \: Compte %s - %s ajouté\n lima-business.import.accountalreadyexist=Échec \: Le compte %s existe déjà \n +lima-business.import.closedPeriodicEntryBook.error.NotLockedPreviousEntryBook=Les périodes financières précédentes pour ce journal doivent être bloquées avant +lima-business.import.closedPeriodicEntryBook.error.unbalanced=Impossible de bloquer la période financière / le journal, il contient des transactions non équilibrées +lima-business.import.closedPeriodicEntryBook.error.unfilled=Impossible de bloquer la période financière / il manque des éléments dans des transactions +lima-business.import.closedPeriodicEntryBook.error.withoutEntryBook=Impossible de bloquer la période financière / il manque un journal dans une transaction (%1$te/%1$tm/%1$tY) lima-business.import.closedperiodicentrybookupdated=Succès \: La période financière %s - %s - %s est ajoutée \! \n lima-business.import.ebpmissingaccount=Échec \: Compte %s inexistant. \nImportation annulée. \nCréer tous les comptes avant d'importer les écritures. lima-business.import.ebpnoentry=Échec \: Ce fichier ne contient aucune entrée. Modified: trunk/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -62,9 +62,9 @@ LimaCallaoTopiaPersistenceContext tcontext = context.newPersistenceContext(); FinancialTransactionTopiaDao ftDAO = tcontext.getFinancialTransactionDao(); - Assert.assertFalse(ftDAO.isExistUnbalancedTransaction( + Assert.assertTrue(ftDAO.getAllUnbalancedTransaction( financialPeriod.getBeginDate(), financialPeriod.getEndDate(), - journalDesVentes)); + journalDesVentes).isEmpty()); } } Added: trunk/lima-business-api/src/main/java/org/chorem/lima/business/ClosedPeriodicEntryBooksException.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/ClosedPeriodicEntryBooksException.java (rev 0) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/ClosedPeriodicEntryBooksException.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -0,0 +1,27 @@ +package org.chorem.lima.business; + +import org.chorem.lima.entity.ClosedPeriodicEntryBook; + +import java.util.Collection; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public abstract class ClosedPeriodicEntryBooksException extends LimaException { + + protected Collection<ClosedPeriodicEntryBook> closedPeriodicEntryBooks; + + public ClosedPeriodicEntryBooksException(Collection<ClosedPeriodicEntryBook> closedPeriodicEntryBooks) { + super(""); + this.closedPeriodicEntryBooks = closedPeriodicEntryBooks; + } + + public ClosedPeriodicEntryBooksException(Collection<ClosedPeriodicEntryBook> closedPeriodicEntryBooks, Throwable cause) { + super("", cause); + this.closedPeriodicEntryBooks = closedPeriodicEntryBooks; + } + + public Collection<ClosedPeriodicEntryBook> getClosedPeriodicEntryBooks() { + return closedPeriodicEntryBooks; + } +} Added: trunk/lima-business-api/src/main/java/org/chorem/lima/business/EntriesException.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/EntriesException.java (rev 0) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/EntriesException.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -0,0 +1,27 @@ +package org.chorem.lima.business; + +import org.chorem.lima.entity.Entry; + +import java.util.Collection; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class EntriesException extends LimaException { + + protected Collection<Entry> entries; + + public EntriesException(Collection<Entry> entries) { + super(""); + this.entries = entries; + } + + public EntriesException(Collection<Entry> entries, Throwable cause) { + super("", cause); + this.entries = entries; + } + + public Collection<Entry> getEntries() { + return entries; + } +} Added: trunk/lima-business-api/src/main/java/org/chorem/lima/business/FinancialTransactionsException.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/FinancialTransactionsException.java (rev 0) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/FinancialTransactionsException.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -0,0 +1,27 @@ +package org.chorem.lima.business; + +import org.chorem.lima.entity.FinancialTransaction; + +import java.util.Collection; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public abstract class FinancialTransactionsException extends LimaException { + + protected Collection<FinancialTransaction> financialTransactions; + + public FinancialTransactionsException(Collection<FinancialTransaction> financialTransactions) { + super(""); + this.financialTransactions = financialTransactions; + } + + public FinancialTransactionsException(Collection<FinancialTransaction> financialTransactions, Throwable cause) { + super("", cause); + this.financialTransactions = financialTransactions; + } + + public Collection<FinancialTransaction> getFinancialTransactions() { + return financialTransactions; + } +} Added: trunk/lima-business-api/src/main/java/org/chorem/lima/business/NotLockedClosedPeriodicEntryBooksException.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/NotLockedClosedPeriodicEntryBooksException.java (rev 0) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/NotLockedClosedPeriodicEntryBooksException.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -0,0 +1,18 @@ +package org.chorem.lima.business; + +import org.chorem.lima.entity.ClosedPeriodicEntryBook; + +import java.util.Collection; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class NotLockedClosedPeriodicEntryBooksException extends ClosedPeriodicEntryBooksException { + public NotLockedClosedPeriodicEntryBooksException(Collection<ClosedPeriodicEntryBook> closedPeriodicEntryBooks) { + super(closedPeriodicEntryBooks); + } + + public NotLockedClosedPeriodicEntryBooksException(Collection<ClosedPeriodicEntryBook> closedPeriodicEntryBooks, Throwable cause) { + super(closedPeriodicEntryBooks, cause); + } +} Added: trunk/lima-business-api/src/main/java/org/chorem/lima/business/UnbalancedFinancialTransactionsException.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/UnbalancedFinancialTransactionsException.java (rev 0) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/UnbalancedFinancialTransactionsException.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -0,0 +1,19 @@ +package org.chorem.lima.business; + +import org.chorem.lima.entity.FinancialTransaction; + +import java.util.Collection; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class UnbalancedFinancialTransactionsException extends FinancialTransactionsException { + + public UnbalancedFinancialTransactionsException(Collection<FinancialTransaction> financialTransactions) { + super(financialTransactions); + } + + public UnbalancedFinancialTransactionsException(Collection<FinancialTransaction> financialTransactions, Throwable cause) { + super(financialTransactions, cause); + } +} Added: trunk/lima-business-api/src/main/java/org/chorem/lima/business/UnfilledEntriesException.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/UnfilledEntriesException.java (rev 0) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/UnfilledEntriesException.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -0,0 +1,18 @@ +package org.chorem.lima.business; + +import org.chorem.lima.entity.Entry; + +import java.util.Collection; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class UnfilledEntriesException extends EntriesException { + public UnfilledEntriesException(Collection<Entry> entries) { + super(entries); + } + + public UnfilledEntriesException(Collection<Entry> entries, Throwable cause) { + super(entries, cause); + } +} Added: trunk/lima-business-api/src/main/java/org/chorem/lima/business/WithoutEntryBookFinancialTransactionsException.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/WithoutEntryBookFinancialTransactionsException.java (rev 0) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/WithoutEntryBookFinancialTransactionsException.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -0,0 +1,18 @@ +package org.chorem.lima.business; + +import org.chorem.lima.entity.FinancialTransaction; + +import java.util.Collection; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class WithoutEntryBookFinancialTransactionsException extends FinancialTransactionsException { + public WithoutEntryBookFinancialTransactionsException(Collection<FinancialTransaction> financialTransactions) { + super(financialTransactions); + } + + public WithoutEntryBookFinancialTransactionsException(Collection<FinancialTransaction> financialTransactions, Throwable cause) { + super(financialTransactions, cause); + } +} Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodService.java 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodService.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -25,7 +25,10 @@ package org.chorem.lima.business.api; -import org.chorem.lima.business.utils.ClosedPeriodicEntryBookException; +import org.chorem.lima.business.NotLockedClosedPeriodicEntryBooksException; +import org.chorem.lima.business.UnbalancedFinancialTransactionsException; +import org.chorem.lima.business.UnfilledEntriesException; +import org.chorem.lima.business.WithoutEntryBookFinancialTransactionsException; import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialPeriod; @@ -52,7 +55,11 @@ List<ClosedPeriodicEntryBook> getAllClosedPeriodicEntryBooksFromUnblockedFiscalPeriod(); - ClosedPeriodicEntryBook blockClosedPeriodicEntryBook(ClosedPeriodicEntryBook closedPeriodicEntryBook) throws ClosedPeriodicEntryBookException; + ClosedPeriodicEntryBook blockClosedPeriodicEntryBook(ClosedPeriodicEntryBook closedPeriodicEntryBook) + throws UnbalancedFinancialTransactionsException, + UnfilledEntriesException, + WithoutEntryBookFinancialTransactionsException, + NotLockedClosedPeriodicEntryBooksException; List<FinancialPeriod> getAllFinancialPeriods(); Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookTopiaDao.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookTopiaDao.java 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookTopiaDao.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -166,11 +166,11 @@ } /** - * if exist previous ClosedPeriodicEntryBook not close + * find all previous ClosedPeriodicEntryBook not close * - * @return exist previous ClosedPeriodicEntryBook not close + * @return previous ClosedPeriodicEntryBook not close */ - public boolean existPreviousClosedPeriodicEntryBooksNotClosed(ClosedPeriodicEntryBook closedPeriodicEntryBook) { + public List<ClosedPeriodicEntryBook> findAllPreviousClosedPeriodicEntryBooksNotLocked(ClosedPeriodicEntryBook closedPeriodicEntryBook) { HqlAndParametersBuilder<ClosedPeriodicEntryBook> builder = newHqlAndParametersBuilder(); builder.addEquals(ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, closedPeriodicEntryBook.getEntryBook()); builder.addEquals(ClosedPeriodicEntryBook.PROPERTY_LOCKED, false); @@ -178,9 +178,8 @@ ClosedPeriodicEntryBook.PROPERTY_FINANCIAL_PERIOD + "." + FinancialPeriod.PROPERTY_END_DATE, closedPeriodicEntryBook.getFinancialPeriod().getBeginDate()); - boolean exist = exists(builder.getHql(), builder.getHqlParameters()); - - return exist; + List<ClosedPeriodicEntryBook> closedPeriodicEntryBooks = findAll(builder.getHql(), builder.getHqlParameters()); + return closedPeriodicEntryBooks; } } Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -259,14 +259,14 @@ } /** - * if exist entry where some field are not filled in. + * gat all entries where some field are not filled in. * * @param beginDate begin date * @param endDate end date * @param entryBook entry book - * @return has entry where some field are not filled in + * @return all entries where some field are not filled in */ - public boolean isExistUnfilledEntry(Date beginDate, Date endDate, EntryBook entryBook) { + public List<Entry> findAllUnfilledEntry(Date beginDate, Date endDate, EntryBook entryBook) { HqlAndParametersBuilder<Entry> builder = newHqlAndParametersBuilder(); builder.addEquals(PROPERTY_ENTRY_BOOK, entryBook); @@ -278,9 +278,9 @@ "OR " + Entry.PROPERTY_DESCRIPTION + " = null " + "OR " + Entry.PROPERTY_DESCRIPTION + " = ''" ); - boolean exists = exists(builder.getHql(), builder.getHqlParameters()); + List<Entry> entries = findAll(builder.getHql(), builder.getHqlParameters()); - return exists; + return entries; } } Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionTopiaDao.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionTopiaDao.java 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionTopiaDao.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -110,14 +110,14 @@ } /** - * Find if has unbalanced transactions. + * Find all unbalanced transactions. * * @param beginDate beginDate * @param endDate endDate * @param entryBook entry book (can be null) * @return if exist unbalanced transactions */ - public boolean isExistUnbalancedTransaction(Date beginDate, Date endDate, + public List<FinancialTransaction> getAllUnbalancedTransaction(Date beginDate, Date endDate, EntryBook entryBook) { HqlAndParametersBuilder<FinancialTransaction> builder = newHqlAndParametersBuilder(); @@ -128,17 +128,17 @@ } builder.addWhereClause(getBalancedClause(builder.getAlias(), false)); builder.setOrderByArguments(FinancialTransaction.PROPERTY_TRANSACTION_DATE, FinancialTransaction.PROPERTY_TOPIA_CREATE_DATE); - boolean exists = exists(builder.getHql(), builder.getHqlParameters()); - return exists; + List<FinancialTransaction> transactions = findAll(builder.getHql(), builder.getHqlParameters()); + return transactions; } /** - * Find all unbalanced transactions. + * Find all balanced transactions. * * @param beginDate beginDate * @param endDate endDate * @param entryBook entry book (can be null) - * @return unbalanced transactions + * @return balanced transactions */ public List<FinancialTransaction> getAllBalancedTransaction(Date beginDate, Date endDate, EntryBook entryBook) { @@ -197,21 +197,22 @@ } /** - * if exist transaction without entry book. + * find all transactions without entry book. * * @param beginDate begin date * @param endDate end date - * @return exist transaction without entry books + * @return transactions without entry books */ - public boolean isExistTransactionWithoutEntryBook(Date beginDate, Date endDate) { + public List<FinancialTransaction> findAllTransactionWithoutEntryBook(Date beginDate, Date endDate) { HqlAndParametersBuilder<FinancialTransaction> builder = newHqlAndParametersBuilder(); builder.addGreaterOrEquals(FinancialTransaction.PROPERTY_TRANSACTION_DATE, beginDate); builder.addLowerOrEquals(FinancialTransaction.PROPERTY_TRANSACTION_DATE, endDate); builder.addNull(FinancialTransaction.PROPERTY_ENTRY_BOOK); - boolean exists = exists(builder.getHql(), builder.getHqlParameters()); - return exists; + List<FinancialTransaction> transactions = findAll(builder.getHql(), builder.getHqlParameters()); + return transactions; + } /** Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellRenderer.java 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellRenderer.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -37,6 +37,32 @@ private static final long serialVersionUID = -2499433026151065390L; + public static String format(BigDecimal value) { + + LimaConfig config = LimaContext.getContext().getConfig(); + String scale = ""; + for (int i = 0; i < config.getScale(); i++) { + scale += "0"; + } + String currency = ""; + if (config.getCurrency()) { + currency = " ¤"; + } + DecimalFormat formatter = new DecimalFormat("##0." + scale + currency); + DecimalFormatSymbols symbol = new DecimalFormatSymbols(); + //set decimalSeparator and thousandSeparator preferences + symbol.setDecimalSeparator(config.getDecimalSeparator()); + symbol.setMonetaryDecimalSeparator(config.getDecimalSeparator()); + symbol.setGroupingSeparator(config.getThousandSeparator()); + formatter.setDecimalFormatSymbols(symbol); + //always set grouping + formatter.setGroupingUsed(true); + formatter.setGroupingSize(3); + String result = formatter.format(value); + return result; + } + + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { @@ -50,26 +76,7 @@ public void setValue(Object aValue) { Object result = aValue; if (aValue != null && aValue instanceof BigDecimal) { - LimaConfig config = LimaContext.getContext().getConfig(); - String scale = ""; - for (int i = 0; i < config.getScale(); i++) { - scale += "0"; - } - String currency = ""; - if (config.getCurrency()) { - currency = " ¤"; - } - DecimalFormat formatter = new DecimalFormat("##0." + scale + currency); - DecimalFormatSymbols symbol = new DecimalFormatSymbols(); - //set decimalSeparator and thousandSeparator preferences - symbol.setDecimalSeparator(config.getDecimalSeparator()); - symbol.setMonetaryDecimalSeparator(config.getDecimalSeparator()); - symbol.setGroupingSeparator(config.getThousandSeparator()); - formatter.setDecimalFormatSymbols(symbol); - //always set grouping - formatter.setGroupingUsed(true); - formatter.setGroupingSize(3); - result = formatter.format(result); + result = format((BigDecimal)result); } super.setValue(result); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java 2014-07-09 13:13:18 UTC (rev 3840) @@ -25,21 +25,33 @@ package org.chorem.lima.ui.financialperiod; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaConfig; +import org.chorem.lima.business.NotLockedClosedPeriodicEntryBooksException; import org.chorem.lima.business.ServiceListener; +import org.chorem.lima.business.UnbalancedFinancialTransactionsException; +import org.chorem.lima.business.UnfilledEntriesException; +import org.chorem.lima.business.WithoutEntryBookFinancialTransactionsException; import org.chorem.lima.business.api.FinancialPeriodService; import org.chorem.lima.business.api.FiscalPeriodService; import org.chorem.lima.business.api.ImportService; -import org.chorem.lima.business.utils.ClosedPeriodicEntryBookException; import org.chorem.lima.business.utils.FinancialPeriodComparator; import org.chorem.lima.entity.ClosedPeriodicEntryBook; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.ui.celleditor.BigDecimalTableCellRenderer; import org.chorem.lima.util.ErrorHelper; import org.jdesktop.swingx.JXTable; -import javax.swing.*; +import javax.swing.AbstractAction; +import javax.swing.ActionMap; +import javax.swing.InputMap; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.KeyStroke; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.util.Collections; @@ -124,8 +136,48 @@ try { closedPeriodicEntryBook = financialPeriodService.blockClosedPeriodicEntryBook(closedPeriodicEntryBook); model.setValue(selectedRow, closedPeriodicEntryBook); - } catch (ClosedPeriodicEntryBookException e) { - errorHelper.showErrorMessage(t(e.getMessage())); + } catch (UnbalancedFinancialTransactionsException e) { + String message = t("lima.ui.financialperiod.block.error.unbalanced.main"); + for (FinancialTransaction transaction : e.getFinancialTransactions()) { + message += "\n - " + t("lima.ui.financialperiod.block.error.unbalanced.transaction", + transaction.getTransactionDate(), + BigDecimalTableCellRenderer.format(transaction.getAmountDebit()), + BigDecimalTableCellRenderer.format(transaction.getAmountCredit())); + } + errorHelper.showErrorMessage(message); + } catch (UnfilledEntriesException e) { + String message = t("lima.ui.financialperiod.block.error.unfilled.main"); + for (Entry entry : e.getEntries()) { + message += "\n - " + t("lima.ui.financialperiod.block.error.unfilled.entry", + entry.getFinancialTransaction().getTransactionDate(), + BigDecimalTableCellRenderer.format(entry.getAmount())); + if (entry.getAccount() == null) { + message += "\n - " + t("lima.ui.financialperiod.block.error.unfilled.noAccount"); + } + if (StringUtils.isBlank(entry.getVoucher())) { + message += "\n - " + t("lima.ui.financialperiod.block.error.unfilled.noVoucher"); + } + if (StringUtils.isBlank(entry.getDescription())) { + message += "\n - " + t("lima.ui.financialperiod.block.error.unfilled.noDescription"); + } + } + errorHelper.showErrorMessage(message); + } catch (WithoutEntryBookFinancialTransactionsException e) { + String message = t("lima.ui.financialperiod.block.error.withoutEntryBook.main"); + for (FinancialTransaction transaction : e.getFinancialTransactions()) { + message += "\n - " + t("lima.ui.financialperiod.block.error.withoutEntryBook.transaction", + transaction.getTransactionDate(), + BigDecimalTableCellRenderer.format(transaction.getAmountCredit())); + } + errorHelper.showErrorMessage(message); + } catch (NotLockedClosedPeriodicEntryBooksException e) { + String message = t("lima.ui.financialperiod.block.error.noLockedPreviousEntryBook.main"); + for (ClosedPeriodicEntryBook previousClosedPeriodicEntryBook : e.getClosedPeriodicEntryBooks()) { + message += "\n - " + t("lima.ui.financialperiod.block.error.noLockedPreviousEntryBook.previousEntryBook", + previousClosedPeriodicEntryBook.getFinancialPeriod().getBeginDate(), + previousClosedPeriodicEntryBook.getFinancialPeriod().getEndDate()); + } + errorHelper.showErrorMessage(message); } } } Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2014-07-09 13:13:18 UTC (rev 3840) @@ -376,6 +376,20 @@ lima.ui.entrybook.update= lima.ui.financialperiod.begin= lima.ui.financialperiod.block= +lima.ui.financialperiod.block.error.NoLockedPreviousEntryBook.main= +lima.ui.financialperiod.block.error.entry= +lima.ui.financialperiod.block.error.noLockedPreviousEntryBook.main= +lima.ui.financialperiod.block.error.noLockedPreviousEntryBook.previousEntryBook= +lima.ui.financialperiod.block.error.unbalanced.main= +lima.ui.financialperiod.block.error.unbalanced.transaction= +lima.ui.financialperiod.block.error.unfilled.entry= +lima.ui.financialperiod.block.error.unfilled.main= +lima.ui.financialperiod.block.error.unfilled.noAccount= +lima.ui.financialperiod.block.error.unfilled.noDescription= +lima.ui.financialperiod.block.error.unfilled.noVoucher= +lima.ui.financialperiod.block.error.unfilled.noVouchier= +lima.ui.financialperiod.block.error.withoutEntryBook.main= +lima.ui.financialperiod.block.error.withoutEntryBook.transaction= lima.ui.financialperiod.blockmessage= lima.ui.financialperiod.blocktitle= lima.ui.financialperiod.closure= Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2014-07-09 09:02:03 UTC (rev 3839) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2014-07-09 13:13:18 UTC (rev 3840) @@ -358,6 +358,17 @@ lima.ui.entrybook.update=Modifier lima.ui.financialperiod.begin=Début lima.ui.financialperiod.block=Cloturer une période +lima.ui.financialperiod.block.error.noLockedPreviousEntryBook.main=Impossible de clôturer cette période car les périodes précedentes ne sont pas clôturer \: +lima.ui.financialperiod.block.error.noLockedPreviousEntryBook.previousEntryBook=période du %1$te %1$tB %1$tY au %2$te %2$tB %2$tY +lima.ui.financialperiod.block.error.unbalanced.main=Impossible de clôturer cette période car elle contient des transactions non équilibrées \: +lima.ui.financialperiod.block.error.unbalanced.transaction=transaction du %1$te/%1$tm/%1$tY d'un débit de %2$s et d'un crédit de %3$s +lima.ui.financialperiod.block.error.unfilled.entry=entré du %1$te/%1$tm/%1$tY pour un montant de %2$s \: +lima.ui.financialperiod.block.error.unfilled.main=Impossible de clôturer cette période car elle contient des entrés incomplétes \: +lima.ui.financialperiod.block.error.unfilled.noAccount=n'a pas de compte +lima.ui.financialperiod.block.error.unfilled.noDescription=n'a pas de description +lima.ui.financialperiod.block.error.unfilled.noVoucher=n'a pas de pièce comptable +lima.ui.financialperiod.block.error.withoutEntryBook.main=Impossible de clôturer cette période car elle contient des transactions sans journal +lima.ui.financialperiod.block.error.withoutEntryBook.transaction=transaction du %1$te/%1$tm/%1$tY d'un montant de %2$s, lima.ui.financialperiod.blockmessage=Êtes vous sûre de vouloir clôturer cette période ? Cette action est irréversible \! lima.ui.financialperiod.blocktitle=Clôture lima.ui.financialperiod.closure=Clôture
participants (1)
-
sbavencoff@users.chorem.org