Search in sources :

Example 1 with VendorContractOrganization

use of org.kuali.kfs.vnd.businessobject.VendorContractOrganization in project cu-kfs by CU-CommunityApps.

the class VendorRule method validateContracts.

private boolean validateContracts(VendorDetail vendorDetail) {
    boolean success = true;
    int vendorPos = 0;
    List<VendorContract> vendorContracts = vendorDetail.getVendorContracts();
    for (VendorContract vendorContract : vendorContracts) {
        List<VendorContractOrganization> organizations = vendorContract.getVendorContractOrganizations();
        List<VendorContractOrganization> organizationCopy = new ArrayList<>(organizations);
        for (VendorContractOrganization organization : organizations) {
            String chartCode = organization.getChartOfAccountsCode();
            String organizationCode = organization.getOrganizationCode();
            if (StringUtils.isNotEmpty(chartCode) && StringUtils.isNotEmpty(organizationCode)) {
                int counter = 0;
                int organizationPos = 0;
                for (VendorContractOrganization org : organizationCopy) {
                    if (chartCode.equalsIgnoreCase(org.getChartOfAccountsCode()) && organizationCode.equalsIgnoreCase(org.getOrganizationCode())) {
                        if (counter++ != 0) {
                            organizationCopy.remove(organization);
                            putFieldError(VendorPropertyConstants.VENDOR_CONTRACT + "[" + vendorPos + "]." + VendorPropertyConstants.VENDOR_CONTRACT_ORGANIZATION + "[" + organizationPos + "]." + VendorPropertyConstants.VENDOR_CUSTOMER_NUMBER_CHART_OF_ACCOUNTS_CODE, VendorKeyConstants.ERROR_DUPLICATE_ENTRY_NOT_ALLOWED, chartCode + " " + organizationCode);
                            success = false;
                            break;
                        }
                    }
                    organizationPos++;
                }
            }
            vendorPos++;
        }
    }
    return success;
}
Also used : VendorContract(org.kuali.kfs.vnd.businessobject.VendorContract) ArrayList(java.util.ArrayList) VendorContractOrganization(org.kuali.kfs.vnd.businessobject.VendorContractOrganization)

Example 2 with VendorContractOrganization

use of org.kuali.kfs.vnd.businessobject.VendorContractOrganization in project cu-kfs by CU-CommunityApps.

the class VendorRule method processCustomAddCollectionLineBusinessRules.

/**
 * Validates business rules for VendorDetail document collection add lines. Add lines are the initial lines on a
 * collections, i.e. the ones next to the "Add" button
 */
@Override
public boolean processCustomAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject bo) {
    boolean success = true;
    // this incoming bo needs to be refreshed because it doesn't have its subobjects setup
    bo.refreshNonUpdateableReferences();
    if (bo instanceof VendorAddress) {
        VendorAddress address = (VendorAddress) bo;
        success = checkAddressCountryEmptyStateZip(address);
    }
    if (bo instanceof VendorContract) {
        VendorContract contract = (VendorContract) bo;
        success &= validateVendorContractBeginEndDates(contract);
        success &= processContractB2BValidation(contract, -1);
    }
    if (bo instanceof VendorContractOrganization) {
        VendorContractOrganization contractOrg = (VendorContractOrganization) bo;
        success &= validateVendorContractOrganization(contractOrg, 0);
    }
    if (bo instanceof VendorCustomerNumber) {
        VendorCustomerNumber customerNumber = (VendorCustomerNumber) bo;
        success &= validateVendorCustomerNumber(customerNumber);
    }
    if (bo instanceof VendorDefaultAddress) {
        VendorDefaultAddress defaultAddress = (VendorDefaultAddress) bo;
        String parentName = StringUtils.substringBeforeLast(collectionName, ".");
        VendorAddress parent = (VendorAddress) ObjectUtils.getPropertyValue(this.getNewBo(), parentName);
        VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getBusinessObject();
        success &= checkDefaultAddressCampus(vendorDetail, defaultAddress, parent);
    }
    if (bo instanceof VendorCommodityCode) {
        VendorCommodityCode commodityCode = (VendorCommodityCode) bo;
        String purchasingCommodityCode = commodityCode.getPurchasingCommodityCode();
        boolean found = ObjectUtils.isNotNull(commodityCode) && StringUtils.isNotBlank(purchasingCommodityCode) && checkVendorCommodityCode(commodityCode);
        if (!found) {
            GlobalVariables.getMessageMap().putError(VendorPropertyConstants.PURCHASING_COMMODITY_CODE, KFSKeyConstants.ERROR_EXISTENCE, purchasingCommodityCode);
        }
        success &= found;
    }
    return success;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorContract(org.kuali.kfs.vnd.businessobject.VendorContract) VendorCustomerNumber(org.kuali.kfs.vnd.businessobject.VendorCustomerNumber) VendorContractOrganization(org.kuali.kfs.vnd.businessobject.VendorContractOrganization) VendorDefaultAddress(org.kuali.kfs.vnd.businessobject.VendorDefaultAddress) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress) VendorCommodityCode(org.kuali.kfs.vnd.businessobject.VendorCommodityCode)

Example 3 with VendorContractOrganization

use of org.kuali.kfs.vnd.businessobject.VendorContractOrganization in project cu-kfs by CU-CommunityApps.

the class VendorRule method validateVendorContractPOLimitAndExcludeFlagCombination.

/**
 * Validates that the proper combination of Exclude Indicator and APO Amount is present on a vendor contract. Do
 * not perform this validation on Contract add line as the user cannot currently enter the sub-collection of
 * contract-orgs so we should not force this until the document is submitted. The rules are : 1. Must enter a
 * Default APO Limit or at least one organization with an APO Amount. 2. If the Exclude Indicator for an
 * organization is N, an organization APO Amount is required. 3. If the Exclude Indicator for an organization is
 * Y, the organization APO Amount is not allowed.
 *
 * @param contract VendorContract
 * @return boolean true if the proper combination of Exclude Indicator and APO Amount is present, otherwise false.
 */
protected boolean validateVendorContractPOLimitAndExcludeFlagCombination(VendorContract contract) {
    boolean valid = true;
    boolean NoOrgHasApoLimit = true;
    List<VendorContractOrganization> organizations = contract.getVendorContractOrganizations();
    if (ObjectUtils.isNotNull(organizations)) {
        int organizationCounter = 0;
        for (VendorContractOrganization organization : organizations) {
            if (ObjectUtils.isNotNull(organization.getVendorContractPurchaseOrderLimitAmount())) {
                NoOrgHasApoLimit = false;
            }
            valid = validateVendorContractOrganization(organization, organizationCounter);
            organizationCounter++;
        }
    }
    if (NoOrgHasApoLimit && ObjectUtils.isNull(contract.getOrganizationAutomaticPurchaseOrderLimit())) {
        // Rule #1 in the above java doc has been violated.
        GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_CONTRACT_DEFAULT_APO_LIMIT, VendorKeyConstants.ERROR_VENDOR_CONTRACT_NO_APO_LIMIT);
        valid = false;
    }
    return valid;
}
Also used : VendorContractOrganization(org.kuali.kfs.vnd.businessobject.VendorContractOrganization)

Example 4 with VendorContractOrganization

use of org.kuali.kfs.vnd.businessobject.VendorContractOrganization in project cu-kfs by CU-CommunityApps.

the class VendorRule method validateVendorContractOrganization.

/**
 * Validates a vendor contract organization. The rules are : 1. If the Exclude Indicator for the organization is N,
 * an organization APO Amount is required. 2. If the Exclude Indicator for the organization is Y, an organization
 * APO Amount is not allowed. 3. The chart and org for the organization must exist in the database.
 *
 * @param organization VendorContractOrganization
 * @return boolean true if these three rules are passed, otherwise false.
 */
protected boolean validateVendorContractOrganization(VendorContractOrganization organization, int counter) {
    boolean valid = true;
    List<String> previousErrorPaths = GlobalVariables.getMessageMap().getErrorPath();
    String errorPath = VendorPropertyConstants.VENDOR_CONTRACT_ORGANIZATION + "[" + counter + "]";
    boolean shouldAddToErrorPath = true;
    // path anymore.
    for (String previous : previousErrorPaths) {
        if (previous.startsWith(KRADConstants.ADD_PREFIX)) {
            shouldAddToErrorPath = false;
            break;
        }
    }
    if (shouldAddToErrorPath) {
        GlobalVariables.getMessageMap().addToErrorPath(errorPath);
    }
    boolean isExcluded = organization.isVendorContractExcludeIndicator();
    if (isExcluded) {
        if (ObjectUtils.isNotNull(organization.getVendorContractPurchaseOrderLimitAmount())) {
            // Rule #2 in the above java doc has been violated.
            GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_CONTRACT_ORGANIZATION_APO_LIMIT, VendorKeyConstants.ERROR_VENDOR_CONTRACT_ORG_EXCLUDED_WITH_APO_LIMIT);
            valid = false;
        }
    } else {
        // isExcluded = false
        if (ObjectUtils.isNull(organization.getVendorContractPurchaseOrderLimitAmount())) {
            // Rule #1 in the above java doc has been violated.
            GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_CONTRACT_ORGANIZATION_APO_LIMIT, VendorKeyConstants.ERROR_VENDOR_CONTRACT_ORG_NOT_EXCLUDED_NO_APO_LIMIT);
            valid = false;
        }
    }
    // The chart and org must exist in the database.
    String chartOfAccountsCode = organization.getChartOfAccountsCode();
    String orgCode = organization.getOrganizationCode();
    if (StringUtils.isNotBlank(chartOfAccountsCode) && StringUtils.isNotBlank(orgCode)) {
        Map<String, String> chartOrgMap = new HashMap<>();
        chartOrgMap.put("chartOfAccountsCode", chartOfAccountsCode);
        if (getBusinessObjectService().countMatching(Chart.class, chartOrgMap) < 1) {
            GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_CONTRACT_CHART_OF_ACCOUNTS_CODE, KFSKeyConstants.ERROR_EXISTENCE, chartOfAccountsCode);
            valid = false;
        }
        chartOrgMap.put("organizationCode", orgCode);
        if (getBusinessObjectService().countMatching(Organization.class, chartOrgMap) < 1) {
            GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_CONTRACT_ORGANIZATION_CODE, KFSKeyConstants.ERROR_EXISTENCE, orgCode);
            valid = false;
        }
    }
    if (shouldAddToErrorPath && organization.getVendorContractPurchaseOrderLimitAmount() != null) {
        BusinessObjectEntry entry = boDictionaryService.getBusinessObjectEntry(VendorContractOrganization.class.getName());
        AttributeDefinition attributeDefinition = entry.getAttributeDefinition(VendorPropertyConstants.VENDOR_CONTRACT_ORGANIZATION_APO_LIMIT);
        valid &= validateAPOAmount(organization.getVendorContractPurchaseOrderLimitAmount(), attributeDefinition);
    }
    if (shouldAddToErrorPath) {
        GlobalVariables.getMessageMap().removeFromErrorPath(errorPath);
    }
    return valid;
}
Also used : Organization(org.kuali.kfs.coa.businessobject.Organization) VendorContractOrganization(org.kuali.kfs.vnd.businessobject.VendorContractOrganization) HashMap(java.util.HashMap) BusinessObjectEntry(org.kuali.kfs.kns.datadictionary.BusinessObjectEntry) VendorContractOrganization(org.kuali.kfs.vnd.businessobject.VendorContractOrganization) AttributeDefinition(org.kuali.kfs.krad.datadictionary.AttributeDefinition) Chart(org.kuali.kfs.coa.businessobject.Chart)

Aggregations

VendorContractOrganization (org.kuali.kfs.vnd.businessobject.VendorContractOrganization)4 VendorContract (org.kuali.kfs.vnd.businessobject.VendorContract)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Chart (org.kuali.kfs.coa.businessobject.Chart)1 Organization (org.kuali.kfs.coa.businessobject.Organization)1 BusinessObjectEntry (org.kuali.kfs.kns.datadictionary.BusinessObjectEntry)1 AttributeDefinition (org.kuali.kfs.krad.datadictionary.AttributeDefinition)1 VendorAddress (org.kuali.kfs.vnd.businessobject.VendorAddress)1 VendorCommodityCode (org.kuali.kfs.vnd.businessobject.VendorCommodityCode)1 VendorCustomerNumber (org.kuali.kfs.vnd.businessobject.VendorCustomerNumber)1 VendorDefaultAddress (org.kuali.kfs.vnd.businessobject.VendorDefaultAddress)1 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)1