maektwain commented on a change in pull request #796:
URL: https://github.com/apache/fineract/pull/796#discussion_r418995870
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java
##########
@@ -148,4 +261,99 @@ private void handleGLClosureIntegrityIssues(final
JsonCommand command, final Dat
throw new
PlatformDataIntegrityException("error.msg.glClosure.unknown.data.integrity.issue",
"Unknown data integrity issue with resource GL Closure: " +
realCause.getMessage());
}
+ private void handleRunningBalanceNotCalculated(final
HashMap<Long,List<IncomeAndExpenseJournalEntryData>>
allIncomeAndExpenseJLWithSubBranches){
+ final Iterator<Map.Entry<Long,List<IncomeAndExpenseJournalEntryData>>>
iterator = allIncomeAndExpenseJLWithSubBranches.entrySet().iterator();
+ while(iterator.hasNext()){
+ final List<IncomeAndExpenseJournalEntryData> incomeAndExpenseJL =
iterator.next().getValue();
+ for(final IncomeAndExpenseJournalEntryData incomeAndExpenseData
:incomeAndExpenseJL ){
+ if(!incomeAndExpenseData.isRunningBalanceCalculated()){ throw
new RunningBalanceNotCalculatedException(incomeAndExpenseData.getOfficeId());}
+ }
+ }
+ }
+ private String bookOffIncomeAndExpense(final
List<IncomeAndExpenseJournalEntryData> incomeAndExpenseJournalEntryDataList,
+ final GLClosureCommand closureData,final GLAccount glAccount,
final Office office){
+ /* All running balances has to be calculated before booking off income
and expense account */
+ for(final IncomeAndExpenseJournalEntryData incomeAndExpenseData
:incomeAndExpenseJournalEntryDataList ){
+ if(!incomeAndExpenseData.isRunningBalanceCalculated()){ throw new
RunningBalanceNotCalculatedException(incomeAndExpenseData.getOfficeId());}
+ }
+ BigDecimal debits = BigDecimal.ZERO;
+ BigDecimal credits = BigDecimal.ZERO;
+
+ int i = 0;
+ int j = 0;
+ for(final IncomeAndExpenseJournalEntryData incomeAndExpense :
incomeAndExpenseJournalEntryDataList){
+ if(incomeAndExpense.isIncomeAccountType()){
+ if(incomeAndExpense.getOfficeRunningBalance().signum() ==
1){debits = debits.add(incomeAndExpense.getOfficeRunningBalance());
+ i++;
+ }
+ else{ credits =
credits.add(incomeAndExpense.getOfficeRunningBalance().abs());
+ j++;
+ }
+ }
+ if(incomeAndExpense.isExpenseAccountType()){
+ if(incomeAndExpense.getOfficeRunningBalance().signum() ==
1){credits = credits.add(incomeAndExpense.getOfficeRunningBalance());
+ j++;
+ }
+ else{debits=
debits.add(incomeAndExpense.getOfficeRunningBalance().abs());
+ i++;
+ }
+ }
+ }
+ final int compare = debits.compareTo(credits);
+ BigDecimal difference = BigDecimal.ZERO;
+ JournalEntryCommand journalEntryCommand = null;
+ if(compare ==1){ j++;}else{
+ i++;
+ }
+
+ SingleDebitOrCreditEntryCommand[] debitsJournalEntry = new
SingleDebitOrCreditEntryCommand[i];
+ SingleDebitOrCreditEntryCommand[] creditsJournalEntry = new
SingleDebitOrCreditEntryCommand[j];
+ int m=0;
+ int n=0;
+ for(final IncomeAndExpenseJournalEntryData incomeAndExpense :
incomeAndExpenseJournalEntryDataList){
+ if(incomeAndExpense.isIncomeAccountType()){
+ if(incomeAndExpense.getOfficeRunningBalance().signum() == 1){
+ debitsJournalEntry[m] = new
SingleDebitOrCreditEntryCommand(null,incomeAndExpense.getAccountId(),incomeAndExpense.getOfficeRunningBalance().abs(),null);
+ m++;
+ }else{
+ creditsJournalEntry[n]= new
SingleDebitOrCreditEntryCommand(null,incomeAndExpense.getAccountId(),incomeAndExpense.getOfficeRunningBalance().abs(),null);
+ n++;
+ }
+ }
+ if(incomeAndExpense.isExpenseAccountType()){
+ if(incomeAndExpense.getOfficeRunningBalance().signum() == 1){
+ creditsJournalEntry[n]= new
SingleDebitOrCreditEntryCommand(null,incomeAndExpense.getAccountId(),incomeAndExpense.getOfficeRunningBalance().abs(),null);
+ n++;
+ }else{
+ debitsJournalEntry[m]= new
SingleDebitOrCreditEntryCommand(null,incomeAndExpense.getAccountId(),incomeAndExpense.getOfficeRunningBalance().abs(),null);
+ m++;
+ }
+ }
+ }
+ String transactionId = null;
+ if(compare == 1){
+ /* book with target gl id on the credit side */
+ difference = debits.subtract(credits);
+ final SingleDebitOrCreditEntryCommand targetBooking = new
SingleDebitOrCreditEntryCommand(null,closureData.getEquityGlAccountId(),difference,null);
+ creditsJournalEntry[n] = targetBooking;
+ journalEntryCommand = new
JournalEntryCommand(office.getId(),closureData.getCurrencyCode(),closureData.getClosingDate(),closureData.getComments(),creditsJournalEntry,debitsJournalEntry,closureData.getIncomeAndExpenseComments(),
+ null,null,null,null,null,null,null,null);
+ transactionId =
this.journalEntryWritePlatformService.createJournalEntryForIncomeAndExpenseBookOff(journalEntryCommand);
+
+ }else if(compare == -1){
+ /* book with target gl id on the debit side*/
+ difference = credits.subtract(debits);
+ final SingleDebitOrCreditEntryCommand targetBooking = new
SingleDebitOrCreditEntryCommand(null,closureData.getEquityGlAccountId(),difference,null);
+ debitsJournalEntry[m]= targetBooking;
+ journalEntryCommand = new
JournalEntryCommand(office.getId(),closureData.getCurrencyCode(),closureData.getClosingDate(),closureData.getComments(),creditsJournalEntry,debitsJournalEntry,closureData.getIncomeAndExpenseComments(),
+ null,null,null,null,null,null,null,null);
+ transactionId =
this.journalEntryWritePlatformService.createJournalEntryForIncomeAndExpenseBookOff(journalEntryCommand);
+ }else if(compare == 0){
+ //throw new RunningBalanceZeroException(office.getName());
+ return null;
Review comment:
I did change it to throw.
----------------------------------------------------------------
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]