Search in sources :

Example 16 with RequisitionDocument

use of org.kuali.kfs.module.purap.document.RequisitionDocument in project cu-kfs by CU-CommunityApps.

the class CuRequisitionServiceImplTest method testCheckAPORulesPerItemForCommodityCodes_Inactive.

public void testCheckAPORulesPerItemForCommodityCodes_Inactive() throws WorkflowException {
    RequisitionDocument requisitionDocument = RequisitionFixture.REQ_NON_B2B_CAP_ASSET_ITEM_INACTIVE_COMM_CODE.createRequisition();
    String result = cuRequisitionServiceImpl.checkAPORulesPerItemForCommodityCodes(RequisitionItemFixture.REQ_ITEM_INACTIVE_COMM_CD.createRequisitionItem(true), requisitionDocument.getVendorDetail().getVendorCommodities(), true);
    // check for active commodity code removed in customization, inactive commodity code should be fine
    assertEquals(KFSConstants.EMPTY_STRING, result);
}
Also used : RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument)

Example 17 with RequisitionDocument

use of org.kuali.kfs.module.purap.document.RequisitionDocument 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)

Example 18 with RequisitionDocument

use of org.kuali.kfs.module.purap.document.RequisitionDocument in project cu-kfs by CU-CommunityApps.

the class CuRequisitionDocument method isB2BTotalAmountForAutoPO.

protected boolean isB2BTotalAmountForAutoPO() {
    boolean returnValue = false;
    ParameterService parameterService = SpringContext.getBean(ParameterService.class);
    String autoPOAmountString = new String(parameterService.getParameterValueAsString(RequisitionDocument.class, CUPurapParameterConstants.B2B_TOTAL_AMOUNT_FOR_AUTO_PO));
    KualiDecimal autoPOAmount = new KualiDecimal(autoPOAmountString);
    // KFSPTS-1625
    String routedBy = getRoutedByPrincipalId();
    if (StringUtils.isBlank(routedBy)) {
        routedBy = this.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
    }
    if (KimApiServiceLocator.getPermissionService().hasPermission(routedBy, CUKFSConstants.ParameterNamespaces.PURCHASING, CUPurapConstants.B2B_HIGHER_LIMIT_PERMISSION)) {
        String paramVal = parameterService.getParameterValueAsString(RequisitionDocument.class, CUPurapParameterConstants.B2B_TOTAL_AMOUNT_FOR_SUPER_USER_AUTO_PO);
        if (StringUtils.isNotBlank(paramVal)) {
            autoPOAmount = new KualiDecimal(paramVal);
        }
    }
    RequisitionDocument document = null;
    try {
        document = (RequisitionDocument) (SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(this.getDocumentNumber()));
    } catch (WorkflowException we) {
    }
    KualiDecimal totalAmount = document.getFinancialSystemDocumentHeader().getFinancialDocumentTotalAmount();
    if (ObjectUtils.isNotNull(autoPOAmount) && ObjectUtils.isNotNull(totalAmount) && (autoPOAmount.compareTo(totalAmount) >= 0)) {
        returnValue = true;
    } else {
        returnValue = false;
    }
    return returnValue;
}
Also used : RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal)

Example 19 with RequisitionDocument

use of org.kuali.kfs.module.purap.document.RequisitionDocument in project cu-kfs by CU-CommunityApps.

the class CuRequisitionDocument method getRoutedByPrincipalId.

public String getRoutedByPrincipalId() {
    DocumentService documentService = SpringContext.getBean(DocumentService.class);
    RequisitionDocument document = null;
    String principalId = null;
    try {
        document = (RequisitionDocument) documentService.getByDocumentHeaderId(this.getDocumentNumber());
        principalId = document.getDocumentHeader().getWorkflowDocument().getRoutedByPrincipalId();
    } catch (WorkflowException we) {
    }
    return principalId;
}
Also used : RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) DocumentService(org.kuali.kfs.krad.service.DocumentService)

Example 20 with RequisitionDocument

use of org.kuali.kfs.module.purap.document.RequisitionDocument in project cu-kfs by CU-CommunityApps.

the class CuRequisitionAccountingLineAuthorizer method renderNewLine.

@Override
public boolean renderNewLine(AccountingDocument accountingDocument, String accountingGroupProperty) {
    WorkflowDocument workflowDocument = ((PurchasingAccountsPayableDocument) accountingDocument).getFinancialSystemDocumentHeader().getWorkflowDocument();
    Set<String> currentNodes = workflowDocument.getCurrentNodeNames();
    if (CollectionUtils.isNotEmpty(currentNodes) && (currentNodes.contains(RequisitionAccountingLineAuthorizer.INITIATOR_NODE) || currentNodes.contains(RequisitionAccountingLineAuthorizer.CONTENT_REVIEW_NODE)) || (currentNodes.contains(RequisitionStatuses.NODE_ACCOUNT) && SpringContext.getBean(CuPurapAccountingService.class).isFiscalOfficersForAllAcctLines((RequisitionDocument) accountingDocument))) {
        return true;
    }
    return super.renderNewLine(accountingDocument, accountingGroupProperty);
}
Also used : RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) WorkflowDocument(org.kuali.rice.kew.api.WorkflowDocument)

Aggregations

RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)21 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)6 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)6 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)4 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)3 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)3 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)2 File (java.io.File)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 DocumentService (org.kuali.kfs.krad.service.DocumentService)2 ElectronicInvoiceLoad (org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceLoad)2 PaymentRequestAccount (org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount)2 RequisitionItem (org.kuali.kfs.module.purap.businessobject.RequisitionItem)2 WorkflowDocument (org.kuali.rice.kew.api.WorkflowDocument)2 CuPaymentRequestItemExtension (edu.cornell.kfs.module.purap.businessobject.CuPaymentRequestItemExtension)1 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)1 CuRequisitionDocument (edu.cornell.kfs.module.purap.document.CuRequisitionDocument)1