-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprintFacturen.py
225 lines (208 loc) · 9.89 KB
/
printFacturen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
from login import hoofdMenu
from postcode import checkpostcode
import os, datetime
from PyQt5.QtCore import Qt, QAbstractTableModel
from PyQt5.QtGui import QFont, QIcon
from PyQt5.QtWidgets import QDialog, QWidget, QMessageBox, QTableView, QVBoxLayout
from sqlalchemy import (Table, Column, Integer, String, MetaData, create_engine,\
Float, ForeignKey, select, and_)
def geenBest(m_email):
msg = QMessageBox()
msg.setStyleSheet("color: black; background-color: gainsboro")
msg.setWindowIcon(QIcon('./images/logos/logo.jpg'))
msg.setIcon(QMessageBox.Information)
msg.setText('Nog geen facturen aanwezig voor deze klant!')
msg.setWindowTitle('Facturen printen')
msg.exec_()
hoofdMenu(m_email)
def printing():
msg = QMessageBox()
msg.setStyleSheet("color: black; background-color: gainsboro")
msg.setWindowIcon(QIcon('./images/logos/logo.jpg'))
msg.setIcon(QMessageBox.Information)
msg.setText('Ogenblik afdrukken wordt gestart!')
msg.setWindowTitle('Webverkooporders printen')
msg.exec_()
def printGeg(filename, movbestnr):
from sys import platform
msgBox=QMessageBox()
msgBox.setStyleSheet("color: black; background-color: gainsboro")
msgBox.setWindowIcon(QIcon('./images/logos/logo.jpg'))
msgBox.setWindowTitle("Printen orderfactuur")
msgBox.setIcon(QMessageBox.Information)
msgBox.setText("Wilt U factuur van ordernummer "+str(movbestnr)+" uitprinten?");
msgBox.setStandardButtons(QMessageBox.Yes)
msgBox.addButton(QMessageBox.No)
msgBox.setStyleSheet("color: black; background-color: gainsboro")
msgBox.setDefaultButton(QMessageBox.Yes)
if(msgBox.exec_() == QMessageBox.Yes):
if platform == 'win32':
os.startfile(filename, "print")
else:
os.system("lpr "+filename)
printing()
def windowSluit(self, m_email):
self.close()
hoofdMenu(m_email)
def kiesOrder(m_email):
metadata = MetaData()
orders_verkoop = Table('orders_verkoop', metadata,
Column('ovbestelID', Integer, primary_key=True),
Column('klantID', None, ForeignKey('klanten.klantID')),
Column('ovbesteldatum', String),
Column('datum_betaald', String),
Column('datum_geleverd', String),
Column('bedrag', Float))
klanten = Table('klanten', metadata,
Column('klantID', Integer(), primary_key=True),
Column('accountID', None, ForeignKey('accounts.accountID')),
Column('rekening', String))
accounts = Table('accounts', metadata,
Column('accountID', Integer(), primary_key=True),
Column('aanhef', String),
Column('voornaam', String),
Column('tussenvoegsel', String),
Column('achternaam', String),
Column('postcode', String),
Column('huisnummer', String),
Column('toevoeging', String),
Column('email', String),
Column('telnr', String))
engine = create_engine('postgresql+psycopg2://postgres@localhost/bisystem')
con = engine.connect()
selord = select([orders_verkoop, klanten, accounts]).where(and_(orders_verkoop.c.klantID == klanten.c.klantID,\
klanten.c.accountID == accounts.c.accountID, accounts.c.email == m_email))
rpc = con.execute(selord).fetchone()
if rpc:
rpord = con.execute(selord)
else:
geenBest(m_email)
mpostcode = rpc[14]
mhuisnr = int(rpc[15])
madres = checkpostcode(mpostcode,mhuisnr)
mstraat = madres[0]
mplaats = madres[1]
class MyWindow(QDialog):
def __init__(self, data_list, header, *args):
QWidget.__init__(self, *args,)
self.setGeometry(50, 50, 900, 900)
self.setWindowTitle('Printen orderfacturen')
self.setWindowIcon(QIcon('./images/logos/logo.jpg'))
self.setWindowFlags(self.windowFlags()| Qt.WindowSystemMenuHint |
Qt.WindowMinMaxButtonsHint)
table_model = MyTableModel(self, data_list, header)
table_view = QTableView()
table_view.setModel(table_model)
font = QFont("Arial", 10)
table_view.setFont(font)
table_view.setColumnHidden(1,True)
table_view.setColumnHidden(6,True)
table_view.setColumnHidden(9,True)
table_view.setColumnHidden(10,True)
table_view.setColumnHidden(11,True)
table_view.setColumnHidden(12,True)
table_view.setColumnHidden(13,True)
table_view.setColumnHidden(14,True)
table_view.setColumnHidden(15,True)
table_view.setColumnHidden(16,True)
table_view.setColumnHidden(17,True)
table_view.setColumnHidden(18,True)
table_view.resizeColumnsToContents()
table_view.setSelectionBehavior(QTableView.SelectRows)
table_view.clicked.connect(printFactuur)
layout = QVBoxLayout(self)
layout.addWidget(table_view)
self.setLayout(layout)
class MyTableModel(QAbstractTableModel):
def __init__(self, parent, mylist, header, *args):
QAbstractTableModel.__init__(self, parent, *args)
self.mylist = mylist
self.header = header
def rowCount(self, parent):
return len(self.mylist)
def columnCount(self, parent):
return len(self.mylist[0])
def data(self, index, role):
if not index.isValid():
return None
elif role != Qt.DisplayRole:
return None
return str(self.mylist[index.row()][index.column()])
def headerData(self, col, orientation, role):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return self.header[col]
return None
header = ['Bestelnummer','','Besteldatum','Betaaldatum', 'Leverdatum','Totaalbedrag','', 'Accountnr',\
'Rekeningnr','','','','','','','','','','']
data_list=[]
for row in rpord:
data_list += [(row)]
def printFactuur(idx):
from sys import platform
movbestnr = idx.data()
if idx.column() == 0:
metadata = MetaData()
orders_verkoop_artikelen = Table('orders_verkoop_artikelen', metadata,
Column('ovaID', Integer, primary_key=True),
Column('ovbestelID', None, ForeignKey('orders_verkoop.ovbestelID')),
Column('artikelID', None, ForeignKey('artikelen.artikelID')),
Column('ovaantal', Integer),
Column('ovleverdatum', String),
Column('verkoopprijs', Float),
Column('regel', Integer),
Column('retour', Float),
Column('betaaldatum', String),
Column('leveringsdatum', String))
artikelen = Table('artikelen', metadata,
Column('artikelID', Integer(), primary_key=True),
Column('artikelomschrijving', String),
Column('artikelprijs', Float),
Column('art_voorraad', Float),
Column('art_eenheid', String),
Column('locatie_magazijn', String))
engine = create_engine('postgresql+psycopg2://postgres@localhost/bisystem')
con = engine.connect()
selova = select([orders_verkoop_artikelen,artikelen]).where(and_(\
orders_verkoop_artikelen.c.ovbestelID == movbestnr, orders_verkoop_artikelen\
.c.artikelID == artikelen.c.artikelID)).order_by(orders_verkoop_artikelen.c.ovaID)
rpova = con.execute(selova)
mblad = 1
rgl = 0
if platform == 'win32':
filename = '.\\forms\\Weborders_Facturen\\Weborder-factuur_'+str(rpc[0])+'.txt'
else:
filename = './forms/Weborders_Facturen/Weborder-factuur_'+str(rpc[0])+'.txt'
adreskop=\
('\n\n\n\n\n\n\nFACTUUR\n\n'+rpc[10]+' '+rpc[11]+' '+rpc[12]+' '+rpc[13]+',\n'+\
mstraat+' '+rpc[15]+rpc[16]+',\n'+\
rpc[14]+' '+mplaats+'.\n\n\n\n\n')
open(filename,'w').write(adreskop)
kop=\
('Ordernummer: '+ str(movbestnr)+' Datum: '+str(datetime.datetime.now())[0:10]+' Besteldatum: '+str(rpc[2])+' Blad : '+str(mblad)+'\n'+
'==============================================================================================\n'+
'Artikelnr Omschrijving Eenheid Aantal Prijs Subtotaal BTW \n'+
'==============================================================================================\n')
mtotaal = 0
for row in rpova:
if rgl == 0 and mblad == 1:
open(filename, 'w').write(adreskop)
open(filename, 'a').write(kop)
rgl = 16
elif rgl%57 == 0:
open(filename, 'a').write(kop)
mblad += 1
msub = row[3]*row[5]
open(filename,'a').write('{:<11d}'.format(row[2])+'{:<37.35s}'.format(row[11])+\
'{:>6s}'.format(row[14])+' '+'{:>6.2f}'.format(row[3])+'{:>10.2f}'.format(row[5])+\
' '+'{:>10.2f}'.format(msub)+' '+'{:>10.2f}'.format(msub*21/121)+'\n')
mtotaal = mtotaal+msub
rgl += 1
tail =(\
'----------------------------------------------------------------------------------------------\n'+
'Totaal factuurbedrag inclusief 21% BTW '+'{:10.2f}'.format(mtotaal)+' \n'+
'==============================================================================================\n')
open(filename,'a').write(tail)
printGeg(filename, movbestnr)
win = MyWindow(data_list, header)
win.exec_()
hoofdMenu(m_email)