|
105 | 105 | import org.apache.fineract.portfolio.savings.domain.SavingsAccountStatusType; |
106 | 106 | import org.apache.fineract.portfolio.savings.domain.SavingsAccountTransaction; |
107 | 107 | import org.apache.fineract.portfolio.savings.domain.SavingsAccountTransactionRepository; |
108 | | -import org.apache.fineract.portfolio.savings.exception.DepositAccountTransactionNotAllowedException; |
109 | 108 | import org.apache.fineract.portfolio.savings.exception.SavingsAccountTransactionNotFoundException; |
110 | 109 | import org.apache.fineract.portfolio.savings.exception.TransactionUpdateNotAllowedException; |
111 | 110 | import org.apache.fineract.useradministration.domain.AppUser; |
@@ -693,10 +692,100 @@ public CommandProcessingResult undoRDTransaction(final Long savingsId, final Lon |
693 | 692 | } |
694 | 693 |
|
695 | 694 | @Override |
696 | | - public CommandProcessingResult adjustFDTransaction(final Long savingsId, @SuppressWarnings("unused") final Long transactionId, |
697 | | - @SuppressWarnings("unused") final JsonCommand command) { |
| 695 | + public CommandProcessingResult adjustFDTransaction(final Long savingsId, final Long transactionId, final JsonCommand command) { |
| 696 | + context.authenticatedUser(); |
| 697 | + |
| 698 | + final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService |
| 699 | + .isSavingsInterestPostingAtCurrentPeriodEnd(); |
| 700 | + final Integer financialYearBeginningMonth = this.configurationDomainService.retrieveFinancialYearBeginningMonth(); |
| 701 | + final Long relaxingDaysConfigForPivotDate = this.configurationDomainService.retrieveRelaxingDaysConfigForPivotDate(); |
| 702 | + this.depositAccountTransactionDataValidator.validate(command, DepositAccountType.FIXED_DEPOSIT); |
| 703 | + |
| 704 | + final SavingsAccountTransaction savingsAccountTransaction = this.savingsAccountTransactionRepository |
| 705 | + .findOneByIdAndSavingsAccountId(transactionId, savingsId); |
| 706 | + if (savingsAccountTransaction == null) { |
| 707 | + throw new SavingsAccountTransactionNotFoundException(savingsId, transactionId); |
| 708 | + } |
| 709 | + |
| 710 | + if ((!savingsAccountTransaction.isDeposit() && !savingsAccountTransaction.isWithdrawal()) |
| 711 | + || savingsAccountTransaction.isReversed()) { |
| 712 | + throw new TransactionUpdateNotAllowedException(savingsId, transactionId); |
| 713 | + } |
| 714 | + |
| 715 | + if (this.accountTransfersReadPlatformService.isAccountTransfer(transactionId, PortfolioAccountType.SAVINGS)) { |
| 716 | + throw new PlatformServiceUnavailableException("error.msg.fixed.deposit.account.transfer.transaction.update.not.allowed", |
| 717 | + "Fixed deposit account transaction:" + transactionId + " update not allowed as it involves in account transfer", |
| 718 | + transactionId); |
| 719 | + } |
| 720 | + |
| 721 | + final LocalDate today = DateUtils.getBusinessLocalDate(); |
| 722 | + final MathContext mc = MathContext.DECIMAL64; |
| 723 | + |
| 724 | + final FixedDepositAccount account = (FixedDepositAccount) this.depositAccountAssembler.assembleFrom(savingsId, |
| 725 | + DepositAccountType.FIXED_DEPOSIT); |
| 726 | + if (!account.isTransactionsAllowed()) { |
| 727 | + throwValidationForActiveStatus(SavingsApiConstants.adjustTransactionAction); |
| 728 | + } |
| 729 | + final Set<Long> existingTransactionIds = new HashSet<>(); |
| 730 | + final Set<Long> existingReversedTransactionIds = new HashSet<>(); |
| 731 | + updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); |
| 732 | + |
| 733 | + final Locale locale = command.extractLocale(); |
| 734 | + final DateTimeFormatter fmt = DateTimeFormatter.ofPattern(command.dateFormat()).withLocale(locale); |
| 735 | + final LocalDate transactionDate = command.localDateValueOfParameterNamed(SavingsApiConstants.transactionDateParamName); |
| 736 | + final BigDecimal transactionAmount = command.bigDecimalValueOfParameterNamed(SavingsApiConstants.transactionAmountParamName); |
| 737 | + final Map<String, Object> changes = new LinkedHashMap<>(); |
| 738 | + final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService.createAndPersistPaymentDetail(command, changes); |
| 739 | + |
| 740 | + account.undoTransaction(transactionId); |
| 741 | + |
| 742 | + SavingsAccountTransaction transaction = null; |
| 743 | + Integer accountType = null; |
| 744 | + UUID refNo = UUID.randomUUID(); |
| 745 | + if (savingsAccountTransaction.isDeposit()) { |
| 746 | + final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount, |
| 747 | + paymentDetail, null, accountType); |
| 748 | + transaction = account.deposit(transactionDTO, false, relaxingDaysConfigForPivotDate, refNo.toString()); |
| 749 | + } else { |
| 750 | + final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount, |
| 751 | + paymentDetail, null, accountType); |
| 752 | + transaction = account.withdraw(transactionDTO, true, false, relaxingDaysConfigForPivotDate, refNo.toString()); |
| 753 | + } |
| 754 | + final Long newtransactionId = saveTransactionToGenerateTransactionId(transaction); |
| 755 | + boolean isInterestTransfer = false; |
| 756 | + final LocalDate postInterestOnDate = null; |
| 757 | + final boolean backdatedTxnsAllowedTill = false; |
| 758 | + final boolean postReversals = false; |
| 759 | + checkClientOrGroupActive(account); |
| 760 | + if (savingsAccountTransaction.isPostInterestCalculationRequired() |
| 761 | + && account.isBeforeLastPostingPeriod(savingsAccountTransaction.getTransactionDate(), false)) { |
| 762 | + account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, |
| 763 | + postInterestOnDate, backdatedTxnsAllowedTill); |
| 764 | + } else { |
| 765 | + account.calculateInterestUsing(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, |
| 766 | + financialYearBeginningMonth, postInterestOnDate, backdatedTxnsAllowedTill, postReversals); |
| 767 | + } |
| 768 | + List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions = null; |
| 769 | + if (account.getOnHoldFunds().compareTo(BigDecimal.ZERO) > 0) { |
| 770 | + depositAccountOnHoldTransactions = this.depositAccountOnHoldTransactionRepository |
| 771 | + .findBySavingsAccountAndReversedFalseOrderByCreatedDateAsc(account); |
| 772 | + } |
| 773 | + account.validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.adjustTransactionAction, depositAccountOnHoldTransactions, |
| 774 | + false); |
| 775 | + final boolean isPreMatureClosure = false; |
| 776 | + account.updateMaturityDateAndAmount(mc, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd, |
| 777 | + financialYearBeginningMonth); |
698 | 778 |
|
699 | | - throw new DepositAccountTransactionNotAllowedException(savingsId, "modify", DepositAccountType.FIXED_DEPOSIT); |
| 779 | + this.savingAccountRepositoryWrapper.saveAndFlush(account); |
| 780 | + postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); |
| 781 | + return new CommandProcessingResultBuilder() // |
| 782 | + .withEntityId(newtransactionId) // |
| 783 | + .withOfficeId(account.officeId()) // |
| 784 | + .withClientId(account.clientId()) // |
| 785 | + .withGroupId(account.groupId()) // |
| 786 | + .withSavingsId(savingsId) // |
| 787 | + .with(changes) // |
| 788 | + .build(); |
700 | 789 | } |
701 | 790 |
|
702 | 791 | @Override |
|
0 commit comments