Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.fineract.portfolio.client.data.ClientData;
import org.apache.fineract.portfolio.paymentdetail.data.PaymentDetailData;

/**
* Immutable data object representing a savings account.
Expand All @@ -48,6 +49,7 @@ public final class AccountTransferData implements Serializable {
private final ClientData toClient;
private final EnumOptionData toAccountType;
private final PortfolioAccountData toAccount;
private final PaymentDetailData paymentDetailData;

// template
private final Collection<OfficeData> fromOfficeOptions;
Expand Down Expand Up @@ -78,7 +80,7 @@ public static AccountTransferData template(final OfficeData fromOffice, final Cl
final String transferDescription = null;
final Boolean reversed = null;
return new AccountTransferData(id, reversed, fromOffice, fromClient, fromAccountType, fromAccount, currency, transferAmount,
transferDate, transferDescription, toOffice, toClient, toAccountType, toAccount, fromOfficeOptions, fromClientOptions,
transferDate, transferDescription, toOffice, toClient, toAccountType, toAccount, null, fromOfficeOptions, fromClientOptions,
fromAccountTypeOptions, fromAccountOptions, toOfficeOptions, toClientOptions, toAccountTypeOptions, toAccountOptions);
}

Expand All @@ -89,7 +91,18 @@ public static AccountTransferData instance(final Long id, final Boolean reversed

return new AccountTransferData(id, reversed, fromOffice, fromClient, fromAccountType, fromAccount, currency, transferAmount,
transferDate, transferDescription, toOffice, toClient, toAccountType, toAccount, null, null, null, null, null, null, null,
null);
null, null);
}

public static AccountTransferData instance(final Long id, final Boolean reversed, final LocalDate transferDate,
final CurrencyData currency, final BigDecimal transferAmount, final String transferDescription, final OfficeData fromOffice,
final OfficeData toOffice, final ClientData fromClient, final ClientData toClient, final EnumOptionData fromAccountType,
final PortfolioAccountData fromAccount, final EnumOptionData toAccountType, final PortfolioAccountData toAccount,
final PaymentDetailData paymentDetailData) {

return new AccountTransferData(id, reversed, fromOffice, fromClient, fromAccountType, fromAccount, currency, transferAmount,
transferDate, transferDescription, toOffice, toClient, toAccountType, toAccount, paymentDetailData, null, null, null, null,
null, null, null, null);
}

public static AccountTransferData transferBasicDetails(final Long id, final CurrencyData currency, final BigDecimal transferAmount,
Expand All @@ -99,17 +112,18 @@ public static AccountTransferData transferBasicDetails(final Long id, final Curr
final EnumOptionData toAccountType = null;

return new AccountTransferData(id, reversed, null, null, fromAccountType, null, currency, transferAmount, transferDate, description,
null, null, toAccountType, null, null, null, null, null, null, null, null, null);
null, null, toAccountType, null, null, null, null, null, null, null, null, null, null);
}

private AccountTransferData(final Long id, final Boolean reversed, final OfficeData fromOffice, final ClientData fromClient,
final EnumOptionData fromAccountType, final PortfolioAccountData fromAccount, final CurrencyData currency,
final BigDecimal transferAmount, final LocalDate transferDate, final String transferDescription, final OfficeData toOffice,
final ClientData toClient, final EnumOptionData toAccountType, final PortfolioAccountData toAccount,
final Collection<OfficeData> fromOfficeOptions, final Collection<ClientData> fromClientOptions,
final Collection<EnumOptionData> fromAccountTypeOptions, final Collection<PortfolioAccountData> fromAccountOptions,
final Collection<OfficeData> toOfficeOptions, final Collection<ClientData> toClientOptions,
final Collection<EnumOptionData> toAccountTypeOptions, final Collection<PortfolioAccountData> toAccountOptions) {
final PaymentDetailData paymentDetailData, final Collection<OfficeData> fromOfficeOptions,
final Collection<ClientData> fromClientOptions, final Collection<EnumOptionData> fromAccountTypeOptions,
final Collection<PortfolioAccountData> fromAccountOptions, final Collection<OfficeData> toOfficeOptions,
final Collection<ClientData> toClientOptions, final Collection<EnumOptionData> toAccountTypeOptions,
final Collection<PortfolioAccountData> toAccountOptions) {
this.id = id;
this.reversed = reversed;
this.fromOffice = fromOffice;
Expand All @@ -125,6 +139,7 @@ private AccountTransferData(final Long id, final Boolean reversed, final OfficeD
this.transferAmount = transferAmount;
this.transferDate = transferDate;
this.transferDescription = transferDescription;
this.paymentDetailData = paymentDetailData;

this.fromOfficeOptions = fromOfficeOptions;
this.fromClientOptions = fromClientOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ private PostAccountTransfersRequest() {}
public Float transferAmount;
@Schema(example = "A description of the transfer")
public String transferDescription;
@Schema(example = "1")
public Long paymentTypeId;
@Schema(example = "ACC-123")
public String accountNumber;
@Schema(example = "CHK-123")
public String checkNumber;
@Schema(example = "RT-123")
public String routingCode;
@Schema(example = "RC-123")
public String receiptNumber;
@Schema(example = "BNK-123")
public String bankNumber;
}

@Schema(description = "PostAccountTransfersResponse")
Expand Down Expand Up @@ -242,6 +254,35 @@ private GetAccountTransfersPageItemsToAccountType() {}
public String description;
}

static final class GetAccountTransfersPageItemsPaymentDetailData {

private GetAccountTransfersPageItemsPaymentDetailData() {}

static final class GetAccountTransfersPageItemsPaymentType {

private GetAccountTransfersPageItemsPaymentType() {}

@Schema(example = "1")
public Long id;
@Schema(example = "Cash")
public String name;
}

@Schema(example = "1")
public Long id;
public GetAccountTransfersPageItemsPaymentType paymentType;
@Schema(example = "ACC-123")
public String accountNumber;
@Schema(example = "CHK-123")
public String checkNumber;
@Schema(example = "RT-123")
public String routingCode;
@Schema(example = "RC-123")
public String receiptNumber;
@Schema(example = "BNK-123")
public String bankNumber;
}

@Schema(example = "1")
public Long id;
@Schema(example = "false")
Expand All @@ -261,6 +302,7 @@ private GetAccountTransfersPageItemsToAccountType() {}
public GetAccountTransfersTemplateResponse.GetAccountTransfersFromClientOptions toClient;
public GetAccountTransfersPageItemsToAccountType toAccountType;
public GetAccountTransfersPageItemsFromAccount toAccount;
public GetAccountTransfersPageItemsPaymentDetailData paymentDetailData;
}

@Schema(example = "4")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ public AccountTransferDTO(final LocalDate transactionDate, final BigDecimal tran
final Long toAccountId, final String description, final Locale locale, final DateTimeFormatter fmt,
final Integer fromTransferType, final Integer toTransferType, final ExternalId txnExternalId, final Loan fromLoan,
final Loan toLoan) {
this(transactionDate, transactionAmount, fromAccountType, toAccountType, fromAccountId, toAccountId, description, locale, fmt, null,
fromTransferType, toTransferType, txnExternalId, fromLoan, toLoan);
}

public AccountTransferDTO(final LocalDate transactionDate, final BigDecimal transactionAmount,
final PortfolioAccountType fromAccountType, final PortfolioAccountType toAccountType, final Long fromAccountId,
final Long toAccountId, final String description, final Locale locale, final DateTimeFormatter fmt,
final PaymentDetail paymentDetail, final Integer fromTransferType, final Integer toTransferType, final ExternalId txnExternalId,
final Loan fromLoan, final Loan toLoan) {
this.transactionDate = transactionDate;
this.transactionAmount = transactionAmount;
this.fromAccountType = fromAccountType;
Expand All @@ -105,7 +114,7 @@ public AccountTransferDTO(final LocalDate transactionDate, final BigDecimal tran
this.description = description;
this.locale = locale;
this.fmt = fmt;
this.paymentDetail = null;
this.paymentDetail = paymentDetail;
this.fromTransferType = fromTransferType;
this.toTransferType = toTransferType;
this.chargeId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.portfolio.account.AccountDetailConstants;
import org.apache.fineract.portfolio.account.api.AccountTransfersApiConstants;
import org.apache.fineract.portfolio.paymentdetail.PaymentDetailConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -52,7 +53,10 @@ public class AccountTransfersDataValidator {
AccountDetailConstants.fromAccountIdParamName, AccountDetailConstants.toOfficeIdParamName,
AccountDetailConstants.toClientIdParamName, AccountDetailConstants.toAccountTypeParamName,
AccountDetailConstants.toAccountIdParamName, AccountTransfersApiConstants.transferDateParamName,
AccountTransfersApiConstants.transferAmountParamName, AccountTransfersApiConstants.transferDescriptionParamName));
AccountTransfersApiConstants.transferAmountParamName, AccountTransfersApiConstants.transferDescriptionParamName,
PaymentDetailConstants.paymentTypeParamName, PaymentDetailConstants.accountNumberParamName,
PaymentDetailConstants.checkNumberParamName, PaymentDetailConstants.routingCodeParamName,
PaymentDetailConstants.receiptNumberParamName, PaymentDetailConstants.bankNumberParamName));

@Autowired
public AccountTransfersDataValidator(final FromJsonHelper fromApiJsonHelper,
Expand Down Expand Up @@ -94,9 +98,34 @@ public void validate(final JsonCommand command) {
baseDataValidator.reset().parameter(AccountTransfersApiConstants.transferDescriptionParamName).value(transactionDescription)
.notBlank().notExceedingLengthOf(200);

validatePaymentTypeDetails(baseDataValidator, element);

throwExceptionIfValidationWarningsExist(dataValidationErrors);
}

private void validatePaymentTypeDetails(final DataValidatorBuilder baseDataValidator, final JsonElement element) {
boolean checkPaymentTypeDetails = false;
final Integer paymentTypeId = this.fromApiJsonHelper.extractIntegerWithLocaleNamed(PaymentDetailConstants.paymentTypeParamName,
element);
baseDataValidator.reset().parameter(PaymentDetailConstants.paymentTypeParamName).value(paymentTypeId).ignoreIfNull()
.integerGreaterThanZero();
final Set<String> paymentDetailParameters = new HashSet<>(Arrays.asList(PaymentDetailConstants.accountNumberParamName,
PaymentDetailConstants.checkNumberParamName, PaymentDetailConstants.routingCodeParamName,
PaymentDetailConstants.receiptNumberParamName, PaymentDetailConstants.bankNumberParamName));
for (final String paymentDetailParameterName : paymentDetailParameters) {
final String paymentDetailParameterValue = this.fromApiJsonHelper.extractStringNamed(paymentDetailParameterName, element);
baseDataValidator.reset().parameter(paymentDetailParameterName).value(paymentDetailParameterValue).ignoreIfNull()
.notExceedingLengthOf(50);
if (paymentDetailParameterValue != null && !paymentDetailParameterValue.equals("")) {
checkPaymentTypeDetails = true;
}
}
if (checkPaymentTypeDetails) {
baseDataValidator.reset().parameter(PaymentDetailConstants.paymentTypeParamName).value(paymentTypeId).notBlank()
.integerGreaterThanZero();
}
}

private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException(dataValidationErrors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@ public class AccountTransferRequest implements Serializable {
private String toClientId;
private String fromAccountId;
private String fromOfficeId;
private Long paymentTypeId;
private String accountNumber;
private String checkNumber;
private String routingCode;
private String receiptNumber;
private String bankNumber;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public AccountTransferDetails assembleSavingsToSavingsTransfer(final JsonCommand

final String description = command.stringValueOfParameterNamed(transferDescriptionParamName);
AccountTransferTransaction accountTransferTransaction = AccountTransferTransaction.savingsToSavingsTransfer(accountTransferDetails,
withdrawal, deposit, transactionDate, transactionMonetaryAmount, description);
withdrawal, deposit, transactionDate, transactionMonetaryAmount, description, withdrawal.getPaymentDetail());
accountTransferDetails.addAccountTransferTransaction(accountTransferTransaction);
return accountTransferDetails;
}
Expand All @@ -73,7 +73,8 @@ public AccountTransferDetails assembleSavingsToLoanTransfer(final JsonCommand co
final String description = command.stringValueOfParameterNamed(transferDescriptionParamName);

AccountTransferTransaction accountTransferTransaction = AccountTransferTransaction.savingsToLoanTransfer(accountTransferDetails,
withdrawal, loanRepaymentTransaction, transactionDate, transactionMonetaryAmount, description);
withdrawal, loanRepaymentTransaction, transactionDate, transactionMonetaryAmount, description,
withdrawal.getPaymentDetail());
accountTransferDetails.addAccountTransferTransaction(accountTransferTransaction);
return accountTransferDetails;
}
Expand All @@ -91,7 +92,7 @@ public AccountTransferDetails assembleLoanToSavingsTransfer(final JsonCommand co
final String description = command.stringValueOfParameterNamed(transferDescriptionParamName);

AccountTransferTransaction accountTransferTransaction = AccountTransferTransaction.loanTosavingsTransfer(accountTransferDetails,
deposit, loanRefundTransaction, transactionDate, transactionMonetaryAmount, description);
deposit, loanRefundTransaction, transactionDate, transactionMonetaryAmount, description, deposit.getPaymentDetail());
accountTransferDetails.addAccountTransferTransaction(accountTransferTransaction);
return accountTransferDetails;
}
Expand All @@ -107,7 +108,7 @@ public AccountTransferDetails assembleSavingsToLoanTransfer(final AccountTransfe
}
AccountTransferTransaction accountTransferTransaction = AccountTransferTransaction.savingsToLoanTransfer(accountTransferDetails,
savingsAccountTransaction, loanTransaction, accountTransferDTO.getTransactionDate(), transactionMonetaryAmount,
accountTransferDTO.getDescription());
accountTransferDTO.getDescription(), accountTransferDTO.getPaymentDetail());
accountTransferDetails.addAccountTransferTransaction(accountTransferTransaction);
return accountTransferDetails;
}
Expand All @@ -124,7 +125,7 @@ public AccountTransferDetails assembleSavingsToSavingsTransfer(final AccountTran

AccountTransferTransaction accountTransferTransaction = AccountTransferTransaction.savingsToSavingsTransfer(accountTransferDetails,
withdrawal, deposit, accountTransferDTO.getTransactionDate(), transactionMonetaryAmount,
accountTransferDTO.getDescription());
accountTransferDTO.getDescription(), accountTransferDTO.getPaymentDetail());
accountTransferDetails.addAccountTransferTransaction(accountTransferTransaction);
return accountTransferDetails;
}
Expand All @@ -139,7 +140,7 @@ public AccountTransferDetails assembleLoanToSavingsTransfer(final AccountTransfe
}
AccountTransferTransaction accountTransferTransaction = AccountTransferTransaction.loanTosavingsTransfer(accountTransferDetails,
deposit, loanRefundTransaction, accountTransferDTO.getTransactionDate(), transactionMonetaryAmount,
accountTransferDTO.getDescription());
accountTransferDTO.getDescription(), accountTransferDTO.getPaymentDetail());
accountTransferDetails.addAccountTransferTransaction(accountTransferTransaction);
return accountTransferDetails;
}
Expand All @@ -154,7 +155,7 @@ public AccountTransferDetails assembleLoanToLoanTransfer(final AccountTransferDT
}
AccountTransferTransaction accountTransferTransaction = AccountTransferTransaction.loanToLoanTransfer(accountTransferDetails,
disburseTransaction, repaymentTransaction, accountTransferDTO.getTransactionDate(), transactionMonetaryAmount,
accountTransferDTO.getDescription());
accountTransferDTO.getDescription(), accountTransferDTO.getPaymentDetail());
accountTransferDetails.addAccountTransferTransaction(accountTransferTransaction);
return accountTransferDetails;
}
Expand Down
Loading
Loading