Search in sources :

Example 11 with WorkflowException

use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.

the class CuElectronicInvoiceHelperServiceImpl method routeEIRTDocuments.

protected boolean routeEIRTDocuments() {
    Collection<String> documentIdList = null;
    try {
        documentIdList = retrieveDocumentsToRoute(KewApiConstants.ROUTE_HEADER_SAVED_CD, ElectronicInvoiceRejectDocument.class);
    } catch (WorkflowException e1) {
        LOG.error("Error retrieving eirt documents for routing: " + e1.getMessage(), e1);
        throw new RuntimeException(e1.getMessage(), e1);
    } catch (RemoteException re) {
        LOG.error("Error retrieving eirt documents for routing: " + re.getMessage(), re);
        throw new RuntimeException(re.getMessage(), re);
    }
    // Collections.reverse(documentIdList);
    LOG.info("EIRTs to Route: " + documentIdList);
    for (String eirtDocumentId : documentIdList) {
        try {
            LOG.info("Retrieving EIRT document # " + eirtDocumentId + ".");
            ElectronicInvoiceRejectDocument eirtDocument = (ElectronicInvoiceRejectDocument) documentService.getByDocumentHeaderId(eirtDocumentId);
            LOG.info("Routing EIRT document # " + eirtDocumentId + ".");
            documentService.prepareWorkflowDocument(eirtDocument);
            LOG.info("EIRT document # " + eirtDocumentId + " prepared for workflow.");
            // calling workflow service to bypass business rule checks
            workflowDocumentService.route(eirtDocument.getDocumentHeader().getWorkflowDocument(), "Routed by electronic invoice batch job", null);
            LOG.info("EIRT document # " + eirtDocumentId + " routed.");
        } catch (WorkflowException e) {
            LOG.error("Error routing document # " + eirtDocumentId + " " + e.getMessage());
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    return true;
}
Also used : ElectronicInvoiceRejectDocument(org.kuali.kfs.module.purap.document.ElectronicInvoiceRejectDocument) CuElectronicInvoiceRejectDocument(edu.cornell.kfs.module.purap.document.CuElectronicInvoiceRejectDocument) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) RemoteException(java.rmi.RemoteException)

Example 12 with WorkflowException

use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.

the class CuPendingTransactionServiceImpl method reverseSourceDocumentsEntries.

/**
 * Reverses the entries of the source documents
 *
 * @param paymentDetail
 * @param sequenceHelper
 */
protected void reverseSourceDocumentsEntries(PaymentDetail paymentDetail, GeneralLedgerPendingEntrySequenceHelper sequenceHelper) {
    // Need to reverse the payment document's GL entries if the check is stopped or cancelled
    if (PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT.equalsIgnoreCase(paymentDetail.getFinancialDocumentTypeCode()) || CUPdpConstants.PdpDocumentTypes.DISBURSEMENT_VOUCHER.equalsIgnoreCase(paymentDetail.getFinancialDocumentTypeCode()) || CUPdpConstants.PdpDocumentTypes.CREDIT_MEMO.equalsIgnoreCase(paymentDetail.getFinancialDocumentTypeCode())) {
        try {
            String sourceDocumentNumber = paymentDetail.getCustPaymentDocNbr();
            try {
                Long.valueOf(sourceDocumentNumber);
            } catch (NumberFormatException nfe) {
                sourceDocumentNumber = null;
            }
            if (sourceDocumentNumber != null && StringUtils.isNotBlank(sourceDocumentNumber)) {
                Document doc = (AccountingDocumentBase) SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(paymentDetail.getCustPaymentDocNbr());
                if (ObjectUtils.isNotNull(doc)) {
                    if (doc instanceof DisbursementVoucherDocument) {
                        // KFSUPGRADE-775
                        DisbursementVoucherDocument dv = (DisbursementVoucherDocument) doc;
                        generateDisbursementVoucherReversalEntries(dv, sequenceHelper);
                    // end KFSUPGRADE-775
                    } else if (doc instanceof VendorCreditMemoDocument) {
                        // KFSPTS-2719
                        String crCmCancelNote = parameterService.getParameterValueAsString(VendorCreditMemoDocument.class, CUPurapParameterConstants.PURAP_CR_CM_CANCEL_NOTE);
                        VendorCreditMemoDocument cmDocument = (VendorCreditMemoDocument) doc;
                        String crCancelMaintDocNbr = getCrCancelMaintenancedocumentNumber(paymentDetail);
                        crCmCancelNote = crCmCancelNote + crCancelMaintDocNbr;
                        try {
                            Note noteObj = documentService.createNoteFromDocument(cmDocument, crCmCancelNote);
                            cmDocument.addNote(noteObj);
                            noteService.save(noteObj);
                        } catch (Exception e) {
                            throw new RuntimeException(e.getMessage());
                        }
                        // KFSUPGRADE-775
                        VendorCreditMemoDocument cm = (VendorCreditMemoDocument) doc;
                        AccountsPayableDocumentSpecificService accountsPayableDocumentSpecificService = cm.getDocumentSpecificService();
                        accountsPayableDocumentSpecificService.updateStatusByNode("", cm);
                        // end KFSUPGRADE-775
                        generateCreditMemoReversalEntries((VendorCreditMemoDocument) doc);
                    } else if (doc instanceof PaymentRequestDocument) {
                        // KFSPTS-2719
                        String crPreqCancelNote = parameterService.getParameterValueAsString(PaymentRequestDocument.class, CUPurapParameterConstants.PURAP_CR_PREQ_CANCEL_NOTE);
                        PaymentRequestDocument paymentRequest = (PaymentRequestDocument) doc;
                        String crCancelMaintDocNbr = getCrCancelMaintenancedocumentNumber(paymentDetail);
                        crPreqCancelNote = crPreqCancelNote + crCancelMaintDocNbr;
                        try {
                            Note cancelNote = documentService.createNoteFromDocument(paymentRequest, crPreqCancelNote);
                            paymentRequest.addNote(cancelNote);
                            noteService.save(cancelNote);
                        } catch (Exception e) {
                            throw new RuntimeException(PurapConstants.REQ_UNABLE_TO_CREATE_NOTE + " " + e);
                        }
                        // cancel extracted should not reopen PO
                        paymentRequest.setReopenPurchaseOrderIndicator(false);
                        // KFSUPGRADE-775
                        AccountsPayableDocumentSpecificService accountsPayableDocumentSpecificService = paymentRequest.getDocumentSpecificService();
                        accountsPayableDocumentSpecificService.updateStatusByNode("", paymentRequest);
                        // end KFSUPGRADE-775
                        generatePaymentRequestReversalEntries(paymentRequest);
                    }
                }
            }
        } catch (WorkflowException we) {
            System.out.println("Exception retrieving document " + paymentDetail.getCustPaymentDocNbr());
        }
    }
}
Also used : VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) AccountsPayableDocumentSpecificService(org.kuali.kfs.module.purap.document.service.AccountsPayableDocumentSpecificService) Note(org.kuali.kfs.krad.bo.Note) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) AccountingDocumentBase(org.kuali.kfs.sys.document.AccountingDocumentBase) VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument) Document(org.kuali.kfs.krad.document.Document) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException)

Example 13 with WorkflowException

use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.

the class PaymentWorksVendorDataProcessingIntoKfsServiceImpl method createKfsVendorMaintenaceDocument.

private MaintenanceDocument createKfsVendorMaintenaceDocument(PaymentWorksVendor pmwVendor, Map<String, List<PaymentWorksIsoFipsCountryItem>> paymentWorksIsoToFipsCountryMap, Map<String, SupplierDiversity> paymentWorksToKfsDiversityMap, PaymentWorksNewVendorRequestsBatchReportData reportData) {
    MaintenanceDocument vendorMaintenceDoc = null;
    try {
        KfsVendorDataWrapper kfsVendorDataWrapper = getPaymentWorksVendorToKfsVendorDetailConversionService().createKfsVendorDetailFromPmwVendor(pmwVendor, paymentWorksIsoToFipsCountryMap, paymentWorksToKfsDiversityMap);
        if (kfsVendorDataWrapper.noProcessingErrorsGenerated()) {
            vendorMaintenceDoc = buildVendorMaintenanceDocument(pmwVendor, kfsVendorDataWrapper);
            LOG.info("createKfsVendorMaintenaceDocument: vendorMaintenceDoc created for pmwVendorId = " + pmwVendor.getPmwVendorRequestId());
        } else {
            reportData.getRecordsThatCouldNotBeProcessedSummary().incrementRecordCount();
            reportData.addPmwVendorThatCouldNotBeProcessed(new PaymentWorksBatchReportRawDataItem(pmwVendor.toString(), kfsVendorDataWrapper.getErrorMessages()));
            LOG.info("createKfsVendorMaintenaceDocument: vendorMaintenceDoc not created due to pmw-to-kfs data conversion error(s): " + kfsVendorDataWrapper.getErrorMessages().toString());
        }
    } catch (WorkflowException we) {
        List<String> edocCreateErrors = getPaymentWorksBatchUtilityService().convertReportDataValidationErrors(GlobalVariables.getMessageMap().getErrorMessages());
        captureKfsProcessingErrorsForVendor(pmwVendor, reportData, edocCreateErrors);
        LOG.error("createKfsVendorMaintenaceDocument: eDoc creation error(s): " + edocCreateErrors.toString());
        LOG.error("createKfsVendorMaintenaceDocument: eDoc creation exception caught: " + we.getMessage());
        vendorMaintenceDoc = null;
    } finally {
        GlobalVariables.getMessageMap().clearErrorMessages();
    }
    return vendorMaintenceDoc;
}
Also used : MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) PaymentWorksBatchReportRawDataItem(edu.cornell.kfs.pmw.batch.report.PaymentWorksBatchReportRawDataItem) List(java.util.List) KfsVendorDataWrapper(edu.cornell.kfs.pmw.batch.businessobject.KfsVendorDataWrapper)

Example 14 with WorkflowException

use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.

the class CUFinancialSystemDocumentServiceImpl method checkAccountingLinesForChanges.

/**
 *  new == null, old == null : no change; line deleted previously.
 *  new == blah, old == blah : no change
 *  new == blah, old == meh : changed
 *  new == null, old == blah : deleted
 *  new == blah, old == null : added
 * @throws WorkflowException
 *
 * @see org.kuali.kfs.sys.document.service.FinancialSystemDocumentService#checkAccountingLinesForChanges(org.kuali.kfs.sys.document.AccountingDocument)
 */
public void checkAccountingLinesForChanges(AccountingDocument accountingDocument) {
    DocumentService docService = SpringContext.getBean(DocumentService.class);
    AccountingDocument savedDoc = null;
    try {
        savedDoc = (AccountingDocument) docService.getByDocumentHeaderId(accountingDocument.getDocumentNumber());
    } catch (WorkflowException we) {
        LOG.error("Unable to retrieve document number " + accountingDocument.getDocumentNumber() + " to evaluate accounting line changes");
    }
    if (savedDoc == null) {
        return;
    }
    if (!accountingDocument.getSourceAccountingLines().isEmpty()) {
        Map<Integer, AccountingLine> newSourceLines = buildAccountingLineMap(accountingDocument.getSourceAccountingLines());
        Map<Integer, AccountingLine> savedSourceLines = buildAccountingLineMap(savedDoc.getSourceAccountingLines());
        if (newSourceLines.isEmpty())
            return;
        int maxSourceKey = findMinOrMaxKeyValue(newSourceLines, savedSourceLines, false);
        int minSourceKey = findMinOrMaxKeyValue(newSourceLines, savedSourceLines, true);
        for (int i = minSourceKey; i < maxSourceKey + 1; i++) {
            AccountingLine newLine = newSourceLines.get(i);
            AccountingLine oldLine = savedSourceLines.get(i);
            if (!compareTo(newLine, oldLine)) {
                String diff = buildLineChangedNoteText(newLine, oldLine);
                if (StringUtils.isNotBlank(diff)) {
                    writeNote(accountingDocument, diff);
                }
            }
        }
    }
    if (!accountingDocument.getTargetAccountingLines().isEmpty()) {
        Map<Integer, AccountingLine> newTargetLines = buildAccountingLineMap(accountingDocument.getTargetAccountingLines());
        Map<Integer, AccountingLine> savedTargetLines = buildAccountingLineMap(savedDoc.getTargetAccountingLines());
        if (newTargetLines.isEmpty())
            return;
        int maxTargetKey = findMinOrMaxKeyValue(newTargetLines, savedTargetLines, false);
        int minTargetKey = findMinOrMaxKeyValue(newTargetLines, savedTargetLines, true);
        for (int i = minTargetKey; i < maxTargetKey + 1; i++) {
            AccountingLine newLine = newTargetLines.get(i);
            AccountingLine oldLine = savedTargetLines.get(i);
            if (!compareTo(newLine, oldLine)) {
                String diff = buildLineChangedNoteText(newLine, oldLine);
                if (StringUtils.isNotBlank(diff)) {
                    writeNote(accountingDocument, diff);
                }
            }
        }
    }
}
Also used : AccountingLine(org.kuali.kfs.sys.businessobject.AccountingLine) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) DocumentService(org.kuali.kfs.krad.service.DocumentService) CUFinancialSystemDocumentService(edu.cornell.kfs.sys.document.service.CUFinancialSystemDocumentService)

Example 15 with WorkflowException

use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.

the class PaymentApplicationForm method populate.

@Override
public void populate(HttpServletRequest request) {
    super.populate(request);
    // Set the next non-invoiced line number
    PaymentApplicationDocument paymentApplicationDocument = getPaymentApplicationDocument();
    if (ObjectUtils.isNotNull(paymentApplicationDocument.getNonInvoicedDistributions())) {
        for (NonInvoicedDistribution u : paymentApplicationDocument.getNonInvoicedDistributions()) {
            if (null == getNextNonInvoicedLineNumber()) {
                setNextNonInvoicedLineNumber(u.getFinancialDocumentLineNumber());
            } else if (u.getFinancialDocumentLineNumber() > getNextNonInvoicedLineNumber()) {
                setNextNonInvoicedLineNumber(u.getFinancialDocumentLineNumber());
            }
        }
    }
    if (null == getNextNonInvoicedLineNumber()) {
        setNextNonInvoicedLineNumber(1);
    }
    // This step doesn't affect anything persisted to the database. It allows proper calculation
    // of amounts for the display.
    String customerNumber = null;
    String docId = getDocument().getDocumentNumber();
    if (ObjectUtils.isNotNull(request.getParameter(KFSConstants.PARAMETER_DOC_ID)) && ObjectUtils.isNull(getDocument().getDocumentNumber())) {
        // The document hasn't yet been set on the form. Let's look it up manually so that we can get the
        // customer number.
        docId = request.getParameter(KFSConstants.PARAMETER_DOC_ID).trim();
        DocumentService documentService = SpringContext.getBean(DocumentService.class);
        Document d;
        try {
            d = documentService.getByDocumentHeaderId(docId);
        } catch (WorkflowException e) {
            throw new RuntimeException("WorkflowException thrown when trying to load docId [" + docId + "]", e);
        }
        PaymentApplicationDocument pDocument = (PaymentApplicationDocument) d;
        AccountsReceivableDocumentHeader arHeader = pDocument.getAccountsReceivableDocumentHeader();
        if (ObjectUtils.isNotNull(arHeader)) {
            customerNumber = arHeader.getCustomerNumber();
        }
    }
    if (ObjectUtils.isNull(getSelectedInvoiceApplication())) {
        if (ObjectUtils.isNull(invoices) || invoices.isEmpty()) {
            if (ObjectUtils.isNotNull(customerNumber)) {
                // get open invoices for the current customer
                CustomerInvoiceDocumentService customerInvoiceDocumentService = SpringContext.getBean(CustomerInvoiceDocumentService.class);
                Collection<CustomerInvoiceDocument> openInvoicesForCustomer = customerInvoiceDocumentService.getOpenInvoiceDocumentsByCustomerNumber(customerNumber);
                setInvoices(new ArrayList<>(openInvoicesForCustomer));
                if (invoices != null && !invoices.isEmpty()) {
                    setSelectedInvoiceDocumentNumber(invoices.get(0).getDocumentNumber());
                }
                setupInvoiceWrappers(docId);
            }
        }
    }
}
Also used : WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) AccountsReceivableDocumentHeader(org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader) CustomerInvoiceDocumentService(org.kuali.kfs.module.ar.document.service.CustomerInvoiceDocumentService) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument) CustomerInvoiceDocument(org.kuali.kfs.module.ar.document.CustomerInvoiceDocument) NonInvoicedDistribution(org.kuali.kfs.module.ar.businessobject.NonInvoicedDistribution) Document(org.kuali.kfs.krad.document.Document) CustomerInvoiceDocument(org.kuali.kfs.module.ar.document.CustomerInvoiceDocument) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument) CashControlDocument(org.kuali.kfs.module.ar.document.CashControlDocument) WorkflowDocument(org.kuali.kfs.kew.api.WorkflowDocument) DocumentService(org.kuali.kfs.krad.service.DocumentService) CustomerInvoiceDocumentService(org.kuali.kfs.module.ar.document.service.CustomerInvoiceDocumentService)

Aggregations

WorkflowException (org.kuali.kfs.kew.api.exception.WorkflowException)52 ArrayList (java.util.ArrayList)12 DocumentService (org.kuali.kfs.krad.service.DocumentService)11 Document (org.kuali.kfs.krad.document.Document)9 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)7 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)7 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)6 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)6 Date (java.sql.Date)5 HashMap (java.util.HashMap)5 MaintenanceDocument (org.kuali.kfs.kns.document.MaintenanceDocument)5 ValidationException (org.kuali.kfs.krad.exception.ValidationException)5 RemoteException (java.rmi.RemoteException)4 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)4 Person (org.kuali.kfs.kim.api.identity.Person)4 AccountingDocument (org.kuali.kfs.sys.document.AccountingDocument)4 CuElectronicInvoiceRejectDocument (edu.cornell.kfs.module.purap.document.CuElectronicInvoiceRejectDocument)3 AccountGlobal (org.kuali.kfs.coa.businessobject.AccountGlobal)3 Note (org.kuali.kfs.krad.bo.Note)3 ContractsGrantsInvoiceDocument (org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument)3