Skip to content

Commit

Permalink
Added option to export time or overtime
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreWohnsland committed Aug 2, 2020
1 parent 3c86acb commit 471983f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/button_controler.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ def generate_report_df(self, month_list, monthly_time, pause_time):

def export_data(self):
report_date = self.ui_controler.get_event_date()
succesful, file_path = self.data_exporter.export_data(self.report_df, report_date)
overtime_report = self.ui_controler.report_choice()
if overtime_report == None:
return
succesful, file_path = self.data_exporter.export_data(self.report_df, report_date, overtime_report)
if succesful:
self.ui_controler.show_message(f"File saved under: {file_path}")
else:
Expand Down
28 changes: 19 additions & 9 deletions src/data_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ def __init__(self):
dirpath = os.path.dirname(__file__)
self.default_save_path = os.path.join(dirpath, "..", "reports")
self.config_handler = ConfigHandler()
self.worktime = 8

def export_data(self, df, report_date):
def export_data(self, df, report_date, overtime_report=True):
config = self.config_handler.get_config_file_data()
file_name = f"{config['Name'].replace(' ', '_')}_{df.index[0].strftime('%m_%Y')}.xlsx"
file_suffix = "time"
if overtime_report:
file_suffix = "overtime"
file_name = f"{config['Name'].replace(' ', '_')}_{df.index[0].strftime('%m_%Y')}_{file_suffix}.xlsx"
save_path = config["savepath"]
if not save_path:
save_path = self.default_save_path
Expand All @@ -26,8 +30,8 @@ def export_data(self, df, report_date):
worksheet = workbook.add_worksheet()
cell_width = 20
worksheet.set_column("A:B", cell_width)
self.write_person_information(worksheet, df, config, bold, color)
self.write_times(worksheet, df, color)
self.write_person_information(worksheet, df, config, bold, color, overtime_report)
self.write_times(worksheet, df, color, overtime_report)
workbook.close()
return True, file_path
except:
Expand All @@ -37,7 +41,7 @@ def export_data(self, df, report_date):
def round_quarterly(self, number):
return round(number * 4) / 4

def write_person_information(self, worksheet, df, config, bold, color):
def write_person_information(self, worksheet, df, config, bold, color, overtime_report):
worksheet.write("A1", "Name:", bold)
worksheet.write("B1", config["Name"], color)
worksheet.write("A2", "Pers.Nr::", bold)
Expand All @@ -47,11 +51,17 @@ def write_person_information(self, worksheet, df, config, bold, color):
worksheet.write("A4", "Jahr", bold)
worksheet.write("B4", df.index[0].year, color)
worksheet.write("A6", "Tag:")
worksheet.write("B6", "Über 8 h")
if overtime_report:
worksheet.write("B6", "Über 8 h")
else:
worksheet.write("B6", "Arbeitszeit")

def write_times(self, worksheet, df, color):
def write_times(self, worksheet, df, color, overtime_report):
time_to_subtract = 0
if overtime_report:
time_to_subtract = self.worktime
for i, (index, row) in enumerate(df.iterrows()):
worksheet.write(f"A{7+i}", index.strftime("%d.%m.%Y"))
if index.weekday() < 5:
overtime = self.round_quarterly(max(row["final_time"] - 8, 0))
worksheet.write(f"B{7+i}", overtime, color)
_time = self.round_quarterly(max(row["final_time"] - time_to_subtract, 0))
worksheet.write(f"B{7+i}", _time, color)
17 changes: 17 additions & 0 deletions src/ui_controler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ def show_message(self, message):
msgBox.show()
msgBox.exec_()

def report_choice(self):
msgBox = QMessageBox()
msgBox.setText("Would you like the report of the overtime (0 if none or the amount) or of the regular hours?")
msgBox.setWindowTitle("Report Generation")
overtime_button = msgBox.addButton("Overtime", QMessageBox.YesRole)
time_button = msgBox.addButton("Time", QMessageBox.NoRole)
cancelBtn = msgBox.addButton("Cancel", QMessageBox.RejectRole)

msgBox.exec_()

if msgBox.clickedButton() == overtime_button:
return True
elif msgBox.clickedButton() == time_button:
return False
elif msgBox.clickedButton() == cancelBtn:
return None

def get_text(self, attribute):
text, ok = QInputDialog.getText(self.ui, "Getting data for config", f"Enter your {attribute}:")
return (text, ok)
Expand Down

0 comments on commit 471983f

Please sign in to comment.