Skip to content
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 @@ -64,7 +64,7 @@ List<WaterDetails> getConnectionsNoListforsingledemand(String tenantId, String l
public List<Canceldemandsearch> getConnectionCancels( String tenantId, String demandid);

public Boolean getUpdates(List demandlists);
public List<Map<String, Object>> getCollection(String tenatId,Long fromDate, Long toDate, String connectionno);
public List<Map<String, Object>> getCollection(String tenatId,Long fromDate, Long toDate, String connectionno,String businessService);


public List<BillSearchs> getBillss (String tenantId, String demandid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,9 @@ public List<Canceldemandsearch> getConnectionCancel(String businessService, Stri


@Override
public List<Map<String, Object>> getCollection(String tenantId, Long taxPeriodFrom, Long taxPeriodTo, String consumerCode) {
public List<Map<String, Object>> getCollection(String tenantId, Long taxPeriodFrom, Long taxPeriodTo, String consumerCode,String businessService) {
List<Object> preparedStatement = new ArrayList<>();
String query = queryBuilder.getCollection(tenantId, taxPeriodFrom, taxPeriodTo, consumerCode, preparedStatement);
String query = queryBuilder.getCollection(tenantId, taxPeriodFrom, taxPeriodTo, consumerCode,businessService, preparedStatement);

log.info("preparedStatement: {} | query: {}", preparedStatement, query);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ public String getCancelBill(String businessService, String tenantId, String cons



public String getCollection( String tenantId, Long taxperiodfrom,Long taxPeriodTo,String consumerCode,
public String getCollection( String tenantId, Long taxperiodfrom,Long taxPeriodTo,String consumerCode,String businessService,
List<Object> preparedStatement) {
StringBuilder query = new StringBuilder(getDemandId);

Expand All @@ -806,12 +806,22 @@ public String getCollection( String tenantId, Long taxperiodfrom,Long taxPerio
preparedStatement.add(consumerCode);


query.append("AND d.businessservice = 'WS' ");
addClauseIfRequired(preparedStatement, query);
query.append(" d.businessservice = ? ");
if (businessService == null || businessService.isEmpty() || "WS".equalsIgnoreCase(businessService)) {
preparedStatement.add("WS");
} else {
preparedStatement.add("SW");
}

// addClauseIfRequired(preparedStatement, query);
// query.append(" dd.collectionamount = '0' ");

addClauseIfRequired(preparedStatement, query);
query.append(" d.status = ? ");
preparedStatement.add("ACTIVE");

addClauseIfRequired(preparedStatement, query);
query.append(" d.ispaymentcompleted = 'false' ");

//Add taxperiodfrom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
@Slf4j
public class DemandService {

@Autowired
private WSCalculationDao wSCalculationDao;

@Autowired
private ServiceRequestRepository repository;

Expand Down Expand Up @@ -576,20 +579,6 @@ private List<Demand> createDemand(CalculationReq calculationReq, List<Calculatio
if (matchingUsages && relatedSwConn != null && !relatedSwConn.isEmpty()) {
// For the metered connections demand has to create one by one

List<Demand> existingSwDemands = searchDemandBasedOnConsumerCode(tenantId, relatedSwConn, requestInfo, "SW");
if (!CollectionUtils.isEmpty(existingSwDemands)) {
for (Demand existingSwDemand : existingSwDemands) {
if (StatusEnum.ACTIVE.equals(existingSwDemand.getStatus())) {
CancelDemandReq cancelDemandReq = new CancelDemandReq();
cancelDemandReq.setId(existingSwDemand.getId());
cancelDemandReq.setTenantId(tenantId);
cancelDemandReq.setConsumerCode(relatedSwConn);
cancelDemandReq.setBusinessService("SW");
dao.cancelPreviousMeterReading(cancelDemandReq);
}
}
}

if (WSCalculationConstant.meteredConnectionType.equalsIgnoreCase(connection.getConnectionType())) {
demandReq.addAll(demands);
businessServices = "SW";
Expand Down Expand Up @@ -2548,5 +2537,66 @@ public StringBuilder getDemandSearchURLForWS(
return url;
}

public void validateNoCollectionBeforeCancel(String connectionNo, String relatedSwConn, List<Map<String, Object>> demandList, List<Map<String, Object>> demandListSw) {
double waterCollected = 0.0;
double swCollected = 0.0;

if (demandList != null && !demandList.isEmpty()) {
for (Map<String, Object> row : demandList) {
Object obj = row.get("amountcollected");
waterCollected = obj != null ? Double.parseDouble(obj.toString()) : 0.0;
}
}

if (demandListSw != null && !demandListSw.isEmpty()) {
for (Map<String, Object> row : demandListSw) {
Object obj = row.get("amountcollected");
swCollected = obj != null ? Double.parseDouble(obj.toString()) : 0.0;
}
}

if (swCollected > 0) {
throw new CustomException("CANCEL_NOT_ALLOWED", "Cancel demand is not allowed for water related sewerage connection " + relatedSwConn + " as collectionamount > 0.");
}
}

public void cancelWaterAndRelatedSwDemand(String tenantId, String connectionNo, String relatedSwConn, List<Map<String, Object>> demandList, List<Map<String, Object>> demandListSw) {

if (demandList != null && !demandList.isEmpty()) {
for (Map<String, Object> row : demandList) {
String demandId = row.get("demandId") != null ? row.get("demandId").toString() : null;
if (demandId == null) {
continue;
}
CancelDemandReq cancelDemandReq = new CancelDemandReq();
cancelDemandReq.setId(demandId);
cancelDemandReq.setTenantId(tenantId);
cancelDemandReq.setConsumerCode(connectionNo);
cancelDemandReq.setBusinessService("WS");

log.info("Synchronously cancelling existing WS demand {} for consumer {}", demandId, connectionNo);

wSCalculationDao.cancelPreviousMeterReading(cancelDemandReq);
}
}

if (demandListSw != null && !demandListSw.isEmpty()) {
for (Map<String, Object> row : demandListSw) {
String demandIdSw = row.get("demandId") != null ? row.get("demandId").toString() : null;
if (demandIdSw == null) {
continue;
}
CancelDemandReq cancelSwDemandReq = new CancelDemandReq();
cancelSwDemandReq.setId(demandIdSw);
cancelSwDemandReq.setTenantId(tenantId);
cancelSwDemandReq.setConsumerCode(relatedSwConn);
cancelSwDemandReq.setBusinessService("SW");

log.info("Synchronously cancelling existing SW demand {} for consumer {}", demandIdSw, relatedSwConn);

wSCalculationDao.cancelPreviousMeterReading(cancelSwDemandReq);
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.egov.wscalculation.service;

import java.util.ArrayList;

import org.egov.tracer.model.CustomException;
import org.egov.wscalculation.validator.MDMSValidator;
import org.json.JSONArray;
import org.json.JSONObject;
Expand Down Expand Up @@ -39,6 +41,9 @@
@Component
public class MeterServicesImpl implements MeterService {

@Autowired
private DemandService demandService;

@Autowired
private WSCalculationDao wSCalculationDao;

Expand Down Expand Up @@ -191,29 +196,29 @@ public List<MeterReading> updateMeterReading(MeterConnectionRequest meterConnect
wsCalculationValidator.validateMeterReading(meterConnectionRequest, true);
}
enrichmentService.enrichMeterReadingRequest(meterConnectionRequest);
List<Map<String, Object>> demandList = wSCalculationDao.getCollection(
meterConnectionRequest.getMeterReading().getTenantId(),
meterConnectionRequest.getMeterReading().getLastReadingDate(),
meterConnectionRequest.getMeterReading().getCurrentReadingDate(),
meterConnectionRequest.getMeterReading().getConnectionNo()
);

if (demandList != null && !demandList.isEmpty()) {
for (Map<String, Object> row : demandList) {
String status = (String) row.get("status");
if ("ACTIVE".equalsIgnoreCase(status)) {
String demandId = (String) row.get("demandId");

CancelDemandReq cancelDemandReq = new CancelDemandReq();
cancelDemandReq.setId(demandId);
cancelDemandReq.setTenantId(meterConnectionRequest.getMeterReading().getTenantId());
cancelDemandReq.setConsumerCode(meterConnectionRequest.getMeterReading().getConnectionNo());
cancelDemandReq.setBusinessService("WS");

wSCalculationDao.cancelPreviousMeterReading(cancelDemandReq);
}
}
}
String tenantId = meterConnectionRequest.getMeterReading().getTenantId();
String connectionNo = meterConnectionRequest.getMeterReading().getConnectionNo();
Long lastReadingDate = meterConnectionRequest.getMeterReading().getLastReadingDate();
Long currentReadingDate = meterConnectionRequest.getMeterReading().getCurrentReadingDate();

// Fetch WS demand only once
List<Map<String, Object>> demandList = wSCalculationDao.getCollection(tenantId, lastReadingDate, currentReadingDate, connectionNo, "WS");

// Get related SW connection
String relatedSwConn = wSCalculationDao.getSwConnection(tenantId, connectionNo);

// Fetch SW demand only once
List<Map<String, Object>> demandListSw = null;
if (relatedSwConn != null && !relatedSwConn.isEmpty()) {
demandListSw = wSCalculationDao.getCollection(tenantId, lastReadingDate, currentReadingDate, relatedSwConn, "SW");
}
// Validate using the SAME fetched lists
demandService.validateNoCollectionBeforeCancel(connectionNo, relatedSwConn, demandList, demandListSw);

// Cancel using the SAME fetched lists
demandService.cancelWaterAndRelatedSwDemand(tenantId, connectionNo, relatedSwConn, demandList, demandListSw);

meterConnectionRequest.getMeterReading().setId(previousMeterReadingId);;
meterReadingsList.add(meterConnectionRequest.getMeterReading());
wSCalculationDao.updateMeterReading(meterConnectionRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void validateMeterReading(MeterConnectionRequest meterConnectionRequest,
criteria.getTenantId(),
meterConnectionRequest.getMeterReading().getLastReadingDate(),
meterConnectionRequest.getMeterReading().getCurrentReadingDate(),
meterConnectionRequest.getMeterReading().getConnectionNo());
meterConnectionRequest.getMeterReading().getConnectionNo(),null);

if (isAnythingPaid != null && !isAnythingPaid.isEmpty()) {
for (Map<String, Object> row : isAnythingPaid) {
Expand Down