From ce6d447ba3d62c2bce6f81f75fdafc6f2fced5d9 Mon Sep 17 00:00:00 2001 From: yoganandhan Date: Wed, 21 Jan 2026 15:02:01 +0530 Subject: [PATCH] changes in facilitywise login --- .../configuration/DataSourceConfig.java | 1 + .../swm/service/AddDetailsService.java | 196 ++++++++++---- .../templates/modules/swm/biocng.html | 63 +---- .../templates/modules/swm/biogas.html | 6 +- .../templates/modules/swm/cdwaste.html | 32 +-- .../templates/modules/swm/eachreport.html | 239 ++++++++++++++---- .../templates/modules/swm/gwtcwaste.html | 8 +- .../templates/modules/swm/incinerator.html | 5 + .../resources/templates/modules/swm/mcc.html | 5 + .../resources/templates/modules/swm/mrf.html | 5 + .../templates/modules/swm/plastingbaling.html | 4 + .../templates/modules/swm/requestlist.html | 35 ++- .../templates/modules/swm/windrow.html | 4 + 13 files changed, 416 insertions(+), 187 deletions(-) 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 d320251..60cd25b 100644 --- a/src/main/java/com/gcc/swm_services/configuration/DataSourceConfig.java +++ b/src/main/java/com/gcc/swm_services/configuration/DataSourceConfig.java @@ -22,6 +22,7 @@ import java.util.Properties; @EnableTransactionManagement public class DataSourceConfig { + // local // private static String host = "localhost:3306"; // private static String dbpassword = "root"; 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 fdddd55..fd5793d 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 @@ -296,67 +296,165 @@ public class AddDetailsService { return jdbcTemplate.queryForList(sql, fromDate, toDate); } + // public List> getZoneWiseFacilityByLogin( + // String username, + // String fromDate, + // String toDate) { + + // 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 AND COALESCE(a.achieved, 0) = 0 THEN 0 + // ELSE LEAST((COALESCE(a.achieved, 0) / t.target) * 100, 100) + // END, 2 + // ) AS percentage + // FROM ( + // /* 🔹 TARGET – ONLY FACILITY FROM LOGIN */ + // SELECT + // zt.zone, + // ft.facilities_name AS facility, + // CASE ft.ft_id + // WHEN 1 THEN zt.mcc + // WHEN 2 THEN zt.windrow + // WHEN 3 THEN zt.bio_cng + // WHEN 4 THEN zt.bio_gas + // WHEN 5 THEN zt.gw_tc_waste + // WHEN 6 THEN zt.mrf_mrr + // WHEN 7 THEN zt.incinerator + // WHEN 8 THEN zt.plasting_baling_centre + // ELSE 0 + // END AS target + + // FROM department_login dl + // JOIN facilities_type ft ON ft.ft_id = dl.dpid + // JOIN zonewise_target zt ON zt.is_active = 1 AND zt.is_delete = 0 + // WHERE dl.user_name = ? + // ) t + // LEFT JOIN ( + // /* 🔹 ACHIEVED – SAME FT_ID + LOGIN */ + // SELECT + // fwd.zone_id AS zone, + // ft.facilities_name AS facility, + // SUM(COALESCE(fwd.weight, 0) + COALESCE(fwd.weight_1, 0)) AS achieved + // FROM facilities_weight_details fwd + // JOIN facilities_type ft ON ft.ft_id = fwd.ft_id + // WHERE fwd.is_active = 1 + // AND fwd.is_delete = 0 + // AND fwd.cby = ? + // AND DATE(fwd.req_date) BETWEEN ? AND ? + // GROUP BY fwd.zone_id, ft.facilities_name + // ) a + // ON a.zone = t.zone AND a.facility = t.facility + // ORDER BY t.zone + // """; + + // return jdbcTemplate.queryForList( + // sql, + // username, + // username, + // fromDate, + // toDate); + // } + + private String normalizeDate(String date) { + + if (date == null || date.isBlank()) { + return date; + } + + // If browser format yyyy-MM-dd → convert to dd-MM-yyyy + if (date.matches("\\d{4}-\\d{2}-\\d{2}")) { + String[] p = date.split("-"); + return p[2] + "-" + p[1] + "-" + p[0]; + } + + // Already dd-MM-yyyy + return date; + } + public List> getZoneWiseFacilityByLogin( String username, String fromDate, String toDate) { + // 🔥 Normalize date format (supports yyyy-MM-dd and dd-MM-yyyy) + fromDate = normalizeDate(fromDate); + toDate = normalizeDate(toDate); + 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 AND COALESCE(a.achieved, 0) = 0 THEN 0 - ELSE LEAST((COALESCE(a.achieved, 0) / t.target) * 100, 100) - END, 2 - ) AS percentage - FROM ( - /* 🔹 TARGET – ONLY FACILITY FROM LOGIN */ - SELECT - zt.zone, - ft.facilities_name AS facility, - CASE - WHEN ft.facilities_name = 'MCC' THEN zt.mcc - WHEN ft.facilities_name = 'Windrow' THEN zt.windrow - WHEN ft.facilities_name = 'Bio-CNG' THEN zt.bio_cng - WHEN ft.facilities_name = 'Bio-GAS' THEN zt.bio_gas - WHEN ft.facilities_name = 'Incinerator' THEN zt.incinerator - WHEN ft.facilities_name = 'Plastic Baling Centre' - THEN zt.plasting_baling_centre - END AS target - FROM department_login dl - JOIN facilities_type ft ON ft.ft_id = dl.dpid - JOIN zonewise_target zt ON zt.is_active = 1 AND zt.is_delete = 0 - WHERE dl.user_name = ? - ) t - LEFT JOIN ( - /* 🔹 ACHIEVED – SAME FT_ID + LOGIN */ - SELECT - fwd.zone_id AS zone, - ft.facilities_name AS facility, - SUM(COALESCE(fwd.weight, 0) + COALESCE(fwd.weight_1, 0)) AS achieved - FROM facilities_weight_details fwd - JOIN facilities_type ft ON ft.ft_id = fwd.ft_id - WHERE fwd.is_active = 1 - AND fwd.is_delete = 0 - AND fwd.cby = ? - AND DATE(fwd.req_date) BETWEEN ? AND ? - GROUP BY fwd.zone_id, ft.facilities_name - ) a - ON a.zone = t.zone AND a.facility = t.facility - ORDER BY t.zone - """; + 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 AND COALESCE(a.achieved, 0) = 0 THEN 0 + ELSE LEAST((COALESCE(a.achieved, 0) / t.target) * 100, 100) + END, 2 + ) AS percentage + FROM ( + /* TARGET */ + SELECT + zt.zone, + ft.ft_id, + ft.facilities_name AS facility, + CASE ft.ft_id + WHEN 1 THEN zt.mcc + WHEN 2 THEN zt.windrow + WHEN 3 THEN zt.bio_cng + WHEN 4 THEN zt.bio_gas + WHEN 5 THEN zt.gw_tc_waste + WHEN 6 THEN zt.mrf_mrr + WHEN 7 THEN zt.incinerator + WHEN 8 THEN zt.plasting_baling_centre + ELSE 0 + END AS target + FROM department_login dl + JOIN facilities_type ft ON ft.ft_id = dl.dpid + JOIN zonewise_target zt + ON zt.is_active = 1 + AND zt.is_delete = 0 + WHERE TRIM(dl.user_name) = ? + ) t + LEFT JOIN ( + /* ACHIEVED */ + SELECT + fwd.zone_id AS zone, + fwd.ft_id, + SUM(COALESCE(fwd.weight, 0) + COALESCE(fwd.weight_1, 0)) AS achieved + FROM facilities_weight_details fwd + WHERE fwd.is_active = 1 + AND fwd.is_delete = 0 + AND TRIM(fwd.cby) = ? + AND fwd.req_date >= STR_TO_DATE(CONCAT(?, ' 00:00:00'), '%d-%m-%Y %H:%i:%s') + AND fwd.req_date <= STR_TO_DATE(CONCAT(?, ' 23:59:59'), '%d-%m-%Y %H:%i:%s') + AND fwd.ft_id = ( + SELECT dpid + FROM department_login + WHERE TRIM(user_name) = ? + ) + 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 + """; return jdbcTemplate.queryForList( sql, username, username, fromDate, - toDate); + toDate, + username); } } diff --git a/src/main/resources/templates/modules/swm/biocng.html b/src/main/resources/templates/modules/swm/biocng.html index 0b57551..fcbe711 100644 --- a/src/main/resources/templates/modules/swm/biocng.html +++ b/src/main/resources/templates/modules/swm/biocng.html @@ -281,6 +281,11 @@ .attr("min", minDate) .attr("max", maxDate) .val(formatDate(today)); + + // 🔒 BLOCK MANUAL TYPING (BUT ALLOW CALENDAR) + $("#date").on("keydown paste", function (e) { + e.preventDefault(); + }); }); $(document).ready(function () { @@ -743,65 +748,7 @@ - function submitRdoDecision(status) { - - let date = ($("#date").val() || "").trim(); - let = $("#detailsModal").data("refid"); - let approvedBy = $("#userName").val(); // 🔥 FROM HIDDEN INPUT - if (!remarks) { - Swal.fire({ - icon: 'warning', - title: 'Remarks Required', - text: 'Please enter remarks before submitting' - }); - return; - } - - Swal.fire({ - title: `Are you sure?`, - text: `You want to ${status.toLowerCase()} this request`, - icon: status === 'APPROVED' ? 'success' : 'error', - showCancelButton: true, - confirmButtonColor: status === 'APPROVED' ? '#28a745' : '#dc3545', - cancelButtonColor: '#6c757d', - confirmButtonText: `Yes, ${status}` - }).then((result) => { - - if (!result.isConfirmed) return; - - $.ajax({ - url: "/gcc/api/flagpoleregistration/rdo/updateDecision", - type: "POST", - data: { - refid: refid, - status: status, - remarks: remarks, - approvedBy: approvedBy // 🔥 PASS TO BACKEND - }, - success: function (res) { - - Swal.fire({ - icon: 'success', - title: status === 'APPROVED' ? 'Approved!' : 'Rejected!', - text: res.message || `Request has been ${status.toLowerCase()}`, - timer: 2000, - showConfirmButton: false - }); - - $("#detailsModal").modal("hide"); - $("#QaqcDatatable").DataTable().ajax.reload(null, false); - }, - error: function () { - Swal.fire({ - icon: 'error', - title: 'Error', - text: 'Failed to update decision' - }); - } - }); - }); - } diff --git a/src/main/resources/templates/modules/swm/biogas.html b/src/main/resources/templates/modules/swm/biogas.html index 248d53e..732e866 100644 --- a/src/main/resources/templates/modules/swm/biogas.html +++ b/src/main/resources/templates/modules/swm/biogas.html @@ -148,7 +148,7 @@
- +