Search in sources :

Example 6 with VendorAddress

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

the class PurchasingActionBase method refresh.

@Override
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PurchasingAccountsPayableFormBase baseForm = (PurchasingAccountsPayableFormBase) form;
    PurchasingDocument document = (PurchasingDocument) baseForm.getDocument();
    String refreshCaller = baseForm.getRefreshCaller();
    BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
    PhoneNumberService phoneNumberService = SpringContext.getBean(PhoneNumberService.class);
    // Format phone numbers
    document.setInstitutionContactPhoneNumber(phoneNumberService.formatNumberIfPossible(document.getInstitutionContactPhoneNumber()));
    document.setRequestorPersonPhoneNumber(phoneNumberService.formatNumberIfPossible(document.getRequestorPersonPhoneNumber()));
    document.setDeliveryToPhoneNumber(phoneNumberService.formatNumberIfPossible(document.getDeliveryToPhoneNumber()));
    // max lengths
    if (StringUtils.equals(refreshCaller, "kimPersonLookupable")) {
        Integer deliveryToNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(document.getClass(), PurapPropertyConstants.DELIVERY_TO_NAME);
        // KFSPTS-518/KFSUPGRADE-351
        if (deliveryToNameMaxLength == null && document instanceof PurchaseOrderAmendmentDocument) {
            deliveryToNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(PurchaseOrderDocument.class, PurapPropertyConstants.DELIVERY_TO_NAME);
        }
        if (StringUtils.isNotEmpty(document.getDeliveryToName()) && ObjectUtils.isNotNull(deliveryToNameMaxLength) && document.getDeliveryToName().length() > deliveryToNameMaxLength) {
            document.setDeliveryToName(document.getDeliveryToName().substring(0, deliveryToNameMaxLength));
            GlobalVariables.getMessageMap().clearErrorPath();
            GlobalVariables.getMessageMap().addToErrorPath(PurapConstants.DELIVERY_TAB_ERRORS);
            GlobalVariables.getMessageMap().putWarning(PurapPropertyConstants.DELIVERY_TO_NAME, PurapKeyConstants.WARNING_DELIVERY_TO_NAME_TRUNCATED);
            GlobalVariables.getMessageMap().removeFromErrorPath(PurapConstants.DELIVERY_TAB_ERRORS);
        }
        Integer requestorNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(document.getClass(), PurapPropertyConstants.REQUESTOR_PERSON_NAME);
        // KFSPTS-518/KFSUPGRADE-351
        if (requestorNameMaxLength == null && document instanceof PurchaseOrderAmendmentDocument) {
            requestorNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(PurchaseOrderDocument.class, PurapPropertyConstants.REQUESTOR_PERSON_NAME);
        }
        if (StringUtils.isNotEmpty(document.getRequestorPersonName()) && ObjectUtils.isNotNull(requestorNameMaxLength) && document.getRequestorPersonName().length() > requestorNameMaxLength) {
            document.setRequestorPersonName(document.getRequestorPersonName().substring(0, requestorNameMaxLength));
            GlobalVariables.getMessageMap().clearErrorPath();
            GlobalVariables.getMessageMap().addToErrorPath(PurapConstants.ADDITIONAL_TAB_ERRORS);
            GlobalVariables.getMessageMap().putWarning(PurapPropertyConstants.REQUESTOR_PERSON_NAME, PurapKeyConstants.WARNING_REQUESTOR_NAME_TRUNCATED);
            GlobalVariables.getMessageMap().removeFromErrorPath(PurapConstants.ADDITIONAL_TAB_ERRORS);
        }
    }
    // Refreshing the fields after returning from a vendor lookup in the vendor tab
    if (StringUtils.equals(refreshCaller, VendorConstants.VENDOR_LOOKUPABLE_IMPL) && document.getVendorDetailAssignedIdentifier() != null && document.getVendorHeaderGeneratedIdentifier() != null) {
        document.setVendorContractGeneratedIdentifier(null);
        document.refreshReferenceObject("vendorContract");
        // retrieve vendor based on selection from vendor lookup
        document.refreshReferenceObject("vendorDetail");
        document.templateVendorDetail(document.getVendorDetail());
        // KFSPTS-1612 : populate vendor contract name
        if (CollectionUtils.isNotEmpty(document.getVendorDetail().getVendorContracts())) {
            for (VendorContract vendorContract : document.getVendorDetail().getVendorContracts()) {
                if (vendorContract.isActive()) {
                    document.setVendorContractGeneratedIdentifier(vendorContract.getVendorContractGeneratedIdentifier());
                    document.refreshReferenceObject("vendorContract");
                }
            }
        }
        // populate default address based on selected vendor
        VendorAddress defaultAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(document.getVendorDetail().getVendorAddresses(), document.getVendorDetail().getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode(), document.getDeliveryCampusCode());
        if (defaultAddress == null) {
            GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_DOC_ADDRESS, PurapKeyConstants.ERROR_INACTIVE_VENDORADDRESS);
        }
        document.templateVendorAddress(defaultAddress);
        // CU enhancement KFSUPGRDE-348
        document.setPurchaseOrderTransmissionMethodCode(((CuVendorAddressExtension) defaultAddress.getExtension()).getPurchaseOrderTransmissionMethodCode());
    }
    // Refreshing the fields after returning from a contract lookup in the vendor tab
    if (StringUtils.equals(refreshCaller, VendorConstants.VENDOR_CONTRACT_LOOKUPABLE_IMPL)) {
        if (StringUtils.isNotEmpty(request.getParameter(KFSPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.VENDOR_CONTRACT_ID))) {
            // retrieve Contract based on selection from contract lookup
            VendorContract refreshVendorContract = new VendorContract();
            refreshVendorContract.setVendorContractGeneratedIdentifier(document.getVendorContractGeneratedIdentifier());
            refreshVendorContract = (VendorContract) businessObjectService.retrieve(refreshVendorContract);
            // retrieve Vendor based on selected contract
            document.setVendorHeaderGeneratedIdentifier(refreshVendorContract.getVendorHeaderGeneratedIdentifier());
            document.setVendorDetailAssignedIdentifier(refreshVendorContract.getVendorDetailAssignedIdentifier());
            document.refreshReferenceObject("vendorDetail");
            document.templateVendorDetail(document.getVendorDetail());
            // always template contract after vendor to keep contract defaults last
            document.templateVendorContract(refreshVendorContract);
            // populate default address from selected vendor
            VendorAddress defaultAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(document.getVendorDetail().getVendorAddresses(), document.getVendorDetail().getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode(), "");
            if (defaultAddress == null) {
                GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_DOC_ADDRESS, PurapKeyConstants.ERROR_INACTIVE_VENDORADDRESS);
            }
            document.templateVendorAddress(defaultAddress);
            // update internal dollar limit for PO since the contract might affect this value
            if (document instanceof PurchaseOrderDocument) {
                PurchaseOrderDocument poDoc = (PurchaseOrderDocument) document;
                KualiDecimal limit = SpringContext.getBean(PurchaseOrderService.class).getInternalPurchasingDollarLimit(poDoc);
                poDoc.setInternalPurchasingLimit(limit);
            }
        }
    }
    // Refreshing the fields after returning from an address lookup in the vendor tab
    if (StringUtils.equals(refreshCaller, VendorConstants.VENDOR_ADDRESS_LOOKUPABLE_IMPL)) {
        if (StringUtils.isNotEmpty(request.getParameter(KFSPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.VENDOR_ADDRESS_ID))) {
            // retrieve address based on selection from address lookup
            VendorAddress refreshVendorAddress = new VendorAddress();
            refreshVendorAddress.setVendorAddressGeneratedIdentifier(document.getVendorAddressGeneratedIdentifier());
            refreshVendorAddress = (VendorAddress) businessObjectService.retrieve(refreshVendorAddress);
            document.templateVendorAddress(refreshVendorAddress);
        }
    }
    // Refreshing corresponding fields after returning from various kuali lookups
    if (StringUtils.equals(refreshCaller, KFSConstants.KUALI_LOOKUPABLE_IMPL)) {
        if (request.getParameter("document.deliveryCampusCode") != null) {
            // returning from a building or campus lookup on the delivery tab (update billing address)
            BillingAddress billingAddress = new BillingAddress();
            billingAddress.setBillingCampusCode(document.getDeliveryCampusCode());
            Map keys = SpringContext.getBean(PersistenceService.class).getPrimaryKeyFieldValues(billingAddress);
            billingAddress = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(BillingAddress.class, keys);
            document.templateBillingAddress(billingAddress);
            if (request.getParameter("document.deliveryBuildingName") == null) {
                // came from campus lookup not building, so clear building
                clearDeliveryBuildingInfo(document, true);
            } else {
                // came from building lookup then turn off "OTHER" and clear room and line2address
                document.setDeliveryBuildingOtherIndicator(false);
                document.setDeliveryBuildingRoomNumber("");
                document.setDeliveryBuildingLine2Address("");
            }
        } else if (request.getParameter("document.chartOfAccountsCode") != null) {
            // returning from a chart/org lookup on the document detail tab (update receiving address)
            document.loadReceivingAddress();
        } else {
            // returning from a building lookup in a capital asset tab location (update location address)
            String buildingCodeParam = findBuildingCodeFromCapitalAssetBuildingLookup(request);
            if (StringUtils.isNotEmpty(buildingCodeParam)) {
                PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
                updateCapitalAssetLocation(request, purchasingForm, document, buildingCodeParam);
            }
        }
    }
    return super.refresh(mapping, form, request, response);
}
Also used : PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) PhoneNumberService(org.kuali.kfs.vnd.service.PhoneNumberService) VendorContract(org.kuali.kfs.vnd.businessobject.VendorContract) PurchaseOrderService(org.kuali.kfs.module.purap.document.service.PurchaseOrderService) PurchasingDocument(org.kuali.kfs.module.purap.document.PurchasingDocument) DataDictionaryService(org.kuali.kfs.datadictionary.legacy.DataDictionaryService) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) VendorService(org.kuali.kfs.vnd.document.service.VendorService) BillingAddress(org.kuali.kfs.module.purap.businessobject.BillingAddress) PersistenceService(org.kuali.kfs.krad.service.PersistenceService) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress) Map(java.util.Map) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 7 with VendorAddress

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

the class CuDisbursementVoucherDocumentGenerator method populateAddressFields.

private void populateAddressFields(DisbursementVoucherPaymentInformationXml paymentInfo, CuDisbursementVoucherDocument dvDocument) {
    if (StringUtils.isNotBlank(paymentInfo.getPayeeAddressId())) {
        VendorAddress vendorAddress = findVendorAddress(paymentInfo);
        dvDocument.templateVendor(vendorAddress.getVendorDetail(), vendorAddress);
    } else {
        CuDisbursementVoucherPayeeDetail payeeDetail = dvDocument.getDvPayeeDetail();
        LOG.info("populateAddressFields, no payee address ID provided, so using the address fields from the XML");
        payeeDetail.setDisbVchrPayeeLine1Addr(paymentInfo.getAddressLine1());
        payeeDetail.setDisbVchrPayeeLine2Addr(paymentInfo.getAddressLine2());
        payeeDetail.setDisbVchrPayeeCityName(paymentInfo.getCity());
        payeeDetail.setDisbVchrPayeeStateCode(paymentInfo.getState());
        payeeDetail.setDisbVchrPayeeCountryCode(paymentInfo.getCountry());
        payeeDetail.setDisbVchrPayeeZipCode(paymentInfo.getPostalCode());
    }
}
Also used : CuDisbursementVoucherPayeeDetail(edu.cornell.kfs.fp.businessobject.CuDisbursementVoucherPayeeDetail) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress)

Example 8 with VendorAddress

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

the class CuDisbursementVoucherDocumentGenerator method findVendorAddress.

private VendorAddress findVendorAddress(DisbursementVoucherPaymentInformationXml paymentInfo) {
    Collection<VendorAddress> vendorAddresses;
    try {
        String[] payeeArray = StringUtils.split(paymentInfo.getPayeeId(), KFSConstants.DASH);
        if (LOG.isInfoEnabled()) {
            LOG.info("findVendorAddress, vendorHeaderGeneratedIdentifier: " + payeeArray[0] + " vendorDetailAssignedIdentifier: " + payeeArray[1] + ", payee address id: " + paymentInfo.getPayeeAddressId());
        }
        Map<String, String> fieldValues = new HashMap<String, String>();
        fieldValues.put(KFSPropertyConstants.VENDOR_HEADER_GENERATED_ID, payeeArray[0]);
        fieldValues.put(KFSPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID, payeeArray[1]);
        fieldValues.put(KFSPropertyConstants.VENDOR_ADDRESS_GENERATED_ID, paymentInfo.getPayeeAddressId());
        fieldValues.put(KFSPropertyConstants.ACCOUNT_ACTIVE_INDICATOR, KFSConstants.ACTIVE_INDICATOR);
        vendorAddresses = businessObjectService.findMatching(VendorAddress.class, fieldValues);
    } catch (Exception e) {
        LOG.error("findVendorAddress, there was an error attempting to find the vendor address", e);
        throw new ValidationException("Unable to find the vendor address: " + e.getMessage());
    }
    if (CollectionUtils.isEmpty(vendorAddresses)) {
        throw new ValidationException("Unable to find a vendor address for vendor number " + paymentInfo.getPayeeId() + " and vendor address id " + paymentInfo.getPayeeAddressId());
    }
    VendorAddress address = vendorAddresses.iterator().next();
    return address;
}
Also used : ValidationException(org.kuali.kfs.krad.exception.ValidationException) HashMap(java.util.HashMap) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress) ValidationException(org.kuali.kfs.krad.exception.ValidationException)

Example 9 with VendorAddress

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

the class VendorRule method refreshSubObjects.

/**
 * Refreshes the references of vendor detail and its sub objects
 *
 * @param vendor VendorDetail document
 */
protected void refreshSubObjects(VendorDetail vendor) {
    if (vendor == null) {
        return;
    }
    // division vendor
    if (!vendor.isVendorParentIndicator()) {
        vendor.refreshNonUpdateableReferences();
        vendor.getVendorHeader().refreshNonUpdateableReferences();
    } else {
        // Retrieve the references objects of the vendor header of this vendor.
        List<String> headerFieldNames = getObjectReferencesListFromBOClass(VendorHeader.class);
        vendor.getVendorHeader().refreshNonUpdateableReferences();
        getPersistenceService().retrieveReferenceObjects(vendor.getVendorHeader(), headerFieldNames);
        // We still need to retrieve all the other references of this vendor in addition to
        // vendor header. Since this is a parent vendor, whose vendor header saving is handled manually,
        // we have already retrieved references for vendor header's attributes above, so we should
        // exclude retrieving reference objects of vendor header.
        List<String> detailFieldNames = getObjectReferencesListFromBOClass(vendor.getClass());
        detailFieldNames.remove(VendorConstants.VENDOR_HEADER_ATTR);
        getPersistenceService().retrieveReferenceObjects(vendor, detailFieldNames);
    }
    // refresh addresses
    if (vendor.getVendorAddresses() != null) {
        for (VendorAddress address : vendor.getVendorAddresses()) {
            address.refreshNonUpdateableReferences();
            if (address.getVendorDefaultAddresses() != null) {
                for (VendorDefaultAddress defaultAddress : address.getVendorDefaultAddresses()) {
                    defaultAddress.refreshNonUpdateableReferences();
                }
            }
        }
    }
    // refresh contacts
    if (vendor.getVendorContacts() != null) {
        for (VendorContact contact : vendor.getVendorContacts()) {
            contact.refreshNonUpdateableReferences();
            // ==== CU Customization ====
            if (contact.getVendorContactPhoneNumbers() != null) {
                for (VendorContactPhoneNumber contactPhoneNumber : contact.getVendorContactPhoneNumbers()) {
                    contactPhoneNumber.refreshNonUpdateableReferences();
                }
            }
        // ==== End of CU Customization Section ====
        }
    }
    // refresh contracts
    if (vendor.getVendorContracts() != null) {
        for (VendorContract contract : vendor.getVendorContracts()) {
            contract.refreshNonUpdateableReferences();
        }
    }
}
Also used : VendorContactPhoneNumber(org.kuali.kfs.vnd.businessobject.VendorContactPhoneNumber) VendorContract(org.kuali.kfs.vnd.businessobject.VendorContract) VendorContact(org.kuali.kfs.vnd.businessobject.VendorContact) VendorDefaultAddress(org.kuali.kfs.vnd.businessobject.VendorDefaultAddress) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress)

Example 10 with VendorAddress

use of org.kuali.kfs.vnd.businessobject.VendorAddress 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)

Aggregations

VendorAddress (org.kuali.kfs.vnd.businessobject.VendorAddress)35 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)13 HashMap (java.util.HashMap)6 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)6 Iterator (java.util.Iterator)5 List (java.util.List)5 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)5 VendorContract (org.kuali.kfs.vnd.businessobject.VendorContract)5 VendorService (org.kuali.kfs.vnd.document.service.VendorService)5 ArrayList (java.util.ArrayList)4 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)3 Map (java.util.Map)3 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)3 WorkflowException (org.kuali.kfs.kew.api.exception.WorkflowException)3 PersistenceService (org.kuali.kfs.krad.service.PersistenceService)3 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)3 VendorDefaultAddress (org.kuali.kfs.vnd.businessobject.VendorDefaultAddress)3 CuVendorAddressExtension (edu.cornell.kfs.vnd.businessobject.CuVendorAddressExtension)2 VendorBatchAddress (edu.cornell.kfs.vnd.businessobject.VendorBatchAddress)2 Date (java.util.Date)2