nikpawar89 commented on a change in pull request #738: GSIM and GLIM with test 
cases (FINERACT-603)
URL: https://github.com/apache/fineract/pull/738#discussion_r410976178
 
 

 ##########
 File path: 
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
 ##########
 @@ -365,11 +387,106 @@ public CommandProcessingResult submitApplication(final 
JsonCommand command) {
                 
createAndPersistCalendarInstanceForInterestRecalculation(newLoanApplication);
             }
 
+
+            // loan account number generation
+            String accountNumber="";
+            GroupLoanIndividualMonitoringAccount glimAccount;
+            BigDecimal applicationId=BigDecimal.ZERO;
+            Boolean isLastChildApplication=false;
+
+
             if (newLoanApplication.isAccountNumberRequiresAutoGeneration()) {
-                final AccountNumberFormat accountNumberFormat = 
this.accountNumberFormatRepository
-                        .findByAccountType(EntityAccountType.LOAN);
-                
newLoanApplication.updateAccountNo(this.accountNumberGenerator.generate(newLoanApplication,
 accountNumberFormat));
-                this.loanRepositoryWrapper.save(newLoanApplication);
+
+                 final AccountNumberFormat accountNumberFormat = 
this.accountNumberFormatRepository.findByAccountType(EntityAccountType.LOAN);
+                // if application is of GLIM type
+                if(newLoanApplication.getLoanType()==4)
+                {
+                    Group group= 
this.groupRepository.findOneWithNotFoundDetection(groupId);
+
+                    //GLIM specific parameters
+                    
if(command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("applicationId")!=null)
+                    {
+                        
applicationId=command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("applicationId");
+                    }
+
+                    
if(command.booleanObjectValueOfParameterNamed("lastApplication")!=null)
+                    {
+                        
isLastChildApplication=command.booleanPrimitiveValueOfParameterNamed("lastApplication");
+                    }
+
+                    
if(command.booleanObjectValueOfParameterNamed("isParentAccount")!=null)
+                    {
+
+                        //empty table check
+                            if(glimRepository.count()!=0)
+                            {
+                                //**************Parent-Not an empty 
table********************
+                                
accountNumber=this.accountNumberGenerator.generate(newLoanApplication, 
accountNumberFormat);
+                                
newLoanApplication.updateAccountNo(accountNumber+"-1");
+                                
glimAccountInfoWritePlatformService.addGLIMAccountInfo(accountNumber,group, 
command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("totalLoan"),Long.valueOf(1),true,
+                                        
LoanStatus.SUBMITTED_AND_PENDING_APPROVAL.getValue(),applicationId);
+                                
newLoanApplication.setGlim(glimRepository.findOneByAccountNumber(accountNumber));
+                                 
this.loanRepositoryWrapper.save(newLoanApplication);
+
+                            }
+                            else
+                            {
+                                //************** Parent-empty 
table********************
+
+                                
accountNumber=this.accountNumberGenerator.generate(newLoanApplication, 
accountNumberFormat);
 
 Review comment:
   most of the stuff is repetitive while creating child account, try extracting 
function so it becomes readable and will reduce lines of code.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to