code import

This commit is contained in:
Ruzicka Pavel 2017-12-29 18:53:46 +01:00
parent 5a102fcd5a
commit fc36d54062
18 changed files with 1809 additions and 1 deletions

91
README.md Normal file → Executable file
View file

@ -1 +1,90 @@
# brmbarSAP === BRMBARSAP ===
== INSTALLATION ==
0) Install required packages:
sqlite3
python
pyqt
1) Create sqlite3 database "brmbar.db" in the brmbarSAP directory:
$ sqlite3 ./brmbar.db < ./schema.sql
$ sqlite3 ./brmbar.db < ./stock.sql
$ sqlite3 ./brmbar.db < ./users.sql
== MIGRATION FROM brmbar3 ==
1) Export users from brmbar3 (spaghetti oneliner):
$ echo "SELECT name,crbalance FROM account_balances where acctype='debt';" | psql brmbar | head -n -2 | tail -n +3 | sed -r -e 's/[\ ]*\|[\ ]*/,/g' | sed -e "s/[a-zA-Z0-9-]*,/\'&\'/g" | sed -e "s/''//g" | sed -e "s/'-'/-/g" | sed -e "s/,'/',/g" | sed -e 's/^/INSERT INTO users VALUES (NULL,/g' | sed -e "s/$/,NULL,'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e','');/g" | sqlite3 ./brmbar.db
2) Fixup:
$ sqlite3 ./brmbar.db "UPDATE users SET code=name;"
3) Stock migration is not possible (yet) - aspon se udela inventura
== EXECUTION ==
1) Run "$ python ./brmbarsap.py"
== DESCRIPTION ==
DB tables:
users - Users defined in the system (some internal only)
stock - Stuff to be bought (some internal only)
barcodes - Barcodes assigned to particular stuff. Each item can have multiple barcodes assigned (1-n relation).
NOTE: Users have their barcodes directly in "users" table (1-1 relation).
transactions - Log of events (changes in user's credit, stock replenishment, bought stuff)
transhuman - Human readable view of "transactions" table
rechuman - Human readable view of "receipts" table
Files:
README.brm - Read it for more information
brmbarsap.py - Main application
brmstock.py - List of items in the stock
brmstockedit.py - Stock editor
brmuser.py - List of users
brmuseredit.py - User editor
brmtrans.py - Transfer credit from one user to another - easier way of negative and positive charge
brmdon.py - Donate money to brmlab
brmbuy.py - Consume, then die
brmrec.py - Receipts
fce.py - Common functions and settings
brmbar.db - sqlite3 database
/dev/shm/brmbarsap_msg - Temporary file for internal communication
schema.sql - CREATE TABLE statements
stock.sql - Default stock entries (internal ONLY)
users.sql - Default user entries (internal ONLY)
brmlab.svg - The logo (c)(r)(tm)(brm)
Scripts around:
userlog.sh USERNAME - Print out daily transaction log for given user
reports.sh - Send daily report to users which have set the email address (add it to your daily-midnight CRON)
stats.sh - Display statistics
== MICS ==
Backup:
Just copy out the brmbar.db database
Debt limit:
Users can be limited NOT to buy/transfer/donate if their credit is lower than BUY_LIMIT constant (set in fce.py)
To disable the limit, set BUY_LIMIT to insanly low value (like -999999)
Note: negative value means that the user can have DEBT up to that value
Password protection:
Users can set password to prevent unauthorized transactions
To clear password, store value of NULL512 (see fce.py) to appropriate user in "users" table
Negative sell price:
Negative price of items can NOT be set in GUI due to its "accidental enrichment" potential
You can set it manually in the "stock" table
Receipts:
Receipts can be made ONLY if profit is bigger than sum of user's credit to avoid "run on brmbar" situation.
The value of the receipt is added to the responsible user's credit
Overflow accounts:
Overflow accounts are meant for cash holders and basicaly always have negative credit (as they withdrawn money from brmbar).
Such users can withdrawn regardless of BUY_LIMIT and are listed in "brmedituser.py" in the middle of fce "brmStoreUser()".
Sum(-credit) on such accounts is equal to brmbar's disponible money.
Reports:
Users can set an email to which daily reports of their transactions will be sent (add reports.sh to your CRON)
== TODO ==
Scripts around (IRC yelling, backups, ...)

102
brmbarsap.py Executable file
View file

@ -0,0 +1,102 @@
#!/usr/bin/python
import sys
import sqlite3
from fce import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
DEBUG=1
app=QApplication(sys.argv)
msg=QLabel("")
t=QTimer()
def brmStock():
if DEBUG: print("brmStock")
rc=os.system(str("python ./brmstock.py"))
brmParseRC(rc,msg,t)
return
def brmUsers():
if DEBUG: print("brmUsers")
rc=os.system(str("python ./brmusers.py"))
brmParseRC(rc,msg,t)
return
def brmBuy(wat=""):
if DEBUG: print("brmBuy: '"+wat+"'")
rc=os.system(str("python ./brmbuy.py '"+wat+"'"))
brmParseRC(rc,msg,t)
return
def brmTransfer():
if DEBUG: print("brmTransfer")
rc=os.system(str("python ./brmtrans.py"))
brmParseRC(rc,msg,t)
return
def brmDonate():
if DEBUG: print("brmTansfer")
rc=os.system(str("python ./brmdon.py"))
brmParseRC(rc,msg,t)
return
def brmReceipt():
if DEBUG: print("brmReceipt")
rc=os.system(str("python ./brmrec.py"))
brmParseRC(rc,msg,t)
return
mainWidget=QWidget()
mainWidget.resize(1280,1024)
mainWidget.setWindowTitle("BrmbarSAP")
mainWidget.setStyleSheet(STYLE_WIDGET)
v1=QVBoxLayout()
brmAddButton(v1,"Stock",brmStock)
v1.addStretch(1)
brmAddButton(v1,"Users",brmUsers)
v2=QVBoxLayout()
v2.addStretch(1)
brmAddButton(v2,"Receipt",brmReceipt)
v2.addStretch(1)
v3=QVBoxLayout()
brmAddButton(v3,"Transfer",brmTransfer)
v3.addStretch(1)
brmAddButton(v3,"Donation",brmDonate)
bbox=QHBoxLayout()
bbox.addStretch(1)
bbox.addLayout(v1)
bbox.addStretch(1)
bbox.addLayout(v2)
bbox.addStretch(1)
bbox.addLayout(v3)
bbox.addStretch(1)
msgbox=QHBoxLayout()
msgbox.addStretch(1)
msg.setStyleSheet(STYLE_MSG)
msgbox.addWidget(msg)
msgbox.addStretch(1)
hbox=QHBoxLayout()
hbox.addStretch(1)
hlp=QLabel("Buy item by scanning its barcode\n\n"
"Read the buttons and gues what they do :)")
hlp.setStyleSheet(STYLE_HELP)
hbox.addWidget(hlp)
hbox.addStretch(1)
screenbox=QVBoxLayout()
brmLabelBox(screenbox,"Welcome in BrmBar!")
screenbox.addLayout(msgbox)
screenbox.addStretch(1)
screenbox.addLayout(hbox)
screenbox.addStretch(3)
screenbox.addLayout(bbox)
screenbox.addStretch(1)
brmAddLine(screenbox,"",'T',STYLE_LE,brmBuy,c=1,foc=1)
mainWidget.setLayout(screenbox)
mainWidget.showFullScreen()
app.exec_()

165
brmbuy.py Executable file
View file

@ -0,0 +1,165 @@
#!/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)

115
brmdon.py Executable file
View file

@ -0,0 +1,115 @@
#!/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 - Donation")
mainWidget.setStyleSheet(STYLE_WIDGET)
def brmDonate(mw=None,c=0):
if DEBUG: print("brmDonate")
les=mw.findChildren(QLineEdit)
cash=str(les[0].text())
pswd=hashlib.sha512(brmSatanize(les[1].text())).hexdigest()
code=brmSatanize(les[-1].text())
if cash=="0":
les[0].setStyleSheet(les[0].styleSheet()+STYLE_BADLE)
return
else:
les[0].setStyleSheet(les[0].styleSheet()+STYLE_OKLE)
if code=="" and c==1:
return # Accidental double-enter
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
if code!="":
dbc.execute("SELECT id,cash,pass FROM users WHERE"
" code='"+code+"' LIMIT 1;")
usr=dbc.fetchone()
if usr==None:
les[-1].setText("")
db.close()
return
if usr[1]<=BUY_LIMIT:
db.close()
sys.exit(EXIT_NOCREDIT)
if usr[2]!=pswd:
db.close()
les[1].setStyleSheet(les[1].styleSheet()+STYLE_BADLE)
return
else:
les[1].setStyleSheet(les[1].styleSheet()+STYLE_OKLE)
dbc.execute("UPDATE users SET cash=cash-"+cash+" WHERE id="+str(usr[0])+""
" LIMIT 1;")
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP"
","+str(usr[0])+",1,1,"+cash+","+cash+");")
else:
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP"
",0,1,1,"+cash+","+cash+");")
db.commit()
db.close()
sys.exit(EXIT_DONATION)
sbox=QHBoxLayout()
al=QLabel("Amount")
al.setStyleSheet(STYLE_TEXT)
sbox.addWidget(al)
sbox.addStretch(1)
brmAddLine(sbox,"0",'N0',STYLE_LE,lambda:QTimer.singleShot(0,
mainWidget.findChildren(QLineEdit)[-1],SLOT('setFocus()')),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:QTimer.singleShot(0,
mainWidget.findChildren(QLineEdit)[-1],SLOT('setFocus()')),c=0)
bbox=QHBoxLayout()
bbox.addStretch(1)
brmAddButton(bbox,"Donate cash",lambda:brmDonate(mainWidget,0))
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 donate to brmlab.\n\n"
"You can either 'Donate cash', or scan your barcode to donate 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,"Donation to brmlab")
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:brmDonate(mainWidget,1))
mainWidget.setLayout(screenbox)
mainWidget.showFullScreen()
mainWidget.findChildren(QLineEdit)[1].setEchoMode(2) # Password masking
app.exec_()
sys.exit(EXIT_CANCEL)

160
brmeditstock.py Executable file
View file

@ -0,0 +1,160 @@
#!/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 - Edit stuff")
mainWidget.setStyleSheet(STYLE_WIDGET)
def brmStoreStock(mw=None):
if DEBUG: print("brmStoreStock")
s=mw.findChildren(QLineEdit)
sname=brmSatanize(s[0].text())
sam=int(s[1].text())
sbuy=float(s[2].text())
ssell=float(s[3].text())
scode=s[4].text() # do NOT satanize!
sid=brmSatanize(s[5].text())
if ssell<sbuy or ssell>2*sbuy: # Check reasonable profit
s[3].setStyleSheet(s[3].styleSheet()+STYLE_BADLE)
return
else:
s[3].setStyleSheet(s[3].styleSheet()+STYLE_OKLE)
if sname=="": # Name required
s[0].setStyleSheet(s[0].styleSheet()+STYLE_BADLE)
return
else:
s[0].setStyleSheet(s[0].styleSheet()+STYLE_OKLE)
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
# Prevent 2 items with same name
dbc.execute("SELECT id FROM stock WHERE name='"+sname+"';")
dbn=dbc.fetchone()
if dbn!=None and str(dbn[0])!=sid:
db.close()
s[0].setStyleSheet(s[0].styleSheet()+STYLE_BADLE)
return
else:
s[0].setStyleSheet(s[0].styleSheet()+STYLE_OKLE)
if sid=="0":
dbc.execute("INSERT INTO stock VALUES (NULL,'"+sname+"',"
" "+str(sam)+","+str(sbuy)+","+str(ssell)+");")
lst=str(dbc.lastrowid)
else:
dbc.execute("UPDATE stock SET name='"+sname+"',"
"quan=quan+("+str(sam)+"),buyprice="+str(sbuy)+","
"sellprice="+str(ssell)+" WHERE id="+str(sid)+" LIMIT 1;")
lst=sid
dbc.execute("DELETE FROM barcodes WHERE stock="+sid+";")
if scode!="":
codes=scode.split(';')
for cde in codes:
dbc.execute("INSERT INTO barcodes VALUES (NULL,"+lst+",'"+str(cde)+"');")
dbc.execute("INSERT INTO TRANSACTIONS VALUES(NULL,CURRENT_TIMESTAMP,1,"
" "+sid+","+str(sam)+","+str(sbuy*sam)+",0);")
db.commit()
db.close()
brmPassMsg("Stock saved! Take "+str(int(sam*sbuy))+" Kc")
sys.exit(EXIT_MSG)
bbox=QHBoxLayout()
bbox.addStretch(1)
brmAddButton(bbox,"Save",lambda:brmStoreStock(mainWidget))
bbox.addStretch(1)
brmAddButton(bbox,"Cancel",lambda:sys.exit(EXIT_CANCEL))
bbox.addStretch(1)
ename=QHBoxLayout()
ename.addStretch(1)
brmAddLine(ename,brmSatanize(sys.argv[2]),'T',STYLE_LE,None,c=0,foc=0,w=600)
ename.addStretch(1)
equan=QHBoxLayout()
al=QLabel("Restock (now "+str(int(brmSatanize(sys.argv[3])))+")")
al.setStyleSheet(STYLE_TEXT)
equan.addWidget(al)
equan.addStretch(1)
brmAddLine(equan,"0","N",STYLE_LE,None,c=0,foc=0)
ebuy=QHBoxLayout()
bl=QLabel("Buy price")
bl.setStyleSheet(STYLE_TEXT)
ebuy.addWidget(bl)
ebuy.addStretch(1)
brmAddLine(ebuy,str(float(brmSatanize(sys.argv[4]))),
"Q+",STYLE_LE,None,c=0,foc=0)
esell=QHBoxLayout()
sl=QLabel("Sell price")
sl.setStyleSheet(STYLE_TEXT)
esell.addWidget(sl)
esell.addStretch(1)
brmAddLine(esell,str(float(brmSatanize(sys.argv[5]))),
"Q+",STYLE_LE,None,c=0,foc=0)
ecode=QHBoxLayout()
cl=QLabel("Barcodes")
cl.setStyleSheet(STYLE_TEXT)
ecode.addWidget(cl)
ecode.addStretch(1)
brmAddLine(ecode,"","T",STYLE_LE,None,c=0,foc=0)
hbox=QHBoxLayout()
hbox.addStretch(1)
hlp=QLabel("Restock existing stuff or enter new one\n\n"
"'Buy price' is the price you want to get back for 1 item\n"
"'Sell price' is the price for which brmbar will sell 1 item\n"
"Set 'Sell' higher than 'Buy price' - give brmbar reasonable profit\n\n"
"Put cursor to 'Barcodes' and scan the barcode of the item\n"
"If there are more different barcodes, split them by ';'\n\n"
"Invalid value is indicated by red background color")
hlp.setStyleSheet(STYLE_HELP)
hbox.addWidget(hlp)
hbox.addStretch(1)
screenbox=QVBoxLayout()
brmLabelBox(screenbox,"Edit item")
screenbox.addLayout(ename)
screenbox.addLayout(equan)
screenbox.addLayout(ebuy)
screenbox.addLayout(esell)
screenbox.addLayout(ecode)
screenbox.addStretch(1)
screenbox.addLayout(hbox)
screenbox.addStretch(3)
screenbox.addLayout(bbox)
# Stores ID of the stock or NULL if new stuff - do nothing, button does it
brmAddLine(screenbox,brmSatanize(sys.argv[1]),'T',STYLE_HIDDEN,None)
mainWidget.setLayout(screenbox)
mainWidget.showFullScreen()
levalue4=mainWidget.findChildren(QLineEdit)[4]
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
for c in dbc.execute("SELECT code FROM barcodes WHERE stock="
""+brmSatanize(sys.argv[1])+";"):
if levalue4.text()=="":
levalue4.setText(brmSatanize(str(c[0])))
else:
levalue4.setText(levalue4.text()+","+brmSatanize(c[0]))
db.close()
app.exec_()
sys.exit(EXIT_CANCEL)

178
brmedituser.py Executable file
View file

@ -0,0 +1,178 @@
#!/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 - Edit user")
mainWidget.setStyleSheet(STYLE_WIDGET)
said=str(int(sys.argv[1]))
san=brmSatanize(sys.argv[2])
sac=str(float(sys.argv[3]))
sam=brmSatanize(sys.argv[4])
def brmStoreUser(mw=None):
if DEBUG: print("brmStoreUser")
le=mw.findChildren(QLineEdit)
leid=str(le[-1].text())
lename=brmSatanize(le[0].text())
lecash=str(le[1].text())
lepass=hashlib.sha512(brmSatanize(le[2].text())).hexdigest()
lenewpass=hashlib.sha512(brmSatanize(le[3].text())).hexdigest()
lemail=str(le[4].text())
if lename=="":
le[0].setStyleSheet(le[0].styleSheet()+STYLE_BADLE)
return
else:
le[0].setStyleSheet(le[0].styleSheet()+STYLE_OKLE)
if lecash=="":
lecash="0"
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
# Usename already used?
dbc.execute("SELECT id FROM users WHERE name='"+lename+"';")
cname=dbc.fetchone()
if cname!=None and str(cname[0])!=leid:
db.close()
le[0].setStyleSheet(le[0].styleSheet()+STYLE_BADLE)
return
else:
le[0].setStyleSheet(le[0].styleSheet()+STYLE_OKLE)
if leid=="0": # New user?
dbc.execute("INSERT INTO users VALUES (NULL,'"+lename+"',"+lecash+","
"'"+lename+"','"+lenewpass+"','"+lemail+"');")
db.commit() # Sync required before next insert
if lecash!="0": # New credit?
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP,"
"(SELECT id FROM users WHERE name='"+lename+"' LIMIT 1),"
"0,1,"+lecash+",0);")
else: # Existing user
dbc.execute("SELECT pass,cash FROM users WHERE id="+leid+" LIMIT 1;")
pswddb=dbc.fetchone()
if lepass!=pswddb[0] and pswddb[0]!=NULL512:
db.close()
le[2].setText("")
le[2].setStyleSheet(le[2].styleSheet()+STYLE_BADLE)
return
else:
le[2].setStyleSheet(le[2].styleSheet()+STYLE_OKLE)
if lename!="sachy_overflow": # Allow overflowers ignore the limit
if ((int(pswddb[1])<BUY_LIMIT and int(lecash)<0) or
int(pswddb[1])+int(lecash)<BUY_LIMIT):
le[1].setStyleSheet(le[1].styleSheet()+STYLE_BADLE)
db.close()
return
else:
le[1].setStyleSheet(le[1].styleSheet()+STYLE_OKLE)
if lecash!="0": # Charge/withdrawal?
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP,"
" "+leid+",0,1,"+lecash+",0);")
zasranypython=" " if lenewpass==NULL512 else "pass='"+lenewpass+"',"
dbc.execute("UPDATE users SET name='"+lename+"',cash=cash+("+lecash+"),"
" "+zasranypython+" code='"+lename+"', mail='"+lemail+"' "
"WHERE id="+leid+" LIMIT 1;")
db.commit()
db.close()
sys.exit(EXIT_USER)
bbox=QHBoxLayout()
bbox.addStretch(1)
brmAddButton(bbox,"Save",lambda:brmStoreUser(mainWidget))
bbox.addStretch(1)
brmAddButton(bbox,"Cancel",lambda:sys.exit(EXIT_CANCEL))
bbox.addStretch(1)
ename=QHBoxLayout()
ename.addStretch(1)
brmAddLine(ename,san,
'T',STYLE_LE,None,c=0,foc=0,w=800)
ename.addStretch(1)
ecash=QHBoxLayout()
cl=QLabel("Charge credit (now "+sac+")")
cl.setStyleSheet(STYLE_TEXT)
ecash.addWidget(cl)
ecash.addStretch(1)
brmAddLine(ecash,"0","N",STYLE_LE,None,c=0,foc=0)
ecode=QHBoxLayout()
bl=QLabel("Assigned barcode")
bl.setStyleSheet(STYLE_TEXT)
ecode.addWidget(bl)
ecode.addStretch(1)
bl2=QLabel(san)
bl2.setStyleSheet(STYLE_TEXT+"margin-right:100px;")
ecode.addWidget(bl2)
epass=QHBoxLayout()
pl=QLabel("Password (if set)")
pl.setStyleSheet(STYLE_TEXT)
epass.addWidget(pl)
epass.addStretch(1)
brmAddLine(epass,"","T",STYLE_LE,None,c=0,foc=0)
enpass=QHBoxLayout()
pnl=QLabel("New password?")
pnl.setStyleSheet(STYLE_TEXT)
enpass.addWidget(pnl)
enpass.addStretch(1)
brmAddLine(enpass,"","T",STYLE_LE,None,c=0,foc=0)
email=QHBoxLayout()
pm=QLabel("Send daily reports to:")
pm.setStyleSheet(STYLE_TEXT)
email.addWidget(pm)
email.addStretch(1)
brmAddLine(email,sam,'M',STYLE_LE,None,c=0,foc=0,w=500)
hbox=QHBoxLayout()
hbox.addStretch(1)
hlp=QLabel("Fill out name for a new user or edit the existing one\n\n"
"You can 'Charge' or 'Withdraw' credit by adding/substracting the Credit\n\n"
"If you are setting the password for the 1st time, leave the upper clear\n\n"
"Fill your mail to receive daily transaction reports\n\n"
"Invalid value is indicated by red background color")
hlp.setStyleSheet(STYLE_HELP)
hbox.addWidget(hlp)
hbox.addStretch(1)
screenbox=QVBoxLayout()
brmLabelBox(screenbox,"Edit user")
screenbox.addLayout(ename)
screenbox.addLayout(ecash)
screenbox.addLayout(ecode)
screenbox.addLayout(epass)
screenbox.addLayout(enpass)
screenbox.addLayout(email)
screenbox.addStretch(1)
screenbox.addLayout(hbox)
screenbox.addStretch(3)
screenbox.addLayout(bbox)
brmAddLine(screenbox,said,'T',STYLE_HIDDEN,None)
mainWidget.setLayout(screenbox)
mainWidget.showFullScreen()
pf=mainWidget.findChildren(QLineEdit)
pf[2].setEchoMode(2) # Password masking
pf[3].setEchoMode(2)
app.exec_()
sys.exit(EXIT_CANCEL)

189
brmlab.svg Executable file
View file

@ -0,0 +1,189 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xml:space="preserve"
height="96"
width="400"
version="1.1"
id="svg2"
inkscape:version="0.47 r22583"
sodipodi:docname="brmlab.svg"><metadata
id="metadata78"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><sodipodi:namedview
pagecolor="#000000"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1024"
inkscape:window-height="720"
id="namedview76"
showgrid="false"
inkscape:zoom="2"
inkscape:cx="208.2391"
inkscape:cy="36.746036"
inkscape:window-x="-3"
inkscape:window-y="-3"
inkscape:window-maximized="1"
inkscape:current-layer="svg2"
inkscape:snap-bbox="true"
inkscape:snap-global="true" />
<defs
id="defs4"><inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 48 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="400 : 48 : 1"
inkscape:persp3d-origin="200 : 32 : 1"
id="perspective80" />
</defs>
<path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 138.5235,47.9225 c -0.80875,2.085 -1.82875,3.32875 -2.725,3.32875 -7.195,0 -24.94,0.0225 -31.97375,0.03125 l 0,-27.4475 31.97375,0.0012 c 1.815,0 4.34625,5.215 4.34625,13.7075 0,3.94625 -0.5925,7.73 -1.62125,10.37875 m 5.475,-22.88625 c -2.39375,-6.155 -6.16375,-7.075 -8.2,-7.075 l -31.97375,-0.0025 0,-12.80625 -5.875,0 0,52.0125 2.9425,-0.0037 c 0,0 25.835,-0.03625 34.90625,-0.03625 2.03625,0 5.80625,-0.9175 8.2,-7.0725 1.30375,-3.35125 2.02,-7.7925 2.02,-12.50875 0,-4.715 -0.71625,-9.1575 -2.02,-12.5075"
id="path10" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 389.4235,47.9225 c -0.80875,2.085 -1.82875,3.32875 -2.7225,3.32875 -7.1975,0 -24.94125,0.0225 -31.97625,0.03125 l 0,-27.4475 31.97625,0.0012 c 1.81375,0 4.345,5.215 4.345,13.7075 0,3.94625 -0.5925,7.73 -1.6225,10.37875 m 5.47625,-22.88625 c -2.39375,-6.155 -6.165,-7.075 -8.19875,-7.075 l -31.97625,-0.0025 0,-12.80625 -5.87375,0 0,52.0125 2.94125,-0.0037 c 0,0 25.83625,-0.03625 34.90875,-0.03625 2.03375,0 5.805,-0.9175 8.19875,-7.0725 1.30375,-3.35125 2.02,-7.7925 2.02,-12.50875 0,-4.715 -0.71625,-9.1575 -2.02,-12.5075"
id="path12" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 301.7235,23.835 c -0.89625,0 -1.91375,1.24375 -2.725,3.32875 -1.03,2.64875 -1.62125,6.43125 -1.62125,10.37875 0,8.4925 2.53125,13.7075 4.34625,13.7075 7.19625,0 24.94,0.0225 31.975,0.03125 l 0,-27.44625 -31.975,0 z m 37.84875,33.32875 -2.94,-0.0038 c 0,0 -25.83625,-0.035 -34.90875,-0.035 -2.035,0 -5.80625,-0.91875 -8.2,-7.07375 -1.3025,-3.35125 -2.02,-7.7925 -2.02,-12.50875 0,-4.715 0.7175,-9.1575 2.02,-12.5075 2.39375,-6.155 6.165,-7.075 8.2,-7.075 l 34.9125,0 2.91979,0.0058 0.0165,39.198 z"
id="path14"
sodipodi:nodetypes="cssscccccssssccc" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 277.2735,57.16 5.874,0 0,-52.0075 -5.874,0 0,52.0075 z"
id="path16" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 191.061,23.06 c -1.0075,-1.47125 -2.7675,-2.98 -5.79125,-4.15625 -3.35,-1.3025 -7.79375,-2.02 -12.50875,-2.02 -4.715,0 -9.15875,0.7175 -12.5075,2.02 -6.155,2.39375 -7.07375,6.16375 -7.07375,8.19875 0,9.87875 -0.0175,30.04875 -0.0175,30.04875 l 5.87375,0.005 c 0,0 0.0175,-20.17375 0.0175,-30.05375 0,-1.81375 5.21375,-4.345 13.7075,-4.345 3.9475,0 7.73,0.59 10.37875,1.62125 1.58875,0.6175 2.6875,1.355 3.1225,2.0675 L 191.061,23.06 z"
id="path18" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 234.6235,27.11 c 0,-1.815 5.24,-4.345 13.73375,-4.345 3.94875,0 7.73,0.59 10.37875,1.62 2.085,0.81125 3.32875,1.83 3.32875,2.725 0,9.0725 0.0188,30.05375 0.0188,30.05375 L 267.956,57.16 c 0,-0.0012 -0.0175,-20.97875 -0.0175,-30.05 0,-2.035 -0.9175,-5.805 -7.0725,-8.2 -3.35125,-1.3025 -7.7925,-2.01875 -12.50875,-2.01875 -4.71625,0 -9.15875,0.71625 -12.50875,2.01875 -1.7975,0.7 -3.16375,1.50625 -4.175,2.3625 -1.01,-0.8475 -2.3675,-1.66875 -4.15,-2.3625 -3.34875,-1.3025 -7.79125,-2.01875 -12.50875,-2.01875 -4.715,0 -9.15625,0.71625 -12.50625,2.01875 -6.15625,2.395 -7.075,6.165 -7.075,8.2 0,9.8775 -0.0163,30.04875 -0.0163,30.04875 l 5.87375,0.005 c 0,0 0.0175,-20.17375 0.0175,-30.05375 0,-1.815 5.215,-4.345 13.70625,-4.345 3.94875,0 7.73125,0.59 10.38,1.62 2.08375,0.81125 3.32875,1.83 3.32875,2.725 0,9.0725 0.0175,30.0575 0.0175,30.0575 l 5.87375,-0.005 c 0,0 0.009,-20.98125 0.009,-30.0525"
id="path20" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 44.7185,8.4475 c -19.99875,0 -36.2675,16.27125 -36.2675,36.27 0,9.6875 3.7725,18.795 10.6225,25.645 6.85125,6.85 15.9575,10.6225 25.645,10.6225 19.99875,0 36.27,-16.27 36.27,-36.2675 -0.0012,-20 -16.27125,-36.27 -36.27,-36.27 m 0,77.91 c -11.12125,0 -21.58,-4.33125 -29.44375,-12.19625 C 7.40975,66.29625 3.0785,55.84 3.0785,44.7175 c 0,-22.96125 18.68,-41.64125 41.64,-41.6425 22.96125,0 41.64125,18.68 41.64125,41.6425 0,22.96 -18.68,41.64 -41.64125,41.64"
id="path22" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 29.611,69.135 c 4.505,2.77875 9.67125,4.24125 15.015,4.24125 5.34375,0 10.51125,-1.4625 15.01625,-4.24125 -1.4825,-2.65375 -1.06625,-6.01 1.16125,-8.2375 1.305,-1.305 3.04,-2.02375 4.885,-2.02375 1.1775,0 2.33125,0.3025 3.34875,0.865 6.91875,-11.21625 5.2525,-25.8825 -4.14625,-35.2825 -3.775,-3.775 -8.46375,-6.3925 -13.61875,-7.615 -0.82875,2.92375 -3.49625,5.0025 -6.645,5.0025 -3.14875,0 -5.81625,-2.07875 -6.645,-5.0025 -5.155,1.2225 -9.845,3.84125 -13.61875,7.61625 -9.40125,9.4 -11.0675,24.065 -4.15,35.28125 1.01875,-0.5625 2.17375,-0.865 3.35,-0.865 1.84625,0 3.58,0.71875 4.88625,2.02375 2.22875,2.2275 2.645,5.58375 1.16125,8.2375 m 15.01375,6.50125 c -6.17625,0 -12.135,-1.8125 -17.2325,-5.24125 l -1.0375,-0.69625 0.795,-0.96125 C 28.681,66.88125 28.55225,64.2 26.8485,62.49625 25.971,61.61875 24.8035,61.135 23.56225,61.135 c -1.0775,0 -2.12625,0.37625 -2.95375,1.05875 L 19.646,62.9875 18.94975,61.9525 C 10.7285,49.73 12.331,33.2875 22.76225,22.8575 27.12475,18.4925 32.621,15.56125 38.656,14.37875 l 1.225,-0.23875 0.12,1.24125 c 0.22875,2.39375 2.2175,4.19875 4.625,4.19875 2.4075,0 4.39625,-1.805 4.62625,-4.19875 l 0.12,-1.24125 1.22375,0.23875 c 6.0325,1.1825 11.53,4.11375 15.89375,8.47625 10.43,10.43125 12.03375,26.875 3.81125,39.0975 l -0.69625,1.035 -0.96125,-0.795 C 67.8135,61.51 66.766,61.135 65.68725,61.135 c -1.24125,0 -2.4075,0.4825 -3.28625,1.36 -1.7025,1.70375 -1.83125,4.38625 -0.30125,6.2425 l 0.79375,0.96125 -1.035,0.69625 C 56.761,73.82375 50.801,75.63625 44.62475,75.63625"
id="path24" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 29.361,29.9225 c -1.17375,0 -2.12875,0.955 -2.12875,2.13 0,1.17375 0.955,2.12875 2.12875,2.12875 1.1725,0 2.12875,-0.955 2.12875,-2.12875 0,-1.175 -0.95625,-2.13 -2.12875,-2.13 m 0,6.52 c -2.4225,0 -4.3925,-1.97 -4.3925,-4.39125 0,-2.42125 1.97,-4.3925 4.3925,-4.3925 2.42125,0 4.39125,1.97125 4.39125,4.3925 0,2.42125 -1.97,4.39125 -4.39125,4.39125"
id="path26" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 25.501,45.1975 c -1.17375,0 -2.12875,0.955 -2.12875,2.13 0,1.175 0.955,2.12875 2.12875,2.12875 1.17375,0 2.13,-0.95375 2.13,-2.12875 0,-1.175 -0.95625,-2.13 -2.13,-2.13 m 0,6.52125 c -2.4225,0 -4.39125,-1.97 -4.39125,-4.39125 0,-2.42125 1.96875,-4.3925 4.39125,-4.3925 2.4225,0 4.3925,1.97125 4.3925,4.3925 0,2.42125 -1.97,4.39125 -4.3925,4.39125"
id="path28" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 63.7485,45.1975 c -1.1725,0 -2.13,0.955 -2.13,2.13 0,1.175 0.9575,2.12875 2.13,2.12875 1.17375,0 2.13,-0.95375 2.13,-2.12875 0,-1.175 -0.95625,-2.13 -2.13,-2.13 m 0,6.52125 c -2.42125,0 -4.3925,-1.97 -4.3925,-4.39125 0,-2.42125 1.97125,-4.3925 4.3925,-4.3925 2.4225,0 4.3925,1.97125 4.3925,4.3925 0,2.42125 -1.97,4.39125 -4.3925,4.39125"
id="path30" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 36.84225,60.385 c -1.17375,0 -2.1275,0.955 -2.1275,2.13 0,1.17375 0.95375,2.12875 2.1275,2.12875 1.17375,0 2.13,-0.955 2.13,-2.12875 0,-1.175 -0.95625,-2.13 -2.13,-2.13 m 0,6.52125 c -2.42125,0 -4.39,-1.97 -4.39,-4.39125 0,-2.42125 1.96875,-4.3925 4.39,-4.3925 2.4225,0 4.3925,1.97125 4.3925,4.3925 0,2.42125 -1.97,4.39125 -4.3925,4.39125"
id="path32" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 59.886,29.9225 c -1.17375,0 -2.13,0.955 -2.13,2.13 0,1.17375 0.95625,2.12875 2.13,2.12875 1.17375,0 2.1275,-0.955 2.1275,-2.12875 0,-1.175 -0.95375,-2.13 -2.1275,-2.13 m 0,6.52 c -2.4225,0 -4.3925,-1.97 -4.3925,-4.39125 0,-2.42125 1.97,-4.3925 4.3925,-4.3925 2.42125,0 4.39,1.97125 4.39,4.3925 0,2.42125 -1.96875,4.39125 -4.39,4.39125"
id="path34" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 52.411,60.385 c -1.17375,0 -2.13,0.95625 -2.13,2.13 0,1.17375 0.95625,2.12875 2.13,2.12875 1.1725,0 2.12875,-0.955 2.12875,-2.12875 0,-1.17375 -0.95625,-2.13 -2.12875,-2.13 m 0,6.52125 c -2.4225,0 -4.3925,-1.97 -4.3925,-4.39125 0,-2.42125 1.97,-4.3925 4.3925,-4.3925 2.42125,0 4.39125,1.97125 4.39125,4.3925 0,2.42125 -1.97,4.39125 -4.39125,4.39125"
id="path36" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 44.636,29.9225 c -1.17375,0 -2.13,0.955 -2.13,2.13 0,1.17375 0.95625,2.12875 2.13,2.12875 1.1725,0 2.12875,-0.955 2.12875,-2.12875 0,-1.175 -0.95625,-2.13 -2.12875,-2.13 m 0,6.52 c -2.4225,0 -4.3925,-1.97 -4.3925,-4.39125 0,-2.42125 1.97,-4.3925 4.3925,-4.3925 2.42125,0 4.39125,1.97125 4.39125,4.3925 0,2.42125 -1.97,4.39125 -4.39125,4.39125"
id="path38" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 38.596,47.2975 12.0775,0 0,-5.075 -12.0775,0 0,5.075 z m 14.34,2.2625 -16.60125,0 0,-9.59875 16.60125,0 0,9.59875 z"
id="path40" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 98.0985,67.81 2.72625,0 0,6.13125 c 1.13875,-1.38875 2.5525,-2.0825 4.23875,-2.0825 0.92,0 1.74375,0.23 2.47375,0.69 0.7275,0.45875 1.27,1.0925 1.625,1.9025 0.355,0.8075 0.53125,2.0125 0.53125,3.61 l 0,7.85 -2.72625,0 0,-8.52375 c 0,-1.00875 -0.2475,-1.82125 -0.74125,-2.435 -0.495,-0.61375 -1.14625,-0.92125 -1.955,-0.92125 -0.59875,0 -1.16375,0.155 -1.69375,0.465 -0.53,0.30875 -1.11375,0.82375 -1.7525,1.5425 l 0,9.8725 -2.72625,0 0,-18.10125 z"
id="path42" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 122.2485,83.185 0,-4.08875 L 120.421,79.8 c -0.92875,0.36875 -1.585,0.74125 -1.97,1.11625 -0.385,0.37375 -0.5775,0.84125 -0.5775,1.4 0,0.56875 0.1825,1.03375 0.54625,1.39375 0.365,0.35875 0.8375,0.53875 1.41625,0.53875 0.87,0 1.6725,-0.355 2.4125,-1.06375 m 2.6825,-5.55875 0,5.85875 c 0,0.47 0.15875,0.70375 0.47875,0.70375 0.33,0 0.84375,-0.245 1.54375,-0.73375 l 0,1.6625 c -0.61875,0.4 -1.11625,0.67125 -1.4925,0.8175 -0.37375,0.14375 -0.76625,0.21625 -1.175,0.21625 -1.16875,0 -1.8575,-0.45875 -2.0675,-1.3775 -1.15875,0.8975 -2.3925,1.3475 -3.7,1.3475 -0.95875,0 -1.75875,-0.31625 -2.39625,-0.95125 -0.64,-0.63375 -0.96,-1.43125 -0.96,-2.38875 0,-0.87 0.3125,-1.64625 0.9375,-2.33 0.62375,-0.68375 1.51,-1.22625 2.65875,-1.625 l 3.49,-1.2 0,-0.73375 c 0,-1.6575 -0.82875,-2.48625 -2.48625,-2.48625 -1.49,0 -2.93625,0.76875 -4.345,2.3075 l 0,-2.9825 c 1.05875,-1.24875 2.5825,-1.8725 4.56875,-1.8725 1.48875,0 2.6825,0.38875 3.58125,1.16875 0.3,0.25 0.57,0.5825 0.80875,0.99625 0.24125,0.415 0.3925,0.82875 0.45625,1.24375 0.065,0.415 0.0987,1.20125 0.0987,2.35875"
id="path44" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 142.461,82.685 0,2.6975 c -1.36875,0.50875 -2.7075,0.76375 -4.015,0.76375 -2.1575,0 -3.87625,-0.64 -5.16125,-1.9175 -1.2825,-1.27875 -1.925,-2.9925 -1.925,-5.13875 0,-2.1675 0.62375,-3.915 1.8725,-5.24375 1.2475,-1.32875 2.8925,-1.9925 4.93,-1.9925 0.7075,0 1.34625,0.0675 1.91,0.20125 0.56375,0.135 1.26,0.3875 2.09,0.7575 l 0,2.90625 c -1.37875,-0.87875 -2.6575,-1.3175 -3.83625,-1.3175 -1.2275,0 -2.2375,0.43125 -3.02625,1.295 -0.78875,0.865 -1.18375,1.965 -1.18375,3.30375 0,1.4075 0.4275,2.52625 1.2825,3.355 0.8525,0.83 2.00375,1.24375 3.45125,1.24375 1.05,0 2.2525,-0.30375 3.61125,-0.91375"
id="path46" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 157.2985,72.1225 3.2375,0 -5.88,6.7425 7.07875,7.04125 -3.65875,0 -6.9025,-7.035 6.125,-6.74875 z m -8.9725,-4.31875 2.7275,0 0,18.10125 -2.7275,0 0,-18.10125 z"
id="path48" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 167.8985,77.6225 6.93625,0 c -0.07,-1.08875 -0.395,-1.9275 -0.97375,-2.51625 -0.57875,-0.58875 -1.3575,-0.885 -2.3375,-0.885 -0.97875,0 -1.78,0.29625 -2.40375,0.885 -0.62375,0.58875 -1.0325,1.4275 -1.22125,2.51625 m -0.0613,1.63375 c 0.07,1.3175 0.51125,2.36625 1.32625,3.14625 0.81375,0.77875 1.865,1.1675 3.1525,1.1675 1.79875,0 3.45625,-0.55875 4.975,-1.6775 l 0,2.66625 c -0.83875,0.56 -1.67125,0.96 -2.49375,1.19875 -0.82625,0.24 -1.79125,0.36 -2.9,0.36 -1.51875,0 -2.74625,-0.315 -3.685,-0.94375 -0.94,-0.62875 -1.69125,-1.47625 -2.25625,-2.53875 -0.56375,-1.065 -0.845,-2.295 -0.845,-3.69375 0,-2.0975 0.59375,-3.8025 1.7825,-5.11625 1.1875,-1.31375 2.73125,-1.97 4.62875,-1.97 1.8275,0 3.285,0.64 4.375,1.9175 1.08875,1.27875 1.62692,3.336068 1.62692,5.483568 l -9.68692,1.82e-4 z"
id="path50"
sodipodi:nodetypes="ccsssccssccssssssssc" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 186.161,72.1225 0,3.16125 0.15125,-0.24 c 1.31875,-2.1275 2.635,-3.19 3.95375,-3.19 1.02875,0 2.1025,0.51875 3.22125,1.5575 l -1.4375,2.3975 c -0.95,-0.9 -1.82875,-1.34875 -2.6375,-1.34875 -0.87875,0 -1.64,0.42 -2.285,1.2575 -0.6425,0.84 -0.96625,1.83375 -0.96625,2.9825 l 0,7.20625 -2.74,0 0,-13.78375 2.74,0 z"
id="path52" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 197.4735,84.9225 0,-2.93625 c 0.7675,0.53875 1.55375,0.97625 2.35875,1.31 0.80375,0.335 1.48,0.5025 2.03,0.5025 0.57,0 1.05875,-0.14 1.46875,-0.42 0.40875,-0.27875 0.61375,-0.61375 0.61375,-1.00375 0,-0.39875 -0.1325,-0.73125 -0.3975,-0.995 -0.26375,-0.265 -0.83625,-0.6475 -1.715,-1.14625 -1.7575,-0.98 -2.90875,-1.81625 -3.4525,-2.51 -0.545,-0.69375 -0.8175,-1.45 -0.8175,-2.27 0,-1.0575 0.4125,-1.9225 1.2375,-2.59125 0.82375,-0.67 1.88375,-1.00375 3.1825,-1.00375 1.34875,0 2.73125,0.38 4.15125,1.1375 l 0,2.6975 C 204.51475,74.715 203.18975,74.225 202.16225,74.225 c -0.53,0 -0.95625,0.1125 -1.28125,0.3375 -0.325,0.22625 -0.48625,0.5225 -0.48625,0.8925 0,0.32125 0.14625,0.625 0.44,0.915 0.295,0.29 0.81125,0.64 1.55125,1.04875 l 0.97375,0.55375 c 2.2975,1.29875 3.44625,2.73625 3.44625,4.315 0,1.1275 -0.4425,2.05375 -1.32625,2.7775 -0.8825,0.72375 -2.01875,1.085 -3.4075,1.085 -0.82,0 -1.55,-0.08625 -2.1875,-0.26125 -0.63875,-0.175 -1.44375,-0.4975 -2.41125,-0.96625"
id="path54" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 217.2485,74.6725 -1.92875,0 0,8.48 c 0.8375,0.42875 1.71375,0.64375 2.6325,0.64375 1.275,0 2.31875,-0.445 3.13,-1.33375 0.81375,-0.88875 1.21875,-2.0325 1.21875,-3.43 0,-0.89875 -0.19125,-1.6925 -0.575,-2.38125 -0.38375,-0.69 -0.9075,-1.1925 -1.57,-1.50625 -0.6625,-0.315 -1.63125,-0.4725 -2.9075,-0.4725 m -4.71375,16.56625 0,-19.11375 4.7725,0 c 2.44375,0 4.34625,0.61 5.7075,1.82875 1.3625,1.21875 2.04375,2.92125 2.04375,5.10875 0,2.0675 -0.6425,3.765 -1.9225,5.0925 -1.28125,1.32875 -2.915,1.99375 -4.89875,1.99375 -0.8775,0 -1.84875,-0.19625 -2.9175,-0.585 l 0,5.675 -2.785,0 z"
id="path56" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 236.7985,83.185 0,-4.08875 -1.82625,0.70375 c -0.92875,0.36875 -1.585,0.74125 -1.97,1.11625 -0.385,0.37375 -0.5775,0.84125 -0.5775,1.4 0,0.56875 0.1825,1.03375 0.54625,1.39375 0.365,0.35875 0.83625,0.53875 1.41625,0.53875 0.87,0 1.67375,-0.355 2.41125,-1.06375 m 2.6825,-5.55875 0,5.85875 c 0,0.47 0.15875,0.70375 0.48,0.70375 0.33,0 0.84375,-0.245 1.54375,-0.73375 l 0,1.6625 c -0.61875,0.4 -1.1175,0.67125 -1.4925,0.8175 -0.375,0.14375 -0.76625,0.21625 -1.175,0.21625 -1.16875,0 -1.8575,-0.45875 -2.0675,-1.3775 -1.15875,0.8975 -2.3925,1.3475 -3.7,1.3475 -0.95875,0 -1.75875,-0.31625 -2.39625,-0.95125 -0.64,-0.63375 -0.96,-1.43125 -0.96,-2.38875 0,-0.87 0.3125,-1.64625 0.9375,-2.33 0.62375,-0.68375 1.51,-1.22625 2.65875,-1.625 l 3.48875,-1.2 0,-0.73375 c 0,-1.6575 -0.8275,-2.48625 -2.485,-2.48625 -1.49,0 -2.9375,0.76875 -4.34625,2.3075 l 0,-2.9825 c 1.06,-1.24875 2.58375,-1.8725 4.57,-1.8725 1.48875,0 2.68125,0.38875 3.58125,1.16875 0.3,0.25 0.57,0.5825 0.80875,0.99625 0.24125,0.415 0.3925,0.82875 0.45625,1.24375 0.065,0.415 0.0975,1.20125 0.0975,2.35875"
id="path58" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 257.011,82.685 0,2.6975 c -1.36875,0.50875 -2.7075,0.76375 -4.015,0.76375 -2.1575,0 -3.87625,-0.64 -5.16125,-1.9175 -1.2825,-1.27875 -1.925,-2.9925 -1.925,-5.13875 0,-2.1675 0.62375,-3.915 1.8725,-5.24375 1.2475,-1.32875 2.8925,-1.9925 4.93,-1.9925 0.70875,0 1.34625,0.0675 1.91,0.20125 0.56375,0.135 1.26,0.3875 2.09,0.7575 l 0,2.90625 c -1.38,-0.87875 -2.6575,-1.3175 -3.83625,-1.3175 -1.2275,0 -2.2375,0.43125 -3.02625,1.295 -0.78875,0.865 -1.18375,1.965 -1.18375,3.30375 0,1.4075 0.4275,2.52625 1.2825,3.355 0.8525,0.83 2.00375,1.24375 3.45125,1.24375 1.05,0 2.2525,-0.30375 3.61125,-0.91375"
id="path60" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 264.986,77.6225 6.93625,0 c -0.07,-1.08875 -0.395,-1.9275 -0.9725,-2.51625 -0.58,-0.58875 -1.35875,-0.885 -2.33875,-0.885 -0.97875,0 -1.77875,0.29625 -2.40375,0.885 -0.62375,0.58875 -1.03125,1.4275 -1.22125,2.51625 m -0.06,1.63375 c 0.07,1.3175 0.5125,2.36625 1.32625,3.14625 0.81375,0.77875 1.865,1.1675 3.15375,1.1675 1.79875,0 3.45625,-0.55875 4.97375,-1.6775 l 0,2.66625 c -0.8375,0.56 -1.67,0.96 -2.49375,1.19875 -0.825,0.24 -1.79,0.36 -2.9,0.36 -1.51875,0 -2.74625,-0.315 -3.685,-0.94375 -0.94,-0.62875 -1.69125,-1.47625 -2.25625,-2.53875 -0.5625,-1.065 -0.845,-2.295 -0.845,-3.69375 0,-2.0975 0.59375,-3.8025 1.7825,-5.11625 1.18875,-1.31375 2.7325,-1.97 4.62875,-1.97 1.82875,0 3.28625,0.64 4.375,1.9175 1.08875,1.27875 1.64156,3.342812 1.64156,5.490312 l -9.70156,-0.0066 z"
id="path62"
sodipodi:nodetypes="ccsssccssccssssssssc" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 296.1485,74.6725 -1.92875,0 0,8.48 c 0.8375,0.42875 1.71375,0.64375 2.6325,0.64375 1.275,0 2.31875,-0.445 3.13,-1.33375 0.8125,-0.88875 1.22,-2.0325 1.22,-3.43 0,-0.89875 -0.1925,-1.6925 -0.57625,-2.38125 -0.385,-0.69 -0.9075,-1.1925 -1.57,-1.50625 -0.6625,-0.315 -1.63125,-0.4725 -2.9075,-0.4725 m -4.71375,16.56625 0,-19.11375 4.7725,0 c 2.44375,0 4.34625,0.61 5.7075,1.82875 1.3625,1.21875 2.0425,2.92125 2.0425,5.10875 0,2.0675 -0.64125,3.765 -1.92125,5.0925 -1.28125,1.32875 -2.91375,1.99375 -4.89875,1.99375 -0.8775,0 -1.85,-0.19625 -2.9175,-0.585 l 0,5.675 -2.785,0 z"
id="path64" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 312.636,72.1225 0,3.16125 0.15,-0.24 c 1.31875,-2.1275 2.63625,-3.19 3.955,-3.19 1.0275,0 2.1025,0.51875 3.22125,1.5575 l -1.43875,2.3975 c -0.94875,-0.9 -1.82625,-1.34875 -2.63625,-1.34875 -0.87875,0 -1.64,0.42 -2.28625,1.2575 -0.6425,0.84 -0.965,1.83375 -0.965,2.9825 l 0,7.20625 -2.74,0 0,-13.78375 2.74,0 z"
id="path66" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 330.611,83.185 0,-4.08875 -1.82625,0.70375 c -0.93,0.36875 -1.58625,0.74125 -1.97125,1.11625 -0.385,0.37375 -0.5775,0.84125 -0.5775,1.4 0,0.56875 0.1825,1.03375 0.54625,1.39375 0.365,0.35875 0.8375,0.53875 1.4175,0.53875 0.86875,0 1.6725,-0.355 2.41125,-1.06375 m 2.68125,-5.55875 0,5.85875 c 0,0.47 0.15875,0.70375 0.47875,0.70375 0.33,0 0.845,-0.245 1.54375,-0.73375 l 0,1.6625 c -0.61875,0.4 -1.11625,0.67125 -1.49125,0.8175 -0.375,0.14375 -0.7675,0.21625 -1.17625,0.21625 -1.16875,0 -1.85625,-0.45875 -2.06625,-1.3775 -1.16,0.8975 -2.39375,1.3475 -3.7,1.3475 -0.96,0 -1.76,-0.31625 -2.3975,-0.95125 -0.63875,-0.63375 -0.95875,-1.43125 -0.95875,-2.38875 0,-0.87 0.31125,-1.64625 0.93625,-2.33 0.62375,-0.68375 1.51,-1.22625 2.65875,-1.625 l 3.49,-1.2 0,-0.73375 c 0,-1.6575 -0.82875,-2.48625 -2.48625,-2.48625 -1.48875,0 -2.93625,0.76875 -4.345,2.3075 l 0,-2.9825 c 1.05875,-1.24875 2.5825,-1.8725 4.56875,-1.8725 1.48875,0 2.6825,0.38875 3.58125,1.16875 0.3,0.25 0.57,0.5825 0.81,0.99625 0.24,0.415 0.39125,0.82875 0.455,1.24375 0.065,0.415 0.0988,1.20125 0.0988,2.35875"
id="path68" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 344.911,74.485 c -0.73875,0 -1.3675,0.25 -1.8875,0.74875 -0.51875,0.5 -0.77875,1.09875 -0.77875,1.7975 0,0.71 0.25375,1.29625 0.765,1.76 0.50875,0.465 1.1525,0.6975 1.93125,0.6975 0.77,0 1.41125,-0.2375 1.925,-0.71125 0.515,-0.475 0.7725,-1.06625 0.7725,-1.775 0,-0.72 -0.26,-1.31875 -0.77875,-1.79875 C 346.341,74.72375 345.691,74.485 344.911,74.485 m -0.64375,12.06 c -0.91875,0 -1.67,0.195 -2.25375,0.58375 -0.58375,0.39 -0.8775,0.88875 -0.8775,1.49875 0,1.4175 1.27875,2.1275 3.83625,2.1275 1.20875,0 2.145,-0.1775 2.8075,-0.5325 0.665,-0.35375 0.9975,-0.85625 0.9975,-1.505 0,-0.64 -0.41875,-1.16125 -1.25875,-1.56625 C 346.67975,86.7475 345.596,86.545 344.26725,86.545 m -4.48,-9.66375 c 0,-1.4675 0.5375,-2.62875 1.61125,-3.4825 1.07375,-0.85375 2.54,-1.28125 4.3975,-1.28125 l 5.6775,0 0,2.1275 -2.78625,0 c 0.53875,0.55 0.91375,1.04875 1.12375,1.4975 0.21,0.45 0.315,0.965 0.315,1.54375 0,0.71875 -0.205,1.42625 -0.615,2.12 -0.40875,0.69375 -0.935,1.225 -1.58125,1.595 -0.64375,0.37 -1.7,0.665 -3.1675,0.88375 -1.02875,0.15125 -1.54375,0.505 -1.54375,1.06375 0,0.32 0.1925,0.5825 0.57625,0.7875 0.385,0.20375 1.0825,0.41625 2.09,0.63625 1.68875,0.37 2.77375,0.66 3.26,0.86875 0.48375,0.21 0.92,0.51 1.31125,0.89875 0.65875,0.66 0.98875,1.48875 0.98875,2.4875 0,1.3075 -0.5825,2.35125 -1.74625,3.13125 -1.165,0.77875 -2.72,1.1675 -4.66625,1.1675 -1.97,0 -3.53875,-0.39125 -4.71125,-1.175 -1.17375,-0.785 -1.76125,-1.835 -1.76125,-3.15375 0,-1.8675 1.15375,-3.07125 3.46,-3.61125 -0.91875,-0.58875 -1.3775,-1.17375 -1.3775,-1.7525 0,-0.43875 0.19625,-0.83875 0.5925,-1.1975 0.39375,-0.36 0.925,-0.625 1.59375,-0.795 -2.02625,-0.8975 -3.04125,-2.3525 -3.04125,-4.36"
id="path70" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 365.1235,85.91 0,-1.76875 c -0.57875,0.635 -1.24,1.1275 -1.98375,1.48 -0.745,0.3525 -1.485,0.5275 -2.225,0.5275 -0.87,0 -1.67,-0.21625 -2.405,-0.65125 -0.735,-0.435 -1.28875,-1.02375 -1.6625,-1.7675 -0.375,-0.74375 -0.56125,-1.98 -0.56125,-3.7075 l 0,-7.89625 2.725,0 0,7.855 c 0,1.4475 0.2075,2.4575 0.62125,3.03125 0.415,0.5725 1.1425,0.86 2.1825,0.86 1.2975,0 2.4,-0.635 3.30875,-1.90375 l 0,-9.8425 2.7275,0 0,13.78375 -2.7275,0 z"
id="path72" /><path
style="fill:#217777;fill-rule:nonzero;stroke:none;stroke-opacity:1;fill-opacity:1"
d="m 376.561,77.6225 6.9375,0 c -0.0725,-1.08875 -0.39625,-1.9275 -0.975,-2.51625 -0.58,-0.58875 -1.35875,-0.885 -2.33875,-0.885 -0.9775,0 -1.77875,0.29625 -2.40375,0.885 -0.62375,0.58875 -1.03125,1.4275 -1.22,2.51625 m -0.06,1.63375 c 0.07,1.3175 0.51125,2.36625 1.32625,3.14625 0.81375,0.77875 1.865,1.1675 3.1525,1.1675 1.79875,0 3.45625,-0.55875 4.975,-1.6775 l 0,2.66625 c -0.83875,0.56 -1.67125,0.96 -2.495,1.19875 -0.825,0.24 -1.79,0.36 -2.89875,0.36 -1.52,0 -2.74625,-0.315 -3.68625,-0.94375 -0.9375,-0.62875 -1.69,-1.47625 -2.255,-2.53875 -0.5625,-1.065 -0.845,-2.295 -0.845,-3.69375 0,-2.0975 0.59375,-3.8025 1.78125,-5.11625 1.18875,-1.31375 2.7325,-1.97 4.62875,-1.97 1.82875,0 3.28625,0.64 4.375,1.9175 1.09,1.27875 1.62984,3.342813 1.62984,5.490313 l -9.68859,-0.0066 z"
id="path74"
sodipodi:nodetypes="ccsssccssccssssssssc" />
</svg>

After

Width:  |  Height:  |  Size: 25 KiB

154
brmrec.py Executable file
View file

@ -0,0 +1,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)

125
brmstock.py Executable file
View file

@ -0,0 +1,125 @@
#!/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 - Manage stock")
mainWidget.setStyleSheet(STYLE_WIDGET)
msg=QLabel("")
t=QTimer()
def brmEditStock(widget=None,code=None,id=None,mw=None):
le=mw.findChildren(QLineEdit)[-1]
if code==None: # Invoked from scanner?
if widget==None: # Actually... new user?
code=""
else:
code=brmSatanize(le.text())
if DEBUG: print("brmEditStock code='"+str(code)+"'")
if code==None: # scanner passed EOL only (no data)
return
# code="" -> New stuff
# code="xyz" -> Edit existing stuff
if code=="":
usr=[0,"Stuff",0,0,0]
else:
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
if id!=None: # If ID is known, use it
dbc.execute("SELECT * FROM stock WHERE id="+str(int(id))+" LIMIT 1;")
else: # If code is known, use it
dbc.execute("SELECT * FROM stock WHERE id=("
"SELECT stock FROM barcodes WHERE code='"+code+"' LIMIT 1) "
"LIMIT 1;")
usr=dbc.fetchone()
db.close()
if usr==None:
return
if DEBUG: print(" "+str(usr))
rc=os.system(str("python ./brmeditstock.py "
"'"+str(usr[0])+"' "
"'"+brmSatanize(usr[1])+"' "
"'"+str(usr[2])+"' "
"'"+str(usr[3])+"' "
"'"+str(usr[4])+"'"))
brmParseRC(rc,msg,t,foc=le)
print("aaaaaaa")
(mw.findChildren(QLineEdit)[-1]).setFocus(True)
# sys.exit(rc>>8)
def brmAddListLayout(p=None,wat=None):
if DEBUG: print("brmAddListLayout: '"+str(wat)+"'")
line=QHBoxLayout()
if wat==None:
nif=QLabel("No items found!")
nif.setStyleSheet(STYLE_TEXT)
line.addWidget(nif)
else:
brmAddButton(line,brmSatanize(wat[1]),
lambda:brmEditStock(mainWidget,str(wat[3]),str(wat[0]),mainWidget),
s="margin-left:100px;")
line.addStretch(1)
pl=QLabel(str(wat[4])+" Kc; #"+str(wat[2]))
pl.setStyleSheet(STYLE_TEXT+"margin-right:100px;")
line.addWidget(pl)
p.addLayout(line)
msgbox=QHBoxLayout()
msgbox.addStretch(1)
msg.setStyleSheet(STYLE_MSG)
msg.setFocusPolicy(0)
msgbox.addWidget(msg)
msgbox.addStretch(1)
bbox=QHBoxLayout()
bbox.addStretch(1)
brmAddButton(bbox,"New stuff",lambda:brmEditStock(None,None,None,mainWidget))
bbox.addStretch(1)
brmAddButton(bbox,"Cancel",lambda:sys.exit(EXIT_CANCEL))
bbox.addStretch(1)
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
# id=0 -> Charge credit
# id=1 -> Donation
dbusr=dbc.execute("SELECT * FROM stock WHERE id>1 ORDER BY name ASC;")
sbox=QScrollArea()
sbox.setWidgetResizable(True)
sbox.setFocusPolicy(0)
sboxList=QWidget(sbox)
sboxList.setFocusPolicy(0)
sboxLayout=QVBoxLayout(sboxList)
sboxList.setLayout(sboxLayout)
for row in dbusr:
brmAddListLayout(sboxLayout,row)
sbox.setWidget(sboxList)
sbox.setStyleSheet(sbox.styleSheet()+"max-width:1200px")
db.close() # Must be closed AFTER the list is completed
screenbox=QVBoxLayout()
brmLabelBox(screenbox,"Stock")
screenbox.addLayout(msgbox)
screenbox.addWidget(sbox)
screenbox.addLayout(bbox)
brmAddLine(screenbox,"",'T',STYLE_HIDDEN,
lambda:brmEditStock(mainWidget,None,None,mainWidget),foc=1)
mainWidget.setLayout(screenbox)
mainWidget.showFullScreen()
app.exec_()
sys.exit(EXIT_CANCEL)

161
brmtrans.py Executable file
View file

@ -0,0 +1,161 @@
#!/usr/bin/python
import sys
import sqlite3
from fce import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
DEBUG=0
scb="Scan barcode now"
app=QApplication(sys.argv)
mainWidget=QWidget()
mainWidget.resize(1280,1024)
mainWidget.setWindowTitle("BrmbarSAP - Transfer credit")
mainWidget.setStyleSheet(STYLE_WIDGET)
def brmTransfer(mw=None):
if DEBUG: print("brmTransfer")
lbls=mw.findChildren(QLabel)
fr=lbls[-5]
to=lbls[-2]
le=mw.findChildren(QLineEdit)
pswd=hashlib.sha512(brmSatanize(le[0].text())).hexdigest()
amount=str(le[1].text())
if amount=="0":
le[1].setStyleSheet(le[1].styleSheet()+STYLE_BADLE)
return
else:
le[1].setStyleSheet(le[1].styleSheet()+STYLE_OKLE)
# users set?
if fr.text()==to.text() or fr.text()[0]=="<" or to.text()[0]=="<":
return
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
dbc.execute("SELECT id,cash,pass FROM users WHERE"
" name='"+brmSatanize(fr.text())+"' LIMIT 1;")
frdb=dbc.fetchone()
if DEBUG: print(" "+str(frdb))
if frdb[1]<=BUY_LIMIT:
db.close()
sys.exit(EXIT_NOCREDIT)
if frdb[2]!=pswd:
db.close()
le[0].setStyleSheet(le[0].styleSheet()+STYLE_BADLE)
le[0].setText("")
return
else:
le[0].setStyleSheet(le[0].styleSheet()+STYLE_OKLE)
dbc.execute("UPDATE users SET cash=cash-("+amount+") WHERE"
" name='"+brmSatanize(fr.text())+"' LIMIT 1;")
dbc.execute("UPDATE users SET cash=cash+("+amount+") WHERE"
" name='"+brmSatanize(to.text())+"' LIMIT 1;")
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP,"
"(SELECT id FROM users WHERE name='"+str(fr.text())+"' LIMIT 1),0,1,"
"-("+amount+"),0);")
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP,"
"(SELECT id FROM users WHERE name='"+str(to.text())+"' LIMIT 1),0,1,"
"+("+amount+"),0);")
db.commit()
db.close()
sys.exit(EXIT_TRANSFERRED)
def brmSetWho(val=""):
if DEBUG: print("brmSetWho: code='"+val+"'")
#le=mainWidget.findChildren(QLineEdit)[-1]
if val=="":
return
lbls=mainWidget.findChildren(QLabel)
fr=lbls[-5]
to=lbls[-2]
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
dbc.execute("SELECT name FROM users WHERE code='"+brmSatanize(val)+""
"' LIMIT 1;")
rec=dbc.fetchone()
if DEBUG: print(" "+str(rec))
if rec==None:
return
print(" "+fr.text())
if fr.text()==scb:
fr.setText(brmSatanize(rec[0]))
to.setText(scb)
else:
to.setText(brmSatanize(rec[0]))
db.close()
fbox=QHBoxLayout()
cf=QLabel("Credit from:")
cf.setStyleSheet(STYLE_TEXT)
fbox.addWidget(cf)
fbox.addStretch(1)
cf2=QLabel(scb)
cf2.setStyleSheet(STYLE_MSG+"margin-right:100px;")
fbox.addWidget(cf2)
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)
tbox=QHBoxLayout()
ct=QLabel("Credit to:")
ct.setStyleSheet(STYLE_TEXT)
tbox.addWidget(ct)
tbox.addStretch(1)
ct2=QLabel("")
ct2.setStyleSheet(STYLE_MSG+"margin-right:100px;")
tbox.addWidget(ct2)
cbox=QHBoxLayout()
al=QLabel("Amount:")
al.setStyleSheet(STYLE_TEXT)
cbox.addWidget(al)
cbox.addStretch(1)
brmAddLine(cbox,"0","N1",STYLE_LE,
lambda:QTimer.singleShot(0,mainWidget.findChildren(QLineEdit)[-1],
SLOT('setFocus()')),c=0)
bbox=QHBoxLayout()
bbox.addStretch(1)
brmAddButton(bbox,"Transfer",lambda:brmTransfer(mainWidget))
bbox.addStretch(1)
brmAddButton(bbox,"Cancel",lambda:sys.exit(EXIT_CANCEL))
bbox.addStretch(1)
screenbox=QVBoxLayout()
brmLabelBox(screenbox,"Transfer credit")
screenbox.addStretch(1)
screenbox.addLayout(fbox)
screenbox.addLayout(pbox)
screenbox.addStretch(1)
screenbox.addLayout(tbox)
screenbox.addStretch(1)
screenbox.addLayout(cbox)
screenbox.addStretch(5)
screenbox.addLayout(bbox)
brmAddLine(screenbox,"",'T',STYLE_HIDDEN,brmSetWho)
mainWidget.setLayout(screenbox)
mainWidget.showFullScreen()
mainWidget.findChildren(QLineEdit)[0].setEchoMode(2) # Password masking
app.exec_()
sys.exit(EXIT_CANCEL)

105
brmusers.py Executable file
View file

@ -0,0 +1,105 @@
#!/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 - Manage users")
mainWidget.setStyleSheet(STYLE_WIDGET)
def brmEditUser(widget=None,code=None,id=None):
if code==None: # Invoked from scanner?
if widget==None: # Actually... new user?
code=""
else:
code=brmSatanize((widget.findChildren(QLineEdit)[0]).text())
if DEBUG: print("brmEditUser code="+str(code))
if code==None: # scanner passed EOL only (no data)
return
# code="" -> New user
# code="xyz" -> Edit existing user
if code=="":
usr=[0,"New user",0,""]
else:
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
if id!=None: # If ID is known, use it
dbc.execute("SELECT id,name,cash,mail FROM users "
"WHERE id="+str(int(id))+" LIMIT 1;")
else:
dbc.execute("SELECT id,name,cash,mail FROM users "
"WHERE code='"+code+"' LIMIT 1;")
usr=dbc.fetchone()
db.close()
if usr==None:
return
if DEBUG: print(" "+str(usr))
rc=os.system(str("python ./brmedituser.py "
"'"+str(int(usr[0]))+"' "
"'"+brmSatanize(usr[1])+"' "
"'"+str(float(usr[2]))+"' "
"'"+brmSatanize(usr[3])+"'"))
sys.exit(rc>>8)
def brmAddListLayout(p=None,wat=None):
if DEBUG: print("brmAddListLayout: '"+str(wat)+"'")
line=QHBoxLayout()
if wat==None:
nu=QLabel("No users found!")
nu.setStyleSheet(STYLE_TEXT)
line.addWidget(nu)
else:
brmAddButton(line,brmSatanize(wat[1]),
lambda:brmEditUser(mainWidget,str(wat[3]),str(wat[0])),
s="margin-left:100px;")
line.addStretch(1)
cl=QLabel(str(float(wat[2])))
cl.setStyleSheet(STYLE_TEXT+"margin-right:100px;")
line.addWidget(cl)
p.addLayout(line)
bbox=QHBoxLayout()
bbox.addStretch(1)
brmAddButton(bbox,"New user",lambda:brmEditUser(None,None,None))
bbox.addStretch(1)
brmAddButton(bbox,"Cancel",lambda:sys.exit(EXIT_CANCEL))
bbox.addStretch(1)
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
# Ignore "Cash" and "Replenishment" users (internal only)
dbusr=dbc.execute("SELECT * FROM users WHERE id>1 ORDER BY name ASC;")
sbox=QScrollArea()
sbox.setWidgetResizable(True)
sbox.setFocusPolicy(0)
sboxList=QWidget(sbox)
sboxList.setFocusPolicy(0)
sboxLayout=QVBoxLayout(sboxList)
sboxList.setLayout(sboxLayout)
for row in dbusr:
brmAddListLayout(sboxLayout,row)
sbox.setWidget(sboxList)
db.close() # Must be closed AFTER the list is completed
screenbox=QVBoxLayout()
brmLabelBox(screenbox,"Users")
screenbox.addWidget(sbox)
screenbox.addLayout(bbox)
brmAddLine(screenbox,"",'T',STYLE_HIDDEN,
lambda:brmEditUser(mainWidget,None,None))
mainWidget.setLayout(screenbox)
mainWidget.showFullScreen()
app.exec_()
sys.exit(EXIT_CANCEL)

186
fce.py Executable file
View file

@ -0,0 +1,186 @@
import os
import sys
import sqlite3
import hashlib
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtSvg import *
from datetime import datetime
STYLE_BTN=("background-color:rgba(0,0,0,100);color:yellow;font-size:48px;"
"border: 1px solid #217777;padding:5px;")
#STYLE_DESC="color:green;font-size:48px"
STYLE_LABEL="color:green;font-size:64px;"
STYLE_LE=("background-color:white;color:black;font-size:48px;"
"margin-right:100px;")
STYLE_BADLE="background-color:red;" # Invalid data indicator
STYLE_OKLE="background-color:white;" # Fixed data indicator
#STYLE_ITEM="color:white;font-size:64px"
STYLE_HIDDEN="background-color:rgba(0,0,0,255);color:white;" #rgba(0,0,0,255);"
STYLE_WIDGET="background-color:black;color:white;"
STYLE_MSG="background-color:black;color:yellow;font-size:32px;"
STYLE_TEXT=("background-color:black;color:white;font-size:48px;"
"margin-left:100px;")
STYLE_HELP=("background-color:black;color:#217777;font-size:32px;")
EXIT_OK=0
EXIT_CANCEL=1
EXIT_MSG=2
EXIT_NOBARCODE=3
EXIT_NOCREDIT=4
EXIT_USER=5
EXIT_STOCKSAVED=6
EXIT_TRANSFERRED=7
EXIT_DONATION=8
MSGS=["Done!",
"Transaction cancelled",
"", # Reserved for external msg
"Unknown barcode",
"FAIL! Credit too low\nPlease recharge",
"User saved",
"Stock saved",
"Credit transferred",
"Thanks for the donation!"]
MSGFILE="/dev/shm/brmbarsap_msg"
BRMDB="./brmbar.db"
BUY_LIMIT=-200
# hashlib.sha512(brmSatanize("")).hexdigest()
NULL512=("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce"
"9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e")
DEBUG=1
# ====================================================================
def brmParseRC(rc=0,msg=None,t=None,foc=None):
# Magic ahead:
# The Return Code is 16bit integer but we need only the HIGH byte
rc=rc>>8
if DEBUG: print("brmParseRC="+str(rc)+"='"+MSGS[rc]+"'")
if rc==EXIT_MSG:
fr=open(MSGFILE,"r")
fmsg=fr.readline()
if DEBUG: print(" FILEMSG: '"+fmsg+"'")
msg.setText(fmsg)
fr.close()
os.remove(MSGFILE)
else:
msg.setText(MSGS[rc])
t.start(5000)
t.timeout.connect(lambda:msg.setText(""))
if foc!=None:
if DEBUG:print(str(foc))
QTimer.singleShot(0,foc,SLOT('setFocus()'))
return
# Sanitize string
def brmSatanize(s=""):
ss=""
sss=""
try:
ss=s.toAscii()
except:
for c in s:
ss=ss+c.encode("ascii","ignore")
for c in ss:
if ord(c) > 31 and ord(c) < 127:
sss=sss+c
ss=sss
ss=ss.replace("'","")
ss=ss.replace("\"","")
ss=ss.replace(";","")
ss=ss.replace("`","")
ss=ss.replace("<","")
ss=ss.replace(">","")
ss=ss.replace("$(","$ (")
if DEBUG: print("brmSatanize:\n "+ss)
return str(ss);
# Clear Lineedit And Pass
def brmCLAP(le=None,f=None,c=1,foc=1):
if DEBUG: print("brmCLAP")
a=le.text()
if c==1:
le.setText("")
try:
f(a)
except: # Revert the value
le.setText(a)
f()
if c==1:
le.setText("")
if foc==1:
QTimer.singleShot(0,le,SLOT('setFocus()'))
le.setFocus(True)
timetimer=QTimer()
def brmLabelBox(p=None,lbl=""):
if DEBUG: print("brmLabelBox: '"+lbl+"'")
b=QHBoxLayout()
b.addWidget(QSvgWidget("./brmlab.svg"))
b.addStretch(1)
b.addWidget(QLabel("<font style='"+STYLE_LABEL+"'>"+lbl+"</font>"))
b.addStretch(1)
timetext=("<font style='"+STYLE_MSG+"'>"
""+datetime.strftime(datetime.now(),'%Y-%m-%d %H:%M:%S')+"</font>")
timewidget=QLabel(timetext)
timetimer.timeout.connect(
lambda:timewidget.setText("<font style='"+STYLE_MSG+"'>"
""+datetime.strftime(datetime.now(),'%Y-%m-%d %H:%M:%S')+"</font>"))
timetimer.start(1000)
b.addWidget(timewidget)
p.addLayout(b)
def brmAddButton(p=None,lbl="",f=exit,w=0,s=""):
if DEBUG: print("addBrmButton: '"+lbl+"'")
butt=QPushButton(lbl)
if int(w)>0:
butt.setStyleSheet(STYLE_BTN+s+"text-align:left;"
"width:"+str(int(w))+"px;max-width:"+str(int(w))+"px;")
else:
butt.setStyleSheet(STYLE_BTN+s)
butt.connect(butt,SIGNAL('pressed()'),f)
butt.setAutoDefault(0)
butt.setFocusPolicy(0)
p.addWidget(butt)
def brmAddLine(p=None,lbl="",r='T',s="",f=exit,w=200,c=1,foc=1):
if DEBUG: print("addBrmLine: '"+str(lbl)+"'")
l=QLineEdit(str(lbl))
l.setStyleSheet(s+"width:"+str(w)+"px;max-width:"+str(w)+"px;")
# if r=="T":
# l.setValidator(QRegExpValidator(QRegExp("^[\d\s\w]*$")))
if r=="Q":
l.setValidator(QRegExpValidator(QRegExp("^-?[0-9]{1,5}(\.[0-9]{1,2})?$")))
if r=="Q+":
l.setValidator(QRegExpValidator(QRegExp("^[0-9]{1,5}(\.[0-9]{0,2})?$")))
if r=="N":
# l.setValidator(QIntValidator(-100000,100000))
l.setValidator(QRegExpValidator(QRegExp("^-?[0-9]{1,5}$")))
if r=="N1":
# l.setValidator(QIntValidator(1,100000))
l.setValidator(QRegExpValidator(QRegExp("^[1-9]{1}[0-9]{0,4}$")))
if r=="N0":
# l.setValidator(QIntValidator(0,100000))
l.setValidator(QRegExpValidator(QRegExp("^[0-9]{1,5}$")))
if r=="M":
l.setValidator(QRegExpValidator(
QRegExp("^[0-9A-Za-z\._-]{1,}@[0-9a-zA-Z\._-{1,}\.[a-zA-Z0-9]{1,}$")))
l.connect(l,SIGNAL('returnPressed()'),lambda:brmCLAP(l,f,c,foc))
if s==STYLE_HIDDEN:
l.setFocusPolicy(Qt.StrongFocus)
QTimer.singleShot(0,l,SLOT('setFocus()'))
p.addWidget(l)
def brmPassMsg(s=""):
fw=open(MSGFILE,"w")
fw.write(s)
fw.close()

17
reports.sh Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
# Send reports to all users with filled mail (from last midnight)
db="./brmbar.db"
usr=$(echo "SELECT name FROM users where mail!='';" | sqlite3 $db)
for u in $usr
do
m=$(echo "SELECT mail FROM users where name='"$u"';" | sqlite3 $db)
l=$(echo ".headers on
SELECT * FROM transhuman WHERE strftime('%Y-%m-%d',age)=date('now','localtime') AND user='$u';" | sqlite3 $db)
if [ -n "$l" ]; then
echo "$l" | mail -s "brmbar report" "$m"
fi
done

39
schema.sql Executable file
View file

@ -0,0 +1,39 @@
CREATE TABLE stock (
id INTEGER PRIMARY KEY ON CONFLICT IGNORE AUTOINCREMENT,
name TEXT DEFAULT 'Junkfood',
quan INTEGER DEFAULT 0,
buyprice FLOAT DEFAULT 0,
sellprice FLOAT DEFAULT 1);
CREATE TABLE users (
id INTEGER PRIMARY KEY ON CONFLICT IGNORE AUTOINCREMENT,
name TEXT NOT NULL DEFAULT 'Muaddib',
cash REAL DEFAULT 0,
code INTEGER DEFAULT 0,
pass TEXT DEFAULT NULL,
mail TEXT DEFAULT NULL);
CREATE TABLE transactions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
age TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
who INTEGER DEFAULT 0,
what INTEGER DEFAULT 0,
amount INTEGER DEFAULT 0,
cash INTEGER DEFAULT 0,
profit INTEGER DEFAULT 0);
CREATE TABLE barcodes (
id INTEGER PRIMARY KEY ON CONFLICT IGNORE AUTOINCREMENT,
stock INTEGER DEFAULT 0,
code INTEGER DEFAULT 0);
CREATE TABLE receipts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
tid INTEGER DEFAULT 0,
comment TEXT DEFAULT NULL);
CREATE VIEW transhuman AS SELECT transactions.id AS tid,age,users.name AS user,stock.name AS stuff,amount,transactions.cash AS price,profit FROM transactions,users,stock WHERE transactions.who=users.id AND transactions.what=stock.id ORDER BY transactions.id DESC;
CREATE VIEW rechuman AS SELECT receipts.id AS rid, transactions.age AS happened, transactions.cash AS price, users.name AS responsible, comment FROM transactions,users,receipts WHERE transactions.who=users.id AND receipts.tid=transactions.id ORDER BY happened DESC;

14
stats.sh Executable file
View file

@ -0,0 +1,14 @@
#!/bin/bash
# Display various stats from brmbar
DB="./brmbar.db"
overflow=$(echo "SELECT sum(cash)*(-1) FROM users WHERE name like '%overflow';" | sqlite3 $DB)
cash=$(echo "SELECT (SELECT sum(profit) FROM transactions)-($overflow);" | sqlite3 $DB)
inv=$(echo "SELECT sum(quan*buyprice) FROM stock;" | sqlite3 $DB)
mate=$(echo "SELECT sum(amount) FROM transhuman WHERE strftime('%Y-%m-%d',age)=date('now','localtime') AND (stuff like '%mate%' OR stuff like '%Mate%');" | sqlite3 $DB)
echo "Overflow: $overflow"
echo "Cash: $cash"
echo "Inventory: $inv"
echo "Clubmate sold today: $mate bottles"

2
stock.sql Executable file
View file

@ -0,0 +1,2 @@
INSERT INTO stock VALUES(0,'Charge credit',0,0.0,0.0);
INSERT INTO stock VALUES(1,'Donation',0,0.0,0.0);

5
userlog.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash
# Print out the log for specified user from last midnight
echo ".headers on
SELECT * FROM transhuman WHERE strftime('%Y-%m-%d',age)=date('now','localtime') AND user='$1';" | sqlite3 ./brmbar.db

2
users.sql Executable file
View file

@ -0,0 +1,2 @@
INSERT INTO users VALUES(0,'Cash',0.0,'','','');
INSERT INTO users VALUES(1,'Replenishment',0.0,'','','');