| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import os
- from fpdf import FPDF
- import config
- from fpdf import FPDF
- import os
- import config
- def format_amount(amount):
- return f"{amount:.2f}".replace(".", ",")
- def generate_uplatnica(order_id, payer_name, payer_address, amount):
- pdf = FPDF(orientation='P', unit='mm', format='A4')
- pdf.set_auto_page_break(False)
- pdf.add_page()
- pdf.set_font("helvetica", size=7)
- # === UPLATNICA AREA (top of A4) ===
- pdf.rect(0, 0, 210, 99)
- # Vertical divider
- pdf.line(105, 0, 105, 99)
- # ===== TOP OPTIONS =====
- labels = ["Hitnost", "Prenos", "Uplata", "Isplata"]
- start_x = 110
- step = 22
- for i, label in enumerate(labels):
- x = start_x + i * step
- pdf.set_xy(x, 2)
- pdf.cell(14, 4, label)
- pdf.rect(x + 14, 2, 4, 4)
- if label == "Uplata":
- pdf.line(x + 14, 2, x + 18, 6)
- pdf.line(x + 18, 2, x + 14, 6)
- # ===== LEFT =====
- pdf.set_font("helvetica", "B", 8)
- pdf.set_xy(5, 5)
- pdf.cell(95, 5, "NALOG PLATIOCA", align="C")
- pdf.rect(5, 12, 95, 14)
- pdf.set_font("helvetica", size=9)
- pdf.set_xy(7, 14)
- pdf.cell(90, 4, payer_name[:40])
- pdf.set_xy(7, 18)
- pdf.cell(90, 4, payer_address[:40])
- pdf.set_font("helvetica", size=6)
- pdf.set_xy(5, 26)
- pdf.cell(95, 4, "(Naziv platioca)", align="C")
- pdf.rect(5, 30, 95, 14)
- pdf.set_font("helvetica", size=9)
- pdf.set_xy(7, 32)
- pdf.cell(90, 4, "Usluge 3D stampe")
- pdf.set_xy(7, 36)
- pdf.cell(90, 4, f"Narudzba {order_id}")
- pdf.set_font("helvetica", size=6)
- pdf.set_xy(5, 44)
- pdf.cell(95, 4, "(Svrha placanja)", align="C")
- pdf.rect(5, 48, 95, 14)
- pdf.set_font("helvetica", size=9)
- pdf.set_xy(7, 50)
- pdf.cell(90, 4, config.COMPANY_NAME[:40])
- pdf.set_font("helvetica", size=6)
- pdf.set_xy(5, 62)
- pdf.cell(95, 4, "(Naziv primaoca)", align="C")
- pdf.line(5, 90, 100, 90)
- pdf.set_xy(5, 90)
- pdf.cell(95, 4, "(Potpis platioca)", align="C")
- # ===== RIGHT =====
- pdf.rect(110, 12, 95, 8)
- pdf.set_font("helvetica", size=7)
- pdf.set_xy(110, 22)
- pdf.cell(10, 4, "EUR")
- pdf.rect(120, 22, 50, 10)
- pdf.rect(175, 22, 30, 10)
- pdf.set_font("helvetica", "B", 11)
- pdf.set_xy(120, 24)
- pdf.cell(50, 6, format_amount(amount), align="C")
- pdf.set_xy(175, 24)
- pdf.cell(30, 6, "121", align="C")
- pdf.set_font("helvetica", size=6)
- pdf.set_xy(120, 32)
- pdf.cell(50, 4, "(Iznos)", align="C")
- pdf.set_xy(175, 32)
- pdf.cell(30, 4, "(Sifra)", align="C")
- pdf.rect(110, 36, 95, 10)
- pdf.set_font("helvetica", size=10)
- pdf.set_xy(110, 38)
- pdf.cell(95, 6, config.ZIRO_RACUN, align="C")
- pdf.rect(110, 50, 20, 8)
- pdf.rect(135, 50, 70, 8)
- pdf.set_xy(110, 52)
- pdf.cell(20, 4, "00", align="C")
- pdf.set_xy(135, 52)
- pdf.cell(70, 4, str(order_id), align="C")
- pdf.line(110, 90, 205, 90)
- pdf.set_xy(110, 90)
- pdf.cell(95, 4, "(Potpis primaoca)", align="C")
- # ===== SAVE =====
- pdf_dir = os.path.join(config.UPLOAD_DIR, "invoices")
- os.makedirs(pdf_dir, exist_ok=True)
- filename = f"uplatnica_order_{order_id}.pdf"
- filepath = os.path.join(pdf_dir, filename)
- pdf.output(filepath)
- return os.path.join("uploads", "invoices", filename).replace("\\", "/")
|