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

Develop #965

Merged
merged 19 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,8 @@ public class WSConfiguration {

@Value("${sms.feedback.notification.enabled}")
private boolean isSMSForFeedbackNotificationEnabled;

@Value("${report.in.chronological.order}")
private boolean isReportRequiredInChronnologicalOrder;

}
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 taxperiodto < ? AND status='ACTIVE') and taxheadcode!= 'WS_ADVANCE_CARRYFORWARD';";
"demandid IN (SELECT id FROM egbs_demand_v1 WHERE consumercode = ? AND taxperiodto < ? AND status='ACTIVE') ";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure 'taxperiodto' parameter is added to the prepared statement

In the TAX_AMOUNT_QUERY, the subquery includes a placeholder for taxperiodto:

"demandid IN (SELECT id FROM egbs_demand_v1 WHERE consumercode = ? AND taxperiodto < ? AND status='ACTIVE') ";

Make sure that the taxperiodto parameter is properly added to the preparedStatement list when executing this query to prevent potential issues with parameter binding and to ensure the query executes correctly.


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 @@ -4,6 +4,7 @@
import io.swagger.models.auth.In;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.egov.waterconnection.config.WSConfiguration;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add missing import for Locale

The class uses Locale.ENGLISH in date formatting but does not import java.util.Locale. This could lead to a Compilation Error.

Apply this diff to add the necessary import:

+ import java.util.Locale;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import org.egov.waterconnection.config.WSConfiguration;
import org.egov.waterconnection.config.WSConfiguration;
import java.util.Locale;

import org.egov.waterconnection.repository.ServiceRequestRepository;
import org.egov.waterconnection.repository.builder.WsQueryBuilder;
import org.egov.waterconnection.util.WaterServicesUtil;
Expand Down Expand Up @@ -54,6 +55,9 @@ public class LedgerReportRowMapper implements ResultSetExtractor<List<Map<String
Integer endYear;
String consumerCode;

@Autowired
private WSConfiguration config;

public void setRequestInfo(RequestInfoWrapper requestInfoWrapper) {
this.requestInfoWrapper = requestInfoWrapper;
}
Expand Down Expand Up @@ -83,9 +87,7 @@ public List<Map<String, Object>> extractData(ResultSet resultSet) throws SQLExce
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);
Expand All @@ -101,8 +103,13 @@ public List<Map<String, Object>> extractData(ResultSet resultSet) throws SQLExce

Long demandGenerationDateLong = resultSet.getLong("demandgenerationdate");
LocalDate demandGenerationDateLocal = Instant.ofEpochMilli(demandGenerationDateLong).atZone(ZoneId.systemDefault()).toLocalDate();
BigDecimal totalAmountPaidResult = getMonthlyTotalAmountPaid(demandGenerationDateLong, consumerCode);
boolean paymentExists = totalAmountPaidResult != null && totalAmountPaidResult.compareTo(BigDecimal.ZERO) > 0;
BigDecimal taxAmountResult = getMonthlyTaxAmount(resultSet.getLong("startdate"), consumerCode,paymentExists);


LedgerReport ledgerReport = ledgerReports.get(monthAndYear);
ledgerReport.getDemand().setArrears(taxAmountResult.subtract(totalAmountPaidResult));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle potential NullPointerException when setting arrears

The method taxAmountResult.subtract(totalAmountPaidResult) could throw a NullPointerException if either taxAmountResult or totalAmountPaidResult is null. Ensure both variables are non-null before performing the subtraction.

Apply this diff to add null checks:

- ledgerReport.getDemand().setArrears(taxAmountResult.subtract(totalAmountPaidResult));
+ BigDecimal arrears = (taxAmountResult != null ? taxAmountResult : BigDecimal.ZERO)
+     .subtract(totalAmountPaidResult != null ? totalAmountPaidResult : BigDecimal.ZERO);
+ ledgerReport.getDemand().setArrears(arrears);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ledgerReport.getDemand().setArrears(taxAmountResult.subtract(totalAmountPaidResult));
BigDecimal arrears = (taxAmountResult != null ? taxAmountResult : BigDecimal.ZERO)
.subtract(totalAmountPaidResult != null ? totalAmountPaidResult : BigDecimal.ZERO);
ledgerReport.getDemand().setArrears(arrears);


if (ledgerReport.getPayment() == null) {
ledgerReport.setPayment(new ArrayList<>());
Expand Down Expand Up @@ -150,7 +157,11 @@ public List<Map<String, Object>> extractData(ResultSet resultSet) throws SQLExce
}
log.info("ledger report list" + monthlyRecordsList);
if (!monthlyRecordsList.isEmpty()) {
addPaymentToLedger(monthlyRecordsList);
if(config.isReportRequiredInChronnologicalOrder())
addPaymentToLedgerChronlogicalOrder(monthlyRecordsList);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Correct typo in method name addPaymentToLedgerChronlogicalOrder

There is a typo in the method name addPaymentToLedgerChronlogicalOrder. The correct spelling is addPaymentToLedgerChronologicalOrder. This typo occurs in both the method call and its definition.

Apply this diff to correct the method name:

- addPaymentToLedgerChronlogicalOrder(monthlyRecordsList);
+ addPaymentToLedgerChronologicalOrder(monthlyRecordsList);

Also, update the method definition accordingly:

- private void addPaymentToLedgerChronlogicalOrder(List<Map<String, Object>> monthlyRecordList) {
+ private void addPaymentToLedgerChronologicalOrder(List<Map<String, Object>> monthlyRecordList) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
addPaymentToLedgerChronlogicalOrder(monthlyRecordsList);
addPaymentToLedgerChronologicalOrder(monthlyRecordsList);

else
addPaymentToLedger(monthlyRecordsList);

}
monthlyRecordsList.sort(new Comparator<Map<String, Object>>() {
@Override
Expand Down Expand Up @@ -199,7 +210,7 @@ private void addPaymentToLedger(List<Map<String, Object>> monthlyRecordList) {
Long transactionDateLong = payment.getTransactionDate();
LocalDate transactionDate = Instant.ofEpochMilli(transactionDateLong).atZone(ZoneId.systemDefault()).toLocalDate();
String transactionMonthAndYear = transactionDate.format(DateTimeFormatter.ofPattern("MMMM yyyy"));
if (ledgerReport.getDemand().getMonthAndYear().equals(transactionMonthAndYear)) {
if (ledgerReport.getDemand().getDemandGenerationDate().compareTo(transactionDateLong)<0 ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Potential logic error in payment matching condition

The condition ledgerReport.getDemand().getDemandGenerationDate().compareTo(transactionDateLong) < 0 on line 213 may incorrectly filter payments. Typically, you may want to include payments made on the same day (<= 0) or ensure the logic aligns with business requirements.

Apply this diff if the intention is to include payments made on the same day:

- if (ledgerReport.getDemand().getDemandGenerationDate().compareTo(transactionDateLong) < 0 ) {
+ if (ledgerReport.getDemand().getDemandGenerationDate().compareTo(transactionDateLong) <= 0 ) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (ledgerReport.getDemand().getDemandGenerationDate().compareTo(transactionDateLong)<0 ) {
if (ledgerReport.getDemand().getDemandGenerationDate().compareTo(transactionDateLong) <= 0 ) {

PaymentLedgerReport paymentLedgerReport = new PaymentLedgerReport();
paymentLedgerReport.setCollectionDate(transactionDateLong);
paymentLedgerReport.setReceiptNo(payment.getPaymentDetails().get(0).getReceiptNumber());
Expand Down Expand Up @@ -234,8 +245,193 @@ private void addPaymentToLedger(List<Map<String, Object>> monthlyRecordList) {
}
}

private BigDecimal getMonthlyTaxAmount(Long startDate, String consumerCode) {

private void addPaymentToLedgerChronlogicalOrder(List<Map<String, Object>> monthlyRecordList){
LedgerReport lastValidDemandReport = null;
monthlyRecordList.sort(new Comparator<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
String monthAndYear1 = (String) o1.keySet().iterator().next();
String monthAndYear2 = (String) o2.keySet().iterator().next();

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM yyyy", Locale.ENGLISH);
YearMonth yearMonth1 = YearMonth.parse(monthAndYear1, formatter);
YearMonth yearMonth2 = YearMonth.parse(monthAndYear2, formatter);

return yearMonth1.compareTo(yearMonth2);
}
});

for (int i = 0; i < monthlyRecordList.size(); i++) {
Map<String, Object> record = monthlyRecordList.get(i);
LedgerReport ledgerReport = (LedgerReport) record.values().iterator().next();

// Skip months where demandGenerationDate is 0 (invalid demands)
if (ledgerReport.getDemand() == null || ledgerReport.getDemand().getDemandGenerationDate() == 0) {
log.info("Skipping LedgerReport for invalid demand in LedgerReport: {}", ledgerReport);
PaymentLedgerReport defaultPaymentLedgerReport = new PaymentLedgerReport();
defaultPaymentLedgerReport.setCollectionDate(null);
defaultPaymentLedgerReport.setReceiptNo("N/A");
defaultPaymentLedgerReport.setPaid(BigDecimal.ZERO);
defaultPaymentLedgerReport.setBalanceLeft(ledgerReport.getDemand().getTotal_due_amount());

if (ledgerReport.getPayment() == null) {
ledgerReport.setPayment(new ArrayList<>());
}
ledgerReport.getPayment().add(defaultPaymentLedgerReport);
ledgerReport.setTotalBalanceLeftInMonth(BigDecimal.ZERO);
ledgerReport.setTotalPaymentInMonth(BigDecimal.ZERO);
continue;
}

String consumerCode = ledgerReport.getDemand().getConnectionNo();
log.info("Processing LedgerReport for Consumer code: " + consumerCode);
List<Payment> payments = addPaymentDetails(consumerCode);
boolean paymentMatched = false;
log.info("Payment:"+payments);
if (payments != null && !payments.isEmpty()) {
BigDecimal totalPaymentInMonth = BigDecimal.ZERO;
BigDecimal totalBalanceLeftInMonth = BigDecimal.ZERO;

// Get current demand's generation date
Long currentDemandDate = ledgerReport.getDemand().getDemandGenerationDate();

for (Payment payment : payments) {
Long transactionDateLong = payment.getTransactionDate();
Long nextMonthDemGenDateLong =getDemandGenerationDateOfNextMonth(monthlyRecordList, i);
log.info("nextMonthDemGenDateLong:"+nextMonthDemGenDateLong);
// Check if the payment date falls on or after the current demand's generation date
if (transactionDateLong >= currentDemandDate &&
(i + 1 == monthlyRecordList.size() || transactionDateLong < nextMonthDemGenDateLong )) {
Comment on lines +301 to +305
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle potential division by zero or null values

In the payment date checks, ensure that nextMonthDemGenDateLong is not zero to prevent logical errors. If nextMonthDemGenDateLong can be zero, additional checks are needed to handle that scenario appropriately.

Apply this diff to add a check for zero values:

if (transactionDateLong >= currentDemandDate &&
-     (i + 1 == monthlyRecordList.size() || transactionDateLong < nextMonthDemGenDateLong)) {
+     (i + 1 == monthlyRecordList.size() || (nextMonthDemGenDateLong != 0 && transactionDateLong < nextMonthDemGenDateLong))) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Long nextMonthDemGenDateLong =getDemandGenerationDateOfNextMonth(monthlyRecordList, i);
log.info("nextMonthDemGenDateLong:"+nextMonthDemGenDateLong);
// Check if the payment date falls on or after the current demand's generation date
if (transactionDateLong >= currentDemandDate &&
(i + 1 == monthlyRecordList.size() || transactionDateLong < nextMonthDemGenDateLong )) {
Long nextMonthDemGenDateLong =getDemandGenerationDateOfNextMonth(monthlyRecordList, i);
log.info("nextMonthDemGenDateLong:"+nextMonthDemGenDateLong);
// Check if the payment date falls on or after the current demand's generation date
if (transactionDateLong >= currentDemandDate &&
(i + 1 == monthlyRecordList.size() || (nextMonthDemGenDateLong != 0 && transactionDateLong < nextMonthDemGenDateLong))) {

LocalDate transactionDate = Instant.ofEpochMilli(transactionDateLong)
.atZone(ZoneId.systemDefault())
.toLocalDate();
log.info("settinng payment for month:"+ledgerReport.getDemand());
PaymentLedgerReport paymentLedgerReport = new PaymentLedgerReport();
paymentLedgerReport.setCollectionDate(transactionDateLong);
paymentLedgerReport.setReceiptNo(payment.getPaymentDetails().get(0).getReceiptNumber());
paymentLedgerReport.setPaid(payment.getTotalAmountPaid());
paymentLedgerReport.setBalanceLeft(payment.getTotalDue().subtract(paymentLedgerReport.getPaid()));

totalPaymentInMonth = totalPaymentInMonth.add(payment.getTotalAmountPaid());
totalBalanceLeftInMonth = totalBalanceLeftInMonth.add(payment.getTotalDue().subtract(payment.getTotalAmountPaid()));

if (ledgerReport.getPayment() == null) {
ledgerReport.setPayment(new ArrayList<>());
}
log.info("Payment for month:"+paymentLedgerReport);
ledgerReport.getPayment().add(paymentLedgerReport);
paymentMatched = true;
}
}

ledgerReport.setTotalBalanceLeftInMonth(ledgerReport.getDemand().getTotal_due_amount().subtract(totalPaymentInMonth));
ledgerReport.setTotalPaymentInMonth(totalPaymentInMonth);
}
// Keep track of the last valid demand (non-zero demandGenerationDate)
if (ledgerReport.getDemand().getDemandGenerationDate() != 0) {
log.info("Last Valid Demand monnth:"+ledgerReport.getDemand());
lastValidDemandReport = ledgerReport;
}
if (!paymentMatched ) {
// Add a default PaymentLedgerReport if no payments matched
log.info("If not matched:"+ledgerReport.getDemand().getMonthAndYear());
PaymentLedgerReport defaultPaymentLedgerReport = new PaymentLedgerReport();
defaultPaymentLedgerReport.setCollectionDate(null);
defaultPaymentLedgerReport.setReceiptNo("N/A");
defaultPaymentLedgerReport.setPaid(BigDecimal.ZERO);
defaultPaymentLedgerReport.setBalanceLeft(ledgerReport.getDemand().getTotal_due_amount());

if (ledgerReport.getPayment() == null) {
ledgerReport.setPayment(new ArrayList<>());
}
ledgerReport.getPayment().add(defaultPaymentLedgerReport);
}


}

// Handle payments for months with no valid demands
if (lastValidDemandReport != null) {
log.info("Last month logic:"+lastValidDemandReport);
// Assign payments to the last valid demand if found
List<Payment> payments = addPaymentDetails(lastValidDemandReport.getDemand().getConnectionNo());
BigDecimal totalPaymentInMonthlastValidMonth = BigDecimal.ZERO;
BigDecimal totalBalanceLeftInMonthLatValidMonth=BigDecimal.ZERO;
lastValidDemandReport.getPayment().clear();
boolean ifLastDemandHavePayments= false;

if (payments != null && !payments.isEmpty()) {

for (Payment payment : payments) {
Long transactionDateLong = payment.getTransactionDate();
if (transactionDateLong >= lastValidDemandReport.getDemand().getDemandGenerationDate()) {
PaymentLedgerReport paymentLedgerReport = new PaymentLedgerReport();
paymentLedgerReport.setCollectionDate(transactionDateLong);
paymentLedgerReport.setReceiptNo(payment.getPaymentDetails().get(0).getReceiptNumber());
paymentLedgerReport.setPaid(payment.getTotalAmountPaid());
paymentLedgerReport.setBalanceLeft(payment.getTotalDue().subtract(paymentLedgerReport.getPaid()));

lastValidDemandReport.getPayment().add(paymentLedgerReport);
totalPaymentInMonthlastValidMonth = totalPaymentInMonthlastValidMonth.add(payment.getTotalAmountPaid());
totalBalanceLeftInMonthLatValidMonth = totalBalanceLeftInMonthLatValidMonth.add(payment.getTotalDue().subtract(payment.getTotalAmountPaid()));
ifLastDemandHavePayments=true;
}
}
lastValidDemandReport.setTotalBalanceLeftInMonth(lastValidDemandReport.getDemand().getTotal_due_amount().subtract(totalPaymentInMonthlastValidMonth));
lastValidDemandReport.setTotalPaymentInMonth(totalPaymentInMonthlastValidMonth);

}
if(!ifLastDemandHavePayments){
// Add a default PaymentLedgerReport if no payments matched
log.info("If not matched:"+lastValidDemandReport.getDemand().getMonthAndYear());
PaymentLedgerReport defaultPaymentLedgerReport = new PaymentLedgerReport();
defaultPaymentLedgerReport.setCollectionDate(null);
defaultPaymentLedgerReport.setReceiptNo("N/A");
defaultPaymentLedgerReport.setPaid(BigDecimal.ZERO);
defaultPaymentLedgerReport.setBalanceLeft(lastValidDemandReport.getDemand().getTotal_due_amount());

if (lastValidDemandReport.getPayment() == null) {
lastValidDemandReport.setPayment(new ArrayList<>());
}
lastValidDemandReport.getPayment().add(defaultPaymentLedgerReport);
}
Comment on lines +385 to +398
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid code duplication when adding default payment ledger reports

The logic for adding a default PaymentLedgerReport when no payments are matched is repeated multiple times in the code. Consider extracting this logic into a separate method to adhere to the DRY (Don't Repeat Yourself) principle.

Apply this diff to create a helper method:

+ private void addDefaultPaymentLedgerReport(LedgerReport ledgerReport, BigDecimal totalDueAmount) {
+     PaymentLedgerReport defaultPaymentLedgerReport = new PaymentLedgerReport();
+     defaultPaymentLedgerReport.setCollectionDate(null);
+     defaultPaymentLedgerReport.setReceiptNo("N/A");
+     defaultPaymentLedgerReport.setPaid(BigDecimal.ZERO);
+     defaultPaymentLedgerReport.setBalanceLeft(totalDueAmount);
+     if (ledgerReport.getPayment() == null) {
+         ledgerReport.setPayment(new ArrayList<>());
+     }
+     ledgerReport.getPayment().add(defaultPaymentLedgerReport);
+ }

...

- // Existing code where default payment ledger report is added
- PaymentLedgerReport defaultPaymentLedgerReport = new PaymentLedgerReport();
- defaultPaymentLedgerReport.setCollectionDate(null);
- defaultPaymentLedgerReport.setReceiptNo("N/A");
- defaultPaymentLedgerReport.setPaid(BigDecimal.ZERO);
- defaultPaymentLedgerReport.setBalanceLeft(ledgerReport.getDemand().getTotal_due_amount());
- if (ledgerReport.getPayment() == null) {
-     ledgerReport.setPayment(new ArrayList<>());
- }
- ledgerReport.getPayment().add(defaultPaymentLedgerReport);
+ // Use the helper method
+ addDefaultPaymentLedgerReport(ledgerReport, ledgerReport.getDemand().getTotal_due_amount());

Committable suggestion was skipped due to low confidence.

}
}

/**
* This method retrieves the demand generation date for the next month in the ledger report.
* If the next month is beyond the list size, it returns 0 to indicate no demand for a future month.
*
* @param monthlyRecordList The list of monthly ledger records.
* @param currentIndex The index of the current month.
* @return The demand generation date of the next month or 0 if there is no next month.
*/
private Long getDemandGenerationDateOfNextMonth(List<Map<String, Object>> monthlyRecordList, int currentIndex) {
// Check if there is a next month in the list
if (currentIndex + 1 < monthlyRecordList.size()) {
// Get the next month's record
Map<String, Object> nextMonthRecord = monthlyRecordList.get(currentIndex + 1);

// Extract the LedgerReport object for the next month
LedgerReport nextMonthLedgerReport = (LedgerReport) nextMonthRecord.values().iterator().next();

// Return the demand generation date of the next month
if (nextMonthLedgerReport != null && nextMonthLedgerReport.getDemand() != null) {
return nextMonthLedgerReport.getDemand().getDemandGenerationDate();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle potential NullPointerException when accessing demand generation date

In the getDemandGenerationDateOfNextMonth method, ensure that getDemandGenerationDate() does not return null to prevent a NullPointerException.

Apply this diff to add a null check:

if (nextMonthLedgerReport != null && nextMonthLedgerReport.getDemand() != null) {
+     if (nextMonthLedgerReport.getDemand().getDemandGenerationDate() != null) {
          return nextMonthLedgerReport.getDemand().getDemandGenerationDate();
+     } else {
+         return 0L;
+     }
}

Committable suggestion was skipped due to low confidence.

}
}
// Return 0 if there is no next month or no valid demand for the next month
return 0L;
}
Comment on lines +248 to +426
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor the addPaymentToLedgerChronologicalOrder method for maintainability

The addPaymentToLedgerChronologicalOrder method is lengthy and complex, which can make it difficult to understand and maintain. Consider refactoring it into smaller, well-named helper methods to enhance readability.



private BigDecimal getMonthlyTaxAmount(Long startDate, String consumerCode,boolean paymentExists) {
StringBuilder taxAmountQuery = new StringBuilder(wsQueryBuilder.TAX_AMOUNT_QUERY);
if (paymentExists) {
// Exclude WS_ADVANCE_CARRYFORWARD if payments exist
taxAmountQuery.append(" AND taxheadcode != 'WS_ADVANCE_CARRYFORWARD'");
}
List<Object> taxAmountParams = new ArrayList<>();
taxAmountParams.add(consumerCode);
taxAmountParams.add(startDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,6 @@ sms.workflow.enabled: true
#ES-config
egov.indexer.es.username=elastic
egov.indexer.es.password=8fwbD6HbJh6HU0oddsHm8TEI

#ledger-report-format
report.in.chronological.order=true
Comment on lines +209 to +211
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Unutilized property report.in.chronological.order detected.

The property report.in.chronological.order=true is defined in application.properties and injected into WSConfiguration.java. However, it is not utilized anywhere within the codebase, which may indicate redundancy or an incomplete implementation.

Please consider the following actions:

  1. Remove the unused property if it is not required to avoid unnecessary configuration.
  2. Verify the intended use of this property to ensure that its implementation aligns with the project's objectives and to complete any pending functionality.
🔗 Analysis chain

Confirm the impact of enabling chronological ordering for ledger reports.

The addition of report.in.chronological.order=true is noted. This change appears to enable chronological ordering for ledger reports, which could affect how reports are generated and displayed in the application.

Please address the following points:

  1. Confirm that this change is intentional and aligns with the PR objectives.
  2. Verify the expected behavior of reports with this setting enabled.
  3. Update any relevant documentation or user guides to reflect this change in report ordering.
  4. Ensure thorough testing of affected reports to validate the impact of this change.

To help verify the impact of this change, you can run the following script to search for usage of this property in the codebase:

This will help identify where the property is being used and potentially affected areas of the code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of the new property in the codebase
rg --type java --type kotlin "report\.in\.chronological\.order"

Length of output: 315


Script:

#!/bin/bash
# Search for all usages of the 'report.in.chronological.order' property in Java and Kotlin files
rg --type java --type kotlin "report\.in\.chronological\.order"

Length of output: 315


Script:

#!/bin/bash
# Find the variable name injected with 'report.in.chronological.order' in WSConfiguration.java
grep -E '@Value\("\${report\.in\.chronological\.order}"\)' municipal-services/ws-services/src/main/java/org/egov/waterconnection/config/WSConfiguration.java

# Assuming the variable name is 'reportInChronologicalOrder', search for its usages within the file
rg 'reportInChronologicalOrder' municipal-services/ws-services/src/main/java/org/egov/waterconnection/config/WSConfiguration.java

Length of output: 332

Loading