updated the PDFGenerator daily.kt
This commit is contained in:
@@ -13,8 +13,8 @@ android {
|
|||||||
applicationId "in.sminnovations.smiadmin"
|
applicationId "in.sminnovations.smiadmin"
|
||||||
minSdk 26
|
minSdk 26
|
||||||
targetSdk 34
|
targetSdk 34
|
||||||
versionCode 6
|
versionCode 7
|
||||||
versionName "1.7"
|
versionName "1.8-beta"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import java.io.FileOutputStream
|
|||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
|
|
||||||
class PDFGenerator_daily(
|
class PDFGenerator_daily(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val companyName: String
|
private val companyName: String
|
||||||
@@ -30,7 +32,7 @@ class PDFGenerator_daily(
|
|||||||
// Constants for page layout
|
// Constants for page layout
|
||||||
private val pageWidth = 595f // A4 width
|
private val pageWidth = 595f // A4 width
|
||||||
private val pageHeight = 842f // A4 height
|
private val pageHeight = 842f // A4 height
|
||||||
private val margin = 40f
|
private val margin = 10f
|
||||||
private val contentWidth = pageWidth - (2 * margin)
|
private val contentWidth = pageWidth - (2 * margin)
|
||||||
|
|
||||||
// Professional color scheme
|
// Professional color scheme
|
||||||
@@ -220,11 +222,6 @@ class PDFGenerator_daily(
|
|||||||
135f,
|
135f,
|
||||||
subtitlePaint
|
subtitlePaint
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
currentY = 180f
|
currentY = 180f
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,13 +254,13 @@ class PDFGenerator_daily(
|
|||||||
canvas.drawText("Status", xPos, currentY + 30f, headerPaint)
|
canvas.drawText("Status", xPos, currentY + 30f, headerPaint)
|
||||||
|
|
||||||
xPos += 80f
|
xPos += 80f
|
||||||
canvas.drawText("Check-in Times", xPos, currentY + 30f, headerPaint)
|
canvas.drawText("Check-in", xPos, currentY + 30f, headerPaint)
|
||||||
|
|
||||||
xPos += 150f
|
xPos += 150f
|
||||||
canvas.drawText("Check-out Times", xPos, currentY + 30f, headerPaint)
|
canvas.drawText("Check-out", xPos, currentY + 30f, headerPaint)
|
||||||
//
|
|
||||||
// xPos += 110f
|
xPos += 110f
|
||||||
// canvas.drawText("Total Hours", xPos, currentY + 30f, headerPaint)
|
canvas.drawText("Hours", xPos, currentY + 30f, headerPaint)
|
||||||
|
|
||||||
currentY += headerHeight + 5f
|
currentY += headerHeight + 5f
|
||||||
}
|
}
|
||||||
@@ -309,7 +306,7 @@ class PDFGenerator_daily(
|
|||||||
Paint().apply {
|
Paint().apply {
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
typeface = Typeface.create("sans-serif-medium", Typeface.BOLD)
|
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(
|
canvas.drawText(
|
||||||
@@ -358,16 +355,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),
|
totalHours,
|
||||||
// margin + 505f,
|
margin + 505f,
|
||||||
// currentY + 25f,
|
currentY + 25f,
|
||||||
// highlightPaint
|
highlightPaint
|
||||||
// )
|
)
|
||||||
//
|
|
||||||
currentY += rowHeight + 10f
|
currentY += rowHeight + 10f
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,43 +423,45 @@ class PDFGenerator_daily(
|
|||||||
regularPaint
|
regularPaint
|
||||||
)
|
)
|
||||||
|
|
||||||
// // Draw zero hours
|
// Draw zero hours
|
||||||
// canvas.drawText(
|
canvas.drawText(
|
||||||
// "0.00 hrs",
|
"0.00",
|
||||||
// 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>): String {
|
||||||
// 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
|
||||||
|
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, ) {
|
private fun drawFooter(paint: Paint, ) {
|
||||||
paint.textAlign = Paint.Align.CENTER
|
paint.textAlign = Paint.Align.CENTER
|
||||||
paint.textSize = 10f
|
paint.textSize = 10f
|
||||||
|
|||||||
Reference in New Issue
Block a user