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 #552 from egovernments/PFM-4518
Browse files Browse the repository at this point in the history
PFM 4518
  • Loading branch information
rahuldevgarg authored Sep 8, 2023
2 parents 45aa580 + dd3bca6 commit dc20c67
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,37 +522,83 @@ public BigDecimal getPenaltyCollectionAmount(@Valid SearchCriteria criteria) {
return jdbcTemplate.queryForObject(query.toString(), BigDecimal.class);
}

public List<BillReportData> getBillReportData(@Valid Long demandStartDate,@Valid Long demandEndDate, @Valid String tenantId) {
public List<BillReportData> getBillReportData(@Valid Long demandStartDate,@Valid Long demandEndDate, @Valid String tenantId, @Valid Integer offset, @Valid Integer limit, @Valid String sortOrder) {
StringBuilder query = new StringBuilder(wsQueryBuilder.BILL_REPORT_QUERY);
query.append("where dem.taxperiodfrom =" + demandStartDate);
query.append(" and dem.taxperiodto =" + demandEndDate);
List<Object> preparedStatement = new ArrayList<>();
preparedStatement.add(demandStartDate);
preparedStatement.add(demandEndDate);
preparedStatement.add(tenantId);

if(!tenantId.isEmpty()){
query.append(" and conn.tenantId ='"+tenantId+"'");
if(sortOrder.equals(SearchCriteria.SortOrder.DESC.name()))
query.append(" DESC ");
else
query.append(" ASC ");

Integer newlimit=wsConfiguration.getDefaultLimit();
Integer newoffset= wsConfiguration.getDefaultOffset();
if(limit==null && offset==null)
newlimit=wsConfiguration.getMaxLimit();
if(limit!=null && limit<=wsConfiguration.getMaxLimit())
newlimit=limit;
if(limit!=null && limit>=wsConfiguration.getMaxLimit())
newlimit=wsConfiguration.getMaxLimit();

if(offset!=null)
newoffset=offset;

if(newlimit > 0) {
query.append(" offset ? limit ? ;");
preparedStatement.add(newoffset);
preparedStatement.add(newlimit);
}
query.append(" group by conn.connectionno,conn.tenantId,dd.taxheadcode,conn.oldConnectionno,conn.createdTime,dd.taxamount,connectionholder.userid order by conn.connectionno,dd.taxheadcode");

List<BillReportData> billReportList = new ArrayList<>();
List<Object> preparedStatement = new ArrayList<>();
try {

billReportList = jdbcTemplate.query(query.toString(), preparedStatement.toArray(), reportRowMapper);
billReportList = jdbcTemplate.query(query.toString(), preparedStatement.toArray(), reportRowMapper);
}
catch(Exception e){
Map<String,String> ex = new HashMap<String,String>(){{
put("DataIntegrityViolationException","e");
}};
throw new CustomException(ex);
}
return billReportList;

}

public List<CollectionReportData> getCollectionReportData(Long payStartDateTime, Long payEndDateTime,
String tenantId) {
String tenantId,@Valid Integer offset, @Valid Integer limit, @Valid String sortOrder) {
StringBuilder query = new StringBuilder(wsQueryBuilder.COLLECTION_REPORT_QUERY);
query.append(" and pay.transactiondate between "+ payStartDateTime +"and " + payEndDateTime);

if(!tenantId.isEmpty()){
query.append(" and conn.tenantId ='"+tenantId+"'");
List<Object> preparedStatement = new ArrayList<>();
preparedStatement.add(payStartDateTime);
preparedStatement.add(payEndDateTime);
preparedStatement.add(tenantId);

if(sortOrder.equals(SearchCriteria.SortOrder.DESC.name()))
query.append(" DESC ");
else
query.append(" ASC ");

Integer newlimit=wsConfiguration.getDefaultLimit();
Integer newoffset= wsConfiguration.getDefaultOffset();
if(limit==null && offset==null)
newlimit=wsConfiguration.getMaxLimit();
if(limit!=null && limit<=wsConfiguration.getMaxLimit())
newlimit=limit;
if(limit!=null && limit>=wsConfiguration.getMaxLimit())
newlimit=wsConfiguration.getMaxLimit();

if(offset!=null)
newoffset=offset;

if (newlimit>0){
query.append(" offset ? limit ? ;");
preparedStatement.add(newoffset);
preparedStatement.add(newlimit);
}
query.append(" group by conn.connectionno,conn.tenantId,conn.oldConnectionno,connectionholder.userid,pd.amountpaid,pay.paymentmode");

List<CollectionReportData> collectionReportList = new ArrayList<>();
List<Object> preparedStatement = new ArrayList<>();

collectionReportList = jdbcTemplate.query(query.toString(), preparedStatement.toArray(), collectionReportRowMapper);
return collectionReportList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,26 @@ public class WsQueryBuilder {
public static final String DEMAND_DETAILS = "select d.consumercode from egbs_demand_v1 d join egbs_demanddetail_v1 dd on d.id = dd.demandid where d.status = 'ACTIVE' ";


public static final String BILL_REPORT_QUERY = "SELECT conn.tenantId as tenantId,dd.taxheadcode as demandType, conn.connectionno as connectionNo, conn.oldConnectionno as oldConnectionNo,"
+ " conn.createdTime as connCreatedDate,dd.taxamount as demandAmount,connectionholder.userid as uuid FROM eg_ws_connection conn "
+ INNER_JOIN_STRING + " eg_ws_connectionholder connectionholder ON connectionholder.connectionid = conn.id "
+ INNER_JOIN_STRING + " egbs_demand_v1 dem ON dem.consumercode=conn.connectionno "
+ INNER_JOIN_STRING + " egbs_demanddetail_v1 dd on dd.demandid=dem.id ";
public static final String BILL_REPORT_QUERY = "SELECT conn.tenantId as tenantId,conn.connectionno as connectionNo,conn.oldConnectionno as oldConnectionNo,conn.createdTime as connCreatedDate,"
+ " connectionholder.userid as uuid,SUM(CASE WHEN dd.taxheadcode = 'WS_TIME_PENALTY' THEN dd.taxamount ELSE 0 END) as WS_TIME_PENALTY_DemandAmount,"
+ " SUM(CASE WHEN dd.taxheadcode = '10101' THEN dd.taxamount ELSE 0 END) as A10101_DemandAmount,"
+ " SUM(CASE WHEN dd.taxheadcode = 'WS_ADVANCE_CARRYFORWARD' THEN dd.taxamount ELSE 0 END) as WS_ADVANCE_CARRYFORWARD_DemandAmount "
+ " FROM eg_ws_connection conn " + INNER_JOIN_STRING + " eg_ws_connectionholder connectionholder ON connectionholder.connectionid = conn.id "
+ INNER_JOIN_STRING + " egbs_demand_v1 dem ON dem.consumercode = conn.connectionno "
+ INNER_JOIN_STRING + " egbs_demanddetail_v1 dd on dd.demandid = dem.id WHERE dem.taxperiodfrom >= ? AND dem.taxperiodto <= ? "
+ " AND conn.tenantId = ? AND conn.status='Active' AND dem.status='ACTIVE' GROUP BY conn.connectionno,conn.tenantId,conn.oldConnectionno,conn.createdTime,connectionholder.userid ORDER BY conn.connectionno ";

public static final String COLLECTION_REPORT_QUERY = "SELECT conn.tenantId as tenantId, conn.connectionno as connectionNo, conn.oldConnectionno as oldConnectionNo,connectionholder.userid as uuid"
+ ",pd.amountpaid as amountpaid,pay.paymentmode as paymentmode FROM eg_ws_connection conn "
+ INNER_JOIN_STRING + " eg_ws_connectionholder connectionholder ON connectionholder.connectionid = conn.id "
+ INNER_JOIN_STRING + " egbs_billdetail_v1 bd on bd.consumercode=conn.connectionno "
+ INNER_JOIN_STRING + " egcl_paymentdetail pd on pd.billid=bd.billid "
+ INNER_JOIN_STRING + " egcl_payment pay on pay.id=pd.paymentid where conn.status='Active' ";
public static final String COLLECTION_REPORT_QUERY = "SELECT distinct conn.tenantId as tenantId,"
+ " conn.connectionno as connectionNo,conn.oldConnectionno as oldConnectionNo,"
+ " connectionholder.userid as uuid, SUM(pd.amountpaid) as totalAmountPaid,"
+ " pay.paymentmode as paymentmode FROM eg_ws_connection conn "
+ INNER_JOIN_STRING + "eg_ws_connectionholder connectionholder ON connectionholder.connectionid = conn.id "
+ INNER_JOIN_STRING + " egbs_billdetail_v1 bd on bd.consumercode = conn.connectionno "
+ INNER_JOIN_STRING + " egcl_paymentdetail pd on pd.billid = bd.billid"
+ INNER_JOIN_STRING + " egcl_payment pay on pay.id = pd.paymentid WHERE conn.status = 'Active' "
+ " AND pay.transactiondate BETWEEN ? AND ? AND conn.tenantId = ? "
+ " AND pay.paymentstatus!='CANCELLED' GROUP BY conn.tenantId,conn.connectionno,conn.oldConnectionno,"
+ " connectionholder.userid,pay.paymentmode ORDER BY conn.connectionno ";

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,30 @@ public class CollectionRowMapper implements ResultSetExtractor<List<CollectionRe
@Override
public List<CollectionReportData> extractData(ResultSet rs) throws SQLException, DataAccessException {
List<CollectionReportData> collectionReportDataList = new ArrayList<>();
CollectionReportData collectionReportData = new CollectionReportData();
Map<String, CollectionReportData> reportData = new HashMap<>();
// CollectionReportData collectionReportData = new CollectionReportData();
// Map<String, CollectionReportData> reportData = new HashMap<>();
while (rs.next()) {
if(reportData.get(rs.getString("connectionNo")) != null) {
setPayments(rs, collectionReportData, reportData);
}
else {
collectionReportData = new CollectionReportData();
List<BigDecimal> paymentAmounts = new ArrayList<>();
// if(reportData.get(rs.getString("connectionNo")) != null) {
// setPayments(rs, collectionReportData, reportData);
// }
// else {

CollectionReportData collectionReportData = new CollectionReportData();
// List<BigDecimal> paymentAmounts = new ArrayList<>();
collectionReportData.setTenantName(rs.getString("tenantId"));
collectionReportData.setConnectionNo(rs.getString("connectionNo"));
collectionReportData.setOldConnectionNo(rs.getString("oldConnectionNo"));
collectionReportData.setUserId(rs.getString("uuid"));
collectionReportData.setPaymentMode(rs.getString("paymentmode"));
paymentAmounts.add(rs.getBigDecimal("amountpaid"));
collectionReportData.setPaymentAmount(paymentAmounts);
reportData.put(rs.getString("connectionNo"), collectionReportData);

}
// paymentAmounts.add(rs.getBigDecimal("amountpaid"));
collectionReportData.setPaymentAmount(rs.getBigDecimal("amountpaid"));
// collectionReportData.getPaymentAmount().add(rs.getBigDecimal("amountpaid"));
collectionReportDataList.add(collectionReportData);
// }

}
List<CollectionReportData> listOfValues = reportData.values().stream().collect( Collectors.toCollection(ArrayList::new));
collectionReportDataList.addAll(listOfValues);
// List<CollectionReportData> listOfValues = reportData.values().stream().collect( Collectors.toCollection(ArrayList::new));
// collectionReportDataList.addAll(listOfValues);
if(!collectionReportDataList.isEmpty()){
enrichConnectionHolderDetails(collectionReportDataList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,25 @@ public class ReportRowMapper implements ResultSetExtractor<List<BillReportData>>
@Override
public List<BillReportData> extractData(ResultSet rs) throws SQLException, DataAccessException {
List<BillReportData> billReportDataList = new ArrayList<>();
BillReportData billReportData = new BillReportData();
Map<String, BillReportData> reportData = new HashMap<>();
// BillReportData billReportData = new BillReportData();
// Map<String, BillReportData> reportData = new HashMap<>();
while (rs.next()) {
if(reportData.get(rs.getString("connectionNo")) != null) {
setDemandTypeValue(rs, billReportData, reportData);
}
else {
billReportData = new BillReportData();
BillReportData billReportData = new BillReportData();

billReportData.setTenantName(rs.getString("tenantId"));
billReportData.setConnectionNo(rs.getString("connectionNo"));
billReportData.setOldConnectionNo(rs.getString("oldConnectionNo"));
billReportData.setUserId(rs.getString("uuid"));
billReportData.setConsumerCreatedOnDate(rs.getString("connCreatedDate"));

setDemandTypeValue(rs, billReportData, reportData);

billReportData.setDemandAmount(rs.getBigDecimal("A10101_DemandAmount"));
billReportData.setPenalty(rs.getBigDecimal("WS_TIME_PENALTY_DemandAmount"));
billReportData.setAdvance(rs.getBigDecimal("WS_ADVANCE_CARRYFORWARD_DemandAmount"));
billReportDataList.add(billReportData);
// setDemandTypeValue(rs, billReportData, reportData);
}

}
List<BillReportData> listOfValues = reportData.values().stream().collect( Collectors.toCollection(ArrayList::new));
billReportDataList.addAll(listOfValues);

// List<BillReportData> listOfValues = reportData.values().stream().collect( Collectors.toCollection(ArrayList::new));
// billReportDataList.addAll(listOfValues);
if(!billReportDataList.isEmpty()){
enrichConnectionHolderDetails(billReportDataList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public interface WaterService {

List<RevenueCollectionData> getRevenueCollectionData(@Valid SearchCriteria criteria, RequestInfo requestInfo);

List<BillReportData> billReport(@Valid String demandStartDate,@Valid String demandEndDate, @Valid String tenantId, RequestInfo requestInfo);
List<BillReportData> billReport(@Valid String demandStartDate, @Valid String demandEndDate, @Valid String tenantId, @Valid Integer offset, @Valid Integer limit, @Valid String sortOrder, RequestInfo requestInfo);

List<CollectionReportData> collectionReport(String paymentStartDate, String paymentEndDate, String tenantId,
List<CollectionReportData> collectionReport(String paymentStartDate, String paymentEndDate, String tenantId,@Valid Integer offset, @Valid Integer limit, @Valid String sortOrder,
RequestInfo requestInfo);

}
Original file line number Diff line number Diff line change
Expand Up @@ -797,20 +797,20 @@ public void postForMeterReading(WaterConnectionRequest waterConnectionrequest, i
}

@Override
public List<BillReportData> billReport(@Valid String demandStartDate, @Valid String demandEndDate, String tenantId, RequestInfo requestInfo) {
public List<BillReportData> billReport(@Valid String demandStartDate, @Valid String demandEndDate, String tenantId, @Valid Integer offset, @Valid Integer limit, @Valid String sortOrder, 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();
List<BillReportData> billReportData = waterDaoImpl.getBillReportData(demStartDateTime,demEndDateTime,tenantId);
List<BillReportData> billReportData = waterDaoImpl.getBillReportData(demStartDateTime,demEndDateTime,tenantId,offset,limit,sortOrder);
return billReportData;
}

@Override
public List<CollectionReportData> collectionReport(String paymentStartDate, String paymentEndDate, String tenantId,
public List<CollectionReportData> collectionReport(String paymentStartDate, String paymentEndDate, String tenantId,@Valid Integer offset, @Valid Integer limit, @Valid String sortOrder,
RequestInfo requestInfo) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
LocalDate payStartDate = LocalDate.parse(paymentStartDate, formatter);
Expand All @@ -819,7 +819,7 @@ public List<CollectionReportData> collectionReport(String paymentStartDate, Stri
Long payStartDateTime = LocalDateTime.of(payStartDate.getYear(), payStartDate.getMonth(), payStartDate.getDayOfMonth(), 0, 0, 0)
.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
Long payEndDateTime = LocalDateTime.of(payEndDate,LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
List<CollectionReportData> collectionReportData = waterDaoImpl.getCollectionReportData(payStartDateTime,payEndDateTime,tenantId);
List<CollectionReportData> collectionReportData = waterDaoImpl.getCollectionReportData(payStartDateTime,payEndDateTime,tenantId,offset,limit,sortOrder);
return collectionReportData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ public ResponseEntity<RevenueCollectionDataResponse> _revenueCollectionData(

@RequestMapping(value = "/_billReport", method = RequestMethod.POST)
public ResponseEntity<BillReportResponse> billReport(@Valid @RequestBody RequestInfoWrapper requestInfoWrapper,
@RequestParam(value = "demandStartDate", required = true) String demandStartDate,@RequestParam(value = "demandEndDate", required = true) String demandEndDate,@RequestParam(value = "tenantId",required = true) String tenantId) {
List<BillReportData> billReport = waterService.billReport(demandStartDate,demandEndDate,tenantId,
requestInfoWrapper.getRequestInfo());
@RequestParam(value = "demandStartDate", required = true) String demandStartDate,@RequestParam(value = "demandEndDate", required = true) String demandEndDate,@RequestParam(value = "tenantId",required = true) String tenantId,@RequestParam(value="offset",required = true) Integer offset,@RequestParam(value="limit",required = true)Integer limit,@RequestParam(value="sortOrder") String sortOrder) {
List<BillReportData> billReport = waterService.billReport(demandStartDate,demandEndDate,tenantId,offset,limit,sortOrder,requestInfoWrapper.getRequestInfo());

BillReportResponse response = BillReportResponse.builder().BillReportData(billReport)
.responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(requestInfoWrapper.getRequestInfo(),
Expand All @@ -210,9 +209,8 @@ public ResponseEntity<BillReportResponse> billReport(@Valid @RequestBody Request

@RequestMapping(value = "/_collectionReport", method = RequestMethod.POST)
public ResponseEntity<CollectionReportResponse> collectionReport(@Valid @RequestBody RequestInfoWrapper requestInfoWrapper,
@RequestParam(value = "paymentStartDate", required = true) String paymentStartDate,@RequestParam(value = "paymentEndDate", required = true) String paymentEndDate,@RequestParam(value = "tenantId",required = true) String tenantId) {
List<CollectionReportData> collectionReport = waterService.collectionReport(paymentStartDate,paymentEndDate,tenantId,
requestInfoWrapper.getRequestInfo());
@RequestParam(value = "paymentStartDate", required = true) String paymentStartDate,@RequestParam(value = "paymentEndDate", required = true) String paymentEndDate,@RequestParam(value = "tenantId",required = true) String tenantId, @RequestParam(value="offset",required = true) Integer offset, @RequestParam(value="limit",required = true)Integer limit, @RequestParam(value="sortOrder") String sortOrder) {
List<CollectionReportData> collectionReport = waterService.collectionReport(paymentStartDate,paymentEndDate,tenantId,offset,limit,sortOrder,requestInfoWrapper.getRequestInfo());

CollectionReportResponse response = CollectionReportResponse.builder().CollectionReportData(collectionReport)
.responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(requestInfoWrapper.getRequestInfo(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ public class CollectionReportData {
private String paymentMode = null;

@JsonProperty("paymentAmount")
private List<BigDecimal> paymentAmount = null;
private BigDecimal paymentAmount = null;
}

0 comments on commit dc20c67

Please sign in to comment.