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

Commit

Permalink
fixed date format in billReport,
Browse files Browse the repository at this point in the history
  • Loading branch information
rahuldevgarg committed Sep 4, 2023
1 parent d4e2913 commit fb05d96
Showing 1 changed file with 48 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
import java.time.Period;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
Expand All @@ -25,9 +19,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import javax.validation.Valid;
Expand All @@ -38,37 +30,20 @@
import org.egov.waterconnection.constants.WCConstants;
import org.egov.waterconnection.producer.WaterConnectionProducer;
import org.egov.waterconnection.repository.ElasticSearchRepository;
import org.egov.waterconnection.repository.WaterDao;
import org.egov.waterconnection.repository.WaterDaoImpl;
import org.egov.waterconnection.repository.WaterRepository;
import org.egov.waterconnection.util.WaterServicesUtil;
import org.egov.waterconnection.validator.ActionValidator;
import org.egov.waterconnection.validator.MDMSValidator;
import org.egov.waterconnection.validator.ValidateProperty;
import org.egov.waterconnection.validator.WaterConnectionValidator;
import org.egov.waterconnection.web.models.AuditDetails;
import org.egov.waterconnection.web.models.BillReportData;
import org.egov.waterconnection.web.models.BillReportResponse;
import org.egov.waterconnection.web.models.BillingCycle;
import org.egov.waterconnection.web.models.CheckList;
import org.egov.waterconnection.web.models.CollectionReportData;
import org.egov.waterconnection.web.models.*;
import org.egov.waterconnection.web.models.Connection.StatusEnum;
import org.egov.waterconnection.web.models.Feedback;
import org.egov.waterconnection.web.models.FeedbackRequest;
import org.egov.waterconnection.web.models.FeedbackSearchCriteria;
import org.egov.waterconnection.web.models.LastMonthSummary;
import org.egov.waterconnection.web.models.Property;
import org.egov.waterconnection.web.models.RevenueCollectionData;
import org.egov.waterconnection.web.models.RevenueDashboard;
import org.egov.waterconnection.web.models.SearchCriteria;
import org.egov.waterconnection.web.models.WaterConnection;
import org.egov.waterconnection.web.models.WaterConnectionRequest;
import org.egov.waterconnection.web.models.WaterConnectionResponse;
import org.egov.waterconnection.web.models.enums.Status;
import org.egov.waterconnection.web.models.workflow.BusinessService;
import org.egov.waterconnection.workflow.WorkflowIntegrator;
import org.egov.waterconnection.workflow.WorkflowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -122,8 +97,6 @@ public class WaterServiceImpl implements WaterService {
@Autowired
private CalculationService calculationService;

@Autowired
private WaterDaoImpl waterDaoImpl;

@Autowired
private UserService userService;
Expand All @@ -136,12 +109,12 @@ public class WaterServiceImpl implements WaterService {

@Autowired
private WaterRepository repository;

@Autowired
private ElasticSearchRepository elasticSearchRepository;

/**
*
*
* @param waterConnectionRequest WaterConnectionRequest contains water
* connection to be created
* @return List of WaterConnection after create
Expand Down Expand Up @@ -181,13 +154,13 @@ public List<WaterConnection> createWaterConnection(WaterConnectionRequest waterC

enrichmentService.postStatusEnrichment(waterConnectionRequest);
waterDaoImpl.saveWaterConnection(waterConnectionRequest);

if (null != waterConnectionRequest.getWaterConnection() && null != waterConnectionRequest.getWaterConnection().getPaymentType()
&& WCConstants.PAYMENT_TYPE_ARREARS.equalsIgnoreCase(waterConnectionRequest.getWaterConnection().getPaymentType())) {
&& WCConstants.PAYMENT_TYPE_ARREARS.equalsIgnoreCase(waterConnectionRequest.getWaterConnection().getPaymentType())) {
if ((waterConnectionRequest.getWaterConnection().getArrears() != null
&& waterConnectionRequest.getWaterConnection().getArrears().intValue() > 0)
|| (waterConnectionRequest.getWaterConnection().getPenalty() != null
&& waterConnectionRequest.getWaterConnection().getPenalty().intValue() > 0)) {
&& waterConnectionRequest.getWaterConnection().getPenalty().intValue() > 0)) {
calculationService.calculateFeeAndGenerateDemand(waterConnectionRequest, property, false);
}

Expand All @@ -197,14 +170,14 @@ public List<WaterConnection> createWaterConnection(WaterConnectionRequest waterC
calculationService.calculateFeeAndGenerateDemand(waterConnectionRequest, property, true);
}
}



return Arrays.asList(waterConnectionRequest.getWaterConnection());
}

/**
*
*
* @param criteria WaterConnectionSearchCriteria contains search criteria on
* water connection
* @param requestInfo
Expand All @@ -228,7 +201,7 @@ public WaterConnectionResponse search(SearchCriteria criteria, RequestInfo reque
}

/**
*
*
* @param criteria WaterConnectionSearchCriteria contains search criteria on
* water connection
* @param requestInfo
Expand All @@ -239,7 +212,7 @@ public WaterConnectionResponse getWaterConnectionsList(SearchCriteria criteria,
}

/**
*
*
* @param waterConnectionRequest WaterConnectionRequest contains water
* connection to be updated
* @return List of WaterConnection after update
Expand All @@ -258,7 +231,7 @@ public List<WaterConnection> updateWaterConnection(WaterConnectionRequest waterC
throw new CustomException("DUPLICATE_OLD_CONNECTION_NUMBER",
"Duplicate Old connection number");
}

mDMSValidator.validateMasterData(waterConnectionRequest, WCConstants.UPDATE_APPLICATION);
Property property = validateProperty.getOrValidateProperty(waterConnectionRequest);
validateProperty.validatePropertyFields(property, waterConnectionRequest.getRequestInfo());
Expand All @@ -278,12 +251,12 @@ public List<WaterConnection> updateWaterConnection(WaterConnectionRequest waterC
// wfIntegrator.callWorkFlow(waterConnectionRequest, property);
// call calculator service to generate the demand for one time fee
if (null != waterConnectionRequest.getWaterConnection() &&
null != waterConnectionRequest.getWaterConnection().getPaymentType() &&
WCConstants.PAYMENT_TYPE_ARREARS.equalsIgnoreCase(waterConnectionRequest.getWaterConnection().getPaymentType())) {
null != waterConnectionRequest.getWaterConnection().getPaymentType() &&
WCConstants.PAYMENT_TYPE_ARREARS.equalsIgnoreCase(waterConnectionRequest.getWaterConnection().getPaymentType())) {
if ((waterConnectionRequest.getWaterConnection().getArrears() != null
&& waterConnectionRequest.getWaterConnection().getArrears().intValue() > 0)
|| (waterConnectionRequest.getWaterConnection().getPenalty() != null
&& waterConnectionRequest.getWaterConnection().getPenalty().intValue() > 0)) {
&& waterConnectionRequest.getWaterConnection().getPenalty().intValue() > 0)) {
calculationService.calculateFeeAndGenerateDemand(waterConnectionRequest, property, false);
}
} else if (null != waterConnectionRequest.getWaterConnection() && null != waterConnectionRequest.getWaterConnection().getPaymentType() && WCConstants.PAYMENT_TYPE_ADVANCE.
Expand All @@ -292,7 +265,7 @@ public List<WaterConnection> updateWaterConnection(WaterConnectionRequest waterC
calculationService.calculateFeeAndGenerateDemand(waterConnectionRequest, property, true);
}
}

// check for edit and send edit notification
waterDaoImpl.pushForEditNotification(waterConnectionRequest);
// Enrich file store Id After payment
Expand All @@ -307,7 +280,7 @@ public List<WaterConnection> updateWaterConnection(WaterConnectionRequest waterC

/**
* Search Water connection to be update
*
*
* @param id
* @param requestInfo
* @return water connection
Expand All @@ -333,7 +306,7 @@ private List<WaterConnection> getAllWaterApplications(WaterConnectionRequest wat
WaterConnectionResponse waterConnection = search(criteria, waterConnectionRequest.getRequestInfo());
return waterConnection.getWaterConnection();
}

private List<WaterConnection> getWaterConnectionForOldConnectionNo(WaterConnectionRequest waterConnectionRequest) {
SearchCriteria criteria = SearchCriteria.builder().tenantId(waterConnectionRequest.getWaterConnection().getTenantId())
.oldConnectionNumber(waterConnectionRequest.getWaterConnection().getOldConnectionNo()).build();
Expand Down Expand Up @@ -370,7 +343,7 @@ private List<WaterConnection> updateWaterConnectionForModifyFlow(WaterConnection
if ((waterConnectionRequest.getWaterConnection().getArrears() != null
&& waterConnectionRequest.getWaterConnection().getArrears().intValue() > 0)
|| (waterConnectionRequest.getWaterConnection().getPenalty() != null
&& waterConnectionRequest.getWaterConnection().getPenalty().intValue() > 0)) {
&& waterConnectionRequest.getWaterConnection().getPenalty().intValue() > 0)) {
calculationService.calculateFeeAndGenerateDemand(waterConnectionRequest, property,false);
}

Expand All @@ -380,11 +353,11 @@ private List<WaterConnection> updateWaterConnectionForModifyFlow(WaterConnection
calculationService.calculateFeeAndGenerateDemand(waterConnectionRequest, property,true);
}
}

// wfIntegrator.callWorkFlow(waterConnectionRequest, property);
boolean isStateUpdatable = waterServiceUtil.getStatusForUpdate(businessService, previousApplicationStatus);
waterDaoImpl.updateWaterConnection(waterConnectionRequest, isStateUpdatable);

if(waterConnectionRequest.getWaterConnection().getStatus().equals(StatusEnum.INACTIVE)) {
waterConnectionRequest.getWaterConnection().setApplicationStatus("INACTIVE");
}
Expand Down Expand Up @@ -676,35 +649,35 @@ private void validateFuzzySearchCriteria(SearchCriteria criteria) {
&& org.apache.commons.lang3.StringUtils.isBlank(criteria.getMobileNumber()))
throw new CustomException("EG_WC_SEARCH_ERROR", " No criteria given for the water connection search");
}


private List<Map<String, Object>> wsDataResponse(Object esResponse) {

List<Map<String, Object>> data;
try {
data = JsonPath.read(esResponse, WCConstants.ES_DATA_PATH);
} catch (Exception e) {
throw new CustomException("PARSING_ERROR", "Failed to extract data from es response");
}
List<Map<String, Object>> data;
try {
data = JsonPath.read(esResponse, WCConstants.ES_DATA_PATH);
} catch (Exception e) {
throw new CustomException("PARSING_ERROR", "Failed to extract data from es response");
}

return data;
}

return data;
}

public WaterConnectionResponse planeSearch(SearchCriteria criteria, RequestInfo requestInfo) {
WaterConnectionResponse waterConnection = getWaterConnectionsListForPlaneSearch(criteria, requestInfo);
waterConnectionValidator.validatePropertyForConnection(waterConnection.getWaterConnection());
enrichmentService.enrichConnectionHolderDeatils(waterConnection.getWaterConnection(), criteria, requestInfo);
return waterConnection;
}

public WaterConnectionResponse getWaterConnectionsListForPlaneSearch(SearchCriteria criteria,
RequestInfo requestInfo) {
RequestInfo requestInfo) {
return waterDaoImpl.getWaterConnectionListForPlaneSearch(criteria, requestInfo);
}

@Override
public List<RevenueCollectionData> getRevenueCollectionData(@Valid SearchCriteria criteria,
RequestInfo requestInfo) {
RequestInfo requestInfo) {

long endDate = criteria.getToDate();
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Expand All @@ -714,25 +687,25 @@ public List<RevenueCollectionData> getRevenueCollectionData(@Valid SearchCriteri
Calendar currentDate = Calendar.getInstance();
int currentYear = currentDate.get(Calendar.YEAR);
int actualMonthnum = currentDate.get(Calendar.MONTH);

currentDate.setTimeInMillis(criteria.getFromDate());
int actualYear = currentDate.get(Calendar.YEAR);

int currentMonthNumber = currentDate.get(Calendar.MONTH);

int totalMonthsTillDate;
LocalDate finYearStarting;

if (currentYear != actualYear && actualYear < currentYear) {
totalMonthsTillDate = 11;
currentMonthDate = LocalDate.of(currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH) + 1,
currentDate.get(Calendar.DAY_OF_MONTH));
finYearStarting = currentMonthDate;
} else {
totalMonthsTillDate = actualMonthnum - currentMonthNumber;
currentMonthDate = LocalDate.of(currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH) + 1,
currentDate.get(Calendar.DAY_OF_MONTH));
finYearStarting = currentMonthDate;
totalMonthsTillDate = actualMonthnum - currentMonthNumber;
currentMonthDate = LocalDate.of(currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH) + 1,
currentDate.get(Calendar.DAY_OF_MONTH));
finYearStarting = currentMonthDate;

}
ArrayList<RevenueCollectionData> data = new ArrayList<RevenueCollectionData>();
Expand Down Expand Up @@ -824,22 +797,22 @@ public void postForMeterReading(WaterConnectionRequest waterConnectionrequest, i
}

@Override
public List<BillReportData> billReport(@Valid String demandStartDate,@Valid String demandEndDate, String tenantId, RequestInfo requestInfo) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/MM/yyyy");
public List<BillReportData> billReport(@Valid String demandStartDate, @Valid String demandEndDate, String tenantId, RequestInfo requestInfo) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
LocalDate demStartDate = LocalDate.parse(demandStartDate, formatter);
LocalDate demEndDate = LocalDate.parse(demandEndDate, formatter);

Long demStartDateTime = LocalDateTime.of(demStartDate.getYear(), demStartDate.getMonth(), demStartDate.getDayOfMonth(), 0, 0, 0)
.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
Long demEndDateTime = LocalDateTime.of(demEndDate,LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
Long demEndDateTime = LocalDateTime.of(demEndDate, LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
List<BillReportData> billReportData = waterDaoImpl.getBillReportData(demStartDateTime,demEndDateTime,tenantId);
return billReportData;
}

@Override
public List<CollectionReportData> collectionReport(String paymentStartDate, String paymentEndDate, String tenantId,
RequestInfo requestInfo) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/MM/yyyy");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
LocalDate payStartDate = LocalDate.parse(paymentStartDate, formatter);
LocalDate payEndDate = LocalDate.parse(paymentEndDate, formatter);

Expand All @@ -849,4 +822,4 @@ public List<CollectionReportData> collectionReport(String paymentStartDate, Stri
List<CollectionReportData> collectionReportData = waterDaoImpl.getCollectionReportData(payStartDateTime,payEndDateTime,tenantId);
return collectionReportData;
}
}
}

0 comments on commit fb05d96

Please sign in to comment.