ERP_Preprocessor / utils /reporting_utils.py
hariqueen's picture
Update utils/reporting_utils.py
675697a verified
"""
๋ณด๊ณ ์„œ ์ƒ์„ฑ ๋ฐ ์š”์•ฝ ๊ด€๋ จ ์œ ํ‹ธ๋ฆฌํ‹ฐ
"""
from typing import Dict, Any
import pandas as pd
def print_data_summary(summary: Dict[str, Any], company_config: Dict[str, Any]) -> None:
"""
๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ ์š”์•ฝ ์ถœ๋ ฅ
Args:
summary: ๋ฐ์ดํ„ฐ ์š”์•ฝ ์ •๋ณด
company_config: ๋ Œํƒˆ์‚ฌ ์„ค์ • ์ •๋ณด
"""
total_count = summary['total_count']
total_amount = summary['total_amount']
account_counts = summary['account_counts']
mapping_summary = summary['mapping_summary']
print(f"\n์ด ์ฒ˜๋ฆฌ ๊ฑด์ˆ˜: {total_count + 1}๊ฑด (์ฐจ๋ณ€ {total_count}๊ฑด, ๋Œ€๋ณ€ 1๊ฑด)")
print(f"์ด ๊ธˆ์•ก: {total_amount:,.0f}์›")
print(f"์ฐจ๋ณ€ ๊ณ„์ •: {len(account_counts)}๊ฐœ ๊ณ„์ • ์‚ฌ์šฉ")
print(f"๋Œ€๋ณ€ ๊ณ„์ •: {company_config['payable_acct']} (๋ฏธ์ง€๊ธ‰๊ธˆ) 1๊ฐœ ๊ณ„์ • ์‚ฌ์šฉ")
# ๊ด€๋ฆฌํ•ญ๋ชฉ ์„ค์ • ๋‚ด์šฉ ์ถœ๋ ฅ
print("\n๊ด€๋ฆฌํ•ญ๋ชฉ ์„ค์ • ์ •๋ณด:")
print(f"- CD_CC (์ฝ”์ŠคํŠธ์„ผํ„ฐ): {company_config['cost_center']} (๊ณ ์ •)")
print(f"- CD_PARTNER (๊ฑฐ๋ž˜์ฒ˜์ฝ”๋“œ): {company_config['partner_code']} (๊ณ ์ •)")
print(f"- CD_PJT (ํ”„๋กœ์ ํŠธ์ฝ”๋“œ): ๊ฐ ํŒ€๋ณ„ ๋งคํ•‘๋œ ์ฝ”๋“œ ์‚ฌ์šฉ")
# ๋งคํ•‘ ์ •๋ณด ์š”์•ฝ
print("\n๋งคํ•‘ ์„ฑ๊ณต ํŒ€๋ช…:")
mapped_teams = mapping_summary['mapped_teams']
for idx, team in enumerate(mapped_teams[:10]):
if len(mapped_teams) > 10 and idx == 9:
print(f"- {team['original']} ... ์™ธ {len(mapped_teams)-10}๊ฐœ")
else:
print(f"- {team['original']} -> {team['mapped']} (ACCT: {team['acct']}, PJT: {team['pjt']})")
def generate_report_file(summary: Dict[str, Any], erp_df: pd.DataFrame, report_file: str) -> None:
"""
์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ ๋ณด๊ณ ์„œ ํŒŒ์ผ ์ƒ์„ฑ
Args:
summary: ๋ฐ์ดํ„ฐ ์š”์•ฝ ์ •๋ณด
erp_df: ERP ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„
report_file: ๋ณด๊ณ ์„œ ํŒŒ์ผ ๊ฒฝ๋กœ
"""
with open(report_file, 'w', encoding='utf-8') as f:
f.write("# ERP ์ „ํ‘œ ์ƒ์„ฑ ๊ฒฐ๊ณผ ๋ณด๊ณ ์„œ\n\n")
# ๊ธฐ๋ณธ ์ •๋ณด
f.write("## 1. ๊ธฐ๋ณธ ์ •๋ณด\n")
f.write(f"- ์ƒ์„ฑ ์ผ์‹œ: {pd.Timestamp.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
f.write(f"- ์ฒ˜๋ฆฌ ๊ฑด์ˆ˜: ์ฐจ๋ณ€ {summary['total_count']}๊ฑด, ๋Œ€๋ณ€ 1๊ฑด\n")
f.write(f"- ์ด ๊ธˆ์•ก: {summary['total_amount']:,.0f}์›\n\n")
# ๊ณ„์ • ๋ถ„ํฌ
f.write("## 2. ๊ณ„์ • ์ฝ”๋“œ๋ณ„ ์‚ฌ์šฉ ํ˜„ํ™ฉ\n")
for acct, count in summary['account_counts'].items():
f.write(f"- {acct}: {count}๊ฑด\n")
f.write("\n")
# ํŒ€๋ณ„ ๋ถ„ํฌ
f.write("## 3. ํŒ€๋ณ„ ๋งคํ•‘ ์ •๋ณด\n")
for team in summary['mapping_summary']['mapped_teams']:
f.write(f"- {team['original']} -> {team['mapped']} (๊ณ„์ •: {team['acct']}, ํ”„๋กœ์ ํŠธ: {team['pjt']})\n")
f.write("\n## 4. ์ „ํ‘œ ์ฃผ์š” ์ •๋ณด\n")
# ์ฐจ๋ณ€ ํ–‰ ์ •๋ณด
debit_rows = erp_df[erp_df["TP_DRCR"] == "1"]
f.write(f"- ์ฐจ๋ณ€ ๊ฑด์ˆ˜: {len(debit_rows)}๊ฑด\n")
f.write(f"- ์ฐจ๋ณ€ ๊ณ„์ •: {len(debit_rows['CD_ACCT'].unique())}๊ฐœ ๊ณ„์ • ์‚ฌ์šฉ\n")
# ๋Œ€๋ณ€ ํ–‰ ์ •๋ณด
credit_rows = erp_df[erp_df["TP_DRCR"] == "2"]
f.write(f"- ๋Œ€๋ณ€ ๊ฑด์ˆ˜: {len(credit_rows)}๊ฑด\n")
f.write(f"- ๋Œ€๋ณ€ ๊ณ„์ •: {credit_rows['CD_ACCT'].iloc[0]} (๋ฏธ์ง€๊ธ‰๊ธˆ)\n")
# ์ „ํ‘œ ๋ฒˆํ˜ธ ์ •๋ณด
f.write(f"- ์ „ํ‘œ ๋ฒˆํ˜ธ: {erp_df['NO_DOCU'].iloc[0]}\n")
print(f"\n์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ ๋ณด๊ณ ์„œ๊ฐ€ '{report_file}'์— ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")