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

Loading…
Cancel
Save