diff --git a/src/main/java/com/gcc/commissionerreview/service/Fooddistributionservice.java b/src/main/java/com/gcc/commissionerreview/service/Fooddistributionservice.java index bf3be52..fa90951 100644 --- a/src/main/java/com/gcc/commissionerreview/service/Fooddistributionservice.java +++ b/src/main/java/com/gcc/commissionerreview/service/Fooddistributionservice.java @@ -26,7 +26,7 @@ public class Fooddistributionservice { } public List> getQuestions() { - String sql = "SELECT qcm.qcm_id, qcm.audit_category, qcm.code, pqm.qid, pqm.q_english " + + String sql = "SELECT qcm.qcm_id, qcm.audit_category, qcm.code, qcm.penalty_amt, pqm.qid, pqm.q_english " + "FROM pmc_questions_master pqm " + "JOIN questions_category_master qcm ON pqm.qcm_id = qcm.qcm_id " + "WHERE pqm.isactive = 1 AND pqm.isdelete = 0 AND qcm.isactive = 1 AND qcm.isdelete = 0 " + @@ -49,15 +49,23 @@ public class Fooddistributionservice { String sql = "SELECT " + "hm.id AS hub_id, hm.zone, hm.ward, hm.permanent_location, hm.si_name, " + "sm.shiftid, sm.name AS shift_name, " + - "qcm.qcm_id, qcm.audit_category, " + + "qcm.qcm_id, qcm.audit_category, qcm.penalty_amt, " + "pqm.qid, pqm.q_english, " + "pam.english_name AS answer_status, " + "COUNT(pf.id) AS issue_count, " + - "SUM(CASE WHEN pf.food_swing_sts IS NOT NULL AND pf.food_swing_sts != '' AND pf.food_swing_sts != '-' " + "SUM(CASE WHEN LOWER(pf.food_swing_sts) = 'challenge' OR LOWER(pf.food_swing_sts) = 'accept' THEN 1 ELSE 0 END) AS fs_review_count, " + + + "SUM(IFNULL(qcm.penalty_amt, 0)) AS penalty_initiated, " + + "SUM(CASE " + + "WHEN LOWER(pf.food_swing_sts) = 'challenge' AND LOWER(pf.ce_sts) = 'reject' THEN IFNULL(qcm.penalty_amt, 0) " + + + "WHEN LOWER(pf.food_swing_sts) = 'accept' THEN IFNULL(qcm.penalty_amt, 0) " + + "WHEN LOWER(pf.food_swing_sts) = 'challenge' AND LOWER(pf.ce_sts) = 'accept' THEN 0 " + + "WHEN LOWER(pf.food_swing_sts) = 'challenge' AND (pf.ce_sts IS NULL OR pf.ce_sts = '' OR pf.ce_sts = '-') THEN 0 " + + + "ELSE IFNULL(qcm.penalty_amt, 0) END) AS penalty_amount, " + + "SUM(CASE WHEN LOWER(pf.food_swing_sts) = 'challenge' AND (pf.ce_sts IS NULL OR pf.ce_sts = '' OR pf.ce_sts = '-') THEN 1 ELSE 0 END) AS pending_count " + - "AND pf.fs_remarks IS NOT NULL AND pf.fs_remarks != '' AND pf.fs_remarks != '-' " + - "AND pf.fs_image IS NOT NULL AND pf.fs_image != '' " + - "THEN 1 ELSE 0 END) AS fs_review_count " + "FROM hub_master hm " + "CROSS JOIN shift_master sm " + "LEFT JOIN pmc_audit pa ON pa.hub_id = hm.id AND pa.shiftid = sm.shiftid AND pa.isactive = 1 AND pa.isdelete = 0 " @@ -65,11 +73,11 @@ public class Fooddistributionservice { "LEFT JOIN pmc_feedback pf ON pf.pmc_audit_id = pa.id AND pf.isactive = 1 AND pf.isdelete = 0 " + "LEFT JOIN pmc_questions_master pqm ON pqm.qid = pf.questions AND pqm.isactive = 1 AND pqm.isdelete = 0 " + - "LEFT JOIN questions_category_master qcm ON qcm.qcm_id = pqm.qcm_id AND qcm.isactive = 1 AND qcm.isdelete = 0 " + "LEFT JOIN questions_category_master qcm ON qcm.qcm_id = pf.qcmid " + "LEFT JOIN pmc_answer_master pam ON pam.aid = pf.answer AND pam.isactive = 1 AND pam.isdelete = 0 " + "WHERE hm.is_active = 1 AND hm.is_delete = 0 AND sm.isactive = 1 AND sm.isdelete = 0 " + - "GROUP BY hm.id, hm.zone, hm.ward, hm.permanent_location, hm.si_name, sm.shiftid, sm.name, qcm.qcm_id, qcm.audit_category, pqm.qid, pqm.q_english, pam.english_name " + "GROUP BY hm.id, hm.zone, hm.ward, hm.permanent_location, hm.si_name, sm.shiftid, sm.name, qcm.qcm_id, qcm.audit_category, qcm.penalty_amt, pqm.qid, pqm.q_english, pam.english_name " + "ORDER BY hm.id, sm.orderby, qcm.orderby, pqm.orderby"; @@ -80,7 +88,8 @@ public class Fooddistributionservice { } } - public List> getComplianceDetailedReport(String fromDate, String toDate, Integer hubId, Integer shiftId, + public List> getComplianceDetailedReport(String fromDate, String toDate, Integer hubId, + Integer shiftId, Integer qid, String status) { String dateFilter = ""; java.util.List params = new java.util.ArrayList<>(); @@ -117,7 +126,9 @@ public class Fooddistributionservice { "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', pf.fs_image) AS fsVideoLink, " + "IFNULL(pf.ce_sts, '-') AS chief_engineer_status, " + "IFNULL(pf.ce_remarks, '-') AS chief_engineer_remarks, " + - "CASE WHEN pf.ce_cby = '11930' THEN 'CE' WHEN pf.ce_cby IS NOT NULL AND pf.ce_cby != '' THEN 'SE' ELSE '-' END AS chief_engineer " + + "CASE WHEN pf.ce_cby = '11930' THEN 'CE' WHEN pf.ce_cby IS NOT NULL AND pf.ce_cby != '' THEN 'SE' ELSE '-' END AS chief_engineer, " + + + "qcm.penalty_amt " + "FROM pmc_feedback pf " + "JOIN pmc_audit pa ON pa.id = pf.pmc_audit_id AND pa.isactive = 1 AND pa.isdelete = 0 " + dateFilter diff --git a/src/main/resources/templates/modules/fooddistribution/fooddistributionreport.html b/src/main/resources/templates/modules/fooddistribution/fooddistributionreport.html index 83b0e7d..394ceb6 100644 --- a/src/main/resources/templates/modules/fooddistribution/fooddistributionreport.html +++ b/src/main/resources/templates/modules/fooddistribution/fooddistributionreport.html @@ -97,13 +97,11 @@ overflow-x: auto !important; } - /* IMPORTANT */ + /* Force Absolute DataTables Dimensions, overriding JS calculations */ + .dataTables_scrollHeadInner, .report-container table.dataTable { - /* width: max-content !important; */ - width: 100% !important; - /* ✅ instead of max-content */ - - /* force table to expand */ + min-width: 100% !important; + width: max-content !important; } /* Sticky columns background fix */ @@ -118,7 +116,7 @@ .report-container table.dataTable tbody tr.grand-total-row td.dtfc-fixed-left { background-color: #003366 !important; - color: #fff !important; + color: #826969 !important; } .dataTables_scrollBody::-webkit-scrollbar { @@ -141,6 +139,7 @@ } /* Modal tweaks */ + #detailModal .modal-content { border-radius: 8px; } @@ -215,29 +214,28 @@
-
- - - - - - - - - - - - - - - - - - -
Zone - Kitchen Name / AddressShift
-
+ + + + + + + + + + + + + + + + + + +
Zone + Kitchen Name / AddressShift
@@ -273,6 +271,7 @@ CE Status CE Remarks CE Updated By + Penalty Amount @@ -308,6 +307,8 @@ + + @@ -364,7 +365,8 @@ { width: "150px", targets: 16 }, // fsImgBtn { width: "120px", targets: 17 }, // CE Status { width: "220px", targets: 18 }, // CE Remarks - { width: "150px", targets: 19 } // Chief Engineer + { width: "150px", targets: 19 }, // Chief Engineer + { width: "150px", targets: 20 } // Penalty Amount ], responsive: false, scrollX: true, @@ -373,7 +375,48 @@ searching: true, paging: true, info: true, - ordering: false + ordering: false, + dom: '<"d-flex justify-content-between align-items-center mb-2"lfB>rtip', + buttons: [ + { + extend: 'excelHtml5', + text: 'Excel', + className: 'btn btn-success btn-sm', + exportOptions: { + format: { + body: function (data, row, column, node) { + if (typeof data === 'string' && data.indexOf('showMedia') !== -1) { + var match = data.match(/showMedia\('([^']+)'/); + if (match) return match[1]; + } + var div = document.createElement("div"); + div.innerHTML = data; + return div.textContent || div.innerText || ""; + } + } + } + }, + { + extend: 'pdfHtml5', + text: 'PDF', + className: 'btn btn-danger btn-sm', + orientation: 'landscape', + pageSize: 'A3', + exportOptions: { + format: { + body: function (data, row, column, node) { + if (typeof data === 'string' && data.indexOf('showMedia') !== -1) { + var match = data.match(/showMedia\('([^']+)'/); + if (match) return match[1]; + } + var div = document.createElement("div"); + div.innerHTML = data; + return div.textContent || div.innerText || ""; + } + } + } + } + ] }); // 1) Fetch categories first @@ -477,6 +520,8 @@ // Add Total column header hr1.append('Total Issue Found'); + hr1.append('Penalty Initiated'); + hr1.append('Penalty Amount'); } function loadAbstractReport() { @@ -564,6 +609,8 @@ var hubGroups = {}; var questionTotals = {}; var grandTotal = 0; + var grandTotalInit = 0; + var grandTotalAmt = 0; data.forEach(function (row) { var kId = row.hub_id; @@ -590,11 +637,16 @@ var qId = row.qid; if (qId) { if (!hubGroups[kId].shifts[shiftId].counts[qId]) { - hubGroups[kId].shifts[shiftId].counts[qId] = { 'Issue Found': 0, 'No Issue': 0, 'fs_review': 0 }; + hubGroups[kId].shifts[shiftId].counts[qId] = { 'Issue Found': 0, 'No Issue': 0, 'fs_review': 0, 'penalty_initiated': 0, 'penalty_amount': 0, 'pending_count': 0 }; } var s = row.answer_status; if (s === 'Issue Found' || s === 'No Issue') { hubGroups[kId].shifts[shiftId].counts[qId][s] += row.issue_count; + if (s === 'Issue Found') { + hubGroups[kId].shifts[shiftId].counts[qId]['penalty_initiated'] += (row.penalty_initiated || 0); + hubGroups[kId].shifts[shiftId].counts[qId]['penalty_amount'] += (row.penalty_amount || 0); + hubGroups[kId].shifts[shiftId].counts[qId]['pending_count'] += (row.pending_count || 0); + } if (row.fs_review_count && row.fs_review_count > 0) { hubGroups[kId].shifts[shiftId].counts[qId]['fs_review'] += row.fs_review_count; } @@ -626,14 +678,20 @@ // Loop in the same order as headers var totalIssues = 0; + var shiftTotalInit = 0; + var shiftTotalAmt = 0; + var shiftPendingCount = 0; Object.values(groupedCategories).forEach(function (cat) { cat.questions.forEach(function (q) { - var counts = shift.counts[q.qid] || { 'Issue Found': 0 }; + var counts = shift.counts[q.qid] || { 'Issue Found': 0, 'penalty_initiated': 0, 'penalty_amount': 0, 'pending_count': 0 }; var issueCount = counts['Issue Found'] || 0; var fsRevCount = counts['fs_review'] || 0; totalIssues += issueCount; + shiftTotalInit += (counts['penalty_initiated'] || 0); + shiftTotalAmt += (counts['penalty_amount'] || 0); + shiftPendingCount += (counts['pending_count'] || 0); questionTotals[q.qid] = (questionTotals[q.qid] || 0) + issueCount; var textVal = issueCount > 0 ? ' 0 ? 'style="color: red;"' : '') + ' data-hubid="' + hub.hub_id + '" data-shiftid="' + shift.shift_id + '" data-qid="' + q.qid + '" data-status="Issue Found">' + issueCount + '' : ''; @@ -644,9 +702,16 @@ }); tr.append('' + (totalIssues > 0 ? totalIssues : '') + ''); + tr.append('' + (shiftTotalInit > 0 ? shiftTotalInit : '') + ''); + + var amtText = shiftTotalAmt > 0 ? shiftTotalAmt : ''; + tr.append('' + amtText + ''); + tbody.append(tr); grandTotal += totalIssues; + grandTotalInit += shiftTotalInit; + grandTotalAmt += shiftTotalAmt; }); }); @@ -664,6 +729,8 @@ }); totalRow.append('' + (grandTotal > 0 ? grandTotal : '') + ''); + totalRow.append('' + (grandTotalInit > 0 ? grandTotalInit : '') + ''); + totalRow.append('' + (grandTotalAmt > 0 ? grandTotalAmt : '') + ''); tbody.append(totalRow); } @@ -686,6 +753,25 @@ fsImgBtn = ''; } + var fsStsStr = (item.fsStatus || '').toLowerCase(); + var ceStsStr = (item.chief_engineer_status || '').toLowerCase(); + var pAmt = parseInt(item.penalty_amt) || 0; + var finalPenalty = pAmt; + + if (item.english_name === 'Issue Found') { + if (fsStsStr === 'challenge' && ceStsStr === 'reject') { + finalPenalty = pAmt; + } else if (fsStsStr === 'accept') { + finalPenalty = pAmt; + } else if (fsStsStr === 'challenge' && ceStsStr === 'accept') { + finalPenalty = '-'; + } else if (fsStsStr === 'challenge' && (ceStsStr === '' || ceStsStr === '-')) { + finalPenalty = 'Pending'; + } + } else { + finalPenalty = '-'; + } + modalTable.row.add([ index + 1, item.auditDate || '-', @@ -706,7 +792,8 @@ fsImgBtn, item.chief_engineer_status || '-', item.chief_engineer_remarks || '-', - item.chief_engineer || '-' + item.chief_engineer || '-', + finalPenalty ]); }); modalTable.draw(); @@ -855,6 +942,7 @@ } }); + // Recalculate precisely after Bootstrap entirely finishes destroying modal padding