655d7ab678d93abcdfb7d9457798337043cbf06d
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

1) # -* coding: utf8 *-
2) 
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

6) # our page size and margins
7) from metrics import *
8) # our custom page style
Bernd Wurst Break long address-lines

Bernd Wurst authored 15 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

11) # reportlab imports
12) from reportlab.lib.units import cm
13) from reportlab.pdfgen import canvas as Canvas
14) 
15) 
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

16) num_pages = 1
17) 
18) 
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

19) def _formatPrice(price, symbol='€'):
20)   '''_formatPrice(price, symbol='€'):
21)   Gets a floating point value and returns a formatted price, suffixed by 'symbol'. '''
22)   s = ("%.2f" % price).replace('.', ',')
23)   pat = re.compile(r'([0-9])([0-9]{3}[.,])')
24)   while pat.search(s):
25)     s = pat.sub(r'\1.\2', s)
26)   return s+' '+symbol
27) 
28) def _niceCount(value):
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)
40) 
41) 
42) def _splitToWidth(canvas, text, width, font, size):
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
57) 
58) 
Bernd Wurst InvoiceText als Blocksatz d...

Bernd Wurst authored 16 years ago

59) def _drawJustifiedString(x, y, text, canvas, width, font, size):
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
76)   available_each = available_space / float((len(words) - 1))
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
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):
87)   x = 2.0 * cm
88)   y = page_height - 5.0*cm
89)   canvas.setFont(font, 8)
Bernd Wurst Änderung der Adresse und al...

Bernd Wurst authored 7 years ago

90)   canvas.drawString(x+0.5*cm, y+0.1*cm, 'schokokeks.org · Köchersberg 32 · 71540 Murrhardt')
Bernd Wurst Break long address-lines

Bernd Wurst authored 15 years ago

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
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

97) 
98)   fontsize = 11
Bernd Wurst Break long address-lines

Bernd Wurst authored 15 years ago

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
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

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:
Bernd Wurst Break long address-lines

Bernd Wurst authored 15 years ago

106)             break
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

107)   for line in lines:
108)     if canvas.stringWidth(line, font, fontsize) > address_width:
Bernd Wurst Break long address-lines

Bernd Wurst authored 15 years ago

109)       mylines = _splitToWidth(canvas, line, address_width, font, fontsize)
110)       for l in mylines:
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

111)   	canvas.setFont(font, fontsize)
Bernd Wurst Break long address-lines

Bernd Wurst authored 15 years ago

112)         canvas.drawString(x+0.5*cm, y, l)
113)         y -= line_height
114)     else:
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

115)       canvas.setFont(font, fontsize)
Bernd Wurst Break long address-lines

Bernd Wurst authored 15 years ago

116)       canvas.drawString(x+0.5*cm, y, line)
117)       y -= line_height
118) 
119) 
120) 
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

121) 
122) def InvoiceToPDF(iv):
123)   from StringIO import StringIO
124)   fd = StringIO()
125)   canvas = Canvas.Canvas(fd, pagesize=A4)
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

126)   
Bernd Wurst Setze PDF-Dokument-Titel

Bernd Wurst authored 14 years ago

127)   if iv.tender:
128)     canvas.setTitle("Angebot von schokokeks.org")
129)   else:
130)     canvas.setTitle("Rechnung von schokokeks.org")
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

132)   canvas.setFont(font, 12)
133) 
134) 
135)   # Waehrungssysmbol
136)   symbol = '€'
137)   y = topcontent
138)   font_size = default_font_size
139)   font_height = 0.35*cm
140)   line_padding = 0.1*cm
141)   line_height = font_height+0.1*cm
142) 
143)   def _partHeight(part):
144)     height = 0
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

145)     if type(part) == Invoice.Text:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

146)       left, right = leftcontent, rightcontent
147)       if part.urgent:
148)         left += 1.5*cm
149)         right -= 1.5*cm
150)         height += len(part.paragraphs) * 3 * line_padding
Bernd Wurst Höhen noch genauer approxim...

Bernd Wurst authored 15 years ago

151)         # Rechne eine Zeile mehr für den Rahmen
152)         height += line_height
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

153)       if part.headline:
154)         height += (len(_splitToWidth(canvas, part.headline, right-left, font+'-Bold', default_font_size+1)) * line_height) + line_padding
155)       for para in part.paragraphs:  
156)         height += (len(_splitToWidth(canvas, para, right-left, font, default_font_size)) * line_height) + line_padding
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

157)     elif type(part) == Invoice.Table:
Bernd Wurst Höhen noch genauer approxim...

Bernd Wurst authored 15 years ago

158)       # Eine Zeile plus 2 mal line_padding für Tabellenkopf
159)       height = line_height + 2 * line_padding
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

160)       # Wenn nur ein Element (plus Summen) hin passt, reicht uns das
161)       el = part.entries[0]
162)       # Die Abstände oben und unten
163)       height += 2 * line_padding
164)       # Die Breite ist konservativ
165)       height += line_height*len(_splitToWidth(canvas, el['subject'], 9.3*cm, font, font_size))
166)       if 'desc' in el and el['desc'] != '':
167)         height += line_height * len(_splitToWidth(canvas, el['desc'], 11*cm, font, font_size))
Bernd Wurst Höhen noch genauer approxim...

Bernd Wurst authored 15 years ago

168)       if part.vatType == 'net':
169)         # Eine Zeile mehr
170)         height += line_height + line_padding
171)       # Für die MwSt-Summen
172)       height += (line_height + line_padding) * len(part.vat)
173)       # Für den Rechnungsbetrag
174)       height += line_height + line_padding
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

175)     return height
176) 
177) 
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

178)   def _tableHead(y):
179)     canvas.setFont(font, font_size)
180)     canvas.drawString(left+(0.1*cm), y-line_height+line_padding, 'Anz.')
181)     canvas.drawString(left+(2.6*cm), y-line_height+line_padding, 'Beschreibung')
182)     if len(part.vat) == 1:
183)       canvas.drawRightString(left+(14.3*cm), y-line_height+line_padding, 'Einzelpreis')
184)     else:
185)       canvas.drawRightString(left+(13.7*cm), y-line_height+line_padding, 'Einzelpreis')
186)     canvas.drawRightString(left+(16.8*cm), y-line_height+line_padding, 'Gesamtpreis')
187)     canvas.setLineWidth(0.01*cm)
188)     canvas.line(left, y - line_height, right, y - line_height)
189)     y -= line_height + 0.02*cm
190)     return y
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

191)    
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

192)   def _PageWrap(canvas):
193)     '''Seitenumbruch'''
194)     global num_pages
195)     num_pages += 1
196)     canvas.setFont(font, default_font_size-2)
197)     canvas.drawRightString(rightcontent, bottomcontent + line_padding, 'Fortsetzung auf Seite %i' % num_pages)
198)     canvas.showPage()
199)     basicPage(canvas)
200)     y = topcontent - font_size
201)     canvas.setFillColor((0,0,0))
202)     canvas.setFont(font, font_size-2)
203)     canvas.drawCentredString(leftcontent + (rightcontent - leftcontent) / 2, y, '- Seite %i -' % num_pages)
204) 
205) 
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

206)   address(canvas, iv.addresslines)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

207) 
208)   font_size = default_font_size
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

209)   y = firstPage(canvas)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

210) 
211)   canvas.setFont(font+'-Bold', font_size+3)
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

212)   min_y = y
213)   if iv.caption:
214)     canvas.drawString(leftcontent, y, iv.caption)
215)     min_y -= (font_size + 3) + 0.5*cm
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

216) 
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

217)   if type(iv) == Invoice.Tender:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

218)     canvas.setFont(font, font_size)
219)     canvas.drawString(rightcolumn, y, "Erstellungsdatum:")
220)     canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
221)     y -= (font_size + 0.1*cm)
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

222)   elif type(iv) == Invoice.Generic:
223)     canvas.setFont(font, font_size)
224)     canvas.drawString(rightcolumn, y, "Datum:")
225)     canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
226)     y -= (font_size + 0.1*cm)
227)   elif type(iv) == Invoice.Invoice:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

228)     canvas.setFont(font+'-Bold', font_size)
229)     canvas.drawString(rightcolumn, y, "Bei Fragen bitte immer angeben:")
230)     y -= (font_size + 0.2*cm)
231)     canvas.setFont(font, font_size)
232)     canvas.drawString(rightcolumn, y, "Rechnungsdatum:")
233)     canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
234)     y -= (font_size + 0.1*cm)
235)     canvas.drawString(rightcolumn, y, "Rechnungsnummer:")
236)     canvas.drawRightString(rightcontent, y, "%i" % iv.id)
237)     y -= (font_size + 0.1*cm)
238)   if iv.customerno:
239)     canvas.drawString(rightcolumn, y, "Kundennummer:")
240)     canvas.drawRightString(rightcontent, y, "%s" % iv.customerno)
241)     y -= (font_size + 0.5*cm)
242)   canvas.setFont(font, font_size)
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

243)   y = min(min_y, y)
244) 
245)   if iv.salutation:
246)     canvas.drawString(leftcontent, y, iv.salutation)
247)     y -= font_size + 0.2*cm
248)     if type(iv) in [Invoice.Tender, Invoice.Invoice]:
249)       introText = 'hiermit stellen wir Ihnen die nachfolgend genannten Leistungen in Rechnung.'
250)       if type(iv) == Invoice.Tender:
251)         introText = 'hiermit unterbreiten wir Ihnen folgendes Angebot.'
252)       intro = _splitToWidth(canvas, introText, rightcontent - leftcontent, font, font_size)
253)       for line in intro:
254)         canvas.drawString(leftcontent, y, line)
255)         y -= font_size + 0.1*cm
256)       y -= font_size + 0.1*cm
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

257) 
258)   font_size = default_font_size
259)   for part in iv.parts:
260)     if y - _partHeight(part) < (bottomcontent + (0.5*cm)):
261)       _PageWrap(canvas)
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

262)       y = topcontent - font_size - line_padding*3
Bernd Wurst Höhen noch genauer approxim...

Bernd Wurst authored 15 years ago

263)     # Debug: Was hat die Höhenbestimmung für diesen Teil als Höhe herausgefunden?
264)     #canvas.line(leftcontent, y-_partHeight(part), rightcontent, y-_partHeight(part))
265) 
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

266)     if type(part) == Invoice.Table:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

267)         
268)       left = leftcontent
269)       right = rightcontent
270)       top = topcontent
271)       bottom = bottomcontent
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

272)       temp_sum = 0.0
273)       y = _tableHead(y)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

274)       odd=True
275)       for el in part.entries:
276)         subject = []
277)         if len(part.vat) == 1:
278)           subject = _splitToWidth(canvas, el['subject'], 10.3*cm, font, font_size)
279)         else:
280)           subject = _splitToWidth(canvas, el['subject'], 9.3*cm, font, font_size)
281)         desc = []
282)         if 'desc' in el and el['desc'] != '':
Bernd Wurst Blocksatz auch für Beschrei...

Bernd Wurst authored 16 years ago

283)           desc = _splitToWidth(canvas, el['desc'], 11*cm, font, font_size)
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

284)         need_lines = len(subject) + len(desc)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

285) 
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

286) 	# need page wrap?
287)       	if y - (need_lines+2 * font_size) < (bottomcontent + 2*cm):
288)           canvas.setFont(font, font_size)
289) 	  # Zwischensumme
290)           canvas.drawRightString(left + 14.5*cm, y-font_height, 'Zwischensumme:')
291)           canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(temp_sum))
292) 	  # page wrap
293) 	  _PageWrap(canvas)
294)           y = topcontent - font_size - line_padding*3
295) 	  # header
296) 	  y = _tableHead(y)
297)           odd=True
298) 	  # übertrag
299)           canvas.setFont(font, font_size)
300)           canvas.drawRightString(left + 14.5*cm, y-font_height, 'Übertrag:')
301)           canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(temp_sum))
302) 	  y -= font_height + line_padding
303) 
304) 	# Zwischensumme (inkl. aktueller Posten)
305)         temp_sum += el['total']
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

306)         # draw the background
307)         if not odd:
308)           canvas.setFillColorRGB(0.9, 0.9, 0.9)
309)         else:
310)           canvas.setFillColorRGB(1, 1, 1)
311)         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)
312)         canvas.setFillColorRGB(0, 0, 0)
313)         y -= line_padding
314)         (integer, decimals) = _niceCount(el['count'])
315)         canvas.drawRightString(left+0.8*cm, y-font_height, integer)
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

316) 	suffix = ''
317) 	if decimals:
318) 	  suffix = ',%s' % decimals
319) 	if el['unit']:
320) 	  suffix = suffix + ' ' + el['unit']
321)         if suffix:
322)           canvas.drawString(left+0.8*cm, y-font_height, '%s' % suffix)
323) 	  
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

324)         if len(part.vat) < 2:
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

325)           canvas.drawString(left+2.7*cm, y-font_height, subject[0])
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

326)           canvas.drawRightString(left+14.3*cm, y-font_height, _formatPrice(el['price']))
327)           if el['tender']:  
328)             canvas.drawRightString(left+16.8*cm, y-font_height, 'eventual')
329)           else:
330)             canvas.drawRightString(left+16.8*cm, y-font_height, _formatPrice(el['total']))
331)           subject = subject[1:]
332)           x = 1
333)           for line in subject:
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

334)             canvas.drawString(left+2.7*cm, y-(x * line_height)-font_height, line)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

335)             x += 1
Bernd Wurst Blocksatz auch für Beschrei...

Bernd Wurst authored 16 years ago

336)           for line in desc[:-1]:
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

337)             _drawJustifiedString(left+2.7*cm, y-(x * line_height)-font_height, line, canvas, 11*cm, font, font_size)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

338)             x += 1
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

339)           canvas.drawString(left+2.7*cm, y-(x * line_height)-font_height, desc[-1])
Bernd Wurst Blocksatz auch für Beschrei...

Bernd Wurst authored 16 years ago

340)           x += 1
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

341)         else:
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

342)           canvas.drawString(left+2.7*cm, y-font_height, subject[0])
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

343)           canvas.drawRightString(left+13.3*cm, y-font_height, _formatPrice(el['price']))
344)           canvas.drawString(left+13.7*cm, y-font_height, str(part.vat[el['vat']][1]))
345)           if el['tender']:  
346)             canvas.drawRightString(left+16.8*cm, y-font_height, 'eventual')
347)           else:
348)             canvas.drawRightString(left+16.8*cm, y-font_height, _formatPrice(el['total']))
349)           subject = subject[1:]
350)           x = 1
351)           for line in subject:
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

352)             canvas.drawString(left+2.7*cm, y-(x * line_height)-font_height, line)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

353)             x += 1
354)           for line in desc:
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

355)             canvas.drawString(left+2.7*cm, y-(x * line_height)-font_height, line)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

356)             x += 1
357)         odd = not odd
358)         y -= (need_lines * line_height) + line_padding
359)       if part.summary:
360)         y -= (0.3*cm)
361)         if part.vatType == 'gross':
362)           canvas.setFont(font+'-Bold', font_size)
363)           if iv.tender:
364)             canvas.drawRightString(left + 14.5*cm, y-font_height, 'Gesamtbetrag:')
365)           else:
366)             canvas.drawRightString(left + 14.5*cm, y-font_height, 'Rechnungsbetrag:')
367)           canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(part.sum))
368)           canvas.setFont(font, font_size)
369)           y -= line_height + line_padding
370)           summaries = []
371)           if len(part.vat) == 1:
372)             vat = part.vat.keys()[0]
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

373)             (integer, decimals) = _niceCount( (vat * 100) )
374)             vatstr = '%s' % integer
375)             if decimals:
376)               vatstr += ',%s' % decimals
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

377)             if iv.tender:
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

378)               summaries.append(('Im Gesamtbetrag sind %s%% MwSt enthalten:' % vatstr, _formatPrice((part.sum/(vat+1))*vat)))
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

379)             else:
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

380)               summaries.append(('Im Rechnungsbetrag sind %s%% MwSt enthalten:' % vatstr, _formatPrice((part.sum/(vat+1))*vat)))
Bernd Wurst Nettobetrag immer angeben (...

Bernd Wurst authored 7 years ago

381)             summaries.append(('Nettobetrag:', _formatPrice(part.sum - (part.sum/(vat+1))*vat)))
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

382)           else:
383)             for vat, vatdata in part.vat.iteritems():
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

384)               (integer, decimals) = _niceCount( (vat * 100) )
385)               vatstr = '%s' % integer
386)               if decimals:
387)                 vatstr += ',%s' % decimals
388)               summaries.append(('%s: Im Teilbetrag von %s sind %s%% MwSt enthalten:' % (vatdata[1], _formatPrice(vatdata[0]), vatstr), _formatPrice((vatdata[0]/(vat+1))*vat)))
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

389)           summaries.sort()
390)           for line in summaries:
391)             canvas.drawRightString(left + 14.5*cm, y-font_height, line[0])
392)             canvas.drawRightString(left + 16.8*cm, y-font_height, line[1])
393)             y -= line_height
394)         else:
395)           canvas.drawRightString(left + 14.5*cm, y-font_height, 'Nettobetrag:')
396)           canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(part.sum))
397)           y -= line_height
398)           summaries = []
399)           if len(part.vat) == 1:
400)             vat = part.vat.keys()[0]
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

401)             (integer, decimals) = _niceCount( (vat * 100) )
402)             vatstr = '%s' % integer
403)             if decimals:
404)               vatstr += ',%s' % decimals
405)             summaries.append(('zzgl. %s%% MwSt:' % vatstr, _formatPrice(vat*part.sum)))
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

406)           elif len(part.vat) > 1:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

407)             for vat, vatdata in part.vat.iteritems():
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

408)               (integer, decimals) = _niceCount( (vat * 100) )
409)               vatstr = '%s' % integer
410)               if decimals:
411)                 vatstr += ',%s' % decimals
412)               summaries.append(('zzgl. %s%% MwSt (%s):' % (vatstr, vatdata[1]), _formatPrice(vat*vatdata[0])))
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

413)           summaries.sort()
414)           for line in summaries:
415)             canvas.drawRightString(left + 14.5*cm, y-font_height, line[0])
416)             canvas.drawRightString(left + 16.8*cm, y-font_height, line[1])
417)             y -= line_height
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

418)           sum = part.sum
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

419)           for vat, vatdata in part.vat.iteritems():
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

420)             sum += vat*vatdata[0]
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

421)           canvas.setFont(font+'-Bold', font_size)
422)           if iv.tender:
423)             canvas.drawRightString(left + 14.5*cm, y-font_height, 'Gesamtbetrag:')
424)           else:
425)             canvas.drawRightString(left + 14.5*cm, y-font_height, 'Rechnungsbetrag:')
426)           canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(sum))
427)           canvas.setFont(font, font_size)
428)           y -= line_height + line_padding
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

429)     elif type(part) == Invoice.Text:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

430)       my_font_size = font_size
431)       canvas.setFont(font, my_font_size)
432)       left, right = leftcontent, rightcontent
433)       firsttime = True
434)       headlines = []
435)       if part.urgent:
436)         left += 1.5*cm
437)         right -= 1.5*cm
438)       if part.headline:
439)         headlines = _splitToWidth(canvas, part.headline, right-left, font, my_font_size)
440)       for para in part.paragraphs:
441)         lines = _splitToWidth(canvas, para, right-left, font, my_font_size)
442)         if part.urgent:
443)           need_height = len(lines) * line_height
444)           if len(headlines) > 0:
445)             need_height += len(headlines) * (line_height + 1) + line_padding
446)           canvas.setFillColorRGB(0.95, 0.95, 0.95)
447)           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)
448)           canvas.setFillColorRGB(0, 0, 0)
449)           y -= line_padding*3
450)         if part.headline and firsttime:
451)           firsttime = False
452)           canvas.setFont(font+'-Bold', my_font_size+1)
453)           for line in headlines:
454)             canvas.drawString(left, y-(font_height+1), line)
455)             y -= line_height + 1
456)           y -= line_padding
457)           canvas.setFont(font, my_font_size)
Bernd Wurst InvoiceText als Blocksatz d...

Bernd Wurst authored 16 years ago

458)         for line in lines[:-1]:
459)           _drawJustifiedString(left, y-font_height, line, canvas, right-left, font, my_font_size)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

460)           y -= line_height
Bernd Wurst InvoiceText als Blocksatz d...

Bernd Wurst authored 16 years ago

461)         canvas.drawString(left, y-font_height, lines[-1])
462)         y -= line_height
463)