Search in sources :

Example 1 with ABCAnalysisClass

use of com.axelor.apps.base.db.ABCAnalysisClass in project axelor-open-suite by axelor.

the class ABCAnalysisServiceImpl method setABCAnalysisClass.

protected void setABCAnalysisClass(ABCAnalysisLine abcAnalysisLine) {
    BigDecimal maxQty = BigDecimal.ZERO;
    BigDecimal maxWorth = BigDecimal.ZERO;
    BigDecimal lineCumulatedQty = abcAnalysisLine.getCumulatedQty().setScale(2, RoundingMode.HALF_UP);
    BigDecimal lineCumulatedWorth = abcAnalysisLine.getCumulatedWorth().setScale(2, RoundingMode.HALF_UP);
    for (ABCAnalysisClass abcAnalysisClass : abcAnalysisClassList) {
        maxQty = maxQty.add(abcAnalysisClass.getQty());
        maxWorth = maxWorth.add(abcAnalysisClass.getWorth());
        if (lineCumulatedQty.compareTo(maxQty) <= 0 && lineCumulatedWorth.compareTo(maxWorth) <= 0) {
            abcAnalysisLine.setAbcAnalysisClass(abcAnalysisClassRepository.find(abcAnalysisClass.getId()));
            break;
        }
    }
}
Also used : ABCAnalysisClass(com.axelor.apps.base.db.ABCAnalysisClass) BigDecimal(java.math.BigDecimal)

Example 2 with ABCAnalysisClass

use of com.axelor.apps.base.db.ABCAnalysisClass in project axelor-open-suite by axelor.

the class ABCAnalysisServiceImpl method checkClasses.

@Override
public void checkClasses(ABCAnalysis abcAnalysis) throws AxelorException {
    List<ABCAnalysisClass> abcAnalysisClassList = abcAnalysis.getAbcAnalysisClassList();
    BigDecimal classQty, classWorth;
    BigDecimal totalQty = BigDecimal.ZERO, totalWorth = BigDecimal.ZERO;
    BigDecimal comparisonValue = new BigDecimal(100);
    for (ABCAnalysisClass abcAnalysisClass : abcAnalysisClassList) {
        classQty = abcAnalysisClass.getQty();
        classWorth = abcAnalysisClass.getWorth();
        if (classQty.compareTo(BigDecimal.ZERO) <= 0 || classWorth.compareTo(BigDecimal.ZERO) <= 0) {
            throw new AxelorException(abcAnalysis, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ABC_CLASSES_NEGATIVE_OR_NULL_QTY_OR_WORTH));
        }
        totalQty = totalQty.add(classQty);
        totalWorth = totalWorth.add(classWorth);
    }
    if (totalQty.compareTo(comparisonValue) != 0 || totalWorth.compareTo(comparisonValue) != 0) {
        throw new AxelorException(abcAnalysis, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ABC_CLASSES_INVALID_QTY_OR_WORTH));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ABCAnalysisClass(com.axelor.apps.base.db.ABCAnalysisClass) BigDecimal(java.math.BigDecimal)

Example 3 with ABCAnalysisClass

use of com.axelor.apps.base.db.ABCAnalysisClass in project axelor-open-suite by axelor.

the class ABCAnalysisServiceImpl method createAbcClass.

private ABCAnalysisClass createAbcClass(String name, Integer sequence, BigDecimal worth, BigDecimal qty) {
    ABCAnalysisClass abcAnalysisClass = new ABCAnalysisClass();
    abcAnalysisClass.setName(name);
    abcAnalysisClass.setSequence(sequence);
    abcAnalysisClass.setWorth(worth);
    abcAnalysisClass.setQty(qty);
    return abcAnalysisClass;
}
Also used : ABCAnalysisClass(com.axelor.apps.base.db.ABCAnalysisClass)

Aggregations

ABCAnalysisClass (com.axelor.apps.base.db.ABCAnalysisClass)3 BigDecimal (java.math.BigDecimal)2 AxelorException (com.axelor.exception.AxelorException)1