Search in sources :

Example 16 with WorkflowException

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

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method generateAndSaveContractsAndGrantsInvoiceDocument.

/**
 * FINP-5295 This method was modified for the backport.
 *
 * Generates and then saves a Contracts & Grants Invoice Document
 *
 * @param awd                the award for the document
 * @param validAwardAccounts the award accounts which should appear on the document
 * @param errorMessages      a List of error messages, to be appended to if there are errors in document generation
 * @param accountDetails     letter of credit details if we're creating via loc
 * @param locCreationType    letter of credit creation type if we're creating via loc
 */
protected void generateAndSaveContractsAndGrantsInvoiceDocument(ContractsAndGrantsBillingAward awd, List<ContractsAndGrantsBillingAwardAccount> validAwardAccounts, List<ErrorMessage> errorMessages, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType) {
    ChartOrgHolder chartOrgHolder = financialSystemUserService.getPrimaryOrganization(awd.getAwardPrimaryFundManager().getFundManager().getPrincipalId(), KFSConstants.OptionalModuleNamespaces.ACCOUNTS_RECEIVABLE);
    /*
         * CU Customization (KFSPTS-23675):
         * Include creationProcessType in the method call.
         */
    ContractsGrantsInvoiceDocument cgInvoiceDocument = createCGInvoiceDocumentByAwardInfo(awd, validAwardAccounts, chartOrgHolder.getChartOfAccountsCode(), chartOrgHolder.getOrganizationCode(), errorMessages, accountDetails, locCreationType, creationProcessType);
    if (ObjectUtils.isNotNull(cgInvoiceDocument)) {
        if (cgInvoiceDocument.getTotalInvoiceAmount().isPositive() || getContractsGrantsInvoiceDocumentService().getInvoiceMilestoneTotal(cgInvoiceDocument).isPositive() || getContractsGrantsInvoiceDocumentService().getBillAmountTotal(cgInvoiceDocument).isPositive() || (ArConstants.BillingFrequencyValues.isTimeBased(awd) && ContractsAndGrantsInvoiceDocumentCreationProcessType.MANUAL.equals(creationProcessType))) {
            try {
                documentService.saveDocument(cgInvoiceDocument, DocumentSystemSaveEvent.class);
            } catch (WorkflowException ex) {
                LOG.error("Error creating cgin documents: " + ex.getMessage(), ex);
                throw new RuntimeException("Error creating cgin documents: " + ex.getMessage(), ex);
            }
        } else {
            ErrorMessage errorMessage;
            List<InvoiceAccountDetail> invoiceAccounts = cgInvoiceDocument.getAccountDetails();
            if (!invoiceAccounts.isEmpty()) {
                errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NON_BILLABLE, invoiceAccounts.get(0).getAccountNumber(), awd.getProposalNumber());
            } else {
                errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NON_BILLABLE, null, awd.getProposalNumber());
            }
            errorMessages.add(errorMessage);
        }
    }
}
Also used : ChartOrgHolder(org.kuali.kfs.sys.businessobject.ChartOrgHolder) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) InvoiceAccountDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail) ContractsGrantsInvoiceDocument(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument) ErrorMessage(org.kuali.kfs.krad.util.ErrorMessage) ContractsGrantsInvoiceDocumentErrorMessage(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorMessage)

Example 17 with WorkflowException

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

the class PaymentSourceExtractionServiceImpl method getListByDocumentStatusCodeCampus.

/**
 * This method retrieves a list of disbursement voucher documents that are in the status provided for the campus
 * code given.
 *
 * @param statusCode     The status of the disbursement vouchers to be retrieved.
 * @param campusCode     The campus code that the disbursement vouchers will be associated with.
 * @param immediatesOnly only retrieve Disbursement Vouchers marked for immediate payment
 * @return A collection of disbursement voucher objects that meet the search criteria given.
 */
protected Collection<DisbursementVoucherDocument> getListByDocumentStatusCodeCampus(String statusCode, String campusCode, boolean immediatesOnly) {
    LOG.info("getListByDocumentStatusCodeCampus(statusCode=" + statusCode + ", campusCode=" + campusCode + ", immediatesOnly=" + immediatesOnly + ") started");
    Collection<DisbursementVoucherDocument> list = new ArrayList<>();
    try {
        Collection<DisbursementVoucherDocument> docs = financialSystemDocumentService.findByDocumentHeaderStatusCode(DisbursementVoucherDocument.class, statusCode);
        for (DisbursementVoucherDocument element : docs) {
            String dvdCampusCode = element.getCampusCode();
            if (dvdCampusCode.equals(campusCode) && KFSConstants.PaymentSourceConstants.PAYMENT_METHOD_CHECK.equals(element.getDisbVchrPaymentMethodCode())) {
                if (!immediatesOnly || element.isImmediatePaymentIndicator()) {
                    list.add(element);
                }
            }
        }
    } catch (WorkflowException we) {
        LOG.error("Could not load Disbursement Voucher Documents with status code = " + statusCode + ": " + we);
        throw new RuntimeException(we);
    }
    return list;
}
Also used : WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) ArrayList(java.util.ArrayList) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument)

Example 18 with WorkflowException

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

the class DebitDeterminerServiceImplTest method test.

public void test() {
    CuDisbursementVoucherDocument dv = null;
    try {
        dv = (CuDisbursementVoucherDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DisbursementVoucherDocument.class);
    } catch (WorkflowException e) {
        throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
    }
    if (dv != null) {
        dv.getDocumentHeader().setDocumentDescription("Test Document Description");
        dv.getDocumentHeader().setExplanation("Stuff");
        dv.initiateDocument();
        VendorDetail vendor = SpringContext.getBean(VendorService.class).getVendorDetail("13366-0");
        VendorAddress vendoraddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(vendor.getVendorHeaderGeneratedIdentifier(), vendor.getVendorDetailAssignedIdentifier(), "RM", "");
        System.out.println(vendoraddress.getVendorCityName() + "\n");
        dv.templateVendor(vendor, vendoraddress);
        dv.setPayeeAssigned(true);
        dv.getDvPayeeDetail().setDisbVchrPaymentReasonCode("S");
        dv.setDisbVchrCheckTotalAmount(new KualiDecimal(86.00));
        dv.setDisbVchrPaymentMethodCode("P");
        dv.setDisbVchrCheckStubText("check text");
        SourceAccountingLine accountingLine = new SourceAccountingLine();
        accountingLine.setChartOfAccountsCode("IT");
        accountingLine.setAccountNumber("G081040");
        accountingLine.setFinancialObjectCode("8462");
        accountingLine.setAmount((new KualiDecimal(-14.00)));
        accountingLine.setPostingYear(dv.getPostingYear());
        accountingLine.setDocumentNumber(dv.getDocumentNumber());
        dv.addSourceAccountingLine(accountingLine);
        SourceAccountingLine accountingLine2 = new SourceAccountingLine();
        accountingLine2.setChartOfAccountsCode("IT");
        accountingLine2.setAccountNumber("1453611");
        accountingLine2.setFinancialObjectCode("8462");
        accountingLine2.setAmount((new KualiDecimal(100.00)));
        accountingLine2.setPostingYear(dv.getPostingYear());
        accountingLine2.setDocumentNumber(dv.getDocumentNumber());
        dv.addSourceAccountingLine(accountingLine2);
        try {
            documentService.saveDocument(dv);
        } catch (WorkflowException e) {
            throw new RuntimeException("Error saving new disbursement voucher document: " + e.getMessage(), e);
        }
    }
    List<GeneralLedgerPendingEntrySourceDetail> glpeS = dv.getGeneralLedgerPendingEntrySourceDetails();
    GeneralLedgerPendingEntrySourceDetail postable = glpeS.get(0);
    System.out.println("GL Detail" + postable.toString() + "\n");
    assertFalse(debitDeterminerService.isDebitConsideringNothingPositiveOnly(dv, postable));
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorService(org.kuali.kfs.vnd.document.service.VendorService) CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) GeneralLedgerPendingEntrySourceDetail(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress) DocumentService(org.kuali.kfs.krad.service.DocumentService)

Example 19 with WorkflowException

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

the class DisbursementVoucherDocumentBatchServiceImpl method populateDisbursementVoucherDocument.

/**
 * Creates a new DV document and populates from the batch instance
 *
 * @param disbursementVoucherBatch
 * @param batchDisbursementVoucherDocument batch dv document to pull values from
 * @param batchDefault contains default values to use if value in feed is empty
 * @param MessageMap MessageMap for adding encountered errors
 * @return DisbursementVoucherDocument created and populated DV document
 */
protected DisbursementVoucherDocument populateDisbursementVoucherDocument(DisbursementVoucherBatch disbursementVoucherBatch, BatchDisbursementVoucherDocument batchDisbursementVoucherDocument, DisbursementVoucherBatchDefault batchDefault, MessageMap MessageMap) {
    DisbursementVoucherDocument disbursementVoucherDocument = null;
    try {
        disbursementVoucherDocument = (DisbursementVoucherDocument) documentService.getNewDocument(DisbursementVoucherDocument.class);
    } catch (WorkflowException e) {
        LOG.error("Error creating new disbursement voucher document: " + e.getMessage());
        throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
    }
    // populate extension with batch id
    DisbursementVoucherDocumentExtension disbursementVoucherDocumentExtension = new DisbursementVoucherDocumentExtension();
    disbursementVoucherDocumentExtension.setDocumentNumber(disbursementVoucherDocument.getDocumentNumber());
    disbursementVoucherDocumentExtension.setBatchId(disbursementVoucherBatch.getBatchId());
    disbursementVoucherDocument.setExtension(disbursementVoucherDocumentExtension);
    populateDisbursementVoucherFields(disbursementVoucherDocument, batchDisbursementVoucherDocument, batchDefault, MessageMap);
    batchFeedHelperService.loadDocumentAttachments(disbursementVoucherDocument, batchDisbursementVoucherDocument.getAttachments(), attachmentsPath, "", MessageMap);
    return disbursementVoucherDocument;
}
Also used : DisbursementVoucherDocumentExtension(com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherDocumentExtension) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) BatchDisbursementVoucherDocument(com.rsmart.kuali.kfs.fp.document.BatchDisbursementVoucherDocument) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument)

Example 20 with WorkflowException

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

the class DisbursementVoucherDocumentBatchServiceImpl method loadDisbursementVouchers.

/**
 * @see com.rsmart.kuali.kfs.fp.batch.service.DisbursementVoucherDocumentBatchService#loadDisbursementVouchers(com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchFeed,
 *      com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchStatus, java.lang.String,
 *      org.kuali.kfs.kns.util.MessageMap)
 */
public void loadDisbursementVouchers(DisbursementVoucherBatchFeed batchFeed, DisbursementVoucherBatchStatus batchStatus, String incomingFileName, MessageMap MessageMap) {
    // get new batch record for the load
    DisbursementVoucherBatch disbursementVoucherBatch = getNewDisbursementVoucherBatch();
    businessObjectService.save(disbursementVoucherBatch);
    batchStatus.setUnitCode(batchFeed.getUnitCode());
    boolean batchHasErrors = false;
    for (BatchDisbursementVoucherDocument batchDisbursementVoucherDocument : batchFeed.getBatchDisbursementVoucherDocuments()) {
        batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_DV_RECORDS_READ, 1);
        batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_ACCOUNTING_RECORDS_READ, batchDisbursementVoucherDocument.getSourceAccountingLines().size());
        // get defaults for DV chart/org
        DisbursementVoucherBatchDefault batchDefault = null;
        if (StringUtils.isNotBlank(batchFeed.getUnitCode())) {
            batchDefault = getDisbursementVoucherBatchDefault(batchFeed.getUnitCode());
        }
        MessageMap documentMessageMap = new MessageMap();
        batchFeedHelperService.performForceUppercase(DisbursementVoucherDocument.class.getName(), batchDisbursementVoucherDocument);
        // create and route doc as system user
        // create and route doc as system user
        UserSession actualUserSession = GlobalVariables.getUserSession();
        GlobalVariables.setUserSession(new UserSession(KFSConstants.SYSTEM_USER));
        MessageMap globalMessageMap = GlobalVariables.getMessageMap();
        GlobalVariables.setMessageMap(documentMessageMap);
        DisbursementVoucherDocument disbursementVoucherDocument = null;
        try {
            disbursementVoucherDocument = populateDisbursementVoucherDocument(disbursementVoucherBatch, batchDisbursementVoucherDocument, batchDefault, documentMessageMap);
            // if the document is valid create GLPEs, Save and Approve
            if (documentMessageMap.hasNoErrors()) {
                businessObjectService.save(disbursementVoucherDocument.getExtension());
                documentService.routeDocument(disbursementVoucherDocument, "", null);
                if (documentMessageMap.hasNoErrors()) {
                    batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_DV_RECORDS_WRITTEN, 1);
                    batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_ACCOUNTING_RECORDS_WRITTEN, disbursementVoucherDocument.getSourceAccountingLines().size());
                    batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_GLPE_RECORDS_WRITTEN, disbursementVoucherDocument.getGeneralLedgerPendingEntries().size());
                    batchStatus.getBatchDisbursementVoucherDocuments().add(disbursementVoucherDocument);
                }
            }
        } catch (WorkflowException e) {
            LOG.error("Unable to route DV: " + e.getMessage());
            throw new RuntimeException("Unable to route DV: " + e.getMessage(), e);
        } catch (ValidationException e1) {
        // will be reported in audit report
        } finally {
            GlobalVariables.setUserSession(actualUserSession);
            GlobalVariables.setMessageMap(globalMessageMap);
        }
        if (documentMessageMap.hasErrors()) {
            batchHasErrors = true;
        }
        // populate summary line and add to report
        DisbursementVoucherBatchSummaryLine batchSummaryLine = populateBatchSummaryLine(disbursementVoucherDocument, documentMessageMap);
        batchStatus.getBatchSummaryLines().add(batchSummaryLine);
    }
    // indicate in global map there were errors (for batch upload screen)
    if (batchHasErrors) {
        MessageMap.putError(KFSConstants.GLOBAL_ERRORS, FPKeyConstants.ERROR_BATCH_DISBURSEMENT_VOUCHER_ERRORS_NOTIFICATION);
    }
    batchFeedHelperService.removeDoneFile(incomingFileName);
}
Also used : ValidationException(org.kuali.kfs.krad.exception.ValidationException) BatchDisbursementVoucherDocument(com.rsmart.kuali.kfs.fp.document.BatchDisbursementVoucherDocument) DisbursementVoucherBatchDefault(com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchDefault) UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) DisbursementVoucherBatch(com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatch) DisbursementVoucherBatchSummaryLine(com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchSummaryLine) MessageMap(org.kuali.kfs.krad.util.MessageMap) BatchDisbursementVoucherDocument(com.rsmart.kuali.kfs.fp.document.BatchDisbursementVoucherDocument) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument)

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