|
@@ -0,0 +1,83 @@
|
|
|
|
|
+import os
|
|
|
|
|
+from fpdf import FPDF
|
|
|
|
|
+import config
|
|
|
|
|
+
|
|
|
|
|
+def generate_uplatnica(order_id: int, payer_name: str, payer_address: str, amount: float) -> str:
|
|
|
|
|
+ """
|
|
|
|
|
+ Generate a simple PDF 'Nalog za uplatu' (Uplatnica) for Montenegro.
|
|
|
|
|
+ Returns the absolute path to the generated PDF.
|
|
|
|
|
+ """
|
|
|
|
|
+ pdf = FPDF(orientation='L', unit='mm', format=(100, 210))
|
|
|
|
|
+ pdf.add_page()
|
|
|
|
|
+
|
|
|
|
|
+ # We will just use the default Helvetica or Arial
|
|
|
|
|
+ pdf.set_font("helvetica", 'B', 12)
|
|
|
|
|
+
|
|
|
|
|
+ # Draw simple border
|
|
|
|
|
+ pdf.rect(5, 5, 200, 90)
|
|
|
|
|
+
|
|
|
|
|
+ # Title
|
|
|
|
|
+ pdf.set_y(10)
|
|
|
|
|
+ pdf.set_font("helvetica", 'B', 14)
|
|
|
|
|
+ pdf.cell(0, 10, "NALOG ZA UPLATU", align="C")
|
|
|
|
|
+
|
|
|
|
|
+ pdf.set_font("helvetica", '', 10)
|
|
|
|
|
+
|
|
|
|
|
+ # Payer Info (Uplatilac)
|
|
|
|
|
+ pdf.set_xy(10, 25)
|
|
|
|
|
+ pdf.cell(40, 5, "UPLATILAC:")
|
|
|
|
|
+ pdf.set_xy(10, 30)
|
|
|
|
|
+ pdf.set_font("helvetica", 'B', 10)
|
|
|
|
|
+ pdf.multi_cell(80, 5, f"{payer_name}\n{payer_address}")
|
|
|
|
|
+ pdf.set_font("helvetica", '', 10)
|
|
|
|
|
+
|
|
|
|
|
+ # Purpose (Svrha uplate)
|
|
|
|
|
+ pdf.set_xy(10, 50)
|
|
|
|
|
+ pdf.cell(40, 5, "SVRHA UPLATE:")
|
|
|
|
|
+ pdf.set_xy(10, 55)
|
|
|
|
|
+ pdf.set_font("helvetica", 'B', 10)
|
|
|
|
|
+ pdf.multi_cell(80, 5, f"Placanje za 3D stampu - Narudzba #{order_id}")
|
|
|
|
|
+ pdf.set_font("helvetica", '', 10)
|
|
|
|
|
+
|
|
|
|
|
+ # Recipient (Primalac)
|
|
|
|
|
+ pdf.set_xy(10, 75)
|
|
|
|
|
+ pdf.cell(40, 5, "PRIMALAC:")
|
|
|
|
|
+ pdf.set_xy(10, 80)
|
|
|
|
|
+ pdf.set_font("helvetica", 'B', 10)
|
|
|
|
|
+ pdf.multi_cell(80, 5, config.COMPANY_NAME)
|
|
|
|
|
+ pdf.set_font("helvetica", '', 10)
|
|
|
|
|
+
|
|
|
|
|
+ # Right column
|
|
|
|
|
+ # Amount
|
|
|
|
|
+ pdf.set_xy(100, 25)
|
|
|
|
|
+ pdf.cell(40, 5, "IZNOS (EUR):")
|
|
|
|
|
+ pdf.set_xy(140, 23)
|
|
|
|
|
+ pdf.set_font("helvetica", 'B', 14)
|
|
|
|
|
+ pdf.cell(40, 8, f"={amount:.2f}", border=1, align="C")
|
|
|
|
|
+ pdf.set_font("helvetica", '', 10)
|
|
|
|
|
+
|
|
|
|
|
+ # Account
|
|
|
|
|
+ pdf.set_xy(100, 40)
|
|
|
|
|
+ pdf.cell(40, 5, "RACUN PRIMAOCA:")
|
|
|
|
|
+ pdf.set_xy(140, 38)
|
|
|
|
|
+ pdf.set_font("helvetica", 'B', 12)
|
|
|
|
|
+ pdf.cell(60, 8, config.ZIRO_RACUN, border=1, align="C")
|
|
|
|
|
+ pdf.set_font("helvetica", '', 10)
|
|
|
|
|
+
|
|
|
|
|
+ # Reference
|
|
|
|
|
+ pdf.set_xy(100, 55)
|
|
|
|
|
+ pdf.cell(40, 5, "POZIV NA BROJ:")
|
|
|
|
|
+ pdf.set_xy(140, 53)
|
|
|
|
|
+ pdf.set_font("helvetica", 'B', 12)
|
|
|
|
|
+ pdf.cell(60, 8, str(order_id), border=1, align="C")
|
|
|
|
|
+
|
|
|
|
|
+ # Save file
|
|
|
|
|
+ pdf_dir = os.path.join(config.UPLOAD_DIR, "invoices")
|
|
|
|
|
+ if not os.path.exists(pdf_dir):
|
|
|
|
|
+ os.makedirs(pdf_dir)
|
|
|
|
|
+
|
|
|
|
|
+ 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("\\", "/")
|