OneCompiler

prompt3

129

Payment Management System (PMS) using Python Streamlit and PostgreSQL
Client: BSNL - Land Line Customer (Monthly Bill Payment)

Develop a Payment Management System (PMS) using Python Streamlit with a PostgreSQL database. The system should ensure proper session management and avoid unnecessary Streamlit reruns. Do not use SQLAlchemyโ€”use psycopg2 for database interactions.

๐Ÿ“‚ Folder Structure:
bash
Copy
Edit
๐Ÿ“‚ pms_project/
โ”‚โ”€โ”€ ๐Ÿ“‚ pages/
โ”‚ โ”‚โ”€โ”€ ๐Ÿ“„ main.py # Bill payment processing
โ”‚ โ”‚โ”€โ”€ ๐Ÿ“„ receipt.py # Receipt generation
โ”‚
โ”‚โ”€โ”€ ๐Ÿ“„ login.py # Entry page (Admin Login)
๐Ÿ›  Functional Requirements
๐Ÿ”น 1) login.py (Admin Login Page)
First page that loads when the app starts.
Contains username and password input fields.
Credentials are checked against the check_admin table in the PostgreSQL database.
If login is successful, the user is redirected to pages/main.py.
If login fails, an error message is displayed.
Database Table: check_admin
username
password
enabled_or_not
date_of_creation_of_username
Implementation Considerations:
Uses session state (st.session_state) to store login status and prevent reruns.
If a user is already logged in, they should be directly taken to pages/main.py without re-entering credentials.
๐Ÿ”น 2) pages/main.py (Bill Payment Portal)
Purpose: Handles bill payments for landline customers.

Workflow:

Text input: The user enters a Telephone Number.
Button: "Fetch Details" โ†’ Retrieves details from the database (Customer_info table).
Displays fetched details:
Customer_Name
Telephone_No
Telephone_Exchange
Monthly_Plan
Billed_Month
Amount_payable
Payment_method (Default: "Cash")
Text input: User enters Name_of_the_Accounts_Officer.
Submit Button:
Updates Payment_Status to "Paid" (from "Pending") in the database.
Updates paid_dt_time with the current timestamp.
"Show Receipt" Button: Appears only after submission and redirects to pages/receipt.py.
Database Table: Customer_info

Custemer_Name
Telephone_No
Telephone_Exchange
Monthly_Plan
Billed_Month
Amount_payable
Payment_method
Payment_Status
paid_dt_time
Name_of_the_Accounts_Officer
Implementation Considerations:

Session state (st.session_state) should be used to store retrieved details and prevent unnecessary reruns.
Use st.form() to wrap the input fields to avoid Streamlitโ€™s default rerun behavior.
Show "Show Receipt" button only after successful submission.
๐Ÿ”น 3) pages/receipt.py (Receipt Generation)
Purpose: Displays a bill payment receipt after successful payment.
Receipt Format:
Customer_Name
Telephone Number
Plan
Billed Month
Amount Paid
Payment Method
Date_time
Account_Officer_details
Implementation Considerations:
Retrieves data from st.session_state to display the latest transaction details.
Ensures that it does not run unless redirected from pages/main.py.
๐Ÿ›‘ Key Enhancements to Avoid Streamlit Reruns:
1๏ธโƒฃ Use st.session_state to retain login status, fetched customer details, and payment information.
2๏ธโƒฃ Use st.form() to group inputs and process data only when the submit button is clicked.
3๏ธโƒฃ Ensure controlled navigation:

login.py โ†’ Redirects to pages/main.py after successful login.
pages/main.py โ†’ Redirects to pages/receipt.py after successful payment.
4๏ธโƒฃ Avoid auto-refresh issues by checking st.session_state before making database calls.
๐Ÿ’ก Final Notes:

Do not create additional filesโ€”only login.py, pages/main.py, and pages/receipt.py should exist.
All database configurations should be written directly inside these files using psycopg2 (without SQLAlchemy).
The generated code must strictly follow this folder structure and functionality.