use of org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceRejectDocument method sanitizeRejectReasons.
public void sanitizeRejectReasons() {
List<ElectronicInvoiceRejectReason> sanitized = new ArrayList<ElectronicInvoiceRejectReason>();
int maxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(ElectronicInvoiceRejectReason.class, "invoiceRejectReasonDescription");
for (ElectronicInvoiceRejectReason rejectReason : invoiceRejectReasons) {
if (rejectReason.getInvoiceRejectReasonDescription().length() > maxLength) {
String reason = rejectReason.getInvoiceRejectReasonDescription();
String type = rejectReason.getInvoiceRejectReasonTypeCode();
String fileName = rejectReason.getInvoiceFileName();
while (reason.length() > maxLength) {
ElectronicInvoiceRejectReason split = new ElectronicInvoiceRejectReason(type, fileName, reason.substring(0, maxLength));
reason = reason.substring(maxLength);
sanitized.add(split);
}
ElectronicInvoiceRejectReason split = new ElectronicInvoiceRejectReason(type, fileName, reason);
sanitized.add(split);
} else {
sanitized.add(rejectReason);
}
}
invoiceRejectReasons = sanitized;
}
use of org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceMatchingServiceImpl method validatePurchaseOrderMatch.
// KFSUPGRADE-482
protected void validatePurchaseOrderMatch(ElectronicInvoiceOrderHolder orderHolder) {
String poIDFieldName = PurapConstants.ElectronicInvoice.RejectDocumentFields.INVOICE_PO_ID;
String poID = orderHolder.getInvoicePurchaseOrderID();
if (StringUtils.isEmpty(poID)) {
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.PO_ID_EMPTY, null, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, poIDFieldName, PurapKeyConstants.ERROR_REJECT_INVOICE_POID_EMPTY);
return;
}
String extraDesc = "Invoice Order ID:" + poID;
if (!NumberUtils.isDigits(poID)) {
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.PO_ID_INVALID_FORMAT, extraDesc, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, poIDFieldName, PurapKeyConstants.ERROR_REJECT_INVOICE_POID_INVALID);
return;
}
// KFSUPGRADE-482 : if number is too large
try {
Integer.parseInt(poID);
} catch (NumberFormatException nfe) {
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.PO_NOT_EXISTS, extraDesc, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, poIDFieldName, PurapKeyConstants.ERROR_REJECT_INVOICE__PO_NOT_EXISTS);
return;
}
PurchaseOrderDocument poDoc = orderHolder.getPurchaseOrderDocument();
if (poDoc == null) {
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.PO_NOT_EXISTS, extraDesc, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, poIDFieldName, PurapKeyConstants.ERROR_REJECT_INVOICE__PO_NOT_EXISTS);
return;
}
if (!poDoc.getApplicationDocumentStatus().equals(PurchaseOrderStatuses.APPDOC_OPEN)) {
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.PO_NOT_OPEN, null, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, poIDFieldName, PurapKeyConstants.ERROR_REJECT_INVOICE_PO_CLOSED);
return;
}
if (poDoc.getVendorHeaderGeneratedIdentifier() == null || poDoc.getVendorDetailAssignedIdentifier() == null || !(poDoc.getVendorHeaderGeneratedIdentifier().equals(orderHolder.getVendorHeaderId()) && poDoc.getVendorDetailAssignedIdentifier().equals(orderHolder.getVendorDetailId()))) {
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.PO_VENDOR_NOT_MATCHES_WITH_INVOICE_VENDOR, null, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return;
}
}
use of org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason 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);
}
}
use of org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImpl method createPaymentRequest.
protected PaymentRequestDocument createPaymentRequest(ElectronicInvoiceOrderHolder orderHolder) {
LOG.info("Creating Payment Request document");
KNSGlobalVariables.getMessageList().clear();
validateInvoiceOrderValidForPREQCreation(orderHolder);
if (LOG.isInfoEnabled()) {
if (orderHolder.isInvoiceRejected()) {
LOG.info("Not possible to convert einvoice details into payment request");
} else {
LOG.info("Payment request document creation validation succeeded");
}
}
if (orderHolder.isInvoiceRejected()) {
return null;
}
PaymentRequestDocument preqDoc = null;
try {
preqDoc = (PaymentRequestDocument) SpringContext.getBean(DocumentService.class).getNewDocument("PREQ");
} catch (WorkflowException e) {
String extraDescription = "Error=" + e.getMessage();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_WORKLOW_EXCEPTION, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
LOG.error("Error creating Payment request document - " + e.getMessage());
return null;
}
PurchaseOrderDocument poDoc = orderHolder.getPurchaseOrderDocument();
if (poDoc == null) {
throw new RuntimeException("Purchase Order document (POId=" + poDoc.getPurapDocumentIdentifier() + ") does not exist in the system");
}
preqDoc.getDocumentHeader().setDocumentDescription(generatePREQDocumentDescription(poDoc));
try {
preqDoc.updateAndSaveAppDocStatus(PurapConstants.PaymentRequestStatuses.APPDOC_IN_PROCESS);
} catch (WorkflowException we) {
throw new RuntimeException("Unable to save route status data for document: " + preqDoc.getDocumentNumber(), we);
}
preqDoc.setInvoiceDate(orderHolder.getInvoiceDate());
preqDoc.setInvoiceNumber(orderHolder.getInvoiceNumber());
preqDoc.setVendorInvoiceAmount(new KualiDecimal(orderHolder.getInvoiceNetAmount()));
preqDoc.setAccountsPayableProcessorIdentifier("E-Invoice");
preqDoc.setVendorCustomerNumber(orderHolder.getCustomerNumber());
preqDoc.setPaymentRequestElectronicInvoiceIndicator(true);
if (orderHolder.getAccountsPayablePurchasingDocumentLinkIdentifier() != null) {
preqDoc.setAccountsPayablePurchasingDocumentLinkIdentifier(orderHolder.getAccountsPayablePurchasingDocumentLinkIdentifier());
}
// Copied from PaymentRequestServiceImpl.populatePaymentRequest()
// set bank code to default bank code in the system parameter
// KFSPTS-1891
boolean hasPaymentMethodCode = false;
if (preqDoc instanceof PaymentRequestDocument) {
String vendorPaymentMethodCode = ((VendorDetailExtension) poDoc.getVendorDetail().getExtension()).getDefaultB2BPaymentMethodCode();
if (StringUtils.isNotEmpty(vendorPaymentMethodCode)) {
((CuPaymentRequestDocument) preqDoc).setPaymentMethodCode(vendorPaymentMethodCode);
hasPaymentMethodCode = true;
} else {
((CuPaymentRequestDocument) preqDoc).setPaymentMethodCode(DEFAULT_EINVOICE_PAYMENT_METHOD_CODE);
}
}
Bank defaultBank = null;
if (hasPaymentMethodCode) {
defaultBank = SpringContext.getBean(CUPaymentMethodGeneralLedgerPendingEntryService.class).getBankForPaymentMethod(((CuPaymentRequestDocument) preqDoc).getPaymentMethodCode());
} else {
// default to baseline behavior - extended documents not in use
// Copied from PaymentRequestServiceImpl.populatePaymentRequest()
// set bank code to default bank code in the system parameter
defaultBank = SpringContext.getBean(BankService.class).getDefaultBankByDocType(PaymentRequestDocument.class);
}
if (defaultBank != null) {
preqDoc.setBankCode(defaultBank.getBankCode());
preqDoc.setBank(defaultBank);
}
RequisitionDocument reqDoc = SpringContext.getBean(RequisitionService.class).getRequisitionById(poDoc.getRequisitionIdentifier());
String reqDocInitiator = reqDoc.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
try {
Person user = KimApiServiceLocator.getPersonService().getPerson(reqDocInitiator);
setProcessingCampus(preqDoc, user.getCampusCode());
} catch (Exception e) {
String extraDescription = "Error setting processing campus code - " + e.getMessage();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_VALIDATION_ERROR, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return null;
}
HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList = SpringContext.getBean(AccountsPayableService.class).expiredOrClosedAccountsList(poDoc);
if (expiredOrClosedAccountList == null) {
expiredOrClosedAccountList = new HashMap();
}
if (LOG.isInfoEnabled()) {
LOG.info(expiredOrClosedAccountList.size() + " accounts has been found as Expired or Closed");
}
preqDoc.populatePaymentRequestFromPurchaseOrder(orderHolder.getPurchaseOrderDocument(), expiredOrClosedAccountList);
// need to populate here for ext price. it become per item
// KFSPTS-1719. convert 1st matching inv item that is qty, but po is non-qty
checkQtyInvItemForNoQtyOrder(preqDoc, orderHolder);
populateItemDetails(preqDoc, orderHolder);
// KFSUPGRADE-485, KFSPTS-1719
if (CollectionUtils.isNotEmpty(((CuElectronicInvoiceOrderHolder) orderHolder).getNonMatchItems())) {
for (ElectronicInvoiceItemHolder invItem : ((CuElectronicInvoiceOrderHolder) orderHolder).getNonMatchItems()) {
PurchaseOrderItem item = (PurchaseOrderItem) ObjectUtils.deepCopy((Serializable) orderHolder.getPurchaseOrderDocument().getItems().get(invItem.getInvoiceItemLineNumber() - 1));
item.setItemLineNumber(invItem.getInvoiceItemLineNumber());
item.setItemDescription(((CuElectronicInvoiceItemHolder) invItem).getReferenceDescription());
// this will be populated to reqitem.poitemunitprice
item.setItemUnitPrice(invItem.getInvoiceItemUnitPrice());
PaymentRequestItem paymentRequestItem = new PaymentRequestItem(item, preqDoc, expiredOrClosedAccountList);
((CuPaymentRequestItemExtension) paymentRequestItem.getExtension()).setInvLineNumber(Integer.parseInt(((CuElectronicInvoiceItemHolder) invItem).getInvLineNumber()));
// need following in case inv item is qty item
paymentRequestItem.setItemQuantity(new KualiDecimal(invItem.getInvoiceItemQuantity()));
paymentRequestItem.setItemUnitOfMeasureCode(invItem.getInvoiceItemUnitOfMeasureCode());
paymentRequestItem.setPurchaseOrderItemUnitPrice(invItem.getInvoiceItemUnitPrice());
// if non qty don't need this unit price set, then this need to have a check
if (invItem.getInvoiceItemQuantity() != null && (new KualiDecimal(invItem.getInvoiceItemQuantity())).isPositive()) {
paymentRequestItem.setItemUnitPrice(invItem.getInvoiceItemUnitPrice());
}
paymentRequestItem.setItemCatalogNumber(invItem.getCatalogNumberStripped());
preqDoc.getItems().add(paymentRequestItem);
((CuElectronicInvoiceOrderHolder) orderHolder).setMisMatchItem((CuElectronicInvoiceItemHolder) invItem);
populateItemDetailsForNonMatching(preqDoc, orderHolder);
((CuElectronicInvoiceOrderHolder) orderHolder).setMisMatchItem(null);
}
}
/**
* Validate totals,paydate
*/
// PaymentRequestDocumentRule.processCalculateAccountsPayableBusinessRules
SpringContext.getBean(KualiRuleService.class).applyRules(new AttributedCalculateAccountsPayableEvent(preqDoc));
SpringContext.getBean(PaymentRequestService.class).calculatePaymentRequest(preqDoc, true);
processItemsForDiscount(preqDoc, orderHolder);
if (orderHolder.isInvoiceRejected()) {
return null;
}
SpringContext.getBean(PaymentRequestService.class).calculatePaymentRequest(preqDoc, false);
/**
* PaymentRequestReview
*/
// PaymentRequestDocumentRule.processRouteDocumentBusinessRules
SpringContext.getBean(KualiRuleService.class).applyRules(new AttributedPaymentRequestForEInvoiceEvent(preqDoc));
if (GlobalVariables.getMessageMap().hasErrors()) {
if (LOG.isInfoEnabled()) {
LOG.info("***************Error in rules processing - " + GlobalVariables.getMessageMap());
}
Map<String, AutoPopulatingList<ErrorMessage>> errorMessages = GlobalVariables.getMessageMap().getErrorMessages();
String errors = errorMessages.toString();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_VALIDATION_ERROR, errors, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return null;
}
if (KNSGlobalVariables.getMessageList().size() > 0) {
if (LOG.isInfoEnabled()) {
LOG.info("Payment request contains " + KNSGlobalVariables.getMessageList().size() + " warning message(s)");
for (int i = 0; i < KNSGlobalVariables.getMessageList().size(); i++) {
LOG.info("Warning " + i + " - " + KNSGlobalVariables.getMessageList().get(i));
}
}
}
addShipToNotes(preqDoc, orderHolder);
try {
// KFSUPGRADE-490: Do save-only operations for just non-EIRT-generated PREQs.
if (orderHolder.isRejectDocumentHolder()) {
SpringContext.getBean(DocumentService.class).routeDocument(preqDoc, null, null);
} else {
SpringContext.getBean(DocumentService.class).saveDocument(preqDoc, DocumentSystemSaveEvent.class);
}
} catch (WorkflowException e) {
e.printStackTrace();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_FAILURE, e.getMessage(), orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return null;
} catch (ValidationException e) {
String extraDescription = GlobalVariables.getMessageMap().toString();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_VALIDATION_ERROR, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return null;
}
return preqDoc;
}
use of org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImpl method doMatchingProcess.
// end KFSUPGRADE-484
// KFSUPGRADE-485
@Override
@NonTransactional
public boolean doMatchingProcess(ElectronicInvoiceRejectDocument rejectDocument) {
/**
* This is needed here since if the user changes the DUNS number.
*/
validateVendorDetails(rejectDocument);
Map itemTypeMappings = getItemTypeMappings(rejectDocument.getVendorHeaderGeneratedIdentifier(), rejectDocument.getVendorDetailAssignedIdentifier());
Map kualiItemTypes = getKualiItemTypes();
CuElectronicInvoiceOrderHolder rejectDocHolder = new CuElectronicInvoiceOrderHolder(rejectDocument, itemTypeMappings, kualiItemTypes);
matchingService.doMatchingProcess(rejectDocHolder);
// KFSPTS-1719 : save the nomatchingitems found during match process.
((CuElectronicInvoiceRejectDocument) rejectDocument).setNonMatchItems(((CuElectronicInvoiceOrderHolder) rejectDocHolder).getNonMatchItems());
/**
* Once we're through with the matching process, it's needed to check whether it's possible
* to create PREQ for the reject doc
*/
if (!rejectDocHolder.isInvoiceRejected()) {
validateInvoiceOrderValidForPREQCreation(rejectDocHolder);
}
// determine which of the reject reasons we should suppress based on the parameter
List<String> ignoreRejectTypes = new ArrayList<String>(parameterService.getParameterValuesAsString(PurapConstants.PURAP_NAMESPACE, "ElectronicInvoiceReject", "SUPPRESS_REJECT_REASON_CODES_ON_EIRT_APPROVAL"));
List<ElectronicInvoiceRejectReason> rejectReasonsToDelete = new ArrayList<ElectronicInvoiceRejectReason>();
for (ElectronicInvoiceRejectReason rejectReason : rejectDocument.getInvoiceRejectReasons()) {
String rejectedReasonTypeCode = rejectReason.getInvoiceRejectReasonTypeCode();
if (StringUtils.isNotBlank(rejectedReasonTypeCode)) {
if (ignoreRejectTypes.contains(rejectedReasonTypeCode)) {
rejectReasonsToDelete.add(rejectReason);
}
}
}
// remove the flagged reject reasons
if (!rejectReasonsToDelete.isEmpty()) {
rejectDocument.getInvoiceRejectReasons().removeAll(rejectReasonsToDelete);
}
// if no reject reasons, then clear error messages
if (rejectDocument.getInvoiceRejectReasons().isEmpty()) {
GlobalVariables.getMessageMap().clearErrorMessages();
}
// this automatically returns false if there are no reject reasons
return !rejectDocHolder.isInvoiceRejected();
}
Aggregations