diff --git a/imports/specht/addDates.js b/imports/specht/addDates.js new file mode 100644 index 0000000..cebbb0b --- /dev/null +++ b/imports/specht/addDates.js @@ -0,0 +1,189 @@ + +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 = [] + +const addDates = async () => { + const {data: workingTimesData,error: workingTimesError} = await supabase.from("workingtimes").select() + console.log(workingTimesData.length) + + let updatedData = workingTimesData.map(item => { + return { + ...item, + startDate: new Date(item.date + "T" + item.start), + endDate: new Date(item.date + "T" + item.end) + } + }) + + console.log(updatedData) + + for (let item of updatedData) { + console.log(item) + const {data,error} = await supabase.from("workingtimes").update(item).eq("id",item.id) + console.log(data) + console.log(error) + } + + + +} + +addDates() + + + + +/*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/pages/vendors/[mode]/[[id]].vue b/spaces/pages/vendors/[mode]/[[id]].vue index 7478892..3709792 100644 --- a/spaces/pages/vendors/[mode]/[[id]].vue +++ b/spaces/pages/vendors/[mode]/[[id]].vue @@ -1,5 +1,4 @@ + + + + + + Abbrechen + + + Speichern + + + Erstellen + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spaces/pages/workingtimes.vue b/spaces/pages/workingtimes/index.vue similarity index 57% rename from spaces/pages/workingtimes.vue rename to spaces/pages/workingtimes/index.vue index 7d94f08..61f34ab 100644 --- a/spaces/pages/workingtimes.vue +++ b/spaces/pages/workingtimes/index.vue @@ -4,8 +4,7 @@ import customParseFormat from "dayjs/plugin/customParseFormat" dayjs.extend(customParseFormat) -import VueDatePicker from '@vuepic/vue-datepicker' -import '@vuepic/vue-datepicker/dist/main.css' + definePageMeta({ @@ -16,6 +15,7 @@ const dataStore = useDataStore() const supabase = useSupabaseClient() const user = useSupabaseUser() const toast = useToast() +const router = useRouter() const timeInfo = ref({ @@ -95,7 +95,6 @@ const columns = [ ] const runningTimeInfo = ref({}) -const showConfigTimeModal = ref(false) const configTimeMode = ref("create") @@ -175,7 +174,6 @@ const createTime = async () => { } else if(data) { itemInfo.value = {} toast.add({title: "Zeit erfolgreich erstellt"}) - showConfigTimeModal.value = false await dataStore.fetchTimes() } @@ -192,7 +190,6 @@ const updateTime = async () => { } toast.add({title: "Zeit erfolgreich gespeichert"}) - showConfigTimeModal.value = false await dataStore.fetchTimes() } @@ -203,7 +200,7 @@ const format = (date) => { } const getDuration = (time) => { - const minutes = Math.floor(dayjs(time.end, "HH:mm:ss").diff(dayjs(time.start, "HH:mm:ss"),'minutes',true)) + const minutes = Math.floor(dayjs(time.endDate).diff(dayjs(time.startDate),'minutes',true)) const hours = Math.floor(minutes/60) return { //dezimal: dez, @@ -233,7 +230,7 @@ const setState = async (newState) => { Start Erstellen @@ -280,153 +277,18 @@ const setState = async (newState) => { - - - - - - Zeiteintrag {{configTimeMode === 'create' ? "erstellen" : "bearbeiten"}} - - - - - - - - - - - - - - - - - - - - - - - - - - {{dataStore.profiles.find(profile => profile.id === itemInfo.profile) ? dataStore.profiles.find(profile => profile.id === itemInfo.profile).fullName : "Benutzer auswählen"}} - - - - - - - - - - - - - Erstellen - - - Speichern - - - - Einreichen - - - - - - - - {configTimeMode = 'edit'; + @select="(row) => { + router.push(`/workingtimes/edit/${row.id}`) + /*configTimeMode = 'edit'; itemInfo = row; - showConfigTimeModal = true}" + showConfigTimeModal = true*/}" >