r3565 - in trunk: lima-business/src/main/java/org/chorem/lima/business/ejb lima-business-api/src/main/java/org/chorem/lima/business/api lima-swing/src/main/java/org/chorem/lima/ui/lettering
Author: mallon Date: 2012-08-03 17:55:10 +0200 (Fri, 03 Aug 2012) New Revision: 3565 Url: http://chorem.org/repositories/revision/lima/3565 Log: fixes #726 Deplacement de code du handler du lettrage dans le service adequat Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.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 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-03 15:02:44 UTC (rev 3564) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2012-08-03 15:55:10 UTC (rev 3565) @@ -32,6 +32,7 @@ import org.chorem.lima.business.AccountingRules; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.api.AccountService; import org.chorem.lima.business.api.EntryBookService; import org.chorem.lima.business.api.FinancialPeriodService; import org.chorem.lima.business.api.FinancialTransactionService; @@ -43,6 +44,7 @@ import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryDAO; +import org.chorem.lima.entity.EntryImpl; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FinancialTransactionDAO; @@ -59,6 +61,8 @@ import java.util.Date; import java.util.List; +import static org.nuiton.i18n.I18n._; + /** * Cette classe permet la création d'une transaction comptable dans l'application. * Toute action sur une transaction entraîne automatiquement une création de log. @@ -83,6 +87,9 @@ protected EntryBookService entryBookService; @EJB + protected AccountService accountService; + + @EJB protected OptionsService optionsService; protected static final Log log = LogFactory.getLog(FinancialTransactionServiceImpl.class); @@ -186,6 +193,117 @@ return nextLetters; } + @Override + public Entry[] getEntriesFromEqualizing(Entry FirstEntrySelected, Entry SecondEntrySelected) throws LimaException{ + + Entry newSameAccountEntry = null; + Entry newCostOrProductEntry = null; + BigDecimal firstSelectedEntryAmount = FirstEntrySelected.getAmount(); + BigDecimal secondSelectedEntryAmount = SecondEntrySelected.getAmount(); + + if ( (firstSelectedEntryAmount.compareTo(BigDecimal.ZERO) != 0 && secondSelectedEntryAmount.compareTo(BigDecimal.ZERO) != 0) + && !firstSelectedEntryAmount.equals(secondSelectedEntryAmount)) { + + /*Calculation of result with it + * Tab : 0 : debit + * 1 : credit*/ + BigDecimal[] firstEntryDebitCredit = debitCreditCalculation(FirstEntrySelected); + BigDecimal[] secondEntryDebitCredit = debitCreditCalculation(SecondEntrySelected); + + /*Subtraction between debit and credit of first and second selected line*/ + BigDecimal firstEntryDebitSubtract = firstEntryDebitCredit[0].subtract(secondEntryDebitCredit[1]); + BigDecimal secondEntryDebitSubtract = secondEntryDebitCredit[0].subtract(firstEntryDebitCredit[1]); + + /*Create handles of new futures entries*/ + Entry sameAccountEntry; + Entry costOrProductEntry; + + /*Set result in the amount of the new entries*/ + if (firstEntryDebitSubtract.compareTo(BigDecimal.ZERO) != 0) { + sameAccountEntry = copyEntryWithoutAmount(FirstEntrySelected); + costOrProductEntry = copyEntryWithoutAmount(FirstEntrySelected); + amountsCalculation(firstEntryDebitSubtract, sameAccountEntry, costOrProductEntry); + } else { + sameAccountEntry = copyEntryWithoutAmount(SecondEntrySelected); + costOrProductEntry = copyEntryWithoutAmount(SecondEntrySelected); + amountsCalculation(secondEntryDebitSubtract, sameAccountEntry, costOrProductEntry); + } + + String accountRegularization = _("lima.ui.lettering.accountRegularization"); + + if (log.isDebugEnabled()) { + log.debug("accountRegularization : " + accountRegularization); + } + + sameAccountEntry.setDescription(accountRegularization); + costOrProductEntry.setDescription(accountRegularization); + + /*Save in the DB the new entries*/ + newSameAccountEntry = createEntry(sameAccountEntry); + newCostOrProductEntry = createEntry(costOrProductEntry); + + } + + Entry [] entries = {newSameAccountEntry, newCostOrProductEntry}; + return entries; + } + + /**Debit and credit calculation for one entry, with its amount + * @param entry Entry for calculation + * @return table of two big decimal, representing respectively debit and credit + * */ + protected BigDecimal[] debitCreditCalculation(Entry entry) { + + boolean firstEntryDebit = entry.getDebit(); + BigDecimal firstEntryAmount = entry.getAmount(); + + BigDecimal debitVal = firstEntryDebit ? firstEntryAmount : BigDecimal.ZERO; + BigDecimal creditVal = firstEntryDebit ? BigDecimal.ZERO : firstEntryAmount; + + BigDecimal[] debitCredit = {debitVal, creditVal}; + + return debitCredit; + } + + /**Copy parametrised entry, without amount*/ + protected Entry copyEntryWithoutAmount(Entry entryToCopy) { + Entry copiedEntry = new EntryImpl(); + + copiedEntry.setAccount(entryToCopy.getAccount()); + copiedEntry.setDescription(entryToCopy.getDescription()); + copiedEntry.setDetail(entryToCopy.getDetail()); + copiedEntry.setFinancialTransaction(entryToCopy.getFinancialTransaction()); + copiedEntry.setVoucher(entryToCopy.getVoucher()); + + return copiedEntry; + } + + /** + *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 sameAccountEntry first new entry created with the same account + * @param costOrProductEntry second new entry created with account 658 or 758 + * */ + 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) { + sameAccountEntry.setDebit(true); + costOrProductEntry.setDebit(false); + costOrProductAccount = accountService.getAccountByNumber("758"); + } else { /*Greater than 0 : debit*/ + sameAccountEntry.setDebit(false); + costOrProductEntry.setDebit(true); + costOrProductAccount = accountService.getAccountByNumber("658"); + } + costOrProductEntry.setAccount(costOrProductAccount); + } + protected String getCharsA(int numberOfA) { String charsA=""; for (int j = 0; j < numberOfA; j++) { @@ -353,13 +471,6 @@ Date financialTransactionOldDate = financialTransactionOld.getTransactionDate(); Date financialTransactionDate = financialTransaction.getTransactionDate(); - if (log.isDebugEnabled()) { - log.debug("Date de la transaction (Old) : " + financialTransactionOldDate); - } - if (log.isDebugEnabled()) { - log.debug("Date de la transaction (New) : " + financialTransactionDate); - } - financialTransactionOld.setEntryBook(financialTransaction.getEntryBook()); financialTransactionOld.setTransactionDate(financialTransactionDate); Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2012-08-03 15:02:44 UTC (rev 3564) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2012-08-03 15:55:10 UTC (rev 3565) @@ -79,10 +79,20 @@ String getNextLetters() throws LimaException; /** - * Retourne toutes les entrées d'une transaction - * pour un compte et la présence d'un lettrage ou (xor) non - * @param filter filtre sur les entrees, selon le compte, les dates de debut et de fin, et le lettrage - * @throws org.nuiton.topia.TopiaException - * */ + * From to selected entries, create one with same account and + * difference between the amounts, and another one with + * account 658 or 758 and an amount conversely of the first created + * @param FirstEntrySelected first entry selected + * @param SecondEntrySelected second entry selected + * @return table of the two new entries + * */ + Entry[] getEntriesFromEqualizing(Entry FirstEntrySelected, Entry SecondEntrySelected) throws LimaException; + + /** + * Retourne toutes les entrées d'une transaction + * pour un compte et la présence d'un lettrage ou (xor) non + * @param filter filtre sur les entrees, selon le compte, les dates de debut et de fin, et le lettrage + * @throws LimaException + * */ List<Entry> getAllEntrieByDatesAndAccountAndLettering(LetteringFilter filter) throws LimaException; } 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-03 15:02:44 UTC (rev 3564) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java 2012-08-03 15:55:10 UTC (rev 3565) @@ -27,8 +27,6 @@ import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.EntryImpl; - import javax.swing.table.AbstractTableModel; import java.math.BigDecimal; import java.util.Date; @@ -243,7 +241,7 @@ } /**Copy parametrised entry, without amount*/ - public Entry copyEntryWithoutAmount(Entry entryToCopy) { + /*public Entry copyEntryWithoutAmount(Entry entryToCopy) { Entry copiedEntry = new EntryImpl(); copiedEntry.setAccount(entryToCopy.getAccount()); @@ -253,5 +251,5 @@ copiedEntry.setVoucher(entryToCopy.getVoucher()); return copiedEntry; - } + }*/ } 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-03 15:02:44 UTC (rev 3564) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 2012-08-03 15:55:10 UTC (rev 3565) @@ -201,23 +201,6 @@ editModel.setUnLettred(false); editModel.setEqualized(false); } - - /*if (mode.equals(buttonMode.DELETTRED)) { - editModel.setLettred(false); - editModel.setUnLettred(true); - } else if (mode.equals("lettrer")) { - if (log.isDebugEnabled()) { - log.debug("Lettred entry"); - } - editModel.setUnLettred(false); - editModel.setLettred(true); - }else if (mode.equals("equalized")) { - editModel.setEqualized(true); - } else { - editModel.setLettred(false); - editModel.setUnLettred(false); - editModel.setEqualized(false); - }*/ } public void setValuesForSelectedEntries() { @@ -340,112 +323,25 @@ int[] selectedRows = view.getTable().getSelectedRows(); if (selectedRows.length == 2) { - /*Treatment only if one of values contains decimals*/ Entry firstSelectedEntry = tableModel.getEntryAt(selectedRows[0]); Entry secondSelectedEntry = tableModel.getEntryAt(selectedRows[1]); - BigDecimal firstSelectedEntryAmount = firstSelectedEntry.getAmount(); - BigDecimal secondSelectedEntryAmount = secondSelectedEntry.getAmount(); + Entry[] newEntriesFormEqualizing = financialTransactionService.getEntriesFromEqualizing(firstSelectedEntry, secondSelectedEntry); + /*Add new entries to the model and the table*/ + Entry newSameAccountEntry = newEntriesFormEqualizing[0]; + Entry newCostOrProductEntry = newEntriesFormEqualizing[1]; + tableModel.addEntry(newSameAccountEntry, newSameAccountEntry.getFinancialTransaction().getTransactionDate()); + tableModel.addEntry(newCostOrProductEntry, newCostOrProductEntry.getFinancialTransaction().getTransactionDate()); - - if ( (firstSelectedEntryAmount.compareTo(BigDecimal.ZERO) != 0 && secondSelectedEntryAmount.compareTo(BigDecimal.ZERO) != 0) - && !firstSelectedEntryAmount.equals(secondSelectedEntryAmount)) { - - /*Calculation of result with it - * Tab : 0 : debit - * 1 : credit*/ - BigDecimal[] firstEntryDebitCredit = debitCreditCalculation(firstSelectedEntry); - BigDecimal[] secondEntryDebitCredit = debitCreditCalculation(secondSelectedEntry); - - /*Subtraction between debit and credit of first and second selected line*/ - BigDecimal firstEntryDebitSubtract = firstEntryDebitCredit[0].subtract(secondEntryDebitCredit[1]); - BigDecimal secondEntryDebitSubtract = secondEntryDebitCredit[0].subtract(firstEntryDebitCredit[1]); - - /*Create handles of new futures entries*/ - Entry sameAccountEntry; - Entry costOrProductEntry; - - /*Set result in the amount of the new entries*/ - if (firstEntryDebitSubtract.compareTo(BigDecimal.ZERO) != 0) { - sameAccountEntry = tableModel.copyEntryWithoutAmount(firstSelectedEntry); - costOrProductEntry = tableModel.copyEntryWithoutAmount(firstSelectedEntry); - amountsCalculation(firstEntryDebitSubtract, sameAccountEntry, costOrProductEntry); - } else { //firstEntryDebitSubtract == 0 - sameAccountEntry = tableModel.copyEntryWithoutAmount(secondSelectedEntry); - costOrProductEntry = tableModel.copyEntryWithoutAmount(secondSelectedEntry); - amountsCalculation(secondEntryDebitSubtract, sameAccountEntry, costOrProductEntry); - } - - String accountRegularization = _("lima.ui.lettering.accountRegularization"); - - 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 sameAccountEntry - * */ - view.getLettringSelectionModel().selectRoundedAndNewEntries(selectedRows[0], selectedRows[1], newSameAccountEntry); - } + /*Re-select the two entries (firstSelectedEntry and secondSelectedEntry) + * and the new sameAccountEntry + * */ + view.getLettringSelectionModel().selectRoundedAndNewEntries(selectedRows[0], selectedRows[1], newSameAccountEntry); } } - /**Debit and credit calculation for one entry, with its amount - * @param entry Entry for calculation - * @return table of two big decimal, representing respectively debit and credit - * */ - protected BigDecimal[] debitCreditCalculation(Entry entry) { - - boolean firstEntryDebit = entry.getDebit(); - BigDecimal firstEntryAmount = entry.getAmount(); - - BigDecimal debitVal = firstEntryDebit ? firstEntryAmount : BigDecimal.ZERO; - BigDecimal creditVal = firstEntryDebit ? BigDecimal.ZERO : firstEntryAmount; - - BigDecimal[] debitCredit = {debitVal, creditVal}; - - return debitCredit; - } - - /** - *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 sameAccountEntry first new entry created with the same account - * @param costOrProductEntry second new entry created with account 658 or 758 - * */ - 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) { - sameAccountEntry.setDebit(true); - costOrProductEntry.setDebit(false); - costOrProductAccount = accountService.getAccountByNumber("758"); - } else { /*Greater than 0 : debit*/ - sameAccountEntry.setDebit(false); - costOrProductEntry.setDebit(true); - costOrProductAccount = accountService.getAccountByNumber("658"); - } - costOrProductEntry.setAccount(costOrProductAccount); - } - /**To test if the filter contain an account and a period * @return true if filter is valid * */
participants (1)
-
mallon@users.chorem.org