Search in sources :

Example 11 with MessageMap

use of org.kuali.kfs.krad.util.MessageMap in project cu-kfs by CU-CommunityApps.

the class SubmitTripWebServiceImpl method buildDisbursementVoucher.

/**
 * @param dvDescription
 * @param dvExplanation
 * @param tripNumber
 * @param travelerNetId
 * @param initiatorNetId
 * @param totalAmount
 * @param checkStubText
 * @return
 * @throws Exception
 */
private String buildDisbursementVoucher(String dvDescription, String dvExplanation, String tripNumber, String travelerNetId, String initiatorNetId, double totalAmount, String checkStubText) throws Exception {
    try {
        if (!isValidDocumentInitiator(initiatorNetId, DISBURSEMENT_VOUCHER)) {
            throw new RuntimeException("Initiator identified does not have permission to create a DV.");
        }
    } catch (Exception ex) {
        throw new RuntimeException("Initiator identified does not have permission to create a DV.", ex);
    }
    // create and route doc as system user
    GlobalVariables.setUserSession(new UserSession(initiatorNetId));
    MessageMap documentErrorMap = new MessageMap();
    GlobalVariables.setMessageMap(documentErrorMap);
    // Create document with description provided
    CuDisbursementVoucherDocument dvDoc = null;
    try {
        dvDoc = (CuDisbursementVoucherDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DisbursementVoucherDocument.class);
    } catch (WorkflowException e) {
        throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
    }
    if (dvDoc != null) {
        dvDoc.getDocumentHeader().setDocumentDescription(dvDescription);
        dvDoc.getDocumentHeader().setExplanation(dvExplanation);
        dvDoc.getDocumentHeader().setOrganizationDocumentNumber(tripNumber);
        dvDoc.initiateDocument();
        // Set vendor to traveler using netID provided
        Person traveler = SpringContext.getBean(PersonService.class).getPersonByPrincipalName(travelerNetId);
        for (EntityAffiliationContract entityAffiliation : ((PersonImpl) traveler).getAffiliations()) {
            if (entityAffiliation.isDefaultValue()) {
                if (StringUtils.equalsIgnoreCase(entityAffiliation.getAffiliationType().getCode(), CuDisbursementVoucherConstants.PayeeAffiliations.STUDENT)) {
                    dvDoc.templateStudent(traveler);
                } else if (StringUtils.equalsIgnoreCase(entityAffiliation.getAffiliationType().getCode(), CuDisbursementVoucherConstants.PayeeAffiliations.ALUMNI)) {
                    dvDoc.templateAlumni(traveler);
                } else if (StringUtils.equalsIgnoreCase(entityAffiliation.getAffiliationType().getCode(), CuDisbursementVoucherConstants.PayeeAffiliations.FACULTY) || StringUtils.equalsIgnoreCase(entityAffiliation.getAffiliationType().getCode(), CuDisbursementVoucherConstants.PayeeAffiliations.STAFF)) {
                    dvDoc.templateEmployee(traveler);
                }
            }
        }
        dvDoc.setPayeeAssigned(true);
        dvDoc.getDvPayeeDetail().setDisbVchrPaymentReasonCode("J");
        dvDoc.setDisbVchrCheckTotalAmount(new KualiDecimal(totalAmount));
        dvDoc.setDisbVchrPaymentMethodCode("P");
        dvDoc.setDisbVchrCheckStubText(checkStubText);
        dvDoc.setTripId(tripNumber);
        dvDoc.setTripAssociationStatusCode(CULegacyTravelServiceImpl.TRIP_ASSOCIATIONS.IS_TRIP_DOC);
        // Persist document
        SpringContext.getBean(DocumentService.class).saveDocument(dvDoc);
        return dvDoc.getDocumentNumber();
    } else {
        return "";
    }
}
Also used : EntityAffiliationContract(org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationContract) CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) PersonImpl(org.kuali.rice.kim.impl.identity.PersonImpl) UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) PersonService(org.kuali.rice.kim.api.identity.PersonService) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) Person(org.kuali.rice.kim.api.identity.Person) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) MessageMap(org.kuali.kfs.krad.util.MessageMap) DocumentService(org.kuali.kfs.krad.service.DocumentService)

Example 12 with MessageMap

use of org.kuali.kfs.krad.util.MessageMap in project cu-kfs by CU-CommunityApps.

the class SubmitTripWebServiceImpl method submitTrip.

/**
 */
public String submitTrip(String dvDescription, String dvExplanation, String tripNumber, String travelerNetId, String initiatorNetId, double totalAmount, String checkStubText) throws Exception {
    UserSession actualUserSession = GlobalVariables.getUserSession();
    MessageMap globalErrorMap = GlobalVariables.getMessageMap();
    try {
        if (totalAmount > 0.00) {
            return buildDisbursementVoucher(dvDescription, dvExplanation, tripNumber, travelerNetId, initiatorNetId, totalAmount, checkStubText);
        } else {
            return buildDistributionIncomeExpenseDocument(dvDescription, dvExplanation, tripNumber, initiatorNetId);
        }
    } finally {
        GlobalVariables.setUserSession(actualUserSession);
        GlobalVariables.setMessageMap(globalErrorMap);
    }
}
Also used : UserSession(org.kuali.kfs.krad.UserSession) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 13 with MessageMap

use of org.kuali.kfs.krad.util.MessageMap 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 14 with MessageMap

use of org.kuali.kfs.krad.util.MessageMap in project cu-kfs by CU-CommunityApps.

the class SubmitTripWebServiceImpl method buildDistributionIncomeExpenseDocument.

/**
 * @param diDescription
 * @param diExplanation
 * @param tripNumber
 * @param initiatorNetId
 * @return
 * @throws Exception
 */
private String buildDistributionIncomeExpenseDocument(String diDescription, String diExplanation, String tripNumber, String initiatorNetId) throws Exception {
    try {
        if (!isValidDocumentInitiator(initiatorNetId, DISTRIBUTION_INCOME_EXPENSE)) {
            throw new RuntimeException("Initiator identified does not have permission to create a DI.");
        }
    } catch (Exception ex) {
        throw new RuntimeException("Initiator identified does not have permission to create a DI.", ex);
    }
    // create and route doc as system user
    GlobalVariables.setUserSession(new UserSession(initiatorNetId));
    MessageMap documentErrorMap = new MessageMap();
    GlobalVariables.setMessageMap(documentErrorMap);
    // Create document with description provided
    CuDistributionOfIncomeAndExpenseDocument diDoc = null;
    try {
        diDoc = (CuDistributionOfIncomeAndExpenseDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DistributionOfIncomeAndExpenseDocument.class);
    } catch (WorkflowException e) {
        throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
    }
    if (diDoc != null) {
        diDoc.getDocumentHeader().setDocumentDescription(diDescription);
        diDoc.getDocumentHeader().setExplanation(diExplanation);
        diDoc.getDocumentHeader().setOrganizationDocumentNumber(tripNumber);
        diDoc.setTripAssociationStatusCode(CULegacyTravelServiceImpl.TRIP_ASSOCIATIONS.IS_TRIP_DOC);
        diDoc.setTripId(tripNumber);
        // Persist document
        SpringContext.getBean(DocumentService.class).saveDocument(diDoc);
        return diDoc.getDocumentNumber();
    } else {
        return "";
    }
}
Also used : UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) MessageMap(org.kuali.kfs.krad.util.MessageMap) DocumentService(org.kuali.kfs.krad.service.DocumentService) CuDistributionOfIncomeAndExpenseDocument(edu.cornell.kfs.fp.document.CuDistributionOfIncomeAndExpenseDocument)

Example 15 with MessageMap

use of org.kuali.kfs.krad.util.MessageMap in project cu-kfs by CU-CommunityApps.

the class CuBudgetAdjustmentDocumentBalancedValidation method validate.

public boolean validate(AttributedDocumentEvent event) {
    MessageMap errors = GlobalVariables.getMessageMap();
    boolean balanced = true;
    // check base amounts are equal
    // KFSMI-3036
    KualiInteger sourceBaseBudgetTotal = getAccountingDocumentForValidation().getSourceBaseBudgetIncomeTotal().subtract(getAccountingDocumentForValidation().getSourceBaseBudgetExpenseTotal());
    KualiInteger targetBaseBudgetTotal = getAccountingDocumentForValidation().getTargetBaseBudgetIncomeTotal().subtract(getAccountingDocumentForValidation().getTargetBaseBudgetExpenseTotal());
    if (sourceBaseBudgetTotal.compareTo(targetBaseBudgetTotal) != 0) {
        GlobalVariables.getMessageMap().putError(KFSConstants.ACCOUNTING_LINE_ERRORS, KFSKeyConstants.ERROR_DOCUMENT_BA_BASE_AMOUNTS_BALANCED);
        balanced = false;
    }
    // check document is balanced within the accounts
    Map accountsMap = buildAccountBalanceMapForDocumentBalance(true);
    for (KualiDecimal accountAmount : (Collection<KualiDecimal>) accountsMap.values()) {
        if (accountAmount.isNonZero()) {
            GlobalVariables.getMessageMap().putError(KFSConstants.ACCOUNTING_LINE_ERRORS, CUKFSKeyConstants.ERROR_DOCUMENT_BA_ACCOUNT_BASE_AMOUNTS_BALANCED);
            balanced = false;
            break;
        }
    }
    // check current amounts balance, income stream balance Map should add to 0
    Map incomeStreamMap = getAccountingDocumentForValidation().buildIncomeStreamBalanceMapForDocumentBalance();
    KualiDecimal totalCurrentAmount = new KualiDecimal(0);
    for (Iterator iter = incomeStreamMap.values().iterator(); iter.hasNext(); ) {
        KualiDecimal streamAmount = (KualiDecimal) iter.next();
        totalCurrentAmount = totalCurrentAmount.add(streamAmount);
    }
    if (totalCurrentAmount.isNonZero()) {
        GlobalVariables.getMessageMap().putError(KFSConstants.ACCOUNTING_LINE_ERRORS, KFSKeyConstants.ERROR_DOCUMENT_BA_CURRENT_AMOUNTS_BALANCED);
        balanced = false;
    }
    // check document is balanced within the accounts
    accountsMap = buildAccountBalanceMapForDocumentBalance(false);
    for (KualiDecimal accountAmount : (Collection<KualiDecimal>) accountsMap.values()) {
        if (accountAmount.isNonZero()) {
            GlobalVariables.getMessageMap().putError(KFSConstants.ACCOUNTING_LINE_ERRORS, CUKFSKeyConstants.ERROR_DOCUMENT_BA_ACCOUNT_AMOUNTS_BALANCED);
            balanced = false;
            break;
        }
    }
    return balanced;
}
Also used : KualiInteger(org.kuali.rice.core.api.util.type.KualiInteger) Iterator(java.util.Iterator) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) MessageMap(org.kuali.kfs.krad.util.MessageMap) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Aggregations

MessageMap (org.kuali.kfs.krad.util.MessageMap)25 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)5 UserSession (org.kuali.kfs.krad.UserSession)4 Person (org.kuali.rice.kim.api.identity.Person)4 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)3 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)3 ValidationException (org.kuali.kfs.krad.exception.ValidationException)3 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)3 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)3 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)2 CuVendorCreditMemoDocument (edu.cornell.kfs.module.purap.document.CuVendorCreditMemoDocument)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 DisbursementVoucherPayeeDetail (org.kuali.kfs.fp.businessobject.DisbursementVoucherPayeeDetail)2 MaintenanceDocument (org.kuali.kfs.krad.maintenance.MaintenanceDocument)2 DocumentService (org.kuali.kfs.krad.service.DocumentService)2 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)2 PurchasingDocument (org.kuali.kfs.module.purap.document.PurchasingDocument)2 VendorCreditMemoDocument (org.kuali.kfs.module.purap.document.VendorCreditMemoDocument)2 ParseException (org.kuali.kfs.sys.exception.ParseException)2