PDFGenerator updated the format

This commit is contained in:
chandrashekhar reddy
2025-02-05 14:32:03 +05:30
parent 43c3137041
commit 5d691e9b1b

View File

@@ -116,7 +116,38 @@ class PDFGenerator(
}
.sorted()
drawEmployeeRow(employee, presentDates, regularPaint, highlightPaint)
// Calculate working days (excluding holidays based on company)
val calendar = Calendar.getInstance().apply {
set(selectedYear, selectedMonth - 1, 1)
}
val totalDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH)
// Count holidays based on company name
val holidays = (1..totalDays).count { day ->
calendar.set(Calendar.DAY_OF_MONTH, day)
when (companyName) {
"ShanMukha Innovations" -> calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ||
calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
"IISc-OMI_LAB" -> calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY
else -> calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY // default case
}
}
val workingDays = totalDays - holidays
// Calculate absent days (excluding holidays)
val absentDays = (1..totalDays).count { day ->
calendar.set(Calendar.DAY_OF_MONTH, day)
val isHoliday = when (companyName) {
"ShanMukha Innovations" -> calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ||
calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
"IISc-OMI_LAB" -> calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY
else -> calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY
}
!isHoliday && !presentDates.contains(day)
}
drawEmployeeRow(employee, presentDates, absentDays, workingDays, regularPaint, highlightPaint)
}
// Add footer with page numbers
@@ -201,6 +232,9 @@ class PDFGenerator(
xPos += 180f
canvas.drawText("Days Present", xPos, currentY + 30f, headerPaint)
xPos += 100f
canvas.drawText("Days Absent", xPos, currentY + 30f, headerPaint)
xPos += 100f
canvas.drawText("Attendance Dates", xPos, currentY + 30f, headerPaint)
@@ -210,6 +244,8 @@ class PDFGenerator(
private fun drawEmployeeRow(
employee: Employee,
presentDates: List<Int>,
absentDays: Int,
workingDays: Int,
regularPaint: Paint,
highlightPaint: Paint
) {
@@ -242,6 +278,14 @@ class PDFGenerator(
highlightPaint
)
// Draw days absent
canvas.drawText(
"$absentDays days",
margin + 295f,
currentY + 10f,
highlightPaint
)
// Draw attendance dates
val datesText = presentDates.chunked(5)
.joinToString("\n") { chunk ->
@@ -254,7 +298,7 @@ class PDFGenerator(
datesText.split("\n").forEach { line ->
canvas.drawText(
line,
margin + 295f,
margin + 395f,
dateY,
regularPaint
)