feat: enhance report on-screen, PDF print layout, and Excel exports with executive styling and audit sign-off

This commit is contained in:
Atharv1705
2026-11-16 12:02:47 +05:30
parent 13fd84a53c
commit ee9390a2a0
5 changed files with 408 additions and 69 deletions
@@ -219,7 +219,7 @@ export function DataTable<TData>({
return (
<div className="space-y-3">
{/* Toolbar */}
<div className="flex flex-col sm:flex-row sm:items-center gap-2">
<div className="no-print flex flex-col sm:flex-row sm:items-center gap-2">
<div className="relative flex-1 min-w-0">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" />
<input
@@ -301,7 +301,7 @@ export function DataTable<TData>({
value={(header.column.getFilterValue() as string) ?? ""}
onChange={(e) => header.column.setFilterValue(e.target.value)}
placeholder="Filter..."
className="w-full px-2 py-0.5 text-xs border border-gray-200 rounded focus:outline-none focus:ring-1 focus:ring-blue-400"
className="no-print w-full px-2 py-0.5 text-xs border border-gray-200 rounded focus:outline-none focus:ring-1 focus:ring-blue-400"
onClick={(e) => e.stopPropagation()}
/>
)}
@@ -357,7 +357,7 @@ export function DataTable<TData>({
{/* Pagination */}
{!loading && visibleRows.length > 0 && (
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-2 px-3 sm:px-4 py-3 border-t border-gray-200 bg-gray-50 text-sm text-gray-600">
<div className="no-print flex flex-col sm:flex-row items-start sm:items-center justify-between gap-2 px-3 sm:px-4 py-3 border-t border-gray-200 bg-gray-50 text-sm text-gray-600">
<span>
{filteredRows.length} record{filteredRows.length !== 1 ? "s" : ""}
{globalFilter || columnFilters.length ? " (filtered)" : ""}
+73 -9
View File
@@ -11,43 +11,107 @@
}
}
@media screen {
.print-only {
display: none !important;
}
}
@media print {
@page {
size: A4 landscape;
margin: 12mm;
margin: 8mm 10mm;
}
aside,
header,
nav,
.no-print {
display: none !important;
}
.print-only {
display: block !important;
}
body {
background: #ffffff !important;
color: #111827 !important;
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
color: #0f172a !important;
-webkit-print-color-adjust: exact !important;
print-color-adjust: exact !important;
font-size: 10px !important;
line-height: 1.35 !important;
}
main {
padding: 0 !important;
margin: 0 !important;
overflow: visible !important;
max-width: 100% !important;
}
/* Prevent elements from breaking across PDF pages */
.print-break-inside-avoid {
break-inside: avoid !important;
page-break-inside: avoid !important;
}
.print-break-before {
break-before: page !important;
page-break-before: always !important;
}
/* Clean up card shadows and borders for crisp PDF generation */
.shadow-sm,
.shadow,
.shadow-md,
.shadow-lg {
box-shadow: none !important;
}
/* High-fidelity PDF Table Styling */
table {
border-collapse: collapse !important;
width: 100% !important;
page-break-inside: auto;
}
thead {
display: table-header-group !important;
}
tfoot {
display: table-footer-group !important;
}
tr {
page-break-inside: avoid !important;
break-inside: avoid !important;
}
th {
background-color: #1e3a8a !important;
color: #ffffff !important;
font-weight: 600 !important;
font-size: 9.5px !important;
padding: 5px 6px !important;
border: 1px solid #1e293b !important;
text-align: center !important;
}
th,
td {
border: 1px solid #d1d5db !important;
font-size: 10px !important;
border: 1px solid #cbd5e1 !important;
font-size: 9px !important;
padding: 4px 6px !important;
color: #0f172a !important;
}
.print-break-inside-avoid {
break-inside: avoid;
tbody tr:nth-child(even) td {
background-color: #f8fafc !important;
}
/* Force chart svg visibility */
.recharts-wrapper {
margin: 0 auto !important;
}
}
+280 -53
View File
@@ -22,6 +22,8 @@ import {
HelpCircle,
AlertCircle,
Lock,
RotateCcw,
Filter,
} from "lucide-react";
import {
REPORT_CATALOG,
@@ -36,6 +38,8 @@ import { useAuthStore } from "@/hooks/useAuth";
import { formatDateTime } from "@/lib/format";
import { DataTable } from "@/components/DataTable";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { cn } from "@/lib/utils";
import { toast } from "@/lib/toast";
function currentMonthStr(): string {
@@ -210,6 +214,55 @@ export function ReportDetailPage() {
contractType,
]);
const activeFiltersCount = useMemo(() => {
let count = 0;
if (departmentId) count++;
if (month && month !== currentMonthStr()) count++;
if (dateFrom || dateTo) count++;
if (dueFrom || dueTo) count++;
if (priority) count++;
if (callStatus) count++;
if (serviceMode) count++;
if (agencyId) count++;
if (supplierId) count++;
if (statusFilter) count++;
if (recordKind && recordKind !== "all") count++;
if (contractType) count++;
return count;
}, [
departmentId,
month,
dateFrom,
dateTo,
dueFrom,
dueTo,
priority,
callStatus,
serviceMode,
agencyId,
supplierId,
statusFilter,
recordKind,
contractType,
]);
function handleResetFilters() {
setMonth(currentMonthStr());
setDateFrom("");
setDateTo("");
setDueFrom("");
setDueTo("");
setDepartmentId("");
setPriority("");
setCallStatus("");
setServiceMode("");
setAgencyId("");
setSupplierId("");
setStatusFilter("");
setRecordKind("all");
setContractType("");
}
const deptsQuery = useQuery({
queryKey: ["departments", "active-only"],
queryFn: () => departmentsApi.list(false),
@@ -344,52 +397,126 @@ export function ReportDetailPage() {
return (
<div className="space-y-5">
{/* Print-Only Letterhead */}
<div className="hidden print:flex items-center justify-between border-b-2 border-[#1e3a8a] pb-3 mb-4">
<div className="flex items-center gap-3">
<img
src="/logo.jpg"
alt="Poona Hospital and Research Centre"
className="h-12 w-12 object-contain"
/>
<div>
<div className="text-base font-bold text-[#1e3a8a]">
Poona Hospital &amp; Research Centre
</div>
<div className="text-xs text-gray-600">
Asset Management &amp; Maintenance — {report?.title ?? meta.title}
{/* Print-Only Official Hospital Letterhead & Scope */}
<div className="hidden print:block mb-4 border-b-2 border-[#1e3a8a] pb-3">
<div className="flex items-start justify-between">
<div className="flex items-center gap-3.5">
<img
src="/logo.jpg"
alt="Poona Hospital and Research Centre"
className="h-14 w-14 object-contain"
/>
<div>
<div className="text-base font-extrabold text-[#1e3a8a] tracking-tight">
POONA HOSPITAL &amp; RESEARCH CENTRE
</div>
<div className="text-[11px] font-semibold text-gray-800">
NABH Accredited Tertiary Care Hospital &bull; Department of Clinical Engineering
</div>
<div className="text-[10px] text-gray-500">
27, Sadashiv Peth, Pune, Maharashtra 411030 &bull; Tel: +91 20 6609 6000
</div>
</div>
</div>
<div className="text-right text-[10px] text-gray-600 space-y-0.5 border-l border-gray-200 pl-3">
<div className="font-bold text-[#1e3a8a] uppercase tracking-wider">
Audit &amp; Operational Record
</div>
<div>
<strong>Ref:</strong> PHRC-BME-{key?.toUpperCase() ?? "REP"}
</div>
<div>
<strong>Date:</strong> {formatDateTime(new Date().toISOString())} IST
</div>
{user?.name && (
<div>
<strong>Generated by:</strong> {user.name} ({user.role?.replace(/_/g, " ").toUpperCase()})
</div>
)}
</div>
</div>
<div className="text-right text-[11px] text-gray-500">
<div>Printed: {formatDateTime(new Date().toISOString())} IST</div>
{user?.name && <div>Generated by: {user.name}</div>}
{/* Print Filter / Scope summary bar */}
<div className="mt-2.5 pt-2 border-t border-gray-200 flex flex-wrap items-center justify-between text-[10px] text-gray-700 bg-gray-50 px-3 py-1.5 rounded">
<div className="flex items-center gap-4 flex-wrap">
<div>
<span className="text-gray-500">Report:</span>{" "}
<strong>{report?.title ?? meta.title}</strong>
</div>
{month && (
<div>
<span className="text-gray-500">Period:</span> <strong>{month}</strong>
</div>
)}
{dateFrom && (
<div>
<span className="text-gray-500">From:</span> <strong>{dateFrom}</strong>
</div>
)}
{dateTo && (
<div>
<span className="text-gray-500">To:</span> <strong>{dateTo}</strong>
</div>
)}
<div>
<span className="text-gray-500">Department:</span>{" "}
<strong>
{departmentId
? departments.find((d) => String(d.id) === departmentId)?.name ?? departmentId
: isDeptUser && user?.department_name
? user.department_name
: "All Departments"}
</strong>
</div>
{priority && (
<div>
<span className="text-gray-500">Priority:</span>{" "}
<strong>{priority.toUpperCase()}</strong>
</div>
)}
{callStatus && (
<div>
<span className="text-gray-500">Status:</span>{" "}
<strong>{callStatus.toUpperCase()}</strong>
</div>
)}
</div>
<div className="font-semibold text-gray-900">
Total Records: {report?.rows?.length ?? 0}
</div>
</div>
</div>
{/* Screen Header */}
<div className="flex flex-wrap items-start justify-between gap-3">
<div className="no-print flex flex-wrap items-start justify-between gap-4 bg-white border border-gray-200 rounded-xl p-5 shadow-sm">
<div>
<Link
to="/reports"
className="no-print inline-flex items-center gap-1.5 text-sm text-gray-500 hover:text-gray-800 mb-1"
>
<ArrowLeft className="h-4 w-4" />
All Reports
</Link>
<h1 className="text-2xl font-bold text-gray-900">
<div className="flex items-center gap-2 mb-2">
<Link
to="/reports"
className="inline-flex items-center gap-1.5 text-xs font-medium text-gray-500 hover:text-[#1e3a8a] transition-colors"
>
<ArrowLeft className="h-3.5 w-3.5" />
All Reports
</Link>
<span className="text-gray-300">&bull;</span>
<Badge variant="outline" className="text-[10px] bg-blue-50/60 text-[#1e3a8a] border-blue-200">
{meta.category}
</Badge>
</div>
<h1 className="text-2xl font-bold text-gray-900 tracking-tight">
{report?.title ?? meta.title}
</h1>
<p className="text-sm text-gray-500 mt-0.5">{meta.description}</p>
<p className="text-sm text-gray-500 mt-1 max-w-2xl leading-relaxed">{meta.description}</p>
</div>
<div className="no-print flex flex-wrap items-center gap-2">
<div className="flex flex-wrap items-center gap-2.5 pt-1">
{key === "monthly-maintenance" && report?.formula_info && (
<Button
type="button"
variant="outline"
size="sm"
onClick={() => setFormulaOpen((o) => !o)}
className="border-blue-200 text-[#1e3a8a] hover:bg-blue-50 font-medium"
>
<HelpCircle className="h-4 w-4 mr-1.5 text-[#1e3a8a]" />
How this is calculated
@@ -400,6 +527,7 @@ export function ReportDetailPage() {
size="sm"
loading={exporting === "xlsx"}
onClick={() => handleExport("xlsx")}
className="bg-emerald-700 hover:bg-emerald-800 text-white shadow-sm font-medium"
>
<FileSpreadsheet className="h-4 w-4 mr-1.5" />
Export Excel (.xlsx)
@@ -409,9 +537,11 @@ export function ReportDetailPage() {
variant="outline"
size="sm"
onClick={() => window.print()}
className="border-gray-300 hover:bg-gray-50 text-gray-700 shadow-sm font-medium"
title="Generates an executive A4 landscape PDF report with official hospital sign-off"
>
<Printer className="h-4 w-4 mr-1.5" />
Print A4
<Printer className="h-4 w-4 mr-1.5 text-[#1e3a8a]" />
Print A4 / PDF
</Button>
</div>
</div>
@@ -458,7 +588,32 @@ export function ReportDetailPage() {
)}
{/* Tailored Filter Bar */}
<div className="no-print bg-white border border-gray-200 rounded-lg p-3.5 flex flex-wrap items-end gap-3">
<div className="no-print bg-white border border-gray-200 rounded-xl p-4 shadow-sm space-y-3">
<div className="flex items-center justify-between border-b border-gray-100 pb-2.5">
<div className="flex items-center gap-2">
<Filter className="h-4 w-4 text-[#1e3a8a]" />
<span className="text-xs font-semibold text-gray-800 uppercase tracking-wider">
Report Parameters &amp; Scope
</span>
{activeFiltersCount > 0 && (
<Badge variant="info" className="text-[10px] px-2 py-0.5">
{activeFiltersCount} active filter{activeFiltersCount > 1 ? "s" : ""}
</Badge>
)}
</div>
{activeFiltersCount > 0 && (
<button
type="button"
onClick={handleResetFilters}
className="text-xs text-gray-500 hover:text-red-600 flex items-center gap-1 transition-colors font-medium"
>
<RotateCcw className="h-3.5 w-3.5" />
Reset filters
</button>
)}
</div>
<div className="flex flex-wrap items-end gap-3.5 pt-0.5">
{(key === "monthly-maintenance" ||
key === "monthly-department" ||
key === "pm-compliance") && (
@@ -742,34 +897,49 @@ export function ReportDetailPage() {
</div>
</>
)}
</div>
</div>
{/* Summary Strip */}
{report && (
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-2.5 print-break-inside-avoid">
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-3 print-break-inside-avoid">
{key === "monthly-maintenance" && (
<div className="bg-emerald-50 border border-emerald-300 rounded-lg p-3">
<div className="text-[11px] font-semibold text-emerald-800">
<div className="bg-white border border-emerald-300 border-t-4 border-t-emerald-600 rounded-xl p-3.5 shadow-sm">
<div className="text-[11px] font-semibold text-emerald-800 uppercase tracking-wider">
Uptime %
</div>
<div className="text-xl font-bold text-emerald-900 mt-0.5 truncate">
<div className="text-2xl font-black text-emerald-900 mt-1 truncate">
{computeUptimePct(report.summary)}
</div>
<div className="text-[10px] text-emerald-700 mt-0.5">Hospital Availability</div>
</div>
)}
{Object.entries(report.summary).map(([sKey, sVal]) => (
<div
key={sKey}
className="bg-white border border-gray-200 rounded-lg p-3"
>
<div className="text-[11px] font-medium text-gray-500">
{humanizeSummaryKey(sKey)}
{Object.entries(report.summary).map(([sKey, sVal]) => {
const isNegative = sKey.includes("downtime") || sKey.includes("overdue") || sKey.includes("under_repair");
const isPositive = sKey.includes("uptime") || sKey.includes("compliance") || sKey.includes("completed");
const borderTopColor = isNegative
? "border-t-rose-500"
: isPositive
? "border-t-emerald-500"
: "border-t-[#1e3a8a]";
return (
<div
key={sKey}
className={cn(
"bg-white border border-gray-200 border-t-4 rounded-xl p-3.5 shadow-sm",
borderTopColor
)}
>
<div className="text-[11px] font-medium text-gray-500 truncate">
{humanizeSummaryKey(sKey)}
</div>
<div className="text-xl font-bold text-gray-900 mt-1 truncate">
{String(sVal)}
</div>
</div>
<div className="text-lg font-bold text-gray-900 mt-0.5 truncate">
{String(sVal)}
</div>
</div>
))}
);
})}
</div>
)}
@@ -788,18 +958,26 @@ export function ReportDetailPage() {
<CartesianGrid strokeDasharray="3 3" stroke="#e5e7eb" />
<XAxis dataKey="department" tick={{ fontSize: 11 }} />
<YAxis tick={{ fontSize: 11 }} />
<Tooltip />
<Legend />
<Tooltip
contentStyle={{
backgroundColor: "#ffffff",
borderColor: "#cbd5e1",
borderRadius: "8px",
boxShadow: "0 4px 6px -1px rgb(0 0 0 / 0.1)",
fontSize: "12px",
}}
/>
<Legend wrapperStyle={{ fontSize: "12px", paddingTop: "8px" }} />
<Bar
dataKey="uptime_hours"
name="Uptime (hrs)"
fill="#22c55e"
fill="#10b981"
radius={[4, 4, 0, 0]}
/>
<Bar
dataKey="downtime_hours"
name="Downtime (hrs)"
fill="#ef4444"
fill="#f43f5e"
radius={[4, 4, 0, 0]}
/>
</BarChart>
@@ -827,8 +1005,16 @@ export function ReportDetailPage() {
<Cell key={idx} fill={entry.color} />
))}
</Pie>
<Tooltip />
<Legend />
<Tooltip
contentStyle={{
backgroundColor: "#ffffff",
borderColor: "#cbd5e1",
borderRadius: "8px",
boxShadow: "0 4px 6px -1px rgb(0 0 0 / 0.1)",
fontSize: "12px",
}}
/>
<Legend wrapperStyle={{ fontSize: "12px", paddingTop: "8px" }} />
</PieChart>
</ResponsiveContainer>
</div>
@@ -844,6 +1030,47 @@ export function ReportDetailPage() {
globalFilterPlaceholder="Quick filter report rows..."
emptyMessage="No rows match the selected report filters."
/>
{/* Hospital Tripartite Sign-off Block (Print / PDF Only) */}
<div className="hidden print:block mt-8 pt-4 border-t-2 border-gray-300 print-break-inside-avoid">
<div className="flex items-center justify-between text-[10px] font-bold uppercase tracking-wider text-gray-700 mb-4">
<span>Hospital Engineering Audit &amp; Verification Sign-off (NABH Chapter FMS)</span>
<span>Poona Hospital &amp; Research Centre</span>
</div>
<div className="grid grid-cols-3 gap-5 text-[10px]">
<div className="border border-gray-300 rounded p-3 space-y-4 bg-gray-50/50">
<div className="font-bold text-gray-800">1. PREPARED BY</div>
<div className="h-9 border-b border-dashed border-gray-400"></div>
<div className="space-y-0.5 text-gray-600">
<div>Name: {user?.name || "Biomedical Engineer"}</div>
<div>Role: {user?.role?.replace(/_/g, " ").toUpperCase() || "BIOMEDICAL"}</div>
<div>Date: {new Date().toLocaleDateString("en-IN")}</div>
</div>
</div>
<div className="border border-gray-300 rounded p-3 space-y-4 bg-gray-50/50">
<div className="font-bold text-gray-800">2. VERIFIED BY</div>
<div className="h-9 border-b border-dashed border-gray-400"></div>
<div className="space-y-0.5 text-gray-600">
<div>Name: __________________________</div>
<div>Role: HOD / Biomedical In-Charge</div>
<div>Date: ____ / ____ / ________</div>
</div>
</div>
<div className="border border-gray-300 rounded p-3 space-y-4 bg-gray-50/50">
<div className="font-bold text-gray-800">3. APPROVED BY</div>
<div className="h-9 border-b border-dashed border-gray-400"></div>
<div className="space-y-0.5 text-gray-600">
<div>Name: __________________________</div>
<div>Role: Medical Superintendent / Director</div>
<div>Date: ____ / ____ / ________</div>
</div>
</div>
</div>
<div className="mt-4 pt-2 border-t border-gray-200 text-[9px] text-gray-500 flex items-center justify-between">
<span>Official Hospital Record &bull; Poona Hospital &amp; Research Centre &bull; Confidential &bull; Retain for 7 Years</span>
<span>AMS Portal Generated &bull; NABH Compliant</span>
</div>
</div>
</div>
);
}
+13
View File
@@ -74,6 +74,19 @@ export function ReportsPage() {
<p className="text-xs text-gray-600 mt-1 leading-relaxed">
{report.description}
</p>
<div className="flex items-center gap-1.5 flex-wrap pt-2.5">
<span className="inline-flex items-center text-[10px] text-emerald-700 bg-emerald-50 px-2 py-0.5 rounded font-medium border border-emerald-100">
Excel (.xlsx)
</span>
<span className="inline-flex items-center text-[10px] text-blue-700 bg-blue-50 px-2 py-0.5 rounded font-medium border border-blue-100">
A4 / PDF Print
</span>
{report.key === "monthly-maintenance" && (
<span className="inline-flex items-center text-[10px] text-purple-700 bg-purple-50 px-2 py-0.5 rounded font-medium border border-purple-100">
Interactive Charts
</span>
)}
</div>
</div>
</div>