Browse Source

changes in reports admin side

master
yoganandhan 9 months ago
parent
commit
449d1f4c25
  1. 9
      src/main/java/com/gcc/swm_services/configuration/DataSourceConfig.java
  2. 1
      src/main/java/com/gcc/swm_services/swm/controller/MainController.java
  3. 33
      src/main/java/com/gcc/swm_services/swm/controller/SwmAdminApiController.java
  4. 39
      src/main/java/com/gcc/swm_services/swm/controller/SwmApiController.java
  5. 52
      src/main/java/com/gcc/swm_services/swm/service/AddDetailsService.java
  6. 9
      src/main/resources/templates/modules/swm/biocng.html
  7. 14
      src/main/resources/templates/modules/swm/biogas.html
  8. 13
      src/main/resources/templates/modules/swm/cdwaste.html
  9. 5
      src/main/resources/templates/modules/swm/eachreport.html
  10. 15
      src/main/resources/templates/modules/swm/gwtcwaste.html
  11. 15
      src/main/resources/templates/modules/swm/incinerator.html
  12. 8
      src/main/resources/templates/modules/swm/mcc.html
  13. 9
      src/main/resources/templates/modules/swm/plastingbaling.html
  14. 381
      src/main/resources/templates/modules/swm/reports.html
  15. 33
      src/main/resources/templates/modules/swm/requestlist.html
  16. 9
      src/main/resources/templates/modules/swm/windrow.html

9
src/main/java/com/gcc/swm_services/configuration/DataSourceConfig.java

@ -23,12 +23,13 @@ import java.util.Properties;
public class DataSourceConfig { public class DataSourceConfig {
// local // local
// private static String host = "localhost:3306";
// private static String dbpassword = "root";
private static String host = "localhost:3306";
private static String dbpassword = "root";
// AWS // 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 @Configuration
@EnableTransactionManagement @EnableTransactionManagement

1
src/main/java/com/gcc/swm_services/swm/controller/MainController.java

@ -44,6 +44,7 @@ public class MainController {
model.addAttribute("LoginUserId", loginUserId); model.addAttribute("LoginUserId", loginUserId);
model.addAttribute("officer_name", officerName); model.addAttribute("officer_name", officerName);
model.addAttribute("UserRole", userRole); model.addAttribute("UserRole", userRole);
model.addAttribute("facilityTypeId", facilityTypeId);
model.addAttribute("isTwoWeightFacility", isTwoWeightFacility); model.addAttribute("isTwoWeightFacility", isTwoWeightFacility);
model.addAttribute("isWeightTypeFacility", isWeightTypeFacility); model.addAttribute("isWeightTypeFacility", isWeightTypeFacility);

33
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"); 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 // 🔴 Facility type 5 → TWO weights + weightType
if (facilityTypeId == 5) { if (facilityTypeId == 5) {
if (weight1 == null || weight1 <= 0) {
if (weight1 == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Second weight is required for GW & TC Waste facility"); "Second weight is required for GW & TC Waste facility");
} }
@ -115,4 +125,21 @@ public class SwmAdminApiController {
"status", "SUCCESS", "status", "SUCCESS",
"data", addDetailsService.getZoneTargetPercentage(fromDate, toDate))); "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)));
}
} }

39
src/main/java/com/gcc/swm_services/swm/controller/SwmApiController.java

@ -104,6 +104,16 @@ public class SwmApiController {
HttpSession session) { HttpSession session) {
try { 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 // 🔴 Validation
if (zoneId <= 0) { if (zoneId <= 0) {
throw new IllegalArgumentException("Invalid zone"); throw new IllegalArgumentException("Invalid zone");
@ -113,34 +123,33 @@ public class SwmApiController {
throw new IllegalArgumentException("Request date is required"); 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) { if (gccUserIdObj == null || usernameObj == null) {
throw new IllegalStateException("User session expired. Please login again."); 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 // 🔴 Facility type 5 → TWO weights + weightType
if (facilityTypeId == 5) { if (facilityTypeId == 5) {
if (weight1 == null || weight1 <= 0) {
if (weight1 == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Second weight is required for GW & TC Waste facility"); "Second weight is required for GW & TC Waste facility");
} }
if (weightType == null || weightType.isBlank()) { if (weightType == null || weightType.isBlank()) {
throw new IllegalArgumentException( 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()) { if (weightType == null || weightType.isBlank()) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Weight type (KDG / PDG) is required");
"Location (KDG / PDG) is required");
} }
} }

52
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 WHERE is_active = 1 AND is_delete = 0
UNION ALL 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 FROM zonewise_target WHERE is_active = 1 AND is_delete = 0
) t ) t
LEFT JOIN ( LEFT JOIN (
@ -296,6 +296,56 @@ public class AddDetailsService {
return jdbcTemplate.queryForList(sql, fromDate, toDate); return jdbcTemplate.queryForList(sql, fromDate, toDate);
} }
public List<Map<String, Object>> 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<Map<String, Object>> getZoneWiseFacilityByLogin( // public List<Map<String, Object>> getZoneWiseFacilityByLogin(
// String username, // String username,
// String fromDate, // String fromDate,

9
src/main/resources/templates/modules/swm/biocng.html

@ -147,7 +147,8 @@
<div class="row"> <div class="row">
<div class="col-md-3"> <div class="col-md-3">
<label for="date" class="form-label" <label for="date" class="form-label"
style="font-size: medium;">Date:</label>
style="font-size: medium;">Date:</label><span
class="text-danger">*</span>
<input type="date" id="date" class="form-control"> <input type="date" id="date" class="form-control">
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
@ -161,7 +162,8 @@
<div class="col-md-3"> <div class="col-md-3">
<label for="weight" class="form-label">Enter Weight:(in MT)</label>
<label for="weight" class="form-label">Enter Weight:(in MT)</label><span
class="text-danger">*</span>
<input type="number" class="form-control" id="weight"> <input type="number" class="form-control" id="weight">
</div> </div>
@ -170,7 +172,8 @@
<!-- SECOND WEIGHT (TC) --> <!-- SECOND WEIGHT (TC) -->
<div class="col-md-3" id="weight2Div" style="display:none;"> <div class="col-md-3" id="weight2Div" style="display:none;">
<label for="weight1">Enter Weight (TC)</label>
<label for="weight1">Enter Weight (TC)</label><span
class="text-danger">*</span>
<input type="number" class="form-control" id="weight1"> <input type="number" class="form-control" id="weight1">
</div> </div>

14
src/main/resources/templates/modules/swm/biogas.html

@ -147,7 +147,8 @@
<div class="row"> <div class="row">
<div class="col-md-3"> <div class="col-md-3">
<label for="date" class="form-label" <label for="date" class="form-label"
style="font-size: medium;">Date:</label>
style="font-size: medium;">Date:</label><span
class="text-danger">*</span>
<input type="date" id="date" class="form-control"> <input type="date" id="date" class="form-control">
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
@ -161,7 +162,8 @@
<div class="col-md-3"> <div class="col-md-3">
<label for="weight" class="form-label">Enter Weight:(in MT)</label>
<label for="weight" class="form-label">Enter Weight:(in MT)</label><span
class="text-danger">*</span>
<input type="number" class="form-control" id="weight"> <input type="number" class="form-control" id="weight">
</div> </div>
@ -170,7 +172,7 @@
<!-- SECOND WEIGHT (TC) --> <!-- SECOND WEIGHT (TC) -->
<div class="col-md-3" id="weight2Div" style="display:none;"> <div class="col-md-3" id="weight2Div" style="display:none;">
<label for="weight1">Enter Weight:</label>
<label for="weight1">Enter Weight:</label><span class="text-danger">*</span>
<input type="number" class="form-control" id="weight1"> <input type="number" class="form-control" id="weight1">
</div> </div>
@ -180,12 +182,6 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>

13
src/main/resources/templates/modules/swm/cdwaste.html

@ -147,7 +147,7 @@
<div class="row"> <div class="row">
<div class="col-md-3"> <div class="col-md-3">
<label for="date" class="form-label" <label for="date" class="form-label"
style="font-size: medium;">Date:</label>
style="font-size: medium;">Date:</label><span class="text-danger">*</span>
<input type="date" id="date" class="form-control"> <input type="date" id="date" class="form-control">
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
@ -161,7 +161,7 @@
<div class="col-md-3"> <div class="col-md-3">
<label for="weight" class="form-label">Enter Weight:(in MT)</label>
<label for="weight" class="form-label">Enter Weight:(in MT)</label><span class="text-danger">*</span>
<input type="number" class="form-control" id="weight"> <input type="number" class="form-control" id="weight">
</div> </div>
@ -170,7 +170,8 @@
<!-- SECOND WEIGHT (TC) --> <!-- SECOND WEIGHT (TC) -->
<div class="col-md-3" id="weight2Div" style="display:none;"> <div class="col-md-3" id="weight2Div" style="display:none;">
<label for="weight1">Enter Weight (TC)</label>
<label for="weight1">Enter Weight (TC)</label><span
class="text-danger">*</span>
<input type="number" class="form-control" id="weight1"> <input type="number" class="form-control" id="weight1">
</div> </div>
@ -190,12 +191,6 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>

5
src/main/resources/templates/modules/swm/eachreport.html

@ -146,12 +146,13 @@
<div class="card-body pb-0"> <div class="card-body pb-0">
<div class="row align-items-end g-3 mb-3"> <div class="row align-items-end g-3 mb-3">
<div class="col-md-3"> <div class="col-md-3">
<label class="form-label">From Date</label>
<label class="form-label">From Date</label><span
class="text-danger">*</span>
<input type="date" id="fromDate" class="form-control"> <input type="date" id="fromDate" class="form-control">
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<label class="form-label">To Date</label>
<label class="form-label">To Date</label><span class="text-danger">*</span>
<input type="date" id="toDate" class="form-control"> <input type="date" id="toDate" class="form-control">
</div> </div>

15
src/main/resources/templates/modules/swm/gwtcwaste.html

@ -148,7 +148,8 @@
<div class="row"> <div class="row">
<div class="col-md-3"> <div class="col-md-3">
<label for="date" class="form-label" <label for="date" class="form-label"
style="font-size: medium;">Date:</label>
style="font-size: medium;">Date:</label><span
class="text-danger">*</span>
<input type="date" id="date" class="form-control"> <input type="date" id="date" class="form-control">
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
@ -165,7 +166,7 @@
<div class="col-md-3"> <div class="col-md-3">
<label for="weight" class="form-label">Enter Weight for Garden <label for="weight" class="form-label">Enter Weight for Garden
Waste:(in MT)</label>
Waste:(in MT)</label><span class="text-danger">*</span>
<input type="number" class="form-control" id="weight"> <input type="number" class="form-control" id="weight">
</div> </div>
@ -175,7 +176,7 @@
<!-- SECOND WEIGHT (TC) --> <!-- SECOND WEIGHT (TC) -->
<div class="col-md-3"> <div class="col-md-3">
<label for="weight1" class="form-label">Enter Weight Tender Coconut:(in <label for="weight1" class="form-label">Enter Weight Tender Coconut:(in
MT)</label>
MT)</label><span class="text-danger">*</span>
<input type="number" class="form-control" id="weight1"> <input type="number" class="form-control" id="weight1">
</div> </div>
@ -387,10 +388,14 @@
return; 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; return;
} }
// if (!weight || weight <= 0) {
// Swal.fire("Validation Error", "Weight must be greater than zero", "warning");
// return;
// }
// ⚠️ Note: // ⚠️ Note:
// Facility type 5 validation is done in BACKEND // Facility type 5 validation is done in BACKEND

15
src/main/resources/templates/modules/swm/incinerator.html

@ -148,7 +148,8 @@
<div class="row"> <div class="row">
<div class="col-md-3"> <div class="col-md-3">
<label for="date" class="form-label" <label for="date" class="form-label"
style="font-size: medium;">Date:</label>
style="font-size: medium;">Date:</label><span
class="text-danger">*</span>
<input type="date" id="date" class="form-control"> <input type="date" id="date" class="form-control">
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
@ -162,7 +163,8 @@
<div class="col-md-3"> <div class="col-md-3">
<label for="weight" class="form-label">Enter Weight:(in MT)</label>
<label for="weight" class="form-label">Enter Weight:(in MT)</label><span
class="text-danger">*</span>
<input type="number" class="form-control" id="weight"> <input type="number" class="form-control" id="weight">
</div> </div>
@ -171,7 +173,8 @@
<!-- SECOND WEIGHT (TC) --> <!-- SECOND WEIGHT (TC) -->
<div class="col-md-3" id="weight2Div" style="display:none;"> <div class="col-md-3" id="weight2Div" style="display:none;">
<label for="weight1">Enter Weight (TC)</label>
<label for="weight1">Enter Weight (TC)</label><span
class="text-danger">*</span>
<input type="number" class="form-control" id="weight1"> <input type="number" class="form-control" id="weight1">
</div> </div>
@ -181,12 +184,6 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>

8
src/main/resources/templates/modules/swm/mcc.html

@ -152,7 +152,7 @@
<div class="col-md-3"> <div class="col-md-3">
<label for="date" class="form-label" style="font-size: medium;"> <label for="date" class="form-label" style="font-size: medium;">
Date: Date:
</label>
</label><span class="text-danger">*</span>
<input type="date" id="date" class="form-control"> <input type="date" id="date" class="form-control">
</div> </div>
@ -167,7 +167,8 @@
<div class="col-md-3"> <div class="col-md-3">
<label for="weight" class="form-label">Enter Weight:(in MT)</label>
<label for="weight" class="form-label">Enter Weight:(in MT)</label><span
class="text-danger">*</span>
<input type="number" class="form-control" id="weight"> <input type="number" class="form-control" id="weight">
</div> </div>
@ -176,7 +177,8 @@
<!-- SECOND WEIGHT (TC) --> <!-- SECOND WEIGHT (TC) -->
<div class="col-md-3" id="weight2Div" style="display:none;"> <div class="col-md-3" id="weight2Div" style="display:none;">
<label for="weight1">Enter Weight (TC)</label>
<label for="weight1">Enter Weight (TC)</label><span
class="text-danger">*</span>
<input type="number" class="form-control" id="weight1"> <input type="number" class="form-control" id="weight1">
</div> </div>

9
src/main/resources/templates/modules/swm/plastingbaling.html

@ -148,7 +148,8 @@
<div class="row"> <div class="row">
<div class="col-md-3"> <div class="col-md-3">
<label for="date" class="form-label" <label for="date" class="form-label"
style="font-size: medium;">Date:</label>
style="font-size: medium;">Date:</label><span
class="text-danger">*</span>
<input type="date" id="date" class="form-control"> <input type="date" id="date" class="form-control">
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
@ -164,13 +165,15 @@
<div class="col-md-3"> <div class="col-md-3">
<label for="weight" class="form-label">Enter Weight:(in MT)</label>
<label for="weight" class="form-label">Enter Weight:(in MT)</label><span
class="text-danger">*</span>
<input type="number" class="form-control" id="weight"> <input type="number" class="form-control" id="weight">
</div> </div>
<!-- SECOND WEIGHT (TC) --> <!-- SECOND WEIGHT (TC) -->
<div class="col-md-3" id="weight2Div" style="display:none;"> <div class="col-md-3" id="weight2Div" style="display:none;">
<label for="weight1">Enter Weight (TC)</label>
<label for="weight1">Enter Weight (TC)</label><span
class="text-danger">*</span>
<input type="number" class="form-control" id="weight1"> <input type="number" class="form-control" id="weight1">
</div> </div>

381
src/main/resources/templates/modules/swm/reports.html

@ -143,7 +143,7 @@
</div> </div>
<!-- FILTER SECTION --> <!-- FILTER SECTION -->
<div class="card-body pb-0">
<!-- <div class="card-body pb-0">
<div class="row align-items-end g-3 mb-3"> <div class="row align-items-end g-3 mb-3">
<div class="col-md-3"> <div class="col-md-3">
<label class="form-label">From Date</label> <label class="form-label">From Date</label>
@ -155,14 +155,73 @@
<input type="date" id="toDate" class="form-control"> <input type="date" id="toDate" class="form-control">
</div> </div>
<div class="col-md-3">
<label class="form-label">date</label>
<input type="date" id="singleDate" class="form-control">
</div>
<div class="col-md-3">
<label class="form-label">Report type</label>
<select>
< </select>
<option></option>
<input type="date" id="singleDate" class="form-control">
</div>
<div class="col-md-3">
<button id="searchBtn" class="btn btn-primary w-100">
Search
</button>
</div>
</div>
</div> -->
<div class="card-body pb-0">
<div class="row align-items-end g-3 mb-3">
<!-- From Date -->
<div class="col-md-3 d-none" id="fromDateDiv">
<label class="form-label">From Date</label><span
class="text-danger">*</span>
<input type="date" id="fromDate" class="form-control">
</div>
<!-- To Date -->
<div class="col-md-3 d-none" id="toDateDiv">
<label class="form-label">To Date</label><span class="text-danger">*</span>
<input type="date" id="toDate" class="form-control">
</div>
<!-- Single Date -->
<div class="col-md-3 d-none" id="singleDateDiv">
<label class="form-label">Date</label> <span class="text-danger">*</span>
</label>
<input type="date" id="singleDate" class="form-control">
</div>
<!-- Report Type -->
<div class="col-md-3">
<label class="form-label">Report Type</label> <span
class="text-danger">*</span>
</label>
<select id="reportType" class="form-control">
<option value="">Select</option>
<option value="DAY">Day Wise</option>
<option value="MONTH">Month Wise/Date Range</option>
</select>
</div>
<!-- Search -->
<div class="col-md-3"> <div class="col-md-3">
<button id="searchBtn" class="btn btn-primary w-100"> <button id="searchBtn" class="btn btn-primary w-100">
Search Search
</button> </button>
</div> </div>
</div> </div>
</div> </div>
<!-- TABLE SECTION --> <!-- TABLE SECTION -->
<div class="card-body pt-0"> <div class="card-body pt-0">
<div class="table-responsive"> <div class="table-responsive">
@ -190,7 +249,11 @@
<thead class="thead-dark"> <thead class="thead-dark">
<!-- ROW 1 : MAIN GROUP HEADERS --> <!-- ROW 1 : MAIN GROUP HEADERS -->
<!-- <tr class="text-center">
<th colspan="23" class="text-center">Average month wise report</th>
</tr> -->
<tr class="text-center"> <tr class="text-center">
<th rowspan="2">S.No</th> <th rowspan="2">S.No</th>
<th rowspan="2">Zone</th> <th rowspan="2">Zone</th>
@ -200,7 +263,7 @@
<th colspan="3">Bio-GAS</th> <th colspan="3">Bio-GAS</th>
<th colspan="3">Horticulture</th> <th colspan="3">Horticulture</th>
<th colspan="3">Incinerator</th> <th colspan="3">Incinerator</th>
<th colspan="3">Plastic Baling Centre</th>
<th colspan="3">Plasting Baling Centre</th>
</tr> </tr>
<!-- ROW 2 : SUB HEADERS --> <!-- ROW 2 : SUB HEADERS -->
@ -329,6 +392,8 @@
<script th:replace="~{fragments/modules/base/script :: script}"></script> <script th:replace="~{fragments/modules/base/script :: script}"></script>
<script type="text/javascript"> <script type="text/javascript">
let table; let table;
$(document).ready(function () { $(document).ready(function () {
@ -339,8 +404,8 @@
searching: true, searching: true,
info: true, info: true,
paging: true, paging: true,
pageLength: 15, // ✅ show 15 rows
lengthMenu: [15, 25, 50, 100], // ✅ optional dropdown
pageLength: 15, // show 15 rows
lengthMenu: [15, 25, 50, 100], // optional dropdown
scrollX: true, scrollX: true,
responsive: false, responsive: false,
dom: 'Bftip', dom: 'Bftip',
@ -385,9 +450,9 @@
'GW & TC Waste Achieved', 'GW & TC Waste Achieved',
'GW & TC Waste %', 'GW & TC Waste %',
'Plastic Baling Centre Target',
'Plastic Baling Centre Achieved',
'Plastic Baling Centre %'
'Plasting Baling Centre Target',
'Plasting Baling Centre Achieved',
'Plasting Baling Centre %'
]; ];
return headers[columnIdx]; return headers[columnIdx];
@ -477,9 +542,9 @@
{ data: "GW & TC Waste_achieved" }, { data: "GW & TC Waste_achieved" },
{ data: "GW & TC Waste_percentage" }, { data: "GW & TC Waste_percentage" },
{ data: "Plastic Baling Centre_target" },
{ data: "Plastic Baling Centre_achieved" },
{ data: "Plastic Baling Centre_percentage" }
{ data: "Plasting Baling Centre_target" },
{ data: "Plasting Baling Centre_achieved" },
{ data: "Plasting Baling Centre_percentage" }
], ],
footerCallback: function () { footerCallback: function () {
@ -534,20 +599,219 @@
$("#searchBtn").on("click", loadReport); $("#searchBtn").on("click", loadReport);
}); });
$(document).ready(function () {
$("#reportType").on("change", function () {
const type = $(this).val();
// Hide all first
$("#singleDateDiv").addClass("d-none");
$("#fromDateDiv, #toDateDiv").addClass("d-none");
// Clear values
$("#singleDate, #fromDate, #toDate").val("");
if (type === "DAY") {
// Day wise → show single date
$("#singleDateDiv").removeClass("d-none");
}
else if (type === "MONTH") {
// Month wise → show from & to date
$("#fromDateDiv, #toDateDiv").removeClass("d-none");
}
});
});
// function loadReport() {
// const fromDate = $("#fromDate").val();
// const toDate = $("#toDate").val();
// if (!fromDate || !toDate) {
// Swal.fire("Validation Error", "Please select both dates", "warning");
// return;
// }
// $.ajax({
// url: "/swm/api/admin/reports",
// type: "GET",
// data: { fromDate, toDate },
// beforeSend: function () {
// Swal.fire({
// title: "Loading...",
// allowOutsideClick: false,
// didOpen: () => Swal.showLoading()
// });
// },
// success: function (res) {
// Swal.close();
// renderZoneTable(res.data);
// },
// error: function () {
// Swal.fire("Error", "Failed to load report", "error");
// }
// });
// }
function getDateDiffInDays(fromDate, toDate) {
const start = new Date(fromDate);
const end = new Date(toDate);
// +1 because inclusive (01 to 10 = 10 days)
return Math.floor((end - start) / (1000 * 60 * 60 * 24)) + 1;
}
// function renderZoneTableMonthWise(data, fromDate, toDate) {
// const zoneMap = {};
// const dayCount = getDateDiffInDays(fromDate, toDate);
// data.forEach(row => {
// const z = row.zone;
// const f = row.facility;
// if (!zoneMap[z]) {
// zoneMap[z] = { zone: z };
// }
// const dailyTarget = Number(row.target || 0);
// const totalAchieved = Number(row.achieved || 0);
// // Overall target for selected date range
// const overallTarget = dailyTarget * dayCount;
// // Raw percentage
// let percent = 0;
// if (overallTarget > 0) {
// percent = (totalAchieved / overallTarget) * 100;
// }
// // ✅ CAP percentage to max 100
// percent = Math.min(percent, 100);
// // Store values (2 decimal places)
// zoneMap[z][f + "_target"] = overallTarget.toFixed(2);
// zoneMap[z][f + "_achieved"] = totalAchieved.toFixed(2);
// zoneMap[z][f + "_percentage"] = percent.toFixed(2) + "%";
// });
// let i = 1;
// const tableData = Object.values(zoneMap).map(r => ({
// sno: i++,
// ...r
// }));
// table.clear().rows.add(tableData).draw();
// }
function renderZoneTableMonthWise(data, fromDate, toDate) {
const zoneMap = {};
const dayCount = getDateDiffInDays(fromDate, toDate);
data.forEach(row => {
const z = row.zone;
const f = row.facility;
if (!zoneMap[z]) {
zoneMap[z] = { zone: z };
}
const dailyTarget = Number(row.target || 0);
const perDayAchieved = Number(row.achieved || 0);
// 🔹 INTERNAL TOTALS (as per your explanation)
const totalTarget = dailyTarget * dayCount;
const totalAchieved = perDayAchieved * dayCount;
// 🔹 AVERAGES SHOWN IN TABLE
const avgTarget =
dayCount > 0 ? (totalTarget / dayCount) : 0;
const avgAchieved =
dayCount > 0 ? (totalAchieved / dayCount) : 0;
// 🔹 PERCENTAGE (based on averages)
let percent = 0;
if (avgTarget > 0) {
percent = (avgAchieved / avgTarget) * 100;
}
// 🔹 Cap at 100%
percent = Math.min(percent, 100);
// 🔹 Store values (2 decimals)
zoneMap[z][f + "_target"] = avgTarget.toFixed(2);
zoneMap[z][f + "_achieved"] = avgAchieved.toFixed(2);
zoneMap[z][f + "_percentage"] = percent.toFixed(2) + "%";
});
let i = 1;
const tableData = Object.values(zoneMap).map(r => ({
sno: i++,
...r
}));
table.clear().rows.add(tableData).draw();
}
function loadReport() { function loadReport() {
const fromDate = $("#fromDate").val();
const toDate = $("#toDate").val();
const reportType = $("#reportType").val();
if (!fromDate || !toDate) {
Swal.fire("Validation Error", "Please select both dates", "warning");
if (!reportType) {
Swal.fire("Validation Error", "Please select Report Type", "warning");
return; return;
} }
let url = "";
let data = {};
// ================= DAY WISE =================
if (reportType === "DAY") {
const singleDate = $("#singleDate").val();
if (!singleDate) {
Swal.fire("Validation Error", "Please select Date", "warning");
return;
}
url = "/swm/api/admin/singledayreports";
data = { Date: singleDate };
}
// ================= MONTH / DATE RANGE =================
else if (reportType === "MONTH") {
const fromDate = $("#fromDate").val();
const toDate = $("#toDate").val();
if (!fromDate || !toDate) {
Swal.fire("Validation Error", "Please select From & To Date", "warning");
return;
}
url = "/swm/api/admin/reports";
data = { fromDate, toDate };
}
$.ajax({ $.ajax({
url: "/swm/api/admin/reports",
url: url,
type: "GET", type: "GET",
data: { fromDate, toDate },
data: data,
beforeSend: function () { beforeSend: function () {
Swal.fire({ Swal.fire({
title: "Loading...", title: "Loading...",
@ -556,8 +820,19 @@
}); });
}, },
success: function (res) { success: function (res) {
Swal.close(); Swal.close();
renderZoneTable(res.data);
// ✅ SEPARATE RENDERING BASED ON REPORT TYPE
if (reportType === "MONTH") {
renderZoneTableMonthWise(
res.data,
$("#fromDate").val(),
$("#toDate").val()
);
} else {
renderZoneTable(res.data); // DAY wise (existing)
}
}, },
error: function () { error: function () {
Swal.fire("Error", "Failed to load report", "error"); Swal.fire("Error", "Failed to load report", "error");
@ -565,6 +840,8 @@
}); });
} }
function renderZoneTable(data) { function renderZoneTable(data) {
const zoneMap = {}; const zoneMap = {};
@ -591,6 +868,76 @@
} }
// function renderZoneTable(data) {
// const zoneMap = {};
// data.forEach(row => {
// const z = row.zone;
// const f = row.facility;
// if (!zoneMap[z]) {
// zoneMap[z] = { zone: z };
// }
// // Create facility bucket
// if (!zoneMap[z][f]) {
// zoneMap[z][f] = {
// dailyTarget: 0,
// totalAchieved: 0,
// dayCount: 0
// };
// }
// const fac = zoneMap[z][f];
// // DAILY target from API
// fac.dailyTarget = Number(row.target || 0);
// // EACH ROW = ONE DAY
// fac.dayCount += 1;
// // SUM achieved
// fac.totalAchieved += Number(row.achieved || 0);
// });
// let i = 1;
// const tableData = [];
// Object.values(zoneMap).forEach(z => {
// const row = {
// sno: i++,
// zone: z.zone
// };
// Object.keys(z).forEach(f => {
// if (f === "zone") return;
// const fac = z[f];
// // ✅ MONTH TARGET = daily target × no of days
// const totalTarget = fac.dailyTarget * fac.dayCount;
// const percent =
// totalTarget > 0
// ? ((fac.totalAchieved / totalTarget) * 100).toFixed(2)
// : "0.00";
// row[f + "_target"] = totalTarget.toFixed(2);
// row[f + "_achieved"] = fac.totalAchieved.toFixed(2);
// row[f + "_percentage"] = percent + "%";
// });
// tableData.push(row);
// });
// table.clear().rows.add(tableData).draw();
// }
</script> </script>
</body> </body>

33
src/main/resources/templates/modules/swm/requestlist.html

@ -146,30 +146,33 @@
<div class="row"> <div class="row">
<div class="col-md-3"> <div class="col-md-3">
<label for="date" class="form-label" <label for="date" class="form-label"
style="font-size: medium;">Date:</label>
style="font-size: medium;">Date:</label><span
class="text-danger">*</span>
<input type="date" id="date" class="form-control"> <input type="date" id="date" class="form-control">
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<label for="zones" class="form-label">Zones <span <label for="zones" class="form-label">Zones <span
class="text-danger">*</span> class="text-danger">*</span>
</label> <select id="zones" class="form-control">
</label>
<select id="zones" class="form-control">
<option value="">Select days</option> <option value="">Select days</option>
</select> </select>
</div> </div>
<input type="hidden" id="facilityTypeId" th:value="${facilityTypeId}">
<div class="col-md-3"> <div class="col-md-3">
<label for="weight" class="form-label">Enter Weight(in MT):</label>
<label for="weight" class="form-label">Enter Weight(in MT):</label><span
class="text-danger">*</span>
<input type="number" class="form-control" id="weight"> <input type="number" class="form-control" id="weight">
</div> </div>
<!-- SECOND WEIGHT (TC) --> <!-- SECOND WEIGHT (TC) -->
<div class="col-md-3" id="weight2Div" style="display:none;"> <div class="col-md-3" id="weight2Div" style="display:none;">
<label for="weight1" class="form-label">Enter Weight(Tender <label for="weight1" class="form-label">Enter Weight(Tender
Coconut):</label>
Coconut):</label><span class="text-danger">*</span>
<input type="number" class="form-control" id="weight1"> <input type="number" class="form-control" id="weight1">
</div> </div>
@ -356,6 +359,8 @@
const weight1 = $("#weight1").val(); const weight1 = $("#weight1").val();
const weightType = $("#facilitytype").val(); const weightType = $("#facilitytype").val();
const facilityTypeId = $("#facilityTypeId").val();
// 🔴 Client-side validations // 🔴 Client-side validations
if (!zoneId) { if (!zoneId) {
Swal.fire("Validation Error", "Please select zone", "warning"); Swal.fire("Validation Error", "Please select zone", "warning");
@ -367,11 +372,25 @@
return; 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; 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: // ⚠️ Note:
// Facility type 5 validation is done in BACKEND // Facility type 5 validation is done in BACKEND
// because facilityTypeId is derived after login // because facilityTypeId is derived after login

9
src/main/resources/templates/modules/swm/windrow.html

@ -147,7 +147,8 @@
<div class="row"> <div class="row">
<div class="col-md-3"> <div class="col-md-3">
<label for="date" class="form-label" <label for="date" class="form-label"
style="font-size: medium;">Date:</label>
style="font-size: medium;">Date:</label><span
class="text-danger">*</span>
<input type="date" id="date" class="form-control"> <input type="date" id="date" class="form-control">
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
@ -161,7 +162,8 @@
<div class="col-md-3"> <div class="col-md-3">
<label for="weight" class="form-label">Enter Weight:(in MT)</label>
<label for="weight" class="form-label">Enter Weight:(in MT)</label><span
class="text-danger">*</span>
<input type="number" class="form-control" id="weight"> <input type="number" class="form-control" id="weight">
</div> </div>
@ -169,7 +171,8 @@
<!-- SECOND WEIGHT (TC) --> <!-- SECOND WEIGHT (TC) -->
<div class="col-md-3" id="weight2Div" style="display:none;"> <div class="col-md-3" id="weight2Div" style="display:none;">
<label for="weight1">Enter Weight (TC)</label>
<label for="weight1">Enter Weight (TC)</label><span
class="text-danger">*</span>
<input type="number" class="form-control" id="weight1"> <input type="number" class="form-control" id="weight1">
</div> </div>

Loading…
Cancel
Save