Download app.py from Dwinward/SAP: direct link, hf CLI and curl.
- Browser
- Download file 3.03 kB
-
https://huggingface.co/spaces/Dwinward/SAP/resolve/main/app.py
- Command line
-
hf download hf://spaces/Dwinward/SAP/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Dwinward/SAP/resolve/main/app.py
3.03 kB
| import streamlit as st | |
| import pandas as pd | |
| import io | |
| st.title("Sales vs SAP Reconciliation") | |
| # File Uploaders | |
| file1 = st.file_uploader("1. Upload Sales Data (File 1)", type=['csv', 'xlsx']) | |
| file2 = st.file_uploader("2. Upload SAP Data (File 2)", type=['csv', 'xlsx']) | |
| if file1 and file2: | |
| if st.button("Run Reconciliation"): | |
| with st.spinner("Processing... this may take a minute for large files."): | |
| # Load Data | |
| df1 = pd.read_excel(file1) if file1.name.endswith('.xlsx') else pd.read_csv(file1) | |
| df2 = pd.read_excel(file2) if file2.name.endswith('.xlsx') else pd.read_csv(file2) | |
| # Process File 1 | |
| df1['Card_Acceptor_Name'] = df1['Card_Acceptor_Name'].astype(str) | |
| df1['Ticket_Number'] = df1['Ticket_Number'].astype(str).str.strip() | |
| df1['Sales_Details'] = df1['Sales_Details'].astype(str).str.strip() | |
| df1['Branch'] = df1['Card_Acceptor_Name'].str[:4] | |
| till_extract = df1['Sales_Details'].str.extract(r'(TILL\d+)', expand=False) | |
| standard_key = df1['Branch'] + df1['Ticket_Number'] | |
| df1['Match_Key'] = till_extract.fillna(standard_key) | |
| df1['Value_Sales'] = pd.to_numeric(df1['Trans_Amount_HUC'], errors='coerce') | |
| df1.loc[df1['Ticket_Number'].str.startswith('K', na=False), 'Value_Sales'] *= -1 | |
| # Process File 2 | |
| df2['Match_Key'] = df2.iloc[:, 3].astype(str).str.strip() | |
| df2['Value_SAP'] = pd.to_numeric(df2.iloc[:, 8], errors='coerce') | |
| # Merge | |
| merged = pd.merge(df1, df2, on='Match_Key', how='outer', indicator=True) | |
| matches = merged[merged['_merge'] == 'both'] | |
| missing_sap = merged[merged['_merge'] == 'left_only'] | |
| missing_sales = merged[merged['_merge'] == 'right_only'] | |
| # Display Summary | |
| st.subheader("Reconciliation Summary") | |
| st.write(f"**Total Matched:** {len(matches):,}") | |
| st.write(f"**Missing in SAP:** {len(missing_sap):,}") | |
| st.write(f"**Missing in Sales:** {len(missing_sales):,}") | |
| # Date Analysis | |
| if 'Transaction_Date' in missing_sap.columns: | |
| st.subheader("Top Problem Dates (Missing in SAP)") | |
| missing_sap['Date_Only'] = pd.to_datetime(missing_sap['Transaction_Date']).dt.date | |
| st.write(missing_sap['Date_Only'].value_counts().head(10)) | |
| # Download Buttons function | |
| def convert_df(df): | |
| return df.to_csv(index=False).encode('utf-8') | |
| st.download_button("Download Matched", convert_df(matches), "1_Matched.csv", "text/csv") | |
| st.download_button("Download Missing in SAP", convert_df(missing_sap), "2_Missing_in_SAP.csv", "text/csv") | |
| st.download_button("Download Missing in Sales", convert_df(missing_sales), "3_Missing_in_Sales.csv", "text/csv") |