Search in sources :

Example 6 with PurchaseOrderAccount

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

the class FavoriteAccountLineBuilderTest method testCreateAndAddMultipleAccountLines.

/*
     * Test creating and adding multiple accounting lines for distinct favorite accounts.
     */
@Test
public void testCreateAndAddMultipleAccountLines() throws Exception {
    reqsItem.setFavoriteAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    poDoc.setFavoriteAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    iwntDoc.setFavoriteAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    PurchasingFavoriteAccountLineBuilderForLineItem<RequisitionAccount> reqsBuilder = createBuilderForLineItem(reqsItem, 0, new RequisitionAccount());
    PurchasingFavoriteAccountLineBuilderForDistribution<PurchaseOrderAccount> poBuilder = createBuilderForDistribution(poDoc, poAccounts, new PurchaseOrderAccount());
    PurApFavoriteAccountLineBuilderForIWantDocument iwntBuilder = createBuilderForIWant(iwntDoc);
    // Initial addition should succeed.
    assertAccountLineAdditionToList(reqsBuilder, testFavoriteAccount, RequisitionAccount.class);
    assertAccountLineAdditionToList(poBuilder, testFavoriteAccount, PurchaseOrderAccount.class);
    assertAccountLineAdditionToList(iwntBuilder, testFavoriteAccount, IWantAccount.class);
    // Subsequent addition for a different favorite account should also succeed.
    reqsItem.setFavoriteAccountLineIdentifier(TEST_ALT_FAVORITE_ACCOUNT_LINE_ID);
    poDoc.setFavoriteAccountLineIdentifier(TEST_ALT_FAVORITE_ACCOUNT_LINE_ID);
    iwntDoc.setFavoriteAccountLineIdentifier(TEST_ALT_FAVORITE_ACCOUNT_LINE_ID);
    assertAccountLineAdditionToList(reqsBuilder, testAltFavoriteAccount, RequisitionAccount.class);
    assertAccountLineAdditionToList(poBuilder, testAltFavoriteAccount, PurchaseOrderAccount.class);
    assertAccountLineAdditionToList(iwntBuilder, testAltFavoriteAccount, IWantAccount.class);
}
Also used : RequisitionAccount(org.kuali.kfs.module.purap.businessobject.RequisitionAccount) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument) PurchaseOrderAccount(org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount) Test(org.junit.Test)

Example 7 with PurchaseOrderAccount

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

the class FavoriteAccountLineBuilderTest method testLineBuilderFailureForNullLineID.

/*
     * Test that a null line ID will cause line creation to fail.
     */
@Test
public void testLineBuilderFailureForNullLineID() throws Exception {
    reqsItem.setFavoriteAccountLineIdentifier(null);
    poDoc.setFavoriteAccountLineIdentifier(null);
    iwntDoc.setFavoriteAccountLineIdentifier(null);
    PurchasingFavoriteAccountLineBuilderForLineItem<RequisitionAccount> reqsBuilder = createBuilderForLineItem(reqsItem, 0, new RequisitionAccount());
    PurchasingFavoriteAccountLineBuilderForDistribution<PurchaseOrderAccount> poBuilder = createBuilderForDistribution(poDoc, poAccounts, new PurchaseOrderAccount());
    PurApFavoriteAccountLineBuilderForIWantDocument iwntBuilder = createBuilderForIWant(iwntDoc);
    assertUnsuccessfulAccountLineCreation(reqsBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineCreation(poBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineCreation(iwntBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineAdditionToList(reqsBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineAdditionToList(poBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineAdditionToList(iwntBuilder);
}
Also used : RequisitionAccount(org.kuali.kfs.module.purap.businessobject.RequisitionAccount) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument) PurchaseOrderAccount(org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount) Test(org.junit.Test)

Example 8 with PurchaseOrderAccount

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

the class CuPendingTransactionServiceImpl method getCreditMemoEncumbrance.

/**
 * 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 cm Credit Memo document
 * @param po Purchase Order document modify encumbrances
 * @return List of accounting lines to use to create the pending general ledger entries
 */
protected List<SourceAccountingLine> getCreditMemoEncumbrance(VendorCreditMemoDocument cm, PurchaseOrderDocument po) {
    LOG.debug("getCreditMemoEncumbrance() started");
    if (ObjectUtils.isNull(po)) {
        return null;
    }
    LOG.debug("getCreditMemoEncumbrance() Receiving items back from vendor (cancelled CM)");
    Map encumbranceAccountMap = new HashMap();
    // Get each item one by one
    for (Iterator items = cm.getItems().iterator(); items.hasNext(); ) {
        CreditMemoItem cmItem = (CreditMemoItem) items.next();
        PurchaseOrderItem poItem = getPoItem(po, cmItem.getItemLineNumber(), cmItem.getItemType());
        // Amount to disencumber for this item
        KualiDecimal itemDisEncumber = null;
        // Amount to alter the invoicedAmt on the PO item
        KualiDecimal itemAlterInvoiceAmt = null;
        String logItmNbr = "Item # " + cmItem.getItemLineNumber();
        LOG.debug("getCreditMemoEncumbrance() " + logItmNbr);
        final KualiDecimal cmItemTotalAmount = (cmItem.getTotalAmount() == null) ? KualiDecimal.ZERO : cmItem.getTotalAmount();
        ;
        // If there isn't a PO item or the total amount is 0, we don't need encumbrances
        if ((poItem == null) || (cmItemTotalAmount == null) || (cmItemTotalAmount.doubleValue() == 0)) {
            LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " No encumbrances required");
        } else {
            LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " Calculate encumbrance GL entries");
            // Do we calculate the encumbrance amount based on quantity or amount?
            if (poItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
                LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " Calculate encumbrance based on quantity");
                // Do encumbrance calculations based on quantity
                KualiDecimal cmQuantity = cmItem.getItemQuantity() == null ? ZERO : cmItem.getItemQuantity();
                KualiDecimal encumbranceQuantityChange = calculateQuantityChange(poItem, cmQuantity);
                LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " encumbranceQtyChange " + encumbranceQuantityChange + " outstandingEncumberedQty " + poItem.getItemOutstandingEncumberedQuantity() + " invoicedTotalQuantity " + poItem.getItemInvoicedTotalQuantity());
                itemDisEncumber = encumbranceQuantityChange.multiply(new KualiDecimal(poItem.getItemUnitPrice()));
                // add tax for encumbrance
                KualiDecimal itemTaxAmount = poItem.getItemTaxAmount() == null ? ZERO : poItem.getItemTaxAmount();
                KualiDecimal encumbranceTaxAmount = encumbranceQuantityChange.divide(poItem.getItemQuantity()).multiply(itemTaxAmount);
                itemDisEncumber = itemDisEncumber.add(encumbranceTaxAmount);
                itemAlterInvoiceAmt = cmItemTotalAmount;
                itemAlterInvoiceAmt = itemAlterInvoiceAmt.multiply(new KualiDecimal("-1"));
            } else {
                LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " Calculate encumbrance based on amount");
                // Do encumbrance calculations based on amount only
                // Decrease encumbrance
                itemDisEncumber = cmItemTotalAmount.multiply(new KualiDecimal("-1"));
                if (poItem.getItemOutstandingEncumberedAmount().add(itemDisEncumber).doubleValue() < 0) {
                    LOG.debug("getCreditMemoEncumbrance() Cancel overflow");
                    itemDisEncumber = poItem.getItemOutstandingEncumberedAmount();
                }
                itemAlterInvoiceAmt = itemDisEncumber;
            }
            // alter the encumbrance based on what was originally encumbered
            poItem.setItemOutstandingEncumberedAmount(poItem.getItemOutstandingEncumberedAmount().add(itemDisEncumber));
            // alter the invoiced amt based on what was actually credited on the credit memo
            poItem.setItemInvoicedTotalAmount(poItem.getItemInvoicedTotalAmount().subtract(itemAlterInvoiceAmt));
            if (poItem.getItemInvoicedTotalAmount().compareTo(ZERO) < 0) {
                poItem.setItemInvoicedTotalAmount(ZERO);
            }
            LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " Amount to disencumber: " + itemDisEncumber);
            // Sort accounts
            Collections.sort((List) poItem.getSourceAccountingLines());
            // make the list of accounts for the disencumbrance entry
            PurchaseOrderAccount lastAccount = null;
            KualiDecimal accountTotal = ZERO;
            // Collections.sort((List)poItem.getSourceAccountingLines());
            for (Iterator accountIter = poItem.getSourceAccountingLines().iterator(); accountIter.hasNext(); ) {
                PurchaseOrderAccount account = (PurchaseOrderAccount) accountIter.next();
                if (!account.isEmpty()) {
                    KualiDecimal encumbranceAmount = null;
                    SourceAccountingLine acctString = account.generateSourceAccountingLine();
                    // amount = item disencumber * account percent / 100
                    encumbranceAmount = itemDisEncumber.multiply(new KualiDecimal(account.getAccountLinePercent().toString())).divide(new KualiDecimal(100));
                    account.setItemAccountOutstandingEncumbranceAmount(account.getItemAccountOutstandingEncumbranceAmount().add(encumbranceAmount));
                    // For rounding check at the end
                    accountTotal = accountTotal.add(encumbranceAmount);
                    lastAccount = account;
                    LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " " + acctString + " = " + encumbranceAmount);
                    if (encumbranceAccountMap.get(acctString) == null) {
                        encumbranceAccountMap.put(acctString, encumbranceAmount);
                    } else {
                        KualiDecimal amt = (KualiDecimal) encumbranceAccountMap.get(acctString);
                        encumbranceAccountMap.put(acctString, amt.add(encumbranceAmount));
                    }
                }
            }
            // account for rounding by adjusting last account as needed
            if (lastAccount != null) {
                KualiDecimal difference = itemDisEncumber.subtract(accountTotal);
                LOG.debug("getCreditMemoEncumbrance() 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();
    for (Iterator 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 : PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) HashMap(java.util.HashMap) CreditMemoItem(org.kuali.kfs.module.purap.businessobject.CreditMemoItem) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) Map(java.util.Map) HashMap(java.util.HashMap) PurchaseOrderAccount(org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount)

Example 9 with PurchaseOrderAccount

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

the class FavoriteAccountLineBuilderTest method testCreateAndAddFavoriteAccountLinesForDistribution.

/*
     * Test creating favorite accounting lines for use with the account distribution section.
     */
@Test
public void testCreateAndAddFavoriteAccountLinesForDistribution() throws Exception {
    reqsDoc.setFavoriteAccountLineIdentifier(TEST_ALT_FAVORITE_ACCOUNT_LINE_ID);
    poDoc.setFavoriteAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    PurchasingFavoriteAccountLineBuilderForDistribution<RequisitionAccount> reqsBuilder = createBuilderForDistribution(reqsDoc, reqsAccounts, new RequisitionAccount());
    PurchasingFavoriteAccountLineBuilderForDistribution<PurchaseOrderAccount> poBuilder = createBuilderForDistribution(poDoc, poAccounts, new PurchaseOrderAccount());
    assertAccountLineCreation(reqsBuilder, testAltFavoriteAccount, RequisitionAccount.class);
    assertAccountLineCreation(poBuilder, testFavoriteAccount, PurchaseOrderAccount.class);
    assertAccountLineAdditionToList(reqsBuilder, testAltFavoriteAccount, RequisitionAccount.class);
    assertAccountLineAdditionToList(poBuilder, testFavoriteAccount, PurchaseOrderAccount.class);
}
Also used : RequisitionAccount(org.kuali.kfs.module.purap.businessobject.RequisitionAccount) PurchaseOrderAccount(org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount) Test(org.junit.Test)

Example 10 with PurchaseOrderAccount

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

the class FavoriteAccountLineBuilderTest method testLineBuilderFailureForPreexistingLine.

/*
     * Test that line creation will fail if a matching line already exists.
     */
@Test
public void testLineBuilderFailureForPreexistingLine() throws Exception {
    reqsItem.setFavoriteAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    poDoc.setFavoriteAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    iwntDoc.setFavoriteAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    PurchasingFavoriteAccountLineBuilderForLineItem<RequisitionAccount> reqsBuilder = createBuilderForLineItem(reqsItem, 0, new RequisitionAccount());
    PurchasingFavoriteAccountLineBuilderForDistribution<PurchaseOrderAccount> poBuilder = createBuilderForDistribution(poDoc, poAccounts, new PurchaseOrderAccount());
    PurApFavoriteAccountLineBuilderForIWantDocument iwntBuilder = createBuilderForIWant(iwntDoc);
    // First additions should succeed.
    assertAccountLineAdditionToList(reqsBuilder, testFavoriteAccount, RequisitionAccount.class);
    assertAccountLineAdditionToList(poBuilder, testFavoriteAccount, PurchaseOrderAccount.class);
    assertAccountLineAdditionToList(iwntBuilder, testFavoriteAccount, IWantAccount.class);
    // Subsequent creations or additions for the same ID should fail.
    assertUnsuccessfulAccountLineCreation(reqsBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineCreation(poBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineCreation(iwntBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineAdditionToList(reqsBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineAdditionToList(poBuilder);
    clearMessageMapErrors();
    assertUnsuccessfulAccountLineAdditionToList(iwntBuilder);
}
Also used : RequisitionAccount(org.kuali.kfs.module.purap.businessobject.RequisitionAccount) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument) PurchaseOrderAccount(org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount) Test(org.junit.Test)

Aggregations

PurchaseOrderAccount (org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount)12 RequisitionAccount (org.kuali.kfs.module.purap.businessobject.RequisitionAccount)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Iterator (java.util.Iterator)5 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)5 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)4 HashMap (java.util.HashMap)4 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)4 List (java.util.List)3 Map (java.util.Map)3 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)3 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)2 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)2 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)1 SequenceAccessorService (org.kuali.kfs.krad.service.SequenceAccessorService)1 CreditMemoItem (org.kuali.kfs.module.purap.businessobject.CreditMemoItem)1 PaymentRequestAccount (org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount)1 PurchaseOrderService (org.kuali.kfs.module.purap.document.service.PurchaseOrderService)1