fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nazeer1100...@apache.org
Subject [1/2] incubator-fineract git commit: fineract collection sheet
Date Thu, 09 Jun 2016 08:15:11 GMT
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 <koustav.muhuri@confluxtechnologies.com>
Authored: Thu May 26 16:31:06 2016 +0530
Committer: Koustav Muhuri <koustav.muhuri@confluxtechnologies.com>
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<String> 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<CodeValueData> closureReasons;
     private final Collection<OfficeData> officeOptions;
     private final Collection<StaffData> staffOptions;
-
-    public static CenterData template(final Long officeId, final String accountNo, final
LocalDate activationDate, final Collection<OfficeData> officeOptions,
-            final Collection<StaffData> staffOptions, final Collection<GroupGeneralData>
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<OfficeData> officeOptions, final Collection<StaffData>
staffOptions,
+            final Collection<GroupGeneralData> groupMembersOptions, final BigDecimal
totalCollected, final BigDecimal totalOverdue,
+            final BigDecimal totaldue, final BigDecimal installmentDue) {
         final CalendarData collectionMeetingCalendar = null;
         final Collection<CodeValueData> 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<GroupGeneralData> groupMembers = null;
         final Collection<OfficeData> officeOptions = null;
@@ -85,15 +95,17 @@ public class CenterData {
         final Collection<CodeValueData> 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<GroupGeneralData>
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<CodeValueData> closureReasons)
{
@@ -114,15 +126,21 @@ public class CenterData {
         final Collection<GroupGeneralData> 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<GroupGeneralData> groupMembers,
final Collection<OfficeData> officeOptions,
             final Collection<StaffData> staffOptions, final Collection<GroupGeneralData>
groupMembersOptions,
-            final CalendarData collectionMeetingCalendar, final Collection<CodeValueData>
closureReasons, final GroupTimelineData timeline) {
+            final CalendarData collectionMeetingCalendar, final Collection<CodeValueData>
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<GroupGeneralData> 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<StaffCenterData> 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<CenterData> 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<StaffCenterData> staffCenterDataArray = new ArrayList<>();


Mime
View raw message