From c9db1cb7275eb01fea016c3faa545a90b4b9523b Mon Sep 17 00:00:00 2001 From: sathwikcs <85106054+sathwikcs@users.noreply.github.com> Date: Mon, 24 Mar 2025 15:08:37 +0530 Subject: [PATCH] updated the PDFGenerator daily.kt --- .../smiadmin/ui/utils/PDFGenerator daily.kt | 124 +++++++++++------- 1 file changed, 74 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/in/sminnovations/smiadmin/ui/utils/PDFGenerator daily.kt b/app/src/main/java/in/sminnovations/smiadmin/ui/utils/PDFGenerator daily.kt index a77819d..101ca0b 100644 --- a/app/src/main/java/in/sminnovations/smiadmin/ui/utils/PDFGenerator daily.kt +++ b/app/src/main/java/in/sminnovations/smiadmin/ui/utils/PDFGenerator daily.kt @@ -73,6 +73,13 @@ class PDFGenerator_daily( textAlign = Paint.Align.CENTER } + val notePaint = Paint().apply { + textSize = 10f + typeface = Typeface.MONOSPACE + color = secondaryColor + textAlign = Paint.Align.CENTER + } + val tableHeaderPaint = Paint().apply { textSize = 14f typeface = Typeface.create("sans-serif-medium", Typeface.BOLD) @@ -100,6 +107,8 @@ class PDFGenerator_daily( val dayStr = String.format("%02d", selectedDate.get(Calendar.DAY_OF_MONTH)) val firebaseDateKey = "$dayStr-$monthStr-$yearStr" + // + drawTopDisclaimer(notePaint) // Draw report header drawReportHeader(formattedDate, titlePaint, subtitlePaint) @@ -177,7 +186,8 @@ class PDFGenerator_daily( private fun drawReportHeader( formattedDate: String, titlePaint: Paint, - subtitlePaint: Paint + subtitlePaint: Paint, + ) { // Draw decorative header background val headerPath = Path().apply { @@ -211,6 +221,10 @@ class PDFGenerator_daily( subtitlePaint ) + + + + currentY = 180f } @@ -247,9 +261,9 @@ class PDFGenerator_daily( xPos += 150f canvas.drawText("Check-out Times", xPos, currentY + 30f, headerPaint) - - xPos += 110f - canvas.drawText("Total Hours", xPos, currentY + 30f, headerPaint) +// +// xPos += 110f +// canvas.drawText("Total Hours", xPos, currentY + 30f, headerPaint) currentY += headerHeight + 5f } @@ -344,16 +358,16 @@ class PDFGenerator_daily( ) checkOutY += 20f } - - // Calculate and draw total hours - val totalHours = calculateTotalHours(attendanceRecord.checkInTimes, attendanceRecord.checkOutTimes) - canvas.drawText( - String.format("%.2f hrs", totalHours), - margin + 505f, - currentY + 25f, - highlightPaint - ) - +// +// // Calculate and draw total hours +// val totalHours = calculateTotalHours(attendanceRecord.checkInTimes, attendanceRecord.checkOutTimes) +// canvas.drawText( +// String.format("%.2f hrs", totalHours), +// margin + 505f, +// currentY + 25f, +// highlightPaint +// ) +// currentY += rowHeight + 10f } @@ -412,55 +426,65 @@ class PDFGenerator_daily( regularPaint ) - // Draw zero hours - canvas.drawText( - "0.00 hrs", - margin + 505f, - currentY + 25f, - highlightPaint - ) +// // Draw zero hours +// canvas.drawText( +// "0.00 hrs", +// margin + 505f, +// currentY + 25f, +// highlightPaint +// ) currentY += rowHeight + 10f } - private fun calculateTotalHours(checkInTimes: List, checkOutTimes: List): Float { - var totalMinutes = 0f - val dateFormat = SimpleDateFormat("dd MMMM yyyy hh:mm:ss a", Locale.getDefault()) +// private fun calculateTotalHours(checkInTimes: List, checkOutTimes: List): Float { +// var totalMinutes = 0f +// val dateFormat = SimpleDateFormat("dd MMMM yyyy hh:mm:ss a", Locale.getDefault()) +// +// // Calculate time for each check-in/check-out pair +// for (i in 0 until minOf(checkInTimes.size, checkOutTimes.size)) { +// try { +// val checkInTime = dateFormat.parse(checkInTimes[i]) +// val checkOutTime = dateFormat.parse(checkOutTimes[i]) +// +// if (checkInTime != null && checkOutTime != null) { +// // Calculate difference in minutes +// val diffMillis = checkOutTime.time - checkInTime.time +// val diffMinutes = diffMillis / (1000 * 60) +// totalMinutes += diffMinutes +// } +// } catch (e: Exception) { +// // Skip if there's an error parsing the date +// continue +// } +// } +// +// // Convert minutes to hours +// return totalMinutes / 60 +// } - // Calculate time for each check-in/check-out pair - for (i in 0 until minOf(checkInTimes.size, checkOutTimes.size)) { - try { - val checkInTime = dateFormat.parse(checkInTimes[i]) - val checkOutTime = dateFormat.parse(checkOutTimes[i]) - - if (checkInTime != null && checkOutTime != null) { - // Calculate difference in minutes - val diffMillis = checkOutTime.time - checkInTime.time - val diffMinutes = diffMillis / (1000 * 60) - totalMinutes += diffMinutes - } - } catch (e: Exception) { - // Skip if there's an error parsing the date - continue - } - } - - // Convert minutes to hours - return totalMinutes / 60 - } - - private fun drawFooter(paint: Paint) { + private fun drawFooter(paint: Paint, ) { paint.textAlign = Paint.Align.CENTER paint.textSize = 10f + canvas.drawText( + "Page ${pageNumber -1}", + pageWidth/2, + pageHeight - margin/2, + paint + ) + + } + private fun drawTopDisclaimer(notePaint: Paint){ + val currentDate = SimpleDateFormat("dd MMMM yyyy HH:mm", Locale.getDefault()) .format(Calendar.getInstance().time) canvas.drawText( - "Generated on: $currentDate | Page $pageNumber", + "This Report was generated by AdminApp on: $currentDate ", pageWidth/2, - pageHeight - margin/2, - paint + 20f, + notePaint ) }