From 66ee33cdde15ced7c1f86ed047ef086511d1dd94 Mon Sep 17 00:00:00 2001
From: flfeders
Date: Tue, 19 Mar 2024 12:26:16 +0100
Subject: [PATCH] Changes in times and Dashboard
---
imports/specht/index.js | 158 ++++++++++++++++++++++++++++
spaces/Dockerfile | 2 +-
spaces/pages/index.vue | 14 ++-
spaces/pages/profiles/show/[id].vue | 21 ++--
spaces/pages/workingtimes.vue | 3 +
spaces/stores/data.js | 5 +
6 files changed, 183 insertions(+), 20 deletions(-)
create mode 100644 imports/specht/index.js
diff --git a/imports/specht/index.js b/imports/specht/index.js
new file mode 100644
index 0000000..2ac1ad5
--- /dev/null
+++ b/imports/specht/index.js
@@ -0,0 +1,158 @@
+
+const csv = require("csv-parser")
+const fs = require("fs")
+const path = require("path")
+const {createClient} = require("@supabase/supabase-js")
+const dayjs = require("dayjs")
+const customParseFormat = require('dayjs/plugin/customParseFormat')
+dayjs.extend(customParseFormat)
+
+
+
+
+const supabase = createClient("https://uwppvcxflrcsibuzsbil.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InV3cHB2Y3hmbHJjc2lidXpzYmlsIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTcwMDkzODE5NCwiZXhwIjoyMDE2NTE0MTk0fQ.6hOkD1J8XBkVJUm-swv0ngLQ74xrEYr28EEbo0rUrts")
+let rows = []
+fs.createReadStream(path.join(__dirname, "./Zeiterfassung.csv"), "utf-8")
+ .pipe(csv({ separator: ";" }))
+ .on("data", (data) => rows.push(data))
+ .on("end", async function () {
+ console.log("finished");
+ console.log(rows)
+
+ let profiles = (await supabase.from("profiles").select()).data
+
+ let times = []
+ let absences = []
+
+ rows.forEach(row => {
+
+ let date = dayjs(row.Datum, "DD.MM.YY",true).format("YYYY-MM-DD")
+ let profileId = profiles.find(i => i.employeeNumber === row['Mitarbeiter']).id
+ if(row.Notiz === 'Krankheit' || row.Notiz === "Urlaub" || row.Notiz === "Berufsschule") {
+ absences.push({
+ user: profileId,
+ tenant: 11,
+ start: date,
+ end: date,
+ reason: row.Notiz,
+ approved: "Genehmigt"
+ })
+ } else {
+ if(row.Start_1 && row.Ende_1) {
+ times.push({
+ profile:profileId,
+ date: date,
+ start: row.Start_1 + ":00",
+ end: row.Ende_1 + ":00",
+ approved:true,
+ tenant: 11,
+ state: "Importiert",
+ notes: row.Notiz
+ })
+ }
+
+ if(row.Start_2&& row.Ende_2) {
+ times.push({
+ profile:profileId,
+ date: date,
+ start: row.Start_2 + ":00",
+ end: row.Ende_2 + ":00",
+ approved:true,
+ tenant: 11,
+ state: "Importiert",
+ notes: row.Notiz
+ })
+ }
+
+ if(row.Start_3 && row.Ende_3) {
+
+ times.push({
+ profile:profileId,
+ date: date,
+ start: row.Start_3 + ":00",
+ end: row.Ende_3 + ":00",
+ approved:true,
+ tenant: 11,
+ state: "Importiert",
+ notes: row.Notiz
+ })
+ }
+
+ if(row.Start_4 && row.Ende_4) {
+ times.push({
+ profile:profileId,
+ date: date,
+ start: row.Start_4 + ":00",
+ end: row.Ende_4 + ":00",
+ approved:true,
+ tenant: 11,
+ state: "Importiert",
+ notes: row.Notiz
+ })
+ }
+ }
+
+
+
+ })
+
+ console.log(times)
+ console.log(times.length)
+
+ /*let hours = 0
+ let datebefore = ""
+ let days = []
+ let daysum = 0
+
+ times.forEach(time => {
+ if(time.date !== datebefore) {
+ datebefore = time.date
+ daysum = 0
+ }
+
+ console.log(time.date)
+ console.log(time.start)
+ console.log(time.end)
+ hours += dayjs(time.end, "HH:mm:ss").diff(dayjs(time.start, "HH:mm:ss"), "minutes")
+
+ daysum += dayjs(time.end, "HH:mm:ss").diff(dayjs(time.start, "HH:mm:ss"), "minutes")
+ console.log(datebefore, daysum/60)
+
+ })
+
+ console.log(hours/60)*/
+
+ await supabase.from("absencerequests").insert(absences)
+ await supabase.from("workingtimes").insert(times)
+
+ /*projects = rows.map(i => {
+
+ let item = {
+ customer : Number(i.customer),
+ tenant: tenant,
+ name: i.Projektname,
+ notes: i.Anmerkungen + "\n" + i['Angaben zum Projekt']
+ }
+
+
+ return item
+
+ })
+ console.log(projects)
+
+
+
+
+ const {data:vendorsData,error: vendorsError} = await supabase.from("projects").insert(projects).select()
+ console.log(vendorsData)
+ console.log(vendorsError)*/
+
+
+
+
+ //console.log(rows)
+ })
+ .on("error", function (error) {
+ console.log(error.message);
+ });
+
diff --git a/spaces/Dockerfile b/spaces/Dockerfile
index 21c098e..18ee495 100644
--- a/spaces/Dockerfile
+++ b/spaces/Dockerfile
@@ -12,4 +12,4 @@ ENV NUXT_PORT=3000
EXPOSE 3000
-ENTRYPOINT ["node", ".output/server/index.mjs"]
+ENTRYPOINT ["node", ".output/server/index.js"]
diff --git a/spaces/pages/index.vue b/spaces/pages/index.vue
index d9ca9f2..ef3abf5 100644
--- a/spaces/pages/index.vue
+++ b/spaces/pages/index.vue
@@ -28,15 +28,11 @@
-->
-
-
@@ -47,6 +43,8 @@ definePageMeta({
middleware: "auth"
})
+const dataStore = useDataStore()
+
const { isNotificationsSlideoverOpen } = useDashboard()
const items = [[{
label: 'Aufgabe',
diff --git a/spaces/pages/profiles/show/[id].vue b/spaces/pages/profiles/show/[id].vue
index b6c9fed..0154921 100644
--- a/spaces/pages/profiles/show/[id].vue
+++ b/spaces/pages/profiles/show/[id].vue
@@ -47,8 +47,8 @@ const changeRange = () => {
subtract = 1
}
- selectedStartDay.value = dayjs().subtract(subtract,selector).startOf(selector).format("YYYY-MM-DD")
- selectedEndDay.value = dayjs().subtract(subtract,selector).endOf(selector).format("YYYY-MM-DD")
+ selectedStartDay.value = dayjs().subtract(subtract,selector === "isoWeek" ? "week" : selector).startOf(selector).format("YYYY-MM-DD")
+ selectedEndDay.value = dayjs().subtract(subtract,selector === "isoWeek" ? "week" : selector).endOf(selector).format("YYYY-MM-DD")
}
@@ -57,7 +57,7 @@ const workingTimeInfo = computed(() => {
let times = dataStore.getWorkingTimesByProfileId(itemInfo.value.id)
- times = times.filter(i => dayjs(i.date).isBetween(selectedStartDay.value,selectedEndDay.value,'day') && i.end)
+ times = times.filter(i => dayjs(i.date).isBetween(dayjs(selectedStartDay.value).subtract(1,"days"),selectedEndDay.value,'day') && i.end)
@@ -68,27 +68,24 @@ const workingTimeInfo = computed(() => {
//Eingreicht
let sumWorkingMinutesEingereicht = 0
times.filter(i => !i.approved).forEach(time => {
- console.log(time)
const minutes = dayjs(time.end, "HH:mm:ss").diff(dayjs(time.start, "HH:mm:ss"),'minutes')
- console.log(minutes)
sumWorkingMinutesEingereicht = sumWorkingMinutesEingereicht + minutes
})
//Bestätigt
let sumWorkingMinutesApproved = 0
times.filter(i => i.approved).forEach(time => {
- const minutes = Math.floor(dayjs(time.end, "HH:mm:ss").diff(dayjs(time.start, "HH:mm:ss"),'minutes'))
+ const minutes = dayjs(time.end, "HH:mm:ss").diff(dayjs(time.start, "HH:mm:ss"),'minutes')
sumWorkingMinutesApproved = sumWorkingMinutesApproved + minutes
})
+ //console.log(times.filter(i => i.approved).length)
+ //console.log(sumWorkingMinutesApproved)
//Saldo
let saldo = (sumWorkingMinutesApproved / 60).toFixed(2) - monthlyWorkingHours
let saldoInOfficial = ((sumWorkingMinutesApproved + sumWorkingMinutesEingereicht) / 60).toFixed(2) - monthlyWorkingHours
-
-
-
return {
monthlyWorkingHours,
sumWorkingMinutesEingereicht,
@@ -211,7 +208,6 @@ changeRange()
@change="changeRange"
/>
-
Saldo: {{workingTimeInfo.saldo}} h
+
+
{
return workingtimes.value.filter(i => i.profile === profileId)
})
+ const getStartedWorkingTimes = computed(() => () => {
+ return workingtimes.value.filter(i => !i.end)
+ })
+
const getStockByProductId = computed(() => (productId) => {
let productMovements = movements.value.filter(movement => movement.productId === productId)
@@ -1254,6 +1258,7 @@ export const useDataStore = defineStore('data', () => {
getTextTemplatesByDocumentType,
getCreatedDocumentsByProject,
getWorkingTimesByProfileId,
+ getStartedWorkingTimes,
getStockByProductId,
getIncomingInvoicesByVehicleId,
getEventTypes,