Example usage for java.math BigDecimal subtract

List of usage examples for java.math BigDecimal subtract

Introduction

In this page you can find the example usage for java.math BigDecimal subtract.

Prototype

public BigDecimal subtract(BigDecimal subtrahend) 

Source Link

Document

Returns a BigDecimal whose value is (this - subtrahend) , and whose scale is max(this.scale(), subtrahend.scale()) .

Usage

From source file:nl.strohalm.cyclos.services.transactions.PaymentServiceImpl.java

/**
 * Validates the given amount/*from   ww w . jav  a 2  s .  c  om*/
 */
private void validateAmount(final BigDecimal amount, Account fromAccount, final Account toAccount,
        final Transfer transfer) {
    // Validate the from account credit limit ...
    final LocalSettings localSettings = settingsService.getLocalSettings();
    if (fromAccount != null) {
        final BigDecimal creditLimit = fromAccount.getCreditLimit();
        if (creditLimit != null) {
            // ... only if not unlimited
            final AccountStatus fromStatus = accountService.getCurrentStatus(new AccountDTO(fromAccount));
            if (creditLimit.abs().floatValue() > -PRECISION_DELTA) {
                final BigDecimal available = localSettings.round(fromStatus.getAvailableBalance());
                if (available.subtract(amount).floatValue() < -PRECISION_DELTA) {
                    final boolean isOriginalAccount = transfer == null ? true
                            : fromAccount.equals(transfer.getRootTransfer().getFrom());
                    fromAccount = fetchService.fetch(fromAccount, Account.Relationships.TYPE);
                    throw new NotEnoughCreditsException(fromAccount, amount, isOriginalAccount);
                }
            }
        }
    }

    // Validate the to account upper credit limit
    if (toAccount != null) {
        final BigDecimal upperCreditLimit = toAccount.getUpperCreditLimit();
        if (upperCreditLimit != null && upperCreditLimit.floatValue() > PRECISION_DELTA) {
            final BigDecimal balance = accountService.getBalance(new AccountDateDTO(toAccount));
            if (upperCreditLimit.subtract(balance).subtract(amount).floatValue() < -PRECISION_DELTA) {
                throw new UpperCreditLimitReachedException(
                        localSettings.getUnitsConverter(toAccount.getType().getCurrency().getPattern())
                                .toString(toAccount.getUpperCreditLimit()),
                        toAccount, amount);
            }
        }
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getBatVar1() {
    try {//from ww  w .ja v  a2  s  . c o m
        BigDecimal res = new BigDecimal(financialRatio.getBat().doubleValue());
        res = res.divide(financialRatioCompOne.getBat(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getBatVar2() {
    try {/*from   w  w w.j  a  v  a  2s . c  o m*/
        BigDecimal res = new BigDecimal(financialRatio.getBat().doubleValue());
        res = res.divide(financialRatioCompTwo.getBat(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getBdtVar1() {
    try {/*from  ww w  .  ja  v a 2 s  . c om*/
        BigDecimal res = new BigDecimal(financialRatio.getBdt().doubleValue());
        res = res.divide(financialRatioCompOne.getBdt(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getBdtVar2() {
    try {//  ww w. ja  v a  2  s  . com
        BigDecimal res = new BigDecimal(financialRatio.getBdt().doubleValue());
        res = res.divide(financialRatioCompTwo.getBdt(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getBaitVar1() {
    try {/*w ww  . ja v  a  2  s . c  om*/
        BigDecimal res = new BigDecimal(financialRatio.getBait().doubleValue());
        res = res.divide(financialRatioCompOne.getBait(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getBaitVar2() {
    try {//from  w  ww.j  a v a2s.  c o  m
        BigDecimal res = new BigDecimal(financialRatio.getBait().doubleValue());
        res = res.divide(financialRatioCompTwo.getBait(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getTaxesVar1() {
    try {//www  .j  a  v  a 2  s.  com
        BigDecimal res = new BigDecimal(financialRatio.getTaxes().doubleValue());
        res = res.divide(financialRatioCompOne.getTaxes(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getTaxesVar2() {
    try {//  w  ww.java2s. c o m
        BigDecimal res = new BigDecimal(financialRatio.getTaxes().doubleValue());
        res = res.divide(financialRatioCompTwo.getTaxes(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getBaitdVar1() {
    try {// w  w w . jav  a2 s .  c om
        BigDecimal res = new BigDecimal(financialRatio.getBaitd().doubleValue());
        res = res.divide(financialRatioCompOne.getBaitd(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}