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;
}
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;
}
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));
}
}
}
}
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();
}
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);
}
}
}
Aggregations