Search in sources :

Example 1 with PurchaseOrderAmendmentDocument

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

the class PurchasingActionBase method refresh.

/**
 * @see org.kuali.kfs.sys.web.struts.KualiAccountingDocumentActionBase#refresh(org.apache.struts.action.ActionMapping,
 *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
@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()));
    // names in KIM are longer than what we store these names at; truncate them to match our data dictionary maxlengths
    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.intValue()) {
            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.intValue()) {
            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.isEmpty(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.kns.service.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.rice.core.api.util.type.KualiDecimal) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress) Map(java.util.Map) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 2 with PurchaseOrderAmendmentDocument

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

the class CuReceivingServiceImpl method spawnPoAmendmentForUnorderedItems.

protected void spawnPoAmendmentForUnorderedItems(ReceivingDocument receivingDocument, PurchaseOrderDocument po) {
    // if receiving line document
    if (receivingDocument instanceof LineItemReceivingDocument) {
        LineItemReceivingDocument rlDoc = (LineItemReceivingDocument) receivingDocument;
        // if a new item has been added spawn a purchase order amendment
        if (hasNewUnorderedItem((LineItemReceivingDocument) receivingDocument)) {
            String newSessionUserId = KFSConstants.SYSTEM_USER;
            try {
                LogicContainer logicToRun = new LogicContainer() {

                    @Override
                    public Object runLogic(Object[] objects) throws Exception {
                        LineItemReceivingDocument rlDoc = (LineItemReceivingDocument) objects[0];
                        String poDocNumber = (String) objects[1];
                        // create a PO amendment
                        PurchaseOrderAmendmentDocument amendmentPo = (PurchaseOrderAmendmentDocument) purchaseOrderService.createAndSavePotentialChangeDocument(poDocNumber, PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT, PurchaseOrderStatuses.APPDOC_AMENDMENT);
                        // KFSPTS-1769, KFSUPGRADE-339
                        ((CuPurchaseOrderAmendmentDocument) amendmentPo).setSpawnPoa(true);
                        // add new lines to amendement
                        addUnorderedItemsToAmendment(amendmentPo, rlDoc);
                        // route amendment
                        documentService.routeDocument(amendmentPo, null, null);
                        // add note to amendment po document
                        String note = "Purchase Order Amendment " + amendmentPo.getPurapDocumentIdentifier() + " (document id " + amendmentPo.getDocumentNumber() + ") created for new unordered line items due to Receiving (document id " + rlDoc.getDocumentNumber() + ")";
                        Note noteObj = documentService.createNoteFromDocument(amendmentPo, note);
                        amendmentPo.addNote(noteObj);
                        noteService.save(noteObj);
                        return null;
                    }
                };
                purapService.performLogicWithFakedUserSession(newSessionUserId, logicToRun, new Object[] { rlDoc, po.getDocumentNumber() });
            } catch (WorkflowException e) {
                String errorMsg = "Workflow Exception caught: " + e.getLocalizedMessage();
                throw new RuntimeException(errorMsg, e);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) CuPurchaseOrderAmendmentDocument(edu.cornell.kfs.module.purap.document.CuPurchaseOrderAmendmentDocument) CuPurchaseOrderAmendmentDocument(edu.cornell.kfs.module.purap.document.CuPurchaseOrderAmendmentDocument) LineItemReceivingDocument(org.kuali.kfs.module.purap.document.LineItemReceivingDocument) Note(org.kuali.kfs.krad.bo.Note) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) LogicContainer(org.kuali.kfs.module.purap.document.service.LogicContainer) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException)

Example 3 with PurchaseOrderAmendmentDocument

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

the class CuPurchaseOrderAction method processAccountingLineOverrides.

/**
 * Overridden to perform the proper account-line-override setup
 * on POA items' account addLines, as well as on all of the items'
 * existing accounting lines instead of just the filtered list
 * from the document's getSourceAccountingLines() method override.
 *
 * @see org.kuali.kfs.sys.web.struts.KualiAccountingDocumentActionBase#processAccountingLineOverrides(
 * org.kuali.kfs.sys.web.struts.KualiAccountingDocumentFormBase)
 */
@Override
protected void processAccountingLineOverrides(KualiAccountingDocumentFormBase transForm) {
    if (transForm.hasDocumentId() && transForm.getDocument() instanceof PurchaseOrderAmendmentDocument) {
        PurchaseOrderAmendmentDocument poaDocument = (PurchaseOrderAmendmentDocument) transForm.getDocument();
        processAccountingLineOverrides(transForm.getNewSourceLine());
        processAccountingLineOverrides(transForm.getNewTargetLine());
        processAccountingLineOverrides(poaDocument, getItemSourceAccountingLines(poaDocument));
        processAccountingLineOverrides(poaDocument, poaDocument.getTargetAccountingLines());
        /*
             * Using null document as first arg, for consistency with regular source/target addLine handling
             * in KualiAccountingDocumentActionBase.
             */
        processAccountingLineOverrides(null, getItemAccountingAddLines(poaDocument));
    } else {
        super.processAccountingLineOverrides(transForm);
    }
}
Also used : PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument)

Example 4 with PurchaseOrderAmendmentDocument

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

the class CuPurchasingProcessVendorValidation method validateDataForMethodOfPOTransmissionExistsOnVendorAddress.

/**
 * This routine verifies that the data necessary for the Method of PO Transmission chosen on the REQ,
 * PO, or POA document exists on the document's VendorAddress record for the chosen Vendor.
 * If the required checks pass, true is returned.
 * If the required checks fail, false is returned.
 *
 * NOTE: This routine could not be used for the VendorAddress validation checks on the Vendor maintenance
 * document because the Method of PO Transmission value selectable on that document pertains to the specific
 * VendorAddress being maintained.  The method of PO transmission being used for this routine's validation
 * checks is the one that is present on the input parameter purchasing document (REQ, PO, or POA) and could
 * be different from the value of the same name that is on the VendorAddress.  It is ok if these two values
 * are different because the user could have changed it after the default was obtained via the lookup and
 * used to populate the REQ, PO, or POA value as long as the data required for the method of PO transmission
 * selected in that document exists on the VendorAddress record chosen on the REQ, PO, or POA.
 *
 * 	For KFSPTS-1458: This method was changed extensively to address new business rules.
 */
public boolean validateDataForMethodOfPOTransmissionExistsOnVendorAddress(Document document) {
    boolean dataExists = true;
    MessageMap errorMap = GlobalVariables.getMessageMap();
    errorMap.clearErrorPath();
    errorMap.addToErrorPath(PurapConstants.VENDOR_ERRORS);
    // for REQ, PO, and POA verify that data exists on form for method of PO transmission value selected
    if ((document instanceof RequisitionDocument) || (document instanceof PurchaseOrderDocument) || (document instanceof PurchaseOrderAmendmentDocument)) {
        PurchaseOrderTransmissionMethodDataRulesServiceImpl purchaseOrderTransmissionMethodDataRulesServiceImpl = SpringContext.getBean(PurchaseOrderTransmissionMethodDataRulesServiceImpl.class);
        PurchasingDocumentBase purapDocument = (PurchasingDocumentBase) document;
        String poTransMethodCode = purapDocument.getPurchaseOrderTransmissionMethodCode();
        if (poTransMethodCode != null && !StringUtils.isBlank(poTransMethodCode)) {
            if (poTransMethodCode.equals(PurapConstants.POTransmissionMethods.FAX)) {
                dataExists = purchaseOrderTransmissionMethodDataRulesServiceImpl.isFaxNumberValid(purapDocument.getVendorFaxNumber());
                if (!dataExists) {
                    errorMap.putError(VendorPropertyConstants.VENDOR_FAX_NUMBER, CUPurapKeyConstants.PURAP_MOPOT_REQUIRED_DATA_MISSING);
                }
            } else if (poTransMethodCode.equals(CUPurapConstants.POTransmissionMethods.EMAIL)) {
                dataExists = purchaseOrderTransmissionMethodDataRulesServiceImpl.isEmailAddressValid(purapDocument.getVendorEmailAddress());
                if (!dataExists) {
                    errorMap.putError("vendorEmailAddress", CUPurapKeyConstants.PURAP_MOPOT_REQUIRED_DATA_MISSING);
                }
            } else if (poTransMethodCode.equals(CUPurapConstants.POTransmissionMethods.MANUAL)) {
                dataExists = purchaseOrderTransmissionMethodDataRulesServiceImpl.isPostalAddressValid(purapDocument.getVendorLine1Address(), purapDocument.getVendorCityName(), purapDocument.getVendorStateCode(), purapDocument.getVendorPostalCode(), purapDocument.getVendorCountryCode());
                if (!dataExists) {
                    errorMap.putError(VendorPropertyConstants.VENDOR_ADDRESS_LINE_1, CUPurapKeyConstants.PURAP_MOPOT_REQUIRED_DATA_MISSING);
                }
            }
        }
    }
    return dataExists;
}
Also used : RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) PurchaseOrderTransmissionMethodDataRulesServiceImpl(edu.cornell.kfs.module.purap.document.service.impl.PurchaseOrderTransmissionMethodDataRulesServiceImpl) MessageMap(org.kuali.kfs.krad.util.MessageMap) PurchasingDocumentBase(org.kuali.kfs.module.purap.document.PurchasingDocumentBase)

Example 5 with PurchaseOrderAmendmentDocument

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

the class PurchasingActionBase method doDistribution.

/**
 * Distribute accounting line(s) to the item(s). Does not distribute the accounting line(s) to an item if there are already
 * accounting lines associated with that item, if the item is a below-the-line item and has no unit cost, or if the item is
 * inactive. Distribute commodity code to the item(s). Does not distribute the commodity code to an item if the item is not
 * above the line item, is inactive or if the commodity code fails the validation (i.e. inactive commodity code or non existence
 * commodity code).
 *
 * @param mapping An ActionMapping
 * @param form An ActionForm
 * @param request The HttpServletRequest
 * @param response The HttpServletResponse
 * @return An ActionForward
 * @throws Exception
 */
public ActionForward doDistribution(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
    boolean needToDistributeCommodityCode = false;
    if (StringUtils.isNotBlank(purchasingForm.getDistributePurchasingCommodityCode())) {
        // Do the logic for distributing purchasing commodity code to all the items.
        needToDistributeCommodityCode = true;
    }
    boolean needToDistributeAccount = false;
    List<PurApAccountingLine> distributionsourceAccountingLines = purchasingForm.getAccountDistributionsourceAccountingLines();
    if (distributionsourceAccountingLines.size() > 0) {
        needToDistributeAccount = true;
    }
    if (needToDistributeAccount || needToDistributeCommodityCode) {
        PurchasingAccountsPayableDocumentBase purApDocument = (PurchasingAccountsPayableDocumentBase) purchasingForm.getDocument();
        boolean institutionNeedsDistributeAccountValidation = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.VALIDATE_ACCOUNT_DISTRIBUTION_IND);
        boolean foundAccountDistributionError = false;
        boolean foundCommodityCodeDistributionError = false;
        boolean performedAccountDistribution = false;
        boolean performedCommodityCodeDistribution = false;
        // do check for account percents only if distribution method not equal to "P"
        if (!PurapConstants.AccountDistributionMethodCodes.PROPORTIONAL_CODE.equalsIgnoreCase(purApDocument.getAccountDistributionMethod())) {
            // the total percentage in the distribute account list does not equal 100 % then we should display error
            if (institutionNeedsDistributeAccountValidation && needToDistributeAccount && purchasingForm.getTotalPercentageOfAccountDistributionsourceAccountingLines().compareTo(new BigDecimal(100)) != 0) {
                GlobalVariables.getMessageMap().putError(PurapConstants.ACCOUNT_DISTRIBUTION_ERROR_KEY, PurapKeyConstants.ERROR_DISTRIBUTE_ACCOUNTS_NOT_100_PERCENT);
                foundAccountDistributionError = true;
            }
        }
        // there is a validation error in the accounts to distribute then we should display an error
        if (institutionNeedsDistributeAccountValidation && needToDistributeAccount && (validateDistributeAccounts(purchasingForm.getDocument(), distributionsourceAccountingLines) == false)) {
            foundAccountDistributionError = true;
        }
        for (PurApItem item : ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItems()) {
            boolean itemIsActive = true;
            if (item instanceof PurchaseOrderItem) {
                // if item is PO item... only validate active items
                itemIsActive = ((PurchaseOrderItem) item).isItemActiveIndicator();
            }
            if (needToDistributeCommodityCode) {
                // only the above the line items need the commodity code.
                if (item.getItemType().isLineItemIndicator() && StringUtils.isBlank(((PurchasingItemBase) item).getPurchasingCommodityCode()) && itemIsActive) {
                    // Ideally we should invoke rules to check whether the commodity code is valid (active, not restricted,
                    // not missing, etc), probably somewhere here or invoke the rule class from here.
                    boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new AttributedCommodityCodesForDistributionEvent("", purchasingForm.getDocument(), purchasingForm.getDistributePurchasingCommodityCode()));
                    if (rulePassed) {
                        ((PurchasingItemBase) item).setPurchasingCommodityCode(purchasingForm.getDistributePurchasingCommodityCode());
                        performedCommodityCodeDistribution = true;
                    } else {
                        foundCommodityCodeDistributionError = true;
                    }
                } else if (item.getItemType().isLineItemIndicator() && !StringUtils.isBlank(((PurchasingItemBase) item).getPurchasingCommodityCode()) && itemIsActive) {
                    // could not apply to line, as it wasn't blank
                    foundCommodityCodeDistributionError = true;
                }
            }
            if (needToDistributeAccount && !foundAccountDistributionError) {
                BigDecimal zero = new BigDecimal(0);
                // We should be distributing accounting lines to above the line items all the time;
                // but only to the below the line items when there is a unit cost.
                boolean unitCostNotZeroForBelowLineItems = item.getItemType().isLineItemIndicator() ? true : item.getItemUnitPrice() != null && zero.compareTo(item.getItemUnitPrice()) < 0;
                Document document = ((PurchasingFormBase) form).getDocument();
                Class clazz = document instanceof PurchaseOrderAmendmentDocument ? PurchaseOrderDocument.class : document.getClass();
                List<String> typesNotAllowingEdit = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(clazz, PurapParameterConstants.PURAP_ITEM_TYPES_RESTRICTING_ACCOUNT_EDIT));
                boolean itemOnExcludeList = (typesNotAllowingEdit == null) ? false : typesNotAllowingEdit.contains(item.getItemTypeCode());
                if (item.getSourceAccountingLines().size() == 0 && unitCostNotZeroForBelowLineItems && !itemOnExcludeList && itemIsActive) {
                    for (PurApAccountingLine purApAccountingLine : distributionsourceAccountingLines) {
                        item.getSourceAccountingLines().add((PurApAccountingLine) ObjectUtils.deepCopy(purApAccountingLine));
                    }
                    performedAccountDistribution = true;
                }
            }
        }
        if ((needToDistributeCommodityCode && performedCommodityCodeDistribution && !foundCommodityCodeDistributionError) || (needToDistributeAccount && performedAccountDistribution && !foundAccountDistributionError)) {
            if (needToDistributeCommodityCode && !foundCommodityCodeDistributionError && performedCommodityCodeDistribution) {
                KNSGlobalVariables.getMessageList().add(PurapKeyConstants.PUR_COMMODITY_CODE_DISTRIBUTED);
                purchasingForm.setDistributePurchasingCommodityCode(null);
            }
            if (needToDistributeAccount && !foundAccountDistributionError && performedAccountDistribution) {
                KNSGlobalVariables.getMessageList().add(PurapKeyConstants.PURAP_GENERAL_ACCOUNTS_DISTRIBUTED);
                distributionsourceAccountingLines.clear();
            }
            purchasingForm.setHideDistributeAccounts(true);
        }
        if ((needToDistributeAccount && !performedAccountDistribution && foundAccountDistributionError)) {
            GlobalVariables.getMessageMap().putError(PurapConstants.ACCOUNT_DISTRIBUTION_ERROR_KEY, PurapKeyConstants.PURAP_GENERAL_NO_ITEMS_TO_DISTRIBUTE_TO, "account numbers");
        }
        if (needToDistributeCommodityCode && !performedCommodityCodeDistribution && foundCommodityCodeDistributionError) {
            GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_PURCHASING_COMMODITY_CODE, PurapKeyConstants.PURAP_GENERAL_NO_ITEMS_TO_DISTRIBUTE_TO, "commodity codes");
        }
    } else {
        GlobalVariables.getMessageMap().putError(PurapConstants.ACCOUNT_DISTRIBUTION_ERROR_KEY, PurapKeyConstants.PURAP_GENERAL_NO_ACCOUNTS_TO_DISTRIBUTE);
    }
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) PurchasingAccountsPayableDocumentBase(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocumentBase) KfsParameterConstants(org.kuali.kfs.sys.service.impl.KfsParameterConstants) ArrayList(java.util.ArrayList) PurApArrayList(org.kuali.kfs.module.purap.util.PurApArrayList) WorkflowDocument(org.kuali.rice.kew.api.WorkflowDocument) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) PurchasingDocument(org.kuali.kfs.module.purap.document.PurchasingDocument) Document(org.kuali.kfs.krad.document.Document) PurchasingAccountsPayableDocument(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument) BigDecimal(java.math.BigDecimal) PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) KualiRuleService(org.kuali.kfs.krad.service.KualiRuleService) PurchasingItemBase(org.kuali.kfs.module.purap.businessobject.PurchasingItemBase) AttributedCommodityCodesForDistributionEvent(org.kuali.kfs.module.purap.document.validation.event.AttributedCommodityCodesForDistributionEvent) PurchasingAccountsPayableDocument(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument)

Aggregations

PurchaseOrderAmendmentDocument (org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument)8 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)5 MessageMap (org.kuali.kfs.krad.util.MessageMap)3 PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)3 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)3 PurchasingDocument (org.kuali.kfs.module.purap.document.PurchasingDocument)3 Map (java.util.Map)2 Note (org.kuali.kfs.krad.bo.Note)2 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)2 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)2 PurchasingAccountsPayableDocument (org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument)2 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)2 WorkflowDocument (org.kuali.rice.kew.api.WorkflowDocument)2 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)2 CuPurchaseOrderAmendmentDocument (edu.cornell.kfs.module.purap.document.CuPurchaseOrderAmendmentDocument)1 PurchaseOrderTransmissionMethodDataRulesServiceImpl (edu.cornell.kfs.module.purap.document.service.impl.PurchaseOrderTransmissionMethodDataRulesServiceImpl)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)1 MaintenanceDocument (org.kuali.kfs.kns.document.MaintenanceDocument)1