47c374396d767c47913c7f57ed29ff993b53c9cd
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

1) # -* coding: utf8 *-
2) 
Bernd Wurst Python-3-Migration

Bernd Wurst authored 5 years ago

3) from __future__ import division
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

4) import Invoice
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

5) import re
6) 
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

7) # our page size and margins
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

8) from .metrics import *
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

9) # our custom page style
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

10) from .custom_elements import basicPage, firstPage, address_header
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

11) 
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

12) # reportlab imports
Bernd Wurst GiroCode auf den Rechnungen

Bernd Wurst authored 7 months ago

13) from reportlab.lib.units import cm, inch
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

14) from reportlab.pdfgen import canvas as Canvas
Bernd Wurst Verstecke Bankdaten bei Rec...

Bernd Wurst authored 7 years ago

15) from reportlab.lib.colors import Color
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

16) 
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

17) 
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

18) def _formatPrice(price, symbol='€'):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

19)     '''_formatPrice(price, symbol='€'):
20)     Gets a floating point value and returns a formatted price, suffixed by 'symbol'. '''
21)     s = ("%.2f" % price).replace('.', ',')
22)     pat = re.compile(r'([0-9])([0-9]{3}[.,])')
23)     while pat.search(s):
24)         s = pat.sub(r'\1.\2', s)
25)     return s + ' ' + symbol
26) 
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

27) 
28) def _niceCount(value):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

29)     '''_niceCount(value):
30)     Returns a tuple (integer , decimals) where decimals can be None'''
31)     if type(value) == int:
32)         return ('%i' % value, None)
33)     if round(value, 2) == int(value):
34)         return ('%i' % int(value), None)
35)     s = '%.2f' % value
36)     (integer, decimals) = s.split('.', 1)
37)     if decimals[-1] == '0':
38)         decimals = decimals[:-1]
39)     return (integer, decimals)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

40) 
41) 
42) def _splitToWidth(canvas, text, width, font, size):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

43)     '''_splitToWidth(canvas, text, width, font, size)
44)     Split a string to several lines of a given width.'''
45)     lines = []
46)     paras = text.split('\n')
47)     for para in paras:
48)         words = para.split(' ')
49)         while len(words) > 0:
50)             mywords = [words[0], ]
51)             del words[0]
52)             while len(words) > 0 and canvas.stringWidth(' '.join(mywords) + ' ' + words[0], font, size) <= width:
53)                 mywords.append(words[0])
54)                 del words[0]
55)             lines.append(' '.join(mywords))
56)     return lines
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

57) 
58) 
Bernd Wurst InvoiceText als Blocksatz d...

Bernd Wurst authored 16 years ago

59) def _drawJustifiedString(x, y, text, canvas, width, font, size):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

60)     text = text.strip()
61)     if canvas.stringWidth(text, font, size) > width:
62)         canvas.drawString(x, y, text)
63)         # too long line, I cannot handle this
64)         return
65)     if ' ' not in text:
66)         canvas.drawString(x, y, text)
67)         # no space in there, nothing to justify
68)         return
69) 
70)     words = ['%s' % w for w in text.split(' ')]
71)     words_width = 0.0
72)     for word in words:
73)         words_width += canvas.stringWidth(word, font, size)
74) 
75)     available_space = width - words_width
Bernd Wurst Python-3-Migration

Bernd Wurst authored 5 years ago

76)     available_each = available_space // float((len(words) - 1))
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

77) 
78)     my_x = x
79)     for idx in range(len(words)):
80)         word = words[idx]
81)         canvas.drawString(my_x, y, word)
82)         my_x += canvas.stringWidth(word, font, size) + available_each
Bernd Wurst InvoiceText als Blocksatz d...

Bernd Wurst authored 16 years ago

83)     return
84) 
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

85) 
Bernd Wurst Break long address-lines

Bernd Wurst authored 15 years ago

86) def address(canvas, lines):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

87)     x = 2.0 * cm
88)     y = page_height - 5.0 * cm
89)     canvas.setFont(font, 8)
90)     canvas.drawString(x + 0.5 * cm, y + 0.1 * cm, 'schokokeks.org · Köchersberg 32 · 71540 Murrhardt')
91)     canvas.setLineWidth(1)
92)     canvas.line(x + 0.4 * cm, y, x + address_width, y)
93)     y = y - 0.2 * cm
94) 
95)     line_height = 11 + 0.1 * cm
96)     y -= line_height
97) 
98)     fontsize = 11
99)     for line in lines:
100)         if canvas.stringWidth(line, font, fontsize) > address_width:
101)             # Wenn es in zwei Zeilen passt, dann ist alles okay, ansonsten verkleinern
102)             if len(lines) > 4 or canvas.stringWidth(line, font, fontsize) > 2 * address_width:
103)                 for candidate in [10.5, 10, 9.5, 9, 8.5, 8]:
104)                     fontsize = candidate
105)                     if (len(lines) <= 4 and canvas.stringWidth(line, font, fontsize) <= 2 * address_width) or canvas.stringWidth(line, font, fontsize) <= address_width:
106)                         break
107)     for line in lines:
108)         if canvas.stringWidth(line, font, fontsize) > address_width:
109)             mylines = _splitToWidth(canvas, line, address_width, font, fontsize)
110)             for l in mylines:
111)                 canvas.setFont(font, fontsize)
112)                 canvas.drawString(x + 0.5 * cm, y, l)
113)                 y -= line_height
114)         else:
115)             canvas.setFont(font, fontsize)
116)             canvas.drawString(x + 0.5 * cm, y, line)
117)             y -= line_height
Bernd Wurst Break long address-lines

Bernd Wurst authored 15 years ago

118) 
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

119) 
Bernd Wurst Verstecke Bankdaten bei Rec...

Bernd Wurst authored 7 years ago

120) def InvoiceToPDF(iv, bankdata=True):
Bernd Wurst Python-3-anpassungen

Bernd Wurst authored 5 years ago

121)     from io import BytesIO
122)     fd = BytesIO()
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

123)     canvas = Canvas.Canvas(fd, pagesize=A4)
124) 
125)     if iv.tender:
126)         canvas.setTitle("Angebot von schokokeks.org")
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

127)     else:
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

128)         canvas.setTitle("Rechnung von schokokeks.org")
129) 
130)     canvas.setFont(font, 12)
131) 
Bernd Wurst syntaxfehler behoben und Gu...

Bernd Wurst authored 5 years ago

132)     num_pages = 1
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

133)     # Waehrungssysmbol
134)     symbol = '€'
135)     y = topcontent
136)     font_size = default_font_size
137)     font_height = 0.35 * cm
138)     line_padding = 0.1 * cm
139)     line_height = font_height + 0.1 * cm
140) 
141)     def _partHeight(part):
142)         height = 0
143)         if type(part) == Invoice.Text:
144)             left, right = leftcontent, rightcontent
145)             if part.urgent:
146)                 left += 1.5 * cm
147)                 right -= 1.5 * cm
148)                 height += len(part.paragraphs) * 3 * line_padding
149)                 # Rechne eine Zeile mehr für den Rahmen
150)                 height += line_height
151)             if part.headline:
152)                 height += (len(_splitToWidth(canvas, part.headline, right - left, font + '-Bold', default_font_size + 1)) * line_height) + line_padding
153)             for para in part.paragraphs:
154)                 height += (len(_splitToWidth(canvas, para, right - left, font, default_font_size)) * line_height) + line_padding
155)         elif type(part) == Invoice.Table:
156)             # Eine Zeile plus 2 mal line_padding für Tabellenkopf
157)             height = line_height + 2 * line_padding
158)             # Wenn nur ein Element (plus Summen) hin passt, reicht uns das
159)             el = part.entries[0]
160)             # Die Abstände oben und unten
161)             height += 2 * line_padding
162)             # Die Breite ist konservativ
163)             height += line_height * len(_splitToWidth(canvas, el['subject'], 9.3 * cm, font, font_size))
164)             if 'desc' in el and el['desc'] != '':
165)                 height += line_height * len(_splitToWidth(canvas, el['desc'], 11 * cm, font, font_size))
166)             if part.vatType == 'net':
167)                 # Eine Zeile mehr
168)                 height += line_height + line_padding
169)             # Für die MwSt-Summen
170)             height += (line_height + line_padding) * len(part.vat)
171)             # Für den Rechnungsbetrag
172)             height += line_height + line_padding
173)         return height
174) 
175)     def _tableHead(y):
176)         canvas.setFont(font, font_size)
177)         canvas.drawString(left + (0.1 * cm), y - line_height + line_padding, 'Anz.')
178)         canvas.drawString(left + (2.6 * cm), y - line_height + line_padding, 'Beschreibung')
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

179)         if len(part.vat) == 1:
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

180)             canvas.drawRightString(left + (14.3 * cm), y - line_height + line_padding, 'Einzelpreis')
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

181)         else:
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

182)             canvas.drawRightString(left + (13.7 * cm), y - line_height + line_padding, 'Einzelpreis')
183)         canvas.drawRightString(left + (16.8 * cm), y - line_height + line_padding, 'Gesamtpreis')
184)         canvas.setLineWidth(0.01 * cm)
185)         canvas.line(left, y - line_height, right, y - line_height)
186)         y -= line_height + 0.02 * cm
187)         return y
188) 
189)     def _PageWrap(canvas):
190)         '''Seitenumbruch'''
Bernd Wurst syntaxfehler behoben und Gu...

Bernd Wurst authored 5 years ago

191)         nonlocal num_pages
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

192)         num_pages += 1
193)         canvas.setFont(font, default_font_size - 2)
194)         canvas.drawRightString(rightcontent, bottomcontent + line_padding, 'Fortsetzung auf Seite %i' % num_pages)
195)         canvas.showPage()
196)         basicPage(canvas)
197)         y = topcontent - font_size
198)         canvas.setFillColor((0, 0, 0))
199)         canvas.setFont(font, font_size - 2)
Bernd Wurst Python-3-Migration

Bernd Wurst authored 5 years ago

200)         canvas.drawCentredString(leftcontent + (rightcontent - leftcontent) // 2, y, '- Seite %i -' % num_pages)
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

201) 
202)     address(canvas, iv.addresslines)
203) 
204)     font_size = default_font_size
205)     y = firstPage(canvas)
206)     if not bankdata:
207)         # Bankdaten überschreiben wenn Lastschrift
208)         canvas.setFillColor(Color(255, 255, 255, alpha=0.8))
Bernd Wurst Python-3-Migration

Bernd Wurst authored 5 years ago

209)         canvas.rect(leftcontent + ((rightcontent - leftcontent) // 3) * 2 - 2, bottomcontent - 2, (rightcontent - leftcontent) // 3, -40, fill=True, stroke=False)
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

210)         canvas.setFillColor(Color(0, 0, 0, alpha=1))
211)         canvas.saveState()
Bernd Wurst Python-3-Migration

Bernd Wurst authored 5 years ago

212)         canvas.translate(leftcontent + ((rightcontent - leftcontent) // 3) * 2 + 2, bottomcontent - 40)
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

213)         canvas.rotate(15)
214)         canvas.drawString(0, 0, "Bitte nicht überweisen")
215)         canvas.restoreState()
216)         # canvas.drawString(leftcontent+((rightcontent-leftcontent)/3)*2 + 2, bottomcontent - 20, "Bitte nicht überweisen")
217) 
218)     canvas.setFont(font + '-Bold', font_size + 3)
219)     min_y = y
220)     if iv.caption:
221)         canvas.drawString(leftcontent, y, iv.caption)
222)         min_y -= (font_size + 3) + 0.5 * cm
223) 
224)     if type(iv) == Invoice.Tender:
225)         canvas.setFont(font, font_size)
226)         canvas.drawString(rightcolumn, y, "Erstellungsdatum:")
227)         canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
228)         y -= (font_size + 0.1 * cm)
229)     elif type(iv) == Invoice.Generic:
230)         canvas.setFont(font, font_size)
231)         canvas.drawString(rightcolumn, y, "Datum:")
232)         canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
233)         y -= (font_size + 0.1 * cm)
234)     elif type(iv) == Invoice.Invoice:
235)         canvas.setFont(font + '-Bold', font_size)
236)         canvas.drawString(rightcolumn, y, "Bei Fragen bitte immer angeben:")
237)         y -= (font_size + 0.2 * cm)
238)         canvas.setFont(font, font_size)
239)         canvas.drawString(rightcolumn, y, "Rechnungsdatum:")
240)         canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
241)         y -= (font_size + 0.1 * cm)
242)         canvas.drawString(rightcolumn, y, "Rechnungsnummer:")
243)         canvas.drawRightString(rightcontent, y, "%i" % iv.id)
244)         y -= (font_size + 0.1 * cm)
245)     if iv.customerno:
246)         canvas.drawString(rightcolumn, y, "Kundennummer:")
247)         canvas.drawRightString(rightcontent, y, "%s" % iv.customerno)
248)         y -= (font_size + 0.5 * cm)
249)     canvas.setFont(font, font_size)
250)     y = min(min_y, y)
251) 
252)     if iv.salutation:
253)         canvas.drawString(leftcontent, y, iv.salutation)
254)         y -= font_size + 0.2 * cm
255)         if type(iv) in [Invoice.Tender, Invoice.Invoice]:
256)             introText = 'hiermit stellen wir Ihnen die nachfolgend genannten Leistungen in Rechnung.'
257)             if type(iv) == Invoice.Tender:
258)                 introText = 'hiermit unterbreiten wir Ihnen folgendes Angebot.'
259)             intro = _splitToWidth(canvas, introText, rightcontent - leftcontent, font, font_size)
260)             for line in intro:
261)                 canvas.drawString(leftcontent, y, line)
262)                 y -= font_size + 0.1 * cm
263)             y -= font_size + 0.1 * cm
264) 
265)     font_size = default_font_size
266)     for part in iv.parts:
267)         if y - _partHeight(part) < (bottomcontent + (0.5 * cm)):
268)             _PageWrap(canvas)
269)             y = topcontent - font_size - line_padding * 3
270)         # Debug: Was hat die Höhenbestimmung für diesen Teil als Höhe herausgefunden?
271)         # canvas.line(leftcontent, y-_partHeight(part), rightcontent, y-_partHeight(part))
272) 
273)         if type(part) == Invoice.Table:
274) 
275)             left = leftcontent
276)             right = rightcontent
277)             top = topcontent
278)             bottom = bottomcontent
279)             temp_sum = 0.0
280)             y = _tableHead(y)
281)             odd = True
282)             for el in part.entries:
283)                 subject = []
284)                 if len(part.vat) == 1:
285)                     subject = _splitToWidth(canvas, el['subject'], 10.3 * cm, font, font_size)
286)                 else:
287)                     subject = _splitToWidth(canvas, el['subject'], 9.3 * cm, font, font_size)
288)                 desc = []
289)                 if 'desc' in el and el['desc'] != '':
290)                     desc = _splitToWidth(canvas, el['desc'], 11 * cm, font, font_size)
291)                 need_lines = len(subject) + len(desc)
292) 
293)                 # need page wrap?
294)                 if y - (need_lines + 2 * font_size) < (bottomcontent + 2 * cm):
295)                     canvas.setFont(font, font_size)
296)                     # Zwischensumme
297)                     canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Zwischensumme:')
298)                     canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(temp_sum))
299)                     # page wrap
300)                     _PageWrap(canvas)
301)                     y = topcontent - font_size - line_padding * 3
302)                     # header
303)                     y = _tableHead(y)
304)                     odd = True
305)                     # übertrag
306)                     canvas.setFont(font, font_size)
307)                     canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Übertrag:')
308)                     canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(temp_sum))
309)                     y -= font_height + line_padding
310) 
311)                 # Zwischensumme (inkl. aktueller Posten)
312)                 temp_sum += el['total']
313)                 # draw the background
314)                 if not odd:
315)                     canvas.setFillColorRGB(0.9, 0.9, 0.9)
316)                 else:
317)                     canvas.setFillColorRGB(1, 1, 1)
318)                 canvas.rect(left, y - (need_lines * line_height) - (2 * line_padding), height=(need_lines * line_height) + (2 * line_padding), width=right - left, fill=1, stroke=0)
319)                 canvas.setFillColorRGB(0, 0, 0)
320)                 y -= line_padding
321)                 (integer, decimals) = _niceCount(el['count'])
322)                 canvas.drawRightString(left + 0.8 * cm, y - font_height, integer)
323)                 suffix = ''
324)                 if decimals:
325)                     suffix = ',%s' % decimals
326)                 if el['unit']:
327)                     suffix = suffix + ' ' + el['unit']
328)                 if suffix:
329)                     canvas.drawString(left + 0.8 * cm, y - font_height, '%s' % suffix)
330) 
331)                 if len(part.vat) < 2:
332)                     canvas.drawString(left + 2.7 * cm, y - font_height, subject[0])
333)                     canvas.drawRightString(left + 14.3 * cm, y - font_height, _formatPrice(el['price']))
334)                     if el['tender']:
335)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, 'eventual')
336)                     else:
337)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(el['total']))
338)                     subject = subject[1:]
339)                     x = 1
340)                     for line in subject:
341)                         canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, line)
342)                         x += 1
343)                     for line in desc[:-1]:
344)                         _drawJustifiedString(left + 2.7 * cm, y - (x * line_height) - font_height, line, canvas, 11 * cm, font, font_size)
345)                         x += 1
346)                     canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, desc[-1])
347)                     x += 1
348)                 else:
349)                     canvas.drawString(left + 2.7 * cm, y - font_height, subject[0])
350)                     canvas.drawRightString(left + 13.3 * cm, y - font_height, _formatPrice(el['price']))
351)                     canvas.drawString(left + 13.7 * cm, y - font_height, str(part.vat[el['vat']][1]))
352)                     if el['tender']:
353)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, 'eventual')
354)                     else:
355)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(el['total']))
356)                     subject = subject[1:]
357)                     x = 1
358)                     for line in subject:
359)                         canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, line)
360)                         x += 1
361)                     for line in desc:
362)                         canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, line)
363)                         x += 1
364)                 odd = not odd
365)                 y -= (need_lines * line_height) + line_padding
366)             if part.summary:
367)                 y -= (0.3 * cm)
368)                 if part.vatType == 'gross':
369)                     summaries = []
370)                     if len(part.vat) == 1:
371)                         vat = list(part.vat.keys())[0]
372)                         (integer, decimals) = _niceCount((vat * 100))
373)                         vatstr = '%s' % integer
374)                         if decimals:
375)                             vatstr += ',%s' % decimals
376)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Nettobetrag:')
377)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(part.sum - (part.sum / (vat + 1)) * vat))
378)                         y -= line_height
379)                         summaries.append(('%s%% MwSt:' % vatstr, _formatPrice((part.sum / (vat + 1)) * vat)))
380)                     else:
381)                         net = 0.0
Bernd Wurst Python-3-Migration

Bernd Wurst authored 5 years ago

382)                         for vat, vatdata in list(part.vat.items()):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

383)                             (integer, decimals) = _niceCount((vat * 100))
384)                             vatstr = '%s' % integer
385)                             if decimals:
386)                                 vatstr += ',%s' % decimals
Bernd Wurst Details beim Rechnungssystem

Bernd Wurst authored 3 years ago

387)                             _gross = vatdata[0]
388)                             _net = _gross / (1+vat)
389)                             _vat = _net * vat
390)                             summaries.append(('%s: Teilbetrag %s: Nettobetrag %s zzgl. %s%% MwSt:' % (vatdata[1], _formatPrice(_gross), _formatPrice(_net), vatstr), _formatPrice(_vat)))
391)                             net += _net
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

392)                         summaries.append(('Nettobetrag gesamt:', _formatPrice(net)))
393)                     summaries.sort()
394)                     for line in summaries:
395)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, line[0])
396)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, line[1])
397)                         y -= line_height
398)                     canvas.setFont(font + '-Bold', font_size)
399)                     if iv.tender:
400)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Gesamtbetrag:')
401)                     else:
402)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Rechnungsbetrag:')
403)                     canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(part.sum))
404)                     canvas.setFont(font, font_size)
405)                     y -= line_height + line_padding
406)                 else:
407)                     canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Nettobetrag:')
408)                     canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(part.sum))
409)                     y -= line_height
410)                     summaries = []
411)                     if len(part.vat) == 1:
412)                         vat = list(part.vat.keys())[0]
413)                         (integer, decimals) = _niceCount((vat * 100))
414)                         vatstr = '%s' % integer
415)                         if decimals:
416)                             vatstr += ',%s' % decimals
417)                         summaries.append(('zzgl. %s%% MwSt:' % vatstr, _formatPrice(vat * part.sum)))
418)                     elif len(part.vat) > 1:
Bernd Wurst Python-3-Migration

Bernd Wurst authored 5 years ago

419)                         for vat, vatdata in list(part.vat.items()):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

420)                             (integer, decimals) = _niceCount((vat * 100))
421)                             vatstr = '%s' % integer
422)                             if decimals:
423)                                 vatstr += ',%s' % decimals
424)                             summaries.append(('zzgl. %s%% MwSt (%s):' % (vatstr, vatdata[1]), _formatPrice(vat * vatdata[0])))
425)                     summaries.sort()
426)                     for line in summaries:
427)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, line[0])
428)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, line[1])
429)                         y -= line_height
430)                     sum = part.sum
Bernd Wurst Python-3-Migration

Bernd Wurst authored 5 years ago

431)                     for vat, vatdata in list(part.vat.items()):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

432)                         sum += vat * vatdata[0]
433)                     canvas.setFont(font + '-Bold', font_size)
434)                     if iv.tender:
435)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Gesamtbetrag:')
436)                     else:
437)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Rechnungsbetrag:')
438)                     canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(sum))
439)                     canvas.setFont(font, font_size)
440)                     y -= line_height + line_padding
441)         elif type(part) == Invoice.Text:
442)             my_font_size = font_size
443)             canvas.setFont(font, my_font_size)
444)             left, right = leftcontent, rightcontent
445)             firsttime = True
446)             headlines = []
447)             if part.urgent:
448)                 left += 1.5 * cm
449)                 right -= 1.5 * cm
450)             if part.headline:
451)                 headlines = _splitToWidth(canvas, part.headline, right - left, font, my_font_size)
452)             for para in part.paragraphs:
453)                 lines = _splitToWidth(canvas, para, right - left, font, my_font_size)
454)                 if part.urgent:
455)                     need_height = len(lines) * line_height
456)                     if len(headlines) > 0:
457)                         need_height += len(headlines) * (line_height + 1) + line_padding
458)                     canvas.setFillColorRGB(0.95, 0.95, 0.95)
459)                     canvas.rect(left - 0.5 * cm, y - (need_height + (6 * line_padding)), height=need_height + (6 * line_padding), width=right - left + 1 * cm, fill=1, stroke=1)
460)                     canvas.setFillColorRGB(0, 0, 0)
461)                     y -= line_padding * 3
462)                 if part.headline and firsttime:
463)                     firsttime = False
464)                     canvas.setFont(font + '-Bold', my_font_size + 1)
465)                     for line in headlines:
466)                         canvas.drawString(left, y - (font_height + 1), line)
467)                         y -= line_height + 1
468)                     y -= line_padding
469)                     canvas.setFont(font, my_font_size)
470)                 for line in lines[:-1]:
471)                     _drawJustifiedString(left, y - font_height, line, canvas, right - left, font, my_font_size)
472)                     y -= line_height
473)                 canvas.drawString(left, y - font_height, lines[-1])
474)                 y -= line_height
475) 
476)                 y -= line_padding * 3
477)             left, right = leftcontent, rightcontent
Bernd Wurst GiroCode auf den Rechnungen

Bernd Wurst authored 7 months ago

478)         elif type(part) == Invoice.Image:
479)             width = (part.imagedata.width / part.dpi) * inch
480)             height = width * (part.imagedata.height / part.imagedata.width)
481)             x = leftcontent
482)             if part.alignment == "center":
483)                 x = leftcontent + (rightcontent - leftcontent)/2 - width/2
484)             elif part.alignment == "right":
485)                 x = rightcontent - width
486)             canvas.drawInlineImage(part.imagedata, x, y-height, width=width, height=height)
487)             y -= line_padding + height
488)             if part.caption:
489)                 canvas.drawString(x, y-font_height, part.caption)
490)                 y -= line_height
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

491)         else:
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

492)             raise NotImplementedError("Cannot handle part of type %s" % type(part))
493)         y -= (0.5 * cm)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

494)