diff --git a/src/main/java/com/gcc/flagpoles/configuration/DataSourceConfig.java b/src/main/java/com/gcc/flagpoles/configuration/DataSourceConfig.java index beb559d..b76562b 100644 --- a/src/main/java/com/gcc/flagpoles/configuration/DataSourceConfig.java +++ b/src/main/java/com/gcc/flagpoles/configuration/DataSourceConfig.java @@ -22,7 +22,7 @@ public class DataSourceConfig { private static final String host = "localhost"; private static final String dbpassword = "root"; - // For AWS + // // For AWS // private static String host = // "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; // private static String dbpassword = "gcc-facial-password"; diff --git a/src/main/java/com/gcc/flagpoles/constants/AppConstants.java b/src/main/java/com/gcc/flagpoles/constants/AppConstants.java index 73ec15c..c1f06e9 100644 --- a/src/main/java/com/gcc/flagpoles/constants/AppConstants.java +++ b/src/main/java/com/gcc/flagpoles/constants/AppConstants.java @@ -1,15 +1,12 @@ package com.gcc.flagpoles.constants; public final class AppConstants { - // for Production -// public static String key_id="rzp_live_66FhxMUNAb9McO"; -// public static String key_secret="aoIzMGQE3xOxin92rYaK75jV"; + // for Production from coworking space booking key_id key_secret + // public static String key_id = "rzp_live_ySI5Ns54Y7qOcJ"; + // public static String key_secret = "Nwf1TjhUtaskof8vePkRR8Sb"; + // uncomment for testing payment + public static String key_id = "rzp_test_tDkHFEqWXmuEi8"; + public static String key_secret = "cBQUjMcKZ4J6vmOKSyNZ92py"; - //uncomment for testing payment - public static String key_id="rzp_test_TADBzz8BXbBpos"; - public static String key_secret="3es3YZ3DFVYdibbGLBtL8nBB"; - - - -} +} \ No newline at end of file diff --git a/src/main/java/com/gcc/flagpoles/controller/ApiController.java b/src/main/java/com/gcc/flagpoles/controller/ApiController.java index 67b9fe8..99f2c6c 100644 --- a/src/main/java/com/gcc/flagpoles/controller/ApiController.java +++ b/src/main/java/com/gcc/flagpoles/controller/ApiController.java @@ -14,6 +14,7 @@ import java.util.Random; import com.gcc.flagpoles.configuration.AppConfig; //import org.json.JSONObject; import com.gcc.flagpoles.constants.AppConstants; +import com.gcc.flagpoles.service.FileUploadService; import com.gcc.flagpoles.service.PaymentService; import com.razorpay.Order; import com.razorpay.RazorpayClient; @@ -22,6 +23,7 @@ import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.transaction.annotation.Transactional; @@ -67,6 +69,9 @@ public class ApiController { @Autowired private PaymentService paymentService; + @Autowired + private FileUploadService fileUploadService; + // @Autowired // private PaymentService paymentService ; @@ -90,7 +95,7 @@ public class ApiController { Random rand = new Random(); int otp = rand.nextInt(90000) + 10000; - //int otp = 22222; + // int otp = 22222; System.out.print("\n otp---:" + otp); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm"); LocalDateTime now = LocalDateTime.now(); @@ -180,7 +185,7 @@ public class ApiController { Random rand = new Random(); int otp = rand.nextInt(90000) + 10000; - //int otp = 22222; + // int otp = 22222; System.out.print("\n otp---:" + otp); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm"); LocalDateTime now = LocalDateTime.now(); @@ -262,10 +267,18 @@ public class ApiController { } } - @PostMapping("/saveRequest") - public ResponseEntity saveRequest(@RequestParam MultiValueMap params) { + @PostMapping(value = "/saveRequest", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public ResponseEntity saveRequest( + @RequestParam MultiValueMap params, + @RequestParam(required = false) MultipartFile aadhaarFile, + @RequestParam(required = false) MultipartFile pattaFile, + @RequestParam(required = false) MultipartFile affidavitFile, + @RequestParam(required = false) MultipartFile ecFile, + @RequestParam(required = false) MultipartFile fmbSketchFile) { + try { - // ✅ 1. Extract Applicant Info + /* ================= Applicant ================= */ + Map applicant = new HashMap<>(); applicant.put("name", params.getFirst("name")); applicant.put("mobileNumber", params.getFirst("mobileNumber")); @@ -278,26 +291,103 @@ public class ApiController { "message", "Applicant details are incomplete.")); } - // ✅ 2. Extract Event Info (with cost-related fields) + String aadhaarNo = params.getFirst("aadhaarNo"); + + if (aadhaarNo == null || !aadhaarNo.matches("\\d{12}")) { + return ResponseEntity.badRequest().body(Map.of( + "status", "error", + "message", "Valid Aadhaar number is mandatory.")); + } + + /* ================= Application ================= */ + + String applicationType = params.getFirst("applicationType"); // 1 TEMP, 2 PERMANENT + String applicationOption = params.getFirst("applicationOption"); // 1 Pole, 2 Statue + + if (applicationType == null) { + return ResponseEntity.badRequest().body(Map.of( + "status", "error", + "message", "Application Type is required.")); + } + + // Validation for Permanent Application fields + if ("2".equals(applicationType)) { + if (params.getFirst("surveyNo") == null || params.getFirst("surveyNo").trim().isEmpty()) { + return ResponseEntity.badRequest() + .body(Map.of("status", "error", "message", "Survey Number is required.")); + } + if (params.getFirst("placeOfErection") == null || params.getFirst("placeOfErection").trim().isEmpty()) { + return ResponseEntity.badRequest() + .body(Map.of("status", "error", "message", "Place of Erection is required.")); + } + } + + /* ================= FILE UPLOAD (PERMANENT ONLY) ================= */ + + String aadhaarPath = null; + String pattaPath = null; + String affidavitPath = null; + String ecPath = null; + String fmbPath = null; + + if ("2".equals(applicationType)) { + + if (aadhaarFile != null && !aadhaarFile.isEmpty()) + aadhaarPath = fileUploadService.fileUpload(aadhaarFile, "aadhaar"); + + if (pattaFile != null && !pattaFile.isEmpty()) + pattaPath = fileUploadService.fileUpload(pattaFile, "patta"); + + if (affidavitFile != null && !affidavitFile.isEmpty()) + affidavitPath = fileUploadService.fileUpload(affidavitFile, "affidavit"); + + if (ecFile != null && !ecFile.isEmpty()) + ecPath = fileUploadService.fileUpload(ecFile, "ec"); + + if (fmbSketchFile != null && !fmbSketchFile.isEmpty()) + fmbPath = fileUploadService.fileUpload(fmbSketchFile, "fmb"); + } + + // Inject paths for service layer + params.set("aadhaarImagePath", aadhaarPath); + params.set("pattaImagePath", pattaPath); + params.set("affidavitImagePath", affidavitPath); + params.set("ecImagePath", ecPath); + params.set("fmbSketchPath", fmbPath); + + /* ================= Event ================= */ + Map event = new HashMap<>(); event.put("type", params.getFirst("eventType")); event.put("date", params.getFirst("eventDate")); event.put("description", params.getFirst("description")); event.put("totalPoles", params.getFirst("totalPoles")); - // event.put("deposit", params.getFirst("deposit")); event.put("totalCost", params.getFirst("totalCost")); - if (event.get("type") == null || event.get("date") == null || event.get("description") == null) { - return ResponseEntity.badRequest().body(Map.of( - "status", "error", - "message", "Event details are incomplete.")); + if (!"2".equals(applicationType)) { + if (event.get("type") == null || event.get("date") == null || event.get("description") == null) { + return ResponseEntity.badRequest().body(Map.of( + "status", "error", + "message", "Event details are incomplete.")); + } + } + + /* ================= Statue Count ================= */ + + if ("2".equals(applicationType) && "2".equals(applicationOption)) { + event.put("totalStatue", "1"); + event.put("totalPoles", "0"); + } else { + event.put("totalStatue", "0"); } - // ✅ 3. Build List of Streets + /* ================= Streets ================= */ + List> streets = new ArrayList<>(); int index = 0; - String globalRatePerPole = params.getFirst("ratePerPole"); // top-level + String globalRatePerPole = params.getFirst("ratePerPole"); + while (true) { String prefix = "streets[" + index + "]."; if (params.getFirst(prefix + "streetName") == null) @@ -310,18 +400,16 @@ public class ApiController { s.put("noOfPoles", params.getFirst(prefix + "noOfPoles")); s.put("poleHeight", params.getFirst(prefix + "poleHeight")); s.put("poleMaterial", params.getFirst(prefix + "poleMaterial")); + s.put("pedestalMaterial", params.getFirst(prefix + "pedestalMaterial")); + s.put("statueMaterial", params.getFirst(prefix + "statueMaterial")); s.put("flagMaterial", params.getFirst(prefix + "flagMaterial")); - s.put("spacing", params.getFirst(prefix + "spacing")); s.put("durationDays", params.getFirst(prefix + "durationDays")); - - // ✅ Ensure latitude/longitude keys match your service s.put("lat", params.getFirst(prefix + "lat")); s.put("long", params.getFirst(prefix + "long")); - // ✅ Fix here: use top-level rate if per-street is null + String rate = params.getFirst(prefix + "ratePerPole"); s.put("ratePerPole", rate != null ? rate : globalRatePerPole); - // ⚙️ Optional validation if (s.get("lat") == null || s.get("long") == null) { return ResponseEntity.badRequest().body(Map.of( "status", "error", @@ -335,31 +423,35 @@ public class ApiController { if (streets.isEmpty()) { return ResponseEntity.badRequest().body(Map.of( "status", "error", - "message", "No street data found in request.")); + "message", "No street data found.")); + } + + if ("2".equals(applicationType) && streets.size() > 1) { + streets = streets.subList(0, 1); } - // System.out.println("applicant" + applicant); - // System.out.println("streets" + streets); - // System.out.println("events" + event); - // ✅ 4. Save request (Service internally checks for nearby requests) - // String userReqId = requestService.saveFlagPoleRequest(applicant, event, - // streets); - String tempRefId = requestService.saveTempBooking(applicant, event, streets); + /* ================= Save ================= */ + + String refId; + + if ("2".equals(applicationType)) { + refId = requestService.savePermanentRequest(applicant, event, streets, params); + } else { + refId = requestService.saveTempBooking(applicant, event, streets, params); + } - // ✅ 5. Return Success Response return ResponseEntity.ok(Map.of( "status", "success", "message", "Application saved successfully.", - "request_id", tempRefId)); + "request_id", refId)); } catch (IllegalArgumentException iae) { - // ⛔ Custom validation or nearby request check failure + return ResponseEntity.badRequest().body(Map.of( "status", "error", "message", iae.getMessage())); } catch (Exception e) { - // ⛔ Unexpected errors e.printStackTrace(); return ResponseEntity.internalServerError().body(Map.of( "status", "error", diff --git a/src/main/java/com/gcc/flagpoles/controller/DateTimeUtil.java b/src/main/java/com/gcc/flagpoles/controller/DateTimeUtil.java deleted file mode 100644 index 2da3382..0000000 --- a/src/main/java/com/gcc/flagpoles/controller/DateTimeUtil.java +++ /dev/null @@ -1,35 +0,0 @@ -// package com.gcc.flagpoles.controller; - -// import org.springframework.stereotype.Service; - -// import java.time.LocalDateTime; -// import java.time.format.DateTimeFormatter; - -// @Service -// public class DateTimeUtil { -// public static String getCurrentDateTime() { -// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ddMMyyyyHHmmss"); -// LocalDateTime now = LocalDateTime.now(); -// return now.format(formatter); -// } -// public static String getCurrentYear() { -// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy"); -// LocalDateTime now = LocalDateTime.now(); -// return now.format(formatter); -// } -// public static String getCurrentMonth() { -// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM"); -// LocalDateTime now = LocalDateTime.now(); -// return now.format(formatter); -// } -// public static String getCurrentDay() { -// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd"); -// LocalDateTime now = LocalDateTime.now(); -// return now.format(formatter); -// } -// public static String getCurrentDateTimeMysql() { -// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); -// LocalDateTime now = LocalDateTime.now(); -// return now.format(formatter); -// } -// } diff --git a/src/main/java/com/gcc/flagpoles/controller/DropDownApiController.java b/src/main/java/com/gcc/flagpoles/controller/DropDownApiController.java index 58d80a3..bfecc6d 100644 --- a/src/main/java/com/gcc/flagpoles/controller/DropDownApiController.java +++ b/src/main/java/com/gcc/flagpoles/controller/DropDownApiController.java @@ -74,4 +74,33 @@ public class DropDownApiController { } } + // get application type + @GetMapping("/getapplicationtype") + public List> getapplicationtype() { + return dropDownService.getApplicationType(); + } + + // get application type + @GetMapping("/getinstallationtype") + public List> getInstallationType() { + return dropDownService.getInstallationType(); + } + + // get application type + @GetMapping("/getapplicationoption") + public List> getApplicationOption() { + return dropDownService.getApplicationOption(); + } + + // get application type + @GetMapping("/getpedestalmaterial") + public List> getPedestalMaterial() { + return dropDownService.getPedestalMaterial(); + } + + @GetMapping("/getstatuematerial") + public List> getStatueMaterial() { + return dropDownService.getStatueMaterial(); + } + } diff --git a/src/main/java/com/gcc/flagpoles/service/DateTimeUtil.java b/src/main/java/com/gcc/flagpoles/service/DateTimeUtil.java new file mode 100644 index 0000000..db7185a --- /dev/null +++ b/src/main/java/com/gcc/flagpoles/service/DateTimeUtil.java @@ -0,0 +1,39 @@ +package com.gcc.flagpoles.service; + +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +@Service +public class DateTimeUtil { + public static String getCurrentDateTime() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ddMMyyyyHHmmss"); + LocalDateTime now = LocalDateTime.now(); + return now.format(formatter); + } + + public static String getCurrentYear() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy"); + LocalDateTime now = LocalDateTime.now(); + return now.format(formatter); + } + + public static String getCurrentMonth() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM"); + LocalDateTime now = LocalDateTime.now(); + return now.format(formatter); + } + + public static String getCurrentDay() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd"); + LocalDateTime now = LocalDateTime.now(); + return now.format(formatter); + } + + public static String getCurrentDateTimeMysql() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime now = LocalDateTime.now(); + return now.format(formatter); + } +} diff --git a/src/main/java/com/gcc/flagpoles/service/DropDownService.java b/src/main/java/com/gcc/flagpoles/service/DropDownService.java index 28ccfcd..8ff93f3 100644 --- a/src/main/java/com/gcc/flagpoles/service/DropDownService.java +++ b/src/main/java/com/gcc/flagpoles/service/DropDownService.java @@ -190,4 +190,29 @@ public class DropDownService { String sql = "SELECT id, ward_name FROM wards WHERE zone_id = ? AND is_active = 1 "; return mysqlJdbcTemplate.queryForList(sql, zoneId); } + + public List> getApplicationType() { + String sql = "SELECT id, type FROM application_type WHERE is_active = 1 "; + return mysqlJdbcTemplate.queryForList(sql); + } + + public List> getApplicationOption() { + String sql = "SELECT id, option_name FROM application_option WHERE is_active = 1 "; + return mysqlJdbcTemplate.queryForList(sql); + } + + public List> getInstallationType() { + String sql = "SELECT id, installation_name FROM installation_type WHERE is_active = 1 and is_delete = 0"; + return mysqlJdbcTemplate.queryForList(sql); + } + + public List> getStatueMaterial() { + String sql = "SELECT id, statue_material_type FROM statue_material WHERE is_active = 1 and is_delete = 0"; + return mysqlJdbcTemplate.queryForList(sql); + } + + public List> getPedestalMaterial() { + String sql = "SELECT id, statue_pedestal_type FROM pedestal_material WHERE is_active = 1 and is_delete = 0"; + return mysqlJdbcTemplate.queryForList(sql); + } } diff --git a/src/main/java/com/gcc/flagpoles/service/FileUploadService.java b/src/main/java/com/gcc/flagpoles/service/FileUploadService.java new file mode 100644 index 0000000..9719c41 --- /dev/null +++ b/src/main/java/com/gcc/flagpoles/service/FileUploadService.java @@ -0,0 +1,118 @@ +package com.gcc.flagpoles.service; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +@Service +public class FileUploadService { + + @Autowired + private Environment environment; + + // public String fileUpload(MultipartFile file, String name) { + + // String uploadDirectory = + // environment.getProperty("file.upload.directory.mobile"); + // String serviceFolderName = environment.getProperty("flagpoles_foldername"); + + // if (uploadDirectory == null || serviceFolderName == null) { + // throw new RuntimeException("Upload directory or service folder not + // configured"); + // } + + // var year = DateTimeUtil.getCurrentYear(); + // var month = DateTimeUtil.getCurrentMonth(); + + // uploadDirectory = uploadDirectory + serviceFolderName + "/" + year + "/" + + // month + "/" +doctype; + + // try { + // // Create folders if not exist + // Path directoryPath = Paths.get(uploadDirectory); + // if (!Files.exists(directoryPath)) { + // Files.createDirectories(directoryPath); + // } + + // // Datetime string + // String datetimetxt = DateTimeUtil.getCurrentDateTime(); + + // // File name + // String fileName = name + "_" + datetimetxt + "_" + + // file.getOriginalFilename(); + // fileName = fileName.replaceAll("\\s+", ""); // Remove space on filename + + // String filePath = uploadDirectory + "/" + fileName; + + // String filepath_txt = "/" + serviceFolderName + "/" + year + "/" + month + + // "/" + fileName; + + // // Create a new Path object + // Path path = Paths.get(filePath); + + // // Get the bytes of the file + // byte[] bytes = file.getBytes(); + + // Files.write(path, bytes); + + // // System.out.println(filePath); + // return filepath_txt; + + // } catch (IOException e) { + // throw new RuntimeException("Failed to upload file: " + + // file.getOriginalFilename(), e); + // } + // } + + public String fileUpload(MultipartFile file, String docType) { + + String uploadDirectory = environment.getProperty("file.upload.directory"); + String serviceFolderName = environment.getProperty("flagpoles_foldername"); + + if (uploadDirectory == null || serviceFolderName == null) { + throw new RuntimeException("Upload directory or service folder not configured"); + } + + String year = DateTimeUtil.getCurrentYear(); + String month = DateTimeUtil.getCurrentMonth(); + + // 👉 base + service + year + month + documentType + String finalUploadDir = uploadDirectory + serviceFolderName + "/" + year + "/" + month + "/" + docType; + + try { + + // Create directory tree + Path directoryPath = Paths.get(finalUploadDir); + if (!Files.exists(directoryPath)) { + Files.createDirectories(directoryPath); + } + + String datetimetxt = DateTimeUtil.getCurrentDateTime(); + + String originalName = file.getOriginalFilename(); + originalName = originalName == null ? "file" : originalName.replaceAll("\\s+", ""); + + String fileName = docType + "_" + datetimetxt + "_" + originalName; + + Path filePath = Paths.get(finalUploadDir + "/" + fileName); + + Files.write(filePath, file.getBytes()); + + // 👉 Path saved to DB (must include docType) + return "/" + serviceFolderName + "/" + year + "/" + month + "/" + docType + "/" + fileName; + + } catch (IOException e) { + throw new RuntimeException("Failed to upload file: " + file.getOriginalFilename(), e); + } + } + +} diff --git a/src/main/java/com/gcc/flagpoles/service/RequestService.java b/src/main/java/com/gcc/flagpoles/service/RequestService.java index 2f442d4..b897687 100644 --- a/src/main/java/com/gcc/flagpoles/service/RequestService.java +++ b/src/main/java/com/gcc/flagpoles/service/RequestService.java @@ -70,8 +70,8 @@ public class RequestService { INSERT INTO user_request_details (applicant_name, mobile_number, applicant_address, event_id, event_date, event_desc, no_of_days, - total_poles, total_cost,payment_status) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,?) + total_poles, total_cost,application_type,payment_status) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,?,?) """; KeyHolder keyHolder = new GeneratedKeyHolder(); @@ -91,7 +91,8 @@ public class RequestService { ps.setInt(8, Integer.parseInt(event.get("totalPoles").toString())); // ps.setDouble(9, deposit); ps.setDouble(9, Double.parseDouble(event.get("totalCost").toString())); - ps.setString(10, paymentstatus); + ps.setInt(10, 1); + ps.setString(11, paymentstatus); return ps; }, keyHolder); @@ -147,32 +148,41 @@ public class RequestService { public String saveTempBooking( Map applicant, Map event, - List> streets) { + List> streets, + MultiValueMap params) { // 1️⃣ Insert TEMP booking (without refid) KeyHolder keyHolder = new GeneratedKeyHolder(); mysqlJdbcTemplate.update(con -> { PreparedStatement ps = con.prepareStatement(""" - INSERT INTO temp_booking - ( - applicant_name, - mobile_number, - applicant_address, - event_id, - event_date, - event_desc, - no_of_days, - total_poles, - deposit, - total_cost, - payment_status, - booking_status, - is_active, - is_delete - ) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'PENDING', 'INITIATED', 1, 0) - """, Statement.RETURN_GENERATED_KEYS); + INSERT INTO temp_booking + ( + applicant_name, + mobile_number, + applicant_address, + event_id, + event_date, + event_desc, + no_of_days, + total_poles, + deposit, + total_cost, + + application_type, + aadhaar_no, + aadhaar_image_path, + + payment_status, + booking_status, + is_active, + is_delete + ) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, + 'PENDING', 'INITIATED', 1, 0) + + """, Statement.RETURN_GENERATED_KEYS); ps.setString(1, applicant.get("name").toString()); ps.setString(2, applicant.get("mobileNumber").toString()); @@ -184,6 +194,11 @@ public class RequestService { ps.setInt(8, Integer.parseInt(event.get("totalPoles").toString())); ps.setDouble(9, 0.0); ps.setDouble(10, Double.parseDouble(event.get("totalCost").toString())); + + ps.setInt(11, Integer.parseInt(params.getFirst("applicationType"))); + ps.setString(12, params.getFirst("aadhaarNo")); + ps.setString(13, params.getFirst("aadhaarImagePath")); + return ps; }, keyHolder); @@ -238,6 +253,206 @@ public class RequestService { return tempRefId; } + @Transactional(transactionManager = "mysqlgccFlagPoleTransactionManager") + public String savePermanentRequest( + Map applicant, + Map event, + List> streets, + MultiValueMap params) { + + KeyHolder kh = new GeneratedKeyHolder(); + + // ---------- SAFE FINAL VALUES (lambda compatible) ---------- + final Integer eventType = (event.get("type") != null && !event.get("type").toString().isBlank()) + ? Integer.parseInt(event.get("type").toString()) + : null; + + final int totalPoles = (event.get("totalPoles") != null && !event.get("totalPoles").toString().isBlank()) + ? Integer.parseInt(event.get("totalPoles").toString()) + : 0; + + final int totalStatue = (event.get("totalStatue") != null && !event.get("totalStatue").toString().isBlank()) + ? Integer.parseInt(event.get("totalStatue").toString()) + : 0; + + final double totalCost = (event.get("totalCost") != null && !event.get("totalCost").toString().isBlank()) + ? Double.parseDouble(event.get("totalCost").toString()) + : 0.0; + + // ---------- SAFE EVENT DATE & DESC ---------- + final String eventDate = (event.get("date") != null && !event.get("date").toString().isBlank()) + ? event.get("date").toString() + : null; + + final String eventDesc = (event.get("description") != null && !event.get("description").toString().isBlank()) + ? event.get("description").toString() + : null; + + mysqlJdbcTemplate.update(con -> { + + PreparedStatement ps = con.prepareStatement(""" + INSERT INTO user_request_details + ( + applicant_name, + mobile_number, + applicant_address, + event_id, + event_date, + event_desc, + no_of_days, + total_poles, + total_statue, + total_cost, + + application_type, + application_option, + installation_type, + + aadhaar_no, + aadhaar_image_path, + + survey_no, + place_of_erection, + others_specify_statue_material, + patta_image_path, + affidavit_image_path, + ec_image_path, + fmb_sketch_path, + + cdate, + payment_status, + booking_status + ) + VALUES (?,?,?,?,?,?,?,?,?,?, + ?,?,?, + ?,?, + ?,?,?,?,?,?,?, + NOW(),'NA','PERMANENT') + """, Statement.RETURN_GENERATED_KEYS); + + // ---------- Applicant ---------- + ps.setString(1, applicant.get("name").toString()); + ps.setString(2, applicant.get("mobileNumber").toString()); + ps.setString(3, applicant.get("address").toString()); + + // ---------- Event (NULL for permanent) ---------- + ps.setObject(4, eventType); + ps.setString(5, eventDate); + ps.setString(6, eventDesc); + + // ---------- Days ---------- + ps.setInt(7, getFirstStreetDays(streets)); + + ps.setInt(8, totalPoles); + ps.setInt(9, totalStatue); + ps.setDouble(10, totalCost); + + // ---------- Masters ---------- + ps.setInt(11, 2); // PERMANENT + + ps.setObject(12, + params.getFirst("applicationOption") != null + ? Integer.parseInt(params.getFirst("applicationOption")) + : null); + + ps.setObject(13, + params.getFirst("installationType") != null + ? Integer.parseInt(params.getFirst("installationType")) + : null); + + // ---------- Aadhaar ---------- + ps.setString(14, params.getFirst("aadhaarNo")); + ps.setString(15, params.getFirst("aadhaarImagePath")); + + // ---------- Permanent extra ---------- + ps.setString(16, params.getFirst("surveyNo")); + ps.setString(17, params.getFirst("placeOfErection")); + ps.setString(18, params.getFirst("otherStatueMaterial")); + ps.setString(19, params.getFirst("pattaImagePath")); + ps.setString(20, params.getFirst("affidavitImagePath")); + ps.setString(21, params.getFirst("ecImagePath")); + ps.setString(22, params.getFirst("fmbSketchPath")); + + return ps; + + }, kh); + + int id = kh.getKey().intValue(); + + // ---------- REFID ---------- + String refId = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + id; + + mysqlJdbcTemplate.update(""" + UPDATE user_request_details + SET refid = ? + WHERE id = ? + """, refId, id); + + // ---------- Streets ---------- + boolean isStatue = "2".equals(params.getFirst("applicationOption")); + + for (Map s : streets) { + + int noOfPoles = 0; + int noOfStatue = 0; + + if (isStatue) { + noOfStatue = 1; + } else { + noOfPoles = Integer.parseInt(s.get("noOfPoles").toString()); + } + + mysqlJdbcTemplate.update(""" + INSERT INTO street_details + ( + street_name, + latitude, + longitude, + zone, + ward, + no_of_poles, + no_of_statue, + height, + pole_material_id, + flag_material_id, + pedestal_material_id, + statue_material_id, + no_of_days, + street_cost, + user_req_id, + refid + ) + VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) + """, + s.get("streetName"), + s.get("lat"), + s.get("long"), + s.get("zoneId"), + s.get("wardId"), + noOfPoles, + noOfStatue, + + // height + s.get("poleHeight"), + + // pole + flag + s.get("poleMaterial"), + s.get("flagMaterial"), + + // 👇 NEW + s.get("pedestalMaterial"), + s.get("statueMaterial"), + + s.get("durationDays"), + s.get("ratePerPole"), + id, + refId); + + } + + return refId; + } + @Transactional(transactionManager = "mysqlgccFlagPoleTransactionManager") public String moveTempToFinal(String tempRefId) { @@ -255,6 +470,7 @@ public class RequestService { total_poles, deposit, total_cost, + application_type, cdate, payment_status, booking_status @@ -270,6 +486,7 @@ public class RequestService { total_poles, deposit, total_cost, + application_type, NOW(), 'COMPLETED', booking_status @@ -536,7 +753,8 @@ public class RequestService { DATE_FORMAT(ud.event_date,'%d-%m-%Y') AS event_date, DATE_FORMAT(ud.cdate,'%d-%m-%Y') AS cdate, ud.total_poles, - ud.no_of_days + ud.no_of_days, + ud.application_type FROM temp_booking ud @@ -620,6 +838,7 @@ public class RequestService { DATE_FORMAT(urd.cdate,'%d-%m-%Y') AS cdate, urd.total_poles, urd.no_of_days, + urd.application_type, p.payment_id, p.paymentstatus, @@ -830,6 +1049,125 @@ public class RequestService { // return new ArrayList<>(resultMap.values()); // } + // old + // @Transactional(transactionManager = "mysqlgccFlagPoleTransactionManager") + // public List> searchRequestsByRefIdOrMobile( + // String refId, + // String mobileNumber) { + + // StringBuilder sql = new StringBuilder(""" + // SELECT + // urd.id, + // urd.applicant_name, + // urd.mobile_number, + // urd.applicant_address, + // urd.event_date, + // urd.ae_status, + // urd.rdo_status, + // urd.no_of_days, + // urd.rdo_remarks, + // urd.refid, + // urd.payment_status, + // urd.booking_status, + // urd.cdate, + // urd.approved_date, + // urd.approved_by, + + // sd.street_name, + // sd.zone, + // sd.ward, + // sd.no_of_poles, + // sd.street_cost, + + // urd.total_cost, + // et.event_name, + + // IFNULL(fc.fine_amount, 0) AS fine_amount, + // IFNULL(rp.amount, 0) AS restoration_amount + + // FROM user_request_details urd + + // LEFT JOIN street_details sd + // ON urd.refid = sd.refid + // AND sd.is_active = 1 + // AND sd.is_delete = 0 + + // LEFT JOIN event_type et + // ON urd.event_id = et.id + + // LEFT JOIN fine_collection fc + // ON urd.refid = fc.ref_id + // AND fc.isactive = 1 + // AND fc.isdelete = 0 + + // LEFT JOIN restoration rp + // ON urd.refid = rp.ref_id + // AND rp.is_active = 1 + // AND rp.is_delete = 0 + + // WHERE 1 = 1 + // """); + + // List params = new ArrayList<>(); + + // // 🔹 Search priority: RefId first, else Mobile + // if (refId != null && !refId.trim().isEmpty()) { + // sql.append(" AND urd.refid = ? "); + // params.add(refId.trim()); + + // } else if (mobileNumber != null && !mobileNumber.trim().isEmpty()) { + // sql.append(" AND urd.mobile_number = ? "); + // params.add(mobileNumber.trim()); + // } + + // sql.append(" ORDER BY urd.cdate DESC, sd.id "); + + // List> rows = + // mysqlJdbcTemplate.queryForList(sql.toString(), params.toArray()); + + // // 🔥 GROUP BY REFID + // Map> resultMap = new LinkedHashMap<>(); + + // for (Map row : rows) { + + // String refid = (String) row.get("refid"); + + // Map request = resultMap.computeIfAbsent(refid, k -> { + // Map map = new LinkedHashMap<>(); + // map.put("refid", row.get("refid")); + // map.put("applicant_name", row.get("applicant_name")); + // map.put("mobile_number", row.get("mobile_number")); + // map.put("applicant_address", row.get("applicant_address")); + // map.put("event_date", row.get("event_date")); + // map.put("ae_status", row.get("ae_status")); + // map.put("rdo_status", row.get("rdo_status")); + // map.put("rdo_remarks", row.get("rdo_remarks")); + // map.put("approved_by", row.get("approved_by")); + // map.put("approved_date", row.get("approved_date")); + // map.put("no_of_days", row.get("no_of_days")); + // map.put("event_name", row.get("event_name")); + // map.put("total_cost", row.get("total_cost")); + // map.put("payment_status", row.get("payment_status")); + // map.put("booking_status", row.get("booking_status")); + // map.put("fine_amount", row.get("fine_amount")); + // map.put("restoration_amount", row.get("restoration_amount")); + // map.put("streets", new ArrayList<>()); + // return map; + // }); + + // Map street = new LinkedHashMap<>(); + // street.put("street_name", row.get("street_name")); + // street.put("zone", row.get("zone")); + // street.put("ward", row.get("ward")); + // street.put("no_of_poles", row.get("no_of_poles")); + // street.put("street_cost", row.get("street_cost")); + + // ((List>) request.get("streets")).add(street); + // } + + // return new ArrayList<>(resultMap.values()); + // } + @Transactional(transactionManager = "mysqlgccFlagPoleTransactionManager") public List> searchRequestsByRefIdOrMobile( String refId, @@ -844,18 +1182,37 @@ public class RequestService { urd.event_date, urd.ae_status, urd.rdo_status, + urd.final_status, -- NEW + urd.final_remarks, + urd.final_approved_by, -- OPTIONAL + urd.final_approved_date, -- OPTIONAL urd.no_of_days, urd.rdo_remarks, urd.refid, urd.payment_status, urd.booking_status, + urd.application_type, + urd.application_option, + urd.installation_type, + at.type AS application_type_name, -- MASTER JOIN + ao.option_name AS application_option_name, -- MASTER JOIN + it.installation_name AS installation_name, -- MASTER JOIN + urd.aadhaar_no, + urd.survey_no, + urd.place_of_erection, urd.cdate, + urd.approved_date, + urd.approved_by, sd.street_name, sd.zone, sd.ward, sd.no_of_poles, sd.street_cost, + pm.pole_material_name, -- MASTER JOIN + fm.flag_material_name, -- MASTER JOIN + sm.statue_material_type, -- MASTER JOIN + pdm.statue_pedestal_type, -- MASTER JOIN urd.total_cost, et.event_name, @@ -873,6 +1230,27 @@ public class RequestService { LEFT JOIN event_type et ON urd.event_id = et.id + LEFT JOIN application_type at + ON urd.application_type = at.id + + LEFT JOIN application_option ao + ON urd.application_option = ao.id + + LEFT JOIN installation_type it + ON urd.installation_type = it.id + + LEFT JOIN pole_material pm + ON sd.pole_material_id = pm.id + + LEFT JOIN flag_material fm + ON sd.flag_material_id = fm.id + + LEFT JOIN statue_material sm + ON sd.statue_material_id = sm.id + + LEFT JOIN pedestal_material pdm + ON sd.pedestal_material_id = pdm.id + LEFT JOIN fine_collection fc ON urd.refid = fc.ref_id AND fc.isactive = 1 @@ -918,12 +1296,27 @@ public class RequestService { map.put("event_date", row.get("event_date")); map.put("ae_status", row.get("ae_status")); map.put("rdo_status", row.get("rdo_status")); + map.put("final_status", row.get("final_status")); // ✅ NEW + map.put("final_remarks", row.get("final_remarks")); // ✅ NEW + map.put("final_approved_by", row.get("final_approved_by")); // ✅ OPTIONAL + map.put("final_approved_date", row.get("final_approved_date")); // ✅ OPTIONAL map.put("rdo_remarks", row.get("rdo_remarks")); + map.put("approved_by", row.get("approved_by")); + map.put("approved_date", row.get("approved_date")); map.put("no_of_days", row.get("no_of_days")); map.put("event_name", row.get("event_name")); map.put("total_cost", row.get("total_cost")); map.put("payment_status", row.get("payment_status")); map.put("booking_status", row.get("booking_status")); + map.put("application_type", row.get("application_type")); + map.put("application_type_name", row.get("application_type_name")); // ✅ NEW + map.put("application_option", row.get("application_option")); + map.put("application_option_name", row.get("application_option_name")); // ✅ NEW + map.put("installation_type", row.get("installation_type")); + map.put("installation_name", row.get("installation_name")); // ✅ NEW + map.put("aadhaar_no", row.get("aadhaar_no")); + map.put("survey_no", row.get("survey_no")); + map.put("place_of_erection", row.get("place_of_erection")); map.put("fine_amount", row.get("fine_amount")); map.put("restoration_amount", row.get("restoration_amount")); map.put("streets", new ArrayList<>()); @@ -936,6 +1329,10 @@ public class RequestService { street.put("ward", row.get("ward")); street.put("no_of_poles", row.get("no_of_poles")); street.put("street_cost", row.get("street_cost")); + street.put("pole_material_name", row.get("pole_material_name")); // ✅ NEW + street.put("flag_material_name", row.get("flag_material_name")); // ✅ NEW + street.put("statue_material_type", row.get("statue_material_type")); // ✅ NEW + street.put("statue_pedestal_type", row.get("statue_pedestal_type")); // ✅ NEW ((List>) request.get("streets")).add(street); } diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 6400f51..48d7fdd 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -15,6 +15,10 @@ server.port=8083 spring.servlet.multipart.max-file-size=20MB +flagpoles_foldername=flagpoles_files +file.upload.directory=${user.dir}/gccoffice_uploads/ + + # file.upload.directory=${user.dir}/gccoffice_uploads # file.dump.upload.directory=${user.dir}/cd_waste_docs/cdwaste_dump diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 21776f7..bdb3eb8 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -13,6 +13,11 @@ server.port=8083 spring.servlet.multipart.max-file-size=20MB +flagpoles_foldername=flagpoles_files +file.upload.directory=${user.dir}/gccoffice_uploads/ + +#file.upload.directory.mobile=${user.dir}/gcc_mobile_service_uploads/ + # file.upload.directory=${user.dir}/gccoffice_uploads # file.dump.upload.directory=${user.dir}/cd_waste_docs/cdwaste_dump diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7470be5..27056a3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,2 @@ #spring.profiles.active=prod -spring.profiles.active=dev \ No newline at end of file +spring.profiles.active=dev \ No newline at end of file diff --git a/src/main/resources/static/assets/images/logo.png b/src/main/resources/static/assets/images/logo.png new file mode 100644 index 0000000..e7decc5 Binary files /dev/null and b/src/main/resources/static/assets/images/logo.png differ diff --git a/src/main/resources/templates/fragments/details.html b/src/main/resources/templates/fragments/details.html index 8c76551..ae25c4d 100644 --- a/src/main/resources/templates/fragments/details.html +++ b/src/main/resources/templates/fragments/details.html @@ -104,6 +104,10 @@ th:text="${requestData.event_name}">

Event Date:

+

Application Type: + +

@@ -181,6 +185,22 @@ style="background: #FB6340; font-size:18px;">Download + + + +
+ +
+ diff --git a/src/main/resources/templates/modules/flagpolesregistration/acknowledgement.html b/src/main/resources/templates/modules/flagpolesregistration/acknowledgement.html index a6ee75f..deb92d8 100644 --- a/src/main/resources/templates/modules/flagpolesregistration/acknowledgement.html +++ b/src/main/resources/templates/modules/flagpolesregistration/acknowledgement.html @@ -91,6 +91,9 @@ }); } + function goBack() { + window.location.href = '/flagpolesregistration'; // Update the URL as per your project's structure + } function exportLicToPDF(details, requestId, format = 'a4', orientation = 'portrait') { diff --git a/src/main/resources/templates/modules/flagpolesregistration/index.html b/src/main/resources/templates/modules/flagpolesregistration/index.html index 4b39270..af156e7 100644 --- a/src/main/resources/templates/modules/flagpolesregistration/index.html +++ b/src/main/resources/templates/modules/flagpolesregistration/index.html @@ -1,123 +1,127 @@ + - - -GCC - FlagPoles - - - - - - - - - - - - - - - - + + + GCC - FlagPoles + + + + + + + + + + + + + + + + + - -
-
- - - - -
- GREATER CHENNAI CORPORATION -
- - - -
- - - - - - + - + + - + + \ No newline at end of file diff --git a/src/main/resources/templates/modules/flagpolesregistration/razor-pay.html b/src/main/resources/templates/modules/flagpolesregistration/razor-pay.html index 4dca2ad..dff6f9a 100644 --- a/src/main/resources/templates/modules/flagpolesregistration/razor-pay.html +++ b/src/main/resources/templates/modules/flagpolesregistration/razor-pay.html @@ -29,8 +29,8 @@ console.log(response); if (response.status == "created") { let options = { - "key": "rzp_test_TADBzz8BXbBpos", // for development - //"key": "rzp_live_66FhxMUNAb9McO", // for production + "key": "rzp_test_tDkHFEqWXmuEi8", // for development + //"key": "rzp_live_ySI5Ns54Y7qOcJ", // for production "amount": response.amount, // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise "currency": "INR", "name": "Greater Chennai Corporation", diff --git a/src/main/resources/templates/modules/flagpolesregistration/requestform.html b/src/main/resources/templates/modules/flagpolesregistration/requestform.html index 51bf9e2..590c6a0 100644 --- a/src/main/resources/templates/modules/flagpolesregistration/requestform.html +++ b/src/main/resources/templates/modules/flagpolesregistration/requestform.html @@ -266,7 +266,7 @@ -
- + -->
-
Application form for erection of temporary flag poles:-
+
Application form for erection of Flag poles / Statue:-
@@ -305,23 +305,71 @@
-
+ +
+ + +
+ + +
+ + + +
+
-
-
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
-
+
+ - - + @@ -650,22 +1010,20 @@ - -