3131import java .util .Locale ;
3232import java .util .Map ;
3333import java .util .Set ;
34+ import lombok .RequiredArgsConstructor ;
3435import org .apache .fineract .accounting .journalentry .service .JournalEntryWritePlatformService ;
3536import org .apache .fineract .infrastructure .accountnumberformat .domain .AccountNumberFormat ;
3637import org .apache .fineract .infrastructure .accountnumberformat .domain .AccountNumberFormatRepositoryWrapper ;
4041import org .apache .fineract .infrastructure .core .domain .ExternalId ;
4142import org .apache .fineract .infrastructure .core .exception .GeneralPlatformDomainRuleException ;
4243import org .apache .fineract .infrastructure .core .service .DateUtils ;
44+ import org .apache .fineract .infrastructure .core .service .ExternalIdFactory ;
4345import org .apache .fineract .portfolio .account .PortfolioAccountType ;
4446import org .apache .fineract .portfolio .account .data .AccountTransferDTO ;
4547import org .apache .fineract .portfolio .account .domain .AccountTransferType ;
6163import org .apache .fineract .portfolio .savings .SavingsTransactionBooleanValues ;
6264import org .apache .fineract .portfolio .savings .service .SavingsAccountDomainService ;
6365import org .apache .fineract .useradministration .domain .AppUser ;
64- import org .springframework .beans .factory .annotation .Autowired ;
6566import org .springframework .stereotype .Service ;
6667import org .springframework .transaction .annotation .Transactional ;
6768
6869@ Service
70+ @ RequiredArgsConstructor
6971public class DepositAccountDomainServiceJpa implements DepositAccountDomainService {
7072
7173 private final SavingsAccountRepositoryWrapper savingsAccountRepository ;
@@ -77,25 +79,7 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi
7779 private final ConfigurationDomainService configurationDomainService ;
7880 private final AccountNumberFormatRepositoryWrapper accountNumberFormatRepository ;
7981 private final CalendarInstanceRepository calendarInstanceRepository ;
80-
81- @ Autowired
82- public DepositAccountDomainServiceJpa (final SavingsAccountRepositoryWrapper savingsAccountRepository ,
83- final JournalEntryWritePlatformService journalEntryWritePlatformService , final AccountNumberGenerator accountNumberGenerator ,
84- final DepositAccountAssembler depositAccountAssembler , final SavingsAccountDomainService savingsAccountDomainService ,
85- final AccountTransfersWritePlatformService accountTransfersWritePlatformService ,
86- final ConfigurationDomainService configurationDomainService ,
87- final AccountNumberFormatRepositoryWrapper accountNumberFormatRepository ,
88- final CalendarInstanceRepository calendarInstanceRepository ) {
89- this .savingsAccountRepository = savingsAccountRepository ;
90- this .journalEntryWritePlatformService = journalEntryWritePlatformService ;
91- this .accountNumberGenerator = accountNumberGenerator ;
92- this .depositAccountAssembler = depositAccountAssembler ;
93- this .savingsAccountDomainService = savingsAccountDomainService ;
94- this .accountTransfersWritePlatformService = accountTransfersWritePlatformService ;
95- this .configurationDomainService = configurationDomainService ;
96- this .accountNumberFormatRepository = accountNumberFormatRepository ;
97- this .calendarInstanceRepository = calendarInstanceRepository ;
98- }
82+ private final ExternalIdFactory externalIdFactory ;
9983
10084 @ Transactional
10185 @ Override
@@ -216,11 +200,12 @@ public Long handleFDAccountClosure(final FixedDepositAccount account, final Paym
216200 final Integer onAccountClosureId = command .integerValueOfParameterNamed (onAccountClosureIdParamName );
217201 final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType .fromInt (onAccountClosureId );
218202 if (onClosureType .isReinvest ()) {
219- FixedDepositAccount reinvestedDeposit = account .reInvest (account .getAccountBalance ());
203+ ExternalId externalId = this .externalIdFactory .create ();
204+ FixedDepositAccount reinvestedDeposit = account .reInvest (account .getAccountBalance (), externalId );
220205 this .depositAccountAssembler .assignSavingAccountHelpers (reinvestedDeposit );
221206 reinvestedDeposit .updateMaturityDateAndAmountBeforeAccountActivation (mc , isPreMatureClosure ,
222207 isSavingsInterestPostingAtCurrentPeriodEnd , financialYearBeginningMonth );
223- this .savingsAccountRepository .save (reinvestedDeposit );
208+ this .savingsAccountRepository .saveAndFlush (reinvestedDeposit );
224209 autoGenerateAccountNumber (reinvestedDeposit );
225210 final SavingsAccountTransaction withdrawal = this .handleWithdrawal (account , fmt , closedDate , account .getAccountBalance (),
226211 paymentDetail , false , isRegularTransaction );
@@ -282,12 +267,14 @@ public Long handleFDAccountMaturityClosure(final FixedDepositAccount account, fi
282267 } else {
283268 reInvestAmount = account .getAccountBalance ();
284269 }
285- FixedDepositAccount reinvestedDeposit = account .reInvest (reInvestAmount );
270+ ExternalId externalId = this .externalIdFactory .create ();
271+
272+ FixedDepositAccount reinvestedDeposit = account .reInvest (reInvestAmount , externalId );
286273 this .depositAccountAssembler .assignSavingAccountHelpers (reinvestedDeposit );
287274 reinvestedDeposit .updateMaturityDateAndAmountBeforeAccountActivation (mc , isPreMatureClosure ,
288275 isSavingsInterestPostingAtCurrentPeriodEnd , financialYearBeginningMonth );
289276
290- this .savingsAccountRepository .save (reinvestedDeposit );
277+ this .savingsAccountRepository .saveAndFlush (reinvestedDeposit );
291278 autoGenerateAccountNumber (reinvestedDeposit );
292279 final SavingsAccountTransaction withdrawal = this .handleWithdrawal (account , fmt , closedDate , reInvestAmount , paymentDetail ,
293280 false , isRegularTransaction );
@@ -439,7 +426,6 @@ private void autoGenerateAccountNumber(final SavingsAccount account) {
439426 if (account .isAccountNumberRequiresAutoGeneration ()) {
440427 final AccountNumberFormat accountNumberFormat = this .accountNumberFormatRepository .findByAccountType (EntityAccountType .SAVINGS );
441428 account .updateAccountNo (this .accountNumberGenerator .generate (account , accountNumberFormat ));
442- this .savingsAccountRepository .save (account );
443429 }
444430 }
445431
0 commit comments