Author: athimel Date: 2014-05-16 17:54:31 +0200 (Fri, 16 May 2014) New Revision: 3810 Url: http://forge.chorem.org/projects/lima/repository/revisions/3810 Log: Fix Dao naming Added: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FiscalPeriodTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/VatStatementTopiaDao.java Removed: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractAccountTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractClosedPeriodicEntryBookTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractEntryTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialPeriodTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialStatementTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialTransactionTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFiscalPeriodTopiaDao.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractVatStatementTopiaDao.java Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractAccountTopiaDao.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractAccountTopiaDao.java 2014-05-16 15:47:37 UTC (rev 3809) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractAccountTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -1,192 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id: AccountDAOImpl.java 3613 2012-08-20 11:38:22Z mallon $ - * $HeadURL: http://svn.chorem.org/svn/lima/trunk/lima-callao/src/main/java/org/chorem/li... $ - * %% - * 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.Map; -import java.util.Set; -import java.util.StringTokenizer; - -import com.google.common.collect.Maps; -import org.apache.commons.lang3.StringUtils; -import org.nuiton.topia.persistence.TopiaException; - -public class AbstractAccountTopiaDao<E extends Account> extends GeneratedAccountTopiaDao<E> { - - /** - * 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 = find(query);*/ - - // code temporaire non performant en attandant: - List<Account> allAccounts = (List<Account>) 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 forAccountNumberEquals(number).findUniqueOrNull(); - } - - /** - * 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"; - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("accountNumberLow", accountNumberLow); - args.put("accountNumberHigh", accountNumberHigh); - return findAll(query, args); - } - - /** - * 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, '_%')"; - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("accountNumber", account.getAccountNumber()); - List<Account> accounts = findAll(query, args); - - 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; - 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 { - String query = "FROM " + Account.class.getName() + " a WHERE a NOT IN (" + - "FROM " + Account.class.getName() + " b where b.accountNumber like a.accountNumber+'%')" + - " AND a.accountNumber LIKE :s"; - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("s",s); - List<Account> accountsResult = findAll(query, args); - 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/AbstractClosedPeriodicEntryBookTopiaDao.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractClosedPeriodicEntryBookTopiaDao.java 2014-05-16 15:47:37 UTC (rev 3809) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractClosedPeriodicEntryBookTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -1,225 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id: ClosedPeriodicEntryBookDAOImpl.java 3476 2012-06-26 15:48:13Z echatellier $ - * $HeadURL: http://svn.chorem.org/lima/trunk/lima-callao/src/main/java/org/chorem/lima/e... $ - * %% - * 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 java.util.Map; - -import com.google.common.collect.Maps; -import org.hibernate.HibernateException; -import org.nuiton.topia.persistence.TopiaException; - -public class AbstractClosedPeriodicEntryBookTopiaDao<E extends ClosedPeriodicEntryBook> extends GeneratedClosedPeriodicEntryBookTopiaDao<E> { - - /** - * FIXME echatellier, remove this method when implemented in topia - * just overriden to use merge() instead of saveOrUpdate() - */ - public ClosedPeriodicEntryBook merge(ClosedPeriodicEntryBook e) throws TopiaException { - try { -// e = (ClosedPeriodicEntryBook)getContext().getHibernate().merge(e); -// getContext().getFiresSupport().warnOnUpdateEntity(e); -// return e; - // TODO DCossé 15/05/14 don't know how to get hibernate - return null; - } catch (HibernateException ex) { - throw new TopiaException(ex); - } - } - - /** - * 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 (List<ClosedPeriodicEntryBook>) forProperties(ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, entryBook).findAll(); - } - - /** - * 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(); - - Map<String, Object> args = Maps.newLinkedHashMap(); - - if (entryBook != null) { - args.put("entryBook", entryBook); - query += " WHERE entryBook = :entryBook"; - if (financialPeriod != null) { - args.put("financialPeriod", financialPeriod); - query += " AND financialPeriod = :financialPeriod"; - //find(query, 0, 0, "entryBook", entryBook, "financialPeriod", financialPeriod); - closedPeriodicEntryBooks = findAll(query, args); - } else { - //find(query, 0, 0, "entryBook", entryBook); - closedPeriodicEntryBooks = findAll(query, args); - } - } else { - if (financialPeriod != null) { - args.put("financialPeriod", financialPeriod); - query += " WHERE financialPeriod = :financialPeriod"; - } - - //find(query, 0, 0, "financialPeriod", financialPeriod); - closedPeriodicEntryBooks = findAll(query, args); - } - - // 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"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate", beginDate); - args.put("endDate", endDate); - - return findAll(query, args); - } - - /** - * 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"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate", beginDate); - args.put("endDate", endDate); - args.put("entryBook", entryBook); - return findAll(query, args); - } - - /** - * 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"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate", beginDate); - args.put("endDate", endDate); - args.put("entryBook", entryBook); - return findAll(query, args); - } - - /** - * Retourne les ClosedPeriodicEntryBook de toutes les exercices encore ouverts. - * - * @return les ClosedPeriodicEntryBook - * @throws TopiaException - */ - public List<ClosedPeriodicEntryBook> findAllClosedPeriodicEntryBooksFromUnblockedFiscalPeriod() throws TopiaException { - String query = "SELECT C FROM " + ClosedPeriodicEntryBook.class.getName() + " C" + - ", " + FiscalPeriod.class.getName() + " F" + - " WHERE C.financialPeriod IN ELEMENTS (F.financialPeriod)" + - " AND F.locked = false" + - " ORDER BY C.financialPeriod.beginDate"; - - List<ClosedPeriodicEntryBook> result = findAll(query); - return result; - } - - /** - * Retourne les ClosedPeriodicEntryBook d'un exercice ouvert. - * - * @return les ClosedPeriodicEntryBook - * @throws TopiaException - */ - public List<ClosedPeriodicEntryBook> findAllClosedPeriodicEntryBooksFromFiscalPeriod(FiscalPeriod fiscalPeriod) throws TopiaException { - String query = "SELECT C FROM " + ClosedPeriodicEntryBook.class.getName() + " C" + - ", " + FiscalPeriod.class.getName() + " F" + - " WHERE C.financialPeriod IN ELEMENTS (F.financialPeriod)" + - " AND F = :fiscalPeriod" + - " ORDER BY C.financialPeriod.beginDate"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("fiscalPeriod", fiscalPeriod); - - List<ClosedPeriodicEntryBook> result = findAll(query, args); - - return result; - } - -} Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractEntryTopiaDao.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractEntryTopiaDao.java 2014-05-16 15:47:37 UTC (rev 3809) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractEntryTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -1,323 +0,0 @@ -/* - * #%L - * Lima callao - * * - * $Id: EntryDAOImpl.java 3783 2014-05-06 16:47:18Z dcosse $ - * $HeadURL: http://svn.chorem.org/lima/trunk/lima-callao/src/main/java/org/chorem/lima/e... $ - * %% - * 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 com.google.common.collect.Maps; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.beans.LetteringFilter; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; - -public class AbstractEntryTopiaDao<E extends Entry> extends GeneratedEntryTopiaDao<E> { - - private static final Log log = LogFactory.getLog(AbstractEntryTopiaDao.class); - - /** - * Requete generique qui recupere les entrees equilibrées portant entre - * deux dates. - * - * @param beginDate begin date - * @param endDate end date - */ - 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"; - 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 - */ - public List<Entry> findAllEntryOfBalancedTransaction(Account account, - Date beginDate, Date endDate) { - - String query = getEquilibredTransactionQuery(beginDate, endDate) + - // concerne le compte - " AND E.account = :account"; - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate", beginDate); - args.put("endDate", endDate); - args.put("account", account); - - List<Entry> entries = findAll(query, args); - - return entries; - } - - /** - * Retourne la somme des entrées des transaction equilibrées entre - * deux dates pour un compte donné. - * - * @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) - */ - public List<Object[]> getDebitCreditOfBalancedTransaction(Account account, - Date beginDate, Date endDate) { - String query = "SELECT E.debit, sum(E.amount) " + - getEquilibredTransactionQuery(beginDate, endDate) + - // concerne le compte - " AND E.account = :account" + - " GROUP BY E.debit"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate", beginDate); - args.put("endDate", endDate); - args.put("account", account); - - List<Object[]> result = findAll(query, args); - 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 - */ - public List<Entry> findAllEntryOfBalancedTransaction(EntryBook entryBook, Date beginDate, - Date endDate) { - String query = getEquilibredTransactionQuery(beginDate, endDate) + - // concerne le journal - " AND E.financialTransaction.entryBook = :entryBook" + - // fix order - " ORDER BY E.financialTransaction.transactionDate, E.financialTransaction.topiaId"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate", beginDate); - args.put("endDate", endDate); - args.put("entryBook", entryBook); - - List<Entry> entries = findAll(query, args); - return entries; - } - - public List<String> findLetters() { - String query = "Select distinct E.lettering FROM " + Entry.class.getName() + " E" + - " where E.lettering <> null" + - " order by E.lettering desc"; - - List<String> result = new ArrayList<String>(this.<String>findAll(query)); - - if (log.isDebugEnabled()) { - log.debug("Size of result : " + result.size()); - } - - return result; - } - - /** - * 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) - */ - public List<Object[]> getDebitCreditOfBalancedTransaction(EntryBook entryBook, - Date beginDate, Date endDate) { - String query = "SELECT E.debit, sum(E.amount) " + - getEquilibredTransactionQuery(beginDate, endDate) + - // concerne le journal - " AND E.financialTransaction.entryBook = :entryBook" + - " GROUP BY E.debit"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate", beginDate); - args.put("endDate", endDate); - args.put("entryBook", entryBook); - - List<Object[]> result = findAll(query, args); - return result; - } - - /** - * Retourne les entrees des transaction entre deux dates pour - * un journal. - * - * @param entryBook entry book - * @param beginDate begin date - * @param endDate end date - */ - public List<Entry> findAllEntryByDateForEntryBook(EntryBook entryBook, Date beginDate, - Date endDate) { - String query = "FROM " + Entry.class.getName() + " E" + - // entre les 2 dates - " WHERE :beginDate <= E.financialTransaction.transactionDate" + - " AND E.financialTransaction.transactionDate <= :endDate" + - // concerne le journal - " AND E.financialTransaction.entryBook = :entryBook"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate", beginDate); - args.put("endDate", endDate); - args.put("entryBook", entryBook); - - List<Entry> entries = findAll(query, args); - return entries; - } - - /** - * Retourne toutes les entrées d'une transaction - * pour un compte et la présence d'un lettrage ou (xor) non - * @param filter filtre sur les entrees, selon le compte, les dates de debut et de fin, et le lettrage - * */ - public List<Entry> findAllEntryByFilter(LetteringFilter filter) { - - List<Entry> entries; - Account account = filter.getAccount(); - - if (account != null && account.getTopiaId() == null) { - // case user want to see all accounts - entries = getAllEntryByLetteringAndDateForEntryBook(filter); - } else { - entries = getAllEntryByAccountLetteringAndDateForEntryBook(filter); - } - return entries; - } - - public List<Entry> getAllEntryByAccountLetteringAndDateForEntryBook(LetteringFilter filter) { - List<Entry> entries; - - String query = "Select E from " + Entry.class.getName() + " E " + - " where E.account.accountNumber like :account "; - - - if (!filter.getDisplayLettered() && filter.getDisplayUnlettred()){ - query += " and (E.lettering is null or E.lettering = '') "; - } else if (filter.getDisplayLettered() && !filter.getDisplayUnlettred()){ - query += " and (E.lettering is not null or E.lettering !='') "; - } - - query += " and E.financialTransaction.transactionDate between :beginDate and :endDate " + - " order by E.financialTransaction.transactionDate, E.financialTransaction." + FinancialTransaction.PROPERTY_TOPIA_CREATE_DATE; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate", filter.getDateStart()); - args.put("endDate", filter.getDateEnd()); - args.put("account", filter.getAccount().getAccountNumber() + "%"); - entries = findAll(query, args); - - return entries; - } - - public List<Entry> getAllEntryByLetteringAndDateForEntryBook(LetteringFilter filter) { - List<Entry> entries; - - String query = "Select E from " + Entry.class.getName() + " E "; - - query += " WHERE E.financialTransaction.transactionDate BETWEEN :beginDate and :endDate "; - - if (!filter.getDisplayLettered() && filter.getDisplayUnlettred()){ - query += " and (E.lettering is null or E.lettering = '') "; - } else if (filter.getDisplayLettered() && !filter.getDisplayUnlettred()){ - query += " and (E.lettering is not null or E.lettering !='') "; - } - - query += " order by E.financialTransaction.transactionDate, E.financialTransaction." + FinancialTransaction.PROPERTY_TOPIA_CREATE_DATE; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate", filter.getDateStart()); - args.put("endDate", filter.getDateEnd()); - - entries = findAll(query, args); - - return entries; - } - - - /** - * Retourne la dernière entrée d'une transaction - * @param financialTransaction transaction sur laquelle la derniere entree est selectionnee - * */ - public Entry getLastEntry(FinancialTransaction financialTransaction) { - List<Entry> entries; - Entry lastEntry = null; - String query = "Select E from " + Entry.class.getName() + " E" + - " where E.financialTransaction.transactionDate = :financialTransactionDate " + - " and E.financialTransaction = :financialTransaction" + - " order by E.topiaCreateDate desc"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("financialTransactionDate", financialTransaction.getTransactionDate()); - args.put("financialTransaction", financialTransaction); - - entries = findAll(query, args); - if (entries.size() > 0) { - lastEntry = entries.get(0); - } - - return lastEntry; - } - - /** - * Retourne la somme des entrées des transaction 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) - */ - public List<Object[]> getDebitCreditOfTransaction(EntryBook entryBook, - Date beginDate, Date endDate) { - String query = "SELECT E.debit, sum(E.amount) " + - "FROM " + Entry.class.getName() + " E" + - // entre les 2 dates - " WHERE :beginDate <= E.financialTransaction.transactionDate" + - " AND E.financialTransaction.transactionDate <= :endDate" + - // concerne le journal - " AND E.financialTransaction.entryBook = :entryBook" + - " GROUP BY E.debit"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate", beginDate); - args.put("endDate", endDate); - args.put("entryBook", entryBook); - - List<Object[]> result = findAll(query, args); - return result; - } -} Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialPeriodTopiaDao.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialPeriodTopiaDao.java 2014-05-16 15:47:37 UTC (rev 3809) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialPeriodTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -1,112 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id: FinancialPeriodDAOImpl.java 3476 2012-06-26 15:48:13Z echatellier $ - * $HeadURL: http://svn.chorem.org/svn/lima/trunk/lima-callao/src/main/java/org/chorem/li... $ - * %% - * 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 java.util.Map; - -import com.google.common.collect.Maps; -import org.nuiton.topia.persistence.TopiaException; - -public class AbstractFinancialPeriodTopiaDao<E extends FinancialPeriod> extends GeneratedFinancialPeriodTopiaDao<E> { - - /** - * 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"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("date", date); - // add unique result here - FinancialPeriod financialPeriod = (FinancialPeriod)findUnique(query, args); - return financialPeriod; - } - - /** - * Return all FinancialPeriod with begin date between two given dates. - * - * @param beginDate period begin date - * @param endDate period end date - * @return FinancialPeriod for {@code date} - * @throws TopiaException - */ - public List<FinancialPeriod> findByDates(Date beginDate, Date endDate) throws TopiaException { - - String query = "FROM " + FinancialPeriod.class.getName() + - " WHERE :beginDate <= beginDate" + - " AND beginDate <= :endDate" + - " ORDER by beginDate"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate", beginDate); - args.put("endDate", endDate); - // add unique result here - List<FinancialPeriod> financialPeriod = findAll(query, args); - return financialPeriod; - } - - /** - * Retourne toutes les periodes ordonnées par date de debut de periode. - * - * @return all period ordered - * @throws TopiaException - */ - public List<FinancialPeriod> findAllOrderByBeginDate() throws TopiaException { - String query = "FROM " + FinancialPeriod.class.getName() + - " ORDER BY beginDate"; - - // add unique result here - List<FinancialPeriod> financialPeriod = findAll(query); - return financialPeriod; - } - - /** - * Retourne toutes les periodes ordonnées par date de debut de periode. - * - * @return all period ordered - * @throws TopiaException - */ - public List<FinancialPeriod> findAllUnlockedOrderByBeginDate() throws TopiaException { - String query = "FROM " + FinancialPeriod.class.getName() + - " WHERE locked = false" + - " ORDER BY beginDate"; - - // add unique result here - List<FinancialPeriod> financialPeriod = findAll(query); - return financialPeriod; - } - -} Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialStatementTopiaDao.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialStatementTopiaDao.java 2014-05-16 15:47:37 UTC (rev 3809) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialStatementTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -1,79 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id: FinancialStatementDAOImpl.java 3585 2012-08-08 14:52:14Z tchemit $ - * $HeadURL: http://svn.chorem.org/svn/lima/trunk/lima-callao/src/main/java/org/chorem/li... $ - * %% - * 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 com.google.common.collect.Maps; - -import java.util.List; -import java.util.Map; - - -/** - * Ajout de requetes specifiques aux {@link FinancialStatement} sur le DAO. - * - * @author chatellier - * @version $Revision: 3585 $ - * - * Last update : $Date: 2012-08-08 16:52:14 +0200 (mer. 08 août 2012) $ - * By : $Author: tchemit $ - */ -public class AbstractFinancialStatementTopiaDao<E extends FinancialStatement> extends GeneratedFinancialStatementTopiaDao<E> { - - /** - * Find all {@code FinancialStatement} ordered by topia create date. - */ - public List<FinancialStatement> findAllOrderedByCreateDate() { - String query = "FROM " + FinancialStatement.class.getName() + - " ORDER BY " + FinancialStatement.PROPERTY_TOPIA_CREATE_DATE; - List<FinancialStatement> result = findAll(query); - return result; - } - - /** - * Find all {@code FinancialStatement} ordered by topia create date. - */ - public List<FinancialStatement> findChildrenFinancialStatement(FinancialStatement financialStatement) { - String query = "FROM " + FinancialStatement.class.getName(); - - if (financialStatement == null) { - query += " WHERE masterFinancialStatement = null"; - } else { - query += " WHERE masterFinancialStatement = :masterFinancialStatement"; - } - query += " ORDER BY " + FinancialStatement.PROPERTY_TOPIA_CREATE_DATE; - - List<FinancialStatement> result; - if (financialStatement == null) { - result = findAll(query); - } else { - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("masterFinancialStatement", financialStatement); - result = findAll(query, args); - } - return result; - } - -} //FinancialStatementDAO Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialTransactionTopiaDao.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialTransactionTopiaDao.java 2014-05-16 15:47:37 UTC (rev 3809) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialTransactionTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -1,329 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id: FinancialTransactionDAOImpl.java 3688 2013-06-27 13:12:22Z Bavencoff $ - * $HeadURL: http://svn.chorem.org/svn/lima/trunk/lima-callao/src/main/java/org/chorem/li... $ - * %% - * 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 com.google.common.collect.Maps; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.Filter.Filter; -import org.hibernate.HibernateException; -import org.nuiton.topia.persistence.TopiaException; -import org.nuiton.topia.persistence.event.TopiaContextAdapter; - -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Ajout de requetes specifiques aux financial transaction sur le DAO. - * - * @author chatellier - * @version $Revision: 3688 $ - * - * Last update : $Date: 2013-06-27 15:12:22 +0200 (jeu. 27 juin 2013) $ - * By : $Author: Bavencoff $ - */ -public class AbstractFinancialTransactionTopiaDao<E extends FinancialTransaction> extends GeneratedFinancialTransactionTopiaDao<E> { - - private static final Log log = LogFactory.getLog(AbstractFinancialTransactionTopiaDao.class); - - /** - * FIXME echatellier, remove this method when implemented in topia - * just overriden to use merge() instead of saveOrUpdate() - */ - public FinancialTransaction merge(FinancialTransaction e) { -// try { -// e = (FinancialTransaction) getContext().getHibernate().merge(e); -// getContext().getFiresSupport().warnOnUpdateEntity(e); -// return e; -// } catch (HibernateException ex) { -// throw new TopiaException(ex); -// } - // TODO DCossé 15/05/14 find a way to get hibernate - return null; - } - - /** - * Return how many transaction are found with specified entryBook. - * - * @param entryBook entry book - * @return transaction referencing entry book - */ - public long getCountByEntryBook(EntryBook entryBook) { - String query = "SELECT count(*) FROM " + FinancialTransaction.class.getName() + " t WHERE t.entryBook = :entryBook"; - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("entryBook", entryBook); - Number count = (Number)findAll(query, args).get(0); - return count.longValue(); - } - - /** - * Find all transactions between two dates. - * - * @param beginDate begin date - * @param endDate end date - * @return unbalanced transactions - */ - public List<FinancialTransaction> findAllByDates(Date beginDate, Date endDate) { - String query = "FROM " + FinancialTransaction.class.getName() + " T"+ - " WHERE :beginDate <= T.transactionDate" + - " AND T.transactionDate <= :endDate" + - " ORDER BY T.transactionDate, T." + FinancialTransaction.PROPERTY_TOPIA_CREATE_DATE; - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate",beginDate); - args.put("endDate", endDate); - List<FinancialTransaction> result = findAll(query,args); - return result; - } - - /** - * Find all transactions between two dates in an entry book. - * - * @param beginDate begin date - * @param endDate end date - * @param entryBook entry book - * @return unbalanced transactions - */ - public List<FinancialTransaction> findAllByDates(Date beginDate, Date endDate, EntryBook entryBook) { - String query = "FROM " + FinancialTransaction.class.getName() + " T"+ - " WHERE :beginDate <= T.transactionDate" + - " AND T.transactionDate <= :endDate" + - " AND T.entryBook = :entryBook" + - " ORDER BY T.transactionDate, T." + FinancialTransaction.PROPERTY_TOPIA_CREATE_DATE; - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate",beginDate); - args.put("endDate", endDate); - args.put("entryBook", entryBook); - List<FinancialTransaction> result = findAll(query, args); - return result; - } - - /** - * Find all unbalanced transactions. - * - * @param beginDate beginDate - * @param endDate endDate - * @param entryBook entry book (can be null) - * @return unbalanced transactions - */ - public List<FinancialTransaction> getAllUnbalancedTransaction(Date beginDate, Date endDate, - EntryBook entryBook) { - 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 :beginDate <= T.transactionDate" + - " AND T.transactionDate <= :endDate"; - List<FinancialTransaction> result; - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate",beginDate); - args.put("endDate", endDate); - if (entryBook != null) { - args.put("entryBook", entryBook); - query += " AND T.entryBook = :entryBook"; - result = findAll(query, args); - } else { - result = findAll(query, args); - } - - return result; - } - - /** - * Find all unbalanced transactions. - * - * @param beginDate beginDate - * @param endDate endDate - * @param entryBook entry book (can be null) - * @return unbalanced transactions - */ - public List<FinancialTransaction> getAllBalancedTransaction(Date beginDate, Date endDate, - EntryBook entryBook) { - 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 :beginDate <= T.transactionDate" + - " AND T.transactionDate <= :endDate"; - List<FinancialTransaction> result; - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate",beginDate); - args.put("endDate", endDate); - - if (entryBook != null) { - args.put("entryBook", entryBook); - query += " AND T.entryBook = :entryBook"; - result = findAll(query, args); - } else { - result = findAll(query, args); - } - - return result; - } - - /** - * Find all unbalanced transactions. - * - * @param beginDate beginDate - * @param endDate endDate - * @param entryBook entry book (can be null) - * @return unbalanced transactions - */ - public List<FinancialTransaction> getAllIncorrectTransaction(Date beginDate, Date endDate, - EntryBook entryBook) { - String query = "SELECT distinct T 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 (SELECT sum(amount) FROM " + Entry.class.getName() + - " WHERE debit = true AND financialTransaction = T) IS NULL" + - " OR (SELECT sum(amount) FROM " + Entry.class.getName() + - " WHERE debit = false AND financialTransaction = T) IS NULL" + - " OR E.account = null" + - " OR E.voucher = null" + - " OR E.voucher = ''" + - " OR E.description = null" + - " OR E.description = '')" + - " AND :beginDate <= T.transactionDate" + - " AND T.transactionDate <= :endDate"; - List<FinancialTransaction> result; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate",beginDate); - args.put("endDate", endDate); - if (entryBook != null) { - args.put("entryBook", entryBook); - query += " AND T.entryBook = :entryBook"; - result = findAll(query, args); - } else { - result = findAll(query, args); - } - - return result; - } - - /** - * Find all transaction where some field are not filled in. - * - * @param beginDate begin date - * @param endDate end date - * @param entryBook entry book - * @return unfilled transaction - */ - public List<FinancialTransaction> getAllUnfilledTransaction(Date beginDate, - Date endDate, EntryBook entryBook) { - String query = "SELECT T 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 :beginDate <= T.transactionDate" + - " AND T.transactionDate <= :endDate"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate",beginDate); - args.put("endDate", endDate); - args.put("entryBook", entryBook); - List<FinancialTransaction> result = findAll(query, args); - return result; - } - - /** - * Find all transaction without entry book. - * - * @param beginDate begin date - * @param endDate end date - * @return transaction without entry books - */ - public List<FinancialTransaction> getAllTransactionWithoutEntryBook(Date beginDate, - Date endDate) { - - String query = "SELECT T 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" + - " AND :beginDate <= T.transactionDate" + - " AND T.transactionDate <= :endDate"; - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("beginDate",beginDate); - args.put("endDate", endDate); - - List<FinancialTransaction> result = findAll(query, args); - - return result; - } - - /** - * Search financial transaction. - * - * - * @param filter filter parameters - * @return financial transaction - */ - public List<FinancialTransaction> searchFinancialTransaction(Filter filter) { - - GeneratorHQuery generator = new GeneratorHQuery(); - filter.accept(generator); - - - String query = generator.getHQuery(); - Map<String,Object> arguments = generator.getParameters(); - - if (log.isDebugEnabled()) { - Set<String> parameters = arguments.keySet(); - for(String param : parameters) { - log.debug("Query : \n" + query + "\nArguments: " + param); - } - } - - // perform query - List<FinancialTransaction> result; - if (arguments.isEmpty()) { - result = findAll(query); - } else { - result = findAll(query, arguments); - } - - if (log.isDebugEnabled()) { - log.debug("Number of founded transactions : " + result.size()); - } - - return result; - } - -} //FinancialTransactionDAO Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFiscalPeriodTopiaDao.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFiscalPeriodTopiaDao.java 2014-05-16 15:47:37 UTC (rev 3809) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFiscalPeriodTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -1,140 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id: FiscalPeriodDAOImpl.java 3598 2012-08-10 16:31:26Z mallon $ - * $HeadURL: http://svn.chorem.org/svn/lima/trunk/lima-callao/src/main/java/org/chorem/li... $ - * %% - * 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 java.util.Map; - -import com.google.common.collect.Maps; -import org.hibernate.HibernateException; -import org.nuiton.topia.persistence.TopiaException; - -/** - * Fiscal period entity DAO. - * - * @author chatellier - * @version $Revision: 3598 $ - * - * Last update : $Date: 2012-08-10 18:31:26 +0200 (ven. 10 août 2012) $ - * By : $Author: mallon $ - */ -public class AbstractFiscalPeriodTopiaDao<E extends FiscalPeriod> extends GeneratedFiscalPeriodTopiaDao<E> { - - /** - * FIXME echatellier, remove this method when implemented in topia - * just overriden to use merge() instead of saveOrUpdate() - */ - @Override - public FiscalPeriod update(FiscalPeriod e) throws TopiaException { - try { -// getContext().getHibernate().merge(e); -// getContext().getFiresSupport().warnOnUpdateEntity(e); -// return e; - // TODO DCossé 15/05/14 find a way to do it - return null; - } catch (HibernateException ex) { - throw new TopiaException(ex); - } - } - - /** - * Find fiscal period by financial period. - * - * @param financialPeriod financial period - * @return fiscal period containing financial period - * @throws TopiaException - */ - public FiscalPeriod findByFinancialPeriod(FinancialPeriod financialPeriod) throws TopiaException { - String query = "FROM " + FiscalPeriod.class.getName() + - " WHERE :financialPeriod in elements(financialPeriod)"; - - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("financialPeriod", financialPeriod); - - List<FiscalPeriod> fiscalPeriods = findAll(query, args); - FiscalPeriod result = null; - if (!fiscalPeriods.isEmpty()) { - result = fiscalPeriods.get(0); - } - return result; - } - - /** - * Get last fiscal period (higher end date). - * - * @return last fiscal period - * @throws TopiaException - */ - public FiscalPeriod getLastFiscalPeriod() throws TopiaException { - String query = "FROM " + FiscalPeriod.class.getName() + - " ORDER BY endDate desc"; - - List<FiscalPeriod> fiscalPeriods = findAll(query); - FiscalPeriod result = null; - if (!fiscalPeriods.isEmpty()) { - result = fiscalPeriods.get(0); - } - - return result; - } - - /** - * Get first fiscal period (higher end date). - * - * @return last fiscal period - * @throws TopiaException - */ - public FiscalPeriod getFirstFiscalPeriod() throws TopiaException { - String query = "FROM " + FiscalPeriod.class.getName() + - " ORDER BY endDate"; - - List<FiscalPeriod> fiscalPeriods = findAll(query); - FiscalPeriod result = null; - if (!fiscalPeriods.isEmpty()) { - result = fiscalPeriods.get(0); - } - return result; - } - - /** - * Get last non locked fiscal period (higher end date). - * - * @return last fiscal period - * @throws TopiaException - */ - public FiscalPeriod getLastUnlockedFiscalPeriod() throws TopiaException { - String query = "FROM " + FiscalPeriod.class.getName() + - " WHERE locked = false" + - " ORDER BY endDate desc"; - - List<FiscalPeriod> fiscalPeriods = findAll(query); - FiscalPeriod result = null; - if (!fiscalPeriods.isEmpty()) { - result = fiscalPeriods.get(0); - } - return result; - } -} Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractVatStatementTopiaDao.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractVatStatementTopiaDao.java 2014-05-16 15:47:37 UTC (rev 3809) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractVatStatementTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -1,103 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id: VatStatementDAOImpl.java 3585 2012-08-08 14:52:14Z tchemit $ - * $HeadURL: http://svn.chorem.org/svn/lima/trunk/lima-callao/src/main/java/org/chorem/li... $ - * %% - * 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 com.google.common.collect.Maps; - -import java.util.List; -import java.util.Map; - - -/** - * Ajout de requetes specifiques aux {@code VatStatement} sur le DAO. - * - * @author chatellier - * @version $Revision: 3585 $ - * - * Last update : $Date: 2012-08-08 16:52:14 +0200 (mer. 08 août 2012) $ - * By : $Author: tchemit $ - */ -public class AbstractVatStatementTopiaDao<E extends VatStatement> extends GeneratedVatStatementTopiaDao<E> { - - /** - * Find all {@code VatStatement} ordered by topia create date. - */ - public List<VatStatement> findAllOrderedByCreateDate() { - String query = "FROM " + VatStatement.class.getName() + - " ORDER BY " + VatStatement.PROPERTY_TOPIA_CREATE_DATE; - List<VatStatement> result = findAll(query); - return result; - } - - /** - * Get masterVatStatement children statement. - * - * @param masterVatStatement master VatStatement - * @return children VatStatement - */ - public List<VatStatement> getChildrenVatStatement(VatStatement masterVatStatement) { - String query = "FROM " + VatStatement.class.getName(); - - if (masterVatStatement == null) { - query += " WHERE masterVatStatement = null"; - } else { - query += " WHERE masterVatStatement = :masterVatStatement"; - } - - query += " ORDER BY " + VatStatement.PROPERTY_TOPIA_CREATE_DATE; - List<VatStatement> result; - if (masterVatStatement == null) { - result = findAll(query); - } else { - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("masterVatStatement", masterVatStatement); - result = findAll(query, args); - } - return result; - } - - /** - * Recherche un statement par equivalence de label. - * - * TODO voir a quoi ca sert vraiment. - * - * @param label label - * @return statement like label - */ - public VatStatement findVatStatementByLabel(String label) { - String query = "FROM " + VatStatement.class.getName() + - " WHERE label LIKE :label"; - Map<String, Object> args = Maps.newLinkedHashMap(); - args.put("label", "%" + label + "%"); - List<VatStatement> statements = findAll(query, args); - VatStatement result = null; - if (!statements.isEmpty()) { - result = statements.get(0); - } - return result; - } - -} //VatStatementDAO Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountTopiaDao.java (from rev 3808, trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractAccountTopiaDao.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountTopiaDao.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -0,0 +1,192 @@ +/* + * #%L + * Lima callao + * + * $Id: AccountDAOImpl.java 3613 2012-08-20 11:38:22Z mallon $ + * $HeadURL: http://svn.chorem.org/svn/lima/trunk/lima-callao/src/main/java/org/chorem/li... $ + * %% + * 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.Map; +import java.util.Set; +import java.util.StringTokenizer; + +import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; +import org.nuiton.topia.persistence.TopiaException; + +public class AccountTopiaDao extends AbstractAccountTopiaDao<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 = find(query);*/ + + // code temporaire non performant en attandant: + List<Account> allAccounts = (List<Account>) 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 forAccountNumberEquals(number).findUniqueOrNull(); + } + + /** + * 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"; + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("accountNumberLow", accountNumberLow); + args.put("accountNumberHigh", accountNumberHigh); + return findAll(query, args); + } + + /** + * 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, '_%')"; + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("accountNumber", account.getAccountNumber()); + List<Account> accounts = findAll(query, args); + + 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; + 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 { + String query = "FROM " + Account.class.getName() + " a WHERE a NOT IN (" + + "FROM " + Account.class.getName() + " b where b.accountNumber like a.accountNumber+'%')" + + " AND a.accountNumber LIKE :s"; + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("s",s); + List<Account> accountsResult = findAll(query, args); + 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/ClosedPeriodicEntryBookTopiaDao.java (from rev 3809, trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractClosedPeriodicEntryBookTopiaDao.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookTopiaDao.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -0,0 +1,225 @@ +/* + * #%L + * Lima callao + * + * $Id: ClosedPeriodicEntryBookDAOImpl.java 3476 2012-06-26 15:48:13Z echatellier $ + * $HeadURL: http://svn.chorem.org/lima/trunk/lima-callao/src/main/java/org/chorem/lima/e... $ + * %% + * 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 java.util.Map; + +import com.google.common.collect.Maps; +import org.hibernate.HibernateException; +import org.nuiton.topia.persistence.TopiaException; + +public class ClosedPeriodicEntryBookTopiaDao extends AbstractClosedPeriodicEntryBookTopiaDao<ClosedPeriodicEntryBook> { + + /** + * FIXME echatellier, remove this method when implemented in topia + * just overriden to use merge() instead of saveOrUpdate() + */ + public ClosedPeriodicEntryBook merge(ClosedPeriodicEntryBook e) throws TopiaException { + try { +// e = (ClosedPeriodicEntryBook)getContext().getHibernate().merge(e); +// getContext().getFiresSupport().warnOnUpdateEntity(e); +// return e; + // TODO DCossé 15/05/14 don't know how to get hibernate + return null; + } catch (HibernateException ex) { + throw new TopiaException(ex); + } + } + + /** + * 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 (List<ClosedPeriodicEntryBook>) forProperties(ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, entryBook).findAll(); + } + + /** + * 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(); + + Map<String, Object> args = Maps.newLinkedHashMap(); + + if (entryBook != null) { + args.put("entryBook", entryBook); + query += " WHERE entryBook = :entryBook"; + if (financialPeriod != null) { + args.put("financialPeriod", financialPeriod); + query += " AND financialPeriod = :financialPeriod"; + //find(query, 0, 0, "entryBook", entryBook, "financialPeriod", financialPeriod); + closedPeriodicEntryBooks = findAll(query, args); + } else { + //find(query, 0, 0, "entryBook", entryBook); + closedPeriodicEntryBooks = findAll(query, args); + } + } else { + if (financialPeriod != null) { + args.put("financialPeriod", financialPeriod); + query += " WHERE financialPeriod = :financialPeriod"; + } + + //find(query, 0, 0, "financialPeriod", financialPeriod); + closedPeriodicEntryBooks = findAll(query, args); + } + + // 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"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate", beginDate); + args.put("endDate", endDate); + + return findAll(query, args); + } + + /** + * 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"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate", beginDate); + args.put("endDate", endDate); + args.put("entryBook", entryBook); + return findAll(query, args); + } + + /** + * 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"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate", beginDate); + args.put("endDate", endDate); + args.put("entryBook", entryBook); + return findAll(query, args); + } + + /** + * Retourne les ClosedPeriodicEntryBook de toutes les exercices encore ouverts. + * + * @return les ClosedPeriodicEntryBook + * @throws TopiaException + */ + public List<ClosedPeriodicEntryBook> findAllClosedPeriodicEntryBooksFromUnblockedFiscalPeriod() throws TopiaException { + String query = "SELECT C FROM " + ClosedPeriodicEntryBook.class.getName() + " C" + + ", " + FiscalPeriod.class.getName() + " F" + + " WHERE C.financialPeriod IN ELEMENTS (F.financialPeriod)" + + " AND F.locked = false" + + " ORDER BY C.financialPeriod.beginDate"; + + List<ClosedPeriodicEntryBook> result = findAll(query); + return result; + } + + /** + * Retourne les ClosedPeriodicEntryBook d'un exercice ouvert. + * + * @return les ClosedPeriodicEntryBook + * @throws TopiaException + */ + public List<ClosedPeriodicEntryBook> findAllClosedPeriodicEntryBooksFromFiscalPeriod(FiscalPeriod fiscalPeriod) throws TopiaException { + String query = "SELECT C FROM " + ClosedPeriodicEntryBook.class.getName() + " C" + + ", " + FiscalPeriod.class.getName() + " F" + + " WHERE C.financialPeriod IN ELEMENTS (F.financialPeriod)" + + " AND F = :fiscalPeriod" + + " ORDER BY C.financialPeriod.beginDate"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("fiscalPeriod", fiscalPeriod); + + List<ClosedPeriodicEntryBook> result = findAll(query, args); + + return result; + } + +} Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java (from rev 3808, trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractEntryTopiaDao.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -0,0 +1,323 @@ +/* + * #%L + * Lima callao + * * + * $Id: EntryDAOImpl.java 3783 2014-05-06 16:47:18Z dcosse $ + * $HeadURL: http://svn.chorem.org/lima/trunk/lima-callao/src/main/java/org/chorem/lima/e... $ + * %% + * 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 com.google.common.collect.Maps; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.beans.LetteringFilter; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +public class EntryTopiaDao extends AbstractEntryTopiaDao<Entry> { + + private static final Log log = LogFactory.getLog(EntryTopiaDao.class); + + /** + * Requete generique qui recupere les entrees equilibrées portant entre + * deux dates. + * + * @param beginDate begin date + * @param endDate end date + */ + 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"; + 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 + */ + public List<Entry> findAllEntryOfBalancedTransaction(Account account, + Date beginDate, Date endDate) { + + String query = getEquilibredTransactionQuery(beginDate, endDate) + + // concerne le compte + " AND E.account = :account"; + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate", beginDate); + args.put("endDate", endDate); + args.put("account", account); + + List<Entry> entries = findAll(query, args); + + return entries; + } + + /** + * Retourne la somme des entrées des transaction equilibrées entre + * deux dates pour un compte donné. + * + * @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) + */ + public List<Object[]> getDebitCreditOfBalancedTransaction(Account account, + Date beginDate, Date endDate) { + String query = "SELECT E.debit, sum(E.amount) " + + getEquilibredTransactionQuery(beginDate, endDate) + + // concerne le compte + " AND E.account = :account" + + " GROUP BY E.debit"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate", beginDate); + args.put("endDate", endDate); + args.put("account", account); + + List<Object[]> result = findAll(query, args); + 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 + */ + public List<Entry> findAllEntryOfBalancedTransaction(EntryBook entryBook, Date beginDate, + Date endDate) { + String query = getEquilibredTransactionQuery(beginDate, endDate) + + // concerne le journal + " AND E.financialTransaction.entryBook = :entryBook" + + // fix order + " ORDER BY E.financialTransaction.transactionDate, E.financialTransaction.topiaId"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate", beginDate); + args.put("endDate", endDate); + args.put("entryBook", entryBook); + + List<Entry> entries = findAll(query, args); + return entries; + } + + public List<String> findLetters() { + String query = "Select distinct E.lettering FROM " + Entry.class.getName() + " E" + + " where E.lettering <> null" + + " order by E.lettering desc"; + + List<String> result = new ArrayList<String>(this.<String>findAll(query)); + + if (log.isDebugEnabled()) { + log.debug("Size of result : " + result.size()); + } + + return result; + } + + /** + * 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) + */ + public List<Object[]> getDebitCreditOfBalancedTransaction(EntryBook entryBook, + Date beginDate, Date endDate) { + String query = "SELECT E.debit, sum(E.amount) " + + getEquilibredTransactionQuery(beginDate, endDate) + + // concerne le journal + " AND E.financialTransaction.entryBook = :entryBook" + + " GROUP BY E.debit"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate", beginDate); + args.put("endDate", endDate); + args.put("entryBook", entryBook); + + List<Object[]> result = findAll(query, args); + return result; + } + + /** + * Retourne les entrees des transaction entre deux dates pour + * un journal. + * + * @param entryBook entry book + * @param beginDate begin date + * @param endDate end date + */ + public List<Entry> findAllEntryByDateForEntryBook(EntryBook entryBook, Date beginDate, + Date endDate) { + String query = "FROM " + Entry.class.getName() + " E" + + // entre les 2 dates + " WHERE :beginDate <= E.financialTransaction.transactionDate" + + " AND E.financialTransaction.transactionDate <= :endDate" + + // concerne le journal + " AND E.financialTransaction.entryBook = :entryBook"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate", beginDate); + args.put("endDate", endDate); + args.put("entryBook", entryBook); + + List<Entry> entries = findAll(query, args); + return entries; + } + + /** + * Retourne toutes les entrées d'une transaction + * pour un compte et la présence d'un lettrage ou (xor) non + * @param filter filtre sur les entrees, selon le compte, les dates de debut et de fin, et le lettrage + * */ + public List<Entry> findAllEntryByFilter(LetteringFilter filter) { + + List<Entry> entries; + Account account = filter.getAccount(); + + if (account != null && account.getTopiaId() == null) { + // case user want to see all accounts + entries = getAllEntryByLetteringAndDateForEntryBook(filter); + } else { + entries = getAllEntryByAccountLetteringAndDateForEntryBook(filter); + } + return entries; + } + + public List<Entry> getAllEntryByAccountLetteringAndDateForEntryBook(LetteringFilter filter) { + List<Entry> entries; + + String query = "Select E from " + Entry.class.getName() + " E " + + " where E.account.accountNumber like :account "; + + + if (!filter.getDisplayLettered() && filter.getDisplayUnlettred()){ + query += " and (E.lettering is null or E.lettering = '') "; + } else if (filter.getDisplayLettered() && !filter.getDisplayUnlettred()){ + query += " and (E.lettering is not null or E.lettering !='') "; + } + + query += " and E.financialTransaction.transactionDate between :beginDate and :endDate " + + " order by E.financialTransaction.transactionDate, E.financialTransaction." + FinancialTransaction.PROPERTY_TOPIA_CREATE_DATE; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate", filter.getDateStart()); + args.put("endDate", filter.getDateEnd()); + args.put("account", filter.getAccount().getAccountNumber() + "%"); + entries = findAll(query, args); + + return entries; + } + + public List<Entry> getAllEntryByLetteringAndDateForEntryBook(LetteringFilter filter) { + List<Entry> entries; + + String query = "Select E from " + Entry.class.getName() + " E "; + + query += " WHERE E.financialTransaction.transactionDate BETWEEN :beginDate and :endDate "; + + if (!filter.getDisplayLettered() && filter.getDisplayUnlettred()){ + query += " and (E.lettering is null or E.lettering = '') "; + } else if (filter.getDisplayLettered() && !filter.getDisplayUnlettred()){ + query += " and (E.lettering is not null or E.lettering !='') "; + } + + query += " order by E.financialTransaction.transactionDate, E.financialTransaction." + FinancialTransaction.PROPERTY_TOPIA_CREATE_DATE; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate", filter.getDateStart()); + args.put("endDate", filter.getDateEnd()); + + entries = findAll(query, args); + + return entries; + } + + + /** + * Retourne la dernière entrée d'une transaction + * @param financialTransaction transaction sur laquelle la derniere entree est selectionnee + * */ + public Entry getLastEntry(FinancialTransaction financialTransaction) { + List<Entry> entries; + Entry lastEntry = null; + String query = "Select E from " + Entry.class.getName() + " E" + + " where E.financialTransaction.transactionDate = :financialTransactionDate " + + " and E.financialTransaction = :financialTransaction" + + " order by E.topiaCreateDate desc"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("financialTransactionDate", financialTransaction.getTransactionDate()); + args.put("financialTransaction", financialTransaction); + + entries = findAll(query, args); + if (entries.size() > 0) { + lastEntry = entries.get(0); + } + + return lastEntry; + } + + /** + * Retourne la somme des entrées des transaction 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) + */ + public List<Object[]> getDebitCreditOfTransaction(EntryBook entryBook, + Date beginDate, Date endDate) { + String query = "SELECT E.debit, sum(E.amount) " + + "FROM " + Entry.class.getName() + " E" + + // entre les 2 dates + " WHERE :beginDate <= E.financialTransaction.transactionDate" + + " AND E.financialTransaction.transactionDate <= :endDate" + + // concerne le journal + " AND E.financialTransaction.entryBook = :entryBook" + + " GROUP BY E.debit"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate", beginDate); + args.put("endDate", endDate); + args.put("entryBook", entryBook); + + List<Object[]> result = findAll(query, args); + return result; + } +} Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodTopiaDao.java (from rev 3808, trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialPeriodTopiaDao.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodTopiaDao.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -0,0 +1,112 @@ +/* + * #%L + * Lima callao + * + * $Id: FinancialPeriodDAOImpl.java 3476 2012-06-26 15:48:13Z echatellier $ + * $HeadURL: http://svn.chorem.org/svn/lima/trunk/lima-callao/src/main/java/org/chorem/li... $ + * %% + * 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 java.util.Map; + +import com.google.common.collect.Maps; +import org.nuiton.topia.persistence.TopiaException; + +public class FinancialPeriodTopiaDao extends AbstractFinancialPeriodTopiaDao<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"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("date", date); + // add unique result here + FinancialPeriod financialPeriod = (FinancialPeriod)findUnique(query, args); + return financialPeriod; + } + + /** + * Return all FinancialPeriod with begin date between two given dates. + * + * @param beginDate period begin date + * @param endDate period end date + * @return FinancialPeriod for {@code date} + * @throws TopiaException + */ + public List<FinancialPeriod> findByDates(Date beginDate, Date endDate) throws TopiaException { + + String query = "FROM " + FinancialPeriod.class.getName() + + " WHERE :beginDate <= beginDate" + + " AND beginDate <= :endDate" + + " ORDER by beginDate"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate", beginDate); + args.put("endDate", endDate); + // add unique result here + List<FinancialPeriod> financialPeriod = findAll(query, args); + return financialPeriod; + } + + /** + * Retourne toutes les periodes ordonnées par date de debut de periode. + * + * @return all period ordered + * @throws TopiaException + */ + public List<FinancialPeriod> findAllOrderByBeginDate() throws TopiaException { + String query = "FROM " + FinancialPeriod.class.getName() + + " ORDER BY beginDate"; + + // add unique result here + List<FinancialPeriod> financialPeriod = findAll(query); + return financialPeriod; + } + + /** + * Retourne toutes les periodes ordonnées par date de debut de periode. + * + * @return all period ordered + * @throws TopiaException + */ + public List<FinancialPeriod> findAllUnlockedOrderByBeginDate() throws TopiaException { + String query = "FROM " + FinancialPeriod.class.getName() + + " WHERE locked = false" + + " ORDER BY beginDate"; + + // add unique result here + List<FinancialPeriod> financialPeriod = findAll(query); + return financialPeriod; + } + +} Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementTopiaDao.java (from rev 3808, trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialStatementTopiaDao.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementTopiaDao.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -0,0 +1,79 @@ +/* + * #%L + * Lima callao + * + * $Id: FinancialStatementDAOImpl.java 3585 2012-08-08 14:52:14Z tchemit $ + * $HeadURL: http://svn.chorem.org/svn/lima/trunk/lima-callao/src/main/java/org/chorem/li... $ + * %% + * 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 com.google.common.collect.Maps; + +import java.util.List; +import java.util.Map; + + +/** + * Ajout de requetes specifiques aux {@link FinancialStatement} sur le DAO. + * + * @author chatellier + * @version $Revision: 3585 $ + * + * Last update : $Date: 2012-08-08 16:52:14 +0200 (mer. 08 août 2012) $ + * By : $Author: tchemit $ + */ +public class FinancialStatementTopiaDao extends AbstractFinancialStatementTopiaDao<FinancialStatement> { + + /** + * Find all {@code FinancialStatement} ordered by topia create date. + */ + public List<FinancialStatement> findAllOrderedByCreateDate() { + String query = "FROM " + FinancialStatement.class.getName() + + " ORDER BY " + FinancialStatement.PROPERTY_TOPIA_CREATE_DATE; + List<FinancialStatement> result = findAll(query); + return result; + } + + /** + * Find all {@code FinancialStatement} ordered by topia create date. + */ + public List<FinancialStatement> findChildrenFinancialStatement(FinancialStatement financialStatement) { + String query = "FROM " + FinancialStatement.class.getName(); + + if (financialStatement == null) { + query += " WHERE masterFinancialStatement = null"; + } else { + query += " WHERE masterFinancialStatement = :masterFinancialStatement"; + } + query += " ORDER BY " + FinancialStatement.PROPERTY_TOPIA_CREATE_DATE; + + List<FinancialStatement> result; + if (financialStatement == null) { + result = findAll(query); + } else { + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("masterFinancialStatement", financialStatement); + result = findAll(query, args); + } + return result; + } + +} //FinancialStatementDAO Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionTopiaDao.java (from rev 3808, trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFinancialTransactionTopiaDao.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionTopiaDao.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -0,0 +1,326 @@ +/* + * #%L + * Lima callao + * + * $Id: FinancialTransactionDAOImpl.java 3688 2013-06-27 13:12:22Z Bavencoff $ + * $HeadURL: http://svn.chorem.org/svn/lima/trunk/lima-callao/src/main/java/org/chorem/li... $ + * %% + * 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 com.google.common.collect.Maps; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.Filter.Filter; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Ajout de requetes specifiques aux financial transaction sur le DAO. + * + * @author chatellier + * @version $Revision: 3688 $ + * + * Last update : $Date: 2013-06-27 15:12:22 +0200 (jeu. 27 juin 2013) $ + * By : $Author: Bavencoff $ + */ +public class FinancialTransactionTopiaDao extends AbstractFinancialTransactionTopiaDao<FinancialTransaction> { + + private static final Log log = LogFactory.getLog(FinancialTransactionTopiaDao.class); + + /** + * FIXME echatellier, remove this method when implemented in topia + * just overriden to use merge() instead of saveOrUpdate() + */ + public FinancialTransaction merge(FinancialTransaction e) { +// try { +// e = (FinancialTransaction) getContext().getHibernate().merge(e); +// getContext().getFiresSupport().warnOnUpdateEntity(e); +// return e; +// } catch (HibernateException ex) { +// throw new TopiaException(ex); +// } + // TODO DCossé 15/05/14 find a way to get hibernate + return null; + } + + /** + * Return how many transaction are found with specified entryBook. + * + * @param entryBook entry book + * @return transaction referencing entry book + */ + public long getCountByEntryBook(EntryBook entryBook) { + String query = "SELECT count(*) FROM " + FinancialTransaction.class.getName() + " t WHERE t.entryBook = :entryBook"; + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("entryBook", entryBook); + Number count = (Number)findAll(query, args).get(0); + return count.longValue(); + } + + /** + * Find all transactions between two dates. + * + * @param beginDate begin date + * @param endDate end date + * @return unbalanced transactions + */ + public List<FinancialTransaction> findAllByDates(Date beginDate, Date endDate) { + String query = "FROM " + FinancialTransaction.class.getName() + " T"+ + " WHERE :beginDate <= T.transactionDate" + + " AND T.transactionDate <= :endDate" + + " ORDER BY T.transactionDate, T." + FinancialTransaction.PROPERTY_TOPIA_CREATE_DATE; + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate",beginDate); + args.put("endDate", endDate); + List<FinancialTransaction> result = findAll(query,args); + return result; + } + + /** + * Find all transactions between two dates in an entry book. + * + * @param beginDate begin date + * @param endDate end date + * @param entryBook entry book + * @return unbalanced transactions + */ + public List<FinancialTransaction> findAllByDates(Date beginDate, Date endDate, EntryBook entryBook) { + String query = "FROM " + FinancialTransaction.class.getName() + " T"+ + " WHERE :beginDate <= T.transactionDate" + + " AND T.transactionDate <= :endDate" + + " AND T.entryBook = :entryBook" + + " ORDER BY T.transactionDate, T." + FinancialTransaction.PROPERTY_TOPIA_CREATE_DATE; + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate",beginDate); + args.put("endDate", endDate); + args.put("entryBook", entryBook); + List<FinancialTransaction> result = findAll(query, args); + return result; + } + + /** + * Find all unbalanced transactions. + * + * @param beginDate beginDate + * @param endDate endDate + * @param entryBook entry book (can be null) + * @return unbalanced transactions + */ + public List<FinancialTransaction> getAllUnbalancedTransaction(Date beginDate, Date endDate, + EntryBook entryBook) { + 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 :beginDate <= T.transactionDate" + + " AND T.transactionDate <= :endDate"; + List<FinancialTransaction> result; + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate",beginDate); + args.put("endDate", endDate); + if (entryBook != null) { + args.put("entryBook", entryBook); + query += " AND T.entryBook = :entryBook"; + result = findAll(query, args); + } else { + result = findAll(query, args); + } + + return result; + } + + /** + * Find all unbalanced transactions. + * + * @param beginDate beginDate + * @param endDate endDate + * @param entryBook entry book (can be null) + * @return unbalanced transactions + */ + public List<FinancialTransaction> getAllBalancedTransaction(Date beginDate, Date endDate, + EntryBook entryBook) { + 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 :beginDate <= T.transactionDate" + + " AND T.transactionDate <= :endDate"; + List<FinancialTransaction> result; + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate",beginDate); + args.put("endDate", endDate); + + if (entryBook != null) { + args.put("entryBook", entryBook); + query += " AND T.entryBook = :entryBook"; + result = findAll(query, args); + } else { + result = findAll(query, args); + } + + return result; + } + + /** + * Find all unbalanced transactions. + * + * @param beginDate beginDate + * @param endDate endDate + * @param entryBook entry book (can be null) + * @return unbalanced transactions + */ + public List<FinancialTransaction> getAllIncorrectTransaction(Date beginDate, Date endDate, + EntryBook entryBook) { + String query = "SELECT distinct T 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 (SELECT sum(amount) FROM " + Entry.class.getName() + + " WHERE debit = true AND financialTransaction = T) IS NULL" + + " OR (SELECT sum(amount) FROM " + Entry.class.getName() + + " WHERE debit = false AND financialTransaction = T) IS NULL" + + " OR E.account = null" + + " OR E.voucher = null" + + " OR E.voucher = ''" + + " OR E.description = null" + + " OR E.description = '')" + + " AND :beginDate <= T.transactionDate" + + " AND T.transactionDate <= :endDate"; + List<FinancialTransaction> result; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate",beginDate); + args.put("endDate", endDate); + if (entryBook != null) { + args.put("entryBook", entryBook); + query += " AND T.entryBook = :entryBook"; + result = findAll(query, args); + } else { + result = findAll(query, args); + } + + return result; + } + + /** + * Find all transaction where some field are not filled in. + * + * @param beginDate begin date + * @param endDate end date + * @param entryBook entry book + * @return unfilled transaction + */ + public List<FinancialTransaction> getAllUnfilledTransaction(Date beginDate, + Date endDate, EntryBook entryBook) { + String query = "SELECT T 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 :beginDate <= T.transactionDate" + + " AND T.transactionDate <= :endDate"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate",beginDate); + args.put("endDate", endDate); + args.put("entryBook", entryBook); + List<FinancialTransaction> result = findAll(query, args); + return result; + } + + /** + * Find all transaction without entry book. + * + * @param beginDate begin date + * @param endDate end date + * @return transaction without entry books + */ + public List<FinancialTransaction> getAllTransactionWithoutEntryBook(Date beginDate, + Date endDate) { + + String query = "SELECT T 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" + + " AND :beginDate <= T.transactionDate" + + " AND T.transactionDate <= :endDate"; + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("beginDate",beginDate); + args.put("endDate", endDate); + + List<FinancialTransaction> result = findAll(query, args); + + return result; + } + + /** + * Search financial transaction. + * + * + * @param filter filter parameters + * @return financial transaction + */ + public List<FinancialTransaction> searchFinancialTransaction(Filter filter) { + + GeneratorHQuery generator = new GeneratorHQuery(); + filter.accept(generator); + + + String query = generator.getHQuery(); + Map<String,Object> arguments = generator.getParameters(); + + if (log.isDebugEnabled()) { + Set<String> parameters = arguments.keySet(); + for(String param : parameters) { + log.debug("Query : \n" + query + "\nArguments: " + param); + } + } + + // perform query + List<FinancialTransaction> result; + if (arguments.isEmpty()) { + result = findAll(query); + } else { + result = findAll(query, arguments); + } + + if (log.isDebugEnabled()) { + log.debug("Number of founded transactions : " + result.size()); + } + + return result; + } + +} //FinancialTransactionDAO Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FiscalPeriodTopiaDao.java (from rev 3808, trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractFiscalPeriodTopiaDao.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FiscalPeriodTopiaDao.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FiscalPeriodTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -0,0 +1,140 @@ +/* + * #%L + * Lima callao + * + * $Id: FiscalPeriodDAOImpl.java 3598 2012-08-10 16:31:26Z mallon $ + * $HeadURL: http://svn.chorem.org/svn/lima/trunk/lima-callao/src/main/java/org/chorem/li... $ + * %% + * 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 java.util.Map; + +import com.google.common.collect.Maps; +import org.hibernate.HibernateException; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Fiscal period entity DAO. + * + * @author chatellier + * @version $Revision: 3598 $ + * + * Last update : $Date: 2012-08-10 18:31:26 +0200 (ven. 10 août 2012) $ + * By : $Author: mallon $ + */ +public class FiscalPeriodTopiaDao extends AbstractFiscalPeriodTopiaDao<FiscalPeriod> { + + /** + * FIXME echatellier, remove this method when implemented in topia + * just overriden to use merge() instead of saveOrUpdate() + */ + @Override + public FiscalPeriod update(FiscalPeriod e) throws TopiaException { + try { +// getContext().getHibernate().merge(e); +// getContext().getFiresSupport().warnOnUpdateEntity(e); +// return e; + // TODO DCossé 15/05/14 find a way to do it + return null; + } catch (HibernateException ex) { + throw new TopiaException(ex); + } + } + + /** + * Find fiscal period by financial period. + * + * @param financialPeriod financial period + * @return fiscal period containing financial period + * @throws TopiaException + */ + public FiscalPeriod findByFinancialPeriod(FinancialPeriod financialPeriod) throws TopiaException { + String query = "FROM " + FiscalPeriod.class.getName() + + " WHERE :financialPeriod in elements(financialPeriod)"; + + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("financialPeriod", financialPeriod); + + List<FiscalPeriod> fiscalPeriods = findAll(query, args); + FiscalPeriod result = null; + if (!fiscalPeriods.isEmpty()) { + result = fiscalPeriods.get(0); + } + return result; + } + + /** + * Get last fiscal period (higher end date). + * + * @return last fiscal period + * @throws TopiaException + */ + public FiscalPeriod getLastFiscalPeriod() throws TopiaException { + String query = "FROM " + FiscalPeriod.class.getName() + + " ORDER BY endDate desc"; + + List<FiscalPeriod> fiscalPeriods = findAll(query); + FiscalPeriod result = null; + if (!fiscalPeriods.isEmpty()) { + result = fiscalPeriods.get(0); + } + + return result; + } + + /** + * Get first fiscal period (higher end date). + * + * @return last fiscal period + * @throws TopiaException + */ + public FiscalPeriod getFirstFiscalPeriod() throws TopiaException { + String query = "FROM " + FiscalPeriod.class.getName() + + " ORDER BY endDate"; + + List<FiscalPeriod> fiscalPeriods = findAll(query); + FiscalPeriod result = null; + if (!fiscalPeriods.isEmpty()) { + result = fiscalPeriods.get(0); + } + return result; + } + + /** + * Get last non locked fiscal period (higher end date). + * + * @return last fiscal period + * @throws TopiaException + */ + public FiscalPeriod getLastUnlockedFiscalPeriod() throws TopiaException { + String query = "FROM " + FiscalPeriod.class.getName() + + " WHERE locked = false" + + " ORDER BY endDate desc"; + + List<FiscalPeriod> fiscalPeriods = findAll(query); + FiscalPeriod result = null; + if (!fiscalPeriods.isEmpty()) { + result = fiscalPeriods.get(0); + } + return result; + } +} Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/VatStatementTopiaDao.java (from rev 3808, trunk/lima-callao/src/main/java/org/chorem/lima/entity/AbstractVatStatementTopiaDao.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/VatStatementTopiaDao.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/VatStatementTopiaDao.java 2014-05-16 15:54:31 UTC (rev 3810) @@ -0,0 +1,103 @@ +/* + * #%L + * Lima callao + * + * $Id: VatStatementDAOImpl.java 3585 2012-08-08 14:52:14Z tchemit $ + * $HeadURL: http://svn.chorem.org/svn/lima/trunk/lima-callao/src/main/java/org/chorem/li... $ + * %% + * 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 com.google.common.collect.Maps; + +import java.util.List; +import java.util.Map; + + +/** + * Ajout de requetes specifiques aux {@code VatStatement} sur le DAO. + * + * @author chatellier + * @version $Revision: 3585 $ + * + * Last update : $Date: 2012-08-08 16:52:14 +0200 (mer. 08 août 2012) $ + * By : $Author: tchemit $ + */ +public class VatStatementTopiaDao extends AbstractVatStatementTopiaDao<VatStatement> { + + /** + * Find all {@code VatStatement} ordered by topia create date. + */ + public List<VatStatement> findAllOrderedByCreateDate() { + String query = "FROM " + VatStatement.class.getName() + + " ORDER BY " + VatStatement.PROPERTY_TOPIA_CREATE_DATE; + List<VatStatement> result = findAll(query); + return result; + } + + /** + * Get masterVatStatement children statement. + * + * @param masterVatStatement master VatStatement + * @return children VatStatement + */ + public List<VatStatement> getChildrenVatStatement(VatStatement masterVatStatement) { + String query = "FROM " + VatStatement.class.getName(); + + if (masterVatStatement == null) { + query += " WHERE masterVatStatement = null"; + } else { + query += " WHERE masterVatStatement = :masterVatStatement"; + } + + query += " ORDER BY " + VatStatement.PROPERTY_TOPIA_CREATE_DATE; + List<VatStatement> result; + if (masterVatStatement == null) { + result = findAll(query); + } else { + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("masterVatStatement", masterVatStatement); + result = findAll(query, args); + } + return result; + } + + /** + * Recherche un statement par equivalence de label. + * + * TODO voir a quoi ca sert vraiment. + * + * @param label label + * @return statement like label + */ + public VatStatement findVatStatementByLabel(String label) { + String query = "FROM " + VatStatement.class.getName() + + " WHERE label LIKE :label"; + Map<String, Object> args = Maps.newLinkedHashMap(); + args.put("label", "%" + label + "%"); + List<VatStatement> statements = findAll(query, args); + VatStatement result = null; + if (!statements.isEmpty()) { + result = statements.get(0); + } + return result; + } + +} //VatStatementDAO
participants (1)
-
athimel@users.chorem.org