-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrmbuy.py
executable file
·165 lines (142 loc) · 4.53 KB
/
brmbuy.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
#!/bin/python
import sys
import sqlite3
from fce import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
DEBUG=0
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
dbc.execute("SELECT * FROM stock WHERE id=("
"SELECT stock FROM barcodes WHERE code='"+brmSatanize(sys.argv[1])+"')"
"LIMIT 1;")
dbrec=dbc.fetchone()
db.close()
if DEBUG: print("DBREC="+str(dbrec))
if dbrec==None:
sys.exit(EXIT_NOBARCODE)
app=QApplication(sys.argv)
mainWidget=QWidget()
mainWidget.resize(1280,1024)
mainWidget.setWindowTitle("BrmbarSAP - BuyScreen")
mainWidget.setStyleSheet(STYLE_WIDGET)
def brmSetAmount(foo=None):
if DEBUG: print("brmSetAmount")
res=mainWidget.findChildren(QLineEdit)
if res[0].text()=="0":
res[0].setStyleSheet(res[0].styleSheet()+STYLE_BADLE)
else:
res[0].setStyleSheet(res[0].styleSheet()+STYLE_OKLE)
QTimer.singleShot(0,res[-1],SLOT('setFocus()'))
def brmPayCash(dbrec=None,a=None):
ale=a.findChildren(QLineEdit)[0]
le=str(ale.text())
sum=str(int(le)*int(dbrec[4]))
profit=str(int(sum)-(int(le)*int(dbrec[3])))
if DEBUG: print("brmPayCash: a="+le+"\n"
" "+str(dbrec[0]))
if int(le)==0:
ale.setStyleSheet(ale.styleSheet()+STYLE_BADLE)
return
else:
ale.setStyleSheet(ale.styleSheet()+STYLE_OKLE)
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP,"
"0,"+str(dbrec[0])+","+le+","+sum+","+profit+");")
dbc.execute("UPDATE stock SET quan=quan-"+le+" WHERE id="+str(dbrec[0])+";")
db.commit()
db.close()
brmPassMsg("Sold! Put "+str(int(le)*dbrec[4])+" to cashbox")
sys.exit(EXIT_MSG)
def brmPayMember(dbrec=None,a=None):
ale=a.findChildren(QLineEdit)[0]
le=str(ale.text())
apswd=a.findChildren(QLineEdit)[1]
pswd=brmSatanize(apswd.text())
sum=str(int(le)*int(dbrec[4]))
profit=str(int(sum)-(int(le)*int(dbrec[3])))
who=brmSatanize((a.findChildren(QLineEdit)[-1]).text())
if DEBUG: print("brmPayMember: a="+le+" who='"+who+"'\n"
" "+str(dbrec))
if who=="": # Just enter, ignore
return
if int(le)==0:
ale.setStyleSheet(ale.styleSheet()+STYLE_BADLE)
return
else:
ale.setStyleSheet(ale.styleSheet()+STYLE_OKLE)
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
dbc.execute("SELECT * FROM users WHERE code='"+who+"' LIMIT 1;")
whoid=dbc.fetchone()
if DEBUG: print(" whoid="+str(whoid))
if whoid==None:
db.close()
apswd.setText("")
return
if hashlib.sha512(pswd).hexdigest()!=whoid[4]:
db.close()
apswd.setText("")
apswd.setStyleSheet(apswd.styleSheet()+STYLE_BADLE)
return
else:
apswd.setStyleSheet(apswd.styleSheet()+STYLE_OKLE)
if whoid[2]<BUY_LIMIT and int(sum)>0: # Allow buy negative price (ex. uklid)
db.close()
sys.exit(EXIT_NOCREDIT)
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP,"
" "+str(whoid[0])+","+str(dbrec[0])+","+le+","+sum+","+profit+");")
dbc.execute("UPDATE stock SET quan=quan-"+le+" WHERE id="+str(dbrec[0])+";")
dbc.execute("UPDATE users SET cash=cash-("+sum+") "
"WHERE id='"+str(whoid[0])+"';")
db.commit()
db.close()
brmPassMsg("'"+brmSatanize(dbrec[1])+"' sold to '"+brmSatanize(whoid[1])+"'")
sys.exit(EXIT_MSG)
sbox=QHBoxLayout()
wl=QLabel(brmSatanize(dbrec[1]))
wl.setStyleSheet(STYLE_TEXT)
sbox.addWidget(wl)
sbox.addStretch(1)
wp=QLabel(str(dbrec[4])+" * ")
wp.setStyleSheet(STYLE_TEXT)
sbox.addWidget(wp)
brmAddLine(sbox,"1",'N1',STYLE_LE,brmSetAmount,c=0)
pbox=QHBoxLayout()
pl=QLabel("Password (if set)")
pl.setStyleSheet(STYLE_TEXT)
pbox.addWidget(pl)
pbox.addStretch(1)
brmAddLine(pbox,"","T",STYLE_LE,lambda:QTimer.singleShot(0,
mainWidget.findChildren(QLineEdit)[-1],SLOT('setFocus()')),c=0)
bbox=QHBoxLayout()
bbox.addStretch(1)
brmAddButton(bbox,"Pay by cash",lambda:brmPayCash(dbrec,mainWidget))
bbox.addStretch(1)
brmAddButton(bbox,"Cancel",lambda:sys.exit(EXIT_CANCEL))
bbox.addStretch(1)
hbox=QHBoxLayout()
hbox.addStretch(1)
hlp=QLabel("Set the required amount you want to buy.\n\n"
"You can either 'Pay by cash', or scan your barcode to pay by credit\n\n"
"Invalid value is indicated by red background color")
hlp.setStyleSheet(STYLE_HELP)
hbox.addWidget(hlp)
hbox.addStretch(1)
screenbox=QVBoxLayout()
brmLabelBox(screenbox,"Transaction overview")
screenbox.addStretch(1)
screenbox.addLayout(sbox)
screenbox.addStretch(1)
screenbox.addLayout(pbox)
screenbox.addStretch(1)
screenbox.addLayout(hbox)
screenbox.addStretch(3)
screenbox.addLayout(bbox)
brmAddLine(screenbox,"",'T',STYLE_HIDDEN,lambda:brmPayMember(dbrec,mainWidget))
mainWidget.setLayout(screenbox)
mainWidget.showFullScreen()
mainWidget.findChildren(QLineEdit)[1].setEchoMode(2) # Password masking
app.exec_()
sys.exit(EXIT_CANCEL)