Author: echatellier Date: 2012-02-21 16:55:51 +0100 (Tue, 21 Feb 2012) New Revision: 3334 Url: http://chorem.org/repositories/revision/lima/3334 Log: Ajout test report. Correction report sans transactions non balanc?\195?\169es (en harcod?\195?\169, ya que ca de vrai) Added: trunk/lima-business/src/test/java/org/chorem/lima/business/ReportServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ReportServiceRuleFrTest.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/ReportService.java trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialTransactionServiceImplTest.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2012-02-21 15:07:06 UTC (rev 3333) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2012-02-21 15:55:51 UTC (rev 3334) @@ -162,7 +162,7 @@ /** * Query for find entries for accountsreports and balancereports - * Just exact and balanced transaction are calculated + * Just exact and balanced transaction are calculated. * * @param account * @param beginDate @@ -181,17 +181,13 @@ String transactionDateProperty = TopiaQuery.getProperty( Entry.PROPERTY_FINANCIAL_TRANSACTION, FinancialTransaction.PROPERTY_TRANSACTION_DATE); - - // FIXME 20120110 echatellier amoutcredit and debit removed since 0.6 - //String amountCreditProperty = TopiaQuery.getProperty( - // Entry.PROPERTY_FINANCIAL_TRANSACTION, FinancialTransaction.PROPERTY_AMOUNT_CREDIT); - //String amountDebitProperty = TopiaQuery.getProperty( - // Entry.PROPERTY_FINANCIAL_TRANSACTION, FinancialTransaction.PROPERTY_AMOUNT_DEBIT); String entryBookProperty = TopiaQuery.getProperty( Entry.PROPERTY_FINANCIAL_TRANSACTION, FinancialTransaction.PROPERTY_ENTRY_BOOK); + // echatellier, oui c'est hardcodé, mais qu'est ce que c'est illisible sans ca query - //.addWhere(amountCreditProperty + " = " + amountDebitProperty) + .addWhere("(select sum(E2.amount) from " + Entry.class.getName() + " E2 where E2.debit = false and E2.financialTransaction = E.financialTransaction) = " + + "(select sum(E2.amount) from " + Entry.class.getName() + " E2 where E2.debit = true and E2.financialTransaction = E.financialTransaction)") .addWhere(transactionDateProperty + " BETWEEN :beginDate AND :endDate") .addNotNull(entryBookProperty) .addParam("beginDate", beginDate) Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/ReportService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/ReportService.java 2012-02-21 15:07:06 UTC (rev 3333) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/ReportService.java 2012-02-21 15:55:51 UTC (rev 3334) @@ -75,7 +75,7 @@ Boolean movementedFilter) throws LimaException; /** - * Generation du grand-livre + * Generation du grand-livre. * * @param beginDate * @param endDate @@ -91,7 +91,7 @@ /** - * Generation du rapports des comptes + * Generation du rapports des comptes. * * @param account * @param thirdPartAccountsMode @@ -107,7 +107,7 @@ /** - * Calculate all credit, debit and solde amounts for the balance + * Calculate all credit, debit and solde amounts for the balance. * <p/> * Get all entries if true * @@ -126,7 +126,7 @@ TopiaContext topiaContext) throws LimaException; /** - * Generation du rapports des journaux + * Generation du rapports des journaux. * * @param entryBook * @param beginDate @@ -139,7 +139,7 @@ Date endDate) throws LimaException; /** - * Generate VAT + * Generate VAT. * * @param fiscalPeriod * @return Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2012-02-21 15:07:06 UTC (rev 3333) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2012-02-21 15:55:51 UTC (rev 3334) @@ -26,6 +26,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; import java.text.DateFormat; import java.text.ParseException; import java.util.Locale; @@ -44,10 +45,16 @@ import org.chorem.lima.business.ejbinterface.FinancialPeriodService; import org.chorem.lima.business.ejbinterface.FinancialTransactionService; import org.chorem.lima.business.ejbinterface.FiscalPeriodService; +import org.chorem.lima.business.ejbinterface.ReportService; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountImpl; +import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryBookImpl; +import org.chorem.lima.entity.EntryImpl; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.entity.FinancialTransactionImpl; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FiscalPeriodImpl; import org.chorem.lima.entity.LimaCallaoDAOHelper; @@ -79,6 +86,7 @@ protected static FinancialPeriodService financialPeriodService; protected static FinancialTransactionService financialTransactionService; protected static FiscalPeriodService fiscalPeriodService; + protected static ReportService reportService; /** * This is a before class method, but junit will fail to run inherited @@ -109,6 +117,7 @@ financialPeriodService = LimaServiceFactory.getService(FinancialPeriodServiceMonitorable.class); financialTransactionService = LimaServiceFactory.getService(FinancialTransactionServiceMonitorable.class); fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodServiceMonitorable.class); + reportService = LimaServiceFactory.getService(ReportServiceMonitorable.class); } /** @@ -187,7 +196,17 @@ */ @Before public void initTestDatabase() throws LimaException, ParseException { + initTestAccounts(); + initTestTransactions(); + } + /** + * Create a basic account plan. + * + * @throws LimaException + * @throws ParseException + */ + protected void initTestAccounts() throws LimaException, ParseException { // clear database clearService.clearDatabase(); @@ -218,10 +237,10 @@ accountService.createAccount(accountBefa, accountBanques); // creation d'un journal - EntryBook entryBook = new EntryBookImpl(); - entryBook.setLabel("Journal des ventes"); - entryBook.setCode("jdv"); - entryBookService.createEntryBook(entryBook); + EntryBook journalDesVentes = new EntryBookImpl(); + journalDesVentes.setLabel("Journal des ventes"); + journalDesVentes.setCode("jdv"); + entryBookService.createEntryBook(journalDesVentes); // creation d'un exercice fiscal FiscalPeriod fiscalPeriod = new FiscalPeriodImpl(); @@ -229,4 +248,43 @@ fiscalPeriod.setEndDate(df.parse("December 31, 2012")); fiscalPeriodService.createFiscalPeriod(fiscalPeriod); } + + /** + * Create some transaction in previous accounts. + * + * @throws LimaException + * @throws ParseException + */ + protected void initTestTransactions() throws LimaException, ParseException { + // add some transactions + // FIXME echatellier 20120221 fix test, following instance already in current method + EntryBook journalDesVentes = entryBookService.getEntryBookByCode("jdv"); + Account accountVmpVae = accountService.getAccountByNumber("511"); + + // TODO echatellier 20120116 improve period choice + FinancialPeriod financialPeriod = financialPeriodService.getAllFinancialPeriods().get(0); + + FinancialTransaction transaction1 = new FinancialTransactionImpl(); + transaction1.setTransactionDate(df.parse("April 4, 2012")); + transaction1.setEntryBook(journalDesVentes); + transaction1.setFinancialPeriod(financialPeriod); + transaction1 = financialTransactionService.createFinancialTransaction(transaction1); + + Entry tr1Entry1 = new EntryImpl(); + tr1Entry1.setAmount(BigDecimal.valueOf(42.0)); + tr1Entry1.setAccount(accountVmpVae); + tr1Entry1.setFinancialTransaction(transaction1); + tr1Entry1.setDescription("test desc"); + tr1Entry1.setVoucher("voucher"); + tr1Entry1 = financialTransactionService.createEntry(tr1Entry1); + + Entry tr1Entry2 = new EntryImpl(); + tr1Entry2.setAmount(BigDecimal.valueOf(42.0)); + tr1Entry2.setDebit(true); + tr1Entry2.setAccount(accountVmpVae); + tr1Entry2.setFinancialTransaction(transaction1); + tr1Entry2.setDescription("test desc"); + tr1Entry2.setVoucher("voucher"); + tr1Entry2 = financialTransactionService.createEntry(tr1Entry2); + } } Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialTransactionServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialTransactionServiceImplTest.java 2012-02-21 15:07:06 UTC (rev 3333) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialTransactionServiceImplTest.java 2012-02-21 15:55:51 UTC (rev 3334) @@ -53,45 +53,6 @@ public class FinancialTransactionServiceImplTest extends AbstractLimaTest { /** - * Init db with some transaction. - * - * @throws ParseException - * @throws LimaException - */ - @Before - public void initTransactions() throws ParseException, LimaException { - - EntryBook journalDesVentes = entryBookService.getEntryBookByCode("jdv"); - Account accountVmpVae = accountService.getAccountByNumber("511"); - - // TODO echatellier 20120116 improve period choice - FinancialPeriod financialPeriod = financialPeriodService.getAllFinancialPeriods().get(0); - - FinancialTransaction transaction1 = new FinancialTransactionImpl(); - transaction1.setTransactionDate(df.parse("April 4, 2012")); - transaction1.setEntryBook(journalDesVentes); - transaction1.setFinancialPeriod(financialPeriod); - transaction1 = financialTransactionService.createFinancialTransaction(transaction1); - - Entry tr1Entry1 = new EntryImpl(); - tr1Entry1.setAmount(BigDecimal.valueOf(42.0)); - tr1Entry1.setAccount(accountVmpVae); - tr1Entry1.setFinancialTransaction(transaction1); - tr1Entry1.setDescription("test desc"); - tr1Entry1.setVoucher("voucher"); - tr1Entry1 = financialTransactionService.createEntry(tr1Entry1); - - Entry tr1Entry2 = new EntryImpl(); - tr1Entry2.setAmount(BigDecimal.valueOf(42.0)); - tr1Entry2.setDebit(true); - tr1Entry2.setAccount(accountVmpVae); - tr1Entry2.setFinancialTransaction(transaction1); - tr1Entry2.setDescription("test desc"); - tr1Entry2.setVoucher("voucher"); - tr1Entry2 = financialTransactionService.createEntry(tr1Entry2); - } - - /** * Test to find all unbalanced transactions. * Nothing wrong here. * Added: trunk/lima-business/src/test/java/org/chorem/lima/business/ReportServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/ReportServiceImplTest.java (rev 0) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/ReportServiceImplTest.java 2012-02-21 15:55:51 UTC (rev 3334) @@ -0,0 +1,107 @@ +/* + * #%L + * Lima business + * + * $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 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.business; + +import java.math.BigDecimal; +import java.text.ParseException; +import java.util.Date; + +import org.chorem.lima.beans.ReportsDatas; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.EntryImpl; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.entity.FinancialTransactionImpl; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test le service de génération des reports. + */ +public class ReportServiceImplTest extends AbstractLimaTest { + + /** + * Test de génération du rapport des comptes. + * + * @throws LimaException + * @throws ParseException + */ + @Test + public void testGenerateAccountsReports() throws LimaException, ParseException { + + Account accountBefa = accountService.getAccountByNumber("51"); + Assert.assertNotNull(accountBefa); + + Date beginDate = df.parse("April 1, 2012"); + Date endDate = df.parse("May 31, 2012"); + ReportsDatas datas = reportService.generateAccountsReports(accountBefa, false, beginDate, endDate); + Assert.assertEquals(BigDecimal.valueOf(42), datas.getAmountCredit().stripTrailingZeros()); + Assert.assertEquals(BigDecimal.valueOf(42), datas.getAmountDebit().stripTrailingZeros()); + + beginDate = df.parse("May 1, 2012"); + datas = reportService.generateAccountsReports(accountBefa, false, beginDate, endDate); + Assert.assertEquals(BigDecimal.valueOf(0), datas.getAmountCredit().stripTrailingZeros()); + Assert.assertEquals(BigDecimal.valueOf(0), datas.getAmountDebit().stripTrailingZeros()); + } + + /** + * Test de génération du rapport des comptes, en verifiant que les transactions + * non équilibrées ne sont pas présentes (modification 0.6). + * + * @throws LimaException + * @throws ParseException + */ + @Test + public void testGenerateAccountsReportsUnlalanced() throws LimaException, ParseException { + EntryBook journalDesVentes = entryBookService.getEntryBookByCode("jdv"); + Account accountVmpVae = accountService.getAccountByNumber("511"); + + // TODO echatellier 20120116 improve period choice + FinancialPeriod financialPeriod = financialPeriodService.getAllFinancialPeriods().get(0); + + FinancialTransaction transaction1 = new FinancialTransactionImpl(); + transaction1.setTransactionDate(df.parse("April 5, 2012")); + transaction1.setEntryBook(journalDesVentes); + transaction1.setFinancialPeriod(financialPeriod); + transaction1 = financialTransactionService.createFinancialTransaction(transaction1); + + Entry tr1Entry1 = new EntryImpl(); + tr1Entry1.setAmount(BigDecimal.valueOf(54.0)); + tr1Entry1.setAccount(accountVmpVae); + tr1Entry1.setFinancialTransaction(transaction1); + tr1Entry1.setDescription("test desc"); + tr1Entry1.setVoucher("voucher"); + tr1Entry1 = financialTransactionService.createEntry(tr1Entry1); + + Date beginDate = df.parse("April 1, 2012"); + Date endDate = df.parse("May 31, 2012"); + ReportsDatas datas = reportService.generateAccountsReports(accountVmpVae, false, beginDate, endDate); + Assert.assertEquals(BigDecimal.valueOf(42), datas.getAmountCredit().stripTrailingZeros()); + Assert.assertEquals(BigDecimal.valueOf(42), datas.getAmountDebit().stripTrailingZeros()); + } +} Property changes on: trunk/lima-business/src/test/java/org/chorem/lima/business/ReportServiceImplTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ReportServiceRuleFrTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ReportServiceRuleFrTest.java (rev 0) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ReportServiceRuleFrTest.java 2012-02-21 15:55:51 UTC (rev 3334) @@ -0,0 +1,62 @@ +/* + * #%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.business.accountingrules; + +import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.business.ReportServiceImplTest; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Add configuration to add specific test on French rules set. + * + * (redo all test defined in ReportServiceImplTest). + * + * Plus ajout de test specific à la locale FR. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ReportServiceRuleFrTest extends ReportServiceImplTest { + + @BeforeClass + public static void installFrenchRule() throws Exception { + LimaConfig.getInstance().setAccountingRule(FranceAccountingRules.class.getName()); + } + + /** + * Test une fois que la regles est correctement instanciée car + * elle peut être mise en cache dans {@link LimaConfig}. + */ + @Test + public void testRuleInstance() { + Assert.assertTrue(LimaConfig.getInstance().getAccountingRules() instanceof FranceAccountingRules); + } +} Property changes on: trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ReportServiceRuleFrTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL