Search in sources :

Example 6 with IWantAccount

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)));
    }
}
Also used : RequisitionAccount(org.kuali.kfs.module.purap.businessobject.RequisitionAccount) IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) BigDecimal(java.math.BigDecimal)

Example 7 with IWantAccount

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());
}
Also used : FavoriteAccount(edu.cornell.kfs.sys.businessobject.FavoriteAccount) CuRequisitionDocument(edu.cornell.kfs.module.purap.document.CuRequisitionDocument) IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) UserProcurementProfileValidationServiceImpl(edu.cornell.kfs.sys.service.impl.UserProcurementProfileValidationServiceImpl) PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) RequisitionItem(org.kuali.kfs.module.purap.businessobject.RequisitionItem) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) MessageMap(org.kuali.kfs.krad.util.MessageMap) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument) BeforeClass(org.junit.BeforeClass)

Example 8 with IWantAccount

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;
}
Also used : IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal)

Example 9 with IWantAccount

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);
        }
    }
}
Also used : IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine)

Example 10 with IWantAccount

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);
        }
    }
}
Also used : IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) BigDecimal(java.math.BigDecimal)

Aggregations

IWantAccount (edu.cornell.kfs.module.purap.businessobject.IWantAccount)13 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)5 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)5 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)5 IWantItem (edu.cornell.kfs.module.purap.businessobject.IWantItem)4 BigDecimal (java.math.BigDecimal)3 PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)3 IWantDocumentService (edu.cornell.kfs.module.purap.document.service.IWantDocumentService)2 FavoriteAccount (edu.cornell.kfs.sys.businessobject.FavoriteAccount)2 ActionForward (org.apache.struts.action.ActionForward)2 CuRequisitionDocument (edu.cornell.kfs.module.purap.document.CuRequisitionDocument)1 UserProcurementProfileValidationServiceImpl (edu.cornell.kfs.sys.service.impl.UserProcurementProfileValidationServiceImpl)1 ArrayList (java.util.ArrayList)1 BeforeClass (org.junit.BeforeClass)1 KualiAddLineEvent (org.kuali.kfs.kns.rule.event.KualiAddLineEvent)1 KualiDocumentFormBase (org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase)1 RouteDocumentEvent (org.kuali.kfs.krad.rules.rule.event.RouteDocumentEvent)1 KualiRuleService (org.kuali.kfs.krad.service.KualiRuleService)1 MessageMap (org.kuali.kfs.krad.util.MessageMap)1 PurApAccountingLineBase (org.kuali.kfs.module.purap.businessobject.PurApAccountingLineBase)1