Compare commits
21
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8b135ee63 | ||
|
|
6066527dc0 | ||
|
|
1f39f27618 | ||
|
|
956be6a6de | ||
|
|
90ca9775ef | ||
|
|
0e33564b95 | ||
|
|
321b260e3d | ||
|
|
be3c885988 | ||
|
|
802393962e | ||
|
|
ac31308443 | ||
|
|
af832dee93 | ||
|
|
8ca5f20a98 | ||
|
|
26b17ece26 | ||
|
|
2e7eb7e47b | ||
|
|
062415a75d | ||
|
|
ab68be4c1e | ||
|
|
513c1785ef | ||
|
|
e70a53eca7 | ||
|
|
c3004a3d2e | ||
|
|
fda4b462dc | ||
|
|
6a1a15ade9 |
@@ -1,4 +1,5 @@
|
||||
.gradle/
|
||||
.kotlin/
|
||||
build/
|
||||
local.properties
|
||||
app/google-services.json
|
||||
|
||||
@@ -34,8 +34,8 @@ android {
|
||||
applicationId = "pl.firmatpp.kierowca"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 122
|
||||
versionName = "1.0.69"
|
||||
versionCode = 132
|
||||
versionName = "1.0.79"
|
||||
setProperty("archivesBaseName", "pl.firmatpp.kierowca")
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package pl.firmatpp.kierowca.data
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.provider.OpenableColumns
|
||||
import java.io.File
|
||||
import java.security.MessageDigest
|
||||
import java.util.UUID
|
||||
@@ -12,6 +13,7 @@ import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import pl.firmatpp.kierowca.data.api.ApiFactory
|
||||
import pl.firmatpp.kierowca.data.api.MobileDriverApi
|
||||
import pl.firmatpp.kierowca.data.model.BootstrapResponse
|
||||
import pl.firmatpp.kierowca.data.model.AcknowledgeTachographReminderBody
|
||||
import pl.firmatpp.kierowca.data.model.BroadcastAuthBody
|
||||
import pl.firmatpp.kierowca.data.model.BroadcastAuthResponse
|
||||
import pl.firmatpp.kierowca.data.model.CancelLeaveRequestBody
|
||||
@@ -19,8 +21,12 @@ import pl.firmatpp.kierowca.data.model.DispatchSheetUploadResponse
|
||||
import pl.firmatpp.kierowca.data.model.CreateLeaveRequestBody
|
||||
import pl.firmatpp.kierowca.data.model.DriverDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveCalendarEntryDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveDocumentDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveForecastDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveRequestDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveSummaryDto
|
||||
import pl.firmatpp.kierowca.data.model.FinishRouteBody
|
||||
import pl.firmatpp.kierowca.data.model.LeaveForecastBody
|
||||
import pl.firmatpp.kierowca.data.model.NotificationPreferencesBody
|
||||
import pl.firmatpp.kierowca.data.model.NotificationPreferencesDto
|
||||
import pl.firmatpp.kierowca.data.model.OtpResponse
|
||||
@@ -33,6 +39,7 @@ import pl.firmatpp.kierowca.data.model.RoutePointsResponse
|
||||
import pl.firmatpp.kierowca.data.model.RouteResponse
|
||||
import pl.firmatpp.kierowca.data.model.StartRouteBody
|
||||
import pl.firmatpp.kierowca.data.model.SyncStateResponse
|
||||
import pl.firmatpp.kierowca.data.model.TachographReminderDto
|
||||
import pl.firmatpp.kierowca.data.model.VerifyOtpBody
|
||||
import pl.firmatpp.kierowca.data.upload.DispatchSheetUploadEntity
|
||||
import pl.firmatpp.kierowca.data.upload.PhotoUploadEntity
|
||||
@@ -56,24 +63,105 @@ class DriverRepository(
|
||||
suspend fun bootstrap(date: String? = null): BootstrapResponse =
|
||||
api.bootstrap(authHeader(requireToken()), date)
|
||||
|
||||
suspend fun acknowledgeTachographReminder(taskIds: List<String>): TachographReminderDto =
|
||||
api.acknowledgeTachographReminder(
|
||||
authHeader(requireToken()),
|
||||
AcknowledgeTachographReminderBody(taskIds),
|
||||
).tachographReminder
|
||||
|
||||
suspend fun route(routeId: String): RouteResponse =
|
||||
api.route(authHeader(requireToken()), routeId)
|
||||
|
||||
suspend fun leaveRequests(): List<DriverLeaveRequestDto> =
|
||||
api.leaveRequests(authHeader(requireToken())).data
|
||||
|
||||
suspend fun leaveSummary(): DriverLeaveSummaryDto =
|
||||
api.leaveSummary(authHeader(requireToken())).data
|
||||
|
||||
suspend fun leaveForecast(
|
||||
dateFrom: String,
|
||||
dateTo: String,
|
||||
type: String,
|
||||
requestMode: String,
|
||||
requestedQuantity: Int?,
|
||||
details: Map<String, String>,
|
||||
): DriverLeaveForecastDto =
|
||||
api.leaveForecast(
|
||||
authHeader(requireToken()),
|
||||
LeaveForecastBody(type, dateFrom, dateTo, requestMode, requestedQuantity, details),
|
||||
).data
|
||||
|
||||
suspend fun leaveCalendar(from: String, to: String): List<DriverLeaveCalendarEntryDto> =
|
||||
api.leaveCalendar(authHeader(requireToken()), from, to).data
|
||||
|
||||
suspend fun leaveRequest(id: String): DriverLeaveRequestDto =
|
||||
api.leaveRequest(authHeader(requireToken()), id).data
|
||||
|
||||
suspend fun createLeaveRequest(dateFrom: String, dateTo: String, type: String, note: String?): DriverLeaveRequestDto =
|
||||
api.createLeaveRequest(authHeader(requireToken()), CreateLeaveRequestBody(dateFrom, dateTo, type, note)).data
|
||||
suspend fun createLeaveRequest(
|
||||
dateFrom: String,
|
||||
dateTo: String,
|
||||
type: String,
|
||||
requestMode: String,
|
||||
requestedQuantity: Int?,
|
||||
details: Map<String, String>,
|
||||
idempotencyKey: String,
|
||||
note: String?,
|
||||
): DriverLeaveRequestDto =
|
||||
api.createLeaveRequest(
|
||||
authHeader(requireToken()),
|
||||
CreateLeaveRequestBody(
|
||||
dateFrom = dateFrom,
|
||||
dateTo = dateTo,
|
||||
type = type,
|
||||
requestMode = requestMode,
|
||||
requestedQuantity = requestedQuantity,
|
||||
details = details,
|
||||
idempotencyKey = idempotencyKey,
|
||||
note = note,
|
||||
),
|
||||
).data
|
||||
|
||||
suspend fun cancelLeaveRequest(id: String, expectedVersion: Long, comment: String? = null): DriverLeaveRequestDto =
|
||||
api.cancelLeaveRequest(authHeader(requireToken()), id, CancelLeaveRequestBody(comment, expectedVersion)).data
|
||||
|
||||
suspend fun leaveDocuments(id: String): List<DriverLeaveDocumentDto> =
|
||||
api.leaveDocuments(authHeader(requireToken()), id).data
|
||||
|
||||
suspend fun uploadLeaveDocument(id: String, documentType: String, uri: Uri): DriverLeaveDocumentDto {
|
||||
val resolver = context.contentResolver
|
||||
val mimeType = resolver.getType(uri) ?: "application/octet-stream"
|
||||
val fileMetadata = resolver.query(
|
||||
uri,
|
||||
arrayOf(OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
)?.use { cursor ->
|
||||
if (!cursor.moveToFirst()) {
|
||||
null
|
||||
} else {
|
||||
cursor.getString(0) to cursor.getLong(1)
|
||||
}
|
||||
}
|
||||
if ((fileMetadata?.second ?: 0L) > 20L * 1024L * 1024L) {
|
||||
error("Dokument jest za duży. Maksymalny rozmiar pliku to 20 MB.")
|
||||
}
|
||||
val bytes = resolver.openInputStream(uri)?.use { it.readBytes() }
|
||||
?: error("Nie można odczytać wybranego dokumentu.")
|
||||
val originalName = fileMetadata?.first
|
||||
?.takeIf { it.isNotBlank() }
|
||||
?: "dokument"
|
||||
val body = bytes.toRequestBody(mimeType.toMediaTypeOrNull())
|
||||
val file = MultipartBody.Part.createFormData("file", originalName, body)
|
||||
|
||||
return api.uploadLeaveDocument(
|
||||
authHeader(requireToken()),
|
||||
id,
|
||||
file,
|
||||
documentType.toPlainTextBody(),
|
||||
).data
|
||||
}
|
||||
|
||||
suspend fun completeRoute(routeId: String) =
|
||||
api.completeRoute(authHeader(requireToken()), routeId)
|
||||
|
||||
@@ -114,6 +202,9 @@ class DriverRepository(
|
||||
source: String,
|
||||
stage: String = "other",
|
||||
metadata: PhotoUploadMetadata = PhotoUploadMetadata(),
|
||||
workflowVersion: String? = null,
|
||||
workflowStepId: String? = null,
|
||||
workflowDocumentId: String? = null,
|
||||
): PhotoUploadResponse {
|
||||
val resolver = context.contentResolver
|
||||
val mimeType = resolver.getType(uri) ?: "image/jpeg"
|
||||
@@ -134,6 +225,9 @@ class DriverRepository(
|
||||
contentSha256.toPlainTextBody(),
|
||||
sourceBody,
|
||||
stage.toPlainTextBody(),
|
||||
workflowVersion?.toPlainTextBody(),
|
||||
workflowStepId?.toPlainTextBody(),
|
||||
workflowDocumentId?.toPlainTextBody(),
|
||||
metadataParts["takenAt"],
|
||||
metadataParts["latitude"],
|
||||
metadataParts["longitude"],
|
||||
@@ -161,6 +255,9 @@ class DriverRepository(
|
||||
upload.contentSha256.toPlainTextBody(),
|
||||
upload.source.toPlainTextBody(),
|
||||
upload.stage.toPlainTextBody(),
|
||||
upload.workflowVersion?.toPlainTextBody(),
|
||||
upload.workflowStepId?.toPlainTextBody(),
|
||||
upload.workflowDocumentId?.toPlainTextBody(),
|
||||
metadataParts["takenAt"],
|
||||
metadataParts["latitude"],
|
||||
metadataParts["longitude"],
|
||||
|
||||
@@ -3,6 +3,8 @@ package pl.firmatpp.kierowca.data.api
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import pl.firmatpp.kierowca.data.model.BootstrapResponse
|
||||
import pl.firmatpp.kierowca.data.model.AcknowledgeTachographReminderBody
|
||||
import pl.firmatpp.kierowca.data.model.AcknowledgeTachographReminderResponse
|
||||
import pl.firmatpp.kierowca.data.model.BroadcastAuthBody
|
||||
import pl.firmatpp.kierowca.data.model.BroadcastAuthResponse
|
||||
import pl.firmatpp.kierowca.data.model.CancelLeaveRequestBody
|
||||
@@ -11,9 +13,14 @@ import pl.firmatpp.kierowca.data.model.CreateLeaveRequestBody
|
||||
import pl.firmatpp.kierowca.data.model.DispatchSheetUploadResponse
|
||||
import pl.firmatpp.kierowca.data.model.FinishRouteBody
|
||||
import pl.firmatpp.kierowca.data.model.LeaveCalendarResponse
|
||||
import pl.firmatpp.kierowca.data.model.LeaveDocumentListResponse
|
||||
import pl.firmatpp.kierowca.data.model.LeaveDocumentResponse
|
||||
import pl.firmatpp.kierowca.data.model.LeaveForecastBody
|
||||
import pl.firmatpp.kierowca.data.model.LeaveForecastResponse
|
||||
import pl.firmatpp.kierowca.data.model.LeaveRequestListResponse
|
||||
import pl.firmatpp.kierowca.data.model.LeaveRequestResponse
|
||||
import pl.firmatpp.kierowca.data.model.LeaveRequestTypesResponse
|
||||
import pl.firmatpp.kierowca.data.model.LeaveSummaryResponse
|
||||
import pl.firmatpp.kierowca.data.model.OtpResponse
|
||||
import pl.firmatpp.kierowca.data.model.NotificationPreferencesBody
|
||||
import pl.firmatpp.kierowca.data.model.NotificationPreferencesDto
|
||||
@@ -67,11 +74,28 @@ interface MobileDriverApi {
|
||||
@Query("date") date: String?,
|
||||
): BootstrapResponse
|
||||
|
||||
@POST("mobile/driver/tachograph-reminder/acknowledge")
|
||||
suspend fun acknowledgeTachographReminder(
|
||||
@Header("Authorization") authorization: String,
|
||||
@Body body: AcknowledgeTachographReminderBody,
|
||||
): AcknowledgeTachographReminderResponse
|
||||
|
||||
@GET("mobile/driver/leave-request-types")
|
||||
suspend fun leaveRequestTypes(
|
||||
@Header("Authorization") authorization: String,
|
||||
): LeaveRequestTypesResponse
|
||||
|
||||
@GET("mobile/driver/leave-summary")
|
||||
suspend fun leaveSummary(
|
||||
@Header("Authorization") authorization: String,
|
||||
): LeaveSummaryResponse
|
||||
|
||||
@POST("mobile/driver/leave-forecast")
|
||||
suspend fun leaveForecast(
|
||||
@Header("Authorization") authorization: String,
|
||||
@Body body: LeaveForecastBody,
|
||||
): LeaveForecastResponse
|
||||
|
||||
@GET("mobile/driver/leave-requests")
|
||||
suspend fun leaveRequests(
|
||||
@Header("Authorization") authorization: String,
|
||||
@@ -96,6 +120,21 @@ interface MobileDriverApi {
|
||||
@Path("id") id: String,
|
||||
): LeaveRequestResponse
|
||||
|
||||
@GET("mobile/driver/leave-requests/{id}/documents")
|
||||
suspend fun leaveDocuments(
|
||||
@Header("Authorization") authorization: String,
|
||||
@Path("id") id: String,
|
||||
): LeaveDocumentListResponse
|
||||
|
||||
@Multipart
|
||||
@POST("mobile/driver/leave-requests/{id}/documents")
|
||||
suspend fun uploadLeaveDocument(
|
||||
@Header("Authorization") authorization: String,
|
||||
@Path("id") id: String,
|
||||
@Part file: MultipartBody.Part,
|
||||
@Part("documentType") documentType: RequestBody,
|
||||
): LeaveDocumentResponse
|
||||
|
||||
@POST("mobile/driver/leave-requests/{id}/cancel")
|
||||
suspend fun cancelLeaveRequest(
|
||||
@Header("Authorization") authorization: String,
|
||||
@@ -177,6 +216,9 @@ interface MobileDriverApi {
|
||||
@Part("contentSha256") contentSha256: RequestBody,
|
||||
@Part("source") source: RequestBody,
|
||||
@Part("stage") stage: RequestBody?,
|
||||
@Part("workflowVersion") workflowVersion: RequestBody?,
|
||||
@Part("workflowStepId") workflowStepId: RequestBody?,
|
||||
@Part("workflowDocumentId") workflowDocumentId: RequestBody?,
|
||||
@Part("takenAt") takenAt: RequestBody?,
|
||||
@Part("latitude") latitude: RequestBody?,
|
||||
@Part("longitude") longitude: RequestBody?,
|
||||
|
||||
@@ -47,6 +47,7 @@ data class BootstrapResponse(
|
||||
val routes: RoutesBucketDto,
|
||||
val driverAppSettings: DriverAppSettingsDto?,
|
||||
val dispatchSheetReminder: DispatchSheetReminderDto? = null,
|
||||
val tachographReminder: TachographReminderDto? = null,
|
||||
val notificationPreferences: NotificationPreferencesDto? = null,
|
||||
val realtime: RealtimeConfigDto? = null,
|
||||
val syncState: SyncStateResponse? = null,
|
||||
@@ -77,15 +78,51 @@ data class DriverAppSettingsDto(
|
||||
val loadingWeightRequirement: String? = null,
|
||||
val unloadingPhotoRequirement: String? = null,
|
||||
val unloadingWeightRequirement: String? = null,
|
||||
val routeWorkflow: DriverRouteWorkflowDto? = null,
|
||||
val dispatchSheetRemindersEnabled: Boolean? = null,
|
||||
val dispatchSheetOnFridays: Boolean? = null,
|
||||
val dispatchSheetOnLastWorkingDay: Boolean? = null,
|
||||
val tachographRemindersEnabled: Boolean? = null,
|
||||
val leaveRequests: LeaveRequestsConfigDto? = null,
|
||||
)
|
||||
|
||||
data class DriverRouteWorkflowDto(
|
||||
val version: String,
|
||||
val customized: Boolean = false,
|
||||
val loading: DriverRouteStageWorkflowDto,
|
||||
val unloading: DriverRouteStageWorkflowDto,
|
||||
)
|
||||
|
||||
data class DriverRouteStageWorkflowDto(
|
||||
val steps: List<DriverRouteWorkflowStepDto> = emptyList(),
|
||||
)
|
||||
|
||||
data class DriverRouteWorkflowStepDto(
|
||||
val id: String,
|
||||
val type: String,
|
||||
val title: String,
|
||||
val description: String = "",
|
||||
val requirement: String = "required",
|
||||
val documents: List<DriverRouteWorkflowDocumentDto> = emptyList(),
|
||||
)
|
||||
|
||||
data class DriverRouteWorkflowDocumentDto(
|
||||
val id: String,
|
||||
val label: String,
|
||||
val description: String = "",
|
||||
val requirement: String = "required",
|
||||
)
|
||||
|
||||
data class LeaveRequestsConfigDto(
|
||||
val enabled: Boolean = false,
|
||||
val types: List<String> = listOf("URLOP"),
|
||||
val usagePoolCodes: List<String> = listOf(
|
||||
"ANNUAL",
|
||||
"ANNUAL_DISABILITY",
|
||||
"FORCE_MAJEURE",
|
||||
"CHILD_CARE_14",
|
||||
"CARE_LEAVE",
|
||||
),
|
||||
)
|
||||
|
||||
data class DispatchSheetReminderDto(
|
||||
@@ -99,6 +136,30 @@ data class DispatchSheetReminderDto(
|
||||
val canUpload: Boolean = false,
|
||||
)
|
||||
|
||||
data class TachographReminderDto(
|
||||
val enabled: Boolean = false,
|
||||
val visible: Boolean = false,
|
||||
val title: String? = null,
|
||||
val message: String? = null,
|
||||
val confirmationLabel: String? = null,
|
||||
val tasks: List<TachographReminderTaskDto>? = null,
|
||||
)
|
||||
|
||||
data class TachographReminderTaskDto(
|
||||
val id: String,
|
||||
val type: String,
|
||||
val label: String,
|
||||
)
|
||||
|
||||
data class AcknowledgeTachographReminderBody(
|
||||
val taskIds: List<String>,
|
||||
)
|
||||
|
||||
data class AcknowledgeTachographReminderResponse(
|
||||
val ok: Boolean,
|
||||
val tachographReminder: TachographReminderDto,
|
||||
)
|
||||
|
||||
data class DispatchSheetPhotoDto(
|
||||
val id: String,
|
||||
val driverId: String,
|
||||
@@ -197,13 +258,111 @@ data class LeaveRequestTypesResponse(
|
||||
|
||||
data class LeaveRequestTypeDto(
|
||||
val value: String,
|
||||
val code: String? = null,
|
||||
val ruleCode: String? = null,
|
||||
val label: String,
|
||||
val category: String? = null,
|
||||
val unit: String? = null,
|
||||
val poolCode: String? = null,
|
||||
val requestModes: List<String> = listOf("days"),
|
||||
val requiredFields: List<String> = emptyList(),
|
||||
val requiredDocuments: List<String> = emptyList(),
|
||||
val fieldOptions: Map<String, Map<String, String>> = emptyMap(),
|
||||
val description: String? = null,
|
||||
val decisionMode: String? = null,
|
||||
val payrollMode: String? = null,
|
||||
val financialTreatmentLabel: String? = null,
|
||||
val affectsAnnualLeaveBalance: Boolean = false,
|
||||
val annualEntitlementImpact: String? = null,
|
||||
val requiresHrVerification: List<String> = emptyList(),
|
||||
val legalBasis: String? = null,
|
||||
)
|
||||
|
||||
data class LeaveSummaryResponse(
|
||||
val data: DriverLeaveSummaryDto,
|
||||
)
|
||||
|
||||
data class DriverLeaveSummaryDto(
|
||||
val pools: List<DriverLeavePoolDto> = emptyList(),
|
||||
val dailyNormMinutes: Int = 480,
|
||||
val balanceConfigured: Boolean = false,
|
||||
val overdueQuantity: Int = 0,
|
||||
val visibleUsagePoolCodes: List<String> = listOf(
|
||||
"ANNUAL",
|
||||
"ANNUAL_DISABILITY",
|
||||
"FORCE_MAJEURE",
|
||||
"CHILD_CARE_14",
|
||||
"CARE_LEAVE",
|
||||
),
|
||||
val availableTypes: List<LeaveRequestTypeDto> = emptyList(),
|
||||
val reminders: List<DriverLeaveReminderDto> = emptyList(),
|
||||
)
|
||||
|
||||
data class DriverLeavePoolDto(
|
||||
val id: Int,
|
||||
val poolCode: String,
|
||||
val year: Int,
|
||||
val unit: String,
|
||||
val calculatedQuantity: Int = 0,
|
||||
val confirmedQuantity: Int? = null,
|
||||
val availableQuantity: Int = 0,
|
||||
val reservedQuantity: Int = 0,
|
||||
val usedQuantity: Int = 0,
|
||||
val grantedQuantity: Int = 0,
|
||||
val overdue: Boolean = false,
|
||||
val status: String,
|
||||
)
|
||||
|
||||
data class DriverLeaveReminderDto(
|
||||
val code: String,
|
||||
val message: String,
|
||||
val poolId: Int? = null,
|
||||
)
|
||||
|
||||
data class LeaveForecastBody(
|
||||
val type: String,
|
||||
val dateFrom: String,
|
||||
val dateTo: String,
|
||||
val requestMode: String,
|
||||
val requestedQuantity: Int? = null,
|
||||
val details: Map<String, String> = emptyMap(),
|
||||
)
|
||||
|
||||
data class LeaveForecastResponse(
|
||||
val data: DriverLeaveForecastDto,
|
||||
)
|
||||
|
||||
data class DriverLeaveForecastDto(
|
||||
val ruleCode: String,
|
||||
val payrollMode: String? = null,
|
||||
val financialTreatmentLabel: String? = null,
|
||||
val affectsAnnualLeaveBalance: Boolean = false,
|
||||
val annualEntitlementImpact: String? = null,
|
||||
val requiresHrVerification: List<String> = emptyList(),
|
||||
val quantityUnit: String,
|
||||
val days: List<DriverLeaveForecastDayDto> = emptyList(),
|
||||
val workingDaysCount: Int = 0,
|
||||
val requestedQuantity: Int = 0,
|
||||
val availableQuantity: Int = 0,
|
||||
val balanceConfigured: Boolean = false,
|
||||
val sufficientBalance: Boolean = true,
|
||||
val pools: List<DriverLeavePoolDto> = emptyList(),
|
||||
)
|
||||
|
||||
data class DriverLeaveForecastDayDto(
|
||||
val date: String,
|
||||
val quantity: Int,
|
||||
val source: String? = null,
|
||||
)
|
||||
|
||||
data class CreateLeaveRequestBody(
|
||||
val dateFrom: String,
|
||||
val dateTo: String,
|
||||
val type: String,
|
||||
val requestMode: String = "days",
|
||||
val requestedQuantity: Int? = null,
|
||||
val details: Map<String, String> = emptyMap(),
|
||||
val idempotencyKey: String? = null,
|
||||
val note: String?,
|
||||
)
|
||||
|
||||
@@ -218,7 +377,13 @@ data class DriverLeaveRequestDto(
|
||||
val dateFrom: String?,
|
||||
val dateTo: String?,
|
||||
val type: String,
|
||||
val ruleCode: String? = null,
|
||||
val typeLabel: String? = null,
|
||||
val requestMode: String = "days",
|
||||
val requestedQuantity: Int? = null,
|
||||
val quantityUnit: String? = null,
|
||||
val rule: DriverLeaveRuleSnapshotDto? = null,
|
||||
val details: Map<String, String> = emptyMap(),
|
||||
val note: String? = null,
|
||||
val status: String,
|
||||
val version: Long = 1,
|
||||
@@ -229,6 +394,65 @@ data class DriverLeaveRequestDto(
|
||||
val decidedAt: String? = null,
|
||||
val decisionComment: String? = null,
|
||||
val events: List<DriverLeaveRequestEventDto> = emptyList(),
|
||||
val allocations: List<DriverLeaveAllocationDto> = emptyList(),
|
||||
val balanceConfigurationRequired: Boolean = false,
|
||||
val missingDocumentTypes: List<String> = emptyList(),
|
||||
val payrollMode: String? = null,
|
||||
val payrollItemTypes: List<String> = emptyList(),
|
||||
val financialTreatmentLabel: String? = null,
|
||||
val affectsAnnualLeaveBalance: Boolean = false,
|
||||
val annualEntitlementImpact: String? = null,
|
||||
val requiresLegalVerification: Boolean = false,
|
||||
val legalVerificationChecks: List<String> = emptyList(),
|
||||
)
|
||||
|
||||
data class DriverLeaveRuleSnapshotDto(
|
||||
val code: String? = null,
|
||||
val label: String? = null,
|
||||
val unit: String? = null,
|
||||
val decisionMode: String? = null,
|
||||
val payrollMode: String? = null,
|
||||
val poolCode: String? = null,
|
||||
val rule: DriverLeaveRuleRequirementsDto? = null,
|
||||
val legalBasis: String? = null,
|
||||
)
|
||||
|
||||
data class DriverLeaveRuleRequirementsDto(
|
||||
val requestModes: List<String> = listOf("days"),
|
||||
val requiredFields: List<String> = emptyList(),
|
||||
val requiredDocuments: List<String> = emptyList(),
|
||||
val fieldOptions: Map<String, Map<String, String>> = emptyMap(),
|
||||
val description: String? = null,
|
||||
val financialTreatmentLabel: String? = null,
|
||||
val affectsAnnualLeaveBalance: Boolean = false,
|
||||
val annualEntitlementImpact: String? = null,
|
||||
val requiresHrVerification: List<String> = emptyList(),
|
||||
)
|
||||
|
||||
data class DriverLeaveAllocationDto(
|
||||
val id: Int,
|
||||
val date: String?,
|
||||
val quantity: Int,
|
||||
val status: String,
|
||||
val poolId: Int? = null,
|
||||
val sourceYear: Int? = null,
|
||||
)
|
||||
|
||||
data class LeaveDocumentListResponse(
|
||||
val data: List<DriverLeaveDocumentDto> = emptyList(),
|
||||
)
|
||||
|
||||
data class LeaveDocumentResponse(
|
||||
val data: DriverLeaveDocumentDto,
|
||||
)
|
||||
|
||||
data class DriverLeaveDocumentDto(
|
||||
val id: Int,
|
||||
val documentType: String,
|
||||
val originalName: String,
|
||||
val mimeType: String? = null,
|
||||
val sizeBytes: Long = 0,
|
||||
val uploadedAt: String? = null,
|
||||
)
|
||||
|
||||
data class DriverLeaveCalendarEntryDto(
|
||||
@@ -326,6 +550,10 @@ data class RoutePhotoDto(
|
||||
val contentSha256: String? = null,
|
||||
val source: String,
|
||||
val stage: String = "other",
|
||||
val workflowVersion: String? = null,
|
||||
val workflowStepId: String? = null,
|
||||
val workflowDocumentId: String? = null,
|
||||
val originalName: String? = null,
|
||||
val mimeType: String?,
|
||||
val size: Long,
|
||||
val url: String,
|
||||
@@ -356,6 +584,8 @@ data class StartRouteBody(
|
||||
val occurredAt: String,
|
||||
val photoClientRequestIds: List<String>,
|
||||
val loadingNotes: String? = null,
|
||||
val workflowVersion: String? = null,
|
||||
val completedStepIds: List<String> = emptyList(),
|
||||
)
|
||||
|
||||
data class FinishRouteBody(
|
||||
@@ -364,6 +594,8 @@ data class FinishRouteBody(
|
||||
val occurredAt: String,
|
||||
val photoClientRequestIds: List<String>,
|
||||
val unloadingNotes: String? = null,
|
||||
val workflowVersion: String? = null,
|
||||
val completedStepIds: List<String> = emptyList(),
|
||||
)
|
||||
|
||||
data class RouteActionResponse(
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.google.gson.Gson
|
||||
import java.io.IOException
|
||||
import java.time.LocalDate
|
||||
import pl.firmatpp.kierowca.data.DriverRepository
|
||||
import pl.firmatpp.kierowca.data.rethrowIfCancellation
|
||||
import pl.firmatpp.kierowca.data.model.BootstrapResponse
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||
import pl.firmatpp.kierowca.data.model.RouteResponse
|
||||
@@ -38,6 +39,7 @@ class DriverSyncRepository(
|
||||
saveSyncStates(response.syncState)
|
||||
CachedValue(response, stale = false, syncedAtEpochMillis = System.currentTimeMillis())
|
||||
}.getOrElse { throwable ->
|
||||
throwable.rethrowIfCancellation()
|
||||
cachedBootstrap(requestedDate, throwable)
|
||||
}
|
||||
}
|
||||
@@ -58,6 +60,7 @@ class DriverSyncRepository(
|
||||
saveSyncStates(response.syncState)
|
||||
CachedValue(response, stale = false, syncedAtEpochMillis = System.currentTimeMillis())
|
||||
}.getOrElse { throwable ->
|
||||
throwable.rethrowIfCancellation()
|
||||
cachedRoute(routeId, throwable)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import pl.firmatpp.kierowca.data.sync.DriverSyncStateEntity
|
||||
DriverRouteCacheEntity::class,
|
||||
DriverSyncStateEntity::class,
|
||||
],
|
||||
version = 7,
|
||||
version = 8,
|
||||
exportSchema = false,
|
||||
)
|
||||
abstract class DriverDatabase : RoomDatabase() {
|
||||
@@ -208,6 +208,16 @@ abstract class DriverDatabase : RoomDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
private val migration7To8 = object : Migration(7, 8) {
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE photo_uploads ADD COLUMN workflowVersion TEXT")
|
||||
db.execSQL("ALTER TABLE photo_uploads ADD COLUMN workflowStepId TEXT")
|
||||
db.execSQL("ALTER TABLE photo_uploads ADD COLUMN workflowDocumentId TEXT")
|
||||
db.execSQL("ALTER TABLE route_actions ADD COLUMN workflowVersion TEXT")
|
||||
db.execSQL("ALTER TABLE route_actions ADD COLUMN completedStepIdsJson TEXT NOT NULL DEFAULT '[]'")
|
||||
}
|
||||
}
|
||||
|
||||
fun get(context: Context): DriverDatabase =
|
||||
instance ?: synchronized(this) {
|
||||
instance ?: Room.databaseBuilder(
|
||||
@@ -221,6 +231,7 @@ abstract class DriverDatabase : RoomDatabase() {
|
||||
migration4To5,
|
||||
migration5To6,
|
||||
migration6To7,
|
||||
migration7To8,
|
||||
).build().also { instance = it }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ data class PhotoUploadEntity(
|
||||
val localPath: String,
|
||||
val source: String,
|
||||
val stage: String = "other",
|
||||
val workflowVersion: String? = null,
|
||||
val workflowStepId: String? = null,
|
||||
val workflowDocumentId: String? = null,
|
||||
val takenAt: String?,
|
||||
val latitude: Double?,
|
||||
val longitude: Double?,
|
||||
|
||||
@@ -13,7 +13,9 @@ import java.io.File
|
||||
import java.security.MessageDigest
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.withContext
|
||||
import pl.firmatpp.kierowca.data.PhotoUploadMetadata
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
||||
@@ -29,12 +31,22 @@ class PhotoUploadOutbox(
|
||||
fun observeQueuedUploads(): Flow<List<PhotoUploadEntity>> =
|
||||
dao.observeQueuedUploads()
|
||||
|
||||
suspend fun enqueue(routeId: String, uri: Uri, source: String, metadata: PhotoUploadMetadata, stage: String = "other"): PhotoUploadEntity {
|
||||
suspend fun enqueue(
|
||||
routeId: String,
|
||||
uri: Uri,
|
||||
source: String,
|
||||
metadata: PhotoUploadMetadata,
|
||||
stage: String = "other",
|
||||
workflowVersion: String? = null,
|
||||
workflowStepId: String? = null,
|
||||
workflowDocumentId: String? = null,
|
||||
): PhotoUploadEntity = withContext(Dispatchers.IO) {
|
||||
val clientRequestId = UUID.randomUUID().toString()
|
||||
val mimeType = context.contentResolver.getType(uri) ?: "image/jpeg"
|
||||
val extension = when (mimeType) {
|
||||
"image/png" -> "png"
|
||||
"image/webp" -> "webp"
|
||||
"application/pdf" -> "pdf"
|
||||
else -> "jpg"
|
||||
}
|
||||
val uploadDir = File(context.filesDir, "photo-upload-outbox").apply { mkdirs() }
|
||||
@@ -46,6 +58,9 @@ class PhotoUploadOutbox(
|
||||
localPath = localFile.absolutePath,
|
||||
source = source,
|
||||
stage = stage,
|
||||
workflowVersion = workflowVersion,
|
||||
workflowStepId = workflowStepId,
|
||||
workflowDocumentId = workflowDocumentId,
|
||||
takenAt = metadata.takenAt,
|
||||
latitude = metadata.latitude,
|
||||
longitude = metadata.longitude,
|
||||
@@ -58,7 +73,7 @@ class PhotoUploadOutbox(
|
||||
dao.upsert(upload)
|
||||
enqueueWorker(clientRequestId)
|
||||
|
||||
return upload
|
||||
upload
|
||||
}
|
||||
|
||||
suspend fun retry(clientRequestId: String) {
|
||||
|
||||
@@ -33,6 +33,8 @@ data class RouteActionEntity(
|
||||
val weight: Double?,
|
||||
val occurredAt: String,
|
||||
val photoClientRequestIdsJson: String,
|
||||
val workflowVersion: String? = null,
|
||||
val completedStepIdsJson: String = "[]",
|
||||
val status: String = RouteActionStatus.Pending,
|
||||
val attemptCount: Int = 0,
|
||||
val lastError: String? = null,
|
||||
|
||||
@@ -48,16 +48,20 @@ class RouteActionOutbox(
|
||||
loadingWeight: Double?,
|
||||
photoClientRequestIds: List<String>,
|
||||
notes: String? = null,
|
||||
workflowVersion: String? = null,
|
||||
completedStepIds: List<String> = emptyList(),
|
||||
): RouteActionEntity =
|
||||
enqueue(RouteActionType.Start, routeId, loadingWeight, photoClientRequestIds, notes)
|
||||
enqueue(RouteActionType.Start, routeId, loadingWeight, photoClientRequestIds, notes, workflowVersion, completedStepIds)
|
||||
|
||||
suspend fun enqueueFinish(
|
||||
routeId: String,
|
||||
unloadingWeight: Double?,
|
||||
photoClientRequestIds: List<String>,
|
||||
notes: String? = null,
|
||||
workflowVersion: String? = null,
|
||||
completedStepIds: List<String> = emptyList(),
|
||||
): RouteActionEntity =
|
||||
enqueue(RouteActionType.Finish, routeId, unloadingWeight, photoClientRequestIds, notes)
|
||||
enqueue(RouteActionType.Finish, routeId, unloadingWeight, photoClientRequestIds, notes, workflowVersion, completedStepIds)
|
||||
|
||||
private suspend fun enqueue(
|
||||
action: String,
|
||||
@@ -65,6 +69,8 @@ class RouteActionOutbox(
|
||||
weight: Double?,
|
||||
photoClientRequestIds: List<String>,
|
||||
notes: String?,
|
||||
workflowVersion: String?,
|
||||
completedStepIds: List<String>,
|
||||
): RouteActionEntity {
|
||||
dao.pruneConfirmed(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7))
|
||||
val entity = RouteActionEntity(
|
||||
@@ -74,6 +80,8 @@ class RouteActionOutbox(
|
||||
weight = weight,
|
||||
occurredAt = Instant.now().toString(),
|
||||
photoClientRequestIdsJson = gson.toJson(photoClientRequestIds.distinct()),
|
||||
workflowVersion = workflowVersion,
|
||||
completedStepIdsJson = gson.toJson(completedStepIds.distinct()),
|
||||
notes = notes?.trim()?.takeIf { it.isNotEmpty() },
|
||||
)
|
||||
|
||||
|
||||
@@ -181,6 +181,8 @@ class RouteActionWorker(
|
||||
occurredAt = action.occurredAt,
|
||||
photoClientRequestIds = photoClientRequestIds,
|
||||
loadingNotes = action.notes,
|
||||
workflowVersion = action.workflowVersion,
|
||||
completedStepIds = completedStepIds(action),
|
||||
),
|
||||
)
|
||||
RouteActionType.Finish -> repository.finishRoute(
|
||||
@@ -191,6 +193,8 @@ class RouteActionWorker(
|
||||
occurredAt = action.occurredAt,
|
||||
photoClientRequestIds = photoClientRequestIds,
|
||||
unloadingNotes = action.notes,
|
||||
workflowVersion = action.workflowVersion,
|
||||
completedStepIds = completedStepIds(action),
|
||||
),
|
||||
)
|
||||
else -> error("Nieznana akcja kursu: ${action.action}")
|
||||
@@ -204,6 +208,14 @@ class RouteActionWorker(
|
||||
.filter { it.isNotBlank() }
|
||||
.distinct()
|
||||
|
||||
private fun completedStepIds(action: RouteActionEntity): List<String> =
|
||||
runCatching {
|
||||
gson.fromJson(action.completedStepIdsJson, Array<String>::class.java)?.toList().orEmpty()
|
||||
}.getOrDefault(emptyList())
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotBlank() }
|
||||
.distinct()
|
||||
|
||||
companion object {
|
||||
const val KEY_CLIENT_ACTION_ID = "clientActionId"
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,24 +2,36 @@ package pl.firmatpp.kierowca.ui
|
||||
|
||||
import java.time.LocalDate
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveCalendarEntryDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeavePoolDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveRequestDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveSummaryDto
|
||||
import pl.firmatpp.kierowca.data.model.LeaveRequestTypeDto
|
||||
|
||||
data class LeaveRequestsConfig(
|
||||
val enabled: Boolean = false,
|
||||
val types: List<String> = listOf("URLOP"),
|
||||
)
|
||||
|
||||
data class AnnualLeaveTotals(
|
||||
val availableMinutes: Int,
|
||||
val reservedMinutes: Int,
|
||||
val usedMinutes: Int,
|
||||
val grantedMinutes: Int,
|
||||
val overdueMinutes: Int,
|
||||
)
|
||||
|
||||
object DriverLeaveRequestUiRules {
|
||||
fun isFeatureVisible(config: LeaveRequestsConfig?): Boolean =
|
||||
config?.enabled == true && config.types.isNotEmpty()
|
||||
|
||||
fun statusLabel(status: String): String =
|
||||
when (status) {
|
||||
"pending" -> "Oczekuje"
|
||||
"approved" -> "Zatwierdzony"
|
||||
"pending" -> "Czeka na decyzję"
|
||||
"approved" -> "Zaakceptowany"
|
||||
"rejected" -> "Odrzucony"
|
||||
"cancel_requested" -> "Anulowanie do decyzji"
|
||||
"cancel_requested" -> "Czeka na anulowanie"
|
||||
"cancelled" -> "Anulowany"
|
||||
"revoked" -> "Cofnięto decyzję"
|
||||
"revoked" -> "Akceptacja cofnięta"
|
||||
else -> "Nieznany status"
|
||||
}
|
||||
|
||||
@@ -33,19 +45,245 @@ object DriverLeaveRequestUiRules {
|
||||
"cancellation_requested" -> "Kierowca poprosił o anulowanie"
|
||||
"cancellation_approved" -> "Anulowanie zatwierdzone"
|
||||
"cancellation_rejected" -> "Anulowanie odrzucone"
|
||||
"period_amended" -> "Zmieniono termin wniosku"
|
||||
"interrupted" -> "Nieobecność została przerwana"
|
||||
"annual_leave_interrupted" -> "Przywrócono urlop wypoczynkowy"
|
||||
else -> "Aktualizacja wniosku"
|
||||
}
|
||||
|
||||
fun typeLabel(type: String): String =
|
||||
when (type) {
|
||||
"URLOP" -> "Urlop"
|
||||
"CHOROBOWE" -> "Chorobowe"
|
||||
"SZKOLENIE" -> "Szkolenie"
|
||||
"URLOP", "ANNUAL" -> "Urlop wypoczynkowy"
|
||||
"ANNUAL_ON_DEMAND" -> "Urlop na żądanie"
|
||||
"ANNUAL_DISABILITY" -> "Dodatkowy urlop"
|
||||
"CHOROBOWE", "SICKNESS" -> "Niezdolność do pracy"
|
||||
"SZKOLENIE", "TRAINING" -> "Urlop szkoleniowy"
|
||||
"WOLNE" -> "Dzień wolny"
|
||||
"INNE" -> "Inne"
|
||||
"INNE", "OTHER_OPERATIONAL" -> "Inna nieobecność"
|
||||
"FORCE_MAJEURE" -> "Siła wyższa"
|
||||
"CHILD_CARE_14" -> "Opieka nad dzieckiem do 14 lat"
|
||||
"CARE_LEAVE" -> "Urlop opiekuńczy"
|
||||
"MATERNITY" -> "Urlop macierzyński"
|
||||
"MATERNITY_EQUIVALENT" -> "Urlop na warunkach macierzyńskiego"
|
||||
"MATERNITY_SUPPLEMENTARY" -> "Uzupełniający urlop macierzyński"
|
||||
"PARENTAL" -> "Urlop rodzicielski"
|
||||
"PATERNITY" -> "Urlop ojcowski"
|
||||
"CHILDCARE_UNPAID" -> "Urlop wychowawczy"
|
||||
"OCCASIONAL" -> "Zwolnienie okolicznościowe"
|
||||
"REHABILITATION" -> "Turnus rehabilitacyjny"
|
||||
"UNPAID" -> "Urlop bezpłatny"
|
||||
"PREGNANCY_EXAMS" -> "Badania w ciąży"
|
||||
"OCCUPATIONAL_EXAMS" -> "Badania pracownicze"
|
||||
"BLOOD_DONATION" -> "Zwolnienie krwiodawcy"
|
||||
"AUTHORITY_SUMMONS" -> "Wezwanie urzędowe"
|
||||
"RESCUE_DUTIES" -> "Obowiązki ratownicze"
|
||||
"MILITARY_DUTIES" -> "Obowiązki wojskowe"
|
||||
"ORGAN_DONOR_EXAMS" -> "Badania dawcy"
|
||||
"CARE_SICKNESS" -> "Opieka nad chorym dzieckiem lub członkiem rodziny"
|
||||
else -> type
|
||||
}
|
||||
|
||||
fun requestType(request: DriverLeaveRequestDto): String =
|
||||
request.typeLabel?.takeIf { it.isNotBlank() }
|
||||
?: request.rule?.label?.takeIf { it.isNotBlank() }
|
||||
?: typeLabel(request.ruleCode ?: request.type)
|
||||
|
||||
fun annualTotals(summary: DriverLeaveSummaryDto?): AnnualLeaveTotals {
|
||||
val annualPools = summary?.pools.orEmpty().filter {
|
||||
it.poolCode == "ANNUAL" && it.unit == "minutes" && it.status == "active"
|
||||
}
|
||||
return AnnualLeaveTotals(
|
||||
availableMinutes = annualPools.sumOf { it.availableQuantity },
|
||||
reservedMinutes = annualPools.sumOf { it.reservedQuantity },
|
||||
usedMinutes = annualPools.sumOf { it.usedQuantity },
|
||||
grantedMinutes = annualPools.sumOf { it.grantedQuantity },
|
||||
overdueMinutes = annualPools.filter { it.year < LocalDate.now().year }.sumOf { it.availableQuantity },
|
||||
)
|
||||
}
|
||||
|
||||
fun annualPools(summary: DriverLeaveSummaryDto?): List<DriverLeavePoolDto> =
|
||||
summary?.pools.orEmpty()
|
||||
.filter { it.poolCode == "ANNUAL" && it.status == "active" }
|
||||
.sortedByDescending { it.year }
|
||||
|
||||
fun isUsageVisible(summary: DriverLeaveSummaryDto?, poolCode: String): Boolean =
|
||||
summary?.visibleUsagePoolCodes?.contains(poolCode) ?: true
|
||||
|
||||
fun otherEntitlementPools(summary: DriverLeaveSummaryDto?): List<DriverLeavePoolDto> =
|
||||
summary?.pools.orEmpty()
|
||||
.filter { it.poolCode != "ANNUAL" && it.status == "active" }
|
||||
.sortedWith(compareBy<DriverLeavePoolDto>({ poolLabel(it.poolCode) }, { -it.year }))
|
||||
|
||||
fun poolLabel(poolCode: String): String =
|
||||
when (poolCode) {
|
||||
"ANNUAL" -> "Urlop wypoczynkowy"
|
||||
"ANNUAL_DISABILITY" -> "Dodatkowy urlop wypoczynkowy"
|
||||
"FORCE_MAJEURE" -> "Siła wyższa"
|
||||
"CHILD_CARE_14" -> "Opieka nad dzieckiem do 14 lat"
|
||||
"CARE_LEAVE" -> "Urlop opiekuńczy"
|
||||
else -> typeLabel(poolCode)
|
||||
}
|
||||
|
||||
fun requestQuantityUnit(request: DriverLeaveRequestDto): String {
|
||||
request.quantityUnit?.takeIf { it == "days" || it == "minutes" }?.let { return it }
|
||||
if (request.requestMode == "hours") return "minutes"
|
||||
if (request.rule?.unit == "calendar_days") return "days"
|
||||
|
||||
val poolCode = request.rule?.poolCode
|
||||
return if (
|
||||
request.requestMode == "days" &&
|
||||
poolCode != null &&
|
||||
poolCode !in setOf("ANNUAL", "ANNUAL_DISABILITY")
|
||||
) {
|
||||
"days"
|
||||
} else {
|
||||
"minutes"
|
||||
}
|
||||
}
|
||||
|
||||
fun allocationStatusLabel(status: String): String =
|
||||
when (status) {
|
||||
"reserved" -> "Uwzględniono w przyszłej nieobecności"
|
||||
"used" -> "Wykorzystano"
|
||||
"released" -> "Przywrócono do wykorzystania"
|
||||
else -> "Rozliczono"
|
||||
}
|
||||
|
||||
fun categoryLabel(category: String?): String =
|
||||
when (category) {
|
||||
"annual" -> "Urlop wypoczynkowy"
|
||||
"statutory_short" -> "Krótkie uprawnienia ustawowe"
|
||||
"family" -> "Rodzina i opieka"
|
||||
"parental" -> "Rodzicielstwo"
|
||||
"health" -> "Zdrowie i rehabilitacja"
|
||||
"training" -> "Nauka i szkolenia"
|
||||
"statutory_exemption" -> "Pozostałe zwolnienia ustawowe"
|
||||
"unpaid" -> "Nieobecności bezpłatne"
|
||||
"operational" -> "Pozostałe nieobecności"
|
||||
else -> "Inne rodzaje nieobecności"
|
||||
}
|
||||
|
||||
fun formatQuantity(quantity: Int, unit: String, dailyNormMinutes: Int = 480): String {
|
||||
if (unit == "days") return dayCountLabel(quantity)
|
||||
|
||||
val safeNorm = dailyNormMinutes.coerceAtLeast(1)
|
||||
val fullDays = quantity / safeNorm
|
||||
val remainingMinutes = quantity % safeNorm
|
||||
val hours = quantity / 60
|
||||
val minutes = quantity % 60
|
||||
val dayPart = when {
|
||||
fullDays == 0 && remainingMinutes == 0 -> "0 dni"
|
||||
remainingMinutes == 0 -> dayCountLabel(fullDays)
|
||||
fullDays == 0 -> "mniej niż 1 dzień"
|
||||
else -> "${dayCountLabel(fullDays)} + ${formatHours(remainingMinutes)}"
|
||||
}
|
||||
|
||||
return "$dayPart · ${hours} godz.${if (minutes > 0) " ${minutes} min" else ""}"
|
||||
}
|
||||
|
||||
fun formatHours(minutes: Int): String {
|
||||
val hours = minutes / 60
|
||||
val remainder = minutes % 60
|
||||
return when {
|
||||
hours == 0 -> "$remainder min"
|
||||
remainder == 0 -> "$hours godz."
|
||||
else -> "$hours godz. $remainder min"
|
||||
}
|
||||
}
|
||||
|
||||
fun dayCountLabel(days: Int): String {
|
||||
val suffix = when {
|
||||
days == 1 -> "dzień"
|
||||
days % 10 in 2..4 && days % 100 !in 12..14 -> "dni"
|
||||
else -> "dni"
|
||||
}
|
||||
return "$days $suffix"
|
||||
}
|
||||
|
||||
fun modeLabel(mode: String): String = if (mode == "hours") "Kilka godzin" else "Całe dni"
|
||||
|
||||
fun decisionExplanation(type: LeaveRequestTypeDto): String =
|
||||
when (type.decisionMode) {
|
||||
"mandatory_registration" -> "Po spełnieniu wymaganych warunków wniosek jest rejestrowany zgodnie z przepisami."
|
||||
"external_event" -> "Nieobecność wymaga potwierdzenia odpowiednim dokumentem."
|
||||
else -> "Wniosek zostanie przekazany do osoby, która podejmie decyzję."
|
||||
}
|
||||
|
||||
fun annualEntitlementImpact(impact: String?): String? =
|
||||
when (impact) {
|
||||
"proportional_after_one_month" ->
|
||||
"Nie pomniejszy puli od razu, ale okres trwający co najmniej miesiąc może zmniejszyć roczny wymiar urlopu po powrocie do pracy."
|
||||
"proportional_on_return_if_started_before_year" ->
|
||||
"Po powrocie z urlopu rozpoczętego w poprzednim roku wymiar urlopu wypoczynkowego zostanie naliczony proporcjonalnie."
|
||||
else -> null
|
||||
}
|
||||
|
||||
fun fieldLabel(field: String): String =
|
||||
when (field) {
|
||||
"childBirthDate" -> "Data urodzenia dziecka"
|
||||
"settlementMode" -> "Sposób wykorzystania w tym roku"
|
||||
"careRecipientName" -> "Imię i nazwisko osoby wymagającej opieki"
|
||||
"careRecipientRelationship" -> "Kim jest dla Ciebie ta osoba"
|
||||
"careReason" -> "Dlaczego potrzebna jest opieka"
|
||||
"careRecipientAddress" -> "Adres osoby wymagającej opieki"
|
||||
"childrenBornCount" -> "Liczba dzieci urodzonych przy jednym porodzie"
|
||||
"entitlementEventKey" -> "Opis zdarzenia"
|
||||
"partNumber" -> "Która to część urlopu"
|
||||
"childIdentityKey" -> "Imię dziecka"
|
||||
"occasionType" -> "Rodzaj zdarzenia rodzinnego"
|
||||
"examType" -> "Rodzaj egzaminu lub nauki"
|
||||
"educationProgramKey" -> "Nazwa szkoły lub programu"
|
||||
"classification" -> "Czego dotyczy nieobecność"
|
||||
"urgentFamilyReason" -> "Jaka pilna sprawa rodzinna wymaga Twojej obecności?"
|
||||
"childrenPlacedCount" -> "Liczba dzieci przyjętych na wychowanie"
|
||||
"placementType" -> "Sposób przyjęcia dziecka na wychowanie"
|
||||
"hospitalizationGroup" -> "Która sytuacja hospitalizacji dotyczy dziecka?"
|
||||
"eligibleHospitalDays" -> "Liczba dni hospitalizacji potwierdzona przez szpital"
|
||||
"maternityLeaveEndsAt" -> "Data zakończenia urlopu macierzyńskiego"
|
||||
"parentalEntitlementVariant" -> "Wymiar urlopu rodzicielskiego"
|
||||
"childcareEntitlementVariant" -> "Rodzaj urlopu wychowawczego"
|
||||
"careRecipientType" -> "Kogo dotyczy opieka?"
|
||||
"careEntitlementEventKey" -> "Opis okresu opieki"
|
||||
else -> "Dodatkowa informacja"
|
||||
}
|
||||
|
||||
fun fieldHint(field: String): String? =
|
||||
when (field) {
|
||||
"childBirthDate" -> "Wpisz datę w formacie RRRR-MM-DD, np. 2020-05-12"
|
||||
"entitlementEventKey" -> "Np. poród z 15.06.2026"
|
||||
"partNumber" -> "Np. 1"
|
||||
"childIdentityKey" -> "Wystarczy imię i rok urodzenia"
|
||||
"educationProgramKey" -> "Np. Technikum Transportowe w Poznaniu"
|
||||
"classification" -> "Krótko opisz powód, aby kadry mogły go prawidłowo zakwalifikować"
|
||||
"urgentFamilyReason" -> "Krótko opisz chorobę lub wypadek oraz dlaczego Twoja natychmiastowa obecność jest konieczna."
|
||||
"eligibleHospitalDays" -> "Wpisz liczbę z zaświadczenia, np. 12"
|
||||
"careEntitlementEventKey" -> "Wpisz prosty opis pozwalający kadrom połączyć części tego samego uprawnienia."
|
||||
else -> null
|
||||
}
|
||||
|
||||
fun documentLabel(type: String): String =
|
||||
when (type) {
|
||||
"disability_certificate" -> "Orzeczenie o niepełnosprawności"
|
||||
"parent_declaration" -> "Oświadczenie rodzica"
|
||||
"birth_document", "birth_or_adoption_document" -> "Dokument potwierdzający urodzenie lub przysposobienie"
|
||||
"adoption_or_care_document" -> "Dokument przysposobienia lub przyjęcia na wychowanie"
|
||||
"hospitalization_certificate" -> "Zaświadczenie o hospitalizacji"
|
||||
"parental_leave_declaration", "childcare_leave_declaration" -> "Oświadczenie dotyczące urlopu rodzicielskiego"
|
||||
"event_document" -> "Dokument potwierdzający zdarzenie"
|
||||
"training_confirmation" -> "Potwierdzenie nauki lub egzaminu"
|
||||
"rehabilitation_referral" -> "Skierowanie na turnus rehabilitacyjny"
|
||||
"medical_referral", "medical_referral_or_confirmation" -> "Skierowanie lub potwierdzenie badania"
|
||||
"blood_donation_certificate" -> "Zaświadczenie o oddaniu krwi"
|
||||
"authority_summons" -> "Wezwanie urzędowe"
|
||||
"rescue_service_confirmation" -> "Potwierdzenie służby ratowniczej"
|
||||
"military_document" -> "Dokument wojskowy"
|
||||
"external_sickness_confirmation" -> "Potwierdzenie niezdolności do pracy"
|
||||
"other_parent_declaration" -> "Oświadczenie drugiego rodzica"
|
||||
"organ_donor_confirmation" -> "Potwierdzenie badań lub zabiegu dawcy"
|
||||
"external_care_confirmation" -> "Potwierdzenie opieki lub e-ZLA"
|
||||
else -> "Wymagany dokument"
|
||||
}
|
||||
|
||||
fun canCancel(status: String, dateFrom: String, today: LocalDate = LocalDate.now()): Boolean {
|
||||
if (status == "pending") return true
|
||||
if (status != "approved") return false
|
||||
|
||||
@@ -12,8 +12,12 @@ import java.time.temporal.ChronoUnit
|
||||
import java.util.Locale
|
||||
import kotlin.math.abs
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteWorkflowDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteWorkflowStepDto
|
||||
import pl.firmatpp.kierowca.data.model.DispatchSheetReminderDto
|
||||
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
||||
import pl.firmatpp.kierowca.data.model.TachographReminderDto
|
||||
import pl.firmatpp.kierowca.data.model.TachographReminderTaskDto
|
||||
import pl.firmatpp.kierowca.data.model.driverLifecycleStatus
|
||||
import pl.firmatpp.kierowca.data.upload.PhotoUploadEntity
|
||||
import pl.firmatpp.kierowca.data.upload.PhotoUploadStatus
|
||||
@@ -276,6 +280,75 @@ fun routeStageRequirementIsVisible(requirement: String): Boolean =
|
||||
fun routeStageRequirementIsRequired(requirement: String): Boolean =
|
||||
normalizeRouteStageRequirement(requirement) == RouteStageRequirement.Required
|
||||
|
||||
object RouteWorkflowStepType {
|
||||
const val Confirmation = "confirmation"
|
||||
const val Weight = "weight"
|
||||
const val Photos = "photos"
|
||||
}
|
||||
|
||||
fun routeWorkflowSteps(workflow: DriverRouteWorkflowDto?, stage: String): List<DriverRouteWorkflowStepDto> =
|
||||
when (stage) {
|
||||
"loading" -> workflow?.loading?.steps
|
||||
"unloading" -> workflow?.unloading?.steps
|
||||
else -> null
|
||||
}.orEmpty().filter { routeStageRequirementIsVisible(it.requirement) }
|
||||
|
||||
fun routeWorkflowSubmitBlocker(
|
||||
workflow: DriverRouteWorkflowDto?,
|
||||
stage: String,
|
||||
completedStepIds: Set<String>,
|
||||
weightText: String,
|
||||
serverPhotos: List<RoutePhotoDto>,
|
||||
localUploads: List<PhotoUploadEntity>,
|
||||
): String? {
|
||||
val steps = routeWorkflowSteps(workflow, stage)
|
||||
if (steps.isEmpty()) return null
|
||||
val normalizedWeight = parseRouteWeightTons(weightText)
|
||||
|
||||
for (step in steps) {
|
||||
val required = routeStageRequirementIsRequired(step.requirement)
|
||||
when (step.type) {
|
||||
RouteWorkflowStepType.Confirmation -> if (required && step.id !in completedStepIds) {
|
||||
return "Potwierdź krok: ${step.title}."
|
||||
}
|
||||
RouteWorkflowStepType.Weight -> when {
|
||||
required && weightText.isBlank() -> return "Uzupełnij krok: ${step.title}."
|
||||
weightText.isNotBlank() && normalizedWeight == null -> return "Podaj poprawny tonaż."
|
||||
weightText.isNotBlank() && normalizedWeight != null && normalizedWeight <= 0.0 -> return "Tonaż musi być większy od zera."
|
||||
weightText.isNotBlank() && normalizedWeight != null && normalizedWeight > routeWeightMaxTons -> return "Tonaż nie może przekraczać 999,999 t."
|
||||
}
|
||||
RouteWorkflowStepType.Photos -> if (
|
||||
required &&
|
||||
serverPhotos.none { it.workflowDocumentId.isNullOrBlank() } &&
|
||||
localUploads.none {
|
||||
it.workflowDocumentId.isNullOrBlank() &&
|
||||
it.status != PhotoUploadStatus.Cancelled.storageValue &&
|
||||
it.status != PhotoUploadStatus.FailedPermanent.storageValue
|
||||
}
|
||||
) {
|
||||
return "Dodaj zdjęcie dla kroku: ${step.title}."
|
||||
}
|
||||
}
|
||||
|
||||
for (document in step.documents.filter { routeStageRequirementIsRequired(it.requirement) }) {
|
||||
val serverPresent = serverPhotos.any {
|
||||
it.workflowStepId == step.id && it.workflowDocumentId == document.id
|
||||
}
|
||||
val localPresent = localUploads.any {
|
||||
it.workflowStepId == step.id &&
|
||||
it.workflowDocumentId == document.id &&
|
||||
it.status != PhotoUploadStatus.Cancelled.storageValue &&
|
||||
it.status != PhotoUploadStatus.FailedPermanent.storageValue
|
||||
}
|
||||
if (!serverPresent && !localPresent) {
|
||||
return "Dodaj dokument „${document.label}” w kroku „${step.title}”."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
fun normalizeRouteStageNotes(value: String): String = value.take(routeStageNotesMaxLength)
|
||||
|
||||
fun parseRouteWeightTons(weightText: String): Double? {
|
||||
@@ -671,6 +744,16 @@ fun canLaunchCameraWithLocationPolicy(requirePreciseLocation: Boolean, hasFineLo
|
||||
fun shouldShowDispatchSheetReminderCard(reminder: DispatchSheetReminderDto?): Boolean =
|
||||
reminder?.dueToday == true && reminder.status in setOf("missing", "uploaded")
|
||||
|
||||
fun shouldShowTachographReminderCard(reminder: TachographReminderDto?): Boolean =
|
||||
reminder?.enabled == true &&
|
||||
reminder.visible &&
|
||||
!reminder.title.isNullOrBlank() &&
|
||||
!reminder.message.isNullOrBlank() &&
|
||||
!reminder.tasks.isNullOrEmpty()
|
||||
|
||||
fun defaultTachographConfirmationSelection(tasks: List<TachographReminderTaskDto>): Set<String> =
|
||||
if (tasks.size == 1) setOf(tasks.single().id) else emptySet()
|
||||
|
||||
fun dispatchSheetPrimaryActionLabel(reminder: DispatchSheetReminderDto?, hasQueuedUpload: Boolean): String =
|
||||
when {
|
||||
hasQueuedUpload -> "Wysyłam zdjęcie..."
|
||||
|
||||
@@ -9,6 +9,8 @@ import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.google.firebase.messaging.FirebaseMessaging
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
@@ -18,11 +20,13 @@ import kotlinx.coroutines.sync.withLock
|
||||
import java.time.LocalDate
|
||||
import java.time.Instant
|
||||
import java.io.IOException
|
||||
import java.util.UUID
|
||||
import pl.firmatpp.kierowca.data.AppPreferencesStore
|
||||
import pl.firmatpp.kierowca.data.ApiErrorMapper
|
||||
import pl.firmatpp.kierowca.data.ApiErrorKind
|
||||
import pl.firmatpp.kierowca.data.DriverRepository
|
||||
import pl.firmatpp.kierowca.data.PhotoUploadMetadata
|
||||
import pl.firmatpp.kierowca.data.rethrowIfCancellation
|
||||
import pl.firmatpp.kierowca.data.sync.DriverSyncRepository
|
||||
import pl.firmatpp.kierowca.data.sync.NetworkMonitor
|
||||
import pl.firmatpp.kierowca.data.sync.StartupOfflineFallbackLoader
|
||||
@@ -30,9 +34,14 @@ import pl.firmatpp.kierowca.data.model.DispatchSheetReminderDto
|
||||
import pl.firmatpp.kierowca.data.model.AppUpdateDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveCalendarEntryDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveDocumentDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveForecastDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveRequestDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveSummaryDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteWorkflowDto
|
||||
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
||||
import pl.firmatpp.kierowca.data.model.TachographReminderDto
|
||||
import pl.firmatpp.kierowca.data.model.driverLifecycleStatus
|
||||
import pl.firmatpp.kierowca.data.upload.DispatchSheetUploadEntity
|
||||
import pl.firmatpp.kierowca.data.upload.DispatchSheetUploadOutbox
|
||||
@@ -64,6 +73,16 @@ enum class DriverScreen { Initializing, Phone, Otp, Routes, Profile, Diagnostics
|
||||
|
||||
enum class ServerConnectionState { Unknown, Reachable, Degraded }
|
||||
|
||||
data class PreparingPhotoUpload(
|
||||
val id: String,
|
||||
val routeId: String,
|
||||
val uri: Uri,
|
||||
val stage: String,
|
||||
val workflowStepId: String?,
|
||||
val workflowDocumentId: String?,
|
||||
val createdAtEpochMillis: Long = System.currentTimeMillis(),
|
||||
)
|
||||
|
||||
data class DriverUiState(
|
||||
val screen: DriverScreen = DriverScreen.Initializing,
|
||||
val loading: Boolean = true,
|
||||
@@ -90,6 +109,7 @@ data class DriverUiState(
|
||||
val loadingWeightRequirement: String = RouteStageRequirement.Required,
|
||||
val unloadingPhotoRequirement: String = RouteStageRequirement.Required,
|
||||
val unloadingWeightRequirement: String = RouteStageRequirement.Required,
|
||||
val routeWorkflow: DriverRouteWorkflowDto? = null,
|
||||
val notifyNewRoutes: Boolean = false,
|
||||
val routeProgressNotificationEnabled: Boolean = true,
|
||||
val notificationPermissionDenied: Boolean = false,
|
||||
@@ -97,20 +117,33 @@ data class DriverUiState(
|
||||
val selectedPhoto: RoutePhotoDto? = null,
|
||||
val routeStageWeightText: String = "",
|
||||
val routeStageNotesText: String = "",
|
||||
val routeStageCompletedStepIds: Set<String> = emptySet(),
|
||||
val routeActions: List<RouteActionEntity> = emptyList(),
|
||||
val visibleRouteActions: List<RouteActionEntity> = emptyList(),
|
||||
val photoUploads: List<PhotoUploadEntity> = emptyList(),
|
||||
val preparingPhotoUploads: List<PreparingPhotoUpload> = emptyList(),
|
||||
val queuedPhotoUploads: List<PhotoUploadEntity> = emptyList(),
|
||||
val dispatchSheetReminder: DispatchSheetReminderDto? = null,
|
||||
val tachographReminder: TachographReminderDto? = null,
|
||||
val tachographReminderSubmitting: Boolean = false,
|
||||
val appUpdate: AppUpdateDto? = null,
|
||||
val dispatchSheetUploads: List<DispatchSheetUploadEntity> = emptyList(),
|
||||
val leaveRequestsConfig: LeaveRequestsConfig? = null,
|
||||
val leaveSummary: DriverLeaveSummaryDto? = null,
|
||||
val leaveRequests: List<DriverLeaveRequestDto> = emptyList(),
|
||||
val selectedLeaveRequest: DriverLeaveRequestDto? = null,
|
||||
val leaveRequestDateFrom: String = LocalDate.now().toString(),
|
||||
val leaveRequestDateTo: String = LocalDate.now().toString(),
|
||||
val leaveRequestType: String = "URLOP",
|
||||
val leaveRequestMode: String = "days",
|
||||
val leaveRequestHoursText: String = "",
|
||||
val leaveRequestDetails: Map<String, String> = emptyMap(),
|
||||
val leaveRequestIdempotencyKey: String = "",
|
||||
val leaveRequestNote: String = "",
|
||||
val leaveForecast: DriverLeaveForecastDto? = null,
|
||||
val leaveForecastLoading: Boolean = false,
|
||||
val leaveDocuments: List<DriverLeaveDocumentDto> = emptyList(),
|
||||
val leaveDocumentUploading: Boolean = false,
|
||||
val leaveCalendarEntries: List<DriverLeaveCalendarEntryDto> = emptyList(),
|
||||
val leaveCalendarLoading: Boolean = false,
|
||||
val leaveCalendarLoadedUntil: String? = null,
|
||||
@@ -199,6 +232,31 @@ internal fun DriverUiState.withLoadedLeaveRequests(
|
||||
)
|
||||
}
|
||||
|
||||
internal fun shouldStartRoutesLoad(
|
||||
screen: DriverScreen,
|
||||
navigateToRoutes: Boolean,
|
||||
startupOfflineOnly: Boolean,
|
||||
startupLoadInProgress: Boolean = false,
|
||||
): Boolean =
|
||||
(!startupLoadInProgress || navigateToRoutes || startupOfflineOnly) &&
|
||||
(screen != DriverScreen.Initializing || navigateToRoutes || startupOfflineOnly)
|
||||
|
||||
internal fun screenAfterBootstrap(
|
||||
currentScreen: DriverScreen,
|
||||
navigateToRoutes: Boolean,
|
||||
leaveRequestsEnabled: Boolean,
|
||||
): DriverScreen = when {
|
||||
currentScreen == DriverScreen.Initializing -> DriverScreen.Routes
|
||||
!leaveRequestsEnabled && currentScreen in setOf(
|
||||
DriverScreen.LeaveRequests,
|
||||
DriverScreen.LeaveRequestDetail,
|
||||
DriverScreen.LeaveCalendar,
|
||||
DriverScreen.AddLeaveRequest,
|
||||
) -> DriverScreen.Routes
|
||||
navigateToRoutes -> DriverScreen.Routes
|
||||
else -> currentScreen
|
||||
}
|
||||
|
||||
class DriverViewModel(application: Application) : AndroidViewModel(application) {
|
||||
private val appPreferencesStore = AppPreferencesStore(application)
|
||||
private val repository = DriverRepository(application)
|
||||
@@ -233,6 +291,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
private var routesRequestGeneration: Long = 0
|
||||
private var routeDetailRequestGeneration: Long = 0
|
||||
private var routesLoadJob: Job? = null
|
||||
private var startupLoadInProgress: Boolean = false
|
||||
val state: StateFlow<DriverUiState> = _state
|
||||
|
||||
init {
|
||||
@@ -470,6 +529,39 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
loadRoutes(date = date, showLoading = true, navigateToRoutes = true)
|
||||
}
|
||||
|
||||
fun acknowledgeTachographReminder(taskIds: List<String>) {
|
||||
val snapshot = _state.value
|
||||
if (taskIds.isEmpty() || snapshot.tachographReminderSubmitting) return
|
||||
if (!snapshot.isOnline) {
|
||||
_state.update { it.copy(error = "Potwierdzenie odczytu wymaga połączenia z internetem.") }
|
||||
return
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
_state.update {
|
||||
it.copy(
|
||||
tachographReminderSubmitting = true,
|
||||
error = null,
|
||||
feedback = null,
|
||||
)
|
||||
}
|
||||
runCatching { repository.acknowledgeTachographReminder(taskIds) }
|
||||
.onSuccess { reminder ->
|
||||
_state.update {
|
||||
it.copy(
|
||||
tachographReminder = reminder,
|
||||
feedback = "Zapisano potwierdzenie odczytu.",
|
||||
error = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
.onFailure { throwable ->
|
||||
_state.update { it.withApiError(throwable) }
|
||||
}
|
||||
_state.update { it.copy(tachographReminderSubmitting = false) }
|
||||
}
|
||||
}
|
||||
|
||||
fun dismissRouteDayLiveUpdate() {
|
||||
_state.update { it.copy(routeDayLiveUpdateMessage = null) }
|
||||
}
|
||||
@@ -480,24 +572,35 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
navigateToRoutes: Boolean,
|
||||
startupOfflineOnly: Boolean = false,
|
||||
) {
|
||||
val requestSnapshot = _state.value
|
||||
if (!shouldStartRoutesLoad(
|
||||
screen = requestSnapshot.screen,
|
||||
navigateToRoutes = navigateToRoutes,
|
||||
startupOfflineOnly = startupOfflineOnly,
|
||||
startupLoadInProgress = startupLoadInProgress,
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
val isStartup = requestSnapshot.screen == DriverScreen.Initializing
|
||||
if (isStartup) startupLoadInProgress = true
|
||||
val generation = ++routesRequestGeneration
|
||||
routesLoadJob?.cancel()
|
||||
routesLoadJob = viewModelScope.launch {
|
||||
val isStartup = _state.value.screen == DriverScreen.Initializing
|
||||
val loadJob = viewModelScope.launch {
|
||||
_state.update { it.copy(loading = showLoading, refreshing = !showLoading, feedback = null, error = null) }
|
||||
|
||||
runCatching {
|
||||
val cached = when {
|
||||
startupOfflineOnly -> syncRepository.bootstrapFromCache(date)
|
||||
?: throw IOException("Brak zapisanych danych dla wybranego dnia.")
|
||||
!_state.value.isOnline -> syncRepository.bootstrapFromCache(date)
|
||||
?: throw IOException("Brak zapisanych danych dla wybranego dnia.")
|
||||
isStartup -> {
|
||||
startupOfflineFallbackLoader.load(
|
||||
onlineLoad = { syncRepository.bootstrap(date) },
|
||||
offlineLoad = { syncRepository.bootstrapFromCache(date) },
|
||||
)
|
||||
}
|
||||
!_state.value.isOnline -> syncRepository.bootstrapFromCache(date)
|
||||
?: throw IOException("Brak zapisanych danych dla wybranego dnia.")
|
||||
else -> syncRepository.bootstrap(date)
|
||||
}
|
||||
val response = cached.value
|
||||
@@ -509,6 +612,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
driver = response.session.driver,
|
||||
routes = response.routes.today,
|
||||
dispatchSheetReminder = response.dispatchSheetReminder,
|
||||
tachographReminder = response.tachographReminder,
|
||||
appUpdate = response.appUpdate ?: it.appUpdate,
|
||||
selectedDate = settings?.selectedDate ?: date ?: it.selectedDate,
|
||||
minRouteDate = settings?.minDate ?: it.minRouteDate,
|
||||
@@ -523,13 +627,15 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
loadingWeightRequirement = normalizeRouteStageRequirement(settings?.loadingWeightRequirement),
|
||||
unloadingPhotoRequirement = normalizeRouteStageRequirement(settings?.unloadingPhotoRequirement),
|
||||
unloadingWeightRequirement = normalizeRouteStageRequirement(settings?.unloadingWeightRequirement),
|
||||
routeWorkflow = settings?.routeWorkflow,
|
||||
leaveRequestsConfig = settings?.leaveRequests?.let { config ->
|
||||
LeaveRequestsConfig(enabled = config.enabled, types = config.types)
|
||||
},
|
||||
screen = if (
|
||||
settings?.leaveRequests?.enabled != true &&
|
||||
it.screen in setOf(DriverScreen.LeaveRequests, DriverScreen.LeaveRequestDetail, DriverScreen.AddLeaveRequest)
|
||||
) DriverScreen.Routes else if (navigateToRoutes) DriverScreen.Routes else it.screen,
|
||||
screen = screenAfterBootstrap(
|
||||
currentScreen = it.screen,
|
||||
navigateToRoutes = navigateToRoutes,
|
||||
leaveRequestsEnabled = settings?.leaveRequests?.enabled == true,
|
||||
),
|
||||
notifyNewRoutes = response.notificationPreferences?.notifyNewRoutes ?: it.notifyNewRoutes,
|
||||
imageAuthHeader = repository.imageAuthHeader(),
|
||||
isStale = cached.stale || !it.isOnline,
|
||||
@@ -556,6 +662,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
reconcileTrackingService(response.routes.today, response.session.driver)
|
||||
}
|
||||
}.onFailure { throwable ->
|
||||
throwable.rethrowIfCancellation()
|
||||
if (generation != routesRequestGeneration) return@onFailure
|
||||
reportHandledException("load_routes", throwable, mapOf("date" to date))
|
||||
if (ApiErrorMapper.map(throwable).kind == ApiErrorKind.Auth) {
|
||||
@@ -573,6 +680,14 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
it.copy(loading = false, refreshing = false)
|
||||
}
|
||||
}
|
||||
routesLoadJob = loadJob
|
||||
if (isStartup) {
|
||||
loadJob.invokeOnCompletion {
|
||||
if (generation == routesRequestGeneration) {
|
||||
startupLoadInProgress = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun openRoute(routeId: String) = openRouteWithTarget(routeId, DriverScreen.Detail)
|
||||
@@ -661,6 +776,12 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
fun openProfile() {
|
||||
_state.update { it.copy(screen = DriverScreen.Profile, error = null) }
|
||||
if (
|
||||
DriverLeaveRequestUiRules.isFeatureVisible(_state.value.leaveRequestsConfig) &&
|
||||
_state.value.isOnline
|
||||
) {
|
||||
viewModelScope.launch { loadLeaveOverview(showLoading = false, navigateToList = false) }
|
||||
}
|
||||
}
|
||||
|
||||
fun openDiagnostics() {
|
||||
@@ -877,13 +998,34 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
private suspend fun loadLeaveRequests(showLoading: Boolean, navigateToList: Boolean): Boolean {
|
||||
return loadLeaveOverview(showLoading, navigateToList)
|
||||
}
|
||||
|
||||
private suspend fun loadLeaveOverview(showLoading: Boolean, navigateToList: Boolean): Boolean {
|
||||
_state.update { it.copy(loading = showLoading, refreshing = !showLoading, error = null, feedback = null) }
|
||||
val result = runCatching { repository.leaveRequests() }
|
||||
result.onSuccess { requests ->
|
||||
val (requestsResult, summaryResult) = coroutineScope {
|
||||
val requests = async { runCatching { repository.leaveRequests() } }
|
||||
val summary = async { runCatching { repository.leaveSummary() } }
|
||||
requests.await() to summary.await()
|
||||
}
|
||||
requestsResult.onSuccess { requests ->
|
||||
_state.update { it.withLoadedLeaveRequests(requests, navigateToList) }
|
||||
}.onFailure { throwable -> _state.update { it.withApiError(throwable) } }
|
||||
summaryResult.onSuccess { summary ->
|
||||
_state.update {
|
||||
it.copy(
|
||||
leaveSummary = summary,
|
||||
leaveForecast = if (it.screen == DriverScreen.AddLeaveRequest) null else it.leaveForecast,
|
||||
)
|
||||
}
|
||||
}.onFailure { throwable ->
|
||||
if (requestsResult.isSuccess) {
|
||||
val message = ApiErrorMapper.map(throwable).message
|
||||
_state.update { it.copy(error = "Nie udało się odświeżyć salda urlopu. $message") }
|
||||
}
|
||||
}
|
||||
_state.update { it.copy(loading = false, refreshing = false) }
|
||||
return result.isSuccess
|
||||
return requestsResult.isSuccess
|
||||
}
|
||||
|
||||
fun openLeaveRequest(id: String) {
|
||||
@@ -901,9 +1043,23 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(loading = true, error = null, feedback = null) }
|
||||
runCatching { repository.leaveRequest(id) }
|
||||
.onSuccess { request ->
|
||||
_state.update { it.copy(screen = DriverScreen.LeaveRequestDetail, selectedLeaveRequest = request, error = null) }
|
||||
val (requestResult, documentsResult) = coroutineScope {
|
||||
val leaveRequest = async { runCatching { repository.leaveRequest(id) } }
|
||||
val documents = async { runCatching { repository.leaveDocuments(id) } }
|
||||
leaveRequest.await() to documents.await()
|
||||
}
|
||||
requestResult
|
||||
.onSuccess { leaveRequest ->
|
||||
_state.update {
|
||||
it.copy(
|
||||
screen = DriverScreen.LeaveRequestDetail,
|
||||
selectedLeaveRequest = leaveRequest,
|
||||
leaveDocuments = documentsResult.getOrDefault(emptyList()),
|
||||
error = documentsResult.exceptionOrNull()?.let { error ->
|
||||
"Nie udało się pobrać listy dokumentów. ${ApiErrorMapper.map(error).message}"
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
.onFailure { throwable -> _state.update { it.withApiError(throwable) } }
|
||||
_state.update { it.copy(loading = false) }
|
||||
@@ -917,14 +1073,44 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
_state.update { it.copy(error = "Złożenie wniosku urlopowego wymaga połączenia z internetem.") }
|
||||
return
|
||||
}
|
||||
if (_state.value.leaveSummary?.availableTypes.isNullOrEmpty()) {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(loading = true, error = null) }
|
||||
runCatching { repository.leaveSummary() }
|
||||
.onSuccess { summary ->
|
||||
_state.update { it.copy(leaveSummary = summary, loading = false) }
|
||||
beginLeaveRequestDraft(config)
|
||||
}
|
||||
.onFailure { throwable ->
|
||||
_state.update { it.withApiError(throwable).copy(loading = false) }
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
beginLeaveRequestDraft(config)
|
||||
}
|
||||
|
||||
private fun beginLeaveRequestDraft(config: LeaveRequestsConfig?) {
|
||||
val today = LocalDate.now().toString()
|
||||
val defaultType = _state.value.leaveSummary?.availableTypes?.firstOrNull()
|
||||
val type = defaultType?.value ?: config?.types?.firstOrNull() ?: "URLOP"
|
||||
val mode = defaultType?.requestModes?.firstOrNull() ?: "days"
|
||||
_state.update {
|
||||
it.copy(
|
||||
screen = DriverScreen.LeaveCalendar,
|
||||
screen = DriverScreen.AddLeaveRequest,
|
||||
leaveRequestDateFrom = today,
|
||||
leaveRequestDateTo = today,
|
||||
leaveRequestType = config?.types?.firstOrNull() ?: "URLOP",
|
||||
leaveRequestType = type,
|
||||
leaveRequestMode = mode,
|
||||
leaveRequestHoursText = "",
|
||||
leaveRequestDetails = if ("settlementMode" in defaultType?.requiredFields.orEmpty()) {
|
||||
mapOf("settlementMode" to mode)
|
||||
} else {
|
||||
emptyMap()
|
||||
},
|
||||
leaveRequestIdempotencyKey = UUID.randomUUID().toString(),
|
||||
leaveRequestNote = "",
|
||||
leaveForecast = null,
|
||||
leaveCalendarEntries = emptyList(),
|
||||
leaveCalendarLoadedUntil = null,
|
||||
leaveCalendarHasSelection = false,
|
||||
@@ -933,22 +1119,64 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
feedback = null,
|
||||
)
|
||||
}
|
||||
loadMoreLeaveCalendarMonths(reset = true)
|
||||
}
|
||||
|
||||
fun updateLeaveRequestDraft(dateFrom: String? = null, dateTo: String? = null, type: String? = null, note: String? = null) {
|
||||
fun updateLeaveRequestType(type: String) {
|
||||
val metadata = _state.value.leaveSummary?.availableTypes?.firstOrNull { it.value == type }
|
||||
_state.update {
|
||||
val nextFrom = dateFrom ?: it.leaveRequestDateFrom
|
||||
val nextTo = dateTo ?: it.leaveRequestDateTo
|
||||
it.copy(
|
||||
leaveRequestDateFrom = nextFrom,
|
||||
leaveRequestDateTo = if (nextTo < nextFrom) nextFrom else nextTo,
|
||||
leaveRequestType = type ?: it.leaveRequestType,
|
||||
leaveRequestNote = note ?: it.leaveRequestNote,
|
||||
leaveRequestType = type,
|
||||
leaveRequestMode = metadata?.requestModes?.firstOrNull() ?: "days",
|
||||
leaveRequestHoursText = "",
|
||||
leaveRequestDetails = if ("settlementMode" in metadata?.requiredFields.orEmpty()) {
|
||||
mapOf("settlementMode" to (metadata?.requestModes?.firstOrNull() ?: "days"))
|
||||
} else {
|
||||
emptyMap()
|
||||
},
|
||||
leaveForecast = null,
|
||||
error = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateLeaveRequestMode(mode: String) {
|
||||
val metadata = selectedLeaveRequestType() ?: return
|
||||
if (mode !in metadata.requestModes) return
|
||||
_state.update {
|
||||
it.copy(
|
||||
leaveRequestMode = mode,
|
||||
leaveRequestDateTo = if (mode == "hours") it.leaveRequestDateFrom else it.leaveRequestDateTo,
|
||||
leaveRequestHoursText = if (mode == "hours") it.leaveRequestHoursText else "",
|
||||
leaveRequestDetails = if ("settlementMode" in metadata.requiredFields) {
|
||||
it.leaveRequestDetails + ("settlementMode" to mode)
|
||||
} else {
|
||||
it.leaveRequestDetails
|
||||
},
|
||||
leaveForecast = null,
|
||||
error = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateLeaveRequestHours(value: String) {
|
||||
val normalized = value.filter { it.isDigit() || it == ',' || it == '.' }.take(5)
|
||||
_state.update { it.copy(leaveRequestHoursText = normalized, leaveForecast = null, error = null) }
|
||||
}
|
||||
|
||||
fun updateLeaveRequestDetail(field: String, value: String) {
|
||||
_state.update {
|
||||
it.copy(
|
||||
leaveRequestDetails = it.leaveRequestDetails + (field to value),
|
||||
leaveForecast = null,
|
||||
error = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateLeaveRequestNote(value: String) {
|
||||
_state.update { it.copy(leaveRequestNote = value, error = null) }
|
||||
}
|
||||
|
||||
fun selectLeaveCalendarDate(date: String) {
|
||||
val selected = runCatching { LocalDate.parse(date) }.getOrNull() ?: return
|
||||
if (selected.isBefore(LocalDate.now())) return
|
||||
@@ -984,7 +1212,15 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
return
|
||||
}
|
||||
|
||||
_state.update { it.copy(screen = DriverScreen.AddLeaveRequest, error = null, feedback = null) }
|
||||
_state.update {
|
||||
it.copy(
|
||||
screen = DriverScreen.AddLeaveRequest,
|
||||
leaveRequestDateTo = if (it.leaveRequestMode == "hours") it.leaveRequestDateFrom else it.leaveRequestDateTo,
|
||||
leaveForecast = null,
|
||||
error = null,
|
||||
feedback = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun reopenLeaveCalendarFromDraft() {
|
||||
@@ -1002,6 +1238,53 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
fun refreshLeaveForecast() {
|
||||
val snapshot = _state.value
|
||||
if (!snapshot.isOnline || snapshot.leaveForecastLoading) return
|
||||
if (!snapshot.leaveCalendarHasSelection) {
|
||||
_state.update { it.copy(error = "Najpierw wybierz termin nieobecności.") }
|
||||
return
|
||||
}
|
||||
val type = selectedLeaveRequestType()
|
||||
if (type == null) {
|
||||
_state.update { it.copy(error = "Wybierz rodzaj nieobecności.") }
|
||||
return
|
||||
}
|
||||
val missingField = type.requiredFields
|
||||
.filterNot { it == "settlementMode" }
|
||||
.firstOrNull { snapshot.leaveRequestDetails[it].isNullOrBlank() }
|
||||
if (missingField != null) {
|
||||
_state.update {
|
||||
it.copy(error = "Uzupełnij pole „${DriverLeaveRequestUiRules.fieldLabel(missingField)}”.")
|
||||
}
|
||||
return
|
||||
}
|
||||
val requestedMinutes = requestedLeaveMinutes(snapshot)
|
||||
if (snapshot.leaveRequestMode == "hours" && requestedMinutes == null) {
|
||||
_state.update { it.copy(error = "Wpisz liczbę godzin, o które chcesz wnioskować.") }
|
||||
return
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(leaveForecastLoading = true, leaveForecast = null, error = null) }
|
||||
runCatching {
|
||||
repository.leaveForecast(
|
||||
dateFrom = snapshot.leaveRequestDateFrom,
|
||||
dateTo = snapshot.leaveRequestDateTo,
|
||||
type = snapshot.leaveRequestType,
|
||||
requestMode = snapshot.leaveRequestMode,
|
||||
requestedQuantity = requestedMinutes,
|
||||
details = snapshot.leaveRequestDetails,
|
||||
)
|
||||
}.onSuccess { forecast ->
|
||||
_state.update { it.copy(leaveForecast = forecast, error = null) }
|
||||
}.onFailure { throwable ->
|
||||
_state.update { it.withApiError(throwable) }
|
||||
}
|
||||
_state.update { it.copy(leaveForecastLoading = false) }
|
||||
}
|
||||
}
|
||||
|
||||
fun loadMoreLeaveCalendarMonths(reset: Boolean = false) {
|
||||
val snapshot = _state.value
|
||||
if (!DriverLeaveRequestUiRules.isFeatureVisible(snapshot.leaveRequestsConfig) || snapshot.leaveCalendarLoading) return
|
||||
@@ -1056,6 +1339,14 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
_state.update { it.copy(error = "Wysłanie wniosku wymaga połączenia z internetem.") }
|
||||
return
|
||||
}
|
||||
if (snapshot.leaveForecast == null) {
|
||||
_state.update { it.copy(error = "Najpierw wybierz „Sprawdź wniosek”, aby zobaczyć jego podsumowanie.") }
|
||||
return
|
||||
}
|
||||
if (!snapshot.leaveForecast.sufficientBalance) {
|
||||
_state.update { it.copy(error = "Nie możesz wysłać tego wniosku, ponieważ dostępne saldo jest za małe.") }
|
||||
return
|
||||
}
|
||||
if (!leaveMutationMutex.tryLock()) return
|
||||
if (snapshot.leaveRequestDateFrom < LocalDate.now().toString()) {
|
||||
_state.update { it.copy(error = "Data od nie może być z przeszłości.") }
|
||||
@@ -1071,16 +1362,30 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
dateFrom = snapshot.leaveRequestDateFrom,
|
||||
dateTo = snapshot.leaveRequestDateTo,
|
||||
type = snapshot.leaveRequestType,
|
||||
requestMode = snapshot.leaveRequestMode,
|
||||
requestedQuantity = requestedLeaveMinutes(snapshot),
|
||||
details = snapshot.leaveRequestDetails,
|
||||
idempotencyKey = snapshot.leaveRequestIdempotencyKey.ifBlank { UUID.randomUUID().toString() },
|
||||
note = snapshot.leaveRequestNote.takeIf { it.isNotBlank() },
|
||||
)
|
||||
}.onSuccess { created ->
|
||||
val requests = runCatching { repository.leaveRequests() }.getOrElse { listOf(created) }
|
||||
val (requests, summary) = coroutineScope {
|
||||
val refreshedRequests = async { runCatching { repository.leaveRequests() }.getOrElse { listOf(created) } }
|
||||
val refreshedSummary = async { runCatching { repository.leaveSummary() }.getOrNull() }
|
||||
refreshedRequests.await() to refreshedSummary.await()
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
screen = DriverScreen.LeaveRequestDetail,
|
||||
selectedLeaveRequest = created,
|
||||
leaveDocuments = emptyList(),
|
||||
leaveRequests = requests,
|
||||
feedback = "Wniosek został wysłany do decyzji.",
|
||||
leaveSummary = summary ?: it.leaveSummary,
|
||||
feedback = if (created.balanceConfigurationRequired) {
|
||||
"Wniosek zapisano. Kadry muszą jeszcze potwierdzić saldo, zanim będzie można go zaakceptować."
|
||||
} else {
|
||||
"Gotowe. Wniosek został wysłany i odpowiednia część salda jest już zarezerwowana."
|
||||
},
|
||||
error = null,
|
||||
)
|
||||
}
|
||||
@@ -1095,6 +1400,51 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
fun uploadSelectedLeaveDocument(documentType: String, uri: Uri) {
|
||||
val request = _state.value.selectedLeaveRequest ?: return
|
||||
if (!_state.value.isOnline || _state.value.leaveDocumentUploading) {
|
||||
if (!_state.value.isOnline) {
|
||||
_state.update { it.copy(error = "Dodanie dokumentu wymaga połączenia z internetem.") }
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(leaveDocumentUploading = true, error = null, feedback = null) }
|
||||
runCatching { repository.uploadLeaveDocument(request.id, documentType, uri) }
|
||||
.onSuccess { document ->
|
||||
_state.update {
|
||||
val updatedRequest = it.selectedLeaveRequest?.copy(
|
||||
missingDocumentTypes = it.selectedLeaveRequest.missingDocumentTypes - documentType,
|
||||
)
|
||||
it.copy(
|
||||
selectedLeaveRequest = updatedRequest,
|
||||
leaveRequests = it.leaveRequests.map { leaveRequest ->
|
||||
if (leaveRequest.id == updatedRequest?.id) updatedRequest else leaveRequest
|
||||
},
|
||||
leaveDocuments = (it.leaveDocuments.filterNot { existing ->
|
||||
existing.documentType == document.documentType
|
||||
} + document).sortedBy { item -> item.documentType },
|
||||
feedback = "Dokument został bezpiecznie dołączony do wniosku.",
|
||||
error = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
.onFailure { throwable -> _state.update { it.withApiError(throwable) } }
|
||||
_state.update { it.copy(leaveDocumentUploading = false) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun selectedLeaveRequestType() =
|
||||
_state.value.leaveSummary?.availableTypes?.firstOrNull { it.value == _state.value.leaveRequestType }
|
||||
|
||||
private fun requestedLeaveMinutes(state: DriverUiState): Int? {
|
||||
if (state.leaveRequestMode != "hours") return null
|
||||
val hours = state.leaveRequestHoursText.replace(',', '.').toDoubleOrNull() ?: return null
|
||||
val minutes = (hours * 60).toInt()
|
||||
return minutes.takeIf { it > 0 }
|
||||
}
|
||||
|
||||
fun cancelSelectedLeaveRequest() {
|
||||
val request = _state.value.selectedLeaveRequest ?: return
|
||||
if (!_state.value.isOnline) {
|
||||
@@ -1109,10 +1459,12 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
try {
|
||||
runCatching { repository.cancelLeaveRequest(request.id, request.version) }
|
||||
.onSuccess { updated ->
|
||||
val refreshedSummary = runCatching { repository.leaveSummary() }.getOrNull()
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedLeaveRequest = updated,
|
||||
leaveRequests = it.leaveRequests.map { existing -> if (existing.id == updated.id) updated else existing },
|
||||
leaveSummary = refreshedSummary ?: it.leaveSummary,
|
||||
feedback = if (updated.status == "cancel_requested") "Anulowanie wysłane do decyzji." else "Wniosek został anulowany.",
|
||||
error = null,
|
||||
)
|
||||
@@ -1141,19 +1493,60 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
fun uploadPhoto(uri: Uri, source: String, metadata: PhotoUploadMetadata = PhotoUploadMetadata(), stage: String = "other") {
|
||||
fun uploadPhoto(
|
||||
uri: Uri,
|
||||
source: String,
|
||||
metadata: PhotoUploadMetadata = PhotoUploadMetadata(),
|
||||
stage: String = "other",
|
||||
workflowStepId: String? = null,
|
||||
workflowDocumentId: String? = null,
|
||||
): Job? {
|
||||
val snapshot = _state.value
|
||||
val route = snapshot.selectedRoute ?: return
|
||||
val route = snapshot.selectedRoute ?: return null
|
||||
if (!routeIsActiveToday(route, snapshot.selectedDate)) {
|
||||
_state.update { it.copy(error = "Zdjęcia możesz dodać tylko w zaplanowanym zakresie kursu.") }
|
||||
return
|
||||
return null
|
||||
}
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(error = null) }
|
||||
runCatching { photoUploadOutbox.enqueue(route.id, uri, source, metadata, stage) }
|
||||
.onFailure { throwable ->
|
||||
_state.update { it.withApiError(throwable) }
|
||||
val preparation = PreparingPhotoUpload(
|
||||
id = UUID.randomUUID().toString(),
|
||||
routeId = route.id,
|
||||
uri = uri,
|
||||
stage = stage,
|
||||
workflowStepId = workflowStepId,
|
||||
workflowDocumentId = workflowDocumentId,
|
||||
)
|
||||
_state.update {
|
||||
it.copy(
|
||||
preparingPhotoUploads = it.preparingPhotoUploads + preparation,
|
||||
error = null,
|
||||
)
|
||||
}
|
||||
return viewModelScope.launch {
|
||||
try {
|
||||
runCatching {
|
||||
photoUploadOutbox.enqueue(
|
||||
routeId = route.id,
|
||||
uri = uri,
|
||||
source = source,
|
||||
metadata = metadata,
|
||||
stage = stage,
|
||||
workflowVersion = snapshot.routeWorkflow?.version,
|
||||
workflowStepId = workflowStepId,
|
||||
workflowDocumentId = workflowDocumentId,
|
||||
)
|
||||
}
|
||||
.onFailure { throwable ->
|
||||
_state.update { it.withApiError(throwable) }
|
||||
}
|
||||
} finally {
|
||||
_state.update {
|
||||
it.copy(
|
||||
preparingPhotoUploads = it.preparingPhotoUploads.filterNot { item ->
|
||||
item.id == preparation.id
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1168,7 +1561,9 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
_state.update { it.copy(error = "Załadunek nie jest dostępny poza zaplanowanym zakresem kursu.") }
|
||||
return
|
||||
}
|
||||
val targetScreen = if (
|
||||
val targetScreen = if (snapshot.routeWorkflow != null) {
|
||||
DriverScreen.StartRoute
|
||||
} else if (
|
||||
!routeStageRequirementIsVisible(snapshot.loadingPhotoRequirement) &&
|
||||
routeStageRequirementIsVisible(snapshot.loadingWeightRequirement)
|
||||
) DriverScreen.LoadingWeight else DriverScreen.StartRoute
|
||||
@@ -1177,6 +1572,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
screen = targetScreen,
|
||||
routeStageWeightText = "",
|
||||
routeStageNotesText = route.loadingNotes.orEmpty(),
|
||||
routeStageCompletedStepIds = emptySet(),
|
||||
feedback = null,
|
||||
error = null,
|
||||
)
|
||||
@@ -1222,6 +1618,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
screen = DriverScreen.FinishRoute,
|
||||
routeStageWeightText = route.unloadingWeight?.toString().orEmpty(),
|
||||
routeStageNotesText = route.unloadingNotes.orEmpty(),
|
||||
routeStageCompletedStepIds = emptySet(),
|
||||
feedback = null,
|
||||
error = null,
|
||||
)
|
||||
@@ -1237,6 +1634,18 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
_state.update { it.copy(routeStageNotesText = normalizeRouteStageNotes(value)) }
|
||||
}
|
||||
|
||||
fun toggleRouteStageStep(stepId: String, completed: Boolean) {
|
||||
_state.update {
|
||||
it.copy(
|
||||
routeStageCompletedStepIds = if (completed) {
|
||||
it.routeStageCompletedStepIds + stepId
|
||||
} else {
|
||||
it.routeStageCompletedStepIds - stepId
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun correctFailedRouteAction() {
|
||||
val snapshot = _state.value
|
||||
val action = (snapshot.visibleRouteActions + snapshot.routeActions)
|
||||
@@ -1335,7 +1744,16 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
val stageUploads = routeStageUsableUploads(
|
||||
snapshot.photoUploads.filter { normalizedRoutePhotoStage(it.stage) == stage },
|
||||
)
|
||||
val submitBlocker = if (stage == "loading") {
|
||||
val submitBlocker = if (snapshot.routeWorkflow != null) {
|
||||
routeWorkflowSubmitBlocker(
|
||||
workflow = snapshot.routeWorkflow,
|
||||
stage = stage,
|
||||
completedStepIds = snapshot.routeStageCompletedStepIds,
|
||||
weightText = snapshot.routeStageWeightText,
|
||||
serverPhotos = stagePhotos,
|
||||
localUploads = stageUploads,
|
||||
)
|
||||
} else if (stage == "loading") {
|
||||
loadingWeightSubmitBlocker(
|
||||
weightText = snapshot.routeStageWeightText,
|
||||
serverPhotoCount = stagePhotos.size,
|
||||
@@ -1358,7 +1776,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
return
|
||||
}
|
||||
|
||||
val photoClientRequestIds = if (routeStageRequirementIsVisible(photoRequirement)) {
|
||||
val photoClientRequestIds = if (snapshot.routeWorkflow != null || routeStageRequirementIsVisible(photoRequirement)) {
|
||||
(stagePhotos.mapNotNull { it.clientRequestId } + stageUploads.map { it.clientRequestId })
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotBlank() }
|
||||
@@ -1377,7 +1795,14 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
runCatching {
|
||||
val updatedRoute = when (stage) {
|
||||
"loading" -> {
|
||||
routeActionOutbox.enqueueStart(route.id, weight, photoClientRequestIds, notes)
|
||||
routeActionOutbox.enqueueStart(
|
||||
route.id,
|
||||
weight,
|
||||
photoClientRequestIds,
|
||||
notes,
|
||||
snapshot.routeWorkflow?.version,
|
||||
snapshot.routeStageCompletedStepIds.toList(),
|
||||
)
|
||||
route.copy(
|
||||
status = "W TRAKCIE",
|
||||
driverStatus = "W TRAKCIE",
|
||||
@@ -1388,7 +1813,14 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
)
|
||||
}
|
||||
"unloading" -> {
|
||||
routeActionOutbox.enqueueFinish(route.id, weight, photoClientRequestIds, notes)
|
||||
routeActionOutbox.enqueueFinish(
|
||||
route.id,
|
||||
weight,
|
||||
photoClientRequestIds,
|
||||
notes,
|
||||
snapshot.routeWorkflow?.version,
|
||||
snapshot.routeStageCompletedStepIds.toList(),
|
||||
)
|
||||
route.copy(
|
||||
status = "ZAKOŃCZONA",
|
||||
driverStatus = "ZAKOŃCZONA",
|
||||
@@ -1409,6 +1841,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
routes = it.routes.map { item -> if (item.id == route.id) updatedRoute else item },
|
||||
routeStageWeightText = "",
|
||||
routeStageNotesText = "",
|
||||
routeStageCompletedStepIds = emptySet(),
|
||||
feedback = if (stage == "loading") {
|
||||
if (snapshot.isOnline) "Potwierdzam załadunek z serwerem." else "Załadunek zapisano w telefonie. Wyślemy go po odzyskaniu internetu."
|
||||
} else {
|
||||
@@ -1610,12 +2043,22 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
)
|
||||
DriverScreen.LeaveRequests -> it.copy(screen = DriverScreen.Routes)
|
||||
DriverScreen.LeaveRequestDetail -> it.copy(screen = DriverScreen.LeaveRequests, selectedLeaveRequest = null, feedback = null)
|
||||
DriverScreen.LeaveCalendar -> it.copy(screen = DriverScreen.LeaveRequests, feedback = null)
|
||||
DriverScreen.LeaveCalendar -> it.copy(
|
||||
screen = if (it.leaveRequestIdempotencyKey.isNotBlank()) DriverScreen.AddLeaveRequest else DriverScreen.LeaveRequests,
|
||||
feedback = null,
|
||||
)
|
||||
DriverScreen.AddLeaveRequest -> it.copy(screen = DriverScreen.LeaveRequests, feedback = null)
|
||||
DriverScreen.Detail -> {
|
||||
photoUploadsJob?.cancel()
|
||||
routeActionsJob?.cancel()
|
||||
it.copy(screen = DriverScreen.Routes, selectedRoute = null, routeActions = emptyList(), photoUploads = emptyList(), feedback = null)
|
||||
it.copy(
|
||||
screen = DriverScreen.Routes,
|
||||
selectedRoute = null,
|
||||
routeActions = emptyList(),
|
||||
photoUploads = emptyList(),
|
||||
preparingPhotoUploads = emptyList(),
|
||||
feedback = null,
|
||||
)
|
||||
}
|
||||
DriverScreen.Profile -> it.copy(screen = DriverScreen.Routes)
|
||||
DriverScreen.Diagnostics -> it.copy(screen = DriverScreen.Profile)
|
||||
@@ -1773,7 +2216,12 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
private suspend fun checkRemoteSyncState() {
|
||||
if (!_state.value.isOnline) return
|
||||
val initialSnapshot = _state.value
|
||||
if (
|
||||
!initialSnapshot.isOnline ||
|
||||
initialSnapshot.screen == DriverScreen.Initializing ||
|
||||
initialSnapshot.driver == null
|
||||
) return
|
||||
syncCheckMutex.withLock {
|
||||
syncHintMutex.withLock { highestHintVersions.clear() }
|
||||
val snapshot = _state.value
|
||||
@@ -1820,6 +2268,8 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
private suspend fun handleSyncHint(hint: DriverSyncHint) {
|
||||
val initialSnapshot = _state.value
|
||||
if (initialSnapshot.screen == DriverScreen.Initializing || initialSnapshot.driver == null) return
|
||||
syncHintMutex.withLock {
|
||||
val hintKey = listOf(hint.scope, hint.date ?: "-", hint.routeId ?: "-").joinToString(":")
|
||||
val previousVersion = highestHintVersions[hintKey]
|
||||
@@ -1856,7 +2306,13 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
if (pending == null || hint.version > pending.version) pendingLeaveHint = hint
|
||||
return
|
||||
}
|
||||
if (snapshot.screen == DriverScreen.LeaveRequests || snapshot.screen == DriverScreen.LeaveRequestDetail) {
|
||||
if (snapshot.screen in setOf(
|
||||
DriverScreen.Profile,
|
||||
DriverScreen.LeaveRequests,
|
||||
DriverScreen.LeaveRequestDetail,
|
||||
DriverScreen.AddLeaveRequest,
|
||||
)
|
||||
) {
|
||||
if (loadLeaveRequests(showLoading = false, navigateToList = false)) {
|
||||
syncRepository.saveSyncScope(hint.asScope())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,287 @@
|
||||
package pl.firmatpp.kierowca.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.camera.core.ImageCapture
|
||||
import androidx.camera.core.ImageCaptureException
|
||||
import androidx.camera.view.CameraController
|
||||
import androidx.camera.view.LifecycleCameraController
|
||||
import androidx.camera.view.PreviewView
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.statusBarsPadding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.outlined.ArrowBack
|
||||
import androidx.compose.material.icons.outlined.CameraAlt
|
||||
import androidx.compose.material.icons.outlined.CheckCircle
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.lifecycle.compose.LocalLifecycleOwner
|
||||
import java.io.File
|
||||
import kotlinx.coroutines.launch
|
||||
import pl.firmatpp.kierowca.ui.theme.TppTheme
|
||||
|
||||
@Composable
|
||||
internal fun MultiplePhotoCameraScreen(
|
||||
stage: String,
|
||||
onPhotoCaptured: suspend (Uri) -> Unit,
|
||||
onClose: () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val lifecycleOwner = LocalLifecycleOwner.current
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val currentOnPhotoCaptured by rememberUpdatedState(onPhotoCaptured)
|
||||
val cameraController = remember(context) {
|
||||
LifecycleCameraController(context).apply {
|
||||
setEnabledUseCases(CameraController.IMAGE_CAPTURE)
|
||||
imageCaptureMode = ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY
|
||||
}
|
||||
}
|
||||
var capturedCount by remember { mutableIntStateOf(0) }
|
||||
var pendingUploads by remember { mutableIntStateOf(0) }
|
||||
var isCapturing by remember { mutableStateOf(false) }
|
||||
var cameraUnavailable by remember { mutableStateOf(false) }
|
||||
var cameraError by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
DisposableEffect(cameraController, lifecycleOwner) {
|
||||
runCatching {
|
||||
cameraController.bindToLifecycle(lifecycleOwner)
|
||||
}.onFailure {
|
||||
cameraUnavailable = true
|
||||
cameraError = "Nie udało się uruchomić aparatu."
|
||||
}
|
||||
|
||||
onDispose {
|
||||
cameraController.unbind()
|
||||
}
|
||||
}
|
||||
|
||||
BackHandler {
|
||||
if (!isCapturing && pendingUploads == 0) onClose()
|
||||
}
|
||||
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.Black),
|
||||
) {
|
||||
AndroidView(
|
||||
factory = { previewContext ->
|
||||
PreviewView(previewContext).apply {
|
||||
controller = cameraController
|
||||
implementationMode = PreviewView.ImplementationMode.COMPATIBLE
|
||||
scaleType = PreviewView.ScaleType.FILL_CENTER
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.align(Alignment.TopCenter)
|
||||
.background(Color.Black.copy(alpha = 0.62f))
|
||||
.statusBarsPadding()
|
||||
.padding(horizontal = 8.dp, vertical = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onClose,
|
||||
enabled = !isCapturing && pendingUploads == 0,
|
||||
) {
|
||||
Icon(
|
||||
Icons.AutoMirrored.Outlined.ArrowBack,
|
||||
contentDescription = "Wróć",
|
||||
tint = Color.White,
|
||||
)
|
||||
}
|
||||
Column {
|
||||
Text(
|
||||
text = if (stage == "loading") "Zdjęcia załadunku" else "Zdjęcia rozładunku",
|
||||
color = Color.White,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
)
|
||||
Text(
|
||||
text = if (pendingUploads > 0) {
|
||||
"Wykonano: $capturedCount · zapisuję: $pendingUploads"
|
||||
} else {
|
||||
"Wykonano: $capturedCount"
|
||||
},
|
||||
color = Color.White.copy(alpha = 0.78f),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.align(Alignment.BottomCenter)
|
||||
.background(Color.Black.copy(alpha = 0.68f))
|
||||
.navigationBarsPadding()
|
||||
.padding(horizontal = 20.dp, vertical = 16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
cameraError?.let { message ->
|
||||
Text(
|
||||
text = message,
|
||||
color = Color.White,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(Color(0xFF8C1D18), RoundedCornerShape(6.dp))
|
||||
.padding(10.dp),
|
||||
)
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(72.dp),
|
||||
) {
|
||||
Button(
|
||||
onClick = {
|
||||
if (isCapturing || cameraUnavailable) return@Button
|
||||
|
||||
val photoFile = createMultipleCameraFile(context)
|
||||
val outputOptions = ImageCapture.OutputFileOptions.Builder(photoFile).build()
|
||||
isCapturing = true
|
||||
cameraController.takePicture(
|
||||
outputOptions,
|
||||
ContextCompat.getMainExecutor(context),
|
||||
object : ImageCapture.OnImageSavedCallback {
|
||||
override fun onImageSaved(outputFileResults: ImageCapture.OutputFileResults) {
|
||||
isCapturing = false
|
||||
cameraError = null
|
||||
capturedCount += 1
|
||||
pendingUploads += 1
|
||||
coroutineScope.launch {
|
||||
try {
|
||||
currentOnPhotoCaptured(cameraFileUri(context, photoFile))
|
||||
} finally {
|
||||
pendingUploads = (pendingUploads - 1).coerceAtLeast(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(exception: ImageCaptureException) {
|
||||
isCapturing = false
|
||||
photoFile.delete()
|
||||
cameraError = "Nie udało się zapisać zdjęcia. Spróbuj ponownie."
|
||||
}
|
||||
},
|
||||
)
|
||||
},
|
||||
enabled = !isCapturing && !cameraUnavailable,
|
||||
modifier = Modifier
|
||||
.align(Alignment.Center)
|
||||
.size(72.dp),
|
||||
shape = CircleShape,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.White,
|
||||
disabledContainerColor = Color.White.copy(alpha = 0.55f),
|
||||
),
|
||||
contentPadding = ButtonDefaults.ContentPadding,
|
||||
) {
|
||||
if (isCapturing) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(28.dp),
|
||||
color = TppTheme.colors.forest,
|
||||
strokeWidth = 3.dp,
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
Icons.Outlined.CameraAlt,
|
||||
contentDescription = "Zrób zdjęcie",
|
||||
tint = TppTheme.colors.forest,
|
||||
modifier = Modifier.size(32.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
Button(
|
||||
onClick = onClose,
|
||||
enabled = !isCapturing && pendingUploads == 0,
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterEnd)
|
||||
.width(104.dp)
|
||||
.height(52.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = TppTheme.colors.forest,
|
||||
),
|
||||
shape = RoundedCornerShape(6.dp),
|
||||
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 6.dp),
|
||||
) {
|
||||
if (pendingUploads > 0) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(16.dp),
|
||||
color = Color.White,
|
||||
strokeWidth = 2.dp,
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
Icons.Outlined.CheckCircle,
|
||||
contentDescription = null,
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size(18.dp),
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = if (pendingUploads > 0) "Zapisuję" else "Gotowe",
|
||||
color = Color.White,
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
maxLines = 1,
|
||||
softWrap = false,
|
||||
overflow = TextOverflow.Clip,
|
||||
modifier = Modifier.padding(start = 4.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun createMultipleCameraFile(context: Context): File {
|
||||
val directory = File(context.cacheDir, "camera").apply { mkdirs() }
|
||||
return File.createTempFile("ladunek-", ".jpg", directory)
|
||||
}
|
||||
|
||||
private fun cameraFileUri(context: Context, file: File): Uri =
|
||||
FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", file)
|
||||
@@ -0,0 +1,94 @@
|
||||
package pl.firmatpp.kierowca.data
|
||||
|
||||
import com.google.gson.Gson
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveRequestDto
|
||||
import pl.firmatpp.kierowca.data.model.LeaveSummaryResponse
|
||||
|
||||
class DriverLeaveApiContractTest {
|
||||
private val gson = Gson()
|
||||
|
||||
@Test
|
||||
fun parsesNewLeaveSummaryWithoutTechnicalFallbacks() {
|
||||
val response = gson.fromJson(
|
||||
"""
|
||||
{
|
||||
"data": {
|
||||
"dailyNormMinutes": 480,
|
||||
"balanceConfigured": true,
|
||||
"overdueQuantity": 480,
|
||||
"visibleUsagePoolCodes": ["ANNUAL", "CHILD_CARE_14"],
|
||||
"pools": [{
|
||||
"id": 7,
|
||||
"poolCode": "ANNUAL",
|
||||
"year": 2026,
|
||||
"unit": "minutes",
|
||||
"availableQuantity": 7680,
|
||||
"reservedQuantity": 960,
|
||||
"usedQuantity": 960,
|
||||
"grantedQuantity": 9600,
|
||||
"status": "active"
|
||||
}],
|
||||
"availableTypes": [{
|
||||
"value": "URLOP",
|
||||
"code": "ANNUAL",
|
||||
"label": "Urlop wypoczynkowy",
|
||||
"requestModes": ["days", "hours"],
|
||||
"requiredFields": [],
|
||||
"requiredDocuments": [],
|
||||
"fieldOptions": {},
|
||||
"description": "Urlop rozliczany według grafiku.",
|
||||
"financialTreatmentLabel": "Płatny według danych przekazanych przez kadry i płace.",
|
||||
"affectsAnnualLeaveBalance": true
|
||||
}]
|
||||
}
|
||||
}
|
||||
""".trimIndent(),
|
||||
LeaveSummaryResponse::class.java,
|
||||
)
|
||||
|
||||
assertEquals(480, response.data.dailyNormMinutes)
|
||||
assertEquals(listOf("ANNUAL", "CHILD_CARE_14"), response.data.visibleUsagePoolCodes)
|
||||
assertEquals(7680, response.data.pools.single().availableQuantity)
|
||||
assertEquals("URLOP", response.data.availableTypes.single().value)
|
||||
assertEquals("ANNUAL", response.data.availableTypes.single().code)
|
||||
assertTrue("hours" in response.data.availableTypes.single().requestModes)
|
||||
assertTrue(response.data.availableTypes.single().affectsAnnualLeaveBalance)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parsesSensitiveOwnRequestDetailsAsFormValues() {
|
||||
val request = gson.fromJson(
|
||||
"""
|
||||
{
|
||||
"id": "12",
|
||||
"dateFrom": "2026-08-03",
|
||||
"dateTo": "2026-08-03",
|
||||
"type": "WOLNE",
|
||||
"ruleCode": "CHILD_CARE_14",
|
||||
"requestMode": "days",
|
||||
"requestedQuantity": 1,
|
||||
"quantityUnit": "days",
|
||||
"details": {
|
||||
"childrenBornCount": 1,
|
||||
"childBirthDate": "2020-05-12"
|
||||
},
|
||||
"financialTreatmentLabel": "Płatne według zasad ustawowych.",
|
||||
"affectsAnnualLeaveBalance": false,
|
||||
"status": "pending",
|
||||
"missingDocumentTypes": ["parent_declaration"]
|
||||
}
|
||||
""".trimIndent(),
|
||||
DriverLeaveRequestDto::class.java,
|
||||
)
|
||||
|
||||
assertEquals("1", request.details["childrenBornCount"])
|
||||
assertEquals("2020-05-12", request.details["childBirthDate"])
|
||||
assertEquals("days", request.quantityUnit)
|
||||
assertEquals(false, request.affectsAnnualLeaveBalance)
|
||||
assertEquals("Płatne według zasad ustawowych.", request.financialTreatmentLabel)
|
||||
assertEquals(listOf("parent_declaration"), request.missingDocumentTypes)
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,10 @@ import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveCalendarDriverDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveCalendarEntryDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeavePoolDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveRequestDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveRuleSnapshotDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverLeaveSummaryDto
|
||||
|
||||
class DriverLeaveRequestUiRulesTest {
|
||||
@Test
|
||||
@@ -18,15 +22,35 @@ class DriverLeaveRequestUiRulesTest {
|
||||
|
||||
@Test
|
||||
fun exposesPolishStatusLabels() {
|
||||
assertEquals("Oczekuje", DriverLeaveRequestUiRules.statusLabel("pending"))
|
||||
assertEquals("Zatwierdzony", DriverLeaveRequestUiRules.statusLabel("approved"))
|
||||
assertEquals("Czeka na decyzję", DriverLeaveRequestUiRules.statusLabel("pending"))
|
||||
assertEquals("Zaakceptowany", DriverLeaveRequestUiRules.statusLabel("approved"))
|
||||
assertEquals("Odrzucony", DriverLeaveRequestUiRules.statusLabel("rejected"))
|
||||
assertEquals("Anulowanie do decyzji", DriverLeaveRequestUiRules.statusLabel("cancel_requested"))
|
||||
assertEquals("Czeka na anulowanie", DriverLeaveRequestUiRules.statusLabel("cancel_requested"))
|
||||
assertEquals("Anulowany", DriverLeaveRequestUiRules.statusLabel("cancelled"))
|
||||
assertEquals("Cofnięto decyzję", DriverLeaveRequestUiRules.statusLabel("revoked"))
|
||||
assertEquals("Akceptacja cofnięta", DriverLeaveRequestUiRules.statusLabel("revoked"))
|
||||
assertEquals("Nieznany status", DriverLeaveRequestUiRules.statusLabel("some_raw_status"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun explainsAnnualBalanceInDaysAndHours() {
|
||||
val summary = DriverLeaveSummaryDto(
|
||||
dailyNormMinutes = 480,
|
||||
balanceConfigured = true,
|
||||
pools = listOf(
|
||||
annualPool(year = 2025, available = 480, reserved = 0, used = 480, granted = 960),
|
||||
annualPool(year = 2026, available = 3_840, reserved = 960, used = 960, granted = 5_760),
|
||||
),
|
||||
)
|
||||
|
||||
val totals = DriverLeaveRequestUiRules.annualTotals(summary)
|
||||
|
||||
assertEquals(4_320, totals.availableMinutes)
|
||||
assertEquals(960, totals.reservedMinutes)
|
||||
assertEquals(1_440, totals.usedMinutes)
|
||||
assertEquals("9 dni · 72 godz.", DriverLeaveRequestUiRules.formatQuantity(totals.availableMinutes, "minutes", 480))
|
||||
assertEquals("2 dni + 2 godz. · 18 godz.", DriverLeaveRequestUiRules.formatQuantity(1_080, "minutes", 480))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun exposesPolishEventActionLabels() {
|
||||
assertEquals("Wniosek złożony", DriverLeaveRequestUiRules.eventActionLabel("submitted"))
|
||||
@@ -37,9 +61,78 @@ class DriverLeaveRequestUiRulesTest {
|
||||
assertEquals("Kierowca poprosił o anulowanie", DriverLeaveRequestUiRules.eventActionLabel("cancellation_requested"))
|
||||
assertEquals("Anulowanie zatwierdzone", DriverLeaveRequestUiRules.eventActionLabel("cancellation_approved"))
|
||||
assertEquals("Anulowanie odrzucone", DriverLeaveRequestUiRules.eventActionLabel("cancellation_rejected"))
|
||||
assertEquals("Przywrócono urlop wypoczynkowy", DriverLeaveRequestUiRules.eventActionLabel("annual_leave_interrupted"))
|
||||
assertEquals("Aktualizacja wniosku", DriverLeaveRequestUiRules.eventActionLabel("some_raw_action"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun formatsStatutoryDayLimitsAsDaysInsteadOfMinutes() {
|
||||
val dayBasedRequest = DriverLeaveRequestDto(
|
||||
id = "child-care",
|
||||
dateFrom = "2026-08-03",
|
||||
dateTo = "2026-08-03",
|
||||
type = "CHILD_CARE_14",
|
||||
requestMode = "days",
|
||||
requestedQuantity = 1,
|
||||
quantityUnit = "days",
|
||||
status = "pending",
|
||||
)
|
||||
val legacyDayBasedRequest = dayBasedRequest.copy(
|
||||
id = "force-majeure",
|
||||
type = "FORCE_MAJEURE",
|
||||
quantityUnit = null,
|
||||
rule = DriverLeaveRuleSnapshotDto(
|
||||
unit = "work_schedule",
|
||||
poolCode = "FORCE_MAJEURE",
|
||||
),
|
||||
)
|
||||
|
||||
assertEquals("days", DriverLeaveRequestUiRules.requestQuantityUnit(dayBasedRequest))
|
||||
assertEquals("1 dzień", DriverLeaveRequestUiRules.formatQuantity(1, "days"))
|
||||
assertEquals("days", DriverLeaveRequestUiRules.requestQuantityUnit(legacyDayBasedRequest))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun exposesOtherStatutoryBalancesSeparatelyFromAnnualLeave() {
|
||||
val summary = DriverLeaveSummaryDto(
|
||||
pools = listOf(
|
||||
annualPool(year = 2026, available = 4_800, reserved = 0, used = 0, granted = 4_800),
|
||||
DriverLeavePoolDto(
|
||||
id = 31,
|
||||
poolCode = "CHILD_CARE_14",
|
||||
year = 2026,
|
||||
unit = "days",
|
||||
availableQuantity = 1,
|
||||
usedQuantity = 1,
|
||||
grantedQuantity = 2,
|
||||
status = "active",
|
||||
),
|
||||
DriverLeavePoolDto(
|
||||
id = 32,
|
||||
poolCode = "CARE_LEAVE",
|
||||
year = 2026,
|
||||
unit = "days",
|
||||
availableQuantity = 5,
|
||||
grantedQuantity = 5,
|
||||
status = "active",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val pools = DriverLeaveRequestUiRules.otherEntitlementPools(summary)
|
||||
|
||||
assertEquals(listOf("CHILD_CARE_14", "CARE_LEAVE"), pools.map { it.poolCode })
|
||||
assertEquals("Urlop opiekuńczy", DriverLeaveRequestUiRules.poolLabel("CARE_LEAVE"))
|
||||
assertEquals("Rodzina i opieka", DriverLeaveRequestUiRules.categoryLabel("family"))
|
||||
assertTrue(DriverLeaveRequestUiRules.isUsageVisible(summary, "ANNUAL"))
|
||||
assertFalse(
|
||||
DriverLeaveRequestUiRules.isUsageVisible(
|
||||
summary.copy(visibleUsagePoolCodes = emptyList()),
|
||||
"ANNUAL",
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun driverCanCancelPendingAndFutureApprovedRequests() {
|
||||
val tomorrow = LocalDate.now().plusDays(1).toString()
|
||||
@@ -105,4 +198,23 @@ class DriverLeaveRequestUiRulesTest {
|
||||
phoneNumber = "+48 600 700 800",
|
||||
),
|
||||
)
|
||||
|
||||
private fun annualPool(
|
||||
year: Int,
|
||||
available: Int,
|
||||
reserved: Int,
|
||||
used: Int,
|
||||
granted: Int,
|
||||
): DriverLeavePoolDto =
|
||||
DriverLeavePoolDto(
|
||||
id = year,
|
||||
poolCode = "ANNUAL",
|
||||
year = year,
|
||||
unit = "minutes",
|
||||
availableQuantity = available,
|
||||
reservedQuantity = reserved,
|
||||
usedQuantity = used,
|
||||
grantedQuantity = granted,
|
||||
status = "active",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,8 +6,14 @@ import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteStageWorkflowDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteWorkflowDocumentDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteWorkflowDto
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteWorkflowStepDto
|
||||
import pl.firmatpp.kierowca.data.model.DispatchSheetReminderDto
|
||||
import pl.firmatpp.kierowca.data.model.RoutePhotoDto
|
||||
import pl.firmatpp.kierowca.data.model.TachographReminderDto
|
||||
import pl.firmatpp.kierowca.data.model.TachographReminderTaskDto
|
||||
import pl.firmatpp.kierowca.data.upload.PhotoUploadEntity
|
||||
import pl.firmatpp.kierowca.data.upload.RouteActionEntity
|
||||
import pl.firmatpp.kierowca.data.upload.RouteActionStatus
|
||||
@@ -16,6 +22,52 @@ import pl.firmatpp.kierowca.data.upload.RouteActionType
|
||||
class DriverUiRulesTest {
|
||||
private val today = LocalDate.parse("2026-06-30")
|
||||
|
||||
@Test
|
||||
fun customWorkflowBlocksUntilConfirmationAndRequiredDocumentArePresent() {
|
||||
val workflow = DriverRouteWorkflowDto(
|
||||
version = "workflow-v1",
|
||||
customized = true,
|
||||
loading = DriverRouteStageWorkflowDto(
|
||||
steps = listOf(
|
||||
DriverRouteWorkflowStepDto(
|
||||
id = "secure-load",
|
||||
type = RouteWorkflowStepType.Confirmation,
|
||||
title = "Sprawdź zabezpieczenie ładunku",
|
||||
requirement = RouteStageRequirement.Required,
|
||||
documents = listOf(
|
||||
DriverRouteWorkflowDocumentDto(
|
||||
id = "cmr",
|
||||
label = "List przewozowy CMR",
|
||||
requirement = RouteStageRequirement.Required,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
unloading = DriverRouteStageWorkflowDto(),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
"Potwierdź krok: Sprawdź zabezpieczenie ładunku.",
|
||||
routeWorkflowSubmitBlocker(workflow, "loading", emptySet(), "", emptyList(), emptyList()),
|
||||
)
|
||||
assertEquals(
|
||||
"Dodaj dokument „List przewozowy CMR” w kroku „Sprawdź zabezpieczenie ładunku”.",
|
||||
routeWorkflowSubmitBlocker(workflow, "loading", setOf("secure-load"), "", emptyList(), emptyList()),
|
||||
)
|
||||
assertEquals(
|
||||
null,
|
||||
routeWorkflowSubmitBlocker(
|
||||
workflow,
|
||||
"loading",
|
||||
setOf("secure-load"),
|
||||
"",
|
||||
listOf(photo("cmr-photo", "loading").copy(workflowStepId = "secure-load", workflowDocumentId = "cmr")),
|
||||
emptyList(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun disabledRouteLocationNeverStartsTracking() {
|
||||
assertFalse(shouldTrackRouteLocation(RouteLocationMode.Disabled, optionalLocationEnabled = true, hasLocationPermission = true))
|
||||
@@ -410,6 +462,57 @@ class DriverUiRulesTest {
|
||||
assertFalse(shouldShowDispatchSheetReminderCard(null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun showsTachographCardOnlyForCompleteReminderEnabledByBackend() {
|
||||
assertTrue(
|
||||
shouldShowTachographReminderCard(
|
||||
TachographReminderDto(
|
||||
enabled = true,
|
||||
visible = true,
|
||||
title = "Odczyt tachografu",
|
||||
message = "Pamiętaj o odczycie.",
|
||||
tasks = listOf(tachographTask()),
|
||||
),
|
||||
),
|
||||
)
|
||||
assertFalse(
|
||||
shouldShowTachographReminderCard(
|
||||
TachographReminderDto(
|
||||
enabled = false,
|
||||
visible = true,
|
||||
title = "Odczyt tachografu",
|
||||
message = "Pamiętaj o odczycie.",
|
||||
tasks = listOf(tachographTask()),
|
||||
),
|
||||
),
|
||||
)
|
||||
assertFalse(
|
||||
shouldShowTachographReminderCard(
|
||||
TachographReminderDto(
|
||||
enabled = true,
|
||||
visible = false,
|
||||
title = "Odczyt tachografu",
|
||||
message = "Pamiętaj o odczycie.",
|
||||
tasks = listOf(tachographTask()),
|
||||
),
|
||||
),
|
||||
)
|
||||
assertFalse(shouldShowTachographReminderCard(null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun preselectsOnlySingleTachographConfirmationTask() {
|
||||
val driverCard = tachographTask()
|
||||
val vehicle = TachographReminderTaskDto(
|
||||
id = "vehicle:12:2026-07-31",
|
||||
type = "vehicle_tachograph",
|
||||
label = "Tachograf pojazdu",
|
||||
)
|
||||
|
||||
assertEquals(setOf(driverCard.id), defaultTachographConfirmationSelection(listOf(driverCard)))
|
||||
assertEquals(emptySet<String>(), defaultTachographConfirmationSelection(listOf(driverCard, vehicle)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun explainsOfflineStateWithoutCachedSync() {
|
||||
assertEquals(
|
||||
@@ -817,4 +920,11 @@ class DriverUiRulesTest {
|
||||
photo = null,
|
||||
canUpload = dueToday,
|
||||
)
|
||||
|
||||
private fun tachographTask(): TachographReminderTaskDto =
|
||||
TachographReminderTaskDto(
|
||||
id = "driver-card:1:2026-07-31",
|
||||
type = "driver_card",
|
||||
label = "Karta kierowcy",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -43,6 +43,55 @@ class DriverUiStateTest {
|
||||
assertEquals(ServerConnectionState.Degraded, failed.serverConnectionState)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun silentRefreshCannotReplaceActiveStartupLoad() {
|
||||
assertFalse(
|
||||
shouldStartRoutesLoad(
|
||||
screen = DriverScreen.Initializing,
|
||||
navigateToRoutes = false,
|
||||
startupOfflineOnly = false,
|
||||
),
|
||||
)
|
||||
assertFalse(
|
||||
shouldStartRoutesLoad(
|
||||
screen = DriverScreen.Routes,
|
||||
navigateToRoutes = false,
|
||||
startupOfflineOnly = false,
|
||||
startupLoadInProgress = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun startupAndManualOfflineLoadsRemainAvailable() {
|
||||
assertTrue(
|
||||
shouldStartRoutesLoad(
|
||||
screen = DriverScreen.Initializing,
|
||||
navigateToRoutes = true,
|
||||
startupOfflineOnly = false,
|
||||
),
|
||||
)
|
||||
assertTrue(
|
||||
shouldStartRoutesLoad(
|
||||
screen = DriverScreen.Initializing,
|
||||
navigateToRoutes = false,
|
||||
startupOfflineOnly = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun successfulBootstrapAlwaysLeavesInitializingScreen() {
|
||||
assertEquals(
|
||||
DriverScreen.Routes,
|
||||
screenAfterBootstrap(
|
||||
currentScreen = DriverScreen.Initializing,
|
||||
navigateToRoutes = false,
|
||||
leaveRequestsEnabled = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun refreshingLeaveRequestsKeepsDetailScreenOpenAndUpdatesSelectedRequest() {
|
||||
val state = DriverUiState(
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package pl.firmatpp.kierowca.ui
|
||||
|
||||
import java.time.LocalDate
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class RouteDatePickerBoundsTest {
|
||||
@Test
|
||||
fun usesTheSameMinAndMaxDatesAsTheRouteSelector() {
|
||||
val bounds = routeDatePickerBounds(
|
||||
selectedDate = "2026-07-24",
|
||||
minDate = "2026-07-17",
|
||||
maxDate = "2026-07-26",
|
||||
)
|
||||
|
||||
assertEquals(LocalDate.parse("2026-07-24"), bounds.selectedDate)
|
||||
assertEquals(LocalDate.parse("2026-07-17"), bounds.minDate)
|
||||
assertEquals(LocalDate.parse("2026-07-26"), bounds.maxDate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun clampsSelectedDateToAllowedRange() {
|
||||
val bounds = routeDatePickerBounds(
|
||||
selectedDate = "2026-07-30",
|
||||
minDate = "2026-07-17",
|
||||
maxDate = "2026-07-26",
|
||||
)
|
||||
|
||||
assertEquals(LocalDate.parse("2026-07-26"), bounds.selectedDate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun normalizesAccidentallyReversedServerBounds() {
|
||||
val bounds = routeDatePickerBounds(
|
||||
selectedDate = "2026-07-24",
|
||||
minDate = "2026-07-26",
|
||||
maxDate = "2026-07-17",
|
||||
)
|
||||
|
||||
assertEquals(LocalDate.parse("2026-07-17"), bounds.minDate)
|
||||
assertEquals(LocalDate.parse("2026-07-26"), bounds.maxDate)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user