r2883 - in trunk: lima-business/src/main/java/org/chorem/lima/business lima-business/src/main/java/org/chorem/lima/business/accountingrules lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/main/resources lima-callao lima-callao/src/main/xmi lima-swing/src/main/java/org/chorem/lima/ui/account lima-swing/src/main/java/org/chorem/lima/ui/subledger lima-swing/src/main/java/org/chorem/lima/ui/transaction/table
Author: jpepin Date: 2010-05-04 15:44:56 +0200 (Tue, 04 May 2010) New Revision: 2883 Url: http://chorem.org/repositories/revision/lima/2883 Log: Externalisation des r?\195?\168gles m?\195?\169tiers (Account Rules) pour quelles soient localisables. V?\195?\169rification dans l'UI lors de la modification de la date d'une transaction que cette derni?\195?\168re est valide. Added: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java Removed: trunk/lima-swing/src/main/java/org/chorem/lima/ui/subledger/model/ Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialPeriodService.java trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-business/src/main/resources/lima.properties trunk/lima-callao/pom.xml trunk/lima-callao/src/main/xmi/accounting.properties trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java 2010-05-04 13:22:41 UTC (rev 2882) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java 2010-05-04 13:44:56 UTC (rev 2883) @@ -54,6 +54,6 @@ void removeAccount(Account account) throws LimaException; void removeAccountwithSubAccounts(Account account) throws LimaException; - + List<Account> getChildrenAccounts(Account masterAccount) throws LimaException; } Added: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2010-05-04 13:44:56 UTC (rev 2883) @@ -0,0 +1,40 @@ +/* *##% 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 org.chorem.lima.entity.Account; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FiscalPeriod; +import org.nuiton.topia.TopiaContext; + +/** + * Service for localized rules + * @author joe + * + */ +public interface AccountingRules { + + public void createAccountRules(Account masterAccount, Account account) throws LimaException; + public void createSubLedgerRules(Account masterAccount, Account account) throws LimaException; + public void createFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException; + public void blockFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException; + public void removeAccountRules(Account account, TopiaContext transaction) throws LimaException; + public void removeEntryBookRules(EntryBook entryBook, TopiaContext topiaTransaction) throws LimaException; + +} Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialPeriodService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialPeriodService.java 2010-05-04 13:22:41 UTC (rev 2882) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialPeriodService.java 2010-05-04 13:44:56 UTC (rev 2883) @@ -19,10 +19,10 @@ package org.chorem.lima.business; +import java.util.Date; import java.util.List; import org.chorem.lima.entity.FinancialPeriod; -import org.chorem.lima.entity.FiscalPeriod; /** * Financial period service. @@ -40,8 +40,7 @@ List<FinancialPeriod> getUnblockedFinancialPeriods() throws LimaException; void createFinancialPeriod(FinancialPeriod financialPeriod) throws LimaException; - - //void updateFiscalPeriod(FinancialPeriod financialPeriod) throws LimaException; - //void removeFiscalPeriod(FinancialPeriod financialPeriod) throws LimaException; + FinancialPeriod getFinancialPeriodWithDate(Date date) throws LimaException; + } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java 2010-05-04 13:22:41 UTC (rev 2882) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java 2010-05-04 13:44:56 UTC (rev 2883) @@ -41,8 +41,6 @@ void createFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; void blockFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; - - //void updateFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; void removeAllFiscalPeriods() throws LimaException; } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2010-05-04 13:22:41 UTC (rev 2882) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2010-05-04 13:44:56 UTC (rev 2883) @@ -19,8 +19,11 @@ package org.chorem.lima.business; +import static org.nuiton.i18n.I18n._; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.accountingrules.DefaultAccountingRules; import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.nuiton.util.ApplicationConfig; import org.nuiton.util.ArgumentsParserException; @@ -44,22 +47,24 @@ private static final String configFile = "lima.properties"; - public static LimaConfig getInstance() { - /* - if (instance == null) { - instance = new LimaConfig(); - instance.setConfigFileName("lima.properties"); - try { - instance.parse(new String[0]); - } catch (ArgumentsParserException ex) { - if (log.isErrorEnabled()) { - log.error("Can't read configuration", ex); - } + protected AccountingRules accountingRules; + + public LimaConfig(){ + // set defaut option (included configuration file name : important) + for (Option o : Option.values()) { + setDefaultOption(o.key, o.defaultValue); + } + + /* // set action alias + for (Action a : Action.values()) { + for (String alias : a.aliases) { + addActionAlias(alias, a.action); } - - // FIXME put this in another place - instance.setOption("topia.persistence.classes", LimaCallaoDAOHelper.getImplementationClassesAsString()); }*/ + + } + + public static LimaConfig getInstance() { if (instance == null) { instance = new LimaConfig(); instance.loadConfiguration(configFile); @@ -67,6 +72,34 @@ return instance; } + /** + * + * @return + */ + public AccountingRules getAccountingRules(){ + //TODO PEPIN 20100503 instancier la bonne classe de nationalite en fonction du fichier de configuration + + if (accountingRules == null){ + Class accountingRulesClass = getOptionAsClass(Option.RULES_NATIONALTY.key); + if (accountingRulesClass == null){ + accountingRules = new DefaultAccountingRules(); + } + else { + try { + accountingRules = (AccountingRules) accountingRulesClass.newInstance(); + } catch (InstantiationException e) { + log.error("Can't instantiate accounting rules", e); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + } + + return accountingRules; + } + + + protected void loadConfiguration(String configFileName){ instance.setConfigFileName(configFileName); @@ -79,5 +112,65 @@ } instance.setOption("topia.persistence.classes", LimaCallaoDAOHelper.getImplementationClassesAsString()); } + + /** + * Lima option definition. + * + * Contains all lima configuration key, with defaut value and + * information for jaxx configuration frame ({@link #type}, + * {@link #_transient}, {@link #_final}...) + */ + public static enum Option implements OptionDef { + + CONFIG_FILE(CONFIG_FILE_NAME, _("lima.config.configFileName.description"), "lima-config.properties", String.class, true, true), + RULES_NATIONALTY("lima.rules",_("lima.config.rulesnationality"),"default", String.class, false, false); + + public final String key; + public final String description; + public final String defaultValue; + public final Class<?> type; + public final boolean _transient; + public final boolean _final; + + private Option(String key, String description, String defaultValue, + Class<?> type, boolean _transient, boolean _final) { + this.key = key; + this.description = description; + this.defaultValue = defaultValue; + this.type = type; + this._final = _final; + this._transient = _transient; + } + + @Override + public boolean isFinal() { + return _final; + } + + @Override + public boolean isTransient() { + return _transient; + } + + @Override + public String getDefaultValue() { + return defaultValue; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getKey() { + return key; + } + + @Override + public Class<?> getType() { + return type; + } + } } Added: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2010-05-04 13:44:56 UTC (rev 2883) @@ -0,0 +1,161 @@ +/* *##% 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.accountingrules; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.AccountingRules; +import org.chorem.lima.business.LimaBusinessException; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.ejb.AccountServiceImpl; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.EntryDAO; +import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.entity.LimaCallaoDAOHelper; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +/** + * Defaults rules, if no localized rules classes is instantiated + * this default class contain the strict minimum rules to check the data integrity + * @author joe + * + */ +public class DefaultAccountingRules implements AccountingRules { + + protected static final Log log = + LogFactory.getLog(DefaultAccountingRules.class); + + /** + * Rules to check before create accounts + */ + @Override + public void createAccountRules(Account masterAccount, Account account) throws LimaException { + // Check if the numberaccount is not blank + if (StringUtils.isBlank(account.getAccountNumber())) { + throw new LimaBusinessException("Invalid AccountNumber : " + + account.getAccountNumber()); + } + } + + /** + * Rules to check before create subledger + */ + @Override + public void createSubLedgerRules(Account masterAccount, Account account) + throws LimaException { + // check the number account is not empty + if (StringUtils.isBlank(account.getAccountNumber())) { + log.debug("TEST"); + throw new LimaBusinessException("Invalid AccountNumber : " + + account.getAccountNumber()); + } + //check if parentaccount have no subaccount + if (masterAccount.getSubAccounts().size() > 0){ + throw new LimaBusinessException( + "Subledger must create on a account whithout subaccount : "); + } + } + + /** + * Rules to check before create fiscals periods + */ + @Override + public void createFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException { + //check if the enddate period is after the begindate period + if (fiscalPeriod.getEndDate().before(fiscalPeriod.getBeginDate())){ + throw new LimaBusinessException( + "The enddate is before the begindate"); + } + } + + /** + * Rules to check before block fiscals periods + */ + @Override + public void blockFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException { + + } + + /** + * Rules to check if an account and all his subaccount is not used + * Recursive function + */ + @Override + public void removeAccountRules(Account account, TopiaContext transaction) throws LimaException { + try{ + EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(transaction); + // Check if account have entries + int nbentries = entryDAO.findAllByAccount(account).size(); + if (nbentries != 0) { + throw new LimaBusinessException("Can't delete Account with entries"); + } + //check if subaccount have entries + AccountServiceImpl accountService = new AccountServiceImpl(); + for (Account childrenAccounts : accountService.getChildrenAccounts(account)) { + removeAccountRules(childrenAccounts, transaction); + } + } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + } + + @Override + public void removeEntryBookRules(EntryBook entryBook, TopiaContext topiaTransaction) throws LimaException { + try { + EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaTransaction); + // Check if entrybook have entries + int nbentries = entryDAO.findAllByEntryBook(entryBook).size(); + log.debug(entryDAO.findAllByEntryBook(entryBook).size()); + if (nbentries != 0) { + throw new LimaBusinessException("Can't delete entryBook with entries"); + } + } + catch (TopiaException ex) { + doCatch(topiaTransaction, ex, log); + } + + } + + /** + * Generic code used to rollback a transaction. + * + * TODO : replace this by JTA + * @throws LimaException + */ + protected void doCatch(TopiaContext transaction, Exception cause, Log log) throws LimaException { + if (transaction != null) { + try { + transaction.rollbackTransaction(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error("Error during rollback context", eee); + } + } + } + if (log.isErrorEnabled()) { + log.error("Exception during query", cause); + } + throw new LimaException("Exception during query", cause); + } + +} Added: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2010-05-04 13:44:56 UTC (rev 2883) @@ -0,0 +1,201 @@ +package org.chorem.lima.business.accountingrules; + +import java.util.Date; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.time.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.business.ejb.FinancialPeriodServiceImpl; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialPeriodImpl; +import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.entity.FiscalPeriodDAO; +import org.chorem.lima.entity.LimaCallaoDAOHelper; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaQuery; +import org.nuiton.topia.framework.TopiaQuery.Op; + +public class FranceAccountingRules extends DefaultAccountingRules { + protected static final Log log = LogFactory.getLog(DefaultAccountingRules.class); + + private FinancialPeriodServiceImpl financialPeriodService = + new FinancialPeriodServiceImpl(); + + /** + * Règles de vérification de la création du PCG, appliquées à la comptabilité française + * + */ + public void createAccountRules(Account masterAccount, Account account) throws LimaException { + super.createAccountRules(masterAccount, account); + + // Check if the number account is type numeric + if (!StringUtils.isNumeric(account.getAccountNumber())){ + throw new LimaBusinessException("AccountNumber is not numeric : " + + account.getAccountNumber()); + } + + // Check if the number account start with the number of the master account + if (masterAccount!=null && !account.getAccountNumber().startsWith( + masterAccount.getAccountNumber())){ + + throw new LimaBusinessException( + "Account Number not begin with the number account master : " + + account.getAccountNumber()); + } + + // Check if master account have a number between 1 to 8 + if (masterAccount==null && !account.getAccountNumber().matches("[1-8]")){ + throw new LimaBusinessException( + "Master account is not a digit between 1 to 8 :" + + account.getAccountNumber()); + } + + } + + /** + * Règles de vérification d'ouverture d'un exercice, appliquées à la comptabilité française + * + * Permet de créer un exercice. + * + * Elle a une durée de un an, composées de 12 périodes mensuelles. + * Elle peut aussi être plus courte ou plus longue si l'entreprise + * se constitu ou entre en liquidation ou que l'entreprise decide + * de changer + * + * Elle correspond à l'exercice comptable. + * Pas plus de deux exercices fiscaux ne peuvent-être ouvert en même temps + * + */ + public void createFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException { + super.createFiscalPeriodRules(fiscalPeriod, transaction); + try { + FiscalPeriodDAO fiscalPeriodDAO = + LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + + //Checks if is not the first fiscalperiod to create + if (fiscalPeriodDAO.findAll().size()!=0){ + + TopiaQuery query = fiscalPeriodDAO.createQuery(); + fiscalPeriodDAO.findAllByQuery(query); + query.addOrderDesc(FiscalPeriod.END_DATE); + + //get the last fiscal period + FiscalPeriod lastFiscalPeriod = fiscalPeriodDAO.findByQuery(query); + log.debug("lastFiscalPeriod : "+lastFiscalPeriod); + + //check the new fiscal period adjoining the last + Date dateLastFiscalPeriod=lastFiscalPeriod.getEndDate(); + dateLastFiscalPeriod = DateUtils. + addMilliseconds(dateLastFiscalPeriod, 1); + Date dateFiscalPeriod=fiscalPeriod.getBeginDate(); + if(dateLastFiscalPeriod.compareTo(dateFiscalPeriod)!=0){ + throw new LimaBusinessException( + "The new fiscalperiod must adjoining the last"); + } + + //We can create a new fiscal period meantime the last fiscal period was not locked + //But not the ante periodfiscal + int unblockedFiscalPeriod = + fiscalPeriodDAO.findAllByLocked(false).size(); + log.debug(unblockedFiscalPeriod); + if (unblockedFiscalPeriod>1){ + throw new LimaBusinessException( + "The ante fiscal period is not locked"); + } + } + + Date beginDate = fiscalPeriod.getBeginDate(); + Date endDate = fiscalPeriod.getEndDate(); + + // FinancialPeriod of 1 month are created + Date loopDate = beginDate; + while (loopDate.compareTo(endDate) <= 0) { + Date loopUpperDate = DateUtils.addMonths(loopDate, 1); + Date periodEndDate = DateUtils.addMilliseconds(loopUpperDate, -1); + FinancialPeriod financialPeriod = new FinancialPeriodImpl(); + financialPeriod.setBeginDate(loopDate); + financialPeriod.setEndDate(periodEndDate); + fiscalPeriod.addFinancialPeriod(financialPeriod); + loopDate = loopUpperDate; + log.debug("financialPeriod : "+financialPeriod); + financialPeriodService.createFinancialPeriod(financialPeriod); + } + } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + } + + /** + * Règles de vérification de fermeture d'un exercice, appliquées à la comptabilité française + */ + public void blockFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException { + try{ + FiscalPeriodDAO fiscalPeriodDAO = + LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + + TopiaQuery query = fiscalPeriodDAO.createQuery(); + fiscalPeriodDAO.findAllByQuery(query); + query.add(FiscalPeriod.LOCKED, Op.EQ, false); + query.addOrder(FiscalPeriod.END_DATE); + + FiscalPeriod oldestUnBlockedFiscalPeriod = + fiscalPeriodDAO.findByQuery(query); + + //Check if the fiscal period to block is the oldest + if (!oldestUnBlockedFiscalPeriod.equals(fiscalPeriod)){ + throw new LimaBusinessException( + "The ante fiscal period must be blocked before this."); + } + } catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + } + + /** + * Generic code used to rollback a transaction. + * + * TODO : replace this by JTA + * @throws LimaException + */ + protected void doCatch(TopiaContext transaction, Exception cause, Log log) throws LimaException { + if (transaction != null) { + try { + transaction.rollbackTransaction(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error("Error during rollback context", eee); + } + } + } + if (log.isErrorEnabled()) { + log.error("Exception during query", cause); + } + throw new LimaException("Exception during query", cause); + } + + /** + * Generic code used too close a transaction. + * + * @param transaction transaction to close + * @param log log (can be null) + * @throws LimaException + */ + protected void doFinally(TopiaContext transaction, Log log) throws LimaException { + if (transaction != null) { + try { + transaction.closeContext(); + } catch (TopiaException ex) { + if (log != null && log.isErrorEnabled()) { + log.error("Can't close transaction", ex); + } + throw new LimaException("Can't close transaction", ex); + } + } + } +} 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-05-04 13:22:41 UTC (rev 2882) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-05-04 13:44:56 UTC (rev 2883) @@ -24,22 +24,20 @@ import java.util.ArrayList; import java.util.List; import java.util.ListIterator; +import java.util.Properties; import javax.ejb.Stateless; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.AccountService; +import org.chorem.lima.business.AccountingRules; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountDAO; -import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryDAO; -import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.Identity; import org.chorem.lima.entity.IdentityDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; @@ -64,10 +62,11 @@ private TopiaContext rootContext; - protected FinancialTransactionServiceImpl financialTransactionService = new FinancialTransactionServiceImpl(); + protected FinancialTransactionServiceImpl financialTransactionService = + new FinancialTransactionServiceImpl(); - //private ConvertAccount convertAccount = new ConvertAccount(); - + protected AccountingRules accountingRules; + public AccountServiceImpl() { LimaConfig config = LimaConfig.getInstance(); try { @@ -77,13 +76,11 @@ log.error("Can't init topia context", ex); } } + accountingRules = config.getAccountingRules(); } /** * Permet de créer un nouveau compte dans le PCG de l'application. - * Il ne peut exister deux numéros identiques. Pour chaque nouveau compte, - * il est vérifié si il n'existe pas un compte avec le numéro donné. Dans ce - * cas présent, le compte n'est pas créé. * ATTENTION : le compte masterAccount, c'est à dire le compte père, doit * exister, sinon le compte n'est pas créé. Si le compte n'a pas de père, alors * mettre masterAccount à null. @@ -94,35 +91,9 @@ @Override public void createAccount(Account masterAccount, Account account) throws LimaException { - // Check if the numberaccount is not blank - if (StringUtils.isBlank(account.getAccountNumber())) { - throw new LimaBusinessException("Invalid AccountNumber : " - + account.getAccountNumber()); - } - - // Check if the number account is type numeric - if (!StringUtils.isNumeric(account.getAccountNumber())){ - throw new LimaBusinessException("AccountNumber is not numeric : " - + account.getAccountNumber()); - } + //check rules before create the account + accountingRules.createAccountRules(masterAccount, account); - // Check if the number account start with the number of the master account - // (specific to the french accountancy) - if (masterAccount!=null && !account.getAccountNumber().startsWith( - masterAccount.getAccountNumber())){ - - throw new LimaBusinessException("" + - "Account Number not begin with the number account master :" - + account.getAccountNumber()); - } - - // Check if master account have a number between 1 to 8 - if (masterAccount==null && !account.getAccountNumber().matches("[1-8]")){ - throw new LimaBusinessException( - "Master account is not a digit between 1 to 8 :" - + account.getAccountNumber()); - } - TopiaContext transaction = null; try { // basic check done, make check in database @@ -160,16 +131,16 @@ } } - + /** + * Permet de créer des comptes tiers + */ @Override public void createSubLedger(Account masterAccount, Account account, Identity identity) throws LimaException { - // check the number account is not empty - if (StringUtils.isBlank(account.getAccountNumber())) { - throw new LimaBusinessException("Invalid AccountNumber : " - + account.getAccountNumber()); - } + //check rules before create the account + accountingRules.createSubLedgerRules(masterAccount, account); + TopiaContext transaction = null; try { // basic check done, make check in database @@ -185,16 +156,9 @@ throw new LimaBusinessException(_( "An account already exists with this number : %s", account.getAccountNumber())); - } - - //check if parentaccount have no subaccount - if (masterAccount.getSubAccounts().size() > 0){ - throw new LimaBusinessException( - "Subledger must create on a account whithout subaccount : "); - } + } accountDAO.create(account); - IdentityDAO identityDAO = LimaCallaoDAOHelper.getIdentityDAO(transaction); @@ -218,239 +182,8 @@ } } - - /*public String createAccount (String accountNumber, String label,Account masterAccount,String type) - { - String result = ServiceHelper.RESPOND_ERROR; - // Détermine si le compte existe déjà ou non - boolean existAccount = existAccount(accountNumber); - // Si le numéro de compte existe - if (existAccount) - { - if (log.isWarnEnabled()) { - log.warn("Le compte numéro "+accountNumber+" existe deja !"); - } - result = ServiceHelper.ACCOUNT_DOUBLE; - } else { - // Création du compte - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaContext); - //Le compte a un père - if ( masterAccount != null ) - { - // Vérification que le compte père existe dans la base de données - boolean existMasterAccount = existAccount(masterAccount.getAccountNumber()); - // Si le compte père n'existe pas - if (!existMasterAccount) - { - if (log.isWarnEnabled()) { - log.warn("Le compte père numéro "+accountNumber+" n'existe pas !"); - } - result = ServiceHelper.ACCOUNT_NOT_MASTER; - } else { - // Creation du compte - Account newAccount = accountDAO.create(); - newAccount.setAccountNumber(accountNumber); - newAccount.setLabel(label); - newAccount.setMasterAccount(masterAccount); - newAccount.setType(type); - // Création BDD - topiaContext.commitTransaction(); - result = ServiceHelper.RESPOND_SUCCESS; - } - } else { - // Le compte n'a pas de père - // Creation du compte - Account newAccount = accountDAO.create(); - newAccount.setAccountNumber(accountNumber); - newAccount.setLabel(label); - newAccount.setType(type); - // Création BDD - topiaContext.commitTransaction(); - result = ServiceHelper.RESPOND_SUCCESS; - } - // Fermeture BDD - topiaContext.closeContext(); - }catch (TopiaException e) { - log.error(e); - } - } - return result; - }*/ - - - /* - * Permet de créer un compte à partir du numéro de compte père. Il appelle - * ensuite createAccount avec le compte père. - * @param accountNumber numéro du compte à créer - * @param label label pour le compte - * @param maserAccountNumber numéro du compte père, si il en a pas, mettre 0. - * @return - * - public String createAccount(String accountNumber, String label, - String masterAccountNumber, String type) { - String result = ServiceHelper.RESPOND_ERROR; - // Recherche le compte Master - Account masterAccount = searchAccount(masterAccountNumber); - // Si le compte père n'existe pas - if (masterAccount == null && !masterAccountNumber.equals("0")) { - if (log.isWarnEnabled()) { - log.warn("Le compte père numéro " + masterAccountNumber - + " n'existe pas !"); - } - result = ServiceHelper.ACCOUNT_NOT_MASTER; - } else { - // Création du compte - result = createAccount(accountNumber, label, masterAccount, type); - } - return result; - }*/ - - /* - * Permet de creer un compte à partir d'un objet DTO - * @param accountDTO compte au format DTO - * @return - * - public String createAccount(AccountDTO accountDTO) { - String result; - String result_final; - boolean error = false; // Si il y a eu une erreur pour créer les enfants - - // Création du compte père - result = createAccount(accountDTO.getAccountNumber(), accountDTO - .getLabel(), accountDTO.getMasterAccount(), accountDTO - .getType()); - // Création des comptes enfants - - // Pour chaque enfant - for (AccountDTO accountChildDTO : accountDTO.getAccountChildDTO()) { - // Création de l'enfant - result = createAccount(accountChildDTO); - // Si il y a eu une erreur - if (!result.equals(ServiceHelper.RESPOND_SUCCESS)) { - if (log.isWarnEnabled()) { - log.warn("Le compte numéro " + accountChildDTO.getLabel() - + " n'a pu être créé !"); - } - error = true; - result_final = result; - } - } - // Si il y a eu une erreur lors de la création d'un enfant, il est envoyé une erreur. - if (error) { - result = ServiceHelper.RESPOND_ERROR; - } - return result; - }*/ - - /* - * Recherche un compte DTO. Il est recherché dans la base de données et est - * converti avec ConvertAccount. ConvertAccount recherche dans la liste de - * ses enfants pour les convertir également, et ainsi de suite. - * @param accountNumber numéro du compte qu'on souhait rechercher - * @return - * - public AccountDTO searchAccountDTO(String accountNumber) { - AccountDTO accountDTO = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - AccountDAO accountDAO = LimaCallaoDAOHelper - .getAccountDAO(topiaContext); - // Recherche du compte - Account account = accountDAO.findByAccountNumber(accountNumber); - // Converti entity en DTO - convertAccount.setTransaction(topiaContext); - accountDTO = convertAccount.accountEntityToDto(account, null); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return accountDTO; - }*/ - - /* - * Permet de rechercher un compte à partir d'un numéro de compte. - * @param accountNumber numéro du compte à rechercher - * @return - * - public Account searchAccount(String accountNumber) { - Account accountResult = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - AccountDAO accountDAO = LimaCallaoDAOHelper - .getAccountDAO(topiaContext); - // Recherche du compte - accountResult = accountDAO.findByAccountNumber(accountNumber); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return accountResult; - }*/ - - /* - * Permet de renvoyer tous les enfants du compte. - * Cette fonction permet de renvoyer les enfants, mais PAS les enfants des - * enfants (et ainsi de suite). Cette méthode descend donc uniquement d'un - * niveau sur la hiérarchie. - * @param account compte dont on souhaite obtenir ses enfants. - * @return - * - public List<Account> searchListChildAccount(Account account) { - List<Account> ListAccount = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - AccountDAO accountDAO = LimaCallaoDAOHelper - .getAccountDAO(topiaContext); - // Recherche des comptes enfants - ListAccount = accountDAO.findAllByMasterAccount(account); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return ListAccount; - }*/ - - /* - * Permet de renvoyer tous les enfants du compte. Elle se base sur la fonction - * searchListChildAccount(Account account). - * Cette fonction permet de renvoyer les enfants, mais PAS les enfants des - * enfants (et ainsi de suite). Cette méthode descend donc uniquement d'un - * niveau sur la hiérarchie. - * @param account numéro de compte dont on souhaite obtenir ses enfants. - * @return - * - public List<Account> searchListChildAccount(String accountNumber) { - List<Account> ListAccount = null; - // Recherche le compte - Account account = searchAccount(accountNumber); - // Si le compte n'existe pas - if (account == null) { - if (log.isWarnEnabled()) { - log.warn("Le compte numéro " + accountNumber - + " n'existe pas !"); - } - } else { - // Recherche des comptes enfants - ListAccount = searchListChildAccount(account); - } - return ListAccount; - }*/ - /** * Permet de convertir tous les comptes. * @@ -470,11 +203,6 @@ LimaCallaoDAOHelper.getAccountDAO(transaction); List<Account> accounts = accountDAO.findAll(); accountsList.addAll(accounts); - for (Account account : accounts) { - for (Account subaccount : getChildrenAccounts(account)) { - - } - } } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -495,32 +223,6 @@ */ @Override public List<Account> getChildrenAccounts(Account masterAccount) throws LimaException { - /*ArrayList<AccountDTO> listAccountDTO = new ArrayList<AccountDTO>(); - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - AccountDAO accountDAO = LimaCallaoDAOHelper - .getAccountDAO(topiaContext); - // Recherche des comptes enfants - List<Account> listAccount = accountDAO.findAll(); - // Pour chaque compte - // Converti entity en DTO - convertAccount.setTransaction(topiaContext); - for (Account account : listAccount) { - // Pour les comptes sans père - if (account.getMasterAccount() == null) { - AccountDTO accountDTO = convertAccount.accountEntityToDto( - account, null); - listAccountDTO.add(accountDTO); - } - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return listAccountDTO;*/ List<Account> accountsList = new ArrayList<Account>(); @@ -540,10 +242,6 @@ query.add("masterAccount = :value or generalLedger = :value") .addParam("value", masterAccount); } - // TODO Erreur Lazy TopiaQuery - /*if (log.isDebugEnabled()) { - log.debug("getChildrenAccounts query : " + query); - }*/ accountsList.addAll(accountDAO.findAllByQuery(query)); } @@ -556,6 +254,7 @@ return accountsList; } + /** * Permet d'effacer un compte dans la base de données. @@ -569,30 +268,17 @@ */ @Override public void removeAccount(Account account) throws LimaException { - int result = 0; TopiaContext transaction = null; try { transaction = rootContext.beginTransaction(); - //Check if an account has not his number - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(transaction); - Entry firstEntry = entryDAO.findByAccount(account); + // Check rules + accountingRules.removeAccountRules(account, transaction); - if (firstEntry != null) { - throw new LimaBusinessException("Can't delete account with entries"); + //Check if the account have subaccount + if (account.getSubAccounts().size() > 0){ + removeAccountwithSubAccounts(account); } - - // Vérifie si une transaction n'appartient pas à ce compte. - //FIXME fonctionne pas - Entry entry = financialTransactionService.findByAccount(transaction, account); - if (entry != null) { - throw new LimaBusinessException("Can't delete Account with entries"); - } - - //Check if the account is not empty - if (account.getSubAccounts().size() > 0){ - throw new LimaBusinessException("Account not empty"); - } else { // remove account AccountDAO accountDAO = @@ -630,7 +316,7 @@ // remove account accountDAO.delete(account); // commit - transaction.commitTransaction(); + transaction.commitTransaction(); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -654,44 +340,6 @@ */ @Override public void updateAccount(Account account) throws LimaException { - /*String result = ServiceHelper.RESPOND_ERROR; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - AccountDAO accountDAO = LimaCallaoDAOHelper - .getAccountDAO(topiaContext); - // Recherche du compte - Account modifyAccount = accountDAO - .findByAccountNumber(accountNumber); - // Si le compte n'existe pas - if (modifyAccount == null) { - if (log.isWarnEnabled()) { - log.warn("Le compte numéro " + accountNumber - + " n'existe pas !"); - } - result = ServiceHelper.ACCOUNT_NOT_EXIST; - } else { - - // Modifie le compte - modifyAccount.setLabel(label); - modifyAccount.setType(type); - // Recherche du compte père - // Si il possède un compte père - if (masterAccount != null) { - modifyAccount.setMasterAccount(masterAccount); - } - modifyAccount.update(); - // Création BDD - topiaContext.commitTransaction(); - // Fermeture BDD - topiaContext.closeContext(); - result = ServiceHelper.RESPOND_SUCCESS; - } - } catch (TopiaException e) { - log.error(e); - } - return result;*/ TopiaContext transaction = null; try { @@ -718,97 +366,4 @@ throw new LimaException("Can't update account", ex); } } - - /* - * Permet de modifier un compte sur son label et son compte père. - * Il recherche le compte père avec le numéro de compte fourni. Appel ensuite - * la méthode modifyAccount avec pour paramètre le compte père trouvé. - * @param accountNumber numéro de compte à modifier - * @param label label à modifier - * @param masterAccountNumber le numéro du compte père - * @return - * - public String modifyAccount(String accountNumber, String label, - String type, String masterAccountNumber) { - String result = ServiceHelper.RESPOND_ERROR; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - AccountDAO accountDAO = LimaCallaoDAOHelper - .getAccountDAO(topiaContext); - - // Modifie le compte - // Recherche du compte père - Account masterAccount = accountDAO - .findByAccountNumber(masterAccountNumber); - result = modifyAccount(accountNumber, label, type, masterAccount); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return result; - }*/ - - /* - * Permet de modifier un compte à partir d'un compte DTO. - * @param accountDTO compte au format DTO qu'on souhaire modifier. - * @return - * - public String modifyAccount(AccountDTO accountDTO) { - String result = ServiceHelper.RESPOND_ERROR; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - AccountDAO accountDAO = LimaCallaoDAOHelper - .getAccountDAO(topiaContext); - // Recherche du compte père - Account masterAccount = accountDAO.findByAccountNumber(accountDTO - .getMasterAccount()); - result = modifyAccount(accountDTO.getAccountNumber(), accountDTO - .getLabel(), accountDTO.getType(), masterAccount); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return result; - }*/ - - /* - * Permet de mettre à jour le compte DTO ainsi que tous ses fils. - * Cette méthode permet d'ajouter, modifier, et supprimer un compte et - * ses enfants (et ainsi de suite). - * @param accountDTO - * @return - * - public String updateDTO(AccountDTO accountDTO) { - String result; - // Si le compte DTO père existe - if (existAccount(accountDTO.getAccountNumber())) { - // Modification du compte père - result = modifyAccount(accountDTO); - } else { - // Création du compte père - result = createAccount(accountDTO); - } - // Pour chaque enfant on lance l'update - for (AccountDTO accountChildDTO : accountDTO.getAccountChildDTO()) { - updateDTO(accountChildDTO); - } - - // On recherche les comptes DTO effacés - List<Account> listAccountChild = searchListChildAccount(accountDTO - .getAccountNumber()); - for (Account account : listAccountChild) { - // Si le compte n'est pas dans la liste, alors on efface - if (!accountDTO.existAccountChild(account.getAccountNumber())) { - result = removeAccount(account.getAccountNumber()); - } - } - return result; - }*/ - } \ No newline at end of file Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-05-04 13:22:41 UTC (rev 2882) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-05-04 13:44:56 UTC (rev 2883) @@ -28,6 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.AccountingRules; import org.chorem.lima.business.EntryBookService; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; @@ -59,8 +60,9 @@ protected FinancialTransactionServiceImpl financialTransactionService = new FinancialTransactionServiceImpl(); - //private ConvertEntryBook convertEntryBook = new ConvertEntryBook(); + protected AccountingRules accountingRules; + public EntryBookServiceImpl() { LimaConfig config = LimaConfig.getInstance(); try { @@ -70,6 +72,7 @@ log.error("Can't init topia context", ex); } } + accountingRules = config.getAccountingRules(); } /** @@ -79,40 +82,6 @@ * @throws LimaException */ public void createEntryBook(EntryBook entryBook) throws LimaException { - /*String result = ServiceHelper.RESPOND_ERROR; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper - .getEntryBookDAO(topiaContext); - - // Si on souhaite avoir un EntryBook unique avec son label - - EntryBook EntryBook = searchEntryBookWithLabel(label); - // Si un EntryBook existe déjà avec ce label - if (EntryBook != null) { - if (log.isWarnEnabled()) { - log.warn("Un EntryBook avec le label " + label - + " existe déjà !"); - } - result = ServiceHelper.EntryBook_DOUBLE; - } else { - // Creation du EntryBook - EntryBook newEntryBook = EntryBookDAO.create(); - newEntryBook.setLabel(label); - newEntryBook.setPrefix(prefix); - newEntryBook.setDescription(description); - // Création BDD - topiaContext.commitTransaction(); - result = ServiceHelper.RESPOND_SUCCESS; - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return result;*/ TopiaContext transaction = null; try { @@ -120,11 +89,15 @@ // TODO move it into JTA transaction = rootContext.beginTransaction(); - // test si un EntryBook de ce nom existe deja - EntryBookDAO entryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(transaction); - EntryBook existingEntryBook = entryBookDAO.findByLabel(entryBook.getLabel()); + // check if entrybook with is name already exist + EntryBookDAO entryBookDAO = + LimaCallaoDAOHelper.getEntryBookDAO(transaction); + EntryBook existingEntryBook = + entryBookDAO.findByLabel(entryBook.getLabel()); if (existingEntryBook != null) { - throw new LimaBusinessException(_("An EntryBook already exists with this label : %s", entryBook.getLabel())); + throw new LimaBusinessException( + _("An EntryBook already exists with this label : %s", + entryBook.getLabel())); } // creation du EntryBook @@ -141,31 +114,10 @@ } } + /** + * return all entrybook + */ public List<EntryBook> getAllEntryBooks() throws LimaException { - /*List<EntryBookDTO> listEntryBookDTO = new ArrayList<EntryBookDTO>(); - - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper - .getEntryBookDAO(topiaContext); - // Creation du EntryBook - List<EntryBook> listEntryBook = EntryBookDAO.findAll(); - // Pour chaque EntryBook, on le transforme en DTO - for (EntryBook EntryBook : listEntryBook) { - // Converti en DTO - EntryBookDTO EntryBookDTO = convertEntryBook - .EntryBookEntityToDto(EntryBook); - // Ajoute à la liste - listEntryBookDTO.add(EntryBookDTO); - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return listEntryBookDTO;*/ List<EntryBook> EntryBooksList = new ArrayList<EntryBook>(); TopiaContext transaction = null; @@ -174,7 +126,7 @@ // TODO move it into JTA transaction = rootContext.beginTransaction(); - // test si un EntryBook de ce nom existe deja + // check if entrybook with is name already exist EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(transaction); List<EntryBook> EntryBooks = EntryBookDAO.findAll(); EntryBooksList.addAll(EntryBooks); @@ -192,78 +144,6 @@ return EntryBooksList; } - /* - * Permet de rechercher un EntryBook existant à partir de son label. - * ATTENTION : il est possible que plusieurs journaux existent avec ce - * même label. La méthode renvoie le premier trouvé. - * @param prefix préfixe du EntryBook recherché - * @return - * - public EntryBook searchEntryBookWithLabel(String label) { - EntryBook EntryBookResult = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper - .getEntryBookDAO(topiaContext); - // Creation du EntryBook - EntryBookResult = EntryBookDAO.findByLabel(label); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return EntryBookResult; - }*/ - - /* - * Permet de rechercher un EntryBook existant à partir du label. - * Le EntryBook recherché est converti automatiquement en format DTO. - * @param prefix préfixe du EntryBook recherché - * @return - * - public EntryBookDTO searchEntryBookDTOWithLabel(String label) { - EntryBook EntryBook = searchEntryBookWithLabel(label); - EntryBookDTO EntryBookDTO = convertEntryBook.EntryBookEntityToDto(EntryBook); - return EntryBookDTO; - }*/ - - /* - * Permet de rechercher un EntryBook unique identifé par son topiaId. - * @param topiaId identifiant du EntryBook recherché - * @return - * - public EntryBook searchEntryBookWithTopiaId(String topiaId) { - EntryBook EntryBookResult = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper - .getEntryBookDAO(topiaContext); - // Creation du EntryBook - EntryBookResult = EntryBookDAO.findByTopiaId(topiaId); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return EntryBookResult; - }*/ - - /* - * Permet de rechercher un EntryBook existant à partir du topiaId. - * Le EntryBook recherché est converti automatiquement en format DTO. - * @param prefix préfixe du EntryBook recherché - * @return - * - public EntryBookDTO searchEntryBookDTOWithTopiaId(String topiaId) { - EntryBook EntryBook = searchEntryBookWithTopiaId(topiaId); - EntryBookDTO EntryBookDTO = convertEntryBook.EntryBookEntityToDto(EntryBook); - return EntryBookDTO; - }*/ - /** * Permet de modifier un journal. * @@ -296,11 +176,10 @@ /** * Permet d'effacer un EntryBook dans la base de données. * - * ATTENTION : si un EntryBook est associé avec des transactions, il est alors + * ATTENTION : si un EntryBook est associé avec des entrées, il est alors * impossible de supprimer celui-ci. * * @param prefix préfixe du EntryBook à supprimer - * @return * @throws LimaException */ public void removeEntryBook(EntryBook entryBook) throws LimaException { @@ -311,13 +190,10 @@ // TODO move it into JTA topiaTransaction = rootContext.beginTransaction(); - // Vérifie si une transaction n'appartient pas à ce EntryBook. - FinancialTransaction financialtransaction = financialTransactionService.findByEntryBook(topiaTransaction, entryBook); - if (financialtransaction != null) { - throw new LimaBusinessException("Can't delete EntryBook with transactions"); - } - - // test si un EntryBook de ce nom existe deja + //check + accountingRules.removeEntryBookRules(entryBook, topiaTransaction); + + //delete EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(topiaTransaction); EntryBookDAO.delete(entryBook); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-05-04 13:22:41 UTC (rev 2882) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-05-04 13:44:56 UTC (rev 2883) @@ -19,6 +19,8 @@ package org.chorem.lima.business.ejb; +import java.util.ArrayList; +import java.util.Date; import java.util.List; import javax.ejb.Stateless; import org.apache.commons.logging.Log; @@ -26,13 +28,17 @@ import org.chorem.lima.business.FinancialPeriodService; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.AccountDAO; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialPeriodDAO; +import org.chorem.lima.entity.FinancialPeriodImpl; 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; /** @@ -45,7 +51,8 @@ public class FinancialPeriodServiceImpl extends AbstractLimaService implements FinancialPeriodService { /** log */ - private static final Log log = LogFactory.getLog(FinancialPeriodServiceImpl.class); + private static final Log log = + LogFactory.getLog(FinancialPeriodServiceImpl.class); private TopiaContext rootContext; @@ -62,53 +69,11 @@ /** * Création d'une période timeSpan mensuelle avec une date de début et de fin. Une période - * peut être bloquée ou non. - * @param beginTimeSpan date de début de période - * @param endTimeSpan date de fin de période - * @param locked est à vrai si la période doit être bloquée. + * peut être bloquée ou non * @return */ @Override - public void createFinancialPeriod(FinancialPeriod financialPeriod /*Date beginTimeSpan, Date endTimeSpan, - Period period, boolean locked*/) throws LimaException { -/* - // timeSpan correspond à une période mensuelle. - // La fonction va donc prendre seulement pour date de référence la - // date beginTimeSpan. Elle calcule automatiquement la date de fin - // suivant le mois. - DateUtil dateutil = new DateUtil(); - // Initialise la date de début au premier du mois - beginTimeSpan = dateutil.InitDateFirstDayMonth(beginTimeSpan); - // Initialise la date de fin au dernier du mois - endTimeSpan = dateutil.InitDateEndDayMonth(beginTimeSpan); - if (log.isInfoEnabled()) { - log.info("Nouveau timeSpan du " + beginTimeSpan.toString() + " au " - + endTimeSpan.toString()); - } - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Creation du timespan - TimeSpan newtimeSpan = timeSpanDAO.create(); - newtimeSpan.setBeginTimeSpan(beginTimeSpan); - newtimeSpan.setEndTimeSpan(endTimeSpan); - newtimeSpan.setLocked(locked); - newtimeSpan.setPeriod(period); - // Création BDD - topiaContext.commitTransaction(); - // Fermeture BDD - topiaContext.closeContext(); - if (log.isInfoEnabled()) { - log.info("Ajout avec succes du timeSpan"); - } - return ServiceHelper.RESPOND_SUCCESS; - } catch (TopiaException e) { - log.error(e); - return ServiceHelper.RESPOND_ERROR; - }*/ + public void createFinancialPeriod(FinancialPeriod financialPeriod) throws LimaException { TopiaContext transaction = null; try { @@ -116,7 +81,9 @@ // TODO move it into JTA transaction = rootContext.beginTransaction(); - createFinancialPeriod(transaction, financialPeriod); + FinancialPeriodDAO financialPeriodDAO = + LimaCallaoDAOHelper.getFinancialPeriodDAO(transaction); + financialPeriodDAO.create(financialPeriod); // commit transaction.commitTransaction(); @@ -130,19 +97,8 @@ } /** - * Create a financial period with an opened transaction. - * - * @param transaction opened transaction - * @param financialPeriod financial period - * @throws TopiaException + * Return all financial periods */ - protected void createFinancialPeriod(TopiaContext transaction, FinancialPeriod financialPeriod) throws TopiaException { - - FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper.getFinancialPeriodDAO(transaction); - financialPeriodDAO.create(financialPeriod); - - } - @Override public List<FinancialPeriod> getAllFinancialPeriods() throws LimaException { @@ -154,7 +110,8 @@ // TODO move it into JTA transaction = rootContext.beginTransaction(); - FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper.getFinancialPeriodDAO(transaction); + FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper. + getFinancialPeriodDAO(transaction); result = financialPeriodDAO.findAll(); // commit @@ -170,6 +127,9 @@ return result; } + /** + * Return all unblocked financial period + */ @Override public List<FinancialPeriod> getUnblockedFinancialPeriods() throws LimaException { @@ -181,7 +141,8 @@ // TODO move it into JTA transaction = rootContext.beginTransaction(); - FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper.getFinancialPeriodDAO(transaction); + FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper. + getFinancialPeriodDAO(transaction); result = financialPeriodDAO.findAllByLocked(false); // commit @@ -196,433 +157,34 @@ return result; } - - /* - * Permet de trouver un timespan directement avec une date. La date peut - * être quelconque. Exemple : d = 17 sept 2000, renvoie la période du - * 1 sept au 30 sept 2000. - * @param d - * @return - * - public TimeSpan searchTimeSpanByDate(Date d) { - TimeSpan timeSpan = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Par précaution, on initialise la date au debut du mois - DateUtil dateutil = new DateUtil(); - // Recherche du timeSpan - Date searchDate = dateutil.InitDateFirstDayMonth(d); - timeSpan = timeSpanDAO.findByBeginTimeSpan(searchDate); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return timeSpan; - }*/ - /* - * Recherche un timeSpan précis, avec sa date de création. - * @param timeSpanDTO timeSpan au format DTO qu'on recherche - * @return - * - public TimeSpan searchTimeSpanByDate(TimeSpanDTO timeSpanDTO) { - TimeSpan timeSpan = searchTimeSpanByDate(timeSpanDTO.getBeginTimeSpan()); - return timeSpan; - }*/ + @Override + public FinancialPeriod getFinancialPeriodWithDate(Date date) throws LimaException { - /* - * Recherche un timeSpan UNIQUE. Celui est identifié par son topiaId. - * @param topiaId Identifiant du timeSpan recherché - * @return - * - public TimeSpan searchTimeSpanWithTopiaId(String topiaId) { - TimeSpan timeSpan = null; + FinancialPeriod financialPeriod= new FinancialPeriodImpl(); + + TopiaContext transaction = null; try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Recherche du timeSpan - timeSpan = timeSpanDAO.findByTopiaId(topiaId); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return timeSpan; - }*/ + transaction = rootContext.beginTransaction(); - /* - * Permet de rechercher un timeSpan à l'aide d'une date. Il fait appel - * à la méthode searchTimeSpanByDate. - * La méthode renvoie un objet DTO. - * @param d - * @return - * - public TimeSpanDTO searchTimeSpanDTOByDate(Date d) { - TimeSpan timeSpan = searchTimeSpanByDate(d); - TimeSpanDTO timeSpanDTO = convertTimeSpan.timeSpanEntityToDto(timeSpan); - return timeSpanDTO; - }*/ + FinancialPeriodDAO financialPeriodDAO = + LimaCallaoDAOHelper.getFinancialPeriodDAO(transaction); - /* - * Permet de faire une recherche de tous les timeSpans d'une période. - * @param period - * @return - * - public List<TimeSpan> searchListTimeSpan(Period period) { - List<TimeSpan> listTimeSpan = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Recherche les timeSpans avec cette période - listTimeSpan = timeSpanDAO.findAllByPeriod(period); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return listTimeSpan; - }*/ - - /* - * Permet de rechercher tous les timeSpans suivant une période donnée. - * Chaque timeSpan est converti ensuite en DTO. - * @param period - * @return - * - public List<TimeSpanDTO> searchListTimeSpanDTO(Period period) { - List<TimeSpanDTO> listTimeSpanDTO = new ArrayList<TimeSpanDTO>(); - List<TimeSpan> listTimeSpan = searchListTimeSpan(period); - for (TimeSpan timeSpan : listTimeSpan) { - TimeSpanDTO timeSpanDTO = convertTimeSpan - .timeSpanEntityToDto(timeSpan); - listTimeSpanDTO.add(timeSpanDTO); - } - return listTimeSpanDTO; - }*/ - - /* - * Permet de bloquer un timespan, celle-ci ne doit pas être bloquée. - * La fonction doit s'assurer que les timeSpans précédents doivent être - * bloqués. - * Les transactions doivent être équilibrées - * @param timespan période qui doit être fermée - * @param period période (12 smois) - * - public String blockTimeSpan(TimeSpan timespan) { - String result = ServiceHelper.RESPOND_ERROR; - // Si la période n'est pas déjà fermée. - if (timespan.getLocked()) { - if (log.isInfoEnabled()) { - log.info("Timespan deja bloqué !"); + TopiaQuery query = financialPeriodDAO.createQuery(); + if (date != null){ + query.add("beginDate = :value").addParam("value", date); } - } else { - Period period = getPeriodWithTimeSpan(timespan); - if (period.getLocked()) { - if (log.isErrorEnabled()) { - log.error("La période du timespan est bloquée !"); - } - } else { - // Vérifie si tous les timeSpans précédents sont bloqués - boolean AllTimeSpanBlock = alltimeSpanBlocked(timespan, period); - if (AllTimeSpanBlock) { - // Enregistrement dans la base de données - try { - // Acces BDD - TopiaContext topiaContext = rootContext - .beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - - // Vérifie si les transactons sont équilibrées - List<Transaction> listTransaction = transactionServiceImpl - .searchListTransactionWithTimeSpan(timespan); - boolean isTransactionBalanced = true; - boolean existTransactionNotBalanced = false; - for (Transaction transaction : listTransaction) { - isTransactionBalanced = transactionServiceImpl - .isTransactionBalanced(transaction); - if (!isTransactionBalanced) { - if (log.isInfoEnabled()) { - log.info("La transaction n'est pas bloquée."); - } - existTransactionNotBalanced = true; - } - } - if (!existTransactionNotBalanced) { - // Bloque la période - timespan.setLocked(true); - // Mise à jour de timespan dans la BDD - timeSpanDAO.update(timespan); - // Création BDD - topiaContext.commitTransaction(); - if (log.isInfoEnabled()) { - log.info("Timespan bloqué avec succès"); - } - result = ServiceHelper.RESPOND_SUCCESS; - } else { - result = ServiceHelper.TRANSACTION_NOT_BALANCED; - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - } else { - if (log.isErrorEnabled()) { - log.error("Il existe un ou plusieurs timespans précédents" - + " non bloqués."); - } - result = ServiceHelper.TIMESPAN_PREC_NOT_BLOCK; - } - } + financialPeriod = financialPeriodDAO.findByQuery(query); } - return result; - }*/ - - /* - * Permet de bloquer une période au format DTO. - * - * @param timespanDTO - * @return - * - public String blockTimeSpan(TimeSpanDTO timespanDTO) { - return blockTimeSpan(searchTimeSpanByDate(timespanDTO)); - }*/ - - /* - * Permet de débloquer un timespan, à condition que les timespans suivants - * celui-ci soient bien débloqués. - * @param timespan - * @param period - * @return - * - public String unblockTimeSpan(TimeSpan timespan) { - String result = ServiceHelper.RESPOND_ERROR; - // Si le timspan n'est pas bloqué - if (!timespan.getLocked()) { - if (log.isWarnEnabled()) { - log.warn("Timespan non bloqué !"); - } - } else { - Period period = getPeriodWithTimeSpan(timespan); - if (period.getLocked()) { - if (log.isErrorEnabled()) { - log.error("La période du timespan est bloquée !"); - } - } else { - boolean NextTimeSpanUnblock = nextTimeSpanUnblock(timespan, - period); - // Si aucun timespan suivant bloqué - if (NextTimeSpanUnblock) { - try { - // Acces BDD - TopiaContext topiaContext = rootContext - .beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // débloque la période - timespan.setLocked(false); - // Mise à jour de timespan dans la BDD - timeSpanDAO.update(timespan); - // Création BDD - topiaContext.commitTransaction(); - if (log.isInfoEnabled()) { - log.info("Timespan débloqué avec succès"); - } - result = ServiceHelper.RESPOND_SUCCESS; - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - } else { - result = ServiceHelper.TIMESPAN_NEXT_NOT_BLOCK; - } - } + catch (TopiaException ex) { + doCatch(transaction, ex, log); } - return result; - }*/ - - /* - * Permet de bloquer une période au format DTO. - * - * @param timespanDTO - * @return - * - public String unblockTimeSpan(TimeSpanDTO timespanDTO) { - return unblockTimeSpan(searchTimeSpanByDate(timespanDTO)); - }*/ - - /* - * Cette méthode va rechercher tous les timeSpans non bloqués après - * le timeSpan renseigné en paramètre. - * Si elle trouve au moins un timeSpan NON bloqué, elle renvoie alors faux. - * Cette méthode permet essentiellement de définir si il est possible - * ou non de bloquer un timeSpan. A savoir, un timeSpan ne peut être bloqué, - * si il existe des timeSpans suivant (dans le calendrier) qui sont non - * bloqués. - * @param timespan - * @param period - * @return - * - private boolean nextTimeSpanUnblock(TimeSpan timespan, Period period) { - boolean NextTimeSpanUnblock = false; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Recherche des TimeSpans avec la même période. - // (on doit récupérer normalement 12 timeSpans) - List<TimeSpan> listeTimeSpanOfPeriod = timeSpanDAO - .findAllByPeriod(period); - NextTimeSpanUnblock = true; - for (TimeSpan timeSpanNext : listeTimeSpanOfPeriod) { - // Si le timespan est après celui qu'on souhaite bloquer ET est non bloqué - if (timeSpanNext.getBeginTimeSpan().compareTo( - timespan.getBeginTimeSpan()) == 1 - && timeSpanNext.getLocked()) { - NextTimeSpanUnblock = false; - if (log.isInfoEnabled()) { - log.info("Timespan " + timeSpanNext.toString() - + " est bloqué"); - } - } - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); + finally { + doFinally(transaction, log); } - return NextTimeSpanUnblock; - }*/ - - /* - * Permet de renvoyer une période dont appartient le timeSpan. - * @param timeSpan timeSpan dont on souhaite retourner la période - * @return - * - private Period getPeriodWithTimeSpan(TimeSpan timeSpan) { - PeriodServiceImpl periodServiceImpl = new PeriodServiceImpl(); - Date beginTimeSpan = timeSpan.getBeginTimeSpan(); - Period period = periodServiceImpl.searchPeriodWithDate(beginTimeSpan); - return period; - }*/ - - /* - * Cette méthode renvoie vrai lorsque tous les timespans de la période - * précédent au timespan en paramètre sont bloqués. - * @param timespan - * @param period le paramètre period est important, en effet un timespan ne - * peut être indépendant. - * @return - * - private boolean alltimeSpanBlocked(TimeSpan timespan, Period period) { - boolean AllTimeSpanBlock = false; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Recherche des TimeSpans avec la même période. - // (on doit récupérer normalement 12 timeSpans) - List<TimeSpan> listeTimeSpanOfPeriod = timeSpanDAO - .findAllByPeriod(period); - // Fermeture BDD - topiaContext.closeContext(); - // On contrôle que les timeSpans précédents sont bloqués. - AllTimeSpanBlock = true; - for (TimeSpan timeSpanPrev : listeTimeSpanOfPeriod) { - // Si la période est avant celle qu'on souhaite bloquer ET est non bloquée - if (timeSpanPrev.getBeginTimeSpan().compareTo( - timespan.getBeginTimeSpan()) == -1 - && !timeSpanPrev.getLocked()) { - AllTimeSpanBlock = false; - if (log.isInfoEnabled()) { - log.info("Timespan " + timeSpanPrev.toString() - + " non bloqué"); - } - } - } - } catch (TopiaException e) { - log.error(e); + + return financialPeriod; } - return AllTimeSpanBlock; - }*/ - - /* - * Permet d'effacer un timeSpan. Ce dernier ne doit pas être bloqué. - * @param timeSpan - * @return - * - public String removeTimeSpan(TimeSpan timeSpan) { - String result = ServiceHelper.RESPOND_ERROR; - // Si le timspan est bloqué - if (timeSpan.getLocked()) { - if (log.isWarnEnabled()) { - log.warn("Timespan bloqué !"); - } - } else { - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Mise à jour de timespan dans la BDD - timeSpanDAO.delete(timeSpan); - // Création BDD - topiaContext.commitTransaction(); - if (log.isInfoEnabled()) { - log.info("Timespan supprimé avec succès"); - } - result = ServiceHelper.RESPOND_SUCCESS; - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - } - return result; - }*/ - - /* - * Vérifie si le timeSpan donné en paramètre est bloqué ou non. - * @param timeSpan - * @return - * - public boolean isTimeSpanBlocked(TimeSpan timeSpan) { - boolean isTimeSpanBlocked = true; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Mise à jour de timespan dans la BDD - TimeSpan timeSpanSearch = timeSpanDAO.findByTopiaId(timeSpan - .getTopiaId()); - isTimeSpanBlocked = timeSpanSearch.getLocked(); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return isTimeSpanBlocked; - }*/ + + } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2010-05-04 13:22:41 UTC (rev 2882) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2010-05-04 13:44:56 UTC (rev 2883) @@ -21,25 +21,21 @@ import static org.nuiton.i18n.I18n._; -import java.util.Calendar; -import java.util.Date; -import java.util.Iterator; +import java.util.Collection; import java.util.List; -import java.util.ListIterator; 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.FiscalPeriodService; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.AccountDAO; + import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialPeriodDAO; -import org.chorem.lima.entity.FinancialPeriodImpl; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FiscalPeriodDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; @@ -47,12 +43,8 @@ import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; -import org.nuiton.topia.framework.TopiaContextImpl; -import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.topia.framework.TopiaQuery; import org.nuiton.topia.framework.TopiaQuery.Op; -import org.nuiton.topia.persistence.TopiaEntity; -import org.apache.commons.lang.time.DateUtils; /** * Gestion des exercices. @@ -69,6 +61,8 @@ private FinancialPeriodServiceImpl financialPeriodService = new FinancialPeriodServiceImpl(); + + protected AccountingRules accountingRules; public FiscalPeriodServiceImpl() { LimaConfig config = LimaConfig.getInstance(); @@ -79,169 +73,28 @@ log.error("Can't init topia context", ex); } } + accountingRules = config.getAccountingRules(); } /** - * Permet de créer un exercice. - * - * Elle a une durée de un an, composées de 12 périodes mensuelles. - * Elle peut aussi être plus courte ou plus longue si l'entreprise - * se constitu ou entre en liquidation ou que l'entreprise decide - * de changer - * - * Elle correspond à l'exercice comptable. - * Pour créer une nouvelle période, la précédente doit être obligatoirement clôturée. - * - * @param beginTimeSpan date début de période - * @param endTimeSpan date fin de période - * @param lock Vrai si la période est bloquée - * @return + * To create a fiscalperiod + * Check localized rules before create */ @Override - public void createFiscalPeriod(FiscalPeriod fiscalPeriod /*Date beginTimeSpan, Date endTimeSpan, boolean lock*/) throws LimaException { - - /*// Par défaut lock est à false - lock = false; - String result = ServiceHelper.RESPOND_ERROR; - - try { - boolean correctPeriod = false; - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - // Creation de la periodDate - PeriodDates newPeriod = new PeriodDates(beginTimeSpan, endTimeSpan); - - // Creation de la période - Period period = periodDAO.create(); - period.setBeginPeriod(newPeriod.getFromDate()); - period.setEndPeriod(newPeriod.getThruDate()); - period.setLocked(lock); - // Vérification si la période est correcte - correctPeriod = isCorrectPeriod(period); - if (correctPeriod) { - // Si elle est correcte : Création BDD - topiaContext.commitTransaction(); - if (log.isInfoEnabled()) { - log.info("Ajout exercice du " + beginTimeSpan.toString() - + " au " + endTimeSpan.toString()); - } - - //Ajout des timeSpans mensuels - //Par défaut, il prend seulement la date beginTimeSpan, et calcule - //la date de fin, c'est pourquoi il est laissé deux fois "beginTimeSpan" - TimeSpanServiceImpl timeSpanImpl = new TimeSpanServiceImpl(); - boolean stop = false; // En cas d'erreur lors de la création d'un timeSpan. - - List<Date> monthList = newPeriod.getMonths(); - - int max = monthList.size(); - log.debug("la periode fait:" + max); - for (int i = 0; i < max; i++) { - // Création timeSpan - result = timeSpanImpl.createTimeSpan(monthList.get(i), - monthList.get(i), period, false); - if (result.equals(ServiceHelper.RESPOND_ERROR)) { - stop = true; - if (log.isErrorEnabled()) { - log.error("Erreur lors de la création des " + max - + " timeSpans"); - } - result = ServiceHelper.PERIOD_CREATE_TIMESPANS; - } - // Supprimer la periode si stop = true - } - if (stop == false) { - result = ServiceHelper.RESPOND_SUCCESS; - } - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return result; */ - - // un exercice ne peut pas faire plus de 24 mois dans tous les cas - - // un exercice doit faire au moins une période - /*if ( fiscalPeriod.getFinancialPeriod() == null || - fiscalPeriod.getFinancialPeriod().isEmpty()) { - throw new LimaBusinessException(_("A fiscal period must have at least one financial period !")); - }*/ - - // un exercice doit être collé au precedent - - // un exercice ne peut être crée que si l'ante precedent est fermé - // on peut creer un exercice si le precedent n'est pas fermé - boolean valid=false; + public void createFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException { + TopiaContext transaction = null; try { - // basic check done, make check in database // TODO move it into JTA transaction = rootContext.beginTransaction(); + + //check rules before create the account + accountingRules.createFiscalPeriodRules(fiscalPeriod, transaction); + FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); - //check if the enddate period is after the begindate period - if (fiscalPeriod.getEndDate().before(fiscalPeriod.getBeginDate())){ - //TODO Exception - throw new LimaBusinessException( - "The enddate is before the begindate"); - } - - //Checks if is not the first fiscalperiod to create - if (fiscalPeriodDAO.findAll().size()!=0){ - - TopiaQuery query = fiscalPeriodDAO.createQuery(); - fiscalPeriodDAO.findAllByQuery(query); - query.addOrderDesc(FiscalPeriod.END_DATE); - - //get the last fiscal period - FiscalPeriod lastFiscalPeriod = fiscalPeriodDAO.findByQuery(query); - log.debug("lastFiscalPeriod : "+lastFiscalPeriod); - - //check the new fiscal period adjoining the last - Date dateLastFiscalPeriod=lastFiscalPeriod.getEndDate(); - dateLastFiscalPeriod = DateUtils. - addMilliseconds(dateLastFiscalPeriod, 1); - Date dateFiscalPeriod=fiscalPeriod.getBeginDate(); - if(dateLastFiscalPeriod.compareTo(dateFiscalPeriod)!=0){ - throw new LimaBusinessException( - "The new fiscalperiod must adjoining the last"); - } - - - //We can create a new fiscal period meantime the last fiscal period was not locked - //But not the ante periodfiscal - int unblockedFiscalPeriod = - fiscalPeriodDAO.findAllByLocked(false).size(); - log.debug(unblockedFiscalPeriod); - if (unblockedFiscalPeriod>1){ - throw new LimaBusinessException( - "The ante fiscal period is not locked"); - } - } - - Date beginDate = fiscalPeriod.getBeginDate(); - Date endDate = fiscalPeriod.getEndDate(); - - // FinancialPeriod of 1 month are created - Date loopDate = beginDate; - while (loopDate.compareTo(endDate) <= 0) { - Date loopUpperDate = DateUtils.addMonths(loopDate, 1); - Date periodEndDate = DateUtils.addMilliseconds(loopUpperDate, -1); - FinancialPeriod financialPeriod = new FinancialPeriodImpl(); - financialPeriod.setBeginDate(loopDate); - financialPeriod.setEndDate(periodEndDate); - fiscalPeriod.addFinancialPeriod(financialPeriod); - loopDate = loopUpperDate; - log.debug("financialPeriod : "+financialPeriod); - financialPeriodService.createFinancialPeriod(financialPeriod); - } //create fiscalPeriodDAO.create(fiscalPeriod); @@ -257,6 +110,9 @@ } + /** + * return all fiscal period + */ public List<FiscalPeriod> getAllFiscalPeriods() throws LimaException { List<FiscalPeriod> result = null; @@ -284,6 +140,9 @@ return result; } + /** + * return all unblocked fiscal periods + */ public List<FiscalPeriod> getAllUnblockedFiscalPeriods() throws LimaException { List<FiscalPeriod> result = null; @@ -300,7 +159,8 @@ //IMPORTANT : LOADING FINANCIAL PERIOD FOR NO LAZY EXCEPTION for (FiscalPeriod fiscalPeriod : result) { - //FIXME besoin d'appeler une lecture bidon de toutes les financialperiod sinon il pete tout de même une lazy exception + //FIXME besoin d'appeler une lecture bidon de toutes les financialperiod + //sinon il pete tout de même une lazy exception for (FinancialPeriod financialPeriod : fiscalPeriod.getFinancialPeriod()) { } } @@ -318,48 +178,53 @@ return result; } + /** + * to block a fiscal period + * + * check localized rules before block it + * + * Two transaction are necessary for no object conflict + * FIXME can found best solution ?! + */ @Override public void blockFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException { TopiaContext transaction = null; + + //open transaction for check try { transaction = rootContext.beginTransaction(); if (fiscalPeriod.getLocked()==true){ throw new LimaBusinessException("Fiscal Period already blocked"); } + //check rules + accountingRules.blockFiscalPeriodRules(fiscalPeriod, transaction); - //TODO verifier que les exercices anterieur a l'exerice à bloquer sont bloqués - FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + } catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } - TopiaQuery query = fiscalPeriodDAO.createQuery(); - fiscalPeriodDAO.findAllByQuery(query); - query.add(FiscalPeriod.LOCKED, Op.EQ, false); - query.addOrder(FiscalPeriod.END_DATE); - // query.add(TopiaEntity.TOPIA_ID, fiscalPeriod.getTopiaId()); - //int oldestblocked = query.executeCount(); + //open transaction for update + try { + transaction = rootContext.beginTransaction(); - FiscalPeriod oldestUnBlockedFiscalPeriod = fiscalPeriodDAO.findByQuery(query); - //log.debug("oldestUnBlockedFiscalPeriod : "+oldestUnBlockedFiscalPeriod); + FiscalPeriodDAO fiscalPeriodDAO = + LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); - //Check if the fiscal period to block is the oldest - if (!oldestUnBlockedFiscalPeriod.equals(fiscalPeriod)){ - throw new LimaBusinessException("The ante fiscal period must be blocked before this."); - } - - oldestUnBlockedFiscalPeriod.setLocked(true); - + // lock fiscalperiod + fiscalPeriod.setLocked(true); // locked all financialperiod of the fiscalperiod - for ( FinancialPeriod financialPeriod : oldestUnBlockedFiscalPeriod.getFinancialPeriod()) { + for ( FinancialPeriod financialPeriod : fiscalPeriod.getFinancialPeriod()) { + log.debug(financialPeriod); financialPeriod.setLocked(true); + log.debug(financialPeriod); } + fiscalPeriodDAO.update(fiscalPeriod); - /* //FIXME JP 23/04/2010 code à changer pour ne pas dépendre de l'impl - TopiaContextImpl topiaContextImpl = (TopiaContextImpl) transaction; - topiaContextImpl.getHibernate().evict(oldestUnBlockedFiscalPeriod);*/ - // update account - fiscalPeriodDAO.update(oldestUnBlockedFiscalPeriod); - // commit transaction.commitTransaction(); @@ -371,6 +236,10 @@ } } + /** + * just for debug, this method must delete + * Unauthorized action for user !!! + */ public void removeAllFiscalPeriods() throws LimaException{ TopiaContext transaction = null; try { @@ -397,378 +266,4 @@ doFinally(transaction, log); } } - - /* - * Permet de créer une période à partir d'une période DTO. - * @param periodDTO période à créer au format DTO. - * @return - * - public String createPeriod(PeriodDTO periodDTO) { - String result = createPeriod(periodDTO.getBeginPeriod(), periodDTO - .getEndPeriod(), false); - // Tous les timeSpans sont automatiquement créés avec la méthode createPeriod - return result; - }*/ - - /* - * Permet de vérifier si la période est correcte (aucun chevauchement avec - * les autres périodes, période(s) précédente(s) bloquée(s), formée de 1 à 24 - * mois). - * @param period période à tester si elle est correcte - * @return - * - private boolean isCorrectPeriod(Period period) { - // Calcul du nombre de mois pour que la période soit valide (12 mois) - int number_months = dateUtil.numberOfMonths(period.getBeginPeriod(), - period.getEndPeriod()); - boolean result = true; - - if (number_months == 0 && number_months >= 24) // Periode de 1mois a 24 mois - { - if (log.isErrorEnabled()) { - log.error("Période du " - + period.getBeginPeriod() - + " au " - + period.getEndPeriod() - + " : L'exercice doit faire au minimum 1 mois et au maximum 24 mois"); - } - result = false; - } else { - // Période(s) précédente(s) bloquée(s). - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - // Recherche les périodes qui ne sont pas bloquées. - List<Period> listePeriod = periodDAO.findAllByLocked(false); - // Recherche la dernière période, les dates doivent se suivre - Date date_search = period.getBeginPeriod(); - Period previousPeriod = periodDAO.findByEndPeriod(dateUtil - .previousDay(date_search)); - // Nombre de périodes dans la base - int number_period = periodDAO.findAll().size(); - // Fermeture BDD - topiaContext.closeContext(); - // Si il y a au moins une période trouvée - if (!(listePeriod.isEmpty())) { - if (log.isErrorEnabled()) { - log.error("Il existe au moins une période précédente non bloquée !"); - } - result = false; - } - // Si la période précédente correspond au jour précédent - // et vérifie si ce n'est pas la première période - if (previousPeriod == null && number_period != 0) { - if (log.isErrorEnabled()) { - log.error("Votre période doit être collée " - + "aux autres périodes !" - + date_search.toString() + " PPP " - + dateUtil.previousDay(date_search).toString()); - } - result = false; - } - } catch (TopiaException e) { - log.error(e); - } - } - return result; - }*/ - - /* - * Cette méthode permet de bloquer une période. Elle doit vérifier que - * tous les timeSpans mensuels sont bloqués. - * @param - * @return - * - public String blockPeriod(Period period) { - String result = ServiceHelper.RESPOND_ERROR; - // La période ne doit pas être nulle - if (period != null) { - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Recherche tous les timeSpans de la période non bloquées - List<TimeSpan> listeTimeSpan = timeSpanDAO - .findAllByPeriod(period); - boolean existTimeSpanNotBlock = false; - for (TimeSpan timeSpan : listeTimeSpan) { - // Si timeSpan non bloqué - if (!timeSpan.getLocked()) { - existTimeSpanNotBlock = true; - if (log.isErrorEnabled()) { - log.error("Le timeSpan du " - + timeSpan.getBeginTimeSpan().toString() - + " au " - + timeSpan.getEndTimeSpan().toString() - + " non bloqué !"); - } - result = ServiceHelper.PERIOD_TIMESPAN_NOT_BLOCK; - } - } - // Si il n'existe pas de timeSpan non bloqué - if (!(existTimeSpanNotBlock)) { - // Bloque la période - period.setLocked(true); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - periodDAO.update(period); - // Création BDD - topiaContext.commitTransaction(); - result = ServiceHelper.RESPOND_SUCCESS; - if (log.isInfoEnabled()) { - log.info("Période " - + period.getBeginPeriod().toString() + " au " - + period.getEndPeriod().toString() - + " bloquée avec succès."); - } - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - } - return result; - }*/ - - /* - * Permet de bloquer une période. Avec la périodeDTO passée en paramètre, on - * effectue une recherche avec la date de début pour récupérer la période - * dans la base de données. Il est possible de l'identifier avec son topiaId, - * mais il y a plus de risque que cette mentien ne soit pas renseignée dans - * l'objet periodDTO. - * @param periodDTO - * @return - * - public String blockPeriod(PeriodDTO periodDTO) { - // Recherche de la période - Period period = searchPeriodWithDate(periodDTO.getBeginPeriod()); - String result = blockPeriod(period); - return result; - }*/ - - /* - * Permet de bloquer TOUS les timeSpans de la période - * @param period - * @return - * - public String blockAllTimeSpanOfPeriod(Period period) { - String result = ServiceHelper.RESPOND_ERROR; - if (period == null) { - if (log.isErrorEnabled()) { - log.error("La période ne peut bloquer ses périodes mensuelles, " - + "il faut une période en entrée."); - } - } else { - // On bloque chaque timeSpan - boolean ErrorBlockTimeSpan = false; - List<TimeSpanDTO> listTimeSpanDTO = timeSpanServiceImpl - .searchListTimeSpanDTO(period); - // tri la liste des timeSpans dans l'ordre croissant des dates - Collections.sort(listTimeSpanDTO); - for (TimeSpanDTO timeSpanDTO : listTimeSpanDTO) { - result = timeSpanServiceImpl.blockTimeSpan(timeSpanDTO); - if (result.equals(ServiceHelper.RESPOND_ERROR)) { - ErrorBlockTimeSpan = true; - } - } - // Si il n'y a pas eu d'erreurs pour bloquer les timespans - if (!ErrorBlockTimeSpan) { - result = ServiceHelper.RESPOND_SUCCESS; - } else { - if (log.isErrorEnabled()) { - log.error("Impossible de bloquer tous les timeSpans."); - } - result = ServiceHelper.PERIOD_ALL_TIMESPAN; - } - } - return result; - }*/ - - /* - * Cette méthode est semblable à searchPeriodWithDateFirst. Elle permet - * de rechercher une période sans forcément connaître la date de départ. On - * donne une date quelconque, et elle retourne la période correspondante. - * @param d - * @return - * - public Period searchPeriodWithDate(Date d) { - Period period = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - // Recherche de toutes les périodes - List<Period> listePeriod = periodDAO.findAll(); - // Fermeture BDD - topiaContext.closeContext(); - // Recherche de la période - for (Period periodSearch : listePeriod) { - // Recherche si la date d est entre la date de début et fin de la période - boolean periodBetweenDate = dateUtil.betweenDate(d, - periodSearch.getBeginPeriod(), periodSearch - .getEndPeriod()); - // Si la date est comprise dans les limites de la période - if (periodBetweenDate) { - period = periodSearch; - } - } - } catch (TopiaException e) { - log.error(e); - } - return period; - }*/ - - /* - * Permet de rechercher une période au format DTO avec une date. Cette date - * peut être quelconque (pas obligatoire d'être le premier jour de la période - * par exemple). - * @param d date comprise dans la période qu'on souhaite rechercher - * @return - * - public PeriodDTO searchPeriodDTOWithDate(Date d) { - Period period = searchPeriodWithDate(d); - // Converti la période en PeriodDTO - PeriodDTO periodDTO = convertPeriod.periodEntityToDto(period); - return periodDTO; - }*/ - - /* - * Permet de renvoyer tous les périodes en format DTO, avec tous les timeSpans - * en format DTO également. - * @return - * - public List<PeriodDTO> getAllPeriod() { - ArrayList<PeriodDTO> listAllPeriodDTO = new ArrayList<PeriodDTO>(); - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - // Recherche de toutes les périodes - List<Period> listePeriod = periodDAO.findAll(); - // Transforme les périodes en DTO - for (Period period : listePeriod) { - PeriodDTO periodDTO = convertPeriod.periodEntityToDto(period); - listAllPeriodDTO.add(periodDTO); - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return listAllPeriodDTO; - }*/ - - /* - * Recherche une période précise, avec son identifiant topiaId. - * @param topiaId identifiant de la période - * @return - * - public Period searchPeriodWithTopiaId(String topiaId) { - Period periodSearch = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - // Creation du journal - periodSearch = periodDAO.findByTopiaId(topiaId); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return periodSearch; - }*/ - - - /* - * Efface une période dans la base de données. Tous les timeSpans sont - * également effacés. Cette méthode est uniquement utilisée pour les tests - * unitaires. - * @param period - * @return - * - public String removePeriod(String topiaId) { - String result = ServiceHelper.RESPOND_ERROR; - Period periodDelete = searchPeriodWithTopiaId(topiaId); - // Si la période n'existe pas - if (periodDelete == null) { - if (log.isWarnEnabled()) { - log.warn("La période " + topiaId + " n'existe pas !"); - } - result = ServiceHelper.PERIOD_NOT_EXIST; - } else // Sinon on efface la période - { - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - // Débloque la période - periodDelete.setLocked(false); - // Mise à jour dans la bdd - periodDAO.update(periodDelete); - // Création BDD - topiaContext.commitTransaction(); - - // Supprime les timeSpans de la période - List<TimeSpanDTO> listTimeSpanDTO = timeSpanServiceImpl - .searchListTimeSpanDTO(periodDelete); - // tri la liste des timeSpans dans l'ordre décroissant des dates - Collections.sort(listTimeSpanDTO, Collections.reverseOrder()); - // Débloque les timeSpans - for (TimeSpanDTO timeSpanDTO : listTimeSpanDTO) { - TimeSpan timeSpan = timeSpanServiceImpl - .searchTimeSpanByDate(timeSpanDTO); - // Si le timeSpan est bloqué - if (timeSpanDTO.isLocked()) { - // débloque le timeSpan - timeSpanServiceImpl.unblockTimeSpan(timeSpan); - } - } - // Efface les timeSpans - for (TimeSpanDTO timeSpanDTO : listTimeSpanDTO) { - TimeSpan timeSpan = timeSpanServiceImpl - .searchTimeSpanByDate(timeSpanDTO); - // efface le timeSpan - timeSpanServiceImpl.removeTimeSpan(timeSpan); - } - - - //Supprime la période - periodDAO.delete(periodDelete); - // Création BDD - topiaContext.commitTransaction(); - // Fermeture BDD - topiaContext.closeContext(); - result = ServiceHelper.RESPOND_SUCCESS; - } catch (TopiaException e) { - log.error(e); - } - } - return result; - }*/ - - /* - * Permet d'effacer une période au format DTO. - * @param periodDTO la période à supprimer - * @return - * - public String removePeriod(PeriodDTO periodDTO) { - String result = removePeriod(periodDTO.getId()); - return result; - }*/ } Modified: trunk/lima-business/src/main/resources/lima.properties =================================================================== --- trunk/lima-business/src/main/resources/lima.properties 2010-05-04 13:22:41 UTC (rev 2882) +++ trunk/lima-business/src/main/resources/lima.properties 2010-05-04 13:44:56 UTC (rev 2883) @@ -6,4 +6,6 @@ hibernate.connection.username=sa hibernate.connection.password= hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:file:~/.lima/limadb \ No newline at end of file +hibernate.connection.url=jdbc:h2:file:~/.lima/limadb + +lima.rules=org.chorem.lima.business.accountingrules.FranceAccountingRules \ No newline at end of file Modified: trunk/lima-callao/pom.xml =================================================================== --- trunk/lima-callao/pom.xml 2010-05-04 13:22:41 UTC (rev 2882) +++ trunk/lima-callao/pom.xml 2010-05-04 13:44:56 UTC (rev 2883) @@ -86,3 +86,4 @@ </build> </project> + Modified: trunk/lima-callao/src/main/xmi/accounting.properties =================================================================== --- trunk/lima-callao/src/main/xmi/accounting.properties 2010-05-04 13:22:41 UTC (rev 2882) +++ trunk/lima-callao/src/main/xmi/accounting.properties 2010-05-04 13:44:56 UTC (rev 2883) @@ -1,8 +1,9 @@ # Precise l'entete de l'ensemble des fichiers generes model.tagvalue.copyright=/*\n Copyright (C) 2009-2010 Lima Callao\n */ -#org.chorem.lima.entity.Account.attribute.subAccounts.tagvalue.lazy=false -#org.chorem.lima.entity.Account.attribute.subLedgers.tagvalue.lazy=false +org.chorem.lima.entity.Account.attribute.subAccounts.tagvalue.lazy=false +org.chorem.lima.entity.Account.attribute.subLedgers.tagvalue.lazy=false +org.chorem.lima.entity.Account.attribute.identity.tagvalue.lazy=false +org.chorem.lima.entity.FiscalPeriod.attribute.financialPeriod.tagvalue.lazy=false -org.chorem.lima.entity.Account.attribute.identity.tagvalue.lazy=false #model.tagvalue.dbSchema=Callao model.tagvalue.String=text \ No newline at end of file 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-05-04 13:22:41 UTC (rev 2882) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2010-05-04 13:44:56 UTC (rev 2883) @@ -251,21 +251,7 @@ Account account = (Account) treePath.getLastPathComponent(); try{ - try { - accountsTreeTableModel.removeAccount(treePath, account); - } - catch(LimaBusinessException ex){ - int n2 = JOptionPane.showConfirmDialog(view, - _("lima.question.confirmremove.account"), - _("lima.question"), - JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE); - if (n2 == JOptionPane.YES_OPTION) { - // update view of treetable - accountsTreeTableModel. - removeAccountwithSubAccounts(treePath, account); - } - } + accountsTreeTableModel.removeAccount(treePath, account); } catch (LimaException ex) { if (log.isErrorEnabled()) { log.error("Can't delete account", ex); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java 2010-05-04 13:22:41 UTC (rev 2882) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java 2010-05-04 13:44:56 UTC (rev 2883) @@ -31,6 +31,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.EntryBookService; +import org.chorem.lima.business.FinancialPeriodService; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaException; import org.chorem.lima.business.FinancialTransactionService; @@ -39,6 +40,7 @@ import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryImpl; import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialPeriodImpl; import org.chorem.lima.entity.FinancialTransactionImpl; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.service.LimaServiceFactory; @@ -79,6 +81,9 @@ /** EntryBook service. */ protected final EntryBookService entryBookService; + /** FinancialPeriod service. */ + protected final FinancialPeriodService financialPeriodService; + protected FinancialPeriod selectedFinancialPeriod; /** @@ -93,6 +98,8 @@ .getTransactionService(); entryBookService = LimaServiceFactory.getInstance(). getEntryBookService(); + financialPeriodService = LimaServiceFactory.getInstance(). + getFinancialPeriodService(); } /** @@ -370,7 +377,8 @@ // create it transactionService.createFinancialTransaction(financialTransaction); int row = getDataList().indexOf(financialTransaction); - fireTableRowsInserted(row, row); + //FIXME Invalid range + fireTableRowsInserted(row, row); } else { throw new LimaBusinessException("No financial period selected"); @@ -419,7 +427,47 @@ (FinancialTransaction)currentRow; switch (column) { case 0: - currentFinancialTransaction.setTransactionDate((Date)value); + // Truncate the date - format 01-MM-YYYY + Date dateCurrentFinancialTransaction = ((Date)value); + dateCurrentFinancialTransaction = + DateUtils.truncate( + dateCurrentFinancialTransaction, Calendar.MONTH); + + // Return the begin date of the current financial period + Date dateCurrentFinancialPeriod = + selectedFinancialPeriod.getBeginDate(); + + // Compare to the begindate of the current financial period + if (!dateCurrentFinancialPeriod.equals(dateCurrentFinancialTransaction)){ + //methode get financialperiod dans le service + FinancialPeriod newFinancialPeriod = + new FinancialPeriodImpl(); + try { + newFinancialPeriod = + financialPeriodService.getFinancialPeriodWithDate( + dateCurrentFinancialTransaction); + } catch (LimaException e) { + if (log.isDebugEnabled()){ + log.debug("Can't get new financialPeriodService"); + } + } + //if the changed financial period is unlocked + if (newFinancialPeriod != null){ + if (newFinancialPeriod.getLocked() == false){ + //update + currentFinancialTransaction. + setTransactionDate((Date)value); + currentFinancialTransaction. + setFinancialPeriod(newFinancialPeriod); + } + } + else { + if (log.isDebugEnabled()){ + log.debug("Can't update on the new date"); + } + } + } + break; } // notify service for modification @@ -432,7 +480,7 @@ } } //update the financial transaction row - fireTableRowsUpdated(row, row); + //fireTableRowsUpdated(row, row); } else if (currentRow instanceof Entry) { Entry currentEntry = (Entry)currentRow; @@ -470,8 +518,10 @@ } //update the financial transaction in entire int financialTransactionRow = - getDataList().indexOf(((Entry) currentRow).getFinancialTransaction()); - fireTableRowsUpdated(financialTransactionRow, financialTransactionRow); + getDataList().indexOf(((Entry) currentRow). + getFinancialTransaction()); + fireTableRowsUpdated(financialTransactionRow, + financialTransactionRow); } } else {
participants (1)
-
jpepin@users.chorem.org