Browse Source

Added PGR Complaints creating page in UI

master
Hariprasath S 3 months ago
parent
commit
0b232fe7c4
  1. 22
      src/main/java/com/gcc/greencommitte/controller/Apicontroller.java
  2. 5
      src/main/java/com/gcc/greencommitte/controller/Maincontroller.java
  3. 406
      src/main/java/com/gcc/greencommitte/service/Greencommitteeservice.java
  4. 499
      src/main/resources/templates/modules/pgrcomplaints.html

22
src/main/java/com/gcc/greencommitte/controller/Apicontroller.java

@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
@ -503,5 +504,26 @@ public class Apicontroller {
"description", "Application withdrawn successfully",
"ref_id", saveStatus));
}
//getpurninglist
@GetMapping("/getpurninglist")
public List<Map<String, Object>> getpurninglist() {
return gcservice.getpurninglist();
}
@PostMapping("/generatepgrcomplaints")
@ResponseBody
public ResponseEntity<?> generatepgrcomplaints(String refid){
return gcservice.generatepgrcomplaints(refid);
}
}

5
src/main/java/com/gcc/greencommitte/controller/Maincontroller.java

@ -29,4 +29,9 @@ public class Maincontroller {
public String withdrawpage(){
return "modules/withdrawpage";
}
@GetMapping("/pgrcomplaints")
public String pgrcomplaints(){
return "modules/pgrcomplaints";
}
}

406
src/main/java/com/gcc/greencommitte/service/Greencommitteeservice.java

@ -24,6 +24,23 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Base64;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gcc.greencommitte.config.AppConfig;
@ -607,6 +624,395 @@ public class Greencommitteeservice {
}
}
public List<Map<String, Object>> getpurninglist() {
String sql=" SELECT "
+ " r.ref_id,r.cby, "
+ " r.p_name, dm.name as deptname,"
+ " r.dept_name,"
+ " CHAR_LENGTH( "
+ " COALESCE( "
+ " NULLIF(r.p_name, ''), "
+ " NULLIF(r.dept_name, ''), "
+ " dm.name "
+ " ) "
+ " ) AS name_length, "
+ " r.address, "
+ " r.ph_no, "
+ " r.gender, "
+ " r.latitude, "
+ " r.longitude, "
+ " r.streetid,r.remarks, "
+ "CHAR_LENGTH(r.remarks) AS remarks_length, "
+ " ( "
+ " SELECT cd.comp_nature_id "
+ " FROM complaint_details cd "
+ " WHERE cd.ref_id = r.ref_id "
+ " AND cd.comp_nature_id IN (1,3) "
+ " LIMIT 1 "
+ " ) AS comp_nature_id, "
+ " ( "
+ " SELECT iu.img_path "
+ " FROM img_uploads iu "
+ " WHERE iu.ref_id = r.ref_id "
+ " AND iu.is_active = 1 "
+ " AND iu.is_delete = 0 "
+ " ORDER BY iu.id "
+ " LIMIT 1 "
+ " ) AS img_path "
+ "FROM reg_details r "
+ "LEFT JOIN dept_master dm ON dm.id=r.dept_id "
+ "WHERE r.is_active = 1 "
+ "AND r.is_delete = 0 AND r.pgrticketno is NULL "
+ "AND r.streetid IS NOT NULL "
+ "AND EXISTS "
+ "( "
+ " SELECT 1 "
+ " FROM complaint_details cd "
+ " WHERE cd.ref_id = r.ref_id "
+ " AND cd.comp_nature_id IN (1,3) "
+ ") ";
try {
return jdbcTemplate.queryForList(sql);
} catch (Exception e) {
e.printStackTrace();
return Collections.emptyList();
}
}
public ResponseEntity<?> generatepgrcomplaints(String refid) {
try {
String sql=" SELECT "
+ " r.ref_id,r.cby, "
+ " r.p_name,dm.name as deptname, "
+ " r.dept_name,"
+ " r.address, "
+ " r.ph_no, "
+ " r.gender, "
+ " r.latitude, "
+ " r.longitude, "
+ " r.streetid,r.remarks, "
+ " ( "
+ " SELECT cd.comp_nature_id "
+ " FROM complaint_details cd "
+ " WHERE cd.ref_id = r.ref_id "
+ " AND cd.comp_nature_id IN (1,3) "
+ " LIMIT 1 "
+ " ) AS comp_nature_id, "
+ " ( "
+ " SELECT iu.img_path "
+ " FROM img_uploads iu "
+ " WHERE iu.ref_id = r.ref_id "
+ " AND iu.is_active = 1 "
+ " AND iu.is_delete = 0 "
+ " ORDER BY iu.id "
+ " LIMIT 1 "
+ " ) AS img_path "
+ "FROM reg_details r "
+ "LEFT JOIN dept_master dm ON dm.id=r.dept_id "
+ "WHERE r.is_active = 1 "
+ "AND r.is_delete = 0 AND r.ref_id=? AND r.pgrticketno is NULL "
+ "AND r.streetid IS NOT NULL "
+ "AND EXISTS "
+ "( "
+ " SELECT 1 "
+ " FROM complaint_details cd "
+ " WHERE cd.ref_id = r.ref_id "
+ " AND cd.comp_nature_id IN (1,3) "
+ ") ";
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql,refid);
System.out.println("Total Generating Complaints : " + list.size());
if(list.isEmpty()) {
return ResponseEntity.ok(Map.of(
"status", false,
"message", "No eligible complaint found for this Ref ID."
));
}
String complaintNumber="";
for (Map<String, Object> row : list) {
try {
String refId = String.valueOf(row.get("ref_id"));
// String imageUrl = "";
//
// if(row.get("img_path") != null){
// imageUrl = "https://gccservices.in/gccofficialapp/files" + row.get("img_path");
// }
//String imageBase64 = convertUrlToBase64(imageUrl);
complaintNumber = sendComplaintToERP(row);
if(complaintNumber == null) {
return ResponseEntity.ok(Map.of(
"status", false,
"message", "ERP complaint generation failed."
));
}
if(complaintNumber != null && !complaintNumber.equals("N/A")){
jdbcTemplate.update(
"UPDATE reg_details SET pgrticketno=? WHERE ref_id=?",
complaintNumber,
refId
);
jdbcTemplate.update(
"UPDATE complaint_details "
+ "SET is_active=0, is_delete=1 "
+ "WHERE ref_id=? "
+ "AND comp_nature_id IN (1,3)",
refId
);
System.out.println(refId + " -> " + complaintNumber);
}
} catch (Exception e) {
System.out.println("Failed RefId : " + row.get("ref_id"));
e.printStackTrace();
}
}
return ResponseEntity.ok(Map.of(
"status", true,
"message", "PGR Complaint generation completed.",
"complaintNumber",complaintNumber,
"total", list.size()
));
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.internalServerError().body(
Map.of(
"status", false,
"message", e.getMessage()
)
);
}
}
private String sendComplaintToERP(Map<String,Object> row) {
try {
String externalUrl = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice";
URL url = new URL(externalUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setDoOutput(true);
String complaintType = "454";
String complaintTitle = "Tree Pruning";
//System.out.println("Name : " + getString(row.get("p_name")));
String complainantName = getComplainantName(row);
String params =
"serviceId=RegComplaint"
+ "&ComplainantName=" + URLEncoder.encode(complainantName, "UTF-8")
+ "&ComplainantAddr=" + URLEncoder.encode(getString(row.get("address")), "UTF-8")
+ "&MobileNo=" + URLEncoder.encode(getString(row.get("ph_no")), "UTF-8")
+ "&Email="+ URLEncoder.encode( "", "UTF-8")
+ "&ComplaintType=" + URLEncoder.encode(complaintType, "UTF-8")
+ "&ComplaintTitle=" + URLEncoder.encode(complaintTitle, "UTF-8")
+ "&ComplaintDetails=" + URLEncoder.encode(getString(row.get("remarks")), "UTF-8")+ URLEncoder.encode(getString(row.get("ref_id")), "UTF-8")
+ "&StreetId=" + URLEncoder.encode(getString(row.get("streetid")), "UTF-8")
//+ "&Comp_Image=" + URLEncoder.encode(imageBase64 == null ? "" : imageBase64, "UTF-8")
+ "&Comp_Image="+ URLEncoder.encode( "", "UTF-8")
+ "&latitude=" + URLEncoder.encode(getString(row.get("latitude")), "UTF-8")
+ "&longtitude=" + URLEncoder.encode(getString(row.get("longitude")), "UTF-8")
+ "&Landmark="+ URLEncoder.encode( "", "UTF-8")
+ "&gender=" + URLEncoder.encode(getString(row.get("gender")), "UTF-8")
+ "&compmode=1";
System.out.println(params);
try(OutputStream os = conn.getOutputStream()){
os.write(params.getBytes("UTF-8"));
}
BufferedReader reader;
System.out.println(conn.getResponseCode());
System.out.println(conn.getResponseMessage());
if(conn.getResponseCode()==200){
reader = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
}else{
reader = new BufferedReader(
new InputStreamReader(conn.getErrorStream()));
}
StringBuilder response = new StringBuilder();
String line;
while((line = reader.readLine()) != null){
response.append(line);
}
reader.close();
String responseText = response.toString();
System.out.println("=================================");
System.out.println("Response Code : " + conn.getResponseCode());
System.out.println("Response Body : ");
System.out.println(responseText);
System.out.println("=================================");
if (!responseText.trim().startsWith("{")) {
System.out.println("Response is not JSON.");
return null;
}
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> responseMap =
mapper.readValue(responseText, Map.class);
return String.valueOf(responseMap.get("Complaint Number"));
}
catch(Exception e){
e.printStackTrace();
return null;
}
}
private String getString(Object obj){
return obj == null ? "" : obj.toString();
}
public String convertUrlToBase64(String urlString) {
try {
URL url = new URL(urlString);
try (InputStream inputStream = url.openStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
byte[] fileBytes = outputStream.toByteArray();
System.out.println("Image Size : " + fileBytes.length + " bytes");
return Base64.getEncoder().encodeToString(fileBytes);
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private String getComplainantName(Map<String, Object> row) {
String name = getString(row.get("p_name")).trim();
if (name.isEmpty()) {
name = getString(row.get("dept_name")).trim();
}
if (name.isEmpty()) {
name = getString(row.get("deptname")).trim();
}
if (name.isEmpty()) {
System.out.println("No Complainant Name found.");
return "";
}
System.out.println("Original Name : " + name);
System.out.println("Original Length : " + name.length());
if (name.length() <= 31) {
return name;
}
String temp = name.substring(0, 31);
int lastSpace = temp.lastIndexOf(' ');
if (lastSpace > 0) {
temp = temp.substring(0, lastSpace);
}
System.out.println("Trimmed Name : " + temp);
System.out.println("Trimmed Length : " + temp.length());
return temp;
}
//private String getComplainantName(Map<String, Object> row) {
//
// String pName = getString(row.get("p_name")).trim();
// if (!pName.isEmpty()) {
// System.out.println("Using p_name : " + pName);
// System.out.println("Length : " + pName.length());
// return pName;
// }
//
// String deptName = getString(row.get("dept_name")).trim();
// if (!deptName.isEmpty()) {
// System.out.println("Using dept_name : " + deptName);
// System.out.println("Length : " + deptName.length());
// return deptName;
// }
//
// String deptMasterName = getString(row.get("deptname")).trim();
// if (!deptMasterName.isEmpty()) {
// System.out.println("Using deptname : " + deptMasterName);
// System.out.println("Length : " + deptMasterName.length());
// return deptMasterName;
// }
//
// System.out.println("No Complainant Name found.");
// System.out.println("Length : 0");
// return "";
//}
}

499
src/main/resources/templates/modules/pgrcomplaints.html

@ -0,0 +1,499 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>GCC Green Committee</title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<base th:href="${baseURL}"/>
<link rel="icon" th:href="@{images/favicon.ico}" type="image/x-icon" />
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700,800" rel="stylesheet">
<link rel="stylesheet" type="text/css" th:href="@{assets/node_modules/bootstrap/dist/css/bootstrap.min.css}">
<link rel="stylesheet" type="text/css" th:href="@{assets/node_modules/select2/dist/css/select2.min.css}">
<link rel="stylesheet" type="text/css" th:href="@{assets/node_modules/sweetalert2/sweetalert2.min.css}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
<!-- DataTables CSS -->
<link href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css" rel="stylesheet"/>
<link href="https://cdn.datatables.net/buttons/2.3.6/css/buttons.dataTables.min.css" rel="stylesheet"/>
<style>
/* Header Styling */
.header {
background-color: #1d495a;
padding: 10px 20px;
color: white;
font-family: Arial, sans-serif;
}
.header .logo img {
height: 50px;
}
.header .center-text {
text-align: center;
font-size: 24px;
}
.header .menu-btn {
background-color: transparent;
border: none;
font-size: 24px;
color: white;
}
.header .menu-btn:hover {
color: #ccc;
}
/* Menu Dropdown */
.menu-dropdown {
position: absolute;
top: 60px;
right: 20px;
background-color: #1d495a;
padding: 10px;
display: none;
flex-direction: column;
z-index: 1000; /* Add z-index to bring the menu above other elements */
}
.menu-dropdown a {
color: white;
margin-bottom: 5px;
text-decoration: none;
}
.menu-dropdown a:hover {
text-decoration: underline;
}
/* Mobile Specific Styling */
@media (max-width: 768px) {
.header {
display: flex;
justify-content: space-between;
align-items: center;
}
.center-text {
font-size: 18px !important;
flex-grow: 1;
text-align: center;
}
.menu-dropdown {
right: 0;
left: 0;
z-index: 1000; /* Add z-index to bring the menu above other elements */
}
}
.card {
border-radius: 12px;
}
.card-h{
border-top-left-radius: 12px;
border-top-right-radius: 12px;
}
#sendOtpButton {
padding: 12px;
font-size: 16px;
border-radius: 6px;
transition: 0.3s ease;
}
#sendOtpButton:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.otp-input-box {
/*display: flex;
justify-content: space-between;*/
width: 100%;
}
.otp-input {
width: 30px;
height: 30px;
border: 1px solid #ccc;
border-radius: 5px;
text-align: center;
font-size: 16px;
margin-right: 10px;
}
.chcolor{
background-color: #1d495a;
border-top-left-radius: 12px !important;
border-top-right-radius: 12px !important;
}
</style>
</head>
<body style="background-color: #ebf1fa;">
<!-- Header Start-->
<header>
<div class="header d-flex justify-content-between align-items-center">
<!-- Left: Logo -->
<div class="logo">
<img src="https://gccservices.in/gcc/assets/images/logo.png" alt="Logo">
</div>
<!-- Center: Text -->
<div class="center-text">
GREATER CHENNAI CORPORATION
</div>
<!-- Right: Button for Menu -->
<div class="menu">
<button class="menu-btn" onclick="toggleMenu()">
&#9776; <!-- Unicode for hamburger menu icon -->
</button>
</div>
</div>
<!-- Dropdown Menu -->
<div class="menu-dropdown" id="menuDropdown">
<a href="https://chennaicorporation.gov.in/gcc/">Home</a>
<a href="https://chennaicorporation.gov.in/gcc/about-GCC/">About GCC</a>
<a href="https://chennaicorporation.gov.in/gcc/who-is-who/index_data.jsp">Who's Who</a>
<a href="https://chennaicorporation.gov.in/gcc/council/about-council/">Council</a>
<a href="https://chennaicorporation.gov.in/gcc/tender/">Tender</a>
<a href="https://chennaicorporation.gov.in/gcc/department/">Departments</a>
<a href="https://chennaicorporation.gov.in/gcc/online-services/">Online Services</a>
<a href="https://gccservices.in/gcc/login">Official Login</a>
</div>
</header>
<!-- Header End-->
<main class="container-fluid mt-4">
<div class="card shadow-lg border-0">
<div class="card-h text-center text-white py-3" style="background-color: #1d495a;">
<h5 class="mb-0">Green Committee Pruning Complaint Creation</h5>
</div>
<div class="card-body">
<table id="RequestListDatatable" class="table table-striped table-bordered table-hover dataTable" role="grid">
<thead class="thead-dark">
<tr role="row">
<th class="text-center">S.No</th>
<th class="text-center">C By</th>
<th class="text-center">Refid</th>
<th class="text-center">Name</th>
<th class="text-center">Name Length</th>
<th class="text-center">Mobile</th>
<th class="text-center">Remarks length</th>
<th class="text-center no-sort" width="%2">Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<button
type="button"
class="btn btn-secondary mt-2 mb-2"
style="font-size: 1.1rem;min-width: 70px;"
id="backButton" onclick="gotoback()">
Back
</button>
</main>
<div id="pageLoader" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255, 255, 255, 0.8); z-index: 9999; text-align: center;">
<div style="position: relative; top: 50%; transform: translateY(-50%);">
<div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
<span class="sr-only">Loading...</span>
</div>
<!-- Add the 'Please wait' text below the spinner -->
<p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
</div>
</div>
<script type="text/javascript" th:src="@{assets/node_modules/jquery/dist/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{assets/node_modules/bootstrap/dist/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{assets/node_modules/select2/dist/js/select2.min.js}"></script>
<script type="text/javascript" th:src="@{assets/node_modules/sweetalert2/sweetalert2.min.js}"></script>
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.3.6/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.3.6/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.3.6/js/buttons.print.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script type="text/javascript">
function gotoback(){
window.location.href = '/greencommittee/home';
}
$(document).ready(function () {
var table = $('#RequestListDatatable').DataTable({
dom: 'Bftip',
columnDefs: [
{ targets: 'no-sort', orderable: false }
],
lengthMenu: [
[50, 100, 200, 500, -1],
['50 rows', '100 rows', '200 rows', 'Show all']
],
scrollY: '50vh',
buttons: [
{
extend: 'pageLength',
className: 'btn btn-warning'
},
{
title: 'Data export',
extend: 'copyHtml5',
text: 'Copy',
className: 'btn btn-secondary',
id: 'copyBtn'
},
{
extend: 'excelHtml5',
text: 'Excel',
className: 'btn btn-secondary',
id: 'excelBtn'
},
{
extend: 'csvHtml5',
text: 'CSV',
className: 'btn btn-secondary',
id: 'csvBtn'
},
{
extend: 'pdfHtml5',
text: 'PDF',
className: 'btn btn-secondary',
id: 'pdfBtn'
}
],
fixedHeader: false,
autoWidth: true,
responsive: true,
searching: false,
select: false,
processing: false
});
fetchDetails();
});
function fetchDetails(){
$('#pageLoader').show();
$.ajax({
url: '/greencommittee/api/getpurninglist',
method: 'GET',
contentType: 'application/json',
success: function (data) {
$('#pageLoader').hide();
let tableContainer = $('#RequestListDatatable');
// Destroy any existing DataTable instance
if ($.fn.DataTable.isDataTable(tableContainer)) {
tableContainer.DataTable().destroy();
}
tableContainer.DataTable({
destroy: true,
searching: true,
autoWidth: false,
paging: true,
info: true,
data: data,
columns: [
{
data: null,
render: (data, type, row, meta) => meta.row + 1,
className: 'text-center'
},
{ data: 'cby', defaultContent: '-', className: 'text-center' },
{ data: 'ref_id', defaultContent: '-', className: 'text-center' },
{
data: null,
className: 'text-center',
render: function (data, type, row) {
return row.p_name?.trim() ||
row.dept_name?.trim() ||
row.deptname?.trim() ||
"-";
}
},
{ data: 'name_length', defaultContent: '-', className: 'text-center' },
{ data: 'ph_no', defaultContent: '-', className: 'text-center' },
{ data: 'remarks_length', defaultContent: '-', className: 'text-center' },
{
data: 'ref_id',
render: function (data, type, row) {
return `<button class="btn btn-primary btn-create"
data-refid="${data}">
Generate PGR
</button>`;
},
className: 'text-center'
}
],
dom: 'Bfrtip',
buttons: [
{ extend: 'pageLength', className: 'btn btn-warning' },
{ extend: 'copyHtml5', text: 'Copy', className: 'btn btn-secondary' },
{ extend: 'excelHtml5', text: 'Excel', className: 'btn btn-secondary' },
{ extend: 'csvHtml5', text: 'CSV', className: 'btn btn-secondary' },
{ extend: 'pdfHtml5', text: 'PDF', className: 'btn btn-secondary' }
],
columnDefs: [{ targets: 'no-sort', orderable: false }],
lengthMenu: [
[50, 100, 200, 500, -1],
['50 rows', '100 rows', '200 rows', 'Show all']
],
scrollY: '80vh',
scrollX: true,
responsive: false
});
},
error: function (xhr, status, error) {
$('#pageLoader').hide();
console.error("Error fetching data:", error);
alert("Failed to load Details .");
}
});
}
$(document).on("click", ".btn-create", function () {
const button = $(this);
const refId = button.data("refid");
Swal.fire({
title: "Generate PGR Complaint?",
text: "Are you sure you want to generate a PGR complaint for " + refId + "?",
icon: "question",
showCancelButton: true,
confirmButtonText: "Yes",
cancelButtonText: "No"
}).then((result) => {
if (!result.isConfirmed) {
return;
}
button.prop("disabled", true).text("Generating...");
$('#pageLoader').show();
$.ajax({
url: "/greencommittee/api/generatepgrcomplaints",
type: "POST",
data: {
refid: refId
},
success: function (response) {
console.log(response);
console.log(response.complaintNumber);
$('#pageLoader').hide();
button.prop("disabled", false).text("Generate PGR");
if (response.status) {
Swal.fire({
icon: "success",
title: "Success",
html:
"<b>PGR Complaint Generated Successfully</b><br><br>" +
"Complaint No : <b>" + (response.complaintNumber) + "</b>"
}).then(() => {
// Refresh table
fetchDetails();
});
} else {
Swal.fire({
icon: "warning",
title: "Failed",
text: response.message || "Unable to generate complaint."
});
}
},
error: function (xhr) {
$('#pageLoader').hide();
button.prop("disabled", false).text("Generate PGR");
let message = "Something went wrong.";
if (xhr.responseJSON && xhr.responseJSON.message) {
message = xhr.responseJSON.message;
}
Swal.fire({
icon: "error",
title: "Error",
text: message
});
}
});
});
});
</script>
</body>
</html>
Loading…
Cancel
Save