Author: mallon Date: 2012-06-22 15:03:22 +0200 (Fri, 22 Jun 2012) New Revision: 3470 Url: http://chorem.org/repositories/revision/lima/3470 Log: Correction sur la gestion des dates des transactions : - Probl?\195?\168me sur l'enregistrement de la date mise ?\195?\160 jour par l'user (Du point de vue fonctionnelle, car du point de vue technique, reste le probl?\195?\168me de rattachement de session et d'utilisation de deux objets.) - Correction de l'interface, en ce qui concerne le changement de la liste d?\195?\169roulante des p?\195?\169riodes comptables en fonction du changement de celle des exercices. - Suppression des tests sur les entr?\195?\169es, puisque ceux-ci sont d?\195?\169j?\195?\160 effectu?\195?\169s lors de la mise ?\195?\160 jour des entr?\195?\169es. - Un utilisateur peut donc entrer n'importe quelle date de transaction, mais elle n'est pas enregistr?\195?\169e et un message avertit l'utilisateur dans deux cas : si la date est en-dehors de tout exercice, ou bien si l'exercice est bloqu?\195?\169. Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FiscalPeriodDAOImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java trunk/lima-swing/src/main/resources/log4j.properties 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 2012-06-21 14:38:23 UTC (rev 3469) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2012-06-22 13:03:22 UTC (rev 3470) @@ -290,119 +290,69 @@ /** * Check : - * 1. if old financialtransaction date are on periodblocked - * 2. if new financialtransaction date are on periodblocked - * 3. if the actual entrybook belong to a blocked closedPeriodicEntryBook - * 4. if the new entrybook belong to a blocked closedPeriodicEntryBook - * 5. if date are on fiscal period - * 6. if all closedperiod are open + * 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 LimaException { - try { - FinancialPeriodDAO financialPeriodDAO = getDaoHelper().getFinancialPeriodDAO(); - FinancialPeriod financialPeriod = financialPeriodDAO.findByDate(financialTransaction.getTransactionDate()); - FinancialPeriod financialPeriodOld = financialPeriodDAO.findByDate(financialTransactionOld.getTransactionDate()); - - //1. check old financial period locked - if (financialPeriodOld.getLocked()) { - throw new LimaBusinessException(_("lima-business.defaultaccountingrules.financialtransactionblocked")); - } - - //2. check new financial period locked - if (financialPeriod.getLocked()) { - throw new LimaBusinessException(_("lima-business.defaultaccountingrules.financialnewdateblocked")); - } - - ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = getDaoHelper().getClosedPeriodicEntryBookDAO(); - - //3. the actual entrybook belong to a blocked closedPeriodicEntryBook - ClosedPeriodicEntryBook closedPeriodicEntryBookOld = - closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod( - financialTransactionOld.getEntryBook(), financialPeriod); - if (closedPeriodicEntryBookOld.getLocked()) { - throw new LimaBusinessException(_("lima-Business.defaultaccountingrules.updateentryerror")); - } - - //4. the new entrybook belong to a blocked closedPeriodicEntryBook - ClosedPeriodicEntryBook closedPeriodicEntryBook = - closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod( - financialTransaction.getEntryBook(), financialPeriod); - if (closedPeriodicEntryBook.getLocked()) { - throw new LimaBusinessException(_("lima-Business.defaultaccountingrules.updatenewentryerror")); - } - - //5. the actual entrybook belong to a blocked closedPeriodicEntryBook - ClosedPeriodicEntryBook closedPeriodicEntryBookOld2 = - closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod( - financialTransactionOld.getEntryBook(), financialPeriodOld); - if (closedPeriodicEntryBookOld2.getLocked()) { - throw new LimaBusinessException(_("lima-Business.defaultaccountingrules.updatefinancialtransactionperioderror")); - } - - //6. the new entrybook belong to a blocked closedPeriodicEntryBook - ClosedPeriodicEntryBook closedPeriodicEntryBook2 = - closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod( - financialTransaction.getEntryBook(), financialPeriodOld); - if (closedPeriodicEntryBook2.getLocked()) { - throw new LimaBusinessException(_("lima-Business.defaultaccountingrules.updatefinancialtransactionnewperioderror")); - } - - - //7. check if date are on fiscal period + try { + + Date financialTransactionDate = financialTransaction.getTransactionDate(); FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); - - //search fiscalperiod have financialperiod in params - FiscalPeriod fiscalPeriod = fiscalPeriodDAO.findByFinancialPeriod(financialPeriod); - - Date beginDateFiscalPeriod = fiscalPeriod.getBeginDate(); - Date endDateFiscalPeriod = fiscalPeriod.getEndDate(); - Date financialTransactionDate = - financialTransaction.getTransactionDate(); - if (financialTransactionDate.before(beginDateFiscalPeriod)) { - throw new LimaBusinessException(_("lima-business.defaultaccountingrules.datebeforeerror")); - } - if (financialTransactionDate.after(endDateFiscalPeriod)) { - throw new LimaBusinessException(_("lima-business.defaultaccountingrules.dateaftererror")); - } - - /* - //6. check all entrybook of old and new financial period are blocked - //FIXME Make this check by topia query ? - List<EntryBook> entryBooks = new ArrayList<EntryBook>(); - List<EntryBook> newClosedEntryBooks = new ArrayList<EntryBook>(); - List<EntryBook> oldClosedEntryBooks = new ArrayList<EntryBook>(); + FiscalPeriod lastFiscalPeriod = fiscalPeriodDAO.getLastFiscalPeriod(); + FiscalPeriod firstFiscalPeriod = fiscalPeriodDAO.getFirstFiscalPeriod(); + Date beginDateFirstFiscalPeriod = firstFiscalPeriod.getBeginDate(); + Date endDateLastFiscalPeriod = lastFiscalPeriod.getEndDate(); + + //check if date are on fiscal period (test if date is after begindate of first f.p. and before enddate of last f.p.) - EntryBookDAO entryBookDAO = - LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); + if (log.isDebugEnabled()) { + 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); + } - entryBooks = entryBookDAO.findAll(); - - for (EntryBook entryBook : entryBooks) { - ClosedPeriodicEntryBook newClosedPeriodicEntryBook = - closedPeriodicEntryBookDAO.findbyEntryBookAndFinancialPeriod( - entryBook, financialPeriod); - ClosedPeriodicEntryBook oldClosedPeriodicEntryBook = - closedPeriodicEntryBookDAO.findbyEntryBookAndFinancialPeriod( - entryBook, financialPeriodOld); - if(newClosedPeriodicEntryBook.getLocked()){ - newClosedEntryBooks.add(entryBook); + //1-date not on a fiscal period + if (financialTransactionDate.before(beginDateFirstFiscalPeriod) || financialTransactionDate.after(endDateLastFiscalPeriod)){ + if (financialTransactionDate.before(beginDateFirstFiscalPeriod)) { + if (log.isDebugEnabled()) { + log.debug("Date de la transaction avant (antérieure) la date de début du premier exercice"); + } + throw new LimaBusinessException(_("lima-business.defaultaccountingrules.datebeforeerror")); } - if(oldClosedPeriodicEntryBook.getLocked()){ - oldClosedEntryBooks.add(entryBook); + + if (financialTransactionDate.after(endDateLastFiscalPeriod)) { + if (log.isDebugEnabled()) { + log.debug("Date de la transaction après (postérieure) la date de fin du dernier exercice"); + } + throw new LimaBusinessException(_("lima-business.defaultaccountingrules.dateaftererror")); } + }else{ //date on a fiscal period (and consequently on a financial), now test if financial is open + + FinancialPeriodDAO financialPeriodDAO = getDaoHelper().getFinancialPeriodDAO(); + FinancialPeriod financialPeriod = financialPeriodDAO.findByDate(financialTransaction.getTransactionDate()); + FinancialPeriod financialPeriodOld = financialPeriodDAO.findByDate(financialTransactionOld.getTransactionDate()); + + //2. check old financial period locked + if (financialPeriodOld.getLocked()) { + if (log.isDebugEnabled()) { + log.debug("Periode (Old) financière bloquée"); + } + throw new LimaBusinessException(_("lima-business.defaultaccountingrules.financialtransactionblocked")); + } + + //3. check new financial period locked + if (financialPeriod.getLocked()) { + if (log.isDebugEnabled()) { + log.debug("Periode (New) financière bloquée"); + } + throw new LimaBusinessException(_("lima-business.defaultaccountingrules.financialnewdateblocked")); + } } - if (oldClosedEntryBooks.size() >0){ - throw new LimaBusinessException("All EntryBook of this financialperiod are not open"); - } - if (newClosedEntryBooks.size() >0){ - throw new LimaBusinessException("All EntryBook of old financialperiod are not open"); - }*/ - - } catch (TopiaException ex) { throw new LimaException("Can't check financial transaction", ex); } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2012-06-21 14:38:23 UTC (rev 3469) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2012-06-22 13:03:22 UTC (rev 3470) @@ -227,23 +227,32 @@ * Method used by update entry and remove entry for update amounts. */ @Override - public void updateFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { + public void updateFinancialTransaction(FinancialTransaction financialTransaction) throws LimaException { AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); try { + + //FIXME mallon 22/06/2012 : Revoir l'utilisation du rattachement à la session et celle des deux objets 'financialTransactionOld' + //et 'financialTransaction' FinancialTransactionDAO transactionDAO = getDaoHelper().getFinancialTransactionDAO(); - FinancialTransaction financialTransactionOld = - transactionDAO.findByTopiaId(financialtransaction.getTopiaId()); + FinancialTransaction financialTransactionOld = transactionDAO.findByTopiaId(financialTransaction.getTopiaId()); - // FIXME echatellier 20120509, plusieurs chose à verifier ici: - // changement de date induisant en changement de période, verifier - // la permission (periode close/non close à l'arrivée) - accountingRules.updateFinancialTransactionDateRules( - financialtransaction, financialTransactionOld); - - financialTransactionOld.setEntryBook( - financialtransaction.getEntryBook()); + accountingRules.updateFinancialTransactionDateRules(financialTransaction, financialTransactionOld); + + Date financialTransactionOldDate = financialTransactionOld.getTransactionDate(); + Date financialTransactionDate = financialTransaction.getTransactionDate(); + + if (log.isDebugEnabled()) { + log.debug("Date de la transaction (Old) : " + financialTransactionOldDate); + } + if (log.isDebugEnabled()) { + log.debug("Date de la transaction (New) : " + financialTransactionDate); + } + + financialTransactionOld.setEntryBook(financialTransaction.getEntryBook()); + financialTransactionOld.setTransactionDate(financialTransactionDate); + transactionDAO.update(financialTransactionOld); } catch (TopiaException ex) { throw new LimaException("Can't update financial transaction", ex); 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 2012-06-21 14:38:23 UTC (rev 3469) +++ trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2012-06-22 13:03:22 UTC (rev 3470) @@ -6,8 +6,8 @@ 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 antérieure à la période fiscale -lima-business.defaultaccountingrules.datebeforeerror=La date est postérieure à la période fiscale +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 lima-business.defaultaccountingrules.deleteentrybookerror=Impossible de supprimer un journal contenant des transactions lima-business.defaultaccountingrules.enddateerror=La date de fin est antérieure à la date de début Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java 2012-06-21 14:38:23 UTC (rev 3469) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java 2012-06-22 13:03:22 UTC (rev 3470) @@ -33,6 +33,7 @@ import org.apache.commons.collections.CollectionUtils; import org.chorem.lima.FinancialStatementWayEnum; import org.chorem.lima.beans.FinancialTransactionSearch; +import org.hibernate.HibernateException; import org.nuiton.topia.TopiaException; /** @@ -47,6 +48,20 @@ public class FinancialTransactionDAOImpl<E extends FinancialTransaction> extends FinancialTransactionDAOAbstract<FinancialTransaction> { /** + * FIXME echatellier, remove this method when implemented in topia + * just overriden to use merge() instead of saveOrUpdate() + */ + public FinancialTransaction merge(FinancialTransaction e) throws TopiaException { + try { + e = (FinancialTransaction)getContext().getHibernate().merge(e); + getContext().getFiresSupport().warnOnUpdateEntity(e); + return e; + } catch (HibernateException ex) { + throw new TopiaException(ex); + } + } + + /** * Return how many transaction are found with specified entryBook. * * @param entryBook entry book Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FiscalPeriodDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FiscalPeriodDAOImpl.java 2012-06-21 14:38:23 UTC (rev 3469) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FiscalPeriodDAOImpl.java 2012-06-22 13:03:22 UTC (rev 3470) @@ -95,6 +95,24 @@ } /** + * Get first fiscal period (higher end date). + * + * @return last fiscal period + * @throws TopiaException + */ + public FiscalPeriod getFirstFiscalPeriod() throws TopiaException { + String query = "FROM " + FiscalPeriod.class.getName() + + " ORDER BY endDate"; + + List<FiscalPeriod> fiscalPeriods = context.find(query); + FiscalPeriod result = null; + if (!fiscalPeriods.isEmpty()) { + result = fiscalPeriods.get(0); + } + return result; + } + + /** * Get last non locked fiscal period (higher end date). * * @return last fiscal period Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2012-06-21 14:38:23 UTC (rev 3469) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2012-06-22 13:03:22 UTC (rev 3470) @@ -154,7 +154,8 @@ log.debug(String.format("Loaded %d financial periods", financialPeriods.size())); } view.getFinancialPeriodComboBoxModel().setObjects(financialPeriods); - + view.getFinancialPeriodComboBoxModel().setSelectedItem(financialPeriods.get(0)); + // update transactions updateFinancialTransactions(); } Modified: trunk/lima-swing/src/main/resources/log4j.properties =================================================================== --- trunk/lima-swing/src/main/resources/log4j.properties 2012-06-21 14:38:23 UTC (rev 3469) +++ trunk/lima-swing/src/main/resources/log4j.properties 2012-06-22 13:03:22 UTC (rev 3470) @@ -39,4 +39,5 @@ # package level log4j.logger.org.chorem.lima=INFO log4j.logger.org.chorem.lima.business.ejb=DEBUG -log4j.logger.org.chorem.lima.ui.account=DEBUG \ No newline at end of file +log4j.logger.org.chorem.lima.ui.account=DEBUG +log4j.logger.org.chorem.lima.business.accountingrules.DefaultAccountingRules=DEBUG \ No newline at end of file