Author: jpepin Date: 2010-04-16 12:26:55 +0200 (Fri, 16 Apr 2010) New Revision: 2864 Log: Modification du mod?\195?\168le et ajout de classe. Classe Transaction chang?\195?\169 en FinancialTransaction Added: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionHelper.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java Removed: trunk/lima-business/src/main/java/org/chorem/lima/business/TransactionService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TransactionServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionHelper.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/TransactionTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/TransactionTableModel.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/UserServiceImpl.java trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java trunk/lima-callao/src/main/xmi/accounting.properties trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionDataTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionFilteredTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionFlattenTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionSortedTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookForm.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/model/EntryBookTableModel.java trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionService.java (from rev 2863, trunk/lima-business/src/main/java/org/chorem/lima/business/TransactionService.java) =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionService.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionService.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -0,0 +1,71 @@ +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* + */ + +package org.chorem.lima.business; + +import java.util.List; + +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialTransaction; + +/** + * Transaction service. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public interface FinancialTransactionService { + + /** + * Find all transaction (use carefully, can return a lot of results). + * + * @return all transaction + * @throws LimaException + */ + List<FinancialTransaction> getAllFinancialTransactions() throws LimaException; + + /** + * Find all transaction for an entry book. + * + * @param entryBook entry book + * @return all transaction for entry book + * @throws LimaException + */ + List<FinancialTransaction> getAllFinancialTransactionsForEntryBook(EntryBook entryBook) throws LimaException; + + /** + * Find all transaction for an entry book and a financial period. + * + * @param entryBook entry book + * @param period financial period + * @return all transaction for entry book and period + * @throws LimaException + */ + List<FinancialTransaction> getAllFinancialTransactionsForEntryBookAndFinancialPeriod(EntryBook entryBook, FinancialPeriod period) throws LimaException; + + void createFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException; + + void updateFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException; + + void removeFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException; +} Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/TransactionService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/TransactionService.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/TransactionService.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -1,71 +0,0 @@ -/* *##% Lima Business - * Copyright (C) 2008 - 2010 CodeLutin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ##%* - */ - -package org.chorem.lima.business; - -import java.util.List; - -import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.entity.FinancialPeriod; -import org.chorem.lima.entity.Transaction; - -/** - * Transaction service. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public interface TransactionService { - - /** - * Find all transaction (use carefully, can return a lot of results). - * - * @return all transaction - * @throws LimaException - */ - List<Transaction> getAllTransactions() throws LimaException; - - /** - * Find all transaction for an entry book. - * - * @param entryBook entry book - * @return all transaction for entry book - * @throws LimaException - */ - List<Transaction> getAllTransactionsForEntryBook(EntryBook entryBook) throws LimaException; - - /** - * Find all transaction for an entry book and a financial period. - * - * @param entryBook entry book - * @param period financial period - * @return all transaction for entry book and period - * @throws LimaException - */ - List<Transaction> getAllTransactionsForEntryBookAndFinancialPeriod(EntryBook entryBook, FinancialPeriod period) throws LimaException; - - Transaction createTransaction() throws LimaException; - - void updateTransaction(Transaction transaction) throws LimaException; - - void removeTransaction(Transaction transaction) throws LimaException; -} Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -35,7 +35,7 @@ import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryBookDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.chorem.lima.entity.Transaction; +import org.chorem.lima.entity.FinancialTransaction; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; @@ -54,7 +54,7 @@ private TopiaContext rootContext; - protected TransactionServiceImpl transactionService = new TransactionServiceImpl(); + protected FinancialTransactionServiceImpl financialTransactionService = new FinancialTransactionServiceImpl(); //private ConvertEntryBook convertEntryBook = new ConvertEntryBook(); @@ -361,8 +361,8 @@ topiaTransaction = rootContext.beginTransaction(); // Vérifie si une transaction n'appartient pas à ce EntryBook. - Transaction transaction = transactionService.findByEntryBook(topiaTransaction, entryBook); - if (transaction != null) { + FinancialTransaction financialtransaction = financialTransactionService.findByEntryBook(topiaTransaction, entryBook); + if (financialtransaction != null) { throw new LimaBusinessException("Can't delete EntryBook with transactions"); } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryServiceImpl.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryServiceImpl.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -46,7 +46,7 @@ private RecordServiceImpl logServiceImpl = new RecordServiceImpl(); // TODO A revoir car transaction a besoin de entry et vice versa - private static TransactionServiceImpl transactionServiceImpl = new TransactionServiceImpl(); + private static FinancialTransactionServiceImpl transactionServiceImpl = new FinancialTransactionServiceImpl(); private AccountServiceImpl accountServiceImpl = new AccountServiceImpl(); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -57,7 +57,7 @@ private FinancialPeriodServiceImpl timeSpanServiceImpl = new FinancialPeriodServiceImpl(); - private TransactionServiceImpl transactionServiceImpl = new TransactionServiceImpl(); + private FinancialTransactionServiceImpl transactionServiceImpl = new FinancialTransactionServiceImpl(); /** * Cete méthode permet d'exporter des données de Callao vers un fichier au Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -50,7 +50,7 @@ private TopiaContext rootContext; - private static TransactionServiceImpl transactionServiceImpl = new TransactionServiceImpl(); + private static FinancialTransactionServiceImpl transactionServiceImpl = new FinancialTransactionServiceImpl(); public FinancialPeriodServiceImpl() { LimaConfig config = LimaConfig.getInstance(); Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java (from rev 2863, trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TransactionServiceImpl.java) =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -0,0 +1,676 @@ +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* + */ + +package org.chorem.lima.business.ejb; + +import static org.nuiton.i18n.I18n._; + +import java.util.List; + +import javax.ejb.Stateless; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaBusinessException; +import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.FinancialTransactionService; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.AccountDAO; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.LimaCallaoDAOHelper; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.entity.FinancialTransactionDAO; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.framework.TopiaQuery; + +/** + * Cette classe permet la création d'une transaction comptable dans l'application. + * Toute action sur une transaction entraîne automatiquement une création de log. + * Une transaction est composée d'entrées comptables. + * Les actions sur les transactions sont soumises au statut de celle-ci, si elle + * est dans une période bloquée ou non. + * + * @author Rémi Chapelet + */ +@Stateless +public class FinancialTransactionServiceImpl extends AbstractLimaService implements FinancialTransactionService { + + private static final Log log = LogFactory.getLog(FinancialTransactionServiceImpl.class); + + private TopiaContext rootContext; + + //private RecordServiceImpl logServiceImpl = new RecordServiceImpl(); + + //private EntryServiceImpl entryServiceImpl = new EntryServiceImpl(); + + //private FinancialPeriodServiceImpl timeSpanServiceImpl = new FinancialPeriodServiceImpl(); + + public FinancialTransactionServiceImpl() { + LimaConfig config = LimaConfig.getInstance(); + try { + rootContext = TopiaContextFactory.getContext(config.getOptions()); + } catch (TopiaNotFoundException ex) { + if (log.isErrorEnabled()) { + log.error("Can't init topia context", ex); + } + } + } + + /** + * Permet de créer une transaction comptable. Pour ajouter une transaction, + * le timeSpan doit être non bloqué. + * @param entryDate + * @param voucherRef + * @param description + * @param timespan + * @param journal + * @return + * @throws LimaException + */ + @Override + public void createFinancialTransaction(FinancialTransaction financialtransaction/*Date entryDate, String voucherRef, + String description, TimeSpan timeSpan, Journal journal*/) throws LimaException { + + + TopiaContext topiaContext = null; + try { + // basic check done, make check in database + // TODO move it into JTA + topiaContext = rootContext.beginTransaction(); + + FinancialTransactionDAO financialtransactionDAO = LimaCallaoDAOHelper + .getFinancialTransactionDAO(topiaContext); + + financialtransactionDAO.create(financialtransaction); + + // commit + topiaContext.commitTransaction(); + } + catch (TopiaException ex) { + doCatch(topiaContext, ex, log); + } + finally { + doFinally(topiaContext, log); + } + + /*String result = ServiceHelper.RESPOND_ERROR; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TransactionDAO transactionDAO = LimaCallaoDAOHelper + .getTransactionDAO(topiaContext); + String isCorrectTransaction = isCorrectTransaction(timeSpan, + journal); + if (isCorrectTransaction.equals(ServiceHelper.RESPOND_SUCCESS)) { + // Creation de la transaction + Transaction newtransaction = transactionDAO.create(); + newtransaction.setTransDate(entryDate); + newtransaction.setVoucherRef(voucherRef); + newtransaction.setDescription(description); + newtransaction.setTimeSpan(timeSpan); + newtransaction.setJournal(journal); + // Création BDD + topiaContext.commitTransaction(); + if (log.isInfoEnabled()) { + log.info("Ajout avec succes de la transaction"); + } + + // Il renvoie soit l'identifiant topiaId ou SUCCESS. + result = newtransaction.getTopiaId(); + //result = ServiceHelper.RESPOND_SUCCESS; + } else { + result = isCorrectTransaction; + } + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return result;*/ + } + + /* + * Permet de créer une transaction à partir d'une transaction DTO. + * ATTENTION : si le journal ou timespan n'existe pas, l'ajout ne peut se + * faire. Si on souhaite, on peut créer le journal automatiquement lors de + * l'ajout de la transaction si il n'existe pas. Pour le timeSpan, il n'est + * pas cohérent qu'il n'existe pas. On ne peut travailler que sur une période + * comptable existante, et par conséquent il ne faut pas le créer. + * @param transactionDTO + * @return + * + public String createTransaction(TransactionDTO transactionDTO) { + String result = ServiceHelper.RESPOND_ERROR; + // Vérifie que transactionDTO possède un journalDTO et un timeSpanDTO + if (transactionDTO.getJournalDTO() == null + || transactionDTO.getTimeSpanDTO() == null) { + if (log.isErrorEnabled()) { + log.error("L'objet transactionDTO ne possède pas de timeSpan ET/OU de journal."); + } + result = ServiceHelper.TRANSACTION_NOT_JOURNAL; + } else { + // Recherche du journal + JournalServiceImpl journalServiceImpl = new JournalServiceImpl(); + Journal journal = journalServiceImpl + .searchJournalWithLabel(transactionDTO.getJournalDTO() + .getLabel()); + // Recherche du timeSpan + TimeSpan timeSpan = timeSpanServiceImpl + .searchTimeSpanByDate(transactionDTO.getTimeSpanDTO() + .getBeginTimeSpan()); + + // Vérification si timeSpan et Journal existe bien + if (journal == null) { + if (log.isErrorEnabled()) { + log.error("Création transaction : Le journal " + + transactionDTO.getJournalDTO().getLabel() + + " n'existe pas."); + } + result = ServiceHelper.TRANSACTION_NOT_JOURNAL; + } else { + if (timeSpan == null) { + if (log.isErrorEnabled()) { + log.error("Création transaction : Le timeSpan " + + transactionDTO.getTimeSpanDTO().toString() + + " n'existe pas."); + } + result = ServiceHelper.TRANSACTION_NOT_TIMESPAN; + } else { + result = createTransaction(transactionDTO.getEntryDate(), + transactionDTO.getVoucherRef(), transactionDTO + .getDescription(), timeSpan, journal); + } + } + } + return result; + }*/ + + /* + * Permet de modifier une transaction. Cette dernière est identifiée par la + * clé topiaId. + * @param topiaId + * @param entryDate + * @param voucherRef + * @param description + * @param timespan + * @param journal + * @return + * + public String modifyTransaction(String topiaId, Date entryDate, + String voucherRef, String description, TimeSpan timeSpan, + Journal journal) { + String result = ServiceHelper.RESPOND_ERROR; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TransactionDAO transactionDAO = LimaCallaoDAOHelper + .getTransactionDAO(topiaContext); + // Vérification que la transaction existe bien + Transaction transaction = transactionDAO.findByTopiaId(topiaId); + if (transaction == null) { + if (log.isInfoEnabled()) { + log.info("La transaction " + voucherRef + + " n'existe pas. (identifiant " + topiaId + ")"); + } + result = ServiceHelper.TRANSACTION_NOT_EXIST; + } else { + // Vérification si la transaction possède de bons paramètres + String correct = isCorrectTransaction(timeSpan, journal); + // Si la transaction est correcte + if (correct.equals(ServiceHelper.RESPOND_SUCCESS)) { + // Modification + transaction.setTransDate(entryDate); + transaction.setVoucherRef(voucherRef); + transaction.setDescription(description); + transaction.setTimeSpan(timeSpan); + transaction.setJournal(journal); + transaction.update(); + // Création BDD + topiaContext.commitTransaction(); + result = ServiceHelper.RESPOND_SUCCESS; + } + } + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return result; + }*/ + + /** + * Permet de retrouver la premiere transaction associée au journal. + * + * Utilisé par entrybook service pour savoir si un journal a des transactions + * associées et empecher la suppression. + * + * @param topiaTransaction context à utiliser + * @param entryBook journal + * @throws TopiaException + */ + protected FinancialTransaction findByEntryBook(TopiaContext topiaTransaction, EntryBook entryBook) throws TopiaException { + + FinancialTransactionDAO transactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaTransaction); + + TopiaQuery query = transactionDAO.createQuery(); + // entryBook is not visible, but column "entryBook" + // exist in transaction table + query.add("entryBook", entryBook); + + FinancialTransaction result = transactionDAO.findByQuery(query); + + return result; + } + + @Override + public List<FinancialTransaction> getAllFinancialTransactions() throws LimaException { + + // find all with null entry book filter + + return getAllFinancialTransactionsForEntryBook(null); + } + + @Override + public List<FinancialTransaction> getAllFinancialTransactionsForEntryBook(EntryBook entryBook) throws LimaException { + + // find all with null period filter + + return getAllFinancialTransactionsForEntryBookAndFinancialPeriod(entryBook, null); + } + + @Override + public List<FinancialTransaction> getAllFinancialTransactionsForEntryBookAndFinancialPeriod(EntryBook entryBook, FinancialPeriod financialPeriod) throws LimaException { + + List<FinancialTransaction> transactions = null; + TopiaContext topiaTransaction = null; + try { + topiaTransaction = rootContext.beginTransaction(); + FinancialTransactionDAO transactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaTransaction); + + // filter with topia query + TopiaQuery query = transactionDAO.createQuery(); + + if (entryBook != null) { + query.add("entryBook", entryBook); + } + + if (financialPeriod != null) { + query.add("financialPeriod", financialPeriod); + } + + transactions = transactionDAO.findAllByQuery(query); + } + catch (TopiaException ex) { + doCatch(topiaTransaction, ex, log); + } + finally { + doFinally(topiaTransaction, log); + } + + return transactions; + } + + /* + * Recherche toutes les transactions appartenant à un même journal donné + * en paramètre. + * @param journal + * @return + * + public List<Transaction> searchListTransactionWithJournal(Journal journal) { + List<Transaction> listTransaction = null; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TransactionDAO transactionDAO = LimaCallaoDAOHelper + .getTransactionDAO(topiaContext); + // Recherche + listTransaction = transactionDAO.findAllByJournal(journal); + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return listTransaction; + }*/ + + /* + * Permet de rechercher toutes les transactions dans la base de données, + * avec en retour une liste de transactions au format DTO. + * @return + * + public List<TransactionDTO> getAllTransactionDTO() { + List<TransactionDTO> listTransactionDTO = new ArrayList<TransactionDTO>(); + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TransactionDAO transactionDAO = LimaCallaoDAOHelper + .getTransactionDAO(topiaContext); + // Recherche + List<Transaction> listTransaction = transactionDAO.findAll(); + // Converti la transaction en DTO + convertTransaction.setTransaction(rootContext); + for (Transaction transaction : listTransaction) { + TransactionDTO transactionDTO = convertTransaction + .transactionEntityToDto(transaction); + listTransactionDTO.add(transactionDTO); + } + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return listTransactionDTO; + }*/ + + /* + * Cette méthode permet de vérifier si une transaction possède des paramètres + * corrects. + * Un journal doit exister. + * Un timeSpan doit exister et être non bloqué. + * @param timeSpan + * @param journal + * @return + * + public String isCorrectTransaction(TimeSpan timeSpan, Journal journal) { + String result = ServiceHelper.RESPOND_SUCCESS; + // Vérification si timeSpan et Journal existe bien + if (journal == null) { + if (log.isErrorEnabled()) { + log.error("Création transaction : Le journal n'existe pas."); + } + result = ServiceHelper.TRANSACTION_NOT_JOURNAL; + } + if (timeSpan == null) { + if (log.isErrorEnabled()) { + log.error("Création transaction : Le timeSpan n'existe pas."); + } + result = ServiceHelper.TRANSACTION_NOT_TIMESPAN; + } else { + // Vérifie si le timeSpan est bloqué + if (timeSpan.getLocked()) { + if (log.isErrorEnabled()) { + log.error("Le timeSpan est bloqué ! Il est donc impossible" + + " d'ajouter une transaction sur cette période. (" + + "Période du " + timeSpan + ")"); + } + result = ServiceHelper.TRANSACTION_TIMESPAN_BLOCKED; + } + } + return result; + }*/ + + @Override + public void updateFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { + + // TODO EC-20100408 add some checks ? (balance, status, etc... ? ) + + TopiaContext topiaTransaction = null; + try { + topiaTransaction = rootContext.beginTransaction(); + FinancialTransactionDAO transactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaTransaction); + transactionDAO.update(financialtransaction); + } + catch (TopiaException ex) { + doCatch(topiaTransaction, ex, log); + } + finally { + doFinally(topiaTransaction, log); + } + + } + + @Override + public void removeFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { + + // TODO EC-20100408 add some checks ? (balance, status, etc... ? ) + + TopiaContext topiaTransaction = null; + try { + topiaTransaction = rootContext.beginTransaction(); + FinancialTransactionDAO transactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaTransaction); + transactionDAO.delete(financialtransaction); + } + catch (TopiaException ex) { + doCatch(topiaTransaction, ex, log); + } + finally { + doFinally(topiaTransaction, log); + } + + } + + /* + * Permet d'ajouter une entrée comptable pour une transaction donnée. + * ATTENTION : la transaction doit être NON bloquée. + * + * @param description + * @param amount + * @param debit + * @param lettering + * @param detail + * @param transaction + * @return + * + public String addEntry(String description, String amount, boolean debit, + String lettering, String detail, Transaction transaction, + Account account) { + String result = ServiceHelper.RESPOND_ERROR; + // Si la transaction est non bloquée + if (!isTransactionBlocked(transaction)) { + // Si il renvoie succes et non l'identifiant (à commenter dans la classe correspondante) + result = entryServiceImpl.createEntry(description, amount, debit, + lettering, detail, transaction, account); + } else { + result = ServiceHelper.TRANSACTION_TIMESPAN_BLOCKED; + } + return result; + }*/ + + /* + * Permet d'ajouter une entrée comptable pour une transaction donnée. + * L'entrée est sous format DTO. + * + * @param entryDTO + * @return + * + public String addEntry(EntryDTO entryDTO) { + String result = ServiceHelper.RESPOND_ERROR; + // Recherche TransactionDTO + TransactionDTO transactonDTO = entryDTO.getTransactionDTO(); + Transaction transaction = searchTransactionWithTopiaId(transactonDTO); + // Si la transaction est non bloquée + if (!isTransactionBlocked(transaction)) { + + // Si il renvoie succes et non l'identifiant (à commenter dans la classe correspondante) + result = entryServiceImpl.createEntry(entryDTO); + } else { + result = ServiceHelper.TRANSACTION_TIMESPAN_BLOCKED; + } + return result; + }*/ + + /* + * Permet de modifier une entrée comptable. + * ATTENTION : la transaction doit être NON bloquée. + * + * @param topiaId + * @param description + * @param amount + * @param debit + * @param lettering + * @param detail + * @param transaction + * @param account + * @return + * + public String modifyEntry(String topiaId, String description, + String amount, boolean debit, String lettering, String detail, + Transaction transaction, Account account) { + String result = ServiceHelper.RESPOND_ERROR; + if (!isTransactionBlocked(transaction)) { + result = entryServiceImpl.modifyEntry(topiaId, description, amount, + debit, lettering, detail, account); + } else { + result = ServiceHelper.TRANSACTION_TIMESPAN_BLOCKED; + } + return result; + }*/ + + /* + * Permet de modifier une entrée. + * @param entryDTO + * @return + * + public String modifyEntry(EntryDTO entryDTO) { + String result = ServiceHelper.RESPOND_ERROR; + // Recherche TransactionDTO + TransactionDTO transactonDTO = entryDTO.getTransactionDTO(); + Transaction transaction = searchTransactionWithTopiaId(transactonDTO); + if (!isTransactionBlocked(transaction)) { + result = entryServiceImpl.modifyEntry(entryDTO); + } else { + result = ServiceHelper.TRANSACTION_TIMESPAN_BLOCKED; + } + return result; + }*/ + + /* + * Permet d'effacer une entrée comptable. Elle est identifiée par son identifiant + * topiaID. Une entrée peut être supprimée seulement si elle est non bloquée. + * @param topiaId + * @return + * + public String removeEntry(String topiaId) { + String result = ServiceHelper.RESPOND_ERROR; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); + // Recherche de l'entry + Entry entryDelete = entryDAO.findByTopiaId(topiaId); + // Entry doit exister + if (entryDelete != null) { + // Prend la transaction dont appartient entry + Transaction transaction = entryDelete.getTransaction(); + // Vérifie si la transaction est non bloquée. + if (!isTransactionBlocked(transaction)) { + // Création d'un log DTO + LogDTO logDTO = new LogDTO("", new Date(), + ServiceHelper.LOG_REMOVE, transaction + .getTransDate(), transaction + .getVoucherRef(), transaction + .getDescription(), entryDelete + .getDescription(), entryDelete.getAmount(), + entryDelete.getDebit(), entryDelete.getLettering()); + // Appel pour supprimer l'entrée + result = entryServiceImpl.removeEntry(topiaId); + // Si la suppression s'est bien déroulée, création log + if (result.equals(ServiceHelper.RESPOND_SUCCESS)) { + // Ajout du log + logServiceImpl.addLog(logDTO); + } + } else { + result = ServiceHelper.TRANSACTION_TIMESPAN_BLOCKED; + } + } else { + result = ServiceHelper.ENTRY_NOT_EXIST; + } + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return result; + }*/ + + /* + * Permet de supprimer une entrée à partir d'un DTO. + * @param entryDTO + * @return + * + public String removeEntry(EntryDTO entryDTO) { + String result = removeEntry(entryDTO.getId()); + return result; + }*/ + + /* + * Permet de vérifier si une transaction est dans une période bloquée ou non + * @param transaction + * @return + * + public boolean isTransactionBlocked(Transaction transaction) { + boolean isTransactionBlocked = true; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TransactionDAO transactionDAO = LimaCallaoDAOHelper + .getTransactionDAO(topiaContext); + // Recherche + Transaction transactionSearch = transactionDAO + .findByTopiaId(transaction.getTopiaId()); + isTransactionBlocked = timeSpanServiceImpl + .isTimeSpanBlocked(transactionSearch.getTimeSpan()); + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return isTransactionBlocked; + }*/ + + /* + * Permet de vérifier si une transaction est équilibrée. + * @param transaction + * @return + * + public boolean isTransactionBalanced(Transaction transaction) { + List<EntryDTO> ListEntryDTO = entryServiceImpl + .searchEntryDTOWithTransaction(transaction); + float debit = 0; + float credit = 0; + // Pour toutes les entrées comptables trouvées + for (EntryDTO entryDTO : ListEntryDTO) { + // Si entrée au debit + if (entryDTO.isDebit()) { + debit = debit + + Float.parseFloat(entryDTO.getAmount().replaceFirst( + ",", ".")); + } else { + credit = credit + + Float.parseFloat(entryDTO.getAmount().replaceFirst( + ",", ".")); + } + } + // Vérifie si le debit == credit + boolean isTransactionBalanced = debit == credit; + return isTransactionBalanced; + }*/ +} \ No newline at end of file Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TransactionServiceImpl.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TransactionServiceImpl.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -1,676 +0,0 @@ -/* *##% Lima Business - * Copyright (C) 2008 - 2010 CodeLutin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ##%* - */ - -package org.chorem.lima.business.ejb; - -import static org.nuiton.i18n.I18n._; - -import java.util.List; - -import javax.ejb.Stateless; - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.LimaBusinessException; -import org.chorem.lima.business.LimaConfig; -import org.chorem.lima.business.LimaException; -import org.chorem.lima.business.TransactionService; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.AccountDAO; -import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.entity.FinancialPeriod; -import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.chorem.lima.entity.Transaction; -import org.chorem.lima.entity.TransactionDAO; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaNotFoundException; -import org.nuiton.topia.framework.TopiaQuery; - -/** - * Cette classe permet la création d'une transaction comptable dans l'application. - * Toute action sur une transaction entraîne automatiquement une création de log. - * Une transaction est composée d'entrées comptables. - * Les actions sur les transactions sont soumises au statut de celle-ci, si elle - * est dans une période bloquée ou non. - * - * @author Rémi Chapelet - */ -@Stateless -public class TransactionServiceImpl extends AbstractLimaService implements TransactionService { - - private static final Log log = LogFactory.getLog(TransactionServiceImpl.class); - - private TopiaContext rootContext; - - //private RecordServiceImpl logServiceImpl = new RecordServiceImpl(); - - //private EntryServiceImpl entryServiceImpl = new EntryServiceImpl(); - - //private FinancialPeriodServiceImpl timeSpanServiceImpl = new FinancialPeriodServiceImpl(); - - public TransactionServiceImpl() { - LimaConfig config = LimaConfig.getInstance(); - try { - rootContext = TopiaContextFactory.getContext(config.getOptions()); - } catch (TopiaNotFoundException ex) { - if (log.isErrorEnabled()) { - log.error("Can't init topia context", ex); - } - } - } - - /** - * Permet de créer une transaction comptable. Pour ajouter une transaction, - * le timeSpan doit être non bloqué. - * @param entryDate - * @param voucherRef - * @param description - * @param timespan - * @param journal - * @return - * @throws LimaException - */ - @Override - public void createTransaction(Transaction transaction/*Date entryDate, String voucherRef, - String description, TimeSpan timeSpan, Journal journal*/) throws LimaException { - - - TopiaContext topiaContext = null; - try { - // basic check done, make check in database - // TODO move it into JTA - topiaContext = rootContext.beginTransaction(); - - TransactionDAO transactionDAO = LimaCallaoDAOHelper - .getTransactionDAO(topiaContext); - - transactionDAO.create(transaction); - - // commit - topiaContext.commitTransaction(); - } - catch (TopiaException ex) { - doCatch(topiaContext, ex, log); - } - finally { - doFinally(topiaContext, log); - } - - /*String result = ServiceHelper.RESPOND_ERROR; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TransactionDAO transactionDAO = LimaCallaoDAOHelper - .getTransactionDAO(topiaContext); - String isCorrectTransaction = isCorrectTransaction(timeSpan, - journal); - if (isCorrectTransaction.equals(ServiceHelper.RESPOND_SUCCESS)) { - // Creation de la transaction - Transaction newtransaction = transactionDAO.create(); - newtransaction.setTransDate(entryDate); - newtransaction.setVoucherRef(voucherRef); - newtransaction.setDescription(description); - newtransaction.setTimeSpan(timeSpan); - newtransaction.setJournal(journal); - // Création BDD - topiaContext.commitTransaction(); - if (log.isInfoEnabled()) { - log.info("Ajout avec succes de la transaction"); - } - - // Il renvoie soit l'identifiant topiaId ou SUCCESS. - result = newtransaction.getTopiaId(); - //result = ServiceHelper.RESPOND_SUCCESS; - } else { - result = isCorrectTransaction; - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return result;*/ - } - - /* - * Permet de créer une transaction à partir d'une transaction DTO. - * ATTENTION : si le journal ou timespan n'existe pas, l'ajout ne peut se - * faire. Si on souhaite, on peut créer le journal automatiquement lors de - * l'ajout de la transaction si il n'existe pas. Pour le timeSpan, il n'est - * pas cohérent qu'il n'existe pas. On ne peut travailler que sur une période - * comptable existante, et par conséquent il ne faut pas le créer. - * @param transactionDTO - * @return - * - public String createTransaction(TransactionDTO transactionDTO) { - String result = ServiceHelper.RESPOND_ERROR; - // Vérifie que transactionDTO possède un journalDTO et un timeSpanDTO - if (transactionDTO.getJournalDTO() == null - || transactionDTO.getTimeSpanDTO() == null) { - if (log.isErrorEnabled()) { - log.error("L'objet transactionDTO ne possède pas de timeSpan ET/OU de journal."); - } - result = ServiceHelper.TRANSACTION_NOT_JOURNAL; - } else { - // Recherche du journal - JournalServiceImpl journalServiceImpl = new JournalServiceImpl(); - Journal journal = journalServiceImpl - .searchJournalWithLabel(transactionDTO.getJournalDTO() - .getLabel()); - // Recherche du timeSpan - TimeSpan timeSpan = timeSpanServiceImpl - .searchTimeSpanByDate(transactionDTO.getTimeSpanDTO() - .getBeginTimeSpan()); - - // Vérification si timeSpan et Journal existe bien - if (journal == null) { - if (log.isErrorEnabled()) { - log.error("Création transaction : Le journal " - + transactionDTO.getJournalDTO().getLabel() - + " n'existe pas."); - } - result = ServiceHelper.TRANSACTION_NOT_JOURNAL; - } else { - if (timeSpan == null) { - if (log.isErrorEnabled()) { - log.error("Création transaction : Le timeSpan " - + transactionDTO.getTimeSpanDTO().toString() - + " n'existe pas."); - } - result = ServiceHelper.TRANSACTION_NOT_TIMESPAN; - } else { - result = createTransaction(transactionDTO.getEntryDate(), - transactionDTO.getVoucherRef(), transactionDTO - .getDescription(), timeSpan, journal); - } - } - } - return result; - }*/ - - /* - * Permet de modifier une transaction. Cette dernière est identifiée par la - * clé topiaId. - * @param topiaId - * @param entryDate - * @param voucherRef - * @param description - * @param timespan - * @param journal - * @return - * - public String modifyTransaction(String topiaId, Date entryDate, - String voucherRef, String description, TimeSpan timeSpan, - Journal journal) { - String result = ServiceHelper.RESPOND_ERROR; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TransactionDAO transactionDAO = LimaCallaoDAOHelper - .getTransactionDAO(topiaContext); - // Vérification que la transaction existe bien - Transaction transaction = transactionDAO.findByTopiaId(topiaId); - if (transaction == null) { - if (log.isInfoEnabled()) { - log.info("La transaction " + voucherRef - + " n'existe pas. (identifiant " + topiaId + ")"); - } - result = ServiceHelper.TRANSACTION_NOT_EXIST; - } else { - // Vérification si la transaction possède de bons paramètres - String correct = isCorrectTransaction(timeSpan, journal); - // Si la transaction est correcte - if (correct.equals(ServiceHelper.RESPOND_SUCCESS)) { - // Modification - transaction.setTransDate(entryDate); - transaction.setVoucherRef(voucherRef); - transaction.setDescription(description); - transaction.setTimeSpan(timeSpan); - transaction.setJournal(journal); - transaction.update(); - // Création BDD - topiaContext.commitTransaction(); - result = ServiceHelper.RESPOND_SUCCESS; - } - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return result; - }*/ - - /** - * Permet de retrouver la premiere transaction associée au journal. - * - * Utilisé par entrybook service pour savoir si un journal a des transactions - * associées et empecher la suppression. - * - * @param topiaTransaction context à utiliser - * @param entryBook journal - * @throws TopiaException - */ - protected Transaction findByEntryBook(TopiaContext topiaTransaction, EntryBook entryBook) throws TopiaException { - - TransactionDAO transactionDAO = LimaCallaoDAOHelper.getTransactionDAO(topiaTransaction); - - TopiaQuery query = transactionDAO.createQuery(); - // entryBook is not visible, but column "entryBook" - // exist in transaction table - query.add("entryBook", entryBook); - - Transaction result = transactionDAO.findByQuery(query); - - return result; - } - - @Override - public List<Transaction> getAllTransactions() throws LimaException { - - // find all with null entry book filter - - return getAllTransactionsForEntryBook(null); - } - - @Override - public List<Transaction> getAllTransactionsForEntryBook(EntryBook entryBook) throws LimaException { - - // find all with null period filter - - return getAllTransactionsForEntryBookAndFinancialPeriod(entryBook, null); - } - - @Override - public List<Transaction> getAllTransactionsForEntryBookAndFinancialPeriod(EntryBook entryBook, FinancialPeriod financialPeriod) throws LimaException { - - List<Transaction> transactions = null; - TopiaContext topiaTransaction = null; - try { - topiaTransaction = rootContext.beginTransaction(); - TransactionDAO transactionDAO = LimaCallaoDAOHelper.getTransactionDAO(topiaTransaction); - - // filter with topia query - TopiaQuery query = transactionDAO.createQuery(); - - if (entryBook != null) { - query.add("entryBook", entryBook); - } - - if (financialPeriod != null) { - query.add("financialPeriod", financialPeriod); - } - - transactions = transactionDAO.findAllByQuery(query); - } - catch (TopiaException ex) { - doCatch(topiaTransaction, ex, log); - } - finally { - doFinally(topiaTransaction, log); - } - - return transactions; - } - - /* - * Recherche toutes les transactions appartenant à un même journal donné - * en paramètre. - * @param journal - * @return - * - public List<Transaction> searchListTransactionWithJournal(Journal journal) { - List<Transaction> listTransaction = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TransactionDAO transactionDAO = LimaCallaoDAOHelper - .getTransactionDAO(topiaContext); - // Recherche - listTransaction = transactionDAO.findAllByJournal(journal); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return listTransaction; - }*/ - - /* - * Permet de rechercher toutes les transactions dans la base de données, - * avec en retour une liste de transactions au format DTO. - * @return - * - public List<TransactionDTO> getAllTransactionDTO() { - List<TransactionDTO> listTransactionDTO = new ArrayList<TransactionDTO>(); - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TransactionDAO transactionDAO = LimaCallaoDAOHelper - .getTransactionDAO(topiaContext); - // Recherche - List<Transaction> listTransaction = transactionDAO.findAll(); - // Converti la transaction en DTO - convertTransaction.setTransaction(rootContext); - for (Transaction transaction : listTransaction) { - TransactionDTO transactionDTO = convertTransaction - .transactionEntityToDto(transaction); - listTransactionDTO.add(transactionDTO); - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return listTransactionDTO; - }*/ - - /* - * Cette méthode permet de vérifier si une transaction possède des paramètres - * corrects. - * Un journal doit exister. - * Un timeSpan doit exister et être non bloqué. - * @param timeSpan - * @param journal - * @return - * - public String isCorrectTransaction(TimeSpan timeSpan, Journal journal) { - String result = ServiceHelper.RESPOND_SUCCESS; - // Vérification si timeSpan et Journal existe bien - if (journal == null) { - if (log.isErrorEnabled()) { - log.error("Création transaction : Le journal n'existe pas."); - } - result = ServiceHelper.TRANSACTION_NOT_JOURNAL; - } - if (timeSpan == null) { - if (log.isErrorEnabled()) { - log.error("Création transaction : Le timeSpan n'existe pas."); - } - result = ServiceHelper.TRANSACTION_NOT_TIMESPAN; - } else { - // Vérifie si le timeSpan est bloqué - if (timeSpan.getLocked()) { - if (log.isErrorEnabled()) { - log.error("Le timeSpan est bloqué ! Il est donc impossible" - + " d'ajouter une transaction sur cette période. (" - + "Période du " + timeSpan + ")"); - } - result = ServiceHelper.TRANSACTION_TIMESPAN_BLOCKED; - } - } - return result; - }*/ - - @Override - public void updateTransaction(Transaction transaction) throws LimaException { - - // TODO EC-20100408 add some checks ? (balance, status, etc... ? ) - - TopiaContext topiaTransaction = null; - try { - topiaTransaction = rootContext.beginTransaction(); - TransactionDAO transactionDAO = LimaCallaoDAOHelper.getTransactionDAO(topiaTransaction); - transactionDAO.update(transaction); - } - catch (TopiaException ex) { - doCatch(topiaTransaction, ex, log); - } - finally { - doFinally(topiaTransaction, log); - } - - } - - @Override - public void removeTransaction(Transaction transaction) throws LimaException { - - // TODO EC-20100408 add some checks ? (balance, status, etc... ? ) - - TopiaContext topiaTransaction = null; - try { - topiaTransaction = rootContext.beginTransaction(); - TransactionDAO transactionDAO = LimaCallaoDAOHelper.getTransactionDAO(topiaTransaction); - transactionDAO.delete(transaction); - } - catch (TopiaException ex) { - doCatch(topiaTransaction, ex, log); - } - finally { - doFinally(topiaTransaction, log); - } - - } - - /* - * Permet d'ajouter une entrée comptable pour une transaction donnée. - * ATTENTION : la transaction doit être NON bloquée. - * - * @param description - * @param amount - * @param debit - * @param lettering - * @param detail - * @param transaction - * @return - * - public String addEntry(String description, String amount, boolean debit, - String lettering, String detail, Transaction transaction, - Account account) { - String result = ServiceHelper.RESPOND_ERROR; - // Si la transaction est non bloquée - if (!isTransactionBlocked(transaction)) { - // Si il renvoie succes et non l'identifiant (à commenter dans la classe correspondante) - result = entryServiceImpl.createEntry(description, amount, debit, - lettering, detail, transaction, account); - } else { - result = ServiceHelper.TRANSACTION_TIMESPAN_BLOCKED; - } - return result; - }*/ - - /* - * Permet d'ajouter une entrée comptable pour une transaction donnée. - * L'entrée est sous format DTO. - * - * @param entryDTO - * @return - * - public String addEntry(EntryDTO entryDTO) { - String result = ServiceHelper.RESPOND_ERROR; - // Recherche TransactionDTO - TransactionDTO transactonDTO = entryDTO.getTransactionDTO(); - Transaction transaction = searchTransactionWithTopiaId(transactonDTO); - // Si la transaction est non bloquée - if (!isTransactionBlocked(transaction)) { - - // Si il renvoie succes et non l'identifiant (à commenter dans la classe correspondante) - result = entryServiceImpl.createEntry(entryDTO); - } else { - result = ServiceHelper.TRANSACTION_TIMESPAN_BLOCKED; - } - return result; - }*/ - - /* - * Permet de modifier une entrée comptable. - * ATTENTION : la transaction doit être NON bloquée. - * - * @param topiaId - * @param description - * @param amount - * @param debit - * @param lettering - * @param detail - * @param transaction - * @param account - * @return - * - public String modifyEntry(String topiaId, String description, - String amount, boolean debit, String lettering, String detail, - Transaction transaction, Account account) { - String result = ServiceHelper.RESPOND_ERROR; - if (!isTransactionBlocked(transaction)) { - result = entryServiceImpl.modifyEntry(topiaId, description, amount, - debit, lettering, detail, account); - } else { - result = ServiceHelper.TRANSACTION_TIMESPAN_BLOCKED; - } - return result; - }*/ - - /* - * Permet de modifier une entrée. - * @param entryDTO - * @return - * - public String modifyEntry(EntryDTO entryDTO) { - String result = ServiceHelper.RESPOND_ERROR; - // Recherche TransactionDTO - TransactionDTO transactonDTO = entryDTO.getTransactionDTO(); - Transaction transaction = searchTransactionWithTopiaId(transactonDTO); - if (!isTransactionBlocked(transaction)) { - result = entryServiceImpl.modifyEntry(entryDTO); - } else { - result = ServiceHelper.TRANSACTION_TIMESPAN_BLOCKED; - } - return result; - }*/ - - /* - * Permet d'effacer une entrée comptable. Elle est identifiée par son identifiant - * topiaID. Une entrée peut être supprimée seulement si elle est non bloquée. - * @param topiaId - * @return - * - public String removeEntry(String topiaId) { - String result = ServiceHelper.RESPOND_ERROR; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); - // Recherche de l'entry - Entry entryDelete = entryDAO.findByTopiaId(topiaId); - // Entry doit exister - if (entryDelete != null) { - // Prend la transaction dont appartient entry - Transaction transaction = entryDelete.getTransaction(); - // Vérifie si la transaction est non bloquée. - if (!isTransactionBlocked(transaction)) { - // Création d'un log DTO - LogDTO logDTO = new LogDTO("", new Date(), - ServiceHelper.LOG_REMOVE, transaction - .getTransDate(), transaction - .getVoucherRef(), transaction - .getDescription(), entryDelete - .getDescription(), entryDelete.getAmount(), - entryDelete.getDebit(), entryDelete.getLettering()); - // Appel pour supprimer l'entrée - result = entryServiceImpl.removeEntry(topiaId); - // Si la suppression s'est bien déroulée, création log - if (result.equals(ServiceHelper.RESPOND_SUCCESS)) { - // Ajout du log - logServiceImpl.addLog(logDTO); - } - } else { - result = ServiceHelper.TRANSACTION_TIMESPAN_BLOCKED; - } - } else { - result = ServiceHelper.ENTRY_NOT_EXIST; - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return result; - }*/ - - /* - * Permet de supprimer une entrée à partir d'un DTO. - * @param entryDTO - * @return - * - public String removeEntry(EntryDTO entryDTO) { - String result = removeEntry(entryDTO.getId()); - return result; - }*/ - - /* - * Permet de vérifier si une transaction est dans une période bloquée ou non - * @param transaction - * @return - * - public boolean isTransactionBlocked(Transaction transaction) { - boolean isTransactionBlocked = true; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TransactionDAO transactionDAO = LimaCallaoDAOHelper - .getTransactionDAO(topiaContext); - // Recherche - Transaction transactionSearch = transactionDAO - .findByTopiaId(transaction.getTopiaId()); - isTransactionBlocked = timeSpanServiceImpl - .isTimeSpanBlocked(transactionSearch.getTimeSpan()); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return isTransactionBlocked; - }*/ - - /* - * Permet de vérifier si une transaction est équilibrée. - * @param transaction - * @return - * - public boolean isTransactionBalanced(Transaction transaction) { - List<EntryDTO> ListEntryDTO = entryServiceImpl - .searchEntryDTOWithTransaction(transaction); - float debit = 0; - float credit = 0; - // Pour toutes les entrées comptables trouvées - for (EntryDTO entryDTO : ListEntryDTO) { - // Si entrée au debit - if (entryDTO.isDebit()) { - debit = debit - + Float.parseFloat(entryDTO.getAmount().replaceFirst( - ",", ".")); - } else { - credit = credit - + Float.parseFloat(entryDTO.getAmount().replaceFirst( - ",", ".")); - } - } - // Vérifie si le debit == credit - boolean isTransactionBalanced = debit == credit; - return isTransactionBalanced; - }*/ -} \ No newline at end of file Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/UserServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/UserServiceImpl.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/UserServiceImpl.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.User; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaNotFoundException; @@ -61,8 +60,9 @@ * @param name new user name * @throws LimaException */ - public void addUser(User user/*String name*/) throws LimaException { - /*// Attention doublon utilisateur + /* + public void addUser(User user/*String name) throws LimaException { + // Attention doublon utilisateur try { // Acces BDD TopiaContext topiaContext = rootContext.beginTransaction(); @@ -83,8 +83,8 @@ throw new LimaException("Can't create user", ex); } - }*/ - } + } + }*/ /** * Find user with name. @@ -92,7 +92,7 @@ * @param name * @throws LimaException */ - public void findUser(String name) throws LimaException { + /*public void findUser(String name) throws LimaException { /*try { // Acces BDD TopiaContext topiaContext = rootContext.beginTransaction(); @@ -110,6 +110,6 @@ log.error("Can't find user", ex); throw new LimaException("Can't find user", ex); } - }*/ - } + } + }*/ } Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -5,7 +5,7 @@ import org.chorem.lima.business.ejb.EntryBookServiceImpl; import org.chorem.lima.business.ejb.FiscalPeriodServiceImpl; import org.chorem.lima.business.ejb.FinancialPeriodServiceImpl; -import org.chorem.lima.business.ejb.TransactionServiceImpl; +import org.chorem.lima.business.ejb.FinancialTransactionServiceImpl; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -19,7 +19,7 @@ /** log. */ private static final org.apache.commons.logging.Log log = LogFactory.getLog(TransactionServiceImplTest.class); - private static TransactionServiceImpl instanceTransaction; + private static FinancialTransactionServiceImpl instanceTransaction; private static FiscalPeriodServiceImpl instancePeriod; private static FinancialPeriodServiceImpl instanceTimespan; private static EntryBookServiceImpl instanceJournal; @@ -34,7 +34,7 @@ @Before public void setUp() { - instanceTransaction = new TransactionServiceImpl(); + instanceTransaction = new FinancialTransactionServiceImpl(); instancePeriod = new FiscalPeriodServiceImpl(); instanceTimespan = new FinancialPeriodServiceImpl(); instanceJournal = new EntryBookServiceImpl(); Modified: trunk/lima-callao/src/main/xmi/accounting.properties =================================================================== --- trunk/lima-callao/src/main/xmi/accounting.properties 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-callao/src/main/xmi/accounting.properties 2010-04-16 10:26:55 UTC (rev 2864) @@ -1,6 +1,6 @@ # Precise l'entete de l'ensemble des fichiers generes model.tagvalue.copyright=/*\n Copyright (C) 2009-2010 Lima Callao\n */ #org.chorem.lima.entity.Account.attribute.subAccounts.tagvalue.lazy=false -org.chorem.lima.entity.Transaction.attribute.entry.tagvalue.lazy=false +org.chorem.lima.entity.FinancialTransaction.attribute.entry.tagvalue.lazy=false #model.tagvalue.dbSchema=Callao model.tagvalue.String=text \ No newline at end of file Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) Modified: trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -36,7 +36,7 @@ import org.chorem.lima.business.FinancialPeriodService; import org.chorem.lima.business.FiscalPeriodService; import org.chorem.lima.business.RecordService; -import org.chorem.lima.business.TransactionService; +import org.chorem.lima.business.FinancialTransactionService; /** * Is class is a service factory based on embedded openejb container. @@ -195,14 +195,14 @@ * * @return transaction service proxy */ - public TransactionService getTransactionService() { + public FinancialTransactionService getTransactionService() { // TODO EC-20100410 put lookup name in configuration // name should be fully configurable due to custom implementation used String lookupName = "TransactionServiceImplLocal"; - TransactionService ejbHome = null; + FinancialTransactionService ejbHome = null; try { - ejbHome = (TransactionService)ctx.lookup(lookupName); + ejbHome = (FinancialTransactionService)ctx.lookup(lookupName); } catch (NamingException eee) { if (log.isErrorEnabled()) { log.error("Can't lookup for service : " + lookupName, eee); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionDataTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionDataTableModel.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionDataTableModel.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -52,7 +52,7 @@ /** * Services */ - private final transient TransactionService transServ; + private final transient FinancialTransactionService transServ; private final List<TransactionDTO> data; private boolean editable = true; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionFilteredTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionFilteredTableModel.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionFilteredTableModel.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -57,7 +57,7 @@ /** * Services */ - protected final transient TransactionService transactionServ; + protected final transient FinancialTransactionService transactionServ; private boolean filtered = false; /** Modified: trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionFlattenTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionFlattenTableModel.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionFlattenTableModel.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -60,7 +60,7 @@ * Services */ protected final EntryService entryServ; - protected final TransactionService transactionServ; + protected final FinancialTransactionService transactionServ; /** * @return Modified: trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionSortedTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionSortedTableModel.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-swing/src/main/java/org/chorem/lima/table/model/TransactionSortedTableModel.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -65,7 +65,7 @@ * Services */ protected final EntryService entryServ; - protected final TransactionService transactionServ; + protected final FinancialTransactionService transactionServ; /** * @param model Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookForm.jaxx 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookForm.jaxx 2010-04-16 10:26:55 UTC (rev 2864) @@ -32,6 +32,17 @@ <Table> <row> <cell> + <JLabel text="lima.entrybook.code"/> + </cell> + <cell> + <JTextField id="entryBookCodeField" text="{getEntryBook().getCode()}"/> + <javax.swing.text.Document javaBean="getEntryBookCodeField().getDocument()" + onInsertUpdate='getEntryBook().setCode(getEntryBookCodeField().getText())' + onRemoveUpdate='getEntryBook().setCode(getEntryBookCodeField().getText())' /> + </cell> + </row> + <row> + <cell> <JLabel text="lima.entrybook.label"/> </cell> <cell> @@ -43,28 +54,17 @@ </row> <row> <cell> - <JLabel text="lima.entrybook.description"/> + <JLabel text="lima.entrybook.type"/> </cell> <cell> - <JTextField id="entryBookDescriptionField" text="{getEntryBook().getDescription()}"/> - <javax.swing.text.Document javaBean="getEntryBookDescriptionField().getDocument()" - onInsertUpdate='getEntryBook().setDescription(getEntryBookDescriptionField().getText())' - onRemoveUpdate='getEntryBook().setDescription(getEntryBookDescriptionField().getText())' /> + <JTextField id="entryBookTypeField" text="{getEntryBook().getType()}"/> + <javax.swing.text.Document javaBean="getEntryBookTypeField().getDocument()" + onInsertUpdate='getEntryBook().setType(getEntryBookTypeField().getText())' + onRemoveUpdate='getEntryBook().setType(getEntryBookTypeField().getText())' /> </cell> </row> <row> <cell> - <JLabel text="lima.entrybook.prefix"/> - </cell> - <cell> - <JTextField id="entryBookPrefixField" text="{getEntryBook().getPrefix()}"/> - <javax.swing.text.Document javaBean="getEntryBookPrefixField().getDocument()" - onInsertUpdate='getEntryBook().setPrefix(getEntryBookPrefixField().getText())' - onRemoveUpdate='getEntryBook().setPrefix(getEntryBookPrefixField().getText())' /> - </cell> - </row> - <row> - <cell> <JButton id="okButton" text="lima.common.ok" onActionPerformed="dispose()"/> </cell> <cell> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/model/EntryBookTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/model/EntryBookTableModel.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/model/EntryBookTableModel.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -126,13 +126,13 @@ switch (column) { case 0: - result = entryBook.getLabel(); + result = entryBook.getCode(); break; case 1: - result = entryBook.getDescription(); + result = entryBook.getLabel(); break; case 2: - result = entryBook.getPrefix(); + result = entryBook.getType(); break; } } catch (LimaException e) { @@ -153,13 +153,13 @@ switch (column) { case 0: - entryBook.setLabel((String)value); + entryBook.setCode((String)value); break; case 1: - entryBook.setDescription((String)value); + entryBook.setLabel((String)value); break; case 2: - entryBook.setPrefix((String)value); + entryBook.setType((String)value); break; } Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionHelper.java (from rev 2859, trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionHelper.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionHelper.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionHelper.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -0,0 +1,79 @@ +/* *##% Lima Main + * Copyright (C) 2008 - 2010 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +package org.chorem.lima.ui.transaction; + +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.FinancialTransaction; + +/** + * TODO add comment here. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class FinancialTransactionHelper { + + /** + * Get total credit for a transaction. + * + * @param transaction transaction to get credit + * @return total credit + */ + public static double getCredit(FinancialTransaction financialtransaction) { + double credit = 0; + for (Entry entry : financialtransaction.getEntry()) { + // TODO EC-20100407 voir si le modele correspond (amount, credit,debit) + if (!entry.getDebit()) { + credit += entry.getAmount(); + } + } + return credit; + } + + /** + * Get total debit for a transaction. + * + * @param transaction transaction to get debit + * @return total debit + */ + public static double getDebit(FinancialTransaction financialtransaction) { + double debit = 0; + for (Entry entry : financialtransaction.getEntry()) { + // TODO EC-20100407 voir si le modele correspond (amount, credit,debit) + if (entry.getDebit()) { + debit += entry.getAmount(); + } + } + return debit; + } + + /** + * Return true if transaction is balanced (credit == debit). + * + * @param transaction transaction to test + * @return {@code true} if transaction is balanced + */ + public static boolean isBalanced(FinancialTransaction financialtransaction) { + boolean balanced = getDebit(financialtransaction) == getCredit(financialtransaction); + return balanced; + } +} Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionViewHandler.java (from rev 2861, trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionViewHandler.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionViewHandler.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionViewHandler.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -0,0 +1,156 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.ui.transaction; + +import static org.nuiton.i18n.I18n._; + +import java.util.List; + +import javax.swing.JOptionPane; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.EntryBookImpl; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.entity.FinancialTransactionImpl; +import org.chorem.lima.ui.entrybook.EntryBookForm; +import org.chorem.lima.ui.entrybook.model.EntryBookTableModel; +import org.chorem.lima.ui.transaction.table.FinancialTransactionTable; +import org.chorem.lima.ui.transaction.table.FinancialTransactionTableModel; +import org.chorem.lima.util.ErrorHelper; +import org.jdesktop.swingx.JXTable; + + +/** + * Handler associated with account view. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class FinancialTransactionViewHandler { + + /** log. */ + private static final Log log = LogFactory.getLog(FinancialTransactionViewHandler.class); + + protected TransactionView view; + + protected FinancialTransactionViewHandler(TransactionView view) { + this.view = view; + } + + //add a new transaction + protected void addFinancialTransaction() { + FinancialTransactionTable table = (FinancialTransactionTable)view.getTransactionTable(); + FinancialTransactionTableModel model = (FinancialTransactionTableModel)table.getModel(); + + try { + model.addFinancialTransaction(); + } catch (LimaException ex) { + if (log.isErrorEnabled()) { + log.error("Can't add transaction", ex); + } + ErrorHelper.showErrorDialog("Can't add transaction", ex); + } + } + + //implement new transaction button + //add a new entry to the selected transaction + public void addEmptyEntry(){ + + FinancialTransactionTable table = (FinancialTransactionTable)view.getTransactionTable(); + FinancialTransactionTableModel model = (FinancialTransactionTableModel)table.getModel(); + + int indexSelectedRow = table.getSelectedRow(); + if (indexSelectedRow != -1) { + Object selectedValue = model.getElementAt(indexSelectedRow); + model.addEmptyEntry(selectedValue, indexSelectedRow); + } + else { + if (log.isWarnEnabled()) { + log.warn("Call addentry selected transaction without selection"); + } + } + } + + /** + * Delete selected row in table (could be transaction or entry). + * + * Called by model. + * @throws LimaException + */ + public void deleteSelectedRow(){ + + FinancialTransactionTable table = (FinancialTransactionTable)view.getTransactionTable(); + FinancialTransactionTableModel model = (FinancialTransactionTableModel)table.getModel(); + + int indexSelectedRow = table.getSelectedRow(); + if (indexSelectedRow != -1) { + + Object selectedValue = model.getElementAt(indexSelectedRow); + String message = null; + if (selectedValue instanceof FinancialTransaction) { + message = _("lima.question.remove.transaction"); + } + else { + message = _("lima.question.remove.entry"); + } + + int response = JOptionPane.showConfirmDialog(view, message, + _("lima.transaction.confirmdelete"), JOptionPane.YES_NO_OPTION); + + if (response == JOptionPane.YES_OPTION) { + + try { + model.removeObject(selectedValue, indexSelectedRow); + } catch (LimaException ex) { + if (log.isErrorEnabled()) { + log.error("Can't remove transaction or entry", ex); + } + ErrorHelper.showErrorDialog("Can't remove transaction or entry", ex); + } + + /* + if (selectedValue instanceof Transaction) { + // TODO EC-20100409 implements this + if (log.isWarnEnabled()) { + log.warn("TODO implement Transaction deletion"); + model.removeTransaction(selectedValue); + } + } + else if (selectedValue instanceof Entry) { + // TODO EC-20100409 implements this + if (log.isWarnEnabled()) { + log.warn("TODO implement Entry deletion"); + } + }*/ + } + } + else { + if (log.isWarnEnabled()) { + log.warn("Call delete selected row without selection"); + } + } + } +} Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionHelper.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionHelper.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionHelper.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -1,79 +0,0 @@ -/* *##% Lima Main - * Copyright (C) 2008 - 2010 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* - */ - -package org.chorem.lima.ui.transaction; - -import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.Transaction; - -/** - * TODO add comment here. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class TransactionHelper { - - /** - * Get total credit for a transaction. - * - * @param transaction transaction to get credit - * @return total credit - */ - public static double getCredit(Transaction transaction) { - double credit = 0; - for (Entry entry : transaction.getEntry()) { - // TODO EC-20100407 voir si le modele correspond (amount, credit,debit) - if (!entry.getDebit()) { - credit += entry.getAmount(); - } - } - return credit; - } - - /** - * Get total debit for a transaction. - * - * @param transaction transaction to get debit - * @return total debit - */ - public static double getDebit(Transaction transaction) { - double debit = 0; - for (Entry entry : transaction.getEntry()) { - // TODO EC-20100407 voir si le modele correspond (amount, credit,debit) - if (entry.getDebit()) { - debit += entry.getAmount(); - } - } - return debit; - } - - /** - * Return true if transaction is balanced (credit == debit). - * - * @param transaction transaction to test - * @return {@code true} if transaction is balanced - */ - public static boolean isBalanced(Transaction transaction) { - boolean balanced = getDebit(transaction) == getCredit(transaction); - return balanced; - } -} Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionViewHandler.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionViewHandler.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -1,156 +0,0 @@ -/* *##% Lima Swing - * Copyright (C) 2008 - 2010 CodeLutin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ##%*/ - -package org.chorem.lima.ui.transaction; - -import static org.nuiton.i18n.I18n._; - -import java.util.List; - -import javax.swing.JOptionPane; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.entity.EntryBookImpl; -import org.chorem.lima.entity.Transaction; -import org.chorem.lima.entity.TransactionImpl; -import org.chorem.lima.ui.entrybook.EntryBookForm; -import org.chorem.lima.ui.entrybook.model.EntryBookTableModel; -import org.chorem.lima.ui.transaction.table.TransactionTable; -import org.chorem.lima.ui.transaction.table.TransactionTableModel; -import org.chorem.lima.util.ErrorHelper; -import org.jdesktop.swingx.JXTable; - - -/** - * Handler associated with account view. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class TransactionViewHandler { - - /** log. */ - private static final Log log = LogFactory.getLog(TransactionViewHandler.class); - - protected TransactionView view; - - protected TransactionViewHandler(TransactionView view) { - this.view = view; - } - - //add a new transaction - protected void addEmptyTransaction() { - TransactionTable table = (TransactionTable)view.getTransactionTable(); - TransactionTableModel model = (TransactionTableModel)table.getModel(); - - try { - model.addEmptyTransaction(); - } catch (LimaException ex) { - if (log.isErrorEnabled()) { - log.error("Can't add transaction", ex); - } - ErrorHelper.showErrorDialog("Can't add transaction", ex); - } - } - - //implement new transaction button - //add a new entry to the selected transaction - public void addEmptyEntry(){ - - TransactionTable table = (TransactionTable)view.getTransactionTable(); - TransactionTableModel model = (TransactionTableModel)table.getModel(); - - int indexSelectedRow = table.getSelectedRow(); - if (indexSelectedRow != -1) { - Object selectedValue = model.getElementAt(indexSelectedRow); - model.addEmptyEntry(selectedValue, indexSelectedRow); - } - else { - if (log.isWarnEnabled()) { - log.warn("Call addentry selected transaction without selection"); - } - } - } - - /** - * Delete selected row in table (could be transaction or entry). - * - * Called by model. - * @throws LimaException - */ - public void deleteSelectedRow(){ - - TransactionTable table = (TransactionTable)view.getTransactionTable(); - TransactionTableModel model = (TransactionTableModel)table.getModel(); - - int indexSelectedRow = table.getSelectedRow(); - if (indexSelectedRow != -1) { - - Object selectedValue = model.getElementAt(indexSelectedRow); - String message = null; - if (selectedValue instanceof Transaction) { - message = _("lima.question.remove.transaction"); - } - else { - message = _("lima.question.remove.entry"); - } - - int response = JOptionPane.showConfirmDialog(view, message, - _("lima.transaction.confirmdelete"), JOptionPane.YES_NO_OPTION); - - if (response == JOptionPane.YES_OPTION) { - - try { - model.removeObject(selectedValue, indexSelectedRow); - } catch (LimaException ex) { - if (log.isErrorEnabled()) { - log.error("Can't remove transaction or entry", ex); - } - ErrorHelper.showErrorDialog("Can't remove transaction or entry", ex); - } - - /* - if (selectedValue instanceof Transaction) { - // TODO EC-20100409 implements this - if (log.isWarnEnabled()) { - log.warn("TODO implement Transaction deletion"); - model.removeTransaction(selectedValue); - } - } - else if (selectedValue instanceof Entry) { - // TODO EC-20100409 implements this - if (log.isWarnEnabled()) { - log.warn("TODO implement Entry deletion"); - } - }*/ - } - } - else { - if (log.isWarnEnabled()) { - log.warn("Call delete selected row without selection"); - } - } - } -} Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTable.java (from rev 2861, trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/TransactionTable.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTable.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTable.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -0,0 +1,374 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.ui.transaction.table; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.util.Date; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.listener.EmptyLineSelectionListener; +import org.chorem.lima.table.editor.DateTableCellEditor; +import org.chorem.lima.ui.transaction.FinancialTransactionViewHandler; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.decorator.ColorHighlighter; + + +/** + * Table des transaction qui ajoute des comportement (keys). + * + * @author ore + * @author Rémi Chapelet + */ +public class FinancialTransactionTable extends JXTable implements KeyListener { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3133690382049594727L; + + /** log. */ + private static final Log log = LogFactory.getLog(FinancialTransactionTable.class); + + protected FinancialTransactionViewHandler handler; + + private ColorHighlighter colorEmptyLine; + + private ColorHighlighter colorTransaction; + + private ColorHighlighter colorBalance; + + private EmptyLineSelectionListener emptyLineSelectionListener; + + /** + */ + public FinancialTransactionTable(FinancialTransactionViewHandler handler/*, + TransactionTableModel model, + TransactionSortedTableColumnModel columnModel*/) { + //super(model, columnModel); + + this.handler = handler; + + /* + * New Table Header + */ + // header renderer getTableHeader().setDefaultRenderer(TransactionHeaderRenderer.getInstance()); + //getTableHeader().addMouseListener(new TransactionHeaderListener(this)); + + /* + * Mod : il est possible d'activer cette option. + * Lorsque l'utilisateur clique sur une ligne du tableau, on ajoute + * automatiquement une nouvelle ligne (une entrée comptable) + */ + //addMouseListener(getEmptyLineSelectionListener()); + + /* + * Mod : il est possible d'activer cette option. + * Lorsque l'utilisateur appuie sur une touche "insert" ou autres, le + * programme insère une ligne comptable. + */ + addKeyListener(this); + + // cell rendering + /*TableColumnModel tcm = getColumnModel(); + tcm.getColumn(TransactionEnum.DATE.ordinal()).setCellRenderer(DateTableCellRenderer.getInstance()); + tcm.getColumn(TransactionEnum.ACCOUNT.ordinal()).setCellRenderer(AccountTableCellRenderer.getInstance()); + tcm.getColumn(TransactionEnum.JOURNAL.ordinal()).setCellRenderer(JournalTableCellRenderer.getInstance()); + tcm.getColumn(TransactionEnum.PERIOD.ordinal()).setCellRenderer(PeriodTableCellRenderer.getInstance()); + tcm.getColumn(TransactionEnum.STATUS.ordinal()).setCellRenderer(StatusTableCellRenderer.getInstance()); + tcm.getColumn(TransactionEnum.DEBIT.ordinal()).setCellRenderer(AmountTableCellRenderer.getInstance()); + tcm.getColumn(TransactionEnum.CREDIT.ordinal()).setCellRenderer(AmountTableCellRenderer.getInstance()); + tcm.getColumn(TransactionEnum.BALANCE.ordinal()).setCellRenderer(AmountTableCellRenderer.getInstance()); + tcm.getColumn(TransactionEnum.DESCRIPTION.ordinal()).setCellRenderer(TextTableCellRenderer.getInstance()); + tcm.getColumn(TransactionEnum.DOCUMENT.ordinal()).setCellRenderer(TextTableCellRenderer.getInstance()); + + // cell editoring + tcm.getColumn(TransactionEnum.DATE.ordinal()).setCellEditor(DateTableCellEditor.getInstance()); + tcm.getColumn(TransactionEnum.ACCOUNT.ordinal()).setCellEditor(AccountTableCellEditor.getInstance()); + tcm.getColumn(TransactionEnum.JOURNAL.ordinal()).setCellEditor(JournalTableCellEditor.getInstance()); + tcm.getColumn(TransactionEnum.DEBIT.ordinal()).setCellEditor(NumberTableCellEditor.getInstance()); + tcm.getColumn(TransactionEnum.CREDIT.ordinal()).setCellEditor(NumberTableCellEditor.getInstance()); + tcm.getColumn(TransactionEnum.DESCRIPTION.ordinal()).setCellEditor(TextTableCellEditor.getInstance()); + tcm.getColumn(TransactionEnum.DOCUMENT.ordinal()).setCellEditor(TextTableCellEditor.getInstance()); + tcm.getColumn(TransactionEnum.PERIOD.ordinal()).setCellEditor(PeriodTableCellEditor.getInstance());*/ + + setDefaultEditor(Date.class, new DateTableCellEditor()); + + + // Color transactions + // addColorTransaction(); + // addColorNonBalancedTransaction(); + } + + /** + * + */ + public void addColorEmptyLine() { + + // Renvoie une couleur jaune pour chaque nouvelle ligne créée + /*removeColorEmptyLine(); + if (TransactionFlattenTableModel.isFlattenModel(getModel())) { + final int posNext = ((TransactionFlattenTableModel) getModel()).getEmptyLinePosition(); + HighlightPredicate predicate = new HighlightPredicate() { + + @Override + public boolean isHighlighted(Component arg0, ComponentAdapter adapter) { + return adapter.row == posNext; + } + }; + colorEmptyLine = new ColorHighlighter(predicate, new Color(248,255,136), Color.BLACK,new Color(248,255,136), Color.BLACK); + addHighlighter(colorEmptyLine); + }*/ + } + + /** + * + */ + public void removeColorEmptyLine() { + if (colorEmptyLine != null) { + removeHighlighter(colorEmptyLine); + } + } + + /** + * Cette méthode permet de colorer toutes les transactions dans le tableau + * afin de bien distinguer les transactions et entrées comptables. + */ + /* protected void addColorTransaction() { + if (colorTransaction != null) { + removeHighlighter(colorTransaction); + } + HighlightPredicate predicate = new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, + ComponentAdapter adapter) { + return getModel().getElementAt(adapter.row) instanceof Transaction; + } + }; + colorTransaction = new ColorHighlighter(predicate, new Color(222, 222, + 222), null, null, null); + addHighlighter(colorTransaction); + }*/ + + /** + * Permet de surligner une transaction dans le tableau lorsque cette dernière + * n'est pas équilibrée. + */ +/* protected void addColorNonBalancedTransaction() { + if (colorBalance != null) { + removeHighlighter(colorBalance); + } + HighlightPredicate predicate = new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, + ComponentAdapter adapter) { + boolean isHighlighted = false; + Object value = getModel().getElementAt(adapter.row); + if (value instanceof Transaction) { + Transaction currentTransaction = (Transaction) value; + if (!TransactionHelper.isBalanced(currentTransaction)) { + isHighlighted = true; + } + } + return isHighlighted; + } + }; + colorTransaction = new ColorHighlighter(predicate, new Color(255, 198, + 209), null, null, null); + addHighlighter(colorTransaction); + }*/ + + /* @Override + public TransactionTableModel getModel() { + return (TransactionTableModel) this.dataModel; + } + + @Override + public TransactionSortedTableColumnModel getColumnModel() { + return (TransactionSortedTableColumnModel) this.columnModel; + } + +*/ + /* + public EmptyLineSelectionListener getEmptyLineSelectionListener() { + if (emptyLineSelectionListener == null) { + return new EmptyLineSelectionListener(); + } + return emptyLineSelectionListener; + } +*/ + @Override + public void keyPressed(KeyEvent e) { + + // VK_DELETE suppression de la transaction en cours + // ou de l'entree + if (e.getKeyCode() == KeyEvent.VK_DELETE) { + // handler.deleteSelectedRow(); + } + + // Touche : insert ou ctrl+I + // Ajoute une transaction + if ((e.getKeyCode() == KeyEvent.VK_INSERT) + || (e.getKeyCode() == KeyEvent.VK_I && e.getModifiers() == KeyEvent.CTRL_MASK)) { + + // TODO EC 20100408 String result = table.getModel().addEmptyTransaction(); + } + + // Touche '+' OU 'ctrl+Entr' + // Ajoute une entrée comptable ou transaction + if (e.getKeyCode() == KeyEvent.VK_PLUS + || (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() == KeyEvent.CTRL_MASK)) { + /*int max_y = table.getRowCount(); + addLine(table); + table.setColumnSelectionInterval(0, 0); + table.setRowSelectionInterval(max_y, max_y);*/ + } + + /** + * Touche tab + * Ajoute une entrée comptable ou transaction seulement si tab est sur + * la dernière cellule. + */ + if (e.getKeyChar() == KeyEvent.VK_TAB) { + // Vérifie si la cellule sélectionnée est la dernière + /*int x = table.getSelectedColumn(); + int y = table.getSelectedRow(); + int max_x = table.getColumnCount() - 1; + int max_y = table.getRowCount() - 1; + if (x == max_x && y == max_y) { + boolean result = addLine(table); + // positionne la sélection sur la nouvelle ligne créée + if (result) { + table.setColumnSelectionInterval(0, 0); + table.setRowSelectionInterval(max_y + 1, max_y + 1); + } + }*/ + } + + } + + /* + * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent) + */ + @Override + public void keyTyped(KeyEvent e) { + + } + + /* + * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) + */ + @Override + public void keyReleased(KeyEvent e) { + + } + + /** + * Permet d'ajouter une nouvelle ligne : transaction ou entrée + * @param table la table + * @return + */ + /*private boolean addLine(TransactionJXTable table) { + if (TransactionFlattenTableModel.isFlattenModel(table.getModel())) { + // Vérifie si le tableau est vide, alors ajout d'une transaction + if (table.getRowCount() == 0) { + String result = table.getModel().addEmptyTransaction(); + ErrorMessage.showMessage(result); + return true; + } + TransactionFlattenTableModel flattenModel = (TransactionFlattenTableModel) table + .getModel(); + int selectedRow = 0; + // Vérifie si une ligne est sélectionnée ou non + if (table.getSelectionModel().isSelectionEmpty()) { + // Not line selected + selectedRow = table.getRowCount() - 1; + } else { + // Line selected + selectedRow = table.getSelectedRow(); + } + // Récupère la position de la transaction rattachée + int parentIndex = flattenModel.getParentIndex(selectedRow); + + // Is transaction editable ? + Object o = flattenModel.getElementAt(parentIndex); + if (DTOHelper.isTransaction(o)) { + // Transaction n'est pas éditable + if (!ServiceHelper.isEditable((TransactionDTO) o)) { + return false; + } + } else { + //Entry n'est pas éditable + if (!ServiceHelper.isEditable((EntryDTO) o)) { + return false; + } + } + + // Vérifie si la transaction est équilibrée ou non (et qu'elle posséde des entrées) + TransactionDTO transaction = (TransactionDTO) flattenModel + .getElementAt(parentIndex); + if (DTOHelper.isBalanced(transaction) + && !transaction.getEntries().isEmpty()) { + String result = table.getModel().addEmptyTransaction(); + ErrorMessage.showMessage(result); + return true; + } + + // Vérifie si une ligne est sélectionnée ou non + if (table.getSelectionModel().isSelectionEmpty()) { + // Not line selected + // Click in not current transaction + if (flattenModel.getCurrentParentIndex() != parentIndex) { + int posNext = selectedRow + 1; + flattenModel.createEmptyLine(); + flattenModel.addEmptyLine(posNext); + // To end + flattenModel.setCurrentParentIndex(parentIndex); + } + + // New Line Color + table.addColorEmptyLine(); + } else { + // Line selected + // Click in not current transaction + if (flattenModel.getCurrentParentIndex() != parentIndex) { + int posNext = flattenModel + .emptyLineNextPosition(selectedRow); + + // Once traitement for transaction + if (flattenModel.isEmptyLineEmpty()) { + flattenModel.createEmptyLine(); + } else { + flattenModel.removeEmptyLine(); + selectedRow = table.getSelectedRow(); + parentIndex = flattenModel.getParentIndex(selectedRow); + posNext = flattenModel + .emptyLineNextPosition(selectedRow); + flattenModel.createEmptyLine(); + } + flattenModel.addEmptyLine(posNext); + // To end + flattenModel.setCurrentParentIndex(parentIndex); + } + + // New Line Color + table.addColorEmptyLine(); + } + return true; + } + return false; + }*/ +} Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java (from rev 2863, trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/TransactionTableModel.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -0,0 +1,506 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.ui.transaction.table; + +import static org.nuiton.i18n.I18n._; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.swing.table.AbstractTableModel; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.RecordService; +import org.chorem.lima.business.FinancialTransactionService; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.LimaCallaoDAOHelper; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.ui.transaction.FinancialTransactionHelper; +import org.chorem.lima.util.ErrorHelper; +import org.nuiton.topia.TopiaContextFactory; + +/** + * Basic transaction table model. + * + * Le modele est filtré sur {@link #selectedEntryBook} et + * {@link #selectedFinancialPeriod} (montée en charge !). + * + * TODO EC20100408 revoir le modele, avoir des transactions et des entries + * c'est pas gérables. + * Le mieux serait d'avoir un "mega component transaction par ligne" et + * que ce composant puisse editer les entries. + * Ou autre chose. + * + * @author ore + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class FinancialTransactionTableModel extends AbstractTableModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3914954536809622358L; + + /** log. */ + private static final Log log = LogFactory + .getLog(FinancialTransactionTableModel.class); + + /** Transaction service. */ + protected final FinancialTransactionService transactionService; + /** Record service. */ + protected final RecordService recordService; + + protected EntryBook selectedEntryBook; + + protected FinancialPeriod selectedFinancialPeriod; + + /** + * Model constructor. + * + * Just init service proxies. + */ + public FinancialTransactionTableModel() { + /* Services */ + recordService = LimaServiceFactory.getInstance().getRecordService(); + transactionService = LimaServiceFactory.getInstance() + .getTransactionService(); + } + + /** + * Le model est une combinaison de Transaction/Entries. + * + * TODO EC20100408 c'est pas evident a manipuler via une table + * + * @return + */ + protected List<Object> getDataList() { + + log.debug("getDatalist"); + + List<Object> results = new ArrayList<Object>(); + try { + + List<FinancialTransaction> financialtransactions = + transactionService.getAllFinancialTransactionsForEntryBookAndFinancialPeriod(selectedEntryBook, selectedFinancialPeriod); + + for (FinancialTransaction financialtransaction : financialtransactions) { + results.add(financialtransaction); + // TODO EC20100408 warn about lazy exception here + // TODO EC20100408 warn about non ordonned transaction.getEntry() + results.addAll(financialtransaction.getEntry()); + } + } + catch (LimaException eee) { + if (log.isErrorEnabled()) { + log.debug("Can't update model", eee); + } + + ErrorHelper.showErrorDialog("Can't get transaction list", eee); + } + + return results; + } + + @Override + public int getColumnCount() { + return 10; + } + + @Override + public Class<?> getColumnClass(int column) { + + Class<?> result = null; + + switch (column) { + case 0: + result = Date.class; + break; + case 1: + result = Account.class; + break; + case 2: + result = EntryBook.class; + break; + case 3: + result = FinancialPeriod.class; + break; + case 4: + result = String.class; + break; + case 5: + result = Double.class; + break; + case 6: + result = Double.class; + break; + case 7: + result = String.class; + break; + case 8: + result = String.class; + break; + case 9: + result = String.class; + break; + } + + return result; + } + + @Override + public String getColumnName(int column) { + String result = "n/a"; + + switch (column) { + case 0: + result = _("lima.transaction.column.date"); + break; + case 1: + result = _("lima.transaction.column.account"); + break; + case 2: + result = _("lima.transaction.column.entrybook"); + break; + case 3: + result = _("lima.transaction.column.period"); + break; + case 4: + result = _("lima.transaction.column.status"); + break; + case 5: + result = _("lima.transaction.column.debit"); + break; + case 6: + result = _("lima.transaction.column.credit"); + break; + case 7: + result = _("lima.transaction.column.balance"); + break; + case 8: + result = _("lima.transaction.column.description"); + break; + case 9: + result = _("lima.transaction.column.document"); + break; + } + + return result; + } + + @Override + public int getRowCount() { + int result = 0; + + // just prevent too much result + if (selectedEntryBook != null) { + List<Object> datas = getDataList(); + result = datas.size(); + } + else { + if (log.isDebugEnabled()) { + log.debug("No entry book selected skip table model update"); + } + } + + return result; + } + + @Override + public Object getValueAt(int row, int column) { + Object result = null; + + // just prevent too much result + System.out.println("OK2"); + if (selectedEntryBook != null) { + // TODO EC-20100407 remove this ugly code + List<Object> datas = getDataList(); + result = datas.get(row); + + if (result instanceof FinancialTransaction) { + FinancialTransaction currentRow = (FinancialTransaction)result; + switch (column) { + case 0: + result = currentRow.getTransactionDate(); + break; + case 1: + result = null; // account ? + break; + case 2: + result = null; // entry book + break; + case 3: + result = null; //currentRow.getFinancialPeriod(); + break; + case 4: + result = null; // what is status ? _("lima.transaction.column.status"); + break; + case 5: + result = FinancialTransactionHelper.getDebit(currentRow); + break; + case 6: + result = FinancialTransactionHelper.getCredit(currentRow); + break; + case 7: + result = FinancialTransactionHelper.getDebit(currentRow) - FinancialTransactionHelper.getCredit(currentRow); + break; + case 8: + result = currentRow.getDescription(); + break; + case 9: + result = currentRow.getVoucherRef(); + break; + } + } + else if (result instanceof Entry) { + Entry currentEntry = (Entry)result; + switch (column) { + case 0: + result = null; // date + break; + case 1: + result = currentEntry.getAccount(); // account ? + break; + case 2: + result = null; // entry book + break; + case 3: + result = null; //currentRow.getFinancialPeriod(); + break; + case 4: + result = null; // what is status ? _("lima.transaction.column.status"); + break; + case 5: + result = currentEntry.getDebit() ? currentEntry.getAmount() : 0; + break; + case 6: + result = currentEntry.getDebit() ? 0 : currentEntry.getAmount(); + break; + case 7: + result = null; + break; + case 8: + result = currentEntry.getDescription(); + break; + case 9: + result = null; + break; + } + } + } + else { + if (log.isDebugEnabled()) { + log.debug("No entry book selected skip table model update"); + } + } + + return result; + } + + + public void setEntryBook(EntryBook entryBook){ + + System.out.println("OK"); + selectedEntryBook = entryBook; + fireTableDataChanged(); + } + + /** + * @throws LimaException + */ + public void addFinancialTransaction() throws LimaException{ + /* Calling transaction service */ + //TODO transaction = currentdate, current periode, current journal + FinancialTransaction financialtransaction =null; + financialtransaction.setFinancialPeriod(selectedFinancialPeriod); + financialtransaction.setEntryBook(selectedEntryBook); + //financialransaction.setDescription(description); + transactionService.createFinancialTransaction(financialtransaction); + int row = getDataList().indexOf(financialtransaction); + //int row = transactionService.getAllTransactions().indexOf(transaction); + log.debug(row); + fireTableRowsInserted(row, row); + } + + + + /** + * @throws LimaException + */ + public void addEmptyEntry(Object value, int row) { + /* Calling transaction service */ + //TODO transaction = currentdate, current periode, current journal + List<Object> datas = getDataList(); + Object currentRow = datas.get(row); + Entry entry=null; + if (currentRow instanceof FinancialTransaction) { + FinancialTransaction currentTransaction = (FinancialTransaction)currentRow; + currentTransaction.addEntry(entry); + } + else if (currentRow instanceof Entry) { + Entry currentEntry = (Entry)currentRow; + //TODO recuperer l'entrée parente, ajouter entrée + } + fireTableRowsUpdated(row, row); + } + + + @Override + public void setValueAt(Object value, int row, int column) { + + // just prevent too much result + if (selectedEntryBook != null) { + // TODO EC-20100407 remove this ugly code + List<Object> datas = getDataList(); + Object currentRow = datas.get(row); + + if (currentRow instanceof FinancialTransaction) { + FinancialTransaction currentFinancialTransaction = + (FinancialTransaction)currentRow; + switch (column) { + case 0: + currentFinancialTransaction.setTransactionDate((Date)value); + break; + /*case 1: + result = null; // account ? + break; + case 2: + result = null; // entry book + break; + case 3: + result = null; //currentRow.getFinancialPeriod(); + break; + case 4: + result = null; // what is status ? _("lima.transaction.column.status"); + break; + case 5: + result = TransactionHelper.getDebit(currentRow); + break; + case 6: + result = TransactionHelper.getCredit(currentRow); + break; + case 7: + result = TransactionHelper.getDebit(currentRow) - TransactionHelper.getCredit(currentRow); + break;*/ + case 8: + currentFinancialTransaction.setDescription((String)value); + break; + case 9: + currentFinancialTransaction.setVoucherRef((String)value); + break; + } + + // notify service for modification + try { + transactionService.updateFinancialTransaction(currentFinancialTransaction); + } catch (LimaException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + //fireTableRowsUpdated(row, row); // to update what ??? + + } + else if (currentRow instanceof Entry) { + Entry currentEntry = (Entry)currentRow; + switch (column) { + /*case 0: + result = null; // date + break;*/ + case 1: + currentEntry.setAccount((Account)value); // account ? + break; + /*case 2: + result = null; // entry book + break; + case 3: + result = null; //currentRow.getFinancialPeriod(); + break; + case 4: + result = null; // what is status ? _("lima.transaction.column.status"); + break;*/ + case 5: + currentEntry.setAmount((Double)value); + currentEntry.setDebit(true); + break; + case 6: + currentEntry.setAmount((Double)value); + currentEntry.setDebit(false); + break; + /*case 7: + result = null; + break;*/ + case 8: + currentEntry.setDescription((String)value); + break; + /*case 9: + result = null; + break;*/ + } + + //transactionService.updateEntry(currentEntry); + // fire modification of all transaction + // see here, table is not adapted :) + } + } + else { + if (log.isDebugEnabled()) { + log.debug("No entry book selected skip table model update"); + } + } + } + + public Object getElementAt(int row){ + + List<Object> datas = getDataList(); + Object currentRow = datas.get(row); + return currentRow; + } + + + /** + * Delete selected row in table (could be transaction or entry). + * + * Called by model. + * @param Object, int + * @throws LimaException + */ + public void removeObject(Object object, int row) throws LimaException { + /* Calling journal service */ + + List<Object> datas = getDataList(); + Object currentRow = datas.get(row); + if (currentRow instanceof FinancialTransaction) { + FinancialTransaction currentTransaction = (FinancialTransaction)currentRow; + transactionService.removeFinancialTransaction(currentTransaction); + fireTableRowsDeleted(row, row); + } + else if (currentRow instanceof Entry) { + Entry currentEntry = (Entry)currentRow; + //TODO supprimer l'entrée + } + } +} Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/TransactionTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/TransactionTable.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/TransactionTable.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -1,383 +0,0 @@ -/* *##% Lima Swing - * Copyright (C) 2008 - 2010 CodeLutin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ##%*/ - -package org.chorem.lima.ui.transaction.table; - -import java.awt.Color; -import java.awt.Component; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.util.Date; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.entity.Transaction; -import org.chorem.lima.listener.EmptyLineSelectionListener; -import org.chorem.lima.table.editor.DateTableCellEditor; -import org.chorem.lima.table.model.TransactionSortedTableColumnModel; -import org.chorem.lima.table.model.TransactionTableModel; -import org.chorem.lima.ui.transaction.TransactionHelper; -import org.chorem.lima.ui.transaction.TransactionViewHandler; -import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.decorator.ColorHighlighter; -import org.jdesktop.swingx.decorator.ComponentAdapter; -import org.jdesktop.swingx.decorator.HighlightPredicate; - -/** - * Table des transaction qui ajoute des comportement (keys). - * - * @author ore - * @author Rémi Chapelet - */ -public class TransactionTable extends JXTable implements KeyListener { - - /** serialVersionUID. */ - private static final long serialVersionUID = 3133690382049594727L; - - /** log. */ - private static final Log log = LogFactory.getLog(TransactionTable.class); - - protected TransactionViewHandler handler; - - private ColorHighlighter colorEmptyLine; - - private ColorHighlighter colorTransaction; - - private ColorHighlighter colorBalance; - - private EmptyLineSelectionListener emptyLineSelectionListener; - - /** - */ - public TransactionTable(TransactionViewHandler handler/*, - TransactionTableModel model, - TransactionSortedTableColumnModel columnModel*/) { - //super(model, columnModel); - - this.handler = handler; - - /* - * New Table Header - */ - // header renderer getTableHeader().setDefaultRenderer(TransactionHeaderRenderer.getInstance()); - //getTableHeader().addMouseListener(new TransactionHeaderListener(this)); - - /* - * Mod : il est possible d'activer cette option. - * Lorsque l'utilisateur clique sur une ligne du tableau, on ajoute - * automatiquement une nouvelle ligne (une entrée comptable) - */ - //addMouseListener(getEmptyLineSelectionListener()); - - /* - * Mod : il est possible d'activer cette option. - * Lorsque l'utilisateur appuie sur une touche "insert" ou autres, le - * programme insère une ligne comptable. - */ - addKeyListener(this); - - // cell rendering - /*TableColumnModel tcm = getColumnModel(); - tcm.getColumn(TransactionEnum.DATE.ordinal()).setCellRenderer(DateTableCellRenderer.getInstance()); - tcm.getColumn(TransactionEnum.ACCOUNT.ordinal()).setCellRenderer(AccountTableCellRenderer.getInstance()); - tcm.getColumn(TransactionEnum.JOURNAL.ordinal()).setCellRenderer(JournalTableCellRenderer.getInstance()); - tcm.getColumn(TransactionEnum.PERIOD.ordinal()).setCellRenderer(PeriodTableCellRenderer.getInstance()); - tcm.getColumn(TransactionEnum.STATUS.ordinal()).setCellRenderer(StatusTableCellRenderer.getInstance()); - tcm.getColumn(TransactionEnum.DEBIT.ordinal()).setCellRenderer(AmountTableCellRenderer.getInstance()); - tcm.getColumn(TransactionEnum.CREDIT.ordinal()).setCellRenderer(AmountTableCellRenderer.getInstance()); - tcm.getColumn(TransactionEnum.BALANCE.ordinal()).setCellRenderer(AmountTableCellRenderer.getInstance()); - tcm.getColumn(TransactionEnum.DESCRIPTION.ordinal()).setCellRenderer(TextTableCellRenderer.getInstance()); - tcm.getColumn(TransactionEnum.DOCUMENT.ordinal()).setCellRenderer(TextTableCellRenderer.getInstance()); - - // cell editoring - tcm.getColumn(TransactionEnum.DATE.ordinal()).setCellEditor(DateTableCellEditor.getInstance()); - tcm.getColumn(TransactionEnum.ACCOUNT.ordinal()).setCellEditor(AccountTableCellEditor.getInstance()); - tcm.getColumn(TransactionEnum.JOURNAL.ordinal()).setCellEditor(JournalTableCellEditor.getInstance()); - tcm.getColumn(TransactionEnum.DEBIT.ordinal()).setCellEditor(NumberTableCellEditor.getInstance()); - tcm.getColumn(TransactionEnum.CREDIT.ordinal()).setCellEditor(NumberTableCellEditor.getInstance()); - tcm.getColumn(TransactionEnum.DESCRIPTION.ordinal()).setCellEditor(TextTableCellEditor.getInstance()); - tcm.getColumn(TransactionEnum.DOCUMENT.ordinal()).setCellEditor(TextTableCellEditor.getInstance()); - tcm.getColumn(TransactionEnum.PERIOD.ordinal()).setCellEditor(PeriodTableCellEditor.getInstance());*/ - - setDefaultEditor(Date.class, new DateTableCellEditor()); - - - // Color transactions - // addColorTransaction(); - // addColorNonBalancedTransaction(); - } - - /** - * - */ - public void addColorEmptyLine() { - - // Renvoie une couleur jaune pour chaque nouvelle ligne créée - /*removeColorEmptyLine(); - if (TransactionFlattenTableModel.isFlattenModel(getModel())) { - final int posNext = ((TransactionFlattenTableModel) getModel()).getEmptyLinePosition(); - HighlightPredicate predicate = new HighlightPredicate() { - - @Override - public boolean isHighlighted(Component arg0, ComponentAdapter adapter) { - return adapter.row == posNext; - } - }; - colorEmptyLine = new ColorHighlighter(predicate, new Color(248,255,136), Color.BLACK,new Color(248,255,136), Color.BLACK); - addHighlighter(colorEmptyLine); - }*/ - } - - /** - * - */ - public void removeColorEmptyLine() { - if (colorEmptyLine != null) { - removeHighlighter(colorEmptyLine); - } - } - - /** - * Cette méthode permet de colorer toutes les transactions dans le tableau - * afin de bien distinguer les transactions et entrées comptables. - */ - /* protected void addColorTransaction() { - if (colorTransaction != null) { - removeHighlighter(colorTransaction); - } - HighlightPredicate predicate = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, - ComponentAdapter adapter) { - return getModel().getElementAt(adapter.row) instanceof Transaction; - } - }; - colorTransaction = new ColorHighlighter(predicate, new Color(222, 222, - 222), null, null, null); - addHighlighter(colorTransaction); - }*/ - - /** - * Permet de surligner une transaction dans le tableau lorsque cette dernière - * n'est pas équilibrée. - */ -/* protected void addColorNonBalancedTransaction() { - if (colorBalance != null) { - removeHighlighter(colorBalance); - } - HighlightPredicate predicate = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, - ComponentAdapter adapter) { - boolean isHighlighted = false; - Object value = getModel().getElementAt(adapter.row); - if (value instanceof Transaction) { - Transaction currentTransaction = (Transaction) value; - if (!TransactionHelper.isBalanced(currentTransaction)) { - isHighlighted = true; - } - } - return isHighlighted; - } - }; - colorTransaction = new ColorHighlighter(predicate, new Color(255, 198, - 209), null, null, null); - addHighlighter(colorTransaction); - }*/ - - /* @Override - public TransactionTableModel getModel() { - return (TransactionTableModel) this.dataModel; - } - - @Override - public TransactionSortedTableColumnModel getColumnModel() { - return (TransactionSortedTableColumnModel) this.columnModel; - } - -*/ - /* - public EmptyLineSelectionListener getEmptyLineSelectionListener() { - if (emptyLineSelectionListener == null) { - return new EmptyLineSelectionListener(); - } - return emptyLineSelectionListener; - } -*/ - @Override - public void keyPressed(KeyEvent e) { - - // VK_DELETE suppression de la transaction en cours - // ou de l'entree - if (e.getKeyCode() == KeyEvent.VK_DELETE) { - // handler.deleteSelectedRow(); - } - - // Touche : insert ou ctrl+I - // Ajoute une transaction - if ((e.getKeyCode() == KeyEvent.VK_INSERT) - || (e.getKeyCode() == KeyEvent.VK_I && e.getModifiers() == KeyEvent.CTRL_MASK)) { - - // TODO EC 20100408 String result = table.getModel().addEmptyTransaction(); - } - - // Touche '+' OU 'ctrl+Entr' - // Ajoute une entrée comptable ou transaction - if (e.getKeyCode() == KeyEvent.VK_PLUS - || (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() == KeyEvent.CTRL_MASK)) { - /*int max_y = table.getRowCount(); - addLine(table); - table.setColumnSelectionInterval(0, 0); - table.setRowSelectionInterval(max_y, max_y);*/ - } - - /** - * Touche tab - * Ajoute une entrée comptable ou transaction seulement si tab est sur - * la dernière cellule. - */ - if (e.getKeyChar() == KeyEvent.VK_TAB) { - // Vérifie si la cellule sélectionnée est la dernière - /*int x = table.getSelectedColumn(); - int y = table.getSelectedRow(); - int max_x = table.getColumnCount() - 1; - int max_y = table.getRowCount() - 1; - if (x == max_x && y == max_y) { - boolean result = addLine(table); - // positionne la sélection sur la nouvelle ligne créée - if (result) { - table.setColumnSelectionInterval(0, 0); - table.setRowSelectionInterval(max_y + 1, max_y + 1); - } - }*/ - } - - } - - /* - * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent) - */ - @Override - public void keyTyped(KeyEvent e) { - - } - - /* - * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) - */ - @Override - public void keyReleased(KeyEvent e) { - - } - - /** - * Permet d'ajouter une nouvelle ligne : transaction ou entrée - * @param table la table - * @return - */ - /*private boolean addLine(TransactionJXTable table) { - if (TransactionFlattenTableModel.isFlattenModel(table.getModel())) { - // Vérifie si le tableau est vide, alors ajout d'une transaction - if (table.getRowCount() == 0) { - String result = table.getModel().addEmptyTransaction(); - ErrorMessage.showMessage(result); - return true; - } - TransactionFlattenTableModel flattenModel = (TransactionFlattenTableModel) table - .getModel(); - int selectedRow = 0; - // Vérifie si une ligne est sélectionnée ou non - if (table.getSelectionModel().isSelectionEmpty()) { - // Not line selected - selectedRow = table.getRowCount() - 1; - } else { - // Line selected - selectedRow = table.getSelectedRow(); - } - // Récupère la position de la transaction rattachée - int parentIndex = flattenModel.getParentIndex(selectedRow); - - // Is transaction editable ? - Object o = flattenModel.getElementAt(parentIndex); - if (DTOHelper.isTransaction(o)) { - // Transaction n'est pas éditable - if (!ServiceHelper.isEditable((TransactionDTO) o)) { - return false; - } - } else { - //Entry n'est pas éditable - if (!ServiceHelper.isEditable((EntryDTO) o)) { - return false; - } - } - - // Vérifie si la transaction est équilibrée ou non (et qu'elle posséde des entrées) - TransactionDTO transaction = (TransactionDTO) flattenModel - .getElementAt(parentIndex); - if (DTOHelper.isBalanced(transaction) - && !transaction.getEntries().isEmpty()) { - String result = table.getModel().addEmptyTransaction(); - ErrorMessage.showMessage(result); - return true; - } - - // Vérifie si une ligne est sélectionnée ou non - if (table.getSelectionModel().isSelectionEmpty()) { - // Not line selected - // Click in not current transaction - if (flattenModel.getCurrentParentIndex() != parentIndex) { - int posNext = selectedRow + 1; - flattenModel.createEmptyLine(); - flattenModel.addEmptyLine(posNext); - // To end - flattenModel.setCurrentParentIndex(parentIndex); - } - - // New Line Color - table.addColorEmptyLine(); - } else { - // Line selected - // Click in not current transaction - if (flattenModel.getCurrentParentIndex() != parentIndex) { - int posNext = flattenModel - .emptyLineNextPosition(selectedRow); - - // Once traitement for transaction - if (flattenModel.isEmptyLineEmpty()) { - flattenModel.createEmptyLine(); - } else { - flattenModel.removeEmptyLine(); - selectedRow = table.getSelectedRow(); - parentIndex = flattenModel.getParentIndex(selectedRow); - posNext = flattenModel - .emptyLineNextPosition(selectedRow); - flattenModel.createEmptyLine(); - } - flattenModel.addEmptyLine(posNext); - // To end - flattenModel.setCurrentParentIndex(parentIndex); - } - - // New Line Color - table.addColorEmptyLine(); - } - return true; - } - return false; - }*/ -} Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/TransactionTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/TransactionTableModel.java 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/TransactionTableModel.java 2010-04-16 10:26:55 UTC (rev 2864) @@ -1,505 +0,0 @@ -/* *##% Lima Swing - * Copyright (C) 2008 - 2010 CodeLutin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ##%*/ - -package org.chorem.lima.ui.transaction.table; - -import static org.nuiton.i18n.I18n._; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import javax.swing.table.AbstractTableModel; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.LimaException; -import org.chorem.lima.business.RecordService; -import org.chorem.lima.business.TransactionService; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.entity.FinancialPeriod; -import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.chorem.lima.entity.Transaction; -import org.chorem.lima.service.LimaServiceFactory; -import org.chorem.lima.ui.transaction.TransactionHelper; -import org.chorem.lima.util.ErrorHelper; -import org.nuiton.topia.TopiaContextFactory; - -/** - * Basic transaction table model. - * - * Le modele est filtré sur {@link #selectedEntryBook} et - * {@link #selectedFinancialPeriod} (montée en charge !). - * - * TODO EC20100408 revoir le modele, avoir des transactions et des entries - * c'est pas gérables. - * Le mieux serait d'avoir un "mega component transaction par ligne" et - * que ce composant puisse editer les entries. - * Ou autre chose. - * - * @author ore - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class TransactionTableModel extends AbstractTableModel { - - /** serialVersionUID. */ - private static final long serialVersionUID = 3914954536809622358L; - - /** log. */ - private static final Log log = LogFactory - .getLog(TransactionTableModel.class); - - /** Transaction service. */ - protected final TransactionService transactionService; - /** Record service. */ - protected final RecordService recordService; - - protected EntryBook selectedEntryBook; - - protected FinancialPeriod selectedFinancialPeriod; - - /** - * Model constructor. - * - * Just init service proxies. - */ - public TransactionTableModel() { - /* Services */ - recordService = LimaServiceFactory.getInstance().getRecordService(); - transactionService = LimaServiceFactory.getInstance() - .getTransactionService(); - } - - /** - * Le model est une combinaison de Transaction/Entries. - * - * TODO EC20100408 c'est pas evident a manipuler via une table - * - * @return - */ - protected List<Object> getDataList() { - - log.debug("getDatalist"); - - List<Object> results = new ArrayList<Object>(); - try { - - List<Transaction> transactions = - transactionService.getAllTransactionsForEntryBookAndFinancialPeriod(selectedEntryBook, selectedFinancialPeriod); - - for (Transaction transaction : transactions) { - results.add(transaction); - // TODO EC20100408 warn about lazy exception here - // TODO EC20100408 warn about non ordonned transaction.getEntry() - results.addAll(transaction.getEntry()); - } - } - catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.debug("Can't update model", eee); - } - - ErrorHelper.showErrorDialog("Can't get transaction list", eee); - } - - return results; - } - - @Override - public int getColumnCount() { - return 10; - } - - @Override - public Class<?> getColumnClass(int column) { - - Class<?> result = null; - - switch (column) { - case 0: - result = Date.class; - break; - case 1: - result = Account.class; - break; - case 2: - result = EntryBook.class; - break; - case 3: - result = FinancialPeriod.class; - break; - case 4: - result = String.class; - break; - case 5: - result = Double.class; - break; - case 6: - result = Double.class; - break; - case 7: - result = String.class; - break; - case 8: - result = String.class; - break; - case 9: - result = String.class; - break; - } - - return result; - } - - @Override - public String getColumnName(int column) { - String result = "n/a"; - - switch (column) { - case 0: - result = _("lima.transaction.column.date"); - break; - case 1: - result = _("lima.transaction.column.account"); - break; - case 2: - result = _("lima.transaction.column.entrybook"); - break; - case 3: - result = _("lima.transaction.column.period"); - break; - case 4: - result = _("lima.transaction.column.status"); - break; - case 5: - result = _("lima.transaction.column.debit"); - break; - case 6: - result = _("lima.transaction.column.credit"); - break; - case 7: - result = _("lima.transaction.column.balance"); - break; - case 8: - result = _("lima.transaction.column.description"); - break; - case 9: - result = _("lima.transaction.column.document"); - break; - } - - return result; - } - - @Override - public int getRowCount() { - int result = 0; - - // just prevent too much result - if (selectedEntryBook != null) { - List<Object> datas = getDataList(); - result = datas.size(); - } - else { - if (log.isDebugEnabled()) { - log.debug("No entry book selected skip table model update"); - } - } - - return result; - } - - @Override - public Object getValueAt(int row, int column) { - Object result = null; - - // just prevent too much result - System.out.println("OK2"); - if (selectedEntryBook != null) { - // TODO EC-20100407 remove this ugly code - List<Object> datas = getDataList(); - result = datas.get(row); - - if (result instanceof Transaction) { - Transaction currentRow = (Transaction)result; - switch (column) { - case 0: - result = currentRow.getTransactionDate(); - break; - case 1: - result = null; // account ? - break; - case 2: - result = null; // entry book - break; - case 3: - result = null; //currentRow.getFinancialPeriod(); - break; - case 4: - result = null; // what is status ? _("lima.transaction.column.status"); - break; - case 5: - result = TransactionHelper.getDebit(currentRow); - break; - case 6: - result = TransactionHelper.getCredit(currentRow); - break; - case 7: - result = TransactionHelper.getDebit(currentRow) - TransactionHelper.getCredit(currentRow); - break; - case 8: - result = currentRow.getDescription(); - break; - case 9: - result = currentRow.getVoucherRef(); - break; - } - } - else if (result instanceof Entry) { - Entry currentEntry = (Entry)result; - switch (column) { - case 0: - result = null; // date - break; - case 1: - result = currentEntry.getAccount(); // account ? - break; - case 2: - result = null; // entry book - break; - case 3: - result = null; //currentRow.getFinancialPeriod(); - break; - case 4: - result = null; // what is status ? _("lima.transaction.column.status"); - break; - case 5: - result = currentEntry.getDebit() ? currentEntry.getAmount() : 0; - break; - case 6: - result = currentEntry.getDebit() ? 0 : currentEntry.getAmount(); - break; - case 7: - result = null; - break; - case 8: - result = currentEntry.getDescription(); - break; - case 9: - result = null; - break; - } - } - } - else { - if (log.isDebugEnabled()) { - log.debug("No entry book selected skip table model update"); - } - } - - return result; - } - - - public void setEntryBook(EntryBook entryBook){ - - System.out.println("OK"); - selectedEntryBook = entryBook; - fireTableDataChanged(); - } - - /** - * @throws LimaException - */ - public void addTransaction() throws LimaException{ - /* Calling transaction service */ - //TODO transaction = currentdate, current periode, current journal - Transaction transaction =null; - transaction.setFinancialPeriod(selectedFinancialPeriod); - transaction.setEntryBook(selectedEntryBook); - transaction.setDescription(description); - transactionService.createTransaction(transaction); - int row = getDataList().indexOf(transaction); - //int row = transactionService.getAllTransactions().indexOf(transaction); - log.debug(row); - fireTableRowsInserted(row, row); - } - - - - /** - * @throws LimaException - */ - public void addEmptyEntry(Object value, int row) { - /* Calling transaction service */ - //TODO transaction = currentdate, current periode, current journal - List<Object> datas = getDataList(); - Object currentRow = datas.get(row); - Entry entry=null; - if (currentRow instanceof Transaction) { - Transaction currentTransaction = (Transaction)currentRow; - currentTransaction.addEntry(entry); - } - else if (currentRow instanceof Entry) { - Entry currentEntry = (Entry)currentRow; - //TODO recuperer l'entrée parente, ajouter entrée - } - fireTableRowsUpdated(row, row); - } - - - @Override - public void setValueAt(Object value, int row, int column) { - - // just prevent too much result - if (selectedEntryBook != null) { - // TODO EC-20100407 remove this ugly code - List<Object> datas = getDataList(); - Object currentRow = datas.get(row); - - if (currentRow instanceof Transaction) { - Transaction currentTransaction = (Transaction)currentRow; - switch (column) { - case 0: - currentTransaction.setTransactionDate((Date)value); - break; - /*case 1: - result = null; // account ? - break; - case 2: - result = null; // entry book - break; - case 3: - result = null; //currentRow.getFinancialPeriod(); - break; - case 4: - result = null; // what is status ? _("lima.transaction.column.status"); - break; - case 5: - result = TransactionHelper.getDebit(currentRow); - break; - case 6: - result = TransactionHelper.getCredit(currentRow); - break; - case 7: - result = TransactionHelper.getDebit(currentRow) - TransactionHelper.getCredit(currentRow); - break;*/ - case 8: - currentTransaction.setDescription((String)value); - break; - case 9: - currentTransaction.setVoucherRef((String)value); - break; - } - - // notify service for modification - try { - transactionService.updateTransaction(currentTransaction); - } catch (LimaException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - //fireTableRowsUpdated(row, row); // to update what ??? - - } - else if (currentRow instanceof Entry) { - Entry currentEntry = (Entry)currentRow; - switch (column) { - /*case 0: - result = null; // date - break;*/ - case 1: - currentEntry.setAccount((Account)value); // account ? - break; - /*case 2: - result = null; // entry book - break; - case 3: - result = null; //currentRow.getFinancialPeriod(); - break; - case 4: - result = null; // what is status ? _("lima.transaction.column.status"); - break;*/ - case 5: - currentEntry.setAmount((Double)value); - currentEntry.setDebit(true); - break; - case 6: - currentEntry.setAmount((Double)value); - currentEntry.setDebit(false); - break; - /*case 7: - result = null; - break;*/ - case 8: - currentEntry.setDescription((String)value); - break; - /*case 9: - result = null; - break;*/ - } - - //transactionService.updateEntry(currentEntry); - // fire modification of all transaction - // see here, table is not adapted :) - } - } - else { - if (log.isDebugEnabled()) { - log.debug("No entry book selected skip table model update"); - } - } - } - - public Object getElementAt(int row){ - - List<Object> datas = getDataList(); - Object currentRow = datas.get(row); - return currentRow; - } - - - /** - * Delete selected row in table (could be transaction or entry). - * - * Called by model. - * @param Object, int - * @throws LimaException - */ - public void removeObject(Object object, int row) throws LimaException { - /* Calling journal service */ - - List<Object> datas = getDataList(); - Object currentRow = datas.get(row); - if (currentRow instanceof Transaction) { - Transaction currentTransaction = (Transaction)currentRow; - transactionService.removeTransaction(currentTransaction); - fireTableRowsDeleted(row, row); - } - else if (currentRow instanceof Entry) { - Entry currentEntry = (Entry)currentRow; - //TODO supprimer l'entrée - } - } -} Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-04-16 10:26:55 UTC (rev 2864) @@ -89,9 +89,9 @@ lima.entries.addtransaction= lima.entries.lettering= lima.entries.searchtransaction= -lima.entrybook.description= +lima.entrybook.code= lima.entrybook.label= -lima.entrybook.prefix= +lima.entrybook.type= lima.error=Error lima.error.account.double=It exists an account with a same number lima.error.account.not.exist=This account doesn't exist Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-04-15 15:30:01 UTC (rev 2863) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-04-16 10:26:55 UTC (rev 2864) @@ -87,9 +87,9 @@ lima.entries.addtransaction=Ajouter une transaction lima.entries.lettering=Ajouter une lettre lima.entries.searchtransaction=Recherche les transactions -lima.entrybook.description=Description +lima.entrybook.code=Code lima.entrybook.label=Libelle -lima.entrybook.prefix=Pr\u00E9fixe +lima.entrybook.type=Type lima.error=Erreur lima.error.account.double=Il existe un compte avec ce m\u00EAme num\u00E9ro de compte lima.error.account.not.exist=Ce num\u00E9ro de compte n'existe pas