Changes in times and Dashboard

This commit is contained in:
2024-03-19 12:26:16 +01:00
parent edf1de189b
commit 66ee33cdde
6 changed files with 183 additions and 20 deletions

158
imports/specht/index.js Normal file
View File

@@ -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);
});