Initial commit - Stand 26.04.2026
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
import openpyxl
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
||||
datei = "Kopie von Kostenrechnung der Nächsten jahre (3).xlsx"
|
||||
print(f"Lade {datei}...")
|
||||
|
||||
wb = openpyxl.load_workbook(datei, data_only=True)
|
||||
ws = wb["Tilgung bei Gleichbleibenden Be"]
|
||||
|
||||
row1 = list(ws.iter_rows(min_row=1, max_row=1, values_only=True))[0]
|
||||
row2 = list(ws.iter_rows(min_row=2, max_row=2, values_only=True))[0]
|
||||
|
||||
# Alle Kredite mit ihren Spalten definieren
|
||||
# Format: (kredit_name, restschuld_col, tilgung_col, zinsen_col, start_datum_col)
|
||||
kredite_config = [
|
||||
("Targo Bank", 2, 3, 4, 1),
|
||||
("Köpke", 6, 7, None, 1),
|
||||
("DSL Bank", 9, 10, 11, 1),
|
||||
("PSD Nord", 13, 14, 15, 1),
|
||||
("Zingelstr. 14", 20, None, 22, 1), # Keine Tilgung-Spalte, aber Rate in 21?
|
||||
("Sparkasse", None, 21, 22, 1), # Sparkasse hat Rate statt Restschuld?
|
||||
("Gesamt", 24, 25, 26, 1),
|
||||
("Carola", 36, None, None, 1), # Nur Restschuld?
|
||||
("Kerstin", 39, None, None, 1), # Nur Restschuld?
|
||||
]
|
||||
|
||||
print("\n" + "="*80)
|
||||
print("KOMPLETTE KREDIT-ANALYSE")
|
||||
print("="*80)
|
||||
|
||||
aktive_kredite = []
|
||||
abgezahlte_kredite = []
|
||||
|
||||
for name, rest_col, tilg_col, zins_col, datum_col in kredite_config:
|
||||
print(f"\n--- {name} ---")
|
||||
print(f" Spalten: Rest={rest_col}, Tilgung={tilg_col}, Zinsen={zins_col}")
|
||||
|
||||
if not rest_col:
|
||||
print(f" [KEINE RESTSCHULD-SPAlTE - Überspringe]")
|
||||
continue
|
||||
|
||||
# Suche die letzte Zeile mit Daten
|
||||
letzte_restschuld = None
|
||||
letztes_datum = None
|
||||
start_datum = None
|
||||
erster_wert = None
|
||||
monatsrate = None
|
||||
zinssatz = None
|
||||
|
||||
letzte_zeile_mit_datum = None
|
||||
|
||||
for row_idx in range(3, min(ws.max_row + 1, 400)):
|
||||
datum_cell = ws.cell(row=row_idx, column=datum_col).value
|
||||
rest_cell = ws.cell(row=row_idx, column=rest_col).value
|
||||
tilg_cell = ws.cell(row=row_idx, column=tilg_col).value if tilg_col else None
|
||||
|
||||
# Konvertiere Restschuld zu Zahl
|
||||
if rest_cell is not None:
|
||||
try:
|
||||
rest_val = float(rest_cell)
|
||||
except:
|
||||
continue
|
||||
else:
|
||||
continue
|
||||
|
||||
# Startdatum = erstes Datum mit Restschuld > 0
|
||||
if start_datum is None and datum_cell and isinstance(datum_cell, datetime) and rest_val > 0:
|
||||
start_datum = datum_cell
|
||||
erster_wert = rest_val
|
||||
|
||||
# Monatsrate aus konstanter Tilgung (erster Wert)
|
||||
if tilg_cell and isinstance(tilg_cell, (int, float)):
|
||||
if tilg_cell > 0 and monatsrate is None:
|
||||
monatsrate = tilg_cell
|
||||
|
||||
# Letzter Wert
|
||||
letzte_restschuld = rest_val
|
||||
if datum_cell and isinstance(datum_cell, datetime):
|
||||
letztes_datum = datum_cell
|
||||
letzte_zeile_mit_datum = row_idx
|
||||
|
||||
# Status ermitteln
|
||||
if letzte_restschuld is not None:
|
||||
# Wenn Restschuld < 10 EUR oder negativ, gilt als abbezahlt
|
||||
status = "ABGEZAHLT" if letzte_restschuld < 10 else "AKTIV"
|
||||
|
||||
print(f" Ursprungsschuld: {erster_wert:,.2f} EUR" if erster_wert else " Ursprungsschuld: N/A")
|
||||
print(f" Aktuelle Restschuld: {letzte_restschuld:,.2f} EUR")
|
||||
print(f" Startdatum: {start_datum.strftime('%d.%m.%Y') if start_datum else 'N/A'}")
|
||||
print(f" Letztes Datum: {letztes_datum.strftime('%d.%m.%Y') if letztes_datum else 'N/A'}")
|
||||
print(f" Monatsrate: {monatsrate:,.2f} EUR" if monatsrate else " Monatsrate: N/A")
|
||||
print(f" STATUS: {status}")
|
||||
|
||||
kredit_info = {
|
||||
"name": name,
|
||||
"ursprungsschuld": erster_wert if erster_wert else 0,
|
||||
"restschuld": letzte_restschuld,
|
||||
"start_datum": start_datum.strftime("%Y-%m-%d") if start_datum else None,
|
||||
"monatsrate": monatsrate,
|
||||
"zinssatz": zinssatz,
|
||||
"status": status
|
||||
}
|
||||
|
||||
if status == "AKTIV":
|
||||
aktive_kredite.append(kredit_info)
|
||||
else:
|
||||
abgezahlte_kredite.append(kredit_info)
|
||||
else:
|
||||
print(f" [Keine Daten gefunden]")
|
||||
|
||||
print("\n" + "="*80)
|
||||
print("ZUSAMMENFASSUNG")
|
||||
print("="*80)
|
||||
|
||||
print(f"\n>>> AKTIVE KREDITE ({len(aktive_kredite)}):")
|
||||
for k in aktive_kredite:
|
||||
print(f" - {k['name']}: {k['restschuld']:,.2f} EUR Restschuld")
|
||||
|
||||
print(f"\n>>> ABGEZAHLT ({len(abgezahlte_kredite)}):")
|
||||
for k in abgezahlte_kredite:
|
||||
print(f" - {k['name']}")
|
||||
|
||||
print("\n" + "="*80)
|
||||
print("JSON für Import (nur AKTIVE):")
|
||||
print("="*80)
|
||||
print(json.dumps(aktive_kredite, indent=2, default=str))
|
||||
|
||||
# Speichere als Datei
|
||||
with open("kredite_analyse.json", "w", encoding="utf-8") as f:
|
||||
json.dump({
|
||||
"aktiv": aktive_kredite,
|
||||
"abgezahlt": abgezahlte_kredite
|
||||
}, f, indent=2, default=str, ensure_ascii=False)
|
||||
|
||||
print("\n✅ Gespeichert in kredite_analyse.json")
|
||||
Reference in New Issue
Block a user