use of org.kuali.kfs.module.cam.businessobject.AssetPayment in project cu-kfs by CU-CommunityApps.
the class AssetSeparatePaymentDistributor method applyBalanceToPaymentAmounts.
/**
* Utility method which can compute the difference between source amount and consumed amounts, then will adjust the last amount
*
* @param source Source payments
* @param consumedList Consumed Payments
*/
private void applyBalanceToPaymentAmounts(AssetPayment source, List<AssetPayment> consumedList) {
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()) {
Method writeMethod = propertyDescriptor.getWriteMethod();
KualiDecimal consumedAmount = KualiDecimal.ZERO;
KualiDecimal currAmt = KualiDecimal.ZERO;
if (writeMethod != null) {
for (int i = 0; i < consumedList.size(); i++) {
currAmt = (KualiDecimal) readMethod.invoke(consumedList.get(i));
consumedAmount = consumedAmount.add(currAmt != null ? currAmt : KualiDecimal.ZERO);
}
}
if (!consumedAmount.equals(amount)) {
AssetPayment lastPayment = consumedList.get(consumedList.size() - 1);
writeMethod.invoke(lastPayment, currAmt.add(amount.subtract(consumedAmount)));
}
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations