Search in sources :

Example 1 with AdjustableSavingsPaymentDto

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");
}
Also used : SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AdjustableSavingsPaymentDto(org.mifos.dto.screen.AdjustableSavingsPaymentDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with AdjustableSavingsPaymentDto

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;
}
Also used : ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AdjustableSavingsPaymentDto(org.mifos.dto.screen.AdjustableSavingsPaymentDto) LocalDate(org.joda.time.LocalDate)

Aggregations

SavingsBO (org.mifos.accounts.savings.business.SavingsBO)2 AdjustableSavingsPaymentDto (org.mifos.dto.screen.AdjustableSavingsPaymentDto)2 ArrayList (java.util.ArrayList)1 LocalDate (org.joda.time.LocalDate)1 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1