Search in sources :

Example 6 with VendorCommodityCode

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

the class CuVendorRule method processAddCollectionLineBusinessRules.

public boolean processAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject bo) {
    boolean success = super.processAddCollectionLineBusinessRules(document, collectionName, bo);
    if (collectionName.equals(VendorConstants.VENDOR_HEADER_ATTR + "." + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES)) {
        VendorDetail vendorDetail = (VendorDetail) document.getDocumentBusinessObject();
        VendorHeader vendorHeader = vendorDetail.getVendorHeader();
        List<VendorSupplierDiversity> vendorSupplierDiversities = vendorHeader.getVendorSupplierDiversities();
        if (vendorSupplierDiversities.size() > 0) {
            int i = 0;
            for (VendorSupplierDiversity vendor : vendorSupplierDiversities) {
                if (((CuVendorSupplierDiversityExtension) vendor.getExtension()).getVendorSupplierDiversityExpirationDate() == null) {
                    success = false;
                    putFieldError(VendorConstants.VENDOR_HEADER_ATTR + "." + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES + "[" + i + "]." + CUVendorPropertyConstants.SUPPLIER_DIVERSITY_EXPRIATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_SUPPLIER_DIVERSITY_DATE_BLANK);
                } else if (((CuVendorSupplierDiversityExtension) vendor.getExtension()).getVendorSupplierDiversityExpirationDate().before(new Date())) {
                    // Only check expiration date on new vendors
                    if (document.isNew()) {
                        success = false;
                        putFieldError(VendorConstants.VENDOR_HEADER_ATTR + "." + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES + "[" + i + "]." + CUVendorPropertyConstants.SUPPLIER_DIVERSITY_EXPRIATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_SUPPLIER_DIVERSITY_DATE_IN_PAST);
                    }
                }
                i++;
            }
        }
        if (!success) {
            return success;
        }
    }
    if (collectionName.equals("vendorCommodities")) {
        VendorCommodityCode codeToBeValidated = (VendorCommodityCode) bo;
        CommodityCode persistedCommodity = commodityCodeService.getByPrimaryId(codeToBeValidated.getPurchasingCommodityCode());
        if (persistedCommodity == null) {
            // a commodity code entered by a user does not exist
            putFieldError("add.vendorCommodities.purchasingCommodityCode", CUVendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_DOES_NOT_EXIST, codeToBeValidated.getPurchasingCommodityCode());
            success = false;
        }
        if (codeToBeValidated.isCommodityDefaultIndicator()) {
            VendorDetail vendorDetail = (VendorDetail) document.getDocumentBusinessObject();
            List<VendorCommodityCode> vendorCommodities = vendorDetail.getVendorCommodities();
            Iterator<VendorCommodityCode> commodities = vendorCommodities.iterator();
            int indice = 0;
            while (commodities.hasNext()) {
                VendorCommodityCode commodity = (VendorCommodityCode) commodities.next();
                if (commodity.isCommodityDefaultIndicator()) {
                    // more than one "default" commodity code has been specified
                    putFieldError("add.vendorCommodities.commodityDefaultIndicator", CUVendorKeyConstants.ERROR_DEFAULT_VENDOR_COMMODITY_CODE_ALREADY_EXISTS, Integer.toString(indice));
                    success = false;
                }
                indice++;
            }
        }
        VendorDetail vendorDetail = (VendorDetail) document.getDocumentBusinessObject();
        boolean commodityAlreadyAssignedToThisVendor = false;
        Iterator<VendorCommodityCode> codes = vendorDetail.getVendorCommodities().iterator();
        while (codes.hasNext()) {
            VendorCommodityCode vcc = codes.next();
            if (vcc.getPurchasingCommodityCode().equals(codeToBeValidated.getPurchasingCommodityCode())) {
                commodityAlreadyAssignedToThisVendor = true;
                break;
            }
        }
        if (commodityAlreadyAssignedToThisVendor) {
            putFieldError("add.vendorCommodities.purchasingCommodityCode", CUVendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_ALREADY_ASSIGNED_TO_VENDOR);
            success = false;
        }
        return success;
    }
    return success;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorHeader(org.kuali.kfs.vnd.businessobject.VendorHeader) VendorCommodityCode(org.kuali.kfs.vnd.businessobject.VendorCommodityCode) CommodityCode(org.kuali.kfs.vnd.businessobject.CommodityCode) CuVendorSupplierDiversityExtension(edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension) VendorSupplierDiversity(org.kuali.kfs.vnd.businessobject.VendorSupplierDiversity) Date(java.util.Date) VendorCommodityCode(org.kuali.kfs.vnd.businessobject.VendorCommodityCode)

Example 7 with VendorCommodityCode

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

the class CuRequisitionServiceImpl method checkAPORulesPerItemForCommodityCodes.

/**
 * Checks the APO rules for Commodity Codes.
 * The rules are as follow:
 * 1. If an institution does not require a commodity code on a requisition but does require a commodity code on a
 * purchase order:
 * a. If the requisition qualifies for an APO and the commodity code is blank on any line item then the system
 * should use the default commodity code for the vendor.
 * b. If there is not a default commodity code for the vendor then the requisition is not eligible to become an
 * APO.
 * 2. The commodity codes where the restricted indicator is Y should disallow the requisition from becoming an
 * APO.
 *
 * KFSPTS-1319 Removed this validation check
 * 3. If the commodity code is Inactive when the requisition is finally approved do not allow the requisition to
 * become an APO.
 *
 * @param purItem
 * @param vendorCommodityCodes
 * @param commodityCodeRequired
 * @return
 */
protected String checkAPORulesPerItemForCommodityCodes(RequisitionItem purItem, List<VendorCommodityCode> vendorCommodityCodes, boolean commodityCodeRequired) {
    // use the default commodity code for the vendor
    if (purItem.getCommodityCode() == null && commodityCodeRequired) {
        for (VendorCommodityCode vcc : vendorCommodityCodes) {
            if (vcc.isCommodityDefaultIndicator()) {
                purItem.setCommodityCode(vcc.getCommodityCode());
                purItem.setPurchasingCommodityCode(vcc.getPurchasingCommodityCode());
            }
        }
    }
    if (purItem.getCommodityCode() == null) {
        // an APO.
        if (commodityCodeRequired) {
            return "There are missing commodity code(s).";
        }
    // KFSPTS-1319: Removed inactive commodity code validation check
    // } else if (!purItem.getCommodityCode().isActive()) {
    // return "Requisition contains inactive commodity codes.";
    } else if (purItem.getCommodityCode().isRestrictedItemsIndicator()) {
        return "Requisition contains an item with a restricted commodity code.";
    }
    return "";
}
Also used : VendorCommodityCode(org.kuali.kfs.vnd.businessobject.VendorCommodityCode)

Aggregations

VendorCommodityCode (org.kuali.kfs.vnd.businessobject.VendorCommodityCode)7 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)5 VendorContract (org.kuali.kfs.vnd.businessobject.VendorContract)3 RequisitionItem (org.kuali.kfs.module.purap.businessobject.RequisitionItem)2 CommodityCode (org.kuali.kfs.vnd.businessobject.CommodityCode)2 CuRequisitionDocument (edu.cornell.kfs.module.purap.document.CuRequisitionDocument)1 CuPurapService (edu.cornell.kfs.module.purap.document.service.CuPurapService)1 CuVendorSupplierDiversityExtension (edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension)1 Date (java.util.Date)1 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)1 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)1 Person (org.kuali.kfs.kim.api.identity.Person)1 KualiRuleService (org.kuali.kfs.krad.service.KualiRuleService)1 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)1 PurchasingDocument (org.kuali.kfs.module.purap.document.PurchasingDocument)1 PurchasingDocumentBase (org.kuali.kfs.module.purap.document.PurchasingDocumentBase)1 AttributedAddPurchasingAccountsPayableItemEvent (org.kuali.kfs.module.purap.document.validation.event.AttributedAddPurchasingAccountsPayableItemEvent)1 PurchasingFormBase (org.kuali.kfs.module.purap.document.web.struts.PurchasingFormBase)1 RequisitionForm (org.kuali.kfs.module.purap.document.web.struts.RequisitionForm)1 VendorAddress (org.kuali.kfs.vnd.businessobject.VendorAddress)1