hariqueen commited on
Commit
675697a
ยท
verified ยท
1 Parent(s): b2b08ea

Update utils/reporting_utils.py

Browse files
Files changed (1) hide show
  1. utils/reporting_utils.py +83 -0
utils/reporting_utils.py CHANGED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ๋ณด๊ณ ์„œ ์ƒ์„ฑ ๋ฐ ์š”์•ฝ ๊ด€๋ จ ์œ ํ‹ธ๋ฆฌํ‹ฐ
3
+ """
4
+ from typing import Dict, Any
5
+ import pandas as pd
6
+
7
+ def print_data_summary(summary: Dict[str, Any], company_config: Dict[str, Any]) -> None:
8
+ """
9
+ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ ์š”์•ฝ ์ถœ๋ ฅ
10
+
11
+ Args:
12
+ summary: ๋ฐ์ดํ„ฐ ์š”์•ฝ ์ •๋ณด
13
+ company_config: ๋ Œํƒˆ์‚ฌ ์„ค์ • ์ •๋ณด
14
+ """
15
+ total_count = summary['total_count']
16
+ total_amount = summary['total_amount']
17
+ account_counts = summary['account_counts']
18
+ mapping_summary = summary['mapping_summary']
19
+
20
+ print(f"\n์ด ์ฒ˜๋ฆฌ ๊ฑด์ˆ˜: {total_count + 1}๊ฑด (์ฐจ๋ณ€ {total_count}๊ฑด, ๋Œ€๋ณ€ 1๊ฑด)")
21
+ print(f"์ด ๊ธˆ์•ก: {total_amount:,.0f}์›")
22
+ print(f"์ฐจ๋ณ€ ๊ณ„์ •: {len(account_counts)}๊ฐœ ๊ณ„์ • ์‚ฌ์šฉ")
23
+ print(f"๋Œ€๋ณ€ ๊ณ„์ •: {company_config['payable_acct']} (๋ฏธ์ง€๊ธ‰๊ธˆ) 1๊ฐœ ๊ณ„์ • ์‚ฌ์šฉ")
24
+
25
+ # ๊ด€๋ฆฌํ•ญ๋ชฉ ์„ค์ • ๋‚ด์šฉ ์ถœ๋ ฅ
26
+ print("\n๊ด€๋ฆฌํ•ญ๋ชฉ ์„ค์ • ์ •๋ณด:")
27
+ print(f"- CD_CC (์ฝ”์ŠคํŠธ์„ผํ„ฐ): {company_config['cost_center']} (๊ณ ์ •)")
28
+ print(f"- CD_PARTNER (๊ฑฐ๋ž˜์ฒ˜์ฝ”๋“œ): {company_config['partner_code']} (๊ณ ์ •)")
29
+ print(f"- CD_PJT (ํ”„๋กœ์ ํŠธ์ฝ”๋“œ): ๊ฐ ํŒ€๋ณ„ ๋งคํ•‘๋œ ์ฝ”๋“œ ์‚ฌ์šฉ")
30
+
31
+ # ๋งคํ•‘ ์ •๋ณด ์š”์•ฝ
32
+ print("\n๋งคํ•‘ ์„ฑ๊ณต ํŒ€๋ช…:")
33
+ mapped_teams = mapping_summary['mapped_teams']
34
+ for idx, team in enumerate(mapped_teams[:10]):
35
+ if len(mapped_teams) > 10 and idx == 9:
36
+ print(f"- {team['original']} ... ์™ธ {len(mapped_teams)-10}๊ฐœ")
37
+ else:
38
+ print(f"- {team['original']} -> {team['mapped']} (ACCT: {team['acct']}, PJT: {team['pjt']})")
39
+
40
+ def generate_report_file(summary: Dict[str, Any], erp_df: pd.DataFrame, report_file: str) -> None:
41
+ """
42
+ ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ ๋ณด๊ณ ์„œ ํŒŒ์ผ ์ƒ์„ฑ
43
+
44
+ Args:
45
+ summary: ๋ฐ์ดํ„ฐ ์š”์•ฝ ์ •๋ณด
46
+ erp_df: ERP ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„
47
+ report_file: ๋ณด๊ณ ์„œ ํŒŒ์ผ ๊ฒฝ๋กœ
48
+ """
49
+ with open(report_file, 'w', encoding='utf-8') as f:
50
+ f.write("# ERP ์ „ํ‘œ ์ƒ์„ฑ ๊ฒฐ๊ณผ ๋ณด๊ณ ์„œ\n\n")
51
+
52
+ # ๊ธฐ๋ณธ ์ •๋ณด
53
+ f.write("## 1. ๊ธฐ๋ณธ ์ •๋ณด\n")
54
+ f.write(f"- ์ƒ์„ฑ ์ผ์‹œ: {pd.Timestamp.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
55
+ f.write(f"- ์ฒ˜๋ฆฌ ๊ฑด์ˆ˜: ์ฐจ๋ณ€ {summary['total_count']}๊ฑด, ๋Œ€๋ณ€ 1๊ฑด\n")
56
+ f.write(f"- ์ด ๊ธˆ์•ก: {summary['total_amount']:,.0f}์›\n\n")
57
+
58
+ # ๊ณ„์ • ๋ถ„ํฌ
59
+ f.write("## 2. ๊ณ„์ • ์ฝ”๋“œ๋ณ„ ์‚ฌ์šฉ ํ˜„ํ™ฉ\n")
60
+ for acct, count in summary['account_counts'].items():
61
+ f.write(f"- {acct}: {count}๊ฑด\n")
62
+ f.write("\n")
63
+
64
+ # ํŒ€๋ณ„ ๋ถ„ํฌ
65
+ f.write("## 3. ํŒ€๋ณ„ ๋งคํ•‘ ์ •๋ณด\n")
66
+ for team in summary['mapping_summary']['mapped_teams']:
67
+ f.write(f"- {team['original']} -> {team['mapped']} (๊ณ„์ •: {team['acct']}, ํ”„๋กœ์ ํŠธ: {team['pjt']})\n")
68
+
69
+ f.write("\n## 4. ์ „ํ‘œ ์ฃผ์š” ์ •๋ณด\n")
70
+ # ์ฐจ๋ณ€ ํ–‰ ์ •๋ณด
71
+ debit_rows = erp_df[erp_df["TP_DRCR"] == "1"]
72
+ f.write(f"- ์ฐจ๋ณ€ ๊ฑด์ˆ˜: {len(debit_rows)}๊ฑด\n")
73
+ f.write(f"- ์ฐจ๋ณ€ ๊ณ„์ •: {len(debit_rows['CD_ACCT'].unique())}๊ฐœ ๊ณ„์ • ์‚ฌ์šฉ\n")
74
+
75
+ # ๋Œ€๋ณ€ ํ–‰ ์ •๋ณด
76
+ credit_rows = erp_df[erp_df["TP_DRCR"] == "2"]
77
+ f.write(f"- ๋Œ€๋ณ€ ๊ฑด์ˆ˜: {len(credit_rows)}๊ฑด\n")
78
+ f.write(f"- ๋Œ€๋ณ€ ๊ณ„์ •: {credit_rows['CD_ACCT'].iloc[0]} (๋ฏธ์ง€๊ธ‰๊ธˆ)\n")
79
+
80
+ # ์ „ํ‘œ ๋ฒˆํ˜ธ ์ •๋ณด
81
+ f.write(f"- ์ „ํ‘œ ๋ฒˆํ˜ธ: {erp_df['NO_DOCU'].iloc[0]}\n")
82
+
83
+ print(f"\n์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ ๋ณด๊ณ ์„œ๊ฐ€ '{report_file}'์— ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")