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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations