Search in sources :

Example 61 with KualiDecimal

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

the class GlLineServiceImpl method createAssetPaymentDocument.

/**
 * @see GlLineService#createAssetPaymentDocument(GeneralLedgerEntry, Integer)
 */
@Override
@NonTransactional
public Document createAssetPaymentDocument(GeneralLedgerEntry primaryGlEntry, Integer capitalAssetLineNumber) throws WorkflowException {
    // Find out the GL Entry
    // initiate a new document
    AssetPaymentDocument document = (AssetPaymentDocument) documentService.getNewDocument(DocumentTypeName.ASSET_PAYMENT);
    document.setCapitalAssetBuilderOriginIndicator(true);
    // populate the capital asset line distribution amount code to the payment document.
    CapitalAssetInformation capitalAssetInformation = findCapitalAssetInformation(primaryGlEntry.getDocumentNumber(), capitalAssetLineNumber);
    if (ObjectUtils.isNotNull(capitalAssetInformation)) {
        // setup asset allocation info accordingly so it can be changed on Asset Payment Document
        if (ObjectUtils.isNull(capitalAssetInformation.getDistributionAmountCode())) {
            document.setAssetPaymentAllocationTypeCode(KFSConstants.CapitalAssets.DISTRIBUTE_COST_EQUALLY_CODE);
            document.setAllocationFromFPDocuments(false);
        } else {
            document.setAssetPaymentAllocationTypeCode(capitalAssetInformation.getDistributionAmountCode());
            document.setAllocationFromFPDocuments(true);
        }
    }
    document.getDocumentHeader().setDocumentDescription(CAB_DESC_PREFIX + primaryGlEntry.getDocumentNumber());
    updatePreTagInformation(primaryGlEntry, document, capitalAssetLineNumber);
    // Asset Payment Detail - sourceAccountingLines on the document....
    document.getSourceAccountingLines().addAll(createAssetPaymentDetails(primaryGlEntry, document, 0, capitalAssetLineNumber));
    KualiDecimal assetAmount = KualiDecimal.ZERO;
    List<SourceAccountingLine> sourceAccountingLines = document.getSourceAccountingLines();
    for (SourceAccountingLine sourceAccountingLine : sourceAccountingLines) {
        assetAmount = assetAmount.add(sourceAccountingLine.getAmount());
    }
    List<AssetPaymentAssetDetail> assetPaymentDetails = document.getAssetPaymentAssetDetail();
    for (AssetPaymentAssetDetail assetPaymentDetail : assetPaymentDetails) {
        assetPaymentDetail.setAllocatedAmount(assetAmount);
    }
    // Asset payment asset detail
    // save the document
    documentService.saveDocument(document);
    markCapitalAssetProcessed(primaryGlEntry, capitalAssetLineNumber);
    deactivateGLEntries(primaryGlEntry, document, capitalAssetLineNumber);
    return document;
}
Also used : CapitalAssetInformation(org.kuali.kfs.fp.businessobject.CapitalAssetInformation) AssetPaymentDocument(org.kuali.kfs.module.cam.document.AssetPaymentDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) AssetPaymentAssetDetail(org.kuali.kfs.module.cam.businessobject.AssetPaymentAssetDetail) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) NonTransactional(org.kuali.kfs.sys.service.NonTransactional)

Example 62 with KualiDecimal

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

the class AssetSeparatePaymentDistributor method applyRatioToPaymentAmounts.

/**
 * Utility method which can take one payment and distribute its amount by ratio to the target payments
 *
 * @param source  Source Payment
 * @param targets Target Payment
 * @param ratios  Ratio to be applied for each target
 */
private void applyRatioToPaymentAmounts(AssetPayment source, AssetPayment[] targets, double[] ratios) {
    try {
        for (PropertyDescriptor propertyDescriptor : assetPaymentProperties) {
            Method readMethod = propertyDescriptor.getReadMethod();
            if (readMethod != null && propertyDescriptor.getPropertyType() != null && KualiDecimal.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
                KualiDecimal amount = (KualiDecimal) readMethod.invoke(source);
                if (amount != null && amount.isNonZero()) {
                    KualiDecimal[] ratioAmounts = KualiDecimalUtils.allocateByRatio(amount, ratios);
                    Method writeMethod = propertyDescriptor.getWriteMethod();
                    if (writeMethod != null) {
                        for (int i = 0; i < ratioAmounts.length; i++) {
                            writeMethod.invoke(targets[i], ratioAmounts[i]);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) Method(java.lang.reflect.Method)

Example 63 with KualiDecimal

use of org.kuali.rice.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 = null;
    // 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.rice.core.api.util.type.KualiDecimal)

Example 64 with KualiDecimal

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

the class AssetSeparatePaymentDistributor method roundAccountChargeAmount.

/**
 * Rounds the last payment by adjusting the amount compared against separate source amount and copies account charge amount to
 * primary depreciation base amount if not zero
 */
private void roundAccountChargeAmount() {
    for (int j = 0; j < this.newAssets.size(); j++) {
        Asset currentAsset = this.newAssets.get(j);
        AssetGlobalDetail detail = this.assetGlobal.getAssetGlobalDetails().get(j);
        AssetPayment lastPayment = currentAsset.getAssetPayments().get(currentAsset.getAssetPayments().size() - 1);
        KualiDecimal totalForAsset = this.totalByAsset.get(currentAsset.getCapitalAssetNumber());
        KualiDecimal diff = detail.getSeparateSourceAmount().subtract(totalForAsset);
        lastPayment.setAccountChargeAmount(lastPayment.getAccountChargeAmount().add(diff));
        currentAsset.setTotalCostAmount(totalForAsset.add(diff));
        AssetPayment lastSource = this.separatedPayments.get(this.separatedPayments.size() - 1);
        lastSource.setAccountChargeAmount(lastSource.getAccountChargeAmount().add(diff));
        // TODO : need more testing
        if (lastPayment.getPrimaryDepreciationBaseAmount() != null && lastPayment.getPrimaryDepreciationBaseAmount().isNonZero()) {
            if (lastPayment.getAccountChargeAmount().isNonZero() || lastPayment.getAccumulatedPrimaryDepreciationAmount() == null || lastPayment.getAccumulatedPrimaryDepreciationAmount().isZero()) {
                lastPayment.setPrimaryDepreciationBaseAmount(lastPayment.getAccountChargeAmount());
                lastSource.setPrimaryDepreciationBaseAmount(lastSource.getAccountChargeAmount());
            }
        }
    }
}
Also used : AssetGlobalDetail(org.kuali.kfs.module.cam.businessobject.AssetGlobalDetail) AssetPayment(org.kuali.kfs.module.cam.businessobject.AssetPayment) Asset(org.kuali.kfs.module.cam.businessobject.Asset) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal)

Example 65 with KualiDecimal

use of org.kuali.rice.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 = null;
    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.rice.core.api.util.type.KualiDecimal) Asset(org.kuali.kfs.module.cam.businessobject.Asset)

Aggregations

KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)209 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)19 Test (org.junit.Test)19 List (java.util.List)15 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)15 CapitalAssetInformation (org.kuali.kfs.fp.businessobject.CapitalAssetInformation)14 BigDecimal (java.math.BigDecimal)13 Date (java.sql.Date)13 Iterator (java.util.Iterator)12 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)12 KualiInteger (org.kuali.rice.core.api.util.type.KualiInteger)12 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)11 IOException (java.io.IOException)10 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)10 Map (java.util.Map)9 CapitalAccountingLines (org.kuali.kfs.fp.businessobject.CapitalAccountingLines)9 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)9 PaymentGroup (org.kuali.kfs.pdp.businessobject.PaymentGroup)9 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)8