diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java index ec76b88b7..37544a752 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java @@ -318,9 +318,12 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe StringBuilder sql = new StringBuilder(mapper.collectionSheetSchema()); sql.append(" WHERE gp.id = :groupId GROUP BY gp.id ,cl.id , ln.id ORDER BY gp.id , cl.id , ln.id "); + //entityType should be center if it's within a center + final CalendarEntityType entityType = (group.isChildGroup()) ? CalendarEntityType.CENTERS : CalendarEntityType.GROUPS; + final SqlParameterSource namedParameters = new MapSqlParameterSource().addValue("dueDate", transactionDateStr) .addValue("groupId", group.getId()).addValue("officeHierarchy", officeHierarchy) - .addValue("entityTypeId", CalendarEntityType.CENTERS.getValue()); + .addValue("entityTypeId", entityType.getValue()); final Collection collectionSheetFlatDatas = this.namedParameterjdbcTemplate.query(sql.toString(), namedParameters, mapper); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java index b816da1fb..0fc5d9dcd 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java @@ -398,4 +398,8 @@ public final class Group extends AbstractPersistable { } return false; } + + public boolean isChildGroup(){ + return (this.parent == null) ? false : true; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/meeting/service/MeetingWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/meeting/service/MeetingWritePlatformServiceJpaRepositoryImpl.java index 9736fc3e5..b77230a86 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/meeting/service/MeetingWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/meeting/service/MeetingWritePlatformServiceJpaRepositoryImpl.java @@ -5,12 +5,12 @@ */ package org.mifosplatform.portfolio.meeting.service; +import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.transactionDateParamName; import static org.mifosplatform.portfolio.meeting.MeetingApiConstants.attendanceTypeParamName; import static org.mifosplatform.portfolio.meeting.MeetingApiConstants.calendarIdParamName; import static org.mifosplatform.portfolio.meeting.MeetingApiConstants.clientIdParamName; import static org.mifosplatform.portfolio.meeting.MeetingApiConstants.clientsAttendanceParamName; import static org.mifosplatform.portfolio.meeting.MeetingApiConstants.meetingDateParamName; -import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.transactionDateParamName; import java.util.ArrayList; import java.util.Collection; @@ -107,13 +107,21 @@ public class MeetingWritePlatformServiceJpaRepositoryImpl implements MeetingWrit private CalendarInstance getCalendarInstance(final JsonCommand command) { final Long calendarId = command.longValueOfParameterNamed(calendarIdParamName); - final Long entityId = command.getSupportedEntityId(); + Long entityId = command.getSupportedEntityId(); final Calendar calendarForUpdate = this.calendarRepository.findOne(calendarId); if (calendarForUpdate == null) { throw new CalendarNotFoundException(calendarId); } + CalendarEntityType entityType = CalendarEntityType.valueOf(command.getSupportedEntityType().toUpperCase()); + //If group is within a center then center entityType should be passed for retrieving CalendarInstance. + if(CalendarEntityType.isGroup(command.getSupportedEntityType().toUpperCase())){ + final Group group = this.groupRepository.findOne(entityId); + if(group.isChildGroup()){ + entityType = CalendarEntityType.CENTERS; + entityId = group.getParent().getId(); + } + } - final Integer entityTypeId = CalendarEntityType.valueOf(command.getSupportedEntityType().toUpperCase()).getValue(); final CalendarInstance calendarInstance = this.calendarInstanceRepository.findByCalendarIdAndEntityIdAndEntityTypeId( - calendarForUpdate.getId(), entityId, entityTypeId); + calendarForUpdate.getId(), entityId, entityType.getValue()); if (calendarInstance == null) { final String postFix = "for." + command.getSupportedEntityType() + "not.found"; final String defaultUserMessage = "No Calendar Instance details found for group with identifier " + entityId