8078fef385bde3ea65c68bf596d2624ed63aa3f9
Bernd Wurst WiP

Bernd Wurst authored 5 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) 
21) class InvoiceImage(object):
22)     def __init__(self, pilimage, caption=None, dpi=80, alignment="left"):
23)         self.imagedata = pilimage
24)         self.alignment = alignment
25)         self.dpi = dpi
26)         self.caption = caption
27) 
28) 
29) class InvoiceText(object):
30)     def __init__(self, content, urgent=False, headline=None):
31)         self.paragraphs = [content]
32)         self.urgent = urgent
33)         self.headline = headline
34)         self.fontsize = 0 # relative Schriftgröße ggü default
35) 
36)     def addParagraph(self, content):
37)         self.paragraphs.append(content)
38) 
39) 
40) class InvoiceTable(object):
41)     def __init__(self, vatType = 'gross', tender = False, summary = True):
42)         self.entries = []
43)         self.vat = {}
44)         self.sum = 0.0
45)         self.payments = []
46)         self.tender = tender
47)         self.summary = summary
48)         if vatType not in ['gross', 'net']:
49)             raise ValueError('vatType must be »gross« or »net«')
50)         self.vatType = vatType
51)     
52)     def validEntry(self, entry):
53)         '''bekommt einen Eintrag und liefert einen Eintrag wenn ok, wirft ansonsten ValueError.
54)         wird benutzt um z.B. die Summe auszurechnen oder ähnliches
55)         '''
56)         k = entry.keys()
57)         e = entry
58)         if not ('count' in k and 'unit' in k and 'subject' in k and 'price' in k and 'vat' in k):
59)             raise ValueError('Some data is missing!')
60)         ret = {'type': 'entry',
61)                'count': e['count'],
62)                'unit': e['unit'],
63)                'subject': e['subject'],
64)                'price': e['price'],
65)                'total': (e['price'] * e['count']),
66)                'vat': e['vat'],
67)                'tender': False,
68)                }
69)         if ret['vat'] > 1:
70)             ret['vat'] = float(ret['vat']) / 100
71)             
72)         if 'tender' in e.keys():
73)             ret['tender'] = e['tender']
74)         if 'desc' in k:
75)             ret['desc'] = e['desc']
76)         if 'period_start' in k:
77)             ret['period_start'] = e['period_start']
78)         if 'period_end' in k:
79)             ret['period_end'] = e['period_end']
80) 
81)         return ret
82)     
83)     def addItem(self, data):
84)         '''Fügt eine Zeile ein. data muss ein Dict mit passenden Keys und passenden
85)         Typen sein'''
86)         d = self.validEntry(data)
87)         if not d['vat'] in self.vat.keys():
88)             self.vat[d['vat']] = [0, chr(65+len(self.vat))]
89)         if 'tender' not in data or not data['tender']:
90)             self.vat[d['vat']][0] += d['total']
91)             self.sum += d['total']
92)         self.entries.append(d)
93)     
94)     def addTitle(self, title):
95)         self.entries.append({'type': 'title', 'title': title,})
96) 
97)     def addPayment(self, type, amount, date):
98)         self.payments.append({"type": type, "amount": amount, "date": date})
99) 
100) 
101) RECHNUNG = 380
102) ANGEBOT = 1
103) GUTSCHRIFT = 381
104) KORREKTUR = 384
105) 
106) VAT_REGULAR = 'S'
107) VAT_KLEINUNTERNEHMER = 'E'
108) VAT_INNERGEM = 'K'
109) 
Bernd Wurst WiP

Bernd Wurst authored 5 months ago

110) PAYMENT_LASTSCHRIFT = "59"
111) PAYMENT_UEBERWEISUNG = "30"
112) PAYMENT_BANKKONTO = "42"
113) PAYMENT_BAR = "10"
114) PAYMENT_KARTE = "48"
115) 
Bernd Wurst WiP

Bernd Wurst authored 5 months ago

116) class Invoice(object):
117)     def __init__(self, tender = False):
118)         self.customerno = None
119)         self.customer = {
120)             "id": None,
121)             "name": None,
122)             "address": {
123)                 "postcode": None,
124)                 "city_name": None,
125)                 "line1": None,
126)                 "line2": None,
127)                 "line3": None,
128)                 "country_id": None,
129)             },
130)             "email": None,
131)         }
132)         self.buyer = self.customer
133)         self.seller = {
134)             "name": None, # juristischer Name
135)             "trade_name": None, # Firmenname
136)             "address": {
137)                 "postcode": None,
138)                 "city_name": None,
139)                 "line1": None,
140)                 "line2": None,
141)                 "line3": None,
142)                 "country_id": None,
143)             },
144)             "phone": None,
145)             "email": None,
146)             "website": None,
147)         }
148)         self.seller_vat_id = None
149)         self.seller_bank_data = {
150)             'kontoinhaber': None,
151)             'iban': None,
152)             'bic': None,
153)             'bankname': None,
154)         }
155)         self.due_date = None
156)         self.debit = False
Bernd Wurst WiP

Bernd Wurst authored 5 months ago

157)         self.payment_type = PAYMENT_UEBERWEISUNG