-
Notifications
You must be signed in to change notification settings - Fork 0
/
brmrec.py
executable file
·154 lines (131 loc) · 3.82 KB
/
brmrec.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
#!/usr/bin/python
import sys
import sqlite3
from fce import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
DEBUG=0
app=QApplication(sys.argv)
mainWidget=QWidget()
mainWidget.resize(1280,1024)
mainWidget.setWindowTitle("BrmbarSAP - Receipt")
mainWidget.setStyleSheet(STYLE_WIDGET)
def brmReceipt(mw=None):
if DEBUG:print("brmReceipt")
le=mw.findChildren(QLineEdit)
led=brmSatanize(le[0].text())
lea=str(int(le[1].text()))
leu=brmSatanize(le[2].text())
lep=hashlib.sha512(brmSatanize(le[3].text())).hexdigest()
if led=="":
le[0].setStyleSheet(le[0].styleSheet()+STYLE_BADLE)
return
else:
le[0].setStyleSheet(le[0].styleSheet()+STYLE_OKLE)
if int(lea)<=0:
le[1].setStyleSheet(le[1].styleSheet()+STYLE_BADLE)
return
else:
le[1].setStyleSheet(le[1].styleSheet()+STYLE_OKLE)
if leu=="":
le[2].setStyleSheet(le[2].styleSheet()+STYLE_BADLE)
return
else:
le[2].setStyleSheet(le[2].styleSheet()+STYLE_OKLE)
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
dbc.execute("SELECT id,pass,name FROM users WHERE code='"+leu+"' LIMIT 1;")
usr=dbc.fetchone()
if DEBUG:print(" "+str(usr))
if usr==None:
db.close()
le[2].setStyleSheet(le[2].styleSheet()+STYLE_BADLE)
return
else:
le[2].setStyleSheet(le[2].styleSheet()+STYLE_OKLE)
if usr[1]!=lep:
db.close()
le[3].setText("")
le[3].setStyleSheet(le[3].styleSheet()+STYLE_BADLE)
return
else:
le[3].setStyleSheet(le[3].styleSheet()+STYLE_OKLE)
dbc.execute("SELECT (SELECT sum(profit) FROM transactions WHERE what=1)-"
"(SELECT sum(cash) FROM users WHERE id>1);")
ac=dbc.fetchone()
if ac==None or float(ac[0])<1:
db.close()
brmPassMsg("No available money to spend")
sys.exit(EXIT_MSG)
if float(ac[0])<int(lea):
db.close()
le[1].setStyleSheet(le[1].styleSheet()+STYLE_BADLE)
return
else:
le[1].setStyleSheet(le[1].styleSheet()+STYLE_OKLE)
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP,"
" "+str(usr[0])+",0,1,"+lea+",-"+lea+");")
db.commit() # Must be before next statement
dbc.execute("INSERT INTO receipts VALUES "
"(NULL,"+str(dbc.lastrowid)+",'"+led+"');")
db.commit()
db.close()
brmPassMsg(lea+" Kc charged to "+usr[2])
sys.exit(EXIT_MSG)
dbox=QHBoxLayout()
dl=QLabel("Description")
dl.setStyleSheet(STYLE_TEXT)
dbox.addWidget(dl)
dbox.addStretch(1)
brmAddLine(dbox,"",'T',STYLE_LE,lambda:None,c=0,w=800)
sbox=QHBoxLayout()
al=QLabel("Amount")
al.setStyleSheet(STYLE_TEXT)
sbox.addWidget(al)
sbox.addStretch(1)
brmAddLine(sbox,"0",'N1',STYLE_LE,lambda:None,c=0)
ubox=QHBoxLayout()
ul=QLabel("Responsible user")
ul.setStyleSheet(STYLE_TEXT)
ubox.addWidget(ul)
ubox.addStretch(1)
brmAddLine(ubox,"",'T',STYLE_LE,lambda:None,c=0)
pbox=QHBoxLayout()
pl=QLabel("User password (if set)")
pl.setStyleSheet(STYLE_TEXT)
pbox.addWidget(pl)
pbox.addStretch(1)
brmAddLine(pbox,"","T",STYLE_LE,lambda:None,c=0)
bbox=QHBoxLayout()
bbox.addStretch(1)
brmAddButton(bbox,"Get paid",lambda:brmReceipt(mainWidget))
bbox.addStretch(1)
brmAddButton(bbox,"Cancel",lambda:sys.exit(EXIT_CANCEL))
bbox.addStretch(1)
hbox=QHBoxLayout()
hbox.addStretch(1)
hlp=QLabel("Identify the receipt (ie 'BrmbarSAP - licence fee'),\n"
"the amount from the receipt and responsible user.\n\n"
"You can NOT withdraw more than available profit\n"
"Invalid value is indicated by red background color")
hlp.setStyleSheet(STYLE_HELP)
hbox.addWidget(hlp)
hbox.addStretch(1)
screenbox=QVBoxLayout()
brmLabelBox(screenbox,"Donation to brmlab")
screenbox.addStretch(1)
screenbox.addLayout(dbox)
screenbox.addStretch(1)
screenbox.addLayout(sbox)
screenbox.addStretch(1)
screenbox.addLayout(ubox)
screenbox.addLayout(pbox)
screenbox.addStretch(1)
screenbox.addLayout(hbox)
screenbox.addStretch(3)
screenbox.addLayout(bbox)
mainWidget.setLayout(screenbox)
mainWidget.showFullScreen()
mainWidget.findChildren(QLineEdit)[3].setEchoMode(2) # Password masking
app.exec_()
sys.exit(EXIT_CANCEL)