use of org.kuali.kfs.module.purap.document.ElectronicInvoiceRejectDocument 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;
}
Aggregations