-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathretailShopHome.py
486 lines (441 loc) · 21.3 KB
/
retailShopHome.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
import sys
import connectDb
import getInfo
import getLists
import retrieveRegional
import subprocess
import os
import getpass
import hashlib
from PyQt4 import QtGui, QtCore
from MainWindow import Ui_MainWindow
from addPerishableWidget import AddNewPerishable
from deletePerishableWidget import DeletePerishable
from updatePerishableWidget import UpdatePerishable
from restockPerishableWidget import RestockPerishable
from updateUnitWidget import RemapUnit
from addUnitWidget import NewUnit
from deleteUnitWidget import DeleteUnit
from createPromotionWidget import CreatePromotion
from deletePromotionWidget import DeletePromotion
from writeoffWidget import PerformWriteoff
from performTransactionWidget import PerformTransaction
def isNumber(s):
try:
float(s)
return True
except ValueError:
return False
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.initialiseAllViews()
#widgetPressed = self.ui.tabWidget.currentIndex()
self.ui.viewall_products.clicked.connect(self.viewProducts)
self.ui.searchbarcode_products.clicked.connect(self.viewProducts)
self.ui.searchname_products.clicked.connect(self.viewProducts)
self.ui.viewall_perishable.clicked.connect(self.viewPerishables)
self.ui.searchbarcode_perishable.clicked.connect(self.viewPerishables)
self.ui.searchname_perishable.clicked.connect(self.viewPerishables)
self.ui.add_perishable.clicked.connect(self.addNewPerishable)
self.ui.remove_perishable.clicked.connect(self.deletePerishable)
self.ui.stock_perishable.clicked.connect(self.restockPerishable)
self.ui.update_perishable.clicked.connect(self.updatePerishable)
self.ui.viewall_tran.clicked.connect(self.viewTran)
self.ui.searchid_tran.clicked.connect(self.viewTran)
self.ui.searchdate_tran.clicked.connect(self.viewTran)
self.ui.add_tran.clicked.connect(self.performTransaction)
self.ui.viewall_units.clicked.connect(self.viewUnits)
self.ui.searchbarcode_units.clicked.connect(self.viewUnits)
self.ui.searchdev_units.clicked.connect(self.viewUnits)
self.ui.newunit.clicked.connect(self.addUnits)
self.ui.updateunit.clicked.connect(self.updateUnits)
self.ui.removeunit.clicked.connect(self.deleteUnits)
self.ui.viewall_promo.clicked.connect(self.viewPromo)
self.ui.searchbarcode_promo.clicked.connect(self.viewPromo)
self.ui.searchname_promo.clicked.connect(self.viewPromo)
self.ui.searchpromo_promo.clicked.connect(self.viewPromo)
self.ui.newpromo.clicked.connect(self.createPromo)
self.ui.removepromo.clicked.connect(self.deletePromo)
self.ui.orderproducts.clicked.connect(self.orderProducts)
self.ui.updatestock.clicked.connect(self.updateStockAndProduct)
self.ui.writeoff.clicked.connect(self.performWriteoff)
def initialiseAllViews(self):
self.dashboard()
self.viewProducts()
self.viewPerishables()
self.viewTran()
self.viewUnits()
self.viewPromo()
def dashboard(self):
conn, cur = connectDb.connectToDatabase()
noOfTrans = "SELECT count(distinct t.transactionid) FROM transaction t WHERE t.date = CURDATE()"
cur.execute(noOfTrans)
countTransDay = cur.fetchone()
countTransDay = countTransDay[0]
if countTransDay != 0:
moneyTrans = "SELECT sum(price) FROM transaction WHERE transaction.date = CURDATE()"
cur.execute(moneyTrans)
totalMoney = cur.fetchone()
totalMoney = totalMoney[0]
itemsSold = "SELECT sum(td.unitsold) FROM transaction t, transactiondetails td WHERE t.transactionid = td.transactionid AND t.date = CURDATE()"
cur.execute(itemsSold)
totalItemsSold = cur.fetchone()
totalItemsSold = totalItemsSold[0]
else:
totalMoney = 0
totalItemsSold = 0
self.ui.noTrans.setText("Number of Transactions Today : %d" % countTransDay)
self.ui.moneyDay.setText("Total Money Received Today : $%.2f" % totalMoney)
self.ui.noItems.setText("Number of Items sold Today: %d" % totalItemsSold)
connectDb.closeDatabaseConnection(conn, cur)
def getProducts(self, option = 0, value = None):
if option == 0:
count, rowProduct = getLists.getProductList(0)
else:
count, rowProduct = getLists.getProductList(option, value)
if option != 1:
self.ui.lineEdit_1_products.clear()
if option != 2:
self.ui.lineEdit_2_products.clear()
return count, rowProduct
def getPerish(self, option = 0, value = None):
if option == 0:
count, rowProduct = getLists.getPerishableList(0)
else:
count, rowProduct = getLists.getPerishableList(option, value)
if option != 1:
self.ui.lineEdit_1_perishable.clear()
if option != 2:
self.ui.lineEdit_2_perishable.clear()
return count, rowProduct
def getTransactions(self, option = 0, value = None):
if option == 0:
count, rowTran = getLists.getTranList(0)
else:
count, rowTran = getLists.getTranList(option, value)
if option != 1:
self.ui.lineEdit_1_tran.clear()
if option != 2:
self.ui.lineEdit_2_tran.clear()
return count, rowTran
def getUnits(self, option = 0, value = None):
if option == 0:
countCashier, rowCashier = getLists.getCashierList(0)
countPdu, rowPDUs = getLists.getPDUList(0)
elif option == 1:
countCashier, rowCashier = getLists.getCashierList(0)
countPdu, rowPDUs = getLists.getPDUList(1, value)
elif option == 2:
countCashier, rowCashier = getLists.getCashierList(2, value)
countPdu, rowPDUs = getLists.getPDUList(2, value)
if option != 1:
self.ui.lineEdit_1_units.clear()
if option != 2:
self.ui.lineEdit_2_units.clear()
return countCashier, rowCashier, countPdu, rowPDUs
def getPromos(self, option = 0, value = None):
if option == 0:
count, rowPromo = getLists.getPromoList(0)
else:
count, rowPromo = getLists.getPromoList(option, value)
if option != 1:
self.ui.lineEdit_1_promo.clear()
if option != 2:
self.ui.lineEdit_2_promo.clear()
if option != 3:
self.ui.lineEdit_3_promo.clear()
return count, rowPromo
def viewProducts(self):
self.ui.statusBar.showMessage("Loading Data, please wait...")
self.dashboard()
flag = 1
headerProducts = ['Barcode', 'Name', 'Category', 'Manufacturer', 'Price per Unit', 'Stock']
columnWidth = [75, 250, 125, 125, 100, 75]
sender = self.sender()
if sender is not None:
senderEvent = sender.text()
if (senderEvent == "Refresh") | (senderEvent == "Transaction"):
count, rowProduct = self.getProducts(0)
elif (senderEvent == "Filter Barcode") & isNumber(self.ui.lineEdit_1_products.text()):
barcodeSearch = int(self.ui.lineEdit_1_products.text())
count, rowProduct = self.getProducts(1, barcodeSearch)
elif senderEvent == "Filter Name":
nameSearch = str(self.ui.lineEdit_2_products.text())
count, rowProduct = self.getProducts(2, nameSearch)
else:
flag = 0
self.ui.lineEdit_1_products.clear()
self.ui.lineEdit_2_products.clear()
self.ui.statusBar.clearMessage()
QtGui.QMessageBox.about(self, "Error!", "The value entered was not valid ")
else:
count, rowProduct = getLists.getProductList(0)
if flag:
self.arrayToTable(rowProduct, self.ui.tableWidget_products, headerProducts, columnWidth, count, count, 6)
if count == 0:
self.ui.statusBar.showMessage("No Results Found", 2000)
def viewPerishables(self):
flag = 1
self.ui.statusBar.showMessage("Loading Data, please wait...")
self.dashboard()
sender = self.sender()
headerProducts = ['Barcode', 'Name', 'Category', 'Manufacturer', 'Price per Unit', 'Stock']
columnWidth = [75, 250, 125, 125, 100, 75]
if sender is not None:
senderEvent = sender.text()
if senderEvent == "Refresh":
count, rowProduct = self.getPerish(0)
elif (senderEvent == "Filter Barcode") & isNumber(self.ui.lineEdit_1_perishable.text()):
barcodeSearch = int(self.ui.lineEdit_1_perishable.text())
count, rowProduct = self.getPerish(1, barcodeSearch)
elif senderEvent == "Filter Name":
nameSearch = str(self.ui.lineEdit_2_perishable.text())
count, rowProduct = self.getPerish(2, nameSearch)
elif senderEvent == "Create New":
count, rowProduct = self.getPerish(0)
elif senderEvent == "Delete":
count, rowProduct = self.getPerish(0)
elif senderEvent == "Restock":
count, rowProduct = self.getPerish(0)
elif senderEvent == "Update":
count, rowProduct = self.getPerish(0)
elif senderEvent == "Transaction":
count, rowProduct = self.getPerish(0)
else:
flag = 0
self.ui.lineEdit_1_perishable.clear()
self.ui.lineEdit_2_perishable.clear()
self.ui.statusBar.clearMessage()
QtGui.QMessageBox.about(self, "Error!", "The value entered was not valid ")
else:
count, rowProduct = getLists.getPerishableList(0)
if flag:
self.arrayToTable(rowProduct, self.ui.tableWidget_perishable, headerProducts, columnWidth, count, count, 6)
if count == 0:
self.ui.statusBar.showMessage("No Results Found", 2000)
def viewTran(self):
self.ui.statusBar.showMessage("Loading Data, please wait...")
self.dashboard()
sender = self.sender()
headerTrans = ['Transaction ID', 'Cashier Unit', 'Date', 'Total Bill']
headerTransDetail = ['Transaction ID', 'Barcode', 'Promo ID', 'Quantity', 'Type of Transaction']
columnWidthTrans = [190, 190, 190, 170]
columnWidthTransDetail = [170, 170, 170, 100, 130]
if sender is not None:
senderEvent = sender.text()
if senderEvent == "Refresh":
count, rowTran = self.getTransactions(0)
self.arrayToTable(rowTran, self.ui.tableWidget_tran, headerTrans, columnWidthTrans, count, count, 4)
elif (senderEvent == "Filter Transaction ID") & isNumber(self.ui.lineEdit_1_tran.text()):
idSearch = int(self.ui.lineEdit_1_tran.text())
count, rowTran = self.getTransactions(1, idSearch)
self.arrayToTable(rowTran, self.ui.tableWidget_tran, headerTransDetail, columnWidthTransDetail, count, count, 5)
elif senderEvent == "Filter Date":
self.ui.lineEdit_1_tran.clear()
dateSearch = str(self.ui.lineEdit_2_tran.text())
year = dateSearch[:4]
month = dateSearch[5:7]
day = dateSearch[8:]
if isNumber(year) & isNumber(month) & isNumber(day):
dateInput = QtCore.QDate(int(year), int(month), int(day))
if dateInput:
count, rowTran = self.getTransactions(2, dateSearch)
self.arrayToTable(rowTran, self.ui.tableWidget_tran, headerTrans, columnWidthTrans, count, count, 4)
else:
self.ui.lineEdit_1_tran.clear()
self.ui.lineEdit_2_tran.clear()
self.ui.statusBar.clearMessage()
QtGui.QMessageBox.about(self, "Error!", "The value entered was not valid ")
else:
self.ui.lineEdit_1_tran.clear()
self.ui.lineEdit_2_tran.clear()
self.ui.statusBar.clearMessage()
QtGui.QMessageBox.about(self, "Error!", "The value entered was not valid ")
elif senderEvent == "Transaction":
count, rowTran = self.getTransactions(0)
self.arrayToTable(rowTran, self.ui.tableWidget_tran, headerTrans, columnWidthTrans, count, count, 4)
else:
self.ui.lineEdit_1_tran.clear()
self.ui.lineEdit_2_tran.clear()
self.ui.statusBar.clearMessage()
QtGui.QMessageBox.about(self, "Error!", "The value entered was not valid ")
else:
count, rowTran = getLists.getTranList(0)
self.arrayToTable(rowTran, self.ui.tableWidget_tran, headerTrans, columnWidthTrans, count, count, 4)
if count == 0:
self.ui.statusBar.showMessage("No Results Found", 2000)
def viewUnits(self):
flag = 1
self.ui.statusBar.showMessage("Loading Data, please wait...")
self.dashboard()
sender = self.sender()
headerCashier = ['Cashier Unit ID']
headerPdu = ['PDU ID', 'Port', 'Barcode Map']
columnCashier = [800]
columnPdu = [260, 260, 260]
if sender is not None:
senderEvent = sender.text()
if senderEvent == "Refresh":
countCashier, rowCashier, countPdu, rowPDUs = self.getUnits(0)
elif (senderEvent == "Filter Barcode") & isNumber(self.ui.lineEdit_1_units.text()):
barcodeSearch = int(self.ui.lineEdit_1_units.text())
countCashier, rowCashier, countPdu, rowPDUs = self.getUnits(1, barcodeSearch)
elif (senderEvent == "Filter Device ID") & isNumber(self.ui.lineEdit_2_units.text()):
nameSearch = int(self.ui.lineEdit_2_units.text())
countCashier, rowCashier, countPdu, rowPDUs = self.getUnits(2, nameSearch)
elif (senderEvent == "Add Cashier"):
countCashier, rowCashier, countPdu, rowPDUs = self.getUnits(0)
elif (senderEvent == "Add PDU"):
countCashier, rowCashier, countPdu, rowPDUs = self.getUnits(0)
elif (senderEvent == "Remap PDU"):
countCashier, rowCashier, countPdu, rowPDUs = self.getUnits(0)
elif (senderEvent == "Delete"):
countCashier, rowCashier, countPdu, rowPDUs = self.getUnits(0)
elif (senderEvent == "Transaction"):
countCashier, rowCashier, countPdu, rowPDUs = self.getUnits(0)
else:
flag = 0
self.ui.lineEdit_1_units.clear()
self.ui.lineEdit_2_units.clear()
self.ui.statusBar.clearMessage()
QtGui.QMessageBox.about(self, "Error!", "The value entered was not valid ")
else:
countCashier, rowCashier = getLists.getCashierList(0)
countPdu, rowPDUs = getLists.getPDUList(0)
if flag:
self.arrayToTable(rowCashier, self.ui.tableWidget_cashier, headerCashier, columnCashier, countCashier, countCashier, 1)
self.arrayToTable(rowPDUs, self.ui.tableWidget_pdu, headerPdu, columnPdu, countPdu, countPdu, 3)
if (countCashier == 0) & (countPdu == 0):
self.ui.statusBar.showMessage("No Results Found", 2000)
def viewPromo(self):
flag = 1
self.ui.statusBar.showMessage("Loading Data, please wait...")
self.dashboard()
sender = self.sender()
headerPromo = ['Promo ID', 'Barcode', 'Name', 'Unit Price', 'Stock', 'Promotion Bundle Value']
columnWidth = [80, 90, 250, 100, 100, 150]
if sender is not None:
senderEvent = sender.text()
if senderEvent == "Refresh":
count, rowPromo = self.getPromos(0)
elif (senderEvent == "Filter Barcode") & isNumber(self.ui.lineEdit_1_promo.text()):
barcodeSearch = int(self.ui.lineEdit_1_promo.text())
count, rowPromo = self.getPromos(1, barcodeSearch)
elif (senderEvent == "Filter Promo ID") & isNumber(self.ui.lineEdit_2_promo.text()):
idSearch = int(self.ui.lineEdit_2_promo.text())
count, rowPromo = self.getPromos(2, idSearch)
elif senderEvent == "Filter Name":
nameSearch = str(self.ui.lineEdit_3_promo.text())
count, rowPromo = self.getPromos(3, nameSearch)
elif senderEvent == "Create":
count, rowPromo = self.getPromos(0)
elif senderEvent == "Delete":
count, rowPromo = self.getPromos(0)
elif senderEvent == "Transaction":
count, rowPromo = self.getPromos(0)
else:
flag = 0
self.ui.lineEdit_1_promo.clear()
self.ui.lineEdit_2_promo.clear()
self.ui.lineEdit_3_promo.clear()
self.ui.statusBar.clearMessage()
QtGui.QMessageBox.about(self, "Error!", "The value entered was not valid ")
else:
count, rowPromo = getLists.getPromoList(0)
if flag:
self.arrayToTable(rowPromo, self.ui.tableWidget_promo, headerPromo, columnWidth, count, count, 6)
if count == 0:
self.ui.statusBar.showMessage("No Results Found", 2000)
def addNewPerishable(self):
self.child = AddNewPerishable(self)
self.child.show()
def deletePerishable(self):
self.child = DeletePerishable(self)
self.child.show()
def restockPerishable(self):
self.child = RestockPerishable(self)
self.child.show()
def updatePerishable(self):
self.child = UpdatePerishable(self)
self.child.show()
def addUnits(self):
self.child = NewUnit(self)
self.child.show()
def updateUnits(self):
self.child = RemapUnit(self)
self.child.show()
def deleteUnits(self):
self.child = DeleteUnit(self)
self.child.show()
def createPromo(self):
self.child = CreatePromotion(self)
self.child.show()
def deletePromo(self):
self.child = DeletePromotion(self)
self.child.show()
def performWriteoff(self):
self.child = PerformWriteoff(self)
self.child.show()
def performTransaction(self):
self.child = PerformTransaction(self)
self.child.show()
def updateStockAndProduct(self):
self.ui.statusBar.showMessage("Checking for Data, please wait...")
proc = subprocess.Popen("php decryptData.php", shell=True, stdout=subprocess.PIPE)
script_response = proc.stdout.read()
self.ui.statusBar.clearMessage()
if "finished" in script_response:
self.ui.statusBar.showMessage("Product List was successfully updated and re-stocked", 5000)
else:
self.ui.statusBar.showMessage("Failed to download. Check internet connection", 5000)
def orderProducts(self):
self.ui.statusBar.showMessage("Sending Data, please wait...")
proc = subprocess.Popen("php senddata.php", shell=True, stdout=subprocess.PIPE)
script_response = proc.stdout.read()
self.ui.statusBar.clearMessage()
if "success" in script_response:
self.ui.statusBar.showMessage("Orders Sent!", 5000)
else:
self.ui.statusBar.showMessage("Sending Failed. Check internet connection", 5000)
def arrayToTable(self, array, qtable, headerLabels, columnWidth, noOfRows, noOfRowsOnce, noOfColumns):
qtable.setColumnCount(noOfColumns)
qtable.setRowCount(noOfRowsOnce)
qtable.setHorizontalHeaderLabels(headerLabels)
for col in range(noOfColumns):
qtable.setColumnWidth(col, columnWidth[col])
for row in range(noOfRowsOnce):
for column in range(noOfColumns):
if array[row][column] is not None:
if type(array[row][column]) is long:
if len(str(array[row][column])) == 8: #if it is barcode, not to express in E notation
cellContent = array[row][column]
else:
cellContent = float(array[row][column])
else:
cellContent = str(array[row][column])
qtable.setItem(row, column, QtGui.QTableWidgetItem(QtCore.QString("%1").arg(cellContent)))
else:
qtable.setItem(row, column, QtGui.QTableWidgetItem(QtCore.QString("NULL")))
self.ui.statusBar.clearMessage()
def managerLogin():
mid, ok = QtGui.QInputDialog.getText(QtGui.QWidget, 'Manager Login', 'Manager Id:')
pwd, ok = QtGui.QInputDialog.getText(self, 'Manager Login', 'Password:')
if ok:
success = getInfo.getManager(mid,pwd)
if success is not None:
app = QtGui.QApplication(sys.argv)
frame = MainWindow()
frame.show()
sys.exit(app.exec_())
else:
ok = QtGui.QMessageBox.information(self, "Information", "Incorrect id or password!")
if ok:
managerLogin()
#managerLogin()
app = QtGui.QApplication(sys.argv)
frame = MainWindow()
frame.show()
sys.exit(app.exec_())