Compare commits

..

No commits in common. "2328a1c1db54ac1d338fb8a71f3f9f90fcd51993" and "d0735c540e6191374f6599d3e0fc6691cb74b319" have entirely different histories.

View file

@ -1,11 +1,11 @@
#!/usr/bin/env python3
#1
from pathlib import Path
from datetime import datetime
import json
import csv
import sys
from openpyxl import Workbook, load_workbook
from openpyxl import Workbook
# --------------------------------------------------
# Kalenderwoche bestimmen
@ -49,12 +49,12 @@ source_json = (
categorized_csv_dir = year_dir / "categorized_csv"
categorized_json_dir = year_dir / "categorized_json"
summary_dir = year_dir / "summary"
jahresauswertung_dir = year_dir / "jahresauswertung"
excel_dir = year_dir / "excel"
categorized_csv_dir.mkdir(parents=True, exist_ok=True)
categorized_json_dir.mkdir(parents=True, exist_ok=True)
summary_dir.mkdir(parents=True, exist_ok=True)
jahresauswertung_dir.mkdir(parents=True, exist_ok=True)
excel_dir.mkdir(parents=True, exist_ok=True)
csv_file = (
categorized_csv_dir
@ -72,8 +72,8 @@ summary_file = (
)
excel_file = (
jahresauswertung_dir
/ f"Kontobewegungen_{year}.xlsx"
excel_dir
/ f"transactions_{year}_KW{week:02d}.xlsx"
)
# --------------------------------------------------
@ -211,51 +211,35 @@ with open(json_file, "w", encoding="utf-8") as outfile:
)
# --------------------------------------------------
# Jahres-Excel aktualisieren
# Excel exportieren
# --------------------------------------------------
if excel_file.exists():
wb = load_workbook(excel_file)
else:
wb = Workbook()
if "Sheet" in wb.sheetnames:
wb.remove(wb["Sheet"])
wb = Workbook()
sheet_name = f"KW{week:02d}"
ws1 = wb.active
ws1.title = "Transaktionen"
# Vorhandenes Blatt ersetzen
if sheet_name in wb.sheetnames:
wb.remove(wb[sheet_name])
ws1.append([
"Datum",
"Betrag",
"Kategorie",
"Name",
"Verwendungszweck"
])
ws = wb.create_sheet(sheet_name)
for t in categorized_transactions:
ws1.append([
t["date"],
t["amount"],
t["category"],
t["applicant_name"],
t["purpose"]
])
# Kennzahlen
ws2 = wb.create_sheet("Kategorien")
total_income = sum(
values["income"]
for values in category_totals.values()
)
total_expenses = sum(
values["expenses"]
for values in category_totals.values()
)
total_saldo = sum(
values["saldo"]
for values in category_totals.values()
)
ws.append(["Kennzahl", "Wert"])
ws.append(["Transaktionen", len(categorized_transactions)])
ws.append(["Einnahmen", total_income])
ws.append(["Ausgaben", total_expenses])
ws.append(["Saldo", total_saldo])
ws.append([])
ws.append([
ws2.append([
"Kategorie",
"Einnahmen",
"Ausgaben",
@ -263,49 +247,16 @@ ws.append([
])
for category, values in sorted(category_totals.items()):
ws.append([
ws2.append([
category,
values["income"],
values["expenses"],
values["saldo"]
])
# --------------------------------------------------
# Übersicht aktualisieren
# --------------------------------------------------
if "Übersicht" in wb.sheetnames:
wb.remove(wb["Übersicht"])
overview = wb.create_sheet("Übersicht", 0)
overview.append([
"KW",
"Einnahmen",
"Ausgaben",
"Saldo"
])
for sheet in sorted(
[s for s in wb.sheetnames if s.startswith("KW")]
):
ws_kw = wb[sheet]
income = ws_kw["B3"].value
expenses = ws_kw["B4"].value
saldo = ws_kw["B5"].value
overview.append([
sheet,
income,
expenses,
saldo
])
wb.save(excel_file)
# --------------------------------------------------
# Kategorien-Summen exportieren
# --------------------------------------------------