python invoice managment
python invoice managment
and **SQLite for data storage**. This will allow you to:
---
### ✅ Features
---
```python
import sqlite3
from tkinter import *
from tkinter import messagebox
# Initialize DB
conn = sqlite3.connect("invoices.db")
cur = conn.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS invoice (
id INTEGER PRIMARY KEY AUTOINCREMENT,
customer TEXT,
item TEXT,
quantity INTEGER,
price REAL,
total REAL
)''')
conn.commit()
# Functions
def add_invoice():
if not (customer_entry.get() and item_entry.get() and quantity_entry.get() and
price_entry.get()):
messagebox.showwarning("Input Error", "All fields must be filled")
return
try:
quantity = int(quantity_entry.get())
price = float(price_entry.get())
total = quantity * price
cur.execute("INSERT INTO invoice (customer, item, quantity, price, total)
VALUES (?, ?, ?, ?, ?)",
(customer_entry.get(), item_entry.get(), quantity, price,
total))
conn.commit()
messagebox.showinfo("Success", "Invoice Added")
clear_fields()
view_invoices()
except ValueError:
messagebox.showerror("Input Error", "Quantity must be integer and price
must be numeric")
def view_invoices():
listbox.delete(0, END)
for row in cur.execute("SELECT * FROM invoice"):
listbox.insert(END, row)
def search_invoice():
query = search_entry.get()
listbox.delete(0, END)
for row in cur.execute("SELECT * FROM invoice WHERE customer LIKE ? OR id
LIKE ?",
(f'%{query}%', f'%{query}%')):
listbox.insert(END, row)
def clear_fields():
customer_entry.delete(0, END)
item_entry.delete(0, END)
quantity_entry.delete(0, END)
price_entry.delete(0, END)
# GUI Setup
root = Tk()
root.title("Invoice Management System")
root.geometry("600x500")
# Buttons
Button(root, text="Add Invoice", command=add_invoice).grid(row=4, column=0,
columnspan=2, pady=10)
Button(root, text="View Invoices", command=view_invoices).grid(row=5, column=0,
columnspan=2, pady=5)
# Search
Label(root, text="Search by Customer/ID").grid(row=6, column=0, pady=5)
search_entry = Entry(root)
search_entry.grid(row=6, column=1)
Button(root, text="Search", command=search_invoice).grid(row=7, column=0,
columnspan=2)
# Listbox
listbox = Listbox(root, width=80)
listbox.grid(row=8, column=0, columnspan=2, pady=10)
# Run App
view_invoices()
root.mainloop()
```
---
### 📦 Requirements
* Python 3.x
* Built-in `sqlite3` and `tkinter`
---