use of org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImpl method rejectElectronicInvoiceFile.
protected void rejectElectronicInvoiceFile(ElectronicInvoiceLoad eInvoiceLoad, String fileDunsNumber, File invoiceFile, String extraDescription, String rejectReasonTypeCode) {
if (LOG.isInfoEnabled()) {
LOG.info("Rejecting the entire invoice file - " + invoiceFile.getName());
}
ElectronicInvoiceLoadSummary eInvoiceLoadSummary = getOrCreateLoadSummary(eInvoiceLoad, fileDunsNumber);
eInvoiceLoadSummary.addFailedInvoiceOrder();
eInvoiceLoad.insertInvoiceLoadSummary(eInvoiceLoadSummary);
ElectronicInvoiceRejectDocument eInvoiceRejectDocument = null;
try {
eInvoiceRejectDocument = (ElectronicInvoiceRejectDocument) SpringContext.getBean(DocumentService.class).getNewDocument("EIRT");
eInvoiceRejectDocument.setInvoiceProcessTimestamp(SpringContext.getBean(DateTimeService.class).getCurrentTimestamp());
eInvoiceRejectDocument.setVendorDunsNumber(fileDunsNumber);
eInvoiceRejectDocument.setDocumentCreationInProgress(true);
if (invoiceFile != null) {
eInvoiceRejectDocument.setInvoiceFileName(invoiceFile.getName());
}
List<ElectronicInvoiceRejectReason> list = new ArrayList<ElectronicInvoiceRejectReason>(1);
String message = "Complete failure document has been created for the Invoice with Filename '" + invoiceFile.getName() + "' due to the following error:\n";
emailTextErrorList.append(message);
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(rejectReasonTypeCode, extraDescription, invoiceFile.getName());
list.add(rejectReason);
emailTextErrorList.append(" - " + rejectReason.getInvoiceRejectReasonDescription());
emailTextErrorList.append("\n\n");
eInvoiceRejectDocument.setInvoiceRejectReasons(list);
eInvoiceRejectDocument.getDocumentHeader().setDocumentDescription("Complete failure");
// KFSCNTRB-1369: Need to Save document
SpringContext.getBean(DocumentService.class).saveDocument(eInvoiceRejectDocument);
String noteText = "Invoice file";
// if (invoiceFile.length() > 0) {
// empty file will casuse attachment creation exception. Hence, job will be stopped
attachInvoiceXMLWithRejectDoc(eInvoiceRejectDocument, invoiceFile, noteText);
// }
eInvoiceLoad.addInvoiceReject(eInvoiceRejectDocument);
} catch (WorkflowException e) {
throw new RuntimeException(e);
}
if (LOG.isInfoEnabled()) {
LOG.info("Complete failure document has been created (DocNo:" + eInvoiceRejectDocument.getDocumentNumber() + ")");
}
}
use of org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImpl method createRejectDocument.
public ElectronicInvoiceRejectDocument createRejectDocument(ElectronicInvoice eInvoice, ElectronicInvoiceOrder electronicInvoiceOrder, ElectronicInvoiceLoad eInvoiceLoad) {
LOG.info("Creating reject document [DUNS=" + eInvoice.getDunsNumber() + ",POID=" + electronicInvoiceOrder.getInvoicePurchaseOrderID() + "]");
ElectronicInvoiceRejectDocument eInvoiceRejectDocument;
try {
eInvoiceRejectDocument = (ElectronicInvoiceRejectDocument) SpringContext.getBean(DocumentService.class).getNewDocument("EIRT");
eInvoiceRejectDocument.setInvoiceProcessTimestamp(SpringContext.getBean(DateTimeService.class).getCurrentTimestamp());
String rejectdocDesc = generateRejectDocumentDescription(eInvoice, electronicInvoiceOrder);
eInvoiceRejectDocument.getDocumentHeader().setDocumentDescription(rejectdocDesc);
eInvoiceRejectDocument.setDocumentCreationInProgress(true);
eInvoiceRejectDocument.setFileLevelData(eInvoice);
eInvoiceRejectDocument.setInvoiceOrderLevelData(eInvoice, electronicInvoiceOrder);
SpringContext.getBean(DocumentService.class).saveDocument(eInvoiceRejectDocument);
String noteText = "Invoice file";
attachInvoiceXMLWithRejectDoc(eInvoiceRejectDocument, getInvoiceFile(eInvoice.getFileName()), noteText);
eInvoiceLoad.addInvoiceReject(eInvoiceRejectDocument);
} catch (WorkflowException e) {
throw new RuntimeException(e);
}
LOG.info("Reject document has been created (DocNo=" + eInvoiceRejectDocument.getDocumentNumber() + ")");
emailTextErrorList.append("DUNS Number - " + eInvoice.getDunsNumber() + " " + eInvoice.getVendorName() + ":\n");
emailTextErrorList.append("An e-invoice from file '" + eInvoice.getFileName() + "' has been rejected due to the following error(s):\n");
// get note text max length from DD
int noteTextMaxLength = NOTE_TEXT_DEFAULT_MAX_LENGTH;
Integer noteTextLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(Note.class, KRADConstants.NOTE_TEXT_PROPERTY_NAME);
if (noteTextLength != null) {
noteTextMaxLength = noteTextLength.intValue();
}
// KFSUPGRADE-489/KITI-2643 - Modified to fix bug reported in KFSPTS-292
// Ensure that we don't overflow the maximum size of the note by creating
// separate notes if necessary.
ArrayList<StringBuffer> rejectReasonNotes = new ArrayList<StringBuffer>();
StringBuffer rejectReasonNote = new StringBuffer();
String rejectReason = "";
rejectReasonNote.append("This reject document has been created because of the following reason(s):\n");
int index = 1;
for (ElectronicInvoiceRejectReason reason : eInvoiceRejectDocument.getInvoiceRejectReasons()) {
emailTextErrorList.append(" - " + reason.getInvoiceRejectReasonDescription() + "\n");
emailTextErrorList.append(" - PO " + eInvoiceRejectDocument.getPurchaseOrderIdentifier() + "\n");
emailTextErrorList.append(" - EIRT " + eInvoiceRejectDocument.getDocumentNumber() + "\n");
// addRejectReasonsToNote("Reject Reason " + index + ". " + reason.getInvoiceRejectReasonDescription(), eInvoiceRejectDocument);
rejectReason = " " + index + ". " + reason.getInvoiceRejectReasonDescription() + "\n";
if (rejectReasonNote.length() + rejectReason.length() > noteTextMaxLength) {
rejectReasonNotes.add(rejectReasonNote);
rejectReasonNote = new StringBuffer();
rejectReasonNote.append("Reject document creation reasons continued:\n");
}
rejectReasonNote.append(rejectReason);
index++;
}
rejectReasonNotes.add(rejectReasonNote);
emailTextErrorList.append("\n");
for (StringBuffer noteText : rejectReasonNotes) {
addRejectReasonsToNote(noteText.toString(), eInvoiceRejectDocument);
}
return eInvoiceRejectDocument;
}
use of org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImpl method processItemsForDiscount.
protected void processItemsForDiscount(PaymentRequestDocument preqDocument, ElectronicInvoiceOrderHolder orderHolder) {
LOG.info("Processing payment request items for discount");
if (!orderHolder.isItemTypeAvailableInItemMapping(ElectronicInvoice.INVOICE_AMOUNT_TYPE_CODE_DISCOUNT)) {
LOG.info("Skipping discount processing since there is no mapping of discount type for this vendor");
return;
}
if (orderHolder.getInvoiceDiscountAmount() == null || orderHolder.getInvoiceDiscountAmount() == BigDecimal.ZERO) {
LOG.info("Skipping discount processing since there is no discount amount found in the invoice file");
return;
}
KualiDecimal discountValueToUse = new KualiDecimal(orderHolder.getInvoiceDiscountAmount().negate());
List<PaymentRequestItem> preqItems = preqDocument.getItems();
boolean alreadyProcessedInvoiceDiscount = false;
boolean hasKualiPaymentTermsDiscountItem = false;
// if e-invoice amount is negative... it is a penalty and we must pay extra
for (int i = 0; i < preqItems.size(); i++) {
PaymentRequestItem preqItem = preqItems.get(i);
hasKualiPaymentTermsDiscountItem = hasKualiPaymentTermsDiscountItem || (StringUtils.equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE, preqItem.getItemTypeCode()));
if (isItemValidForUpdation(preqItem.getItemTypeCode(), ElectronicInvoice.INVOICE_AMOUNT_TYPE_CODE_DISCOUNT, orderHolder)) {
alreadyProcessedInvoiceDiscount = true;
if (StringUtils.equals(preqItem.getItemTypeCode(), PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE)) {
// Item is kuali payment terms discount item... must perform calculation
// if discount item exists on PREQ and discount dollar amount exists... use greater amount
LOG.info("Discount Check - E-Invoice matches PREQ item type '" + preqItem.getItemTypeCode() + "'... now checking for amount");
KualiDecimal preqExtendedPrice = preqItem.getExtendedPrice() == null ? KualiDecimal.ZERO : preqItem.getExtendedPrice();
if ((discountValueToUse.compareTo(preqExtendedPrice)) < 0) {
LOG.info("Discount Check - Using E-Invoice amount (" + discountValueToUse + ") as it is more discount than current payment terms amount " + preqExtendedPrice);
preqItem.setItemUnitPrice(discountValueToUse.bigDecimalValue());
preqItem.setExtendedPrice(discountValueToUse);
}
} else {
// item is not payment terms discount item... just add value
// if discount item exists on PREQ and discount dollar amount exists... use greater amount
LOG.info("Discount Check - E-Invoice matches PREQ item type '" + preqItem.getItemTypeCode() + "'");
LOG.info("Discount Check - Using E-Invoice amount (" + discountValueToUse + ") as it is greater than payment terms amount");
preqItem.addToUnitPrice(discountValueToUse.bigDecimalValue());
preqItem.addToExtendedPrice(discountValueToUse);
}
}
}
if (!alreadyProcessedInvoiceDiscount) {
String itemTypeRequired = PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE;
if (hasKualiPaymentTermsDiscountItem || !orderHolder.isItemTypeAvailableInItemMapping(ElectronicInvoice.INVOICE_AMOUNT_TYPE_CODE_DISCOUNT)) {
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_DISCOUNT_ERROR, null, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return;
} else if (discountValueToUse.isNonZero()) {
PaymentRequestItem newItem = new PaymentRequestItem();
newItem.setItemUnitPrice(discountValueToUse.bigDecimalValue());
// KFSUPGRADE-473
// newItem.setItemTypeCode(PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE);
newItem.setItemTypeCode(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE);
newItem.setItemDescription(CUPurapConstants.ElectronicInvoice.DISCOUNT_DESCRIPTION);
newItem.setExtendedPrice(discountValueToUse);
newItem.setPurapDocument(preqDocument);
preqDocument.addItem(newItem);
}
}
LOG.info("Completed processing payment request items for discount");
}
use of org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceMatchingServiceImpl method validateCatalogNumber.
protected void validateCatalogNumber(ElectronicInvoiceItemHolder itemHolder) {
PurchaseOrderItem poItem = itemHolder.getPurchaseOrderItem();
ElectronicInvoiceOrderHolder orderHolder = itemHolder.getInvoiceOrderHolder();
String invoiceCatalogNumberStripped = itemHolder.getCatalogNumberStripped();
String poCatalogNumberStripped = ElectronicInvoiceUtils.stripSplChars(poItem.getItemCatalogNumber());
/**
* If Catalog number in invoice and po are not empty, create reject reason if it doesn't match
*/
if (StringUtils.isNotBlank(invoiceCatalogNumberStripped) && StringUtils.isNotBlank(poCatalogNumberStripped)) {
if (!StringUtils.equalsIgnoreCase(poCatalogNumberStripped, invoiceCatalogNumberStripped)) {
String extraDescription = "Invoice Catalog No:" + invoiceCatalogNumberStripped + ", PO Catalog No:" + poCatalogNumberStripped;
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.CATALOG_NUMBER_MISMATCH, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, PurapConstants.ElectronicInvoice.RejectDocumentFields.INVOICE_ITEM_CATALOG_NUMBER, PurapKeyConstants.ERROR_REJECT_CATALOG_MISMATCH);
}
} else {
/**
* If catalog number is empty in PO/&Invoice, check whether the catalog check is required for the requisition source.
* If exists in param, create reject reason.
* If not exists, continue with UOM and unit price match.
*/
String reqSourceRequiringCatalogMatch = SpringContext.getBean(ParameterService.class).getParameterValueAsString(ElectronicInvoiceStep.class, PurapParameterConstants.ElectronicInvoiceParameters.REQUISITION_SOURCES_REQUIRING_CATALOG_MATCHING);
String requisitionSourceCodeInPO = orderHolder.getPurchaseOrderDocument().getRequisitionSourceCode();
if (StringUtils.isNotEmpty(reqSourceRequiringCatalogMatch)) {
String[] requisitionSourcesFromParam = StringUtils.split(reqSourceRequiringCatalogMatch, ';');
if (ArrayUtils.contains(requisitionSourcesFromParam, requisitionSourceCodeInPO)) {
String extraDescription = "Invoice Catalog No:" + invoiceCatalogNumberStripped + ", PO Catalog No:" + poItem.getItemCatalogNumber();
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.CATALOG_NUMBER_MISMATCH, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, PurapConstants.ElectronicInvoice.RejectDocumentFields.INVOICE_ITEM_CATALOG_NUMBER, PurapKeyConstants.ERROR_REJECT_CATALOG_MISMATCH);
}
}
}
}
use of org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceMatchingServiceImpl method validateInvoiceItem.
protected void validateInvoiceItem(ElectronicInvoiceItemHolder itemHolder, Set poLineNumbers, Set invLineNumbers) {
PurchaseOrderItem poItem = itemHolder.getPurchaseOrderItem();
ElectronicInvoiceOrderHolder orderHolder = itemHolder.getInvoiceOrderHolder();
boolean isNonMatching = false;
if (poItem == null) {
// investigating. this should stay because the inv line should have the correcrt invitemline# set up
String extraDescription = "Invoice Item Line Number:" + itemHolder.getInvoiceItemLineNumber();
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.NO_MATCHING_PO_ITEM, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, PurapConstants.ElectronicInvoice.RejectDocumentFields.INVOICE_ITEM_LINE_NUMBER, PurapKeyConstants.ERROR_REJECT_INVOICE__ITEM_NOMATCH);
return;
}
// only noqty item. the old behavior for qty item does not check the duplicate inv line#
if (invLineNumbers.contains(((CuElectronicInvoiceItemHolder) itemHolder).getInvLineNumber()) && poItem.isNoQtyItem()) {
String extraDescription = "Invoice Item Line Number:" + itemHolder.getInvoiceItemLineNumber();
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.DUPLIATE_INVOICE_LINE_ITEM, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, PurapConstants.ElectronicInvoice.RejectDocumentFields.INVOICE_ITEM_LINE_NUMBER, PurapKeyConstants.ERROR_REJECT_PO_ITEM_DUPLICATE);
return;
} else {
invLineNumbers.add(((CuElectronicInvoiceItemHolder) itemHolder).getInvLineNumber());
}
if (poLineNumbers.contains(itemHolder.getInvoiceItemLineNumber())) {
// TODO : investigating Do NOT commit. Duplicate is not OK for qty item
if (!poItem.isNoQtyItem()) {
String extraDescription = "Invoice Item Line Number:" + itemHolder.getInvoiceItemLineNumber();
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.DUPLIATE_INVOICE_LINE_ITEM, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, PurapConstants.ElectronicInvoice.RejectDocumentFields.INVOICE_ITEM_LINE_NUMBER, PurapKeyConstants.ERROR_REJECT_PO_ITEM_DUPLICATE);
return;
} else {
((CuElectronicInvoiceOrderHolder) orderHolder).getNonMatchItems().add((CuElectronicInvoiceItemHolder) itemHolder);
isNonMatching = true;
}
} else {
poLineNumbers.add(itemHolder.getInvoiceItemLineNumber());
}
if (!poItem.isItemActiveIndicator()) {
String extraDescription = "PO Item Line Number:" + poItem.getItemLineNumber();
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.INACTIVE_LINE_ITEM, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, PurapConstants.ElectronicInvoice.RejectDocumentFields.INVOICE_ITEM_LINE_NUMBER, PurapKeyConstants.ERROR_REJECT_PO_ITEM_INACTIVE);
return;
}
// KFSPTS-1719 skip this if po is noqty item
if (!itemHolder.isCatalogNumberAcceptIndicatorEnabled() && !poItem.isNoQtyItem()) {
validateCatalogNumber(itemHolder);
if (orderHolder.isInvoiceRejected()) {
return;
}
}
if (!itemHolder.isUnitOfMeasureAcceptIndicatorEnabled()) {
// KFSUPGRADE-485 : if po is no qty but inv is qty, then is it necessary to check here ? should not matter
if (!poItem.isNoQtyItem() && !StringUtils.equalsIgnoreCase(poItem.getItemUnitOfMeasureCode(), itemHolder.getInvoiceItemUnitOfMeasureCode())) {
String extraDescription = "Invoice UOM:" + itemHolder.getInvoiceItemUnitOfMeasureCode() + ", PO UOM:" + poItem.getItemUnitOfMeasureCode();
ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.UNIT_OF_MEASURE_MISMATCH, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason, PurapConstants.ElectronicInvoice.RejectDocumentFields.INVOICE_ITEM_UOM, PurapKeyConstants.ERROR_REJECT_UOM_MISMATCH);
return;
}
}
validateUnitPrice(itemHolder);
if (orderHolder.isInvoiceRejected()) {
return;
}
validateSalesTax(itemHolder);
if (orderHolder.isInvoiceRejected()) {
return;
}
// KFSPTS-1719, KFSUPGRADE-485 : this is more appropriate to check if item is non-qty. because user can potentially enter qty for non-qty item
if (!poItem.isNoQtyItem()) {
// if (poItem.getItemQuantity() != null) {
validateQtyBasedItem(itemHolder);
} else {
validateNonQtyBasedItem(itemHolder);
}
}
Aggregations