Author: jpepin Date: 2010-08-13 17:27:33 +0200 (Fri, 13 Aug 2010) New Revision: 3003 Url: http://chorem.org/repositories/revision/lima/3003 Log: Modification de la fonction d'entr?\195?\169es non ?\195?\169quilibr?\195?\169s en entr?\195?\169es incorrectes : v?\195?\169rification suppl?\195?\169mentaire sur le journal et les comptes. D?\195?\169bogue surlignage entr?\195?\169e non ?\195?\169quilibr?\195?\169. Ajout fonction copie-colle d'entr?\195?\169es. Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialTransactionService.java trunk/lima-swing/src/main/java/org/chorem/lima/service/ServiceMonitorableHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.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/FinancialTransactionView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.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 trunk/pom.xml Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-08-13 13:01:51 UTC (rev 3002) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-08-13 15:27:33 UTC (rev 3003) @@ -408,7 +408,6 @@ .addParam("account", account); Account master = accountDAO.findByQuery(query); - log.debug(master); accountingRules.updateAccountRules(master, account); subAccount.setMasterAccount(account.getMasterAccount()); subAccount.setSubAccounts(account.getSubAccounts()); @@ -563,9 +562,6 @@ doCatch(topiaContext, ex, log); } } - for (Account account : accounts) { - log.debug("accounts " + account.getAccountNumber()); - } return accounts; } 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 2010-08-13 13:01:51 UTC (rev 3002) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-08-13 15:27:33 UTC (rev 3003) @@ -23,7 +23,10 @@ import java.math.BigDecimal; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; + import javax.ejb.Stateless; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -46,6 +49,7 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; import org.nuiton.topia.framework.TopiaQuery; +import org.nuiton.topia.framework.TopiaQuery.Op; /** * Cette classe permet la création d'une transaction comptable dans l'application. @@ -182,21 +186,27 @@ * Get unbalanced financialtransaction from selected fiscalperiod */ @Override - public List<FinancialTransaction> getAllFinancialTransactionsUnbalanced(FiscalPeriod fiscalPeriod) throws LimaException { + public Set<FinancialTransaction> getAllInexactFinancialTransactions(FiscalPeriod fiscalPeriod) throws LimaException { TopiaContext topiaContext = null; - List<FinancialTransaction> result = null; + Set<FinancialTransaction> result = new HashSet<FinancialTransaction>(); try { topiaContext = beginTransaction(); FinancialTransactionDAO financialTransactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); - TopiaQuery query = financialTransactionDAO.createQuery("E"); query.addFrom(FiscalPeriod.class, "F") - .addWhere("E.amountCredit != E.amountDebit") + .addWhere("E.amountCredit != E.amountDebit OR E.entryBook = null") .addInElements("E.financialPeriod", "F.financialPeriod") .addEquals("F", fiscalPeriod); - result = financialTransactionDAO.findAllByQuery(query); + result.addAll(financialTransactionDAO.findAllByQuery(query)); + + TopiaQuery query2 = financialTransactionDAO.createQuery("T"); + query2.addFrom(Entry.class, "E") + .addWhere("E.account = null") + .addInElements("E", "T.entry"); + result.addAll(financialTransactionDAO.findAllByQuery(query2)); + /* Just for fun : IN HQL result = topiaContext.find( "FROM org.chorem.lima.entity.FinancialTransaction "+ @@ -391,6 +401,34 @@ EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); entryDAO.create(entry); + + //get new entry amounts + BigDecimal entryAmount = entry.getAmount(); + Boolean entryAmountIsDebit = entry.getDebit(); + BigDecimal entryDebit = new BigDecimal(0), entryCredit = new BigDecimal(0); + if (entryAmountIsDebit){ + entryDebit = entryAmount; + } + else { + entryCredit = entryAmount; + } + + //calculate financial transaction amounts + FinancialTransaction financialTransaction = + entry.getFinancialTransaction(); + + BigDecimal amountDebit = financialTransaction.getAmountDebit(); + amountDebit = amountDebit.add(entryDebit); + financialTransaction.setAmountDebit(amountDebit); + + BigDecimal amountCredit = financialTransaction.getAmountCredit(); + amountCredit = amountCredit.add(entryCredit); + financialTransaction.setAmountCredit(amountCredit); + + //update financial transaction + updateFinancialTransactionWithTransaction( + financialTransaction, topiaContext); + commitTransaction(topiaContext); } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialTransactionService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialTransactionService.java 2010-08-13 13:01:51 UTC (rev 3002) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialTransactionService.java 2010-08-13 15:27:33 UTC (rev 3003) @@ -20,6 +20,8 @@ package org.chorem.lima.business.ejbinterface; import java.util.List; +import java.util.Set; + import javax.ejb.Remote; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaException; @@ -57,7 +59,7 @@ List<FinancialTransaction> getAllFinancialTransactionsForEntryBookAndFinancialPeriod( EntryBook entryBook, FinancialPeriod period) throws LimaException; - List<FinancialTransaction> getAllFinancialTransactionsUnbalanced(FiscalPeriod fiscalPeriod) throws LimaException; + Set<FinancialTransaction> getAllInexactFinancialTransactions(FiscalPeriod fiscalPeriod) throws LimaException; List<FinancialTransaction> getAllFinancialTransactionsBalanced(FiscalPeriod fiscalPeriod) throws LimaException; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/service/ServiceMonitorableHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/service/ServiceMonitorableHandler.java 2010-08-13 13:01:51 UTC (rev 3002) +++ trunk/lima-swing/src/main/java/org/chorem/lima/service/ServiceMonitorableHandler.java 2010-08-13 15:27:33 UTC (rev 3003) @@ -25,8 +25,6 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.LimaBusinessException; -import org.chorem.lima.business.LimaException; import org.chorem.lima.business.ServiceListener; public class ServiceMonitorableHandler implements InvocationHandler { @@ -67,6 +65,7 @@ if (!method.getName().startsWith("get")){ for (ServiceListener serviceListener : listeners) { serviceListener.notifyMethod(service.toString(), method.getName()); + log.debug("proxy : " + service.toString() + " " + method.getName()); } } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java 2010-08-13 13:01:51 UTC (rev 3002) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java 2010-08-13 15:27:33 UTC (rev 3003) @@ -22,7 +22,11 @@ import java.awt.Component; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; +import java.math.BigDecimal; import java.util.Date; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.ui.celleditor.AccountTableCellEditor; @@ -45,6 +49,10 @@ /** serialVersionUID. */ private static final long serialVersionUID = 3133690382049594727L; + + /** log. */ + private static final Log log = LogFactory + .getLog(FinancialTransactionTable.class); protected FinancialTransactionViewHandler handler; @@ -110,9 +118,9 @@ ComponentAdapter adapter) { boolean isHighlighted = false; Object value = adapter.getValueAt(adapter.row, 8); - if (value instanceof Double) { - Double currentBalance = (Double) value; - if (currentBalance != 0) { + if (value instanceof BigDecimal) { + BigDecimal currentBalance = (BigDecimal) value; + if (currentBalance.doubleValue() != 0) { isHighlighted = true; } } 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 2010-08-13 13:01:51 UTC (rev 3002) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java 2010-08-13 15:27:33 UTC (rev 3003) @@ -413,12 +413,42 @@ fireTableDataChanged(); } + public void addEntry(Object value, Entry entry, int row) throws LimaException { + FinancialTransaction currentTransaction = null; + int financialTransactionRow = 0; + Object currentRow = cacheDataList.get(row); + //check if current row is a transaction or an entry + if (currentRow instanceof FinancialTransaction) { + currentTransaction = (FinancialTransaction)currentRow; + //update the financial transaction in entire + financialTransactionRow = + getDataList().indexOf(((FinancialTransaction) currentRow)); + } + else if (currentRow instanceof Entry) { + Entry currentEntry = (Entry)currentRow; + //get back the parent transaction of the entry + currentTransaction = currentEntry.getFinancialTransaction(); + //update the financial transaction in entire + financialTransactionRow = + getDataList().indexOf(((Entry) currentRow). + getFinancialTransaction()); + } + //create it + entry.setFinancialTransaction(currentTransaction); + financialTransactionService.createEntry(entry); + fireTableRowsUpdated(financialTransactionRow, getRowCount()-1); + + //on recharge la liste + cacheDataList = getDataList(); + fireTableDataChanged(); + } + /** * to modifiy financialtransaction or entry */ @Override public void setValueAt(Object value, int row, int column) { - int financialTransactionRow=0; + int financialTransactionRow = 0; if (cacheDataList != null) { Object currentRow = cacheDataList.get(row); if (currentRow instanceof FinancialTransaction) { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2010-08-13 13:01:51 UTC (rev 3002) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2010-08-13 15:27:33 UTC (rev 3003) @@ -67,11 +67,19 @@ /> </cell> <cell> + <JButton text="lima.common.copy" + onActionPerformed="getHandler().copyRow()" enabled="{isSelectedRow()}"/> + </cell> + <cell> + <JButton text="lima.common.paste" + onActionPerformed="getHandler().pasteRow()" enabled="{isSelectedRow()}"/> + </cell> + <cell> <JButton text="lima.add.transaction" onActionPerformed="getHandler().addFinancialTransaction()"/> </cell> <cell> - <JButton text="lima.add.entry" onActionPerformed="getHandler().addEmptyEntry()"/> + <JButton text="lima.add.entry" onActionPerformed="getHandler().addEmptyEntry()" enabled="{isSelectedRow()}"/> </cell> <cell> <JButton text="lima.common.remove" @@ -80,7 +88,7 @@ </cell> </row> <row> - <cell fill="both" weightx="1" weighty="1" rows="3" columns="8"> + <cell fill="both" weightx="1" weighty="1" rows="3" columns="9"> <JScrollPane> <org.chorem.lima.ui.financialtransaction.FinancialTransactionTableModel id="financialTransactionTableModel"/> 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 2010-08-13 13:01:51 UTC (rev 3002) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2010-08-13 15:27:33 UTC (rev 3003) @@ -27,6 +27,7 @@ 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.FinancialTransaction; import org.chorem.lima.ui.combobox.FinancialPeriodComboBoxModel; import org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel; @@ -57,11 +58,51 @@ protected FiscalPeriodComboBoxModel fiscalPeriodComboBoxModel; protected FinancialPeriodComboBoxModel financialPeriodComboBoxModel; + + protected Object clipBoard; protected FinancialTransactionViewHandler(FinancialTransactionView view) { this.view = view; } + //copy entry + public void copyRow(){ + int indexSelectedRow = table.getSelectedRow(); + + if (indexSelectedRow != -1) { + clipBoard = tableModel.getElementAt(indexSelectedRow); + } + } + + //paste entry + public void pasteRow(){ + int indexSelectedRow = table.getSelectedRow(); + + if (indexSelectedRow != -1) { + Object selectedValue = tableModel.getElementAt(indexSelectedRow); + if (clipBoard instanceof Entry) { + try { + tableModel.addEntry(selectedValue, (Entry) clipBoard, indexSelectedRow); + //select the new line + ListSelectionModel selectionModel = + table.getSelectionModel(); + selectionModel.setSelectionInterval( + indexSelectedRow+1, indexSelectedRow+1); + //focus on second column + table.changeSelection(indexSelectedRow+1, 1, false, false); + table.requestFocusInWindow(); + } catch (LimaException eee){ + if (log.isErrorEnabled()) { + log.error("Can't past entry", eee); + } + DialogHelper.showMessageDialog(eee.getMessage()); + } + } + + } + + } + //add a new transaction public void addFinancialTransaction() { table = view.getFinancialTransactionTable(); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTable.java 2010-08-13 13:01:51 UTC (rev 3002) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTable.java 2010-08-13 15:27:33 UTC (rev 3003) @@ -22,6 +22,7 @@ import java.awt.Component; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; +import java.math.BigDecimal; import java.util.Date; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.EntryBook; @@ -113,9 +114,9 @@ ComponentAdapter adapter) { boolean isHighlighted = false; Object value = adapter.getValueAt(adapter.row, 8); - if (value instanceof Double) { - Double currentBalance = (Double) value; - if (currentBalance != 0) { + if (value instanceof BigDecimal) { + BigDecimal currentBalance = (BigDecimal) value; + if (currentBalance.doubleValue() != 0) { isHighlighted = true; } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTableModel.java 2010-08-13 13:01:51 UTC (rev 3002) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTableModel.java 2010-08-13 15:27:33 UTC (rev 3003) @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.Set; + import javax.swing.table.AbstractTableModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -98,8 +100,8 @@ List<Object> results = new ArrayList<Object>(); if(selectedFiscalPeriod != null){ try { - List<FinancialTransaction> financialtransactions = - financialTransactionService.getAllFinancialTransactionsUnbalanced(selectedFiscalPeriod); + Set<FinancialTransaction> financialtransactions = + financialTransactionService.getAllInexactFinancialTransactions(selectedFiscalPeriod); for (FinancialTransaction financialtransaction : financialtransactions) { results.add(financialtransaction); List<Entry> entries = (List<Entry>) financialtransaction.getEntry(); @@ -338,6 +340,7 @@ FinancialTransaction currentTransaction = null; Object currentRow = cacheDataList.get(row); Entry entry = new EntryImpl(); + entry.setAmount(new BigDecimal(0)); //check if current row is a transaction or an entry if (currentRow instanceof FinancialTransaction) { currentTransaction = (FinancialTransaction)currentRow; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java 2010-08-13 13:01:51 UTC (rev 3002) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java 2010-08-13 15:27:33 UTC (rev 3003) @@ -21,6 +21,8 @@ import static org.nuiton.i18n.I18n._; import java.awt.Color; import java.util.List; +import java.util.Set; + import javax.swing.JEditorPane; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; @@ -99,9 +101,9 @@ List<FiscalPeriod> unblockedFiscalPeriods = fiscalPeriodService.getAllUnblockedFiscalPeriods(); if (unblockedFiscalPeriods.size() != 0){ - List<FinancialTransaction> financialTransactionsUnbal = + Set<FinancialTransaction> financialTransactionsUnbal = financialTransactionService. - getAllFinancialTransactionsUnbalanced(unblockedFiscalPeriods.get(0)); + getAllInexactFinancialTransactions(unblockedFiscalPeriods.get(0)); if (financialTransactionsUnbal.size()>0){ setBackground(redBackground); String transactionsString = financialTransactionsUnbal.size() @@ -146,7 +148,7 @@ @Override public void notifyMethod(String serviceName, String methodeName) { - if (methodeName.contains("FiscalPeriod") || methodeName.contains("FinancialTransaction") || methodeName.contains("importEntries") || methodeName.contains("importAll")){ + if (methodeName.contains("FiscalPeriod") || methodeName.contains("FinancialTransaction") || methodeName.contains("Entry") || methodeName.contains("importEntries") || methodeName.contains("importAll")){ refresh(); } } 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-08-13 13:01:51 UTC (rev 3002) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-08-13 15:27:33 UTC (rev 3003) @@ -46,11 +46,13 @@ lima.common.addSubLedger= lima.common.cancel= lima.common.close= +lima.common.copy= lima.common.fin= lima.common.import= lima.common.importexport=Import/Export lima.common.next= lima.common.ok= +lima.common.paste= lima.common.print= lima.common.quit= lima.common.remove= 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-08-13 13:01:51 UTC (rev 3002) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-08-13 15:27:33 UTC (rev 3003) @@ -43,10 +43,12 @@ lima.common.addSubLedger=Ajouter Compte Tiers lima.common.cancel=Annuler lima.common.close=Fermer +lima.common.copy=Copier lima.common.fin=Termin\u00E9 lima.common.importexport=Importer/Exporter lima.common.next=Suivant lima.common.ok=OK +lima.common.paste=Coller lima.common.print= lima.common.quit=Quitter lima.common.remove=Supprimer @@ -72,7 +74,7 @@ lima.entries=Traitement lima.entries.addtransaction=Saisir des \u00E9critures lima.entries.lettering=Ajouter une lettre -lima.entries.searchunbalancedtransaction=Entr\u00E9es non \u00E9quilibr\u00E9es +lima.entries.searchunbalancedtransaction=Entr\u00E9es incorrect lima.entrybook=Journal lima.entrybook.add=Ajouter un journal lima.entrybook.code= @@ -241,7 +243,7 @@ limahome.transaction.balanced=transactions, toutes sont \u00E9quilibr\u00E9es limahome.transaction.create=Ajouter des \u00E9critures limahome.transaction.modifiy.balanced=Modifier les \u00E9critures -limahome.transaction.modifiy.unbalanced=Modifier les \u00E9critures non \u00E9quilibr\u00E9es +limahome.transaction.modifiy.unbalanced=Modifier les \u00E9critures incorrect limahome.transaction.nothing=Aucune \u00E9criture limahome.transaction.unbalanced=\u00E9critures ne sont pas \u00E9quilibr\u00E9es \! update= Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-08-13 13:01:51 UTC (rev 3002) +++ trunk/pom.xml 2010-08-13 15:27:33 UTC (rev 3003) @@ -275,9 +275,9 @@ <projectId>lima</projectId> <!-- customized libs version --> - <nuiton-utils.version>1.3.2-SNAPSHOT</nuiton-utils.version> + <nuiton-utils.version>1.4</nuiton-utils.version> <eugene.version>2.1.1</eugene.version> - <topia.version>2.4.1-SNAPSHOT</topia.version> + <topia.version>2.4.2</topia.version> <jaxx.version>2.1</jaxx.version> <i18n.version>1.2.2</i18n.version>