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:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getInfrastructuresVar2() {
    try {//from  www .  j  a v  a  2s  .  c o m
        BigDecimal res = new BigDecimal(financialRatio.getInfrastructures().doubleValue());
        res = res.divide(financialRatioCompTwo.getInfrastructures(), 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 getFinancialExpensesVar1() {
    try {//from  ww  w . ja va 2 s.c om
        BigDecimal res = new BigDecimal(financialRatio.getFinancialExpenses().doubleValue());
        res = res.divide(financialRatioCompOne.getFinancialExpenses(), 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 getFinancialExpensesVar2() {
    try {/*from  ww  w  .  ja v  a2  s.  co m*/
        BigDecimal res = new BigDecimal(financialRatio.getFinancialExpenses().doubleValue());
        res = res.divide(financialRatioCompTwo.getFinancialExpenses(), 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 getShortTermLiabilityVar1() {
    try {// w  w w  .  j  av  a  2  s. c om
        BigDecimal res = new BigDecimal(financialRatio.getShortTermLiability().doubleValue());
        res = res.divide(financialRatioCompOne.getShortTermLiability(), 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 getShortTermLiabilityVar2() {
    try {//  w w w.j a va 2  s  .  c o m
        BigDecimal res = new BigDecimal(financialRatio.getShortTermLiability().doubleValue());
        res = res.divide(financialRatioCompTwo.getShortTermLiability(), 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 getTotalOtherResourcesVar1() {
    try {/*from ww  w  .j  av a 2 s. c  om*/
        BigDecimal res = new BigDecimal(financialRatio.getTotalOtherResources().doubleValue());
        res = res.divide(financialRatioCompOne.getTotalOtherResources(), 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 getTotalOtherResourcesVar2() {
    try {/*from w  ww.j  a  va 2  s .  c o  m*/
        BigDecimal res = new BigDecimal(financialRatio.getTotalOtherResources().doubleValue());
        res = res.divide(financialRatioCompTwo.getTotalOtherResources(), 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 getOtherExploitationExpensesVar1() {
    try {//from w w  w.j a  v a  2  s .  c o  m
        BigDecimal res = new BigDecimal(financialRatio.getOtherExploitationExpenses().doubleValue());
        res = res.divide(financialRatioCompOne.getOtherExploitationExpenses(), 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 getOtherExploitationExpensesVar2() {
    try {/*from  w w  w . j a  v a 2s. c o m*/
        BigDecimal res = new BigDecimal(financialRatio.getOtherExploitationExpenses().doubleValue());
        res = res.divide(financialRatioCompTwo.getOtherExploitationExpenses(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

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

From source file:com.mg.merp.planning.support.MPSProcessorServiceBean.java

private void calculateProductionPlan(short lowLevelCode) {
    //?  PlanningItem, BucketOffset desc
    Collections.sort(generatedMPSLines, new Comparator<MpsLine>() {

        public int compare(MpsLine o1, MpsLine o2) {
            if (o1.getPlanningItem().getId() < o2.getPlanningItem().getId())
                return 1;
            else if (o1.getPlanningItem().getId() > o2.getPlanningItem().getId())
                return -1;
            else {
                if (o1.getBucketOffset() < o2.getBucketOffset())
                    return 1;
                else if (o1.getBucketOffset() > o2.getBucketOffset())
                    return -1;
                else
                    return 0;
            }//from  w  w w. j  a v  a  2 s  .co m
        }

    });

    BigDecimal availableOnBeginBucket = BigDecimal.ZERO;
    GenericItem currentPlanningItem = null;
    for (MpsLine mpsLine : generatedMPSLines) {
        if (MathUtils.compareToZero(mpsLine.getProductionDemandQty()) <= 0
                && mpsLine.getLevelCode() == lowLevelCode) {
            if (currentPlanningItem == null
                    || currentPlanningItem.getId() != mpsLine.getPlanningItem().getId()) {
                currentPlanningItem = mpsLine.getPlanningItem();
                availableOnBeginBucket = BigDecimal.ZERO;
            }

            BigDecimal plannedQty = mpsLine.calculatePlannedQuantity(availableOnBeginBucket);

            Bom bom = bomService.findCurrentBOM(currentPlanningItem.getCatalog().getId());
            if (bom != null) {
                BigDecimal MaxQty = bom.getMaxLotQty(), MinQty = bom.getMinLotQty(),
                        Increment = bom.getLotIncrementQty(), Remainder, RemInc;
                if (!(MathUtils.compareToZeroOrNull(MaxQty) == 0 || MathUtils.compareToZeroOrNull(MinQty) == 0
                        || MathUtils.compareToZeroOrNull(Increment) == 0)) {
                    //?  ?  ?  
                    if (bom.getCatalog().getMeasure1().getId() != mpsLine.getMeasure().getId()) {
                        MaxQty = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(),
                                mpsLine.getMeasure(), bom.getCatalog(), mpsLine.getBucketOffsetDate(), MaxQty);
                        MinQty = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(),
                                mpsLine.getMeasure(), bom.getCatalog(), mpsLine.getBucketOffsetDate(), MinQty);
                        Increment = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(),
                                mpsLine.getMeasure(), bom.getCatalog(), mpsLine.getBucketOffsetDate(),
                                Increment);
                    }

                    long NumOfMax = plannedQty.divide(MaxQty).longValue();
                    Remainder = plannedQty.subtract(MaxQty.multiply(new BigDecimal(NumOfMax)));
                    plannedQty = MaxQty.multiply(new BigDecimal(NumOfMax));
                    if (MathUtils.compareToZero(Remainder) != 0) {
                        if (Remainder.compareTo(MinQty) == -1)
                            plannedQty = plannedQty.add(MinQty);
                        else {
                            long NumOfInc = Remainder.subtract(MinQty).divide(Increment).longValue();
                            RemInc = Remainder.subtract(MinQty)
                                    .subtract(Increment.multiply(new BigDecimal(NumOfInc)));
                            if (MathUtils.compareToZero(RemInc) != 0)
                                plannedQty = plannedQty.add(MinQty)
                                        .add(Increment.multiply(new BigDecimal(NumOfInc))).add(Increment);
                            else
                                plannedQty = plannedQty.add(Remainder);
                        }
                    }
                }
            }
            availableOnBeginBucket = mpsLine.calculateAvailableQuantityOnEndBucket(plannedQty,
                    availableOnBeginBucket);

            if (MathUtils.compareToZero(plannedQty) < 0)
                plannedQty = BigDecimal.ZERO;
            mpsLine.setPlannedQty(plannedQty);
        }
    }
}