Search in sources :

Example 46 with VendorDetail

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

the class CuElectronicInvoiceHelperServiceImpl method setVendorDetails.

protected void setVendorDetails(ElectronicInvoice eInvoice) {
    // based on code found in this class
    // Marcia mentioned that each einvoice just for one po.
    String poID = eInvoice.getInvoiceDetailOrders().get(0).getOrderReferenceOrderID();
    PurchaseOrderDocument po = null;
    if (StringUtils.isNotEmpty(eInvoice.getDunsNumber())) {
        // KFSUPGRADE-479 : retrieve vendor from po vendor.
        VendorDetail vendorDetail = null;
        if (NumberUtils.isDigits(StringUtils.defaultString(poID)) && !isIntegerTooLarge(poID)) {
            po = purchaseOrderService.getCurrentPurchaseOrder(new Integer(poID));
        }
        if (po != null) {
            vendorDetail = vendorService.getVendorDetail(po.getVendorHeaderGeneratedIdentifier(), po.getVendorDetailAssignedIdentifier());
            if (vendorDetail == null) {
                vendorDetail = vendorService.getVendorByDunsNumber(eInvoice.getDunsNumber());
            }
        } else {
            vendorDetail = vendorService.getVendorByDunsNumber(eInvoice.getDunsNumber());
        }
        if (vendorDetail != null) {
            LOG.info("Vendor match found - " + vendorDetail.getVendorNumber());
            eInvoice.setVendorHeaderID(vendorDetail.getVendorHeaderGeneratedIdentifier());
            eInvoice.setVendorDetailID(vendorDetail.getVendorDetailAssignedIdentifier());
            eInvoice.setVendorName(vendorDetail.getVendorName());
        } else {
            eInvoice.setVendorHeaderID(null);
            eInvoice.setVendorDetailID(null);
            eInvoice.setVendorName(null);
        }
    }
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument)

Example 47 with VendorDetail

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

the class CuDisbursementVoucherDocumentTest method testGeneratePayeeTypeDisplayName.

@Test
public void testGeneratePayeeTypeDisplayName() throws Exception {
    setupPayeeDetail("0", "12345");
    assertTrue("Payee Detail Extension should have had a blank suffix", StringUtils.isBlank(getDetailExtensionFromDv().getPayeeTypeSuffix()));
    assertTrue("Payee Detail Extension should have had a blank suffix display value", StringUtils.isBlank(getDetailExtensionFromDv().getPayeeTypeSuffixForDisplay()));
    assertEquals("Payee Detail has the wrong Payee Type display name", VENDOR_PAYEE_TYPE_NAME, cuDisbursementVoucherDocument.getDvPayeeDetail().getDisbursementVoucherPayeeTypeName());
    VendorDetail vendor = vendorService.getVendorDetail("12345-0");
    assertNotNull("Vendor 12345-0 should have been found", vendor);
    getDetailExtensionFromDv().setPayeeTypeSuffix(cuDisbursementVoucherDocument.createVendorPayeeTypeSuffix(vendor.getVendorHeader().getVendorType()));
    assertEquals("Payee Detail Extension has the wrong suffix defined", VENDOR_PAYEE_TYPE_SUFFIX, getDetailExtensionFromDv().getPayeeTypeSuffix());
    assertEquals("Payee Detail Extension has the wrong suffix display value", VENDOR_PAYEE_TYPE_SUFFIX_FOR_DISPLAY, getDetailExtensionFromDv().getPayeeTypeSuffixForDisplay());
    assertEquals("Payee Detail has the wrong Payee Type suffix-included display name", VENDOR_PAYEE_TYPE_NAME_WITH_SUFFIX, cuDisbursementVoucherDocument.getDvPayeeDetail().getDisbursementVoucherPayeeTypeName());
    cuDisbursementVoucherDocument.setDvPayeeDetail(new TestDisbursementVoucherPayeeDetail());
    assertTrue("DV Payee ID Number should be cleared", StringUtils.isBlank(cuDisbursementVoucherDocument.getDvPayeeDetail().getDisbVchrPayeeIdNumber()));
    assertTrue("Payee Type Code should be cleared", StringUtils.isBlank(cuDisbursementVoucherDocument.getDvPayeeDetail().getDisbursementVoucherPayeeTypeCode()));
    assertTrue("Payee Detail Extension should have had its suffix cleared out", StringUtils.isBlank(getDetailExtensionFromDv().getPayeeTypeSuffix()));
    assertTrue("Payee Detail Extension should have had a blank suffix display value due to suffix being cleared", StringUtils.isBlank(getDetailExtensionFromDv().getPayeeTypeSuffixForDisplay()));
    assertEquals("Payee Detail should have had an empty Payee Type display name", StringUtils.EMPTY, cuDisbursementVoucherDocument.getDvPayeeDetail().getDisbursementVoucherPayeeTypeName());
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) Test(org.junit.Test)

Example 48 with VendorDetail

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

the class CuDisbursementVoucherExtractionHelperServiceImplTest method test.

public void test() {
    CuDisbursementVoucherDocument dv = null;
    try {
        dv = (CuDisbursementVoucherDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DisbursementVoucherDocument.class);
    } catch (WorkflowException e) {
        throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
    }
    if (dv != null) {
        dv.getDocumentHeader().setDocumentDescription("Test Document Description");
        dv.getDocumentHeader().setExplanation("Stuff");
        dv.initiateDocument();
        VendorDetail vendor = SpringContext.getBean(VendorService.class).getVendorDetail("13366-0");
        VendorAddress vendoraddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(vendor.getVendorHeaderGeneratedIdentifier(), vendor.getVendorDetailAssignedIdentifier(), "RM", "");
        System.out.println(vendoraddress.getVendorCityName() + "\n");
        dv.templateVendor(vendor, vendoraddress);
        dv.setPayeeAssigned(true);
        dv.getDvPayeeDetail().setDisbVchrPaymentReasonCode("S");
        dv.setDisbVchrCheckTotalAmount(new KualiDecimal(86.00));
        dv.setDisbVchrPaymentMethodCode("P");
        dv.setDisbVchrCheckStubText("check text");
        dv.setCampusCode("IT");
        SourceAccountingLine accountingLine = new SourceAccountingLine();
        accountingLine.setChartOfAccountsCode("IT");
        accountingLine.setAccountNumber("G081040");
        accountingLine.setFinancialObjectCode("2045");
        accountingLine.setAmount((new KualiDecimal(86.00)));
        accountingLine.setPostingYear(dv.getPostingYear());
        accountingLine.setDocumentNumber(dv.getDocumentNumber());
        dv.addSourceAccountingLine(accountingLine);
        try {
            documentService.saveDocument(dv);
        } catch (WorkflowException e) {
            throw new RuntimeException("Error saving new disbursement voucher document: " + e.getMessage(), e);
        }
    }
    Date transactionTimestamp = new Date(SpringContext.getBean(DateTimeService.class).getCurrentDate().getTime());
    Date processRunDate = new java.sql.Date(transactionTimestamp.getTime());
    PaymentGroup pg = cuDisbursementVoucherExtractionHelperService.createPaymentGroup(dv, processRunDate);
    assertTrue(pg.getPaymentDetails().get(0).getCustPaymentDocNbr().equalsIgnoreCase(dv.getDocumentNumber()));
}
Also used : PaymentGroup(org.kuali.kfs.pdp.businessobject.PaymentGroup) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) DocumentService(org.kuali.kfs.krad.service.DocumentService) Date(java.sql.Date) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorService(org.kuali.kfs.vnd.document.service.VendorService) CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress) DateTimeService(org.kuali.rice.core.api.datetime.DateTimeService)

Example 49 with VendorDetail

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

the class CuDisbursementVoucherDocumentIntegrationTest method setupCuDisbursementVoucherDocument.

private CuDisbursementVoucherDocument setupCuDisbursementVoucherDocument() throws WorkflowException {
    CuDisbursementVoucherDocument dv = (CuDisbursementVoucherDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DisbursementVoucherDocument.class);
    dv.getDocumentHeader().setDocumentDescription("Test Document Description");
    dv.getDocumentHeader().setExplanation("Stuff");
    dv.initiateDocument();
    VendorDetail vendor = vendorService.getVendorDetail("13366-0");
    VendorAddress vendoraddress = vendorService.getVendorDefaultAddress(vendor.getVendorHeaderGeneratedIdentifier(), vendor.getVendorDetailAssignedIdentifier(), "RM", "");
    dv.templateVendor(vendor, vendoraddress);
    dv.setPayeeAssigned(true);
    dv.getDvPayeeDetail().setDisbVchrPaymentReasonCode("S");
    dv.setDisbVchrCheckTotalAmount(new KualiDecimal(86.00));
    dv.setDisbVchrPaymentMethodCode("P");
    dv.setDisbVchrCheckStubText("check text");
    dv.setCampusCode("IT");
    SourceAccountingLine accountingLine = new SourceAccountingLine();
    accountingLine.setChartOfAccountsCode("IT");
    accountingLine.setAccountNumber("G081040");
    accountingLine.setFinancialObjectCode("2045");
    accountingLine.setAmount((new KualiDecimal(86.00)));
    accountingLine.setPostingYear(dv.getPostingYear());
    accountingLine.setDocumentNumber(dv.getDocumentNumber());
    dv.addSourceAccountingLine(accountingLine);
    documentService.saveDocument(dv);
    return dv;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument)

Example 50 with VendorDetail

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

the class CuB2BShoppingServiceImpl method createRequisitionsFromCxml.

@Override
public List createRequisitionsFromCxml(B2BShoppingCart message, Person user) throws WorkflowException {
    LOG.debug("createRequisitionsFromCxml() started");
    // for returning requisitions
    ArrayList requisitions = new ArrayList();
    // get items from the cart
    List items = message.getItems();
    // get vendor(s) for the items
    List vendors = getAllVendors(items);
    // create requisition(s) (one per vendor)
    for (Iterator iter = vendors.iterator(); iter.hasNext(); ) {
        VendorDetail vendor = (VendorDetail) iter.next();
        // create requisition
        RequisitionDocument req = (RequisitionDocument) documentService.getNewDocument(PurapConstants.REQUISITION_DOCUMENT_TYPE);
        String description = ((B2BShoppingCartItem) items.get(0)).getExtrinsic("CartName");
        String businessPurpose = ((CuB2BShoppingCart) message).getBusinessPurpose();
        req.getDocumentHeader().setDocumentDescription(description);
        req.getDocumentHeader().setExplanation(businessPurpose);
        req.setupAccountDistributionMethod();
        // set b2b contract for vendor
        VendorContract contract = vendorService.getVendorB2BContract(vendor, user.getCampusCode());
        if (ObjectUtils.isNotNull(contract)) {
            req.setVendorContractGeneratedIdentifier(contract.getVendorContractGeneratedIdentifier());
            if (ObjectUtils.isNotNull(contract.getPurchaseOrderCostSourceCode())) {
                // if cost source is set on contract, use it
                req.setPurchaseOrderCostSourceCode(contract.getPurchaseOrderCostSourceCode());
            } else {
                // if cost source is null on the contract, we set it by default to "Estimate"
                req.setPurchaseOrderCostSourceCode(PurapConstants.POCostSources.ESTIMATE);
            }
        } else {
            LOG.error("createRequisitionsFromCxml() Contract is missing for vendor " + vendor.getVendorName() + " (" + vendor.getVendorNumber() + ")");
            throw new B2BShoppingException(PurapConstants.B2B_VENDOR_CONTRACT_NOT_FOUND_ERROR_MESSAGE);
        }
        // get items for this vendor
        List itemsForVendor = getAllVendorItems(items, vendor);
        // KFSPTS-985
        checkToPopulateFavoriteAccount(itemsForVendor, user);
        // default data from user
        req.setDeliveryCampusCode(user.getCampusCode());
        req.setDeliveryToName(user.getName());
        req.setDeliveryToEmailAddress(user.getEmailAddressUnmasked());
        req.setDeliveryToPhoneNumber(SpringContext.getBean(PhoneNumberService.class).formatNumberIfPossible(user.getPhoneNumber()));
        DefaultPrincipalAddress defaultPrincipalAddress = new DefaultPrincipalAddress(user.getPrincipalId());
        Map addressKeys = SpringContext.getBean(PersistenceService.class).getPrimaryKeyFieldValues(defaultPrincipalAddress);
        defaultPrincipalAddress = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(DefaultPrincipalAddress.class, addressKeys);
        if (ObjectUtils.isNotNull(defaultPrincipalAddress) && ObjectUtils.isNotNull(defaultPrincipalAddress.getBuilding())) {
            if (defaultPrincipalAddress.getBuilding().isActive()) {
                req.setDeliveryCampusCode(defaultPrincipalAddress.getCampusCode());
                req.templateBuildingToDeliveryAddress(defaultPrincipalAddress.getBuilding());
                req.setDeliveryBuildingRoomNumber(defaultPrincipalAddress.getBuildingRoomNumber());
            } else {
                // since building is now inactive, delete default building record
                SpringContext.getBean(BusinessObjectService.class).delete(defaultPrincipalAddress);
            }
        }
        ChartOrgHolder purapChartOrg = SpringContext.getBean(FinancialSystemUserService.class).getPrimaryOrganization(user, PurapConstants.PURAP_NAMESPACE);
        if (ObjectUtils.isNotNull(purapChartOrg)) {
            req.setChartOfAccountsCode(purapChartOrg.getChartOfAccountsCode());
            req.setOrganizationCode(purapChartOrg.getOrganizationCode());
        }
        req.setRequestorPersonName(user.getName());
        req.setRequestorPersonEmailAddress(user.getEmailAddress());
        req.setRequestorPersonPhoneNumber(phoneNumberService.formatNumberIfPossible(user.getPhoneNumber()));
        req.setUseTaxIndicator(purchasingService.getDefaultUseTaxIndicatorValue(req));
        // set defaults that need to be set
        req.setVendorHeaderGeneratedIdentifier(vendor.getVendorHeaderGeneratedIdentifier());
        req.setVendorDetailAssignedIdentifier(vendor.getVendorDetailAssignedIdentifier());
        req.setVendorName(vendor.getVendorName());
        req.setVendorRestrictedIndicator(vendor.getVendorRestrictedIndicator());
        req.setItems(itemsForVendor);
        req.setDocumentFundingSourceCode(parameterService.getParameterValueAsString(RequisitionDocument.class, PurapParameterConstants.DEFAULT_FUNDING_SOURCE));
        req.setRequisitionSourceCode(PurapConstants.RequisitionSources.B2B);
        req.updateAndSaveAppDocStatus(PurapConstants.RequisitionStatuses.APPDOC_IN_PROCESS);
        // KFSPTS-1446 : Needed to move the setting of method of PO transmission to after the templateVendorAddress call because that method will set the method of PO transmission to the value on the vendor address.
        // req.setPurchaseOrderTransmissionMethodCode(PurapConstants.POTransmissionMethods.ELECTRONIC);
        req.setOrganizationAutomaticPurchaseOrderLimit(purapService.getApoLimit(req.getVendorContractGeneratedIdentifier(), req.getChartOfAccountsCode(), req.getOrganizationCode()));
        // retrieve from an item (sent in cxml at item level, but stored in db at REQ level)
        req.setExternalOrganizationB2bSupplierIdentifier(getSupplierIdFromFirstItem(itemsForVendor));
        // retrieve default PO address and set address
        VendorAddress vendorAddress = vendorService.getVendorDefaultAddress(vendor.getVendorHeaderGeneratedIdentifier(), vendor.getVendorDetailAssignedIdentifier(), VendorConstants.AddressTypes.PURCHASE_ORDER, user.getCampusCode());
        if (ObjectUtils.isNotNull(vendorAddress)) {
            req.templateVendorAddress(vendorAddress);
        }
        // KFSPTS-1446: Moved the setting of this attribute here from its original location to maintain the value of ELECTRONIC and not lose it to the templateVendorAddress value
        req.setPurchaseOrderTransmissionMethodCode(PurapConstants.POTransmissionMethods.ELECTRONIC);
        // retrieve billing address based on delivery campus and populate REQ with retrieved billing address
        BillingAddress billingAddress = new BillingAddress();
        billingAddress.setBillingCampusCode(req.getDeliveryCampusCode());
        Map keys = persistenceService.getPrimaryKeyFieldValues(billingAddress);
        billingAddress = businessObjectService.findByPrimaryKey(BillingAddress.class, keys);
        req.templateBillingAddress(billingAddress);
        // populate receiving address with the default one for the chart/org
        req.loadReceivingAddress();
        req.fixItemReferences();
        // save requisition to database
        purapService.saveDocumentNoValidation(req);
        // add requisition to List
        requisitions.add(req);
    }
    return requisitions;
}
Also used : DefaultPrincipalAddress(org.kuali.kfs.module.purap.businessobject.DefaultPrincipalAddress) VendorContract(org.kuali.kfs.vnd.businessobject.VendorContract) ArrayList(java.util.ArrayList) B2BShoppingException(org.kuali.kfs.module.purap.exception.B2BShoppingException) CuB2BShoppingCart(edu.cornell.kfs.module.purap.util.cxml.CuB2BShoppingCart) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) PersistenceService(org.kuali.kfs.krad.service.PersistenceService) BillingAddress(org.kuali.kfs.module.purap.businessobject.BillingAddress) ChartOrgHolder(org.kuali.kfs.sys.businessobject.ChartOrgHolder) B2BShoppingCartItem(org.kuali.kfs.module.purap.businessobject.B2BShoppingCartItem) FinancialSystemUserService(org.kuali.kfs.sys.service.FinancialSystemUserService) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress)

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