use of org.kuali.kfs.vnd.businessobject.PurchaseOrderCostSource in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceMatchingServiceImpl method validateUnitPrice.
protected void validateUnitPrice(ElectronicInvoiceItemHolder itemHolder) {
PurchaseOrderCostSource costSource = itemHolder.getInvoiceOrderHolder().getPurchaseOrderDocument().getPurchaseOrderCostSource();
PurchaseOrderItem poItem = itemHolder.getPurchaseOrderItem();
ElectronicInvoiceOrderHolder orderHolder = itemHolder.getInvoiceOrderHolder();
String extraDescription = "Invoice Item Line Number:" + itemHolder.getInvoiceItemLineNumber();
BigDecimal actualVariance = itemHolder.getInvoiceItemUnitPrice().subtract(poItem.getItemUnitPrice());
BigDecimal lowerPercentage = null;
if (costSource.getItemUnitPriceLowerVariancePercent() != null) {
// Checking for lower variance
lowerPercentage = costSource.getItemUnitPriceLowerVariancePercent();
} else {
// If the cost source itemUnitPriceLowerVariancePercent is null then
// we'll use the exact match (100%).
lowerPercentage = new BigDecimal(100);
}
BigDecimal lowerAcceptableVariance = (lowerPercentage.divide(new BigDecimal(100))).multiply(poItem.getItemUnitPrice()).negate();
// KFSUPGRADE-485
if (!poItem.isNoQtyItem() && lowerAcceptableVariance.compareTo(actualVariance) > 0) {
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.INVOICE_AMT_LESSER_THAN_LOWER_VARIANCE, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, PurapConstants.ElectronicInvoice.RejectDocumentFields.INVOICE_ITEM_UNIT_PRICE, PurapKeyConstants.ERROR_REJECT_UNITPRICE_LOWERVARIANCE);
}
BigDecimal upperPercentage = null;
if (costSource.getItemUnitPriceUpperVariancePercent() != null) {
// Checking for upper variance
upperPercentage = costSource.getItemUnitPriceUpperVariancePercent();
} else {
// If the cost source itemUnitPriceLowerVariancePercent is null then
// we'll use the exact match (100%).
upperPercentage = new BigDecimal(100);
}
BigDecimal upperAcceptableVariance = (upperPercentage.divide(new BigDecimal(100))).multiply(poItem.getItemUnitPrice());
if (upperAcceptableVariance.compareTo(actualVariance) < 0) {
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.INVOICE_AMT_GREATER_THAN_UPPER_VARIANCE, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, PurapConstants.ElectronicInvoice.RejectDocumentFields.INVOICE_ITEM_UNIT_PRICE, PurapKeyConstants.ERROR_REJECT_UNITPRICE_UPPERVARIANCE);
}
}
Aggregations