-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject_for_test.py
2172 lines (1849 loc) · 81.8 KB
/
project_for_test.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
import xlrd
import xlsxwriter
import time
# import DateTime
from time import gmtime, strftime
from datetime import date
import random
from tabulate import tabulate
def get_total_price_of_recipect(rec_num):
# ============================== get lists of recipects =====================================
# saving location file
location = r'C:\Users\micha\PycharmProjects\yesodotFinish\recipects.xlsx'
# variable that present the file we will work with
recipects_file = xlrd.open_workbook(location)
# the specific sheet we need from the file:
sheet = recipects_file.sheet_by_index(0)
row_list = []
recipects_list = []
# copy the file to list:
for i in range(0, sheet.nrows):
row_list = sheet.row_values(i)
recipects_list.append(row_list)
total_price = 0
# search for recipect number:
for i in range(len(recipects_list)):
if recipects_list[i][0] == rec_num:
total_price += recipects_list[i][2]
return total_price
def update_stock_with_cancellation(items_list):
# saving location file
location = r'C:\Users\micha\PycharmProjects\yesodotFinish\inventory.xlsx'
# variable that present the file we will work with
inventory_file = xlrd.open_workbook(location)
# the specific sheet we need from the file:
sheet = inventory_file.sheet_by_index(0)
# copy the file to list
inventory_list = []
# list- code, name, amount, price
for i in range(sheet.nrows):
row_list = sheet.row_values(i)
inventory_list.append(row_list)
# update the inventory by update the list:
for i in range(len(items_list)):
product_code = items_list[i][0]
amount = int(items_list[i][3])
for j in range(len(inventory_list)):
if inventory_list[j][0] == product_code:
inventory_list[j][3] = inventory_list[j][3] + amount
# update the file by copy the new list:
inventory_workbook = xlsxwriter.Workbook('inventory.xlsx')
worksheet = inventory_workbook.add_worksheet('inventory1')
for i in range(len(inventory_list)):
# print(inventory_list[i])
for j in range(len(inventory_list[i])):
worksheet.write(i, j, inventory_list[i][j])
# print(inventory_list[i])
inventory_workbook.close()
####################################################################################
def update_cancelled_report(data_list):
# saving location file
location = r'C:\Users\micha\PycharmProjects\yesodotFinish\sales.xlsx'
# variable that present the file we will work with
cancelled_sales_file = xlrd.open_workbook(location)
# the specific sheet we need from the file:
sheet1 = cancelled_sales_file.sheet_by_index(0)
sheet2 = cancelled_sales_file.sheet_by_index(1)
sales_list = []
row = []
# copy the file- sheet 1 to list:
for i in range(sheet1.nrows):
row = sheet1.row_values(i)
sales_list.append(row)
# copy the file to list:
cancelled_sales_list = []
row_list = []
for i in range(0, sheet2.nrows):
row_list = sheet2.row_values(i)
cancelled_sales_list.append(row_list)
cancelled_sales_list.append(data_list)
# copy the new list to the file:
sales_workbook = xlsxwriter.Workbook('sales.xlsx')
workseet_sales = sales_workbook.add_worksheet('sales')
worksheet_cancel = sales_workbook.add_worksheet('cancelled sales')
for i in range(len(sales_list)):
for j in range(len(sales_list[i])):
workseet_sales.write(i, j, sales_list[i][j])
for i in range(len(cancelled_sales_list)):
for j in range(len(cancelled_sales_list[i])):
worksheet_cancel.write(i, j, cancelled_sales_list[i][j])
sales_workbook.close()
####################################################################################
def cancel_sell(access):
# first, recognition process of recipect:
recipect_num = int(input('Please enter recepict number: '))
while check_recipect_number_validation(recipect_num) == False:
recipect_num = int(input('recepict number wrong, enter again: '))
today = str(date.today())
recipect_date = get_recipect_date(recipect_num)
if recipect_date == today:
# ==================get from sales report the items in the recipct========================
# saving location file
location = r'C:\Users\micha\PycharmProjects\yesodotFinish\sales.xlsx'
# variable that present the file we will work with
sales_file = xlrd.open_workbook(location)
# the specific sheet we need from the file:
sheet = sales_file.sheet_by_index(0)
row_list1 = []
sales_list = []
canceled_list = []
recipect_item_list = []
item = []
# copy the file to list- copy sheet 1:
for i in range(0, sheet.nrows):
row_list1 = sheet.row_values(i)
sales_list.append(row_list1)
# find the relevant items by recipect number, at the end of the process i get list of items belong to the recipect
for i in range(len(sales_list)):
if sales_list[i][7] == recipect_num:
code = sales_list[i][3]
name = sales_list[i][4]
amount = sales_list[i][5]
price = sales_list[i][6]
item = [code, name, amount, price]
recipect_item_list.append(item)
# =================== get total price we need to refund =======================
total_sum = get_total_price_of_recipect(recipect_num)
'The cancellation fee according to the law is 5% or 100 NIS, whichever is lower'
check_5_Percent = 0.05 * total_sum
Cancellation_fee = 0
if check_5_Percent < 100:
Cancellation_fee = check_5_Percent
else:
Cancellation_fee = 100
Refund = total_sum - Cancellation_fee
Refund = round(Refund)
print('recipect items list is:\n')
for i in range(len(recipect_item_list)):
print(recipect_item_list[i])
print('-------------------')
print('Dear employee, the customer must receive a refund of {0} NIS'.format(Refund))
# ====================== update inventory after items are returned ===============
update_stock_with_cancellation(recipect_item_list)
print('cancellation process finished successfully')
date_now = time.localtime()
current_year, current_month, current_day = date_now[0], date_now[1], date_now[2]
data_list = [recipect_num, current_year, current_month, current_day, Refund]
update_cancelled_report(data_list)
else:
print('You can not cancel a sell.\nCancellation of sell is valid only for one day.')
Open_Menu(access)
####################################################################################
def clear_constraints(access):
constraints_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\Constraints1.xlsx'
constraints_file = xlrd.open_workbook(constraints_loc)
sheet = constraints_file.sheet_by_index(0)
sheet_list = []
for i in range(sheet.nrows):
row_list = sheet.row_values(i)
sheet_list.append(row_list)
workbook_constraints = xlsxwriter.Workbook('Constraints1.xlsx')
worksheet = workbook_constraints.add_worksheet('shifts')
for i in range(len(sheet_list)):
for j in range(len(sheet_list[i])): # number of rows in sheet
worksheet.write(i, j, sheet_list[i][j])
workbook_constraints.close()
Open_Menu(access)
####################################################################################
def add_2_workers_to_shifts(worker1, worker2):
constraints_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\Constraints1.xlsx'
constraints_file = xlrd.open_workbook(constraints_loc)
screwed_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\Screwed.xlsx'
screwed_file = xlrd.open_workbook(screwed_loc)
amount_sheets_constraints = constraints_file.nsheets
constraints_list = []
row_list = []
screwed_list = []
# add the sheets of constraints to list##########
for i in range(amount_sheets_constraints):
sheet = constraints_file.sheet_by_index(i)
sheet_list = [sheet.name]
for j in range(sheet.nrows):
row_list = sheet.row_values(j)
sheet_list.append(row_list)
constraints_list.append(sheet_list)
count = 0
# change the no one can to worker
for i in range(len(constraints_list[0])):
for j in range(len(constraints_list[0][i])):
if constraints_list[0][i][j] == 'no one can' and count == 1:
constraints_list[0][i][j] = worker2
elif constraints_list[0][i][j] == 'no one can':
constraints_list[0][i][j] = worker1
count += 1
# copy the list to excel
workbook_constraints = xlsxwriter.Workbook('Constraints1.xlsx')
for i in range(len(constraints_list)):
worksheet = workbook_constraints.add_worksheet(constraints_list[i][0]) # constraints_list[i][0]- sheet name
for j in range(1, len(constraints_list[i])): # number of rows in sheet
for k in range(len(constraints_list[i][j])):
worksheet.write(j - 1, k, constraints_list[i][j][k])
workbook_constraints.close()
# add the sheets of screwed to list##########
for i in range(2):
sheet = screwed_file.sheet_by_index(i)
sheet_list = [sheet.name]
for j in range(sheet.nrows):
row_list = sheet.row_values(j)
sheet_list.append(row_list)
screwed_list.append(sheet_list)
# add the one/two workers to screwed list
if count == 1:
screwed_list[0].append([screwed_file.sheet_by_index(0).nrows, worker1])
elif count == 2:
screwed_list[0].append([screwed_file.sheet_by_index(0).nrows, worker1])
screwed_list[0].append([screwed_file.sheet_by_index(0).nrows + 1, worker2])
# copy the list to excel
workbook = xlsxwriter.Workbook('Screwed.xlsx')
for i in range(len(screwed_list)):
worksheet = workbook.add_worksheet(screwed_list[i][0]) # constraints_list[i][0]- sheet name
for j in range(1, len(screwed_list[i])): # number of rows in sheet
for k in range(len(screwed_list[i][j])):
worksheet.write(j - 1, k, screwed_list[i][j][k])
workbook.close()
####################################################################################
def max_val(var):
maximum = 0
for i in range(len(var)):
if var[i] > maximum:
maximum = var[i]
return maximum
####################################################################################
def find_2_workers_when_no_one_can():
screwed_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\Screwed.xlsx'
screwed_file = xlrd.open_workbook(screwed_loc)
number_of_shifts_sheet = screwed_file.sheet_by_index(1)
screwed_sheet = screwed_file.sheet_by_index(0)
screwed_worker1 = screwed_sheet.cell_value(screwed_sheet.nrows - 1, 1)
screwed_worker2 = screwed_sheet.cell_value(screwed_sheet.nrows - 2, 1)
list_of_number_of_shifts = []
for i in range(1, number_of_shifts_sheet.nrows):
list_of_number_of_shifts.append(number_of_shifts_sheet.cell_value(i, 1))
maximum_shifts = max_val(list_of_number_of_shifts)
index_of_max = list_of_number_of_shifts.index(maximum_shifts)
first = second = maximum_shifts
first_worker = second_worker = number_of_shifts_sheet.cell_value(index_of_max + 1, 0)
for i in range(len(list_of_number_of_shifts)):
# If current element is smaller than first then update both first and second
if list_of_number_of_shifts[i] < first and list_of_number_of_shifts[i] != screwed_worker1 and \
list_of_number_of_shifts[i] != screwed_worker2:
second = first
second_worker = first_worker
first = list_of_number_of_shifts[i]
first_worker = number_of_shifts_sheet.cell_value(i + 1, 0)
# If list_of_number_of_shifts[i] is in between first and second then update second
elif list_of_number_of_shifts[i] < second and list_of_number_of_shifts[i] != first and list_of_number_of_shifts[
i] != screwed_worker1 and list_of_number_of_shifts[i] != screwed_worker2:
second = list_of_number_of_shifts[i]
second_worker = number_of_shifts_sheet.cell_value(i + 1, 0)
add_2_workers_to_shifts(first_worker, second_worker)
####################################################################################
def count_shift_for_worker():
constraints_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\Constraints1.xlsx'
constraints_file = xlrd.open_workbook(constraints_loc)
# screwed_loc = r'C:\Users\micha\Desktop\project_new\Group2_Yesodot\final project\Screwed.xlsx'
screwed_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\Screwed.xlsx'
screwed_file = xlrd.open_workbook(screwed_loc)
shifts_sheet = constraints_file.sheet_by_index(0)
shiftsForWorker_sheet = screwed_file.sheet_by_index(1)
workers_dict = {}
for i in range(1, shiftsForWorker_sheet.nrows):
worker = shiftsForWorker_sheet.cell_value(i, 0)
workers_dict[worker] = 0
for j in range(shifts_sheet.nrows):
for k in range(shifts_sheet.ncols):
if worker == shifts_sheet.cell_value(j, k):
workers_dict[worker] = workers_dict[worker] + 1
return workers_dict
####################################################################################
def write_number_of_shifts_to_sheet():
shifts_dict = count_shift_for_worker()
row_list = []
screwed_list = []
sheet_list = []
screwed_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\Screwed.xlsx'
screwed_file = xlrd.open_workbook(screwed_loc)
amount_sheets = screwed_file.nsheets
# copy the excel to list
for i in range(amount_sheets):
sheet = screwed_file.sheet_by_index(i)
sheet_list = [sheet.name]
for j in range(sheet.nrows):
row_list = sheet.row_values(j)
sheet_list.append(row_list)
screwed_list.append(sheet_list)
# add the numbers of shifts to each worker
for i in range(2, len(screwed_list[1])):
screwed_list[1][i][1] = shifts_dict[screwed_list[1][i][0]]
workbook = xlsxwriter.Workbook('Screwed.xlsx')
for i in range(len(screwed_list)):
worksheet = workbook.add_worksheet(screwed_list[i][0])
for j in range(1, len(screwed_list[i])): # number of rows in sheet
for k in range(len(screwed_list[i][j])):
worksheet.write(j - 1, k, screwed_list[i][j][k])
workbook.close()
####################################################################################
# make list of constraints of shift manager
def build_list_of_constraints_of_shift_manager(name):
shiftManager_constraints = []
constraints_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\Constraints1.xlsx'
constraints_file = xlrd.open_workbook(constraints_loc)
# find the sheet of the shift manager- michal
for i in range(constraints_file.nsheets):
sheet = constraints_file.sheet_by_index(i)
if sheet.name == name:
shiftManager_constraints.append(name)
break
# add the constraints to a list
for j in range(sheet.nrows):
for k in range(sheet.ncols):
if sheet.cell_value(j, k) == 'NO':
shiftManager_constraints.append([j, k]) # j- the shift, k- the day
return shiftManager_constraints
####################################################################################
def make_shifts_for_shift_manager(list_of_constraints):
list = []
michal_number_of_shifts = 0
emilia_number_of_shifts = 0
for i in range(1, 3):
row_list = []
for j in range(1, 8):
if (list_of_constraints[0][1][0] == i and list_of_constraints[0][1][1] == j) or (
list_of_constraints[0][2][0] == i and list_of_constraints[0][2][
1] == j): # if michal cant work, put emilia
row_list.append(list_of_constraints[1][0])
emilia_number_of_shifts += 1
elif (list_of_constraints[1][1][0] == i and list_of_constraints[1][1][1] == j) or (
list_of_constraints[1][2][0] == i and list_of_constraints[1][2][1] == j):
row_list.append(list_of_constraints[0][0])
michal_number_of_shifts += 1
elif emilia_number_of_shifts < michal_number_of_shifts:
row_list.append(list_of_constraints[1][0])
emilia_number_of_shifts += 1
else:
row_list.append(list_of_constraints[0][0])
michal_number_of_shifts += 1
list.append(row_list)
return list
####################################################################################
# the function gets list of people who can work in the shift and return list by random of two workers
def make_shift_by_random(day):
shift = []
if len(day) == 0:
shift.append('no one can')
shift.append('no one can')
return shift
elif len(day) == 1:
shift.append(day[0])
shift.append('no one can')
return shift
while len(shift) < 2:
rand = random.randint(0, len(day) - 1)
if len(shift) == 0:
shift.append(day[rand])
else:
for i in range(len(shift)):
if day[rand] != shift[i]:
shift.append(day[rand])
break
return shift
####################################################################################
# get from build_shifts the col and row of the cell that represent the shift
# and append all the workers that can work in this shift
def build_one_shift(row, col):
shift = []
constraints_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\Constraints1.xlsx'
constraints_file = xlrd.open_workbook(constraints_loc)
amount_sheets = constraints_file.nsheets - 2
for i in range(1, amount_sheets):
sheet = constraints_file.sheet_by_index(i)
if sheet.cell_value(row, col) != 'NO':
shift.append(sheet.name)
return shift
####################################################################################
def build_shifts(access):
constraints_list = []
row_list = []
constraints_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\Constraints1.xlsx'
constraints_file = xlrd.open_workbook(constraints_loc)
amount_sheets = constraints_file.nsheets
# add the sheets of constraints to list##########
if amount_sheets < 9:
print('You still can not build shifts, not all employees have submitted constraints')
Open_Menu(access)
for i in range(1, amount_sheets):
sheet = constraints_file.sheet_by_index(i)
sheet_list = [sheet.name]
for j in range(sheet.nrows):
row_list = sheet.row_values(j)
sheet_list.append(row_list)
constraints_list.append(sheet_list)
# every workers that can work in every shift:
# send to function the cell of the shift that he will check with each worker
# and add him to the list if he can work
sunday_morning = build_one_shift(1, 1)
sunday_evening = build_one_shift(2, 1)
monday_morning = build_one_shift(1, 2)
monday_evening = build_one_shift(2, 2)
tuesday_morning = build_one_shift(1, 3)
tuesday_evening = build_one_shift(2, 3)
wednesday_morning = build_one_shift(1, 4)
wednesday_evening = build_one_shift(2, 4)
thursday_morning = build_one_shift(1, 5)
thursday_evening = build_one_shift(2, 5)
friday_morning = build_one_shift(1, 6)
saturday_evening = build_one_shift(2, 7)
# list of workers in the shift
sunday_morning_shift = make_shift_by_random(sunday_morning)
sunday_evening_shift = make_shift_by_random(sunday_evening)
monday_morning_shift = make_shift_by_random(monday_morning)
monday_evening_shift = make_shift_by_random(monday_evening)
tuesday_morning_shift = make_shift_by_random(tuesday_morning)
tuesday_evening_shift = make_shift_by_random(tuesday_evening)
wednesday_morning_shift = make_shift_by_random(wednesday_morning)
wednesday_evening_shift = make_shift_by_random(wednesday_evening)
thursday_morning_shift = make_shift_by_random(thursday_morning)
thursday_evening_shift = make_shift_by_random(thursday_evening)
friday_morning_shift = make_shift_by_random(friday_morning)
saturday_evening_shift = make_shift_by_random(saturday_evening)
workbook = xlsxwriter.Workbook('Constraints1.xlsx')
worksheet = workbook.add_worksheet('shifts')
# input the table of shifts
worksheet.write(1, 0, 'Morning')
worksheet.write(2, 0, 'Morning')
worksheet.write(3, 0, 'shift manager')
worksheet.write(4, 0, 'Evening')
worksheet.write(5, 0, 'Evening')
worksheet.write(6, 0, 'shift manager')
worksheet.write(0, 1, 'Sunday')
worksheet.write(0, 2, 'Monday')
worksheet.write(0, 3, 'Tuesday')
worksheet.write(0, 4, 'Wednesday')
worksheet.write(0, 5, 'Thursday')
worksheet.write(0, 6, 'Friday')
worksheet.write(0, 7, 'Saturday')
# add the workers to each shift in the sheet
for i in range(2):
worksheet.write(i + 1, 1, sunday_morning_shift[i])
for i in range(2):
worksheet.write(i + 4, 1, sunday_evening_shift[i])
for i in range(2):
worksheet.write(i + 1, 2, monday_morning_shift[i])
for i in range(2):
worksheet.write(i + 4, 2, monday_evening_shift[i])
for i in range(2):
worksheet.write(i + 1, 3, tuesday_morning_shift[i])
for i in range(2):
worksheet.write(i + 4, 3, tuesday_evening_shift[i])
for i in range(2):
worksheet.write(i + 1, 4, wednesday_morning_shift[i])
for i in range(2):
worksheet.write(i + 4, 4, wednesday_evening_shift[i])
for i in range(2):
worksheet.write(i + 1, 5, thursday_morning_shift[i])
for i in range(2):
worksheet.write(i + 4, 5, thursday_evening_shift[i])
for i in range(2):
worksheet.write(i + 1, 6, friday_morning_shift[i])
for i in range(2):
worksheet.write(i + 4, 7, saturday_evening_shift[i])
# add the shifts of the shifts managers:
shift_managers_constraints = []
shift_managers_constraints.append(build_list_of_constraints_of_shift_manager('michal'))
shift_managers_constraints.append(build_list_of_constraints_of_shift_manager('emilia'))
list_of_shifts_for_sManager = (make_shifts_for_shift_manager(shift_managers_constraints))
for i in range(1, 7):
worksheet.write(3, i, list_of_shifts_for_sManager[0][i - 1])
for i in range(1, 8):
if i == 6:
continue
elif i == 7:
worksheet.write(6, i, list_of_shifts_for_sManager[1][i - 2])
else:
worksheet.write(6, i, list_of_shifts_for_sManager[1][i - 1])
# copy the sheets of constraints
for i in range(len(constraints_list)):
worksheet = workbook.add_worksheet(constraints_list[i][0]) # constraints_list[i][0]- sheet name
for j in range(1, len(constraints_list[i])): # number of rows in sheet
for k in range(len(constraints_list[i][j])):
worksheet.write(j - 1, k, constraints_list[i][j][k])
workbook.close()
find_2_workers_when_no_one_can()
write_number_of_shifts_to_sheet()
Open_Menu(access)
####################################################################################
# manager can put cell and the name he want to change for working
def make_changes_in_shifts(access):
constraints_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\Constraints1.xlsx'
constraints_file = xlrd.open_workbook(constraints_loc)
sheet = constraints_file.sheet_by_index(0)
row_list = [' ', '0', '1', '2', '3', '4', '5', '6', '7']
sheet_list = []
sheet_list.append(row_list)
amount_sheets = constraints_file.nsheets
constraints_list = []
# add the shifts to list
for i in range(sheet.nrows):
row_list = [i]
row_list.extend(sheet.row_values(i))
sheet_list.append(row_list)
print(tabulate(sheet_list, tablefmt="fancy_grid"))
# add the sheets of constraints to list##########
for i in range(amount_sheets):
sheet = constraints_file.sheet_by_index(i)
sheet_list = [sheet.name]
for j in range(sheet.nrows):
row_list = sheet.row_values(j)
sheet_list.append(row_list)
constraints_list.append(sheet_list)
print('enter row and col of the cell you want to change, for end entet- done')
passworde_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\passwarde.xlsx'
passworde_file = xlrd.open_workbook(passworde_loc)
sheet_passworde = passworde_file.sheet_by_index(0)
while True:
flag = 0
row = input('row- ')
if row == 'done' or row == 'Done':
break
row = int(row)
if row > 6 or row < 1:
print('try again')
continue
col = int(input('col- '))
if col > 7 or col < 1:
print('try again')
continue
worker = str(input('worker- '))
for i in range(sheet_passworde.nrows):
if worker == sheet_passworde.cell_value(i, 0):
flag = 1
break
if flag == 1:
constraints_list[0][row + 1][col] = worker
else:
print('the worker does not exist')
workbook = xlsxwriter.Workbook('Constraints1.xlsx')
for i in range(len(constraints_list)):
worksheet = workbook.add_worksheet(constraints_list[i][0]) # constraints_list[i][0]- sheet name
for j in range(1, len(constraints_list[i])): # number of rows in sheet
for k in range(len(constraints_list[i][j])):
worksheet.write(j - 1, k, constraints_list[i][j][k])
workbook.close()
Open_Menu(access)
####################################################################################
# shows to the screen table of shifts
def shifts_report(access):
constraints_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\Constraints1.xlsx'
constraints_file = xlrd.open_workbook(constraints_loc)
sheet = constraints_file.sheet_by_index(0)
row_list = []
sheet_list = []
##add the shifts to list
for i in range(sheet.nrows):
row_list = sheet.row_values(i)
sheet_list.append(row_list)
print(tabulate(sheet_list, tablefmt="fancy_grid"))
Open_Menu(access)
####################################################################################
# returns the total amount of the sales in the current day
def Daily_Money_amount(year, month, day):
sales_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\recipects.xlsx'
sales_file = xlrd.open_workbook(sales_loc)
sheet = sales_file.sheet_by_index(0)
temp_list = []
total_money_amount = 0
# this part is for coping the existing data thats in the file already
for i in range(1, sheet.nrows):
row_list = sheet.row_values(i)
temp_list.append(row_list)
# this part summs all the money from all the sells that were made the current day.
for i in range(1, len(temp_list)):
if date == temp_list[i][1]:
total_money_amount = total_money_amount + temp_list[i][2]
return total_money_amount
####################################################################################
# this function writes the daily money amount with the current date into EOD excel file and returns the daily amount of money
def EOD_report(access):
EOD_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\EOD.xlsx'
EOD_file = xlrd.open_workbook(EOD_loc)
sheet = EOD_file.sheet_by_index(0)
date1 = str(date.today())
date_now = strftime("%d %b %Y", time.localtime())
EOD_list = []
t_list = []
# this part is for coping the existing data thats in the file already
for j in range(sheet.nrows):
row_list = sheet.row_values(j)
EOD_list.append(row_list)
# this part makes a new list with the following data: the current date and the total amont of money(using the above function) and appending it with the rest of the information.
total = Daily_Money_amount(date1)
t_list.append(date_now)
t_list.append(total)
EOD_list.append(t_list)
print('The total money for this day is:', end=' ')
print(total)
# this part writes all the lists to the excel file.
EOD_workbook = xlsxwriter.Workbook('EOD.xlsx')
worksheet = EOD_workbook.add_worksheet('EOD01')
for i in range(len(EOD_list)):
for j in range(len(EOD_list[i])):
worksheet.write(i, j, EOD_list[i][j])
EOD_workbook.close()
Open_Menu(access)
####################################################################################
# this function checks if the money that was counted in the EOD report matches the money that was counted by the worker
def Closing_The_Register(access):
flag = 0
while flag == 0:
date1 = str(date.today())
money_from_register = input('Enter the amount you counted:')
if float(money_from_register) == Daily_Money_amount(date1):
print('All Valid.')
else:
print('Please inform the shift manager that the money you entered does not match the EOD report.'
'Would you to close the register anyway?[yes/no]')
# only if the worker enters yes the function will close and the menu will be shown again.
answer = input()
if answer == 'yes':
flag == 1
Open_Menu(access)
elif answer == 'no':
flag == 0
else: # if the worker wont enter the right answer than the whole process will start again.
print('not valid input.')
flag == 0
Open_Menu(access)
####################################################################################
# print table of all the inventory
def get_inventory_report(access):
inventory_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\Inventory.xlsx'
inventory_file = xlrd.open_workbook(inventory_loc)
sheet = inventory_file.sheet_by_index(0)
row_list = []
inventory_list = []
for i in range(0, sheet.nrows):
row_list = sheet.row_values(i)
inventory_list.append(row_list)
# print table report
print(tabulate(inventory_list, tablefmt="fancy_grid"))
Open_Menu(access)
####################################################################################
# Prints all names and hours of all employees
def get_manager_presence_report(access):
month = int(input('enter the number of month of the report you want: '))
while True:
if month > 0 and month < 13:
break
month = int(input('wrong choice, try again: '))
print('***** Presence Report For Manager *****')
presence_list = []
presence_list.append(['worker', 'arrival', 'departure', 'total'])
presence_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\presence1.xlsx'
presence_file = xlrd.open_workbook(presence_loc)
sheet = presence_file.sheet_by_index(0)
for i in range(0, sheet.nrows):
if sheet.cell_value(i, 7) == '':
continue
if sheet.cell_value(i, 4) == str(month):
total_sec = int(sheet.cell_value(i, 8))
sec = total_sec % 60
total_sec = total_sec // 60
mint = total_sec % 60
hour = total_sec // 60
row_list = [sheet.cell_value(i, 1), sheet.cell_value(i, 3), sheet.cell_value(i, 7),
('%02d:%02d:%02d' % (hour, mint, sec))]
presence_list.append(row_list)
# print table report
print(tabulate(presence_list, tablefmt="fancy_grid"))
Open_Menu(access)
####################################################################################
# print presence report for the worker who asked for
def get_monthly_presence_report(access):
name = input('enter your name: ')
now = time.localtime()
month = now[1]
print(' ***** Presence Report *****')
presence_list = []
presence_list.append(['arrival time', 'departure time', 'total work time'])
presence_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\presence1.xlsx'
presence_file = xlrd.open_workbook(presence_loc)
sheet = presence_file.sheet_by_index(0)
for i in range(0, sheet.nrows):
if sheet.cell_value(i, 7) == '':
continue
if sheet.cell_value(i, 1) == name and sheet.cell_value(i, 4) == str(month):
total_sec = sheet.cell_value(i, 8)
sec = total_sec % 60
total_sec = total_sec // 60
mint = total_sec % 60
hour = total_sec // 60
row_list = [sheet.cell_value(i, 3), sheet.cell_value(i, 7), ('%02d:%02d:%02d' % (hour, mint, sec))]
presence_list.append(row_list)
print(tabulate(presence_list, tablefmt="fancy_grid"))
Open_Menu(access)
####################################################################################
# returning some product to the Storage
def return_inventory(access):
flag = 0
while flag == 0:
inventory_list = []
updated_stock_list = []
inventory_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\inventory.xlsx'
inventory_file = xlrd.open_workbook(inventory_loc)
sheet = inventory_file.sheet_by_index(0)
k, l = 0, 0
# coping the existing data to a new list
for i in range(sheet.nrows):
row_list = sheet.row_values(i)
inventory_list.append(row_list)
# converting float numbers to integers(except from the price column)
for i in range(1, len(inventory_list)):
num = inventory_list[i][0]
inventory_list[i][0] = int(num)
num = inventory_list[i][3]
inventory_list[i][3] = int(num)
# prints the current inventory
print(tabulate(inventory_list, tablefmt="fancy_grid"))
picks = []
# input from the manager which item to send back
pick = int(input("enter product code of item you want to send back?:"))
try: # if the input is not valid exeption is trown.
if pick > (len(inventory_list) - 1):
raise ValueError('Not valid choice.')
except ValueError:
print('Value Error.Pick again')
# searching for the index of the item that the manager entered
picks.append(pick)
for i in range(len(inventory_list)):
for j in range(len(inventory_list[i])):
for k in range(len(picks)):
if picks[k] == inventory_list[i][j]:
l = i + 1
# making a new list without the deleted item
for i in range(0, l - 1, 1):
updated_stock_list.append(inventory_list[i])
for j in range(l, len(inventory_list), 1):
updated_stock_list.append(inventory_list[j])
try:
pick2 = input("would you like to remove another item from the inventory?:[yes/no]")
if pick2 == 'yes':
flag = 0
elif pick2 == 'no':
flag = 1
else:
raise ValueError('Not valid choice.')
except ValueError:
print('Value Error.Pick again')
# after the manager decides what to delete the updated inventory is being written back to the excel file.
inventory_workbook = xlsxwriter.Workbook('inventory.xlsx')
worksheet = inventory_workbook.add_worksheet('inventory1')
for i in range(len(updated_stock_list)):
for j in range(len(updated_stock_list[i])):
worksheet.write(i, j, updated_stock_list[i][j])
inventory_workbook.close()
Open_Menu(access)
####################################################################################
# gets name of worker and add to data base of the presence
def arrival_to_work(access):
password_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\passwarde.xlsx'
password_file = xlrd.open_workbook(password_loc)
password_sheet = password_file.sheet_by_index(0)
name = input('enter your first name: ')
last = input('enter your last name: ')
flag = 0
while True:
for i in range(password_sheet.nrows):
if password_sheet.cell_value(i, 0) == name and password_sheet.cell_value(i, 3) == last:
flag = 1
break
if flag:
break
print('wrong name')
name = input('enter your first name: ')
last = input('enter your last name: ')
date_now = time.localtime()
presence_list = []
row_list = []
presence_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\presence1.xlsx'
presence_file = xlrd.open_workbook(presence_loc)
sheet = presence_file.sheet_by_index(0)
for i in range(0, sheet.nrows):
row_list = sheet.row_values(i)
if i > 0:
row_list[0] = int(row_list[0])
presence_list.append(row_list)
month = ('{0}'.format(date_now[1]))
day = ('{0}'.format(date_now[2]))
weekDay = ('{0}'.format(date_now[6] + 2))
presence_list.append(
[sheet.nrows, name, last, strftime("%a, %d %b %Y %H:%M:%S", time.localtime()), month, day, weekDay])
presence_workbook = xlsxwriter.Workbook('presence1.xlsx')
worksheet = presence_workbook.add_worksheet('presence')
for i in range(len(presence_list)):
for j in range(len(presence_list[i])):
worksheet.write(i, j, presence_list[i][j])
presence_workbook.close()
Open_Menu(access)
####################################################################################
# gets name of worker and add to data base of the presence the time of leaving the work
def departure(access):
password_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\passwarde.xlsx'
password_file = xlrd.open_workbook(password_loc)
password_sheet = password_file.sheet_by_index(0)
name = input('enter your first name: ')
last = input('enter your last name: ')
flag = 0
while True:
for i in range(password_sheet.nrows):
if password_sheet.cell_value(i, 0) == name and password_sheet.cell_value(i, 3) == last:
flag = 1
break
if flag:
break
print('wrong name')
name = input('enter your first name: ')
last = input('enter your last name: ')
presence_list = []
row_list = []
presence_loc = r'C:\Users\micha\PycharmProjects\yesodotFinish\presence1.xlsx'
presence_file = xlrd.open_workbook(presence_loc)
sheet = presence_file.sheet_by_index(0)
for i in range(0, sheet.nrows):
row_list = sheet.row_values(i)
if i > 0:
row_list[0] = int(row_list[0])
presence_list.append(row_list)
for i in range(1, len(presence_list)):
if presence_list[i][1] == name and presence_list[i][2] == last:
presence_list[i][7] = strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
worker = i
worker_arrival = presence_list[worker][3]
worker_departure = presence_list[worker][7]
# calculates the second of each time
arrival_time = (int(worker_arrival[17]) * 10 + int(worker_arrival[18])) * 3600 + \
(int(worker_arrival[20]) * 10 + int(worker_arrival[21])) * 60 + \
(int(worker_arrival[23]) * 10 + int(worker_arrival[24]))
departure_time = (int(worker_departure[17]) * 10 + int(worker_departure[18])) * 3600 + \
(int(worker_departure[20]) * 10 + int(worker_departure[21])) * 60 + \
(int(worker_departure[23]) * 10 + int(worker_departure[24]))
delta = departure_time - arrival_time
presence_list[worker][8] = delta
presence_workbook = xlsxwriter.Workbook('presence1.xlsx')
worksheet = presence_workbook.add_worksheet('presence')
for i in range(len(presence_list)):
for j in range(len(presence_list[i])):
worksheet.write(i, j, presence_list[i][j])
presence_workbook.close()
Open_Menu(access)
####################################################################################