diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/FuzzySearchQueryBuilder.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/FuzzySearchQueryBuilder.java index db159acd0..3d60fb1f4 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/FuzzySearchQueryBuilder.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/FuzzySearchQueryBuilder.java @@ -110,6 +110,7 @@ public String getFuzzySearchQuery(SearchCriteria criteria, List ids){ } finalQuery = mapper.writeValueAsString(node); + log.info("final query is"+finalQuery); } catch (Exception e){ diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/WsQueryBuilder.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/WsQueryBuilder.java index f6a31b8eb..7b9799011 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/WsQueryBuilder.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/WsQueryBuilder.java @@ -208,7 +208,7 @@ public class WsQueryBuilder { "ORDER BY startdate"; public static final String TAX_AMOUNT_QUERY="SELECT SUM(taxamount) FROM egbs_demanddetail_v1 WHERE " + - "demandid IN (SELECT id FROM egbs_demand_v1 WHERE consumercode = ? AND taxperiodfrom < ? AND status='ACTIVE');"; + "demandid IN (SELECT id FROM egbs_demand_v1 WHERE consumercode = ? AND taxperiodto < ? AND status='ACTIVE');"; public static final String TOTAL_AMOUNT_PAID_QUERY="SELECT SUM(totalamountpaid) FROM egcl_payment WHERE " + "id IN (SELECT paymentid FROM egcl_paymentdetail WHERE billid IN " + diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/LedgerReportRowMapper.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/LedgerReportRowMapper.java index b3e49e72d..a95dd13b8 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/LedgerReportRowMapper.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/LedgerReportRowMapper.java @@ -76,14 +76,19 @@ public List> extractData(ResultSet resultSet) throws SQLExce while (!currentMonth.isAfter(endMonth)) { String monthAndYear = currentMonth.format(DateTimeFormatter.ofPattern("MMMM yyyy")); + LocalDate startOfMonth = currentMonth.atDay(1); + Long epochTime = startOfMonth.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli(); LedgerReport ledgerReport = new LedgerReport(); ledgerReport.setDemand(new DemandLedgerReport()); ledgerReport.getDemand().setMonthAndYear(monthAndYear); ledgerReport.getDemand().setConnectionNo(consumerCode); + BigDecimal taxAmountResult = getMonthlyTaxAmount(epochTime, consumerCode); + BigDecimal totalAmountPaidResult = getMonthlyTotalAmountPaid(epochTime, consumerCode); + ledgerReport.getDemand().setArrears(taxAmountResult.subtract(totalAmountPaidResult)); + log.info("Arrers are "+ledgerReport.getDemand().getArrears()+" and monthandYear"+ ledgerReport.getDemand().getMonthAndYear()); ledgerReports.put(monthAndYear, ledgerReport); currentMonth = currentMonth.plusMonths(1); } - while (resultSet.next()) { Long dateLong = resultSet.getLong("enddate"); LocalDate date = Instant.ofEpochMilli(dateLong).atZone(ZoneId.systemDefault()).toLocalDate(); @@ -102,30 +107,35 @@ public List> extractData(ResultSet resultSet) throws SQLExce ledgerReport.setPayment(new ArrayList<>()); } - if (code.equals("10102")) { - ledgerReport.getDemand().setArrears(taxamount != null ? taxamount : BigDecimal.ZERO); - ledgerReport.getDemand().setMonthAndYear(monthAndYear); - } else if (code.equals("WS_TIME_PENALTY") || code.equals("10201")) { +// if (code.equals("10102")) { +// ledgerReport.getDemand().setArrears(taxamount != null ? taxamount : BigDecimal.ZERO); +// ledgerReport.getDemand().setMonthAndYear(monthAndYear); +// } else + BigDecimal arrers_Penalty=BigDecimal.ZERO; + if(code.equalsIgnoreCase("10201")) + { + arrers_Penalty=taxamount; + } + if(code.equalsIgnoreCase("WS_Round_Off")) + { + ledgerReport.getDemand().setTaxamount(ledgerReport.getDemand().getTaxamount().add(taxamount)); + } + if (code.equalsIgnoreCase("WS_TIME_PENALTY")) { ledgerReport.getDemand().setPenalty(taxamount != null ? taxamount : BigDecimal.ZERO); BigDecimal amount = ledgerReport.getDemand().getTaxamount() != null ? ledgerReport.getDemand().getTaxamount() : BigDecimal.ZERO; ledgerReport.getDemand().setTotalForCurrentMonth((taxamount != null ? taxamount : BigDecimal.ZERO).add(amount)); - ledgerReport.getDemand().setTotal_due_amount(ledgerReport.getDemand().getTotalForCurrentMonth().add(ledgerReport.getDemand().getArrears() != null ? ledgerReport.getDemand().getArrears() : BigDecimal.ZERO)); - } else if (code.equals("10101")) { + } else if (code.equalsIgnoreCase("10101")) { ledgerReport.getDemand().setMonthAndYear(monthAndYear); ledgerReport.getDemand().setDemandGenerationDate(demandGenerationDateLong); - ledgerReport.getDemand().setTaxamount(taxamount); + ledgerReport.getDemand().setTaxamount(ledgerReport.getDemand().getTaxamount().add(taxamount)); ledgerReport.getDemand().setTotalForCurrentMonth(ledgerReport.getDemand().getTaxamount().add(ledgerReport.getDemand().getPenalty() != null ? ledgerReport.getDemand().getPenalty() : BigDecimal.ZERO)); long dueDateMillis = demandGenerationDateLocal.plus(10, ChronoUnit.DAYS).atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli(); long penaltyAppliedDateMillis = demandGenerationDateLocal.plus(11, ChronoUnit.DAYS).atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli(); ledgerReport.getDemand().setDueDate(dueDateMillis); ledgerReport.getDemand().setPenaltyAppliedDate(penaltyAppliedDateMillis); - Long startDate = resultSet.getLong("startdate"); - String connectionno = resultSet.getString("connectionno"); - BigDecimal taxAmountResult = getMonthlyTaxAmount(startDate, connectionno); - BigDecimal totalAmountPaidResult = getMonthlyTotalAmountPaid(startDate, connectionno); - ledgerReport.getDemand().setArrears(taxAmountResult.subtract(totalAmountPaidResult)); - ledgerReport.getDemand().setTotal_due_amount(ledgerReport.getDemand().getTotalForCurrentMonth().add(ledgerReport.getDemand().getArrears())); +// ledgerReport.getDemand().setTotal_due_amount(ledgerReport.getDemand().getTotalForCurrentMonth().add(ledgerReport.getDemand().getArrears())); } + ledgerReport.getDemand().setTotal_due_amount(ledgerReport.getDemand().getTotalForCurrentMonth().add(ledgerReport.getDemand().getArrears() != null ? ledgerReport.getDemand().getArrears() : BigDecimal.ZERO)); ledgerReport.getDemand().setConnectionNo(resultSet.getString("connectionno")); ledgerReport.getDemand().setOldConnectionNo(resultSet.getString("oldconnectionno")); ledgerReport.getDemand().setUserId(resultSet.getString("uuid")); @@ -182,6 +192,8 @@ private void addPaymentToLedger(List> monthlyRecordList) { boolean paymentMatched = false; if(payments!=null) { + BigDecimal totalPaymentInMonth=BigDecimal.ZERO; + BigDecimal totalBalanceLeftInMonth=BigDecimal.ZERO; for (Payment payment : payments) { Long transactionDateLong = payment.getTransactionDate(); LocalDate transactionDate = Instant.ofEpochMilli(transactionDateLong).atZone(ZoneId.systemDefault()).toLocalDate(); @@ -191,15 +203,9 @@ private void addPaymentToLedger(List> monthlyRecordList) { paymentLedgerReport.setCollectionDate(transactionDateLong); paymentLedgerReport.setReceiptNo(payment.getPaymentDetails().get(0).getReceiptNumber()); paymentLedgerReport.setPaid(payment.getTotalAmountPaid()); - BigDecimal totalDueAmount=ledgerReport.getDemand().getTotal_due_amount(); - if(totalDueAmount.equals(BigDecimal.ZERO)) - { - paymentLedgerReport.setBalanceLeft(payment.getTotalDue().subtract(paymentLedgerReport.getPaid())); - } - else - { - paymentLedgerReport.setBalanceLeft(totalDueAmount.subtract(paymentLedgerReport.getPaid())); - } + paymentLedgerReport.setBalanceLeft(payment.getTotalDue().subtract(paymentLedgerReport.getPaid())); + totalPaymentInMonth=totalPaymentInMonth.add(payment.getTotalAmountPaid()); + totalBalanceLeftInMonth=totalBalanceLeftInMonth.add(payment.getTotalDue()); if (ledgerReport.getPayment() == null) { ledgerReport.setPayment(new ArrayList<>()); } @@ -207,6 +213,8 @@ private void addPaymentToLedger(List> monthlyRecordList) { paymentMatched = true; } } + ledgerReport.setTotalBalanceLeftInMonth(totalBalanceLeftInMonth); + ledgerReport.setTotalPaymentInMonth(totalPaymentInMonth); } if (!paymentMatched) { PaymentLedgerReport defaultPaymentLedgerReport = new PaymentLedgerReport(); diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/DemandLedgerReport.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/DemandLedgerReport.java index c7cad175e..b84da9289 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/DemandLedgerReport.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/DemandLedgerReport.java @@ -56,12 +56,4 @@ public class DemandLedgerReport { @JsonProperty("penaltyAppliedOnDate") private Long penaltyAppliedDate=0L; -// public DemandLedgerReport(String monthAndYear) { -// this.monthAndYear = monthAndYear; -// this.taxamount = BigDecimal.ZERO; -// this.penalty = BigDecimal.ZERO; -// this.totalForCurrentMonth = BigDecimal.ZERO; -// this.arrears = BigDecimal.ZERO; -// this.total_due_amount = BigDecimal.ZERO; -// } } diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/LedgerReport.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/LedgerReport.java index 3dac0232e..720e7f2cb 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/LedgerReport.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/LedgerReport.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.*; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -17,4 +18,10 @@ public class LedgerReport @JsonProperty("payment") private List payment=new ArrayList<>(); + + @JsonProperty("totalPaymentInMonth") + private BigDecimal totalPaymentInMonth=BigDecimal.ZERO; + + @JsonProperty("totalBalanceLeftInMonth") + private BigDecimal totalBalanceLeftInMonth=BigDecimal.ZERO; }