]> wagnertech.de Git - SVBaL.git/blobdiff - python/eh_util/eh_app/AWK/routines.py
Merge remote-tracking branch 'origin/kassenschreiben2025' into simon
[SVBaL.git] / python / eh_util / eh_app / AWK / routines.py
index ba362a0dcf0b357d067aa8af830b644d85738644..4a98c0ebdae4e1faa59023bf2a509cdb84afedea 100644 (file)
@@ -1,4 +1,5 @@
 import os
+from eh_app.AWK import config
 '''
 def handle_uploaded_file(csv_file):
     csv_file_name = str(csv_file)
@@ -8,24 +9,88 @@ def handle_uploaded_file(csv_file):
         for chunk in csv_file.chunks():
             destination.write(chunk)
 '''
-def aktualisiere_config(config, data):
-    if data["briefpapier"]:
-        uploaded_file = data["briefpapier"]
+def aktualisiere_config(config, data, file):
+
+    if file:
+        uploaded_file = file.name
         data_path = config.requireConfig("data_path")
         # copy briefpapier into data_path
-        with open(os.path.join(data_path, uploaded_file.name), 'wb+') as destination:
-            for chunk in uploaded_file.chunks():
+        with open(os.path.join(data_path, uploaded_file), 'wb+') as destination:
+            for chunk in file.chunks():
                 destination.write(chunk)
-        config.set_config("briefpapier", uploaded_file.name)
-    
+        config.setConfig("briefpapier", uploaded_file)
+
     if data["basisbeitrag"]:
-        config.set_config("beitrag_basis", data["basisbeitrag"])
-        
+        config.setConfig("beitrag_basis", data["basisbeitrag"])
+
     if data["zusatzbeitrag"]:
-        config.set_config("beitrag_zusatz", data["zusatzbeitrag"])
+        config.setConfig("beitrag_zusatz", data["zusatzbeitrag"])
+    
+def erstelle_ehmeldung(data):
+    from PyPDF2 import PdfFileWriter, PdfFileReader
+    from datetime import date
+    import io
+    from reportlab.pdfgen import canvas
+    from reportlab.lib.pagesizes import letter
     
-def erstellepdf(text):
-    with open(r'G:\SVBaL\python\eh_util\eh_app\test.tex', 'w') as f: # öffnet ein neues Dokument mit dem Namen test.tex
-        f.write(text) # schreibt in dieses neue Dokument
+    packet = io.BytesIO()
+    can = canvas.Canvas(packet, pagesize=letter)
+    
+    # Adressfeld
+    can.setFont("Helvetica", 12)
+    can.drawString(205, 618, data["VorZuname"])
+    can.drawString(205, 600, data["VorZunamePartner"])
+    can.drawString(205, 583, data["Wohnanschrift"])
+    can.drawString(205, 566, data["Telefon"])
+    can.drawString(365, 566, data["Email"])
+    can.drawString(205, 549, data["Geburtsdatum"])
+    versichertes_object = data["VersichertesObjekt"]
+    if versichertes_object == "":
+        versichertes_object = data["Wohnanschrift"]
+    can.drawString(205, 500, versichertes_object)
+    can.drawString(193, 466, str(data["AnzahlWohnungen"]))
+    if data["Selbstgenutzt"]:
+        can.drawString(350, 466, "X")
+    if data["Eigentumswohnung"]:
+        can.drawString(188, 449, "X")
+    if data["Gewerblich"]:
+        can.drawString(350, 449, "X")
+    can.drawString(140, 376, date.today().strftime('%d.%m.%Y'))
+    can.drawString(350, 376, "Maschinell erstellt.")
         
-    # TODO: AUfruf PDF latex tex -> pdf
+    can.save()
+    
+    #move to the beginning of the StringIO buffer
+    packet.seek(0)
+    
+    # create a new PDF with Reportlab
+    new_pdf = PdfFileReader(packet)
+    # read your existing PDF
+    existing_pdf = PdfFileReader(open("/home/sparky2021/SVBaL/Aktuell/BeitrittserklarungSVBaL.pdf", "rb"))
+    output = PdfFileWriter()
+    # add the "watermark" (which is the new pdf) on the existing page
+    page = existing_pdf.pages[0]
+    page.mergePage(new_pdf.pages[0])
+    output.addPage(page)
+    # finally, write "output" to a real file
+    output_stream = open("meldung.pdf", "wb")
+    output.write(output_stream)
+    output_stream.close()
+      
+def pdfs_erstellen(request, verein):
+    from django.template import loader
+    
+    # lese alle Miglieder
+    cf = config.getInstance("svbal")
+    cf.setConfig("DataFile", "../../Test/etc/Export.csv")
+    from eh_app.qmodels import Mitglied
+    mm = Mitglied.objects.all()
+    template = loader.get_template("brief.tex")
+    
+    from eh_app.AWK.pdf_ersteller import PdfErsteller
+    pe = PdfErsteller(request, template, "../../latex")
+    
+    # Erstelle PDFs
+    for m in mm:
+        pe.erstellepdf(m)
+