Redone Submit/approve Process

This commit is contained in:
2025-11-10 11:07:11 +01:00
parent 06b97cbdae
commit 87aaa28d92
2 changed files with 75 additions and 13 deletions

View File

@@ -38,6 +38,20 @@ export function useStaffTime() {
}) })
} }
async function submit(id: string) {
return await $api<StaffTimeEntry>(`/api/staff/time/${id}`, {
method: 'PUT',
body: { state: 'submitted' },
})
}
async function approve(id: string) {
return await $api<StaffTimeEntry>(`/api/staff/time/${id}`, {
method: 'PUT',
body: { state: 'approved' },
})
}
async function get(id: string) { async function get(id: string) {
return await $api<StaffTimeEntry>(`/api/staff/time/${id}`, { method: 'GET' }) return await $api<StaffTimeEntry>(`/api/staff/time/${id}`, { method: 'GET' })
} }
@@ -50,5 +64,5 @@ export function useStaffTime() {
return await $api(`/api/staff/time/${id}`, { method: 'PUT', body: data }) return await $api(`/api/staff/time/${id}`, { method: 'PUT', body: data })
} }
return { list, start, stop, get, create, update } return { list, start, stop,submit,approve, get, create, update }
} }

View File

@@ -2,7 +2,7 @@
import { useStaffTime } from '~/composables/useStaffTime' import { useStaffTime } from '~/composables/useStaffTime'
import { useAuthStore } from '~/stores/auth' import { useAuthStore } from '~/stores/auth'
const { list, start, stop } = useStaffTime() const { list, start, stop, submit,approve } = useStaffTime()
const auth = useAuthStore() const auth = useAuthStore()
const router = useRouter() const router = useRouter()
@@ -51,6 +51,16 @@ function handleEdit(entry: any) {
showModal.value = true showModal.value = true
} }
async function handleSubmit(entry: any) {
await submit(entry.id)
await load()
}
async function handleApprove(entry: any) {
await approve(entry.id)
await load()
}
onMounted(async () => { onMounted(async () => {
await loadUsers() await loadUsers()
await load() await load()
@@ -115,14 +125,19 @@ onMounted(async () => {
/> />
<!-- 🔹 Button zur Auswertung --> <!-- 🔹 Button zur Auswertung -->
<UButton <UTooltip
v-if="selectedUser" :text="selectedUser ? 'Anwesenheiten des Mitarbeiters auswerten' : 'Mitarbeiter für die Auswertung auswählen'"
color="gray" >
icon="i-heroicons-chart-bar" <UButton
label="Auswertung" :disabled="!selectedUser"
variant="soft" color="gray"
@click="router.push(`/staff/time/${selectedUser}/evaluate`)" icon="i-heroicons-chart-bar"
/> label="Auswertung"
variant="soft"
@click="router.push(`/staff/time/${selectedUser}/evaluate`)"
/>
</UTooltip>
</div> </div>
</template> </template>
</UDashboardToolbar> </UDashboardToolbar>
@@ -131,15 +146,15 @@ onMounted(async () => {
<UDashboardPanelContent> <UDashboardPanelContent>
<UTable <UTable
:rows="entries" :rows="entries"
@select="(row) => handleEdit(row)"
:columns="[ :columns="[
{ key: 'actions', label: '' },
{ key: 'state', label: 'Status' }, { key: 'state', label: 'Status' },
{ key: 'started_at', label: 'Start' }, { key: 'started_at', label: 'Start' },
{ key: 'stopped_at', label: 'Ende' }, { key: 'stopped_at', label: 'Ende' },
{ key: 'duration_minutes', label: 'Dauer' }, { key: 'duration_minutes', label: 'Dauer' },
{ key: 'description', label: 'Beschreibung' }, { key: 'description', label: 'Beschreibung' },
...(canViewAll ? [{ key: 'user_name', label: 'Benutzer' }] : []), ...(canViewAll ? [{ key: 'user_name', label: 'Benutzer' }] : []),
{ key: 'actions', label: '' },
]" ]"
> >
<template #state-data="{row}"> <template #state-data="{row}">
@@ -163,7 +178,40 @@ onMounted(async () => {
{{ row.user_id ? users.find(i => i.user_id === row.user_id).full_name : '-' }} {{ row.user_id ? users.find(i => i.user_id === row.user_id).full_name : '-' }}
</template> </template>
<template #actions-data="{ row }"> <template #actions-data="{ row }">
<UButton variant="ghost" icon="i-heroicons-pencil-square" @click="handleEdit(row)" /> <UTooltip
text="Zeit genehmigen"
v-if="row.state === 'submitted'"
>
<UButton
variant="ghost"
icon="i-heroicons-check-circle"
@click="handleApprove(row)"
/>
</UTooltip>
<UTooltip
text="Zeit einreichen"
v-if="row.state === 'draft'"
>
<UButton
variant="ghost"
icon="i-heroicons-arrow-right-end-on-rectangle"
@click="handleSubmit(row)"
/>
</UTooltip>
<UTooltip
text="Zeit bearbeiten"
v-if="row.state === 'draft'"
>
<UButton
variant="ghost"
icon="i-heroicons-pencil-square"
@click="handleEdit(row)"
/>
</UTooltip>
</template> </template>
</UTable> </UTable>
</UDashboardPanelContent> </UDashboardPanelContent>