use of org.mifos.dto.screen.AdjustableSavingsPaymentDto in project head by mifos.
the class SavingsApplyAdjustmentAction method list.
@TransactionDemarcate(joinToken = true)
public ActionForward list(ActionMapping mapping, @SuppressWarnings("unused") ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
List<AdjustableSavingsPaymentDto> adjustablePayments = this.savingsServiceFacade.retrievePaymentsForAdjustment(savings.getAccountId());
SessionUtils.setCollectionAttribute(SavingsConstants.ADJUSTABLE_PAYMENTS, adjustablePayments, request);
return mapping.findForward("list_savings_adjustments");
}
use of org.mifos.dto.screen.AdjustableSavingsPaymentDto in project head by mifos.
the class SavingsServiceFacadeWebTier method retrievePaymentsForAdjustment.
@Override
public List<AdjustableSavingsPaymentDto> retrievePaymentsForAdjustment(Integer accountId) {
SavingsBO savingsAccount = this.savingsDao.findById(accountId);
List<AdjustableSavingsPaymentDto> adjustablePayments = new ArrayList<AdjustableSavingsPaymentDto>();
for (AccountPaymentEntity payment : savingsAccount.getAccountPayments()) {
if (payment.isSavingsDepositOrWithdrawal() && payment.getAmount().isGreaterThan(Money.zero())) {
AdjustableSavingsPaymentDto adjustableSavingsPaymentDto = new AdjustableSavingsPaymentDto(payment.getPaymentId(), payment.getReceiptNumber(), payment.getAmount().getAmount(), new LocalDate(payment.getPaymentDate()), (payment.getReceiptDate() == null) ? null : new LocalDate(payment.getReceiptDate()), payment.getPaymentType().getName(), payment.isSavingsDeposit());
adjustablePayments.add(adjustableSavingsPaymentDto);
}
}
Collections.sort(adjustablePayments, new Comparator<AdjustableSavingsPaymentDto>() {
@Override
public int compare(AdjustableSavingsPaymentDto o1, AdjustableSavingsPaymentDto o2) {
int result;
LocalDate firstDate = o1.getPaymentDate();
LocalDate secondDate = o2.getPaymentDate();
// sort by date
if (firstDate.isAfter(secondDate)) {
result = -1;
} else if (firstDate.isBefore(secondDate)) {
result = 1;
} else {
// withdrawal comes after deposit
if (o1.isWithdrawal() && !o2.isWithdrawal()) {
result = -1;
} else if (!o1.isWithdrawal() && o2.isWithdrawal()) {
result = 1;
} else {
result = 0;
}
}
return result;
}
});
return adjustablePayments;
}
Aggregations