-
Notifications
You must be signed in to change notification settings - Fork 0
/
summary.py
292 lines (227 loc) · 12.1 KB
/
summary.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
from tkinter import *
import datetime
import calendar
import tkinter.messagebox
# Summary of hours
class Summary(ttk.LabelFrame):
def __init__(self, parent, controller, *args, **kwargs):
ttk.LabelFrame.__init__(self, parent, *args, **kwargs)
self.controller = controller
for i in range(3):
self.grid_rowconfigure(i, weight = 1)
self.grid_columnconfigure(0, weight = 1)
# Top frame
self.top_frame = ttk.LabelFrame(self, borderwidth=2, relief = RIDGE, text="Harmonogram a wykonanie", labelanchor='nw')
for i in range(3):
self.top_frame.grid_rowconfigure(i, weight = 1)
for i in range(3):
self.top_frame.grid_columnconfigure(i, weight = 1)
self.s_hours_s = StringVar()
self.s_days_s = StringVar()
self.w_hours_s = StringVar()
self.w_days_s = StringVar()
self.s_hours = ttk.Entry(self.top_frame, textvariable = self.s_hours_s, justify = "center", width = 10)
self.s_days = ttk.Entry(self.top_frame, textvariable = self.s_days_s, justify = "center", width = 10)
self.w_hours = ttk.Entry(self.top_frame, textvariable = self.w_hours_s, justify = "center", width = 10)
self.w_days = ttk.Entry(self.top_frame, textvariable = self.w_days_s, justify = "center", width = 10)
self.days_label = ttk.Label(self.top_frame, text="Dni")
self.hours_label = ttk.Label(self.top_frame, text="Godz")
self.s_label = ttk.Label(self.top_frame, text="Harmonogram")
self.w_label = ttk.Label(self.top_frame, text="Wykonanie")
self.days_label.grid(row = 1, column = 0)
self.hours_label.grid(row = 2, column = 0)
self.s_label.grid(row = 0, column = 1)
self.w_label.grid(row = 0, column = 2)
self.s_days.grid(row = 1, column = 1, padx = 10)
self.s_hours.grid(row = 2, column = 1, padx = 10)
self.w_hours.grid(row = 2, column = 2, padx = 10)
self.w_days.grid(row = 1, column = 2, padx = 10)
self.top_frame.grid(row=0, sticky = NSEW)
# Middle Frame
self.mid_frame = ttk.LabelFrame(self, borderwidth = 2, relief = RIDGE, text = "Podsumowanie")
for i in range(9):
self.mid_frame.grid_rowconfigure(i, weight = 1)
for i in range(3):
self.mid_frame.grid_columnconfigure(i, weight = 1)
self.sum_entries = {}
self.m_labels_s = ("Godz : Min", "Dni", "Czas pracy", "50%", "100%", "Noc", "Szkolenie", "Inne", "Urlop", "Zwolnienie")
self.m_labels = {}
# summary table
for col in range(3):
for row in range(9):
if col == 0 and row > 0:
self.m_labels[row, col] = ttk.Label(self.mid_frame, text = self.m_labels_s[row+1])
self.m_labels[row, col].grid(row = row, column = col)
if col == 1:
if row == 0:
self.m_labels[row, col] = ttk.Label(self.mid_frame, text = self.m_labels_s[0])
self.m_labels[row, col].grid(row = row, column = col)
else:
self.sum_entries[row, col] = ttk.Entry(self.mid_frame, width = 10, justify = "center")
self.sum_entries[row, col].grid(row = row, column = col, padx = 10)
if col == 2:
if row == 0:
self.m_labels[row, col] = ttk.Label(self.mid_frame, text = self.m_labels_s[1])
self.m_labels[row, col].grid(row = row, column = col)
elif row == 1 or row == 7 or row == 8:
self.sum_entries[row, col] = ttk.Entry(self.mid_frame, width = 10, justify = "center")
self.sum_entries[row, col].grid(row = row, column = col, padx = 10)
self.mid_frame.grid(row = 1, sticky = NSEW)
#bottom frame
self.bot_frame = ttk.LabelFrame(self, text = "Urlop", borderwidth = 2, relief = RIDGE)
for i in range(5):
self.bot_frame.grid_rowconfigure(i, weight = 1)
for i in range(3):
self.bot_frame.grid_columnconfigure(i, weight = 1)
self.in_month = ttk.Label(self.bot_frame, text = "W miesiącu")
self.in_year = ttk.Label(self.bot_frame, text = "W roku")
self.back_0_s = StringVar()
self.back_1_s = StringVar()
self.back_2_s = StringVar()
self.back_0_s.set(str(datetime.datetime.now().year - 0))
self.back_1_s.set(str(datetime.datetime.now().year - 1))
self.back_2_s.set(str(datetime.datetime.now().year - 2))
self.back_0_l = ttk.Label(self.bot_frame, textvariable = self.back_0_s)
self.back_1_l = ttk.Label(self.bot_frame, textvariable = self.back_1_s)
self.back_2_l = ttk.Label(self.bot_frame, textvariable = self.back_2_s)
self.used_leave_l = ttk.Label(self.bot_frame, text = "Wykorzystany:")
self.used_leave_m = ttk.Entry(self.bot_frame, width = 7, justify = "center")
self.used_leave_y = ttk.Entry(self.bot_frame, width = 7, justify = "center")
self.back_0 = ttk.Entry(self.bot_frame, width = 7, justify = "center")
self.back_1 = ttk.Entry(self.bot_frame, width = 7, justify = "center")
self.back_2 = ttk.Entry(self.bot_frame, width = 7, justify = "center")
self.total_l = ttk.Label(self.bot_frame, text = "Pozostały:")
self.total = ttk.Entry(self.bot_frame, width = 7, justify = "center")
self.in_month.grid(row = 0, column = 1)
self.in_year.grid(row = 0, column = 2)
self.back_0_l.grid(row = 2, column = 0, sticky = S)
self.back_1_l.grid(row = 2, column = 1, sticky = S)
self.back_2_l.grid(row = 2, column = 2, sticky = S)
self.used_leave_l.grid(row = 1, column = 0, sticky = E)
self.used_leave_l.grid(row = 1, column = 0)
self.used_leave_m.grid(row = 1, column = 1, padx = 10)
self.used_leave_y.grid(row = 1, column = 2, padx =10)
self.back_0.grid(row=3, column = 0, padx = 10)
self.back_1.grid(row = 3, column = 1, padx =10)
self.back_2.grid(row = 3, column = 2, padx =10)
self.total_l.grid(row = 4, column = 0, sticky = E)
self.total.grid(row = 4, column = 1, pady = 10)
self.bot_frame.grid(row = 2, sticky = NSEW)
def after_init(self):
self.sum_hours()
# summing hours for every employee
def sum_hours(self):
w_d = 0
s_h = 0
s_d = 0
F1 = "%H"
F2 = "%H:%M"
sum1 = datetime.timedelta()
sum2 = datetime.timedelta()
sum3 = datetime.timedelta()
sum4 = datetime.timedelta()
# values for worked time, holiday...
values = [0, 0, 0, 0, 0, 0, 0]
month_len = self.master.month.get_month_len()
for col in range(2,10):
for row in range(1, month_len):
if col == 2:
s = self.master.input_table.entries[row, col].get()
w = self.master.work_time.entries[row, col].get()
if w != "":
if ":" in str(w):
delta = datetime.datetime.strptime(str(w), F2)
sum1 += datetime.timedelta(hours = delta.hour, minutes = delta.minute)
else:
delta = datetime.datetime.strptime(str(w), F1)
sum1 += datetime.timedelta(hours = delta.hour, minutes = delta.minute)
w_d += 1
if s != "":
s_h += int(self.master.input_table.entries[row, col].get())
s_d += 1
elif col == 3:
w = self.master.work_time.entries[row, col].get()
if w != "":
if ":" in str(w):
delta = datetime.datetime.strptime(str(w), F2)
sum2 += datetime.timedelta(hours = delta.hour, minutes = delta.minute)
else:
delta = datetime.datetime.strptime(str(w), F1)
sum2 += datetime.timedelta(hours = delta.hour, minutes = delta.minute)
elif col == 4:
w = self.master.work_time.entries[row, col].get()
if w != "":
if ":" in str(w):
delta = datetime.datetime.strptime(str(w), F2)
sum3 += datetime.timedelta(hours = delta.hour, minutes = delta.minute)
else:
delta = datetime.datetime.strptime(str(w), F1)
sum3 += datetime.timedelta(hours = delta.hour, minutes = delta.minute)
elif col == 5:
w = self.master.work_time.entries[row, col].get()
if w != "":
if ":" in str(w):
delta = datetime.datetime.strptime(str(w), F2)
sum4 += datetime.timedelta(hours = delta.hour, minutes = delta.minute)
else:
delta = datetime.datetime.strptime(str(w), F1)
sum4 += datetime.timedelta(hours = delta.hour, minutes = delta.minute)
elif col == 9:
if self.master.work_time.labels[row].cget("background") != "red":
s = self.master.work_time.entries[row, col].get()
if s != "":
values[col-3] += int(self.master.work_time.entries[row, col].get())
else:
s = self.master.work_time.entries[row, col].get()
if s != "":
values[col-3] += int(self.master.work_time.entries[row, col].get())
sec = sum1.total_seconds()
m = int((sec%3600) // 60)
h = int(sec // 3600)
sec2 = sum2.total_seconds()
m2 = int((sec2%3600) // 60)
h2 = int(sec2 // 3600)
sec3 = sum3.total_seconds()
m3 = int((sec3%3600) // 60)
h3 = int(sec3 // 3600)
sec4 = sum4.total_seconds()
m4 = int((sec4%3600) // 60)
h4 = int(sec4 // 3600)
x = str(str(h) + ":" + str(m).zfill(2))
x2 = str(str(h2) + ":" + str(m2).zfill(2))
x3 = str(str(h3) + ":" + str(m3).zfill(2))
x4 = str(str(h4) + ":" + str(m4).zfill(2))
self.w_hours_s.set((x))
self.w_days_s.set((w_d))
self.s_hours_s.set(int(s_h))
self.s_days_s.set(int(s_d))
self.sum_entries[2,1].delete(0, 10)
self.sum_entries[2,1].insert(0, x2)
self.sum_entries[3,1].delete(0, 10)
self.sum_entries[3,1].insert(0, x3)
self.sum_entries[4,1].delete(0, 10)
self.sum_entries[4,1].insert(0, x4)
# Summaries
self.sum_entries[1,1].delete(0, 10)
self.sum_entries[1,1].insert(0, x)
self.sum_entries[1,2].delete(0, 10)
self.sum_entries[1,2].insert(0, int(w_d))
for v in range(3,7):
self.sum_entries[v+2, 1].delete(0, 10)
self.sum_entries[v+2, 1].insert(0, values[v])
self.sum_entries[7, 2].delete(0,10)
self.sum_entries[7, 2].insert(0, int(values[5]/8))
self.used_leave_m.delete(0,10)
self.used_leave_m.insert(0, int(values[5]/8))
self.sum_entries[8, 2].delete(0,10)
self.sum_entries[8, 2].insert(0, int(values[6]/8))
def sum_holiday(self):
try:
total = int(self.master.employee.hol_days) + int(self.back_1.get()) + int(self.back_2.get()) - int(self.used_leave_y.get())
self.total.delete(0, END)
self.total.insert(0, total)
self.back_0.delete(0, END)
self.back_0.insert(0, self.master.employee.hol_days)
except Exception as e:
self.controller.set_status("Coś poszło nie tak, spróbuj cofnąć miesiąc i ponownie wczytaj ten miesiąc")
messagebox.showerror("Błąd", e)