updated the PDFGenerator daily.kt

This commit is contained in:
sathwikcs
2025-03-24 15:08:37 +05:30
parent 5489aeb588
commit c9db1cb727

View File

@@ -73,6 +73,13 @@ class PDFGenerator_daily(
textAlign = Paint.Align.CENTER textAlign = Paint.Align.CENTER
} }
val notePaint = Paint().apply {
textSize = 10f
typeface = Typeface.MONOSPACE
color = secondaryColor
textAlign = Paint.Align.CENTER
}
val tableHeaderPaint = Paint().apply { val tableHeaderPaint = Paint().apply {
textSize = 14f textSize = 14f
typeface = Typeface.create("sans-serif-medium", Typeface.BOLD) 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 dayStr = String.format("%02d", selectedDate.get(Calendar.DAY_OF_MONTH))
val firebaseDateKey = "$dayStr-$monthStr-$yearStr" val firebaseDateKey = "$dayStr-$monthStr-$yearStr"
//
drawTopDisclaimer(notePaint)
// Draw report header // Draw report header
drawReportHeader(formattedDate, titlePaint, subtitlePaint) drawReportHeader(formattedDate, titlePaint, subtitlePaint)
@@ -177,7 +186,8 @@ class PDFGenerator_daily(
private fun drawReportHeader( private fun drawReportHeader(
formattedDate: String, formattedDate: String,
titlePaint: Paint, titlePaint: Paint,
subtitlePaint: Paint subtitlePaint: Paint,
) { ) {
// Draw decorative header background // Draw decorative header background
val headerPath = Path().apply { val headerPath = Path().apply {
@@ -211,6 +221,10 @@ class PDFGenerator_daily(
subtitlePaint subtitlePaint
) )
currentY = 180f currentY = 180f
} }
@@ -247,9 +261,9 @@ class PDFGenerator_daily(
xPos += 150f xPos += 150f
canvas.drawText("Check-out Times", xPos, currentY + 30f, headerPaint) canvas.drawText("Check-out Times", xPos, currentY + 30f, headerPaint)
//
xPos += 110f // xPos += 110f
canvas.drawText("Total Hours", xPos, currentY + 30f, headerPaint) // canvas.drawText("Total Hours", xPos, currentY + 30f, headerPaint)
currentY += headerHeight + 5f currentY += headerHeight + 5f
} }
@@ -344,16 +358,16 @@ class PDFGenerator_daily(
) )
checkOutY += 20f checkOutY += 20f
} }
//
// Calculate and draw total hours // // Calculate and draw total hours
val totalHours = calculateTotalHours(attendanceRecord.checkInTimes, attendanceRecord.checkOutTimes) // val totalHours = calculateTotalHours(attendanceRecord.checkInTimes, attendanceRecord.checkOutTimes)
canvas.drawText( // canvas.drawText(
String.format("%.2f hrs", totalHours), // String.format("%.2f hrs", totalHours),
margin + 505f, // margin + 505f,
currentY + 25f, // currentY + 25f,
highlightPaint // highlightPaint
) // )
//
currentY += rowHeight + 10f currentY += rowHeight + 10f
} }
@@ -412,55 +426,65 @@ class PDFGenerator_daily(
regularPaint regularPaint
) )
// Draw zero hours // // Draw zero hours
canvas.drawText( // canvas.drawText(
"0.00 hrs", // "0.00 hrs",
margin + 505f, // margin + 505f,
currentY + 25f, // currentY + 25f,
highlightPaint // highlightPaint
) // )
currentY += rowHeight + 10f currentY += rowHeight + 10f
} }
private fun calculateTotalHours(checkInTimes: List<String>, checkOutTimes: List<String>): Float { // private fun calculateTotalHours(checkInTimes: List<String>, checkOutTimes: List<String>): Float {
var totalMinutes = 0f // var totalMinutes = 0f
val dateFormat = SimpleDateFormat("dd MMMM yyyy hh:mm:ss a", Locale.getDefault()) // 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 private fun drawFooter(paint: Paint, ) {
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) {
paint.textAlign = Paint.Align.CENTER paint.textAlign = Paint.Align.CENTER
paint.textSize = 10f 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()) val currentDate = SimpleDateFormat("dd MMMM yyyy HH:mm", Locale.getDefault())
.format(Calendar.getInstance().time) .format(Calendar.getInstance().time)
canvas.drawText( canvas.drawText(
"Generated on: $currentDate | Page $pageNumber", "This Report was generated by AdminApp on: $currentDate ",
pageWidth/2, pageWidth/2,
pageHeight - margin/2, 20f,
paint notePaint
) )
} }