Search in sources :

Example 6 with ElectronicInvoiceRejectDocument

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;
}
Also used : ElectronicInvoiceRejectDocument(org.kuali.kfs.module.purap.document.ElectronicInvoiceRejectDocument) CuElectronicInvoiceRejectDocument(edu.cornell.kfs.module.purap.document.CuElectronicInvoiceRejectDocument) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) ArrayList(java.util.ArrayList) ElectronicInvoiceRejectReason(org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason) WorkflowDocumentService(org.kuali.kfs.krad.workflow.service.WorkflowDocumentService) DocumentService(org.kuali.kfs.krad.service.DocumentService) FinancialSystemDocumentService(org.kuali.kfs.sys.document.service.FinancialSystemDocumentService) DataDictionaryService(org.kuali.kfs.krad.service.DataDictionaryService)

Aggregations

ElectronicInvoiceRejectDocument (org.kuali.kfs.module.purap.document.ElectronicInvoiceRejectDocument)6 CuElectronicInvoiceRejectDocument (edu.cornell.kfs.module.purap.document.CuElectronicInvoiceRejectDocument)5 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)4 DocumentService (org.kuali.kfs.krad.service.DocumentService)3 WorkflowDocumentService (org.kuali.kfs.krad.workflow.service.WorkflowDocumentService)3 ElectronicInvoiceLoadSummary (org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceLoadSummary)3 FinancialSystemDocumentService (org.kuali.kfs.sys.document.service.FinancialSystemDocumentService)3 File (java.io.File)2 RemoteException (java.rmi.RemoteException)2 ArrayList (java.util.ArrayList)2 ElectronicInvoiceRejectReason (org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason)2 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)2 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 NumberFormat (java.text.NumberFormat)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1