use of edu.cornell.kfs.module.purap.businessobject.IWantAccount in project cu-kfs by CU-CommunityApps.
the class FavoriteAccountLineBuilderTest method assertAccountingLineHasCorrectConfiguration.
/*
* Convenience method for validating that the generated accounting line has the correct data and is of the correct type.
*/
private void assertAccountingLineHasCorrectConfiguration(FavoriteAccount expectedAccount, Class<? extends GeneralLedgerPendingEntrySourceDetail> expectedLineClass, GeneralLedgerPendingEntrySourceDetail acctLine) throws Exception {
if (!expectedLineClass.isAssignableFrom(acctLine.getClass())) {
fail("Expected line type is " + expectedLineClass.getName() + " but the generated line is of type " + acctLine.getClass().getName() + " which is not an instance of the expected one");
}
assertEquals("Generated line has wrong chart code", expectedAccount.getChartOfAccountsCode(), acctLine.getChartOfAccountsCode());
assertEquals("Generated line has wrong account number", expectedAccount.getAccountNumber(), acctLine.getAccountNumber());
assertEquals("Generated line has wrong sub-account number", expectedAccount.getSubAccountNumber(), acctLine.getSubAccountNumber());
assertEquals("Generated line has wrong object code", expectedAccount.getFinancialObjectCode(), acctLine.getFinancialObjectCode());
assertEquals("Generated line has wrong sub-object code", expectedAccount.getFinancialSubObjectCode(), acctLine.getFinancialSubObjectCode());
assertEquals("Generated line has wrong project code", expectedAccount.getProjectCode(), acctLine.getProjectCode());
assertEquals("Generated line has wrong org ref ID", expectedAccount.getOrganizationReferenceId(), acctLine.getOrganizationReferenceId());
// Validate pre-initialized percentage. The retrieval means will vary depending on line type and whether we need hacks to avoid Spring calls.
if (acctLine instanceof RequisitionAccount) {
assertEquals("Generated line has wrong percentage (comparison against 100% should have been zero)", 0, getRequisitionAccountLinePercent(((RequisitionAccount) acctLine)).compareTo(new BigDecimal(100)));
} else if (acctLine instanceof PurApAccountingLine) {
assertEquals("Generated line has wrong percentage (comparison against 100% should have been zero)", 0, ((PurApAccountingLine) acctLine).getAccountLinePercent().compareTo(new BigDecimal(100)));
} else if (acctLine instanceof IWantAccount) {
assertEquals("Generated line has wrong amount-or-percent indicator", CUPurapConstants.PERCENT, ((IWantAccount) acctLine).getUseAmountOrPercent());
assertEquals("Generated line has wrong percentage (comparison against 100% should have been zero)", 0, ((IWantAccount) acctLine).getAmountOrPercent().compareTo(new KualiDecimal(100)));
}
}
use of edu.cornell.kfs.module.purap.businessobject.IWantAccount in project cu-kfs by CU-CommunityApps.
the class FavoriteAccountLineBuilderTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
userProcurementProfileValidationService = new UserProcurementProfileValidationServiceImpl();
userFavoriteAccountService = new ExtendedTestUserFavoriteAccountService();
reqsAccounts = new ArrayList<PurApAccountingLine>();
poAccounts = new ArrayList<PurApAccountingLine>();
reqsItem = new RequisitionItem();
poItem = new PurchaseOrderItem();
reqsDoc = getMockedDocument(CuRequisitionDocument.class);
poDoc = getMockedDocument(PurchaseOrderDocument.class);
iwntDoc = getMockedDocument(IWantDocument.class);
iwntDoc.setAccounts(new ArrayList<IWantAccount>());
// Favorite Account with only some fields populated.
testFavoriteAccount = new FavoriteAccount();
testFavoriteAccount.setAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
testFavoriteAccount.setUserProfileId(TEST_USER_PROFILE_ID);
testFavoriteAccount.setChartOfAccountsCode(TEST_CHART_CODE);
testFavoriteAccount.setAccountNumber(TEST_ACCOUNT_NUMBER);
testFavoriteAccount.setFinancialObjectCode(TEST_OBJECT_CODE);
// Favorite Account with all fields populated (except reference objects or object ID or version number).
testAltFavoriteAccount = new FavoriteAccount();
testAltFavoriteAccount.setAccountLineIdentifier(TEST_ALT_FAVORITE_ACCOUNT_LINE_ID);
testAltFavoriteAccount.setUserProfileId(TEST_ALT_USER_PROFILE_ID);
testAltFavoriteAccount.setChartOfAccountsCode(TEST_ALT_CHART_CODE);
testAltFavoriteAccount.setAccountNumber(TEST_ALT_ACCOUNT_NUMBER);
testAltFavoriteAccount.setSubAccountNumber(TEST_ALT_SUB_ACCOUNT_NUMBER);
testAltFavoriteAccount.setFinancialObjectCode(TEST_ALT_OBJECT_CODE);
testAltFavoriteAccount.setFinancialSubObjectCode(TEST_ALT_SUB_OBJECT_CODE);
testAltFavoriteAccount.setProjectCode(TEST_ALT_PROJECT_CODE);
testAltFavoriteAccount.setOrganizationReferenceId(TEST_ALT_ORG_REF_ID);
GlobalVariables.setMessageMap(new MessageMap());
}
use of edu.cornell.kfs.module.purap.businessobject.IWantAccount in project cu-kfs by CU-CommunityApps.
the class IWantDocument method getAccountingLinesTotal.
/**
* Computes the accounting lines total amount
*
* @return
*/
public KualiDecimal getAccountingLinesTotal() {
KualiDecimal totalDollarAmount = KualiDecimal.ZERO;
KualiDecimal accountTotal = KualiDecimal.ZERO;
for (IWantAccount accountLine : accounts) {
// if amount
if (CUPurapConstants.AMOUNT.equalsIgnoreCase(accountLine.getUseAmountOrPercent())) {
if (accountLine.getAmountOrPercent() != null) {
accountTotal = accountLine.getAmountOrPercent();
} else {
accountTotal = KualiDecimal.ZERO;
}
}
// if percent
if (CUPurapConstants.PERCENT.equalsIgnoreCase(accountLine.getUseAmountOrPercent())) {
if (accountLine.getAmountOrPercent() != null) {
if (totalDollarAmount != null) {
accountTotal = (accountLine.getAmountOrPercent().multiply(getTotalDollarAmount())).divide(new KualiDecimal(100));
} else {
accountTotal = KualiDecimal.ZERO;
}
} else {
accountTotal = KualiDecimal.ZERO;
}
}
totalDollarAmount = totalDollarAmount.add(accountTotal);
}
return totalDollarAmount;
}
use of edu.cornell.kfs.module.purap.businessobject.IWantAccount in project cu-kfs by CU-CommunityApps.
the class IWantDocumentServiceImpl method copyIWantDocAccountingLinesToDVDoc.
/**
* Copies the accounting lines from the I Want document to the Requisition document
*
* @param requisitionDocument
* @param iWantDocument
* @param requisitionForm
*/
private void copyIWantDocAccountingLinesToDVDoc(DisbursementVoucherDocument disbursementVoucherDocument, IWantDocument iWantDocument, DisbursementVoucherForm disbursementVoucherForm) {
int accountsSize = iWantDocument.getAccounts() != null ? iWantDocument.getAccounts().size() : 0;
if (accountsSize > 0) {
for (IWantAccount iWantAccount : iWantDocument.getAccounts()) {
SourceAccountingLine dvAccount = disbursementVoucherForm.getNewSourceLine();
dvAccount.setChartOfAccountsCode(iWantAccount.getChartOfAccountsCode());
dvAccount.setAccountNumber(iWantAccount.getAccountNumber());
dvAccount.setSubAccountNumber(iWantAccount.getSubAccountNumber());
dvAccount.setFinancialObjectCode(iWantAccount.getFinancialObjectCode());
dvAccount.setFinancialSubObjectCode(iWantAccount.getFinancialSubObjectCode());
dvAccount.setProjectCode(iWantAccount.getProjectCode());
dvAccount.setOrganizationReferenceId(iWantAccount.getOrganizationReferenceId());
if (CUPurapConstants.PERCENT.equalsIgnoreCase(iWantAccount.getUseAmountOrPercent()) && iWantAccount.getAmountOrPercent() != null) {
// compute amount
KualiDecimal lineAmount = iWantAccount.getAmountOrPercent().multiply(iWantDocument.getTotalDollarAmount());
if (lineAmount.isNonZero()) {
lineAmount = lineAmount.divide(new KualiDecimal(100));
}
dvAccount.setAmount(lineAmount);
} else {
dvAccount.setAmount(iWantAccount.getAmountOrPercent());
}
disbursementVoucherDocument.addSourceAccountingLine(dvAccount);
disbursementVoucherForm.setNewSourceLine(null);
}
}
}
use of edu.cornell.kfs.module.purap.businessobject.IWantAccount in project cu-kfs by CU-CommunityApps.
the class IWantDocumentServiceImpl method copyIWantDocAccountingLinesToReqDoc.
/**
* Copies the accounting lines from the I Want document to the Requisition document
*
* @param requisitionDocument
* @param iWantDocument
* @param requisitionForm
*/
private void copyIWantDocAccountingLinesToReqDoc(RequisitionDocument requisitionDocument, IWantDocument iWantDocument, RequisitionForm requisitionForm) {
int itemsSize = iWantDocument.getItems() != null ? iWantDocument.getItems().size() : 0;
int accountsSize = iWantDocument.getAccounts() != null ? iWantDocument.getAccounts().size() : 0;
// we only add accounts information if there or only one item or there is only one account, otherwise ignore
if (itemsSize == 1 || accountsSize == 1) {
for (IWantAccount iWantAccount : iWantDocument.getAccounts()) {
PurApAccountingLine requisitionAccount = requisitionForm.getAccountDistributionnewSourceLine();
requisitionAccount.setChartOfAccountsCode(iWantAccount.getChartOfAccountsCode());
requisitionAccount.setAccountNumber(iWantAccount.getAccountNumber());
requisitionAccount.setSubAccountNumber(iWantAccount.getSubAccountNumber());
requisitionAccount.setFinancialObjectCode(iWantAccount.getFinancialObjectCode());
requisitionAccount.setFinancialSubObjectCode(iWantAccount.getFinancialSubObjectCode());
requisitionAccount.setProjectCode(iWantAccount.getProjectCode());
requisitionAccount.setOrganizationReferenceId(iWantAccount.getOrganizationReferenceId());
if (CUPurapConstants.PERCENT.equalsIgnoreCase(iWantAccount.getUseAmountOrPercent())) {
requisitionAccount.setAccountLinePercent(iWantAccount.getAmountOrPercent().bigDecimalValue().setScale(0, RoundingMode.HALF_UP));
} else {
// compute amount based on percent
BigDecimal requisitionAccountPercent = BigDecimal.ZERO;
KualiDecimal iWantDocTotalDollarAmount = iWantDocument.getTotalDollarAmount();
if (iWantDocTotalDollarAmount != null && iWantAccount.getAmountOrPercent() != null && iWantDocTotalDollarAmount.isNonZero() && iWantAccount.getAmountOrPercent().isNonZero()) {
requisitionAccountPercent = (iWantAccount.getAmountOrPercent().divide(iWantDocTotalDollarAmount).bigDecimalValue()).multiply(new BigDecimal("100"));
requisitionAccountPercent = requisitionAccountPercent.setScale(0, RoundingMode.HALF_UP);
}
requisitionAccount.setAccountLinePercent(requisitionAccountPercent);
}
requisitionForm.addAccountDistributionsourceAccountingLine(requisitionAccount);
}
}
}
Aggregations