06db2136cf749513a3e31b7b8b552e8c11735aa6
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

1) # -* coding: utf8 *-
2) # (C) 2011 by Bernd Wurst <bernd@schokokeks.org>
3) 
4) # This file is part of Bib2011.
5) #
6) # Bib2011 is free software: you can redistribute it and/or modify
7) # it under the terms of the GNU General Public License as published by
8) # the Free Software Foundation, either version 3 of the License, or
9) # (at your option) any later version.
10) #
11) # Bib2011 is distributed in the hope that it will be useful,
12) # but WITHOUT ANY WARRANTY; without even the implied warranty of
13) # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14) # GNU General Public License for more details.
15) #
16) # You should have received a copy of the GNU General Public License
17) # along with Bib2011.  If not, see <http://www.gnu.org/licenses/>.
18) 
19) import datetime
20) 
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

21) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

22) class InvoiceImage(object):
23)     def __init__(self, pilimage, caption=None, dpi=80, alignment="left"):
24)         self.imagedata = pilimage
25)         self.alignment = alignment
26)         self.dpi = dpi
27)         self.caption = caption
28) 
29) 
30) class InvoiceText(object):
31)     def __init__(self, content, urgent=False, headline=None):
32)         self.paragraphs = [content]
33)         self.urgent = urgent
34)         self.headline = headline
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

35)         self.fontsize = 0  # relative Schriftgröße ggü default
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

36) 
37)     def addParagraph(self, content):
38)         self.paragraphs.append(content)
39) 
40) 
41) class InvoiceTable(object):
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

42)     def __init__(self, vatType='gross', tender=False, summary=True):
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

43)         self.entries = []
44)         self.vat = {}
45)         self.sum = 0.0
46)         self.payments = []
47)         self.tender = tender
48)         self.summary = summary
49)         if vatType not in ['gross', 'net']:
50)             raise ValueError('vatType must be »gross« or »net«')
51)         self.vatType = vatType
52)     
53)     def validEntry(self, entry):
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

54)         """bekommt einen Eintrag und liefert einen Eintrag, wenn ok; wirft ansonsten ValueError.
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

55)         wird benutzt um z.B. die Summe auszurechnen oder ähnliches
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

56)         """
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

57)         k = entry.keys()
58)         e = entry
59)         if not ('count' in k and 'unit' in k and 'subject' in k and 'price' in k and 'vat' in k):
60)             raise ValueError('Some data is missing!')
61)         ret = {'type': 'entry',
62)                'count': e['count'],
63)                'unit': e['unit'],
64)                'subject': e['subject'],
65)                'price': e['price'],
66)                'total': (e['price'] * e['count']),
67)                'vat': e['vat'],
68)                'tender': False,
69)                }
70)         if ret['vat'] > 1:
71)             ret['vat'] = float(ret['vat']) / 100
72)             
73)         if 'tender' in e.keys():
74)             ret['tender'] = e['tender']
75)         if 'desc' in k:
76)             ret['desc'] = e['desc']
77)         if 'period_start' in k:
78)             ret['period_start'] = e['period_start']
79)         if 'period_end' in k:
80)             ret['period_end'] = e['period_end']
81) 
82)         return ret
83)     
84)     def addItem(self, data):
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

85)         """Fügt eine Zeile ein. data muss ein Dict mit passenden Keys und passenden
86)         Typen sein"""
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

87)         d = self.validEntry(data)
88)         if not d['vat'] in self.vat.keys():
89)             self.vat[d['vat']] = [0, chr(65+len(self.vat))]
90)         if 'tender' not in data or not data['tender']:
91)             self.vat[d['vat']][0] += d['total']
92)             self.sum += d['total']
93)         self.entries.append(d)
94)     
95)     def addTitle(self, title):
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

96)         self.entries.append({'type': 'title', 'title': title, })
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

97) 
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

98)     def addPayment(self, payment_type, amount, date):
99)         self.payments.append({"type": payment_type, "amount": amount, "date": date})
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

100) 
101) 
102) RECHNUNG = 380
103) ANGEBOT = 1
104) GUTSCHRIFT = 381
105) KORREKTUR = 384
106) 
107) VAT_REGULAR = 'S'
108) VAT_KLEINUNTERNEHMER = 'E'
109) VAT_INNERGEM = 'K'
110) 
Bernd Wurst WiP

Bernd Wurst authored 4 months ago

111) PAYMENT_LASTSCHRIFT = "59"
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

112) PAYMENT_UEBERWEISUNG = "58"
Bernd Wurst WiP

Bernd Wurst authored 4 months ago

113) PAYMENT_BANKKONTO = "42"
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

114) PAYMENT_ONLINE = "68"
Bernd Wurst WiP

Bernd Wurst authored 4 months ago

115) PAYMENT_BAR = "10"
116) PAYMENT_KARTE = "48"
117) 
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

118) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

119) class Invoice(object):
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

120)     def __init__(self, tender=False):
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

121)         self.customerno = None
122)         self.customer = {
123)             "id": None,
124)             "name": None,
125)             "address": {
126)                 "postcode": None,
127)                 "city_name": None,
128)                 "line1": None,
129)                 "line2": None,
130)                 "line3": None,
131)                 "country_id": None,
132)             },
133)             "email": None,
134)         }
135)         self.buyer = self.customer
136)         self.seller = {
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

137)             "name": None,  # juristischer Name
138)             "trade_name": None,  # Firmenname
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

139)             "address": {
140)                 "postcode": None,
141)                 "city_name": None,
142)                 "line1": None,
143)                 "line2": None,
144)                 "line3": None,
145)                 "country_id": None,
146)             },
147)             "phone": None,
148)             "email": None,
149)             "website": None,
150)         }
151)         self.seller_vat_id = None
152)         self.seller_bank_data = {
153)             'kontoinhaber': None,
154)             'iban': None,
155)             'bic': None,
156)             'bankname': None,
157)         }
158)         self.due_date = None
159)         self.debit = False
Bernd Wurst WiP

Bernd Wurst authored 4 months ago

160)         self.payment_type = PAYMENT_UEBERWEISUNG
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

161)         self.debit_mandate_id = None
162)         self.creditor_reference_id = None
163)         self.buyer_bank_data = {
164)             'kontoinhaber': None,
165)             'iban': None,
166)             'bic': None,
167)             'bankname': None,
168)         }
169)         self.vat_type = VAT_REGULAR
170)         self.salutation = 'Sehr geehte Damen und Herren,'
171)         self.id = None
172)         self.cash = True
173)         self.type = RECHNUNG
174)         self.logo_image_file = None
175)         self.tender = tender
176)         self.title = 'Rechnung'
177)         if tender:
178)             self.title = 'Angebot'
179)         self.official = True
180)         self.parts = []
181)         self.pagecount = 0
182)         self.date = datetime.date.today()
183)     
184)     def setDate(self, date):
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

185)         if not isinstance(date, datetime.date):