Zeige in PDF abweichende Arbeitszeiten einzelner Techniker an

master
Niko Diamadis 4 years ago
parent 2316a39bd9
commit bc089d1cd7
Signed by: niko
GPG Key ID: BE53B0B17B1B142E

@ -13,7 +13,6 @@ import com.cyb3rko.techniklogger.toPrettyString
import com.itextpdf.text.*
import com.itextpdf.text.pdf.PdfPTable
import com.itextpdf.text.pdf.PdfWriter
import com.parse.ParseObject
import es.dmoral.toasty.Toasty
import java.io.File
import java.io.FileNotFoundException
@ -24,16 +23,16 @@ import kotlin.Exception
internal class ExportBuilder(
private val myContext: Context,
data: MutableList<Mission>,
missions: MutableList<Mission>,
private val binding: FragmentListingBinding,
year: String
) : Document(PageSize.A4.rotate()) {
private val data = data.reversed()
private val missions = missions.reversed()
private val destination = "${Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)}/"
private val directory = File(destination)
private lateinit var file: File
private val table = PdfPTable(4)
private val techniker = mutableListOf<List<String>>()
private val memberNames = mutableListOf<List<String>>()
private val time = SimpleDateFormat("dd.MM.yyyy, HH:mm", Locale.GERMANY).format(Date())
init {
@ -78,16 +77,19 @@ internal class ExportBuilder(
}
private fun fetchTechniker(index: Int = 0) {
if (index < data.size) {
ParseController.fetchParticipations(data[index].objectId, true) { entries, e ->
if (index < missions.size) {
val mission = missions[index]
ParseController.fetchParticipations(mission.objectId, true) { participations, e ->
if (e == null) {
val tempList = mutableListOf<String>()
var aktuellerTechniker: ParseObject
entries.forEach {
aktuellerTechniker = it.getParseObject("von")!!
tempList.add(aktuellerTechniker.getString("name")!!)
val tempMemberNames = mutableListOf<String>()
participations.forEach {
if (it.duration != 0f && mission.duration != it.duration) {
tempMemberNames.add("${it.name} (${it.duration.toPrettyString()} h)")
} else {
tempMemberNames.add(it.name)
}
}
techniker.add(tempList.sorted())
memberNames.add(tempMemberNames)
fetchTechniker(index + 1)
}
}
@ -97,11 +99,11 @@ internal class ExportBuilder(
}
private fun export() {
data.forEachIndexed { index, mission ->
missions.forEachIndexed { index, mission ->
val information = listOf(
SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY).format(mission.date()),
mission.name,
techniker[index].joinToString("\n"),
memberNames[index].joinToString("\n"),
mission.duration.toPrettyString())
information.forEachIndexed { _, string ->
table.addCell(NormalCell(string))

Loading…
Cancel
Save