Author: echatellier Date: 2012-05-04 15:53:36 +0200 (Fri, 04 May 2012) New Revision: 3402 Url: http://chorem.org/repositories/revision/lima/3402 Log: Begin report service refactoring. Move query to DAO. Remove topia query. Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.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-05-04 13:17:42 UTC (rev 3401) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2012-05-04 13:53:36 UTC (rev 3402) @@ -157,42 +157,6 @@ return reportsDatas; } - /* - * Query for find entries for accountsreports and balancereports - * Just exact and balanced transaction are calculated. - * - * @param account - * @param beginDate - * @param endDate - * @param entryDAO - * @param queryAlias - * @return - * @throws LimaException - * - protected TopiaQuery createEntryQuery(Account account, - Date beginDate, - Date endDate, - EntryDAO entryDAO, - String queryAlias) { - TopiaQuery query = entryDAO.createQuery(queryAlias); - - String transactionDateProperty = TopiaQuery.getProperty( - Entry.PROPERTY_FINANCIAL_TRANSACTION, FinancialTransaction.PROPERTY_TRANSACTION_DATE); - 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("(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) - .addParam("endDate", endDate) - .addEquals(Entry.PROPERTY_ACCOUNT, account); - - return query; - }*/ - /** * Get list entries * Calculate all credit, debit and solde amounts for the accounts reports @@ -206,9 +170,7 @@ * @throws TopiaException */ protected ReportsDatas generateSubAccountReportsWithTransaction(Account account, - Date beginDate, - Date endDate, - TopiaContext topiaContext) throws TopiaException { + Date beginDate, Date endDate, TopiaContext topiaContext) throws TopiaException { ReportsDatas reportsDatas = new ReportsDatasImpl(); BigDecimal credit = new BigDecimal(0); BigDecimal debit = new BigDecimal(0); @@ -217,11 +179,11 @@ EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); // trouve les entrees associées à ca compte entre les date données - List<Entry> listEntries = entryDAO.findAllEntryOfEquilibredTransaction(account, beginDate, endDate); + List<Entry> listEntries = entryDAO.findAllEntryOfBalancedTransaction(account, beginDate, endDate); reportsDatas.setListEntry(listEntries); // recupere les totaux pour le compte - List<Object[]> results = entryDAO.getDebitCreditOfEquilibredTransaction(account, beginDate, endDate); + List<Object[]> results = entryDAO.getDebitCreditOfBalancedTransaction(account, beginDate, endDate); int nbAmount = results.size(); if (nbAmount == 2) { debit = (BigDecimal) results.get(0)[1]; @@ -259,37 +221,20 @@ * @throws TopiaException */ public ReportsDatas generateSubAccountBalanceWithTransaction(Account account, - Date beginDate, - Date endDate, - Boolean getEntries, - TopiaContext topiaContext) throws LimaException, TopiaException { + Date beginDate, Date endDate, Boolean getEntries, TopiaContext topiaContext) throws LimaException, TopiaException { ReportsDatas reportsDatas = new ReportsDatasImpl(); BigDecimal credit = new BigDecimal(0); BigDecimal debit = new BigDecimal(0); BigDecimal solde = new BigDecimal(0); - //String queryAlias = "E"; EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); if (getEntries) { - //TopiaQuery entriesQuery = - // createEntryQuery(account, beginDate, endDate, entryDAO, queryAlias); - //IMPORTANT : LOADING ENTRIES AND IS COLUMN FOR NO LAZY EXCEPTION - //entriesQuery.addLoad(Entry.PROPERTY_FINANCIAL_TRANSACTION); - //String loadEntryBookProperty = - // TopiaQuery.getProperty(Entry.PROPERTY_FINANCIAL_TRANSACTION, - // FinancialTransaction.PROPERTY_ENTRY_BOOK); - //entriesQuery.addLoad(loadEntryBookProperty); - List<Entry> listEntries = entryDAO.findAllEntryOfEquilibredTransaction(account, beginDate, endDate); + List<Entry> listEntries = entryDAO.findAllEntryOfBalancedTransaction(account, beginDate, endDate); reportsDatas.setListEntry(listEntries); } - //TopiaQuery amountsQuery = - // createEntryQuery(account, beginDate, endDate, entryDAO, queryAlias); - //amountsQuery.setSelect("E." + Entry.PROPERTY_DEBIT, "SUM(E." + Entry.PROPERTY_AMOUNT + ")"); - //amountsQuery.addGroup("E." + Entry.PROPERTY_DEBIT); - //results = amountsQuery.execute(topiaContext); - List<Object[]> results = entryDAO.getDebitCreditOfEquilibredTransaction(account, beginDate, endDate); + List<Object[]> results = entryDAO.getDebitCreditOfBalancedTransaction(account, beginDate, endDate); int nbAmount = results.size(); if (nbAmount == 2) { debit = (BigDecimal) results.get(0)[1]; @@ -330,114 +275,55 @@ */ @Override public ReportsDatas generateEntryBooksReports(EntryBook entryBook, - Date beginDate, - Date endDate) throws LimaException { + Date beginDate, Date endDate) throws LimaException { ReportsDatas reportsDatas = new ReportsDatasImpl(); BigDecimal credit = new BigDecimal(0); BigDecimal debit = new BigDecimal(0); BigDecimal solde = new BigDecimal(0); - List<Object[]> results; - if (entryBook != null && beginDate != null && endDate != null) { - // Get all entries with a topia query - TopiaContext topiaTransaction = beginTransaction(rootContext); - try { - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaTransaction); - TopiaQuery entriesQuery = createEntryBookReportsQuery( - entryBook, beginDate, endDate, entryDAO, "E"); - String orderDateProperty = - TopiaQuery.getProperty("E", Entry.PROPERTY_FINANCIAL_TRANSACTION, FinancialTransaction.PROPERTY_TRANSACTION_DATE); - String orderIdProperty = - TopiaQuery.getProperty("E", Entry.PROPERTY_FINANCIAL_TRANSACTION, FinancialTransaction.TOPIA_ID); - entriesQuery.addOrder(orderDateProperty) - .addOrder(orderIdProperty); - reportsDatas.setListEntry(entryDAO.findAllByQuery(entriesQuery)); - - TopiaQuery amountsQuery = - createEntryBookReportsQuery(entryBook, beginDate, endDate, entryDAO, "E"); - amountsQuery.setSelect("E." + Entry.PROPERTY_DEBIT, "SUM(E." + Entry.PROPERTY_AMOUNT + ")"); - amountsQuery.addGroup("E." + Entry.PROPERTY_DEBIT); - results = amountsQuery.execute(topiaTransaction); - int nbAmount = results.size(); - if (nbAmount == 2) { + // Get all entries with a topia query + TopiaContext topiaTransaction = beginTransaction(rootContext); + try { + EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaTransaction); + List<Entry> entries = entryDAO.findAllEntryOfBalancedTransaction(entryBook, beginDate, endDate); + reportsDatas.setListEntry(entries); + + List<Object[]> results = entryDAO.getDebitCreditOfBalancedTransaction(entryBook, beginDate, endDate); + int nbAmount = results.size(); + if (nbAmount == 2) { + debit = (BigDecimal) results.get(0)[1]; + credit = (BigDecimal) results.get(1)[1]; + } + if (nbAmount == 1) { + if ((Boolean) results.get(0)[0]) { debit = (BigDecimal) results.get(0)[1]; - credit = (BigDecimal) results.get(1)[1]; + } else { + credit = (BigDecimal) results.get(0)[1]; } - if (nbAmount == 1) { - if ((Boolean) results.get(0)[0]) { - debit = (BigDecimal) results.get(0)[1]; - } else { - credit = (BigDecimal) results.get(0)[1]; - } - } + } - // set the amounts and solde - //solde = debit - credit; - solde = solde.add(debit); - solde = solde.subtract(credit); - if (solde.compareTo(BigDecimal.ZERO) == 1) { - reportsDatas.setSoldeDebit(true); - } - solde = solde.abs(); - - reportsDatas.setAmountCredit(credit); - reportsDatas.setAmountDebit(debit); - reportsDatas.setAmountSolde(solde); - - //commitTransaction(topiaTransaction); - } catch (Exception ex) { - doCatch(topiaTransaction, ex); - } finally { - doFinally(topiaTransaction); + // set the amounts and solde + //solde = debit - credit; + solde = solde.add(debit); + solde = solde.subtract(credit); + if (solde.compareTo(BigDecimal.ZERO) == 1) { + reportsDatas.setSoldeDebit(true); } + solde = solde.abs(); + + reportsDatas.setAmountCredit(credit); + reportsDatas.setAmountDebit(debit); + reportsDatas.setAmountSolde(solde); + } catch (Exception ex) { + doCatch(topiaTransaction, ex); + } finally { + doFinally(topiaTransaction); } return reportsDatas; } /** - * Query for find entries for accountsreports and balancereports - * Just balanced transaction are calculated - * - * @param entryBook - * @param beginDate - * @param endDate - * @param entryDAO - * @param queryAlias - * @return - * @throws LimaException - */ - public TopiaQuery createEntryBookReportsQuery(EntryBook entryBook, - Date beginDate, - Date endDate, - EntryDAO entryDAO, - String queryAlias) throws LimaException { - TopiaQuery query = entryDAO.createQuery(queryAlias); - 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); - query - //.addWhere(amountCreditProperty + " = " + amountDebitProperty) - .addEquals(entryBookProperty, entryBook) - .addWhere(transactionDateProperty + " BETWEEN :beginDate AND :endDate") - .addParam("beginDate", beginDate) - .addParam("endDate", endDate); - - return query; - } - - /** * Get balance trial * <p/> * Calculate the amounts and the solde for all subaccounts @@ -476,8 +362,7 @@ } //build list account from selectedAccounts else { - accounts = accountDAO.stringToListAccounts( - result, false); + accounts = accountDAO.stringToListAccounts( result, false); } for (Account account : accounts) { ReportsDatas reportsDatas = @@ -571,6 +456,8 @@ accountsList = accountDAO.findAll(); for (Account account : accountsList) { //VAT accounts start only with number 44 + //FIXME echatellier 44 is hardcoded and depends on + //french rule ? if (account.getAccountNumber().startsWith("44")) { list.add(generateBalanceTrial(fp.getBeginDate(), fp.getEndDate(), account.getAccountNumber(), Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java 2012-05-04 13:17:42 UTC (rev 3401) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java 2012-05-04 13:53:36 UTC (rev 3402) @@ -33,24 +33,21 @@ public class EntryDAOImpl<E extends Entry> extends EntryDAOAbstract<Entry> { /** - * Requete generique qui recupere les entrees equilibrées portant sur un - * compte entre deux dates. + * Requete generique qui recupere les entrees equilibrées portant entre + * deux dates. * * @param account account * @param beginDate begin date * @param endDate end date */ - protected String getEquilibredTransactionQuery(Account account, - Date beginDate, Date endDate) { + protected String getEquilibredTransactionQuery(Date beginDate, Date endDate) { String query = "FROM " + Entry.class.getName() + " E" + // equlibrée (somme des débit = somme des crédit) " WHERE (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)" + // entre les 2 dates " AND :beginDate <= E.financialTransaction.transactionDate" + - " AND E.financialTransaction.transactionDate <= :endDate" + - // concerne le compte - " AND E.account = :account"; + " AND E.financialTransaction.transactionDate <= :endDate"; return query; } @@ -64,10 +61,12 @@ * @return entries * @throws TopiaException */ - public List<Entry> findAllEntryOfEquilibredTransaction(Account account, + public List<Entry> findAllEntryOfBalancedTransaction(Account account, Date beginDate, Date endDate) throws TopiaException { - String query = getEquilibredTransactionQuery(account, beginDate, endDate); + String query = getEquilibredTransactionQuery(beginDate, endDate) + + // concerne le compte + " AND E.account = :account"; List<Entry> entries = context.find(query, "beginDate", beginDate, "endDate", endDate, "account", account); @@ -78,20 +77,67 @@ * Retourne la somme des entrées des transaction equilibrées entre * deux dates pour un compte donné. * - * @param account le compte + * @param account account * @param beginDate bebin date * @param endDate end date * @return list boolean,int (une ligne pour le debit true, une ligne pour le credit) * @throws TopiaException */ - public List<Object[]> getDebitCreditOfEquilibredTransaction(Account account, + public List<Object[]> getDebitCreditOfBalancedTransaction(Account account, Date beginDate, Date endDate) throws TopiaException { String query = "SELECT E.debit, sum(E.amount) " + - getEquilibredTransactionQuery(account, beginDate, endDate) + + getEquilibredTransactionQuery(beginDate, endDate) + + // concerne le compte + " AND E.account = :account" + " GROUP BY E.debit"; List<Object[]> result = context.find(query, "beginDate", beginDate, "endDate", endDate, "account", account); return result; } + + /** + * Retourne les entrees des transaction equlibrées entre deux dates pour + * un journal. + * + * @param entryBook entry book + * @param beginDate begin date + * @param endDate end date + * @throws TopiaException + */ + public List<Entry> findAllEntryOfBalancedTransaction(EntryBook entryBook, Date beginDate, + Date endDate) throws TopiaException { + String query = getEquilibredTransactionQuery(beginDate, endDate) + + // concerne le compte + " AND E.entryBook = :entryBook" + + // fix order + " ORDER BY, E.financialTransaction.beginDate, E.financialTransaction.topiaId"; + + List<Entry> entries = context.find(query, "beginDate", beginDate, + "endDate", endDate, "entryBook", entryBook); + return entries; + } + + /** + * Retourne la somme des entrées des transaction equilibrées entre + * deux dates pour un journal donné. + * + * @param entryBook entry book + * @param beginDate bebin date + * @param endDate end date + * @return list boolean,int (une ligne pour le debit true, une ligne pour le credit) + * @throws TopiaException + */ + public List<Object[]> getDebitCreditOfBalancedTransaction(EntryBook entryBook, + Date beginDate, Date endDate) throws TopiaException { + String query = "SELECT E.debit, sum(E.amount) " + + getEquilibredTransactionQuery(beginDate, endDate) + + // concerne le compte + " AND E.entryBook = :entryBook" + + " GROUP BY E.debit"; + + List<Object[]> result = context.find(query, "beginDate", beginDate, + "endDate", endDate, "entryBook", entryBook); + return result; + } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java 2012-05-04 13:17:42 UTC (rev 3401) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java 2012-05-04 13:53:36 UTC (rev 3402) @@ -58,7 +58,6 @@ import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; - /** * Handler associated with accounts reports view. * By : $Author$
participants (1)
-
echatellier@users.chorem.org