r3563 - in trunk: lima-business/src/main/java/org/chorem/lima/business/accountingrules lima-business/src/main/java/org/chorem/lima/business/ejb lima-swing/src/main/java/org/chorem/lima/ui/lettering lima-swing/src/main/resources lima-swing/src/main/resources/i18n
Author: mallon Date: 2012-08-02 19:06:11 +0200 (Thu, 02 Aug 2012) New Revision: 3563 Url: http://chorem.org/repositories/revision/lima/3563 Log: refs #726 Correction permettant d ajouter une entree avec la difference entre les deux selectionnees, et portant le meme numero de compte que ces deux dernieres. Une autre entree est aussi ajoutee, en credit / debit, en 658 / 758. Un enum a aussi ete ajoute pour les modes correspondant aux boutons, pour plus de clarte - Reste a repartir le code ne devant pas etre dans le handler dans un service. Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties trunk/lima-swing/src/main/resources/log4j.properties 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-08-02 09:45:20 UTC (rev 3562) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2012-08-02 17:06:11 UTC (rev 3563) @@ -258,17 +258,24 @@ try { + if (log.isDebugEnabled()) { + log.debug("entry : " + entry); + log.debug("entryOld : " + entryOld); + } + FinancialPeriodDAO financialPeriodDAO = getDaoHelper().getFinancialPeriodDAO(); FinancialPeriod financialPeriod = financialPeriodDAO.findByDate(entry.getFinancialTransaction().getTransactionDate()); ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = getDaoHelper().getClosedPeriodicEntryBookDAO(); - //second case - ClosedPeriodicEntryBook closedPeriodicEntryBook = - closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod( - entryOld.getFinancialTransaction().getEntryBook(), financialPeriod); - if (closedPeriodicEntryBook.getLocked()) { - throw new LimaBusinessException(_("lima-Business.defaultaccountingrules.updateentryerror")); + if (entryOld != null) { + //second case + ClosedPeriodicEntryBook closedPeriodicEntryBook = + closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod( + entryOld.getFinancialTransaction().getEntryBook(), financialPeriod); + if (closedPeriodicEntryBook.getLocked()) { + throw new LimaBusinessException(_("lima-Business.defaultaccountingrules.updateentryerror")); + } } //third case Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2012-08-02 09:45:20 UTC (rev 3562) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2012-08-02 17:06:11 UTC (rev 3563) @@ -370,7 +370,6 @@ AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); try { - EntryDAO entryDAO = getDaoHelper().getEntryDAO(); Entry entryOld = entryDAO.findByTopiaId(entry.getTopiaId()); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java 2012-08-02 09:45:20 UTC (rev 3562) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java 2012-08-02 17:06:11 UTC (rev 3563) @@ -237,13 +237,15 @@ public void updateLettersSelectedEntries(int[] entries, String letters) { for (int rowEntry : entries){ getEntryAt(rowEntry).setLettering(letters); + fireTableRowsUpdated(rowEntry, rowEntry); } - fireTableDataChanged(); +// fireTableDataChanged(); } /**Copy parametrised entry, without amount*/ public Entry copyEntryWithoutAmount(Entry entryToCopy) { Entry copiedEntry = new EntryImpl(); + copiedEntry.setAccount(entryToCopy.getAccount()); copiedEntry.setDescription(entryToCopy.getDescription()); copiedEntry.setDetail(entryToCopy.getDetail()); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 2012-08-02 09:45:20 UTC (rev 3562) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 2012-08-02 17:06:11 UTC (rev 3563) @@ -34,6 +34,7 @@ import org.chorem.lima.business.api.FinancialPeriodService; import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.api.FiscalPeriodService; +import org.chorem.lima.business.ejb.FinancialTransactionServiceImpl; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.FiscalPeriod; @@ -48,6 +49,8 @@ import java.util.Date; import java.util.List; +import static org.nuiton.i18n.I18n._; + /** * Handler associated with financial transaction view. * @@ -76,6 +79,7 @@ protected BigDecimal solde = BigDecimal.ZERO; protected LettringSelectionModel lettringSelectionModel; protected LetteringEditModel editModel; + protected enum buttonMode {DELETTRED, LETTRED, EQUALIZED, ALL} private static final Log log = LogFactory.getLog(LetteringViewHandler.class); public LetteringViewHandler(LetteringView view) { @@ -107,7 +111,7 @@ public void balanceAndActions() { if (view.getTable().getSelectedRows().length == 0) { - onButtonModeChanged("all"); + onButtonModeChanged(buttonMode.ALL); } else if (!letteringNotExist(view.getTable().getSelectedRow())) { //lettred entries @@ -115,7 +119,7 @@ setValuesForSelectedEntries(); //For U.I. buttons (Lettering and unlettering) - onButtonModeChanged("delettrer"); + onButtonModeChanged(buttonMode.DELETTRED); } else { if (log.isDebugEnabled()) { log.debug("unlettred entries"); @@ -145,13 +149,13 @@ !amountFirst.equals(BigDecimal.ZERO) && !amountSecond.equals(BigDecimal.ZERO) && secondSelectedEntry.getDebit() != firstSelectedEntry.getDebit() && !amountFirst.equals(amountSecond)) { - onButtonModeChanged("equalized"); + onButtonModeChanged(buttonMode.EQUALIZED); } }else { if (log.isDebugEnabled()) { log.debug("!2 rows selected"); } - onButtonModeChanged("all"); + onButtonModeChanged(buttonMode.ALL); } //Unlettred entries @@ -162,12 +166,12 @@ log.debug("Rows selected"); } setValuesForSelectedEntries(); - onButtonModeChanged("lettrer"); + onButtonModeChanged(buttonMode.LETTRED); } else { if (log.isDebugEnabled()) { log.debug("No Rows selected"); } - onButtonModeChanged("all"); + onButtonModeChanged(buttonMode.ALL); } } } @@ -186,8 +190,27 @@ return emptyOrNull; } - public void onButtonModeChanged(String mode) { - if (mode.equals("delettrer")) { + public void onButtonModeChanged(buttonMode buttonMode) { + + switch (buttonMode) { + case DELETTRED : + editModel.setLettred(false); + editModel.setUnLettred(true); + break; + case LETTRED: + editModel.setUnLettred(false); + editModel.setLettred(true); + break; + case EQUALIZED: + editModel.setEqualized(true); + break; + default: + editModel.setLettred(false); + editModel.setUnLettred(false); + editModel.setEqualized(false); + } + + /*if (mode.equals(buttonMode.DELETTRED)) { editModel.setLettred(false); editModel.setUnLettred(true); } else if (mode.equals("lettrer")) { @@ -202,7 +225,7 @@ editModel.setLettred(false); editModel.setUnLettred(false); editModel.setEqualized(false); - } + }*/ } public void setValuesForSelectedEntries() { @@ -313,7 +336,6 @@ view.getTableModel().updateEntries(entries, datesEntree, journalEntrees); } onBalanceChanged(null); - //view.getLettringSelectionModel().clearSelection(); } /**To make the difference between two selected entries and @@ -344,28 +366,42 @@ BigDecimal firstEntryDebitSubtract = firstEntryDebitCredit[0].subtract(secondEntryDebitCredit[1]); BigDecimal secondEntryDebitSubtract = secondEntryDebitCredit[0].subtract(firstEntryDebitCredit[1]); - /*Create handle of new future entry*/ - Entry entry; + /*Create handles of new futures entries*/ + Entry sameAccountEntry; + Entry costOrProductEntry; - /*Set result in the amount of the new entry*/ + /*Set result in the amount of the new entries*/ if (firstEntryDebitSubtract.compareTo(BigDecimal.ZERO) != 0) { - entry = tableModel.copyEntryWithoutAmount(firstSelectedEntry); - amountsCalculation(firstSelectedEntry, secondSelectedEntry, firstEntryDebitSubtract, entry); + sameAccountEntry = tableModel.copyEntryWithoutAmount(firstSelectedEntry); + costOrProductEntry = tableModel.copyEntryWithoutAmount(firstSelectedEntry); + amountsCalculation(firstEntryDebitSubtract, sameAccountEntry, costOrProductEntry); } else { //firstEntryDebitSubtract == 0 - entry = tableModel.copyEntryWithoutAmount(secondSelectedEntry); - amountsCalculation(firstSelectedEntry, secondSelectedEntry, secondEntryDebitSubtract, entry); + sameAccountEntry = tableModel.copyEntryWithoutAmount(secondSelectedEntry); + costOrProductEntry = tableModel.copyEntryWithoutAmount(secondSelectedEntry); + amountsCalculation(secondEntryDebitSubtract, sameAccountEntry, costOrProductEntry); } - /*Add new entry to the model and the table*/ - tableModel.addEntry(entry, entry.getFinancialTransaction().getTransactionDate()); + String accountRegularization = _("lima.ui.lettering.accountRegularization"); - /*Save in DB the new entry*/ - financialTransactionService.createEntry(entry); + if (log.isDebugEnabled()) { + log.debug("accountRegularization : " + accountRegularization); + } + sameAccountEntry.setDescription(accountRegularization); + costOrProductEntry.setDescription(accountRegularization); + + /*Save in the DB the new entries*/ + Entry newSameAccountEntry = financialTransactionService.createEntry(sameAccountEntry); + Entry newCostOrProductEntry = financialTransactionService.createEntry(costOrProductEntry); + + /*Add new entries to the model and the table*/ + tableModel.addEntry(newSameAccountEntry, newSameAccountEntry.getFinancialTransaction().getTransactionDate()); + tableModel.addEntry(newCostOrProductEntry, newCostOrProductEntry.getFinancialTransaction().getTransactionDate()); + /*Re-select the two entries (firstSelectedEntry and secondSelectedEntry) - * and the new entry + * and the new sameAccountEntry * */ - view.getLettringSelectionModel().selectRoundedAndNewEntries(selectedRows[0], selectedRows[1], entry); + view.getLettringSelectionModel().selectRoundedAndNewEntries(selectedRows[0], selectedRows[1], newSameAccountEntry); } } } @@ -388,31 +424,29 @@ } /** - *Calculation of amount for the new entry created and one of the two old entries - * @param firstSelectedEntry first selected entry - * @param secondSelectedEntry second selected entry + *Calculation of amount for the new entries created + * and determine for the second if account is in costs (658) + * or products (758) * @param resultOfFirstSecondEntrySubtraction difference between the two old entries - * @param newEntry new entry created + * @param sameAccountEntry first new entry created with the same account + * @param costOrProductEntry second new entry created with account 658 or 758 * */ - protected void amountsCalculation(Entry firstSelectedEntry, Entry secondSelectedEntry, BigDecimal resultOfFirstSecondEntrySubtraction, Entry newEntry) { - BigDecimal newDebitOrCredit; - if (secondSelectedEntry.getAmount().compareTo(firstSelectedEntry.getAmount())>0) { - newDebitOrCredit = secondSelectedEntry.getAmount().subtract(resultOfFirstSecondEntrySubtraction.abs()); - secondSelectedEntry.setAmount(newDebitOrCredit); - financialTransactionService.updateEntry(secondSelectedEntry); - } else { - newDebitOrCredit = firstSelectedEntry.getAmount().subtract(resultOfFirstSecondEntrySubtraction.abs()); - firstSelectedEntry.setAmount(newDebitOrCredit); - financialTransactionService.updateEntry(firstSelectedEntry); - } - newEntry.setAmount(resultOfFirstSecondEntrySubtraction.abs()); + protected void amountsCalculation( BigDecimal resultOfFirstSecondEntrySubtraction, Entry sameAccountEntry, Entry costOrProductEntry) { + sameAccountEntry.setAmount(resultOfFirstSecondEntrySubtraction.abs()); + costOrProductEntry.setAmount(resultOfFirstSecondEntrySubtraction.abs()); + Account costOrProductAccount; /*-1 for less than 0 : credit*/ if (resultOfFirstSecondEntrySubtraction.compareTo(BigDecimal.ZERO) == -1) { - newEntry.setDebit(false); + sameAccountEntry.setDebit(true); + costOrProductEntry.setDebit(false); + costOrProductAccount = accountService.getAccountByNumber("758"); } else { /*Greater than 0 : debit*/ - newEntry.setDebit(true); + sameAccountEntry.setDebit(false); + costOrProductEntry.setDebit(true); + costOrProductAccount = accountService.getAccountByNumber("658"); } + costOrProductEntry.setAccount(costOrProductAccount); } /**To test if the filter contain an account and a period @@ -461,22 +495,24 @@ public void addLetter() { String newLetters = financialTransactionService.getNextLetters(); changeLetter(newLetters); + onButtonModeChanged(buttonMode.DELETTRED); } /**Remove a group of three letters to n entries*/ public void removeLetter() { changeLetter(null); + onButtonModeChanged(buttonMode.LETTRED); } /**Add or remove a group of three letters to n entries*/ protected void changeLetter(String newLetters) { + int[] entrieSelected = view.getTable().getSelectedRows(); view.getTableModel().updateLettersSelectedEntries(entrieSelected, newLetters); for (int indexEntry : entrieSelected){ financialTransactionService.updateEntry(view.getTableModel().getEntryAt(indexEntry)); - view.getTable().addRowSelectionInterval(indexEntry, indexEntry); } } 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 2012-08-02 09:45:20 UTC (rev 3562) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2012-08-02 17:06:11 UTC (rev 3563) @@ -326,6 +326,7 @@ lima.ui.importexport.wait=Job in progress… lima.ui.importexport.waittitle= lima.ui.lettering.account=Accounts +lima.ui.lettering.accountRegularization=Lettering regularization lima.ui.lettering.actions=Actions lima.ui.lettering.beginFinancialPeriod=From lima.ui.lettering.buttonAuto=Auto 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 2012-08-02 09:45:20 UTC (rev 3562) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2012-08-02 17:06:11 UTC (rev 3563) @@ -326,6 +326,7 @@ lima.ui.importexport.wait=Traitement en cours… lima.ui.importexport.waittitle=Traitement en cours lima.ui.lettering.account=Comptes +lima.ui.lettering.accountRegularization=Régularisation lettrage lima.ui.lettering.actions=Actions lima.ui.lettering.beginFinancialPeriod=De lima.ui.lettering.buttonAuto=Auto Modified: trunk/lima-swing/src/main/resources/log4j.properties =================================================================== --- trunk/lima-swing/src/main/resources/log4j.properties 2012-08-02 09:45:20 UTC (rev 3562) +++ trunk/lima-swing/src/main/resources/log4j.properties 2012-08-02 17:06:11 UTC (rev 3563) @@ -43,4 +43,6 @@ log4j.logger.org.chorem.lima.ui.lettering.LettringSelectionModel=DEBUG log4j.logger.org.chorem.lima.ui.lettering.LetteringEditModel=DEBUG log4j.logger.org.chorem.lima.ui.financialtransaction.FinancialTransactionTableModel=DEBUG -log4j.logger.org.chorem.lima.ui.celleditor.BigDecimalTableCellEditor=DEBUG \ No newline at end of file +log4j.logger.org.chorem.lima.ui.celleditor.BigDecimalTableCellEditor=DEBUG +log4j.logger.org.chorem.lima.business.accountingrules.DefaultAccountingRules=DEBUG +log4j.logger.org.chorem.lima.business.ejb.FinancialTransactionServiceImpl=DEBUG \ No newline at end of file
participants (1)
-
mallon@users.chorem.org