Author: echatellier Date: 2012-05-04 16:36:29 +0200 (Fri, 04 May 2012) New Revision: 3403 Url: http://chorem.org/repositories/revision/lima/3403 Log: Remove topia query from all dao Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java 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-05-04 13:53:36 UTC (rev 3402) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java 2012-05-04 14:36:29 UTC (rev 3403) @@ -28,7 +28,6 @@ import java.util.List; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaQuery; /** * Ajout de requetes specifiques aux financial transaction sur le DAO. @@ -57,40 +56,46 @@ /** * Find all unbalanced transactions. * - * @param period period + * @param financialPeriod period * @param entryBook entry book * @return unbalanced transactions * @throws TopiaException */ - public List<FinancialTransaction> getAllUnbalancedTransaction(FinancialPeriod period, + public List<FinancialTransaction> getAllUnbalancedTransaction(FinancialPeriod financialPeriod, EntryBook entryBook) throws TopiaException { - TopiaQuery query = createQuery("E"); - query.addWhere("E.amountCredit != E.amountDebit") - .addEquals(FinancialTransaction.PROPERTY_ENTRY_BOOK, entryBook) - .addEquals(FinancialTransaction.PROPERTY_FINANCIAL_PERIOD, period); - List<FinancialTransaction> result = findAllByQuery(query); + String query = "FROM " + FinancialTransaction.class.getName() + " T"+ + " WHERE (SELECT sum(amount) FROM " + Entry.class.getName() + + " WHERE debit = true AND financialTransaction = T) != " + + " (SELECT sum(amount) FROM " + Entry.class.getName() + + " WHERE debit = false AND financialTransaction = T)" + + " AND T.financialPeriod = :financialPeriod" + + " AND T.entryBook = :entryBook"; + List<FinancialTransaction> result = context.find(query, "financialPeriod", + financialPeriod, "entryBook", entryBook); return result; } /** * Find all transaction where some field are not filled in. * - * @param period period + * @param financialPeriod period * @param entryBook entry book * @return unfilled transaction * @throws TopiaException */ - public List<FinancialTransaction> getAllUnfilledTransaction(FinancialPeriod period, + public List<FinancialTransaction> getAllUnfilledTransaction(FinancialPeriod financialPeriod, EntryBook entryBook) throws TopiaException { - TopiaQuery query = createQuery("T"); - query.addDistinct() - .addOrder("T." + FinancialTransaction.TOPIA_CREATE_DATE) - .addFrom(FiscalPeriod.class, "F") - .addLeftJoin("T." + FinancialTransaction.PROPERTY_ENTRY, "E", true) - .addWhere("T.amountCredit != T.amountDebit OR E.account = null OR E.voucher = null OR E.voucher = '' OR E.description = null OR E.description = ''") - .addEquals(FinancialTransaction.PROPERTY_ENTRY_BOOK, entryBook) - .addEquals(FinancialTransaction.PROPERTY_FINANCIAL_PERIOD, period); - List<FinancialTransaction> result = findAllByQuery(query); + String query = "FROM " + FinancialTransaction.class.getName() + " T"+ + " LEFT JOIN T.entry AS E" + + " WHERE ((SELECT sum(amount) FROM " + Entry.class.getName() + + " WHERE debit = true AND financialTransaction = T) != " + + " (SELECT sum(amount) FROM " + Entry.class.getName() + + " WHERE debit = false AND financialTransaction = T) + OR E.account = null" + + " OR E.voucher = null OR E.voucher = '' OR E.description = null OR E.description = '')" + + " AND T.entryBook = :entryBook" + + " AND T.financialPeriod = :financialPeriod"; + List<FinancialTransaction> result = context.find(query, "financialPeriod", + financialPeriod, "entryBook", entryBook); return result; } @@ -98,20 +103,31 @@ * Find all transaction without entry book. * * TODO echatellier 20120425 same method as getAllUnfilledTransaction ? - * doesn't concern a period ? * * @return * @throws TopiaException */ public List<FinancialTransaction> getAllTransactionWithoutEntryBook() throws TopiaException { - TopiaQuery query = createQuery("T"); + /*TopiaQuery query = createQuery("T"); query.addDistinct() .addOrder("T." + FinancialTransaction.TOPIA_CREATE_DATE) .addFrom(FiscalPeriod.class, "F") .addLeftJoin("T." + FinancialTransaction.PROPERTY_ENTRY, "E", true) .addWhere("T.amountCredit != T.amountDebit OR E.account = null OR E.voucher = null OR E.voucher = '' OR E.description = null OR E.description = ''") .addNull(FinancialTransaction.PROPERTY_ENTRY_BOOK); - List<FinancialTransaction> result = findAllByQuery(query); + List<FinancialTransaction> result = findAllByQuery(query);*/ + + String query = "FROM " + FinancialTransaction.class.getName() + " T"+ + " LEFT JOIN T.entry AS E" + + " WHERE ((SELECT sum(amount) FROM " + Entry.class.getName() + + " WHERE debit = true AND financialTransaction = T) != " + + " (SELECT sum(amount) FROM " + Entry.class.getName() + + " WHERE debit = false AND financialTransaction = T) + OR E.account = null" + + " OR E.voucher = null OR E.voucher = '' OR E.description = null OR E.description = '')" + + " AND entryBook = null"; + // FIXME echatellier 20120504 doesn't concern a period ? all database ? + List<FinancialTransaction> result = context.find(query); + return result; }