Files
FEDEO/imports/specht/addDates.js
2024-04-07 18:26:14 +02:00

190 lines
5.5 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
});*/