remove unused warnings, replace toDateMidnight with toDateTimeAtStartOfDay method as recommended by joda time lib.

This commit is contained in:
Keith Woodlock
2013-11-13 10:34:10 +00:00
parent aa0df6a0c3
commit 40882a002b
14 changed files with 118 additions and 130 deletions
@@ -267,10 +267,10 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
.getTransactionId()); .getTransactionId());
if (journalEntries.size() <= 1) { throw new JournalEntriesNotFoundException(command.getTransactionId()); } if (journalEntries.size() <= 1) { throw new JournalEntriesNotFoundException(command.getTransactionId()); }
Long officeId = journalEntries.get(0).getOffice().getId(); final Long officeId = journalEntries.get(0).getOffice().getId();
final String reversalTransactionId = generateTransactionId(officeId); final String reversalTransactionId = generateTransactionId(officeId);
final boolean manualEntry = true; final boolean manualEntry = true;
for (final JournalEntry journalEntry : journalEntries) { for (final JournalEntry journalEntry : journalEntries) {
JournalEntry reversalJournalEntry; JournalEntry reversalJournalEntry;
final String reversalComment = "Reversal entry for Journal Entry with Entry Id :" + journalEntry.getId() final String reversalComment = "Reversal entry for Journal Entry with Entry Id :" + journalEntry.getId()
@@ -330,7 +330,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
private void validateBusinessRulesForJournalEntries(final JournalEntryCommand command) { private void validateBusinessRulesForJournalEntries(final JournalEntryCommand command) {
/** check if date of Journal entry is valid ***/ /** check if date of Journal entry is valid ***/
final LocalDate entryLocalDate = command.getTransactionDate(); final LocalDate entryLocalDate = command.getTransactionDate();
final Date transactionDate = entryLocalDate.toDateMidnight().toDate(); final Date transactionDate = entryLocalDate.toDateTimeAtStartOfDay().toDate();
// shouldn't be in the future // shouldn't be in the future
final Date todaysDate = new Date(); final Date todaysDate = new Date();
if (transactionDate.after(todaysDate)) { throw new JournalEntryInvalidException(GL_JOURNAL_ENTRY_INVALID_REASON.FUTURE_DATE, if (transactionDate.after(todaysDate)) { throw new JournalEntryInvalidException(GL_JOURNAL_ENTRY_INVALID_REASON.FUTURE_DATE,
@@ -347,7 +347,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
final SingleDebitOrCreditEntryCommand[] debits = command.getDebits(); final SingleDebitOrCreditEntryCommand[] debits = command.getDebits();
// atleast one debit or credit must be present // atleast one debit or credit must be present
if ((credits == null || credits.length <= 0) || (debits == null || debits.length <= 0)) { throw new JournalEntryInvalidException( if (credits == null || credits.length <= 0 || debits == null || debits.length <= 0) { throw new JournalEntryInvalidException(
GL_JOURNAL_ENTRY_INVALID_REASON.NO_DEBITS_OR_CREDITS, null, null, null); } GL_JOURNAL_ENTRY_INVALID_REASON.NO_DEBITS_OR_CREDITS, null, null, null); }
checkDebitAndCreditAmounts(credits, debits); checkDebitAndCreditAmounts(credits, debits);
@@ -381,11 +381,11 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
* TODO: Need a better implementation with guaranteed uniqueness (but not a * TODO: Need a better implementation with guaranteed uniqueness (but not a
* long UUID)...maybe something tied to system clock.. * long UUID)...maybe something tied to system clock..
*/ */
private String generateTransactionId(Long officeId) { private String generateTransactionId(final Long officeId) {
AppUser user = this.context.authenticatedUser(); final AppUser user = this.context.authenticatedUser();
Long time = System.currentTimeMillis(); final Long time = System.currentTimeMillis();
String uniqueVal = String.valueOf(time) + user.getId() + officeId; final String uniqueVal = String.valueOf(time) + user.getId() + officeId;
String transactionId = Long.toHexString(Long.parseLong(uniqueVal)); final String transactionId = Long.toHexString(Long.parseLong(uniqueVal));
return transactionId; return transactionId;
} }
@@ -28,7 +28,7 @@ import com.google.gson.reflect.TypeToken;
/** /**
* Immutable representation of a command. * Immutable representation of a command.
* *
* Wraps the provided JSON with convenience functions for extracting parameter * Wraps the provided JSON with convenience functions for extracting parameter
* values and checking for changes against an existing value. * values and checking for changes against an existing value.
*/ */
@@ -295,7 +295,7 @@ public final class JsonCommand {
public Date DateValueOfParameterNamed(final String parameterName) { public Date DateValueOfParameterNamed(final String parameterName) {
final LocalDate localDate = this.fromApiJsonHelper.extractLocalDateNamed(parameterName, this.parsedCommand); final LocalDate localDate = this.fromApiJsonHelper.extractLocalDateNamed(parameterName, this.parsedCommand);
if (localDate == null) { return null; } if (localDate == null) { return null; }
return localDate.toDateMidnight().toDate(); return localDate.toDateTimeAtStartOfDay().toDate();
} }
public boolean isChangeInStringParameterNamed(final String parameterName, final String existingValue) { public boolean isChangeInStringParameterNamed(final String parameterName, final String existingValue) {
@@ -23,7 +23,7 @@ import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidation
public class DateUtils { public class DateUtils {
public static Date getDateOfTenant() { public static Date getDateOfTenant() {
return getLocalDateOfTenant().toDateMidnight().toDate(); return getLocalDateOfTenant().toDateTimeAtStartOfDay().toDate();
} }
public static LocalDate getLocalDateOfTenant() { public static LocalDate getLocalDateOfTenant() {
@@ -63,7 +63,7 @@ public class DateUtils {
final String formattedSqlDate = df.format(date); final String formattedSqlDate = df.format(date);
return formattedSqlDate; return formattedSqlDate;
} }
public static boolean isDateInTheFuture(final LocalDate localDate){ public static boolean isDateInTheFuture(final LocalDate localDate){
return localDate.isAfter(getLocalDateOfTenant()); return localDate.isAfter(getLocalDateOfTenant());
} }
@@ -76,7 +76,7 @@ public class Office extends AbstractPersistable<Long> {
private Office(final Office parent, final String name, final LocalDate openingDate, final String externalId) { private Office(final Office parent, final String name, final LocalDate openingDate, final String externalId) {
this.parent = parent; this.parent = parent;
this.openingDate = openingDate.toDateMidnight().toDate(); this.openingDate = openingDate.toDateTimeAtStartOfDay().toDate();
if (parent != null) { if (parent != null) {
this.parent.addChild(this); this.parent.addChild(this);
} }
@@ -80,13 +80,13 @@ public class Calendar extends AbstractAuditableCustom<AppUser, Long> {
this.location = StringUtils.defaultIfEmpty(location, null); this.location = StringUtils.defaultIfEmpty(location, null);
if (null != startDate) { if (null != startDate) {
this.startDate = startDate.toDateMidnight().toDate(); this.startDate = startDate.toDateTimeAtStartOfDay().toDate();
} else { } else {
this.startDate = null; this.startDate = null;
} }
if (null != endDate) { if (null != endDate) {
this.endDate = endDate.toDateMidnight().toDate(); this.endDate = endDate.toDateTimeAtStartOfDay().toDate();
} else { } else {
this.endDate = null; this.endDate = null;
} }
@@ -178,10 +178,10 @@ public final class Client extends AbstractPersistable<Long> {
} }
if (activationDate != null) { if (activationDate != null) {
this.activationDate = activationDate.toDateMidnight().toDate(); this.activationDate = activationDate.toDateTimeAtStartOfDay().toDate();
} }
if (officeJoiningDate != null) { if (officeJoiningDate != null) {
this.officeJoiningDate = officeJoiningDate.toDateMidnight().toDate(); this.officeJoiningDate = officeJoiningDate.toDateTimeAtStartOfDay().toDate();
} }
if (StringUtils.isNotBlank(firstname)) { if (StringUtils.isNotBlank(firstname)) {
this.firstname = firstname.trim(); this.firstname = firstname.trim();
@@ -10,7 +10,6 @@ public class LoanInstallmentChargeData {
private final LocalDate dueDate; private final LocalDate dueDate;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final BigDecimal amount; private final BigDecimal amount;
@SuppressWarnings("unused")
private final BigDecimal amountOutstanding; private final BigDecimal amountOutstanding;
private final boolean paid; private final boolean paid;
private final boolean waived; private final boolean waived;
@@ -32,15 +31,15 @@ public class LoanInstallmentChargeData {
public LocalDate getDueDate() { public LocalDate getDueDate() {
return this.dueDate; return this.dueDate;
} }
public boolean isPaymentPending(){ public boolean isPaymentPending(){
return !(paid || waived); return !(this.paid || this.waived);
} }
public BigDecimal getAmountOutstanding() { public BigDecimal getAmountOutstanding() {
return this.amountOutstanding; return this.amountOutstanding;
} }
} }
@@ -72,7 +72,6 @@ public class LoanCharge extends AbstractPersistable<Long> {
@Column(name = "calculation_on_amount", scale = 6, precision = 19, nullable = true) @Column(name = "calculation_on_amount", scale = 6, precision = 19, nullable = true)
private BigDecimal amountPercentageAppliedTo; private BigDecimal amountPercentageAppliedTo;
@SuppressWarnings("unused")
@Column(name = "charge_amount_or_percentage", scale = 6, precision = 19, nullable = false) @Column(name = "charge_amount_or_percentage", scale = 6, precision = 19, nullable = false)
private BigDecimal amountOrPercentage; private BigDecimal amountOrPercentage;
@@ -105,10 +104,10 @@ public class LoanCharge extends AbstractPersistable<Long> {
@Column(name = "max_cap", scale = 6, precision = 19, nullable = true) @Column(name = "max_cap", scale = 6, precision = 19, nullable = true)
private BigDecimal maxCap; private BigDecimal maxCap;
@LazyCollection(LazyCollectionOption.FALSE) @LazyCollection(LazyCollectionOption.FALSE)
@OneToMany(cascade = CascadeType.ALL, mappedBy = "loancharge", orphanRemoval = true) @OneToMany(cascade = CascadeType.ALL, mappedBy = "loancharge", orphanRemoval = true)
private Set<LoanInstallmentCharge> loanInstallmentCharge = new HashSet<LoanInstallmentCharge>(); private final Set<LoanInstallmentCharge> loanInstallmentCharge = new HashSet<LoanInstallmentCharge>();
public static LoanCharge createNewFromJson(final Loan loan, final Charge chargeDefinition, final JsonCommand command) { public static LoanCharge createNewFromJson(final Loan loan, final Charge chargeDefinition, final JsonCommand command) {
@@ -248,18 +247,18 @@ public class LoanCharge extends AbstractPersistable<Long> {
break; break;
} }
this.amountOrPercentage = chargeAmount; this.amountOrPercentage = chargeAmount;
if(this.loan!=null && this.isInstalmentFee()){ if(this.loan!=null && isInstalmentFee()){
Set<LoanInstallmentCharge> chargePerInstallments = this.loan.generateInstallmentLoanCharges(this); final Set<LoanInstallmentCharge> chargePerInstallments = this.loan.generateInstallmentLoanCharges(this);
if(this.loanInstallmentCharge.isEmpty()){ if(this.loanInstallmentCharge.isEmpty()){
this.loanInstallmentCharge.addAll(chargePerInstallments); this.loanInstallmentCharge.addAll(chargePerInstallments);
}else{ }else{
int index = 0; int index = 0;
LoanInstallmentCharge[] loanChargePerInstallments = new LoanInstallmentCharge[chargePerInstallments.size()]; final LoanInstallmentCharge[] loanChargePerInstallments = new LoanInstallmentCharge[chargePerInstallments.size()];
LoanInstallmentCharge[] loanChargePerInstallmentArray = chargePerInstallments.toArray(loanChargePerInstallments); final LoanInstallmentCharge[] loanChargePerInstallmentArray = chargePerInstallments.toArray(loanChargePerInstallments);
for(LoanInstallmentCharge chargePerInstallment:this.loanInstallmentCharge){ for(final LoanInstallmentCharge chargePerInstallment:this.loanInstallmentCharge){
chargePerInstallment.copyFrom(loanChargePerInstallmentArray[index++]); chargePerInstallment.copyFrom(loanChargePerInstallmentArray[index++]);
} }
} }
} }
} }
@@ -276,7 +275,7 @@ public class LoanCharge extends AbstractPersistable<Long> {
this.amountOutstanding = calculateAmountOutstanding(currency); this.amountOutstanding = calculateAmountOutstanding(currency);
this.paid = false; this.paid = false;
this.waived = false; this.waived = false;
for(LoanInstallmentCharge installmentCharge:loanInstallmentCharge){ for(final LoanInstallmentCharge installmentCharge:this.loanInstallmentCharge){
installmentCharge.resetPaidAmount(currency); installmentCharge.resetPaidAmount(currency);
} }
} }
@@ -285,15 +284,15 @@ public class LoanCharge extends AbstractPersistable<Long> {
this.amountPaid = BigDecimal.ZERO; this.amountPaid = BigDecimal.ZERO;
this.amountOutstanding = calculateAmountOutstanding(currency); this.amountOutstanding = calculateAmountOutstanding(currency);
this.paid = false; this.paid = false;
for(LoanInstallmentCharge installmentCharge:loanInstallmentCharge){ for(final LoanInstallmentCharge installmentCharge:this.loanInstallmentCharge){
installmentCharge.resetPaidAmount(currency); installmentCharge.resetPaidAmount(currency);
} }
} }
public Money waive(final MonetaryCurrency currency, Integer loanInstallmentNumber) { public Money waive(final MonetaryCurrency currency, final Integer loanInstallmentNumber) {
if(isInstalmentFee()){ if(isInstalmentFee()){
LoanInstallmentCharge chargePerInstallment = getInstallmentLoanCharge(loanInstallmentNumber); final LoanInstallmentCharge chargePerInstallment = getInstallmentLoanCharge(loanInstallmentNumber);
Money amountWaived = chargePerInstallment.waive(currency); final Money amountWaived = chargePerInstallment.waive(currency);
if(this.amountWaived == null){ if(this.amountWaived == null){
this.amountWaived = BigDecimal.ZERO; this.amountWaived = BigDecimal.ZERO;
} }
@@ -310,7 +309,7 @@ public class LoanCharge extends AbstractPersistable<Long> {
this.paid = false; this.paid = false;
this.waived = true; this.waived = true;
return getAmountWaived(currency); return getAmountWaived(currency);
} }
private BigDecimal calculateAmountOutstanding(final MonetaryCurrency currency) { private BigDecimal calculateAmountOutstanding(final MonetaryCurrency currency) {
@@ -353,15 +352,15 @@ public class LoanCharge extends AbstractPersistable<Long> {
break; break;
} }
this.amountOrPercentage = amount; this.amountOrPercentage = amount;
if(this.loan !=null && this.isInstalmentFee()){ if(this.loan !=null && isInstalmentFee()){
Set<LoanInstallmentCharge> chargePerInstallments = this.loan.generateInstallmentLoanCharges(this); final Set<LoanInstallmentCharge> chargePerInstallments = this.loan.generateInstallmentLoanCharges(this);
if(this.loanInstallmentCharge.isEmpty()){ if(this.loanInstallmentCharge.isEmpty()){
this.loanInstallmentCharge.addAll(chargePerInstallments); this.loanInstallmentCharge.addAll(chargePerInstallments);
}else{ }else{
int index = 0; int index = 0;
LoanInstallmentCharge[] loanChargePerInstallments = new LoanInstallmentCharge[chargePerInstallments.size()]; final LoanInstallmentCharge[] loanChargePerInstallments = new LoanInstallmentCharge[chargePerInstallments.size()];
LoanInstallmentCharge[] loanChargePerInstallmentArray = chargePerInstallments.toArray(loanChargePerInstallments); final LoanInstallmentCharge[] loanChargePerInstallmentArray = chargePerInstallments.toArray(loanChargePerInstallments);
for(LoanInstallmentCharge chargePerInstallment:this.loanInstallmentCharge){ for(final LoanInstallmentCharge chargePerInstallment:this.loanInstallmentCharge){
chargePerInstallment.copyFrom(loanChargePerInstallmentArray[index++]); chargePerInstallment.copyFrom(loanChargePerInstallmentArray[index++]);
} }
} }
@@ -416,15 +415,15 @@ public class LoanCharge extends AbstractPersistable<Long> {
break; break;
} }
this.amountOrPercentage = newValue; this.amountOrPercentage = newValue;
if(this.isInstalmentFee()){ if(isInstalmentFee()){
Set<LoanInstallmentCharge> chargePerInstallments = this.loan.generateInstallmentLoanCharges(this); final Set<LoanInstallmentCharge> chargePerInstallments = this.loan.generateInstallmentLoanCharges(this);
if(this.loanInstallmentCharge.isEmpty()){ if(this.loanInstallmentCharge.isEmpty()){
this.loanInstallmentCharge.addAll(chargePerInstallments); this.loanInstallmentCharge.addAll(chargePerInstallments);
}else{ }else{
int index = 0; int index = 0;
LoanInstallmentCharge[] loanChargePerInstallments = new LoanInstallmentCharge[chargePerInstallments.size()]; final LoanInstallmentCharge[] loanChargePerInstallments = new LoanInstallmentCharge[chargePerInstallments.size()];
LoanInstallmentCharge[] loanChargePerInstallmentArray = chargePerInstallments.toArray(loanChargePerInstallments); final LoanInstallmentCharge[] loanChargePerInstallmentArray = chargePerInstallments.toArray(loanChargePerInstallments);
for(LoanInstallmentCharge chargePerInstallment:this.loanInstallmentCharge){ for(final LoanInstallmentCharge chargePerInstallment:this.loanInstallmentCharge){
chargePerInstallment.copyFrom(loanChargePerInstallmentArray[index++]); chargePerInstallment.copyFrom(loanChargePerInstallmentArray[index++]);
} }
} }
@@ -615,9 +614,9 @@ public class LoanCharge extends AbstractPersistable<Long> {
* Amount used to pay off this charge * Amount used to pay off this charge
* @return Actual amount paid on this charge * @return Actual amount paid on this charge
*/ */
public Money updatePaidAmountBy(final Money incrementBy,final Integer installmentNumber, Money feeAmount) { public Money updatePaidAmountBy(final Money incrementBy,final Integer installmentNumber, final Money feeAmount) {
Money processAmount = Money.zero(incrementBy.getCurrency()); Money processAmount = Money.zero(incrementBy.getCurrency());
if(this.isInstalmentFee()){ if(isInstalmentFee()){
if(installmentNumber == null){ if(installmentNumber == null){
processAmount = getUnpaidInstallmentLoanCharge().updatePaidAmountBy(incrementBy, feeAmount); processAmount = getUnpaidInstallmentLoanCharge().updatePaidAmountBy(incrementBy, feeAmount);
}else{ }else{
@@ -701,7 +700,7 @@ public class LoanCharge extends AbstractPersistable<Long> {
public LoanInstallmentCharge getUnpaidInstallmentLoanCharge() { public LoanInstallmentCharge getUnpaidInstallmentLoanCharge() {
LoanInstallmentCharge unpaidChargePerInstallment = null; LoanInstallmentCharge unpaidChargePerInstallment = null;
for (LoanInstallmentCharge loanChargePerInstallment : this.loanInstallmentCharge) { for (final LoanInstallmentCharge loanChargePerInstallment : this.loanInstallmentCharge) {
if (loanChargePerInstallment.isPending() if (loanChargePerInstallment.isPending()
&& (unpaidChargePerInstallment == null || unpaidChargePerInstallment.getRepaymentInstallment().getDueDate() && (unpaidChargePerInstallment == null || unpaidChargePerInstallment.getRepaymentInstallment().getDueDate()
.isAfter(loanChargePerInstallment.getRepaymentInstallment().getDueDate()))) { .isAfter(loanChargePerInstallment.getRepaymentInstallment().getDueDate()))) {
@@ -710,40 +709,40 @@ public class LoanCharge extends AbstractPersistable<Long> {
} }
return unpaidChargePerInstallment; return unpaidChargePerInstallment;
} }
public LoanInstallmentCharge getInstallmentLoanCharge(LocalDate periodDueDate) { public LoanInstallmentCharge getInstallmentLoanCharge(final LocalDate periodDueDate) {
for (LoanInstallmentCharge loanChargePerInstallment : this.loanInstallmentCharge) { for (final LoanInstallmentCharge loanChargePerInstallment : this.loanInstallmentCharge) {
if (periodDueDate.isEqual(loanChargePerInstallment.getRepaymentInstallment().getDueDate())) { if (periodDueDate.isEqual(loanChargePerInstallment.getRepaymentInstallment().getDueDate())) {
return loanChargePerInstallment; return loanChargePerInstallment;
} }
} }
return null; return null;
} }
public LoanInstallmentCharge getInstallmentLoanCharge(Integer installmentNumber) { public LoanInstallmentCharge getInstallmentLoanCharge(final Integer installmentNumber) {
for (LoanInstallmentCharge loanChargePerInstallment : this.loanInstallmentCharge) { for (final LoanInstallmentCharge loanChargePerInstallment : this.loanInstallmentCharge) {
if (installmentNumber.equals(loanChargePerInstallment.getRepaymentInstallment().getInstallmentNumber().intValue()) ){ if (installmentNumber.equals(loanChargePerInstallment.getRepaymentInstallment().getInstallmentNumber().intValue()) ){
return loanChargePerInstallment; return loanChargePerInstallment;
} }
} }
return null; return null;
} }
public void clearLoanInstallmentCharges(){ public void clearLoanInstallmentCharges(){
this.loanInstallmentCharge.clear(); this.loanInstallmentCharge.clear();
} }
public void addLoanInstallmentCharges(Collection<LoanInstallmentCharge> installmentCharges){ public void addLoanInstallmentCharges(final Collection<LoanInstallmentCharge> installmentCharges){
this.loanInstallmentCharge.addAll(installmentCharges); this.loanInstallmentCharge.addAll(installmentCharges);
} }
public boolean hasNoLoanInstallmentCharges(){ public boolean hasNoLoanInstallmentCharges(){
return this.loanInstallmentCharge.isEmpty(); return this.loanInstallmentCharge.isEmpty();
} }
public LoanRepaymentScheduleInstallment fetchRepaymentInstallment(Money trasferedAmount){ public LoanRepaymentScheduleInstallment fetchRepaymentInstallment(final Money trasferedAmount){
for (LoanInstallmentCharge loanChargePerInstallment : this.loanInstallmentCharge) { for (final LoanInstallmentCharge loanChargePerInstallment : this.loanInstallmentCharge) {
if (loanChargePerInstallment.isPending() && if (loanChargePerInstallment.isPending() &&
trasferedAmount.getAmount().equals(loanChargePerInstallment.getAmountThroughChargePayment(trasferedAmount.getCurrency()).getAmount()) ){ trasferedAmount.getAmount().equals(loanChargePerInstallment.getAmountThroughChargePayment(trasferedAmount.getCurrency()).getAmount()) ){
return loanChargePerInstallment.getRepaymentInstallment(); return loanChargePerInstallment.getRepaymentInstallment();
} }
@@ -21,11 +21,10 @@ import org.springframework.data.jpa.domain.AbstractPersistable;
@Table(name = "m_loan_installment_charge") @Table(name = "m_loan_installment_charge")
public class LoanInstallmentCharge extends AbstractPersistable<Long> { public class LoanInstallmentCharge extends AbstractPersistable<Long> {
@SuppressWarnings("unused")
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "loan_charge_id", referencedColumnName = "id", nullable = false) @JoinColumn(name = "loan_charge_id", referencedColumnName = "id", nullable = false)
private LoanCharge loancharge; private LoanCharge loancharge;
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "loan_schedule_id", referencedColumnName = "id", nullable = false) @JoinColumn(name = "loan_schedule_id", referencedColumnName = "id", nullable = false)
private LoanRepaymentScheduleInstallment installment; private LoanRepaymentScheduleInstallment installment;
@@ -44,7 +43,7 @@ public class LoanInstallmentCharge extends AbstractPersistable<Long> {
@Column(name = "amount_outstanding_derived", scale = 6, precision = 19, nullable = false) @Column(name = "amount_outstanding_derived", scale = 6, precision = 19, nullable = false)
private BigDecimal amountOutstanding; private BigDecimal amountOutstanding;
@Column(name = "amount_through_charge_payment", scale = 6, precision = 19, nullable = true) @Column(name = "amount_through_charge_payment", scale = 6, precision = 19, nullable = true)
private BigDecimal amountThroughChargePayment; private BigDecimal amountThroughChargePayment;
@@ -53,13 +52,13 @@ public class LoanInstallmentCharge extends AbstractPersistable<Long> {
@Column(name = "waived", nullable = false) @Column(name = "waived", nullable = false)
private boolean waived = false; private boolean waived = false;
public LoanInstallmentCharge() { public LoanInstallmentCharge() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public LoanInstallmentCharge(BigDecimal amount,LoanCharge loanCharge,LoanRepaymentScheduleInstallment installment) { public LoanInstallmentCharge(final BigDecimal amount,final LoanCharge loanCharge,final LoanRepaymentScheduleInstallment installment) {
this.loancharge = loanCharge; this.loancharge = loanCharge;
this.installment = installment; this.installment = installment;
this.amount = amount; this.amount = amount;
@@ -68,15 +67,15 @@ public class LoanInstallmentCharge extends AbstractPersistable<Long> {
this.amountWaived = null; this.amountWaived = null;
this.amountWrittenOff = null; this.amountWrittenOff = null;
} }
public void copyFrom(LoanInstallmentCharge loanChargePerInstallment){ public void copyFrom(final LoanInstallmentCharge loanChargePerInstallment){
this.amount = loanChargePerInstallment.amount; this.amount = loanChargePerInstallment.amount;
this.installment = loanChargePerInstallment.installment; this.installment = loanChargePerInstallment.installment;
this.amountOutstanding = calculateOutstanding(); this.amountOutstanding = calculateOutstanding();
this.paid = determineIfFullyPaid(); this.paid = determineIfFullyPaid();
} }
public Money waive(final MonetaryCurrency currency) { public Money waive(final MonetaryCurrency currency) {
this.amountWaived = this.amountOutstanding; this.amountWaived = this.amountOutstanding;
this.amountOutstanding = BigDecimal.ZERO; this.amountOutstanding = BigDecimal.ZERO;
@@ -89,14 +88,14 @@ public class LoanInstallmentCharge extends AbstractPersistable<Long> {
public Money getAmountWaived(final MonetaryCurrency currency) { public Money getAmountWaived(final MonetaryCurrency currency) {
return Money.of(currency, this.amountWaived); return Money.of(currency, this.amountWaived);
} }
private boolean determineIfFullyPaid() { private boolean determineIfFullyPaid() {
if(this.amount == null){ if(this.amount == null){
return true; return true;
} }
return BigDecimal.ZERO.compareTo(calculateOutstanding()) == 0; return BigDecimal.ZERO.compareTo(calculateOutstanding()) == 0;
} }
private BigDecimal calculateOutstanding() { private BigDecimal calculateOutstanding() {
if(this.amount == null){ if(this.amount == null){
return null; return null;
@@ -121,11 +120,11 @@ public class LoanInstallmentCharge extends AbstractPersistable<Long> {
return this.amount.subtract(totalAccountedFor); return this.amount.subtract(totalAccountedFor);
} }
public BigDecimal getAmount() { public BigDecimal getAmount() {
return this.amount; return this.amount;
} }
public Money getAmount(final MonetaryCurrency currency) { public Money getAmount(final MonetaryCurrency currency) {
return Money.of(currency, this.amount); return Money.of(currency, this.amount);
} }
@@ -137,12 +136,12 @@ public class LoanInstallmentCharge extends AbstractPersistable<Long> {
public BigDecimal getAmountOutstanding() { public BigDecimal getAmountOutstanding() {
return this.amountOutstanding; return this.amountOutstanding;
} }
private BigDecimal calculateAmountOutstanding(final MonetaryCurrency currency) { private BigDecimal calculateAmountOutstanding(final MonetaryCurrency currency) {
return getAmount(currency).minus(getAmountWaived(currency)).minus(getAmountPaid(currency)).getAmount(); return getAmount(currency).minus(getAmountWaived(currency)).minus(getAmountPaid(currency)).getAmount();
} }
public boolean isPaid() { public boolean isPaid() {
return this.paid; return this.paid;
} }
@@ -152,16 +151,16 @@ public class LoanInstallmentCharge extends AbstractPersistable<Long> {
} }
public boolean isPending(){ public boolean isPending(){
return !(isPaid() || isWaived()); return !(isPaid() || isWaived());
} }
public LoanRepaymentScheduleInstallment getRepaymentInstallment() { public LoanRepaymentScheduleInstallment getRepaymentInstallment() {
return this.installment; return this.installment;
} }
public Money updatePaidAmountBy(final Money incrementBy, Money feeAmount) { public Money updatePaidAmountBy(final Money incrementBy, final Money feeAmount) {
Money amountPaidToDate = Money.of(incrementBy.getCurrency(), this.amountPaid); Money amountPaidToDate = Money.of(incrementBy.getCurrency(), this.amountPaid);
final Money amountOutstanding = Money.of(incrementBy.getCurrency(), this.amountOutstanding); final Money amountOutstanding = Money.of(incrementBy.getCurrency(), this.amountOutstanding);
@@ -183,17 +182,17 @@ public class LoanInstallmentCharge extends AbstractPersistable<Long> {
return amountPaidOnThisCharge; return amountPaidOnThisCharge;
} }
public Money getAmountWrittenOff(final MonetaryCurrency currency) { public Money getAmountWrittenOff(final MonetaryCurrency currency) {
return Money.of(currency, this.amountWrittenOff); return Money.of(currency, this.amountWrittenOff);
} }
public void resetPaidAmount(final MonetaryCurrency currency) { public void resetPaidAmount(final MonetaryCurrency currency) {
this.amountPaid = BigDecimal.ZERO; this.amountPaid = BigDecimal.ZERO;
this.amountOutstanding = calculateAmountOutstanding(currency); this.amountOutstanding = calculateAmountOutstanding(currency);
this.paid = false; this.paid = false;
} }
public void resetToOriginal(final MonetaryCurrency currency) { public void resetToOriginal(final MonetaryCurrency currency) {
this.amountPaid = BigDecimal.ZERO; this.amountPaid = BigDecimal.ZERO;
this.amountWaived = BigDecimal.ZERO; this.amountWaived = BigDecimal.ZERO;
@@ -203,7 +202,7 @@ public class LoanInstallmentCharge extends AbstractPersistable<Long> {
this.waived = false; this.waived = false;
} }
public Money getAmountThroughChargePayment(final MonetaryCurrency currency) { public Money getAmountThroughChargePayment(final MonetaryCurrency currency) {
return Money.of(currency, this.amountThroughChargePayment); return Money.of(currency, this.amountThroughChargePayment);
} }
@@ -7,22 +7,15 @@ package org.mifosplatform.portfolio.loanaccount.domain;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom; import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency; import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
@@ -105,7 +98,7 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
@Temporal(TemporalType.DATE) @Temporal(TemporalType.DATE)
@Column(name = "obligations_met_on_date") @Column(name = "obligations_met_on_date")
private Date obligationsMetOnDate; private Date obligationsMetOnDate;
protected LoanRepaymentScheduleInstallment() { protected LoanRepaymentScheduleInstallment() {
this.installmentNumber = null; this.installmentNumber = null;
this.fromDate = null; this.fromDate = null;
@@ -118,8 +111,8 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
final BigDecimal penaltyCharges) { final BigDecimal penaltyCharges) {
this.loan = loan; this.loan = loan;
this.installmentNumber = installmentNumber; this.installmentNumber = installmentNumber;
this.fromDate = fromDate.toDateMidnight().toDate(); this.fromDate = fromDate.toDateTimeAtStartOfDay().toDate();
this.dueDate = dueDate.toDateMidnight().toDate(); this.dueDate = dueDate.toDateTimeAtStartOfDay().toDate();
this.principal = defaultToNullIfZero(principal); this.principal = defaultToNullIfZero(principal);
this.interestCharged = defaultToNullIfZero(interest); this.interestCharged = defaultToNullIfZero(interest);
this.feeChargesCharged = defaultToNullIfZero(feeCharges); this.feeChargesCharged = defaultToNullIfZero(feeCharges);
@@ -133,21 +133,21 @@ public final class LoanTransaction extends AbstractPersistable<Long> {
} }
public static LoanTransaction initiateTransfer(final Office office, final Loan loan, final LocalDate transferDate) { public static LoanTransaction initiateTransfer(final Office office, final Loan loan, final LocalDate transferDate) {
return new LoanTransaction(loan, office, LoanTransactionType.INITIATE_TRANSFER.getValue(), transferDate.toDateMidnight().toDate(), return new LoanTransaction(loan, office, LoanTransactionType.INITIATE_TRANSFER.getValue(), transferDate.toDateTimeAtStartOfDay().toDate(),
loan.getSummary().getTotalOutstanding(), loan.getSummary().getTotalPrincipalOutstanding(), loan.getSummary() loan.getSummary().getTotalOutstanding(), loan.getSummary().getTotalPrincipalOutstanding(), loan.getSummary()
.getTotalInterestOutstanding(), loan.getSummary().getTotalFeeChargesOutstanding(), loan.getSummary() .getTotalInterestOutstanding(), loan.getSummary().getTotalFeeChargesOutstanding(), loan.getSummary()
.getTotalPenaltyChargesOutstanding(), null, false, null,null); .getTotalPenaltyChargesOutstanding(), null, false, null,null);
} }
public static LoanTransaction approveTransfer(final Office office, final Loan loan, final LocalDate transferDate) { public static LoanTransaction approveTransfer(final Office office, final Loan loan, final LocalDate transferDate) {
return new LoanTransaction(loan, office, LoanTransactionType.APPROVE_TRANSFER.getValue(), transferDate.toDateMidnight().toDate(), return new LoanTransaction(loan, office, LoanTransactionType.APPROVE_TRANSFER.getValue(), transferDate.toDateTimeAtStartOfDay().toDate(),
loan.getSummary().getTotalOutstanding(), loan.getSummary().getTotalPrincipalOutstanding(), loan.getSummary() loan.getSummary().getTotalOutstanding(), loan.getSummary().getTotalPrincipalOutstanding(), loan.getSummary()
.getTotalInterestOutstanding(), loan.getSummary().getTotalFeeChargesOutstanding(), loan.getSummary() .getTotalInterestOutstanding(), loan.getSummary().getTotalFeeChargesOutstanding(), loan.getSummary()
.getTotalPenaltyChargesOutstanding(), null, false, null,null); .getTotalPenaltyChargesOutstanding(), null, false, null,null);
} }
public static LoanTransaction withdrawTransfer(final Office office, final Loan loan, final LocalDate transferDate) { public static LoanTransaction withdrawTransfer(final Office office, final Loan loan, final LocalDate transferDate) {
return new LoanTransaction(loan, office, LoanTransactionType.WITHDRAW_TRANSFER.getValue(), transferDate.toDateMidnight().toDate(), return new LoanTransaction(loan, office, LoanTransactionType.WITHDRAW_TRANSFER.getValue(), transferDate.toDateTimeAtStartOfDay().toDate(),
loan.getSummary().getTotalOutstanding(), loan.getSummary().getTotalPrincipalOutstanding(), loan.getSummary() loan.getSummary().getTotalOutstanding(), loan.getSummary().getTotalPrincipalOutstanding(), loan.getSummary()
.getTotalInterestOutstanding(), loan.getSummary().getTotalFeeChargesOutstanding(), loan.getSummary() .getTotalInterestOutstanding(), loan.getSummary().getTotalFeeChargesOutstanding(), loan.getSummary()
.getTotalPenaltyChargesOutstanding(), null, false, null,null); .getTotalPenaltyChargesOutstanding(), null, false, null,null);
@@ -176,18 +176,18 @@ public final class LoanTransaction extends AbstractPersistable<Long> {
public static boolean transactionAmountsMatch(final MonetaryCurrency currency, final LoanTransaction loanTransaction, public static boolean transactionAmountsMatch(final MonetaryCurrency currency, final LoanTransaction loanTransaction,
final LoanTransaction newLoanTransaction) { final LoanTransaction newLoanTransaction) {
if (loanTransaction.getAmount(currency).isEqualTo(newLoanTransaction.getAmount(currency)) if (loanTransaction.getAmount(currency).isEqualTo(newLoanTransaction.getAmount(currency))
&& (loanTransaction.getPrincipalPortion(currency).isEqualTo(newLoanTransaction.getPrincipalPortion(currency))) && loanTransaction.getPrincipalPortion(currency).isEqualTo(newLoanTransaction.getPrincipalPortion(currency))
&& (loanTransaction.getInterestPortion(currency).isEqualTo(newLoanTransaction.getInterestPortion(currency))) && loanTransaction.getInterestPortion(currency).isEqualTo(newLoanTransaction.getInterestPortion(currency))
&& (loanTransaction.getFeeChargesPortion(currency).isEqualTo(newLoanTransaction.getFeeChargesPortion(currency))) && loanTransaction.getFeeChargesPortion(currency).isEqualTo(newLoanTransaction.getFeeChargesPortion(currency))
&& (loanTransaction.getPenaltyChargesPortion(currency).isEqualTo(newLoanTransaction.getPenaltyChargesPortion(currency))) && loanTransaction.getPenaltyChargesPortion(currency).isEqualTo(newLoanTransaction.getPenaltyChargesPortion(currency))
&& (loanTransaction.getOverPaymentPortion(currency).isEqualTo(newLoanTransaction.getOverPaymentPortion(currency)))) { return true; } && loanTransaction.getOverPaymentPortion(currency).isEqualTo(newLoanTransaction.getOverPaymentPortion(currency))) { return true; }
return false; return false;
} }
private LoanTransaction(final Loan loan, final Office office, final Integer typeOf, final Date dateOf, final BigDecimal amount, private LoanTransaction(final Loan loan, final Office office, final Integer typeOf, final Date dateOf, final BigDecimal amount,
final BigDecimal principalPortion, final BigDecimal interestPortion, final BigDecimal feeChargesPortion, final BigDecimal principalPortion, final BigDecimal interestPortion, final BigDecimal feeChargesPortion,
final BigDecimal penaltyChargesPortion, final BigDecimal overPaymentPortion, final boolean reversed, final BigDecimal penaltyChargesPortion, final BigDecimal overPaymentPortion, final boolean reversed,
final PaymentDetail paymentDetail,String externalId) { final PaymentDetail paymentDetail,final String externalId) {
super(); super();
this.loan = loan; this.loan = loan;
this.typeOf = typeOf; this.typeOf = typeOf;
@@ -222,7 +222,7 @@ public final class LoanTransaction extends AbstractPersistable<Long> {
this.loan = loan; this.loan = loan;
this.typeOf = type.getValue(); this.typeOf = type.getValue();
this.amount = amount; this.amount = amount;
this.dateOf = date.toDateMidnight().toDate(); this.dateOf = date.toDateTimeAtStartOfDay().toDate();
this.externalId = externalId; this.externalId = externalId;
this.office = office; this.office = office;
} }
@@ -233,7 +233,7 @@ public final class LoanTransaction extends AbstractPersistable<Long> {
this.typeOf = type.getValue(); this.typeOf = type.getValue();
this.paymentDetail = paymentDetail; this.paymentDetail = paymentDetail;
this.amount = amount; this.amount = amount;
this.dateOf = date.toDateMidnight().toDate(); this.dateOf = date.toDateTimeAtStartOfDay().toDate();
this.externalId = externalId; this.externalId = externalId;
this.office = office; this.office = office;
} }
@@ -256,7 +256,7 @@ public final class LoanTransaction extends AbstractPersistable<Long> {
/** /**
* This updates the derived fields of a loan transaction for the principal, * This updates the derived fields of a loan transaction for the principal,
* interest and interest waived portions. * interest and interest waived portions.
* *
* This accumulates the values passed to the already existent values for * This accumulates the values passed to the already existent values for
* each of the portions. * each of the portions.
*/ */
@@ -503,8 +503,8 @@ public final class LoanTransaction extends AbstractPersistable<Long> {
return LoanTransactionType.REFUND.equals(getTypeOf()) && isNotReversed(); return LoanTransactionType.REFUND.equals(getTypeOf()) && isNotReversed();
} }
public void updateExternalId(String externalId) { public void updateExternalId(final String externalId) {
this.externalId = externalId; this.externalId = externalId;
} }
@@ -73,7 +73,7 @@ public class GuarantorCommand {
} }
public Date getDobAsDate() { public Date getDobAsDate() {
return this.dob.toDateMidnight().toDate(); return this.dob.toDateTimeAtStartOfDay().toDate();
} }
public void validateForCreate() { public void validateForCreate() {
@@ -5,10 +5,8 @@
*/ */
package org.mifosplatform.portfolio.loanaccount.service; package org.mifosplatform.portfolio.loanaccount.service;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -151,7 +149,7 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
this.calendarInstanceRepository = calendarInstanceRepository; this.calendarInstanceRepository = calendarInstanceRepository;
this.savingsAccountAssembler = savingsAccountAssembler; this.savingsAccountAssembler = savingsAccountAssembler;
this.accountAssociationsRepository = accountAssociationsRepository; this.accountAssociationsRepository = accountAssociationsRepository;
this.loanChargeRepository = loanChargeRepository; this.loanChargeRepository = loanChargeRepository;
} }
private LoanLifecycleStateMachine defaultLoanLifecycleStateMachine() { private LoanLifecycleStateMachine defaultLoanLifecycleStateMachine() {
@@ -340,14 +338,14 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
if (changes.containsKey("recalculateLoanSchedule")) { if (changes.containsKey("recalculateLoanSchedule")) {
changes.remove("recalculateLoanSchedule"); changes.remove("recalculateLoanSchedule");
final JsonElement parsedQuery = this.fromJsonHelper.parse(command.json()); final JsonElement parsedQuery = this.fromJsonHelper.parse(command.json());
final JsonQuery query = JsonQuery.from(command.json(), parsedQuery, this.fromJsonHelper); final JsonQuery query = JsonQuery.from(command.json(), parsedQuery, this.fromJsonHelper);
final LoanScheduleModel loanSchedule = this.calculationPlatformService.calculateLoanSchedule(query); final LoanScheduleModel loanSchedule = this.calculationPlatformService.calculateLoanSchedule(query);
existingLoanApplication.updateLoanSchedule(loanSchedule); existingLoanApplication.updateLoanSchedule(loanSchedule);
} }
final String chargesParamName = "charges"; final String chargesParamName = "charges";
if (changes.containsKey(chargesParamName)) { if (changes.containsKey(chargesParamName)) {
final Set<LoanCharge> loanCharges = this.loanChargeAssembler.fromParsedJson(command.parsedJson()); final Set<LoanCharge> loanCharges = this.loanChargeAssembler.fromParsedJson(command.parsedJson());
@@ -361,10 +359,10 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
final Note note = Note.loanNote(existingLoanApplication, submittedOnNote); final Note note = Note.loanNote(existingLoanApplication, submittedOnNote);
this.noteRepository.save(note); this.noteRepository.save(note);
} }
for (final LoanCharge loanCharge : existingLoanApplication.charges()) { for (final LoanCharge loanCharge : existingLoanApplication.charges()) {
if(loanCharge.isInstalmentFee() && loanCharge.hasNoLoanInstallmentCharges()){ if (loanCharge.isInstalmentFee() && loanCharge.hasNoLoanInstallmentCharges()) {
Set<LoanInstallmentCharge> chargePerInstallments = existingLoanApplication.generateInstallmentLoanCharges(loanCharge); final Set<LoanInstallmentCharge> chargePerInstallments = existingLoanApplication.generateInstallmentLoanCharges(loanCharge);
loanCharge.addLoanInstallmentCharges(chargePerInstallments); loanCharge.addLoanInstallmentCharges(chargePerInstallments);
this.loanChargeRepository.save(loanCharge); this.loanChargeRepository.save(loanCharge);
} }
@@ -40,10 +40,10 @@ import com.google.gson.JsonArray;
/** /**
* Loan products allow for categorisation of an organisations loans into * Loan products allow for categorisation of an organisations loans into
* something meaningful to them. * something meaningful to them.
* *
* They provide a means of simplifying creation/maintenance of loans. They can * They provide a means of simplifying creation/maintenance of loans. They can
* also allow for product comparison to take place when reporting. * also allow for product comparison to take place when reporting.
* *
* They allow for constraints to be added at product level. * They allow for constraints to be added at product level.
*/ */
@Entity @Entity
@@ -193,11 +193,11 @@ public class LoanProduct extends AbstractPersistable<Long> {
this.includeInBorrowerCycle = includeInBorrowerCycle; this.includeInBorrowerCycle = includeInBorrowerCycle;
if (startDate != null) { if (startDate != null) {
this.startDate = startDate.toDateMidnight().toDate(); this.startDate = startDate.toDateTimeAtStartOfDay().toDate();
} }
if (closeDate != null) { if (closeDate != null) {
this.closeDate = closeDate.toDateMidnight().toDate(); this.closeDate = closeDate.toDateTimeAtStartOfDay().toDate();
} }
this.externalId = externalId; this.externalId = externalId;
@@ -227,7 +227,7 @@ public class LoanProduct extends AbstractPersistable<Long> {
final Set<Charge> currentSetOfCharges = new HashSet<Charge>(this.charges); final Set<Charge> currentSetOfCharges = new HashSet<Charge>(this.charges);
final Set<Charge> newSetOfCharges = new HashSet<Charge>(newProductCharges); final Set<Charge> newSetOfCharges = new HashSet<Charge>(newProductCharges);
if (!(currentSetOfCharges.equals(newSetOfCharges))) { if (!currentSetOfCharges.equals(newSetOfCharges)) {
updated = true; updated = true;
this.charges = newProductCharges; this.charges = newProductCharges;
} }
@@ -401,7 +401,7 @@ public class LoanProduct extends AbstractPersistable<Long> {
// If all min and max fields are null then loanProductMinMaxConstraints // If all min and max fields are null then loanProductMinMaxConstraints
// initialising to null // initialising to null
// Reset LoanProductMinMaxConstraints with null values. // Reset LoanProductMinMaxConstraints with null values.
this.loanProductMinMaxConstraints = (this.loanProductMinMaxConstraints == null) ? new LoanProductMinMaxConstraints(null, null, this.loanProductMinMaxConstraints = this.loanProductMinMaxConstraints == null ? new LoanProductMinMaxConstraints(null, null,
null, null, null, null) : this.loanProductMinMaxConstraints; null, null, null, null) : this.loanProductMinMaxConstraints;
return this.loanProductMinMaxConstraints; return this.loanProductMinMaxConstraints;
} }