From 5d691e9b1be334d5438b0b08e80b12b7a4d5761b Mon Sep 17 00:00:00 2001 From: chandrashekhar reddy Date: Wed, 5 Feb 2025 14:32:03 +0530 Subject: [PATCH] PDFGenerator updated the format --- .../smiadmin/ui/utils/PDFGenerator.kt | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/in/sminnovations/smiadmin/ui/utils/PDFGenerator.kt b/app/src/main/java/in/sminnovations/smiadmin/ui/utils/PDFGenerator.kt index de3d0b6..c152c5d 100644 --- a/app/src/main/java/in/sminnovations/smiadmin/ui/utils/PDFGenerator.kt +++ b/app/src/main/java/in/sminnovations/smiadmin/ui/utils/PDFGenerator.kt @@ -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, + 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 )