Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,15 +1,12 @@
|
|
| 1 |
-
"""
|
| 2 |
-
ERP μλ μ ν μμ± λ©μΈ μ€ν νμΌ
|
| 3 |
-
"""
|
| 4 |
import os
|
| 5 |
import argparse
|
| 6 |
from datetime import datetime
|
| 7 |
-
|
| 8 |
-
import
|
| 9 |
-
import
|
| 10 |
-
import
|
| 11 |
-
import
|
| 12 |
-
import
|
| 13 |
import pandas as pd
|
| 14 |
from pyexcel_xls import save_data
|
| 15 |
from collections import OrderedDict
|
|
@@ -22,11 +19,11 @@ def process_rental_company(company_name: str):
|
|
| 22 |
Args:
|
| 23 |
company_name: μ²λ¦¬ν λ νμ¬ μ΄λ¦
|
| 24 |
"""
|
| 25 |
-
if company_name not in
|
| 26 |
print(f"μ€λ₯: '{company_name}' λ νμ¬ μ€μ μ μ°Ύμ μ μμ΅λλ€.")
|
| 27 |
return
|
| 28 |
|
| 29 |
-
company_config =
|
| 30 |
print(f"'{company_name}' λ νμ¬ λ°μ΄ν° μ²λ¦¬ μμ...")
|
| 31 |
|
| 32 |
input_file = company_config['input_file']
|
|
@@ -34,21 +31,21 @@ def process_rental_company(company_name: str):
|
|
| 34 |
erp_form_file = company_config['erp_form_file']
|
| 35 |
output_csv = company_config['output_csv']
|
| 36 |
output_excel = company_config['output_excel']
|
| 37 |
-
report_file = os.path.join(
|
| 38 |
|
| 39 |
-
mapping_dict =
|
| 40 |
-
df, df_filtered =
|
| 41 |
-
summary =
|
| 42 |
-
erp_df =
|
| 43 |
-
erp_df =
|
| 44 |
-
erp_df =
|
| 45 |
|
| 46 |
-
erp_form =
|
| 47 |
-
result_df =
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
#
|
| 52 |
|
| 53 |
print(f"\n'{company_name}' λ νμ¬ λ°μ΄ν° μ²λ¦¬ μλ£.")
|
| 54 |
|
|
@@ -70,19 +67,19 @@ def process_rental_company_with_voucher(uploaded_file_path, voucher_number, empl
|
|
| 70 |
raise ValueError("μ¬μλ²νΈλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ. μ¬μλ²νΈλ νμ μ
λ ₯κ°μ
λλ€.")
|
| 71 |
|
| 72 |
company_name = "νκ΅λ ν"
|
| 73 |
-
company_config =
|
| 74 |
|
| 75 |
# μ¬μλ²νΈ μ€μ - μ
λ ₯λ κ° μ¬μ©
|
| 76 |
company_config['id_write'] = employee_number.strip()
|
| 77 |
|
| 78 |
mapping_file = company_config['mapping_file']
|
| 79 |
-
mapping_dict =
|
| 80 |
|
| 81 |
-
df, df_filtered =
|
| 82 |
-
summary =
|
| 83 |
-
erp_df =
|
| 84 |
-
erp_df =
|
| 85 |
-
erp_df =
|
| 86 |
|
| 87 |
# μ νλ²νΈ μ±μλ£κΈ°
|
| 88 |
if 'ROW_ID' in erp_df.columns:
|
|
@@ -91,22 +88,18 @@ def process_rental_company_with_voucher(uploaded_file_path, voucher_number, empl
|
|
| 91 |
erp_df['NO_DOCU'] = voucher_number
|
| 92 |
|
| 93 |
# ERP μμ λ‘λ
|
| 94 |
-
erp_form =
|
| 95 |
|
| 96 |
# ERP μμμ λ§μΆ°μ λ°μ΄ν° μ€λΉ
|
| 97 |
-
result_df =
|
| 98 |
|
| 99 |
# μ μ₯
|
| 100 |
output_filename = f"μλμ ν_μμ±νμΌ_{datetime.now().strftime('%Y%m%d')}.xls"
|
| 101 |
-
output_path = os.path.join(
|
| 102 |
|
| 103 |
-
os.makedirs(
|
| 104 |
|
| 105 |
try:
|
| 106 |
-
# pyexcel_xlsμ OrderedDict λͺ¨λ μν¬νΈ
|
| 107 |
-
from pyexcel_xls import save_data
|
| 108 |
-
from collections import OrderedDict
|
| 109 |
-
|
| 110 |
# λ°μ΄ν°νλ μμ 리μ€νΈλ‘ λ³ν
|
| 111 |
headers = result_df.columns.tolist()
|
| 112 |
data = [headers] # ν€λλ₯Ό 첫 λ²μ§Έ νμΌλ‘ μΆκ°
|
|
@@ -146,7 +139,7 @@ def main():
|
|
| 146 |
args = parser.parse_args()
|
| 147 |
|
| 148 |
if args.all:
|
| 149 |
-
for company_name in
|
| 150 |
process_rental_company(company_name)
|
| 151 |
print('-' * 80)
|
| 152 |
elif args.company:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import argparse
|
| 3 |
from datetime import datetime
|
| 4 |
+
from core.config import RENTAL_COMPANIES, OUTPUT_DIR
|
| 5 |
+
from mappers.mapping_utils import load_mapping_file
|
| 6 |
+
from processors.rental_processor import load_and_preprocess_data, summarize_data
|
| 7 |
+
from generators.korea_rental_gen import generate_erp_data, prepare_erp_columns, set_management_items
|
| 8 |
+
from utils.file_handler import load_erp_form_template, prepare_file_with_template, save_to_files
|
| 9 |
+
from utils.reporter import print_data_summary
|
| 10 |
import pandas as pd
|
| 11 |
from pyexcel_xls import save_data
|
| 12 |
from collections import OrderedDict
|
|
|
|
| 19 |
Args:
|
| 20 |
company_name: μ²λ¦¬ν λ νμ¬ μ΄λ¦
|
| 21 |
"""
|
| 22 |
+
if company_name not in RENTAL_COMPANIES:
|
| 23 |
print(f"μ€λ₯: '{company_name}' λ νμ¬ μ€μ μ μ°Ύμ μ μμ΅λλ€.")
|
| 24 |
return
|
| 25 |
|
| 26 |
+
company_config = RENTAL_COMPANIES[company_name]
|
| 27 |
print(f"'{company_name}' λ νμ¬ λ°μ΄ν° μ²λ¦¬ μμ...")
|
| 28 |
|
| 29 |
input_file = company_config['input_file']
|
|
|
|
| 31 |
erp_form_file = company_config['erp_form_file']
|
| 32 |
output_csv = company_config['output_csv']
|
| 33 |
output_excel = company_config['output_excel']
|
| 34 |
+
report_file = os.path.join(OUTPUT_DIR, f'λ³΄κ³ μ_{company_name}_{datetime.now().strftime("%Y%m%d")}.txt')
|
| 35 |
|
| 36 |
+
mapping_dict = load_mapping_file(mapping_file)
|
| 37 |
+
df, df_filtered = load_and_preprocess_data(input_file, company_config, mapping_dict)
|
| 38 |
+
summary = summarize_data(df_filtered, mapping_dict)
|
| 39 |
+
erp_df = generate_erp_data(df_filtered, company_config)
|
| 40 |
+
erp_df = prepare_erp_columns(erp_df)
|
| 41 |
+
erp_df = set_management_items(erp_df, df_filtered, company_config)
|
| 42 |
|
| 43 |
+
erp_form = load_erp_form_template(erp_form_file)
|
| 44 |
+
result_df = prepare_file_with_template(erp_df, erp_form)
|
| 45 |
|
| 46 |
+
save_to_files(result_df, output_csv, output_excel, len(erp_df))
|
| 47 |
+
print_data_summary(summary, company_config)
|
| 48 |
+
# generate_report_file(summary, erp_df, report_file)
|
| 49 |
|
| 50 |
print(f"\n'{company_name}' λ νμ¬ λ°μ΄ν° μ²λ¦¬ μλ£.")
|
| 51 |
|
|
|
|
| 67 |
raise ValueError("μ¬μλ²νΈλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ. μ¬μλ²νΈλ νμ μ
λ ₯κ°μ
λλ€.")
|
| 68 |
|
| 69 |
company_name = "νκ΅λ ν"
|
| 70 |
+
company_config = RENTAL_COMPANIES[company_name].copy() # μ€μ μ 볡μ¬ν΄μ μ¬μ©
|
| 71 |
|
| 72 |
# μ¬μλ²νΈ μ€μ - μ
λ ₯λ κ° μ¬μ©
|
| 73 |
company_config['id_write'] = employee_number.strip()
|
| 74 |
|
| 75 |
mapping_file = company_config['mapping_file']
|
| 76 |
+
mapping_dict = load_mapping_file(mapping_file)
|
| 77 |
|
| 78 |
+
df, df_filtered = load_and_preprocess_data(uploaded_file_path, company_config, mapping_dict)
|
| 79 |
+
summary = summarize_data(df_filtered, mapping_dict)
|
| 80 |
+
erp_df = generate_erp_data(df_filtered, company_config)
|
| 81 |
+
erp_df = prepare_erp_columns(erp_df)
|
| 82 |
+
erp_df = set_management_items(erp_df, df_filtered, company_config)
|
| 83 |
|
| 84 |
# μ νλ²νΈ μ±μλ£κΈ°
|
| 85 |
if 'ROW_ID' in erp_df.columns:
|
|
|
|
| 88 |
erp_df['NO_DOCU'] = voucher_number
|
| 89 |
|
| 90 |
# ERP μμ λ‘λ
|
| 91 |
+
erp_form = load_erp_form_template(company_config['erp_form_file'])
|
| 92 |
|
| 93 |
# ERP μμμ λ§μΆ°μ λ°μ΄ν° μ€λΉ
|
| 94 |
+
result_df = prepare_file_with_template(erp_df, erp_form)
|
| 95 |
|
| 96 |
# μ μ₯
|
| 97 |
output_filename = f"μλμ ν_μμ±νμΌ_{datetime.now().strftime('%Y%m%d')}.xls"
|
| 98 |
+
output_path = os.path.join(OUTPUT_DIR, output_filename)
|
| 99 |
|
| 100 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 101 |
|
| 102 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
# λ°μ΄ν°νλ μμ 리μ€νΈλ‘ λ³ν
|
| 104 |
headers = result_df.columns.tolist()
|
| 105 |
data = [headers] # ν€λλ₯Ό 첫 λ²μ§Έ νμΌλ‘ μΆκ°
|
|
|
|
| 139 |
args = parser.parse_args()
|
| 140 |
|
| 141 |
if args.all:
|
| 142 |
+
for company_name in RENTAL_COMPANIES.keys():
|
| 143 |
process_rental_company(company_name)
|
| 144 |
print('-' * 80)
|
| 145 |
elif args.company:
|