]> wagnertech.de Git - SVBaL.git/blob - 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
1 import os
2 from eh_app.AWK import config
3 '''
4 def handle_uploaded_file(csv_file):
5     csv_file_name = str(csv_file)
6     data_path = config.getInstance().requireConfig("data_path")
7     path = os.path.join(data_path, csv_file_name)
8     with open(path, 'wb+') as destination:
9         for chunk in csv_file.chunks():
10             destination.write(chunk)
11 '''
12 def aktualisiere_config(config, data, file):
13
14     if file:
15         uploaded_file = file.name
16         data_path = config.requireConfig("data_path")
17         # copy briefpapier into data_path
18         with open(os.path.join(data_path, uploaded_file), 'wb+') as destination:
19             for chunk in file.chunks():
20                 destination.write(chunk)
21         config.setConfig("briefpapier", uploaded_file)
22
23     if data["basisbeitrag"]:
24         config.setConfig("beitrag_basis", data["basisbeitrag"])
25
26     if data["zusatzbeitrag"]:
27         config.setConfig("beitrag_zusatz", data["zusatzbeitrag"])
28     
29 def erstelle_ehmeldung(data):
30     from PyPDF2 import PdfFileWriter, PdfFileReader
31     from datetime import date
32     import io
33     from reportlab.pdfgen import canvas
34     from reportlab.lib.pagesizes import letter
35     
36     packet = io.BytesIO()
37     can = canvas.Canvas(packet, pagesize=letter)
38     
39     # Adressfeld
40     can.setFont("Helvetica", 12)
41     can.drawString(205, 618, data["VorZuname"])
42     can.drawString(205, 600, data["VorZunamePartner"])
43     can.drawString(205, 583, data["Wohnanschrift"])
44     can.drawString(205, 566, data["Telefon"])
45     can.drawString(365, 566, data["Email"])
46     can.drawString(205, 549, data["Geburtsdatum"])
47     versichertes_object = data["VersichertesObjekt"]
48     if versichertes_object == "":
49         versichertes_object = data["Wohnanschrift"]
50     can.drawString(205, 500, versichertes_object)
51     can.drawString(193, 466, str(data["AnzahlWohnungen"]))
52     if data["Selbstgenutzt"]:
53         can.drawString(350, 466, "X")
54     if data["Eigentumswohnung"]:
55         can.drawString(188, 449, "X")
56     if data["Gewerblich"]:
57         can.drawString(350, 449, "X")
58     can.drawString(140, 376, date.today().strftime('%d.%m.%Y'))
59     can.drawString(350, 376, "Maschinell erstellt.")
60         
61     can.save()
62     
63     #move to the beginning of the StringIO buffer
64     packet.seek(0)
65     
66     # create a new PDF with Reportlab
67     new_pdf = PdfFileReader(packet)
68     # read your existing PDF
69     existing_pdf = PdfFileReader(open("/home/sparky2021/SVBaL/Aktuell/BeitrittserklarungSVBaL.pdf", "rb"))
70     output = PdfFileWriter()
71     # add the "watermark" (which is the new pdf) on the existing page
72     page = existing_pdf.pages[0]
73     page.mergePage(new_pdf.pages[0])
74     output.addPage(page)
75     # finally, write "output" to a real file
76     output_stream = open("meldung.pdf", "wb")
77     output.write(output_stream)
78     output_stream.close()
79       
80 def pdfs_erstellen(request, verein):
81     from django.template import loader
82     
83     # lese alle Miglieder
84     cf = config.getInstance("svbal")
85     cf.setConfig("DataFile", "../../Test/etc/Export.csv")
86     from eh_app.qmodels import Mitglied
87     mm = Mitglied.objects.all()
88     template = loader.get_template("brief.tex")
89     
90     from eh_app.AWK.pdf_ersteller import PdfErsteller
91     pe = PdfErsteller(request, template, "../../latex")
92     
93     # Erstelle PDFs
94     for m in mm:
95         pe.erstellepdf(m)
96