-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive_dtr.py
1420 lines (1096 loc) · 42.6 KB
/
archive_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
class Ui_DTRA(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
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_DTRA.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_DTRA.page_num=0
while Ui_DTRA.page_num<Ui_DTRA.Total_page:
Ui_DTRA.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_DTRA.TBLdtr.rowCount()):
record = []
for col in range(Ui_DTRA.TBLdtr.columnCount()):
if (row>=2) & (row<=8):
if ((col>=1) & (col<=4))| (col==6):
val = Ui_DTRA.TBLdtr.item(row, col).text()
record.append(val)
else:
date = Ui_DTRA.TBLdtr.item(row, col).text()
record.append(date)
else:
record.append(Ui_DTRA.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_DTRA.LEName.text()}"
ws.cells(2+added, 3).value = f": {Ui_DTRA.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_DTRA.week_list2[index]}"
added=added+16
index=index+1
def resetData():
#reset
Ui_DTRA.LBPageCount.setText(f"1 out of {1}")
Ui_DTRA.LEName.setText("")
Ui_DTRA.LEPostion.setText("")
Ui_DTRA.page_num = 1
Ui_DTRA.LBDateDTR.setText(Ui_DTRA.Date_title)
Ui_DTRA.BtnPrev.setEnabled(False)
Ui_DTRA.BtnNext.setEnabled(False)
Ui_DTRA.DTRWeekList.setEnabled(True)
Ui_DTRA.BtnBack.show()
Ui_DTRA.BtnPrint.hide()
#reset
for k in range(2,9):
for y in range(0,7):
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
item.setText("")
item.setFlags(Ui_DTRA.not_editable) #Disable item edit
Ui_DTRA.TBLdtr.setItem(k, y, item)
trh = QtWidgets.QTableWidgetItem()
trh = Ui_DTRA.TBLdtr.item(9,5)
trh.setTextAlignment(QtCore.Qt.AlignCenter)
trh.setText("")
tot = QtWidgets.QTableWidgetItem()
tot = Ui_DTRA.TBLdtr.item(9,6)
tot.setTextAlignment(QtCore.Qt.AlignCenter)
tot.setText("")
def editDTR(BtnBack):
Ui_DTRA.insert_data(Ui_DTRA.editable)
Ui_DTRA.BtnPrint.hide()
Ui_DTRA.BtnPrev.hide()
Ui_DTRA.BtnNext.hide()
BtnBack.hide()
Ui_DTRA.ProjectTab.setEnabled(False)
Ui_DTRA.DTRWeekList.setEnabled(False)
def cancelEdit(BtnBack):
if (Dialog.confirm_dialog("Are you sure you want to discard changes?") == QMessageBox.Ok):
Ui_DTRA.insert_data(Ui_DTRA.not_editable)
Ui_DTRA.BtnPrint.show()
Ui_DTRA.BtnPrev.show()
Ui_DTRA.BtnNext.show()
BtnBack.show()
Ui_DTRA.DTRWeekList.setEnabled(True)
Ui_DTRA.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
#computation
for k in range(2,9):
date = Ui_DTRA.TBLdtr.item(k,0).text()
if len(date)>0:
date=QDate(Ui_DTRA.process_date2(date))
date = date.toString("yyyy,MM,dd")
in_AM = Ui_DTRA.TBLdtr.item(k,1).text()
out_AM = Ui_DTRA.TBLdtr.item(k,2).text()
in_PM = Ui_DTRA.TBLdtr.item(k,3).text()
out_PM = Ui_DTRA.TBLdtr.item(k,4).text()
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_DTRA.TBLdtr.item(k,5)
rh.setTextAlignment(QtCore.Qt.AlignCenter)
rh.setText(str(total))
ot = Ui_DTRA.TBLdtr.item(k,6).text()
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_DTRA.currentEmployee} AND `project_id`={Ui_DTRA.projectid}"
cursor.execute(query2)
con.commit()
except :
Dialog.msg_dialog(str(sys.exc_info()))
trh = QtWidgets.QTableWidgetItem()
trh = Ui_DTRA.TBLdtr.item(9,5)
trh.setTextAlignment(QtCore.Qt.AlignCenter)
trh.setText(str(totalrh))
tot = QtWidgets.QTableWidgetItem()
tot = Ui_DTRA.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_DTRA.projectid} AND `employee_id`={Ui_DTRA.currentEmployee}")
res1 = cursor.fetchall()
cursor.execute(f"SELECT * FROM `project_payroll` WHERE `project_id`={Ui_DTRA.projectid} AND `employee_id`={Ui_DTRA.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_DTRA.process_date(startDate[x]))
dateY=QDate(Ui_DTRA.process_date(endDate[x]))
for y in res1:#cdtr
dateZ= QDate(Ui_DTRA.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_DTRA.currentEmployee} AND `project_id`={Ui_DTRA.projectid}"
cursor.execute(query2)
con.commit()
#update full payroll
cursor.execute(f"SELECT * FROM `project_payroll` WHERE `project_id`={Ui_DTRA.projectid} AND `employee_id`={Ui_DTRA.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_DTRA.insert_data(Ui_DTRA.not_editable)
Ui_DTRA.BtnPrint.show()
Ui_DTRA.BtnPrev.show()
Ui_DTRA.BtnNext.show()
Ui_DTRA.DTRWeekList.setEnabled(True)
BtnBack.show()
Ui_DTRA.ProjectTab.setEnabled(True)
Dialog.msg_dialog("DTR has been updated")
def getEmployees():
Ui_DTRA.resetData()
cursor = con.cursor()
Ui_DTRA.employee_id=[]
cursor.execute(f"SELECT * FROM `projecte` WHERE `project_id` = {Ui_DTRA.projectid}")
res = cursor.fetchall()
for x in res:
Ui_DTRA.employee_id.append(x[2])
#set total page
Ui_DTRA.Total_page=len(Ui_DTRA.employee_id)
def getdtrinfo(item):
# Insert Data in the table
Ui_DTRA.weekvalue=item.value
Ui_DTRA.LBDateDTR.setText(Ui_DTRA.week_list2[Ui_DTRA.weekvalue])
Ui_DTRA.LBPageCount.setText(f"1 out of {Ui_DTRA.Total_page}")
if len(Ui_DTRA.employee_id)>0:
Ui_DTRA.BtnPrev.setEnabled(True)
Ui_DTRA.BtnNext.setEnabled(True)
Ui_DTRA.BtnPrint.show()
Ui_DTRA.page_num = 1
Ui_DTRA.insert_data(Ui_DTRA.not_editable)
def produce_table():
#Sample
#Ui_DTRA.Employees = ['haha','s Ong','g Ong','Francis g']
#Ui_DTRA.Total_page = len(Ui_DTRA.Employees)
# Produce Table DTR (Null By Default - For Initial Display Only)
# May vary in Employee List
for x in Ui_DTRA.Employees:
# Table
Ui_DTRA.Table(Ui_DTRA.Employees.index(x))
Ui_DTRA.Total_page = Ui_DTRA.Total_page + 1
def Next():
# MaxPages Limit
if Ui_DTRA.page_num < Ui_DTRA.Total_page:
Ui_DTRA.page_num=Ui_DTRA.page_num+1
Ui_DTRA.LBPageCount.setText(f"{Ui_DTRA.page_num} out of {Ui_DTRA.Total_page}")
Ui_DTRA.insert_data(Ui_DTRA.not_editable)
def Prev():
# Page 1 Limit
if Ui_DTRA.page_num > 1:
Ui_DTRA.page_num=Ui_DTRA.page_num-1
Ui_DTRA.LBPageCount.setText(f"{Ui_DTRA.page_num} out of {Ui_DTRA.Total_page}")
Ui_DTRA.insert_data(Ui_DTRA.not_editable)
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_DTRA.getEmployees()
Ui_DTRA.week_list = []
Ui_DTRA.week_list2 = []
startdate=""
enddate=""
Ui_DTRA.weekarray=[]
try:
cursor = con.cursor()
cursor.execute(f"SELECT * FROM `projects` WHERE `project_id`={Ui_DTRA.projectid}")
res = cursor.fetchall()
for x in res:
startdate=QDate(Ui_DTRA.process_date(x[4]))
enddate=QDate(Ui_DTRA.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_DTRA.week_list2.append(week2)
week = startdate.toString("MM/dd/yyyy")+" - "+ week
Ui_DTRA.week_list.append(week)
break
if i==6:
week2 =week2 +" - "+ startdate.toString("MM/dd/yyyy")
Ui_DTRA.week_list2.append(week2)
week =startdate.toString("MM/dd/yyyy") +" - "+ week
Ui_DTRA.week_list.append(week)
startdate=startdate.addDays(1)
Ui_DTRA.weekarray.append(array)
except:
Dialog.msg_dialog(str(sys.exc_info()))
Ui_DTRA.DTRWeekList.clear()
index = 0
while index < len(Ui_DTRA.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_DTRA.DTRWeekList.addItem(item)
item = Ui_DTRA.DTRWeekList.item(index)
item.setText(Ui_DTRA.week_list[index])
index = index + 1
def insert_data(status):
cursor = con.cursor()
if len(Ui_DTRA.employee_id)>0:
try:
cursor.execute(f"SELECT * FROM `employees` WHERE `id` ={Ui_DTRA.employee_id[Ui_DTRA.page_num-1]}")
res = cursor.fetchall()
full_name = (f"{res[0][1]}, {res[0][2]} {res[0][3]}.")
Ui_DTRA.LEName.setText(full_name)
Ui_DTRA.LEPostion.setText(res[0][15])
Ui_DTRA.currentEmployee=Ui_DTRA.employee_id[Ui_DTRA.page_num-1]
cursor.execute(f"SELECT * FROM `projectdtr` WHERE `project_id` = {Ui_DTRA.projectid} AND `employee_id`={Ui_DTRA.employee_id[Ui_DTRA.page_num-1]}")
res = cursor.fetchall()
row=2
#reset
for k in range(2,9):
for y in range(0,7):
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
item.setText("")
item.setFlags(status)
Ui_DTRA.TBLdtr.setItem(k, y, item)
totalrh=0
totalot=0
for j in range(0,len(Ui_DTRA.weekarray[Ui_DTRA.weekvalue])):
for x in res:
if Ui_DTRA.weekarray[Ui_DTRA.weekvalue][j]==x[3]:
index = 3
for y in range(0,7):
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
if y==0:
date=QDate(Ui_DTRA.process_date(x[index]))
item.setText(date.toString("MM/dd/yyyy"))
item.setFlags(Ui_DTRA.not_editable)
elif y==5:
item.setText(str(x[index]))
item.setFlags(Ui_DTRA.not_editable)
else:
item.setText(str(x[index]))
item.setFlags(status)
Ui_DTRA.TBLdtr.setItem(row, y, item)
index = index + 1
totalrh=totalrh+x[8]
totalot=totalot+x[9]
row=row+1
trh = QtWidgets.QTableWidgetItem()
trh = Ui_DTRA.TBLdtr.item(9,5)
trh.setTextAlignment(QtCore.Qt.AlignCenter)
trh.setText(str(totalrh))
tot = QtWidgets.QTableWidgetItem()
tot = Ui_DTRA.TBLdtr.item(9,6)
tot.setTextAlignment(QtCore.Qt.AlignCenter)
tot.setText(str(totalot))
except mysql.connector.Error as e:
print(e)
#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_DTRA.BtnPrint = QtWidgets.QPushButton(ProjectDTR)
Ui_DTRA.BtnPrint.setGeometry(QtCore.QRect(100, 370, 100, 31))
Ui_DTRA.BtnPrint.setFont(font)
Ui_DTRA.BtnPrint.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
Ui_DTRA.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_DTRA.BtnPrint.setIcon(icon)
Ui_DTRA.BtnPrint.setObjectName("Ui_DTRA.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_DTRA.DTRWeekList = QtWidgets.QListWidget(DTRWidget)
Ui_DTRA.DTRWeekList.setGeometry(QtCore.QRect(0, 0, 281, 301))
Ui_DTRA.DTRWeekList.setLayoutDirection(QtCore.Qt.RightToLeft)
Ui_DTRA.DTRWeekList.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
Ui_DTRA.DTRWeekList.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
Ui_DTRA.DTRWeekList.setObjectName("DTRWeekList")
Ui_DTRA.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_DTRA.LBDateDTR = QtWidgets.QLabel(ProjectDTR)
Ui_DTRA.LBDateDTR.setGeometry(QtCore.QRect(310, 10, 311, 31))
#set Font 16
font.setPointSize(16)
# DTR Title (Week)
Ui_DTRA.LBDateDTR.setFont(font)
Ui_DTRA.LBDateDTR.setStyleSheet("background-color: rgb(148, 0, 2,.4);border-radius:8px;color:white;")
Ui_DTRA.LBDateDTR.setAlignment(QtCore.Qt.AlignCenter)
Ui_DTRA.LBDateDTR.setObjectName("LBDate")
# Font set (12)
font.setPointSize(12)
# DTR Page Prev Button
Ui_DTRA.BtnPrev = QtWidgets.QPushButton(ProjectDTR)
Ui_DTRA.BtnPrev.setGeometry(QtCore.QRect(860, 10, 31, 31))
Ui_DTRA.BtnPrev.setFont(font)
Ui_DTRA.BtnPrev.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
Ui_DTRA.BtnPrev.setStyleSheet("background-color: rgb(148, 0, 2,.4);border-radius:8px;color:white;")
Ui_DTRA.BtnPrev.setObjectName("BtnPrev")
# DTR Page Next Button
Ui_DTRA.BtnNext = QtWidgets.QPushButton(ProjectDTR)
Ui_DTRA.BtnNext.setGeometry(QtCore.QRect(1020, 10, 31, 31))
Ui_DTRA.BtnNext.setFont(font)
Ui_DTRA.BtnNext.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
Ui_DTRA.BtnNext.setStyleSheet("background-color: rgb(148, 0, 2,.4);border-radius:8px;color:white;")
Ui_DTRA.BtnNext.setObjectName("BtnNext")
# Page Count ( 1 out of 1 )
Ui_DTRA.LBPageCount = QtWidgets.QLabel(ProjectDTR)
Ui_DTRA.LBPageCount.setGeometry(QtCore.QRect(900, 10, 111, 31))
Ui_DTRA.LBPageCount.setFont(font)
Ui_DTRA.LBPageCount.setStyleSheet("background-color: rgb(148, 0, 2,.4);border-radius:8px;color:white;")
Ui_DTRA.LBPageCount.setAlignment(QtCore.Qt.AlignCenter)
Ui_DTRA.LBPageCount.setObjectName("LBPageCount")
# Stack DTR Pages
Ui_DTRA.DTRStack = QtWidgets.QStackedWidget(ProjectDTR)
Ui_DTRA.DTRStack.setGeometry(QtCore.QRect(310, 50, 741, 371))
Ui_DTRA.DTRStack.setObjectName("DTRStack")
_translate = QtCore.QCoreApplication.translate
LBDTRTitle.setText(_translate("DashbaordWindow", "Daily Time Record"))
Ui_DTRA.BtnPrint.setText(_translate("DashbaordWindow", " Print"))
__sortingEnabled = Ui_DTRA.DTRWeekList.isSortingEnabled()
Ui_DTRA.DTRWeekList.setSortingEnabled(False)
Ui_DTRA.DTRWeekList.setSortingEnabled(__sortingEnabled)
Ui_DTRA.BtnPrev.setText(_translate("DashbaordWindow", "<"))
Ui_DTRA.BtnNext.setText(_translate("DashbaordWindow", ">"))
Ui_DTRA.LBPageCount.setText(_translate("DashbaordWindow", (f"1 out of {Ui_DTRA.Total_page}")))
#Product Table (Null By Default)
Ui_DTRA.produce_table()
# Next Button Change
Ui_DTRA.BtnNext.clicked.connect(Ui_DTRA.Next)
# Prev Button Change
Ui_DTRA.BtnPrev.clicked.connect(Ui_DTRA.Prev)
#print btn
Ui_DTRA.BtnPrint.clicked.connect(lambda: Ui_DTRA.printDTR())
Ui_DTRA.BtnPrint.hide()
# selection function
Ui_DTRA.DTRWeekList.itemClicked.connect(Ui_DTRA.getdtrinfo)
Ui_DTRA.LEName.setEnabled(False)
Ui_DTRA.LEPostion.setEnabled(False)
Ui_DTRA.BtnBack=BtnBack
Ui_DTRA.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_DTRA.LEName = QtWidgets.QLineEdit(DTRGroup)
Ui_DTRA.LEName.setGeometry(QtCore.QRect(90, 12, 321, 18))
Ui_DTRA.LEName.setFont(font)
Ui_DTRA.LEName.setObjectName("LEName")
#DTR Table
Ui_DTRA.TBLdtr = QtWidgets.QTableWidget(DTRGroup)
Ui_DTRA.TBLdtr.setGeometry(QtCore.QRect(10, 40, 701, 295))
Ui_DTRA.TBLdtr.setFont(font)
Ui_DTRA.TBLdtr.setStyleSheet("QTableWidget::item{border:1px solid white;}QTableWidget{border:1px solid white;}")
Ui_DTRA.TBLdtr.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
Ui_DTRA.TBLdtr.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
Ui_DTRA.TBLdtr.setShowGrid(True)
Ui_DTRA.TBLdtr.setWordWrap(True)
Ui_DTRA.TBLdtr.setCornerButtonEnabled(True)
Ui_DTRA.TBLdtr.setColumnCount(7)
Ui_DTRA.TBLdtr.setObjectName("TBLdtr")
Ui_DTRA.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_DTRA.TBLdtr.setVerticalHeaderItem(x, item)
# Horizontal Header Add item (Hidden)
for x in range(0,7):
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
Ui_DTRA.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_DTRA.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_DTRA.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_DTRA.TBLdtr.setItem(x, 0, item)
item = QtWidgets.QTableWidgetItem()
item.setFont(font)
item.setTextAlignment(QtCore.Qt.AlignCenter)
# Set Row-Col Span
Ui_DTRA.TBLdtr.setSpan(0,0,2,1)
Ui_DTRA.TBLdtr.setSpan(0,1,1,2)
Ui_DTRA.TBLdtr.setSpan(0,3,1,2)
Ui_DTRA.TBLdtr.setSpan(0,5,1,2)
Ui_DTRA.TBLdtr.setSpan(9,0,1,5)
# disable editable cells
for i in range(2,10):
index = 0
for x in range(1,7):
item = QtWidgets.QTableWidgetItem()
item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) #Disable item edit
Ui_DTRA.TBLdtr.setItem(i, x, item)
index = index + 1
# Table Attributes
Ui_DTRA.TBLdtr.horizontalHeader().setVisible(False)
Ui_DTRA.TBLdtr.horizontalHeader().setCascadingSectionResizes(False)
Ui_DTRA.TBLdtr.horizontalHeader().setDefaultSectionSize(100)
Ui_DTRA.TBLdtr.horizontalHeader().setHighlightSections(False)
Ui_DTRA.TBLdtr.horizontalHeader().setSortIndicatorShown(False)
Ui_DTRA.TBLdtr.horizontalHeader().setStretchLastSection(True)
Ui_DTRA.TBLdtr.verticalHeader().setVisible(False)
Ui_DTRA.TBLdtr.verticalHeader().setCascadingSectionResizes(False)
Ui_DTRA.TBLdtr.verticalHeader().setHighlightSections(False)
Ui_DTRA.TBLdtr.verticalHeader().setSortIndicatorShown(False)
Ui_DTRA.TBLdtr.verticalHeader().setStretchLastSection(False)
# Label Position
font.setBold(True)
LBPostion = QtWidgets.QLabel(DTRGroup)
LBPostion.setGeometry(QtCore.QRect(420, 13, 71, 11))
LBPostion.setFont(font)
LBPostion.setObjectName("LBPostion")
# Input Position
font.setBold(False)
font.setWeight(50)
Ui_DTRA.LEPostion = QtWidgets.QLineEdit(DTRGroup)
Ui_DTRA.LEPostion.setGeometry(QtCore.QRect(500, 12, 321, 18))
Ui_DTRA.LEPostion.setFont(font)
Ui_DTRA.LEPostion.setObjectName("LEPostion")
# Set Name
Ui_DTRA.LEName.setText(Ui_DTRA.Employees[page])
# Add to List
Ui_DTRA.DTR_Pages.append(DTRPage)
# Add to Stack
Ui_DTRA.DTRStack.addWidget(Ui_DTRA.DTR_Pages[page])
# Set Text Vertical Header
index = 0
vheader= ['1','2','3','4','5','6','7','8','9','10']
for x in vheader:
item = Ui_DTRA.TBLdtr.verticalHeaderItem(0)
item.setText(_translate("DashbaordWindow", x))
index = index + 1
# Set Text Horizontal Header First Row
index = 0
hheader = ['Date','Time In','Time Out','Time In','Time Out','Reg Hrs.','Overtime',]
for x in hheader:
item = Ui_DTRA.TBLdtr.horizontalHeaderItem(0)
item.setText(_translate("DashbaordWindow", x))
index = index + 1
# Set Text @ Span (Row & Column)
span_col = [0,1,3,5]
hheader_span = ['Date','AM','PM','TOTAL HOURS']
index = 0
while index < len(span_col):
item = Ui_DTRA.TBLdtr.item(0, span_col[index])
item.setText(_translate("DashbaordWindow", hheader_span[index]))
index = index + 1
# Set Text Horizontal Header Second Row
index = 1 # Header Start @ 1 in Second Row
hheader2 = ['Time In','Time Out','Time In','Time Out','Reg Hrs.','Overtime']
for x in hheader2:
item = Ui_DTRA.TBLdtr.item(1, index)
item.setText(_translate("DashbaordWindow", x))
index = index + 1
# Dates
index = 0
for x in range(2,9):
item = Ui_DTRA.TBLdtr.item(x, 0)
item.setText(_translate("DashbaordWindow", Ui_DTRA.Dates[index]))
index = index + 1
item = Ui_DTRA.TBLdtr.item(9, 0)
Ui_DTRA.LBDateDTR.setText(_translate("DashbaordWindow", Ui_DTRA.Date_title))
# Footer
item.setText(_translate("DashbaordWindow", "Total Hours"))
#Set Text Defaults
LBName.setText(_translate("DashbaordWindow", "Name :"))
Ui_DTRA.LEName.setPlaceholderText(_translate("DashbaordWindow", "Employee Name"))
Ui_DTRA.TBLdtr.setSortingEnabled(False)
LBPostion.setText(_translate("DashbaordWindow", "Position :"))
Ui_DTRA.LEPostion.setPlaceholderText(_translate("DashbaordWindow", "Employee Position"))
class Ui_Payroll(object):
TBLPayroll = "" # Table Payroll
PDList = "" # Payroll Date List
#Employee Sample List (Default Null)
Employees = 9 # List of Employees in Specific Project Default 9 Rows For Initial Display
LBDate = "" # Payroll Date Title (Week)
week_title = "Week Title" # Week Title Default
weekstart=[]
weekvalue=0
def printPayroll():
cursor = con.cursor()
cursor.execute(f"SELECT * FROM `projects` WHERE `project_id` = {Ui_DTRA.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 = 'Payroll'
rows = []
columnHeaders = ["","","","","","","","","","","","","","",""]
count=1
maxRow=Ui_Payroll.TBLPayroll.rowCount()+5