Browse Source

added custom error page and birth and death restapiservices url added for fetching records

master
yoganandhan 1 year ago
parent
commit
283c1a69e7
  1. 136
      src/main/java/com/gcc/crslogs/controller/ApiController.java
  2. 43
      src/main/java/com/gcc/crslogs/controller/CustomErrorController.java
  3. 11
      src/main/java/com/gcc/crslogs/controller/MainController.java
  4. 160
      src/main/java/com/gcc/crslogs/service/BirthAndDeathDetailsService.java
  5. 352
      src/main/resources/templates/modules/crslogspages/birth.html
  6. 160
      src/main/resources/templates/modules/crslogspages/death.html
  7. 49
      src/main/resources/templates/modules/crslogspages/message.html

136
src/main/java/com/gcc/crslogs/controller/ApiController.java

@ -17,6 +17,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@ -149,35 +150,114 @@ public class ApiController {
}
///////////////////////birth details getting method///////////////////
@GetMapping("/birth-details")
public ResponseEntity<?> fetchBirthCertificateSecurely(
@RequestParam String dob,
@RequestParam String sex,
@RequestParam(required = false) String regno,
@RequestParam(required = false) String childname,
@RequestParam(required = false) String fathername,
@RequestParam(required = false) String mothername) {
if (dob.isEmpty() || sex.isEmpty()) {
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "DOB and Sex are mandatory.");
return ResponseEntity.badRequest().body(error);
}
try {
Map<String, Object> result = birthAndDeathDetailsService.fetchBirthCertificate(dob, sex, regno, childname, fathername, mothername);
return ResponseEntity.ok(result);
} catch (Exception e) {
e.printStackTrace();
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "Something went wrong: " + e.getMessage());
return ResponseEntity.status(500).body(error);
}
}
///////////////////////birth details getting method///////////////////
// now using in live
// @GetMapping("/birth-details")
// public ResponseEntity<?> fetchBirthCertificateSecurely(
// @RequestParam String dob,
// @RequestParam String sex,
// @RequestParam(required = false) String regno,
// @RequestParam(required = false) String childname,
// @RequestParam(required = false) String fathername,
// @RequestParam(required = false) String mothername) {
// if (dob.isEmpty() || sex.isEmpty()) {
// Map<String, Object> error = new HashMap<>();
// error.put("status", false);
// error.put("message", "DOB and Sex are mandatory.");
// return ResponseEntity.badRequest().body(error);
// }
// try {
// Map<String, Object> result = birthAndDeathDetailsService.fetchBirthCertificate(dob, sex, regno, childname, fathername, mothername);
// return ResponseEntity.ok(result);
// } catch (Exception e) {
// e.printStackTrace();
// Map<String, Object> error = new HashMap<>();
// error.put("status", false);
// error.put("message", "Something went wrong: " + e.getMessage());
// return ResponseEntity.status(500).body(error);
// }
// }
// from external api restapiservices
@PostMapping("/birth-details")
public ResponseEntity<?> fetchBirthCertificateSecurely(@RequestBody Map<String, String> params) {
String dob = params.get("dob");
String sex = params.get("sex");
String childname = params.getOrDefault("childname", "");
String fathername = params.getOrDefault("fathername", "");
String mothername = params.getOrDefault("mothername", "");
if (dob == null || dob.isEmpty() || sex == null || sex.isEmpty()) {
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "DOB and Sex are mandatory.");
return ResponseEntity.badRequest().body(error);
}
//System.out.println("fathername " + fathername);
//System.out.println("mothername " + mothername);
try {
Map<String, Object> result = birthAndDeathDetailsService.fetchLocalBirthCertificate(
dob, fathername, mothername, childname, sex
);
return ResponseEntity.ok(result);
} catch (Exception e) {
e.printStackTrace();
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "Something went wrong: " + e.getMessage());
return ResponseEntity.status(500).body(error);
}
}
// from external api restapiservices
@PostMapping("/death-details")
public ResponseEntity<?> fetchDeathCertificateSecurely(@RequestBody Map<String, String> params) {
String dod = params.get("dod");
String sex = params.get("sex");
String personname = params.getOrDefault("personname", "");
String fathername = params.getOrDefault("fathername", "");
String mothername = params.getOrDefault("mothername", "");
if (dod == null || dod.isEmpty() || sex == null || sex.isEmpty()) {
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "DOB and Sex are mandatory.");
return ResponseEntity.badRequest().body(error);
}
//System.out.println("fathername " + fathername);
//System.out.println("mothername " + mothername);
try {
Map<String, Object> result = birthAndDeathDetailsService.fetchLocalDeathCertificate(
dod, fathername, mothername, personname, sex
);
return ResponseEntity.ok(result);
} catch (Exception e) {
e.printStackTrace();
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "Something went wrong: " + e.getMessage());
return ResponseEntity.status(500).body(error);
}
}

43
src/main/java/com/gcc/crslogs/controller/CustomErrorController.java

@ -0,0 +1,43 @@
package com.gcc.crslogs.controller;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.ui.Model;
import jakarta.servlet.http.HttpServletRequest;
@Controller
public class CustomErrorController implements ErrorController {
@RequestMapping("/error")
public String handleError(HttpServletRequest request, Model model) {
Integer statusCode = (Integer) request.getAttribute("jakarta.servlet.error.status_code");
String title = "Error";
String message = "An unexpected error occurred.";
String code = statusCode != null ? statusCode.toString() : "";
if (statusCode != null) {
switch (statusCode) {
case 404:
title = "Page Not Found";
message = "Sorry, the page you are looking for does not exist.";
break;
case 403:
title = "Access Forbidden";
message = "You do not have permission to access this page.";
break;
case 500:
title = "Internal Server Error";
message = "Oops! Something went wrong on our end.";
break;
default:
title = "Error";
message = "An unexpected error occurred.";
}
}
model.addAttribute("code", code);
model.addAttribute("title", title);
model.addAttribute("message", message);
return "modules/crslogspages/message";
}
}

11
src/main/java/com/gcc/crslogs/controller/MainController.java

@ -84,4 +84,15 @@ public class MainController {
return "modules/crslogspages/death";
}
// Example for error
@GetMapping("/some-error")
public String showError(Model model) {
model.addAttribute("code", "404");
model.addAttribute("title", "Page Not Found");
model.addAttribute("message", "Sorry, the page you are looking for does not exist.");
return "modules/crslogspages/message";
}
}

160
src/main/java/com/gcc/crslogs/service/BirthAndDeathDetailsService.java

@ -2,8 +2,10 @@ package com.gcc.crslogs.service;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
@ -12,12 +14,17 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -39,7 +46,7 @@ public class BirthAndDeathDetailsService {
//using for live
public Map<String, Object> fetchBirthCertificate(String dob, String sex, String regno, String childName, String fatherName, String motherName) throws Exception {
Map<String, String> params = new LinkedHashMap(); // keep order
@ -76,11 +83,114 @@ public class BirthAndDeathDetailsService {
return mapper.readValue(cleanJson, new TypeReference<Map<String, Object>>() {});
}
// to created our external api from restservices
public Map<String, Object> fetchLocalBirthCertificate(
String dob, String fatherName, String motherName, String childName, String sex) throws Exception {
String apiUrl = "https://gccservices.chennaicorporation.gov.in/gccrestservices/api/birth-certificate/by-detailsnewforWeb";
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("incident_date", dob); // yyyy-MM-dd
params.add("gender", sex);
// 🔹 Pass optional values if provided (converted to UPPERCASE, DB expects this)
if (fatherName != null && !fatherName.trim().isEmpty()) {
params.add("father_name", fatherName.trim().toUpperCase());
}
if (motherName != null && !motherName.trim().isEmpty()) {
params.add("mother_name", motherName.trim().toUpperCase());
}
if (childName != null && !childName.trim().isEmpty()) {
params.add("child_name", childName.trim().toUpperCase());
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(params, headers);
ResponseEntity<String> response = restTemplate.postForEntity(apiUrl, entity, String.class);
String rawJson = response.getBody();
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> result = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {});
// ✅ Only keep records that actually have a PDF link
// if (result.containsKey("certificate_details")) {
// List<Map<String, Object>> details = (List<Map<String, Object>>) result.get("certificate_details");
// List<Map<String, Object>> filtered = details.stream()
// .filter(row -> row.get("pdf_url") != null && !row.get("pdf_url").toString().trim().isEmpty())
// .toList();
// result.put("certificate_details", filtered);
// }
return result;
}
// to created our external api from restservices
public Map<String, Object> fetchLocalDeathCertificate(
String dod, String fatherName, String motherName, String personName, String sex) throws Exception {
String apiUrl = "https://gccservices.chennaicorporation.gov.in/gccrestservices/api/death-certificate/by-detailsnewforWeb";
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("incident_date", dod); // yyyy-MM-dd
params.add("gender", sex);
// 🔹 Pass optional values if provided (converted to UPPERCASE, DB expects this)
if (fatherName != null && !fatherName.trim().isEmpty()) {
params.add("father_name", fatherName.trim().toUpperCase());
}
if (motherName != null && !motherName.trim().isEmpty()) {
params.add("mother_name", motherName.trim().toUpperCase());
}
if (personName != null && !personName.trim().isEmpty()) {
params.add("person_name", personName.trim().toUpperCase());
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(params, headers);
ResponseEntity<String> response = restTemplate.postForEntity(apiUrl, entity, String.class);
String rawJson = response.getBody();
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> result = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {});
// ✅ Only keep records that actually have a PDF link
// if (result.containsKey("certificate_details")) {
// List<Map<String, Object>> details = (List<Map<String, Object>>) result.get("certificate_details");
// List<Map<String, Object>> filtered = details.stream()
// .filter(row -> row.get("pdf_url") != null && !row.get("pdf_url").toString().trim().isEmpty())
// .toList();
// result.put("certificate_details", filtered);
// }
return result;
}
//using in live
public Map<String, Object> fetchDeathCertificate(String dod, String sex, String regno, String personName, String fatherName, String motherName) throws Exception {
@SuppressWarnings("rawtypes")
@ -115,51 +225,9 @@ public class BirthAndDeathDetailsService {
return mapper.readValue(cleanJson, new TypeReference<Map<String, Object>>() {});
}
private String clean(String input) {
if (input == null) return "";
return input.replace("\"", "").trim(); // remove unescaped quotes
}
// private String sanitizeJsonResponse(String rawJson) {
// if (rawJson == null) return "";
//
// // Remove illegal control characters (but keep line breaks if needed)
// return rawJson
// .replace("\\", "\\\\") // Escape backslashes
// .replaceAll("[\\p{Cntrl}&&[^\r\n\t]]", "") // Remove non-printable control characters (except tabs/newlines)
// .replaceAll("\t", "") // Remove tab characters explicitly (common cause of error)
// .replaceAll("\\s*:\\s*\n\\s*\"", ":\"") // Fix broken key-value splits
// .replaceAll("\r", "") // Remove carriage return if any
// .replaceAll("\n", "") // Optionally remove newlines if JSON is malformed across lines
// .replaceAll(",\\s*\\[", "[") // Remove comma before array start
// .replaceAll("\\[\\s*,", "[") // Remove comma after array start
// .replaceAll(",\\s*\\]", "]"); // Remove trailing comma in array
// }
// private String sanitizeJsonResponse(String rawJson) {
// if (rawJson == null) return "";
// return rawJson
// .replace("\\", "\\\\") // Escape backslashes
// .replaceAll("[\\p{Cntrl}&&[^\r\n\t]]", "") // Remove non-printable control characters
// .replaceAll("\t", "") // Remove tab characters
// .replaceAll("\\s*:\\s*\n\\s*\"", ":\"") // Fix broken key-value splits
// .replaceAll("\r", "") // Remove carriage return
// .replaceAll("\n", "") // Remove newlines
// .replaceAll(",\\s*\\[", "[") // Remove comma before array start
// .replaceAll("\\[\\s*,", "[") // Remove comma after array start
// .replaceAll(",\\s*\\]", "]") // Remove trailing comma in array
// .replaceAll("\"\"\"", "\"\"") // ← fix triple quotes
// .replaceAll("\"{3,}", "\"") // ← fallback: collapse 3+ quotes to 1
// .replaceAll(":(\\s*)\"{2,}\"", ":\"\"") // ← handle `:"""` to `:""`
// .replaceAll("\"\\s*\\(", " ("); // Remove quote before parenthesis
// }
private String sanitizeJsonResponse(String rawJson) {

352
src/main/resources/templates/modules/crslogspages/birth.html

@ -517,7 +517,7 @@ body {
<div class="row mb-3">
<div class="col-md-5">
<label class="form-label" for="phoneNumber">Enter Register Number </label> <input type="text"
<label class="form-label" for="registerno">Enter Register Number </label> <input type="text"
id="regno" class="form-control"
placeholder="Enter Register number">
</div>
@ -609,7 +609,7 @@ body {
<div class="row mb-3">
<div class="col-md-5">
<label class="form-label" for="phoneNumber">Enter Register Number </label> <input type="text"
<label class="form-label" for="registerno">Enter Register Number </label> <input type="text"
class="form-control"
placeholder="Enter Register number">
</div>
@ -744,7 +744,7 @@ body {
</div>
</div>
</div>
</div>
</div>
@ -966,134 +966,254 @@ document.addEventListener("DOMContentLoaded", function () {
});
// this function currently using in live
// function fetchBirthData() {
// const dob = document.getElementById('dateofbirth').value;
// const gender = document.querySelector('input[name="gender"]:checked')?.value;
// const captchaInput = document.getElementById('birth-captcha-input');
// //console.log("gender:", gender);
// // Validate Date of Birth
// if (!dob) {
// Swal.fire({
// icon: 'warning',
// title: 'Missing Date of Birth',
// text: 'Please enter your Date of Birth.'
// });
// return;
// }
// // Validate Gender
// if (!gender) {
// Swal.fire({
// icon: 'warning',
// title: 'Missing Gender Selection',
// text: 'Please select a gender.'
// });
// return;
// }
// // CAPTCHA validation first
// // Validate CAPTCHA
// if (!validateCaptcha('birth')) {
// //captchaInput.classList.add('is-invalid');
// //captchaInput.focus();
// return;
// } else {
// captchaInput.classList.remove('is-invalid');
// }
// const formattedDob = dob.split("-").reverse().join("/"); // Convert yyyy-MM-dd to dd/MM/yyyy
// //console.log("dob:", formattedDob);
// $('#pageLoader').show();
// $.ajax({
// url: '/crs/api/birth-details',
// method: 'GET',
// data: {
// dob: formattedDob,
// sex: gender.charAt(0).toUpperCase()
// },
// success: function (response) {
// $('#pageLoader').hide();
// if (response && response.BIRTH && response.BIRTH.length > 0) {
// console.log("birthdetails:",response);
// let html = `
// <table id="birthDataTable" class="table table-bordered table-striped">
// <thead>
// <tr>
// <th>S.No</th>
// <th>Reg No</th>
// <th>Child Name</th>
// <th>Father</th>
// <th>Mother</th>
// <th>DOB</th>
// <th>Certificate Link</th>
// </tr>
// </thead>
// <tbody>`;
// response.BIRTH.forEach((row, index) => {
// html += `<tr>
// <td>${index + 1}</td>
// <td>${row.REGNO}</td>
// <td>${row.CHILDNAME}</td>
// <td>${row.FATHERNAME}</td>
// <td>${row.MOTHERNAME}</td>
// <td>${row.DOB}</td>
// <td>${row.ENGLISHURL ? `<a href="${row.ENGLISHURL}" target="_blank"
// onclick="saveCertificateLog('${row.REGNO}', '${row.DOB}', '${row.ENGLISHURL}', 'Birth')">View</a>` : 'N/A'}</td>
// </tr>`;
// });
// html += `</tbody></table>`;
// $('#birthModalBody').html(html);
// setTimeout(() => {
// $('#birthDataTable').DataTable({
// responsive: true,
// pagingType: "full_numbers", // Buttons for pagination
// language: {
// search: "🔍 Search: ",
// emptyTable: "No records found",
// paginate: {
// previous: "<button class='btn btn-outline-primary btn-sm'>Previous</button>",
// next: "<button class='btn btn-outline-primary btn-sm'>Next</button>"
// }
// },
// columnDefs: [
// { orderable: false, targets: 0 } // Disable sorting on S.No
// ]
// });
// }, 100);
// }
// else {
// $('#birthModalBody').html('<p class="text-danger">No birth records found.</p>');
// }
// const modal = new bootstrap.Modal(document.getElementById('birthModal'));
// modal.show();
// },
// error: function (xhr) {
// $('#pageLoader').hide();
// let message = "Something went wrong.";
// if (xhr.responseJSON && xhr.responseJSON.message) {
// message = xhr.responseJSON.message;
// }
// alert("Error: " + message);
// }
// });
// }
// new function
function fetchBirthData() {
const dob = document.getElementById('dateofbirth').value;
const gender = document.querySelector('input[name="gender"]:checked')?.value;
const captchaInput = document.getElementById('birth-captcha-input');
const fatherName = document.getElementById('fathername')?.value || "";
const motherName = document.getElementById('mothername')?.value || "";
const childName = document.getElementById('childname')?.value || "";
// Validate DOB
if (!dob) {
Swal.fire({ icon: 'warning', title: 'Missing Date of Birth', text: 'Please enter your Date of Birth.' });
return;
}
// Validate Gender
if (!gender) {
Swal.fire({ icon: 'warning', title: 'Missing Gender Selection', text: 'Please select a gender.' });
return;
}
const dob = document.getElementById('dateofbirth').value;
const gender = document.querySelector('input[name="gender"]:checked')?.value;
const captchaInput = document.getElementById('birth-captcha-input');
//console.log("gender:", gender);
// Validate Date of Birth
if (!dob) {
Swal.fire({
icon: 'warning',
title: 'Missing Date of Birth',
text: 'Please enter your Date of Birth.'
});
return;
}
// Validate Gender
if (!gender) {
Swal.fire({
icon: 'warning',
title: 'Missing Gender Selection',
text: 'Please select a gender.'
});
return;
}
// CAPTCHA validation first
// Validate CAPTCHA
if (!validateCaptcha('birth')) {
//captchaInput.classList.add('is-invalid');
//captchaInput.focus();
return;
} else {
captchaInput.classList.remove('is-invalid');
}
// CAPTCHA validation
if (!validateCaptcha('birth')) {
return;
} else {
captchaInput.classList.remove('is-invalid');
}
const formattedDob = dob.split("-").reverse().join("/"); // Convert yyyy-MM-dd to dd/MM/yyyy
//console.log("dob:", formattedDob);
$('#pageLoader').show();
$('#pageLoader').show();
$.ajax({
url: '/crs/api/birth-details',
method: 'GET',
data: {
dob: formattedDob,
const payload = {
dob: dob,
sex: gender.charAt(0).toUpperCase()
},
success: function (response) {
$('#pageLoader').hide();
if (response && response.BIRTH && response.BIRTH.length > 0) {
console.log("birthdetails:",response);
let html = `
<table id="birthDataTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>S.No</th>
<th>Reg No</th>
<th>Child Name</th>
<th>Father</th>
<th>Mother</th>
<th>DOB</th>
<th>Certificate Link</th>
</tr>
</thead>
<tbody>`;
response.BIRTH.forEach((row, index) => {
html += `<tr>
<td>${index + 1}</td>
<td>${row.REGNO}</td>
<td>${row.CHILDNAME}</td>
<td>${row.FATHERNAME}</td>
<td>${row.MOTHERNAME}</td>
<td>${row.DOB}</td>
<td>${row.ENGLISHURL ? `<a href="${row.ENGLISHURL}" target="_blank"
onclick="saveCertificateLog('${row.REGNO}', '${row.DOB}', '${row.ENGLISHURL}', 'Birth')">View</a>` : 'N/A'}</td>
</tr>`;
});
};
if (fatherName.trim()) payload.fathername = fatherName.trim();
if (motherName.trim()) payload.mothername = motherName.trim();
if (childName.trim()) payload.childname = childName.trim();
$.ajax({
url: '/crs/api/birth-details',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify(payload),
success: function (response) {
$('#pageLoader').hide();
if (response && response.certificate_details && response.certificate_details.length > 0) {
let html = `
<table id="birthDataTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>S.No</th>
<th>Reg No</th>
<th>Child Name</th>
<th>DOB</th>
<th>Father Name</th>
<th>Mother Name</th>
<th>Certificate Link</th>
</tr>
</thead>
<tbody>`;
response.certificate_details.forEach((row, index) => {
html += `<tr>
<td>${index + 1}</td>
<td>${row.regno}</td>
<td>${row.name}</td>
<td>${row.dob}</td>
<td>${row.father_name}</td>
<td>${row.mother_name}</td>
<td><a href="${row.pdf_url}" target="_blank"
onclick="saveCertificateLog('${row.regno}', '${row.dob}', '${row.pdf_url}', 'Birth')">View</a></td>
</tr>`;
});
html += `</tbody></table>`;
$('#birthModalBody').html(html);
html += `</tbody></table>`;
$('#birthModalBody').html(html);
setTimeout(() => {
$('#birthDataTable').DataTable({
responsive: true,
pagingType: "full_numbers",
language: {
search: "🔍 Search: ",
emptyTable: "No records found",
paginate: {
previous: "<button class='btn btn-outline-primary btn-sm'>Previous</button>",
next: "<button class='btn btn-outline-primary btn-sm'>Next</button>"
}
},
columnDefs: [{ orderable: false, targets: 0 }]
});
}, 100);
} else {
$('#birthModalBody').html('<p class="text-danger">No birth records found.</p>');
}
setTimeout(() => {
$('#birthDataTable').DataTable({
responsive: true,
pagingType: "full_numbers", // Buttons for pagination
language: {
search: "🔍 Search: ",
emptyTable: "No records found",
paginate: {
previous: "<button class='btn btn-outline-primary btn-sm'>Previous</button>",
next: "<button class='btn btn-outline-primary btn-sm'>Next</button>"
}
},
columnDefs: [
{ orderable: false, targets: 0 } // Disable sorting on S.No
]
});
}, 100);
}
else {
$('#birthModalBody').html('<p class="text-danger">No birth records found.</p>');
const modal = new bootstrap.Modal(document.getElementById('birthModal'));
modal.show();
},
error: function (xhr) {
$('#pageLoader').hide();
let message = "Something went wrong.";
if (xhr.responseJSON && xhr.responseJSON.message) {
message = xhr.responseJSON.message;
}
alert("Error: " + message);
}
});
}
const modal = new bootstrap.Modal(document.getElementById('birthModal'));
modal.show();
},
error: function (xhr) {
$('#pageLoader').hide();
let message = "Something went wrong.";
if (xhr.responseJSON && xhr.responseJSON.message) {
message = xhr.responseJSON.message;
}
alert("Error: " + message);
}
});
}
// this function only using in live
function fetchDeathData() {
const dod = document.getElementById('dateofdeath').value;

160
src/main/resources/templates/modules/crslogspages/death.html

@ -1095,12 +1095,128 @@ $.ajax({
}
// using fetchdeathdata function in live
// function fetchDeathData() {
// const dod = document.getElementById('dateofdeath').value;
// const gender = document.querySelector('input[name="deathgender"]:checked')?.value;
// const captchaInput = document.getElementById('death-captcha-input');
// // console.log("gender:", gender);
// // Validate Date of Birth
// if (!dod) {
// Swal.fire({
// icon: 'warning',
// title: 'Missing Date of Birth',
// text: 'Please enter your Date of Birth.'
// });
// return;
// }
// // Validate Gender
// if (!gender) {
// Swal.fire({
// icon: 'warning',
// title: 'Missing Gender Selection',
// text: 'Please select a gender.'
// });
// return;
// }
// if (!validateCaptcha('death')) {
// //captchaInput.classList.add('is-invalid');
// //captchaInput.focus();
// return;
// } else {
// captchaInput.classList.remove('is-invalid');
// }
// const formattedDod = dod.split("-").reverse().join("/"); // Convert yyyy-MM-dd to dd/MM/yyyy
// // console.log("dod:", formattedDod);
// $('#pageLoader').show();
// $.ajax({
// url: '/crs/api/death-details',
// method: 'GET',
// data: {
// dod: formattedDod,
// sex: gender.charAt(0).toUpperCase()
// },
// success: function (response) {
// $('#pageLoader').hide();
// if (response && response.DEATH && response.DEATH.length > 0) {
// let html = '<table id="deathDataTable" class="table table-bordered"><thead><tr>' +
// '<th>S.No</th><th>Reg No</th><th>Person Name</th>' +
// '<th>Father Name</th><th>Mother Name</th><th>DOD</th><th>Certificate Link</th></tr></thead><tbody>';
// response.DEATH.forEach((row ,index) => {
// html += `<tr>
// <td>${index + 1}</td>
// <td>${row.REGNO}</td>
// <td>${row.DEATHPERSONNAME}</td>
// <td>${row.FATHERNAME}</td>
// <td>${row.MOTHERNAME}</td>
// <td>${row.DOD}</td>
// <td>${row.ENGLISHURL ? `<a href="${row.ENGLISHURL}" target="_blank"
// onclick="saveCertificateLog('${row.REGNO}', '${row.DOD}', '${row.ENGLISHURL}', 'Death')">View</a>` : 'N/A'}</td> </tr>`;
// });
// html += '</tbody></table>';
// $('#deathModalBody').html(html);
// // Delay initialization to ensure DOM is ready
// setTimeout(() => {
// $('#deathDataTable').DataTable({
// responsive: true,
// pagingType: "full_numbers", // Buttons for pagination
// language: {
// search: "🔍 Search: ",
// emptyTable: "No records found",
// paginate: {
// previous: "<button class='btn btn-outline-primary btn-sm'>Previous</button>",
// next: "<button class='btn btn-outline-primary btn-sm'>Next</button>"
// }
// },
// columnDefs: [
// { orderable: false, targets: 0 } // Disable sorting on S.No
// ]
// });
// }, 100);
// } else {
// $('#deathModalBody').html('<p class="text-danger">No deathrecords found.</p>');
// }
// const modal = new bootstrap.Modal(document.getElementById('deathModal'));
// modal.show();
// },
// error: function (xhr) {
// $('#pageLoader').hide();
// let message = "Something went wrong.";
// if (xhr.responseJSON && xhr.responseJSON.message) {
// message = xhr.responseJSON.message;
// }
// alert("Error: " + message);
// }
// });
// }
// using for local testin from restapiservices
function fetchDeathData() {
const dod = document.getElementById('dateofdeath').value;
const gender = document.querySelector('input[name="deathgender"]:checked')?.value;
const captchaInput = document.getElementById('death-captcha-input');
const fatherName = document.getElementById('deathfathername')?.value || "";
const motherName = document.getElementById('deathmothername')?.value || "";
const personName = document.getElementById('personname')?.value || "";
// console.log("gender:", gender);
@ -1108,8 +1224,8 @@ const captchaInput = document.getElementById('death-captcha-input');
if (!dod) {
Swal.fire({
icon: 'warning',
title: 'Missing Date of Birth',
text: 'Please enter your Date of Birth.'
title: 'Missing Date of Death',
text: 'Please enter your Date of Death.'
});
return;
}
@ -1138,31 +1254,40 @@ const formattedDod = dod.split("-").reverse().join("/"); // Convert yyyy-MM-dd t
// console.log("dod:", formattedDod);
$('#pageLoader').show();
const payload = {
dod: dod,
sex: gender.charAt(0).toUpperCase()
};
if (fatherName.trim()) payload.fathername = fatherName.trim();
if (motherName.trim()) payload.mothername = motherName.trim();
if (personName.trim()) payload.personName = personName.trim();
$.ajax({
url: '/crs/api/death-details',
method: 'GET',
data: {
dod: formattedDod,
sex: gender.charAt(0).toUpperCase()
},
method: 'POST',
contentType: 'application/json',
data: JSON.stringify(payload),
success: function (response) {
$('#pageLoader').hide();
if (response && response.DEATH && response.DEATH.length > 0) {
if (response && response.certificate_details && response.certificate_details.length > 0) {
let html = '<table id="deathDataTable" class="table table-bordered"><thead><tr>' +
'<th>S.No</th><th>Reg No</th><th>Person Name</th>' +
'<th>Father Name</th><th>Mother Name</th><th>DOD</th><th>Certificate Link</th></tr></thead><tbody>';
response.DEATH.forEach((row ,index) => {
response.certificate_details.forEach((row ,index) => {
html += `<tr>
<td>${index + 1}</td>
<td>${row.REGNO}</td>
<td>${row.DEATHPERSONNAME}</td>
<td>${row.FATHERNAME}</td>
<td>${row.MOTHERNAME}</td>
<td>${row.DOD}</td>
<td>${row.ENGLISHURL ? `<a href="${row.ENGLISHURL}" target="_blank"
onclick="saveCertificateLog('${row.REGNO}', '${row.DOD}', '${row.ENGLISHURL}', 'Death')">View</a>` : 'N/A'}</td> </tr>`;
<td>${row.regno}</td>
<td>${row.name}</td>
<td>${row.father_name}</td>
<td>${row.mother_name}</td>
<td>${row.dod}</td>
<td><a href="${row.pdf_url}" target="_blank"
onclick="saveCertificateLog('${row.regno}', '${row.dod}', '${row.pdf_url}', 'Death')">View</a></td>
</tr>`;
});
html += '</tbody></table>';
@ -1207,7 +1332,6 @@ $.ajax({
function saveCertificateLog(regNo, eventDate, url, service){
$.ajax({
url: '/crs/api/saveCertificateLogs',

49
src/main/resources/templates/modules/crslogspages/message.html

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title th:text="${title} ?: 'Message'">Message</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body { background: #f8fafc; color: #333; font-family: 'Segoe UI', Arial, sans-serif; margin: 0; }
.center-box {
max-width: 400px;
margin: 80px auto;
background: #fff;
border-radius: 12px;
box-shadow: 0 2px 16px #0001;
padding: 40px 30px 30px 30px;
text-align: center;
}
.center-box h1 { font-size: 3rem; color: #007bff; margin: 0 0 10px 0; }
.center-box h2 { font-size: 1.5rem; margin: 0 0 10px 0; }
.center-box p { color: #666; margin-bottom: 30px; }
.btn-home {
display: inline-block;
background: #007bff;
color: #fff;
padding: 12px 32px;
border-radius: 6px;
text-decoration: none;
font-size: 1.1rem;
transition: background 0.2s;
}
.btn-home:hover { background: #0056b3; }
@media (max-width: 600px) {
.center-box { padding: 25px 10px; }
.center-box h1 { font-size: 2rem; }
}
</style>
</head>
<body>
<div class="center-box">
<h1 th:text="${code} ?: 'Info'">Info</h1>
<h2 th:text="${title} ?: 'Message'">Message</h2>
<p th:text="${message} ?: 'No details provided.'">No details provided.</p>
<a href="/crs/birthloginpage" class="btn-home">Go to Home</a>
</div>
<script>
setTimeout(() => { window.location.href = '/crs/birthloginpage'; }, 10000);
</script>
</body>
</html>
Loading…
Cancel
Save