Search in sources :

Example 11 with PurApItem

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

the class PurchasingAccountsPayableDocumentBase method getTotalDollarAmountWithExclusionsSubsetItems.

/**
 * This method...
 *
 * @param excludedTypes
 * @param includeBelowTheLine
 * @param itemsForTotal
 * @return
 */
protected KualiDecimal getTotalDollarAmountWithExclusionsSubsetItems(String[] excludedTypes, boolean includeBelowTheLine, List<PurApItem> itemsForTotal) {
    if (excludedTypes == null) {
        excludedTypes = new String[] {};
    }
    KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
    for (PurApItem item : itemsForTotal) {
        item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
        ItemType it = item.getItemType();
        if ((includeBelowTheLine || it.isLineItemIndicator()) && !ArrayUtils.contains(excludedTypes, it.getItemTypeCode())) {
            KualiDecimal totalAmount = item.getTotalAmount();
            KualiDecimal itemTotal = (totalAmount != null) ? totalAmount : KualiDecimal.ZERO;
            total = total.add(itemTotal);
        }
    }
    return total;
}
Also used : PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) ItemType(org.kuali.kfs.module.purap.businessobject.ItemType) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal)

Example 12 with PurApItem

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

the class PurchasingAccountsPayableDocumentBase method refreshNonUpdateableReferences.

@Override
public void refreshNonUpdateableReferences() {
    super.refreshNonUpdateableReferences();
    for (PurApItem item : (List<PurApItem>) this.getItems()) {
        // refresh the accounts if they do exist...
        for (PurApAccountingLine account : item.getSourceAccountingLines()) {
            account.refreshNonUpdateableReferences();
        }
    }
    fixItemReferences();
}
Also used : PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) List(java.util.List) ArrayList(java.util.ArrayList)

Example 13 with PurApItem

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

the class PurchasingAccountsPayableDocumentBase method getSourceAccountingLinesForComparison.

/**
 * Accounting lines that are read-only should skip validation
 *
 * @see org.kuali.kfs.sys.document.AccountingDocumentBase#getSourceAccountingLinesForComparison()
 */
@SuppressWarnings("rawtypes")
@Override
protected List getSourceAccountingLinesForComparison() {
    LOG.info("Checking source accounting lines for read-only fields");
    List<String> restrictedItemTypesList = new ArrayList<String>();
    try {
        restrictedItemTypesList = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(this.getClass(), PurapParameterConstants.PURAP_ITEM_TYPES_RESTRICTING_ACCOUNT_EDIT));
    } catch (IllegalArgumentException iae) {
    // do nothing, not a problem if no restricted types are defined
    }
    PurapAccountingService purApAccountingService = SpringContext.getBean(PurapAccountingService.class);
    List currentSourceLines = new ArrayList();
    for (PurApItem item : (List<PurApItem>) this.getItems()) {
        // Disable validation if the item is read-only
        final boolean isNotReadOnly = !((restrictedItemTypesList != null) && restrictedItemTypesList.contains(item.getItemTypeCode()));
        if (isNotReadOnly) {
            currentSourceLines.addAll(item.getSourceAccountingLines());
        }
    }
    return currentSourceLines;
}
Also used : ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) PurapAccountingService(org.kuali.kfs.module.purap.service.PurapAccountingService)

Example 14 with PurApItem

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

the class PurchasingAccountsPayableDocumentBase method getIndexedErrorPathPrefix.

private String getIndexedErrorPathPrefix(String errorPathPrefix, AccountingLine currentLine) {
    int idx = 0;
    int i = 0;
    for (PurApItem item : (List<PurApItem>) this.getItems()) {
        int j = 0;
        // the error icon may be placed in wrong line.
        if (CollectionUtils.isNotEmpty(item.getSourceAccountingLines())) {
            Collections.sort(item.getSourceAccountingLines(), new PurapAccountingLineComparator());
        }
        for (PurApAccountingLine acctLine : item.getSourceAccountingLines()) {
            if (acctLine == currentLine) {
                return errorPathPrefix + i + "]." + KFSConstants.EXISTING_SOURCE_ACCT_LINE_PROPERTY_NAME + "[" + j + "]";
            } else {
                j++;
            }
        }
        i++;
    }
    return errorPathPrefix + 0 + "]." + KFSConstants.EXISTING_SOURCE_ACCT_LINE_PROPERTY_NAME + "[" + 0 + "]";
}
Also used : PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) List(java.util.List) ArrayList(java.util.ArrayList) PurapAccountingLineComparator(org.kuali.kfs.module.purap.util.PurapAccountingLineComparator)

Example 15 with PurApItem

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

the class CuPurapServiceImpl method prorateForTradeInAndFullOrderDiscount.

public void prorateForTradeInAndFullOrderDiscount(PurchasingAccountsPayableDocument purDoc) {
    if (purDoc instanceof VendorCreditMemoDocument) {
        throw new RuntimeException("This method not applicable for VCM documents");
    }
    // TODO: are we throwing sufficient errors in this method?
    PurApItem fullOrderDiscount = null;
    PurApItem tradeIn = null;
    KualiDecimal totalAmount = KualiDecimal.ZERO;
    KualiDecimal totalTaxAmount = KualiDecimal.ZERO;
    List<PurApAccountingLine> distributedAccounts = null;
    List<SourceAccountingLine> summaryAccounts = null;
    // iterate through below the line and grab FoD and TrdIn.
    for (PurApItem item : purDoc.getItems()) {
        if (item.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE)) {
            fullOrderDiscount = item;
        } else if (item.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) {
            tradeIn = item;
        }
    }
    // If Discount is not null or zero get proration list for all non misc items and set (if not empty?)
    if (fullOrderDiscount != null && fullOrderDiscount.getExtendedPrice() != null && fullOrderDiscount.getExtendedPrice().isNonZero()) {
        // empty
        KNSGlobalVariables.getMessageList().add("Full order discount accounts cleared and regenerated");
        fullOrderDiscount.getSourceAccountingLines().clear();
        // total amount is pretax dollars
        totalAmount = purDoc.getTotalDollarAmountAboveLineItems().subtract(purDoc.getTotalTaxAmountAboveLineItems());
        totalTaxAmount = purDoc.getTotalTaxAmountAboveLineItems();
        // Before we generate account summary, we should update the account amounts first.
        purapAccountingService.updateAccountAmounts(purDoc);
        // calculate tax
        boolean salesTaxInd = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.ENABLE_SALES_TAX_IND);
        boolean useTaxIndicator = purDoc.isUseTaxIndicator();
        if (salesTaxInd == true && (ObjectUtils.isNull(fullOrderDiscount.getItemTaxAmount()) && useTaxIndicator == false)) {
            KualiDecimal discountAmount = fullOrderDiscount.getExtendedPrice();
            KualiDecimal discountTaxAmount = discountAmount.divide(totalAmount).multiply(totalTaxAmount);
            fullOrderDiscount.setItemTaxAmount(discountTaxAmount);
        }
        // generate summary
        summaryAccounts = purapAccountingService.generateSummary(PurApItemUtils.getAboveTheLineOnly(purDoc.getItems()));
        if (summaryAccounts.size() == 0) {
            if (purDoc.shouldGiveErrorForEmptyAccountsProration()) {
                GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_SUMMARY_ACCOUNTS_LIST_EMPTY, "full order discount");
            }
        } else {
            // prorate accounts
            distributedAccounts = purapAccountingService.generateAccountDistributionForProration(summaryAccounts, totalAmount.add(totalTaxAmount), 2, fullOrderDiscount.getAccountingLineClass());
            for (PurApAccountingLine distributedAccount : distributedAccounts) {
                // KFSPTS-2200 : set item, so it can be verified as discount when validating
                if (distributedAccount instanceof PurApAccountingLineBase) {
                    ((PurApAccountingLineBase) distributedAccount).setDiscountTradeIn(true);
                }
                BigDecimal percent = distributedAccount.getAccountLinePercent();
                BigDecimal roundedPercent = new BigDecimal(Math.round(percent.doubleValue()));
                distributedAccount.setAccountLinePercent(roundedPercent);
            }
            // update amounts on distributed accounts
            purapAccountingService.updateAccountAmountsWithTotal(distributedAccounts, totalAmount, fullOrderDiscount.getTotalAmount());
            fullOrderDiscount.setSourceAccountingLines(distributedAccounts);
        }
    } else if (fullOrderDiscount != null && (fullOrderDiscount.getExtendedPrice() == null || fullOrderDiscount.getExtendedPrice().isZero())) {
        fullOrderDiscount.getSourceAccountingLines().clear();
    }
    // If tradeIn is not null or zero get proration list for all non misc items and set (if not empty?)
    if (tradeIn != null && tradeIn.getExtendedPrice() != null && tradeIn.getExtendedPrice().isNonZero()) {
        tradeIn.getSourceAccountingLines().clear();
        totalAmount = purDoc.getTotalDollarAmountForTradeIn();
        KualiDecimal tradeInTotalAmount = tradeIn.getTotalAmount();
        // Before we generate account summary, we should update the account amounts first.
        purapAccountingService.updateAccountAmounts(purDoc);
        // Before generating the summary, lets replace the object code in a cloned accounts collection sothat we can
        // consolidate all the modified object codes during summary generation.
        List<PurApItem> clonedTradeInItems = new ArrayList<PurApItem>();
        Collection<String> objectSubTypesRequiringQty = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.OBJECT_SUB_TYPES_REQUIRING_QUANTITY));
        Collection<String> purchasingObjectSubTypes = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(KfsParameterConstants.CAPITAL_ASSETS_BATCH.class, PurapParameterConstants.PURCHASING_OBJECT_SUB_TYPES));
        String tradeInCapitalObjectCode = SpringContext.getBean(ParameterService.class).getParameterValueAsString(PurapConstants.PURAP_NAMESPACE, "Document", "TRADE_IN_OBJECT_CODE_FOR_CAPITAL_ASSET");
        String tradeInCapitalLeaseObjCd = SpringContext.getBean(ParameterService.class).getParameterValueAsString(PurapConstants.PURAP_NAMESPACE, "Document", "TRADE_IN_OBJECT_CODE_FOR_CAPITAL_LEASE");
        for (PurApItem item : purDoc.getTradeInItems()) {
            PurApItem cloneItem = (PurApItem) ObjectUtils.deepCopy(item);
            List<PurApAccountingLine> sourceAccountingLines = cloneItem.getSourceAccountingLines();
            for (PurApAccountingLine accountingLine : sourceAccountingLines) {
                if (objectSubTypesRequiringQty.contains(accountingLine.getObjectCode().getFinancialObjectSubTypeCode())) {
                    accountingLine.setFinancialObjectCode(tradeInCapitalObjectCode);
                } else if (purchasingObjectSubTypes.contains(accountingLine.getObjectCode().getFinancialObjectSubTypeCode())) {
                    accountingLine.setFinancialObjectCode(tradeInCapitalLeaseObjCd);
                }
            }
            clonedTradeInItems.add(cloneItem);
        }
        summaryAccounts = purapAccountingService.generateSummary(clonedTradeInItems);
        if (summaryAccounts.size() == 0) {
            if (purDoc.shouldGiveErrorForEmptyAccountsProration()) {
                GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_SUMMARY_ACCOUNTS_LIST_EMPTY, "trade in");
            }
        } else {
            distributedAccounts = purapAccountingService.generateAccountDistributionForProration(summaryAccounts, totalAmount, 2, tradeIn.getAccountingLineClass());
            for (PurApAccountingLine distributedAccount : distributedAccounts) {
                // KFSPTS-2200 : set item, so it can be verified as discount when validating
                if (distributedAccount instanceof PurApAccountingLineBase) {
                    ((PurApAccountingLineBase) distributedAccount).setDiscountTradeIn(true);
                }
                BigDecimal percent = distributedAccount.getAccountLinePercent();
                BigDecimal roundedPercent = new BigDecimal(Math.round(percent.doubleValue()));
                distributedAccount.setAccountLinePercent(roundedPercent);
                // set the accountAmount same as tradeIn amount not line item's amount
                resetAccountAmount(distributedAccount, tradeInTotalAmount);
            }
            tradeIn.setSourceAccountingLines(distributedAccounts);
        }
    }
}
Also used : VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) KfsParameterConstants(org.kuali.kfs.sys.service.impl.KfsParameterConstants) ArrayList(java.util.ArrayList) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) PurApAccountingLineBase(org.kuali.kfs.module.purap.businessobject.PurApAccountingLineBase) BigDecimal(java.math.BigDecimal) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal)

Aggregations

PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)45 PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)17 ArrayList (java.util.ArrayList)15 List (java.util.List)15 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)10 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)7 PurchasingAccountsPayableDocument (org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument)5 PurchasingDocument (org.kuali.kfs.module.purap.document.PurchasingDocument)5 KualiRuleService (org.kuali.kfs.krad.service.KualiRuleService)4 ItemType (org.kuali.kfs.module.purap.businessobject.ItemType)4 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)4 PurchasingItemBase (org.kuali.kfs.module.purap.businessobject.PurchasingItemBase)4 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)4 BigDecimal (java.math.BigDecimal)3 HashSet (java.util.HashSet)3 PurApAccountingLineBase (org.kuali.kfs.module.purap.businessobject.PurApAccountingLineBase)3 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)3 PurchaseOrderAmendmentDocument (org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument)3 PurchasingAccountsPayableDocumentBase (org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocumentBase)3 WorkflowDocument (org.kuali.rice.kew.api.WorkflowDocument)3