Date to LocalDate - part 1

This commit is contained in:
Adam Saghy
2022-07-11 11:22:47 +02:00
committed by Arnold Gálovics
parent adaac89583
commit ef96d5cc50
47 changed files with 495 additions and 828 deletions
@@ -18,7 +18,7 @@
*/ */
package org.apache.fineract.infrastructure.configuration.data; package org.apache.fineract.infrastructure.configuration.data;
import java.util.Date; import java.time.LocalDate;
/** /**
* Immutable data object for global configuration property. * Immutable data object for global configuration property.
@@ -32,7 +32,7 @@ public class GlobalConfigurationPropertyData {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final Long value; private final Long value;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final Date dateValue; private final LocalDate dateValue;
private String stringValue; private String stringValue;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final Long id; private final Long id;
@@ -41,7 +41,7 @@ public class GlobalConfigurationPropertyData {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final boolean trapDoor; private final boolean trapDoor;
public GlobalConfigurationPropertyData(final String name, final boolean enabled, final Long value, final Date dateValue, public GlobalConfigurationPropertyData(final String name, final boolean enabled, final Long value, final LocalDate dateValue,
final String stringValue, final String description, final boolean trapDoor) { final String stringValue, final String description, final boolean trapDoor) {
this.name = name; this.name = name;
this.enabled = enabled; this.enabled = enabled;
@@ -53,7 +53,7 @@ public class GlobalConfigurationPropertyData {
this.trapDoor = trapDoor; this.trapDoor = trapDoor;
} }
public GlobalConfigurationPropertyData(final String name, final boolean enabled, final Long value, Date dateValue, public GlobalConfigurationPropertyData(final String name, final boolean enabled, final Long value, LocalDate dateValue,
final String stringValue, final Long id, final String description, final boolean isTrapDoor) { final String stringValue, final Long id, final String description, final boolean isTrapDoor) {
this.name = name; this.name = name;
this.enabled = enabled; this.enabled = enabled;
@@ -81,7 +81,7 @@ public class GlobalConfigurationPropertyData {
return this.stringValue; return this.stringValue;
} }
public Date getDateValue() { public LocalDate getDateValue() {
return this.dateValue; return this.dateValue;
} }
@@ -18,7 +18,7 @@
*/ */
package org.apache.fineract.infrastructure.configuration.domain; package org.apache.fineract.infrastructure.configuration.domain;
import java.util.Date; import java.time.LocalDate;
import org.apache.fineract.infrastructure.cache.domain.CacheType; import org.apache.fineract.infrastructure.cache.domain.CacheType;
public interface ConfigurationDomainService { public interface ConfigurationDomainService {
@@ -67,7 +67,7 @@ public interface ConfigurationDomainService {
boolean isOrganisationstartDateEnabled(); boolean isOrganisationstartDateEnabled();
Date retrieveOrganisationStartDate(); LocalDate retrieveOrganisationStartDate();
boolean isPaymnetypeApplicableforDisbursementCharge(); boolean isPaymnetypeApplicableforDisbursementCharge();
@@ -18,7 +18,7 @@
*/ */
package org.apache.fineract.infrastructure.configuration.domain; package org.apache.fineract.infrastructure.configuration.domain;
import java.util.Date; import java.time.LocalDate;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -238,7 +238,7 @@ public class ConfigurationDomainServiceJpa implements ConfigurationDomainService
} }
@Override @Override
public Date retrieveOrganisationStartDate() { public LocalDate retrieveOrganisationStartDate() {
final String propertyName = "organisation-start-date"; final String propertyName = "organisation-start-date";
final GlobalConfigurationPropertyData property = getGlobalConfigurationPropertyData(propertyName); final GlobalConfigurationPropertyData property = getGlobalConfigurationPropertyData(propertyName);
return property.getDateValue(); return property.getDateValue();
@@ -18,7 +18,7 @@
*/ */
package org.apache.fineract.infrastructure.configuration.domain; package org.apache.fineract.infrastructure.configuration.domain;
import java.util.Date; import java.time.LocalDate;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import javax.persistence.Column; import javax.persistence.Column;
@@ -44,7 +44,7 @@ public class GlobalConfigurationProperty extends AbstractPersistableCustom {
private Long value; private Long value;
@Column(name = "date_value", nullable = true) @Column(name = "date_value", nullable = true)
private Date dateValue; private LocalDate dateValue;
@Column(name = "string_value", nullable = true) @Column(name = "string_value", nullable = true)
private String stringValue; private String stringValue;
@@ -65,7 +65,7 @@ public class GlobalConfigurationProperty extends AbstractPersistableCustom {
this.isTrapDoor = false; this.isTrapDoor = false;
} }
public GlobalConfigurationProperty(final String name, final boolean enabled, final Long value, final Date dateValue, public GlobalConfigurationProperty(final String name, final boolean enabled, final Long value, final LocalDate dateValue,
final String stringValue, final String description, final boolean isTrapDoor) { final String stringValue, final String description, final boolean isTrapDoor) {
this.name = name; this.name = name;
this.enabled = enabled; this.enabled = enabled;
@@ -84,7 +84,7 @@ public class GlobalConfigurationProperty extends AbstractPersistableCustom {
return this.value; return this.value;
} }
public Date getDateValue() { public LocalDate getDateValue() {
return this.dateValue; return this.dateValue;
} }
@@ -117,7 +117,7 @@ public class GlobalConfigurationProperty extends AbstractPersistableCustom {
final String dateValueParamName = "dateValue"; final String dateValueParamName = "dateValue";
if (command.isChangeInDateParameterNamed(dateValueParamName, this.dateValue)) { if (command.isChangeInDateParameterNamed(dateValueParamName, this.dateValue)) {
final Date newDateValue = command.dateValueOfParameterNamed(dateValueParamName); final LocalDate newDateValue = command.localDateValueOfParameterNamed(dateValueParamName);
actualChanges.put(dateValueParamName, newDateValue); actualChanges.put(dateValueParamName, newDateValue);
this.dateValue = newDateValue; this.dateValue = newDateValue;
} }
@@ -18,9 +18,10 @@
*/ */
package org.apache.fineract.infrastructure.configuration.service; package org.apache.fineract.infrastructure.configuration.service;
import java.sql.Date;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Date; import java.time.LocalDate;
import java.util.List; import java.util.List;
import org.apache.fineract.infrastructure.configuration.data.GlobalConfigurationData; import org.apache.fineract.infrastructure.configuration.data.GlobalConfigurationData;
import org.apache.fineract.infrastructure.configuration.data.GlobalConfigurationPropertyData; import org.apache.fineract.infrastructure.configuration.data.GlobalConfigurationPropertyData;
@@ -105,7 +106,8 @@ public class ConfigurationReadPlatformServiceImpl implements ConfigurationReadPl
final String description = rs.getString("description"); final String description = rs.getString("description");
final Long id = rs.getLong("id"); final Long id = rs.getLong("id");
final boolean isTrapDoor = rs.getBoolean("is_trap_door"); final boolean isTrapDoor = rs.getBoolean("is_trap_door");
return new GlobalConfigurationPropertyData(name, enabled, value, dateValue, stringValue, id, description, isTrapDoor); final LocalDate localDate = dateValue != null ? dateValue.toLocalDate() : null;
return new GlobalConfigurationPropertyData(name, enabled, value, localDate, stringValue, id, description, isTrapDoor);
} }
} }
@@ -36,7 +36,6 @@ import java.util.Set;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.security.domain.BasicPasswordEncodablePlatformUser; import org.apache.fineract.infrastructure.security.domain.BasicPasswordEncodablePlatformUser;
import org.apache.fineract.infrastructure.security.domain.PlatformUser; import org.apache.fineract.infrastructure.security.domain.PlatformUser;
import org.apache.fineract.infrastructure.security.service.PlatformPasswordEncoder; import org.apache.fineract.infrastructure.security.service.PlatformPasswordEncoder;
@@ -371,12 +370,8 @@ public final class JsonCommand {
return this.fromApiJsonHelper.extractLongNamed(parameterName, this.parsedCommand); return this.fromApiJsonHelper.extractLongNamed(parameterName, this.parsedCommand);
} }
public boolean isChangeInDateParameterNamed(final String parameterName, final Date existingValue) { public boolean isChangeInDateParameterNamed(final String parameterName, final LocalDate existingValue) {
LocalDate localDate = null; return isChangeInLocalDateParameterNamed(parameterName, existingValue);
if (existingValue != null) {
localDate = LocalDate.ofInstant(existingValue.toInstant(), DateUtils.getDateTimeZoneOfTenant());
}
return isChangeInLocalDateParameterNamed(parameterName, localDate);
} }
public boolean isChangeInTimeParameterNamed(final String parameterName, final Date existingValue, final String timeFormat) { public boolean isChangeInTimeParameterNamed(final String parameterName, final Date existingValue, final String timeFormat) {
@@ -18,9 +18,8 @@
*/ */
package org.apache.fineract.infrastructure.core.domain; package org.apache.fineract.infrastructure.core.domain;
import static org.apache.fineract.infrastructure.core.service.DateUtils.getDateTimeZoneOfTenant;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Date;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
@@ -28,7 +27,6 @@ import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.Date;
import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.springframework.jdbc.support.JdbcUtils; import org.springframework.jdbc.support.JdbcUtils;
@@ -44,7 +42,7 @@ public final class JdbcSupport {
ZonedDateTime dateTime = null; ZonedDateTime dateTime = null;
final Timestamp dateValue = rs.getTimestamp(columnName); final Timestamp dateValue = rs.getTimestamp(columnName);
if (dateValue != null) { if (dateValue != null) {
dateTime = ZonedDateTime.ofInstant(new Date(dateValue.getTime()).toInstant(), DateUtils.getDateTimeZoneOfTenant()); dateTime = ZonedDateTime.ofInstant(dateValue.toInstant(), DateUtils.getDateTimeZoneOfTenant());
} }
return dateTime; return dateTime;
} }
@@ -53,25 +51,25 @@ public final class JdbcSupport {
LocalDateTime dateTime = null; LocalDateTime dateTime = null;
final Timestamp dateValue = rs.getTimestamp(columnName); final Timestamp dateValue = rs.getTimestamp(columnName);
if (dateValue != null) { if (dateValue != null) {
dateTime = LocalDateTime.ofInstant(new Date(dateValue.getTime()).toInstant(), getDateTimeZoneOfTenant()); dateTime = dateValue.toLocalDateTime();
} }
return dateTime; return dateTime;
} }
public static LocalDate getLocalDate(final ResultSet rs, final String columnName) throws SQLException { public static LocalDate getLocalDate(final ResultSet rs, final String columnName) throws SQLException {
LocalDate localDate = null; LocalDate localDate = null;
final Date dateValue = rs.getTimestamp(columnName); final Date dateValue = rs.getDate(columnName);
if (dateValue != null) { if (dateValue != null) {
localDate = LocalDate.ofInstant(dateValue.toInstant(), DateUtils.getDateTimeZoneOfTenant()); localDate = dateValue.toLocalDate();
} }
return localDate; return localDate;
} }
public static LocalTime getLocalTime(final ResultSet rs, final String columnName) throws SQLException { public static LocalTime getLocalTime(final ResultSet rs, final String columnName) throws SQLException {
LocalTime localTime = null; LocalTime localTime = null;
final Date timeValue = rs.getTimestamp(columnName); final Timestamp timeValue = rs.getTimestamp(columnName);
if (timeValue != null) { if (timeValue != null) {
localTime = LocalTime.ofInstant(timeValue.toInstant(), DateUtils.getDateTimeZoneOfTenant()); localTime = timeValue.toLocalDateTime().toLocalTime();
} }
return localTime; return localTime;
} }
@@ -18,7 +18,7 @@
*/ */
package org.apache.fineract.infrastructure.entityaccess.domain; package org.apache.fineract.infrastructure.entityaccess.domain;
import java.util.Date; import java.time.LocalDate;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import javax.persistence.Column; import javax.persistence.Column;
@@ -26,8 +26,6 @@ import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
@@ -49,15 +47,13 @@ public class FineractEntityToEntityMapping extends AbstractPersistableCustom {
private Long toId; private Long toId;
@Column(name = "start_date", nullable = true) @Column(name = "start_date", nullable = true)
@Temporal(TemporalType.DATE) private LocalDate startDate;
private Date startDate;
@Column(name = "end_date", nullable = true) @Column(name = "end_date", nullable = true)
@Temporal(TemporalType.DATE) private LocalDate endDate;
private Date endDate;
private FineractEntityToEntityMapping(final FineractEntityRelation relationId, final Long fromId, final Long toId, final Date startDate, private FineractEntityToEntityMapping(final FineractEntityRelation relationId, final Long fromId, final Long toId,
final Date endDate) { final LocalDate startDate, final LocalDate endDate) {
this.relationId = relationId; this.relationId = relationId;
this.fromId = fromId; this.fromId = fromId;
this.toId = toId; this.toId = toId;
@@ -70,8 +66,8 @@ public class FineractEntityToEntityMapping extends AbstractPersistableCustom {
// //
} }
public static FineractEntityToEntityMapping newMap(FineractEntityRelation relationId, Long fromId, Long toId, Date startDate, public static FineractEntityToEntityMapping newMap(FineractEntityRelation relationId, Long fromId, Long toId, LocalDate startDate,
Date endDate) { LocalDate endDate) {
return new FineractEntityToEntityMapping(relationId, fromId, toId, startDate, endDate); return new FineractEntityToEntityMapping(relationId, fromId, toId, startDate, endDate);
@@ -96,18 +92,16 @@ public class FineractEntityToEntityMapping extends AbstractPersistableCustom {
if (command.isChangeInDateParameterNamed(FineractEntityApiResourceConstants.startDate, this.startDate)) { if (command.isChangeInDateParameterNamed(FineractEntityApiResourceConstants.startDate, this.startDate)) {
final String valueAsInput = command.stringValueOfParameterNamed(FineractEntityApiResourceConstants.startDate); final String valueAsInput = command.stringValueOfParameterNamed(FineractEntityApiResourceConstants.startDate);
actualChanges.put(FineractEntityApiResourceConstants.startDate, valueAsInput); actualChanges.put(FineractEntityApiResourceConstants.startDate, valueAsInput);
final Date startDate = command.dateValueOfParameterNamed(FineractEntityApiResourceConstants.startDate); this.startDate = command.localDateValueOfParameterNamed(FineractEntityApiResourceConstants.startDate);
this.startDate = startDate;
} }
if (command.isChangeInDateParameterNamed(FineractEntityApiResourceConstants.endDate, this.endDate)) { if (command.isChangeInDateParameterNamed(FineractEntityApiResourceConstants.endDate, this.endDate)) {
final String valueAsInput = command.stringValueOfParameterNamed(FineractEntityApiResourceConstants.endDate); final String valueAsInput = command.stringValueOfParameterNamed(FineractEntityApiResourceConstants.endDate);
actualChanges.put(FineractEntityApiResourceConstants.endDate, valueAsInput); actualChanges.put(FineractEntityApiResourceConstants.endDate, valueAsInput);
final Date endDate = command.dateValueOfParameterNamed(FineractEntityApiResourceConstants.endDate); this.endDate = command.localDateValueOfParameterNamed(FineractEntityApiResourceConstants.endDate);
this.endDate = endDate;
} }
if (startDate != null && endDate != null) { if (startDate != null && endDate != null) {
if (endDate.before(startDate)) { if (endDate.isBefore(startDate)) {
throw new FineractEntityToEntityMappingDateException(startDate.toString(), endDate.toString()); throw new FineractEntityToEntityMappingDateException(startDate.toString(), endDate.toString());
} }
} }
@@ -18,7 +18,7 @@
*/ */
package org.apache.fineract.infrastructure.entityaccess.service; package org.apache.fineract.infrastructure.entityaccess.service;
import java.util.Date; import java.time.LocalDate;
import org.apache.fineract.infrastructure.codes.domain.CodeValueRepositoryWrapper; import org.apache.fineract.infrastructure.codes.domain.CodeValueRepositoryWrapper;
import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService; import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService;
import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationProperty; import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationProperty;
@@ -87,8 +87,8 @@ public class FineractEntityAccessUtil {
if (restrictToUserOfficeProperty.isEnabled()) { if (restrictToUserOfficeProperty.isEnabled()) {
final Long officeId = thisUser.getOffice().getId(); final Long officeId = thisUser.getOffice().getId();
Date startDateFormapping = null; LocalDate startDateFormapping = null;
Date endDateFormapping = null; LocalDate endDateFormapping = null;
FineractEntityRelation fineractEntityRelation = fineractEntityRelationRepositoryWrapper FineractEntityRelation fineractEntityRelation = fineractEntityRelationRepositoryWrapper
.findOneByCodeName(fineractEntityAccessType.toStr()); .findOneByCodeName(fineractEntityAccessType.toStr());
Long relId = fineractEntityRelation.getId(); Long relId = fineractEntityRelation.getId();
@@ -18,7 +18,7 @@
*/ */
package org.apache.fineract.infrastructure.entityaccess.service; package org.apache.fineract.infrastructure.entityaccess.service;
import java.util.Date; import java.time.LocalDate;
import java.util.Map; import java.util.Map;
import javax.persistence.PersistenceException; import javax.persistence.PersistenceException;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
@@ -95,12 +95,12 @@ public class FineractEntityAccessWriteServiceImpl implements FineractEntityAcces
final Long fromId = command.longValueOfParameterNamed(FineractEntityApiResourceConstants.fromEnityType); final Long fromId = command.longValueOfParameterNamed(FineractEntityApiResourceConstants.fromEnityType);
final Long toId = command.longValueOfParameterNamed(FineractEntityApiResourceConstants.toEntityType); final Long toId = command.longValueOfParameterNamed(FineractEntityApiResourceConstants.toEntityType);
final Date startDate = command.dateValueOfParameterNamed(FineractEntityApiResourceConstants.startDate); final LocalDate startDate = command.localDateValueOfParameterNamed(FineractEntityApiResourceConstants.startDate);
final Date endDate = command.dateValueOfParameterNamed(FineractEntityApiResourceConstants.endDate); final LocalDate endDate = command.localDateValueOfParameterNamed(FineractEntityApiResourceConstants.endDate);
fromApiJsonDeserializer.checkForEntity(relId.toString(), fromId, toId); fromApiJsonDeserializer.checkForEntity(relId.toString(), fromId, toId);
if (startDate != null && endDate != null) { if (startDate != null && endDate != null) {
if (endDate.before(startDate)) { if (endDate.isBefore(startDate)) {
throw new FineractEntityToEntityMappingDateException(startDate.toString(), endDate.toString()); throw new FineractEntityToEntityMappingDateException(startDate.toString(), endDate.toString());
} }
} }
@@ -29,9 +29,7 @@ import static org.apache.fineract.portfolio.savings.SavingsApiConstants.localePa
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@@ -44,8 +42,6 @@ import javax.persistence.JoinColumn;
import javax.persistence.JoinTable; import javax.persistence.JoinTable;
import javax.persistence.ManyToMany; import javax.persistence.ManyToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
@@ -53,7 +49,6 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.organisation.holiday.api.HolidayApiConstants; import org.apache.fineract.organisation.holiday.api.HolidayApiConstants;
import org.apache.fineract.organisation.office.domain.Office; import org.apache.fineract.organisation.office.domain.Office;
@@ -65,16 +60,13 @@ public class Holiday extends AbstractPersistableCustom {
private String name; private String name;
@Column(name = "from_date", nullable = false) @Column(name = "from_date", nullable = false)
@Temporal(TemporalType.DATE) private LocalDate fromDate;
private Date fromDate;
@Column(name = "to_date", nullable = false) @Column(name = "to_date", nullable = false)
@Temporal(TemporalType.DATE) private LocalDate toDate;
private Date toDate;
@Column(name = "repayments_rescheduled_to", nullable = true) @Column(name = "repayments_rescheduled_to", nullable = true)
@Temporal(TemporalType.DATE) private LocalDate repaymentsRescheduledTo;
private Date repaymentsRescheduledTo;
@Column(name = "rescheduling_type", nullable = false) @Column(name = "rescheduling_type", nullable = false)
private int reschedulingType; private int reschedulingType;
@@ -150,8 +142,7 @@ public class Holiday extends AbstractPersistableCustom {
actualChanges.put(fromDateParamName, valueAsInput); actualChanges.put(fromDateParamName, valueAsInput);
actualChanges.put(dateFormatParamName, dateFormatAsInput); actualChanges.put(dateFormatParamName, dateFormatAsInput);
actualChanges.put(localeParamName, localeAsInput); actualChanges.put(localeParamName, localeAsInput);
final LocalDate newValue = command.localDateValueOfParameterNamed(fromDateParamName); this.fromDate = command.localDateValueOfParameterNamed(fromDateParamName);
this.fromDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant());
} }
if (command.isChangeInLocalDateParameterNamed(toDateParamName, getToDateLocalDate())) { if (command.isChangeInLocalDateParameterNamed(toDateParamName, getToDateLocalDate())) {
@@ -160,8 +151,7 @@ public class Holiday extends AbstractPersistableCustom {
actualChanges.put(dateFormatParamName, dateFormatAsInput); actualChanges.put(dateFormatParamName, dateFormatAsInput);
actualChanges.put(localeParamName, localeAsInput); actualChanges.put(localeParamName, localeAsInput);
final LocalDate newValue = command.localDateValueOfParameterNamed(toDateParamName); this.toDate = command.localDateValueOfParameterNamed(toDateParamName);
this.toDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant());
} }
if (command.isChangeInLocalDateParameterNamed(repaymentsRescheduledToParamName, getRepaymentsRescheduledToLocalDate())) { if (command.isChangeInLocalDateParameterNamed(repaymentsRescheduledToParamName, getRepaymentsRescheduledToLocalDate())) {
@@ -170,8 +160,7 @@ public class Holiday extends AbstractPersistableCustom {
actualChanges.put(dateFormatParamName, dateFormatAsInput); actualChanges.put(dateFormatParamName, dateFormatAsInput);
actualChanges.put(localeParamName, localeAsInput); actualChanges.put(localeParamName, localeAsInput);
final LocalDate newValue = command.localDateValueOfParameterNamed(repaymentsRescheduledToParamName); this.repaymentsRescheduledTo = command.localDateValueOfParameterNamed(repaymentsRescheduledToParamName);
this.repaymentsRescheduledTo = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant());
} }
if (command.hasParameter(officesParamName)) { if (command.hasParameter(officesParamName)) {
@@ -234,15 +223,15 @@ public class Holiday extends AbstractPersistableCustom {
} }
if (fromDate != null) { if (fromDate != null) {
this.fromDate = Date.from(fromDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.fromDate = fromDate;
} }
if (toDate != null) { if (toDate != null) {
this.toDate = Date.from(toDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.toDate = toDate;
} }
if (repaymentsRescheduledTo != null) { if (repaymentsRescheduledTo != null) {
this.repaymentsRescheduledTo = Date.from(repaymentsRescheduledTo.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.repaymentsRescheduledTo = repaymentsRescheduledTo;
} }
this.status = status; this.status = status;
@@ -263,11 +252,7 @@ public class Holiday extends AbstractPersistableCustom {
protected Holiday() {} protected Holiday() {}
public LocalDate getRepaymentsRescheduledToLocalDate() { public LocalDate getRepaymentsRescheduledToLocalDate() {
LocalDate repaymentsRescheduledTo = null; return this.repaymentsRescheduledTo;
if (this.repaymentsRescheduledTo != null) {
repaymentsRescheduledTo = LocalDate.ofInstant(this.repaymentsRescheduledTo.toInstant(), DateUtils.getDateTimeZoneOfTenant());
}
return repaymentsRescheduledTo;
} }
public boolean isProcessed() { public boolean isProcessed() {
@@ -279,19 +264,11 @@ public class Holiday extends AbstractPersistableCustom {
} }
public LocalDate getFromDateLocalDate() { public LocalDate getFromDateLocalDate() {
LocalDate fromDate = null; return this.fromDate;
if (this.fromDate != null) {
fromDate = LocalDate.ofInstant(this.fromDate.toInstant(), DateUtils.getDateTimeZoneOfTenant());
}
return fromDate;
} }
public LocalDate getToDateLocalDate() { public LocalDate getToDateLocalDate() {
LocalDate toDate = null; return this.toDate;
if (this.toDate != null) {
toDate = LocalDate.ofInstant(this.toDate.toInstant(), DateUtils.getDateTimeZoneOfTenant());
}
return toDate;
} }
public void processed() { public void processed() {
@@ -18,7 +18,7 @@
*/ */
package org.apache.fineract.organisation.holiday.domain; package org.apache.fineract.organisation.holiday.domain;
import java.util.Date; import java.time.LocalDate;
import java.util.List; import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
@@ -28,7 +28,7 @@ import org.springframework.data.repository.query.Param;
public interface HolidayRepository extends JpaRepository<Holiday, Long>, JpaSpecificationExecutor<Holiday> { public interface HolidayRepository extends JpaRepository<Holiday, Long>, JpaSpecificationExecutor<Holiday> {
@Query("select holiday from Holiday holiday, IN(holiday.offices) office where (holiday.fromDate >= :date OR :date <= holiday.toDate) and holiday.status = :status and office.id = :officeId") @Query("select holiday from Holiday holiday, IN(holiday.offices) office where (holiday.fromDate >= :date OR :date <= holiday.toDate) and holiday.status = :status and office.id = :officeId")
List<Holiday> findByOfficeIdAndGreaterThanDate(@Param("officeId") Long officeId, @Param("date") Date date, List<Holiday> findByOfficeIdAndGreaterThanDate(@Param("officeId") Long officeId, @Param("date") LocalDate date,
@Param("status") Integer status); @Param("status") Integer status);
@Query("select holiday from Holiday holiday where holiday.processed = false and holiday.status = :status") @Query("select holiday from Holiday holiday where holiday.processed = false and holiday.status = :status")
@@ -19,8 +19,6 @@
package org.apache.fineract.organisation.holiday.domain; package org.apache.fineract.organisation.holiday.domain;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.fineract.organisation.holiday.exception.HolidayNotFoundException; import org.apache.fineract.organisation.holiday.exception.HolidayNotFoundException;
import org.apache.fineract.organisation.holiday.service.HolidayUtil; import org.apache.fineract.organisation.holiday.service.HolidayUtil;
@@ -62,7 +60,7 @@ public class HolidayRepositoryWrapper {
this.repository.delete(holiday); this.repository.delete(holiday);
} }
public List<Holiday> findByOfficeIdAndGreaterThanDate(final Long officeId, final Date date) { public List<Holiday> findByOfficeIdAndGreaterThanDate(final Long officeId, final LocalDate date) {
return this.repository.findByOfficeIdAndGreaterThanDate(officeId, date, HolidayStatusType.ACTIVE.getValue()); return this.repository.findByOfficeIdAndGreaterThanDate(officeId, date, HolidayStatusType.ACTIVE.getValue());
} }
@@ -71,8 +69,7 @@ public class HolidayRepositoryWrapper {
} }
public boolean isHoliday(Long officeId, LocalDate transactionDate) { public boolean isHoliday(Long officeId, LocalDate transactionDate) {
final List<Holiday> holidays = findByOfficeIdAndGreaterThanDate(officeId, final List<Holiday> holidays = findByOfficeIdAndGreaterThanDate(officeId, transactionDate);
Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
return HolidayUtil.isHoliday(transactionDate, holidays); return HolidayUtil.isHoliday(transactionDate, holidays);
} }
} }
@@ -19,8 +19,6 @@
package org.apache.fineract.organisation.staff.domain; package org.apache.fineract.organisation.staff.domain;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import javax.persistence.Column; import javax.persistence.Column;
@@ -29,8 +27,6 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
@@ -77,8 +73,7 @@ public class Staff extends AbstractPersistableCustom {
private boolean active; private boolean active;
@Column(name = "joining_date", nullable = true) @Column(name = "joining_date", nullable = true)
@Temporal(TemporalType.DATE) private LocalDate joiningDate;
private Date joiningDate;
@ManyToOne @ManyToOne
@JoinColumn(name = "organisational_role_parent_staff_id", nullable = true) @JoinColumn(name = "organisational_role_parent_staff_id", nullable = true)
@@ -132,9 +127,7 @@ public class Staff extends AbstractPersistableCustom {
this.loanOfficer = isLoanOfficer; this.loanOfficer = isLoanOfficer;
this.active = isActive == null ? true : isActive; this.active = isActive == null ? true : isActive;
deriveDisplayName(firstname); deriveDisplayName(firstname);
if (joiningDate != null) { this.joiningDate = joiningDate;
this.joiningDate = Date.from(joiningDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
} }
public EnumOptionData organisationalRoleData() { public EnumOptionData organisationalRoleData() {
@@ -213,8 +206,7 @@ public class Staff extends AbstractPersistableCustom {
if (command.isChangeInDateParameterNamed(joiningDateParamName, this.joiningDate)) { if (command.isChangeInDateParameterNamed(joiningDateParamName, this.joiningDate)) {
final String valueAsInput = command.stringValueOfParameterNamed(joiningDateParamName); final String valueAsInput = command.stringValueOfParameterNamed(joiningDateParamName);
actualChanges.put(joiningDateParamName, valueAsInput); actualChanges.put(joiningDateParamName, valueAsInput);
final LocalDate newValue = command.localDateValueOfParameterNamed(joiningDateParamName); this.joiningDate = command.localDateValueOfParameterNamed(joiningDateParamName);
this.joiningDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant());
} }
return actualChanges; return actualChanges;
@@ -34,9 +34,7 @@ import static org.apache.fineract.portfolio.account.api.StandingInstructionApiCo
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.MonthDay; import java.time.MonthDay;
import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -45,15 +43,12 @@ import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.ApiParameterError; import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType; import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType;
@Entity @Entity
@@ -80,13 +75,11 @@ public class AccountTransferStandingInstruction extends AbstractPersistableCusto
@Column(name = "amount", scale = 6, precision = 19, nullable = true) @Column(name = "amount", scale = 6, precision = 19, nullable = true)
private BigDecimal amount; private BigDecimal amount;
@Temporal(TemporalType.DATE)
@Column(name = "valid_from") @Column(name = "valid_from")
private Date validFrom; private LocalDate validFrom;
@Temporal(TemporalType.DATE)
@Column(name = "valid_till") @Column(name = "valid_till")
private Date validTill; private LocalDate validTill;
@Column(name = "recurrence_type") @Column(name = "recurrence_type")
private Integer recurrenceType; private Integer recurrenceType;
@@ -103,9 +96,8 @@ public class AccountTransferStandingInstruction extends AbstractPersistableCusto
@Column(name = "recurrence_on_month") @Column(name = "recurrence_on_month")
private Integer recurrenceOnMonth; private Integer recurrenceOnMonth;
@Temporal(TemporalType.DATE)
@Column(name = "last_run_date") @Column(name = "last_run_date")
private Date latsRunDate; private LocalDate latsRunDate;
protected AccountTransferStandingInstruction() { protected AccountTransferStandingInstruction() {
@@ -135,14 +127,8 @@ public class AccountTransferStandingInstruction extends AbstractPersistableCusto
this.instructionType = instructionType; this.instructionType = instructionType;
this.status = status; this.status = status;
this.amount = amount; this.amount = amount;
if (validFrom != null) { this.validFrom = validFrom;
this.validFrom = Date.from(validFrom.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.validTill = validTill;
}
if (validTill == null) {
this.validTill = null;
} else {
this.validTill = Date.from(validTill.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
this.recurrenceType = recurrenceType; this.recurrenceType = recurrenceType;
this.recurrenceFrequency = recurrenceFrequency; this.recurrenceFrequency = recurrenceFrequency;
this.recurrenceInterval = recurrenceInterval; this.recurrenceInterval = recurrenceInterval;
@@ -170,15 +156,13 @@ public class AccountTransferStandingInstruction extends AbstractPersistableCusto
} }
if (command.isChangeInDateParameterNamed(validFromParamName, this.validFrom)) { if (command.isChangeInDateParameterNamed(validFromParamName, this.validFrom)) {
final LocalDate newValue = command.localDateValueOfParameterNamed(validFromParamName); this.validFrom = command.localDateValueOfParameterNamed(validFromParamName);
actualChanges.put(validFromParamName, newValue); actualChanges.put(validFromParamName, this.validFrom);
this.validFrom = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant());
} }
if (command.isChangeInDateParameterNamed(validTillParamName, this.validTill)) { if (command.isChangeInDateParameterNamed(validTillParamName, this.validTill)) {
final LocalDate newValue = command.localDateValueOfParameterNamed(validTillParamName); this.validTill = command.localDateValueOfParameterNamed(validTillParamName);
actualChanges.put(validTillParamName, newValue); actualChanges.put(validTillParamName, this.validTill);
this.validTill = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant());
} }
if (command.isChangeInBigDecimalParameterNamed(amountParamName, this.amount)) { if (command.isChangeInBigDecimalParameterNamed(amountParamName, this.amount)) {
@@ -248,9 +232,7 @@ public class AccountTransferStandingInstruction extends AbstractPersistableCusto
private void validateDependencies(final DataValidatorBuilder baseDataValidator) { private void validateDependencies(final DataValidatorBuilder baseDataValidator) {
if (this.validTill != null && this.validFrom != null) { if (this.validTill != null && this.validFrom != null) {
baseDataValidator.reset().parameter(validTillParamName) baseDataValidator.reset().parameter(validTillParamName).value(this.validTill).validateDateAfter(this.validFrom);
.value(LocalDate.ofInstant(this.validTill.toInstant(), DateUtils.getDateTimeZoneOfTenant()))
.validateDateAfter(LocalDate.ofInstant(this.validFrom.toInstant(), DateUtils.getDateTimeZoneOfTenant()));
} }
if (AccountTransferRecurrenceType.fromInt(recurrenceType).isPeriodicRecurrence()) { if (AccountTransferRecurrenceType.fromInt(recurrenceType).isPeriodicRecurrence()) {
@@ -290,7 +272,7 @@ public class AccountTransferStandingInstruction extends AbstractPersistableCusto
} }
public void updateLatsRunDate(Date latsRunDate) { public void updateLatsRunDate(LocalDate latsRunDate) {
this.latsRunDate = latsRunDate; this.latsRunDate = latsRunDate;
} }
@@ -593,9 +593,7 @@ public class AccountDetailsReadPlatformServiceJpaRepositoryImpl implements Accou
.append(" join m_client as c on c.id = g.entity_id ").append(" LEFT JOIN m_product_loan AS lp ON lp.id = l.product_id") .append(" join m_client as c on c.id = g.entity_id ").append(" LEFT JOIN m_product_loan AS lp ON lp.id = l.product_id")
.append(" left join m_loan_arrears_aging la on la.loan_id = l.id") .append(" left join m_loan_arrears_aging la on la.loan_id = l.id")
.append(" left join m_code_value cv ON cv.id = g.client_reln_cv_id") .append(" left join m_code_value cv ON cv.id = g.client_reln_cv_id")
.append(" left join m_savings_account sa on sa.client_id = c.id") .append(" left join m_savings_account sa on sa.client_id = c.id");
;
return accountsSummary.toString(); return accountsSummary.toString();
} }
@@ -730,8 +730,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
if (loanStatus.isOpen() || loanStatus.isPendingApproval() || loanStatus.isAwaitingDisbursal()) { if (loanStatus.isOpen() || loanStatus.isPendingApproval() || loanStatus.isAwaitingDisbursal()) {
final String errorMessage = "Client cannot be closed because of non-closed loans."; final String errorMessage = "Client cannot be closed because of non-closed loans.";
throw new InvalidClientStateTransitionException("close", "loan.non-closed", errorMessage); throw new InvalidClientStateTransitionException("close", "loan.non-closed", errorMessage);
} else if (loanStatus.isClosed() } else if (loanStatus.isClosed() && loan.getClosedOnDate().isAfter(closureDate)) {
&& loan.getClosedOnDate().after(Date.from(closureDate.atStartOfDay(ZoneId.systemDefault()).toInstant()))) {
final String errorMessage = "The client closureDate cannot be before the loan closedOnDate."; final String errorMessage = "The client closureDate cannot be before the loan closedOnDate.";
throw new InvalidClientStateTransitionException("close", "date.cannot.before.loan.closed.date", errorMessage, throw new InvalidClientStateTransitionException("close", "date.cannot.before.loan.closed.date", errorMessage,
closureDate, loan.getClosedOnDate()); closureDate, loan.getClosedOnDate());
@@ -19,20 +19,20 @@
package org.apache.fineract.portfolio.floatingrates.data; package org.apache.fineract.portfolio.floatingrates.data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.time.LocalDate;
public class InterestRatePeriodData { public class InterestRatePeriodData {
private Date fromDate; private LocalDate fromDate;
private final BigDecimal interestRate; private final BigDecimal interestRate;
private final boolean isDifferentialToBLR; private final boolean isDifferentialToBLR;
private final Date blrFromDate; private final LocalDate blrFromDate;
private final BigDecimal blrInterestRate; private final BigDecimal blrInterestRate;
private BigDecimal loanDifferentialInterestRate; private BigDecimal loanDifferentialInterestRate;
private BigDecimal loanProductDifferentialInterestRate; private BigDecimal loanProductDifferentialInterestRate;
private BigDecimal effectiveInterestRate; private BigDecimal effectiveInterestRate;
public InterestRatePeriodData(Date fromDate, BigDecimal interestRate, boolean isDifferentialToBLR, Date blrFromDate, public InterestRatePeriodData(LocalDate fromDate, BigDecimal interestRate, boolean isDifferentialToBLR, LocalDate blrFromDate,
BigDecimal blrInterestRate) { BigDecimal blrInterestRate) {
this.fromDate = fromDate; this.fromDate = fromDate;
this.interestRate = interestRate; this.interestRate = interestRate;
@@ -41,11 +41,11 @@ public class InterestRatePeriodData {
this.blrInterestRate = blrInterestRate; this.blrInterestRate = blrInterestRate;
} }
public Date getFromDate() { public LocalDate getFromDate() {
return this.fromDate; return this.fromDate;
} }
public void setFromDate(Date fromDate) { public void setFromDate(LocalDate fromDate) {
this.fromDate = fromDate; this.fromDate = fromDate;
} }
@@ -57,7 +57,7 @@ public class InterestRatePeriodData {
return this.isDifferentialToBLR; return this.isDifferentialToBLR;
} }
public Date getBlrFromDate() { public LocalDate getBlrFromDate() {
return this.blrFromDate; return this.blrFromDate;
} }
@@ -19,10 +19,10 @@
package org.apache.fineract.portfolio.floatingrates.service; package org.apache.fineract.portfolio.floatingrates.service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Date;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.fineract.infrastructure.core.domain.JdbcSupport; import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
import org.apache.fineract.portfolio.floatingrates.data.FloatingRateData; import org.apache.fineract.portfolio.floatingrates.data.FloatingRateData;
@@ -221,8 +221,9 @@ public class FloatingRatesReadPlatformServiceImpl implements FloatingRatesReadPl
final boolean isDifferentialToBLR = rs.getBoolean("linkedrateperiods_is_differential_to_base_lending_rate"); final boolean isDifferentialToBLR = rs.getBoolean("linkedrateperiods_is_differential_to_base_lending_rate");
final Date blrFromDate = rs.getDate("baserate_from_date"); final Date blrFromDate = rs.getDate("baserate_from_date");
final BigDecimal blrInterestRate = rs.getBigDecimal("baserate_interest_rate"); final BigDecimal blrInterestRate = rs.getBigDecimal("baserate_interest_rate");
final LocalDate fromLocalDate = fromDate != null ? fromDate.toLocalDate() : null;
return new InterestRatePeriodData(fromDate, interestRate, isDifferentialToBLR, blrFromDate, blrInterestRate); final LocalDate blrFromLocalDate = blrFromDate != null ? blrFromDate.toLocalDate() : null;
return new InterestRatePeriodData(fromLocalDate, interestRate, isDifferentialToBLR, blrFromLocalDate, blrInterestRate);
} }
public String schema() { public String schema() {
@@ -19,9 +19,7 @@
package org.apache.fineract.portfolio.group.service; package org.apache.fineract.portfolio.group.service;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@@ -618,8 +616,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
final String errorMessage = groupOrCenter.getGroupLevel().getLevelName() + " cannot be closed because of non-closed loans."; final String errorMessage = groupOrCenter.getGroupLevel().getLevelName() + " cannot be closed because of non-closed loans.";
throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(), "close", "loan.not.closed", throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(), "close", "loan.not.closed",
errorMessage); errorMessage);
} else if (loanStatus.isClosed() } else if (loanStatus.isClosed() && loan.getClosedOnDate().isAfter(closureDate)) {
&& loan.getClosedOnDate().after(Date.from(closureDate.atStartOfDay(ZoneId.systemDefault()).toInstant()))) {
final String errorMessage = groupOrCenter.getGroupLevel().getLevelName() final String errorMessage = groupOrCenter.getGroupLevel().getLevelName()
+ "closureDate cannot be before the loan closedOnDate."; + "closureDate cannot be before the loan closedOnDate.";
throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(), "close", throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(), "close",
@@ -20,8 +20,6 @@ package org.apache.fineract.portfolio.loanaccount.data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.Map; import java.util.Map;
import org.apache.fineract.organisation.monetary.data.CurrencyData; import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType; import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType;
@@ -88,8 +86,8 @@ public class LoanScheduleAccrualData {
return this.officeId; return this.officeId;
} }
public Date getDueDate() { public LocalDate getDueDate() {
return Date.from(this.dueDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); return this.dueDate;
} }
public LocalDate getDueDateAsLocaldate() { public LocalDate getDueDateAsLocaldate() {
@@ -21,11 +21,9 @@ package org.apache.fineract.portfolio.loanaccount.domain;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -377,8 +375,8 @@ public class LoanAccountDomainServiceJpa implements LoanAccountDomainService {
loan.handlePayDisbursementTransaction(chargeId, newPaymentTransaction, existingTransactionIds, existingReversedTransactionIds); loan.handlePayDisbursementTransaction(chargeId, newPaymentTransaction, existingTransactionIds, existingReversedTransactionIds);
} else { } else {
final boolean allowTransactionsOnHoliday = this.configurationDomainService.allowTransactionsOnHolidayEnabled(); final boolean allowTransactionsOnHoliday = this.configurationDomainService.allowTransactionsOnHolidayEnabled();
final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(), final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(), transactionDate,
Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), HolidayStatusType.ACTIVE.getValue()); HolidayStatusType.ACTIVE.getValue());
final WorkingDays workingDays = this.workingDaysRepository.findOne(); final WorkingDays workingDays = this.workingDaysRepository.findOne();
final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled(); final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled();
final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled(); final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled();
@@ -454,8 +452,8 @@ public class LoanAccountDomainServiceJpa implements LoanAccountDomainService {
final LoanTransaction newRefundTransaction = LoanTransaction.refund(loan.getOffice(), refundAmount, paymentDetail, transactionDate, final LoanTransaction newRefundTransaction = LoanTransaction.refund(loan.getOffice(), refundAmount, paymentDetail, transactionDate,
txnExternalId); txnExternalId);
final boolean allowTransactionsOnHoliday = this.configurationDomainService.allowTransactionsOnHolidayEnabled(); final boolean allowTransactionsOnHoliday = this.configurationDomainService.allowTransactionsOnHolidayEnabled();
final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(), final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(), transactionDate,
Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), HolidayStatusType.ACTIVE.getValue()); HolidayStatusType.ACTIVE.getValue());
final WorkingDays workingDays = this.workingDaysRepository.findOne(); final WorkingDays workingDays = this.workingDaysRepository.findOne();
final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled(); final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled();
@@ -542,7 +540,7 @@ public class LoanAccountDomainServiceJpa implements LoanAccountDomainService {
} }
boolean isOrganisationDateEnabled = this.configurationDomainService.isOrganisationstartDateEnabled(); boolean isOrganisationDateEnabled = this.configurationDomainService.isOrganisationstartDateEnabled();
Date organisationStartDate = DateUtils.getBusinessDate(); LocalDate organisationStartDate = DateUtils.getBusinessLocalDate();
if (isOrganisationDateEnabled) { if (isOrganisationDateEnabled) {
organisationStartDate = this.configurationDomainService.retrieveOrganisationStartDate(); organisationStartDate = this.configurationDomainService.retrieveOrganisationStartDate();
} }
@@ -564,8 +562,7 @@ public class LoanAccountDomainServiceJpa implements LoanAccountDomainService {
if (installment.getDueDate().isAfter(loan.getMaturityDate())) { if (installment.getDueDate().isAfter(loan.getMaturityDate())) {
accruedTill = DateUtils.getBusinessLocalDate(); accruedTill = DateUtils.getBusinessLocalDate();
} }
if (!isOrganisationDateEnabled || LocalDate.ofInstant(organisationStartDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()) if (!isOrganisationDateEnabled || organisationStartDate.isBefore(installment.getDueDate())) {
.isBefore(installment.getDueDate())) {
generateLoanScheduleAccrualData(accruedTill, loanScheduleAccrualDatas, loanId, officeId, accrualStartDate, generateLoanScheduleAccrualData(accruedTill, loanScheduleAccrualDatas, loanId, officeId, accrualStartDate,
repaymentFrequency, repayEvery, interestCalculatedFrom, loanProductId, currency, currencyData, loanCharges, repaymentFrequency, repayEvery, interestCalculatedFrom, loanProductId, currency, currencyData, loanCharges,
installment); installment);
@@ -681,8 +678,8 @@ public class LoanAccountDomainServiceJpa implements LoanAccountDomainService {
final LoanTransaction newRefundTransaction = LoanTransaction.refundForActiveLoan(loan.getOffice(), refundAmount, paymentDetail, final LoanTransaction newRefundTransaction = LoanTransaction.refundForActiveLoan(loan.getOffice(), refundAmount, paymentDetail,
transactionDate, txnExternalId); transactionDate, txnExternalId);
final boolean allowTransactionsOnHoliday = this.configurationDomainService.allowTransactionsOnHolidayEnabled(); final boolean allowTransactionsOnHoliday = this.configurationDomainService.allowTransactionsOnHolidayEnabled();
final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(), final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(), transactionDate,
Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), HolidayStatusType.ACTIVE.getValue()); HolidayStatusType.ACTIVE.getValue());
final WorkingDays workingDays = this.workingDaysRepository.findOne(); final WorkingDays workingDays = this.workingDaysRepository.findOne();
final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled(); final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled();
@@ -21,11 +21,9 @@ package org.apache.fineract.portfolio.loanaccount.domain;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.MathContext; import java.math.MathContext;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@@ -40,12 +38,9 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
import org.apache.fineract.organisation.monetary.domain.Money; import org.apache.fineract.organisation.monetary.domain.Money;
import org.apache.fineract.organisation.monetary.domain.MoneyHelper; import org.apache.fineract.organisation.monetary.domain.MoneyHelper;
@@ -72,9 +67,8 @@ public class LoanCharge extends AbstractPersistableCustom {
@Column(name = "charge_time_enum", nullable = false) @Column(name = "charge_time_enum", nullable = false)
private Integer chargeTime; private Integer chargeTime;
@Temporal(TemporalType.DATE)
@Column(name = "due_for_collection_as_of_date") @Column(name = "due_for_collection_as_of_date")
private Date dueDate; private LocalDate dueDate;
@Column(name = "charge_calculation_enum") @Column(name = "charge_calculation_enum")
private Integer chargeCalculation; private Integer chargeCalculation;
@@ -201,8 +195,7 @@ public class LoanCharge extends AbstractPersistableCustom {
if (chargeDefinition.getChargeTimeType().equals(ChargeTimeType.SPECIFIED_DUE_DATE.getValue()) && loan.isMultiDisburmentLoan()) { if (chargeDefinition.getChargeTimeType().equals(ChargeTimeType.SPECIFIED_DUE_DATE.getValue()) && loan.isMultiDisburmentLoan()) {
amountPercentageAppliedTo = BigDecimal.ZERO; amountPercentageAppliedTo = BigDecimal.ZERO;
for (final LoanDisbursementDetails loanDisbursementDetails : loan.getDisbursementDetails()) { for (final LoanDisbursementDetails loanDisbursementDetails : loan.getDisbursementDetails()) {
if (!loanDisbursementDetails.expectedDisbursementDate() if (!loanDisbursementDetails.expectedDisbursementDate().isAfter(dueDate)) {
.after(Date.from(dueDate.atStartOfDay(ZoneId.systemDefault()).toInstant()))) {
amountPercentageAppliedTo = amountPercentageAppliedTo.add(loanDisbursementDetails.principal()); amountPercentageAppliedTo = amountPercentageAppliedTo.add(loanDisbursementDetails.principal());
} }
} }
@@ -252,7 +245,7 @@ public class LoanCharge extends AbstractPersistableCustom {
chargeDefinition.getName()); chargeDefinition.getName());
} }
this.dueDate = Date.from(dueDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.dueDate = dueDate;
} else { } else {
this.dueDate = null; this.dueDate = null;
} }
@@ -400,7 +393,7 @@ public class LoanCharge extends AbstractPersistableCustom {
public void update(final BigDecimal amount, final LocalDate dueDate, final BigDecimal loanPrincipal, Integer numberOfRepayments, public void update(final BigDecimal amount, final LocalDate dueDate, final BigDecimal loanPrincipal, Integer numberOfRepayments,
BigDecimal loanCharge) { BigDecimal loanCharge) {
if (dueDate != null) { if (dueDate != null) {
this.dueDate = Date.from(dueDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.dueDate = dueDate;
} }
if (amount != null) { if (amount != null) {
@@ -448,7 +441,7 @@ public class LoanCharge extends AbstractPersistableCustom {
// much amount disbursed. // much amount disbursed.
if (this.loan.isMultiDisburmentLoan() && this.isSpecifiedDueDate()) { if (this.loan.isMultiDisburmentLoan() && this.isSpecifiedDueDate()) {
for (final LoanDisbursementDetails loanDisbursementDetails : this.loan.getDisbursementDetails()) { for (final LoanDisbursementDetails loanDisbursementDetails : this.loan.getDisbursementDetails()) {
if (!loanDisbursementDetails.expectedDisbursementDate().after(this.getDueDate())) { if (!loanDisbursementDetails.expectedDisbursementDate().isAfter(this.getDueDate())) {
amountPercentageAppliedTo = amountPercentageAppliedTo.add(loanDisbursementDetails.principal()); amountPercentageAppliedTo = amountPercentageAppliedTo.add(loanDisbursementDetails.principal());
} }
} }
@@ -487,8 +480,7 @@ public class LoanCharge extends AbstractPersistableCustom {
actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("dateFormat", dateFormatAsInput);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
final LocalDate newValue = command.localDateValueOfParameterNamed(dueDateParamName); this.dueDate = command.localDateValueOfParameterNamed(dueDateParamName);
this.dueDate = Date.from(newValue.atStartOfDay(ZoneId.systemDefault()).toInstant());
} }
final String amountParamName = "amount"; final String amountParamName = "amount";
@@ -596,14 +588,10 @@ public class LoanCharge extends AbstractPersistableCustom {
} }
public LocalDate getDueLocalDate() { public LocalDate getDueLocalDate() {
LocalDate dueDate = null; return this.dueDate;
if (this.dueDate != null) {
dueDate = LocalDate.ofInstant(this.dueDate.toInstant(), DateUtils.getDateTimeZoneOfTenant());
}
return dueDate;
} }
public Date getDueDate() { public LocalDate getDueDate() {
return this.dueDate; return this.dueDate;
} }
@@ -20,17 +20,13 @@ package org.apache.fineract.portfolio.loanaccount.domain;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Date;
import java.util.Objects; import java.util.Objects;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.portfolio.loanaccount.data.DisbursementData; import org.apache.fineract.portfolio.loanaccount.data.DisbursementData;
@Entity @Entity
@@ -41,13 +37,11 @@ public class LoanDisbursementDetails extends AbstractPersistableCustom {
@JoinColumn(name = "loan_id", nullable = false) @JoinColumn(name = "loan_id", nullable = false)
private Loan loan; private Loan loan;
@Temporal(TemporalType.DATE)
@Column(name = "expected_disburse_date") @Column(name = "expected_disburse_date")
private Date expectedDisbursementDate; private LocalDate expectedDisbursementDate;
@Temporal(TemporalType.DATE)
@Column(name = "disbursedon_date") @Column(name = "disbursedon_date")
private Date actualDisbursementDate; private LocalDate actualDisbursementDate;
@Column(name = "principal", scale = 6, precision = 19, nullable = false) @Column(name = "principal", scale = 6, precision = 19, nullable = false)
private BigDecimal principal; private BigDecimal principal;
@@ -59,8 +53,8 @@ public class LoanDisbursementDetails extends AbstractPersistableCustom {
} }
public LoanDisbursementDetails(final Date expectedDisbursementDate, final Date actualDisbursementDate, final BigDecimal principal, public LoanDisbursementDetails(final LocalDate expectedDisbursementDate, final LocalDate actualDisbursementDate,
final BigDecimal netDisbursalAmount) { final BigDecimal principal, final BigDecimal netDisbursalAmount) {
this.expectedDisbursementDate = expectedDisbursementDate; this.expectedDisbursementDate = expectedDisbursementDate;
this.actualDisbursementDate = actualDisbursementDate; this.actualDisbursementDate = actualDisbursementDate;
this.principal = principal; this.principal = principal;
@@ -96,19 +90,19 @@ public class LoanDisbursementDetails extends AbstractPersistableCustom {
this.actualDisbursementDate = disbursementDetails.actualDisbursementDate; this.actualDisbursementDate = disbursementDetails.actualDisbursementDate;
} }
public Date expectedDisbursementDate() { public LocalDate expectedDisbursementDate() {
return this.expectedDisbursementDate; return this.expectedDisbursementDate;
} }
public LocalDate expectedDisbursementDateAsLocalDate() { public LocalDate expectedDisbursementDateAsLocalDate() {
LocalDate expectedDisburseDate = null; LocalDate expectedDisburseDate = null;
if (this.expectedDisbursementDate != null) { if (this.expectedDisbursementDate != null) {
expectedDisburseDate = LocalDate.ofInstant(this.expectedDisbursementDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); expectedDisburseDate = this.expectedDisbursementDate;
} }
return expectedDisburseDate; return expectedDisburseDate;
} }
public Date actualDisbursementDate() { public LocalDate actualDisbursementDate() {
return this.actualDisbursementDate; return this.actualDisbursementDate;
} }
@@ -120,26 +114,18 @@ public class LoanDisbursementDetails extends AbstractPersistableCustom {
this.principal = principal; this.principal = principal;
} }
public Date getDisbursementDate() { public LocalDate getDisbursementDate() {
Date disbursementDate = this.expectedDisbursementDate; return this.actualDisbursementDate;
if (this.actualDisbursementDate != null) {
disbursementDate = this.actualDisbursementDate;
}
return disbursementDate;
} }
public DisbursementData toData() { public DisbursementData toData() {
LocalDate expectedDisburseDate = expectedDisbursementDateAsLocalDate(); LocalDate expectedDisburseDate = expectedDisbursementDateAsLocalDate();
LocalDate actualDisburseDate = null;
if (this.actualDisbursementDate != null) {
actualDisburseDate = LocalDate.ofInstant(this.actualDisbursementDate.toInstant(), DateUtils.getDateTimeZoneOfTenant());
}
BigDecimal waivedChargeAmount = null; BigDecimal waivedChargeAmount = null;
return new DisbursementData(getId(), expectedDisburseDate, actualDisburseDate, this.principal, this.netDisbursalAmount, null, null, return new DisbursementData(getId(), expectedDisburseDate, this.actualDisbursementDate, this.principal, this.netDisbursalAmount,
waivedChargeAmount); null, null, waivedChargeAmount);
} }
public void updateActualDisbursementDate(Date actualDisbursementDate) { public void updateActualDisbursementDate(LocalDate actualDisbursementDate) {
this.actualDisbursementDate = actualDisbursementDate; this.actualDisbursementDate = actualDisbursementDate;
} }
@@ -151,7 +137,7 @@ public class LoanDisbursementDetails extends AbstractPersistableCustom {
this.netDisbursalAmount = netDisbursalAmount; this.netDisbursalAmount = netDisbursalAmount;
} }
public void updateExpectedDisbursementDateAndAmount(Date expectedDisbursementDate, BigDecimal principal) { public void updateExpectedDisbursementDateAndAmount(LocalDate expectedDisbursementDate, BigDecimal principal) {
this.expectedDisbursementDate = expectedDisbursementDate; this.expectedDisbursementDate = expectedDisbursementDate;
this.principal = principal; this.principal = principal;
} }
@@ -20,17 +20,12 @@ package org.apache.fineract.portfolio.loanaccount.domain;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.infrastructure.core.service.DateUtils;
@Entity @Entity
@Table(name = "m_loan_interest_recalculation_additional_details") @Table(name = "m_loan_interest_recalculation_additional_details")
@@ -40,9 +35,8 @@ public class LoanInterestRecalcualtionAdditionalDetails extends AbstractPersista
@JoinColumn(name = "loan_repayment_schedule_id", nullable = false) @JoinColumn(name = "loan_repayment_schedule_id", nullable = false)
private LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment; private LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment;
@Temporal(TemporalType.DATE)
@Column(name = "effective_date") @Column(name = "effective_date")
private Date effectiveDate; private LocalDate effectiveDate;
@Column(name = "amount", scale = 6, precision = 19, nullable = false) @Column(name = "amount", scale = 6, precision = 19, nullable = false)
private BigDecimal amount; private BigDecimal amount;
@@ -53,13 +47,13 @@ public class LoanInterestRecalcualtionAdditionalDetails extends AbstractPersista
public LoanInterestRecalcualtionAdditionalDetails(final LocalDate effectiveDate, final BigDecimal amount) { public LoanInterestRecalcualtionAdditionalDetails(final LocalDate effectiveDate, final BigDecimal amount) {
if (effectiveDate != null) { if (effectiveDate != null) {
this.effectiveDate = Date.from(effectiveDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.effectiveDate = effectiveDate;
} }
this.amount = amount; this.amount = amount;
} }
public LocalDate getEffectiveDate() { public LocalDate getEffectiveDate() {
return LocalDate.ofInstant(this.effectiveDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); return this.effectiveDate;
} }
public BigDecimal getAmount() { public BigDecimal getAmount() {
@@ -19,18 +19,12 @@
package org.apache.fineract.portfolio.loanaccount.domain; package org.apache.fineract.portfolio.loanaccount.domain;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom; import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.organisation.staff.domain.Staff; import org.apache.fineract.organisation.staff.domain.Staff;
@Entity @Entity
@@ -45,24 +39,21 @@ public class LoanOfficerAssignmentHistory extends AbstractAuditableCustom {
@JoinColumn(name = "loan_officer_id", nullable = true) @JoinColumn(name = "loan_officer_id", nullable = true)
private Staff loanOfficer; private Staff loanOfficer;
@Temporal(TemporalType.DATE)
@Column(name = "start_date") @Column(name = "start_date")
private Date startDate; private LocalDate startDate;
@Temporal(TemporalType.DATE)
@Column(name = "end_date") @Column(name = "end_date")
private Date endDate; private LocalDate endDate;
public static LoanOfficerAssignmentHistory createNew(final Loan loan, final Staff loanOfficer, final LocalDate startDate) { public static LoanOfficerAssignmentHistory createNew(final Loan loan, final Staff loanOfficer, final LocalDate startDate) {
return new LoanOfficerAssignmentHistory(loan, loanOfficer, Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), return new LoanOfficerAssignmentHistory(loan, loanOfficer, startDate, null);
null);
} }
protected LoanOfficerAssignmentHistory() { protected LoanOfficerAssignmentHistory() {
// //
} }
private LoanOfficerAssignmentHistory(final Loan loan, final Staff loanOfficer, final Date startDate, final Date endDate) { private LoanOfficerAssignmentHistory(final Loan loan, final Staff loanOfficer, final LocalDate startDate, final LocalDate endDate) {
this.loan = loan; this.loan = loan;
this.loanOfficer = loanOfficer; this.loanOfficer = loanOfficer;
this.startDate = startDate; this.startDate = startDate;
@@ -74,11 +65,11 @@ public class LoanOfficerAssignmentHistory extends AbstractAuditableCustom {
} }
public void updateStartDate(final LocalDate startDate) { public void updateStartDate(final LocalDate startDate) {
this.startDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.startDate = startDate;
} }
public void updateEndDate(final LocalDate endDate) { public void updateEndDate(final LocalDate endDate) {
this.endDate = Date.from(endDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.endDate = endDate;
} }
public boolean matchesStartDateOf(final LocalDate matchingDate) { public boolean matchesStartDateOf(final LocalDate matchingDate) {
@@ -86,7 +77,7 @@ public class LoanOfficerAssignmentHistory extends AbstractAuditableCustom {
} }
public LocalDate getStartDate() { public LocalDate getStartDate() {
return LocalDate.ofInstant(this.startDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); return this.startDate;
} }
public boolean hasStartDateBefore(final LocalDate matchingDate) { public boolean hasStartDateBefore(final LocalDate matchingDate) {
@@ -104,12 +95,11 @@ public class LoanOfficerAssignmentHistory extends AbstractAuditableCustom {
* @return * @return
*/ */
public boolean isEndDateAfter(final LocalDate compareDate) { public boolean isEndDateAfter(final LocalDate compareDate) {
return this.endDate == null ? false return this.endDate.isAfter(compareDate);
: LocalDate.ofInstant(this.endDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()).isAfter(compareDate);
} }
public LocalDate getEndDate() { public LocalDate getEndDate() {
return ObjectUtils.defaultIfNull(LocalDate.ofInstant(this.endDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()), null); return this.endDate;
} }
public boolean isSameLoanOfficer(final Staff staff) { public boolean isSameLoanOfficer(final Staff staff) {
@@ -20,9 +20,7 @@ package org.apache.fineract.portfolio.loanaccount.domain;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
@@ -33,10 +31,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom; import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
import org.apache.fineract.organisation.monetary.domain.Money; import org.apache.fineract.organisation.monetary.domain.Money;
import org.apache.fineract.portfolio.repaymentwithpostdatedchecks.domain.PostDatedChecks; import org.apache.fineract.portfolio.repaymentwithpostdatedchecks.domain.PostDatedChecks;
@@ -53,13 +48,11 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
@Column(name = "installment", nullable = false) @Column(name = "installment", nullable = false)
private Integer installmentNumber; private Integer installmentNumber;
@Temporal(TemporalType.DATE)
@Column(name = "fromdate", nullable = true) @Column(name = "fromdate", nullable = true)
private Date fromDate; private LocalDate fromDate;
@Temporal(TemporalType.DATE)
@Column(name = "duedate", nullable = false) @Column(name = "duedate", nullable = false)
private Date dueDate; private LocalDate dueDate;
@Column(name = "principal_amount", scale = 6, precision = 19, nullable = true) @Column(name = "principal_amount", scale = 6, precision = 19, nullable = true)
private BigDecimal principal; private BigDecimal principal;
@@ -127,9 +120,8 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
@Column(name = "completed_derived", nullable = false) @Column(name = "completed_derived", nullable = false)
private boolean obligationsMet; private boolean obligationsMet;
@Temporal(TemporalType.DATE)
@Column(name = "obligations_met_on_date") @Column(name = "obligations_met_on_date")
private Date obligationsMetOnDate; private LocalDate obligationsMetOnDate;
@Column(name = "recalculated_interest_component", nullable = false) @Column(name = "recalculated_interest_component", nullable = false)
private boolean recalculatedInterestComponent; private boolean recalculatedInterestComponent;
@@ -156,8 +148,8 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
final Set<LoanInterestRecalcualtionAdditionalDetails> compoundingDetails, final BigDecimal rescheduleInterestPortion) { final Set<LoanInterestRecalcualtionAdditionalDetails> compoundingDetails, final BigDecimal rescheduleInterestPortion) {
this.loan = loan; this.loan = loan;
this.installmentNumber = installmentNumber; this.installmentNumber = installmentNumber;
this.fromDate = Date.from(fromDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.fromDate = fromDate;
this.dueDate = Date.from(dueDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.dueDate = dueDate;
this.principal = defaultToNullIfZero(principal); this.principal = defaultToNullIfZero(principal);
this.interestCharged = defaultToNullIfZero(interest); this.interestCharged = defaultToNullIfZero(interest);
this.feeChargesCharged = defaultToNullIfZero(feeCharges); this.feeChargesCharged = defaultToNullIfZero(feeCharges);
@@ -177,8 +169,8 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
final Set<LoanInterestRecalcualtionAdditionalDetails> compoundingDetails) { final Set<LoanInterestRecalcualtionAdditionalDetails> compoundingDetails) {
this.loan = loan; this.loan = loan;
this.installmentNumber = installmentNumber; this.installmentNumber = installmentNumber;
this.fromDate = Date.from(fromDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.fromDate = fromDate;
this.dueDate = Date.from(dueDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.dueDate = dueDate;
this.principal = defaultToNullIfZero(principal); this.principal = defaultToNullIfZero(principal);
this.interestCharged = defaultToNullIfZero(interest); this.interestCharged = defaultToNullIfZero(interest);
this.feeChargesCharged = defaultToNullIfZero(feeCharges); this.feeChargesCharged = defaultToNullIfZero(feeCharges);
@@ -216,12 +208,7 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
} }
public LocalDate getFromDate() { public LocalDate getFromDate() {
LocalDate fromLocalDate = null; return this.fromDate;
if (this.fromDate != null) {
fromLocalDate = LocalDate.ofInstant(this.fromDate.toInstant(), DateUtils.getDateTimeZoneOfTenant());
}
return fromLocalDate;
} }
public void setPostDatedChecksToNull() { public void setPostDatedChecksToNull() {
@@ -233,7 +220,7 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
} }
public LocalDate getDueDate() { public LocalDate getDueDate() {
return LocalDate.ofInstant(this.dueDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); return this.dueDate;
} }
public Money getPrincipal(final MonetaryCurrency currency) { public Money getPrincipal(final MonetaryCurrency currency) {
@@ -613,7 +600,7 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
public void updateDerivedFields(final MonetaryCurrency currency, final LocalDate actualDisbursementDate) { public void updateDerivedFields(final MonetaryCurrency currency, final LocalDate actualDisbursementDate) {
if (!this.obligationsMet && getTotalOutstanding(currency).isZero()) { if (!this.obligationsMet && getTotalOutstanding(currency).isZero()) {
this.obligationsMet = true; this.obligationsMet = true;
this.obligationsMetOnDate = Date.from(actualDisbursementDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.obligationsMetOnDate = actualDisbursementDate;
} }
} }
@@ -641,7 +628,7 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
private void checkIfRepaymentPeriodObligationsAreMet(final LocalDate transactionDate, final MonetaryCurrency currency) { private void checkIfRepaymentPeriodObligationsAreMet(final LocalDate transactionDate, final MonetaryCurrency currency) {
this.obligationsMet = getTotalOutstanding(currency).isZero(); this.obligationsMet = getTotalOutstanding(currency).isZero();
if (this.obligationsMet) { if (this.obligationsMet) {
this.obligationsMetOnDate = Date.from(transactionDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.obligationsMetOnDate = transactionDate;
} else { } else {
this.obligationsMetOnDate = null; this.obligationsMetOnDate = null;
} }
@@ -649,13 +636,13 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
public void updateDueDate(final LocalDate newDueDate) { public void updateDueDate(final LocalDate newDueDate) {
if (newDueDate != null) { if (newDueDate != null) {
this.dueDate = Date.from(newDueDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.dueDate = newDueDate;
} }
} }
public void updateFromDate(final LocalDate newFromDate) { public void updateFromDate(final LocalDate newFromDate) {
if (newFromDate != null) { if (newFromDate != null) {
this.fromDate = Date.from(newFromDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.fromDate = newFromDate;
} }
} }
@@ -690,9 +677,7 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
} }
public void updateObligationMetOnDate(final LocalDate obligationsMetOnDate) { public void updateObligationMetOnDate(final LocalDate obligationsMetOnDate) {
this.obligationsMetOnDate = (obligationsMetOnDate != null) this.obligationsMetOnDate = obligationsMetOnDate;
? Date.from(obligationsMetOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant())
: null;
} }
public void updateInterestWrittenOff(final BigDecimal interestWrittenOff) { public void updateInterestWrittenOff(final BigDecimal interestWrittenOff) {
@@ -721,13 +706,7 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
} }
public LocalDate getObligationsMetOnDate() { public LocalDate getObligationsMetOnDate() {
LocalDate obligationsMetOnDate = null; return this.obligationsMetOnDate;
if (this.obligationsMetOnDate != null) {
obligationsMetOnDate = LocalDate.ofInstant(this.obligationsMetOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant());
}
return obligationsMetOnDate;
} }
/********** UNPAY COMPONENTS ****/ /********** UNPAY COMPONENTS ****/
@@ -106,7 +106,7 @@ public class LoanRepaymentScheduleProcessingWrapper {
if (loanCharge.getLoan() != null && loanCharge.isSpecifiedDueDate() if (loanCharge.getLoan() != null && loanCharge.isSpecifiedDueDate()
&& loanCharge.getLoan().isMultiDisburmentLoan()) { && loanCharge.getLoan().isMultiDisburmentLoan()) {
for (final LoanDisbursementDetails loanDisbursementDetails : loanCharge.getLoan().getDisbursementDetails()) { for (final LoanDisbursementDetails loanDisbursementDetails : loanCharge.getLoan().getDisbursementDetails()) {
if (!loanDisbursementDetails.expectedDisbursementDate().after(loanCharge.getDueDate())) { if (!loanDisbursementDetails.expectedDisbursementDate().isAfter(loanCharge.getDueDate())) {
amount = amount.add(loanDisbursementDetails.principal()); amount = amount.add(loanDisbursementDetails.principal());
} }
} }
@@ -18,8 +18,8 @@
*/ */
package org.apache.fineract.portfolio.loanaccount.domain; package org.apache.fineract.portfolio.loanaccount.domain;
import java.time.LocalDate;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.List; import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
@@ -74,11 +74,11 @@ public interface LoanRepository extends JpaRepository<Loan, Long>, JpaSpecificat
String FIND_BY_ACCOUNT_NUMBER = "select loan from Loan loan where loan.accountNumber = :accountNumber"; String FIND_BY_ACCOUNT_NUMBER = "select loan from Loan loan where loan.accountNumber = :accountNumber";
@Query(FIND_GROUP_LOANS_DISBURSED_AFTER) @Query(FIND_GROUP_LOANS_DISBURSED_AFTER)
List<Loan> getGroupLoansDisbursedAfter(@Param("disbursementDate") Date disbursementDate, @Param("groupId") Long groupId, List<Loan> getGroupLoansDisbursedAfter(@Param("disbursementDate") LocalDate disbursementDate, @Param("groupId") Long groupId,
@Param("loanType") Integer loanType); @Param("loanType") Integer loanType);
@Query(FIND_CLIENT_OR_JLG_LOANS_DISBURSED_AFTER) @Query(FIND_CLIENT_OR_JLG_LOANS_DISBURSED_AFTER)
List<Loan> getClientOrJLGLoansDisbursedAfter(@Param("disbursementDate") Date disbursementDate, @Param("clientId") Long clientId); List<Loan> getClientOrJLGLoansDisbursedAfter(@Param("disbursementDate") LocalDate disbursementDate, @Param("clientId") Long clientId);
@Query(FIND_MAX_GROUP_LOAN_COUNTER_QUERY) @Query(FIND_MAX_GROUP_LOAN_COUNTER_QUERY)
Integer getMaxGroupLoanCounter(@Param("groupId") Long groupId, @Param("loanType") Integer loanType); Integer getMaxGroupLoanCounter(@Param("groupId") Long groupId, @Param("loanType") Integer loanType);
@@ -129,7 +129,7 @@ public interface LoanRepository extends JpaRepository<Loan, Long>, JpaSpecificat
@Param("loanStatuses") Collection<Integer> loanStatuses, @Param("loanTypes") Collection<Integer> loanTypes); @Param("loanStatuses") Collection<Integer> loanStatuses, @Param("loanTypes") Collection<Integer> loanTypes);
@Query("select loan.id from Loan loan where loan.actualDisbursementDate > :disbursalDate order by loan.actualDisbursementDate") @Query("select loan.id from Loan loan where loan.actualDisbursementDate > :disbursalDate order by loan.actualDisbursementDate")
List<Long> getLoansDisbursedAfter(@Param("disbursalDate") Date disbursalDate); List<Long> getLoansDisbursedAfter(@Param("disbursalDate") LocalDate disbursalDate);
@Query("select loan from Loan loan where loan.client.office.id IN :officeIds and loan.loanStatus IN :loanStatuses") @Query("select loan from Loan loan where loan.client.office.id IN :officeIds and loan.loanStatus IN :loanStatuses")
List<Loan> findByClientOfficeIdsAndLoanStatus(@Param("officeIds") Collection<Long> officeIds, List<Loan> findByClientOfficeIdsAndLoanStatus(@Param("officeIds") Collection<Long> officeIds,
@@ -18,10 +18,10 @@
*/ */
package org.apache.fineract.portfolio.loanaccount.domain; package org.apache.fineract.portfolio.loanaccount.domain;
import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.fineract.portfolio.loanaccount.exception.LoanNotFoundException; import org.apache.fineract.portfolio.loanaccount.exception.LoanNotFoundException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -88,13 +88,13 @@ public class LoanRepositoryWrapper {
} }
// Only root entities is enough // Only root entities is enough
public List<Loan> getGroupLoansDisbursedAfter(@Param("disbursementDate") Date disbursementDate, @Param("groupId") Long groupId, public List<Loan> getGroupLoansDisbursedAfter(@Param("disbursementDate") LocalDate disbursementDate, @Param("groupId") Long groupId,
@Param("loanType") Integer loanType) { @Param("loanType") Integer loanType) {
return this.repository.getGroupLoansDisbursedAfter(disbursementDate, groupId, loanType); return this.repository.getGroupLoansDisbursedAfter(disbursementDate, groupId, loanType);
} }
// Only root entities enough // Only root entities enough
public List<Loan> getClientOrJLGLoansDisbursedAfter(@Param("disbursementDate") Date disbursementDate, public List<Loan> getClientOrJLGLoansDisbursedAfter(@Param("disbursementDate") LocalDate disbursementDate,
@Param("clientId") Long clientId) { @Param("clientId") Long clientId) {
return this.repository.getClientOrJLGLoansDisbursedAfter(disbursementDate, clientId); return this.repository.getClientOrJLGLoansDisbursedAfter(disbursementDate, clientId);
} }
@@ -192,7 +192,7 @@ public class LoanRepositoryWrapper {
} }
// This method is not used // This method is not used
public List<Long> getLoansDisbursedAfter(@Param("disbursalDate") Date disbursalDate) { public List<Long> getLoansDisbursedAfter(@Param("disbursalDate") LocalDate disbursalDate) {
return this.repository.getLoansDisbursedAfter(disbursalDate); return this.repository.getLoansDisbursedAfter(disbursalDate);
} }
@@ -20,7 +20,6 @@ package org.apache.fineract.portfolio.loanaccount.domain;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Date;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
@@ -28,11 +27,8 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.portfolio.loanaccount.data.LoanTermVariationsData; import org.apache.fineract.portfolio.loanaccount.data.LoanTermVariationsData;
import org.apache.fineract.portfolio.loanproduct.service.LoanEnumerations; import org.apache.fineract.portfolio.loanproduct.service.LoanEnumerations;
@@ -47,16 +43,14 @@ public class LoanTermVariations extends AbstractPersistableCustom {
@Column(name = "term_type", nullable = false) @Column(name = "term_type", nullable = false)
private Integer termType; private Integer termType;
@Temporal(TemporalType.DATE)
@Column(name = "applicable_date", nullable = false) @Column(name = "applicable_date", nullable = false)
private Date termApplicableFrom; private LocalDate termApplicableFrom;
@Column(name = "decimal_value", scale = 6, precision = 19) @Column(name = "decimal_value", scale = 6, precision = 19)
private BigDecimal decimalValue; private BigDecimal decimalValue;
@Temporal(TemporalType.DATE)
@Column(name = "date_value") @Column(name = "date_value")
private Date dateValue; private LocalDate dateValue;
@Column(name = "is_specific_to_installment", nullable = false) @Column(name = "is_specific_to_installment", nullable = false)
private boolean isSpecificToInstallment; private boolean isSpecificToInstallment;
@@ -71,8 +65,8 @@ public class LoanTermVariations extends AbstractPersistableCustom {
@JoinColumn(name = "parent_id") @JoinColumn(name = "parent_id")
private LoanTermVariations parent; private LoanTermVariations parent;
public LoanTermVariations(final Integer termType, final Date termApplicableFrom, final BigDecimal decimalValue, final Date dateValue, public LoanTermVariations(final Integer termType, final LocalDate termApplicableFrom, final BigDecimal decimalValue,
final boolean isSpecificToInstallment, final Loan loan) { final LocalDate dateValue, final boolean isSpecificToInstallment, final Loan loan) {
this.loan = loan; this.loan = loan;
this.termApplicableFrom = termApplicableFrom; this.termApplicableFrom = termApplicableFrom;
this.termType = termType; this.termType = termType;
@@ -84,8 +78,8 @@ public class LoanTermVariations extends AbstractPersistableCustom {
this.parent = null; this.parent = null;
} }
public LoanTermVariations(final Integer termType, final Date termApplicableFrom, final BigDecimal decimalValue, final Date dateValue, public LoanTermVariations(final Integer termType, final LocalDate termApplicableFrom, final BigDecimal decimalValue,
final boolean isSpecificToInstallment, final Loan loan, final Integer loanStatus) { final LocalDate dateValue, final boolean isSpecificToInstallment, final Loan loan, final Integer loanStatus) {
this.loan = loan; this.loan = loan;
this.termApplicableFrom = termApplicableFrom; this.termApplicableFrom = termApplicableFrom;
this.termType = termType; this.termType = termType;
@@ -97,9 +91,9 @@ public class LoanTermVariations extends AbstractPersistableCustom {
this.parent = null; this.parent = null;
} }
public LoanTermVariations(final Integer termType, final Date termApplicableFrom, final BigDecimal decimalValue, final Date dateValue, public LoanTermVariations(final Integer termType, final LocalDate termApplicableFrom, final BigDecimal decimalValue,
final boolean isSpecificToInstallment, final Loan loan, final Integer loanStatus, final Boolean isActive, final LocalDate dateValue, final boolean isSpecificToInstallment, final Loan loan, final Integer loanStatus,
final LoanTermVariations parent) { final Boolean isActive, final LoanTermVariations parent) {
this.loan = loan; this.loan = loan;
this.termApplicableFrom = termApplicableFrom; this.termApplicableFrom = termApplicableFrom;
this.termType = termType; this.termType = termType;
@@ -120,36 +114,32 @@ public class LoanTermVariations extends AbstractPersistableCustom {
} }
public LoanTermVariationsData toData() { public LoanTermVariationsData toData() {
LocalDate termStartDate = LocalDate.ofInstant(this.termApplicableFrom.toInstant(), DateUtils.getDateTimeZoneOfTenant());
LocalDate dateValue = null;
if (this.dateValue != null) {
dateValue = LocalDate.ofInstant(this.dateValue.toInstant(), DateUtils.getDateTimeZoneOfTenant());
}
EnumOptionData type = LoanEnumerations.loanvariationType(this.termType); EnumOptionData type = LoanEnumerations.loanvariationType(this.termType);
return new LoanTermVariationsData(getId(), type, termStartDate, this.decimalValue, dateValue, this.isSpecificToInstallment); return new LoanTermVariationsData(getId(), type, this.termApplicableFrom, this.decimalValue, this.dateValue,
this.isSpecificToInstallment);
} }
public Date getTermApplicableFrom() { public LocalDate getTermApplicableFrom() {
return this.termApplicableFrom; return this.termApplicableFrom;
} }
public LocalDate fetchTermApplicaDate() { public LocalDate fetchTermApplicaDate() {
return LocalDate.ofInstant(this.termApplicableFrom.toInstant(), DateUtils.getDateTimeZoneOfTenant()); return this.termApplicableFrom;
} }
public BigDecimal getTermValue() { public BigDecimal getTermValue() {
return this.decimalValue; return this.decimalValue;
} }
public Date getDateValue() { public LocalDate getDateValue() {
return this.dateValue; return this.dateValue;
} }
public LocalDate fetchDateValue() { public LocalDate fetchDateValue() {
return this.dateValue == null ? null : LocalDate.ofInstant(this.dateValue.toInstant(), DateUtils.getDateTimeZoneOfTenant()); return this.dateValue;
} }
public void setTermApplicableFrom(Date termApplicableFrom) { public void setTermApplicableFrom(LocalDate termApplicableFrom) {
this.termApplicableFrom = termApplicableFrom; this.termApplicableFrom = termApplicableFrom;
} }
@@ -20,9 +20,7 @@ package org.apache.fineract.portfolio.loanaccount.guarantor.command;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.fineract.infrastructure.core.data.ApiParameterError; import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
@@ -90,8 +88,8 @@ public class GuarantorCommand {
return GuarantorType.EXTERNAL.getValue().equals(this.guarantorTypeId); return GuarantorType.EXTERNAL.getValue().equals(this.guarantorTypeId);
} }
public Date getDobAsDate() { public LocalDate getDobAsDate() {
return Date.from(this.dob.atStartOfDay(ZoneId.systemDefault()).toInstant()); return this.dob;
} }
public void validateForCreate() { public void validateForCreate() {
@@ -18,8 +18,8 @@
*/ */
package org.apache.fineract.portfolio.loanaccount.guarantor.domain; package org.apache.fineract.portfolio.loanaccount.guarantor.domain;
import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -31,8 +31,6 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.codes.domain.CodeValue; import org.apache.fineract.infrastructure.codes.domain.CodeValue;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
@@ -65,8 +63,7 @@ public class Guarantor extends AbstractPersistableCustom {
private String lastname; private String lastname;
@Column(name = "dob") @Column(name = "dob")
@Temporal(TemporalType.DATE) private LocalDate dateOfBirth;
private Date dateOfBirth;
@Column(name = "address_line_1", length = 500) @Column(name = "address_line_1", length = 500)
private String addressLine1; private String addressLine1;
@@ -106,9 +103,9 @@ public class Guarantor extends AbstractPersistableCustom {
} }
private Guarantor(final Loan loan, final CodeValue clientRelationshipType, final Integer gurantorType, final Long entityId, private Guarantor(final Loan loan, final CodeValue clientRelationshipType, final Integer gurantorType, final Long entityId,
final String firstname, final String lastname, final Date dateOfBirth, final String addressLine1, final String addressLine2, final String firstname, final String lastname, final LocalDate dateOfBirth, final String addressLine1,
final String city, final String state, final String country, final String zip, final String housePhoneNumber, final String addressLine2, final String city, final String state, final String country, final String zip,
final String mobilePhoneNumber, final String comment, final boolean active, final String housePhoneNumber, final String mobilePhoneNumber, final String comment, final boolean active,
final List<GuarantorFundingDetails> guarantorFundDetails) { final List<GuarantorFundingDetails> guarantorFundDetails) {
this.loan = loan; this.loan = loan;
this.clientRelationshipType = clientRelationshipType; this.clientRelationshipType = clientRelationshipType;
@@ -138,7 +135,7 @@ public class Guarantor extends AbstractPersistableCustom {
if (GuarantorType.EXTERNAL.getValue().equals(gurantorType)) { if (GuarantorType.EXTERNAL.getValue().equals(gurantorType)) {
final String firstname = command.stringValueOfParameterNamed(GuarantorJSONinputParams.FIRSTNAME.getValue()); final String firstname = command.stringValueOfParameterNamed(GuarantorJSONinputParams.FIRSTNAME.getValue());
final String lastname = command.stringValueOfParameterNamed(GuarantorJSONinputParams.LASTNAME.getValue()); final String lastname = command.stringValueOfParameterNamed(GuarantorJSONinputParams.LASTNAME.getValue());
final Date dateOfBirth = command.dateValueOfParameterNamed(GuarantorJSONinputParams.DATE_OF_BIRTH.getValue()); final LocalDate dateOfBirth = command.localDateValueOfParameterNamed(GuarantorJSONinputParams.DATE_OF_BIRTH.getValue());
final String addressLine1 = command.stringValueOfParameterNamed(GuarantorJSONinputParams.ADDRESS_LINE_1.getValue()); final String addressLine1 = command.stringValueOfParameterNamed(GuarantorJSONinputParams.ADDRESS_LINE_1.getValue());
final String addressLine2 = command.stringValueOfParameterNamed(GuarantorJSONinputParams.ADDRESS_LINE_2.getValue()); final String addressLine2 = command.stringValueOfParameterNamed(GuarantorJSONinputParams.ADDRESS_LINE_2.getValue());
final String city = command.stringValueOfParameterNamed(GuarantorJSONinputParams.CITY.getValue()); final String city = command.stringValueOfParameterNamed(GuarantorJSONinputParams.CITY.getValue());
@@ -249,9 +246,9 @@ public class Guarantor extends AbstractPersistableCustom {
} }
private void handlePropertyUpdate(final JsonCommand command, final Map<String, Object> actualChanges, final String paramName, private void handlePropertyUpdate(final JsonCommand command, final Map<String, Object> actualChanges, final String paramName,
Date propertyToBeUpdated) { LocalDate propertyToBeUpdated) {
if (command.isChangeInDateParameterNamed(paramName, propertyToBeUpdated)) { if (command.isChangeInDateParameterNamed(paramName, propertyToBeUpdated)) {
final Date newValue = command.dateValueOfParameterNamed(paramName); final LocalDate newValue = command.localDateValueOfParameterNamed(paramName);
actualChanges.put(paramName, newValue); actualChanges.put(paramName, newValue);
// propertyToBeUpdated = newValue; // propertyToBeUpdated = newValue;
@@ -21,9 +21,7 @@ package org.apache.fineract.portfolio.loanaccount.loanschedule.domain;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.MathContext; import java.math.MathContext;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -1388,20 +1386,12 @@ public final class LoanApplicationTerms {
return this.repaymentPeriodFrequencyType; return this.repaymentPeriodFrequencyType;
} }
public Date getRepaymentStartFromDate() { public LocalDate getRepaymentStartFromDate() {
Date dateValue = null; return this.repaymentsStartingFromDate;
if (this.repaymentsStartingFromDate != null) {
dateValue = Date.from(this.repaymentsStartingFromDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
return dateValue;
} }
public Date getInterestChargedFromDate() { public LocalDate getInterestChargedFromDate() {
Date dateValue = null; return this.interestChargedFromDate;
if (this.interestChargedFromDate != null) {
dateValue = Date.from(this.interestChargedFromDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
return dateValue;
} }
public void setPrincipal(Money principal) { public void setPrincipal(Money principal) {
@@ -19,15 +19,13 @@
package org.apache.fineract.portfolio.loanaccount.loanschedule.domain; package org.apache.fineract.portfolio.loanaccount.loanschedule.domain;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.time.LocalDate;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.portfolio.loanaccount.domain.Loan; import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.rescheduleloan.domain.LoanRescheduleRequest; import org.apache.fineract.portfolio.loanaccount.rescheduleloan.domain.LoanRescheduleRequest;
@@ -47,13 +45,11 @@ public class LoanRepaymentScheduleHistory extends AbstractPersistableCustom {
@Column(name = "installment", nullable = false) @Column(name = "installment", nullable = false)
private Integer installmentNumber; private Integer installmentNumber;
@Temporal(TemporalType.DATE)
@Column(name = "fromdate", nullable = true) @Column(name = "fromdate", nullable = true)
private Date fromDate; private LocalDate fromDate;
@Temporal(TemporalType.DATE)
@Column(name = "duedate", nullable = false) @Column(name = "duedate", nullable = false)
private Date dueDate; private LocalDate dueDate;
@Column(name = "principal_amount", scale = 6, precision = 19, nullable = true) @Column(name = "principal_amount", scale = 6, precision = 19, nullable = true)
private BigDecimal principal; private BigDecimal principal;
@@ -67,9 +63,8 @@ public class LoanRepaymentScheduleHistory extends AbstractPersistableCustom {
@Column(name = "penalty_charges_amount", scale = 6, precision = 19, nullable = true) @Column(name = "penalty_charges_amount", scale = 6, precision = 19, nullable = true)
private BigDecimal penaltyCharges; private BigDecimal penaltyCharges;
@Temporal(TemporalType.DATE)
@Column(name = "created_date") @Column(name = "created_date")
private Date createdOnDate; private LocalDate createdOnDate;
@Column(name = "createdby_id") @Column(name = "createdby_id")
private Long createdByUser; private Long createdByUser;
@@ -77,9 +72,8 @@ public class LoanRepaymentScheduleHistory extends AbstractPersistableCustom {
@Column(name = "lastmodifiedby_id") @Column(name = "lastmodifiedby_id")
private Long lastModifiedByUser; private Long lastModifiedByUser;
@Temporal(TemporalType.DATE)
@Column(name = "lastmodified_date") @Column(name = "lastmodified_date")
private Date lastModifiedOnDate; private LocalDate lastModifiedOnDate;
@Column(name = "version") @Column(name = "version")
private Integer version; private Integer version;
@@ -93,9 +87,10 @@ public class LoanRepaymentScheduleHistory extends AbstractPersistableCustom {
* LoanRepaymentScheduleHistory constructor * LoanRepaymentScheduleHistory constructor
**/ **/
private LoanRepaymentScheduleHistory(final Loan loan, final LoanRescheduleRequest loanRescheduleRequest, private LoanRepaymentScheduleHistory(final Loan loan, final LoanRescheduleRequest loanRescheduleRequest,
final Integer installmentNumber, final Date fromDate, final Date dueDate, final BigDecimal principal, final Integer installmentNumber, final LocalDate fromDate, final LocalDate dueDate, final BigDecimal principal,
final BigDecimal interestCharged, final BigDecimal feeChargesCharged, final BigDecimal penaltyCharges, final Date createdOnDate, final BigDecimal interestCharged, final BigDecimal feeChargesCharged, final BigDecimal penaltyCharges,
final Long createdByUser, final Long lastModifiedByUser, final Date lastModifiedOnDate, final Integer version) { final LocalDate createdOnDate, final Long createdByUser, final Long lastModifiedByUser, final LocalDate lastModifiedOnDate,
final Integer version) {
this.loan = loan; this.loan = loan;
this.loanRescheduleRequest = loanRescheduleRequest; this.loanRescheduleRequest = loanRescheduleRequest;
@@ -117,9 +112,10 @@ public class LoanRepaymentScheduleHistory extends AbstractPersistableCustom {
* @return an instance of the LoanRepaymentScheduleHistory class * @return an instance of the LoanRepaymentScheduleHistory class
**/ **/
public static LoanRepaymentScheduleHistory instance(final Loan loan, final LoanRescheduleRequest loanRescheduleRequest, public static LoanRepaymentScheduleHistory instance(final Loan loan, final LoanRescheduleRequest loanRescheduleRequest,
final Integer installmentNumber, final Date fromDate, final Date dueDate, final BigDecimal principal, final Integer installmentNumber, final LocalDate fromDate, final LocalDate dueDate, final BigDecimal principal,
final BigDecimal interestCharged, final BigDecimal feeChargesCharged, final BigDecimal penaltyCharges, final Date createdOnDate, final BigDecimal interestCharged, final BigDecimal feeChargesCharged, final BigDecimal penaltyCharges,
final Long createdByUser, final Long lastModifiedByUser, final Date lastModifiedOnDate, final Integer version) { final LocalDate createdOnDate, final Long createdByUser, final Long lastModifiedByUser, final LocalDate lastModifiedOnDate,
final Integer version) {
return new LoanRepaymentScheduleHistory(loan, loanRescheduleRequest, installmentNumber, fromDate, dueDate, principal, return new LoanRepaymentScheduleHistory(loan, loanRescheduleRequest, installmentNumber, fromDate, dueDate, principal,
interestCharged, feeChargesCharged, penaltyCharges, createdOnDate, createdByUser, lastModifiedByUser, lastModifiedOnDate, interestCharged, feeChargesCharged, penaltyCharges, createdOnDate, createdByUser, lastModifiedByUser, lastModifiedOnDate,
@@ -25,12 +25,10 @@ import java.math.BigDecimal;
import java.math.MathContext; import java.math.MathContext;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoField; import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@@ -443,8 +441,8 @@ public class LoanScheduleAssembler {
officeId = group.getOffice().getId(); officeId = group.getOffice().getId();
} }
final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled(); final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled();
final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(officeId, final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(officeId, expectedDisbursementDate,
Date.from(expectedDisbursementDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), HolidayStatusType.ACTIVE.getValue()); HolidayStatusType.ACTIVE.getValue());
final WorkingDays workingDays = this.workingDaysRepository.findOne(); final WorkingDays workingDays = this.workingDaysRepository.findOne();
HolidayDetailDTO detailDTO = new HolidayDetailDTO(isHolidayEnabled, holidays, workingDays); HolidayDetailDTO detailDTO = new HolidayDetailDTO(isHolidayEnabled, holidays, workingDays);
final boolean isInterestToBeRecoveredFirstWhenGreaterThanEMI = this.configurationDomainService final boolean isInterestToBeRecoveredFirstWhenGreaterThanEMI = this.configurationDomainService
@@ -622,8 +620,8 @@ public class LoanScheduleAssembler {
} }
final LocalDate expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed("expectedDisbursementDate", element); final LocalDate expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed("expectedDisbursementDate", element);
final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(officeId, final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(officeId, expectedDisbursementDate,
Date.from(expectedDisbursementDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), HolidayStatusType.ACTIVE.getValue()); HolidayStatusType.ACTIVE.getValue());
final WorkingDays workingDays = this.workingDaysRepository.findOne(); final WorkingDays workingDays = this.workingDaysRepository.findOne();
validateDisbursementDateIsOnNonWorkingDay(loanApplicationTerms.getExpectedDisbursementDate(), workingDays); validateDisbursementDateIsOnNonWorkingDay(loanApplicationTerms.getExpectedDisbursementDate(), workingDays);
@@ -671,8 +669,7 @@ public class LoanScheduleAssembler {
final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled(); final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled();
final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(officeId, final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(officeId,
Date.from(loanApplicationTerms.getExpectedDisbursementDate().atStartOfDay(ZoneId.systemDefault()).toInstant()), loanApplicationTerms.getExpectedDisbursementDate(), HolidayStatusType.ACTIVE.getValue());
HolidayStatusType.ACTIVE.getValue());
final WorkingDays workingDays = this.workingDaysRepository.findOne(); final WorkingDays workingDays = this.workingDaysRepository.findOne();
final LoanScheduleGenerator loanScheduleGenerator = this.loanScheduleFactory.create(loanApplicationTerms.getInterestMethod()); final LoanScheduleGenerator loanScheduleGenerator = this.loanScheduleFactory.create(loanApplicationTerms.getInterestMethod());
@@ -690,8 +687,7 @@ public class LoanScheduleAssembler {
final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled(); final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled();
final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(officeId, final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(officeId,
Date.from(loanApplicationTerms.getExpectedDisbursementDate().atStartOfDay(ZoneId.systemDefault()).toInstant()), loanApplicationTerms.getExpectedDisbursementDate(), HolidayStatusType.ACTIVE.getValue());
HolidayStatusType.ACTIVE.getValue());
final WorkingDays workingDays = this.workingDaysRepository.findOne(); final WorkingDays workingDays = this.workingDaysRepository.findOne();
HolidayDetailDTO holidayDetailDTO = new HolidayDetailDTO(isHolidayEnabled, holidays, workingDays); HolidayDetailDTO holidayDetailDTO = new HolidayDetailDTO(isHolidayEnabled, holidays, workingDays);
@@ -872,8 +868,7 @@ public class LoanScheduleAssembler {
throw new PlatformApiDataValidationException(dataValidationErrors); throw new PlatformApiDataValidationException(dataValidationErrors);
} }
if (loan.getExpectedFirstRepaymentOnDate() == null) { if (loan.getExpectedFirstRepaymentOnDate() == null) {
loan.setExpectedFirstRepaymentOnDate( loan.setExpectedFirstRepaymentOnDate(loan.fetchRepaymentScheduleInstallment(1).getDueDate());
Date.from(loan.fetchRepaymentScheduleInstallment(1).getDueDate().atStartOfDay(ZoneId.systemDefault()).toInstant()));
} }
final LocalDate recalculateFrom = null; final LocalDate recalculateFrom = null;
ScheduleGeneratorDTO scheduleGeneratorDTO = this.loanUtilService.buildScheduleGeneratorDTO(loan, recalculateFrom); ScheduleGeneratorDTO scheduleGeneratorDTO = this.loanUtilService.buildScheduleGeneratorDTO(loan, recalculateFrom);
@@ -1007,15 +1002,14 @@ public class LoanScheduleAssembler {
decimalValueVariationType = LoanTermVariationType.PRINCIPAL_AMOUNT; decimalValueVariationType = LoanTermVariationType.PRINCIPAL_AMOUNT;
} }
LocalDate duedateLocalDate = this.fromApiJsonHelper.extractLocalDateNamed(LoanApiConstants.dueDateParamName, arrayElement, LocalDate dueDate = this.fromApiJsonHelper.extractLocalDateNamed(LoanApiConstants.dueDateParamName, arrayElement, dateFormat,
dateFormat, locale); locale);
Date dueDate = Date.from(duedateLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
LocalDate modifiedDuedateLocalDate = this.fromApiJsonHelper.extractLocalDateNamed(LoanApiConstants.modifiedDueDateParamName, LocalDate modifiedDuedateLocalDate = this.fromApiJsonHelper.extractLocalDateNamed(LoanApiConstants.modifiedDueDateParamName,
arrayElement, dateFormat, locale); arrayElement, dateFormat, locale);
Date modifiedDuedate = null; LocalDate modifiedDuedate = null;
if (modifiedDuedateLocalDate != null) { if (modifiedDuedateLocalDate != null) {
modifiedDuedate = Date.from(modifiedDuedateLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); modifiedDuedate = modifiedDuedateLocalDate;
} }
boolean isSpecificToInstallment = true; boolean isSpecificToInstallment = true;
if (isInsertInstallment) { if (isInsertInstallment) {
@@ -1037,7 +1031,7 @@ public class LoanScheduleAssembler {
if (modifiedDuedate == null) { if (modifiedDuedate == null) {
modifiedDuedate = dueDate; modifiedDuedate = dueDate;
} }
Date date = null; LocalDate date = null;
LoanTermVariations data = new LoanTermVariations(decimalValueVariationType.getValue(), modifiedDuedate, decimalValue, LoanTermVariations data = new LoanTermVariations(decimalValueVariationType.getValue(), modifiedDuedate, decimalValue,
date, isSpecificToInstallment, loan); date, isSpecificToInstallment, loan);
loanTermVariations.add(data); loanTermVariations.add(data);
@@ -19,10 +19,10 @@
package org.apache.fineract.portfolio.loanaccount.loanschedule.service; package org.apache.fineract.portfolio.loanaccount.loanschedule.service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.ZoneId; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
import org.apache.fineract.portfolio.loanaccount.domain.Loan; import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment; import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
@@ -57,15 +57,15 @@ public class LoanScheduleHistoryWritePlatformServiceImpl implements LoanSchedule
for (LoanRepaymentScheduleInstallment repaymentScheduleInstallment : repaymentScheduleInstallments) { for (LoanRepaymentScheduleInstallment repaymentScheduleInstallment : repaymentScheduleInstallments) {
final Integer installmentNumber = repaymentScheduleInstallment.getInstallmentNumber(); final Integer installmentNumber = repaymentScheduleInstallment.getInstallmentNumber();
Date fromDate = null; LocalDate fromDate = null;
Date dueDate = null; LocalDate dueDate = null;
if (repaymentScheduleInstallment.getFromDate() != null) { if (repaymentScheduleInstallment.getFromDate() != null) {
fromDate = Date.from(repaymentScheduleInstallment.getFromDate().atStartOfDay(ZoneId.systemDefault()).toInstant()); fromDate = repaymentScheduleInstallment.getFromDate();
} }
if (repaymentScheduleInstallment.getDueDate() != null) { if (repaymentScheduleInstallment.getDueDate() != null) {
dueDate = Date.from(repaymentScheduleInstallment.getDueDate().atStartOfDay(ZoneId.systemDefault()).toInstant()); dueDate = repaymentScheduleInstallment.getDueDate();
} }
final BigDecimal principal = repaymentScheduleInstallment.getPrincipal(currency).getAmount(); final BigDecimal principal = repaymentScheduleInstallment.getPrincipal(currency).getAmount();
@@ -73,18 +73,20 @@ public class LoanScheduleHistoryWritePlatformServiceImpl implements LoanSchedule
final BigDecimal feeChargesCharged = repaymentScheduleInstallment.getFeeChargesCharged(currency).getAmount(); final BigDecimal feeChargesCharged = repaymentScheduleInstallment.getFeeChargesCharged(currency).getAmount();
final BigDecimal penaltyCharges = repaymentScheduleInstallment.getPenaltyChargesCharged(currency).getAmount(); final BigDecimal penaltyCharges = repaymentScheduleInstallment.getPenaltyChargesCharged(currency).getAmount();
Date createdOnDate = null; LocalDate createdOnDate = null;
if (repaymentScheduleInstallment.getCreatedDate().isPresent()) { if (repaymentScheduleInstallment.getCreatedDate().isPresent()) {
createdOnDate = Date.from(repaymentScheduleInstallment.getCreatedDate().get()); // NOSONAR createdOnDate = LocalDate.ofInstant(repaymentScheduleInstallment.getCreatedDate().get(),
DateUtils.getDateTimeZoneOfTenant()); // NOSONAR
} }
final Long createdByUser = repaymentScheduleInstallment.getCreatedBy().orElse(null); final Long createdByUser = repaymentScheduleInstallment.getCreatedBy().orElse(null);
final Long lastModifiedByUser = repaymentScheduleInstallment.getLastModifiedBy().orElse(null); final Long lastModifiedByUser = repaymentScheduleInstallment.getLastModifiedBy().orElse(null);
Date lastModifiedOnDate = null; LocalDate lastModifiedOnDate = null;
if (repaymentScheduleInstallment.getLastModifiedDate().isPresent()) { if (repaymentScheduleInstallment.getLastModifiedDate().isPresent()) {
lastModifiedOnDate = Date.from(repaymentScheduleInstallment.getLastModifiedDate().get()); // NOSONAR lastModifiedOnDate = LocalDate.ofInstant(repaymentScheduleInstallment.getLastModifiedDate().get(),
DateUtils.getDateTimeZoneOfTenant()); // NOSONAR
} }
LoanRepaymentScheduleHistory loanRepaymentScheduleHistory = LoanRepaymentScheduleHistory.instance(loan, loanRescheduleRequest, LoanRepaymentScheduleHistory loanRepaymentScheduleHistory = LoanRepaymentScheduleHistory.instance(loan, loanRescheduleRequest,
@@ -19,8 +19,6 @@
package org.apache.fineract.portfolio.loanaccount.rescheduleloan.domain; package org.apache.fineract.portfolio.loanaccount.rescheduleloan.domain;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -32,11 +30,8 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.fineract.infrastructure.codes.domain.CodeValue; import org.apache.fineract.infrastructure.codes.domain.CodeValue;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.portfolio.loanaccount.domain.Loan; import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRescheduleRequestToTermVariationMapping; import org.apache.fineract.portfolio.loanaccount.domain.LoanRescheduleRequestToTermVariationMapping;
import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus; import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
@@ -57,9 +52,8 @@ public class LoanRescheduleRequest extends AbstractPersistableCustom {
@Column(name = "reschedule_from_installment") @Column(name = "reschedule_from_installment")
private Integer rescheduleFromInstallment; private Integer rescheduleFromInstallment;
@Temporal(TemporalType.DATE)
@Column(name = "reschedule_from_date") @Column(name = "reschedule_from_date")
private Date rescheduleFromDate; private LocalDate rescheduleFromDate;
@Column(name = "recalculate_interest") @Column(name = "recalculate_interest")
private Boolean recalculateInterest; private Boolean recalculateInterest;
@@ -71,25 +65,22 @@ public class LoanRescheduleRequest extends AbstractPersistableCustom {
@Column(name = "reschedule_reason_comment") @Column(name = "reschedule_reason_comment")
private String rescheduleReasonComment; private String rescheduleReasonComment;
@Temporal(TemporalType.DATE)
@Column(name = "submitted_on_date") @Column(name = "submitted_on_date")
private Date submittedOnDate; private LocalDate submittedOnDate;
@ManyToOne @ManyToOne
@JoinColumn(name = "submitted_by_user_id") @JoinColumn(name = "submitted_by_user_id")
private AppUser submittedByUser; private AppUser submittedByUser;
@Temporal(TemporalType.DATE)
@Column(name = "approved_on_date") @Column(name = "approved_on_date")
private Date approvedOnDate; private LocalDate approvedOnDate;
@ManyToOne @ManyToOne
@JoinColumn(name = "approved_by_user_id") @JoinColumn(name = "approved_by_user_id")
private AppUser approvedByUser; private AppUser approvedByUser;
@Temporal(TemporalType.DATE)
@Column(name = "rejected_on_date") @Column(name = "rejected_on_date")
private Date rejectedOnDate; private LocalDate rejectedOnDate;
@ManyToOne @ManyToOne
@JoinColumn(name = "rejected_by_user_id") @JoinColumn(name = "rejected_by_user_id")
@@ -107,9 +98,9 @@ public class LoanRescheduleRequest extends AbstractPersistableCustom {
* LoanRescheduleRequest constructor * LoanRescheduleRequest constructor
**/ **/
private LoanRescheduleRequest(final Loan loan, final Integer statusEnum, final Integer rescheduleFromInstallment, private LoanRescheduleRequest(final Loan loan, final Integer statusEnum, final Integer rescheduleFromInstallment,
final Date rescheduleFromDate, final Boolean recalculateInterest, final CodeValue rescheduleReasonCodeValue, final LocalDate rescheduleFromDate, final Boolean recalculateInterest, final CodeValue rescheduleReasonCodeValue,
final String rescheduleReasonComment, final Date submittedOnDate, final AppUser submittedByUser, final Date approvedOnDate, final String rescheduleReasonComment, final LocalDate submittedOnDate, final AppUser submittedByUser,
final AppUser approvedByUser, final Date rejectedOnDate, AppUser rejectedByUser) { final LocalDate approvedOnDate, final AppUser approvedByUser, final LocalDate rejectedOnDate, AppUser rejectedByUser) {
this.loan = loan; this.loan = loan;
this.statusEnum = statusEnum; this.statusEnum = statusEnum;
this.rescheduleFromInstallment = rescheduleFromInstallment; this.rescheduleFromInstallment = rescheduleFromInstallment;
@@ -129,9 +120,9 @@ public class LoanRescheduleRequest extends AbstractPersistableCustom {
* @return a new instance of the LoanRescheduleRequest class * @return a new instance of the LoanRescheduleRequest class
**/ **/
public static LoanRescheduleRequest instance(final Loan loan, final Integer statusEnum, final Integer rescheduleFromInstallment, public static LoanRescheduleRequest instance(final Loan loan, final Integer statusEnum, final Integer rescheduleFromInstallment,
final Date rescheduleFromDate, final Boolean recalculateInterest, final CodeValue rescheduleReasonCodeValue, final LocalDate rescheduleFromDate, final Boolean recalculateInterest, final CodeValue rescheduleReasonCodeValue,
final String rescheduleReasonComment, final Date submittedOnDate, final AppUser submittedByUser, final Date approvedOnDate, final String rescheduleReasonComment, final LocalDate submittedOnDate, final AppUser submittedByUser,
final AppUser approvedByUser, final Date rejectedOnDate, AppUser rejectedByUser) { final LocalDate approvedOnDate, final AppUser approvedByUser, final LocalDate rejectedOnDate, AppUser rejectedByUser) {
return new LoanRescheduleRequest(loan, statusEnum, rescheduleFromInstallment, rescheduleFromDate, recalculateInterest, return new LoanRescheduleRequest(loan, statusEnum, rescheduleFromInstallment, rescheduleFromDate, recalculateInterest,
rescheduleReasonCodeValue, rescheduleReasonComment, submittedOnDate, submittedByUser, approvedOnDate, approvedByUser, rescheduleReasonCodeValue, rescheduleReasonComment, submittedOnDate, submittedByUser, approvedOnDate, approvedByUser,
@@ -163,14 +154,7 @@ public class LoanRescheduleRequest extends AbstractPersistableCustom {
* @return due date of the rescheduling start point * @return due date of the rescheduling start point
**/ **/
public LocalDate getRescheduleFromDate() { public LocalDate getRescheduleFromDate() {
return this.rescheduleFromDate;
LocalDate localDate = null;
if (this.rescheduleFromDate != null) {
localDate = LocalDate.ofInstant(this.rescheduleFromDate.toInstant(), DateUtils.getDateTimeZoneOfTenant());
}
return localDate;
} }
/** /**
@@ -191,13 +175,7 @@ public class LoanRescheduleRequest extends AbstractPersistableCustom {
* @return the date the request was submitted * @return the date the request was submitted
**/ **/
public LocalDate getSubmittedOnDate() { public LocalDate getSubmittedOnDate() {
LocalDate localDate = null; return this.submittedOnDate;
if (this.submittedOnDate != null) {
localDate = LocalDate.ofInstant(this.submittedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant());
}
return localDate;
} }
/** /**
@@ -211,13 +189,7 @@ public class LoanRescheduleRequest extends AbstractPersistableCustom {
* @return the date the request was approved * @return the date the request was approved
**/ **/
public LocalDate getApprovedOnDate() { public LocalDate getApprovedOnDate() {
LocalDate localDate = null; return this.approvedOnDate;
if (this.approvedOnDate != null) {
localDate = LocalDate.ofInstant(this.approvedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant());
}
return localDate;
} }
/** /**
@@ -231,13 +203,7 @@ public class LoanRescheduleRequest extends AbstractPersistableCustom {
* @return the date the request was rejected * @return the date the request was rejected
**/ **/
public LocalDate getRejectedOnDate() { public LocalDate getRejectedOnDate() {
LocalDate localDate = null; return this.rejectedOnDate;
if (this.rejectedOnDate != null) {
localDate = LocalDate.ofInstant(this.rejectedOnDate.toInstant(), DateUtils.getDateTimeZoneOfTenant());
}
return localDate;
} }
/** /**
@@ -274,7 +240,7 @@ public class LoanRescheduleRequest extends AbstractPersistableCustom {
if (approvedOnDate != null) { if (approvedOnDate != null) {
this.approvedByUser = approvedByUser; this.approvedByUser = approvedByUser;
this.approvedOnDate = Date.from(approvedOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.approvedOnDate = approvedOnDate;
this.statusEnum = LoanStatus.APPROVED.getValue(); this.statusEnum = LoanStatus.APPROVED.getValue();
} }
} }
@@ -293,7 +259,7 @@ public class LoanRescheduleRequest extends AbstractPersistableCustom {
if (approvedOnDate != null) { if (approvedOnDate != null) {
this.rejectedByUser = approvedByUser; this.rejectedByUser = approvedByUser;
this.rejectedOnDate = Date.from(approvedOnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); this.rejectedOnDate = approvedOnDate;
this.statusEnum = LoanStatus.REJECTED.getValue(); this.statusEnum = LoanStatus.REJECTED.getValue();
} }
} }
@@ -21,9 +21,7 @@ package org.apache.fineract.portfolio.loanaccount.rescheduleloan.service;
import java.math.MathContext; import java.math.MathContext;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.fineract.organisation.monetary.domain.MoneyHelper; import org.apache.fineract.organisation.monetary.domain.MoneyHelper;
@@ -109,8 +107,7 @@ public class LoanReschedulePreviewPlatformServiceImpl implements LoanRescheduleP
if (loanRescheduleRequestToTermVariationMapping.getLoanTermVariations().getTermType().isDueDateVariation() if (loanRescheduleRequestToTermVariationMapping.getLoanTermVariations().getTermType().isDueDateVariation()
&& rescheduleFromDate != null) { && rescheduleFromDate != null) {
adjustedApplicableDate = loanRescheduleRequestToTermVariationMapping.getLoanTermVariations().fetchDateValue(); adjustedApplicableDate = loanRescheduleRequestToTermVariationMapping.getLoanTermVariations().fetchDateValue();
loanRescheduleRequestToTermVariationMapping.getLoanTermVariations() loanRescheduleRequestToTermVariationMapping.getLoanTermVariations().setTermApplicableFrom(rescheduleFromDate);
.setTermApplicableFrom(Date.from(rescheduleFromDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
} }
loanTermVariationsData.add(loanRescheduleRequestToTermVariationMapping.getLoanTermVariations().toData()); loanTermVariationsData.add(loanRescheduleRequestToTermVariationMapping.getLoanTermVariations().toData());
} }
@@ -22,11 +22,9 @@ import java.math.BigDecimal;
import java.math.MathContext; import java.math.MathContext;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@@ -213,32 +211,27 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
final Boolean recalculateInterest = jsonCommand final Boolean recalculateInterest = jsonCommand
.booleanObjectValueOfParameterNamed(RescheduleLoansApiConstants.recalculateInterestParamName); .booleanObjectValueOfParameterNamed(RescheduleLoansApiConstants.recalculateInterestParamName);
final Date endDate = jsonCommand.dateValueOfParameterNamed(RescheduleLoansApiConstants.endDateParamName); final LocalDate endDate = jsonCommand.localDateValueOfParameterNamed(RescheduleLoansApiConstants.endDateParamName);
final BigDecimal emi = jsonCommand.bigDecimalValueOfParameterNamed(RescheduleLoansApiConstants.emiParamName); final BigDecimal emi = jsonCommand.bigDecimalValueOfParameterNamed(RescheduleLoansApiConstants.emiParamName);
// initialize set the value to null // initialize set the value to null
Date submittedOnDate = null; LocalDate submittedOnDate = null;
// check if the parameter is in the JsonCommand object // check if the parameter is in the JsonCommand object
if (jsonCommand.hasParameter(RescheduleLoansApiConstants.submittedOnDateParamName)) { if (jsonCommand.hasParameter(RescheduleLoansApiConstants.submittedOnDateParamName)) {
// create a LocalDate object from the "submittedOnDate" Date // create a LocalDate object from the "submittedOnDate" Date
// string // string
LocalDate localDate = jsonCommand.localDateValueOfParameterNamed(RescheduleLoansApiConstants.submittedOnDateParamName); submittedOnDate = jsonCommand.localDateValueOfParameterNamed(RescheduleLoansApiConstants.submittedOnDateParamName);
if (localDate != null) {
// update the value of the "submittedOnDate" variable
submittedOnDate = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
} }
// initially set the value to null // initially set the value to null
Date rescheduleFromDate = null; LocalDate rescheduleFromDate = null;
// start point of the rescheduling exercise // start point of the rescheduling exercise
Integer rescheduleFromInstallment = null; Integer rescheduleFromInstallment = null;
// initially set the value to null // initially set the value to null
Date adjustedDueDate = null; LocalDate adjustedDueDate = null;
// check if the parameter is in the JsonCommand object // check if the parameter is in the JsonCommand object
if (jsonCommand.hasParameter(RescheduleLoansApiConstants.rescheduleFromDateParamName)) { if (jsonCommand.hasParameter(RescheduleLoansApiConstants.rescheduleFromDateParamName)) {
@@ -252,19 +245,14 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
rescheduleFromInstallment = installment.getInstallmentNumber(); rescheduleFromInstallment = installment.getInstallmentNumber();
// update the value of the "rescheduleFromDate" variable // update the value of the "rescheduleFromDate" variable
rescheduleFromDate = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); rescheduleFromDate = localDate;
} }
} }
if (jsonCommand.hasParameter(RescheduleLoansApiConstants.adjustedDueDateParamName)) { if (jsonCommand.hasParameter(RescheduleLoansApiConstants.adjustedDueDateParamName)) {
// create a LocalDate object from the "adjustedDueDate" Date // create a LocalDate object from the "adjustedDueDate" Date
// string // string
LocalDate localDate = jsonCommand.localDateValueOfParameterNamed(RescheduleLoansApiConstants.adjustedDueDateParamName); adjustedDueDate = jsonCommand.localDateValueOfParameterNamed(RescheduleLoansApiConstants.adjustedDueDateParamName);
if (localDate != null) {
// update the value of the "adjustedDueDate"variable
adjustedDueDate = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
} }
final LoanRescheduleRequest loanRescheduleRequest = LoanRescheduleRequest.instance(loan, final LoanRescheduleRequest loanRescheduleRequest = LoanRescheduleRequest.instance(loan,
@@ -277,7 +265,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
final Boolean isActive = false; final Boolean isActive = false;
final boolean isSpecificToInstallment = false; final boolean isSpecificToInstallment = false;
BigDecimal decimalValue = null; BigDecimal decimalValue = null;
Date dueDate = null; LocalDate dueDate = null;
// create term variations for flat and declining balance loans // create term variations for flat and declining balance loans
createLoanTermVariationsForRegularLoans(loan, graceOnPrincipal, graceOnInterest, extraTerms, interestRate, rescheduleFromDate, createLoanTermVariationsForRegularLoans(loan, graceOnPrincipal, graceOnInterest, extraTerms, interestRate, rescheduleFromDate,
adjustedDueDate, loanRescheduleRequest, loanRescheduleRequestToTermVariationMappings, isActive, isSpecificToInstallment, adjustedDueDate, loanRescheduleRequest, loanRescheduleRequestToTermVariationMappings, isActive, isSpecificToInstallment,
@@ -302,23 +290,21 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
} }
private void createLoanTermVariationsForRegularLoans(final Loan loan, final Integer graceOnPrincipal, final Integer graceOnInterest, private void createLoanTermVariationsForRegularLoans(final Loan loan, final Integer graceOnPrincipal, final Integer graceOnInterest,
final Integer extraTerms, final BigDecimal interestRate, Date rescheduleFromDate, Date adjustedDueDate, final Integer extraTerms, final BigDecimal interestRate, LocalDate rescheduleFromDate, LocalDate adjustedDueDate,
final LoanRescheduleRequest loanRescheduleRequest, final LoanRescheduleRequest loanRescheduleRequest,
List<LoanRescheduleRequestToTermVariationMapping> loanRescheduleRequestToTermVariationMappings, final Boolean isActive, List<LoanRescheduleRequestToTermVariationMapping> loanRescheduleRequestToTermVariationMappings, final Boolean isActive,
final boolean isSpecificToInstallment, BigDecimal decimalValue, Date dueDate, Date endDate, BigDecimal emi) { final boolean isSpecificToInstallment, BigDecimal decimalValue, LocalDate dueDate, LocalDate endDate, BigDecimal emi) {
if (rescheduleFromDate != null && endDate != null && emi != null) { if (rescheduleFromDate != null && endDate != null && emi != null) {
LoanTermVariations parent = null; LoanTermVariations parent = null;
LocalDate rescheduleFromLocDate = LocalDate.ofInstant(rescheduleFromDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); LocalDate rescheduleFromLocDate = rescheduleFromDate;
LocalDate endDateLocDate = LocalDate.ofInstant(endDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()); LocalDate endDateLocDate = endDate;
final Integer termType = LoanTermVariationType.EMI_AMOUNT.getValue(); final Integer termType = LoanTermVariationType.EMI_AMOUNT.getValue();
List<LoanRepaymentScheduleInstallment> installments = loan.getRepaymentScheduleInstallments(); List<LoanRepaymentScheduleInstallment> installments = loan.getRepaymentScheduleInstallments();
for (LoanRepaymentScheduleInstallment installment : installments) { for (LoanRepaymentScheduleInstallment installment : installments) {
if (installment.getDueDate().isEqual(rescheduleFromLocDate) || installment.getDueDate().isEqual(endDateLocDate) if (installment.getDueDate().isEqual(rescheduleFromLocDate) || installment.getDueDate().isEqual(endDateLocDate)
|| (installment.getDueDate().isAfter(rescheduleFromLocDate) && installment.getDueDate().isBefore(endDateLocDate))) { || (installment.getDueDate().isAfter(rescheduleFromLocDate) && installment.getDueDate().isBefore(endDateLocDate))) {
createLoanTermVariations(loanRescheduleRequest, termType, loan, createLoanTermVariations(loanRescheduleRequest, termType, loan, installment.getDueDate(), installment.getDueDate(),
Date.from(installment.getDueDate().atStartOfDay(ZoneId.systemDefault()).toInstant()),
Date.from(installment.getDueDate().atStartOfDay(ZoneId.systemDefault()).toInstant()),
loanRescheduleRequestToTermVariationMappings, isActive, true, emi, parent); loanRescheduleRequestToTermVariationMappings, isActive, true, emi, parent);
} }
if (installment.getDueDate().isAfter(endDateLocDate)) { if (installment.getDueDate().isAfter(endDateLocDate)) {
@@ -374,7 +360,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
} }
private LoanTermVariations createLoanTermVariations(LoanRescheduleRequest loanRescheduleRequest, final Integer termType, private LoanTermVariations createLoanTermVariations(LoanRescheduleRequest loanRescheduleRequest, final Integer termType,
final Loan loan, Date rescheduleFromDate, Date adjustedDueDate, final Loan loan, LocalDate rescheduleFromDate, LocalDate adjustedDueDate,
List<LoanRescheduleRequestToTermVariationMapping> loanRescheduleRequestToTermVariationMappings, final Boolean isActive, List<LoanRescheduleRequestToTermVariationMapping> loanRescheduleRequestToTermVariationMappings, final Boolean isActive,
final boolean isSpecificToInstallment, final BigDecimal decimalValue, LoanTermVariations parent) { final boolean isSpecificToInstallment, final BigDecimal decimalValue, LoanTermVariations parent) {
LoanTermVariations loanTermVariation = new LoanTermVariations(termType, rescheduleFromDate, decimalValue, adjustedDueDate, LoanTermVariations loanTermVariation = new LoanTermVariations(termType, rescheduleFromDate, decimalValue, adjustedDueDate,
@@ -436,8 +422,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
&& activeLoanTermVariation.fetchDateValue().equals(dueDateVariationInCurrentRequest.fetchTermApplicaDate())) { && activeLoanTermVariation.fetchDateValue().equals(dueDateVariationInCurrentRequest.fetchTermApplicaDate())) {
activeLoanTermVariation.markAsInactive(); activeLoanTermVariation.markAsInactive();
rescheduleFromDate = activeLoanTermVariation.fetchTermApplicaDate(); rescheduleFromDate = activeLoanTermVariation.fetchTermApplicaDate();
dueDateVariationInCurrentRequest dueDateVariationInCurrentRequest.setTermApplicableFrom(rescheduleFromDate);
.setTermApplicableFrom(Date.from(rescheduleFromDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
} else if (!activeLoanTermVariation.fetchTermApplicaDate().isBefore(fromScheduleDate)) { } else if (!activeLoanTermVariation.fetchTermApplicaDate().isBefore(fromScheduleDate)) {
while (currentScheduleDate.isBefore(activeLoanTermVariation.fetchTermApplicaDate())) { while (currentScheduleDate.isBefore(activeLoanTermVariation.fetchTermApplicaDate())) {
currentScheduleDate = this.scheduledDateGenerator.generateNextRepaymentDate(currentScheduleDate, currentScheduleDate = this.scheduledDateGenerator.generateNextRepaymentDate(currentScheduleDate,
@@ -447,8 +432,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
changeMap.put(currentScheduleDate, modifiedScheduleDate); changeMap.put(currentScheduleDate, modifiedScheduleDate);
} }
if (changeMap.containsKey(activeLoanTermVariation.fetchTermApplicaDate())) { if (changeMap.containsKey(activeLoanTermVariation.fetchTermApplicaDate())) {
activeLoanTermVariation.setTermApplicableFrom(Date.from(changeMap activeLoanTermVariation.setTermApplicableFrom(changeMap.get(activeLoanTermVariation.fetchTermApplicaDate()));
.get(activeLoanTermVariation.fetchTermApplicaDate()).atStartOfDay(ZoneId.systemDefault()).toInstant()));
} }
} }
} }
@@ -20,11 +20,9 @@ package org.apache.fineract.portfolio.loanaccount.service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@@ -271,8 +269,8 @@ public class LoanAccrualWritePlatformServiceImpl implements LoanAccrualWritePlat
String transactionSql = "INSERT INTO m_loan_transaction (loan_id,office_id,is_reversed,transaction_type_enum,transaction_date,amount,interest_portion_derived," String transactionSql = "INSERT INTO m_loan_transaction (loan_id,office_id,is_reversed,transaction_type_enum,transaction_date,amount,interest_portion_derived,"
+ "fee_charges_portion_derived,penalty_charges_portion_derived, submitted_on_date) VALUES (?, ?, false, ?, ?, ?, ?, ?, ?, ?)"; + "fee_charges_portion_derived,penalty_charges_portion_derived, submitted_on_date) VALUES (?, ?, false, ?, ?, ?, ?, ?, ?, ?)";
this.jdbcTemplate.update(transactionSql, scheduleAccrualData.getLoanId(), scheduleAccrualData.getOfficeId(), this.jdbcTemplate.update(transactionSql, scheduleAccrualData.getLoanId(), scheduleAccrualData.getOfficeId(),
LoanTransactionType.ACCRUAL.getValue(), Date.from(accruedTill.atStartOfDay(ZoneId.systemDefault()).toInstant()), amount, LoanTransactionType.ACCRUAL.getValue(), accruedTill, amount, interestportion, feeportion, penaltyportion,
interestportion, feeportion, penaltyportion, DateUtils.getBusinessDate()); DateUtils.getBusinessDate());
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
final Long transactonId = this.jdbcTemplate.queryForObject("SELECT " + sqlGenerator.lastInsertId(), Long.class); // NOSONAR final Long transactonId = this.jdbcTemplate.queryForObject("SELECT " + sqlGenerator.lastInsertId(), Long.class); // NOSONAR
@@ -293,8 +291,7 @@ public class LoanAccrualWritePlatformServiceImpl implements LoanAccrualWritePlat
scheduleAccrualData.getRepaymentScheduleId()); scheduleAccrualData.getRepaymentScheduleId());
String updateLoan = "UPDATE m_loan SET accrued_till=? WHERE id=?"; String updateLoan = "UPDATE m_loan SET accrued_till=? WHERE id=?";
this.jdbcTemplate.update(updateLoan, Date.from(accruedTill.atStartOfDay(ZoneId.systemDefault()).toInstant()), this.jdbcTemplate.update(updateLoan, accruedTill, scheduleAccrualData.getLoanId());
scheduleAccrualData.getLoanId());
final Map<String, Object> accountingBridgeData = deriveAccountingBridgeData(scheduleAccrualData, transactionMap); final Map<String, Object> accountingBridgeData = deriveAccountingBridgeData(scheduleAccrualData, transactionMap);
this.journalEntryWritePlatformService.createJournalEntriesForLoan(accountingBridgeData); this.journalEntryWritePlatformService.createJournalEntriesForLoan(accountingBridgeData);
} }
@@ -21,10 +21,8 @@ package org.apache.fineract.portfolio.loanaccount.service;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@@ -344,8 +342,7 @@ public class LoanAssembler {
final LoanApplicationTerms loanApplicationTerms = this.loanScheduleAssembler.assembleLoanTerms(element); final LoanApplicationTerms loanApplicationTerms = this.loanScheduleAssembler.assembleLoanTerms(element);
final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled(); final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled();
final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loanApplication.getOfficeId(), final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loanApplication.getOfficeId(),
Date.from(loanApplicationTerms.getExpectedDisbursementDate().atStartOfDay(ZoneId.systemDefault()).toInstant()), loanApplicationTerms.getExpectedDisbursementDate(), HolidayStatusType.ACTIVE.getValue());
HolidayStatusType.ACTIVE.getValue());
final WorkingDays workingDays = this.workingDaysRepository.findOne(); final WorkingDays workingDays = this.workingDaysRepository.findOne();
final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled(); final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled();
final boolean allowTransactionsOnHoliday = this.configurationDomainService.allowTransactionsOnHolidayEnabled(); final boolean allowTransactionsOnHoliday = this.configurationDomainService.allowTransactionsOnHolidayEnabled();
@@ -402,8 +399,7 @@ public class LoanAssembler {
final boolean allowTransactionsOnHoliday = this.configurationDomainService.allowTransactionsOnHolidayEnabled(); final boolean allowTransactionsOnHoliday = this.configurationDomainService.allowTransactionsOnHolidayEnabled();
final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loanApplication.getOfficeId(), final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loanApplication.getOfficeId(),
Date.from(loanApplication.getExpectedDisbursedOnLocalDate().atStartOfDay(ZoneId.systemDefault()).toInstant()), loanApplication.getExpectedDisbursedOnLocalDate(), HolidayStatusType.ACTIVE.getValue());
HolidayStatusType.ACTIVE.getValue());
final WorkingDays workingDays = this.workingDaysRepository.findOne(); final WorkingDays workingDays = this.workingDaysRepository.findOne();
final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled(); final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled();
@@ -21,7 +21,6 @@ package org.apache.fineract.portfolio.loanaccount.service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.core.service.Page;
import org.apache.fineract.infrastructure.core.service.SearchParameters; import org.apache.fineract.infrastructure.core.service.SearchParameters;
@@ -123,7 +122,7 @@ public interface LoanReadPlatformService {
boolean isGuaranteeRequired(Long loanId); boolean isGuaranteeRequired(Long loanId);
Date retrieveMinimumDateOfRepaymentTransaction(Long loanId); LocalDate retrieveMinimumDateOfRepaymentTransaction(Long loanId);
PaidInAdvanceData retrieveTotalPaidInAdvance(Long loanId); PaidInAdvanceData retrieveTotalPaidInAdvance(Long loanId);
@@ -24,13 +24,11 @@ import java.math.BigDecimal;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -1656,7 +1654,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
public Collection<LoanScheduleAccrualData> retriveScheduleAccrualData() { public Collection<LoanScheduleAccrualData> retriveScheduleAccrualData() {
LoanScheduleAccrualMapper mapper = new LoanScheduleAccrualMapper(); LoanScheduleAccrualMapper mapper = new LoanScheduleAccrualMapper();
Date organisationStartDate = this.configurationDomainService.retrieveOrganisationStartDate(); LocalDate organisationStartDate = this.configurationDomainService.retrieveOrganisationStartDate();
final StringBuilder sqlBuilder = new StringBuilder(400); final StringBuilder sqlBuilder = new StringBuilder(400);
sqlBuilder.append("select ").append(mapper.schema()).append( sqlBuilder.append("select ").append(mapper.schema()).append(
" where (recaldet.is_compounding_to_be_posted_as_transaction is null or recaldet.is_compounding_to_be_posted_as_transaction = false) ") " where (recaldet.is_compounding_to_be_posted_as_transaction is null or recaldet.is_compounding_to_be_posted_as_transaction = false) ")
@@ -1671,8 +1669,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
Map<String, Object> paramMap = new HashMap<>(3); Map<String, Object> paramMap = new HashMap<>(3);
paramMap.put("active", LoanStatus.ACTIVE.getValue()); paramMap.put("active", LoanStatus.ACTIVE.getValue());
paramMap.put("type", AccountingRuleType.ACCRUAL_PERIODIC.getValue()); paramMap.put("type", AccountingRuleType.ACCRUAL_PERIODIC.getValue());
paramMap.put("organisationStartDate", (organisationStartDate == null) ? DateUtils.getBusinessLocalDate() paramMap.put("organisationStartDate", (organisationStartDate == null) ? DateUtils.getBusinessLocalDate() : organisationStartDate);
: LocalDate.ofInstant(organisationStartDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()));
paramMap.put("currentDate", DateUtils.getBusinessLocalDate()); paramMap.put("currentDate", DateUtils.getBusinessLocalDate());
return this.namedParameterJdbcTemplate.query(sqlBuilder.toString(), paramMap, mapper); return this.namedParameterJdbcTemplate.query(sqlBuilder.toString(), paramMap, mapper);
@@ -1682,7 +1679,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
public Collection<LoanScheduleAccrualData> retrivePeriodicAccrualData(final LocalDate tillDate) { public Collection<LoanScheduleAccrualData> retrivePeriodicAccrualData(final LocalDate tillDate) {
LoanSchedulePeriodicAccrualMapper mapper = new LoanSchedulePeriodicAccrualMapper(); LoanSchedulePeriodicAccrualMapper mapper = new LoanSchedulePeriodicAccrualMapper();
Date organisationStartDate = this.configurationDomainService.retrieveOrganisationStartDate(); LocalDate organisationStartDate = this.configurationDomainService.retrieveOrganisationStartDate();
final StringBuilder sqlBuilder = new StringBuilder(400); final StringBuilder sqlBuilder = new StringBuilder(400);
sqlBuilder.append("select ").append(mapper.schema()).append( sqlBuilder.append("select ").append(mapper.schema()).append(
" where (recaldet.is_compounding_to_be_posted_as_transaction is null or recaldet.is_compounding_to_be_posted_as_transaction = false) ") " where (recaldet.is_compounding_to_be_posted_as_transaction is null or recaldet.is_compounding_to_be_posted_as_transaction = false) ")
@@ -1694,8 +1691,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
Map<String, Object> paramMap = new HashMap<>(4); Map<String, Object> paramMap = new HashMap<>(4);
if (organisationStartDate != null) { if (organisationStartDate != null) {
sqlBuilder.append(" and ls.duedate > :organisationStartDate "); sqlBuilder.append(" and ls.duedate > :organisationStartDate ");
paramMap.put("organisationStartDate", paramMap.put("organisationStartDate", organisationStartDate);
LocalDate.ofInstant(organisationStartDate.toInstant(), DateUtils.getDateTimeZoneOfTenant()));
} }
sqlBuilder.append(" order by loan.id,ls.duedate "); sqlBuilder.append(" order by loan.id,ls.duedate ");
paramMap.put("active", LoanStatus.ACTIVE.getValue()); paramMap.put("active", LoanStatus.ACTIVE.getValue());
@@ -2084,10 +2080,11 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
} }
@Override @Override
public Date retrieveMinimumDateOfRepaymentTransaction(Long loanId) { public LocalDate retrieveMinimumDateOfRepaymentTransaction(Long loanId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
Date date = this.jdbcTemplate.queryForObject( LocalDate date = this.jdbcTemplate.queryForObject(
"select min(transaction_date) from m_loan_transaction where loan_id=? and transaction_type_enum=2", Date.class, loanId); "select min(transaction_date) from m_loan_transaction where loan_id=? and transaction_type_enum=2", LocalDate.class,
loanId);
return date; return date;
} }
@@ -2155,13 +2152,10 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final Collection<InterestRatePeriodData> intRates = this.floatingRatesReadPlatformService final Collection<InterestRatePeriodData> intRates = this.floatingRatesReadPlatformService
.retrieveInterestRatePeriods(loanData.loanProductId()); .retrieveInterestRatePeriods(loanData.loanProductId());
for (final InterestRatePeriodData rate : intRates) { for (final InterestRatePeriodData rate : intRates) {
if (rate.getFromDate() if (rate.getFromDate().compareTo(loanData.getDisbursementDate()) > 0 && loanData.isFloatingInterestRate()) {
.compareTo(Date.from(loanData.getDisbursementDate().atStartOfDay(ZoneId.systemDefault()).toInstant())) > 0
&& loanData.isFloatingInterestRate()) {
updateInterestRatePeriodData(rate, loanData); updateInterestRatePeriodData(rate, loanData);
intRatePeriodData.add(rate); intRatePeriodData.add(rate);
} else if (rate.getFromDate() } else if (rate.getFromDate().compareTo(loanData.getDisbursementDate()) <= 0) {
.compareTo(Date.from(loanData.getDisbursementDate().atStartOfDay(ZoneId.systemDefault()).toInstant())) <= 0) {
updateInterestRatePeriodData(rate, loanData); updateInterestRatePeriodData(rate, loanData);
intRatePeriodData.add(rate); intRatePeriodData.add(rate);
break; break;
@@ -2187,8 +2181,8 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
} }
rate.setEffectiveInterestRate(effectiveInterestRate); rate.setEffectiveInterestRate(effectiveInterestRate);
if (rate.getFromDate().compareTo(Date.from(loan.getDisbursementDate().atStartOfDay(ZoneId.systemDefault()).toInstant())) < 0) { if (rate.getFromDate().compareTo(loan.getDisbursementDate()) < 0) {
rate.setFromDate(Date.from(loan.getDisbursementDate().atStartOfDay(ZoneId.systemDefault()).toInstant())); rate.setFromDate(loan.getDisbursementDate());
} }
} }
@@ -22,9 +22,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
@@ -194,8 +192,7 @@ public class LoanUtilService {
private HolidayDetailDTO constructHolidayDTO(final Loan loan) { private HolidayDetailDTO constructHolidayDTO(final Loan loan) {
final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled(); final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled();
final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(), final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(),
Date.from(loan.getDisbursementDate().atStartOfDay(ZoneId.systemDefault()).toInstant()), loan.getDisbursementDate(), HolidayStatusType.ACTIVE.getValue());
HolidayStatusType.ACTIVE.getValue());
final WorkingDays workingDays = this.workingDaysRepository.findOne(); final WorkingDays workingDays = this.workingDaysRepository.findOne();
final boolean allowTransactionsOnHoliday = this.configurationDomainService.allowTransactionsOnHolidayEnabled(); final boolean allowTransactionsOnHoliday = this.configurationDomainService.allowTransactionsOnHolidayEnabled();
final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled(); final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled();
@@ -319,17 +316,14 @@ public class LoanUtilService {
int i = 0; int i = 0;
do { do {
final JsonObject jsonObject = disbursementDataArray.get(i).getAsJsonObject(); final JsonObject jsonObject = disbursementDataArray.get(i).getAsJsonObject();
Date expectedDisbursementDate = null; LocalDate expectedDisbursementDate = null;
Date actualDisbursementDate = null; LocalDate actualDisbursementDate = null;
BigDecimal principal = null; BigDecimal principal = null;
BigDecimal netDisbursalAmount = null; BigDecimal netDisbursalAmount = null;
if (jsonObject.has(LoanApiConstants.disbursementDateParameterName)) { if (jsonObject.has(LoanApiConstants.disbursementDateParameterName)) {
LocalDate date = this.fromApiJsonHelper.extractLocalDateNamed(LoanApiConstants.disbursementDateParameterName, expectedDisbursementDate = this.fromApiJsonHelper
jsonObject, dateFormat, locale); .extractLocalDateNamed(LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale);
if (date != null) {
expectedDisbursementDate = Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
} }
if (jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName) if (jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName)
&& jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).isJsonPrimitive() && jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).isJsonPrimitive()
@@ -29,7 +29,6 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@@ -318,8 +317,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
if (loan.loanProduct().isDisallowExpectedDisbursements()) { if (loan.loanProduct().isDisallowExpectedDisbursements()) {
// create artificial 'tranche/expected disbursal' as current disburse code expects it for multi-disbursal // create artificial 'tranche/expected disbursal' as current disburse code expects it for multi-disbursal
// products // products
final Date artificialExpectedDate = Date final LocalDate artificialExpectedDate = loan.getExpectedDisbursedOnLocalDate();
.from(loan.getExpectedDisbursedOnLocalDate().atStartOfDay(ZoneId.systemDefault()).toInstant());
LoanDisbursementDetails disbursementDetail = new LoanDisbursementDetails(artificialExpectedDate, null, LoanDisbursementDetails disbursementDetail = new LoanDisbursementDetails(artificialExpectedDate, null,
loan.getDisbursedAmount(), null); loan.getDisbursedAmount(), null);
disbursementDetail.updateLoan(loan); disbursementDetail.updateLoan(loan);
@@ -359,14 +357,14 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
checkClientOrGroupActive(loan); checkClientOrGroupActive(loan);
final LocalDate nextPossibleRepaymentDate = loan.getNextPossibleRepaymentDateForRescheduling(); final LocalDate nextPossibleRepaymentDate = loan.getNextPossibleRepaymentDateForRescheduling();
final Date rescheduledRepaymentDate = command.dateValueOfParameterNamed("adjustRepaymentDate"); final LocalDate rescheduledRepaymentDate = command.localDateValueOfParameterNamed("adjustRepaymentDate");
entityDatatableChecksWritePlatformService.runTheCheckForProduct(loanId, EntityTables.LOAN.getName(), entityDatatableChecksWritePlatformService.runTheCheckForProduct(loanId, EntityTables.LOAN.getName(),
StatusEnum.DISBURSE.getCode().longValue(), EntityTables.LOAN.getForeignKeyColumnNameOnDatatable(), loan.productId()); StatusEnum.DISBURSE.getCode().longValue(), EntityTables.LOAN.getForeignKeyColumnNameOnDatatable(), loan.productId());
LocalDate recalculateFrom = null; LocalDate recalculateFrom = null;
if (!loan.isMultiDisburmentLoan()) { if (!loan.isMultiDisburmentLoan()) {
loan.setActualDisbursementDate(Date.from(actualDisbursementDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); loan.setActualDisbursementDate(actualDisbursementDate);
} }
ScheduleGeneratorDTO scheduleGeneratorDTO = this.loanUtilService.buildScheduleGeneratorDTO(loan, recalculateFrom); ScheduleGeneratorDTO scheduleGeneratorDTO = this.loanUtilService.buildScheduleGeneratorDTO(loan, recalculateFrom);
@@ -669,7 +667,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
} }
final LocalDate nextPossibleRepaymentDate = null; final LocalDate nextPossibleRepaymentDate = null;
final Date rescheduledRepaymentDate = null; final LocalDate rescheduledRepaymentDate = null;
for (final SingleDisbursalCommand singleLoanDisbursalCommand : disbursalCommand) { for (final SingleDisbursalCommand singleLoanDisbursalCommand : disbursalCommand) {
final Loan loan = this.loanAssembler.assembleFrom(singleLoanDisbursalCommand.getLoanId()); final Loan loan = this.loanAssembler.assembleFrom(singleLoanDisbursalCommand.getLoanId());
@@ -970,7 +968,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
if (singleLoanRepaymentCommand != null) { if (singleLoanRepaymentCommand != null) {
Loan loan = this.loanRepositoryWrapper.findOneWithNotFoundDetection(singleLoanRepaymentCommand.getLoanId()); Loan loan = this.loanRepositoryWrapper.findOneWithNotFoundDetection(singleLoanRepaymentCommand.getLoanId());
final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(), final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(),
Date.from(singleLoanRepaymentCommand.getTransactionDate().atStartOfDay(ZoneId.systemDefault()).toInstant())); singleLoanRepaymentCommand.getTransactionDate());
final WorkingDays workingDays = this.workingDaysRepository.findOne(); final WorkingDays workingDays = this.workingDaysRepository.findOne();
final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled(); final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled();
boolean isHolidayEnabled = false; boolean isHolidayEnabled = false;
@@ -2360,8 +2358,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
} }
} }
holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(), holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(), loan.getDisbursementDate());
Date.from(loan.getDisbursementDate().atStartOfDay(ZoneId.systemDefault()).toInstant()));
if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled()) { if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled()) {
ScheduleGeneratorDTO scheduleGeneratorDTO = loanUtilService.buildScheduleGeneratorDTO(loan, recalculateFrom); ScheduleGeneratorDTO scheduleGeneratorDTO = loanUtilService.buildScheduleGeneratorDTO(loan, recalculateFrom);
loan.setHelpers(null, this.loanSummaryWrapper, this.transactionProcessingStrategy); loan.setHelpers(null, this.loanSummaryWrapper, this.transactionProcessingStrategy);
@@ -2414,15 +2411,14 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
private void updateLoanCounters(final Loan loan, final LocalDate actualDisbursementDate) { private void updateLoanCounters(final Loan loan, final LocalDate actualDisbursementDate) {
if (loan.isGroupLoan()) { if (loan.isGroupLoan()) {
final List<Loan> loansToUpdateForLoanCounter = this.loanRepositoryWrapper.getGroupLoansDisbursedAfter( final List<Loan> loansToUpdateForLoanCounter = this.loanRepositoryWrapper.getGroupLoansDisbursedAfter(actualDisbursementDate,
Date.from(actualDisbursementDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), loan.getGroupId(), loan.getGroupId(), AccountType.GROUP.getValue());
AccountType.GROUP.getValue());
final Integer newLoanCounter = getNewGroupLoanCounter(loan); final Integer newLoanCounter = getNewGroupLoanCounter(loan);
final Integer newLoanProductCounter = getNewGroupLoanProductCounter(loan); final Integer newLoanProductCounter = getNewGroupLoanProductCounter(loan);
updateLoanCounter(loan, loansToUpdateForLoanCounter, newLoanCounter, newLoanProductCounter); updateLoanCounter(loan, loansToUpdateForLoanCounter, newLoanCounter, newLoanProductCounter);
} else { } else {
final List<Loan> loansToUpdateForLoanCounter = this.loanRepositoryWrapper.getClientOrJLGLoansDisbursedAfter( final List<Loan> loansToUpdateForLoanCounter = this.loanRepositoryWrapper
Date.from(actualDisbursementDate.atStartOfDay(ZoneId.systemDefault()).toInstant()), loan.getClientId()); .getClientOrJLGLoansDisbursedAfter(actualDisbursementDate, loan.getClientId());
final Integer newLoanCounter = getNewClientOrJLGLoanCounter(loan); final Integer newLoanCounter = getNewClientOrJLGLoanCounter(loan);
final Integer newLoanProductCounter = getNewClientOrJLGLoanProductCounter(loan); final Integer newLoanProductCounter = getNewClientOrJLGLoanProductCounter(loan);
updateLoanCounter(loan, loansToUpdateForLoanCounter, newLoanCounter, newLoanProductCounter); updateLoanCounter(loan, loansToUpdateForLoanCounter, newLoanCounter, newLoanProductCounter);
@@ -3087,8 +3083,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
private void regenerateScheduleOnDisbursement(final JsonCommand command, final Loan loan, final boolean recalculateSchedule, private void regenerateScheduleOnDisbursement(final JsonCommand command, final Loan loan, final boolean recalculateSchedule,
final ScheduleGeneratorDTO scheduleGeneratorDTO, final LocalDate nextPossibleRepaymentDate, final ScheduleGeneratorDTO scheduleGeneratorDTO, final LocalDate nextPossibleRepaymentDate,
final Date rescheduledRepaymentDate) { final LocalDate rescheduledRepaymentDate) {
AppUser currentUser = getAppUserIfPresent();
final LocalDate actualDisbursementDate = command.localDateValueOfParameterNamed("actualDisbursementDate"); final LocalDate actualDisbursementDate = command.localDateValueOfParameterNamed("actualDisbursementDate");
BigDecimal emiAmount = command.bigDecimalValueOfParameterNamed(LoanApiConstants.emiAmountParameterName); BigDecimal emiAmount = command.bigDecimalValueOfParameterNamed(LoanApiConstants.emiAmountParameterName);
loan.regenerateScheduleOnDisbursement(scheduleGeneratorDTO, recalculateSchedule, actualDisbursementDate, emiAmount, loan.regenerateScheduleOnDisbursement(scheduleGeneratorDTO, recalculateSchedule, actualDisbursementDate, emiAmount,