Author: jpepin Date: 2010-05-10 18:38:31 +0200 (Mon, 10 May 2010) New Revision: 2891 Url: http://chorem.org/repositories/revision/lima/2891 Log: Ajout fonction Balance Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java Modified: 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/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTableModel.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-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2010-05-10 14:42:46 UTC (rev 2890) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2010-05-10 16:38:31 UTC (rev 2891) @@ -118,7 +118,7 @@ <JMenu text="lima.structure"> <JMenuItem text="lima.chartofaccounts.management" onActionPerformed='getHandler().showAccountView(this)' actionIcon='account'/> - <JMenuItem text="lima.chartofaccounts.journal" onActionPerformed='getHandler().showJournalView(this)' + <JMenuItem text="lima.chartofaccounts.journal" onActionPerformed='getHandler().showEntryBookView(this)' actionIcon='journal'/> <JMenuItem text="lima.fiscalyear.management" onActionPerformed='getHandler().showFiscalPeriodView(this)'/> </JMenu> @@ -141,8 +141,8 @@ <JMenu text="lima.reports"> <JMenuItem text="lima.accounts" onActionPerformed='getHandler().showAccountReports(this)'/> <JMenuItem text="lima.entrybooks" onActionPerformed='getHandler().showEntryBookReports(this)'/> + <JMenuItem text="lima.balance" onActionPerformed='getHandler().showBalanceView(this)'/> <JMenuItem text="lima.reports" onActionPerformed='getHandler().showReportsView(this)' actionIcon='rapport'/> - <JMenuItem text="lima.balance" onActionPerformed='getHandler().showBalanceView(this)'/> <JMenuItem text="lima.bilan" onActionPerformed='getHandler().showBilanView(this)'/> <JMenuItem text="lima.result" onActionPerformed='getHandler().showResultView(this)'/> </JMenu> 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-10 14:42:46 UTC (rev 2890) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2010-05-10 16:38:31 UTC (rev 2891) @@ -19,7 +19,6 @@ package org.chorem.lima.ui; import static org.nuiton.i18n.I18n._; -import static org.nuiton.i18n.I18n.n_; import java.awt.Desktop; import java.net.URL; @@ -37,6 +36,7 @@ import org.chorem.lima.LimaContext; import org.chorem.lima.ui.account.AccountView; import org.chorem.lima.ui.accountsreports.AccountsReportsView; +import org.chorem.lima.ui.balance.BalanceView; import org.chorem.lima.ui.entrybook.EntryBookView; import org.chorem.lima.ui.entrybooksreports.EntryBooksReportsView; import org.chorem.lima.ui.fiscalperiod.FiscalPeriodView; @@ -276,25 +276,33 @@ HomeView homeView = new HomeView(mainView); mainView.showTab(_("lima.tab.home"), homeView, false); } - /** - * Show fiscal period view to create or block a period + * Show account tree table view to create or modify accounts * @param rootContext */ - public void showFiscalPeriodView(JAXXContext rootContext) { + public void showAccountView(JAXXContext rootContext) { MainView mainView = getUI(rootContext); - FiscalPeriodView fiscalPeriodView = new FiscalPeriodView(mainView); - mainView.showTab(_("lima.tab.fiscalperiod"), fiscalPeriodView); + AccountView accountView = new AccountView(mainView); + mainView.showTab(_("lima.tab.account"), accountView); } /** * Show account tree table view to create or modify accounts * @param rootContext */ - public void showAccountView(JAXXContext rootContext) { + public void showEntryBookView(JAXXContext rootContext) { MainView mainView = getUI(rootContext); - AccountView accountView = new AccountView(mainView); - mainView.showTab(_("lima.tab.account"), accountView); + EntryBookView entryBookView= new EntryBookView(mainView); + mainView.showTab(_("lima.tab.account"), entryBookView); } + /** + * Show fiscal period view to create or block a period + * @param rootContext + */ + public void showFiscalPeriodView(JAXXContext rootContext) { + MainView mainView = getUI(rootContext); + FiscalPeriodView fiscalPeriodView = new FiscalPeriodView(mainView); + mainView.showTab(_("lima.tab.fiscalperiod"), fiscalPeriodView); + } /** * Show account table report to view an account on a period @@ -326,15 +334,11 @@ FinancialTransactionView transactionView = new FinancialTransactionView(mainView); mainView.showTab(_("lima.tab.transaction"), transactionView); } - - /** - * Show EntryBook view to create entry book - * @param rootContext - */ - public void showJournalView(JAXXContext rootContext) { + + public void showBalanceView(JAXXContext rootContext) { MainView mainView = getUI(rootContext); - EntryBookView entryBookView = new EntryBookView(mainView); - mainView.showTab(_("lima.tab.journal"), entryBookView); + BalanceView balanceView = new BalanceView(mainView); + mainView.showTab(_("lima.tab.balance"), balanceView); } public void showBilanView(JAXXContext rootContext) { @@ -343,12 +347,6 @@ // mainView.showTab(_("lima.tab.bilan"), bilanView); } - public void showBalanceView(JAXXContext rootContext) { - MainView mainView = getUI(rootContext); - // BalanceView balanceView = new BalanceView(mainView); - // mainView.showTab(_("lima.tab.balance"), balanceView); - } - public void showClosureTimeSpanView(JAXXContext rootContext) { //getClosureView().initBlockForm(); } Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceTableModel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceTableModel.java 2010-05-10 16:38:31 UTC (rev 2891) @@ -0,0 +1,217 @@ +/* + * *##% 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.balance; + +import static org.nuiton.i18n.I18n._; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javassist.bytecode.stackmap.BasicBlock.Catch; + +import javax.swing.table.AbstractTableModel; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.AccountService; +import org.chorem.lima.business.FinancialTransactionService; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.ui.ReportsHelper; +import org.chorem.lima.util.ErrorHelper; + +/** + * Entry book table model. + * + * @author ore + * @author chatellier + * @version $Revision: 2865 $ + * + * Last update : $Date: 2010-04-19 15:19:30 +0200 (lun. 19 avril 2010) $ + * By : $Author: jpepin $ + */ +public class BalanceTableModel extends AbstractTableModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 7578692417919755647L; + + /** log. */ + private static final Log log = LogFactory.getLog(BalanceTableModel.class); + + /** Services. */ + protected AccountService accountService; + protected FinancialTransactionService financialTransactionService; + + /** Helper */ + protected ReportsHelper helper; + + /** Account. */ + protected Account selectedAccount; + + /** Begin Date. */ + protected Date selectedBeginDate; + + /** EndDate. */ + protected Date selectedEndDate; + + /** data cache */ + protected List<Account> cacheDataList; + + /** amount debit */ + protected Double amountDebit; + + /** amount credit */ + protected Double amountCredit; + + /** + * Constructor. + */ + public BalanceTableModel() { + accountService = LimaServiceFactory.getInstance().getAccountService(); + financialTransactionService = LimaServiceFactory.getInstance().getTransactionService(); + amountCredit=0.00; + amountDebit=0.00; + } + + @Override + public int getRowCount() { + return cacheDataList.size(); + } + + @Override + public int getColumnCount() { + return 6; + } + + @Override + public String getColumnName(int column) { + String res = "n/a"; + switch (column) { + case 0: + res = _("lima.account.number"); // Numero de compte + break; + case 1: + res = _("lima.account.label"); // Label + break; + case 2: + res = _("lima.balance.move.debit"); // Total Debit + break; + case 3: + res = _("lima.balance.move.credit"); // Total Credit + break; + case 4: + res = _("lima.balance.solde.debit"); //Solde Debit + break; + case 5: + res = _("lima.balance.solde.credit"); //Solde Credit + break; + } + return res; + } + + @Override + public Object getValueAt(int row, int column) { + Object result = null; + Account currentRow = cacheDataList.get(row); + //get entries for the period for the current row + try { + List<Entry> entries = financialTransactionService.getAllEntriesForAccount(currentRow, selectedBeginDate, selectedEndDate); + Double solde = helper.getSolde(entries); + Double debit = helper.getTotalDebit(entries); + Double credit = helper.getTotalCredit(entries); + switch (column) { + case 0: + result = currentRow.getAccountNumber(); //account number + break; + case 1: + result = currentRow.getLabel(); //account label + break; + case 2: + result = debit; // total debit + break; + case 3: + result = credit; // total crédit + break; + case 4: // solde debit + if (solde>0){ + result = Math.abs(solde); + } + else { + result = 0; + } + break; + case 5: // solde credit + if (solde<0){ + result = Math.abs(solde); + } + else { + result = 0; + } + break; + } + } + catch (Exception eee) { + log.debug("Can't get entries", eee); + } + + return result; + } + + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + // Just read, no write + return false; + } + + public void setBeginDate(Date date){ + log.debug("setBeginDate"); + selectedBeginDate = date; + log.debug(selectedBeginDate); + cacheDataList=getDataList(); + fireTableDataChanged(); + } + + public void setEndDate(Date date){ + log.debug("setEndDate"); + selectedEndDate = date; + log.debug(selectedEndDate); + cacheDataList=getDataList(); + fireTableDataChanged(); + } + + public List<Account> getDataList(){ + List<Account> results = new ArrayList<Account>(); + try { + results = accountService.getAllAccounts(); + } + catch (LimaException eee) { + if (log.isErrorEnabled()) { + log.debug("Can't update model", eee); + } + ErrorHelper.showErrorDialog("Can't get entries list", eee); + } + return results; + } + +} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx 2010-05-10 16:38:31 UTC (rev 2891) @@ -0,0 +1,97 @@ +<!-- ##% 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> + <BalanceViewHandler id="handler" javaBean="new BalanceViewHandler(this)" /> + <Boolean id="selectedRow" javaBean="false" /> + <org.chorem.lima.ui.balance.BalanceTableModel id="modelBalanceTable"/> + <script> + <![CDATA[ + + import org.chorem.lima.entity.Account; + import org.apache.commons.lang.time.DateUtils; + import java.util.Calendar; + + // get begin date + Calendar calendarBegin = Calendar.getInstance(); + // set begindate to JAN 1 - 0:00.000 of this years + Date beginDate = calendarBegin.getTime(); + beginDate = DateUtils.truncate(beginDate, Calendar.YEAR); + getModelBalanceTable().setBeginDate(beginDate); + + // get end date + Calendar calendarEnd = Calendar.getInstance(); + Date endDate = calendarEnd.getTime(); + getModelBalanceTable().setEndDate(endDate); + + getBeginDatePicker().setDate(beginDate); + getEndDatePicker().setDate(endDate); + + ]]> + </script> + <row fill="horizontal" weightx="1" weighty="0" anchor="center"> + <cell> + <JLabel id="beginCalendarPanelLabel" text="lima.accountsreports.begincalendar"/> + </cell> + <cell> + <org.jdesktop.swingx.JXDatePicker id="beginDatePicker" + onActionPerformed="getModelBalanceTable().setBeginDate(beginDatePicker.getDate()); + getHandler().updateFooterLabel()" /> + </cell> + <cell> + <JLabel id="endCalendarPanelLabel" text="lima.accountsreports.endcalendar"/> + </cell> + <cell> + <org.jdesktop.swingx.JXDatePicker id="endDatePicker" + onActionPerformed="getModelBalanceTable().setEndDate(endDatePicker.getDate()); + getHandler().updateFooterLabel()"/> + </cell> + </row> + <row> + <cell fill="both" weightx="1" weighty="1" columns="6"> + <JScrollPane> + <org.jdesktop.swingx.JXTable id="balanceTable" rowHeight="24" + model="{getModelBalanceTable()}" + highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}" + selectionMode="{ListSelectionModel.SINGLE_SELECTION}" + columnControlVisible="true"/> + <javax.swing.ListSelectionModel javaBean="getBalanceTable().getSelectionModel()" + onValueChanged="setSelectedRow(balanceTable.getSelectedRow() != -1)"/> + </JScrollPane> + </cell> + </row> + <row fill="horizontal" anchor="center"> + <cell> + <JLabel text="lima.amountcredit"/> + </cell> + <cell> + <JLabel id="amountCreditLabel" /> + </cell> + <cell> + <JLabel text="lima.amountdebit" /> + </cell> + <cell> + <JLabel id="amountDebitLabel" /> + </cell> + <cell> + <JLabel id="soldeLabel" text="lima.solde"/> + </cell> + <cell> + <JLabel id="amountSoldeLabel"/> + </cell> + </row> +</Table> \ No newline at end of file Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java 2010-05-10 16:38:31 UTC (rev 2891) @@ -0,0 +1,80 @@ +/* *##% 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.balance; + +import static org.nuiton.i18n.I18n._; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.ui.ReportsHelper; + + +/** + * Handler associated with accounts reports view. + * + * @author chatellier + * @version $Revision: 2884 $ + * + * Last update : $Date: 2010-05-06 11:57:19 +0200 (jeu. 06 mai 2010) $ + * By : $Author: jpepin $ + */ +public class BalanceViewHandler { + + /** log. */ + private static final Log log = + LogFactory.getLog(BalanceViewHandler.class); + + protected BalanceView view; + + /** Helper **/ + protected ReportsHelper helper; + + protected BalanceViewHandler(BalanceView view) { + this.view = view; + } + + public void updateFooterLabel(){ + BalanceTableModel tablemodel = + (BalanceTableModel) view.getBalanceTable().getModel(); + Double amountCredit = tablemodel.amountCredit; + Double amountDebit = tablemodel.amountDebit; + view.amountCreditLabel.setText(String.valueOf(amountCredit)); + view.amountDebitLabel.setText(String.valueOf(amountDebit)); + + Double amountSolde = amountDebit - amountCredit; + view.amountSoldeLabel.setText(String.valueOf(amountSolde)); + + if (amountSolde <0){ + //solde debiteur + view.soldeLabel.setText(_("lima.soldecredit")); + } + else if(amountSolde > 0) { + //solde créditeur + view.soldeLabel.setText(_("lima.soldedebit")); + } + else { + //solde = 0 + view.soldeLabel.setText(_("lima.solde")); + } + } + +} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTableModel.java 2010-05-10 14:42:46 UTC (rev 2890) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTableModel.java 2010-05-10 16:38:31 UTC (rev 2891) @@ -162,7 +162,7 @@ } else { if (log.isDebugEnabled()) { - log.debug("No Account selected skip table model update"); + log.debug("No EntryBook selected skip table model update"); } } 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-10 14:42:46 UTC (rev 2890) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-05-10 16:38:31 UTC (rev 2891) @@ -104,7 +104,7 @@ lima.entries.addtransaction= lima.entries.lettering= lima.entries.searchtransaction= -lima.entrybook= +lima.entrybook=Entry Book lima.entrybook.code= lima.entrybook.label= lima.entrybook.type= @@ -191,7 +191,6 @@ lima.init.context.done=Context was initialized in %1$s lima.init.errorclosing= lima.init.ui.done=UI initialized -lima.journal=Journal lima.lettered=Lettered lima.lettering=Lettering lima.lettering.add= 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-10 14:42:46 UTC (rev 2890) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-05-10 16:38:31 UTC (rev 2891) @@ -102,7 +102,7 @@ lima.entries.addtransaction=Saisir des \u00E9critures lima.entries.lettering=Ajouter une lettre lima.entries.searchtransaction=Recherche les transactions -lima.entrybook= +lima.entrybook=Journal lima.entrybook.code=Code lima.entrybook.label=Libelle lima.entrybook.type=Type @@ -187,7 +187,6 @@ lima.init.context.done=Initialisation du context termin\u00E9 en %1$s lima.init.errorclosing= lima.init.ui.done=Initialisation des interface graphiques termin\u00E9e -lima.journal=Journal lima.lettered=Lettr\u00E9 lima.lettering=Lettrage lima.lettering.add=Ajouter une lettre