Withdraw of deposit amount
This commit is contained in:
+8
-2
@@ -21,6 +21,7 @@ import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.api.commands.DepositAccountWithdrawalCommand;
|
||||
import org.mifosng.platform.api.commands.DepositStateTransitionApprovalCommand;
|
||||
import org.mifosng.platform.api.commands.DepositStateTransitionCommand;
|
||||
import org.mifosng.platform.api.commands.UndoStateTransitionCommand;
|
||||
@@ -196,6 +197,10 @@ public class DepositAccountsApiResource {
|
||||
DepositStateTransitionApprovalCommand command=apiDataConversionService.convertJsonToDepositStateTransitionApprovalCommand(accountId, jsonRequestBody);
|
||||
EntityIdentifier identifier = this.depositAccountWritePlatformService.approveDepositApplication(command);
|
||||
response = Response.ok().entity(identifier).build();
|
||||
} else if(is(commandParam, "withdrawal")){
|
||||
DepositAccountWithdrawalCommand command = apiDataConversionService.convertJsonToDepositWithdrawalCommand(accountId, jsonRequestBody);
|
||||
EntityIdentifier identifier = this.depositAccountWritePlatformService.withdrawDepositAccountMoney(command);
|
||||
response = Response.ok().entity(identifier).build();
|
||||
} else {
|
||||
DepositStateTransitionCommand command=apiDataConversionService.convertJsonToDepositStateTransitionCommand(accountId, jsonRequestBody);
|
||||
if (is(commandParam, "reject")) {
|
||||
@@ -204,9 +209,10 @@ public class DepositAccountsApiResource {
|
||||
} else if (is(commandParam, "withdrewbyclient")) {
|
||||
EntityIdentifier identifier = this.depositAccountWritePlatformService.withdrawDepositApplication(command);
|
||||
response = Response.ok().entity(identifier).build();
|
||||
} else if (is(commandParam, "mature")){
|
||||
/*} else if (is(commandParam, "withdrawal")){
|
||||
EntityIdentifier identifier = this.depositAccountWritePlatformService.matureDepositApplication(command);
|
||||
response = Response.ok().entity(identifier).build(); }
|
||||
response = Response.ok().entity(identifier).build();*/
|
||||
}
|
||||
|
||||
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(accountId, command.getNote());
|
||||
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package org.mifosng.platform.api.commands;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class DepositAccountWithdrawalCommand {
|
||||
|
||||
private final Long accountId;
|
||||
private final boolean renewAccount;
|
||||
private final BigDecimal deposit;
|
||||
|
||||
private final String note;
|
||||
|
||||
public DepositAccountWithdrawalCommand(final Long accountId, final boolean renewAccount, final BigDecimal deposit, final String note) {
|
||||
this.accountId = accountId;
|
||||
this.renewAccount = renewAccount;
|
||||
this.deposit = deposit;
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
public Long getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public boolean isRenewAccount() {
|
||||
return renewAccount;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public BigDecimal getDeposit() {
|
||||
return deposit;
|
||||
}
|
||||
}
|
||||
+3
@@ -5,6 +5,7 @@ import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
|
||||
import org.mifosng.platform.api.commands.ChargeCommand;
|
||||
import org.mifosng.platform.api.commands.ClientCommand;
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.api.commands.DepositAccountWithdrawalCommand;
|
||||
import org.mifosng.platform.api.commands.DepositProductCommand;
|
||||
import org.mifosng.platform.api.commands.DepositStateTransitionApprovalCommand;
|
||||
import org.mifosng.platform.api.commands.DepositStateTransitionCommand;
|
||||
@@ -66,4 +67,6 @@ public interface ApiDataConversionService {
|
||||
DepositStateTransitionApprovalCommand convertJsonToDepositStateTransitionApprovalCommand(Long resourceIdentifier, String jsonRequestBody);
|
||||
|
||||
StaffCommand convertJsonToStaffCommand(Long resourceIdentifier, String json);
|
||||
|
||||
DepositAccountWithdrawalCommand convertJsonToDepositWithdrawalCommand(Long resourceIdentifier, String jsonRequestBody);
|
||||
}
|
||||
+24
@@ -22,6 +22,7 @@ import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
|
||||
import org.mifosng.platform.api.commands.ChargeCommand;
|
||||
import org.mifosng.platform.api.commands.ClientCommand;
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.api.commands.DepositAccountWithdrawalCommand;
|
||||
import org.mifosng.platform.api.commands.DepositProductCommand;
|
||||
import org.mifosng.platform.api.commands.DepositStateTransitionApprovalCommand;
|
||||
import org.mifosng.platform.api.commands.DepositStateTransitionCommand;
|
||||
@@ -1144,4 +1145,27 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
||||
|
||||
return new DepositStateTransitionApprovalCommand(resourceIdentifier, productId, commencementDate, tenureInMonths, deposit, interestCompoundedEveryPeriodType,interestCompoundedEvery, note);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DepositAccountWithdrawalCommand convertJsonToDepositWithdrawalCommand(final Long resourceIdentifier, final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) {
|
||||
throw new InvalidJsonException();
|
||||
}
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, String>>(){}.getType();
|
||||
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
Set<String> supportedParams = new HashSet<String>(Arrays.asList("renewAccount","deposit", "note"));
|
||||
|
||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||
|
||||
Set<String> modifiedParameters = new HashSet<String>();
|
||||
|
||||
BigDecimal deposit=extractBigDecimalParameter("deposit", requestMap, modifiedParameters);
|
||||
boolean renewAccount=extractBooleanParameter("renewAccount", requestMap, modifiedParameters);
|
||||
String note = extractStringParameter("note", requestMap, modifiedParameters);
|
||||
|
||||
return new DepositAccountWithdrawalCommand(resourceIdentifier,renewAccount, deposit, note);
|
||||
}
|
||||
}
|
||||
@@ -300,6 +300,10 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
|
||||
return date;
|
||||
}
|
||||
|
||||
public BigDecimal getProjectedTotalOnMaturity() {
|
||||
return projectedTotalOnMaturity;
|
||||
}
|
||||
|
||||
public void reject(final LocalDate rejectedOn,
|
||||
final DepositLifecycleStateMachine depositLifecycleStateMachine) {
|
||||
|
||||
@@ -466,4 +470,50 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
|
||||
this.renewdAccount = account;
|
||||
|
||||
}
|
||||
|
||||
public void withdrawDepositAccountMoney(boolean renewAccount, DepositLifecycleStateMachine depositLifecycleStateMachine) {
|
||||
|
||||
if (new LocalDate().isAfter(maturesOnDate()) || new LocalDate().equals(maturesOnDate())) {
|
||||
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(
|
||||
DepositAccountEvent.DEPOSIT_MATURED,
|
||||
DepositAccountStatus.fromInt(this.depositStatus));
|
||||
this.depositStatus = statusEnum.getValue();
|
||||
|
||||
if(!renewAccount){
|
||||
DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.withdraw(Money.of(this.currency, this.total), new LocalDate());
|
||||
depositaccountTransaction.updateAccount(this);
|
||||
this.depositaccountTransactions.add(depositaccountTransaction);
|
||||
|
||||
DepositAccountStatus statusEnumForClose = depositLifecycleStateMachine.transition(
|
||||
DepositAccountEvent.DEPOSIT_CLOSED,
|
||||
DepositAccountStatus.fromInt(this.depositStatus));
|
||||
this.depositStatus = statusEnumForClose.getValue();
|
||||
|
||||
this.depositAmount = null;
|
||||
this.interestRate = null;
|
||||
this.tenureInMonths = null;
|
||||
this.interestCompoundedEvery = null;
|
||||
this.interestCompoundedFrequencyType = null;
|
||||
this.closedOnDate = new LocalDate().toDate();
|
||||
this.withdrawnOnDate = null;
|
||||
this.rejectedOnDate = null;
|
||||
|
||||
}else if(renewAccount){
|
||||
DepositAccountStatus statusEnumForClose = depositLifecycleStateMachine.transition(
|
||||
DepositAccountEvent.DEPOSIT_CLOSED,
|
||||
DepositAccountStatus.fromInt(this.depositStatus));
|
||||
this.depositStatus = statusEnumForClose.getValue();
|
||||
|
||||
DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.withdraw(Money.of(this.currency, this.total), new LocalDate());
|
||||
depositaccountTransaction.updateAccount(this);
|
||||
this.depositaccountTransactions.add(depositaccountTransaction);
|
||||
|
||||
this.closedOnDate = new LocalDate().toDate();
|
||||
this.withdrawnOnDate = null;
|
||||
this.rejectedOnDate = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -110,13 +110,13 @@ public class DepositAccountAssembler {
|
||||
return new DepositLifecycleStateMachineImpl(allowedDepositStatuses);
|
||||
}
|
||||
|
||||
public DepositAccount assembleFrom(DepositAccount account) {
|
||||
public DepositAccount assembleFrom(DepositAccount account, BigDecimal newDepositAmount) {
|
||||
|
||||
Client client = account.client();
|
||||
|
||||
DepositProduct product = account.product();
|
||||
|
||||
Money deposit = Money.of(product.getCurrency(), account.getDeposit().getAmount());
|
||||
Money deposit = Money.of(product.getCurrency(), newDepositAmount);
|
||||
|
||||
Integer tenureInMonths = product.getTenureInMonths();
|
||||
|
||||
|
||||
+5
@@ -1,6 +1,7 @@
|
||||
package org.mifosng.platform.saving.service;
|
||||
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.api.commands.DepositAccountWithdrawalCommand;
|
||||
import org.mifosng.platform.api.commands.DepositStateTransitionApprovalCommand;
|
||||
import org.mifosng.platform.api.commands.DepositStateTransitionCommand;
|
||||
import org.mifosng.platform.api.commands.UndoStateTransitionCommand;
|
||||
@@ -30,4 +31,8 @@ public interface DepositAccountWritePlatformService {
|
||||
@PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE', 'CAN_APPROVE_DEPOSIT_ROLE', 'CAN_APPROVE_DEPOSIT_IN_THE_PAST_ROLE')")
|
||||
EntityIdentifier matureDepositApplication(DepositStateTransitionCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE', 'CAN_APPROVE_DEPOSIT_ROLE', 'CAN_APPROVE_DEPOSIT_IN_THE_PAST_ROLE')")
|
||||
EntityIdentifier withdrawDepositAccountMoney(DepositAccountWithdrawalCommand command);
|
||||
|
||||
|
||||
}
|
||||
|
||||
+37
-2
@@ -1,11 +1,13 @@
|
||||
package org.mifosng.platform.saving.service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.api.commands.DepositAccountWithdrawalCommand;
|
||||
import org.mifosng.platform.api.commands.DepositStateTransitionApprovalCommand;
|
||||
import org.mifosng.platform.api.commands.DepositStateTransitionCommand;
|
||||
import org.mifosng.platform.api.commands.UndoStateTransitionCommand;
|
||||
@@ -257,11 +259,12 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
||||
account.matureDepositApplication(eventDate, defaultDepositLifecycleStateMachine());
|
||||
this.depositAccountRepository.save(account);
|
||||
|
||||
if(account.isRenewalAllowed()){
|
||||
/*if(account.isRenewalAllowed()){
|
||||
final DepositAccount renewedAccount = this.depositAccountAssembler.assembleFrom(account);
|
||||
this.depositAccountRepository.save(renewedAccount);
|
||||
return new EntityIdentifier(renewedAccount.getId()); //returns the new deposit application id
|
||||
}
|
||||
}*/
|
||||
|
||||
String noteText = command.getNote();
|
||||
if (StringUtils.isNotBlank(noteText)) {
|
||||
Note note = Note.depositNote(account, noteText);
|
||||
@@ -270,4 +273,36 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
||||
|
||||
return new EntityIdentifier(account.getId());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier withdrawDepositAccountMoney(DepositAccountWithdrawalCommand command) {
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
DepositAccount account = this.depositAccountRepository.findOne(command.getAccountId());
|
||||
if (account == null || account.isDeleted()) {
|
||||
throw new DepositAccountNotFoundException(command.getAccountId());
|
||||
}
|
||||
|
||||
account.withdrawDepositAccountMoney(command.isRenewAccount(), defaultDepositLifecycleStateMachine());
|
||||
this.depositAccountRepository.save(account);
|
||||
|
||||
BigDecimal deposit = account.getProjectedTotalOnMaturity();
|
||||
if(command.getDeposit() != null)
|
||||
deposit = command.getDeposit();
|
||||
|
||||
if(command.isRenewAccount()){
|
||||
final DepositAccount renewedAccount = this.depositAccountAssembler.assembleFrom(account,deposit);
|
||||
this.depositAccountRepository.save(renewedAccount);
|
||||
return new EntityIdentifier(renewedAccount.getId()); //returns the new deposit application id
|
||||
}
|
||||
|
||||
String noteText = command.getNote();
|
||||
if (StringUtils.isNotBlank(noteText)) {
|
||||
Note note = Note.depositNote(account, noteText);
|
||||
this.noteRepository.save(note);
|
||||
}
|
||||
return new EntityIdentifier(account.getId());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user