Search in sources :

Example 6 with AssetPayment

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);
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) AssetPayment(org.kuali.kfs.module.cam.businessobject.AssetPayment) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) Method(java.lang.reflect.Method)

Aggregations

AssetPayment (org.kuali.kfs.module.cam.businessobject.AssetPayment)6 Asset (org.kuali.kfs.module.cam.businessobject.Asset)3 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)3 PropertyDescriptor (java.beans.PropertyDescriptor)1 Method (java.lang.reflect.Method)1 AssetGlobalDetail (org.kuali.kfs.module.cam.businessobject.AssetGlobalDetail)1