scripts/kalkulatorZONDA.py Repository Zonda-Kalkulator-PITolenia- Original path scripts/kalkulatorZONDA.pyRole SOURCE Size 35714 bytes Lines 1078 SHA-256 a803069c9de59e100339e2244228483d7adcc1a1d9e6d7b0a29ead5592a01bb0Displayed range 1001–1078 Previous file/page · Project index · Next file/page
# =========================
def main():
os.makedirs(INPUT_DIR, exist_ok=True)
pairs, warnings = detect_pairs(INPUT_DIR)
if not pairs:
raise RuntimeError("Nie znalazłem żadnych poprawnych par OPS/TRD po dopasowaniu datami w _wrzuc_raport.")
if warnings:
for w in warnings:
warn(w)
print()
nbp = NbpClient()
out_files: List[str] = []
total_pairs = len(pairs)
for run_idx, pr in enumerate(pairs, start=1):
year = int(pr["year"])
ops_path = pr["ops_path"]
trd_path = pr["trd_path"]
out_path = os.path.join(ROOT_DIR, f"Zonda PIT38 {year}.csv")
title_blue(f"===== ({run_idx}/{total_pairs}) START =====\n")
print(f"[PAIR] Rok {year}:")
print(f"[OK] Operacje: {os.path.basename(ops_path)}")
print(f"[OK] Transakcje: {os.path.basename(trd_path)}\n")
try:
if (not FORCE_REBUILD) and os.path.exists(out_path):
warn(f"Wynik już istnieje: {os.path.basename(out_path)} (ustaw FORCE_REBUILD=True aby przeliczyć)")
out_files.append(out_path)
print()
continue
produced_path, revenue, cost, profit, tax_full, fee_fiat_matched, fee_ops_total_pln, fee_ops_valued, fee_ops_unvalued, fee_ops_total_cnt, month_stats = compute_one_year(
ops_path=ops_path,
trd_path=trd_path,
year=year,
nbp=nbp
)
print_year_result(
year=year,
month_stats=month_stats,
revenue=revenue,
cost=cost,
profit=profit,
tax_full=tax_full,
fee_fiat_matched=fee_fiat_matched,
fee_ops_total_pln=fee_ops_total_pln,
fee_ops_valued=fee_ops_valued,
fee_ops_unvalued=fee_ops_unvalued,
fee_ops_total_cnt=fee_ops_total_cnt,
)
print_success_or_loss(year, profit)
out_files.append(produced_path)
except Exception as pair_err:
warn(f"Rok {year}: nie udało się policzyć pary ({pair_err})")
print()
spaced_rainbow("Życzę miłego dnia")
print("\n\nPliki wynikowe:")
for p in out_files:
print(f" - {p}")
if __name__ == "__main__":
try:
main()
except Exception as e:
print("\n" + c("❌ Błąd: ", RED) + str(e))
print("\n[ERROR] Kalkulator zakonczyl sie bledem.")
finally:
pause_exit()