Search in sources :

Example 96 with KualiDecimal

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

the class AssetGlobalServiceImpl method totalPaymentByAsset.

/**
 * We need to calculate asset total amount from the sum of its payments. Otherwise, the asset total amount could
 * mismatch with the sum of payments.
 */
@Override
public KualiDecimal totalPaymentByAsset(AssetGlobal assetGlobal, boolean lastEntry) {
    KualiDecimal assetTotalAmount = KualiDecimal.ZERO;
    List<AssetPaymentDetail> assetPaymentDetails = assetGlobal.getAssetPaymentDetails();
    int numberOfTotalAsset = assetGlobal.getAssetGlobalDetails().size();
    if (numberOfTotalAsset > 0) {
        for (AssetPaymentDetail assetPaymentDetail : assetPaymentDetails) {
            KualiDecimal assetPaymentUnitCost = assetPaymentDetail.getAmount().divide(new KualiDecimal(numberOfTotalAsset));
            if (lastEntry) {
                assetPaymentUnitCost = assetPaymentDetail.getAmount().subtract(assetPaymentUnitCost.multiply(new KualiDecimal(numberOfTotalAsset - 1)));
            }
            assetTotalAmount = assetTotalAmount.add(assetPaymentUnitCost);
        }
    }
    return assetTotalAmount;
}
Also used : AssetPaymentDetail(org.kuali.kfs.module.cam.businessobject.AssetPaymentDetail) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Example 97 with KualiDecimal

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

the class AssetGlobalServiceImpl method getCreateNewAssets.

@Override
public List<PersistableBusinessObject> getCreateNewAssets(AssetGlobal assetGlobal) {
    List<PersistableBusinessObject> persistables = new ArrayList<>();
    // create new assets with inner loop handling payments
    Iterator<AssetGlobalDetail> assetGlobalDetailsIterator = assetGlobal.getAssetGlobalDetails().iterator();
    for (int assetGlobalDetailsIndex = 0; assetGlobalDetailsIterator.hasNext(); assetGlobalDetailsIndex++) {
        AssetGlobalDetail assetGlobalDetail = assetGlobalDetailsIterator.next();
        // Create the asset with most fields set as required
        Asset asset = setupAsset(assetGlobal, assetGlobalDetail, false);
        // track total cost of all payments for this assetGlobalDetail
        KualiDecimal paymentsAccountChargeAmount = new KualiDecimal(0);
        // take care of all the payments for this asset
        for (AssetPaymentDetail assetPaymentDetail : assetGlobal.getAssetPaymentDetails()) {
            AssetPayment assetPayment = setupCreateNewAssetPayment(assetGlobalDetail.getCapitalAssetNumber(), assetGlobal.getAcquisitionTypeCode(), assetGlobal.getAssetGlobalDetails().size(), assetGlobalDetailsIndex, assetPaymentDetail);
            paymentsAccountChargeAmount = paymentsAccountChargeAmount.add(assetPayment.getAccountChargeAmount());
            asset.getAssetPayments().add(assetPayment);
        }
        // set the amount generically. Note for separate this should equal assetGlobalDetail.getSeparateSourceAmount()
        asset.setTotalCostAmount(paymentsAccountChargeAmount);
        persistables.add(asset);
    }
    return persistables;
}
Also used : PersistableBusinessObject(org.kuali.kfs.krad.bo.PersistableBusinessObject) AssetGlobalDetail(org.kuali.kfs.module.cam.businessobject.AssetGlobalDetail) AssetPayment(org.kuali.kfs.module.cam.businessobject.AssetPayment) AssetPaymentDetail(org.kuali.kfs.module.cam.businessobject.AssetPaymentDetail) ArrayList(java.util.ArrayList) Asset(org.kuali.kfs.module.cam.businessobject.Asset) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Example 98 with KualiDecimal

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

the class AssetGlobalServiceImpl method createGLPostables.

@Override
public void createGLPostables(AssetGlobal assetGlobal, CamsGeneralLedgerPendingEntrySourceBase assetGlobalGlPoster) {
    List<AssetPaymentDetail> assetPaymentDetails = assetGlobal.getAssetPaymentDetails();
    for (AssetPaymentDetail assetPaymentDetail : assetPaymentDetails) {
        if (isPaymentFinancialObjectActive(assetPaymentDetail)) {
            KualiDecimal accountChargeAmount = assetPaymentDetail.getAmount();
            if (accountChargeAmount != null && !accountChargeAmount.isZero()) {
                assetGlobalGlPoster.getGeneralLedgerPendingEntrySourceDetails().add(createAssetGlpePostable(assetGlobal, assetPaymentDetail, AmountCategory.PAYMENT));
                assetGlobalGlPoster.getGeneralLedgerPendingEntrySourceDetails().add(createAssetGlpePostable(assetGlobal, assetPaymentDetail, AmountCategory.PAYMENT_OFFSET));
            }
        }
    }
}
Also used : AssetPaymentDetail(org.kuali.kfs.module.cam.businessobject.AssetPaymentDetail) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Example 99 with KualiDecimal

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

the class AssetSeparatePaymentDistributor method distribute.

public void distribute() {
    KualiDecimal totalSourceAmount = this.assetGlobal.getTotalCostAmount();
    KualiDecimal totalSeparateAmount = this.assetGlobal.getSeparateSourceTotalAmount();
    KualiDecimal remainingAmount = totalSourceAmount.subtract(totalSeparateAmount);
    // Compute separate ratio
    separateRatio = totalSeparateAmount.doubleValue() / totalSourceAmount.doubleValue();
    // Compute the retained ratio
    retainRatio = remainingAmount.doubleValue() / totalSourceAmount.doubleValue();
    List<AssetGlobalDetail> assetGlobalDetails = this.assetGlobal.getAssetGlobalDetails();
    int size = assetGlobalDetails.size();
    assetAllocateRatios = new double[size];
    AssetGlobalDetail assetGlobalDetail;
    // Compute ratio by each asset
    for (int i = 0; i < size; i++) {
        assetGlobalDetail = assetGlobalDetails.get(i);
        Long capitalAssetNumber = assetGlobalDetail.getCapitalAssetNumber();
        totalByAsset.put(capitalAssetNumber, KualiDecimal.ZERO);
        assetAllocateRatios[i] = assetGlobalDetail.getSeparateSourceAmount().doubleValue() / totalSeparateAmount.doubleValue();
    }
    // Prepare the source and offset payments for split
    prepareSourcePaymentsForSplit();
    // Distribute payments by ratio
    allocatePaymentAmountsByRatio();
    // Round and balance by each payment line
    roundPaymentAmounts();
    // Round and balance by separate source amount
    roundAccountChargeAmount();
    // create offset payments
    createOffsetPayments();
}
Also used : AssetGlobalDetail(org.kuali.kfs.module.cam.businessobject.AssetGlobalDetail) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Example 100 with KualiDecimal

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

the class AssetSeparatePaymentDistributor method computeAccumulatedDepreciationAmount.

/**
 * Sums up YTD values and Previous Year value to decide accumulated depreciation amount
 */
private void computeAccumulatedDepreciationAmount() {
    KualiDecimal previousYearAmount;
    for (Asset asset : this.newAssets) {
        List<AssetPayment> assetPayments = asset.getAssetPayments();
        for (AssetPayment currPayment : assetPayments) {
            previousYearAmount = currPayment.getPreviousYearPrimaryDepreciationAmount();
            previousYearAmount = previousYearAmount == null ? KualiDecimal.ZERO : previousYearAmount;
            KualiDecimal computedAmount = previousYearAmount.add(sumPeriodicDepreciationAmounts(currPayment));
            if (computedAmount.isNonZero()) {
                currPayment.setAccumulatedPrimaryDepreciationAmount(computedAmount);
            }
        }
    }
    for (AssetPayment currPayment : this.offsetPayments) {
        previousYearAmount = currPayment.getPreviousYearPrimaryDepreciationAmount();
        previousYearAmount = previousYearAmount == null ? KualiDecimal.ZERO : previousYearAmount;
        KualiDecimal computedAmount = previousYearAmount.add(sumPeriodicDepreciationAmounts(currPayment));
        if (computedAmount.isNonZero()) {
            currPayment.setAccumulatedPrimaryDepreciationAmount(computedAmount);
        }
    }
}
Also used : AssetPayment(org.kuali.kfs.module.cam.businessobject.AssetPayment) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) Asset(org.kuali.kfs.module.cam.businessobject.Asset)

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