r3407 - in trunk: lima-business/src/main/java/org/chorem/lima/business/accountingrules lima-business/src/test/java/org/chorem/lima/entity lima-callao/src/main/java/org/chorem/lima/entity
Author: echatellier Date: 2012-05-09 15:09:24 +0200 (Wed, 09 May 2012) New Revision: 3407 Url: http://chorem.org/repositories/revision/lima/3407 Log: Refactoring periodic entry book rule Added: trunk/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java 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 2012-05-09 13:03:32 UTC (rev 3406) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2012-05-09 13:09:24 UTC (rev 3407) @@ -175,7 +175,9 @@ return financialPeriods; } - /** Règles de vérification de fermeture d'un exercice, appliquées à la comptabilité française */ + /** + * Règles de vérification de fermeture d'un exercice, appliquées à la comptabilité française. + */ @Override public void blockFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException { try { @@ -209,6 +211,10 @@ * get all blocked closedperiodicentrybook while his same period, return the number * <p/> * compare there + * + * FIXME echatellier 20120504 a quoi ca sert de recuperer un nombre + * et de le comparer avec un autre, c'est pas plus simple de verifier + * qu'il reste des ClosedPeriodicEntryBook non clos ? */ @Override public void blockClosedPeriodicEntryBookRules(ClosedPeriodicEntryBook closedPeriodicEntryBook, TopiaContext topiaTransaction) throws LimaException { @@ -216,51 +222,35 @@ closedPeriodicEntryBook, topiaTransaction); FinancialPeriod financialPeriod = closedPeriodicEntryBook.getFinancialPeriod(); - List<ClosedPeriodicEntryBook> closedPeriodicEntryBooks = - new ArrayList<ClosedPeriodicEntryBook>(); try { // Get all closedperiod between for the period and entrybook - Date endDate = closedPeriodicEntryBook. - getFinancialPeriod().getBeginDate(); + Date endDate = closedPeriodicEntryBook.getFinancialPeriod().getBeginDate(); + // FIXME echatellier 20120502 c'est pas un hack ca ? + // un period peut ne pas durer un mois endDate = DateUtils.addMonths(endDate, -1); - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(topiaTransaction); + FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(topiaTransaction); - //search fiscalperiod have financialperiod in params - TopiaQuery query1 = fiscalPeriodDAO.createQuery() - .addInElements(":financialPeriod", "financialPeriod") - .addParam("financialPeriod", financialPeriod); - FiscalPeriod fiscalPeriod = fiscalPeriodDAO.findByQuery(query1); - + //search fiscalperiod have financialperiod + FiscalPeriod fiscalPeriod = fiscalPeriodDAO.findByFinancialPeriod(financialPeriod); Date beginDate = fiscalPeriod.getBeginDate(); - + // FIXME echatellier 20120502 quels est la rapport entre beginDate + // et endDate ? il ne provienent pas du même endroit EntryBook entryBook = closedPeriodicEntryBook.getEntryBook(); ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaTransaction); - TopiaQuery query = closedPeriodicEntryBookDAO.createQuery(); - String closedPeriodicEntryBookDateProperty = - TopiaQuery.getProperty(ClosedPeriodicEntryBook.PROPERTY_FINANCIAL_PERIOD, - FinancialPeriod.PROPERTY_BEGIN_DATE); - query.addWhere(closedPeriodicEntryBookDateProperty - + " BETWEEN :beginDate AND :endDate") - .addEquals(ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, entryBook) - .addParam("beginDate", beginDate) - .addParam("endDate", endDate); - closedPeriodicEntryBooks. - addAll(closedPeriodicEntryBookDAO.findAllByQuery(query)); + List<ClosedPeriodicEntryBook> closedPeriodicEntryBooks = + closedPeriodicEntryBookDAO.findAllByEntryBookAndDates(entryBook, beginDate, endDate); + // FIXME echatellier 20120504 juste un count suffit int nbClosedPeriodicEntryBooks = closedPeriodicEntryBooks.size(); // Get all closed between for the period, entrybook and are blocked - query.addEquals(ClosedPeriodicEntryBook.PROPERTY_LOCKED, true); - closedPeriodicEntryBooks.clear(); - closedPeriodicEntryBooks. - addAll(closedPeriodicEntryBookDAO.findAllByQuery(query)); + closedPeriodicEntryBooks = closedPeriodicEntryBookDAO.findAllByEntryBookAndDatesLocked(entryBook, beginDate, endDate); int nbBlockedClosedPeriodicEntryBooks = closedPeriodicEntryBooks.size(); Added: trunk/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java (rev 0) +++ trunk/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java 2012-05-09 13:09:24 UTC (rev 3407) @@ -0,0 +1,71 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.entity; + +import java.util.List; + +import org.chorem.lima.business.AbstractLimaTest; +import org.chorem.lima.business.LimaException; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; + +/** + * Test for {@link FinancialTransactionDAO}. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class FinancialTransactionDAOTest extends AbstractLimaTest { + + @Before + public void initTest() throws Exception { + initTestDatabase(); + } + + /** + * Test la recherche des transactions non equilibrées. + * + * @throws TopiaException + * @throws LimaException + */ + @Test + public void testFindAllUnbalancedTransactions() throws TopiaException, LimaException { + + FinancialPeriod financialPeriod = financialPeriodService.getAllFinancialPeriods().get(0); + EntryBook journalDesVentes = entryBookService.getEntryBookByCode("jdv"); + + TopiaContext tx = getTestContext().beginTransaction(); + FinancialTransactionDAO ftDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(tx); + List<FinancialTransaction> fTransactions = ftDAO.getAllUnbalancedTransaction(financialPeriod, journalDesVentes); + Assert.assertNotNull(fTransactions); + } +} Property changes on: trunk/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java 2012-05-09 13:03:32 UTC (rev 3406) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java 2012-05-09 13:09:24 UTC (rev 3407) @@ -102,5 +102,46 @@ " ORDER BY entryBook.code"; return context.find(query, 0d, 0d, "beginDate", beginDate, "endDate", endDate); } + + /** + * Retourne toutes les ClosedPeriodicEntryBook par interval de date + * sur les periodes sur lequelles elles portent pour un journal. + * + * @param entryBook entry book + * @param beginDate begin date + * @param endDate end date + * @return all ClosedPeriodicEntryBook between begin and end + * @throws TopiaException + */ + public List<ClosedPeriodicEntryBook> findAllByEntryBookAndDates(EntryBook entryBook, + Date beginDate, Date endDate) throws TopiaException { + String query = "FROM " + ClosedPeriodicEntryBook.class.getName() + + " WHERE :begindate <= financialPeriod.beginDate " + + " AND financialPeriod.beginDate <= :endDate" + + " AND entryBook = :entryBook"; + return context.find(query, 0d, 0d, "beginDate", beginDate, "endDate", endDate, "entryBook", entryBook); + } + + /** + * Retourne toutes les ClosedPeriodicEntryBook par interval de date + * sur les periodes sur lequelles elles portent pour un journal. + * + * @param entryBook entry book + * @param beginDate begin date + * @param endDate end date + * @return all ClosedPeriodicEntryBook between begin and end + * @throws TopiaException + */ + public List<ClosedPeriodicEntryBook> findAllByEntryBookAndDatesLocked(EntryBook entryBook, + Date beginDate, Date endDate) throws TopiaException { + + String query = "FROM " + ClosedPeriodicEntryBook.class.getName() + + " WHERE :begindate <= financialPeriod.beginDate " + + " AND financialPeriod.beginDate <= :endDate" + + " AND entryBook = :entryBook" + + " AND locked = true"; + return context.find(query, 0d, 0d, "beginDate", beginDate, "endDate", endDate, "entryBook", entryBook); + } + }
participants (1)
-
echatellier@users.chorem.org