Search in sources :

Example 1 with VendorDetail

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

the class IWantDocumentFeedServiceImpl method populateIWantDocument.

/**
 * Populates an I Want document based on the input data.
 *
 * @param batchIWantDocument
 */
private void populateIWantDocument(BatchIWantDocument batchIWantDocument, String incomingFileName) {
    boolean noErrors = true;
    List<AdHocRoutePerson> adHocRoutePersons = new ArrayList<AdHocRoutePerson>();
    LOG.info("Creating I Want document from data related to source number: " + batchIWantDocument.getSourceNumber());
    try {
        if (StringUtils.isBlank(batchIWantDocument.getInitiator())) {
            LOG.error("Initiator net ID cannot be empty: " + batchIWantDocument.getInitiator());
            noErrors = false;
        }
        // if initiator is blank we cannot create the I Want doc
        if (noErrors) {
            Person initiator = personService.getPersonByPrincipalName(batchIWantDocument.getInitiator());
            if (ObjectUtils.isNull(initiator)) {
                LOG.error("Initiator net ID is not valid: " + batchIWantDocument.getInitiator());
                noErrors = false;
            }
            // if initiator is not valid we cannot create the I Want doc
            if (noErrors) {
                IWantDocument iWantDocument = (IWantDocument) documentService.getNewDocument(CUPurapConstants.IWNT_DOC_TYPE, batchIWantDocument.getInitiator());
                iWantDocumentService.setUpIWantDocDefaultValues(iWantDocument, initiator);
                if (StringUtils.isNotBlank(batchIWantDocument.getInitiatorNetID())) {
                    iWantDocument.setInitiatorNetID(batchIWantDocument.getInitiatorNetID());
                }
                iWantDocument.getDocumentHeader().setExplanation(batchIWantDocument.getBusinessPurpose());
                iWantDocument.setExplanation(batchIWantDocument.getBusinessPurpose());
                if (StringUtils.isNotBlank(batchIWantDocument.getCollegeLevelOrganization())) {
                    iWantDocument.setCollegeLevelOrganization(batchIWantDocument.getCollegeLevelOrganization());
                }
                if (StringUtils.isNotBlank(batchIWantDocument.getDepartmentLevelOrganization())) {
                    iWantDocument.setDepartmentLevelOrganization(batchIWantDocument.getDepartmentLevelOrganization());
                }
                iWantDocument.getDocumentHeader().setOrganizationDocumentNumber(batchIWantDocument.getSourceNumber());
                // populate requester fields
                populateIWantDocRequestorSection(initiator, batchIWantDocument, iWantDocument);
                // populate deliver to section
                populateIWantDocDeliverToSection(batchIWantDocument, iWantDocument);
                // populate vendor data
                if (StringUtils.isNotBlank(batchIWantDocument.getVendorNumber())) {
                    String[] vendorNumbers = batchIWantDocument.getVendorNumber().split("-");
                    if (vendorNumbers.length == 2) {
                        try {
                            Integer vendorHeaderId = new Integer(vendorNumbers[0]);
                            Integer vendorId = new Integer(vendorNumbers[1]);
                            String phoneNumber = "Phone: ";
                            Map<String, Object> fieldValues = new HashMap<String, Object>();
                            fieldValues.put("vendorHeaderGeneratedIdentifier", vendorHeaderId);
                            fieldValues.put("vendorDetailAssignedIdentifier", vendorId);
                            fieldValues.put("vendorPhoneTypeCode", "PH");
                            Collection<VendorPhoneNumber> vendorPhoneNumbers = businessObjectService.findMatching(VendorPhoneNumber.class, fieldValues);
                            if (ObjectUtils.isNotNull(vendorPhoneNumbers) && vendorPhoneNumbers.size() > 0) {
                                VendorPhoneNumber retrievedVendorPhoneNumber = vendorPhoneNumbers.toArray(new VendorPhoneNumber[1])[0];
                                phoneNumber += retrievedVendorPhoneNumber.getVendorPhoneNumber();
                            }
                            Map<String, Object> fieldValuesVendorDetail = new HashMap<String, Object>();
                            fieldValuesVendorDetail.put("vendorHeaderGeneratedIdentifier", vendorHeaderId);
                            fieldValuesVendorDetail.put("vendorDetailAssignedIdentifier", vendorId);
                            VendorDetail vendorDetail = businessObjectService.findByPrimaryKey(VendorDetail.class, fieldValuesVendorDetail);
                            if (ObjectUtils.isNotNull(vendorDetail)) {
                                iWantDocument.setVendorHeaderGeneratedIdentifier(vendorHeaderId);
                                iWantDocument.setVendorDetailAssignedIdentifier(vendorId);
                                iWantDocument.setVendorName(vendorDetail.getVendorName());
                                updateDefaultVendorAddress(vendorDetail);
                                // populate vendor info
                                String addressLine1 = vendorDetail.getDefaultAddressLine1() != null ? vendorDetail.getDefaultAddressLine1() : StringUtils.EMPTY;
                                String addressLine2 = vendorDetail.getDefaultAddressLine2() != null ? vendorDetail.getDefaultAddressLine2() : StringUtils.EMPTY;
                                String cityName = vendorDetail.getDefaultAddressCity() != null ? vendorDetail.getDefaultAddressCity() : StringUtils.EMPTY;
                                String stateCode = vendorDetail.getDefaultAddressStateCode() != null ? vendorDetail.getDefaultAddressStateCode() : StringUtils.EMPTY;
                                String countryCode = vendorDetail.getDefaultAddressCountryCode() != null ? vendorDetail.getDefaultAddressCountryCode() : StringUtils.EMPTY;
                                String postalCode = vendorDetail.getDefaultAddressPostalCode() != null ? vendorDetail.getDefaultAddressPostalCode() : StringUtils.EMPTY;
                                String faxNumber = "Fax: " + (vendorDetail.getDefaultFaxNumber() != null ? vendorDetail.getDefaultFaxNumber() : StringUtils.EMPTY);
                                String url = "URL: " + (vendorDetail.getVendorUrlAddress() != null ? vendorDetail.getVendorUrlAddress() : StringUtils.EMPTY);
                                String vendorInfo = new StringBuilder(100).append(addressLine1).append('\n').append(addressLine2).append('\n').append(cityName).append(", ").append(postalCode).append(", ").append(stateCode).append(", ").append(countryCode).append('\n').append(faxNumber).append('\n').append(phoneNumber).append(" \n").append(url).toString();
                                iWantDocument.setVendorDescription(vendorInfo);
                            } else {
                                // Invalid vendor number
                                LOG.error("Vendor with id: " + batchIWantDocument.getVendorNumber() + " does not exist.");
                                noErrors = false;
                            }
                        } catch (NumberFormatException e) {
                            LOG.error("Vendor id: " + batchIWantDocument.getVendorNumber() + " is not valid.");
                            noErrors = false;
                        }
                    } else {
                        // Invalid vendor number
                        LOG.error("Vendor ID is not valid: " + batchIWantDocument.getVendorNumber());
                        noErrors = false;
                    }
                } else {
                    if (StringUtils.isNotEmpty(batchIWantDocument.getVendorName())) {
                        iWantDocument.setVendorName(batchIWantDocument.getVendorName());
                    }
                    if (StringUtils.isNotEmpty(batchIWantDocument.getVendorDescription())) {
                        iWantDocument.setVendorDescription(batchIWantDocument.getVendorDescription());
                    }
                }
                // add items
                noErrors &= populateIWantDocItems(batchIWantDocument, iWantDocument);
                // add accounts
                noErrors &= populateIWantDocAccounts(batchIWantDocument, iWantDocument);
                // account Description
                if (StringUtils.isNotBlank(batchIWantDocument.getAccountDescriptionTxt())) {
                    iWantDocument.setAccountDescriptionTxt(batchIWantDocument.getAccountDescriptionTxt());
                }
                if (StringUtils.isNotBlank(batchIWantDocument.getCommentsAndSpecialInstructions())) {
                    iWantDocument.setCommentsAndSpecialInstructions(batchIWantDocument.getCommentsAndSpecialInstructions());
                }
                iWantDocument.setGoods(batchIWantDocument.isGoods());
                if (StringUtils.isNotBlank(batchIWantDocument.getServicePerformedOnCampus())) {
                    iWantDocument.setServicePerformedOnCampus(batchIWantDocument.getServicePerformedOnCampus());
                }
                if (StringUtils.isNotBlank(batchIWantDocument.getCurrentRouteToNetId())) {
                    Person adHocRouteTo = personService.getPersonByPrincipalName(batchIWantDocument.getCurrentRouteToNetId());
                    if (ObjectUtils.isNull(adHocRouteTo)) {
                        LOG.error("Ad Hoc Route to net ID is not valid: " + batchIWantDocument.getCurrentRouteToNetId());
                        noErrors = false;
                    } else {
                        iWantDocument.setCurrentRouteToNetId(batchIWantDocument.getCurrentRouteToNetId());
                        AdHocRoutePerson recipient = new AdHocRoutePerson();
                        recipient.setId(iWantDocument.getCurrentRouteToNetId());
                        recipient.setActionRequested(KewApiConstants.ACTION_REQUEST_APPROVE_REQ);
                        adHocRoutePersons.add(recipient);
                        iWantDocument.setAdHocRoutePersons(adHocRoutePersons);
                    }
                }
                iWantDocumentService.setIWantDocumentDescription(iWantDocument);
                // add notes
                addNotes(iWantDocument, batchIWantDocument);
                // add attachments
                loadDocumentAttachments(iWantDocument, batchIWantDocument.getAttachments(), incomingFileName);
                boolean rulePassed = true;
                // call business rules
                rulePassed &= ruleService.applyRules(new SaveDocumentEvent("", iWantDocument));
                if (!rulePassed) {
                    LOG.error("I Want document " + iWantDocument.getDocumentNumber() + "not saved due to errors");
                    logErrorMessages();
                } else if (noErrors) {
                    documentService.saveDocument(iWantDocument);
                }
            }
        }
    } catch (Exception e) {
        LOG.error("error while creating I Want document:  " + e.getMessage(), e);
        throw new RuntimeException("Error encountered while attempting to create I Want document " + e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SaveDocumentEvent(org.kuali.kfs.krad.rules.rule.event.SaveDocumentEvent) AdHocRoutePerson(org.kuali.kfs.krad.bo.AdHocRoutePerson) VendorPhoneNumber(org.kuali.kfs.vnd.businessobject.VendorPhoneNumber) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ParseException(org.kuali.kfs.sys.exception.ParseException) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) AdHocRoutePerson(org.kuali.kfs.krad.bo.AdHocRoutePerson) Person(org.kuali.rice.kim.api.identity.Person) BatchIWantDocument(edu.cornell.kfs.module.purap.document.BatchIWantDocument) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument)

Example 2 with VendorDetail

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

the class PaymentGroup method setPayeeIdAndName.

/**
 * @param string
 */
public void setPayeeIdAndName(String string) {
    if (string.split("-").length == 1) {
        // process Payee as a employee
        payeeId = string;
    } else {
        // process Payee as a vendor
        payeeId = string;
        BusinessObjectService bos = SpringContext.getBean(BusinessObjectService.class);
        String[] headerDetails = payeeId.split("-");
        Map<String, String> fieldValues = new HashMap<String, String>();
        fieldValues.put("vendorHeaderGeneratedIdentifier", headerDetails[0]);
        fieldValues.put("vendorDetailAssignedIdentifier", headerDetails[1]);
        List<VendorDetail> details = (List<VendorDetail>) bos.findMatching(VendorDetail.class, fieldValues);
        if (details.size() == 1) {
            payeeName = details.get(0).getVendorName();
        } else {
            throw new RuntimeException("Could not locate Vendor for payeeId [ " + string + " ]");
        }
    }
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService)

Example 3 with VendorDetail

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

the class PurchasingDocumentBase method getHasB2BVendor.

public boolean getHasB2BVendor() {
    if (getVendorHeaderGeneratedIdentifier() != null) {
        refreshReferenceObject(VendorPropertyConstants.VENDOR_DETAIL);
        String campusCode = GlobalVariables.getUserSession().getPerson().getCampusCode();
        VendorDetail vendorDetail = getVendorDetail();
        if (vendorDetail == null || StringUtils.isEmpty(campusCode)) {
            // this should never happen
            return false;
        }
        return SpringContext.getBean(VendorService.class).getVendorB2BContract(vendorDetail, campusCode) != null;
    }
    return false;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail)

Example 4 with VendorDetail

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

the class CuDisbursementVoucherDocument method refreshPayeeTypeSuffixIfPaymentIsEditable.

public void refreshPayeeTypeSuffixIfPaymentIsEditable() {
    TransactionalDocumentAuthorizer docAuthorizer = getDvDocumentAuthorizer();
    if (docAuthorizer.canEdit(this, GlobalVariables.getUserSession().getPerson())) {
        Set<String> editModes = getDvDocumentPresentationController().getEditModes(this);
        editModes = docAuthorizer.getEditModes(this, GlobalVariables.getUserSession().getPerson(), editModes);
        if (editModes.contains(KfsAuthorizationConstants.DisbursementVoucherEditMode.PAYEE_ENTRY)) {
            String newSuffix;
            if (getDvPayeeDetail().isVendor()) {
                VendorDetail vendor = getVendorService().getByVendorNumber(getDvPayeeDetail().getDisbVchrPayeeIdNumber());
                if (ObjectUtils.isNotNull(vendor)) {
                    newSuffix = createVendorPayeeTypeSuffix(vendor.getVendorHeader().getVendorType());
                } else {
                    newSuffix = StringUtils.EMPTY;
                }
            } else {
                newSuffix = StringUtils.EMPTY;
            }
            ((CuDisbursementVoucherPayeeDetailExtension) getDvPayeeDetail().getExtension()).setPayeeTypeSuffix(newSuffix);
        }
    }
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) CuDisbursementVoucherPayeeDetailExtension(edu.cornell.kfs.fp.businessobject.CuDisbursementVoucherPayeeDetailExtension) TransactionalDocumentAuthorizer(org.kuali.kfs.kns.document.authorization.TransactionalDocumentAuthorizer)

Example 5 with VendorDetail

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

the class CuDisbursementPayeeLookupableHelperServiceImpl method getVendorsAsPayees.

protected List<DisbursementPayee> getVendorsAsPayees(Map<String, String> fieldValues) {
    List<DisbursementPayee> payeeList = new ArrayList<DisbursementPayee>();
    Map<String, String> fieldsForLookup = this.getVendorFieldValues(fieldValues);
    vendorLookupable.setBusinessObjectClass(VendorDetail.class);
    vendorLookupable.validateSearchParameters(fieldsForLookup);
    List<? extends BusinessObject> vendorList = vendorLookupable.getSearchResults(fieldsForLookup);
    for (BusinessObject vendor : vendorList) {
        VendorDetail vendorDetail = (VendorDetail) vendor;
        CuDisbursementPayee payee = getPayeeFromVendor(vendorDetail, fieldValues);
        payeeList.add(payee);
    }
    return payeeList;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) CuDisbursementPayee(edu.cornell.kfs.fp.businessobject.CuDisbursementPayee) ArrayList(java.util.ArrayList) CuDisbursementPayee(edu.cornell.kfs.fp.businessobject.CuDisbursementPayee) DisbursementPayee(org.kuali.kfs.fp.businessobject.DisbursementPayee) BusinessObject(org.kuali.rice.krad.bo.BusinessObject)

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