Search in sources :

Example 16 with DisbursementVoucherDocument

use of org.kuali.kfs.fp.document.DisbursementVoucherDocument in project cu-kfs by CU-CommunityApps.

the class RecurringDisbursementVoucherDocumentServiceImpl method getCuDisbursementVoucherDocument.

private CuDisbursementVoucherDocument getCuDisbursementVoucherDocument(List<DisbursementVoucherDocument> generatedDVs, RecurringDisbursementVoucherDocument recurringDV, Date dvCheckDate) throws WorkflowException {
    for (DisbursementVoucherDocument dv : generatedDVs) {
        if (dv.getDisbursementVoucherDueDate().equals(dvCheckDate)) {
            return (CuDisbursementVoucherDocument) dv;
        }
    }
    CuDisbursementVoucherDocument dv = buildCuDisbursementVoucherDocument(recurringDV);
    dv.setDisbursementVoucherDueDate(dvCheckDate);
    dv.setDisbursementVoucherCheckDate(new Timestamp(dvCheckDate.getTime()));
    generatedDVs.add(dv);
    return dv;
}
Also used : CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) Timestamp(java.sql.Timestamp) RecurringDisbursementVoucherDocument(edu.cornell.kfs.fp.document.RecurringDisbursementVoucherDocument) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument) CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)

Example 17 with DisbursementVoucherDocument

use of org.kuali.kfs.fp.document.DisbursementVoucherDocument 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.rice.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.rice.kew.api.exception.WorkflowException)

Example 18 with DisbursementVoucherDocument

use of org.kuali.kfs.fp.document.DisbursementVoucherDocument 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.rice.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)

Example 19 with DisbursementVoucherDocument

use of org.kuali.kfs.fp.document.DisbursementVoucherDocument 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.rice.kew.api.exception.WorkflowException) BatchDisbursementVoucherDocument(com.rsmart.kuali.kfs.fp.document.BatchDisbursementVoucherDocument) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument)

Example 20 with DisbursementVoucherDocument

use of org.kuali.kfs.fp.document.DisbursementVoucherDocument in project cu-kfs by CU-CommunityApps.

the class RecurringDisbursementVoucherDocumentServiceImpl method generateDisbursementDocumentsFromRecurringDV.

@Override
public List<DisbursementVoucherDocument> generateDisbursementDocumentsFromRecurringDV(RecurringDisbursementVoucherDocument recurringDV) throws WorkflowException {
    List<DisbursementVoucherDocument> generatedDVs = new ArrayList<DisbursementVoucherDocument>();
    int rowId = 0;
    for (Object accountingLine : recurringDV.getSourceAccountingLines()) {
        ScheduledSourceAccountingLine scheduledAccountingLine = (ScheduledSourceAccountingLine) accountingLine;
        TreeMap<Date, KualiDecimal> datesAndAmounts = getScheduledAccountingLineService().generateDatesAndAmounts(scheduledAccountingLine, rowId);
        for (Date date : datesAndAmounts.keySet()) {
            KualiDecimal amount = datesAndAmounts.get(date);
            CuDisbursementVoucherDocument disbursementVoucherDocument = getCuDisbursementVoucherDocument(generatedDVs, recurringDV, date);
            disbursementVoucherDocument.setDisbVchrCheckTotalAmount(calculateDVCheckAmount(amount, disbursementVoucherDocument));
            RecurringDisbursementVoucherDetail dvDetail = getDetailtem(recurringDV.getRecurringDisbursementVoucherDetails(), date);
            dvDetail.setDvDocumentNumber(disbursementVoucherDocument.getDocumentNumber());
            disbursementVoucherDocument.setDisbVchrCheckStubText(dvDetail.getDvCheckStub());
            SourceAccountingLine line = buildSourceAccountingLine(scheduledAccountingLine);
            line.setAmount(amount);
            disbursementVoucherDocument.addSourceAccountingLine(line);
        }
        rowId++;
    }
    saveDisbursementVouchers(generatedDVs, recurringDV);
    return generatedDVs;
}
Also used : CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) ArrayList(java.util.ArrayList) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) RecurringDisbursementVoucherDetail(edu.cornell.kfs.fp.businessobject.RecurringDisbursementVoucherDetail) ScheduledSourceAccountingLine(edu.cornell.kfs.fp.businessobject.ScheduledSourceAccountingLine) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) ScheduledSourceAccountingLine(edu.cornell.kfs.fp.businessobject.ScheduledSourceAccountingLine) RecurringDisbursementVoucherDocument(edu.cornell.kfs.fp.document.RecurringDisbursementVoucherDocument) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument) CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) Date(java.sql.Date)

Aggregations

DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)44 RecurringDisbursementVoucherDocument (edu.cornell.kfs.fp.document.RecurringDisbursementVoucherDocument)10 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)8 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)7 ArrayList (java.util.ArrayList)6 List (java.util.List)4 DisbursementVoucherNonEmployeeTravel (org.kuali.kfs.fp.businessobject.DisbursementVoucherNonEmployeeTravel)4 DisbursementVoucherPayeeDetail (org.kuali.kfs.fp.businessobject.DisbursementVoucherPayeeDetail)4 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)4 Date (java.sql.Date)3 DisbursementVoucherNonEmployeeExpense (org.kuali.kfs.fp.businessobject.DisbursementVoucherNonEmployeeExpense)3 DisbursementVoucherTaxService (org.kuali.kfs.fp.document.service.DisbursementVoucherTaxService)3 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)3 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)3 BatchDisbursementVoucherDocument (com.rsmart.kuali.kfs.fp.document.BatchDisbursementVoucherDocument)2 CuDisbursementVoucherPayeeDetail (edu.cornell.kfs.fp.businessobject.CuDisbursementVoucherPayeeDetail)2 RecurringDisbursementVoucherDetail (edu.cornell.kfs.fp.businessobject.RecurringDisbursementVoucherDetail)2 HashMap (java.util.HashMap)2 DisbursementVoucherPreConferenceRegistrant (org.kuali.kfs.fp.businessobject.DisbursementVoucherPreConferenceRegistrant)2 DisbursementVoucherTravelService (org.kuali.kfs.fp.document.service.DisbursementVoucherTravelService)2