Repository navigation
Expand file tree
/
Copy pathdatabase.py
More file actions
68 lines (61 loc) · 2.13 KB
/
Copy pathdatabase.py
File metadata and controls
68 lines (61 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
SQLite database operations for the cash register system
"""
import sqlite3
from datetime import datetime
class Database:
def __init__(self, db_path='cash_register.db'):
"""Initialize database connection and create tables"""
self.conn = sqlite3.connect(db_path)
self.cursor = self.conn.cursor()
self.create_tables()
def create_tables(self):
"""Create required tables if they don't exist"""
# Inventory table
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS inventory (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
price REAL NOT NULL,
quantity INTEGER NOT NULL,
description TEXT,
barcode TEXT UNIQUE
)
''')
# Customers table
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS customers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
email TEXT NOT NULL,
phone TEXT,
address TEXT,
city TEXT,
state TEXT,
zip_code TEXT,
dob TEXT NOT NULL,
id_image_path TEXT NOT NULL,
date_added TEXT NOT NULL
)
''')
# Transactions table
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS transactions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
customer_id INTEGER,
total REAL NOT NULL,
tax REAL NOT NULL,
payment_method TEXT NOT NULL,
items TEXT NOT NULL,
timestamp TEXT NOT NULL,
id_verified INTEGER NOT NULL,
FOREIGN KEY(customer_id) REFERENCES customers(id)
)
''')
self.conn.commit()
# Additional database operations...
# (Add methods for CRUD operations on all tables)
def close(self):
"""Close database connection"""
self.conn.close()