Author: mallon Date: 2012-08-07 14:57:47 +0200 (Tue, 07 Aug 2012) New Revision: 3569 Url: http://chorem.org/repositories/revision/lima/3569 Log: fixes #741 Desormais, lors de l ajout d une entree, celle-ci porte les memes descriptions et pieces comptables que la derniere ajoutee (Soit, la precedente), et les lignes ajoutees ne sont donc plus vides. La demande 741 est li?\195?\169e aussi a la #730 et a la #699. Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java trunk/lima-swing/src/main/resources/log4j.properties Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2012-08-06 16:03:49 UTC (rev 3568) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2012-08-07 12:57:47 UTC (rev 3569) @@ -258,11 +258,6 @@ try { - if (log.isDebugEnabled()) { - log.debug("entry : " + entry); - log.debug("entryOld : " + entryOld); - } - FinancialPeriodDAO financialPeriodDAO = getDaoHelper().getFinancialPeriodDAO(); FinancialPeriod financialPeriod = financialPeriodDAO.findByDate(entry.getFinancialTransaction().getTransactionDate()); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2012-08-06 16:03:49 UTC (rev 3568) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2012-08-07 12:57:47 UTC (rev 3569) @@ -451,6 +451,21 @@ return entries; } + @Override + public Entry getLastEntry(FinancialTransaction financialTransaction) throws LimaException { + Entry lastEntry; + + try { + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); + lastEntry = entryDAO.getLastEntry(financialTransaction); + + } catch (Exception ex) { + throw new LimaException("Can't get entries", ex); + } + + return lastEntry; + } + /** * Method used by update entry and remove entry for update amounts. */ Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2012-08-06 16:03:49 UTC (rev 3568) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2012-08-07 12:57:47 UTC (rev 3569) @@ -95,4 +95,10 @@ * @throws LimaException * */ List<Entry> getAllEntrieByDatesAndAccountAndLettering(LetteringFilter filter) throws LimaException; + + /** + * Retourne la dernière entrée d'une transaction + * @param financialTransaction transaction sur laquelle la derniere entree est selectionnee + * */ + Entry getLastEntry(FinancialTransaction financialTransaction) throws LimaException; } Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java 2012-08-06 16:03:49 UTC (rev 3568) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java 2012-08-07 12:57:47 UTC (rev 3569) @@ -25,6 +25,8 @@ package org.chorem.lima.entity; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.LetteringFilter; import org.nuiton.topia.TopiaException; @@ -34,6 +36,8 @@ public class EntryDAOImpl<E extends Entry> extends EntryDAOAbstract<Entry> { + private static final Log log = LogFactory.getLog(EntryDAOImpl.class); + /** * Requete generique qui recupere les entrees equilibrées portant entre * deux dates. @@ -203,6 +207,26 @@ } /** + * Retourne la dernière entrée d'une transaction + * @param financialTransaction transaction sur laquelle la derniere entree est selectionnee + * */ + public Entry getLastEntry(FinancialTransaction financialTransaction) throws TopiaException { + List<Entry> entries; + String query = "Select E from " + Entry.class.getName() + " E" + + " where E.financialTransaction.transactionDate = :financialTransactionDate " + + " and E.financialTransaction = :financialTransaction" + + " order by E.topiaCreateDate desc"; + + entries = context.findAll(query, "financialTransactionDate", financialTransaction.getTransactionDate(), "financialTransaction", financialTransaction); + + Entry lastEntry = entries.get(0); + if (log.isDebugEnabled()) { + log.debug("Last entry description : " + lastEntry.getDescription() ); + } + return lastEntry; + } + + /** * Retourne la somme des entrées des transaction entre * deux dates pour un journal donné. * Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java 2012-08-06 16:03:49 UTC (rev 3568) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java 2012-08-07 12:57:47 UTC (rev 3569) @@ -263,23 +263,6 @@ return result; } - /**Get the precedent entry of the entry passed in parameter*/ - public Entry getPrecedentEntry(Entry entry) { - for (Object transactionOrEntry : transactionAndEntries) { - if(transactionOrEntry instanceof Entry) { - if (transactionOrEntry.equals(entry)) { - Object objectAt = getObjectAt(transactionAndEntries.indexOf(transactionOrEntry) - 1); - if (objectAt instanceof Entry){ - return (Entry) objectAt; - } else { - return null; - } - } - } - } - return null; - } - public Object getObjectAt(int row) { if (row == -1) { return null; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2012-08-06 16:03:49 UTC (rev 3568) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2012-08-07 12:57:47 UTC (rev 3569) @@ -265,12 +265,11 @@ financialTransactionRow = tableModel.indexOf(((Entry) currentRow). getFinancialTransaction()); } + //create it entry.setFinancialTransaction(currentTransaction); Entry newEntry = financialTransactionService.createEntry(entry); currentTransaction.addEntry(entry); - //FIXME echatellier 20120413 what is fired here ? - //fireTableRowsUpdated(financialTransactionRow, financialTransactionRow + currentTransaction.getEntry().size() - 1); // on met a jour l'ui int newRow = financialTransactionRow + currentTransaction.getEntry().size() /*+ 1*/; @@ -350,27 +349,35 @@ // real selected row or selected transaction row ? int indexSelectedRow = table.getSelectedRow(); if (indexSelectedRow != -1) { - //int firstentryBookrow = tableModel.getFirstEntry(indexSelectedRow); - Entry precedentEntry = null; - if (tableModel.getObjectAt(indexSelectedRow) instanceof Entry) { - precedentEntry = tableModel.getPrecedentEntry((Entry)tableModel.getObjectAt(indexSelectedRow)); + Entry lastEntryOfTransaction; + + //First case, where line selected is an entry : take its transaction + //to select the last entry of the transaction + Object entryOrTransaction = tableModel.getObjectAt(indexSelectedRow); + if (entryOrTransaction instanceof Entry) { + lastEntryOfTransaction = financialTransactionService.getLastEntry(((Entry) entryOrTransaction).getFinancialTransaction()); + } else { //Second case, we have an instance of transaction, so select the last entry of it + lastEntryOfTransaction = financialTransactionService.getLastEntry((FinancialTransaction)entryOrTransaction); } - if (log.isInfoEnabled()) { - log.info("Selected row : " + indexSelectedRow); + if (log.isDebugEnabled()) { + log.debug("Selected row : " + indexSelectedRow); } String defaultVoucher = null; String defaultDescription = null; - if (precedentEntry != null) { - defaultVoucher = precedentEntry.getVoucher(); - defaultDescription = precedentEntry.getDescription(); + if (lastEntryOfTransaction != null) { + defaultVoucher = lastEntryOfTransaction.getVoucher(); + defaultDescription = lastEntryOfTransaction.getDescription(); } // creates the new entry Entry entry = new EntryImpl(); entry.setVoucher(defaultVoucher); + if (log.isDebugEnabled()) { + log.debug("Description of precedent entry : " + defaultDescription); + } entry.setDescription(defaultDescription); String defaultAccount; @@ -379,10 +386,10 @@ BigDecimal tvaTax = null; //Calculation of tva tax only if first entry is a sale - if (precedentEntry != null && precedentEntry.getAccount()!= null){ - defaultAccount = precedentEntry.getAccount().getAccountNumber(); + if (lastEntryOfTransaction != null && lastEntryOfTransaction.getAccount()!= null){ + defaultAccount = lastEntryOfTransaction.getAccount().getAccountNumber(); if (defaultAccount.equals("410") || defaultAccount.equals("418")){ - tvaTax = (precedentEntry.getAmount()).multiply(tvaPercentAdd); + tvaTax = (lastEntryOfTransaction.getAmount()).multiply(tvaPercentAdd); } } @@ -406,6 +413,7 @@ //get back the parent transaction of the entry currentTransaction = currentEntry.getFinancialTransaction(); } + // create it in service entry.setFinancialTransaction(currentTransaction); Entry newEntry = financialTransactionService.createEntry(entry); Modified: trunk/lima-swing/src/main/resources/log4j.properties =================================================================== --- trunk/lima-swing/src/main/resources/log4j.properties 2012-08-06 16:03:49 UTC (rev 3568) +++ trunk/lima-swing/src/main/resources/log4j.properties 2012-08-07 12:57:47 UTC (rev 3569) @@ -46,4 +46,7 @@ log4j.logger.org.chorem.lima.ui.celleditor.BigDecimalTableCellEditor=DEBUG log4j.logger.org.chorem.lima.business.accountingrules.DefaultAccountingRules=DEBUG log4j.logger.org.chorem.lima.business.ejb.FinancialTransactionServiceImpl=DEBUG -log4j.logger.org.chorem.lima.business.ui.celleditor.BigDecimalTableCellEditor=DEBUG \ No newline at end of file +log4j.logger.org.chorem.lima.business.ui.celleditor.BigDecimalTableCellEditor=DEBUG +log4j.logger.org.chorem.lima.business.ui.financialtransaction.FinancialTransactionTableModel=DEBUG +log4j.logger.org.chorem.lima.entity.EntryDAOImpl=DEBUG +log4j.logger.org.chorem.lima.ui.financialtransaction.FinancialTransactionViewHandler=DEBUG \ No newline at end of file