MIFOSX-1398,MIFOSX-1403
This commit is contained in:
+20
-8
@@ -37,6 +37,7 @@ import org.mifosplatform.portfolio.loanaccount.domain.LoanTransaction;
|
||||
import org.mifosplatform.portfolio.loanaccount.domain.LoanTransactionType;
|
||||
import org.mifosplatform.portfolio.loanaccount.service.LoanAssembler;
|
||||
import org.mifosplatform.portfolio.paymentdetail.domain.PaymentDetail;
|
||||
import org.mifosplatform.portfolio.savings.SavingsTransactionBooleanValues;
|
||||
import org.mifosplatform.portfolio.savings.domain.SavingsAccount;
|
||||
import org.mifosplatform.portfolio.savings.domain.SavingsAccountAssembler;
|
||||
import org.mifosplatform.portfolio.savings.domain.SavingsAccountDomainService;
|
||||
@@ -102,14 +103,17 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
||||
boolean isInterestTransfer = false;
|
||||
boolean isAccountTransfer = true;
|
||||
Long fromLoanAccountId = null;
|
||||
boolean isWithdrawBalance = false;
|
||||
|
||||
if (isSavingsToSavingsAccountTransfer(fromAccountType, toAccountType)) {
|
||||
|
||||
fromSavingsAccountId = command.longValueOfParameterNamed(fromAccountIdParamName);
|
||||
final SavingsAccount fromSavingsAccount = this.savingsAccountAssembler.assembleFrom(fromSavingsAccountId);
|
||||
|
||||
final SavingsTransactionBooleanValues transactionBooleanValues = new SavingsTransactionBooleanValues(isAccountTransfer,
|
||||
isRegularTransaction, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer(), isInterestTransfer, isWithdrawBalance);
|
||||
final SavingsAccountTransaction withdrawal = this.savingsAccountDomainService.handleWithdrawal(fromSavingsAccount, fmt,
|
||||
transactionDate, transactionAmount, paymentDetail, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer(),
|
||||
isInterestTransfer, isAccountTransfer, isRegularTransaction);
|
||||
transactionDate, transactionAmount, paymentDetail, transactionBooleanValues);
|
||||
|
||||
final Long toSavingsId = command.longValueOfParameterNamed(toAccountIdParamName);
|
||||
final SavingsAccount toSavingsAccount = this.savingsAccountAssembler.assembleFrom(toSavingsId);
|
||||
@@ -127,9 +131,10 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
||||
fromSavingsAccountId = command.longValueOfParameterNamed(fromAccountIdParamName);
|
||||
final SavingsAccount fromSavingsAccount = this.savingsAccountAssembler.assembleFrom(fromSavingsAccountId);
|
||||
|
||||
final SavingsTransactionBooleanValues transactionBooleanValues = new SavingsTransactionBooleanValues(isAccountTransfer,
|
||||
isRegularTransaction, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer(), isInterestTransfer, isWithdrawBalance);
|
||||
final SavingsAccountTransaction withdrawal = this.savingsAccountDomainService.handleWithdrawal(fromSavingsAccount, fmt,
|
||||
transactionDate, transactionAmount, paymentDetail, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer(),
|
||||
isInterestTransfer, isAccountTransfer, isRegularTransaction);
|
||||
transactionDate, transactionAmount, paymentDetail, transactionBooleanValues);
|
||||
|
||||
final Long toLoanAccountId = command.longValueOfParameterNamed(toAccountIdParamName);
|
||||
final Loan toLoanAccount = this.loanAccountAssembler.assembleFrom(toLoanAccountId);
|
||||
@@ -235,6 +240,7 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
||||
public Long transferFunds(final AccountTransferDTO accountTransferDTO) {
|
||||
Long transferTransactionId = null;
|
||||
final boolean isAccountTransfer = true;
|
||||
final boolean isWithdrawBalance = false;
|
||||
final boolean isRegularTransaction = accountTransferDTO.isRegularTransaction();
|
||||
AccountTransferDetails accountTransferDetails = accountTransferDTO.getAccountTransferDetails();
|
||||
if (isSavingsToLoanAccountTransfer(accountTransferDTO.getFromAccountType(), accountTransferDTO.getToAccountType())) {
|
||||
@@ -251,10 +257,13 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
||||
this.loanAccountAssembler.setHelpers(toLoanAccount);
|
||||
}
|
||||
|
||||
final SavingsTransactionBooleanValues transactionBooleanValues = new SavingsTransactionBooleanValues(isAccountTransfer,
|
||||
isRegularTransaction, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer(), AccountTransferType.fromInt(
|
||||
accountTransferDTO.getTransferType()).isInterestTransfer(), isWithdrawBalance);
|
||||
|
||||
final SavingsAccountTransaction withdrawal = this.savingsAccountDomainService.handleWithdrawal(fromSavingsAccount,
|
||||
accountTransferDTO.getFmt(), accountTransferDTO.getTransactionDate(), accountTransferDTO.getTransactionAmount(),
|
||||
accountTransferDTO.getPaymentDetail(), fromSavingsAccount.isWithdrawalFeeApplicableForTransfer(), AccountTransferType
|
||||
.fromInt(accountTransferDTO.getTransferType()).isInterestTransfer(), isAccountTransfer, isRegularTransaction);
|
||||
accountTransferDTO.getPaymentDetail(), transactionBooleanValues);
|
||||
|
||||
LoanTransaction loanTransaction = null;
|
||||
|
||||
@@ -297,10 +306,13 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
||||
this.savingsAccountAssembler.setHelpers(toSavingsAccount);
|
||||
}
|
||||
|
||||
final SavingsTransactionBooleanValues transactionBooleanValues = new SavingsTransactionBooleanValues(isAccountTransfer,
|
||||
isRegularTransaction, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer(), AccountTransferType.fromInt(
|
||||
accountTransferDTO.getTransferType()).isInterestTransfer(), isWithdrawBalance);
|
||||
|
||||
final SavingsAccountTransaction withdrawal = this.savingsAccountDomainService.handleWithdrawal(fromSavingsAccount,
|
||||
accountTransferDTO.getFmt(), accountTransferDTO.getTransactionDate(), accountTransferDTO.getTransactionAmount(),
|
||||
accountTransferDTO.getPaymentDetail(), fromSavingsAccount.isWithdrawalFeeApplicableForTransfer(), AccountTransferType
|
||||
.fromInt(accountTransferDTO.getTransferType()).isInterestTransfer(), isAccountTransfer, isRegularTransaction);
|
||||
accountTransferDTO.getPaymentDetail(), transactionBooleanValues);
|
||||
|
||||
final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount,
|
||||
accountTransferDTO.getFmt(), accountTransferDTO.getTransactionDate(), accountTransferDTO.getTransactionAmount(),
|
||||
|
||||
+11
-4
@@ -57,7 +57,9 @@ public class StandingInstructionHistoryReadPlatformServiceImpl implements Standi
|
||||
sqlBuilder.append("select SQL_CALC_FOUND_ROWS ");
|
||||
sqlBuilder.append(this.standingInstructionHistoryMapper.schema());
|
||||
if (standingInstructionDTO.transferType() != null || standingInstructionDTO.clientId() != null
|
||||
|| standingInstructionDTO.clientName() != null) {
|
||||
|| standingInstructionDTO.clientName() != null
|
||||
|| (standingInstructionDTO.fromAccountType() != null && standingInstructionDTO.fromAccount() != null)
|
||||
|| standingInstructionDTO.startDateRange() != null || standingInstructionDTO.endDateRange() != null) {
|
||||
sqlBuilder.append(" where ");
|
||||
}
|
||||
boolean addAndCaluse = false;
|
||||
@@ -108,11 +110,16 @@ public class StandingInstructionHistoryReadPlatformServiceImpl implements Standi
|
||||
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
sqlBuilder.append(" atsih.execution_time >= ? ");
|
||||
paramObj.add(df.format(standingInstructionDTO.startDateRange()));
|
||||
if (standingInstructionDTO.endDateRange() != null) {
|
||||
addAndCaluse = true;
|
||||
}
|
||||
|
||||
if (standingInstructionDTO.endDateRange() != null) {
|
||||
if (addAndCaluse) {
|
||||
sqlBuilder.append(" and ");
|
||||
sqlBuilder.append(" atsih.execution_time < ? ");
|
||||
paramObj.add(df.format(standingInstructionDTO.endDateRange()));
|
||||
}
|
||||
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
sqlBuilder.append(" atsih.execution_time < ? ");
|
||||
paramObj.add(df.format(standingInstructionDTO.endDateRange()));
|
||||
addAndCaluse = true;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -248,7 +248,7 @@ public class LoanEnumerations {
|
||||
break;
|
||||
case DISBURSEMENT:
|
||||
optionData = new LoanTransactionEnumData(LoanTransactionType.DISBURSEMENT.getValue().longValue(),
|
||||
LoanTransactionType.DISBURSEMENT.getCode(), "Dibursement");
|
||||
LoanTransactionType.DISBURSEMENT.getCode(), "Disbursement");
|
||||
break;
|
||||
case REPAYMENT:
|
||||
optionData = new LoanTransactionEnumData(LoanTransactionType.REPAYMENT.getValue().longValue(),
|
||||
|
||||
+3
-1
@@ -98,6 +98,7 @@ public class SavingsApiConstants {
|
||||
public static final String minRequiredBalanceParamName = "minRequiredBalance";
|
||||
public static final String enforceMinRequiredBalanceParamName = "enforceMinRequiredBalance";
|
||||
public static final String minBalanceForInterestCalculationParamName = "minBalanceForInterestCalculation";
|
||||
public static final String withdrawBalanceParamName = "withdrawBalance";
|
||||
|
||||
// transaction parameters
|
||||
public static final String transactionDateParamName = "transactionDate";
|
||||
@@ -206,7 +207,8 @@ public class SavingsApiConstants {
|
||||
dateFormatParamName, activatedOnDateParamName));
|
||||
|
||||
public static final Set<String> SAVINGS_ACCOUNT_CLOSE_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName,
|
||||
dateFormatParamName, closedOnDateParamName, noteParamName));
|
||||
dateFormatParamName, closedOnDateParamName, noteParamName, paymentTypeIdParamName, withdrawBalanceParamName,
|
||||
transactionAccountNumberParamName, checkNumberParamName, routingCodeParamName, receiptNumberParamName, bankNumberParamName));
|
||||
|
||||
public static final Set<String> SAVINGS_ACCOUNT_CHARGES_RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList(chargeIdParamName,
|
||||
savingsAccountChargeIdParamName, chargeNameParamName, penaltyParamName, chargeTimeTypeParamName, dueAsOfDateParamName,
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package org.mifosplatform.portfolio.savings;
|
||||
|
||||
public class SavingsTransactionBooleanValues {
|
||||
|
||||
private final boolean isAccountTransfer;
|
||||
private final boolean isRegularTransaction;
|
||||
private final boolean isApplyWithdrawFee;
|
||||
private final boolean isInterestTransfer;
|
||||
private final boolean isWithdrawBalance;
|
||||
|
||||
public SavingsTransactionBooleanValues(final boolean isAccountTransfer, final boolean isRegularTransaction,
|
||||
final boolean isApplyWithdrawFee, final boolean isInterestTransfer, final boolean isWithdrawBalance) {
|
||||
|
||||
this.isAccountTransfer = isAccountTransfer;
|
||||
this.isRegularTransaction = isRegularTransaction;
|
||||
this.isApplyWithdrawFee = isApplyWithdrawFee;
|
||||
this.isInterestTransfer = isInterestTransfer;
|
||||
this.isWithdrawBalance = isWithdrawBalance;
|
||||
}
|
||||
|
||||
public boolean isAccountTransfer() {
|
||||
return this.isAccountTransfer;
|
||||
}
|
||||
|
||||
public boolean isRegularTransaction() {
|
||||
return this.isRegularTransaction;
|
||||
}
|
||||
|
||||
public boolean isApplyWithdrawFee() {
|
||||
return this.isApplyWithdrawFee;
|
||||
}
|
||||
|
||||
public boolean isInterestTransfer() {
|
||||
return this.isInterestTransfer;
|
||||
}
|
||||
|
||||
public boolean isWithdrawBalance() {
|
||||
return this.isWithdrawBalance;
|
||||
}
|
||||
|
||||
}
|
||||
+26
-13
@@ -15,6 +15,7 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.routingCod
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.transactionAccountNumberParamName;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.transactionAmountParamName;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.transactionDateParamName;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawBalanceParamName;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
@@ -71,17 +72,8 @@ public class SavingsAccountTransactionDataValidator {
|
||||
|
||||
final BigDecimal transactionAmount = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(transactionAmountParamName, element);
|
||||
baseDataValidator.reset().parameter(transactionAmountParamName).value(transactionAmount).notNull().positiveAmount();
|
||||
|
||||
// Validate all string payment detail fields for max length
|
||||
final Integer paymentTypeId = this.fromApiJsonHelper.extractIntegerWithLocaleNamed(paymentTypeIdParamName, element);
|
||||
baseDataValidator.reset().parameter(paymentTypeIdParamName).value(paymentTypeId).ignoreIfNull().integerGreaterThanZero();
|
||||
final Set<String> paymentDetailParameters = new HashSet<>(Arrays.asList(transactionAccountNumberParamName,
|
||||
checkNumberParamName, routingCodeParamName, receiptNumberParamName, bankNumberParamName));
|
||||
for (final String paymentDetailParameterName : paymentDetailParameters) {
|
||||
final String paymentDetailParameterValue = this.fromApiJsonHelper.extractStringNamed(paymentDetailParameterName, element);
|
||||
baseDataValidator.reset().parameter(paymentDetailParameterName).value(paymentDetailParameterValue).ignoreIfNull()
|
||||
.notExceedingLengthOf(50);
|
||||
}
|
||||
|
||||
validatePaymentTypeDetails(baseDataValidator, element);
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
@@ -122,12 +114,33 @@ public class SavingsAccountTransactionDataValidator {
|
||||
|
||||
final JsonElement element = command.parsedJson();
|
||||
|
||||
final LocalDate activationDate = this.fromApiJsonHelper.extractLocalDateNamed(closedOnDateParamName, element);
|
||||
baseDataValidator.reset().parameter(closedOnDateParamName).value(activationDate).notNull();
|
||||
final LocalDate closedonDate = this.fromApiJsonHelper.extractLocalDateNamed(closedOnDateParamName, element);
|
||||
baseDataValidator.reset().parameter(closedOnDateParamName).value(closedonDate).notNull();
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(withdrawBalanceParamName, element)) {
|
||||
final Boolean withdrawBalance = this.fromApiJsonHelper.extractBooleanNamed(withdrawBalanceParamName, element);
|
||||
baseDataValidator.reset().parameter(withdrawBalanceParamName).value(withdrawBalance).isOneOfTheseValues(true, false);
|
||||
}
|
||||
|
||||
validatePaymentTypeDetails(baseDataValidator, element);
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
private void validatePaymentTypeDetails(final DataValidatorBuilder baseDataValidator, JsonElement element) {
|
||||
// Validate all string payment detail fields for max length
|
||||
final Integer paymentTypeId = this.fromApiJsonHelper.extractIntegerWithLocaleNamed(paymentTypeIdParamName, element);
|
||||
baseDataValidator.reset().parameter(paymentTypeIdParamName).value(paymentTypeId).ignoreIfNull().integerGreaterThanZero();
|
||||
final Set<String> paymentDetailParameters = new HashSet<>(Arrays.asList(transactionAccountNumberParamName, checkNumberParamName,
|
||||
routingCodeParamName, receiptNumberParamName, bankNumberParamName));
|
||||
for (final String paymentDetailParameterName : paymentDetailParameters) {
|
||||
final String paymentDetailParameterValue = this.fromApiJsonHelper.extractStringNamed(paymentDetailParameterName, element);
|
||||
baseDataValidator.reset().parameter(paymentDetailParameterName).value(paymentDetailParameterValue).ignoreIfNull()
|
||||
.notExceedingLengthOf(50);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
||||
if (!dataValidationErrors.isEmpty()) {
|
||||
//
|
||||
|
||||
+22
-1
@@ -37,6 +37,7 @@ import org.mifosplatform.portfolio.savings.DepositAccountOnClosureType;
|
||||
import org.mifosplatform.portfolio.savings.DepositAccountType;
|
||||
import org.mifosplatform.portfolio.savings.DepositsApiConstants;
|
||||
import org.mifosplatform.portfolio.savings.SavingsApiConstants;
|
||||
import org.mifosplatform.portfolio.savings.SavingsTransactionBooleanValues;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -76,8 +77,12 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi
|
||||
final boolean applyWithdrawFee, final boolean isRegularTransaction) {
|
||||
boolean isAccountTransfer = false;
|
||||
boolean isInterestTransfer = false;
|
||||
boolean isWithdrawBalance = false;
|
||||
|
||||
SavingsTransactionBooleanValues transactionBooleanValues = new SavingsTransactionBooleanValues(isAccountTransfer,
|
||||
isRegularTransaction, applyWithdrawFee, isInterestTransfer, isWithdrawBalance);
|
||||
return this.savingsAccountDomainService.handleWithdrawal(account, fmt, transactionDate, transactionAmount, paymentDetail,
|
||||
applyWithdrawFee, isInterestTransfer, isAccountTransfer, isRegularTransaction);
|
||||
transactionBooleanValues);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -164,6 +169,10 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi
|
||||
savingsTransactionId = withdrawal.getId();
|
||||
}
|
||||
|
||||
/***
|
||||
* Update account transactionIds for post journal entries.
|
||||
*/
|
||||
updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
|
||||
account.close(user, command, tenantsTodayDate, changes);
|
||||
this.savingsAccountRepository.save(account);
|
||||
|
||||
@@ -230,6 +239,10 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi
|
||||
savingsTransactionId = withdrawal.getId();
|
||||
}
|
||||
|
||||
/***
|
||||
* Update account transactionIds for post journal entries.
|
||||
*/
|
||||
updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
|
||||
account.close(user, command, tenantsTodayDate, changes);
|
||||
|
||||
this.savingsAccountRepository.save(account);
|
||||
@@ -286,6 +299,10 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi
|
||||
savingsTransactionId = withdrawal.getId();
|
||||
}
|
||||
|
||||
/***
|
||||
* Update account transactionIds for post journal entries.
|
||||
*/
|
||||
updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
|
||||
account.prematureClosure(user, command, tenantsTodayDate, changes);
|
||||
|
||||
this.savingsAccountRepository.save(account);
|
||||
@@ -331,6 +348,10 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi
|
||||
savingsTransactionId = withdrawal.getId();
|
||||
}
|
||||
|
||||
/***
|
||||
* Update account transactionIds for post journal entries.
|
||||
*/
|
||||
updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
|
||||
account.prematureClosure(user, command, tenantsTodayDate, changes);
|
||||
this.savingsAccountRepository.save(account);
|
||||
postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds, isAccountTransfer);
|
||||
|
||||
+2
-2
@@ -790,7 +790,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
return transactionBeforeLastInterestPosting;
|
||||
}
|
||||
|
||||
public void validateAccountBalanceDoesNotBecomeNegative(final BigDecimal transactionAmount) {
|
||||
public void validateAccountBalanceDoesNotBecomeNegative(final BigDecimal transactionAmount, final boolean isWithdrawBalance) {
|
||||
final List<SavingsAccountTransaction> transactionsSortedByDate = retreiveListOfTransactions();
|
||||
Money runningBalance = Money.zero(this.currency);
|
||||
|
||||
@@ -804,7 +804,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
final BigDecimal withdrawalFee = null;
|
||||
// deal with potential minRequiredBalance and
|
||||
// enforceMinRequiredBalance
|
||||
if (this.minRequiredBalance != null && this.enforceMinRequiredBalance) {
|
||||
if (!isWithdrawBalance && this.minRequiredBalance != null && this.enforceMinRequiredBalance) {
|
||||
if (runningBalance.minus(this.minRequiredBalance).isLessThanZero()) { throw new InsufficientAccountBalanceException(
|
||||
"transactionAmount", getAccountBalance(), withdrawalFee, transactionAmount); }
|
||||
}
|
||||
|
||||
+2
-2
@@ -11,12 +11,12 @@ import java.util.Set;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.mifosplatform.portfolio.paymentdetail.domain.PaymentDetail;
|
||||
import org.mifosplatform.portfolio.savings.SavingsTransactionBooleanValues;
|
||||
|
||||
public interface SavingsAccountDomainService {
|
||||
|
||||
SavingsAccountTransaction handleWithdrawal(SavingsAccount account, DateTimeFormatter fmt, LocalDate transactionDate,
|
||||
BigDecimal transactionAmount, PaymentDetail paymentDetail, boolean applyWithdrawFee, boolean isInterestTransfer,
|
||||
boolean isAccountTransfer, boolean isRegularTransaction);
|
||||
BigDecimal transactionAmount, PaymentDetail paymentDetail, SavingsTransactionBooleanValues transactionBooleanValues);
|
||||
|
||||
SavingsAccountTransaction handleDeposit(SavingsAccount account, DateTimeFormatter fmt, LocalDate transactionDate,
|
||||
BigDecimal transactionAmount, PaymentDetail paymentDetail, boolean isAccountTransfer, boolean isRegularTransaction);
|
||||
|
||||
+9
-8
@@ -20,6 +20,7 @@ import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency;
|
||||
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepositoryWrapper;
|
||||
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
|
||||
import org.mifosplatform.portfolio.paymentdetail.domain.PaymentDetail;
|
||||
import org.mifosplatform.portfolio.savings.SavingsTransactionBooleanValues;
|
||||
import org.mifosplatform.portfolio.savings.data.SavingsAccountTransactionDTO;
|
||||
import org.mifosplatform.portfolio.savings.exception.DepositAccountTransactionNotAllowedException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -49,30 +50,30 @@ public class SavingsAccountDomainServiceJpa implements SavingsAccountDomainServi
|
||||
@Override
|
||||
public SavingsAccountTransaction handleWithdrawal(final SavingsAccount account, final DateTimeFormatter fmt,
|
||||
final LocalDate transactionDate, final BigDecimal transactionAmount, final PaymentDetail paymentDetail,
|
||||
final boolean applyWithdrawFee, boolean isInterestTransfer, final boolean isAccountTransfer, final boolean isRegularTransaction) {
|
||||
final SavingsTransactionBooleanValues transactionBooleanValues) {
|
||||
|
||||
if (isRegularTransaction && !account.allowWithdrawal()) { throw new DepositAccountTransactionNotAllowedException(account.getId(),
|
||||
"withdraw", account.depositAccountType()); }
|
||||
if (transactionBooleanValues.isRegularTransaction() && !account.allowWithdrawal()) { throw new DepositAccountTransactionNotAllowedException(
|
||||
account.getId(), "withdraw", account.depositAccountType()); }
|
||||
final Set<Long> existingTransactionIds = new HashSet<>();
|
||||
final Set<Long> existingReversedTransactionIds = new HashSet<>();
|
||||
updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
|
||||
final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount,
|
||||
paymentDetail, new Date());
|
||||
final SavingsAccountTransaction withdrawal = account.withdraw(transactionDTO, applyWithdrawFee);
|
||||
final SavingsAccountTransaction withdrawal = account.withdraw(transactionDTO, transactionBooleanValues.isApplyWithdrawFee());
|
||||
|
||||
final MathContext mc = MathContext.DECIMAL64;
|
||||
if (account.isBeforeLastPostingPeriod(transactionDate)) {
|
||||
final LocalDate today = DateUtils.getLocalDateOfTenant();
|
||||
account.postInterest(mc, today, isInterestTransfer);
|
||||
account.postInterest(mc, today, transactionBooleanValues.isInterestTransfer());
|
||||
} else {
|
||||
final LocalDate today = DateUtils.getLocalDateOfTenant();
|
||||
account.calculateInterestUsing(mc, today, isInterestTransfer);
|
||||
account.calculateInterestUsing(mc, today, transactionBooleanValues.isInterestTransfer());
|
||||
}
|
||||
account.validateAccountBalanceDoesNotBecomeNegative(transactionAmount);
|
||||
account.validateAccountBalanceDoesNotBecomeNegative(transactionAmount, transactionBooleanValues.isWithdrawBalance());
|
||||
saveTransactionToGenerateTransactionId(withdrawal);
|
||||
this.savingsAccountRepository.save(account);
|
||||
|
||||
postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds, isAccountTransfer);
|
||||
postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds, transactionBooleanValues.isAccountTransfer());
|
||||
|
||||
return withdrawal;
|
||||
}
|
||||
|
||||
+38
-5
@@ -9,6 +9,7 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.SAVINGS_AC
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.amountParamName;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.chargeIdParamName;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.dueAsOfDateParamName;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawBalanceParamName;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
@@ -60,6 +61,7 @@ import org.mifosplatform.portfolio.paymentdetail.domain.PaymentDetail;
|
||||
import org.mifosplatform.portfolio.paymentdetail.service.PaymentDetailWritePlatformService;
|
||||
import org.mifosplatform.portfolio.savings.SavingsAccountTransactionType;
|
||||
import org.mifosplatform.portfolio.savings.SavingsApiConstants;
|
||||
import org.mifosplatform.portfolio.savings.SavingsTransactionBooleanValues;
|
||||
import org.mifosplatform.portfolio.savings.data.SavingsAccountChargeDataValidator;
|
||||
import org.mifosplatform.portfolio.savings.data.SavingsAccountTransactionDTO;
|
||||
import org.mifosplatform.portfolio.savings.data.SavingsAccountTransactionDataValidator;
|
||||
@@ -242,11 +244,16 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
|
||||
|
||||
final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId);
|
||||
checkClientOrGroupActive(account);
|
||||
boolean isInterestTransfer = false;
|
||||
boolean isAccountTransfer = false;
|
||||
boolean isRegularTransaction = true;
|
||||
|
||||
final boolean isAccountTransfer = false;
|
||||
final boolean isRegularTransaction = true;
|
||||
final boolean isApplyWithdrawFee = true;
|
||||
final boolean isInterestTransfer = false;
|
||||
final boolean isWithdrawBalance = false;
|
||||
final SavingsTransactionBooleanValues transactionBooleanValues = new SavingsTransactionBooleanValues(isAccountTransfer,
|
||||
isRegularTransaction, isApplyWithdrawFee, isInterestTransfer, isWithdrawBalance);
|
||||
final SavingsAccountTransaction withdrawal = this.savingsAccountDomainService.handleWithdrawal(account, fmt, transactionDate,
|
||||
transactionAmount, paymentDetail, true, isInterestTransfer, isAccountTransfer, isRegularTransaction);
|
||||
transactionAmount, paymentDetail, transactionBooleanValues);
|
||||
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withEntityId(withdrawal.getId()) //
|
||||
@@ -525,7 +532,33 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
|
||||
throw new SavingsAccountClosingNotAllowedException("linked", defaultUserMessage, savingsId);
|
||||
}
|
||||
|
||||
final Map<String, Object> changes = account.close(user, command, DateUtils.getLocalDateOfTenant());
|
||||
final boolean isWithdrawBalance = command.booleanPrimitiveValueOfParameterNamed(withdrawBalanceParamName);
|
||||
|
||||
final Locale locale = command.extractLocale();
|
||||
final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
|
||||
final LocalDate closedDate = command.localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);
|
||||
|
||||
final Map<String, Object> changes = new LinkedHashMap<>();
|
||||
|
||||
if (isWithdrawBalance && account.getSummary().getAccountBalance(account.getCurrency()).isGreaterThanZero()) {
|
||||
|
||||
final BigDecimal transactionAmount = account.getSummary().getAccountBalance();
|
||||
final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService.createAndPersistPaymentDetail(command, changes);
|
||||
|
||||
final boolean isAccountTransfer = false;
|
||||
final boolean isRegularTransaction = true;
|
||||
final boolean isApplyWithdrawFee = false;
|
||||
final boolean isInterestTransfer = false;
|
||||
final SavingsTransactionBooleanValues transactionBooleanValues = new SavingsTransactionBooleanValues(isAccountTransfer,
|
||||
isRegularTransaction, isApplyWithdrawFee, isInterestTransfer, isWithdrawBalance);
|
||||
|
||||
this.savingsAccountDomainService.handleWithdrawal(account, fmt, closedDate, transactionAmount, paymentDetail,
|
||||
transactionBooleanValues);
|
||||
|
||||
}
|
||||
|
||||
final Map<String, Object> accountChanges = account.close(user, command, DateUtils.getLocalDateOfTenant());
|
||||
changes.putAll(accountChanges);
|
||||
if (!changes.isEmpty()) {
|
||||
this.savingAccountRepository.save(account);
|
||||
final String noteText = command.stringValueOfParameterNamed("note");
|
||||
|
||||
Reference in New Issue
Block a user