107 lines
3.1 KiB
JavaScript
107 lines
3.1 KiB
JavaScript
const { Pool } = require('pg');
|
|
|
|
// Verbindung zur Datenbank
|
|
const pool = new Pool({
|
|
host: '192.168.0.141',
|
|
port: 5432,
|
|
database: 'buchhaltung',
|
|
user: 'postgres',
|
|
password: 'postgres'
|
|
});
|
|
|
|
async function importTest() {
|
|
const client = await pool.connect();
|
|
|
|
try {
|
|
console.log('=== TEST-IMPORT: Yvonne Brandt 2023 ===\n');
|
|
|
|
// Prüfe vorhandene Einträge
|
|
const checkResult = await client.query(
|
|
"SELECT COUNT(*) FROM nebenkosten WHERE wohnung = $1 AND mieter LIKE $2",
|
|
['Zingelstr. 14', '%Brandt%']
|
|
);
|
|
const existingCount = parseInt(checkResult.rows[0].count);
|
|
console.log(`Vorhandene Einträge für Brandt/Zingelstr. 14: ${existingCount}`);
|
|
|
|
// Test-Einheit: Brandt 2023
|
|
const testData = {
|
|
jahr: 2023,
|
|
wohnung: 'Zingelstr. 14',
|
|
mieter: 'Yvonne Brandt',
|
|
kaltmiete: null,
|
|
nebenkosten: 501.48, // Summe aus Excel
|
|
versicherung: 129.58, // Geb. Vers./Haftpflichtv.
|
|
heizkosten: 102.53, // Wartung Heizung
|
|
wasser: null,
|
|
muell: 153.85, // Müllabfuhr
|
|
sonstiges: 115.53 // Grundsteuer (40.17) + Niederschlagwasser (75.36)
|
|
};
|
|
|
|
console.log('\n=== ZU IMPORTIERENDE DATEN ===');
|
|
console.log(JSON.stringify(testData, null, 2));
|
|
|
|
// INSERT
|
|
const query = `
|
|
INSERT INTO nebenkosten
|
|
(jahr, wohnung, mieter, kaltmiete, nebenkosten, heizkosten, wasser, muell, versicherung, sonstiges)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
|
RETURNING *
|
|
`;
|
|
|
|
const values = [
|
|
testData.jahr,
|
|
testData.wohnung,
|
|
testData.mieter,
|
|
testData.kaltmiete,
|
|
testData.nebenkosten,
|
|
testData.heizkosten,
|
|
testData.wasser,
|
|
testData.muell,
|
|
testData.versicherung,
|
|
testData.sonstiges
|
|
];
|
|
|
|
console.log('\n=== FÜHRE IMPORT AUS ===');
|
|
const result = await client.query(query, values);
|
|
|
|
console.log('\n✓ ERFOLGREICH IMPORTIERT:');
|
|
console.log(' ID:', result.rows[0].id);
|
|
console.log(' Jahr:', result.rows[0].jahr);
|
|
console.log(' Wohnung:', result.rows[0].wohnung);
|
|
console.log(' Mieter:', result.rows[0].mieter);
|
|
console.log(' Nebenkosten:', result.rows[0].nebenkosten, '€');
|
|
console.log(' Versicherung:', result.rows[0].versicherung, '€');
|
|
console.log(' Heizkosten:', result.rows[0].heizkosten, '€');
|
|
console.log(' Müll:', result.rows[0].muell, '€');
|
|
console.log(' Sonstiges:', result.rows[0].sonstiges, '€');
|
|
|
|
// Verifiziere
|
|
const verifyResult = await client.query(
|
|
'SELECT * FROM nebenkosten WHERE id = $1',
|
|
[result.rows[0].id]
|
|
);
|
|
|
|
console.log('\n=== VERIFIZIERUNG ===');
|
|
if (verifyResult.rows.length === 1) {
|
|
console.log('✓ Datensatz in Datenbank bestätigt');
|
|
} else {
|
|
console.log('✗ Datensatz nicht gefunden!');
|
|
}
|
|
|
|
return result.rows[0];
|
|
|
|
} catch (error) {
|
|
console.error('\n❌ FEHLER beim Import:', error.message);
|
|
throw error;
|
|
} finally {
|
|
client.release();
|
|
await pool.end();
|
|
}
|
|
}
|
|
|
|
// Führe Import aus
|
|
importTest().catch(err => {
|
|
console.error('\nImport fehlgeschlagen:', err);
|
|
process.exit(1);
|
|
});
|