Dwinward commited on
Commit
c4ce710
·
verified ·
1 Parent(s): a5e6c3f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import io
4
+
5
+ st.title("Sales vs SAP Reconciliation")
6
+
7
+ # File Uploaders
8
+ file1 = st.file_uploader("1. Upload Sales Data (File 1)", type=['csv', 'xlsx'])
9
+ file2 = st.file_uploader("2. Upload SAP Data (File 2)", type=['csv', 'xlsx'])
10
+
11
+ if file1 and file2:
12
+ if st.button("Run Reconciliation"):
13
+ with st.spinner("Processing... this may take a minute for large files."):
14
+ # Load Data
15
+ df1 = pd.read_excel(file1) if file1.name.endswith('.xlsx') else pd.read_csv(file1)
16
+ df2 = pd.read_excel(file2) if file2.name.endswith('.xlsx') else pd.read_csv(file2)
17
+
18
+ # Process File 1
19
+ df1['Card_Acceptor_Name'] = df1['Card_Acceptor_Name'].astype(str)
20
+ df1['Ticket_Number'] = df1['Ticket_Number'].astype(str).str.strip()
21
+ df1['Sales_Details'] = df1['Sales_Details'].astype(str).str.strip()
22
+ df1['Branch'] = df1['Card_Acceptor_Name'].str[:4]
23
+
24
+ till_extract = df1['Sales_Details'].str.extract(r'(TILL\d+)', expand=False)
25
+ standard_key = df1['Branch'] + df1['Ticket_Number']
26
+ df1['Match_Key'] = till_extract.fillna(standard_key)
27
+
28
+ df1['Value_Sales'] = pd.to_numeric(df1['Trans_Amount_HUC'], errors='coerce')
29
+ df1.loc[df1['Ticket_Number'].str.startswith('K', na=False), 'Value_Sales'] *= -1
30
+
31
+ # Process File 2
32
+ df2['Match_Key'] = df2.iloc[:, 3].astype(str).str.strip()
33
+ df2['Value_SAP'] = pd.to_numeric(df2.iloc[:, 8], errors='coerce')
34
+
35
+ # Merge
36
+ merged = pd.merge(df1, df2, on='Match_Key', how='outer', indicator=True)
37
+ matches = merged[merged['_merge'] == 'both']
38
+ missing_sap = merged[merged['_merge'] == 'left_only']
39
+ missing_sales = merged[merged['_merge'] == 'right_only']
40
+
41
+ # Display Summary
42
+ st.subheader("Reconciliation Summary")
43
+ st.write(f"**Total Matched:** {len(matches):,}")
44
+ st.write(f"**Missing in SAP:** {len(missing_sap):,}")
45
+ st.write(f"**Missing in Sales:** {len(missing_sales):,}")
46
+
47
+ # Date Analysis
48
+ if 'Transaction_Date' in missing_sap.columns:
49
+ st.subheader("Top Problem Dates (Missing in SAP)")
50
+ missing_sap['Date_Only'] = pd.to_datetime(missing_sap['Transaction_Date']).dt.date
51
+ st.write(missing_sap['Date_Only'].value_counts().head(10))
52
+
53
+ # Download Buttons function
54
+ def convert_df(df):
55
+ return df.to_csv(index=False).encode('utf-8')
56
+
57
+ st.download_button("Download Matched", convert_df(matches), "1_Matched.csv", "text/csv")
58
+ st.download_button("Download Missing in SAP", convert_df(missing_sap), "2_Missing_in_SAP.csv", "text/csv")
59
+ st.download_button("Download Missing in Sales", convert_df(missing_sales), "3_Missing_in_Sales.csv", "text/csv")