main.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from fast_excel_to_bill.bill_doc.docx_builder import DOCFileBuilder
  2. from fast_excel_to_bill import config_for_custom_bills
  3. from tool_lib import datetime_functions
  4. from datetime import datetime
  5. payment_request_range = config_for_custom_bills.payment_request_range
  6. year = int(datetime_functions.datetime_to_str(datetime_functions.get_current_date(), '%Y'))
  7. current_month_year= datetime_functions.datetime_to_str('current', '%m_%Y')
  8. docx_output_path = config_for_custom_bills.docx_output_dir_path+ r'\bill_{}.docx'.format(current_month_year)
  9. def main():
  10. # Get Data which is necessary for the docx
  11. # data_from_excel = ...
  12. payment_request_date = datetime_functions.add_days_to_date(datetime_functions.get_current_date(),payment_request_range)
  13. payment_request_date = datetime_functions.datetime_to_str(payment_request_date, '%d.%m.%Y')
  14. # data_from_excel.append(payment_request_date)
  15. # Create a doc file which is based on a docx template
  16. builder_obj = DOCFileBuilder(config_for_custom_bills.docx_input_path, docx_output_path)
  17. # Set Date of Template
  18. current_date = datetime_functions.datetime_to_str(datetime_functions.get_current_date(), '%d.%m.%Y')
  19. builder_obj.replace_dates_string_in_standard_text(current_date)
  20. builder_obj.replace_dates_string_in_all_tables(current_date)
  21. # Set Leistungszeitraum
  22. last_month = datetime_functions.get_current_month_number()-1
  23. month_range = datetime_functions.get_count_of_days_for_specific_month(year=year, month_number=last_month)
  24. if last_month>9:
  25. start_date = '01.'+ str(last_month) +'.'+ str(year)
  26. else:
  27. start_date = '01.' + '0' + str(last_month) + '.' + str(year)
  28. end_date = datetime_functions.add_days_to_date(datetime.strptime(start_date,'%d.%m.%Y'), month_range-1)
  29. end_date = datetime_functions.datetime_to_str(end_date, '%d.%m.%Y')
  30. builder_obj.replace_Leistungszeitraum(start_date, end_date)
  31. builder_obj.save_docx()
  32. # Replace Placeholders
  33. # place_holders = config_for_custom_bills.list_of_place_holders
  34. # for place_holder in place_holders:
  35. # builder_obj.replace_custom_placeholder_in_doc(place_holder, data_from_excel)
  36. # keys = ['KW', 'Leistung', 'Zeit in Stunden', 'Betrag in Euro']
  37. # example_tuple = [(123123, 213123, 12312312, 445235)]
  38. # key_table = builder_obj.search_table_with_key_columns(keys)
  39. # builder_obj.replace_rows(key_table, example_tuple)
  40. # builder_obj.delete_empty_rows_in_table(key_table, 4)
  41. # builder_obj.document.add_page_break()
  42. # key_table = builder_obj.search_table_with_key_columns(['KW', 'Leistungsübersicht'])
  43. # builder_obj.delete_empty_rows_in_table(key_table, 2)
  44. data_to_bill_doc = ...
  45. # Transform the doc file to a pdf file
  46. doc_to_pdf = ...
  47. if __name__ == '__main__':
  48. main()