Initial commit - Stand 26.04.2026
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
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]
|
||||
|
||||
# Kredite mit ihren Spalten - basierend auf der Header-Struktur
|
||||
# Format: (kredit_name, restschuld_col, tilgung_col, zinsen_col)
|
||||
# Spalten sind 1-basiert
|
||||
|
||||
kredite_config = [
|
||||
("Targo Bank", 2, 3, 4),
|
||||
("Köpke", 6, 7, 8),
|
||||
("DSL Bank", 9, 10, 11),
|
||||
("PSD Nord", 13, 14, 15),
|
||||
("Zingelstr. 14", 20, 21, 22), # Rate in 21
|
||||
("Carola", 36, 37, 38),
|
||||
("Kerstin", 39, 40, 41),
|
||||
("PVCreditplus", 42, 43, 44), # Gefunden in Zeile 2, Spalte 42
|
||||
("Sparkasse", 45, 46, 47),
|
||||
]
|
||||
|
||||
print("\n" + "="*80)
|
||||
print("KORRIGIERTE KREDIT-ANALYSE")
|
||||
print("="*80)
|
||||
|
||||
aktive_kredite = []
|
||||
abgezahlte_kredite = []
|
||||
|
||||
# Aktuelles Datum für Vergleich
|
||||
heute = datetime(2026, 4, 20)
|
||||
|
||||
for name, rest_col, tilg_col, zins_col in kredite_config:
|
||||
print(f"\n--- {name} ---")
|
||||
print(f" Spalten: Rest={rest_col}, Tilgung={tilg_col}, Zinsen={zins_col}")
|
||||
|
||||
# Prüfe Header
|
||||
rest_header = row2[rest_col-1] if rest_col-1 < len(row2) else None
|
||||
print(f" Header Restschuld-Spalte: {rest_header}")
|
||||
|
||||
if rest_header != "Restschuld":
|
||||
print(f" [WARNUNG: Header ist '{rest_header}', nicht 'Restschuld']")
|
||||
|
||||
# Suche die relevanten Daten
|
||||
start_datum = None
|
||||
start_restschuld = None
|
||||
aktuelle_restschuld = None
|
||||
aktuelles_datum = None
|
||||
monatsrate = None
|
||||
zinssatz = None
|
||||
|
||||
# Finde erstes Datum mit Restschuld
|
||||
for row_idx in range(3, min(ws.max_row + 1, 500)):
|
||||
datum_cell = ws.cell(row=row_idx, column=1).value
|
||||
rest_cell = ws.cell(row=row_idx, column=rest_col).value
|
||||
|
||||
if datum_cell and isinstance(datum_cell, datetime):
|
||||
if rest_cell is not None:
|
||||
try:
|
||||
rest_val = float(rest_cell)
|
||||
if rest_val > 0 and start_datum is None:
|
||||
start_datum = datum_cell
|
||||
start_restschuld = rest_val
|
||||
print(f" Erster Wert: {rest_val:,.2f} EUR am {datum_cell.strftime('%d.%m.%Y')}")
|
||||
|
||||
# Monatsrate aus nächster Zeile
|
||||
next_tilg = ws.cell(row=row_idx+1, column=tilg_col).value if tilg_col else None
|
||||
if next_tilg and isinstance(next_tilg, (int, float)) and next_tilg > 0:
|
||||
monatsrate = next_tilg
|
||||
print(f" Monatsrate: {monatsrate:,.2f} EUR")
|
||||
break
|
||||
except:
|
||||
continue
|
||||
|
||||
# Finde aktuellen Stand (April 2026 oder letzter Wert)
|
||||
for row_idx in range(3, ws.max_row + 1):
|
||||
datum_cell = ws.cell(row=row_idx, column=1).value
|
||||
rest_cell = ws.cell(row=row_idx, column=rest_col).value
|
||||
|
||||
if datum_cell and isinstance(datum_cell, datetime):
|
||||
if rest_cell is not None:
|
||||
try:
|
||||
rest_val = float(rest_cell)
|
||||
# Nimm den Wert für April 2026 oder den letzten vorhandenen
|
||||
if datum_cell.year == 2026 and datum_cell.month == 4:
|
||||
aktuelle_restschuld = rest_val
|
||||
aktuelles_datum = datum_cell
|
||||
break
|
||||
elif datum_cell < heute:
|
||||
aktuelle_restschuld = rest_val
|
||||
aktuelles_datum = datum_cell
|
||||
except:
|
||||
continue
|
||||
|
||||
if aktuelle_restschuld is not None:
|
||||
# Status ermitteln
|
||||
status = "ABGEZAHLT" if aktuelle_restschuld < 100 else "AKTIV"
|
||||
|
||||
print(f" Aktuelle Restschuld ({aktuelles_datum.strftime('%d.%m.%Y')}): {aktuelle_restschuld:,.2f} EUR")
|
||||
print(f" STATUS: {status}")
|
||||
|
||||
kredit_info = {
|
||||
"name": name,
|
||||
"ursprungsschuld": start_restschuld if start_restschuld else aktuelle_restschuld,
|
||||
"restschuld": aktuelle_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_korrigiert.json", "w", encoding="utf-8") as f:
|
||||
json.dump({
|
||||
"aktiv": aktive_kredite,
|
||||
"abgezahlt": abgezahlte_kredite
|
||||
}, f, indent=2, default=str, ensure_ascii=False)
|
||||
|
||||
print("\nGespeichert in kredite_analyse_korrigiert.json")
|
||||
Reference in New Issue
Block a user