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 #693 from egovernments/PFM-4082
Browse files Browse the repository at this point in the history
PFM-4082 Expense Bill Report
  • Loading branch information
pradeepkumarcm-egov authored Jan 10, 2024
2 parents 5b2ce17 + 0feeffb commit e80986e
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import org.egov.echallan.producer.Producer;
import org.egov.echallan.repository.builder.ChallanQueryBuilder;
import org.egov.echallan.repository.rowmapper.ChallanRowMapper;
import org.egov.echallan.repository.rowmapper.ExpenseBillReportRowMapper;
import org.egov.echallan.service.ChallanService;
import org.egov.echallan.util.CommonUtils;
import org.egov.echallan.web.models.ExpenseBillReportData;
import org.egov.echallan.web.models.collection.Bill;
import org.egov.echallan.web.models.collection.PaymentDetail;
import org.egov.echallan.web.models.collection.PaymentRequest;
Expand Down Expand Up @@ -63,7 +65,9 @@ public class ChallanRepository {
private ChallanQueryBuilder queryBuilder;

private ChallanRowMapper rowMapper;


private ExpenseBillReportRowMapper expenseBillReportRowMapper;

private RestTemplate restTemplate;

@Autowired
Expand All @@ -79,13 +83,14 @@ public class ChallanRepository {
private ObjectMapper mapper;
@Autowired
public ChallanRepository(Producer producer, ChallanConfiguration config,ChallanQueryBuilder queryBuilder,
JdbcTemplate jdbcTemplate,ChallanRowMapper rowMapper,RestTemplate restTemplate) {
JdbcTemplate jdbcTemplate,ChallanRowMapper rowMapper,RestTemplate restTemplate, ExpenseBillReportRowMapper expenseBillReportRowMapper) {
this.producer = producer;
this.config = config;
this.jdbcTemplate = jdbcTemplate;
this.queryBuilder = queryBuilder ;
this.rowMapper = rowMapper;
this.restTemplate = restTemplate;
this.expenseBillReportRowMapper = expenseBillReportRowMapper;
}


Expand Down Expand Up @@ -484,4 +489,40 @@ public List<String> fetchESIds(SearchCriteria criteria) {
new SingleColumnRowMapper<>(String.class));
return ids;
}

public List<ExpenseBillReportData> getExpenseBillReport(Long monthStartDateTime, Long monthEndDateTime, String tenantId, Integer offset, Integer limit)
{
StringBuilder expenseBillQuery =new StringBuilder(queryBuilder.EXPENSEBILLQUERY);

List<Object> preparedStatement=new ArrayList<>();
preparedStatement.add(tenantId);
preparedStatement.add(tenantId);
preparedStatement.add(monthStartDateTime);
preparedStatement.add(monthEndDateTime);

Integer newLimit=config.getDefaultLimit();
Integer newOffset=config.getDefaultOffset();

if(limit==null && offset==null)
newLimit=config.getMaxSearchLimit();
if(limit!=null && limit<=config.getMaxSearchLimit())
newLimit=limit;
if(limit!=null && limit>=config.getMaxSearchLimit())
newLimit=config.getMaxSearchLimit();

if(offset!=null)
newOffset=offset;

if(newLimit>0)
{
expenseBillQuery.append("offset ? limit ? ;");
preparedStatement.add(newOffset);
preparedStatement.add(newLimit);
}

log.info("Query of expense bill report " +expenseBillQuery.toString()+" prepared statement "+preparedStatement);
List<ExpenseBillReportData> expenseBillReportDataList=new ArrayList<>();
expenseBillReportDataList=jdbcTemplate.query(expenseBillQuery.toString(), preparedStatement.toArray(),expenseBillReportRowMapper);
return expenseBillReportDataList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,20 @@ public ChallanQueryBuilder(ChallanConfiguration config) {

public static final String PENDINGEXPCOLLTILLDATE = "SELECT coalesce(SUM(DMDL.TAXAMOUNT - DMDL.COLLECTIONAMOUNT),0) FROM EGBS_DEMAND_V1 DMD INNER JOIN EGBS_DEMANDDETAIL_V1 DMDL ON DMD.ID=DMDL.DEMANDID AND DMD.TENANTID=DMDL.TENANTID INNER JOIN EG_ECHALLAN CH ON CH.referenceId=DMD.CONSUMERCODE AND DMD.TENANTID=CH.TENANTID WHERE DMD.BUSINESSSERVICE LIKE '%EXPENSE%' and DMD.status='ACTIVE' ";


public String getChallanSearchQuery(SearchCriteria criteria, List<Object> preparedStmtList) {
public static final String EXPENSEBILLQUERY="SELECT challan.typeofexpense,vendor.name,challan.billdate, " +
" challan.taxperiodfrom,challan.taxperiodto,challan.applicationstatus, " +
" challan.paiddate,challan.filestoreid,challan.lastmodifiedtime, " +
" challan.lastmodifiedby as lastmodifiedbyUuid,SUM(dd.taxamount) as total_taxamount " +
" FROM eg_echallan challan LEFT JOIN eg_vendor vendor ON challan.vendor = vendor.id " +
" LEFT JOIN egbs_demand_v1 d ON challan.challanno = d.consumercode " +
" LEFT JOIN egbs_demanddetail_v1 dd ON d.id = dd.demandid WHERE " +
" challan.tenantid = ? AND dd.tenantid = ? " +
" AND challan.createdtime >= ? AND challan.createdtime <= ?" +
" GROUP BY challan.typeofexpense,vendor.name,challan.billdate,challan.taxperiodfrom, " +
" challan.taxperiodto,challan.applicationstatus,challan.paiddate,challan.filestoreid, " +
" challan.lastmodifiedtime,challan.lastmodifiedby ORDER BY challan.createdtime DESC ";

public String getChallanSearchQuery(SearchCriteria criteria, List<Object> preparedStmtList) {

StringBuilder builder = new StringBuilder(QUERY);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package org.egov.echallan.repository.rowmapper;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.egov.echallan.model.UserInfo;
import org.egov.echallan.service.UserService;
import org.egov.echallan.web.models.ExpenseBillReportData;
import org.egov.echallan.web.models.ExpenseBillReportResponse;
import org.egov.echallan.web.models.user.User;
import org.egov.echallan.web.models.user.UserDetailResponse;
import org.egov.echallan.web.models.user.UserSearchRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Component;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

@Component
@Slf4j
public class ExpenseBillReportRowMapper implements ResultSetExtractor<List<ExpenseBillReportData>>
{
@Autowired
private ObjectMapper mapper;

@Autowired
private UserService userService;

@Override
public List<ExpenseBillReportData> extractData(ResultSet resultSet) throws SQLException, DataAccessException {

List<ExpenseBillReportData> expenseBillReportDataList=new ArrayList<>();

while(resultSet.next())
{
ExpenseBillReportData expenseBillReportData=new ExpenseBillReportData();
expenseBillReportData.setTypeOfExpense(resultSet.getString("typeofexpense"));
expenseBillReportData.setVendorName(resultSet.getString("name"));
expenseBillReportData.setAmount(resultSet.getLong("total_taxamount"));
expenseBillReportData.setBillDate(resultSet.getLong("billdate"));
expenseBillReportData.setTaxPeriodFrom(resultSet.getLong("taxperiodfrom"));
expenseBillReportData.setTaxPeriodTo(resultSet.getLong("taxperiodto"));
expenseBillReportData.setApplicationStatus(resultSet.getString("applicationstatus"));

if(resultSet.getString("paiddate")!=null)
expenseBillReportData.setPaidDate(resultSet.getLong("paiddate"));
else
expenseBillReportData.setPaidDate(0L);
if(resultSet.getString("filestoreid")!=null)
expenseBillReportData.setFilestoreid("Yes");
else
expenseBillReportData.setFilestoreid("No");
if(Objects.equals(resultSet.getString("applicationstatus"), "CANCELLED")) {
expenseBillReportData.setLastModifiedTime(resultSet.getLong("lastmodifiedtime"));
expenseBillReportData.setLastModifiedByUuid(resultSet.getString("lastmodifiedbyUuid"));
enrichExpenseHolderDetails(expenseBillReportData);
}
else
{
expenseBillReportData.setLastModifiedTime(0L);
expenseBillReportData.setLastModifiedBy(null);
}
expenseBillReportDataList.add(expenseBillReportData);
}
return expenseBillReportDataList;
}

private void enrichExpenseHolderDetails(ExpenseBillReportData expenseBillReportData)
{
UserSearchRequest userSearchRequest=new UserSearchRequest();
userSearchRequest.setUuid(Collections.singletonList(expenseBillReportData.getLastModifiedByUuid()));
log.info("Uuid's for searching users"+userSearchRequest.getUuid().toString());

UserDetailResponse userDetailResponse=userService.getUsers(userSearchRequest);
log.info("User after searching"+userDetailResponse.getUser().toString());

enrichConnectionHolderInfo(userDetailResponse,expenseBillReportData);
}

private void enrichConnectionHolderInfo(UserDetailResponse userDetailResponse, ExpenseBillReportData expenseBillReportData)
{
List<UserInfo> connectionHolderInfos= userDetailResponse.getUser();
if (connectionHolderInfos.isEmpty()) {
return;
}
log.info("Users in enrichConnectionHolderInfo method"+connectionHolderInfos.toString());
expenseBillReportData.setLastModifiedBy(connectionHolderInfos.get(0).getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;

Expand All @@ -27,6 +24,7 @@
import org.egov.echallan.util.CommonUtils;
import org.egov.echallan.validator.ChallanValidator;
import org.egov.echallan.web.models.ChallanCollectionData;
import org.egov.echallan.web.models.ExpenseBillReportData;
import org.egov.echallan.web.models.ExpenseDashboard;
import org.egov.echallan.web.models.user.UserDetailResponse;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -377,5 +375,19 @@ public List<Challan> getChallansWithOwnerInfoForPlaneSearch(SearchCriteria crite
challans = enrichmentService.enrichChallanSearch(challans,criteria,requestInfo);
return challans;
}


public List<ExpenseBillReportData> expenseBillReport(RequestInfo requestInfo, String monthstartDate,String monthendDate, String tenantId, Integer offset, Integer limit)
{
DateTimeFormatter dtf=DateTimeFormatter.ofPattern("dd/MM/yyyy");
LocalDate startDate=LocalDate.parse(monthstartDate,dtf);
LocalDate endDate=LocalDate.parse(monthendDate,dtf);

Long monthStartDateTime=LocalDateTime.of(startDate.getYear(),startDate.getMonth(),startDate.getDayOfMonth(),
0,0,0).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
Long monthEndDateTime=LocalDateTime.of(endDate, LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();

List<ExpenseBillReportData> expenseBillReport=repository.getExpenseBillReport(monthStartDateTime,monthEndDateTime,tenantId,offset,limit);
return expenseBillReport;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,11 @@ public UserDetailResponse getUserById(RequestInfo requestInfo, String tenantId,
StringBuilder uri = new StringBuilder(userHost).append(userSearchEndpoint);
return userCall(userSearchRequest, uri);
}


public UserDetailResponse getUsers(UserSearchRequest userSearchRequest)
{
StringBuilder uri = new StringBuilder(userHost).append(userSearchEndpoint);
UserDetailResponse userDetailResponse = userCall(userSearchRequest, uri);
return userDetailResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,11 @@
import org.egov.echallan.service.ChallanService;
import org.egov.echallan.service.SchedulerService;
import org.egov.echallan.util.ResponseInfoFactory;
import org.egov.echallan.web.models.ChallanCollectionData;
import org.egov.echallan.web.models.ChallanCollectionDataResponse;
import org.egov.echallan.web.models.ExpenseDashboard;
import org.egov.echallan.web.models.ExpenseDashboardResponse;
import org.egov.echallan.web.models.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;


@RestController
Expand Down Expand Up @@ -171,5 +163,21 @@ public ResponseEntity<ChallanResponse> updateCreateoPayment(@Valid @RequestBody
return new ResponseEntity<>(response, HttpStatus.OK);
}

@PostMapping("/_expenseBillReport")
public ResponseEntity<ExpenseBillReportResponse> expenseBillReport(@Valid @RequestBody RequestInfoWrapper requestInfoWrapper,
@RequestParam("monthstartDate") String monthstartDate,
@RequestParam("monthendDate") String monthendDate,
@RequestParam("tenantId") String tenantId,
@RequestParam("offset") Integer offset,
@RequestParam("limit") Integer limit)
{
List<ExpenseBillReportData> expenseBillReport=challanService.expenseBillReport(requestInfoWrapper.getRequestInfo(),monthstartDate,monthendDate,tenantId,offset,limit);
ExpenseBillReportResponse expenseBillReportResponse=
ExpenseBillReportResponse.builder().ExpenseBillReportData(expenseBillReport)
.responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(requestInfoWrapper.getRequestInfo(),
true))
.build();
return new ResponseEntity<>(expenseBillReportResponse,HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.egov.echallan.web.models;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import org.egov.echallan.model.Amount;
import org.hibernate.validator.constraints.SafeHtml;

import java.util.List;

@Builder
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class ExpenseBillReportData
{
@JsonProperty("typeOfExpense")
private String typeOfExpense;

@JsonProperty("vendorName")
private String vendorName;

@JsonProperty("amount")
private Long amount;

@JsonProperty("billDate")
private Long billDate;

@JsonProperty("taxPeriodFrom")
private Long taxPeriodFrom;

@JsonProperty("taxPeriodTo")
private Long taxPeriodTo;

@JsonProperty("applicationStatus")
private String applicationStatus;

@JsonProperty("paidDate")
private Long paidDate;

@JsonProperty("filestoreid")
@SafeHtml
private String filestoreid;

@JsonProperty("lastModifiedTime")
private Long lastModifiedTime;

@JsonProperty("lastModifiedByUuid")
private String lastModifiedByUuid;

@JsonProperty("lastModifiedBy")
private String lastModifiedBy;

@JsonProperty("tenantId")
private String tenantId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.egov.echallan.web.models;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import org.apache.coyote.RequestInfo;
import org.egov.common.contract.response.ResponseInfo;

import java.util.List;


@Builder
public class ExpenseBillReportResponse {

@JsonProperty("ExpenseBillReportData")
private List<ExpenseBillReportData> ExpenseBillReportData;

@JsonProperty("responseInfo")
private ResponseInfo responseInfo = null;

}

0 comments on commit e80986e

Please sign in to comment.