/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.portfolio.loanaccount.data;
import java.math.BigDecimal;
import org.joda.time.LocalDate;
/**
* Immutable data object representing disbursement information.
*/
public class DisbursementData implements Comparable<DisbursementData> {
@SuppressWarnings("unused")
private final Long id;
private final LocalDate expectedDisbursementDate;
private final LocalDate actualDisbursementDate;
private final BigDecimal principal;
@SuppressWarnings("unused")
private final String loanChargeId;
private final BigDecimal chargeAmount;
public DisbursementData(Long id, final LocalDate expectedDisbursementDate, final LocalDate actualDisbursementDate,
final BigDecimal principalDisbursed, final String loanChargeId, BigDecimal chargeAmount) {
this.id = id;
this.expectedDisbursementDate = expectedDisbursementDate;
this.actualDisbursementDate = actualDisbursementDate;
this.principal = principalDisbursed;
this.loanChargeId = loanChargeId;
this.chargeAmount = chargeAmount;
}
public LocalDate disbursementDate() {
LocalDate disbursementDate = this.expectedDisbursementDate;
if (this.actualDisbursementDate != null) {
disbursementDate = this.actualDisbursementDate;
}
return disbursementDate;
}
public BigDecimal amount() {
return this.principal;
}
public BigDecimal getChargeAmount() {
return this.chargeAmount;
}
public boolean isDisbursed() {
return this.actualDisbursementDate != null;
}
@Override
public int compareTo(final DisbursementData obj) {
if (obj == null) { return -1; }
return obj.expectedDisbursementDate.compareTo(this.expectedDisbursementDate);
}
public boolean isDueForDisbursement(final LocalDate fromNotInclusive, final LocalDate upToAndInclusive) {
final LocalDate dueDate = disbursementDate();
return occursOnDayFromAndUpToAndIncluding(fromNotInclusive, upToAndInclusive, dueDate);
}
private boolean occursOnDayFromAndUpToAndIncluding(final LocalDate fromNotInclusive, final LocalDate upToAndInclusive,
final LocalDate target) {
return target != null && target.isAfter(fromNotInclusive) && !target.isAfter(upToAndInclusive);
}
}