diff --git a/src/button_controler.py b/src/button_controler.py index 8da55c5..23ef944 100644 --- a/src/button_controler.py +++ b/src/button_controler.py @@ -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: diff --git a/src/data_exporter.py b/src/data_exporter.py index 6774686..9d41530 100644 --- a/src/data_exporter.py +++ b/src/data_exporter.py @@ -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 @@ -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: @@ -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) @@ -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) diff --git a/src/ui_controler.py b/src/ui_controler.py index 62b78cd..6c5b7fb 100644 --- a/src/ui_controler.py +++ b/src/ui_controler.py @@ -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)