Search in sources :

Example 46 with WorkflowException

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

the class PaymentApplicationAdjustmentDocument method generateDocumentGeneralLedgerPendingEntries.

@Override
public boolean generateDocumentGeneralLedgerPendingEntries(final GeneralLedgerPendingEntrySequenceHelper sequenceHelper) {
    try {
        final Document adjusteeDocument = getDocumentService().getByDocumentHeaderId(adjusteeDocumentNumber);
        getPaymentApplicationAdjustmentDocumentService().createPendingEntries(adjusteeDocument, this, getPostingYear(), sequenceHelper).forEach(this::addPendingEntry);
        return true;
    } catch (final WorkflowException e) {
        LOG.error("generateDocumentGeneralLedgerPendingEntries(...) - Failed to generate pending entries", e);
    }
    return false;
}
Also used : WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) Document(org.kuali.kfs.krad.document.Document) WorkflowDocument(org.kuali.kfs.kew.api.WorkflowDocument)

Example 47 with WorkflowException

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

the class CashControlDocument method getReferenceFinancialDocument.

public Document getReferenceFinancialDocument() {
    DocumentService documentService = SpringContext.getBean(DocumentService.class);
    Document document = null;
    try {
        document = documentService.getByDocumentHeaderId(getReferenceFinancialDocumentNumber());
    } catch (WorkflowException we) {
        LOG.warn("Unable to retrieve reference financial document: " + getReferenceFinancialDocumentNumber(), we);
    }
    return document;
}
Also used : WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) Document(org.kuali.kfs.krad.document.Document) GeneralLedgerPostingDocument(org.kuali.kfs.sys.document.GeneralLedgerPostingDocument) DocumentService(org.kuali.kfs.krad.service.DocumentService) CashControlDocumentService(org.kuali.kfs.module.ar.document.service.CashControlDocumentService)

Example 48 with WorkflowException

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

the class PaymentApplicationAction method loadInvoices.

/**
 * This method loads the invoices for currently selected customer
 *
 * @param payAppForm
 * @param selectedInvoiceNumber
 */
protected void loadInvoices(PaymentApplicationForm payAppForm, String selectedInvoiceNumber) {
    PaymentApplicationDocument payAppDoc = payAppForm.getPaymentApplicationDocument();
    AccountsReceivableDocumentHeader arDocHeader = payAppDoc.getAccountsReceivableDocumentHeader();
    String currentInvoiceNumber = selectedInvoiceNumber;
    // entered against the db, and complain to the user if either is not right.
    if (StringUtils.isNotBlank(payAppForm.getSelectedCustomerNumber())) {
        Map<String, String> pkMap = new HashMap<>();
        pkMap.put(ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER, payAppForm.getSelectedCustomerNumber());
        int found = getBusinessObjectService().countMatching(Customer.class, pkMap);
        if (found == 0) {
            addFieldError(KFSConstants.PaymentApplicationTabErrorCodes.APPLY_TO_INVOICE_DETAIL_TAB, ArPropertyConstants.PaymentApplicationDocumentFields.ENTERED_INVOICE_CUSTOMER_NUMBER, ArKeyConstants.PaymentApplicationDocumentErrors.ENTERED_INVOICE_CUSTOMER_NUMBER_INVALID);
        }
    }
    boolean validInvoice = this.isValidInvoice(payAppForm);
    if (!validInvoice) {
        addFieldError(KFSConstants.PaymentApplicationTabErrorCodes.APPLY_TO_INVOICE_DETAIL_TAB, ArPropertyConstants.PaymentApplicationDocumentFields.ENTERED_INVOICE_NUMBER, ArKeyConstants.ERROR_CUSTOMER_INVOICE_DOCUMENT_NOT_FINAL);
    }
    // form with an empty customer number wherever possible.
    if (StringUtils.isBlank(payAppForm.getSelectedCustomerNumber())) {
        if (StringUtils.isBlank(arDocHeader.getCustomerNumber())) {
            if (payAppDoc.hasCashControlDetail()) {
                payAppForm.setSelectedCustomerNumber(payAppDoc.getCashControlDetail().getCustomerNumber());
                arDocHeader.setCustomerNumber(payAppDoc.getCashControlDetail().getCustomerNumber());
            }
        } else {
            payAppForm.setSelectedCustomerNumber(arDocHeader.getCustomerNumber());
        }
    } else {
        arDocHeader.setCustomerNumber(payAppForm.getSelectedCustomerNumber());
    }
    String customerNumber = payAppForm.getSelectedCustomerNumber();
    // Invoice number entered, but no customer number entered
    if (StringUtils.isBlank(customerNumber) && StringUtils.isNotBlank(currentInvoiceNumber) && validInvoice) {
        Customer customer = getCustomerInvoiceDocumentService().getCustomerByInvoiceDocumentNumber(currentInvoiceNumber);
        customerNumber = customer.getCustomerNumber();
        payAppDoc.getAccountsReceivableDocumentHeader().setCustomerNumber(customerNumber);
    }
    // load up the control docs and non-applied holdings for non-cash-control payapps
    if (StringUtils.isNotBlank(customerNumber)) {
        if (!payAppDoc.hasCashControlDocument()) {
            List<PaymentApplicationDocument> nonAppliedControlDocs = new ArrayList<>();
            List<NonAppliedHolding> nonAppliedControlHoldings = new ArrayList<>();
            // documents and nonapplied holdings that this doc paid against.
            if (payAppDoc.isFinal()) {
                nonAppliedControlDocs.addAll(payAppDoc.getPaymentApplicationDocumentsUsedAsControlDocuments());
                nonAppliedControlHoldings.addAll(payAppDoc.getNonAppliedHoldingsUsedAsControls());
            } else {
                // otherwise, we pull all available non-zero non-applied holdings for
                // this customer, and make the associated docs and non-applied holdings available
                // retrieve the set of available non-applied holdings for this customer
                nonAppliedControlHoldings.addAll(getNonAppliedHoldingService().getNonAppliedHoldingsForCustomer(customerNumber));
                // get the parent list of payapp documents that they come from
                List<String> controlDocNumbers = new ArrayList<>();
                for (NonAppliedHolding nonAppliedHolding : nonAppliedControlHoldings) {
                    if (nonAppliedHolding.getAvailableUnappliedAmount().isPositive() && !controlDocNumbers.contains(nonAppliedHolding.getReferenceFinancialDocumentNumber())) {
                        controlDocNumbers.add(nonAppliedHolding.getReferenceFinancialDocumentNumber());
                    }
                }
                // only try to retrieve docs if we have any to retrieve
                if (!controlDocNumbers.isEmpty()) {
                    try {
                        List<Document> docs = getDocumentService().getDocumentsByListOfDocumentHeaderIds(PaymentApplicationDocument.class, controlDocNumbers);
                        for (Document doc : docs) {
                            nonAppliedControlDocs.add((PaymentApplicationDocument) doc);
                        }
                    } catch (WorkflowException e) {
                        throw new RuntimeException("A runtimeException was thrown when trying to retrieve a list " + "of documents.", e);
                    }
                }
            }
            // set the form vars from what we've loaded up here
            payAppForm.setNonAppliedControlDocs(nonAppliedControlDocs);
            payAppForm.setNonAppliedControlHoldings(nonAppliedControlHoldings);
            payAppDoc.setNonAppliedHoldingsForCustomer(new ArrayList<>(nonAppliedControlHoldings));
            payAppForm.setNonAppliedControlAllocations(null);
        }
    }
    // reload invoices for the selected customer number
    if (StringUtils.isNotBlank(customerNumber)) {
        Collection<CustomerInvoiceDocument> openInvoicesForCustomer;
        // at this point, we want to show the invoices it paid against, NOT the set of open invoices
        if (payAppDoc.isFinal()) {
            openInvoicesForCustomer = payAppDoc.getInvoicesPaidAgainst();
        } else {
            openInvoicesForCustomer = getCustomerInvoiceDocumentService().getOpenInvoiceDocumentsByCustomerNumber(customerNumber);
        }
        payAppForm.setInvoices(new ArrayList<>(openInvoicesForCustomer));
        payAppForm.setupInvoiceWrappers(payAppDoc.getDocumentNumber());
    }
    // if no invoice number entered than get the first invoice
    if (StringUtils.isNotBlank(customerNumber) && StringUtils.isBlank(currentInvoiceNumber)) {
        if (payAppForm.getInvoices() == null || payAppForm.getInvoices().isEmpty()) {
            currentInvoiceNumber = null;
        } else {
            currentInvoiceNumber = payAppForm.getInvoices().get(0).getDocumentNumber();
        }
    }
    // load information for the current selected invoice
    if (StringUtils.isNotBlank(currentInvoiceNumber)) {
        payAppForm.setSelectedInvoiceDocumentNumber(currentInvoiceNumber);
        payAppForm.setEnteredInvoiceDocumentNumber(currentInvoiceNumber);
    }
    // Make sure the invoice applies state are up to date
    for (PaymentApplicationInvoiceApply invoiceApplication : payAppForm.getInvoiceApplications()) {
        updateInvoiceApplication(payAppDoc, invoiceApplication);
    }
    // clear any NonInvoiced add line information from the form vars
    payAppForm.setNonInvoicedAddLine(null);
    // load any NonAppliedHolding information into the form vars
    if (payAppDoc.getNonAppliedHolding() != null) {
        payAppForm.setNonAppliedHoldingCustomerNumber(payAppDoc.getNonAppliedHolding().getCustomerNumber());
        payAppForm.setNonAppliedHoldingAmount(payAppDoc.getNonAppliedHolding().getFinancialDocumentLineAmount());
    } else {
        // clear any NonAppliedHolding information from the form vars if it's empty
        payAppForm.setNonAppliedHoldingCustomerNumber(null);
        payAppForm.setNonAppliedHoldingAmount(null);
    }
    // Presort this list to not reload in the jsp - https://jira.kuali.org/browse/KFSCNTRB-1377
    payAppForm.setInvoiceApplications(sortInvoiceApplications(payAppForm.getInvoiceApplications()));
}
Also used : HashMap(java.util.HashMap) Customer(org.kuali.kfs.module.ar.businessobject.Customer) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) ArrayList(java.util.ArrayList) NonAppliedHolding(org.kuali.kfs.module.ar.businessobject.NonAppliedHolding) PaymentApplicationAdjustmentDocument(org.kuali.kfs.module.ar.document.PaymentApplicationAdjustmentDocument) Document(org.kuali.kfs.krad.document.Document) CustomerInvoiceDocument(org.kuali.kfs.module.ar.document.CustomerInvoiceDocument) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument) AccountsReceivableDocumentHeader(org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument) CustomerInvoiceDocument(org.kuali.kfs.module.ar.document.CustomerInvoiceDocument)

Example 49 with WorkflowException

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

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method routeContractsGrantsInvoiceDocuments.

/**
 * This method retrieves all the Contracts & Grants Invoice Documents with a status of Saved and routes them to
 * the next step in the routing path.
 *
 * @return True if the routing was performed successfully. A runtime exception will be thrown if any errors occur
 *         while routing.
 */
@Override
public void routeContractsGrantsInvoiceDocuments() {
    final String currentUserPrincipalId = GlobalVariables.getUserSession().getPerson().getPrincipalId();
    List<String> documentIdList = retrieveContractsGrantsInvoiceDocumentsToRoute(DocumentStatus.SAVED, currentUserPrincipalId);
    if (LOG.isInfoEnabled()) {
        LOG.info("CGinvoice to Route: " + documentIdList);
    }
    for (String cgInvoiceDocId : documentIdList) {
        try {
            ContractsGrantsInvoiceDocument cgInvoiceDoc = (ContractsGrantsInvoiceDocument) documentService.getByDocumentHeaderId(cgInvoiceDocId);
            // To route documents only if the user in the session is same as the initiator.
            if (LOG.isInfoEnabled()) {
                LOG.info("Routing Contracts & Grants Invoice document # " + cgInvoiceDocId + ".");
            }
            documentService.prepareWorkflowDocument(cgInvoiceDoc);
            // calling workflow service to bypass business rule checks
            workflowDocumentService.route(cgInvoiceDoc.getDocumentHeader().getWorkflowDocument(), "", null);
        } catch (WorkflowException e) {
            LOG.error("Error routing document # " + cgInvoiceDocId + " " + e.getMessage());
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}
Also used : WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) ContractsGrantsInvoiceDocument(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument)

Example 50 with WorkflowException

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

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method createCGInvoiceDocumentByAwardInfo.

/*
     * CU Customization (KFSPTS-23675):
     * Added creationProcessType argument and its usage of it.
     */
@Override
public ContractsGrantsInvoiceDocument createCGInvoiceDocumentByAwardInfo(ContractsAndGrantsBillingAward awd, List<ContractsAndGrantsBillingAwardAccount> accounts, String chartOfAccountsCode, String organizationCode, List<ErrorMessage> errorMessages, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType) {
    ContractsGrantsInvoiceDocument cgInvoiceDocument = null;
    if (ObjectUtils.isNotNull(accounts) && !accounts.isEmpty()) {
        if (chartOfAccountsCode != null && organizationCode != null) {
            try {
                cgInvoiceDocument = (ContractsGrantsInvoiceDocument) documentService.getNewDocument(ContractsGrantsInvoiceDocument.class);
                // Set description to the document created.
                cgInvoiceDocument.getDocumentHeader().setDocumentDescription(buildDocumentDescription(awd, accounts));
                // setup several Default Values for CGInvoice document which extends from Customer Invoice Document
                // a) set billing org and chart code
                cgInvoiceDocument.setBillByChartOfAccountCode(chartOfAccountsCode);
                cgInvoiceDocument.setBilledByOrganizationCode(organizationCode);
                // b) set processing org and chart code
                List<String> procCodes = getContractsGrantsInvoiceDocumentService().getProcessingFromBillingCodes(chartOfAccountsCode, organizationCode);
                AccountsReceivableDocumentHeader accountsReceivableDocumentHeader = new AccountsReceivableDocumentHeader();
                accountsReceivableDocumentHeader.setDocumentNumber(cgInvoiceDocument.getDocumentNumber());
                // Set processing chart and org codes
                if (procCodes != null) {
                    int procCodesSize = procCodes.size();
                    // Set processing chart
                    if (procCodesSize > 0) {
                        accountsReceivableDocumentHeader.setProcessingChartOfAccountCode(procCodes.get(0));
                    }
                    // Set processing org code
                    if (procCodesSize > 1) {
                        accountsReceivableDocumentHeader.setProcessingOrganizationCode(procCodes.get(1));
                    }
                }
                cgInvoiceDocument.setAccountsReceivableDocumentHeader(accountsReceivableDocumentHeader);
                populateInvoiceFromAward(awd, accounts, cgInvoiceDocument, accountDetails, locCreationType, creationProcessType);
                contractsGrantsInvoiceDocumentService.createSourceAccountingLines(cgInvoiceDocument, accounts);
                if (ObjectUtils.isNotNull(cgInvoiceDocument.getInvoiceGeneralDetail().getAward())) {
                    contractsGrantsInvoiceDocumentService.updateSuspensionCategoriesOnDocument(cgInvoiceDocument);
                }
                LOG.info("Created Contracts & Grants Invoice Document " + cgInvoiceDocument.getDocumentNumber());
            } catch (WorkflowException ex) {
                LOG.error("Error creating cgin documents: " + ex.getMessage(), ex);
                throw new RuntimeException("Error creating cgin documents: " + ex.getMessage(), ex);
            }
        } else {
            // if chart of account code or organization code is not available, output the error
            final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NO_CHART_OR_ORG, awd.getProposalNumber());
            errorMessages.add(errorMessage);
        }
    }
    return cgInvoiceDocument;
}
Also used : WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) AccountsReceivableDocumentHeader(org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader) ContractsGrantsInvoiceDocument(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument) ErrorMessage(org.kuali.kfs.krad.util.ErrorMessage) ContractsGrantsInvoiceDocumentErrorMessage(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorMessage)

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