Files
online-energieausweis/src/testing/ausweise-fix-rechnungsid.ts
2025-04-12 16:40:21 +02:00

52 lines
1.9 KiB
TypeScript

import { Enums, prisma } from "#lib/server/prisma.js";
import Papa from "papaparse"
import * as fs from "fs";
import { fileURLToPath } from "url";
import { generatePrefixedId } from "#lib/db.js";
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
const path = fileURLToPath(new URL("./rechnungen.csv", import.meta.url));
if (!fs.existsSync(path)) {
throw new Error(`${path} existiert nicht.`)
}
const file = fs.createReadStream(path, "utf8");
Papa.parse(file, {
header: true,
async complete(results, file) {
let i = 0;
for (const rechnung of results.data as any) {
i++
if (i % 1000 === 0) {
console.log(`Processed ${i} of ${results.data.length}, ${Math.round(i / results.data.length * 100)}%`)
}
const existing_rechnung = await prisma.rechnung.findFirst({
where: {
alte_id: parseInt(rechnung.id)
}
})
if (existing_rechnung) {
const existing_bedarfsausweiswohnen = await prisma.bedarfsausweisWohnen.findFirst({
where: {
alte_ausweis_id: parseInt(rechnung.ausweis_id)
}
})
if (existing_bedarfsausweiswohnen){
if (existing_bedarfsausweiswohnen.rechnung_id != existing_rechnung.id){
console.log('Rechnungsnummer weicht ab. Alte Ausweis Id:'+ rechnung.ausweis_id + ': ' + existing_bedarfsausweiswohnen.rechnung_id + ' vs ' + existing_rechnung.id);
//Todo: Rechnungsid updaten
} else {
//console.log('Rechnungsnummer Abgleich ok. Alte Ausweis Id:'+ rechnung.ausweis_id + ': ' + existing_bedarfsausweiswohnen.rechnung_id + ' vs ' + existing_rechnung.id);
}
}
} else {
console.log('Rechnung existiert nicht: '+ parseInt(rechnung.id));
}
//if (i > 10000) break;
}
}
});