Completed:
✅ Admin: Process creation, field configuration, template upload ✅ Staff: Session list, new session (header form), scanning interface ✅ Duplicate detection (same session = blue, other session = orange) ✅ Weight entry popup, edit/delete scans
This commit is contained in:
@@ -31,36 +31,7 @@ def init_database():
|
||||
created_timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
''')
|
||||
|
||||
# Modules Table - defines available system modules
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS Modules (
|
||||
module_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
module_name TEXT UNIQUE NOT NULL,
|
||||
module_key TEXT UNIQUE NOT NULL,
|
||||
description TEXT,
|
||||
icon TEXT,
|
||||
is_active INTEGER DEFAULT 1,
|
||||
display_order INTEGER DEFAULT 0
|
||||
)
|
||||
''')
|
||||
|
||||
# UserModules Table - which modules each user can access
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS UserModules (
|
||||
user_module_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
module_id INTEGER NOT NULL,
|
||||
granted_by INTEGER,
|
||||
granted_timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES Users(user_id),
|
||||
FOREIGN KEY (module_id) REFERENCES Modules(module_id),
|
||||
FOREIGN KEY (granted_by) REFERENCES Users(user_id),
|
||||
UNIQUE(user_id, module_id)
|
||||
)
|
||||
''')
|
||||
|
||||
|
||||
|
||||
# CountSessions Table
|
||||
# NOTE: current_baseline_version removed - CURRENT is now global
|
||||
cursor.execute('''
|
||||
@@ -195,6 +166,90 @@ def init_database():
|
||||
)
|
||||
''')
|
||||
|
||||
# ============================================
|
||||
# CONSUMPTION SHEETS MODULE TABLES
|
||||
# ============================================
|
||||
|
||||
# cons_processes - Master list of consumption sheet process types
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS cons_processes (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
process_key TEXT UNIQUE NOT NULL,
|
||||
process_name TEXT NOT NULL,
|
||||
template_file BLOB,
|
||||
template_filename TEXT,
|
||||
rows_per_page INTEGER DEFAULT 30,
|
||||
detail_start_row INTEGER DEFAULT 10,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
created_by INTEGER NOT NULL,
|
||||
is_active INTEGER DEFAULT 1,
|
||||
FOREIGN KEY (created_by) REFERENCES Users(user_id)
|
||||
)
|
||||
''')
|
||||
|
||||
# cons_process_fields - Custom field definitions for each process
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS cons_process_fields (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
process_id INTEGER NOT NULL,
|
||||
table_type TEXT NOT NULL CHECK(table_type IN ('header', 'detail')),
|
||||
field_name TEXT NOT NULL,
|
||||
field_label TEXT NOT NULL,
|
||||
field_type TEXT NOT NULL CHECK(field_type IN ('TEXT', 'INTEGER', 'REAL', 'DATE', 'DATETIME')),
|
||||
max_length INTEGER,
|
||||
is_required INTEGER DEFAULT 0,
|
||||
is_active INTEGER DEFAULT 1,
|
||||
sort_order INTEGER DEFAULT 0,
|
||||
excel_cell TEXT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (process_id) REFERENCES cons_processes(id)
|
||||
)
|
||||
''')
|
||||
|
||||
# cons_sessions - Staff scanning sessions
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS cons_sessions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
process_id INTEGER NOT NULL,
|
||||
created_by INTEGER NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
status TEXT DEFAULT 'active' CHECK(status IN ('active', 'archived')),
|
||||
FOREIGN KEY (process_id) REFERENCES cons_processes(id),
|
||||
FOREIGN KEY (created_by) REFERENCES Users(user_id)
|
||||
)
|
||||
''')
|
||||
|
||||
# cons_session_header_values - Flexible storage for header field values
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS cons_session_header_values (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
session_id INTEGER NOT NULL,
|
||||
field_id INTEGER NOT NULL,
|
||||
field_value TEXT,
|
||||
FOREIGN KEY (session_id) REFERENCES cons_sessions(id),
|
||||
FOREIGN KEY (field_id) REFERENCES cons_process_fields(id)
|
||||
)
|
||||
''')
|
||||
|
||||
# cons_session_details - Scanned lot details
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS cons_session_details (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
session_id INTEGER NOT NULL,
|
||||
item_number TEXT,
|
||||
lot_number TEXT NOT NULL,
|
||||
weight REAL,
|
||||
scanned_by INTEGER NOT NULL,
|
||||
scanned_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
duplicate_status TEXT DEFAULT 'normal' CHECK(duplicate_status IN ('normal', 'dup_same_session', 'dup_other_session')),
|
||||
duplicate_info TEXT,
|
||||
comment TEXT,
|
||||
is_deleted INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (session_id) REFERENCES cons_sessions(id),
|
||||
FOREIGN KEY (scanned_by) REFERENCES Users(user_id)
|
||||
)
|
||||
''')
|
||||
|
||||
# Create Indexes
|
||||
# MASTER baseline indexes
|
||||
cursor.execute('CREATE INDEX IF NOT EXISTS idx_baseline_master_lot ON BaselineInventory_Master(session_id, lot_number)')
|
||||
@@ -211,6 +266,14 @@ def init_database():
|
||||
|
||||
# Note: No indexes on BaselineInventory_Current needed - UNIQUE constraint handles lookups
|
||||
|
||||
# Consumption Sheets indexes
|
||||
cursor.execute('CREATE INDEX IF NOT EXISTS idx_cons_process_fields_process ON cons_process_fields(process_id, table_type)')
|
||||
cursor.execute('CREATE INDEX IF NOT EXISTS idx_cons_process_fields_active ON cons_process_fields(process_id, is_active)')
|
||||
cursor.execute('CREATE INDEX IF NOT EXISTS idx_cons_sessions_process ON cons_sessions(process_id, status)')
|
||||
cursor.execute('CREATE INDEX IF NOT EXISTS idx_cons_sessions_user ON cons_sessions(created_by, status)')
|
||||
cursor.execute('CREATE INDEX IF NOT EXISTS idx_cons_session_details_session ON cons_session_details(session_id, is_deleted)')
|
||||
cursor.execute('CREATE INDEX IF NOT EXISTS idx_cons_session_details_lot ON cons_session_details(lot_number)')
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
print(f"✅ Database initialized at: {DB_PATH}")
|
||||
@@ -248,4 +311,4 @@ def create_default_users():
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_database()
|
||||
create_default_users()
|
||||
create_default_users()
|
||||
Reference in New Issue
Block a user