Search in sources :

Example 51 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CuElectronicInvoiceHelperServiceImpl method processAboveTheLineItem.

@Override
protected void processAboveTheLineItem(PaymentRequestItem purapItem, ElectronicInvoiceOrderHolder orderHolder) {
    LOG.info("Processing above the line item");
    ElectronicInvoiceItemHolder itemHolder = orderHolder.getItemByLineNumber(purapItem.getItemLineNumber().intValue());
    // KFSPTS-1719 : investigation
    if (((CuElectronicInvoiceOrderHolder) orderHolder).getMisMatchItem() != null) {
        itemHolder = ((CuElectronicInvoiceOrderHolder) orderHolder).getMisMatchItem();
    }
    if (itemHolder == null) {
        LOG.info("Electronic Invoice does not have item with Ref Item Line number " + purapItem.getItemLineNumber());
        return;
    }
    purapItem.setItemUnitPrice(itemHolder.getInvoiceItemUnitPrice());
    purapItem.setItemQuantity(new KualiDecimal(itemHolder.getInvoiceItemQuantity()));
    purapItem.setItemTaxAmount(new KualiDecimal(itemHolder.getTaxAmount()));
    purapItem.setItemCatalogNumber(itemHolder.getInvoiceItemCatalogNumber());
    purapItem.setItemDescription(itemHolder.getInvoiceItemDescription());
    // KFSUPGRADE-478
    if (itemHolder.getSubTotalAmount() != null) {
        purapItem.setExtendedPrice(itemHolder.getSubTotalAmount());
    } else {
        if (purapItem.getItemQuantity() != null) {
            LOG.info("Item number " + purapItem.getItemLineNumber() + " needs calculation of extended " + "price from quantity " + purapItem.getItemQuantity() + " and unit cost " + purapItem.getItemUnitPrice());
            purapItem.setExtendedPrice(purapItem.getItemQuantity().multiply(new KualiDecimal(purapItem.getItemUnitPrice())));
        } else {
            LOG.info("Item number " + purapItem.getItemLineNumber() + " has no quantity so extended price " + "equals unit price of " + purapItem.getItemUnitPrice());
            purapItem.setExtendedPrice(new KualiDecimal(purapItem.getItemUnitPrice()));
        }
    }
}
Also used : ElectronicInvoiceItemHolder(org.kuali.kfs.module.purap.service.impl.ElectronicInvoiceItemHolder) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Example 52 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CuPurapGeneralLedgerServiceImpl method reencumberEncumbrance.

@Override
protected List<SourceAccountingLine> reencumberEncumbrance(PaymentRequestDocument preq) {
    LOG.debug("reencumberEncumbrance() started");
    PurchaseOrderDocument po = purchaseOrderService.getCurrentPurchaseOrder(preq.getPurchaseOrderIdentifier());
    Map encumbranceAccountMap = new HashMap();
    // Get each item one by one
    for (Iterator items = preq.getItems().iterator(); items.hasNext(); ) {
        PaymentRequestItem payRequestItem = (PaymentRequestItem) items.next();
        PurchaseOrderItem poItem = getPoItem(po, payRequestItem.getItemLineNumber(), payRequestItem.getItemType());
        // Amount to reencumber for this item
        KualiDecimal itemReEncumber = null;
        String logItmNbr = "Item # " + payRequestItem.getItemLineNumber();
        if (LOG.isDebugEnabled()) {
            LOG.debug("reencumberEncumbrance() " + logItmNbr);
        }
        // If there isn't a PO item or the total amount is 0, we don't need encumbrances
        final KualiDecimal preqItemTotalAmount = (payRequestItem.getTotalAmount() == null) ? KualiDecimal.ZERO : payRequestItem.getTotalAmount();
        if ((poItem == null) || (preqItemTotalAmount.doubleValue() == 0)) {
            if (poItem != null) {
                // KFSUPGRADE-893 recumber $0 item too
                if (poItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance based on quantity");
                    }
                    // Do disencumbrance calculations based on quantity
                    KualiDecimal preqQuantity = payRequestItem.getItemQuantity() == null ? ZERO : payRequestItem.getItemQuantity();
                    KualiDecimal outstandingEncumberedQuantity = poItem.getItemOutstandingEncumberedQuantity() == null ? ZERO : poItem.getItemOutstandingEncumberedQuantity();
                    KualiDecimal invoicedTotal = poItem.getItemInvoicedTotalQuantity() == null ? ZERO : poItem.getItemInvoicedTotalQuantity();
                    poItem.setItemInvoicedTotalQuantity(invoicedTotal.subtract(preqQuantity));
                    poItem.setItemOutstandingEncumberedQuantity(outstandingEncumberedQuantity.add(preqQuantity));
                }
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " No encumbrances required");
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance GL entries");
            }
            // Do we calculate the encumbrance amount based on quantity or amount?
            if (poItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance based on quantity");
                }
                // Do disencumbrance calculations based on quantity
                KualiDecimal preqQuantity = payRequestItem.getItemQuantity() == null ? ZERO : payRequestItem.getItemQuantity();
                KualiDecimal outstandingEncumberedQuantity = poItem.getItemOutstandingEncumberedQuantity() == null ? ZERO : poItem.getItemOutstandingEncumberedQuantity();
                KualiDecimal invoicedTotal = poItem.getItemInvoicedTotalQuantity() == null ? ZERO : poItem.getItemInvoicedTotalQuantity();
                poItem.setItemInvoicedTotalQuantity(invoicedTotal.subtract(preqQuantity));
                poItem.setItemOutstandingEncumberedQuantity(outstandingEncumberedQuantity.add(preqQuantity));
                // do math as big decimal as doing it as a KualiDecimal will cause the item price to round to 2 digits
                itemReEncumber = new KualiDecimal(preqQuantity.bigDecimalValue().multiply(poItem.getItemUnitPrice()));
                // add tax for encumbrance
                KualiDecimal itemTaxAmount = poItem.getItemTaxAmount() == null ? ZERO : poItem.getItemTaxAmount();
                KualiDecimal encumbranceTaxAmount = preqQuantity.divide(poItem.getItemQuantity()).multiply(itemTaxAmount);
                itemReEncumber = itemReEncumber.add(encumbranceTaxAmount);
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance based on amount");
                }
                itemReEncumber = preqItemTotalAmount;
                // this prevents negative encumbrance
                if ((poItem.getTotalAmount() != null) && (poItem.getTotalAmount().bigDecimalValue().signum() < 0)) {
                    // po item extended cost is negative
                    if ((poItem.getTotalAmount().compareTo(itemReEncumber)) > 0) {
                        itemReEncumber = poItem.getTotalAmount();
                    }
                } else if ((poItem.getTotalAmount() != null) && (poItem.getTotalAmount().bigDecimalValue().signum() >= 0)) {
                    // po item extended cost is positive
                    if ((poItem.getTotalAmount().compareTo(itemReEncumber)) < 0) {
                        itemReEncumber = poItem.getTotalAmount();
                    }
                }
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " Amount to reencumber: " + itemReEncumber);
            }
            KualiDecimal outstandingEncumberedAmount = poItem.getItemOutstandingEncumberedAmount() == null ? ZERO : poItem.getItemOutstandingEncumberedAmount();
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " PO Item Outstanding Encumbrance Amount set to: " + outstandingEncumberedAmount);
            }
            KualiDecimal newOutstandingEncumberedAmount = outstandingEncumberedAmount.add(itemReEncumber);
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " New PO Item Outstanding Encumbrance Amount to set: " + newOutstandingEncumberedAmount);
            }
            poItem.setItemOutstandingEncumberedAmount(newOutstandingEncumberedAmount);
            KualiDecimal invoicedTotalAmount = poItem.getItemInvoicedTotalAmount() == null ? ZERO : poItem.getItemInvoicedTotalAmount();
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " PO Item Invoiced Total Amount set to: " + invoicedTotalAmount);
            }
            KualiDecimal newInvoicedTotalAmount = invoicedTotalAmount.subtract(preqItemTotalAmount);
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " New PO Item Invoiced Total Amount to set: " + newInvoicedTotalAmount);
            }
            poItem.setItemInvoicedTotalAmount(newInvoicedTotalAmount);
            // make the list of accounts for the reencumbrance entry
            PurchaseOrderAccount lastAccount = null;
            KualiDecimal accountTotal = ZERO;
            // Sort accounts
            Collections.sort((List) poItem.getSourceAccountingLines());
            for (Iterator accountIter = poItem.getSourceAccountingLines().iterator(); accountIter.hasNext(); ) {
                PurchaseOrderAccount account = (PurchaseOrderAccount) accountIter.next();
                if (!account.isEmpty()) {
                    SourceAccountingLine acctString = account.generateSourceAccountingLine();
                    // amount = item reencumber * account percent / 100
                    KualiDecimal reencumbranceAmount = itemReEncumber.multiply(new KualiDecimal(account.getAccountLinePercent().toString())).divide(HUNDRED);
                    account.setItemAccountOutstandingEncumbranceAmount(account.getItemAccountOutstandingEncumbranceAmount().add(reencumbranceAmount));
                    // For rounding check at the end
                    accountTotal = accountTotal.add(reencumbranceAmount);
                    lastAccount = account;
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("reencumberEncumbrance() " + logItmNbr + " " + acctString + " = " + reencumbranceAmount);
                    }
                    if (encumbranceAccountMap.containsKey(acctString)) {
                        KualiDecimal currentAmount = (KualiDecimal) encumbranceAccountMap.get(acctString);
                        encumbranceAccountMap.put(acctString, reencumbranceAmount.add(currentAmount));
                    } else {
                        encumbranceAccountMap.put(acctString, reencumbranceAmount);
                    }
                }
            }
            // account for rounding by adjusting last account as needed
            if (lastAccount != null) {
                KualiDecimal difference = itemReEncumber.subtract(accountTotal);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("reencumberEncumbrance() difference: " + logItmNbr + " " + difference);
                }
                SourceAccountingLine acctString = lastAccount.generateSourceAccountingLine();
                KualiDecimal amount = (KualiDecimal) encumbranceAccountMap.get(acctString);
                if (amount == null) {
                    encumbranceAccountMap.put(acctString, difference);
                } else {
                    encumbranceAccountMap.put(acctString, amount.add(difference));
                }
                lastAccount.setItemAccountOutstandingEncumbranceAmount(lastAccount.getItemAccountOutstandingEncumbranceAmount().add(difference));
            }
        }
    }
    SpringContext.getBean(BusinessObjectService.class).save(po);
    List<SourceAccountingLine> encumbranceAccounts = new ArrayList<SourceAccountingLine>();
    for (Iterator<SourceAccountingLine> iter = encumbranceAccountMap.keySet().iterator(); iter.hasNext(); ) {
        SourceAccountingLine acctString = iter.next();
        KualiDecimal amount = (KualiDecimal) encumbranceAccountMap.get(acctString);
        if (amount.doubleValue() != 0) {
            acctString.setAmount(amount);
            encumbranceAccounts.add(acctString);
        }
    }
    return encumbranceAccounts;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) PaymentRequestItem(org.kuali.kfs.module.purap.businessobject.PaymentRequestItem) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) Iterator(java.util.Iterator) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) HashMap(java.util.HashMap) Map(java.util.Map) PurchaseOrderAccount(org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount)

Example 53 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CuPurapGeneralLedgerServiceImpl method generateEntriesPaymentRequest.

protected boolean generateEntriesPaymentRequest(PaymentRequestDocument preq, List encumbrances, List summaryAccounts, String processType) {
    LOG.debug("generateEntriesPaymentRequest() started");
    boolean success = true;
    preq.setGeneralLedgerPendingEntries(new ArrayList());
    /*
         * Can't let generalLedgerPendingEntryService just create all the entries because we need the sequenceHelper to carry over
         * from the encumbrances to the actuals and also because we need to tell the PaymentRequestDocumentRule customize entry
         * method how to customize differently based on if creating an encumbrance or actual.
         */
    GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper(getNextAvailableSequence(preq.getDocumentNumber()));
    // when cancelling a PREQ, do not book encumbrances if PO is CLOSED
    if (encumbrances != null && !(CANCEL_PAYMENT_REQUEST.equals(processType) && PurchaseOrderStatuses.APPDOC_CLOSED.equals(preq.getPurchaseOrderDocument().getApplicationDocumentStatus()))) {
        LOG.debug("generateEntriesPaymentRequest() generate encumbrance entries");
        if (CREATE_PAYMENT_REQUEST.equals(processType)) {
            // on create, use CREDIT code for encumbrances
            preq.setDebitCreditCodeForGLEntries(GL_CREDIT_CODE);
        } else if (CANCEL_PAYMENT_REQUEST.equals(processType)) {
            // on cancel, use DEBIT code
            preq.setDebitCreditCodeForGLEntries(GL_DEBIT_CODE);
        }
        preq.setGenerateEncumbranceEntries(true);
        for (Iterator iter = encumbrances.iterator(); iter.hasNext(); ) {
            AccountingLine accountingLine = (AccountingLine) iter.next();
            preq.generateGeneralLedgerPendingEntries(accountingLine, sequenceHelper);
            // increment for the next line
            sequenceHelper.increment();
        }
    }
    if (ObjectUtils.isNotNull(summaryAccounts) && !summaryAccounts.isEmpty()) {
        LOG.debug("generateEntriesPaymentRequest() now book the actuals");
        preq.setGenerateEncumbranceEntries(false);
        if (CREATE_PAYMENT_REQUEST.equals(processType) || MODIFY_PAYMENT_REQUEST.equals(processType)) {
            // on create and modify, use DEBIT code
            preq.setDebitCreditCodeForGLEntries(GL_DEBIT_CODE);
        } else if (CANCEL_PAYMENT_REQUEST.equals(processType)) {
            // on cancel, use CREDIT code
            preq.setDebitCreditCodeForGLEntries(GL_CREDIT_CODE);
        }
        for (Iterator iter = summaryAccounts.iterator(); iter.hasNext(); ) {
            SummaryAccount summaryAccount = (SummaryAccount) iter.next();
            preq.generateGeneralLedgerPendingEntries(summaryAccount.getAccount(), sequenceHelper);
            // increment for the next line
            sequenceHelper.increment();
        }
        // generate offset accounts for use tax if it exists (useTaxContainers will be empty if not a use tax document)
        List<UseTaxContainer> useTaxContainers = SpringContext.getBean(PurapAccountingService.class).generateUseTaxAccount(preq);
        for (UseTaxContainer useTaxContainer : useTaxContainers) {
            PurApItemUseTax offset = useTaxContainer.getUseTax();
            List<SourceAccountingLine> accounts = useTaxContainer.getAccounts();
            for (SourceAccountingLine sourceAccountingLine : accounts) {
                preq.generateGeneralLedgerPendingEntries(sourceAccountingLine, sequenceHelper, useTaxContainer.getUseTax());
                // increment for the next line
                sequenceHelper.increment();
            }
        }
        // Manually save preq summary accounts
        if (MODIFY_PAYMENT_REQUEST.equals(processType)) {
            // for modify, regenerate the summary from the doc
            List<SummaryAccount> summaryAccountsForModify = SpringContext.getBean(PurapAccountingService.class).generateSummaryAccountsWithNoZeroTotalsNoUseTax(preq);
            saveAccountsPayableSummaryAccounts(summaryAccountsForModify, preq.getPurapDocumentIdentifier(), PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT);
        } else {
            // for create and cancel, use the summary accounts
            saveAccountsPayableSummaryAccounts(summaryAccounts, preq.getPurapDocumentIdentifier(), PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT);
        }
        // manually save cm account change tables (CAMS needs this)
        if (CREATE_PAYMENT_REQUEST.equals(processType) || MODIFY_PAYMENT_REQUEST.equals(processType)) {
            SpringContext.getBean(PurapAccountRevisionService.class).savePaymentRequestAccountRevisions(preq.getItems(), preq.getPostingYearFromPendingGLEntries(), preq.getPostingPeriodCodeFromPendingGLEntries());
        } else if (CANCEL_PAYMENT_REQUEST.equals(processType)) {
            SpringContext.getBean(PurapAccountRevisionService.class).cancelPaymentRequestAccountRevisions(preq.getItems(), preq.getPostingYearFromPendingGLEntries(), preq.getPostingPeriodCodeFromPendingGLEntries());
        }
        // we would only want to do this when booking the actuals (not the encumbrances)
        if (preq.getGeneralLedgerPendingEntries() == null || preq.getGeneralLedgerPendingEntries().size() < 2) {
            LOG.warn("No gl entries for accounting lines.");
        } else {
            // upon create, build the entries normally
            if (CREATE_PAYMENT_REQUEST.equals(processType)) {
                getPaymentMethodGeneralLedgerPendingEntryService().generatePaymentMethodSpecificDocumentGeneralLedgerPendingEntries(preq, ((CuPaymentRequestDocument) preq).getPaymentMethodCode(), preq.getBankCode(), KRADConstants.DOCUMENT_PROPERTY_NAME + "." + "bankCode", preq.getGeneralLedgerPendingEntry(0), false, false, sequenceHelper);
            } else if (MODIFY_PAYMENT_REQUEST.equals(processType)) {
                // upon modify, we need to calculate the deltas here and pass them in so the appropriate adjustments are created
                KualiDecimal bankOffsetAmount = KualiDecimal.ZERO;
                Map<String, KualiDecimal> changesByChart = new HashMap<String, KualiDecimal>();
                if (ObjectUtils.isNotNull(summaryAccounts) && !summaryAccounts.isEmpty()) {
                    for (SummaryAccount a : (List<SummaryAccount>) summaryAccounts) {
                        bankOffsetAmount = bankOffsetAmount.add(a.getAccount().getAmount());
                        if (changesByChart.get(a.getAccount().getChartOfAccountsCode()) == null) {
                            changesByChart.put(a.getAccount().getChartOfAccountsCode(), a.getAccount().getAmount());
                        } else {
                            changesByChart.put(a.getAccount().getChartOfAccountsCode(), changesByChart.get(a.getAccount().getChartOfAccountsCode()).add(a.getAccount().getAmount()));
                        }
                    }
                }
                getPaymentMethodGeneralLedgerPendingEntryService().generatePaymentMethodSpecificDocumentGeneralLedgerPendingEntries(preq, ((CuPaymentRequestDocument) preq).getPaymentMethodCode(), preq.getBankCode(), KRADConstants.DOCUMENT_PROPERTY_NAME + "." + "bankCode", preq.getGeneralLedgerPendingEntry(0), true, false, sequenceHelper, bankOffsetAmount, changesByChart);
            }
        }
        preq.generateDocumentGeneralLedgerPendingEntries(sequenceHelper);
    // END MOD
    }
    // Manually save GL entries for Payment Request and encumbrances
    saveGLEntries(preq.getGeneralLedgerPendingEntries());
    return success;
}
Also used : SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) AccountingLine(org.kuali.kfs.sys.businessobject.AccountingLine) UseTaxContainer(org.kuali.kfs.module.purap.util.UseTaxContainer) PurApItemUseTax(org.kuali.kfs.module.purap.businessobject.PurApItemUseTax) ArrayList(java.util.ArrayList) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) PurapAccountingService(org.kuali.kfs.module.purap.service.PurapAccountingService) GeneralLedgerPendingEntrySequenceHelper(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper) PurapAccountRevisionService(org.kuali.kfs.module.purap.service.PurapAccountRevisionService) SummaryAccount(org.kuali.kfs.module.purap.util.SummaryAccount) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument) Iterator(java.util.Iterator) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) HashMap(java.util.HashMap) Map(java.util.Map)

Example 54 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CuPurapAccountingServiceImpl method updatePreqAccountAmountsOnly.

/*
     * the calculation is based on the percentage of new total amount divided by the existing item totals.
     * The calculated percentage is high precision (20 decimal digits).
     * Then this calculated percentage is used to update each accounting line amount accordingly.
     */
private <T extends PurApAccountingLine> void updatePreqAccountAmountsOnly(List<T> sourceAccountingLines, KualiDecimal totalAmount) {
    if ((totalAmount != null) && KualiDecimal.ZERO.compareTo(totalAmount) != 0) {
        KualiDecimal accountTotal = getItemAccountTotal((List<PurApAccountingLine>) sourceAccountingLines);
        if ((!accountTotal.equals(totalAmount) || isAnyAccountLinePercentEmpty((List<PurApAccountingLine>) sourceAccountingLines)) && !accountTotal.equals(KualiDecimal.ZERO)) {
            BigDecimal tmpPercent = totalAmount.bigDecimalValue().divide(accountTotal.bigDecimalValue(), PurapConstants.CREDITMEMO_PRORATION_SCALE.intValue(), KualiDecimal.ROUND_BEHAVIOR);
            int accountNum = 0;
            accountTotal = KualiDecimal.ZERO;
            BigDecimal percentTotalRoundUp = BigDecimal.ZERO;
            for (T account : sourceAccountingLines) {
                if (accountNum++ < sourceAccountingLines.size() - 1) {
                    if (ObjectUtils.isNotNull(account.getAmount())) {
                        BigDecimal calcAmountBd = tmpPercent.multiply(account.getAmount().bigDecimalValue());
                        calcAmountBd = calcAmountBd.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR);
                        KualiDecimal calcAmount = new KualiDecimal(calcAmountBd);
                        account.setAmount(calcAmount);
                        if (ObjectUtils.isNull(account.getAccountLinePercent()) || account.getAccountLinePercent().compareTo(BigDecimal.ZERO) == 0) {
                            // Tax Item is regenerated if Treasury Manager 'calculate'
                            BigDecimal tmpAcctPercent = account.getAmount().bigDecimalValue().divide(totalAmount.bigDecimalValue(), PurapConstants.CREDITMEMO_PRORATION_SCALE.intValue(), KualiDecimal.ROUND_BEHAVIOR);
                            account.setAccountLinePercent(tmpAcctPercent.multiply(new BigDecimal(100)));
                        }
                        accountTotal = accountTotal.add(calcAmount);
                    }
                } else {
                    account.setAmount(totalAmount.subtract(accountTotal));
                    if (ObjectUtils.isNull(account.getAccountLinePercent()) || account.getAccountLinePercent().compareTo(BigDecimal.ZERO) == 0) {
                        account.setAccountLinePercent(new BigDecimal(100).subtract(percentTotalRoundUp));
                    }
                }
                percentTotalRoundUp = percentTotalRoundUp.add(account.getAccountLinePercent());
            }
        }
    } else {
        for (T account : sourceAccountingLines) {
            account.setAmount(KualiDecimal.ZERO);
        }
    }
}
Also used : PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) List(java.util.List) BigDecimal(java.math.BigDecimal)

Example 55 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CuPurapAccountingServiceImpl method updatePreqItemAccountAmountsOnly.

/*
     * Updates PREQ accounting line amounts only when Treasury Manager is doing 'calculate'.
     * Currently, the foundation 'updateAccountAmounts' is based on the saved accounting line percentage which is rounded to 2 decimal digits.
     * If the total amount is changed by Treasury Manager, and the calculation is based on 'percentage' saved, then it will cause some amount fraction rounding issue.
     * This is reported in KFSPTS-3644.  You can see the detail explanation of the rounding issues.
     */
private void updatePreqItemAccountAmountsOnly(PurApItem item) {
    List<PurApAccountingLine> sourceAccountingLines = item.getSourceAccountingLines();
    KualiDecimal totalAmount = item.getTotalAmount();
    if (ObjectUtils.isNull(totalAmount) || totalAmount.equals(KualiDecimal.ZERO)) {
        totalAmount = getExtendedPrice(item);
    }
    if (!totalAmount.equals(KualiDecimal.ZERO) && getItemAccountTotal(sourceAccountingLines).equals(KualiDecimal.ZERO)) {
        // item.refreshReferenceObject("sourceAccountingLines"); // this is not working
        // The item account totals can become '0' if Treasury Manager set the unit price to '0 by accident and do calculate.
        // We need to refresh the accounting line amount from DB in order to continue.
        refreshAccountAmount(item);
    }
    if (StringUtils.equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_MISC_CODE, item.getItemTypeCode()) || StringUtils.equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE, item.getItemTypeCode()) || StringUtils.equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE, item.getItemTypeCode())) {
        if (totalAmount.isNonZero() && getItemAccountTotal(sourceAccountingLines).isZero()) {
            updateMiscFrtSphdAccountAmountsWithTotal(sourceAccountingLines, totalAmount);
        } else {
            updatePreqAccountAmountsOnly(sourceAccountingLines, totalAmount);
        }
    } else {
        updatePreqAccountAmountsOnly(sourceAccountingLines, totalAmount);
    }
}
Also used : PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Aggregations

KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)280 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)36 Test (org.junit.Test)28 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)21 BigDecimal (java.math.BigDecimal)18 List (java.util.List)18 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)15 Date (java.sql.Date)14 CapitalAssetInformation (org.kuali.kfs.fp.businessobject.CapitalAssetInformation)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 ConcurStandardAccountingExtractDetailLine (edu.cornell.kfs.concur.batch.businessobject.ConcurStandardAccountingExtractDetailLine)11 KualiInteger (org.kuali.kfs.core.api.util.type.KualiInteger)11 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)11 IOException (java.io.IOException)10 InvoiceDetailAccountObjectCode (org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)10 Map (java.util.Map)9 ParameterEvaluator (org.kuali.kfs.core.api.parameter.ParameterEvaluator)9 CapitalAccountingLines (org.kuali.kfs.fp.businessobject.CapitalAccountingLines)9 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)8