-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding organisation start in global configuartion #12
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
package org.apache.fineract.portfolio.loanaccount.domain; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Date; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
@@ -437,6 +438,8 @@ public void reverseTransfer(final LoanTransaction loanTransaction) { | |
@Override | ||
public void recalculateAccruals(Loan loan) { | ||
LocalDate accruedTill = loan.getAccruedTill(); | ||
boolean isOrganisationDateEnabled = this.configurationDomainService.isOrganisationstartDateEnable(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the API as Enabled.... it is better for readability |
||
Date organisationStartDate = this.configurationDomainService.retriveOrganisationStartDate(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do this only when Start Date is enabled.... one DB query can be avoided.... |
||
if (!loan.isPeriodicAccrualAccountingEnabledOnLoanProduct() || !loan.repaymentScheduleDetail().isInterestRecalculationEnabled() | ||
|| accruedTill == null || loan.isNpa() || !loan.status().isActive()) { return; } | ||
Collection<LoanScheduleAccrualData> loanScheduleAccrualDatas = new ArrayList<>(); | ||
|
@@ -454,7 +457,7 @@ public void recalculateAccruals(Loan loan) { | |
Set<LoanCharge> loanCharges = loan.charges(); | ||
|
||
for (LoanRepaymentScheduleInstallment installment : installments) { | ||
if (!accruedTill.isBefore(installment.getDueDate()) | ||
if (isOrganisationDateEnabled && new LocalDate(organisationStartDate).isBefore(installment.getDueDate()) && !accruedTill.isBefore(installment.getDueDate()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If organisationStartDate is not enabled.... this value might be null.... is this scenario tested? |
||
|| (accruedTill.isAfter(installment.getFromDate()) && !accruedTill.isAfter(installment.getDueDate()))) { | ||
BigDecimal dueDateFeeIncome = BigDecimal.ZERO; | ||
BigDecimal dueDatePenaltyIncome = BigDecimal.ZERO; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
import org.apache.fineract.accounting.common.AccountingRuleType; | ||
import org.apache.fineract.infrastructure.codes.data.CodeValueData; | ||
import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService; | ||
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; | ||
import org.apache.fineract.infrastructure.core.data.EnumOptionData; | ||
import org.apache.fineract.infrastructure.core.domain.JdbcSupport; | ||
import org.apache.fineract.infrastructure.core.service.DateUtils; | ||
|
@@ -148,6 +149,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { | |
private final LoanRepaymentScheduleTransactionProcessorFactory loanRepaymentScheduleTransactionProcessorFactory; | ||
private final FloatingRatesReadPlatformService floatingRatesReadPlatformService; | ||
private final LoanUtilService loanUtilService; | ||
private final ConfigurationDomainService configurationDomainService; | ||
|
||
@Autowired | ||
public LoanReadPlatformServiceImpl(final PlatformSecurityContext context, final LoanRepository loanRepository, | ||
|
@@ -160,7 +162,8 @@ public LoanReadPlatformServiceImpl(final PlatformSecurityContext context, final | |
final CalendarReadPlatformService calendarReadPlatformService, final StaffReadPlatformService staffReadPlatformService, | ||
final PaymentTypeReadPlatformService paymentTypeReadPlatformService, | ||
final LoanRepaymentScheduleTransactionProcessorFactory loanRepaymentScheduleTransactionProcessorFactory, | ||
final FloatingRatesReadPlatformService floatingRatesReadPlatformService, final LoanUtilService loanUtilService) { | ||
final FloatingRatesReadPlatformService floatingRatesReadPlatformService, final LoanUtilService loanUtilService, | ||
final ConfigurationDomainService configurationDomainService) { | ||
this.context = context; | ||
this.loanRepository = loanRepository; | ||
this.loanTransactionRepository = loanTransactionRepository; | ||
|
@@ -180,6 +183,7 @@ public LoanReadPlatformServiceImpl(final PlatformSecurityContext context, final | |
this.loanRepaymentScheduleTransactionProcessorFactory = loanRepaymentScheduleTransactionProcessorFactory; | ||
this.floatingRatesReadPlatformService = floatingRatesReadPlatformService; | ||
this.loanUtilService = loanUtilService; | ||
this.configurationDomainService = configurationDomainService; | ||
} | ||
|
||
@Override | ||
|
@@ -1559,34 +1563,42 @@ public LoanTermVariationsData mapRow(final ResultSet rs, @SuppressWarnings("unus | |
public Collection<LoanScheduleAccrualData> retriveScheduleAccrualData() { | ||
|
||
LoanScheduleAccrualMapper mapper = new LoanScheduleAccrualMapper(); | ||
final Date organisationStartDate = this.configurationDomainService.retriveOrganisationStartDate(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens when organisationStartDate is disabled? |
||
final StringBuilder sqlBuilder = new StringBuilder(400); | ||
sqlBuilder | ||
.append("select ") | ||
.append(mapper.schema()) | ||
.append(" where ((ls.fee_charges_amount <> if(ls.accrual_fee_charges_derived is null,0, ls.accrual_fee_charges_derived))") | ||
.append(" or ( ls.penalty_charges_amount <> if(ls.accrual_penalty_charges_derived is null,0,ls.accrual_penalty_charges_derived))") | ||
.append(" or ( ls.interest_amount <> if(ls.accrual_interest_derived is null,0,ls.accrual_interest_derived)))") | ||
.append(" and loan.loan_status_id=? and mpl.accounting_type=? and loan.is_npa=0 and ls.duedate <= CURDATE() order by loan.id,ls.duedate"); | ||
return this.jdbcTemplate.query(sqlBuilder.toString(), mapper, new Object[] { LoanStatus.ACTIVE.getValue(), | ||
AccountingRuleType.ACCRUAL_PERIODIC.getValue() }); | ||
.append(" and ls.duedate > :organisationstartdate and loan.loan_status_id=:active and mpl.accounting_type=:type and loan.is_npa=0 and ls.duedate <= CURDATE() order by loan.id,ls.duedate"); | ||
Map<String, Object> paramMap = new HashMap<>(3); | ||
paramMap.put("active", LoanStatus.ACTIVE.getValue()); | ||
paramMap.put("type", AccountingRuleType.ACCRUAL_PERIODIC.getValue()); | ||
paramMap.put("organisationstartdate", formatter.print(new LocalDate(organisationStartDate))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens when organisationStartDate is disabled? |
||
|
||
return this.namedParameterJdbcTemplate.query(sqlBuilder.toString(), paramMap, mapper); | ||
} | ||
|
||
@Override | ||
public Collection<LoanScheduleAccrualData> retrivePeriodicAccrualData(final LocalDate tillDate) { | ||
|
||
LoanSchedulePeriodicAccrualMapper mapper = new LoanSchedulePeriodicAccrualMapper(); | ||
final Date organisationStartDate = this.configurationDomainService.retriveOrganisationStartDate(); | ||
final StringBuilder sqlBuilder = new StringBuilder(400); | ||
sqlBuilder | ||
.append("select ") | ||
.append(mapper.schema()) | ||
.append(" where ((ls.fee_charges_amount <> if(ls.accrual_fee_charges_derived is null,0, ls.accrual_fee_charges_derived))") | ||
.append(" or (ls.penalty_charges_amount <> if(ls.accrual_penalty_charges_derived is null,0,ls.accrual_penalty_charges_derived))") | ||
.append(" or (ls.interest_amount <> if(ls.accrual_interest_derived is null,0,ls.accrual_interest_derived)))") | ||
.append(" and loan.loan_status_id=:active and mpl.accounting_type=:type and loan.is_npa=0 and (ls.duedate <= :tilldate or (ls.duedate > :tilldate and ls.fromdate < :tilldate)) order by loan.id,ls.duedate"); | ||
Map<String, Object> paramMap = new HashMap<>(3); | ||
.append(" and loan.loan_status_id=:active and mpl.accounting_type=:type and ls.duedate > :organisationstartdate and (loan.closedon_date <= :tilldate or loan.closedon_date is null)") | ||
.append(" and loan.is_npa=0 and (ls.duedate <= :tilldate or (ls.duedate > :tilldate and ls.fromdate < :tilldate)) order by loan.id,ls.duedate"); | ||
Map<String, Object> paramMap = new HashMap<>(4); | ||
paramMap.put("active", LoanStatus.ACTIVE.getValue()); | ||
paramMap.put("type", AccountingRuleType.ACCRUAL_PERIODIC.getValue()); | ||
paramMap.put("tilldate", formatter.print(tillDate)); | ||
paramMap.put("organisationstartdate", formatter.print(new LocalDate(organisationStartDate))); | ||
|
||
return this.namedParameterJdbcTemplate.query(sqlBuilder.toString(), paramMap, mapper); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE `c_configuration` | ||
ADD COLUMN `date_value` DATE NULL DEFAULT NULL AFTER `value`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing is being validated? looks like missing validation