From 6ed17b3e0789cb6f74b93522c538fb6630e45f66 Mon Sep 17 00:00:00 2001 From: sathwikcs <85106054+sathwikcs@users.noreply.github.com> Date: Tue, 8 Apr 2025 12:28:38 +0530 Subject: [PATCH] updated the PDFGenerator daily.kt --- app/build.gradle | 4 +- .../smiadmin/ui/utils/PDFGenerator daily.kt | 109 +++++++++--------- 2 files changed, 56 insertions(+), 57 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 240b5eb..ed96a19 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,8 +13,8 @@ android { applicationId "in.sminnovations.smiadmin" minSdk 26 targetSdk 34 - versionCode 6 - versionName "1.7" + versionCode 7 + versionName "1.8-beta" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } 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 101ca0b..13efeca 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 @@ -18,6 +18,8 @@ import java.io.FileOutputStream import java.text.SimpleDateFormat import java.util.Calendar import java.util.Locale + + class PDFGenerator_daily( private val context: Context, private val companyName: String @@ -30,7 +32,7 @@ class PDFGenerator_daily( // Constants for page layout private val pageWidth = 595f // A4 width private val pageHeight = 842f // A4 height - private val margin = 40f + private val margin = 10f private val contentWidth = pageWidth - (2 * margin) // Professional color scheme @@ -220,11 +222,6 @@ class PDFGenerator_daily( 135f, subtitlePaint ) - - - - - currentY = 180f } @@ -257,13 +254,13 @@ class PDFGenerator_daily( canvas.drawText("Status", xPos, currentY + 30f, headerPaint) xPos += 80f - canvas.drawText("Check-in Times", xPos, currentY + 30f, headerPaint) + canvas.drawText("Check-in", xPos, currentY + 30f, headerPaint) xPos += 150f - canvas.drawText("Check-out Times", xPos, currentY + 30f, headerPaint) -// -// xPos += 110f -// canvas.drawText("Total Hours", xPos, currentY + 30f, headerPaint) + canvas.drawText("Check-out", xPos, currentY + 30f, headerPaint) + + xPos += 110f + canvas.drawText("Hours", xPos, currentY + 30f, headerPaint) currentY += headerHeight + 5f } @@ -309,7 +306,7 @@ class PDFGenerator_daily( Paint().apply { textSize = 12f typeface = Typeface.create("sans-serif-medium", Typeface.BOLD) - color = Color.rgb(231, 76, 60) // Red for incomplete + color = Color.rgb(92, 75, 242) // Purple for incomplete } } canvas.drawText( @@ -358,16 +355,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( + totalHours, + margin + 505f, + currentY + 25f, + highlightPaint + ) + currentY += rowHeight + 10f } @@ -426,43 +423,45 @@ class PDFGenerator_daily( regularPaint ) -// // Draw zero hours -// canvas.drawText( -// "0.00 hrs", -// margin + 505f, -// currentY + 25f, -// highlightPaint -// ) - + // Draw zero hours + canvas.drawText( + "0.00", + 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()) -// -// // 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 calculateTotalHours(checkInTimes: List, checkOutTimes: List): String { + 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 total minutes to hours and minutes + val hours = totalMinutes.toInt() / 60 + val minutes = totalMinutes.toInt() % 60 + + // Format as "HH:MM" + return String.format("%d:%02d", hours, minutes) + } private fun drawFooter(paint: Paint, ) { paint.textAlign = Paint.Align.CENTER paint.textSize = 10f