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