Author: vsalaun Date: 2011-08-10 13:38:02 +0200 (Wed, 10 Aug 2011) New Revision: 3257 Url: http://chorem.org/repositories/revision/lima/3257 Log: #426 enable changing master account for an account 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/DocumentServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountForm.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java 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/resources/i18n/lima-swing_en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 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 2011-08-09 12:38:19 UTC (rev 3256) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2011-08-10 11:38:02 UTC (rev 3257) @@ -335,6 +335,17 @@ } 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) { + if (t.getMasterAccount() != null) { + t.getMasterAccount().getTopiaId(); + } + t.sizeSubAccounts(); + t.sizeSubLedgers(); + } } catch (TopiaException ex) { @@ -425,9 +436,7 @@ * Il n'est pas possible de modifier un numéro de compte. * Si le compte n'existe pas, il envoie alors un message d'avertissement. * - * @param accountNumber numéro de compte à modifier - * @param label label à modifier - * @param masterAccountNumber compte père à modifier + * @param account compte à modifier * @throws LimaException */ @@ -444,19 +453,15 @@ LimaCallaoDAOHelper.getAccountDAO(transaction); Account subAccount = accountDAO.findByTopiaId(account.getTopiaId()); //check rules account if ledger or account - if (account.getGeneralLedger() == null){ + if (account.getGeneralLedger() == null) { // is an account - //get masteraccount, search account have account in params in all subaccounts collection - TopiaQuery query = accountDAO.createQuery() - .addInElements(":account", "subAccounts") - .addParam("account", account); - Account master = accountDAO.findByQuery(query); + Account master = account.getMasterAccount(); accountingRules.updateAccountRules(master, account); subAccount.setMasterAccount(account.getMasterAccount()); subAccount.setSubAccounts(account.getSubAccounts()); } - else { + else { // is a ledger accountingRules.updateSubLedgerRules(account); subAccount.setGeneralLedger(account.getGeneralLedger()); subAccount.setSubLedgers(account.getSubLedgers()); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2011-08-09 12:38:19 UTC (rev 3256) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2011-08-10 11:38:02 UTC (rev 3257) @@ -37,11 +37,9 @@ import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.Locale; import javax.ejb.EJB; import javax.ejb.Stateless; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountForm.jaxx 2011-08-09 12:38:19 UTC (rev 3256) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountForm.jaxx 2011-08-10 11:38:02 UTC (rev 3257) @@ -28,28 +28,56 @@ onWindowClosing="performCancel();"> <org.chorem.lima.entity.Account id="account" javaBean='null'/> - <Boolean id="addState" javaBean='true'/> <script> <![CDATA[ + import org.chorem.lima.business.AccountServiceMonitorable; + import org.chorem.lima.service.LimaServiceFactory; + import org.chorem.lima.business.LimaException; + import org.chorem.lima.entity.AccountImpl; + getRootPane().setDefaultButton(ok); protected void performCancel() { setAccount(null); dispose(); } + protected void performOk() { + if (getMasterAccountTextField().getText().length() != 0) { + AccountServiceMonitorable accountService = + LimaServiceFactory.getInstance().getService( + AccountServiceMonitorable.class); + Account masterAccount = new AccountImpl(); + try { + System.out.println("setMaster : " + + getMasterAccountTextField().getText() + " to : " + + getAccount().getAccountNumber()); + masterAccount = accountService + .getAccountByNumber(getMasterAccountTextField().getText()); + } catch (LimaException eee) { + log.debug("Can't search account for update : " + + getMasterAccountTextField().getText(), eee); + } + if (masterAccount != null) { + getAccount().setMasterAccount(masterAccount); + } else { + getAccount().setMasterAccount(null); + } + } else { + setAccount(null); + } + dispose(); + } ]]> </script> <Table> + <row> <cell fill="horizontal"> <JLabel text="lima.charts.account.number"/> </cell> <cell fill="horizontal"> - <JTextField id="numberTextField" editable='{isAddState()}' text="{getAccount().getAccountNumber()}"/> - <javax.swing.text.Document javaBean="getNumberTextField().getDocument()" - onInsertUpdate='getAccount().setAccountNumber(getNumberTextField().getText())' - onRemoveUpdate='getAccount().setAccountNumber(getNumberTextField().getText())' /> + <JTextField id="numberTextField" editable='{false}' text="{getAccount().getAccountNumber()}"/> </cell> </row> <row> @@ -64,11 +92,19 @@ </cell> </row> <row> + <cell fill="horizontal"> + <JLabel text="lima.common.masteraccount"/> + </cell> + <cell fill="horizontal"> + <JTextField id="masterAccountTextField" text="{getAccount().getMasterAccount().getAccountNumber()}"/> + </cell> + </row> + <row> <cell fill="none"> <JButton text="lima.common.cancel" onActionPerformed="performCancel()"/> </cell> <cell fill="none"> - <JButton id="ok" text="lima.common.ok" onActionPerformed="dispose()"/> + <JButton id="ok" text="lima.common.ok" onActionPerformed="performOk()"/> </cell> </row> </Table> Modified: 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 2011-08-09 12:38:19 UTC (rev 3256) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java 2011-08-10 11:38:02 UTC (rev 3257) @@ -222,21 +222,24 @@ /** * Update account. * - * @param path * @param account * @throws LimaException */ - public void updateAccount(TreePath path, Account 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 (LimaBusinessException eee) { - modelSupport.fireTreeStructureChanged(path); - throw eee; + //modelSupport.fireTreeStructureChanged(path); + throw new LimaBusinessException("Can't update account : " + + account.getAccountNumber(), eee); } - modelSupport.fireTreeStructureChanged(path); + //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(); } /** 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 2011-08-09 12:38:19 UTC (rev 3256) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2011-08-10 11:38:02 UTC (rev 3257) @@ -144,61 +144,61 @@ }; public void addSubLedger(){ - JXTreeTable accountsTreeTable = view.getAccountsTreeTable(); - AccountTreeTableModel accountsTreeTableModel = - (AccountTreeTableModel)accountsTreeTable.getTreeTableModel(); - - Account newAccount = new AccountImpl(); - SubLedgerForm subledgerForm = new SubLedgerForm(view); - subledgerForm.setAccount(newAccount); - // jaxx constructor don't call super() ? - subledgerForm.setLocationRelativeTo(view); - subledgerForm.setVisible(true); - newAccount=subledgerForm.getAccount(); - - // null == cancel action - if (newAccount != null) { - Account parentAccount = new AccountImpl(); - String number = newAccount.getAccountNumber(); + + JXTreeTable accountsTreeTable = view.getAccountsTreeTable(); + AccountTreeTableModel accountsTreeTableModel = + (AccountTreeTableModel)accountsTreeTable.getTreeTableModel(); + Account newAccount = new AccountImpl(); + SubLedgerForm subledgerForm = new SubLedgerForm(view); + subledgerForm.setAccount(newAccount); + // jaxx constructor don't call super() ? + subledgerForm.setLocationRelativeTo(view); + subledgerForm.setVisible(true); + newAccount=subledgerForm.getAccount(); + + // null == cancel action + if (newAccount != null) { + Account parentAccount = new AccountImpl(); + String number = newAccount.getAccountNumber(); - //search for the nearest account from the one been created - //e.g.: for 41019 search for 4, 41, 410, 4101 - //and stop when the account doesn't exist, use last account found instead - for (int i = 1; i<=number.length(); i++) { - try { - //get the parent account from the new account subnumber - parentAccount = accountService.getAccountByNumber(number.substring(0, i)); - } catch (LimaException eee) { - log.debug("Can't search account : " + number.substring(0, i), eee); - } - if (parentAccount == null) { - try { - //if the account is null, get the previous account searched then stop the loop - parentAccount = accountService.getAccountByNumber(number.substring(0, i-1)); - break; - } catch (LimaException eee) { - log.debug("Can't search account : " + number.substring(0, i-1), eee); - } - } - } + //search for the nearest account from the one been created + //e.g.: for 41019 search for 4, 41, 410, 4101 + //and stop when the account doesn't exist, use last account found instead + for (int i = 1; i<=number.length(); i++) { + try { + //get the parent account from the new account subnumber + parentAccount = accountService.getAccountByNumber(number.substring(0, i)); + } catch (LimaException eee) { + log.debug("Can't search account : " + number.substring(0, i), eee); + } + if (parentAccount == null) { + try { + //if the account is null, get the previous account searched then stop the loop + parentAccount = accountService.getAccountByNumber(number.substring(0, i-1)); + break; + } catch (LimaException eee) { + log.debug("Can't search account : " + number.substring(0, i-1), eee); + } + } + } - // add it - try { - accountsTreeTableModel.addSubLedger(parentAccount, newAccount); - } catch (LimaBusinessException eee) { - if (log.isErrorEnabled()) { - log.error("Can't add subledger", eee); - } - DialogHelper.showMessageDialog(eee.getMessage()); - } + // add it + try { + accountsTreeTableModel.addSubLedger(parentAccount, newAccount); + } catch (LimaBusinessException eee) { + if (log.isErrorEnabled()) { + log.error("Can't add subledger", eee); + } + DialogHelper.showMessageDialog(eee.getMessage()); + } - catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't add subledger", eee); - } - DialogHelper.showMessageDialog(eee.getMessage()); - } - } + catch (LimaException eee) { + if (log.isErrorEnabled()) { + log.error("Can't add subledger", eee); + } + DialogHelper.showMessageDialog(eee.getMessage()); + } + } } /** @@ -223,7 +223,7 @@ treePath = new TreePath(accountsTreeTableModel.getRoot()); } //test if selectedrow is account or ledger - if (selectedObject.getGeneralLedger()==null){ + if (selectedObject.getGeneralLedger()==null) { AccountForm accountForm = new AccountForm(view); accountForm.setAccount(selectedObject); // jaxx constructor don't call super() ? @@ -231,9 +231,9 @@ accountForm.setVisible(true); // null == cancel action selectedObject = accountForm.getAccount(); - } + } // else is a subledger - else{ + else { SubLedgerForm subLedgerForm = new SubLedgerForm(view); subLedgerForm.setAccount(selectedObject); // jaxx constructor don't call super() ? @@ -243,11 +243,11 @@ selectedObject = subLedgerForm.getAccount(); } //if action confirmed - if (selectedObject != null){ + if (selectedObject != null) { // update it try { accountsTreeTableModel. - updateAccount(treePath, selectedObject); + updateAccount(selectedObject); } catch (LimaException eee) { if (log.isErrorEnabled()) { log.error("Can't add update", eee); 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 2011-08-09 12:38:19 UTC (rev 3256) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/SubLedgerForm.jaxx 2011-08-10 11:38:02 UTC (rev 3257) @@ -28,8 +28,6 @@ onWindowClosing="performCancel();"> <org.chorem.lima.entity.Account id="account" javaBean='null'/> - - <Boolean id="addState" javaBean='true'/> <script> <![CDATA[ @@ -47,7 +45,7 @@ <JLabel text="lima.common.code"/> </cell> <cell fill="horizontal"> - <JTextField id="numberTextField" editable='{isAddState()}' + <JTextField id="numberTextField" text="{getAccount().getAccountNumber()}"/> <javax.swing.text.Document javaBean="getNumberTextField().getDocument()" onInsertUpdate='getAccount().setAccountNumber(getNumberTextField().getText())' Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2011-08-09 12:38:19 UTC (rev 3256) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2011-08-10 11:38:02 UTC (rev 3257) @@ -70,6 +70,7 @@ lima.common.globalexception=Global lima exception lima.common.info=Information lima.common.label=Label +lima.common.masteraccount=Master account lima.common.movmentedfilter=Accounts filtered lima.common.next=Next lima.common.ok=OK Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2011-08-09 12:38:19 UTC (rev 3256) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2011-08-10 11:38:02 UTC (rev 3257) @@ -70,6 +70,7 @@ lima.common.globalexception=Global lima exception lima.common.info=Information lima.common.label=Libellé +lima.common.masteraccount=Compte parent lima.common.movmentedfilter=Comptes mouvementés lima.common.next=Suivant lima.common.ok=OK