Complete-Python-Mastery icon indicating copy to clipboard operation
Complete-Python-Mastery copied to clipboard

Assignment: E-commerce-like Advanced Billing System using Python

Open Pankaj-Str opened this issue 1 year ago • 2 comments

Objective:

Create an advanced billing system for an e-commerce application that allows users to input product details, apply GST, select discount offers, remove products, and calculate the final bill. The system should provide a detailed invoice with a breakdown of each item, taxes, discounts, and the total amount in Indian Rupees (₹).

Requirements:

  1. Product Input:

    • Allow the user to input multiple product details including:
      • Product ID
      • Product Name
      • Quantity
      • Unit Price (in ₹)
  2. GST Calculation:

    • Apply GST (Goods and Services Tax) to each product. GST rates should be variable and user-defined (e.g., 5%, 12%, 18%, 28%).
  3. Discount Offers:

    • Allow the user to select from various discount offers:
      • Percentage Discount on the total bill (e.g., 5%, 10%, 15%)
      • Fixed Amount Discount on the total bill (e.g., ₹100, ₹200)
      • Discount on specific products (e.g., 10% off on Product A)
  4. Product Removal:

    • Allow the user to remove products from the list by entering the Product ID.
  5. View Products:

    • Allow the user to view all products added to the bill with their details.
  6. Invoice Generation:

    • Generate a detailed invoice including:
      • Product details (Product ID, Name, Quantity, Unit Price, Subtotal)
      • GST applied
      • Discounts applied
      • Total amount before and after tax and discounts
  7. User Interface:

    • Create a simple text-based menu-driven interface to interact with the system.
    • Provide options to:
      • Add a new product
      • View all products
      • Remove a product
      • Apply GST
      • Apply Discounts
      • Generate and view the final invoice
  8. Data Validation:

    • Ensure data validation for user inputs (e.g., numeric values for prices and quantities, valid GST rates).

Example Workflow:

  1. Add Products:

    Enter Product ID: 101
    Enter Product Name: Laptop
    Enter Quantity: 2
    Enter Unit Price (₹): 75000
    Enter Product ID: 102
    Enter Product Name: Mouse
    Enter Quantity: 5
    Enter Unit Price (₹): 500
    
  2. View Products:

    -----------------------------------
    Products List:
    -----------------------------------
    Product ID: 101, Product Name: Laptop, Quantity: 2, Unit Price (₹): 75000
    Product ID: 102, Product Name: Mouse, Quantity: 5, Unit Price (₹): 500
    
  3. Remove Product:

    Enter Product ID to remove: 102
    
  4. Apply GST:

    Enter GST rate (%): 18
    
  5. Apply Discounts:

    Select Discount Type:
    1. Percentage Discount on Total Bill
    2. Fixed Amount Discount on Total Bill
    3. Discount on Specific Product
    Enter Choice: 1
    Enter Discount Rate (%): 10
    
  6. Generate Invoice:

    -----------------------------------
    E-commerce Billing System Invoice
    -----------------------------------
    Product ID: 101
    Product Name: Laptop
    Quantity: 2
    Unit Price (₹): 75000
    Subtotal (₹): 150000
    GST @ 18% (₹): 27000
    -----------------------------------
    Total before discount (₹): 177000
    Discount @ 10% (₹): 17700
    -----------------------------------
    Final Total (₹): 159300
    -----------------------------------
    

Submission:

Submit the Python script implementing the advanced billing system. Ensure your code is well-documented with comments explaining each part of the logic. Include a README file explaining how to run your program and any dependencies required.

Evaluation Criteria:

  • Correctness and completeness of the implemented features
  • Code readability and documentation
  • Handling of edge cases and data validation
  • User interface and user experience

Pankaj-Str avatar Jul 20 '24 14:07 Pankaj-Str


productID = []
productName = []
quantity = []
unitPrice = []

option = 1
gst = 0
val = 0
discount = 0
switchOption = int(input("Enter 1. To add new product\n 2. To view all products\n 3. To remove a product\n 4. To apply GST\n 5. To apply discounts\n 6. To generate and view the final invoice\n"))
while(switchOption != 0):

        if(switchOption == 1):
        
            prodID = input("Enter Product ID: ")
            productID.append(prodID)
            prodName = input("Enter Product Name: ")
            productName.append(prodName)
            quanti = int(input("Enter Quantity: "))
            quantity.append(quanti)
            uniPrice = int(input("Enter Unit Price (Rs): "))
            unitPrice.append(uniPrice)
            switchOption = int(input("Enter 1. To add new product\n 2. To view all products\n 3. To remove a product\n 4. To apply GST\n 5. To apply discounts\n 6. To generate and view the final invoice\n"))
        
        elif(switchOption == 2):
            print("-----------------------------------")
            print("Products List:")
            print("-----------------------------------")
            for i in range(0, len(productID)):
            
                print(f"Product ID: {productID[i]}, Product Name: {productName[i]}, Quantity: {quantity[i]} + Unit Price (Rs): {unitPrice[i]}")
            
            switchOption = int(input("Enter 1. To add new product\n 2. To view all products\n 3. To remove a product\n 4. To apply GST\n 5. To apply discounts\n 6. To generate and view the final invoice\n"))

        elif(switchOption == 3):
            prodID = input("Enter Product ID to remove: ")
            index = 0
            for i in range(0, len(productID)):
                if(productID[i] == prodID):
                    index = i

            num = productID.pop(index)
            num = productName.pop(index)
            num = quantity.pop(index)
            num = unitPrice.pop(index)
            switchOption = int(input("Enter 1. To add new product\n 2. To view all products\n 3. To remove a product\n 4. To apply GST\n 5. To apply discounts\n 6. To generate and view the final invoice\n"))

        elif(switchOption == 4):
        
            gst = int(input("Enter GST rate (%): "))
            switchOption = int(input("Enter 1. To add new product\n 2. To view all products\n 3. To remove a product\n 4. To apply GST\n 5. To apply discounts\n 6. To generate and view the final invoice\n"))

        elif(switchOption == 5):
            rate = 0
            discount = 0
            print("Select Discount Type:\n 1. Percentage Discount on Total Bill\n 2. Fixed Amount Discount on Total Bill\n 3. Discount on Specific Product\n")
            val = int(input("Enter choice: "))
            if(val == 1):
                rate = int(input("Enter Discount Rate (%): "))

            elif(val == 2):
                discount = int(input("Enter the fixed amount discount on total bill: "))

            elif(val == 3):
                for i in range(0, len(productID)):
                    dis = int(input(f"Enter the discount for productID {productID[i]}: "))
                    unitPrice[i] = unitPrice[i] - (unitPrice[i] * dis / 100)
            switchOption = int(input("Enter 1. To add new product\n 2. To view all products\n 3. To remove a product\n 4. To apply GST\n 5. To apply discounts\n 6. To generate and view the final invoice\n"))

        elif(switchOption == 6):
            print("-----------------------------------")
            print("E-commerce Billing System Invoice")
            print("-----------------------------------")
            subtotal = 0
            for i in range(0, len(productID)):
                print(f"Product ID: {productID[i]}")
                print(f"Product Name: {productName[i]}")
                print(f"Quantity: {quantity[i]}")
                print(f"Unit Price (Rs): {unitPrice[i]}")
                subtotal = subtotal + quantity[i] * unitPrice[i]
            print(f"Subtotal (Rs): {subtotal}")
            print(f"GST @ {gst}% (Rs): {(gst*subtotal/100)}")
            print("-----------------------------------")
            print(f"Total before discount (₹): {(subtotal + gst*subtotal/100)}")
            if(val == 1):
                print(f"Discount @ {rate}% (Rs): {rate*(subtotal + gst*subtotal/100)/100}")
                print("-----------------------------------")
                finalTotal = (subtotal + gst*subtotal/100) - ((rate*(subtotal + gst*subtotal/100)/100))
                print(f"Final Total (₹): {finalTotal}")
                print("-----------------------------------")
            elif(val == 2):
                print(f"Discount is {discount}")
                print("-----------------------------------")
                finalTotal = (subtotal + gst*subtotal/100) - discount
                print(f"Final Total (₹): {finalTotal}")
                print("-----------------------------------")   
            elif(val == 3):
                print("-----------------------------------")
                finalTotal = (subtotal + gst*subtotal/100)
                print(f"Final Total (₹): {finalTotal}")
                print("-----------------------------------")
            switchOption = 0

nickyjbn avatar Jul 23 '24 05:07 nickyjbn

https://github.com/developology/E-Commerce-Billing-System-

RiddhiiA avatar Aug 03 '24 10:08 RiddhiiA

products = {}  # Dictionary to store product details with Product ID as key

total_discount = 0  # Variable to store total discount applied

def add_product():
    """Function to add a new product to the billing system"""
    try:
        product_id = input("Enter Product ID: ")
        if product_id in products:
            print("Product ID already exists! Try updating the quantity instead.\n")
            return
        name = input("Enter Product Name: ")
        quantity = int(input("Enter Quantity: "))
        unit_price = float(input("Enter Unit Price (₹): "))
        products[product_id] = {
            "name": name,
            "quantity": quantity,
            "unit_price": unit_price,
            "gst_rate": 0,
            "discount": 0
        }
        print("Product added successfully!\n")
    except ValueError:
        print("Invalid input! Please enter numeric values for quantity and unit price.\n")

def view_products():
    """Function to display all added products"""
    if not products:
        print("No products added yet.\n")
        return
    print("Product List:")
    for product_id, details in products.items():
        print(f"ID: {product_id}, Name: {details['name']}, Quantity: {details['quantity']}, Price (₹): {details['unit_price']}")
    print()

def remove_product():
    """Function to remove a product from the billing system"""
    product_id = input("Enter Product ID to remove: ")
    if product_id in products:
        del products[product_id]
        print("Product removed successfully!\n")
    else:
        print("Product ID not found!\n")

def apply_gst():
    """Function to apply GST to all products"""
    try:
        gst_rate = float(input("Enter GST rate (%): "))
        if 0 <= gst_rate <= 100:
            for product in products.values():
                product["gst_rate"] = gst_rate
            print(f"GST of {gst_rate}% applied to all products.\n")
        else:
            print("Invalid GST rate! It must be between 0 and 100.\n")
    except ValueError:
        print("Invalid input! Please enter a numeric GST rate.\n")

def apply_discount():
    """Function to apply discount on total bill or specific products"""
    global total_discount
    try:
        print("Select Discount Type:")
        print("1. Percentage Discount on Total Bill")
        print("2. Fixed Amount Discount on Total Bill")
        print("3. Discount on Specific Product")
        choice = int(input("Enter Choice: "))
        if choice == 1:
            total_discount = float(input("Enter Discount Rate (%): "))
        elif choice == 2:
            total_discount = float(input("Enter Discount Amount: "))
        elif choice == 3:
            product_id = input("Enter Product ID for Discount: ")
            if product_id in products:
                discount_rate = float(input("Enter Discount Rate (%): "))
                products[product_id]["discount"] = discount_rate
                print("Discount applied successfully!\n")
            else:
                print("Product not found!\n")
        else:
            print("Invalid choice!\n")
    except ValueError:
        print("Invalid input! Please enter numeric values where required.\n")

def generate_invoice():
    """Function to generate and display the final invoice"""
    global total_discount
    if not products:
        print("No products added yet. Cannot generate invoice.\n")
        return
    print("-----------------------------------")
    print("E-commerce Billing System Invoice")
    print("-----------------------------------")
    total_before_discount = 0
    total_gst = 0
    total_discount_amount = 0
    
    for product_id, details in products.items():
        subtotal = details['quantity'] * details['unit_price']
        gst = (subtotal * details['gst_rate']) / 100
        discount = (subtotal * details['discount']) / 100
        total_before_discount += subtotal + gst
        total_gst += gst
        total_discount_amount += discount
        
        print(f"Product ID: {product_id}")
        print(f"Product Name: {details['name']}")
        print(f"Quantity: {details['quantity']}")
        print(f"Unit Price (₹): {details['unit_price']:.2f}")
        print(f"Subtotal (₹): {subtotal:.2f}")
        print(f"GST @ {details['gst_rate']}% (₹): {gst:.2f}")
        if discount > 0:
            print(f"Discount (₹): {discount:.2f}")
        print("-----------------------------------")
    
    if isinstance(total_discount, float) and total_discount > 0:
        if total_discount <= 100:
            discount_amount = (total_before_discount * total_discount) / 100
        else:
            discount_amount = total_discount
        total_discount_amount += discount_amount
        print(f"Total before discount (₹): {total_before_discount:.2f}")
        print(f"Discount Applied (₹): {discount_amount:.2f}")
        print("-----------------------------------")
    
    final_total = total_before_discount - total_discount_amount
    print(f"Final Total (₹): {final_total:.2f}")
    print("-----------------------------------\n")

def main():
    """Main function to display menu and handle user input"""
    while True:
        print("1. Add New Product")
        print("2. View All Products")
        print("3. Remove Product")
        print("4. Apply GST")
        print("5. Apply Discounts")
        print("6. Generate Invoice")
        print("7. Exit")
        choice = input("Enter your choice: ")
        if choice == '1':
            add_product()
        elif choice == '2':
            view_products()
        elif choice == '3':
            remove_product()
        elif choice == '4':
            apply_gst()
        elif choice == '5':
            apply_discount()
        elif choice == '6':
            generate_invoice()
        elif choice == '7':
            print("Exiting...\n")
            break
        else:
            print("Invalid choice! Please try again.\n")

if __name__ == "__main__":
    main()

ritvik-patil avatar Feb 12 '25 13:02 ritvik-patil