updated the PDFGenerator daily.kt

This commit is contained in:
sathwikcs
2025-04-08 12:28:38 +05:30
parent c9db1cb727
commit 6ed17b3e07
2 changed files with 56 additions and 57 deletions

View File

@@ -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"
}

View File

@@ -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<String>, checkOutTimes: List<String>): 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<String>, checkOutTimes: List<String>): 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