Author: jpepin Date: 2010-05-11 17:39:50 +0200 (Tue, 11 May 2010) New Revision: 2893 Url: http://chorem.org/repositories/revision/lima/2893 Log: Ajout fonction visualisation des journaux clotur?\195?\169s pour chaque p?\195?\169riode financi?\195?\168re Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.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/entrybook/model/EntryBookTableModel.java trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 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-11 10:01:59 UTC (rev 2892) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2010-05-11 15:39:50 UTC (rev 2893) @@ -121,6 +121,7 @@ <JMenuItem text="lima.chartofaccounts.journal" onActionPerformed='getHandler().showEntryBookView(this)' actionIcon='journal'/> <JMenuItem text="lima.fiscalyear.management" onActionPerformed='getHandler().showFiscalPeriodView(this)'/> + <JMenuItem text="lima.financialperiod.management" onActionPerformed='getHandler().showFinancialPeriodView(this)'/> </JMenu> <JMenu text="lima.entries"> 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-11 10:01:59 UTC (rev 2892) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2010-05-11 15:39:50 UTC (rev 2893) @@ -39,6 +39,7 @@ 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.financialperiod.FinancialPeriodView; import org.chorem.lima.ui.fiscalperiod.FiscalPeriodView; import org.chorem.lima.ui.transaction.FinancialTransactionView; import org.chorem.lima.ui.transaction.LetteringView; @@ -292,8 +293,9 @@ public void showEntryBookView(JAXXContext rootContext) { MainView mainView = getUI(rootContext); EntryBookView entryBookView= new EntryBookView(mainView); - mainView.showTab(_("lima.tab.account"), entryBookView); + mainView.showTab(_("lima.entrybooks"), entryBookView); } + /** * Show fiscal period view to create or block a period * @param rootContext @@ -305,6 +307,16 @@ } /** + * Show financial period view to create or block a period + * @param rootContext + */ + public void showFinancialPeriodView(JAXXContext rootContext) { + MainView mainView = getUI(rootContext); + FinancialPeriodView financialPeriodView = new FinancialPeriodView(mainView); + mainView.showTab(_("lima.financialperiod.management"), financialPeriodView); + } + + /** * Show account table report to view an account on a period * @param rootContext */ Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/model/EntryBookTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/model/EntryBookTableModel.java 2010-05-11 10:01:59 UTC (rev 2892) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/model/EntryBookTableModel.java 2010-05-11 15:39:50 UTC (rev 2893) @@ -135,9 +135,10 @@ result = entryBook.getType(); break; } - } catch (LimaException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (LimaException eee) { + if (log.isDebugEnabled()){ + log.debug("Can't get EntryBook",eee); + } } return result; Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTableModel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTableModel.java 2010-05-11 15:39:50 UTC (rev 2893) @@ -0,0 +1,223 @@ +/* *##% 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.financialperiod; + +import static org.nuiton.i18n.I18n._; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import javax.swing.table.AbstractTableModel; +import javax.transaction.Transaction; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.openejb.spi.TransactionService; +import org.chorem.lima.business.EntryBookService; +import org.chorem.lima.business.FinancialPeriodService; +import org.chorem.lima.business.FinancialTransactionService; +import org.chorem.lima.business.FiscalPeriodService; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.util.ErrorHelper; + +/** + * TODO add comment here. + * + * @author chatellier + * @version $Revision: 2884 $ + * + * Last update : $Date: 2010-05-06 11:57:19 +0200 (jeu. 06 mai 2010) $ + * By : $Author: jpepin $ + */ +public class FinancialPeriodTableModel extends AbstractTableModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 77027335135838258L; + + private static final Log log = LogFactory.getLog(FinancialPeriodTableModel.class); + + /** services */ + protected FiscalPeriodService fiscalPeriodService; + protected EntryBookService entryBookService; + protected FinancialPeriodService financialPeriodService; + + /** Datas cache */ + protected List<FinancialPeriodEntryBook> cacheDataList; + + public FinancialPeriodTableModel() { + fiscalPeriodService = LimaServiceFactory.getInstance().getFiscalPeriodService(); + entryBookService = LimaServiceFactory.getInstance().getEntryBookService(); + financialPeriodService = LimaServiceFactory.getInstance().getFinancialPeriodService(); + } + + /** Object to encapsulate entrybook and financialperiod */ + class FinancialPeriodEntryBook{ + FinancialPeriod financialPeriod; + EntryBook entryBook; + FinancialPeriodEntryBook(FinancialPeriod financialPeriod, EntryBook entryBook){ + this.financialPeriod=financialPeriod; + this.entryBook=entryBook; + } + } + + /* + * @see javax.swing.table.TableModel#getRowCount() + */ + @Override + public int getRowCount() { + cacheDataList=getDataList(); + return cacheDataList.size(); + } + + /* + * @see javax.swing.table.TableModel#getColumnCount() + */ + @Override + public int getColumnCount() { + return 3; + } + + /* + * @see javax.swing.table.TableModel#getColumnName(int) + */ + @Override + public String getColumnName(int columnIndex) { + + String result = "n/a"; + + switch(columnIndex) { + case 0 : + result = _("lima.tab.financialperiod"); + break; + case 1: + result = _("lima.entrybook"); + break; + case 2: + result = _("Bloquée"); + break; + } + + return result; + } + + /* + * @see javax.swing.table.TableModel#getColumnClass(int) + */ + @Override + public Class<?> getColumnClass(int columnIndex) { + // both String + return String.class; + } + + /* + * @see javax.swing.table.TableModel#isCellEditable(int, int) + */ + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + return false; + } + + /* + * @see javax.swing.table.TableModel#getValueAt(int, int) + */ + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + Object result = null; + + FinancialPeriodEntryBook financialPeriodEntryBook = cacheDataList.get(rowIndex); + + String[] monthName = {_("lima.date.january"), _("lima.date.february"), + _("lima.date.march"), _("lima.date.april"), _("lima.date.may"), + _("lima.date.june"), _("lima.date.july"), _("lima.date.august"), + _("lima.date.september"), _("lima.date.october"), + _("lima.date.november"), _("lima.date.december")}; + + if (financialPeriodEntryBook != null){ + /* Date date = fiscalPeriod.getBeginDate(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + String formatBeginDate = monthName[calendar.get(Calendar.MONTH)] + +" "+String.valueOf(calendar.get(Calendar.YEAR)); + date = fiscalPeriod.getEndDate(); + calendar.setTime(date); + String formatEndDate = monthName[calendar.get(Calendar.MONTH)] + +" "+String.valueOf(calendar.get(Calendar.YEAR)); + date = fiscalPeriod.getEndDate();*/ + + switch (columnIndex) { + case 0: + result = financialPeriodEntryBook.financialPeriod;//formatBeginDate + " - " + formatEndDate; + break; + case 1: + result = financialPeriodEntryBook.entryBook; + break; + case 2: + result=null; //get boolean financialperiod/entrybook blocked + } + } + + return result; + } + + public List<FinancialPeriodEntryBook> getDataList(){ + + List<FinancialPeriodEntryBook> results = new ArrayList<FinancialPeriodEntryBook>(); + List<FinancialPeriod> periods = new ArrayList<FinancialPeriod>(); + List<EntryBook> entrybooks = new ArrayList<EntryBook>(); + + try { + // get all fiscal period unblocked + List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllUnblockedFiscalPeriods(); + for (FiscalPeriod fiscalPeriod : fiscalPeriods) { + // get all financial period from unblocked fiscal period + periods.addAll(fiscalPeriod.getFinancialPeriod()); + } + // get all entrybook + entrybooks = entryBookService.getAllEntryBooks(); + // build the list with entrybook and financial period + for (FinancialPeriod period : periods) { + for (EntryBook entryB : entrybooks){ + FinancialPeriodEntryBook financialPeriodEntryBook = new FinancialPeriodEntryBook(period, entryB); + results.add(financialPeriodEntryBook); + } + } + + } + catch (LimaException eee) { + if (log.isErrorEnabled()) { + log.debug("Can't update model", eee); + } + ErrorHelper.showErrorDialog("Can't get entrybook and financial period list"); + } + return results; + } + + + public void blockFinancialPeriod(FiscalPeriod fiscalPeriod) throws LimaException { + fiscalPeriodService.blockFiscalPeriod(fiscalPeriod); + fireTableDataChanged(); + } +} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodView.jaxx (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodView.jaxx 2010-05-11 15:39:50 UTC (rev 2893) @@ -0,0 +1,57 @@ +<!-- ##% 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> + + <FinancialPeriodViewHandler id="handler" javaBean="new FinancialPeriodViewHandler(this)" /> + <org.chorem.lima.ui.financialperiod.FinancialPeriodTableModel id="modelFinancialPeriodTable"/> + + <Boolean id="selectedPeriod" javaBean="false" /> + <script> + <![CDATA[ + + void $afterCompleteSetup() { + //getModelFinancialPeriodTable().getDataList(); + } + + ]]> + </script> + <row> + <cell fill="both" weightx="1" weighty="1"> + <JScrollPane> + <org.jdesktop.swingx.JXTable id="financialPeriodTable" + model="{getModelFinancialPeriodTable()}" + highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}" + rowHeight="24" + selectionMode="{ListSelectionModel.SINGLE_INTERVAL_SELECTION}" + columnControlVisible="true" /> + <javax.swing.ListSelectionModel javaBean="getFinancialPeriodTable().getSelectionModel()" + onValueChanged="setSelectedPeriod(financialPeriodTable.getSelectedRow() != -1)"/> + </JScrollPane> + </cell> + <cell fill="horizontal" weighty="1" anchor="north"> + <Table> + <row> + <cell> + <JButton id="blockButton" text="lima.financialperiod.block" enabled="{isSelectedPeriod()}" + onActionPerformed="getHandler().blockFinancialPeriod()" /> + </cell> + </row> + </Table> + </cell> + </row> +</Table> Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java 2010-05-11 15:39:50 UTC (rev 2893) @@ -0,0 +1,85 @@ +/* *##% 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.financialperiod; + +import static org.nuiton.i18n.I18n._; + +import java.util.Calendar; +import java.util.Date; + +import javax.swing.JOptionPane; + +import org.apache.commons.lang.NotImplementedException; +import org.jdesktop.swingx.JXTable; +import org.nuiton.util.DateUtils; +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.entity.EntryBook; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialPeriodImpl; +import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.ui.entrybook.model.EntryBookTableModel; +import org.chorem.lima.ui.fiscalperiod.model.FiscalPeriodTableModel; +import org.chorem.lima.ui.fiscalperiod.AddPeriod; +import org.chorem.lima.ui.fiscalperiod.FiscalPeriodView; +import org.chorem.lima.util.ErrorHelper; + +/** + * TODO add comment here. + * + * @author chatellier + * @version $Revision: 2872 $ + * + * Last update : $Date: 2010-04-23 16:40:13 +0200 (ven. 23 avril 2010) $ + * By : $Author: jpepin $ + */ +public class FinancialPeriodViewHandler { + + private static final Log log = LogFactory.getLog(FinancialPeriodViewHandler.class); + + protected FinancialPeriodView view; + + protected FinancialPeriodViewHandler(FinancialPeriodView view) { + this.view = view; + } + + public void blockFinancialPeriod() { + /* JXTable financialPeriodeTable = view.getFinancialPeriodTable(); + int selectedRow = financialPeriodeTable.getSelectedRow(); + FinancialPeriodTableModel model = (FinancialPeriodTableModel)view.getFinancialPeriodTable().getModel(); + + // blocked it + try { + FinancialPeriod selectedFinancialPeriod = model.getFinancialPeriodAtRow(selectedRow); + int response = JOptionPane.showConfirmDialog(view, _("lima.question.financialperiod.blocked"), + _("lima.question"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + + if (response == JOptionPane.YES_OPTION) { + model.blockFinancialPeriod(selectedFinancialPeriod); + } + } catch (LimaException ex) { + if (log.isErrorEnabled()) { + log.error("Can't block financialperiod", ex); + } + ErrorHelper.showErrorDialog("Can't block financialperiod", ex); + }*/ + } +} 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-11 10:01:59 UTC (rev 2892) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-05-11 15:39:50 UTC (rev 2893) @@ -155,6 +155,8 @@ lima.filter.less.than=Less than lima.filter.not.contains=Not contains lima.filter.starts.with=Starts with +lima.financialperiod.block= +lima.financialperiod.management= lima.find.transaction=Find transaction lima.fiscalperiod.addFiscalPeriod= lima.fiscalperiod.block= @@ -269,6 +271,7 @@ lima.progressBar.load.etape5=Loading transactions lima.question=Question lima.question.confirmremove.account=This account have subaccounts, do you want remove this account ? +lima.question.financialperiod.blocked= lima.question.fiscalperiod.blocked= lima.question.fiscalperiod.morethan12= lima.question.load.accounts=There is no existing accounts in Lima. Do you want to load default accounts ? 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-11 10:01:59 UTC (rev 2892) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-05-11 15:39:50 UTC (rev 2893) @@ -153,6 +153,8 @@ lima.filter.less.than=Inf\u00E9rieur \u00E0 lima.filter.not.contains=Ne contient pas lima.filter.starts.with=Commence par +lima.financialperiod.block= +lima.financialperiod.management=P\u00E9riodes comptables lima.find.transaction=Rechercher transaction lima.fiscalperiod.addFiscalPeriod=Nouvel exercice lima.fiscalperiod.block=Cloturer un exercice @@ -254,6 +256,7 @@ lima.progressBar.load.etape5=Chargement des transactions lima.question=Question lima.question.confirmremove.account=Ce compte poss\u00E8de des sous comptes, voulez-vous supprimer ce compte ? +lima.question.financialperiod.blocked= lima.question.fiscalperiod.blocked=\u00C8tes vous s\u00FBre de vouloir cl\u00F4turer cette exercice ? Cette action est irr\u00E9versible \! lima.question.fiscalperiod.morethan12=La p\u00E9riode s\u00E9lectionner n'est pas de 12 mois, voulez-vous continuer ? lima.question.load.accounts=Il n'y a aucun plan comptable existant dans Lima. Voulez-vous en charger un par d\u00E9faut ? @@ -297,7 +300,6 @@ lima.tab.blocked=Block\u00E9 lima.tab.fiscalperiod=Exercice lima.tab.home=Accueil -lima.tab.journal=Journal lima.tab.lettering=Lettrage lima.tab.reports=Rapports lima.tab.result=Compte de r\u00E9sultat