fix for loan officer assignment mifosx-260
This commit is contained in:
+23
@@ -160,4 +160,27 @@ public final class LoanEventApiJsonValidator {
|
|||||||
|
|
||||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void validateUpdateOfLoanOfficer(final String json) {
|
||||||
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
|
|
||||||
|
final Set<String> disbursementParameters = new HashSet<String>(Arrays.asList("assignmentDate", "fromLoanOfficerId",
|
||||||
|
"toLoanOfficerId", "locale", "dateFormat"));
|
||||||
|
|
||||||
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
|
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, disbursementParameters);
|
||||||
|
|
||||||
|
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loanOfficer");
|
||||||
|
|
||||||
|
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
|
// final Long fromLoanOfficerId =
|
||||||
|
// fromApiJsonHelper.extractLongNamed("fromLoanOfficerId", element);
|
||||||
|
final Long toLoanOfficerId = fromApiJsonHelper.extractLongNamed("toLoanOfficerId", element);
|
||||||
|
|
||||||
|
baseDataValidator.reset().parameter("toLoanOfficerId").value(toLoanOfficerId).ignoreIfNull().integerGreaterThanZero();
|
||||||
|
|
||||||
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+27
-28
@@ -147,7 +147,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
.with(changes) //
|
.with(changes) //
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> bulkLoanDisbursal(JsonCommand command, CollectionSheetBulkDisbursalCommand bulkDisbursalCommand) {
|
public Map<String, Object> bulkLoanDisbursal(JsonCommand command, CollectionSheetBulkDisbursalCommand bulkDisbursalCommand) {
|
||||||
@@ -155,31 +155,28 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
|
|
||||||
SingleDisbursalCommand[] disbursalCommand = bulkDisbursalCommand.getDisburseTransactions();
|
SingleDisbursalCommand[] disbursalCommand = bulkDisbursalCommand.getDisburseTransactions();
|
||||||
Map<String, Object> changes = new LinkedHashMap<String, Object>();
|
Map<String, Object> changes = new LinkedHashMap<String, Object>();
|
||||||
if(disbursalCommand == null){
|
if (disbursalCommand == null) { return changes; }
|
||||||
return changes;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < disbursalCommand.length; i++) {
|
for (int i = 0; i < disbursalCommand.length; i++) {
|
||||||
SingleDisbursalCommand singleLoanDisbursalCommand = disbursalCommand[i];
|
SingleDisbursalCommand singleLoanDisbursalCommand = disbursalCommand[i];
|
||||||
|
|
||||||
final Loan loan = retrieveLoanBy(singleLoanDisbursalCommand.getLoanId());
|
final Loan loan = retrieveLoanBy(singleLoanDisbursalCommand.getLoanId());
|
||||||
|
|
||||||
final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(loan.getCurrencyCode());
|
final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(loan.getCurrencyCode());
|
||||||
|
|
||||||
final List<Long> existingTransactionIds = new ArrayList<Long>();
|
final List<Long> existingTransactionIds = new ArrayList<Long>();
|
||||||
final List<Long> existingReversedTransactionIds = new ArrayList<Long>();
|
final List<Long> existingReversedTransactionIds = new ArrayList<Long>();
|
||||||
|
|
||||||
changes.putAll(loan.disburse(currentUser, command, currency, existingTransactionIds,
|
changes.putAll(loan.disburse(currentUser, command, currency, existingTransactionIds, existingReversedTransactionIds));
|
||||||
existingReversedTransactionIds));
|
|
||||||
if (!changes.isEmpty()) {
|
if (!changes.isEmpty()) {
|
||||||
this.loanRepository.save(loan);
|
this.loanRepository.save(loan);
|
||||||
|
|
||||||
final String noteText = command.stringValueOfParameterNamed("note");
|
final String noteText = command.stringValueOfParameterNamed("note");
|
||||||
if (StringUtils.isNotBlank(noteText)) {
|
if (StringUtils.isNotBlank(noteText)) {
|
||||||
Note note = Note.loanNote(loan, noteText);
|
Note note = Note.loanNote(loan, noteText);
|
||||||
this.noteRepository.save(note);
|
this.noteRepository.save(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds);
|
postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,16 +247,16 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
if (StringUtils.isNotBlank(noteText)) {
|
if (StringUtils.isNotBlank(noteText)) {
|
||||||
changes.put("note", noteText);
|
changes.put("note", noteText);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandProcessingResultBuilder commandProcessingResultBuilder = saveLoanRepayment(loanId, transactionAmount, transactionDate, noteText);
|
CommandProcessingResultBuilder commandProcessingResultBuilder = saveLoanRepayment(loanId, transactionAmount, transactionDate,
|
||||||
|
noteText);
|
||||||
return commandProcessingResultBuilder
|
|
||||||
.withCommandId(command.commandId()) //
|
return commandProcessingResultBuilder.withCommandId(command.commandId()) //
|
||||||
.withLoanId(loanId) //
|
.withLoanId(loanId) //
|
||||||
.with(changes) //
|
.with(changes) //
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandProcessingResultBuilder saveLoanRepayment(final Long loanId, final BigDecimal transactionAmount,
|
private CommandProcessingResultBuilder saveLoanRepayment(final Long loanId, final BigDecimal transactionAmount,
|
||||||
final LocalDate transactionDate, final String noteText) {
|
final LocalDate transactionDate, final String noteText) {
|
||||||
final Loan loan = retrieveLoanBy(loanId);
|
final Loan loan = retrieveLoanBy(loanId);
|
||||||
@@ -288,7 +285,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
}
|
}
|
||||||
this.loanRepository.save(loan);
|
this.loanRepository.save(loan);
|
||||||
|
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(noteText)) {
|
if (StringUtils.isNotBlank(noteText)) {
|
||||||
Note note = Note.loanTransactionNote(loan, newRepaymentTransaction, noteText);
|
Note note = Note.loanTransactionNote(loan, newRepaymentTransaction, noteText);
|
||||||
this.noteRepository.save(note);
|
this.noteRepository.save(note);
|
||||||
@@ -297,10 +293,10 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds);
|
postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds);
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
.withEntityId(newRepaymentTransaction.getId()) //
|
.withEntityId(newRepaymentTransaction.getId()) //
|
||||||
.withOfficeId(loan.getOfficeId()) //
|
.withOfficeId(loan.getOfficeId()) //
|
||||||
.withClientId(loan.getClientId()) //
|
.withClientId(loan.getClientId()) //
|
||||||
.withGroupId(loan.getGroupId()); //
|
.withGroupId(loan.getGroupId()); //
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -310,16 +306,17 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
context.authenticatedUser();
|
context.authenticatedUser();
|
||||||
final SingleRepaymentCommand[] repaymentCommand = bulkRepaymentCommand.getLoanTransactions();
|
final SingleRepaymentCommand[] repaymentCommand = bulkRepaymentCommand.getLoanTransactions();
|
||||||
final Map<String, Object> changes = new LinkedHashMap<String, Object>();
|
final Map<String, Object> changes = new LinkedHashMap<String, Object>();
|
||||||
|
|
||||||
if(repaymentCommand == null) return changes;
|
if (repaymentCommand == null) return changes;
|
||||||
|
|
||||||
for (SingleRepaymentCommand singleLoanRepaymentCommand : repaymentCommand) {
|
for (SingleRepaymentCommand singleLoanRepaymentCommand : repaymentCommand) {
|
||||||
saveLoanRepayment(singleLoanRepaymentCommand.getLoanId(), singleLoanRepaymentCommand.getTransactionAmount(), bulkRepaymentCommand.getTransactionDate(), bulkRepaymentCommand.getNote());
|
saveLoanRepayment(singleLoanRepaymentCommand.getLoanId(), singleLoanRepaymentCommand.getTransactionAmount(),
|
||||||
|
bulkRepaymentCommand.getTransactionDate(), bulkRepaymentCommand.getNote());
|
||||||
changes.put("bulkTransations", singleLoanRepaymentCommand);
|
changes.put("bulkTransations", singleLoanRepaymentCommand);
|
||||||
}
|
}
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult adjustLoanTransaction(final Long loanId, final Long transactionId, final JsonCommand command) {
|
public CommandProcessingResult adjustLoanTransaction(final Long loanId, final Long transactionId, final JsonCommand command) {
|
||||||
@@ -784,6 +781,8 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
|
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
|
this.loanEventApiJsonValidator.validateUpdateOfLoanOfficer(command.json());
|
||||||
|
|
||||||
final Long fromLoanOfficerId = command.longValueOfParameterNamed("fromLoanOfficerId");
|
final Long fromLoanOfficerId = command.longValueOfParameterNamed("fromLoanOfficerId");
|
||||||
final Long toLoanOfficerId = command.longValueOfParameterNamed("toLoanOfficerId");
|
final Long toLoanOfficerId = command.longValueOfParameterNamed("toLoanOfficerId");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user