Author: echatellier Date: 2012-04-04 15:25:23 +0200 (Wed, 04 Apr 2012) New Revision: 3351 Url: http://chorem.org/repositories/revision/lima/3351 Log: Remove subAcount and ledgerAccount loop association. Account tree is now renderer by account number association. Added: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaRuntimeException.java trunk/lima-business/src/test/java/org/chorem/lima/entity/ trunk/lima-business/src/test/java/org/chorem/lima/entity/AccountDAOTest.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAO.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAO.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAO.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableRenderer.java Removed: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAOImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 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 trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/AccountService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/AccountServiceLocal.java trunk/lima-business/src/main/java/org/chorem/lima/business/migration/MigrationV0_6.java trunk/lima-business/src/main/java/org/chorem/lima/service/LimaServiceFactory.java trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/AccountServiceRuleFrTest.java trunk/lima-callao/src/main/xmi/accounting.properties trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/SubLedgerForm.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateAccountForm.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateSubLedgerForm.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/SubAccountComboBoxModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -46,22 +46,17 @@ /** * Account rule : check create account. * - * @param masterAccount parent account * @param account new account * @throws LimaException if rule validation fails */ - void createAccountRules(Account masterAccount, Account account) throws LimaException; + void createAccountRules(Account account) throws LimaException; - void createSubLedgerRules(Account masterAccount, Account account) throws LimaException; + void updateAccountRules(Account account) throws LimaException; - void updateAccountRules(Account masterAccount, Account account) throws LimaException; - - void updateSubLedgerRules(Account account) throws LimaException; - void removeAccountRules(Account account, TopiaContext transaction) throws LimaException; /** - * Entrybook rules + * Entrybook rules. * * @param entryBook * @param topiaTransaction Added: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaRuntimeException.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaRuntimeException.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaRuntimeException.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -0,0 +1,60 @@ +/* + * #%L + * Lima business + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 CodeLutin, Chatellier Eric + * %% + * 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 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.business; + +/** + * Lima runtime exception. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class LimaRuntimeException extends RuntimeException { + + /** serialVersionUID. */ + private static final long serialVersionUID = -6876236663940184462L; + + /** + * Constructs a new exception with the specified detail message. + * + * @param message message + */ + public LimaRuntimeException(String message) { + super(message); + } + + /** + * Constructs a new exception with the specified detail message and cause. + * + * @param message message + * @param cause cause + */ + public LimaRuntimeException(String message, Throwable cause) { + super(message, cause); + } +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaRuntimeException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: 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 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -71,7 +71,7 @@ * Rules to check before create accounts. */ @Override - public void createAccountRules(Account masterAccount, Account account) throws LimaException { + public void createAccountRules(Account account) throws LimaException { // Check if the numberaccount is not blank if (StringUtils.isBlank(account.getAccountNumber())) { @@ -80,19 +80,13 @@ } } - /** Rules to check before create subledger */ @Override - public void createSubLedgerRules(Account masterAccount, Account account) - throws LimaException { - // check the number account is not empty + public void updateAccountRules(Account account) throws LimaException { + // Check if the numberaccount is not blank if (StringUtils.isBlank(account.getAccountNumber())) { throw new LimaBusinessException(_("lima-business.defaultaccountingrules.invalidaccountnumber", account.getAccountNumber())); } - // check if parentaccount have no subaccount - if (masterAccount.getSubAccounts().isEmpty()) { - throw new LimaBusinessException(_("lima-business.defaultaccountingrules.subledgererror")); - } } /** Rules to check before create fiscals periods */ @@ -455,23 +449,4 @@ } throw new LimaException(_("lima-business.common.queryerror"), cause); } - - @Override - public void updateAccountRules(Account masterAccount, Account account) throws LimaException { - // Check if the numberaccount is not blank - if (StringUtils.isBlank(account.getAccountNumber())) { - throw new LimaBusinessException(_("lima-business.defaultaccountingrules.invalidaccountnumber", - account.getAccountNumber())); - } - } - - @Override - public void updateSubLedgerRules(Account account) throws LimaException { - // check the number account is not empty - if (StringUtils.isBlank(account.getAccountNumber())) { - throw new LimaBusinessException(_("lima-business.defaultaccountingrules.invalidaccountnumber", - account.getAccountNumber())); - } - } - } Modified: 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 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -56,69 +56,48 @@ protected static final Log log = LogFactory.getLog(FranceAccountingRules.class); - /** Règles de vérification de la création du PCG, appliquées à la comptabilité française */ + /** + * Règles de vérification de la création du PCG, appliquées à la comptabilité française. + */ @Override - public void createAccountRules(Account masterAccount, Account account) throws LimaException { - super.createAccountRules(masterAccount, account); + public void createAccountRules(Account account) throws LimaException { + super.createAccountRules(account); - // Check if the number account is type numeric - if (!StringUtils.isNumeric(account.getAccountNumber())) { + String accountNumber = account.getAccountNumber(); + + // ledger account must be located in 411 account + if (!StringUtils.isNumeric(accountNumber) && accountNumber.startsWith("4")) { throw new LimaBusinessException(_("lima-business.franceaccountingrules.accountnumbernotnumeric", 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(_("lima-business.franceaccountingrules.accountnumbernotmaster", - account.getAccountNumber())); - } - - // Check if master account have a number between 1 to 8 - if (masterAccount == null && !account.getAccountNumber().matches("[1-8]")) { + // Check root account starts with 1 to 8 + if (accountNumber.length() == 1 && accountNumber.matches("[1-8]")) { throw new LimaBusinessException(_("lima-business.franceaccountingrules.accountstartnumbererror", account.getAccountNumber())); } - } @Override - public void updateAccountRules(Account masterAccount, Account account) throws LimaException { - super.updateAccountRules(masterAccount, account); + public void updateAccountRules(Account account) throws LimaException { + super.updateAccountRules(account); + String accountNumber = account.getAccountNumber(); + // Check if the number account is type numeric if (!StringUtils.isNumeric(account.getAccountNumber())) { throw new LimaBusinessException(_("lima-business.franceaccountingrules.accountnumbernotnumeric", 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(_("lima-business.franceaccountingrules.accountnumbernotmaster", - account.getAccountNumber())); - } - - // Check if master account have a number between 1 to 8 - if (masterAccount == null && !account.getAccountNumber().matches("[1-8]")) { + // Check root account starts with 1 to 8 + if (accountNumber.length() == 1 && accountNumber.matches("[1-8]")) { throw new LimaBusinessException(_("lima-business.franceaccountingrules.accountstartnumbererror", account.getAccountNumber())); } } - /** Rules to check before create subledger */ - @Override - public void createSubLedgerRules(Account masterAccount, Account account) throws LimaException { - super.createSubLedgerRules(masterAccount, account); - - // check if the master account number is begin with 4 - if (!masterAccount.getAccountNumber().startsWith("4")) { - throw new LimaBusinessException(_("lima-business.franceaccountingrules.masteraccountnumbererror", - account.getAccountNumber())); - } - } - /** * Règles de vérification d'ouverture d'un exercice, appliquées à la comptabilité française * <p/> 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 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -37,7 +37,6 @@ import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaQuery; import javax.ejb.Stateless; import java.util.ArrayList; @@ -64,8 +63,28 @@ } @Override - public void createAccountWithTransaction(Account masterAccount, - Account account, + public long getAccountCount() throws LimaException { + long result = 0; + TopiaContext transaction = beginTransaction(rootContext); + try { + + // check if the accountnumber already exist + AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); + + result = accountDAO.count(); + } catch (Exception ex) { + doCatch(transaction, ex); + } finally { + doFinally(transaction); + } + return result; + } + + /** + * Create new account with existing transaction. + */ + @Override + public void createAccountWithTransaction(Account account, TopiaContext topiaContext) throws LimaException { try { @@ -87,18 +106,6 @@ //create it accountDAO.create(account); - Account masterAccountUpdate = null; - if (masterAccount != null) { - masterAccountUpdate = accountDAO.findByAccountNumber( - masterAccount.getAccountNumber()); - } - - // check if parent account exist; - if (masterAccountUpdate != null) { - masterAccountUpdate.addSubAccounts(account); - accountDAO.update(masterAccountUpdate); - } - commitTransaction(topiaContext); } catch (TopiaException ex) { doCatch(topiaContext, ex); @@ -116,37 +123,17 @@ * @throws LimaException */ @Override - public void createAccount(Account masterAccount, - Account account) throws LimaException { + public void createAccount(Account account) throws LimaException { - //check rules before create the account + // check rules before create the account AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); - accountingRules.createAccountRules(masterAccount, account); + accountingRules.createAccountRules(account); TopiaContext transaction = beginTransaction(rootContext); try { - createAccountWithTransaction(masterAccount, account, transaction); - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); - } - } - - @Override - public void createSubLedgerWithTransaction(Account masterAccount, - Account account, - TopiaContext topiaContext) throws LimaException { - - try { - - // force upppercase account number - account.setAccountNumber(account.getAccountNumber().toUpperCase()); - // check if the accountnumber already exist - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(topiaContext); + AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); Account existAccount = accountDAO.findByAccountNumber(account.getAccountNumber()); if (existAccount != null) { @@ -155,45 +142,12 @@ account.getAccountNumber())); } - //create it - accountDAO.create(account); - - Account masterAccountUpdate = null; - if (masterAccount != null) { - masterAccountUpdate = accountDAO.findByAccountNumber( - masterAccount.getAccountNumber()); - } - - // check if the masteraccount exist; - if (masterAccount != null) { - masterAccountUpdate.addSubLedgers(account); - accountDAO.update(masterAccountUpdate); - } - - commitTransaction(topiaContext); - } catch (TopiaException ex) { - doCatch(topiaContext, ex); - } - } - - /** Permet de créer des comptes tiers */ - @Override - public void createSubLedger(Account masterAccount, - Account account) throws LimaException { - - //check rules before create the account - AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); - accountingRules.createSubLedgerRules(masterAccount, account); - - TopiaContext transaction = beginTransaction(rootContext); - try { - createSubLedgerWithTransaction(masterAccount, account, transaction); + createAccountWithTransaction(account, transaction); } catch (Exception ex) { doCatch(transaction, ex); } finally { doFinally(transaction); } - } /** Permer d'obtenir la liste des comptes à partir d'une de ses propriétés */ @@ -263,8 +217,7 @@ TopiaContext transaction = beginTransaction(rootContext); try { - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(transaction); + AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); accountsList = accountDAO.findAll(); Collections.sort(accountsList, new AccountComparator()); @@ -280,7 +233,7 @@ /** Permet d'obtenir tout les comptes feuilles */ @Override - public List<Account> getAllSubAccounts() throws LimaException { + public List<Account> getAllLeafAccounts() throws LimaException { List<Account> accountsList = null; @@ -288,7 +241,7 @@ try { AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); - accountsList = accountDAO.findAllSubAccounts(); + accountsList = accountDAO.findAllLeafAccounts(); } catch (Exception ex) { doCatch(transaction, ex); } finally { @@ -308,17 +261,17 @@ @Override public List<Account> getChildrenAccounts(Account masterAccount) throws LimaException { - List<Account> accountsList = new ArrayList<Account>(); + List<Account> accountsList = null; TopiaContext transaction = beginTransaction(rootContext); try { AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); - TopiaQuery query = accountDAO.createQuery(); + //TopiaQuery query = accountDAO.createQuery(); //tchemit 2011-09-21 Only consider account childs from the master account // link otherwise account can be found from different masterAccount - query.addEquals(Account.PROPERTY_MASTER_ACCOUNT, masterAccount); + //query.addEquals(Account.PROPERTY_MASTER_ACCOUNT, masterAccount); // if (masterAccount == null) { // query.addEquals(Account.PROPERTY_MASTER_ACCOUNT, masterAccount); // query.addWhere(Account.PROPERTY_GENERAL_LEDGER, TopiaQuery.Op.EQ, null); @@ -328,20 +281,22 @@ // Account.PROPERTY_GENERAL_LEDGER + " = :value") // .addParam("value", masterAccount); // } - accountsList.addAll(accountDAO.findAllByQuery(query)); - Collections.sort(accountsList, new AccountComparator()); + //accountsList.addAll(accountDAO.findAllByQuery(query)); + //Collections.sort(accountsList, new AccountComparator()); // sort of bug fix 2011.09.10 vsalaun (+ bleny) // do NOT delete these lines unless you find a better way to // prevent lazy exception when updating account from the account chart - for (Account t : accountsList) { + /*for (Account t : accountsList) { if (t.getMasterAccount() != null) { t.getMasterAccount().getTopiaId(); } t.sizeSubAccounts(); t.sizeSubLedgers(); t.getGeneralLedger(); - } + }*/ + + accountsList = accountDAO.getSubAccounts(masterAccount); } catch (Exception ex) { doCatch(transaction, ex); @@ -442,25 +397,7 @@ AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); Account subAccount = accountDAO.findByTopiaId(account.getTopiaId()); - //check rules account if ledger or account - if (account.getGeneralLedger() == null) { // is an account - - Account master = account.getMasterAccount(); - - accountingRules.updateAccountRules(master, account); - subAccount.setMasterAccount(account.getMasterAccount()); - subAccount.setSubAccounts(account.getSubAccounts()); - } else { // is a ledger - accountingRules.updateSubLedgerRules(account); - subAccount.setGeneralLedger(account.getGeneralLedger()); - subAccount.setSubLedgers(account.getSubLedgers()); - subAccount.setThirdParty(account.getThirdParty()); - } - - // update account - subAccount.setAccountNumber(account.getAccountNumber()); - subAccount.setLabel(account.getLabel()); - + accountingRules.updateAccountRules(account); accountDAO.update(subAccount); commitTransaction(transaction); } catch (Exception ex) { Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -484,18 +484,6 @@ nextLine[1] = account.getAccountNumber(); nextLine[2] = account.getLabel(); nextLine[3] = account.getThirdParty(); - Account masterAccount = account.getMasterAccount(); - Account generalLedger = account.getGeneralLedger(); - String masterAccountString = ""; - String generalLedgerString = ""; - if (masterAccount != null) { - masterAccountString = masterAccount.getAccountNumber(); - } - nextLine[4] = masterAccountString; - if (generalLedger != null) { - generalLedgerString = generalLedger.getAccountNumber(); - } - nextLine[5] = generalLedgerString; // Ajoute la ligne au fichier csvWriter.writeNext(nextLine); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -521,7 +521,7 @@ FinancialStatementDAO financialStatementDAO = LimaCallaoDAOHelper.getFinancialStatementDAO(transaction); - List<Account> accountsList = accountDAO.findAllSubAccounts(); + List<Account> accountsList = accountDAO.findAllLeafAccounts(); List<FinancialStatement> financialStatementsList = financialStatementDAO.findAll(); 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 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -333,10 +333,10 @@ //89 BILAN Account accountMaster = accountService.getAccountByNumber("89"); if (accountMaster == null) { - Account accountSuperMaster = accountService.getAccountByNumber("8"); + accountMaster = new AccountImpl(); accountMaster.setAccountNumber("89"); accountMaster.setLabel("BILAN"); - accountService.createAccount(accountSuperMaster, accountMaster); + accountService.createAccount(accountMaster); accountMaster = accountService.getAccountByNumber("89"); } @@ -346,7 +346,7 @@ beginRetainedAccount = new AccountImpl(); beginRetainedAccount.setAccountNumber("890"); beginRetainedAccount.setLabel("Bilan d'ouverture"); - accountService.createAccount(accountMaster, beginRetainedAccount); + accountService.createAccount(beginRetainedAccount); beginRetainedAccount = accountService.getAccountByNumber("890"); } @@ -356,7 +356,7 @@ endRetainedAccount = new AccountImpl(); endRetainedAccount.setAccountNumber("891"); endRetainedAccount.setLabel("Bilan de clôture"); - accountService.createAccount(accountMaster, endRetainedAccount); + accountService.createAccount(endRetainedAccount); endRetainedAccount = accountService.getAccountByNumber("891"); } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -366,8 +366,7 @@ .findByAccountNumber(masterAccountNumber); i++; } - accountService.createSubLedgerWithTransaction( - masterAccount, account, topiaContext); + accountService.createAccountWithTransaction(account, topiaContext); result.append(_("lima-business.import.accountadded", accountNumber, label)); } // else if account and exclude account start with 0 (fix from error on EBP) @@ -375,8 +374,7 @@ // if account is class account : 1, 2, 3, 4, 5, 6, 7,… int nbCharAccountNumber = accountNumber.length(); if (nbCharAccountNumber == 1) { - accountService.createAccountWithTransaction(null, - account, topiaContext); + accountService.createAccountWithTransaction(account, topiaContext); result.append(_("lima-business.import.accountadded", accountNumber, label)); } else { Account masterAccount = null; @@ -388,8 +386,7 @@ .findByAccountNumber(masterAccountNumber); i++; } - accountService.createAccountWithTransaction( - masterAccount, account, topiaContext); + accountService.createAccountWithTransaction(account, topiaContext); result.append(_("lima-business.import.accountadded", accountNumber, label)); } } @@ -1239,13 +1236,8 @@ account.setLabel(accountImport.getLabel()); account.setThirdParty(accountImport.getThirdParty()); - if (generalLedger != null) { - accountService.createSubLedgerWithTransaction( - generalLedger, account, topiaContext); - } else { - accountService.createAccountWithTransaction( - masterAccount, account, topiaContext); - } + accountService.createAccountWithTransaction(account, topiaContext); + result.append(_("lima-business.import.accountadded", accountImport.getAccountNumber(), accountImport.getLabel())); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -114,9 +114,9 @@ if (account != null) { //Get allsubaccounts and thirdParts accounts - List<Account> accounts = (List<Account>) account.getSubAccounts(); + List<Account> accounts = null; // FIXME review code (List<Account>) account.getSubAccounts(); if (thirdPartAccountsMode) { - List<Account> thirdPartAccount = (List<Account>) account.getSubLedgers(); + List<Account> thirdPartAccount = null; // FIXME review code (List<Account>) account.getSubLedgers(); if (thirdPartAccount != null) { ReportsDatas subReportsDatas = generateSubAccountReportsWithTransaction(account, beginDate, endDate, topiaContext); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/AccountService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/AccountService.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/AccountService.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -43,6 +43,14 @@ @Remote public interface AccountService { + /** + * Return account count. + * + * @return account count + * @throws LimaException technical exception + */ + long getAccountCount() throws LimaException; + List<Account> getAllAccountByProperty(String propertyName, String value) throws LimaException; @@ -61,9 +69,15 @@ Account getAccountByNumber(String number) throws LimaException; + /** + * Return all account ordered by account name. + * + * @return all account + * @throws LimaException + */ List<Account> getAllAccounts() throws LimaException; - List<Account> getAllSubAccounts() throws LimaException; + List<Account> getAllLeafAccounts() throws LimaException; /** * Create new account. If {@code masterAccount} is not null, {@code account} @@ -73,12 +87,8 @@ * @param account account * @throws LimaException */ - void createAccount(Account masterAccount, - Account account) throws LimaException; + void createAccount(Account account) throws LimaException; - void createSubLedger(Account masterAccount, - Account account) throws LimaException; - void updateAccount(Account account) throws LimaException; void removeAccount(Account account) throws LimaException; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/AccountServiceLocal.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/AccountServiceLocal.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/AccountServiceLocal.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2010 CodeLutin + * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -40,12 +40,9 @@ * Last update : $Date$ * By : $Author$ */ - @Local public interface AccountServiceLocal extends AccountService { - void createAccountWithTransaction(Account masterAccount, Account account, TopiaContext topiaContext) throws LimaException; + void createAccountWithTransaction(Account account, TopiaContext topiaContext) throws LimaException; - void createSubLedgerWithTransaction(Account masterAccount, Account account, TopiaContext topiaContext) throws LimaException; - } \ No newline at end of file Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/migration/MigrationV0_6.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/migration/MigrationV0_6.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/migration/MigrationV0_6.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -27,9 +27,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.AccountDAO; -import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.topia.migration.TopiaMigrationCallbackByClass; @@ -63,74 +60,14 @@ log.info("Migrates to version 0.6"); } - // find all account with no master account and attach them to a master - // if master does not exists let's create it also - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(tx); - List<Account> accounts = accountDAO.findAll(); - for (Account account : accounts) { - fillMasterAccountNumber(accountDAO, account); - } - // delete computed fields queries.add("Alter table FINANCIALTRANSACTION drop column AMOUNTDEBIT"); queries.add("Alter table FINANCIALTRANSACTION drop column AMOUNTCREDIT"); + + // modele refactoring + queries.add("drop table record"); + queries.add("alter table account drop column masteraccount"); + queries.add("alter table account drop column generalledger"); } - protected void fillMasterAccountNumber(AccountDAO accountDAO, Account account) throws TopiaException { - if (account.getMasterAccount() != null) { - // have already a master account - return; - } - - String accountNumber = account.getAccountNumber(); - - if (log.isInfoEnabled()) { - log.info("Account " + accountNumber + " does not have a masterAccount, will fill one."); - } - int length = accountNumber.length(); - if (length == 1) { - - // this is a master account, nothing to do - return; - } - String masterAccountNumber = null; - - if (length > 3) { - // fill with master account with 3 digits - masterAccountNumber = accountNumber.substring(0, 3); - } else if (length == 3) { - // fill with master account with 2 digits - masterAccountNumber = accountNumber.substring(0, 2); - } else if (length == 2) { - // fill with master account with 1 digits - masterAccountNumber = accountNumber.substring(0, 1); - } - - if (masterAccountNumber != null) { - - Account masterAccount = getMasterAccount(accountDAO, account, masterAccountNumber); - - if (log.isInfoEnabled()) { - log.info("Set masterAccount [" + masterAccountNumber + "] to account [" + accountNumber + "]"); - } - account.setMasterAccount(masterAccount); - - // let's fill master account - fillMasterAccountNumber(accountDAO, masterAccount); - } - } - - protected Account getMasterAccount(AccountDAO accountDAO, - Account subAccount, - String accountNumber) throws TopiaException { - Account masterAccount = - accountDAO.findByAccountNumber(accountNumber); - if (masterAccount == null) { - - // creates it - masterAccount = accountDAO.create(Account.PROPERTY_ACCOUNT_NUMBER, accountNumber); - } - masterAccount.addSubAccounts(subAccount); - return masterAccount; - } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/service/LimaServiceFactory.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -40,10 +40,6 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.openejb.OpenEJB; -import org.apache.openejb.assembler.classic.AppInfo; -import org.apache.openejb.assembler.classic.Assembler; -import org.apache.openejb.loader.SystemInstance; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.ServiceMonitorable; import org.nuiton.util.ApplicationConfig; Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -71,6 +71,10 @@ import org.junit.BeforeClass; import org.nuiton.i18n.I18n; import org.nuiton.i18n.init.ClassPathI18nInitializer; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.TopiaRuntimeException; /** * Common initialization code for all lima tests. @@ -227,37 +231,37 @@ Account classFinancier = new AccountImpl(); classFinancier.setAccountNumber("5"); classFinancier.setLabel("Comptes financiers"); - accountService.createAccount(null, classFinancier); + accountService.createAccount(classFinancier); Account accountVmp = new AccountImpl(); accountVmp.setAccountNumber("50"); accountVmp.setLabel("Valeurs mobilières de placement"); - accountService.createAccount(classFinancier, accountVmp); + accountService.createAccount(accountVmp); Account accountPel = new AccountImpl(); accountPel.setAccountNumber("501"); accountPel.setLabel("Parts dans des entreprises liées"); - accountService.createAccount(accountVmp, accountPel); + accountService.createAccount(accountPel); Account accountAP = new AccountImpl(); accountAP.setAccountNumber("502"); accountAP.setLabel("Actions propres"); - accountService.createAccount(accountVmp, accountAP); + accountService.createAccount(accountAP); Account accountBefa = new AccountImpl(); accountBefa.setAccountNumber("51"); accountBefa.setLabel("Banques établissements financiers et assimilés"); - accountService.createAccount(classFinancier, accountBefa); + accountService.createAccount(accountBefa); Account accountVmpVae = new AccountImpl(); accountVmpVae.setAccountNumber("511"); accountVmpVae.setLabel("Valeurs à l'encaissement"); - accountService.createAccount(accountBefa, accountVmpVae); + accountService.createAccount(accountVmpVae); Account accountBanques = new AccountImpl(); accountBanques.setAccountNumber("512"); accountBanques.setLabel("Banques"); - accountService.createAccount(accountBefa, accountBanques); + accountService.createAccount(accountBanques); // creation d'un journal EntryBook journalDesVentes = new EntryBookImpl(); @@ -310,4 +314,24 @@ tr1Entry2.setVoucher("voucher"); tr1Entry2 = financialTransactionService.createEntry(tr1Entry2); } + + /** + * Method to use only for class that need a context to be tester. + * Only for DOA for now. + * + * @return a topia context + */ + protected static TopiaContext getTestContext() { + try { + LimaConfig config = LimaConfig.getInstance(); + Properties options = config.getFlatOptions(); + + if (log.isDebugEnabled()) { + log.debug("Opening context to database : " + options.getProperty("hibernate.connection.url")); + } + return TopiaContextFactory.getContext(options); + } catch (TopiaNotFoundException ex) { + throw new TopiaRuntimeException("Could not acquire root context", ex); + } + } } Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -60,7 +60,7 @@ Account myAccount = new AccountImpl(); myAccount.setAccountNumber("2"); myAccount.setLabel("Comptes d'immobilisations"); - accountService.createAccount(null, myAccount); + accountService.createAccount(myAccount); } /** @@ -73,7 +73,7 @@ Account myAccount = new AccountImpl(); myAccount.setAccountNumber("5"); myAccount.setLabel("Comptes de capitaux"); - accountService.createAccount(null, myAccount); + accountService.createAccount(myAccount); } /** @@ -89,7 +89,7 @@ Account myAccount = new AccountImpl(); myAccount.setAccountNumber("42"); // erreur de compte (4) myAccount.setLabel("Comptes de tiers"); - accountService.createAccount(null, myAccount); + accountService.createAccount(myAccount); } /** @@ -104,22 +104,22 @@ Account classCharges = new AccountImpl(); classCharges.setAccountNumber("6"); classCharges.setLabel("Comptes de charges"); - accountService.createAccount(null, classCharges); + accountService.createAccount(classCharges); Account accountAchat = new AccountImpl(); accountAchat.setAccountNumber("60"); accountAchat.setLabel("Achats (sauf 603)"); - accountService.createAccount(classCharges, accountAchat); + accountService.createAccount(accountAchat); Account accountSe = new AccountImpl(); accountSe.setAccountNumber("61"); accountSe.setLabel("Services extérieurs"); - accountService.createAccount(classCharges, accountSe); + accountService.createAccount(accountSe); Account accountVs = new AccountImpl(); accountVs.setAccountNumber("603"); accountVs.setLabel("Variations des stocks (approvisionnements et marchandises)"); - accountService.createAccount(accountAchat, accountVs); + accountService.createAccount(accountVs); } /** @@ -134,12 +134,12 @@ Account classFinancier = new AccountImpl(); classFinancier.setAccountNumber("5"); classFinancier.setLabel("Comptes financiers"); - accountService.createAccount(null, classFinancier); + accountService.createAccount(classFinancier); Account accountVmp = new AccountImpl(); accountVmp.setAccountNumber("40"); accountVmp.setLabel("Fournisseurs et comptes rattachés"); - accountService.createAccount(classFinancier, accountVmp); + accountService.createAccount(accountVmp); } /** @@ -178,6 +178,17 @@ } /** + * Find all leaf account. + * + * @throws LimaException + */ + @Test + public void getAllLeafAccountTest() throws LimaException { + List<Account> listAccount = accountService.getAllLeafAccounts(); + Assert.assertEquals(4, listAccount.size()); + } + + /** * Permet de tester si un compte est bien effacé. * * @throws LimaException Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -116,12 +116,13 @@ * @throws Exception */ @Test - public void testImportAccountLedgerAccount() throws Exception { + public void testImportCreateIntermediaiteAccount() throws Exception { importEBPData(); Account compteTiers = accountService.getAccountByNumber("4"); Account employeAccount = accountService.getAccountByNumber("401TEEMP"); - Assert.assertEquals(compteTiers, employeAccount.getGeneralLedger()); + Assert.assertNotNull(compteTiers); + Assert.assertNotNull(employeAccount); } /** Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/AccountServiceRuleFrTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/AccountServiceRuleFrTest.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/AccountServiceRuleFrTest.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -71,6 +71,6 @@ public void testCreateAccountWrongNumber() throws LimaException { Account myAccount = new AccountImpl(); myAccount.setAccountNumber("42"); - accountService.createAccount(null, myAccount); + accountService.createAccount(myAccount); } } Added: trunk/lima-business/src/test/java/org/chorem/lima/entity/AccountDAOTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/entity/AccountDAOTest.java (rev 0) +++ trunk/lima-business/src/test/java/org/chorem/lima/entity/AccountDAOTest.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -0,0 +1,60 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.entity; + +import java.util.List; + +import org.chorem.lima.business.AbstractLimaTest; +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.topia.TopiaException; + +/** + * Test for AccountDAO class. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class AccountDAOTest extends AbstractLimaTest { + + /** + * Test la recherche de compte par interval. + * @throws TopiaException + */ + @Test + public void testStringToListAccounts() throws TopiaException { + AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(getTestContext()); + + List<Account> accounts = accountDAO.stringToListAccounts("50..511", false); + Assert.assertEquals(3, accounts.size()); + + accounts = accountDAO.stringToListAccounts("60..99", false); + Assert.assertEquals(0, accounts.size()); + } +} Property changes on: trunk/lima-business/src/test/java/org/chorem/lima/entity/AccountDAOTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAO.java (from rev 3340, trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAO.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAO.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -0,0 +1,198 @@ +/* + * #%L + * Lima callao + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric + * %% + * 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 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.entity; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.StringTokenizer; + + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaException; + +public class AccountDAO extends AccountDAOAbstract<Account> { + + private static final Log log = LogFactory.getLog(AccountDAO.class); + + /** + * Retourne tous les comptes qui n'ont pas eux meme de sous compte. + */ + public List<Account> findAllLeafAccounts() throws TopiaException { + String query = "FROM " + Account.class.getName() + " a WHERE a NOT IN (" + + "FROM " + Account.class.getName() + " b where b.accountNumber like concat(a.accountNumber,'%'))"; + List<Account> accounts = context.find(query); + return accounts; + } + + /** + * TODO pas compris l'interet de la methode, si on veut un compte feuille + * par son numero, cela revient a avoir un compte par son numero. + */ + @Deprecated + public Account findLeafAccountByNumber(String number) throws TopiaException { + return findByAccountNumber(number); + } + + /** + * Find account contained into account number interval. + * + * @param accountNumberLow min account number + * @param accountNumberHigh max account number + * @return account list + * @throws TopiaException + */ + protected List<Account> findIntervalAccountByNumber(String accountNumberLow, + String accountNumberHigh) throws TopiaException { + String query = "FROM " + Account.class.getName() + " WHERE ? < accountNumber AND accountNumber > ?"; + return (List<Account>) context.find(query, accountNumberLow, accountNumberHigh); + } + + /** + * @deprecated since 0.6, business method, need to be moved out of dao + */ + @Deprecated + public List<Account> stringToListAccounts(String selectedAccounts, + Boolean leafAccountsMode) throws TopiaException { + Set<Account> accounts = new HashSet<Account>(); + if (selectedAccounts != null) { + //Remove Spaces + String result = StringUtils.deleteWhitespace(selectedAccounts); + + Boolean first = true; + StringTokenizer stStar = new StringTokenizer(result, "-"); + while (stStar.hasMoreTokens()) { + String subString = stStar.nextToken(); + + //Split comma + StringTokenizer stComma = new StringTokenizer(subString, ","); + while (stComma.hasMoreTokens()) { + String s = stComma.nextToken(); + //if intervall account + if (s.contains("..") && !s.endsWith("..")) { + //Split .. + String stringDoubleDot[] = s.split("\\.\\."); + + List<Account> resultIntervall = + findIntervalAccountByNumber(stringDoubleDot[0], stringDoubleDot[1]); + + //if first add accounts, else remove + if (first) { + accounts.addAll(resultIntervall); + } else { + accounts.removeAll(resultIntervall); + } + } + //else one account + else { + Account account = null; + if (leafAccountsMode) { + account = findLeafAccountByNumber(s); + } else { + account = findByAccountNumber(s); + } + //if exist + if (account != null) { + //if first + if (first) { + accounts.add(account); + } else { + accounts.remove(account); + } + } + //search all account start with accountnumber + else { + /*TopiaQuery query = createQuery(); + String subAccountsProperty = TopiaQuery.getProperty(Account.PROPERTY_SUB_ACCOUNTS); + query.addWhere("not exists elements (" + subAccountsProperty + ")") + .addWhere(Account.PROPERTY_ACCOUNT_NUMBER, Op.LIKE, s + "%"); + List<Account> accountsResult = (List<Account>) findAllByQuery(query);*/ + + String query = "FROM " + Account.class.getName() + " a WHERE NOT IN (" + + "FROM " + Account.class.getName() + " b where b.accountNumber like a.accountNumber+'%')" + + " AND a.accountNumber LIKE ?"; + List<Account> accountsResult = getContext().find(query, s); + if (accountsResult != null) { + //if first + if (first) { + accounts.addAll(accountsResult); + } else { + accounts.removeAll(accountsResult); + } + } + } + } + } + first = false; + } + } + return new ArrayList(accounts); + } + + /* + * @see org.chorem.lima.entity.AccountDAOAbstract#getSubAccounts(org.chorem.lima.entity.Account) + */ + public List<Account> getSubAccounts(Account account) throws TopiaException { + + List<Account> accountsResult = null; + + /*String query = "FROM " + Account.class.getName() + " a WHERE a.accountNumber LIKE :like" + + " ORDER BY a.accountNumber"; + + + // FIXME echatellier 20120321 remove hard coded 8 here + // usefull for efficient tree loading but not beautiful code + String likeSuffix = ""; + while (CollectionUtils.isEmpty(accountsResult) && likeSuffix.length() < 8) { + likeSuffix += "_"; + if (account != null) { + accountsResult = getContext().find(query, "like", account.getAccountNumber() + likeSuffix); + } else { + accountsResult = getContext().find(query, "like", likeSuffix); + } + }*/ + + // on recherche les sous comptes de account + // qui ne sont pas eux meme des sous comptes intermediaire + // autrement dir, les fils directs + /*String query = "FROM " + Account.class.getName() + " a" + + " WHERE a.accountNumber LIKE :like" + + " AND a not in (FROM " + Account.class.getName() + " b" + + " WHERE b.accountNumber like concat(a.accountNumber,'%'))" + + " ORDER BY a.accountNumber"; + + if (account != null) { + accountsResult = getContext().find(query, "like", account.getAccountNumber() + "%"); + } else { + accountsResult = getContext().find(query, "like", "%"); + }*/ + + return accountsResult; + } +} Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -1,148 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id$ - * $HeadURL$ - * %% - * 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 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.entity; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaQuery; -import org.nuiton.topia.framework.TopiaQuery.Op; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.StringTokenizer; - -public class AccountDAOImpl<E extends Account> extends AccountDAOAbstract<E> { - - private static final Log log = LogFactory.getLog(AccountDAOImpl.class); - - /** - * List all subaccounts (no folderaccounts, exclude accounts contains thirdpart accounts) - * Sort by accout number in lexicographical order - */ - @Override - public List<Account> findAllSubAccounts() throws TopiaException { - TopiaQuery query = createQuery(); - String subAccountsProperty = TopiaQuery.getProperty(Account.PROPERTY_SUB_ACCOUNTS); - query.addWhere("not exists elements (" + subAccountsProperty + ")") - .addOrder(Account.PROPERTY_ACCOUNT_NUMBER); - return (List<Account>) findAllByQuery(query); - } - - @Override - public Account findSubAccountByNumber(String number) throws TopiaException { - TopiaQuery query = createQuery(); - String subAccountsProperty = TopiaQuery.getProperty(Account.PROPERTY_SUB_ACCOUNTS); - String subLedgersProperty = TopiaQuery.getProperty(Account.PROPERTY_SUB_LEDGERS); - query.addWhere("not exists elements (" + subAccountsProperty + ")") - .addWhere("not exists elements (" + subLedgersProperty + ")") - .addEquals(Account.PROPERTY_ACCOUNT_NUMBER, number); - return findByQuery(query); - } - - public List<Account> findIntervalAccountByNumber(String accountNumberLow, - String accountNumberHigh) throws TopiaException { - TopiaQuery query = createQuery(); - query.addBetween(Account.PROPERTY_ACCOUNT_NUMBER, - accountNumberLow, accountNumberHigh); - return (List<Account>) findAllByQuery(query); - } - - @Override - public List<Account> stringToListAccounts(String selectedAccounts, - Boolean subAccountsMode) throws TopiaException { - HashSet<Account> accounts = new HashSet<Account>(); - if (selectedAccounts != null) { - //Remove Spaces - String result = StringUtils.deleteWhitespace(selectedAccounts); - - Boolean first = true; - StringTokenizer stStar = new StringTokenizer(result, "-"); - while (stStar.hasMoreTokens()) { - String subString = stStar.nextToken(); - - //Split comma - StringTokenizer stComma = new StringTokenizer(subString, ","); - while (stComma.hasMoreTokens()) { - String s = stComma.nextToken(); - //if intervall account - if (s.contains("..") && !s.endsWith("..")) { - //Split .. - String stringDoubleDot[] = s.split("\\.\\."); - - List<Account> resultIntervall = - findIntervalAccountByNumber(stringDoubleDot[0], stringDoubleDot[1]); - - //if first add accounts, else remove - if (first) { - accounts.addAll(resultIntervall); - } else { - accounts.removeAll(resultIntervall); - } - } - //else one account - else { - Account account = null; - if (subAccountsMode) { - account = findSubAccountByNumber(s); - } else { - account = findByAccountNumber(s); - } - //if exist - if (account != null) { - //if first - if (first) { - accounts.add(account); - } else { - accounts.remove(account); - } - } - //search all account start with accountnumber - else { - TopiaQuery query = createQuery(); - String subAccountsProperty = TopiaQuery.getProperty(Account.PROPERTY_SUB_ACCOUNTS); - query.addWhere("not exists elements (" + subAccountsProperty + ")") - .addWhere(Account.PROPERTY_ACCOUNT_NUMBER, Op.LIKE, s + "%"); - List<Account> accountsResult = (List<Account>) findAllByQuery(query); - if (accountsResult != null) { - //if first - if (first) { - accounts.addAll(accountsResult); - } else { - accounts.removeAll(accountsResult); - } - } - } - } - } - first = false; - } - } - return new ArrayList(accounts); - } -} Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAO.java (from rev 3322, trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAO.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAO.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -0,0 +1,71 @@ +/* + * #%L + * Lima callao + * + * $Id$ + * $HeadURL$ + * %% + * 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 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.entity; + +import java.util.Date; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaQuery; +import org.nuiton.topia.framework.TopiaQuery.Op; + +public class ClosedPeriodicEntryBookDAO extends ClosedPeriodicEntryBookDAOImpl<ClosedPeriodicEntryBook> { + + private static final Log log = LogFactory.getLog(ClosedPeriodicEntryBookDAO.class); + + + /** Return ClosedPeriodicEntryBook by EntryBook and FinancialPeriod */ + public ClosedPeriodicEntryBook findByEntryBookAndFinancialPeriod( + EntryBook entryBook, FinancialPeriod financialPeriod) + throws TopiaException { + + TopiaQuery query = createQuery(); + if (entryBook != null) { + query.addEquals(ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, entryBook); + } + if (financialPeriod != null) { + query.addEquals(ClosedPeriodicEntryBook.PROPERTY_FINANCIAL_PERIOD, financialPeriod); + } + return findByQuery(query); + } + + public List<ClosedPeriodicEntryBook> findAllByDates(Date beginDate, + Date endDate) throws TopiaException { + TopiaQuery query = createQuery(); + if (beginDate != null && endDate != null) { + String beginDateProperty = TopiaQuery.getProperty(ClosedPeriodicEntryBook.PROPERTY_FINANCIAL_PERIOD, FinancialPeriod.PROPERTY_BEGIN_DATE); + String endDateProperty = TopiaQuery.getProperty(ClosedPeriodicEntryBook.PROPERTY_FINANCIAL_PERIOD, FinancialPeriod.PROPERTY_BEGIN_DATE); + String entrybookProperty = TopiaQuery.getProperty(ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, EntryBook.PROPERTY_CODE); + query.addWhere(beginDateProperty, Op.GE, beginDate) + .addWhere(endDateProperty, Op.LE, endDate) + .addOrder(beginDateProperty, entrybookProperty); + } + return (List<ClosedPeriodicEntryBook>) findAllByQuery(query); + } + +} Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -1,73 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id$ - * $HeadURL$ - * %% - * 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 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.entity; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaQuery; -import org.nuiton.topia.framework.TopiaQuery.Op; - -import java.util.Date; -import java.util.List; - -public class ClosedPeriodicEntryBookDAOImpl<E extends ClosedPeriodicEntryBook> extends ClosedPeriodicEntryBookDAOAbstract<E> { - - private static final Log log = LogFactory.getLog(ClosedPeriodicEntryBookDAOImpl.class); - - - /** Return ClosedPeriodicEntryBook by EntryBook and FinancialPeriod */ - @Override - public ClosedPeriodicEntryBook findByEntryBookAndFinancialPeriod( - EntryBook entryBook, FinancialPeriod financialPeriod) - throws TopiaException { - - TopiaQuery query = createQuery(); - if (entryBook != null) { - query.addEquals(ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, entryBook); - } - if (financialPeriod != null) { - query.addEquals(ClosedPeriodicEntryBook.PROPERTY_FINANCIAL_PERIOD, financialPeriod); - } - return findByQuery(query); - } - - @Override - public List<ClosedPeriodicEntryBook> findAllByDates(Date beginDate, - Date endDate) throws TopiaException { - TopiaQuery query = createQuery(); - if (beginDate != null && endDate != null) { - String beginDateProperty = TopiaQuery.getProperty(ClosedPeriodicEntryBook.PROPERTY_FINANCIAL_PERIOD, FinancialPeriod.PROPERTY_BEGIN_DATE); - String endDateProperty = TopiaQuery.getProperty(ClosedPeriodicEntryBook.PROPERTY_FINANCIAL_PERIOD, FinancialPeriod.PROPERTY_BEGIN_DATE); - String entrybookProperty = TopiaQuery.getProperty(ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, EntryBook.PROPERTY_CODE); - query.addWhere(beginDateProperty, Op.GE, beginDate) - .addWhere(endDateProperty, Op.LE, endDate) - .addOrder(beginDateProperty, entrybookProperty); - } - return (List<ClosedPeriodicEntryBook>) findAllByQuery(query); - } - -} Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAO.java (from rev 3322, trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAOImpl.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAO.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAO.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -0,0 +1,50 @@ +/* + * #%L + * Lima callao + * + * $Id$ + * $HeadURL$ + * %% + * 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 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.entity; + +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaQuery; + +import java.util.Date; + +public class FinancialPeriodDAO extends FinancialPeriodDAOImpl<FinancialPeriod> { + + /** + * Return FinancialPeriod by Date + * Date is include between financialperiod begin and end date + */ + public FinancialPeriod findByDate(Date date) throws TopiaException { + + TopiaQuery query = createQuery(); + if (date != null) { + query.addWhere(FinancialPeriod.PROPERTY_BEGIN_DATE + " <= :value") + .addWhere(FinancialPeriod.PROPERTY_END_DATE + " >= :value") + .addParam("value", date); + } + return findByQuery(query); + } + +} Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAOImpl.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAOImpl.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -1,51 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id$ - * $HeadURL$ - * %% - * 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 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.entity; - -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaQuery; - -import java.util.Date; - -public class FinancialPeriodDAOImpl<E extends FinancialPeriod> extends FinancialPeriodDAOAbstract<E> { - - /** - * Return FinancialPeriod by Date - * Date is include between financialperiod begin and end date - */ - @Override - public FinancialPeriod findByDate(Date date) throws TopiaException { - - TopiaQuery query = createQuery(); - if (date != null) { - query.addWhere(FinancialPeriod.PROPERTY_BEGIN_DATE + " <= :value") - .addWhere(FinancialPeriod.PROPERTY_END_DATE + " >= :value") - .addParam("value", date); - } - return findByQuery(query); - } - -} Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementImpl.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementImpl.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -1,45 +0,0 @@ -/* - * #%L - * Lima callao - * - * $Id$ - * $HeadURL$ - * %% - * 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 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.entity; - -public class FinancialStatementImpl extends FinancialStatementAbstract { - - private static final long serialVersionUID = 1L; - - protected Integer level; - - @Override - public int getLevel() { - if (level == null) { - if (masterFinancialStatement != null) { - level = masterFinancialStatement.getLevel() + 1; - } else { - level = 1; - } - } - return level; - } -} Copied: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementImpl.java (from rev 3322, trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementImpl.java) =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementImpl.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementImpl.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -0,0 +1,45 @@ +/* + * #%L + * Lima callao + * + * $Id$ + * $HeadURL$ + * %% + * 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 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.entity; + +public class FinancialStatementImpl extends FinancialStatementAbstract { + + private static final long serialVersionUID = 1L; + + protected Integer level; + + @Override + public int getLevel() { + if (level == null) { + if (masterFinancialStatement != null) { + level = masterFinancialStatement.getLevel() + 1; + } else { + level = 1; + } + } + return level; + } +} Modified: trunk/lima-callao/src/main/xmi/accounting.properties =================================================================== --- trunk/lima-callao/src/main/xmi/accounting.properties 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-callao/src/main/xmi/accounting.properties 2012-04-04 13:25:23 UTC (rev 3351) @@ -27,6 +27,7 @@ model.tagvalue.version=0.6 model.tagvalue.constantPrefix=PROPERTY_ model.tagValue.notGenerateToString=true +model.tagvalue.String=text # natural id org.chorem.lima.entity.Account.class.tagvalue.naturalIdMutable=false @@ -46,14 +47,8 @@ org.chorem.lima.entity.FiscalPeriod.attribute.endDate.tagvalue.notNull=true # lazy -org.chorem.lima.entity.Account.attribute.subAccounts.tagvalue.lazy=false -org.chorem.lima.entity.Account.attribute.subLedgers.tagvalue.lazy=false org.chorem.lima.entity.FiscalPeriod.attribute.financialPeriod.tagvalue.lazy=false org.chorem.lima.entity.FinancialStatement.attribute.subFinancialStatements.tagvalue.lazy=false org.chorem.lima.entity.FinancialStatement.attribute.masterFinancialStatement.tagvalue.lazy=false org.chorem.lima.entity.VatStatement.attribute.subVatStatements.tagvalue.lazy=false org.chorem.lima.entity.VatStatement.attribute.masterVatStatement.tagvalue.lazy=false - - -#model.tagvalue.dbSchema=Callao -model.tagvalue.String=text \ No newline at end of file Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) Modified: trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -161,10 +161,10 @@ AccountService accountService = LimaServiceFactory.getService(AccountServiceMonitorable.class); - List<Account> accounts = accountService.getChildrenAccounts(null); - if (accounts.isEmpty()) { + long accountCount = accountService.getAccountCount(); + if (accountCount == 0) { if (log.isInfoEnabled()) { - log.info("Propose for defaut account loading"); + log.info("Propose for default account loading"); } OpeningView openingView = new OpeningView(); openingView.setSize(800, 400); Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -1,374 +0,0 @@ -/* - * #%L - * Lima Swing - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric - * %% - * 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 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.ui.account; - -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.ejbinterface.AccountService; -import org.chorem.lima.business.monitorable.AccountServiceMonitorable; -import org.chorem.lima.entity.Account; -import org.chorem.lima.service.LimaServiceFactory; -import org.chorem.lima.util.ErrorHelper; -import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; -import org.jdesktop.swingx.treetable.DefaultTreeTableModel; -import org.jdesktop.swingx.treetable.MutableTreeTableNode; -import org.jdesktop.swingx.treetable.TreeTableNode; - -import javax.swing.tree.TreePath; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.List; - -import static org.nuiton.i18n.I18n._; - -/** - * Tree table model for account edition. - * - * @author ore - * @author chatellier - * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ - */ -public class AccountTreeTableModel extends DefaultTreeTableModel { - - /** log. */ - private static final Log log = LogFactory.getLog(AccountViewHandler.class); - - /** Account service. */ - protected final AccountService accountService; - - public class AccountTreeTableNode extends DefaultMutableTreeTableNode { - - protected boolean loaded; - - AccountTreeTableNode(Account userObject) { - super(userObject); - } - - @Override - public Account getUserObject() { - return (Account) super.getUserObject(); - } - - @Override - public int getChildCount() { - loadChildrenIfRequired(); - return super.getChildCount(); - } - - private void loadChildrenIfRequired() { - if (!loaded) { - loaded = true; - loadChilds(getUserObject()); - } - } - - @Override - public void setParent(MutableTreeTableNode newParent) { - parent = newParent; - } - - private void loadChilds(Account account) { - try { - if (log.isInfoEnabled()) { - log.info("Loading childs for account " + (account == null ? "Root node" : account.getAccountNumber())); - } - List<Account> childs = - accountService.getChildrenAccounts(account); - for (Account child : childs) { - add(new AccountTreeTableNode(child)); - } - } catch (LimaException e) { - ErrorHelper.showErrorDialog( - "Could not load child of account " + account, e); - } finally { - loaded = true; - } - } - - @Override - public Enumeration<? extends MutableTreeTableNode> children() { - loadChildrenIfRequired(); - return super.children(); - } - - @Override - public TreeTableNode getChildAt(int childIndex) { - loadChildrenIfRequired(); - return super.getChildAt(childIndex); - } - - @Override - public boolean isEditable(int column) { - return false; - } - - @Override - public Object getValueAt(int column) { - Account account = getUserObject(); - - Object result = null; - if (account != null) { - switch (column) { - case 0: - result = account.getAccountNumber(); - break; - case 1: - result = account.getLabel(); - break; - } - } - return result; - } - - @Override - public int getColumnCount() { - return 2; - } - } - - /** Model constructor. Init account service used here. */ - public AccountTreeTableModel() { - - setColumnIdentifiers(Arrays.asList(_("lima.table.number"), - _("lima.table.label"))); - - setRoot(new AccountTreeTableNode(null)); - - // Gets factory service - accountService = - LimaServiceFactory.getService(AccountServiceMonitorable.class); - } - -// @Override -// public int getColumnCount() { -// return 2; -// } - -// @Override -// public String getColumnName(int column) { -// String res = null; -// switch (column) { -// case 0: -// res = _("lima.table.number"); -// break; -// case 1: -// res = _("lima.table.label"); -// break; -// } -// return res; -// } - -// @Override -// public int getChildCount(Object node) { -// int result = 0; -// if (node == getRoot()) { -// try { -// result = accountService.getChildrenAccounts(null).size(); -// } catch (LimaException eee) { -// log.debug("Can't count child", eee); -// } -// } else { -// Account parentAccount = (Account) node; -// try { -// result = accountService.getChildrenAccounts(parentAccount).size(); -// } catch (LimaException eee) { -// log.debug("Can't count child", eee); -// } -// } -// return result; -// } - -// @Override -// public Object getChild(Object parent, int index) { -// Object result = null; -// if (parent == getRoot()) { -// try { -// List<Account> allAccounts = -// accountService.getChildrenAccounts(null); -// result = allAccounts.get(index); -// } catch (LimaException eee) { -// log.debug("Can't get child", eee); -// } -// } else { -// Account parentAccount = (Account) parent; -// -// // FIXME sub account is a collection ? -// try { -// List<Account> subaccounts = -// accountService.getChildrenAccounts(parentAccount); -// result = subaccounts.get(index); -// } catch (LimaException eee) { -// log.debug("Can't get child", eee); -// } -// } -// return result; -// } - -// @Override -// public int getIndexOfChild(Object parent, Object child) { -// int result = 0; -// Account parentAccount = (Account) parent; -// Account childAccount = (Account) child; -// -// if (parent == getRoot()) { -// try { -// List<Account> allAccounts = -// accountService.getChildrenAccounts(null); -// result = allAccounts.indexOf(child); -// } catch (LimaException eee) { -// log.debug("Can't get index child", eee); -// } -// } else { -// // FIXME sub account is a collection ? -// try { -// List<Account> subaccounts = -// accountService.getChildrenAccounts(parentAccount); -// result = subaccounts.indexOf(childAccount); -// } catch (LimaException eee) { -// log.debug("Can't get index child", eee); -// } -// } -// return result; -// } - -// @Override -// public Object getValueAt(Object node, int column) { -// Object result = "n/a"; -// if (node instanceof Account) { -// Account account = (Account) node; -// switch (column) { -// case 0: -// result = account.getAccountNumber(); -// break; -// case 1: -// result = account.getLabel(); -// break; -// } -// } -// return result; -// } - -// @Override -// public boolean isCellEditable(Object node, int column) { -// return false; -// } - -// @Override -// public boolean isLeaf(Object node) { -// return getChildCount(node) == 0; -// } - - /** - * Add account - * - * @param parentAccount - * @param account - * @throws LimaException - */ - public void addAccount(Account parentAccount, - Account account) throws LimaException { - accountService.createAccount(parentAccount, account); - //FIXME 2011.08.09 vsalaun quick tree refresh, it should refresh only the path changed - //modelSupport.fireTreeStructureChanged(path); - modelSupport.fireNewRoot(); - } - - /** - * Add account - * - * @param parentAccount - * @param account - * @throws LimaException - */ - public void addSubLedger(Account parentAccount, - Account account) throws LimaException { - accountService.createSubLedger(parentAccount, account); - //FIXME 2011.08.09 vsalaun quick tree refresh, it should refresh only the path changed - //modelSupport.fireTreeStructureChanged(path); - modelSupport.fireNewRoot(); - } - - /** - * Update account. - * - * @param account - * @throws LimaException - */ - public void updateAccount(Account account) throws LimaException { - // Calling account service - //FIXME Force fire for no update if error. Where is the cache ? - try { - accountService.updateAccount(account); - } catch (LimaException eee) { - //modelSupport.fireTreeStructureChanged(path); - throw new LimaBusinessException("Can't update account : " - + account.getAccountNumber(), eee); - } - //FIXME 2011.08.10 vsalaun quick tree refresh, it should only refresh the path where - //the account were, and the path where it has been moved - //modelSupport.fireTreeStructureChanged(path); - modelSupport.fireNewRoot(); - } - - /** Refresh accountschart. */ - public void refreshTree() { - - modelSupport.fireNewRoot(); - } - - /** - * Remove account. - * - * @param path - * @throws LimaException - */ - public void removeAccount(TreePath path) throws LimaException { - - // Calling account service - AccountTreeTableNode node = getLastPathComponent(path); - Account account = node.getUserObject(); - int index = getIndexOfChild( - path.getParentPath().getLastPathComponent(), node); - accountService.removeAccount(account); - modelSupport.fireChildRemoved(path.getParentPath(), index, node); - } - - public Account getAccount(TreePath path) { - AccountTreeTableNode lastPathComponent = getLastPathComponent(path); - Account account = lastPathComponent.getUserObject(); - return account; - } - - public AccountTreeTableNode getLastPathComponent(TreePath path) { - AccountTreeTableNode lastPathComponent = (AccountTreeTableNode) path.getLastPathComponent(); - return lastPathComponent; - } -} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableRenderer.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableRenderer.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -0,0 +1,65 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.ui.account; + +import java.awt.Component; + +import javax.swing.JTree; + +import org.chorem.lima.entity.Account; +import org.jdesktop.swingx.renderer.DefaultTreeRenderer; +import org.jdesktop.swingx.treetable.MutableTreeTableNode; + +/** + * Account renderer in account tree. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class AccountTreeTableRenderer extends DefaultTreeRenderer { + + /** serialVersionUID. */ + private static final long serialVersionUID = -3249368726501873583L; + + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, + boolean selected, boolean expanded, boolean leaf, int row, + boolean hasFocus) { + + MutableTreeTableNode node = (MutableTreeTableNode)value; + Account account = (Account)node.getUserObject(); + Object localValue = value; + if (account != null) { + localValue = account.getAccountNumber(); + } + return super.getTreeCellRendererComponent(tree, localValue, selected, expanded, + leaf, row, hasFocus); + } + +} Property changes on: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableRenderer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx 2012-04-04 13:25:23 UTC (rev 3351) @@ -5,7 +5,7 @@ $Id$ $HeadURL$ %% - Copyright (C) 2008 - 2010 CodeLutin + Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric %% This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -34,20 +34,18 @@ <Boolean id="selectedRow" javaBean="false"/> - <script> - <![CDATA[ + <script><![CDATA[ void $afterCompleteSetup() { handler.init(); } - ]]> - </script> + ]]></script> <row> <cell fill="both" weightx="1" weighty="1" rows='5'> <JScrollPane> <JXTreeTable id="accountsTreeTable" selectionMode="{ListSelectionModel.SINGLE_SELECTION}" - treeTableModel="{new AccountTreeTableModel()}" + treeCellRenderer="{new AccountTreeTableRenderer()}" highlighters="{HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}"/> <ListSelectionModel initializer='accountsTreeTable.getSelectionModel()' onValueChanged="setSelectedRow(accountsTreeTable.getSelectedRow() != -1)"/> @@ -61,7 +59,7 @@ <row> <cell fill="horizontal"> <JButton id="addSubLedger" text="lima.charts.account.addSubLedger" - onActionPerformed="handler.launchAddSubLedgerForm()"/> + onActionPerformed="/*handler.launchAddSubLedgerForm()*/"/> </cell> </row> <row> 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 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -25,10 +25,28 @@ package org.chorem.lima.ui.account; -import org.apache.commons.lang3.ObjectUtils; +import static org.nuiton.i18n.I18n._; + +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +import javax.swing.JOptionPane; +import javax.swing.tree.TreePath; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.LimaRuntimeException; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.ejbinterface.AccountService; import org.chorem.lima.business.monitorable.AccountServiceMonitorable; @@ -39,19 +57,12 @@ import org.chorem.lima.enums.ImportExportEnum; import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.ui.importexport.ImportExport; -import org.chorem.lima.util.DialogHelper; import org.chorem.lima.util.ErrorHelper; import org.jdesktop.swingx.JXTreeTable; +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; +import org.jdesktop.swingx.treetable.DefaultTreeTableModel; +import org.jdesktop.swingx.treetable.TreeTableNode; -import javax.swing.JOptionPane; -import javax.swing.tree.TreePath; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import static org.nuiton.i18n.I18n._; - /** * Handler associated with account view. * @@ -66,20 +77,43 @@ /** log. */ private static final Log log = LogFactory.getLog(AccountViewHandler.class); - protected final AccountView view; - protected AccountService accountService; - protected AccountViewHandler(AccountView view) { + protected AccountView view; + + /** + * Sort account with label length. + */ + protected static Comparator<Account> accountLengthComparator = new Comparator<Account>() { + @Override + public int compare(Account o1, Account o2) { + int result = o1.getAccountNumber().length() - o2.getAccountNumber().length(); + if (result == 0) { + result = -1; + } + return result; + } + }; + protected static Comparator<String> reverseAccountLengthComparator = new Comparator<String>() { + @Override + public int compare(String o1, String o2) { + int result = o2.length() - o1.length(); + if (result == 0) { + result = -1; + } + return result; + } + }; + + public AccountViewHandler(AccountView view) { this.view = view; // Gets factory service LimaServiceFactory.addServiceListener(ImportServiceMonitorable.class, this); - accountService = - LimaServiceFactory.getService(AccountServiceMonitorable.class); + accountService = LimaServiceFactory.getService(AccountServiceMonitorable.class); } public void init() { - JXTreeTable table = getTreeTable(); + JXTreeTable table = view.getAccountsTreeTable(); table.addKeyListener(new KeyAdapter() { /** * for each action combination key are think @@ -105,10 +139,52 @@ } } }); + + loadAllAccounts(); } + /** + * Load all accounts from service and display it into tree table. + */ + protected void loadAllAccounts() { + try { + // default data load + List<Account> accounts = accountService.getAllAccounts(); + Collections.sort(accounts, accountLengthComparator); + + // render in tree node hierarchy for DefaultTreeTableModel + SortedMap<String, DefaultMutableTreeTableNode> nodeCache = new TreeMap<String, DefaultMutableTreeTableNode>(reverseAccountLengthComparator); + DefaultMutableTreeTableNode root = new DefaultMutableTreeTableNode(null); + for (Account account : accounts) { + // find parent + DefaultMutableTreeTableNode parentNode = root; + Iterator<Map.Entry<String, DefaultMutableTreeTableNode>> itNodes = nodeCache.entrySet().iterator(); + while (itNodes.hasNext()) { + Map.Entry<String, DefaultMutableTreeTableNode> entry = itNodes.next(); + String accountNumber = entry.getKey(); + if (account.getAccountNumber().startsWith(accountNumber)) { + parentNode = entry.getValue(); + break; + } + } + + // make current node + DefaultMutableTreeTableNode node = new DefaultMutableTreeTableNode(account); + parentNode.add(node); + + nodeCache.put(account.getAccountNumber(), node); + } + DefaultTreeTableModel model = new DefaultTreeTableModel(root); + model.setColumnIdentifiers(Arrays.asList(_("lima.table.number"), + _("lima.table.label"))); + JXTreeTable table = view.getAccountsTreeTable(); + table.setTreeTableModel(model); + } catch (LimaException ex) { + throw new LimaRuntimeException("Can't load accounts from service"); + } + } + public void launchAddAccountForm() { - Account newAccount = new AccountImpl(); AccountForm accountForm = new AccountForm(view); accountForm.setAccount(newAccount); @@ -117,40 +193,18 @@ accountForm.setVisible(true); } - public void launchAddSubLedgerForm() { - - Account newAccount = new AccountImpl(); - SubLedgerForm subledgerForm = new SubLedgerForm(view); - subledgerForm.setAccount(newAccount); - // jaxx constructor don't call super() ? - subledgerForm.setLocationRelativeTo(view); - subledgerForm.setVisible(true); - } - /** * Open update account (or subledger) form with selected account * from the tree. */ public void launchUpdateAccountForm() { - Account selectedObject = getSelectedAccount(); - if (selectedObject != null) { - - if (selectedObject.getGeneralLedger() == null) { - UpdateAccountForm accountForm = new UpdateAccountForm(view); - accountForm.setAccount(selectedObject); - // jaxx constructor don't call super() ? - accountForm.setLocationRelativeTo(view); - accountForm.setVisible(true); - } else { - UpdateSubLedgerForm subLedgerForm = new UpdateSubLedgerForm(view); - subLedgerForm.setAccount(selectedObject); - // jaxx constructor don't call super() ? - subLedgerForm.setLocationRelativeTo(view); - subLedgerForm.setVisible(true); - } - } + UpdateAccountForm accountForm = new UpdateAccountForm(view); + accountForm.setAccount(selectedObject); + // jaxx constructor don't call super() ? + accountForm.setLocationRelativeTo(view); + accountForm.setVisible(true); } /** @@ -177,20 +231,20 @@ } // add it - try { + /*try { getTreeTableModel().addAccount(masterAccount, newAccount); } catch (LimaException ex) { if (log.isErrorEnabled()) { log.error("Can't add account", ex); } ErrorHelper.showErrorDialog(view, _("lima.account.addaccounterror"), ex); - } + }*/ } finally { dialog.dispose(); } } - public void doAddSubLedger(SubLedgerForm dialog) { + /*public void doAddSubLedger(SubLedgerForm dialog) { try { Account newAccount = dialog.getAccount(); @@ -221,26 +275,26 @@ } finally { dialog.dispose(); } - } + }*/ public void doUpdateAccount(UpdateAccountForm dialog) { Account account = dialog.getAccount(); - String newMasterAccountNumber = + /*String newMasterAccountNumber = dialog.getMasterAccountTextField().getText(); String newLabel = dialog.getDescriptionTextField().getText(); boolean hasChanged = updateMasterAccount(account, newMasterAccountNumber); - hasChanged |= updateLabel(account, newLabel); + hasChanged |= updateLabel(account, newLabel);*/ try { - if (hasChanged) { + //if (hasChanged) { // can update account updateAccount(account); - } + //} } finally { @@ -253,7 +307,7 @@ Account account = dialog.getAccount(); - String newMasterAccountNumber = + /*String newMasterAccountNumber = dialog.getMasterAccountTextField().getText(); String newLabel = dialog.getDescriptionTextField().getText(); String newThirdParty = dialog.getThirdPartyTextField().getText(); @@ -261,15 +315,12 @@ boolean hasChanged = updateMasterAccount(account, newMasterAccountNumber); hasChanged |= updateLabel(account, newLabel); - hasChanged |= updateThirdParty(account, newThirdParty); + hasChanged |= updateThirdParty(account, newThirdParty);*/ try { - if (hasChanged) { + // can update subLedger + updateAccount(account); - // can update subLedger - updateAccount(account); - } - } finally { // close dialog @@ -281,7 +332,7 @@ public void doRemoveAccount() { // maybe this code can be factorised - JXTreeTable treeTable = getTreeTable(); + JXTreeTable treeTable = view.getAccountsTreeTable(); // Any row selected int selectedRow = treeTable.getSelectedRow(); @@ -296,14 +347,14 @@ TreePath treePath = treeTable.getPathForRow(selectedRow); - try { + /*try { getTreeTableModel().removeAccount(treePath); } catch (LimaException eee) { if (log.isErrorEnabled()) { log.error("Can't delete account", eee); } DialogHelper.showErrorMessageDialog(view, eee); - } + }*/ } } } @@ -345,14 +396,14 @@ methodeName.contains("importAsCSV")) { // refresh model - getTreeTableModel().refreshTree(); + //getTreeTableModel().refreshTree(); //FIXME tchemit-2011-09-23 Should never do this... refresh view view.repaint(); } } - protected boolean updateMasterAccount(Account account, + /*protected boolean updateMasterAccount(Account account, String newMasterAccountNumber) { boolean hasChanged = false; String oldMasterAccountNumber = account.getMasterAccount() == null ? @@ -405,29 +456,19 @@ } return hasChanged; - } + }*/ protected void updateAccount(Account selectedObject) { - try { + /*try { getTreeTableModel().updateAccount(selectedObject); } catch (LimaException eee) { if (log.isErrorEnabled()) { log.error("Can't add update", eee); } DialogHelper.showErrorMessageDialog(view, eee); - } + }*/ } - protected JXTreeTable getTreeTable() { - return view.getAccountsTreeTable(); - } - - protected AccountTreeTableModel getTreeTableModel() { - AccountTreeTableModel model = - (AccountTreeTableModel) getTreeTable().getTreeTableModel(); - return model; - } - protected Account getMasterAccount(Account account) { String number = account.getAccountNumber(); @@ -459,15 +500,14 @@ protected Account getSelectedAccount() { - JXTreeTable table = getTreeTable(); + JXTreeTable table = view.getAccountsTreeTable(); Account selectedObject = null; int selectedRow = table.getSelectedRow(); if (selectedRow > -1) { TreePath treePath = table.getPathForRow(selectedRow); - AccountTreeTableModel.AccountTreeTableNode lastPathComponent = - (AccountTreeTableModel.AccountTreeTableNode) treePath.getLastPathComponent(); - selectedObject = lastPathComponent.getUserObject(); + TreeTableNode lastPathComponent = (TreeTableNode) treePath.getLastPathComponent(); + selectedObject = (Account)lastPathComponent.getUserObject(); } return selectedObject; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/SubLedgerForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/SubLedgerForm.jaxx 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/SubLedgerForm.jaxx 2012-04-04 13:25:23 UTC (rev 3351) @@ -90,7 +90,7 @@ <JPanel layout='{new GridLayout(1,0)}'> <JButton text="lima.common.cancel" onActionPerformed="dispose()"/> <JButton id="ok" text="lima.common.ok" - onActionPerformed="handler.doAddSubLedger(this)"/> + onActionPerformed="/*handler.doAddSubLedger(this)*/"/> </JPanel> </cell> </row> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateAccountForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateAccountForm.jaxx 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateAccountForm.jaxx 2012-04-04 13:25:23 UTC (rev 3351) @@ -64,7 +64,7 @@ <JTextField id="descriptionTextField" text="{getAccount().getLabel()}"/> </cell> </row> - <row> + <!-- <row> <cell fill="horizontal"> <JLabel text="lima.common.masteraccount" labelFor='{masterAccountTextField}'/> @@ -73,7 +73,7 @@ <JTextField id="masterAccountTextField" text="{getAccount().getMasterAccount().getAccountNumber()}"/> </cell> - </row> + </row> --> <row> <cell columns="2"> <JPanel layout='{new GridLayout(1,0)}'> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateSubLedgerForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateSubLedgerForm.jaxx 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateSubLedgerForm.jaxx 2012-04-04 13:25:23 UTC (rev 3351) @@ -73,7 +73,7 @@ <JTextField id="thirdPartyTextField" text="{getAccount().getThirdParty()}"/> </cell> </row> - <row> + <!-- <row> <cell fill="horizontal"> <JLabel text="lima.common.masteraccount" labelFor='{masterAccountTextField}'/> @@ -82,7 +82,7 @@ <JTextField id="masterAccountTextField" text="{getAccount().getMasterAccount().getAccountNumber()}"/> </cell> - </row> + </row> --> <row> <cell columns="2"> <JPanel layout='{new GridLayout(1,0)}'> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/SubAccountComboBoxModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/SubAccountComboBoxModel.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/SubAccountComboBoxModel.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -86,7 +86,7 @@ public List<Account> getDataList() { List<Account> result = new ArrayList<Account>(); try { - result = accountService.getAllSubAccounts(); + result = accountService.getAllLeafAccounts(); } catch (LimaException eee) { if (log.isDebugEnabled()) { log.debug("Can't get list subaccounts", eee); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java 2012-04-04 09:03:41 UTC (rev 3350) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java 2012-04-04 13:25:23 UTC (rev 3351) @@ -98,11 +98,11 @@ try { - List<Account> accounts = accountService.getAllAccounts(); - if (accounts.size() > 0) { + long accountCount = accountService.getAccountCount(); + if (accountCount > 0) { setBackground(greenBackground); String accountsString = _("lima.home.chartaccounts.state1_2") + " " - + accounts.size() + " " + _("lima.home.chartaccounts.state2_2") + + accountCount + " " + _("lima.home.chartaccounts.state2_2") + "<br/><br/><a href='#accountschart'>" + _("lima.home.chartaccounts.modify") + "</a>"; //set Text