PDFGenerator updated the format
This commit is contained in:
@@ -116,7 +116,38 @@ class PDFGenerator(
|
|||||||
}
|
}
|
||||||
.sorted()
|
.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
|
// Add footer with page numbers
|
||||||
@@ -201,6 +232,9 @@ class PDFGenerator(
|
|||||||
xPos += 180f
|
xPos += 180f
|
||||||
canvas.drawText("Days Present", xPos, currentY + 30f, headerPaint)
|
canvas.drawText("Days Present", xPos, currentY + 30f, headerPaint)
|
||||||
|
|
||||||
|
xPos += 100f
|
||||||
|
canvas.drawText("Days Absent", xPos, currentY + 30f, headerPaint)
|
||||||
|
|
||||||
xPos += 100f
|
xPos += 100f
|
||||||
canvas.drawText("Attendance Dates", xPos, currentY + 30f, headerPaint)
|
canvas.drawText("Attendance Dates", xPos, currentY + 30f, headerPaint)
|
||||||
|
|
||||||
@@ -210,6 +244,8 @@ class PDFGenerator(
|
|||||||
private fun drawEmployeeRow(
|
private fun drawEmployeeRow(
|
||||||
employee: Employee,
|
employee: Employee,
|
||||||
presentDates: List<Int>,
|
presentDates: List<Int>,
|
||||||
|
absentDays: Int,
|
||||||
|
workingDays: Int,
|
||||||
regularPaint: Paint,
|
regularPaint: Paint,
|
||||||
highlightPaint: Paint
|
highlightPaint: Paint
|
||||||
) {
|
) {
|
||||||
@@ -242,6 +278,14 @@ class PDFGenerator(
|
|||||||
highlightPaint
|
highlightPaint
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Draw days absent
|
||||||
|
canvas.drawText(
|
||||||
|
"$absentDays days",
|
||||||
|
margin + 295f,
|
||||||
|
currentY + 10f,
|
||||||
|
highlightPaint
|
||||||
|
)
|
||||||
|
|
||||||
// Draw attendance dates
|
// Draw attendance dates
|
||||||
val datesText = presentDates.chunked(5)
|
val datesText = presentDates.chunked(5)
|
||||||
.joinToString("\n") { chunk ->
|
.joinToString("\n") { chunk ->
|
||||||
@@ -254,7 +298,7 @@ class PDFGenerator(
|
|||||||
datesText.split("\n").forEach { line ->
|
datesText.split("\n").forEach { line ->
|
||||||
canvas.drawText(
|
canvas.drawText(
|
||||||
line,
|
line,
|
||||||
margin + 295f,
|
margin + 395f,
|
||||||
dateY,
|
dateY,
|
||||||
regularPaint
|
regularPaint
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user