-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_dtr.py
1553 lines (1218 loc) · 47.5 KB
/
project_dtr.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 -*-
# Form implementation generated from reading ui file 'project_dtr.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
import mysql
from PyQt5 import QtCore, QtGui, QtWidgets
from db import con
import sys
from PyQt5.QtCore import QVariant, Qt, QDate
from PyQt5.QtGui import QColor
from dialogs import Dialog
from PyQt5.QtWidgets import QMessageBox, QDialog
import win32com.client as win32
from project_activity import Ui_Activity
class Ui_DTR(object):
ProjectTab=""
#cell status
not_editable = QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled
editable = QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsEditable
BtnBack=""
LBProjectTitle = "" #Project Title
DTRWidget = "" # Widget for DTR List
DTRWeekList = "" # List of Weeks (DTR)
LBDateDTR = "" # DTR Week Date Title
# DTR page Buttons
BtnPrint = "" # BTN Print
BtnEdit = "" # BTN Edit DTR Page
BtnCancel = "" # BTN Cancel DTR Page
BtnSave = ""
BtnPrev = "" # Button Prev DTR ( < )
BtnNext = "" # Button Next DTR ( > )
#DTR Table Stack
DTRStack = ""
#Page Number Indicator
page_num = 1
LBPageCount = ""
# DTR Pages (Null by Default)
DTR_Pages = []
# Date Title (Date Title by Default)
Date_title = "Date Title"
# List of Employees (Null by Default)
Employees = ['']
# List of Dates (Null by Default)
Dates = ['','','','','','','']
#total page
Total_page = 0
TBLdtr = "" # DTR Table
LEName = "" # Employee Name
LEPostion = "" # Employee Position
projectid=0
weekvalue=0 #list selection value
weekarray=[] #list of week multidimentional
week_list=[] #week on list selection
week_list2=[]
employee_id=[]
currentEmployee=0
def printDTR():
cursor = con.cursor()
cursor.execute(f"SELECT * FROM `projects` WHERE `project_id` = {Ui_DTR.projectid}")
res = cursor.fetchall()
projname=res[0][1]
projsite=res[0][3]
xlApp = win32.Dispatch('Excel.Application')
xlApp.Visible = True
# create a new excel workbook
wb = xlApp.Workbooks.Add()
# create a new excel worksheet
ws = wb.worksheets.add
ws.name ='DTR'
added=0
index=0
Ui_DTR.page_num=0
while Ui_DTR.page_num<Ui_DTR.Total_page:
Ui_DTR.Next()
rows = []
columnHeaders = ["","","","","","",""]
#add border
ws.Range(ws.cells(6+added, 1),ws.cells(15+added, 8)).verticalalignment=-4108
ws.Range(ws.cells(6+added, 1),ws.cells(15+added, 8)).horizontalalignment=-4108
ws.Range(ws.cells(6+added, 1),ws.cells(15+added, 8)).Borders(2).Weight = 3
ws.Range(ws.cells(6+added, 2),ws.cells(16+added, 8)).Borders(3).Weight = 3
ws.Range(ws.Cells(6+added,2),ws.Cells(7+added,2)).MergeCells = True
ws.Range(ws.Cells(6+added,3),ws.Cells(6+added,4)).MergeCells = True
ws.Range(ws.Cells(6+added,5),ws.Cells(6+added,6)).MergeCells = True
ws.Range(ws.Cells(6+added,7),ws.Cells(6+added,8)).MergeCells = True
ws.Range(ws.Cells(15+added,2),ws.Cells(15+added,6)).MergeCells = True
ws.Range(ws.Cells(1+added,3),ws.Cells(1+added,5)).MergeCells = True
ws.Range(ws.Cells(2+added,3),ws.Cells(2+added,5)).MergeCells = True
ws.Range(ws.Cells(3+added,3),ws.Cells(3+added,5)).MergeCells = True
ws.Range(ws.Cells(4+added,3),ws.Cells(4+added,5)).MergeCells = True
ws.Range(ws.Cells(5+added,3),ws.Cells(5+added,5)).MergeCells = True
# retrieve table content
for row in range(Ui_DTR.TBLdtr.rowCount()):
record = []
for col in range(Ui_DTR.TBLdtr.columnCount()):
if (row>=2) & (row<=8):
if ((col>=1) & (col<=4))| (col==6):
val = Ui_DTR.TBLdtr.cellWidget(row,col).value()
record.append(val)
else:
date = Ui_DTR.TBLdtr.item(row, col).text()
record.append(date)
else:
record.append(Ui_DTR.TBLdtr.item(row, col).text())
rows.append(record)
# insert table content to Excel
ws.Range(ws.cells(6+added, 2),ws.cells(len(rows)+5+added, len(columnHeaders)+1)).value = rows
ws.Columns.AutoFit()
#insert personal Info
ws.cells(1+added, 2).value = "Name"
ws.cells(2+added, 2).value = "Position"
ws.cells(3+added, 2).value = "Project"
ws.cells(4+added, 2).value = "Location"
ws.cells(5+added, 2).value = "Period"
ws.cells(1+added, 3).value = f": {Ui_DTR.LEName.text()}"
ws.cells(2+added, 3).value = f": {Ui_DTR.LEPostion.text()}"
ws.cells(3+added, 3).value = f": {projname}"
ws.cells(4+added, 3).value = f": {projsite}"
ws.cells(5+added, 3).value = f": {Ui_DTR.week_list2[index]}"
added=added+16
index=index+1
def resetData():
#reset
Ui_DTR.LBPageCount.setText(f"1 out of {1}")
Ui_DTR.LEName.setText("")
Ui_DTR.LEPostion.setText("")
Ui_DTR.page_num = 1
Ui_DTR.LBDateDTR.setText(Ui_DTR.Date_title)
Ui_DTR.BtnPrev.setEnabled(False)
Ui_DTR.BtnNext.setEnabled(False)
Ui_DTR.BtnEdit.hide()
Ui_DTR.BtnPrint.hide()
Ui_DTR.BtnCancel.hide()
Ui_DTR.BtnSave.hide()
Ui_DTR.DTRWeekList.setEnabled(True)
Ui_DTR.BtnBack.show()
#reset
for k in range(2,9):
for y in range(0,7):
if ((y==1) | (y==2) | (y==3) | (y==4) | (y==6)):
Ui_DTR.TBLdtr.removeCellWidget(k, y)
else:
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
item.setText("")
item.setFlags(Ui_DTR.not_editable) #Disable item edit
Ui_DTR.TBLdtr.setItem(k, y, item)
trh = QtWidgets.QTableWidgetItem()
trh = Ui_DTR.TBLdtr.item(9,5)
trh.setTextAlignment(QtCore.Qt.AlignCenter)
trh.setText("")
tot = QtWidgets.QTableWidgetItem()
tot = Ui_DTR.TBLdtr.item(9,6)
tot.setTextAlignment(QtCore.Qt.AlignCenter)
tot.setText("")
def editDTR(BtnBack):
Ui_DTR.insert_data(True)
Ui_DTR.BtnEdit.hide()
Ui_DTR.BtnCancel.show()
Ui_DTR.BtnSave.show()
Ui_DTR.BtnPrint.hide()
Ui_DTR.BtnPrev.hide()
Ui_DTR.BtnNext.hide()
BtnBack.hide()
Ui_DTR.ProjectTab.setEnabled(False)
Ui_DTR.DTRWeekList.setEnabled(False)
def cancelEdit(BtnBack):
if (Dialog.confirm_dialog("Are you sure you want to discard changes?") == QMessageBox.Ok):
Ui_DTR.insert_data(False)
Ui_DTR.BtnEdit.show()
Ui_DTR.BtnCancel.hide()
Ui_DTR.BtnSave.hide()
Ui_DTR.BtnPrint.show()
Ui_DTR.BtnPrev.show()
Ui_DTR.BtnNext.show()
BtnBack.show()
Ui_DTR.DTRWeekList.setEnabled(True)
Ui_DTR.ProjectTab.setEnabled(True)
def saveEdit(BtnBack):
if (Dialog.confirm_dialog("Are you sure you want to update changes?") == QMessageBox.Ok):
cursor = con.cursor()
totalrh=0
totalot=0
invalid = False
row_invalid = ""
for k in range(2,9):
if (Ui_DTR.TBLdtr.item(k,0).text() == ""):
continue
in_AM = Ui_DTR.TBLdtr.cellWidget(k,1).value()
out_AM = Ui_DTR.TBLdtr.cellWidget(k,2).value()
in_PM = Ui_DTR.TBLdtr.cellWidget(k,3).value()
out_PM = Ui_DTR.TBLdtr.cellWidget(k,4).value()
ot = Ui_DTR.TBLdtr.cellWidget(k,6).value()
if (in_AM >= out_AM and in_AM != 0 and out_AM != 0) | (in_PM >= out_PM and in_PM != 0 and out_PM != 0) | (in_AM == 0 and out_AM > 0) | (in_PM == 0 and out_PM > 0) | (in_AM < 8 and in_AM != 0 ):
invalid = True
row_invalid = row_invalid + ", " + (str(k-1))
if invalid == False:
#computation
for k in range(2,9):
date = Ui_DTR.TBLdtr.item(k,0).text()
if len(date)>0:
date=QDate(Ui_DTR.process_date2(date))
date = date.toString("yyyy,MM,dd")
in_AM = Ui_DTR.TBLdtr.cellWidget(k,1).value()
out_AM = Ui_DTR.TBLdtr.cellWidget(k,2).value()
in_PM = Ui_DTR.TBLdtr.cellWidget(k,3).value()
out_PM = Ui_DTR.TBLdtr.cellWidget(k,4).value()
AM = 0
PM = 0
if int(out_AM)>0:
AM = int(out_AM)-int(in_AM)
if int(out_PM)>0:
PM = int(out_PM)-int(in_PM)
total = AM+PM
totalrh=totalrh+total
rh = QtWidgets.QTableWidgetItem()
rh = Ui_DTR.TBLdtr.item(k,5)
rh.setTextAlignment(QtCore.Qt.AlignCenter)
rh.setText(str(total))
ot = Ui_DTR.TBLdtr.cellWidget(k,6).value()
totalot = totalot + int(ot)
try:
#update db
query2 = f"UPDATE `projectdtr` SET `AM_TimeIn`={in_AM} ,`AM_TimeOut`={out_AM} ,`PM_TimeIn`={in_PM}, `PM_TimeOut`={out_PM} ,`RH`={total} ,`OT`={ot} WHERE `date`='{date}' AND `employee_id`={Ui_DTR.currentEmployee}"
cursor.execute(query2)
con.commit()
except :
Dialog.msg_dialog(str(sys.exc_info()))
trh = QtWidgets.QTableWidgetItem()
trh = Ui_DTR.TBLdtr.item(9,5)
trh.setTextAlignment(QtCore.Qt.AlignCenter)
trh.setText(str(totalrh))
tot = QtWidgets.QTableWidgetItem()
tot = Ui_DTR.TBLdtr.item(9,6)
tot.setTextAlignment(QtCore.Qt.AlignCenter)
tot.setText(str(totalot))
# update payroll
cursor.execute(f"SELECT * FROM `projectdtr` WHERE `project_id`={Ui_DTR.projectid} AND `employee_id`={Ui_DTR.currentEmployee}")
res1 = cursor.fetchall()
cursor.execute(f"SELECT * FROM `project_payroll` WHERE `project_id`={Ui_DTR.projectid} AND `employee_id`={Ui_DTR.currentEmployee}")
res4 = cursor.fetchall()
startDate=[]
endDate=[]
for x in res4:
startDate.append(x[3])
endDate.append(x[4])
for x in range(0,len(startDate)):
dateZ=""
dateX=""
dateY=""
TRH=0
OT=0
dateX=QDate(Ui_DTR.process_date(startDate[x]))
dateY=QDate(Ui_DTR.process_date(endDate[x]))
for y in res1:#cdtr
dateZ= QDate(Ui_DTR.process_date(y[3]))
if (dateZ>=dateX) & (dateZ<=dateY):
TRH=TRH+int(y[8])
OT=OT+int(y[9])
#update payroll week ot and rh
d1=dateX.toString("yyyy,MM,dd")
d2=dateY.toString("yyyy,MM,dd")
query2 = f"UPDATE `project_payroll` SET `TRH`={TRH},`OT`={OT} WHERE `startDate`='{d1}' AND `endDate`='{d2}' AND `employee_id`={Ui_DTR.currentEmployee} AND `project_id`={Ui_DTR.projectid}"
cursor.execute(query2)
con.commit()
#update full payroll
cursor.execute(f"SELECT * FROM `project_payroll` WHERE `project_id`={Ui_DTR.projectid} AND `employee_id`={Ui_DTR.currentEmployee}")
res = cursor.fetchall()
for x in res:
rateDay=float(x[7])*8
AmountReg=float(x[7])*float(x[8])
AmountOT=float(x[9])*float(x[7])
AmountOT= AmountOT + (float(AmountOT)*0.3)
TotalAmount = AmountReg+AmountOT+x[10]
Netpay=TotalAmount+x[12]
query2 = f"UPDATE `project_payroll` SET `rateDay`={rateDay}, `AmountReg`={AmountReg}, `AmountOT`={AmountOT}, `TotalAmount`={TotalAmount}, `Netpay`={Netpay} WHERE `id`={x[0]}"
cursor.execute(query2)
con.commit()
Ui_DTR.insert_data(False)
Ui_DTR.BtnEdit.show()
Ui_DTR.BtnCancel.hide()
Ui_DTR.BtnSave.hide()
Ui_DTR.BtnPrint.show()
Ui_DTR.BtnPrev.show()
Ui_DTR.BtnNext.show()
Ui_DTR.DTRWeekList.setEnabled(True)
BtnBack.show()
Ui_DTR.ProjectTab.setEnabled(True)
Dialog.msg_dialog("DTR has been updated")
Ui_Activity.record_activity("admin",f"Update Daily Time Record of {Ui_DTR.LEName.text()}")
else:
row_invalid = row_invalid.replace(",","",1)
Dialog.msg_dialog(f"DTR Update Unsuccessful \u2794 Invalid Input at Row(s) {row_invalid.strip()}")
def getEmployees():
Ui_DTR.resetData()
cursor = con.cursor()
Ui_DTR.employee_id=[]
cursor.execute(f"SELECT * FROM `projecte` WHERE `project_id` = {Ui_DTR.projectid}")
res = cursor.fetchall()
for x in res:
Ui_DTR.employee_id.append(x[2])
#set total page
Ui_DTR.Total_page=len(Ui_DTR.employee_id)
def getdtrinfo(item):
# Insert Data in the table
Ui_DTR.weekvalue=item.value
Ui_DTR.LBDateDTR.setText(Ui_DTR.week_list2[Ui_DTR.weekvalue])
Ui_DTR.LBPageCount.setText(f"1 out of {Ui_DTR.Total_page}")
if len(Ui_DTR.employee_id)>0:
Ui_DTR.BtnPrev.setEnabled(True)
Ui_DTR.BtnNext.setEnabled(True)
Ui_DTR.page_num = 1
Ui_DTR.BtnEdit.show()
Ui_DTR.BtnPrint.show()
Ui_DTR.insert_data(False)
def produce_table():
#Sample
#Ui_DTR.Employees = ['haha','s Ong','g Ong','Francis g']
#Ui_DTR.Total_page = len(Ui_DTR.Employees)
# Produce Table DTR (Null By Default - For Initial Display Only)
# May vary in Employee List
for x in Ui_DTR.Employees:
# Table
Ui_DTR.Table(Ui_DTR.Employees.index(x))
Ui_DTR.Total_page = Ui_DTR.Total_page + 1
def Next():
# MaxPages Limit
if Ui_DTR.page_num < Ui_DTR.Total_page:
Ui_DTR.page_num=Ui_DTR.page_num+1
Ui_DTR.LBPageCount.setText(f"{Ui_DTR.page_num} out of {Ui_DTR.Total_page}")
Ui_DTR.insert_data(False)
def Prev():
# Page 1 Limit
if Ui_DTR.page_num > 1:
Ui_DTR.page_num=Ui_DTR.page_num-1
Ui_DTR.LBPageCount.setText(f"{Ui_DTR.page_num} out of {Ui_DTR.Total_page}")
Ui_DTR.insert_data(False)
def process_date(bday):
index = 0
start = 0
flag1 = True
flag2 = False
flag3 = False
while index < len(bday):
if flag1 and (bday[index] == ","):
year = bday[start:index]
start = index + 1
flag1 = False
flag2 = True
elif flag2 and (bday[index] == ","):
month = bday[start:index]
start = index + 1
flag2 = False
flag3 = True
if flag3:
day = bday[start:len(bday)]
break
index = index + 1
return QDate(int(year), int(month), int(day))
def process_date2(bday):
index = 0
start = 0
flag1 = True
flag2 = False
flag3 = False
while index < len(bday):
if flag1 and (bday[index] == "/"):
year = bday[start:index]
start = index + 1
flag1 = False
flag2 = True
elif flag2 and (bday[index] == "/"):
month = bday[start:index]
start = index + 1
flag2 = False
flag3 = True
if flag3:
day = bday[start:len(bday)]
break
index = index + 1
return QDate(int(day), int(year), int(month))
def insert_week():
Ui_DTR.getEmployees()
Ui_DTR.week_list = []
Ui_DTR.week_list2 = []
startdate=""
enddate=""
Ui_DTR.weekarray=[]
try:
cursor = con.cursor()
cursor.execute(f"SELECT * FROM `projects` WHERE `project_id`={Ui_DTR.projectid}")
res = cursor.fetchall()
for x in res:
startdate=QDate(Ui_DTR.process_date(x[4]))
enddate=QDate(Ui_DTR.process_date(x[5]))
while startdate<enddate:
array=[]
week=""
week2=""
for i in range(0,7):
array.append(startdate.toString("yyyy,MM,dd"))
if i==0:
week= week+startdate.toString("MM/dd/yyyy")
week2= week2+startdate.toString("MM/dd/yyyy")
if startdate==enddate:
week2 = week2+" - "+startdate.toString("MM/dd/yyyy")
Ui_DTR.week_list2.append(week2)
week = startdate.toString("MM/dd/yyyy")+" - "+ week
Ui_DTR.week_list.append(week)
break
if i==6:
week2 =week2 +" - "+ startdate.toString("MM/dd/yyyy")
Ui_DTR.week_list2.append(week2)
week =startdate.toString("MM/dd/yyyy") +" - "+ week
Ui_DTR.week_list.append(week)
startdate=startdate.addDays(1)
Ui_DTR.weekarray.append(array)
except:
Dialog.msg_dialog(str(sys.exc_info()))
Ui_DTR.DTRWeekList.clear()
index = 0
while index < len(Ui_DTR.week_list):
item = QtWidgets.QListWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
item.setBackground(QColor('#666666')) if (index % 2) == 0 else item.setBackground(QColor('#595959'))
item.value=index
Ui_DTR.DTRWeekList.addItem(item)
item = Ui_DTR.DTRWeekList.item(index)
item.setText(Ui_DTR.week_list[index])
index = index + 1
def insert_data(status):
cursor = con.cursor()
if len(Ui_DTR.employee_id)>0:
try:
cursor.execute(f"SELECT * FROM `employees` WHERE `id` ={Ui_DTR.employee_id[Ui_DTR.page_num-1]}")
res = cursor.fetchall()
full_name = (f"{res[0][1]}, {res[0][2]} {res[0][3]}.")
Ui_DTR.LEName.setText(full_name)
Ui_DTR.LEPostion.setText(res[0][15])
Ui_DTR.currentEmployee=Ui_DTR.employee_id[Ui_DTR.page_num-1]
cursor.execute(f"SELECT * FROM `projectdtr` WHERE `project_id` = {Ui_DTR.projectid} AND `employee_id`={Ui_DTR.employee_id[Ui_DTR.page_num-1]}")
res = cursor.fetchall()
row=2
#Font for Input
font = QtGui.QFont()
font.setFamily("Calibri")
font.setPointSize(12)
# Regex
my_regex = QtCore.QRegExp("^\\d{1,2}()?$")
#reset
for k in range(2,9):
for y in range(0,7):
SpinHour = QtWidgets.QSpinBox(Ui_DTR.TBLdtr)
SpinHour.setGeometry(QtCore.QRect(260, 260, 42, 22))
SpinHour.setFont(font)
SpinHour.setLayoutDirection(QtCore.Qt.LeftToRight)
SpinHour.setAlignment(QtCore.Qt.AlignCenter)
SpinHour.setAutoFillBackground(False)
SpinHour.setFrame(False)
SpinHour.setEnabled(status)
SpinHour.setObjectName("SpinHour")
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
item.setText("")
if (y == 1) or (y == 2):
#my_validator = QtGui.QRegExpValidator(my_regex,LEHour)
#LEHour.setValidator(my_validator)
SpinHour.setMinimum(0)
SpinHour.setMaximum(12)
Ui_DTR.TBLdtr.setCellWidget(k, y, SpinHour)
elif (y == 3) or (y == 4):
SpinHour.setMinimum(0)
SpinHour.setMaximum(5)
Ui_DTR.TBLdtr.setCellWidget(k, y, SpinHour)
elif y==6:
Ui_DTR.TBLdtr.setCellWidget(k, y, SpinHour)
else:
Ui_DTR.TBLdtr.setItem(k, y, item)
totalrh=0
totalot=0
for j in range(0,len(Ui_DTR.weekarray[Ui_DTR.weekvalue])):
for x in res:
if Ui_DTR.weekarray[Ui_DTR.weekvalue][j]==x[3]:
index = 3
cap=24
for y in range(0,7):
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
if y==0:
date=QDate(Ui_DTR.process_date(x[index]))
item.setText(date.toString("MM/dd/yyyy"))
item.setFlags(Ui_DTR.not_editable)
Ui_DTR.TBLdtr.setItem(row, y, item)
elif y==5:
item.setText(str(x[index]))
item.setFlags(Ui_DTR.not_editable)
Ui_DTR.TBLdtr.setItem(row, y, item)
cap=cap-int(x[index])
else:
if y==6:
if cap>16:
cap=16
Ui_DTR.TBLdtr.cellWidget(row, y).setMaximum(cap)
Ui_DTR.TBLdtr.cellWidget(row, y).setValue(int(x[index]))
#Ui_DTR.TBLdtr.setItem(row, y, item)
index = index + 1
totalrh=totalrh+x[8]
totalot=totalot+x[9]
row=row+1
# Remove Uneccessary Widgets
for x in range(2,9):
for y in range(0,7):
if (Ui_DTR.TBLdtr.item(x, 0).text() == ""):
Ui_DTR.TBLdtr.removeCellWidget(x,y)
trh = QtWidgets.QTableWidgetItem()
trh = Ui_DTR.TBLdtr.item(9,5)
trh.setTextAlignment(QtCore.Qt.AlignCenter)
trh.setText(str(totalrh))
tot = QtWidgets.QTableWidgetItem()
tot = Ui_DTR.TBLdtr.item(9,6)
tot.setTextAlignment(QtCore.Qt.AlignCenter)
tot.setText(str(totalot))
except mysql.connector.Error as e:
Dialog.msg_dialog(str(sys.exc_info()))
#Ui_PEForm.show_dialog(e)
def PDTR(ProjectDTR,BtnBack,ProjectTab):
#Font for Title
font = QtGui.QFont()
font.setFamily("Calibri")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
# -----------------------Project DTR Start-------------------------
# DTR Title
LBDTRTitle = QtWidgets.QLabel(ProjectDTR)
LBDTRTitle.setGeometry(QtCore.QRect(10, 10, 271, 31))
LBDTRTitle.setFont(font)
LBDTRTitle.setStyleSheet("color: rgb(255, 255, 255);")
LBDTRTitle.setAlignment(QtCore.Qt.AlignCenter)
LBDTRTitle.setObjectName("LBDTRTitle")
#Font Normal (12)
font.setPointSize(12)
# Print Button
Ui_DTR.BtnPrint = QtWidgets.QPushButton(ProjectDTR)
Ui_DTR.BtnPrint.setGeometry(QtCore.QRect(100, 370, 100, 31))
Ui_DTR.BtnPrint.setFont(font)
Ui_DTR.BtnPrint.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
Ui_DTR.BtnPrint.setStyleSheet("background-color: rgb(0, 0, 0.9);color: rgb(255, 255, 255);border-radius:5px;")
#set Icon Print BTN
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/Icons/Assets/PrintIcon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
Ui_DTR.BtnPrint.setIcon(icon)
Ui_DTR.BtnPrint.setObjectName("Ui_DTR.BtnPrint")
#DTR Scroll Area
DTRScroll = QtWidgets.QScrollArea(ProjectDTR)
DTRScroll.setEnabled(True)
DTRScroll.setGeometry(QtCore.QRect(10, 50, 281, 301))
DTRScroll.setStyleSheet("background-color: rgb(120, 120,120,.3);border-radius:8px;")
DTRScroll.setWidgetResizable(True)
DTRScroll.setObjectName("DTRScroll")
# DTR Widget > Scroll
DTRWidget = QtWidgets.QWidget()
DTRWidget.setEnabled(True)
DTRWidget.setGeometry(QtCore.QRect(0, 0, 281, 301))
DTRWidget.setObjectName("DTRWidget")
# List > DTR Widget
Ui_DTR.DTRWeekList = QtWidgets.QListWidget(DTRWidget)
Ui_DTR.DTRWeekList.setGeometry(QtCore.QRect(0, 0, 281, 301))
Ui_DTR.DTRWeekList.setLayoutDirection(QtCore.Qt.RightToLeft)
Ui_DTR.DTRWeekList.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
Ui_DTR.DTRWeekList.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
Ui_DTR.DTRWeekList.setObjectName("DTRWeekList")
Ui_DTR.DTRWeekList.setStyleSheet("background-color: rgb(167, 167, 167,.4);\n"
"border-radius:5px;\n"
"font-size:18px;\n"
"color:white;\n"
"")
#setWidget At Scroll Area
DTRScroll.setWidget(DTRWidget)
Ui_DTR.LBDateDTR = QtWidgets.QLabel(ProjectDTR)
Ui_DTR.LBDateDTR.setGeometry(QtCore.QRect(310, 10, 311, 31))
#set Font 16
font.setPointSize(16)
# DTR Title (Week)
Ui_DTR.LBDateDTR.setFont(font)
Ui_DTR.LBDateDTR.setStyleSheet("background-color: rgb(148, 0, 2,.4);border-radius:8px;color:white;")
Ui_DTR.LBDateDTR.setAlignment(QtCore.Qt.AlignCenter)
Ui_DTR.LBDateDTR.setObjectName("LBDate")
# Font set (12)
font.setPointSize(12)
# Edit Button
Ui_DTR.BtnEdit = QtWidgets.QPushButton(ProjectDTR)
Ui_DTR.BtnEdit.setGeometry(QtCore.QRect(630, 10, 100, 31))
Ui_DTR.BtnEdit.setFont(font)
Ui_DTR.BtnEdit.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
Ui_DTR.BtnEdit.setStyleSheet("background-color: rgb(0, 0, 0.9);color: rgb(255, 255, 255);border-radius:5px;")
#set icon Edit Button
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(":/Icons/Assets/EditIcon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
Ui_DTR.BtnEdit.setIcon(icon1)
Ui_DTR.BtnEdit.setObjectName("BtnEdit")
# BtnCancel
Ui_DTR.BtnCancel = QtWidgets.QPushButton(ProjectDTR)
Ui_DTR.BtnCancel.setGeometry(QtCore.QRect(630, 10, 100, 31))
Ui_DTR.BtnCancel.setFont(font)
Ui_DTR.BtnCancel.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
Ui_DTR.BtnCancel.setStyleSheet("background-color: rgb(0, 0, 0.9);color: rgb(255, 255, 255);border-radius:5px;")
#set icon Edit Button
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(":/Icons/Assets/CancelIcon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
Ui_DTR.BtnCancel.setIcon(icon1)
Ui_DTR.BtnCancel.setObjectName("BtnCancel")
Ui_DTR.BtnCancel.hide()
# BtnSave
Ui_DTR.BtnSave = QtWidgets.QPushButton(ProjectDTR)
Ui_DTR.BtnSave.setGeometry(QtCore.QRect(745, 10, 100, 31))
Ui_DTR.BtnSave.setFont(font)
Ui_DTR.BtnSave.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
Ui_DTR.BtnSave.setStyleSheet("background-color: rgb(0, 0, 0.9);color: rgb(255, 255, 255);border-radius:5px;")
#set icon Edit Button
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(":/Icons/Assets/SaveIcon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
Ui_DTR.BtnSave.setIcon(icon1)
Ui_DTR.BtnSave.setObjectName("BtnSave")
Ui_DTR.BtnSave.hide()
# DTR Page Prev Button
Ui_DTR.BtnPrev = QtWidgets.QPushButton(ProjectDTR)
Ui_DTR.BtnPrev.setGeometry(QtCore.QRect(860, 10, 31, 31))
Ui_DTR.BtnPrev.setFont(font)
Ui_DTR.BtnPrev.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
Ui_DTR.BtnPrev.setStyleSheet("background-color: rgb(148, 0, 2,.4);border-radius:8px;color:white;")
Ui_DTR.BtnPrev.setObjectName("BtnPrev")
# DTR Page Next Button
Ui_DTR.BtnNext = QtWidgets.QPushButton(ProjectDTR)
Ui_DTR.BtnNext.setGeometry(QtCore.QRect(1020, 10, 31, 31))
Ui_DTR.BtnNext.setFont(font)
Ui_DTR.BtnNext.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
Ui_DTR.BtnNext.setStyleSheet("background-color: rgb(148, 0, 2,.4);border-radius:8px;color:white;")
Ui_DTR.BtnNext.setObjectName("BtnNext")
# Page Count ( 1 out of 1 )
Ui_DTR.LBPageCount = QtWidgets.QLabel(ProjectDTR)
Ui_DTR.LBPageCount.setGeometry(QtCore.QRect(900, 10, 111, 31))
Ui_DTR.LBPageCount.setFont(font)
Ui_DTR.LBPageCount.setStyleSheet("background-color: rgb(148, 0, 2,.4);border-radius:8px;color:white;")
Ui_DTR.LBPageCount.setAlignment(QtCore.Qt.AlignCenter)
Ui_DTR.LBPageCount.setObjectName("LBPageCount")
# Stack DTR Pages
Ui_DTR.DTRStack = QtWidgets.QStackedWidget(ProjectDTR)
Ui_DTR.DTRStack.setGeometry(QtCore.QRect(310, 50, 741, 371))
Ui_DTR.DTRStack.setObjectName("DTRStack")
_translate = QtCore.QCoreApplication.translate
LBDTRTitle.setText(_translate("DashbaordWindow", "Daily Time Record"))
Ui_DTR.BtnPrint.setText(_translate("DashbaordWindow", " Print"))
__sortingEnabled = Ui_DTR.DTRWeekList.isSortingEnabled()
Ui_DTR.DTRWeekList.setSortingEnabled(False)
Ui_DTR.DTRWeekList.setSortingEnabled(__sortingEnabled)
Ui_DTR.BtnEdit.setText(_translate("DashbaordWindow", "Edit"))
Ui_DTR.BtnCancel.setText(_translate("DashbaordWindow", "Cancel"))
Ui_DTR.BtnSave.setText(_translate("DashbaordWindow", "Save"))
Ui_DTR.BtnPrev.setText(_translate("DashbaordWindow", "<"))
Ui_DTR.BtnNext.setText(_translate("DashbaordWindow", ">"))
Ui_DTR.LBPageCount.setText(_translate("DashbaordWindow", (f"1 out of {Ui_DTR.Total_page}")))
#Product Table (Null By Default)
Ui_DTR.produce_table()
# Next Button Change
Ui_DTR.BtnNext.clicked.connect(Ui_DTR.Next)
# Prev Button Change
Ui_DTR.BtnPrev.clicked.connect(Ui_DTR.Prev)
#edit Btn
Ui_DTR.BtnEdit.clicked.connect(lambda: Ui_DTR.editDTR(BtnBack))
#cancel Btn
Ui_DTR.BtnCancel.clicked.connect(lambda: Ui_DTR.cancelEdit(BtnBack))
#save Btn
Ui_DTR.BtnSave.clicked.connect(lambda: Ui_DTR.saveEdit(BtnBack))
#print btn
Ui_DTR.BtnPrint.clicked.connect(lambda: Ui_DTR.printDTR())
Ui_DTR.BtnPrint.hide()
# selection function
Ui_DTR.DTRWeekList.itemClicked.connect(Ui_DTR.getdtrinfo)
Ui_DTR.LEName.setEnabled(False)
Ui_DTR.LEPostion.setEnabled(False)
Ui_DTR.BtnEdit.hide()
Ui_DTR.BtnBack=BtnBack
Ui_DTR.ProjectTab=ProjectTab
def Table(page):
#DTR Page Widget
DTRPage = QtWidgets.QWidget()
DTRPage.setObjectName("DTRPage")
#BG DTR
BgDTR = QtWidgets.QLabel(DTRPage)
BgDTR.setGeometry(QtCore.QRect(0, 0, 741, 371))
BgDTR.setStyleSheet("background-color: rgb(148, 0, 2,.4);border-radius:8px;")
BgDTR.setText("")
BgDTR.setObjectName("BGDTR")
#DTR Group
DTRGroup = QtWidgets.QGroupBox(DTRPage)
DTRGroup.setGeometry(QtCore.QRect(10, 10, 721, 345))
DTRGroup.setStyleSheet("border:none;border-radius:8px;color:white;")
DTRGroup.setTitle("")
DTRGroup.setObjectName("DTRGroup")
# BG2 DTR
BgDTR_2 = QtWidgets.QLabel(DTRGroup)
BgDTR_2.setGeometry(QtCore.QRect(0, 0, 721, 345))
BgDTR_2.setStyleSheet("background-color:rgba(40,0,0,.5);")
BgDTR_2.setText("")
BgDTR_2.setAlignment(QtCore.Qt.AlignCenter)
BgDTR_2.setObjectName("BGDTR_2")
#FOnt Properties
font = QtGui.QFont()
font.setFamily("Calibri")
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
#Label Employee Name
LBName = QtWidgets.QLabel(DTRGroup)
LBName.setGeometry(QtCore.QRect(10, 13, 71, 11))
LBName.setFont(font)
LBName.setObjectName("LBName")
#Input Employee Name
font.setBold(False)
Ui_DTR.LEName = QtWidgets.QLineEdit(DTRGroup)
Ui_DTR.LEName.setGeometry(QtCore.QRect(90, 12, 321, 18))
Ui_DTR.LEName.setFont(font)
Ui_DTR.LEName.setObjectName("LEName")
#DTR Table
Ui_DTR.TBLdtr = QtWidgets.QTableWidget(DTRGroup)
Ui_DTR.TBLdtr.setGeometry(QtCore.QRect(10, 40, 701, 295))
Ui_DTR.TBLdtr.setFont(font)
Ui_DTR.TBLdtr.setStyleSheet("QTableWidget::item{border:1px solid white;}QTableWidget{border:1px solid white;}")
Ui_DTR.TBLdtr.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
Ui_DTR.TBLdtr.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
Ui_DTR.TBLdtr.setShowGrid(True)
Ui_DTR.TBLdtr.setWordWrap(True)
Ui_DTR.TBLdtr.setCornerButtonEnabled(True)
Ui_DTR.TBLdtr.setColumnCount(7)
Ui_DTR.TBLdtr.setObjectName("TBLdtr")
Ui_DTR.TBLdtr.setRowCount(10)
_translate = QtCore.QCoreApplication.translate
# Vertical Header Add item (Hidden)
for x in range(0,10):
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
Ui_DTR.TBLdtr.setVerticalHeaderItem(x, item)
# Horizontal Header Add item (Hidden)
for x in range(0,7):
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
Ui_DTR.TBLdtr.setHorizontalHeaderItem(x, item)
# Font for Headers
font.setBold(True)
# "Date" Header (Seperate for Rowspan)
item = QtWidgets.QTableWidgetItem()
item.setFont(font)
item.setTextAlignment(QtCore.Qt.AlignCenter)
# Header 1st Row
for x in range(0,7):
item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
Ui_DTR.TBLdtr.setItem(0, x, item)
item = QtWidgets.QTableWidgetItem()
item.setFont(font)
item.setTextAlignment(QtCore.Qt.AlignCenter)
# Header 2nd Row
for x in range(0,7):
item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
Ui_DTR.TBLdtr.setItem(1, x, item)
item = QtWidgets.QTableWidgetItem()
item.setFont(font)
item.setTextAlignment(QtCore.Qt.AlignCenter)
# Dates
for x in range(2,10):
item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
Ui_DTR.TBLdtr.setItem(x, 0, item)
item = QtWidgets.QTableWidgetItem()
item.setFont(font)
item.setTextAlignment(QtCore.Qt.AlignCenter)
# Set Row-Col Span
Ui_DTR.TBLdtr.setSpan(0,0,2,1)
Ui_DTR.TBLdtr.setSpan(0,1,1,2)
Ui_DTR.TBLdtr.setSpan(0,3,1,2)
Ui_DTR.TBLdtr.setSpan(0,5,1,2)
Ui_DTR.TBLdtr.setSpan(9,0,1,5)
# disable editable cells
for i in range(2,10):
index = 0
for x in range(1,7):