Search in sources :

Example 21 with MessageMap

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

the class FavoriteAccountLineBuilderTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    userProcurementProfileValidationService = new UserProcurementProfileValidationServiceImpl();
    userFavoriteAccountService = new ExtendedTestUserFavoriteAccountService();
    reqsAccounts = new ArrayList<PurApAccountingLine>();
    poAccounts = new ArrayList<PurApAccountingLine>();
    reqsItem = new RequisitionItem();
    poItem = new PurchaseOrderItem();
    reqsDoc = getMockedDocument(CuRequisitionDocument.class);
    poDoc = getMockedDocument(PurchaseOrderDocument.class);
    iwntDoc = getMockedDocument(IWantDocument.class);
    iwntDoc.setAccounts(new ArrayList<IWantAccount>());
    // Favorite Account with only some fields populated.
    testFavoriteAccount = new FavoriteAccount();
    testFavoriteAccount.setAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    testFavoriteAccount.setUserProfileId(TEST_USER_PROFILE_ID);
    testFavoriteAccount.setChartOfAccountsCode(TEST_CHART_CODE);
    testFavoriteAccount.setAccountNumber(TEST_ACCOUNT_NUMBER);
    testFavoriteAccount.setFinancialObjectCode(TEST_OBJECT_CODE);
    // Favorite Account with all fields populated (except reference objects or object ID or version number).
    testAltFavoriteAccount = new FavoriteAccount();
    testAltFavoriteAccount.setAccountLineIdentifier(TEST_ALT_FAVORITE_ACCOUNT_LINE_ID);
    testAltFavoriteAccount.setUserProfileId(TEST_ALT_USER_PROFILE_ID);
    testAltFavoriteAccount.setChartOfAccountsCode(TEST_ALT_CHART_CODE);
    testAltFavoriteAccount.setAccountNumber(TEST_ALT_ACCOUNT_NUMBER);
    testAltFavoriteAccount.setSubAccountNumber(TEST_ALT_SUB_ACCOUNT_NUMBER);
    testAltFavoriteAccount.setFinancialObjectCode(TEST_ALT_OBJECT_CODE);
    testAltFavoriteAccount.setFinancialSubObjectCode(TEST_ALT_SUB_OBJECT_CODE);
    testAltFavoriteAccount.setProjectCode(TEST_ALT_PROJECT_CODE);
    testAltFavoriteAccount.setOrganizationReferenceId(TEST_ALT_ORG_REF_ID);
    GlobalVariables.setMessageMap(new MessageMap());
}
Also used : FavoriteAccount(edu.cornell.kfs.sys.businessobject.FavoriteAccount) CuRequisitionDocument(edu.cornell.kfs.module.purap.document.CuRequisitionDocument) IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) UserProcurementProfileValidationServiceImpl(edu.cornell.kfs.sys.service.impl.UserProcurementProfileValidationServiceImpl) PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) RequisitionItem(org.kuali.kfs.module.purap.businessobject.RequisitionItem) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) MessageMap(org.kuali.kfs.krad.util.MessageMap) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument) BeforeClass(org.junit.BeforeClass)

Example 22 with MessageMap

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

the class PurchasingProcessItemValidation method validate.

/* (non-Javadoc)
	 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
	 */
public boolean validate(AttributedDocumentEvent event) {
    boolean valid = true;
    PurchasingDocument purDocument = (PurchasingDocument) event.getDocument();
    MessageMap errorMap = GlobalVariables.getMessageMap();
    errorMap.clearErrorPath();
    // errorMap.addToErrorPath(PurapConstants.ITEM_TAB_ERRORS);
    // KFSPTS-1719 :  remove this validation
    // // Check that item isn't a non-qty item on an e-invoice vendor order
    // Check that there aren't any req items that already have non-qty values entered
    List<PurApItem> reqItems = purDocument.getItems();
    // KFSPTS-2096
    if (!reqItems.isEmpty()) {
        String itemTypeCode = KFSConstants.EMPTY_STRING;
        int i = 0;
        for (PurApItem item : reqItems) {
            if (StringUtils.isEmpty(itemTypeCode) && (PurapConstants.ItemTypeCodes.ITEM_TYPE_SERVICE_CODE.equalsIgnoreCase(item.getItemTypeCode()) || PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE.equalsIgnoreCase(item.getItemTypeCode()))) {
                itemTypeCode = item.getItemTypeCode();
            }
            if (StringUtils.isNotBlank(itemTypeCode) && (PurapConstants.ItemTypeCodes.ITEM_TYPE_SERVICE_CODE.equalsIgnoreCase(item.getItemTypeCode()) || PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE.equalsIgnoreCase(item.getItemTypeCode())) && !itemTypeCode.equalsIgnoreCase(item.getItemTypeCode())) {
                // Throw error that mix qty and no-qty
                // errorMap.addToErrorPath("document.item["+ i + "].itemTypeCode");
                errorMap.putError("document.item[" + i + "].itemTypeCode", CUPurapKeyConstants.PURAP_MIX_ITEM_QTY_NONQTY);
                // errorMap.removeFromErrorPath("document.item["+ i + "].itemTypeCode");
                valid &= false;
            }
            if (PurapConstants.ItemTypeCodes.ITEM_TYPE_SERVICE_CODE.equalsIgnoreCase(item.getItemTypeCode()) || PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE.equalsIgnoreCase(item.getItemTypeCode())) {
                i++;
            }
        }
    }
    // errorMap.clearErrorPath();
    return valid;
}
Also used : PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) PurchasingDocument(org.kuali.kfs.module.purap.document.PurchasingDocument) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 23 with MessageMap

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

the class CuPurchasingProcessVendorValidation method validate.

@Override
public boolean validate(AttributedDocumentEvent event) {
    boolean valid = true;
    PurchasingDocument purDocument = (PurchasingDocument) event.getDocument();
    MessageMap errorMap = GlobalVariables.getMessageMap();
    errorMap.clearErrorPath();
    errorMap.addToErrorPath(PurapConstants.VENDOR_ERRORS);
    if (!purDocument.getRequisitionSourceCode().equals(PurapConstants.RequisitionSources.B2B)) {
        // CU enhancement here. Replaced foundation implementation block
        if ((purDocument.getVendorHeaderGeneratedIdentifier() != null) && (!(isDocumentInNodeWhereMopotDataValidationIsBypassed(purDocument))) && (purDocument.getPurchaseOrderTransmissionMethodCode().equals(CUPurapConstants.POTransmissionMethods.EMAIL) || purDocument.getPurchaseOrderTransmissionMethodCode().equals(PurapConstants.POTransmissionMethods.FAX) || purDocument.getPurchaseOrderTransmissionMethodCode().equals(CUPurapConstants.POTransmissionMethods.MANUAL))) {
            valid &= this.validateDataForMethodOfPOTransmissionExistsOnVendorAddress(purDocument);
        // called routine took care of presenting error message to user
        }
    }
    VendorDetail vendorDetail = getVendorService().getVendorDetail(purDocument.getVendorHeaderGeneratedIdentifier(), purDocument.getVendorDetailAssignedIdentifier());
    if (ObjectUtils.isNull(vendorDetail)) {
        return valid;
    }
    VendorHeader vendorHeader = vendorDetail.getVendorHeader();
    // make sure that the vendor is not debarred
    if (vendorDetail.isVendorDebarred()) {
        if (getParameterService().getParameterValueAsBoolean(KFSConstants.OptionalModuleNamespaces.PURCHASING_ACCOUNTS_PAYABLE, "Requisition", PurapParameterConstants.SHOW_DEBARRED_VENDOR_WARNING_IND)) {
            if (StringUtils.isEmpty(((PurchasingDocumentBase) purDocument).getJustification())) {
                errorMap.putWarning(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.WARNING_DEBARRED_VENDOR, vendorDetail.getVendorName());
                valid &= false;
            }
        } else {
            errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_DEBARRED_VENDOR);
            valid &= false;
        }
    }
    // make sure that the vendor is of allowed type
    List<String> allowedVendorTypes = new ArrayList<String>(getParameterService().getParameterValuesAsString(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapRuleConstants.PURAP_VENDOR_TYPE_ALLOWED_ON_REQ_AND_PO));
    if (allowedVendorTypes != null && !allowedVendorTypes.isEmpty()) {
        if (ObjectUtils.isNotNull(vendorHeader) && ObjectUtils.isNotNull(vendorHeader.getVendorTypeCode()) && !allowedVendorTypes.contains(vendorHeader.getVendorTypeCode())) {
            valid &= false;
            errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_INVALID_VENDOR_TYPE);
        }
    }
    // make sure that the vendor is active
    if (!vendorDetail.isActiveIndicator()) {
        valid &= false;
        errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_INACTIVE_VENDOR);
    }
    // make sure that the vendor contract is active and not expired.
    // KFSUPGRADE-266 remove kfsmi-8690/kfscntrb-929
    // if (ObjectUtils.isNotNull(purDocument.getVendorContractGeneratedIdentifier())) {
    // VendorContract vendorContract = SpringContext.getBean(BusinessObjectService.class).findBySinglePrimaryKey(VendorContract.class, purDocument.getVendorContractGeneratedIdentifier());
    // Date currentDate = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();
    // 
    // if (currentDate.compareTo(vendorContract.getVendorContractEndDate()) > 0 || !vendorContract.isActive()) {
    // valid &= false;
    // errorMap.putError(VendorPropertyConstants.VENDOR_CONTRACT_NAME, PurapKeyConstants.ERROR_INACTIVE_OR_EXPIRED_VENDOR_CONTRACT);
    // }
    // }
    // validate vendor address
    getPostalCodeValidationService().validateAddress(purDocument.getVendorCountryCode(), purDocument.getVendorStateCode(), purDocument.getVendorPostalCode(), PurapPropertyConstants.VENDOR_STATE_CODE, PurapPropertyConstants.VENDOR_POSTAL_CODE);
    errorMap.clearErrorPath();
    return valid;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorHeader(org.kuali.kfs.vnd.businessobject.VendorHeader) ArrayList(java.util.ArrayList) PurchasingDocument(org.kuali.kfs.module.purap.document.PurchasingDocument) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 24 with MessageMap

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

the class CuPaymentRequestTaxAreaValidation method validateTaxRates.

protected boolean validateTaxRates(PaymentRequestDocument preq) {
    boolean valid = true;
    String code = preq.getTaxClassificationCode();
    BigDecimal fedrate = preq.getTaxFederalPercent();
    BigDecimal strate = preq.getTaxStatePercent();
    MessageMap errorMap = GlobalVariables.getMessageMap();
    // only test the cases when income class and tax rates aren't empty/N
    if (StringUtils.isEmpty(code) || StringUtils.equalsIgnoreCase(code, "N") || fedrate == null || strate == null) {
        return true;
    }
    // validate that the federal and state tax rates are among the allowed set
    // (ArrayList<BigDecimal>) federalTaxRates.get(code);
    ArrayList<BigDecimal> fedrates = retrieveTaxRates(code, "F");
    if (!listContainsValue(fedrates, fedrate)) {
        valid = false;
        errorMap.putError(PurapPropertyConstants.TAX_FEDERAL_PERCENT, PurapKeyConstants.ERROR_PAYMENT_REQUEST_TAX_FIELD_VALUE_INVALID_IF, PurapPropertyConstants.TAX_CLASSIFICATION_CODE, PurapPropertyConstants.TAX_FEDERAL_PERCENT);
    }
    // (ArrayList<BigDecimal>) stateTaxRates.get(code);
    ArrayList<BigDecimal> strates = retrieveTaxRates(code, "S");
    if (!listContainsValue(strates, strate)) {
        valid = false;
        errorMap.putError(PurapPropertyConstants.TAX_STATE_PERCENT, PurapKeyConstants.ERROR_PAYMENT_REQUEST_TAX_FIELD_VALUE_INVALID_IF, PurapPropertyConstants.TAX_CLASSIFICATION_CODE, PurapPropertyConstants.TAX_STATE_PERCENT);
    }
    // validate that the federal and state tax rate abide to certain relationship
    if (fedrate.compareTo(new BigDecimal(0)) == 0 && strate.compareTo(new BigDecimal(0)) != 0) {
        valid = false;
        errorMap.putError(PurapPropertyConstants.TAX_STATE_PERCENT, PurapKeyConstants.ERROR_PAYMENT_REQUEST_TAX_RATE_MUST_ZERO_IF, PurapPropertyConstants.TAX_FEDERAL_PERCENT, PurapPropertyConstants.TAX_STATE_PERCENT);
    }
    return valid;
}
Also used : BigDecimal(java.math.BigDecimal) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 25 with MessageMap

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

the class CuPurchaseOrderProcessVendorValidation method validate.

@Override
public boolean validate(AttributedDocumentEvent event) {
    boolean valid = super.validate(event);
    PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) event.getDocument();
    PurchaseOrderDocument poDocument = (PurchaseOrderDocument) purapDocument;
    MessageMap errorMap = GlobalVariables.getMessageMap();
    errorMap.clearErrorPath();
    errorMap.addToErrorPath(PurapConstants.VENDOR_ERRORS);
    // check to see if the vendor exists in the database, i.e. its ID is not null
    Integer vendorHeaderID = poDocument.getVendorHeaderGeneratedIdentifier();
    if (ObjectUtils.isNull(vendorHeaderID)) {
        valid = false;
        errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_NONEXIST_VENDOR);
    }
    // vendor active validation...
    VendorDetail vendorDetail = super.getVendorService().getVendorDetail(poDocument.getVendorHeaderGeneratedIdentifier(), poDocument.getVendorDetailAssignedIdentifier());
    if (ObjectUtils.isNull(vendorDetail)) {
        return valid;
    }
    // make sure that the vendor is active
    if (!vendorDetail.isActiveIndicator()) {
        valid &= false;
        errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_INACTIVE_VENDOR);
    }
    // validate vendor address
    super.getPostalCodeValidationService().validateAddress(poDocument.getVendorCountryCode(), poDocument.getVendorStateCode(), poDocument.getVendorPostalCode(), PurapPropertyConstants.VENDOR_STATE_CODE, PurapPropertyConstants.VENDOR_POSTAL_CODE);
    // Do checks for alternate payee vendor.
    Integer alternateVendorHdrGeneratedId = poDocument.getAlternateVendorHeaderGeneratedIdentifier();
    Integer alternateVendorHdrDetailAssignedId = poDocument.getAlternateVendorDetailAssignedIdentifier();
    VendorDetail alternateVendor = super.getVendorService().getVendorDetail(alternateVendorHdrGeneratedId, alternateVendorHdrDetailAssignedId);
    if (alternateVendor != null) {
        if (alternateVendor.isVendorDebarred()) {
            errorMap.putError(PurapPropertyConstants.ALTERNATE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_DEBARRED);
            valid &= false;
        }
        if (StringUtils.equals(alternateVendor.getVendorHeader().getVendorTypeCode(), VendorTypes.DISBURSEMENT_VOUCHER)) {
            errorMap.putError(PurapPropertyConstants.ALTERNATE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_DV_TYPE);
            valid &= false;
        }
        if (!alternateVendor.isActiveIndicator()) {
            errorMap.putError(PurapPropertyConstants.ALTERNATE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_INACTIVE, PODocumentsStrings.ALTERNATE_PAYEE_VENDOR);
            valid &= false;
        }
    }
    // make sure that the vendor contract expiration date and not marked inactive.
    // KFSUPGRADE-266 remove kfsmi-8690/kfscntrb-929
    // if (StringUtils.isNotBlank(poDocument.getVendorContractName())) {
    // if (super.getVendorService().isVendorContractExpired(poDocument, poDocument.getVendorContractGeneratedIdentifier(), vendorDetail)) {
    // errorMap.putError(VendorPropertyConstants.VENDOR_CONTRACT_END_DATE, PurapKeyConstants.ERROR_EXPIRED_CONTRACT_END_DATE);
    // valid &= false;
    // }
    // }
    errorMap.clearErrorPath();
    return valid;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) PurchasingAccountsPayableDocument(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument) 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