Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #815

Merged
merged 26 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
adee4f3
ISTE-159 - progress - changes
Hari-egov May 29, 2024
645cd99
Owners
Hari-egov May 29, 2024
26f5665
Duplicate bill changes
Taniya-eGov May 29, 2024
3c97434
updated BillRepositoryV2
Taniya-eGov May 30, 2024
5a5a22b
ISTE - 159 changes
Hari-egov May 31, 2024
5928845
ISTE-39 and ISTE 159
Hari-egov Jun 7, 2024
cdc5b77
ISTE 159 & ISTE 39 FIX
Hari-egov Jun 7, 2024
6721992
Merge branch 'master' of https://github.com/egovernments/punjab-mgram…
Hari-egov Jun 7, 2024
27a36d1
ISTE 159,39 UAT Build
Hari-egov Jun 7, 2024
2942721
Meter Connection disable removed
Hari-egov Jun 7, 2024
0d997a6
ISTE-44-pending issue: added chnages asked by anniket for bill genrat…
Jun 11, 2024
b4e6559
updated application.properties
Taniya-eGov Jun 12, 2024
64f9ab6
Merge branch 'develop' into ISTE-41-billing
Taniya-eGov Jun 12, 2024
2c9ef9d
ISTE-173-FIX
Hari-egov Jun 12, 2024
c6b30bc
ISTE-173 FIX -2
Hari-egov Jun 12, 2024
fd4ca00
ISTE -159,39 Changes requested by Naveen
Hari-egov Jun 12, 2024
ec48fd2
Merge pull request #800 from egovernments/ISTE-41-billing
pradeepkumarcm-egov Jun 12, 2024
0b31f54
Merge branch 'develop' of https://github.com/egovernments/punjab-mgra…
Hari-egov Jun 12, 2024
3b01e83
Merge branch 'ISTE-159-39' of https://github.com/egovernments/punjab-…
Hari-egov Jun 12, 2024
230f137
CHANGES ISTE-173 - Commented Changes Done
Hari-egov Jun 13, 2024
0749c5d
Merge pull request #812 from egovernments/ISTE-173-BUILD
pradeepkumarcm-egov Jun 13, 2024
9ab94c2
Merge pull request #809 from egovernments/ISTE-44-pendingIssuesFix
pradeepkumarcm-egov Jun 14, 2024
2e6945a
Remarks Localization Changes
Hari-egov Jun 14, 2024
511cb08
Merge pull request #814 from egovernments/ISTE-173-Check
pradeepkumarcm-egov Jun 14, 2024
e8c6b0f
Added chnages for penalty
Jun 14, 2024
1d8c2ae
Merge pull request #816 from egovernments/RoundOffPenalty
debasishchakraborty-egovt Jun 14, 2024
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 @@ -28,6 +28,9 @@ public class BillV2 {
@Size(max = 256)
private String id;

@JsonProperty("userId")
private String userId;

Comment on lines +31 to +33
Copy link

Choose a reason for hiding this comment

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

The addition of userId is aligned with the backend changes mentioned. Consider adding validation annotations (e.g., @Size, @NotNull) if applicable, depending on the expected constraints for userId.

@JsonProperty("mobileNumber")
@Pattern(regexp = "^[0-9]{10}$", message = "MobileNumber should be 10 digit number")
private String mobileNumber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public void setValues(PreparedStatement ps, int index) throws SQLException {
AuditDetails auditDetails = bill.getAuditDetails();

ps.setString(1, bill.getId());
ps.setString(15, bill.getUserId());
ps.setString(16, bill.getConsumerCode());
Comment on lines +72 to +73
Copy link

Choose a reason for hiding this comment

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

Ensure correct parameter ordering in the prepared statement for userId and consumerCode.

The order of parameters userId and consumerCode in the prepared statement seems incorrect. They should match the order of fields in the INSERT_BILL_QUERY defined in BillQueryBuilder.java. Please verify and adjust accordingly.

ps.setString(2, bill.getTenantId());
ps.setString(3, bill.getPayerName());
ps.setString(4, bill.getPayerAddress());
Expand All @@ -82,8 +84,8 @@ public void setValues(PreparedStatement ps, int index) throws SQLException {
ps.setString(12, bill.getMobileNumber());
ps.setString(13, bill.getStatus().toString());
ps.setObject(14, util.getPGObject(bill.getAdditionalDetails()));
ps.setString(15, bill.getConsumerCode());
ps.setString(16, bill.getTenantId());
// ps.setString(15, bill.getConsumerCode());
// ps.setString(16, bill.getTenantId());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ public class BillQueryBuilder {
public static final String BILL_STATUS_UPDATE_BASE_QUERY = "UPDATE egbs_bill_v1 SET status=?, lastmodifieddate=? {replace} WHERE status='ACTIVE' AND tenantId = ? ";

public static final String INSERT_BILL_QUERY = "INSERT into egbs_bill_v1 "
+ " (id, tenantid, payername, payeraddress, payeremail, isactive, iscancelled, createdby, createddate, lastmodifiedby, lastmodifieddate, mobilenumber, status, additionaldetails)"
+ " SELECT ?,?,?,?,?,?,?,?,?,?,?,?,?,? "
+ " WHERE NOT EXISTS (SELECT distinct(consumercode) FROM egbs_bill_v1 bill INNER JOIN egbs_billdetail_v1 billd ON bill.id=billd.billid "
+ " WHERE status = 'ACTIVE' AND consumerCode = ? AND bill.tenantid = ?)";
+"(id, tenantid, payername, payeraddress, payeremail, isactive, iscancelled, createdby, createddate, lastmodifiedby, lastmodifieddate,"
+" mobilenumber, status, additionaldetails, payerid, consumercode)"
+"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";


public static final String INSERT_BILLDETAILS_QUERY = "INSERT into egbs_billdetail_v1 "
Expand All @@ -49,7 +48,7 @@ public class BillQueryBuilder {
+ " INNER JOIN (SELECT bd_consumercode, min(b_createddate) as mindate FROM billresult GROUP BY bd_consumercode) as uniqbill"
+ " ON uniqbill.bd_consumercode=billresult.bd_consumercode AND uniqbill.mindate=billresult.b_createddate ";

public static final String BILL_BASE_QUERY = "SELECT b.id AS b_id,b.mobilenumber, b.tenantid AS b_tenantid,"
public static final String BILL_BASE_QUERY = "SELECT b.id AS b_id,b.mobilenumber, b.tenantid AS b_tenantid,b.payerid AS b_payerid,"
+ " b.payername AS b_payername, b.payeraddress AS b_payeraddress, b.payeremail AS b_payeremail,b.filestoreid AS b_fileStoreId,"
+ " b.isactive AS b_isactive, b.iscancelled AS b_iscancelled, b.createdby AS b_createdby, b.status as b_status,"
+ " b.createddate AS b_createddate, b.lastmodifiedby AS b_lastmodifiedby, b.lastmodifieddate AS b_lastmodifieddate,"
Expand Down Expand Up @@ -82,9 +81,9 @@ public String getBillQuery(BillSearchCriteria billSearchCriteria, List<Object> p
}
addWhereClause(billQuery, preparedStatementValues, billSearchCriteria);

if(billSearchCriteria!=null && billSearchCriteria.getReturnAllBills()) {
return billQuery.toString();
}
// if(billSearchCriteria!=null && billSearchCriteria.getReturnAllBills()) {
// return billQuery.toString();
// }
Comment on lines +84 to +86
Copy link

Choose a reason for hiding this comment

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

Commented out conditional return statement.

The conditional return statement in getBillQuery has been commented out. If this logic is no longer needed, it should be removed to avoid confusion. Otherwise, please clarify the reason for its retention.

StringBuilder maxQuery = addPagingClause(billQuery, preparedStatementValues, billSearchCriteria);

return maxQuery.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public List<BillV2> extractData(ResultSet rs) throws SQLException {
.id(billId)
.totalAmount(BigDecimal.ZERO)
.tenantId(rs.getString("b_tenantid"))
.userId(rs.getString("b_payerid"))
.payerName(rs.getString("b_payername"))
.payerAddress(rs.getString("b_payeraddress"))
.payerEmail(rs.getString("b_payeremail"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Copy link

Choose a reason for hiding this comment

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

Importing java.util.stream.Stream seems unnecessary as there is no visible usage of streams that would necessitate this import in the provided code.

Please verify if the Stream import is used elsewhere in the file. If not, consider removing it to clean up unused imports.


import org.egov.common.contract.request.RequestInfo;
import org.egov.demand.config.ApplicationProperties;
Expand Down Expand Up @@ -99,6 +100,10 @@
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.egov.demand.producer.Producer;
import org.egov.demand.web.contract.UserResponse;
import org.egov.demand.web.contract.UserSearchRequest;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -138,9 +143,20 @@ public class BillServicev2 {

@Autowired
private BillValidator billValidator;

@Autowired
private Producer producer;

@Autowired
private ObjectMapper mapper;

@Value("${kafka.topics.cancel.bill.topic.name}")
private String billCancelTopic;

@Value("${kafka.topics.billgen.topic.name}")
private String notifTopicName;

private static List<String> ownerPlainRequestFieldsList;

/**
* Cancell bill operation can be carried by this method, based on consumerCodes
Expand All @@ -154,6 +170,7 @@ public class BillServicev2 {
public Integer cancelBill(UpdateBillRequest updateBillRequest) {

UpdateBillCriteria cancelBillCriteria = updateBillRequest.getUpdateBillCriteria();
billValidator.validateBillSearchRequest(cancelBillCriteria);
Set<String> consumerCodes = cancelBillCriteria.getConsumerCodes();
cancelBillCriteria.setStatusToBeUpdated(BillStatus.CANCELLED);

Expand All @@ -162,10 +179,31 @@ public Integer cancelBill(UpdateBillRequest updateBillRequest) {
throw new CustomException("EG_BS_CANCEL_BILL_ERROR", "Only one consumer code can be provided in the Cancel request");
} else {

return billRepository.updateBillStatus(cancelBillCriteria);
int result = billRepository.updateBillStatus(cancelBillCriteria);
sendNotificationForBillCancellation(updateBillRequest.getRequestInfo(), cancelBillCriteria);
return result;
}
}

private void sendNotificationForBillCancellation(RequestInfo requestInfo, UpdateBillCriteria cancelBillCriteria) {
Set<String> consumerCodes = cancelBillCriteria.getConsumerCodes();
if(CollectionUtils.isEmpty(consumerCodes))
return;

List<BillV2> bills = billRepository.findBill(BillSearchCriteria.builder()
.service(cancelBillCriteria.getBusinessService())
.tenantId(cancelBillCriteria.getTenantId())
.consumerCode(consumerCodes)
.build());

if (CollectionUtils.isEmpty(bills))
return;

BillRequestV2 req = BillRequestV2.builder().bills(bills).requestInfo(requestInfo).build();
producer.push(billCancelTopic, req);

}

/**
* Fetches the bill for given parameters
*
Expand Down Expand Up @@ -428,6 +466,7 @@ private List<BillV2> prepareBill(List<Demand> demands, RequestInfo requestInfo)
.status(BillStatus.ACTIVE)
.billDetails(billDetails)
.totalAmount(billAmount)
.userId(payer.getUuid())
.billNumber(billNumber)
.tenantId(tenantId)
.id(billId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri
Integer rate = (Integer) paymentMasterData.get("rate");
String penaltyType = String.valueOf(paymentMasterData.get("type"));
totalApplicablePenalty = currentmonthBill.multiply(new BigDecimal(rate).divide(new BigDecimal(100)));
totalApplicablePenalty = totalApplicablePenalty.setScale(0, RoundingMode.CEILING);
totalApplicablePenalty = totalApplicablePenalty.setScale(0, RoundingMode.HALF_UP);
} else {
log.info("MDMS data is Null Penalty not connfigured");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,21 @@ private Constants() {}

public static final String COUNT_REPLACE_CANCEL_BILL_MSG = "{count}";


// Bill cancel

public static final String CANCELLATION_REASON_MSG= "reasonMessage";

public static final String CANCELLATION_REASON_CODE= "reason";

public static final String CANCELL_REASON_MSG_NOT_FOUND = "EG_BS_CANCELL_REASON_MSG_NOT";
public static final String CANCELL_REASON_MSG_NOT_FOUND_MSG = "Cancell Reason message with key " + "'" + CANCELLATION_REASON_MSG + "'" + " is madnatory Text field in additionalDetails of Bill cancell Request";
public static final String CANCELL_REASON_MSG_EMPTY_MSG = "Cancell Reason message cannot be empty";

public static final String CANCELL_REASON_CODE_NOT_FOUND = "EG_BS_CANCELL_REASON_CODE_NOT";
public static final String CANCELL_REASON_CODE_NOT_FOUND_MSG = "Cancellation Reason with key " + "'" + CANCELLATION_REASON_CODE + "'" + " is a madnatory Text field in additionalDetails of Bill cancell Request";
public static final String CANCELL_REASON_CODE_EMPTY_MSG = "Cancell Reason code cannot be empty";
Comment on lines +178 to +188
Copy link

Choose a reason for hiding this comment

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

Ensure spelling and grammar in exception messages.

- public static final String CANCELL_REASON_MSG_NOT_FOUND_MSG = "Cancell Reason message with key " + "'" + CANCELLATION_REASON_MSG + "'" + " is madnatory Text field in additionalDetails of Bill cancell Request";
+ public static final String CANCELL_REASON_MSG_NOT_FOUND_MSG = "Cancellation Reason message with key " + "'" + CANCELLATION_REASON_MSG + "'" + " is a mandatory Text field in additionalDetails of Bill cancellation Request";

- public static final String CANCELL_REASON_CODE_NOT_FOUND_MSG = "Cancellation Reason with key " + "'" + CANCELLATION_REASON_CODE + "'" + " is a madnatory Text field in additionalDetails of Bill cancell Request";
+ public static final String CANCELL_REASON_CODE_NOT_FOUND_MSG = "Cancellation Reason with key " + "'" + CANCELLATION_REASON_CODE + "'" + " is a mandatory Text field in additionalDetails of Bill cancellation Request";
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
public static final String CANCELLATION_REASON_MSG= "reasonMessage";
public static final String CANCELLATION_REASON_CODE= "reason";
public static final String CANCELL_REASON_MSG_NOT_FOUND = "EG_BS_CANCELL_REASON_MSG_NOT";
public static final String CANCELL_REASON_MSG_NOT_FOUND_MSG = "Cancell Reason message with key " + "'" + CANCELLATION_REASON_MSG + "'" + " is madnatory Text field in additionalDetails of Bill cancell Request";
public static final String CANCELL_REASON_MSG_EMPTY_MSG = "Cancell Reason message cannot be empty";
public static final String CANCELL_REASON_CODE_NOT_FOUND = "EG_BS_CANCELL_REASON_CODE_NOT";
public static final String CANCELL_REASON_CODE_NOT_FOUND_MSG = "Cancellation Reason with key " + "'" + CANCELLATION_REASON_CODE + "'" + " is a madnatory Text field in additionalDetails of Bill cancell Request";
public static final String CANCELL_REASON_CODE_EMPTY_MSG = "Cancell Reason code cannot be empty";
public static final String CANCELLATION_REASON_MSG= "reasonMessage";
public static final String CANCELLATION_REASON_CODE= "reason";
public static final String CANCELL_REASON_MSG_NOT_FOUND = "EG_BS_CANCELL_REASON_MSG_NOT";
public static final String CANCELL_REASON_MSG_NOT_FOUND_MSG = "Cancellation Reason message with key " + "'" + CANCELLATION_REASON_MSG + "'" + " is a mandatory Text field in additionalDetails of Bill cancellation Request";
public static final String CANCELL_REASON_MSG_EMPTY_MSG = "Cancell Reason message cannot be empty";
public static final String CANCELL_REASON_CODE_NOT_FOUND = "EG_BS_CANCELL_REASON_CODE_NOT";
public static final String CANCELL_REASON_CODE_NOT_FOUND_MSG = "Cancellation Reason with key " + "'" + CANCELLATION_REASON_CODE + "'" + " is a mandatory Text field in additionalDetails of Bill cancellation Request";
public static final String CANCELL_REASON_CODE_EMPTY_MSG = "Cancell Reason code cannot be empty";


public static final String PENALTY_PATH_CODE = "$.MdmsRes.ws-services-calculation.Penalty";

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package org.egov.demand.web.validator;

import java.util.HashMap;
import java.util.Map;
import static org.egov.demand.util.Constants.BILL_GEN_MANDATORY_FIELDS_MISSING_KEY;
import static org.egov.demand.util.Constants.BILL_GEN_MANDATORY_FIELDS_MISSING_MSG;

import org.egov.common.contract.request.RequestInfo;
import org.egov.demand.model.BillSearchCriteria;
import org.egov.demand.model.BillV2.BillStatus;
import org.egov.demand.model.GenerateBillCriteria;
import org.egov.demand.util.Util;
import org.egov.tracer.model.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.Errors;
import org.egov.demand.model.UpdateBillCriteria;
import org.egov.demand.util.Constants;
import org.springframework.util.StringUtils;

import com.fasterxml.jackson.databind.JsonNode;

@Component
public class BillValidator {
Expand Down Expand Up @@ -57,4 +65,28 @@ public void validateBillSearchCriteria(BillSearchCriteria billCriteria, RequestI
}
}

public void validateBillSearchRequest(UpdateBillCriteria cancelBillCriteria) {
cancelBillCriteria.setStatusToBeUpdated(BillStatus.CANCELLED);
JsonNode additionalDetails = cancelBillCriteria.getAdditionalDetails();
Map<String, String> errorMap = new HashMap<>();
JsonNode reasonMsg = additionalDetails.get(Constants.CANCELLATION_REASON_MSG);
JsonNode reasonCode = additionalDetails.get(Constants.CANCELLATION_REASON_CODE);
if (null != reasonCode && reasonCode.isTextual()) {
if (StringUtils.isEmpty(reasonCode.textValue()))
errorMap.put(Constants.CANCELL_REASON_CODE_NOT_FOUND, Constants.CANCELL_REASON_CODE_EMPTY_MSG);
} else {
errorMap.put(Constants.CANCELL_REASON_CODE_NOT_FOUND, Constants.CANCELL_REASON_CODE_NOT_FOUND_MSG);
}

if (null != reasonMsg && reasonMsg.isTextual()) {
if (StringUtils.isEmpty(reasonMsg.textValue()))
errorMap.put(Constants.CANCELL_REASON_MSG_NOT_FOUND, Constants.CANCELL_REASON_MSG_EMPTY_MSG);
} else {
errorMap.put(Constants.CANCELL_REASON_MSG_NOT_FOUND, Constants.CANCELL_REASON_MSG_NOT_FOUND_MSG);
}
if (!CollectionUtils.isEmpty(errorMap)) {
throw new CustomException(errorMap);
}
}
Comment on lines +68 to +90
Copy link

Choose a reason for hiding this comment

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

The method validateBillSearchRequest correctly updates the bill status and performs validation on cancellation reasons. However, consider using more descriptive variable names for reasonMsg and reasonCode to enhance readability. Also, ensure that the error keys and messages are well-documented and localized if necessary.


}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ egov.apportion.endpoint=/apportion-service/v2/demand/_apportion
# billgen notif topic
kafka.topics.billgen.topic.name=billing-billgen-topic-name
bill.notification.fallback.locale=en_IN
kafka.topics.cancel.bill.topic.name=bill-cancel-topic-name

# notif topic
kafka.topics.notification.sms=egov.core.notification.sms
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE egbs_bill_v1 add column payerid character varying (128);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ALTER TABLE egbs_bill_v1 ADD COLUMN IF NOT EXISTS consumercode CHARACTER VARYING(256);

UPDATE egbs_bill_v1 b SET consumerCode = bd.consumercode FROM egbs_billdetail_v1 bd WHERE bd.billid = b.id;

ALTER TABLE egbs_bill_v1 ALTER COLUMN consumercode SET NOT NULL;

CREATE UNIQUE INDEX IF NOT EXISTS index_egbs_UNIQUE_ACTIVE_BILL ON egbs_bill_v1 (consumercode, tenantid, status) where status='ACTIVE';
Loading
Loading