Cs Project
Cs Project
class Database:
def __init__(self, host, user, password,
database):
self.host = host
self.user = user
self.password = password
self.database = database
self.connection = None
def connect(self):
try:
self.connection = mq.connect(
host=self.host,
user=self.user,
password=self.password,
database=self.database
)
except mq.Error as e:
print(f"Database Connection Error:
{e}")
def close(self):
if self.connection:
self.connection.close()
def register_user(db):
print("\n--- Registering New User ---")
ph = input("Enter Phone Number: ")
name = input("Enter Name: ")
address = input("Enter Address: ")
aadhar = input("Enter Aadhar Number: ")
email = input("Enter Email: ")
try:
initial_calls = int(input("Enter Initial Call
Count: "))
initial_ftp = float(input("Enter Initial FTP
(Bill Amount): "))
except ValueError:
print("Invalid input for call count or FTP.
Please enter numerical values.")
return
db.execute_query(
"INSERT INTO customer (Phno, name,
address, aadhar_no, email, call_count, ftp,
payment_status) VALUES (%s, %s, %s, %s,
%s, %s, %s, %s)",
(ph, name, address, aadhar, email,
initial_calls, initial_ftp, "Paid")
)
print("User registered successfully!")
def view_customer_details(db):
print("\n--- Viewing Customer Details ---")
ph = input("Enter Phone Number: ")
customer = customer[0]
print("\n--- Customer Details ---")
print(f"Phone Number: {customer[0]}")
print(f"Name: {customer[1]}")
print(f"Address: {customer[2]}")
print(f"Aadhar Number: {customer[3]}")
print(f"Email: {customer[4]}")
print(f"Call Count: {customer[5]}")
print(f"FTP (Bill Amount):
₹{customer[6]}")
print(f"Payment Status: {customer[7]}")
def show_all_records(db):
print("\n--- All Customer Records ---")
customers = db.fetch_all("SELECT *
FROM customer")
if not customers:
print("No customer records found!")
return
print(f"\n{'Phone':<15}{'Name':<20}{'Addres
s':<30}{'Aadhar':<15}{'Email':<25}{'Calls':<1
0}{'FTP':<10}{'Payment Status':<15}")
print("=" * 140)
for customer in customers:
print(f"{customer[0]:<15}{customer[1]:<20}{
customer[2]:<30}{customer[3]:<15}{custome
r[4]:<25}{customer[5]:<10}{customer[6]:<10
}{customer[7]:<15}")
print("=" * 140)
def make_payment(db):
print("\n--- Making Payment ---")
ph = input("Enter Phone Number: ")
customer = customer[0]
outstanding_bill = customer[6]
payment_status = customer[7]
if payment_status == "Paid":
print("No pending bills! All dues are
cleared.")
return
print(f"Outstanding Bill:
₹{outstanding_bill}")
confirm = input("Confirm payment?
(yes/no): ").strip().lower()
if confirm == "yes":
query = "UPDATE customer SET ftp =
%s, payment_status = %s WHERE Phno =
%s"
db.execute_query(query, (0, "Paid", ph))
print("Payment successful! All dues are
cleared.")
else:
print("Payment cancelled.")
def delete_customer(db):
print("\n--- Deleting Customer ---")
ph = input("Enter Phone Number: ")
def update_customer(db):
print("\n--- Updating Customer Details ---")
ph = input("Enter Phone Number: ")
if choice == 1:
new_name = input("Enter New Name: ")
db.execute_query("UPDATE customer
SET name = %s WHERE Phno = %s",
(new_name, ph))
elif choice == 2:
new_address = input("Enter New
Address: ")
db.execute_query("UPDATE customer
SET address = %s WHERE Phno = %s",
(new_address, ph))
elif choice == 3:
new_aadhar = input("Enter New Aadhar
Number: ")
db.execute_query("UPDATE customer
SET aadhar_no = %s WHERE Phno = %s",
(new_aadhar, ph))
elif choice == 4:
new_email = input("Enter New Email: ")
db.execute_query("UPDATE customer
SET email = %s WHERE Phno = %s",
(new_email, ph))
elif choice == 5:
try:
new_call_count = int(input("Enter
New Call Count: "))
db.execute_query("UPDATE customer
SET call_count = %s WHERE Phno = %s",
(new_call_count, ph))
except ValueError:
print("Invalid input! Please enter a
valid integer for the call count.")
return
else:
print("Invalid choice!")
return
def generate_bill(db):
print("\n--- Generating Bill ---")
ph = input("Enter Phone Number: ")
customer = customer[0]
call_count = customer[5]
ftp = customer[6]
try:
new_calls = int(input("Enter new call
count: "))
except ValueError:
print("Invalid input! Please enter a valid
integer for call count.")
return
updated_call_count = call_count +
new_calls
db.execute_query(
"UPDATE customer SET call_count =
%s, ftp = %s, payment_status = %s WHERE
Phno = %s",
(updated_call_count, total_bill,
"Pending", ph)
)
print(f"Updated Bill: ₹{total_bill}")
def main_menu():
db = Database(host="localhost",
user="root", password="rithick123",
database="telephone2")
while True:
print("\n--- ONLINE TELEPHONE
BILLING SYSTEM ---")
print("1. Register User")
print("2. View Customer Details")
print("3. Show All Records")
print("4. Generate Bill")
print("5. Make Payment")
print("6. Delete Customer")
print("7. Update Customer")
print("8. Exit")
try:
choice = int(input("Enter your choice:
"))
except ValueError:
print("Invalid input! Please enter a
number between 1 and 8.")
continue
if choice == 1:
register_user(db)
elif choice == 2:
view_customer_details(db)
elif choice == 3:
show_all_records(db)
elif choice == 4:
generate_bill(db)
elif choice == 5:
make_payment(db)
elif choice == 6:
delete_customer(db)
elif choice == 7:
update_customer(db)
elif choice == 8:
print("Exiting...")
db.close() # Close the database
connection when exiting
break # Exit the loop and terminate
the program
else:
print("Invalid choice! Please try
again.")
if __name__ == "__main__":
main_menu()
SQL CODE
CREATE DATABASE telephone;
USE telephone;
MAKE PAYMENT
DELETING THE CUSTOMER RECORD
_____________
ACKNOWLEDGEMENT
I would like to express my special thanks
of gratitude to my teacher Mrs. G. Sujeetha
as well as our principal Mrs. K. Geetha
who gave me the golden opportunity to do
this wonderful project on the topic
“Telephone Billing System", which also
helped me in doing a lot of research and I
came to know about so many new things. I
am really thankful to them.
Secondly, I would also like to thank my
parents and friends who helped me a lot in
finalizing this project within the limited
time frame.
R.RITHICK BALAJI
XII A
COMPUTER SCIENCE PROJECT