Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 85BCC200ACA for ; Thu, 9 Jun 2016 10:15:20 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 84500160A2B; Thu, 9 Jun 2016 08:15:20 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3611C160A58 for ; Thu, 9 Jun 2016 10:15:19 +0200 (CEST) Received: (qmail 9849 invoked by uid 500); 9 Jun 2016 08:15:18 -0000 Mailing-List: contact commits-help@fineract.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@fineract.incubator.apache.org Delivered-To: mailing list commits@fineract.incubator.apache.org Received: (qmail 9840 invoked by uid 99); 9 Jun 2016 08:15:18 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Jun 2016 08:15:18 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 085E4C0EB4 for ; Thu, 9 Jun 2016 08:15:18 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx2-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id gEVTXkJY7XN3 for ; Thu, 9 Jun 2016 08:15:14 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-eu.apache.org (ASF Mail Server at mx2-lw-eu.apache.org) with SMTP id C014B5F19D for ; Thu, 9 Jun 2016 08:15:12 +0000 (UTC) Received: (qmail 9755 invoked by uid 99); 9 Jun 2016 08:15:11 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Jun 2016 08:15:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BE7CFDFC61; Thu, 9 Jun 2016 08:15:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: nazeer1100126@apache.org To: commits@fineract.incubator.apache.org Date: Thu, 09 Jun 2016 08:15:11 -0000 Message-Id: <48e9c54de0af46e0805f64be101e6a53@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] incubator-fineract git commit: fineract collection sheet archived-at: Thu, 09 Jun 2016 08:15:20 -0000 Repository: incubator-fineract Updated Branches: refs/heads/develop 979b57c38 -> 41440de25 fineract collection sheet Project: http://git-wip-us.apache.org/repos/asf/incubator-fineract/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-fineract/commit/3fa07c8b Tree: http://git-wip-us.apache.org/repos/asf/incubator-fineract/tree/3fa07c8b Diff: http://git-wip-us.apache.org/repos/asf/incubator-fineract/diff/3fa07c8b Branch: refs/heads/develop Commit: 3fa07c8bc59ab2b062272a8b0df694c6b9e683f7 Parents: f96d96a Author: Koustav Muhuri Authored: Thu May 26 16:31:06 2016 +0530 Committer: Koustav Muhuri Committed: Mon May 30 16:01:25 2016 +0530 ---------------------------------------------------------------------- .../group/api/GroupingTypesApiConstants.java | 6 +- .../portfolio/group/data/CenterData.java | 60 +++++++++++++------ .../service/CenterReadPlatformServiceImpl.java | 62 +++++++++++++++----- 3 files changed, 93 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/3fa07c8b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/GroupingTypesApiConstants.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/GroupingTypesApiConstants.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/GroupingTypesApiConstants.java index 7a823e5..bf1d6d0 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/GroupingTypesApiConstants.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/GroupingTypesApiConstants.java @@ -75,6 +75,10 @@ public class GroupingTypesApiConstants { public static final String collectionMeetingCalendar = "collectionMeetingCalendar"; public static final String timeLine = "timeline"; public static final String closureReasons = "closureReasons"; + public static final String totalCollected = "totalCollected"; + public static final String totalOverdue = "totalOverdue"; + public static final String totaldue = "totaldue"; + public static final String installmentDue = "installmentDue"; // group close parameters public static final String closureDateParamName = "closureDate"; @@ -123,5 +127,5 @@ public class GroupingTypesApiConstants { dateFormatParamName, closureDateParamName, closureReasonIdParamName)); public static final Set STAFF_CENTER_RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList(staffIdParamName, - staffNameParamName, meetingFallCenters)); + staffNameParamName, meetingFallCenters, totalCollected, totalOverdue, totaldue, installmentDue)); } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/3fa07c8b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/CenterData.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/CenterData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/CenterData.java index 5b265b2..b05267d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/CenterData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/CenterData.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.portfolio.group.data; +import java.math.BigDecimal; import java.util.Collection; import org.apache.fineract.infrastructure.codes.data.CodeValueData; @@ -57,26 +58,35 @@ public class CenterData { private final Collection closureReasons; private final Collection officeOptions; private final Collection staffOptions; - - public static CenterData template(final Long officeId, final String accountNo, final LocalDate activationDate, final Collection officeOptions, - final Collection staffOptions, final Collection groupMembersOptions) { + private final BigDecimal totalCollected; + private final BigDecimal totalOverdue; + private final BigDecimal totaldue; + private final BigDecimal installmentDue; + + public static CenterData template(final Long officeId, final String accountNo, final LocalDate activationDate, + final Collection officeOptions, final Collection staffOptions, + final Collection groupMembersOptions, final BigDecimal totalCollected, final BigDecimal totalOverdue, + final BigDecimal totaldue, final BigDecimal installmentDue) { final CalendarData collectionMeetingCalendar = null; final Collection closureReasons = null; final GroupTimelineData timeline = null; - return new CenterData(null, accountNo, null, null, null, activationDate, officeId, null, null, null, null, null, officeOptions, staffOptions, - groupMembersOptions, collectionMeetingCalendar, closureReasons, timeline); + return new CenterData(null, accountNo, null, null, null, activationDate, officeId, null, null, null, null, null, officeOptions, + staffOptions, groupMembersOptions, collectionMeetingCalendar, closureReasons, timeline, totalCollected, totalOverdue, + totaldue, installmentDue); } public static CenterData withTemplate(final CenterData templateCenter, final CenterData center) { - return new CenterData(center.id, center.accountNo, center.name, center.externalId, center.status, center.activationDate, center.officeId, - center.officeName, center.staffId, center.staffName, center.hierarchy, center.groupMembers, templateCenter.officeOptions, - templateCenter.staffOptions, templateCenter.groupMembersOptions, templateCenter.collectionMeetingCalendar, - templateCenter.closureReasons, center.timeline); + return new CenterData(center.id, center.accountNo, center.name, center.externalId, center.status, center.activationDate, + center.officeId, center.officeName, center.staffId, center.staffName, center.hierarchy, center.groupMembers, + templateCenter.officeOptions, templateCenter.staffOptions, templateCenter.groupMembersOptions, + templateCenter.collectionMeetingCalendar, templateCenter.closureReasons, center.timeline, center.totalCollected, + center.totalOverdue, center.totaldue, center.installmentDue); } - public static CenterData instance(final Long id, final String accountNo, final String name, final String externalId, final EnumOptionData status, - final LocalDate activationDate, final Long officeId, final String officeName, final Long staffId, final String staffName, - final String hierarchy, final GroupTimelineData timeline, final CalendarData collectionMeetingCalendar) { + public static CenterData instance(final Long id, final String accountNo, final String name, final String externalId, + final EnumOptionData status, final LocalDate activationDate, final Long officeId, final String officeName, final Long staffId, + final String staffName, final String hierarchy, final GroupTimelineData timeline, final CalendarData collectionMeetingCalendar, + final BigDecimal totalCollected, final BigDecimal totalOverdue, final BigDecimal totaldue, final BigDecimal installmentDue) { final Collection groupMembers = null; final Collection officeOptions = null; @@ -85,15 +95,17 @@ public class CenterData { final Collection closureReasons = null; return new CenterData(id, accountNo, name, externalId, status, activationDate, officeId, officeName, staffId, staffName, hierarchy, - groupMembers, officeOptions, staffOptions, groupMembersOptions, collectionMeetingCalendar, closureReasons, timeline); + groupMembers, officeOptions, staffOptions, groupMembersOptions, collectionMeetingCalendar, closureReasons, timeline, + totalCollected, totalOverdue, totaldue, installmentDue); } public static CenterData withAssociations(final CenterData centerData, final Collection groupMembers, final CalendarData collectionMeetingCalendar) { - return new CenterData(centerData.id, centerData.accountNo, centerData.name, centerData.externalId, centerData.status, centerData.activationDate, - centerData.officeId, centerData.officeName, centerData.staffId, centerData.staffName, centerData.hierarchy, groupMembers, - centerData.officeOptions, centerData.staffOptions, centerData.groupMembersOptions, collectionMeetingCalendar, - centerData.closureReasons, centerData.timeline); + return new CenterData(centerData.id, centerData.accountNo, centerData.name, centerData.externalId, centerData.status, + centerData.activationDate, centerData.officeId, centerData.officeName, centerData.staffId, centerData.staffName, + centerData.hierarchy, groupMembers, centerData.officeOptions, centerData.staffOptions, centerData.groupMembersOptions, + collectionMeetingCalendar, centerData.closureReasons, centerData.timeline, centerData.totalCollected, + centerData.totalOverdue, centerData.totaldue, centerData.installmentDue); } public static CenterData withClosureReasons(final Collection closureReasons) { @@ -114,15 +126,21 @@ public class CenterData { final Collection groupMembersOptions = null; final CalendarData collectionMeetingCalendar = null; final GroupTimelineData timeline = null; + final BigDecimal totalCollected = null; + final BigDecimal totalOverdue = null; + final BigDecimal totaldue = null; + final BigDecimal installmentDue = null; return new CenterData(id, accountNo, name, externalId, status, activationDate, officeId, officeName, staffId, staffName, hierarchy, - groupMembers, officeOptions, staffOptions, groupMembersOptions, collectionMeetingCalendar, closureReasons, timeline); + groupMembers, officeOptions, staffOptions, groupMembersOptions, collectionMeetingCalendar, closureReasons, timeline, + totalCollected, totalOverdue, totaldue, installmentDue); } private CenterData(final Long id, final String accountNo, final String name, final String externalId, final EnumOptionData status, final LocalDate activationDate, final Long officeId, final String officeName, final Long staffId, final String staffName, final String hierarchy, final Collection groupMembers, final Collection officeOptions, final Collection staffOptions, final Collection groupMembersOptions, - final CalendarData collectionMeetingCalendar, final Collection closureReasons, final GroupTimelineData timeline) { + final CalendarData collectionMeetingCalendar, final Collection closureReasons, final GroupTimelineData timeline, + final BigDecimal totalCollected, final BigDecimal totalOverdue, final BigDecimal totaldue, final BigDecimal installmentDue) { this.id = id; this.accountNo = accountNo; this.name = name; @@ -149,6 +167,10 @@ public class CenterData { this.collectionMeetingCalendar = collectionMeetingCalendar; this.closureReasons = closureReasons; this.timeline = timeline; + this.totalCollected = totalCollected; + this.totaldue = totaldue; + this.totalOverdue = totalOverdue; + this.installmentDue = installmentDue; } public Long officeId() { http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/3fa07c8b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java index fc503b7..ca8aa1b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.portfolio.group.service; +import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; @@ -40,6 +41,7 @@ import org.apache.fineract.infrastructure.core.data.PaginationParameters; import org.apache.fineract.infrastructure.core.data.PaginationParametersDataValidator; import org.apache.fineract.infrastructure.core.domain.JdbcSupport; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.core.service.PaginationHelper; import org.apache.fineract.infrastructure.core.service.RoutingDataSource; @@ -67,6 +69,8 @@ import org.apache.fineract.portfolio.group.exception.CenterNotFoundException; import org.apache.fineract.useradministration.domain.AppUser; import org.joda.time.LocalDate; import org.joda.time.LocalTime; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; @@ -85,6 +89,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService private final CodeValueReadPlatformService codeValueReadPlatformService; private final ConfigurationDomainService configurationDomainService; private final CalendarReadPlatformService calendarReadPlatformService; + private final DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); // data mappers private final CenterDataMapper centerMapper = new CenterDataMapper(); @@ -221,8 +226,8 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService submittedByLastname, activationDate, activatedByUsername, activatedByFirstname, activatedByLastname, closedOnDate, closedByUsername, closedByFirstname, closedByLastname); - return CenterData.instance(id, accountNo, name, externalId, status, activationDate, officeId, officeName, staffId, staffName, hierarchy, - timeline, null); + return CenterData.instance(id, accountNo, name, externalId, status, activationDate, officeId, officeName, staffId, staffName, + hierarchy, timeline, null, null, null, null, null); } } @@ -232,13 +237,26 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService public CenterCalendarDataMapper() { - schemaSql = " select g.id as id, g.account_no as accountNo, g.display_name as name, g.office_id as officeId, g.staff_id as staffId, s.display_name as staffName, g.external_id as externalId, " - + " g.status_enum as statusEnum, g.activation_date as activationDate, g.hierarchy as hierarchy, " - + " c.id as calendarId, ci.id as calendarInstanceId, ci.entity_id as entityId, " - + " ci.entity_type_enum as entityTypeId, c.title as title, c.description as description, " - + " c.location as location, c.start_date as startDate, c.end_date as endDate, c.recurrence as recurrence,c.meeting_time as meetingTime " - + " from m_calendar c join m_calendar_instance ci on ci.calendar_id=c.id and ci.entity_type_enum=4 join m_group g " - + " on g.id = ci.entity_id join m_staff s on g.staff_id = s.id where g.office_id=? "; + schemaSql = "select ce.id as id, g.account_no as accountNo," + + "ce.display_name as name, g.office_id as officeId, g.staff_id as staffId, s.display_name as staffName," + + " g.external_id as externalId, g.status_enum as statusEnum, g.activation_date as activationDate," + + " g.hierarchy as hierarchy, c.id as calendarId, ci.id as calendarInstanceId, ci.entity_id as entityId," + + " ci.entity_type_enum as entityTypeId, c.title as title, c.description as description," + + "c.location as location, c.start_date as startDate, c.end_date as endDate, c.recurrence as recurrence,c.meeting_time as meetingTime," + + "sum(if(l.loan_status_id=300 and lrs.duedate = ?," + + "(ifnull(lrs.principal_amount,0)) + (ifnull(lrs.interest_amount,0)),0)) as installmentDue," + + "sum(if(l.loan_status_id=300 and lrs.duedate = ?," + + "(ifnull(lrs.principal_completed_derived,0)) + (ifnull(lrs.interest_completed_derived,0)),0)) as totalCollected," + + "sum(if(l.loan_status_id=300 and lrs.duedate <= ?, (ifnull(lrs.principal_amount,0)) + (ifnull(lrs.interest_amount,0)),0))" + + "- sum(if(l.loan_status_id=300 and lrs.duedate <= ?, (ifnull(lrs.principal_completed_derived,0)) + (ifnull(lrs.interest_completed_derived,0)),0)) as totaldue, " + + "sum(if(l.loan_status_id=300 and lrs.duedate < ?, (ifnull(lrs.principal_amount,0)) + (ifnull(lrs.interest_amount,0)),0))" + + "- sum(if(l.loan_status_id=300 and lrs.duedate < ?, (ifnull(lrs.principal_completed_derived,0)) + (ifnull(lrs.interest_completed_derived,0)),0)) as totaloverdue" + + " from m_calendar c join m_calendar_instance ci on ci.calendar_id=c.id and ci.entity_type_enum=4" + + " join m_group ce on ce.id = ci.entity_id" + " join m_group g on g.parent_id = ce.id" + + " join m_group_client gc on gc.group_id=g.id" + " join m_client cl on cl.id=gc.client_id" + + " join m_loan l on l.client_id = cl.id" + + " join m_loan_repayment_schedule lrs on lrs.loan_id=l.id join m_staff s on g.staff_id = s.id" + + " where g.office_id=?"; } public String schema() { @@ -272,14 +290,18 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService final LocalDate endDate = JdbcSupport.getLocalDate(rs, "endDate"); final String recurrence = rs.getString("recurrence"); final LocalTime meetingTime = JdbcSupport.getLocalTime(rs,"meetingTime"); + final BigDecimal totalCollected = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "totalCollected"); + final BigDecimal totalOverdue = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "totalOverdue"); + final BigDecimal totaldue = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "totaldue"); + final BigDecimal installmentDue = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "installmentDue"); Integer monthOnDay = CalendarUtils.getMonthOnDay(recurrence); CalendarData calendarData = CalendarData.instance(calendarId, calendarInstanceId, entityId, entityType, title, description, location, startDate, endDate, null, null, false, recurrence, null, null, null, null, null, null, null, null, null, null, null, null, null, null, meetingTime, monthOnDay); - return CenterData.instance(id, accountNo, name, externalId, status, activationDate, officeId, null, staffId, staffName, hierarchy, null, - calendarData); + return CenterData.instance(id, accountNo, name, externalId, status, activationDate, officeId, null, staffId, staffName, + hierarchy, null, calendarData, totalCollected, totalOverdue, totaldue, installmentDue); } } @@ -440,11 +462,16 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService } final Collection groupMembersOptions = null; final String accountNo = null; + final BigDecimal totalCollected = null; + final BigDecimal totalOverdue = null; + final BigDecimal totaldue = null; + final BigDecimal installmentDue = null; // final boolean clientPendingApprovalAllowed = // this.configurationDomainService.isClientPendingApprovalAllowedEnabled(); - return CenterData.template(officeIdDefaulted, accountNo, new LocalDate(), officeOptions, staffOptions, groupMembersOptions); + return CenterData.template(officeIdDefaulted, accountNo, new LocalDate(), officeOptions, staffOptions, groupMembersOptions, + totalCollected, totalOverdue, totaldue, installmentDue); } private Long defaultToUsersOfficeIfNull(final Long officeId) { @@ -520,15 +547,20 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService @Override public Collection retriveAllCentersByMeetingDate(final Long officeId, final Date meetingDate, final Long staffId) { validateForGenerateCollectionSheet(staffId); + LocalDate localDate = new LocalDate(meetingDate); final CenterCalendarDataMapper centerCalendarMapper = new CenterCalendarDataMapper(); String sql = centerCalendarMapper.schema(); Collection centerDataArray = null; - + String passeddate = formatter.print(localDate); if (staffId != null) { sql += " and g.staff_id=? "; - centerDataArray = this.jdbcTemplate.query(sql, centerCalendarMapper, new Object[] { officeId, staffId }); + sql += "and lrs.duedate<='" + passeddate + "' and l.loan_type_enum=3"; + sql += " group by c.id,ci.id"; + centerDataArray = this.jdbcTemplate.query(sql, centerCalendarMapper, new Object[] { passeddate, passeddate, passeddate, passeddate, + passeddate, passeddate, officeId, staffId }); } else { - centerDataArray = this.jdbcTemplate.query(sql, centerCalendarMapper, new Object[] { officeId }); + centerDataArray = this.jdbcTemplate.query(sql, centerCalendarMapper, new Object[] { passeddate, passeddate, passeddate, passeddate, + passeddate, passeddate, officeId }); } Collection staffCenterDataArray = new ArrayList<>();