adding maturity for deposit account

This commit is contained in:
Madhukar
2012-09-13 10:07:47 +05:30
parent 1fe9856eb2
commit 1957dba4ac
4 changed files with 81 additions and 1 deletions
@@ -205,6 +205,9 @@ public class DepositAccountsApiResource {
} else if (is(commandParam, "withdrewbyclient")) {
EntityIdentifier identifier = this.depositAccountWritePlatformService.withdrawDepositApplication(command);
response = Response.ok().entity(identifier).build();
} else if (is(commandParam, "matureAccount")){
EntityIdentifier identifier = this.depositAccountWritePlatformService.matureDepositApplication(command);
response = Response.ok().entity(identifier).build();
}
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(accountId, command.getNote());
@@ -289,6 +289,14 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
}
return date;
}
public LocalDate getMaturityDate() {
LocalDate date = null;
if (this.maturesOnDate != null) {
date = new LocalDate(this.maturesOnDate);
}
return date;
}
public void reject(final LocalDate rejectedOn,
final DepositLifecycleStateMachine depositLifecycleStateMachine) {
@@ -373,4 +381,39 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
public Client client() {
return this.client;
}
public void matureDepositApplication(LocalDate maturedOnDate, DepositLifecycleStateMachine depositLifecycleStateMachine) {
if (maturedOnDate.isAfter(maturesOnDate()) || new LocalDate().equals(maturesOnDate())) {
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(
DepositAccountEvent.DEPOSIT_MATURED,
DepositAccountStatus.fromInt(this.depositStatus));
this.depositStatus = statusEnum.getValue();
if(!this.renewalAllowed){
DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.withdraw(Money.of(this.currency, this.total), maturedOnDate);
depositaccountTransaction.updateAccount(this);
this.depositaccountTransactions.add(depositaccountTransaction);
}
}
if (maturesOnDate().isBefore(new LocalDate())) {
final String errorMessage = "The date on which a deposit is rejected cannot be before its submittal date: "
+ new LocalDate().toString();
throw new InvalidDepositStateTransitionException("reject",
"cannot.be.before.submittal.date", errorMessage,
maturedOnDate, new LocalDate());
}
}
public LocalDate maturesOnDate() {
LocalDate date = null;
if (this.maturesOnDate != null) {
date = new LocalDate(this.maturesOnDate);
}
return date;
}
}
@@ -27,4 +27,7 @@ public interface DepositAccountWritePlatformService {
@PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE', 'CAN_APPROVE_DEPOSIT_ROLE', 'CAN_APPROVE_DEPOSIT_IN_THE_PAST_ROLE')")
EntityIdentifier undoDepositApproval(UndoStateTransitionCommand undoCommand);
@PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE', 'CAN_APPROVE_DEPOSIT_ROLE', 'CAN_APPROVE_DEPOSIT_IN_THE_PAST_ROLE')")
EntityIdentifier matureDepositApplication(DepositStateTransitionCommand command);
}
@@ -18,9 +18,9 @@ import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
import org.mifosng.platform.exceptions.ProductNotFoundException;
import org.mifosng.platform.saving.domain.DepositAccount;
import org.mifosng.platform.saving.domain.DepositAccountRepository;
import org.mifosng.platform.saving.domain.DepositAccountStatus;
import org.mifosng.platform.saving.domain.DepositLifecycleStateMachine;
import org.mifosng.platform.saving.domain.DepositLifecycleStateMachineImpl;
import org.mifosng.platform.saving.domain.DepositAccountStatus;
import org.mifosng.platform.saving.domain.FixedTermDepositInterestCalculator;
import org.mifosng.platform.security.PlatformSecurityContext;
import org.mifosng.platform.user.domain.AppUser;
@@ -234,4 +234,35 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
}
return new EntityIdentifier(account.getId());
}
@Transactional
@Override
public EntityIdentifier matureDepositApplication(DepositStateTransitionCommand command) {
AppUser currentUser = context.authenticatedUser();
DepositStateTransitionCommandValidator validator = new DepositStateTransitionCommandValidator(command);
validator.validate();
DepositAccount account = this.depositAccountRepository.findOne(command.getAccountId());
if (account == null || account.isDeleted()) {
throw new DepositAccountNotFoundException(command.getAccountId());
}
LocalDate eventDate = command.getEventDate();
if (this.isBeforeToday(eventDate) && currentUser.canNotApproveLoanInPast()) {
throw new NoAuthorizationException("User has no authority to mature deposit with a date in the past.");
}
account.matureDepositApplication(eventDate, defaultDepositLifecycleStateMachine());
this.depositAccountRepository.save(account);
String noteText = command.getNote();
if (StringUtils.isNotBlank(noteText)) {
Note note = Note.depositNote(account, noteText);
this.noteRepository.save(note);
}
return new EntityIdentifier(account.getId());
}
}