r3401 - trunk/lima-callao/src/main/java/org/chorem/lima/entity
Author: echatellier Date: 2012-05-04 15:17:42 +0200 (Fri, 04 May 2012) New Revision: 3401 Url: http://chorem.org/repositories/revision/lima/3401 Log: Rename DAO to DAOImpl Added: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAOImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java Removed: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAO.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAO.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAO.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAO.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAO.java Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAO.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAO.java 2012-05-04 09:43:18 UTC (rev 3400) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAO.java 2012-05-04 13:17:42 UTC (rev 3401) @@ -1,190 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 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.entity; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.StringTokenizer; - -import org.apache.commons.lang3.StringUtils; -import org.nuiton.topia.TopiaException; - -public class AccountDAO extends AccountDAOImpl<Account> { - - /** - * Retourne tous les comptes qui n'ont pas eux meme de sous compte. - * - * @return leaf accounts - * @throws TopiaException - */ - public List<Account> findAllLeafAccounts() throws TopiaException { - // FIXME echatellier 20120413 la requete ne fonctionne pas - // et retourne vide - /*String query = "FROM " + Account.class.getName() + " a WHERE a NOT IN (" + - "FROM " + Account.class.getName() + " b where b.accountNumber like concat(a.accountNumber,'%'))"; - List<Account> accounts = context.find(query);*/ - - // code temporaire non performant en attandant: - List<Account> allAccounts = findAll(); - Iterator<Account> itAccount = allAccounts.iterator(); - while (itAccount.hasNext()) { - Account acc = itAccount.next(); - Iterator<Account> itAccount2 = allAccounts.iterator(); - while (itAccount2.hasNext()) { - Account acc2 = itAccount2.next(); - if (!acc2.getAccountNumber().equals(acc.getAccountNumber()) && - acc2.getAccountNumber().startsWith(acc.getAccountNumber())) { - itAccount.remove(); - break; - } - } - } - return allAccounts; - } - - /** - * TODO pas compris l'interet de la methode, si on veut un compte feuille - * par son numero, cela revient a avoir un compte par son numero. - */ - @Deprecated - public Account findLeafAccountByNumber(String number) throws TopiaException { - return findByAccountNumber(number); - } - - /** - * Find account contained into account number interval. - * - * @param accountNumberLow min account number - * @param accountNumberHigh max account number - * @return account list - * @throws TopiaException - */ - protected List<Account> findIntervalAccountByNumber(String accountNumberLow, - String accountNumberHigh) throws TopiaException { - String query = "FROM " + Account.class.getName() + " WHERE :accountNumberLow <= accountNumber AND accountNumber <= :accountNumberHigh"; - return (List<Account>) context.find(query, "accountNumberLow", - accountNumberLow, "accountNumberHigh", accountNumberHigh); - } - - /** - * Retourne tous les comptes dont le numero commence par celui specifié. - * - * @param account parent account - * @return - * @throws TopiaException - */ - public List<Account> findAllSubAccounts(Account account) throws TopiaException { - - String query = "FROM " + Account.class.getName() + " a WHERE a.accountNumber LIKE concat(:accountNumber, '_%')"; - List<Account> accounts = context.find(query, "accountNumber", account.getAccountNumber()); - - return accounts; - } - - /** - * @deprecated since 0.6, business method, need to be moved out of dao - */ - @Deprecated - public List<Account> stringToListAccounts(String selectedAccounts, - Boolean leafAccountsMode) throws TopiaException { - Set<Account> accounts = new HashSet<Account>(); - if (selectedAccounts != null) { - //Remove Spaces - String result = StringUtils.deleteWhitespace(selectedAccounts); - - Boolean first = true; - StringTokenizer stStar = new StringTokenizer(result, "-"); - while (stStar.hasMoreTokens()) { - String subString = stStar.nextToken(); - - //Split comma - StringTokenizer stComma = new StringTokenizer(subString, ","); - while (stComma.hasMoreTokens()) { - String s = stComma.nextToken(); - //if intervall account - if (s.contains("..") && !s.endsWith("..")) { - //Split .. - String stringDoubleDot[] = s.split("\\.\\."); - - List<Account> resultIntervall = - findIntervalAccountByNumber(stringDoubleDot[0], stringDoubleDot[1]); - - //if first add accounts, else remove - if (first) { - accounts.addAll(resultIntervall); - } else { - accounts.removeAll(resultIntervall); - } - } - //else one account - else { - Account account = null; - if (leafAccountsMode) { - account = findLeafAccountByNumber(s); - } else { - account = findByAccountNumber(s); - } - //if exist - if (account != null) { - //if first - if (first) { - accounts.add(account); - } else { - accounts.remove(account); - } - } - //search all account start with accountnumber - else { - /*TopiaQuery query = createQuery(); - String subAccountsProperty = TopiaQuery.getProperty(Account.PROPERTY_SUB_ACCOUNTS); - query.addWhere("not exists elements (" + subAccountsProperty + ")") - .addWhere(Account.PROPERTY_ACCOUNT_NUMBER, Op.LIKE, s + "%"); - List<Account> accountsResult = (List<Account>) findAllByQuery(query);*/ - - String query = "FROM " + Account.class.getName() + " a WHERE NOT IN (" + - "FROM " + Account.class.getName() + " b where b.accountNumber like a.accountNumber+'%')" + - " AND a.accountNumber LIKE ?"; - List<Account> accountsResult = getContext().find(query, s); - if (accountsResult != null) { - //if first - if (first) { - accounts.addAll(accountsResult); - } else { - accounts.removeAll(accountsResult); - } - } - } - } - } - first = false; - } - } - return new ArrayList(accounts); - } -} Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java (from rev 3400, trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAO.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java 2012-05-04 13:17:42 UTC (rev 3401) @@ -0,0 +1,190 @@ +/* + * #%L + * Lima callao + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 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.entity; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.StringTokenizer; + +import org.apache.commons.lang3.StringUtils; +import org.nuiton.topia.TopiaException; + +public class AccountDAOImpl<E extends Account> extends AccountDAOAbstract<Account> { + + /** + * Retourne tous les comptes qui n'ont pas eux meme de sous compte. + * + * @return leaf accounts + * @throws TopiaException + */ + public List<Account> findAllLeafAccounts() throws TopiaException { + // FIXME echatellier 20120413 la requete ne fonctionne pas + // et retourne vide + /*String query = "FROM " + Account.class.getName() + " a WHERE a NOT IN (" + + "FROM " + Account.class.getName() + " b where b.accountNumber like concat(a.accountNumber,'%'))"; + List<Account> accounts = context.find(query);*/ + + // code temporaire non performant en attandant: + List<Account> allAccounts = findAll(); + Iterator<Account> itAccount = allAccounts.iterator(); + while (itAccount.hasNext()) { + Account acc = itAccount.next(); + Iterator<Account> itAccount2 = allAccounts.iterator(); + while (itAccount2.hasNext()) { + Account acc2 = itAccount2.next(); + if (!acc2.getAccountNumber().equals(acc.getAccountNumber()) && + acc2.getAccountNumber().startsWith(acc.getAccountNumber())) { + itAccount.remove(); + break; + } + } + } + return allAccounts; + } + + /** + * TODO pas compris l'interet de la methode, si on veut un compte feuille + * par son numero, cela revient a avoir un compte par son numero. + */ + @Deprecated + public Account findLeafAccountByNumber(String number) throws TopiaException { + return findByAccountNumber(number); + } + + /** + * Find account contained into account number interval. + * + * @param accountNumberLow min account number + * @param accountNumberHigh max account number + * @return account list + * @throws TopiaException + */ + protected List<Account> findIntervalAccountByNumber(String accountNumberLow, + String accountNumberHigh) throws TopiaException { + String query = "FROM " + Account.class.getName() + " WHERE :accountNumberLow <= accountNumber AND accountNumber <= :accountNumberHigh"; + return (List<Account>) context.find(query, "accountNumberLow", + accountNumberLow, "accountNumberHigh", accountNumberHigh); + } + + /** + * Retourne tous les comptes dont le numero commence par celui specifié. + * + * @param account parent account + * @return + * @throws TopiaException + */ + public List<Account> findAllSubAccounts(Account account) throws TopiaException { + + String query = "FROM " + Account.class.getName() + " a WHERE a.accountNumber LIKE concat(:accountNumber, '_%')"; + List<Account> accounts = context.find(query, "accountNumber", account.getAccountNumber()); + + return accounts; + } + + /** + * @deprecated since 0.6, business method, need to be moved out of dao + */ + @Deprecated + public List<Account> stringToListAccounts(String selectedAccounts, + Boolean leafAccountsMode) throws TopiaException { + Set<Account> accounts = new HashSet<Account>(); + if (selectedAccounts != null) { + //Remove Spaces + String result = StringUtils.deleteWhitespace(selectedAccounts); + + Boolean first = true; + StringTokenizer stStar = new StringTokenizer(result, "-"); + while (stStar.hasMoreTokens()) { + String subString = stStar.nextToken(); + + //Split comma + StringTokenizer stComma = new StringTokenizer(subString, ","); + while (stComma.hasMoreTokens()) { + String s = stComma.nextToken(); + //if intervall account + if (s.contains("..") && !s.endsWith("..")) { + //Split .. + String stringDoubleDot[] = s.split("\\.\\."); + + List<Account> resultIntervall = + findIntervalAccountByNumber(stringDoubleDot[0], stringDoubleDot[1]); + + //if first add accounts, else remove + if (first) { + accounts.addAll(resultIntervall); + } else { + accounts.removeAll(resultIntervall); + } + } + //else one account + else { + Account account = null; + if (leafAccountsMode) { + account = findLeafAccountByNumber(s); + } else { + account = findByAccountNumber(s); + } + //if exist + if (account != null) { + //if first + if (first) { + accounts.add(account); + } else { + accounts.remove(account); + } + } + //search all account start with accountnumber + else { + /*TopiaQuery query = createQuery(); + String subAccountsProperty = TopiaQuery.getProperty(Account.PROPERTY_SUB_ACCOUNTS); + query.addWhere("not exists elements (" + subAccountsProperty + ")") + .addWhere(Account.PROPERTY_ACCOUNT_NUMBER, Op.LIKE, s + "%"); + List<Account> accountsResult = (List<Account>) findAllByQuery(query);*/ + + String query = "FROM " + Account.class.getName() + " a WHERE NOT IN (" + + "FROM " + Account.class.getName() + " b where b.accountNumber like a.accountNumber+'%')" + + " AND a.accountNumber LIKE ?"; + List<Account> accountsResult = getContext().find(query, s); + if (accountsResult != null) { + //if first + if (first) { + accounts.addAll(accountsResult); + } else { + accounts.removeAll(accountsResult); + } + } + } + } + } + first = false; + } + } + return new ArrayList(accounts); + } +} Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAO.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAO.java 2012-05-04 09:43:18 UTC (rev 3400) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAO.java 2012-05-04 13:17:42 UTC (rev 3401) @@ -1,106 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 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.entity; - -import java.util.Date; -import java.util.List; - -import org.nuiton.topia.TopiaException; - -public class ClosedPeriodicEntryBookDAO extends ClosedPeriodicEntryBookDAOImpl<ClosedPeriodicEntryBook> { - - /** - * Find all ClosedPeriodicEntryBook with common EntryBook. - * - * @param entryBook entry book property - * @return ClosedPeriodicEntryBook list - * @throws TopiaException - */ - public List<ClosedPeriodicEntryBook> findAllByEntryBook(EntryBook entryBook) throws TopiaException { - return findAllByProperties(ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, entryBook); - } - - /** - * Return ClosedPeriodicEntryBook by EntryBook and FinancialPeriod. - * - * @param entryBook - * @param financialPeriod - * @return ClosedPeriodicEntryBook - * @throws TopiaException - */ - public ClosedPeriodicEntryBook findByEntryBookAndFinancialPeriod( - EntryBook entryBook, FinancialPeriod financialPeriod) - throws TopiaException { - - List<ClosedPeriodicEntryBook> closedPeriodicEntryBooks; - String query = "FROM " + ClosedPeriodicEntryBook.class.getName(); - if (entryBook != null) { - query += " WHERE entryBook = :entryBook"; - if (financialPeriod != null) { - query += " AND financialPeriod = :financialPeriod"; - //context.find(query, 0, 0, "entryBook", entryBook, "financialPeriod", financialPeriod); - closedPeriodicEntryBooks = context.find(query, "entryBook", entryBook, "financialPeriod", financialPeriod); - } else { - //context.find(query, 0, 0, "entryBook", entryBook); - closedPeriodicEntryBooks = context.find(query, "entryBook", entryBook); - } - } else { - if (financialPeriod != null) { - query += " WHERE financialPeriod = :financialPeriod"; - } - - //context.find(query, 0, 0, "financialPeriod", financialPeriod); - closedPeriodicEntryBooks = context.find(query, "financialPeriod", financialPeriod); - } - - // get only first one - ClosedPeriodicEntryBook result = null; - if (!closedPeriodicEntryBooks.isEmpty()) { - result = closedPeriodicEntryBooks.get(0); - } - return result; - } - - /** - * Retourne toutes les ClosedPeriodicEntryBook par interval de date - * sur les periodes sur lequelles elles portent ordonnée par journal. - * - * @param beginDate begin date - * @param endDate end date - * @return all ClosedPeriodicEntryBook between begin and end - * @throws TopiaException - */ - public List<ClosedPeriodicEntryBook> findAllByDates(Date beginDate, - Date endDate) throws TopiaException { - - String query = "FROM " + ClosedPeriodicEntryBook.class.getName() + - " WHERE :begindate <= financialPeriod.beginDate " + - " AND financialPeriod.beginDate <= :endDate" + - " ORDER BY entryBook.code"; - return context.find(query, 0d, 0d, "beginDate", beginDate, "endDate", endDate); - } - -} Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java (from rev 3400, trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAO.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java 2012-05-04 13:17:42 UTC (rev 3401) @@ -0,0 +1,106 @@ +/* + * #%L + * Lima callao + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 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.entity; + +import java.util.Date; +import java.util.List; + +import org.nuiton.topia.TopiaException; + +public class ClosedPeriodicEntryBookDAOImpl<E extends ClosedPeriodicEntryBook> extends ClosedPeriodicEntryBookDAOAbstract<ClosedPeriodicEntryBook> { + + /** + * Find all ClosedPeriodicEntryBook with common EntryBook. + * + * @param entryBook entry book property + * @return ClosedPeriodicEntryBook list + * @throws TopiaException + */ + public List<ClosedPeriodicEntryBook> findAllByEntryBook(EntryBook entryBook) throws TopiaException { + return findAllByProperties(ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, entryBook); + } + + /** + * Return ClosedPeriodicEntryBook by EntryBook and FinancialPeriod. + * + * @param entryBook + * @param financialPeriod + * @return ClosedPeriodicEntryBook + * @throws TopiaException + */ + public ClosedPeriodicEntryBook findByEntryBookAndFinancialPeriod( + EntryBook entryBook, FinancialPeriod financialPeriod) + throws TopiaException { + + List<ClosedPeriodicEntryBook> closedPeriodicEntryBooks; + String query = "FROM " + ClosedPeriodicEntryBook.class.getName(); + if (entryBook != null) { + query += " WHERE entryBook = :entryBook"; + if (financialPeriod != null) { + query += " AND financialPeriod = :financialPeriod"; + //context.find(query, 0, 0, "entryBook", entryBook, "financialPeriod", financialPeriod); + closedPeriodicEntryBooks = context.find(query, "entryBook", entryBook, "financialPeriod", financialPeriod); + } else { + //context.find(query, 0, 0, "entryBook", entryBook); + closedPeriodicEntryBooks = context.find(query, "entryBook", entryBook); + } + } else { + if (financialPeriod != null) { + query += " WHERE financialPeriod = :financialPeriod"; + } + + //context.find(query, 0, 0, "financialPeriod", financialPeriod); + closedPeriodicEntryBooks = context.find(query, "financialPeriod", financialPeriod); + } + + // get only first one + ClosedPeriodicEntryBook result = null; + if (!closedPeriodicEntryBooks.isEmpty()) { + result = closedPeriodicEntryBooks.get(0); + } + return result; + } + + /** + * Retourne toutes les ClosedPeriodicEntryBook par interval de date + * sur les periodes sur lequelles elles portent ordonnée par journal. + * + * @param beginDate begin date + * @param endDate end date + * @return all ClosedPeriodicEntryBook between begin and end + * @throws TopiaException + */ + public List<ClosedPeriodicEntryBook> findAllByDates(Date beginDate, + Date endDate) throws TopiaException { + + String query = "FROM " + ClosedPeriodicEntryBook.class.getName() + + " WHERE :begindate <= financialPeriod.beginDate " + + " AND financialPeriod.beginDate <= :endDate" + + " ORDER BY entryBook.code"; + return context.find(query, 0d, 0d, "beginDate", beginDate, "endDate", endDate); + } + +} Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAO.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAO.java 2012-05-04 09:43:18 UTC (rev 3400) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAO.java 2012-05-04 13:17:42 UTC (rev 3401) @@ -1,97 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 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.entity; - -import java.util.Date; -import java.util.List; - -import org.nuiton.topia.TopiaException; - -public class EntryDAO extends EntryDAOImpl<Entry> { - - /** - * Requete generique qui recupere les entrees equilibrées portant sur un - * compte entre deux dates. - * - * @param account account - * @param beginDate begin date - * @param endDate end date - */ - protected String getEquilibredTransactionQuery(Account account, - 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"; - return query; - } - - /** - * Query for find entries for accountsreports and balancereports - * Just exact and balanced transaction are calculated. - * - * @param account account - * @param beginDate begin date - * @param endDate end date - * @return entries - * @throws TopiaException - */ - public List<Entry> findAllEntryOfEquilibredTransaction(Account account, - Date beginDate, Date endDate) throws TopiaException { - - String query = getEquilibredTransactionQuery(account, beginDate, endDate); - - List<Entry> entries = context.find(query, "beginDate", beginDate, - "endDate", endDate, "account", account); - return entries; - } - - /** - * Retourne la somme des entrées des transaction equilibrées entre - * deux dates pour un compte donné. - * - * @param account le compte - * @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, - Date beginDate, Date endDate) throws TopiaException { - String query = "SELECT E.debit, sum(E.amount) " + - getEquilibredTransactionQuery(account, beginDate, endDate) + - " GROUP BY E.debit"; - - List<Object[]> result = context.find(query, "beginDate", beginDate, - "endDate", endDate, "account", account); - return result; - } -} Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java (from rev 3400, trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAO.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java 2012-05-04 13:17:42 UTC (rev 3401) @@ -0,0 +1,97 @@ +/* + * #%L + * Lima callao + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 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.entity; + +import java.util.Date; +import java.util.List; + +import org.nuiton.topia.TopiaException; + +public class EntryDAOImpl<E extends Entry> extends EntryDAOAbstract<Entry> { + + /** + * Requete generique qui recupere les entrees equilibrées portant sur un + * compte entre deux dates. + * + * @param account account + * @param beginDate begin date + * @param endDate end date + */ + protected String getEquilibredTransactionQuery(Account account, + 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"; + return query; + } + + /** + * Query for find entries for accountsreports and balancereports + * Just exact and balanced transaction are calculated. + * + * @param account account + * @param beginDate begin date + * @param endDate end date + * @return entries + * @throws TopiaException + */ + public List<Entry> findAllEntryOfEquilibredTransaction(Account account, + Date beginDate, Date endDate) throws TopiaException { + + String query = getEquilibredTransactionQuery(account, beginDate, endDate); + + List<Entry> entries = context.find(query, "beginDate", beginDate, + "endDate", endDate, "account", account); + return entries; + } + + /** + * Retourne la somme des entrées des transaction equilibrées entre + * deux dates pour un compte donné. + * + * @param account le compte + * @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, + Date beginDate, Date endDate) throws TopiaException { + String query = "SELECT E.debit, sum(E.amount) " + + getEquilibredTransactionQuery(account, beginDate, endDate) + + " GROUP BY E.debit"; + + List<Object[]> result = context.find(query, "beginDate", beginDate, + "endDate", endDate, "account", account); + return result; + } +} Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAO.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAO.java 2012-05-04 09:43:18 UTC (rev 3400) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAO.java 2012-05-04 13:17:42 UTC (rev 3401) @@ -1,58 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 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.entity; - -import java.util.Date; -import java.util.List; - -import org.nuiton.topia.TopiaException; - -public class FinancialPeriodDAO extends FinancialPeriodDAOImpl<FinancialPeriod> { - - /** - * Return FinancialPeriod by Date. - * Date is include between financialperiod begin and end date. - * - * @param date period middle date - * @return FinancialPeriod for {@code date} - * @throws TopiaException - */ - public FinancialPeriod findByDate(Date date) throws TopiaException { - - String query = "FROM " + FinancialPeriod.class.getName() + - " WHERE beginDate <= :date" + - " AND :date <= endDate"; - - // add unique result here - List<FinancialPeriod> financialPeriod = context.find(query, "date", date); - FinancialPeriod result = null; - if (!financialPeriod.isEmpty()) { - result = financialPeriod.get(0); - } - return result; - } - -} Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAOImpl.java (from rev 3400, trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAO.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAOImpl.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAOImpl.java 2012-05-04 13:17:42 UTC (rev 3401) @@ -0,0 +1,58 @@ +/* + * #%L + * Lima callao + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 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.entity; + +import java.util.Date; +import java.util.List; + +import org.nuiton.topia.TopiaException; + +public class FinancialPeriodDAOImpl<E extends FinancialPeriod> extends FinancialPeriodDAOAbstract<FinancialPeriod> { + + /** + * Return FinancialPeriod by Date. + * Date is include between financialperiod begin and end date. + * + * @param date period middle date + * @return FinancialPeriod for {@code date} + * @throws TopiaException + */ + public FinancialPeriod findByDate(Date date) throws TopiaException { + + String query = "FROM " + FinancialPeriod.class.getName() + + " WHERE beginDate <= :date" + + " AND :date <= endDate"; + + // add unique result here + List<FinancialPeriod> financialPeriod = context.find(query, "date", date); + FinancialPeriod result = null; + if (!financialPeriod.isEmpty()) { + result = financialPeriod.get(0); + } + return result; + } + +} Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAO.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAO.java 2012-05-04 09:43:18 UTC (rev 3400) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAO.java 2012-05-04 13:17:42 UTC (rev 3401) @@ -1,118 +0,0 @@ -/* - * #%L - * Lima callao - * - * $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.entity; - -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. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class FinancialTransactionDAO extends FinancialTransactionDAOImpl<FinancialTransaction> { - - /** - * Return how many transaction are found with specified entryBook. - * - * @param entryBook entry book - * @return transaction referencing entry book - * @throws TopiaException - */ - public long getCountByEntryBook(EntryBook entryBook) throws TopiaException { - String query = "SELECT count(*) FROM " + FinancialTransaction.class.getName() + " t WHERE t.entryBook = :entryBook"; - Number count = (Number)context.find(query, "entryBook", entryBook).get(0); - return count.longValue(); - } - - /** - * Find all unbalanced transactions. - * - * @param period period - * @param entryBook entry book - * @return unbalanced transactions - * @throws TopiaException - */ - public List<FinancialTransaction> getAllUnbalancedTransaction(FinancialPeriod period, - 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); - return result; - } - - /** - * Find all transaction where some field are not filled in. - * - * @param period period - * @param entryBook entry book - * @return unfilled transaction - * @throws TopiaException - */ - public List<FinancialTransaction> getAllUnfilledTransaction(FinancialPeriod period, - 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); - return result; - } - - /** - * 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"); - 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); - return result; - } - -} //FinancialTransactionDAO Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java (from rev 3397, trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAO.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java 2012-05-04 13:17:42 UTC (rev 3401) @@ -0,0 +1,118 @@ +/* + * #%L + * Lima callao + * + * $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.entity; + +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. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class FinancialTransactionDAOImpl<E extends FinancialTransaction> extends FinancialTransactionDAOAbstract<FinancialTransaction> { + + /** + * Return how many transaction are found with specified entryBook. + * + * @param entryBook entry book + * @return transaction referencing entry book + * @throws TopiaException + */ + public long getCountByEntryBook(EntryBook entryBook) throws TopiaException { + String query = "SELECT count(*) FROM " + FinancialTransaction.class.getName() + " t WHERE t.entryBook = :entryBook"; + Number count = (Number)context.find(query, "entryBook", entryBook).get(0); + return count.longValue(); + } + + /** + * Find all unbalanced transactions. + * + * @param period period + * @param entryBook entry book + * @return unbalanced transactions + * @throws TopiaException + */ + public List<FinancialTransaction> getAllUnbalancedTransaction(FinancialPeriod period, + 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); + return result; + } + + /** + * Find all transaction where some field are not filled in. + * + * @param period period + * @param entryBook entry book + * @return unfilled transaction + * @throws TopiaException + */ + public List<FinancialTransaction> getAllUnfilledTransaction(FinancialPeriod period, + 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); + return result; + } + + /** + * 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"); + 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); + return result; + } + +} //FinancialTransactionDAO
participants (1)
-
echatellier@users.chorem.org