Search in sources :

Example 6 with PurchaseOrderItem

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

the class CuElectronicInvoiceMatchingServiceImpl method validateUnitPrice.

protected void validateUnitPrice(ElectronicInvoiceItemHolder itemHolder) {
    PurchaseOrderCostSource costSource = itemHolder.getInvoiceOrderHolder().getPurchaseOrderDocument().getPurchaseOrderCostSource();
    PurchaseOrderItem poItem = itemHolder.getPurchaseOrderItem();
    ElectronicInvoiceOrderHolder orderHolder = itemHolder.getInvoiceOrderHolder();
    String extraDescription = "Invoice Item Line Number:" + itemHolder.getInvoiceItemLineNumber();
    BigDecimal actualVariance = itemHolder.getInvoiceItemUnitPrice().subtract(poItem.getItemUnitPrice());
    BigDecimal lowerPercentage = null;
    if (costSource.getItemUnitPriceLowerVariancePercent() != null) {
        // Checking for lower variance
        lowerPercentage = costSource.getItemUnitPriceLowerVariancePercent();
    } else {
        // If the cost source itemUnitPriceLowerVariancePercent is null then
        // we'll use the exact match (100%).
        lowerPercentage = new BigDecimal(100);
    }
    BigDecimal lowerAcceptableVariance = (lowerPercentage.divide(new BigDecimal(100))).multiply(poItem.getItemUnitPrice()).negate();
    // KFSUPGRADE-485
    if (!poItem.isNoQtyItem() && lowerAcceptableVariance.compareTo(actualVariance) > 0) {
        ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.INVOICE_AMT_LESSER_THAN_LOWER_VARIANCE, extraDescription, orderHolder.getFileName());
        orderHolder.addInvoiceOrderRejectReason(rejectReason, PurapConstants.ElectronicInvoice.RejectDocumentFields.INVOICE_ITEM_UNIT_PRICE, PurapKeyConstants.ERROR_REJECT_UNITPRICE_LOWERVARIANCE);
    }
    BigDecimal upperPercentage = null;
    if (costSource.getItemUnitPriceUpperVariancePercent() != null) {
        // Checking for upper variance
        upperPercentage = costSource.getItemUnitPriceUpperVariancePercent();
    } else {
        // If the cost source itemUnitPriceLowerVariancePercent is null then
        // we'll use the exact match (100%).
        upperPercentage = new BigDecimal(100);
    }
    BigDecimal upperAcceptableVariance = (upperPercentage.divide(new BigDecimal(100))).multiply(poItem.getItemUnitPrice());
    if (upperAcceptableVariance.compareTo(actualVariance) < 0) {
        ElectronicInvoiceRejectReason rejectReason = createRejectReason(PurapConstants.ElectronicInvoice.INVOICE_AMT_GREATER_THAN_UPPER_VARIANCE, extraDescription, orderHolder.getFileName());
        orderHolder.addInvoiceOrderRejectReason(rejectReason, PurapConstants.ElectronicInvoice.RejectDocumentFields.INVOICE_ITEM_UNIT_PRICE, PurapKeyConstants.ERROR_REJECT_UNITPRICE_UPPERVARIANCE);
    }
}
Also used : PurchaseOrderCostSource(org.kuali.kfs.vnd.businessobject.PurchaseOrderCostSource) PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) ElectronicInvoiceRejectReason(org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason) BigDecimal(java.math.BigDecimal) ElectronicInvoiceOrderHolder(org.kuali.kfs.module.purap.service.impl.ElectronicInvoiceOrderHolder)

Example 7 with PurchaseOrderItem

use of org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem 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.rice.core.api.util.type.KualiDecimal) HashMap(java.util.HashMap) Map(java.util.Map) PurchaseOrderAccount(org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount)

Example 8 with PurchaseOrderItem

use of org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem 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 9 with PurchaseOrderItem

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

the class CuPendingTransactionServiceImpl method reencumberEncumbrance.

/**
 * Re-encumber the Encumbrance on a PO based on values in a PREQ. This is used when a PREQ is cancelled. Note: This modifies the
 * encumbrance values on the PO and saves the PO
 *
 * @param preq PREQ for invoice
 * @return List of accounting lines to use to create the pending general ledger entries
 */
protected List<SourceAccountingLine> reencumberEncumbrance(PaymentRequestDocument preq) {
    LOG.debug("reencumberEncumbrance() started");
    PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).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();
        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)) {
            LOG.debug("reencumberEncumbrance() " + logItmNbr + " No encumbrances required");
        } else {
            LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance GL entries");
            // Do we calculate the encumbrance amount based on quantity or amount?
            if (poItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
                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));
                itemReEncumber = preqQuantity.multiply(new KualiDecimal(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 {
                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();
                    }
                }
            }
            LOG.debug("reencumberEncumbrance() " + logItmNbr + " Amount to reencumber: " + itemReEncumber);
            KualiDecimal outstandingEncumberedAmount = poItem.getItemOutstandingEncumberedAmount() == null ? ZERO : poItem.getItemOutstandingEncumberedAmount();
            LOG.debug("reencumberEncumbrance() " + logItmNbr + " PO Item Outstanding Encumbrance Amount set to: " + outstandingEncumberedAmount);
            KualiDecimal newOutstandingEncumberedAmount = outstandingEncumberedAmount.add(itemReEncumber);
            LOG.debug("reencumberEncumbrance() " + logItmNbr + " New PO Item Outstanding Encumbrance Amount to set: " + newOutstandingEncumberedAmount);
            poItem.setItemOutstandingEncumberedAmount(newOutstandingEncumberedAmount);
            KualiDecimal invoicedTotalAmount = poItem.getItemInvoicedTotalAmount() == null ? ZERO : poItem.getItemInvoicedTotalAmount();
            LOG.debug("reencumberEncumbrance() " + logItmNbr + " PO Item Invoiced Total Amount set to: " + invoicedTotalAmount);
            KualiDecimal newInvoicedTotalAmount = invoicedTotalAmount.subtract(preqItemTotalAmount);
            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;
                    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);
                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));
            }
        }
    }
    List<SourceAccountingLine> encumbranceAccounts = new ArrayList<SourceAccountingLine>();
    for (Iterator<SourceAccountingLine> iter = encumbranceAccountMap.keySet().iterator(); iter.hasNext(); ) {
        SourceAccountingLine acctString = (SourceAccountingLine) iter.next();
        KualiDecimal amount = (KualiDecimal) encumbranceAccountMap.get(acctString);
        if (amount.doubleValue() != 0) {
            acctString.setAmount(amount);
            encumbranceAccounts.add(acctString);
        }
    }
    return encumbranceAccounts;
}
Also used : PurchaseOrderService(org.kuali.kfs.module.purap.document.service.PurchaseOrderService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) 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.rice.core.api.util.type.KualiDecimal) Map(java.util.Map) HashMap(java.util.HashMap) PurchaseOrderAccount(org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount)

Example 10 with PurchaseOrderItem

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

Aggregations

PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)22 ArrayList (java.util.ArrayList)11 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)9 Iterator (java.util.Iterator)8 List (java.util.List)8 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)8 ElectronicInvoiceRejectReason (org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason)5 PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)5 HashMap (java.util.HashMap)4 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)4 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)4 PurchaseOrderAccount (org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount)4 ElectronicInvoiceOrderHolder (org.kuali.kfs.module.purap.service.impl.ElectronicInvoiceOrderHolder)4 BigDecimal (java.math.BigDecimal)3 Map (java.util.Map)3 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)3 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)2