Search in sources :

Example 66 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CapitalAssetInformationActionBase method getAccountingLineAmount.

/**
 * Returns the amount of the group accounting line from the capital asset information that
 * matches the capital accounting lines (only one lines, of course). If none exists, zero is returned.
 *
 * @param capitalAsset
 * @param capitalAccountingLine
 * @return accountLineAmount
 */
protected KualiDecimal getAccountingLineAmount(CapitalAssetInformation capitalAsset, CapitalAccountingLines capitalAccountingLine) {
    KualiDecimal accountLineAmount = KualiDecimal.ZERO;
    List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
    for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
        if (groupAccountLine.getCapitalAssetLineNumber().compareTo(capitalAsset.getCapitalAssetLineNumber()) == 0 && groupAccountLine.getSequenceNumber().compareTo(capitalAccountingLine.getSequenceNumber()) == 0 && groupAccountLine.getFinancialDocumentLineTypeCode().equals(KFSConstants.SOURCE.equals(capitalAccountingLine.getLineType()) ? KFSConstants.SOURCE_ACCT_LINE_TYPE_CODE : KFSConstants.TARGET_ACCT_LINE_TYPE_CODE) && groupAccountLine.getChartOfAccountsCode().equals(capitalAccountingLine.getChartOfAccountsCode()) && groupAccountLine.getAccountNumber().equals(capitalAccountingLine.getAccountNumber()) && groupAccountLine.getFinancialObjectCode().equals(capitalAccountingLine.getFinancialObjectCode())) {
            return groupAccountLine.getAmount();
        }
    }
    return accountLineAmount;
}
Also used : KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) CapitalAssetAccountsGroupDetails(org.kuali.kfs.fp.businessobject.CapitalAssetAccountsGroupDetails)

Example 67 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CapitalAssetInformationActionBase method adjustVarianceOnCapitalAssets.

/**
 * adjusts variances on capital assets where distribution method is set
 * as "distribute evenly" and capital asset amount is odd value.  Reduce the
 * capital asset amount line by 0.01 and then adjust the account amounts. Finally
 * any variance between capital accounting lines and capital assets is added
 * to the last capital asset and its accounting lines.
 *
 * @param capitalAssetInformation
 */
protected void adjustVarianceOnCapitalAssets(List<CapitalAssetInformation> capitalAssetInformation) {
    KualiDecimal adjustedCapitalAssetBalance = KualiDecimal.ZERO;
    CapitalAssetInformation lastCapitalAsset = null;
    for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
        // look at only cost equal assets...
        if (KFSConstants.CapitalAssets.DISTRIBUTE_COST_EQUALLY_CODE.equalsIgnoreCase(capitalAsset.getDistributionAmountCode())) {
            if (capitalAsset.getCapitalAssetLineAmount().mod(new KualiDecimal(2)) != KualiDecimal.ZERO) {
                capitalAsset.setCapitalAssetLineAmount(capitalAsset.getCapitalAssetLineAmount().subtract(new KualiDecimal(0.01)));
                adjustedCapitalAssetBalance = adjustedCapitalAssetBalance.add(new KualiDecimal(0.01));
                lastCapitalAsset = capitalAsset;
            }
        }
    }
    if (ObjectUtils.isNotNull(lastCapitalAsset) && adjustedCapitalAssetBalance.isNonZero()) {
        lastCapitalAsset.setCapitalAssetLineAmount(lastCapitalAsset.getCapitalAssetLineAmount().add(adjustedCapitalAssetBalance));
    }
}
Also used : CapitalAssetInformation(org.kuali.kfs.fp.businessobject.CapitalAssetInformation) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Example 68 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CapitalAssetInformationActionBase method redistributeEqualAmountsForAccountingLineForCreateAssets.

/**
 * @param selectedCapitalAccountingLines
 * @param capitalAssetInformation
 * @param remainingAmountToDistribute
 */
protected void redistributeEqualAmountsForAccountingLineForCreateAssets(List<CapitalAccountingLines> selectedCapitalAccountingLines, List<CapitalAssetInformation> capitalAssetInformation, KualiDecimal remainingAmountToDistribute) {
    // get the total capital assets quantity
    int totalQuantity = getTotalQuantityOfCreateAssets(selectedCapitalAccountingLines, capitalAssetInformation);
    if (totalQuantity > 0) {
        KualiDecimal equalCreateAssetAmount = remainingAmountToDistribute.divide(new KualiDecimal(totalQuantity), true);
        int lastAssetIndex = 0;
        CapitalAssetInformation lastCapitalAsset = new CapitalAssetInformation();
        if (equalCreateAssetAmount.compareTo(KualiDecimal.ZERO) != 0) {
            for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
                if (KFSConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR.equals(capitalAsset.getCapitalAssetActionIndicator()) && KFSConstants.CapitalAssets.DISTRIBUTE_COST_EQUALLY_CODE.equalsIgnoreCase(capitalAsset.getDistributionAmountCode()) && capitalAssetExists(selectedCapitalAccountingLines, capitalAsset, KFSConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR)) {
                    redistributeEqualAmounts(selectedCapitalAccountingLines, capitalAsset, equalCreateAssetAmount, totalQuantity);
                    if (ObjectUtils.isNotNull(capitalAsset.getCapitalAssetQuantity())) {
                        lastAssetIndex = lastAssetIndex + capitalAsset.getCapitalAssetQuantity();
                    }
                    // get a reference to the last capital create asset to fix any variances...
                    lastCapitalAsset = capitalAsset;
                }
            }
        }
        // apply any variance left to the last
        KualiDecimal varianceForAssets = remainingAmountToDistribute.subtract(equalCreateAssetAmount.multiply(new KualiDecimal(lastAssetIndex)));
        if (varianceForAssets.isNonZero()) {
            lastCapitalAsset.setCapitalAssetLineAmount(lastCapitalAsset.getCapitalAssetLineAmount().add(varianceForAssets));
            redistributeEqualAmountsOnLastCapitalAsset(selectedCapitalAccountingLines, lastCapitalAsset, capitalAssetInformation, KFSConstants.CapitalAssets.CAPITAL_ASSET_CREATE_ACTION_INDICATOR);
        }
    }
}
Also used : CapitalAssetInformation(org.kuali.kfs.fp.businessobject.CapitalAssetInformation) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Example 69 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CapitalAssetInformationActionBase method getRemainingAmounToDistribute.

/**
 * Calculates the remaining amount to distribute by taking selected capital accounting lines
 * and subtracting the allocated capital asset accounting lines amounts totals.
 *
 * @param selectedCapitalAccountingLines
 * @param form
 * @return remainingAmountToDistribute
 */
protected KualiDecimal getRemainingAmounToDistribute(List<CapitalAccountingLines> selectedCapitalAccountingLines, ActionForm form) {
    KualiDecimal capitalAccountsAmountToDistribute = KualiDecimal.ZERO;
    KualiDecimal capitalAssetsAllocatedAmount = KualiDecimal.ZERO;
    CapitalAccountingLinesFormBase calfb = (CapitalAccountingLinesFormBase) form;
    CapitalAssetInformationDocumentBase capitalAssetInformationDocumentBase = (CapitalAssetInformationDocumentBase) calfb.getFinancialDocument();
    List<CapitalAssetInformation> capitalAssets = capitalAssetInformationDocumentBase.getCapitalAssetInformation();
    CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) calfb.getFinancialDocument();
    List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();
    for (CapitalAccountingLines capitalAccountingLine : capitalAccountingLines) {
        if (capitalAccountingLine.isSelectLine() && !capitalAccountingLine.isAmountDistributed()) {
            selectedCapitalAccountingLines.add(capitalAccountingLine);
            capitalAccountsAmountToDistribute = capitalAccountsAmountToDistribute.add(capitalAccountingLine.getAmount());
            capitalAssetsAllocatedAmount = capitalAssetsAllocatedAmount.add(getCapitalAssetsAmountAllocated(capitalAssets, capitalAccountingLine));
        }
    }
    return capitalAccountsAmountToDistribute.subtract(capitalAssetsAllocatedAmount);
}
Also used : CapitalAssetInformation(org.kuali.kfs.fp.businessobject.CapitalAssetInformation) CapitalAssetInformationDocumentBase(org.kuali.kfs.fp.document.CapitalAssetInformationDocumentBase) CapitalAccountingLines(org.kuali.kfs.fp.businessobject.CapitalAccountingLines) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) CapitalAccountingLinesDocumentBase(org.kuali.kfs.fp.document.CapitalAccountingLinesDocumentBase)

Example 70 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CapitalAssetInformationActionBase method redistributeToGroupAccountingLinesFromAssetsByAmounts.

/**
 * when the user user hits refresh button, takes the amount in the amount field and
 * distributes to the group capital accounting lines for that asset only.
 *
 * @param selectedCapitalAccountingLines
 * @param capitalAsset
 */
protected void redistributeToGroupAccountingLinesFromAssetsByAmounts(List<CapitalAccountingLines> selectedCapitalAccountingLines, CapitalAssetInformation capitalAsset) {
    KualiDecimal amountToDistribute = capitalAsset.getCapitalAssetLineAmount();
    KualiDecimal amountDistributed = KualiDecimal.ZERO;
    KualiDecimal totalCapitalAccountsAmount = getTotalCapitalAccountsAmounts(selectedCapitalAccountingLines);
    // to capture the last group accounting line to update its amount with any variance.
    CapitalAssetAccountsGroupDetails lastGroupAccountLine = new CapitalAssetAccountsGroupDetails();
    List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
    for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
        BigDecimal linePercent = getCapitalAccountingLinePercent(selectedCapitalAccountingLines, groupAccountLine, totalCapitalAccountsAmount);
        // found the accounting line
        lastGroupAccountLine = groupAccountLine;
        KualiDecimal groupAccountLineAmount = capitalAsset.getCapitalAssetLineAmount().multiply(new KualiDecimal(linePercent));
        groupAccountLine.setAmount(groupAccountLineAmount);
        // keep track of amount distributed so far.
        amountDistributed = amountDistributed.add(groupAccountLineAmount);
    }
    // add any variance in the amounts to the last group accounting line.
    lastGroupAccountLine.setAmount(lastGroupAccountLine.getAmount().add(amountToDistribute.subtract(amountDistributed)));
}
Also used : KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) CapitalAssetAccountsGroupDetails(org.kuali.kfs.fp.businessobject.CapitalAssetAccountsGroupDetails) BigDecimal(java.math.BigDecimal)

Aggregations

KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)280 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)36 Test (org.junit.Test)28 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)21 BigDecimal (java.math.BigDecimal)18 List (java.util.List)18 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)15 Date (java.sql.Date)14 CapitalAssetInformation (org.kuali.kfs.fp.businessobject.CapitalAssetInformation)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 ConcurStandardAccountingExtractDetailLine (edu.cornell.kfs.concur.batch.businessobject.ConcurStandardAccountingExtractDetailLine)11 KualiInteger (org.kuali.kfs.core.api.util.type.KualiInteger)11 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)11 IOException (java.io.IOException)10 InvoiceDetailAccountObjectCode (org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)10 Map (java.util.Map)9 ParameterEvaluator (org.kuali.kfs.core.api.parameter.ParameterEvaluator)9 CapitalAccountingLines (org.kuali.kfs.fp.businessobject.CapitalAccountingLines)9 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)8