2 # -*- coding: utf-8 -*-
4 import os, re, subprocess, sys
6 def search_substr(f, str):
14 str = str.replace(', ', ',')
15 money_re = re.compile('^-?\d+,\d\d$')
20 return float(f.replace(',', '.'))
22 def next_price(f, str):
23 p = search_substr(f, str)
26 print 'next_price(%s) -> line "%s" -> %.2f' % (str, p.strip(), price)
34 print '%-30s: %10.2f €' % (k, p[k])
36 if len(sys.argv) != 2:
37 print 'Usage:', sys.argv[0], '<PDF file>'
41 txtpath = pdfpath[:-3] + 'txt'
44 assert subprocess.call(['pdftotext', '-enc', 'UTF-8', '-layout', '-nopgbrk', pdfpath]) == 0
49 os.unlink(txtpath) # so that we don't forget later
53 common = next_price(f, 'Monatliche Beträge')
54 #other = next_price(f, 'Sonstige Leistungen des Konzerns')
56 # common = common + other
57 bill_vat = next_price(f, 'Umsatzsteuer 16 %')
58 bill_gross = next_price(f, 'Rechnungsbetrag')
60 bill_item_re = re.compile('^\s*\d+\.\s*.*16')
63 assert search_substr(f, 'Summe Monatliche Beträge')
64 assert search_substr(f, '...........')
65 assert search_substr(f, '...........')
68 if l.find('..........') >= 0:
71 if bill_item_re.match(l):
74 price[cur_number] = price.setdefault(cur_number, 0) + p
75 print 'adding %.2f to %s for "%s"' % (p, cur_number, l.strip())
76 if l.find('Summe Verbindungen für oben angegebene Rufnummer') >= 0:
78 if l.find('Rufnummer (') >= 0:
79 cur_number = l.strip()
80 print l.strip(), ' -> switching to', cur_number
82 assert search_substr(f, '...........')
85 if search_substr(f, 'Beträge anderer Anbieter'):
87 if l.find('Summe Beträge anderer Anbieter') >= 0:
89 if bill_item_re.match(l):
92 print 'adding %.2f to %s for "%s"' % (p, cur_number, l.strip())
93 price[cur_number] = price.setdefault(cur_number, 0) + p
94 if l.find('Rufnummer (') >= 0:
95 cur_number = l.strip()
96 print l.strip(), ' -> switching to', cur_number
98 print '----------------------------------------'
101 print 'Allgemeine Gebühren: %.2f' % common
103 common = common / len(price)
105 for k, v in price.iteritems():
106 price[k] = v + common
109 print '----------------------------------------'
110 print 'Verrechnung allgemeine Gebühren (Aufschlag für jeden: %.2f)' % common
116 for k, v in price.iteritems():
119 print '----------------------------------------'
120 print 'Aufschlag Mehrwertsteuer:'
123 print '----------------------------------------'
124 print 'Berechnete MwST: %.3f, Rechnungs-MwSt: %.2f' % (vat, bill_vat)
125 print 'Berechnete Bruttosume: %.3f, Rechnungs-Bruttosumme: %.2f' % (gross, bill_gross)