-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.py
1772 lines (1497 loc) · 64.7 KB
/
home.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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
import os
import sqlite3
import sys, time, json
import pandas as pd
from PyQt5 import QtGui, QtWidgets, QtPrintSupport, QtCore
from PyQt5.QtCore import Qt
from PyQt5.uic import loadUi
import openpyxl
def loadCss(css="main.css"):
if os.path.exists(f"./css/{css}"):
with open(f"./css/{css}", "r") as style:
stylesheet = style.read()
style.close()
return stylesheet
else:
os.makedirs("./css/")
with open(f"./css/{css}", "w") as file:
file.write("*{display:none}")
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def loadpathsql(filepath):
default = "./datas/pystock.db"
db = default
try:
if os.path.exists(filepath):
with open(filepath, "r") as file:
db = file.readline()
else:
db = default
except:
db = default
return db
count = 0
class Worker(QtCore.QObject):
finished = QtCore.pyqtSignal(str)
prog = QtCore.pyqtSignal(str)
def __init__(self, datas, percent):
super(Worker, self).__init__()
self.dbpath = loadpathsql("db.txt")
self.datas = datas
self.percent = percent
self.runs = True
def upload(self):
connexion = sqlite3.connect(self.dbpath)
cursor = connexion.cursor()
i = 0
size = len(self.datas)
for data in self.datas:
if self.runs is True:
stat = f"{i}/{size} articles importés"
insert_data_re = "INSERT INTO posts(title,prix,qtt,vendu,image,barcode) VALUES(?,?,?,?,?,?)"
cursor.execute(insert_data_re,
[data["designation"], int(data["prix"]), int(data["qtt"]), 0, "default.png",
data["codebar"]]
)
connexion.commit()
self.prog.emit(stat)
i += 1
cursor.close()
connexion.close()
self.finished.emit("import terminée")
class Home(QtWidgets.QMainWindow):
def __init__(self):
super(Home, self).__init__()
# loader = loadUi("home.ui")
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.progress)
self.win = loadUi("home.ui")
self.posts = loadUi("posts.ui")
self.savemodal = loadUi("save.ui")
self.mois = loadUi("moi.ui")
self.credit = loadUi("credit.ui")
self.prints = loadUi("prints.ui")
self.getModal = loadUi("getModal.ui")
self.getModal.setModal(True)
# self.win.setupUi(self)
# set window icon
self.banner = "icon.png"
self.dbpath = loadpathsql("db.txt")
self.win.setWindowIcon(QtGui.QIcon("./imgs/icon.ico"))
self.win.icon.setPixmap(QtGui.QPixmap(f"./imgs/{self.banner}"))
# Modify window
self.getModal.setWindowFlag(Qt.FramelessWindowHint)
self.getModal.setAttribute(Qt.WA_TranslucentBackground)
self.getModal.setWindowTitle("recherche en cour...")
# app datas
self.get_app_infos()
# general infos
self.app_banner = ""
self.loaduserinfos()
# update app name
self.win.appName.setText(self.app_name)
self.win.setWindowTitle(self.app_name)
# sidebar
self.setIcons(self.win.goHome, "home2.svg")
self.setIcons(self.win.goPanier, "upload-cloud.svg")
self.setIcons(self.win.goUsers, "users.svg")
self.setIcons(self.win.goStat, "database.svg")
self.setIcons(self.win.goCog, "settings.svg")
self.setIcons(self.win.iconf, "cld.png")
# dynamic title
# router
self.win.goHome.clicked.connect(self.setHome)
self.win.goPanier.clicked.connect(self.setPanier)
self.win.goUsers.clicked.connect(self.setUsers)
self.win.goStat.clicked.connect(self.setStats)
self.win.goCog.clicked.connect(self.setGoCog)
self.win.goinsolved.clicked.connect(self.setGoInsolved)
# set posts in datasTable
# disable btn visiblilit
self.win.success.setVisible(False)
self.win.error.setVisible(False)
self.win.success_users.setVisible(False)
self.win.error_users.setVisible(False)
self.win.poststable.setColumnCount(4)
self.win.poststable.setHorizontalHeaderLabels(("Nom du produit", "Prix", "En Stock", "Identifiant", "Vendre"))
self.win.listall.setColumnCount(4)
self.win.listall.setHorizontalHeaderLabels(("Nom du produit", "Prix", "En Stock", "Identifiant"))
self.win.posts_select.setColumnCount(4)
self.win.posts_select.setHorizontalHeaderLabels(("Nom du produit", "Prix", "Qt", "Total"))
self.win.tabrapport.setColumnCount(3)
self.win.tabrapport.setHorizontalHeaderLabels(("Nom du produit", "Prix", "Quantitee"))
self.win.tabuser.setColumnCount(3)
self.win.tabuser.setHorizontalHeaderLabels(("Nom d'usage", "Mot de passe", "Identifiant"))
self.win.tabinsolved.setColumnCount(6)
self.win.tabinsolved.setHorizontalHeaderLabels(("Nom", "Tel", "Cni", "Somme", "Localisation", "Identifiant"))
self.win.poststable.setColumnWidth(0, 170)
self.win.poststable.setColumnWidth(1, 150)
self.win.poststable.setColumnWidth(2, 70)
self.win.poststable.setColumnWidth(3, 70)
self.win.poststable.setColumnWidth(4, 90)
self.win.listall.setColumnWidth(0, 200)
self.win.listall.setColumnWidth(1, 100)
self.win.listall.setColumnWidth(2, 70)
self.win.listall.setColumnWidth(3, 70)
self.win.tabuser.setColumnWidth(0, 200)
self.win.tabuser.setColumnWidth(1, 110)
self.win.tabuser.setColumnWidth(2, 80)
self.win.tabrapport.setColumnWidth(0, 200)
self.win.tabrapport.setColumnWidth(1, 100)
self.win.tabrapport.setColumnWidth(2, 60)
# self.win.posts_select.setColumnWidth(0,160)
self.loadvente()
self.loaddata()
self.loaduser()
self.loadinsolved()
self.sumdata()
self.sumdatajour()
self.setup_connexion()
# setting page
# settings params
self.code = 1
self.impres = 1
self.head = 1
self.sizep = 380
self.curent_moi = time.localtime().tm_mon
self.current_year = time.localtime().tm_year
self.get_app_infos()
# calling the filter bar
self.search_filter()
#self.win.search.textChanged.connect(self.keyPressEvent)
def keyPressEvent(self, event):
if event.key() == Qt.Key_Enter:
print("Enter pressed ")
def progress(self):
global count
if count > 100:
self.getModal.close()
count += 1
def setup_connexion(self):
self.win.post_save.clicked.connect(self.save_post)
self.win.post_save.setIcon(QtGui.QIcon("./imgs/shopping-ba.svg"))
self.win.refresh.setIcon(QtGui.QIcon("./imgs/refresh.png"))
self.win.refresh.clicked.connect(self.ref)
self.win.user_save.clicked.connect(self.add_user)
self.win.user_save.setIcon(QtGui.QIcon("./imgs/user-plus (1).svg"))
self.win.select_img.clicked.connect(self.select_banner)
self.win.select_img.setIcon(QtGui.QIcon("./imgs/image.svg"))
self.win.save_general.clicked.connect(self.save_general)
self.win.save_general.setIcon(QtGui.QIcon("./imgs/save.svg"))
self.win.add_selection.clicked.connect(self.add_selection)
self.win.add_selection.setIcon(QtGui.QIcon("./imgs/plus-circle.svg"))
self.win.addstock.clicked.connect(self.addstock)
self.win.addstock.setIcon(QtGui.QIcon("./imgs/plus-circle.svg"))
self.win.reset.clicked.connect(self.reset_selection)
self.win.reset.setIcon(QtGui.QIcon("./imgs/trash.svg"))
self.win.resetdef.clicked.connect(self.removepost)
self.win.resetdef.setIcon(QtGui.QIcon("./imgs/trash.svg"))
self.win.deluser.clicked.connect(self.deluser)
self.win.deluser.setIcon(QtGui.QIcon("./imgs/trash.svg"))
self.win.sale.clicked.connect(self.sale)
self.win.sale.setIcon(QtGui.QIcon("./imgs/shop.svg"))
self.win.closeSection.clicked.connect(self.endsection)
self.win.closeSection.setIcon(QtGui.QIcon("./imgs/log-out.svg"))
self.win.generate.clicked.connect(self.generaterapport)
self.win.generate.setIcon(QtGui.QIcon("./imgs/file-text.svg"))
self.win.saveconf.clicked.connect(self.saveconf)
self.win.resetdb.clicked.connect(self.restore)
self.win.chooseexcel.clicked.connect(self.chooseexcel)
self.win.confirmimport.clicked.connect(self.biguploadaconf)
self.win.solv.clicked.connect(self.solv)
self.win.search_btn.setIcon(QtGui.QIcon("./imgs/search.svg"))
self.win.layer.setPixmap(QtGui.QPixmap(f"./imgs/layers (1).svg").scaled(30, 30))
self.win.list.setPixmap(QtGui.QPixmap(f"./imgs/list.svg").scaled(30, 30))
self.win.icolist.setPixmap(QtGui.QPixmap(f"./imgs/list.svg").scaled(30, 30))
self.win.icoadd.setPixmap(QtGui.QPixmap(f"./imgs/upload.svg").scaled(30, 30))
self.win.icoadduser.setPixmap(QtGui.QPixmap(f"./imgs/user-check (1).svg").scaled(30, 30))
self.win.icolistuser.setPixmap(QtGui.QPixmap(f"./imgs/list.svg").scaled(30, 30))
self.win.icorapport.setPixmap(QtGui.QPixmap(f"./imgs/pie-chart.svg").scaled(30, 30))
self.win.icoqtt.setPixmap(QtGui.QPixmap(f"./imgs/sb2.svg").scaled(60, 60))
self.win.icosum.setPixmap(QtGui.QPixmap(f"./imgs/sc.svg").scaled(60, 60))
# rapport connexion ui
self.win.jour.clicked.connect(self.loadrapportday)
self.win.mois.clicked.connect(self.loadrapportmois)
self.win.ok.clicked.connect(self.filter)
self.win.savepost.clicked.connect(self.savepost)
self.win.this_mois.clicked.connect(self.mois_modal)
self.savemodal.savetoexcel.clicked.connect(self.savetoexcel2)
self.credit.update.clicked.connect(self.updatecredit)
self.win.showupdate.clicked.connect(self.modalcredit)
self.win.savepost.setIcon(QtGui.QIcon("./imgs/save.svg"))
self.prints.direct.clicked.connect(self.directprint)
self.prints.browser.clicked.connect(self.broserprint)
def ref(self):
self.loaddata("")
def loaddata(self, filter=""):
self.getModal.txt.setText(f"Chargement des articles...")
self.getModal.setModal(True)
self.getModal.show()
connection = sqlite3.connect(self.dbpath)
cur = connection.cursor()
sqlquery = f"SELECT * FROM posts WHERE title LIKE ? AND visible = ? ORDER BY id DESC"
print("start fetch")
cur.execute(sqlquery, ['%' + filter + '%', 1])
datas = cur.fetchall()
size = 50
try:
size = len(datas)
except:
pass
self.win.poststable.setRowCount(size)
self.win.listall.setRowCount(size)
tablerow = 0
for row in range(size):
self.win.poststable.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f""))
self.win.poststable.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f""))
self.win.poststable.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f""))
self.win.poststable.setItem(tablerow, 3, QtWidgets.QTableWidgetItem(f""))
self.win.poststable.setItem(tablerow, 4, QtWidgets.QTableWidgetItem(f""))
self.win.poststable.setCellWidget(tablerow, 4, QtWidgets.QLabel(""))
# list
self.win.listall.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f""))
self.win.listall.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f""))
self.win.listall.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f""))
self.win.listall.setItem(tablerow, 3, QtWidgets.QTableWidgetItem(f""))
tablerow += 1
tablerow = 0
for row in datas:
btn = QtWidgets.QPushButton("")
btn.setObjectName("addcard")
btn.setStyleSheet(loadCss())
btn.setIcon(QtGui.QIcon("./imgs/shop.svg"))
self.win.poststable.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f"{row[1]}"))
self.win.poststable.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f"{'{:,}'.format(row[2])} FCFA"))
if int(row[3]) - int(row[4]) == 0:
self.win.poststable.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f"Rupture de stock"))
else:
self.win.poststable.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f"{int(row[3]) - int(row[4])}"))
self.win.poststable.setItem(tablerow, 3, QtWidgets.QTableWidgetItem(f"{row[0]}"))
self.win.poststable.setCellWidget(tablerow, 4, btn)
# list
self.win.listall.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f"{row[1]}"))
self.win.listall.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f"{'{:,}'.format(row[2])} FCFA"))
if int(row[3]) - int(row[4]) == 0:
self.win.listall.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f"Rupture de stock"))
else:
self.win.listall.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f"{int(row[3]) - int(row[4])}"))
self.win.listall.setItem(tablerow, 3, QtWidgets.QTableWidgetItem(f"{row[0]}"))
tablerow += 1
# self.getModal.setModal(False)
# self.getModal.close()
# self.getModal.close()
self.timer.start(100)
cur.close()
connection.close()
def loadvente(self):
connection = sqlite3.connect(self.dbpath)
cur = connection.cursor()
sqlquery = f"SELECT vente.qtt, posts.title, posts.prix FROM vente LEFT JOIN posts ON vente.post_id = posts.id WHERE vente.validate = ?"
cur.execute(sqlquery, [0])
datas = cur.fetchall()
size = 10
try:
size = len(datas)
except:
pass
self.win.posts_select.setRowCount(size)
print(datas)
tablerow = 0
for row in range(size):
self.win.posts_select.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f""))
self.win.posts_select.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f""))
self.win.posts_select.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f""))
self.win.posts_select.setItem(tablerow, 3, QtWidgets.QTableWidgetItem(f""))
tablerow += 1
tablerow = 0
for row in datas:
self.win.posts_select.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f"{row[1]}"))
self.win.posts_select.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f"{'{:,}'.format(row[2])} F"))
self.win.posts_select.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f"{row[0]}"))
self.win.posts_select.setItem(tablerow, 3, QtWidgets.QTableWidgetItem(
f"{'{:,}'.format(int(row[0]) * int(row[2]))} F"))
tablerow += 1
cur.close()
connection.close()
self.sumdata()
def loaduserinfos(self):
with open("./datas/user.json", "r") as file:
self.userinfos = json.load(file)
self.win.appUser.setText(
f"<html><head/><body><p align='right'>{self.userinfos['pseudo']}</p></body></html>")
self.win.goPanier.setVisible(int(self.userinfos['role']))
self.win.goUsers.setVisible(int(self.userinfos['role']))
# self.win.goStat.setVisible(int(self.userinfos['role']))
self.win.goCog.setVisible(int(self.userinfos['role']))
def loaduser(self, filter=""):
connection = sqlite3.connect(self.dbpath)
cur = connection.cursor()
sqlquery = f"SELECT * FROM users WHERE pseudo LIKE ? ORDER BY id DESC"
print("start fetch")
datas = cur.execute(sqlquery, ['%' + filter + '%'])
size = 10
try:
size = len(datas)
except:
pass
self.win.tabuser.setRowCount(size)
tablerow = 0
for row in range(size):
self.win.tabuser.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f""))
self.win.tabuser.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f""))
self.win.tabuser.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f""))
# list
tablerow += 1
tablerow = 0
for row in datas:
self.win.tabuser.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f"{row[1]}"))
self.win.tabuser.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f"{row[5]}"))
self.win.tabuser.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f"{row[0]}"))
# list
tablerow += 1
def loadinsolved(self, filter=""):
connection = sqlite3.connect(self.dbpath)
cur = connection.cursor()
sqlquery = f"SELECT * FROM insolved WHERE solved LIKE ? ORDER BY id DESC"
cur.execute(sqlquery, [0])
datas = cur.fetchall()
size = 10
try:
size = len(datas)
except:
pass
self.win.tabinsolved.setRowCount(size)
tablerow = 0
for row in range(size):
self.win.tabinsolved.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f""))
self.win.tabinsolved.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f""))
self.win.tabinsolved.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f""))
self.win.tabinsolved.setItem(tablerow, 3, QtWidgets.QTableWidgetItem(f""))
self.win.tabinsolved.setItem(tablerow, 4, QtWidgets.QTableWidgetItem(f""))
self.win.tabinsolved.setItem(tablerow, 5, QtWidgets.QTableWidgetItem(f""))
# list
tablerow += 1
tablerow = 0
for row in datas:
self.win.tabinsolved.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f"{row[1]}"))
self.credit.nom.setText(f"{row[1]}")
self.win.tabinsolved.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f"{row[2]}"))
self.credit.tel.setText(f"{row[2]}")
self.win.tabinsolved.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f"{row[4]}"))
self.credit.cni.setText(f"{row[4]}")
self.win.tabinsolved.setItem(tablerow, 3, QtWidgets.QTableWidgetItem(f"{row[7]}"))
self.credit.somme.setValue(int(row[7]))
self.win.tabinsolved.setItem(tablerow, 4, QtWidgets.QTableWidgetItem(f"{row[3]}"))
self.credit.localisation.setText(f"{row[3]}")
self.win.tabinsolved.setItem(tablerow, 5, QtWidgets.QTableWidgetItem(f"{row[0]}"))
# list
tablerow += 1
def loadrapportday(self, filter=""):
connection = sqlite3.connect(self.dbpath)
cur = connection.cursor()
jour = f'{time.localtime().tm_mday}'
sqlquery = f"SELECT vente.qtt, posts.title, posts.prix FROM vente LEFT JOIN posts ON vente.post_id = posts.id WHERE vente.validate = ? AND vente.jour = ? AND vente.mois = ? AND vente.an = ?"
cur.execute(sqlquery, [1, jour, self.curent_moi, self.current_year])
datas = cur.fetchall()
size = 50
try:
size = len(datas)
except:
pass
self.win.tabrapport.setRowCount(size)
print(datas)
tablerow = 0
for row in range(size):
self.win.tabrapport.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f""))
self.win.tabrapport.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f""))
self.win.tabrapport.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f""))
tablerow += 1
tablerow = 0
for row in datas:
self.win.tabrapport.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f"{row[1]}"))
self.win.tabrapport.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f"{'{:,}'.format(row[2])} FCFA"))
self.win.tabrapport.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f"{row[0]}"))
tablerow += 1
print(row[0])
cur.close()
connection.close()
self.sumdatajour()
self.win.current.setText("Jour")
def loadrapportmois(self, filter=""):
self.curent_moi = time.localtime().tm_mon
self.win.this_mois.setText(self.getMois(self.curent_moi))
connection = sqlite3.connect(self.dbpath)
cur = connection.cursor()
jour = f'{time.localtime().tm_mon}'
sqlquery = f"SELECT vente.qtt, posts.title, posts.prix FROM vente LEFT JOIN posts ON vente.post_id = posts.id WHERE vente.validate = ? AND vente.mois = ? AND vente.an = ?"
cur.execute(sqlquery, [1, self.curent_moi, self.current_year])
datas = cur.fetchall()
size = 50
try:
size = len(datas)
except:
pass
self.win.tabrapport.setRowCount(size)
print(datas)
tablerow = 0
for row in range(size):
self.win.tabrapport.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f""))
self.win.tabrapport.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f""))
self.win.tabrapport.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f""))
tablerow += 1
tablerow = 0
for row in datas:
self.win.tabrapport.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f"{row[1]}"))
self.win.tabrapport.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f"{'{:,}'.format(row[2])} FCFA"))
self.win.tabrapport.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f"{row[0]}"))
tablerow += 1
print(row[0])
cur.close()
connection.close()
self.sumdatamois()
self.win.current.setText("Mois")
def loadrapportmoisfilt(self, filter=""):
connection = sqlite3.connect(self.dbpath)
cur = connection.cursor()
jour = f'{time.localtime().tm_mon}'
year = time.localtime().tm_year
sqlquery = f"SELECT vente.qtt, posts.title, posts.prix FROM vente LEFT JOIN posts ON vente.post_id = posts.id WHERE vente.validate = ? AND vente.mois = ? AND vente.an = ?"
cur.execute(sqlquery, [1, filter, self.current_year])
datas = cur.fetchall()
size = 50
try:
size = len(datas)
except:
pass
self.win.tabrapport.setRowCount(size)
print(datas)
tablerow = 0
for row in range(size):
self.win.tabrapport.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f""))
self.win.tabrapport.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f""))
self.win.tabrapport.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f""))
tablerow += 1
tablerow = 0
for row in datas:
self.win.tabrapport.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(f"{row[1]}"))
self.win.tabrapport.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(f"{'{:,}'.format(row[2])} FCFA"))
self.win.tabrapport.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(f"{row[0]}"))
tablerow += 1
print(row[0])
cur.close()
connection.close()
self.sumdatamoisfilt()
self.win.current.setText("Mois")
# app
def setIcons(self, elem, icon='default.png'):
try:
elem.setIcon(QtGui.QIcon(f"./imgs/{icon}"))
except:
elem.setPixmap(QtGui.QPixmap(f"./imgs/{icon}").scaled(30, 30))
def setPage(self, page, title, ico):
# self.loadvente()
# self.loaddata()
self.setIcons(self.win.iconf, icon=f"{ico}")
self.win.titlef.setText(title)
self.win.stackedWidget.setCurrentWidget(page)
self.win.setWindowTitle(title)
self.win.success_update.setVisible(False)
# pages
def setHome(self):
self.loadvente()
# self.loaddata()
self.setPage(self.win.home, "Store", "pn.png")
def setPanier(self):
self.win.success.setVisible(False)
self.win.error.setVisible(False)
self.setPage(self.win.addproduct, "Televerser un produit", "add.png")
def setUsers(self):
self.loaduser()
self.setPage(self.win.users, "Utilisateurs", "ad.png")
self.win.success_users.setVisible(False)
self.win.error_users.setVisible(False)
def setStats(self):
mois = time.localtime().tm_mon
self.loadrapportday()
self.sumdatajour()
self.setPage(self.win.stats, "Statistique", "trending-up.svg")
self.win.this_mois.setText(self.getMois(mois))
def setGoCog(self):
self.setPage(self.win.settings, "Paramêtre", "setting.png")
def setGoInsolved(self):
self.loadinsolved()
self.setPage(self.win.page_insolved, "Insolvables", "send.png")
@staticmethod
def closeWindow(self):
exit(0)
# page_add_post
def save_post(self):
self.win.success.setVisible(False)
self.win.error.setVisible(False)
# get data
titre = self.win.title_post.text()
qtt = self.win.qtt_post.text()
price = self.win.price_post.text()
barcode = self.win.barcode.text().lower()
connection = sqlite3.connect(self.dbpath)
cur = connection.cursor()
def verifycode():
if len(barcode) >= 3:
re = f"SELECT * FROM posts WHERE barcode = ?"
cur.execute(re, [barcode])
codes = cur.fetchall()
nbcode = 0
for code in codes:
nbcode += 1
if nbcode >= 1:
return True
else:
return False
else:
return False
if not verifycode():
if titre == "" or qtt == "" or price == "":
self.win.error.setVisible(True)
print("error")
return False
else:
print("sauvegarde..")
# insert in database
print("...av")
insert_data_re = "INSERT INTO posts(title,prix,qtt,vendu,image,barcode) VALUES(?,?,?,?,?,?)"
cur.execute(insert_data_re, [titre, int(price), int(qtt), 0, "default.png", barcode])
print("...ap")
self.win.success.setVisible(True)
# renitialisation des champs
self.win.title_post.setText("")
self.win.qtt_post.setValue(1)
self.win.price_post.setValue(100)
self.win.barcode.setText("")
connection.commit()
else:
self.showbox(content="Ce produit existe déja en base de donnée")
cur.close()
connection.close()
print(f'{titre, qtt, price}')
self.loaddata()
# page_manage_users
def add_user(self):
self.win.success_users.setVisible(False)
self.win.error_users.setVisible(False)
# get data
user_name = self.win.user_name.text()
password = self.win.password.text()
try:
if user_name == "" or password == '':
self.win.error_users.setVisible(True)
print("error")
return False
else:
connection = sqlite3.connect(self.dbpath)
cur = connection.cursor()
# insert in database
insert_data_re = "INSERT INTO users(pseudo,name,avatar,role,password) VALUES(?,?,?,?,?)"
cur.execute(insert_data_re, [user_name, "", "avatar.png", 0, password])
print("...ap")
self.win.success_users.setVisible(True)
self.win.user_name.setText("")
self.win.password.setText("")
connection.commit()
connection.close()
except:
self.win.error_users.setVisible(True)
self.loaduser()
# page_settings
def select_banner(self):
select = QtWidgets.QFileDialog.getOpenFileName(filter="*.jpg;*.png;*.ico;*.svg")
file = select[0]
if file == '':
file = self.file
print("aucune image selectionnée !")
else:
self.win.banner_up.setPixmap(QtGui.QPixmap(file).scaled(200, 400, QtCore.Qt.KeepAspectRatio))
self.ban = file
def saveconf(self):
imprim = self.win.imprim.isChecked()
code = self.win.code.isChecked()
header = self.win.header.isChecked()
print(code)
connexion = sqlite3.connect(self.dbpath)
cursor = connexion.cursor()
cursor.execute(f"UPDATE settings SET impression = {imprim}, codebar = {code}, header = {header} WHERE id = ?",
[1])
connexion.commit()
cursor.close()
connexion.close()
self.get_app_infos()
self.showbox(msgtype=QtWidgets.QMessageBox.Information, title="success",
content="Modifications prisent en compte")
def save_general(self):
try:
# general
new_app_name = self.win.entreprise.text()
new_banner = self.ban
new_banner_name = new_banner.split("/")[-1]
# upload_files
with open(new_banner, "rb") as filer:
with open(f"./adm/{new_banner_name}", "wb") as file:
data = filer.read()
file.write(data)
# Persist in database
connexion = sqlite3.connect(self.dbpath)
cursor = connexion.cursor()
insert_data_re = "UPDATE settings SET app_name = ?"
cursor.execute(insert_data_re, [new_app_name])
insert_data_re = "UPDATE settings SET app_banner = ?"
cursor.execute(insert_data_re, [new_banner_name])
connexion.commit()
cursor.close()
connexion.close()
self.win.success_update.setVisible(True)
self.get_app_infos()
except:
# Persist in database
connexion = sqlite3.connect(self.dbpath)
cursor = connexion.cursor()
insert_data_re = "UPDATE settings SET app_name = ?"
cursor.execute(insert_data_re, [new_app_name])
connexion.commit()
cursor.close()
connexion.close()
self.win.success_update.setVisible(True)
self.get_app_infos()
def get_app_infos(self):
connexion = sqlite3.connect(self.dbpath)
cursor = connexion.cursor()
requetes_infos = "SELECT * FROM settings ORDER BY id DESC LIMIT 1"
for data in cursor.execute(requetes_infos):
self.app_name = data[1]
self.app_banner = data[2]
ban = data[2]
impression = data[3]
codebar = data[4]
header = data[5]
self.win.appName.setText(self.app_name)
self.win.imprim.setChecked(int(impression))
self.win.code.setChecked(int(codebar))
self.win.header.setChecked(int(header))
self.code = codebar
self.impres = impression
self.head = header
self.win.barcode.setVisible(self.code)
self.win.labelcode.setVisible(self.code)
self.banner = self.app_banner
self.win.entreprise.setText(self.app_name)
self.win.banner_up.setPixmap(QtGui.QPixmap(f"./adm/{ban}").scaled(200, 400, QtCore.Qt.KeepAspectRatio))
self.file = self.app_banner
print(self.app_name)
cursor.close()
connexion.close()
def search_filter(self):
def filter():
search_bar_text = self.win.search.text()
self.loaddata(filter=search_bar_text)
def load():
pass
self.win.search.textChanged.connect(load)
self.win.search_btn.clicked.connect(filter);
# page Manage posts
def add_selection(self):
id = self.win.id.text().lower()
qtt = self.win.qtt.text()
if id == "":
print("Entrez un identifiant")
self.showbox(content="Veillez entrer un identifiant valide !")
elif qtt == "":
print("Entrez une quantitée")
self.showbox(content="Veillez entrer une quantité")
else:
connexion = sqlite3.connect(self.dbpath)
cursor = connexion.cursor()
get_id_re = "SELECT * FROM posts WHERE id = ?"
id_number = 0;
in_stock = 0;
vendu = 0;
for identifiant in cursor.execute(get_id_re, [id]):
id_number += 1
in_stock = int(identifiant[3]) - int(identifiant[4])
vendu = identifiant[4]
if id_number <= 0:
get_code_re = "SELECT * FROM posts WHERE barcode = ?"
cursor.execute(get_code_re, [id])
data = cursor.fetchall()
for code in data:
id = code[0]
id_number += 1
in_stock = int(code[3]) - int(code[4])
vendu = code[4]
cursor.close()
connexion.close()
if id_number <= 0:
print("Produit introuvable")
self.showbox(content="Ce produit n'existe pas!")
elif int(qtt) <= int(in_stock):
self.ftime = st = f'{time.localtime().tm_mday}/{time.localtime().tm_mon}/{time.localtime().tm_year}/{time.localtime().tm_hour}/{time.localtime().tm_min} '
jour = f'{time.localtime().tm_mday}'
mois = f'{time.localtime().tm_mon}'
connexion2 = sqlite3.connect(self.dbpath)
cursor2 = connexion2.cursor()
insert_vente_re = "INSERT INTO vente(post_id, user_id, qtt, validate, created_at, jour, mois, an) VALUES(?,?,?,?,?,?,?,?)"
update_post_re = "UPDATE posts SET vendu = ?"
cursor2.execute(insert_vente_re, [id, 1, qtt, 0, self.ftime, jour, mois, time.localtime().tm_year])
connexion2.commit()
cursor2.close()
connexion2.close()
print("Produit ajouté avec success :) ")
self.win.id.setText("")
self.win.qtt.setText("")
self.loadvente()
else:
print("Entrez une quantitée convenable !")
self.showbox(content="Stock restant insuffisant !")
def reset_selection(self):
self.loadvente()
connexion3 = sqlite3.connect(self.dbpath)
cursor3 = connexion3.cursor()
delete_selection_re = "DELETE FROM vente WHERE validate = ?"
cursor3.execute(delete_selection_re, [0])
connexion3.commit()
self.loadvente()
cursor3.close()
connexion3.close()
self.loadvente()
def sale(self):
# PRINT
if self.impres:
if self.win.posts_select.rowCount() >= 1:
self.prints.setModal(True)
self.prints.setWindowTitle("choix d'impression")
self.prints.show()
else:
self.showbox(content="Aucun contenu à vendre ! ")
else:
self.complete()
def complete(self):
# insolved
insolved = self.win.insolved.isChecked()
if insolved:
(name, nameok) = self.showdialog(title="Nom", msg="Entrez le nom du client")
(phone, phoneok) = self.showdialog(title="phone", msg="Entrez le numero de telephone du client")
(localisation, localisationok) = self.showdialog(title="habitation",
msg="Entrez le lieu d'habitat du client ")
(cni, cniok) = self.showdialog(title="CNI", msg="Entrez le numero de la cni du client")
con = sqlite3.connect(self.dbpath)
cu = con.cursor()
cu.execute("SELECT * FROM vente WHERE validate NOT LIKE ? LIMIT 100", [1])
datas = cu.fetchall()
ids = []
somme = 0
for id in datas:
ids.append(id[1])
cu.execute("SELECT prix FROM posts WHERE id = ?", [id[1]])
prices = cu.fetchall()
for price in prices:
somme += int(price[0])
cu.execute(
"INSERT INTO insolved(name, phone, lacalisation, cni, solved, posts_ids, somme) values(?,?,?,?,?,?,?)",
[name, phone, localisation, cni, 0, str(f"{ids}"), somme])
con.commit()
cu.close()
con.close()
self.showbox(msgtype=QtWidgets.QMessageBox.Information, title="La client à bien été enregistré",
content="La client à bien été enregistré")
self.win.insolved.setChecked(False)
print(f"name: {name}; nameok:{nameok} ")
# validate vente
connexion = sqlite3.connect(self.dbpath)
cursor = connexion.cursor()
# update post
id = []
in_stock = []
qt = []
cursor.execute("SELECT * FROM vente WHERE validate NOT LIKE ? LIMIT 100", [1])
datas = cursor.fetchall()
for identifiant in datas:
print(f"=============================================={identifiant}===================================")
print(f"=================================================================================")
post_id = identifiant[1]
qtt = identifiant[3]
id.append(post_id)
qt.append(qtt)
get_in_stock_re = f"SELECT * FROM posts WHERE id = ?"
for stock in cursor.execute(get_in_stock_re, [post_id]):
in_stock.append(int(stock[4]))
i = 0
for num in range(len(id)):
update_post_re = f"UPDATE posts SET vendu = {int(in_stock[i] + int(qt[i]))} WHERE id = ?"
cursor.execute(update_post_re, [id[i]])
connexion.commit()
self.loadvente()
self.loaddata()
i += 1
# update validate
update_vente_re = "UPDATE vente SET validate = 1 WHERE validate = ?"
cursor.execute(update_vente_re, [0])
connexion.commit()
cursor.close()
connexion.close()
self.loadvente()
self.loaddata()