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;
}
}
}
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));
}
}
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;
}
Aggregations