0% found this document useful (0 votes)
17 views6 pages

PayBill Management System Full Program

Computer cbse project
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views6 pages

PayBill Management System Full Program

Computer cbse project
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

config.

py

# config.py

DB_CONFIG = {

"host": "localhost",

"user": "root",

"password": "",

"database": "PayBillDB"

EMAIL_CONFIG = {

"email": "[email protected]",

"password": "yourpassword",

"smtp_server": "smtp.gmail.com",

"port": 587

database.py

# database.py

import mysql.connector

from config import DB_CONFIG

def connect_db():

"""Establish and return a database connection."""

try:

return mysql.connector.connect(**DB_CONFIG)

except mysql.connector.Error as err:

print(f"Database connection failed: {err}")

return None

def execute_query(query, params=None, fetch_one=False, fetch_all=False):

"""Execute a database query with optional fetch."""


conn = connect_db()

if not conn:

return None

try:

cursor = conn.cursor(dictionary=True)

cursor.execute(query, params)

conn.commit()

if fetch_one:

return cursor.fetchone()

elif fetch_all:

return cursor.fetchall()

except mysql.connector.Error as err:

print(f"Query execution failed: {err}")

finally:

if conn.is_connected():

conn.close()

email_utils.py

# email_utils.py

import smtplib

from email.mime.text import MIMEText

from email.mime.multipart import MIMEMultipart

from email.mime.base import MIMEBase

from email import encoders

import os

from config import EMAIL_CONFIG

def send_email(to_email, pdf_path, bill_id):

"""Send an email with a PDF attachment."""

sender_email = EMAIL_CONFIG["email"]

sender_password = EMAIL_CONFIG["password"]

subject = f"Billing Receipt for Bill ID: {bill_id}"


body = "Dear User,\n\nPlease find attached the billing receipt for your recent payment."

msg = MIMEMultipart()

msg['From'] = sender_email

msg['To'] = to_email

msg['Subject'] = subject

msg.attach(MIMEText(body, 'plain'))

if os.path.exists(pdf_path):

with open(pdf_path, "rb") as attachment:

part = MIMEBase('application', 'octet-stream')

part.set_payload(attachment.read())

encoders.encode_base64(part)

part.add_header(

"Content-Disposition",

f"attachment; filename={os.path.basename(pdf_path)}",

msg.attach(part)

try:

server = smtplib.SMTP(EMAIL_CONFIG["smtp_server"], EMAIL_CONFIG["port"])

server.starttls()

server.login(sender_email, sender_password)

server.sendmail(sender_email, to_email, msg.as_string())

print(f"Email sent successfully to {to_email}.")

except Exception as e:

print(f"Failed to send email: {e}")

finally:

server.quit()

reporting.py

# reporting.py

import matplotlib.pyplot as plt


from database import execute_query

def generate_payment_trends():

"""Generate a bar chart for monthly payment trends."""

query = """

SELECT DATE_FORMAT(due_date, '%Y-%m') as month, COUNT(*) as total

FROM bills WHERE status = 'Paid'

GROUP BY month ORDER BY month ASC

"""

data = execute_query(query, fetch_all=True)

if not data:

print("No data available for reporting.")

return

months = [item['month'] for item in data]

totals = [item['total'] for item in data]

plt.bar(months, totals, color='skyblue')

plt.xlabel("Month")

plt.ylabel("Total Payments")

plt.title("Monthly Payment Trends")

plt.xticks(rotation=45)

plt.tight_layout()

plt.savefig("payment_trends.png")

print("Payment trends report generated: payment_trends.png")

main.py

# main.py

from database import execute_query

from email_utils import send_email

from reporting import generate_payment_trends

from fpdf import FPDF

from getpass import getpass


def generate_bill_pdf(bill, pdf_path):

"""Generate a PDF receipt for the bill."""

pdf = FPDF()

pdf.add_page()

pdf.set_font("Arial", size=12)

pdf.cell(200, 10, txt="Payment Receipt", ln=True, align='C')

pdf.cell(200, 10, txt=f"Bill ID: {bill['id']}", ln=True)

pdf.cell(200, 10, txt=f"Amount: {bill['amount']}", ln=True)

pdf.cell(200, 10, txt=f"Due Date: {bill['due_date']}", ln=True)

pdf.cell(200, 10, txt="Status: Paid", ln=True)

pdf.output(pdf_path)

print(f"Receipt PDF generated: {pdf_path}")

def admin_dashboard():

"""Admin dashboard for managing the system."""

print("\n---- Admin Dashboard ----")

print("1. View all users")

print("2. View all bills")

print("3. Generate reports")

print("4. Logout")

choice = input("Enter your choice: ")

if choice == '1':

view_users()

elif choice == '2':

view_bills()

elif choice == '3':

generate_payment_trends()

elif choice == '4':

print("Logging out...")

else:

print("Invalid choice!")
admin_dashboard()

# Define more functions for user and guest workflows...

if __name__ == "__main__":

print("Welcome to the Advanced PayBill Management System!")

# Call the login function or main menu

You might also like