110 lines
4.0 KiB
Python
110 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
|
||
import urllib.parse
|
||
import qrcode
|
||
from pathlib import Path
|
||
from datetime import datetime
|
||
from PIL import Image, ImageTk
|
||
import customtkinter as ctk
|
||
from tkinter import messagebox
|
||
|
||
IBAN = "CZ7520100000002800046620"
|
||
CURRENCY = "CZK"
|
||
OUTPUT_DIR = Path("QRPlatby")
|
||
OUTPUT_DIR.mkdir(exist_ok=True)
|
||
|
||
PRIJMENI = "Buzalka"
|
||
JMENO = "Vladimír"
|
||
RODCIS = "730928104"
|
||
|
||
ITEMS = {
|
||
"Očkování chřipka Vaxigrip": 600.00,
|
||
"Očkování chřipka Efluelda": 1300.00,
|
||
}
|
||
|
||
def create_spayd(iban, amount, vs, msg, currency="CZK"):
|
||
msg_encoded = urllib.parse.quote(msg, safe="$%*+-.:/")
|
||
return f"SPD*1.0*ACC:{iban}*AM:{amount:.2f}*CC:{currency}*X-VS:{vs}*MSG:{msg_encoded}"
|
||
|
||
class QRPlatbaApp(ctk.CTk):
|
||
def __init__(self):
|
||
super().__init__()
|
||
self.title("QR Platba – Ordinace MUDr. Buzalková")
|
||
self.geometry("520x520")
|
||
self.minsize(480, 480)
|
||
self.resizable(True, True)
|
||
|
||
ctk.set_appearance_mode("light")
|
||
ctk.set_default_color_theme("blue")
|
||
|
||
frame = ctk.CTkFrame(self, corner_radius=10)
|
||
frame.pack(expand=True, fill="both", padx=20, pady=20)
|
||
|
||
ctk.CTkLabel(frame, text="Generátor QR Platby",
|
||
font=("Arial", 20, "bold")).pack(pady=(10, 20))
|
||
|
||
patient = ctk.CTkFrame(frame, corner_radius=8)
|
||
patient.pack(fill="x", pady=(0, 20), padx=10)
|
||
for text in [f"Příjmení: {PRIJMENI}",
|
||
f"Jméno: {JMENO}",
|
||
f"Rodné číslo: {RODCIS}"]:
|
||
ctk.CTkLabel(patient, text=text, font=("Arial", 12)).pack(anchor="w", padx=10, pady=2)
|
||
|
||
pay = ctk.CTkFrame(frame, corner_radius=8)
|
||
pay.pack(fill="x", pady=(0, 20), padx=10)
|
||
ctk.CTkLabel(pay, text="Vyberte položku k úhradě:",
|
||
font=("Arial", 12, "bold")).pack(anchor="w", padx=10, pady=(10, 5))
|
||
|
||
self.selected_item = ctk.StringVar(value=list(ITEMS.keys())[0])
|
||
self.combo = ctk.CTkOptionMenu(pay,
|
||
variable=self.selected_item,
|
||
values=list(ITEMS.keys()),
|
||
font=("Arial", 12),
|
||
command=self.update_amount)
|
||
self.combo.pack(fill="x", padx=10)
|
||
self.amount_label = ctk.CTkLabel(pay, text="", font=("Arial", 12, "italic"))
|
||
self.amount_label.pack(anchor="e", padx=10, pady=(5, 10))
|
||
self.update_amount()
|
||
|
||
ctk.CTkButton(frame, text="Vytvořit QR Platbu",
|
||
font=("Arial", 13, "bold"),
|
||
height=40,
|
||
command=self.generate_qr).pack(pady=10)
|
||
|
||
self.qr_label = ctk.CTkLabel(frame, text="")
|
||
self.qr_label.pack(pady=15)
|
||
|
||
ctk.CTkLabel(frame,
|
||
text="© Ordinace MUDr. Buzalková | QR Platba dle ČBA v1.2",
|
||
font=("Arial", 10),
|
||
text_color="#666").pack(side="bottom", pady=(10, 0))
|
||
|
||
def update_amount(self, _=None):
|
||
item = self.selected_item.get()
|
||
self.amount_label.configure(text=f"Částka: {ITEMS[item]:.2f} Kč")
|
||
|
||
def generate_qr(self):
|
||
item = self.selected_item.get()
|
||
spayd = create_spayd(IBAN, ITEMS[item], RODCIS, f"{PRIJMENI} {JMENO} – {item}", CURRENCY)
|
||
img = qrcode.make(spayd)
|
||
filename = f"{PRIJMENI}_{JMENO}_{datetime.now():%Y%m%d_%H%M%S}.png"
|
||
out_path = OUTPUT_DIR / filename
|
||
img.save(out_path)
|
||
|
||
img_resized = img.resize((300, 300))
|
||
qr_tk = ImageTk.PhotoImage(img_resized)
|
||
self.qr_label.configure(image=qr_tk)
|
||
self.qr_label.image = qr_tk
|
||
|
||
# 🔄 Adjust window height dynamically
|
||
self.update_idletasks()
|
||
self.geometry(f"{self.winfo_reqwidth()}x{self.winfo_reqheight()}")
|
||
|
||
messagebox.showinfo("QR Platba vytvořena",
|
||
f"Soubor uložen jako:\n{out_path}\n\nSPD řetězec:\n{spayd}")
|
||
|
||
if __name__ == "__main__":
|
||
app = QRPlatbaApp()
|
||
app.mainloop()
|