r2939 - in trunk: lima-business/src/main/java/org/chorem/lima/business lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/main/java/org/chorem/lima/business/utils lima-callao/src/main/xmi lima-swing/src/main/java/org/chorem/lima/service lima-swing/src/main/java/org/chorem/lima/ui lima-swing/src/main/java/org/chorem/lima/ui/account lima-swing/src/main/java/org/chorem/lima/ui/financialstatement lima-swing/src/main/resources/i18n
Author: jpepin Date: 2010-06-09 19:27:20 +0200 (Wed, 09 Jun 2010) New Revision: 2939 Url: http://chorem.org/repositories/revision/lima/2939 Log: Ajout syst?\195?\168me de stockage du plan de g?\195?\169n?\195?\169ration pour le bilan et le compte de r?\195?\169sultat. Nouveau service FinancialStatementService, et nouvelle vue dans l'UI avec ajout, modification, suppression. Added: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialStatementService.java trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialStatementServiceLocal.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementHeaderForm.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementMovementForm.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementTreeTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementViewHandler.java Removed: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/DateUtil.java trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionComparator.java trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionDateComparator.java trunk/lima-business/src/main/java/org/chorem/lima/business/utils/NumberUtil.java 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/ReportServiceImpl.java trunk/lima-callao/src/main/xmi/accounting.properties trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 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/account/AccountViewHandler.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 Added: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialStatementService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialStatementService.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialStatementService.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -0,0 +1,41 @@ +/* *##% Lima Business + * 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.business; + +import java.util.List; + +import javax.ejb.Remote; +import org.chorem.lima.entity.FinancialStatementHeader; +import org.chorem.lima.entity.FinancialStatementMovement; + +@Remote +public interface FinancialStatementService { + + void createFinancialStatementHeader(FinancialStatementHeader masterFinancialStatementHeader, FinancialStatementHeader financialStatementHeader) throws LimaException, LimaBusinessException; + void updateFinancialStatementHeader(FinancialStatementHeader financialStatementHeader) throws LimaException, LimaBusinessException; + void removeFinancialStatementHeader(FinancialStatementHeader financialStatementHeader) throws LimaException, LimaBusinessException; + + void createFinancialStatementMovement(FinancialStatementHeader masterFinancialStatementHeader, FinancialStatementMovement financialStatementMovement) throws LimaException, LimaBusinessException; + void updateFinancialStatementMovement(FinancialStatementMovement financialStatementMovement) throws LimaException, LimaBusinessException; + void removeFinancialStatementMovement(FinancialStatementMovement financialStatementMovement) throws LimaException, LimaBusinessException; + + public List<Object> getChildrenFinancialStatement(FinancialStatementHeader financialStatementHeader) throws LimaException; + List<Object> getAllChildrenFinancialStatement(FinancialStatementHeader financialStatementHeader, List<Object> objects) throws LimaException, LimaBusinessException; +} Added: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialStatementServiceLocal.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialStatementServiceLocal.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialStatementServiceLocal.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -0,0 +1,27 @@ +/* *##% Lima Business + * 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.business; + +import javax.ejb.Local; + +@Local +public interface FinancialStatementServiceLocal extends FinancialStatementService { + +} 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-06-08 17:35:17 UTC (rev 2938) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -46,7 +46,7 @@ * Permet d'implémenter le Plan Comptable Général. * Un compte ne peut être supprimé si il contient des écritures comptables. * Un compte peut devenir père et avoir des comptes fils. Chaque compte créé doit - * renseigné si il appartient à un compte père avec le numéro de compte père. + * renseigner si il appartient à un compte père avec le numéro de compte père. * * @author Rémi Chapelet */ @@ -307,13 +307,10 @@ // Check rules for subaccount if have entries accountingRules.removeAccountRules(account, transaction); accountDAO.delete(subAccount); - log.debug(subAccount); } } // remove account - accountDAO.delete(account); - log.debug(account); - + accountDAO.delete(account); //commit commitTransaction(transaction); Added: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -0,0 +1,334 @@ +/* *##% Lima Business + * 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.business.ejb; + +import static org.nuiton.i18n.I18n._; +import java.util.ArrayList; +import java.util.List; +import javax.ejb.Stateless; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.AccountingRules; +import org.chorem.lima.business.FinancialStatementService; +import org.chorem.lima.business.FinancialStatementServiceLocal; +import org.chorem.lima.business.LimaBusinessException; +import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.FinancialStatementHeader; +import org.chorem.lima.entity.FinancialStatementHeaderDAO; +import org.chorem.lima.entity.FinancialStatementMovement; +import org.chorem.lima.entity.FinancialStatementMovementDAO; +import org.chorem.lima.entity.LimaCallaoDAOHelper; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.framework.TopiaQuery; + +@Stateless +public class FinancialStatementServiceImpl extends AbstractLimaService implements FinancialStatementService, FinancialStatementServiceLocal{ + + private static final Log log = + LogFactory.getLog(AccountServiceImpl.class); + + private TopiaContext rootContext; + + protected AccountingRules accountingRules; + + public FinancialStatementServiceImpl() { + LimaConfig config = LimaConfig.getInstance(); + try { + rootContext = TopiaContextFactory.getContext(config.getOptions()); + } catch (TopiaNotFoundException ex) { + if (log.isErrorEnabled()) { + log.error("Can't init topia context", ex); + } + } + accountingRules = config.getAccountingRules(); + } + + @Override + public void createFinancialStatementHeader(FinancialStatementHeader masterFinancialStatementHeader, FinancialStatementHeader financialStatementHeader) throws LimaException, LimaBusinessException { + + TopiaContext transaction = null; + try { + transaction = beginTransaction(); + + // check if FinancialStatementHeader label already exist + FinancialStatementHeaderDAO financialStatementHeaderDAO = + LimaCallaoDAOHelper.getFinancialStatementHeaderDAO(transaction); + + FinancialStatementHeader existFinancialStatementHeader = + financialStatementHeaderDAO.findByLabel(financialStatementHeader.getLabel()); + + if (existFinancialStatementHeader != null) { + throw new LimaBusinessException(_( + "An financialStatement already exists with this label : %s", + financialStatementHeader.getLabel())); + } + + financialStatementHeaderDAO.create(financialStatementHeader); + + // check if parent account exist; + if (masterFinancialStatementHeader != null) { + masterFinancialStatementHeader.addSubFinancialStatementHeaders(financialStatementHeader); + financialStatementHeaderDAO.update(masterFinancialStatementHeader); + } + + commitTransaction(transaction); + } + catch (Exception ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + } + + @Override + public void createFinancialStatementMovement(FinancialStatementHeader masterFinancialStatementHeader, FinancialStatementMovement financialStatementMovement) throws LimaException, LimaBusinessException { + + TopiaContext transaction = null; + try { + transaction = beginTransaction(); + + // check if FinancialStatementMovement label already exist + FinancialStatementMovementDAO financialStatementMovementDAO = + LimaCallaoDAOHelper.getFinancialStatementMovementDAO(transaction); + FinancialStatementHeaderDAO financialStatementHeaderDAO = + LimaCallaoDAOHelper.getFinancialStatementHeaderDAO(transaction); + + FinancialStatementMovement existFinancialStatementMovement = + financialStatementMovementDAO.findByLabel(financialStatementMovement.getLabel()); + + if (existFinancialStatementMovement != null) { + throw new LimaBusinessException(_( + "An financialStatement already exists with this label : %s", + financialStatementMovement.getLabel())); + } + + // check if masterFinancialStatementHeader exist; + if (masterFinancialStatementHeader != null) { + //create it + financialStatementMovementDAO.create(financialStatementMovement); + //update master + masterFinancialStatementHeader.addFinancialStatementMovement(financialStatementMovement); + financialStatementHeaderDAO.update(masterFinancialStatementHeader); + } + + commitTransaction(transaction); + } + catch (Exception ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + + } + + @Override + public void removeFinancialStatementHeader(FinancialStatementHeader financialStatementHeader) throws LimaException, LimaBusinessException { + + TopiaContext transaction = null; + try { + transaction = beginTransaction(); + FinancialStatementHeaderDAO financialStatementHeaderDAO = + LimaCallaoDAOHelper.getFinancialStatementHeaderDAO(transaction); + + //get all subFinancialStatementHeader and FinancialStatementMovement + List<Object> objects = getAllChildrenFinancialStatement(financialStatementHeader, new ArrayList<Object>()); + + //if FinancialStatementHeader have subFinancialStatementHeader + if (objects.size() > 0){ + for (Object object : objects) { + if (object instanceof FinancialStatementHeader){ + financialStatementHeaderDAO.delete((FinancialStatementHeader) object); + } + else { + //remove financial statement movement + removeFinancialStatementMovementWithTransaction((FinancialStatementMovement) object, transaction); + } + } + } + // remove account + financialStatementHeaderDAO.delete(financialStatementHeader); + + //commit + commitTransaction(transaction); + + } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + + } + + @Override + public void removeFinancialStatementMovement(FinancialStatementMovement financialStatementMovement) throws LimaException, LimaBusinessException { + TopiaContext transaction = null; + try { + transaction = beginTransaction(); + removeFinancialStatementMovementWithTransaction(financialStatementMovement, transaction); + } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + } + + + public void removeFinancialStatementMovementWithTransaction(FinancialStatementMovement financialStatementMovement, TopiaContext topiaContext) throws LimaException, LimaBusinessException { + try{ + FinancialStatementMovementDAO financialStatementMovementDAO = + LimaCallaoDAOHelper.getFinancialStatementMovementDAO(topiaContext); + financialStatementMovementDAO.delete(financialStatementMovement); + //commit + commitTransaction(topiaContext); + } + catch (TopiaException ex) { + doCatch(topiaContext, ex, log); + } + } + + @Override + public List<Object> getAllChildrenFinancialStatement(FinancialStatementHeader financialStatementHeader, List<Object> objects) throws LimaException, LimaBusinessException { + return objects; + // TODO Auto-generated method stub + } + + @Override + public List<Object> getChildrenFinancialStatement(FinancialStatementHeader masterFinancialStatementHeader) throws LimaException { + List<Object> objects = new ArrayList<Object>(); + + TopiaContext transaction = null; + try { + transaction = beginTransaction(); + + FinancialStatementHeaderDAO financialStatementHeaderDAO = + LimaCallaoDAOHelper.getFinancialStatementHeaderDAO(transaction); + + + TopiaQuery query = financialStatementHeaderDAO.createQuery(); + if (masterFinancialStatementHeader == null){ + query.addEquals("masterFinancialStatementHeader", masterFinancialStatementHeader); + } + else { + query.addWhere("masterFinancialStatementHeader = :value") + .addParam("value", masterFinancialStatementHeader); + } + objects.addAll(financialStatementHeaderDAO.findAllByQuery(query)); + + if (objects.isEmpty()){ + FinancialStatementMovementDAO financialStatementMovementDAO = + LimaCallaoDAOHelper.getFinancialStatementMovementDAO(transaction); + TopiaQuery query2 = financialStatementMovementDAO.createQuery(); + if (masterFinancialStatementHeader != null){ + query2.addWhere("financialStatementHeader = :value") + .addParam("value", masterFinancialStatementHeader); + } + objects.addAll(financialStatementMovementDAO.findAllByQuery(query2)); + } + } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + return objects; + } + + @Override + public void updateFinancialStatementHeader(FinancialStatementHeader financialStatementHeader) throws LimaException, LimaBusinessException { + TopiaContext transaction = null; + try { + transaction = beginTransaction(); + + // DAO + FinancialStatementHeaderDAO financialStatementHeaderDAO = + LimaCallaoDAOHelper.getFinancialStatementHeaderDAO(transaction); + //update + financialStatementHeaderDAO.update(financialStatementHeader); + //commit + commitTransaction(transaction); + } + catch (TopiaException ex) { + if (log.isErrorEnabled()) { + log.error("Error during update financialStatementHeader", ex); + } + throw new LimaException("Can't update financialStatementHeader", ex); + } + finally { + doFinally(transaction, log); + } + } + + @Override + public void updateFinancialStatementMovement(FinancialStatementMovement financialStatementMovement) throws LimaException, LimaBusinessException { + TopiaContext transaction = null; + try { + transaction = beginTransaction(); + + // DAO + FinancialStatementMovementDAO financialStatementMovementDAO = + LimaCallaoDAOHelper.getFinancialStatementMovementDAO(transaction); + //update + financialStatementMovementDAO.update(financialStatementMovement); + //commit + commitTransaction(transaction); + } + catch (TopiaException ex) { + if (log.isErrorEnabled()) { + log.error("Error during update financialStatementMovement", ex); + } + throw new LimaException("Can't update financialStatementMovement", ex); + } + finally { + doFinally(transaction, log); + } + } + + protected TopiaContext beginTransaction() throws TopiaException { + // basic check done, make check in database + // TODO move it into JTA + TopiaContext topiaTransaction; + topiaTransaction = rootContext.beginTransaction(); + log.trace("beginTransaction"+topiaTransaction); + return topiaTransaction; + } + + protected void commitTransaction(TopiaContext topiaTransaction) throws TopiaException { + try { + topiaTransaction.commitTransaction(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error("Error during commit context", eee); + } + throw eee; + } + } + +} Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2010-06-08 17:35:17 UTC (rev 2938) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -20,15 +20,11 @@ package org.chorem.lima.business.ejb; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.StringTokenizer; - import javax.ejb.Stateless; - import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -40,16 +36,11 @@ import org.chorem.lima.business.LimaException; import org.chorem.lima.business.ReportService; import org.chorem.lima.business.ReportServiceLocal; -import org.chorem.lima.business.utils.EntryComparator; -import org.chorem.lima.business.utils.EntryFinancialTransactionComparator; -import org.chorem.lima.business.utils.EntryFinancialTransactionDateComparator; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountDAO; -import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryDAO; -import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.nuiton.topia.TopiaContext; @@ -425,7 +416,6 @@ //Remove Spaces selectedAccounts = StringUtils.deleteWhitespace(selectedAccounts); - log.debug(selectedAccounts); //if no filter account if (selectedAccounts == null || selectedAccounts.equals("")){ accounts = accountDAO.findAllSubAccounts(); @@ -433,7 +423,8 @@ //build list account from selectedAccounts else{ accounts = new ArrayList<Account>(); - List<String> accountNumbers = new ArrayList<String>(); + //use hashset for delete duplicate numbers + HashSet<String> accountNumbers = new HashSet<String>(); //Split comma StringTokenizer stComma = new StringTokenizer(selectedAccounts, ","); while (stComma.hasMoreTokens()) { @@ -451,9 +442,6 @@ accountNumbers.add(s); } } - // remove duplicate numbers - HashSet<String> hashSet = new HashSet<String>(accountNumbers); - accountNumbers = new ArrayList<String>(hashSet); for (String accountNumber : accountNumbers) { Account accountFilter = accountDAO.findByAccountNumber(accountNumber); @@ -461,7 +449,6 @@ accounts.add(accountFilter); } } - log.debug(accounts); } for (Account account : accounts) { ReportsDatas reportsDatas = Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/DateUtil.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/DateUtil.java 2010-06-08 17:35:17 UTC (rev 2938) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/DateUtil.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -1,185 +0,0 @@ -/** - * *##% Callao DateUtil - * Copyright (C) 2009 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.business.utils; - -import java.util.Date; -import java.util.Calendar; -import java.util.GregorianCalendar; - -import org.apache.commons.logging.LogFactory; - - -/** - * Cette classe permet de manipuler des dates. - * @author Rémi Chapelet - * - * @deprecated since 0.4.0, use commons lang or nuiton dateutils - */ -public class DateUtil { - - /** log */ - private static final org.apache.commons.logging.Log log = LogFactory.getLog(DateUtil.class); - - - /** - * Initialise la date d'entrée le premier du mois à minuit. - * Exemple : 15 janvier 2009, alors date de sortie 1 Janvier 2009 00h00m00s - * @param d date - * @return - */ - public Date InitDateFirstDayMonth (Date d) - { - Date date_result = new Date(d.getYear(),d.getMonth(),1,0,0,0); - return date_result; - } - - /** - * Permet de retourner la date de fin de mois. Si on lui donne la date - * 5 Janv 2000, elle retourne alors 31 Jan 2000. - * @param d date de référence - * @return la date du fin de mois - */ - public Date InitDateEndDayMonth (Date d) - { - Calendar c = new GregorianCalendar (d.getYear()+1900,d.getMonth(),d.getDate()); - // Calcul le dernier jour du mois, prend en compte les années bixestiles - Integer maxDay = c.getActualMaximum(Calendar.DAY_OF_MONTH); - //Date dateEnd = new Date(d.getYear(),d.getMonth(),maxDay,23,59,59); - Calendar dateEnd = new GregorianCalendar (d.getYear()+1900,d.getMonth(),maxDay,23,59,59); - Date result = dateEnd.getTime(); - return result; - } - - /** - * Permet de comparer deux dates. Si d1 est plus grande que d2, alors true - * @param d1 Date 1 - * @param d2 Date 2 - * @return - */ - public boolean DateGreatThan (Date d1, Date d2) - { - boolean result = false; - long diff = d1.getTime() - d2.getTime(); - if (diff > 0 ) - { - result=true; - } - return result; - } - - /** - * Permet de calculer le nombre de mois entre les deux dates. - * @param d1 date 1 - * @param d2 date 2 - * @return - */ - public int numberOfMonths (Date d1, Date d2) - { - GregorianCalendar gc1 = new GregorianCalendar(); - gc1.setTime(d1); - GregorianCalendar gc2 = new GregorianCalendar(); - gc2.setTime(d2); - int number_months = 0; - gc1.add(GregorianCalendar.MONTH, 1); - while(gc1.compareTo(gc2)<=0) { - number_months++; - gc1.add(GregorianCalendar.MONTH, 1); - } - return number_months; - } - - /** - * Permet de renvoyer la date précédente à celle donnée en paramètre. - * Exemple : d = 17 avril 2000, return 16 avril 2000 - * @param d - * @return - */ - public Date previousDay(Date d) - { - Calendar c = new GregorianCalendar (d.getYear()+1900,d.getMonth(),d.getDate(),23,59,59); - // Calcul le jour précédent - c.add(Calendar.DATE, -1); - Date result = c.getTime(); - return result; - } - - /** - * Permet de copier une date. - * @param d - * @return - */ - public Date copyDate (Date d) - { - Date date_result = new Date(d.getYear(),d.getMonth(),d.getDay(),d.getHours(),d.getMinutes(),d.getSeconds()); - return date_result; - } - - /** - * Implémentation de compareTO. Si il y a besoin, il est possible de la modifier. - * @param d1 - * @param d2 - * @return - */ - public int compareDate(Date d1, Date d2) - { - return d1.compareTo(d2); - } - - /** - * Permet de renvoyer vrai si une date d donnée est entre deux dates. - * @param d date se trouvant ou non dans la période - * @param dateBegin date de début de période - * @param dateEnd date de fin de période - * @return - */ - public boolean betweenDate (Date d, Date dateBegin, Date dateEnd) - { - boolean result = false; - if ( ( (compareDate(d,dateBegin) == 0) || (compareDate(d,dateBegin) == 1) ) - && ( (compareDate(d,dateEnd) == 0) || (compareDate(d,dateEnd) == -1) ) ) - { - result = true; - } - return result; - } - - /** - * Permet de découper une date dans un tableau. - * Indices : - * 0 : année - * 1 : mois - * 2 : jour - * @param d - * @return - */ - public String[] arrayDate (Date d) - { - String dateTab[] = new String[3]; - // année - dateTab[0] = Integer.toString(d.getYear()+1900); - // mois - dateTab[1] = Integer.toString(d.getMonth()); - // jour - dateTab[2] = Integer.toString(d.getDate()); - return dateTab; - } - - -} Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionComparator.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionComparator.java 2010-06-08 17:35:17 UTC (rev 2938) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionComparator.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -1,32 +0,0 @@ -/* *##% 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.business.utils; - -import java.util.Comparator; - -import org.chorem.lima.entity.Entry; - -public class EntryFinancialTransactionComparator implements Comparator<Entry>{ - - @Override - public int compare(Entry o1, Entry o2) { - return o1.getFinancialTransaction().getTopiaId().compareTo(o2.getFinancialTransaction().getTopiaId()); - } - -} Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionDateComparator.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionDateComparator.java 2010-06-08 17:35:17 UTC (rev 2938) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionDateComparator.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -1,33 +0,0 @@ -/* *##% 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.business.utils; - -import java.util.Comparator; - -import org.chorem.lima.entity.Entry; - -public class EntryFinancialTransactionDateComparator implements Comparator<Entry>{ - - @Override - public int compare(Entry o1, Entry o2) { - return o1.getFinancialTransaction().getTransactionDate() - .compareTo(o2.getFinancialTransaction().getTransactionDate()); - } - -} Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/NumberUtil.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/NumberUtil.java 2010-06-08 17:35:17 UTC (rev 2938) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/NumberUtil.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -1,103 +0,0 @@ -/** - * *##% Callao NumberUtil - * Copyright (C) 2009 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.business.utils; - - -import java.text.NumberFormat; -import java.text.ParseException; -import java.util.Locale; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Cette classe permet de manipuler des nombres. - * Elle est utilisée essentiellement au niveau des entrées comptables afin de - * formater tous les nombres suivant la norme comptabilité choisie. - * @author Rémi Chapelet - * - * @deprecated since 0.4.0, use {@link NumberFormat} directly - */ -public class NumberUtil { - - /** log */ - private static final Log log = LogFactory.getLog(NumberUtil.class); - - public static NumberFormat numberFormat; - - public static final String format = "%0$10.2f"; - - - /** - * Instancie la classe NumberFormat. Elle va permettre d'apporter des méthodes - * pour manipuler les chaines de caractères et les nombres. - * On doit définir la variable locale. - * @return - */ - public static NumberFormat getNumberFormat() { - if (numberFormat == null) { - numberFormat = NumberFormat.getNumberInstance(Locale.FRENCH); - } - return numberFormat; - } - - /** - * Format la chaine de caractère en nombre. - * @param amount - */ - public Double formatNumber (String amount) - { - Double numberDouble; - try { - Number number = getNumberFormat().parse(amount); - numberDouble = number.doubleValue(); - } catch (ParseException e) { - throw new RuntimeException(e); - } - return numberDouble; - } - - - /** - * Formate un nombre sous format Double en renvoyant en chaîne de caractère. - * Il utilise la variable "format" pour définir le formatage ainsi que la - * variable locale. - * @param number - * @return - */ - public String format(double number) - { - return String.format(Locale.FRENCH, format, number).trim(); - } - - /** - * Formate un nombre sous format String. - * @param theDouble - * @return - */ - public String format(String amount) - { - return format(formatNumber(amount)); - } - - - - -} \ No newline at end of file Modified: trunk/lima-callao/src/main/xmi/accounting.properties =================================================================== --- trunk/lima-callao/src/main/xmi/accounting.properties 2010-06-08 17:35:17 UTC (rev 2938) +++ trunk/lima-callao/src/main/xmi/accounting.properties 2010-06-09 17:27:20 UTC (rev 2939) @@ -4,6 +4,9 @@ org.chorem.lima.entity.Account.attribute.subLedgers.tagvalue.lazy=false org.chorem.lima.entity.FinancialTransaction.attribute.financialPeriod.tagvalue.lazy=false org.chorem.lima.entity.FiscalPeriod.attribute.financialPeriod.tagvalue.lazy=false +org.chorem.lima.entity.FinancialStatementHeader.attribute.subFinancialStatementHeaders.tagvalue.lazy=false +org.chorem.lima.entity.FinancialStatementHeader.attribute.financialStatementMovement.tagvalue.lazy=false + #model.tagvalue.dbSchema=Callao model.tagvalue.String=text \ No newline at end of file Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) Modified: trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 2010-06-08 17:35:17 UTC (rev 2938) +++ trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -34,6 +34,7 @@ import org.chorem.lima.business.AccountService; import org.chorem.lima.business.EntryBookService; import org.chorem.lima.business.FinancialPeriodService; +import org.chorem.lima.business.FinancialStatementService; import org.chorem.lima.business.FiscalPeriodService; import org.chorem.lima.business.RecordService; import org.chorem.lima.business.FinancialTransactionService; @@ -235,9 +236,8 @@ /** - * Get record service. + * Get report service. * - * @return record service proxy */ public ReportService getReportService() { @@ -256,6 +256,24 @@ } /** + * Get financial statement service. + * + */ + public FinancialStatementService getFinancialStatementService() { + + String lookupName = "FinancialStatementServiceImplRemote"; + FinancialStatementService ejbHome = null; + try { + ejbHome = (FinancialStatementService)ctx.lookup(lookupName); + } catch (NamingException eee) { + if (log.isErrorEnabled()) { + log.error("Can't lookup for service : " + lookupName, eee); + } + } + return ejbHome; + } + + /** * Get record service. * * @return record service proxy 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-06-08 17:35:17 UTC (rev 2938) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2010-06-09 17:27:20 UTC (rev 2939) @@ -122,6 +122,7 @@ actionIcon='journal'/> <JMenuItem text="lima.charts.fiscalyear" onActionPerformed='getHandler().showFiscalPeriodView(this)'/> <JMenuItem text="lima.charts.financialperiod" onActionPerformed='getHandler().showFinancialPeriodView(this)'/> + <JMenuItem text="lima.charts.financialstatement" onActionPerformed='getHandler().showFinancialStatementView(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-06-08 17:35:17 UTC (rev 2938) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -41,6 +41,7 @@ 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.financialstatement.FinancialStatementView; import org.chorem.lima.ui.financialtransaction.FinancialTransactionView; import org.chorem.lima.ui.financialtransaction.LetteringView; import org.chorem.lima.ui.financialtransactionunbalanced.FinancialTransactionUnbalancedView; @@ -319,6 +320,16 @@ } /** + * Show financial statement view to generate balance sheet and income statement + * @param rootContext + */ + public void showFinancialStatementView(JAXXContext rootContext) { + MainView mainView = getUI(rootContext); + FinancialStatementView financialStatementView = new FinancialStatementView(mainView); + mainView.showTab(_("lima.charts.financialstatement"), financialStatementView); + } + + /** * Show account table report to view an account on a period * @param rootContext */ Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2010-06-08 17:35:17 UTC (rev 2938) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -81,6 +81,8 @@ if ( selectedRow != -1) { treePath = view.getAccountsTreeTable().getPathForRow(selectedRow); } else { + //FIXME Get root created on model with Impl() + //Can best not create root in model, and verify if root is null ? treePath = new TreePath(accountsTreeTableModel.getRoot()); } Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementHeaderForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementHeaderForm.jaxx (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementHeaderForm.jaxx 2010-06-09 17:27:20 UTC (rev 2939) @@ -0,0 +1,53 @@ +<!-- ##% 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. + ##% --> + +<JDialog modal="true"> + + <org.chorem.lima.entity.FinancialStatementHeader id="header" javaBean='null'/> + <Boolean id="addState" javaBean='true'/> + + <script> + <![CDATA[ + protected void performCancel() { + setHeader(null); + dispose(); + } + ]]> + </script> + + <Table> + <row> + <cell fill="horizontal"> + <JLabel text="lima.financialstatement.label"/> + </cell> + <cell fill="horizontal"> + <JTextField id="descriptionTextField" text="{getHeader().getLabel()}"/> + <javax.swing.text.Document javaBean="getDescriptionTextField().getDocument()" + onInsertUpdate='getHeader().setLabel(getDescriptionTextField().getText())' + onRemoveUpdate='getHeader().setLabel(getDescriptionTextField().getText())' /> + </cell> + </row> + <row> + <cell fill="none"> + <JButton text="lima.common.ok" onActionPerformed="dispose()"/> + </cell> + <cell fill="none"> + <JButton text="lima.common.cancel" onActionPerformed="performCancel()"/> + </cell> + </row> + </Table> +</JDialog> \ No newline at end of file Property changes on: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementHeaderForm.jaxx ___________________________________________________________________ Added: svn:executable + * Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementMovementForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementMovementForm.jaxx (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementMovementForm.jaxx 2010-06-09 17:27:20 UTC (rev 2939) @@ -0,0 +1,98 @@ +<!-- ##% 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. + ##% --> + +<JDialog modal="true"> + + <org.chorem.lima.entity.FinancialStatementMovement id="movement" javaBean='null'/> + + <Boolean id="addState" javaBean='true'/> + + <script> + <![CDATA[ + protected void performCancel() { + setMovement(null); + dispose(); + } + ]]> + </script> + + <Table> + <row> + <cell fill="horizontal"> + <JLabel text="lima.financialstatement.label"/> + </cell> + <cell fill="horizontal"> + <JTextField id="descriptionTextField" text="{getMovement().getLabel()}"/> + <javax.swing.text.Document javaBean="getDescriptionTextField().getDocument()" + onInsertUpdate='getMovement().setLabel(getDescriptionTextField().getText())' + onRemoveUpdate='getMovement().setLabel(getDescriptionTextField().getText())' /> + </cell> + </row> + <row> + <cell fill="horizontal"> + <JLabel text="lima.financialstatement.accounts"/> + </cell> + <cell fill="horizontal"> + <JTextField id="accountsTextField" text="{getMovement().getAccounts()}"/> + <javax.swing.text.Document javaBean="getAccountsTextField().getDocument()" + onInsertUpdate='getMovement().setAccounts(getAccountsTextField().getText())' + onRemoveUpdate='getMovement().setAccounts(getAccountsTextField().getText())' /> + </cell> + </row> + <row> + <cell fill="horizontal"> + <JLabel text="lima.financialstatement.creditaccounts"/> + </cell> + <cell fill="horizontal"> + <JTextField id="debitAccountsTextField" text="{getMovement().getDebitAccounts()}"/> + <javax.swing.text.Document javaBean="getDebitAccountsTextField().getDocument()" + onInsertUpdate='getMovement().setDebitAccounts(getDebitAccountsTextField().getText())' + onRemoveUpdate='getMovement().setDebitAccounts(getDebitAccountsTextField().getText())' /> + </cell> + </row> + <row> + <cell fill="horizontal"> + <JLabel text="lima.financialstatement.debitaccounts"/> + </cell> + <cell fill="horizontal"> + <JTextField id="creditAccountsTextField" text="{getMovement().getCreditAccounts()}"/> + <javax.swing.text.Document javaBean="getCreditAccountsTextField().getDocument()" + onInsertUpdate='getMovement().setCreditAccounts(getCreditAccountsTextField().getText())' + onRemoveUpdate='getMovement().setCreditAccounts(getCreditAccountsTextField().getText())' /> + </cell> + </row> + <row> + <cell fill="horizontal"> + <JLabel text="lima.financialstatement.provisiondeprecationaccounts"/> + </cell> + <cell fill="horizontal"> + <JTextField id="provisionDeprecationAccountsTextField" text="{getMovement().getProvisionDeprecationAccounts()}"/> + <javax.swing.text.Document javaBean="getProvisionDeprecationAccountsTextField().getDocument()" + onInsertUpdate='getMovement().setProvisionDeprecationAccounts(getProvisionDeprecationAccountsTextField().getText())' + onRemoveUpdate='getMovement().setProvisionDeprecationAccounts(getProvisionDeprecationAccountsTextField().getText())' /> + </cell> + </row> + <row> + <cell fill="none"> + <JButton text="lima.common.ok" onActionPerformed="dispose()"/> + </cell> + <cell fill="none"> + <JButton text="lima.common.cancel" onActionPerformed="performCancel()"/> + </cell> + </row> + </Table> +</JDialog> \ No newline at end of file Property changes on: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementMovementForm.jaxx ___________________________________________________________________ Added: svn:executable + * Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementTreeTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementTreeTableModel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementTreeTableModel.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -0,0 +1,269 @@ +/* *##% 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.financialstatement; + +import static org.nuiton.i18n.I18n._; +import java.util.List; +import javax.swing.tree.TreePath; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.FinancialStatementService; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.FinancialStatementHeader; +import org.chorem.lima.entity.FinancialStatementHeaderImpl; +import org.chorem.lima.entity.FinancialStatementMovement; +import org.chorem.lima.service.LimaServiceFactory; +import org.jdesktop.swingx.treetable.AbstractTreeTableModel; + +/** + * Tree table model for account edition. + * + * @author ore + * @author chatellier + * @version $Revision: 2934 $ + * + * Last update : $Date: 2010-06-08 11:55:04 +0200 (mar., 08 juin 2010) $ + * By : $Author: jpepin $ + */ +public class FinancialStatementTreeTableModel extends AbstractTreeTableModel { + + /** log. */ + private static final Log log = LogFactory.getLog(FinancialStatementViewHandler.class); + + /** Account service. */ + protected final FinancialStatementService financialStatementService; + + /** + * Model constructor. Init account service used here. + */ + public FinancialStatementTreeTableModel() { + //create root for the tree + super(new FinancialStatementHeaderImpl()); + // Gets factory service + financialStatementService = LimaServiceFactory.getInstance().getFinancialStatementService(); + } + + + @Override + public int getColumnCount() { + return 1; + } + + @Override + public String getColumnName(int column) { + String res = null; + switch (column) { + case 0: + res = _("lima.account.label"); + break; + } + return res; + } + + @Override + public int getChildCount(Object node) { + int result = 0; + if (node == getRoot()) { + try { + result = financialStatementService. + getChildrenFinancialStatement(null).size(); + } catch (LimaException eee) { + log.debug("Can't count child", eee); + } + } + else { + if (node instanceof FinancialStatementHeader){ + FinancialStatementHeader parentFinancialStatementHeader = + (FinancialStatementHeader) node; + try { + result = financialStatementService.getChildrenFinancialStatement( + parentFinancialStatementHeader).size(); + } catch (LimaException eee) { + log.debug("Can't count child", eee); + } + } + } + return result; + } + + @Override + public Object getChild(Object parent, int index) { + Object result = null; + if (parent == getRoot()) { + try { + List<Object> allObjects = + financialStatementService.getChildrenFinancialStatement(null); + result = allObjects.get(index); + } catch (LimaException eee) { + log.debug("Can't get child", eee); + } + } + else { + FinancialStatementHeader parentFinancialStatementHeader = + (FinancialStatementHeader) parent; + try { + List<Object> objects = financialStatementService. + getChildrenFinancialStatement(parentFinancialStatementHeader); + result = objects.get(index); + } catch (LimaException eee) { + log.debug("Can't get child", eee); + } + } + return result; + } + + @Override + public int getIndexOfChild(Object parent, Object child) { + int result = 0; + + if (parent == getRoot()) { + try { + List<Object> allObjects = + financialStatementService.getChildrenFinancialStatement(null); + result = allObjects.indexOf(child); + } catch (LimaException eee) { + log.debug("Can't get index child", eee); + } + } + else { + FinancialStatementHeader parentFinancialStatementHeader = + (FinancialStatementHeader) parent; + try { + List<Object> objects = financialStatementService. + getChildrenFinancialStatement(parentFinancialStatementHeader); + result = objects.indexOf(child); + } catch (LimaException eee) { + log.debug("Can't get index child", eee); + } + } + return result; + } + + @Override + public Object getValueAt(Object node, int column) { + Object result = "n/a"; + if (node instanceof FinancialStatementHeader) { + FinancialStatementHeader financialStatementHeader = (FinancialStatementHeader) node; + switch (column) { + case 0: + result = financialStatementHeader.getLabel(); + break; + } + } + else { + FinancialStatementMovement financialStatementMovement = (FinancialStatementMovement) node; + switch (column) { + case 0: + result = financialStatementMovement.getLabel(); + break; + } + } + return result; + } + + @Override + public boolean isCellEditable(Object node, int column) { + return false; + } + + @Override + public boolean isLeaf(Object node) { + return getChildCount(node) == 0; + } + + /** + * Add FinancialStatementHeader (path can be null). + * + * @param path + * @param account + * @throws LimaException + */ + public void addFinancialStatementHeader(TreePath path, FinancialStatementHeader financialStatementHeader) throws LimaException { + // Calling account service + FinancialStatementHeader parentFinancialStatementHeader = + (FinancialStatementHeader) path.getLastPathComponent(); + if (parentFinancialStatementHeader == getRoot()) { + parentFinancialStatementHeader = null; + } + financialStatementService.createFinancialStatementHeader( + parentFinancialStatementHeader, financialStatementHeader); + modelSupport.fireTreeStructureChanged(path.getParentPath()); + } + + /** + * Add FinancialStatementMovement (path can't be null). + * + * @param path + * @param account + * @throws LimaException + */ + public void addFinancialStatementMovement(TreePath path, FinancialStatementMovement financialStatementMovement) throws LimaException { + // Calling account service + FinancialStatementHeader parentFinancialStatementHeader = + (FinancialStatementHeader) path.getLastPathComponent(); + if (parentFinancialStatementHeader != getRoot()) { + financialStatementService.createFinancialStatementMovement(parentFinancialStatementHeader, financialStatementMovement); + modelSupport.fireTreeStructureChanged(path); + } + } + + /** + * Update financialStatementHeader. + * + * @param path + * @param account + * @throws LimaException + */ + public void updateFinancialStatement(TreePath path, Object object) throws LimaException { + + int index = getIndexOfChild( + path.getParentPath().getLastPathComponent(), object); + if (object instanceof FinancialStatementHeader){ + financialStatementService.updateFinancialStatementHeader((FinancialStatementHeader) object); + } + else { + financialStatementService.updateFinancialStatementMovement((FinancialStatementMovement) object); + } + modelSupport.fireTreeStructureChanged(path); + } + + + + /** + * Remove financialStatementHeader or financialStatementMovement + * + * @param path + * @param object + * @throws LimaException + */ + public void removeFinancialStatementObject(TreePath path, Object object) throws LimaException { + // Calling account service + int index = getIndexOfChild( + path.getParentPath().getLastPathComponent(), object); + if (object instanceof FinancialStatementHeader){ + financialStatementService.removeFinancialStatementHeader((FinancialStatementHeader) object); + } + else { + financialStatementService.removeFinancialStatementMovement((FinancialStatementMovement) object); + } + + modelSupport.fireChildRemoved(path.getParentPath(), index, object); + } + +} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementView.jaxx (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementView.jaxx 2010-06-09 17:27:20 UTC (rev 2939) @@ -0,0 +1,67 @@ +<!-- ##% 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> + + <FinancialStatementViewHandler id="handler" javaBean="new FinancialStatementViewHandler(this)" /> + <Boolean id="selectedRow" javaBean="false" /> + + <script> + <![CDATA[ + //getHandler().init(); + ]]> + </script> + + <row> + <cell fill="both" weightx="1" weighty="1" rows='4'> + <JScrollPane> + <org.jdesktop.swingx.JXTreeTable id="treeTable" + selectionMode="{ListSelectionModel.SINGLE_SELECTION}" + treeTableModel="{new org.chorem.lima.ui.financialstatement.FinancialStatementTreeTableModel()}" + highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}" /> + <javax.swing.ListSelectionModel + javaBean="getTreeTable().getSelectionModel()" + onValueChanged="setSelectedRow(treeTable.getSelectedRow() != -1)"/> + </JScrollPane> + </cell> + <cell fill="horizontal"> + <JButton id="addFinancialStatementHeader" text="lima.add.financialstatementheader" + onActionPerformed="getHandler().addFinancialStatementHeader()"/> + </cell> + </row> + <row> + <cell fill="horizontal"> + <JButton id="addFinancialStatementMovement" text="lima.add.financialstatementmovement" + onActionPerformed="getHandler().addFinancialStatementMovement()" + enabled="{isSelectedRow()}"/> + </cell> + </row> + <row> + <cell fill="horizontal"> + <JButton id="updateButton" text="lima.common.update" + onActionPerformed="getHandler().updateFinancialStatement()" + enabled="{isSelectedRow()}"/> + </cell> + </row> + <row> + <cell fill="horizontal"> + <JButton id="removeButton" text="lima.common.remove" + onActionPerformed="getHandler().removeFinancialStatement()" + enabled="{isSelectedRow()}"/> + </cell> + </row> +</Table> \ No newline at end of file Property changes on: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementView.jaxx ___________________________________________________________________ Added: svn:executable + * Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementViewHandler.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatement/FinancialStatementViewHandler.java 2010-06-09 17:27:20 UTC (rev 2939) @@ -0,0 +1,237 @@ +/* *##% 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.financialstatement; + +import static org.nuiton.i18n.I18n._; +import javax.swing.JOptionPane; +import javax.swing.tree.TreePath; +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.FinancialStatementHeader; +import org.chorem.lima.entity.FinancialStatementHeaderImpl; +import org.chorem.lima.entity.FinancialStatementMovement; +import org.chorem.lima.entity.FinancialStatementMovementImpl; +import org.chorem.lima.util.DialogHelper; +import org.chorem.lima.util.ErrorHelper; +import org.jdesktop.swingx.JXTreeTable; + +/** + * Handler associated with account view. + * + * @author chatellier + * @version $Revision: 2934 $ + * + * Last update : $Date: 2010-06-08 11:55:04 +0200 (mar., 08 juin 2010) $ + * By : $Author: jpepin $ + */ +public class FinancialStatementViewHandler { + + /** log. */ + private static final Log log = LogFactory.getLog(FinancialStatementViewHandler.class); + + protected FinancialStatementView view; + + protected JXTreeTable treeTable; + + protected FinancialStatementTreeTableModel treeTableModel; + + protected FinancialStatementViewHandler(FinancialStatementView view) { + this.view = view; + } + + /** + * Add new account with account form. + */ + public void addFinancialStatementHeader() { + treeTable = view.getTreeTable(); + treeTableModel = + (FinancialStatementTreeTableModel) treeTable.getTreeTableModel(); + + FinancialStatementHeader newFinancialStatementHeader = new FinancialStatementHeaderImpl(); + FinancialStatementHeaderForm financialStatementHeaderForm = new FinancialStatementHeaderForm(view); + financialStatementHeaderForm.setHeader(newFinancialStatementHeader); + // jaxx constructor don't call super() ? + financialStatementHeaderForm.setLocationRelativeTo(view); + financialStatementHeaderForm.setVisible(true); + + // null == cancel action + newFinancialStatementHeader = financialStatementHeaderForm.getHeader(); + if (newFinancialStatementHeader != null) { + // get current selection path + TreePath treePath = null; + int selectedRow = treeTable.getSelectedRow(); + if ( selectedRow != -1) { + treePath = treeTable.getPathForRow(selectedRow); + } else { + treePath = new TreePath(treeTableModel.getRoot()); + } + + // add it + try { + treeTableModel.addFinancialStatementHeader(treePath, newFinancialStatementHeader); + } catch (LimaBusinessException eee) { + if (log.isErrorEnabled()) { + log.error("Can't add financialStatementHeader", eee); + } + DialogHelper.showMessageDialog(eee.getMessage()); + + } + + catch (LimaException ex) { + if (log.isErrorEnabled()) { + log.error("Can't add financialStatementHeader", ex); + } + ErrorHelper.showErrorDialog("Can't add financialStatementHeader", ex); + } + } + }; + + public void addFinancialStatementMovement(){ + + treeTable = view.getTreeTable(); + treeTableModel = + (FinancialStatementTreeTableModel) treeTable.getTreeTableModel(); + + FinancialStatementMovement newFinancialStatementMovement = new FinancialStatementMovementImpl(); + FinancialStatementMovementForm financialStatementMovementForm = new FinancialStatementMovementForm(view); + financialStatementMovementForm.setMovement(newFinancialStatementMovement); + // jaxx constructor don't call super() ? + financialStatementMovementForm.setLocationRelativeTo(view); + financialStatementMovementForm.setVisible(true); + newFinancialStatementMovement=financialStatementMovementForm.getMovement(); + + // null == cancel action + if (newFinancialStatementMovement != null) { + // get current selection path + TreePath treePath = null; + int selectedRow = view.treeTable.getSelectedRow(); + treePath = view.treeTable.getPathForRow(selectedRow); + // add it + try { + treeTableModel. + addFinancialStatementMovement(treePath, newFinancialStatementMovement); + } catch (LimaBusinessException eee) { + if (log.isErrorEnabled()) { + log.error("Can't add FinancialStatementMovement", eee); + } + DialogHelper.showMessageDialog(eee.getMessage()); + } + + catch (LimaException eee) { + if (log.isErrorEnabled()) { + log.error("Can't add FinancialStatementMovement", eee); + } + DialogHelper.showMessageDialog(eee.getMessage()); + } + } + } + + /** + * Open account form with selected account. + * Verifiy if it's an account or a subledger + */ + public void updateFinancialStatement() { + + treeTable = view.getTreeTable(); + treeTableModel = + (FinancialStatementTreeTableModel) treeTable.getTreeTableModel(); + + // get selected account + int selectedRow = view.treeTable.getSelectedRow(); + TreePath treePath = view.treeTable.getPathForRow(selectedRow); // not null + Object selectedObject = treePath.getLastPathComponent(); + //update Account or update SubLedger + if (selectedObject != null) { + // get current selection path + if ( selectedRow != -1) { + treePath = view.treeTable.getPathForRow(selectedRow); + } else { + treePath = new TreePath(treeTableModel.getRoot()); + } + //test if selectedrow is account or ledger + if (selectedObject instanceof FinancialStatementHeader){ + FinancialStatementHeaderForm financialStatementHeaderForm = new FinancialStatementHeaderForm(view); + financialStatementHeaderForm.setHeader((FinancialStatementHeader) selectedObject); + // jaxx constructor don't call super() ? + financialStatementHeaderForm.setLocationRelativeTo(view); + financialStatementHeaderForm.setVisible(true); + // null == cancel action + selectedObject = financialStatementHeaderForm.getHeader(); + } + // else is a subledger + else{ + FinancialStatementMovementForm financialStatementMovementForm = new FinancialStatementMovementForm(view); + financialStatementMovementForm.setMovement((FinancialStatementMovement) selectedObject); + // jaxx constructor don't call super() ? + financialStatementMovementForm.setLocationRelativeTo(view); + financialStatementMovementForm.setVisible(true); + // null == cancel action + selectedObject = financialStatementMovementForm.getMovement(); + } + //if action confirmed + if (selectedObject != null){ + // update it + try { + treeTableModel.updateFinancialStatement(treePath, selectedObject); + } catch (LimaException eee) { + if (log.isErrorEnabled()) { + log.error("Can't add update", eee); + } + DialogHelper.showMessageDialog(eee.getMessage()); + } + } + } + } + + /** + * Ask for user to remove for selected account, and remove it if confirmed. + */ + public void removeFinancialStatement() { + treeTable = view.getTreeTable(); + treeTableModel = + (FinancialStatementTreeTableModel) treeTable.getTreeTableModel(); + + // Any row selected + int selectedRow = view.treeTable.getSelectedRow(); + if ( selectedRow != -1) { + int n = JOptionPane.showConfirmDialog(view, + _("lima.question.remove.account"), + _("lima.question"), + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE); + if (n == JOptionPane.YES_OPTION) { + // update view of treetable + TreePath treePath = view.treeTable.getPathForRow(selectedRow); + Object object = treePath.getLastPathComponent(); + + try{ + treeTableModel.removeFinancialStatementObject(treePath, object); + } catch (LimaException eee) { + if (log.isErrorEnabled()) { + log.error("Can't delete account", eee); + } + DialogHelper.showMessageDialog(eee.getMessage()); + } + } + } + }; + +} 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-06-08 17:35:17 UTC (rev 2938) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-06-09 17:27:20 UTC (rev 2939) @@ -34,6 +34,8 @@ lima.action.normalscreen.tip=Open ui in normal screen lima.add=Add lima.add.entry=Add an entry +lima.add.financialstatementheader= +lima.add.financialstatementmovement= lima.add.lettering=Add a letter lima.add.transaction=Add a transaction lima.all=All @@ -62,6 +64,7 @@ lima.charts.account=Accounts chart lima.charts.entrybook=EntryBooks chart lima.charts.financialperiod=Financial Periods +lima.charts.financialstatement= lima.charts.fiscalyear=Fiscal Years lima.close=Closed lima.closure=Closure @@ -162,6 +165,11 @@ lima.filter.starts.with=Starts with lima.financialperiod.block= lima.financialperiod.management= +lima.financialstatement.accounts= +lima.financialstatement.creditaccounts= +lima.financialstatement.debitaccounts= +lima.financialstatement.label= +lima.financialstatement.provisiondeprecationaccounts= lima.find.transaction=Find transaction lima.fiscalperiod.addFiscalPeriod= lima.fiscalperiod.block= 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-06-08 17:35:17 UTC (rev 2938) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-06-09 17:27:20 UTC (rev 2939) @@ -34,6 +34,8 @@ lima.action.normalscreen=Ecran normal lima.action.normalscreen.tip=Revenir en \u00E9cran normal lima.add.entry=Ajouter entr\u00E9e +lima.add.financialstatementheader= +lima.add.financialstatementmovement= lima.add.lettering= lima.add.transaction=Ajouter transaction lima.all=Tous @@ -61,6 +63,7 @@ lima.charts.account=Plan comptable lima.charts.entrybook=Journaux lima.charts.financialperiod=P\u00E9riodes comptables +lima.charts.financialstatement= lima.charts.fiscalyear=Exercices lima.close=Ferm\u00E9 lima.closure=Cloture @@ -161,6 +164,11 @@ lima.filter.starts.with=Commence par lima.financialperiod.block=Cloturer une p\u00E9riode lima.financialperiod.management= +lima.financialstatement.accounts= +lima.financialstatement.creditaccounts= +lima.financialstatement.debitaccounts= +lima.financialstatement.label= +lima.financialstatement.provisiondeprecationaccounts= lima.find.transaction=Rechercher transaction lima.fiscalperiod.addFiscalPeriod=Nouvel exercice lima.fiscalperiod.block=Cloturer un exercice
participants (1)
-
jpepin@users.chorem.org