r3564 - in trunk: lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/main/java/org/chorem/lima/business/utils lima-swing/src/main/java/org/chorem/lima/ui/lettering
Author: mallon Date: 2012-08-03 17:02:44 +0200 (Fri, 03 Aug 2012) New Revision: 3564 Url: http://chorem.org/repositories/revision/lima/3564 Log: fixes #735 Correction permettant une meilleure incr?\195?\169mentation du lettrage. Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/utils/LetteringComparator.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-02 17:06:11 UTC (rev 3563) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2012-08-03 15:02:44 UTC (rev 3564) @@ -25,6 +25,8 @@ package org.chorem.lima.business.ejb; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.FinancialTransactionSearch; import org.chorem.lima.beans.LetteringFilter; import org.chorem.lima.business.AccountingRules; @@ -83,6 +85,8 @@ @EJB protected OptionsService optionsService; + protected static final Log log = LogFactory.getLog(FinancialTransactionServiceImpl.class); + @Override public FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { @@ -126,6 +130,7 @@ @Override public String getNextLetters() throws LimaException { String lastActualLetters; + String nextLetters = ""; try { EntryDAO entryDAO = getDaoHelper().getEntryDAO(); @@ -137,14 +142,58 @@ } /**Increment letter alphabetically*/ - if (lastActualLetters.charAt(0) != 'Z') { - String finLastActualLetters = lastActualLetters.substring(1, lastActualLetters.length()); - return String.valueOf( (char) (lastActualLetters.charAt(0) + 1)) + finLastActualLetters; + int indexCharToIncrement = 0; + int lastActualLettersLength = lastActualLetters.length(); + String findLastLetters; + String findFirstLetters =""; + int numberOfA; + + /*Searching which letter is 'Z', and so must be incremented*/ + for (int i = 0; i < lastActualLettersLength; i++) { + if (lastActualLetters.charAt(i) != 'Z') { + indexCharToIncrement = i; + } + } + + /*When no letter, just set 'A'*/ + if (lastActualLettersLength != 0) { + + /*Get first letter(s), only if we have more of one letter (One letter = letter to increment)*/ + String firstPartActualLetters = lastActualLetters.substring(0, indexCharToIncrement); + if (firstPartActualLetters.length() > 1) { + findFirstLetters = firstPartActualLetters; + } + + /*Get the letters after the correct letter to increment and + *increment it (Using 'indexCharToIncrement') + * */ + findLastLetters = lastActualLetters.substring(indexCharToIncrement+1, lastActualLettersLength); + if (lastActualLetters.charAt(indexCharToIncrement) != 'Z') { + /*Last letters transform to x 'A' (x = Number of 'Z'), if they are 'Z'*/ + if (findLastLetters.length() > 0) { + if (findLastLetters.charAt(0) == 'Z') { + numberOfA = findLastLetters.length(); + findLastLetters=getCharsA(numberOfA); + } + } + nextLetters = findFirstLetters + String.valueOf( (char) (lastActualLetters.charAt(indexCharToIncrement) + 1)) + findLastLetters; + } + } else { - return "A" + lastActualLetters; + numberOfA = lastActualLettersLength +1; + nextLetters = getCharsA(numberOfA); } + return nextLetters; } + protected String getCharsA(int numberOfA) { + String charsA=""; + for (int j = 0; j < numberOfA; j++) { + charsA = charsA+"A"; + } + return charsA; + } + public String findLastLetter(List<String> letters) { String result; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/LetteringComparator.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/LetteringComparator.java 2012-08-02 17:06:11 UTC (rev 3563) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/LetteringComparator.java 2012-08-03 15:02:44 UTC (rev 3564) @@ -3,13 +3,6 @@ import java.io.Serializable; import java.util.Comparator; -/** - * Created with IntelliJ IDEA. - * User: mallon - * Date: 24/07/12 - * Time: 15:39 - * To change this template use File | Settings | File Templates. - */ public class LetteringComparator implements Serializable , Comparator<String> { private static final long serialVersionUID = 1L; 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 17:06:11 UTC (rev 3563) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 2012-08-03 15:02:44 UTC (rev 3564) @@ -134,21 +134,13 @@ Entry firstSelectedEntry = tableModel.getEntryAt(selectedRows[0]); Entry secondSelectedEntry = tableModel.getEntryAt(selectedRows[1]); - BigDecimal [] amountFirstEntry = debitCreditCalculation(firstSelectedEntry); - BigDecimal amountFirst = amountFirstEntry[0].equals(BigDecimal.ZERO)?amountFirstEntry[1]:amountFirstEntry[0]; - BigDecimal [] amountSecondEntry = debitCreditCalculation(secondSelectedEntry); - BigDecimal amountSecond = amountSecondEntry[0].equals(BigDecimal.ZERO)?amountSecondEntry[1]:amountSecondEntry[0]; + /*Get decimals*/ + BigDecimal firstSelectedEntryAmount = firstSelectedEntry.getAmount(); + BigDecimal secondSelectedEntryAmount = secondSelectedEntry.getAmount(); - if (log.isDebugEnabled()) { - log.debug(amountFirst + " - " + amountSecond); - } - - /*String decimalFirstEntrySelected = (firstSelectedEntry.getAmount().toString().split("\\."))[1]; - String decimalSecondSelectedEntry = (secondSelectedEntry.getAmount().toString().split("\\."))[1];*/ - if ( /*(!decimalFirstEntrySelected.equals("00") || !decimalSecondSelectedEntry.equals("00"))*/ - !amountFirst.equals(BigDecimal.ZERO) && !amountSecond.equals(BigDecimal.ZERO) - && secondSelectedEntry.getDebit() != firstSelectedEntry.getDebit() - && !amountFirst.equals(amountSecond)) { + if ( secondSelectedEntry.getDebit() != firstSelectedEntry.getDebit() + && firstSelectedEntryAmount.subtract(secondSelectedEntryAmount).abs().compareTo(BigDecimal.ZERO) >=0 + && firstSelectedEntryAmount.subtract(secondSelectedEntryAmount).abs().compareTo(BigDecimal.ONE) <=0) { onButtonModeChanged(buttonMode.EQUALIZED); } }else { @@ -353,9 +345,14 @@ Entry firstSelectedEntry = tableModel.getEntryAt(selectedRows[0]); Entry secondSelectedEntry = tableModel.getEntryAt(selectedRows[1]); - if ( (firstSelectedEntry.getAmount().compareTo(BigDecimal.ZERO) != 0 && secondSelectedEntry.getAmount().compareTo(BigDecimal.ZERO) != 0) - && !firstSelectedEntry.getAmount().equals(secondSelectedEntry.getAmount())) { + BigDecimal firstSelectedEntryAmount = firstSelectedEntry.getAmount(); + BigDecimal secondSelectedEntryAmount = secondSelectedEntry.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*/
participants (1)
-
mallon@users.chorem.org