Prechádzať zdrojové kódy

customer and month specific bills with summarized tasks

Nico Ruhnke 2 rokov pred
rodič
commit
ad66ae56a4

+ 46 - 5
fast_excel_to_bill/config_for_custom_bills.py

@@ -1,11 +1,48 @@
+# Path helper because Linux and Windows Paths are written differently
+from pathlib import Path
+
+# Bill specific Config
+OUTPUT_MONTH = 3  # -1 for last Month
+OUTPUT_YEAR = 2022  # -1 for current year
+OUTPUT_CUSTOMER = 'Bentomax'
+
+# User specific Parameter (COMMENT/UNCOMMENT USER AND SYSTEM)
+
+# Danny Config
+USER = 'Danny'
+SYSTEM = USER + ''
+
+# Nokko Config
+# USER = 'Nokko'
+# SYSTEM = USER + 'Windows'
+# SYSTEM = USER + 'Ubuntu'
+
+GLOBAL_TOOLS_DIR_PATH = {
+    'Danny': Path("C:/Users/Danny/Desktop/EnD and Investment/Tools/"),
+    'NokkoUbuntu': Path('TODO'),
+    'NokkoWindows': Path("E:/Business/END/PythonProjekte/Tools/")
+}
+WORKTIME_TABLE_PATH = GLOBAL_TOOLS_DIR_PATH[SYSTEM] / Path('time_recoder/time_recorded_tables/')
+
+WORKTIME_TABLE_NAME = {
+    'Danny': 'work_time_danny.xlsx',
+    'NokkoUbuntu': 'nokko_ubuntu.xlsx',
+    'NokkoWindows': 'nokko_windows.xlsx'
+}
+
+OVERTIME_TABLE_NAME = {
+    'Danny': 'overtime_danny.xlsx',
+    'Nokko': 'overtime_nokko.xlsx'
+}
+
 # Docx Builder
-DOCX_INPUT_PATH = r'C:\Users\Danny\Desktop\EnD and Investment\Tools\fast_excel_to_bill\test_folder\Templates\templeta.docx'
+DOCX_INPUT_PATH = GLOBAL_TOOLS_DIR_PATH[SYSTEM] / Path('fast_excel_to_bill/test_folder/Templates/templeta.docx')
 LIST_OF_KEYS = ['Arbeitszeit', 'Task']
-ROUND_TIME = 300
+ROUND_TIME = 60
 
-SAVE_OVERTIME_IN_TABLE = r'C:\Users\Danny\Desktop\EnD and Investment\Tools\time_recoder\time_recorded_tables\overtime_danny.xlsx'
+SAVE_OVERTIME_IN_TABLE = WORKTIME_TABLE_PATH / OVERTIME_TABLE_NAME[USER]
 
-docx_output_dir_path = r'C:\Users\Danny\Desktop\EnD and Investment\Tools\fast_excel_to_bill\test_folder'# Variable cuz search of dir of customer can be implemeted
+docx_output_dir_path = GLOBAL_TOOLS_DIR_PATH[SYSTEM] / Path('fast_excel_to_bill/test_folder/') # Variable cuz search of dir of customer can be implemeted
 list_of_place_holders = ['?Netto?','?zzgl.?', '?gesamt?', 'insertdate'] # variable cuz search can be implemented
 
 # Burden Date
@@ -18,5 +55,9 @@ NUMBER_OF_COLUMNS_FIRST_TABLE = len(FIRST_TABLE_KEYS)
 SECOND_TABLE_KEYS = ['KW', 'Leistungsübersicht']
 NUMBER_OF_COLUMNS_SECOND_TABLE = len(SECOND_TABLE_KEYS) # variable cuz searching of number of columns can be done
 
+
+
 # Excel Pathes
-employee_worktime_table_pathes = [r'C:\Users\Danny\Desktop\EnD and Investment\Tools\time_recoder\time_recorded_tables\work_time_danny.xlsx'] # Variable cuz search of dir of tables can be implemented
+employee_worktime_table_pathes = [#WORKTIME_TABLE_PATH / WORKTIME_TABLE_NAME['Danny'],
+                                  WORKTIME_TABLE_PATH / WORKTIME_TABLE_NAME['NokkoUbuntu'],
+                                  WORKTIME_TABLE_PATH / WORKTIME_TABLE_NAME['NokkoWindows']] # Variable cuz search of dir of tables can be implemented

+ 22 - 10
fast_excel_to_bill/main.py

@@ -1,21 +1,22 @@
 from fast_excel_to_bill.bill_doc.docx_builder import DOCFileBuilder
 from fast_excel_to_bill import config_for_custom_bills
+from fast_excel_to_bill.config_for_custom_bills import OUTPUT_MONTH, OUTPUT_YEAR
 from tool_lib import datetime_functions
 from datetime import datetime
 from fast_excel_to_bill.transform_excel_data_to_bill_data.time_recorder_format_main import main_data_collection, \
     round_worktime_for_week, add_sum_to_dict, get_task_out_of_tree
 
-payment_request_range = config_for_custom_bills.payment_request_range
-year = int(datetime_functions.datetime_to_str(datetime_functions.get_current_date(), '%Y'))
-current_month_year = datetime_functions.datetime_to_str('current', '%m_%Y')
-docx_output_path = config_for_custom_bills.docx_output_dir_path + r'\bill_{}.docx'.format(current_month_year)
+PAYMENT_REQUEST_RANGE = config_for_custom_bills.payment_request_range
+CURRENT_YEAR = int(datetime_functions.datetime_to_str(datetime_functions.get_current_date(), '%Y'))
+CURRENT_MONTH_YEAR = datetime_functions.datetime_to_str('current', '%m_%Y')
+DOCX_OUTPUT_PATH = config_for_custom_bills.docx_output_dir_path / 'bill_{}.docx'.format(CURRENT_MONTH_YEAR)
 
 
 def get_excel_data():
     # Get Data which is necessary for the docx
     bill_data_dict = main_data_collection(config_for_custom_bills.employee_worktime_table_pathes, config_for_custom_bills.LIST_OF_KEYS)
 
-    # transform data to fomat
+    # transform data to format
     bill_data_dict = round_worktime_for_week(bill_data_dict, config_for_custom_bills.SAVE_OVERTIME_IN_TABLE,
                                                         config_for_custom_bills.ROUND_TIME)
     bill_data_dict = add_sum_to_dict(bill_data_dict, config_for_custom_bills.income_per_hour)
@@ -30,8 +31,15 @@ def set_current_dates(builder_obj):
     return builder_obj
 
 
-def set_Leistungszeitraum(builder_obj):
-    last_month = datetime_functions.get_current_month_number() - 1
+def set_Leistungszeitraum(builder_obj, month: int, year: int):
+    if not 0 < month <= 12:
+        last_month = datetime_functions.get_current_month_number() - 1
+    else:
+        last_month = month
+
+    if year < 0:
+        year = CURRENT_YEAR
+
     month_range = datetime_functions.get_count_of_days_for_specific_month(year=year, month_number=last_month)
     if last_month > 9:
         start_date = '01.' + str(last_month) + '.' + str(year)
@@ -43,6 +51,10 @@ def set_Leistungszeitraum(builder_obj):
     return builder_obj
 
 
+def set_rechnungsnummer():
+    pass
+
+
 def fill_table(builder_obj, key_list, data_list):
     table = builder_obj.search_table_with_key_columns(key_list)
     builder_obj.replace_rows(table, data_list)
@@ -56,13 +68,13 @@ def main():
     bill_data_dict = get_excel_data()
 
     # Create a doc file which is based on a docx template
-    builder_obj = DOCFileBuilder(config_for_custom_bills.DOCX_INPUT_PATH, docx_output_path)
+    builder_obj = DOCFileBuilder(config_for_custom_bills.DOCX_INPUT_PATH, DOCX_OUTPUT_PATH)
 
     # Set Date of Template
     builder_obj = set_current_dates(builder_obj)
 
     # Set Leistungszeitraum
-    builder_obj = set_Leistungszeitraum(builder_obj)
+    builder_obj = set_Leistungszeitraum(builder_obj, OUTPUT_MONTH, OUTPUT_YEAR)
 
     # Table KW/Time/ sum
     data_list = []
@@ -83,7 +95,7 @@ def main():
     netto = sum([bill_data_dict[key]['Betrag'] for key in bill_data_dict.keys()])
     tax = round(netto * 0.19, 2)
     abs_amount = netto + tax
-    payment_request_date = datetime_functions.add_days_to_date(datetime_functions.get_current_date(), payment_request_range)
+    payment_request_date = datetime_functions.add_days_to_date(datetime_functions.get_current_date(), PAYMENT_REQUEST_RANGE)
     payment_request_date = datetime_functions.datetime_to_str(payment_request_date, '%d.%m.%Y')
     place_holder_replacement_list = [netto, tax, abs_amount, payment_request_date]
 

+ 50 - 2
fast_excel_to_bill/transform_excel_data_to_bill_data/time_recorder_format_main.py

@@ -1,5 +1,8 @@
+from fast_excel_to_bill.config_for_custom_bills import OUTPUT_CUSTOMER, OUTPUT_MONTH, OUTPUT_YEAR
 from tool_lib.read_table import Read_Table
 from tool_lib.create_excel_tables import CreateTable
+import numpy as np
+
 
 def add_sum_to_dict(work_time_dict, income_per_hour):
     for key in work_time_dict.keys():
@@ -38,14 +41,13 @@ def round_worktime_for_week(work_time_dict,overtime_table_path, round_time = 300
     save_overtime_in_excel(overtime_dict,overtime_table_path)
     return work_time_dict
 
+
 def get_task_out_of_tree(work_time_dict):
     for key in work_time_dict.keys():
         work_time_dict[key]['Task'] = ['-   ' + last_branch[last_branch.rfind('/')+1:] for last_branch in work_time_dict[key]['Task']]
     return work_time_dict
 
 
-
-
 def compress_data_by_key_list(*compressable_lists, key_list):
     '''
     function: a list containing different Values, if a Value is more than one time
@@ -101,6 +103,26 @@ def main_data_collection(pathes, list_of_keys=['Arbeitszeit', 'Task']):
             read_table_object = Read_Table(path)
             table_object = read_table_object.table_to_dict()
 
+            # Filter Data
+            customer_filter_value_indices = []
+            for task_value_idx in range(len(table_object['Task'])):
+                task_value = table_object['Task'][task_value_idx]
+                if task_value.startswith('root/' + OUTPUT_CUSTOMER):
+                    customer_filter_value_indices.append(task_value_idx)
+            if OUTPUT_MONTH > 9:
+                date_filter = str(OUTPUT_MONTH) + '/' + str(OUTPUT_YEAR)
+            else:
+                date_filter = '0' + str(OUTPUT_MONTH) + '/' + str(OUTPUT_YEAR)
+            date_filter_value_indices = []
+            for date_value_idx in range(len(table_object['Datum'])):
+                date_value = table_object['Datum'][date_value_idx]
+                if date_value.endswith(date_filter):
+                    date_filter_value_indices.append(date_value_idx)
+            customer_and_date_filtered_indices = list(set(customer_filter_value_indices) & set(date_filter_value_indices))
+
+            for key in table_object:
+                table_object[key] = [table_object[key][idx] for idx in customer_and_date_filtered_indices]
+
             # Calendar Week
             calendar_weeks_list = table_object['Kalenderwoche']
 
@@ -119,6 +141,9 @@ def main_data_collection(pathes, list_of_keys=['Arbeitszeit', 'Task']):
             # Compress Data by Calendar week
             for key in key_dict.keys():
                 all_weeks = compress_data_by_key_list(key_dict[key], key_list=calendar_weeks_list)
+                if key == 'Task':
+                    for idx in range(len(all_weeks)):
+                        all_weeks[idx] = list(set(all_weeks[idx]))
                 for week_indx, week in enumerate(list(set(calendar_weeks_list))):
                     if c == 0:
                         week_keys_to_list_of_keys_dict[week][key] = all_weeks[week_indx]
@@ -135,6 +160,26 @@ def main_data_collection(pathes, list_of_keys=['Arbeitszeit', 'Task']):
         # Calendar Week
         calendar_weeks_list = table_object['Kalenderwoche']
 
+        # Filter Data
+        customer_filter_value_indices = []
+        for task_value_idx in range(len(table_object['Task'])):
+            task_value = table_object['Task'][task_value_idx]
+            if task_value.startswith('root/' + OUTPUT_CUSTOMER):
+                customer_filter_value_indices.append(task_value_idx)
+        if OUTPUT_MONTH > 9:
+            date_filter = str(OUTPUT_MONTH) + '/' + str(OUTPUT_YEAR)
+        else:
+            date_filter = '0' + str(OUTPUT_MONTH) + '/' + str(OUTPUT_YEAR)
+        date_filter_value_indices = []
+        for date_value_idx in range(len(table_object['Datum'])):
+            date_value = table_object['Datum'][date_value_idx]
+            if date_value.endswith(date_filter):
+                date_filter_value_indices.append(date_value_idx)
+        customer_and_date_filtered_indices = list(set(customer_filter_value_indices) & set(date_filter_value_indices))
+
+        for key in table_object:
+            table_object[key] = [table_object[key][idx] for idx in customer_and_date_filtered_indices]
+
         # Add new Weeks to dict
         for week in list(set(calendar_weeks_list)):
             if week in week_keys_to_list_of_keys_dict:
@@ -151,6 +196,9 @@ def main_data_collection(pathes, list_of_keys=['Arbeitszeit', 'Task']):
         compressed_lists = []
         for key in key_dict.keys():
             all_weeks = compress_data_by_key_list(key_dict[key], key_list=calendar_weeks_list)
+            if key == 'Task':
+                for idx in range(len(all_weeks)):
+                    all_weeks[idx] = list(set(all_weeks[idx]))
             for week_indx, week in enumerate(list(set(calendar_weeks_list))):
                 week_keys_to_list_of_keys_dict[week][key] = all_weeks[week_indx]