Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -397,6 +397,12 @@ def main():
|
|
| 397 |
# Initialize session state for last error
|
| 398 |
if 'last_error' not in st.session_state:
|
| 399 |
st.session_state['last_error'] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
|
| 401 |
# Sidebar: Select input type: Bulk PDF or CSV Upload
|
| 402 |
input_type = st.sidebar.radio("Select Input Type", ("Bulk Bank Statement Upload", "CSV Upload"))
|
|
@@ -475,7 +481,7 @@ def main():
|
|
| 475 |
except Exception as e:
|
| 476 |
st.error(f"Error processing CSV file: {str(e)}")
|
| 477 |
|
| 478 |
-
# If transactions are loaded, show DataFrame
|
| 479 |
if all_transactions:
|
| 480 |
df = pd.DataFrame(all_transactions)
|
| 481 |
# Drop 'Unnamed:' columns from the final DataFrame
|
|
@@ -484,9 +490,26 @@ def main():
|
|
| 484 |
try:
|
| 485 |
df['Amount'] = pd.to_numeric(df['Amount'], errors='coerce')
|
| 486 |
df['Amount'] = df['Amount'].apply(lambda x: f"R {x:,.2f}" if x >= 0 else f"R ({abs(x):,.2f})")
|
| 487 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
except Exception as e:
|
| 489 |
st.warning("Some data could not be formatted correctly.")
|
|
|
|
|
|
|
| 490 |
st.success("Transactions loaded successfully!")
|
| 491 |
st.write("### Extracted Transactions")
|
| 492 |
st.dataframe(df)
|
|
@@ -499,9 +522,11 @@ def main():
|
|
| 499 |
st.write("### Generate Financial Report")
|
| 500 |
col1, col2 = st.columns(2)
|
| 501 |
with col1:
|
| 502 |
-
|
|
|
|
| 503 |
with col2:
|
| 504 |
-
|
|
|
|
| 505 |
|
| 506 |
statement_type = st.selectbox("Select Financial Statement", ["Income Statement", "Cashflow Statement", "Balance Sheet"])
|
| 507 |
|
|
|
|
| 397 |
# Initialize session state for last error
|
| 398 |
if 'last_error' not in st.session_state:
|
| 399 |
st.session_state['last_error'] = None
|
| 400 |
+
|
| 401 |
+
# Initialize session state for transaction date range
|
| 402 |
+
if 'min_date' not in st.session_state:
|
| 403 |
+
st.session_state['min_date'] = date(2024, 1, 1) # Default min date
|
| 404 |
+
if 'max_date' not in st.session_state:
|
| 405 |
+
st.session_state['max_date'] = date(2024, 12, 31) # Default max date
|
| 406 |
|
| 407 |
# Sidebar: Select input type: Bulk PDF or CSV Upload
|
| 408 |
input_type = st.sidebar.radio("Select Input Type", ("Bulk Bank Statement Upload", "CSV Upload"))
|
|
|
|
| 481 |
except Exception as e:
|
| 482 |
st.error(f"Error processing CSV file: {str(e)}")
|
| 483 |
|
| 484 |
+
# If transactions are loaded, show DataFrame and update date ranges
|
| 485 |
if all_transactions:
|
| 486 |
df = pd.DataFrame(all_transactions)
|
| 487 |
# Drop 'Unnamed:' columns from the final DataFrame
|
|
|
|
| 490 |
try:
|
| 491 |
df['Amount'] = pd.to_numeric(df['Amount'], errors='coerce')
|
| 492 |
df['Amount'] = df['Amount'].apply(lambda x: f"R {x:,.2f}" if x >= 0 else f"R ({abs(x):,.2f})")
|
| 493 |
+
|
| 494 |
+
# Process dates and extract min/max dates for date range inputs
|
| 495 |
+
df['Date'] = pd.to_datetime(df['Date'], format='%d/%m/%Y', errors='coerce')
|
| 496 |
+
|
| 497 |
+
# Get min and max dates from transactions
|
| 498 |
+
if not df['Date'].isna().all():
|
| 499 |
+
min_date = df['Date'].min().date()
|
| 500 |
+
max_date = df['Date'].max().date()
|
| 501 |
+
|
| 502 |
+
# Update session state with actual transaction date range
|
| 503 |
+
st.session_state['min_date'] = min_date
|
| 504 |
+
st.session_state['max_date'] = max_date
|
| 505 |
+
|
| 506 |
+
# Format dates for display
|
| 507 |
+
df['Date'] = df['Date'].dt.strftime('%d/%m/%Y')
|
| 508 |
+
|
| 509 |
except Exception as e:
|
| 510 |
st.warning("Some data could not be formatted correctly.")
|
| 511 |
+
st.exception(e)
|
| 512 |
+
|
| 513 |
st.success("Transactions loaded successfully!")
|
| 514 |
st.write("### Extracted Transactions")
|
| 515 |
st.dataframe(df)
|
|
|
|
| 522 |
st.write("### Generate Financial Report")
|
| 523 |
col1, col2 = st.columns(2)
|
| 524 |
with col1:
|
| 525 |
+
# Use the min_date from transactions if available, otherwise use default
|
| 526 |
+
start_date = st.date_input("Start Date", st.session_state['min_date'])
|
| 527 |
with col2:
|
| 528 |
+
# Use the max_date from transactions if available, otherwise use default
|
| 529 |
+
end_date = st.date_input("End Date", st.session_state['max_date'])
|
| 530 |
|
| 531 |
statement_type = st.selectbox("Select Financial Statement", ["Income Statement", "Cashflow Statement", "Balance Sheet"])
|
| 532 |
|