diff --git a/src/main/java/com/gcc/swm_services/configuration/DataSourceConfig.java b/src/main/java/com/gcc/swm_services/configuration/DataSourceConfig.java index 60cd25b..f0de302 100644 --- a/src/main/java/com/gcc/swm_services/configuration/DataSourceConfig.java +++ b/src/main/java/com/gcc/swm_services/configuration/DataSourceConfig.java @@ -23,12 +23,13 @@ import java.util.Properties; public class DataSourceConfig { // local - // private static String host = "localhost:3306"; - // private static String dbpassword = "root"; + private static String host = "localhost:3306"; + private static String dbpassword = "root"; // 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"; + // private static String host = + // "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; + // private static String dbpassword = "gcc-facial-password"; @Configuration @EnableTransactionManagement diff --git a/src/main/java/com/gcc/swm_services/swm/controller/MainController.java b/src/main/java/com/gcc/swm_services/swm/controller/MainController.java index b689b74..8cf3cac 100644 --- a/src/main/java/com/gcc/swm_services/swm/controller/MainController.java +++ b/src/main/java/com/gcc/swm_services/swm/controller/MainController.java @@ -44,6 +44,7 @@ public class MainController { model.addAttribute("LoginUserId", loginUserId); model.addAttribute("officer_name", officerName); model.addAttribute("UserRole", userRole); + model.addAttribute("facilityTypeId", facilityTypeId); model.addAttribute("isTwoWeightFacility", isTwoWeightFacility); model.addAttribute("isWeightTypeFacility", isWeightTypeFacility); diff --git a/src/main/java/com/gcc/swm_services/swm/controller/SwmAdminApiController.java b/src/main/java/com/gcc/swm_services/swm/controller/SwmAdminApiController.java index a4820f6..0f9ac2a 100644 --- a/src/main/java/com/gcc/swm_services/swm/controller/SwmAdminApiController.java +++ b/src/main/java/com/gcc/swm_services/swm/controller/SwmAdminApiController.java @@ -48,13 +48,23 @@ public class SwmAdminApiController { throw new IllegalArgumentException("Request date is required"); } - if (weight == null || weight <= 0) { - throw new IllegalArgumentException("Weight must be greater than zero"); + if (weight == null) { + throw new IllegalArgumentException("Weight is required"); + } + + if (facilityTypeId == 5) { + if (weight < 0) { + throw new IllegalArgumentException("Weight cannot be negative"); + } + } else { + if (weight <= 0) { + throw new IllegalArgumentException("Weight must be greater than zero"); + } } // πŸ”΄ Facility type 5 β†’ TWO weights + weightType if (facilityTypeId == 5) { - if (weight1 == null || weight1 <= 0) { + if (weight1 == null) { throw new IllegalArgumentException( "Second weight is required for GW & TC Waste facility"); } @@ -115,4 +125,21 @@ public class SwmAdminApiController { "status", "SUCCESS", "data", addDetailsService.getZoneTargetPercentage(fromDate, toDate))); } + + @GetMapping("/singledayreports") + public ResponseEntity getZoneTargetPercentagePerDay( + @RequestParam String Date) { + + if (Date == null || Date.isBlank()) { + + return ResponseEntity.badRequest().body( + Map.of("status", "ERROR", "message", "Date range is required")); + } + + return ResponseEntity.ok( + Map.of( + "status", "SUCCESS", + "data", addDetailsService.getZoneTargetPercentageForOneDay(Date))); + } + } diff --git a/src/main/java/com/gcc/swm_services/swm/controller/SwmApiController.java b/src/main/java/com/gcc/swm_services/swm/controller/SwmApiController.java index 6261fa6..389b32d 100644 --- a/src/main/java/com/gcc/swm_services/swm/controller/SwmApiController.java +++ b/src/main/java/com/gcc/swm_services/swm/controller/SwmApiController.java @@ -104,6 +104,16 @@ public class SwmApiController { HttpSession session) { try { + + // πŸ” Session values + Object gccUserIdObj = session.getAttribute("gcc_user_id"); + Object usernameObj = session.getAttribute("username"); + int gccUserId = Integer.parseInt(gccUserIdObj.toString()); + String username = usernameObj.toString(); + + // πŸ” gcc_user_id β†’ dpid β†’ facilityTypeId + int dpid = addDetailsService.getDpidByGccUserId(gccUserId); + int facilityTypeId = dpid; // πŸ”΄ Validation if (zoneId <= 0) { throw new IllegalArgumentException("Invalid zone"); @@ -113,34 +123,33 @@ public class SwmApiController { throw new IllegalArgumentException("Request date is required"); } - if (weight == null || weight <= 0) { - throw new IllegalArgumentException("Weight must be greater than zero"); + if (weight == null) { + throw new IllegalArgumentException("Weight is required"); } - // πŸ” Session values - Object gccUserIdObj = session.getAttribute("gcc_user_id"); - Object usernameObj = session.getAttribute("username"); + if (facilityTypeId == 5) { + if (weight < 0) { + throw new IllegalArgumentException("Weight cannot be negative"); + } + } else { + if (weight <= 0) { + throw new IllegalArgumentException("Weight must be greater than zero"); + } + } if (gccUserIdObj == null || usernameObj == null) { throw new IllegalStateException("User session expired. Please login again."); } - int gccUserId = Integer.parseInt(gccUserIdObj.toString()); - String username = usernameObj.toString(); - - // πŸ” gcc_user_id β†’ dpid β†’ facilityTypeId - int dpid = addDetailsService.getDpidByGccUserId(gccUserId); - int facilityTypeId = dpid; - // πŸ”΄ Facility type 5 β†’ TWO weights + weightType if (facilityTypeId == 5) { - if (weight1 == null || weight1 <= 0) { + if (weight1 == null) { throw new IllegalArgumentException( "Second weight is required for GW & TC Waste facility"); } if (weightType == null || weightType.isBlank()) { throw new IllegalArgumentException( - "Weight type (KDG / PDG) is required"); + "Location (KDG / PDG) is required"); } } @@ -148,7 +157,7 @@ public class SwmApiController { if (weightType == null || weightType.isBlank()) { throw new IllegalArgumentException( - "Weight type (KDG / PDG) is required"); + "Location (KDG / PDG) is required"); } } diff --git a/src/main/java/com/gcc/swm_services/swm/service/AddDetailsService.java b/src/main/java/com/gcc/swm_services/swm/service/AddDetailsService.java index fd5793d..68965e3 100644 --- a/src/main/java/com/gcc/swm_services/swm/service/AddDetailsService.java +++ b/src/main/java/com/gcc/swm_services/swm/service/AddDetailsService.java @@ -266,7 +266,7 @@ public class AddDetailsService { WHERE is_active = 1 AND is_delete = 0 UNION ALL - SELECT zone, 9, 'Plastic Baling Centre', plasting_baling_centre + SELECT zone, 8, 'Plasting Baling Centre', plasting_baling_centre FROM zonewise_target WHERE is_active = 1 AND is_delete = 0 ) t LEFT JOIN ( @@ -296,6 +296,56 @@ public class AddDetailsService { return jdbcTemplate.queryForList(sql, fromDate, toDate); } + public List> getZoneTargetPercentageForOneDay(String date) { + String sql = """ + SELECT + t.zone, + t.facility, + t.target, + COALESCE(a.achieved, 0) AS achieved, + ROUND( + CASE + WHEN t.target = 0 AND COALESCE(a.achieved, 0) > 0 THEN 100 + WHEN t.target = 0 THEN 0 + ELSE LEAST((COALESCE(a.achieved, 0) / t.target) * 100, 100) + END, + 2 + ) AS percentage + FROM ( + SELECT zone, 1 AS ft_id, 'MCC' AS facility, mcc AS target FROM zonewise_target WHERE is_active = 1 AND is_delete = 0 + UNION ALL SELECT zone, 2, 'Windrow', windrow FROM zonewise_target WHERE is_active = 1 AND is_delete = 0 + UNION ALL SELECT zone, 3, 'Bio-CNG', bio_cng FROM zonewise_target WHERE is_active = 1 AND is_delete = 0 + UNION ALL SELECT zone, 4, 'Bio-GAS', bio_gas FROM zonewise_target WHERE is_active = 1 AND is_delete = 0 + UNION ALL SELECT zone, 5, 'GW & TC Waste', gw_tc_waste FROM zonewise_target WHERE is_active = 1 AND is_delete = 0 + UNION ALL SELECT zone, 6, 'MRF OR RRC', mrf_mrr FROM zonewise_target WHERE is_active = 1 AND is_delete = 0 + UNION ALL SELECT zone, 7, 'Incinerator', incinerator FROM zonewise_target WHERE is_active = 1 AND is_delete = 0 + UNION ALL SELECT zone, 8, 'Plasting Baling Centre', plasting_baling_centre FROM zonewise_target WHERE is_active = 1 AND is_delete = 0 + ) t + LEFT JOIN ( + SELECT + fwd.zone_id AS zone, + fwd.ft_id, + SUM( + CASE + WHEN fwd.ft_id = 5 + THEN COALESCE(fwd.weight, 0) + COALESCE(fwd.weight_1, 0) + ELSE COALESCE(fwd.weight, 0) + END + ) AS achieved + FROM facilities_weight_details fwd + WHERE fwd.is_active = 1 + AND fwd.is_delete = 0 + AND DATE(fwd.req_date) = ? -- **single‑date filter** + GROUP BY fwd.zone_id, fwd.ft_id + ) a + ON a.zone = t.zone + AND a.ft_id = t.ft_id + ORDER BY t.zone, t.facility + """; + // Only one parameter (the date) is bound now. + return jdbcTemplate.queryForList(sql, date); + } + // public List> getZoneWiseFacilityByLogin( // String username, // String fromDate, diff --git a/src/main/resources/templates/modules/swm/biocng.html b/src/main/resources/templates/modules/swm/biocng.html index fcbe711..333d06f 100644 --- a/src/main/resources/templates/modules/swm/biocng.html +++ b/src/main/resources/templates/modules/swm/biocng.html @@ -147,7 +147,8 @@
+ style="font-size: medium;">Date:*
@@ -161,7 +162,8 @@
- + *
@@ -170,7 +172,8 @@ diff --git a/src/main/resources/templates/modules/swm/biogas.html b/src/main/resources/templates/modules/swm/biogas.html index a3ba5a3..415cc33 100644 --- a/src/main/resources/templates/modules/swm/biogas.html +++ b/src/main/resources/templates/modules/swm/biogas.html @@ -147,7 +147,8 @@
+ style="font-size: medium;">Date:*
@@ -161,7 +162,8 @@
- + *
@@ -170,7 +172,7 @@ @@ -180,12 +182,6 @@
- - - - - -
diff --git a/src/main/resources/templates/modules/swm/cdwaste.html b/src/main/resources/templates/modules/swm/cdwaste.html index 30ba818..f80a972 100644 --- a/src/main/resources/templates/modules/swm/cdwaste.html +++ b/src/main/resources/templates/modules/swm/cdwaste.html @@ -147,7 +147,7 @@
+ style="font-size: medium;">Date:*
@@ -161,7 +161,7 @@
- + *
@@ -170,7 +170,8 @@ @@ -190,12 +191,6 @@
- - - - - - diff --git a/src/main/resources/templates/modules/swm/eachreport.html b/src/main/resources/templates/modules/swm/eachreport.html index 83a6df8..0b6ca7b 100644 --- a/src/main/resources/templates/modules/swm/eachreport.html +++ b/src/main/resources/templates/modules/swm/eachreport.html @@ -146,12 +146,13 @@
- + *
- + *
diff --git a/src/main/resources/templates/modules/swm/gwtcwaste.html b/src/main/resources/templates/modules/swm/gwtcwaste.html index 67964cc..98042ad 100644 --- a/src/main/resources/templates/modules/swm/gwtcwaste.html +++ b/src/main/resources/templates/modules/swm/gwtcwaste.html @@ -148,7 +148,8 @@
+ style="font-size: medium;">Date:*
@@ -165,7 +166,7 @@
+ Waste:(in MT)*
@@ -175,7 +176,7 @@
+ MT)*
@@ -387,10 +388,14 @@ return; } - if (!weight || weight <= 0) { - Swal.fire("Validation Error", "Weight must be greater than zero", "warning"); + if (!weight || weight == "") { + Swal.fire("Validation Error", "Weight is required", "warning"); return; } + // if (!weight || weight <= 0) { + // Swal.fire("Validation Error", "Weight must be greater than zero", "warning"); + // return; + // } // ⚠️ Note: // Facility type 5 validation is done in BACKEND diff --git a/src/main/resources/templates/modules/swm/incinerator.html b/src/main/resources/templates/modules/swm/incinerator.html index 329ad20..4cfb6d5 100644 --- a/src/main/resources/templates/modules/swm/incinerator.html +++ b/src/main/resources/templates/modules/swm/incinerator.html @@ -148,7 +148,8 @@
+ style="font-size: medium;">Date:*
@@ -162,7 +163,8 @@
- + *
@@ -171,7 +173,8 @@ @@ -181,12 +184,6 @@
- - - - - -
diff --git a/src/main/resources/templates/modules/swm/mcc.html b/src/main/resources/templates/modules/swm/mcc.html index ae7fbe8..9c94243 100644 --- a/src/main/resources/templates/modules/swm/mcc.html +++ b/src/main/resources/templates/modules/swm/mcc.html @@ -152,7 +152,7 @@
+ *
@@ -167,7 +167,8 @@
- + *
@@ -176,7 +177,8 @@ diff --git a/src/main/resources/templates/modules/swm/plastingbaling.html b/src/main/resources/templates/modules/swm/plastingbaling.html index 588759c..5764ba0 100644 --- a/src/main/resources/templates/modules/swm/plastingbaling.html +++ b/src/main/resources/templates/modules/swm/plastingbaling.html @@ -148,7 +148,8 @@
+ style="font-size: medium;">Date:*
@@ -164,13 +165,15 @@
- + *
diff --git a/src/main/resources/templates/modules/swm/reports.html b/src/main/resources/templates/modules/swm/reports.html index 110f8ef..4b6990a 100644 --- a/src/main/resources/templates/modules/swm/reports.html +++ b/src/main/resources/templates/modules/swm/reports.html @@ -143,7 +143,7 @@
-
+ + +
+
+ + +
+ * + +
+ + +
+ * + +
+ + +
+ * + + +
+ + +
+ * + + +
+ +
+
+
@@ -190,7 +249,11 @@ + + S.No Zone @@ -200,7 +263,7 @@ Bio-GAS Horticulture Incinerator - Plastic Baling Centre + Plasting Baling Centre @@ -329,6 +392,8 @@ diff --git a/src/main/resources/templates/modules/swm/requestlist.html b/src/main/resources/templates/modules/swm/requestlist.html index dc1df7a..2a927f4 100644 --- a/src/main/resources/templates/modules/swm/requestlist.html +++ b/src/main/resources/templates/modules/swm/requestlist.html @@ -146,30 +146,33 @@
+ style="font-size: medium;">Date:*
- +
- + *
@@ -356,6 +359,8 @@ const weight1 = $("#weight1").val(); const weightType = $("#facilitytype").val(); + const facilityTypeId = $("#facilityTypeId").val(); + // πŸ”΄ Client-side validations if (!zoneId) { Swal.fire("Validation Error", "Please select zone", "warning"); @@ -367,11 +372,25 @@ return; } - if (!weight || weight <= 0) { - Swal.fire("Validation Error", "Weight must be greater than zero", "warning"); + if (weight == null || weight == "") { + Swal.fire("Validation Error", "Weight is required", "warning"); return; } + if (facilityTypeId == 5) { + if (weight < 0) { + Swal.fire("Validation Error", "Weight cannot be negative", "warning"); + return; + } + } else { + if (weight <= 0) { + Swal.fire("Validation Error", "Weight must be greater than zero", "warning"); + return; + } + } + + + // ⚠️ Note: // Facility type 5 validation is done in BACKEND // because facilityTypeId is derived after login diff --git a/src/main/resources/templates/modules/swm/windrow.html b/src/main/resources/templates/modules/swm/windrow.html index b39511a..700a784 100644 --- a/src/main/resources/templates/modules/swm/windrow.html +++ b/src/main/resources/templates/modules/swm/windrow.html @@ -147,7 +147,8 @@
+ style="font-size: medium;">Date:*
@@ -161,7 +162,8 @@
- + *
@@ -169,7 +171,8 @@