Corrected Errors in Workintimes

Introduced Error Logging to Supabase
This commit is contained in:
2025-01-07 16:43:24 +01:00
parent ff1685a721
commit 26fef320ef
7 changed files with 162 additions and 102 deletions

View File

@@ -159,11 +159,11 @@ const links = computed(() => {
label: "Vorgänge", label: "Vorgänge",
to: "/inventory", to: "/inventory",
icon: "i-heroicons-square-3-stack-3d" icon: "i-heroicons-square-3-stack-3d"
},{ },/*{
label: "Bestände", label: "Bestände",
to: "/inventory/stocks", to: "/inventory/stocks",
icon: "i-heroicons-square-3-stack-3d" icon: "i-heroicons-square-3-stack-3d"
}, },*/
... role.checkRight("spaces") ? [{ ... role.checkRight("spaces") ? [{
label: "Lagerplätze", label: "Lagerplätze",
to: "/standardEntity/spaces", to: "/standardEntity/spaces",

View File

@@ -0,0 +1,101 @@
<script setup>
import dayjs from "dayjs";
const profileStore = useProfileStore();
const supabase = useSupabaseClient()
const toast = useToast()
const runningTimeInfo = ref({})
const setupPage = async () => {
runningTimeInfo.value = (await supabase.from("workingtimes").select().eq("profile", profileStore.activeProfile.id).is("endDate", null).single()).data || {}
console.log(runningTimeInfo.value)
}
setupPage()
/*if(dataStore.workingtimes.find(time => time.profile === profileStore.activeProfile.id && !time.endDate)) {
runningTimeInfo.value = dataStore.workingtimes.find(time => time.profile === profileStore.activeProfile.id && !time.end)
}*/
const startTime = async () => {
console.log("started")
runningTimeInfo.value = {
profile: profileStore.activeProfile.id,
startDate: dayjs(),
tenant: profileStore.currentTenant,
state: "Im Web gestartet",
source: "Dashboard"
}
const {data,error} = await supabase
.from("workingtimes")
.insert([runningTimeInfo.value])
.select()
if(error) {
console.log(error)
toast.add({title: "Fehler beim starten der Zeit",color:"rose"})
} else if(data) {
toast.add({title: "Zeit erfolgreich gestartet"})
runningTimeInfo.value = data[0]
console.log(runningTimeInfo.value)
}
}
const stopStartedTime = async () => {
runningTimeInfo.value.endDate = dayjs()
runningTimeInfo.value.state = "Im Web gestoppt"
const {error,status} = await supabase
.from("workingtimes")
.update(runningTimeInfo.value)
.eq('id',runningTimeInfo.value.id)
if(error) {
console.log(error)
let errorId = await useError().logError(`${status} - ${JSON.stringify(error)}`)
toast.add({title: errorId ? `Fehler beim stoppen der Zeit (Fehler ID: ${errorId})` : `Fehler beim stoppen der Zeit`,color:"rose"})
} else {
toast.add({title: "Zeit erfolgreich gestoppt"})
runningTimeInfo.value = {}
}
}
</script>
<template>
<div v-if="runningTimeInfo.startDate">
<p>Start: {{dayjs(runningTimeInfo.startDate).format("HH:mm")}}</p>
<p>Dauer: {{dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') > 59 ? `${Math.floor(dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') / 60)}:${dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') % 60} h` : dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') + ' min' }}</p>
<UFormGroup
class="mt-2"
label="Notizen:"
>
<UTextarea
v-model="runningTimeInfo.notes"
/>
</UFormGroup>
<UButton
class="mt-3"
@click="stopStartedTime"
:disabled="!runningTimeInfo.id"
>
Stop
</UButton>
</div>
<div v-else>
<p>Keine Anwesenheit gestartet</p>
<UButton
class="mt-3"
@click="startTime"
>Starten</UButton>
</div>
</template>
<style scoped>
</style>

25
composables/useError.js Normal file
View File

@@ -0,0 +1,25 @@
export const useError = (resourceType) => {
const supabase = useSupabaseClient()
const toast = useToast()
const profileStore = useProfileStore()
const logError = async (error) => {
let errorData = {
message: error,
tenant: profileStore.currentTenant,
profile: profileStore.activeProfile.id
}
const {data:supabaseData,error:supabaseError} = await supabase.from("errors").insert(errorData).select().single()
if(supabaseError) {
console.error(supabaseError)
} else if(supabaseData) {
return supabaseData.id
}
}
return { logError}
}

View File

@@ -15,24 +15,29 @@
<UDashboardPanelContent> <UDashboardPanelContent>
<UDashboardCard <UDashboardCard
class="mt-3"
title="Anwesenheiten" title="Anwesenheiten"
v-if="dataStore.getStartedWorkingTimes().length > 0" v-if="dataStore.getStartedWorkingTimes().length > 0"
> >
<p v-for="time in dataStore.getStartedWorkingTimes()"><UIcon name="i-heroicons-check"/>{{profileStore.getProfileById(time.profile).fullName}}</p> <p v-for="time in dataStore.getStartedWorkingTimes()"><UIcon name="i-heroicons-check"/>{{profileStore.getProfileById(time.profile).fullName}}</p>
</UDashboardCard> </UDashboardCard>
<UDashboardCard <UDashboardCard
:ui="{ body: { padding: '!pb-3 !px-5' }}" class="mt-3"
> >
<display-income-and-expenditure/> <display-income-and-expenditure/>
</UDashboardCard> </UDashboardCard>
<UDashboardCard <UDashboardCard
class="w-1/3 mt-3" class="w-1/3 mt-3"
:ui="{ body: { padding: '!py-5 !px-5' }}"
> >
<display-open-balances/> <display-open-balances/>
</UDashboardCard> </UDashboardCard>
<UDashboardCard
class="w-1/3 mt-3"
>
<display-running-time/>
</UDashboardCard>
</UDashboardPanelContent> </UDashboardPanelContent>
</UDashboardPanel> </UDashboardPanel>
</UDashboardPage> </UDashboardPage>

View File

@@ -123,18 +123,24 @@ const workingTimeInfo = computed(() => {
return dayjs(date).isSameOrAfter(start) && dayjs(date).isSameOrBefore(end) return dayjs(date).isSameOrAfter(start) && dayjs(date).isSameOrBefore(end)
} }
absencerequests.value.filter(i => (dayjs(i.start).isBetween(dayjs(selectedStartDay.value),dayjs(selectedEndDay.value)) || dayjs(i.end).isBetween(dayjs(selectedStartDay.value),dayjs(selectedEndDay.value)) ) && i.reason === "Urlaub" && i.approved === "Genehmigt").forEach(absenceRequest => { absencerequests.value.filter(i => (dayjs(i.startDate).isBetween(dayjs(selectedStartDay.value),dayjs(selectedEndDay.value)) || dayjs(i.endDate).isBetween(dayjs(selectedStartDay.value),dayjs(selectedEndDay.value)) ) && (i.reason === "Urlaub" || i.reason === "Berufsschule") && i.approved === "Genehmigt").forEach(absenceRequest => {
let durationInDays = 0 let durationInDays = 0
if(isBetween(absenceRequest.start,selectedStartDay.value,selectedEndDay.value) && isBetween(absenceRequest.end,selectedStartDay.value,selectedEndDay.value)) { console.log(absenceRequest)
if(isBetween(absenceRequest.startDate,selectedStartDay.value,selectedEndDay.value) && isBetween(absenceRequest.endDate,selectedStartDay.value,selectedEndDay.value)) {
//Full in Range //Full in Range
durationInDays = dayjs(absenceRequest.end).diff(absenceRequest.start, "days") + 1 console.log("Full in Range")
} else if(isBetween(absenceRequest.start,selectedStartDay.value,selectedEndDay.value) && !isBetween(absenceRequest.end,selectedStartDay.value,selectedEndDay.value)) { durationInDays = dayjs(absenceRequest.endDate).diff(absenceRequest.startDate, "days") + 1
console.log(durationInDays)
} else if(isBetween(absenceRequest.startDate,selectedStartDay.value,selectedEndDay.value) && !isBetween(absenceRequest.endDate,selectedStartDay.value,selectedEndDay.value)) {
//Start in Range //Start in Range
durationInDays = dayjs(selectedEndDay.value).diff(absenceRequest.start, "days") + 1 console.log("Start in Range")
} else if(!isBetween(absenceRequest.start,selectedStartDay.value,selectedEndDay.value) && isBetween(absenceRequest.end,selectedStartDay.value,selectedEndDay.value)) { durationInDays = dayjs(selectedEndDay.value).diff(absenceRequest.startDate, "days") + 1
} else if(!isBetween(absenceRequest.startDate,selectedStartDay.value,selectedEndDay.value) && isBetween(absenceRequest.endDate,selectedStartDay.value,selectedEndDay.value)) {
//End in Range //End in Range
durationInDays = dayjs(absenceRequest.end).diff(selectedStartDay.value, "days") + 1 console.log("End in Range")
durationInDays = dayjs(absenceRequest.endDate).diff(selectedStartDay.value, "days") + 1
} }
sumVacationDays += durationInDays sumVacationDays += durationInDays
@@ -308,7 +314,7 @@ changeRange()
<p>Eingreicht: {{Math.floor(workingTimeInfo.sumWorkingMinutesEingereicht/60)}}:{{String(workingTimeInfo.sumWorkingMinutesEingereicht % 60).padStart(2,"0")}} h</p> <p>Eingreicht: {{Math.floor(workingTimeInfo.sumWorkingMinutesEingereicht/60)}}:{{String(workingTimeInfo.sumWorkingMinutesEingereicht % 60).padStart(2,"0")}} h</p>
<p>Genehmigt: {{Math.floor(workingTimeInfo.sumWorkingMinutesApproved/60)}}:{{String(workingTimeInfo.sumWorkingMinutesApproved % 60).padStart(2,"0")}} h</p> <p>Genehmigt: {{Math.floor(workingTimeInfo.sumWorkingMinutesApproved/60)}}:{{String(workingTimeInfo.sumWorkingMinutesApproved % 60).padStart(2,"0")}} h</p>
<p>Feiertagsausgleich: {{Math.floor(workingTimeInfo.sumWorkingMinutesRecreationDays/60)}}:{{String(workingTimeInfo.sumWorkingMinutesRecreationDays % 60).padStart(2,"0")}} h / {{workingTimeInfo.sumRecreationDays}} Tage</p> <p>Feiertagsausgleich: {{Math.floor(workingTimeInfo.sumWorkingMinutesRecreationDays/60)}}:{{String(workingTimeInfo.sumWorkingMinutesRecreationDays % 60).padStart(2,"0")}} h / {{workingTimeInfo.sumRecreationDays}} Tage</p>
<p>Urlaubsausgleich: {{Math.floor(workingTimeInfo.sumWorkingMinutesVacationDays/60)}}:{{String(workingTimeInfo.sumWorkingMinutesVacationDays % 60).padStart(2,"0")}} h / {{workingTimeInfo.sumVacationDays}} Tage</p> <p>Urlaubs-/Berufsschulausgleich: {{Math.floor(workingTimeInfo.sumWorkingMinutesVacationDays/60)}}:{{String(workingTimeInfo.sumWorkingMinutesVacationDays % 60).padStart(2,"0")}} h / {{workingTimeInfo.sumVacationDays}} Tage</p>
<p>Soll Stunden: {{Math.floor(workingTimeInfo.workingMinutesTarget/60)}}:{{String(workingTimeInfo.workingMinutesTarget % 60 ).padStart(2,"0")}} h</p> <p>Soll Stunden: {{Math.floor(workingTimeInfo.workingMinutesTarget/60)}}:{{String(workingTimeInfo.workingMinutesTarget % 60 ).padStart(2,"0")}} h</p>
<!-- <p>Abwesend: </p> <!-- <p>Abwesend: </p>

View File

@@ -11,17 +11,10 @@ definePageMeta({
const dataStore = useDataStore() const dataStore = useDataStore()
const profileStore = useProfileStore() const profileStore = useProfileStore()
const supabase = useSupabaseClient() const supabase = useSupabaseClient()
const user = useSupabaseUser()
const toast = useToast()
const router = useRouter() const router = useRouter()
const timeInfo = ref({
profile: "",
start: "",
end: null,
notes: null,
})
const filterUser = ref(profileStore.activeProfile.id || "") const filterUser = ref(profileStore.activeProfile.id || "")
@@ -108,53 +101,8 @@ const columns = [
] ]
const runningTimeInfo = ref({})
const startTime = async () => {
console.log("started")
timeInfo.value = {
profile: profileStore.activeProfile.id,
startDate: dayjs(),
tenant: profileStore.currentTenant,
state: "Im Web gestartet"
}
const {data,error} = await supabase
.from("workingtimes")
.insert([timeInfo.value])
.select()
if(error) {
console.log(error)
} else if(data) {
//timeInfo.value = data[0]
await dataStore.fetchWorkingTimes()
runningTimeInfo.value = timeInfo.value//dataStore.times.find(time => time.profile === profileStore.activeProfile.id && !time.endDate)
}
}
const stopStartedTime = async () => {
runningTimeInfo.value.endDate = dayjs()
runningTimeInfo.value.state = "Im Web gestoppt"
const {data,error} = await supabase
.from("workingtimes")
.update(runningTimeInfo.value)
.eq('id',runningTimeInfo.value.id)
.select()
console.log(data)
if(error) {
console.log(error)
} else {
toast.add({title: "Zeit erfolgreich gestoppt"})
runningTimeInfo.value = {}
dataStore.fetchWorkingTimes()
}
}
if(dataStore.workingtimes.find(time => time.profile === profileStore.activeProfile.id && !time.endDate)) {
runningTimeInfo.value = dataStore.workingtimes.find(time => time.profile === profileStore.activeProfile.id && !time.end)
}
const getDuration = (time) => { const getDuration = (time) => {
const minutes = Math.floor(dayjs(time.endDate).diff(dayjs(time.startDate),'minutes',true)) const minutes = Math.floor(dayjs(time.endDate).diff(dayjs(time.startDate),'minutes',true))
@@ -185,17 +133,19 @@ const expand = ref({
row: {} row: {}
}) })
const setEndDate = (row) => {
row.startDate = dayjs(row.startDate).toISOString()
row.endDate = dayjs(row.endDate).set("year", dayjs(row.startDate).get("year")).set("month", dayjs(row.startDate).get("month")).set("date", dayjs(row.startDate).get("date"))
row.endDate = dayjs(row.endDate).toISOString()
}
</script> </script>
<template> <template>
<UDashboardNavbar title="Anwesenheiten"> <UDashboardNavbar title="Anwesenheiten">
<template #right> <template #right>
<UButton
@click="startTime"
:disabled="runningTimeInfo.id "
>
Start
</UButton>
<UButton <UButton
@click="router.push(`/workingtimes/edit`)" @click="router.push(`/workingtimes/edit`)"
> >
@@ -224,34 +174,6 @@ const expand = ref({
</UButton> </UButton>
</template> </template>
</UDashboardToolbar> </UDashboardToolbar>
<div class="mx-3">
<UAlert
v-if="runningTimeInfo.startDate && !runningTimeInfo.endDate"
class="my-3"
title="Laufende Zeit:"
>
<template #description>
<p>Start: {{dayjs(runningTimeInfo.startDate).format("HH:mm")}}</p>
<p>Dauer: {{dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') > 59 ? `${Math.floor(dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') / 60)}:${dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') % 60} h` : dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') + ' min' }}</p>
<UFormGroup
class="mt-2"
label="Notizen:"
>
<UTextarea
v-model="runningTimeInfo.notes"
/>
</UFormGroup>
<UButton
class="mt-3"
@click="stopStartedTime"
:disabled="!runningTimeInfo.id"
>
Stop
</UButton>
</template>
</UAlert>
</div>
<UTable <UTable
class="mt-3" class="mt-3"
@@ -287,6 +209,7 @@ const expand = ref({
</UTooltip> </UTooltip>
</InputGroup> </InputGroup>
<div class="p-4" v-if="!row.approved"> <div class="p-4" v-if="!row.approved">
{{row}}
<UFormGroup label="Start:"> <UFormGroup label="Start:">
@@ -298,7 +221,7 @@ const expand = ref({
/> />
<template #panel="{ close }"> <template #panel="{ close }">
<LazyDatePicker v-model="row.startDate" @close="row.endDate = row.startDate" mode="dateTime"/> <LazyDatePicker v-model="row.startDate" @close="setEndDate(row)" mode="dateTime"/>
</template> </template>
</UPopover> </UPopover>
</UFormGroup> </UFormGroup>

View File

@@ -1411,7 +1411,7 @@ export const useDataStore = defineStore('data', () => {
}, },
{ {
key: "materialComposing", key: "materialComposing",
label: "Zusammensetzung Materialpreis", label: "Zusammensetzung Materialpreis pro Einheit",
inputType: "materialComposing", inputType: "materialComposing",
}, },
{ {