Search in sources :

Example 11 with PurApAccountingLine

use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine in project cu-kfs by CU-CommunityApps.

the class CuPurchaseOrderAmendmentHasUnitCostAndValidPercentage method validate.

public boolean validate(AttributedDocumentEvent event) {
    boolean valid = true;
    PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) event.getDocument();
    List<PurApItem> items = purapDocument.getItems();
    for (PurApItem item : items) {
        if (item.isConsideredEntered()) {
            BigDecimal unitPrice = ((PurchaseOrderItem) item).getItemUnitPrice();
            List<PurApAccountingLine> lines = item.getSourceAccountingLines();
            // check if unit price is zero or null and item has accounts associated with it
            if ((unitPrice == null || (unitPrice.compareTo(BigDecimal.ZERO) == 0)) && lines.size() > 0) {
                GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERRORS, CUKFSKeyConstants.ERROR_NO_UNIT_COST_WITH_ACCOUNTS, item.getItemIdentifierString());
                valid = false;
            }
            if ((unitPrice != null && unitPrice.compareTo(BigDecimal.ZERO) != 0) && lines.size() == 0) {
                GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERRORS, CUKFSKeyConstants.ERROR_UNIT_COST_W_O_ACCOUNT, item.getItemIdentifierString());
                valid = false;
            }
            BigDecimal totalPercent = new BigDecimal(0);
            for (PurApAccountingLine accountingLine : lines) {
                totalPercent = totalPercent.add(accountingLine.getAccountLinePercent());
                // if an account distribution is zero percent, invalid
                if (accountingLine.getAccountLinePercent().compareTo(BigDecimal.ZERO) == 0) {
                    GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, CUKFSKeyConstants.ERROR_NO_ZERO_PERCENT_ACCOUNT_LINES_ALLOWED, item.getItemIdentifierString());
                    valid = false;
                }
            }
            // if total percent is not 100, error
            if (totalPercent.compareTo(new BigDecimal(100)) != 0) {
                // KFSPTS-1769.  if it is spawnpoa for unordered item, then don't check
                if (!((purapDocument instanceof CuPurchaseOrderAmendmentDocument) && ((CuPurchaseOrderAmendmentDocument) purapDocument).isSpawnPoa())) {
                    GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_ACCOUNTING_TOTAL, item.getItemIdentifierString());
                    valid = false;
                }
            }
        }
    }
    return valid;
}
Also used : PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) CuPurchaseOrderAmendmentDocument(edu.cornell.kfs.module.purap.document.CuPurchaseOrderAmendmentDocument) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) PurchasingAccountsPayableDocument(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument) BigDecimal(java.math.BigDecimal)

Example 12 with PurApAccountingLine

use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine in project cu-kfs by CU-CommunityApps.

the class PurchaseOrderDocument method getFirstAccount.

/**
 * Returns the first PO item's first accounting line (assuming the item list is sequentially ordered).
 *
 * @return - The first accounting line of the first PO item.
 */
protected PurApAccountingLine getFirstAccount() {
    // loop through items, and pick the first item with non-empty accounting lines
    if (getItems() != null && !getItems().isEmpty()) {
        for (Iterator iter = getItems().iterator(); iter.hasNext(); ) {
            PurchaseOrderItem item = (PurchaseOrderItem) iter.next();
            if (item.isConsideredEntered() && item.getSourceAccountingLines() != null && !item.getSourceAccountingLines().isEmpty()) {
                // accounting lines are not empty so pick the first account
                PurApAccountingLine accountingLine = item.getSourceAccountingLine(0);
                accountingLine.refreshNonUpdateableReferences();
                return accountingLine;
            }
        }
    }
    return null;
}
Also used : PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) Iterator(java.util.Iterator)

Example 13 with PurApAccountingLine

use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine in project cu-kfs by CU-CommunityApps.

the class PurchaseOrderDocument method getAccountsForAwardRouting.

public List<Account> getAccountsForAwardRouting() {
    List<Account> accounts = new ArrayList<Account>();
    ParameterService parameterService = SpringContext.getBean(ParameterService.class);
    for (PurApItem item : (List<PurApItem>) this.getItems()) {
        for (PurApAccountingLine accountingLine : item.getSourceAccountingLines()) {
            if (isObjectCodeAllowedForAwardRouting(accountingLine, parameterService)) {
                if (ObjectUtils.isNull(accountingLine.getAccount())) {
                    accountingLine.refreshReferenceObject("account");
                }
                if (accountingLine.getAccount() != null && !accounts.contains(accountingLine.getAccount())) {
                    accounts.add(accountingLine.getAccount());
                }
            }
        }
    }
    return accounts;
}
Also used : Account(org.kuali.kfs.coa.businessobject.Account) PurchaseOrderAccount(org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount) ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with PurApAccountingLine

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

Example 15 with PurApAccountingLine

use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine in project cu-kfs by CU-CommunityApps.

the class PurchasingActionBase method validateDistributeAccounts.

/**
 * Validates that the accounting lines while a distribute accounts action is being taken.
 *
 * @param document
 * @param distributionsourceAccountingLines
 * @return
 */
protected boolean validateDistributeAccounts(Document document, List<PurApAccountingLine> distributionsourceAccountingLines) {
    boolean rulePassed = true;
    String errorPrefix = null;
    int i = 0;
    for (PurApAccountingLine accountingLine : distributionsourceAccountingLines) {
        errorPrefix = "accountDistributionsourceAccountingLine" + "[" + Integer.toString(i) + "]";
        rulePassed &= SpringContext.getBean(KualiRuleService.class).applyRules(new AddAccountingLineEvent(errorPrefix, document, accountingLine));
        i++;
    }
    return rulePassed;
}
Also used : AddAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)

Aggregations

PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)27 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)17 ArrayList (java.util.ArrayList)9 List (java.util.List)7 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)7 BigDecimal (java.math.BigDecimal)6 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)5 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)5 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)4 IWantAccount (edu.cornell.kfs.module.purap.businessobject.IWantAccount)3 PurchaseOrderAmendmentDocument (org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument)3 PurchasingAccountsPayableDocument (org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument)3 KfsParameterConstants (org.kuali.kfs.sys.service.impl.KfsParameterConstants)3 WorkflowDocument (org.kuali.rice.kew.api.WorkflowDocument)3 Account (org.kuali.kfs.coa.businessobject.Account)2 KualiRuleService (org.kuali.kfs.krad.service.KualiRuleService)2 PurchasingItemBase (org.kuali.kfs.module.purap.businessobject.PurchasingItemBase)2 RequisitionAccount (org.kuali.kfs.module.purap.businessobject.RequisitionAccount)2 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)2 PurchasingAccountsPayableDocumentBase (org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocumentBase)2