r2916 - in trunk: lima-business/src/main/java/org/chorem/lima/business lima-business/src/main/java/org/chorem/lima/business/ejb lima-callao/src/main/xmi lima-swing/src/main/java/org/chorem/lima/ui lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced lima-swing/src/main/resources/i18n
Author: jpepin Date: 2010-05-27 19:22:42 +0200 (Thu, 27 May 2010) New Revision: 2916 Url: http://chorem.org/repositories/revision/lima/2916 Log: Ajout dans l'ui d'une vue des entr?\195?\169es non ?\195?\169quilibr?\195?\169es Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedHelper.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/financialtransactionunbalanced/FinancialTransactionUnbalancedView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedViewHandler.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionService.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/FinancialTransactionServiceImpl.java trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.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 Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionService.java 2010-05-27 15:16:22 UTC (rev 2915) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionService.java 2010-05-27 17:22:42 UTC (rev 2916) @@ -25,6 +25,7 @@ import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.entity.FiscalPeriod; /** * Transaction service. @@ -68,6 +69,8 @@ List<FinancialTransaction> getAllFinancialTransactionsForEntryBookAndFinancialPeriod( EntryBook entryBook, FinancialPeriod period) throws LimaException; + List<FinancialTransaction> getAllFinancialTransactionsUnbalanced(FiscalPeriod fiscalPeriod) throws LimaException; + void createFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException; void updateFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException; 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-05-27 15:16:22 UTC (rev 2915) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-05-27 17:22:42 UTC (rev 2916) @@ -330,6 +330,10 @@ return result; } + /** + * Just for debug + *TODO REMOVE + */ @Override public List<ClosedPeriodicEntryBook> getAllClosedPeriodicEntryBooks() throws LimaException { List<ClosedPeriodicEntryBook> result = null; 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-05-27 15:16:22 UTC (rev 2915) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-05-27 17:22:42 UTC (rev 2916) @@ -40,6 +40,7 @@ import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryDAO; import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FinancialTransactionDAO; @@ -213,6 +214,7 @@ if (financialPeriod != null) { query.add("financialPeriod", financialPeriod); } + financialTransactions = transactionDAO.findAllByQuery(query); //IMPORTANT : LOADING ENTRIES AND IS COLUMN FOR NO LAZY EXCEPTION @@ -235,9 +237,31 @@ return financialTransactions; } - @Override + public List<FinancialTransaction> getAllFinancialTransactionsUnbalanced(FiscalPeriod fiscalPeriod) throws LimaException { + TopiaContext topiaContext = null; + List<FinancialTransaction> result = null; + try { + topiaContext = beginTransaction(); + + FinancialTransactionDAO financialTransactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); + TopiaQuery query = financialTransactionDAO.createQuery("E"); + query.add(FinancialTransaction.ENTRY); + result = query.execute(); + log.debug(result); + + } + catch (TopiaException ex) { + doCatch(topiaContext, ex, log); + } + finally { + doFinally(topiaContext, log); + } + return result; + } + + @Override public void updateFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { TopiaContext topiaTransaction = null; @@ -384,6 +408,7 @@ } } + protected TopiaContext beginTransaction() throws TopiaException { // basic check done, make check in database // TODO move it into JTA Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2010-05-27 15:16:22 UTC (rev 2915) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2010-05-27 17:22:42 UTC (rev 2916) @@ -127,7 +127,7 @@ <JMenu text="lima.entries"> <JMenuItem text="lima.entries.addtransaction" onActionPerformed='getHandler().showTransactionView(this)' actionIcon='transaction'/> - <JMenuItem text="lima.entries.searchtransaction" onActionPerformed='getHandler().showSearchView(this)' + <JMenuItem text="lima.entries.searchunbalancedtransaction" onActionPerformed='getHandler().showTransactionUnbalancedView(this)' actionIcon='search'/> <JMenuItem text="lima.entries.lettering" onActionPerformed='getHandler().showLetteringView(this)' actionIcon='lettering'/> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2010-05-27 15:16:22 UTC (rev 2915) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2010-05-27 17:22:42 UTC (rev 2916) @@ -43,6 +43,8 @@ import org.chorem.lima.ui.fiscalperiod.FiscalPeriodView; import org.chorem.lima.ui.financialtransaction.FinancialTransactionView; import org.chorem.lima.ui.financialtransaction.LetteringView; +import org.chorem.lima.ui.financialtransactionunbalanced.FinancialTransactionUnbalancedView; +import org.chorem.lima.ui.financialtransactionunbalanced.FinancialTransactionUnbalancedViewHandler; import org.chorem.lima.util.ErrorHelper; /** @@ -347,6 +349,12 @@ mainView.showTab(_("lima.tab.transaction"), transactionView); } + public void showTransactionUnbalancedView(JAXXContext rootContext) { + MainView mainView = getUI(rootContext); + FinancialTransactionUnbalancedView searchResultView = new FinancialTransactionUnbalancedView(mainView); + mainView.showTab(_("lima.entries.searchunbalancedtransaction"), searchResultView); + } + public void showBalanceView(JAXXContext rootContext) { MainView mainView = getUI(rootContext); BalanceView balanceView = new BalanceView(mainView); @@ -381,12 +389,6 @@ mainView.showTab(_("lima.tab.lettering"), letteringView); } - public void showSearchResultView(JAXXContext rootContext) { - /*MainView mainView = getUI(rootContext); - SearchResultView searchResultView = new SearchResultView(mainView); - mainView.showTab(_("lima.tab.search.result"), searchResultView);*/ - } - public void showSearchView(JAXXContext rootContext) { /*if (!getSearchView().isEnabled()) { getSearchView().setEnabled(true); Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedHelper.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedHelper.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedHelper.java 2010-05-27 17:22:42 UTC (rev 2916) @@ -0,0 +1,84 @@ +/* *##% 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.financialtransactionunbalanced; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.ui.accountsreports.AccountsReportsTableModel; + +/** + * TODO add comment here. + * + * @author chatellier + * @version $Revision: 2901 $ + * + * Last update : $Date: 2010-05-19 12:52:43 +0200 (mer. 19 mai 2010) $ + * By : $Author: jpepin $ + */ +public class FinancialTransactionUnbalancedHelper { + /** log. */ + private static final Log log = LogFactory.getLog(AccountsReportsTableModel.class); + + /** + * 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; + } +} Added: 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 (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTable.java 2010-05-27 17:22:42 UTC (rev 2916) @@ -0,0 +1,199 @@ +/* *##% 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.financialtransactionunbalanced; + +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.Account; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.ui.financialtransaction.FinancialTransactionHelper; +import org.chorem.lima.ui.financialtransactionunbalanced.FinancialTransactionUnbalancedViewHandler; +import org.chorem.lima.ui.financialtransaction.table.AccountTableCellEditor; +import org.chorem.lima.ui.financialtransaction.table.DateTableCellEditor; +import org.chorem.lima.ui.financialtransaction.table.EntryBookTableCellEditor; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.decorator.ColorHighlighter; +import org.jdesktop.swingx.decorator.ComponentAdapter; +import org.jdesktop.swingx.decorator.HighlightPredicate; +import org.jdesktop.swingx.decorator.Highlighter; + + +/** + * Table des transaction qui ajoute des comportement (keys). + * + * @author ore + * @author Rémi Chapelet + */ +public class FinancialTransactionUnbalancedTable extends JXTable implements KeyListener { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3133690382049594727L; + + /** log. */ + private static final Log log = LogFactory.getLog(FinancialTransactionUnbalancedTable.class); + + protected FinancialTransactionUnbalancedViewHandler handler; + + private Highlighter colorTransaction; + + private ColorHighlighter colorBalance; + + /** + */ + public FinancialTransactionUnbalancedTable(FinancialTransactionUnbalancedViewHandler handler) { + + this.handler = handler; + + addKeyListener(this); + + //Get new date editor + setDefaultEditor(Date.class, new DateTableCellEditor()); + //Get new entry book editor + setDefaultEditor(EntryBook.class, new EntryBookTableCellEditor()); + //Get new account editor + setDefaultEditor(Account.class, new AccountTableCellEditor()); + + //highlight financial financial transactions + addColorTransaction(); + // highlight unbalanced financial transactions + addColorNonBalancedTransaction(); + } + + /** + * Cette méthode permet de colorer toutes les transactions dans le tableau + * afin de bien distinguer les transactions et entrées comptables. + * On récupère la première cellule, on vérifie que c'est une date + */ + protected void addColorTransaction() { + if (colorTransaction != null) { + removeHighlighter(colorTransaction); + } + HighlightPredicate predicate = new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, + ComponentAdapter adapter) { + return adapter.getValueAt(adapter.row, 0) instanceof Date; + } + }; + colorTransaction = + new ColorHighlighter(predicate, new Color(222,222,222), null); + addHighlighter(colorTransaction); + } + + + + /** + * Permet de surligner une transaction dans le tableau lorsque + * cette dernière n'est pas équilibrée. + * On récupère la dernière cellule de la ligne + * et on vérifie si la valeur est différente de 0 + */ + 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 = adapter.getValueAt(adapter.row, 8); + if (value instanceof Double) { + Double currentBalance = (Double) value; + if (currentBalance != 0) { + isHighlighted = true; + } + } + return isHighlighted; + } + }; + colorTransaction = + new ColorHighlighter(predicate, new Color(255, 198, 209), null); + addHighlighter(colorTransaction); + } + + /** + * for each action combination key are think + * for extend keyboard and laptop keyboard + */ + @Override + public void keyPressed(KeyEvent e) { + + //TODO combinaison de touches dans la config + + // delete selected row with the key : delete or ctrl clear + // ou de l'entree + if ((e.getKeyCode() == KeyEvent.VK_DELETE ) + || (e.getKeyCode() == KeyEvent.VK_CLEAR + && e.getModifiers() == KeyEvent.CTRL_MASK)){ + handler.deleteSelectedRow(); + } + + // add entry with the key combination : insert or ctrl + enter + if ((e.getKeyCode() == KeyEvent.VK_INSERT ) + || (e.getKeyCode() == KeyEvent.VK_ENTER + && e.getModifiers() == KeyEvent.CTRL_MASK)) { + handler.addEmptyEntry(); + } + + /** + * Touche tab + * Ajoute une entrée comptable 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 = this.getSelectedColumn(); + int y = this.getSelectedRow(); + int max_x = this.getColumnCount() - 1; + int max_y = this.getRowCount() - 1; + if (x == max_x && y == max_y) { + handler.addEmptyEntry(); + // positionne la sélection sur la nouvelle ligne créée + this.setColumnSelectionInterval(0, 0); + this.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) { + + } +} Added: 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 (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTableModel.java 2010-05-27 17:22:42 UTC (rev 2916) @@ -0,0 +1,532 @@ +/* *##% 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.financialtransactionunbalanced; + +import static org.nuiton.i18n.I18n._; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +import javax.swing.table.AbstractTableModel; + +import org.apache.commons.lang.time.DateUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.EntryBookService; +import org.chorem.lima.business.FinancialPeriodService; +import org.chorem.lima.business.LimaBusinessException; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.FinancialTransactionService; +import org.chorem.lima.business.utils.EntryComparator; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.EntryImpl; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialPeriodImpl; +import org.chorem.lima.entity.FinancialTransactionImpl; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.ui.financialtransaction.FinancialTransactionHelper; +import org.chorem.lima.util.ErrorHelper; + +/** + * Basic transaction table model. + * + * Le modele est filtré sur {@link #selectedEntryBook} et + * {@link #selectedFinancialPeriod} (montée en charge !). + * + * @author ore + * @author chatellier + * @version $Revision: 2897 $ + * + * Last update : $Date: 2010-05-14 13:22:26 +0200 (ven. 14 mai 2010) $ + * By : $Author: jpepin $ + */ +public class FinancialTransactionUnbalancedTableModel extends AbstractTableModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3914954536809622358L; + + /** log. */ + private static final Log log = LogFactory + .getLog(FinancialTransactionUnbalancedTableModel.class); + + /** Transaction service. */ + protected final FinancialTransactionService financialTransactionService; + + /** EntryBook service. */ + protected final EntryBookService entryBookService; + + /** FinancialPeriod service. */ + protected final FinancialPeriodService financialPeriodService; + + /** selected financial period */ + protected FiscalPeriod selectedFiscalPeriod; + + /** data cache */ + protected List<Object> cacheDataList; + + /** collection + + + /** + * Model constructor. + * + * Just init service proxies. + */ + public FinancialTransactionUnbalancedTableModel() { + /* Services */ + financialTransactionService = LimaServiceFactory.getInstance() + .getTransactionService(); + entryBookService = LimaServiceFactory.getInstance(). + getEntryBookService(); + financialPeriodService = LimaServiceFactory.getInstance(). + getFinancialPeriodService(); + } + + /** + * Le model est une combinaison de Transaction/Entries. + * + * + * @return + */ + protected List<Object> getDataList() { + + List<Object> results = new ArrayList<Object>(); + try { + List<FinancialTransaction> financialtransactions = + financialTransactionService.getAllFinancialTransactionsUnbalanced(selectedFiscalPeriod); + for (FinancialTransaction financialtransaction : financialtransactions) { + results.add(financialtransaction); + List<Entry> entries = (List<Entry>) financialtransaction.getEntry(); + Collections.sort(entries, new EntryComparator()); + results.addAll(entries); + } + } + 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 9; + } + + @Override + public Class<?> getColumnClass(int column) { + + Class<?> result = null; + + switch (column) { + case 0: + result = Date.class; + break; + case 1: + result = EntryBook.class; + break; + case 2: + result = String.class; + break; + case 3: + result = Account.class; + break; + case 4: + result = String.class; + break; + case 5: + result = String.class; + break; + case 6: + result = Double.class; + break; + case 7: + result = Double.class; + break; + case 8: + result = Double.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.entrybook"); + break; + case 2: + result = _("lima.transaction.column.voucher"); + break; + case 3: + result = _("lima.transaction.column.account"); + break; + case 4: + result = _("lima.transaction.column.description"); + break; + case 5: + result = _("lima.transaction.column.position"); + break; + case 6: + result = _("lima.transaction.column.debit"); + break; + case 7: + result = _("lima.transaction.column.credit"); + break; + case 8: + result = _("lima.transaction.column.balance"); + break; + } + + return result; + } + + @Override + public int getRowCount() { + int result = 0; + + // just prevent too much result + if (selectedFiscalPeriod != null) { + //cacheDataList = getDataList(); + result = cacheDataList.size(); + } + else { + if (log.isDebugEnabled()) { + log.debug("No fiscalPeriod selected skip table model update"); + } + } + + return result; + } + + @Override + public Object getValueAt(int row, int column) { + Object result = null; + + // just prevent too much result + if (selectedFiscalPeriod != null) { + result = cacheDataList.get(row); + + if (result instanceof FinancialTransaction) { + FinancialTransaction currentRow = (FinancialTransaction)result; + + switch (column) { + case 0: + result = currentRow.getTransactionDate(); + break; + case 1: + result = null; // voucher + break; + case 2: + result = null; //entrybook + break; + case 3: + result = null; // account + break; + case 4: + result = null; // description + break; + case 5 : + result = null; // position + break; + case 6: + result = FinancialTransactionHelper.getDebit(currentRow); + break; + case 7: + result = FinancialTransactionHelper.getCredit(currentRow); + break; + case 8: + result = FinancialTransactionHelper.getDebit(currentRow) + - FinancialTransactionHelper.getCredit(currentRow); + break; + } + } + else if (result instanceof Entry) { + Entry currentEntry = (Entry)result; + switch (column) { + case 0: + result = null; // date + break; + case 1 : // entry book + if (currentEntry.getEntryBook() != null){ + result = currentEntry.getEntryBook().getCode(); + } + else { + result = null; + } + break; + case 2: + result = currentEntry.getVoucher(); + break; + case 3: // account + if (currentEntry.getAccount() != null){ + result = currentEntry.getAccount().getAccountNumber(); + } + else { + result = null; + } + break; + case 4: + result = currentEntry.getDescription(); + break; + case 5 : + result = currentEntry.getPosition(); + break; + case 6: + result = currentEntry.getDebit() ? currentEntry.getAmount() : 0; + break; + case 7: + result = currentEntry.getDebit() ? 0 : currentEntry.getAmount(); + break; + case 8: + result = null; // balance + break; + } + + } + } + else { + if (log.isDebugEnabled()) { + log.debug("No fiscalPeriod selected skip table model update"); + } + } + + return result; + } + + public void setFiscalPeriod(FiscalPeriod fiscalPeriod){ + + selectedFiscalPeriod = fiscalPeriod; + cacheDataList = getDataList(); + fireTableDataChanged(); + } + + /** + * To set cells editable or not + * different condition for entry or financial transaction + */ + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + boolean editableCell=false; + Object currentRow = cacheDataList.get(rowIndex); + // cells editable for the entry row, all cells exclude the date + if ((currentRow instanceof Entry) && !(columnIndex==0)) { + editableCell=true; + } + // cells editable for the financialtransaction row, no cells exclude the date + if ((currentRow instanceof FinancialTransaction) && (columnIndex==0)){ + editableCell=true; + } + return editableCell; + } + + + /** + * @throws LimaException + */ + public void addEmptyEntry(Object value, int row) throws LimaException { + FinancialTransaction currentTransaction = null; + Object currentRow = cacheDataList.get(row); + Entry entry = new EntryImpl(); + //check if current row is a transaction or an entry + if (currentRow instanceof FinancialTransaction) { + currentTransaction = (FinancialTransaction)currentRow; + } + else if (currentRow instanceof Entry) { + Entry currentEntry = (Entry)currentRow; + //get back the parent transaction of the entry + currentTransaction = currentEntry.getFinancialTransaction(); + } + //create it + entry.setFinancialTransaction(currentTransaction); + financialTransactionService.createEntry(entry); + //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; + // just prevent too much result + if (selectedFiscalPeriod != null) { + Object currentRow = cacheDataList.get(row); + if (currentRow instanceof FinancialTransaction) { + FinancialTransaction currentFinancialTransaction = + (FinancialTransaction)currentRow; + switch (column) { + case 0: + // Truncate the date - format 01-MM-YYYY + Date dateCurrentFinancialTransaction = ((Date)value); + dateCurrentFinancialTransaction = + DateUtils.truncate( + dateCurrentFinancialTransaction, Calendar.MONTH); + + // Return the begin date of the current financial period + Date dateCurrentFinancialPeriod = + selectedFiscalPeriod.getBeginDate(); + + // Compare to the begindate of the current financial period + if (!dateCurrentFinancialPeriod.equals(dateCurrentFinancialTransaction)){ + //methode get financialperiod dans le service + FinancialPeriod newFinancialPeriod = + new FinancialPeriodImpl(); + try { + newFinancialPeriod = + financialPeriodService.getFinancialPeriodWithDate( + dateCurrentFinancialTransaction); + } catch (LimaException e) { + if (log.isDebugEnabled()){ + log.debug("Can't get new financialPeriodService"); + } + } + //if the changed financial period is unlocked + if (newFinancialPeriod != null){ + if (newFinancialPeriod.getLocked() == false){ + //update + currentFinancialTransaction. + setTransactionDate((Date)value); + currentFinancialTransaction. + setFinancialPeriod(newFinancialPeriod); + } + } + else { + if (log.isDebugEnabled()){ + log.debug("Can't update on the new date"); + } + } + } + + break; + } + // notify service for modification + try { + financialTransactionService. + updateFinancialTransaction(currentFinancialTransaction); + } catch (LimaException e) { + if (log.isDebugEnabled()){ + log.debug("Can't update financial transaction", e); + } + } + //update the financial transaction in entire + financialTransactionRow = + getDataList().indexOf(((FinancialTransaction) currentRow)); + } + else if (currentRow instanceof Entry) { + Entry currentEntry = (Entry)currentRow; + switch (column) { + case 1 : + currentEntry.setEntryBook((EntryBook)value); + break; + case 2 : + currentEntry.setVoucher((String)value); + break; + case 3: + currentEntry.setAccount((Account)value); + break; + case 4: + currentEntry.setDescription((String)value); + break; + case 5 : + currentEntry.setPosition((String)value); + break; + case 6: + currentEntry.setAmount((Double)value); + currentEntry.setDebit(true); + break; + case 7: + currentEntry.setAmount((Double)value); + currentEntry.setDebit(false); + break; + } + try { + financialTransactionService.updateEntry(currentEntry); + } catch (LimaException e) { + if (log.isDebugEnabled()){ + log.debug("Can't update entry", e); + } + } + //update the financial transaction in entire + financialTransactionRow = + getDataList().indexOf(((Entry) currentRow). + getFinancialTransaction()); + } + //on recharge la liste + cacheDataList = getDataList(); + fireTableRowsUpdated(financialTransactionRow, getRowCount()-1); + } + else { + if (log.isDebugEnabled()) { + log.debug("No fiscalPeriod selected skip table model update"); + } + } + } + + public Object getElementAt(int row){ + + Object currentRow = cacheDataList.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 { + Object currentRow = cacheDataList.get(row); + if (currentRow instanceof FinancialTransaction) { + FinancialTransaction currentTransaction = + (FinancialTransaction)currentRow; + financialTransactionService.removeFinancialTransaction(currentTransaction); + } + else if (currentRow instanceof Entry) { + Entry currentEntry = (Entry)currentRow; + financialTransactionService.removeEntry(currentEntry); + } + //on recharge la liste + cacheDataList = getDataList(); + fireTableRowsDeleted(row, getRowCount()); + } + +} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedView.jaxx (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedView.jaxx 2010-05-27 17:22:42 UTC (rev 2916) @@ -0,0 +1,74 @@ +<!-- ##% 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. + ##% --> + +<Table> + <FinancialTransactionUnbalancedViewHandler id="handler" javaBean="new FinancialTransactionUnbalancedViewHandler(this)" /> + <Boolean id="selectedRow" javaBean="false" /> + <org.chorem.lima.ui.combobox.FinancialPeriodComboBoxModel id="modelFinancialPeriod"/> + <script> + <![CDATA[ + + import org.chorem.lima.entity.FiscalPeriod; + import org.chorem.lima.entity.FinancialPeriod; + + ]]> + </script> + + <!-- <JPopupMenu id="MenuRightPanel"> + <JMenuItem text="lima.add.transaction" onActionPerformed='addEmptyTransaction()'/> + <JMenuItem text="lima.print"/> + </JPopupMenu> + <JPopupMenu id="MenuRightTransaction"> + <JMenuItem text="lima.add" onActionPerformed='addEmptyTransaction()'/> + <JMenuItem text="lima.print"/> + </JPopupMenu> --> + + <row fill="horizontal" weightx="1" weighty="0" anchor="center"> + <cell> + <JLabel id="fiscalPeriodLabel" text="lima.charts.fiscalyear"/> + </cell> + <cell> + <JComboBox id="fiscalPeriodComboBox" + model="{new org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel()}" + renderer="{new org.chorem.lima.ui.combobox.FiscalPeriodComboBoxRenderer()}" + onItemStateChanged="getFinancialTransactionUnbalancedTableModel().setFiscalPeriod( (FiscalPeriod) event.getItem())" + editable="false"/> + </cell> + <cell> + <JButton text="lima.add.entry" onActionPerformed="getHandler().addEmptyEntry()"/> + </cell> + <cell> + <JButton text="lima.common.remove" + onActionPerformed="getHandler().deleteSelectedRow()" + enabled="{isSelectedRow()}"/> + </cell> + </row> + <row> + <cell fill="both" weightx="1" weighty="1" rows="3" columns="7"> + <JScrollPane> + <org.chorem.lima.ui.financialtransactionunbalanced.FinancialTransactionUnbalancedTableModel + id="financialTransactionUnbalancedTableModel" /> + <org.chorem.lima.ui.financialtransactionunbalanced.FinancialTransactionUnbalancedTable + id="financialTransactionUnbalancedTable" sortable="false" rowHeight="22" + constructorParams="getHandler()" model="{getFinancialTransactionUnbalancedTableModel()}" + selectionMode="{ListSelectionModel.SINGLE_SELECTION}" /> + <javax.swing.ListSelectionModel javaBean="getFinancialTransactionUnbalancedTable().getSelectionModel()" + onValueChanged="setSelectedRow(financialTransactionUnbalancedTable.getSelectedRow() != -1)"/> + </JScrollPane> + </cell> + </row> +</Table> \ No newline at end of file Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedViewHandler.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedViewHandler.java 2010-05-27 17:22:42 UTC (rev 2916) @@ -0,0 +1,130 @@ +/* *##% 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.financialtransactionunbalanced; + +import static org.nuiton.i18n.I18n._; + + +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.FinancialTransaction; +import org.chorem.lima.ui.financialtransaction.table.FinancialTransactionTable; +import org.chorem.lima.ui.financialtransaction.table.FinancialTransactionTableModel; + +/** + * Handler associated with financial transaction view. + * + * @author chatellier + * @version $Revision: 2901 $ + * + * Last update : $Date: 2010-05-19 12:52:43 +0200 (mer. 19 mai 2010) $ + * By : $Author: jpepin $ + */ +public class FinancialTransactionUnbalancedViewHandler { + + /** log. */ + private static final Log log = + LogFactory.getLog(FinancialTransactionUnbalancedViewHandler.class); + + protected FinancialTransactionUnbalancedView view; + + protected FinancialTransactionUnbalancedViewHandler(FinancialTransactionUnbalancedView view) { + this.view = view; + } + + //implement new transaction button + //add a new entry to the selected transaction + public void addEmptyEntry(){ + + FinancialTransactionUnbalancedTable table = + (FinancialTransactionUnbalancedTable)view.getFinancialTransactionUnbalancedTable(); + FinancialTransactionUnbalancedTableModel model = + (FinancialTransactionUnbalancedTableModel)table.getModel(); + + int indexSelectedRow = table.getSelectedRow(); + if (indexSelectedRow != -1) { + Object selectedValue = model.getElementAt(indexSelectedRow); + try { + model.addEmptyEntry(selectedValue, indexSelectedRow); + } catch (LimaException ex){ + if (log.isErrorEnabled()) { + log.error("Can't add emptyentry", ex); + } + JOptionPane.showMessageDialog(view, + _("lima.warning.entrybookscloded")); + } + } + 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(){ + + FinancialTransactionUnbalancedTable table = + (FinancialTransactionUnbalancedTable)view.getFinancialTransactionUnbalancedTable(); + FinancialTransactionUnbalancedTableModel model = + (FinancialTransactionUnbalancedTableModel)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); + } + JOptionPane.showMessageDialog(view, + _("lima.warning.entrybookscloded")); + } + } + } + else { + if (log.isWarnEnabled()) { + log.warn("Call delete selected row without selection"); + } + } + } +} 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-05-27 15:16:22 UTC (rev 2915) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-05-27 17:22:42 UTC (rev 2916) @@ -107,7 +107,7 @@ lima.entries=Entries lima.entries.addtransaction= lima.entries.lettering= -lima.entries.searchtransaction= +lima.entries.searchunbalancedtransaction= lima.entrybook=Entry Book lima.entrybook.add=Add Entry Book lima.entrybook.code= 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-05-27 15:16:22 UTC (rev 2915) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-05-27 17:22:42 UTC (rev 2916) @@ -105,7 +105,7 @@ lima.entries=Traitement lima.entries.addtransaction=Saisir des \u00E9critures lima.entries.lettering=Ajouter une lettre -lima.entries.searchtransaction=Recherche les transactions +lima.entries.searchunbalancedtransaction=Entr\u00E9es non \u00E9quilibr\u00E9es lima.entrybook=Journal lima.entrybook.add=Ajouter un journal lima.entrybook.code=Code
participants (1)
-
jpepin@users.chorem.org