f6645aadc1eb565767ecad403a3a705b956538be
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
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 7 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
Bernd Wurst Verstecke Bankdaten bei Rec...

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 16 years ago

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]:
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

104)           fontsize = candidate
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

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 Mache die Invoice-Library f...

Bernd Wurst authored 7 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) 
Bernd Wurst Verstecke Bankdaten bei Rec...

Bernd Wurst authored 7 years ago

122) def InvoiceToPDF(iv, bankdata=True):
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

123)   try:
124)     from StringIO import StringIO
125)   except ImportError:
126)     from io import StringIO
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

127)   fd = StringIO()
128)   canvas = Canvas.Canvas(fd, pagesize=A4)
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

129)   
Bernd Wurst Setze PDF-Dokument-Titel

Bernd Wurst authored 14 years ago

130)   if iv.tender:
131)     canvas.setTitle("Angebot von schokokeks.org")
132)   else:
133)     canvas.setTitle("Rechnung von schokokeks.org")
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 15 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 15 years ago

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

Bernd Wurst authored 11 years ago

163)       # Wenn nur ein Element (plus Summen) hin passt, reicht uns das
164)       el = part.entries[0]
165)       # Die Abstände oben und unten
166)       height += 2 * line_padding
167)       # Die Breite ist konservativ
168)       height += line_height*len(_splitToWidth(canvas, el['subject'], 9.3*cm, font, font_size))
169)       if 'desc' in el and el['desc'] != '':
170)         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

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

Bernd Wurst authored 16 years ago

178)     return height
179) 
180) 
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 16 years ago

194)    
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

210) 
211)   font_size = default_font_size
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

212)   y = firstPage(canvas)
Bernd Wurst Verstecke Bankdaten bei Rec...

Bernd Wurst authored 7 years ago

213)   if bankdata==False:
214)     # Bankdaten überschreiben wenn Lastschrift
215)     canvas.setFillColor( Color(255,255,255, alpha=0.8) )
216)     canvas.rect(leftcontent+((rightcontent-leftcontent)/3)*2 - 2, bottomcontent - 2, (rightcontent-leftcontent)/3, -40, fill=True, stroke=False)
217)     canvas.setFillColor( Color(0,0,0, alpha=1) ) 
218)     canvas.saveState()
219)     canvas.translate( leftcontent+((rightcontent-leftcontent)/3)*2 + 2, bottomcontent - 40 )
220)     canvas.rotate( 15 )
221)     canvas.drawString( 0, 0, "Bitte nicht überweisen" )
222)     canvas.restoreState()
223)     #canvas.drawString(leftcontent+((rightcontent-leftcontent)/3)*2 + 2, bottomcontent - 20, "Bitte nicht überweisen")
224) 
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

227)   min_y = y
228)   if iv.caption:
229)     canvas.drawString(leftcontent, y, iv.caption)
230)     min_y -= (font_size + 3) + 0.5*cm
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

231) 
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

237)   elif type(iv) == Invoice.Generic:
238)     canvas.setFont(font, font_size)
239)     canvas.drawString(rightcolumn, y, "Datum:")
240)     canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
241)     y -= (font_size + 0.1*cm)
242)   elif type(iv) == Invoice.Invoice:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

243)     canvas.setFont(font+'-Bold', font_size)
244)     canvas.drawString(rightcolumn, y, "Bei Fragen bitte immer angeben:")
245)     y -= (font_size + 0.2*cm)
246)     canvas.setFont(font, font_size)
247)     canvas.drawString(rightcolumn, y, "Rechnungsdatum:")
248)     canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
249)     y -= (font_size + 0.1*cm)
250)     canvas.drawString(rightcolumn, y, "Rechnungsnummer:")
251)     canvas.drawRightString(rightcontent, y, "%i" % iv.id)
252)     y -= (font_size + 0.1*cm)
253)   if iv.customerno:
254)     canvas.drawString(rightcolumn, y, "Kundennummer:")
255)     canvas.drawRightString(rightcontent, y, "%s" % iv.customerno)
256)     y -= (font_size + 0.5*cm)
257)   canvas.setFont(font, font_size)
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

258)   y = min(min_y, y)
259) 
260)   if iv.salutation:
261)     canvas.drawString(leftcontent, y, iv.salutation)
262)     y -= font_size + 0.2*cm
263)     if type(iv) in [Invoice.Tender, Invoice.Invoice]:
264)       introText = 'hiermit stellen wir Ihnen die nachfolgend genannten Leistungen in Rechnung.'
265)       if type(iv) == Invoice.Tender:
266)         introText = 'hiermit unterbreiten wir Ihnen folgendes Angebot.'
267)       intro = _splitToWidth(canvas, introText, rightcontent - leftcontent, font, font_size)
268)       for line in intro:
269)         canvas.drawString(leftcontent, y, line)
270)         y -= font_size + 0.1*cm
271)       y -= font_size + 0.1*cm
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

272) 
273)   font_size = default_font_size
274)   for part in iv.parts:
275)     if y - _partHeight(part) < (bottomcontent + (0.5*cm)):
276)       _PageWrap(canvas)
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 15 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

282)         
283)       left = leftcontent
284)       right = rightcontent
285)       top = topcontent
286)       bottom = bottomcontent
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

287)       temp_sum = 0.0
288)       y = _tableHead(y)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

289)       odd=True
290)       for el in part.entries:
291)         subject = []
292)         if len(part.vat) == 1:
293)           subject = _splitToWidth(canvas, el['subject'], 10.3*cm, font, font_size)
294)         else:
295)           subject = _splitToWidth(canvas, el['subject'], 9.3*cm, font, font_size)
296)         desc = []
297)         if 'desc' in el and el['desc'] != '':
Bernd Wurst Blocksatz auch für Beschrei...

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 16 years ago

300) 
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

301) 	# need page wrap?
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

302)         if y - (need_lines+2 * font_size) < (bottomcontent + 2*cm):
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

303)           canvas.setFont(font, font_size)
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

304)           # Zwischensumme
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

305)           canvas.drawRightString(left + 14.5*cm, y-font_height, 'Zwischensumme:')
306)           canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(temp_sum))
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

307)           # page wrap
308)           _PageWrap(canvas)
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

309)           y = topcontent - font_size - line_padding*3
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

310)           # header
311)           y = _tableHead(y)
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

312)           odd=True
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

313)           # übertrag
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

314)           canvas.setFont(font, font_size)
315)           canvas.drawRightString(left + 14.5*cm, y-font_height, 'Übertrag:')
316)           canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(temp_sum))
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

317)           y -= font_height + line_padding
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

318) 
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

319)         # Zwischensumme (inkl. aktueller Posten)
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

320)         temp_sum += el['total']
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

321)         # draw the background
322)         if not odd:
323)           canvas.setFillColorRGB(0.9, 0.9, 0.9)
324)         else:
325)           canvas.setFillColorRGB(1, 1, 1)
326)         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)
327)         canvas.setFillColorRGB(0, 0, 0)
328)         y -= line_padding
329)         (integer, decimals) = _niceCount(el['count'])
330)         canvas.drawRightString(left+0.8*cm, y-font_height, integer)
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

331)         suffix = ''
332)         if decimals:
333)           suffix = ',%s' % decimals
334)         if el['unit']:
335)           suffix = suffix + ' ' + el['unit']
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

336)         if suffix:
337)           canvas.drawString(left+0.8*cm, y-font_height, '%s' % suffix)
338) 	  
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

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

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 16 years ago

341)           canvas.drawRightString(left+14.3*cm, y-font_height, _formatPrice(el['price']))
342)           if el['tender']:  
343)             canvas.drawRightString(left+16.8*cm, y-font_height, 'eventual')
344)           else:
345)             canvas.drawRightString(left+16.8*cm, y-font_height, _formatPrice(el['total']))
346)           subject = subject[1:]
347)           x = 1
348)           for line in subject:
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

349)             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

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 11 years ago

352)             _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

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

Bernd Wurst authored 11 years ago

354)           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

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 16 years ago

358)           canvas.drawRightString(left+13.3*cm, y-font_height, _formatPrice(el['price']))
359)           canvas.drawString(left+13.7*cm, y-font_height, str(part.vat[el['vat']][1]))
360)           if el['tender']:  
361)             canvas.drawRightString(left+16.8*cm, y-font_height, 'eventual')
362)           else:
363)             canvas.drawRightString(left+16.8*cm, y-font_height, _formatPrice(el['total']))
364)           subject = subject[1:]
365)           x = 1
366)           for line in subject:
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

367)             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

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

Bernd Wurst authored 11 years ago

370)             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

371)             x += 1
372)         odd = not odd
373)         y -= (need_lines * line_height) + line_padding
374)       if part.summary:
375)         y -= (0.3*cm)
376)         if part.vatType == 'gross':
377)           summaries = []
378)           if len(part.vat) == 1:
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

379)             vat = list(part.vat.keys())[0]
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

380)             (integer, decimals) = _niceCount( (vat * 100) )
381)             vatstr = '%s' % integer
382)             if decimals:
383)               vatstr += ',%s' % decimals
Bernd Wurst Netto- und Bruttobetrag imm...

Bernd Wurst authored 6 years ago

384)             canvas.drawRightString(left + 14.5*cm, y-font_height, 'Nettobetrag:')
385)             canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(part.sum - (part.sum/(vat+1))*vat))
386)             y -= line_height
387)             summaries.append(('%s%% MwSt:' % vatstr, _formatPrice((part.sum/(vat+1))*vat)))
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

388)           else:
Bernd Wurst Netto- und Bruttobetrag imm...

Bernd Wurst authored 6 years ago

389)             net = 0.0
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 16 years ago

391)               (integer, decimals) = _niceCount( (vat * 100) )
392)               vatstr = '%s' % integer
393)               if decimals:
394)                 vatstr += ',%s' % decimals
Bernd Wurst Netto- und Bruttobetrag imm...

Bernd Wurst authored 6 years ago

395)               summaries.append(('%s: Teilbetrag %s zzgl. %s%% MwSt:' % (vatdata[1], _formatPrice(vatdata[0]), vatstr), _formatPrice((vatdata[0]/(vat+1))*vat)))
396)               net += vatdata[0]
397)             summaries.append(('Nettobetrag gesamt:', _formatPrice(net)))
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

398)           summaries.sort()
399)           for line in summaries:
400)             canvas.drawRightString(left + 14.5*cm, y-font_height, line[0])
401)             canvas.drawRightString(left + 16.8*cm, y-font_height, line[1])
402)             y -= line_height
Bernd Wurst Netto- und Bruttobetrag imm...

Bernd Wurst authored 6 years ago

403)           canvas.setFont(font+'-Bold', font_size)
404)           if iv.tender:
405)             canvas.drawRightString(left + 14.5*cm, y-font_height, 'Gesamtbetrag:')
406)           else:
407)             canvas.drawRightString(left + 14.5*cm, y-font_height, 'Rechnungsbetrag:')
408)           canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(part.sum))
409)           canvas.setFont(font, font_size)
410)           y -= line_height + line_padding
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

411)         else:
412)           canvas.drawRightString(left + 14.5*cm, y-font_height, 'Nettobetrag:')
413)           canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(part.sum))
414)           y -= line_height
415)           summaries = []
416)           if len(part.vat) == 1:
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

417)             vat = list(part.vat.keys())[0]
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

418)             (integer, decimals) = _niceCount( (vat * 100) )
419)             vatstr = '%s' % integer
420)             if decimals:
421)               vatstr += ',%s' % decimals
422)             summaries.append(('zzgl. %s%% MwSt:' % vatstr, _formatPrice(vat*part.sum)))
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

423)           elif len(part.vat) > 1:
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 16 years ago

425)               (integer, decimals) = _niceCount( (vat * 100) )
426)               vatstr = '%s' % integer
427)               if decimals:
428)                 vatstr += ',%s' % decimals
429)               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

430)           summaries.sort()
431)           for line in summaries:
432)             canvas.drawRightString(left + 14.5*cm, y-font_height, line[0])
433)             canvas.drawRightString(left + 16.8*cm, y-font_height, line[1])
434)             y -= line_height
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

435)           sum = part.sum
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

436)           for vat, vatdata in part.vat.items():
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

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

Bernd Wurst authored 16 years ago

438)           canvas.setFont(font+'-Bold', font_size)
439)           if iv.tender:
440)             canvas.drawRightString(left + 14.5*cm, y-font_height, 'Gesamtbetrag:')
441)           else:
442)             canvas.drawRightString(left + 14.5*cm, y-font_height, 'Rechnungsbetrag:')
443)           canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(sum))
444)           canvas.setFont(font, font_size)
445)           y -= line_height + line_padding
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

447)       my_font_size = font_size
448)       canvas.setFont(font, my_font_size)
449)       left, right = leftcontent, rightcontent
450)       firsttime = True
451)       headlines = []
452)       if part.urgent:
453)         left += 1.5*cm
454)         right -= 1.5*cm
455)       if part.headline:
456)         headlines = _splitToWidth(canvas, part.headline, right-left, font, my_font_size)
457)       for para in part.paragraphs:
458)         lines = _splitToWidth(canvas, para, right-left, font, my_font_size)
459)         if part.urgent:
460)           need_height = len(lines) * line_height
461)           if len(headlines) > 0:
462)             need_height += len(headlines) * (line_height + 1) + line_padding
463)           canvas.setFillColorRGB(0.95, 0.95, 0.95)
464)           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)
465)           canvas.setFillColorRGB(0, 0, 0)
466)           y -= line_padding*3
467)         if part.headline and firsttime:
468)           firsttime = False
469)           canvas.setFont(font+'-Bold', my_font_size+1)
470)           for line in headlines:
471)             canvas.drawString(left, y-(font_height+1), line)
472)             y -= line_height + 1
473)           y -= line_padding
474)           canvas.setFont(font, my_font_size)
Bernd Wurst InvoiceText als Blocksatz d...

Bernd Wurst authored 16 years ago

475)         for line in lines[:-1]:
476)           _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

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

Bernd Wurst authored 16 years ago

478)         canvas.drawString(left, y-font_height, lines[-1])
479)         y -= line_height
480)