|
@@ -2,56 +2,95 @@ 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 import config_for_custom_bills
|
|
from tool_lib import datetime_functions
|
|
from tool_lib import datetime_functions
|
|
from datetime import datetime
|
|
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
|
|
payment_request_range = config_for_custom_bills.payment_request_range
|
|
year = int(datetime_functions.datetime_to_str(datetime_functions.get_current_date(), '%Y'))
|
|
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)
|
|
|
|
|
|
+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)
|
|
|
|
|
|
|
|
|
|
-def main():
|
|
|
|
|
|
+def get_excel_data():
|
|
# Get Data which is necessary for the docx
|
|
# Get Data which is necessary for the docx
|
|
- # data_from_excel = ...
|
|
|
|
- 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')
|
|
|
|
- # data_from_excel.append(payment_request_date)
|
|
|
|
|
|
+ bill_data_dict = main_data_collection(config_for_custom_bills.employee_worktime_table_pathes, config_for_custom_bills.LIST_OF_KEYS)
|
|
|
|
|
|
- # Create a doc file which is based on a docx template
|
|
|
|
- builder_obj = DOCFileBuilder(config_for_custom_bills.docx_input_path, docx_output_path)
|
|
|
|
|
|
+ # transform data to fomat
|
|
|
|
+ bill_data_dict, over_time = round_worktime_for_week(bill_data_dict, config_for_custom_bills.ROUND_TIME)
|
|
|
|
+ bill_data_dict = add_sum_to_dict(bill_data_dict, config_for_custom_bills.income_per_hour)
|
|
|
|
+ bill_data_dict = get_task_out_of_tree(bill_data_dict)
|
|
|
|
+ return bill_data_dict
|
|
|
|
|
|
- # Set Date of Template
|
|
|
|
|
|
+
|
|
|
|
+def set_current_dates(builder_obj):
|
|
current_date = datetime_functions.datetime_to_str(datetime_functions.get_current_date(), '%d.%m.%Y')
|
|
current_date = datetime_functions.datetime_to_str(datetime_functions.get_current_date(), '%d.%m.%Y')
|
|
builder_obj.replace_dates_string_in_standard_text(current_date)
|
|
builder_obj.replace_dates_string_in_standard_text(current_date)
|
|
builder_obj.replace_dates_string_in_all_tables(current_date)
|
|
builder_obj.replace_dates_string_in_all_tables(current_date)
|
|
|
|
+ return builder_obj
|
|
|
|
|
|
- # Set Leistungszeitraum
|
|
|
|
- last_month = datetime_functions.get_current_month_number()-1
|
|
|
|
|
|
+
|
|
|
|
+def set_Leistungszeitraum(builder_obj):
|
|
|
|
+ last_month = datetime_functions.get_current_month_number() - 1
|
|
month_range = datetime_functions.get_count_of_days_for_specific_month(year=year, month_number=last_month)
|
|
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)
|
|
|
|
|
|
+ if last_month > 9:
|
|
|
|
+ start_date = '01.' + str(last_month) + '.' + str(year)
|
|
else:
|
|
else:
|
|
start_date = '01.' + '0' + str(last_month) + '.' + str(year)
|
|
start_date = '01.' + '0' + str(last_month) + '.' + str(year)
|
|
- end_date = datetime_functions.add_days_to_date(datetime.strptime(start_date,'%d.%m.%Y'), month_range-1)
|
|
|
|
|
|
+ end_date = datetime_functions.add_days_to_date(datetime.strptime(start_date, '%d.%m.%Y'), month_range - 1)
|
|
end_date = datetime_functions.datetime_to_str(end_date, '%d.%m.%Y')
|
|
end_date = datetime_functions.datetime_to_str(end_date, '%d.%m.%Y')
|
|
builder_obj.replace_Leistungszeitraum(start_date, end_date)
|
|
builder_obj.replace_Leistungszeitraum(start_date, end_date)
|
|
- builder_obj.save_docx()
|
|
|
|
|
|
+ return builder_obj
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+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)
|
|
|
|
+ builder_obj.delete_empty_rows_in_table(table, config_for_custom_bills.NUMBER_OF_COLUMNS_FIRST_TABLE)
|
|
|
|
+ return builder_obj
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def main():
|
|
|
|
+ # Get Data
|
|
|
|
+
|
|
|
|
+ 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)
|
|
|
|
+
|
|
|
|
+ # Set Date of Template
|
|
|
|
+ builder_obj = set_current_dates(builder_obj)
|
|
|
|
+
|
|
|
|
+ # Set Leistungszeitraum
|
|
|
|
+ builder_obj = set_Leistungszeitraum(builder_obj)
|
|
|
|
+
|
|
|
|
+ # Table KW/Time/ sum
|
|
|
|
+ data_list = []
|
|
|
|
+ for key in bill_data_dict.keys():
|
|
|
|
+ data_list += [(key, bill_data_dict[key][config_for_custom_bills.LIST_OF_KEYS[0]], bill_data_dict[key]['Betrag'])]
|
|
|
|
+
|
|
|
|
+ builder_obj = fill_table(builder_obj, config_for_custom_bills.FIRST_TABLE_KEYS, data_list)
|
|
|
|
+
|
|
|
|
+ # Table KW and Task
|
|
|
|
+ data_list = []
|
|
|
|
+ for key in bill_data_dict.keys():
|
|
|
|
+ data_list += [(key, bill_data_dict[key][config_for_custom_bills.LIST_OF_KEYS[1]])]
|
|
|
|
+
|
|
|
|
+ builder_obj = fill_table(builder_obj, config_for_custom_bills.SECOND_TABLE_KEYS, data_list)
|
|
|
|
+
|
|
# Replace Placeholders
|
|
# Replace Placeholders
|
|
- # place_holders = config_for_custom_bills.list_of_place_holders
|
|
|
|
- # for place_holder in place_holders:
|
|
|
|
- # builder_obj.replace_custom_placeholder_in_doc(place_holder, data_from_excel)
|
|
|
|
-
|
|
|
|
- # keys = ['KW', 'Leistung', 'Zeit in Stunden', 'Betrag in Euro']
|
|
|
|
- # example_tuple = [(123123, 213123, 12312312, 445235)]
|
|
|
|
- # key_table = builder_obj.search_table_with_key_columns(keys)
|
|
|
|
- # builder_obj.replace_rows(key_table, example_tuple)
|
|
|
|
- # builder_obj.delete_empty_rows_in_table(key_table, 4)
|
|
|
|
- # builder_obj.document.add_page_break()
|
|
|
|
- # key_table = builder_obj.search_table_with_key_columns(['KW', 'Leistungsübersicht'])
|
|
|
|
- # builder_obj.delete_empty_rows_in_table(key_table, 2)
|
|
|
|
- data_to_bill_doc = ...
|
|
|
|
-
|
|
|
|
- # Transform the doc file to a pdf file
|
|
|
|
- doc_to_pdf = ...
|
|
|
|
|
|
+
|
|
|
|
+ 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.datetime_to_str(payment_request_date, '%d.%m.%Y')
|
|
|
|
+ place_holder_replacement_list = [netto, tax, abs_amount, payment_request_date]
|
|
|
|
+
|
|
|
|
+ place_holders = config_for_custom_bills.list_of_place_holders
|
|
|
|
+ for count, place_holder in enumerate(place_holders):
|
|
|
|
+ builder_obj.replace_custom_placeholder_in_doc(place_holder, str(place_holder_replacement_list[count]))
|
|
|
|
+
|
|
|
|
+ builder_obj.save_docx()
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|