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);
}
}
}
use of org.kuali.kfs.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);
}
}
Aggregations