Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #898 from egovernments/ISTE-229
Browse files Browse the repository at this point in the history
Iste 229
  • Loading branch information
pradeepkumarcm-egov authored Aug 9, 2024
2 parents 10a704f + f1f9d86 commit 7fd9f1c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public String getFuzzySearchQuery(SearchCriteria criteria, List<String> ids){
}

finalQuery = mapper.writeValueAsString(node);
log.info("final query is"+finalQuery);

}
catch (Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,19 @@ public List<Map<String, Object>> 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();
Expand All @@ -102,30 +107,35 @@ public List<Map<String, Object>> 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"));
Expand Down Expand Up @@ -182,6 +192,8 @@ private void addPaymentToLedger(List<Map<String, Object>> 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();
Expand All @@ -191,22 +203,18 @@ private void addPaymentToLedger(List<Map<String, Object>> 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<>());
}
ledgerReport.getPayment().add(paymentLedgerReport);
paymentMatched = true;
}
}
ledgerReport.setTotalBalanceLeftInMonth(totalBalanceLeftInMonth);
ledgerReport.setTotalPaymentInMonth(totalPaymentInMonth);
}
if (!paymentMatched) {
PaymentLedgerReport defaultPaymentLedgerReport = new PaymentLedgerReport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -17,4 +18,10 @@ public class LedgerReport

@JsonProperty("payment")
private List<PaymentLedgerReport> payment=new ArrayList<>();

@JsonProperty("totalPaymentInMonth")
private BigDecimal totalPaymentInMonth=BigDecimal.ZERO;

@JsonProperty("totalBalanceLeftInMonth")
private BigDecimal totalBalanceLeftInMonth=BigDecimal.ZERO;
}

0 comments on commit 7fd9f1c

Please sign in to comment.