Search in sources :

Example 36 with VendorDetail

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

the class VendorInactivateConvertBatchServiceImpl method inactivateConvert.

/**
 */
public boolean inactivateConvert(String fileName, BatchInputFileType batchInputFileType) {
    boolean result = true;
    // load up the file into a byte array
    byte[] fileByteContent = safelyLoadFileBytes(fileName);
    LOG.info("Attempting to parse the file");
    Object parsedObject = null;
    try {
        parsedObject = batchInputFileService.parse(batchInputFileType, fileByteContent);
    } catch (ParseException e) {
        String errorMessage = "Error parsing batch file: " + e.getMessage();
        LOG.error(errorMessage, e);
        throw new RuntimeException(errorMessage);
    }
    // make sure we got the type we expected, then cast it
    if (!(parsedObject instanceof List)) {
        String errorMessage = "Parsed file was not of the expected type.  Expected [" + List.class + "] but got [" + parsedObject.getClass() + "].";
        criticalError(errorMessage);
    }
    List<VendorInactivateConvertBatch> vendors = ((List<VendorInactivateConvertBatch>) parsedObject);
    for (VendorInactivateConvertBatch vendor : vendors) {
        String[] vendorId = vendor.getVendorId().split("-");
        Collection<VendorDetail> vendorDets = businessObjectService.findMatching(VendorDetail.class, Collections.singletonMap("vendorHeaderGeneratedIdentifier", vendorId[0]));
        GlobalVariables.setUserSession(new UserSession("kfs"));
        VendorDetail vnd = cuVendorService.getByVendorNumber(vendor.getVendorId());
        if (ObjectUtils.isNull(vnd)) {
            LOG.info("Vendor with id: " + vendor.getVendorId() + " does not exist in the database.");
        }
        if ((ObjectUtils.isNotNull(vnd))) {
            VendorHeader vHead = businessObjectService.findBySinglePrimaryKey(VendorHeader.class, vnd.getVendorHeaderGeneratedIdentifier());
            if (vendor.getAction().equalsIgnoreCase("inactivate") && ((vendorDets.size() == 1) || !(vendorId[1].equalsIgnoreCase("0")))) {
                inactivateVendor(vnd, vendor.getNote(), vendor.getReason());
            } else if (vendor.getAction().equalsIgnoreCase("activate") && ((vendorDets.size() == 1) || !(vendorId[1].equalsIgnoreCase("0")))) {
                activateVendor(vnd, vendor.getNote(), vendor.getReason());
            } else if (vendor.getAction().equalsIgnoreCase("convert") && ((vendorDets.size() == 1) || !(vendorId[1].equalsIgnoreCase("0")))) {
                convertVendor(vHead, vnd, vendor.getNote(), vendor.getConvertType());
            } else if (vendorDets.size() > 1) {
                LOG.info("failed to process for " + vnd.getVendorNumber() + ", This vendor has child records. These must be processed through the application");
            } else {
                String errorMessage = "Failed to parse vendor action expected inactivate or convert but recevied " + vendor.getAction();
                criticalError(errorMessage);
            }
        }
    }
    return result;
}
Also used : VendorHeader(org.kuali.kfs.vnd.businessobject.VendorHeader) VendorInactivateConvertBatch(edu.cornell.kfs.vnd.businessobject.VendorInactivateConvertBatch) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) UserSession(org.kuali.kfs.krad.UserSession) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(org.kuali.kfs.sys.exception.ParseException)

Example 37 with VendorDetail

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

the class CuVendorRule method checkAutoLiabilityAmountAndExpiration.

protected boolean checkAutoLiabilityAmountAndExpiration(MaintenanceDocument document) {
    boolean success = true;
    VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getBusinessObject();
    VendorDetailExtension vendorDetailExt = ((VendorDetailExtension) vendorDetail.getExtension());
    if (vendorDetailExt.getAutomobileLiabilityCoverageAmount() != null && vendorDetailExt.getAutomobileLiabilityExpiration() == null) {
        success = false;
        putFieldError(CUVendorPropertyConstants.AUTOMOBILE_LIABILITY_EXPIRATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_AUTO_EXPR_NEEDED);
    }
    if (vendorDetailExt.getAutomobileLiabilityCoverageAmount() == null && vendorDetailExt.getAutomobileLiabilityExpiration() != null) {
        success = false;
        putFieldError(CUVendorPropertyConstants.AUTOMOBILE_LIABILITY_AMOUNT, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_AUTO_COVERAGE_NEEDED);
    }
    if (vendorDetailExt.getAutomobileLiabilityExpiration() != null && vendorDetailExt.getAutomobileLiabilityExpiration().before(new Date())) {
        // Only check expiration date on new vendors
        if (document.isNew()) {
            success = false;
            putFieldError(CUVendorPropertyConstants.AUTOMOBILE_LIABILITY_EXPIRATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_DATE_IN_PAST);
        }
    }
    return success;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorDetailExtension(edu.cornell.kfs.vnd.businessobject.VendorDetailExtension) Date(java.util.Date)

Example 38 with VendorDetail

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

the class CuVendorRule method checkInsuranceRequired.

protected boolean checkInsuranceRequired(MaintenanceDocument document) {
    boolean success = true;
    boolean dataEntered = false;
    VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getBusinessObject();
    VendorDetailExtension vendorDetailExt = ((VendorDetailExtension) vendorDetail.getExtension());
    if (vendorDetailExt.isInsuranceRequiredIndicator()) {
        dataEntered |= (vendorDetailExt.getAutomobileLiabilityCoverageAmount() == null ? false : true);
        dataEntered |= (vendorDetailExt.getAutomobileLiabilityExpiration() == null ? false : true);
        dataEntered |= (vendorDetailExt.getCornellAdditionalInsuredIndicator() == null ? false : true);
        dataEntered |= (vendorDetailExt.getExcessLiabilityUmbExpiration() == null ? false : true);
        dataEntered |= (vendorDetailExt.getExcessLiabilityUmbrellaAmount() == null ? false : true);
        dataEntered |= (vendorDetailExt.getGeneralLiabilityCoverageAmount() == null ? false : true);
        dataEntered |= (vendorDetailExt.getGeneralLiabilityExpiration() == null ? false : true);
        dataEntered |= (vendorDetailExt.getWorkmansCompCoverageAmount() == null ? false : true);
        dataEntered |= (vendorDetailExt.getWorkmansCompExpiration() == null ? false : true);
        dataEntered |= (vendorDetailExt.getHealthOffSiteCateringLicenseReq() == null ? false : true);
        dataEntered |= (vendorDetailExt.getHealthOffSiteLicenseExpirationDate() == null ? false : true);
        dataEntered |= (vendorDetailExt.getInsuranceNotes() == null ? false : true);
        if (!dataEntered) {
            putFieldError(CUVendorPropertyConstants.INSURANCE_REQUIRED, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_INSURANCE_REQUIRED_USED_WO_DATA);
            return false;
        }
    }
    return success;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorDetailExtension(edu.cornell.kfs.vnd.businessobject.VendorDetailExtension)

Example 39 with VendorDetail

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

the class CuVendorRule method checkMerchantNameUniqueness.

protected boolean checkMerchantNameUniqueness(MaintenanceDocument document) {
    boolean success = true;
    VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getBusinessObject();
    List<CuVendorCreditCardMerchant> vendorCreditCardMerchants = ((VendorDetailExtension) vendorDetail.getExtension()).getVendorCreditCardMerchants();
    ArrayList<String> merchantNames = new ArrayList<String>();
    int i = 0;
    for (CuVendorCreditCardMerchant vendorCreditCardMerchant : vendorCreditCardMerchants) {
        if (merchantNames.contains(vendorCreditCardMerchant.getCreditMerchantName())) {
            putFieldError("vendorCreditCardMerchants[" + i + "].creditMerchantName", CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_CREDIT_MERCHANT_NAME_DUPLICATE);
            // can't have duplicate merchant names, part of the primary key for the table in the db
            success = false;
        }
        if (vendorCreditCardMerchant.getCreditMerchantName() == null || vendorCreditCardMerchant.getCreditMerchantName().equals("")) {
            // can't have a null or blank name, it's part of the primary key for this table in the db
            putFieldError("vendorCreditCardMerchants[" + i + "].creditMerchantName", CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_CREDIT_MERCHANT_NAME_BLANK);
            success = false;
        }
        merchantNames.add(vendorCreditCardMerchant.getCreditMerchantName());
        i++;
    }
    return success;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) CuVendorCreditCardMerchant(edu.cornell.kfs.vnd.businessobject.CuVendorCreditCardMerchant) ArrayList(java.util.ArrayList) VendorDetailExtension(edu.cornell.kfs.vnd.businessobject.VendorDetailExtension)

Example 40 with VendorDetail

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

the class CuVendorRule method checkGeneralLiabilityAmountAndExpiration.

protected boolean checkGeneralLiabilityAmountAndExpiration(MaintenanceDocument document) {
    boolean success = true;
    VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getBusinessObject();
    VendorDetailExtension vendorDetailExt = ((VendorDetailExtension) vendorDetail.getExtension());
    if (vendorDetailExt.getGeneralLiabilityCoverageAmount() != null && vendorDetailExt.getGeneralLiabilityExpiration() == null) {
        success = false;
        putFieldError(CUVendorPropertyConstants.GENERAL_LIABILITY_EXPIRATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_GENERAL_LIABILITY_EXPR_DATE_NEEDED);
    }
    if (vendorDetailExt.getGeneralLiabilityCoverageAmount() == null && vendorDetailExt.getGeneralLiabilityExpiration() != null) {
        success = false;
        putFieldError(CUVendorPropertyConstants.GENERAL_LIABILITY_AMOUNT, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_GENERAL_LIABILITY_COVERAGE_NEEDED);
    }
    if (vendorDetailExt.getGeneralLiabilityExpiration() != null && vendorDetailExt.getGeneralLiabilityExpiration().before(new Date())) {
        // Only check expiration date on new vendors
        if (document.isNew()) {
            success = false;
            putFieldError(CUVendorPropertyConstants.GENERAL_LIABILITY_EXPIRATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_DATE_IN_PAST);
        }
    }
    return success;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorDetailExtension(edu.cornell.kfs.vnd.businessobject.VendorDetailExtension) Date(java.util.Date)

Aggregations

VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)54 ArrayList (java.util.ArrayList)14 VendorAddress (org.kuali.kfs.vnd.businessobject.VendorAddress)12 Date (java.util.Date)10 List (java.util.List)10 VendorDetailExtension (edu.cornell.kfs.vnd.businessobject.VendorDetailExtension)9 HashMap (java.util.HashMap)9 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)7 VendorHeader (org.kuali.kfs.vnd.businessobject.VendorHeader)7 VendorService (org.kuali.kfs.vnd.document.service.VendorService)7 Iterator (java.util.Iterator)6 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)5 MessageMap (org.kuali.kfs.krad.util.MessageMap)5 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)5 Person (org.kuali.rice.kim.api.identity.Person)5 IOException (java.io.IOException)4 VendorCommodityCode (org.kuali.kfs.vnd.businessobject.VendorCommodityCode)4 VendorContract (org.kuali.kfs.vnd.businessobject.VendorContract)4 VendorSupplierDiversity (org.kuali.kfs.vnd.businessobject.VendorSupplierDiversity)4 FileNotFoundException (java.io.FileNotFoundException)3