${awerReportDataSnapshot.taskCompletionRate.toFixed(1)}%
Time Allocation Breakdown:
- Core/Productive Tasks: ${awerReportDataSnapshot.coreTaskHours.toFixed(1)} hrs (${awerReportDataSnapshot.timeAllocation.core.toFixed(1)}%)
- Meetings: ${awerReportDataSnapshot.meetingHours.toFixed(1)} hrs (${awerReportDataSnapshot.timeAllocation.meetings.toFixed(1)}%)
- Admin/Communication: ${awerReportDataSnapshot.adminHours.toFixed(1)} hrs (${awerReportDataSnapshot.timeAllocation.admin.toFixed(1)}%)
- Breaks: ${awerReportDataSnapshot.breakHours.toFixed(1)} hrs (${awerReportDataSnapshot.timeAllocation.breaks.toFixed(1)}%)
${unaccountedTime !== 0 ? `- Unaccounted: ${unaccountedTime.toFixed(1)} hrs (${awerReportDataSnapshot.timeAllocation.unaccounted.toFixed(1)}%)
` : ''}
Task & Focus Summary:
Tasks Planned: ${awerReportDataSnapshot.tasksPlanned}, Completed: ${awerReportDataSnapshot.tasksCompleted}
Unplanned Tasks Handled: ${awerReportDataSnapshot.unplannedTasks}
Self-Rated Focus Level: ${awerReportDataSnapshot.focusLevel} / 5
Major Distractions: ${awerReportDataSnapshot.distractions}
Qualitative Reflection:
What went well / helped efficiency:
${awerReportDataSnapshot.wentWell.replace(/\n/g, '
')}
What hindered efficiency / caused delays:
${awerReportDataSnapshot.hinderedEfficiency.replace(/\n/g, '
')}
Key learning / improvement for next period:
${awerReportDataSnapshot.keyLearning.replace(/\n/g, '
')}
`;
reportDisplay.style.display = 'block';
const pdfBtn = document.getElementById('awer-pdf-download');
if(pdfBtn) pdfBtn.style.display = 'inline-block';
}
function awerFormatDateForDisplay(dateStr) {
if (!dateStr) return "N/A";
const date = new Date(dateStr + 'T00:00:00'); // Ensure parsing as local date
return date.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });
}
function awerDownloadPDF() {
if (!jsPDF_constructor_awer) { alert("PDF library error. Cannot generate PDF."); return; }
if (Object.keys(awerReportDataSnapshot).length === 0) {
alert("Please generate the report first."); return;
}
const { reportId, periodStart, periodEnd, totalHours, coreTaskHours, meetingHours, adminHours, breakHours,
tasksPlanned, tasksCompleted, unplannedTasks, focusLevel, distractions,
wentWell, hinderedEfficiency, keyLearning,
productiveTimeRatio, taskCompletionRate, timeAllocation } = awerReportDataSnapshot;
const doc = new jsPDF_constructor_awer('p', 'pt', 'a4');
const FONT_FAMILY = "helvetica";
const ACCENT_COLOR_HEX = getComputedStyle(document.documentElement).getPropertyValue('--accent-color').trim();
const PRIMARY_TEXT_COLOR_HEX = getComputedStyle(document.documentElement).getPropertyValue('--primary-text').trim();
const SECTION_TITLE_COLOR_HEX = getComputedStyle(document.documentElement).getPropertyValue('--section-title-color').trim();
const BUTTON_TEXT_COLOR_HEX = getComputedStyle(document.documentElement).getPropertyValue('--button-text-color').trim();
let yPos = 40;
const pageWidth = doc.internal.pageSize.getWidth();
const margin = 40;
const usableWidth = pageWidth - (2 * margin);
doc.setFillColor(ACCENT_COLOR_HEX);
doc.rect(0, 0, pageWidth, yPos + 10, 'F');
doc.setFont(FONT_FAMILY, "bold"); doc.setFontSize(18); doc.setTextColor(BUTTON_TEXT_COLOR_HEX);
doc.text("Work Efficiency Report", pageWidth / 2, yPos, { align: "center" });
yPos += 25;
doc.setFont(FONT_FAMILY, "normal"); doc.setFontSize(10); doc.setTextColor(PRIMARY_TEXT_COLOR_HEX);
doc.text(`Report ID: ${reportId}`, margin, yPos); yPos += 12;
doc.text(`Period: ${awerFormatDateForDisplay(periodStart)} to ${awerFormatDateForDisplay(periodEnd)}`, margin, yPos); yPos += 12;
const genDate = new Date(2025, 4, 18).toLocaleDateString(undefined, { year: 'numeric', month: 'long', day: 'numeric' });
doc.text(`Generated on: ${genDate}`, margin, yPos); yPos += 20;
const addTextSection = (title, contentArray) => {
if (yPos > doc.internal.pageSize.getHeight() - (contentArray.length * 12) - 40) { doc.addPage(); yPos = margin; }
doc.setFont(FONT_FAMILY, "bold"); doc.setFontSize(11); doc.setTextColor(SECTION_TITLE_COLOR_HEX);
doc.text(title, margin, yPos); yPos += 15;
doc.setFont(FONT_FAMILY, "normal"); doc.setFontSize(10);
contentArray.forEach(item => {
if (yPos > doc.internal.pageSize.getHeight() - 25) { doc.addPage(); yPos = margin; }
const lines = doc.splitTextToSize(item, usableWidth);
doc.text(lines, margin, yPos);
yPos += lines.length * 12 + (item.includes(":") ? 2 : 0); // More space after labeled items
});
yPos += 5;
};
// Quantitative Analysis
addTextSection("Quantitative Analysis:", [
`Total Hours Worked: ${totalHours.toFixed(1)} hrs`,
`Productive Time Ratio (Core Tasks): ${productiveTimeRatio.toFixed(1)}%`,
"Time Allocation:",
` - Core/Productive: ${coreTaskHours.toFixed(1)} hrs (${timeAllocation.core.toFixed(1)}%)`,
` - Meetings: ${meetingHours.toFixed(1)} hrs (${timeAllocation.meetings.toFixed(1)}%)`,
` - Admin/Communication: ${adminHours.toFixed(1)} hrs (${timeAllocation.admin.toFixed(1)}%)`,
` - Breaks: ${breakHours.toFixed(1)} hrs (${timeAllocation.breaks.toFixed(1)}%)`,
(totalHours - (coreTaskHours+meetingHours+adminHours+breakHours) !== 0) ? ` - Unaccounted: ${(totalHours - (coreTaskHours+meetingHours+adminHours+breakHours)).toFixed(1)} hrs (${timeAllocation.unaccounted.toFixed(1)}%)` : ""
].filter(Boolean)); // Filter out empty string for unaccounted
addTextSection("Task Performance:", [
`Tasks Planned: ${tasksPlanned}`,
`Tasks Completed: ${tasksCompleted}`,
`Task Completion Rate: ${taskCompletionRate.toFixed(1)}%`,
`Unplanned Tasks Handled: ${unplannedTasks}`
]);
addTextSection("Focus & Distractions:", [
`Self-Rated Focus Level: ${focusLevel} / 5`,
`Major Distractions Encountered: ${distractions || "None specified."}`
]);
// Qualitative Analysis
addTextSection("Qualitative Reflection:", []); // Title only, content follows
addTextSection("What went well / helped efficiency:", [wentWell || "Not specified."]);
addTextSection("What hindered efficiency / caused delays:", [hinderedEfficiency || "Not specified."]);
addTextSection("Key learning / improvement for next period:", [keyLearning || "Not specified."]);
// Footer
const pageCount = doc.internal.getNumberOfPages();
for (let i = 1; i <= pageCount; i++) {
doc.setPage(i);
const pageHeight = doc.internal.pageSize.getHeight();
doc.setLineWidth(0.5); doc.setDrawColor(ACCENT_COLOR_HEX);
doc.line(margin, pageHeight - 30, pageWidth - margin, pageHeight - 30);
doc.setFont(FONT_FAMILY, "normal"); doc.setFontSize(8); doc.setTextColor(PRIMARY_TEXT_COLOR_HEX);
doc.text(`Page ${i} of ${pageCount}`, pageWidth / 2, pageHeight - 20, { align: "center" });
}
doc.save(`Work_Efficiency_Report_${reportId.replace(/[^a-z0-9]/gi, '_')}.pdf`);
}