2 # -*- coding: utf-8 -*-
4 import os, re, subprocess, sys
6 def search_substr(f, str):
14 money_re = re.compile('^-?\d+,\d\d$')
19 return float(f.replace(',', '.'))
21 def next_price(f, str):
22 p = search_substr(f, str)
25 print 'next_price(%s) -> line "%s" -> %.2f' % (str, p.strip(), price)
33 print '%-30s: %10.2f €' % (k, p[k])
35 if len(sys.argv) != 2:
36 print 'Usage:', sys.argv[0], '<PDF file>'
40 txtpath = pdfpath[:-3] + 'txt'
43 assert subprocess.call(['pdftotext', '-enc', 'UTF-8', '-layout', '-nopgbrk', pdfpath]) == 0
48 os.unlink(txtpath) # so that we don't forget later
52 common = next_price(f, 'Monatliche Beträge')
53 #other = next_price(f, 'Sonstige Leistungen des Konzerns')
55 # common = common + other
56 bill_vat = next_price(f, 'Umsatzsteuer 16 %')
57 bill_gross = next_price(f, 'Rechnungsbetrag')
59 bill_item_re = re.compile('^\s*\d+\.\s*.*16')
62 assert search_substr(f, 'Summe Monatliche Beträge')
63 assert search_substr(f, ':::::::::::::')
65 if l.find('::::::::::::') >= 0:
68 if bill_item_re.match(l):
71 price[cur_number] = price.setdefault(cur_number, 0) + p
72 print 'adding %.2f to %s for "%s"' % (p, cur_number, l.strip())
73 if l.find('Summe Verbindungen für oben angegebene Rufnummer') >= 0:
75 if l.find('Rufnummer (') >= 0:
76 cur_number = l.strip()
77 print l.strip(), ' -> switching to', cur_number
80 if search_substr(f, 'Beträge anderer Anbieter'):
82 if l.find('Summe Beträge anderer Anbieter') >= 0:
84 if bill_item_re.match(l):
87 print 'adding %.2f to %s for "%s"' % (p, cur_number, l.strip())
88 price[cur_number] = price.setdefault(cur_number, 0) + p
89 if l.find('Rufnummer (') >= 0:
90 cur_number = l.strip()
91 print l.strip(), ' -> switching to', cur_number
93 print '----------------------------------------'
96 print 'Allgemeine Gebühren: %.2f' % common
98 common = common / len(price)
100 for k, v in price.iteritems():
101 price[k] = v + common
104 print '----------------------------------------'
105 print 'Verrechnung allgemeine Gebühren (Aufschlag für jeden: %.2f)' % common
111 for k, v in price.iteritems():
114 print '----------------------------------------'
115 print 'Aufschlag Mehrwertsteuer:'
118 print '----------------------------------------'
119 print 'Berechnete MwST: %.3f, Rechnungs-MwSt: %.2f' % (vat, bill_vat)
120 print 'Berechnete Bruttosume: %.3f, Rechnungs-Bruttosumme: %.2f' % (gross, bill_gross)